@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
@@ -7,7 +7,7 @@
7
7
  # Usage:
8
8
  # forge-parallel.sh plan <plan-dir> --repo <dir> [routing flags] [--decompose-level low|medium|high] [--ui]
9
9
  # [--qa-threshold P0|P1|P2|P3|none|default] [--profile NAME | --no-profile]
10
- # [--collapse-chains]
10
+ # [--collapse-chains] [--split-depth N] [--split-children N] [--split-nodes N]
11
11
  # forge-parallel.sh auto <plan-dir> --repo <dir> --goal-file <file> [--planner <spec>] [--decompose-level L]
12
12
  # [--plan auto|always|never] [--one-task-difficulty low|medium|high]
13
13
  # [--no-collapse] [--approved] [plan flags...] [-- run flags...]
@@ -17,21 +17,27 @@
17
17
  # [--qa-threshold P0|P1|P2|P3|none|default] [--verify-retries N] [--no-forecast]
18
18
  # [--sweep P0|P1|P2|P3 [--sweep-plausible] [--sweep-max N]]
19
19
  # [--sweep-ahead | --no-sweep-ahead] [--attribute | --no-attribute]
20
+ # [--auto-split [--split-planner <spec>] | --no-auto-split]
20
21
  # forge-parallel.sh retry <plan-dir> <task-id> [--dwarf <spec>] [--setup <command>]
21
22
  # [--answer <text> | --answer-file <file>] (a NEEDS_INPUT task)
22
23
  # [--decide retry=N|threshold=Pn] [--dwarf <spec>] --reason "<why>" --approved
23
24
  # (a NEEDS_DECISION task)
25
+ # [--decide split[=fresh] [--subtasks <file> | --planner <spec>] --reason "<why>" --approved]
26
+ # (split the task into subtasks: any task that has not passed)
24
27
  # [--no-dispatch] (prepare it and start nothing: the next `run` dispatches it)
25
28
  # [--timeout S] [--qa-threshold Pn|none|default] [--verify-retries N]
26
29
  # [--retry-failed N] [--infra-retries M]
27
30
  # forge-parallel.sh integrate <plan-dir> --approved [--verify-retries N] [--final-review <qa-spec>]
28
31
  # forge-parallel.sh review <plan-dir> [--qa <spec>] [--yolo-qa] [--qa-threshold Pn|none|default]
29
32
  # forge-parallel.sh attribute <plan-dir> [--force] (find a merge that breaks the failed verification)
33
+ # forge-parallel.sh verify <plan-dir> [--verify-retries N] [--verify-parallel N] (verify the integration branch again, nothing else)
30
34
  # forge-parallel.sh accept <plan-dir> <task-id> --reason "<why>" --approved
31
35
  # forge-parallel.sh adopt <plan-dir> <commit|a..b> | --head --reason "<why>" [--qa <spec>] [--approved]
32
36
  # (a commit made outside forge, reviewed alone, comes into the run)
33
37
  # forge-parallel.sh split <plan-dir> <new-plan> --tasks <id,id> [--dry-run]
34
38
  # forge-parallel.sh combine <new-plan> <plan-a> <plan-b> [<plan>...] [--verify <command>] [--dry-run]
39
+ # forge-parallel.sh next <plan-dir> [<new-plan>] [--planner <spec>] [plan flags...]
40
+ # (plan the next stage of a goal larger than one plan, after <plan-dir> merged)
35
41
  # forge-parallel.sh _task <plan-dir> <task-id> (internal; coordinator target)
36
42
  # forge-parallel.sh _group <plan-dir> <group-id> (internal; one QA review of a review=group group, #140)
37
43
  # forge-parallel.sh _group_settle <plan-dir> <group-id> [--tasks a,b]
@@ -117,6 +123,13 @@
117
123
  # before routing, merge a chain into one task named combined.
118
124
  # A one-task or branching plan is left as it is, and collapsing
119
125
  # a plan that is already collapsed is not an error
126
+ # --split-depth N recursive decomposition (#153): how many levels of subtasks a task may be
127
+ # split into (default 2; 0 turns splitting off)
128
+ # --split-children N most subtasks one split may make (default 6)
129
+ # --split-nodes N most subtasks in the whole run, over every level (default 24)
130
+ # The three limits are shown under the task table, kept in
131
+ # decomposition.json and frozen by the first run: a split that would pass
132
+ # one is recorded as `bounded` and the task runs as one task
120
133
  #
121
134
  # The QA threshold (plan, run, retry, review; kept for the plan):
122
135
  # --qa-threshold Pn the least severe CONFIRMED finding that still blocks (P0 worst ...
@@ -141,6 +154,20 @@
141
154
  # on its way (kept for the plan; --no-sweep-ahead turns it off)
142
155
  # --attribute when the run's combined verification fails, search the merge order for
143
156
  # a merge that breaks it (kept for the plan; --no-attribute turns it off)
157
+ # --auto-split a task that stops for a decision on `split` is split into subtasks by the
158
+ # planner, within the plan's limits, without waiting for you; without it the
159
+ # task waits for your `retry --decide split`. The planner is --split-planner
160
+ # SPEC, else the one the plan was made with. Kept for the plan;
161
+ # --no-auto-split turns it off
162
+ #
163
+ # Subtasks (#153): a task can be split into subtasks, at plan time by the planner or later by
164
+ # `retry <plan> <task> --decide split`. The subtasks are a plan of their own in
165
+ # <plan-dir>/tasks/<task>/sub: they are routed with the plan's difficulty pools, own paths inside the
166
+ # task's files, run on the same scheduler under the run's one --max-parallel, and merge into the
167
+ # task's branch. The task is then reviewed on everything they produced. `split` keeps the task's
168
+ # existing work and the subtasks build on it; `split=fresh` starts over from the task's base and
169
+ # keeps the old work on refs/forge/kept/<run>/<task>. A subtask that fails is retried in its own
170
+ # plan (retry <plan-dir>/tasks/<task>/sub <subtask>); the next `run` of the plan picks the task up.
144
171
  #
145
172
  # auto (#87, #88): from a goal to a finished run in one blocking command, with no orchestrating
146
173
  # session in between. In a NEW plan dir (created when missing; one that already has tasks.tsv
@@ -180,9 +207,8 @@ DISPATCH="$SKILL_DIR/scripts/forge-dispatch.sh"
180
207
  MEMORY="$SKILL_DIR/scripts/forge-memory.sh"
181
208
  source "$SKILL_DIR/scripts/forge-artifact.sh"
182
209
  source "$SKILL_DIR/scripts/forge-metrics.sh"
183
- source "$SKILL_DIR/scripts/forge-fractal-options.sh"
184
210
  source "$SKILL_DIR/scripts/forge-ui-options.sh"
185
- # Beside fractal's, and for the same reason: an option parser sourced from inside
211
+ # Sourced here, at the top: an option parser sourced from inside
186
212
  # a function, after that function has already walked its arguments, cannot parse
187
213
  # anything. Every --jev flag was rejected as "unknown option" until this line.
188
214
  JEV_OPTS=0
@@ -191,7 +217,7 @@ JEV_OPTS=0
191
217
  # Flags shared by several subcommands, then the helper libraries. Functions only, resolved
192
218
  # at call time, so they may use die/note/field and friends defined below.
193
219
  source "$SKILL_DIR/scripts/forge-parallel-options.sh"
194
- for forge_lib in task gates verify attribute plans review adopt group; do
220
+ for forge_lib in task gates verify attribute plans review adopt group decompose; do
195
221
  [ -f "$SKILL_DIR/scripts/forge-lib-$forge_lib.sh" ] && source "$SKILL_DIR/scripts/forge-lib-$forge_lib.sh"
196
222
  done
197
223
  OUTPUT=summary
@@ -347,22 +373,17 @@ EOF
347
373
  forge_profile_export "$PLAN"
348
374
  }
349
375
 
350
- # What `run` reads from the frozen profile when its flags do not say: the retry budgets,
351
- # and the Fractal planner (only with --fractal-auto-decompose, which --fractal-planner needs).
376
+ # What `run` reads from the frozen profile when its flags do not say: the retry budgets.
352
377
  forge_profile_run_values() { # forge_profile_run_values <plan-dir>
353
- local key val arg auto=0 planner=0
378
+ local key val
354
379
  [ -f "$1/profile.json" ] || return 0
355
- for arg in ${FRACTAL_ARGS[@]+"${FRACTAL_ARGS[@]}"}; do
356
- case "$arg" in --fractal-auto-decompose) auto=1 ;; --fractal-planner) planner=1 ;; esac
357
- done
358
380
  while IFS="$(printf '\t')" read -r key val; do
359
381
  case "$key" in
360
382
  policy.retry_failed) [ "$PP_RETRY_FAILED_SET" = 1 ] || PP_RETRY_FAILED="$val" ;;
361
383
  policy.infra_retries) [ "$PP_INFRA_RETRIES_SET" = 1 ] || PP_INFRA_RETRIES="$val" ;;
362
- routing.fractal_planner) [ "$auto$planner" != 10 ] || FRACTAL_ARGS+=(--fractal-planner "$val") ;;
363
384
  esac
364
385
  done <<EOF
365
- $(forge_profile_py value "$1/profile.json" policy.retry_failed policy.infra_retries routing.fractal_planner 2>/dev/null)
386
+ $(forge_profile_py value "$1/profile.json" policy.retry_failed policy.infra_retries 2>/dev/null)
366
387
  EOF
367
388
  }
368
389
 
@@ -656,48 +677,21 @@ forge_groups_max_tasks() {
656
677
  printf '%s' "${value:-6}"
657
678
  }
658
679
 
659
- # Put back the groups a refused derive replaced, or remove the ones it just wrote.
660
- # A Fractal refusal must not leave a review=group groups.tsv that makes every later plan exit 2.
661
- forge_groups_snap_restore() { # forge_groups_snap_restore <plan> <snap dir or empty>
662
- local plan="$1" snap="${2:-}"
663
- if [ -n "$snap" ] && [ -f "$snap/groups.tsv" ]; then cp "$snap/groups.tsv" "$plan/groups.tsv"
664
- else rm -f "$plan/groups.tsv"; fi
665
- if [ -n "$snap" ] && [ -f "$snap/groups.frozen" ]; then cp "$snap/groups.frozen" "$plan/groups.frozen"
666
- else rm -f "$plan/groups.frozen"; fi
667
- [ -z "$snap" ] || rm -rf "$snap"
668
- }
669
-
670
- forge_groups_snap_drop() { [ -z "${1:-}" ] || rm -rf "$1"; }
671
-
672
680
  # forge_groups_plan <plan> <--groups value> <--group-review 0|1> <--group-max-tasks value>
673
681
  forge_groups_plan() {
674
- local plan="$1" src="$2" review="$3" max="$4" out="" snap=""
675
- # derive and a --groups file replace groups.tsv before the Fractal check can refuse them.
676
- if [ -f "$plan/groups.tsv" ] || [ -f "$plan/groups.frozen" ]; then
677
- snap="$(mktemp -d)" || die "could not snapshot the plan's groups" 3
678
- [ ! -f "$plan/groups.tsv" ] || cp "$plan/groups.tsv" "$snap/groups.tsv" \
679
- || { forge_groups_snap_drop "$snap"; die "could not snapshot $plan/groups.tsv" 3; }
680
- [ ! -f "$plan/groups.frozen" ] || cp "$plan/groups.frozen" "$snap/groups.frozen" \
681
- || { forge_groups_snap_drop "$snap"; die "could not snapshot $plan/groups.frozen" 3; }
682
- fi
682
+ local plan="$1" src="$2" review="$3" max="$4" out=""
683
683
  if [ "$src" = waves ]; then
684
684
  out="$(forge_groups_py derive "$plan" --review "$([ "$review" = 1 ] && echo group || echo task)" \
685
- --max-tasks "$(forge_groups_max_tasks "$plan" "$max")" 2>&1)" || { forge_groups_snap_drop "$snap"; forge_groups_die "$out"; }
685
+ --max-tasks "$(forge_groups_max_tasks "$plan" "$max")" 2>&1)" || forge_groups_die "$out"
686
686
  elif [ -n "$src" ]; then
687
- cp "$src" "$plan/groups.tsv" || { forge_groups_snap_drop "$snap"; die "could not copy '$src' to $plan/groups.tsv" 3; }
687
+ cp "$src" "$plan/groups.tsv" || die "could not copy '$src' to $plan/groups.tsv" 3
688
688
  fi
689
689
  if [ ! -f "$plan/groups.tsv" ] && [ ! -f "$plan/groups.frozen" ]; then
690
- forge_groups_snap_drop "$snap"
691
690
  return 0
692
691
  fi
693
692
  # validate, then resolve (writes the group qa back), then freeze
694
693
  out="$(forge_groups_py validate "$plan" --max-tasks "$(forge_groups_max_tasks "$plan" "$max")" 2>&1)" \
695
- || { forge_groups_snap_drop "$snap"; forge_groups_die "$out"; }
696
- if forge_groups_have_review "$plan" && forge_plan_is_fractal "$plan"; then
697
- forge_groups_snap_restore "$plan" "$snap"
698
- die "group review does not support Fractal yet" 2
699
- fi
700
- forge_groups_snap_drop "$snap"
694
+ || forge_groups_die "$out"
701
695
  out="$(forge_groups_py resolve "$plan" 2>&1)" || forge_groups_die "$out"
702
696
  out="$(forge_groups_py freeze "$plan" 2>&1)" || forge_groups_die "$out"
703
697
  return 0
@@ -783,6 +777,7 @@ do_plan() {
783
777
  local RETRY_PER_MODEL=""
784
778
  local COLLAPSE=0 COLLAPSED_NOW=0 FEAT_ERR="" GRP_SRC="" GRP_REVIEW=0 GRP_MAX="" GRP_DIFF=""
785
779
  local CHAIN_PREV="" CHAIN_BASE="" CHAIN_MOVE=0
780
+ local SPLIT_DEPTH="" SPLIT_CHILDREN="" SPLIT_NODES="" DECOMPOSE_LINES=""
786
781
  # The retro, brief and summaries choices, settled before anything is written: a refusal
787
782
  # (a bad value, no model, a spec that does not resolve) leaves the plan dir as it was.
788
783
  forge_features_scan "$@"
@@ -827,6 +822,14 @@ do_plan() {
827
822
  printf '%s' "${2:-}" | grep -Eq '^[0-9]{1,9}$' && [ "$((10#$2))" -ge 1 ] || die "--group-max-diff-kb needs a positive integer"
828
823
  GRP_DIFF="$((10#$2))"; shift 2 ;;
829
824
  --collapse-chains) COLLAPSE=1; shift ;;
825
+ --split-depth|--split-children|--split-nodes)
826
+ printf '%s' "${2:-}" | grep -Eq '^[0-9]{1,3}$' || die "$1 needs a whole number" 2
827
+ case "$1" in
828
+ --split-depth) SPLIT_DEPTH="$((10#$2))" ;;
829
+ --split-children) SPLIT_CHILDREN="$((10#$2))" ;;
830
+ *) SPLIT_NODES="$((10#$2))" ;;
831
+ esac
832
+ shift 2 ;;
830
833
  --dwarf) D_ANY="${2:?}"; shift 2 ;;
831
834
  --dwarf-high) D_HI="${2:?}"; shift 2 ;;
832
835
  --dwarf-medium) D_MD="${2:?}"; shift 2 ;;
@@ -878,12 +881,15 @@ do_plan() {
878
881
  2) exit 2 ;;
879
882
  esac
880
883
  fi
884
+ forge_removed_flag "$1"
881
885
  die "plan: unknown option '$1'"
882
886
  ;;
883
887
  esac
884
888
  done
885
889
  [ -d "$PLAN" ] || die "plan dir '$PLAN' does not exist"
886
890
  [ "$GRP_REVIEW" = 0 ] || [ "$GRP_SRC" = waves ] || die "--group-review goes with --groups waves (it sets the review of the groups waves derives)"
891
+ # The decomposition limits (#153): a bad value, or a change after the first run froze them, refuses the call.
892
+ forge_decompose_limits "$PLAN" "$SPLIT_DEPTH" "$SPLIT_CHILDREN" "$SPLIT_NODES"
887
893
  # The profile (#48) first: its gates and budget count for every decision-model step below,
888
894
  # and its values stand in for the flags this call did not give.
889
895
  forge_profile_plan
@@ -981,16 +987,18 @@ do_plan() {
981
987
  # Before any decision-model step: the privacy floor and the run budget read these.
982
988
  [ "$JEV_OPTS" = 1 ] && forge_decide_env "$REPO" "$PLAN"
983
989
  [ -s "$PLAN/run_id" ] || basename "$PLAN" | sed 's/^forge-//' > "$PLAN/run_id"
984
- # Every plan, --ui or not: forge-ui's view of this repo's runs reads the registry.
985
- forge_ui_register "$PLAN"
990
+ # Every plan, --ui or not: forge-ui's view of this repo's runs reads the registry. A sub-plan (#153)
991
+ # is reached through the plan it belongs to.
992
+ forge_is_sub_plan "$PLAN" || forge_ui_register "$PLAN"
986
993
  [ "${FORGE_RIPWIRE:-}" != off ] || touch "$PLAN/no_ripwire"
987
994
  # Persist plan choices for later run and retry processes.
988
- [ "$NOMEM" = 1 ] && : > "$PLAN/no_memory"
995
+ { [ "$NOMEM" = 1 ] || forge_repo_memory_off "$REPO"; } && : > "$PLAN/no_memory"
989
996
  [ -n "$PLANNER" ] && printf '%s\n' "$PLANNER" > "$PLAN/planner"
990
- python3 - "$PLAN/fractal-routing.json" "$D_ANY" "$D_LO" "$D_MD" "$D_HI" <<'PY'
997
+ # dwarf-routing.json; a plan made before 0.23 kept these pools under another name, read once here.
998
+ python3 - "$PLAN/dwarf-routing.json" "$(forge_pools_file "$PLAN")" "$D_ANY" "$D_LO" "$D_MD" "$D_HI" <<'PY'
991
999
  import json,sys
992
1000
  from pathlib import Path
993
- p=Path(sys.argv[1]); data=json.loads(p.read_text()) if p.exists() else {}
1001
+ p=Path(sys.argv[1]); old=Path(sys.argv.pop(2)); data=json.loads(old.read_text()) if old.exists() else {}
994
1002
  for key,value in zip(('any','low','medium','high'),sys.argv[2:]):
995
1003
  if value: data[key]=[s.strip() for s in value.split(',') if s.strip()]
996
1004
  p.write_text(json.dumps(data))
@@ -1009,7 +1017,7 @@ PY
1009
1017
  # Uncommitted work is invisible to every dwarf, because worktrees branch from a
1010
1018
  # commit. That is the likeliest way to get a confusingly wrong result, so it is
1011
1019
  # stated loudly rather than left for the user to deduce from an odd diff.
1012
- if [ ! -s "$PLAN/after" ] && [ -z "${CHAIN_PREV:-}" ] && [ -n "$(cd "$REPO" && git status --porcelain 2>/dev/null)" ]; then
1020
+ if [ ! -s "$PLAN/after" ] && [ -z "${CHAIN_PREV:-}" ] && [ -n "$(user_tree_changes "$REPO")" ]; then
1013
1021
  note "WARNING: '$REPO' has uncommitted changes. Task worktrees branch from HEAD,"
1014
1022
  note " so those edits will NOT be visible to any dwarf. Commit or stash first"
1015
1023
  note " if the tasks depend on them."
@@ -1170,7 +1178,7 @@ EOF
1170
1178
  if [ "$dw" != UNASSIGNED ]; then
1171
1179
  local assigned
1172
1180
  assigned="$(python3 "$SKILL_DIR/scripts/forge-route.py" assign --plan "$PLAN" --task "$id" \
1173
- --tier "$diff" --epsilon "${EXPLORE:-0}" --default "$dw" --pools "$PLAN/fractal-routing.json" 2>/dev/null)"
1181
+ --tier "$diff" --epsilon "${EXPLORE:-0}" --default "$dw" --pools "$(forge_pools_file "$PLAN")" 2>/dev/null)"
1174
1182
  [ -z "$assigned" ] || dw="$assigned"
1175
1183
  fi
1176
1184
  fi
@@ -1266,7 +1274,19 @@ EOF
1266
1274
  # frozen fingerprint is of the table the run will use.
1267
1275
  forge_groups_plan "$PLAN" "$GRP_SRC" "$GRP_REVIEW" "$GRP_MAX"
1268
1276
 
1277
+ # Recursive decomposition (#153), once the table is routed: the splits a planner proposed become
1278
+ # sub-plans within the limits, routed with this plan's pools, and every other task is recorded as
1279
+ # kept whole. Not for a plan that is about to be refused for an unassigned task.
1280
+ [ "$unassigned" -gt 0 ] || forge_decompose_settle "$PLAN"
1281
+
1282
+ # The brief each task starts from: a change after this is logged at the next dispatch (#220).
1283
+ local seen_id
1284
+ for seen_id in $(all_ids "$T"); do
1285
+ [ ! -d "$PLAN/tasks/$seen_id" ] || record_seen_inputs "$PLAN/tasks/$seen_id" || true
1286
+ done
1287
+
1269
1288
  render_table "$PLAN"
1289
+ forge_decompose_table "$PLAN"
1270
1290
  if [ -n "$qa_kept_msg" ]; then
1271
1291
  echo "note: --qa left existing reviewer(s) unchanged on: $qa_kept_msg (set qa to '-' in tasks.tsv to let --qa fill them)"
1272
1292
  echo
@@ -1350,6 +1370,13 @@ try:
1350
1370
  n = open(plan + '/retry_per_model', encoding='utf-8').read().strip()
1351
1371
  except OSError:
1352
1372
  sys.exit(0)
1373
+ # The scheduler and forge-route.py read only 1-99 and treat anything else as no file (#158): a
1374
+ # hand-edited value is named as ignored, never shown as the setting with a worst case that assumes it.
1375
+ if not re.fullmatch(r'[0-9]{1,9}', n) or not 1 <= int(n) <= 99:
1376
+ print('retry per model: ignored, %s holds %r and not a number from 1 to 99; the run uses --escalate-after '
1377
+ '(plan --retry-per-model N sets it, --no-retry-per-model removes the file)' % (plan + '/retry_per_model', n[:40]))
1378
+ sys.exit(0)
1379
+ n = str(int(n))
1353
1380
  print('retry per model: %s (a task may fail %s times on each model the retry policy gives it, then it moves a rung up)' % (n, n))
1354
1381
  try:
1355
1382
  raw = subprocess.check_output([sys.executable, route, 'worst-case', '--plan', plan], text=True)
@@ -1484,6 +1511,11 @@ EOF
1484
1511
  done
1485
1512
  echo
1486
1513
  done
1514
+ # The model each spec runs today (#187): an alias moves to newer models over time, so the
1515
+ # table says which version `sol` or `astra` is before anything is spent.
1516
+ local models_block
1517
+ models_block="$(python3 "$SKILL_DIR/scripts/forge_models.py" legend "$T" 2>/dev/null)" || models_block=""
1518
+ [ -z "$models_block" ] || printf '%s\n\n' "$models_block"
1487
1519
  render_groups "$PLAN"
1488
1520
  # A chain collapsed on this call, or a chain left as a chain. one and branches say nothing.
1489
1521
  # COLLAPSED_NOW is do_plan's: collapsed.json from an earlier plan is not announced again.
@@ -1592,7 +1624,7 @@ except Exception:
1592
1624
  for tier in ("low", "any"):
1593
1625
  specs = data.get(tier) if isinstance(data, dict) else None
1594
1626
  if isinstance(specs, list) and specs and isinstance(specs[0], str) and specs[0]:
1595
- print(specs[0]); break' "$1/fractal-routing.json" 2>/dev/null)"
1627
+ print(specs[0]); break' "$(forge_pools_file "$1")" 2>/dev/null)"
1596
1628
  [ -n "$spec" ] || return 0
1597
1629
  [ -f "$1/yolo_dwarf" ] && flags=--yolo
1598
1630
  ft="$(forge_fast_tier "$1" dwarf)"
@@ -1712,17 +1744,24 @@ populate_submodules() { # populate_submodules <repo> <wt> <tdir> <id>
1712
1744
  # work in — it just has to install things itself, which is the status quo this exists
1713
1745
  # to improve on. Failing the task instead would turn a slow run into a dead one.
1714
1746
  run_worktree_setup() { # run_worktree_setup <plan> <repo> <wt> <tdir> <id>
1715
- local PLAN="$1" REPO="$2" wt="$3" tdir="$4" id="$5" cmd
1747
+ local PLAN="$1" REPO="$2" wt="$3" tdir="$4" id="$5" cmd before_ignored=""
1716
1748
  # Every worktree forge makes reaches here once, right after it exists, so the submodules'
1717
1749
  # files are in place before `.forge/setup` runs. The outcome lands in <tdir>/submodules.txt.
1718
1750
  populate_submodules "$REPO" "$wt" "$tdir" "$id"
1719
1751
  cmd="$(worktree_setup_command "$PLAN" "$REPO")"
1720
1752
  [ -n "$cmd" ] || return 0
1753
+ before_ignored="$(mktemp "${TMPDIR:-/tmp}/forge-setup-ignored.XXXXXX" 2>/dev/null || true)"
1754
+ [ -z "$before_ignored" ] || forge_capture_ignored_before "$wt" "$before_ignored"
1721
1755
  if (cd "$wt" && eval "$cmd") >"$tdir/setup.out" 2>&1; then
1722
1756
  note "$id: worktree setup ok"
1757
+ python3 "$SKILL_DIR/scripts/forge-setup-stale.py" record-commit "$wt" --out "$tdir/setup.commit" 2>/dev/null || true
1723
1758
  else
1724
1759
  note "$id: worktree setup failed (continuing) — see $tdir/setup.out"
1725
1760
  fi
1761
+ if [ -n "$before_ignored" ]; then
1762
+ forge_record_setup_generated "$wt" "$before_ignored"
1763
+ rm -f "$before_ignored"
1764
+ fi
1726
1765
  }
1727
1766
 
1728
1767
  add_task_worktree() { # add_task_worktree <repo> <wt> <br> <base>: on <br> when it exists, else a new <br> at <base>
@@ -1760,6 +1799,24 @@ dispatch_duration() { # dispatch_duration <tdir> <role>
1760
1799
  #
1761
1800
  # A warning, never a failure: a dwarf that genuinely had to touch one more file did
1762
1801
  # the right thing, and failing the task for it would be worse than reporting it.
1802
+ # The run summary's scope drift of one task, on one line (#220): a path the task's current brief names
1803
+ # (prompt.md or approach.md, as a person may have added it mid-run) is marked as such, apart from paths
1804
+ # nothing explains.
1805
+ drift_labelled() { # drift_labelled <tdir>
1806
+ local tdir="$1" f out="" brief=()
1807
+ [ ! -f "$tdir/prompt.md" ] || brief+=("$tdir/prompt.md")
1808
+ [ ! -f "$tdir/approach.md" ] || brief+=("$tdir/approach.md")
1809
+ while IFS= read -r f; do
1810
+ [ -n "$f" ] || continue
1811
+ if [ "${#brief[@]}" -gt 0 ] && grep -qF -- "$f" "${brief[@]}" 2>/dev/null; then
1812
+ out="${out:+$out }$f (named in the brief)"
1813
+ else
1814
+ out="${out:+$out }$f"
1815
+ fi
1816
+ done < "$tdir/drift.txt"
1817
+ printf '%s' "$out"
1818
+ }
1819
+
1763
1820
  check_drift() { # check_drift <declared-comma-list> <tdir> <wt> <base>
1764
1821
  local declared="$1" tdir="$2" wt="$3" base="$4" touched f d covered
1765
1822
  : > "$tdir/drift.txt"
@@ -1824,6 +1881,59 @@ record_dispatched_inputs() { # record_dispatched_inputs <tdir>
1824
1881
  done
1825
1882
  }
1826
1883
 
1884
+ # The brief forge last accounted for (#220): prompt.md and approach.md as `plan` left them, then as each
1885
+ # change to them was logged (at a dispatch, or by a STALE check). prompt.seen is written last.
1886
+ record_seen_inputs() { # record_seen_inputs <tdir>
1887
+ local tdir="$1" f tmp
1888
+ for f in approach prompt; do
1889
+ tmp="$tdir/.$f.seen.tmp"
1890
+ if [ -f "$tdir/$f.md" ]; then cp "$tdir/$f.md" "$tmp" || { rm -f "$tmp"; return 1; }
1891
+ else : > "$tmp" || return 1; fi
1892
+ mv "$tmp" "$tdir/$f.seen" || { rm -f "$tmp"; return 1; }
1893
+ done
1894
+ }
1895
+
1896
+ # One control.log entry for a change to a task's brief: actor scheduler, action prompt-changed, the attempt,
1897
+ # the files and when forge saw it (`during`: attempt, review or dispatch).
1898
+ audit_brief_change() { # audit_brief_change <plan> <id> <attempt> <during> <file>...
1899
+ python3 - "$SKILL_DIR/scripts/forge-control.py" "$@" <<'PY' 2>/dev/null || note "$2: control.log not updated with the brief change"
1900
+ import importlib.util, sys
1901
+ from pathlib import Path
1902
+ spec = importlib.util.spec_from_file_location('forge_control', sys.argv[1])
1903
+ module = importlib.util.module_from_spec(spec)
1904
+ sys.modules['forge_control'] = module
1905
+ spec.loader.exec_module(module)
1906
+ module.audit(Path(sys.argv[2]), 'scheduler', 'prompt-changed', sys.argv[3], 'prompt', int(sys.argv[4]), None,
1907
+ files=sys.argv[6:], during=sys.argv[5])
1908
+ PY
1909
+ }
1910
+
1911
+ # At dispatch (#220): a brief edited since forge last saw it (between attempts, while the task waited for
1912
+ # a decision or its dependencies, or before its first dispatch) gets its control.log entry now, and its
1913
+ # diff in brief.diff, so every change after `plan` is on record. The baseline is prompt.seen, else the
1914
+ # previous attempt's prompt.dispatched; with neither (a plan from before #220) there is nothing to compare.
1915
+ audit_brief_at_dispatch() { # audit_brief_at_dispatch <plan> <id> <tdir> <attempt>
1916
+ local PLAN="$1" id="$2" tdir="$3" attempt="$4" f cur old ext=seen changed=() tmp="$3/.brief.diff.tmp"
1917
+ [ -f "$tdir/prompt.seen" ] || ext=dispatched
1918
+ [ -f "$tdir/prompt.$ext" ] || { record_seen_inputs "$tdir" || true; return 0; }
1919
+ : > "$tmp" || return 0
1920
+ for f in prompt approach; do
1921
+ cur="$tdir/$f.md"; [ -f "$cur" ] || cur=/dev/null
1922
+ old="$tdir/$f.$ext"; [ -f "$old" ] || old=/dev/null
1923
+ cmp -s "$old" "$cur" && continue
1924
+ changed+=("$f.md")
1925
+ diff -u --label "$f.md (as forge last saw it)" --label "$f.md (attempt $attempt)" "$old" "$cur" >> "$tmp" || true
1926
+ done
1927
+ if [ "${#changed[@]}" -gt 0 ]; then
1928
+ mv "$tmp" "$tdir/brief.diff" || rm -f "$tmp"
1929
+ audit_brief_change "$PLAN" "$id" "$attempt" dispatch "${changed[@]}"
1930
+ note "$id: its brief changed since forge last saw it (${changed[*]}); attempt $attempt gets the new text (see $tdir/brief.diff)"
1931
+ else
1932
+ rm -f "$tmp"
1933
+ fi
1934
+ record_seen_inputs "$tdir" || true
1935
+ }
1936
+
1827
1937
  # Brief inputs the last completed review judged (#209), written in reverse order so
1828
1938
  # prompt.reviewed's presence marks the snapshot complete.
1829
1939
  record_reviewed_inputs() { # record_reviewed_inputs <tdir> <thr>
@@ -1856,8 +1966,11 @@ brief_changed_since_review() { # brief_changed_since_review <tdir> <thr> -> 0 wh
1856
1966
  # Whether the planner edited prompt.md or approach.md while the attempt ran (#150). Returns 0 when it did:
1857
1967
  # the attempt is then STALE, written to stale.diff and control.log, and the caller stops before any review.
1858
1968
  # Returns 1 when nothing changed, or when the attempt predates the .dispatched copies (no check possible).
1859
- prompt_drifted() { # prompt_drifted <plan> <id> <tdir> <attempt>
1860
- local PLAN="$1" id="$2" tdir="$3" attempt="$4" f cur old changed=() tmp="$3/.stale.diff.tmp" what
1969
+ # With `review` (#212) the check runs after the review instead: an edit made while the reviewer worked means
1970
+ # its verdict judged the old text, so it does not count. The finished review is kept as qa.stale.last for the
1971
+ # next attempt to read, and the attempt is STALE all the same.
1972
+ prompt_drifted() { # prompt_drifted <plan> <id> <tdir> <attempt> [attempt|review]
1973
+ local PLAN="$1" id="$2" tdir="$3" attempt="$4" during="${5:-attempt}" f cur old changed=() tmp="$3/.stale.diff.tmp" what
1861
1974
  [ -f "$tdir/prompt.dispatched" ] || return 1
1862
1975
  : > "$tmp" || return 1
1863
1976
  for f in prompt approach; do
@@ -1869,19 +1982,17 @@ prompt_drifted() { # prompt_drifted <plan> <id> <tdir> <attempt>
1869
1982
  done
1870
1983
  if [ "${#changed[@]}" -eq 0 ]; then rm -f "$tmp" "$tdir/stale.diff"; return 1; fi
1871
1984
  mv "$tmp" "$tdir/stale.diff" || rm -f "$tmp"
1872
- python3 - "$SKILL_DIR/scripts/forge-control.py" "$PLAN" "$id" "$attempt" "${changed[@]}" <<'PY' 2>/dev/null \
1873
- || note "$id: control.log not updated with the prompt change"
1874
- import importlib.util, sys
1875
- from pathlib import Path
1876
- spec = importlib.util.spec_from_file_location('forge_control', sys.argv[1])
1877
- module = importlib.util.module_from_spec(spec)
1878
- sys.modules['forge_control'] = module
1879
- spec.loader.exec_module(module)
1880
- module.audit(Path(sys.argv[2]), 'scheduler', 'prompt-changed', sys.argv[3], 'prompt', int(sys.argv[4]), None,
1881
- files=sys.argv[5:])
1882
- PY
1985
+ audit_brief_change "$PLAN" "$id" "$attempt" "$during" "${changed[@]}"
1986
+ # Logged once: the dispatch that follows compares with this, not with the attempt's copy (#220).
1987
+ record_seen_inputs "$tdir" || true
1883
1988
  what="${changed[0]}"; [ "${#changed[@]}" -eq 1 ] || what="${changed[0]} and ${changed[1]}"
1884
- note "$id: $what changed during attempt $attempt — not reviewed; the implementer gets the new text (no attempt spent)"
1989
+ if [ "$during" = review ]; then
1990
+ rm -f "$tdir/qa.stale.last"
1991
+ [ ! -f "$tdir/qa.last" ] || mv -f "$tdir/qa.last" "$tdir/qa.stale.last"
1992
+ note "$id: $what changed during the review of attempt $attempt — its verdict does not count; the implementer gets the new text and the review's findings (no attempt spent)"
1993
+ else
1994
+ note "$id: $what changed during attempt $attempt — not reviewed; the implementer gets the new text (no attempt spent)"
1995
+ fi
1885
1996
  echo STALE > "$tdir/status"
1886
1997
  # The implementer has to run again, so a saved QA-only resume of this attempt no longer applies.
1887
1998
  rm -f "$tdir/resume"
@@ -1987,10 +2098,6 @@ do_task_body() (
1987
2098
  local reviewed review source_fp review_fp
1988
2099
  REPO="$(cat "$PLAN/repo")"; run_id="$(cat "$PLAN/run_id")"
1989
2100
  tdir="$PLAN/tasks/$id"; mkdir -p "$tdir"
1990
- if [ -s "$PLAN/fractal-selection.json" ]; then
1991
- forge_fractal_select "$PLAN" "$REPO" parallel 0 || return $?
1992
- fi
1993
- forge_fast_fractal_note "$PLAN"
1994
2101
  forge_metric_begin "$tdir" task
1995
2102
  dependencies_ready "$PLAN" "$id" || return 1
1996
2103
  echo RUNNING > "$tdir/status"
@@ -2059,12 +2166,21 @@ do_task_body() (
2059
2166
  return 1
2060
2167
  fi
2061
2168
 
2062
- local is_script=0
2169
+ local is_script=0 is_split=0
2063
2170
  task_is_script "$PLAN" "$id" && is_script=1
2171
+ # A split task (#153) whose subtasks are not on its branch yet runs them here, where a model task
2172
+ # runs its implementer. Once they are (sub.merged), a retry is an ordinary one: its implementer
2173
+ # fixes the review's findings in the combined work, and no subtask runs twice.
2174
+ if forge_split_open "$PLAN" "$id"; then
2175
+ is_split=1
2176
+ if [ -n "$resume" ]; then resume=""; rm -f "$tdir/resume"; attempt=$(( attempt + 1 )); echo "$attempt" > "$tdir/attempt"; fi
2177
+ fi
2064
2178
  if [ -z "$resume" ]; then
2065
2179
  # Persist each source separately; QA receives complete context once.
2066
2180
  write_capsule "$PLAN" "$id" dwarf >/dev/null
2067
2181
  cp "$tdir/capsule.md" "$tdir/baseline.capsule"
2182
+ # A brief edited since forge last saw it is logged now, whenever the edit landed (#220).
2183
+ audit_brief_at_dispatch "$PLAN" "$id" "$tdir" "$attempt"
2068
2184
  # What this attempt's implementer is given, to tell later whether the planner edited it (#150).
2069
2185
  record_dispatched_inputs "$tdir" || { rm -f "$tdir/prompt.dispatched"; note "$id: could not record the dispatched prompt; a later edit will not be detected"; }
2070
2186
  if [ "$is_script" = 1 ]; then
@@ -2073,21 +2189,30 @@ do_task_body() (
2073
2189
  forge_metric_phase dispatch
2074
2190
  run_script_task "$PLAN" "$id" "$tdir" "$wt" "$base" || return 1
2075
2191
  fi
2192
+ if [ "$is_split" = 1 ]; then
2193
+ # The subtasks run as a plan of their own and merge into this task's branch. The snapshot and
2194
+ # everything after it are the same: one commit, then the review of the cumulative diff.
2195
+ forge_metric_phase dispatch
2196
+ run_split_task "$PLAN" "$id" "$tdir" "$wt" "$base" "$attempt" || return 1
2197
+ fi
2076
2198
  # The implementer's part, from here to the snapshot, belongs to model tasks only (no reindent, to
2077
2199
  # keep the diff of this section readable).
2078
- if [ "$is_script" != 1 ]; then
2200
+ if [ "$is_script" != 1 ] && [ "$is_split" != 1 ]; then
2079
2201
  # --task lets Jev narrow the injected slice to facts that bear on THIS task. Without
2080
2202
  # it, or with Jev off, the full role slice is injected exactly as before.
2081
2203
  /bin/bash "$MEMORY" inject "$REPO" dwarf --task "$tdir/prompt.md" \
2082
2204
  --run-dir "$tdir" > "$tdir/dwarf.memory"
2205
+ # The messages queued for this task's next attempt (forge control steer, #134) are this attempt's.
2206
+ steer_take "$PLAN" "$id" "$attempt"
2083
2207
  {
2084
2208
  python3 "$SKILL_DIR/scripts/forge-prompt.py" --requirements "$tdir/prompt.md" --capsule "$tdir/baseline.capsule" --approach "$tdir/approach.md" --retry "$tdir/retry_findings.md" --retry-source "$(cat "$tdir/retry_findings.source" 2>/dev/null || echo review)" --memory "$tdir/dwarf.memory"
2209
+ steer_section "$tdir" "$attempt" dwarf
2085
2210
  [ ! -f "$PLAN/sweep_ahead" ] || python3 "$SKILL_DIR/scripts/forge-sweep.py" ahead "$PLAN" "$id" --role dwarf 2>/dev/null
2086
2211
  echo "Implement this task in the repository. Follow the intended approach unless it is wrong; explain deviations. Run the task's requested verification and report results."
2087
2212
  echo "On retry, fix the findings in the existing work; preserve parts not criticised. Explain any finding you reject."
2088
- # With repository verification configured, the whole suite runs after the merge, never per attempt.
2213
+ # With repository verification configured, the whole suite runs once at the end of the run, never per attempt.
2089
2214
  echo; python3 "$SKILL_DIR/scripts/forge-contract.py" dwarf $([ ! -f "$PLAN/pre_review_tests" ] || echo --pre-review) \
2090
- $([ -z "$(verify_source_for "$PLAN" "$REPO")" ] || echo --verify-after-merge)
2215
+ $([ -z "$(verify_source_for "$PLAN" "$REPO" "$(cat "$PLAN/wt_root" 2>/dev/null)/_integration")" ] || echo --verify-after-merge)
2091
2216
  echo; /bin/bash "$MEMORY" note dwarf
2092
2217
  # Last, after the memory note. Nothing is printed when retro is off.
2093
2218
  forge_retro_prompt "$PLAN" dwarf
@@ -2101,9 +2226,7 @@ do_task_body() (
2101
2226
  # dispatch, and nothing here can abort the attempt: a doctor that fails means fresh.
2102
2227
  local is_mode=fresh is_reason="" is_id="" is_fp="" is_cont=()
2103
2228
  if [ -f "$PLAN/implementer_session" ]; then
2104
- if [ -n "${FORGE_FRACTAL_RUN:-}" ] || forge_plan_is_fractal "$PLAN"; then
2105
- is_reason=fractal
2106
- elif [ "$attempt" = 1 ]; then
2229
+ if [ "$attempt" = 1 ]; then
2107
2230
  is_reason=first-attempt
2108
2231
  elif [ ! -s "$tdir/retry_findings.md" ]; then
2109
2232
  is_reason=no-findings
@@ -2122,7 +2245,8 @@ do_task_body() (
2122
2245
  fi
2123
2246
  forge_metric_phase dispatch
2124
2247
  local dwarf_cmd=(/bin/bash "$DISPATCH" dwarf "$dw" --repo "$wt" --run-dir "$tdir" \
2125
- --ripwire-query-file "$tdir/prompt.md" --prompt-file "$tdir/dwarf.input" ${yd:+"$yd"} $ft_dwarf --output "${FORGE_OUTPUT:-summary}")
2248
+ --ripwire-query-file "$tdir/prompt.md" --prompt-file "$tdir/dwarf.input" ${yd:+"$yd"} $ft_dwarf --output "${FORGE_OUTPUT:-summary}" \
2249
+ --steer "$PLAN" "$id" "$attempt")
2126
2250
  "${dwarf_cmd[@]}" ${is_cont[@]+"${is_cont[@]}"} >"$tdir/dwarf.out" 2>&1
2127
2251
  rc=$?
2128
2252
  if [ "$rc" = 9 ] && [ "$is_mode" = continued ]; then
@@ -2187,9 +2311,7 @@ do_task_body() (
2187
2311
  # .forge/ is forge's own memory, rewritten in the user's tree after every run.
2188
2312
  # Left in, it would reach QA as if a dwarf had written it, and any task whose
2189
2313
  # files touched it would collide with every other task in the wave planner.
2190
- if [ -z "${FORGE_FRACTAL_RUN:-}" ] || [ "${FORGE_FRACTAL_RETRY:-}" = 1 ]; then
2191
- [ -s "$tdir/changes.diff" ] && mv "$tdir/changes.diff" "$tdir/changes.prev.diff"
2192
- fi
2314
+ [ -s "$tdir/changes.diff" ] && mv "$tdir/changes.diff" "$tdir/changes.prev.diff"
2193
2315
  (cd "$wt" && git add -A -- . ":(exclude).forge" \
2194
2316
  && git diff --cached --binary "$base" -- . ":(exclude).forge") > "$tdir/changes.diff" 2>/dev/null || { echo ERROR > "$tdir/status"; return 1; }
2195
2317
  if [ ! -s "$tdir/changes.diff" ]; then
@@ -2206,6 +2328,10 @@ do_task_body() (
2206
2328
  echo "The script produced no changes." > "$tdir/qa.last"
2207
2329
  note "$id: the script produced an empty diff"; return 1
2208
2330
  fi
2331
+ if [ "$is_split" = 1 ]; then
2332
+ echo "The subtasks produced no changes at all." > "$tdir/qa.last"
2333
+ note "$id: its subtasks produced an empty diff"; return 1
2334
+ fi
2209
2335
  echo "The dwarf produced no changes at all." > "$tdir/qa.last"
2210
2336
  note "$id: dwarf produced an empty diff"; return 1
2211
2337
  fi
@@ -2213,7 +2339,7 @@ do_task_body() (
2213
2339
  # its code is reviewed rather than refused as identical: the refusal is for a diff a review
2214
2340
  # already judged. The same applies when the brief or threshold changed since that review (#209).
2215
2341
  if [ -s "$tdir/changes.prev.diff" ] && cmp -s "$tdir/changes.diff" "$tdir/changes.prev.diff" \
2216
- && [ "$(cat "$tdir/retry_findings.source" 2>/dev/null)" != bounce ]; then
2342
+ && [ "$is_split" != 1 ] && [ "$(cat "$tdir/retry_findings.source" 2>/dev/null)" != bounce ]; then
2217
2343
  if brief_changed_since_review "$tdir" "$qa_thr"; then
2218
2344
  note "$id: brief changed since the last review — reviewing the unchanged diff against the updated brief"
2219
2345
  else
@@ -2238,7 +2364,7 @@ do_task_body() (
2238
2364
  fi
2239
2365
 
2240
2366
  (cd "$wt" && git -c user.name=forge -c user.email=forge@local \
2241
- commit --allow-empty -q -m "forge($id) attempt $attempt: $(field "$T" "$id" title)$([ "$is_script" != 1 ] || echo ' (script)')") >/dev/null 2>&1 || {
2367
+ commit --allow-empty -q -m "forge($id) attempt $attempt: $(field "$T" "$id" title)$([ "$is_script" != 1 ] || echo ' (script)')$([ "$is_split" != 1 ] || echo ' (subtasks)')") >/dev/null 2>&1 || {
2242
2368
  echo ERROR > "$tdir/status"; return 1;
2243
2369
  }
2244
2370
  reviewed="$(git -C "$wt" rev-parse HEAD)" || return 1
@@ -2296,6 +2422,7 @@ do_task_body() (
2296
2422
  FORGE_REVIEW_SNAPSHOT="$review" # forge_metric_begin's EXIT trap removes it, whatever the outcome
2297
2423
  forge_review_snapshot "$wt" "$base" "$reviewed" "$review" || { echo ERROR > "$tdir/status"; return 1; }
2298
2424
  forge_review_deps "$wt" "$review" "$tdir/review.deps"
2425
+ forge_review_submodules "$wt" "$review" "$tdir/review.deps"
2299
2426
  source_fp="$(forge_fingerprint "$wt")" || return 1
2300
2427
  # The review copy is a commit: an untracked file the reviewer leaves there (a test run's
2301
2428
  # bytecode) changes nothing that merges, so only tracked content counts (#95).
@@ -2324,23 +2451,17 @@ do_task_body() (
2324
2451
  note "$id: the tests this attempt affects fail — sent back to the implementer without a review (see $tdir/prereview.md)"
2325
2452
  return 0
2326
2453
  fi
2327
- # What changed since the review whose findings this reviewer is handed. Fractal keeps
2328
- # today's prompt unless it retries, as changes.prev.diff does. dwarf.last is the reply of
2454
+ # What changed since the review whose findings this reviewer is handed. dwarf.last is the reply of
2329
2455
  # the attempt under review: a dwarf run just rewrote it, or $resume (the validated QA-only
2330
2456
  # path, never the raw marker) guarantees the reviewed commit is the one it describes.
2331
- local prompt_extra=()
2332
- if [ -z "${FORGE_FRACTAL_RUN:-}" ] || [ "${FORGE_FRACTAL_RETRY:-}" = 1 ]; then
2333
- prompt_extra+=(--role qa)
2334
- attempt_delta "$tdir" "$wt" "$reviewed"
2335
- if [ -s "$tdir/changes.since.diff" ]; then
2336
- prompt_extra+=(--retry-diff "$tdir/changes.since.diff" --retry-stat "$tdir/changes.since.stat"
2337
- --retry-range "$(awk '{ print substr($1, 1, 7) ".." substr($2, 1, 7) }' "$tdir/changes.since.range")")
2338
- fi
2339
- if [ -s "$tdir/retry_findings.md" ] && [ -s "$tdir/dwarf.last" ]; then
2340
- prompt_extra+=(--reply "$tdir/dwarf.last")
2341
- fi
2342
- else
2343
- rm -f "$tdir/changes.since.diff" "$tdir/changes.since.range" "$tdir/changes.since.stat"
2457
+ local prompt_extra=(--role qa)
2458
+ attempt_delta "$tdir" "$wt" "$reviewed"
2459
+ if [ -s "$tdir/changes.since.diff" ]; then
2460
+ prompt_extra+=(--retry-diff "$tdir/changes.since.diff" --retry-stat "$tdir/changes.since.stat"
2461
+ --retry-range "$(awk '{ print substr($1, 1, 7) ".." substr($2, 1, 7) }' "$tdir/changes.since.range")")
2462
+ fi
2463
+ if [ -s "$tdir/retry_findings.md" ] && [ -s "$tdir/dwarf.last" ]; then
2464
+ prompt_extra+=(--reply "$tdir/dwarf.last")
2344
2465
  fi
2345
2466
  # A finding sweep's fix task gets the narrow review: one FIXED / NOT FIXED line per finding.
2346
2467
  local qa_kind=task
@@ -2360,6 +2481,7 @@ do_task_body() (
2360
2481
  [ "$(wc -c < "$tdir/.qa.diff" | tr -d ' ')" -le "$REVIEW_DIFF_LIMIT" ] || qa_inline=0
2361
2482
  {
2362
2483
  python3 "$SKILL_DIR/scripts/forge-prompt.py" --requirements "$tdir/prompt.md" --capsule "$tdir/baseline.capsule" --approach "$tdir/approach.md" --retry "$tdir/retry_findings.md" --retry-source "$(cat "$tdir/retry_findings.source" 2>/dev/null || echo review)" ${prompt_extra[@]+"${prompt_extra[@]}"} --memory "$tdir/dwarf.memory" --memory "$tdir/qa.memory"
2484
+ steer_section "$tdir" "$attempt" qa
2363
2485
  python3 "$SKILL_DIR/scripts/forge-contract.py" qa --part head --kind "$qa_kind"
2364
2486
  echo
2365
2487
  if [ "$is_script" = 1 ]; then
@@ -2406,7 +2528,14 @@ for r in json.load(sys.stdin):
2406
2528
  echo "matters because another task may own those files."
2407
2529
  echo
2408
2530
  fi
2409
- python3 "$SKILL_DIR/scripts/forge-contract.py" qa --part tail --kind "$qa_kind" --threshold "$qa_thr"
2531
+ local qa_test_mins="" qa_test_mins_flag=()
2532
+ for _tmf in "$tdir/qa_test_minutes" "$PLAN/qa_test_minutes"; do
2533
+ if [ -f "$_tmf" ]; then
2534
+ qa_test_mins="$(head -1 "$_tmf" 2>/dev/null | tr -d ' \r')"
2535
+ case "$qa_test_mins" in ''|*[!0-9]*) qa_test_mins="" ;; *) qa_test_mins_flag=(--test-minutes "$qa_test_mins") ; break ;; esac
2536
+ fi
2537
+ done
2538
+ python3 "$SKILL_DIR/scripts/forge-contract.py" qa --part tail --kind "$qa_kind" --threshold "$qa_thr" ${qa_test_mins_flag[@]+"${qa_test_mins_flag[@]}"}
2410
2539
  echo
2411
2540
  if [ "$qa_inline" = 1 ]; then
2412
2541
  echo '```diff'; cat "$tdir/.qa.diff"; echo '```'
@@ -2430,7 +2559,7 @@ for r in json.load(sys.stdin):
2430
2559
  # how often two reviewers agree. It reviews its own snapshot from its own dir under
2431
2560
  # $PLAN/shadow/, and nothing in this script ever reads its result.
2432
2561
  local shadow_pid=""
2433
- if [ -s "$PLAN/shadow_qa" ] && [ -z "${FORGE_FRACTAL_RUN:-}" ]; then
2562
+ if [ -s "$PLAN/shadow_qa" ]; then
2434
2563
  python3 "$SKILL_DIR/scripts/forge-shadow.py" run --plan "$PLAN" --task "$id" --worktree "$wt" \
2435
2564
  --base "$base" --reviewed "$reviewed" --attempt "$attempt" --qa "$qa" --tdir "$tdir" ${yq:+--yolo} \
2436
2565
  </dev/null >/dev/null 2>&1 &
@@ -2441,9 +2570,7 @@ for r in json.load(sys.stdin):
2441
2570
  # fresh dispatch, and nothing here can abort the round: a doctor that fails means fresh.
2442
2571
  local rs_mode=fresh rs_reason="" rs_id="" rs_row=1 rs_cont=()
2443
2572
  if [ "$rs_on" = 1 ]; then
2444
- if [ -n "${FORGE_FRACTAL_RUN:-}" ] || forge_plan_is_fractal "$PLAN"; then
2445
- rs_reason=fractal
2446
- elif [ -f "$PLAN/reviewer_session_rate" ] && ! grep -qxF "$id" "$PLAN/reviewer_session_tasks" 2>/dev/null; then
2573
+ if [ -f "$PLAN/reviewer_session_rate" ] && ! grep -qxF "$id" "$PLAN/reviewer_session_tasks" 2>/dev/null; then
2447
2574
  rs_reason=not-sampled # the comparison half of --reviewer-session-rate: every round is fresh
2448
2575
  elif [ ! -s "$tdir/retry_findings.md" ]; then
2449
2576
  rs_reason=first-round
@@ -2516,6 +2643,9 @@ for r in json.load(sys.stdin):
2516
2643
  echo review > "$tdir/invalidated.reason"
2517
2644
  echo INVALIDATED > "$tdir/status"; note "$id: artifact changed during review"; return 1
2518
2645
  fi
2646
+ # The brief edited while the reviewer worked (#212): the verdict judged text that is gone, so it does not
2647
+ # count. STALE as before review, nothing spent; the next attempt gets the new text and these findings.
2648
+ if prompt_drifted "$PLAN" "$id" "$tdir" "$attempt" review; then return 0; fi
2519
2649
  local verdict
2520
2650
  verdict="$(forge_verdict "$tdir/qa.last")"
2521
2651
  /bin/bash "$MEMORY" record "$REPO" --last "$tdir/qa.last" --role qa \
@@ -2545,7 +2675,15 @@ do_task() {
2545
2675
  local rc
2546
2676
  do_task_body "$@"; rc=$?
2547
2677
  record_attempt "$1" "$2"
2548
- post_attempt "$1" "$2"
2678
+ # A split task waiting for its subtasks (#153) was not attempted: nothing to judge or escalate.
2679
+ [ -s "$1/tasks/$2/sub.waiting" ] || post_attempt "$1" "$2"
2680
+ # run --auto-split (#153): a task that just stopped on `split` is split by the planner, and its
2681
+ # subtasks run now, in this same entry, so the scheduler sees one task that took longer.
2682
+ if forge_auto_split "$1" "$2"; then
2683
+ do_task_body "$@"; rc=$?
2684
+ record_attempt "$1" "$2"
2685
+ [ -s "$1/tasks/$2/sub.waiting" ] || post_attempt "$1" "$2"
2686
+ fi
2549
2687
  return $rc
2550
2688
  }
2551
2689
 
@@ -2578,13 +2716,16 @@ merge_task() { # merge_task <plan> <id> -> 0 merged, 1 conflicted
2578
2716
  return 1
2579
2717
  fi
2580
2718
  if (cd "$int_wt" && git merge --no-ff -m "forge: merge $id" "$reviewed" >/dev/null 2>&1); then
2581
- git -C "$int_wt" rev-parse HEAD > "$PLAN/accepted.integration"
2719
+ local integration
2720
+ integration="$(git -C "$int_wt" rev-parse HEAD)"
2721
+ printf '%s\n' "$integration" > "$PLAN/accepted.integration"
2722
+ mark_verification_stale "$PLAN" "$integration"
2582
2723
  touch "$PLAN/tasks/$id/merged"
2583
2724
  rm -f "$tdir/conflict.files"
2584
2725
  # Which of a sweep task's findings its reviewer marked fixed: what `forge issues` leaves out.
2585
2726
  [ ! -f "$tdir/sweep.json" ] || python3 "$SKILL_DIR/scripts/forge-sweep.py" settle "$PLAN" "$id" >/dev/null 2>&1 || true
2586
2727
  forge_dataset_event merge --dir "$PLAN" --task "$id" --set status=MERGED --set commit="$reviewed" \
2587
- --set integration="$(cat "$PLAN/accepted.integration")"
2728
+ --set integration="$integration"
2588
2729
  return 0
2589
2730
  fi
2590
2731
  # Which files collided is the label for whether two tasks were coupled, and the abort
@@ -2608,7 +2749,7 @@ _retry_answer_scan() { # _retry_answer_scan <scratch-dir> <retry args...>
2608
2749
  while [ $# -gt 0 ]; do
2609
2750
  case "$1" in
2610
2751
  --no-ripwire|--yolo-dwarf|--yolo-qa|--no-dispatch) shift ;;
2611
- --output|--verify|--setup) [ $# -ge 2 ] || break; shift 2 ;;
2752
+ --output|--verify|--setup|--subtasks|--planner) [ $# -ge 2 ] || break; shift 2 ;;
2612
2753
  --dwarf) [ $# -ge 2 ] || break; dwarf="$2"; shift 2 ;;
2613
2754
  --decide) [ $# -ge 2 ] || break; decide="$2"; shift 2 ;;
2614
2755
  --reason) [ $# -ge 2 ] || break; reason="$2"; shift 2 ;;
@@ -2668,7 +2809,7 @@ report_untested() { # report_untested <plan> <id>...: verdicts that rest on read
2668
2809
  for id in "$@"; do
2669
2810
  tests_note="$(forge_tests_note "$plan/tasks/$id/qa.last")"
2670
2811
  if [ -n "$tests_note" ]; then
2671
- [ "$untested" = 0 ] && echo "reviews whose tests could not run:"
2812
+ [ "$untested" = 0 ] && echo "reviews whose tests did not complete:"
2672
2813
  untested=1
2673
2814
  printf ' %-*s %s\n' "$id_w" "$id" "$tests_note"
2674
2815
  fi
@@ -2679,7 +2820,9 @@ report_untested() { # report_untested <plan> <id>...: verdicts that rest on read
2679
2820
  do_retry() {
2680
2821
  local PLAN="${1:?retry needs a plan dir}" id="${2:?retry needs a task id}"; shift 2
2681
2822
  FORGE_RUN_STARTED="$(forge_now)"
2823
+ forge_refuse_fractal_run "$PLAN" retry
2682
2824
  local NEWDWARF="" jev_rc=0 ANSWER="" ANSWER_FILE="" HAVE_ANSWER=0 DECIDE="" REASON="" APPROVED=0 NO_DISPATCH=0
2825
+ local SUBTASKS="" SPLIT_PLANNER=""
2683
2826
  # An answer is validated before any option below writes into the plan: a rejected answer
2684
2827
  # changes nothing, --setup and --verify included. Only a NEEDS_INPUT task takes one. The
2685
2828
  # arguments are walked the way the loop below walks them (a value is never taken for a flag),
@@ -2726,7 +2869,9 @@ do_retry() {
2726
2869
  --no-ripwire) export FORGE_RIPWIRE=off; shift ;;
2727
2870
  --output) OUTPUT="${2:?}"; shift 2 ;;
2728
2871
  --dwarf) NEWDWARF="${2:?--dwarf needs a spec}"; shift 2 ;;
2729
- --decide) DECIDE="${2:?--decide needs retry=N or threshold=Pn}"; shift 2 ;;
2872
+ --decide) DECIDE="${2:?--decide needs retry=N, threshold=Pn or split}"; shift 2 ;;
2873
+ --subtasks) SUBTASKS="${2:?--subtasks needs a file}"; shift 2 ;;
2874
+ --planner) SPLIT_PLANNER="${2:?--planner needs a spec}"; shift 2 ;;
2730
2875
  --reason) REASON="${2?--reason needs a text}"; shift 2 ;;
2731
2876
  --approved) APPROVED=1; shift ;;
2732
2877
  --no-dispatch) NO_DISPATCH=1; shift ;;
@@ -2751,6 +2896,7 @@ do_retry() {
2751
2896
  2) exit 2 ;;
2752
2897
  esac
2753
2898
  fi
2899
+ forge_removed_flag "$1"
2754
2900
  die "retry: unknown option '$1'"
2755
2901
  ;;
2756
2902
  esac
@@ -2786,8 +2932,19 @@ do_retry() {
2786
2932
  die "retry: '$id' already has a decision recorded and waits for the next run; forge-parallel.sh run $PLAN starts it" 2
2787
2933
  fi
2788
2934
  retry_decision_gate "$PLAN" "$id" "$st" "$DECIDE" "$NEWDWARF" "$REASON" "$APPROVED"
2935
+ # A split (#153): --subtasks and --planner belong to it alone, and it does not name a model for the task.
2936
+ local is_split_decision=0 cap_decide="$DECIDE"
2937
+ if forge_decide_is_split "$DECIDE"; then
2938
+ is_split_decision=1
2939
+ cap_decide="retry=1" # the split grants the one attempt that reviews the whole task
2940
+ [ -z "$NEWDWARF" ] || die "retry: --decide split does not take --dwarf: the subtasks are routed with the plan's pools" 2
2941
+ [ -z "$SUBTASKS" ] || [ -z "$SPLIT_PLANNER" ] || die "retry: give --subtasks FILE or --planner SPEC, not both" 2
2942
+ [ -n "$SUBTASKS" ] || [ -n "$SPLIT_PLANNER" ] || SPLIT_PLANNER="$(forge_split_planner "$PLAN")"
2943
+ else
2944
+ [ -z "$SUBTASKS$SPLIT_PLANNER" ] || die "retry: --subtasks and --planner go with --decide split" 2
2945
+ fi
2789
2946
  # A task at its attempt cap (#69) is refused with the decision commands unless --decide retry=N reaches past it.
2790
- if ! attempt_cap_gate "$PLAN" "$id" "$st" "$DECIDE"; then write_results "$PLAN"; return 2; fi
2947
+ if ! attempt_cap_gate "$PLAN" "$id" "$st" "$cap_decide"; then write_results "$PLAN"; return 2; fi
2791
2948
  # The user's answer to a NEEDS_INPUT task's question (validated above): written before
2792
2949
  # anything else is prepared, atomically, and kept when the preparation then refuses (the
2793
2950
  # same answer can be retried).
@@ -2805,7 +2962,10 @@ do_retry() {
2805
2962
  # A refusal (the retry policy found no stronger model, or the escalation could not be
2806
2963
  # written) must stop here: past this point the status is cleared and a dwarf dispatched.
2807
2964
  local prc=0
2808
- if [ "$st" = NEEDS_DECISION ]; then
2965
+ if [ "$is_split_decision" = 1 ]; then
2966
+ # The sub-plan is made and the decision recorded; the task's next entry runs its subtasks.
2967
+ retry_split "$PLAN" "$id" "$DECIDE" "$REASON" "$SUBTASKS" "$SPLIT_PLANNER" user || prc=$?
2968
+ elif [ "$st" = NEEDS_DECISION ]; then
2809
2969
  retry_decided "$PLAN" "$id" "$DECIDE" "$NEWDWARF" "$REASON" || prc=$?
2810
2970
  else
2811
2971
  prepare_retry "$PLAN" "$id" "$NEWDWARF" || prc=$?
@@ -2817,6 +2977,7 @@ do_retry() {
2817
2977
  if [ "$prc" != 0 ]; then
2818
2978
  write_results "$PLAN"
2819
2979
  [ "$prc" = 3 ] && return 2
2980
+ [ "$prc" = 6 ] && return 3 # --decide files+= refused (#199): nothing was written
2820
2981
  return "$prc"
2821
2982
  fi
2822
2983
  [ "${FORGE_RIPWIRE:-}" != off ] || touch "$PLAN/no_ripwire"
@@ -2842,9 +3003,8 @@ do_retry() {
2842
3003
  fi
2843
3004
  rm -f "$tdir/retry.prepared"
2844
3005
 
2845
- note "retrying $id with dwarf $(field "$T" "$id" dwarf)"
2846
- forge_fast_fractal_note "$PLAN"
2847
- export FORGE_FRACTAL_RETRY=1
3006
+ if forge_split_open "$PLAN" "$id"; then note "running the subtasks of $id"
3007
+ else note "retrying $id with dwarf $(field "$T" "$id" dwarf)"; fi
2848
3008
  export FORGE_DATASET_TRIGGER=human
2849
3009
  do_task "$PLAN" "$id"
2850
3010
  st="$(task_status "$PLAN" "$id")"
@@ -2906,7 +3066,10 @@ do_retry() {
2906
3066
  for lid in $(all_ids "$T"); do
2907
3067
  case "$(task_status "$PLAN" "$lid")" in PENDING|BLOCKED) left="${left:+$left }$lid" ;; esac
2908
3068
  done
2909
- if [ -n "$left" ]; then
3069
+ if forge_is_sub_plan "$PLAN"; then
3070
+ # A sub-plan (#153) has no verification of its own; its task picks the work up at the next run.
3071
+ note "$PLAN is the sub-plan of a split task: forge-parallel.sh run $(forge_decompose_py root "$PLAN" 2>/dev/null) brings its merged subtasks into the task and reviews it"
3072
+ elif [ -n "$left" ]; then
2910
3073
  note "verification deferred: tasks still to run ($left); the next run, or integrate, verifies the integration branch"
2911
3074
  else
2912
3075
  verify_result "$PLAN" "$(cat "$PLAN/wt_root")/_integration" "$PLAN" || { write_results "$PLAN"; run_report_extras "$PLAN"; return 5; }
@@ -3040,6 +3203,13 @@ verify_result() ( verify_result_body "$@" ) # plan, checkout, artifact directory
3040
3203
  # finished verification's verification.command or verification.lanes.d/). It replaces
3041
3204
  # verify_source_for and verify-discover, so a re-run judges by the predicate that verification
3042
3205
  # used, whatever the plan, the repository or discovery would say now.
3206
+ verify_mark_stale_if_needed() { # verify_mark_stale_if_needed <out> <stale_status> <stale_reason>
3207
+ local out="$1" st="${2:-}" reason="${3:-}"
3208
+ [ "$st" = STALE ] || return 0
3209
+ printf '%s\n' "${reason:-setup inputs changed}" > "$out/verification.stale_setup"
3210
+ note "warning: verification ran against stale setup (${reason:-lockfile or setup input merged since setup}); pass --setup-before-verify or prepend setup to the verify command"
3211
+ }
3212
+
3043
3213
  verify_result_body() { # plan, checkout, artifact directory[, fixed source]
3044
3214
  local plan="$1" wt="$2" out="$3" cmd="" before after rc=0 repo jev_loaded=0 vretries
3045
3215
  FORGE_VERIFY_STOP=0 FORGE_VERIFY_GROUP="" FORGE_VERIFY_TIMER="" FORGE_VERIFY_GRACE=5
@@ -3051,7 +3221,7 @@ verify_result_body() { # plan, checkout, artifact directory[, fixed source]
3051
3221
  rm -f "$out/verification.status" "$out/verification.exit" \
3052
3222
  "$out/verification.flaky" "$out/verification.retry.log" "$out/verification.failing.log" "$out/verification.coverage.txt" \
3053
3223
  "$out/verification.runs.tsv" "$out"/verification.run-*.log "$out/verification.commit" \
3054
- "$out/verification.lanes.json" "$out"/verification.lane.*.log
3224
+ "$out/verification.lanes.json" "$out"/verification.lane.*.log "$out/verification.stale_setup"
3055
3225
  # The commit being verified, named before any early return, so every outcome (FAIL and
3056
3226
  # UNVERIFIED included) can be joined to the code it judged.
3057
3227
  git -C "$wt" rev-parse HEAD > "$out/verification.commit" 2>/dev/null || rm -f "$out/verification.commit"
@@ -3081,7 +3251,12 @@ verify_result_body() { # plan, checkout, artifact directory[, fixed source]
3081
3251
  note "combined result UNVERIFIED: the fixed verification source $fixed is missing or empty"; return 0
3082
3252
  fi
3083
3253
  else
3084
- vsource="$(verify_source_for "$plan" "$repo")"
3254
+ vsource="$(verify_source_for "$plan" "$repo" "$wt")"
3255
+ # The checkout's own lanes or command run (#151): say where the root's copy differs.
3256
+ case "${vsource%%$'\t'*}" in
3257
+ *:checkout) local diffline
3258
+ while IFS= read -r diffline; do note "$diffline"; done < <(verify_root_difference "$vsource" "$repo") ;;
3259
+ esac
3085
3260
  fi
3086
3261
  case "$vsource" in command:*) cmd="$(cat "${vsource#*$'\t'}")" ;; esac
3087
3262
  # A lanes snapshot belongs to the verification that wrote it: a run on a command, or on
@@ -3091,10 +3266,40 @@ verify_result_body() { # plan, checkout, artifact directory[, fixed source]
3091
3266
  echo FAIL > "$out/verification.status"
3092
3267
  note "verification checkout has source changes outside its commit"; return 1
3093
3268
  fi
3269
+ local stale_status="" stale_reason="" setup_cmd_now=""
3270
+ setup_cmd_now="$(worktree_setup_command "$plan" "$repo")"
3271
+ if [ -n "$setup_cmd_now" ]; then
3272
+ local stale_out="" setup_commit_arg=""
3273
+ # The integration worktree's record, only for that checkout: integrate's candidate and
3274
+ # attribute's scratch have their own setup (or none), read from their git-dir marker.
3275
+ if [ -s "$plan/tasks/_integration/setup.commit" ] && [ -s "$plan/wt_root" ] \
3276
+ && [ "$wt" -ef "$(cat "$plan/wt_root")/_integration" ]; then
3277
+ setup_commit_arg="$plan/tasks/_integration/setup.commit"
3278
+ fi
3279
+ stale_out="$(python3 "$SKILL_DIR/scripts/forge-setup-stale.py" check "$plan" "$wt" "$repo" ${setup_commit_arg:+--setup-commit "$setup_commit_arg"} 2>/dev/null || true)"
3280
+ stale_status="${stale_out%%$'\t'*}"
3281
+ stale_reason="${stale_out#*$'\t'}"
3282
+ if [ "$stale_status" = RERUN ]; then
3283
+ note "setup: re-running before verification ($stale_reason)"
3284
+ local setup_log="$out/setup.verify.out"
3285
+ [ -d "$out/tasks/_integration" ] && setup_log="$out/tasks/_integration/setup.verify.out"
3286
+ if (cd "$wt" && eval "$setup_cmd_now") >"$setup_log" 2>&1; then
3287
+ note "setup before verification ok"
3288
+ local commit_out="$out/setup.commit"
3289
+ [ -d "$out/tasks/_integration" ] && commit_out="$out/tasks/_integration/setup.commit"
3290
+ python3 "$SKILL_DIR/scripts/forge-setup-stale.py" record-commit "$wt" --out "$commit_out" 2>/dev/null || true
3291
+ else
3292
+ note "setup before verification failed (continuing) — see $setup_log"
3293
+ fi
3294
+ stale_status=""
3295
+ fi
3296
+ fi
3094
3297
  case "$vsource" in
3095
3298
  lanes:*)
3096
- verify_lanes_run "$plan" "$wt" "$out" "${vsource#*$'\t'}" "$vretries"
3097
- return $? ;;
3299
+ local vrc=0
3300
+ verify_lanes_run "$plan" "$wt" "$out" "${vsource#*$'\t'}" "$vretries" || vrc=$?
3301
+ [ "$vrc" = 0 ] || verify_mark_stale_if_needed "$out" "$stale_status" "$stale_reason"
3302
+ return "$vrc" ;;
3098
3303
  esac
3099
3304
  # Only when nothing is configured: ask Jev to name a command that actually exists
3100
3305
  # in the repo. Its exit code, not its stdout text, decides whether a judgment was
@@ -3187,6 +3392,7 @@ with open(out + "/verification.jev.json", "w") as fh:
3187
3392
  if [ "$rc3" != 0 ] && [ "$rc3" != 126 ] && [ "$rc3" != 127 ] && [ "$b3" = "$a3" ]; then
3188
3393
  echo FAIL > "$out/verification.status"
3189
3394
  note "the failing tests fail again on their own (exit $rc3): a regression, not a flaky test, so the full command is not rerun; see $out/verification.log"
3395
+ verify_mark_stale_if_needed "$out" "$stale_status" "$stale_reason"
3190
3396
  return 1
3191
3397
  fi
3192
3398
  fi
@@ -3217,6 +3423,7 @@ with open(out + "/verification.jev.json", "w") as fh:
3217
3423
  fi
3218
3424
  echo FAIL > "$out/verification.status"
3219
3425
  note "combined verification failed or changed source; see $out/verification.log"
3426
+ verify_mark_stale_if_needed "$out" "$stale_status" "$stale_reason"
3220
3427
  return 1
3221
3428
  fi
3222
3429
  echo PASS > "$out/verification.status"
@@ -3402,16 +3609,15 @@ forge_brief_stale() { # forge_brief_stale <plan> <merged-task>
3402
3609
  # A failure here is one note; the run goes on. run.flags.json describes this run of the plan,
3403
3610
  # not a choice a split or rerun copies, so it is not in the plan option lists.
3404
3611
  forge_run_flags_write() { # forge_run_flags_write <plan> <max-parallel> [argv...]
3405
- local plan="$1" maxp="$2" timeout_file="" verify_file="" fractal=0 ahead=0 sweep_max=""
3612
+ local plan="$1" maxp="$2" timeout_file="" verify_file="" ahead=0 sweep_max=""
3406
3613
  shift 2
3407
3614
  [ ! -s "$plan/timeout" ] || timeout_file="$plan/timeout"
3408
3615
  [ ! -f "$plan/verify_cmd" ] || verify_file="$plan/verify_cmd"
3409
- forge_plan_is_fractal "$plan" && fractal=1
3410
3616
  [ ! -f "$plan/sweep_ahead" ] || ahead=1
3411
3617
  [ "$PP_SWEEP_MAX_SET" = 1 ] && sweep_max="$PP_SWEEP_MAX"
3412
3618
  python3 - "$plan/run.flags.json" \
3413
3619
  "$PP_RETRY_FAILED" "$PP_INFRA_RETRIES" "$PP_SWEEP" "$sweep_max" \
3414
- "$PP_SWEEP_PLAUSIBLE" "$ahead" "$maxp" "$timeout_file" "$verify_file" "$fractal" \
3620
+ "$PP_SWEEP_PLAUSIBLE" "$ahead" "$maxp" "$timeout_file" "$verify_file" \
3415
3621
  -- "$@" <<'PY' >/dev/null 2>&1 || note "could not write $plan/run.flags.json"
3416
3622
  import json, os, sys, tempfile, time
3417
3623
 
@@ -3426,10 +3632,10 @@ def whole(value):
3426
3632
  return int(value) if value != '' else None
3427
3633
 
3428
3634
  args = sys.argv[1:]
3429
- if len(args) < 12 or args[11] != '--':
3635
+ if len(args) < 11 or args[10] != '--':
3430
3636
  sys.exit(1)
3431
3637
  dest = args[0]
3432
- retry, infra, sweep, sweep_max, plausible, ahead, maxp, timeout_file, verify_file, fractal = args[1:11]
3638
+ retry, infra, sweep, sweep_max, plausible, ahead, maxp, timeout_file, verify_file = args[1:10]
3433
3639
  timeout = text(timeout_file)
3434
3640
  data = {
3435
3641
  'retry_failed': int(retry),
@@ -3441,8 +3647,7 @@ data = {
3441
3647
  'max_parallel': int(maxp),
3442
3648
  'timeout': int(timeout.strip()) if timeout is not None else None,
3443
3649
  'verify': text(verify_file),
3444
- 'fractal': fractal == '1',
3445
- 'argv': args[12:],
3650
+ 'argv': args[11:],
3446
3651
  'at': time.time(),
3447
3652
  }
3448
3653
  parent = os.path.dirname(dest) or '.'
@@ -3468,15 +3673,15 @@ do_run() {
3468
3673
  trap run_signal TERM INT
3469
3674
  local PLAN="${1:?run needs a plan dir}"; shift
3470
3675
  FORGE_RUN_STARTED="$(forge_now)" # the summary's overridden verdicts are this run's
3471
- local fractal_pipeline_args=("$@")
3472
- local MAXP=3 DRY=0 jev_rc=0 FORECAST=1 fractal_answer=""
3676
+ local run_argv=("$@")
3677
+ local MAXP=3 DRY=0 jev_rc=0 FORECAST=1 AUTO_SPLIT="" SPLIT_PLANNER="" is_sub=0
3678
+ forge_is_sub_plan "$PLAN" && is_sub=1
3473
3679
  while [ $# -gt 0 ]; do
3474
3680
  case "$1" in
3475
3681
  --no-forecast) FORECAST=0; shift ;;
3476
- --fractal) forge_fractal_flag on || exit $?; shift ;;
3477
- --fractal-auto-decompose) forge_fractal_flag on || exit $?; FRACTAL_ARGS+=("$1"); shift ;;
3478
- --no-fractal) forge_fractal_flag off || exit $?; shift ;;
3479
- --fractal-*) FRACTAL_ARGS+=("$1" "${2:?}"); shift 2 ;;
3682
+ --auto-split) AUTO_SPLIT=on; shift ;;
3683
+ --no-auto-split) AUTO_SPLIT=off; shift ;;
3684
+ --split-planner) SPLIT_PLANNER="${2:?--split-planner needs a spec}"; shift 2 ;;
3480
3685
  --no-ripwire) export FORGE_RIPWIRE=off; shift ;;
3481
3686
  --output) OUTPUT="${2:?}"; shift 2 ;;
3482
3687
  --max-parallel) MAXP="${2:?}"; shift 2 ;;
@@ -3495,20 +3700,30 @@ do_run() {
3495
3700
  2) exit 2 ;;
3496
3701
  esac
3497
3702
  fi
3703
+ forge_removed_flag "$1"
3498
3704
  die "run: unknown option '$1'"
3499
3705
  ;;
3500
3706
  esac
3501
3707
  done
3708
+ forge_refuse_fractal_run "$PLAN" run
3502
3709
  forge_profile_run_values "$PLAN"
3503
3710
  [ "$JEV_OPTS" = 1 ] && forge_jev_settle "$PLAN"
3504
3711
  [ -n "$PP_SWEEP" ] || [ "$PP_SWEEP_PLAUSIBLE$PP_SWEEP_MAX_SET" = 00 ] || die "--sweep-plausible and --sweep-max go with --sweep"
3712
+ # Auto-split (#153): kept for the plan, and refused now when there is no planner to ask.
3713
+ forge_auto_split_store "$PLAN" "$AUTO_SPLIT" "$SPLIT_PLANNER"
3505
3714
  case "$OUTPUT" in summary|full) ;; *) die "--output must be summary or full" ;; esac
3506
3715
  export FORGE_OUTPUT="$OUTPUT"
3507
3716
  case "$MAXP" in ''|*[!0-9]*) die "--max-parallel must be positive" ;; esac
3508
3717
  [ "$MAXP" -gt 0 ] || die "--max-parallel must be positive"
3509
3718
  # Said once, before any dispatch. The run itself still follows retry_per_model.
3510
- if [ -f "$PLAN/retry_per_model" ] && [ -f "$PLAN/escalate_after" ]; then
3511
- note "retry-per-model $(tr -d '[:space:]' < "$PLAN/retry_per_model") replaces --escalate-after for this plan"
3719
+ if [ -f "$PLAN/retry_per_model" ]; then
3720
+ local rpm; rpm="$(tr -d '[:space:]' < "$PLAN/retry_per_model")"
3721
+ # The reading forge-route.py and the scheduler use: 1 to 99, at most 9 digits.
3722
+ if [[ "$rpm" =~ ^[0-9]{1,9}$ ]] && [ "$((10#$rpm))" -ge 1 ] && [ "$((10#$rpm))" -le 99 ]; then
3723
+ [ ! -f "$PLAN/escalate_after" ] || note "retry-per-model $((10#$rpm)) replaces --escalate-after for this plan"
3724
+ else
3725
+ note "retry_per_model holds '$(printf '%.40s' "$rpm")', not a number from 1 to 99, so this run ignores it"
3726
+ fi
3512
3727
  fi
3513
3728
  local T="$PLAN/tasks.tsv" W="$PLAN/waves.tsv"
3514
3729
  [ -s "$W" ] || die "no waves.tsv — run the plan subcommand first"
@@ -3518,9 +3733,6 @@ do_run() {
3518
3733
  if [ -f "$PLAN/groups.tsv" ] || [ -f "$PLAN/groups.frozen" ]; then
3519
3734
  local groups_out
3520
3735
  groups_out="$(forge_groups_py check "$PLAN" 2>&1)" || forge_groups_die "$groups_out"
3521
- if forge_groups_have_review "$PLAN" && { [ "${FRACTAL_CHOICE:-}" = on ] || forge_plan_is_fractal "$PLAN"; }; then
3522
- die "group review does not support Fractal yet" 2
3523
- fi
3524
3736
  fi
3525
3737
 
3526
3738
  compute_waves "$PLAN"
@@ -3533,28 +3745,15 @@ do_run() {
3533
3745
  if [ "$DRY" != 1 ]; then
3534
3746
  # The concurrency limit this run was given, for forge-ui to draw; a later run rewrites it.
3535
3747
  printf '%s\n' "$MAXP" > "$PLAN/max_parallel"
3536
- # Plan registers too; this also picks up plans made before it did.
3537
- forge_ui_register "$PLAN"
3538
- forge_storage_check "$PLAN" "$REPO"
3539
- fi
3540
- # --fractal and an existing selection are refused above. The other way on is this
3541
- # prompt, which forge_fractal_parallel_run asks only once stdin is a terminal and
3542
- # fractal-selection.json does not exist yet (enabled: false has already chosen).
3543
- # Answering y must refuse before that call writes fractal-selection.json; answering
3544
- # n is the same as --no-fractal, so it is not asked twice.
3545
- if [ "$DRY" != 1 ] && [ -t 0 ] && [ -z "${FRACTAL_CHOICE:-}" ] \
3546
- && [ ! -e "$PLAN/fractal-selection.json" ] && ! forge_plan_is_fractal "$PLAN" \
3547
- && forge_groups_have_review "$PLAN"; then
3548
- printf 'Use Fractal for this run? [y/N] ' >&2
3549
- IFS= read -r fractal_answer || fractal_answer=""
3550
- fractal_answer="$(printf '%s' "$fractal_answer" | tr -d '\r' | tr '[:upper:]' '[:lower:]')"
3551
- case "$fractal_answer" in
3552
- y) die "group review does not support Fractal yet" 2 ;;
3553
- esac
3554
- forge_fractal_flag off || exit $?
3748
+ # Plan registers too; this also picks up plans made before it did. A sub-plan (#153) is reached
3749
+ # through the plan it belongs to, and its limits are that plan's.
3750
+ if [ "$is_sub" = 0 ]; then
3751
+ forge_ui_register "$PLAN"
3752
+ forge_storage_check "$PLAN" "$REPO"
3753
+ # The decomposition limits do not change once the plan runs.
3754
+ forge_decompose_py freeze "$PLAN" >/dev/null 2>&1 || note "could not freeze the decomposition limits (decomposition.json)"
3755
+ fi
3555
3756
  fi
3556
- forge_fractal_parallel_run "$PLAN" "$REPO" "$DRY" ${fractal_pipeline_args[@]+"${fractal_pipeline_args[@]}"} || return $?
3557
- forge_fast_fractal_note "$PLAN"
3558
3757
  # Durable, beside the repo — never TMPDIR. A temp worktree root has destroyed
3559
3758
  # real work here before: isolated worktrees are never pushed, so when the root
3560
3759
  # goes, the only copy of that work goes with it.
@@ -3578,7 +3777,7 @@ do_run() {
3578
3777
  fi
3579
3778
 
3580
3779
  # run.flags.json describes this run of the plan, not a choice a split or rerun copies.
3581
- forge_run_flags_write "$PLAN" "$MAXP" ${fractal_pipeline_args[@]+"${fractal_pipeline_args[@]}"}
3780
+ forge_run_flags_write "$PLAN" "$MAXP" ${run_argv[@]+"${run_argv[@]}"}
3582
3781
 
3583
3782
  forge_metric_begin "$PLAN" parallel
3584
3783
  forge_metric_phase preflight
@@ -3586,6 +3785,10 @@ do_run() {
3586
3785
  [ ! -f "$PLAN/no_ripwire" ] || export FORGE_RIPWIRE=off
3587
3786
  preflight_plan "$PLAN" || return $?
3588
3787
  [ -z "$PP_SWEEP" ] || sweep_preflight "$PLAN" || return $?
3788
+ # The planner --auto-split would ask, checked with the rest before any model is paid for.
3789
+ if [ -f "$PLAN/auto_split" ] && [ -n "$(forge_split_planner "$PLAN")" ]; then
3790
+ /bin/bash "$DISPATCH" doctor --spec "$(forge_split_planner "$PLAN")" --role planner $(forge_fast_tier "$PLAN" planner) || return $?
3791
+ fi
3589
3792
  /bin/bash "$SKILL_DIR/scripts/forge-install-ripwire.sh" || true
3590
3793
  forge_metric_phase preparation
3591
3794
  mkdir -p "$wt_root"
@@ -3624,7 +3827,8 @@ do_run() {
3624
3827
  # history says may bounce. Advisory, budgeted and silent without history; it never stops a run.
3625
3828
  [ "$FORECAST" = 1 ] && forecast_report "$PLAN"
3626
3829
  # Invalid verification lanes stop the run here, before any model is paid for, so before the question writer below.
3627
- verify_lanes_check "$PLAN" "$REPO" "$int_wt"
3830
+ # A sub-plan (#153) has no verification of its own: its task's review and the root plan's verification judge it.
3831
+ [ "$is_sub" = 1 ] || verify_lanes_check "$PLAN" "$REPO" "$int_wt"
3628
3832
  # Brief mode (#135), when the plan has it on. Strict asks first and refuses to start while a question of a
3629
3833
  # task that has not started is unanswered; advisory and gated write the questions beside the scheduler.
3630
3834
  local brief_level
@@ -3634,7 +3838,14 @@ do_run() {
3634
3838
  advisory|gated) forge_brief_start "$PLAN" ;;
3635
3839
  esac
3636
3840
  # Say now, before any model is paid for, which suites the verify command will not run.
3637
- verify_coverage_report "$REPO" "$(verify_command_for "$PLAN" "$REPO")" "$PLAN/verification.coverage.txt"
3841
+ [ "$is_sub" = 1 ] || verify_coverage_report "$REPO" "$(verify_command_for "$PLAN" "$REPO" "$int_wt")" "$PLAN/verification.coverage.txt"
3842
+ # What a split task's own run of its subtasks takes from this run (#153): the budgets, and one
3843
+ # --max-parallel for the whole tree, counted in the root plan.
3844
+ export FORGE_RUN_RETRY_FAILED="$PP_RETRY_FAILED" FORGE_RUN_INFRA_RETRIES="$PP_INFRA_RETRIES"
3845
+ if [ "$is_sub" = 0 ] || [ -z "${FORGE_TREE_ROOT:-}" ]; then
3846
+ FORGE_TREE_ROOT="$(forge_decompose_py root "$PLAN" 2>/dev/null)"; FORGE_TREE_ROOT="${FORGE_TREE_ROOT:-$PLAN}"
3847
+ export FORGE_TREE_ROOT FORGE_TREE_CAP="$MAXP"
3848
+ fi
3638
3849
  local sched_rc=0 paused=0 sched_args=()
3639
3850
  [ "$PP_RETRY_FAILED" -gt 0 ] && sched_args+=(--retry-failed "$PP_RETRY_FAILED")
3640
3851
  [ "$PP_INFRA_RETRIES" -gt 0 ] && sched_args+=(--infra-retries "$PP_INFRA_RETRIES")
@@ -3660,7 +3871,7 @@ do_run() {
3660
3871
  # verifying; the next `run` resumes and verifies at its end. An interrupted run has
3661
3872
  # merged only part of its work: a verification of that is not worth its minutes, and it
3662
3873
  # would run again as the rerun if it were killed.
3663
- if [ "$paused" = 0 ] && [ "$interrupted" = 0 ]; then
3874
+ if [ "$paused" = 0 ] && [ "$interrupted" = 0 ] && [ "$is_sub" = 0 ]; then
3664
3875
  run_phase=verification
3665
3876
  ( verify_result_body "$PLAN" "$int_wt" "$PLAN" ) <&0 &
3666
3877
  run_child=$!
@@ -3712,7 +3923,7 @@ do_run() {
3712
3923
  if [ -s "$PLAN/tasks/$id/drift.txt" ]; then
3713
3924
  [ "$drift" = 0 ] && echo "scope drift (touched files the task did not declare):"
3714
3925
  drift=1
3715
- printf ' %-*s %s\n' "$id_w" "$id" "$(tr '\n' ' ' < "$PLAN/tasks/$id/drift.txt")"
3926
+ printf ' %-*s %s\n' "$id_w" "$id" "$(drift_labelled "$PLAN/tasks/$id")"
3716
3927
  fi
3717
3928
  done
3718
3929
  [ "$drift" = 1 ] && echo
@@ -3744,6 +3955,8 @@ do_run() {
3744
3955
  fi
3745
3956
  # Tasks stopped for a decision (#69): why, and the choices. Not failures to retry either.
3746
3957
  report_decisions "$PLAN"
3958
+ # Split tasks whose subtasks have not all merged (#153): not failures of the task either.
3959
+ report_subtasks "$PLAN"
3747
3960
  # Members implemented and waiting for their group's review (#140): not failures either.
3748
3961
  local implemented; implemented="$(awk -F'\t' '$2=="IMPLEMENTED" {print $1}' "$PLAN/results.tsv")"
3749
3962
  if [ -n "$implemented" ]; then
@@ -3764,6 +3977,9 @@ do_run() {
3764
3977
  fi
3765
3978
  if [ "$failed" = 1 ] && [ "$paused" = 0 ] && [ "$interrupted" = 0 ] && [ "$(cat "$PLAN/verification.status" 2>/dev/null)" = FAIL ]; then
3766
3979
  echo "combined verification failed: see $PLAN/verification.log"
3980
+ if [ -s "$PLAN/verification.stale_setup" ]; then
3981
+ echo "warning: stale setup — generated files may predate merged setup inputs ($(cat "$PLAN/verification.stale_setup")); rerun with --setup-before-verify or prepend setup to the verify command"
3982
+ fi
3767
3983
  echo
3768
3984
  if [ -f "$PLAN/attribute_on" ] && declare -F attribute_search >/dev/null; then
3769
3985
  # This run holds the plan lock: the search function, never the subcommand.
@@ -3785,11 +4001,24 @@ do_run() {
3785
4001
  /bin/bash "$MEMORY" spend "$REPO" --run "$run_id" 2>/dev/null | sed 's/^/ /'
3786
4002
  echo
3787
4003
  fi
3788
- if [ ! -f "$PLAN/no_memory" ] && [ -s "$REPO/.forge/memory.md" ]; then
3789
- echo "project memory: $(grep -c '^- ' "$REPO/.forge/memory.md") fact(s) in .forge/ —"
3790
- echo " uncommitted, and the only thing forge wrote outside its own branches."
3791
- echo
3792
- echo "Your branch and working tree were not touched, apart from .forge/ above."
4004
+ # A goal larger than this plan (#153): once this stage has merged, the next one can be planned.
4005
+ [ "$failed" = 1 ] || [ "$interrupted" = 1 ] || [ "$paused" = 1 ] || report_later "$PLAN"
4006
+ local mem_home=""
4007
+ [ -f "$PLAN/no_memory" ] || mem_home="$(/bin/bash "$MEMORY" where "$REPO" 2>/dev/null)"
4008
+ if [ -n "$mem_home" ] && [ -s "$mem_home/.forge/memory.md" ]; then
4009
+ if [ "$mem_home" = "$REPO" ]; then
4010
+ echo "project memory: $(grep -c '^- ' "$mem_home/.forge/memory.md") fact(s) in .forge/ —"
4011
+ echo " uncommitted, and the only thing forge wrote outside its own branches."
4012
+ echo
4013
+ echo "Your branch and working tree were not touched, apart from .forge/ above."
4014
+ else
4015
+ # #159: a linked worktree's learnings live in the main checkout, so removing it loses none.
4016
+ echo "project memory: $(grep -c '^- ' "$mem_home/.forge/memory.md") fact(s) in $mem_home/.forge/ —"
4017
+ echo " the main checkout's, since $REPO is a linked worktree: removing that worktree loses none of them."
4018
+ echo " Uncommitted, and the only thing forge wrote outside its own branches."
4019
+ echo
4020
+ echo "Your branch and working tree were not touched."
4021
+ fi
3793
4022
  else
3794
4023
  echo "Your branch and working tree were not touched."
3795
4024
  fi
@@ -3799,6 +4028,45 @@ do_run() {
3799
4028
  return 0
3800
4029
  }
3801
4030
 
4031
+ # The changes in the user's checkout that make it dirty, as `git status --porcelain` lines, leaving
4032
+ # out forge's own project memory (#156): .forge/memory.md and .forge/ledger.tsv are written into the
4033
+ # repository by forge and never committed by it, so they must not block forge's own integrate, nor be
4034
+ # what a person is told to commit or stash.
4035
+ user_tree_changes() { # user_tree_changes <repo>
4036
+ git -C "$1" status --porcelain -- . ':(exclude).forge/memory.md' ':(exclude).forge/ledger.tsv' 2>/dev/null
4037
+ }
4038
+
4039
+ # --- verify -------------------------------------------------------------------
4040
+ # The plan's verification of its integration branch, and nothing else (#151): after a lane was
4041
+ # fixed, or to tell a flaky failure from a real one, without a `run` that has nothing to dispatch.
4042
+ # The same lanes or command a run would use, on the same checkout, with its results in the plan.
4043
+ do_verify() {
4044
+ local PLAN="${1:?verify needs a plan dir}"; shift
4045
+ while [ $# -gt 0 ]; do
4046
+ if forge_pp_flag verify "$PLAN" "$@"; then shift "$PP_SHIFT"; else die "verify: unknown option '$1'"; fi
4047
+ done
4048
+ [ -s "$PLAN/tasks.tsv" ] || die "no tasks.tsv in '$PLAN'" 3
4049
+ [ -s "$PLAN/wt_root" ] && [ -s "$PLAN/repo" ] && [ -s "$PLAN/accepted.integration" ] \
4050
+ || die "this plan has never been run, so it has no integration branch to verify" 3
4051
+ local REPO int_wt
4052
+ REPO="$(cat "$PLAN/repo")"; int_wt="$(cat "$PLAN/wt_root")/_integration"
4053
+ [ -e "$int_wt/.git" ] || die "the integration worktree $int_wt is missing" 3
4054
+ [ "$(git -C "$int_wt" rev-parse HEAD 2>/dev/null)" = "$(cat "$PLAN/accepted.integration")" ] \
4055
+ || die "integration branch changed outside this run. To bring those commits into the run: forge-parallel.sh adopt $PLAN --head --reason \"...\"" 3
4056
+ verify_lanes_check "$PLAN" "$REPO" "$int_wt"
4057
+ local left="" lid
4058
+ for lid in $(all_ids "$PLAN/tasks.tsv"); do
4059
+ case "$(task_status "$PLAN" "$lid")" in PENDING|BLOCKED|RUNNING) left="${left:+$left }$lid" ;; esac
4060
+ done
4061
+ [ -z "$left" ] || note "tasks still to run ($left): this verifies the integration branch as it is now, without them"
4062
+ local rc=0
4063
+ verify_result "$PLAN" "$int_wt" "$PLAN" || rc=$?
4064
+ write_results "$PLAN"
4065
+ report_verify_notes "$PLAN"
4066
+ echo "verification of $(git -C "$int_wt" rev-parse --short HEAD 2>/dev/null): $(cat "$PLAN/verification.status" 2>/dev/null || echo UNVERIFIED)"
4067
+ case "$rc" in 0) return 0 ;; 130) return 130 ;; *) return 5 ;; esac
4068
+ }
4069
+
3802
4070
  # --- integrate ----------------------------------------------------------------
3803
4071
  do_integrate() {
3804
4072
  local PLAN="${1:?}"; shift
@@ -3810,13 +4078,16 @@ do_integrate() {
3810
4078
  esac
3811
4079
  done
3812
4080
  [ "$APPROVED" = 1 ] || die "integrate needs --approved: it merges forge's work into YOUR current branch"
4081
+ ! forge_is_sub_plan "$PLAN" || die "integrate: '$PLAN' is the sub-plan of a split task; its work merges into that task. Integrate the plan it belongs to: $(forge_decompose_py root "$PLAN" 2>/dev/null)" 3
3813
4082
  report_unmerged "$PLAN"
3814
4083
  local REPO run_id int_br cur
3815
4084
  REPO="$(cat "$PLAN/repo")"; run_id="$(cat "$PLAN/run_id")"; int_br="forge/$run_id-integration"
3816
4085
  cur="$(cd "$REPO" && git rev-parse --abbrev-ref HEAD)"
3817
4086
  [ "$cur" = HEAD ] && die "integration requires a checked-out user branch" 3
3818
4087
  [ "$cur" = "$int_br" ] && die "you are already on $int_br"
3819
- [ -n "$(cd "$REPO" && git status --porcelain)" ] && die "working tree is dirty — commit or stash before integrating"
4088
+ local dirty; dirty="$(user_tree_changes "$REPO")"
4089
+ [ -z "$dirty" ] || die "working tree is dirty — commit or stash before integrating (forge's own .forge/memory.md and .forge/ledger.tsv do not count):
4090
+ $(printf '%s\n' "$dirty" | head -10)"
3820
4091
  # Verify the actual combined candidate, including changes on the user's branch.
3821
4092
  local parent target candidate candidate_sha out
3822
4093
  parent="$(git -C "$REPO" rev-parse HEAD)" || return 3
@@ -3859,7 +4130,7 @@ do_integrate() {
3859
4130
  [ "$(git -C "$REPO" rev-parse --abbrev-ref HEAD)" = "$cur" ] &&
3860
4131
  [ "$(git -C "$REPO" rev-parse HEAD)" = "$parent" ] &&
3861
4132
  [ "$(git -C "$REPO" rev-parse "$int_br")" = "$target" ] &&
3862
- [ -z "$(git -C "$REPO" status --porcelain)" ] || die "branch or working tree changed during verification" 3
4133
+ [ -z "$(user_tree_changes "$REPO")" ] || die "branch or working tree changed during verification" 3
3863
4134
  git -C "$REPO" merge --ff-only "$candidate_sha" || return 6
3864
4135
  # The user's branch has moved: the run shipped. Recorded now, because the cleanup below
3865
4136
  # can still fail and make the command's exit code say otherwise.
@@ -4136,10 +4407,9 @@ AUTO_PROFILE
4136
4407
  # --- main ---------------------------------------------------------------------
4137
4408
  if [ "${1:-}" = --help ] || [ "${1:-}" = -h ]; then
4138
4409
  awk '/^# Usage:/ {on=1} /^set -uo pipefail/ {on=0} on {sub(/^# ?/, ""); print}' "$SELF"
4139
- forge_fractal_help
4140
4410
  exit 0
4141
4411
  fi
4142
- [ $# -ge 1 ] || die "usage: forge-parallel.sh <plan|auto|run|retry|accept|adopt|review|integrate|split|attribute|combine> <plan-dir> [...]"
4412
+ [ $# -ge 1 ] || die "usage: forge-parallel.sh <plan|auto|run|retry|accept|adopt|review|integrate|split|attribute|verify|combine|next> <plan-dir> [...]"
4143
4413
  CMD="$1"; shift
4144
4414
  [ ! -f "${1:-}/no_ripwire" ] || export FORGE_RIPWIRE=off
4145
4415
  if [ -d "${1:-}" ]; then
@@ -4147,7 +4417,7 @@ if [ -d "${1:-}" ]; then
4147
4417
  fi
4148
4418
  case "$CMD" in
4149
4419
  # `combine` takes a plan dir that does not exist yet and locks its sources itself.
4150
- run|retry|integrate|accept|adopt|review|split|attribute)
4420
+ run|retry|integrate|accept|adopt|review|split|attribute|verify)
4151
4421
  if [ "$(forge_posix_path "${FORGE_PLAN_LOCK:-}")" != "${1:-}" ]; then
4152
4422
  exec python3 "$SKILL_DIR/scripts/forge-schedule.py" lock "$SELF" "$CMD" "$@"
4153
4423
  fi ;;
@@ -4156,7 +4426,7 @@ esac
4156
4426
  # path (die included). Installed after the lock re-exec, so it fires once, in the process
4157
4427
  # that did the work; `_task` and `_merge` are parts of a `run` and are not recorded alone.
4158
4428
  case "$CMD" in
4159
- plan|run|retry|integrate|accept|adopt|review|split|attribute|combine)
4429
+ plan|run|retry|integrate|accept|adopt|review|split|attribute|verify|combine)
4160
4430
  FORGE_DATASET_INVOCATION="inv-$(date +%s)-$$-$RANDOM"; export FORGE_DATASET_INVOCATION
4161
4431
  FORGE_DATASET_STARTED="$(date +%s)"
4162
4432
  FORGE_DATASET_ARGV=("$@")
@@ -4167,7 +4437,7 @@ esac
4167
4437
  need_fn() { declare -F "$1" >/dev/null || die "'$CMD' is not available: $1 is missing" 3; }
4168
4438
  # A plan with a frozen profile asks its decision-model gates from that copy (`plan` does it itself,
4169
4439
  # after it freezes). The internal subcommands inherit it from the `run` that started them.
4170
- case "$CMD" in run|retry|integrate|accept|adopt|review|split|attribute) forge_profile_export "${1:-}" ;; esac
4440
+ case "$CMD" in run|retry|integrate|accept|adopt|review|split|attribute|verify) forge_profile_export "${1:-}" ;; esac
4171
4441
  case "$CMD" in
4172
4442
  plan) do_plan "$@"; rc=$?; forge_update_notice; exit "$rc" ;;
4173
4443
  auto) do_auto "$@" ;;
@@ -4205,7 +4475,9 @@ case "$CMD" in
4205
4475
  review) need_fn do_review; do_review "$@" ;;
4206
4476
  split) need_fn do_split; do_split "$@" ;;
4207
4477
  attribute) need_fn do_attribute; do_attribute "$@" ;;
4478
+ verify) do_verify "$@" ;;
4208
4479
  combine) need_fn do_combine; do_combine "$@" ;;
4480
+ next) need_fn do_next; do_next "$@" ;;
4209
4481
  _task) do_task "$@" ;;
4210
4482
  _merge) merge_task "$@" ;;
4211
4483
  _group) need_fn do_group; do_group "$@" ;;