@giamme/forge 0.18.0 → 0.20.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 (93) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/README.md +1 -0
  3. package/SKILL.md +19 -2
  4. package/VERSION +1 -1
  5. package/docs/artifacts.md +25 -1
  6. package/docs/commands.md +217 -18
  7. package/docs/decomposed-runs.md +114 -1
  8. package/docs/development.md +2 -1
  9. package/docs/forge-ui.md +138 -18
  10. package/docs/memory.md +25 -4
  11. package/docs/models.md +8 -0
  12. package/docs/reviews.md +122 -0
  13. package/forge +26 -3
  14. package/package.json +2 -1
  15. package/references/dataset.md +20 -1
  16. package/references/decompose.md +641 -41
  17. package/references/harnesses.md +18 -3
  18. package/references/memory.md +30 -5
  19. package/references/planning.md +43 -14
  20. package/references/ui.md +53 -6
  21. package/registry.tsv +8 -3
  22. package/scripts/forge-brief.py +88 -3
  23. package/scripts/forge-compare.py +4 -3
  24. package/scripts/forge-contract.py +202 -27
  25. package/scripts/forge-control.py +117 -5
  26. package/scripts/forge-dispatch.sh +34 -5
  27. package/scripts/forge-findings.py +675 -0
  28. package/scripts/forge-group.py +496 -0
  29. package/scripts/forge-groups.py +89 -0
  30. package/scripts/forge-handoff.py +1128 -0
  31. package/scripts/forge-issues.py +228 -97
  32. package/scripts/forge-lib-group.sh +641 -0
  33. package/scripts/forge-lib-plans.sh +339 -3
  34. package/scripts/forge-lib-task.sh +197 -4
  35. package/scripts/forge-memory.sh +711 -17
  36. package/scripts/forge-parallel.sh +721 -38
  37. package/scripts/forge-planner.py +104 -8
  38. package/scripts/forge-route.py +190 -12
  39. package/scripts/forge-runs.py +9 -5
  40. package/scripts/forge-schedule.py +417 -52
  41. package/scripts/forge-solo.sh +2 -0
  42. package/scripts/forge-sweep.py +199 -44
  43. package/scripts/forge-worktrees.py +243 -0
  44. package/scripts/forge_brief/__init__.py +294 -50
  45. package/scripts/forge_brief/answers.py +58 -11
  46. package/scripts/forge_brief/proposals.py +1630 -0
  47. package/scripts/forge_dataset/efforts.py +4 -3
  48. package/scripts/forge_dataset/export.py +24 -12
  49. package/scripts/forge_dataset/facts.py +5 -3
  50. package/scripts/forge_dataset/forecast.py +8 -18
  51. package/scripts/forge_dataset/harvest.py +204 -9
  52. package/scripts/forge_dataset/history.py +11 -6
  53. package/scripts/forge_dataset/importer.py +65 -1
  54. package/scripts/forge_dataset/names.py +66 -0
  55. package/scripts/forge_dataset/reviewers.py +5 -2
  56. package/scripts/forge_dataset/risk.py +6 -3
  57. package/scripts/forge_dataset/routing.py +6 -1
  58. package/scripts/forge_findings/__init__.py +17 -0
  59. package/scripts/forge_findings/apply.py +441 -0
  60. package/scripts/forge_findings/status.py +43 -0
  61. package/scripts/forge_findings/store.py +583 -0
  62. package/scripts/forge_findings/tags.py +53 -0
  63. package/scripts/forge_findings/triage.py +603 -0
  64. package/scripts/forge_groups/__init__.py +308 -0
  65. package/scripts/forge_groups/attribute.py +289 -0
  66. package/scripts/forge_groups/review.py +286 -0
  67. package/scripts/forge_identity.py +327 -0
  68. package/scripts/forge_memory_list.py +7 -3
  69. package/scripts/forge_owner.py +152 -0
  70. package/scripts/forge_side/__init__.py +228 -38
  71. package/ui/docs/api.md +303 -29
  72. package/ui/forge_ui/control.py +1018 -6
  73. package/ui/forge_ui/executions.py +8 -1
  74. package/ui/forge_ui/export.py +31 -4
  75. package/ui/forge_ui/groups.py +264 -0
  76. package/ui/forge_ui/models.py +70 -8
  77. package/ui/forge_ui/projects.py +209 -22
  78. package/ui/forge_ui/reader.py +262 -19
  79. package/ui/forge_ui/server.py +4 -0
  80. package/ui/forge_ui/static/app.js +93 -13
  81. package/ui/forge_ui/static/briefview.js +350 -47
  82. package/ui/forge_ui/static/diffview.js +86 -1
  83. package/ui/forge_ui/static/findingsactions.js +201 -0
  84. package/ui/forge_ui/static/groupsview.js +332 -0
  85. package/ui/forge_ui/static/index.html +3 -0
  86. package/ui/forge_ui/static/panel.js +127 -7
  87. package/ui/forge_ui/static/projectsview.js +764 -30
  88. package/ui/forge_ui/static/runmodel.js +14 -3
  89. package/ui/forge_ui/static/storageview.js +91 -10
  90. package/ui/forge_ui/static/style.css +138 -5
  91. package/ui/forge_ui/static/triageview.js +423 -0
  92. package/ui/forge_ui/static/worktreesview.js +233 -12
  93. package/ui/forge_ui/storage.py +14 -0
