@giamme/forge 0.17.0 → 0.19.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 +57 -0
- package/README.md +1 -0
- package/SKILL.md +32 -5
- package/VERSION +1 -1
- package/docs/artifacts.md +33 -1
- package/docs/commands.md +147 -16
- package/docs/dataset.md +5 -0
- package/docs/decomposed-runs.md +122 -1
- package/docs/development.md +2 -1
- package/docs/forge-ui.md +98 -8
- package/docs/memory.md +27 -4
- package/docs/models.md +8 -0
- package/docs/reviews.md +122 -0
- package/docs/safety.md +8 -0
- package/forge +44 -4
- package/package.json +2 -1
- package/references/dataset.md +39 -1
- package/references/decompose.md +737 -16
- package/references/harnesses.md +18 -3
- package/references/planning.md +43 -14
- package/references/solo.md +2 -1
- package/references/ui.md +56 -6
- package/registry.tsv +8 -3
- package/scripts/forge-artifact.sh +14 -0
- package/scripts/forge-brief.py +217 -0
- package/scripts/forge-compare.py +13 -2
- package/scripts/forge-config.py +176 -9
- package/scripts/forge-contract.py +246 -28
- package/scripts/forge-control.py +200 -15
- package/scripts/forge-dispatch.sh +48 -15
- package/scripts/forge-du.py +167 -0
- package/scripts/forge-group.py +496 -0
- package/scripts/forge-groups.py +89 -0
- package/scripts/forge-handoff.py +1128 -0
- package/scripts/forge-lib-adopt.sh +1 -0
- package/scripts/forge-lib-group.sh +641 -0
- package/scripts/forge-lib-plans.sh +343 -4
- package/scripts/forge-lib-review.sh +29 -1
- package/scripts/forge-lib-task.sh +197 -4
- package/scripts/forge-memory.sh +245 -3
- package/scripts/forge-metrics.sh +7 -3
- package/scripts/forge-parallel-options.sh +4 -0
- package/scripts/forge-parallel.sh +1216 -41
- package/scripts/forge-planner.py +104 -8
- package/scripts/forge-prompt.py +120 -0
- package/scripts/forge-retro.py +115 -0
- package/scripts/forge-route.py +190 -12
- package/scripts/forge-runs-compact.py +443 -0
- package/scripts/forge-runs-rm.py +2 -0
- package/scripts/forge-runs.py +27 -8
- package/scripts/forge-schedule.py +633 -49
- package/scripts/forge-shadow.py +7 -1
- package/scripts/forge-solo.sh +4 -0
- package/scripts/forge-summarize.py +698 -0
- package/scripts/forge-ui-options.sh +10 -0
- package/scripts/forge-worktrees.py +243 -0
- package/scripts/forge_brief/__init__.py +831 -0
- package/scripts/forge_brief/answers.py +506 -0
- package/scripts/forge_brief/proposals.py +1630 -0
- package/scripts/forge_dataset/__init__.py +10 -0
- package/scripts/forge_dataset/efforts.py +4 -3
- package/scripts/forge_dataset/export.py +36 -10
- package/scripts/forge_dataset/facts.py +8 -4
- package/scripts/forge_dataset/forecast.py +8 -18
- package/scripts/forge_dataset/harvest.py +241 -12
- package/scripts/forge_dataset/history.py +13 -6
- package/scripts/forge_dataset/importer.py +65 -1
- package/scripts/forge_dataset/names.py +66 -0
- package/scripts/forge_dataset/reviewers.py +5 -2
- package/scripts/forge_dataset/risk.py +6 -3
- package/scripts/forge_dataset/routing.py +6 -1
- package/scripts/forge_decide/__init__.py +11 -1
- package/scripts/forge_groups/__init__.py +308 -0
- package/scripts/forge_groups/attribute.py +289 -0
- package/scripts/forge_groups/review.py +286 -0
- package/scripts/forge_locations.py +366 -0
- package/scripts/forge_owner.py +152 -0
- package/scripts/forge_registry.py +19 -0
- package/scripts/forge_retro/__init__.py +417 -0
- package/scripts/forge_retro/issues.py +1193 -0
- package/scripts/forge_retro/report.py +671 -0
- package/scripts/forge_side/__init__.py +482 -0
- package/scripts/forge_storage.py +515 -0
- package/ui/README.md +68 -8
- package/ui/docs/api.md +375 -31
- package/ui/forge_ui/control.py +451 -11
- package/ui/forge_ui/executions.py +8 -1
- package/ui/forge_ui/export.py +53 -7
- package/ui/forge_ui/groups.py +264 -0
- package/ui/forge_ui/links.py +337 -0
- package/ui/forge_ui/models.py +125 -10
- package/ui/forge_ui/projects.py +4 -1
- package/ui/forge_ui/reader.py +919 -45
- package/ui/forge_ui/server.py +4 -0
- package/ui/forge_ui/static/app.js +173 -11
- package/ui/forge_ui/static/briefview.js +605 -0
- package/ui/forge_ui/static/checksview.js +6 -2
- package/ui/forge_ui/static/controls.js +5 -0
- package/ui/forge_ui/static/diffview.js +86 -1
- package/ui/forge_ui/static/groupsview.js +332 -0
- package/ui/forge_ui/static/index.html +4 -0
- package/ui/forge_ui/static/panel.js +394 -8
- package/ui/forge_ui/static/projectsview.js +189 -10
- package/ui/forge_ui/static/runmodel.js +27 -4
- package/ui/forge_ui/static/storageview.js +352 -0
- package/ui/forge_ui/static/style.css +176 -6
- package/ui/forge_ui/static/worktreesview.js +235 -14
- package/ui/forge_ui/storage.py +150 -0
- package/ui/forge_ui/transcripts.py +35 -10
- package/ui/forge_ui/worktrees.py +154 -13
|
@@ -129,6 +129,7 @@ do_adopt() {
|
|
|
129
129
|
tip="$(git -C "$int_wt" rev-parse HEAD)"
|
|
130
130
|
|
|
131
131
|
local review="$out/review" thr verdict gate_line decision kept inline=1 vcmd
|
|
132
|
+
FORGE_REVIEW_SNAPSHOT="$review" # the EXIT trap of forge-parallel.sh removes it on every exit (#139)
|
|
132
133
|
forge_review_snapshot "$int_wt" "$base" "$tip" "$review" > "$out/snapshot.log" 2>&1 \
|
|
133
134
|
|| { adopt_rollback; die "adopt: cannot build the review snapshot (see $out/snapshot.log)" 3; }
|
|
134
135
|
forge_review_deps "$int_wt" "$review" "$out/review.deps"
|
|
@@ -0,0 +1,641 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Group review for forge-parallel.sh (#140). Sourced; functions only.
|
|
3
|
+
#
|
|
4
|
+
# forge-parallel.sh _group <plan> <gid>
|
|
5
|
+
#
|
|
6
|
+
# Opt-in: a `review=group` group of <plan>/groups.tsv is reviewed ONCE, over the work of all its
|
|
7
|
+
# members together. Its members stopped at IMPLEMENTED (reviewed.commit, source.fingerprint). This builds
|
|
8
|
+
# a candidate (the integration worktree's HEAD plus each member's reviewed.commit, merged in member
|
|
9
|
+
# order), bounds its diff, gives it one QA dispatch, and attributes the findings to the members.
|
|
10
|
+
# It writes the group's outcome files and changes no member's state, except INVALIDATED for a member that
|
|
11
|
+
# moved. What the outcome does to the members is the second half of this file:
|
|
12
|
+
#
|
|
13
|
+
# forge-parallel.sh _group_settle <plan> <gid> [--tasks a,b] a FAIL sends its implicated members back
|
|
14
|
+
# forge-parallel.sh _merge_group <plan> <gid> a PASS merges every member, or none
|
|
15
|
+
#
|
|
16
|
+
# Files in <plan>/groups/<gid>/ (every status write is atomic):
|
|
17
|
+
# status REVIEWING while it runs, then PASS FAIL NEEDS_DECISION UNKNOWN CONFLICT INFRA
|
|
18
|
+
# TIMEOUT ERROR INVALIDATED or WAITING
|
|
19
|
+
# round the round number, 1 for the first review
|
|
20
|
+
# candidate.base the integration HEAD the candidate starts from candidate.commit its tip
|
|
21
|
+
# members.tsv round, task, reviewed commit, attempt: one row per member per round that built a candidate
|
|
22
|
+
# fingerprint sha256 of the sorted task=commit lines and a final tree=<candidate tree> line
|
|
23
|
+
# conflict.files the files a conflicting member merge left unmerged (status CONFLICT)
|
|
24
|
+
# combined.diff the candidate's whole diff; decision.md why a round stopped for a person
|
|
25
|
+
# qa.input qa.last qa.out qa.gate known_issues.md infra.txt as a task's review files
|
|
26
|
+
# attribution.json the findings attributed to members, with the round members.paths task<TAB>path
|
|
27
|
+
# qa.round-<n>.last the reply of round n, which the next round's prompt quotes from
|
|
28
|
+
# rounds.tsv round, epoch, status, implicated (comma list or -), qa spec
|
|
29
|
+
# The candidate worktree is <wt_root>/_group-<gid>; it stays (a later merge uses candidate.commit).
|
|
30
|
+
# Written by _group_settle: settled.round (the round it settled), settle.tasks (round<TAB>ids a person named,
|
|
31
|
+
# kept until the round is settled), decision.<round>.md (decision.md once a person answered).
|
|
32
|
+
# Written by _merge_group: merged (the group's), invalidated.reason (integration-moved, integration-dirty,
|
|
33
|
+
# candidate-moved), conflict.files.
|
|
34
|
+
|
|
35
|
+
group_set_status() { # group_set_status <group dir> <status>: atomic
|
|
36
|
+
local tmp="$1/.status.$$.tmp"
|
|
37
|
+
printf '%s\n' "$2" > "$tmp" && mv -f "$tmp" "$1/status"
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
# The round's status, and the row that says so. Every way out of a round after its status was set goes
|
|
41
|
+
# through here, so rounds.tsv has one line per round.
|
|
42
|
+
group_end() { # group_end <group dir> <round> <status> <qa spec> [implicated comma list]
|
|
43
|
+
local gdir="$1" round="$2" status="$3" qa="$4" implicated="${5:-}"
|
|
44
|
+
group_set_status "$gdir" "$status"
|
|
45
|
+
printf '%s\t%s\t%s\t%s\t%s\n' "$round" "$(date +%s)" "$status" "${implicated:--}" "$qa" >> "$gdir/rounds.tsv"
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
group_size_limit() { # group_size_limit <plan> -> the diff size bound in KB
|
|
49
|
+
local kb
|
|
50
|
+
kb="$(head -1 "$1/group_max_diff_kb" 2>/dev/null | tr -dc '0-9')"
|
|
51
|
+
[ -n "$kb" ] && [ "$kb" -gt 0 ] 2>/dev/null || kb=256
|
|
52
|
+
printf '%s\n' "$kb"
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
group_candidate_remove() { # group_candidate_remove <plan> <repo> <path>: any earlier candidate, registered or not
|
|
56
|
+
local plan="$1" repo="$2" path="$3"
|
|
57
|
+
git -C "$repo" worktree prune >/dev/null 2>&1
|
|
58
|
+
[ -e "$path" ] || [ -L "$path" ] || return 0
|
|
59
|
+
if git -C "$repo" worktree remove --force "$path" >/dev/null 2>&1; then
|
|
60
|
+
forge_worktree_event removed "$plan" "$repo" "$path" - candidate
|
|
61
|
+
fi
|
|
62
|
+
rm -rf "$path"
|
|
63
|
+
git -C "$repo" worktree prune >/dev/null 2>&1
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
do_group() (
|
|
67
|
+
local PLAN="${1:?usage: forge-parallel.sh _group <plan> <gid>}" gid="${2:?usage: forge-parallel.sh _group <plan> <gid>}"
|
|
68
|
+
[ -d "$PLAN" ] || die "$PLAN is not a plan directory" 2
|
|
69
|
+
local G="$PLAN/groups/$gid" row review qa members
|
|
70
|
+
row="$(forge_groups_py show "$PLAN" 2>/dev/null | awk -F'\t' -v g="$gid" '$1 == g { print; exit }')"
|
|
71
|
+
[ -n "$row" ] || die "$gid is not a group of $PLAN" 2
|
|
72
|
+
IFS=$'\t' read -r _ review qa members _ <<< "$row"
|
|
73
|
+
[ "$review" = group ] || die "group $gid has review=$review: only a review=group group is reviewed as one" 2
|
|
74
|
+
|
|
75
|
+
# 1. Status and round.
|
|
76
|
+
mkdir -p "$G" || die "could not create $G" 3
|
|
77
|
+
local round REPO run_id wt_root
|
|
78
|
+
round="$(tr -dc '0-9' < "$G/round" 2>/dev/null)"
|
|
79
|
+
round=$(( ${round:-0} + 1 ))
|
|
80
|
+
printf '%s\n' "$round" > "$G/round.tmp" && mv -f "$G/round.tmp" "$G/round"
|
|
81
|
+
# What an earlier round left that this one would otherwise be read as. attribution.json and
|
|
82
|
+
# qa.round-<n>.last stay: the next prompt quotes them.
|
|
83
|
+
rm -f "$G/qa.last" "$G/qa.input" "$G/qa.out" "$G/qa.gate" "$G/known_issues.md" "$G/infra.txt" "$G/decision.md" \
|
|
84
|
+
"$G/conflict.files" "$G/candidate.base" "$G/candidate.commit" "$G/fingerprint" "$G/combined.diff" \
|
|
85
|
+
"$G/merge.out" "$G/members.paths" "$G/review.base" "$G/invalidated.reason"
|
|
86
|
+
group_set_status "$G" REVIEWING
|
|
87
|
+
REPO="$(cat "$PLAN/repo")"; run_id="$(cat "$PLAN/run_id")"; wt_root="$(cat "$PLAN/wt_root")"
|
|
88
|
+
# --timeout given to run/retry is kept in the plan and wins over the environment, as for a task.
|
|
89
|
+
[ -s "$PLAN/timeout" ] && export FORGE_TIMEOUT="$(cat "$PLAN/timeout")"
|
|
90
|
+
local ids=() id tdir st waiting=0 reviewed moved=0
|
|
91
|
+
IFS=, read -ra ids <<< "$members"
|
|
92
|
+
|
|
93
|
+
# 2. The members: each one IMPLEMENTED, still at the commit and the fingerprint it was judged at.
|
|
94
|
+
for id in "${ids[@]}"; do
|
|
95
|
+
st="$(task_status "$PLAN" "$id")"
|
|
96
|
+
if [ "$st" != IMPLEMENTED ]; then
|
|
97
|
+
note "group $gid: $id is $st, not IMPLEMENTED — waiting"
|
|
98
|
+
waiting=1
|
|
99
|
+
fi
|
|
100
|
+
done
|
|
101
|
+
if [ "$waiting" = 1 ]; then group_end "$G" "$round" WAITING "$qa"; return 0; fi
|
|
102
|
+
for id in "${ids[@]}"; do
|
|
103
|
+
tdir="$PLAN/tasks/$id"
|
|
104
|
+
reviewed="$(cat "$tdir/reviewed.commit" 2>/dev/null)"
|
|
105
|
+
if [ -z "$reviewed" ] \
|
|
106
|
+
|| [ "$(git -C "$REPO" rev-parse --verify --quiet "forge/$run_id/$id" 2>/dev/null)" != "$reviewed" ] \
|
|
107
|
+
|| [ "$(forge_fingerprint "$wt_root/$id" 2>/dev/null)" != "$(cat "$tdir/source.fingerprint" 2>/dev/null)" ]; then
|
|
108
|
+
echo group-candidate > "$tdir/invalidated.reason"
|
|
109
|
+
group_set_status "$tdir" INVALIDATED
|
|
110
|
+
note "group $gid: $id moved since it was implemented — invalidated"
|
|
111
|
+
moved=1
|
|
112
|
+
fi
|
|
113
|
+
done
|
|
114
|
+
if [ "$moved" = 1 ]; then group_end "$G" "$round" WAITING "$qa"; return 0; fi
|
|
115
|
+
|
|
116
|
+
# 3. The candidate: the integration HEAD plus every member's reviewed commit, merged in member order.
|
|
117
|
+
local cand="$wt_root/_group-$gid" base commit
|
|
118
|
+
base="$(git -C "$wt_root/_integration" rev-parse HEAD 2>/dev/null)" || base=""
|
|
119
|
+
if [ -z "$base" ]; then
|
|
120
|
+
note "group $gid: the integration worktree has no HEAD"
|
|
121
|
+
group_end "$G" "$round" ERROR "$qa"; return 0
|
|
122
|
+
fi
|
|
123
|
+
group_candidate_remove "$PLAN" "$REPO" "$cand"
|
|
124
|
+
if ! git -C "$REPO" worktree add --detach "$cand" "$base" > "$G/merge.out" 2>&1; then
|
|
125
|
+
note "group $gid: could not create the candidate worktree — see $G/merge.out"
|
|
126
|
+
group_end "$G" "$round" ERROR "$qa"; return 0
|
|
127
|
+
fi
|
|
128
|
+
forge_worktree_event created "$PLAN" "$REPO" "$cand" - candidate
|
|
129
|
+
printf '%s\n' "$base" > "$G/candidate.base"
|
|
130
|
+
for id in "${ids[@]}"; do
|
|
131
|
+
if ! git -C "$cand" -c user.name=forge -c user.email=forge@local \
|
|
132
|
+
merge --no-ff -m "forge: group $gid candidate: $id" "$(cat "$PLAN/tasks/$id/reviewed.commit")" >> "$G/merge.out" 2>&1; then
|
|
133
|
+
git -C "$cand" diff --name-only --diff-filter=U > "$G/conflict.files" 2>/dev/null
|
|
134
|
+
git -C "$cand" merge --abort >/dev/null 2>&1
|
|
135
|
+
if [ -s "$G/conflict.files" ]; then
|
|
136
|
+
note "group $gid: $id conflicts with the members before it: $(tr '\n' ' ' < "$G/conflict.files")"
|
|
137
|
+
group_end "$G" "$round" CONFLICT "$qa"
|
|
138
|
+
else
|
|
139
|
+
rm -f "$G/conflict.files"
|
|
140
|
+
note "group $gid: merging $id failed — see $G/merge.out"
|
|
141
|
+
group_end "$G" "$round" ERROR "$qa"
|
|
142
|
+
fi
|
|
143
|
+
return 0
|
|
144
|
+
fi
|
|
145
|
+
done
|
|
146
|
+
commit="$(git -C "$cand" rev-parse HEAD)"
|
|
147
|
+
printf '%s\n' "$commit" > "$G/candidate.commit"
|
|
148
|
+
for id in "${ids[@]}"; do
|
|
149
|
+
printf '%s\t%s\t%s\t%s\n' "$round" "$id" "$(cat "$PLAN/tasks/$id/reviewed.commit")" "$(cat "$PLAN/tasks/$id/attempt" 2>/dev/null || echo 0)"
|
|
150
|
+
done >> "$G/members.tsv"
|
|
151
|
+
{
|
|
152
|
+
for id in "${ids[@]}"; do printf '%s=%s\n' "$id" "$(cat "$PLAN/tasks/$id/reviewed.commit")"; done | LC_ALL=C sort
|
|
153
|
+
printf 'tree=%s\n' "$(git -C "$cand" rev-parse "$commit^{tree}")"
|
|
154
|
+
} | python3 -I -c 'import hashlib, sys; print(hashlib.sha256(sys.stdin.buffer.read()).hexdigest())' > "$G/fingerprint"
|
|
155
|
+
|
|
156
|
+
# 4. The size bound. A group over it is not reviewed, cut down or sent elsewhere: a person decides.
|
|
157
|
+
git -C "$cand" diff --binary --irreversible-delete "$base" "$commit" -- . ':(exclude).forge' > "$G/combined.diff" 2>/dev/null \
|
|
158
|
+
|| { note "group $gid: could not read the candidate's diff"; group_end "$G" "$round" ERROR "$qa"; return 0; }
|
|
159
|
+
local diff_bytes limit
|
|
160
|
+
diff_bytes="$(wc -c < "$G/combined.diff" | tr -d ' ')"
|
|
161
|
+
limit="$(group_size_limit "$PLAN")"
|
|
162
|
+
if [ "$diff_bytes" -gt $(( limit * 1024 )) ]; then
|
|
163
|
+
python3 -I "$SKILL_DIR/scripts/forge_groups/review.py" decision "$PLAN" "$gid" oversized --size "$diff_bytes" --limit "$limit" \
|
|
164
|
+
> "$G/decision.md.tmp" && mv -f "$G/decision.md.tmp" "$G/decision.md" \
|
|
165
|
+
|| { note "group $gid: could not write decision.md"; group_end "$G" "$round" ERROR "$qa"; return 0; }
|
|
166
|
+
note "group $gid: the combined diff is $diff_bytes bytes, over the $limit KB limit — stopped for your decision, see $G/decision.md"
|
|
167
|
+
group_end "$G" "$round" NEEDS_DECISION "$qa"; return 0
|
|
168
|
+
fi
|
|
169
|
+
|
|
170
|
+
# 5. The review snapshot, removed on every way out.
|
|
171
|
+
local snap="$G/review-$round-$$" stale cand_fp snap_fp thr
|
|
172
|
+
for stale in "$G"/review-*; do forge_drop_snapshot "$stale"; done
|
|
173
|
+
trap 'forge_drop_snapshot "$snap"' EXIT
|
|
174
|
+
trap 'exit 143' TERM INT
|
|
175
|
+
if ! forge_review_snapshot "$cand" "$base" "$commit" "$snap"; then
|
|
176
|
+
note "group $gid: could not make the review snapshot"
|
|
177
|
+
group_end "$G" "$round" ERROR "$qa"; return 0
|
|
178
|
+
fi
|
|
179
|
+
cand_fp="$(forge_fingerprint "$cand")" || { group_end "$G" "$round" ERROR "$qa"; return 0; }
|
|
180
|
+
# A commit: an untracked file the reviewer leaves behind merges nothing, so only tracked content counts (#95).
|
|
181
|
+
snap_fp="$(forge_fingerprint "$snap" --tracked)" || { group_end "$G" "$round" ERROR "$qa"; return 0; }
|
|
182
|
+
|
|
183
|
+
# 6. The prompt.
|
|
184
|
+
thr="$(qa_threshold_for "$PLAN" "")"
|
|
185
|
+
if ! python3 -I "$SKILL_DIR/scripts/forge_groups/review.py" prompt "$PLAN" "$gid" --threshold "$thr" > "$G/qa.input.tmp" \
|
|
186
|
+
|| ! mv -f "$G/qa.input.tmp" "$G/qa.input"; then
|
|
187
|
+
rm -f "$G/qa.input.tmp"
|
|
188
|
+
note "group $gid: could not build the review prompt"
|
|
189
|
+
group_end "$G" "$round" ERROR "$qa"; return 0
|
|
190
|
+
fi
|
|
191
|
+
local prompt_bytes
|
|
192
|
+
prompt_bytes="$(wc -c < "$G/qa.input" | tr -d ' ')"
|
|
193
|
+
if [ -z "$qa" ] || [ "$qa" = - ]; then
|
|
194
|
+
note "group $gid: no qa spec in groups.tsv; run plan again"
|
|
195
|
+
group_end "$G" "$round" ERROR "$qa"; return 0
|
|
196
|
+
fi
|
|
197
|
+
|
|
198
|
+
# 7. One QA dispatch, as a task's.
|
|
199
|
+
local yq="" ft_qa rc
|
|
200
|
+
[ -f "$PLAN/yolo_qa" ] && yq="--yolo"
|
|
201
|
+
ft_qa="$(forge_fast_tier "$PLAN" qa)"
|
|
202
|
+
local before_qa made
|
|
203
|
+
before_qa="$(ls -d "$G"/attempts/qa-* 2>/dev/null)"
|
|
204
|
+
/bin/bash "$DISPATCH" qa "$qa" --repo "$snap" --run-dir "$G" --review-base "$(cat "$G/review.base")" \
|
|
205
|
+
--prompt-file "$G/qa.input" ${yq:+"$yq"} $ft_qa --output "${FORGE_OUTPUT:-summary}" > "$G/qa.out" 2>&1
|
|
206
|
+
rc=$?
|
|
207
|
+
# The dispatch's own record of its round: the harvest reads it before it matches replies, so a round
|
|
208
|
+
# that leaves no qa.round-<n>.last (invalidated, timed out) still gets its dispatch.
|
|
209
|
+
for made in "$G"/attempts/qa-*; do
|
|
210
|
+
[ -d "$made" ] || continue
|
|
211
|
+
case $'\n'"$before_qa"$'\n' in *$'\n'"$made"$'\n'*) continue ;; esac
|
|
212
|
+
printf '%s\n' "$round" > "$made/group.round" 2>/dev/null || true
|
|
213
|
+
done
|
|
214
|
+
if [ "${FORGE_OUTPUT:-summary}" = full ]; then cat "$G/qa.out"; fi
|
|
215
|
+
if [ "$rc" -ne 0 ]; then
|
|
216
|
+
case "$rc" in
|
|
217
|
+
7) note "group $gid: qa hit the dispatch timeout — see $G/qa.out"; group_end "$G" "$round" TIMEOUT "$qa" ;;
|
|
218
|
+
8) { cp "$G/qa.infra" "$G/infra.txt" 2>/dev/null || : > "$G/infra.txt"; printf 'stage=qa\n' >> "$G/infra.txt"; }
|
|
219
|
+
note "group $gid: qa hit an infrastructure failure ($(sed -n 's/^class=//p' "$G/infra.txt" | head -1)) — see $G/infra.txt"
|
|
220
|
+
group_end "$G" "$round" INFRA "$qa" ;;
|
|
221
|
+
*) note "group $gid: qa dispatch failed — see $G/qa.out"; group_end "$G" "$round" ERROR "$qa" ;;
|
|
222
|
+
esac
|
|
223
|
+
return 0
|
|
224
|
+
fi
|
|
225
|
+
|
|
226
|
+
# 8. A tracked change to the candidate or to the snapshot during the review means the reply may not
|
|
227
|
+
# describe the commit under review.
|
|
228
|
+
if [ "$(forge_fingerprint "$cand")" != "$cand_fp" ] || [ "$(forge_fingerprint "$snap" --tracked)" != "$snap_fp" ]; then
|
|
229
|
+
note "group $gid: the candidate changed during its review"
|
|
230
|
+
group_end "$G" "$round" INVALIDATED "$qa"; return 0
|
|
231
|
+
fi
|
|
232
|
+
|
|
233
|
+
# 9. The verdict, and the gate at the plan's threshold: it can accept a FAIL made only of tolerated
|
|
234
|
+
# findings, and fail a PASS that lists a blocking one. No verdict is UNKNOWN, never a pass.
|
|
235
|
+
local verdict line decision="" final gated=0
|
|
236
|
+
verdict="$(forge_verdict "$G/qa.last" 2>/dev/null)"
|
|
237
|
+
[ -n "$verdict" ] || verdict=UNKNOWN
|
|
238
|
+
cp "$G/qa.last" "$G/qa.round-$round.last" 2>/dev/null || true
|
|
239
|
+
line="$(python3 "$SKILL_DIR/scripts/forge-contract.py" gate --verdict "$verdict" --qa-last "$G/qa.last" \
|
|
240
|
+
--threshold "$thr" --known-issues "$G/known_issues.md" 2>/dev/null)" || line=""
|
|
241
|
+
if [ -n "$line" ]; then
|
|
242
|
+
printf '%s\t%s\n' "$thr" "$line" > "$G/qa.gate"
|
|
243
|
+
decision="${line%%$'\t'*}"
|
|
244
|
+
fi
|
|
245
|
+
case "$decision" in accept|fail) gated=1 ;; esac
|
|
246
|
+
if [ "$verdict" = UNKNOWN ]; then final=UNKNOWN
|
|
247
|
+
elif [ "$decision" = accept ] || { [ "$verdict" = PASS ] && [ "$decision" != fail ]; }; then final=PASS
|
|
248
|
+
else final=FAIL; fi
|
|
249
|
+
|
|
250
|
+
# 10. Attribution: each finding to the members whose diff changed the file it names.
|
|
251
|
+
local implicated="-" ambiguous="-" findings=0 facts
|
|
252
|
+
for id in "${ids[@]}"; do
|
|
253
|
+
git -C "$REPO" -c core.quotepath=off diff --name-only "$(cat "$PLAN/tasks/$id/base_ref")" \
|
|
254
|
+
"$(cat "$PLAN/tasks/$id/reviewed.commit")" -- . ':(exclude).forge' | awk -v t="$id" '{ print t "\t" $0 }'
|
|
255
|
+
done > "$G/members.paths"
|
|
256
|
+
if [ -f "$G/qa.last" ]; then
|
|
257
|
+
if python3 -I "$SKILL_DIR/scripts/forge_groups/attribute.py" --qa-last "$G/qa.last" --members "$G/members.paths" \
|
|
258
|
+
--threshold "$thr" > "$G/attribution.json.tmp" 2> "$G/attribution.err" \
|
|
259
|
+
&& python3 -I -c 'import json, sys; d = json.load(sys.stdin); d["round"] = int(sys.argv[1]); print(json.dumps(d, indent=2, ensure_ascii=False))' \
|
|
260
|
+
"$round" < "$G/attribution.json.tmp" > "$G/attribution.json.new" \
|
|
261
|
+
&& mv -f "$G/attribution.json.new" "$G/attribution.json"; then
|
|
262
|
+
rm -f "$G/attribution.json.tmp" "$G/attribution.err"
|
|
263
|
+
facts="$(python3 -I "$SKILL_DIR/scripts/forge_groups/review.py" facts "$G/attribution.json")" || facts=""
|
|
264
|
+
IFS=$'\t' read -r implicated ambiguous findings _ <<< "$facts"
|
|
265
|
+
: "${implicated:=-}" "${ambiguous:=-}" "${findings:=0}"
|
|
266
|
+
else
|
|
267
|
+
rm -f "$G/attribution.json.tmp" "$G/attribution.json.new"
|
|
268
|
+
note "group $gid: could not attribute the findings — see $G/attribution.err"
|
|
269
|
+
group_end "$G" "$round" ERROR "$qa"; return 0
|
|
270
|
+
fi
|
|
271
|
+
fi
|
|
272
|
+
if [ "$final" = FAIL ] && [ "$ambiguous" != - ]; then
|
|
273
|
+
if python3 -I "$SKILL_DIR/scripts/forge_groups/review.py" decision "$PLAN" "$gid" ambiguous --attribution "$G/attribution.json" \
|
|
274
|
+
> "$G/decision.md.tmp" && mv -f "$G/decision.md.tmp" "$G/decision.md"; then
|
|
275
|
+
final=NEEDS_DECISION
|
|
276
|
+
note "group $gid: a blocking finding names no member task — stopped for your decision, see $G/decision.md"
|
|
277
|
+
else
|
|
278
|
+
rm -f "$G/decision.md.tmp"
|
|
279
|
+
note "group $gid: could not write decision.md; the group stays FAIL"
|
|
280
|
+
fi
|
|
281
|
+
fi
|
|
282
|
+
|
|
283
|
+
# 11. The round's records.
|
|
284
|
+
group_end "$G" "$round" "$final" "$qa" "$([ "$implicated" = - ] || printf '%s' "$implicated")"
|
|
285
|
+
forge_dataset_event group_review --dir "$PLAN" --set group="$gid" --set round="$round" \
|
|
286
|
+
--set members="$members" --set reviewer="$qa" --set verdict="$verdict" --set gated="$gated" \
|
|
287
|
+
--set implicated="$([ "$implicated" = - ] || printf '%s' "$implicated")" \
|
|
288
|
+
--set ambiguous="$([ "$ambiguous" = - ] || printf '%s' "$ambiguous")" \
|
|
289
|
+
--set findings="$findings" --set diff_bytes="$diff_bytes" --set prompt_bytes="$prompt_bytes"
|
|
290
|
+
return 0
|
|
291
|
+
)
|
|
292
|
+
|
|
293
|
+
# --- settling a group's outcome (#140) ------------------------------------------------------------
|
|
294
|
+
|
|
295
|
+
# A member's qa.last for one group round: a header, then the findings attributed to it (and, on a decision,
|
|
296
|
+
# the ambiguous ones a person gave it), then a verdict line. The blocks are the parser's own texts, in the
|
|
297
|
+
# group's order, so every one of them is a block of the group's qa.last. A finding that names other members
|
|
298
|
+
# too is preceded by `Also involves: <the others>` on a line of its own, which no finding block starts at.
|
|
299
|
+
group_member_report() { # group_member_report <group dir> <id> <members comma list> <verdict> [assigned ns [named ids]]
|
|
300
|
+
python3 -I - "$SKILL_DIR/scripts/forge_groups" "$@" <<'PY'
|
|
301
|
+
import json
|
|
302
|
+
import sys
|
|
303
|
+
from pathlib import Path
|
|
304
|
+
|
|
305
|
+
sys.path.insert(0, sys.argv[1])
|
|
306
|
+
import attribute
|
|
307
|
+
|
|
308
|
+
gdir, me, members, verdict = Path(sys.argv[2]), sys.argv[3], [m for m in sys.argv[4].split(',') if m], sys.argv[5]
|
|
309
|
+
assigned = {int(n) for n in (sys.argv[6] if len(sys.argv) > 6 else '').split(',') if n.strip().isdigit()}
|
|
310
|
+
named = [t for t in (sys.argv[7] if len(sys.argv) > 7 else '').split(',') if t]
|
|
311
|
+
round_no = int((gdir / 'round').read_text().strip() or 0)
|
|
312
|
+
text = (gdir / 'qa.last').read_text(encoding='utf-8', errors='replace')
|
|
313
|
+
rows = None
|
|
314
|
+
try:
|
|
315
|
+
data = json.loads((gdir / 'attribution.json').read_text(encoding='utf-8'))
|
|
316
|
+
if data.get('round') == round_no:
|
|
317
|
+
rows = data['findings']
|
|
318
|
+
except (OSError, ValueError, KeyError):
|
|
319
|
+
pass
|
|
320
|
+
blocks = attribute._contract().parse_findings(text)
|
|
321
|
+
if rows is None or len(rows) != len(blocks):
|
|
322
|
+
sys.stderr.write('the attribution does not describe the review of round %d\n' % round_no)
|
|
323
|
+
sys.exit(3)
|
|
324
|
+
out = ['Group %s, round %d: one review of %s. The findings below are the ones attributed to %s.'
|
|
325
|
+
% (gdir.name, round_no, ', '.join(members), me)]
|
|
326
|
+
count = 0
|
|
327
|
+
for row, finding in zip(rows, blocks):
|
|
328
|
+
tasks = row.get('tasks') or []
|
|
329
|
+
note = None
|
|
330
|
+
if me in tasks:
|
|
331
|
+
others = [t for t in tasks if t != me]
|
|
332
|
+
if others:
|
|
333
|
+
note = 'Also involves: ' + ', '.join(others)
|
|
334
|
+
elif row.get('n') in assigned and me in named:
|
|
335
|
+
others = [t for t in named if t != me]
|
|
336
|
+
note = ('Also involves: ' + ', '.join(others)) if others else \
|
|
337
|
+
'Not attributed to a member task by the review; assigned to %s by a decision.' % me
|
|
338
|
+
else:
|
|
339
|
+
continue
|
|
340
|
+
count += 1
|
|
341
|
+
out.append('')
|
|
342
|
+
if note:
|
|
343
|
+
out.append(note)
|
|
344
|
+
out.append(finding.text)
|
|
345
|
+
if not count:
|
|
346
|
+
out += ['', 'No finding is attributed to %s.' % me]
|
|
347
|
+
out += ['', 'FORGE_VERDICT: ' + verdict]
|
|
348
|
+
sys.stdout.write('\n'.join(out) + '\n')
|
|
349
|
+
PY
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
group_infra_class() { sed -n 's/^class=//p' "$1/infra.txt" 2>/dev/null | head -1; }
|
|
353
|
+
|
|
354
|
+
# Which of this group's rounds a status leaves to a person or to the scheduler: the line a status that
|
|
355
|
+
# settles nothing prints.
|
|
356
|
+
group_status_line() { # group_status_line <gid> <group dir> <status>
|
|
357
|
+
local gid="$1" G="$2" st="$3"
|
|
358
|
+
case "$st" in
|
|
359
|
+
PASS) echo "group $gid: PASS — nothing to send back; merge it with _merge_group" ;;
|
|
360
|
+
NEEDS_DECISION) echo "group $gid: NEEDS_DECISION — see $G/decision.md; name who fixes it with _group_settle $PLAN $gid --tasks <id,id>" ;;
|
|
361
|
+
UNKNOWN) echo "group $gid: UNKNOWN — the reviewer gave no verdict; review the group again" ;;
|
|
362
|
+
CONFLICT) echo "group $gid: CONFLICT — its members conflict ($(tr '\n' ' ' 2>/dev/null < "$G/conflict.files" || true)); a member must change" ;;
|
|
363
|
+
INFRA) echo "group $gid: INFRA — infrastructure failure ($(group_infra_class "$G")); no attempt spent, review the group again" ;;
|
|
364
|
+
TIMEOUT) echo "group $gid: TIMEOUT — the review hit the dispatch timeout; review the group again" ;;
|
|
365
|
+
ERROR) echo "group $gid: ERROR — the review could not run, see $G/merge.out and $G/qa.out" ;;
|
|
366
|
+
INVALIDATED) echo "group $gid: INVALIDATED — $(head -1 "$G/invalidated.reason" 2>/dev/null || echo 'the candidate changed during its review'); review the group again" ;;
|
|
367
|
+
WAITING) echo "group $gid: WAITING — a member is not IMPLEMENTED yet" ;;
|
|
368
|
+
REVIEWING) echo "group $gid: REVIEWING — a review is running" ;;
|
|
369
|
+
*) echo "group $gid: ${st:-no status} — the group was not reviewed" ;;
|
|
370
|
+
esac
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
do_group_settle() (
|
|
374
|
+
local usage="usage: forge-parallel.sh _group_settle <plan> <gid> [--tasks a,b]"
|
|
375
|
+
local PLAN="${1:?$usage}" gid="${2:?$usage}" named="" G row review members id st round verdict thr
|
|
376
|
+
shift 2
|
|
377
|
+
while [ $# -gt 0 ]; do
|
|
378
|
+
case "$1" in
|
|
379
|
+
--tasks) [ $# -ge 2 ] || die "--tasks needs a comma list of member tasks" 2; named="$2"; shift 2 ;;
|
|
380
|
+
--tasks=*) named="${1#--tasks=}"; shift ;;
|
|
381
|
+
*) die "unknown option '$1'. $usage" 2 ;;
|
|
382
|
+
esac
|
|
383
|
+
done
|
|
384
|
+
[ -d "$PLAN" ] || die "$PLAN is not a plan directory" 2
|
|
385
|
+
G="$PLAN/groups/$gid"
|
|
386
|
+
row="$(forge_groups_py show "$PLAN" 2>/dev/null | awk -F'\t' -v g="$gid" '$1 == g { print; exit }')"
|
|
387
|
+
[ -n "$row" ] || die "$gid is not a group of $PLAN" 2
|
|
388
|
+
IFS=$'\t' read -r _ review _ members _ <<< "$row"
|
|
389
|
+
[ "$review" = group ] || die "group $gid has review=$review: only a review=group group is settled as one" 2
|
|
390
|
+
local ids=() want=() n
|
|
391
|
+
IFS=, read -ra ids <<< "$members"
|
|
392
|
+
# Who a person named: members, written once, in member order.
|
|
393
|
+
if [ -n "$named" ]; then
|
|
394
|
+
local given=() g
|
|
395
|
+
IFS=, read -ra given <<< "${named// /}"
|
|
396
|
+
[ ${#given[@]} -gt 0 ] || die "--tasks names no task" 2
|
|
397
|
+
for g in "${given[@]}"; do
|
|
398
|
+
[ -n "$g" ] || die "--tasks has an empty task id" 2
|
|
399
|
+
case ",$members," in *",$g,"*) ;; *) die "--tasks: $g is not a member of group $gid ($members)" 2 ;; esac
|
|
400
|
+
done
|
|
401
|
+
for id in "${ids[@]}"; do case ",${named// /}," in *",$id,"*) want+=("$id") ;; esac; done
|
|
402
|
+
fi
|
|
403
|
+
round="$(tr -dc '0-9' < "$G/round" 2>/dev/null)"
|
|
404
|
+
[ -n "$round" ] || die "group $gid has not been reviewed" 2
|
|
405
|
+
# One settle per round, however often it is asked.
|
|
406
|
+
[ "$(cat "$G/settled.round" 2>/dev/null)" = "$round" ] && return 0
|
|
407
|
+
st="$(head -1 "$G/status" 2>/dev/null | tr -d '[:space:]')"
|
|
408
|
+
|
|
409
|
+
# A person's answer to a decision: the findings that name no member go to the tasks they named.
|
|
410
|
+
local pending="" assigned=""
|
|
411
|
+
if [ -n "$named" ]; then
|
|
412
|
+
local kept
|
|
413
|
+
kept="$(awk -F'\t' -v r="$round" '$1 == r { print $2; exit }' "$G/settle.tasks" 2>/dev/null)"
|
|
414
|
+
if [ "$st" = FAIL ] && [ -n "$kept" ]; then
|
|
415
|
+
# An answer that was interrupted: it settles as it was given.
|
|
416
|
+
IFS=, read -ra want <<< "$kept"
|
|
417
|
+
elif [ "$st" != NEEDS_DECISION ]; then
|
|
418
|
+
die "group $gid is $st, not NEEDS_DECISION: --tasks answers a decision" 2
|
|
419
|
+
fi
|
|
420
|
+
elif [ "$st" = FAIL ]; then
|
|
421
|
+
kept="$(awk -F'\t' -v r="$round" '$1 == r { print $2; exit }' "$G/settle.tasks" 2>/dev/null)"
|
|
422
|
+
[ -z "$kept" ] || { IFS=, read -ra want <<< "$kept"; named="$kept"; }
|
|
423
|
+
fi
|
|
424
|
+
if [ "$st" != FAIL ] && [ "$st" != NEEDS_DECISION ] || { [ "$st" = NEEDS_DECISION ] && [ -z "$named" ]; }; then
|
|
425
|
+
note "$(group_status_line "$gid" "$G" "$st")"
|
|
426
|
+
return 0
|
|
427
|
+
fi
|
|
428
|
+
local facts implicated ambiguous named_ids=()
|
|
429
|
+
if [ -n "$named" ]; then
|
|
430
|
+
facts="$(python3 -I "$SKILL_DIR/scripts/forge_groups/review.py" facts "$G/attribution.json" 2>/dev/null)" || facts=""
|
|
431
|
+
IFS=$'\t' read -r implicated ambiguous _ <<< "$facts"
|
|
432
|
+
if [ "$(python3 -I -c 'import json, sys; print(json.load(open(sys.argv[1])).get("round"))' "$G/attribution.json" 2>/dev/null)" != "$round" ] \
|
|
433
|
+
|| [ -z "${ambiguous:-}" ] || [ "$ambiguous" = - ]; then
|
|
434
|
+
die "group $gid has no blocking finding that names no member in round $round: nothing for --tasks to assign" 2
|
|
435
|
+
fi
|
|
436
|
+
assigned="$ambiguous"
|
|
437
|
+
# The members whose own blocking findings the review attributed go back too, named or not: left
|
|
438
|
+
# IMPLEMENTED, the next group round would only find the same thing again.
|
|
439
|
+
named_ids=("${want[@]}")
|
|
440
|
+
if [ -n "${implicated:-}" ] && [ "$implicated" != - ]; then
|
|
441
|
+
local union=()
|
|
442
|
+
for id in "${ids[@]}"; do
|
|
443
|
+
case ",${named// /},$implicated," in *",$id,"*) union+=("$id") ;; esac
|
|
444
|
+
done
|
|
445
|
+
want=("${union[@]}")
|
|
446
|
+
fi
|
|
447
|
+
else
|
|
448
|
+
facts="$(python3 -I "$SKILL_DIR/scripts/forge_groups/review.py" facts "$G/attribution.json" 2>/dev/null)" || facts=""
|
|
449
|
+
IFS=$'\t' read -r implicated ambiguous _ <<< "$facts"
|
|
450
|
+
if [ -z "${implicated:-}" ] || [ "$implicated" = - ]; then
|
|
451
|
+
note "group $gid: FAIL, but no member is implicated — nothing to send back"
|
|
452
|
+
return 0
|
|
453
|
+
fi
|
|
454
|
+
IFS=, read -ra want <<< "$implicated"
|
|
455
|
+
# Member order, whatever order the attribution listed them in.
|
|
456
|
+
local ordered=()
|
|
457
|
+
for id in "${ids[@]}"; do case ",$implicated," in *",$id,"*) ordered+=("$id") ;; esac; done
|
|
458
|
+
if [ ${#ordered[@]} -eq 0 ]; then
|
|
459
|
+
note "group $gid: FAIL, but the implicated tasks ($implicated) are not members — nothing to send back"
|
|
460
|
+
return 0
|
|
461
|
+
fi
|
|
462
|
+
want=("${ordered[@]}")
|
|
463
|
+
named=""
|
|
464
|
+
fi
|
|
465
|
+
|
|
466
|
+
# Every member's report is made before anything changes: one that cannot be made changes nothing.
|
|
467
|
+
verdict="$(forge_verdict "$G/qa.last" 2>/dev/null)"; [ "$verdict" = PASS ] || [ "$verdict" = FAIL ] || verdict=FAIL
|
|
468
|
+
thr="$(cut -f1 "$G/qa.gate" 2>/dev/null | head -1)"; [ -n "$thr" ] || thr="$(qa_threshold_for "$PLAN" "")"
|
|
469
|
+
local named_csv=""; [ -z "$named" ] || named_csv="$(IFS=,; echo "${named_ids[*]}")"
|
|
470
|
+
for id in "${want[@]}"; do
|
|
471
|
+
if ! group_member_report "$G" "$id" "$members" FAIL "$assigned" "$named_csv" > "$PLAN/tasks/$id/.qa.last.settle.tmp" 2> "$G/settle.err"; then
|
|
472
|
+
for n in "${want[@]}"; do rm -f "$PLAN/tasks/$n/.qa.last.settle.tmp"; done
|
|
473
|
+
note "group $gid: could not write $id's findings — $(head -1 "$G/settle.err") (see $G/attribution.json)"
|
|
474
|
+
return 3
|
|
475
|
+
fi
|
|
476
|
+
done
|
|
477
|
+
rm -f "$G/settle.err"
|
|
478
|
+
|
|
479
|
+
# A decision is answered: the status says FAIL first, and decision.md is kept as the round's.
|
|
480
|
+
if [ -n "$named" ] && [ "$st" = NEEDS_DECISION ]; then
|
|
481
|
+
printf '%s\t%s\n' "$round" "$named_csv" > "$G/settle.tasks.tmp" && mv -f "$G/settle.tasks.tmp" "$G/settle.tasks"
|
|
482
|
+
group_set_status "$G" FAIL
|
|
483
|
+
[ ! -f "$G/decision.md" ] || mv -f "$G/decision.md" "$G/decision.$round.md"
|
|
484
|
+
fi
|
|
485
|
+
local tdir
|
|
486
|
+
for id in "${want[@]}"; do
|
|
487
|
+
tdir="$PLAN/tasks/$id"
|
|
488
|
+
if [ "$(cat "$tdir/settled.group" 2>/dev/null)" = "$gid $round" ]; then rm -f "$tdir/.qa.last.settle.tmp"; continue; fi
|
|
489
|
+
mv -f "$tdir/.qa.last.settle.tmp" "$tdir/qa.last"
|
|
490
|
+
qa_gate "$PLAN" "$id" "$tdir" "$verdict" "$thr"
|
|
491
|
+
echo FAIL > "$tdir/status"
|
|
492
|
+
record_judged_attempt "$PLAN" "$id" FAIL
|
|
493
|
+
post_attempt "$PLAN" "$id" || true
|
|
494
|
+
printf '%s %s\n' "$gid" "$round" > "$tdir/settled.group"
|
|
495
|
+
done
|
|
496
|
+
printf '%s\n' "$round" > "$G/settled.round.tmp" && mv -f "$G/settled.round.tmp" "$G/settled.round"
|
|
497
|
+
rm -f "$G/settle.tasks"
|
|
498
|
+
note "group $gid: round $round sent back to $(IFS=,; echo "${want[*]}")"
|
|
499
|
+
return 0
|
|
500
|
+
)
|
|
501
|
+
|
|
502
|
+
# --- merging a group (#140) ------------------------------------------------------------------------
|
|
503
|
+
|
|
504
|
+
group_invalidate() { # group_invalidate <plan> <gid> <reason>: the group's status, its reason, and the dataset's row
|
|
505
|
+
printf '%s\n' "$3" > "$1/groups/$2/invalidated.reason"
|
|
506
|
+
group_set_status "$1/groups/$2" INVALIDATED
|
|
507
|
+
forge_dataset_event group_merge --dir "$1" --set group="$2" --set status=INVALIDATED --set reason="$3"
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
# The fingerprint do_group wrote, from what is on disk now: the members' commits of the round, sorted, and
|
|
511
|
+
# the candidate's tree.
|
|
512
|
+
group_recompute_fingerprint() { # group_recompute_fingerprint <plan> <gid> <round> <repo>
|
|
513
|
+
local G="$1/groups/$2" commit
|
|
514
|
+
commit="$(cat "$G/candidate.commit" 2>/dev/null)"
|
|
515
|
+
{
|
|
516
|
+
awk -F'\t' -v r="$3" '$1 == r { print $2 "=" $3 }' "$G/members.tsv" 2>/dev/null | LC_ALL=C sort
|
|
517
|
+
printf 'tree=%s\n' "$(git -C "$4" rev-parse --verify --quiet "$commit^{tree}" 2>/dev/null)"
|
|
518
|
+
} | python3 -I -c 'import hashlib, sys; print(hashlib.sha256(sys.stdin.buffer.read()).hexdigest())'
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
merge_group() { # merge_group <plan> <gid> -> 0 merged, 1 not
|
|
522
|
+
local usage="usage: forge-parallel.sh _merge_group <plan> <gid>"
|
|
523
|
+
local PLAN="${1:?$usage}" gid="${2:?$usage}" G REPO run_id int_wt row review members st round id
|
|
524
|
+
[ -d "$PLAN" ] || die "$PLAN is not a plan directory" 2
|
|
525
|
+
G="$PLAN/groups/$gid"
|
|
526
|
+
row="$(forge_groups_py show "$PLAN" 2>/dev/null | awk -F'\t' -v g="$gid" '$1 == g { print; exit }')"
|
|
527
|
+
[ -n "$row" ] || die "$gid is not a group of $PLAN" 2
|
|
528
|
+
IFS=$'\t' read -r _ review _ members _ <<< "$row"
|
|
529
|
+
[ "$review" = group ] || die "group $gid has review=$review: only a review=group group is merged as one" 2
|
|
530
|
+
if [ -f "$G/merged" ]; then note "group $gid: already merged"; return 0; fi
|
|
531
|
+
st="$(head -1 "$G/status" 2>/dev/null | tr -d '[:space:]')"
|
|
532
|
+
if [ "$st" != PASS ]; then note "group $gid: ${st:-not reviewed}, not PASS — nothing to merge"; return 1; fi
|
|
533
|
+
REPO="$(cat "$PLAN/repo")"; run_id="$(cat "$PLAN/run_id")"
|
|
534
|
+
int_wt="$(cat "$PLAN/wt_root")/_integration"
|
|
535
|
+
round="$(tr -dc '0-9' < "$G/round" 2>/dev/null)"
|
|
536
|
+
local ids=()
|
|
537
|
+
IFS=, read -ra ids <<< "$members"
|
|
538
|
+
|
|
539
|
+
# merge_task's guards.
|
|
540
|
+
if [ -s "$PLAN/accepted.integration" ] && [ "$(git -C "$int_wt" rev-parse HEAD)" != "$(cat "$PLAN/accepted.integration")" ]; then
|
|
541
|
+
group_invalidate "$PLAN" "$gid" integration-moved
|
|
542
|
+
note "group $gid: the integration branch moved outside this run. To bring those commits into the run: forge-parallel.sh adopt $PLAN --head --reason \"...\""
|
|
543
|
+
return 1
|
|
544
|
+
fi
|
|
545
|
+
if [ -n "$(git -C "$int_wt" status --porcelain -- . ':(exclude).forge')" ]; then
|
|
546
|
+
group_invalidate "$PLAN" "$gid" integration-dirty
|
|
547
|
+
return 1
|
|
548
|
+
fi
|
|
549
|
+
local dep
|
|
550
|
+
for id in "${ids[@]}"; do
|
|
551
|
+
for dep in $(field "$PLAN/tasks.tsv" "$id" deps | tr ',' ' '); do
|
|
552
|
+
[ "$dep" = - ] && continue
|
|
553
|
+
if [ "$(task_status "$PLAN" "$dep")" != MERGED ]; then
|
|
554
|
+
note "group $gid: $id is BLOCKED by $dep ($(task_status "$PLAN" "$dep"))"
|
|
555
|
+
return 1
|
|
556
|
+
fi
|
|
557
|
+
done
|
|
558
|
+
done
|
|
559
|
+
|
|
560
|
+
# The candidate and the members are what the review judged.
|
|
561
|
+
local moved=() off=0 reviewed head commit
|
|
562
|
+
for id in "${ids[@]}"; do
|
|
563
|
+
reviewed="$(awk -F'\t' -v r="$round" -v t="$id" '$1 == r && $2 == t { c = $3 } END { print c }' "$G/members.tsv" 2>/dev/null)"
|
|
564
|
+
head="$(git -C "$REPO" rev-parse --verify --quiet "forge/$run_id/$id" 2>/dev/null)"
|
|
565
|
+
if [ -z "$reviewed" ] || [ "$head" != "$reviewed" ] \
|
|
566
|
+
|| [ "$(forge_fingerprint "$(cat "$PLAN/wt_root")/$id" 2>/dev/null)" != "$(cat "$PLAN/tasks/$id/source.fingerprint" 2>/dev/null)" ]; then
|
|
567
|
+
moved+=("$id")
|
|
568
|
+
elif [ "$(task_status "$PLAN" "$id")" != IMPLEMENTED ]; then
|
|
569
|
+
off=1
|
|
570
|
+
fi
|
|
571
|
+
done
|
|
572
|
+
commit="$(cat "$G/candidate.commit" 2>/dev/null)"
|
|
573
|
+
if [ ${#moved[@]} -gt 0 ]; then
|
|
574
|
+
for id in "${moved[@]}"; do
|
|
575
|
+
echo group-candidate > "$PLAN/tasks/$id/invalidated.reason"
|
|
576
|
+
echo INVALIDATED > "$PLAN/tasks/$id/status"
|
|
577
|
+
done
|
|
578
|
+
group_invalidate "$PLAN" "$gid" candidate-moved
|
|
579
|
+
note "group $gid: ${moved[*]} moved since the review — nothing merged"
|
|
580
|
+
return 1
|
|
581
|
+
fi
|
|
582
|
+
if [ "$off" = 1 ] || [ -z "$commit" ] \
|
|
583
|
+
|| [ "$(group_recompute_fingerprint "$PLAN" "$gid" "$round" "$REPO")" != "$(cat "$G/fingerprint" 2>/dev/null)" ]; then
|
|
584
|
+
group_invalidate "$PLAN" "$gid" candidate-moved
|
|
585
|
+
note "group $gid: the candidate is not what was reviewed — nothing merged"
|
|
586
|
+
return 1
|
|
587
|
+
fi
|
|
588
|
+
|
|
589
|
+
# Each member's report, made before the merge: one that cannot be made does not leave a merge half recorded.
|
|
590
|
+
local thr verdict ids_csv
|
|
591
|
+
thr="$(cut -f1 "$G/qa.gate" 2>/dev/null | head -1)"; [ -n "$thr" ] || thr="$(qa_threshold_for "$PLAN" "")"
|
|
592
|
+
ids_csv="$(IFS=,; echo "${ids[*]}")"
|
|
593
|
+
for id in "${ids[@]}"; do
|
|
594
|
+
group_member_report "$G" "$id" "$members" PASS > "$PLAN/tasks/$id/.qa.last.merge.tmp" 2>/dev/null || {
|
|
595
|
+
printf 'Group %s, round %s: one review of %s. The findings below are the ones attributed to %s.\n\n' \
|
|
596
|
+
"$gid" "$round" "${members//,/, }" "$id"
|
|
597
|
+
printf '(The review could not be attributed; the whole of it follows.)\n\n'
|
|
598
|
+
cat "$G/qa.last" 2>/dev/null
|
|
599
|
+
printf '\nFORGE_VERDICT: PASS\n'
|
|
600
|
+
} > "$PLAN/tasks/$id/.qa.last.merge.tmp"
|
|
601
|
+
done
|
|
602
|
+
|
|
603
|
+
if ! git -C "$int_wt" merge --no-ff -m "forge: merge group $gid ($ids_csv)" "$commit" >/dev/null 2>&1; then
|
|
604
|
+
# Which files collided is kept, and the abort erases it. No member is merged: nothing is promoted partly.
|
|
605
|
+
git -C "$int_wt" diff --name-only --diff-filter=U > "$G/conflict.files" 2>/dev/null
|
|
606
|
+
git -C "$int_wt" merge --abort >/dev/null 2>&1
|
|
607
|
+
for id in "${ids[@]}"; do rm -f "$PLAN/tasks/$id/.qa.last.merge.tmp"; echo CONFLICT > "$PLAN/tasks/$id/status"; done
|
|
608
|
+
group_set_status "$G" CONFLICT
|
|
609
|
+
forge_dataset_event group_merge --dir "$PLAN" --set group="$gid" --set status=CONFLICT --set commit="$commit" \
|
|
610
|
+
--set conflicts="$(tr '\n' ' ' < "$G/conflict.files" 2>/dev/null)"
|
|
611
|
+
note "group $gid: conflicts with the integration branch: $(tr '\n' ' ' < "$G/conflict.files" 2>/dev/null)"
|
|
612
|
+
return 1
|
|
613
|
+
fi
|
|
614
|
+
git -C "$int_wt" rev-parse HEAD > "$PLAN/accepted.integration"
|
|
615
|
+
local tdir integration
|
|
616
|
+
integration="$(cat "$PLAN/accepted.integration")"
|
|
617
|
+
for id in "${ids[@]}"; do
|
|
618
|
+
tdir="$PLAN/tasks/$id"
|
|
619
|
+
touch "$tdir/merged"
|
|
620
|
+
rm -f "$tdir/conflict.files"
|
|
621
|
+
mv -f "$tdir/.qa.last.merge.tmp" "$tdir/qa.last"
|
|
622
|
+
qa_gate "$PLAN" "$id" "$tdir" PASS "$thr"
|
|
623
|
+
echo PASS > "$tdir/status"
|
|
624
|
+
record_judged_attempt "$PLAN" "$id" PASS
|
|
625
|
+
[ ! -f "$tdir/sweep.json" ] || python3 "$SKILL_DIR/scripts/forge-sweep.py" settle "$PLAN" "$id" >/dev/null 2>&1 || true
|
|
626
|
+
done
|
|
627
|
+
rm -f "$G/conflict.files" "$G/invalidated.reason"
|
|
628
|
+
touch "$G/merged"
|
|
629
|
+
forge_dataset_event group_merge --dir "$PLAN" --set group="$gid" --set status=MERGED --set commit="$commit" \
|
|
630
|
+
--set members="$members" --set integration="$integration"
|
|
631
|
+
for id in "${ids[@]}"; do
|
|
632
|
+
forge_dataset_event merge --dir "$PLAN" --task "$id" --set status=MERGED \
|
|
633
|
+
--set commit="$(awk -F'\t' -v r="$round" -v t="$id" '$1 == r && $2 == t { c = $3 } END { print c }' "$G/members.tsv")" \
|
|
634
|
+
--set integration="$integration" --set group="$gid"
|
|
635
|
+
done
|
|
636
|
+
note "group $gid: $ids_csv merged"
|
|
637
|
+
# With brief on, flag each member's dependents here, for the scheduler and a direct call alike (the
|
|
638
|
+
# scheduler's merge_group does not repeat it).
|
|
639
|
+
for id in "${ids[@]}"; do forge_brief_stale "$PLAN" "$id"; done
|
|
640
|
+
return 0
|
|
641
|
+
}
|