@giamme/forge 0.14.1 → 0.16.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 (81) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/SKILL.md +47 -14
  3. package/VERSION +1 -1
  4. package/docs/artifacts.md +1 -1
  5. package/docs/commands.md +302 -9
  6. package/docs/forge-ui.md +14 -0
  7. package/docs/memory.md +22 -0
  8. package/docs/models.md +53 -0
  9. package/docs/reviews.md +7 -0
  10. package/forge +11 -0
  11. package/package.json +1 -1
  12. package/references/dataset.md +16 -4
  13. package/references/decompose.md +154 -9
  14. package/references/harnesses.md +21 -1
  15. package/references/planning.md +59 -0
  16. package/references/solo.md +5 -1
  17. package/references/ui.md +48 -1
  18. package/scripts/forge-artifact.sh +53 -0
  19. package/scripts/forge-compare.py +6 -3
  20. package/scripts/forge-config.py +531 -4
  21. package/scripts/forge-contract.py +55 -8
  22. package/scripts/forge-control.py +0 -2
  23. package/scripts/forge-dispatch.sh +84 -14
  24. package/scripts/forge-fail-first.py +3 -1
  25. package/scripts/forge-guard.py +247 -8
  26. package/scripts/forge-issues.py +12 -0
  27. package/scripts/forge-lib-adopt.sh +260 -0
  28. package/scripts/forge-lib-attribute.sh +10 -2
  29. package/scripts/forge-lib-plans.sh +35 -6
  30. package/scripts/forge-lib-review.sh +13 -5
  31. package/scripts/forge-lib-task.sh +138 -5
  32. package/scripts/forge-memory.sh +41 -4
  33. package/scripts/forge-metrics.sh +7 -0
  34. package/scripts/forge-parallel-options.sh +12 -6
  35. package/scripts/forge-parallel.sh +659 -32
  36. package/scripts/forge-plan-check.py +591 -8
  37. package/scripts/forge-planner.py +480 -0
  38. package/scripts/forge-route.py +16 -2
  39. package/scripts/forge-runs-rm.py +23 -7
  40. package/scripts/forge-runtime.py +111 -2
  41. package/scripts/forge-schedule.py +5 -2
  42. package/scripts/forge-shadow.py +53 -7
  43. package/scripts/forge-solo.sh +87 -7
  44. package/scripts/forge_dataset/cli.py +26 -0
  45. package/scripts/forge_dataset/efforts.py +215 -0
  46. package/scripts/forge_dataset/export.py +1 -0
  47. package/scripts/forge_dataset/harvest.py +55 -0
  48. package/scripts/forge_dataset/history.py +126 -0
  49. package/scripts/forge_dataset/worktrees.py +95 -0
  50. package/scripts/forge_decide/__init__.py +19 -1
  51. package/scripts/forge_decide/builtin_profiles.json +25 -0
  52. package/scripts/forge_decide/cli.py +12 -0
  53. package/scripts/forge_decide/profiles.py +866 -0
  54. package/scripts/forge_decide/resolve.py +38 -6
  55. package/scripts/forge_memory_list.py +153 -0
  56. package/scripts/forge_worktrees.py +88 -0
  57. package/ui/README.md +31 -0
  58. package/ui/docs/api.md +168 -12
  59. package/ui/forge_ui/__init__.py +14 -1
  60. package/ui/forge_ui/__main__.py +1 -1
  61. package/ui/forge_ui/control.py +250 -12
  62. package/ui/forge_ui/executions.py +28 -8
  63. package/ui/forge_ui/findings.py +7 -0
  64. package/ui/forge_ui/models.py +60 -1
  65. package/ui/forge_ui/projects.py +571 -0
  66. package/ui/forge_ui/reader.py +48 -8
  67. package/ui/forge_ui/static/app.js +99 -21
  68. package/ui/forge_ui/static/cloudui.js +6 -2
  69. package/ui/forge_ui/static/convo.js +1 -1
  70. package/ui/forge_ui/static/diffview.js +2 -2
  71. package/ui/forge_ui/static/files.js +1 -1
  72. package/ui/forge_ui/static/index.html +5 -1
  73. package/ui/forge_ui/static/leaderboard.js +5 -1
  74. package/ui/forge_ui/static/modelstats.js +25 -1
  75. package/ui/forge_ui/static/panel.js +47 -4
  76. package/ui/forge_ui/static/projectsview.js +372 -0
  77. package/ui/forge_ui/static/settings.js +924 -29
  78. package/ui/forge_ui/static/style.css +116 -3
  79. package/ui/forge_ui/static/uikit.js +94 -1
  80. package/ui/forge_ui/static/worktreesview.js +250 -0
  81. package/ui/forge_ui/worktrees.py +570 -0
@@ -264,6 +264,84 @@ def session_id(log: str, harness: str) -> str | None:
264
264
  return result_id if type(result_id) is str else None
265
265
 
266
266
 
