@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
@@ -8,13 +8,21 @@
8
8
  pre-review-tests
9
9
  (on/off), pre-review-parallel (1-64), max-attempts (0 = no cap;
10
10
  needs --confirm: raising the cap is a person's decision),
11
- converge-window (reviews the non-converging signal looks at)
11
+ converge-window (reviews the non-converging signal looks at),
12
+ summaries (on/off; with --task also inherit; on for a finished run
13
+ also starts `forge summarize` detached, output in summaries.out)
12
14
  pin <plan> <task> <spec> the model the task's next FULL implementer retry uses
13
15
  unpin <plan> <task>
14
16
  retry <plan> <task> [--dwarf SPEC] queue a retry of a stopped or failed task into the live run
17
+ retry <plan> <task> --answer TEXT answer a NEEDS_INPUT task's question (or --answer-file F, - for stdin):
18
+ queued into the live run, which writes tasks/<id>/answer.md and
19
+ requeues the task; with no run live, `forge-parallel.sh retry
20
+ --answer-file --no-dispatch` prepares it for the next `run`
15
21
  a NEEDS_DECISION task (reviews that do not converge, or a stop with no
16
22
  stronger model) is resumed only by a decision: --decide retry=N or
17
23
  threshold=P0..P3, or --dwarf SPEC, each with --reason TEXT --approved
24
+ accept <plan> <task> --reason TEXT --approved queue an accept of a FAIL, UNKNOWN or NEEDS_DECISION task into the
25
+ live run: its findings become known issues, it merges, its dependents start
18
26
  add <plan> <task> queue a row added to tasks.tsv (with its prompt.md) into the live run
19
27
  drain <plan> start nothing new; running tasks finish and the scheduler waits
20
28
  while tasks remain (with none left to start, the run ends as usual)
@@ -46,6 +54,9 @@ A pin, a retry's --dwarf and an added row's specs are checked with `forge-dispat
46
54
  FORGE_CONTROL_DOCTOR replaces `bash forge-dispatch.sh doctor` with another command line, which
47
55
  then gets `--spec <spec> --role <role>`; tests use it.
48
56
 
57
+ An answer is 1 to 8000 characters (after stripping), with no NUL byte, and its request must fit the
58
+ scheduler's 64 KiB limit. control.log records the retry with the value `answer` and `answer_chars`, never the text.
59
+
49
60
  Exit codes: 0 ok, 2 usage or invalid input (including an unsafe path), 3 refused (not live, MERGED,
50
61
  Fractal, a spec that fails doctor, the control lock busy for over 5 s).
51
62
  """
@@ -62,6 +73,7 @@ import shlex
62
73
  import stat
63
74
  import subprocess
64
75
  import sys
76
+ import tempfile
65
77
  import time
66
78
  from pathlib import Path
67
79
 
@@ -91,6 +103,7 @@ NEXT_VERIFY = 'at the next verification'
91
103
  NEXT_INFRA_WAIT = 'at the next infrastructure wait'
92
104
  NEXT_INFRA_STOP = 'at the next infrastructure stop'
93
105
  NEXT_DISPATCH = "at the scheduler's next dispatch decision"
106
+ NEXT_CHANGE = "at the task's next change"
94
107
 
95
108
 
96
109
  class Invalid(Exception):
@@ -374,8 +387,9 @@ def task_status(plan, task, strict=False):
374
387
  return words[0] if words else 'PENDING'
375
388
 
376
389
 
377
- def refuse_task(plan, task, pin=False):
378
- if task_status(plan, task, strict=True) == 'MERGED':
390
+ def refuse_task(plan, task, pin=False, merged_ok=False):
391
+ # merged_ok: a switch that changes no run behaviour (summaries) may still be set on a finished task.
392
+ if task_status(plan, task, strict=True) == 'MERGED' and not merged_ok:
379
393
  raise Refused(f'task {task} is MERGED: nothing left to change')
380
394
  if pin and is_fractal(plan):
381
395
  raise Refused('this plan runs under Fractal, which never applies pins')
@@ -564,6 +578,12 @@ def _onoff(value, _task):
564
578
  raise Invalid('needs on or off')
565
579
 
566
580
 
581
+ def _summaries(value, task):
582
+ if value in ('on', 'off') or (task and value == 'inherit'):
583
+ return value
584
+ raise Invalid('needs on or off' + (' (or inherit to drop the override)' if task else ''))
585
+
586
+
567
587
  # key -> (plan only or both, validator, file, live only, when it applies)
568
588
  KEYS = {
569
589
  'qa-threshold': ('both', _qa, 'qa_threshold', False, NEXT_ATTEMPT),
@@ -580,6 +600,7 @@ KEYS = {
580
600
  'pre-review-parallel': ('plan', _parallel, 'pre_review_parallel', False, NEXT_ATTEMPT),
581
601
  'max-attempts': ('plan', _int, 'max_attempts', False, NEXT_DECISION),
582
602
  'converge-window': ('plan', _int, 'converge_window', False, NEXT_DECISION),
603
+ 'summaries': ('both', _summaries, 'summaries', False, NEXT_CHANGE),
583
604
  }
584
605
 
585
606
 
@@ -607,14 +628,15 @@ def audit(plan, actor, action, task, key, value, previous, **extra):
607
628
  return entry
608
629
 
609
630
 
610
- def change(args, plan, rows, action, task, key, work, applies, summary, live_only=False, pin_guard=False):
631
+ def change(args, plan, rows, action, task, key, work, applies, summary, live_only=False, pin_guard=False,
632
+ merged_ok=False):
611
633
  """Run work() -> (value, previous, changed) under the control lock, audit a change, report the result."""
612
634
  with control_lock(plan):
613
635
  probe(plan, 'control.log') # an unsafe log refuses the change instead of leaving it unaudited
614
636
  if live_only and not is_live(plan):
615
637
  raise Refused(f'{key or action} can only change while a run is live (no live scheduler for this plan)')
616
638
  if task:
617
- refuse_task(plan, task, pin_guard)
639
+ refuse_task(plan, task, pin_guard, merged_ok)
618
640
  value, previous, changed = work()
619
641
  if changed: # setting a value it already has, or unpinning nothing, is not a change
620
642
  audit(plan, args.actor, action, task, key, value, previous)
@@ -668,8 +690,28 @@ def cmd_set(args):
668
690
  return value, previous, changed or any(swept)
669
691
 
670
692
  where = f'task {task}' if task else 'the plan'
671
- return change(args, plan, rows, 'set', task, args.key, work, applies,
672
- lambda v: f'set {args.key} {v} on {where}', live_only=live_only)
693
+ done = change(args, plan, rows, 'set', task, args.key, work, applies,
694
+ lambda v: f'set {args.key} {v} on {where}', live_only=live_only,
695
+ merged_ok=args.key == 'summaries')
696
+ if args.key == 'summaries' and value == 'on':
697
+ start_summaries(plan, task)
698
+ return done
699
+
700
+
701
+ def start_summaries(plan, task):
702
+ """A finished run has no scheduler to notice a change: `summaries on` starts `forge summarize` itself,
703
+ detached, its output in summaries.out. A live run's scheduler does it at the next change instead.
704
+ Best effort: the switch is already set."""
705
+ if is_live(plan):
706
+ return
707
+ command = [sys.executable, os.path.join(SKILL, 'scripts', 'forge-summarize.py'), plan]
708
+ if task:
709
+ command += ['--task', task]
710
+ try:
711
+ 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)
713
+ except OSError:
714
+ pass
673
715
 
674
716
 
675
717
  def doctor(spec, role='dwarf'):
@@ -804,12 +846,17 @@ def check_row(plan, rows, task):
804
846
  return dwarf, qa
805
847
 
806
848
 
807
- def queue(args, plan, verb, task, dwarf, decision=None):
849
+ def queue(args, plan, verb, task, dwarf, decision=None, accept_reason=None, answer=None):
808
850
  """Write the request under the control lock, live only; log it with its id.
809
- decision: a retry's (--decide choice or None, reason, approved) for a NEEDS_DECISION task."""
851
+ decision: a retry's (--decide choice or None, reason, approved) for a NEEDS_DECISION task.
852
+ accept_reason: an accept's reason; it is given with --approved (#138).
853
+ answer: a NEEDS_INPUT task's answer (#147); the log records that there was one, never the text."""
810
854
  with control_lock(plan):
811
855
  probe(plan, 'control.log')
812
856
  if not is_live(plan):
857
+ if verb == 'accept':
858
+ raise Refused(f'accept needs a live run (no live scheduler for this plan); with no run going, accept it '
859
+ f'directly: forge-parallel.sh accept {plan} {task} --reason TEXT --approved')
813
860
  raise Refused(f'{verb} needs a live run (no live scheduler for this plan)')
814
861
  if verb == 'retry':
815
862
  refuse_task(plan, task, pin=True)
@@ -817,13 +864,26 @@ def queue(args, plan, verb, task, dwarf, decision=None):
817
864
  request = dict(verb=verb, task=task, dwarf=dwarf, at=time.time(), actor=args.actor)
818
865
  if decision:
819
866
  request.update(decide=decision[0], reason=decision[1], approved=True)
820
- write_atomic(plan, f'{REQUESTS}/{name}', json.dumps(request) + '\n')
821
- audit(plan, args.actor, verb, task, None, dwarf or (decision[0] if decision else None), None, request=name)
867
+ extra = {}
868
+ if accept_reason is not None:
869
+ request.update(reason=accept_reason, approved=True)
870
+ extra['reason'] = accept_reason
871
+ if answer is not None:
872
+ request['answer'] = answer
873
+ extra['answer_chars'] = len(answer)
874
+ body = json.dumps(request) + '\n'
875
+ if len(body.encode('utf-8')) > REQUEST_MAX:
876
+ raise Refused(f'the answer does not fit in a request ({len(body.encode("utf-8"))} bytes, the scheduler reads '
877
+ f'at most {REQUEST_MAX}): shorten it')
878
+ write_atomic(plan, f'{REQUESTS}/{name}', body)
879
+ audit(plan, args.actor, verb, task, None,
880
+ 'answer' if answer is not None else dwarf or (decision[0] if decision else None), None, request=name, **extra)
822
881
  if args.json:
823
882
  json.dump(dict(queued=True, request=name), sys.stdout)
824
883
  sys.stdout.write('\n')
825
884
  else:
826
- print(f'queued {verb} of task {task}' + (f' on {dwarf}' if dwarf else '') + f' (request {name}); '
885
+ print(f'queued {verb} of task {task}' + (f' on {dwarf}' if dwarf else '') + (' with an answer' if answer is not None else '')
886
+ + f' (request {name}); '
827
887
  'the scheduler applies or refuses it at its next pass and logs the outcome in control.log')
828
888
  return 0
829
889
 
@@ -855,9 +915,101 @@ def decision_of(plan, args, dwarf):
855
915
  return args.decide, reason, True
856
916
 
857
917
 
918
+ ANSWER_MAX = 8000 # characters; the scheduler reads the same limit
919
+ REQUEST_MAX = 64 * 1024 # bytes of one request file; the scheduler ignores a larger one
920
+ ANSWER_READ = ANSWER_MAX * 4 + 1024 # bytes; one more means the file continues past the read
921
+
922
+
923
+ def read_capped(handle):
924
+ """Up to ANSWER_READ bytes, and whether at least one byte follows."""
925
+ data = handle.read(ANSWER_READ)
926
+ extra = handle.read(1) if len(data) == ANSWER_READ else b''
927
+ return data, extra
928
+
929
+
930
+ def answer_file_text(path):
931
+ """The answer file's text. A file that continues past the read is over the character limit:
932
+ a prefix of only whitespace is not an empty answer, and a character split by the read is not bad UTF-8."""
933
+ try:
934
+ if path == '-':
935
+ data, extra = read_capped(sys.stdin.buffer)
936
+ else:
937
+ with open(path, 'rb') as handle:
938
+ data, extra = read_capped(handle)
939
+ except OSError as error:
940
+ raise Invalid(f'--answer-file {path}: {error.strerror or error}')
941
+ try:
942
+ text = data.decode('utf-8')
943
+ except UnicodeDecodeError as error:
944
+ if extra and error.reason == 'unexpected end of data':
945
+ raise Invalid(f'the answer is limited to {ANSWER_MAX} characters')
946
+ raise Invalid('the answer is not valid UTF-8 text')
947
+ if extra and not text.strip():
948
+ raise Invalid(f'the answer is limited to {ANSWER_MAX} characters')
949
+ return text
950
+
951
+
952
+ def answer_of(args):
953
+ """The answer --answer or --answer-file gives (stripped), None when neither is given."""
954
+ if args.answer is None and args.answer_file is None:
955
+ return None
956
+ if args.answer is not None and args.answer_file is not None:
957
+ raise Invalid('give --answer or --answer-file, not both')
958
+ if args.dwarf is not None or args.decide is not None:
959
+ raise Invalid('--answer answers a NEEDS_INPUT task and is not combined with --dwarf or --decide')
960
+ if args.reason is not None or args.approved:
961
+ raise Invalid('--answer answers a NEEDS_INPUT task and is not combined with --reason or --approved')
962
+ text = args.answer
963
+ if args.answer_file is not None:
964
+ text = answer_file_text(args.answer_file)
965
+ text = text.strip()
966
+ if not text:
967
+ raise Invalid('the answer is empty')
968
+ if '\0' in text:
969
+ raise Invalid('the answer contains a NUL byte')
970
+ if len(text) > ANSWER_MAX:
971
+ raise Invalid(f'the answer is limited to {ANSWER_MAX} characters')
972
+ return text
973
+
974
+
975
+ def retry_prepared(args, plan, answer):
976
+ """No scheduler is live: prepare the answered task for the next `run`, as `forge-parallel.sh retry
977
+ --answer-file --no-dispatch` does, and pass its exit code through."""
978
+ fd, tmp = tempfile.mkstemp(dir=plan, prefix='.answer-', suffix='.txt') # 0600
979
+ try:
980
+ with os.fdopen(fd, 'w', encoding='utf-8') as handle:
981
+ 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']
984
+ if args.json: # stdout is the JSON: the command's own words go to stderr
985
+ done = subprocess.run(command, stdin=subprocess.DEVNULL, capture_output=True, text=True)
986
+ sys.stderr.write(done.stdout + done.stderr)
987
+ else:
988
+ done = subprocess.run(command, stdin=subprocess.DEVNULL)
989
+ finally:
990
+ with contextlib.suppress(OSError):
991
+ os.unlink(tmp)
992
+ if done.returncode == 0 and args.json:
993
+ json.dump(dict(queued=False, prepared=True), sys.stdout)
994
+ sys.stdout.write('\n')
995
+ elif done.returncode == 0:
996
+ print(f'no run is live: task {args.task} is prepared with your answer; the next `forge-parallel.sh run {plan}` '
997
+ 'dispatches it')
998
+ return done.returncode
999
+
1000
+
858
1001
  def cmd_retry(args):
859
1002
  plan, rows = load(args.plan)
860
1003
  require_task(rows, args.task)
1004
+ answer = answer_of(args)
1005
+ if answer is not None:
1006
+ refuse_task(plan, args.task, pin=True)
1007
+ status = task_status(plan, args.task, strict=True)
1008
+ if status != 'NEEDS_INPUT':
1009
+ raise Refused(f'task {args.task} is {status}, not waiting for an answer: --answer only answers a NEEDS_INPUT task')
1010
+ if not is_live(plan):
1011
+ return retry_prepared(args, plan, answer)
1012
+ return queue(args, plan, 'retry', args.task, None, answer=answer)
861
1013
  dwarf = None
862
1014
  if args.dwarf is not None:
863
1015
  dwarf = clean_spec(args.dwarf, '--dwarf')
@@ -868,6 +1020,29 @@ def cmd_retry(args):
868
1020
  return queue(args, plan, 'retry', args.task, dwarf, decision)
869
1021
 
870
1022
 
1023
+ ACCEPTABLE = ('FAIL', 'UNKNOWN', 'NEEDS_DECISION') # what plain `accept` takes: a verdict to override
1024
+
1025
+
1026
+ def cmd_accept(args):
1027
+ """Queue an accept into the live run (#138): the scheduler holds the plan lock that plain
1028
+ `forge-parallel.sh accept` needs, so it applies the request itself at its next pass."""
1029
+ plan, rows = load(args.plan)
1030
+ require_task(rows, args.task)
1031
+ refuse_task(plan, args.task)
1032
+ reason = re.sub(r'\s+', ' ', args.reason or '').strip()
1033
+ if not reason:
1034
+ raise Invalid('accept needs --reason TEXT: why this work is acceptable despite the reviewer, recorded with the work')
1035
+ if len(reason) > 2000:
1036
+ raise Invalid('--reason is limited to 2000 characters')
1037
+ if not args.approved:
1038
+ raise Invalid('accept needs --approved: it overrides the reviewer\'s verdict, and is only given on the user\'s instruction')
1039
+ status = task_status(plan, args.task, strict=True)
1040
+ if status not in ACCEPTABLE:
1041
+ raise Refused(f'task {args.task} is {status}: accept overrides a reviewer\'s verdict, so it takes a FAIL, '
1042
+ 'UNKNOWN or NEEDS_DECISION task')
1043
+ return queue(args, plan, 'accept', args.task, None, accept_reason=reason)
1044
+
1045
+
871
1046
  def cmd_add(args):
872
1047
  plan, rows = load(args.plan)
873
1048
  dwarf, qa = check_row(plan, rows, args.task)
@@ -940,7 +1115,7 @@ def cmd_show(args):
940
1115
  def parser():
941
1116
  top = argparse.ArgumentParser(prog='forge control', description="Show and change a plan's live controls.")
942
1117
  sub = top.add_subparsers(dest='command', required=True,
943
- metavar='{show,set,pin,unpin,retry,add,drain,resume,stop}')
1118
+ metavar='{show,set,pin,unpin,retry,accept,add,drain,resume,stop}')
944
1119
 
945
1120
  def common(p, mutator=True):
946
1121
  p.add_argument('plan', metavar='PLAN_DIR', help="the plan dir (the one with tasks.tsv)")
@@ -953,11 +1128,12 @@ def parser():
953
1128
  p.set_defaults(func=cmd_show)
954
1129
  p = sub.add_parser('set', help='change a control', description='Keys: ' + ', '.join(KEYS) + '. '
955
1130
  'retry-budget, infra-retries and max-parallel change only while a run is live. '
956
- 'qa-threshold and retry-budget also take --task (value inherit drops the override; at run level, default drops the file and none means P3).')
1131
+ 'qa-threshold, retry-budget and summaries also take --task (value inherit drops the override; at run level, default drops the file and none means P3). '
1132
+ 'summaries on|off turns generated task summaries on or off; on for a finished run also starts them.')
957
1133
  common(p)
958
1134
  p.add_argument('key', choices=list(KEYS))
959
1135
  p.add_argument('value')
960
- p.add_argument('--task', metavar='ID', help='change this task only (qa-threshold, retry-budget)')
1136
+ p.add_argument('--task', metavar='ID', help='change this task only (qa-threshold, retry-budget, summaries)')
961
1137
  p.add_argument('--confirm', action='store_true', help="max-attempts only: the change is a person's decision")
962
1138
  p.set_defaults(func=cmd_set)
963
1139
  p = sub.add_parser('pin', help="set the model a task's next full retry uses")
@@ -974,9 +1150,18 @@ def parser():
974
1150
  p.add_argument('task')
975
1151
  p.add_argument('--dwarf', metavar='SPEC', help='the implementer for this retry (an explicit escalation)')
976
1152
  p.add_argument('--decide', metavar='CHOICE', help='decide a NEEDS_DECISION task: retry=N (1 to 20) or threshold=P0..P3')
1153
+ p.add_argument('--answer', metavar='TEXT', help="answer a NEEDS_INPUT task's question (1 to 8000 characters)")
1154
+ p.add_argument('--answer-file', metavar='FILE', help='the answer, read from FILE (- for stdin)')
977
1155
  p.add_argument('--reason', metavar='TEXT', help='why (a decision needs it)')
978
1156
  p.add_argument('--approved', action='store_true', help='the decision is the user\'s (a decision needs it)')
979
1157
  p.set_defaults(func=cmd_retry)
1158
+ p = sub.add_parser('accept', help="queue an accept of a FAIL or NEEDS_DECISION task into the live run: "
1159
+ "its findings become known issues and it merges (the user's decision only)")
1160
+ common(p)
1161
+ p.add_argument('task')
1162
+ p.add_argument('--reason', metavar='TEXT', required=False, help='why the work is acceptable despite the reviewer (required)')
1163
+ p.add_argument('--approved', action='store_true', help="the decision is the user's (required)")
1164
+ p.set_defaults(func=cmd_accept)
980
1165
  p = sub.add_parser('add', help='queue a row added to tasks.tsv into the live run')
981
1166
  common(p)
982
1167
  p.add_argument('task')
@@ -13,11 +13,13 @@
13
13
  # (claude, openclaude, codex; custom prompt only)
14
14
  # forge-dispatch.sh dwarf <spec> ... --continue-session <id> continue that implementer session
15
15
  # (claude, openclaude)
16
+ # forge-dispatch.sh side <spec> --prompt-file <f> [--repo <dir>] [--run-dir <d>] [--yolo] [--dry-run]
17
+ # read-only; a brief or summary dispatch (default effort low)
16
18
  # any role: [--no-ripwire] [--ripwire-query-file <requirements>]
17
19
  # any role: [--timeout <seconds>] 0 disables the watchdog
18
20
  # any role: [--service-tier fast] codex and claude only; any other harness exits 3
19
21
  # before it runs. doctor --spec takes the same option.
20
- # forge-dispatch.sh doctor --spec <spec> [--role dwarf|qa|planner] [--service-tier fast]
22
+ # forge-dispatch.sh doctor --spec <spec> [--role dwarf|qa|planner|side] [--service-tier fast]
21
23
  # A measured slowdown is `forge: note: …` on stderr, never in
22
24
  # the resolved block. A plain dispatch does not print it.
23
25
  # forge-dispatch.sh efforts --spec <spec>
@@ -52,7 +54,8 @@
52
54
  # provider_down, network, or an empty answer; forge_infra.py says what each
53
55
  # means): the model never got to do its work. $ROLE.infra says which.
54
56
  # A DWARF that exits 0 with an empty final message also writes $ROLE.infra
55
- # (class=empty) but still exits 0; consult the file only if the diff is empty.
57
+ # (class=empty) but still exits 0, as does one its CLI cancelled (class=cancelled);
58
+ # consult the file only if the diff is empty.
56
59
  # 9 the session was not continued (--continue-session only): the harness cannot
57
60
  # continue one, or it ran and failed. The caller may dispatch fresh; dispatch
58
61
  # never does, so each dispatch keeps its own record. $ROLE.continue says why.
@@ -206,14 +209,14 @@ EOT
206
209
  return $rc
207
210
  }
208
211
 
209
- [ $# -ge 1 ] || die "usage: forge-dispatch.sh <doctor|dwarf|qa|planner|efforts> [spec] [options]"
212
+ [ $# -ge 1 ] || die "usage: forge-dispatch.sh <doctor|dwarf|qa|planner|side|efforts> [spec] [options]"
210
213
  if [ "$1" = efforts ]; then shift; efforts_cmd "$@"; exit $?; fi
211
214
  ROLE="$1"; shift
212
215
  if [ "$ROLE" = report ]; then python3 "$RUNTIME" report "${1:?report needs a run directory}"; exit $?; fi
213
216
  PREFLIGHT=0
214
217
  if [ "$ROLE" = doctor ]; then
215
218
  if [ $# = 0 ]; then doctor; exit $?; fi
216
- [ "${1:-}" = --spec ] || die "doctor accepts --spec <spec> [--role dwarf|qa|planner] [--service-tier fast]"
219
+ [ "${1:-}" = --spec ] || die "doctor accepts --spec <spec> [--role dwarf|qa|planner|side] [--service-tier fast]"
217
220
  SPEC_CHECK="${2:?--spec needs a spec}"; shift 2
218
221
  ROLE=dwarf
219
222
  if [ "${1:-}" = --role ]; then ROLE="${2:?}"; shift 2; fi
@@ -223,12 +226,13 @@ if [ "$ROLE" = doctor ]; then
223
226
  echo 'Offline capability check' > "$CHECK_DIR/input"
224
227
  set -- "$SPEC_CHECK" --run-dir "$CHECK_DIR" --prompt-file "$CHECK_DIR/input" "$@"
225
228
  fi
226
- case "$ROLE" in dwarf|qa|planner) ;; *) die "unknown role '$ROLE' (expected dwarf, qa, planner or doctor)" ;; esac
229
+ case "$ROLE" in dwarf|qa|planner|side) ;; *) die "unknown role '$ROLE' (expected dwarf, qa, planner, side or doctor)" ;; esac
227
230
 
228
- # qa and planner both read the repo and write nothing to it: a reviewer that can
229
- # edit the diff is no longer an independent check of it, and a planner that edits
230
- # has quietly become the dwarf. They share one permission profile.
231
- read_only_role() { case "$ROLE" in qa|planner) return 0 ;; *) return 1 ;; esac; }
231
+ # qa, planner and side all read the repo and write nothing to it: a reviewer that
232
+ # can edit the diff is no longer an independent check of it, a planner that edits
233
+ # has quietly become the dwarf, and a side dispatch (a brief or a summary) must
234
+ # not touch the work it is reading. They share one permission profile.
235
+ read_only_role() { case "$ROLE" in qa|planner|side) return 0 ;; *) return 1 ;; esac; }
232
236
  [ $# -ge 1 ] || die "role '$ROLE' needs a spec, e.g. sol:xhigh:openclaude"
233
237
  SPEC="$1"; shift
234
238
 
@@ -330,9 +334,10 @@ else
330
334
  # implementer tends to rubber-stamp, which defeats the point of a second model;
331
335
  # xhigh reviews cost about twice as much for the same verdicts (#89). Planning is
332
336
  # the stage where thinking pays for itself most cheaply — a bad plan is executed
333
- # at full cost by every dwarf downstream of it. forge-parallel.sh's approval
337
+ # at full cost by every dwarf downstream of it. A side dispatch (brief, summary)
338
+ # is a cheap read, so it defaults to low. forge-parallel.sh's approval
334
339
  # table names the QA default (render_table).
335
- case "$ROLE" in dwarf) EFFORT="medium" ;; qa) EFFORT="high" ;; planner) EFFORT="xhigh" ;; esac
340
+ case "$ROLE" in dwarf) EFFORT="medium" ;; qa) EFFORT="high" ;; planner) EFFORT="xhigh" ;; side) EFFORT="low" ;; esac
336
341
  DEFAULTED=1
337
342
  [ -n "$LADDER" ] || EFFORT="" # opencode: no ladder, let the provider choose
338
343
  else
@@ -442,6 +447,7 @@ if [ "$PREFLIGHT" != 1 ] && [ "$DRY" != 1 ]; then
442
447
  for watcher in ${wpid:-} ${spid:-}; do pkill -P "$watcher" 2>/dev/null; kill "$watcher" 2>/dev/null; done
443
448
  [ -z "${cpid:-}" ] || kill "$cpid" 2>/dev/null
444
449
  rm -f "$RUN_DIR/$ROLE.harness" "$RUN_DIR/$ROLE.tracked"
450
+ case "${ROLE_TMP:-}" in "$RUN_DIR"/.*-tmp.*) [ ! -d "$ROLE_TMP" ] || rm -rf -- "$ROLE_TMP" ;; esac
445
451
  }
446
452
  # What the EXIT trap's `finish` archives. Pessimistic until an outcome is known, so every
447
453
  # path out of a continue request (a signal, a usage error after this point) leaves a record.
@@ -527,6 +533,19 @@ cp "$PROMPT_FILE" "$RUN_DIR/$ROLE.delivered"
527
533
  case "$HARNESS" in opencode|antigravity) PROMPT="$(cat "$PROMPT_FILE")" ;; esac
528
534
 
529
535
  # --- build argv ---------------------------------------------------------------
536
+ # A read-only codex role: the read-only sandbox, plus a permissions profile that reads everything
537
+ # and writes only ROLE_TMP (#148). The sandbox mode stays as the fallback: a codex that does not
538
+ # know profiles keeps a plain read-only sandbox. Probed with `codex sandbox -P` and
539
+ # `codex debug prompt-input` (0.164): the profile wins, and the repository stays read-only.
540
+ codex_read_only() {
541
+ CMD+=(-c 'sandbox_mode="read-only"')
542
+ [ -n "$ROLE_TMP" ] || return 0
543
+ local path="${ROLE_TMP//\\/\\\\}"
544
+ path="${path//\"/\\\"}"
545
+ CMD+=(-c 'default_permissions="forge-read-only"'
546
+ -c "permissions.forge-read-only.filesystem={\"/\"=\"read\", \"$path\"=\"write\"}")
547
+ }
548
+
530
549
  # Sets CMD (and PROMPT_VIA_STDIN) for the dispatch, or for the fresh one when CONTINUE_ID is empty.
531
550
  build_cmd() {
532
551
  CMD=()
@@ -554,7 +573,7 @@ build_cmd() {
554
573
  [ -n "$EFFORT" ] && CMD+=(-c "model_reasoning_effort=$EFFORT")
555
574
  [ "$SERVICE_TIER" = fast ] && CMD+=(-c "service_tier=fast")
556
575
  if [ "$YOLO" = 1 ]; then CMD+=(--dangerously-bypass-approvals-and-sandbox)
557
- else CMD+=(-c 'sandbox_mode="read-only"'); fi
576
+ else codex_read_only; fi
558
577
  case "$CONTINUE_ID" in -*) CMD+=(-- "$CONTINUE_ID") ;; esac
559
578
  CMD+=(-)
560
579
  PROMPT_VIA_STDIN=1
@@ -565,7 +584,7 @@ build_cmd() {
565
584
  # --approve-for-me and --dangerously-bypass-... are mutually exclusive.
566
585
  if [ "$YOLO" = 1 ]; then CMD+=(--dangerously-bypass-approvals-and-sandbox)
567
586
  elif [ "$ROLE" = "dwarf" ]; then CMD+=(--approve-for-me)
568
- else CMD+=(-s read-only); fi
587
+ else codex_read_only; fi
569
588
  CMD+=(-)
570
589
  PROMPT_VIA_STDIN=1
571
590
  fi
@@ -675,6 +694,19 @@ build_cmd() {
675
694
  *) die "no dispatch recipe for harness '$HARNESS'" ;;
676
695
  esac
677
696
  }
697
+ # A read-only role's own writable temp dir (#148). Test runners need one (Vitest's EPERM in a
698
+ # read-only sandbox), and the role gets none otherwise. It sits in the run dir, outside the
699
+ # repository, so the tree under review and its fingerprint are untouched; TMPDIR, TMP and TEMP
700
+ # point at it, and the dispatch removes it when it ends. A dry run or a preflight only shows
701
+ # its shape.
702
+ ROLE_TMP=""
703
+ if read_only_role; then
704
+ if [ -n "$ATTEMPT" ]; then
705
+ ROLE_TMP="$(mktemp -d "$RUN_DIR/.$ROLE-tmp.XXXXXX")" || ROLE_TMP=""
706
+ else
707
+ ROLE_TMP="$RUN_DIR/.$ROLE-tmp.XXXXXX"
708
+ fi
709
+ fi
678
710
  build_cmd
679
711
 
680
712
  # Offline validation uses the exact command recipe, never a model request.
@@ -830,10 +862,11 @@ case "${FORGE_ORPHAN_GUARD:-on}" in off|OFF|Off|0|no|false) ;; *)
830
862
  esac
831
863
  RUNCMD=("${CMD[@]}")
832
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"; }
833
866
  if [ "$PROMPT_VIA_STDIN" = 1 ]; then
834
- ( cd "$REPO" && exec "${RUNCMD[@]}" < "$PROMPT_FILE" ) > "$LOG" 2>&1 &
867
+ ( cd "$REPO" && role_env && exec "${RUNCMD[@]}" < "$PROMPT_FILE" ) > "$LOG" 2>&1 &
835
868
  else
836
- ( cd "$REPO" && exec "${RUNCMD[@]}" </dev/null ) > "$LOG" 2>&1 &
869
+ ( cd "$REPO" && role_env && exec "${RUNCMD[@]}" </dev/null ) > "$LOG" 2>&1 &
837
870
  fi
838
871
  hpid=$!
839
872
  # Log clock: when the log grew, so forge-ui can time the commands of a harness whose events