@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
|
@@ -1,19 +1,29 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
2
|
"""The QA contract: one shared review prompt, a severity vocabulary and a deterministic gate.
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
Subcommands, stdlib only, no network:
|
|
5
5
|
|
|
6
|
-
qa --part head|tail [--kind task|final|solo|sweep] [--threshold P0|P1|P2|P3|none]
|
|
6
|
+
qa --part head|tail [--kind task|final|solo|sweep|adopt|group|script] [--threshold P0|P1|P2|P3|none]
|
|
7
7
|
Prints one piece of the QA prompt. The caller prints everything between and
|
|
8
8
|
after the pieces itself (scope notes, the diff fence, the memory note and the
|
|
9
9
|
"Place any learning notes before the final FORGE_VERDICT ..." sentence).
|
|
10
10
|
dwarf [--pre-review]
|
|
11
11
|
Prints the implementer rules block that callers append to the dwarf prompt;
|
|
12
12
|
--pre-review adds that forge runs the affected tests before the review (#85).
|
|
13
|
+
retro --role dwarf|qa|planner|review
|
|
14
|
+
Prints the retro-note instruction. Most tasks have nothing to say. Only the
|
|
15
|
+
dwarf's text mentions writing .forge/retro-inbox.jsonl when a hard blocker hits.
|
|
13
16
|
gate --verdict PASS|FAIL|UNKNOWN --qa-last FILE [--threshold Pn|none] [--known-issues OUT]
|
|
14
17
|
Prints ONE tab-separated line
|
|
15
18
|
decision <TAB> worst_confirmed <TAB> n_confirmed <TAB> n_unlabelled <TAB> n_below
|
|
16
19
|
and, when findings were tolerated, writes them to OUT.
|
|
20
|
+
outside --qa-last FILE [--threshold Pn|none]
|
|
21
|
+
Prints a JSON list, one object per parsed finding: n (1-based), severity (P0-P3
|
|
22
|
+
or null), status, blocking (the gate's per-finding rule at the threshold) and
|
|
23
|
+
outside (the paths of that finding's last {outside=…} brace).
|
|
24
|
+
blocked --message FILE
|
|
25
|
+
Prints a JSON list of {"path", "why"} from every FORGE_BLOCKED line. The why may
|
|
26
|
+
be empty. A repeated path keeps the first line.
|
|
17
27
|
|
|
18
28
|
Severity. Reviewers label every finding P0 (data loss, security hole, crash or wrong
|
|
19
29
|
result on the main path), P1 (wrong behaviour on realistic input, breaks an existing
|
|
@@ -57,11 +67,14 @@ line (`[P2]`, `(P2)`, `**P2**`, `P2:`, `P2 -` or a standalone `P2`; uppercase on
|
|
|
57
67
|
Facts (#119). A finding may end its first line (or, wrapped, its last) with
|
|
58
68
|
`{reach=main|realistic|unusual origin=new|existing evidence=ran|traced|suspected}`. They are
|
|
59
69
|
recorded in shadow and decide nothing: the gate never reads them, and `split_facts` cuts the
|
|
60
|
-
suffix for readers that show the line. A missing or malformed suffix changes nothing.
|
|
70
|
+
suffix for readers that show the line. A missing or malformed suffix changes nothing. A group
|
|
71
|
+
review may put `{tasks=…}` on that same line; the facts are still read when that brace follows
|
|
72
|
+
them, and still when the facts brace is what closes the line. `{outside=…}` is cut the same
|
|
73
|
+
way, on its own or beside `{tasks=…}`, in either order.
|
|
61
74
|
|
|
62
75
|
Phantom findings. A reviewer may echo the contract it was given. Three layers keep that
|
|
63
|
-
from creating findings or blocking: (1) FORGE_VERDICT, FORGE_LEARNING
|
|
64
|
-
before parsing (the verdict line itself says "CONFIRMED"); (2) any line that is a
|
|
76
|
+
from creating findings or blocking: (1) FORGE_VERDICT, FORGE_LEARNING, FORGE_TESTS, FORGE_RETRO and
|
|
77
|
+
FORGE_BLOCKED text is removed before parsing (the verdict line itself says "CONFIRMED"); (2) any line that is a
|
|
65
78
|
contiguous fragment of this module's own contract text (all parts, kinds and thresholds,
|
|
66
79
|
whitespace-collapsed, at least 25 characters, list marker ignored) is removed, which
|
|
67
80
|
covers the example bullet, the severity definitions and the instructions even when
|
|
@@ -69,7 +82,7 @@ re-wrapped; (3) a block whose first line holds the literal placeholder
|
|
|
69
82
|
`path/file.py:123` is ignored. A leftover false match can only add a finding or a
|
|
70
83
|
blocker, and an added CONFIRMED finding without a label blocks.
|
|
71
84
|
|
|
72
|
-
Exit codes: 0 ok (even for `keep`), 2 usage, 3 unreadable
|
|
85
|
+
Exit codes: 0 ok (even for `keep`), 2 usage, 3 unreadable input file or unwritable OUT
|
|
73
86
|
file. On any nonzero exit callers must treat the decision as `keep`.
|
|
74
87
|
"""
|
|
75
88
|
from __future__ import annotations
|
|
@@ -77,13 +90,14 @@ from __future__ import annotations
|
|
|
77
90
|
import argparse
|
|
78
91
|
import collections
|
|
79
92
|
import functools
|
|
93
|
+
import json
|
|
80
94
|
import os
|
|
81
95
|
import re
|
|
82
96
|
import sys
|
|
83
97
|
|
|
84
98
|
SEVERITIES = ('P0', 'P1', 'P2', 'P3')
|
|
85
99
|
PLACEHOLDER = 'path/file.py:123'
|
|
86
|
-
KINDS = ('task', 'final', 'solo', 'sweep', 'adopt')
|
|
100
|
+
KINDS = ('task', 'final', 'solo', 'sweep', 'adopt', 'group', 'script')
|
|
87
101
|
DEFAULT_THRESHOLD = 'P2'
|
|
88
102
|
QA_TEST_MINUTES = 5 # the reviewer's own test time, beyond which it says the check is too broad (#89)
|
|
89
103
|
|
|
@@ -155,13 +169,29 @@ _HEAD = {
|
|
|
155
169
|
],
|
|
156
170
|
}
|
|
157
171
|
|
|
172
|
+
# A scripted task (#142): its diff is what tasks/<id>/run produced; the reviewer judges the command
|
|
173
|
+
# and its result. Same tail as `task`.
|
|
174
|
+
_HEAD['script'] = _HEAD['task'] + [
|
|
175
|
+
'This diff was produced by the command below, not written by hand. Check the command and its',
|
|
176
|
+
'result: is the result complete and correct for the requirements, and did the command do only',
|
|
177
|
+
'what it should? When the change is mechanical you need not read every changed file; sample it,',
|
|
178
|
+
'and say what you sampled.',
|
|
179
|
+
]
|
|
180
|
+
# Group review (#140) is the task contract plus one review over several tasks. The shared
|
|
181
|
+
# preamble stays the task one, so a change to it reaches group; these lines are the addition.
|
|
182
|
+
_HEAD['group'] = _HEAD['task'] + [
|
|
183
|
+
'This review covers several tasks, listed with their own requirements and acceptance',
|
|
184
|
+
'criteria. Judge each task against its own criteria, and judge the combined change',
|
|
185
|
+
'as a whole, including how the tasks fit together.',
|
|
186
|
+
]
|
|
187
|
+
|
|
158
188
|
_FINDINGS = [
|
|
159
189
|
'Report findings only — do not edit any file. For each finding give the file and line,',
|
|
160
190
|
'what breaks, and a concrete input that triggers it. Mark each CONFIRMED if you traced',
|
|
161
191
|
'it in the code, or PLAUSIBLE if you could not fully verify it.',
|
|
162
192
|
]
|
|
163
193
|
# #69: task reviews returned a few findings per round. These two lines follow _FINDINGS for
|
|
164
|
-
# task and
|
|
194
|
+
# task, solo, adopt and group, so the findings rules stay one paragraph. Final and sweep omit them.
|
|
165
195
|
_ALL_CONFIRMED = ['List every CONFIRMED finding you find, not only the most important few.']
|
|
166
196
|
_SOLO_EXTRA = ['If the diff is correct, say so plainly rather than inventing something to report.']
|
|
167
197
|
|
|
@@ -207,6 +237,36 @@ _SEVERITY = [
|
|
|
207
237
|
FACTS = {'reach': ('main', 'realistic', 'unusual'), 'origin': ('new', 'existing'),
|
|
208
238
|
'evidence': ('ran', 'traced', 'suspected')}
|
|
209
239
|
|
|
240
|
+
# Group review (#140) attributes each finding to a member. The facts brace above is a different
|
|
241
|
+
# tag and may sit on the same bullet; `{tasks=…}` has to be its own brace or the two are confused.
|
|
242
|
+
# The facts brace still closes the line (`split_facts` reads a group that ends it). `{tasks=…}`
|
|
243
|
+
# sits immediately before that brace. A tasks brace written after the facts is still parsed, so a
|
|
244
|
+
# reviewer who ends on `{tasks=…}` does not drop the shadow measurement, but the prompt names one order.
|
|
245
|
+
_GROUP_ATTRIB = [
|
|
246
|
+
'Attribute each finding to the task whose diff changed the file it names.',
|
|
247
|
+
'When a finding is about a different task than the file suggests, or it spans',
|
|
248
|
+
'several tasks, end its bullet with {tasks=a,b}, the ids of the tasks that must',
|
|
249
|
+
'change. A finding with no file needs {tasks=…}.',
|
|
250
|
+
'The {reach=… origin=… evidence=…} facts may sit on the same bullet. They are not',
|
|
251
|
+
'the tasks tag. Write {tasks=…} in its own braces, immediately before the facts',
|
|
252
|
+
'brace, so the facts brace still ends the line:',
|
|
253
|
+
' - [P1][CONFIRMED] path/file.py:123 — {tasks=a,b} {reach=realistic origin=new evidence=traced}',
|
|
254
|
+
]
|
|
255
|
+
|
|
256
|
+
# #149. The only fix is a file this task did not declare. The brace is its own, immediately
|
|
257
|
+
# before the facts, like `{tasks=…}`. Final, sweep and adopt do not say it: those reviews
|
|
258
|
+
# are not sending one task back to edit its own files. outside-stop reads the brace.
|
|
259
|
+
# The example is one line: tail lines other than the two verdict lines are at most 95
|
|
260
|
+
# characters, and it keeps path/file.py:123 so an echoed bullet is not a finding.
|
|
261
|
+
_OUTSIDE = [
|
|
262
|
+
'When the only fix for a finding is a change in a file outside the files this task',
|
|
263
|
+
'declared, end the finding\'s first line with {outside=<repo-relative path>},',
|
|
264
|
+
'several paths comma-separated. Write {outside=…} in its own braces,',
|
|
265
|
+
'immediately before the facts brace, like the tasks tag. Use it only when the fix',
|
|
266
|
+
'cannot be made inside the task\'s files:',
|
|
267
|
+
' - [P1][CONFIRMED] path/file.py:123 — {outside=a.py,b.py} {reach=main origin=new evidence=ran}',
|
|
268
|
+
]
|
|
269
|
+
|
|
210
270
|
_SWEEP_FINDINGS = [
|
|
211
271
|
'Report findings only — do not edit any file. A finding here is a regression the change',
|
|
212
272
|
'introduced: give its file and line, what breaks, and a concrete input that triggers it. Mark it',
|
|
@@ -255,10 +315,14 @@ def qa_text(part: str, kind: str = 'task', threshold=None) -> str:
|
|
|
255
315
|
if part != 'tail':
|
|
256
316
|
raise ValueError('part must be head or tail')
|
|
257
317
|
lines = list(_SWEEP_FINDINGS if kind == 'sweep' else _FINDINGS)
|
|
258
|
-
if kind in ('task', 'solo', 'adopt'):
|
|
318
|
+
if kind in ('task', 'solo', 'adopt', 'group', 'script'):
|
|
259
319
|
lines += _ALL_CONFIRMED + _SOLO_EXTRA
|
|
260
320
|
lines += [''] + _VERIFY
|
|
261
321
|
lines += [''] + _SEVERITY
|
|
322
|
+
if kind in ('task', 'solo', 'group', 'script'):
|
|
323
|
+
lines += [''] + _OUTSIDE
|
|
324
|
+
if kind == 'group':
|
|
325
|
+
lines += [''] + _GROUP_ATTRIB
|
|
262
326
|
lines += [''] + _threshold_clause(rank, kind) + _CHECKED
|
|
263
327
|
if kind == 'sweep':
|
|
264
328
|
lines += [''] + _SWEEP_STATUS
|
|
@@ -297,6 +361,10 @@ _DWARF = [
|
|
|
297
361
|
'- Finish every measurement and test run BEFORE your last message and report its actual',
|
|
298
362
|
' result. If you could not run something, say so explicitly instead of claiming it passed.',
|
|
299
363
|
'- State precisely which verification commands you ran and what each one returned.',
|
|
364
|
+
# #149. Do not edit a file the task does not own. outside-stop reads these lines.
|
|
365
|
+
'- When a fix you need is in a file outside your task\'s files, do not edit that file;',
|
|
366
|
+
' finish your work, then end your final message with one line per path,',
|
|
367
|
+
' FORGE_BLOCKED: <path>: <why>',
|
|
300
368
|
]
|
|
301
369
|
|
|
302
370
|
|
|
@@ -306,6 +374,38 @@ _DWARF_PRE_REVIEW = [
|
|
|
306
374
|
]
|
|
307
375
|
|
|
308
376
|
|
|
377
|
+
# Retro notes (#132). Silence is the default: the task being hard is not a note. Only the
|
|
378
|
+
# dwarf can be blocked before it has a final message, so only that text mentions the inbox.
|
|
379
|
+
RETRO_ROLES = ('dwarf', 'qa', 'planner', 'review')
|
|
380
|
+
_RETRO = [
|
|
381
|
+
'Most tasks have nothing to report. Write a retro note only for an obstacle that came',
|
|
382
|
+
'from forge, this machine, or the instructions. The task\'s own difficulty does not',
|
|
383
|
+
'belong here: a hard task is not a note.',
|
|
384
|
+
'When you do have one, put it on a line of its own in your final message, as JSON:',
|
|
385
|
+
' FORGE_RETRO: {"type":"sandbox","fixable_by":"user","summary":"the sandbox blocked git push","evidence":{"command":"git push","exit":128,"error":"fatal: unable to access"},"blocking":true,"tried":"retried the push once"}',
|
|
386
|
+
'type is one of environment, sandbox, tooling, prompt, forge-bug, other.',
|
|
387
|
+
'fixable_by is one of user, forge, unsure.',
|
|
388
|
+
'summary is one line. evidence is the command, its exit code and the error text',
|
|
389
|
+
'(keep the error under 2 KB). blocking is true when you could not finish without it.',
|
|
390
|
+
'tried is what you did before giving up. Omit the line when there is nothing to say.',
|
|
391
|
+
]
|
|
392
|
+
_RETRO_INBOX = [
|
|
393
|
+
'If a hard blocker hits before you can finish, append that same JSON object as one',
|
|
394
|
+
'line to .forge/retro-inbox.jsonl in this worktree, at that moment. .forge is already',
|
|
395
|
+
'excluded from diffs and commits.',
|
|
396
|
+
]
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
def retro_text(role: str) -> str:
|
|
400
|
+
"""The retro-note instruction for one role, newline-terminated."""
|
|
401
|
+
if role not in RETRO_ROLES:
|
|
402
|
+
raise ValueError('role must be one of ' + ', '.join(RETRO_ROLES))
|
|
403
|
+
lines = list(_RETRO)
|
|
404
|
+
if role == 'dwarf':
|
|
405
|
+
lines += [''] + _RETRO_INBOX
|
|
406
|
+
return '\n'.join(lines) + '\n'
|
|
407
|
+
|
|
408
|
+
|
|
309
409
|
def dwarf_text(pre_review: bool = False, verify_after_merge: bool = False) -> str:
|
|
310
410
|
"""The implementer rules block, newline-terminated."""
|
|
311
411
|
lines = []
|
|
@@ -319,7 +419,7 @@ def dwarf_text(pre_review: bool = False, verify_after_merge: bool = False) -> st
|
|
|
319
419
|
|
|
320
420
|
# --- parsing ---------------------------------------------------------------------
|
|
321
421
|
|
|
322
|
-
_PROTOCOL = re.compile(r'FORGE_(?:VERDICT|LEARNING|TESTS):.*$')
|
|
422
|
+
_PROTOCOL = re.compile(r'FORGE_(?:VERDICT|LEARNING|TESTS|RETRO|BLOCKED):.*$')
|
|
323
423
|
_QUOTE = re.compile(r'^\s*(?:>[ \t]?)+')
|
|
324
424
|
_MARKER = re.compile(r'^(?:[-*+•–]|\d{1,3}[.)]|#{1,6})\s+')
|
|
325
425
|
_HEADING = re.compile(r'^ {0,3}#{1,6}[ \t]+\S')
|
|
@@ -347,6 +447,8 @@ def _contract_flat() -> str:
|
|
|
347
447
|
for part in ('head', 'tail'):
|
|
348
448
|
for threshold in SEVERITIES: # None and `none` render one of these
|
|
349
449
|
parts.append(qa_text(part, kind, threshold))
|
|
450
|
+
for role in RETRO_ROLES: # an echoed retro instruction is not a finding either
|
|
451
|
+
parts.append(retro_text(role))
|
|
350
452
|
return _collapse(' '.join(parts))
|
|
351
453
|
|
|
352
454
|
|
|
@@ -431,25 +533,45 @@ def _finding(number: int, lines: list):
|
|
|
431
533
|
# when it names at least one of the three facts: a finding's own text may end in braces (`{}`, `{a=1}`).
|
|
432
534
|
_FACTS_SUFFIX = re.compile(r'[ \t]*[`*_]*\{([^{}\n]*)\}[`*_.]*[ \t]*$')
|
|
433
535
|
_FACT = re.compile(r'([A-Za-z]+)[ \t]*[=:][ \t]*([A-Za-z]+)')
|
|
536
|
+
# `{tasks=…}` and `{outside=…}` are their own braces. When either (or both, in either order)
|
|
537
|
+
# follows the facts, the facts group no longer closes the line. Cut every such trailing brace
|
|
538
|
+
# and try the facts suffix on what remains. A brace of either kind before the facts stays.
|
|
539
|
+
_ATTR_TAIL = re.compile(
|
|
540
|
+
r'(?:[ \t]*[`*_]*\{[ \t]*(?:tasks|outside)[ \t]*=[ \t]*[^{}\n]*\}[`*_.]*)+[ \t]*$',
|
|
541
|
+
re.IGNORECASE)
|
|
542
|
+
_OUTSIDE_TAG = re.compile(r'\{[ \t]*outside[ \t]*=[ \t]*([^{}]*)\}', re.IGNORECASE)
|
|
543
|
+
_PATH_SPLIT = re.compile(r'[\s,]+')
|
|
434
544
|
|
|
435
545
|
|
|
436
546
|
def split_facts(line: str):
|
|
437
547
|
"""(line without its facts suffix, {reach, origin, evidence}) or (line, None) when it has none.
|
|
438
548
|
|
|
439
549
|
A fact whose value is not one of its words reads None, and keys other than the three are ignored:
|
|
440
|
-
a malformed suffix is still cut from the line, so it never reaches a location or a title.
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
550
|
+
a malformed suffix is still cut from the line, so it never reaches a location or a title.
|
|
551
|
+
`{tasks=…}` or `{outside=…}` after the facts is not a facts suffix: those braces are cut, in
|
|
552
|
+
either order, and the facts are kept. Either brace before the facts stays on the returned line,
|
|
553
|
+
as it does when it is the only brace."""
|
|
554
|
+
original = line or ''
|
|
555
|
+
bodies = [original]
|
|
556
|
+
tail = _ATTR_TAIL.search(original)
|
|
557
|
+
if tail:
|
|
558
|
+
bodies.append(original[:tail.start()])
|
|
559
|
+
for body in bodies:
|
|
560
|
+
match = _FACTS_SUFFIX.search(body)
|
|
561
|
+
if not match:
|
|
562
|
+
continue
|
|
563
|
+
said = {key.lower(): value.lower() for key, value in _FACT.findall(match.group(1))}
|
|
564
|
+
if not any(key in said for key in FACTS):
|
|
565
|
+
continue
|
|
566
|
+
return body[:match.start()], {key: said[key] if said.get(key) in words else None
|
|
567
|
+
for key, words in FACTS.items()}
|
|
568
|
+
return original, None
|
|
449
569
|
|
|
450
570
|
|
|
451
571
|
def facts(text: str):
|
|
452
|
-
"""The facts of one finding block: its first line's suffix, else its last line's (a wrapped bullet).
|
|
572
|
+
"""The facts of one finding block: its first line's suffix, else its last line's (a wrapped bullet).
|
|
573
|
+
|
|
574
|
+
A `{tasks=…}` or `{outside=…}` brace after the facts does not hide them."""
|
|
453
575
|
lines = [line for line in (text or '').split('\n') if line.strip()]
|
|
454
576
|
for line in lines[:1] + lines[-1:]:
|
|
455
577
|
found = split_facts(line)[1]
|
|
@@ -458,6 +580,22 @@ def facts(text: str):
|
|
|
458
580
|
return None
|
|
459
581
|
|
|
460
582
|
|
|
583
|
+
def outside_paths(finding_text: str) -> list:
|
|
584
|
+
"""Paths of the last `{outside=…}` brace in a finding block, in the order written.
|
|
585
|
+
|
|
586
|
+
Paths are comma or space separated. Backticks and quotes are removed, and a repeated
|
|
587
|
+
path is dropped. No brace, or a brace that names no path, is an empty list."""
|
|
588
|
+
matches = list(_OUTSIDE_TAG.finditer(finding_text or ''))
|
|
589
|
+
if not matches:
|
|
590
|
+
return []
|
|
591
|
+
seen = []
|
|
592
|
+
for part in _PATH_SPLIT.split(matches[-1].group(1).strip()):
|
|
593
|
+
path = part.strip('`"\'')
|
|
594
|
+
if path and path not in seen:
|
|
595
|
+
seen.append(path)
|
|
596
|
+
return seen
|
|
597
|
+
|
|
598
|
+
|
|
461
599
|
def parse_findings(text: str) -> list:
|
|
462
600
|
"""Finding blocks of a QA reply, in order; see the module docstring for the rules."""
|
|
463
601
|
found = (_finding(start, lines) for start, _, lines in _blocks(_clean(text)))
|
|
@@ -466,6 +604,16 @@ def parse_findings(text: str) -> list:
|
|
|
466
604
|
|
|
467
605
|
# --- the gate --------------------------------------------------------------------
|
|
468
606
|
|
|
607
|
+
def finding_blocks(finding, threshold=None) -> bool:
|
|
608
|
+
"""Whether one finding blocks at the threshold: the gate's per-finding rule.
|
|
609
|
+
|
|
610
|
+
CONFIRMED or UNSTATED blocks when it has no severity, or a severity at the threshold
|
|
611
|
+
or worse. PLAUSIBLE never blocks. `none` is P3, and an empty threshold is the default."""
|
|
612
|
+
rank = _rank(threshold)
|
|
613
|
+
return (finding.status in ('CONFIRMED', 'UNSTATED')
|
|
614
|
+
and (finding.severity is None or finding.severity <= rank))
|
|
615
|
+
|
|
616
|
+
|
|
469
617
|
def gate(verdict: str, text: str, threshold=None) -> GateResult:
|
|
470
618
|
"""Check a QA verdict against its findings: a FAIL may be accepted as
|
|
471
619
|
PASS-with-known-issues, a PASS that lists a blocking finding fails."""
|
|
@@ -477,8 +625,7 @@ def gate(verdict: str, text: str, threshold=None) -> GateResult:
|
|
|
477
625
|
+ sum(1 for f in findings if f.status == 'UNSTATED'))
|
|
478
626
|
worst = 'P%d' % min(f.severity for f in labelled) if labelled else '-'
|
|
479
627
|
below = tuple(f for f in labelled if f.severity > rank)
|
|
480
|
-
blocking = any(f
|
|
481
|
-
and (f.severity is None or f.severity <= rank) for f in findings)
|
|
628
|
+
blocking = any(finding_blocks(f, threshold) for f in findings)
|
|
482
629
|
if verdict == 'PASS' and blocking:
|
|
483
630
|
decision = 'fail'
|
|
484
631
|
elif (verdict == 'FAIL' and confirmed and unlabelled == 0
|
|
@@ -504,6 +651,32 @@ def _tests_reason(text: str) -> str | None:
|
|
|
504
651
|
return ''.join(ch for ch in text.strip(_TESTS_TRIM) if ch.isprintable())[:_TESTS_REASON_MAX] or None
|
|
505
652
|
|
|
506
653
|
|
|
654
|
+
# An implementer's report that a fix lives outside the task's files (#149). Same leading
|
|
655
|
+
# markdown as a FORGE_TESTS line. The why may be empty; a repeated path keeps the first.
|
|
656
|
+
_BLOCKED_LINE = re.compile(r'^[ \t>*_`+-]*FORGE_BLOCKED:[ \t*_`]*(.*?)[ \t*_`]*$', re.M)
|
|
657
|
+
|
|
658
|
+
|
|
659
|
+
def blocked_lines(message: str) -> list:
|
|
660
|
+
"""`(path, why)` for every `FORGE_BLOCKED: <path>: <why>` line, in order.
|
|
661
|
+
|
|
662
|
+
Leading markdown (`-`, `*`, `>`, backticks) is ignored. The why may be empty.
|
|
663
|
+
A repeated path keeps the first line."""
|
|
664
|
+
found = []
|
|
665
|
+
seen = set()
|
|
666
|
+
text = (message or '').replace('\r\n', '\n').replace('\r', '\n')
|
|
667
|
+
for raw in _BLOCKED_LINE.findall(text):
|
|
668
|
+
if ':' not in raw:
|
|
669
|
+
continue
|
|
670
|
+
path, why = raw.split(':', 1)
|
|
671
|
+
path = path.strip().strip('`"\'')
|
|
672
|
+
why = why.strip()
|
|
673
|
+
if not path or path in seen:
|
|
674
|
+
continue
|
|
675
|
+
seen.add(path)
|
|
676
|
+
found.append((path, why))
|
|
677
|
+
return found
|
|
678
|
+
|
|
679
|
+
|
|
507
680
|
def tests_report(text) -> dict | None:
|
|
508
681
|
"""{status: ran|not_needed|could_not_run|unclear, reason} from a QA reply, or None when it does not say."""
|
|
509
682
|
report = None
|
|
@@ -518,6 +691,20 @@ def tests_report(text) -> dict | None:
|
|
|
518
691
|
return report
|
|
519
692
|
|
|
520
693
|
|
|
694
|
+
def outside_report(text: str, threshold=None) -> list:
|
|
695
|
+
"""One object per parsed finding: n, severity, status, blocking, outside paths."""
|
|
696
|
+
rows = []
|
|
697
|
+
for number, finding in enumerate(parse_findings(text or ''), 1):
|
|
698
|
+
rows.append({
|
|
699
|
+
'n': number,
|
|
700
|
+
'severity': None if finding.severity is None else 'P%d' % finding.severity,
|
|
701
|
+
'status': finding.status,
|
|
702
|
+
'blocking': finding_blocks(finding, threshold),
|
|
703
|
+
'outside': outside_paths(finding.text),
|
|
704
|
+
})
|
|
705
|
+
return rows
|
|
706
|
+
|
|
707
|
+
|
|
521
708
|
def known_issues_text(threshold, tolerated) -> str:
|
|
522
709
|
name = SEVERITIES[_rank(threshold)]
|
|
523
710
|
lines = ['## Known issues (QA findings below blocking threshold %s)' % name, '',
|
|
@@ -545,6 +732,20 @@ def _emit(text: str) -> None:
|
|
|
545
732
|
sys.stdout.buffer.flush()
|
|
546
733
|
|
|
547
734
|
|
|
735
|
+
def _emit_json(data) -> None:
|
|
736
|
+
_emit(json.dumps(data, indent=2, ensure_ascii=False) + '\n')
|
|
737
|
+
|
|
738
|
+
|
|
739
|
+
def _read_text(path: str):
|
|
740
|
+
"""The file's text, or None when it cannot be read (the caller exits 3)."""
|
|
741
|
+
try:
|
|
742
|
+
with open(path, 'rb') as handle:
|
|
743
|
+
return handle.read().decode('utf-8', 'replace')
|
|
744
|
+
except OSError as error:
|
|
745
|
+
sys.stderr.write('forge-contract: cannot read %s: %s\n' % (path, error))
|
|
746
|
+
return None
|
|
747
|
+
|
|
748
|
+
|
|
548
749
|
def _parser() -> argparse.ArgumentParser:
|
|
549
750
|
parser = argparse.ArgumentParser(
|
|
550
751
|
prog='forge-contract.py', formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
@@ -560,13 +761,17 @@ def _parser() -> argparse.ArgumentParser:
|
|
|
560
761
|
help='head = review preamble, tail = findings format + verdict contract')
|
|
561
762
|
qa.add_argument('--kind', choices=KINDS, default='task',
|
|
562
763
|
help='task (default), final (whole-run review), solo (solo wording), sweep (a finding '
|
|
563
|
-
'sweep task: per-finding FIXED lines, regressions only)
|
|
764
|
+
'sweep task: per-finding FIXED lines, regressions only), adopt (a range made outside '
|
|
765
|
+
'forge) or group (one review over several tasks; attribute each finding)')
|
|
564
766
|
qa.add_argument('--threshold', type=_threshold_arg, default=None, metavar='P0..P3|none',
|
|
565
767
|
help='least severe level that still blocks; none = P3 (default: %s)' % DEFAULT_THRESHOLD)
|
|
566
768
|
dwarf = sub.add_parser('dwarf', help='print the implementer rules block')
|
|
567
769
|
dwarf.add_argument('--pre-review', action='store_true', help='forge runs the affected tests before the review')
|
|
568
770
|
dwarf.add_argument('--verify-after-merge', action='store_true',
|
|
569
771
|
help='the run verifies the repository after each merge, so the whole suite is left to it')
|
|
772
|
+
retro = sub.add_parser('retro', help='print the retro-note instruction for one role')
|
|
773
|
+
retro.add_argument('--role', required=True, choices=RETRO_ROLES,
|
|
774
|
+
help='dwarf also hears about .forge/retro-inbox.jsonl')
|
|
570
775
|
gate_parser = sub.add_parser(
|
|
571
776
|
'gate', help='print: decision (accept|fail|keep), worst_confirmed, n_confirmed, n_unlabelled, n_below')
|
|
572
777
|
gate_parser.add_argument('--verdict', required=True, choices=('PASS', 'FAIL', 'UNKNOWN'))
|
|
@@ -578,6 +783,13 @@ def _parser() -> argparse.ArgumentParser:
|
|
|
578
783
|
help='write tolerated findings here when there are any')
|
|
579
784
|
tests = sub.add_parser('tests', help='print what the reply says about its tests: status, a tab, the reason')
|
|
580
785
|
tests.add_argument('--qa-last', required=True, metavar='FILE', help='the QA reply')
|
|
786
|
+
outside = sub.add_parser('outside', help='print each finding\'s outside paths as JSON')
|
|
787
|
+
outside.add_argument('--qa-last', required=True, metavar='FILE', help='the QA reply')
|
|
788
|
+
outside.add_argument('--threshold', type=_threshold_arg, default=None, metavar='P0..P3|none',
|
|
789
|
+
help='least severe level that still blocks; none = P3 (default: %s)'
|
|
790
|
+
% DEFAULT_THRESHOLD)
|
|
791
|
+
blocked = sub.add_parser('blocked', help='print FORGE_BLOCKED lines from an implementer message')
|
|
792
|
+
blocked.add_argument('--message', required=True, metavar='FILE', help='the implementer message')
|
|
581
793
|
return parser
|
|
582
794
|
|
|
583
795
|
|
|
@@ -589,17 +801,23 @@ def main(argv=None) -> int:
|
|
|
589
801
|
if args.command == 'dwarf':
|
|
590
802
|
_emit(dwarf_text(args.pre_review, args.verify_after_merge))
|
|
591
803
|
return 0
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
804
|
+
if args.command == 'retro':
|
|
805
|
+
_emit(retro_text(args.role))
|
|
806
|
+
return 0
|
|
807
|
+
text = _read_text(args.message if args.command == 'blocked' else args.qa_last)
|
|
808
|
+
if text is None:
|
|
597
809
|
return 3
|
|
598
810
|
if args.command == 'tests':
|
|
599
811
|
report = tests_report(text)
|
|
600
812
|
if report:
|
|
601
813
|
_emit('%s\t%s\n' % (report['status'], report['reason'] or ''))
|
|
602
814
|
return 0
|
|
815
|
+
if args.command == 'outside':
|
|
816
|
+
_emit_json(outside_report(text, args.threshold))
|
|
817
|
+
return 0
|
|
818
|
+
if args.command == 'blocked':
|
|
819
|
+
_emit_json([{'path': path, 'why': why} for path, why in blocked_lines(text)])
|
|
820
|
+
return 0
|
|
603
821
|
result = gate(args.verdict, text, args.threshold)
|
|
604
822
|
if args.known_issues and result.n_below >= 1:
|
|
605
823
|
temporary = args.known_issues + '.%d.tmp' % os.getpid()
|