@giamme/forge 0.11.1 → 0.12.1

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 (54) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/SKILL.md +7 -3
  3. package/VERSION +1 -1
  4. package/docs/artifacts.md +50 -11
  5. package/docs/commands.md +56 -8
  6. package/docs/decomposed-runs.md +43 -2
  7. package/docs/forge-ui.md +55 -8
  8. package/docs/reviews.md +64 -6
  9. package/package.json +1 -1
  10. package/references/dataset.md +4 -2
  11. package/references/decompose.md +191 -17
  12. package/references/harnesses.md +13 -1
  13. package/references/ui.md +25 -4
  14. package/scripts/forge-contract.py +37 -7
  15. package/scripts/forge-control.py +268 -25
  16. package/scripts/forge-dispatch.sh +90 -3
  17. package/scripts/forge-guard.py +156 -15
  18. package/scripts/forge-issues.py +47 -3
  19. package/scripts/forge-lib-plans.sh +9 -3
  20. package/scripts/forge-lib-review.sh +24 -5
  21. package/scripts/forge-lib-task.sh +53 -5
  22. package/scripts/forge-lib-verify.sh +137 -6
  23. package/scripts/forge-parallel-options.sh +85 -0
  24. package/scripts/forge-parallel.sh +262 -31
  25. package/scripts/forge-ripwire.py +1 -1
  26. package/scripts/forge-route.py +157 -5
  27. package/scripts/forge-runtime.py +49 -1
  28. package/scripts/forge-schedule.py +735 -53
  29. package/scripts/forge-solo.sh +3 -1
  30. package/scripts/forge-sweep.py +542 -0
  31. package/scripts/forge-verify.py +878 -0
  32. package/scripts/forge_dataset/forecast.py +33 -5
  33. package/scripts/forge_dataset/harvest.py +10 -4
  34. package/scripts/forge_verify_reports.py +225 -0
  35. package/ui/README.md +58 -12
  36. package/ui/docs/api.md +277 -28
  37. package/ui/forge_ui/checks.py +331 -0
  38. package/ui/forge_ui/control.py +12 -2
  39. package/ui/forge_ui/export.py +25 -8
  40. package/ui/forge_ui/reader.py +657 -24
  41. package/ui/forge_ui/server.py +29 -0
  42. package/ui/forge_ui/static/app.js +15 -7
  43. package/ui/forge_ui/static/checksview.js +449 -0
  44. package/ui/forge_ui/static/controls.js +217 -33
  45. package/ui/forge_ui/static/convo.js +11 -2
  46. package/ui/forge_ui/static/findingsview.js +6 -4
  47. package/ui/forge_ui/static/gantt.js +14 -9
  48. package/ui/forge_ui/static/index.html +2 -0
  49. package/ui/forge_ui/static/panel.js +44 -1
  50. package/ui/forge_ui/static/runmodel.js +109 -12
  51. package/ui/forge_ui/static/scene3d.js +9 -5
  52. package/ui/forge_ui/static/style.css +113 -0
  53. package/ui/forge_ui/static/verifyview.js +324 -0
  54. package/ui/forge_ui/transcripts.py +225 -54
@@ -20,9 +20,15 @@ bias (inverse-propensity weighting needs the probability each choice had).
20
20
  The retry policy: after <plan>/escalate_after (default 3; 0 = off) failed attempts on
21
21
  one spec, the next attempt goes to the next tier up of the user's pools instead of
22
22
  repeating the same dispatch. Prints that spec when one is due. When none exists, writes
