@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.
Files changed (110) hide show
  1. package/CHANGELOG.md +57 -0
  2. package/README.md +1 -0
  3. package/SKILL.md +32 -5
  4. package/VERSION +1 -1
  5. package/docs/artifacts.md +33 -1
  6. package/docs/commands.md +147 -16
  7. package/docs/dataset.md +5 -0
  8. package/docs/decomposed-runs.md +122 -1
  9. package/docs/development.md +2 -1
  10. package/docs/forge-ui.md +98 -8
  11. package/docs/memory.md +27 -4
  12. package/docs/models.md +8 -0
  13. package/docs/reviews.md +122 -0
  14. package/docs/safety.md +8 -0
  15. package/forge +44 -4
  16. package/package.json +2 -1
  17. package/references/dataset.md +39 -1
  18. package/references/decompose.md +737 -16
  19. package/references/harnesses.md +18 -3
  20. package/references/planning.md +43 -14
  21. package/references/solo.md +2 -1
  22. package/references/ui.md +56 -6
  23. package/registry.tsv +8 -3
  24. package/scripts/forge-artifact.sh +14 -0
  25. package/scripts/forge-brief.py +217 -0
  26. package/scripts/forge-compare.py +13 -2
  27. package/scripts/forge-config.py +176 -9
  28. package/scripts/forge-contract.py +246 -28
  29. package/scripts/forge-control.py +200 -15
  30. package/scripts/forge-dispatch.sh +48 -15
  31. package/scripts/forge-du.py +167 -0
  32. package/scripts/forge-group.py +496 -0
  33. package/scripts/forge-groups.py +89 -0
  34. package/scripts/forge-handoff.py +1128 -0
  35. package/scripts/forge-lib-adopt.sh +1 -0
  36. package/scripts/forge-lib-group.sh +641 -0
  37. package/scripts/forge-lib-plans.sh +343 -4
  38. package/scripts/forge-lib-review.sh +29 -1
  39. package/scripts/forge-lib-task.sh +197 -4
  40. package/scripts/forge-memory.sh +245 -3
  41. package/scripts/forge-metrics.sh +7 -3
  42. package/scripts/forge-parallel-options.sh +4 -0
  43. package/scripts/forge-parallel.sh +1216 -41
  44. package/scripts/forge-planner.py +104 -8
  45. package/scripts/forge-prompt.py +120 -0
  46. package/scripts/forge-retro.py +115 -0
  47. package/scripts/forge-route.py +190 -12
  48. package/scripts/forge-runs-compact.py +443 -0
  49. package/scripts/forge-runs-rm.py +2 -0
  50. package/scripts/forge-runs.py +27 -8
  51. package/scripts/forge-schedule.py +633 -49
  52. package/scripts/forge-shadow.py +7 -1
  53. package/scripts/forge-solo.sh +4 -0
  54. package/scripts/forge-summarize.py +698 -0
  55. package/scripts/forge-ui-options.sh +10 -0
  56. package/scripts/forge-worktrees.py +243 -0
  57. package/scripts/forge_brief/__init__.py +831 -0
  58. package/scripts/forge_brief/answers.py +506 -0
  59. package/scripts/forge_brief/proposals.py +1630 -0
  60. package/scripts/forge_dataset/__init__.py +10 -0
  61. package/scripts/forge_dataset/efforts.py +4 -3
  62. package/scripts/forge_dataset/export.py +36 -10
  63. package/scripts/forge_dataset/facts.py +8 -4
  64. package/scripts/forge_dataset/forecast.py +8 -18
  65. package/scripts/forge_dataset/harvest.py +241 -12
  66. package/scripts/forge_dataset/history.py +13 -6
  67. package/scripts/forge_dataset/importer.py +65 -1
  68. package/scripts/forge_dataset/names.py +66 -0
  69. package/scripts/forge_dataset/reviewers.py +5 -2
  70. package/scripts/forge_dataset/risk.py +6 -3
  71. package/scripts/forge_dataset/routing.py +6 -1
  72. package/scripts/forge_decide/__init__.py +11 -1
  73. package/scripts/forge_groups/__init__.py +308 -0
  74. package/scripts/forge_groups/attribute.py +289 -0
  75. package/scripts/forge_groups/review.py +286 -0
  76. package/scripts/forge_locations.py +366 -0
  77. package/scripts/forge_owner.py +152 -0
  78. package/scripts/forge_registry.py +19 -0
  79. package/scripts/forge_retro/__init__.py +417 -0
  80. package/scripts/forge_retro/issues.py +1193 -0
  81. package/scripts/forge_retro/report.py +671 -0
  82. package/scripts/forge_side/__init__.py +482 -0
  83. package/scripts/forge_storage.py +515 -0
  84. package/ui/README.md +68 -8
  85. package/ui/docs/api.md +375 -31
  86. package/ui/forge_ui/control.py +451 -11
  87. package/ui/forge_ui/executions.py +8 -1
  88. package/ui/forge_ui/export.py +53 -7
  89. package/ui/forge_ui/groups.py +264 -0
  90. package/ui/forge_ui/links.py +337 -0
  91. package/ui/forge_ui/models.py +125 -10
  92. package/ui/forge_ui/projects.py +4 -1
  93. package/ui/forge_ui/reader.py +919 -45
  94. package/ui/forge_ui/server.py +4 -0
  95. package/ui/forge_ui/static/app.js +173 -11
  96. package/ui/forge_ui/static/briefview.js +605 -0
  97. package/ui/forge_ui/static/checksview.js +6 -2
  98. package/ui/forge_ui/static/controls.js +5 -0
  99. package/ui/forge_ui/static/diffview.js +86 -1
  100. package/ui/forge_ui/static/groupsview.js +332 -0
  101. package/ui/forge_ui/static/index.html +4 -0
  102. package/ui/forge_ui/static/panel.js +394 -8
  103. package/ui/forge_ui/static/projectsview.js +189 -10
  104. package/ui/forge_ui/static/runmodel.js +27 -4
  105. package/ui/forge_ui/static/storageview.js +352 -0
  106. package/ui/forge_ui/static/style.css +176 -6
  107. package/ui/forge_ui/static/worktreesview.js +235 -14
  108. package/ui/forge_ui/storage.py +150 -0
  109. package/ui/forge_ui/transcripts.py +35 -10
  110. package/ui/forge_ui/worktrees.py +154 -13