267
+ _TIER_UNSUPPORTED = 'is not advertised as supported for model'
268
+
269
+
270
+ def read_speed(log: str, harness: str) -> tuple[str | None, str | None]:
271
+ """The speed the harness actually ran at, and why it was not fast.
272
+
273
+ claude: `usage.speed` of the last result, and `fast_mode_disabled_reason` when
274
+ that speed is not `fast`. codex: `default` and the error message when an
275
+ `item.completed` error says the tier is not advertised for the model; otherwise
276
+ the stream says nothing. Any other harness, or a log that does not say, is unknown.
277
+ """
278
+ if harness == 'codex':
279
+ reason = None
280
+ for event in _events(log)[0]:
281
+ if event.get('type') != 'item.completed':
282
+ continue
283
+ item = event.get('item')
284
+ if not isinstance(item, dict) or item.get('type') != 'error':
285
+ continue
286
+ message = item.get('message')
287
+ if isinstance(message, str) and _TIER_UNSUPPORTED in message:
288
+ reason = message
289
+ return ('default', reason) if reason else (None, None)
290
+ if harness != 'claude':
291
+ return None, None
292
+ speed = reason = None
293
+ saw = False
294
+ for event in _events(log)[0]:
295
+ if event.get('type') != 'result':
296
+ continue
297
+ saw = True
298
+ usage = event.get('usage')
299
+ value = usage.get('speed') if isinstance(usage, dict) else None
300
+ speed = value if isinstance(value, str) and value else None
301
+ disabled = event.get('fast_mode_disabled_reason')
302
+ reason = disabled if isinstance(disabled, str) and disabled else None
303
+ if not saw or not speed:
304
+ return None, None
305
+ if speed == 'fast':
306
+ return speed, None
307
+ return speed, reason
308
+
309
+
310
+ def speed_note(harness: str, asked: str | None, speed: str | None, reason: str | None) -> str | None:
311
+ """The one line to print when `asked` is fast and the log ran slower, else None."""
312
+ if asked != 'fast' or not speed or speed == 'fast':
313
+ return None
314
+ if harness == 'claude' and reason:
315
+ return '%s ran at %s speed: fast mode is unavailable (%s)' % (harness, speed, reason)
316
+ if reason:
317
+ return '%s ran at %s speed: %s' % (harness, speed, reason)
318
+ return '%s ran at %s speed' % (harness, speed)
319
+
320
+
321
+ def _resolved_service_tier(root: Path, role: str) -> str | None:
322
+ path = root / (role + '.resolved')
323
+ if not path.exists():
324
+ return None
325
+ found = None
326
+ prefix = 'service_tier='
327
+ for line in path.read_text(errors='replace').splitlines():
328
+ if line.startswith(prefix):
329
+ found = line[len(prefix):].strip() or None
330
+ return found
331
+
332
+
333
+ def speed_command(log: str, harness: str) -> None:
334
+ """Print the slower-speed note for a log, or nothing. Exit stays 0."""
335
+ try:
336
+ text = Path(log).read_text(errors='replace')
337
+ except OSError:
338
+ return
339
+ speed, reason = read_speed(text, harness)
340
+ note = speed_note(harness, 'fast', speed, reason)
341
+ if note:
342
+ print(note)
343
+
344
+
267
345
  def finish(attempt: str, root: str, role: str, harness: str, rc: str) -> None:
268
346
  try:
269
347
  _finish(Path(attempt), Path(root), role, harness, rc)
@@ -279,6 +357,7 @@ def _finish(attempt: Path, root: Path, role: str, harness: str, rc: str) -> None
279
357
  text = log.read_text(errors='replace') if structured and log.exists() else ''
280
358
  final, usage = extract(text, harness)
281
359
  found = session_id(text, harness)
360
+ speed, speed_reason = read_speed(text, harness)
282
361
  if not last.exists() or not last.stat().st_size:
283
362
  if final is not None:
284
363
  last.write_text(final + '\n')
@@ -292,6 +371,9 @@ def _finish(attempt: Path, root: Path, role: str, harness: str, rc: str) -> None
292
371
  harness=harness,
293
372
  prompt_bytes=prompt.stat().st_size if prompt_ready else None,
294
373
  session_id=found,
374
+ service_tier=_resolved_service_tier(root, role),
375
+ speed=speed,
376
+ speed_reason=speed_reason,
295
377
  **usage,
296
378
  )
297
379
  infra = root / (role + '.infra')
@@ -550,11 +632,30 @@ def _codex_terminal_errors(events: list) -> list[str]:
550
632
  error = event.get('error')
551
633
  message = error.get('message') if isinstance(error, dict) else error
552
634
  pending.append(message if isinstance(message, str) else json.dumps(event))
635
+ elif kind == 'item.completed' and isinstance(event.get('item'), dict) and event['item'].get('type') == 'error':
636
+ pass # a notice ("Falling back from WebSockets to HTTPS"), not the run going on
553
637
  else:
554
638
  pending = [] # any later activity means the run went on past the error
555
639
  return pending
556
640
 
557
641
 
642
+ # codex's own words for a connection that never came up (#114). Only the message it stopped on
643
+ # answers to these, or stderr when it emitted no event at all: beside a turn, the same words on
644
+ # stderr are routine (an MCP server's transport, a model-list refresh) while the turn fails for its
645
+ # own reason, an early reconnect notice says nothing about a later failure, and "request timed out"
646
+ # in another harness's raw log may be a test's output.
647
+ _CODEX_NETWORK = _P(r"\bworkspace routing discovery (?:failed|timed out)\b|\berror sending request\b|\brequest timed out\b", re.I)
648
+ _CODEX_RECONNECTS_SPENT = _P(r"\bReconnecting\.\.\. (\d+)/\1\b")
649
+
650
+
651
+ def _codex_network(pending: list, now: float | None = None):
652
+ """A network stop when codex stopped on its own network wording, or after using up its
653
+ reconnect loop whatever it said next. None otherwise."""
654
+ if pending and (_CODEX_NETWORK.search(pending[-1]) or any(_CODEX_RECONNECTS_SPENT.search(m) for m in pending)):
655
+ return 'network', retry_after('\n'.join(pending), now), _one_line(pending[-1])
656
+ return None
657
+
658
+
558
659
  def _codex_final(events: list, last: str) -> str:
559
660
  try:
560
661
  path = Path(last) if last else None
