@giamme/forge 0.21.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 (165) hide show
  1. package/CHANGELOG.md +81 -0
  2. package/README.md +25 -15
  3. package/SKILL.md +137 -216
  4. package/VERSION +1 -1
  5. package/bin/forge.js +104 -0
  6. package/docs/README.md +2 -3
  7. package/docs/add-ons.md +5 -3
  8. package/docs/artifacts.md +17 -2
  9. package/docs/commands.md +85 -63
  10. package/docs/decomposed-runs.md +195 -21
  11. package/docs/development.md +12 -10
  12. package/docs/forge-ui.md +33 -4
  13. package/docs/install.md +127 -6
  14. package/docs/memory.md +6 -1
  15. package/docs/models.md +36 -10
  16. package/docs/reviews.md +50 -29
  17. package/docs/safety.md +27 -2
  18. package/docs/troubleshooting.md +8 -11
  19. package/forge +29 -4
  20. package/forge.cmd +56 -0
  21. package/package.json +6 -3
  22. package/references/dataset.md +10 -9
  23. package/references/decompose-integration.md +337 -0
  24. package/references/decompose-opt-in.md +527 -0
  25. package/references/decompose-recovery.md +569 -0
  26. package/references/decompose-review.md +256 -0
  27. package/references/decompose.md +99 -1606
  28. package/references/findings.md +68 -0
  29. package/references/harnesses.md +7 -12
  30. package/references/memory.md +13 -2
  31. package/references/planning.md +48 -18
  32. package/references/ripwire.md +38 -13
  33. package/references/runtime.md +22 -33
  34. package/references/setup.md +90 -0
  35. package/references/solo.md +13 -42
  36. package/references/ui.md +12 -5
  37. package/registry.tsv +40 -22
  38. package/scripts/forge-artifact.sh +148 -13
  39. package/scripts/forge-compare.py +5 -15
  40. package/scripts/forge-config.py +14 -1
  41. package/scripts/forge-contract.py +216 -53
  42. package/scripts/forge-control.py +781 -51
  43. package/scripts/forge-dispatch.sh +202 -42
  44. package/scripts/forge-du.py +13 -3
  45. package/scripts/forge-guard.py +137 -6
  46. package/scripts/forge-handoff.py +221 -39
  47. package/scripts/forge-install-ripwire.sh +100 -24
  48. package/scripts/forge-install.sh +100 -41
  49. package/scripts/forge-issues.py +6 -4
  50. package/scripts/forge-jev-options.sh +3 -5
  51. package/scripts/forge-lib-adopt.sh +169 -5
  52. package/scripts/forge-lib-attribute.sh +10 -3
  53. package/scripts/forge-lib-decompose.sh +454 -0
  54. package/scripts/forge-lib-env.sh +179 -0
  55. package/scripts/forge-lib-group.sh +9 -6
  56. package/scripts/forge-lib-plans.sh +38 -21
  57. package/scripts/forge-lib-review.sh +28 -8
  58. package/scripts/forge-lib-task.sh +263 -69
  59. package/scripts/forge-lib-verify.sh +59 -10
  60. package/scripts/forge-memory.sh +83 -4
  61. package/scripts/forge-metrics.sh +10 -3
  62. package/scripts/forge-parallel-options.sh +23 -4
  63. package/scripts/forge-parallel.sh +602 -217
  64. package/scripts/forge-plan-check.py +71 -8
  65. package/scripts/forge-planner.py +303 -17
  66. package/scripts/forge-pr.py +9 -1
  67. package/scripts/forge-prompt.py +2 -2
  68. package/scripts/forge-review-links.py +248 -0
  69. package/scripts/forge-ripwire.py +234 -16
  70. package/scripts/forge-route.py +19 -27
  71. package/scripts/forge-runs-rm.py +92 -21
  72. package/scripts/forge-runs.py +46 -5
  73. package/scripts/forge-runtime.py +39 -14
  74. package/scripts/forge-schedule.py +141 -33
  75. package/scripts/forge-setup-stale.py +236 -0
  76. package/scripts/forge-setup.py +804 -0
  77. package/scripts/forge-shadow.py +2 -20
  78. package/scripts/forge-solo-lock.py +46 -0
  79. package/scripts/forge-solo.sh +39 -58
  80. package/scripts/forge-sweep.py +3 -2
  81. package/scripts/forge-ui.py +8 -1
  82. package/scripts/forge-update.sh +8 -3
  83. package/scripts/forge-verify.py +17 -1
  84. package/scripts/forge-version.py +13 -1
  85. package/scripts/forge-watch.py +7 -2
  86. package/scripts/forge-win.sh +156 -0
  87. package/scripts/forge_brief/__init__.py +6 -1
  88. package/scripts/forge_brief/proposals.py +6 -1
  89. package/scripts/forge_dataset/__init__.py +1 -1
  90. package/scripts/forge_dataset/capture.py +0 -34
  91. package/scripts/forge_dataset/checks.py +0 -1
  92. package/scripts/forge_dataset/cli.py +5 -1
  93. package/scripts/forge_dataset/export.py +28 -6
  94. package/scripts/forge_dataset/facts.py +1 -2
  95. package/scripts/forge_dataset/forecast.py +1 -1
  96. package/scripts/forge_dataset/harvest.py +107 -7
  97. package/scripts/forge_dataset/importer.py +3 -2
  98. package/scripts/forge_dataset/pairs.py +3 -3
  99. package/scripts/forge_dataset/reviewers.py +4 -3
  100. package/scripts/forge_dataset/routing.py +6 -3
  101. package/scripts/forge_dataset/tiers.py +1 -1
  102. package/scripts/forge_decide/__init__.py +1 -1
  103. package/scripts/forge_decide/budget.py +12 -7
  104. package/scripts/forge_decide/profiles.py +11 -14
  105. package/scripts/forge_decide/replay.py +9 -4
  106. package/scripts/forge_decompose.py +987 -0
  107. package/scripts/forge_flock.py +17 -2
  108. package/scripts/forge_groups/review.py +6 -1
  109. package/scripts/forge_jev/__init__.py +1 -1
  110. package/scripts/forge_jev/cli.py +10 -1
  111. package/scripts/forge_jev/gates.py +10 -1
  112. package/scripts/forge_jev/verify.py +10 -2
  113. package/scripts/forge_legacy.py +86 -0
  114. package/scripts/forge_memory_home.py +57 -0
  115. package/scripts/forge_models.py +151 -0
  116. package/scripts/forge_posix.py +17 -0
  117. package/scripts/forge_prefs.py +138 -0
  118. package/scripts/forge_proc.py +108 -0
  119. package/scripts/forge_registry.py +2 -2
  120. package/scripts/forge_side/__init__.py +23 -4
  121. package/scripts/forge_storage.py +28 -15
  122. package/ui/README.md +22 -10
  123. package/ui/docs/api.md +121 -99
  124. package/ui/forge_ui/control.py +53 -16
  125. package/ui/forge_ui/export.py +0 -10
  126. package/ui/forge_ui/models.py +15 -2
  127. package/ui/forge_ui/projects.py +4 -1
  128. package/ui/forge_ui/reader.py +462 -60
  129. package/ui/forge_ui/server.py +0 -10
  130. package/ui/forge_ui/static/app.js +28 -9
  131. package/ui/forge_ui/static/checksview.js +12 -3
  132. package/ui/forge_ui/static/controls.js +147 -11
  133. package/ui/forge_ui/static/convo.js +5 -2
  134. package/ui/forge_ui/static/diffview.js +4 -5
  135. package/ui/forge_ui/static/panel.js +180 -77
  136. package/ui/forge_ui/static/projectsview.js +16 -2
  137. package/ui/forge_ui/static/runmodel.js +18 -4
  138. package/ui/forge_ui/static/scene3d.js +52 -31
  139. package/ui/forge_ui/static/settings.js +1 -1
  140. package/ui/forge_ui/static/storageview.js +2 -2
  141. package/ui/forge_ui/static/style.css +23 -6
  142. package/ui/forge_ui/static/worktreesview.js +8 -4
  143. package/ui/forge_ui/transcripts.py +6 -0
  144. package/ui/forge_ui/worktrees.py +13 -1
  145. package/docs/fractal.md +0 -181
  146. package/references/fractal-dashboard.md +0 -21
  147. package/references/fractal.md +0 -307
  148. package/scripts/forge-fractal-dispatch.sh +0 -4
  149. package/scripts/forge-fractal-options.sh +0 -54
  150. package/scripts/forge-fractal.py +0 -6
  151. package/scripts/forge-install-fractal.sh +0 -4
  152. package/scripts/forge_fractal/__init__.py +0 -88
  153. package/scripts/forge_fractal/bridge.py +0 -46
  154. package/scripts/forge_fractal/cli.py +0 -224
  155. package/scripts/forge_fractal/dashboard.css +0 -138
  156. package/scripts/forge_fractal/dashboard.html +0 -41
  157. package/scripts/forge_fractal/dashboard.js +0 -687
  158. package/scripts/forge_fractal/decomposition.py +0 -262
  159. package/scripts/forge_fractal/execution.py +0 -659
  160. package/scripts/forge_fractal/inspection.py +0 -261
  161. package/scripts/forge_fractal/install.py +0 -158
  162. package/scripts/forge_fractal/invocation.py +0 -95
  163. package/scripts/forge_fractal/pipeline.py +0 -125
  164. package/scripts/forge_fractal/selection.py +0 -180
  165. package/ui/forge_ui/fractal.py +0 -582