@@ -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"
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 ;;
@@ -267,6 +583,8 @@ do_accept() {
267
583
  echo "attempt=$attempt"
268
584
  echo "reviewed_commit=$sha"
269
585
  [ "${gdec:-}" != fail ] || echo "gate=fail"
586
+ # Through forge control on a live run: who asked (ui or cli), as control.log has it (#138).
587
+ [ -z "${FORGE_ACCEPT_ACTOR:-}" ] || echo "actor=$FORGE_ACCEPT_ACTOR"
270
588
  } > "$tdir/accepted.by"
271
589
  echo PASS > "$tdir/status"
272
590
 
@@ -283,7 +601,8 @@ do_accept() {
283
601
  write_results "$PLAN"
284
602
  echo "$id accepted by a human and merged"
285
603
  echo "known issues recorded in $ki"
286
- if [ "$(awk -F'\t' '$2!="MERGED" {n++} END {print n+0}' "$PLAN/results.tsv")" -gt 0 ]; then
604
+ # A live run starts the tasks that waited on it by itself.
605
+ if [ -z "${FORGE_ACCEPT_LIVE:-}" ] && [ "$(awk -F'\t' '$2!="MERGED" {n++} END {print n+0}' "$PLAN/results.tsv")" -gt 0 ]; then
287
606
  echo "tasks that were waiting on it are unchanged; continue with: forge-parallel.sh run $PLAN"
288
607
  fi
289
608
  return 0
@@ -550,7 +869,7 @@ Retry or accept them (or split them off into their own plan) first." 3
550
869
  done
551
870
  all=1; for p in "${SRC[@]}"; do [ -f "$p/pre_review_tests" ] || all=0; done
552
871
  [ "$all" = 1 ] && : > "$NEW/pre_review_tests"
553
- 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
554
873
  same=1
555
874
  for p in "${SRC[@]}"; do
556
875
  if [ ! -f "$p/$f" ] || ! cmp -s "$p/$f" "${SRC[0]}/$f"; then same=0; fi
@@ -704,6 +1023,12 @@ except Exception:
704
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
705
1024
  done
706
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
707
1032
  local STAYS="" # built in a loop: bash 3.2 cannot parse a `case` inside $( )
708
1033
  for id in $(all_ids "$T"); do
709
1034
  case "$SEL" in *" $id "*) ;; *) STAYS="$STAYS $id" ;; esac
