@giamme/forge 0.16.0 → 0.18.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 (95) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/SKILL.md +16 -3
  3. package/VERSION +1 -1
  4. package/docs/artifacts.md +8 -0
  5. package/docs/commands.md +70 -6
  6. package/docs/dataset.md +13 -0
  7. package/docs/decomposed-runs.md +8 -0
  8. package/docs/forge-ui.md +23 -2
  9. package/docs/memory.md +2 -0
  10. package/docs/reviews.md +15 -1
  11. package/docs/safety.md +8 -0
  12. package/forge +24 -1
  13. package/package.json +1 -1
  14. package/references/dataset.md +143 -5
  15. package/references/decision-models.md +15 -2
  16. package/references/decompose.md +180 -11
  17. package/references/planning.md +3 -2
  18. package/references/solo.md +2 -1
  19. package/references/ui.md +5 -2
  20. package/scripts/forge-artifact.sh +14 -0
  21. package/scripts/forge-brief.py +132 -0
  22. package/scripts/forge-compare.py +11 -1
  23. package/scripts/forge-config.py +176 -9
  24. package/scripts/forge-contract.py +98 -4
  25. package/scripts/forge-control.py +86 -13
  26. package/scripts/forge-dispatch.sh +14 -10
  27. package/scripts/forge-du.py +167 -0
  28. package/scripts/forge-issues.py +4 -3
  29. package/scripts/forge-ledger.py +3 -1
  30. package/scripts/forge-lib-adopt.sh +8 -1
  31. package/scripts/forge-lib-plans.sh +5 -2
  32. package/scripts/forge-lib-review.sh +29 -1
  33. package/scripts/forge-metrics.sh +29 -3
  34. package/scripts/forge-parallel-options.sh +4 -0
  35. package/scripts/forge-parallel.sh +506 -10
  36. package/scripts/forge-plan-check.py +25 -2
  37. package/scripts/forge-planner.py +20 -6
  38. package/scripts/forge-prompt.py +120 -0
  39. package/scripts/forge-retro.py +115 -0
  40. package/scripts/forge-runs-compact.py +443 -0
  41. package/scripts/forge-runs-rm.py +2 -0
  42. package/scripts/forge-runs.py +18 -3
  43. package/scripts/forge-schedule.py +279 -4
  44. package/scripts/forge-shadow.py +35 -10
  45. package/scripts/forge-solo.sh +2 -0
  46. package/scripts/forge-summarize.py +698 -0
  47. package/scripts/forge-sweep.py +25 -10
  48. package/scripts/forge-ui-options.sh +10 -0
  49. package/scripts/forge_brief/__init__.py +587 -0
  50. package/scripts/forge_brief/answers.py +459 -0
  51. package/scripts/forge_dataset/__init__.py +10 -0
  52. package/scripts/forge_dataset/cli.py +83 -0
  53. package/scripts/forge_dataset/export.py +18 -4
  54. package/scripts/forge_dataset/facts.py +280 -0
  55. package/scripts/forge_dataset/harvest.py +56 -9
  56. package/scripts/forge_dataset/history.py +5 -3
  57. package/scripts/forge_dataset/outcomes.py +206 -58
  58. package/scripts/forge_dataset/pairs.py +174 -0
  59. package/scripts/forge_dataset/risk.py +108 -0
  60. package/scripts/forge_dataset/tiers.py +427 -0
  61. package/scripts/forge_decide/__init__.py +11 -1
  62. package/scripts/forge_decide/cli.py +23 -2
  63. package/scripts/forge_decide/labels.py +30 -6
  64. package/scripts/forge_decide/replay.py +10 -4
  65. package/scripts/forge_locations.py +366 -0
  66. package/scripts/forge_registry.py +19 -0
  67. package/scripts/forge_retro/__init__.py +417 -0
  68. package/scripts/forge_retro/issues.py +1193 -0
  69. package/scripts/forge_retro/report.py +671 -0
  70. package/scripts/forge_side/__init__.py +477 -0
  71. package/scripts/forge_storage.py +515 -0
  72. package/ui/README.md +68 -8
  73. package/ui/docs/api.md +217 -20
  74. package/ui/forge_ui/control.py +92 -11
  75. package/ui/forge_ui/export.py +31 -5
  76. package/ui/forge_ui/findings.py +4 -2
  77. package/ui/forge_ui/links.py +337 -0
  78. package/ui/forge_ui/models.py +57 -4
  79. package/ui/forge_ui/projects.py +4 -1
  80. package/ui/forge_ui/reader.py +732 -34
  81. package/ui/forge_ui/server.py +8 -0
  82. package/ui/forge_ui/static/app.js +92 -5
  83. package/ui/forge_ui/static/briefview.js +302 -0
  84. package/ui/forge_ui/static/checksview.js +6 -2
  85. package/ui/forge_ui/static/controls.js +5 -0
  86. package/ui/forge_ui/static/diffview.js +7 -3
  87. package/ui/forge_ui/static/index.html +3 -0
  88. package/ui/forge_ui/static/panel.js +311 -4
  89. package/ui/forge_ui/static/runmodel.js +13 -1
  90. package/ui/forge_ui/static/storageview.js +271 -0
  91. package/ui/forge_ui/static/style.css +100 -3
  92. package/ui/forge_ui/static/worktreesview.js +3 -3
  93. package/ui/forge_ui/storage.py +136 -0
  94. package/ui/forge_ui/transcripts.py +35 -10
  95. package/ui/forge_ui/worktrees.py +154 -13
