@giamme/forge 0.17.0 → 0.19.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 (110) hide show
  1. package/CHANGELOG.md +57 -0
  2. package/README.md +1 -0
  3. package/SKILL.md +32 -5
  4. package/VERSION +1 -1
  5. package/docs/artifacts.md +33 -1
  6. package/docs/commands.md +147 -16
  7. package/docs/dataset.md +5 -0
  8. package/docs/decomposed-runs.md +122 -1
  9. package/docs/development.md +2 -1
  10. package/docs/forge-ui.md +98 -8
  11. package/docs/memory.md +27 -4
  12. package/docs/models.md +8 -0
  13. package/docs/reviews.md +122 -0
  14. package/docs/safety.md +8 -0
  15. package/forge +44 -4
  16. package/package.json +2 -1
  17. package/references/dataset.md +39 -1
  18. package/references/decompose.md +737 -16
  19. package/references/harnesses.md +18 -3
  20. package/references/planning.md +43 -14
  21. package/references/solo.md +2 -1
  22. package/references/ui.md +56 -6
  23. package/registry.tsv +8 -3
  24. package/scripts/forge-artifact.sh +14 -0
  25. package/scripts/forge-brief.py +217 -0
  26. package/scripts/forge-compare.py +13 -2
  27. package/scripts/forge-config.py +176 -9
  28. package/scripts/forge-contract.py +246 -28
  29. package/scripts/forge-control.py +200 -15
  30. package/scripts/forge-dispatch.sh +48 -15
  31. package/scripts/forge-du.py +167 -0
  32. package/scripts/forge-group.py +496 -0
  33. package/scripts/forge-groups.py +89 -0
  34. package/scripts/forge-handoff.py +1128 -0
  35. package/scripts/forge-lib-adopt.sh +1 -0
  36. package/scripts/forge-lib-group.sh +641 -0
  37. package/scripts/forge-lib-plans.sh +343 -4
  38. package/scripts/forge-lib-review.sh +29 -1
  39. package/scripts/forge-lib-task.sh +197 -4
  40. package/scripts/forge-memory.sh +245 -3
  41. package/scripts/forge-metrics.sh +7 -3
  42. package/scripts/forge-parallel-options.sh +4 -0
  43. package/scripts/forge-parallel.sh +1216 -41
  44. package/scripts/forge-planner.py +104 -8
  45. package/scripts/forge-prompt.py +120 -0
  46. package/scripts/forge-retro.py +115 -0
  47. package/scripts/forge-route.py +190 -12
  48. package/scripts/forge-runs-compact.py +443 -0
  49. package/scripts/forge-runs-rm.py +2 -0
  50. package/scripts/forge-runs.py +27 -8
  51. package/scripts/forge-schedule.py +633 -49
  52. package/scripts/forge-shadow.py +7 -1
  53. package/scripts/forge-solo.sh +4 -0
  54. package/scripts/forge-summarize.py +698 -0
  55. package/scripts/forge-ui-options.sh +10 -0
  56. package/scripts/forge-worktrees.py +243 -0
  57. package/scripts/forge_brief/__init__.py +831 -0
  58. package/scripts/forge_brief/answers.py +506 -0
  59. package/scripts/forge_brief/proposals.py +1630 -0
  60. package/scripts/forge_dataset/__init__.py +10 -0
  61. package/scripts/forge_dataset/efforts.py +4 -3
  62. package/scripts/forge_dataset/export.py +36 -10
  63. package/scripts/forge_dataset/facts.py +8 -4
  64. package/scripts/forge_dataset/forecast.py +8 -18
  65. package/scripts/forge_dataset/harvest.py +241 -12
  66. package/scripts/forge_dataset/history.py +13 -6
  67. package/scripts/forge_dataset/importer.py +65 -1
  68. package/scripts/forge_dataset/names.py +66 -0
  69. package/scripts/forge_dataset/reviewers.py +5 -2
  70. package/scripts/forge_dataset/risk.py +6 -3
  71. package/scripts/forge_dataset/routing.py +6 -1
  72. package/scripts/forge_decide/__init__.py +11 -1
  73. package/scripts/forge_groups/__init__.py +308 -0
  74. package/scripts/forge_groups/attribute.py +289 -0
  75. package/scripts/forge_groups/review.py +286 -0
  76. package/scripts/forge_locations.py +366 -0
  77. package/scripts/forge_owner.py +152 -0
  78. package/scripts/forge_registry.py +19 -0
  79. package/scripts/forge_retro/__init__.py +417 -0
  80. package/scripts/forge_retro/issues.py +1193 -0
  81. package/scripts/forge_retro/report.py +671 -0
  82. package/scripts/forge_side/__init__.py +482 -0
  83. package/scripts/forge_storage.py +515 -0
  84. package/ui/README.md +68 -8
  85. package/ui/docs/api.md +375 -31
  86. package/ui/forge_ui/control.py +451 -11
  87. package/ui/forge_ui/executions.py +8 -1
  88. package/ui/forge_ui/export.py +53 -7
  89. package/ui/forge_ui/groups.py +264 -0
  90. package/ui/forge_ui/links.py +337 -0
  91. package/ui/forge_ui/models.py +125 -10
  92. package/ui/forge_ui/projects.py +4 -1
  93. package/ui/forge_ui/reader.py +919 -45
  94. package/ui/forge_ui/server.py +4 -0
  95. package/ui/forge_ui/static/app.js +173 -11
  96. package/ui/forge_ui/static/briefview.js +605 -0
  97. package/ui/forge_ui/static/checksview.js +6 -2
  98. package/ui/forge_ui/static/controls.js +5 -0
  99. package/ui/forge_ui/static/diffview.js +86 -1
  100. package/ui/forge_ui/static/groupsview.js +332 -0
  101. package/ui/forge_ui/static/index.html +4 -0
  102. package/ui/forge_ui/static/panel.js +394 -8
  103. package/ui/forge_ui/static/projectsview.js +189 -10
  104. package/ui/forge_ui/static/runmodel.js +27 -4
  105. package/ui/forge_ui/static/storageview.js +352 -0
  106. package/ui/forge_ui/static/style.css +176 -6
  107. package/ui/forge_ui/static/worktreesview.js +235 -14
  108. package/ui/forge_ui/storage.py +150 -0
  109. package/ui/forge_ui/transcripts.py +35 -10
  110. package/ui/forge_ui/worktrees.py +154 -13
