@giamme/forge 0.14.0 → 0.15.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.
Files changed (44) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/SKILL.md +47 -14
  3. package/VERSION +1 -1
  4. package/docs/artifacts.md +2 -1
  5. package/docs/commands.md +301 -7
  6. package/docs/models.md +53 -0
  7. package/package.json +1 -1
  8. package/references/dataset.md +12 -3
  9. package/references/decompose.md +108 -7
  10. package/references/harnesses.md +21 -1
  11. package/references/planning.md +59 -0
  12. package/references/ui.md +39 -1
  13. package/scripts/forge-compare.py +6 -3
  14. package/scripts/forge-config.py +531 -4
  15. package/scripts/forge-dispatch.sh +132 -22
  16. package/scripts/forge-lib-plans.sh +19 -2
  17. package/scripts/forge-lib-review.sh +5 -3
  18. package/scripts/forge-lib-task.sh +119 -0
  19. package/scripts/forge-parallel-options.sh +12 -6
  20. package/scripts/forge-parallel.sh +572 -26
  21. package/scripts/forge-plan-check.py +591 -8
  22. package/scripts/forge-planner.py +480 -0
  23. package/scripts/forge-route.py +72 -23
  24. package/scripts/forge-runtime.py +157 -1
  25. package/scripts/forge-shadow.py +51 -7
  26. package/scripts/forge-solo.sh +81 -7
  27. package/scripts/forge_dataset/cli.py +10 -0
  28. package/scripts/forge_dataset/efforts.py +215 -0
  29. package/scripts/forge_dataset/harvest.py +44 -0
  30. package/scripts/forge_decide/__init__.py +19 -1
  31. package/scripts/forge_decide/builtin_profiles.json +25 -0
  32. package/scripts/forge_decide/cli.py +12 -0
  33. package/scripts/forge_decide/profiles.py +866 -0
  34. package/scripts/forge_decide/resolve.py +38 -6
  35. package/ui/docs/api.md +87 -8
  36. package/ui/forge_ui/control.py +173 -12
  37. package/ui/forge_ui/executions.py +28 -8
  38. package/ui/forge_ui/models.py +60 -1
  39. package/ui/forge_ui/reader.py +21 -1
  40. package/ui/forge_ui/static/leaderboard.js +5 -1
  41. package/ui/forge_ui/static/modelstats.js +25 -1
  42. package/ui/forge_ui/static/panel.js +19 -2
  43. package/ui/forge_ui/static/settings.js +788 -25
  44. package/ui/forge_ui/static/style.css +23 -0
@@ -10,6 +10,7 @@ from collections import OrderedDict
10
10
  import json
11
11
  import math
12
12
  import os
13
+ from pathlib import Path
13
14
  import threading
14
15
  import time
15
16
 
@@ -21,14 +22,72 @@ _MAX_WARNINGS = 500
21
22
  _RUNNING_S = 120
22
23
  _SIZE = 4096
23
24
  _PASS = ('PASS', 'MERGED')
25
+ _TIERS = ('low', 'medium', 'high')
24
26
  _LOCK = threading.Lock()
25
27
  _RUNS = OrderedDict() # realpath -> (signature, computed at, facts)
28
+ # realpath -> the balanced profile's recommendation, or None when that file could not be read.
29
+ # Kept for the process, including a failure: the next server picks up an edited file, not this one.
30
+ _RECOMMENDED = {}
31
+ _REC_LOCK = threading.Lock()
26
32
 
27
33
 
28
34
  def _alias(spec):
29
35
  return (spec.split(':', 1)[0] or None) if isinstance(spec, str) else None
30
36
 
31
37
 
