@giamme/forge 0.12.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/CHANGELOG.md +77 -0
  2. package/README.md +1 -1
  3. package/SKILL.md +31 -12
  4. package/VERSION +1 -1
  5. package/docs/add-ons.md +11 -6
  6. package/docs/artifacts.md +18 -6
  7. package/docs/commands.md +189 -17
  8. package/docs/decomposed-runs.md +13 -5
  9. package/docs/forge-ui.md +34 -4
  10. package/docs/memory.md +2 -1
  11. package/docs/models.md +4 -2
  12. package/docs/reviews.md +81 -19
  13. package/docs/troubleshooting.md +3 -1
  14. package/forge +17 -1
  15. package/package.json +1 -1
  16. package/references/dataset.md +40 -14
  17. package/references/decision-models.md +759 -0
  18. package/references/decompose.md +197 -28
  19. package/references/harnesses.md +10 -3
  20. package/references/planning.md +8 -0
  21. package/references/solo.md +13 -3
  22. package/references/ui.md +11 -0
  23. package/scripts/forge-artifact.sh +30 -4
  24. package/scripts/forge-config.py +238 -29
  25. package/scripts/forge-contract.py +127 -58
  26. package/scripts/forge-control.py +40 -9
  27. package/scripts/forge-decide.py +6 -0
  28. package/scripts/forge-dispatch.sh +47 -15
  29. package/scripts/forge-fail-first.py +2 -2
  30. package/scripts/forge-gate-addressed.sh +40 -0
  31. package/scripts/forge-gate-message.sh +64 -0
  32. package/scripts/forge-issues.py +368 -36
  33. package/scripts/forge-jev-options.sh +269 -42
  34. package/scripts/forge-lib-attribute.sh +447 -0
  35. package/scripts/forge-lib-gates.sh +32 -0
  36. package/scripts/forge-lib-plans.sh +17 -6
  37. package/scripts/forge-lib-review.sh +24 -19
  38. package/scripts/forge-lib-task.sh +219 -39
  39. package/scripts/forge-lib-verify.sh +45 -8
  40. package/scripts/forge-memory.sh +3 -3
  41. package/scripts/forge-parallel-options.sh +44 -5
  42. package/scripts/forge-parallel.sh +503 -304
  43. package/scripts/forge-plan-check.py +35 -1
  44. package/scripts/forge-pre-review.py +437 -0
  45. package/scripts/forge-prompt.py +25 -5
  46. package/scripts/forge-route.py +2 -2
  47. package/scripts/forge-runtime.py +55 -1
  48. package/scripts/forge-schedule.py +70 -9
  49. package/scripts/forge-shadow.py +2 -2
  50. package/scripts/forge-solo.sh +41 -10
  51. package/scripts/forge-submodules.py +389 -0
  52. package/scripts/forge-sweep.py +542 -0
  53. package/scripts/forge_dataset/cli.py +12 -6
  54. package/scripts/forge_dataset/export.py +55 -45
  55. package/scripts/forge_dataset/forecast.py +4 -1
  56. package/scripts/forge_dataset/harvest.py +33 -5
  57. package/scripts/{forge_jev/outcome.py → forge_dataset/states.py} +21 -7
  58. package/scripts/forge_decide/__init__.py +141 -0
  59. package/scripts/forge_decide/budget.py +149 -0
  60. package/scripts/forge_decide/cache.py +66 -0
  61. package/scripts/forge_decide/cli.py +953 -0
  62. package/scripts/forge_decide/doctor.py +221 -0
  63. package/scripts/forge_decide/label_addressed.py +75 -0
  64. package/scripts/forge_decide/label_attribution.py +62 -0
  65. package/scripts/forge_decide/label_coverage.py +81 -0
  66. package/scripts/forge_decide/label_message.py +38 -0
  67. package/scripts/forge_decide/label_prompt.py +139 -0
  68. package/scripts/forge_decide/labels.py +328 -0
  69. package/scripts/forge_decide/metrics.py +125 -0
  70. package/scripts/forge_decide/migrate.py +226 -0
  71. package/scripts/forge_decide/providers.py +292 -0
  72. package/scripts/forge_decide/replay.py +350 -0
  73. package/scripts/forge_decide/report.py +382 -0
  74. package/scripts/forge_decide/resolve.py +397 -0
  75. package/scripts/forge_decide/sites.py +377 -0
  76. package/scripts/forge_jev/__init__.py +202 -104
  77. package/scripts/forge_jev/addressed.py +171 -0
  78. package/scripts/forge_jev/attribution.py +198 -0
  79. package/scripts/forge_jev/cli.py +460 -382
  80. package/scripts/forge_jev/client.py +155 -77
  81. package/scripts/forge_jev/coupling.py +19 -87
  82. package/scripts/forge_jev/coverage.py +303 -0
  83. package/scripts/forge_jev/findings.py +219 -0
  84. package/scripts/forge_jev/gates.py +225 -27
  85. package/scripts/forge_jev/memory.py +65 -4
  86. package/scripts/forge_jev/message.py +134 -0
  87. package/scripts/forge_jev/plan_gates.py +294 -0
  88. package/scripts/forge_jev/questions.py +173 -313
  89. package/scripts/forge_jev/verify.py +130 -104
  90. package/ui/README.md +41 -10
  91. package/ui/docs/api.md +212 -44
  92. package/ui/forge_ui/checks.py +331 -0
  93. package/ui/forge_ui/control.py +60 -11
  94. package/ui/forge_ui/export.py +8 -3
  95. package/ui/forge_ui/models.py +1 -0
  96. package/ui/forge_ui/reader.py +436 -26
  97. package/ui/forge_ui/server.py +13 -0
  98. package/ui/forge_ui/static/app.js +15 -8
  99. package/ui/forge_ui/static/checksview.js +449 -0
  100. package/ui/forge_ui/static/controls.js +20 -13
  101. package/ui/forge_ui/static/convo.js +11 -2
  102. package/ui/forge_ui/static/findingsview.js +6 -4
  103. package/ui/forge_ui/static/index.html +1 -0
  104. package/ui/forge_ui/static/panel.js +105 -17
  105. package/ui/forge_ui/static/runmodel.js +40 -2
  106. package/ui/forge_ui/static/scene3d.js +2 -15
  107. package/ui/forge_ui/static/settings.js +336 -41
  108. package/ui/forge_ui/static/style.css +72 -7
  109. package/ui/forge_ui/transcripts.py +225 -54
  110. package/references/jev.md +0 -865
  111. package/scripts/forge_jev/backtest.py +0 -322
  112. package/scripts/forge_jev/corpus.py +0 -156
  113. package/scripts/forge_jev/features.py +0 -24
  114. package/scripts/forge_jev/predict.py +0 -204
  115. package/scripts/forge_jev/review.py +0 -73
  116. package/scripts/forge_jev/routing.py +0 -271
  117. package/scripts/forge_jev/subset.py +0 -123
@@ -6,20 +6,27 @@
6
6
  #
7
7
  # Usage:
8
8
  # forge-parallel.sh plan <plan-dir> --repo <dir> [routing flags] [--decompose-level low|medium|high] [--ui]
9
+ # [--qa-threshold P0|P1|P2|P3|none|default]
9
10
  # forge-parallel.sh run <plan-dir> [--max-parallel N] [--yolo-dwarf] [--yolo-qa]
10
11
  # [--verify <command>] [--setup <command>] [--dry-run]
11
12
  # [--timeout S] [--retry-failed N] [--infra-retries M]
12
- # [--qa-threshold P0|P1|P2|P3] [--verify-retries N] [--no-forecast]
13
+ # [--qa-threshold P0|P1|P2|P3|none|default] [--verify-retries N] [--no-forecast]
14
+ # [--sweep P0|P1|P2|P3 [--sweep-plausible] [--sweep-max N]]
15
+ # [--sweep-ahead | --no-sweep-ahead] [--attribute | --no-attribute]
13
16
  # forge-parallel.sh retry <plan-dir> <task-id> [--dwarf <spec>] [--setup <command>]
14
- # [--timeout S] [--qa-threshold Pn] [--verify-retries N]
17
+ # [--answer <text> | --answer-file <file>] (a NEEDS_INPUT task)
18
+ # [--timeout S] [--qa-threshold Pn|none|default] [--verify-retries N]
15
19
  # forge-parallel.sh integrate <plan-dir> --approved [--verify-retries N] [--final-review <qa-spec>]
16
- # forge-parallel.sh review <plan-dir> [--qa <spec>] [--yolo-qa] [--qa-threshold Pn]
20
+ # forge-parallel.sh review <plan-dir> [--qa <spec>] [--yolo-qa] [--qa-threshold Pn|none|default]
21
+ # forge-parallel.sh attribute <plan-dir> [--force] (find a merge that breaks the failed verification)
17
22
  # forge-parallel.sh accept <plan-dir> <task-id> --reason "<why>" --approved
18
23
  # forge-parallel.sh split <plan-dir> <new-plan> --tasks <id,id> [--dry-run]
19
24
  # forge-parallel.sh combine <new-plan> <plan-a> <plan-b> [<plan>...] [--verify <command>] [--dry-run]
20
25
  # forge-parallel.sh _task <plan-dir> <task-id> (internal; coordinator target)
21
26
  # forge-parallel.sh _qa_only <plan-dir> <task-id> (internal; exit 0 when the next entry only re-runs QA)
22
27
  # forge-parallel.sh _waves <plan-dir> (internal; rewrite waves.tsv after a live `forge control add`)
28
+ # forge-parallel.sh _sweep <plan-dir> --severity Pn [--plausible] [--max N]
29
+ # (internal; plan the finding sweep, print its task ids)
23
30
  #
24
31
  # Routing flags (plan):
25
32
  # --dwarf <spec> fallback for any difficulty tier not named below
@@ -37,18 +44,39 @@
37
44
  # unchanged, and starts fresh whenever it cannot; each round is
38
45
  # logged in tasks/<id>/review_sessions.tsv and tagged in the
39
46
  # dataset. `--no-reviewer-session` turns it off (the default)
47
+ # --implementer-session opt-in: a retry continues the implementer's earlier session
48
+ # (claude, openclaude) when its spec is unchanged and its work is
49
+ # still what the review judged, and starts fresh whenever it cannot;
50
+ # each attempt is logged in tasks/<id>/implementer_sessions.tsv.
51
+ # `--no-implementer-session` turns it off (the default)
40
52
  # --explore E on by default at 0.2 (0 turns it off, and is kept): a row left
41
53
  # to forge gets, with probability E/2, its neighbouring model
42
54
  # (one tier away in the given pools) instead of its pool's turn;
43
55
  # each decision and its odds go to tasks/<id>/route.jsonl
44
56
  # (precedence: flag, this plan's earlier choice, FORGE_ROUTE_EXPLORE)
45
57
  #
58
+ # The QA threshold (plan, run, retry, review; kept for the plan):
59
+ # --qa-threshold Pn the least severe CONFIRMED finding that still blocks (P0 worst ...
60
+ # P3 mildest; P2 when not set). forge decides the verdict from the
61
+ # findings: a PASS that lists a CONFIRMED finding at Pn or worse (or
62
+ # one with no severity) becomes FAIL; a FAIL made only of findings
63
+ # less severe than Pn is accepted as PASS-with-known-issues, and those
64
+ # are recorded in known_issues.md. `none` (or `off`) = P3, every
65
+ # CONFIRMED finding blocks; `default` goes back to P2
66
+ #
46
67
  # Opt-in run behaviour (all off unless asked):
47
68
  # --retry-failed N re-queue a task whose reviewer said FAIL up to N more times,
48
69
  # inside the same run, while the other tasks keep going
49
70
  # --infra-retries M wait out quota/auth/network stops up to M times instead of pausing
50
- # --qa-threshold Pn a reviewer FAIL made only of findings less severe than Pn is
51
- # accepted as PASS-with-known-issues (P0 worst ... P3 mildest)
71
+ # --sweep Pn once every task has merged, before verification: the open findings
72
+ # at Pn or worse (tolerated, and PLAUSIBLE with --sweep-plausible) become
73
+ # at most --sweep-max N fix tasks (default 5), one per file, each with a
74
+ # narrow review; the sweep plan is printed and kept in sweep/. Once per
75
+ # plan; what it does not fix stays for `forge issues`
76
+ # --sweep-ahead a task is also told the open findings in files it owns, to fix only
77
+ # on its way (kept for the plan; --no-sweep-ahead turns it off)
78
+ # --attribute when the run's combined verification fails, search the merge order for
79
+ # a merge that breaks it (kept for the plan; --no-attribute turns it off)
52
80
  #
53
81
  # Exit codes: 0 ok | 2 usage/validation | 3 precondition (not a git repo, etc.)
54
82
  # 5 some task failed QA or verification failed | 6 integration conflict
