@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
|
@@ -86,6 +86,16 @@ ADDED_COLUMNS = (('code_sha', 'TEXT'), ('forge_rev', 'TEXT'))
|
|
|
86
86
|
PROVENANCE = ('forge_version', 'registry_sha', 'code_sha', 'forge_rev')
|
|
87
87
|
|
|
88
88
|
|
|
89
|
+
def is_side_role(role) -> bool:
|
|
90
|
+
"""True for a harvested side dispatch (`side_brief`, `side_summary`, any `side_*`).
|
|
91
|
+
|
|
92
|
+
The files on disk stay `side.*`; harvest records the kind in the role so attempt
|
|
93
|
+
statistics can leave the dispatch out. A bare `side` is the dispatch role, not one
|
|
94
|
+
of these.
|
|
95
|
+
"""
|
|
96
|
+
return isinstance(role, str) and role.startswith('side_')
|
|
97
|
+
|
|
98
|
+
|
|
89
99
|
def enabled() -> bool:
|
|
90
100
|
return os.environ.get('FORGE_DATASET', 'on').strip().lower() not in OFF
|
|
91
101
|
|
|
@@ -184,13 +184,14 @@ def plan_notes(plan) -> list:
|
|
|
184
184
|
"""`note:` lines for the distinct slow specs in a plan's dwarf and qa columns.
|
|
185
185
|
|
|
186
186
|
After routing, tasks.tsv holds concrete specs. The same spec twice is one line. A
|
|
187
|
-
missing table prints nothing.
|
|
187
|
+
missing table prints nothing. A dwarf cell of `script` is a task kind, not a model spec.
|
|
188
188
|
"""
|
|
189
189
|
from .harvest import tasks_rows
|
|
190
190
|
seen, out = set(), []
|
|
191
191
|
for row in tasks_rows(Path(plan) / 'tasks.tsv').values():
|
|
192
|
-
|
|
193
|
-
|
|
192
|
+
dwarf = (row.get('dwarf') or '').strip()
|
|
193
|
+
qa = (row.get('qa') or '').strip()
|
|
194
|
+
for spec in (('' if dwarf == 'script' else dwarf), qa):
|
|
194
195
|
if not spec or spec == '-' or spec in seen:
|
|
195
196
|
continue
|
|
196
197
|
seen.add(spec)
|
|
@@ -32,7 +32,7 @@ import time
|
|
|
32
32
|
from collections import Counter, defaultdict
|
|
33
33
|
from pathlib import Path
|
|
34
34
|
|
|
35
|
-
from . import SKILL, connect, data_home, read_blob
|
|
35
|
+
from . import SKILL, connect, data_home, is_side_role, read_blob
|
|
36
36
|
from .harvest import review_completeness
|
|
37
37
|
from .states import assemble, retry, siblings, task_size
|
|
38
38
|
|
|
@@ -239,7 +239,9 @@ class Runs:
|
|
|
239
239
|
rows.sort(key=lambda e: (e['attempt'] or 0, e['d'].get('wall_started') or e['ts']))
|
|
240
240
|
self.dispatches = defaultdict(list)
|
|
241
241
|
for e in store.of('dispatch'):
|
|
242
|
-
|
|
242
|
+
# A group review names no task. scope group stays out of per-task indexes even
|
|
243
|
+
# if a task was recorded, the way a side dispatch stays out of attempt statistics.
|
|
244
|
+
if e['task'] and e['d'].get('scope') != 'group':
|
|
243
245
|
self.dispatches[(e['run'], e['task'], e['d'].get('role'))].append(e)
|
|
244
246
|
# Store order is import order. A reader that takes [-1] means the dispatch
|
|
245
247
|
# the attempt ended on, so each list is chronological; a tie keeps store order.
|
|
@@ -328,15 +330,18 @@ def _siblings(plan, task_id) -> list:
|
|
|
328
330
|
def _attempts(runs: Runs, run, task, rows) -> list:
|
|
329
331
|
"""One entry per real attempt number, oldest first: {n, events, outcome, reason}.
|
|
330
332
|
|
|
331
|
-
Refunded and infra-stopped executions spent no attempt.
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
333
|
+
Refunded and infra-stopped executions spent no attempt. So did one whose prompt or
|
|
334
|
+
approach changed while it ran (`prompt_changed`): the plan moved, not the implementer.
|
|
335
|
+
A row stored before that field exists has no key and is counted, the same as an
|
|
336
|
+
explicit false. A QA-only rerun keeps its attempt's number, so the number's last
|
|
337
|
+
execution holds its final status. outcome is True or False, or None when the attempt
|
|
338
|
+
says nothing about the implementer (reason names why): a later success must never be
|
|
339
|
+
labeled as the first attempt's.
|
|
335
340
|
"""
|
|
336
341
|
by_n = {}
|
|
337
342
|
for e in rows:
|
|
338
343
|
d = e['d']
|
|
339
|
-
if d.get('refunded') or d.get('infra') or not d.get('status'):
|
|
344
|
+
if d.get('refunded') or d.get('infra') or d.get('prompt_changed') or not d.get('status'):
|
|
340
345
|
continue
|
|
341
346
|
by_n.setdefault(e['attempt'] or 0, []).append(e)
|
|
342
347
|
out = []
|
|
@@ -586,6 +591,21 @@ def _ending_qa(rows) -> dict:
|
|
|
586
591
|
return ending
|
|
587
592
|
|
|
588
593
|
|
|
594
|
+
def not_an_attempt(role, data=None) -> bool:
|
|
595
|
+
"""A shadow review, a side dispatch, or a group review: tokens stay, attempt statistics do not.
|
|
596
|
+
|
|
597
|
+
`qa_shadow` is the second reviewer. A harvested side call is `side_<kind>`
|
|
598
|
+
(`is_side_role`); the dir on disk, and a side dispatch harvested outside
|
|
599
|
+
`side/<kind>/`, keeps the role `side`. A group review is one QA dispatch for
|
|
600
|
+
several tasks (`scope` `group`); it is not any one task's review. `data` is the
|
|
601
|
+
dispatch's data, when the caller has it. None of these is the review of record.
|
|
602
|
+
Shadow agreement still reads `qa_shadow`. This does not drop the dispatch's tokens.
|
|
603
|
+
"""
|
|
604
|
+
if role == 'qa_shadow' or role == 'side' or is_side_role(role):
|
|
605
|
+
return True
|
|
606
|
+
return isinstance(data, dict) and data.get('scope') == 'group'
|
|
607
|
+
|
|
608
|
+
|
|
589
609
|
def _qa_rows(runs: Runs):
|
|
590
610
|
"""Every independent QA dispatch with a verdict, with the diff it was shown and its task text.
|
|
591
611
|
|
|
@@ -610,13 +630,17 @@ def _qa_rows(runs: Runs):
|
|
|
610
630
|
word, _, conf = text.strip().partition('\t')
|
|
611
631
|
effort[(run, task, e['attempt'])] = (word, _float(conf))
|
|
612
632
|
for (run, task, role), rows in runs.dispatches.items():
|
|
613
|
-
|
|
633
|
+
# The review of record only. A shadow pair is selected below; a side dispatch, and a
|
|
634
|
+
# group review of several tasks, is not a row.
|
|
635
|
+
if not_an_attempt(role) or role != 'qa':
|
|
614
636
|
continue
|
|
615
637
|
ending = _ending_qa(rows)
|
|
616
638
|
for index, e in enumerate(rows):
|
|
617
639
|
if session_continued(e):
|
|
618
640
|
continue
|
|
619
641
|
d = e['d']
|
|
642
|
+
if not_an_attempt(role, d):
|
|
643
|
+
continue
|
|
620
644
|
if d.get('verdict') not in ('PASS', 'FAIL'):
|
|
621
645
|
continue
|
|
622
646
|
prompt = store.text((d.get('blobs') or {}).get('prompt'))
|
|
@@ -672,7 +696,8 @@ def shadow_pairs(runs: Runs) -> dict:
|
|
|
672
696
|
ended[(e['run'], e['task'], _int(e['d'].get('attempt')))] = e['d'].get('status')
|
|
673
697
|
out = {}
|
|
674
698
|
for (run, task, role), rows in runs.dispatches.items():
|
|
675
|
-
|
|
699
|
+
# Selects the shadow reviewer. A side role is not `qa_shadow`, so it is not a pair.
|
|
700
|
+
if role != 'qa_shadow' or is_side_role(role):
|
|
676
701
|
continue
|
|
677
702
|
for shadow in rows:
|
|
678
703
|
n = shadow['attempt']
|
|
@@ -700,7 +725,8 @@ def agreement(runs: Runs) -> dict:
|
|
|
700
725
|
key = '%s vs %s' % (primary['d'].get('model'), shadow['d'].get('model'))
|
|
701
726
|
by_pair[key][0] += 1
|
|
702
727
|
by_pair[key][1] += primary['d']['verdict'] == shadow['d']['verdict']
|
|
703
|
-
shadows = sum(len(rows) for (_, _, role), rows in runs.dispatches.items()
|
|
728
|
+
shadows = sum(len(rows) for (_, _, role), rows in runs.dispatches.items()
|
|
729
|
+
if role == 'qa_shadow' and not is_side_role(role))
|
|
704
730
|
agree = sum(a for _, a in by_pair.values())
|
|
705
731
|
return dict(shadow_reviews=shadows, pairs=len(pairs), agree=agree,
|
|
706
732
|
by_pair={k: dict(pairs=n, agree=a) for k, (n, a) in sorted(by_pair.items())})
|
|
@@ -28,8 +28,8 @@ import re
|
|
|
28
28
|
import sys
|
|
29
29
|
from collections import Counter, defaultdict
|
|
30
30
|
|
|
31
|
-
from . import connect, dataset_dir
|
|
32
|
-
from .export import Runs, Store, _ending_qa, _gate_decision, shadow_pairs
|
|
31
|
+
from . import connect, dataset_dir, is_side_role
|
|
32
|
+
from .export import Runs, Store, _ending_qa, _gate_decision, not_an_attempt, shadow_pairs
|
|
33
33
|
|
|
34
34
|
FACTS = {'reach': ('main', 'realistic', 'unusual'), 'origin': ('new', 'existing'),
|
|
35
35
|
'evidence': ('ran', 'traced', 'suspected')}
|
|
@@ -156,7 +156,11 @@ def report(runs: Runs, repo: str = None) -> dict:
|
|
|
156
156
|
by_sev = defaultdict(Counter)
|
|
157
157
|
for e in runs.store.of('dispatch'):
|
|
158
158
|
d = e['d']
|
|
159
|
-
|
|
159
|
+
role = d.get('role')
|
|
160
|
+
# qa and qa_shadow are reviews. A side dispatch is neither, even when it carries a
|
|
161
|
+
# findings list. A group review is one dispatch for several tasks, not one review.
|
|
162
|
+
if (role not in ('qa', 'qa_shadow') or is_side_role(role) or d.get('scope') == 'group'
|
|
163
|
+
or not mine(e) or not isinstance(d.get('findings'), list)):
|
|
160
164
|
continue
|
|
161
165
|
found = [f for f in d['findings'] if isinstance(f, dict)]
|
|
162
166
|
cov['reviews'] += 1
|
|
@@ -194,7 +198,7 @@ def report(runs: Runs, repo: str = None) -> dict:
|
|
|
194
198
|
|
|
195
199
|
rules = out['rules']
|
|
196
200
|
for (run, task, role), rows in runs.dispatches.items():
|
|
197
|
-
if role
|
|
201
|
+
if not rows or not_an_attempt(role, rows[0].get('d')) or role != 'qa' or not mine(rows[0]):
|
|
198
202
|
continue
|
|
199
203
|
ended = sorted(_ending_qa(rows).items(), key=lambda item: item[0] or 0)
|
|
200
204
|
attempts = [n for n, _ in ended]
|
|
@@ -33,6 +33,7 @@ from pathlib import Path
|
|
|
33
33
|
|
|
34
34
|
from . import SKILL, connect, dataset_dir, record
|
|
35
35
|
from .export import Runs, Store
|
|
36
|
+
from .names import registry_models # noqa: F401 (forge-route, forge-compare and efforts import it from here)
|
|
36
37
|
from .routing import tasks as routing_tasks, wilson
|
|
37
38
|
|
|
38
39
|
MIN_HISTORY = 5
|
|
@@ -43,23 +44,6 @@ OFF = {'0', 'off', 'false', 'no'}
|
|
|
43
44
|
|
|
44
45
|
# --- the registry, as forge-route.py reads it (that module's name is not importable) ---
|
|
45
46
|
|
|
46
|
-
def registry_models() -> dict:
|
|
47
|
-
"""{alias: {harness: model id}}; the first row of an alias is its default."""
|
|
48
|
-
out = {}
|
|
49
|
-
path = Path(os.environ.get('FORGE_REGISTRY') or str(SKILL / 'registry.tsv'))
|
|
50
|
-
try:
|
|
51
|
-
lines = path.read_text().splitlines()
|
|
52
|
-
except OSError:
|
|
53
|
-
return out
|
|
54
|
-
for line in lines:
|
|
55
|
-
if not line.strip() or line.startswith('#'):
|
|
56
|
-
continue
|
|
57
|
-
cells = line.split('\t')
|
|
58
|
-
if len(cells) >= 3:
|
|
59
|
-
out.setdefault(cells[0], {}).setdefault(cells[1], cells[2])
|
|
60
|
-
return out
|
|
61
|
-
|
|
62
|
-
|
|
63
47
|
def resolve(spec, registry: dict) -> tuple:
|
|
64
48
|
"""(model id, effort or None) a dwarf spec such as `sol`, `sol:high` or `sol:high:codex` runs."""
|
|
65
49
|
parts = str(spec or '').split(':')
|
|
@@ -86,13 +70,19 @@ def _tsv(path: Path) -> list:
|
|
|
86
70
|
|
|
87
71
|
|
|
88
72
|
def plan_tasks(plan: Path) -> tuple:
|
|
89
|
-
"""([task dicts to forecast], [ids already merged]) from tasks.tsv (declared tier when kept).
|
|
73
|
+
"""([task dicts to forecast], [ids already merged]) from tasks.tsv (declared tier when kept).
|
|
74
|
+
|
|
75
|
+
A dwarf cell of `script` is a task that runs `tasks/<id>/run`, not a model to price. Those
|
|
76
|
+
rows are left out of both lists: not forecast, and not reported as already merged.
|
|
77
|
+
"""
|
|
90
78
|
declared = {r['id']: r for r in _tsv(plan / 'tasks.declared.tsv')}
|
|
91
79
|
out, merged = [], []
|
|
92
80
|
for row in _tsv(plan / 'tasks.tsv'):
|
|
93
81
|
tid = row.get('id')
|
|
94
82
|
if not tid:
|
|
95
83
|
continue
|
|
84
|
+
if (row.get('dwarf') or '').strip() == 'script':
|
|
85
|
+
continue
|
|
96
86
|
if (plan / 'tasks' / tid / 'merged').exists():
|
|
97
87
|
merged.append(tid)
|
|
98
88
|
continue
|
|
@@ -25,13 +25,18 @@ from pathlib import Path
|
|
|
25
25
|
|
|
26
26
|
from . import SCRIPTS, put_blob, put_file, sha256
|
|
27
27
|
|
|
28
|
-
DISPATCH_ROLES = ('dwarf', 'qa', 'planner')
|
|
29
|
-
|
|
28
|
+
DISPATCH_ROLES = ('dwarf', 'qa', 'planner', 'side')
|
|
29
|
+
# The file role stays `side`. Harvest records side_<kind> (see dispatch_event);
|
|
30
|
+
# attempt statistics tell those apart with forge_dataset.is_side_role.
|
|
31
|
+
# `script` is tasks/<id>/run, not a model dispatch. Import and live capture treat
|
|
32
|
+
# attempts/script-* as a pipeline execution, so events_for records no dispatch for it.
|
|
33
|
+
PIPELINE_ROLES = ('task', 'solo', 'verification', 'parallel', 'script')
|
|
30
34
|
TASKS_COLS = ('id', 'deps', 'difficulty', 'files', 'dwarf', 'qa', 'title')
|
|
31
35
|
STRUCTURED = ('codex', 'claude', 'openclaude', 'grok', 'opencode') # as forge-runtime.py's: .last is the message, not the log
|
|
32
36
|
# Plan files that change what a plan decides, added to its rid only when present (see plan_event).
|
|
33
|
-
PLAN_RID_LATER = ('decompose_level', 'shadow_qa', 'shadow_rate', 'explore', 'reviewer_session',
|
|
34
|
-
'implementer_session', 'pre_review_tests'
|
|
37
|
+
PLAN_RID_LATER = ('decompose_level', 'shadow_qa', 'shadow_rate', 'explore', 'reviewer_session', 'reviewer_session_rate',
|
|
38
|
+
'implementer_session', 'pre_review_tests', 'retro_mode', 'brief', 'brief_scope', 'brief_model',
|
|
39
|
+
'summaries', 'summaries_model', 'retry_per_model')
|
|
35
40
|
|
|
36
41
|
# Files a task or solo execution may write. begin() snapshots their signatures so
|
|
37
42
|
# finish() can tell this execution's outputs from what an earlier one left behind.
|
|
@@ -47,6 +52,7 @@ WATCHED = (
|
|
|
47
52
|
'verification.lanes.json', 'results.tsv',
|
|
48
53
|
'prereview.failed', 'bounced', 'message.failed', 'needs_input.md', 'lateral.tsv',
|
|
49
54
|
'decision.md', 'decisions.tsv', 'ledger.tsv',
|
|
55
|
+
'prompt.md', 'approach.md', 'prompt.dispatched', 'approach.dispatched', 'stale.diff',
|
|
50
56
|
)
|
|
51
57
|
|
|
52
58
|
# The markers of an attempt forge sent back without a review, and the kind each one records.
|
|
@@ -315,6 +321,18 @@ def locate(root: str | Path, role: str | None = None) -> dict:
|
|
|
315
321
|
if p.parent.parent.name == 'shadow' and (p.parent.parent.parent / 'tasks.tsv').exists():
|
|
316
322
|
# <plan>/shadow/<task>/<attempt>-<k>: a shadow review (forge-shadow.py) of that task.
|
|
317
323
|
plan, ctx['task'], ctx['scope'], ctx['shadow'] = p.parent.parent.parent, p.parent.name, 'task', True
|
|
324
|
+
elif p.parent.parent.parent.name == 'side' and (p.parent.parent.parent.parent / 'tasks.tsv').exists():
|
|
325
|
+
# <plan>/side/<kind>/<task>/<n>: a side dispatch (brief or summary) of that task.
|
|
326
|
+
# The role is recorded as side_<kind> (see dispatch_event), the way a shadow
|
|
327
|
+
# review is recorded as qa_shadow. n counts dispatches; it is not the attempt.
|
|
328
|
+
kind = p.parent.parent.name
|
|
329
|
+
plan, ctx['task'], ctx['scope'], ctx['side'] = (
|
|
330
|
+
p.parent.parent.parent.parent, p.parent.name, 'task', kind)
|
|
331
|
+
elif p.parent.name == 'groups' and (p.parent.parent / 'tasks.tsv').exists():
|
|
332
|
+
# <plan>/groups/<gid>: one QA dispatch for a review=group group. Not a task.
|
|
333
|
+
# Checked after shadow and side, and before a name prefix (final-review-*,
|
|
334
|
+
# integrate-*), so a group id with one of those names stays a group.
|
|
335
|
+
plan, ctx['task'], ctx['scope'], ctx['group'] = p.parent.parent, None, 'group', p.name
|
|
318
336
|
elif p.parent.name == 'tasks' and (p.parent.parent / 'tasks.tsv').exists():
|
|
319
337
|
plan, ctx['task'], ctx['scope'] = p.parent.parent, p.name, 'task'
|
|
320
338
|
elif p.name.startswith('final-review-') and (p.parent / 'tasks.tsv').exists():
|
|
@@ -423,6 +441,164 @@ def session_record(attempt: Path, role: str, metrics: dict) -> tuple[str | None,
|
|
|
423
441
|
return recorded, 'continued' if kv(path).get('mode') == 'continued' else 'failed'
|
|
424
442
|
|
|
425
443
|
|
|
444
|
+
def side_kind(root: Path, role: str, prov: dict | None = None) -> str | None:
|
|
445
|
+
"""The kind of a side dispatch (`brief`, `summary`), or None when this is not one.
|
|
446
|
+
|
|
447
|
+
The files stay `side.*`. The kind lives in the directory `<plan>/side/<kind>/...`
|
|
448
|
+
and, when a caller already knows it, in prov['side'].
|
|
449
|
+
"""
|
|
450
|
+
if role != 'side':
|
|
451
|
+
return None
|
|
452
|
+
recorded = (prov or {}).get('side')
|
|
453
|
+
if isinstance(recorded, str) and recorded and '/' not in recorded and recorded not in ('.', '..'):
|
|
454
|
+
return recorded
|
|
455
|
+
return locate(root, role).get('side')
|
|
456
|
+
|
|
457
|
+
|
|
458
|
+
def group_members(plan: Path, gid: str) -> list:
|
|
459
|
+
"""Task ids of `gid` in groups.tsv, in file order. Empty when the group is absent."""
|
|
460
|
+
for line in (text(plan / 'groups.tsv') or '').splitlines():
|
|
461
|
+
if not line.strip() or line.startswith('#'):
|
|
462
|
+
continue
|
|
463
|
+
cells = line.split('\t')
|
|
464
|
+
if len(cells) < 4 or cells[0] != gid:
|
|
465
|
+
continue
|
|
466
|
+
raw = cells[3].strip()
|
|
467
|
+
if raw in ('', '-'):
|
|
468
|
+
return []
|
|
469
|
+
return [item.strip() for item in raw.split(',') if item.strip() and item.strip() != '-']
|
|
470
|
+
return []
|
|
471
|
+
|
|
472
|
+
|
|
473
|
+
def member_rows(group_dir: Path) -> list:
|
|
474
|
+
"""members.tsv rows: round, task, reviewed commit, attempt. One row per member per round."""
|
|
475
|
+
rows = []
|
|
476
|
+
for line in (text(group_dir / 'members.tsv') or '').splitlines():
|
|
477
|
+
if not line.strip() or line.startswith('#'):
|
|
478
|
+
continue
|
|
479
|
+
cells = line.split('\t')
|
|
480
|
+
if len(cells) < 4 or not cells[0].isdigit():
|
|
481
|
+
continue
|
|
482
|
+
rows.append(dict(round=int(cells[0]), task=cells[1], commit=cells[2], attempt=as_int(cells[3])))
|
|
483
|
+
return rows
|
|
484
|
+
|
|
485
|
+
|
|
486
|
+
def _group_rounds(rows: list) -> list:
|
|
487
|
+
rounds = []
|
|
488
|
+
for row in rows:
|
|
489
|
+
if row['round'] not in rounds:
|
|
490
|
+
rounds.append(row['round'])
|
|
491
|
+
return rounds
|
|
492
|
+
|
|
493
|
+
|
|
494
|
+
def group_qa_attempts(group_dir: Path) -> list:
|
|
495
|
+
"""QA attempt dirs under a group root, oldest first."""
|
|
496
|
+
attempts = [path for path in (group_dir / 'attempts').glob('qa-*') if path.is_dir()]
|
|
497
|
+
|
|
498
|
+
def started(path: Path):
|
|
499
|
+
return ((read_json(path / 'metrics.json') or {}).get('wall_started') or 0, path.name)
|
|
500
|
+
|
|
501
|
+
return sorted(attempts, key=started)
|
|
502
|
+
|
|
503
|
+
|
|
504
|
+
def assign_group_rounds(group_dir: Path) -> dict:
|
|
505
|
+
"""qa attempt dir name -> round, for an import. The round file is not the source.
|
|
506
|
+
|
|
507
|
+
The file is incremented when the next round starts, so it may already name a round
|
|
508
|
+
this dispatch did not review. members.tsv names the rounds that built a candidate.
|
|
509
|
+
A dispatch that recorded its round (`group.round`, written by `_group` since the
|
|
510
|
+
dispatch ended) is that round's. For the others: a reply copied to qa.round-<n>.last
|
|
511
|
+
is that round's; remaining dispatches zip onto the rounds that have such a file, or
|
|
512
|
+
onto every members.tsv round when none does. An oversized round writes members.tsv
|
|
513
|
+
and no reply, so it takes no dispatch.
|
|
514
|
+
"""
|
|
515
|
+
rounds = _group_rounds(member_rows(group_dir))
|
|
516
|
+
assignment = {}
|
|
517
|
+
used = set()
|
|
518
|
+
unmatched = []
|
|
519
|
+
attempts = []
|
|
520
|
+
for attempt in group_qa_attempts(group_dir):
|
|
521
|
+
recorded = (text(attempt / 'group.round') or '').strip()
|
|
522
|
+
if recorded.isdigit():
|
|
523
|
+
assignment[attempt.name] = int(recorded)
|
|
524
|
+
used.add(int(recorded))
|
|
525
|
+
else:
|
|
526
|
+
attempts.append(attempt)
|
|
527
|
+
for attempt in attempts:
|
|
528
|
+
last = text(attempt / 'qa.last')
|
|
529
|
+
matched = None
|
|
530
|
+
if last is not None:
|
|
531
|
+
for number in rounds:
|
|
532
|
+
if number in used:
|
|
533
|
+
continue
|
|
534
|
+
copy = group_dir / ('qa.round-%d.last' % number)
|
|
535
|
+
if copy.is_file() and text(copy) == last:
|
|
536
|
+
matched = number
|
|
537
|
+
break
|
|
538
|
+
if matched is None:
|
|
539
|
+
unmatched.append(attempt)
|
|
540
|
+
else:
|
|
541
|
+
assignment[attempt.name] = matched
|
|
542
|
+
used.add(matched)
|
|
543
|
+
reviewed = [number for number in rounds if (group_dir / ('qa.round-%d.last' % number)).is_file()]
|
|
544
|
+
pool = [number for number in (reviewed or rounds) if number not in used]
|
|
545
|
+
for attempt, number in zip(unmatched, pool):
|
|
546
|
+
assignment[attempt.name] = number
|
|
547
|
+
return assignment
|
|
548
|
+
|
|
549
|
+
|
|
550
|
+
def group_judgments(plan: Path) -> dict:
|
|
551
|
+
"""(task id, attempt number) -> {group, round} for attempts a group QA dispatch judged.
|
|
552
|
+
|
|
553
|
+
A members.tsv row whose round has no QA dispatch did not judge. The latest judged
|
|
554
|
+
round for a pair wins.
|
|
555
|
+
"""
|
|
556
|
+
judged = {}
|
|
557
|
+
groups = Path(plan) / 'groups'
|
|
558
|
+
if not groups.is_dir():
|
|
559
|
+
return judged
|
|
560
|
+
for group_dir in sorted(path for path in groups.iterdir() if path.is_dir()):
|
|
561
|
+
assigned = set(assign_group_rounds(group_dir).values())
|
|
562
|
+
if not assigned:
|
|
563
|
+
continue
|
|
564
|
+
for row in member_rows(group_dir):
|
|
565
|
+
if row['round'] not in assigned or row['attempt'] is None or not row['task']:
|
|
566
|
+
continue
|
|
567
|
+
judged[(row['task'], row['attempt'])] = dict(group=group_dir.name, round=row['round'])
|
|
568
|
+
return judged
|
|
569
|
+
|
|
570
|
+
|
|
571
|
+
def annotate_group_attempt(event: dict, tdir: Path) -> None:
|
|
572
|
+
"""Point a member attempt at the group review that judged it, and drop the copied task review.
|
|
573
|
+
|
|
574
|
+
Settle and merge write that member's qa.last and qa.gate onto the task dir. Those are
|
|
575
|
+
not a task-level review: the attempt keeps the link (`review_scope`, `group`, `round`)
|
|
576
|
+
and the per-task review fields stay empty. An attempt with its own qa dispatch is
|
|
577
|
+
left unchanged. An attempt no group judged gains no key, so a plan without a group
|
|
578
|
+
review imports the same events as before.
|
|
579
|
+
"""
|
|
580
|
+
if event.get('kind') != 'attempt' or Path(tdir).parent.name != 'tasks':
|
|
581
|
+
return
|
|
582
|
+
data = event.get('data')
|
|
583
|
+
if not isinstance(data, dict):
|
|
584
|
+
return
|
|
585
|
+
if any(str(name).startswith('qa-') for name in (data.get('children') or [])):
|
|
586
|
+
return
|
|
587
|
+
plan = Path(tdir).parent.parent
|
|
588
|
+
if not (plan / 'tasks.tsv').is_file():
|
|
589
|
+
return
|
|
590
|
+
link = group_judgments(plan).get((Path(tdir).name, event.get('attempt')))
|
|
591
|
+
if not link:
|
|
592
|
+
return
|
|
593
|
+
data['review_scope'] = 'group'
|
|
594
|
+
data['group'] = link['group']
|
|
595
|
+
data['round'] = link['round']
|
|
596
|
+
data['gate'] = None
|
|
597
|
+
blobs = data.get('blobs')
|
|
598
|
+
if isinstance(blobs, dict):
|
|
599
|
+
blobs.pop('forge_note', None)
|
|
600
|
+
|
|
601
|
+
|
|
426
602
|
def dispatch_event(attempt: Path, root: Path, role: str, harness: str, rc, prov: dict, src: str = 'live') -> dict:
|
|
427
603
|
metrics = read_json(attempt / 'metrics.json') or {}
|
|
428
604
|
resolved = kv(attempt / (role + '.resolved'))
|
|
@@ -437,10 +613,26 @@ def dispatch_event(attempt: Path, root: Path, role: str, harness: str, rc, prov:
|
|
|
437
613
|
verdict = verdict_of(message) if message is not None else None
|
|
438
614
|
found, parsed = parse_review(message) if role == 'qa' else ([], True)
|
|
439
615
|
shadow = prov.get('shadow')
|
|
616
|
+
kind = side_kind(root, role, prov)
|
|
617
|
+
located = locate(root, role)
|
|
618
|
+
# A group root stays a group even when an older provenance named a task. The dispatch
|
|
619
|
+
# is one review of several tasks, so the event's task stays empty.
|
|
620
|
+
group_root = located.get('scope') == 'group' or prov.get('scope') == 'group'
|
|
621
|
+
scope = 'group' if group_root else prov.get('scope')
|
|
622
|
+
task_id = None if group_root else prov.get('task')
|
|
623
|
+
# A shadow review keeps the qa files and contract but is never a task's review, so it
|
|
624
|
+
# gets its own role: nothing that reads qa dispatches mistakes it for the one that decided.
|
|
625
|
+
# A side dispatch keeps the side files and is recorded as side_<kind>, so attempt
|
|
626
|
+
# statistics can leave it out (forge_dataset.is_side_role). A group review keeps the
|
|
627
|
+
# role qa; scope group is what leaves it out of one task's statistics.
|
|
628
|
+
if kind:
|
|
629
|
+
recorded_role = 'side_' + kind
|
|
630
|
+
elif shadow and role == 'qa':
|
|
631
|
+
recorded_role = 'qa_shadow'
|
|
632
|
+
else:
|
|
633
|
+
recorded_role = role
|
|
440
634
|
data = dict(
|
|
441
|
-
|
|
442
|
-
# gets its own role: nothing that reads qa dispatches mistakes it for the one that decided.
|
|
443
|
-
role='qa_shadow' if shadow and role == 'qa' else role, alias=resolved.get('alias'), harness=harness, model=resolved.get('model'),
|
|
635
|
+
role=recorded_role, alias=resolved.get('alias'), harness=harness, model=resolved.get('model'),
|
|
444
636
|
effort=None if not effort or effort.startswith('<') else effort,
|
|
445
637
|
# metrics.json is the record finish() wrote. A run from before that record falls
|
|
446
638
|
# back to the resolved line, which exists only when a tier was asked.
|
|
@@ -460,14 +652,25 @@ def dispatch_event(attempt: Path, root: Path, role: str, harness: str, rc, prov:
|
|
|
460
652
|
findings_parse=review_completeness(verdict, found, parsed) if role == 'qa' else None,
|
|
461
653
|
tests=review_tests(message) if role == 'qa' else None,
|
|
462
654
|
session_id=session_id, session_continue=session_continue,
|
|
463
|
-
root=str(root), scope=
|
|
655
|
+
root=str(root), scope=scope, trigger=prov.get('trigger'),
|
|
464
656
|
**({'shadow': shadow} if shadow else {}),
|
|
465
657
|
)
|
|
658
|
+
if group_root and role == 'qa':
|
|
659
|
+
gid = located.get('group') or Path(root).name
|
|
660
|
+
plan = located.get('plan') or Path(root).resolve().parent.parent
|
|
661
|
+
# Live capture reads the round file, which holds the round in progress. An import
|
|
662
|
+
# reads members.tsv: the file advances when the next round starts.
|
|
663
|
+
data['group'] = gid
|
|
664
|
+
data['members'] = group_members(plan, gid)
|
|
665
|
+
if src == 'import':
|
|
666
|
+
data['round'] = assign_group_rounds(Path(root)).get(Path(attempt).name)
|
|
667
|
+
else:
|
|
668
|
+
data['round'] = as_int(first_line(Path(root) / 'round'))
|
|
466
669
|
prompt = None if delivery == 'native_review' else put_file(attempt / (role + '.prompt'), 'prompt')
|
|
467
670
|
last = put_file(attempt / (role + '.last'), 'message' if final_source == 'structured' else 'log')
|
|
468
671
|
return dict(rid=attempt.name, kind='dispatch', ts=prov.get('wall_ended') or time.time(), src=src,
|
|
469
672
|
run=prov.get('run'), run_id=prov.get('run_id'), mode=prov.get('mode'),
|
|
470
|
-
task=
|
|
673
|
+
task=task_id, attempt=prov.get('attempt_now'), parent=prov.get('parent'),
|
|
471
674
|
inv=prov.get('inv'), data=dict(data, blobs=blobs(prompt=prompt, message=last)))
|
|
472
675
|
|
|
473
676
|
|
|
@@ -500,6 +703,30 @@ def children(root: Path, parent: str) -> list:
|
|
|
500
703
|
return found
|
|
501
704
|
|
|
502
705
|
|
|
706
|
+
def attempt_prompt_changed(status) -> bool:
|
|
707
|
+
"""Whether this attempt stopped unreviewed because its prompt or approach changed (#150).
|
|
708
|
+
|
|
709
|
+
A store row from before the field exists reads as false: `.get` of a missing key, and
|
|
710
|
+
this function is what writes the key. No re-import is required.
|
|
711
|
+
"""
|
|
712
|
+
return status == 'STALE'
|
|
713
|
+
|
|
714
|
+
|
|
715
|
+
def requirement_blob(tdir: Path, stem: str):
|
|
716
|
+
"""The prompt or approach the implementer was dispatched with.
|
|
717
|
+
|
|
718
|
+
`<stem>.dispatched` is that text when the attempt recorded it. An attempt from before
|
|
719
|
+
the record falls back to `<stem>.md`. An empty `approach.dispatched` means there was
|
|
720
|
+
no approach, stored the same way as a missing approach.md: no blob.
|
|
721
|
+
"""
|
|
722
|
+
dispatched = tdir / (stem + '.dispatched')
|
|
723
|
+
if dispatched.is_file():
|
|
724
|
+
if stem == 'approach' and text(dispatched) == '':
|
|
725
|
+
return None
|
|
726
|
+
return put_file(dispatched, 'prompt')
|
|
727
|
+
return put_file(tdir / (stem + '.md'), 'prompt')
|
|
728
|
+
|
|
729
|
+
|
|
503
730
|
def task_event(attempt: Path, tdir: Path, rc, prov: dict, src: str = 'live') -> dict:
|
|
504
731
|
before = prov.get('files')
|
|
505
732
|
made = lambda name: produced(tdir, before, name)
|
|
@@ -524,6 +751,7 @@ def task_event(attempt: Path, tdir: Path, rc, prov: dict, src: str = 'live') ->
|
|
|
524
751
|
sent_back=next((kind for marker, kind in SENT_BACK if made(marker)), None),
|
|
525
752
|
retry_source=first_line(tdir / 'retry_findings.source'),
|
|
526
753
|
identical_retry=bool(diff) and made('changes.prev.diff') and diff == text(tdir / 'changes.prev.diff'),
|
|
754
|
+
prompt_changed=attempt_prompt_changed(status),
|
|
527
755
|
produced=sorted(n for n in WATCHED if made(n)),
|
|
528
756
|
carried=sorted(n for n in WATCHED if (tdir / n).exists() and not made(n)),
|
|
529
757
|
children=children(tdir, attempt.name),
|
|
@@ -542,7 +770,7 @@ def task_event(attempt: Path, tdir: Path, rc, prov: dict, src: str = 'live') ->
|
|
|
542
770
|
qa_effort_jev=put_file(tdir / 'qa.effort.jev') if made('qa.effort.jev') else None,
|
|
543
771
|
review_triage_jev=put_file(tdir / 'qa.jev.json') if made('qa.jev.json') else None,
|
|
544
772
|
routing_jev=put_file(tdir / 'jev.json'),
|
|
545
|
-
prompt=
|
|
773
|
+
prompt=requirement_blob(tdir, 'prompt'), approach=requirement_blob(tdir, 'approach'),
|
|
546
774
|
)
|
|
547
775
|
data['blobs'] = refs
|
|
548
776
|
return dict(rid=attempt.name, kind='attempt', ts=prov.get('wall_ended') or time.time(), src=src,
|
|
@@ -773,8 +1001,9 @@ def plan_event(plan: Path, prov: dict, src: str = 'live', inventory: bool = True
|
|
|
773
1001
|
fractal_selection=read_json(plan / 'fractal-selection.json'),
|
|
774
1002
|
jev_coupling=read_json(plan / 'jev-coupling.json'),
|
|
775
1003
|
options=dict({name: first_line(plan / name) for name in ('verify_retries', 'timeout', 'final_qa',
|
|
776
|
-
'shadow_qa', 'shadow_rate', 'explore', 'reviewer_session',
|
|
777
|
-
'implementer_session'
|
|
1004
|
+
'shadow_qa', 'shadow_rate', 'explore', 'reviewer_session', 'reviewer_session_rate',
|
|
1005
|
+
'implementer_session', 'retro_mode', 'brief', 'brief_scope',
|
|
1006
|
+
'brief_model', 'summaries', 'summaries_model', 'retry_per_model')
|
|
778
1007
|
if (plan / name).exists()}, qa_threshold=threshold, qa_threshold_source=threshold_source),
|
|
779
1008
|
flags=sorted(name for name in ('no_memory', 'no_ripwire', 'yolo_dwarf', 'yolo_qa', 'pre_review_tests')
|
|
780
1009
|
if (plan / name).exists()),
|
|
@@ -5,9 +5,12 @@ exist. Each run is one record with its repository and base commit, so the screen
|
|
|
5
5
|
belongs to (the same base-commit rule forge-ui's repos.py uses for a run whose checkout is gone):
|
|
6
6
|
|
|
7
7
|
runs {run (dataset uid), run_id, mode, repo_path, base, first, last}
|
|
8
|
-
findings one per review dispatch (qa, qa_shadow) that listed findings
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
findings one per review dispatch (qa, qa_shadow) that listed findings. A side dispatch
|
|
9
|
+
(`side_*`, or the bare role `side`) is not a review and is left out, and so is a
|
|
10
|
+
group review (`scope` `group`): one QA dispatch for several tasks. Each row is
|
|
11
|
+
{run, run_id, task, attempt, role, scope, reviewer, verdict, ts, findings:
|
|
12
|
+
[{head, severity (0-3 or null), status, line}]}, as the capture parsed them
|
|
13
|
+
with forge-contract.py (no second parser)
|
|
11
14
|
learnings one per FORGE_LEARNING line a dispatch emitted: {run, run_id, task, role, model, ts, category, text}
|
|
12
15
|
ledger the ledger rows `forge dataset import --ledger` stored: {repo_path, ts, run_id, task, role, model,
|
|
13
16
|
category, key, text, injectable}
|
|
@@ -18,7 +21,8 @@ from __future__ import annotations
|
|
|
18
21
|
|
|
19
22
|
import json
|
|
20
23
|
|
|
21
|
-
from . import connect, dataset_dir, enabled
|
|
24
|
+
from . import connect, dataset_dir, enabled, is_side_role
|
|
25
|
+
from .names import dispatch_name
|
|
22
26
|
|
|
23
27
|
_HEAD_MAX = 400
|
|
24
28
|
_TEXT_MAX = 2000
|
|
@@ -71,11 +75,14 @@ def load() -> dict:
|
|
|
71
75
|
if task is None and parent in attempt_task:
|
|
72
76
|
task, attempt = task or attempt_task[parent][0], attempt or attempt_task[parent][1]
|
|
73
77
|
role = d.get('role')
|
|
74
|
-
spec =
|
|
78
|
+
spec = dispatch_name(d)
|
|
75
79
|
if d.get('effort') and spec and ':' not in str(spec):
|
|
76
80
|
spec = '%s:%s' % (spec, d['effort'])
|
|
77
81
|
found = d.get('findings')
|
|
78
|
-
|
|
82
|
+
# qa and qa_shadow only. side_* is not a review, and neither is a group review
|
|
83
|
+
# (scope group): one dispatch for several tasks, so its findings are not history.
|
|
84
|
+
if (role in ('qa', 'qa_shadow') and not is_side_role(role) and d.get('scope') != 'group'
|
|
85
|
+
and isinstance(found, list) and found):
|
|
79
86
|
items = []
|
|
80
87
|
for f in found:
|
|
81
88
|
if not isinstance(f, dict) or not isinstance(f.get('head'), str):
|