@@ -795,6 +1120,10 @@ except Exception:
795
1120
  for f in $PLANS_OPTION_FILES; do
796
1121
  [ ! -e "$PLAN/$f" ] || cp -p "$PLAN/$f" "$NEW/$f" || ok=0
797
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"
798
1127
  # The plan's verification lanes travel with it, like its --verify.
799
1128
  [ ! -d "$PLAN/verify.d" ] || cp -Rp "$PLAN/verify.d" "$NEW/verify.d" || ok=0
800
1129
  for id in $(all_ids "$T"); do
@@ -811,11 +1140,21 @@ except Exception:
811
1140
  # the new plan is complete, and undoing it would leave the source without its rows.
812
1141
  trap - INT TERM
813
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
814
1152
  if ! awk -F'\t' -v ids="$SEL" '/^#/ || !NF {print; next} index(ids, " " $1 " ") {next} {print}' "$T" > "$srctmp" \
815
1153
  || ! mv "$srctmp" "$T"; then
816
- rm -f "$srctmp"; plans_undo; trap - INT TERM
1154
+ rm -f "$srctmp"; plans_groups_restore "$PLAN" "$gbak"; plans_undo; trap - INT TERM
817
1155
  die "could not update '$T'; nothing was moved" 3
818
1156
  fi