@@ -73,7 +101,7 @@ JEV_OPTS=0
73
101
  # Flags shared by several subcommands, then the helper libraries. Functions only, resolved
74
102
  # at call time, so they may use die/note/field and friends defined below.
75
103
  source "$SKILL_DIR/scripts/forge-parallel-options.sh"
76
- for forge_lib in task verify plans review; do
104
+ for forge_lib in task gates verify attribute plans review; do
77
105
  [ -f "$SKILL_DIR/scripts/forge-lib-$forge_lib.sh" ] && source "$SKILL_DIR/scripts/forge-lib-$forge_lib.sh"
78
106
  done
79
107
  OUTPUT=summary
@@ -136,7 +164,7 @@ pool_pick() { # pool_pick <comma-list> <index>
136
164
  do_plan() {
137
165
  local PLAN="${1:?plan needs a plan dir}"; shift
138
166
  local REPO="" D_ANY="" D_HI="" D_MD="" D_LO="" Q_ANY="" Q_HI="" Q_MD="" Q_LO=""
139
- local PLANNER="" NOMEM=0 jev_rc=0 DLEVEL="" SHADOW_QA="" SHADOW_RATE="" EXPLORE="" FAIL_FIRST="" REVIEWER_SESSION=""
167
+ local PLANNER="" NOMEM=0 jev_rc=0 DLEVEL="" SHADOW_QA="" SHADOW_RATE="" EXPLORE="" FAIL_FIRST="" REVIEWER_SESSION="" IMPLEMENTER_SESSION="" PRE_REVIEW="" PRE_REVIEW_PARALLEL=""
140
168
  while [ $# -gt 0 ]; do
141
169
  case "$1" in
142
170
  --repo) REPO="${2:?}"; shift 2 ;;
@@ -164,12 +192,23 @@ do_plan() {
164
192
  --ui|--no-ui) forge_ui_flag "$1"; shift ;;
165
193
  --fail-first) FAIL_FIRST=on; shift ;;
166
194
  --no-fail-first) FAIL_FIRST=off; shift ;;
195
+ --pre-review-tests) PRE_REVIEW=on; shift ;;
196
+ --no-pre-review-tests) PRE_REVIEW=off; shift ;;
197
+ --pre-review-parallel)
198
+ printf '%s' "${2:-}" | grep -Eq '^[0-9]{1,2}$' && [ "$2" -ge 1 ] && [ "$2" -le 64 ] \
199
+ || die "--pre-review-parallel needs an integer from 1 to 64" 2
200
+ PRE_REVIEW_PARALLEL="$((10#$2))"; shift 2 ;;
167
201
  --reviewer-session) REVIEWER_SESSION=on; shift ;;
168
202
  --no-reviewer-session) REVIEWER_SESSION=off; shift ;;
203
+ --implementer-session) IMPLEMENTER_SESSION=on; shift ;;
204
+ --no-implementer-session) IMPLEMENTER_SESSION=off; shift ;;
169
205
  *)
170
206
  # `case` is not a loop, so `continue` here belongs to the enclosing while.
207
+ # The shared flags write into the plan dir (--qa-threshold), so it must exist first.
208
+ [ -d "$PLAN" ] || die "plan dir '$PLAN' does not exist"
209
+ if forge_pp_flag plan "$PLAN" "$@"; then shift "$PP_SHIFT"; continue; fi
171
210
  if [ "$JEV_OPTS" = 1 ]; then
172
- forge_jev_flag "$1"; jev_rc=$?
211
+ forge_jev_flag "$@"; jev_rc=$?
173
212
  case "$jev_rc" in
174
213
  0) shift "$JEV_SHIFT"; continue ;;
175
214
  2) exit 2 ;;
@@ -201,9 +240,16 @@ do_plan() {
201
240
  || printf '%s\n' "$SHADOW_RATE" > "$PLAN/shadow_rate"
202
241
  # Fail-first evidence (opt-in, advisory) is part of the plan too: every task's review gets it.
203
242
  case "$FAIL_FIRST" in on) : > "$PLAN/fail_first" ;; off) rm -f "$PLAN/fail_first" ;; esac
243
+ # Pre-review tests (opt-in, #85): each attempt's affected tests run before its review, and a
244
+ # red result goes back to the implementer without one.
245
+ case "$PRE_REVIEW" in on) : > "$PLAN/pre_review_tests" ;; off) rm -f "$PLAN/pre_review_tests" ;; esac
246
+ # How many checks run at once across the plan's tasks (forge_pre_review's slots; default 2).
247
+ [ -z "$PRE_REVIEW_PARALLEL" ] || printf '%s\n' "$PRE_REVIEW_PARALLEL" > "$PLAN/pre_review_parallel"
204
248
  # Reviewer-session continuation (opt-in experiment): the file holds `on`. Readers only
205
249
  # test that it exists; the dataset records its content.
206
250
  case "$REVIEWER_SESSION" in on) printf '%s\n' on > "$PLAN/reviewer_session" ;; off) rm -f "$PLAN/reviewer_session" ;; esac
251
+ # Implementer-session continuation (opt-in, #90): the same `on` file, read the same way.
252
+ case "$IMPLEMENTER_SESSION" in on) printf '%s\n' on > "$PLAN/implementer_session" ;; off) rm -f "$PLAN/implementer_session" ;; esac
207
253
  # Exploration is decided here and only here, so the table and preflight see what will run.
208
254
  # On by default: choosing models from measured pass rates needs some randomized picks, and
209
255
  # history had almost none (9 tasks ever ran on more than one spec). The flag wins, then
@@ -228,6 +274,8 @@ do_plan() {
228
274
  fi
229
275
  [ -s "$PLAN/repo" ] || die "plan needs --repo the first time"
230
276
  REPO="$(cat "$PLAN/repo")"
277
+ # Before any decision-model step: the privacy floor and the run budget read these.
278
+ [ "$JEV_OPTS" = 1 ] && forge_decide_env "$REPO" "$PLAN"
231
279
  [ -s "$PLAN/run_id" ] || basename "$PLAN" | sed 's/^forge-//' > "$PLAN/run_id"
232
280
  # Every plan, --ui or not: forge-ui's view of this repo's runs reads the registry.
233
281
  forge_ui_register "$PLAN"
@@ -253,54 +301,68 @@ PY
253
301
  note " if the tasks depend on them."
254
302
  fi
255
303
 
256
- # --- jev: advisory difficulty scoring ------------------------------------------
257
- # Advisory only: a suggested tier, and gate warnings about the task text. Writing a Jev
258
- # tier into the difficulty column (`--jev-act`, gated on a per-repo calibration) was
259
- # removed on 2026-10-17 without ever having acted; models are chosen from measured pass
260
- # rates instead (plan --explore, `forge dataset routing`).
304
+ # --- jev: plan-time gates ------------------------------------------------------
305
+ # Prompt adequacy and drift: warnings about the task text and its declared files. Drift
306
+ # `on` adds the files it predicts to tasks.tsv (inside score-plan); `shadow` only records.
261
307
  local jev_loaded=0
262
308
  if [ -f "$SKILL_DIR/scripts/forge-jev-options.sh" ]; then
263
309
  source "$SKILL_DIR/scripts/forge-jev-options.sh" 2>/dev/null && jev_loaded=1
264
310
  fi
265
- if [ "$jev_loaded" = 1 ] && forge_jev_active routing; then
311
+ if [ "$jev_loaded" = 1 ] && { forge_decide_active prompt || forge_decide_active drift; }; then
266
312
  local jev_scores jev_rc
267
313
  jev_scores="$(python3 "$SKILL_DIR/scripts/forge-jev.py" score-plan \
268
314
  --plan "$PLAN" --repo "$REPO" 2>/dev/null)"
269
315
  jev_rc=$?
316
+ # A gate in shadow is asked and recorded by score-plan, which leaves it out of
317
+ # these rows: what is printed here is only what an `on` gate has to say.
318
+ # --jev-shadow before migration keeps its gates `on` and prints a count for the
319
+ # warnings, as it always did; what a gate ADDED is still said, whatever the flag.
270
320
  if [ "$jev_rc" -eq 0 ] && [ -n "$jev_scores" ]; then
271
- # Shadow mode records the judgment and prints nothing per task.
272
- if [ "${FORGE_JEV_SHADOW:-}" = on ]; then
273
- note "jev: scored $(printf '%s\n' "$jev_scores" | grep -c . ) task(s) in shadow mode (no change)"
274
- else
275
- local jid jtier jconf jcomp jesc jdecl jwarn jdrift
276
- # The columns score-plan prints: id, tier, confidence, composite, escalated,
277
- # declared, warnings, drift. Read in lockstep with cmd_score_plan.
278
- while IFS="$(printf '\t')" read -r jid jtier jconf jcomp jesc jdecl jwarn jdrift; do
279
- [ -n "$jid" ] || continue
280
- # score-plan writes "-" for "not escalated"; only a real reason is worth showing.
281
- [ "$jesc" = "-" ] && jesc=""
282
- note "jev: $jid suggests $jtier (confidence $jconf${jesc:+, escalated: $jesc}) — declared $jdecl"
283
- # Gates are warnings: they are about the task text and its declared files, not
284
- # about which model runs it.
285
- if [ -n "$jwarn" ] && [ "$jwarn" != "-" ]; then
286
- case "$jwarn" in
287
- *prompt_adequacy*) note "jev: $jid — the prompt may be too vague for QA to judge correctness against" ;;
288
- esac
289
- case "$jwarn" in
290
- *independently_verifiable*) note "jev: $jid — may not be verifiable on its own (decompose.md forbids splitting this finely)" ;;
291
- esac
292
- fi
293
- if [ -n "$jdrift" ] && [ "$jdrift" != "-" ]; then
294
- note "jev: $jid may also edit undeclared files: $jdrift"
295
- note " undeclared files break wave disjointness — add them to the files column or split the task"
296
- fi
297
- done <<EOF
321
+ local jid jwarn jdrift
322
+ # The columns score-plan prints: id, warnings, drift. Read in lockstep with
323
+ # cmd_score_plan.
324
+ while IFS="$(printf '\t')" read -r jid jwarn jdrift; do
325
+ [ -n "$jid" ] || continue
326
+ if [ "${FORGE_JEV_SHADOW:-}" != on ]; then
327
+ case "$jwarn" in
328
+ *prompt_adequacy*) note "jev: $jid — the prompt may be too vague for QA to judge correctness against" ;;
329
+ esac
330
+ fi
331
+ if [ -n "$jdrift" ] && [ "$jdrift" != "-" ]; then
332
+ # The drift field only names files score-plan ADDED (drift `on`): a shadowed gate
333
+ # prints '-', so there is no "may edit undeclared files" case left to hint at.
334
+ note "drift added to $jid: $jdrift"
335
+ fi
336
+ done <<EOF
298
337
  $jev_scores
299
338
  EOF
339
+ if [ "${FORGE_JEV_SHADOW:-}" = on ]; then
340
+ note "jev: scored $(printf '%s\n' "$jev_scores" | grep -c .) task(s) in shadow mode (no change)"
300
341
  fi
301
342
  fi
302
343
  fi
303
344
 
345
+ # Coverage: does some task's acceptance criteria deliver each requirement of request.md?
346
+ # `on` marks the ones no task covers pending in plan-gates.json; the send-back file below
347
+ # says which, so nothing is printed here.
348
+ if [ "$jev_loaded" = 1 ] && forge_decide_active coverage; then
349
+ python3 "$SKILL_DIR/scripts/forge-jev.py" coverage --plan "$PLAN" --repo "$REPO" >/dev/null 2>&1 || true
350
+ fi
351
+
352
+ # The one send-back step of this call, after every pre-resolve gate: prompt and coverage
353
+ # mark what to rewrite, and exit 4 hands it back before validation, waves and the table.
354
+ # An item is sent back once; the re-plan lists what is still wrong under the table.
355
+ if [ "$jev_loaded" = 1 ] && { forge_decide_active prompt || forge_decide_active coverage; }; then
356
+ local sendback_out sendback_rc=0 sendback_n
357
+ sendback_out="$(python3 "$SKILL_DIR/scripts/forge-plan-check.py" sendback "$PLAN" 2>/dev/null)" || sendback_rc=$?
358
+ if [ "$sendback_rc" -eq 4 ]; then
359
+ printf '%s\n' "$sendback_out"
360
+ sendback_n="$(printf '%s\n' "$sendback_out" | grep -c '^- ')"
361
+ note "plan gates sent $sendback_n item(s) back: rewrite them as $PLAN/plan.sendback.md says, then run plan again (once)"
362
+ return 4
363
+ fi
364
+ fi
365
+
304
366
  # --- validate + resolve routing ---
305
367
  local tmp="$PLAN/.tasks.tsv.new"; : > "$tmp"