@@ -599,11 +700,15 @@ def classify(log: str, harness: str, rc: object, last: str = '', role: str = '',
599
700
  if final.strip():
600
701
  return None
601
702
  if pending:
602
- hit = classify_text('\n'.join(pending), now=now)
703
+ hit = classify_text('\n'.join(pending), now=now) or _codex_network(pending, now)
603
704
  if hit:
604
705
  return hit
605
706
  return 'empty', None, 'codex finished with exit 0 but produced no final message'
606
- return classify_text('\n'.join(pending + [_tail(stray)]), now=now)
707
+ hit = classify_text('\n'.join(pending + [_tail(stray)]), now=now) or _codex_network(pending, now)
708
+ if hit or events:
709
+ return hit
710
+ # It died before its first event, so stderr is all it said and no turn gave another reason.
711
+ return _codex_network([line for line in stray if _CODEX_NETWORK.search(line)], now)
607
712
 
608
713
  if harness == 'opencode' and events:
609
714
  # Like codex: an error event counts when the run produced no answer after it.
@@ -761,6 +866,10 @@ def main() -> None:
761
866
  settle(*args)
762
867
  elif command == 'settled':
763
868
  settled_command(*args)
869
+ elif command == 'speed':
870
+ if len(args) != 2:
871
+ raise ValueError('usage: forge-runtime.py speed LOG HARNESS')
872
+ speed_command(*args)
764
873
  else:
765
874
  raise ValueError('unknown runtime command: ' + command)
766
875
  except (OSError, ValueError, RuntimeError) as error:
@@ -631,6 +631,10 @@ def schedule(script: str, plan: str, capacity: int, retry_failed: int = 0,
631
631
  backoff_warned = [] # an invalid infra_backoff file is reported once
632
632
  graceful = False # `forge control stop`: start nothing more, end once running tasks are done
633
633
  human = set() # tasks whose next dispatch is a `forge control retry` (dataset trigger human)
634
+ for name in tasks: # `retry --no-dispatch` (#118) prepared it for this run: still a person's retry
635
+ if (plan / 'tasks' / name / 'retry.prepared').exists():
636
+ retried.add(name)
637
+ human.add(name)
634
638
  fractal = _fractal_plan(plan)
635
639
  drain_told = False # the drained message was printed for this drain
636
640
  sweep_asked = False # this invocation already asked for the finding sweep
@@ -1083,8 +1087,6 @@ def schedule(script: str, plan: str, capacity: int, retry_failed: int = 0,
1083
1087
  return 'refused', (name + ' is waiting for your decision, and only a decision resumes it: '
1084
1088
  + decision_head(plan, name) + ' (retry --decide retry=N | threshold=Pn, or --dwarf SPEC,'
1085
1089
  + ' with --reason and --approved)')
1086
- if decide and dwarf:
1087
- return 'refused', 'give --decide or --dwarf, not both: a decision is one choice'
1088
1090
  if not (reason or '').strip() or not approved:
1089
1091
  return 'refused', name + ' is waiting for your decision: a decision needs --reason and --approved'
1090
1092
  decision = (['--decide', decide] if decide else []) + ['--reason', reason, '--approved']
@@ -1356,6 +1358,7 @@ def schedule(script: str, plan: str, capacity: int, retry_failed: int = 0,
1356
1358
  FORGE_DATASET_TRIGGER='human' if name in human else 'auto')
1357
1359
  if name in retried else None)
1358
1360
  human.discard(name)
1361
+ _remove(plan, 'tasks', name, 'retry.prepared')
1359
1362
  process = subprocess.Popen(
1360
1363
  ['/bin/bash', script, '_task', str(plan), name],
1361
1364
  stdout=log, stderr=subprocess.STDOUT, start_new_session=True, env=env,
@@ -11,7 +11,9 @@ turns this on for a sampled share of reviewed attempts (`--shadow-rate`, default
11
11
  dir under <plan>/shadow/<id>/<attempt>-<k>/, reviews a byte-identical copy of the
12
12
  primary's qa.input, and returns. Never exits nonzero.
13
13
  forge-shadow.py preflight --plan P
14
- Which listed shadow specs resolve here; writes <plan>/shadow_qa.ok. Never fails a run.
14
+ Which listed shadow specs resolve here; writes <plan>/shadow_qa.ok. A spec that
15
+ cannot run here is skipped. A fast-tier refusal stops the run with dispatch's
16
+ own message and exit code, before any model call.
15
17
 
16
18
  Guarantees, because the task waits for this process before it writes any status:
17
19
  - nothing reads the shadow's result in the run path; it changes no status, memory,
@@ -49,6 +51,36 @@ STOP_WAIT_S = 10
49
51
  PREPARE_TIMEOUT_S = 120
50
52
 
51
53
 
54
+ def plan_is_fractal(plan: Path) -> bool:
55
+ """True when this plan's saved selection says Fractal runs the dispatches."""
56
+ try:
57
+ data = json.loads((plan / 'fractal-selection.json').read_text())
58
+ except (OSError, ValueError):
59
+ return False
60
+ return isinstance(data, dict) and bool(data.get('enabled'))
61
+
62
+
63
+ def service_tier_args(plan: Path, role: str) -> list[str]:
64
+ """`--service-tier fast` when <role> is a line of <plan>/fast, and nothing otherwise.
65
+
66
+ Fractal dispatches through its own runner and does not take the option. A retry
67
+ preflights before that runner is selected, so a plan whose selection is already on
68
+ is the same case for every role it dispatches. A whole-run review is not one of them.
69
+ Specs never change.
70
+ """
71
+ if os.environ.get('FORGE_FRACTAL_RUN'):
72
+ return []
73
+ try:
74
+ text = (plan / 'fast').read_text()
75
+ except OSError:
76
+ return []
77
+ if role not in [line.strip() for line in text.splitlines() if line.strip()]:
78
+ return []
79
+ if role != 'review' and plan_is_fractal(plan):
80
+ return []
81
+ return ['--service-tier', 'fast']
82
+
83
+
52
84
  def rate_of(plan: Path) -> float:
53
85
  try:
54
86
  rate = float((plan / 'shadow_rate').read_text().strip())
@@ -197,6 +229,8 @@ def run(args) -> int:
197
229
  if bash('forge_review_snapshot', args.worktree, args.base, args.reviewed, str(review)).returncode:
198
230
  status = 'error'
199
231
  return 0
232
+ # The prompt is the primary's, so this checkout has to hold what it says.
233
+ bash('forge_review_deps', args.worktree, str(review), os.devnull)
200
234
  before = bash('forge_fingerprint', str(review), '--tracked').stdout.strip()
201
235
  shutil.copyfile(Path(args.tdir) / 'qa.input', out / 'qa.input')
202
236
  env = dict(os.environ, FORGE_SHADOW='1', FORGE_SHADOW_ATTEMPT=args.attempt,
@@ -207,6 +241,7 @@ def run(args) -> int:
207
241
  '--output', 'summary']
208
242
  if args.yolo:
209
243
  argv.append('--yolo')
244
+ argv.extend(service_tier_args(plan, 'qa'))
210
245
  with open(out / 'shadow.out', 'wb') as log:
211
246
  STATE['child'] = subprocess.Popen(argv, stdin=subprocess.DEVNULL, stdout=log, stderr=subprocess.STDOUT,
212
247
  env=env, close_fds=True)
@@ -269,16 +304,27 @@ def preflight(args) -> int:
269
304
  ok = []
270
305
  for spec in listed:
271
306
  flags = ['--yolo'] if (plan / 'yolo_qa').exists() else []
307
+ flags.extend(service_tier_args(plan, 'qa'))
272
308
  try:
273
309
  result = subprocess.run(['/bin/bash', str(DISPATCH), 'doctor', '--spec', spec, '--role', 'qa', *flags],
274
- stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, timeout=120)
275
- good = result.returncode == 0
310
+ stdout=subprocess.PIPE, stderr=subprocess.STDOUT, timeout=120, text=True)
276
311
  except (OSError, subprocess.SubprocessError):
277
- good = False
278
- if good:
279
- ok.append(spec)
280
- else:
281
312
  print('forge: shadow review spec %s is not usable here; it is skipped' % spec, file=sys.stderr)
313
+ continue
314
+ if result.returncode == 0:
315
+ ok.append(spec)
316
+ continue
317
+ # Dispatch refuses a fast tier the harness cannot take (exit 3) before it checks
318
+ # that the binary exists, and both failures share that exit. The message is how
319
+ # they differ. Re-emit it unchanged and stop: skipping the shadow would let the
320
+ # dwarf and the primary review run and be billed.
321
+ text = result.stdout or ''
322
+ if result.returncode == 3 and 'has no per-invocation fast tier' in text:
323
+ sys.stderr.write(text)
324
+ if text and not text.endswith('\n'):
325
+ sys.stderr.write('\n')
326
+ return 3
327
+ print('forge: shadow review spec %s is not usable here; it is skipped' % spec, file=sys.stderr)
282
328
  write(plan / 'shadow_qa.ok', ','.join(ok) + '\n')
283
329
  if listed and not ok:
284
330
  print('forge: no shadow review spec is usable; shadow reviews are off for this run', file=sys.stderr)
@@ -20,6 +20,13 @@
20
20
  # [--approach <file>] [--yolo-dwarf] [--yolo-qa]
21
21
  # [--native-review] [--no-memory] [--timeout <s>] [--dry-run] [--ui]
22
22
  # [--fail-first] [--qa-threshold P0|P1|P2|P3|none]
23
+ # [--fast ROLES] dwarf, qa or none (planner, review and all are refused);
24
+ # kept in <run-dir>/fast. none removes it; omitting it keeps it
25
+ # [--profile NAME | --no-profile] a named profile (forge config profile list) picks
26
+ # the dwarf and qa (its medium pool, else its any pool), the QA
27
+ # threshold, the timeout and the fast roles that no flag gives;
28
+ # frozen in <run-dir>/profile.json, which later runs of the dir keep.
29
+ # With neither flag, that copy, else the default profile, applies
23
30
  #
24
31
  # Reads <run-dir>/prompt.md the implementation instruction (required)
25
32
  # <run-dir>/goal.txt one line, what the user asked for (optional)
@@ -29,6 +36,7 @@
29
36
  # <run-dir>/verdict PASS | FAIL | UNKNOWN, when qa emitted one (after the severity gate)
30
37
  # <run-dir>/qa.gate, known_issues.md the gate's decision and the tolerated findings
31
38
  # <run-dir>/qa_threshold with --qa-threshold: the blocking level (default P2)
39
+ # <run-dir>/profile.json with a profile: the frozen copy of it
32
40
  # <run-dir>/failfirst.json with --fail-first: do the change's tests fail without it?
33
41
  # <run-dir>/status RUNNING, then this invocation's outcome
34
42
  # <run-dir>/dwarf.spec, qa.spec and attempts.tsv
@@ -95,7 +103,7 @@ forge_metric_on_exit() {
95
103
  }
96
104
 
97
105
  if [ "${1:-}" = --help ] || [ "${1:-}" = -h ]; then
98
- sed -n '18,39s/^# *//p' "$0"
106
+ sed -n '18,47s/^# *//p' "$0"
99
107
  forge_fractal_help
100
108
  echo 'Explicit Fractal retry: repeat the original command with --retry.'
101
109
  exit 0
@@ -104,8 +112,12 @@ RUN="${1:-}"; [ -n "$RUN" ] || die "usage: forge-solo.sh <run-dir> --repo <dir>
104
112
  case "$RUN" in -*) die "first argument must be the run directory, got '$RUN'" ;; esac
105
113
  shift
106
114
 
115
+ # --- profiles (#48): the same reading, freezing and exporting as forge-parallel.sh's plan ---
116
+ forge_profile_py() { PYTHONPATH="$SKILL_DIR/scripts${PYTHONPATH:+:$PYTHONPATH}" python3 -m forge_decide.profiles "$@"; }
117
+
107
118
  OUTPUT=summary
108
119
  REPO="$PWD"; DWARF=""; QA="opus"; APPROACH=""; YD=""; YQ=""; NATIVE=""; TIMEOUT=""; DRY=0; FAIL_FIRST=0; QA_THR=
120
+ FAST_GIVEN=0; FAST_PARSED=""; QA_GIVEN=0; PF_NAME=""; PF_NONE=0
109
121
  while [ $# -gt 0 ]; do
110
122
  case "$1" in
111
123
  --fractal) forge_fractal_flag on || exit $?; shift ;;
@@ -116,7 +128,9 @@ while [ $# -gt 0 ]; do
116
128
  --output) OUTPUT="${2:?}"; shift 2 ;;
117
129
  --repo) REPO="${2:?--repo needs a value}"; shift 2 ;;
118
130
  --dwarf) DWARF="${2:?--dwarf needs a spec}"; shift 2 ;;
