@giamme/forge 0.12.1 → 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 (107) hide show
  1. package/CHANGELOG.md +55 -0
  2. package/README.md +1 -1
  3. package/SKILL.md +29 -12
  4. package/VERSION +1 -1
  5. package/docs/add-ons.md +11 -6
  6. package/docs/artifacts.md +12 -6
  7. package/docs/commands.md +179 -17
  8. package/docs/decomposed-runs.md +13 -5
  9. package/docs/forge-ui.md +7 -3
  10. package/docs/memory.md +2 -1
  11. package/docs/models.md +4 -2
  12. package/docs/reviews.md +49 -20
  13. package/docs/troubleshooting.md +3 -1
  14. package/forge +17 -1
  15. package/package.json +1 -1
  16. package/references/dataset.md +39 -13
  17. package/references/decision-models.md +759 -0
  18. package/references/decompose.md +166 -29
  19. package/references/harnesses.md +10 -3
  20. package/references/planning.md +8 -0
  21. package/references/solo.md +13 -3
  22. package/scripts/forge-artifact.sh +30 -4
  23. package/scripts/forge-config.py +238 -29
  24. package/scripts/forge-contract.py +95 -56
  25. package/scripts/forge-control.py +40 -9
  26. package/scripts/forge-decide.py +6 -0
  27. package/scripts/forge-dispatch.sh +38 -16
  28. package/scripts/forge-fail-first.py +2 -2
  29. package/scripts/forge-gate-addressed.sh +40 -0
  30. package/scripts/forge-gate-message.sh +64 -0
  31. package/scripts/forge-issues.py +321 -33
  32. package/scripts/forge-jev-options.sh +269 -42
  33. package/scripts/forge-lib-attribute.sh +447 -0
  34. package/scripts/forge-lib-gates.sh +32 -0
  35. package/scripts/forge-lib-plans.sh +17 -6
  36. package/scripts/forge-lib-review.sh +22 -17
  37. package/scripts/forge-lib-task.sh +217 -38
  38. package/scripts/forge-lib-verify.sh +45 -8
  39. package/scripts/forge-memory.sh +3 -3
  40. package/scripts/forge-parallel-options.sh +18 -5
  41. package/scripts/forge-parallel.sh +455 -303
  42. package/scripts/forge-plan-check.py +35 -1
  43. package/scripts/forge-pre-review.py +437 -0
  44. package/scripts/forge-prompt.py +25 -5
  45. package/scripts/forge-route.py +2 -2
  46. package/scripts/forge-runtime.py +10 -4
  47. package/scripts/forge-schedule.py +21 -5
  48. package/scripts/forge-shadow.py +2 -2
  49. package/scripts/forge-solo.sh +38 -9
  50. package/scripts/forge-submodules.py +389 -0
  51. package/scripts/forge_dataset/cli.py +12 -6
  52. package/scripts/forge_dataset/export.py +55 -45
  53. package/scripts/forge_dataset/harvest.py +33 -5
  54. package/scripts/{forge_jev/outcome.py → forge_dataset/states.py} +21 -7
  55. package/scripts/forge_decide/__init__.py +141 -0
  56. package/scripts/forge_decide/budget.py +149 -0
  57. package/scripts/forge_decide/cache.py +66 -0
  58. package/scripts/forge_decide/cli.py +953 -0
  59. package/scripts/forge_decide/doctor.py +221 -0
  60. package/scripts/forge_decide/label_addressed.py +75 -0
  61. package/scripts/forge_decide/label_attribution.py +62 -0
  62. package/scripts/forge_decide/label_coverage.py +81 -0
  63. package/scripts/forge_decide/label_message.py +38 -0
  64. package/scripts/forge_decide/label_prompt.py +139 -0
  65. package/scripts/forge_decide/labels.py +328 -0
  66. package/scripts/forge_decide/metrics.py +125 -0
  67. package/scripts/forge_decide/migrate.py +226 -0
  68. package/scripts/forge_decide/providers.py +292 -0
  69. package/scripts/forge_decide/replay.py +350 -0
  70. package/scripts/forge_decide/report.py +382 -0
  71. package/scripts/forge_decide/resolve.py +397 -0
  72. package/scripts/forge_decide/sites.py +377 -0
  73. package/scripts/forge_jev/__init__.py +202 -104
  74. package/scripts/forge_jev/addressed.py +171 -0
  75. package/scripts/forge_jev/attribution.py +198 -0
  76. package/scripts/forge_jev/cli.py +460 -382
  77. package/scripts/forge_jev/client.py +155 -77
  78. package/scripts/forge_jev/coupling.py +19 -87
  79. package/scripts/forge_jev/coverage.py +303 -0
  80. package/scripts/forge_jev/findings.py +219 -0
  81. package/scripts/forge_jev/gates.py +225 -27
  82. package/scripts/forge_jev/memory.py +65 -4
  83. package/scripts/forge_jev/message.py +134 -0
  84. package/scripts/forge_jev/plan_gates.py +294 -0
  85. package/scripts/forge_jev/questions.py +173 -313
  86. package/scripts/forge_jev/verify.py +130 -104
  87. package/ui/README.md +2 -2
  88. package/ui/docs/api.md +60 -32
  89. package/ui/forge_ui/control.py +60 -11
  90. package/ui/forge_ui/export.py +2 -1
  91. package/ui/forge_ui/models.py +1 -0
  92. package/ui/forge_ui/reader.py +87 -14
  93. package/ui/forge_ui/static/app.js +2 -2
  94. package/ui/forge_ui/static/controls.js +20 -13
  95. package/ui/forge_ui/static/panel.js +63 -17
  96. package/ui/forge_ui/static/runmodel.js +23 -1
  97. package/ui/forge_ui/static/scene3d.js +2 -15
  98. package/ui/forge_ui/static/settings.js +336 -41
  99. package/ui/forge_ui/static/style.css +19 -7
  100. package/references/jev.md +0 -865
  101. package/scripts/forge_jev/backtest.py +0 -322
  102. package/scripts/forge_jev/corpus.py +0 -156
  103. package/scripts/forge_jev/features.py +0 -24
  104. package/scripts/forge_jev/predict.py +0 -204
  105. package/scripts/forge_jev/review.py +0 -73
  106. package/scripts/forge_jev/routing.py +0 -271
  107. package/scripts/forge_jev/subset.py +0 -123