1157
+ rm -rf "$gbak"
819
1158
  {
820
1159
  echo "moved to $NEW (run forge/$NEWRID) on $(date '+%Y-%m-%dT%H:%M:%S%z')"
821
1160
  for id in $PICKED; do
@@ -26,7 +26,8 @@
26
26
  # qa.out, verdict (PASS | FAIL | UNKNOWN | INVALIDATED | ACCEPTED; absent when nothing was
27
27
  # judged), qa.gate and known_issues.md (with a threshold), qa.infra (infrastructure stop),
28
28
  # review.meta, context.md, notes.md, tasks.summary, combined.diff (when inlined),
29
- # source/review.fingerprint and review-<pid>/ (the disposable checkout the reviewer ran in).
29
+ # source/review.fingerprint and review-<pid>/ (the disposable checkout the reviewer ran in, removed
30
+ # when the review ends; FORGE_KEEP_SNAPSHOTS=1 keeps it).
30
31
  # `review` also keeps $PLAN/final-review (a link to the newest directory) and
31
32
  # $PLAN/final-review.verdict (a copy of its verdict).
32
33
  #
@@ -357,7 +358,19 @@ PY
357
358
  # src is a repository or worktree that contains both revisions; it is also the checkout
358
359
  # whose fingerprint must not change while the reviewer runs. Never uses `die`/`exit`:
359
360
  # it is called from inside do_integrate.
361
+ # The review snapshot goes once the review is over, on every return (#139). A signal that ends the
362
+ # process first leaves it, and the next final review of the plan removes it: they hold the plan's
363
+ # lock, so one runs at a time and any snapshot already there is an interrupted one's.
360
364
  final_review() {
365
+ local final_rc
366
+ FINAL_REVIEW_SNAPSHOT=""
367
+ final_review_body "$@"; final_rc=$?
368
+ forge_drop_snapshot "$FINAL_REVIEW_SNAPSHOT"
369
+ FINAL_REVIEW_SNAPSHOT=""
370
+ return "$final_rc"
371
+ }
372
+
373
+ final_review_body() {
361
374
  local plan="$1" base="$2" tip="$3" src="$4" out="$5" spec="$6" yolo="${7:-}"
362
375
  local review n rc verdict thr gate_line gate_forced source_fp review_fp vdir tflag="" inline=1 diff_n ft
363
376
  local plan_real prev="" prev_rel=none prev_tip="" since=none integration="" prev_note=""
@@ -391,8 +404,13 @@ final_review() {
391
404
 
392
405
  # `forge_review_snapshot` writes review.base beside the snapshot, so it gets a directory
393
406
  # of its own under the artifact dir.
407
+ local stale
408
+ for stale in "$out"/review-* "$plan"/final-review*/review-* "$plan"/integrate-*/final-review/review-*; do
409
+ [ -d "$stale/.git" ] && forge_drop_snapshot "$stale"
410
+ done
394
411
  review="$out/review-$$"; n=0
395
412
  while [ -e "$review" ]; do n=$((n+1)); review="$out/review-$$-$n"; done
413
+ FINAL_REVIEW_SNAPSHOT="$review"
396
414
  forge_review_snapshot "$src" "$base" "$tip" "$review" > "$out/snapshot.log" 2>&1 ||
397
415
  { note "final review: cannot build the review snapshot (see $out/snapshot.log)"; return 3; }
398
416
  forge_review_deps "$src" "$review" "$out/review.deps"
@@ -482,6 +500,9 @@ final_review() {
482
500
  echo " git diff HEAD~1 HEAD -- . ':(exclude).forge'"
483
501
  echo "(and 'git diff --stat HEAD~1 HEAD' for the overview)."
484
502
  fi
503
+ # Last. A shadow of a task review copies qa.input itself; this prompt is the final
504
+ # review's, and nothing copies it onward. Off prints nothing.
505
+ forge_retro_prompt "$plan" review
485
506
  } > "$out/qa.input"
486
507
 
487
508
  [ -s "$plan/timeout" ] && tflag="--timeout $(cat "$plan/timeout")"
@@ -516,12 +537,19 @@ final_review() {
516
537
  fi
517
538
  rs_mode=fresh
518
539
  mv "$out/qa.out" "$out/qa.continue.out" 2>/dev/null || true
540
+ # The fresh dispatch deletes qa.last and qa.log as it starts. Record the continuation
541
+ # first; a failure to record does not change rc, which the fresh dispatch sets next.
542
+ forge_retro_record "$plan" qa "$out"
519
543
  FORGE_CAPABILITY_CACHE="${FORGE_CAPABILITY_CACHE:-$plan/capabilities}" \
520
544
  "${qa_cmd[@]}" > "$out/qa.out" 2>&1
521
545
  rc=$?
522
546
  fi
523
547
  [ ! -f "$plan/reviewer_session" ] || { echo "session=$rs_mode"; echo "session_reason=$rs_reason"; } >> "$out/review.meta"
524
548
  if [ "${FORGE_OUTPUT:-summary}" = full ]; then cat "$out/qa.out"; fi
549
+ # The dispatch role is qa, so the notes are in qa.last. No task: this is the whole run.
550
+ # Record and the regenerated report never change rc; the case below still decides it.
551
+ forge_retro_record "$plan" qa "$out"
552
+ forge_retro_report "$plan"
525
553
  case "$rc" in
526
554
  0) ;;
527
555
  8) note "final review: the reviewer hit an infrastructure failure; nothing was judged"