@@ -14,9 +14,13 @@ import time
14
14
  from forge_ui import findings
15
15
 
16
16
 
17
- NAME = re.compile(r'(task|dwarf|qa|solo|verification|parallel)-[0-9a-f]{32}')
17
+ # A model dispatch's id is <role>-<32 hex>. A scripted task's command is script-<16 hex>
18
+ # (forge-parallel.sh). It is an execution, not a model role.
19
+ NAME = re.compile(r'(?:(?:task|dwarf|qa|solo|verification|parallel)-[0-9a-f]{32}|script-[0-9a-f]{16})')
18
20
  _KIND = re.compile(r'(final-review|integrate)-([0-9]+)-([0-9]+)')
19
21
  _SHADOW = re.compile(r'[0-9]+-[0-9]+')
22
+ # A group dir under groups/. The same shape as a group id (forge_groups, the group route).
23
+ _GROUP_DIR = re.compile(r'[a-z0-9][a-z0-9-]{0,39}')
20
24
  CONTAINERS = ('task', 'solo')
21
25
  _MODEL_ROLES = ('dwarf', 'qa')
22
26
  # attempts.tsv is appended right after the task execution's EXIT trap ran finish().
@@ -445,6 +449,9 @@ def locate(run_path, name, task_ids):
445
449
  for child in kinds:
446
450
  if child.startswith('integrate-'):
447
451
  yield child + '/final-review/attempts'
452
+ # A review=group group's QA dispatch writes its attempts here, as a task's land in the task dir.
453
+ for child in listed('groups', _GROUP_DIR):
454
+ yield f'groups/{child}/attempts'
448
455
 
449
456
  for rel in candidates():
450
457
  try:
@@ -26,8 +26,10 @@ from forge_ui import __version__, reader, server
26
26
 
27
27
  STATIC = server.STATIC_DIR
28
28
  # what the exported page runs; every other script index.html loads is in LEFT_OUT, with the reason
