@giamme/forge 0.20.0 → 0.22.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.
- package/CHANGELOG.md +36 -0
- package/README.md +13 -3
- package/VERSION +1 -1
- package/bin/forge.js +104 -0
- package/docs/README.md +1 -0
- package/docs/development.md +1 -1
- package/docs/install.md +91 -2
- package/docs/reviews.md +6 -4
- package/docs/troubleshooting.md +1 -1
- package/forge +4 -0
- package/forge.cmd +56 -0
- package/package.json +5 -3
- package/scripts/forge-artifact.sh +5 -1
- package/scripts/forge-config.py +10 -9
- package/scripts/forge-control.py +61 -38
- package/scripts/forge-dispatch.sh +108 -31
- package/scripts/forge-group.py +2 -1
- package/scripts/forge-guard.py +207 -38
- package/scripts/forge-handoff.py +14 -17
- package/scripts/forge-install.sh +82 -9
- package/scripts/forge-issues.py +5 -2
- package/scripts/forge-lib-env.sh +158 -0
- package/scripts/forge-lib-group.sh +5 -5
- package/scripts/forge-lib-plans.sh +8 -3
- package/scripts/forge-lib-task.sh +40 -15
- package/scripts/forge-memory.sh +2 -0
- package/scripts/forge-metrics.sh +6 -1
- package/scripts/forge-parallel.sh +174 -53
- package/scripts/forge-planner.py +28 -2
- package/scripts/forge-pre-review.py +11 -4
- package/scripts/forge-ripwire.py +68 -22
- package/scripts/forge-route.py +10 -3
- package/scripts/forge-runs-compact.py +3 -2
- package/scripts/forge-runs-rm.py +14 -14
- package/scripts/forge-runtime.py +38 -21
- package/scripts/forge-schedule.py +90 -56
- package/scripts/forge-shadow.py +16 -9
- package/scripts/forge-solo.sh +6 -2
- package/scripts/forge-summarize.py +7 -3
- package/scripts/forge-sweep.py +8 -3
- package/scripts/forge-ui.py +8 -13
- package/scripts/forge-update.sh +6 -1
- package/scripts/forge-verify.py +30 -23
- package/scripts/forge-win.sh +156 -0
- package/scripts/forge_brief/__init__.py +7 -2
- package/scripts/forge_brief/proposals.py +13 -3
- package/scripts/forge_decide/budget.py +18 -8
- package/scripts/forge_decide/replay.py +15 -5
- package/scripts/forge_findings/apply.py +2 -1
- package/scripts/forge_findings/store.py +16 -4
- package/scripts/forge_findings/triage.py +6 -15
- package/scripts/forge_flock.py +102 -0
- package/scripts/forge_fractal/__init__.py +7 -3
- package/scripts/forge_fractal/cli.py +7 -2
- package/scripts/forge_fractal/execution.py +14 -14
- package/scripts/forge_fractal/invocation.py +3 -2
- package/scripts/forge_fractal/pipeline.py +2 -1
- package/scripts/forge_fractal/selection.py +2 -1
- package/scripts/forge_identity.py +2 -1
- package/scripts/forge_locations.py +14 -4
- package/scripts/forge_posix.py +125 -0
- package/scripts/forge_proc.py +507 -0
- package/scripts/forge_registry.py +17 -8
- package/scripts/forge_retro/__init__.py +8 -2
- package/scripts/forge_retro/issues.py +2 -1
- package/scripts/forge_side/__init__.py +32 -14
- package/scripts/forge_storage.py +11 -1
- package/ui/forge_ui/control.py +42 -14
- package/ui/forge_ui/reader.py +24 -18
- package/ui/forge_ui/server.py +10 -1
- package/ui/forge_ui/static/scene3d.js +23 -2
|
@@ -172,6 +172,10 @@ set -uo pipefail
|
|
|
172
172
|
|
|
173
173
|
SELF="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/$(basename "${BASH_SOURCE[0]}")"
|
|
174
174
|
SKILL_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
175
|
+
# Windows: re-run inside MSYS2 when started from Git Bash (no-op elsewhere).
|
|
176
|
+
. "$SKILL_DIR/scripts/forge-win.sh"
|
|
177
|
+
source "$SKILL_DIR/scripts/forge-lib-env.sh"
|
|
178
|
+
forge_ensure_python3
|
|
175
179
|
DISPATCH="$SKILL_DIR/scripts/forge-dispatch.sh"
|
|
176
180
|
MEMORY="$SKILL_DIR/scripts/forge-memory.sh"
|
|
177
181
|
source "$SKILL_DIR/scripts/forge-artifact.sh"
|
|
@@ -209,6 +213,13 @@ field() { # field <tasks.tsv> <id> <colname>
|
|
|
209
213
|
}
|
|
210
214
|
all_ids() { awk -F'\t' '!/^#/ && NF {print $1}' "$1"; }
|
|
211
215
|
|
|
216
|
+
render_results_table() { # render_results_table <plan>
|
|
217
|
+
local w
|
|
218
|
+
w="$(id_col_width "$1/results.tsv" "$1/tasks.tsv")"
|
|
219
|
+
printf ' %-*s %-14s %s\n' "$w" id status branch
|
|
220
|
+
awk -F'\t' -v w="$w" '{printf " %-*s %-14s %s\n", w, $1, $2, $3}' "$1/results.tsv"
|
|
221
|
+
}
|
|
222
|
+
|
|
212
223
|
list_has() { # list_has <needle> <comma-list>
|
|
213
224
|
local n="$1" l="$2" w
|
|
214
225
|
[ "$l" = "-" ] && return 1
|
|
@@ -1106,8 +1117,14 @@ EOF
|
|
|
1106
1117
|
fi
|
|
1107
1118
|
fi
|
|
1108
1119
|
|
|
1109
|
-
|
|
1110
|
-
|
|
1120
|
+
# A refused plan (a task left UNASSIGNED below) puts tasks.tsv back as it was, so nothing it
|
|
1121
|
+
# routed, such as the default reviewer, is frozen into the next plan (#178). The copy is only
|
|
1122
|
+
# made for a refusal, under one name, so an exit in between leaves at most this one file,
|
|
1123
|
+
# which the next plan removes.
|
|
1124
|
+
local tmp="$PLAN/.tasks.tsv.new" orig_tasks="$PLAN/.tasks.tsv.orig"
|
|
1125
|
+
: > "$tmp"
|
|
1126
|
+
rm -f "$orig_tasks"
|
|
1127
|
+
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 qa_kept_msg="" qa_flag_spec=""
|
|
1111
1128
|
printf '# id\tdeps\tdifficulty\tfiles\tdwarf\tqa\ttitle\n' > "$tmp"
|
|
1112
1129
|
local id deps diff files dw qa title line
|
|
1113
1130
|
while IFS= read -r line; do
|
|
@@ -1169,16 +1186,27 @@ EOF
|
|
|
1169
1186
|
if [ "$qa" = "-" ] || [ -z "$qa" ]; then
|
|
1170
1187
|
if [ -n "$Q_ANY" ]; then qa="$(pool_pick "$Q_ANY" "$qan_i")"; qan_i=$((qan_i+1)); else qa="opus"; fi
|
|
1171
1188
|
fi
|
|
1189
|
+
else
|
|
1190
|
+
qa_flag_spec=""
|
|
1191
|
+
case "$diff" in
|
|
1192
|
+
high) qa_flag_spec="${Q_HI:-$Q_ANY}" ;;
|
|
1193
|
+
medium) qa_flag_spec="${Q_MD:-$Q_ANY}" ;;
|
|
1194
|
+
low) qa_flag_spec="${Q_LO:-$Q_ANY}" ;;
|
|
1195
|
+
esac
|
|
1196
|
+
if [ -n "$qa_flag_spec" ] && ! list_has "$qa" "$qa_flag_spec"; then
|
|
1197
|
+
qa_kept_msg="${qa_kept_msg:+$qa_kept_msg, }$id ($qa)"
|
|
1198
|
+
fi
|
|
1172
1199
|
fi
|
|
1173
1200
|
# A column runs one spec; a list there would only fail later, at its first dispatch.
|
|
1174
1201
|
case "$dw" in *,*) die "task '$id': the dwarf column names one spec, not a list ('$dw'); pool models with a --dwarf flag" ;; esac
|
|
1175
1202
|
case "$qa" in *,*) die "task '$id': the qa column names one spec, not a list ('$qa'); pool reviewers with a --qa flag" ;; esac
|
|
1176
1203
|
printf '%s\t%s\t%s\t%s\t%s\t%s\t%s\n' "$id" "$deps" "$diff" "$files" "$dw" "$qa" "$title" >> "$tmp"
|
|
1177
1204
|
done < "$T"
|
|
1205
|
+
[ "$unassigned" -eq 0 ] || cp "$T" "$orig_tasks"
|
|
1178
1206
|
mv "$tmp" "$T"
|
|
1179
1207
|
# Which cells routing filled in, so a re-plan under another profile replaces those and no others.
|
|
1180
1208
|
# Kept current through a --no-profile re-plan too, once a profile has recorded any.
|
|
1181
|
-
if [ -f "$PLAN/profile.json" ] || [ -f "$PLAN/routed.json" ]; then
|
|
1209
|
+
if [ "$unassigned" -eq 0 ] && { [ -f "$PLAN/profile.json" ] || [ -f "$PLAN/routed.json" ]; }; then
|
|
1182
1210
|
forge_profile_py routed "$PLAN" 2>/dev/null || true
|
|
1183
1211
|
fi
|
|
1184
1212
|
|
|
@@ -1239,6 +1267,10 @@ EOF
|
|
|
1239
1267
|
forge_groups_plan "$PLAN" "$GRP_SRC" "$GRP_REVIEW" "$GRP_MAX"
|
|
1240
1268
|
|
|
1241
1269
|
render_table "$PLAN"
|
|
1270
|
+
if [ -n "$qa_kept_msg" ]; then
|
|
1271
|
+
echo "note: --qa left existing reviewer(s) unchanged on: $qa_kept_msg (set qa to '-' in tasks.tsv to let --qa fill them)"
|
|
1272
|
+
echo
|
|
1273
|
+
fi
|
|
1242
1274
|
# What the gates did, from plan-gates.json: files and deps they added, prompts and
|
|
1243
1275
|
# requirements still flagged. Prints nothing when no gate recorded anything.
|
|
1244
1276
|
python3 "$SKILL_DIR/scripts/forge-plan-check.py" gates "$PLAN" 2>/dev/null || true
|
|
@@ -1253,6 +1285,7 @@ EOF
|
|
|
1253
1285
|
forge_ui_launch "$PLAN"
|
|
1254
1286
|
|
|
1255
1287
|
if [ "$unassigned" -gt 0 ]; then
|
|
1288
|
+
mv -f "$orig_tasks" "$T"
|
|
1256
1289
|
note ""
|
|
1257
1290
|
note "$unassigned task(s) are UNASSIGNED: their difficulty tier has no --dwarf-<tier>"
|
|
1258
1291
|
note "rule and there is no plain --dwarf fallback. Assign them before running —"
|
|
@@ -1428,23 +1461,25 @@ EOF
|
|
|
1428
1461
|
echo "QA effort: high where a reviewer spec names none (forge-dispatch.sh's default; planning stays at xhigh)"
|
|
1429
1462
|
fi
|
|
1430
1463
|
echo
|
|
1431
|
-
local w id dws starred=0
|
|
1464
|
+
local w id dws starred=0 id_w pad
|
|
1465
|
+
id_w="$(id_col_width "$T")"
|
|
1466
|
+
printf -v pad '%*s' $((id_w + 3)) ''
|
|
1432
1467
|
for w in $(awk -F'\t' '{print $1}' "$W" | sort -un); do
|
|
1433
1468
|
local cnt; cnt="$(awk -F'\t' -v w="$w" '$1==w' "$W" | wc -l | tr -d ' ')"
|
|
1434
1469
|
echo "wave $w ($cnt parallel)"
|
|
1435
|
-
printf '
|
|
1470
|
+
printf ' %-*s %-7s %-24s %-14s %s\n' "$id_w" id diff dwarf qa files
|
|
1436
1471
|
for id in $(awk -F'\t' -v w="$w" '$1==w {print $2}' "$W"); do
|
|
1437
1472
|
dws="$(field "$T" "$id" dwarf)"
|
|
1438
1473
|
if [ -s "$PLAN/tasks/$id/route.explored" ] && [ "$(cat "$PLAN/tasks/$id/route.explored")" = "$dws" ]; then
|
|
1439
1474
|
dws="$dws*"; starred=1
|
|
1440
1475
|
fi
|
|
1441
|
-
printf '
|
|
1442
|
-
"$id" "$(field "$T" "$id" difficulty)" "$dws" \
|
|
1476
|
+
printf ' %-*s %-7s %-24s %-14s %s\n' \
|
|
1477
|
+
"$id_w" "$id" "$(field "$T" "$id" difficulty)" "$dws" \
|
|
1443
1478
|
"$(field "$T" "$id" qa)" "$(field "$T" "$id" files)"
|
|
1444
1479
|
# The approach is shown here because this gate is the only moment a human can
|
|
1445
1480
|
# change the plan for free. After dispatch, changing it costs a whole run.
|
|
1446
1481
|
if [ -s "$PLAN/tasks/$id/approach.md" ]; then
|
|
1447
|
-
sed
|
|
1482
|
+
sed "s/^/${pad}| /" "$PLAN/tasks/$id/approach.md"
|
|
1448
1483
|
fi
|
|
1449
1484
|
done
|
|
1450
1485
|
echo
|
|
@@ -1593,12 +1628,14 @@ write_capsule() { # write_capsule <plan> <id> <role>
|
|
|
1593
1628
|
echo "Files this task owns: $(field "$T" "$me" files)"
|
|
1594
1629
|
echo
|
|
1595
1630
|
echo "## Run status"
|
|
1596
|
-
|
|
1631
|
+
local id_w
|
|
1632
|
+
id_w="$(id_col_width "$T")"
|
|
1633
|
+
printf '%-*s %-7s %-11s %s\n' "$id_w" id diff status files
|
|
1597
1634
|
for id in $(all_ids "$T"); do
|
|
1598
1635
|
if [ "$id" = "$me" ]; then st="THIS ONE"
|
|
1599
1636
|
elif [ -s "$PLAN/tasks/$id/reviewed.commit" ] && git -C "$(cat "$PLAN/repo")" merge-base --is-ancestor "$(cat "$PLAN/tasks/$id/reviewed.commit")" "$(cat "$PLAN/tasks/$me/base_ref")"; then st=MERGED
|
|
1600
1637
|
else st="NOT IN BASE"; fi
|
|
1601
|
-
printf '
|
|
1638
|
+
printf '%-*s %-7s %-11s %s\n' "$id_w" "$id" "$(field "$T" "$id" difficulty)" "$st" "$(field "$T" "$id" files)"
|
|
1602
1639
|
done
|
|
1603
1640
|
echo
|
|
1604
1641
|
echo "## Ground rules"
|
|
@@ -1688,18 +1725,26 @@ run_worktree_setup() { # run_worktree_setup <plan> <repo> <wt> <tdir> <id>
|
|
|
1688
1725
|
fi
|
|
1689
1726
|
}
|
|
1690
1727
|
|
|
1728
|
+
add_task_worktree() { # add_task_worktree <repo> <wt> <br> <base>: on <br> when it exists, else a new <br> at <base>
|
|
1729
|
+
if (cd "$1" && git rev-parse --verify --quiet "$3" >/dev/null 2>&1); then
|
|
1730
|
+
(cd "$1" && git worktree add "$2" "$3")
|
|
1731
|
+
else
|
|
1732
|
+
(cd "$1" && git worktree add -b "$3" "$2" "$4")
|
|
1733
|
+
fi
|
|
1734
|
+
}
|
|
1735
|
+
|
|
1691
1736
|
ensure_worktree() { # ensure_worktree <repo> <wt> <br> <base> <tdir> <plan> <id>
|
|
1692
1737
|
local REPO="$1" wt="$2" br="$3" base="$4" tdir="$5" PLAN="$6" id="$7"
|
|
1693
|
-
|
|
1694
|
-
#
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1738
|
+
[ ! -e "$wt/.git" ] || return 0
|
|
1739
|
+
# A worktree directory deleted by hand leaves its registration behind, and that registration
|
|
1740
|
+
# blocks `worktree add` with "already exists": prune, then add again. Only after a failed add:
|
|
1741
|
+
# tasks start together, and a prune while another task's add is midway removes that task's
|
|
1742
|
+
# half-made registration ("could not open '.git/worktrees/<id>/gitdir'"). The second add also
|
|
1743
|
+
# recovers from a prune that another forge process ran at that moment.
|
|
1744
|
+
add_task_worktree "$REPO" "$wt" "$br" "$base" >"$tdir/worktree.out" 2>&1 || {
|
|
1745
|
+
(cd "$REPO" && git worktree prune >/dev/null 2>&1)
|
|
1746
|
+
add_task_worktree "$REPO" "$wt" "$br" "$base" >>"$tdir/worktree.out" 2>&1
|
|
1747
|
+
} || return 1
|
|
1703
1748
|
forge_worktree_event created "$PLAN" "$REPO" "$wt" "$br" task "$id"
|
|
1704
1749
|
run_worktree_setup "$PLAN" "$REPO" "$wt" "$tdir" "$id"
|
|
1705
1750
|
}
|
|
@@ -1779,6 +1824,35 @@ record_dispatched_inputs() { # record_dispatched_inputs <tdir>
|
|
|
1779
1824
|
done
|
|
1780
1825
|
}
|
|
1781
1826
|
|
|
1827
|
+
# Brief inputs the last completed review judged (#209), written in reverse order so
|
|
1828
|
+
# prompt.reviewed's presence marks the snapshot complete.
|
|
1829
|
+
record_reviewed_inputs() { # record_reviewed_inputs <tdir> <thr>
|
|
1830
|
+
local tdir="$1" thr="${2:-}" f tmp
|
|
1831
|
+
tmp="$tdir/.approach.reviewed.tmp"
|
|
1832
|
+
if [ -f "$tdir/approach.md" ]; then cp "$tdir/approach.md" "$tmp" || { rm -f "$tmp"; return 1; }
|
|
1833
|
+
else : > "$tmp" || return 1; fi
|
|
1834
|
+
mv "$tmp" "$tdir/approach.reviewed" || { rm -f "$tmp"; return 1; }
|
|
1835
|
+
tmp="$tdir/.qa.reviewed.threshold.tmp"
|
|
1836
|
+
printf '%s\n' "$thr" > "$tmp" && mv "$tmp" "$tdir/qa.reviewed.threshold" || { rm -f "$tmp"; return 1; }
|
|
1837
|
+
tmp="$tdir/.prompt.reviewed.tmp"
|
|
1838
|
+
if [ -f "$tdir/prompt.md" ]; then cp "$tdir/prompt.md" "$tmp" || { rm -f "$tmp"; return 1; }
|
|
1839
|
+
else : > "$tmp" || return 1; fi
|
|
1840
|
+
mv "$tmp" "$tdir/prompt.reviewed" || { rm -f "$tmp"; return 1; }
|
|
1841
|
+
}
|
|
1842
|
+
|
|
1843
|
+
brief_changed_since_review() { # brief_changed_since_review <tdir> <thr> -> 0 when changed
|
|
1844
|
+
local tdir="$1" thr="${2:-}" f cur
|
|
1845
|
+
[ -f "$tdir/prompt.reviewed" ] || return 1
|
|
1846
|
+
for f in prompt approach; do
|
|
1847
|
+
cur="$tdir/$f.md"; [ -f "$cur" ] || cur=/dev/null
|
|
1848
|
+
cmp -s "$tdir/$f.reviewed" "$cur" || return 0
|
|
1849
|
+
done
|
|
1850
|
+
if [ -f "$tdir/qa.reviewed.threshold" ]; then
|
|
1851
|
+
[ "$(cat "$tdir/qa.reviewed.threshold" 2>/dev/null)" = "$thr" ] || return 0
|
|
1852
|
+
fi
|
|
1853
|
+
return 1
|
|
1854
|
+
}
|
|
1855
|
+
|
|
1782
1856
|
# Whether the planner edited prompt.md or approach.md while the attempt ran (#150). Returns 0 when it did:
|
|
1783
1857
|
# the attempt is then STALE, written to stale.diff and control.log, and the caller stops before any review.
|
|
1784
1858
|
# Returns 1 when nothing changed, or when the attempt predates the .dispatched copies (no check possible).
|
|
@@ -1968,7 +2042,7 @@ do_task_body() (
|
|
|
1968
2042
|
base="$(git -C "$(cat "$PLAN/wt_root")/_integration" rev-parse HEAD)"; printf '%s\n' "$base" > "$tdir/base_ref"
|
|
1969
2043
|
fi
|
|
1970
2044
|
|
|
1971
|
-
local dw qa yd yq rc ft_dwarf ft_qa
|
|
2045
|
+
local dw qa yd yq rc ft_dwarf ft_qa qa_thr
|
|
1972
2046
|
dw="$(field "$T" "$id" dwarf)"; qa="$(field "$T" "$id" qa)"
|
|
1973
2047
|
yd=""; yq=""
|
|
1974
2048
|
[ -f "$PLAN/yolo_dwarf" ] && yd="--yolo"
|
|
@@ -1976,6 +2050,8 @@ do_task_body() (
|
|
|
1976
2050
|
# Empty when the role is not listed, so the recorded command line is unchanged.
|
|
1977
2051
|
ft_dwarf="$(forge_fast_tier "$PLAN" dwarf)"
|
|
1978
2052
|
ft_qa="$(forge_fast_tier "$PLAN" qa)"
|
|
2053
|
+
# Read once per attempt: governs brief-change re-review (#209), the QA prompt, and qa_gate.
|
|
2054
|
+
qa_thr="$(qa_threshold_for "$PLAN" "$id")"
|
|
1979
2055
|
|
|
1980
2056
|
if ! ensure_worktree "$REPO" "$wt" "$br" "$base" "$tdir" "$PLAN" "$id"; then
|
|
1981
2057
|
echo ERROR > "$tdir/status"
|
|
@@ -2135,18 +2211,22 @@ do_task_body() (
|
|
|
2135
2211
|
fi
|
|
2136
2212
|
# A bounced attempt (retry_findings.source `bounce`) was never reviewed, so a retry that keeps
|
|
2137
2213
|
# its code is reviewed rather than refused as identical: the refusal is for a diff a review
|
|
2138
|
-
# already judged.
|
|
2214
|
+
# already judged. The same applies when the brief or threshold changed since that review (#209).
|
|
2139
2215
|
if [ -s "$tdir/changes.prev.diff" ] && cmp -s "$tdir/changes.diff" "$tdir/changes.prev.diff" \
|
|
2140
2216
|
&& [ "$(cat "$tdir/retry_findings.source" 2>/dev/null)" != bounce ]; then
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2217
|
+
if brief_changed_since_review "$tdir" "$qa_thr"; then
|
|
2218
|
+
note "$id: brief changed since the last review — reviewing the unchanged diff against the updated brief"
|
|
2219
|
+
else
|
|
2220
|
+
# A retry its CLI cancelled before it changed anything did not keep the code on purpose.
|
|
2221
|
+
if grep -qx 'class=cancelled' "$tdir/dwarf.infra" 2>/dev/null; then
|
|
2222
|
+
infra_stop "$tdir" "$id" dwarf "$attempt"; return 8
|
|
2223
|
+
fi
|
|
2224
|
+
echo FAIL > "$tdir/status"
|
|
2225
|
+
: > "$tdir/noretry"
|
|
2226
|
+
echo "The retry changed nothing: the diff is byte-identical to the previous attempt." \
|
|
2227
|
+
> "$tdir/qa.last"
|
|
2228
|
+
note "$id: retry produced no new changes — not re-reviewing identical code"; return 1
|
|
2144
2229
|
fi
|
|
2145
|
-
echo FAIL > "$tdir/status"
|
|
2146
|
-
: > "$tdir/noretry"
|
|
2147
|
-
echo "The retry changed nothing: the diff is byte-identical to the previous attempt." \
|
|
2148
|
-
> "$tdir/qa.last"
|
|
2149
|
-
note "$id: retry produced no new changes — not re-reviewing identical code"; return 1
|
|
2150
2230
|
fi
|
|
2151
2231
|
|
|
2152
2232
|
if ! git -C "$wt" diff --cached --quiet "$base" -- .forge; then
|
|
@@ -2224,8 +2304,7 @@ do_task_body() (
|
|
|
2224
2304
|
echo "$review_fp" > "$tdir/review.fingerprint"
|
|
2225
2305
|
|
|
2226
2306
|
forge_metric_phase preparation
|
|
2227
|
-
local
|
|
2228
|
-
qa_thr="$(qa_threshold_for "$PLAN" "$id")"
|
|
2307
|
+
local rs_on=0
|
|
2229
2308
|
# Read once per round, like the threshold: continuing the earlier reviewer's session is an
|
|
2230
2309
|
# opt-in experiment (plan --reviewer-session), and a round never changes its mind midway.
|
|
2231
2310
|
[ -f "$PLAN/reviewer_session" ] && rs_on=1
|
|
@@ -2456,6 +2535,7 @@ for r in json.load(sys.stdin):
|
|
|
2456
2535
|
# FAIL. qa_thr is the value the review prompt was built with, so the prompt and the gate of
|
|
2457
2536
|
# one attempt agree. Before record_attempt, so attempts.tsv shows the gated status.
|
|
2458
2537
|
qa_gate "$PLAN" "$id" "$tdir" "$verdict" "$qa_thr"
|
|
2538
|
+
record_reviewed_inputs "$tdir" "$qa_thr" || true
|
|
2459
2539
|
return 0
|
|
2460
2540
|
)
|
|
2461
2541
|
|
|
@@ -2513,7 +2593,7 @@ merge_task() { # merge_task <plan> <id> -> 0 merged, 1 conflicted
|
|
|
2513
2593
|
(cd "$int_wt" && git merge --abort >/dev/null 2>&1)
|
|
2514
2594
|
echo CONFLICT > "$PLAN/tasks/$id/status"
|
|
2515
2595
|
forge_dataset_event merge --dir "$PLAN" --task "$id" --set status=CONFLICT --set commit="$reviewed" \
|
|
2516
|
-
--set conflicts="$(tr '\n' ' ' < "$tdir/conflict.files"
|
|
2596
|
+
--set conflicts="$(tr '\n' ' ' 2>/dev/null < "$tdir/conflict.files")"
|
|
2517
2597
|
return 1
|
|
2518
2598
|
}
|
|
2519
2599
|
|
|
@@ -2583,13 +2663,14 @@ PY
|
|
|
2583
2663
|
}
|
|
2584
2664
|
|
|
2585
2665
|
report_untested() { # report_untested <plan> <id>...: verdicts that rest on reading alone (#117)
|
|
2586
|
-
local plan="$1" id tests_note untested=0; shift
|
|
2666
|
+
local plan="$1" id tests_note untested=0 id_w; shift
|
|
2667
|
+
id_w="$(id_col_width "$plan/tasks.tsv")"
|
|
2587
2668
|
for id in "$@"; do
|
|
2588
2669
|
tests_note="$(forge_tests_note "$plan/tasks/$id/qa.last")"
|
|
2589
2670
|
if [ -n "$tests_note" ]; then
|
|
2590
2671
|
[ "$untested" = 0 ] && echo "reviews whose tests could not run:"
|
|
2591
2672
|
untested=1
|
|
2592
|
-
printf '
|
|
2673
|
+
printf ' %-*s %s\n' "$id_w" "$id" "$tests_note"
|
|
2593
2674
|
fi
|
|
2594
2675
|
done
|
|
2595
2676
|
[ "$untested" = 0 ] || echo
|
|
@@ -2833,8 +2914,7 @@ do_retry() {
|
|
|
2833
2914
|
write_results "$PLAN"
|
|
2834
2915
|
echo
|
|
2835
2916
|
# 14 covers NEEDS_DECISION; 9 pushes the branch column out for IMPLEMENTED (11) too.
|
|
2836
|
-
|
|
2837
|
-
awk -F'\t' '{printf " %-14s %-14s %s\n", $1, $2, $3}' "$PLAN/results.tsv"
|
|
2917
|
+
render_results_table "$PLAN"
|
|
2838
2918
|
run_report_extras "$PLAN"
|
|
2839
2919
|
report_decisions "$PLAN"
|
|
2840
2920
|
[ "$(task_status "$PLAN" "$id")" = "MERGED" ] || return 5
|
|
@@ -2863,16 +2943,28 @@ verify_group_stop() { # TERM the verify command's group; KILL it after FORGE_VER
|
|
|
2863
2943
|
# Until the guard's setsid there is no group: the TERM goes to the guard itself, which dies
|
|
2864
2944
|
# of it before it starts the command. A group that forms all the same gets its TERM from
|
|
2865
2945
|
# the timer.
|
|
2866
|
-
|
|
2946
|
+
if forge_is_windows && [ -r "/proc/$group/winpid" ]; then
|
|
2947
|
+
forge_kill_group "$group" TERM
|
|
2948
|
+
kill -TERM "$group" 2>/dev/null || true
|
|
2949
|
+
else
|
|
2950
|
+
kill -TERM -- "-$group" 2>/dev/null || { termed=0; kill -TERM "$group" 2>/dev/null; }
|
|
2951
|
+
fi
|
|
2867
2952
|
# The timer polls in short naps rather than sleeping the whole grace in one: it ends by
|
|
2868
2953
|
# itself within a nap of the group's last member, and a long sleep left behind would hold
|
|
2869
2954
|
# the plan lock it inherited.
|
|
2870
2955
|
( trap - TERM INT
|
|
2871
2956
|
ticks=$((FORGE_VERIFY_GRACE * 10))
|
|
2872
|
-
while kill -0 -- "-$group" 2>/dev/null || { [ "$termed" = 0 ] && kill -0 "$group" 2>/dev/null; }; do
|
|
2957
|
+
while kill -0 -- "-$group" 2>/dev/null || { [ "$termed" = 0 ] && kill -0 "$group" 2>/dev/null; } || { forge_is_windows && [ -r "/proc/$group/winpid" ] && kill -0 "$group" 2>/dev/null; }; do
|
|
2873
2958
|
if [ "$termed" = 0 ] && kill -TERM -- "-$group" 2>/dev/null; then termed=1; fi
|
|
2874
2959
|
if [ "$ticks" -le 0 ]; then
|
|
2875
|
-
if
|
|
2960
|
+
if forge_is_windows && [ -r "/proc/$group/winpid" ]; then
|
|
2961
|
+
forge_kill_group "$group" KILL
|
|
2962
|
+
kill -KILL "$group" 2>/dev/null
|
|
2963
|
+
elif [ "$termed" = 1 ]; then
|
|
2964
|
+
kill -KILL -- "-$group" 2>/dev/null
|
|
2965
|
+
else
|
|
2966
|
+
kill -KILL "$group" 2>/dev/null
|
|
2967
|
+
fi
|
|
2876
2968
|
break
|
|
2877
2969
|
fi
|
|
2878
2970
|
sleep 0.1
|
|
@@ -2887,20 +2979,25 @@ verify_signal() { # trap handler of a stoppable verification
|
|
|
2887
2979
|
}
|
|
2888
2980
|
|
|
2889
2981
|
verify_exec() { # verify_exec <checkout> <command> <log> [grace seconds, default 5] -> the command's exit code, 130 when stopped
|
|
2890
|
-
local wt="$1" cmd="$2" log="$3" rc=0 group deadline
|
|
2982
|
+
local wt="$1" cmd="$2" log="$3" rc=0 group deadline guard_py="$SKILL_DIR/scripts/forge-guard.py"
|
|
2891
2983
|
if [ "${FORGE_RUN_STOPPABLE:-0}" != 1 ]; then
|
|
2892
2984
|
(cd "$wt" && /bin/bash -c "$cmd") > "$log" 2>&1
|
|
2893
2985
|
return $?
|
|
2894
2986
|
fi
|
|
2895
2987
|
FORGE_VERIFY_GRACE="${4:-5}"
|
|
2896
2988
|
[ "$FORGE_VERIFY_STOP" = 1 ] && return 130
|
|
2989
|
+
! forge_is_windows || guard_py="$(forge_host_path "$guard_py")"
|
|
2897
2990
|
# A background job ignores SIGINT and SIGQUIT, and the command would inherit that; the
|
|
2898
2991
|
# wrapper restores both before the guard puts the command in a session of its own.
|
|
2899
|
-
(cd "$wt" && exec python3 -c 'import os, signal, sys
|
|
2900
|
-
for
|
|
2901
|
-
signal
|
|
2992
|
+
(cd "$wt" && { ! forge_is_windows || export MSYS_NO_PATHCONV=1; } && exec python3 -c 'import os, signal, subprocess, sys
|
|
2993
|
+
for sig_name in ("SIGINT", "SIGQUIT"):
|
|
2994
|
+
sig = getattr(signal, sig_name, None)
|
|
2995
|
+
if sig is not None:
|
|
2996
|
+
signal.signal(sig, signal.SIG_DFL)
|
|
2997
|
+
if os.name == "nt":
|
|
2998
|
+
sys.exit(subprocess.run([sys.executable] + sys.argv[1:]).returncode)
|
|
2902
2999
|
os.execv(sys.executable, [sys.executable] + sys.argv[1:])' \
|
|
2903
|
-
"$
|
|
3000
|
+
"$guard_py" session -- /bin/bash -c "$cmd") > "$log" 2>&1 <&0 &
|
|
2904
3001
|
group=$!
|
|
2905
3002
|
FORGE_VERIFY_GROUP="$group"
|
|
2906
3003
|
[ "$FORGE_VERIFY_STOP" = 1 ] && verify_group_stop
|
|
@@ -2951,7 +3048,8 @@ verify_result_body() { # plan, checkout, artifact directory[, fixed source]
|
|
|
2951
3048
|
forge_metric_begin "$out" verification
|
|
2952
3049
|
forge_metric_phase verification
|
|
2953
3050
|
repo="$(cat "$plan/repo")"
|
|
2954
|
-
rm -f "$out/verification.
|
|
3051
|
+
rm -f "$out/verification.status" "$out/verification.exit" \
|
|
3052
|
+
"$out/verification.flaky" "$out/verification.retry.log" "$out/verification.failing.log" "$out/verification.coverage.txt" \
|
|
2955
3053
|
"$out/verification.runs.tsv" "$out"/verification.run-*.log "$out/verification.commit" \
|
|
2956
3054
|
"$out/verification.lanes.json" "$out"/verification.lane.*.log
|
|
2957
3055
|
# The commit being verified, named before any early return, so every outcome (FAIL and
|
|
@@ -3203,9 +3301,32 @@ forge_brief_start() { # forge_brief_start <plan>
|
|
|
3203
3301
|
PYTHONPATH="$SKILL_DIR/scripts${PYTHONPATH:+:$PYTHONPATH}" python3 -c \
|
|
3204
3302
|
'import sys, forge_brief; forge_brief.note_missing_groups(sys.argv[1])' "$plan" || true
|
|
3205
3303
|
python3 - "$plan" "$SKILL_DIR/scripts/forge-brief.py" <<'PY' || { note "brief: could not start the question writer"; return 0; }
|
|
3206
|
-
import os, subprocess, sys
|
|
3304
|
+
import os, subprocess, sys, time
|
|
3207
3305
|
plan, script = sys.argv[1], sys.argv[2]
|
|
3208
3306
|
pidfile = os.path.join(plan, 'brief.pid')
|
|
3307
|
+
if not hasattr(os, 'fork'):
|
|
3308
|
+
worker = (
|
|
3309
|
+
'import os, subprocess, sys\n'
|
|
3310
|
+
'plan, script, pidfile = sys.argv[1], sys.argv[2], sys.argv[3]\n'
|
|
3311
|
+
'try:\n'
|
|
3312
|
+
' with open(pidfile, "w") as handle:\n'
|
|
3313
|
+
' handle.write("%d\\n" % os.getpid())\n'
|
|
3314
|
+
' subprocess.run([sys.executable, script, "write", plan], stdin=subprocess.DEVNULL)\n'
|
|
3315
|
+
'finally:\n'
|
|
3316
|
+
' try: os.unlink(pidfile)\n'
|
|
3317
|
+
' except OSError: pass\n'
|
|
3318
|
+
)
|
|
3319
|
+
flags = getattr(subprocess, 'CREATE_NEW_PROCESS_GROUP', 0) | getattr(subprocess, 'DETACHED_PROCESS', 0)
|
|
3320
|
+
with open(os.path.join(plan, 'brief.out'), 'ab') as out:
|
|
3321
|
+
proc = subprocess.Popen(
|
|
3322
|
+
[sys.executable, '-c', worker, plan, script, pidfile],
|
|
3323
|
+
stdin=subprocess.DEVNULL, stdout=out, stderr=out,
|
|
3324
|
+
creationflags=flags, close_fds=True,
|
|
3325
|
+
)
|
|
3326
|
+
deadline = time.monotonic() + 2.0
|
|
3327
|
+
while time.monotonic() < deadline and not os.path.exists(pidfile) and proc.poll() is None:
|
|
3328
|
+
time.sleep(0.02)
|
|
3329
|
+
sys.exit(0)
|
|
3209
3330
|
ready, signal_ready = os.pipe()
|
|
3210
3331
|
child = os.fork()
|
|
3211
3332
|
if child:
|
|
@@ -3437,7 +3558,7 @@ do_run() {
|
|
|
3437
3558
|
# Durable, beside the repo — never TMPDIR. A temp worktree root has destroyed
|
|
3438
3559
|
# real work here before: isolated worktrees are never pushed, so when the root
|
|
3439
3560
|
# goes, the only copy of that work goes with it.
|
|
3440
|
-
wt_root="$(cd "$REPO/.." && pwd)/.forge-worktrees/$run_id"
|
|
3561
|
+
wt_root="$(forge_host_path "$(cd "$REPO/.." && pwd)/.forge-worktrees/$run_id")"
|
|
3441
3562
|
echo "$wt_root" > "$PLAN/wt_root"
|
|
3442
3563
|
# Sibling, not parent: git refs are files, so a branch `forge/<run>` makes
|
|
3443
3564
|
# `forge/<run>/<task>` impossible ("cannot lock ref ... exists; cannot create").
|
|
@@ -3573,8 +3694,7 @@ do_run() {
|
|
|
3573
3694
|
echo "results (integration branch: $int_br)"
|
|
3574
3695
|
echo "artifacts: $PLAN/tasks/<id>/{dwarf,qa}.{last,log}; results: $PLAN/results.tsv"
|
|
3575
3696
|
# 14 covers NEEDS_DECISION; 9 pushes the branch column out for IMPLEMENTED (11) too.
|
|
3576
|
-
|
|
3577
|
-
awk -F'\t' '{printf " %-14s %-14s %s\n", $1, $2, $3}' "$PLAN/results.tsv"
|
|
3697
|
+
render_results_table "$PLAN"
|
|
3578
3698
|
echo
|
|
3579
3699
|
if [ -n "$retro_line" ]; then printf '%s\n\n' "$retro_line"; fi
|
|
3580
3700
|
run_report_extras "$PLAN"
|
|
@@ -3586,12 +3706,13 @@ do_run() {
|
|
|
3586
3706
|
|
|
3587
3707
|
# Undeclared files are reported here rather than buried in a task log, because
|
|
3588
3708
|
# this is the list that explains any CONFLICT above.
|
|
3589
|
-
local drift=0
|
|
3709
|
+
local drift=0 id_w
|
|
3710
|
+
id_w="$(id_col_width "$T")"
|
|
3590
3711
|
for id in $(all_ids "$T"); do
|
|
3591
3712
|
if [ -s "$PLAN/tasks/$id/drift.txt" ]; then
|
|
3592
3713
|
[ "$drift" = 0 ] && echo "scope drift (touched files the task did not declare):"
|
|
3593
3714
|
drift=1
|
|
3594
|
-
printf '
|
|
3715
|
+
printf ' %-*s %s\n' "$id_w" "$id" "$(tr '\n' ' ' < "$PLAN/tasks/$id/drift.txt")"
|
|
3595
3716
|
fi
|
|
3596
3717
|
done
|
|
3597
3718
|
[ "$drift" = 1 ] && echo
|
|
@@ -4027,7 +4148,7 @@ fi
|
|
|
4027
4148
|
case "$CMD" in
|
|
4028
4149
|
# `combine` takes a plan dir that does not exist yet and locks its sources itself.
|
|
4029
4150
|
run|retry|integrate|accept|adopt|review|split|attribute)
|
|
4030
|
-
if [ "${FORGE_PLAN_LOCK:-}" != "${1:-}" ]; then
|
|
4151
|
+
if [ "$(forge_posix_path "${FORGE_PLAN_LOCK:-}")" != "${1:-}" ]; then
|
|
4031
4152
|
exec python3 "$SKILL_DIR/scripts/forge-schedule.py" lock "$SELF" "$CMD" "$@"
|
|
4032
4153
|
fi ;;
|
|
4033
4154
|
esac
|
package/scripts/forge-planner.py
CHANGED
|
@@ -455,15 +455,41 @@ def check_graph(tasks: list):
|
|
|
455
455
|
visit(t['id'], [t['id']])
|
|
456
456
|
|
|
457
457
|
|
|
458
|
+
MAX_JSON_DEPTH = 64 # a plan is a few levels deep; anything near this is not a plan
|
|
459
|
+
MAX_INT_DIGITS = 4300 # Python's own limit from 3.11 (and late 3.9/3.10 patch releases); not in 3.9.13 or Apple's 3.9.6
|
|
460
|
+
|
|
461
|
+
|
|
462
|
+
def bounded_int(text: str) -> int:
|
|
463
|
+
"""int() for json.loads, refusing the very long integers that recent Pythons refuse too."""
|
|
464
|
+
if len(text.lstrip('-')) > MAX_INT_DIGITS:
|
|
465
|
+
raise ValueError(f'an integer of more than {MAX_INT_DIGITS} digits')
|
|
466
|
+
return int(text)
|
|
467
|
+
|
|
468
|
+
|
|
469
|
+
def nested_deeper_than(value, limit: int) -> bool:
|
|
470
|
+
"""Whether lists and objects nest more than `limit` levels, checked without recursion."""
|
|
471
|
+
stack = [(value, 1)]
|
|
472
|
+
while stack:
|
|
473
|
+
item, depth = stack.pop()
|
|
474
|
+
if isinstance(item, (dict, list)):
|
|
475
|
+
if depth > limit:
|
|
476
|
+
return True
|
|
477
|
+
stack.extend((child, depth + 1) for child in (item.values() if isinstance(item, dict) else item))
|
|
478
|
+
return False
|
|
479
|
+
|
|
480
|
+
|
|
458
481
|
def parse_reply(reply: str):
|
|
459
482
|
"""(tasks, groups). groups is None when the reply has no groups key, else a list (maybe empty)."""
|
|
460
483
|
body = extract_block(reply)
|
|
461
484
|
try:
|
|
462
|
-
data = json.loads(body, object_pairs_hook=no_duplicate_keys)
|
|
485
|
+
data = json.loads(body, object_pairs_hook=no_duplicate_keys, parse_int=bounded_int)
|
|
463
486
|
except (ValueError, RecursionError) as err:
|
|
464
487
|
# JSONDecodeError is a ValueError; so is Python's limit on integer digits. Nesting deeper
|
|
465
|
-
# than the interpreter allows raises RecursionError.
|
|
488
|
+
# than the interpreter allows raises RecursionError (up to Python 3.11; from 3.12 the
|
|
489
|
+
# parser goes much deeper, hence the explicit limit below).
|
|
466
490
|
raise Refusal(f'the forge-plan body is not valid JSON: {type(err).__name__}: {str(err)[:200]}')
|
|
491
|
+
if nested_deeper_than(data, MAX_JSON_DEPTH):
|
|
492
|
+
raise Refusal(f'the forge-plan body is not valid JSON: nested more than {MAX_JSON_DEPTH} levels deep')
|
|
467
493
|
check_keys(data, ('tasks',), 'the forge-plan body', ('groups',))
|
|
468
494
|
tasks = data['tasks']
|
|
469
495
|
if not isinstance(tasks, list) or not 1 <= len(tasks) <= MAX_TASKS:
|
|
@@ -54,6 +54,11 @@ import sys
|
|
|
54
54
|
import tempfile
|
|
55
55
|
import time
|
|
56
56
|
|
|
57
|
+
_SCRIPTS = str(Path(__file__).resolve().parent)
|
|
58
|
+
if _SCRIPTS not in sys.path:
|
|
59
|
+
sys.path.insert(0, _SCRIPTS)
|
|
60
|
+
import forge_proc # noqa: E402
|
|
61
|
+
|
|
57
62
|
_SPEC = importlib.util.spec_from_file_location('forge_fail_first', Path(__file__).resolve().parent / 'forge-fail-first.py')
|
|
58
63
|
failfirst = importlib.util.module_from_spec(_SPEC)
|
|
59
64
|
_SPEC.loader.exec_module(failfirst)
|
|
@@ -228,10 +233,12 @@ class Slot:
|
|
|
228
233
|
fd = os.open(path, os.O_CREAT | os.O_EXCL | os.O_WRONLY, 0o644)
|
|
229
234
|
except FileExistsError:
|
|
230
235
|
try:
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
except
|
|
236
|
+
holder = int(path.read_text().strip() or 0)
|
|
237
|
+
if holder != 0 and not forge_proc.pid_alive(holder):
|
|
238
|
+
path.unlink(missing_ok=True) # its holder is gone
|
|
239
|
+
except ValueError:
|
|
240
|
+
path.unlink(missing_ok=True)
|
|
241
|
+
except OSError:
|
|
235
242
|
pass
|
|
236
243
|
continue
|
|
237
244
|
with os.fdopen(fd, 'w') as handle:
|