@@ -59,33 +59,15 @@ STOP_WAIT_S = 10
59
59
  PREPARE_TIMEOUT_S = 120
60
60
 
61
61
 
62
- def plan_is_fractal(plan: Path) -> bool:
63
- """True when this plan's saved selection says Fractal runs the dispatches."""
64
- try:
65
- data = json.loads((plan / 'fractal-selection.json').read_text())
66
- except (OSError, ValueError):
67
- return False
68
- return isinstance(data, dict) and bool(data.get('enabled'))
69
-
70
-
71
62
  def service_tier_args(plan: Path, role: str) -> list[str]:
72
63
  """`--service-tier fast` when <role> is a line of <plan>/fast, and nothing otherwise.
73
-
74
- Fractal dispatches through its own runner and does not take the option. A retry
75
- preflights before that runner is selected, so a plan whose selection is already on
76
- is the same case for every role it dispatches. A whole-run review is not one of them.
77
- Specs never change.
78
- """
79
- if os.environ.get('FORGE_FRACTAL_RUN'):
80
- return []
64
+ Specs never change."""
81
65
  try:
82
66
  text = (plan / 'fast').read_text()
83
67
  except OSError:
84
68
  return []
85
69
  if role not in [line.strip() for line in text.splitlines() if line.strip()]:
86
70
  return []
87
- if role != 'review' and plan_is_fractal(plan):
88
- return []
89
71
  return ['--service-tier', 'fast']
90
72
 
91
73
 
@@ -241,7 +223,7 @@ def run(args) -> int:
241
223
  parent = os.getppid()
242
224
  status, out, spec, why, review = 'skipped', None, None, None, None
243
225
  try:
244
- if os.environ.get('FORGE_FRACTAL_RUN') or not sampled(plan, args.task, args.attempt, rate_of(plan)):
226
+ if not sampled(plan, args.task, args.attempt, rate_of(plan)):
245
227
  return 0
246
228
  spec, why = pick(candidates(plan), args.qa)
247
229
  if not spec:
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env python3
2
+ """Take a solo run's lock, then run forge-solo.sh under it.
3
+
4
+ forge-solo-lock.py <run-dir> <script> [args...]
5
+
6
+ `<run-dir>/pipeline.lock` is held for the whole run: the re-executed script inherits the open
7
+ file, and FORGE_SOLO_LOCK names the run directory so it knows it is the one holding it. A second
8
+ run of the same directory, `forge runs rm` and `forge runs compact` find the lock busy. Exit 3
9
+ when another process holds it.
10
+ """
11
+ from __future__ import annotations
12
+
13
+ import os
14
+ import sys
15
+ from pathlib import Path
16
+
17
+ _SCRIPTS = str(Path(__file__).resolve().parent)
18
+ if _SCRIPTS not in sys.path:
19
+ sys.path.insert(0, _SCRIPTS)
20
+ import forge_flock as fcntl # noqa: E402
21
+ import forge_proc # noqa: E402
22
+
23
+
24
+ def main(argv: list) -> int:
25
+ if len(argv) < 2:
26
+ print(__doc__.strip(), file=sys.stderr)
27
+ return 2
28
+ run = argv[0]
29
+ try:
30
+ handle = (Path(run) / 'pipeline.lock').open('a')
31
+ fcntl.flock(handle, fcntl.LOCK_EX | fcntl.LOCK_NB)
32
+ except BlockingIOError:
33
+ print('forge: another forge-solo.sh run of ' + run + ' is still going; wait for it to end, '
34
+ 'or use a new run directory', file=sys.stderr)
35
+ return 3
36
+ except OSError as error:
37
+ print('forge: could not take the lock of ' + run + ': ' + str(error), file=sys.stderr)
38
+ return 3
39
+ os.set_inheritable(handle.fileno(), True)
40
+ forge_proc.exec_or_exit(forge_proc.bash_cmd(*argv[1:]), env=dict(os.environ, FORGE_SOLO_LOCK=run),
41
+ inherit_fds=True)
42
+ return 0
43
+
44
+
45
+ if __name__ == '__main__':
46
+ sys.exit(main(sys.argv[1:]))
@@ -19,7 +19,7 @@
19
19
  # forge-solo.sh <run-dir> --repo <dir> --dwarf <spec> [--qa <spec>]
20
20
  # [--approach <file>] [--yolo-dwarf] [--yolo-qa]
21
21
  # [--native-review] [--no-memory] [--timeout <s>] [--dry-run] [--ui]
22
- # [--fail-first] [--qa-threshold P0|P1|P2|P3|none]
22
+ # [--fail-first] [--qa-threshold P0|P1|P2|P3|none] [--qa-test-minutes N]
23
23
  # [--fast ROLES] dwarf, qa or none (planner, review and all are refused);
24
24
  # kept in <run-dir>/fast. none removes it; omitting it keeps it
25
25
  # [--profile NAME | --no-profile] a named profile (forge config profile list) picks
@@ -48,11 +48,14 @@
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"
54
58
  source "$SKILL_DIR/scripts/forge-metrics.sh"
55
- source "$SKILL_DIR/scripts/forge-fractal-options.sh"
56
59
  source "$SKILL_DIR/scripts/forge-ui-options.sh"
57
60
  source "$SKILL_DIR/scripts/forge-lib-task.sh"
58
61
  JEV_OPTS=0
@@ -63,8 +66,8 @@ ORIGINAL_ARGS=("$@")
63
66
  die() { printf 'forge: %s\n' "$1" >&2; exit "${2:-2}"; }
64
67
  note() { printf 'forge: %s\n' "$*" >&2; }
65
68
 
66
- # forge_metric_begin's EXIT trap calls this, before runtime finish and Fractal's
67
- # _outcome read status. Only this script defines it. It must not change the exit code.
69
+ # forge_metric_begin's EXIT trap calls this, before runtime finish reads status.
70
+ # Only this script defines it. It must not change the exit code.
68
71
  forge_metric_on_exit() {
69
72
  local rc="${1:-}" status="" word="" cls="" n=0 pick=""
70
73
  [ -n "${RUN:-}" ] || return 0
@@ -104,8 +107,6 @@ forge_metric_on_exit() {
104
107
 
105
108
  if [ "${1:-}" = --help ] || [ "${1:-}" = -h ]; then
106
109
  sed -n '18,47s/^# *//p' "$0"
107
- forge_fractal_help
108
- echo 'Explicit Fractal retry: repeat the original command with --retry.'
109
110
  exit 0
110
111
  fi
111
112
  RUN="${1:-}"; [ -n "$RUN" ] || die "usage: forge-solo.sh <run-dir> --repo <dir> --dwarf <spec> [--qa <spec>]"
@@ -116,15 +117,10 @@ shift
116
117
  forge_profile_py() { PYTHONPATH="$SKILL_DIR/scripts${PYTHONPATH:+:$PYTHONPATH}" python3 -m forge_decide.profiles "$@"; }
117
118
 
118
119
  OUTPUT=summary
119
- REPO="$PWD"; DWARF=""; QA="opus"; APPROACH=""; YD=""; YQ=""; NATIVE=""; TIMEOUT=""; DRY=0; FAIL_FIRST=0; QA_THR=
120
+ REPO="$PWD"; DWARF=""; QA="opus"; APPROACH=""; YD=""; YQ=""; NATIVE=""; TIMEOUT=""; DRY=0; FAIL_FIRST=0; QA_THR=; QA_TEST_MINS=
120
121
  FAST_GIVEN=0; FAST_PARSED=""; QA_GIVEN=0; PF_NAME=""; PF_NONE=0
121
122
  while [ $# -gt 0 ]; do
122
123
  case "$1" in
123
- --fractal) forge_fractal_flag on || exit $?; shift ;;
124
- --fractal-auto-decompose) forge_fractal_flag on || exit $?; FRACTAL_ARGS+=("$1"); shift ;;
125
- --no-fractal) forge_fractal_flag off || exit $?; shift ;;
126
- --retry) export FORGE_FRACTAL_RETRY=1; shift ;;
127
- --fractal-*|--dwarf-low|--dwarf-medium|--dwarf-high) FRACTAL_ARGS+=("$1" "${2:?}"); shift 2 ;;
128
124
  --output) OUTPUT="${2:?}"; shift 2 ;;
129
125
  --repo) REPO="${2:?--repo needs a value}"; shift 2 ;;
130
126
  --dwarf) DWARF="${2:?--dwarf needs a spec}"; shift 2 ;;
@@ -149,6 +145,10 @@ while [ $# -gt 0 ]; do
149
145
  QA_THR="$(printf '%s' "${2:?--qa-threshold needs P0, P1, P2, P3 or none}" | tr 'a-z' 'A-Z')"
150
146
  case "$QA_THR" in P0|P1|P2|P3) ;; NONE) QA_THR=none ;; *) die "--qa-threshold must be P0, P1, P2, P3 or none, got '$2'" 2 ;; esac
151
147
  shift 2 ;;
148
+ --qa-test-minutes)
149
+ case "${2:-}" in ''|*[!0-9]*) die "--qa-test-minutes needs a non-negative integer, got '${2:-}'" 2 ;; esac
150
+ QA_TEST_MINS="$2"
151
+ shift 2 ;;
152
152
  --ui|--no-ui) forge_ui_flag "$1"; shift ;;
153
153
  *)
154
154
  # `case` is not a loop, so `continue` here belongs to the enclosing while.
@@ -159,6 +159,11 @@ while [ $# -gt 0 ]; do
159
159
  2) exit 2 ;;
160
160
  esac
161
161
  fi
162
+ forge_removed_flag "$1"
163
+ # Solo took these only to route Fractal's child tasks.
164
+ case "$1" in --dwarf-low|--dwarf-medium|--dwarf-high|--retry)
165
+ die "$1 was removed with Fractal in forge $FORGE_FRACTAL_REMOVED_IN: a solo run has one implementer, --dwarf" ;;
166
+ esac
162
167
  die "unknown option '$1'" ;;
163
168
  esac
164
169
  done
@@ -179,14 +184,6 @@ pf_args=()
179
184
  [ -z "$QA_THR" ] || pf_args+=(--given qa_threshold)
180
185
  [ -z "$TIMEOUT" ] || pf_args+=(--given timeout)
181
186
  [ "$FAST_GIVEN" != 1 ] || pf_args+=(--given fast)
182
- pf_auto=0; pf_planner=0
183
- for pf_arg in ${FRACTAL_ARGS[@]+"${FRACTAL_ARGS[@]}"}; do
184
- case "$pf_arg" in
185
- --dwarf-low|--dwarf-medium|--dwarf-high) pf_args+=(--given "${pf_arg#--}") ;;
186
- --fractal-auto-decompose) pf_auto=1 ;;
187
- --fractal-planner) pf_planner=1; pf_args+=(--given fractal-planner) ;;
188
- esac
189
- done
190
187
  PF_LINE=""
191
188
  pf_out="$(forge_profile_py solo "$RUN" --repo "$REPO" ${pf_args[@]+"${pf_args[@]}"})" || exit $?
192
189
  while IFS="$(printf '\t')" read -r pf_key pf_val; do
@@ -196,12 +193,6 @@ while IFS="$(printf '\t')" read -r pf_key pf_val; do
196
193
  qa_threshold) QA_THR="$pf_val" ;;
197
194
  timeout) TIMEOUT="$pf_val" ;;
198
195
  fast) forge_fast_parse "$pf_val" solo; FAST_GIVEN=1 ;;
199
- # Fractal's tier pools and planner count only where Fractal is selected (and the planner
200
- # only with automatic decomposition, which --fractal-planner needs).
201
- pool.low) [ "$FRACTAL_CHOICE" != on ] || FRACTAL_ARGS+=(--dwarf-low "$pf_val") ;;
202
- pool.medium) [ "$FRACTAL_CHOICE" != on ] || FRACTAL_ARGS+=(--dwarf-medium "$pf_val") ;;
203
- pool.high) [ "$FRACTAL_CHOICE" != on ] || FRACTAL_ARGS+=(--dwarf-high "$pf_val") ;;
204
- fractal_planner) [ "$FRACTAL_CHOICE$pf_auto$pf_planner" != on10 ] || FRACTAL_ARGS+=(--fractal-planner "$pf_val") ;;
205
196
  line) PF_LINE="$pf_val" ;;
206
197
  # The gates and budget of the copy this run uses, for it and everything it starts.
207
198
  decide) [ -z "$pf_val" ] || export FORGE_DECIDE_PROFILE_JSON="$pf_val" ;;
@@ -226,10 +217,12 @@ case "$(cd "$RUN" && pwd)/" in
226
217
  esac
227
218
 
228
219
  RUN="$(cd "$RUN" && pwd)"
220
+ # A run directory an earlier forge ran under Fractal is read, never run again (#154).
221
+ [ "$DRY" = 1 ] || forge_refuse_fractal_run "$RUN" forge-solo.sh
229
222
  # The frozen copy, atomically. Only the process that holds the run's lock writes it (a refused
230
223
  # second start, or a dry run, must not change what an active run froze): the first pass above
231
224
  # 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
225
+ if [ "$DRY" != 1 ] && [ "$(forge_posix_path "${FORGE_SOLO_LOCK:-}")" = "$RUN" ]; then
233
226
  forge_profile_py solo "$RUN" --repo "$REPO" --no-validate --write ${pf_args[@]+"${pf_args[@]}"} >/dev/null || exit $?
234
227
  fi
235
228
  [ -z "$PF_LINE" ] || [ -n "${FORGE_SOLO_LOCK:-}" ] || echo "$PF_LINE"
@@ -237,10 +230,11 @@ fi
237
230
  # same run dir restores it rather than re-reading whatever flags are passed then.
238
231
  [ "$JEV_OPTS" = 1 ] && { forge_jev_restore "$RUN" || true; forge_jev_record "$RUN"; }
239
232
  REPO="$(cd "$REPO" && pwd)"
233
+ forge_repo_memory_off "$REPO" && export FORGE_MEMORY=off # forge setup: memory off here
240
234
  # Before any decision-model step: the privacy floor and the run budget read these.
241
235
  [ "$JEV_OPTS" = 1 ] && forge_decide_env "$REPO" "$RUN"
242
- if [ "$DRY" != 1 ] && [ "${FORGE_SOLO_LOCK:-}" != "$RUN" ]; then
243
- exec python3 "$SKILL_DIR/scripts/forge-fractal.py" _lock "$RUN" "$0" "${ORIGINAL_ARGS[@]}"
236
+ if [ "$DRY" != 1 ] && [ "$(forge_posix_path "${FORGE_SOLO_LOCK:-}")" != "$RUN" ]; then
237
+ exec python3 "$SKILL_DIR/scripts/forge-solo-lock.py" "$RUN" "$0" "${ORIGINAL_ARGS[@]}"
244
238
  fi
245
239
  # After the lock re-exec, so the process that dispatches is the one that writes it.
246
240
  forge_fast_store "$RUN"
@@ -249,28 +243,8 @@ export FORGE_CAPABILITY_CACHE="$RUN/capabilities"
249
243
  TFLAG=""; [ -n "$TIMEOUT" ] && TFLAG="--timeout $TIMEOUT"
250
244
  GOAL="$(head -1 "$RUN/goal.txt" 2>/dev/null || true)"
251
245
 
252
- FFLAGS=()
253
- [ -z "$YD" ] || FFLAGS+=(--yolo-dwarf)
254
- [ -z "$YQ" ] || FFLAGS+=(--yolo-qa)
255
- forge_fractal_select "$RUN" "$REPO" solo "$DRY" --dwarf "$DWARF" --qa "$QA" ${FFLAGS[@]+"${FFLAGS[@]}"} || exit $?
256
- forge_fast_fractal_note "$RUN"
257
- # Computed after Fractal selects, so a Fractal dispatch is not asked for the tier.
258
246
  ft_dwarf="$(forge_fast_tier "$RUN" dwarf)"
259
247
  ft_qa="$(forge_fast_tier "$RUN" qa)"
260
- if [ -n "${FORGE_FRACTAL_RUN:-}" ]; then
261
- # The UI choice is per invocation: a tmux resume replays these args and must not open it again.
262
- REMEMBER_ARGS=()
263
- for arg in "${ORIGINAL_ARGS[@]}"; do
264
- case "$arg" in --ui|--no-ui) ;; *) REMEMBER_ARGS+=("$arg") ;; esac
265
- done
266
- python3 "$SKILL_DIR/scripts/forge-fractal.py" _remember "$0" ${REMEMBER_ARGS[@]+"${REMEMBER_ARGS[@]}"} || exit $?
267
- fi
268
- if [ -n "${FORGE_FRACTAL_RUN:-}" ] && [ "$DRY" != 1 ] && [ "${FORGE_FRACTAL_RETRY:-}" != 1 ]; then
269
- python3 "$SKILL_DIR/scripts/forge-fractal.py" _checkpoint "$REPO"
270
- checkpoint_rc=$?
271
- [ "$checkpoint_rc" != 0 ] || exit 0
272
- [ "$checkpoint_rc" = 1 ] || exit "$checkpoint_rc"
273
- fi
274
248
 
275
249
  # The dispatches see a review snapshot, not the repo, so the run dir names it for the dataset.
276
250
  [ "$DRY" = 1 ] || printf '%s\n' "$REPO" > "$RUN/repo"
@@ -321,14 +295,10 @@ forge_metric_phase preflight
321
295
  /bin/bash "$DISPATCH" doctor --spec "$DWARF" --role dwarf $YD $TFLAG $ft_dwarf || exit $?
322
296
  /bin/bash "$DISPATCH" doctor --spec "$QA" --role qa $YQ $NATIVE $TFLAG $ft_qa || exit $?
323
297
  /bin/bash "$SKILL_DIR/scripts/forge-install-ripwire.sh" || true
324
- # After the _lock re-exec and the Fractal checkpoint exit, so it runs once per run.
298
+ # After the lock re-exec, so it runs once per run.
325
299
  forge_ui_launch "$RUN"
326
300
  forge_metric_phase snapshot
327
- if [ -n "${FORGE_FRACTAL_RUN:-}" ] && [ -s "$RUN/start.tree" ]; then
328
- START="$(cat "$RUN/start.tree")"
329
- else
330
- START="$(forge_tree "$REPO")" || die "cannot record starting snapshot" 3
331
- fi
301
+ START="$(forge_tree "$REPO")" || die "cannot record starting snapshot" 3
332
302
  echo "$START" > "$RUN/start.tree"
333
303
  git -C "$REPO" diff --binary HEAD "$START" -- . ':(exclude).forge' > "$RUN/existing.diff"
334
304
  forge_metric_phase dispatch
@@ -367,6 +337,7 @@ REVIEW="$RUN/review-$(date +%s)-$$"
367
337
  FORGE_REVIEW_SNAPSHOT="$REVIEW" # forge_metric_begin's EXIT trap removes it, whatever the outcome (#139)
368
338
  forge_review_snapshot "$REPO" "$START" "$END" "$REVIEW" || die "cannot create review snapshot" 3
369
339
  forge_review_deps "$REPO" "$REVIEW" "$RUN/review.deps"
340
+ forge_review_submodules "$REPO" "$REVIEW" "$RUN/review.deps"
370
341
  SOURCE_FP="$(forge_fingerprint "$REPO")" || exit 3
371
342
  [ "$(forge_tree "$REPO")" = "$END" ] || { echo INVALIDATED > "$RUN/verdict"; die "source changed while preparing QA" 5; }
372
343
  # The review snapshot is a commit; the reviewer's untracked leftovers there do not count (#95).
@@ -396,7 +367,11 @@ fi
396
367
  [ -s "$RUN/failfirst.txt" ] || echo "Forge ran no tests of its own on this attempt, so nothing here stands in for yours."
397
368
  echo
398
369
  if [ -s "$RUN/failfirst.txt" ]; then cat "$RUN/failfirst.txt"; echo; fi
399
- python3 "$SKILL_DIR/scripts/forge-contract.py" qa --part tail --kind solo --threshold "$THR"
370
+ [ -z "$QA_TEST_MINS" ] || printf '%s\n' "$QA_TEST_MINS" > "$RUN/qa_test_minutes"
371
+ _SOLO_TM="$(head -1 "$RUN/qa_test_minutes" 2>/dev/null | tr -d ' \r')"
372
+ _SOLO_TM_FLAG=()
373
+ case "$_SOLO_TM" in ''|*[!0-9]*) ;; *) _SOLO_TM_FLAG=(--test-minutes "$_SOLO_TM") ;; esac
374
+ python3 "$SKILL_DIR/scripts/forge-contract.py" qa --part tail --kind solo --threshold "$THR" ${_SOLO_TM_FLAG[@]+"${_SOLO_TM_FLAG[@]}"}
400
375
  echo
401
376
  # --irreversible-delete: a deleted file shows as a header, not every line it had (one deleted
402
377
  # data directory once made a 7.1M-character prompt that the reviewer's CLI refused).
@@ -431,7 +406,7 @@ dur_qa="$(sed -n 's/^duration_s=//p' "$RUN/qa.resolved" 2>/dev/null | tail -1)"
431
406
  # that cannot run (no output) keeps the reviewer's verdict.
432
407
  gate_note=""
433
408
  tests_note="$(forge_tests_note "$RUN/qa.last")"
434
- [ -z "$tests_note" ] || note "the reviewer's tests could not run: $tests_note"
409
+ [ -z "$tests_note" ] || note "the reviewer's tests did not complete: $tests_note"
435
410
  if [ -z "$NATIVE" ]; then
436
411
  gate_line="$(python3 "$SKILL_DIR/scripts/forge-contract.py" gate --verdict "${verdict:-UNKNOWN}" \
437
412
  --qa-last "$RUN/qa.last" --threshold "$THR" --known-issues "$RUN/known_issues.md" 2>/dev/null)" || gate_line=""
@@ -439,7 +414,13 @@ if [ -z "$NATIVE" ]; then
439
414
  printf '%s\t%s\n' "$THR" "$gate_line" > "$RUN/qa.gate"
440
415
  case "$(printf '%s' "$gate_line" | awk -F'\t' '{print $1}')" in
441
416
  accept) verdict=PASS; gate_note=" (accepted with known issues: $RUN/known_issues.md)" ;;
442
- fail) verdict=FAIL; gate_note=" (the reviewer said PASS, but listed a CONFIRMED finding at or above the $THR threshold — forge made it FAIL)" ;;
417
+ fail)
418
+ verdict=FAIL
419
+ if [ "$(printf '%s' "$gate_line" | awk -F'\t' '{print $6}')" = tests ]; then
420
+ gate_note=" (the reviewer said PASS, but reported failing tests — forge made it FAIL)"
421
+ else
422
+ gate_note=" (the reviewer said PASS, but listed a CONFIRMED finding at or above the $THR threshold — forge made it FAIL)"
423
+ fi ;;
443
424
  esac
444
425
  fi
445
426
  fi
@@ -63,6 +63,7 @@ SCRIPTS = Path(__file__).resolve().parent
63
63
  if str(SCRIPTS) not in sys.path:
64
64
  sys.path.insert(0, str(SCRIPTS))
65
65
  import forge_flock as fcntl # noqa: E402
66
+ import forge_legacy # noqa: E402
66
67
  import forge_posix # noqa: E402
67
68
  SEVERITIES = ('P0', 'P1', 'P2', 'P3')
68
69
  DEFAULT_MAX = 5 # fix tasks one sweep may add
@@ -259,7 +260,7 @@ class Context:
259
260
  def __init__(self, plan: Path):
260
261
  self.plan = plan
261
262
  self.repo = read(plan / 'repo')
262
- wt_root = read(plan / 'wt_root')
263
+ wt_root = forge_posix.host_path(read(plan / 'wt_root'))
263
264
  self.integration = os.path.join(wt_root, '_integration') if wt_root else ''
264
265
  rc, tip = git(self.integration, 'rev-parse', 'HEAD') if self.integration else (1, b'')
265
266
  self.tip = tip.decode().strip() if not rc else ''
@@ -371,7 +372,7 @@ def groups(kept: list, limit: int) -> tuple:
371
372
 
372
373
  def pools(plan: Path) -> dict:
373
374
  try:
374
- data = json.loads(read(plan / 'fractal-routing.json') or '{}')
375
+ data = json.loads(read(forge_legacy.pools_path(plan)) or '{}')
375
376
  except ValueError:
376
377
  return {}
377
378
  return data if isinstance(data, dict) else {}
@@ -190,7 +190,14 @@ def terminate(pid) -> bool:
190
190
 
191
191
 
192
192
  def read_only_wanted() -> bool:
193
- return os.environ.get('FORGE_UI_READONLY', '').strip().lower() in ('1', 'true', 'yes', 'on')
193
+ """FORGE_UI_READONLY, or `forge setup` answered ui_controls off."""
194
+ if os.environ.get('FORGE_UI_READONLY', '').strip().lower() in ('1', 'true', 'yes', 'on'):
195
+ return True
196
+ try:
197
+ import forge_prefs
198
+ except ImportError:
199
+ return False
200
+ return forge_prefs.get('ui_controls') == 'off'
194
201
 
195
202
 
196
203
  def is_read_only(answer) -> bool:
@@ -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.
@@ -57,10 +62,10 @@ main() {
57
62
  fi
58
63
  # Updating Forge does not offer installation of optional dependencies.
59
64
  if [ "$dry" = 1 ]; then
60
- FORGE_RIPWIRE=off /bin/bash "$source_dir/scripts/forge-install.sh" --dry-run || return $?
65
+ FORGE_RIPWIRE=off FORGE_SETUP=off /bin/bash "$source_dir/scripts/forge-install.sh" --dry-run || return $?
61
66
  echo 'forge: preview only; remote changes and live harness availability are not verified'
62
67
  else
63
- FORGE_RIPWIRE=off /bin/bash "$source_dir/scripts/forge-install.sh" || {
68
+ FORGE_RIPWIRE=off FORGE_SETUP=off /bin/bash "$source_dir/scripts/forge-install.sh" || {
64
69
  echo 'forge: source retained; some installations failed. Fix the reported cause and retry with --local' >&2; return 1;
65
70
  }
66
71
  echo 'forge: installations refreshed; restart active harness sessions to load the updated skill'
@@ -281,6 +281,21 @@ def _file_mode() -> int:
281
281
  return 0o666 & ~mask
282
282
 
283
283
 
284
+ def _replace(tmp: str, path: Path) -> None:
285
+ """os.replace, which on Windows is refused (PermissionError) while another process has the
286
+ target open: forge-ui or a watcher reading lanes.json. The reader holds it for a moment, so
287
+ try again for up to 2 s instead of ending the whole verification on a read."""
288
+ deadline = time.monotonic() + 2
289
+ while True:
290
+ try:
291
+ os.replace(tmp, path)
292
+ return
293
+ except PermissionError:
294
+ if os.name != 'nt' or time.monotonic() >= deadline:
295
+ raise
296
+ time.sleep(0.01)
297
+
298
+
284
299
  def write_atomic(path: Path, text: str) -> None:
285
300
  """Write through a temp file and rename. mkstemp makes the file 0600; the lane logs