306
368
  local hi_i=0 md_i=0 lo_i=0 an_i=0 qhi_i=0 qmd_i=0 qlo_i=0 qan_i=0 unassigned=0
@@ -369,50 +431,53 @@ EOF
369
431
 
370
432
  compute_waves "$PLAN"
371
433
 
372
- # --- clef: silent first-attempt predictions -------------------------------------
373
- # Recorded only (tasks/<id>/clef.first_pass and the run dataset), so a later export can
374
- # measure whether Clef tells which tasks a first attempt will fail. Nothing in a run
375
- # reads them. Without a Cloudflare provider the command returns at once; with one it
376
- # bounds itself (one deadline for the plan, an in-process watchdog).
377
- if [ "${FORGE_JEV:-}" != off ]; then
378
- python3 "$SKILL_DIR/scripts/forge-jev.py" first-pass --plan "$PLAN" --repo "$REPO" >/dev/null 2>&1 || true
379
- fi
380
-
381
- # --- jev: advisory wave coupling ------------------------------------------------
382
- # Disjoint files bound parallelism structurally, but they cannot see the conflict
383
- # where one task in a wave changes an interface another task in the SAME wave
384
- # consumes -- both diffs are clean against their own baseline, and the merge is
385
- # broken. This is advisory only: it never edits tasks.tsv, never adds a dep, and
386
- # never changes waves.tsv, so it must run after compute_waves and before the table
387
- # that reports the plan is printed.
388
- if [ "$jev_loaded" = 1 ] && forge_jev_active gates; then
434
+ # --- jev: forward dependency ----------------------------------------------------
435
+ # Wave order is structural, but it cannot see an earlier-wave task written against
436
+ # an interface a later-wave task builds. Forward `on` adds that dep to tasks.tsv (inside
437
+ # `coupling`, refusing a cycle), so the waves are computed again below when it did;
438
+ # otherwise the gate only advises. It runs after compute_waves and before the table.
439
+ if [ "$jev_loaded" = 1 ] && forge_decide_active forward; then
389
440
  local jev_coupling jev_coupling_rc
390
441
  jev_coupling="$(python3 "$SKILL_DIR/scripts/forge-jev.py" coupling \
391
442
  --plan "$PLAN" --repo "$REPO" 2>/dev/null)"
392
443
  jev_coupling_rc=$?
444
+ # A shadowed forward gate is recorded in jev-coupling.json and prints no row; --jev-shadow
445
+ # before migration counts the advisory rows, as it always did. Rows an `on` gate acted
446
+ # on (`added`, `cycle`) are said and acted on whatever the flag.
393
447
  if [ "$jev_coupling_rc" -eq 0 ] && [ -n "$jev_coupling" ]; then
394
- if [ "${FORGE_JEV_SHADOW:-}" = on ]; then
395
- note "jev: found $(printf '%s\n' "$jev_coupling" | grep -c .) coupled pair(s) in shadow mode (no change)"
396
- else
397
- local ca cb cp ckind
398
- while IFS="$(printf '\t')" read -r ca cb cp ckind; do
399
- [ -n "$ca" ] || continue
400
- # Two different failures, so two different sentences. same-wave is a broken
401
- # merge between concurrent tasks; forward is an earlier task written against
402
- # work that has not been built yet, which its own review cannot catch.
403
- if [ "$ckind" = forward ]; then
404
- note "jev: task '$ca' runs before '$cb' and may depend on what it builds ($cp) — consider a dep"
405
- else
406
- note "jev: tasks '$ca' and '$cb' may conflict despite disjoint files ($cp) — consider a dep"
407
- fi
408
- done <<EOF
448
+ local ca cb cp ckind dep_added=0 advisory=0
449
+ while IFS="$(printf '\t')" read -r ca cb cp ckind; do
450
+ [ -n "$ca" ] || continue
451
+ # An earlier task written against work that has not been built yet, which its own
452
+ # review cannot catch. The last column says what `on` did about it.
453
+ case "$ckind" in
454
+ added)
455
+ dep_added=1
456
+ note "forward: task '$ca' now waits for '$cb' ($cp) — it may depend on what '$cb' builds" ;;
457
+ cycle)
458
+ note "forward: '$ca' may depend on '$cb' ($cp), but that dependency would form a cycle — not added" ;;
459
+ *)
460
+ advisory=$((advisory+1))
461
+ [ "${FORGE_JEV_SHADOW:-}" = on ] ||
462
+ note "jev: task '$ca' runs before '$cb' and may depend on what it builds ($cp) — consider a dep" ;;
463
+ esac
464
+ done <<EOF
409
465
  $jev_coupling
410
466
  EOF
467
+ if [ "$advisory" -gt 0 ] && [ "${FORGE_JEV_SHADOW:-}" = on ]; then
468
+ note "jev: found $advisory coupled pair(s) in shadow mode (no change)"
411
469
  fi
470
+ if [ "$dep_added" = 1 ]; then compute_waves "$PLAN"; fi
412
471
  fi
413
472
  fi
414
473
 
415
474
  render_table "$PLAN"
475
+ # What the gates did, from plan-gates.json: files and deps they added, prompts and
476
+ # requirements still flagged. Prints nothing when no gate recorded anything.
477
+ python3 "$SKILL_DIR/scripts/forge-plan-check.py" gates "$PLAN" 2>/dev/null || true
478
+ # Advisory, under the table: a privacy floor that silences every gate, and which
479
+ # gates this plan's runs will ask. Prints nothing when it cannot tell.
480
+ [ "$jev_loaded" = 1 ] && forge_decide_plan_lines "${FORGE_DECIDE_REPO:-$REPO}"
416
481
  # Before the UNASSIGNED return, so the URL prints under the table either way.
417
482
  forge_ui_launch "$PLAN"
418
483
 
@@ -494,9 +559,34 @@ render_table() {
494
559
  echo "fail-first: on, but $(cat "$PLAN/repo")/.forge/verify-subset (a test command with {files}) is missing, so nothing will run"
495
560
  fi
496
561
  fi
562
+ if [ -f "$PLAN/pre_review_tests" ]; then
563
+ if [ -s "$(cat "$PLAN/repo")/.forge/verify-subset" ]; then
564
+ echo "pre-review tests: on — each attempt's affected tests run before its review; a red attempt goes back to its implementer unreviewed"
565
+ else
566
+ echo "pre-review tests: on, but $(cat "$PLAN/repo")/.forge/verify-subset (a test command with {files} or {changed}) is missing, so nothing will run"
567
+ fi
568
+ fi
497
569
  if [ -f "$PLAN/reviewer_session" ]; then
498
570
  echo "reviewer-session: a later review round continues the reviewer's earlier session when its QA spec is unchanged (experiment; falls back to a fresh session)"
499
571
  fi
572
+ if [ -f "$PLAN/implementer_session" ]; then
573
+ echo "implementer-session: a retry continues the implementer's earlier session when its spec is unchanged and its work is as the review left it (claude, openclaude; falls back to a fresh session)"
574
+ fi
575
+ # The plan-level threshold: at plan time no per-task file exists yet.
576
+ local qa_level qa_src
577
+ read -r qa_level qa_src <<EOF
578
+ $(qa_threshold_walk "$PLAN" "")
579
+ EOF
580
+ case "$qa_level" in
581
+ P3) echo "QA threshold: P3 ($qa_src) — every CONFIRMED finding blocks" ;;
582
+ P0) echo "QA threshold: P0 ($qa_src) — P0 blocks; a CONFIRMED P1–P3 is recorded as a known issue" ;;
583
+ P1) echo "QA threshold: P1 ($qa_src) — P0–P1 block; a CONFIRMED P2–P3 is recorded as a known issue" ;;
584
+ *) echo "QA threshold: P2 ($qa_src) — P0–P2 block; a CONFIRMED P3 is recorded as a known issue" ;;
585
+ esac
586
+ # A reviewer spec that names no effort reviews at forge-dispatch.sh's QA default (#89).
587
+ if awk -F'\t' '$0 !~ /^#/ && NF >= 6 { split($6, s, ":"); if (s[2] == "") found = 1 } END { exit !found }' "$T"; then
588
+ echo "QA effort: high where a reviewer spec names none (forge-dispatch.sh's default; planning stays at xhigh)"
589
+ fi
500
590
  echo
501
591
  local w id dws starred=0
502
592
  for w in $(awk -F'\t' '{print $1}' "$W" | sort -un); do
@@ -584,6 +674,28 @@ preflight_plan() {
584
674
  fi
585
675
  }
586
676
 
677
+ # The implementer a sweep task gets when the plan has a low tier (or a plain --dwarf pool): checked
678
+ # with the rest, before any model is paid for, since no task may have used it yet.
679
+ sweep_preflight() { # sweep_preflight <plan>
680
+ local spec flags=""
681
+ spec="$(python3 -c 'import json, sys
682
+ try:
683
+ data = json.load(open(sys.argv[1]))
684
+ except Exception:
685
+ sys.exit()
686
+ for tier in ("low", "any"):
687
+ specs = data.get(tier) if isinstance(data, dict) else None
688
+ if isinstance(specs, list) and specs and isinstance(specs[0], str) and specs[0]:
689
+ print(specs[0]); break' "$1/fractal-routing.json" 2>/dev/null)"
690
+ [ -n "$spec" ] || return 0
691
+ [ -f "$1/yolo_dwarf" ] && flags=--yolo
692
+ /bin/bash "$DISPATCH" doctor --spec "$spec" --role dwarf $flags
693
+ }
694
+
695
+ sweep_plan() { # sweep_plan <plan> --severity Pn [--plausible] [--max N]: the scheduler's _sweep
696
+ python3 "$SKILL_DIR/scripts/forge-sweep.py" plan "$@"
697
+ }
698
+
587
699
  write_capsule() { # write_capsule <plan> <id> <role>
588
700
  local PLAN="$1" me="$2" role="$3" T="$1/tasks.tsv"
589
701
  local run_id; run_id="$(cat "$PLAN/run_id")"
@@ -622,6 +734,16 @@ write_capsule() { # write_capsule <plan> <id> <role>
622
734
  echo "- MERGED means present in this task's pinned baseline; later merges are not included."
623
735
  echo "- The review diff is only this task's work against that baseline."
624
736
  echo "- Implementation must respect other tasks' ownership; report necessary scope changes."
737
+ if [ -s "$PLAN/tasks/$me/submodules.txt" ]; then
738
+ local sm_st sm_path
739
+ while IFS="$(printf '\t')" read -r sm_st sm_path _; do
740
+ if [ "$sm_st" = missing ]; then
741
+ echo "- Submodule \`$sm_path\` is not available in this worktree (its directory is empty)."
742
+ else
743
+ echo "- \`$sm_path\` is a submodule: its files are here to read and build with. Changes there are not part of your change and are never committed or reviewed."
744
+ fi
745
+ done < "$PLAN/tasks/$me/submodules.txt"
746
+ fi
625
747
 
626
748
  } > "$out"
627
749
  echo "$out"
@@ -662,11 +784,29 @@ worktree_setup_command() { # worktree_setup_command <plan> <repo>
662
784
  return 0
663
785
  }
664
786
 
787
+ # Exports each submodule's files into a fresh worktree (offline, no `.git`, so they stay
788
+ # invisible to every diff and fingerprint). Never fatal: a failure leaves the directory empty.
789
+ populate_submodules() { # populate_submodules <repo> <wt> <tdir> <id>
790
+ local repo="$1" wt="$2" tdir="$3" id="$4" st path _sha detail err
791
+ rm -f "$tdir/submodules.txt"
792
+ err="$(python3 "$SKILL_DIR/scripts/forge-submodules.py" populate --source "$repo" --worktree "$wt" \
793
+ --out "$tdir/submodules.txt" 2>&1 >/dev/null)" \
794
+ || note "$id: submodule population failed (continuing): $(printf '%s' "$err" | tail -1)"
795
+ [ -s "$tdir/submodules.txt" ] || return 0
796
+ while IFS="$(printf '\t')" read -r st path _sha detail; do
797
+ [ "$st" = missing ] && note "$id: submodule $path is not available in this worktree ($detail)"
798
+ done < "$tdir/submodules.txt"
799
+ return 0
800
+ }
801
+
665
802
  # Non-fatal by design. A setup step that fails leaves a worktree the dwarf can still
666
803
  # work in — it just has to install things itself, which is the status quo this exists
667
804
  # to improve on. Failing the task instead would turn a slow run into a dead one.
668
805
  run_worktree_setup() { # run_worktree_setup <plan> <repo> <wt> <tdir> <id>
669
806
  local PLAN="$1" REPO="$2" wt="$3" tdir="$4" id="$5" cmd
807
+ # Every worktree forge makes reaches here once, right after it exists, so the submodules'
808
+ # files are in place before `.forge/setup` runs. The outcome lands in <tdir>/submodules.txt.
809
+ populate_submodules "$REPO" "$wt" "$tdir" "$id"
670
810
  cmd="$(worktree_setup_command "$PLAN" "$REPO")"
671
811
  [ -n "$cmd" ] || return 0
672
812
  if (cd "$wt" && eval "$cmd") >"$tdir/setup.out" 2>&1; then
@@ -757,14 +897,12 @@ do_task_body() (
757
897
  if [ -z "$resume" ]; then
758
898
  attempt=$(( attempt + 1 ))
759
899
  echo "$attempt" > "$tdir/attempt"
760
- # Silent: Clef's guess at whether this retry passes with the findings it was handed.
761
- # Only a real new dwarf attempt (not a QA-only resume); recorded in clef.retry_pass.<n>
762
- # and the run dataset, never read by the run, and it can never fail the task.
763
- if [ "$attempt" -gt 1 ] && [ -s "$tdir/retry_findings.md" ] && [ "${FORGE_JEV:-}" != off ]; then
764
- python3 "$SKILL_DIR/scripts/forge-jev.py" retry-pass --plan "$PLAN" --repo "$REPO" --task "$id" \
765
- --attempt "$attempt" >/dev/null 2>&1 || true
766
- fi
767
900
  fi
901
+ # The gate's decision belongs to the review that made it. A review that ends before the gate
902
+ # (invalidated, timed out, no changes) must not leave an earlier attempt's decision for the
903
+ # next retry note or `accept` to read; prepare_retry has already carried it forward.
904
+ rm -f "$tdir/qa.gate" "$tdir/known_issues.md" "$tdir/invalidated.reason" "$tdir/prereview.failed" \
905
+ "$tdir/bounced" "$tdir/message.failed"
768
906
 
769
907
  # The base is pinned per task on first creation and reused by every retry. The
770
908
  # integration branch moves as later waves land, so re-reading the run-level
@@ -797,17 +935,73 @@ do_task_body() (
797
935
  /bin/bash "$MEMORY" inject "$REPO" dwarf --task "$tdir/prompt.md" \
798
936
  --run-dir "$tdir" > "$tdir/dwarf.memory"
799
937
  {
800
- python3 "$SKILL_DIR/scripts/forge-prompt.py" --requirements "$tdir/prompt.md" --capsule "$tdir/baseline.capsule" --approach "$tdir/approach.md" --retry "$tdir/retry_findings.md" --memory "$tdir/dwarf.memory"
938
+ python3 "$SKILL_DIR/scripts/forge-prompt.py" --requirements "$tdir/prompt.md" --capsule "$tdir/baseline.capsule" --approach "$tdir/approach.md" --retry "$tdir/retry_findings.md" --retry-source "$(cat "$tdir/retry_findings.source" 2>/dev/null || echo review)" --memory "$tdir/dwarf.memory"
939
+ [ ! -f "$PLAN/sweep_ahead" ] || python3 "$SKILL_DIR/scripts/forge-sweep.py" ahead "$PLAN" "$id" --role dwarf 2>/dev/null
801
940
  echo "Implement this task in the repository. Follow the intended approach unless it is wrong; explain deviations. Run the task's requested verification and report results."
802
941
  echo "On retry, fix the findings in the existing work; preserve parts not criticised. Explain any finding you reject."
803
- echo; python3 "$SKILL_DIR/scripts/forge-contract.py" dwarf
942
+ echo; python3 "$SKILL_DIR/scripts/forge-contract.py" dwarf $([ ! -f "$PLAN/pre_review_tests" ] || echo --pre-review)
804
943
  echo; /bin/bash "$MEMORY" note dwarf
805
944
  } > "$tdir/dwarf.input"
806
945
  guard_before_dwarf "$wt" "$tdir"
946
+ # Whether this attempt continues the implementer's earlier session (plan
947
+ # --implementer-session, #90): only a retry of judged work that is still exactly what was
948
+ # judged, on the harness, model and effort that made it. Every other answer is a fresh
949
+ # dispatch, and nothing here can abort the attempt: a doctor that fails means fresh.
950
+ local is_mode=fresh is_reason="" is_id="" is_fp="" is_cont=()
951
+ if [ -f "$PLAN/implementer_session" ]; then
952
+ if [ -n "${FORGE_FRACTAL_RUN:-}" ] || forge_plan_is_fractal "$PLAN"; then
953
+ is_reason=fractal
954
+ elif [ "$attempt" = 1 ]; then
955
+ is_reason=first-attempt
956
+ elif [ ! -s "$tdir/retry_findings.md" ]; then
957
+ is_reason=no-findings
958
+ elif ! implementer_work_unchanged "$tdir" "$wt"; then
959
+ is_reason=work-changed
960
+ else
961
+ FORGE_CAPABILITY_CACHE="${FORGE_CAPABILITY_CACHE:-$PLAN/capabilities}" \
962
+ /bin/bash "$DISPATCH" doctor --spec "$dw" --role dwarf $yd > "$tdir/dwarf.doctor" 2>&1 || : > "$tdir/dwarf.doctor"
963
+ IFS=$'\t' read -r is_mode is_reason is_id < <(review_session_decide \
964
+ "$tdir/retry_findings.dwarf.session" "$tdir/retry_findings.dwarf.resolved" "$tdir/dwarf.doctor" "claude openclaude")
965
+ if [ "$is_mode" = continued ]; then
966
+ is_cont=(--continue-session "$is_id")
967
+ is_fp="$(forge_fingerprint "$wt")" || is_fp=""
968
+ fi
969
+ fi
970
+ fi
807
971
  forge_metric_phase dispatch
808
- /bin/bash "$DISPATCH" dwarf "$dw" --repo "$wt" --run-dir "$tdir" \
809
- --ripwire-query-file "$tdir/prompt.md" --prompt-file "$tdir/dwarf.input" $yd --output "${FORGE_OUTPUT:-summary}" >"$tdir/dwarf.out" 2>&1
972
+ local dwarf_cmd=(/bin/bash "$DISPATCH" dwarf "$dw" --repo "$wt" --run-dir "$tdir" \
973
+ --ripwire-query-file "$tdir/prompt.md" --prompt-file "$tdir/dwarf.input" ${yd:+"$yd"} --output "${FORGE_OUTPUT:-summary}")
974
+ "${dwarf_cmd[@]}" ${is_cont[@]+"${is_cont[@]}"} >"$tdir/dwarf.out" 2>&1
810
975
  rc=$?
976
+ if [ "$rc" = 9 ] && [ "$is_mode" = continued ]; then
977
+ # The session was not continued (the harness cannot, or it failed). Why comes from the
978
+ # continued dispatch's record, which a fresh one clears.
979
+ if [ "$(sed -n 's/^reason=//p' "$tdir/dwarf.continue" 2>/dev/null | head -1)" = unsupported ]; then
980
+ is_reason=continue-unsupported
981
+ else
982
+ is_reason=continue-failed
983
+ fi
984
+ mv "$tdir/dwarf.out" "$tdir/dwarf.continue.out" 2>/dev/null || true
985
+ if [ -n "$is_fp" ] && [ "$(forge_fingerprint "$wt")" = "$is_fp" ]; then
986
+ # It changed nothing, so the same input goes to a fresh session, which decides the attempt.
987
+ is_mode=fresh
988
+ "${dwarf_cmd[@]}" >"$tdir/dwarf.out" 2>&1
989
+ rc=$?
990
+ else
991
+ # It worked on the task before it failed: that is a failed implementer, as when a fresh
992
+ # one fails, and running a fresh one on top would pay for the attempt twice.
993
+ is_mode=failed
994
+ cp "$tdir/dwarf.continue.out" "$tdir/dwarf.out" 2>/dev/null || true
995
+ rc=4
996
+ note "$id: the continued implementer session failed after changing files — not running a fresh one on top"
997
+ fi
998
+ fi
999
+ if [ -f "$PLAN/implementer_session" ]; then
1000
+ # One row per attempt, describing the dispatch whose result counts.
1001
+ local is_row=1
1002
+ [ ! -f "$tdir/implementer_sessions.tsv" ] || is_row=$(( $(wc -l < "$tdir/implementer_sessions.tsv") + 1 ))
1003
+ printf '%s\t%s\t%s\t%s\t%s\n' "$is_row" "$attempt" "$is_mode" "$is_reason" "$is_id" >> "$tdir/implementer_sessions.tsv"
1004
+ fi
811
1005
  if [ "${FORGE_OUTPUT:-summary}" = full ]; then cat "$tdir/dwarf.out"; fi
812
1006
  if [ "$rc" -ne 0 ]; then
813
1007
  case "$rc" in
@@ -823,6 +1017,8 @@ do_task_body() (
823
1017
  --duration "$(dispatch_duration "$tdir" dwarf)" >/dev/null 2>&1
824
1018
 
825
1019
  guard_after_dwarf "$wt" "$tdir" "$id"
1020
+ # Before the snapshot, so a dwarf that only asked a question (and changed nothing) still reaches it.
1021
+ forge_post_dwarf_gates "$PLAN" "$id" "$tdir" "$wt" "$attempt" || return 0
826
1022
  forge_metric_phase snapshot
827
1023
  # Capture the real diff, including new files, then commit on the task branch.
828
1024
  # Diffed against the task's pinned base rather than the branch head, so a retry
@@ -847,7 +1043,11 @@ do_task_body() (
847
1043
  echo "The dwarf produced no changes at all." > "$tdir/qa.last"
848
1044
  note "$id: dwarf produced an empty diff"; return 1
849
1045
  fi
850
- if [ -s "$tdir/changes.prev.diff" ] && cmp -s "$tdir/changes.diff" "$tdir/changes.prev.diff"; then
1046
+ # A bounced attempt (retry_findings.source `bounce`) was never reviewed, so a retry that keeps
1047
+ # its code is reviewed rather than refused as identical: the refusal is for a diff a review
1048
+ # already judged.
1049
+ if [ -s "$tdir/changes.prev.diff" ] && cmp -s "$tdir/changes.diff" "$tdir/changes.prev.diff" \
1050
+ && [ "$(cat "$tdir/retry_findings.source" 2>/dev/null)" != bounce ]; then
851
1051
  echo FAIL > "$tdir/status"
852
1052
  : > "$tdir/noretry"
853
1053
  echo "The retry changed nothing: the diff is byte-identical to the previous attempt." \
@@ -874,47 +1074,46 @@ do_task_body() (
874
1074
  echo INVALIDATED > "$tdir/status"; return 1
875
1075
  fi
876
1076
  echo "$reviewed" > "$tdir/reviewed.commit"
1077
+ # The implementer session that made this commit, and what it ran as: the one a retry of
1078
+ # these findings may continue (plan --implementer-session; carried with the findings).
1079
+ rm -f "$tdir/reviewed.dwarf.session" "$tdir/reviewed.dwarf.resolved"
1080
+ [ ! -s "$tdir/dwarf.session" ] || cp "$tdir/dwarf.session" "$tdir/reviewed.dwarf.session"
1081
+ [ ! -s "$tdir/dwarf.resolved" ] || cp "$tdir/dwarf.resolved" "$tdir/reviewed.dwarf.resolved"
1082
+ forge_pre_qa_gates "$PLAN" "$id" "$tdir" "$wt" "$attempt" "$reviewed" || return 0
877
1083
  else
878
1084
  reviewed="$(cat "$tdir/reviewed.commit")"
879
1085
  fi
880
1086
  review="$tdir/review-$attempt-$$"
881
1087
  forge_review_snapshot "$wt" "$base" "$reviewed" "$review" || { echo ERROR > "$tdir/status"; return 1; }
882
1088
  source_fp="$(forge_fingerprint "$wt")" || return 1
883
- review_fp="$(forge_fingerprint "$review")" || return 1
1089
+ # The review copy is a commit: an untracked file the reviewer leaves there (a test run's
1090
+ # bytecode) changes nothing that merges, so only tracked content counts (#95).
1091
+ review_fp="$(forge_fingerprint "$review" --tracked)" || return 1
884
1092
  echo "$source_fp" > "$tdir/source.fingerprint"
885
1093
  echo "$review_fp" > "$tdir/review.fingerprint"
886
1094
 
887
1095
  forge_metric_phase preparation
888
- local jev_loaded_qa=0 subset_cmd="" qa_thr rs_on=0
1096
+ local qa_thr rs_on=0
889
1097
  qa_thr="$(qa_threshold_for "$PLAN" "$id")"
890
1098
  # Read once per round, like the threshold: continuing the earlier reviewer's session is an
891
1099
  # opt-in experiment (plan --reviewer-session), and a round never changes its mind midway.
892
1100
  [ -f "$PLAN/reviewer_session" ] && rs_on=1
893
1101
 
894
- # A SEPARATE file from .forge/verify, and opt-in. It must contain {files}, because
895
- # only the project knows how its runner takes a file list -- `pytest -q {files}` works,
896
- # `npm test -- {files}` needs the dashes, and `go test ./...` cannot do it at all.
897
- # Absent, this whole feature stays off and nothing extra runs.
898
- [ -s "$REPO/.forge/verify-subset" ] && subset_cmd="$(cat "$REPO/.forge/verify-subset")"
899
- if [ -f "$SKILL_DIR/scripts/forge-jev-options.sh" ]; then
900
- source "$SKILL_DIR/scripts/forge-jev-options.sh" 2>/dev/null && jev_loaded_qa=1
901
- fi
902
- # Early feedback for the reviewer: run the tests this change most likely broke, in a
903
- # throwaway export. Requires a configured verify command -- without one there is no
904
- # runner to point at a file list, and inventing one is not this feature's job.
905
- if [ -n "$subset_cmd" ] && [ "$jev_loaded_qa" = 1 ] && forge_jev_active tests; then
906
- git -C "$wt" diff --name-only "$(cat "$tdir/review.base")" "$reviewed" \
907
- > "$tdir/changed.txt" 2>/dev/null || : > "$tdir/changed.txt"
908
- python3 "$SKILL_DIR/scripts/forge-jev.py" test-subset --repo "$wt" \
909
- --commit "$reviewed" --task "$tdir/prompt.md" --command "$subset_cmd" \
910
- --changed "$tdir/changed.txt" --base "$(cat "$tdir/review.base")" \
911
- --run-dir "$tdir" > "$tdir/subset.jev.txt" 2>/dev/null \
912
- || : > "$tdir/subset.jev.txt"
913
- fi
914
1102
  # Opt-in (plan --fail-first): do this attempt's new tests fail without its change? Read-only
915
- # on the review snapshot, like the subset run above; the reviewer gets the evidence.
1103
+ # on the review snapshot, so the task worktree is untouched; the reviewer gets the evidence.
916
1104
  rm -f "$tdir/failfirst.json" "$tdir/failfirst.txt"
917
1105
  [ ! -f "$PLAN/fail_first" ] || forge_fail_first "$review" "$tdir" "$REPO"
1106
+ # Opt-in (plan --pre-review-tests, #85): the tests this attempt affects, before paying for a
1107
+ # review. Red: the attempt fails unreviewed and its findings are the test output. A QA-only
1108
+ # resume re-reviews work that already passed this check, and keeps its evidence.
1109
+ [ -f "$PLAN/pre_review_tests" ] || rm -f "$tdir/prereview.json" "$tdir/prereview.txt" "$tdir/prereview.md"
1110
+ if [ -f "$PLAN/pre_review_tests" ] && [ -z "$resume" ] && ! forge_pre_review "$review" "$tdir" "$REPO" "$PLAN"; then
1111
+ : > "$tdir/prereview.failed"
1112
+ rm -f "$tdir/qa.last" # an earlier attempt's review describes other code
1113
+ echo FAIL > "$tdir/status"
1114
+ note "$id: the tests this attempt affects fail — sent back to the implementer without a review (see $tdir/prereview.md)"
1115
+ return 0
1116
+ fi
918
1117
  # What changed since the review whose findings this reviewer is handed. Fractal keeps
919
1118
  # today's prompt unless it retries, as changes.prev.diff does. dwarf.last is the reply of
920
1119
  # the attempt under review: a dwarf run just rewrote it, or $resume (the validated QA-only
@@ -933,25 +1132,19 @@ do_task_body() (
933
1132
  else
934
1133
  rm -f "$tdir/changes.since.diff" "$tdir/changes.since.range" "$tdir/changes.since.stat"
935
1134
  fi
1135
+ # A finding sweep's fix task gets the narrow review: one FIXED / NOT FIXED line per finding.
1136
+ local qa_kind=task
1137
+ [ ! -f "$tdir/sweep.json" ] || qa_kind=sweep
936
1138
  # QA uses the dispatch-time ownership and baseline, never later merge state.
937
1139
  /bin/bash "$MEMORY" inject "$REPO" qa --task "$tdir/prompt.md" \
938
1140
  --run-dir "$tdir" > "$tdir/qa.memory"
939
1141
  {
940
- python3 "$SKILL_DIR/scripts/forge-prompt.py" --requirements "$tdir/prompt.md" --capsule "$tdir/baseline.capsule" --approach "$tdir/approach.md" --retry "$tdir/retry_findings.md" ${prompt_extra[@]+"${prompt_extra[@]}"} --memory "$tdir/dwarf.memory" --memory "$tdir/qa.memory"
941
- python3 "$SKILL_DIR/scripts/forge-contract.py" qa --part head --kind task
1142
+ python3 "$SKILL_DIR/scripts/forge-prompt.py" --requirements "$tdir/prompt.md" --capsule "$tdir/baseline.capsule" --approach "$tdir/approach.md" --retry "$tdir/retry_findings.md" --retry-source "$(cat "$tdir/retry_findings.source" 2>/dev/null || echo review)" ${prompt_extra[@]+"${prompt_extra[@]}"} --memory "$tdir/dwarf.memory" --memory "$tdir/qa.memory"
1143
+ python3 "$SKILL_DIR/scripts/forge-contract.py" qa --part head --kind "$qa_kind"
942
1144
  echo
1145
+ [ ! -f "$PLAN/sweep_ahead" ] || python3 "$SKILL_DIR/scripts/forge-sweep.py" ahead "$PLAN" "$id" --role qa 2>/dev/null
943
1146
  if [ -s "$tdir/failfirst.txt" ]; then cat "$tdir/failfirst.txt"; echo; fi
944
- # A subset failure is the one thing a reviewer most wants to know and cannot see
945
- # from the diff. It runs in a throwaway export of the reviewed commit, so the task
946
- # worktree is untouched and no fingerprint can change. It never replaces
947
- # verification -- the full suite still runs at integration exactly as before.
948
- if [ -s "$tdir/subset.jev.txt" ]; then
949
- cat "$tdir/subset.jev.txt"
950
- echo
951
- echo "That is a subset chosen by relevance, not the full suite, so a pass would"
952
- echo "prove nothing and is not reported. A failure here is real."
953
- echo
954
- fi
1147
+ if [ -s "$tdir/prereview.txt" ]; then cat "$tdir/prereview.txt"; echo; fi
955
1148
  if [ -s "$tdir/guard.txt" ]; then
956
1149
  # Facts forge observed about how the implementer worked. On a first attempt the reviewer
957
1150
  # never sees the implementer's own report (a retry's reviewer gets the reply, to check
@@ -971,9 +1164,11 @@ do_task_body() (
971
1164
  echo "matters because another task may own those files."
972
1165
  echo
973
1166
  fi
974
- python3 "$SKILL_DIR/scripts/forge-contract.py" qa --part tail --kind task ${qa_thr:+--threshold "$qa_thr"}
1167
+ python3 "$SKILL_DIR/scripts/forge-contract.py" qa --part tail --kind "$qa_kind" --threshold "$qa_thr"
975
1168
  echo
976
- echo '```diff'; cat "$tdir/changes.diff"; echo '```'
1169
+ # --irreversible-delete: a deleted file shows as a header, not every line it had (one deleted
1170
+ # data directory once made a 7.1M-character prompt that the reviewer's CLI refused).
1171
+ echo '```diff'; git -C "$wt" diff --binary --irreversible-delete "$base" "$reviewed" -- . ':(exclude).forge'; echo '```'
977
1172
  echo; /bin/bash "$MEMORY" note qa
978
1173
  echo "Place any learning notes before the final FORGE_VERDICT: PASS or FORGE_VERDICT: FAIL line."
979
1174
  } > "$tdir/qa.input"
@@ -1046,7 +1241,10 @@ do_task_body() (
1046
1241
  rm -f "$tdir/resume"
1047
1242
 
1048
1243
  forge_metric_phase verification
1049
- if [ "$(forge_fingerprint "$wt")" != "$source_fp" ] || [ "$(forge_fingerprint "$review")" != "$review_fp" ]; then
1244
+ if [ "$(forge_fingerprint "$wt")" != "$source_fp" ] || [ "$(forge_fingerprint "$review" --tracked)" != "$review_fp" ]; then
1245
+ # The committed work is untouched, so --retry-failed may review it again (reason `review`);
1246
+ # the merge-time invalidations below leave no reason and wait for a human.
1247
+ echo review > "$tdir/invalidated.reason"
1050
1248
  echo INVALIDATED > "$tdir/status"; note "$id: artifact changed during review"; return 1
1051
1249
  fi
1052
1250
  local verdict
@@ -1063,43 +1261,11 @@ do_task_body() (
1063
1261
  # pass would merge unreviewed code, so it is fail-safe by construction.
1064
1262
  *) echo UNKNOWN > "$tdir/status" ;;
1065
1263
  esac
1066
- # With an explicit --qa-threshold a FAIL made only of tolerated findings becomes an
1067
- # accepted PASS-with-known-issues. No threshold, no change. qa_thr is the value the review
1068
- # prompt was built with, so the prompt and the gate of one attempt agree.
1264
+ # The gate at the effective threshold: a FAIL made only of tolerated findings becomes an
1265
+ # accepted PASS-with-known-issues, a PASS that lists a blocking CONFIRMED finding becomes
1266
+ # FAIL. qa_thr is the value the review prompt was built with, so the prompt and the gate of
1267
+ # one attempt agree. Before record_attempt, so attempts.tsv shows the gated status.
1069
1268
  qa_gate "$PLAN" "$id" "$tdir" "$verdict" "$qa_thr"
1070
-
1071
- # Annotate a FAIL that looks unsound. Note what this does NOT do: the status file is
1072
- # already written above and nothing below rewrites it. A model that could talk a
1073
- # reviewer out of a FAIL would produce confident PASSes on code nobody checked, which
1074
- # is worth less than having no reviewer at all. Only a human acts on this line.
1075
- if [ "$verdict" = FAIL ] && [ "$(cat "$tdir/status")" = FAIL ]; then
1076
- # do_task is a subshell and does not inherit do_plan's copy, so source it here.
1077
- # A missing or broken options file leaves jev_loaded=0 and this block does nothing.
1078
- local jev_loaded=0 jev_rc
1079
- if [ -f "$SKILL_DIR/scripts/forge-jev-options.sh" ]; then
1080
- source "$SKILL_DIR/scripts/forge-jev-options.sh" 2>/dev/null && jev_loaded=1
1081
- fi
1082
- if [ "$jev_loaded" = 1 ] && forge_jev_active gates; then
1083
- # One request, not two: asking the same question twice costs twice and can come
1084
- # back with two different answers, and the record must match what was printed.
1085
- python3 "$SKILL_DIR/scripts/forge-jev.py" review-triage --review "$tdir/qa.last" \
1086
- --diff "$tdir/changes.diff" --run-dir "$tdir" --json > "$tdir/qa.jev.json" 2>/dev/null
1087
- jev_rc=$?
1088
- if [ "$jev_rc" -eq 0 ]; then
1089
- note "$id: FAIL stands, but jev flags the review — $(python3 -c '
1090
- import json, sys
1091
- try:
1092
- data = json.load(open(sys.argv[1]))
1093
- except Exception:
1094
- sys.exit(0)
1095
- print("; ".join(data.get("reasons") or []))
1096
- ' "$tdir/qa.jev.json" 2>/dev/null)"
1097
- else
1098
- # Exit 1 means the review looked sound; there is nothing to say and no file to keep.
1099
- rm -f "$tdir/qa.jev.json" 2>/dev/null || true
1100
- fi
1101
- fi
1102
- fi
1103
1269
  return 0
1104
1270
  )
1105
1271
 
@@ -1147,6 +1313,8 @@ merge_task() { # merge_task <plan> <id> -> 0 merged, 1 conflicted
1147
1313
  git -C "$int_wt" rev-parse HEAD > "$PLAN/accepted.integration"
1148
1314
  touch "$PLAN/tasks/$id/merged"
1149
1315
  rm -f "$tdir/conflict.files"
1316
+ # Which of a sweep task's findings its reviewer marked fixed: what `forge issues` leaves out.
1317
+ [ ! -f "$tdir/sweep.json" ] || python3 "$SKILL_DIR/scripts/forge-sweep.py" settle "$PLAN" "$id" >/dev/null 2>&1 || true
1150
1318
  forge_dataset_event merge --dir "$PLAN" --task "$id" --set status=MERGED --set commit="$reviewed" \
1151
1319
  --set integration="$(cat "$PLAN/accepted.integration")"
1152
1320
  return 0
@@ -1162,17 +1330,86 @@ merge_task() { # merge_task <plan> <id> -> 0 merged, 1 conflicted
1162
1330
  }
1163
1331
 
1164
1332
  # --- retry --------------------------------------------------------------------
1333
+ # The answer arguments of `retry`, found by walking the option list as do_retry's own loop does,
1334
+ # so the value of another option (--setup '--answer') is never mistaken for one. Run it in a
1335
+ # subshell with a scratch directory as the plan: the shared option parsers write into it, not
1336
+ # into the real plan. Leaves n (how many answer flags), flag, val and novalue in the scratch dir.
1337
+ _retry_answer_scan() { # _retry_answer_scan <scratch-dir> <retry args...>
1338
+ local sd="$1"; shift
1339
+ local n=0 flag="" val="" novalue=0 rc=0
1340
+ while [ $# -gt 0 ]; do
1341
+ case "$1" in
1342
+ --no-ripwire|--yolo-dwarf|--yolo-qa) shift ;;
1343
+ --output|--dwarf|--verify|--setup) [ $# -ge 2 ] || break; shift 2 ;;
1344
+ --answer|--answer-file)
1345
+ n=$((n + 1)); flag="$1"
1346
+ if [ $# -ge 2 ]; then val="$2"; shift 2; else novalue=1; shift; fi ;;
1347
+ *)
1348
+ if forge_pp_flag retry "$sd" "$@"; then shift "$PP_SHIFT"; continue; fi
1349
+ if [ "${JEV_OPTS:-0}" = 1 ]; then
1350
+ forge_jev_flag "$@"; rc=$?
1351
+ case "$rc" in
1352
+ 0) shift "$JEV_SHIFT"; continue ;;
1353
+ 2) exit 2 ;;
1354
+ esac
1355
+ fi
1356
+ break ;;
1357
+ esac
1358
+ done
1359
+ printf '%s' "$n" > "$sd/n"; printf '%s' "$flag" > "$sd/flag"; printf '%s' "$val" > "$sd/val"
1360
+ [ "$novalue" = 0 ] || : > "$sd/novalue"
1361
+ }
1362
+
1165
1363
  # A failed task keeps its branch and worktree "so there is something to inspect and
1166
1364
  # retry from" — this is the retry. It is a command a human types, not an automatic
1167
1365
  # repair loop, which is what keeps forge's one-dwarf-then-QA rule intact.
1168
1366
  do_retry() {
1169
1367
  local PLAN="${1:?retry needs a plan dir}" id="${2:?retry needs a task id}"; shift 2
1170
- local NEWDWARF="" jev_rc=0
1368
+ FORGE_RUN_STARTED="$(forge_now)"
1369
+ local NEWDWARF="" jev_rc=0 ANSWER="" ANSWER_FILE="" HAVE_ANSWER=0
1370
+ # An answer is validated before any option below writes into the plan: a rejected answer
1371
+ # changes nothing, --setup and --verify included. Only a NEEDS_INPUT task takes one. The
1372
+ # arguments are walked the way the loop below walks them (a value is never taken for a flag),
1373
+ # in a subshell against a scratch plan dir, so nothing real is written by the walk.
1374
+ local pre_dir="$PLAN/.answer-scan.$$" pre_n=0 pre_have="" pre_val="" pre_novalue=0 pre_ok=0
1375
+ rm -rf "$pre_dir"
1376
+ if mkdir "$pre_dir" 2>/dev/null; then
1377
+ if ( _retry_answer_scan "$pre_dir" "$@" ) >/dev/null 2>&1; then
1378
+ pre_ok=1
1379
+ pre_n="$(<"$pre_dir/n")"; pre_have="$(<"$pre_dir/flag")"; pre_val="$(<"$pre_dir/val")"
1380
+ [ ! -f "$pre_dir/novalue" ] || pre_novalue=1
1381
+ # `$(<f)` drops trailing newlines, so an answer of only newlines needs the size check.
1382
+ [ -s "$pre_dir/val" ] || pre_val=""
1383
+ fi
1384
+ rm -rf "$pre_dir"
1385
+ else
1386
+ die "retry: cannot write to the plan dir $PLAN"
1387
+ fi
1388
+ if [ "$pre_ok" = 1 ] && [ "$pre_n" != 0 ]; then
1389
+ [ "$pre_n" = 1 ] || die "retry: give --answer or --answer-file once"
1390
+ [ "$pre_novalue" = 0 ] || die "retry: $pre_have needs a value"
1391
+ [ -s "$PLAN/tasks.tsv" ] && all_ids "$PLAN/tasks.tsv" | grep -qx "$id" || die "no task '$id' in this plan"
1392
+ local pre_st; pre_st="$(task_status "$PLAN" "$id")"
1393
+ [ "$pre_st" = NEEDS_INPUT ] || die "retry: '$id' is $pre_st, not waiting for an answer; --answer and --answer-file only answer a NEEDS_INPUT task"
1394
+ if [ "$pre_have" = --answer-file ]; then
1395
+ [ -f "$pre_val" ] && [ -r "$pre_val" ] || die "retry: --answer-file '$pre_val' is not a readable file"
1396
+ [ -s "$pre_val" ] || die "retry: --answer-file '$pre_val' is empty"
1397
+ else
1398
+ [ -n "$pre_val" ] || die "retry: the answer is empty"
1399
+ fi
1400
+ fi
1171
1401
  while [ $# -gt 0 ]; do
1172
1402
  case "$1" in
1173
1403
  --no-ripwire) export FORGE_RIPWIRE=off; shift ;;
1174
1404
  --output) OUTPUT="${2:?}"; shift 2 ;;
1175
1405
  --dwarf) NEWDWARF="${2:?--dwarf needs a spec}"; shift 2 ;;
1406
+ # The check above refuses an empty answer first; these hold when its walk could not run.
1407
+ --answer) [ "$HAVE_ANSWER" = 0 ] || die "retry: give --answer or --answer-file once"
1408
+ ANSWER="${2?--answer needs the answer text}"; HAVE_ANSWER=1; shift 2
1409
+ [ -n "$ANSWER" ] || die "retry: the answer is empty" ;;
1410
+ --answer-file) [ "$HAVE_ANSWER" = 0 ] || die "retry: give --answer or --answer-file once"
1411
+ ANSWER_FILE="${2:?--answer-file needs a file}"; HAVE_ANSWER=2; shift 2
1412
+ [ -s "$ANSWER_FILE" ] || die "retry: --answer-file '$ANSWER_FILE' is empty or missing" ;;
1176
1413
  --yolo-dwarf) touch "$PLAN/yolo_dwarf"; shift ;;
1177
1414
  --yolo-qa) touch "$PLAN/yolo_qa"; shift ;;
1178
1415
  --verify) printf '%s' "${2:?--verify needs a command}" > "$PLAN/verify_cmd"; rm -rf "$PLAN/verify.d"; PP_LANES_FRESH=0; shift 2 ;;