@@ -46,6 +46,16 @@ bias (inverse-propensity weighting needs the probability each choice had).
46
46
  re-read escalate_after inside it: a policy decision made before a human switched the
47
47
  policy off writes nothing.
48
48
 
49
+ forge-route.py per-model --plan P --task ID
50
+ forge-route.py worst-case --plan P
51
+ `plan --retry-per-model N` (<plan>/retry_per_model, 1-99): a task may fail N times on each
52
+ rung the retry policy gives it (the stronger tiers of the pools, then the efforts when
53
+ escalate_effort is on), and the count starts again after each escalation. It replaces
54
+ escalate_after as the trigger. `per-model` prints {retry, rung, failed_on_rung, rungs_left,
55
+ per_model} as JSON (exit 2 when the plan has no valid file); `worst-case` prints the dispatches
56
+ the unmerged tasks can spend, per task and in total, and the tasks N*rungs takes past
57
+ max_attempts. Without the file nothing else here changes.
58
+
49
59
  forge-route.py fallback --plan P --task ID [--exclude harness/model,...]
50
60
  The lateral move of an infrastructure stop: prints the next free model of the pool of the
51
61
  tier the task runs in (the newest record of it: see running_tier), or exits 1 when there is none.
@@ -92,6 +102,7 @@ import errno
92
102
  import fcntl
93
103
  import hashlib
94
104
  import json
105
+ import math
95
106
  import os
96
107
  import random
97
108
  import re
@@ -107,7 +118,7 @@ TIERS = ('low', 'medium', 'high')
107
118
  SCRIPTS = Path(__file__).resolve().parent
108
119
  REGISTRY = SCRIPTS.parent / 'registry.tsv'
109
120
  FAILED = ('FAIL', 'TIMEOUT', 'BOUNCED', 'INCOMPLETE') # a judgment against the spec that ran
