@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.
- package/CHANGELOG.md +57 -0
- package/README.md +1 -0
- package/SKILL.md +32 -5
- package/VERSION +1 -1
- package/docs/artifacts.md +33 -1
- package/docs/commands.md +147 -16
- package/docs/dataset.md +5 -0
- package/docs/decomposed-runs.md +122 -1
- package/docs/development.md +2 -1
- package/docs/forge-ui.md +98 -8
- package/docs/memory.md +27 -4
- package/docs/models.md +8 -0
- package/docs/reviews.md +122 -0
- package/docs/safety.md +8 -0
- package/forge +44 -4
- package/package.json +2 -1
- package/references/dataset.md +39 -1
- package/references/decompose.md +737 -16
- package/references/harnesses.md +18 -3
- package/references/planning.md +43 -14
- package/references/solo.md +2 -1
- package/references/ui.md +56 -6
- package/registry.tsv +8 -3
- package/scripts/forge-artifact.sh +14 -0
- package/scripts/forge-brief.py +217 -0
- package/scripts/forge-compare.py +13 -2
- package/scripts/forge-config.py +176 -9
- package/scripts/forge-contract.py +246 -28
- package/scripts/forge-control.py +200 -15
- package/scripts/forge-dispatch.sh +48 -15
- package/scripts/forge-du.py +167 -0
- package/scripts/forge-group.py +496 -0
- package/scripts/forge-groups.py +89 -0
- package/scripts/forge-handoff.py +1128 -0
- package/scripts/forge-lib-adopt.sh +1 -0
- package/scripts/forge-lib-group.sh +641 -0
- package/scripts/forge-lib-plans.sh +343 -4
- package/scripts/forge-lib-review.sh +29 -1
- package/scripts/forge-lib-task.sh +197 -4
- package/scripts/forge-memory.sh +245 -3
- package/scripts/forge-metrics.sh +7 -3
- package/scripts/forge-parallel-options.sh +4 -0
- package/scripts/forge-parallel.sh +1216 -41
- package/scripts/forge-planner.py +104 -8
- package/scripts/forge-prompt.py +120 -0
- package/scripts/forge-retro.py +115 -0
- package/scripts/forge-route.py +190 -12
- package/scripts/forge-runs-compact.py +443 -0
- package/scripts/forge-runs-rm.py +2 -0
- package/scripts/forge-runs.py +27 -8
- package/scripts/forge-schedule.py +633 -49
- package/scripts/forge-shadow.py +7 -1
- package/scripts/forge-solo.sh +4 -0
- package/scripts/forge-summarize.py +698 -0
- package/scripts/forge-ui-options.sh +10 -0
- package/scripts/forge-worktrees.py +243 -0
- package/scripts/forge_brief/__init__.py +831 -0
- package/scripts/forge_brief/answers.py +506 -0
- package/scripts/forge_brief/proposals.py +1630 -0
- package/scripts/forge_dataset/__init__.py +10 -0
- package/scripts/forge_dataset/efforts.py +4 -3
- package/scripts/forge_dataset/export.py +36 -10
- package/scripts/forge_dataset/facts.py +8 -4
- package/scripts/forge_dataset/forecast.py +8 -18
- package/scripts/forge_dataset/harvest.py +241 -12
- package/scripts/forge_dataset/history.py +13 -6
- package/scripts/forge_dataset/importer.py +65 -1
- package/scripts/forge_dataset/names.py +66 -0
- package/scripts/forge_dataset/reviewers.py +5 -2
- package/scripts/forge_dataset/risk.py +6 -3
- package/scripts/forge_dataset/routing.py +6 -1
- package/scripts/forge_decide/__init__.py +11 -1
- package/scripts/forge_groups/__init__.py +308 -0
- package/scripts/forge_groups/attribute.py +289 -0
- package/scripts/forge_groups/review.py +286 -0
- package/scripts/forge_locations.py +366 -0
- package/scripts/forge_owner.py +152 -0
- package/scripts/forge_registry.py +19 -0
- package/scripts/forge_retro/__init__.py +417 -0
- package/scripts/forge_retro/issues.py +1193 -0
- package/scripts/forge_retro/report.py +671 -0
- package/scripts/forge_side/__init__.py +482 -0
- package/scripts/forge_storage.py +515 -0
- package/ui/README.md +68 -8
- package/ui/docs/api.md +375 -31
- package/ui/forge_ui/control.py +451 -11
- package/ui/forge_ui/executions.py +8 -1
- package/ui/forge_ui/export.py +53 -7
- package/ui/forge_ui/groups.py +264 -0
- package/ui/forge_ui/links.py +337 -0
- package/ui/forge_ui/models.py +125 -10
- package/ui/forge_ui/projects.py +4 -1
- package/ui/forge_ui/reader.py +919 -45
- package/ui/forge_ui/server.py +4 -0
- package/ui/forge_ui/static/app.js +173 -11
- package/ui/forge_ui/static/briefview.js +605 -0
- package/ui/forge_ui/static/checksview.js +6 -2
- package/ui/forge_ui/static/controls.js +5 -0
- package/ui/forge_ui/static/diffview.js +86 -1
- package/ui/forge_ui/static/groupsview.js +332 -0
- package/ui/forge_ui/static/index.html +4 -0
- package/ui/forge_ui/static/panel.js +394 -8
- package/ui/forge_ui/static/projectsview.js +189 -10
- package/ui/forge_ui/static/runmodel.js +27 -4
- package/ui/forge_ui/static/storageview.js +352 -0
- package/ui/forge_ui/static/style.css +176 -6
- package/ui/forge_ui/static/worktreesview.js +235 -14
- package/ui/forge_ui/storage.py +150 -0
- package/ui/forge_ui/transcripts.py +35 -10
- package/ui/forge_ui/worktrees.py +154 -13
package/ui/forge_ui/export.py
CHANGED
|
@@ -25,24 +25,55 @@ import urllib.parse
|
|
|
25
25
|
from forge_ui import __version__, reader, server
|
|
26
26
|
|
|
27
27
|
STATIC = server.STATIC_DIR
|
|
28
|
-
# what the exported page runs
|
|
29
|
-
|
|
30
|
-
|
|
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.
|
|
31
|
+
SCRIPTS = ('theme.js', 'icons.js', 'datatable.js', 'shell.js', 'runmodel.js', 'cloudmodel.js', 'graph.js', 'gantt.js', 'verifyview.js', 'checksview.js',
|
|
32
|
+
'briefview.js', 'groupsview.js', 'panel.js', 'diffview.js', 'convo.js', 'files.js', 'map3d.js', 'search.js', 'app.js')
|
|
33
|
+
LEFT_OUT = {
|
|
34
|
+
'uikit.js': 'write helpers and the guards that keep a poll from redrawing what a person holds; a snapshot neither writes nor polls',
|
|
35
|
+
'controls.js': 'changes a live run',
|
|
36
|
+
'rundelete.js': 'deletes a run',
|
|
37
|
+
'settings.js': 'the settings screen reads and writes the server',
|
|
38
|
+
'notify.js': 'notifications come from polling the run list',
|
|
39
|
+
'modelstats.js': 'the model leaderboard needs /api/models, which a snapshot does not carry',
|
|
40
|
+
'leaderboard.js': 'the model leaderboard needs /api/models, which a snapshot does not carry',
|
|
41
|
+
'cloudui.js': 'the run cloud needs every run, and a snapshot carries one',
|
|
42
|
+
'findingsview.js': 'the open-findings page dismisses findings or files them as issues',
|
|
43
|
+
'worktreesview.js': 'the Worktrees screen needs /api/worktrees',
|
|
44
|
+
'storageview.js': 'the Disk screen needs /api/storage',
|
|
45
|
+
'projectsview.js': 'the Projects screen needs every run of the repository',
|
|
46
|
+
}
|
|
31
47
|
MODULES = ('iso.js', 'cloud3d.js', 'findings3d.js', 'stagectl.js', 'scene3d.js') # bundled in dependency order
|
|
32
48
|
DIFF_CAP = 1 << 20 # one diff's JSON
|
|
33
49
|
TRANSCRIPT_CAP = 2 << 20 # one execution's transcript
|
|
34
50
|
TOTAL_CAP = 25 << 20 # every response together
|
|
35
51
|
CDN = 'https://cdn.jsdelivr.net/npm/three@0.160.0/'
|
|
36
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}$')
|
|
37
56
|
# texts that can hold code, prompts or private notes: nulled unless texts=True
|
|
38
57
|
_TEXT_KEYS = frozenset(('prompt', 'last', 'request', 'log_tail', 'dwarf_tail', 'qa_tail', 'qa_last', 'qa_input',
|
|
39
58
|
'tasks_summary', 'known_issues', 'texts', 'text', 'planning_last', 'approach', 'retry_findings',
|
|
40
59
|
'dwarf_input', 'error', 'last_line', 'message', 'excerpt', 'tail', 'lines', 'call', 'split',
|
|
41
60
|
'needs_input', 'detail'))
|
|
42
61
|
# keys that are private text only under one parent: a person's --reason on each decision (`reason` elsewhere is
|
|
43
|
-
# a short machine word, such as a sweep's dropped-finding reason, and stays); the --reason of each adoption too
|
|
62
|
+
# a short machine word, such as a sweep's dropped-finding reason, and stays); the --reason of each adoption too.
|
|
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.
|
|
67
|
+
# A brief question's why, the choices in options, its default and the answer a person typed are private
|
|
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.
|
|
44
71
|
_TEXT_KEYS_UNDER = {'decisions': frozenset(('reason',)), 'adoptions': frozenset(('reason',)),
|
|
45
|
-
'adoption': frozenset(('reason',))
|
|
72
|
+
'adoption': frozenset(('reason',)), 'header': frozenset(('goal', 'criteria')),
|
|
73
|
+
'groups': frozenset(('goal', 'decision')),
|
|
74
|
+
'questions': frozenset(('why', 'options', 'default', 'answer')),
|
|
75
|
+
'parked': frozenset(('why', 'options', 'default', 'answer')),
|
|
76
|
+
'proposals': frozenset(('summary', 'diff', 'reason'))}
|
|
46
77
|
|
|
47
78
|
|
|
48
79
|
def _enc(value):
|
|
@@ -102,7 +133,9 @@ class _Snapshot:
|
|
|
102
133
|
value = server.api_get(self.catalog, path)
|
|
103
134
|
if value is server.NO_ROUTE or value is None:
|
|
104
135
|
return None
|
|
105
|
-
|
|
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)
|
|
106
139
|
size = len(json.dumps(value, ensure_ascii=False).encode('utf-8'))
|
|
107
140
|
if not required and ((cap and size > cap) or self.size + size > TOTAL_CAP):
|
|
108
141
|
self.omitted.append({'path': path, 'bytes': size, 'why': 'larger than 1 MB' if cap and size > cap else 'over the 25 MB total'})
|
|
@@ -167,7 +200,20 @@ def build(catalog, key, texts=False, paths=False, now=None):
|
|
|
167
200
|
tasks = [t for t in (detail.get('tasks') or []) if isinstance(t, dict) and t.get('id')]
|
|
168
201
|
for task in tasks:
|
|
169
202
|
snap.add(f"{base}/tasks/{_enc(task['id'])}")
|
|
170
|
-
|
|
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)})
|
|
171
217
|
for name in names:
|
|
172
218
|
snap.add(f'{base}/executions/{name}')
|
|
173
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
|