@@ -1181,7 +1418,7 @@ do_retry() {
1181
1418
  # `case` is not a loop, so `continue` here belongs to the enclosing while.
1182
1419
  if forge_pp_flag retry "$PLAN" "$@"; then shift "$PP_SHIFT"; continue; fi
1183
1420
  if [ "$JEV_OPTS" = 1 ]; then
1184
- forge_jev_flag "$1"; jev_rc=$?
1421
+ forge_jev_flag "$@"; jev_rc=$?
1185
1422
  case "$jev_rc" in
1186
1423
  0) shift "$JEV_SHIFT"; continue ;;
1187
1424
  2) exit 2 ;;
@@ -1192,6 +1429,8 @@ do_retry() {
1192
1429
  esac
1193
1430
  done
1194
1431
  [ "$JEV_OPTS" = 1 ] && forge_jev_settle "$PLAN"
1432
+ # Before any decision-model step: the privacy floor and the run budget read these.
1433
+ [ "$JEV_OPTS" = 1 ] && [ -s "$PLAN/repo" ] && forge_decide_env "$(cat "$PLAN/repo")" "$PLAN"
1195
1434
  case "$OUTPUT" in summary|full) ;; *) die "--output must be summary or full" ;; esac
1196
1435
  export FORGE_OUTPUT="$OUTPUT"