@@ -0,0 +1,280 @@
1
+ """`forge dataset facts`: the reach, origin and evidence reviewers give each finding (#119), measured in shadow.
2
+
3
+ A reviewer ends a finding's first line with `{reach=main|realistic|unusual origin=new|existing
4
+ evidence=ran|traced|suspected}`. Nothing in forge decides on these facts yet. This report says whether
5
+ a gate that did would be better than the severity line alone:
6
+
7
+ coverage how many findings carry the facts, and how reach splits by severity
8
+ agreement pairs of reviews of one attempt (`--shadow-qa`): of the findings both reviewers name (same
9
+ file, lines at most LINE_WINDOW apart), how often they agree on the severity and on each
10
+ fact, raw and chance-corrected (Cohen's kappa, since severity has four values and reach three)
11
+ rules each candidate rule replayed on the review every task attempt ended on, against the same
12
+ replay without it: the reviews that would have passed, the attempts after them that would
13
+ not have run, and the findings that would have stopped blocking, to check by hand whether
14
+ they were bugs that mattered
15
+
16
+ The rules only relax: a finding they release is CONFIRMED with a severity at the threshold or worse.
17
+ `unusual` releases reach=unusual unless it is P0 (P0 is data loss, a security hole or a crash: the
18
+ "unless security or data loss" exception), `existing` releases origin=existing (it would go to the
19
+ backlog), `both` does both. An unlabelled finding is never released, as it blocks at every threshold.
20
+
21
+ Advisory only: nothing that builds a prompt, gates or routes reads this report.
22
+ """
23
+ from __future__ import annotations
24
+
25
+ import json
26
+ import os
27
+ import re
28
+ import sys
29
+ from collections import Counter, defaultdict
30
+
31
+ from . import connect, dataset_dir, is_side_role
32
+ from .export import Runs, Store, _ending_qa, _gate_decision, not_an_attempt, shadow_pairs
33
+
34
+ FACTS = {'reach': ('main', 'realistic', 'unusual'), 'origin': ('new', 'existing'),
35
+ 'evidence': ('ran', 'traced', 'suspected')}
36
+ LINE_WINDOW = 10
37
+ EXAMPLES = 50
38
+ RULES = {
39
+ 'unusual': 'unusual reach does not block unless P0',
40
+ 'existing': 'existing findings do not block',
41
+ 'both': 'both of the above',
42
+ }
43
+ _WHERE = re.compile(r'([\w./\\-]+\.\w+|[\w./\\-]+/[\w.-]+):(\d+)')
44
+
45
+
46
+ def _facts(f) -> dict:
47
+ found = f.get('facts')
48
+ return found if isinstance(found, dict) else {}
49
+
50
+
51
+ def _released(rule):
52
+ def release(f):
53
+ sev, facts = f.get('severity'), _facts(f)
54
+ if f.get('status') not in ('CONFIRMED', 'UNSTATED') or sev is None:
55
+ return False
56
+ unusual = facts.get('reach') == 'unusual' and sev > 0
57
+ existing = facts.get('origin') == 'existing'
58
+ return {'unusual': unusual, 'existing': existing, 'both': unusual or existing}[rule]
59
+ return release
60
+
61
+
62
+ def decide(verdict, found, rank, release=lambda f: False) -> str:
63
+ """pass or fail: forge-contract's gate on recorded findings, with `release`d findings tolerated.
64
+
65
+ Without a release it is the gate itself: a PASS fails on a blocking finding (CONFIRMED or UNSTATED,
66
+ at the threshold or worse, or unlabelled); a FAIL passes when it has CONFIRMED findings, none
67
+ UNSTATED, and every CONFIRMED one is labelled below the threshold. A released finding counts as
68
+ tolerated, so a FAIL whose blocking findings are all released passes."""
69
+ def tolerated(f):
70
+ return release(f) or (f.get('severity') is not None and f['severity'] > rank)
71
+ if verdict == 'PASS':
72
+ return 'fail' if any(f.get('status') in ('CONFIRMED', 'UNSTATED') and not tolerated(f) for f in found) else 'pass'
73
+ confirmed = [f for f in found if f.get('status') == 'CONFIRMED']
74
+ if not confirmed or any(f.get('status') == 'UNSTATED' and not release(f) for f in found):
75
+ return 'fail'
76
+ return 'pass' if all(tolerated(f) for f in confirmed) else 'fail'
77
+
78
+
79
+ def _rank(value) -> int:
80
+ value = (value or '').strip().upper()
81
+ if value == 'NONE':
82
+ return 3
83
+ return int(value[1]) if value in ('P0', 'P1', 'P2', 'P3') else 2
84
+
85
+
86
+ def _threshold(runs, run, task, attempt):
87
+ """The threshold the attempt's gate ran with (its qa.gate line), else the plan's, else P2."""
88
+ for e in runs.attempts.get((run, task), []):
89
+ if e['attempt'] == attempt:
90
+ cells = (e['d'].get('gate') or '').split('\t')
91
+ if cells[0].strip():
92
+ return _rank(cells[0])
93
+ plans = runs.plans.get(run) or []
94
+ return _rank(((plans[-1]['d'].get('options') or {}).get('qa_threshold')) if plans else None)
95
+
96
+
97
+ def _kappa(pairs) -> float | None:
98
+ if not pairs:
99
+ return None
100
+ n = len(pairs)
101
+ seen = sum(a == b for a, b in pairs) / n
102
+ left, right = Counter(a for a, _ in pairs), Counter(b for _, b in pairs)
103
+ chance = sum(left[c] * right[c] for c in left) / (n * n)
104
+ return None if chance >= 1 else (seen - chance) / (1 - chance)
105
+
106
+
107
+ def _where(f):
108
+ match = _WHERE.search(f.get('head') or '')
109
+ return (match.group(1), int(match.group(2))) if match else None
110
+
111
+
112
+ def _matched(a_found, b_found) -> list:
113
+ """(a, b) findings two reviewers both named: same file, the nearest line at most LINE_WINDOW apart."""
114
+ out, used = [], set()
115
+ for a in a_found:
116
+ at = _where(a)
117
+ if at is None:
118
+ continue
119
+ best = None
120
+ for i, b in enumerate(b_found):
121
+ bt = _where(b)
122
+ if i in used or bt is None or bt[0] != at[0] or abs(bt[1] - at[1]) > LINE_WINDOW:
123
+ continue
124
+ if best is None or abs(bt[1] - at[1]) < best[0]:
125
+ best = (abs(bt[1] - at[1]), i)
126
+ if best is not None:
127
+ used.add(best[1])
128
+ out.append((a, b_found[best[1]]))
129
+ return out
130
+
131
+
132
+ def _measure(pairs) -> dict:
133
+ return dict(compared=len(pairs), agree=sum(a == b for a, b in pairs),
134
+ kappa=None if _kappa(pairs) is None else round(_kappa(pairs), 3))
135
+
136
+
137
+ def _empty():
138
+ return dict(coverage=dict(reviews=0, reviews_with_facts=0, findings=0, findings_with_facts=0,
139
+ values={k: {} for k in FACTS}, reach_by_severity={}),
140
+ agreement=dict(pairs=0, matched=0, severity=_measure([]), **{k: _measure([]) for k in FACTS}),
141
+ rules=dict(reviews=0, reviews_with_facts=0,
142
+ **{name: dict(label=label, would_pass=0, attempts_saved=0, released=[])
143
+ for name, label in RULES.items()}),
144
+ line_window=LINE_WINDOW)
145
+
146
+
147
+ def report(runs: Runs, repo: str = None) -> dict:
148
+ out = _empty()
149
+ paths = runs.store.repo_paths
150
+
151
+ def mine(e):
152
+ return not repo or paths.get(e['repo']) == repo
153
+
154
+ cov = out['coverage']
155
+ values = {k: Counter() for k in FACTS}
156
+ by_sev = defaultdict(Counter)
157
+ for e in runs.store.of('dispatch'):
158
+ d = e['d']
159
+ role = d.get('role')
160
+ # qa and qa_shadow are reviews. A side dispatch is neither, even when it carries a findings list.
161
+ if role not in ('qa', 'qa_shadow') or is_side_role(role) or not mine(e) or not isinstance(d.get('findings'), list):
162
+ continue
163
+ found = [f for f in d['findings'] if isinstance(f, dict)]
164
+ cov['reviews'] += 1
165
+ cov['reviews_with_facts'] += any(_facts(f) for f in found)
166
+ for f in found:
167
+ cov['findings'] += 1
168
+ facts = _facts(f)
169
+ if not facts:
170
+ continue
171
+ cov['findings_with_facts'] += 1
172
+ for key in FACTS:
173
+ values[key][facts.get(key) or 'unreadable'] += 1
174
+ sev = f.get('severity')
175
+ by_sev['P%d' % sev if isinstance(sev, int) else 'unlabelled'][facts.get('reach') or 'unreadable'] += 1
176
+ cov['values'] = {k: dict(sorted(c.items())) for k, c in values.items()}
177
+ cov['reach_by_severity'] = {s: dict(sorted(c.items())) for s, c in sorted(by_sev.items())}
178
+
179
+ agree = out['agreement']
180
+ severity, per_fact = [], {k: [] for k in FACTS}
181
+ for primary, shadow in shadow_pairs(runs).values():
182
+ if not mine(primary):
183
+ continue
184
+ agree['pairs'] += 1
185
+ for a, b in _matched(primary['d'].get('findings') or [], shadow['d'].get('findings') or []):
186
+ agree['matched'] += 1
187
+ if a.get('severity') is not None and b.get('severity') is not None:
188
+ severity.append((a['severity'], b['severity']))
189
+ for key in FACTS:
190
+ x, y = _facts(a).get(key), _facts(b).get(key)
191
+ if x and y:
192
+ per_fact[key].append((x, y))
193
+ agree['severity'] = _measure(severity)
194
+ for key in FACTS:
195
+ agree[key] = _measure(per_fact[key])
196
+
197
+ rules = out['rules']
198
+ for (run, task, role), rows in runs.dispatches.items():
199
+ if not_an_attempt(role) or role != 'qa' or not rows or not mine(rows[0]):
200
+ continue
201
+ ended = sorted(_ending_qa(rows).items(), key=lambda item: item[0] or 0)
202
+ attempts = [n for n, _ in ended]
203
+ for name in RULES:
204
+ release = _released(name)
205
+ for n, index in ended:
206
+ d = rows[index]['d']
207
+ found = [f for f in d.get('findings') or [] if isinstance(f, dict)]
208
+ rank = _threshold(runs, run, task, n)
209
+ if decide(d['verdict'], found, rank) == 'fail' and decide(d['verdict'], found, rank, release) == 'pass':
210
+ item = rules[name]
211
+ item['would_pass'] += 1
212
+ # The first review this rule would have passed ends the task: the attempts after it did not need to run.
213
+ item['attempts_saved'] += sum(1 for m in attempts if (m or 0) > (n or 0))
214
+ for f in found:
215
+ if release(f) and not (f['severity'] > rank) and len(item['released']) < EXAMPLES:
216
+ item['released'].append(dict(run=run, task=task, attempt=n, severity='P%d' % f['severity'],
217
+ facts=_facts(f), head=f.get('head')))
218
+ break
219
+ for n, index in ended:
220
+ found = rows[index]['d'].get('findings') or []
221
+ rules['reviews'] += 1
222
+ rules['reviews_with_facts'] += any(_facts(f) for f in found if isinstance(f, dict))
223
+ return out
224
+
225
+
226
+ def load(repo: str = None) -> dict:
227
+ # Reading must not create a store: a fresh machine gets an empty report.
228
+ if not (dataset_dir() / 'dataset.sqlite').exists():
229
+ return _empty()
230
+ db = connect()
231
+ try:
232
+ runs = Runs(Store(db))
233
+ finally:
234
+ db.close()
235
+ return report(runs, repo=repo)
236
+
237
+
238
+ def _pct(n, d):
239
+ return '%d%%' % round(100 * n / d) if d else '-'
240
+
241
+
242
+ def _line(name, m):
243
+ if not m['compared']:
244
+ return ' %-9s not compared yet' % name
245
+ kappa = '' if m['kappa'] is None else ', kappa %.2f' % m['kappa']
246
+ return ' %-9s %d of %d agree (%s%s)' % (name, m['agree'], m['compared'], _pct(m['agree'], m['compared']), kappa)
247
+
248
+
249
+ def main(args) -> int:
250
+ rep = load(os.path.realpath(args.repo) if args.repo else None)
251
+ if args.json:
252
+ print(json.dumps(rep, indent=2, sort_keys=True))
253
+ return 0
254
+ cov, agree, rules = rep['coverage'], rep['agreement'], rep['rules']
255
+ print('facts: %d of %d findings carry reach, origin and evidence (%s), in %d of %d reviews'
256
+ % (cov['findings_with_facts'], cov['findings'], _pct(cov['findings_with_facts'], cov['findings']),
257
+ cov['reviews_with_facts'], cov['reviews']))
258
+ print(' (recorded in shadow: nothing in forge decides on them; advisory only)')
259
+ for key in FACTS:
260
+ if cov['values'][key]:
261
+ print(' %-9s %s' % (key, ' '.join('%s %d' % kv for kv in cov['values'][key].items())))
262
+ for sev, counts in cov['reach_by_severity'].items():
263
+ print(' %-9s reach %s' % (sev, ' '.join('%s %d' % kv for kv in counts.items())))
264
+ print('agreement: %d shadow pairs, %d findings both reviewers named (same file, lines within %d)'
265
+ % (agree['pairs'], agree['matched'], rep['line_window']))
266
+ for key in ('severity',) + tuple(FACTS):
267
+ print(_line(key, agree[key]))
268
+ print('rules: replayed on the review each of %d task attempts ended on (%d with facts)'
269
+ % (rules['reviews'], rules['reviews_with_facts']))
270
+ for name, label in RULES.items():
271
+ item = rules[name]
272
+ print(' %-9s %s: %d reviews would have passed, %d later attempts not run'
273
+ % (name, label, item['would_pass'], item['attempts_saved']))
274
+ shown = rules['both']['released']
275
+ if shown:
276
+ print('findings that would have stopped blocking (were they real bugs that mattered?):')
277
+ for f in shown:
278
+ facts = '/'.join(f['facts'].get(k) or '?' for k in FACTS)
279
+ print(' %s %s#%s %s %s %s' % (f['run'], f['task'], f['attempt'], f['severity'], facts, f['head']))
280
+ return 0
@@ -25,13 +25,16 @@ from pathlib import Path
25
25
 