110
- NEUTRAL = ('INFRA', 'UNKNOWN', 'ERROR', 'RUNNING', 'INTERRUPTED', 'NEEDS_INPUT', 'NEEDS_DECISION') # say nothing about it
121
+ NEUTRAL = ('INFRA', 'UNKNOWN', 'ERROR', 'RUNNING', 'INTERRUPTED', 'NEEDS_INPUT', 'NEEDS_DECISION', 'STALE') # say nothing about it
111
122
  DEFAULT_ESCALATE_AFTER = 3
112
123
  DEFAULT_MAX_ATTEMPTS = 8 # `plan --max-attempts`; a plan without the file
113
124
  DEFAULT_EFFORT = 'medium' # forge-dispatch.sh dwarf default
@@ -343,7 +354,9 @@ def qa_fallback_pick(current: str, implementer: str, pools: dict, registry: dict
343
354
  own = canonical(current, registry)
344
355
  if not any(canonical(s, registry) == own for pool in order for s in pool):
345
356
  return None
346
- wrote = implementer if implementer not in ('', '-', 'UNASSIGNED') else None
357
+ # `script` names the command that implements the task, not a model, so it cannot
358
+ # exclude a reviewer that shares a registry alias of that name.
359
+ wrote = implementer if implementer not in ('', '-', 'UNASSIGNED', 'script') else None
347
360
  for pool in order:
348
361
  keys = [canonical(s, registry) for s in pool]
349
362
  start = keys.index(own) if own in keys else -1
@@ -382,7 +395,9 @@ def running_tier(plan: Path, task: str, current: str = '') -> str:
382
395
  the task still runs its spec: an older record never beats a newer pick of the same model (#106).
383
396
  With neither, or when the newest is for another spec (the table was edited by hand), the
384
397
  difficulty. `current` is the spec the task runs, read from tasks.tsv when not given. '' when the
385
- difficulty is no tier."""
398
+ difficulty is no tier, and when the task is scripted: `script` is not a model, so nothing is recorded."""
399
+ if current == 'script' or _is_script(plan, task):
400
+ return ''
386
401
  tier = _row_cell(plan, task, 2)
387
402
  if tier not in TIERS:
388
403
  return ''
@@ -414,9 +429,14 @@ def write_running_tier(plan: str, task: str, tier: str, spec: str, control) -> N
414
429
 
415
430
  def record_running_tier(plan: str, task: str, row: str, control) -> None:
416
431
  """tasks/<id>/running.tier for an escalations.tsv row: the tier the row moved the task to, decided
417
- here with the pools of this moment. A fallback stays in its tier."""
432
+ here with the pools of this moment. A fallback stays in its tier. A scripted task has no model
433
+ tier to record, and an existing file is left as it is."""
434
+ if _is_script(Path(plan), task):
435
+ return
418
436
  cells = row.rstrip('\n').split('\t')
419
437
  frm, to, source = cells[2], cells[3], cells[4] if len(cells) > 4 else 'policy'
438
+ if to == 'script':
439
+ return
420
440
  tier = running_tier(Path(plan), task, frm)
421
441
  if tier and source != 'fallback':
422
442
  tier = escalation_target(source, frm, to, tier, load_pools(Path(plan) / 'fractal-routing.json'),
@@ -427,6 +447,8 @@ def record_running_tier(plan: str, task: str, row: str, control) -> None:
427
447
 
428
448
  def fallback(args) -> int:
429
449
  plan = Path(os.path.realpath(args.plan))
450
+ if _is_script(plan, args.task):
451
+ return 1
430
452
  current = _dwarf_of(plan, args.task)
431
453
  if not current or current in ('-', 'UNASSIGNED'):
432
454
  return 1
@@ -488,7 +510,11 @@ def explore(args) -> tuple:
488
510
  def assign(args) -> str:
489
511
  """`plan`'s resolution of a row: the exploration draw, then the record of the tier its pick runs in,
490
512
  newer than any record it replaces. A record that cannot be written is removed rather than left to
491
- speak for the new pick. Prints the pick; any failure prints SPEC, as explore does."""
513
+ speak for the new pick. Prints the pick; any failure prints SPEC, as explore does.
514
+
515
+ A scripted row is not a model to explore or to record a tier for: the cell comes back unchanged."""
516
+ if args.default == 'script' or _is_script(Path(args.plan), args.task):
517
+ return 'script'
492
518
  chosen, tier = args.default, args.tier
493
519
  with contextlib.suppress(Exception):
494
520
  chosen, tier = explore(args)
@@ -523,6 +549,14 @@ def _dwarf_of(plan: Path, task: str) -> str:
523
549
  return ''
524
550
 
525
551
 
552
+ def _is_script(plan: Path, task: str) -> bool:
553
+ """True when the task's dwarf cell is the literal `script`: it runs tasks/<id>/run, not a model."""
554
+ try:
555
+ return _dwarf_of(plan, task) == 'script'
556
+ except OSError:
557
+ return False
558
+
559
+
526
560
  def _spec_parts(spec: str):
527
561
  """(alias, effort, harness) of alias[:effort[:harness]]. Effort and harness are '' when unnamed."""
528
562
  alias, sep, rest = str(spec).partition(':')
@@ -693,6 +727,122 @@ def _setting(plan: Path) -> int:
693
727
  return DEFAULT_ESCALATE_AFTER
694
728
 
695
729
 
730
+ # --- per-model retries (#141) ------------------------------------------------------
731
+ # `plan --retry-per-model N`: a task may fail N times on each rung the retry policy gives it, and the
732
+ # count starts again after each escalation. The trigger lives in escalation(); the questions the
733
+ # scheduler and the plan table ask (may it retry, what is the worst case) are answered here.
734
+
735
+ MAX_RUNGS = 12
736
+ NON_MODEL_DWARFS = ('', '-', 'UNASSIGNED', 'script')
737
+
738
+
739
+ def per_model_setting(plan: Path):
740
+ """<plan>/retry_per_model as an integer from 1 to 99, else None (missing, empty or malformed)."""
741
+ try:
742
+ value = (plan / 'retry_per_model').read_text().strip()
743
+ except OSError:
744
+ return None
745
+ if not re.fullmatch(r'[0-9]{1,9}', value):
746
+ return None
747
+ return int(value) if 1 <= int(value) <= 99 else None
748
+
749
+
750
+ def rungs_above(spec: str, plan: Path) -> list:
751
+ """The specs the policy would move through from `spec`, in order: repeated stronger() until it
752
+ returns None, then, with the effort step on, repeated _next_effort_spec on the last one. A spec
753
+ in none of the pools has none. Stops on a repeat, and at MAX_RUNGS."""
754
+ if spec in NON_MODEL_DWARFS:
755
+ return []
756
+ registry = registry_models()
757
+ pools = load_pools(plan / 'fractal-routing.json')
758
+ if rank_of(spec, pools, registry) is None:
759
+ return []
760
+ out, seen = [], {spec}
761
+ current = spec
762
+ while len(out) < MAX_RUNGS:
763
+ target, _why = stronger(current, pools, registry)
764
+ if not target or target in seen:
765
+ break
766
+ out.append(target)
767
+ seen.add(target)
768
+ current = target
769
+ if _effort_step(plan):
770
+ while len(out) < MAX_RUNGS:
771
+ target = _next_effort_spec(current)
772
+ if not target or target in seen:
773
+ break
774
+ out.append(target)
775
+ seen.add(target)
776
+ current = target
777
+ return out
778
+
779
+
780
+ def _task_listed(plan: Path, task: str) -> bool:
781
+ try:
782
+ lines = (plan / 'tasks.tsv').read_text().splitlines()
783
+ except OSError:
784
+ return False
785
+ return any(not line.startswith('#') and line.split('\t')[0] == task for line in lines)
786
+
787
+
788
+ def per_model(plan: Path, task: str) -> dict:
789
+ """{"retry", "rung", "failed_on_rung", "rungs_left", "per_model"}: whether the task may be attempted
790
+ again under the per-model budget. Pins and held decisions are the scheduler's other checks."""
791
+ limit = per_model_setting(plan)
792
+ out = {'retry': False, 'rung': '', 'failed_on_rung': 0, 'rungs_left': 0, 'per_model': limit}
793
+ if limit is None or not task or not _task_listed(plan, task):
794
+ return out
795
+ current = _dwarf_of(plan, task)
796
+ tdir = plan / 'tasks' / task
797
+ decided = decided_attempt(tdir)
798
+ rows = [row for row in attempt_rows(tdir) if row[0] > decided]
799
+ failed = failed_streak(rows, current, registry_models(), by_effort=_effort_step(plan),
800
+ laterals=lateral_rows(tdir))
801
+ left = len(rungs_above(current, plan))
802
+ out.update(rung=current, failed_on_rung=failed, rungs_left=left, retry=failed < limit or left > 0)
803
+ return out
804
+
805
+
806
+ def _shadow_rate(plan: Path) -> float:
807
+ try:
808
+ rate = float((plan / 'shadow_rate').read_text().strip())
809
+ except (OSError, ValueError):
810
+ return 0.1
811
+ # As forge-shadow.py's rate_of reads it: a share past 1 samples every review, never more.
812
+ return min(max(rate, 0.0), 1.0) if rate == rate else 0.1
813
+
814
+
815
+ def worst_case(plan: Path) -> dict:
816
+ """The most dispatches the unmerged tasks can spend if every rung fails N times: the implementer's
817
+ (`dwarf`), the reviewer's (`qa`) and the shadow reviews (`shadow`). N is 1 without retry_per_model."""
818
+ limit = per_model_setting(plan)
819
+ n = limit or 1
820
+ cap = max_attempts_setting(plan)
821
+ shadow_on = (plan / 'shadow_qa').exists()
822
+ rate = _shadow_rate(plan)
823
+ tasks, capped = [], []
824
+ try:
825
+ lines = (plan / 'tasks.tsv').read_text().splitlines()
826
+ except OSError:
827
+ lines = []
828
+ for line in lines:
829
+ cells = line.split('\t')
830
+ if line.startswith('#') or not cells or not cells[0]:
831
+ continue
832
+ task = cells[0]
833
+ if (plan / 'tasks' / task / 'merged').exists():
834
+ continue
835
+ dwarf = cells[4] if len(cells) > 4 else ''
836
+ rungs = 1 if dwarf in NON_MODEL_DWARFS else 1 + len(rungs_above(dwarf, plan))
837
+ qa = n * rungs
838
+ tasks.append({'id': task, 'rungs': rungs, 'dwarf': 0 if dwarf == 'script' else n * rungs,
839
+ 'qa': qa, 'shadow': math.ceil(qa * rate) if shadow_on else 0})
840
+ if cap > 0 and n * rungs > cap:
841
+ capped.append(task)
842
+ total = sum(t['dwarf'] + t['qa'] + t['shadow'] for t in tasks)
843
+ return {'per_model': limit, 'tasks': tasks, 'total': total, 'capped': capped}
844
+
845
+
696
846
  def _fractal(plan: Path) -> bool:
697
847
  try:
698
848
  return bool(json.loads((plan / 'fractal-selection.json').read_text()).get('enabled'))
@@ -716,10 +866,11 @@ def max_attempts_setting(plan: Path) -> int:
716
866
 
717
867
 
718
868
  def attempts_spent(tdir: Path) -> int:
719
- """Attempts the task has used: the attempts.tsv rows whose status is not INFRA. An infrastructure stop
720
- spends none. A QA-only resume re-reviews the same attempt number and writes a row of its own, and that
869
+ """Attempts the task has used: the attempts.tsv rows whose status is not INFRA or STALE. An infrastructure
870
+ stop spends none, and neither does an attempt whose prompt was edited while it ran (STALE). A QA-only
871
+ resume re-reviews the same attempt number and writes a row of its own, and that
721
872
  row spends one too: a task whose reviews return no verdict reaches its cap like any other."""
722
- return sum(1 for _number, status, _spec in attempt_rows(tdir) if status != 'INFRA')
873
+ return sum(1 for _number, status, _spec in attempt_rows(tdir) if status not in ('INFRA', 'STALE'))
723
874
 
724
875
 
725
876
  def granted_attempts(tdir: Path) -> int:
@@ -876,16 +1027,22 @@ def _qa_next(tdir: Path) -> bool:
876
1027
  return False
877
1028
 
878
1029
 
1030
+ def _patience(plan: Path) -> int:
1031
+ """Failures on one model before the next tier: retry_per_model when set (#141, it replaces
1032
+ escalate_after for its plan), else escalate_after. 0 is off."""
1033
+ return per_model_setting(plan) or _setting(plan)
1034
+
1035
+
879
1036
  def _apply(plan: Path, tdir: Path, clear=(), writes=(), policy=True, pin=None):
880
1037
  """Clear and write markers under the control lock. Returns (policy stood, pin reported).
881
1038
 
882
- The policy re-reads escalate_after inside the lock (a human may have switched it off since
1039
+ The policy re-reads its patience inside the lock (a human may have switched it off since
883
1040
  the decision was made): it then writes nothing and its markers go, as `--escalate-after 0`
884
- clears them. A pin is reported as escalation.next only while it is still pending; the stop
1041
+ clears them. retry_per_model, when set, is that patience, as in escalation(). A pin is reported as escalation.next only while it is still pending; the stop
885
1042
  and split markers beneath it stay the policy's, because the pin has not been applied.
886
1043
  """
887
1044
  with _control_lock(plan):
888
- stood = policy and _setting(plan) > 0
1045
+ stood = policy and _patience(plan) > 0
889
1046
  if policy and not stood:
890
1047
  clear, writes = MARKERS, ()
891
1048
  reported = pin is not None and _pin(tdir) == pin
@@ -900,6 +1057,9 @@ def _apply(plan: Path, tdir: Path, clear=(), writes=(), policy=True, pin=None):
900
1057
  def _decide(plan: Path, tdir: Path, args, after: int):
901
1058
  """What the policy wants done to the markers: (clear, writes, spec to print, exit code)."""
902
1059
  current = _dwarf_of(plan, args.task)
1060
+ if current == 'script':
1061
+ # No implementer to escalate, and no pin to report: drop any markers a model once left.
1062
+ return MARKERS, (), '', 0
903
1063
  if not current or current in ('-', 'UNASSIGNED'):
904
1064
  return (), (), '', 0
905
1065
  registry = registry_models()
@@ -931,7 +1091,13 @@ def escalation(args) -> int:
931
1091
  tdir = _task_dir(plan, args.task)
932
1092
  if tdir is None:
933
1093
  return 0
934
- after = _setting(plan)
1094
+ # A scripted task has no model to change. Idle, even with a pending pin or a failed streak:
1095
+ # print nothing, leave no escalation marker, and remove ones already there. The pin file
1096
+ # itself stays; nothing here applies it.
1097
+ if _is_script(plan, args.task):
1098
+ _clear(tdir, *MARKERS)
1099
+ return 0
1100
+ after = _patience(plan)
935
1101
  fractal = _fractal(plan)
936
1102
  # Fractal plans freeze their eligible set at selection; a QA-only resume spends no dwarf
937
1103
  # attempt, so neither is a moment to change the implementer.
@@ -1054,6 +1220,11 @@ def main(argv=None) -> int:
1054
1220
  p.add_argument('--plan', required=True)
1055
1221
  p.add_argument('--task', required=True)
1056
1222
  p.add_argument('--exclude', default='', help='harness/model pairs to skip, comma-separated (harness/* for all)')
1223
+ p = sub.add_parser('per-model', help='whether a task may retry under plan --retry-per-model (exit 2 without it)')
1224
+ p.add_argument('--plan', required=True)
1225
+ p.add_argument('--task', required=True)
1226
+ p = sub.add_parser('worst-case', help='the most dispatches the unmerged tasks can spend under --retry-per-model')
1227
+ p.add_argument('--plan', required=True)
1057
1228
  for name in ('record', 'lateral'):
1058
1229
  p = sub.add_parser(name, help=argparse.SUPPRESS)
1059
1230
  p.add_argument('--plan', required=True)
@@ -1077,6 +1248,13 @@ def main(argv=None) -> int:
1077
1248
  return record_lateral(args)
1078
1249
  if args.command == 'attempt-cap':
1079
1250
  return attempt_cap_cmd(args)
1251
+ if args.command == 'per-model':
1252
+ result = per_model(Path(os.path.realpath(args.plan)), args.task)
1253
+ print(json.dumps(result))
1254
+ return 0 if result['per_model'] is not None else 2
1255
+ if args.command == 'worst-case':
1256
+ print(json.dumps(worst_case(Path(os.path.realpath(args.plan)))))
1257
+ return 0
1080
1258
  if args.command in ('fallback', 'qa-fallback'):
1081
1259
  try:
1082
1260
  return (fallback if args.command == 'fallback' else qa_fallback)(args)