@@ -16,8 +16,12 @@ record_attempt() { # record_attempt <plan> <id>
16
16
  local tdir="$1/tasks/$2" cls=""
17
17
  [ "$(task_status "$1" "$2")" = BLOCKED ] && return 0 # never started: nothing to audit
18
18
  [ "$(task_status "$1" "$2")" = INFRA ] && cls="$(sed -n 's/^class=//p' "$tdir/infra.txt" 2>/dev/null | head -1)"
19
+ # A send-back that no reviewer judged keeps the task status FAIL; attempts.tsv names its kind.
20
+ local st; st="$(task_status "$1" "$2")"
21
+ if [ -f "$tdir/bounced" ]; then st=BOUNCED
22
+ elif [ -f "$tdir/message.failed" ]; then st=INCOMPLETE; fi
19
23
  printf '%s\t%s\t%s\t%s\t%s\n' "$(date +%s)" "$(cat "$tdir/attempt" 2>/dev/null || echo 0)" \
20
- "$(task_status "$1" "$2")" "$cls" "$(field "$1/tasks.tsv" "$2" dwarf)" >> "$tdir/attempts.tsv"
24
+ "$st" "$cls" "$(field "$1/tasks.tsv" "$2" dwarf)" >> "$tdir/attempts.tsv"
21
25
  }
22
26
 
23
27
  # --- infrastructure stops -------------------------------------------------------
@@ -146,7 +150,8 @@ qa_only_next() { # qa_only_next <plan> <id>
146
150
  [ -n "$wt" ] && reviewed_state_matches "$tdir" "$wt"
147
151
  return
148
152
  fi
149
- if [ "$(task_status "$1" "$2")" = UNKNOWN ] && [ -s "$tdir/reviewed.commit" ]; then
153
+ case "$(task_status "$1" "$2")" in UNKNOWN|INVALIDATED) ;; *) return 1 ;; esac
154
+ if [ -s "$tdir/reviewed.commit" ]; then
150
155
  [ -n "$wt" ] && reviewed_state_matches "$tdir" "$wt"
151
156
  return
152
157
  fi
@@ -186,28 +191,79 @@ carry_findings() { # carry_findings <tdir>
186
191
  cp "$tdir/reviewed.commit" "$tdir/.retry_findings.commit.tmp" \
187
192
  && mv "$tdir/.retry_findings.commit.tmp" "$tdir/retry_findings.commit"
188
193
  else
189
- rm -f "$tdir/retry_findings.commit"
194
+ rm -f "$tdir/retry_findings.commit" "$tdir/retry_findings.source"
190
195
  fi
191
196
  # The reviewer session that wrote these findings, and what it ran as, kept beside them for a
192
197
  # plan with --reviewer-session. Removed first, so an older session never sits next to newer
193
198
  # findings; a review that left no session leaves none here.
194
199
  rm -f "$tdir/retry_findings.session" "$tdir/retry_findings.resolved"
195
- cp "$tdir/qa.last" "$tdir/retry_findings.md"
200
+ carry_implementer_session "$tdir"
201
+ printf 'review\n' > "$tdir/retry_findings.source"
202
+ local gthr gdec
203
+ IFS="$(printf '\t')" read -r gthr gdec _ < "$tdir/qa.gate" 2>/dev/null || true
204
+ if [ "${gdec:-}" = fail ]; then
205
+ # forge, not the reviewer, failed this attempt: say so above the copied report.
206
+ { 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"
207
+ cat "$tdir/qa.last"; } > "$tdir/.retry_findings.md.tmp" && mv "$tdir/.retry_findings.md.tmp" "$tdir/retry_findings.md"
208
+ else
209
+ cp "$tdir/qa.last" "$tdir/retry_findings.md"
210
+ fi
196
211
  [ ! -f "$tdir/qa.session" ] || cp "$tdir/qa.session" "$tdir/retry_findings.session" 2>/dev/null || true
197
212
  [ ! -f "$tdir/qa.resolved" ] || cp "$tdir/qa.resolved" "$tdir/retry_findings.resolved" 2>/dev/null || true
198
213
  }
199
214
 
215
+ # The retry findings of an attempt forge sent back without a review: <file> (prereview.md,
216
+ # bounce.md or message.md) is copied to retry_findings.md and <source> names where it came from.
217
+ # They are kept against the commit they were written about, and no reviewer session goes with them.
218
+ # With `keep`, retry_findings.commit stays as it is: a bounce's findings are the last review's,
219
+ # and its reviewed.commit is the bounced attempt's, which nobody reviewed.
220
+ carry_sent_back() { # carry_sent_back <tdir> <file> <source> [keep]
221
+ local tdir="$1" file="$2" source="$3" keep="${4:-}"
222
+ if [ "$keep" = keep ]; then
223
+ :
224
+ elif [ -s "$tdir/reviewed.commit" ]; then
225
+ cp "$tdir/reviewed.commit" "$tdir/.retry_findings.commit.tmp" \
226
+ && mv "$tdir/.retry_findings.commit.tmp" "$tdir/retry_findings.commit"
227
+ else
228
+ rm -f "$tdir/retry_findings.commit" "$tdir/retry_findings.source"
229
+ fi
230
+ rm -f "$tdir/retry_findings.session" "$tdir/retry_findings.resolved"
231
+ carry_implementer_session "$tdir"
232
+ printf '%s\n' "$source" > "$tdir/.retry_findings.source.tmp" && mv "$tdir/.retry_findings.source.tmp" "$tdir/retry_findings.source"
233
+ cp "$tdir/$file" "$tdir/.retry_findings.md.tmp" && mv "$tdir/.retry_findings.md.tmp" "$tdir/retry_findings.md"
234
+ }
235
+
236
+ # The failing tests and the end of their output (#85).
237
+ carry_prereview() { carry_sent_back "$1" prereview.md prereview; } # carry_prereview <tdir>
238
+ # The blocking findings a retry left unaddressed (#43).
239
+ carry_bounce() { carry_sent_back "$1" bounce.md bounce keep; } # carry_bounce <tdir>
240
+ # What the implementer's final message said about not finishing (#44).
241
+ carry_message() { carry_sent_back "$1" message.md message; } # carry_message <tdir>
242
+
243
+ # The implementer session that produced the judged commit (reviewed.dwarf.*, recorded with
244
+ # reviewed.commit), kept beside the findings for a plan with --implementer-session, as
245
+ # carry_findings keeps the reviewer's.
246
+ carry_implementer_session() { # carry_implementer_session <tdir>
247
+ local tdir="$1" n
248
+ for n in session resolved; do
249
+ rm -f "$tdir/retry_findings.dwarf.$n"
250
+ [ ! -f "$tdir/reviewed.dwarf.$n" ] || cp "$tdir/reviewed.dwarf.$n" "$tdir/retry_findings.dwarf.$n" 2>/dev/null || true
251
+ done
252
+ }
253
+
200
254
  # --- reviewer-session continuation (plan --reviewer-session, an opt-in experiment) ------------
201
- # review_session_decide <session-file> <resolved-file> <resolution-file>: whether this review
202
- # round continues the earlier reviewer's session. Prints `mode<TAB>reason<TAB>session`; the
203
- # session is the id to continue, and empty for every fresh answer.
204
- # session-file the id the earlier review ran under (retry_findings.session / qa.session)
205
- # resolved-file that review's resolution (retry_findings.resolved / qa.resolved)
255
+ # review_session_decide <session-file> <resolved-file> <resolution-file> [harnesses]: whether this
256
+ # round continues the earlier session. Prints `mode<TAB>reason<TAB>session`; the session is the
257
+ # id to continue, and empty for every fresh answer.
258
+ # session-file the id the earlier round ran under (retry_findings.session / qa.session)
259
+ # resolved-file that round's resolution (retry_findings.resolved / qa.resolved)
206
260
  # resolution-file this dispatch's resolution (doctor output): harness=, model=, effort=
261
+ # harnesses the ones that can continue this role (default: a reviewer's, claude
262
+ # openclaude codex; an implementer passes claude openclaude)
207
263
  # The caller has already handled the cases that need no files (first round, Fractal). Anything
208
264
  # that cannot be checked is fresh; nothing here aborts.
209
265
  review_session_decide() {
210
- local sf="$1" rf="$2" cf="$3" id="" k a b h
266
+ local sf="$1" rf="$2" cf="$3" can="${4:-claude openclaude codex}" id="" k a b h
211
267
  [ -f "$sf" ] && id="$(head -1 "$sf" 2>/dev/null | tr -d '\r')"
212
268
  if [ -z "$id" ]; then printf 'fresh\tno-session\t\n'; return 0; fi
213
269
  case "$id" in *[!A-Za-z0-9-]*) printf 'fresh\tinvalid-session\t\n'; return 0 ;; esac
@@ -219,13 +275,24 @@ review_session_decide() {
219
275
  b="$(sed -n "s/^$k=//p" "$cf" 2>/dev/null | head -1)"
220
276
  if [ -z "$a" ] || [ "$a" != "$b" ]; then printf 'fresh\tspec-changed\t\n'; return 0; fi
221
277
  done
222
- case "$h" in
223
- claude|openclaude|codex) printf 'continued\tsame-spec\t%s\n' "$id" ;;
278
+ case " $can " in
279
+ *" $h "*) printf 'continued\tsame-spec\t%s\n' "$id" ;;
224
280
  *) printf 'fresh\tharness-unsupported\t\n' ;;
225
281
  esac
226
282
  return 0
227
283
  }
228
284
 
285
+ # Whether the task's worktree is still exactly the commit the carried findings judged: nothing
286
+ # committed or edited since (a timed-out or interrupted implementer leaves edits behind). Only
287
+ # then does the implementer session that made that commit know the work it would continue.
288
+ implementer_work_unchanged() { # implementer_work_unchanged <tdir> <worktree>
289
+ local tdir="$1" wt="$2" head
290
+ [ -s "$tdir/retry_findings.commit" ] || return 1
291
+ head="$(git -C "$wt" rev-parse -q --verify HEAD 2>/dev/null)" || return 1
292
+ [ "$head" = "$(cat "$tdir/retry_findings.commit")" ] || return 1
293
+ [ -z "$(git -C "$wt" status --porcelain --untracked-files=all -- . ':(exclude).forge' 2>/dev/null)" ]
294
+ }
295
+
229
296
  # The diff between the attempt the carried findings judged and the one under review now, as
230
297
  # files a later gate can reuse (tasks/<id>/changes.since.{diff,range,stat}). All three go
231
298
  # when there is no valid range: no findings, no recorded commit, a commit that is unknown or
@@ -250,22 +317,81 @@ attempt_delta() { # attempt_delta <tdir> <worktree> <reviewed-commit>
250
317
  return 0
251
318
  }
252
319
 
