@giamme/forge 0.22.0 → 0.23.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 (153) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/README.md +19 -12
  3. package/SKILL.md +137 -216
  4. package/VERSION +1 -1
  5. package/docs/README.md +2 -3
  6. package/docs/add-ons.md +5 -3
  7. package/docs/artifacts.md +17 -2
  8. package/docs/commands.md +85 -63
  9. package/docs/decomposed-runs.md +195 -21
  10. package/docs/development.md +11 -9
  11. package/docs/forge-ui.md +33 -4
  12. package/docs/install.md +37 -5
  13. package/docs/memory.md +6 -1
  14. package/docs/models.md +36 -10
  15. package/docs/reviews.md +44 -25
  16. package/docs/safety.md +27 -2
  17. package/docs/troubleshooting.md +7 -10
  18. package/forge +25 -4
  19. package/package.json +2 -1
  20. package/references/dataset.md +10 -9
  21. package/references/decompose-integration.md +337 -0
  22. package/references/decompose-opt-in.md +527 -0
  23. package/references/decompose-recovery.md +569 -0
  24. package/references/decompose-review.md +256 -0
  25. package/references/decompose.md +99 -1606
  26. package/references/findings.md +68 -0
  27. package/references/harnesses.md +7 -12
  28. package/references/memory.md +13 -2
  29. package/references/planning.md +48 -18
  30. package/references/ripwire.md +38 -13
  31. package/references/runtime.md +22 -33
  32. package/references/setup.md +90 -0
  33. package/references/solo.md +13 -42
  34. package/references/ui.md +12 -5
  35. package/registry.tsv +40 -22
  36. package/scripts/forge-artifact.sh +143 -12
  37. package/scripts/forge-compare.py +5 -15
  38. package/scripts/forge-config.py +14 -1
  39. package/scripts/forge-contract.py +216 -53
  40. package/scripts/forge-control.py +777 -54
  41. package/scripts/forge-dispatch.sh +95 -12
  42. package/scripts/forge-du.py +13 -3
  43. package/scripts/forge-handoff.py +221 -39
  44. package/scripts/forge-install-ripwire.sh +100 -24
  45. package/scripts/forge-install.sh +18 -32
  46. package/scripts/forge-issues.py +6 -4
  47. package/scripts/forge-jev-options.sh +3 -5
  48. package/scripts/forge-lib-adopt.sh +169 -5
  49. package/scripts/forge-lib-attribute.sh +10 -3
  50. package/scripts/forge-lib-decompose.sh +454 -0
  51. package/scripts/forge-lib-env.sh +21 -0
  52. package/scripts/forge-lib-group.sh +4 -1
  53. package/scripts/forge-lib-plans.sh +30 -18
  54. package/scripts/forge-lib-review.sh +28 -8
  55. package/scripts/forge-lib-task.sh +225 -56
  56. package/scripts/forge-lib-verify.sh +59 -10
  57. package/scripts/forge-memory.sh +81 -4
  58. package/scripts/forge-metrics.sh +4 -2
  59. package/scripts/forge-parallel-options.sh +23 -4
  60. package/scripts/forge-parallel.sh +447 -175
  61. package/scripts/forge-plan-check.py +71 -8
  62. package/scripts/forge-planner.py +303 -17
  63. package/scripts/forge-pr.py +9 -1
  64. package/scripts/forge-prompt.py +2 -2
  65. package/scripts/forge-review-links.py +248 -0
  66. package/scripts/forge-ripwire.py +234 -16
  67. package/scripts/forge-route.py +19 -27
  68. package/scripts/forge-runs-rm.py +92 -21
  69. package/scripts/forge-runs.py +46 -5
  70. package/scripts/forge-runtime.py +37 -12
  71. package/scripts/forge-schedule.py +124 -33
  72. package/scripts/forge-setup-stale.py +236 -0
  73. package/scripts/forge-setup.py +804 -0
  74. package/scripts/forge-shadow.py +2 -20
  75. package/scripts/forge-solo-lock.py +46 -0
  76. package/scripts/forge-solo.sh +33 -56
  77. package/scripts/forge-sweep.py +2 -1
  78. package/scripts/forge-ui.py +8 -1
  79. package/scripts/forge-update.sh +2 -2
  80. package/scripts/forge-verify.py +16 -1
  81. package/scripts/forge-version.py +13 -1
  82. package/scripts/forge-watch.py +7 -2
  83. package/scripts/forge_dataset/__init__.py +1 -1
  84. package/scripts/forge_dataset/capture.py +0 -34
  85. package/scripts/forge_dataset/checks.py +0 -1
  86. package/scripts/forge_dataset/cli.py +5 -1
  87. package/scripts/forge_dataset/export.py +28 -6
  88. package/scripts/forge_dataset/facts.py +1 -2
  89. package/scripts/forge_dataset/forecast.py +1 -1
  90. package/scripts/forge_dataset/harvest.py +107 -7
  91. package/scripts/forge_dataset/importer.py +3 -2
  92. package/scripts/forge_dataset/pairs.py +3 -3
  93. package/scripts/forge_dataset/reviewers.py +4 -3
  94. package/scripts/forge_dataset/routing.py +6 -3
  95. package/scripts/forge_dataset/tiers.py +1 -1
  96. package/scripts/forge_decide/__init__.py +1 -1
  97. package/scripts/forge_decide/profiles.py +11 -14
  98. package/scripts/forge_decompose.py +987 -0
  99. package/scripts/forge_groups/review.py +6 -1
  100. package/scripts/forge_jev/__init__.py +1 -1
  101. package/scripts/forge_jev/cli.py +10 -1
  102. package/scripts/forge_jev/gates.py +10 -1
  103. package/scripts/forge_jev/verify.py +10 -2
  104. package/scripts/forge_legacy.py +86 -0
  105. package/scripts/forge_memory_home.py +57 -0
  106. package/scripts/forge_models.py +151 -0
  107. package/scripts/forge_prefs.py +138 -0
  108. package/scripts/forge_side/__init__.py +10 -0
  109. package/scripts/forge_storage.py +28 -15
  110. package/ui/README.md +22 -10
  111. package/ui/docs/api.md +121 -99
  112. package/ui/forge_ui/control.py +46 -14
  113. package/ui/forge_ui/export.py +0 -10
  114. package/ui/forge_ui/models.py +15 -2
  115. package/ui/forge_ui/projects.py +4 -1
  116. package/ui/forge_ui/reader.py +456 -59
  117. package/ui/forge_ui/server.py +0 -10
  118. package/ui/forge_ui/static/app.js +28 -9
  119. package/ui/forge_ui/static/checksview.js +12 -3
  120. package/ui/forge_ui/static/controls.js +147 -11
  121. package/ui/forge_ui/static/convo.js +5 -2
  122. package/ui/forge_ui/static/diffview.js +4 -5
  123. package/ui/forge_ui/static/panel.js +180 -77
  124. package/ui/forge_ui/static/projectsview.js +16 -2
  125. package/ui/forge_ui/static/runmodel.js +18 -4
  126. package/ui/forge_ui/static/scene3d.js +29 -29
  127. package/ui/forge_ui/static/settings.js +1 -1
  128. package/ui/forge_ui/static/storageview.js +2 -2
  129. package/ui/forge_ui/static/style.css +23 -6
  130. package/ui/forge_ui/static/worktreesview.js +8 -4
  131. package/ui/forge_ui/transcripts.py +6 -0
  132. package/ui/forge_ui/worktrees.py +13 -1
  133. package/docs/fractal.md +0 -181
  134. package/references/fractal-dashboard.md +0 -21
  135. package/references/fractal.md +0 -307
  136. package/scripts/forge-fractal-dispatch.sh +0 -4
  137. package/scripts/forge-fractal-options.sh +0 -54
  138. package/scripts/forge-fractal.py +0 -6
  139. package/scripts/forge-install-fractal.sh +0 -4
  140. package/scripts/forge_fractal/__init__.py +0 -88
  141. package/scripts/forge_fractal/bridge.py +0 -46
  142. package/scripts/forge_fractal/cli.py +0 -224
  143. package/scripts/forge_fractal/dashboard.css +0 -138
  144. package/scripts/forge_fractal/dashboard.html +0 -41
  145. package/scripts/forge_fractal/dashboard.js +0 -687
  146. package/scripts/forge_fractal/decomposition.py +0 -262
  147. package/scripts/forge_fractal/execution.py +0 -659
  148. package/scripts/forge_fractal/inspection.py +0 -261
  149. package/scripts/forge_fractal/install.py +0 -158
  150. package/scripts/forge_fractal/invocation.py +0 -95
  151. package/scripts/forge_fractal/pipeline.py +0 -125
  152. package/scripts/forge_fractal/selection.py +0 -180
  153. package/ui/forge_ui/fractal.py +0 -582