38
+ def _builtin_profiles_path():
39
+ """scripts/forge_decide/builtin_profiles.json, located from this package the way reader._forge_infra finds
40
+ scripts/forge_infra.py. Read as data: forge-ui never imports forge_decide."""
41
+ return Path(__file__).resolve().parents[2] / 'scripts' / 'forge_decide' / 'builtin_profiles.json'
42
+
43
+
44
+ def _first_spec(pool):
45
+ """The first spec of a tier's routing pool, or None when the pool does not start with one."""
46
+ if isinstance(pool, list) and pool and isinstance(pool[0], str) and pool[0]:
47
+ return pool[0]
48
+ return None
49
+
50
+
51
+ def _recommended_from(data):
52
+ """balanced's dwarf per tier: the first spec of each routing.dwarf pool. None when that profile is not there."""
53
+ profiles = data.get('profiles') if isinstance(data, dict) else None
54
+ body = profiles.get('balanced') if isinstance(profiles, dict) else None
55
+ routing = body.get('routing') if isinstance(body, dict) else None
56
+ pools = routing.get('dwarf') if isinstance(routing, dict) else None
57
+ if not isinstance(pools, dict):
58
+ return None
59
+ dwarf = {}
60
+ for tier in _TIERS:
61
+ spec = _first_spec(pools.get(tier))
62
+ if spec:
63
+ dwarf[tier] = spec
64
+ if not dwarf:
65
+ return None
66
+ source = body.get('source')
67
+ return dict(profile='balanced', source=source if isinstance(source, str) else '', dwarf=dwarf)
68
+
69
+
70
+ def _load_recommended(path):
71
+ try:
72
+ data = json.loads(Path(path).read_text(encoding='utf-8'))
73
+ except (OSError, ValueError, RecursionError):
74
+ return None
75
+ return _recommended_from(data)
76
+
77
+
78
+ def recommended():
79
+ """The balanced built-in profile's dwarf per tier, or None when its file cannot be read. Cached per process."""
80
+ path = _builtin_profiles_path()
81
+ try:
82
+ key = os.path.realpath(path)
83
+ except OSError:
84
+ key = os.fspath(path)
85
+ with _REC_LOCK:
86
+ if key not in _RECOMMENDED:
87
+ _RECOMMENDED[key] = _load_recommended(path)
88
+ return _RECOMMENDED[key]
89
+
90
+
32
91
  def _attempt_rows(rd, name):
33
92
  """{n: (status, dwarf spec)} from attempts.tsv, oldest first. Infra-refunded rows spent no
34
93
  attempt; a QA-only resume reuses its number, so the number's last row holds its status."""
@@ -214,4 +273,4 @@ def collect(found):
214
273
  warnings += facts['warnings']
215
274
  count += 1
216
275
  return dict(generated=now, runs=count, truncated=truncated, tasks=tasks, reviews=reviews,
217
- warnings=warnings[:_MAX_WARNINGS])
276
+ warnings=warnings[:_MAX_WARNINGS], recommended=recommended())
@@ -1437,12 +1437,31 @@ _SOLO_SETTINGS = ('explore', 'shadow_rate', 'shadow_qa', 'timeout', 'max_paralle
1437
1437
  'escalate_after', 'verify_retries', 'final_qa')
1438
1438
 
1439
1439
 
1440
+ def _frozen_profile(reader):
1441
+ """settings.profile from profile.json: the name and level the run froze, and the dotted keys a flag
1442
+ of the run replaced (`overridden`, a list, empty when none).
1443
+
1444
+ None when the file is absent, unreadable, or not a frozen profile. The rest of the file (body,
1445
+ shadowed, frozen_at) stays on disk; the page asks the profile endpoints for a live body."""
1446
+ name = 'profile.json'
1447
+ obj = reader.object(name)
1448
+ if obj is None:
1449
+ return None
1450
+ profile_name, level, overridden = obj.get('name'), obj.get('level'), obj.get('overridden')
1451
+ if not (isinstance(profile_name, str) and profile_name and isinstance(level, str) and level
1452
+ and isinstance(overridden, list) and all(isinstance(key, str) for key in overridden)):
1453
+ reader.warn(name, 'not a profile')
1454
+ return None
1455
+ return dict(name=profile_name, level=level, overridden=overridden)
1456
+
1457
+
1440
1458
  def _solo_detail(reader, source):
1441
1459
  result = _solo_summary(reader, source)
1442
1460
  status = next(iter(result['counts']))
1443
1461
  result['request'] = reader.cap(reader.text('request.md'), 'request')
1444
1462
  result['settings'] = dict.fromkeys(_SOLO_SETTINGS)