286
301
  follow the umask, so the state files get the same mode (a forge-ui server may read them
@@ -290,7 +305,7 @@ def write_atomic(path: Path, text: str) -> None:
290
305
  os.fchmod(fd, _file_mode())
291
306
  with os.fdopen(fd, 'w') as fh:
292
307
  fh.write(text)
293
- os.replace(tmp, path)
308
+ _replace(tmp, path)
294
309
  except BaseException:
295
310
  try:
296
311
  os.unlink(tmp)
@@ -856,6 +871,7 @@ def cmd_run(args: argparse.Namespace) -> int:
856
871
 
857
872
  signal.signal(signal.SIGTERM, interrupt)
858
873
  signal.signal(signal.SIGINT, interrupt)
874
+ forge_proc.install_signal(forge_proc.SIGBREAK, interrupt)
859
875
  return verification.run()
860
876
 
861
877
 
@@ -161,12 +161,24 @@ def check(source: Path, info: dict) -> dict:
161
161
 
162
162
 
163
163
  def disabled() -> bool:
164
- if os.environ.get('FORGE_UPDATE_CHECK', '').strip().lower() in _OFF:
164
+ if os.environ.get('FORGE_UPDATE_CHECK', '').strip().lower() in _OFF or setup_off():
165
165
  return True
166
166
  ci = os.environ.get('CI', '').strip().lower()
167
167
  return bool(ci) and ci not in _OFF
168
168
 
169
169
 
170
+ def setup_off() -> bool:
171
+ """`forge setup` answered update_check off (setup.json); a missing helper means on."""
172
+ try:
173
+ here = str(Path(__file__).resolve().parent)
174
+ if here not in sys.path:
175
+ sys.path.insert(0, here)
176
+ import forge_prefs
177
+ except ImportError:
178
+ return False
179
+ return forge_prefs.update_check_off()
180
+
181
+
170
182
  def available_line(latest: str, current: str, info: dict | None = None) -> str:
171
183
  return f'forge {latest} is available (you have {current}): {update_command(info or {})}'
172
184
 
@@ -3,7 +3,8 @@
3
3
 
4
4
  Follow forge runs from the terminal and hear about them without keeping forge-ui open.
5
5
 
6
- A line is printed whenever a task changes status. A run that finishes or fails, a task that fails
6
+ A line is printed whenever a task changes status; the subtasks of a task that was split are
7
+ followed too, named by their path (`d/a` is subtask a of task d). A run that finishes or fails, a task that fails
7
8
  and a final review's verdict are also events: each raises a desktop notification where one can be
8
9
  shown (notify-send on Linux, osascript on macOS; on a headless machine or in CI there is no
9
10
  notifier and the events only print), and runs the optional hooks:
@@ -68,7 +69,11 @@ def run_state(summary: dict) -> str:
68
69
 
69
70
 
70
71
  def statuses(summary: dict) -> dict:
71
- return {item['id']: item['status'] for item in summary.get('task_statuses') or []}
72
+ """Every task's status, and every subtask's under a task that was split (#153), named by its path (`d/a`)."""
73
+ found = {item['id']: item['status'] for item in summary.get('task_statuses') or []}
74
+ for item in (summary.get('decomposition') or {}).get('statuses') or []:
75
+ found[item['id']] = item['status']
76
+ return found
72
77
 
73
78
 
74
79
  def goal_of(summary: dict) -> str:
@@ -0,0 +1,156 @@
1
+ #!/usr/bin/env bash
2
+ # forge-win.sh — sourced first by forge's entry scripts. Does nothing except on Windows in
3
+ # MSYS2 mode.
4
+ #
5
+ # On Windows forge runs natively by default: Git Bash with Windows' own Python. MSYS2 mode is
6
+ # the alternative for POSIX behaviour as on Linux: forge runs inside MSYS2, whose bash, git,
7
+ # python3 and ps agree on process ids, process groups, signals, flock and symlinks. It is opt-in:
8
+ #
9
+ # FORGE_WIN_MODE=msys2 an entry script started from Git Bash re-runs itself inside MSYS2
10
+ # an MSYS2 shell forge started there runs there, whatever FORGE_WIN_MODE says
11
+ #
12
+ # Inside MSYS2 this file exports FORGE_WIN_MODE=msys2, so helpers that adapt forge to native
13
+ # Windows can tell they are not in native mode.
14
+ #
15
+ # pacman -S python git procps-ng diffutils in the MSYS2 at FORGE_MSYS2_ROOT (default C:/msys64)
16
+ #
17
+ # Symlinks are made as real Windows symlinks (Developer Mode must be on). A link to a target
18
+ # that does not exist yet falls back to an MSYS-only link, which native programs see as a file.
19
+ #
20
+ # FORGE_WIN_AGENT_PATH is the PATH forge started with, in Git Bash or an MSYS2 shell, before
21
+ # /usr/bin goes first. forge-dispatch.sh gives it back to the agent CLIs, so they see what they
22
+ # would outside forge rather than MSYS2's tools first.
23
+ #
24
+ # This file is sourced on macOS too, so it keeps to Bash 3.2: no mapfile, no ${var,,}.
25
+ if [ "${BASH_SOURCE[0]}" = "$0" ]; then
26
+ # Run, not sourced: the landing side of the hop below. The original command line arrives in
27
+ # FORGE_WIN_ARGV, NUL-separated and base64-encoded, because a Windows command line cannot
28
+ # carry every argument unchanged (a double quote inside one is lost).
29
+ [ -n "${FORGE_WIN_ARGV:-}" ] || { echo "forge-win.sh is sourced by forge's entry scripts; it is not a command" >&2; exit 2; }
30
+ _forge_argv=()
31
+ while IFS= read -r -d '' _forge_arg; do _forge_argv+=("$_forge_arg"); done \
32
+ < <(printf '%s' "$FORGE_WIN_ARGV" | /usr/bin/base64 -d)
33
+ unset FORGE_WIN_ARGV _forge_arg
34
+ exec /usr/bin/bash "${_forge_argv[@]}"
35
+ fi
36
+ case "${OSTYPE:-}" in msys*|cygwin*) ;; *) return 0 ;; esac
37
+ case "${FORGE_WIN_MODE:-native}" in
38
+ native|msys2) ;;
39
+ *) echo "forge: FORGE_WIN_MODE is '$FORGE_WIN_MODE'; use native (the default) or msys2" >&2; exit 2 ;;
40
+ esac
41
+
42
+ # MSYS2 has pacman; Git for Windows has git-bash.exe at its root (its SDK, which has both, is
43
+ # Git Bash too). Only file tests here: native mode must not pay for a single extra process.
44
+ if [ ! -x /usr/bin/pacman ] || [ -e /git-bash.exe ]; then
45
+ [ "${FORGE_WIN_MODE:-native}" = msys2 ] || return 0 # native mode: Git Bash runs forge itself
46
+ _forge_msys="${FORGE_MSYS2_ROOT:-C:/msys64}"
47
+ _forge_msys="${_forge_msys%/}"
48
+ if [ ! -x "$_forge_msys/usr/bin/bash.exe" ]; then
49
+ echo "forge: FORGE_WIN_MODE=msys2, but MSYS2 was not found at $_forge_msys (set FORGE_MSYS2_ROOT)" >&2
50
+ exit 127
51
+ fi
52
+ # One hop only: landing anywhere but an MSYS2 would otherwise re-run the script for ever.
53
+ if [ -n "${FORGE_WIN_REEXEC:-}" ]; then
54
+ echo "forge: re-ran inside $_forge_msys, which does not look like MSYS2 (no /usr/bin/pacman)" >&2
55
+ exit 127
56
+ fi
57
+ # The hop goes through a native program. Started directly, MSYS2's bash would get almost none of
58
+ # this environment: two copies of the MSYS runtime cannot hand it to each other.
59
+ _forge_native=""
60
+ for _forge_tool in python3 python py; do
61
+ if "$_forge_tool" -c 'import sys; sys.exit(sys.platform != "win32")' 2>/dev/null; then _forge_native="$_forge_tool"; break; fi
62
+ done
63
+ if [ -z "$_forge_native" ]; then
64
+ echo "forge: MSYS2 mode needs a native Windows Python on the Git Bash PATH to hand over to MSYS2; or start forge from an MSYS2 shell" >&2
65
+ exit 127
66
+ fi
67
+ FORGE_WIN_ARGV="$(printf '%s\0' "$(/usr/bin/cygpath -m "$0")" "$@" | /usr/bin/base64 -w0)"
68
+ export FORGE_WIN_ARGV FORGE_WIN_REEXEC=1 FORGE_WIN_MSYSTEM="${MSYSTEM-}"
69
+ # Ctrl-C reaches MSYS2's bash as well, and forge's own handlers clean up (worktrees, agents).
70
+ # The hand-over only waits for it: subprocess.call would kill it on KeyboardInterrupt.
71
+ MSYS_NO_PATHCONV=1 MSYS2_ARG_CONV_EXCL='*' exec "$_forge_native" -c '
72
+ import subprocess, sys
73
+ child = subprocess.Popen(sys.argv[1:])
74
+ while True:
75
+ try:
76
+ sys.exit(child.wait())
77
+ except KeyboardInterrupt:
78
+ pass
79
+ ' "$_forge_msys/usr/bin/bash.exe" "$(/usr/bin/cygpath -m "${BASH_SOURCE[0]}")"
80
+ fi
81
+
82
+ # Inside MSYS2: started from an MSYS2 shell, or just arrived from Git Bash.
83
+ _forge_msys="$(/usr/bin/cygpath -m /)"
84
+ _forge_msys="${_forge_msys%/}"
85
+ for _forge_tool in python3 git procps cmp diff; do
86
+ if [ ! -x "/usr/bin/$_forge_tool" ]; then
87
+ echo "forge: the MSYS2 at $_forge_msys has no $_forge_tool; run there: pacman -S python git procps-ng diffutils" >&2
88
+ exit 127
89
+ fi
90
+ done
91
+ [ -z "${FORGE_WIN_REEXEC:-}" ] || unset FORGE_WIN_REEXEC MSYS_NO_PATHCONV MSYS2_ARG_CONV_EXCL
92
+ # The PATH and MSYSTEM forge started with (Git Bash's, or the MSYS2 shell's) are what an agent
93
+ # CLI should see. forge itself needs MSYS2's python3 and git ahead of everything: a UCRT64 or
94
+ # MINGW64 shell puts /ucrt64/bin or /mingw64/bin first, where a MinGW Python is a native Windows
95
+ # Python. Child scripts inherit both, so this runs once.
96
+ if [ -z "${FORGE_WIN_AGENT_PATH:-}" ]; then
97
+ export FORGE_WIN_AGENT_PATH="$PATH"
98
+ [ -n "${FORGE_WIN_MSYSTEM+set}" ] || export FORGE_WIN_MSYSTEM="${MSYSTEM-}"
99
+ fi
100
+ case "$PATH" in /usr/bin:*) ;; *) export PATH="/usr/bin:$PATH" ;; esac
101
+ # Real Windows symlinks, unless the user already chose how MSYS2 makes them.
102
+ case " ${MSYS-} " in *" winsymlinks"*) ;; *) MSYS="${MSYS:+$MSYS }winsymlinks:native" ;; esac
103
+ # FORGE_WIN_MODE says which mode runs, to every child script and helper, also when forge was
104
+ # started from an MSYS2 shell without it: native-port helpers must treat MSYS2 mode as POSIX.
105
+ export MSYSTEM=MSYS MSYS FORGE_WIN_MODE=msys2
106
+ # Worktree links must be relative: Git for Windows, which the native agent CLIs use, cannot follow
107
+ # the /c/... paths MSYS2's git writes. The setting travels in the environment, but the first
108
+ # worktree made with it adds extensions.relativeWorktrees to the repository's config, and from
109
+ # then on Git older than 2.48 (and libgit2- or JGit-based tools) refuses to open the repository.
110
+ # So both gits must be 2.48 or newer; children of this script inherit the result.
111
+ if [ -z "${FORGE_WIN_GIT_CHECKED:-}" ]; then
112
+ _forge_git_too_old() { # _forge_git_too_old <git> <how to update>: says why and succeeds when < 2.48
113
+ local version major minor
114
+ version="$("$1" --version 2>/dev/null)"
115
+ version="${version#git version }"
116
+ major="${version%%.*}"
117
+ minor="${version#*.}"
118
+ minor="${minor%%.*}"
119
+ case "$major.$minor" in
120
+ [0-9]*.[0-9]*) ;;
121
+ *) echo "forge: cannot read the version of $1 ('$version'); MSYS2 mode needs Git 2.48 or newer" >&2; return 0 ;;
122
+ esac
123
+ if [ "$major" -gt 2 ] || { [ "$major" -eq 2 ] && [ "$minor" -ge 48 ]; }; then return 1; fi
124
+ echo "forge: MSYS2 mode needs Git 2.48 or newer for relative worktree links; $1 is $version: $2" >&2
125
+ return 0
126
+ }
127
+ if _forge_git_too_old /usr/bin/git 'update MSYS2 with pacman -Syu'; then exit 127; fi
128
+ _forge_agent_git="$(PATH="${FORGE_WIN_AGENT_PATH:-$PATH}" command -v git)"
129
+ if [ -n "$_forge_agent_git" ] && [ "$_forge_agent_git" != /usr/bin/git ] \
130
+ && _forge_git_too_old "$_forge_agent_git" 'update Git for Windows'; then exit 127; fi
131
+ unset -f _forge_git_too_old
132
+ export FORGE_WIN_GIT_CHECKED=1
133
+ fi
134
+ case " ${GIT_CONFIG_KEY_0-} ${GIT_CONFIG_KEY_1-} ${GIT_CONFIG_KEY_2-} ${GIT_CONFIG_KEY_3-} " in
135
+ *" worktree.useRelativePaths "*) ;;
136
+ *) _forge_n="${GIT_CONFIG_COUNT:-0}"
137
+ export "GIT_CONFIG_KEY_$_forge_n=worktree.useRelativePaths" "GIT_CONFIG_VALUE_$_forge_n=true"
138
+ export GIT_CONFIG_COUNT="$((_forge_n + 1))" ;;
139
+ esac
140
+ # procps' pkill reads every /proc/<pid>/stat, which Cygwin fills by asking Windows: about half a
141
+ # second per process. forge only runs `pkill [-SIGNAL] -P <parent>`, which /proc/<pid>/ppid answers
142
+ # at once. Anything else goes to the real pkill. Scripts sourced after this file (forge-metrics.sh)
143
+ # get the function too.
144
+ pkill() {
145
+ local sig=TERM parent="" arg dir ppid found=1
146
+ for arg in "$@"; do
147
+ case "$arg" in -P) ;; -[A-Z]*|-[0-9]*) sig="${arg#-}" ;; [0-9]*) parent="$arg" ;; *) command pkill "$@"; return ;; esac
148
+ done
149
+ [ -n "$parent" ] || { command pkill "$@"; return; }
150
+ for dir in /proc/[0-9]*; do
151
+ read -r ppid < "$dir/ppid" 2>/dev/null || continue
152
+ [ "$ppid" = "$parent" ] && kill -s "$sig" "${dir#/proc/}" 2>/dev/null && found=0
153
+ done
154
+ return "$found"
155
+ }
156
+ unset _forge_msys _forge_tool _forge_n _forge_native _forge_agent_git