26
26
  from . import SCRIPTS, put_blob, put_file, sha256
27
27
 
28
- DISPATCH_ROLES = ('dwarf', 'qa', 'planner')
28
+ DISPATCH_ROLES = ('dwarf', 'qa', 'planner', 'side')
29
+ # The file role stays `side`. Harvest records side_<kind> (see dispatch_event);
30
+ # attempt statistics tell those apart with forge_dataset.is_side_role.
29
31
  PIPELINE_ROLES = ('task', 'solo', 'verification', 'parallel')
30
32
  TASKS_COLS = ('id', 'deps', 'difficulty', 'files', 'dwarf', 'qa', 'title')
31
33
  STRUCTURED = ('codex', 'claude', 'openclaude', 'grok', 'opencode') # as forge-runtime.py's: .last is the message, not the log
32
34
  # Plan files that change what a plan decides, added to its rid only when present (see plan_event).
33
35
  PLAN_RID_LATER = ('decompose_level', 'shadow_qa', 'shadow_rate', 'explore', 'reviewer_session',
34
- 'implementer_session', 'pre_review_tests')
36
+ 'implementer_session', 'pre_review_tests', 'retro_mode', 'brief', 'brief_scope', 'brief_model',
37
+ 'summaries', 'summaries_model')
35
38
 