@@ -0,0 +1,454 @@
1
+ #!/usr/bin/env bash
2
+ # Recursive decomposition for forge-parallel.sh (#153): a task split into subtasks, and a goal
3
+ # split into plans.
4
+ #
5
+ # Sourced by forge-parallel.sh, which provides die/note/field/all_ids/task_status, compute_waves,
6
+ # carry_findings, forge_dataset_event, forge_fast_tier, forge_pools_file, DISPATCH and SELF.
7
+ # Functions only; nothing runs at source time. The node model, the limits and the validation of a
8
+ # split are scripts/forge_decompose.py; the planner's side is scripts/forge-planner.py.
9
+ #
10
+ # plan <plan> --split-depth N --split-children N --split-nodes N the limits, frozen by the first run
11
+ # run <plan> --auto-split [--split-planner SPEC] | --no-auto-split a task that stops on `split` is
12
+ # split by the planner, within the limits
13
+ # retry <plan> <task> --decide split[=fresh] [--subtasks FILE | --planner SPEC] --reason "..." --approved
14
+ # next <plan> [<new-plan-dir>] [--planner SPEC] [plan flags...] plan the next stage of a larger goal
15
+ #
16
+ # A split task's subtasks are a plan of their own, <plan>/tasks/<id>/sub. The task's next entry runs
17
+ # that plan instead of an implementer (run_split_task), merges its integration branch into the task's
18
+ # branch, and the task is then snapshotted and reviewed as any attempt is: on its cumulative diff.
19
+
20
+ forge_decompose_py() { python3 "$SKILL_DIR/scripts/forge_decompose.py" "$@"; }
21
+
22
+ forge_is_split() { # forge_is_split <plan> <id>: the task has a sub-plan
23
+ [ -f "$1/tasks/$2/sub/tasks.tsv" ]
24
+ }
25
+
26
+ # The task's next entry runs its sub-plan: it has one, and its work is not on the task's branch yet.
27
+ forge_split_open() { # forge_split_open <plan> <id>
28
+ [ -f "$1/tasks/$2/sub/tasks.tsv" ] && [ ! -e "$1/tasks/$2/sub.merged" ]
29
+ }
30
+
31
+ forge_is_sub_plan() { # forge_is_sub_plan <plan>
32
+ [ -f "$1/parent.json" ] || return 1
33
+ case "$1" in */tasks/*/sub) return 0 ;; esac
34
+ return 1
35
+ }
36
+
37
+ forge_decide_is_split() { # forge_decide_is_split <--decide value>
38
+ case "${1:-}" in split|split=keep|split=fresh) return 0 ;; esac
39
+ return 1
40
+ }
41
+
42
+ # --- plan ------------------------------------------------------------------------------------
43
+
44
+ # The limits a plan was given, set before anything else of the plan is written: a value out of
45
+ # range, or a change after the first run froze them, refuses the whole `plan` call (exit 2).
46
+ forge_decompose_limits() { # forge_decompose_limits <plan> <depth|""> <children|""> <nodes|"">
47
+ local out args=()
48
+ [ -z "$2" ] || args+=(--depth "$2")
49
+ [ -z "$3" ] || args+=(--children "$3")
50
+ [ -z "$4" ] || args+=(--nodes "$4")
51
+ [ "${#args[@]}" -gt 0 ] || return 0
52
+ out="$(forge_decompose_py limits "$1" "${args[@]}" 2>&1 >/dev/null)" || die "${out#refused: }" 2
53
+ }
54
+
55
+ # One sub-plan made ready to run: its waves, and the tier each subtask's model runs in (what `plan`
56
+ # records for a row it routes, so an escalation of a subtask knows where it starts).
57
+ forge_sub_prepare() { # forge_sub_prepare <sub-plan>
58
+ local sub="$1" id
59
+ ( compute_waves "$sub" ) || return 1
60
+ for id in $(all_ids "$sub/tasks.tsv"); do
61
+ python3 "$SKILL_DIR/scripts/forge-route.py" assign --plan "$sub" --task "$id" \
62
+ --tier "$(field "$sub/tasks.tsv" "$id" difficulty)" --epsilon 0 \
63
+ --default "$(field "$sub/tasks.tsv" "$id" dwarf)" --pools "$(forge_pools_file "$sub")" >/dev/null 2>&1 || true
64
+ done
65
+ forge_decompose_snapshot "$sub"
66
+ }
67
+
68
+ # The dataset's record of a plan (a sub-plan is never made by `plan`, which records the others), and
69
+ # again of the plan a task was just split in: the decision is part of what was planned.
70
+ forge_decompose_snapshot() { # forge_decompose_snapshot <plan>
71
+ forge_dataset_off && return 0
72
+ python3 "$SKILL_DIR/scripts/forge-dataset.py" plan "$1" >/dev/null 2>&1 || true
73
+ }
74
+
75
+ forge_sub_prepare_all() { # forge_sub_prepare_all <plan>: every sub-plan under it that has no waves yet
76
+ local sub rc=0
77
+ while IFS= read -r sub; do
78
+ [ -n "$sub" ] || continue
79
+ [ -s "$sub/waves.tsv" ] && continue
80
+ forge_sub_prepare "$sub" || rc=1
81
+ done <<FORGE_SUBS
82
+ $(forge_decompose_py subs "$1" 2>/dev/null)
83
+ FORGE_SUBS
84
+ return $rc
85
+ }
86
+
87
+ # After `plan` routed the table: the planner's proposed splits become sub-plans within the limits,
88
+ # and every other task is recorded as kept whole. DECOMPOSE_LINES is what happened, for the table.
89
+ forge_decompose_settle() { # forge_decompose_settle <plan>
90
+ local by=default
91
+ DECOMPOSE_LINES=""
92
+ [ ! -s "$1/planner.prompt" ] || by=planner
93
+ DECOMPOSE_LINES="$(forge_decompose_py settle "$1" --by "$by" 2>/dev/null)" || true
94
+ forge_sub_prepare_all "$1" || note "a sub-plan's waves could not be computed; forge-parallel.sh run reports it"
95
+ }
96
+
97
+ # Under the task table: the limits (always: they are what the user approves with the plan), what the
98
+ # planner split, and the stages it proposes after this plan.
99
+ forge_decompose_table() { # forge_decompose_table <plan>
100
+ local plan="$1" tree stages
101
+ forge_decompose_py limits "$plan" 2>/dev/null || return 0
102
+ if [ -f "$plan/auto_split" ]; then
103
+ echo " auto-split is on: a task that stops on \`split\` is split by the planner within these limits"
104
+ else
105
+ echo " a task that stops on \`split\` waits for your choice (run --auto-split lets the planner split it within these limits)"
106
+ fi
107
+ [ -z "${DECOMPOSE_LINES:-}" ] || printf '%s\n' "$DECOMPOSE_LINES" | sed 's/^/ /'
108
+ tree="$(forge_decompose_py tree "$plan" --split-only 2>/dev/null)"
109
+ if [ -n "$tree" ]; then
110
+ echo "subtasks (a split task runs its subtasks as a plan of its own, on its branch, and is then reviewed on all of it):"
111
+ printf '%s\n' "$tree" | sed 's/^/ /'
112
+ fi
113
+ stages="$(forge_decompose_py later "$plan" 2>/dev/null)"
114
+ if [ -n "$stages" ]; then
115
+ echo "later stages (the goal is larger than this plan; each is planned when the one before has merged):"
116
+ printf '%s\n' "$stages" | sed 's/^/ /'
117
+ echo " plan the next one with: forge-parallel.sh next $plan"
118
+ fi
119
+ echo
120
+ }
121
+
122
+ # --- run -------------------------------------------------------------------------------------
123
+
124
+ # The planner a split is asked of: run --split-planner, else the planner the plan was made with.
125
+ forge_split_planner() { # forge_split_planner <plan>
126
+ if [ -s "$1/split_planner" ]; then head -1 "$1/split_planner"
127
+ elif [ -s "$1/planner" ]; then head -1 "$1/planner"; fi
128
+ }
129
+
130
+ # run --auto-split / --no-auto-split / --split-planner, as do_run parsed them. Kept as plan files.
131
+ forge_auto_split_store() { # forge_auto_split_store <plan> <on|off|""> <planner spec|"">
132
+ local plan="$1"
133
+ [ -z "$3" ] || printf '%s\n' "$3" > "$plan/split_planner" || die "could not write $plan/split_planner"
134
+ case "$2" in
135
+ on) : > "$plan/auto_split" || die "could not write $plan/auto_split" ;;
136
+ off) rm -f "$plan/auto_split" ;;
137
+ esac
138
+ if [ -f "$plan/auto_split" ] && [ -z "$(forge_split_planner "$plan")" ]; then
139
+ die "--auto-split needs a planner to ask: give --split-planner SPEC (forge does not pick a model on your behalf)" 2
140
+ fi
141
+ }
142
+
143
+ # The summary block for tasks whose subtasks have not all merged: not failures of the task itself.
144
+ report_subtasks() { # report_subtasks <plan>
145
+ local plan="$1" id any=0
146
+ for id in $(all_ids "$plan/tasks.tsv"); do
147
+ [ -s "$plan/tasks/$id/sub.waiting" ] || continue
148
+ [ "$any" = 1 ] || echo "waiting for their subtasks:"
149
+ any=1
150
+ printf ' %s: %s\n' "$id" "$(tr '\n' ',' < "$plan/tasks/$id/sub.waiting" | sed 's/,$//; s/,/, /g')"
151
+ echo " its plan: $plan/tasks/$id/sub (retry a subtask there: forge-parallel.sh retry $plan/tasks/$id/sub <subtask>)"
152
+ done
153
+ [ "$any" = 0 ] || { echo " once they have merged, forge-parallel.sh run $plan brings them into the task and reviews it"; echo; }
154
+ }
155
+
156
+ # After a run whose every task merged: the stage the planner proposed next, if any.
157
+ report_later() { # report_later <plan>
158
+ local plan="$1" stages
159
+ forge_is_sub_plan "$plan" && return 0
160
+ stages="$(forge_decompose_py later "$plan" 2>/dev/null)"
161
+ [ -n "$stages" ] || return 0
162
+ [ "$(awk -F'\t' '$2 != "MERGED" { n++ } END { print n + 0 }' "$plan/results.tsv" 2>/dev/null)" = 0 ] || return 0
163
+ echo "this plan is one stage of a larger goal; the stages that follow:"
164
+ printf '%s\n' "$stages" | sed 's/^/ /'
165
+ echo " plan the next one (it starts from this plan's integration branch): forge-parallel.sh next $plan"
166
+ echo
167
+ }
168
+
169
+ # One slot of the tree's concurrency bound, held until this task process ends. A split task takes
170
+ # it for its own review: its scheduler gave its slot back while the subtasks ran. Never blocks a
171
+ # task that no scheduler is bounding (a `retry`).
172
+ forge_tree_slot() { # forge_tree_slot <task dir>
173
+ local root="${FORGE_TREE_ROOT:-}" cap="${FORGE_TREE_CAP:-}" ready="$1/.slot.ready.$$" pid
174
+ [ -n "$root" ] && [ -n "$cap" ] || return 0
175
+ rm -f "$ready"
176
+ python3 "$SKILL_DIR/scripts/forge_decompose.py" slot --root "$root" --cap "$cap" --while-pid "$$" --ready "$ready" \
177
+ </dev/null >/dev/null 2>&1 &
178
+ pid=$!
179
+ while [ ! -e "$ready" ] && kill -0 "$pid" 2>/dev/null; do sleep 0.2; done
180
+ rm -f "$ready"
181
+ }
182
+
183
+ # The entry of a split task: runs its sub-plan and, when every subtask has merged, brings the
184
+ # sub-plan's integration branch onto the task's branch. Returns 0 then, and the caller goes on to
185
+ # the snapshot and the review of the cumulative diff. Otherwise the status is written and it
186
+ # returns non-zero: BLOCKED with sub.waiting (a subtask failed, stopped or waits for a person; the
187
+ # attempt is not spent, and the next `run` enters here again), or INTERRUPTED.
188
+ run_split_task() { # run_split_task <plan> <id> <tdir> <wt> <base> <attempt>
189
+ local PLAN="$1" id="$2" tdir="$3" wt="$4" base="$5" attempt="$6"
190
+ local sub="$3/sub" REPO run_id sub_run sub_br start tip rc=0 left args=() grace
191
+ REPO="$(cat "$PLAN/repo")"; run_id="$(cat "$PLAN/run_id")"
192
+ sub_run="$(cat "$sub/run_id")"; sub_br="forge/$sub_run-integration"
193
+ rm -f "$tdir/sub.waiting" "$tdir/sub.infra"
194
+ if ! git -C "$REPO" rev-parse --verify --quiet "$sub_br" >/dev/null 2>&1; then
195
+ # First entry: where the subtasks start. `keep` builds on the task's work as it stands, with
196
+ # whatever an interrupted attempt left uncommitted; `fresh` starts over from the task's base and
197
+ # keeps the earlier work on a ref of its own.
198
+ start="$(python3 -c 'import json, sys
199
+ try:
200
+ print(json.load(open(sys.argv[1])).get("start") or "keep")
201
+ except Exception:
202
+ print("keep")' "$sub/parent.json" 2>/dev/null)"
203
+ if [ "$start" = fresh ]; then
204
+ tip="$(git -C "$wt" rev-parse HEAD)" || { echo ERROR > "$tdir/status"; return 1; }
205
+ if [ "$tip" != "$base" ]; then
206
+ git -C "$REPO" update-ref "refs/forge/kept/$run_id/$id" "$tip" >/dev/null 2>&1 \
207
+ && printf '%s\n' "$tip" > "$tdir/sub.kept" \
208
+ || { echo ERROR > "$tdir/status"; note "$id: could not keep its earlier work on a ref; nothing was reset"; return 1; }
209
+ note "$id: starting over from its base; its earlier work stays on refs/forge/kept/$run_id/$id"
210
+ fi
211
+ if ! { git -C "$wt" reset -q --hard "$base" && git -C "$wt" clean -fdq -e .forge; } >"$tdir/sub.reset.out" 2>&1; then
212
+ echo ERROR > "$tdir/status"; note "$id: could not reset its worktree to its base (see $tdir/sub.reset.out)"; return 1
213
+ fi
214
+ rm -f "$tdir/changes.diff" "$tdir/changes.prev.diff" "$tdir/reviewed.commit"
215
+ elif [ -n "$(git -C "$wt" status --porcelain -- . ':(exclude).forge' 2>/dev/null)" ]; then
216
+ (cd "$wt" && git add -A -- . ':(exclude).forge' && git -c user.name=forge -c user.email=forge@local \
217
+ commit -q -m "forge($id): work in progress, kept for its subtasks") >/dev/null 2>&1 \
218
+ || { echo ERROR > "$tdir/status"; note "$id: could not commit the work its subtasks build on"; return 1; }
219
+ fi
220
+ tip="$(git -C "$wt" rev-parse HEAD)" || { echo ERROR > "$tdir/status"; return 1; }
221
+ git -C "$REPO" branch "$sub_br" "$tip" >/dev/null 2>&1 \
222
+ || { echo ERROR > "$tdir/status"; note "$id: could not create $sub_br for its subtasks"; return 1; }
223
+ printf '%s\n' "$tip" > "$sub/integration.base"
224
+ fi
225
+ [ -s "$sub/waves.tsv" ] || forge_sub_prepare "$sub" \
226
+ || { echo ERROR > "$tdir/status"; note "$id: its sub-plan has no valid task order (see $sub/tasks.tsv)"; return 1; }
227
+ # The run's own budgets and bound apply to the subtasks too. A nested run gets a shorter grace on
228
+ # an interrupt than the run above it, so it has ended before that one stops waiting for it.
229
+ args=(--no-forecast --max-parallel "${FORGE_TREE_CAP:-$(cat "$PLAN/max_parallel" 2>/dev/null || echo 3)}")
230
+ [ "${FORGE_RUN_RETRY_FAILED:-0}" -gt 0 ] 2>/dev/null && args+=(--retry-failed "$FORGE_RUN_RETRY_FAILED")
231
+ [ "${FORGE_RUN_INFRA_RETRIES:-0}" -gt 0 ] 2>/dev/null && args+=(--infra-retries "$FORGE_RUN_INFRA_RETRIES")
232
+ grace="$(awk -v g="${FORGE_INTERRUPT_GRACE:-10}" 'BEGIN { g += 0; if (g <= 0) g = 10; printf "%.1f", g * 0.6 }')"
233
+ note "$id: running its $(all_ids "$sub/tasks.tsv" | grep -c .) subtasks (their plan: $sub)"
234
+ FORGE_INTERRUPT_GRACE="$grace" FORGE_PLAN_LOCK="" FORGE_DATASET_TRIGGER="" \
235
+ /bin/bash "$SELF" run "$sub" "${args[@]}" > "$tdir/sub.out" 2>&1 </dev/null || rc=$?
236
+ left="$(forge_decompose_py waiting "$PLAN" "$id" 2>/dev/null)"
237
+ if [ "$rc" = 130 ] || [ "$rc" -gt 128 ]; then
238
+ echo INTERRUPTED > "$tdir/status"
239
+ [ "$attempt" -gt 0 ] && echo $((attempt - 1)) > "$tdir/attempt"
240
+ note "$id: interrupted while its subtasks ran"; return 1
241
+ fi
242
+ if [ -n "$left" ] || { [ "$rc" != 0 ] && [ "$rc" != 5 ]; }; then
243
+ # Not a failure of this task: its subtasks have not all merged. Nothing was judged, so no
244
+ # attempt is spent; the next run enters here again and the sub-plan resumes where it is.
245
+ [ -n "$left" ] || left="its sub-plan run ended with exit $rc (see $tdir/sub.out)"
246
+ printf '%s\n' "$left" > "$tdir/sub.waiting"
247
+ [ "$rc" != 8 ] || : > "$tdir/sub.infra"
248
+ [ "$attempt" -gt 0 ] && echo $((attempt - 1)) > "$tdir/attempt"
249
+ echo BLOCKED > "$tdir/status"
250
+ if [ "$rc" = 8 ]; then
251
+ note "$id: its subtasks paused on an infrastructure failure ($(printf '%s' "$left" | tr '\n' ',' | sed 's/,$//; s/,/, /g')) — no attempt spent; re-run to resume"
252
+ else
253
+ note "$id: waiting for its subtasks ($(printf '%s' "$left" | tr '\n' ',' | sed 's/,$//; s/,/, /g')) — see $sub and $tdir/sub.out"
254
+ fi
255
+ return 1
256
+ fi
257
+ # Every subtask merged. Usually a fast-forward: the sub-plan's branch started at this task's tip.
258
+ if ! git -C "$wt" -c user.name=forge -c user.email=forge@local merge --no-edit -q "$sub_br" >"$tdir/sub.merge.out" 2>&1; then
259
+ git -C "$wt" merge --abort >/dev/null 2>&1 || true
260
+ echo ERROR > "$tdir/status"
261
+ note "$id: its subtasks' work ($sub_br) did not merge into its branch — see $tdir/sub.merge.out"; return 1
262
+ fi
263
+ git -C "$REPO" rev-parse "$sub_br" > "$tdir/sub.merged.tmp" && mv "$tdir/sub.merged.tmp" "$tdir/sub.merged" \
264
+ || { rm -f "$tdir/sub.merged.tmp"; echo ERROR > "$tdir/status"; return 1; }
265
+ # The sub-plan's integration worktree has done its job; its branch stays, so each subtask's work
266
+ # can still be read.
267
+ local sub_wt; sub_wt="$(cat "$sub/wt_root" 2>/dev/null)/_integration"
268
+ if [ -d "$sub_wt" ] && (cd "$REPO" && git worktree remove --force "$sub_wt" >/dev/null 2>&1); then
269
+ forge_worktree_event removed "$sub" "$REPO" "$sub_wt" "$sub_br" integration
270
+ fi
271
+ note "$id: its subtasks merged into its branch; reviewing the whole task"
272
+ forge_tree_slot "$tdir"
273
+ return 0
274
+ }
275
+
276
+ # --- the split of a task -----------------------------------------------------------------------
277
+
278
+ # One planner dispatch about one task: split it, or keep it whole. 0 when its reply was parsed into
279
+ # tasks/<id>/split.proposal.json, 8 on an infrastructure stop, 4 when it failed or was refused.
280
+ forge_split_ask_planner() { # forge_split_ask_planner <plan> <id> <keep|fresh> <spec>
281
+ local PLAN="$1" id="$2" start="$3" spec="$4" tdir="$1/tasks/$2" where rc=0 tier out
282
+ where="$(cat "$PLAN/wt_root" 2>/dev/null)/$id"
283
+ # The planner reads the task's work so far when the subtasks will build on it.
284
+ if [ "$start" = fresh ] || [ ! -d "$where" ]; then where="$(cat "$PLAN/repo")"; fi
285
+ tier="$(forge_fast_tier "$PLAN" planner)"
286
+ python3 "$SKILL_DIR/scripts/forge-planner.py" node-prompt --plan "$PLAN" --task "$id" --start "$start" >/dev/null || return 4
287
+ mkdir -p "$tdir/split" && cp "$tdir/split.prompt" "$tdir/split/planner.prompt" || return 4
288
+ note "$id: asking the planner ($spec) whether to split it"
289
+ /bin/bash "$DISPATCH" planner "$spec" --repo "$where" --run-dir "$tdir/split" --prompt-file "$tdir/split/planner.prompt" \
290
+ --output summary ${tier:+$tier} > "$tdir/split/planner.out" 2>&1 || rc=$?
291
+ if [ "$rc" = 8 ]; then
292
+ note "$id: the planner stopped on an infrastructure failure (see $tdir/split/planner.infra); the task is as it was"
293
+ return 8
294
+ fi
295
+ [ "$rc" = 0 ] || { note "$id: the planner failed (exit $rc; see $tdir/split/planner.out); the task is as it was"; return 4; }
296
+ out="$(python3 "$SKILL_DIR/scripts/forge-planner.py" node-parse --plan "$PLAN" --task "$id" --reply "$tdir/split/planner.last" 2>&1)" \
297
+ || { note "$id: the planner's ${out:-reply was refused}; the task is as it was"; return 4; }
298
+ }
299
+
300
+ # The split of a task, decided by a person (`retry --decide split`, by `user`) or by a run with
301
+ # --auto-split (by `auto`). The subtasks come from <file> (a person or an orchestrator wrote them),
302
+ # from the planner <spec>, or from a proposal already stored and checked (neither given). On 0 the
303
+ # sub-plan exists, the decision is recorded, and the task's next entry runs it; the caller clears
304
+ # the status. Any other return leaves the task as it was: 2 usage, 3 not split (kept whole, at a
305
+ # limit, or refused; a limit and a kept-whole answer are recorded on the node), 8 the planner
306
+ # stopped on infrastructure.
307
+ retry_split() { # retry_split <plan> <id> <split|split=fresh> <reason> <file|""> <spec|""> <user|auto>
308
+ local PLAN="$1" id="$2" decide="$3" reason="$4" file="$5" spec="$6" by="${7:-user}"
309
+ local tdir="$1/tasks/$2" start=keep out rc=0 attempt ctx="" n
310
+ case "$decide" in split=fresh) start=fresh ;; esac
311
+ if forge_is_split "$PLAN" "$id"; then
312
+ note "$id is already split into subtasks ($tdir/sub): they are kept, never made twice. forge-parallel.sh run $PLAN runs what is left of them"
313
+ return 3
314
+ fi
315
+ if [ -n "$file" ]; then
316
+ [ -f "$file" ] && [ -r "$file" ] || { note "retry: --subtasks '$file' is not a readable file"; return 2; }
317
+ out="$(python3 "$SKILL_DIR/scripts/forge-planner.py" node-parse --plan "$PLAN" --task "$id" --reply "$file" 2>&1)" \
318
+ || { note "$id: the ${out:-subtasks were refused}; nothing was changed"; return 3; }
319
+ elif [ -n "$spec" ]; then
320
+ forge_split_ask_planner "$PLAN" "$id" "$start" "$spec" || return $?
321
+ elif [ ! -s "$tdir/split.proposal.json" ]; then
322
+ note "retry: --decide split needs the subtasks: --subtasks FILE (a forge-plan block or its JSON, as forge-planner.py node-prompt describes it), or --planner SPEC to ask a planner"
323
+ return 2
324
+ fi
325
+ if [ "$start" = keep ] && [ -s "$tdir/qa.last" ] && grep -q 'FORGE_VERDICT' "$tdir/qa.last" 2>/dev/null; then
326
+ ctx="$tdir/.split.context"
327
+ {
328
+ echo "## The work so far, and its last review"
329
+ echo
330
+ echo "The parent task was attempted before it was split. That work is on the branch you start from: build on"
331
+ echo "it, and do not redo what is there and right. Its last review said:"
332
+ echo
333
+ tail -c 6000 "$tdir/qa.last"
334
+ } > "$ctx"
335
+ fi
336
+ out="$(forge_decompose_py split "$PLAN" "$id" --proposal "$tdir/split.proposal.json" --reason "$reason" --by "$by" \
337
+ --start "$start" ${ctx:+--context-file "$ctx"} 2>&1)" || rc=$?
338
+ rm -f "$tdir/split.proposal.json" "$tdir/.split.context"
339
+ case "$rc" in
340
+ 0) ;;
341
+ 4) note "$id: not split — ${out#bounded: }. The node is recorded as bounded and the task stays as it is"; return 3 ;;
342
+ 5) note "$id: kept whole — the answer was one task, not a split. That is recorded with its reason, and the task stays as it is"; return 3 ;;
343
+ *) note "$id: the split was refused — ${out#refused: }; nothing was changed"; return 3 ;;
344
+ esac
345
+ forge_sub_prepare_all "$PLAN" || { note "$id: its sub-plan has no valid task order (see $tdir/sub/tasks.tsv)"; }
346
+ # The decision, as every decision is recorded. It grants the one attempt that reviews the whole
347
+ # task once its subtasks have merged (retry=1 is what the attempt cap reads).
348
+ attempt="$(cat "$tdir/attempt" 2>/dev/null || echo 0)"
349
+ reason="$(printf '%s' "$reason" | tr '\n\r\t' ' ' | sed 's/^ *//; s/ *$//')"
350
+ printf '%s\t%s\t%s\t%s\n' "$(date +%s)" "$attempt" "retry=1 $decide" "$reason" >> "$tdir/decisions.tsv" \
351
+ || note "$id: could not record the decision in decisions.tsv"
352
+ if [ "$start" = fresh ]; then
353
+ rm -f "$tdir/retry_findings.md" "$tdir/retry_findings.commit" "$tdir/retry_findings.source" "$tdir/retry_findings.session" \
354
+ "$tdir/retry_findings.resolved" "$tdir/retry_findings.dwarf.session" "$tdir/retry_findings.dwarf.resolved"
355
+ elif grep -q 'FORGE_VERDICT' "$tdir/qa.last" 2>/dev/null; then
356
+ carry_findings "$tdir" # the review of the whole task is told what the last one found
357
+ fi
358
+ rm -f "$tdir/escalation.stop" "$tdir/split.suggested" "$tdir/escalation.next" "$tdir/decided.left" "$tdir/noretry" \
359
+ "$tdir/decision.md" "$tdir/decision.from" "$tdir/resume" "$tdir/sub.waiting" "$tdir/sub.infra"
360
+ forge_dataset_event decision --dir "$PLAN" --task "$id" --set "choice=$decide" --set "reason=$reason" \
361
+ --set "attempt=$attempt" --set "by=$by"
362
+ forge_decompose_snapshot "$PLAN"
363
+ n="$(all_ids "$tdir/sub/tasks.tsv" | grep -c .)"
364
+ note "$id: split into $n subtasks ($(all_ids "$tdir/sub/tasks.tsv" | tr '\n' ' ' | sed 's/ $//')); their plan is $tdir/sub"
365
+ return 0
366
+ }
367
+
368
+ # run --auto-split (#153): a task that just stopped for a decision with `split` among its reasons is
369
+ # split by the planner, within the limits, without waiting. 0 when it was: the caller enters the
370
+ # task again, which now runs its subtasks. Asked once per task: a task the planner kept whole, or a
371
+ # split a limit refused, waits for the user like any other stop.
372
+ forge_auto_split() { # forge_auto_split <plan> <id>
373
+ local PLAN="$1" id="$2" tdir="$1/tasks/$2" reasons spec rc=0
374
+ [ -f "$PLAN/auto_split" ] || return 1
375
+ [ "$(task_status "$PLAN" "$id")" = NEEDS_DECISION ] || return 1
376
+ reasons="$(sed -n '1s/^reasons: //p' "$tdir/decision.md" 2>/dev/null)"
377
+ case ", $reasons," in *", split,"*) ;; *) return 1 ;; esac
378
+ forge_is_split "$PLAN" "$id" && return 1
379
+ [ ! -f "$tdir/auto_split.asked" ] || return 1
380
+ spec="$(forge_split_planner "$PLAN")"
381
+ [ -n "$spec" ] || { note "$id: --auto-split has no planner to ask (run --split-planner SPEC); the task waits for your decision"; return 1; }
382
+ : > "$tdir/auto_split.asked"
383
+ retry_split "$PLAN" "$id" split "auto-split: the task stopped on split ($reasons)" "" "$spec" auto || rc=$?
384
+ if [ "$rc" != 0 ]; then
385
+ # An infrastructure stop of the planner decided nothing: the next run asks again.
386
+ [ "$rc" != 8 ] || rm -f "$tdir/auto_split.asked"
387
+ return 1
388
+ fi
389
+ rm -f "$tdir/status"
390
+ return 0
391
+ }
392
+
393
+ # --- goal -> plans -----------------------------------------------------------------------------
394
+
395
+ # next <plan> [<new-plan-dir>] [--planner SPEC] [plan flags...]: the plan of the next stage of a
396
+ # larger goal. <plan> must have merged. The new plan starts from its integration branch (--after),
397
+ # takes its routing pools, its options and its limits, and is planned by the planner from the code
398
+ # as it is now. It stops at the table: every plan of a chain is approved on its own.
399
+ do_next() {
400
+ local PLAN="${1:?next needs a plan dir}"; shift
401
+ local NEW="" PLANNER="" EXTRA=() out new repo f key value pools=()
402
+ if [ $# -gt 0 ] && [ "${1#-}" = "$1" ]; then NEW="$1"; shift; fi
403
+ while [ $# -gt 0 ]; do
404
+ case "$1" in
405
+ --planner) PLANNER="${2:?--planner needs a spec}"; shift 2 ;;
406
+ --approved) die "next plans the stage and stops at its table: each plan of a chain is approved on its own, then run with forge-parallel.sh run" 2 ;;
407
+ *) EXTRA+=("$1"); shift ;;
408
+ esac
409
+ done
410
+ [ -s "$PLAN/tasks.tsv" ] || die "no tasks.tsv in '$PLAN'"
411
+ forge_refuse_fractal_run "$PLAN" next
412
+ [ -n "$PLANNER" ] || PLANNER="$(head -1 "$PLAN/planner" 2>/dev/null || true)"
413
+ [ -n "$PLANNER" ] || die "next needs a planner for the new plan: --planner SPEC" 2
414
+ repo="$(cat "$PLAN/repo" 2>/dev/null)"
415
+ [ -n "$repo" ] && [ -d "$repo" ] || die "'$PLAN' has no repository to plan in" 3
416
+ out="$(forge_decompose_py next "$PLAN" ${NEW:+--dir "$NEW"} 2>&1)" || die "next: ${out#refused: }" 3
417
+ new="$out"
418
+ # What the plan before it was made with applies to this one: options, pools, limits.
419
+ for f in no_ripwire no_memory yolo_dwarf yolo_qa reviewer_session implementer_session fast pre_review_tests \
420
+ pre_review_parallel fail_first qa_threshold qa_test_minutes timeout verify_retries verify_cmd verify_parallel setup_cmd setup_before_verify final_qa \
421
+ explore escalate_after retry_per_model max_attempts profile.json retro_mode summaries summaries_model \
422
+ auto_split split_planner; do
423
+ [ ! -f "$PLAN/$f" ] || cp -p "$PLAN/$f" "$new/$f" || die "could not write $new/$f" 3
424
+ done
425
+ [ ! -d "$PLAN/verify.d" ] || cp -Rp "$PLAN/verify.d" "$new/verify.d" || die "could not write $new/verify.d" 3
426
+ while IFS="$(printf '\t')" read -r key value; do
427
+ [ -n "$key" ] && [ -n "$value" ] || continue
428
+ pools+=("$key" "$value")
429
+ done <<FORGE_POOLS
430
+ $(python3 - "$(forge_pools_file "$PLAN")" "$PLAN/qa-routing.json" "$PLAN/decomposition.json" <<'PY'
431
+ import json, sys
432
+ def load(path):
433
+ try:
434
+ data = json.load(open(path, encoding='utf-8'))
435
+ except (OSError, ValueError):
436
+ return {}
437
+ return data if isinstance(data, dict) else {}
438
+ for role, path in (('dwarf', sys.argv[1]), ('qa', sys.argv[2])):
439
+ for tier, flag in (('any', '--' + role), ('low', '--%s-low' % role), ('medium', '--%s-medium' % role), ('high', '--%s-high' % role)):
440
+ specs = load(path).get(tier)
441
+ if isinstance(specs, list) and specs and all(isinstance(s, str) and s and '\t' not in s for s in specs):
442
+ print('%s\t%s' % (flag, ','.join(specs)))
443
+ limits = load(sys.argv[3]).get('limits')
444
+ if isinstance(limits, dict):
445
+ for key in ('depth', 'children', 'nodes'):
446
+ if type(limits.get(key)) is int:
447
+ print('--split-%s\t%d' % (key, limits[key]))
448
+ PY
449
+ )
450
+ FORGE_POOLS
451
+ note "next: planning stage $(python3 -c 'import json, sys; print(json.load(open(sys.argv[1])).get("stage", "?"))' "$new/chain.json" 2>/dev/null) in $new, from the integration branch of $PLAN"
452
+ /bin/bash "$SELF" auto "$new" --repo "$repo" --goal-file "$new/request.md" --plan always --planner "$PLANNER" \
453
+ --after "$PLAN" ${pools[@]+"${pools[@]}"} ${EXTRA[@]+"${EXTRA[@]}"}
454
+ }
@@ -44,6 +44,12 @@ forge_host_path() {
44
44
  fi
45
45
  }