320
+ # --- NEEDS_INPUT (#44) ------------------------------------------------------------
321
+ # A task stopped for the user's answer (needs_input.md holds the question). It resumes only
322
+ # when answer.md is non-empty and strictly newer than the question; a stale answer, left over
323
+ # from before the question was asked, is no answer. Compared in nanoseconds: the shell's -nt looks
324
+ # at whole seconds on some systems.
325
+ answer_ready() { # answer_ready <tdir>
326
+ [ -s "$1/answer.md" ] || return 1
327
+ [ -f "$1/needs_input.md" ] || return 0 # no question left to be older than
328
+ python3 -c 'import os, sys; sys.exit(0 if os.stat(sys.argv[1]).st_mtime_ns > os.stat(sys.argv[2]).st_mtime_ns else 1)' \
329
+ "$1/answer.md" "$1/needs_input.md" 2>/dev/null
330
+ }
331
+
332
+ # retry_findings.next: the findings so far, then the question quoted and the answer. Nothing
333
+ # else changes until commit_answer_findings.
334
+ compose_answer_findings() { # compose_answer_findings <tdir>
335
+ local tdir="$1" tmp="$1/.retry_findings.next.tmp"
336
+ {
337
+ if [ -s "$tdir/retry_findings.md" ]; then
338
+ cat "$tdir/retry_findings.md"
339
+ printf '\n\n'
340
+ fi
341
+ printf "## The user's answer\n\n"
342
+ if [ -f "$tdir/needs_input.md" ]; then sed 's/^/> /' "$tdir/needs_input.md"; printf '\n'; fi
343
+ cat "$tdir/answer.md"
344
+ printf '\n'
345
+ } > "$tmp" && mv "$tmp" "$tdir/retry_findings.next" || { rm -f "$tmp"; return 1; }
346
+ }
347
+
348
+ # The retry goes ahead: the composed findings replace the old ones, their source is the answer,
349
+ # retry_findings.commit stays as it was, and the question and answer are consumed. The reviewer
350
+ # and implementer sessions kept beside the old findings stay with them.
351
+ commit_answer_findings() { # commit_answer_findings <tdir>
352
+ local tdir="$1"
353
+ printf 'answer\n' > "$tdir/.retry_findings.source.tmp" && mv "$tdir/.retry_findings.source.tmp" "$tdir/retry_findings.source" \
354
+ && mv "$tdir/retry_findings.next" "$tdir/retry_findings.md" || return 1
355
+ rm -f "$tdir/needs_input.md" "$tdir/answer.md"
356
+ }
357
+
253
358
  # Shared by `retry` (a human asked) and the scheduler's automatic retries. The findings
254
359
  # are the whole point of retrying rather than re-running: the dwarf is told what was
255
360
  # wrong with its own previous attempt.
256
361
  prepare_retry() { # prepare_retry <plan> <id> [new-dwarf]
257
362
  local PLAN="$1" id="$2" newdwarf="${3:-}" T="$1/tasks.tsv" tdir="$1/tasks/$2" st verdict
258
363
  st="$(task_status "$PLAN" "$id")"
364
+ # A NEEDS_INPUT task waits for the user, and nothing here may change before the answer is
365
+ # known to be there: no file removed, no status changed, no escalation.
366
+ if [ "$st" = NEEDS_INPUT ] && ! answer_ready "$tdir"; then
367
+ note "$id is waiting for an answer: forge-parallel.sh retry $PLAN $id --answer \"<text>\""
368
+ return 2
369
+ fi
259
370
  verdict="$(forge_verdict "$tdir/qa.last" 2>/dev/null)"
260
371
  if [ "$st" = INFRA ]; then
261
372
  # Nothing was judged, so there is nothing new to carry forward; the stop already
262
373
  # recorded where to resume (a `resume` marker for a QA-stage stop).
263
374
  note "$id: resuming after an infrastructure stop"
264
- elif [ "$st" = UNKNOWN ] && [ -s "$tdir/reviewed.commit" ]; then
265
- # The reviewer never reached a verdict, so the code was not rejected. Re-asking QA is
266
- # cheaper and more honest than paying an implementer to rewrite unjudged work; the
267
- # marker is validated against the worktree below before it is believed.
375
+ elif [ "$st" = NEEDS_INPUT ]; then
376
+ # Exclusive: an older qa.last (a reviewed FAIL before the question) must not reach
377
+ # carry_findings and overwrite the answer. The result is composed into retry_findings.next
378
+ # and only moved into place once escalation and pins have agreed to the retry.
379
+ compose_answer_findings "$tdir" || return 1
380
+ elif { [ "$st" = UNKNOWN ] || [ "$st" = INVALIDATED ]; } && [ -s "$tdir/reviewed.commit" ]; then
381
+ # The reviewer never reached a verdict, or its verdict was voided because something changed
382
+ # during the review: either way the code was not rejected. Re-asking QA is cheaper and more
383
+ # honest than paying an implementer to rewrite unjudged work; the marker is validated
384
+ # against the worktree below before it is believed (a changed worktree runs the full task).
268
385
  echo qa > "$tdir/resume"
386
+ elif [ "$st" = FAIL ] && [ -f "$tdir/prereview.failed" ] && [ -s "$tdir/prereview.md" ]; then
387
+ # No reviewer ran: forge's own pre-review tests failed (#85), and their output is the finding.
388
+ carry_prereview "$tdir"
389
+ elif [ "$st" = FAIL ] && [ -f "$tdir/bounced" ] && [ -s "$tdir/bounce.md" ]; then
390
+ # No reviewer ran: the retry left the blocking findings it was sent unaddressed (#43).
391
+ carry_bounce "$tdir"
392
+ elif [ "$st" = FAIL ] && [ -f "$tdir/message.failed" ] && [ -s "$tdir/message.md" ]; then
393
+ # No reviewer ran: the implementer's own final message said it did not finish (#44).
394
+ carry_message "$tdir"
269
395
  # Only a real review replaces the findings. The runner also writes explanatory text
270
396
  # into qa.last when it fails a task without dispatching QA ("produced no changes at
271
397
  # all"), and copying that over would throw away the actual findings the previous
@@ -279,7 +405,8 @@ prepare_retry() { # prepare_retry <plan> <id> [new-dwarf]
279
405
  else
280
406
  note "$id: no previous QA findings to pass on (last status was $st)"
281
407
  : > "$tdir/retry_findings.md"
282
- rm -f "$tdir/retry_findings.commit" "$tdir/retry_findings.session" "$tdir/retry_findings.resolved"
408
+ rm -f "$tdir/retry_findings.commit" "$tdir/retry_findings.source" "$tdir/retry_findings.session" "$tdir/retry_findings.resolved" \
409
+ "$tdir/retry_findings.dwarf.session" "$tdir/retry_findings.dwarf.resolved"
283
410
  fi
284
411
  # A QA-only resume (an unreviewed verdict, or a QA-stage infrastructure stop) re-asks the
285
412
  # reviewer about work that is already committed; the dwarf does not run, so it is no moment
@@ -289,6 +416,7 @@ prepare_retry() { # prepare_retry <plan> <id> [new-dwarf]
289
416
  if resume_check "$PLAN" "$id"; then
290
417
  qa_only=1
291
418
  [ "$st" = UNKNOWN ] && note "$id: the reviewer gave no verdict — re-running QA on the unchanged work"
419
+ [ "$st" = INVALIDATED ] && note "$id: the last review was voided — re-running QA on the unchanged work"
292
420
  fi
293
421
  # Who decides the next implementer, in this order: an explicit --dwarf (the human's call,
294
422
  # source `retry`), a pin (the human's call, applied once, source `pin`), then the retry
@@ -309,6 +437,7 @@ prepare_retry() { # prepare_retry <plan> <id> [new-dwarf]
309
437
  elif [ "$has_pin" = 1 ] && ! escalation_record_ok "$PLAN" "$id"; then
310
438
  # Before the claim: a refused record leaves the pin unclaimed and tasks.tsv as it was.
311
439
  note "$id: could not record the escalation in escalations.tsv; nothing was retried"
440
+ rm -f "$tdir/retry_findings.next"
312
441
  return 1
313
442
  elif [ "$has_pin" = 1 ] && pinned="$(claim_pin "$tdir")"; then
314
443
  esc_source=pin
@@ -317,6 +446,7 @@ prepare_retry() { # prepare_retry <plan> <id> [new-dwarf]
317
446
  else
318
447
  next="$(python3 "$SKILL_DIR/scripts/forge-route.py" escalation --plan "$PLAN" --task "$id")"; rc=$?
319
448
  if [ "$rc" = 3 ]; then
449
+ rm -f "$tdir/retry_findings.next"
320
450
  note "$(cat "$tdir/split.suggested" 2>/dev/null)"
321
451
  return 3
322
452
  fi
@@ -330,8 +460,9 @@ prepare_retry() { # prepare_retry <plan> <id> [new-dwarf]
330
460
  # request is recorded and consumed.
331
461
  if [ "$newdwarf" = "$cur" ] && [ "$esc_source" != pin ]; then newdwarf=""; fi
332
462
  if [ -n "$newdwarf" ]; then
333
- write_escalation "$PLAN" "$id" "$cur" "$newdwarf" "$esc_source" || return 1
463
+ write_escalation "$PLAN" "$id" "$cur" "$newdwarf" "$esc_source" || { rm -f "$tdir/retry_findings.next"; return 1; }
334
464
  fi
465
+ [ "$st" != NEEDS_INPUT ] || commit_answer_findings "$tdir" || return 1
335
466
  rm -f "$tdir/noretry"
336
467
  }
337
468
 
@@ -486,42 +617,69 @@ guard_after_dwarf() { # guard_after_dwarf <wt> <tdir> <id>
486
617
  }
487
618
 
488
619
  # --- QA severity gate -----------------------------------------------------------
489
- qa_threshold_for() { # per-task file wins over the plan-level default; prints nothing if unset
490
- # A per-task "none" exempts the task from a plan-wide threshold (prints nothing, no fallback).
491
- # A plan-level "none" is the same as no file. Anything but P0-P3 or none is ignored, so a
492
- # garbage per-task value falls back to the plan file.
620
+ # The bash mirror of forge-contract.py's DEFAULT_THRESHOLD; a test asserts the two agree.
621
+ FORGE_QA_THRESHOLD_DEFAULT=P2
622
+
623
+ # qa_threshold_walk <plan> <id> -> "<level> <set|default>": the per-task file, then the plan
624
+ # file, then the default. "none" in a file means nothing is tolerated, the same as P3 (so a
625
+ # per-task none still exempts a task from a plan-wide tolerant threshold). Anything but P0-P3
626
+ # or none is ignored: a garbage per-task value falls through to the plan file, a garbage plan
627
+ # value to the default. An empty id reads the plan level only (the approval table).
628
+ qa_threshold_walk() {
493
629
  local f v
494
630
  for f in "$1/tasks/$2/qa_threshold" "$1/qa_threshold"; do
631
+ [ -n "$2" ] || [ "$f" = "$1/qa_threshold" ] || continue
495
632
  [ -s "$f" ] || continue
496
633
  v="$(head -1 "$f" | tr -d ' \r' | tr 'a-z' 'A-Z')"
497
634
  case "$v" in
498
- P0|P1|P2|P3) printf '%s\n' "$v"; return 0 ;;
499
- NONE) [ "$f" = "$1/qa_threshold" ] || return 0 ;;
635
+ P0|P1|P2|P3) printf '%s set\n' "$v"; return 0 ;;
636
+ NONE) printf 'P3 set\n'; return 0 ;;
500
637
  esac
501
638
  done
502
- return 0
639
+ printf '%s default\n' "$FORGE_QA_THRESHOLD_DEFAULT"
640
+ }
641
+
642
+ qa_threshold_for() { # qa_threshold_for <plan> <id> -> the effective threshold, always a value
643
+ local v; v="$(qa_threshold_walk "$1" "$2")"; printf '%s\n' "${v%% *}"
503
644
  }
504
645
 
505
- # With an explicit threshold, a reviewer's FAIL whose confirmed findings are all labelled
506
- # and less severe than the threshold is accepted as PASS-with-known-issues. The literal
507
- # status stays PASS, so the merge path, the scheduler and Fractal need no new vocabulary.
508
- # Anything unlabelled stays blocking: a finding the gate cannot place is not tolerated.
646
+ qa_threshold_source() { # qa_threshold_source <plan> <id> -> set | default
647
+ local v; v="$(qa_threshold_walk "$1" "$2")"; printf '%s\n' "${v##* }"
648
+ }
649
+
650
+ # Epoch seconds with milliseconds, for the flip log and FORGE_RUN_STARTED. Whole seconds cannot
651
+ # tell a flip from just before a run started apart from one in the same second after it.
652
+ forge_now() { python3 -c 'import time; print("%.3f" % time.time())' 2>/dev/null || date +%s; }
653
+
654
+ # The gate goes both ways, at the effective threshold. A reviewer's FAIL whose confirmed
655
+ # findings are all labelled and less severe than the threshold is accepted as
656
+ # PASS-with-known-issues; the literal status stays PASS, so the merge path, the scheduler
657
+ # and Fractal need no new vocabulary. A PASS that lists a blocking CONFIRMED finding (at the
658
+ # threshold or worse, or with no severity) becomes FAIL.
509
659
  # The optional 5th argument is the threshold the caller already used for this attempt's review
510
- # prompt; when given (even empty) it is used as-is, so a change to the files between the prompt
511
- # and the gate cannot split one attempt across two thresholds. Absent, the files are read.
660
+ # prompt; when given it is used as-is, so a change to the files between the prompt and the
661
+ # gate cannot split one attempt across two thresholds. Absent (or empty), the files are read.
512
662
  qa_gate() { # qa_gate <plan> <id> <tdir> <verdict> [threshold]
513
- local plan="$1" id="$2" tdir="$3" verdict="$4" thr line
663
+ local plan="$1" id="$2" tdir="$3" verdict="$4" thr="${5:-}" line worst
514
664
  rm -f "$tdir/qa.gate" "$tdir/known_issues.md"
515
- if [ "$#" -ge 5 ]; then thr="$5"; else thr="$(qa_threshold_for "$plan" "$id")"; fi
516
- [ -n "$thr" ] || return 0
665
+ [ -n "$thr" ] || thr="$(qa_threshold_for "$plan" "$id")"
517
666
  line="$(python3 "$SKILL_DIR/scripts/forge-contract.py" gate --verdict "${verdict:-UNKNOWN}" \
518
667
  --qa-last "$tdir/qa.last" --threshold "$thr" --known-issues "$tdir/known_issues.md" 2>/dev/null)" || return 0
519
668
  [ -n "$line" ] || return 0
520
669
  printf '%s\t%s\n' "$thr" "$line" > "$tdir/qa.gate"
521
- if [ "$(printf '%s' "$line" | awk -F'\t' '{print $1}')" = accept ]; then
522
- echo PASS > "$tdir/status"
523
- note "$id: the reviewer said FAIL, but every confirmed finding is less severe than the $thr threshold — accepted with known issues ($tdir/known_issues.md)"
524
- fi
670
+ case "$(printf '%s' "$line" | awk -F'\t' '{print $1}')" in
671
+ accept)
672
+ echo PASS > "$tdir/status"
673
+ note "$id: the reviewer said FAIL, but every confirmed finding is less severe than the $thr threshold — accepted with known issues ($tdir/known_issues.md)" ;;
674
+ fail)
675
+ echo FAIL > "$tdir/status"
676
+ worst="$(printf '%s' "$line" | awk -F'\t' '{print $2}')"
677
+ note "$id: the reviewer said PASS but listed a CONFIRMED finding at or above the $thr threshold (worst $worst) — forge made it FAIL"
678
+ # A scheduled task's notes go to its task.out, and a later attempt replaces qa.gate: this
679
+ # log is what lets the run's summary say forge overrode a verdict (report_gate_flips).
680
+ printf '%s\t%s\t%s\t%s\n' "$(forge_now)" "$(cat "$tdir/attempt" 2>/dev/null || echo 0)" "$thr" "$worst" \
681
+ >> "$tdir/qa.flips" ;;
682
+ esac
525
683
  return 0
