@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
@@ -0,0 +1,447 @@
1
+ #!/usr/bin/env bash
2
+ # Integration attribution for forge-parallel.sh (#45). Sourced; functions only.
3
+ #
4
+ # When a run's combined verification fails, every task passed its own review and the merge as a
5
+ # whole is broken. This searches the merge order for a BREAKING MERGE: a merge k whose prefix
6
+ # k-1 verified PASS and whose prefix k verified FAIL, both actually verified. Prefix 0 is the
7
+ # integration base, prefix n the tip. Verification is an arbitrary command, so failure need not
8
+ # be monotonic over the merges (1 breaks it, 2 fixes it, 3 breaks it again): a binary search finds
9
+ # *a* verified pass->fail boundary, not the earliest failing merge, and nothing here says "first".
10
+ #
11
+ # forge-parallel.sh attribute <plan> [--force]
12
+ # forge-parallel.sh run <plan> --attribute (the same search after a failed verification)
13
+ #
14
+ # Every step verifies a prefix in a scratch worktree with the verification the run used (its
15
+ # verification.lanes.d/, or its verification.command), never today's config and never discovery.
16
+ # Nothing is merged, reverted or accepted; no task status changes.
17
+ #
18
+ # State of one search, in files under $PLAN/attribute/ (the flag file is $PLAN/attribute_on):
19
+ # merges.tsv k, commit, task id steps.tsv prefix, commit, status, seconds, source
20
+ # Each verified step writes into $PLAN/attribute/<prefix>-<short sha>/.
21
+ #
22
+ # The gate (`attribution`, #45): before the binary search, a decision model ranks the merged tasks
23
+ # by how likely each broke the failing verification. In `on`, the top suspect's boundary is probed
24
+ # first (prefix k-1, then prefix k): a pass->fail pair names it, anything else narrows the bounds
25
+ # of the search. In `shadow` only the ranking is recorded. $PLAN/attribute/gate.json holds what
26
+ # attribution.json reports as `gate`.
27
+
28
+ # The prefix's commit: the base, or the k-th first-parent merge commit. The last merge commit is
29
+ # the tip unless something follows it (a `forge: combine` commit, a hand commit); the run's
30
+ # failure belongs to the tip, so it only stands for prefix n when the two are the same commit.
31
+ attribute_commit() { # attribute_commit <k>
32
+ if [ "$1" = 0 ]; then printf '%s\n' "$ATTR_BASE"
33
+ elif [ "$1" -gt "$ATTR_N" ]; then printf '%s\n' "$ATTR_TIP" # prefix n+1: commits follow the last merge
34
+ else awk -F'\t' -v k="$1" '$1 == k { print $2; exit }' "$ATTR_DIR/merges.tsv"
35
+ fi
36
+ }
37
+
38
+ # The scratch worktree is this search's own: a path no task owns and nothing else uses. A task id
39
+ # may be any name, so `_attribute` can be a task's worktree; that one is never touched. A detached
40
+ # worktree at the path is a leftover of an earlier search and is reused.
41
+ attribute_scratch_pick() { # attribute_scratch_pick <wt_root>
42
+ local root="$1" name="_attribute" i=0
43
+ git -C "$ATTR_REPO" worktree prune >/dev/null 2>&1
44
+ while :; do
45
+ if ! { [ -s "$ATTR_PLAN/tasks.tsv" ] && all_ids "$ATTR_PLAN/tasks.tsv" | grep -qxF -- "$name"; } \
46
+ && { [ ! -e "$root/$name" ] || { [ -e "$root/$name/.git" ] && ! git -C "$root/$name" symbolic-ref -q HEAD >/dev/null 2>&1; }; }; then
47
+ break
48
+ fi
49
+ i=$((i + 1)); name="_attribute-$i"
50
+ done
51
+ ATTR_SCRATCH="$root/$name"
52
+ ATTR_SCRATCH_OWNED=1
53
+ }
54
+
55
+ attribute_scratch_remove() {
56
+ [ "${ATTR_SCRATCH_OWNED:-0}" = 1 ] && [ -n "${ATTR_SCRATCH:-}" ] || return 0
57
+ git -C "$ATTR_REPO" worktree remove --force "$ATTR_SCRATCH" >/dev/null 2>&1
58
+ rm -rf "$ATTR_SCRATCH"
59
+ git -C "$ATTR_REPO" worktree prune >/dev/null 2>&1
60
+ return 0
61
+ }
62
+
63
+ attribute_record() { # attribute_record <prefix> <commit> <status> <seconds> <source>
64
+ printf '%s\t%s\t%s\t%s\t%s\n' "$1" "$2" "$3" "$4" "$5" >> "$ATTR_DIR/steps.tsv"
65
+ }
66
+
67
+ # Verify prefix k once. The result is cached: a second call answers from steps.tsv. Sets
68
+ # ATTR_STATUS (PASS, FAIL, UNVERIFIED, INTERRUPTED or SETUP_FAILED) and, when it is not a
69
+ # verified result, ATTR_REASON. Returns 0 verified, 1 inconclusive, 2 the step could not run.
70
+ attribute_verify() { # attribute_verify <k>
71
+ local k="$1" commit dir t0 rc=0 status setup_cmd
72
+ ATTR_REASON=""
73
+ status="$(awk -F'\t' -v k="$k" '$1 == k && ($3 == "PASS" || $3 == "FAIL") { print $3; exit }' "$ATTR_DIR/steps.tsv" 2>/dev/null)"
74
+ if [ -n "$status" ]; then ATTR_STATUS="$status"; return 0; fi
75
+ commit="$(attribute_commit "$k")"
76
+ dir="$ATTR_DIR/$k-${commit:0:12}"
77
+ rm -rf "$dir"; mkdir -p "$dir" || { ATTR_REASON="could not create $dir"; return 2; }
78
+ attribute_scratch_remove
79
+ if ! git -C "$ATTR_REPO" worktree add --detach "$ATTR_SCRATCH" "$commit" > "$dir/worktree.out" 2>&1; then
80
+ ATTR_REASON="could not create the scratch worktree for prefix $k: $(tail -1 "$dir/worktree.out")"
81
+ return 2
82
+ fi
83
+ note "attribute: verifying prefix $k of $ATTR_N (${commit:0:12})"
84
+ populate_submodules "$ATTR_REPO" "$ATTR_SCRATCH" "$dir" "prefix $k"
85
+ setup_cmd="$(worktree_setup_command "$ATTR_PLAN" "$ATTR_REPO")"
86
+ if [ -n "$setup_cmd" ]; then
87
+ # Stoppable like the verification: a stop reaches the setup command's whole group.
88
+ ( FORGE_RUN_STOPPABLE=1 FORGE_VERIFY_STOP=0 FORGE_VERIFY_GROUP="" FORGE_VERIFY_TIMER=""
89
+ trap verify_signal TERM INT
90
+ verify_exec "$ATTR_SCRATCH" "$setup_cmd" "$dir/setup.out" ) <&0 &
91
+ ATTR_CHILD=$!
92
+ [ "$ATTR_STOP" = 1 ] && kill -TERM "$ATTR_CHILD" 2>/dev/null
93
+ run_wait "$ATTR_CHILD"; rc=$run_rc
94
+ ATTR_CHILD=""
95
+ if [ "$rc" = 130 ] || [ "$ATTR_STOP" = 1 ]; then
96
+ ATTR_STATUS=INTERRUPTED; ATTR_REASON="interrupted during the worktree setup of prefix $k"
97
+ attribute_record "$k" "$commit" SETUP_INTERRUPTED 0 search
98
+ attribute_scratch_remove
99
+ return 1
100
+ elif [ "$rc" != 0 ]; then
101
+ attribute_record "$k" "$commit" SETUP_FAILED 0 search
102
+ ATTR_STATUS=SETUP_FAILED
103
+ ATTR_REASON="the worktree setup failed at prefix $k (see $dir/setup.out)"
104
+ attribute_scratch_remove
105
+ return 1
106
+ fi
107
+ fi
108
+ t0="$(date +%s)"
109
+ # In the background, as `run` does: a stop reaches this shell, which passes it on, and the
110
+ # verification stops its command's whole group.
111
+ ( FORGE_RUN_STOPPABLE=1; verify_result_body "$ATTR_PLAN" "$ATTR_SCRATCH" "$dir" "$ATTR_SOURCE" ) <&0 &
112
+ ATTR_CHILD=$!
113
+ [ "$ATTR_STOP" = 1 ] && kill -TERM "$ATTR_CHILD" 2>/dev/null
114
+ run_wait "$ATTR_CHILD"; rc=$run_rc
115
+ ATTR_CHILD=""
116
+ status="$(cat "$dir/verification.status" 2>/dev/null)"
117
+ if [ "$rc" = 130 ] || [ "$ATTR_STOP" = 1 ] || [ "$status" = INTERRUPTED ]; then
118
+ ATTR_STATUS=INTERRUPTED; ATTR_REASON="interrupted while verifying prefix $k"
119
+ else
120
+ case "$status" in
121
+ PASS|FAIL) ATTR_STATUS="$status" ;;
122
+ *) ATTR_STATUS=UNVERIFIED; ATTR_REASON="prefix $k could not be verified (see $dir)" ;;
123
+ esac
124
+ fi
125
+ attribute_record "$k" "$commit" "$ATTR_STATUS" "$(( $(date +%s) - t0 ))" search
126
+ attribute_scratch_remove
127
+ case "$ATTR_STATUS" in PASS|FAIL) return 0 ;; esac
128
+ return 1
129
+ }
130
+
131
+ # Prefix lo is known PASS and prefix hi known FAIL: halve the interval until hi = lo + 1. Merge
132
+ # hi is then a breaking merge (ATTR_LO, ATTR_HI). Returns as attribute_verify does.
133
+ attribute_bisect() { # attribute_bisect <lo> <hi>
134
+ local lo="$1" hi="$2" mid rc
135
+ while [ $((hi - lo)) -gt 1 ]; do
136
+ mid=$(( (lo + hi) / 2 ))
137
+ attribute_verify "$mid"; rc=$?
138
+ [ "$rc" = 0 ] || return "$rc"
139
+ if [ "$ATTR_STATUS" = PASS ]; then lo="$mid"; else hi="$mid"; fi
140
+ done
141
+ ATTR_LO="$lo"; ATTR_HI="$hi"
142
+ return 0
143
+ }
144
+
145
+ # attribution.json (atomically), from merges.tsv and steps.tsv.
146
+ attribute_write_json() { # attribute_write_json <culprit prefix or empty> <base_fails 0|1> <inconclusive text>
147
+ python3 - "$ATTR_PLAN" "$ATTR_DIR" "$1" "$2" "$3" <<'PY'
148
+ import json, os, sys
149
+ plan, adir, culprit_k, base_fails, inconclusive = sys.argv[1:6]
150
+
151
+ def rows(name):
152
+ try:
153
+ with open(os.path.join(adir, name), encoding='utf-8') as fh:
154
+ return [line.rstrip('\n').split('\t') for line in fh if line.strip()]
155
+ except OSError:
156
+ return []
157
+
158
+ merges = [{'id': r[2], 'commit': r[1]} for r in rows('merges.tsv')]
159
+ try:
160
+ with open(os.path.join(adir, 'gate.json'), encoding='utf-8') as fh:
161
+ gate = json.load(fh)
162
+ except (OSError, ValueError):
163
+ gate = None
164
+ steps = []
165
+ for r in rows('steps.tsv'):
166
+ steps.append({'prefix': int(r[0]), 'commit': r[1], 'status': r[2],
167
+ 'seconds': int(r[3]) if r[3] else None, 'source': r[4]})
168
+ doc = {
169
+ 'culprit': merges[int(culprit_k) - 1]['id'] if culprit_k else None,
170
+ 'base_fails': base_fails == '1',
171
+ 'inconclusive': inconclusive or None,
172
+ 'merges': merges,
173
+ 'steps': steps,
174
+ 'verification_runs': sum(1 for s in steps if s['source'] == 'search' and not s['status'].startswith('SETUP_')),
175
+ 'gate': gate,
176
+ }
177
+ tmp = os.path.join(plan, '.attribution.json.tmp')
178
+ with open(tmp, 'w', encoding='utf-8') as fh:
179
+ json.dump(doc, fh, indent=2)
180
+ fh.write('\n')
181
+ os.replace(tmp, os.path.join(plan, 'attribution.json'))
182
+ PY
183
+ }
184
+
185
+ # tasks/<culprit>/verification.md: the failing step's log, its last 200 lines, under a header.
186
+ attribute_write_log() { # attribute_write_log <prefix k>
187
+ local k="$1" commit id dir log tmp
188
+ commit="$(attribute_commit "$k")"
189
+ id="$(awk -F'\t' -v k="$k" '$1 == k { print $3; exit }' "$ATTR_DIR/merges.tsv")"
190
+ dir="$ATTR_DIR/$k-${commit:0:12}"
191
+ log="$dir/verification.log"
192
+ [ -f "$log" ] || log="$ATTR_PLAN/verification.log" # the tip, known FAIL from the run itself
193
+ mkdir -p "$ATTR_PLAN/tasks/$id" || return 0
194
+ tmp="$ATTR_PLAN/tasks/$id/.verification.md.$$"
195
+ {
196
+ printf '# Verification failed at prefix %s (%s)\n\n' "$k" "$commit"
197
+ printf 'Merge %s is a merge that breaks verification: prefix %s passed and prefix %s failed.\n' "$id" "$((k - 1))" "$k"
198
+ printf 'The last 200 lines of the failing verification log follow.\n\n```\n'
199
+ tail -n 200 "$log" 2>/dev/null
200
+ printf '```\n'
201
+ } > "$tmp" && mv -f "$tmp" "$ATTR_PLAN/tasks/$id/verification.md" || rm -f "$tmp"
202
+ return 0
203
+ }
204
+
205
+ # What the search says and records once it has stopped: attribution.json, the culprit's log, the
206
+ # dataset event and the summary line.
207
+ attribute_conclude() { # attribute_conclude <culprit prefix or empty> <base_fails 0|1> <inconclusive text>
208
+ local runs
209
+ attribute_write_json "$1" "$2" "$3" || return 1
210
+ [ -z "$1" ] || attribute_write_log "$1"
211
+ forge_dataset_event attribution --dir "$ATTR_PLAN" --file attribution="$ATTR_PLAN/attribution.json"
212
+ runs="$(python3 -c 'import json, sys; print(json.load(open(sys.argv[1]))["verification_runs"])' "$ATTR_PLAN/attribution.json" 2>/dev/null)"
213
+ if [ -n "$1" ]; then
214
+ printf 'integration failure: merge %s breaks verification (prefix %s passes, %s fails; %s verification runs)%s\n' \
215
+ "$(awk -F'\t' -v k="$1" '$1 == k { print $3; exit }' "$ATTR_DIR/merges.tsv")" "$(( $1 - 1 ))" "$1" "$runs" \
216
+ "$([ "$ATTR_GATE_OUTCOME" = confirmed ] && printf " (the decision model's first guess)")"
217
+ elif [ "$2" = 1 ]; then
218
+ printf 'integration failure: the base already fails verification (%s runs)\n' "$runs"
219
+ else
220
+ printf 'integration failure: attribution inconclusive — %s (%s runs)\n' "$3" "$runs"
221
+ fi
222
+ }
223
+
224
+ # Everything the search needs, checked before anything runs. Each refusal is exit 2.
225
+ attribute_evidence() { # attribute_evidence <plan> <force>
226
+ local plan="$1" force="$2" repo run_id
227
+ [ -s "$plan/wt_root" ] && [ -s "$plan/repo" ] || die "this plan has never been run: there is nothing to attribute"
228
+ repo="$(cat "$plan/repo")"; run_id="$(cat "$plan/run_id" 2>/dev/null)"
229
+ if [ "$force" != 1 ]; then
230
+ [ "$(cat "$plan/verification.status" 2>/dev/null)" = FAIL ] \
231
+ || die "the run's verification did not fail (verification.status is '$(cat "$plan/verification.status" 2>/dev/null)'): nothing to attribute; --force verifies the tip itself"
232
+ [ -s "$plan/verification.commit" ] && [ -s "$plan/accepted.integration" ] \
233
+ && [ "$(cat "$plan/verification.commit")" = "$(cat "$plan/accepted.integration")" ] \
234
+ || die "the failed verification was not of the accepted integration commit: it says nothing about the tip; --force verifies the tip itself"
235
+ fi
236
+ [ -s "$plan/integration.base" ] || die "$plan/integration.base is missing: no base to search from"
237
+ git -C "$repo" rev-parse --verify --quiet "$(cat "$plan/integration.base")^{commit}" >/dev/null \
238
+ || die "the integration base $(cat "$plan/integration.base") is not a commit of $repo"
239
+ git -C "$repo" rev-parse --verify --quiet "forge/$run_id-integration^{commit}" >/dev/null \
240
+ || die "the integration branch forge/$run_id-integration does not exist in $repo"
241
+ if [ "$force" != 1 ] && [ "$(git -C "$repo" rev-parse "forge/$run_id-integration")" != "$(cat "$plan/verification.commit")" ]; then
242
+ die "the integration branch moved since the failed verification: it says nothing about the tip; --force verifies the tip itself"
243
+ fi
244
+ return 0
245
+ }
246
+
247
+ # The log of the failing verification the model reads: the tip's own step when it was verified
248
+ # here (--force), else the run's verification.log. May not exist, and the verb then has no opinion.
249
+ attribute_tip_log() {
250
+ local c dir
251
+ for c in "$((ATTR_N + 1))" "$ATTR_N"; do
252
+ dir="$ATTR_DIR/$c-$(attribute_short "$c")"
253
+ if [ -f "$dir/verification.log" ]; then printf '%s\n' "$dir/verification.log"; return 0; fi
254
+ done
255
+ printf '%s\n' "$ATTR_PLAN/verification.log"
256
+ }
257
+ attribute_short() { local commit; commit="$(attribute_commit "$1")"; printf '%s\n' "${commit:0:12}"; }
258
+
259
+ # The gate's mode (on or shadow) from the status forge_decide_active cached; empty when unknown.
260
+ attribute_gate_mode() {
261
+ printf '%s' "${FORGE_DECIDE_STATUS_JSON:-}" | python3 -c '
262
+ import json, sys
263
+ try:
264
+ print(json.load(sys.stdin)["gates"]["attribution"]["mode"])
265
+ except Exception:
266
+ pass' 2>/dev/null
267
+ }
268
+
269
+ # gate.json (atomically) from ATTR_GATE_*: the mode alone when the verb gave no ranking.
270
+ attribute_gate_save() {
271
+ [ -n "$ATTR_GATE_MODE" ] || return 0
272
+ python3 - "$ATTR_DIR/gate.json" "$ATTR_GATE_MODE" "$ATTR_GATE_RANK" "$ATTR_GATE_TRIED" "$ATTR_GATE_OUTCOME" <<'PY'
273
+ import json, os, sys
274
+ path, mode, rank, tried, outcome = sys.argv[1:6]
275
+ gate = {'mode': mode}
276
+ if rank:
277
+ ranking = []
278
+ for line in rank.splitlines():
279
+ ident, _, p = line.partition('\t')
280
+ try:
281
+ ranking.append({'id': ident, 'p': float(p)})
282
+ except ValueError:
283
+ continue
284
+ gate.update(ranking=ranking, tried=tried or None, outcome=outcome or None)
285
+ tmp = path + '.tmp'
286
+ with open(tmp, 'w', encoding='utf-8') as fh:
287
+ json.dump(gate, fh)
288
+ os.replace(tmp, path)
289
+ PY
290
+ return 0
291
+ }
292
+
293
+ # Ask the decision model who broke the tip. Sets ATTR_GATE_MODE (empty: no gate), ATTR_GATE_RANK
294
+ # (`id<TAB>p` lines, highest first) and ATTR_GUESS, the merge number of the top suspect when the
295
+ # gate is `on` and the suspect is a merged task (not `none`). A failed verb leaves the mode alone.
296
+ attribute_gate_ask() {
297
+ local mode rc=0 top
298
+ ATTR_GATE_MODE="" ATTR_GATE_RANK="" ATTR_GATE_TRIED="" ATTR_GATE_OUTCOME="" ATTR_GUESS=""
299
+ declare -F forge_decide_active >/dev/null || return 0
300
+ declare -F forge_decide_env >/dev/null && forge_decide_env "$ATTR_REPO" "$ATTR_PLAN"
301
+ forge_decide_active attribution || return 0
302
+ mode="$(attribute_gate_mode)"
303
+ case "$mode" in on|shadow) ;; *) return 0 ;; esac
304
+ ATTR_GATE_MODE="$mode"
305
+ # In the background like a verification: a stop reaches the verb and ends the wait.
306
+ ( exec python3 "$SKILL_DIR/scripts/forge-jev.py" attribution \
307
+ --plan "$ATTR_PLAN" --repo "$ATTR_REPO" --log "$(attribute_tip_log)" \
308
+ > "$ATTR_DIR/gate.out" 2>/dev/null ) </dev/null &
309
+ ATTR_CHILD=$!
310
+ [ "$ATTR_STOP" = 1 ] && kill -TERM "$ATTR_CHILD" 2>/dev/null
311
+ run_wait "$ATTR_CHILD"; rc=$run_rc
312
+ ATTR_CHILD=""
313
+ [ "$ATTR_STOP" = 1 ] && return 0
314
+ if [ "$rc" = 0 ]; then ATTR_GATE_RANK="$(cat "$ATTR_DIR/gate.out" 2>/dev/null)"; fi
315
+ attribute_gate_save
316
+ [ "$mode" = on ] && [ -n "$ATTR_GATE_RANK" ] || return 0
317
+ top="${ATTR_GATE_RANK%%$'\t'*}"
318
+ ATTR_GUESS="$(ID="$top" awk -F'\t' '$3 == ENVIRON["ID"] { print $1; exit }' "$ATTR_DIR/merges.tsv")"
319
+ return 0
320
+ }
321
+
322
+ # The search. Runs as a subshell of its caller (`( attribute_search ... )`): it owns its scratch
323
+ # worktree, its traps and its globals. Exit 0 when it finished (a culprit or not), 1 when a step
324
+ # could not run at all, 2 on a refusal.
325
+ attribute_search() { # attribute_search <plan> <force 0|1>
326
+ ATTR_PLAN="$1"; local force="$2" run_id rc=0 line k=0 src kind loc lo=0 hi
327
+ attribute_evidence "$ATTR_PLAN" "$force"
328
+ ATTR_REPO="$(cat "$ATTR_PLAN/repo")"; run_id="$(cat "$ATTR_PLAN/run_id")"
329
+ ATTR_DIR="$ATTR_PLAN/attribute"
330
+ ATTR_BASE="$(git -C "$ATTR_REPO" rev-parse "$(cat "$ATTR_PLAN/integration.base")^{commit}")"
331
+ ATTR_TIP="$(git -C "$ATTR_REPO" rev-parse "forge/$run_id-integration^{commit}")"
332
+ ATTR_SCRATCH="" ATTR_SCRATCH_OWNED=0
333
+ ATTR_STOP=0 ATTR_CHILD="" ATTR_STATUS="" ATTR_REASON="" ATTR_LO="" ATTR_HI="" ATTR_SOURCE=""
334
+ ATTR_GATE_MODE="" ATTR_GATE_RANK="" ATTR_GATE_TRIED="" ATTR_GATE_OUTCOME="" ATTR_GUESS=""
335
+ trap 'ATTR_STOP=1; [ -n "$ATTR_CHILD" ] && kill -TERM "$ATTR_CHILD" 2>/dev/null' TERM INT
336
+ trap 'attribute_scratch_remove' EXIT
337
+ attribute_scratch_pick "$(cat "$ATTR_PLAN/wt_root")"
338
+ rm -rf "$ATTR_DIR" "$ATTR_PLAN/attribution.json"
339
+ mkdir -p "$ATTR_DIR" || die "could not create $ATTR_DIR" 1
340
+ : > "$ATTR_DIR/steps.tsv"
341
+
342
+ # The merges, oldest first, as forge-sweep.py merged_since reads the subjects.
343
+ git -C "$ATTR_REPO" log --first-parent --reverse --format='%H %s' "$ATTR_BASE..$ATTR_TIP" 2>/dev/null \
344
+ | awk '{ if (match($0, /^[0-9a-f]+ forge: merge [^ ]+ *$/)) { n++; printf "%d\t%s\t%s\n", n, $1, $4 } }' > "$ATTR_DIR/merges.tsv"
345
+ ATTR_N="$(wc -l < "$ATTR_DIR/merges.tsv" | tr -d ' ')"
346
+
347
+ # The run's own predicate. Lanes win: a lanes verification leaves a verification.command that
348
+ # only describes them.
349
+ if verify_lanes_present "$ATTR_PLAN/verification.lanes.d"; then ATTR_SOURCE="lanes:$ATTR_PLAN/verification.lanes.d"
350
+ elif [ -s "$ATTR_PLAN/verification.command" ]; then ATTR_SOURCE="command:$ATTR_PLAN/verification.command"
351
+ elif [ "$force" = 1 ]; then
352
+ src="$(verify_source_for "$ATTR_PLAN" "$ATTR_REPO")"; kind="${src%%$'\t'*}"; loc="${src#*$'\t'}"
353
+ case "$kind" in
354
+ lanes:*) ATTR_SOURCE="lanes:$loc" ;;
355
+ command:*) ATTR_SOURCE="command:$loc" ;;
356
+ esac
357
+ fi
358
+ if [ -z "$ATTR_SOURCE" ]; then
359
+ if [ "$force" = 1 ]; then attribute_conclude "" 0 "no verification is configured"
360
+ else attribute_conclude "" 0 "the run's verification was not recorded"; fi
361
+ return 0
362
+ fi
363
+ if [ "$ATTR_N" = 0 ]; then
364
+ attribute_conclude "" 0 "the integration branch has no merge after its base"
365
+ return 0
366
+ fi
367
+
368
+ # 1. the base
369
+ attribute_verify 0; rc=$?
370
+ [ "$rc" != 2 ] || { note "attribute: $ATTR_REASON"; return 1; }
371
+ if [ "$rc" = 1 ]; then attribute_conclude "" 0 "$ATTR_REASON"; return 0; fi
372
+ if [ "$ATTR_STATUS" = FAIL ]; then attribute_conclude "" 1 ""; return 0; fi
373
+ # 2. the tip: FAIL from the run's own verification when it is the last merge commit itself.
374
+ # With --force the tip is verified here, and when commits follow the last merge it is its own
375
+ # step (prefix n+1): a tip that passes ends the search whatever the last merge does. Prefix n
376
+ # is verified whenever the run's FAIL cannot stand for it, so a boundary is always between two
377
+ # verified merge commits.
378
+ if [ "$force" = 1 ] && [ "$(attribute_commit "$ATTR_N")" != "$ATTR_TIP" ]; then
379
+ attribute_verify "$((ATTR_N + 1))"; rc=$?
380
+ [ "$rc" != 2 ] || { note "attribute: $ATTR_REASON"; return 1; }
381
+ if [ "$rc" = 1 ]; then attribute_conclude "" 0 "$ATTR_REASON"; return 0; fi
382
+ if [ "$ATTR_STATUS" = PASS ]; then attribute_conclude "" 0 "the tip passes"; return 0; fi
383
+ fi
384
+ if [ "$force" = 1 ] || [ "$(attribute_commit "$ATTR_N")" != "$ATTR_TIP" ]; then
385
+ attribute_verify "$ATTR_N"; rc=$?
386
+ [ "$rc" != 2 ] || { note "attribute: $ATTR_REASON"; return 1; }
387
+ if [ "$rc" = 1 ]; then attribute_conclude "" 0 "$ATTR_REASON"; return 0; fi
388
+ if [ "$ATTR_STATUS" = PASS ]; then
389
+ if [ "$(attribute_commit "$ATTR_N")" = "$ATTR_TIP" ]; then attribute_conclude "" 0 "the tip passes"
390
+ else attribute_conclude "" 0 "the last merge passes: the failure comes from a commit after it, not from a merge"; fi
391
+ return 0
392
+ fi
393
+ else
394
+ attribute_record "$ATTR_N" "$ATTR_TIP" FAIL "" run
395
+ fi
396
+ # 3. the boundary between the passing base and the failing tip. In `on` the model's top suspect
397
+ # is probed first: prefix k-1 then prefix k. A pass->fail pair is a breaking merge; otherwise the
398
+ # bounds of the search narrow to the side of the suspect the failure is on.
399
+ hi="$ATTR_N"
400
+ attribute_gate_ask
401
+ if [ "$ATTR_STOP" = 1 ]; then attribute_conclude "" 0 "interrupted while asking the decision model"; return 0; fi
402
+ if [ -n "$ATTR_GUESS" ]; then
403
+ ATTR_GATE_TRIED="$(awk -F'\t' -v k="$ATTR_GUESS" '$1 == k { print $3; exit }' "$ATTR_DIR/merges.tsv")"
404
+ attribute_verify "$((ATTR_GUESS - 1))"; rc=$?
405
+ if [ "$rc" = 0 ] && [ "$ATTR_STATUS" = PASS ]; then
406
+ lo="$((ATTR_GUESS - 1))"
407
+ attribute_verify "$ATTR_GUESS"; rc=$?
408
+ if [ "$rc" = 0 ] && [ "$ATTR_STATUS" = FAIL ]; then
409
+ ATTR_GATE_OUTCOME=confirmed; attribute_gate_save
410
+ attribute_conclude "$ATTR_GUESS" 0 ""
411
+ return 0
412
+ elif [ "$rc" = 0 ]; then lo="$ATTR_GUESS"; ATTR_GATE_OUTCOME=refuted; fi
413
+ elif [ "$rc" = 0 ]; then hi="$((ATTR_GUESS - 1))"; ATTR_GATE_OUTCOME=refuted; fi
414
+ attribute_gate_save
415
+ [ "$rc" != 2 ] || { note "attribute: $ATTR_REASON"; return 1; }
416
+ if [ "$rc" = 1 ]; then attribute_conclude "" 0 "$ATTR_REASON"; return 0; fi
417
+ fi
418
+ attribute_bisect "$lo" "$hi"; rc=$?
419
+ [ "$rc" != 2 ] || { note "attribute: $ATTR_REASON"; return 1; }
420
+ if [ "$rc" = 1 ]; then attribute_conclude "" 0 "$ATTR_REASON"; return 0; fi
421
+ attribute_conclude "$ATTR_HI" 0 ""
422
+ return 0
423
+ }
424
+
425
+ # forge-parallel.sh attribute <plan> [--force]
426
+ do_attribute() {
427
+ local PLAN="${1:?attribute needs a plan dir}"; shift
428
+ local force=0 job="" rc=0 stopped=0
429
+ while [ $# -gt 0 ]; do
430
+ case "$1" in
431
+ --force) force=1; shift ;;
432
+ *) die "attribute: unknown option '$1'" ;;
433
+ esac
434
+ done
435
+ # The plan's frozen decision selection (--gate, --no-gates, budget), as `run` and `retry` restore it:
436
+ # the gate resolves as it did in the run, never from whatever this shell has today.
437
+ [ "${JEV_OPTS:-0}" = 1 ] && [ -d "$PLAN" ] && forge_jev_restore "$PLAN"
438
+ # A job this shell can stop: a TERM here reaches the search, which stops its verification.
439
+ trap 'stopped=1; [ -n "$job" ] && kill -TERM "$job" 2>/dev/null' TERM INT
440
+ ( attribute_search "$PLAN" "$force" ) <&0 &
441
+ job=$!
442
+ [ "$stopped" = 1 ] && kill -TERM "$job" 2>/dev/null
443
+ run_wait "$job"; rc=$run_rc
444
+ trap - TERM INT
445
+ [ "$stopped" = 1 ] && [ "$rc" -gt 128 ] && rc=130
446
+ return "$rc"
447
+ }
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env bash
2
+ # Where run-time gates plug into do_task_body. Sourced by forge-parallel.sh next to forge-lib-task.sh.
3
+ #
4
+ # Each hook calls its gate only when the gate is defined, so a forge without the gate files runs
5
+ # exactly as before. A gate returns 1 when it sent the attempt back (it has written the status and
6
+ # the notes); the hook passes that on and the call site ends the attempt. Any other failure of a
7
+ # gate (exit 2 and up) counts as "did not act": gates fail open.
8
+
9
+ forge_gates_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
10
+ for forge_gate_file in forge-gate-message.sh forge-gate-addressed.sh; do
11
+ [ -f "$forge_gates_dir/$forge_gate_file" ] && source "$forge_gates_dir/$forge_gate_file"
12
+ done
13
+ unset forge_gate_file
14
+
15
+ # After the dwarf's reply is in, before the diff snapshot and its empty-diff exits: a dwarf that
16
+ # only asks a question usually changes nothing, and must still reach the gate.
17
+ forge_post_dwarf_gates() { # forge_post_dwarf_gates <plan> <id> <tdir> <wt> <attempt>
18
+ declare -F forge_gate_message >/dev/null || return 0
19
+ local rc=0
20
+ forge_gate_message "$@" || rc=$?
21
+ [ "$rc" -eq 1 ] && return 1
22
+ return 0
23
+ }
24
+
25
+ # After reviewed.commit and reviewed.dwarf.* are written for a fresh dwarf, before QA is dispatched.
26
+ forge_pre_qa_gates() { # forge_pre_qa_gates <plan> <id> <tdir> <wt> <attempt> <reviewed>
27
+ declare -F forge_gate_addressed >/dev/null || return 0
28
+ local rc=0
29
+ forge_gate_addressed "$@" || rc=$?
30
+ [ "$rc" -eq 1 ] && return 1
31
+ return 0
32
+ }
@@ -130,7 +130,7 @@ plans_make_integration() { # plans_make_integration <repo> <branch> <commit> <wt
130
130
 
131
131
  # Per-plan option files carried to a derived plan. The cost-bearing choices a user made
132
132
  # for this plan apply to the plan made from it; `planner` does not (nothing plans again).
133
- PLANS_OPTION_FILES="no_ripwire no_memory yolo_dwarf yolo_qa reviewer_session qa_threshold timeout verify_retries verify_cmd verify_parallel setup_cmd final_qa shadow_qa shadow_rate explore escalate_after fractal-routing.json fractal-selection.json jev-selection.json"
133
+ PLANS_OPTION_FILES="no_ripwire no_memory yolo_dwarf yolo_qa reviewer_session implementer_session pre_review_tests pre_review_parallel qa_threshold timeout verify_retries verify_cmd verify_parallel setup_cmd final_qa shadow_qa shadow_rate explore escalate_after fractal-routing.json fractal-selection.json jev-selection.json"
134
134
 
135
135
  # --- accept ---------------------------------------------------------------------
136
136
  # A reviewer's FAIL is the QA gate; overriding it is the user's call and never forge's or
@@ -225,10 +225,16 @@ do_accept() {
225
225
  sha="$(cat "$tdir/reviewed.commit")"
226
226
  body="$(plans_reviewer_text "$tdir" "$st")"
227
227
  n="$(printf '%s\n' "$body" | grep -c '^- ')"
228
+ local gthr gdec
229
+ IFS="$(printf '\t')" read -r gthr gdec _ < "$tdir/qa.gate" 2>/dev/null || true
228
230
  rm -f "$kibak"; [ -f "$ki" ] && cp -p "$ki" "$kibak"
229
231
  {
230
232
  if [ -s "$ki" ]; then cat "$ki"; echo; fi
231
- echo "## Accepted by a human despite the reviewer's $st verdict"
233
+ if [ "${gdec:-}" = fail ]; then
234
+ echo "## Accepted by a human despite forge's FAIL (the reviewer said PASS, but listed findings at or above $gthr)"
235
+ else
236
+ echo "## Accepted by a human despite the reviewer's $st verdict"
237
+ fi
232
238
  echo
233
239
  echo "Reason: $reason"
234
240
  echo "Accepted by $who on $when (task $id, attempt $attempt, reviewed commit ${sha:0:12})."
@@ -249,6 +255,7 @@ do_accept() {
249
255
  echo "epoch=$(date +%s)"
250
256
  echo "attempt=$attempt"
251
257
  echo "reviewed_commit=$sha"
258
+ [ "${gdec:-}" != fail ] || echo "gate=fail"
252
259
  } > "$tdir/accepted.by"
253
260
  echo PASS > "$tdir/status"
254
261
 
@@ -505,7 +512,7 @@ Retry or accept them (or split them off into their own plan) first." 3
505
512
  [ "$ok" = 1 ] || { plans_undo; trap - INT TERM; die "could not write the combined plan" 3; }
506
513
 
507
514
  # Options: a plan-wide choice carries over when every source made it identically; the
508
- # permission flags and the reviewer-session experiment only when every source chose them.
515
+ # permission flags, session continuation and pre-review tests only when every source chose them.
509
516
  local goals="" g
510
517
  for p in "${SRC[@]}"; do
511
518
  if [ -s "$p/goal.txt" ]; then g="$(tr '\n' ' ' < "$p/goal.txt" | sed 's/ *$//')"; else g="$(basename "$p")"; fi
@@ -522,9 +529,13 @@ Retry or accept them (or split them off into their own plan) first." 3
522
529
  done
523
530
  # Same gate as the permission flags. The file holds `on`, which is what `plan` writes
524
531
  # and what the dataset records; readers only test that the file exists.
525
- all=1; for p in "${SRC[@]}"; do [ -f "$p/reviewer_session" ] || all=0; done
526
- [ "$all" = 1 ] && printf '%s\n' on > "$NEW/reviewer_session"
527
- for f in qa_threshold timeout verify_retries verify_parallel; do
532
+ for f in reviewer_session implementer_session; do
533
+ all=1; for p in "${SRC[@]}"; do [ -f "$p/$f" ] || all=0; done
534
+ [ "$all" = 1 ] && printf '%s\n' on > "$NEW/$f"
535
+ done
536
+ all=1; for p in "${SRC[@]}"; do [ -f "$p/pre_review_tests" ] || all=0; done
537
+ [ "$all" = 1 ] && : > "$NEW/pre_review_tests"
538
+ for f in qa_threshold timeout verify_retries verify_parallel pre_review_parallel; do
528
539
  same=1
529
540
  for p in "${SRC[@]}"; do
530
541
  if [ ! -f "$p/$f" ] || ! cmp -s "$p/$f" "${SRC[0]}/$f"; then same=0; fi
@@ -38,9 +38,8 @@ REVIEW_SINCE_LIMIT=204800 # largest "changes since the previous review" plac
38
38
  REVIEW_DIFF_LIMIT=409600 # largest combined diff placed inline in the prompt
39
39
 
40
40
  # --- small helpers ---------------------------------------------------------------------
41
- review_threshold() { # the plan-level blocking threshold, or nothing
42
- [ -s "$1/qa_threshold" ] && head -1 "$1/qa_threshold" | tr -d ' \r'
43
- return 0
41
+ review_threshold() { # the plan-level blocking threshold: the plan file, else the default; always a value
42
+ qa_threshold_for "$1" ""
44
43
  }
45
44
 
46
45
  review_yolo_flag() { # review_yolo_flag <plan> [force] -> "--yolo" or nothing
@@ -360,7 +359,7 @@ PY
360
359
  # it is called from inside do_integrate.
361
360
  final_review() {
362
361
  local plan="$1" base="$2" tip="$3" src="$4" out="$5" spec="$6" yolo="${7:-}"
363
- local review n rc verdict thr gate_line source_fp review_fp vdir tflag="" inline=1 diff_n
362
+ local review n rc verdict thr gate_line gate_forced source_fp review_fp vdir tflag="" inline=1 diff_n
364
363
  local plan_real prev="" prev_rel=none prev_tip="" since=none integration="" prev_note=""
365
364
  [ -n "$yolo" ] && yolo=--yolo
366
365
  [ -n "$spec" ] || { note "final review: no QA spec given"; return 3; }
@@ -394,7 +393,7 @@ final_review() {
394
393
  while [ -e "$review" ]; do n=$((n+1)); review="$out/review-$$-$n"; done
395
394
  forge_review_snapshot "$src" "$base" "$tip" "$review" > "$out/snapshot.log" 2>&1 ||
396
395
  { note "final review: cannot build the review snapshot (see $out/snapshot.log)"; return 3; }
397
- source_fp="$(forge_fingerprint "$src")" && review_fp="$(forge_fingerprint "$review")" ||
396
+ source_fp="$(forge_fingerprint "$src")" && review_fp="$(forge_fingerprint "$review" --tracked)" ||
398
397
  { note "final review: cannot fingerprint the checkouts"; return 3; }
399
398
  printf '%s\n' "$source_fp" > "$out/source.fingerprint"
400
399
  printf '%s\n' "$review_fp" > "$out/review.fingerprint"
@@ -424,7 +423,7 @@ final_review() {
424
423
  { note "final review: cannot assemble the review context"; return 3; }
425
424
 
426
425
  # At most the limit plus one byte is ever read, so an enormous change cannot fill the disk.
427
- git -C "$src" diff --binary "$base" "$tip" -- . ':(exclude).forge' 2>/dev/null |
426
+ git -C "$src" diff --binary --irreversible-delete "$base" "$tip" -- . ':(exclude).forge' 2>/dev/null |
428
427
  head -c $((REVIEW_DIFF_LIMIT + 1)) > "$out/combined.diff"
429
428
  diff_n="$(wc -c < "$out/combined.diff" | tr -d ' ')"
430
429
  if [ "$diff_n" -gt "$REVIEW_DIFF_LIMIT" ]; then inline=0; rm -f "$out/combined.diff"; fi
@@ -443,7 +442,7 @@ final_review() {
443
442
  echo "There are no changes since that review: it judged this same commit."
444
443
  else
445
444
  echo "### Changes since that review ($(printf '%.7s' "$since")..$(printf '%.7s' "$tip"))"
446
- git -C "$src" diff --binary "$since" "$tip" -- . ':(exclude).forge' 2>/dev/null |
445
+ git -C "$src" diff --binary --irreversible-delete "$since" "$tip" -- . ':(exclude).forge' 2>/dev/null |
447
446
  head -c $((REVIEW_SINCE_LIMIT + 1)) > "$out/since.diff"
448
447
  if [ "$inline" = 1 ] && [ "$(wc -c < "$out/since.diff" | tr -d ' ')" -le "$REVIEW_SINCE_LIMIT" ] &&
449
448
  ! grep -q '```diff' "$out/since.diff"; then
@@ -467,7 +466,7 @@ final_review() {
467
466
  echo
468
467
  cat "$out/notes.md"
469
468
  [ -s "$out/previous.md" ] && cat "$out/previous.md"
470
- python3 "$SKILL_DIR/scripts/forge-contract.py" qa --part tail --kind final ${thr:+--threshold "$thr"}
469
+ python3 "$SKILL_DIR/scripts/forge-contract.py" qa --part tail --kind final --threshold "$thr"
471
470
  echo
472
471
  if [ "$inline" = 1 ]; then
473
472
  echo '```diff'; cat "$out/combined.diff"; echo '```'
@@ -537,7 +536,7 @@ final_review() {
537
536
  return 5 ;;
538
537
  esac
539
538
 
540
- if [ "$(forge_fingerprint "$src")" != "$source_fp" ] || [ "$(forge_fingerprint "$review")" != "$review_fp" ]; then
539
+ if [ "$(forge_fingerprint "$src")" != "$source_fp" ] || [ "$(forge_fingerprint "$review" --tracked)" != "$review_fp" ]; then
541
540
  printf 'INVALIDATED\n' > "$out/verdict"
542
541
  note "final review: the checkout changed while the reviewer ran; the review is invalid"
543
542
  echo
@@ -549,15 +548,17 @@ final_review() {
549
548
  verdict=""
550
549
  [ -s "$out/qa.last" ] && verdict="$(forge_verdict "$out/qa.last")"
551
550
  verdict="${verdict:-UNKNOWN}"
552
- if [ -n "$thr" ]; then
553
- # Same gate as per-task QA: a FAIL made only of labelled findings below the threshold
554
- # is accepted with known issues; anything unlabelled stays blocking.
555
- gate_line="$(python3 "$SKILL_DIR/scripts/forge-contract.py" gate --verdict "$verdict" \
556
- --qa-last "$out/qa.last" --threshold "$thr" --known-issues "$out/known_issues.md" 2>/dev/null)" || gate_line=""
557
- if [ -n "$gate_line" ]; then
558
- printf '%s\t%s\n' "$thr" "$gate_line" > "$out/qa.gate"
559
- if [ "$(printf '%s' "$gate_line" | awk -F'\t' '{print $1}')" = accept ]; then verdict=ACCEPTED; fi
560
- fi
551
+ # Same gate as per-task QA, both ways: a FAIL made only of labelled findings below the
552
+ # threshold is accepted with known issues; a PASS listing a blocking CONFIRMED finding fails.
553
+ gate_line="$(python3 "$SKILL_DIR/scripts/forge-contract.py" gate --verdict "$verdict" \
554
+ --qa-last "$out/qa.last" --threshold "$thr" --known-issues "$out/known_issues.md" 2>/dev/null)" || gate_line=""
555
+ gate_forced=""
556
+ if [ -n "$gate_line" ]; then
557
+ printf '%s\t%s\n' "$thr" "$gate_line" > "$out/qa.gate"
558
+ case "$(printf '%s' "$gate_line" | awk -F'\t' '{print $1}')" in
559
+ accept) verdict=ACCEPTED ;;
560
+ fail) [ "$verdict" = PASS ] && { verdict=FAIL; gate_forced=1; } ;;
561
+ esac
561
562
  fi
562
563
  printf '%s\n' "$verdict" > "$out/verdict"
563
564
 
@@ -571,7 +572,11 @@ final_review() {
571
572
  echo " known issues: $out/known_issues.md"
572
573
  echo " report: $out/qa.last" ;;
573
574
  FAIL)
574
- echo "final review ($spec): verdict FAIL (blocking) — the reviewer confirmed at least one defect in the combined result."
575
+ if [ -n "$gate_forced" ]; then
576
+ echo "final review ($spec): verdict FAIL (blocking) — the reviewer said PASS, but listed a CONFIRMED finding at or above the $thr threshold — forge made it FAIL."
577
+ else
578
+ echo "final review ($spec): verdict FAIL (blocking) — the reviewer confirmed at least one defect in the combined result."
579
+ fi
575
580
  echo " findings: $out/qa.last" ;;
576
581
  *)
577
582
  echo "final review ($spec): verdict UNKNOWN (blocking) — the reviewer ended without a FORGE_VERDICT line, so nothing was concluded."