46
46
 
47
+ # forge_repo_memory_off REPO: `forge setup` chose no project memory for this clone
48
+ # (git config forge.memory off). The env var and --no-memory work as before, on top.
49
+ forge_repo_memory_off() {
50
+ [ "$(git -C "${1:-.}" config --get forge.memory 2>/dev/null)" = off ]
51
+ }
52
+
47
53
  forge_ensure_python3() {
48
54
  forge_is_windows || return 0
49
55
 
@@ -156,3 +162,18 @@ forge_link_dir() {
156
162
  fi
157
163
  ln -sfn "$src" "$dest"
158
164
  }
165
+
166
+ # Mark an earlier verification result STALE when accepted.integration moves past verification.commit
167
+ # (#194): accept and deferred merges leave the new tip unverified until run or integrate verifies it.
168
+ mark_verification_stale() { # mark_verification_stale <plan> <new-tip>
169
+ local plan="$1" tip="${2:-}" cur_status cur_vc
170
+ cur_status="$(cat "$plan/verification.status" 2>/dev/null || true)"
171
+ case "$cur_status" in
172
+ PASS|FAIL|INTERRUPTED)
173
+ cur_vc="$(cat "$plan/verification.commit" 2>/dev/null || true)"
174
+ if [ "$cur_vc" != "$tip" ]; then
175
+ echo STALE > "$plan/verification.status"
176
+ rm -f "$plan/verification.exit"
177
+ fi ;;
178
+ esac
179
+ }
@@ -82,7 +82,7 @@ do_group() (
82
82
  # qa.round-<n>.last stay: the next prompt quotes them.
83
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
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"
85
+ "$G/merge.out" "$G/members.paths" "$G/review.base" "$G/review.deps" "$G/invalidated.reason"
86
86
  group_set_status "$G" REVIEWING
87
87
  REPO="$(cat "$PLAN/repo")"; run_id="$(cat "$PLAN/run_id")"; wt_root="$(cat "$PLAN/wt_root")"
88
88
  # --timeout given to run/retry is kept in the plan and wins over the environment, as for a task.
@@ -176,6 +176,8 @@ do_group() (
176
176
  note "group $gid: could not make the review snapshot"
177
177
  group_end "$G" "$round" ERROR "$qa"; return 0
178
178
  fi
179
+ run_worktree_setup "$PLAN" "$REPO" "$cand" "$G" "group-$gid"
180
+ forge_review_deps "$cand" "$snap" "$G/review.deps"
179
181
  cand_fp="$(forge_fingerprint "$cand")" || { group_end "$G" "$round" ERROR "$qa"; return 0; }
180
182
  # A commit: an untracked file the reviewer leaves behind merges nothing, so only tracked content counts (#95).
181
183
  snap_fp="$(forge_fingerprint "$snap" --tracked)" || { group_end "$G" "$round" ERROR "$qa"; return 0; }
@@ -614,6 +616,7 @@ merge_group() { # merge_group <plan> <gid> -> 0 merged, 1 not
614
616
  git -C "$int_wt" rev-parse HEAD > "$PLAN/accepted.integration"
615
617
  local tdir integration
616
618
  integration="$(cat "$PLAN/accepted.integration")"
619
+ mark_verification_stale "$PLAN" "$integration"
617
620
  for id in "${ids[@]}"; do
618
621
  tdir="$PLAN/tasks/$id"
619
622
  touch "$tdir/merged"
@@ -130,7 +130,7 @@ plans_make_integration() { # plans_make_integration <repo> <branch> <commit> <wt
130
130
 
131
131
  # Per-plan option files carried to a derived plan. The cost-bearing choices a user made
132
132
  # for this plan apply to the plan made from it; `planner` does not (nothing plans again).
133
- PLANS_OPTION_FILES="no_ripwire no_memory yolo_dwarf yolo_qa reviewer_session 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"
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 qa_test_minutes timeout verify_retries verify_cmd verify_parallel setup_cmd setup_before_verify final_qa shadow_qa shadow_rate explore escalate_after retry_per_model dwarf-routing.json fractal-routing.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
134
 
135
135
  # --- plan --after: a plan that starts from another plan's integration branch (#143) -------
136
136
  # $PLAN/after holds the previous plan's absolute path; $PLAN/integration.base the commit its work
@@ -550,14 +550,16 @@ do_accept() {
550
550
  sha="$(cat "$tdir/reviewed.commit")"
551
551
  body="$(plans_reviewer_text "$tdir" "$st")"
552
552
  n="$(printf '%s\n' "$body" | grep -c '^- ')"
553
- local gthr='' gdec=''
553
+ local gthr='' gdec='' greason=''
554
554
  if [ -f "$tdir/qa.gate" ]; then
555
- IFS="$(printf '\t')" read -r gthr gdec _ < "$tdir/qa.gate" || true
555
+ IFS="$(printf '\t')" read -r gthr gdec _ _ _ _ greason < "$tdir/qa.gate" || true
556
556
  fi
557
557
  rm -f "$kibak"; [ -f "$ki" ] && cp -p "$ki" "$kibak"
558
558
  {
559
559
  if [ -s "$ki" ]; then cat "$ki"; echo; fi
560
- if [ "${gdec:-}" = fail ]; then
560
+ if [ "${gdec:-}" = fail ] && [ "${greason:-}" = tests ]; then
561
+ echo "## Accepted by a human despite forge's FAIL (the reviewer said PASS, but reported failing tests)"
562
+ elif [ "${gdec:-}" = fail ]; then
561
563
  echo "## Accepted by a human despite forge's FAIL (the reviewer said PASS, but listed findings at or above $gthr)"
562
564
  else
563
565
  echo "## Accepted by a human despite the reviewer's $st verdict"
@@ -602,8 +604,15 @@ do_accept() {
602
604
  echo "$id accepted by a human and merged"
603
605
  echo "known issues recorded in $ki"
604
606
  # 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
606
- echo "tasks that were waiting on it are unchanged; continue with: forge-parallel.sh run $PLAN"
607
+ if [ -z "${FORGE_ACCEPT_LIVE:-}" ]; then
608
+ local rem
609
+ rem="$(awk -F'\t' '$2!="MERGED" {n++} END {print n+0}' "$PLAN/results.tsv")"
610
+ if [ "$rem" -gt 0 ]; then
611
+ echo "tasks that were waiting on it are unchanged; continue with: forge-parallel.sh run $PLAN"
612
+ fi
613
+ if [ "$(cat "$PLAN/verification.status" 2>/dev/null)" = STALE ] || [ "$rem" -eq 0 ]; then
614
+ echo "merged result is unverified until 'run' or 'integrate' verifies it: forge-parallel.sh run $PLAN"
615
+ fi
607
616
  fi
608
617
  return 0
609
618
  }
@@ -661,6 +670,8 @@ do_combine() {
661
670
  p="$(cd "$p" && pwd)"
662
671
  [ -f "$p/tasks.tsv" ] || die "combine: '$p' is not a forge plan (no tasks.tsv)" 3
663
672
  [ "$p" != "$NEW" ] || die "combine: the new plan cannot be one of its sources" 3
673
+ # The subtasks of a split task (#153) merge into that task; they are not a plan to combine.
674
+ ! forge_is_sub_plan "$p" || die "combine: '$p' holds the subtasks of a split task: its work merges into that task, not into a combined plan" 3
664
675
  case "$seen" in *"|$p|"*) die "combine: plan '$p' is listed twice" 3 ;; esac
665
676
  seen="$seen|$p|"
666
677
  norm+=("$p")
@@ -874,7 +885,9 @@ Retry or accept them (or split them off into their own plan) first." 3
874
885
  done
875
886
  all=1; for p in "${SRC[@]}"; do [ -f "$p/pre_review_tests" ] || all=0; done
876
887
  [ "$all" = 1 ] && : > "$NEW/pre_review_tests"
877
- for f in qa_threshold timeout verify_retries verify_parallel pre_review_parallel fast retry_per_model; do
888
+ all=1; for p in "${SRC[@]}"; do [ -f "$p/setup_before_verify" ] || all=0; done
889
+ [ "$all" = 1 ] && printf '%s\n' on > "$NEW/setup_before_verify"
890
+ for f in qa_threshold qa_test_minutes timeout verify_retries verify_parallel pre_review_parallel fast retry_per_model; do
878
891
  same=1
879
892
  for p in "${SRC[@]}"; do
880
893
  if [ ! -f "$p/$f" ] || ! cmp -s "$p/$f" "${SRC[0]}/$f"; then same=0; fi
@@ -914,7 +927,7 @@ sys.exit(0 if key(sys.argv[1]) == key(sys.argv[2]) else 1)' "$p/profile.json" "$
914
927
  [ -s "$p/verify_cmd" ] && { cp -p "$p/verify_cmd" "$NEW/verify_cmd"; break; }
915
928
  done
916
929
  fi
917
- for f in fractal-routing.json jev-selection.json; do
930
+ for f in dwarf-routing.json fractal-routing.json jev-selection.json; do
918
931
  for p in "${SRC[@]}"; do [ -f "$p/$f" ] && { cp -p "$p/$f" "$NEW/$f"; break; }; done
919
932
  done
920
933
  {
@@ -976,16 +989,15 @@ do_split() {
976
989
  done
977
990
  PICKED="$(printf '%s' "$SEL" | sed 's/^ *//; s/ *$//')"
978
991
 
979
- # Fractal binds a task's state to hashed output paths under the plan directory; moving
980
- # the task out would orphan it, and no honest way to re-bind it exists.
981
- if [ -s "$PLAN/fractal-selection.json" ]; then
982
- python3 -c 'import json, sys
983
- try:
984
- sys.exit(0 if json.load(open(sys.argv[1])).get("enabled") is False else 1)
985
- except Exception:
986
- sys.exit(1)' "$PLAN/fractal-selection.json" \
987
- || die "this plan runs under Fractal, which binds each task to output paths under the plan directory; a Fractal-backed plan cannot be split" 3
988
- fi
992
+ # A plan made with Fractal (removed in forge 0.23) kept each task's state under paths of its own
993
+ # runtime: its tasks cannot be moved to a plan that runs.
994
+ forge_refuse_fractal_run "$PLAN" split
995
+ # #153: a split task's subtasks are a plan under this run's id, on its branches. They stay with
996
+ # the run: neither they nor the task they belong to move to another plan.
997
+ ! forge_is_sub_plan "$PLAN" || die "split: '$PLAN' holds the subtasks of a split task; they stay with that task" 3
998
+ for id in $PICKED; do
999
+ ! forge_is_split "$PLAN" "$id" || die "split: task '$id' is split into subtasks ($PLAN/tasks/$id/sub), which stay with this run; it cannot move to another plan" 3
1000
+ done
989
1001
  for f in repo run_id wt_root accepted.integration; do
990
1002
  [ -s "$PLAN/$f" ] || die "plan has no $f: it has not run far enough to split ('run' it first)" 3
991
1003
  done