@giamme/forge 0.12.1 → 0.13.1
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 +66 -0
- package/README.md +1 -1
- package/SKILL.md +29 -12
- package/VERSION +1 -1
- package/docs/add-ons.md +11 -6
- package/docs/artifacts.md +12 -6
- package/docs/commands.md +179 -17
- package/docs/decomposed-runs.md +13 -5
- package/docs/forge-ui.md +14 -4
- package/docs/memory.md +2 -1
- package/docs/models.md +4 -2
- package/docs/reviews.md +49 -20
- package/docs/troubleshooting.md +3 -1
- package/forge +17 -1
- package/package.json +1 -1
- package/references/dataset.md +39 -13
- package/references/decision-models.md +763 -0
- package/references/decompose.md +166 -29
- package/references/harnesses.md +10 -3
- package/references/planning.md +8 -0
- package/references/solo.md +13 -3
- package/scripts/forge-artifact.sh +30 -4
- package/scripts/forge-config.py +238 -29
- package/scripts/forge-contract.py +95 -56
- package/scripts/forge-control.py +40 -9
- package/scripts/forge-decide.py +6 -0
- package/scripts/forge-dispatch.sh +38 -16
- package/scripts/forge-fail-first.py +2 -2
- package/scripts/forge-gate-addressed.sh +40 -0
- package/scripts/forge-gate-message.sh +64 -0
- package/scripts/forge-issues.py +321 -33
- package/scripts/forge-jev-options.sh +269 -42
- package/scripts/forge-lib-attribute.sh +447 -0
- package/scripts/forge-lib-gates.sh +32 -0
- package/scripts/forge-lib-plans.sh +22 -6
- package/scripts/forge-lib-review.sh +22 -17
- package/scripts/forge-lib-task.sh +217 -38
- package/scripts/forge-lib-verify.sh +45 -8
- package/scripts/forge-memory.sh +3 -3
- package/scripts/forge-parallel-options.sh +18 -5
- package/scripts/forge-parallel.sh +457 -303
- package/scripts/forge-plan-check.py +35 -1
- package/scripts/forge-pre-review.py +437 -0
- package/scripts/forge-prompt.py +25 -5
- package/scripts/forge-route.py +2 -2
- package/scripts/forge-runtime.py +10 -4
- package/scripts/forge-schedule.py +21 -5
- package/scripts/forge-shadow.py +2 -2
- package/scripts/forge-solo.sh +39 -9
- package/scripts/forge-submodules.py +389 -0
- package/scripts/forge-ui-options.sh +25 -0
- package/scripts/forge_dataset/cli.py +12 -6
- package/scripts/forge_dataset/export.py +140 -84
- package/scripts/forge_dataset/harvest.py +33 -5
- package/scripts/{forge_jev/outcome.py → forge_dataset/states.py} +21 -7
- package/scripts/forge_decide/__init__.py +141 -0
- package/scripts/forge_decide/budget.py +180 -0
- package/scripts/forge_decide/cache.py +66 -0
- package/scripts/forge_decide/cli.py +953 -0
- package/scripts/forge_decide/doctor.py +270 -0
- package/scripts/forge_decide/label_addressed.py +75 -0
- package/scripts/forge_decide/label_attribution.py +62 -0
- package/scripts/forge_decide/label_coverage.py +81 -0
- package/scripts/forge_decide/label_message.py +38 -0
- package/scripts/forge_decide/label_prompt.py +139 -0
- package/scripts/forge_decide/labels.py +328 -0
- package/scripts/forge_decide/metrics.py +125 -0
- package/scripts/forge_decide/migrate.py +226 -0
- package/scripts/forge_decide/providers.py +292 -0
- package/scripts/forge_decide/replay.py +350 -0
- package/scripts/forge_decide/report.py +382 -0
- package/scripts/forge_decide/resolve.py +397 -0
- package/scripts/forge_decide/sites.py +377 -0
- package/scripts/forge_jev/__init__.py +202 -104
- package/scripts/forge_jev/addressed.py +171 -0
- package/scripts/forge_jev/attribution.py +198 -0
- package/scripts/forge_jev/cli.py +460 -382
- package/scripts/forge_jev/client.py +155 -77
- package/scripts/forge_jev/coupling.py +19 -87
- package/scripts/forge_jev/coverage.py +303 -0
- package/scripts/forge_jev/findings.py +219 -0
- package/scripts/forge_jev/gates.py +225 -27
- package/scripts/forge_jev/memory.py +65 -4
- package/scripts/forge_jev/message.py +134 -0
- package/scripts/forge_jev/plan_gates.py +294 -0
- package/scripts/forge_jev/questions.py +173 -313
- package/scripts/forge_jev/verify.py +130 -104
- package/ui/README.md +2 -2
- package/ui/docs/api.md +92 -39
- package/ui/forge_ui/control.py +71 -14
- package/ui/forge_ui/export.py +2 -1
- package/ui/forge_ui/models.py +17 -16
- package/ui/forge_ui/reader.py +132 -21
- package/ui/forge_ui/repos.py +428 -0
- package/ui/forge_ui/static/app.js +24 -5
- package/ui/forge_ui/static/cloudmodel.js +8 -5
- package/ui/forge_ui/static/controls.js +20 -13
- package/ui/forge_ui/static/modelstats.js +12 -8
- package/ui/forge_ui/static/panel.js +63 -17
- package/ui/forge_ui/static/runmodel.js +48 -7
- package/ui/forge_ui/static/scene3d.js +2 -15
- package/ui/forge_ui/static/settings.js +481 -68
- package/ui/forge_ui/static/style.css +56 -9
- package/references/jev.md +0 -865
- package/scripts/forge_jev/backtest.py +0 -322
- package/scripts/forge_jev/corpus.py +0 -156
- package/scripts/forge_jev/features.py +0 -24
- package/scripts/forge_jev/predict.py +0 -204
- package/scripts/forge_jev/review.py +0 -73
- package/scripts/forge_jev/routing.py +0 -271
- package/scripts/forge_jev/subset.py +0 -123
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
"""Integration attribution (#45): which merged task most likely broke the combined verification.
|
|
2
|
+
|
|
3
|
+
`forge-parallel.sh attribute` searches the merge order for a merge that breaks the run's
|
|
4
|
+
verification, one full verification per step. This asks one Choice, `culprit`, over every merged
|
|
5
|
+
task id plus `none`, given the end of the failing log and each merge's diff, and prints the
|
|
6
|
+
ranking: `<id>TAB<p>` per line, highest first, `none` included. The shell decides what to do with
|
|
7
|
+
it by the gate's mode (`on` probes the top suspect's boundary first; `shadow` only records it).
|
|
8
|
+
The gate never reaches a verdict by itself: a wrong guess only costs the shell one more step.
|
|
9
|
+
|
|
10
|
+
forge-jev.py attribution --plan P --repo R --log L
|
|
11
|
+
|
|
12
|
+
Exit 3 is no opinion: the gate is off, the log is missing, fewer than two merges, or the model
|
|
13
|
+
did not answer.
|
|
14
|
+
"""
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
import re
|
|
18
|
+
import subprocess
|
|
19
|
+
from pathlib import Path
|
|
20
|
+
|
|
21
|
+
from . import site_ready
|
|
22
|
+
from .client import ask, probabilities
|
|
23
|
+
from .questions import culprit
|
|
24
|
+
|
|
25
|
+
SITE = 'jev-attribution'
|
|
26
|
+
LOG_LINES = 150
|
|
27
|
+
DIFF_CHARS = 3000
|
|
28
|
+
# The subject forge-lib-attribute.sh keeps: `<sha> forge: merge <id>` (an awk match on `%H %s`).
|
|
29
|
+
_MERGE = re.compile(r'([0-9a-f]+) forge: merge ([^ ]+) *')
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def _read(path: Path) -> str:
|
|
33
|
+
try:
|
|
34
|
+
return path.read_text(errors='replace')
|
|
35
|
+
except OSError:
|
|
36
|
+
return ''
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _git(repo, *args) -> str | None:
|
|
40
|
+
try:
|
|
41
|
+
done = subprocess.run(['git', '-C', str(repo), *args], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL,
|
|
42
|
+
text=True, errors='replace', timeout=60)
|
|
43
|
+
except (OSError, subprocess.SubprocessError):
|
|
44
|
+
return None
|
|
45
|
+
return done.stdout if done.returncode == 0 else None
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def merges(plan, repo) -> list[tuple[str, str]]:
|
|
49
|
+
"""[(commit, task id)], oldest first: the integration branch's first-parent `forge: merge <id>`
|
|
50
|
+
commits after its base, as forge-lib-attribute.sh reads them. [] when the base or the branch
|
|
51
|
+
is missing."""
|
|
52
|
+
plan = Path(plan)
|
|
53
|
+
run_id = _read(plan / 'run_id').strip()
|
|
54
|
+
base = _read(plan / 'integration.base').strip()
|
|
55
|
+
if not run_id or not base:
|
|
56
|
+
return []
|
|
57
|
+
base_commit = (_git(repo, 'rev-parse', base + '^{commit}') or '').strip()
|
|
58
|
+
tip = (_git(repo, 'rev-parse', f'forge/{run_id}-integration^{{commit}}') or '').strip()
|
|
59
|
+
if not base_commit or not tip:
|
|
60
|
+
return []
|
|
61
|
+
listing = _git(repo, 'log', '--first-parent', '--reverse', '--format=%H %s', f'{base_commit}..{tip}') or ''
|
|
62
|
+
out = []
|
|
63
|
+
for line in listing.splitlines():
|
|
64
|
+
found = _MERGE.fullmatch(line)
|
|
65
|
+
if found:
|
|
66
|
+
out.append((found.group(1), found.group(2)))
|
|
67
|
+
return out
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def _tasks_tsv(plan: Path) -> dict[str, tuple[str, list[str]]]:
|
|
71
|
+
"""id -> (title, files): tasks.tsv columns 7 and 4."""
|
|
72
|
+
out = {}
|
|
73
|
+
for line in _read(plan / 'tasks.tsv').splitlines():
|
|
74
|
+
cells = line.split('\t')
|
|
75
|
+
if len(cells) < 7 or line.startswith('#'):
|
|
76
|
+
continue
|
|
77
|
+
files = [name.strip() for name in cells[3].split(',') if name.strip() and name.strip() != '-']
|
|
78
|
+
out[cells[0]] = (cells[6], files)
|
|
79
|
+
return out
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def _diff(repo, commit: str) -> str:
|
|
83
|
+
text = _git(repo, 'diff', f'{commit}^1', commit) or ''
|
|
84
|
+
return text[:DIFF_CHARS] + ('\n[cut]' if len(text) > DIFF_CHARS else '')
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def _tail(path: Path) -> str:
|
|
88
|
+
return '\n'.join(_read(path).splitlines()[-LOG_LINES:])
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def state_of(plan, repo, log) -> dict | None:
|
|
92
|
+
"""The request's state, or None with fewer than two merges."""
|
|
93
|
+
plan = Path(plan)
|
|
94
|
+
found = merges(plan, repo)
|
|
95
|
+
if len(found) < 2:
|
|
96
|
+
return None
|
|
97
|
+
listed = _tasks_tsv(plan)
|
|
98
|
+
tasks = []
|
|
99
|
+
for commit, task in found:
|
|
100
|
+
title, files = listed.get(task, ('', []))
|
|
101
|
+
tasks.append(dict(id=task, title=title, files=files, diff=_diff(repo, commit)))
|
|
102
|
+
return dict(run=_read(plan / 'run_id').strip() or plan.name, log=_tail(Path(log)), tasks=tasks)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def ranking(probs: dict, order: list) -> list[tuple[str, float]]:
|
|
106
|
+
"""(option, p), highest first; equal probabilities keep the order the options were asked in."""
|
|
107
|
+
place = {option: i for i, option in enumerate(order)}
|
|
108
|
+
return sorted(probs.items(), key=lambda item: (-item[1], place.get(item[0], len(place))))
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def main(args) -> int:
|
|
112
|
+
if not site_ready(SITE):
|
|
113
|
+
return 3
|
|
114
|
+
plan, log = Path(args.plan), Path(args.log)
|
|
115
|
+
if not log.is_file():
|
|
116
|
+
return 3
|
|
117
|
+
state = state_of(plan, args.repo, log)
|
|
118
|
+
if state is None:
|
|
119
|
+
return 3
|
|
120
|
+
ids = [task['id'] for task in state['tasks']]
|
|
121
|
+
result = ask(state, {'culprit': culprit(ids)}, site=SITE, run_dir=str(plan))
|
|
122
|
+
order = ranking(probabilities(result, 'culprit'), ids + ['none'])
|
|
123
|
+
if not order:
|
|
124
|
+
return 3
|
|
125
|
+
print('\n'.join(f'{option}\t{p:.3f}' for option, p in order))
|
|
126
|
+
return 0
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
# --- measurement: what forge_decide.sites reads for this site --------------------------------
|
|
130
|
+
|
|
131
|
+
PREFIX = 'culprit:'
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def _options(body) -> list[str]:
|
|
135
|
+
questions = body.get('questions') if isinstance(body, dict) else None
|
|
136
|
+
question = questions.get('culprit') if isinstance(questions, dict) else None
|
|
137
|
+
criteria = question.get('criteria') if isinstance(question, dict) else None
|
|
138
|
+
return [str(option) for option in criteria] if isinstance(criteria, dict) else []
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def decisions(body) -> list[str]:
|
|
142
|
+
"""`culprit:<id>` per option of the request except `none`, in the order asked."""
|
|
143
|
+
return [PREFIX + option for option in _options(body) if option != 'none']
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def score(answers, qid, request=None) -> float | None:
|
|
147
|
+
"""The option's probability in the Choice's distribution."""
|
|
148
|
+
if not str(qid).startswith(PREFIX):
|
|
149
|
+
return None
|
|
150
|
+
probs = probabilities({'answers': answers or {}}, 'culprit')
|
|
151
|
+
return probs.get(str(qid)[len(PREFIX):])
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def _asked_order(request) -> list[str]:
|
|
155
|
+
"""The options in the order the run asked them: the merge order of the request's tasks, then
|
|
156
|
+
`none`. A stored request sorts its criteria, so they cannot say; its state's task list does."""
|
|
157
|
+
if not isinstance(request, dict):
|
|
158
|
+
return []
|
|
159
|
+
state = request.get('state')
|
|
160
|
+
tasks = state.get('tasks') if isinstance(state, dict) else None
|
|
161
|
+
if isinstance(tasks, list):
|
|
162
|
+
ids = [str(item['id']) for item in tasks if isinstance(item, dict) and 'id' in item]
|
|
163
|
+
if ids:
|
|
164
|
+
return ids + ['none']
|
|
165
|
+
return _options(request)
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def fired(answers, threshold_value=None, request=None) -> list[str] | None:
|
|
169
|
+
"""The top option when it is not `none` (there is no threshold). Ties break as `main` ranks
|
|
170
|
+
them, by the order the run asked the options in. None when options tie at the top and the
|
|
171
|
+
request does not give that order (the report has only the question names when it finds no
|
|
172
|
+
stored body): the winner cannot be known then."""
|
|
173
|
+
probs = probabilities({'answers': answers or {}}, 'culprit')
|
|
174
|
+
order = _asked_order(request)
|
|
175
|
+
ordered = ranking(probs, order)
|
|
176
|
+
if not ordered:
|
|
177
|
+
return []
|
|
178
|
+
tied = [option for option, p in ordered if p == ordered[0][1]]
|
|
179
|
+
if len(tied) > 1 and any(option not in order for option in tied):
|
|
180
|
+
return None
|
|
181
|
+
if ordered[0][0] == 'none':
|
|
182
|
+
return []
|
|
183
|
+
return [PREFIX + ordered[0][0]]
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
def baseline(body, qid) -> float:
|
|
187
|
+
"""How many of the task's declared files appear in the failing log: the plain rule the
|
|
188
|
+
model's probability is measured against."""
|
|
189
|
+
state = body.get('state') if isinstance(body, dict) else None
|
|
190
|
+
if not isinstance(state, dict):
|
|
191
|
+
return 0.0
|
|
192
|
+
log = str(state.get('log') or '')
|
|
193
|
+
task = str(qid)[len(PREFIX):]
|
|
194
|
+
for item in state.get('tasks') if isinstance(state.get('tasks'), list) else []:
|
|
195
|
+
if isinstance(item, dict) and item.get('id') == task:
|
|
196
|
+
files = item.get('files')
|
|
197
|
+
return float(sum(1 for name in files if str(name) in log)) if isinstance(files, list) else 0.0
|
|
198
|
+
return 0.0
|