@giamme/forge 0.20.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 (71) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/README.md +13 -3
  3. package/VERSION +1 -1
  4. package/bin/forge.js +104 -0
  5. package/docs/README.md +1 -0
  6. package/docs/development.md +1 -1
  7. package/docs/install.md +91 -2
  8. package/docs/reviews.md +6 -4
  9. package/docs/troubleshooting.md +1 -1
  10. package/forge +4 -0
  11. package/forge.cmd +56 -0
  12. package/package.json +5 -3
  13. package/scripts/forge-artifact.sh +5 -1
  14. package/scripts/forge-config.py +10 -9
  15. package/scripts/forge-control.py +61 -38
  16. package/scripts/forge-dispatch.sh +108 -31
  17. package/scripts/forge-group.py +2 -1
  18. package/scripts/forge-guard.py +207 -38
  19. package/scripts/forge-handoff.py +14 -17
  20. package/scripts/forge-install.sh +82 -9
  21. package/scripts/forge-issues.py +5 -2
  22. package/scripts/forge-lib-env.sh +158 -0
  23. package/scripts/forge-lib-group.sh +5 -5
  24. package/scripts/forge-lib-plans.sh +8 -3
  25. package/scripts/forge-lib-task.sh +40 -15
  26. package/scripts/forge-memory.sh +2 -0
  27. package/scripts/forge-metrics.sh +6 -1
  28. package/scripts/forge-parallel.sh +174 -53
  29. package/scripts/forge-planner.py +28 -2
  30. package/scripts/forge-pre-review.py +11 -4
  31. package/scripts/forge-ripwire.py +68 -22
  32. package/scripts/forge-route.py +10 -3
  33. package/scripts/forge-runs-compact.py +3 -2
  34. package/scripts/forge-runs-rm.py +14 -14
  35. package/scripts/forge-runtime.py +38 -21
  36. package/scripts/forge-schedule.py +90 -56
  37. package/scripts/forge-shadow.py +16 -9
  38. package/scripts/forge-solo.sh +6 -2
  39. package/scripts/forge-summarize.py +7 -3
  40. package/scripts/forge-sweep.py +8 -3
  41. package/scripts/forge-ui.py +8 -13
  42. package/scripts/forge-update.sh +6 -1
  43. package/scripts/forge-verify.py +30 -23
  44. package/scripts/forge-win.sh +156 -0
  45. package/scripts/forge_brief/__init__.py +7 -2
  46. package/scripts/forge_brief/proposals.py +13 -3
  47. package/scripts/forge_decide/budget.py +18 -8
  48. package/scripts/forge_decide/replay.py +15 -5
  49. package/scripts/forge_findings/apply.py +2 -1
  50. package/scripts/forge_findings/store.py +16 -4
  51. package/scripts/forge_findings/triage.py +6 -15
  52. package/scripts/forge_flock.py +102 -0
  53. package/scripts/forge_fractal/__init__.py +7 -3
  54. package/scripts/forge_fractal/cli.py +7 -2
  55. package/scripts/forge_fractal/execution.py +14 -14
  56. package/scripts/forge_fractal/invocation.py +3 -2
  57. package/scripts/forge_fractal/pipeline.py +2 -1
  58. package/scripts/forge_fractal/selection.py +2 -1
  59. package/scripts/forge_identity.py +2 -1
  60. package/scripts/forge_locations.py +14 -4
  61. package/scripts/forge_posix.py +125 -0
  62. package/scripts/forge_proc.py +507 -0
  63. package/scripts/forge_registry.py +17 -8
  64. package/scripts/forge_retro/__init__.py +8 -2
  65. package/scripts/forge_retro/issues.py +2 -1
  66. package/scripts/forge_side/__init__.py +32 -14
  67. package/scripts/forge_storage.py +11 -1
  68. package/ui/forge_ui/control.py +42 -14
  69. package/ui/forge_ui/reader.py +24 -18
  70. package/ui/forge_ui/server.py +10 -1
  71. package/ui/forge_ui/static/scene3d.js +23 -2
@@ -65,7 +65,6 @@ from __future__ import annotations
65
65
  import argparse
66
66
  import contextlib
67
67
  import errno
68
- import fcntl
69
68
  import json
70
69
  import os
71
70
  import re
@@ -82,7 +81,10 @@ from pathlib import Path
82
81
  SCRIPTS = os.path.dirname(os.path.realpath(__file__))
83
82
  if SCRIPTS not in sys.path:
84
83
  sys.path.insert(0, SCRIPTS)
84
+ import forge_flock as fcntl # noqa: E402
85
85
  import forge_infra # noqa: E402
86
+ import forge_posix # noqa: E402
87
+ import forge_proc # noqa: E402
86
88
 
87
89
  SKILL = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
88
90
  LOCK_WAIT = 5.0
@@ -94,7 +96,6 @@ DEFAULT_VERIFY_RETRIES = 1 # forge-parallel.sh
94
96
  DEFAULT_PRE_REVIEW_PARALLEL = 2 # forge-artifact.sh forge_pre_review
95
97
  LEVELS = ('P0', 'P1', 'P2', 'P3')
96
98
  STOP_MARKERS = ('escalation.stop', 'split.suggested', 'escalation.next')
97
- DIR_FLAGS = os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW | os.O_CLOEXEC
98
99
 
99
100
  NEXT_ATTEMPT = "at the task's next attempt"
100
101
  NEXT_DECISION = 'at the next retry decision'
@@ -126,7 +127,7 @@ def valid_task_id(name):
126
127
 
127
128
  def _enter(fd, part, create, rel):
