@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
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
"""GitHub links named in a task's markdown. No network, and no git."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import re
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
# A fenced block (CommonMark: up to three spaces, matching marker, backtick info has no backtick).
|
|
8
|
+
_FENCE = re.compile(r'^( {0,3})(`{3,}|~{3,})(.*)$')
|
|
9
|
+
# An ATX heading. `#8` has no space, so it stays a reference; `# Title` does not.
|
|
10
|
+
_ATX = re.compile(r'^[ ]{0,3}#{1,6}(?:[ \t]|$)')
|
|
11
|
+
# One block-quote marker: up to three spaces, `>`, and one optional space (CommonMark).
|
|
12
|
+
_QUOTE = re.compile(r'^( {0,3}> ?)')
|
|
13
|
+
# A thematic break. It takes precedence over a list marker (`- - -` is not a list).
|
|
14
|
+
_HR = re.compile(r'^ {0,3}([-*_])(?:[ \t]*\1){2,}[ \t]*$')
|
|
15
|
+
_NEXT = re.compile(r'https://github\.com/[^\s<>)\]]+|(?<![\w/])#(\d+)\b', re.IGNORECASE)
|
|
16
|
+
_ISSUE = re.compile(
|
|
17
|
+
r'^https://github\.com/([^/\s?#]+)/([^/\s?#]+)/(issues|pull)/(\d+)(?:[/?#]|$)', re.IGNORECASE)
|
|
18
|
+
_REMOTES = (
|
|
19
|
+
re.compile(r'^git@github\.com:([^/]+)/([^/]+?)(?:\.git)?/?$', re.IGNORECASE),
|
|
20
|
+
re.compile(r'^ssh://(?:git@)?github\.com/([^/]+)/([^/]+?)(?:\.git)?/?$', re.IGNORECASE),
|
|
21
|
+
re.compile(r'^https://github\.com/([^/]+)/([^/]+?)(?:\.git)?/?$', re.IGNORECASE),
|
|
22
|
+
re.compile(r'^git://github\.com/([^/]+)/([^/]+?)(?:\.git)?/?$', re.IGNORECASE),
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class _ListItem:
|
|
27
|
+
"""One open list item. `indent` is the spaces a later line needs to stay inside it."""
|
|
28
|
+
|
|
29
|
+
def __init__(self, indent, has_content):
|
|
30
|
+
self.indent = indent
|
|
31
|
+
self.has_content = has_content
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _blank(line):
|
|
35
|
+
return line.strip(' \t') == ''
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _expand_leading(line):
|
|
39
|
+
"""Leading tabs become spaces at stops of 4, the way CommonMark measures indent.
|
|
40
|
+
|
|
41
|
+
Only the indent is expanded. A tab later in the line is left as it is, and the original
|
|
42
|
+
line is what gets masked, so a reference's text does not move.
|
|
43
|
+
"""
|
|
44
|
+
column = 0
|
|
45
|
+
index = 0
|
|
46
|
+
while index < len(line) and line[index] in ' \t':
|
|
47
|
+
if line[index] == ' ':
|
|
48
|
+
column += 1
|
|
49
|
+
else:
|
|
50
|
+
column += 4 - (column % 4)
|
|
51
|
+
index += 1
|
|
52
|
+
return ' ' * column + line[index:]
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def _space_indent(line):
|
|
56
|
+
index = 0
|
|
57
|
+
while index < len(line) and line[index] == ' ':
|
|
58
|
+
index += 1
|
|
59
|
+
return index
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def _open_fence(line):
|
|
63
|
+
"""`(marker, length, indent)` or None. `line` is what remains after its containers."""
|
|
64
|
+
match = _FENCE.match(line)
|
|
65
|
+
if match is None:
|
|
66
|
+
return None
|
|
67
|
+
indent, mark, info = match.group(1), match.group(2), match.group(3)
|
|
68
|
+
if mark[0] == '`' and '`' in info:
|
|
69
|
+
return None
|
|
70
|
+
return mark[0], len(mark), len(indent)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def _close_fence(line, opened):
|
|
74
|
+
match = _FENCE.match(line)
|
|
75
|
+
if match is None:
|
|
76
|
+
return False
|
|
77
|
+
mark, info = match.group(2), match.group(3)
|
|
78
|
+
# CommonMark: a closer may take up to three spaces whatever the opener took; _FENCE caps it.
|
|
79
|
+
return mark[0] == opened[0] and len(mark) >= opened[1] and not info.strip()
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def _list_opener(line):
|
|
83
|
+
"""`(content indent, has content)` when `line` starts a list item, else None.
|
|
84
|
+
|
|
85
|
+
Four or more spaces before the marker is an indented code block, not a list. More than
|
|
86
|
+
four spaces after the marker are content; the item's own indent stays marker plus one.
|
|
87
|
+
"""
|
|
88
|
+
if _HR.match(line):
|
|
89
|
+
return None
|
|
90
|
+
mark_at = 0
|
|
91
|
+
while mark_at < 3 and mark_at < len(line) and line[mark_at] == ' ':
|
|
92
|
+
mark_at += 1
|
|
93
|
+
if mark_at >= len(line) or line[mark_at] == ' ':
|
|
94
|
+
return None
|
|
95
|
+
body = line[mark_at:]
|
|
96
|
+
if body[0] in '-+*':
|
|
97
|
+
width = 1
|
|
98
|
+
else:
|
|
99
|
+
width = 0
|
|
100
|
+
while width < len(body) and width < 9 and body[width].isdigit():
|
|
101
|
+
width += 1
|
|
102
|
+
if width == 0 or width >= len(body) or body[width] not in '.)':
|
|
103
|
+
return None
|
|
104
|
+
width += 1
|
|
105
|
+
after = body[width:]
|
|
106
|
+
spaces = 0
|
|
107
|
+
while spaces < len(after) and after[spaces] == ' ':
|
|
108
|
+
spaces += 1
|
|
109
|
+
if spaces == 0 and after != '':
|
|
110
|
+
return None
|
|
111
|
+
if spaces == len(after):
|
|
112
|
+
padding, has_content = 1, False
|
|
113
|
+
elif spaces > 4:
|
|
114
|
+
padding, has_content = 1, True
|
|
115
|
+
else:
|
|
116
|
+
padding, has_content = spaces, True
|
|
117
|
+
return mark_at + width + padding, has_content
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def _list_interrupts(line):
|
|
121
|
+
"""A bullet interrupts a paragraph. An ordered marker does only when its number is 1."""
|
|
122
|
+
if _list_opener(line) is None:
|
|
123
|
+
return False
|
|
124
|
+
body = line[_space_indent(line):]
|
|
125
|
+
return body[:1] in '-+*' or body.startswith('1.') or body.startswith('1)')
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def _interrupts_paragraph(line):
|
|
129
|
+
return (_ATX.match(line) is not None or _open_fence(line) is not None or _QUOTE.match(line) is not None
|
|
130
|
+
or _HR.match(line) is not None or _list_interrupts(line))
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def _open_containers(rest, containers, paragraph):
|
|
134
|
+
"""Open block quotes and list items at the start of `rest`. Return the leaf content."""
|
|
135
|
+
while rest:
|
|
136
|
+
match = _QUOTE.match(rest)
|
|
137
|
+
if match:
|
|
138
|
+
containers.append('quote')
|
|
139
|
+
rest = rest[match.end():]
|
|
140
|
+
paragraph = False
|
|
141
|
+
continue
|
|
142
|
+
opened = _list_opener(rest)
|
|
143
|
+
if opened is not None and (not paragraph or _list_interrupts(rest)):
|
|
144
|
+
indent, has_content = opened
|
|
145
|
+
containers.append(_ListItem(indent, has_content))
|
|
146
|
+
rest = rest[indent:]
|
|
147
|
+
paragraph = False
|
|
148
|
+
continue
|
|
149
|
+
break
|
|
150
|
+
return rest
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def _continue(line, containers, allow_lazy):
|
|
154
|
+
"""Match open quotes and list items outside-in.
|
|
155
|
+
|
|
156
|
+
Return `(kept, rest, lazy)`. A miss closes that container and everything inside it
|
|
157
|
+
(`kept` false) so the line is tried again. A fenced block does not continue lazily:
|
|
158
|
+
`allow_lazy` is only for a paragraph, and a line that starts a block is not one.
|
|
159
|
+
"""
|
|
160
|
+
rest = line
|
|
161
|
+
for index, box in enumerate(containers):
|
|
162
|
+
if box == 'quote':
|
|
163
|
+
match = _QUOTE.match(rest)
|
|
164
|
+
if match:
|
|
165
|
+
rest = rest[match.end():]
|
|
166
|
+
continue
|
|
167
|
+
elif _blank(rest):
|
|
168
|
+
# A blank line stays in an item that already has content, and ends an empty one.
|
|
169
|
+
if not box.has_content:
|
|
170
|
+
del containers[index:]
|
|
171
|
+
return False, line, False
|
|
172
|
+
continue
|
|
173
|
+
else:
|
|
174
|
+
spaces = _space_indent(rest)
|
|
175
|
+
if spaces >= box.indent:
|
|
176
|
+
rest = rest[box.indent:]
|
|
177
|
+
box.has_content = True
|
|
178
|
+
continue
|
|
179
|
+
if allow_lazy and not _blank(line) and not _interrupts_paragraph(rest):
|
|
180
|
+
return True, line, True
|
|
181
|
+
del containers[index:]
|
|
182
|
+
return False, line, False
|
|
183
|
+
return True, rest, False
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
def _mask(text):
|
|
187
|
+
"""Blank fenced blocks, inline code spans, and ATX heading lines. Length stays put.
|
|
188
|
+
|
|
189
|
+
A fence inside a block quote ends when the quote ends: a fenced block does not run on
|
|
190
|
+
into the next paragraph. A fence under a list item is indented with the item; that
|
|
191
|
+
indent is removed before the marker is recognized. A marker indented four or more
|
|
192
|
+
spaces outside a list is an indented code block and is left alone. A quoted fence
|
|
193
|
+
marker inside a top-level fence is content, so it does not close the outer fence.
|
|
194
|
+
"""
|
|
195
|
+
masked, containers, fence, paragraph = [], [], None, False
|
|
196
|
+
lines = text.splitlines()
|
|
197
|
+
index = 0
|
|
198
|
+
while index < len(lines):
|
|
199
|
+
line = lines[index]
|
|
200
|
+
view = _expand_leading(line)
|
|
201
|
+
if fence is not None:
|
|
202
|
+
kept, rest, _lazy = _continue(view, containers, allow_lazy=False)
|
|
203
|
+
if not kept:
|
|
204
|
+
fence = None
|
|
205
|
+
continue
|
|
206
|
+
if _close_fence(rest, fence):
|
|
207
|
+
fence = None
|
|
208
|
+
masked.append(' ' * len(line))
|
|
209
|
+
index += 1
|
|
210
|
+
continue
|
|
211
|
+
kept, rest, lazy = _continue(view, containers, allow_lazy=paragraph)
|
|
212
|
+
if not kept:
|
|
213
|
+
continue
|
|
214
|
+
if lazy:
|
|
215
|
+
paragraph = True
|
|
216
|
+
masked.append(line)
|
|
217
|
+
index += 1
|
|
218
|
+
continue
|
|
219
|
+
rest = _open_containers(rest, containers, paragraph)
|
|
220
|
+
opened = _open_fence(rest)
|
|
221
|
+
if opened is not None:
|
|
222
|
+
fence = opened
|
|
223
|
+
paragraph = False
|
|
224
|
+
masked.append(' ' * len(line))
|
|
225
|
+
index += 1
|
|
226
|
+
continue
|
|
227
|
+
paragraph = not _blank(rest) and _ATX.match(rest) is None and _HR.match(rest) is None
|
|
228
|
+
masked.append(line)
|
|
229
|
+
index += 1
|
|
230
|
+
body = _mask_spans('\n'.join(masked))
|
|
231
|
+
blanked = []
|
|
232
|
+
for line in body.split('\n'):
|
|
233
|
+
blanked.append(' ' * len(line) if _ATX.match(line) else line)
|
|
234
|
+
return '\n'.join(blanked)
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
def _mask_spans(text):
|
|
238
|
+
"""Blank inline code spans. A span closes on the next run of the same number of backticks."""
|
|
239
|
+
out, index, size = [], 0, len(text)
|
|
240
|
+
while index < size:
|
|
241
|
+
if text[index] != '`':
|
|
242
|
+
out.append(text[index])
|
|
243
|
+
index += 1
|
|
244
|
+
continue
|
|
245
|
+
end = index
|
|
246
|
+
while end < size and text[end] == '`':
|
|
247
|
+
end += 1
|
|
248
|
+
length, cursor, close = end - index, end, None
|
|
249
|
+
while cursor < size:
|
|
250
|
+
if text[cursor] != '`':
|
|
251
|
+
cursor += 1
|
|
252
|
+
continue
|
|
253
|
+
run = cursor
|
|
254
|
+
while run < size and text[run] == '`':
|
|
255
|
+
run += 1
|
|
256
|
+
if run - cursor == length:
|
|
257
|
+
close = run
|
|
258
|
+
break
|
|
259
|
+
cursor = run
|
|
260
|
+
if close is None:
|
|
261
|
+
out.append(text[index:end])
|
|
262
|
+
index = end
|
|
263
|
+
else:
|
|
264
|
+
out.append(' ' * (close - index))
|
|
265
|
+
index = close
|
|
266
|
+
return ''.join(out)
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
def _slug(origin):
|
|
270
|
+
"""`(owner, repo)` of a GitHub remote, or None. SSH and HTTPS both work. No network."""
|
|
271
|
+
if not isinstance(origin, str):
|
|
272
|
+
return None
|
|
273
|
+
text = origin.strip()
|
|
274
|
+
if len(text) >= 2 and text[0] == text[-1] and text[0] in '\'"':
|
|
275
|
+
text = text[1:-1].strip()
|
|
276
|
+
for pattern in _REMOTES:
|
|
277
|
+
match = pattern.match(text)
|
|
278
|
+
if match is None:
|
|
279
|
+
continue
|
|
280
|
+
owner, repo = match.group(1), match.group(2)
|
|
281
|
+
if owner in ('.', '..') or repo in ('.', '..'):
|
|
282
|
+
return None
|
|
283
|
+
return owner, repo
|
|
284
|
+
return None
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
def _number(text):
|
|
288
|
+
"""The integer, or None when the digit string is longer than Python will convert."""
|
|
289
|
+
try:
|
|
290
|
+
return int(text)
|
|
291
|
+
except ValueError:
|
|
292
|
+
return None
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
def _issue(token, source):
|
|
296
|
+
token = token.rstrip('.,;:!?')
|
|
297
|
+
match = _ISSUE.match(token)
|
|
298
|
+
if match is None:
|
|
299
|
+
return dict(kind='url', number=None, url=token, source=source)
|
|
300
|
+
number = _number(match.group(4))
|
|
301
|
+
# A number past the conversion limit is still a URL; it is not an issue number.
|
|
302
|
+
if number is None:
|
|
303
|
+
return dict(kind='url', number=None, url=token, source=source)
|
|
304
|
+
owner, repo, kind = match.group(1), match.group(2), match.group(3).lower()
|
|
305
|
+
path = 'pull' if kind == 'pull' else 'issues'
|
|
306
|
+
url = f'https://github.com/{owner}/{repo}/{path}/{number}'
|
|
307
|
+
return dict(kind='pr' if kind == 'pull' else 'issue', number=number, url=url, source=source)
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
def extract(text, source, origin=None):
|
|
311
|
+
"""`[{kind, number, url, source}]` in order, deduplicated.
|
|
312
|
+
|
|
313
|
+
`kind` is `issue`, `pr` or `url`. A `#N` reference is an issue; its url is
|
|
314
|
+
`https://github.com/<owner>/<repo>/issues/N` when `origin` is that repo's GitHub
|
|
315
|
+
remote, and null otherwise. Full issue and pull URLs are canonical, so the same
|
|
316
|
+
number written as `#N` and as a URL is one link. A digit string Python will not
|
|
317
|
+
convert is skipped for `#N`, and kept as kind `url` for a full URL. Nothing is fetched.
|
|
318
|
+
"""
|
|
319
|
+
if not text:
|
|
320
|
+
return []
|
|
321
|
+
slug = _slug(origin)
|
|
322
|
+
found, seen = [], set()
|
|
323
|
+
for match in _NEXT.finditer(_mask(text)):
|
|
324
|
+
if match.group(1) is None:
|
|
325
|
+
item = _issue(match.group(0), source)
|
|
326
|
+
else:
|
|
327
|
+
number = _number(match.group(1))
|
|
328
|
+
if number is None:
|
|
329
|
+
continue
|
|
330
|
+
url = f'https://github.com/{slug[0]}/{slug[1]}/issues/{number}' if slug else None
|
|
331
|
+
item = dict(kind='issue', number=number, url=url, source=source)
|
|
332
|
+
key = (item['kind'], item['number'], item['url'])
|
|
333
|
+
if key in seen:
|
|
334
|
+
continue
|
|
335
|
+
seen.add(key)
|
|
336
|
+
found.append(item)
|
|
337
|
+
return found
|
package/ui/forge_ui/models.py
CHANGED
|
@@ -7,14 +7,16 @@ implementer is censored, never counted as a failure.
|
|
|
7
7
|
from __future__ import annotations
|
|
8
8
|
|
|
9
9
|
from collections import OrderedDict
|
|
10
|
+
import importlib.util
|
|
10
11
|
import json
|
|
11
12
|
import math
|
|
12
13
|
import os
|
|
13
14
|
from pathlib import Path
|
|
15
|
+
import sys
|
|
14
16
|
import threading
|
|
15
17
|
import time
|
|
16
18
|
|
|
17
|
-
from forge_ui import executions, reader
|
|
19
|
+
from forge_ui import executions, findings, reader
|
|
18
20
|
|
|
19
21
|
|
|
20
22
|
_MAX_ROWS = 50000
|
|
@@ -35,6 +37,115 @@ def _alias(spec):
|
|
|
35
37
|
return (spec.split(':', 1)[0] or None) if isinstance(spec, str) else None
|
|
36
38
|
|
|
37
39
|
|
|
40
|
+
_DATASET = Path(__file__).resolve().parents[2] / 'scripts' / 'forge_dataset' / '__init__.py'
|
|
41
|
+
_SIDE_LOCK = threading.Lock()
|
|
42
|
+
_SIDE_FN = {}
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def _is_side_role():
|
|
46
|
+
"""forge_dataset.is_side_role, loaded read-only the way reader loads forge_infra. None when it cannot be."""
|
|
47
|
+
with _SIDE_LOCK:
|
|
48
|
+
if 'fn' in _SIDE_FN:
|
|
49
|
+
return _SIDE_FN['fn']
|
|
50
|
+
fn = None
|
|
51
|
+
scripts = str(_DATASET.parents[1])
|
|
52
|
+
inserted = scripts not in sys.path
|
|
53
|
+
if inserted:
|
|
54
|
+
sys.path.insert(0, scripts)
|
|
55
|
+
try:
|
|
56
|
+
spec = importlib.util.spec_from_file_location(
|
|
57
|
+
'forge_dataset_for_ui', _DATASET,
|
|
58
|
+
loader=findings._ReadOnlyLoader('forge_dataset_for_ui', str(_DATASET)))
|
|
59
|
+
module = importlib.util.module_from_spec(spec)
|
|
60
|
+
spec.loader.exec_module(module)
|
|
61
|
+
candidate = getattr(module, 'is_side_role', None)
|
|
62
|
+
fn = candidate if callable(candidate) else None
|
|
63
|
+
except Exception:
|
|
64
|
+
fn = None
|
|
65
|
+
finally:
|
|
66
|
+
if inserted and scripts in sys.path:
|
|
67
|
+
sys.path.remove(scripts)
|
|
68
|
+
_SIDE_FN['fn'] = fn
|
|
69
|
+
return fn
|
|
70
|
+
|
|
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
|
+
|
|
110
|
+
def side_role(role) -> bool:
|
|
111
|
+
"""A side dispatch: harvested `side_*`, or the on-disk role `side` (`is_side_role` rejects the bare name).
|
|
112
|
+
|
|
113
|
+
Not an attempt. A shadow review is a separate flag on the execution; this is only the role.
|
|
114
|
+
"""
|
|
115
|
+
if role == 'side':
|
|
116
|
+
return True
|
|
117
|
+
fn = _is_side_role()
|
|
118
|
+
if fn is not None:
|
|
119
|
+
return bool(fn(role))
|
|
120
|
+
return isinstance(role, str) and role.startswith('side_')
|
|
121
|
+
|
|
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
|
+
|
|
142
|
+
def _primary_qa(item) -> bool:
|
|
143
|
+
"""The review of record for an attempt. A shadow review, a side dispatch and a group review are not one."""
|
|
144
|
+
role = item['role']
|
|
145
|
+
return (role == 'qa' and not item['shadow'] and role != 'qa_shadow' and not side_role(role)
|
|
146
|
+
and not _group_scope(item))
|
|
147
|
+
|
|
148
|
+
|
|
38
149
|
def _builtin_profiles_path():
|
|
39
150
|
"""scripts/forge_decide/builtin_profiles.json, located from this package the way reader._forge_infra finds
|
|
40
151
|
scripts/forge_infra.py. Read as data: forge-ui never imports forge_decide."""
|
|
@@ -127,7 +238,7 @@ def _attempts(rows, execs, plan_spec):
|
|
|
127
238
|
result = []
|
|
128
239
|
for n, (status, logged) in rows.items():
|
|
129
240
|
dwarfs = [item for item in execs if item['role'] == 'dwarf' and item['attempt'] == n]
|
|
130
|
-
reviews = [item for item in execs if item
|
|
241
|
+
reviews = [item for item in execs if _primary_qa(item) and item['attempt'] == n]
|
|
131
242
|
outcome, reason = _outcome(status, dwarfs, reviews)
|
|
132
243
|
last = dwarfs[-1] if dwarfs else None
|
|
133
244
|
model = last['model'] if last is not None else None
|
|
@@ -140,7 +251,7 @@ def _attempts(rows, execs, plan_spec):
|
|
|
140
251
|
else:
|
|
141
252
|
spec = source = None
|
|
142
253
|
verdict = reviews[-1]['verdict'] if reviews else None
|
|
143
|
-
result.append(dict(n=n, alias=model
|
|
254
|
+
result.append(dict(n=n, alias=_named(model) if model else _alias(spec), spec=spec, source=source,
|
|
144
255
|
outcome=outcome, reason=reason, gate=outcome == 'pass' and verdict == 'FAIL',
|
|
145
256
|
gate_fail=outcome == 'fail' and verdict == 'PASS',
|
|
146
257
|
model_s=last['phases'].get('model') if last is not None else None,
|
|
@@ -166,9 +277,9 @@ def _route(rd, base):
|
|
|
166
277
|
def _reviews(key, ident, execs, shadows):
|
|
167
278
|
rows = []
|
|
168
279
|
for item in execs:
|
|
169
|
-
if item
|
|
280
|
+
if _primary_qa(item) and item['state'] == 'done':
|
|
170
281
|
model = item['model'] or {}
|
|
171
|
-
rows.append(dict(run=key, task=ident, n=item['attempt'], kind='primary', alias=model
|
|
282
|
+
rows.append(dict(run=key, task=ident, n=item['attempt'], kind='primary', alias=_named(model),
|
|
172
283
|
spec=model.get('spec'), verdict=item['verdict'], findings=item['findings'],
|
|
173
284
|
duration_s=item['duration_s'], tokens=item['tokens'], agreement=None, primary_alias=None))
|
|
174
285
|
for entry, items, _ in shadows:
|
|
@@ -176,13 +287,13 @@ def _reviews(key, ident, execs, shadows):
|
|
|
176
287
|
continue
|
|
177
288
|
model = (items[-1]['model'] if items else None) or {}
|
|
178
289
|
spec = entry['spec'] if isinstance(entry['spec'], str) else model.get('spec')
|
|
179
|
-
primaries = [item for item in execs if item
|
|
290
|
+
primaries = [item for item in execs if _primary_qa(item)
|
|
180
291
|
and item['attempt'] == entry['attempt'] and item['model']]
|
|
181
|
-
rows.append(dict(run=key, task=ident, n=entry['attempt'], kind='shadow', alias=model
|
|
292
|
+
rows.append(dict(run=key, task=ident, n=entry['attempt'], kind='shadow', alias=_named(model) or _alias(spec),
|
|
182
293
|
spec=spec, verdict=entry['verdict'], findings=entry['findings'],
|
|
183
294
|
duration_s=entry['duration_s'], tokens=items[-1]['tokens'] if items else None,
|
|
184
295
|
agreement=entry['agreement'],
|
|
185
|
-
primary_alias=primaries[-1]['model']
|
|
296
|
+
primary_alias=_named(primaries[-1]['model']) if primaries else _alias(entry['primary'])))
|
|
186
297
|
return rows
|
|
187
298
|
|
|
188
299
|
|
|
@@ -205,10 +316,14 @@ def _facts(path, summary, root):
|
|
|
205
316
|
execs = reader._task_execs(rd, task)
|
|
206
317
|
shadows = reader._shadows(rd, task['id'], execs)
|
|
207
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'
|
|
208
322
|
tasks.append(dict(base_row, task=task['id'], kind='plan', difficulty=task['difficulty'] or None,
|
|
209
323
|
explored=explored, propensity=propensity, final_status=task['status'],
|
|
210
324
|
accepted=reader._nonempty(rd, base + '/accepted.by'),
|
|
211
|
-
attempts=_attempts(_attempt_rows(rd, base + '/attempts.tsv'), execs,
|
|
325
|
+
attempts=[] if scripted else _attempts(_attempt_rows(rd, base + '/attempts.tsv'), execs,
|
|
326
|
+
task['dwarf']),
|
|
212
327
|
escalations=[{'n': item['attempt'], 'from': item['from'], 'to': item['to']}
|
|
213
328
|
for item in reader._history(rd, base + '/escalations.tsv', True)]))
|
|
214
329
|
reviews += _reviews(key, task['id'], execs, shadows)
|
|
@@ -221,7 +336,7 @@ def _facts(path, summary, root):
|
|
|
221
336
|
run = execs[-1] if execs else None
|
|
222
337
|
model = (run['model'] if run else None) or {}
|
|
223
338
|
spec = review['spec'] or model.get('spec')
|
|
224
|
-
reviews.append(dict(run=key, task=None, n=None, kind='final', alias=model
|
|
339
|
+
reviews.append(dict(run=key, task=None, n=None, kind='final', alias=_named(model) or _alias(spec),
|
|
225
340
|
spec=spec, verdict=review['verdict'] if review['verdict'] in ('PASS', 'FAIL') else None,
|
|
226
341
|
findings=review['findings'], duration_s=review['duration_s'],
|
|
227
342
|
tokens=run['tokens'] if run else None, agreement=None, primary_alias=None))
|
package/ui/forge_ui/projects.py
CHANGED
|
@@ -30,7 +30,7 @@ from pathlib import Path
|
|
|
30
30
|
import threading
|
|
31
31
|
import time
|
|
32
32
|
|
|
33
|
-
from forge_ui import executions, findings as F, reader, repos
|
|
33
|
+
from forge_ui import executions, findings as F, models, reader, repos
|
|
34
34
|
|
|
35
35
|
ISSUES = Path(__file__).resolve().parents[2] / 'scripts' / 'forge-issues.py'
|
|
36
36
|
CACHE_S = 300
|
|
@@ -246,6 +246,9 @@ def _dataset_occurrences(hist, runs_here):
|
|
|
246
246
|
for (run, task), reviews in by_run.items():
|
|
247
247
|
reviews.sort(key=lambda r: r.get('ts') or 0)
|
|
248
248
|
for index, review in enumerate(reviews):
|
|
249
|
+
# A side dispatch is not a review of the task. qa_shadow stays a shadow row.
|
|
250
|
+
if models.side_role(review.get('role')):
|
|
251
|
+
continue
|
|
249
252
|
superseded = any(r.get('verdict') == 'PASS' and r.get('role') == 'qa' for r in reviews[index + 1:])
|
|
250
253
|
for item in review.get('findings') or []:
|
|
251
254
|
head = item['head']
|