526
684
  }
527
685
 
@@ -546,6 +704,9 @@ report_known_issues() { # report_known_issues <plan>
546
704
  local plan="$1" id n=0
547
705
  for id in $(all_ids "$plan/tasks.tsv"); do
548
706
  [ -s "$plan/tasks/$id/known_issues.md" ] || continue
707
+ # A FAIL task's tolerated findings are on disk too (the gate writes them whatever its
708
+ # decision), but nothing was accepted: only a passed or merged task's are.
709
+ case "$(task_status "$plan" "$id")" in PASS|MERGED) ;; *) continue ;; esac
549
710
  [ "$n" = 0 ] && echo "known issues accepted (findings below the QA threshold, or accepted by a human):"
550
711
  n=$((n+1))
551
712
  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"
@@ -554,6 +715,23 @@ report_known_issues() { # report_known_issues <plan>
554
715
  return 0
555
716
  }
556
717
 
718
+ # The PASS verdicts forge turned into FAIL, since FORGE_RUN_STARTED (set by run and retry;
719
+ # unset shows them all), including those whose task a later attempt fixed.
720
+ report_gate_flips() { # report_gate_flips <plan>
721
+ local plan="$1" id n=0 at attempt thr worst
722
+ for id in $(all_ids "$plan/tasks.tsv"); do
723
+ [ -s "$plan/tasks/$id/qa.flips" ] || continue
724
+ while IFS="$(printf '\t')" read -r at attempt thr worst; do
725
+ awk -v at="${at:-0}" -v since="${FORGE_RUN_STARTED:-0}" 'BEGIN { exit !(at + 0 >= since + 0) }' || continue
726
+ [ "$n" = 0 ] && echo "forge overrode the reviewer's verdict (PASS, but it listed a CONFIRMED finding at or above the threshold):"
727
+ n=$((n+1))
728
+ printf ' %-14s attempt %s: PASS -> FAIL at the %s threshold (worst %s)\n' "$id" "$attempt" "$thr" "$worst"
729
+ done < "$plan/tasks/$id/qa.flips"
730
+ done
731
+ [ "$n" -gt 0 ] && echo
732
+ return 0
733
+ }
734
+
557
735
  report_guard_notes() { # report_guard_notes <plan>
558
736
  local plan="$1" id n=0 line
559
737
  for id in $(all_ids "$plan/tasks.tsv"); do
@@ -648,6 +826,7 @@ report_escalations() { # report_escalations <plan>
648
826
  run_report_extras() { # run_report_extras <plan> [<verification dir>]
649
827
  report_infra "$1"
650
828
  report_escalations "$1"
829
+ report_gate_flips "$1"
651
830
  report_known_issues "$1"
652
831
  python3 "$SKILL_DIR/scripts/forge-sweep.py" report "$1" 2>/dev/null || true
653
832
  report_guard_notes "$1"
@@ -31,21 +31,51 @@ verify_source_for() { # verify_source_for <plan> <repo>
31
31
  # lane's command (its #forge: option lines left out), one after another. Prints nothing
32
32
  # when nothing is configured.
33
33
  verify_command_for() { # verify_command_for <plan> <repo>
34
- local src loc f
34
+ local src loc
35
35
  src="$(verify_source_for "$1" "$2")"
36
36
  loc="${src#*$'\t'}"
37
37
  case "$src" in
38
38
  command:*) cat "$loc" ;;
39
- lanes:*)
40
- for f in "$loc"/*; do
41
- [ -f "$f" ] || continue
42
- case "${f##*/}" in *~) continue ;; esac
43
- awk 'body || !/^#forge:/ { body = 1; print }' "$f"
44
- done ;;
39
+ lanes:*) verify_lanes_command "$loc" ;;
45
40
  esac
46
41
  return 0
47
42
  }