119
- --qa) QA="${2:?--qa needs a spec}"; shift 2 ;;
131
+ --qa) QA="${2:?--qa needs a spec}"; QA_GIVEN=1; shift 2 ;;
132
+ --profile) PF_NAME="${2:?--profile needs a profile name}"; shift 2 ;;
133
+ --no-profile) PF_NONE=1; shift ;;
120
134
  --approach) APPROACH="${2:?--approach needs a file}"; shift 2 ;;
121
135
  --yolo-dwarf) YD="--yolo"; shift ;;
122
136
  --yolo-qa) YQ="--yolo"; shift ;;
@@ -126,6 +140,11 @@ while [ $# -gt 0 ]; do
126
140
  --timeout) TIMEOUT="${2:?--timeout needs seconds}"; shift 2 ;;
127
141
  --dry-run) DRY=1; shift ;;
128
142
  --fail-first) FAIL_FIRST=1; shift ;;
143
+ --fast)
144
+ [ -n "${2:-}" ] || die "--fast needs a comma list of roles (dwarf, qa, planner, review), all or none"
145
+ forge_fast_parse "$2" solo
146
+ FAST_GIVEN=1
147
+ shift 2 ;;
129
148
  --qa-threshold)
130
149
  QA_THR="$(printf '%s' "${2:?--qa-threshold needs P0, P1, P2, P3 or none}" | tr 'a-z' 'A-Z')"
131
150
  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
@@ -149,6 +168,48 @@ done
149
168
 
150
169
  case "$OUTPUT" in summary|full) ;; *) die "--output must be summary or full" ;; esac
151
170
 
171
+ # A profile (#48) stands in for the flags that were not given. Read and checked here, before the
172
+ # model is asked for and before anything is written: an unknown or invalid profile stops the run.
173
+ [ -z "$PF_NAME" ] || [ "$PF_NONE" = 0 ] || die "--profile and --no-profile are mutually exclusive"
174
+ pf_args=()
175
+ [ -z "$PF_NAME" ] || pf_args+=(--profile "$PF_NAME")
176
+ [ "$PF_NONE" = 0 ] || pf_args+=(--no-profile)
177
+ [ -z "$DWARF" ] || pf_args+=(--given dwarf)
178
+ [ "$QA_GIVEN" != 1 ] || pf_args+=(--given qa)
179
+ [ -z "$QA_THR" ] || pf_args+=(--given qa_threshold)
180
+ [ -z "$TIMEOUT" ] || pf_args+=(--given timeout)
181
+ [ "$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
+ PF_LINE=""
191
+ pf_out="$(forge_profile_py solo "$RUN" --repo "$REPO" ${pf_args[@]+"${pf_args[@]}"})" || exit $?
192
+ while IFS="$(printf '\t')" read -r pf_key pf_val; do
193
+ case "$pf_key" in
194
+ dwarf) DWARF="$pf_val" ;;
195
+ qa) QA="$pf_val" ;;
196
+ qa_threshold) QA_THR="$pf_val" ;;
197
+ timeout) TIMEOUT="$pf_val" ;;
198
+ 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
+ line) PF_LINE="$pf_val" ;;
206
+ # The gates and budget of the copy this run uses, for it and everything it starts.
207
+ decide) [ -z "$pf_val" ] || export FORGE_DECIDE_PROFILE_JSON="$pf_val" ;;
208
+ esac
209
+ done <<EOF
210
+ $pf_out
211
+ EOF
212
+
152
213
  # Forge never picks the model: every dispatch spends the user's quota, and choosing
153
214
  # for them is not the tool's call.
154
215
  [ -n "$DWARF" ] || die "--dwarf is required"
@@ -165,6 +226,13 @@ case "$(cd "$RUN" && pwd)/" in
165
226
  esac
166
227
 
167
228
  RUN="$(cd "$RUN" && pwd)"
229
+ # The frozen copy, atomically. Only the process that holds the run's lock writes it (a refused
230
+ # second start, or a dry run, must not change what an active run froze): the first pass above
231
+ # 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
233
+ forge_profile_py solo "$RUN" --repo "$REPO" --no-validate --write ${pf_args[@]+"${pf_args[@]}"} >/dev/null || exit $?
234
+ fi
235
+ [ -z "$PF_LINE" ] || [ -n "${FORGE_SOLO_LOCK:-}" ] || echo "$PF_LINE"
168
236
  # Freeze the selection now that the run dir is real and absolute. A retry of this
169
237
  # same run dir restores it rather than re-reading whatever flags are passed then.
170
238
  [ "$JEV_OPTS" = 1 ] && { forge_jev_restore "$RUN" || true; forge_jev_record "$RUN"; }
@@ -174,6 +242,8 @@ REPO="$(cd "$REPO" && pwd)"
174
242
  if [ "$DRY" != 1 ] && [ "${FORGE_SOLO_LOCK:-}" != "$RUN" ]; then
175
243
  exec python3 "$SKILL_DIR/scripts/forge-fractal.py" _lock "$RUN" "$0" "${ORIGINAL_ARGS[@]}"
176
244
  fi
245
+ # After the lock re-exec, so the process that dispatches is the one that writes it.
246
+ forge_fast_store "$RUN"
177
247
  RUN_ID="$(basename "$RUN")"
178
248
  export FORGE_CAPABILITY_CACHE="$RUN/capabilities"
179
249
  TFLAG=""; [ -n "$TIMEOUT" ] && TFLAG="--timeout $TIMEOUT"
@@ -183,6 +253,10 @@ FFLAGS=()
183
253
  [ -z "$YD" ] || FFLAGS+=(--yolo-dwarf)
184
254
  [ -z "$YQ" ] || FFLAGS+=(--yolo-qa)
185
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
+ ft_dwarf="$(forge_fast_tier "$RUN" dwarf)"
259
+ ft_qa="$(forge_fast_tier "$RUN" qa)"
186
260
  if [ -n "${FORGE_FRACTAL_RUN:-}" ]; then
187
261
  # The UI choice is per invocation: a tmux resume replays these args and must not open it again.
188
262
  REMEMBER_ARGS=()
@@ -235,7 +309,7 @@ if [ "$DRY" = 1 ]; then
235
309
  echo "--- dry run ---"
236
310
  [ "$FORGE_UI_WANTED" != 1 ] || note "--ui ignored: a dry run starts no UI"
237
311
  /bin/bash "$DISPATCH" dwarf "$DWARF" --repo "$REPO" --run-dir "$RUN" \
238
- --ripwire-query-file "$RUN/prompt.md" --prompt-file "$RUN/dwarf.input" $YD $TFLAG --dry-run
312
+ --ripwire-query-file "$RUN/prompt.md" --prompt-file "$RUN/dwarf.input" $YD $TFLAG $ft_dwarf --dry-run
239
313
  echo
240
314
  echo "qa would be: $QA $NATIVE $YQ"
241
315
  echo "dwarf prompt: $RUN/dwarf.input ($(wc -l < "$RUN/dwarf.input" | tr -d ' ') lines)"
@@ -243,8 +317,8 @@ if [ "$DRY" = 1 ]; then
243
317
  fi
244
318
 
245
319
  forge_metric_phase preflight
246
- /bin/bash "$DISPATCH" doctor --spec "$DWARF" --role dwarf $YD $TFLAG || exit $?
247
- /bin/bash "$DISPATCH" doctor --spec "$QA" --role qa $YQ $NATIVE $TFLAG || exit $?
320
+ /bin/bash "$DISPATCH" doctor --spec "$DWARF" --role dwarf $YD $TFLAG $ft_dwarf || exit $?
321
+ /bin/bash "$DISPATCH" doctor --spec "$QA" --role qa $YQ $NATIVE $TFLAG $ft_qa || exit $?
248
322
  /bin/bash "$SKILL_DIR/scripts/forge-install-ripwire.sh" || true
249
323
  # After the _lock re-exec and the Fractal checkpoint exit, so it runs once per run.
250
324
  forge_ui_launch "$RUN"
@@ -260,7 +334,7 @@ forge_metric_phase dispatch
260
334
  note "dwarf $DWARF in $REPO"
261
335
  guard_before_dwarf "$REPO" "$RUN"
262
336
  /bin/bash "$DISPATCH" dwarf "$DWARF" --repo "$REPO" --run-dir "$RUN" \
263
- --ripwire-query-file "$RUN/prompt.md" --prompt-file "$RUN/dwarf.input" $YD $TFLAG --output "$OUTPUT"
337
+ --ripwire-query-file "$RUN/prompt.md" --prompt-file "$RUN/dwarf.input" $YD $TFLAG $ft_dwarf --output "$OUTPUT"
264
338
  rc=$?
265
339
  dur_dwarf="$(sed -n 's/^duration_s=//p' "$RUN/dwarf.resolved" 2>/dev/null | tail -1)"
266
340
  /bin/bash "$MEMORY" record "$REPO" --last "$RUN/dwarf.last" --role dwarf \
@@ -288,6 +362,7 @@ fi
288
362
 
289
363
  REVIEW="$RUN/review-$(date +%s)-$$"
290
364
  forge_review_snapshot "$REPO" "$START" "$END" "$REVIEW" || die "cannot create review snapshot" 3
365
+ forge_review_deps "$REPO" "$REVIEW" "$RUN/review.deps"
291
366
  SOURCE_FP="$(forge_fingerprint "$REPO")" || exit 3
292
367
  [ "$(forge_tree "$REPO")" = "$END" ] || { echo INVALIDATED > "$RUN/verdict"; die "source changed while preparing QA" 5; }
293
368
  # The review snapshot is a commit; the reviewer's untracked leftovers there do not count (#95).
@@ -313,6 +388,9 @@ fi
313
388
  python3 "$SKILL_DIR/scripts/forge-prompt.py" --requirements "$RUN/prompt.md" --approach "$APPROACH" --goal "$RUN/goal.txt" --memory "$RUN/dwarf.memory" --memory "$RUN/qa.memory"
314
389
  python3 "$SKILL_DIR/scripts/forge-contract.py" qa --part head --kind solo
315
390
  echo
391
+ cat "$RUN/review.deps"
392
+ [ -s "$RUN/failfirst.txt" ] || echo "Forge ran no tests of its own on this attempt, so nothing here stands in for yours."
393
+ echo
316
394
  if [ -s "$RUN/failfirst.txt" ]; then cat "$RUN/failfirst.txt"; echo; fi
317
395
  python3 "$SKILL_DIR/scripts/forge-contract.py" qa --part tail --kind solo --threshold "$THR"
318
396
  echo
@@ -326,7 +404,7 @@ fi
326
404
  forge_metric_phase dispatch
327
405
  note "qa $QA on $(wc -l < "$RUN/changes.diff" | tr -d ' ') diff lines"
328
406
  /bin/bash "$DISPATCH" qa "$QA" --repo "$REVIEW" --review-base "$(cat "$RUN/review.base")" --run-dir "$RUN" \
329
- --ripwire-query-file "$RUN/prompt.md" --prompt-file "$RUN/qa.input" $YQ $NATIVE $TFLAG --output "$OUTPUT"
407
+ --ripwire-query-file "$RUN/prompt.md" --prompt-file "$RUN/qa.input" $YQ $NATIVE $TFLAG $ft_qa --output "$OUTPUT"
330
408
  rc=$?
331
409
  forge_metric_phase verification
332
410
  verdict="$(forge_verdict "$RUN/qa.last")"
@@ -348,6 +426,8 @@ dur_qa="$(sed -n 's/^duration_s=//p' "$RUN/qa.resolved" 2>/dev/null | tail -1)"
348
426
  # Otherwise forge enforces the severity rule itself, as a decomposed task's gate does; a gate
349
427
  # that cannot run (no output) keeps the reviewer's verdict.
350
428
  gate_note=""
429
+ tests_note="$(forge_tests_note "$RUN/qa.last")"
430
+ [ -z "$tests_note" ] || note "the reviewer's tests could not run: $tests_note"
351
431
  if [ -z "$NATIVE" ]; then
352
432
  gate_line="$(python3 "$SKILL_DIR/scripts/forge-contract.py" gate --verdict "${verdict:-UNKNOWN}" \
353
433
  --qa-last "$RUN/qa.last" --threshold "$THR" --known-issues "$RUN/known_issues.md" 2>/dev/null)" || gate_line=""
@@ -196,11 +196,28 @@ def run_reviewers(args) -> int:
196
196
  return reviewers.main(args)
197
197
 
198
198
 
199
+ def run_history(args) -> int:
200
+ from . import history
201
+ return history.main(args)
202
+
203
+
204
+ def run_worktrees(args) -> int:
205
+ from . import worktrees
206
+ return worktrees.main(args)
207
+
208
+
199
209
  def run_forecast(args) -> int:
200
210
  from . import forecast
201
211
  return forecast.main(args)
202
212
 
203
213
 
214
+ def slow_notes(args) -> int:
215
+ from . import efforts
216
+ for line in efforts.plan_notes(args.plan):
217
+ print(line)
218
+ return 0
219
+
220
+
204
221
  def parser() -> argparse.ArgumentParser:
205
222
  top = argparse.ArgumentParser(prog='forge dataset', description='The run dataset: every run\'s inputs and outcomes.')
206
223
  sub = top.add_subparsers(dest='command', required=True)
@@ -247,12 +264,21 @@ def parser() -> argparse.ArgumentParser:
247
264
  p.add_argument('--repo', help='only this repo')
248
265
  p.add_argument('--json', action='store_true')
249
266
  p.set_defaults(func=run_reviewers)
267
+ p = sub.add_parser('history', help="every review's findings and every learning, for forge-ui's Projects screen")
268
+ p.add_argument('--json', action='store_true')
269
+ p.set_defaults(func=run_history)
270
+ p = sub.add_parser('worktrees', help="the worktrees forge created and removed, for forge-ui's Worktrees screen")
271
+ p.add_argument('--json', action='store_true')
272
+ p.set_defaults(func=run_worktrees)
250
273
  p = sub.add_parser('forecast', help="a plan's likely tokens, time and first-try pass rate, from past tasks (advisory)")
251
274
  p.add_argument('plan', help='the plan dir')
252
275
  p.add_argument('--repo', help='only history from this repo')
253
276
  p.add_argument('--json', action='store_true')
254
277
  p.add_argument('--run', action='store_true', help=argparse.SUPPRESS) # forge-parallel.sh run: budgeted, silent, records
255
278
  p.set_defaults(func=run_forecast)
279
+ p = sub.add_parser('slow-notes', help=argparse.SUPPRESS) # forge-parallel.sh plan: under the table
280
+ p.add_argument('plan')
281
+ p.set_defaults(func=slow_notes)
256
282
  p = sub.add_parser('event', help=argparse.SUPPRESS)
257
283
  p.add_argument('name')
258
284
  p.add_argument('--dir')