@giamme/forge 0.21.0 → 0.22.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 (42) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +6 -3
  3. package/VERSION +1 -1
  4. package/bin/forge.js +104 -0
  5. package/docs/development.md +1 -1
  6. package/docs/install.md +91 -2
  7. package/docs/reviews.md +6 -4
  8. package/docs/troubleshooting.md +1 -1
  9. package/forge +4 -0
  10. package/forge.cmd +56 -0
  11. package/package.json +5 -3
  12. package/scripts/forge-artifact.sh +5 -1
  13. package/scripts/forge-control.py +10 -3
  14. package/scripts/forge-dispatch.sh +108 -31
  15. package/scripts/forge-guard.py +137 -6
  16. package/scripts/forge-install.sh +82 -9
  17. package/scripts/forge-lib-env.sh +158 -0
  18. package/scripts/forge-lib-group.sh +5 -5
  19. package/scripts/forge-lib-plans.sh +8 -3
  20. package/scripts/forge-lib-task.sh +40 -15
  21. package/scripts/forge-memory.sh +2 -0
  22. package/scripts/forge-metrics.sh +6 -1
  23. package/scripts/forge-parallel.sh +156 -43
  24. package/scripts/forge-runtime.py +2 -2
  25. package/scripts/forge-schedule.py +18 -1
  26. package/scripts/forge-solo.sh +6 -2
  27. package/scripts/forge-sweep.py +1 -1
  28. package/scripts/forge-update.sh +6 -1
  29. package/scripts/forge-verify.py +1 -0
  30. package/scripts/forge-win.sh +156 -0
  31. package/scripts/forge_brief/__init__.py +6 -1
  32. package/scripts/forge_brief/proposals.py +6 -1
  33. package/scripts/forge_decide/budget.py +12 -7
  34. package/scripts/forge_decide/replay.py +9 -4
  35. package/scripts/forge_flock.py +17 -2
  36. package/scripts/forge_posix.py +17 -0
  37. package/scripts/forge_proc.py +108 -0
  38. package/scripts/forge_registry.py +2 -2
  39. package/scripts/forge_side/__init__.py +13 -4
  40. package/ui/forge_ui/control.py +7 -2
  41. package/ui/forge_ui/reader.py +6 -1
  42. package/ui/forge_ui/static/scene3d.js +23 -2
@@ -172,6 +172,10 @@ set -uo pipefail
172
172
 
173
173
  SELF="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/$(basename "${BASH_SOURCE[0]}")"
174
174
  SKILL_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
175
+ # Windows: re-run inside MSYS2 when started from Git Bash (no-op elsewhere).
176
+ . "$SKILL_DIR/scripts/forge-win.sh"
177
+ source "$SKILL_DIR/scripts/forge-lib-env.sh"
178
+ forge_ensure_python3
175
179
  DISPATCH="$SKILL_DIR/scripts/forge-dispatch.sh"
176
180
  MEMORY="$SKILL_DIR/scripts/forge-memory.sh"
177
181
  source "$SKILL_DIR/scripts/forge-artifact.sh"
@@ -209,6 +213,13 @@ field() { # field <tasks.tsv> <id> <colname>
209
213
  }
210
214
  all_ids() { awk -F'\t' '!/^#/ && NF {print $1}' "$1"; }
211
215
 
216
+ render_results_table() { # render_results_table <plan>
217
+ local w
218
+ w="$(id_col_width "$1/results.tsv" "$1/tasks.tsv")"
219
+ printf ' %-*s %-14s %s\n' "$w" id status branch
220
+ awk -F'\t' -v w="$w" '{printf " %-*s %-14s %s\n", w, $1, $2, $3}' "$1/results.tsv"
221
+ }
222
+
212
223
  list_has() { # list_has <needle> <comma-list>
213
224
  local n="$1" l="$2" w
214
225
  [ "$l" = "-" ] && return 1
@@ -1106,8 +1117,14 @@ EOF
1106
1117
  fi
1107
1118
  fi
1108
1119
 
1109
- local tmp="$PLAN/.tasks.tsv.new"; : > "$tmp"
1110
- local hi_i=0 md_i=0 lo_i=0 an_i=0 qhi_i=0 qmd_i=0 qlo_i=0 qan_i=0 unassigned=0
1120
+ # A refused plan (a task left UNASSIGNED below) puts tasks.tsv back as it was, so nothing it
1121
+ # routed, such as the default reviewer, is frozen into the next plan (#178). The copy is only
1122
+ # made for a refusal, under one name, so an exit in between leaves at most this one file,
1123
+ # which the next plan removes.
1124
+ local tmp="$PLAN/.tasks.tsv.new" orig_tasks="$PLAN/.tasks.tsv.orig"
1125
+ : > "$tmp"
1126
+ rm -f "$orig_tasks"
1127
+ local hi_i=0 md_i=0 lo_i=0 an_i=0 qhi_i=0 qmd_i=0 qlo_i=0 qan_i=0 unassigned=0 qa_kept_msg="" qa_flag_spec=""
1111
1128
  printf '# id\tdeps\tdifficulty\tfiles\tdwarf\tqa\ttitle\n' > "$tmp"
1112
1129
  local id deps diff files dw qa title line
1113
1130
  while IFS= read -r line; do
@@ -1169,16 +1186,27 @@ EOF
1169
1186
  if [ "$qa" = "-" ] || [ -z "$qa" ]; then
1170
1187
  if [ -n "$Q_ANY" ]; then qa="$(pool_pick "$Q_ANY" "$qan_i")"; qan_i=$((qan_i+1)); else qa="opus"; fi
1171
1188
  fi
1189
+ else
1190
+ qa_flag_spec=""
1191
+ case "$diff" in
1192
+ high) qa_flag_spec="${Q_HI:-$Q_ANY}" ;;
1193
+ medium) qa_flag_spec="${Q_MD:-$Q_ANY}" ;;
1194
+ low) qa_flag_spec="${Q_LO:-$Q_ANY}" ;;
1195
+ esac
1196
+ if [ -n "$qa_flag_spec" ] && ! list_has "$qa" "$qa_flag_spec"; then
1197
+ qa_kept_msg="${qa_kept_msg:+$qa_kept_msg, }$id ($qa)"
1198
+ fi
1172
1199
  fi
1173
1200
  # A column runs one spec; a list there would only fail later, at its first dispatch.
1174
1201
  case "$dw" in *,*) die "task '$id': the dwarf column names one spec, not a list ('$dw'); pool models with a --dwarf flag" ;; esac
1175
1202
  case "$qa" in *,*) die "task '$id': the qa column names one spec, not a list ('$qa'); pool reviewers with a --qa flag" ;; esac
1176
1203
  printf '%s\t%s\t%s\t%s\t%s\t%s\t%s\n' "$id" "$deps" "$diff" "$files" "$dw" "$qa" "$title" >> "$tmp"
1177
1204
  done < "$T"
1205
+ [ "$unassigned" -eq 0 ] || cp "$T" "$orig_tasks"
1178
1206
  mv "$tmp" "$T"
1179
1207
  # Which cells routing filled in, so a re-plan under another profile replaces those and no others.
1180
1208
  # Kept current through a --no-profile re-plan too, once a profile has recorded any.
1181
- if [ -f "$PLAN/profile.json" ] || [ -f "$PLAN/routed.json" ]; then
1209
+ if [ "$unassigned" -eq 0 ] && { [ -f "$PLAN/profile.json" ] || [ -f "$PLAN/routed.json" ]; }; then
1182
1210
  forge_profile_py routed "$PLAN" 2>/dev/null || true
1183
1211
  fi
1184
1212
 
@@ -1239,6 +1267,10 @@ EOF
1239
1267
  forge_groups_plan "$PLAN" "$GRP_SRC" "$GRP_REVIEW" "$GRP_MAX"
1240
1268
 
1241
1269
  render_table "$PLAN"
1270
+ if [ -n "$qa_kept_msg" ]; then
1271
+ echo "note: --qa left existing reviewer(s) unchanged on: $qa_kept_msg (set qa to '-' in tasks.tsv to let --qa fill them)"
1272
+ echo
1273
+ fi
1242
1274
  # What the gates did, from plan-gates.json: files and deps they added, prompts and
1243
1275
  # requirements still flagged. Prints nothing when no gate recorded anything.
1244
1276
  python3 "$SKILL_DIR/scripts/forge-plan-check.py" gates "$PLAN" 2>/dev/null || true
@@ -1253,6 +1285,7 @@ EOF
1253
1285
  forge_ui_launch "$PLAN"
1254
1286
 
1255
1287
  if [ "$unassigned" -gt 0 ]; then
1288
+ mv -f "$orig_tasks" "$T"
1256
1289
  note ""
1257
1290
  note "$unassigned task(s) are UNASSIGNED: their difficulty tier has no --dwarf-<tier>"
1258
1291
  note "rule and there is no plain --dwarf fallback. Assign them before running —"
@@ -1428,23 +1461,25 @@ EOF
1428
1461
  echo "QA effort: high where a reviewer spec names none (forge-dispatch.sh's default; planning stays at xhigh)"
1429
1462
  fi
1430
1463
  echo
1431
- local w id dws starred=0
1464
+ local w id dws starred=0 id_w pad
1465
+ id_w="$(id_col_width "$T")"
1466
+ printf -v pad '%*s' $((id_w + 3)) ''
1432
1467
  for w in $(awk -F'\t' '{print $1}' "$W" | sort -un); do
1433
1468
  local cnt; cnt="$(awk -F'\t' -v w="$w" '$1==w' "$W" | wc -l | tr -d ' ')"
1434
1469
  echo "wave $w ($cnt parallel)"
1435
- printf ' %-14s %-7s %-24s %-14s %s\n' id diff dwarf qa files
1470
+ printf ' %-*s %-7s %-24s %-14s %s\n' "$id_w" id diff dwarf qa files
1436
1471
  for id in $(awk -F'\t' -v w="$w" '$1==w {print $2}' "$W"); do
1437
1472
  dws="$(field "$T" "$id" dwarf)"
1438
1473
  if [ -s "$PLAN/tasks/$id/route.explored" ] && [ "$(cat "$PLAN/tasks/$id/route.explored")" = "$dws" ]; then
1439
1474
  dws="$dws*"; starred=1
1440
1475
  fi
1441
- printf ' %-14s %-7s %-24s %-14s %s\n' \
1442
- "$id" "$(field "$T" "$id" difficulty)" "$dws" \
1476
+ printf ' %-*s %-7s %-24s %-14s %s\n' \
1477
+ "$id_w" "$id" "$(field "$T" "$id" difficulty)" "$dws" \
1443
1478
  "$(field "$T" "$id" qa)" "$(field "$T" "$id" files)"
1444
1479
  # The approach is shown here because this gate is the only moment a human can
1445
1480
  # change the plan for free. After dispatch, changing it costs a whole run.
1446
1481
  if [ -s "$PLAN/tasks/$id/approach.md" ]; then
1447
- sed 's/^/ | /' "$PLAN/tasks/$id/approach.md"
1482
+ sed "s/^/${pad}| /" "$PLAN/tasks/$id/approach.md"
1448
1483
  fi
1449
1484
  done
1450
1485
  echo
@@ -1593,12 +1628,14 @@ write_capsule() { # write_capsule <plan> <id> <role>
1593
1628
  echo "Files this task owns: $(field "$T" "$me" files)"
1594
1629
  echo
1595
1630
  echo "## Run status"
1596
- printf '%-14s %-7s %-9s %s\n' id diff status files
1631
+ local id_w
1632
+ id_w="$(id_col_width "$T")"
1633
+ printf '%-*s %-7s %-11s %s\n' "$id_w" id diff status files
1597
1634
  for id in $(all_ids "$T"); do
1598
1635
  if [ "$id" = "$me" ]; then st="THIS ONE"
1599
1636
  elif [ -s "$PLAN/tasks/$id/reviewed.commit" ] && git -C "$(cat "$PLAN/repo")" merge-base --is-ancestor "$(cat "$PLAN/tasks/$id/reviewed.commit")" "$(cat "$PLAN/tasks/$me/base_ref")"; then st=MERGED
1600
1637
  else st="NOT IN BASE"; fi
1601
- printf '%-14s %-7s %-9s %s\n' "$id" "$(field "$T" "$id" difficulty)" "$st" "$(field "$T" "$id" files)"
1638
+ printf '%-*s %-7s %-11s %s\n' "$id_w" "$id" "$(field "$T" "$id" difficulty)" "$st" "$(field "$T" "$id" files)"
1602
1639
  done
1603
1640
  echo
1604
1641
  echo "## Ground rules"
@@ -1787,6 +1824,35 @@ record_dispatched_inputs() { # record_dispatched_inputs <tdir>
1787
1824
  done
1788
1825
  }
1789
1826
 
1827
+ # Brief inputs the last completed review judged (#209), written in reverse order so
1828
+ # prompt.reviewed's presence marks the snapshot complete.
1829
+ record_reviewed_inputs() { # record_reviewed_inputs <tdir> <thr>
1830
+ local tdir="$1" thr="${2:-}" f tmp
1831
+ tmp="$tdir/.approach.reviewed.tmp"
1832
+ if [ -f "$tdir/approach.md" ]; then cp "$tdir/approach.md" "$tmp" || { rm -f "$tmp"; return 1; }
1833
+ else : > "$tmp" || return 1; fi
1834
+ mv "$tmp" "$tdir/approach.reviewed" || { rm -f "$tmp"; return 1; }
1835
+ tmp="$tdir/.qa.reviewed.threshold.tmp"
1836
+ printf '%s\n' "$thr" > "$tmp" && mv "$tmp" "$tdir/qa.reviewed.threshold" || { rm -f "$tmp"; return 1; }
1837
+ tmp="$tdir/.prompt.reviewed.tmp"
1838
+ if [ -f "$tdir/prompt.md" ]; then cp "$tdir/prompt.md" "$tmp" || { rm -f "$tmp"; return 1; }
1839
+ else : > "$tmp" || return 1; fi
1840
+ mv "$tmp" "$tdir/prompt.reviewed" || { rm -f "$tmp"; return 1; }
1841
+ }
1842
+
1843
+ brief_changed_since_review() { # brief_changed_since_review <tdir> <thr> -> 0 when changed
1844
+ local tdir="$1" thr="${2:-}" f cur
1845
+ [ -f "$tdir/prompt.reviewed" ] || return 1
1846
+ for f in prompt approach; do
1847
+ cur="$tdir/$f.md"; [ -f "$cur" ] || cur=/dev/null
1848
+ cmp -s "$tdir/$f.reviewed" "$cur" || return 0
1849
+ done
1850
+ if [ -f "$tdir/qa.reviewed.threshold" ]; then
1851
+ [ "$(cat "$tdir/qa.reviewed.threshold" 2>/dev/null)" = "$thr" ] || return 0
1852
+ fi
1853
+ return 1
1854
+ }
1855
+
1790
1856
  # Whether the planner edited prompt.md or approach.md while the attempt ran (#150). Returns 0 when it did:
1791
1857
  # the attempt is then STALE, written to stale.diff and control.log, and the caller stops before any review.
1792
1858
  # Returns 1 when nothing changed, or when the attempt predates the .dispatched copies (no check possible).
@@ -1976,7 +2042,7 @@ do_task_body() (
1976
2042
  base="$(git -C "$(cat "$PLAN/wt_root")/_integration" rev-parse HEAD)"; printf '%s\n' "$base" > "$tdir/base_ref"
1977
2043
  fi
1978
2044
 
1979
- local dw qa yd yq rc ft_dwarf ft_qa
2045
+ local dw qa yd yq rc ft_dwarf ft_qa qa_thr
1980
2046
  dw="$(field "$T" "$id" dwarf)"; qa="$(field "$T" "$id" qa)"
1981
2047
  yd=""; yq=""
1982
2048
  [ -f "$PLAN/yolo_dwarf" ] && yd="--yolo"
@@ -1984,6 +2050,8 @@ do_task_body() (
1984
2050
  # Empty when the role is not listed, so the recorded command line is unchanged.
1985
2051
  ft_dwarf="$(forge_fast_tier "$PLAN" dwarf)"
1986
2052
  ft_qa="$(forge_fast_tier "$PLAN" qa)"
2053
+ # Read once per attempt: governs brief-change re-review (#209), the QA prompt, and qa_gate.
2054
+ qa_thr="$(qa_threshold_for "$PLAN" "$id")"
1987
2055
 
1988
2056
  if ! ensure_worktree "$REPO" "$wt" "$br" "$base" "$tdir" "$PLAN" "$id"; then
1989
2057
  echo ERROR > "$tdir/status"
@@ -2143,18 +2211,22 @@ do_task_body() (
2143
2211
  fi
2144
2212
  # A bounced attempt (retry_findings.source `bounce`) was never reviewed, so a retry that keeps
2145
2213
  # its code is reviewed rather than refused as identical: the refusal is for a diff a review
2146
- # already judged.
2214
+ # already judged. The same applies when the brief or threshold changed since that review (#209).
2147
2215
  if [ -s "$tdir/changes.prev.diff" ] && cmp -s "$tdir/changes.diff" "$tdir/changes.prev.diff" \
2148
2216
  && [ "$(cat "$tdir/retry_findings.source" 2>/dev/null)" != bounce ]; then
2149
- # A retry its CLI cancelled before it changed anything did not keep the code on purpose.
2150
- if grep -qx 'class=cancelled' "$tdir/dwarf.infra" 2>/dev/null; then
2151
- infra_stop "$tdir" "$id" dwarf "$attempt"; return 8
2217
+ if brief_changed_since_review "$tdir" "$qa_thr"; then
2218
+ note "$id: brief changed since the last review — reviewing the unchanged diff against the updated brief"
2219
+ else
2220
+ # A retry its CLI cancelled before it changed anything did not keep the code on purpose.
2221
+ if grep -qx 'class=cancelled' "$tdir/dwarf.infra" 2>/dev/null; then
2222
+ infra_stop "$tdir" "$id" dwarf "$attempt"; return 8
2223
+ fi
2224
+ echo FAIL > "$tdir/status"
2225
+ : > "$tdir/noretry"
2226
+ echo "The retry changed nothing: the diff is byte-identical to the previous attempt." \
2227
+ > "$tdir/qa.last"
2228
+ note "$id: retry produced no new changes — not re-reviewing identical code"; return 1
2152
2229
  fi
2153
- echo FAIL > "$tdir/status"
2154
- : > "$tdir/noretry"
2155
- echo "The retry changed nothing: the diff is byte-identical to the previous attempt." \
2156
- > "$tdir/qa.last"
2157
- note "$id: retry produced no new changes — not re-reviewing identical code"; return 1
2158
2230
  fi
2159
2231
 
2160
2232
  if ! git -C "$wt" diff --cached --quiet "$base" -- .forge; then
@@ -2232,8 +2304,7 @@ do_task_body() (
2232
2304
  echo "$review_fp" > "$tdir/review.fingerprint"
2233
2305
 
2234
2306
  forge_metric_phase preparation
2235
- local qa_thr rs_on=0
2236
- qa_thr="$(qa_threshold_for "$PLAN" "$id")"
2307
+ local rs_on=0
2237
2308
  # Read once per round, like the threshold: continuing the earlier reviewer's session is an
2238
2309
  # opt-in experiment (plan --reviewer-session), and a round never changes its mind midway.
2239
2310
  [ -f "$PLAN/reviewer_session" ] && rs_on=1
@@ -2464,6 +2535,7 @@ for r in json.load(sys.stdin):
2464
2535
  # FAIL. qa_thr is the value the review prompt was built with, so the prompt and the gate of
2465
2536
  # one attempt agree. Before record_attempt, so attempts.tsv shows the gated status.
2466
2537
  qa_gate "$PLAN" "$id" "$tdir" "$verdict" "$qa_thr"
2538
+ record_reviewed_inputs "$tdir" "$qa_thr" || true
2467
2539
  return 0
2468
2540
  )
2469
2541
 
@@ -2521,7 +2593,7 @@ merge_task() { # merge_task <plan> <id> -> 0 merged, 1 conflicted
2521
2593
  (cd "$int_wt" && git merge --abort >/dev/null 2>&1)
2522
2594
  echo CONFLICT > "$PLAN/tasks/$id/status"
2523
2595
  forge_dataset_event merge --dir "$PLAN" --task "$id" --set status=CONFLICT --set commit="$reviewed" \
2524
- --set conflicts="$(tr '\n' ' ' < "$tdir/conflict.files" 2>/dev/null)"
2596
+ --set conflicts="$(tr '\n' ' ' 2>/dev/null < "$tdir/conflict.files")"
2525
2597
  return 1
2526
2598
  }
2527
2599
 
@@ -2591,13 +2663,14 @@ PY
2591
2663
  }
2592
2664
 
2593
2665
  report_untested() { # report_untested <plan> <id>...: verdicts that rest on reading alone (#117)
2594
- local plan="$1" id tests_note untested=0; shift
2666
+ local plan="$1" id tests_note untested=0 id_w; shift
2667
+ id_w="$(id_col_width "$plan/tasks.tsv")"
2595
2668
  for id in "$@"; do
2596
2669
  tests_note="$(forge_tests_note "$plan/tasks/$id/qa.last")"
2597
2670
  if [ -n "$tests_note" ]; then
2598
2671
  [ "$untested" = 0 ] && echo "reviews whose tests could not run:"
2599
2672
  untested=1
2600
- printf ' %-14s %s\n' "$id" "$tests_note"
2673
+ printf ' %-*s %s\n' "$id_w" "$id" "$tests_note"
2601
2674
  fi
2602
2675
  done
2603
2676
  [ "$untested" = 0 ] || echo
@@ -2841,8 +2914,7 @@ do_retry() {
2841
2914
  write_results "$PLAN"
2842
2915
  echo
2843
2916
  # 14 covers NEEDS_DECISION; 9 pushes the branch column out for IMPLEMENTED (11) too.
2844
- printf ' %-14s %-14s %s\n' id status branch
2845
- awk -F'\t' '{printf " %-14s %-14s %s\n", $1, $2, $3}' "$PLAN/results.tsv"
2917
+ render_results_table "$PLAN"
2846
2918
  run_report_extras "$PLAN"
2847
2919
  report_decisions "$PLAN"
2848
2920
  [ "$(task_status "$PLAN" "$id")" = "MERGED" ] || return 5
@@ -2871,16 +2943,28 @@ verify_group_stop() { # TERM the verify command's group; KILL it after FORGE_VER
2871
2943
  # Until the guard's setsid there is no group: the TERM goes to the guard itself, which dies
2872
2944
  # of it before it starts the command. A group that forms all the same gets its TERM from
2873
2945
  # the timer.
2874
- kill -TERM -- "-$group" 2>/dev/null || { termed=0; kill -TERM "$group" 2>/dev/null; }
2946
+ if forge_is_windows && [ -r "/proc/$group/winpid" ]; then
2947
+ forge_kill_group "$group" TERM
2948
+ kill -TERM "$group" 2>/dev/null || true
2949
+ else
2950
+ kill -TERM -- "-$group" 2>/dev/null || { termed=0; kill -TERM "$group" 2>/dev/null; }
2951
+ fi
2875
2952
  # The timer polls in short naps rather than sleeping the whole grace in one: it ends by
2876
2953
  # itself within a nap of the group's last member, and a long sleep left behind would hold
2877
2954
  # the plan lock it inherited.
2878
2955
  ( trap - TERM INT
2879
2956
  ticks=$((FORGE_VERIFY_GRACE * 10))
2880
- while kill -0 -- "-$group" 2>/dev/null || { [ "$termed" = 0 ] && kill -0 "$group" 2>/dev/null; }; do
2957
+ while kill -0 -- "-$group" 2>/dev/null || { [ "$termed" = 0 ] && kill -0 "$group" 2>/dev/null; } || { forge_is_windows && [ -r "/proc/$group/winpid" ] && kill -0 "$group" 2>/dev/null; }; do
2881
2958
  if [ "$termed" = 0 ] && kill -TERM -- "-$group" 2>/dev/null; then termed=1; fi
2882
2959
  if [ "$ticks" -le 0 ]; then
2883
- if [ "$termed" = 1 ]; then kill -KILL -- "-$group" 2>/dev/null; else kill -KILL "$group" 2>/dev/null; fi
2960
+ if forge_is_windows && [ -r "/proc/$group/winpid" ]; then
2961
+ forge_kill_group "$group" KILL
2962
+ kill -KILL "$group" 2>/dev/null
2963
+ elif [ "$termed" = 1 ]; then
2964
+ kill -KILL -- "-$group" 2>/dev/null
2965
+ else
2966
+ kill -KILL "$group" 2>/dev/null
2967
+ fi
2884
2968
  break
2885
2969
  fi
2886
2970
  sleep 0.1
@@ -2895,20 +2979,25 @@ verify_signal() { # trap handler of a stoppable verification
2895
2979
  }
2896
2980
 
2897
2981
  verify_exec() { # verify_exec <checkout> <command> <log> [grace seconds, default 5] -> the command's exit code, 130 when stopped
2898
- local wt="$1" cmd="$2" log="$3" rc=0 group deadline
2982
+ local wt="$1" cmd="$2" log="$3" rc=0 group deadline guard_py="$SKILL_DIR/scripts/forge-guard.py"
2899
2983
  if [ "${FORGE_RUN_STOPPABLE:-0}" != 1 ]; then
2900
2984
  (cd "$wt" && /bin/bash -c "$cmd") > "$log" 2>&1
2901
2985
  return $?
2902
2986
  fi
2903
2987
  FORGE_VERIFY_GRACE="${4:-5}"
2904
2988
  [ "$FORGE_VERIFY_STOP" = 1 ] && return 130
2989
+ ! forge_is_windows || guard_py="$(forge_host_path "$guard_py")"
2905
2990
  # A background job ignores SIGINT and SIGQUIT, and the command would inherit that; the
2906
2991
  # wrapper restores both before the guard puts the command in a session of its own.
2907
- (cd "$wt" && exec python3 -c 'import os, signal, sys
2908
- for name in (signal.SIGINT, signal.SIGQUIT):
2909
- signal.signal(name, signal.SIG_DFL)
2992
+ (cd "$wt" && { ! forge_is_windows || export MSYS_NO_PATHCONV=1; } && exec python3 -c 'import os, signal, subprocess, sys
2993
+ for sig_name in ("SIGINT", "SIGQUIT"):
2994
+ sig = getattr(signal, sig_name, None)
2995
+ if sig is not None:
2996
+ signal.signal(sig, signal.SIG_DFL)
2997
+ if os.name == "nt":
2998
+ sys.exit(subprocess.run([sys.executable] + sys.argv[1:]).returncode)
2910
2999
  os.execv(sys.executable, [sys.executable] + sys.argv[1:])' \
2911
- "$SKILL_DIR/scripts/forge-guard.py" session -- /bin/bash -c "$cmd") > "$log" 2>&1 <&0 &
3000
+ "$guard_py" session -- /bin/bash -c "$cmd") > "$log" 2>&1 <&0 &
2912
3001
  group=$!
2913
3002
  FORGE_VERIFY_GROUP="$group"
2914
3003
  [ "$FORGE_VERIFY_STOP" = 1 ] && verify_group_stop
@@ -2959,7 +3048,8 @@ verify_result_body() { # plan, checkout, artifact directory[, fixed source]
2959
3048
  forge_metric_begin "$out" verification
2960
3049
  forge_metric_phase verification
2961
3050
  repo="$(cat "$plan/repo")"
2962
- rm -f "$out/verification.flaky" "$out/verification.retry.log" "$out/verification.failing.log" "$out/verification.coverage.txt" \
3051
+ rm -f "$out/verification.status" "$out/verification.exit" \
3052
+ "$out/verification.flaky" "$out/verification.retry.log" "$out/verification.failing.log" "$out/verification.coverage.txt" \
2963
3053
  "$out/verification.runs.tsv" "$out"/verification.run-*.log "$out/verification.commit" \
2964
3054
  "$out/verification.lanes.json" "$out"/verification.lane.*.log
2965
3055
  # The commit being verified, named before any early return, so every outcome (FAIL and
@@ -3211,9 +3301,32 @@ forge_brief_start() { # forge_brief_start <plan>
3211
3301
  PYTHONPATH="$SKILL_DIR/scripts${PYTHONPATH:+:$PYTHONPATH}" python3 -c \
3212
3302
  'import sys, forge_brief; forge_brief.note_missing_groups(sys.argv[1])' "$plan" || true
3213
3303
  python3 - "$plan" "$SKILL_DIR/scripts/forge-brief.py" <<'PY' || { note "brief: could not start the question writer"; return 0; }
3214
- import os, subprocess, sys
3304
+ import os, subprocess, sys, time
3215
3305
  plan, script = sys.argv[1], sys.argv[2]
3216
3306
  pidfile = os.path.join(plan, 'brief.pid')
3307
+ if not hasattr(os, 'fork'):
3308
+ worker = (
3309
+ 'import os, subprocess, sys\n'
3310
+ 'plan, script, pidfile = sys.argv[1], sys.argv[2], sys.argv[3]\n'
3311
+ 'try:\n'
3312
+ ' with open(pidfile, "w") as handle:\n'
3313
+ ' handle.write("%d\\n" % os.getpid())\n'
3314
+ ' subprocess.run([sys.executable, script, "write", plan], stdin=subprocess.DEVNULL)\n'
3315
+ 'finally:\n'
3316
+ ' try: os.unlink(pidfile)\n'
3317
+ ' except OSError: pass\n'
3318
+ )
3319
+ flags = getattr(subprocess, 'CREATE_NEW_PROCESS_GROUP', 0) | getattr(subprocess, 'DETACHED_PROCESS', 0)
3320
+ with open(os.path.join(plan, 'brief.out'), 'ab') as out:
3321
+ proc = subprocess.Popen(
3322
+ [sys.executable, '-c', worker, plan, script, pidfile],
3323
+ stdin=subprocess.DEVNULL, stdout=out, stderr=out,
3324
+ creationflags=flags, close_fds=True,
3325
+ )
3326
+ deadline = time.monotonic() + 2.0
3327
+ while time.monotonic() < deadline and not os.path.exists(pidfile) and proc.poll() is None:
3328
+ time.sleep(0.02)
3329
+ sys.exit(0)
3217
3330
  ready, signal_ready = os.pipe()
3218
3331
  child = os.fork()
3219
3332
  if child:
@@ -3445,7 +3558,7 @@ do_run() {
3445
3558
  # Durable, beside the repo — never TMPDIR. A temp worktree root has destroyed
3446
3559
  # real work here before: isolated worktrees are never pushed, so when the root
3447
3560
  # goes, the only copy of that work goes with it.
3448
- wt_root="$(cd "$REPO/.." && pwd)/.forge-worktrees/$run_id"
3561
+ wt_root="$(forge_host_path "$(cd "$REPO/.." && pwd)/.forge-worktrees/$run_id")"
3449
3562
  echo "$wt_root" > "$PLAN/wt_root"
3450
3563
  # Sibling, not parent: git refs are files, so a branch `forge/<run>` makes
3451
3564
  # `forge/<run>/<task>` impossible ("cannot lock ref ... exists; cannot create").
@@ -3581,8 +3694,7 @@ do_run() {
3581
3694
  echo "results (integration branch: $int_br)"
3582
3695
  echo "artifacts: $PLAN/tasks/<id>/{dwarf,qa}.{last,log}; results: $PLAN/results.tsv"
3583
3696
  # 14 covers NEEDS_DECISION; 9 pushes the branch column out for IMPLEMENTED (11) too.
3584
- printf ' %-14s %-14s %s\n' id status branch
3585
- awk -F'\t' '{printf " %-14s %-14s %s\n", $1, $2, $3}' "$PLAN/results.tsv"
3697
+ render_results_table "$PLAN"
3586
3698
  echo
3587
3699
  if [ -n "$retro_line" ]; then printf '%s\n\n' "$retro_line"; fi
3588
3700
  run_report_extras "$PLAN"
@@ -3594,12 +3706,13 @@ do_run() {
3594
3706
 
3595
3707
  # Undeclared files are reported here rather than buried in a task log, because
3596
3708
  # this is the list that explains any CONFLICT above.
3597
- local drift=0
3709
+ local drift=0 id_w
3710
+ id_w="$(id_col_width "$T")"
3598
3711
  for id in $(all_ids "$T"); do
3599
3712
  if [ -s "$PLAN/tasks/$id/drift.txt" ]; then
3600
3713
  [ "$drift" = 0 ] && echo "scope drift (touched files the task did not declare):"
3601
3714
  drift=1
3602
- printf ' %-14s %s\n' "$id" "$(tr '\n' ' ' < "$PLAN/tasks/$id/drift.txt")"
3715
+ printf ' %-*s %s\n' "$id_w" "$id" "$(tr '\n' ' ' < "$PLAN/tasks/$id/drift.txt")"
3603
3716
  fi
3604
3717
  done
3605
3718
  [ "$drift" = 1 ] && echo
@@ -4035,7 +4148,7 @@ fi
4035
4148
  case "$CMD" in
4036
4149
  # `combine` takes a plan dir that does not exist yet and locks its sources itself.
4037
4150
  run|retry|integrate|accept|adopt|review|split|attribute)
4038
- if [ "${FORGE_PLAN_LOCK:-}" != "${1:-}" ]; then
4151
+ if [ "$(forge_posix_path "${FORGE_PLAN_LOCK:-}")" != "${1:-}" ]; then
4039
4152
  exec python3 "$SKILL_DIR/scripts/forge-schedule.py" lock "$SELF" "$CMD" "$@"
4040
4153
  fi ;;
4041
4154
  esac
@@ -47,7 +47,7 @@ def _dataset(hook: str, *args) -> None:
47
47
 
48
48
 
49
49
  def capability_help(cache: str, registry: str, recipe: str, command: list[str]) -> str:
50
- binary = Path(command[0]).resolve()
50
+ binary, exec_command = forge_proc.resolve_win_command(command)
51
51
  stat = binary.stat()
52
52
  identity = [
53
53
  str(binary), stat.st_dev, stat.st_ino, stat.st_size,
@@ -61,7 +61,7 @@ def capability_help(cache: str, registry: str, recipe: str, command: list[str])
61
61
  path = root / key
62
62
  if path.exists():
63
63
  return path.read_text()
64
- result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
64
+ result = subprocess.run(exec_command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
65
65
  if result.returncode:
66
66
  raise RuntimeError(result.stdout.decode(errors='replace'))
67
67
  temporary = root / (key + '.' + uuid.uuid4().hex)
@@ -709,6 +709,12 @@ def schedule(script: str, plan: str, capacity: int, retry_failed: int = 0,
709
709
  raise ValueError('task ' + GROUP_KEY + g.id + ' clashes with group ' + g.id)
710
710
  group_of = {m: g.id for g in rgroups.values() for m in g.members} # member -> its review group
711
711
  active = {} # task id, or GROUP_KEY + gid for a running group review
712
+ task_jobs: dict[str, forge_proc.ProcessJob] = {}
713
+
714
+ def _track_job(key: str, pid: int) -> None:
715
+ job = forge_proc.ProcessJob()
716
+ if job.attach(pid):
717
+ task_jobs[key] = job
712
718
  pending = list(tasks)
713
719
  interrupted = False
714
720
  group_again = set() # groups to review once more whatever their status says (a resume, an UNKNOWN)
@@ -1591,6 +1597,7 @@ def schedule(script: str, plan: str, capacity: int, retry_failed: int = 0,
1591
1597
  stdout=log, stderr=subprocess.STDOUT, **forge_proc.popen_group_kwargs(),
1592
1598
  )
1593
1599
  active[GROUP_KEY + gid] = process, log
1600
+ _track_job(GROUP_KEY + gid, process.pid)
1594
1601
  group_again.discard(gid)
1595
1602
  print('forge: reviewing group ' + gid + ' (' + ', '.join(rgroups[gid].members) + ')',
1596
1603
  file=sys.stderr, flush=True)
@@ -1697,6 +1704,10 @@ def schedule(script: str, plan: str, capacity: int, retry_failed: int = 0,
1697
1704
  into.add(name)
1698
1705
  log.close()
1699
1706
  del active[name]
1707
+ job = task_jobs.pop(name, None)
1708
+ if job is not None:
1709
+ job.disarm()
1710
+ job.close()
1700
1711
  if name.startswith(GROUP_KEY) and name not in tasks:
1701
1712
  gid = name[len(GROUP_KEY):]
1702
1713
  if os.environ.get('FORGE_OUTPUT') == 'full':
@@ -1832,6 +1843,7 @@ def schedule(script: str, plan: str, capacity: int, retry_failed: int = 0,
1832
1843
 
1833
1844
  signal.signal(signal.SIGTERM, stop)
1834
1845
  signal.signal(signal.SIGINT, stop)
1846
+ forge_proc.install_signal(forge_proc.SIGBREAK, stop)
1835
1847
  try:
1836
1848
  live_start(plan, tasks, retry_failed, infra_retries, rgroups)
1837
1849
  summaries_on_change()
@@ -1971,7 +1983,7 @@ def schedule(script: str, plan: str, capacity: int, retry_failed: int = 0,
1971
1983
  continue
1972
1984
  root = plan / 'tasks' / name
1973
1985
  if not (root / 'base_ref').exists():
1974
- worktree = Path((plan / 'wt_root').read_text().strip()) / '_integration'
1986
+ worktree = Path(forge_posix.host_path((plan / 'wt_root').read_text().strip())) / '_integration'
1975
1987
  base = subprocess.check_output(['git', '-C', str(worktree), 'rev-parse', 'HEAD'])
1976
1988
  (root / 'base_ref').write_bytes(base)
1977
1989
  log = open(root / 'task.out', 'ab')
@@ -1987,6 +1999,7 @@ def schedule(script: str, plan: str, capacity: int, retry_failed: int = 0,
1987
1999
  stdout=log, stderr=subprocess.STDOUT, env=env, **forge_proc.popen_group_kwargs(),
1988
2000
  )
1989
2001
  active[name] = process, log
2002
+ _track_job(name, process.pid)
1990
2003
  pending.remove(name)
1991
2004
  print('forge: dispatched ' + name + ' -> ' + str(root), file=sys.stderr, flush=True)
1992
2005
  if not active and graceful:
@@ -2045,6 +2058,10 @@ def schedule(script: str, plan: str, capacity: int, retry_failed: int = 0,
2045
2058
  for name, (process, log) in stopping:
2046
2059
  if name in waiting:
2047
2060
  forge_proc.kill_tree(process.pid, force=True)
2061
+ job = task_jobs.pop(name, None)
2062
+ if job is not None:
2063
+ job.terminate()
2064
+ job.close()
2048
2065
  try:
2049
2066
  process.wait(timeout=5)
2050
2067
  except subprocess.TimeoutExpired:
@@ -48,6 +48,10 @@
48
48
  set -uo pipefail
49
49
 
50
50
  SKILL_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
51
+ # Windows: re-run inside MSYS2 when started from Git Bash (no-op elsewhere).
52
+ . "$SKILL_DIR/scripts/forge-win.sh"
53
+ source "$SKILL_DIR/scripts/forge-lib-env.sh"
54
+ forge_ensure_python3
51
55
  DISPATCH="$SKILL_DIR/scripts/forge-dispatch.sh"
52
56
  MEMORY="$SKILL_DIR/scripts/forge-memory.sh"
53
57
  source "$SKILL_DIR/scripts/forge-artifact.sh"
@@ -229,7 +233,7 @@ RUN="$(cd "$RUN" && pwd)"
229
233
  # The frozen copy, atomically. Only the process that holds the run's lock writes it (a refused
230
234
  # second start, or a dry run, must not change what an active run froze): the first pass above
231
235
  # only read and checked, and the re-exec under the lock chooses again from the same arguments.
232
- if [ "$DRY" != 1 ] && [ "${FORGE_SOLO_LOCK:-}" = "$RUN" ]; then
236
+ if [ "$DRY" != 1 ] && [ "$(forge_posix_path "${FORGE_SOLO_LOCK:-}")" = "$RUN" ]; then
233
237
  forge_profile_py solo "$RUN" --repo "$REPO" --no-validate --write ${pf_args[@]+"${pf_args[@]}"} >/dev/null || exit $?
234
238
  fi
235
239
  [ -z "$PF_LINE" ] || [ -n "${FORGE_SOLO_LOCK:-}" ] || echo "$PF_LINE"
@@ -239,7 +243,7 @@ fi
239
243
  REPO="$(cd "$REPO" && pwd)"
240
244
  # Before any decision-model step: the privacy floor and the run budget read these.
241
245
  [ "$JEV_OPTS" = 1 ] && forge_decide_env "$REPO" "$RUN"
242
- if [ "$DRY" != 1 ] && [ "${FORGE_SOLO_LOCK:-}" != "$RUN" ]; then
246
+ if [ "$DRY" != 1 ] && [ "$(forge_posix_path "${FORGE_SOLO_LOCK:-}")" != "$RUN" ]; then
243
247
  exec python3 "$SKILL_DIR/scripts/forge-fractal.py" _lock "$RUN" "$0" "${ORIGINAL_ARGS[@]}"
244
248
  fi
245
249
  # After the lock re-exec, so the process that dispatches is the one that writes it.
@@ -259,7 +259,7 @@ class Context:
259
259
  def __init__(self, plan: Path):
260
260
  self.plan = plan
261
261
  self.repo = read(plan / 'repo')
262
- wt_root = read(plan / 'wt_root')
262
+ wt_root = forge_posix.host_path(read(plan / 'wt_root'))
263
263
  self.integration = os.path.join(wt_root, '_integration') if wt_root else ''
264
264
  rc, tip = git(self.integration, 'rev-parse', 'HEAD') if self.integration else (1, b'')
265
265
  self.tip = tip.decode().strip() if not rc else ''
@@ -2,6 +2,9 @@
2
2
  # Update the canonical checkout, then refresh each harness through the installer.
3
3
  set -uo pipefail
4
4
 
5
+ source "$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)/forge-lib-env.sh"
6
+ forge_ensure_python3
7
+
5
8
  main() {
6
9
  local source_dir dry=0 local_only=0 upstream remote branch before after changes
7
10
  source_dir="$(cd -P "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" || return 2
@@ -24,7 +27,9 @@ main() {
24
27
  fi
25
28
  echo "forge: update source: $source_dir"
26
29
  if [ "$local_only" = 0 ]; then
27
- if [ "$(git -C "$source_dir" rev-parse --show-toplevel 2>/dev/null)" != "$source_dir" ]; then
30
+ local git_top
31
+ git_top="$(git -C "$source_dir" rev-parse --show-toplevel 2>/dev/null || true)"
32
+ if [ "$(forge_posix_path "$git_top")" != "$(forge_posix_path "$source_dir")" ]; then
28
33
  case "$source_dir" in
29
34
  */node_modules/*)
30
35
  # @latest, because older npm updated a global package within ^version: never 0.7 -> 0.8.
@@ -856,6 +856,7 @@ def cmd_run(args: argparse.Namespace) -> int:
856
856
 
857
857
  signal.signal(signal.SIGTERM, interrupt)
858
858
  signal.signal(signal.SIGINT, interrupt)
859
+ forge_proc.install_signal(forge_proc.SIGBREAK, interrupt)
859
860
  return verification.run()
860
861
 
861
862