36
39
  # Files a task or solo execution may write. begin() snapshots their signatures so
37
40
  # finish() can tell this execution's outputs from what an earlier one left behind.
@@ -183,11 +186,21 @@ def parse_review(message: str | None) -> tuple[list, bool]:
183
186
  if not message:
184
187
  return [], True
185
188
  try:
186
- parsed = contract().parse_findings(message)
189
+ module = contract()
190
+ parsed = module.parse_findings(message)
187
191
  except Exception:
188
192
  return [], False
189
- return [dict(status=f.status, severity=f.severity, located=f.located, line=f.line,
190
- head=f.text.splitlines()[0][:300] if f.text else '') for f in parsed], True
193
+ out = []
194
+ for f in parsed:
195
+ head = f.text.splitlines()[0] if f.text else ''
196
+ item = dict(status=f.status, severity=f.severity, located=f.located, line=f.line,
197
+ head=module.split_facts(head)[0][:300])
198
+ # #119: the facts suffix is kept apart, so a head reads as it did before it existed.
199
+ found = module.facts(f.text)
200
+ if found is not None:
201
+ item['facts'] = found
202
+ out.append(item)
203
+ return out, True
191
204
 
192
205
 
193
206
  def review_completeness(verdict: str | None, found: list, parsed: bool = True) -> str | None:
@@ -305,6 +318,13 @@ def locate(root: str | Path, role: str | None = None) -> dict:
305
318
  if p.parent.parent.name == 'shadow' and (p.parent.parent.parent / 'tasks.tsv').exists():
306
319
  # <plan>/shadow/<task>/<attempt>-<k>: a shadow review (forge-shadow.py) of that task.
307
320
  plan, ctx['task'], ctx['scope'], ctx['shadow'] = p.parent.parent.parent, p.parent.name, 'task', True
321
+ elif p.parent.parent.parent.name == 'side' and (p.parent.parent.parent.parent / 'tasks.tsv').exists():
322
+ # <plan>/side/<kind>/<task>/<n>: a side dispatch (brief or summary) of that task.
323
+ # The role is recorded as side_<kind> (see dispatch_event), the way a shadow
324
+ # review is recorded as qa_shadow. n counts dispatches; it is not the attempt.
325
+ kind = p.parent.parent.name
326
+ plan, ctx['task'], ctx['scope'], ctx['side'] = (
327
+ p.parent.parent.parent.parent, p.parent.name, 'task', kind)
308
328
  elif p.parent.name == 'tasks' and (p.parent.parent / 'tasks.tsv').exists():
309
329
  plan, ctx['task'], ctx['scope'] = p.parent.parent, p.name, 'task'
