@giamme/forge 0.18.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 +33 -0
- package/README.md +1 -0
- package/SKILL.md +16 -2
- package/VERSION +1 -1
- package/docs/artifacts.md +25 -1
- package/docs/commands.md +81 -14
- package/docs/decomposed-runs.md +114 -1
- package/docs/development.md +2 -1
- package/docs/forge-ui.md +84 -15
- package/docs/memory.md +25 -4
- package/docs/models.md +8 -0
- package/docs/reviews.md +122 -0
- package/forge +20 -3
- package/package.json +2 -1
- package/references/dataset.md +20 -1
- package/references/decompose.md +621 -33
- package/references/harnesses.md +18 -3
- package/references/planning.md +43 -14
- package/references/ui.md +53 -6
- package/registry.tsv +8 -3
- package/scripts/forge-brief.py +88 -3
- package/scripts/forge-compare.py +4 -3
- package/scripts/forge-contract.py +202 -27
- package/scripts/forge-control.py +117 -5
- package/scripts/forge-dispatch.sh +34 -5
- 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-group.sh +641 -0
- package/scripts/forge-lib-plans.sh +339 -3
- package/scripts/forge-lib-task.sh +197 -4
- package/scripts/forge-memory.sh +245 -3
- package/scripts/forge-parallel.sh +715 -34
- package/scripts/forge-planner.py +104 -8
- package/scripts/forge-route.py +190 -12
- package/scripts/forge-runs.py +9 -5
- package/scripts/forge-schedule.py +354 -45
- package/scripts/forge-solo.sh +2 -0
- package/scripts/forge-worktrees.py +243 -0
- package/scripts/forge_brief/__init__.py +294 -50
- package/scripts/forge_brief/answers.py +58 -11
- package/scripts/forge_brief/proposals.py +1630 -0
- package/scripts/forge_dataset/efforts.py +4 -3
- package/scripts/forge_dataset/export.py +24 -12
- package/scripts/forge_dataset/facts.py +5 -3
- package/scripts/forge_dataset/forecast.py +8 -18
- package/scripts/forge_dataset/harvest.py +204 -9
- package/scripts/forge_dataset/history.py +11 -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_groups/__init__.py +308 -0
- package/scripts/forge_groups/attribute.py +289 -0
- package/scripts/forge_groups/review.py +286 -0
- package/scripts/forge_owner.py +152 -0
- package/scripts/forge_side/__init__.py +12 -7
- package/ui/docs/api.md +173 -17
- package/ui/forge_ui/control.py +361 -2
- package/ui/forge_ui/executions.py +8 -1
- package/ui/forge_ui/export.py +31 -4
- package/ui/forge_ui/groups.py +264 -0
- package/ui/forge_ui/models.py +70 -8
- package/ui/forge_ui/reader.py +262 -19
- package/ui/forge_ui/server.py +4 -0
- package/ui/forge_ui/static/app.js +93 -13
- package/ui/forge_ui/static/briefview.js +350 -47
- 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 +1 -0
- package/ui/forge_ui/static/panel.js +127 -7
- package/ui/forge_ui/static/projectsview.js +189 -10
- package/ui/forge_ui/static/runmodel.js +14 -3
- package/ui/forge_ui/static/storageview.js +91 -10
- package/ui/forge_ui/static/style.css +79 -5
- package/ui/forge_ui/static/worktreesview.js +233 -12
- package/ui/forge_ui/storage.py +14 -0
|
@@ -130,7 +130,322 @@ 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 implementer_session fast 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 profile.json routed.json retro_mode brief brief_scope brief_model summaries summaries_model"
|
|
133
|
+
PLANS_OPTION_FILES="no_ripwire no_memory yolo_dwarf yolo_qa reviewer_session reviewer_session_rate reviewer_session_tasks implementer_session fast 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 retry_per_model fractal-routing.json fractal-selection.json jev-selection.json profile.json routed.json retro_mode brief brief_scope brief_model summaries summaries_model groups.tsv groups.frozen group_max_tasks group_max_diff_kb after"
|
|
134
|
+
|
|
135
|
+
# --- plan --after: a plan that starts from another plan's integration branch (#143) -------
|
|
136
|
+
# $PLAN/after holds the previous plan's absolute path; $PLAN/integration.base the commit its work
|
|
137
|
+
# started from (the previous plan's accepted.integration). The integration branch of this plan is
|
|
138
|
+
# created there at plan time, so `run` finds it and reuses it.
|
|
139
|
+
|
|
140
|
+
# The repository a checkout belongs to: its main working tree, as a physical path. The same for the
|
|
141
|
+
# main checkout and every linked worktree; repo.identity names it once the checkout is gone.
|
|
142
|
+
plans_repo_root() { # plans_repo_root <checkout> <plan dir>
|
|
143
|
+
local root=""
|
|
144
|
+
root="$(git -C "$1" worktree list --porcelain 2>/dev/null | awk '/^worktree /{ sub(/^worktree /, ""); print; exit }')"
|
|
145
|
+
if [ -z "$root" ] && [ -f "$2/repo.identity" ]; then
|
|
146
|
+
root="$(python3 -I -c 'import json, sys; print(json.load(open(sys.argv[1])).get("root") or "")' "$2/repo.identity" 2>/dev/null)"
|
|
147
|
+
fi
|
|
148
|
+
[ -n "$root" ] || root="$1"
|
|
149
|
+
(cd "$root" 2>/dev/null && pwd -P) || printf '%s\n' "$root"
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
# The pid of a plan's live scheduler (scheduler.live names it), else nothing.
|
|
153
|
+
plans_live_pid() { # plans_live_pid <plan dir>
|
|
154
|
+
local pid
|
|
155
|
+
[ -f "$1/scheduler.live" ] || return 0
|
|
156
|
+
pid="$(python3 -I -c 'import json, sys; print(int(json.load(open(sys.argv[1]))["pid"]))' "$1/scheduler.live" 2>/dev/null)" || return 0
|
|
157
|
+
[ -n "$pid" ] && kill -0 "$pid" 2>/dev/null && printf '%s\n' "$pid"
|
|
158
|
+
return 0
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
# The plan's own _integration worktree, when it is the only checkout of forge/<rid>-integration,
|
|
162
|
+
# clean, and still at <commit>. `run` leaves the branch there. Empty when another checkout holds
|
|
163
|
+
# it, or this one has uncommitted changes: those are not moved.
|
|
164
|
+
plans_chain_own_wt() { # plans_chain_own_wt <repo> <plan> <run id> <commit>
|
|
165
|
+
local repo="$1" plan="$2" rid="$3" commit="$4" want="" wt="" line="" n=0 found=""
|
|
166
|
+
local found_phys="" want_phys=""
|
|
167
|
+
[ -s "$plan/wt_root" ] || return 0
|
|
168
|
+
want="$(head -1 "$plan/wt_root")/_integration"
|
|
169
|
+
[ -d "$want" ] || return 0
|
|
170
|
+
[ "$(git -C "$want" rev-parse --abbrev-ref HEAD 2>/dev/null)" = "forge/$rid-integration" ] || return 0
|
|
171
|
+
[ "$(git -C "$want" rev-parse HEAD 2>/dev/null)" = "$commit" ] || return 0
|
|
172
|
+
git -C "$want" diff --quiet && git -C "$want" diff --cached --quiet || return 0
|
|
173
|
+
while IFS= read -r line || [ -n "$line" ]; do
|
|
174
|
+
case "$line" in
|
|
175
|
+
worktree\ *) wt="${line#worktree }" ;;
|
|
176
|
+
"branch refs/heads/forge/$rid-integration") n=$((n + 1)); found="$wt" ;;
|
|
177
|
+
esac
|
|
178
|
+
done < <(git -C "$repo" worktree list --porcelain 2>/dev/null)
|
|
179
|
+
[ "$n" = 1 ] || return 0
|
|
180
|
+
found_phys="$(cd "$found" 2>/dev/null && pwd -P)" || return 0
|
|
181
|
+
want_phys="$(cd "$want" 2>/dev/null && pwd -P)" || return 0
|
|
182
|
+
[ "$found_phys" = "$want_phys" ] || return 0
|
|
183
|
+
printf '%s\n' "$want"
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
# plans_chain_early <plan> <plan's arguments...>: settles --after before plan writes anything.
|
|
187
|
+
# Refuses (exit 2) with nothing written; otherwise sets CHAIN_PREV (the previous plan's absolute
|
|
188
|
+
# path) and CHAIN_BASE (the commit to start from), both empty when plan has no new --after to
|
|
189
|
+
# apply: none given, or the one the plan already records.
|
|
190
|
+
plans_chain_early() {
|
|
191
|
+
local plan="$1" given="" repo_flag="" want="" arg have_after=0
|
|
192
|
+
shift
|
|
193
|
+
CHAIN_PREV=""; CHAIN_BASE=""; CHAIN_MOVE=0; CHAIN_WT=""
|
|
194
|
+
for arg in "$@"; do
|
|
195
|
+
case "$want" in
|
|
196
|
+
--after) given="$arg"; have_after=1; want=""; continue ;;
|
|
197
|
+
--repo) repo_flag="$arg"; want=""; continue ;;
|
|
198
|
+
esac
|
|
199
|
+
want=""
|
|
200
|
+
case "$arg" in --after|--repo) want="$arg" ;; esac
|
|
201
|
+
done
|
|
202
|
+
[ "$want" != --after ] || die "--after needs a plan directory" 2
|
|
203
|
+
[ "$have_after" = 1 ] || return 0
|
|
204
|
+
[ -n "$given" ] || die "--after needs a plan directory" 2
|
|
205
|
+
[ -d "$given" ] || die "--after '$given' is not a directory" 2
|
|
206
|
+
local prev prev_phys old="" merged=0
|
|
207
|
+
prev="$(plans_abs "$given")"; prev_phys="$(cd "$given" && pwd -P)"
|
|
208
|
+
[ "$prev_phys" != "$(cd "$plan" && pwd -P)" ] || die "--after: a plan cannot come after itself" 2
|
|
209
|
+
[ -s "$prev/tasks.tsv" ] && [ -s "$prev/run_id" ] && [ -s "$prev/repo" ] \
|
|
210
|
+
|| die "--after '$given' is not a plan directory (it needs tasks.tsv, run_id and repo)" 2
|
|
211
|
+
# Once a task of this plan has merged, its base is fixed: the predecessor it records again is a
|
|
212
|
+
# plain re-plan, any other is refused.
|
|
213
|
+
local m
|
|
214
|
+
for m in "$plan"/tasks/*/merged; do [ ! -e "$m" ] || merged=1; done
|
|
215
|
+
[ ! -s "$plan/after" ] || old="$(head -1 "$plan/after")"
|
|
216
|
+
if [ "$merged" = 1 ] && [ -n "$old" ]; then
|
|
217
|
+
if [ "$old" = "$prev" ] || { [ -d "$old" ] && [ "$(cd "$old" && pwd -P)" = "$prev_phys" ]; }; then return 0; fi
|
|
218
|
+
die "this plan already follows '$old' and has merged work: --after '$given' would move it to another base" 2
|
|
219
|
+
fi
|
|
220
|
+
|
|
221
|
+
local repo="$repo_flag"
|
|
222
|
+
[ -n "$repo" ] || repo="$(cat "$plan/repo" 2>/dev/null)"
|
|
223
|
+
[ -n "$repo" ] || die "plan needs --repo the first time" 2
|
|
224
|
+
[ -d "$repo" ] || die "--repo '$repo' is not a directory" 2
|
|
225
|
+
local prepo; prepo="$(head -1 "$prev/repo")"
|
|
226
|
+
[ "$(plans_repo_root "$repo" "$plan")" = "$(plans_repo_root "$prepo" "$prev")" ] \
|
|
227
|
+
|| die "--after '$given' belongs to another repository ($prepo), not $repo" 2
|
|
228
|
+
|
|
229
|
+
local prid id st bad="" ibr tip acc
|
|
230
|
+
prid="$(head -1 "$prev/run_id")"
|
|
231
|
+
for id in $(all_ids "$prev/tasks.tsv"); do
|
|
232
|
+
st="$(task_status "$prev" "$id")"
|
|
233
|
+
[ "$st" = MERGED ] || bad="${bad:+$bad, }$id ($st)"
|
|
234
|
+
done
|
|
235
|
+
[ -z "$bad" ] || die "plan $prid is not finished: not merged yet: $bad" 2
|
|
236
|
+
ibr="forge/$prid-integration"
|
|
237
|
+
tip="$(git -C "$repo" rev-parse --verify --quiet "refs/heads/$ibr")" \
|
|
238
|
+
|| die "plan $prid's integration branch $ibr is missing" 2
|
|
239
|
+
acc="$(head -1 "$prev/accepted.integration" 2>/dev/null)"
|
|
240
|
+
[ -n "$acc" ] || die "plan $prid has no accepted.integration: run it first" 2
|
|
241
|
+
[ "$tip" = "$acc" ] \
|
|
242
|
+
|| die "$ibr is at $(plans_short "$tip") but plan $prid accepted $(plans_short "$acc"): adopt it into that plan first (forge-parallel.sh adopt $prev --head --reason \"...\")" 2
|
|
243
|
+
local pid; pid="$(plans_live_pid "$prev")"
|
|
244
|
+
[ -z "$pid" ] || die "plan $prid is running (scheduler pid $pid): wait for it to stop" 2
|
|
245
|
+
# This plan's own integration branch: a re-plan finds it where it belongs, or the name is taken.
|
|
246
|
+
local rid mine
|
|
247
|
+
if [ -s "$plan/run_id" ]; then rid="$(head -1 "$plan/run_id")"; else rid="$(plans_run_id "$plan")"; fi
|
|
248
|
+
[ -n "$rid" ] || die "'$plan' has no usable name: its run id is the directory name minus a leading 'forge-'" 2
|
|
249
|
+
git check-ref-format "refs/heads/forge/$rid-integration" >/dev/null 2>&1 \
|
|
250
|
+
|| die "'$rid' cannot be part of a branch name; use a plan directory name of plain letters, digits, '-' and '_'" 2
|
|
251
|
+
if mine="$(git -C "$repo" rev-parse --verify --quiet "refs/heads/forge/$rid-integration")"; then
|
|
252
|
+
if [ "$mine" != "$acc" ]; then
|
|
253
|
+
# Its own branch, still where this plan started and holding nothing of its work (a re-plan after the
|
|
254
|
+
# plan it follows moved, or after another --after), is moved to the new base. Any other branch of
|
|
255
|
+
# that name is somebody's work: it is never reset. `run` leaves that branch checked out in this
|
|
256
|
+
# plan's _integration worktree, and then tells you to re-plan the same predecessor once it moves:
|
|
257
|
+
# that checkout is moved with the branch. A different --after, or any other checkout, is refused.
|
|
258
|
+
local oldbase="" own=""
|
|
259
|
+
[ ! -s "$plan/integration.base" ] || oldbase="$(head -1 "$plan/integration.base")"
|
|
260
|
+
if [ "$merged" = 0 ] && [ -n "$oldbase" ] && [ "$mine" = "$oldbase" ]; then
|
|
261
|
+
if git -C "$repo" worktree list --porcelain 2>/dev/null | grep -qx "branch refs/heads/forge/$rid-integration"; then
|
|
262
|
+
if [ -n "$old" ] && { [ "$old" = "$prev" ] || { [ -d "$old" ] && [ "$(cd "$old" && pwd -P)" = "$prev_phys" ]; }; }; then
|
|
263
|
+
own="$(plans_chain_own_wt "$repo" "$plan" "$rid" "$oldbase")"
|
|
264
|
+
fi
|
|
265
|
+
if [ -z "$own" ]; then
|
|
266
|
+
die "forge/$rid-integration is checked out in a worktree: remove that worktree (git worktree remove) before planning from another base" 2
|
|
267
|
+
fi
|
|
268
|
+
CHAIN_WT="$own"
|
|
269
|
+
fi
|
|
270
|
+
CHAIN_MOVE=1
|
|
271
|
+
else
|
|
272
|
+
die "forge/$rid-integration already exists at $(plans_short "$mine"), not at $(plans_short "$acc") where plan $prid ended: pick another plan directory name or delete that branch" 2
|
|
273
|
+
fi
|
|
274
|
+
fi
|
|
275
|
+
fi
|
|
276
|
+
CHAIN_PREV="$prev"; CHAIN_BASE="$acc"
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
# Writes what plans_chain_early settled: after, integration.base, and the integration branch.
|
|
280
|
+
plans_chain_store() { # plans_chain_store <plan> <repo> <run id>
|
|
281
|
+
local plan="$1" repo="$2" rid="$3"
|
|
282
|
+
[ -n "${CHAIN_PREV:-}" ] || return 0
|
|
283
|
+
local oldbase=""
|
|
284
|
+
[ ! -s "$plan/integration.base" ] || oldbase="$(head -1 "$plan/integration.base")"
|
|
285
|
+
if [ "${CHAIN_MOVE:-0}" = 1 ]; then
|
|
286
|
+
if [ -n "${CHAIN_WT:-}" ]; then
|
|
287
|
+
# The branch is checked out there, so `branch -f` cannot move it. The worktree is this plan's,
|
|
288
|
+
# clean, and still at the old base: reset follows the new tip and keeps untracked setup files.
|
|
289
|
+
git -C "$CHAIN_WT" reset --hard "$CHAIN_BASE" >/dev/null 2>&1 \
|
|
290
|
+
|| die "could not move forge/$rid-integration to $(plans_short "$CHAIN_BASE")" 3
|
|
291
|
+
else
|
|
292
|
+
git -C "$repo" branch -f "forge/$rid-integration" "$CHAIN_BASE" >/dev/null 2>&1 \
|
|
293
|
+
|| die "could not move forge/$rid-integration to $(plans_short "$CHAIN_BASE")" 3
|
|
294
|
+
fi
|
|
295
|
+
# What an earlier run accepted was that branch at the old base: it is not a tip to hold the branch to.
|
|
296
|
+
if [ -n "$oldbase" ] && [ "$(head -1 "$plan/accepted.integration" 2>/dev/null)" = "$oldbase" ]; then
|
|
297
|
+
rm -f "$plan/accepted.integration"
|
|
298
|
+
fi
|
|
299
|
+
elif ! git -C "$repo" rev-parse --verify --quiet "refs/heads/forge/$rid-integration" >/dev/null; then
|
|
300
|
+
git -C "$repo" branch "forge/$rid-integration" "$CHAIN_BASE" >/dev/null 2>&1 \
|
|
301
|
+
|| die "could not create forge/$rid-integration at $(plans_short "$CHAIN_BASE")" 3
|
|
302
|
+
fi
|
|
303
|
+
printf '%s\n' "$CHAIN_PREV" > "$plan/after" || die "could not write $plan/after" 3
|
|
304
|
+
printf '%s\n' "$CHAIN_BASE" > "$plan/integration.base" || die "could not write $plan/integration.base" 3
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
# The table's line for a chained plan. Nothing without `after`.
|
|
308
|
+
plans_chain_line() { # plans_chain_line <plan>
|
|
309
|
+
[ -s "$1/after" ] || return 0
|
|
310
|
+
local prev prid base=""
|
|
311
|
+
prev="$(head -1 "$1/after")"
|
|
312
|
+
prid="$(head -1 "$prev/run_id" 2>/dev/null)"
|
|
313
|
+
[ -n "$prid" ] || prid="$(plans_run_id "$prev")"
|
|
314
|
+
[ ! -s "$1/integration.base" ] || base="$(head -1 "$1/integration.base")"
|
|
315
|
+
printf 'after: %s (%s)\n' "$prid" "${base:0:12}"
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
# `run` on a chained plan, before it creates or reuses the integration branch: while no task of
|
|
319
|
+
# this plan has merged, the plan it follows must still end where this plan started. A plan that
|
|
320
|
+
# moved on since (an adoption, a later run) would make this plan's tasks start from old code.
|
|
321
|
+
# An ancestor is enough: a plan split from a chained plan starts later than its predecessor ended.
|
|
322
|
+
plans_chain_run_check() { # plans_chain_run_check <plan> <repo>
|
|
323
|
+
local plan="$1" repo="$2" prev prid acc base m
|
|
324
|
+
[ -s "$plan/after" ] || return 0
|
|
325
|
+
for m in "$plan"/tasks/*/merged; do [ ! -e "$m" ] || return 0; done
|
|
326
|
+
prev="$(head -1 "$plan/after")"
|
|
327
|
+
if [ ! -s "$prev/accepted.integration" ]; then
|
|
328
|
+
note "plan --after: '$prev' has no accepted.integration to check this plan's base against; going on"
|
|
329
|
+
return 0
|
|
330
|
+
fi
|
|
331
|
+
prid="$(head -1 "$prev/run_id" 2>/dev/null)"; [ -n "$prid" ] || prid="$(plans_run_id "$prev")"
|
|
332
|
+
acc="$(head -1 "$prev/accepted.integration")"
|
|
333
|
+
base="$(head -1 "$plan/integration.base" 2>/dev/null)"
|
|
334
|
+
[ -n "$base" ] || die "plan $plan follows $prev but has no integration.base: run plan $plan --after $prev again" 3
|
|
335
|
+
git -C "$repo" merge-base --is-ancestor "$acc" "$base" >/dev/null 2>&1 \
|
|
336
|
+
|| die "plan $prid moved since this plan was made: run plan $plan --after $prev again" 3
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
# `integrate` on a chained plan: the run ids from the first plan to this one, from the after files.
|
|
340
|
+
plans_chain_names() { # plans_chain_names <plan>
|
|
341
|
+
local cur="$1" ids="" rid next n=0
|
|
342
|
+
while :; do
|
|
343
|
+
rid="$(head -1 "$cur/run_id" 2>/dev/null)"; [ -n "$rid" ] || rid="$(plans_run_id "$cur")"
|
|
344
|
+
ids="$rid${ids:+ → $ids}"
|
|
345
|
+
# A missing after file is the start of the chain. A zero-byte after cannot name its
|
|
346
|
+
# predecessor, so the list stops the same way a missing plan directory does.
|
|
347
|
+
[ -e "$cur/after" ] || { printf '%s\n' "$ids"; return 0; }
|
|
348
|
+
[ -s "$cur/after" ] || { printf '… → %s\n' "$ids"; return 0; }
|
|
349
|
+
next="$(head -1 "$cur/after")"
|
|
350
|
+
n=$((n + 1))
|
|
351
|
+
if [ "$n" -gt 64 ] || [ ! -r "$next/run_id" ]; then printf '… → %s\n' "$ids"; return 0; fi
|
|
352
|
+
cur="$next"
|
|
353
|
+
done
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
# --- groups across a split (#140) -----------------------------------------------------
|
|
357
|
+
# groups.tsv names tasks, so a split has to say where each group goes. A group whose members all
|
|
358
|
+
# move goes with them; one whose members all stay stays; one that would be cut in two is refused
|
|
359
|
+
# when it reviews its members together (review=group) and cut otherwise (review=task: each plan
|
|
360
|
+
# keeps the members it has). Both plans end with a groups.tsv that validates and a matching
|
|
361
|
+
# groups.frozen, or with neither.
|
|
362
|
+
# plans_groups_py <mode> <src plan> <dest plan> <moved ids, space separated>
|
|
363
|
+
# check exit 1 and say why when a review=group group would be cut in two
|
|
364
|
+
# moved <dest>/groups.tsv = the groups of <src>, cut to the moved ids; frozen
|
|
365
|
+
# staying <dest>/groups.tsv = the groups of <src>, cut to the tasks of <src> not moved; frozen
|
|
366
|
+
plans_groups_py() {
|
|
367
|
+
python3 - "$SKILL_DIR/scripts" "$@" <<'PY'
|
|
368
|
+
import os
|
|
369
|
+
import sys
|
|
370
|
+
from pathlib import Path
|
|
371
|
+
|
|
372
|
+
sys.path.insert(0, sys.argv[1])
|
|
373
|
+
import forge_groups as fg
|
|
374
|
+
|
|
375
|
+
mode, src, dest, moved = sys.argv[2], Path(sys.argv[3]), Path(sys.argv[4]), set(sys.argv[5].split())
|
|
376
|
+
try:
|
|
377
|
+
groups = fg.load(src)
|
|
378
|
+
if mode == 'check':
|
|
379
|
+
def member_merged(member):
|
|
380
|
+
# task_status: the merged marker wins, otherwise the status file's word.
|
|
381
|
+
task = src / 'tasks' / member
|
|
382
|
+
if (task / 'merged').is_file():
|
|
383
|
+
return True
|
|
384
|
+
try:
|
|
385
|
+
text = (task / 'status').read_text()
|
|
386
|
+
except OSError:
|
|
387
|
+
return False
|
|
388
|
+
return text.strip() == 'MERGED'
|
|
389
|
+
|
|
390
|
+
for g in groups:
|
|
391
|
+
hit = [m for m in g.members if m in moved]
|
|
392
|
+
if g.review == 'group' and hit and len(hit) != len(g.members):
|
|
393
|
+
left = [m for m in g.members if m not in moved]
|
|
394
|
+
merged_left = [m for m in left if member_merged(m)]
|
|
395
|
+
plural, who, verb = 's' if len(hit) > 1 else '', ', '.join(hit), 'are' if len(hit) > 1 else 'is'
|
|
396
|
+
if merged_left:
|
|
397
|
+
# split refuses a MERGED task, so "--tasks <every member>" is not a command the user can run.
|
|
398
|
+
parts = []
|
|
399
|
+
open_left = [m for m in left if m not in merged_left]
|
|
400
|
+
if open_left:
|
|
401
|
+
parts.append('%s, which would stay behind' % ', '.join(open_left))
|
|
402
|
+
parts.append('%s, which %s MERGED and cannot move' % (
|
|
403
|
+
', '.join(merged_left), 'are' if len(merged_left) > 1 else 'is'))
|
|
404
|
+
sys.stderr.write("task%s %s %s in review group %s with %s, so the group can be neither moved whole nor cut\n"
|
|
405
|
+
% (plural, who, verb, g.id, ', and '.join(parts)))
|
|
406
|
+
else:
|
|
407
|
+
sys.stderr.write("task%s %s %s in review group %s with %s, which would stay behind: move the whole group "
|
|
408
|
+
"(--tasks %s) or none of it\n"
|
|
409
|
+
% (plural, who, verb, g.id, ', '.join(left), ','.join(g.members)))
|
|
410
|
+
sys.exit(1)
|
|
411
|
+
sys.exit(0)
|
|
412
|
+
if mode == 'moved':
|
|
413
|
+
keep = moved
|
|
414
|
+
else:
|
|
415
|
+
keep = {m for m in fg._tasks(src)} - moved
|
|
416
|
+
cut = [g._replace(members=tuple(m for m in g.members if m in keep)) for g in groups]
|
|
417
|
+
cut = [g for g in cut if g.members]
|
|
418
|
+
if cut:
|
|
419
|
+
fg.write(dest, cut)
|
|
420
|
+
fg.freeze(dest)
|
|
421
|
+
else:
|
|
422
|
+
for name in ('groups.tsv', 'groups.frozen'):
|
|
423
|
+
try:
|
|
424
|
+
os.unlink(dest / name)
|
|
425
|
+
except FileNotFoundError:
|
|
426
|
+
pass
|
|
427
|
+
except fg.GroupError as error:
|
|
428
|
+
sys.stderr.write('%s\n' % ' '.join(str(error).split()))
|
|
429
|
+
sys.exit(1)
|
|
430
|
+
PY
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
# plans_groups_restore <plan> <backup dir>: the source's groups as they were before a split touched them.
|
|
434
|
+
plans_groups_restore() {
|
|
435
|
+
[ -d "$2" ] || return 0
|
|
436
|
+
local f
|
|
437
|
+
for f in groups.tsv groups.frozen; do
|
|
438
|
+
if [ -e "$2/$f" ]; then cp -p "$2/$f" "$1/$f"; else rm -f "$1/$f"; fi
|
|
439
|
+
done
|
|
440
|
+
rm -rf "$2"
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
# An IMPLEMENTED task (#140) is a group member whose own pipeline is done; only its group's review
|
|
444
|
+
# judges it, so neither retry nor accept can act on it. Exit 3.
|
|
445
|
+
plans_implemented_refuse() { # plans_implemented_refuse <plan> <id>
|
|
446
|
+
local gid; gid="$(forge_groups_id_of "$1" "$2")"
|
|
447
|
+
die "$2 is implemented and waits for group ${gid:-?}'s review" 3
|
|
448
|
+
}
|
|
134
449
|
|
|
135
450
|
# --- accept ---------------------------------------------------------------------
|
|
136
451
|
# A reviewer's FAIL is the QA gate; overriding it is the user's call and never forge's or
|
|
@@ -140,6 +455,7 @@ PLANS_OPTION_FILES="no_ripwire no_memory yolo_dwarf yolo_qa reviewer_session imp
|
|
|
140
455
|
plans_why_not() { # plans_why_not <plan> <id> <status>: exit 3 with advice for a status accept cannot take
|
|
141
456
|
local plan="$1" id="$2" st="$3"
|
|
142
457
|
case "$st" in
|
|
458
|
+
IMPLEMENTED) plans_implemented_refuse "$plan" "$id" ;;
|
|
143
459
|
MERGED) die "task '$id' is already merged — nothing to accept" 3 ;;
|
|
144
460
|
PASS) die "task '$id' already passed review; 'forge-parallel.sh run $plan' merges it — nothing to accept" 3 ;;
|
|
145
461
|
INVALIDATED) die "task '$id' is INVALIDATED: its work or the integration branch changed after the review, so the review no longer describes it. Use 'forge-parallel.sh retry $plan $id' for a fresh review" 3 ;;
|
|
@@ -553,7 +869,7 @@ Retry or accept them (or split them off into their own plan) first." 3
|
|
|
553
869
|
done
|
|
554
870
|
all=1; for p in "${SRC[@]}"; do [ -f "$p/pre_review_tests" ] || all=0; done
|
|
555
871
|
[ "$all" = 1 ] && : > "$NEW/pre_review_tests"
|
|
556
|
-
for f in qa_threshold timeout verify_retries verify_parallel pre_review_parallel fast; do
|
|
872
|
+
for f in qa_threshold timeout verify_retries verify_parallel pre_review_parallel fast retry_per_model; do
|
|
557
873
|
same=1
|
|
558
874
|
for p in "${SRC[@]}"; do
|
|
559
875
|
if [ ! -f "$p/$f" ] || ! cmp -s "$p/$f" "${SRC[0]}/$f"; then same=0; fi
|
|
@@ -707,6 +1023,12 @@ except Exception:
|
|
|
707
1023
|
[ "$dst" = MERGED ] || die "task '$id' depends on '$dep', which is not merged (status $dst) and is not being moved; move '$dep' too or finish it first" 3
|
|
708
1024
|
done
|
|
709
1025
|
done
|
|
1026
|
+
# A review group is reviewed as one: it moves whole or stays whole (a review=task group is cut).
|
|
1027
|
+
if [ -f "$PLAN/groups.tsv" ]; then
|
|
1028
|
+
local groups_err
|
|
1029
|
+
groups_err="$(plans_groups_py check "$PLAN" "$PLAN" "$PICKED" 2>&1)" \
|
|
1030
|
+
|| die "split: ${groups_err:-groups.tsv could not be read}" 3
|
|
1031
|
+
fi
|
|
710
1032
|
local STAYS="" # built in a loop: bash 3.2 cannot parse a `case` inside $( )
|
|
711
1033
|
for id in $(all_ids "$T"); do
|
|
712
1034
|
case "$SEL" in *" $id "*) ;; *) STAYS="$STAYS $id" ;; esac
|
|
@@ -798,6 +1120,10 @@ except Exception:
|
|
|
798
1120
|
for f in $PLANS_OPTION_FILES; do
|
|
799
1121
|
[ ! -e "$PLAN/$f" ] || cp -p "$PLAN/$f" "$NEW/$f" || ok=0
|
|
800
1122
|
done
|
|
1123
|
+
# The copy above brought groups.tsv whole; the new plan keeps the groups of the tasks it got.
|
|
1124
|
+
# tasks.tsv is written already: the frozen fingerprint is of its rows.
|
|
1125
|
+
[ ! -e "$PLAN/groups.tsv" ] || plans_groups_py moved "$PLAN" "$NEW" "$PICKED" >/dev/null 2>&1 || ok=0
|
|
1126
|
+
[ -e "$PLAN/groups.tsv" ] || rm -f "$NEW/groups.frozen"
|
|
801
1127
|
# The plan's verification lanes travel with it, like its --verify.
|
|
802
1128
|
[ ! -d "$PLAN/verify.d" ] || cp -Rp "$PLAN/verify.d" "$NEW/verify.d" || ok=0
|
|
803
1129
|
for id in $(all_ids "$T"); do
|
|
@@ -814,11 +1140,21 @@ except Exception:
|
|
|
814
1140
|
# the new plan is complete, and undoing it would leave the source without its rows.
|
|
815
1141
|
trap - INT TERM
|
|
816
1142
|
local srctmp="$PLAN/.tasks.tsv.split" marker="$PLAN/split-$(basename "$NEW").txt"
|
|
1143
|
+
# The source's groups lose the moved tasks, and are frozen again, before its tasks.tsv does: the
|
|
1144
|
+
# members that stay have the same rows in both. A failure puts them back.
|
|
1145
|
+
local gbak="$PLAN/.groups.split.bak"
|
|
1146
|
+
if [ -e "$PLAN/groups.tsv" ]; then
|
|
1147
|
+
rm -rf "$gbak"; mkdir "$gbak" && cp -p "$PLAN/groups.tsv" "$gbak/groups.tsv" \
|
|
1148
|
+
&& { [ ! -e "$PLAN/groups.frozen" ] || cp -p "$PLAN/groups.frozen" "$gbak/groups.frozen"; } \
|
|
1149
|
+
&& plans_groups_py staying "$PLAN" "$PLAN" "$PICKED" >/dev/null 2>&1 \
|
|
1150
|
+
|| { plans_groups_restore "$PLAN" "$gbak"; plans_undo; trap - INT TERM; die "could not update the groups of '$PLAN'; nothing was moved" 3; }
|
|
1151
|
+
fi
|
|
817
1152
|
if ! awk -F'\t' -v ids="$SEL" '/^#/ || !NF {print; next} index(ids, " " $1 " ") {next} {print}' "$T" > "$srctmp" \
|
|
818
1153
|
|| ! mv "$srctmp" "$T"; then
|
|
819
|
-
rm -f "$srctmp"; plans_undo; trap - INT TERM
|
|
1154
|
+
rm -f "$srctmp"; plans_groups_restore "$PLAN" "$gbak"; plans_undo; trap - INT TERM
|
|
820
1155
|
die "could not update '$T'; nothing was moved" 3
|
|
821
1156
|
fi
|
|
1157
|
+
rm -rf "$gbak"
|
|
822
1158
|
{
|
|
823
1159
|
echo "moved to $NEW (run forge/$NEWRID) on $(date '+%Y-%m-%dT%H:%M:%S%z')"
|
|
824
1160
|
for id in $PICKED; do
|