1197
1436
  local T="$PLAN/tasks.tsv" tdir="$PLAN/tasks/$id"
@@ -1200,6 +1439,18 @@ do_retry() {
1200
1439
  [ -s "$PLAN/wt_root" ] || die "this plan has never been run — use 'run', not 'retry'"
1201
1440
  local st; st="$(task_status "$PLAN" "$id")"
1202
1441
  [ "$st" = "MERGED" ] && die "task '$id' already merged — nothing to retry"
1442
+ [ "$HAVE_ANSWER" = 0 ] || [ "$st" = NEEDS_INPUT ] || die "retry: '$id' is $st, not waiting for an answer; --answer and --answer-file only answer a NEEDS_INPUT task"
1443
+ # The user's answer to a NEEDS_INPUT task's question (validated above): written before
1444
+ # anything else is prepared, atomically, and kept when the preparation then refuses (the
1445
+ # same answer can be retried).
1446
+ if [ "$HAVE_ANSWER" != 0 ]; then
1447
+ if [ "$HAVE_ANSWER" = 2 ]; then
1448
+ cp "$ANSWER_FILE" "$tdir/.answer.md.tmp" || { rm -f "$tdir/.answer.md.tmp"; die "retry: could not write the answer" 1; }
1449
+ else
1450
+ printf '%s\n' "$ANSWER" > "$tdir/.answer.md.tmp" || { rm -f "$tdir/.answer.md.tmp"; die "retry: could not write the answer" 1; }
1451
+ fi
1452
+ mv "$tdir/.answer.md.tmp" "$tdir/answer.md" || die "retry: could not write the answer" 1
1453
+ fi
1203
1454
 
1204
1455
  # Findings carry-forward, the optional --dwarf escalation and the QA-only resume
1205
1456
  # decision are shared with the scheduler's automatic retries.
@@ -1246,42 +1497,11 @@ do_retry() {
1246
1497
  echo
1247
1498
  printf ' %-14s %-9s %s\n' id status branch
1248
1499
  awk -F'\t' '{printf " %-14s %-9s %s\n", $1, $2, $3}' "$PLAN/results.tsv"
1249
- forge_jev_review_flags "$PLAN"
1250
1500
  run_report_extras "$PLAN"
1251
1501
  [ "$(task_status "$PLAN" "$id")" = "MERGED" ] || return 5
1252
1502
  return 0
1253
1503
  }
1254
1504
 
1255
- # Print any Jev review-triage flags under the results table.
1256
- #
1257
- # do_task's notes go to tasks/<id>/task.out, which the scheduler only echoes when
1258
- # FORGE_OUTPUT=full -- the right call for parallel dispatch, where interleaved output is
1259
- # unreadable. But it meant this particular note was written where nobody would read it,
1260
- # and it is the only signal that a FAIL may not be sound. A human has to see it to act
1261
- # on it, and the default output mode is `summary`.
1262
- #
1263
- # qa.jev.json exists only when the review was flagged: review-triage deletes it when the
1264
- # review looks sound, so its presence is the signal and no new file is needed.
1265
- forge_jev_review_flags() {
1266
- local plan="$1" id notice printed=0
1267
- for id in $(all_ids "$plan/tasks.tsv"); do
1268
- [ -s "$plan/tasks/$id/qa.jev.json" ] || continue
1269
- notice="$(python3 -c '
1270
- import json, sys
1271
- try:
1272
- data = json.load(open(sys.argv[1]))
1273
- except Exception:
1274
- sys.exit(0)
1275
- print("; ".join(data.get("reasons") or []))
1276
- ' "$plan/tasks/$id/qa.jev.json" 2>/dev/null)"
1277
- [ -n "$notice" ] || continue
1278
- [ "$printed" = 0 ] && { echo; printed=1; }
1279
- printf ' jev: %s — the FAIL stands; %s\n' "$id" "$notice"
1280
- done
1281
- [ "$printed" = 1 ] && printf ' A flagged review is not an overturned one. Read it before retrying.\n'
1282
- return 0
1283
- }
1284
-
1285
1505
  # One row per execution of the verify command, with its own copy of the log: the
1286
1506
  # deterministic rerun and Jev's retry both write verification.retry.log, so without this
1287
1507
  # only the last of them would survive.
@@ -1375,12 +1595,16 @@ verify_stopped() { # verify_stopped <out>
1375
1595
  verify_mark_interrupted "$1"
1376
1596
  }
1377
1597
 
1378
- verify_result() ( verify_result_body "$@" ) # plan, checkout, artifact directory
1598
+ verify_result() ( verify_result_body "$@" ) # plan, checkout, artifact directory[, fixed source]
1379
1599
 
1380
1600
  # The body is a function of its own so `run` can start it as `( verify_result_body ... ) &`:
1381
1601
  # that one subshell is the background job, the home of the signal handler above and of
1382
1602
  # forge_metric_begin's EXIT trap.
1383
- verify_result_body() { # plan, checkout, artifact directory
1603
+ # An optional fourth argument fixes the verification: "command:<file>" or "lanes:<dir>" (a
1604
+ # finished verification's verification.command or verification.lanes.d/). It replaces
1605
+ # verify_source_for and verify-discover, so a re-run judges by the predicate that verification
1606
+ # used, whatever the plan, the repository or discovery would say now.
1607
+ verify_result_body() { # plan, checkout, artifact directory[, fixed source]
1384
1608
  local plan="$1" wt="$2" out="$3" cmd="" before after rc=0 repo jev_loaded=0 vretries
1385
1609
  FORGE_VERIFY_STOP=0 FORGE_VERIFY_GROUP="" FORGE_VERIFY_TIMER="" FORGE_VERIFY_GRACE=5
1386
1610
  [ "${FORGE_RUN_STOPPABLE:-0}" = 1 ] && trap verify_signal TERM INT
@@ -1400,23 +1624,38 @@ verify_result_body() { # plan, checkout, artifact directory
1400
1624
  vretries="$(cat "$plan/verify_retries" 2>/dev/null)"
1401
1625
  case "$vretries" in ''|*[!0-9]*) vretries=1 ;; esac
1402
1626
  # Sourced unconditionally (cheap: local function/var definitions, no network) so
1403
- # forge_jev_active is available below. verify_result is itself a subshell, so this
1627
+ # forge_decide_active is available below. verify_result is itself a subshell, so this
1404
1628
  # never leaks state into the caller. A missing or broken options file just leaves
1405
1629
  # jev_loaded=0 and every Jev branch below falls through to today's behaviour.
1406
1630
  if [ -f "$SKILL_DIR/scripts/forge-jev-options.sh" ]; then
1407
1631
  source "$SKILL_DIR/scripts/forge-jev-options.sh" 2>/dev/null && jev_loaded=1
1408
1632
  fi
1409
- local vsource; vsource="$(verify_source_for "$plan" "$repo")"
1633
+ local vsource fixed="${4:-}"
1634
+ if [ -n "$fixed" ]; then
1635
+ vsource="$(verify_fixed_source "$fixed")" || { echo UNVERIFIED > "$out/verification.status"
1636
+ note "combined result UNVERIFIED: unusable fixed verification source: $fixed"; return 0; }
1637
+ # A fixed source that is missing or empty is not a reason to look elsewhere.
1638
+ case "$vsource" in
1639
+ lanes:*) verify_lanes_present "${vsource#*$'\t'}" || vsource="none" ;;
1640
+ *) [ -s "${vsource#*$'\t'}" ] || vsource="none" ;;
1641
+ esac
1642
+ if [ "$vsource" = none ]; then
1643
+ echo UNVERIFIED > "$out/verification.status"
1644
+ note "combined result UNVERIFIED: the fixed verification source $fixed is missing or empty"; return 0
1645
+ fi
1646
+ else
1647
+ vsource="$(verify_source_for "$plan" "$repo")"
1648
+ fi
1410
1649
  case "$vsource" in command:*) cmd="$(cat "${vsource#*$'\t'}")" ;; esac
1650
+ # A lanes snapshot belongs to the verification that wrote it: a run on a command, or on
1651
+ # other lanes, leaves none behind (verify_lanes_run makes the new one).
1652
+ case "$vsource" in lanes:*) ;; *) rm -rf "$out/verification.lanes.d" ;; esac
1411
1653
  if [ "$(forge_tree "$wt")" != "$(git -C "$wt" rev-parse HEAD^{tree})" ]; then
1412
1654
  echo FAIL > "$out/verification.status"
1413
1655
  note "verification checkout has source changes outside its commit"; return 1
1414
1656
  fi
1415
1657
  case "$vsource" in
1416
1658
  lanes:*)
1417
- if [ "$jev_loaded" = 1 ] && forge_jev_active tests; then
1418
- note "jev: flake triage applies to a single verify command; lanes rerun their own failures"
1419
- fi
1420
1659
  verify_lanes_run "$plan" "$wt" "$out" "${vsource#*$'\t'}" "$vretries"
1421
1660
  return $? ;;
1422
1661
  esac
@@ -1425,8 +1664,8 @@ verify_result_body() { # plan, checkout, artifact directory
1425
1664
  # produced — any non-zero exit (no key, disabled, nothing suitable, a traceback)
1426
1665
  # falls straight through to the exact UNVERIFIED behaviour below. A Jev failure
1427
1666
  # must never change the outcome of a run.
1428
- if [ -z "$cmd" ] && [ "$jev_loaded" = 1 ] && forge_jev_active tests; then
1429
- local jev_json jev_rc jev_cmd
1667
+ if [ -z "$cmd" ] && [ -z "$fixed" ] && [ "$jev_loaded" = 1 ] && forge_decide_active verify-discover; then
1668
+ local jev_json jev_rc jev_cmd jev_note
1430
1669
  # --json rather than the bare form: the record exists so a human can audit why a
1431
1670
  # command ran, and "confidence: null" answers nothing. The exit code still decides.
1432
1671
  jev_json="$(python3 "$SKILL_DIR/scripts/forge-jev.py" verify-discover --repo "$repo" --json --run-dir "$out" 2>/dev/null)"
@@ -1443,9 +1682,22 @@ except ValueError:
1443
1682
  fi
1444
1683
  if [ -n "$jev_cmd" ]; then
1445
1684
  cmd="$jev_cmd"
1685
+ # Coverage (#42): the pick's evidence names fewer languages than the repo has. The
1686
+ # pick stands and its run still decides; only the announcement says so.
1687
+ jev_note="$(printf '%s' "$jev_json" | python3 -c '
1688
+ import json, sys
1689
+ try:
1690
+ coverage = (json.load(sys.stdin) or {}).get("coverage") or {}
1691
+ except ValueError:
1692
+ coverage = {}
1693
+ covered = coverage.get("covered") or []
1694
+ missing = [language for language in coverage.get("present") or [] if language not in covered]
1695
+ if covered and missing:
1696
+ print(" — it may cover only part of the repo (covers %s; the repo also has %s)" % (", ".join(covered), ", ".join(missing)))
1697
+ ' 2>/dev/null)"
1446
1698
  # Loud on purpose: an unreviewed command is about to run on the user's behalf,
1447
1699
  # and they must never discover that later from a log instead of right here.
1448
- note "jev chose a verification command (no --verify or .forge/verify configured): $cmd"
1700
+ note "jev chose a verification command (no --verify or .forge/verify configured): $cmd$jev_note"
1449
1701
  printf '%s' "$jev_json" | python3 -c '
1450
1702
  import json, sys
1451
1703
  out = sys.argv[1]
@@ -1476,11 +1728,10 @@ with open(out + "/verification.jev.json", "w") as fh:
1476
1728
  verify_stopped "$out" && return 130
1477
1729
  echo "$before" > "$out/verification.fingerprint"
1478
1730
  if [ "$rc" != 0 ] || [ "$before" != "$after" ]; then
1479
- local flaked=0 det_retried=0 n_retry=0 rc3 b3 a3
1480
- # Deterministic rerun first: the rerun itself is the evidence, so unlike Jev's triage
1481
- # below it needs no model and no recorded trap. A tree change is never retried.
1731
+ local flaked=0 n_retry=0 rc3 b3 a3
1732
+ # The rerun itself is the evidence: it needs no model and no recorded trap. A tree
1733
+ # change is never retried.
1482
1734
  if [ "$rc" != 0 ] && [ "$before" = "$after" ] && [ "$vretries" -gt 0 ]; then
1483
- det_retried=1
1484
1735
  while [ "$n_retry" -lt "$vretries" ] && [ "$flaked" = 0 ]; do
1485
1736
  n_retry=$((n_retry+1)); rc3=0
1486
1737
  note "verification failed (exit $rc); rerunning to tell a flaky lane from a regression ($n_retry/$vretries)"
@@ -1502,96 +1753,6 @@ with open(out + "/verification.jev.json", "w") as fh:
1502
1753
  fi
1503
1754
  done
1504
1755
  fi
1505
- # A tree change is never a flake — it stays FAIL immediately, no triage. Beyond
1506
- # that, act on a "known_flake" verdict ONLY when Forge's own memory already
1507
- # records a `trap` for this repo: a model alone deciding a failure was a flake
1508
- # is exactly how a real regression ships, so the verdict needs corroboration
1509
- # from Forge's own records, not just the model's word.
1510
- if [ "$rc" != 0 ] && [ "$before" = "$after" ] && [ "$jev_loaded" = 1 ] \
1511
- && [ "$det_retried" = 0 ] \
1512
- && forge_jev_active tests \
1513
- && [ -s "$repo/.forge/memory.md" ] \
1514
- && awk '/^## Known traps$/{f=1;next} /^## /{f=0} f && NF{c++} END{exit !(c>0)}' "$repo/.forge/memory.md"
1515
- then
1516
- local triage_json triage_rc verdict="" confidence="" flake_act="0.90" parsed corroborated=0 retried=0 rc2="" before2 after2
1517
- triage_json="$(python3 "$SKILL_DIR/scripts/forge-jev.py" verify-triage --repo "$repo" \
1518
- --command "$cmd" --log "$out/verification.log" --json --run-dir "$out" 2>/dev/null)"
1519
- triage_rc=$?
1520
- if [ "$triage_rc" -eq 0 ] && [ -n "$triage_json" ]; then
1521
- parsed="$(printf '%s' "$triage_json" | python3 -c '
1522
- import json, sys
1523
- try:
1524
- data = json.load(sys.stdin)
1525
- except ValueError:
1526
- data = {}
1527
- print(data.get("verdict") or "")
1528
- c = data.get("confidence")
1529
- print(c if c is not None else "")
1530
- print(bool(data.get("corroborated")))
1531
- ' 2>/dev/null)"
1532
- verdict="$(printf '%s\n' "$parsed" | sed -n 1p)"
1533
- confidence="$(printf '%s\n' "$parsed" | sed -n 2p)"
1534
- # triage() reports whether a recorded trap shares a distinctive token with this
1535
- # failure's output. Without that, one flaky test noted months ago would excuse
1536
- # every future failure in the repo.
1537
- [ "$(printf '%s\n' "$parsed" | sed -n 3p)" = "True" ] && corroborated=1 || corroborated=0
1538
- if [ -n "$FORGE_JEV_STATUS_JSON" ]; then
1539
- local threshold_read
1540
- threshold_read="$(printf '%s' "$FORGE_JEV_STATUS_JSON" | python3 -c '
1541
- import json, sys
1542
- try:
1543
- data = json.load(sys.stdin)
1544
- except ValueError:
1545
- data = {}
1546
- v = (data.get("thresholds") or {}).get("flake_act")
1547
- print(v if v is not None else "0.90")
1548
- ' 2>/dev/null)"
1549
- [ -n "$threshold_read" ] && flake_act="$threshold_read"
1550
- fi
1551
- if [ "$verdict" = known_flake ] && [ -n "$confidence" ] && [ "$corroborated" = 1 ] \
1552
- && awk -v a="$confidence" -v b="$flake_act" 'BEGIN{exit !(a+0 >= b+0)}'
1553
- then
1554
- retried=1
1555
- note "jev: known_flake (confidence $confidence >= $flake_act), corroborated by a recorded trap — retrying once"
1556
- before2="$(forge_fingerprint "$wt")" || return 1
1557
- vt0="$(date +%s)"
1558
- verify_stopped "$out" && return 130
1559
- verify_exec "$wt" "$cmd" "$out/verification.retry.log" || rc2=$?
1560
- rc2="${rc2:-0}"
1561
- after2="$(forge_fingerprint "$wt")" || { verify_stopped "$out" && return 130; return 1; }
1562
- verify_run_note "$out" jev_retry "$rc2" "$before2" "$after2" verification.retry.log "$vt0"
1563
- verify_stopped "$out" && return 130
1564
- if [ "$rc2" = 0 ] && [ "$before2" = "$after2" ]; then
1565
- flaked=1
1566
- note "jev: retry passed — treating as a corroborated flake, not a regression"
1567
- else
1568
- note "jev: retry also failed (exit $rc2) — keeping FAIL"
1569
- fi
1570
- fi
1571
- python3 -c '
1572
- import json, sys
1573
- out, verdict, confidence, threshold, corroborated, retried, first_rc, retry_rc = sys.argv[1:9]
1574
- path = out + "/verification.jev.json"
1575
- try:
1576
- with open(path) as fh:
1577
- data = json.load(fh)
1578
- except (OSError, ValueError):
1579
- data = {}
1580
- data["triage"] = {
1581
- "verdict": verdict or None,
1582
- "confidence": float(confidence) if confidence else None,
1583
- "flake_act_threshold": float(threshold),
1584
- "trap_corroboration": corroborated == "1",
1585
- "retried": retried == "1",
1586
- "first_exit": int(first_rc),
1587
- "retry_exit": int(retry_rc) if retry_rc != "" else None,
1588
- }
1589
- with open(path, "w") as fh:
1590
- json.dump(data, fh, indent=2, sort_keys=True)
1591
- fh.write("\n")
1592
- ' "$out" "$verdict" "$confidence" "$flake_act" "$corroborated" "$retried" "$rc" "$rc2" 2>/dev/null || true
1593
- fi
1594
- fi
1595
1756
  if [ "$flaked" = 1 ]; then
1596
1757
  echo PASS > "$out/verification.status"
1597
1758
  return 0
@@ -1646,6 +1807,7 @@ do_run() {
1646
1807
  FORGE_RUN_STOPPABLE=1
1647
1808
  trap run_signal TERM INT
1648
1809
  local PLAN="${1:?run needs a plan dir}"; shift
1810
+ FORGE_RUN_STARTED="$(forge_now)" # the summary's overridden verdicts are this run's
1649
1811
  local fractal_pipeline_args=("$@")
1650
1812
  local MAXP=3 DRY=0 jev_rc=0 FORECAST=1
1651
1813
  while [ $# -gt 0 ]; do
@@ -1667,7 +1829,7 @@ do_run() {
1667
1829
  # `case` is not a loop, so `continue` here belongs to the enclosing while.
1668
1830
  if forge_pp_flag run "$PLAN" "$@"; then shift "$PP_SHIFT"; continue; fi
1669
1831
  if [ "$JEV_OPTS" = 1 ]; then
1670
- forge_jev_flag "$1"; jev_rc=$?
1832
+ forge_jev_flag "$@"; jev_rc=$?
1671
1833
  case "$jev_rc" in
1672
1834
  0) shift "$JEV_SHIFT"; continue ;;
1673
1835
  2) exit 2 ;;
@@ -1678,6 +1840,7 @@ do_run() {
1678
1840
  esac
1679
1841
  done
1680
1842
  [ "$JEV_OPTS" = 1 ] && forge_jev_settle "$PLAN"
1843
+ [ -n "$PP_SWEEP" ] || [ "$PP_SWEEP_PLAUSIBLE$PP_SWEEP_MAX_SET" = 00 ] || die "--sweep-plausible and --sweep-max go with --sweep"
1681
1844
  case "$OUTPUT" in summary|full) ;; *) die "--output must be summary or full" ;; esac
1682
1845
  export FORGE_OUTPUT="$OUTPUT"
1683
1846
  case "$MAXP" in ''|*[!0-9]*) die "--max-parallel must be positive" ;; esac
@@ -1689,6 +1852,8 @@ do_run() {
1689
1852
  compute_waves "$PLAN"
1690
1853
  local REPO run_id wt_root int_wt int_br
1691
1854
  REPO="$(cat "$PLAN/repo")"; run_id="$(cat "$PLAN/run_id")"
1855
+ # Before any decision-model step: the privacy floor and the run budget read these.
1856
+ [ "$JEV_OPTS" = 1 ] && forge_decide_env "$REPO" "$PLAN"
1692
1857
  if [ "$DRY" != 1 ]; then
1693
1858
  # The concurrency limit this run was given, for forge-ui to draw; a later run rewrites it.
1694
1859
  printf '%s\n' "$MAXP" > "$PLAN/max_parallel"
@@ -1723,6 +1888,7 @@ do_run() {
1723
1888
  [ "${FORGE_RIPWIRE:-}" != off ] || touch "$PLAN/no_ripwire"
1724
1889
  [ ! -f "$PLAN/no_ripwire" ] || export FORGE_RIPWIRE=off
1725
1890
  preflight_plan "$PLAN" || return $?
1891
+ [ -z "$PP_SWEEP" ] || sweep_preflight "$PLAN" || return $?
1726
1892
  /bin/bash "$SKILL_DIR/scripts/forge-install-ripwire.sh" || true
1727
1893
  forge_metric_phase preparation
1728
1894
  mkdir -p "$wt_root"
@@ -1763,6 +1929,8 @@ do_run() {
1763
1929
  local sched_rc=0 paused=0 sched_args=()
1764
1930
  [ "$PP_RETRY_FAILED" -gt 0 ] && sched_args+=(--retry-failed "$PP_RETRY_FAILED")
1765
1931
  [ "$PP_INFRA_RETRIES" -gt 0 ] && sched_args+=(--infra-retries "$PP_INFRA_RETRIES")
1932
+ [ -n "$PP_SWEEP" ] && sched_args+=(--sweep "$PP_SWEEP" --sweep-max "$PP_SWEEP_MAX")
1933
+ [ "$PP_SWEEP_PLAUSIBLE" = 1 ] && sched_args+=(--sweep-plausible)
1766
1934
  forge_metric_phase dispatch
1767
1935
  # In the background so a signal to this shell ends the wait; the scheduler gets it as TERM,
1768
1936
  # stops its tasks and returns 130.
@@ -1811,9 +1979,13 @@ do_run() {
1811
1979
  echo "artifacts: $PLAN/tasks/<id>/{dwarf,qa}.{last,log}; results: $PLAN/results.tsv"
1812
1980
  printf ' %-14s %-9s %s\n' id status branch
1813
1981
  awk -F'\t' '{printf " %-14s %-9s %s\n", $1, $2, $3}' "$PLAN/results.tsv"
1814
- forge_jev_review_flags "$PLAN"
1815
1982
  echo
1816
1983
  run_report_extras "$PLAN"
1984
+ # Pre-review tests (#85): every check of the plan, and the reviews the red ones saved.
1985
+ local pre_review
1986
+ pre_review="$(cat "$PLAN"/tasks/*/prereview.log 2>/dev/null | awk -F'\t' 'NF >= 3 { n++; if ($2 == "failed") f++; s += $3 }
1987
+ END { if (n) printf "pre-review tests: %d check(s), %d attempt(s) sent back without a review, %ds of test time\n", n, f, s }')"
1988
+ [ -z "$pre_review" ] || { echo "$pre_review"; echo; }
1817
1989
 
1818
1990
  # Undeclared files are reported here rather than buried in a task log, because
1819
1991
  # this is the list that explains any CONFLICT above.
@@ -1838,10 +2010,21 @@ do_run() {
1838
2010
  for id in $stopped_ids; do echo " forge-parallel.sh retry $PLAN $id"; done
1839
2011
  fi
1840
2012
  [ "$interrupted" = 1 ] || [ -n "$stopped_ids" ] && echo
2013
+ # Tasks stopped for the user's answer: the question as it was asked, and the command that
2014
+ # answers it. Not failures, so the retry hint below does not count them.
2015
+ local waiting; waiting="$(awk -F'\t' '$2=="NEEDS_INPUT" {print $1}' "$PLAN/results.tsv")"
2016
+ if [ -n "$waiting" ]; then
2017
+ echo "waiting for your answer:"
2018
+ for id in $waiting; do
2019
+ printf ' %s: %s\n' "$id" "$(awk 'NF { print substr($0, 1, 120); exit }' "$PLAN/tasks/$id/needs_input.md" 2>/dev/null)"
2020
+ echo " answer with: forge-parallel.sh retry $PLAN $id --answer \"<text>\""
2021
+ done
2022
+ echo
2023
+ fi
1841
2024
  # The retry hint is for tasks that actually failed; a run that only failed verification,
1842
2025
  # or only paused on infrastructure, has nothing to retry task by task. An interrupted task
1843
- # has its own hint above.
1844
- if [ "$(awk -F'\t' '$2!="MERGED" && $2!="INFRA" && $2!="PENDING" && $2!="BLOCKED" && $2!="INTERRUPTED" {n++} END {print n+0}' "$PLAN/results.tsv")" -gt 0 ]; then
2026
+ # has its own hint above, a task waiting for an answer its own block.
2027
+ if [ "$(awk -F'\t' '$2!="MERGED" && $2!="INFRA" && $2!="PENDING" && $2!="BLOCKED" && $2!="INTERRUPTED" && $2!="NEEDS_INPUT" {n++} END {print n+0}' "$PLAN/results.tsv")" -gt 0 ]; then
1845
2028
  echo "retry a failed task with its reviewer's findings:"
1846
2029
  echo " forge-parallel.sh retry $PLAN <task-id> [--dwarf <spec>]"
1847
2030
  echo "or let a run retry them itself: forge-parallel.sh run $PLAN --retry-failed 1"
@@ -1850,6 +2033,20 @@ do_run() {
1850
2033
  if [ "$failed" = 1 ] && [ "$paused" = 0 ] && [ "$interrupted" = 0 ] && [ "$(cat "$PLAN/verification.status" 2>/dev/null)" = FAIL ]; then
1851
2034
  echo "combined verification failed: see $PLAN/verification.log"
1852
2035
  echo
2036
+ if [ -f "$PLAN/attribute_on" ] && declare -F attribute_search >/dev/null; then
2037
+ # This run holds the plan lock: the search function, never the subcommand.
2038
+ run_phase=attribute
2039
+ ( attribute_search "$PLAN" 0 ) <&0 &
2040
+ run_child=$!
2041
+ [ "$run_stop" = 1 ] && kill -TERM "$run_child" 2>/dev/null
2042
+ run_wait "$run_child"
2043
+ run_child=""
2044
+ [ "$run_stop" = 1 ] && interrupted=1
2045
+ echo
2046
+ else
2047
+ echo "find a merge that broke it: forge-parallel.sh attribute $PLAN"
2048
+ echo
2049
+ fi
1853
2050
  fi
1854
2051
 
1855
2052
  if [ ! -f "$PLAN/no_memory" ]; then
@@ -1932,7 +2129,7 @@ if [ "${1:-}" = --help ] || [ "${1:-}" = -h ]; then
1932
2129
  forge_fractal_help
1933
2130
  exit 0
1934
2131
  fi
1935
- [ $# -ge 1 ] || die "usage: forge-parallel.sh <plan|run|retry|accept|review|integrate|split|combine> <plan-dir> [...]"
2132
+ [ $# -ge 1 ] || die "usage: forge-parallel.sh <plan|run|retry|accept|review|integrate|split|attribute|combine> <plan-dir> [...]"
1936
2133
  CMD="$1"; shift
1937
2134
  [ ! -f "${1:-}/no_ripwire" ] || export FORGE_RIPWIRE=off
1938
2135
  if [ -d "${1:-}" ]; then
@@ -1940,7 +2137,7 @@ if [ -d "${1:-}" ]; then
1940
2137
  fi
1941
2138
  case "$CMD" in
1942
2139
  # `combine` takes a plan dir that does not exist yet and locks its sources itself.
1943
- run|retry|integrate|accept|review|split)
2140
+ run|retry|integrate|accept|review|split|attribute)
1944
2141
  if [ "${FORGE_PLAN_LOCK:-}" != "${1:-}" ]; then
1945
2142
  exec python3 "$SKILL_DIR/scripts/forge-schedule.py" lock "$SELF" "$CMD" "$@"
1946
2143
  fi ;;
@@ -1949,7 +2146,7 @@ esac
1949
2146
  # path (die included). Installed after the lock re-exec, so it fires once, in the process
1950
2147
  # that did the work; `_task` and `_merge` are parts of a `run` and are not recorded alone.
1951
2148
  case "$CMD" in
1952
- plan|run|retry|integrate|accept|review|split|combine)
2149
+ plan|run|retry|integrate|accept|review|split|attribute|combine)
1953
2150
  FORGE_DATASET_INVOCATION="inv-$(date +%s)-$$-$RANDOM"; export FORGE_DATASET_INVOCATION
1954
2151
  FORGE_DATASET_STARTED="$(date +%s)"
1955
2152
  FORGE_DATASET_ARGV=("$@")
@@ -1977,11 +2174,13 @@ case "$CMD" in
1977
2174
  accept) need_fn do_accept; do_accept "$@" ;;
1978
2175
  review) need_fn do_review; do_review "$@" ;;
1979
2176
  split) need_fn do_split; do_split "$@" ;;
2177
+ attribute) need_fn do_attribute; do_attribute "$@" ;;
1980
2178
  combine) need_fn do_combine; do_combine "$@" ;;
1981
2179
  _task) do_task "$@" ;;
1982
2180
  _merge) merge_task "$@" ;;
1983
2181
  _prepare_retry) retry_for_scheduler "$@" ;;
1984
2182
  _qa_only) qa_only_next "$@" ;;
1985
2183
  _waves) compute_waves "$@" ;;
2184
+ _sweep) sweep_plan "$@" ;;
1986
2185
  *) die "unknown subcommand '$CMD'" ;;
1987
2186
  esac