29
+ # groupsview.js is the group page. It is named here before that file exists; _page skips a
30
+ # SCRIPTS entry whose file is absent, so the export still builds.
29
31
  SCRIPTS = ('theme.js', 'icons.js', 'datatable.js', 'shell.js', 'runmodel.js', 'cloudmodel.js', 'graph.js', 'gantt.js', 'verifyview.js', 'checksview.js',
30
- 'briefview.js', 'panel.js', 'diffview.js', 'convo.js', 'files.js', 'map3d.js', 'search.js', 'app.js')
32
+ 'briefview.js', 'groupsview.js', 'findingsactions.js', 'triageview.js', 'panel.js', 'diffview.js', 'convo.js', 'files.js', 'map3d.js', 'search.js', 'app.js')
31
33
  LEFT_OUT = {
32
34
  'uikit.js': 'write helpers and the guards that keep a poll from redrawing what a person holds; a snapshot neither writes nor polls',
33
35
  'controls.js': 'changes a live run',
@@ -48,6 +50,9 @@ TRANSCRIPT_CAP = 2 << 20 # one execution's tr
48
50
  TOTAL_CAP = 25 << 20 # every response together
49
51
  CDN = 'https://cdn.jsdelivr.net/npm/three@0.160.0/'
50
52
  _EXEC = re.compile(r'(?:task|dwarf|qa|solo|verification|parallel)-[0-9a-f]{32}')
53
+ # GET /api/runs/<key>/groups/<gid> is the group dict itself, so its goal and decision are not nested
54
+ # under a `groups` key. clean() is told the parent is `groups` for that path.
55
+ _GROUP_DETAIL = re.compile(r'/groups/[a-z0-9][a-z0-9-]{0,39}$')
51
56
  # texts that can hold code, prompts or private notes: nulled unless texts=True
52
57
  _TEXT_KEYS = frozenset(('prompt', 'last', 'request', 'log_tail', 'dwarf_tail', 'qa_tail', 'qa_last', 'qa_input',
53
58
  'tasks_summary', 'known_issues', 'texts', 'text', 'planning_last', 'approach', 'retry_findings',
@@ -56,12 +61,19 @@ _TEXT_KEYS = frozenset(('prompt', 'last', 'request', 'log_tail', 'dwarf_tail', '
56
61
  # keys that are private text only under one parent: a person's --reason on each decision (`reason` elsewhere is
57
62
  # a short machine word, such as a sweep's dropped-finding reason, and stays); the --reason of each adoption too.
58
63
  # A task header's goal and criteria are paragraphs of the prompt; the run's own `goal` (its title) stays.
64
+ # A group's goal (the planner's line in groups.tsv) and the first line of its decision.md are private too,
65
+ # on the run's `groups` list and on GET …/groups/<gid>. A group's title stays. A task's `decision` is an
66
+ # object under `tasks` (its `text` is already in _TEXT_KEYS); it is not this string.
59
67
  # A brief question's why, the choices in options, its default and the answer a person typed are private
60
68
  # only under `questions` and `parked` (`text` is already in _TEXT_KEYS). `scope`, `state` and `id` stay.
69
+ # A proposal's summary, diff and refusal reason are the model's prose and the patch. pid, state, scope,
70
+ # group, hash and the truncation flag stay. `reason` under `affected` is a short machine word and stays.
61
71
  _TEXT_KEYS_UNDER = {'decisions': frozenset(('reason',)), 'adoptions': frozenset(('reason',)),
62
72
  'adoption': frozenset(('reason',)), 'header': frozenset(('goal', 'criteria')),
73
+ 'groups': frozenset(('goal', 'decision')),
63
74
  'questions': frozenset(('why', 'options', 'default', 'answer')),
64
- 'parked': frozenset(('why', 'options', 'default', 'answer'))}
75
+ 'parked': frozenset(('why', 'options', 'default', 'answer')),
76
+ 'proposals': frozenset(('summary', 'diff', 'reason'))}
65
77
 
66
78
 
67
79
  def _enc(value):
@@ -121,7 +133,9 @@ class _Snapshot:
121
133
  value = server.api_get(self.catalog, path)
122
134
  if value is server.NO_ROUTE or value is None:
123
135
  return None
124
- value = self.clean(value)
136
+ # The group route returns the group at the root, so goal and decision blank the way they do
137
+ # under the run's `groups` list.
138
+ value = self.clean(value, 'groups' if _GROUP_DETAIL.search(path) else None)
125
139
  size = len(json.dumps(value, ensure_ascii=False).encode('utf-8'))
126
140
  if not required and ((cap and size > cap) or self.size + size > TOTAL_CAP):
127
141
  self.omitted.append({'path': path, 'bytes': size, 'why': 'larger than 1 MB' if cap and size > cap else 'over the 25 MB total'})
@@ -186,7 +200,20 @@ def build(catalog, key, texts=False, paths=False, now=None):
186
200
  tasks = [t for t in (detail.get('tasks') or []) if isinstance(t, dict) and t.get('id')]
187
201
  for task in tasks:
188
202
  snap.add(f"{base}/tasks/{_enc(task['id'])}")
189
- names = sorted(set(_EXEC.findall(json.dumps(run))))
203
+ # A group's review dispatch is not named on the run, only on its own detail. Snapshot that detail,
204
+ # and fold the dispatch into the execution list so its transcript is stored with the others.
205
+ extra_execs = []
206
+ for item in run.get('groups') or []:
207
+ if not isinstance(item, dict):
208
+ continue
209
+ gid = item.get('id')
210
+ if not isinstance(gid, str) or not re.fullmatch(r'[a-z0-9][a-z0-9-]{0,39}', gid):
211
+ continue
212
+ body = snap.add(f'{base}/groups/{_enc(gid)}')
213
+ execution = body.get('execution') if isinstance(body, dict) else None
214
+ if isinstance(execution, dict) and isinstance(execution.get('id'), str):
215
+ extra_execs.append(execution['id'])
216
+ names = sorted(set(_EXEC.findall(json.dumps(run))) | {name for name in extra_execs if _EXEC.fullmatch(name)})
190
217
  for name in names:
191
218
  snap.add(f'{base}/executions/{name}')
192
219
  reviews = [r.get('name') for r in (run.get('final_reviews') or []) if isinstance(r, dict) and r.get('name')]
@@ -0,0 +1,264 @@
1
+ """Groups of a plan: `<plan>/groups.tsv` and, for a group that is reviewed as one, `<plan>/groups/<gid>/`.
2
+
3
+ Read through the run reader (`text`, `rows`, `object`, `exists`). A missing file is an empty result.
4
+ A malformed one is a warning on `reader.warnings` and whatever rows could still be read: nothing here raises.
5
+
6
+ `groups.tsv` is `id review qa members title goal`, tab-separated, `#` comments and blank lines ignored.
7
+ `-` in a cell is `None`. `members` is a list of task ids. A `review=task` group is that identity only.
8
+ A `review=group` group also has the review state in its directory: `status`, `round`, `merged`,
9
+ `rounds.tsv` (`round epoch status implicated reviewer`), and the first line of `decision.md`.
10
+ `group()` adds the review itself: `attribution.json`, `members.tsv`, `qa.last`, `known_issues.md`,
11
+ `candidate.base` and `candidate.commit`, and the QA dispatch `executions.scan` reads from
12
+ `groups/<gid>/attempts/` — the same builder a task's QA dispatch uses.
13
+ """
14
+ from __future__ import annotations
15
+
16
+ import math
17
+ import re
18
+
19
+ from forge_ui import executions
20
+
21
+
22
+ # The same shape forge_groups accepts, and the shape the group route matches.
23
+ GID = re.compile(r'[a-z0-9][a-z0-9-]{0,39}')
24
+ # Head and tail kept of a review text, as TaskDetail's texts and a final review's qa.last do
25
+ # (reader.excerpt: two bounded reads, the cut marked in reader.truncated).
26
+ _TEXT_HEAD = 20000
27
+ _TEXT_TAIL = 8000
28
+ _REVIEWS = ('task', 'group')
29
+
30
+
31
+ def _blank(value):
32
+ """A stripped cell, or None for an empty one and for `-`."""
33
+ if value is None:
34
+ return None
35
+ text = str(value).strip()
36
+ return None if text in ('', '-') else text
37
+
38
+
39
+ def _id_list(value):
40
+ """A comma list of ids, or None for an empty cell and for `-`."""
41
+ text = _blank(value)
42
+ if text is None:
43
+ return None
44
+ items = [part.strip() for part in text.split(',') if part.strip()]
45
+ return items or None
46
+
47
+
48
+ def _int(reader, label, value, what):
49
+ text = (value or '').strip()
50
+ if text in ('', '-'):
51
+ return None
52
+ try:
53
+ return int(text)
54
+ except (ValueError, OverflowError):
55
+ reader.warn(label, f'{what} is not an integer')
56
+ return None
57
+
58
+
59
+ def _rounds(reader, name):
60
+ """rounds.tsv rows that parse. A bad row is warned and skipped."""
61
+ result = []
62
+ for label, row in reader.rows(name, 5):
63
+ if len(row) != 5:
64
+ reader.warn(label, 'expected 5 columns')
65
+ try:
66
+ number, epoch = int(row[0].strip()), float(row[1].strip())
67
+ if not math.isfinite(epoch):
68
+ raise ValueError()
69
+ except (ValueError, OverflowError):
70
+ reader.warn(label, 'invalid round or epoch')
71
+ continue
72
+ result.append(dict(round=number, epoch=epoch, status=_blank(row[2]),
73
+ implicated=_id_list(row[3]), reviewer=_blank(row[4])))
74
+ return result
75
+
76
+
77
+ def _state(reader, gid):
78
+ """The review state a review=group group carries. Missing files are null, not an error."""
79
+ prefix = f'groups/{gid}'
80
+ rounds = _rounds(reader, prefix + '/rounds.tsv')
81
+ last = rounds[-1] if rounds else None
82
+ return dict(status=reader.word(prefix + '/status'), round=reader.number(prefix + '/round', int),
83
+ merged=reader.exists(prefix + '/merged'),
84
+ implicated=None if last is None else last['implicated'],
85
+ decision=reader.line(prefix + '/decision.md'), rounds=rounds)
86
+
87
+
88
+ def groups(reader) -> list:
89
+ """One dict per groups.tsv row, in file order. `[]` when the plan has no groups.tsv."""
90
+ if not reader.exists('groups.tsv'):
91
+ return []
92
+ found, seen = [], set()
93
+ for label, row in reader.rows('groups.tsv', 6):
94
+ if len(row) != 6:
95
+ reader.warn(label, 'expected 6 columns')
96
+ gid = row[0].strip()
97
+ if not GID.fullmatch(gid):
98
+ reader.warn(label, 'invalid group id')
99
+ continue
100
+ if gid in seen:
101
+ reader.warn(label, 'duplicate group id')
102
+ continue
103
+ seen.add(gid)
104
+ # `-` is None in every cell, review included. Anything but task or group is still returned,
105
+ # without review state, and warned.
106
+ review = _blank(row[1])
107
+ if review not in _REVIEWS:
108
+ reader.warn(label, 'review must be task or group')
109
+ item = dict(id=gid, review=review, qa=_blank(row[2]), members=_id_list(row[3]),
110
+ title=_blank(row[4]), goal=_blank('\t'.join(row[5:])))
111
+ if review == 'group':
112
+ item.update(_state(reader, gid))
113
+ found.append(item)
114
+ return found
115
+
116
+
117
+ def _members_by_round(reader, name):
118
+ """members.tsv grouped by round, in file order: [{round, members: [{task, commit, attempt}]}]."""
119
+ rows = []
120
+ for label, row in reader.rows(name, 4):
121
+ raw = (row[0] or '').strip()
122
+ number = _int(reader, label, row[0], 'round')
123
+ if number is None:
124
+ # `_int` already warned a cell that is not an integer. A blank one has not.
125
+ if raw in ('', '-'):
126
+ reader.warn(label, 'invalid round')
127
+ continue
128
+ task = row[1].strip()
129
+ if not task or task == '-':
130
+ reader.warn(label, 'missing task')
131
+ continue
132
+ rows.append(dict(round=number, task=task, commit=_blank(row[2]),
133
+ attempt=_int(reader, label, row[3], 'attempt')))
134
+ grouped, index = [], {}
135
+ for row in rows:
136
+ bucket = index.get(row['round'])
137
+ if bucket is None:
138
+ bucket = index[row['round']] = dict(round=row['round'], members=[])
139
+ grouped.append(bucket)
140
+ bucket['members'].append(dict(task=row['task'], commit=row['commit'], attempt=row['attempt']))
141
+ return grouped
142
+
143
+
144
+ def _flag(reader, name, index, item, key):
145
+ value = item.get(key)
146
+ if type(value) is bool:
147
+ return value
148
+ if value is not None:
149
+ reader.warn(name, f'finding {index} {key} is not a boolean')
150
+ return False
151
+
152
+
153
+ def _finding(reader, name, index, item):
154
+ number = item.get('n')
155
+ if type(number) is not int:
156
+ reader.warn(name, f'finding {index} has no n')
157
+ number = index
158
+ line = item.get('line')
159
+ if type(line) is not int:
160
+ if line is not None:
161
+ reader.warn(name, f'finding {index} line is not an integer')
162
+ line = None
163
+ tasks = item.get('tasks')
164
+ if not (isinstance(tasks, list) and all(isinstance(part, str) for part in tasks)):
165
+ reader.warn(name, f'finding {index} tasks is not a list of ids')
166
+ tasks = []
167
+
168
+ def text(key):
169
+ value = item.get(key)
170
+ return value if isinstance(value, str) and value else None
171
+
172
+ return dict(n=number, severity=text('severity'), status=text('status'), file=text('file'), line=line,
173
+ tasks=tasks, blocking=_flag(reader, name, index, item, 'blocking'),
174
+ ambiguous=_flag(reader, name, index, item, 'ambiguous'))
175
+
176
+
177
+ def _strings(reader, name, obj, key):
178
+ value = obj.get(key)
179
+ if value is None:
180
+ return []
181
+ if isinstance(value, list) and all(isinstance(part, str) for part in value):
182
+ return value
183
+ reader.warn(name, f'{key} is not a list of ids')
184
+ return []
185
+
186
+
187
+ def _numbers(reader, name, obj, key):
188
+ value = obj.get(key)
189
+ if value is None:
190
+ return []
191
+ if isinstance(value, list) and all(type(part) is int for part in value):
192
+ return value
193
+ reader.warn(name, f'{key} is not a list of numbers')
194
+ return []
195
+
196
+
197
+ def _attribution(reader, name):
198
+ """attribution.json, or None when it is missing or not an attribution (warned)."""
199
+ obj = reader.object(name)
200
+ if obj is None:
201
+ return None
202
+ findings = obj.get('findings')
203
+ if not isinstance(findings, list):
204
+ reader.warn(name, 'not an attribution')
205
+ return None
206
+ parsed = []
207
+ for index, item in enumerate(findings, 1):
208
+ if not isinstance(item, dict):
209
+ reader.warn(name, f'finding {index} is not an object')
210
+ continue
211
+ parsed.append(_finding(reader, name, index, item))
212
+ number = obj.get('round')
213
+ if type(number) is not int:
214
+ if number is not None:
215
+ reader.warn(name, 'round is not an integer')
216
+ number = None
217
+ result = dict(round=number, findings=parsed, implicated=_strings(reader, name, obj, 'implicated'),
218
+ ambiguous=_numbers(reader, name, obj, 'ambiguous'))
219
+ blocking = obj.get('blocking')
220
+ if type(blocking) is bool:
221
+ result['blocking'] = blocking
222
+ elif blocking is not None:
223
+ reader.warn(name, 'blocking is not a boolean')
224
+ return result
225
+
226
+
227
+ def _review_execution(reader, gid):
228
+ """The group's QA dispatch, built the same way as a task's: the newest qa execution in its attempts/."""
229
+ prefix = f'groups/{gid}'
230
+ # REVIEWING is the only status on which the dispatch is still in flight. Any other, including a
231
+ # missing status file, leaves an execution with no exit code orphaned rather than running.
232
+ execs = executions.scan(reader, prefix + '/attempts', reader.word(prefix + '/status') == 'REVIEWING', ('qa',))
233
+ return execs[-1] if execs else None
234
+
235
+
236
+ def group(reader, gid) -> dict | None:
237
+ """One group, with its review, or None when `gid` is not a group of this plan.
238
+
239
+ A gid that cannot name a group dir (`GID`) is None without a read. The dict is the `groups()`
240
+ row plus `attribution`, `members_by_round`, `qa_last`, `known_issues`, `candidate` and
241
+ `execution`. `qa_last` and `known_issues` go through `reader.excerpt`, the bounded reader the
242
+ task and review inspectors use. `warnings` are this group's files under `groups/<gid>/`:
243
+ a bad `groups.tsv` row, and another group's files, belong to the list read, not this one.
244
+ `truncated` names the texts this read cut.
245
+ """
246
+ if not isinstance(gid, str) or not GID.fullmatch(gid):
247
+ return None
248
+ noted = len(reader.warnings)
249
+ cut = len(reader.truncated)
250
+ found = next((dict(item) for item in groups(reader) if item['id'] == gid), None)
251
+ if found is None:
252
+ return None
253
+ prefix = f'groups/{gid}/'
254
+ found['attribution'] = _attribution(reader, prefix + 'attribution.json')
255
+ found['members_by_round'] = _members_by_round(reader, prefix + 'members.tsv')
256
+ found['qa_last'] = reader.excerpt(prefix + 'qa.last', _TEXT_HEAD, _TEXT_TAIL, 'qa_last')
257
+ found['known_issues'] = reader.excerpt(prefix + 'known_issues.md', _TEXT_HEAD, _TEXT_TAIL, 'known_issues')
258
+ found['candidate'] = dict(base=_blank(reader.line(prefix + 'candidate.base')),
259
+ commit=_blank(reader.line(prefix + 'candidate.commit')))
260
+ found['execution'] = _review_execution(reader, gid)
261
+ # groups() walked every row. Keep warnings for this group's files only: not groups.tsv, not another group.
262
+ found['warnings'] = [item for item in reader.warnings[noted:] if item.startswith(prefix)]
263
+ found['truncated'] = reader.truncated[cut:]
264
+ return found
@@ -69,6 +69,44 @@ def _is_side_role():
69
69
  return fn
70
70
 
71
71
 
72
+ _NAMES = _DATASET.parent / 'names.py'
73
+ _NAME_FN = {}
74
+
75
+
76
+ def _dispatch_name():
77
+ """forge_dataset.names.dispatch_name, loaded read-only. None when it cannot be."""
78
+ with _SIDE_LOCK:
79
+ if 'fn' in _NAME_FN:
80
+ return _NAME_FN['fn']
81
+ fn = None
82
+ try:
83
+ spec = importlib.util.spec_from_file_location(
84
+ 'forge_dataset_names_for_ui', _NAMES,
85
+ loader=findings._ReadOnlyLoader('forge_dataset_names_for_ui', str(_NAMES)))
86
+ module = importlib.util.module_from_spec(spec)
87
+ spec.loader.exec_module(module)
88
+ candidate = getattr(module, 'dispatch_name', None)
89
+ fn = candidate if callable(candidate) else None
90
+ except Exception:
91
+ fn = None
92
+ _NAME_FN['fn'] = fn
93
+ return fn
94
+
95
+
96
+ def _named(model):
97
+ """The alias a model row is counted under: an alias that has since moved to a newer model
98
+ names its old dispatches by the alias that resolves to their model today (`terra-5.6`)."""
99
+ if not model:
100
+ return None
101
+ fn = _dispatch_name()
102
+ if fn is None:
103
+ return model.get('alias')
104
+ try:
105
+ return fn(dict(alias=model.get('alias'), model=model.get('model'), harness=model.get('harness'))) or model.get('alias')
106
+ except Exception:
107
+ return model.get('alias')
108
+
109
+
72
110
  def side_role(role) -> bool:
73
111
  """A side dispatch: harvested `side_*`, or the on-disk role `side` (`is_side_role` rejects the bare name).
74
112
 
@@ -82,10 +120,30 @@ def side_role(role) -> bool:
82
120
  return isinstance(role, str) and role.startswith('side_')
83
121
 
84
122
 
123
+ def _group_scope(item) -> bool:
124
+ """A group review: one QA dispatch for several tasks, not one task's review of record.
125
+
126
+ The execution may say so (`scope`, or dataset.json's `scope`). A path under
127
+ `groups/<gid>/` says so too, which is how a scan of that dir is recognized before
128
+ the execution dict carries the field. A task whose id is `groups` lives under `tasks/`.
129
+ """
130
+ if item.get('scope') == 'group':
131
+ return True
132
+ dataset = getattr(item, 'dataset', None)
133
+ if isinstance(dataset, dict) and dataset.get('scope') == 'group':
134
+ return True
135
+ rel = getattr(item, 'rel', None)
136
+ if not isinstance(rel, str) or not rel:
137
+ return False
138
+ head, _, _ = rel.partition('/')
139
+ return head == 'groups'
140
+
141
+
85
142
  def _primary_qa(item) -> bool:
86
- """The review of record for an attempt. A shadow review and a side dispatch are not one."""
143
+ """The review of record for an attempt. A shadow review, a side dispatch and a group review are not one."""
87
144
  role = item['role']
88
- return role == 'qa' and not item['shadow'] and role != 'qa_shadow' and not side_role(role)
145
+ return (role == 'qa' and not item['shadow'] and role != 'qa_shadow' and not side_role(role)
146
+ and not _group_scope(item))
89
147
 
90
148
 
91
149
  def _builtin_profiles_path():
@@ -193,7 +251,7 @@ def _attempts(rows, execs, plan_spec):
193
251
  else:
194
252
  spec = source = None
195
253
  verdict = reviews[-1]['verdict'] if reviews else None
196
- result.append(dict(n=n, alias=model['alias'] if model else _alias(spec), spec=spec, source=source,
254
+ result.append(dict(n=n, alias=_named(model) if model else _alias(spec), spec=spec, source=source,
197
255
  outcome=outcome, reason=reason, gate=outcome == 'pass' and verdict == 'FAIL',
198
256
  gate_fail=outcome == 'fail' and verdict == 'PASS',
199
257
  model_s=last['phases'].get('model') if last is not None else None,
@@ -221,7 +279,7 @@ def _reviews(key, ident, execs, shadows):
221
279
  for item in execs:
222
280
  if _primary_qa(item) and item['state'] == 'done':
223
281
  model = item['model'] or {}
224
- rows.append(dict(run=key, task=ident, n=item['attempt'], kind='primary', alias=model.get('alias'),
282
+ rows.append(dict(run=key, task=ident, n=item['attempt'], kind='primary', alias=_named(model),
225
283
  spec=model.get('spec'), verdict=item['verdict'], findings=item['findings'],
226
284
  duration_s=item['duration_s'], tokens=item['tokens'], agreement=None, primary_alias=None))
227
285
  for entry, items, _ in shadows:
@@ -231,11 +289,11 @@ def _reviews(key, ident, execs, shadows):
231
289
  spec = entry['spec'] if isinstance(entry['spec'], str) else model.get('spec')
232
290
  primaries = [item for item in execs if _primary_qa(item)
233
291
  and item['attempt'] == entry['attempt'] and item['model']]
234
- rows.append(dict(run=key, task=ident, n=entry['attempt'], kind='shadow', alias=model.get('alias') or _alias(spec),
292
+ rows.append(dict(run=key, task=ident, n=entry['attempt'], kind='shadow', alias=_named(model) or _alias(spec),
235
293
  spec=spec, verdict=entry['verdict'], findings=entry['findings'],
236
294
  duration_s=entry['duration_s'], tokens=items[-1]['tokens'] if items else None,
237
295
  agreement=entry['agreement'],
238
- primary_alias=primaries[-1]['model']['alias'] if primaries else _alias(entry['primary'])))
296
+ primary_alias=_named(primaries[-1]['model']) if primaries else _alias(entry['primary'])))
239
297
  return rows
240
298
 
241
299
 
@@ -258,10 +316,14 @@ def _facts(path, summary, root):
258
316
  execs = reader._task_execs(rd, task)
259
317
  shadows = reader._shadows(rd, task['id'], execs)
260
318
  explored, propensity = _route(rd, base)
319
+ # A scripted task (#142) ran a command, not a model: its attempts are no implementer's result.
320
+ # Its reviews still count for the reviewer.
321
+ scripted = task['dwarf'] == 'script'
261
322
  tasks.append(dict(base_row, task=task['id'], kind='plan', difficulty=task['difficulty'] or None,
262
323
  explored=explored, propensity=propensity, final_status=task['status'],
263
324
  accepted=reader._nonempty(rd, base + '/accepted.by'),
264
- attempts=_attempts(_attempt_rows(rd, base + '/attempts.tsv'), execs, task['dwarf']),
325
+ attempts=[] if scripted else _attempts(_attempt_rows(rd, base + '/attempts.tsv'), execs,
326
+ task['dwarf']),
265
327
  escalations=[{'n': item['attempt'], 'from': item['from'], 'to': item['to']}
266
328
  for item in reader._history(rd, base + '/escalations.tsv', True)]))
267
329
  reviews += _reviews(key, task['id'], execs, shadows)
@@ -274,7 +336,7 @@ def _facts(path, summary, root):
274
336
  run = execs[-1] if execs else None
275
337
  model = (run['model'] if run else None) or {}
276
338
  spec = review['spec'] or model.get('spec')
277
- reviews.append(dict(run=key, task=None, n=None, kind='final', alias=model.get('alias') or _alias(spec),
339
+ reviews.append(dict(run=key, task=None, n=None, kind='final', alias=_named(model) or _alias(spec),
278
340
  spec=spec, verdict=review['verdict'] if review['verdict'] in ('PASS', 'FAIL') else None,
279
341
  findings=review['findings'], duration_s=review['duration_s'],
280
342
  tokens=run['tokens'] if run else None, agreement=None, primary_alias=None))