128
129
  try:
129
- return os.open(part, DIR_FLAGS, dir_fd=fd)
130
+ return forge_posix.enter_dir(fd, part, nofollow=True)
130
131
  except FileNotFoundError:
131
132
  if not create:
132
133
  return None
@@ -135,11 +136,11 @@ def _enter(fd, part, create, rel):
135
136
  raise Invalid(f'{rel}: {part} is not a real directory')
136
137
  raise
137
138
  try:
138
- os.mkdir(part, dir_fd=fd)
139
+ forge_posix.mkdir_at(fd, part)
139
140
  except FileExistsError:
140
141
  pass
141
142
  try:
142
- return os.open(part, DIR_FLAGS, dir_fd=fd)
143
+ return forge_posix.enter_dir(fd, part, nofollow=True)
143
144
  except OSError as error:
144
145
  if error.errno in (errno.ELOOP, errno.ENOTDIR):
145
146
  raise Invalid(f'{rel}: {part} is not a real directory')
@@ -149,25 +150,25 @@ def _enter(fd, part, create, rel):
149
150
  def _open_parent(plan, rel, create=False):
150
151
  """(fd of rel's parent dir, leaf name); (None, leaf) when a parent does not exist and create is off."""
151
152
  *dirs, leaf = rel.split('/')
152
- fd = os.open(plan, os.O_RDONLY | os.O_DIRECTORY | os.O_CLOEXEC)
153
+ fd = forge_posix.open_dir(plan, nofollow=False)
153
154
  try:
154
155
  for part in dirs:
155
156
  nxt = _enter(fd, part, create, rel)
156
- os.close(fd)
157
+ forge_posix.close_dir(fd)
157
158
  fd = nxt
158
159
  if fd is None:
159
160
  return None, leaf
160
161
  return fd, leaf
161
162
  except BaseException:
162
163
  if fd is not None:
163
- os.close(fd)
164
+ forge_posix.close_dir(fd)
164
165
  raise
165
166
 
166
167
 
167
168
  def _regular(fd, leaf, rel):
168
169
  """The lstat of an existing regular file, None when absent; anything else is unsafe."""
169
170
  try:
170
- st = os.stat(leaf, dir_fd=fd, follow_symlinks=False)
171
+ st = forge_posix.stat_at(fd, leaf, follow_symlinks=False)
171
172
  except FileNotFoundError:
172
173
  return None
173
174
  if not stat.S_ISREG(st.st_mode):
@@ -183,7 +184,7 @@ def probe(plan, rel):
183
184
  try:
184
185
  return _regular(fd, leaf, rel) is not None
185
186
  finally:
186
- os.close(fd)
187
+ forge_posix.close_dir(fd)
187
188
 
188
189
 
189
190
  def _read(plan, rel, tail):
@@ -192,7 +193,11 @@ def _read(plan, rel, tail):
192
193
  return None
193
194
  try:
194
195
  try:
195
- rfd = os.open(leaf, os.O_RDONLY | os.O_NOFOLLOW | os.O_NONBLOCK | os.O_CLOEXEC, dir_fd=fd)
196
+ rfd = forge_posix.open_at(
197
+ fd,
198
+ leaf,
199
+ os.O_RDONLY | forge_posix.O_NOFOLLOW | forge_posix.O_NONBLOCK | forge_posix.O_CLOEXEC,
200
+ )
196
201
  except FileNotFoundError:
197
202
  return None
198
203
  except OSError as error:
@@ -210,7 +215,7 @@ def _read(plan, rel, tail):
210
215
  finally:
211
216
  os.close(rfd)
212
217
  finally:
213
- os.close(fd)
218
+ forge_posix.close_dir(fd)
214
219
  if cut:
215
220
  data = data.partition(b'\n')[2] # the first line is cut in half
216
221
  return data.decode('utf-8', 'replace')
@@ -243,18 +248,23 @@ def write_atomic(plan, rel, text):
243
248
  tmp = f'.{leaf}.{os.getpid()}.{time.time_ns()}.tmp'
244
249
  try:
245
250
  _regular(fd, leaf, rel)
246
- tfd = os.open(tmp, os.O_WRONLY | os.O_CREAT | os.O_EXCL | os.O_NOFOLLOW | os.O_CLOEXEC, 0o644, dir_fd=fd)
251
+ tfd = forge_posix.open_at(
252
+ fd,
253
+ tmp,
254
+ os.O_WRONLY | os.O_CREAT | os.O_EXCL | forge_posix.O_NOFOLLOW | forge_posix.O_CLOEXEC,
255
+ 0o644,
256
+ )
247
257
  try:
248
258
  os.write(tfd, text.encode('utf-8'))
249
259
  finally:
250
260
  os.close(tfd)
251
- os.replace(tmp, leaf, src_dir_fd=fd, dst_dir_fd=fd)
261
+ forge_posix.replace_at(fd, tmp, leaf)
252
262
  except BaseException:
253
263
  with contextlib.suppress(OSError):
254
- os.unlink(tmp, dir_fd=fd)
264
+ forge_posix.unlink_at(fd, tmp)
255
265
  raise
256
266
  finally:
257
- os.close(fd)
267
+ forge_posix.close_dir(fd)
258
268
 
259
269
 
260
270
  def remove_safe(plan, rel):
@@ -265,12 +275,12 @@ def remove_safe(plan, rel):
265
275
  try:
266
276
  if _regular(fd, leaf, rel) is None:
267
277
  return False
268
- os.unlink(leaf, dir_fd=fd)
278
+ forge_posix.unlink_at(fd, leaf)
269
279
  return True