1445
1463
  result['settings']['qa_threshold'], result['settings']['qa_threshold_source'] = _threshold(reader)
1464
+ result['settings']['profile'] = _frozen_profile(reader)
1446
1465
  result['verification'] = None
1447
1466
  result['attribution'] = _attribution(reader)
1448
1467
  result['waves'] = [['solo']]
@@ -1529,7 +1548,8 @@ def detail(path, source='plan') -> dict:
1529
1548
  max_parallel=reader.number('max_parallel', int),
1530
1549
  qa_threshold=threshold[0], qa_threshold_source=threshold[1],
1531
1550
  escalate_after=reader.number('escalate_after', int),
1532
- verify_retries=reader.number('verify_retries', int), final_qa=reader.line('final_qa'))
1551
+ verify_retries=reader.number('verify_retries', int), final_qa=reader.line('final_qa'),
1552
+ profile=_frozen_profile(reader))
1533
1553
  waves, wave_map = _waves(reader)
1534
1554
  result['waves'] = [waves.get(n, []) for n in range(1, max(waves, default=0) + 1)]
1535
1555
  branches = {row[0]: _nullable(row[2]) for _, row in reader.rows('results.tsv', 3)}
@@ -303,7 +303,11 @@ window.ForgeLeaderboard = (() => {
303
303
  const det = el('details', undefined, 'lb-diff'); det.open = prefs.open.includes(d);
304
304
  const sum = el('summary');
305
305
  sum.append(el('span', DIFF_LABEL[d], 'lb-diff-name'), el('span', `${plural(tasks, 'task')} · ${plural(rows.length, 'model')} · first-attempt pass ${n ? `${pct(k / n)} (${k}/${n})` : '—'}`, 'muted'));
306
- det.append(sum, implementerTable(rows, ctx, f.minN, `Implementers, ${DIFF_LABEL[d].toLowerCase()}`));
306
+ det.append(sum);
307
+ // The built-in profile's dwarf for this tier, under the summary. Nothing when the server sent none.
308
+ const rec = MS.recommendedLine(data && data.recommended, d, rows);
309
+ if (rec) det.append(el('p', rec, 'muted'));
310
+ det.append(implementerTable(rows, ctx, f.minN, `Implementers, ${DIFF_LABEL[d].toLowerCase()}`));
307
311
  det.addEventListener('toggle', () => {
308
312
  if (det.open === prefs.open.includes(d)) return;
309
313
  prefs.open = det.open ? prefs.open.concat(d) : prefs.open.filter(x => x !== d); save();
@@ -267,5 +267,29 @@
267
267
  return { state: 'rate', p: row.rate, lo: ci[0], hi: ci[1], ...base };
268
268
  }
269
269
 
270
- return { DIFFS, KINDS, SEVERITIES, DEFAULT_MIN_N, wilson, emptyFilter, normFilter, taskMatch, options, leaderboard, heldUp };
270
+ // The median model time as the recommendation's source writes times ("1.9 min"): minutes, one decimal.
271
+ function minutesText(s) {
272
+ s = num(s);
273
+ if (s === null) return '—';
274
+ const tenths = Math.round(Math.max(0, s) / 6);
275
+ const whole = Math.floor(tenths / 10), frac = tenths % 10;
276
+ return (frac ? whole + '.' + frac : String(whole)) + ' min';
277
+ }
278
+
279
+ // The line under a "By difficulty" tier. Null when `recommended` is absent or names no dwarf for `tier`
280
+ // (the page then shows nothing). `rows` are that tier's implementer rows: the alias's own median when
281
+ // it was measured there, otherwise the line says it has not run on the tier.
282
+ function recommendedLine(recommended, tier, rows) {
283
+ const rec = obj(recommended), dwarf = rec && obj(rec.dwarf);
284
+ const spec = dwarf && typeof dwarf[tier] === 'string' ? dwarf[tier] : '';
285
+ if (!spec) return null;
286
+ const profile = typeof rec.profile === 'string' ? rec.profile : '';
287
+ const source = typeof rec.source === 'string' ? rec.source : '';
288
+ const alias = spec.split(':')[0];
289
+ const row = alias ? list(rows).find(r => obj(r) && r.alias === alias) : null;
290
+ const tail = row ? 'your median model time ' + minutesText(row.medianModelS) : 'not run on this tier yet';
291
+ return `Recommended: ${spec} (built-in profile "${profile}", ${source}) · ${tail}`;
292
+ }
293
+
294
+ return { DIFFS, KINDS, SEVERITIES, DEFAULT_MIN_N, wilson, emptyFilter, normFilter, taskMatch, options, leaderboard, heldUp, recommendedLine };
271
295
  });
@@ -306,12 +306,28 @@ window.ForgePanel = (() => {
306
306
  parent.append(bar, legend);
307
307
  }
308
308
  const tokens = t => t ? `${display(t.input)} in (${display(t.cached)} cached) · ${display(t.output)} out` : '—';
309
+ // A tier row exists only when one was asked. A logged speed that is not that tier sits beside it, with the reason.
310
+ function tierText(m) {
311
+ const asked = m && m.service_tier;
312
+ if (!asked) return undefined;
313
+ const speed = m.speed;
314
+ if (!speed || speed === asked) return String(asked);
315
+ return m.speed_reason ? `${asked} asked · ran ${speed} (${m.speed_reason})` : `${asked} asked · ran ${speed}`;
316
+ }
309
317
  function modelFields(m) {
310
318
  if (!m) return [['Model', '—']];
311
- return [['Spec', m.spec ? plate(m.spec) : undefined], ['Harness', m.harness, true], ['Model', m.model, true], ['Effort', m.effort], m.clamped ? ['Clamped', m.clamped] : ['Clamped', undefined]];
319
+ return [['Spec', m.spec ? plate(m.spec) : undefined], ['Harness', m.harness, true], ['Model', m.model, true], ['Effort', m.effort],
320
+ ['Tier', tierText(m)], m.clamped ? ['Clamped', m.clamped] : ['Clamped', undefined]];
312
321
  }
313
322
 
314
323
  /* ---------- views ---------- */
324
+ // `NAME (level)`, plus the frozen flags when settings.profile lists them. No row when the run froze no profile.
325
+ function profileLine(settings) {
326
+ const profile = settings && settings.profile;
327
+ if (!profile || typeof profile !== 'object') return undefined;
328
+ const line = window.ForgeSettings && window.ForgeSettings.profileRowText && window.ForgeSettings.profileRowText(profile);
329
+ return line || undefined;
330
+ }
315
331
  // the run's record: what it was asked, how it was set up, and what verification printed (the header names and counts it)
316
332
  function runRecord(host, ctx) {
317
333
  const run = ctx.run, solo = run.kind === 'solo';
@@ -320,7 +336,8 @@ window.ForgePanel = (() => {
320
336
  ['Decompose', run.decompose_level], ['Updated', time(run.updated)], ['Explore', run.settings && run.settings.explore], ['Shadow rate', run.settings && run.settings.shadow_rate],
321
337
  ['Shadow reviewers', run.settings && plates(list(run.settings.shadow_qa))], ['QA threshold', run.settings && run.settings.qa_threshold && run.settings.qa_threshold + (run.settings.qa_threshold_source === 'default' ? ' (default)' : '')],
322
338
  ['Max parallel', run.settings && run.settings.max_parallel], ['Final reviewer', run.settings && run.settings.final_qa ? plate(run.settings.final_qa) : undefined],
323
- ['Timeout (seconds)', run.settings && run.settings.timeout], ['Verification', chip((run.verification && run.verification.status) || run.verification_status)],
339
+ ['Timeout (seconds)', run.settings && run.settings.timeout], ['Profile', profileLine(run.settings)],
340
+ ['Verification', chip((run.verification && run.verification.status) || run.verification_status)],
324
341
  ['Command', run.verification && run.verification.command, true]]);
325
342
  details(host, 'Request', display(run.request), 'run-request');
326
343
  if (!solo) details(host, 'Waves', list(run.waves).map((ids, i) => `${i + 1}: ${list(ids).join(', ')}`).join('\n') || '—', 'waves');