48
43
 
44
+ # The commands of the lanes in one directory, as text (see verify_command_for).
45
+ verify_lanes_command() { # verify_lanes_command <lanes dir>
46
+ local f
47
+ for f in "$1"/*; do
48
+ [ -f "$f" ] || continue
49
+ case "${f##*/}" in *~) continue ;; esac
50
+ awk 'body || !/^#forge:/ { body = 1; print }' "$f"
51
+ done
52
+ return 0
53
+ }
54
+
55
+ # A fixed verification source, "command:<file>" or "lanes:<dir>", as verify_source_for prints
56
+ # one ("<kind><TAB><location>"), so a re-run uses the predicate an earlier verification used
57
+ # (its verification.command, its verification.lanes.d/) and never a newer config or discovery.
58
+ # Prints nothing, and fails, on anything else.
59
+ verify_fixed_source() { # verify_fixed_source <command:file | lanes:dir>
60
+ case "$1" in
61
+ command:?*) printf 'command:fixed\t%s\n' "${1#command:}" ;;
62
+ lanes:?*) printf 'lanes:fixed\t%s\n' "${1#lanes:}" ;;
63
+ *) return 1 ;;
64
+ esac
65
+ }
66
+
67
+ # Freeze the lane files a verification runs, so the same lanes can be run again after the
68
+ # directory changed or vanished: a plain copy at $out/verification.lanes.d/, made before the
69
+ # runner starts. A re-run that already reads that directory leaves it alone.
70
+ verify_lanes_snapshot() { # verify_lanes_snapshot <lanes dir> <out>
71
+ local snap="$2/verification.lanes.d" tmp
72
+ [ "$1" -ef "$snap" ] && return 0
73
+ tmp="$(mktemp -d "$2/.verification.lanes.XXXXXX")" || return 1
74
+ if cp -R "$1/." "$tmp/" && rm -rf "$snap" && mv "$tmp" "$snap"; then return 0; fi
75
+ rm -rf "$tmp"
76
+ return 1
77
+ }
78
+
49
79
  # Lanes are checked before any model is paid for: the runner's own validation, against the
50
80
  # checkout the lanes will run in (baseline= files exist, reports= and baseline= stay inside).
51
81
  # Dies with exit 2 and the runner's messages on an invalid source; a single command, or
@@ -98,9 +128,16 @@ verify_lanes_run() { # verify_lanes_run <plan> <checkout> <out> <lanes dir> <ret
98
128
  parallel="$(cat "$plan/verify_parallel" 2>/dev/null)"
99
129
  case "$parallel" in ''|*[!0-9]*) parallel=3 ;; esac
100
130
  [ "$retries" -le 9 ] 2>/dev/null || retries=9 # the runner takes 0 to 9
131
+ verify_lanes_snapshot "$dir" "$out" || {
132
+ echo FAIL > "$out/verification.status"
133
+ note "could not copy the verification lanes to $out/verification.lanes.d"; return 1
134
+ }
135
+ # From here on the frozen copy is the lanes' only source: an edit to the live directory
136
+ # after the copy must not change what runs, or the snapshot would not be its predicate.
137
+ dir="$out/verification.lanes.d"
101
138
  python3 "$SKILL_DIR/scripts/forge-verify.py" lanes --lanes-dir "$dir" 2>/dev/null \
102
139
  | awk -F'\t' '{ print $1 ": " $3 }' > "$out/verification.command"
103
- verify_coverage_report "$wt" "$(verify_command_for "$plan" "$(cat "$plan/repo")")" "$out/verification.coverage.txt"
140
+ verify_coverage_report "$wt" "$(verify_lanes_command "$dir")" "$out/verification.coverage.txt"
104
141
  forge_fingerprint "$wt" > "$out/verification.fingerprint" || return 1
105
142
  # The runner judges "a lane changed the checkout" by forge's own fingerprint.
106
143
  fpcmd="source $(printf %q "$SKILL_DIR/scripts/forge-artifact.sh") && forge_fingerprint ."
@@ -172,7 +172,7 @@ rebuild() { # rebuild <repo> -> prints "kept<TAB>pruned_stale<TAB>pruned_cap"
172
172
  # An unreachable or undecided answer keeps the entry -- dropping a fact on a
173
173
  # failed request would erode memory over time with nothing recording why.
174
174
  if [ "${FORGE_MEMORY_DEEP_PRUNE:-0}" = 1 ] && [ -n "$anchor" ] \
175
- && [ "$jev_loaded" = 1 ] && forge_jev_active memory; then
175
+ && [ "$jev_loaded" = 1 ] && forge_decide_active memory-stale; then
176
176
  if python3 "$SKILL_DIR/scripts/forge-jev.py" memory-stale \
177
177
  --text "$text" --anchor "$repo/$anchor" \
178
178
  ${JEV_RUN_DIR:+--run-dir "$JEV_RUN_DIR"} >/dev/null 2>&1; then
@@ -295,7 +295,7 @@ do_inject() {
295
295
  if [ -f "$SKILL_DIR/scripts/forge-jev-options.sh" ]; then
296
296
  source "$SKILL_DIR/scripts/forge-jev-options.sh" 2>/dev/null && jev_loaded=1
297
297
  fi
298
- if [ "$jev_loaded" = 1 ] && forge_jev_active memory; then
298
+ if [ "$jev_loaded" = 1 ] && forge_decide_active memory-slice; then
299
299
  local facts sliced
300
300
  facts="$(printf '%s\n' "$body" | grep '^- ' || true)"
301
301
  if [ -n "$facts" ]; then
@@ -425,7 +425,7 @@ do_record() {
425
425
  # exactly as the model emitted them. The row is written either way -- the ledger
426
426
  # is append-only and never injected, so this gates injection, never recording.
427
427
  inject=1; ecat="$cat"; jcat=""; jinject=""; jmatch=""
428
- if [ "$jev_loaded" = 1 ] && forge_jev_active memory; then
428
+ if [ "$jev_loaded" = 1 ] && forge_decide_active memory-curate; then
429
429
  curated="$(python3 "$SKILL_DIR/scripts/forge-jev.py" memory-curate \
430
430
  --repo "$repo" --category "$cat" --text "$text" \
431
431
  ${JEV_RUN_DIR:+--run-dir "$JEV_RUN_DIR"} 2>/dev/null)"
@@ -25,7 +25,9 @@
25
25
  # linear:S,T[,C] or list:a,b,... (default exp:60)
26
26
  # --infra-fallback run $PLAN/infra_fallback a dwarf's capacity stop moves it to the next healthy
27
27
  # --no-infra-fallback model of its tier pool (off by default)
28
- # --qa-threshold Pn|none run retry $PLAN/qa_threshold least severe finding that still blocks
28
+ # --qa-threshold Pn|none|default plan run retry review $PLAN/qa_threshold least severe CONFIRMED
29
+ # finding that still blocks; none (or off) =
30
+ # P3, default removes the file (P2)
29
31
  # --verify-retries N run retry integrate $PLAN/verify_retries reruns of a failed verify command
30
32
  # --escalate-after N run retry $PLAN/escalate_after failed attempts on one model before the
31
33
  # next goes a tier up (default 3; 0 = off)
@@ -40,6 +42,9 @@
40
42
  # --sweep-max N run (this run only) at most N sweep tasks (default 5)
41
43
  # --sweep-ahead run $PLAN/sweep_ahead a task is told the open findings in files it
42
44
  # --no-sweep-ahead owns, to fix on its way (off by default)
45
+ # --attribute run $PLAN/attribute_on after a failed combined verification, search the
46
+ # --no-attribute merge order for a merge that breaks it (off by
47
+ # default; `forge-parallel.sh attribute` does it later)
43
48
  # --verify-lane L=CMD run retry $PLAN/verify.d/<L> a verification lane: name[options]=command,
44
49
  # options as in a lane file (group=g,first,...);
45
50
  # repeatable; replaces --verify and the lanes
@@ -101,11 +106,13 @@ forge_pp_flag() {
101
106
  PP_MSG="$(python3 "$SKILL_DIR/scripts/forge-schedule.py" backoff-check "${2:-}" 2>&1)" || die "${PP_MSG#forge: }"
102
107
  printf '%s\n' "$2" > "$plan/infra_backoff" ;;
103
108
  --qa-threshold)
104
- case "$cmd" in run|retry|review) ;; *) return 1 ;; esac
109
+ case "$cmd" in plan|run|retry|review) ;; *) return 1 ;; esac
110
+ # none (or off) means nothing is tolerated, the same as P3; no file means the default.
105
111
  case "${2:-}" in
106
- P0|P1|P2|P3) printf '%s' "$2" > "$plan/qa_threshold" ;;
107
- none|off) rm -f "$plan/qa_threshold" ;;
108
- *) die "--qa-threshold needs P0, P1, P2, P3 or none" ;;
112
+ P0|P1|P2|P3) printf '%s' "$2" > "$plan/qa_threshold" || die "could not write $plan/qa_threshold" ;;
113
+ none|off) printf 'none' > "$plan/qa_threshold" || die "could not write $plan/qa_threshold" ;;
114
+ default) rm -f "$plan/qa_threshold" ;;
115
+ *) die "--qa-threshold needs P0, P1, P2, P3, none or default" ;;
109
116
  esac ;;
110
117
  --escalate-after)
111
118
  case "$cmd" in run|retry) ;; *) return 1 ;; esac
@@ -153,6 +160,12 @@ forge_pp_flag() {
153
160
  --no-sweep-ahead)
154
161
  [ "$cmd" = run ] || return 1
155
162
  PP_SHIFT=1; rm -f "$plan/sweep_ahead" ;;
163
+ --attribute)
164
+ [ "$cmd" = run ] || return 1
165
+ PP_SHIFT=1; printf 'on\n' > "$plan/attribute_on" ;;
166
+ --no-attribute)
167
+ [ "$cmd" = run ] || return 1
168
+ PP_SHIFT=1; rm -f "$plan/attribute_on" ;;
156
169
  --final-review)
157
170
  [ "$cmd" = integrate ] || return 1
158
171
  PP_FINAL_REVIEW="${2:?--final-review needs a QA spec}"