270
280
  except FileNotFoundError:
271
281
  return False
272
282
  finally:
273
- os.close(fd)
283
+ forge_posix.close_dir(fd)
274
284
 
275
285
 
276
286
  def append_line(plan, rel, line):
@@ -281,7 +291,12 @@ def append_line(plan, rel, line):
281
291
  raise Invalid(f'{rel}: a parent directory is missing')
282
292
  try:
283
293
  _regular(fd, leaf, rel)
284
- afd = os.open(leaf, os.O_WRONLY | os.O_APPEND | os.O_CREAT | os.O_NOFOLLOW | os.O_CLOEXEC, 0o644, dir_fd=fd)
294
+ afd = forge_posix.open_at(
295
+ fd,
296
+ leaf,
297
+ os.O_WRONLY | os.O_APPEND | os.O_CREAT | forge_posix.O_NOFOLLOW | forge_posix.O_CLOEXEC,
298
+ 0o644,
299
+ )
285
300
  try:
286
301
  if not stat.S_ISREG(os.fstat(afd).st_mode):
287
302
  raise Invalid(f'{rel} is not a regular file')
@@ -289,7 +304,7 @@ def append_line(plan, rel, line):
289
304
  finally:
290
305
  os.close(afd)
291
306
  finally:
292
- os.close(fd)
307
+ forge_posix.close_dir(fd)
293
308
 
294
309
 
295
310
  @contextlib.contextmanager
@@ -299,13 +314,18 @@ def control_lock(plan):
299
314
  try:
300
315
  _regular(fd, leaf, 'control.lock') # a FIFO would block the open
301
316
  try:
302
- lock = os.open(leaf, os.O_RDWR | os.O_CREAT | os.O_NOFOLLOW | os.O_CLOEXEC, 0o644, dir_fd=fd)
317
+ lock = forge_posix.open_at(
318
+ fd,
319
+ leaf,
320
+ os.O_RDWR | os.O_CREAT | forge_posix.O_NOFOLLOW | forge_posix.O_CLOEXEC,
321
+ 0o644,
322
+ )
303
323
  except OSError as error:
304
324
  if error.errno == errno.ELOOP:
305
325
  raise Invalid('control.lock is not a regular file')
306
326
  raise
307
327
  finally:
308
- os.close(fd)
328
+ forge_posix.close_dir(fd)
309
329
  try:
310
330
  deadline = time.monotonic() + LOCK_WAIT
311
331
  while True:
@@ -351,17 +371,7 @@ def is_live(plan):
351
371
  pid = json.loads(read_file(plan, 'scheduler.live') or '')['pid']
352
372
  except (ValueError, KeyError, TypeError):
353
373
  return False
354
- if type(pid) is not int or pid <= 0:
355
- return False
356
- try:
357
- os.kill(pid, 0)
358
- except ProcessLookupError:
359
- return False
360
- except PermissionError:
361
- return True
362
- except (OSError, OverflowError):
363
- return False
364
- return True
374
+ return forge_proc.pid_alive(pid)
365
375
 
366
376
 
367
377
  def is_fractal(plan):
@@ -709,7 +719,8 @@ def start_summaries(plan, task):
709
719
  command += ['--task', task]
710
720
  try:
711
721
  with open(os.path.join(plan, 'summaries.out'), 'ab') as out:
712
- subprocess.Popen(command, stdin=subprocess.DEVNULL, stdout=out, stderr=out, start_new_session=True)
722
+ subprocess.Popen(command, stdin=subprocess.DEVNULL, stdout=out, stderr=out,
723
+ **forge_proc.popen_group_kwargs(detached=True))
713
724
  except OSError:
714
725
  pass
715
726
 
@@ -717,7 +728,12 @@ def start_summaries(plan, task):
717
728
  def doctor(spec, role='dwarf'):
718
729
  """Offline capability check of a spec: Refused when it fails, no quota spent."""
719
730
  override = os.environ.get('FORGE_CONTROL_DOCTOR')
720
- base = shlex.split(override) if override else ['bash', os.path.join(SKILL, 'scripts', 'forge-dispatch.sh'), 'doctor']
731
+ if override:
732
+ base = shlex.split(override)
733
+ elif forge_proc.IS_WINDOWS:
734
+ base = forge_proc.bash_cmd(os.path.join(SKILL, 'scripts', 'forge-dispatch.sh'), 'doctor')
735
+ else:
736
+ base = ['bash', os.path.join(SKILL, 'scripts', 'forge-dispatch.sh'), 'doctor']
721
737
  try:
722
738
  done = subprocess.run(base + ['--spec', spec, '--role', role], capture_output=True, text=True,
723
739
  stdin=subprocess.DEVNULL, timeout=60)
@@ -898,7 +914,10 @@ def decision_of(plan, args, dwarf):
898
914
  status = task_status(plan, args.task, strict=True)
899
915
  if status != 'NEEDS_DECISION':
900
916
  if args.decide is not None:
901
- raise Refused(f'task {args.task} is {status}, not waiting for a decision: --decide only decides a NEEDS_DECISION task')
917
+ hint = ' (retry without --decide)' if status in (
918
+ 'FAIL', 'UNKNOWN', 'ERROR', 'TIMEOUT', 'INTERRUPTED', 'INVALIDATED', 'CONFLICT',
919
+ ) else ''
920
+ raise Refused(f'task {args.task} is {status}, not waiting for a decision: --decide only decides a NEEDS_DECISION task{hint}')
902
921
  return None
903
922
  if args.decide is None and dwarf is None:
904
923
  head = ' '.join(line.strip() for line in (read_file(plan, f'tasks/{args.task}/decision.md') or '').splitlines()[:3]
@@ -979,8 +998,12 @@ def retry_prepared(args, plan, answer):
979
998
  try:
980
999
  with os.fdopen(fd, 'w', encoding='utf-8') as handle:
981
1000
  handle.write(answer + '\n')
982
- command = ['bash', os.path.join(SKILL, 'scripts', 'forge-parallel.sh'), 'retry', plan, args.task,
983
- '--answer-file', tmp, '--no-dispatch']
1001
+ script = os.path.join(SKILL, 'scripts', 'forge-parallel.sh')
1002
+ if forge_proc.IS_WINDOWS:
1003
+ base = forge_proc.bash_cmd(script)
1004
+ else:
1005
+ base = ['bash', script]
1006
+ command = base + ['retry', plan, args.task, '--answer-file', tmp, '--no-dispatch']
984
1007
  if args.json: # stdout is the JSON: the command's own words go to stderr
985
1008
  done = subprocess.run(command, stdin=subprocess.DEVNULL, capture_output=True, text=True)
986
1009
  sys.stderr.write(done.stdout + done.stderr)
@@ -65,6 +65,10 @@
65
65
  set -uo pipefail
66
66
 
67
67
  SKILL_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
68
+ # Windows: re-run inside MSYS2 when started from Git Bash (no-op elsewhere).
69
+ . "$SKILL_DIR/scripts/forge-win.sh"
70
+ source "$SKILL_DIR/scripts/forge-lib-env.sh"
71
+ forge_ensure_python3
68
72
  REGISTRY="${FORGE_REGISTRY:-$SKILL_DIR/registry.tsv}"
69
73
  RUNTIME="$SKILL_DIR/scripts/forge-runtime.py"
70
74
  GUARD="$SKILL_DIR/scripts/forge-guard.py"
@@ -94,6 +98,51 @@ binary_for() {
94
98
  case "$1" in antigravity) echo agy ;; *) echo "$1" ;; esac
95
99
  }
96
100
 
101
+ # Resolve a harness CLI: first PATH, then well-known per-user Windows install paths.
102
+ resolve_binary() { # resolve_binary <harness> -> path on stdout, exit 1 if missing
103
+ local name bin cand localappdata appdata userprofile
104
+ name="$(binary_for "$1")"
105
+ if bin="$(command -v "$name" 2>/dev/null)" && [ -n "$bin" ]; then
106
+ printf '%s\n' "$bin"; return 0
107
+ fi
108
+ forge_is_windows || return 1
109
+ if bin="$(command -v "$name.cmd" 2>/dev/null)" && [ -n "$bin" ]; then
110
+ printf '%s\n' "$bin"; return 0
111
+ fi
112
+ localappdata="$(forge_posix_path "${LOCALAPPDATA:-}")"
113
+ appdata="$(forge_posix_path "${APPDATA:-}")"
114
+ userprofile="$(forge_posix_path "${USERPROFILE:-}")"
115
+ case "$1" in
116
+ antigravity)
117
+ for cand in ${localappdata:+"$localappdata/agy/bin/agy.exe"}; do
118
+ [ -f "$cand" ] && { printf '%s\n' "$cand"; return 0; }
119
+ done ;;
120
+ opencode)
121
+ if bin="$(command -v opencode-cli 2>/dev/null)" && [ -n "$bin" ]; then
122
+ printf '%s\n' "$bin"; return 0
123
+ fi
124
+ for cand in \
125
+ ${localappdata:+"$localappdata/Programs/@opencode-aidesktop/resources/opencode-cli.exe"} \
126
+ ${appdata:+"$appdata/npm/opencode.cmd"} \
127
+ ${appdata:+"$appdata/npm/opencode"}; do
128
+ [ -f "$cand" ] && { printf '%s\n' "$cand"; return 0; }
129
+ done ;;
130
+ claude)
131
+ for cand in \
132
+ ${userprofile:+"$userprofile/.local/bin/claude.exe"} \
133
+ ${HOME:+"$HOME/.local/bin/claude.exe"}; do
134
+ [ -f "$cand" ] && { printf '%s\n' "$cand"; return 0; }
135
+ done ;;
136
+ openclaude|codex)
137
+ for cand in \
138
+ ${appdata:+"$appdata/npm/$name.cmd"} \
139
+ ${appdata:+"$appdata/npm/$name"}; do
140
+ [ -f "$cand" ] && { printf '%s\n' "$cand"; return 0; }
141
+ done ;;
142
+ esac
143
+ return 1
144
+ }
145
+
97
146
  # Every effort word forge recognizes, weakest first. Used only to tell "you asked
98
147
  # for more thinking than this pairing offers" (clamp, keep going) apart from "that
99
148
  # is not an effort level" (stop). ultra and ultracode are each their harness's top
@@ -190,7 +239,7 @@ doctor() {
190
239
  local rc=0 h bin
191
240
  printf '%-12s %-10s %s\n' HARNESS STATUS DETAIL
192
241
  for h in codex claude openclaude opencode antigravity grok; do
193
- bin="$(command -v "$(binary_for "$h")" 2>/dev/null)"
242
+ bin="$(resolve_binary "$h" 2>/dev/null)"
194
243
  if [ -z "$bin" ]; then
195
244
  printf '%-12s %-10s %s\n' "$h" MISSING "$(binary_for "$h") not on PATH"; rc=1; continue
196
245
  fi
@@ -432,19 +481,20 @@ if [ "$PREFLIGHT" != 1 ] && [ "$DRY" != 1 ]; then
432
481
  # dispatch and must not be the thing that hangs it.
433
482
  exit_cleanup() {
434
483
  [ -z "${tpid:-}" ] || kill -TERM "$tpid" 2>/dev/null
484
+ local _hw="${hwinpid:-${hpid:-}}"
435
485
  if [ -n "${hpid:-}" ] && kill -0 "$hpid" 2>/dev/null; then
436
- [ "${GUARD_ON:-0}" != 1 ] || kill -s TERM -- "-$hpid" 2>/dev/null
437
- pkill -TERM -P "$hpid" 2>/dev/null; kill -TERM "$hpid" 2>/dev/null
486
+ [ "${GUARD_ON:-0}" != 1 ] || forge_kill_group "$hpid" TERM
487
+ forge_kill_children "$hpid" TERM; kill -TERM "$hpid" 2>/dev/null
438
488
  if [ "${GUARD_ON:-0}" = 1 ]; then
439
- sleep 1; kill -s KILL -- "-$hpid" 2>/dev/null
489
+ sleep 1; forge_kill_group "$hpid" KILL
440
490
  # what it started in sessions of their own (#129)
441
- python3 "$GUARD" reap "$hpid" "$RUN_DIR/$ROLE.orphans" --tracked "$RUN_DIR/$ROLE.tracked" >/dev/null 2>&1
491
+ python3 "$GUARD" reap "$_hw" "$RUN_DIR/$ROLE.orphans" --tracked "$RUN_DIR/$ROLE.tracked" >/dev/null 2>&1
442
492
  fi
443
- elif [ "${GUARD_ON:-0}" = 1 ] && [ "${reaped:-0}" != 1 ] && [ -n "${hpid:-}" ]; then
493
+ elif [ "${GUARD_ON:-0}" = 1 ] && [ "${reaped:-0}" != 1 ] && [ -n "${_hw:-}" ]; then
444
494
  # Interrupted after the harness exited but before the normal reap.
445
- python3 "$GUARD" reap "$hpid" "$RUN_DIR/$ROLE.orphans" --tracked "$RUN_DIR/$ROLE.tracked" >/dev/null 2>&1
495
+ python3 "$GUARD" reap "$_hw" "$RUN_DIR/$ROLE.orphans" --tracked "$RUN_DIR/$ROLE.tracked" >/dev/null 2>&1
446
496
  fi
447
- for watcher in ${wpid:-} ${spid:-}; do pkill -P "$watcher" 2>/dev/null; kill "$watcher" 2>/dev/null; done
497
+ for watcher in ${wpid:-} ${spid:-}; do forge_kill_children "$watcher" TERM; kill "$watcher" 2>/dev/null; done
448
498
  [ -z "${cpid:-}" ] || kill "$cpid" 2>/dev/null
449
499
  rm -f "$RUN_DIR/$ROLE.harness" "$RUN_DIR/$ROLE.tracked"
450
500
  case "${ROLE_TMP:-}" in "$RUN_DIR"/.*-tmp.*) [ ! -d "$ROLE_TMP" ] || rm -rf -- "$ROLE_TMP" ;; esac
@@ -547,6 +597,15 @@ codex_read_only() {
547
597
  }
548
598
 
549
599
  # Sets CMD (and PROMPT_VIA_STDIN) for the dispatch, or for the fresh one when CONTINUE_ID is empty.
600
+ D_REPO="$REPO"; D_RUN_DIR="$RUN_DIR"; D_LAST="$LAST"; D_PROMPT_FILE="$PROMPT_FILE"; D_GUARD="$GUARD"
601
+ if forge_is_windows; then
602
+ D_REPO="$(forge_host_path "$REPO")"
603
+ D_RUN_DIR="$(forge_host_path "$RUN_DIR")"
604
+ D_LAST="$(forge_host_path "$LAST")"
605
+ D_PROMPT_FILE="$(forge_host_path "$PROMPT_FILE")"
606
+ D_GUARD="$(forge_host_path "$GUARD")"
607
+ fi
608
+
550
609
  build_cmd() {
551
610
  CMD=()
552
611
  case "$HARNESS" in
@@ -557,7 +616,7 @@ build_cmd() {
557
616
  # whether the diff is correct, but not whether it is the change that was
558
617
  # actually asked for. `codex exec review` also has no --cd, hence the
559
618
  # subshell cd below.
560
- CMD=(codex exec review --json -m "$MODEL" --skip-git-repo-check -o "$LAST")
619
+ CMD=(codex exec review --json -m "$MODEL" --skip-git-repo-check -o "$D_LAST")
561
620
  [ -n "$EFFORT" ] && CMD+=(-c "model_reasoning_effort=$EFFORT")
562
621
  [ "$SERVICE_TIER" = fast ] && CMD+=(-c "service_tier=fast")
563
622
  if [ -n "$REVIEW_BASE" ]; then CMD+=(--base "$REVIEW_BASE"); else CMD+=(--uncommitted); fi
@@ -569,7 +628,7 @@ build_cmd() {
569
628
  # An id that starts with '-' would be read as a flag, so it goes after a `--`.
570
629
  CMD=(codex exec resume)
571
630
  case "$CONTINUE_ID" in -*) ;; *) CMD+=("$CONTINUE_ID") ;; esac
572
- CMD+=(--json -m "$MODEL" --skip-git-repo-check -o "$LAST")
631
+ CMD+=(--json -m "$MODEL" --skip-git-repo-check -o "$D_LAST")
573
632
  [ -n "$EFFORT" ] && CMD+=(-c "model_reasoning_effort=$EFFORT")
574
633
  [ "$SERVICE_TIER" = fast ] && CMD+=(-c "service_tier=fast")
575
634
  if [ "$YOLO" = 1 ]; then CMD+=(--dangerously-bypass-approvals-and-sandbox)
@@ -578,7 +637,7 @@ build_cmd() {
578
637
  CMD+=(-)
579
638
  PROMPT_VIA_STDIN=1
580
639
  else
581
- CMD=(codex exec --json -m "$MODEL" -C "$REPO" --skip-git-repo-check -o "$LAST")
640
+ CMD=(codex exec --json -m "$MODEL" -C "$D_REPO" --skip-git-repo-check -o "$D_LAST")
582
641
  [ -n "$EFFORT" ] && CMD+=(-c "model_reasoning_effort=$EFFORT")
583
642
  [ "$SERVICE_TIER" = fast ] && CMD+=(-c "service_tier=fast")
584
643
  # --approve-for-me and --dangerously-bypass-... are mutually exclusive.
@@ -593,7 +652,7 @@ build_cmd() {
593
652
  # The run dir sits outside the repo (so it stays out of the diff), which also
594
653
  # puts it outside the harness's default reach — without this the agent
595
654
  # refuses to open the very artifacts forge just wrote for it.
596
- CMD=("$HARNESS" -p --model "$MODEL" --add-dir "$RUN_DIR")
655
+ CMD=("$HARNESS" -p --model "$MODEL" --add-dir "$D_RUN_DIR")
597
656
  # One JSON message per line: what the agent said and every tool call, so the run keeps
598
657
  # its conversation (forge-ui reads it), ending in the `result` line forge-runtime.py
599
658
  # takes the final message and the tokens from. stream-json needs --verbose with -p.
@@ -639,7 +698,7 @@ build_cmd() {
639
698
  PROMPT_VIA_STDIN=1
640
699
  ;;
641
700
  opencode)
642
- CMD=(opencode run -m "$MODEL" --dir "$REPO")
701
+ CMD=(opencode run -m "$MODEL" --dir "$D_REPO")
643
702
  [ -n "$EFFORT" ] && CMD+=(--variant "$EFFORT")
644
703
  # opencode run exposes no sandbox tier — without --auto it blocks on a
645
704
  # permission prompt that nothing can answer headlessly, so it is always set.
@@ -660,7 +719,7 @@ build_cmd() {
660
719
  # --add-dir on the repo is not optional. Antigravity is workspace-scoped
661
720
  # rather than cwd-scoped, so without it the agent searches the wrong tree and
662
721
  # the run dies on "Find command timed out: context deadline exceeded".
663
- CMD+=(--add-dir "$REPO" --add-dir "$RUN_DIR")
722
+ CMD+=(--add-dir "$D_REPO" --add-dir "$D_RUN_DIR")
664
723
  if [ "$YOLO" = 1 ]; then CMD+=(--dangerously-skip-permissions)
665
724
  elif read_only_role; then CMD+=(--mode plan)
666
725
  else CMD+=(--mode accept-edits); fi
@@ -672,7 +731,7 @@ build_cmd() {
672
731
  # claude gives without acceptEdits, so the dwarf gets edits and the whole shell.
673
732
  # The Messages-format stream ends in a claude-shaped `result` line, which
674
733
  # forge-runtime.py reads for the final message and the tokens.
675
- CMD=(grok --model "$MODEL" --prompt-file "$PROMPT_FILE" --output-format streaming-messages-json)
734
+ CMD=(grok --model "$MODEL" --prompt-file "$D_PROMPT_FILE" --output-format streaming-messages-json)
676
735
  [ -n "$EFFORT" ] && CMD+=(--reasoning-effort "$EFFORT")
677
736
  # After its last turn a headless run waits for the background work it started (a test
678
737
  # suite, say) and wakes the model with each result, but by default for only 600 s: then
@@ -693,6 +752,9 @@ build_cmd() {
693
752
  ;;
694
753
  *) die "no dispatch recipe for harness '$HARNESS'" ;;
695
754
  esac
755
+ if [ -n "${RESOLVED_BIN:-}" ] && ! command -v "$(binary_for "$HARNESS")" >/dev/null 2>&1; then
756
+ CMD[0]="$RESOLVED_BIN"
757
+ fi
696
758
  }
697
759
  # A read-only role's own writable temp dir (#148). Test runners need one (Vitest's EPERM in a
698
760
  # read-only sandbox), and the role gets none otherwise. It sits in the run dir, outside the
@@ -700,12 +762,15 @@ build_cmd() {
700
762
  # point at it, and the dispatch removes it when it ends. A dry run or a preflight only shows
701
763
  # its shape.
702
764
  ROLE_TMP=""
765
+ D_ROLE_TMP=""
703
766
  if read_only_role; then
704
767
  if [ -n "$ATTEMPT" ]; then
705
768
  ROLE_TMP="$(mktemp -d "$RUN_DIR/.$ROLE-tmp.XXXXXX")" || ROLE_TMP=""
706
769
  else
707
770
  ROLE_TMP="$RUN_DIR/.$ROLE-tmp.XXXXXX"
708
771
  fi
772
+ D_ROLE_TMP="$ROLE_TMP"
773
+ [ -z "$ROLE_TMP" ] || ! forge_is_windows || D_ROLE_TMP="$(forge_host_path "$ROLE_TMP")"
709
774
  fi
710
775
  build_cmd
711
776
 
@@ -735,7 +800,12 @@ unadvertised_flag() { # unadvertised_flag <help text>
735
800
  preflight_command() {
736
801
  local bin help flag request="$CONTINUE_ID"
737
802
  local help_args=(--help) continue_args=(--help)
738
- bin="$(command -v "$(binary_for "$HARNESS")")" || die "harness '$HARNESS' is not installed" 3
803
+ bin="$(resolve_binary "$HARNESS")" || die "harness '$HARNESS' is not installed" 3
804
+ ! forge_is_windows || bin="$(forge_host_path "$bin")"
805
+ RESOLVED_BIN="$bin"
806
+ if ! command -v "$(binary_for "$HARNESS")" >/dev/null 2>&1; then
807
+ CMD[0]="$RESOLVED_BIN"
808
+ fi
739
809
  case "$HARNESS" in
740
810
  codex) help_args=(exec --help); continue_args=(exec resume --help); [ "$NATIVE_REVIEW" = 1 ] && help_args=(exec review --help) ;;
741
811
  opencode) help_args=(run --help) ;;
@@ -829,7 +899,11 @@ fi
829
899
  if [ "$YOLO" = 1 ]; then
830
900
  note "YOLO: $HARNESS runs with sandbox and approvals disabled in $REPO"
831
901
  fi
832
- [ -n "$(command -v "$(binary_for "$HARNESS")")" ] || die "harness '$HARNESS' is not installed ($(binary_for "$HARNESS") not on PATH)" 3
902
+ RESOLVED_BIN="$(resolve_binary "$HARNESS")" || die "harness '$HARNESS' is not installed ($(binary_for "$HARNESS") not on PATH)" 3
903
+ ! forge_is_windows || RESOLVED_BIN="$(forge_host_path "$RESOLVED_BIN")"
904
+ if ! command -v "$(binary_for "$HARNESS")" >/dev/null 2>&1; then
905
+ CMD[0]="$RESOLVED_BIN"
906
+ fi
833
907
 
834
908
  # Harnesses that take the prompt on argv get stdin redirected from /dev/null:
835
909
  # codex exec otherwise blocks waiting to append piped input to the prompt, which
@@ -861,14 +935,17 @@ case "${FORGE_ORPHAN_GUARD:-on}" in off|OFF|Off|0|no|false) ;; *)
861
935
  if [ -z "${FORGE_FRACTAL_RUN:-}" ] && [ -r "$GUARD" ] && [ "$(python3 "$GUARD" ping 2>/dev/null)" = ok ]; then GUARD_ON=1; fi ;;
862
936
  esac
863
937
  RUNCMD=("${CMD[@]}")
864
- [ "$GUARD_ON" != 1 ] || RUNCMD=(python3 "$GUARD" session -- "${CMD[@]}")
865
- role_env() { [ -z "$ROLE_TMP" ] || export TMPDIR="$ROLE_TMP" TMP="$ROLE_TMP" TEMP="$ROLE_TMP"; }
938
+ # Windows MSYS2 mode (forge-win.sh): the harness gets the PATH it had in Git Bash, not MSYS2's.
939
+ [ -z "${FORGE_WIN_AGENT_PATH:-}" ] || RUNCMD=(env -u MSYS -u FORGE_WIN_AGENT_PATH "PATH=$FORGE_WIN_AGENT_PATH" "MSYSTEM=${FORGE_WIN_MSYSTEM-}" "${CMD[@]}")
940
+ [ "$GUARD_ON" != 1 ] || RUNCMD=(python3 "$D_GUARD" session -- "${RUNCMD[@]}")
941
+ role_env() { [ -z "$D_ROLE_TMP" ] || export TMPDIR="$D_ROLE_TMP" TMP="$D_ROLE_TMP" TEMP="$D_ROLE_TMP"; }
866
942
  if [ "$PROMPT_VIA_STDIN" = 1 ]; then
867
- ( cd "$REPO" && role_env && exec "${RUNCMD[@]}" < "$PROMPT_FILE" ) > "$LOG" 2>&1 &
943
+ ( cd "$REPO" && role_env && { ! forge_is_windows || export MSYS_NO_PATHCONV=1; } && exec "${RUNCMD[@]}" < "$PROMPT_FILE" ) > "$LOG" 2>&1 &
868
944
  else
869
- ( cd "$REPO" && role_env && exec "${RUNCMD[@]}" </dev/null ) > "$LOG" 2>&1 &
945
+ ( cd "$REPO" && role_env && { ! forge_is_windows || export MSYS_NO_PATHCONV=1; } && exec "${RUNCMD[@]}" </dev/null ) > "$LOG" 2>&1 &
870
946
  fi
871
947
  hpid=$!
948
+ hwinpid="$(forge_winpid "$hpid")"
872
949
  # Log clock: when the log grew, so forge-ui can time the commands of a harness whose events
873
950
  # carry no time (codex, grok). Advisory and off with FORGE_LOG_CLOCK=off; it ends on its own
874
951
  # if this dispatch dies first.
@@ -881,9 +958,9 @@ esac
881
958
  # (forge-guard.py stop) in case this dispatch dies before the trap finishes. The start time
882
959
  # tells the pid apart from a later reuse, and survives the exec chain $! still goes through.
883
960
  if [ "$GUARD_ON" = 1 ]; then
884
- hident="$(python3 "$GUARD" identity "$hpid" 2>/dev/null)" || hident=""
961
+ hident="$(python3 "$GUARD" identity "$hwinpid" 2>/dev/null)" || hident=""
885
962
  if [ -n "$hident" ]; then
886
- printf '%s\t%s\n' "$hpid" "$hident" > "$RUN_DIR/.$ROLE.harness.tmp" \
963
+ printf '%s\t%s\n' "$hwinpid" "$hident" > "$RUN_DIR/.$ROLE.harness.tmp" \
887
964
  && mv -f "$RUN_DIR/.$ROLE.harness.tmp" "$RUN_DIR/$ROLE.harness"
888
965
  fi
889
966
  fi
@@ -892,19 +969,19 @@ fi
892
969
  # it as a descendant, so the reap finds it by pid and start time. Advisory, like the guard.
893
970
  tpid=""
894
971
  if [ "$GUARD_ON" = 1 ]; then
895
- python3 "$GUARD" track "$hpid" "$RUN_DIR/$ROLE.tracked" </dev/null >/dev/null 2>&1 & tpid=$!
972
+ python3 "$GUARD" track "$hwinpid" "$RUN_DIR/$ROLE.tracked" </dev/null >/dev/null 2>&1 & tpid=$!
896
973
  fi
897
974
 
898
975
  # Ends the harness: the whole process group first when the harness has its own (GUARD_ON),
899
976
  # then children, then the process itself, then SIGKILL for a CLI that traps TERM and takes
900
977
  # its time. Without the guard there is no group to signal as a unit.
901
978
  stop_harness() {
902
- [ "$GUARD_ON" != 1 ] || kill -s TERM -- "-$hpid" 2>/dev/null
903
- pkill -TERM -P "$hpid" 2>/dev/null
979
+ [ "$GUARD_ON" != 1 ] || forge_kill_group "$hpid" TERM
980
+ forge_kill_children "$hpid" TERM
904
981
  kill -TERM "$hpid" 2>/dev/null
905
982
  sleep 5
906
- [ "$GUARD_ON" != 1 ] || kill -s KILL -- "-$hpid" 2>/dev/null
907
- pkill -KILL -P "$hpid" 2>/dev/null
983
+ [ "$GUARD_ON" != 1 ] || forge_kill_group "$hpid" KILL
984
+ forge_kill_children "$hpid" KILL
908
985
  kill -KILL "$hpid" 2>/dev/null
909
986
  }
910
987
 
@@ -929,7 +1006,7 @@ spid=""
929
1006
  case "$HARNESS" in claude|openclaude)
930
1007
  if [ "$RESULT_GRACE" != 0 ]; then
931
1008
  (
932
- python3 "$RUNTIME" settle "$LOG" "$RESULT_GRACE" "$hpid" </dev/null || exit 0
1009
+ python3 "$RUNTIME" settle "$LOG" "$RESULT_GRACE" "$hwinpid" </dev/null || exit 0
933
1010
  kill -0 "$hpid" 2>/dev/null || exit 0
934
1011
  : > "$RUN_DIR/$ROLE.settled"
935
1012
  stop_harness
@@ -950,7 +1027,7 @@ fi
950
1027
  for watcher in $wpid $spid; do
951
1028
  # The watchdog is asleep in a child of its own, and so is the grace watcher; kill that
952
1029
  # too or it outlives the run as an orphan holding the timer.
953
- pkill -P "$watcher" 2>/dev/null
1030
+ forge_kill_children "$watcher" TERM
954
1031
  kill "$watcher" 2>/dev/null
955
1032
  wait "$watcher" 2>/dev/null
956
1033
  done
@@ -961,7 +1038,7 @@ done
961
1038
  # changes nothing about the exit code.
962
1039
  if [ -n "$tpid" ]; then kill -TERM "$tpid" 2>/dev/null; wait "$tpid" 2>/dev/null; tpid=""; fi
963
1040
  if [ "$GUARD_ON" = 1 ]; then
964
- orphans_found="$(python3 "$GUARD" reap "$hpid" "$RUN_DIR/$ROLE.orphans" --tracked "$RUN_DIR/$ROLE.tracked" 2>/dev/null)"
1041
+ orphans_found="$(python3 "$GUARD" reap "$hwinpid" "$RUN_DIR/$ROLE.orphans" --tracked "$RUN_DIR/$ROLE.tracked" 2>/dev/null)"
965
1042
  case "$orphans_found" in ''|*[!0-9]*|0) ;; *) note "$HARNESS left $orphans_found process(es) running after it exited; killed — see $RUN_DIR/$ROLE.orphans" ;; esac
966
1043
  fi
967
1044
  reaped=1
@@ -42,6 +42,7 @@ from pathlib import Path
42
42
 
43
43
  sys.path.insert(0, str(Path(__file__).resolve().parent))
44
44
  import forge_groups # noqa: E402
45
+ import forge_proc # noqa: E402
45
46
 
46
47
  SCRIPTS = Path(__file__).resolve().parent
47
48
  PARALLEL = SCRIPTS / 'forge-parallel.sh'
@@ -346,7 +347,7 @@ def rearm(plan: str, gid: str, seen: str, reason: str) -> None:
346
347
  def run_settle(plan: str, gid: str, tasks: list) -> int:
347
348
  """_group_settle --tasks. Outside the control lock: post_attempt takes that same lock
348
349
  when the retry policy writes a marker, and holding it here would time that write out."""
349
- command = ['/bin/bash', str(PARALLEL), '_group_settle', plan, gid, '--tasks', ','.join(tasks)]
350
+ command = forge_proc.bash_cmd(PARALLEL, '_group_settle', plan, gid, '--tasks', ','.join(tasks))
350
351
  try:
351
352
  result = subprocess.run(command, capture_output=True, text=True, timeout=120)
352
353
  except OSError as error: