@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,294 @@
|
|
|
1
|
+
"""What the plan-time gates did to a plan, and the edits they may make to tasks.tsv.
|
|
2
|
+
|
|
3
|
+
`$PLAN/plan-gates.json` records it: drift files added (or only predicted), forward dependencies
|
|
4
|
+
added, skipped for a cycle or only predicted, prompt scores, requirements no task covers, and
|
|
5
|
+
which items were sent back to the planner. It lives across re-plans. `sent_back` is append-only
|
|
6
|
+
history, so an item goes back at most once per plan whatever happens to the current state in
|
|
7
|
+
between; `pending` is what the current `plan` call marked and `sendback()` turns into
|
|
8
|
+
`plan.sendback.md`.
|
|
9
|
+
|
|
10
|
+
Standard library only (the threshold is read from forge_jev when it is importable). Every write
|
|
11
|
+
is a temp file in the same directory and an `os.replace`.
|
|
12
|
+
"""
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
import json
|
|
16
|
+
import os
|
|
17
|
+
import shutil
|
|
18
|
+
import tempfile
|
|
19
|
+
from pathlib import Path
|
|
20
|
+
|
|
21
|
+
GATES_FILE = 'plan-gates.json'
|
|
22
|
+
SENDBACK_FILE = 'plan.sendback.md'
|
|
23
|
+
KINDS = ('prompt', 'coverage')
|
|
24
|
+
DEFAULT_PROMPT_WARN = 0.55
|
|
25
|
+
FILES_COL, DEPS_COL = 3, 1
|
|
26
|
+
MIN_COLS = 7
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _atomic_write(path: Path, data: str | bytes) -> None:
|
|
30
|
+
raw = data.encode('utf-8', 'surrogateescape') if isinstance(data, str) else data
|
|
31
|
+
fd, tmp = tempfile.mkstemp(dir=str(path.parent), prefix='.' + path.name + '.')
|
|
32
|
+
try:
|
|
33
|
+
with os.fdopen(fd, 'wb') as handle:
|
|
34
|
+
handle.write(raw)
|
|
35
|
+
if path.exists():
|
|
36
|
+
shutil.copymode(str(path), tmp)
|
|
37
|
+
os.replace(tmp, str(path))
|
|
38
|
+
except BaseException:
|
|
39
|
+
try:
|
|
40
|
+
os.unlink(tmp)
|
|
41
|
+
except OSError:
|
|
42
|
+
pass
|
|
43
|
+
raise
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def load(plan) -> dict:
|
|
47
|
+
try:
|
|
48
|
+
value = json.loads((Path(plan) / GATES_FILE).read_text())
|
|
49
|
+
except (OSError, ValueError):
|
|
50
|
+
return {}
|
|
51
|
+
return value if isinstance(value, dict) else {}
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def save(plan, data: dict) -> None:
|
|
55
|
+
_atomic_write(Path(plan) / GATES_FILE, json.dumps(data, indent=2) + '\n')
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
# --- tasks.tsv ---------------------------------------------------------------------------
|
|
59
|
+
|
|
60
|
+
def _read_tasks(plan: Path):
|
|
61
|
+
"""(text, lines) with every byte kept, so a rewrite touches only the cell it means to."""
|
|
62
|
+
try:
|
|
63
|
+
text = (plan / 'tasks.tsv').read_bytes().decode('utf-8', 'surrogateescape')
|
|
64
|
+
except OSError:
|
|
65
|
+
return None, []
|
|
66
|
+
return text, text.split('\n')
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def _is_row(line: str) -> bool:
|
|
70
|
+
return bool(line.strip()) and not line.startswith('#') and line.count('\t') + 1 >= MIN_COLS
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def _names(cell: str) -> list[str]:
|
|
74
|
+
cell = cell.strip()
|
|
75
|
+
return [] if cell in ('', '-') else [n.strip() for n in cell.split(',') if n.strip()]
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def _norm(name: str) -> str:
|
|
79
|
+
name = name.strip()
|
|
80
|
+
while name.startswith('./'):
|
|
81
|
+
name = name[2:]
|
|
82
|
+
return name.rstrip('/') or '.'
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def _covered(name: str, listed: list[str]) -> bool:
|
|
86
|
+
name = _norm(name)
|
|
87
|
+
for have in listed:
|
|
88
|
+
have = _norm(have)
|
|
89
|
+
if have == '.' or name == have or name.startswith(have + '/'):
|
|
90
|
+
return True
|
|
91
|
+
return False
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def _row_index(lines: list[str], task: str):
|
|
95
|
+
for i, line in enumerate(lines):
|
|
96
|
+
if _is_row(line) and line.split('\t', 1)[0] == task:
|
|
97
|
+
return i
|
|
98
|
+
return None
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def _rewrite(plan: Path, lines: list[str], index: int, col: int, value: str) -> None:
|
|
102
|
+
cells = lines[index].split('\t')
|
|
103
|
+
cells[col] = value
|
|
104
|
+
lines[index] = '\t'.join(cells)
|
|
105
|
+
_atomic_write(plan / 'tasks.tsv', '\n'.join(lines))
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def add_files(plan, task: str, files) -> list[str]:
|
|
109
|
+
"""Append `files` to the task's `files` column; returns the names actually added."""
|
|
110
|
+
plan = Path(plan)
|
|
111
|
+
_text, lines = _read_tasks(plan)
|
|
112
|
+
index = _row_index(lines, task)
|
|
113
|
+
if index is None:
|
|
114
|
+
return []
|
|
115
|
+
listed = _names(lines[index].split('\t')[FILES_COL])
|
|
116
|
+
added = []
|
|
117
|
+
for name in files:
|
|
118
|
+
name = str(name).strip()
|
|
119
|
+
if not name or name == '-' or _covered(name, listed + added):
|
|
120
|
+
continue
|
|
121
|
+
added.append(name)
|
|
122
|
+
if added:
|
|
123
|
+
_rewrite(plan, lines, index, FILES_COL, ','.join(listed + added))
|
|
124
|
+
return added
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def _deps(lines: list[str]) -> dict[str, list[str]]:
|
|
128
|
+
out = {}
|
|
129
|
+
for line in lines:
|
|
130
|
+
if _is_row(line):
|
|
131
|
+
cells = line.split('\t')
|
|
132
|
+
out[cells[0]] = _names(cells[DEPS_COL])
|
|
133
|
+
return out
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def add_dep(plan, earlier: str, later: str) -> bool:
|
|
137
|
+
"""Make `earlier` wait for `later`. False, with no change, when that would form a cycle."""
|
|
138
|
+
plan = Path(plan)
|
|
139
|
+
_text, lines = _read_tasks(plan)
|
|
140
|
+
deps = _deps(lines)
|
|
141
|
+
if earlier not in deps or later not in deps or earlier == later:
|
|
142
|
+
return False
|
|
143
|
+
if later in deps[earlier]:
|
|
144
|
+
return True
|
|
145
|
+
# A cycle forms when `later` already waits for `earlier`, however indirectly.
|
|
146
|
+
seen, stack = set(), [later]
|
|
147
|
+
while stack:
|
|
148
|
+
node = stack.pop()
|
|
149
|
+
if node == earlier:
|
|
150
|
+
return False
|
|
151
|
+
if node in seen:
|
|
152
|
+
continue
|
|
153
|
+
seen.add(node)
|
|
154
|
+
stack.extend(deps.get(node, ()))
|
|
155
|
+
index = _row_index(lines, earlier)
|
|
156
|
+
_rewrite(plan, lines, index, DEPS_COL, ','.join(deps[earlier] + [later]))
|
|
157
|
+
return True
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
# --- send-back ---------------------------------------------------------------------------
|
|
161
|
+
|
|
162
|
+
def mark_pending(data: dict, kind: str, key: str) -> bool:
|
|
163
|
+
"""Queue `key` for sending back unless it ever was. Returns whether it was queued."""
|
|
164
|
+
if kind not in KINDS:
|
|
165
|
+
raise ValueError('unknown send-back kind: %r' % (kind,))
|
|
166
|
+
sent = data.setdefault('sent_back', {}).setdefault(kind, [])
|
|
167
|
+
if key in sent:
|
|
168
|
+
return False
|
|
169
|
+
sent.append(key)
|
|
170
|
+
data.setdefault('pending', {}).setdefault(kind, []).append(key)
|
|
171
|
+
return True
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def _prompt_warn() -> float:
|
|
175
|
+
try:
|
|
176
|
+
import forge_jev
|
|
177
|
+
return float(forge_jev.threshold('prompt_warn', site='jev-prompt'))
|
|
178
|
+
except Exception:
|
|
179
|
+
return DEFAULT_PROMPT_WARN
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def _score(value) -> str:
|
|
183
|
+
return ' (%.2f)' % value if isinstance(value, (int, float)) else ''
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
def _line(text) -> str:
|
|
187
|
+
return ' '.join(str(text).split())
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
def _titles(plan: Path) -> dict[str, str]:
|
|
191
|
+
_text, lines = _read_tasks(plan)
|
|
192
|
+
return {l.split('\t')[0]: l.split('\t')[6] for l in lines if _is_row(l)}
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
def _sendback_text(plan: Path, data: dict) -> str:
|
|
196
|
+
pending = data.get('pending') or {}
|
|
197
|
+
threshold = _prompt_warn()
|
|
198
|
+
titles = _titles(plan)
|
|
199
|
+
prompts = []
|
|
200
|
+
for task in pending.get('prompt') or []:
|
|
201
|
+
title = titles.get(task)
|
|
202
|
+
entry = (data.get('prompt') or {}).get(task) or {}
|
|
203
|
+
prompts.append('- %s%s%s: tasks/%s/prompt.md' % (
|
|
204
|
+
task, ' — "%s"' % _line(title) if title else '', _score(entry.get('p')), task))
|
|
205
|
+
uncovered = {u.get('sha'): u for u in (data.get('coverage') or {}).get('uncovered') or []
|
|
206
|
+
if isinstance(u, dict)}
|
|
207
|
+
covers = []
|
|
208
|
+
for sha in pending.get('coverage') or []:
|
|
209
|
+
entry = uncovered.get(sha)
|
|
210
|
+
if entry and entry.get('text'):
|
|
211
|
+
covers.append('- "%s"%s: add it to a task\'s ## Acceptance criteria, or add a task'
|
|
212
|
+
% (_line(entry['text']), _score(entry.get('p'))))
|
|
213
|
+
if not prompts and not covers:
|
|
214
|
+
return ''
|
|
215
|
+
out = ['# Sent back by forge\'s plan gates', '',
|
|
216
|
+
'Rewrite what is listed here, then run `plan` again. Forge sends each task and requirement back once:',
|
|
217
|
+
'anything still flagged next time is listed under the table instead.']
|
|
218
|
+
if prompts:
|
|
219
|
+
out += ['', '## Task prompts a reviewer could not judge (prompt gate, below %g)' % threshold] + prompts
|
|
220
|
+
if covers:
|
|
221
|
+
out += ['', '## Requirements no task covers (coverage gate)'] + covers
|
|
222
|
+
return '\n'.join(out) + '\n'
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
def sendback(plan) -> bool:
|
|
226
|
+
"""Write (or remove) plan.sendback.md from the pending items, then empty `pending`."""
|
|
227
|
+
plan = Path(plan)
|
|
228
|
+
data = load(plan)
|
|
229
|
+
body = _sendback_text(plan, data)
|
|
230
|
+
path = plan / SENDBACK_FILE
|
|
231
|
+
if body:
|
|
232
|
+
_atomic_write(path, body)
|
|
233
|
+
else:
|
|
234
|
+
try:
|
|
235
|
+
path.unlink()
|
|
236
|
+
except OSError:
|
|
237
|
+
pass
|
|
238
|
+
pending = data.get('pending') or {}
|
|
239
|
+
if any(pending.get(kind) for kind in pending):
|
|
240
|
+
data['pending'] = {kind: [] for kind in KINDS}
|
|
241
|
+
save(plan, data)
|
|
242
|
+
return bool(body)
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
# --- the block under the table -----------------------------------------------------------
|
|
246
|
+
|
|
247
|
+
def _entries(value) -> list[dict]:
|
|
248
|
+
return [e for e in value or [] if isinstance(e, dict)]
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
def marks(plan) -> list[str]:
|
|
252
|
+
data = load(Path(plan))
|
|
253
|
+
out = []
|
|
254
|
+
drift = data.get('drift') if isinstance(data.get('drift'), dict) else {}
|
|
255
|
+
for task in sorted(drift):
|
|
256
|
+
entry = drift[task] if isinstance(drift[task], dict) else {}
|
|
257
|
+
for item in _entries(entry.get('added')):
|
|
258
|
+
out.append('drift added to %s: %s%s' % (task, item.get('file'), _score(item.get('p'))))
|
|
259
|
+
for item in _entries(entry.get('would_add')):
|
|
260
|
+
out.append('drift (shadow) would add to %s: %s%s' % (task, item.get('file'), _score(item.get('p'))))
|
|
261
|
+
forward = data.get('forward') if isinstance(data.get('forward'), dict) else {}
|
|
262
|
+
|
|
263
|
+
def pairs(name):
|
|
264
|
+
return sorted(_entries(forward.get(name)), key=lambda e: (str(e.get('earlier')), str(e.get('later'))))
|
|
265
|
+
for item in pairs('added'):
|
|
266
|
+
out.append('forward added a dependency: %s now waits for %s%s'
|
|
267
|
+
% (item.get('earlier'), item.get('later'), _score(item.get('p'))))
|
|
268
|
+
for item in pairs('would_add'):
|
|
269
|
+
out.append('forward (shadow) would add a dependency: %s would wait for %s%s'
|
|
270
|
+
% (item.get('earlier'), item.get('later'), _score(item.get('p'))))
|
|
271
|
+
for item in pairs('skipped_cycle'):
|
|
272
|
+
out.append('forward skipped a dependency that would form a cycle: %s on %s%s'
|
|
273
|
+
% (item.get('earlier'), item.get('later'), _score(item.get('p'))))
|
|
274
|
+
prompt = data.get('prompt') if isinstance(data.get('prompt'), dict) else {}
|
|
275
|
+
sent = (data.get('sent_back') or {}).get('prompt') or []
|
|
276
|
+
threshold = _prompt_warn()
|
|
277
|
+
# The shadow lines come first, then the rewrites that did not help; ids are sorted within each.
|
|
278
|
+
shadows, stuck = [], []
|
|
279
|
+
for task in sorted(prompt):
|
|
280
|
+
entry = prompt[task] if isinstance(prompt[task], dict) else {}
|
|
281
|
+
p, after = entry.get('p'), entry.get('after')
|
|
282
|
+
if entry.get('shadow'):
|
|
283
|
+
if isinstance(p, (int, float)) and p < threshold:
|
|
284
|
+
shadows.append('prompt (shadow) %s: %.2f, below %g' % (task, p, threshold))
|
|
285
|
+
elif task in sent and isinstance(after, (int, float)) and after < threshold:
|
|
286
|
+
stuck.append('prompt still below %g after its rewrite: %s (%.2f)' % (threshold, task, after))
|
|
287
|
+
out += shadows + stuck
|
|
288
|
+
coverage = data.get('coverage') if isinstance(data.get('coverage'), dict) else {}
|
|
289
|
+
sent = (data.get('sent_back') or {}).get('coverage') or []
|
|
290
|
+
uncovered = sorted((e for e in _entries(coverage.get('uncovered')) if e.get('sha') in sent),
|
|
291
|
+
key=lambda e: str(e.get('text')))
|
|
292
|
+
for item in uncovered:
|
|
293
|
+
out.append('requirements no task covers: "%s"%s' % (_line(item.get('text')), _score(item.get('p'))))
|
|
294
|
+
return ['decision-model gates:'] + [' ' + line for line in out] if out else []
|