310
330
  elif p.name.startswith('final-review-') and (p.parent / 'tasks.tsv').exists():
@@ -413,6 +433,20 @@ def session_record(attempt: Path, role: str, metrics: dict) -> tuple[str | None,
413
433
  return recorded, 'continued' if kv(path).get('mode') == 'continued' else 'failed'
414
434
 
415
435
 
436
+ def side_kind(root: Path, role: str, prov: dict | None = None) -> str | None:
437
+ """The kind of a side dispatch (`brief`, `summary`), or None when this is not one.
438
+
439
+ The files stay `side.*`. The kind lives in the directory `<plan>/side/<kind>/...`
440
+ and, when a caller already knows it, in prov['side'].
441
+ """
442
+ if role != 'side':
443
+ return None
444
+ recorded = (prov or {}).get('side')
445
+ if isinstance(recorded, str) and recorded and '/' not in recorded and recorded not in ('.', '..'):
446
+ return recorded
447
+ return locate(root, role).get('side')
448
+
449
+
416
450
  def dispatch_event(attempt: Path, root: Path, role: str, harness: str, rc, prov: dict, src: str = 'live') -> dict:
417
451
  metrics = read_json(attempt / 'metrics.json') or {}
418
452
  resolved = kv(attempt / (role + '.resolved'))
@@ -427,10 +461,19 @@ def dispatch_event(attempt: Path, root: Path, role: str, harness: str, rc, prov:
427
461
  verdict = verdict_of(message) if message is not None else None
428
462
  found, parsed = parse_review(message) if role == 'qa' else ([], True)
429
463
  shadow = prov.get('shadow')
464
+ kind = side_kind(root, role, prov)
465
+ # A shadow review keeps the qa files and contract but is never a task's review, so it
466
+ # gets its own role: nothing that reads qa dispatches mistakes it for the one that decided.
467
+ # A side dispatch keeps the side files and is recorded as side_<kind>, so attempt
468
+ # statistics can leave it out (forge_dataset.is_side_role).
469
+ if kind:
470
+ recorded_role = 'side_' + kind
471
+ elif shadow and role == 'qa':
472
+ recorded_role = 'qa_shadow'
473
+ else:
474
+ recorded_role = role
430
475
  data = dict(
431
- # A shadow review keeps the qa files and contract but is never a task's review, so it
432
- # gets its own role: nothing that reads qa dispatches mistakes it for the one that decided.
433
- role='qa_shadow' if shadow and role == 'qa' else role, alias=resolved.get('alias'), harness=harness, model=resolved.get('model'),
476
+ role=recorded_role, alias=resolved.get('alias'), harness=harness, model=resolved.get('model'),
434
477
  effort=None if not effort or effort.startswith('<') else effort,
435
478
  # metrics.json is the record finish() wrote. A run from before that record falls
436
479
  # back to the resolved line, which exists only when a tier was asked.
@@ -711,7 +754,10 @@ def plan_event(plan: Path, prov: dict, src: str = 'live', inventory: bool = True
711
754
  source = 'planner'
712
755
  else:
713
756
  source = 'orchestrator'
757
+ risk = (text(tdir / 'risk') or '').split()
714
758
  per_task[tid] = dict(row, declared_difficulty=declared_tier, difficulty_source=source,
759
+ # #122: the task's risk, recorded in shadow beside its difficulty (None: not rated)
760
+ risk=risk[0] if risk and risk[0] in ('low', 'medium', 'high') else None,
715
761
  routing=routing, prompt=put_file(tdir / 'prompt.md', 'prompt'),
716
762
  approach=put_file(tdir / 'approach.md', 'prompt'))
717
763
  decisions = jsonl(tdir / 'route.jsonl')
@@ -761,7 +807,8 @@ def plan_event(plan: Path, prov: dict, src: str = 'live', inventory: bool = True
761
807
  jev_coupling=read_json(plan / 'jev-coupling.json'),
762
808
  options=dict({name: first_line(plan / name) for name in ('verify_retries', 'timeout', 'final_qa',
763
809
  'shadow_qa', 'shadow_rate', 'explore', 'reviewer_session',
764
- 'implementer_session')
810
+ 'implementer_session', 'retro_mode', 'brief', 'brief_scope',
811
+ 'brief_model', 'summaries', 'summaries_model')
765
812
  if (plan / name).exists()}, qa_threshold=threshold, qa_threshold_source=threshold_source),
766
813
  flags=sorted(name for name in ('no_memory', 'no_ripwire', 'yolo_dwarf', 'yolo_qa', 'pre_review_tests')
767
814
  if (plan / name).exists()),
@@ -5,7 +5,8 @@ exist. Each run is one record with its repository and base commit, so the screen
5
5
  belongs to (the same base-commit rule forge-ui's repos.py uses for a run whose checkout is gone):
6
6
 
7
7
  runs {run (dataset uid), run_id, mode, repo_path, base, first, last}
8
- findings one per review dispatch (qa, qa_shadow) that listed findings: {run, run_id, task, attempt, role,
8
+ findings one per review dispatch (qa, qa_shadow) that listed findings. A side dispatch
9
+ (`side_*`, or the bare role `side`) is not a review and is left out: {run, run_id, task, attempt, role,
9
10
  scope, reviewer, verdict, ts, findings: [{head, severity (0-3 or null), status, line}]}, as the
10
11
  capture parsed them with forge-contract.py (no second parser)
11
12
  learnings one per FORGE_LEARNING line a dispatch emitted: {run, run_id, task, role, model, ts, category, text}
@@ -18,7 +19,7 @@ from __future__ import annotations
18
19
 
19
20
  import json
20
21
 
21
- from . import connect, dataset_dir, enabled
22
+ from . import connect, dataset_dir, enabled, is_side_role
22
23
 
23
24
  _HEAD_MAX = 400
24
25
  _TEXT_MAX = 2000
@@ -75,7 +76,8 @@ def load() -> dict:
75
76
  if d.get('effort') and spec and ':' not in str(spec):
76
77
  spec = '%s:%s' % (spec, d['effort'])
77
78
  found = d.get('findings')
78
- if role in ('qa', 'qa_shadow') and isinstance(found, list) and found:
79
+ # qa and qa_shadow only. side_* is not a review, so its findings are not history.
80
+ if role in ('qa', 'qa_shadow') and not is_side_role(role) and isinstance(found, list) and found:
79
81
  items = []
80
82
  for f in found:
81
83
  if not isinstance(f, dict) or not isinstance(f.get('head'), str):