23
- tasks/<id>/escalation.stop and split.suggested and exits 3. `--check` (run after every
24
- attempt) also records a due escalation in escalation.next, and clears the markers once
25
- the streak no longer holds. A pending tasks/<id>/escalation.pin (a human's one-shot
23
+ tasks/<id>/escalation.stop and split.suggested and exits 3. When <plan>/escalate_effort
24
+ contains `on` and no higher tier has another model, the same alias and harness is tried
25
+ once more at the next effort its pairing accepts (weakest above the current one; a spec
26
+ that names no effort counts as medium, a dwarf dispatch's default) before that stop.
27
+ The streak then counts per effort, so the new effort starts again. At the pairing's
28
+ highest effort the task still stops, and split.suggested says that effort was tried too.
29
+ With the file absent the streak and the stop are exactly as before. `--check` (run after
30
+ every attempt) also records a due escalation in escalation.next, and clears the markers
31
+ once the streak no longer holds. A pending tasks/<id>/escalation.pin (a human's one-shot
26
32
  choice, applied by prepare_retry) is what `--check` reports as the next model instead
27
33
  (escalation.next = its spec), whatever escalate_after says, unless the next retry is a
28
34
  QA-only resume or the plan is Fractal (pins never apply there). `--qa-only-next` is
@@ -60,6 +66,7 @@ import os
60
66
  import random
61
67
  import secrets
62
68
  import stat
69
+ import subprocess
63
70
  import sys
64
71
  import tempfile
65
72
  import time
@@ -71,7 +78,12 @@ REGISTRY = SCRIPTS.parent / 'registry.tsv'
71
78
  FAILED = ('FAIL', 'TIMEOUT') # a judgment against the spec that ran
72
79
  NEUTRAL = ('INFRA', 'UNKNOWN', 'ERROR', 'RUNNING', 'INTERRUPTED') # say nothing about it
73
80
  DEFAULT_ESCALATE_AFTER = 3
81
+ DEFAULT_EFFORT = 'medium' # forge-dispatch.sh dwarf default
74
82
  LOCK_WAIT = 5.0 # seconds to wait for P/control.lock
83
+ # forge-dispatch.sh rank_of. Only for "which accepted effort is above this one"; the set of
84
+ # efforts a pairing accepts comes from `forge-dispatch.sh efforts`, not from this table.
85
+ # ultra and ultracode share a rank: each is its own harness's top, under different names.
86
+ EFFORT_RANK = {'low': 0, 'medium': 1, 'high': 2, 'xhigh': 3, 'max': 4, 'ultra': 5, 'ultracode': 5}
75
87
 
76
88
 
77
89
  def rng_for(task: str):
@@ -209,6 +221,64 @@ def stronger(spec: str, pools: dict, registry: dict):
209
221
  return None, 'it is already in the highest tier of this plan\'s pools (%s)' % TIERS[rank]
210
222
 
211
223
 
224
+ # --- capacity fallback ---------------------------------------------------------------
225
+
226
+ def pair_of(spec: str, registry: dict):
227
+ """(harness, model id) a spec runs on, as forge-dispatch.sh's lookup resolves it; None when it cannot."""
228
+ parts = str(spec).split(':')
229
+ alias, harness = parts[0], ':'.join(parts[2:])
230
+ rows = registry.get(alias)
231
+ if rows:
232
+ if not harness:
233
+ return next(iter(rows.items()))
234
+ return harness, rows.get(harness, alias)
235
+ return (harness, alias) if harness else None
236
+
237
+
238
+ def parse_excluded(text: str) -> set:
239
+ """`harness/model` items, comma-separated; `harness/*` excludes every model on that harness."""
240
+ out = set()
241
+ for item in (text or '').split(','):
242
+ harness, slash, model = item.strip().partition('/')
243
+ if harness and slash and model:
244
+ out.add((harness, model))
245
+ return out
246
+
247
+
248
+ def fallback_pick(current: str, pools: dict, registry: dict, excluded: set):
249
+ """The next member of the current dwarf's own tier pool, in pool order and wrapping around,
250
+ that runs another model on a pair nobody paused; None when there is none."""
251
+ rank = rank_of(current, pools, registry)
252
+ if rank is None:
253
+ return None
254
+ pool = pools[TIERS[rank]]
255
+ own = canonical(current, registry)
256
+ keys = [canonical(s, registry) for s in pool]
257
+ start = keys.index(own) if own in keys else -1
258
+ for step in range(1, len(pool) + 1):
259
+ candidate = pool[(start + step) % len(pool)]
260
+ pair = pair_of(candidate, registry)
261
+ if canonical(candidate, registry) == own or pair is None:
262
+ continue
263
+ if pair in excluded or (pair[0], '*') in excluded:
264
+ continue
265
+ return candidate
266
+ return None
267
+
268
+
269
+ def fallback(args) -> int:
270
+ plan = Path(os.path.realpath(args.plan))
271
+ current = _dwarf_of(plan, args.task)
272
+ if not current or current in ('-', 'UNASSIGNED'):
273
+ return 1
274
+ pick = fallback_pick(current, load_pools(plan / 'fractal-routing.json'), registry_models(),
275
+ parse_excluded(args.exclude))
276
+ if not pick:
277
+ return 1
278
+ print(pick)
279
+ return 0
280
+
281
+
212
282
  # --- exploration -------------------------------------------------------------------
213
283
 
214
284
  def explore(args) -> str:
@@ -250,20 +320,87 @@ def _dwarf_of(plan: Path, task: str) -> str:
250
320
  return ''
251
321
 
252
322
 
253
- def failed_streak(rows: list, current: str, registry: dict) -> int:
323
+ def _spec_parts(spec: str):
324
+ """(alias, effort, harness) of alias[:effort[:harness]]. Effort and harness are '' when unnamed."""
325
+ alias, sep, rest = str(spec).partition(':')
326
+ if not sep:
327
+ return alias, '', ''
328
+ effort, sep, harness = rest.partition(':')
329
+ return alias, effort, harness if sep else ''
330
+
331
+
332
+ def _effort_of(spec: str) -> str:
333
+ """The effort a spec names, or medium when it names none (what a dwarf dispatch runs)."""
334
+ _alias, effort, _harness = _spec_parts(spec)
335
+ return effort or DEFAULT_EFFORT
336
+
337
+
338
+ def _effort_step(plan: Path) -> bool:
339
+ try:
340
+ return (plan / 'escalate_effort').read_text().strip() == 'on'
341
+ except OSError:
342
+ return False
343
+
344
+
345
+ def _accepted_efforts(spec: str) -> list:
346
+ """Efforts `spec`'s pairing accepts, weakest first. Empty when dispatch cannot say."""
347
+ try:
348
+ done = subprocess.run(
349
+ ['bash', str(SCRIPTS / 'forge-dispatch.sh'), 'efforts', '--spec', spec],
350
+ capture_output=True, text=True, timeout=30)
351
+ except (OSError, subprocess.SubprocessError):
352
+ return []
353
+ if done.returncode != 0:
354
+ return []
355
+ return [line.strip() for line in done.stdout.splitlines() if line.strip()]
356
+
357
+
358
+ def _effective_effort(requested: str, accepted: list):
359
+ """The effort a dwarf dispatch runs when `requested` is asked of a pairing accepting
360
+ `accepted`: as asked when accepted, else the strongest accepted at or below it, else the
361
+ weakest accepted (forge-dispatch.sh's clamp)."""
362
+ if requested in accepted:
363
+ return requested
364
+ want = EFFORT_RANK.get(requested)
365
+ below = [e for e in accepted if want is not None and EFFORT_RANK.get(e, 99) <= want]
366
+ return below[-1] if below else (accepted[0] if accepted else None)
367
+
368
+
369
+ def _next_effort_spec(spec: str):
370
+ """The same alias and harness at the next accepted effort above the one a dispatch of
371
+ `spec` actually runs, or None."""
372
+ alias, _effort, harness = _spec_parts(spec)
373
+ accepted = _accepted_efforts(spec)
374
+ rank = EFFORT_RANK.get(_effective_effort(_effort_of(spec), accepted) or '')
375
+ if not alias or rank is None:
376
+ return None
377
+ for effort in accepted:
378
+ other = EFFORT_RANK.get(effort)
379
+ if other is not None and other > rank:
380
+ return '%s:%s:%s' % (alias, effort, harness) if harness else '%s:%s' % (alias, effort)
381
+ return None
382
+
383
+
384
+ def failed_streak(rows: list, current: str, registry: dict, by_effort: bool = False) -> int:
254
385
  """Distinct trailing attempt numbers that failed on `current`'s model.
255
386
 
256
387
  rows: (attempt, status, spec-or-None) oldest first. A row without a spec predates the
257
388
  column and is taken as the current spec. Infra stops, missing verdicts and forge errors
258
389
  judge nothing and are skipped; a pass, a merge or another model ends the streak.
390
+ With by_effort, another effort of the same model ends it too (a bump starts a new
391
+ streak). A spec that names no effort counts as medium. With by_effort off the count
392
+ is by model only, as before.
259
393
  """
260
394
  model = canonical(current, registry)
395
+ effort = _effort_of(current) if by_effort else None
261
396
  seen = set()
262
397
  for attempt, status, spec in reversed(rows):
263
398
  if status in NEUTRAL:
264
399
  continue
265
400
  if spec and canonical(spec, registry) != model:
266
401
  break
402
+ if effort is not None and _effort_of(spec or current) != effort:
403
+ break
267
404
  if status not in FAILED:
268
405
  break
269
406
  seen.add(attempt)
@@ -439,13 +576,19 @@ def _decide(plan: Path, tdir: Path, args, after: int):
439
576
  if not current or current in ('-', 'UNASSIGNED'):
440
577
  return (), (), '', 0
441
578
  registry = registry_models()
442
- streak = failed_streak(attempt_rows(tdir), current, registry)
579
+ step = _effort_step(plan)
580
+ streak = failed_streak(attempt_rows(tdir), current, registry, by_effort=step)
443
581
  if streak < after:
444
582
  return MARKERS, (), '', 0
445
583
  target, why = stronger(current, load_pools(plan / 'fractal-routing.json'), registry)
584
+ # Only once no higher tier has a model. A tier-up is still the stronger move.
585
+ if target is None and step:
586
+ target = _next_effort_spec(current)
446
587
  if target:
447
588
  writes = (('escalation.next', target + '\n'),) if args.check else ()
448
589
  return ('escalation.stop', 'split.suggested'), writes, target, 0
590
+ if step:
591
+ why = '%s. The highest effort this pairing accepts was tried as well' % why
449
592
  split = ('%s failed %d attempts on %s, and %s. Another attempt on the same model rarely passes, '
450
593
  'so split the task into smaller ones, or retry it with an explicit --dwarf <spec>.\n'
451
594
  % (args.task, streak, current, why))
@@ -536,6 +679,10 @@ def main(argv=None) -> int:
536
679
  p.add_argument('--check', action='store_true')
537
680
  p.add_argument('--qa-only-next', choices=('yes', 'no'), default=None,
538
681
  help='whether the next entry only re-runs QA, as the caller measured it')
682
+ p = sub.add_parser('fallback', help='the same-tier model a capacity stop moves to')
683
+ p.add_argument('--plan', required=True)
684
+ p.add_argument('--task', required=True)
685
+ p.add_argument('--exclude', default='', help='harness/model pairs to skip, comma-separated (harness/* for all)')
539
686
  p = sub.add_parser('record', help=argparse.SUPPRESS)
540
687
  p.add_argument('--plan', required=True)
541
688
  p.add_argument('--task', required=True)
@@ -551,6 +698,11 @@ def main(argv=None) -> int:
551
698
  return 0
552
699
  if args.command == 'record':
553
700
  return record_escalation(args)
701
+ if args.command == 'fallback':
702
+ try:
703
+ return fallback(args)
704
+ except Exception:
705
+ return 1
554
706
  try:
555
707
  return escalation(args)
556
708
  except Exception:
@@ -9,6 +9,7 @@ import os
9
9
  from pathlib import Path
10
10
  import re
11
11
  import shutil
12
+ import signal
12
13
  import subprocess
13
14
  import sys
14
15
  import time
@@ -97,6 +98,51 @@ def phase(attempt: str, name: str, rc: str | None = None) -> None:
97
98
  write_json(path, data)
98
99
 
99
100
 
101
+ CLOCK_EVERY_S = 1.0
102
+
103
+
104
+ class _ClockStop(Exception):
105
+ pass
106
+
107
+
108
+ def clock(log: str, out: str, every: str | None = None) -> None:
109
+ """When the harness log grew: one `<epoch seconds> <bytes>` line in `out` for each sample that saw a new
110
+ size, the first at the start. codex's and grok's events carry no time of their own, so forge-ui times them
111
+ from this. Runs beside the harness until a TERM (dispatch sends it once the harness exited) or until the
112
+ dispatch that started it is gone, and ends with one last sample. Advisory: nothing reads its exit."""
113
+ def stop(signum: int, frame: object) -> None:
114
+ raise _ClockStop()
115
+
116
+ signal.signal(signal.SIGTERM, stop)
117
+ signal.signal(signal.SIGINT, stop)
118
+ parent, period, last = os.getppid(), float(every) if every else CLOCK_EVERY_S, -1
119
+
120
+ def sample() -> None:
121
+ nonlocal last
122
+ # A TERM waits until the line is whole: it is delivered when the mask is lifted.
123
+ signal.pthread_sigmask(signal.SIG_BLOCK, {signal.SIGTERM})
124
+ try:
125
+ size = os.stat(log).st_size
126
+ if size != last:
127
+ with open(out, 'a') as stream:
128
+ stream.write('%.3f %d\n' % (time.time(), size))
129
+ last = size
130
+ except OSError:
131
+ pass
132
+ finally:
133
+ signal.pthread_sigmask(signal.SIG_UNBLOCK, {signal.SIGTERM})
134
+
135
+ try:
136
+ while os.getppid() == parent:
137
+ sample()
138
+ time.sleep(period)
139
+ except _ClockStop:
140
+ pass
141
+ signal.signal(signal.SIGTERM, signal.SIG_IGN)
142
+ signal.signal(signal.SIGINT, signal.SIG_IGN)
143
+ sample()
144
+
145
+
100
146
  def token_count(value: object) -> int | None:
101
147
  return value if type(value) is int and value >= 0 else None
102
148
 
@@ -254,7 +300,7 @@ def _finish(attempt: Path, root: Path, role: str, harness: str, rc: str) -> None
254
300
  session_path.unlink(missing_ok=True)
255
301
  if found is not None:
256
302
  session_path.write_text(found + '\n')
257
- for suffix in ('prompt', 'last', 'log', 'resolved', 'cmd', 'timedout', 'infra', 'orphans',
303
+ for suffix in ('prompt', 'last', 'log', 'clock', 'resolved', 'cmd', 'timedout', 'infra', 'orphans',
258
304
  'session', 'continue'):
259
305
  if suffix == 'prompt' and not prompt_ready:
260
306
  continue
@@ -621,6 +667,8 @@ def main() -> None:
621
667
  report(*args)
622
668
  elif command == 'classify':
623
669
  classify_command(*args)
670
+ elif command == 'clock':
671
+ clock(*args)
624
672
  else:
625
673
  raise ValueError('unknown runtime command: ' + command)
626
674
  except (OSError, ValueError, RuntimeError) as error: