@giamme/forge 0.12.0 → 0.12.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 +22 -0
- package/SKILL.md +3 -1
- package/VERSION +1 -1
- package/docs/artifacts.md +6 -0
- package/docs/commands.md +11 -1
- package/docs/forge-ui.md +28 -2
- package/docs/reviews.md +33 -0
- package/package.json +1 -1
- package/references/dataset.md +1 -1
- package/references/decompose.md +32 -0
- package/references/ui.md +11 -0
- package/scripts/forge-contract.py +37 -7
- package/scripts/forge-dispatch.sh +12 -2
- package/scripts/forge-issues.py +47 -3
- package/scripts/forge-lib-review.sh +2 -2
- package/scripts/forge-lib-task.sh +2 -1
- package/scripts/forge-parallel-options.sh +26 -0
- package/scripts/forge-parallel.sh +50 -3
- package/scripts/forge-runtime.py +49 -1
- package/scripts/forge-schedule.py +49 -4
- package/scripts/forge-solo.sh +3 -1
- package/scripts/forge-sweep.py +542 -0
- package/scripts/forge_dataset/forecast.py +4 -1
- package/ui/README.md +40 -9
- package/ui/docs/api.md +154 -14
- package/ui/forge_ui/checks.py +331 -0
- package/ui/forge_ui/export.py +7 -3
- package/ui/forge_ui/reader.py +350 -13
- package/ui/forge_ui/server.py +13 -0
- package/ui/forge_ui/static/app.js +13 -6
- package/ui/forge_ui/static/checksview.js +449 -0
- package/ui/forge_ui/static/convo.js +11 -2
- package/ui/forge_ui/static/findingsview.js +6 -4
- package/ui/forge_ui/static/index.html +1 -0
- package/ui/forge_ui/static/panel.js +42 -0
- package/ui/forge_ui/static/runmodel.js +17 -1
- package/ui/forge_ui/static/style.css +53 -0
- package/ui/forge_ui/transcripts.py +225 -54
package/ui/forge_ui/export.py
CHANGED
|
@@ -26,7 +26,7 @@ from forge_ui import __version__, reader, server
|
|
|
26
26
|
|
|
27
27
|
STATIC = server.STATIC_DIR
|
|
28
28
|
# what the exported page runs, in index.html's order; the cloud, the leaderboard and notifications need a server
|
|
29
|
-
SCRIPTS = ('theme.js', 'icons.js', 'datatable.js', 'shell.js', 'runmodel.js', 'cloudmodel.js', 'graph.js', 'gantt.js', 'verifyview.js', 'panel.js', 'diffview.js', 'convo.js', 'files.js', 'map3d.js',
|
|
29
|
+
SCRIPTS = ('theme.js', 'icons.js', 'datatable.js', 'shell.js', 'runmodel.js', 'cloudmodel.js', 'graph.js', 'gantt.js', 'verifyview.js', 'checksview.js', 'panel.js', 'diffview.js', 'convo.js', 'files.js', 'map3d.js',
|
|
30
30
|
'search.js', 'app.js')
|
|
31
31
|
MODULES = ('iso.js', 'cloud3d.js', 'findings3d.js', 'stagectl.js', 'scene3d.js') # bundled in dependency order
|
|
32
32
|
DIFF_CAP = 1 << 20 # one diff's JSON
|
|
@@ -37,7 +37,7 @@ _EXEC = re.compile(r'(?:task|dwarf|qa|solo|verification|parallel)-[0-9a-f]{32}')
|
|
|
37
37
|
# texts that can hold code, prompts or private notes: nulled unless texts=True
|
|
38
38
|
_TEXT_KEYS = frozenset(('prompt', 'last', 'request', 'log_tail', 'dwarf_tail', 'qa_tail', 'qa_last', 'qa_input',
|
|
39
39
|
'tasks_summary', 'known_issues', 'texts', 'text', 'planning_last', 'approach', 'retry_findings',
|
|
40
|
-
'dwarf_input', 'error', 'last_line', 'message', 'excerpt', 'tail', 'lines'))
|
|
40
|
+
'dwarf_input', 'error', 'last_line', 'message', 'excerpt', 'tail', 'lines', 'call', 'split'))
|
|
41
41
|
|
|
42
42
|
|
|
43
43
|
def _enc(value):
|
|
@@ -188,10 +188,14 @@ def build(catalog, key, texts=False, paths=False, now=None):
|
|
|
188
188
|
snap.add(url, cap=DIFF_CAP)
|
|
189
189
|
for name in reviews:
|
|
190
190
|
snap.add(f'{base}/final-reviews/{_enc(name)}/diff', cap=DIFF_CAP)
|
|
191
|
-
# what each dwarf and reviewer said and ran: its conversation is all text
|
|
191
|
+
# what each dwarf and reviewer said and ran: its conversation is all text, and so are the commands it ran
|
|
192
192
|
for name in names:
|
|
193
193
|
if name.startswith(('dwarf-', 'qa-')):
|
|
194
194
|
snap.add(f'{base}/executions/{name}/transcript', cap=TRANSCRIPT_CAP)
|
|
195
|
+
snap.add(f'{base}/executions/{name}/checks')
|
|
196
|
+
for task in tasks:
|
|
197
|
+
snap.add(f"{base}/tasks/{_enc(task['id'])}/checks")
|
|
198
|
+
snap.add(f'{base}/environment')
|
|
195
199
|
# the verification's log tails: its own, each lane's and each lane run's (line ranges stay out)
|
|
196
200
|
verification = run.get('verification') or {}
|
|
197
201
|
if verification:
|
package/ui/forge_ui/reader.py
CHANGED
|
@@ -12,7 +12,7 @@ import stat
|
|
|
12
12
|
import time
|
|
13
13
|
import urllib.parse
|
|
14
14
|
|
|
15
|
-
from forge_ui import diffs, executions, findings, fractal, transcripts
|
|
15
|
+
from forge_ui import checks, diffs, executions, findings, fractal, transcripts
|
|
16
16
|
from forge_ui.findings import verdict as _verdict
|
|
17
17
|
|
|
18
18
|
|
|
@@ -545,6 +545,133 @@ def _accepted_fields(reader, name, text):
|
|
|
545
545
|
return attempt, status if status in ('FAIL', 'UNKNOWN') else None
|
|
546
546
|
|
|
547
547
|
|
|
548
|
+
def _log_path(reader, rel):
|
|
549
|
+
"""The regular file `rel` of the run dir as a Path, or None; a path that resolves outside the run is never read."""
|
|
550
|
+
try:
|
|
551
|
+
real = Path(os.path.realpath(reader.path / rel))
|
|
552
|
+
if executions.inside(reader.path, str(real)) and stat.S_ISREG(real.stat().st_mode):
|
|
553
|
+
return real
|
|
554
|
+
if real.exists():
|
|
555
|
+
reader.warn(rel, 'outside the run dir or not a regular file')
|
|
556
|
+
except (OSError, ValueError):
|
|
557
|
+
pass
|
|
558
|
+
return None
|
|
559
|
+
|
|
560
|
+
|
|
561
|
+
_CALL_CAP = 400 # characters of the running command in RunDetail
|
|
562
|
+
|
|
563
|
+
|
|
564
|
+
def _now(reader, owner_dir, execs):
|
|
565
|
+
"""Task.now: where a running task (or solo run) is. The dwarf or reviewer running in it, with the call it is
|
|
566
|
+
making and when its log last moved; else the task execution's own phase."""
|
|
567
|
+
running = [item for item in execs if item['state'] == 'running' and not item['shadow']]
|
|
568
|
+
agent = next((item for item in reversed(running) if item['role'] in ('dwarf', 'qa')), None)
|
|
569
|
+
item = agent or next((item for item in reversed(running) if item['role'] in executions.CONTAINERS), None)
|
|
570
|
+
if item is None:
|
|
571
|
+
return None
|
|
572
|
+
now = dict(role=item['role'], execution=item['id'], attempt=item['attempt'], phase=item['phase'],
|
|
573
|
+
phase_started=item['phase_started'], started=item['started'], last_output_at=None, call=None)
|
|
574
|
+
if agent is not None:
|
|
575
|
+
rel = posixpath.join(owner_dir, agent['role'] + '.log')
|
|
576
|
+
reader.stat(rel) # the page redraws while the agent writes
|
|
577
|
+
log = _log_path(reader, rel)
|
|
578
|
+
state = transcripts.live(log, (agent['model'] or {}).get('harness')) if log is not None else None
|
|
579
|
+
if state is not None:
|
|
580
|
+
call = state['call']
|
|
581
|
+
if call is not None:
|
|
582
|
+
command = call['command']
|
|
583
|
+
call = dict(call, command=command if not command or len(command) <= _CALL_CAP else command[:_CALL_CAP] + '…',
|
|
584
|
+
check=checks.classify(command) if command else None)
|
|
585
|
+
now.update(last_output_at=state['last_output_at'], call=call)
|
|
586
|
+
return now
|
|
587
|
+
|
|
588
|
+
|
|
589
|
+
def _scheduler(reader):
|
|
590
|
+
"""RunDetail.scheduler: whether a scheduler runs this plan now, and, while one does, what holds it: a drain, a
|
|
591
|
+
stop, infrastructure pauses (scheduler-written infra.paused) and the capacity it dispatches up to."""
|
|
592
|
+
pid = (reader.object('scheduler.live') or {}).get('pid') if reader.exists('scheduler.live') else None
|
|
593
|
+
live = False
|
|
594
|
+
if type(pid) is int and pid > 0:
|
|
595
|
+
try:
|
|
596
|
+
os.kill(pid, 0)
|
|
597
|
+
live = True
|
|
598
|
+
except PermissionError:
|
|
599
|
+
live = True
|
|
600
|
+
except (OSError, OverflowError):
|
|
601
|
+
live = False
|
|
602
|
+
result = dict(live=live, drained=False, stopping=None, pauses=[], max_parallel=None)
|
|
603
|
+
if not live:
|
|
604
|
+
return result
|
|
605
|
+
stop = reader.line('stop')
|
|
606
|
+
capacity = reader.number('max_parallel', int)
|
|
607
|
+
result.update(drained=reader.exists('drain'), stopping=stop if stop in ('graceful', 'now') else None,
|
|
608
|
+
max_parallel=capacity if capacity is not None and 1 <= capacity <= 64 else None)
|
|
609
|
+
paused = reader.object('infra.paused') if reader.exists('infra.paused') else None
|
|
610
|
+
for scope in (paused or {}).get('scopes') or []:
|
|
611
|
+
if isinstance(scope, dict):
|
|
612
|
+
result['pauses'].append({key: scope.get(key) for key in
|
|
613
|
+
('scope', 'class', 'harness', 'model', 'tasks', 'cycle', 'until', 'exhausted')})
|
|
614
|
+
return result
|
|
615
|
+
|
|
616
|
+
|
|
617
|
+
_STOPPED = ('FAIL', 'BLOCKED', 'INFRA', 'INTERRUPTED', 'TIMEOUT', 'ERROR', 'CONFLICT', 'NOCHANGES', 'INVALIDATED', 'UNKNOWN')
|
|
618
|
+
|
|
619
|
+
|
|
620
|
+
def _escalation_stop(reader, ident):
|
|
621
|
+
"""The retry policy stopped this task: {attempts, model, split} from escalation.stop and split.suggested."""
|
|
622
|
+
text = reader.text(f'tasks/{ident}/escalation.stop')
|
|
623
|
+
if text is None:
|
|
624
|
+
return None
|
|
625
|
+
cells = (text.splitlines() or [''])[0].split('\t')
|
|
626
|
+
attempts = int(cells[0]) if cells[0].strip().isdigit() else None
|
|
627
|
+
split = (reader.text(f'tasks/{ident}/split.suggested') or '').strip()
|
|
628
|
+
return dict(kind='escalation', attempts=attempts, model=cells[1].strip() if len(cells) > 1 and cells[1].strip() else None,
|
|
629
|
+
split=reader.cap(split, f'tasks/{ident}/split.suggested', 600) or None)
|
|
630
|
+
|
|
631
|
+
|
|
632
|
+
def _waiting(reader, tasks, scheduler):
|
|
633
|
+
"""Task.waiting: why a task that is not running is not, as far as the run dir tells.
|
|
634
|
+
|
|
635
|
+
escalation (the retry policy stopped it, whether or not a scheduler runs); and while one runs: infra (a pause
|
|
636
|
+
holds it), deps (on tasks not merged yet), drained, stopping, overlap (it shares files with a running task),
|
|
637
|
+
slot (the run is at its capacity) or next (nothing holds it: it starts at the scheduler's next turn)."""
|
|
638
|
+
status = {task['id']: task['status'] for task in tasks}
|
|
639
|
+
running = [task for task in tasks if task['status'] == 'RUNNING']
|
|
640
|
+
for task in tasks:
|
|
641
|
+
task['waiting'] = None
|
|
642
|
+
if task['status'] in ('RUNNING', 'MERGED'):
|
|
643
|
+
continue
|
|
644
|
+
stop = _escalation_stop(reader, task['id'])
|
|
645
|
+
if stop is not None:
|
|
646
|
+
task['waiting'] = stop
|
|
647
|
+
continue
|
|
648
|
+
if not scheduler['live'] or task['status'] not in ('PENDING', 'INFRA'):
|
|
649
|
+
continue
|
|
650
|
+
pause = next((p for p in scheduler['pauses'] if p['scope'] == 'all' or task['id'] in (p['tasks'] or [])), None)
|
|
651
|
+
if pause is not None:
|
|
652
|
+
task['waiting'] = dict(pause, kind='infra')
|
|
653
|
+
continue
|
|
654
|
+
if task['status'] != 'PENDING':
|
|
655
|
+
continue
|
|
656
|
+
on = [dep for dep in task['deps'] if status.get(dep) != 'MERGED']
|
|
657
|
+
if on:
|
|
658
|
+
task['waiting'] = dict(kind='deps', on=on, stopped=[dep for dep in on if status.get(dep) in _STOPPED])
|
|
659
|
+
elif scheduler['stopping']:
|
|
660
|
+
task['waiting'] = dict(kind='stopping', mode=scheduler['stopping'])
|
|
661
|
+
elif scheduler['drained']:
|
|
662
|
+
task['waiting'] = dict(kind='drained')
|
|
663
|
+
else:
|
|
664
|
+
mine = [_scope(path) for path in task['files'] if path and path != '-']
|
|
665
|
+
shared = [other['id'] for other in running if _overlap(mine, [_scope(p) for p in other['files'] if p and p != '-'])]
|
|
666
|
+
cap = scheduler['max_parallel']
|
|
667
|
+
if shared:
|
|
668
|
+
task['waiting'] = dict(kind='overlap', on=shared)
|
|
669
|
+
elif cap is not None and len(running) >= cap:
|
|
670
|
+
task['waiting'] = dict(kind='slot', running=len(running), max_parallel=cap)
|
|
671
|
+
else:
|
|
672
|
+
task['waiting'] = dict(kind='next')
|
|
673
|
+
|
|
674
|
+
|
|
548
675
|
def _task_detail(reader, task, run_id, waves, branches):
|
|
549
676
|
"""Fill in a plan task; returns every execution it read (its own and its shadows')."""
|
|
550
677
|
ident = task['id']
|
|
@@ -587,12 +714,15 @@ def _task_detail(reader, task, run_id, waves, branches):
|
|
|
587
714
|
task['clef']['retry_pass'][suffix] = obj
|
|
588
715
|
execs = _task_execs(reader, task)
|
|
589
716
|
task['executions'] = execs
|
|
717
|
+
task['now'] = _now(reader, prefix, execs) if task['status'] == 'RUNNING' else None
|
|
590
718
|
merged = reader.stat(prefix + '/merged') if task['status'] == 'MERGED' else None
|
|
591
719
|
task['merged_at'] = float(merged.st_mtime) if merged is not None else None
|
|
592
720
|
task['findings'] = executions.summary_of(qa)
|
|
593
721
|
task['gate'] = _gate(reader, prefix + '/qa.gate')
|
|
594
722
|
task['known_issues'] = _nonempty(reader, prefix + '/known_issues.md')
|
|
595
723
|
task['fail_first'] = _fail_first(reader, prefix + '/failfirst.json')
|
|
724
|
+
task['sweep'] = _sweep_task(reader, prefix, task['status'])
|
|
725
|
+
task['swept'] = []
|
|
596
726
|
shadows = _shadows(reader, ident, execs)
|
|
597
727
|
task['shadow'] = [entry for entry, _, _ in shadows]
|
|
598
728
|
# What `forge control show` reads of the task. A change there (a write, or a delete: the dir's mtime) moves `updated`,
|
|
@@ -603,6 +733,73 @@ def _task_detail(reader, task, run_id, waves, branches):
|
|
|
603
733
|
return execs + [item for _, items, _ in shadows for item in items]
|
|
604
734
|
|
|
605
735
|
|
|
736
|
+
# --- the finding sweep (run --sweep): its plan, each fix task's findings and what became of them ------------------
|
|
737
|
+
|
|
738
|
+
_MAX_SWEEP = 200
|
|
739
|
+
_SWEEP_STATES = ('fixed', 'not-fixed', 'unreported')
|
|
740
|
+
|
|
741
|
+
|
|
742
|
+
def _text_or_none(value, size=400):
|
|
743
|
+
return value[:size] if isinstance(value, str) and value else None
|
|
744
|
+
|
|
745
|
+
|
|
746
|
+
def _sweep_task(reader, prefix, status):
|
|
747
|
+
"""A fix task's file and findings: each with what its review said (fixed, not-fixed, or unreported when the
|
|
748
|
+
task merged without a line for it), or None while the task has not merged; None for any other task."""
|
|
749
|
+
obj = reader.object(prefix + '/sweep.json')
|
|
750
|
+
if obj is None or not isinstance(obj.get('findings'), list):
|
|
751
|
+
return None
|
|
752
|
+
said = {}
|
|
753
|
+
if status == 'MERGED':
|
|
754
|
+
for item in list((reader.object(prefix + '/sweep.outcome.json') or {}).get('findings') or []):
|
|
755
|
+
if isinstance(item, dict) and item.get('status') in _SWEEP_STATES and isinstance(item.get('id'), str):
|
|
756
|
+
said[item['id']] = (item['status'], _text_or_none(item.get('note')))
|
|
757
|
+
found = []
|
|
758
|
+
for item in obj['findings'][:_MAX_SWEEP]:
|
|
759
|
+
if not isinstance(item, dict) or not isinstance(item.get('id'), str):
|
|
760
|
+
continue
|
|
761
|
+
state, note = said.get(item['id'], ('unreported' if status == 'MERGED' else None, None))
|
|
762
|
+
found.append(dict(id=item['id'], severity=_text_or_none(item.get('severity'), 8),
|
|
763
|
+
confidence=_text_or_none(item.get('confidence'), 16), task=_text_or_none(item.get('task'), 200),
|
|
764
|
+
location=_text_or_none(item.get('location')),
|
|
765
|
+
summary=_text_or_none((item.get('text') or '').split('\n')[0] if isinstance(item.get('text'), str) else None),
|
|
766
|
+
status=state, note=note))
|
|
767
|
+
return dict(file=_text_or_none(obj.get('file')), findings=found)
|
|
768
|
+
|
|
769
|
+
|
|
770
|
+
def _sweep(reader, tasks):
|
|
771
|
+
"""RunDetail.sweep: the run's finding sweep, from sweep/plan.json and its fix tasks; None when it was never
|
|
772
|
+
swept. Also fills each source task's `swept`: its findings a fix task took, and what became of them."""
|
|
773
|
+
by_id = {task['id']: task for task in tasks}
|
|
774
|
+
fix = [task for task in tasks if task.get('sweep')]
|
|
775
|
+
for task in fix:
|
|
776
|
+
for item in task['sweep']['findings']:
|
|
777
|
+
source = by_id.get(item['task'])
|
|
778
|
+
if source is not None and len(source['swept']) < _MAX_SWEEP:
|
|
779
|
+
source['swept'].append(dict(item, by=task['id']))
|
|
780
|
+
obj = reader.object('sweep/plan.json')
|
|
781
|
+
if obj is None:
|
|
782
|
+
return None
|
|
783
|
+
found = [item for task in fix for item in task['sweep']['findings']]
|
|
784
|
+
dropped = []
|
|
785
|
+
for item in list(obj.get('dropped') or [])[:_MAX_SWEEP]:
|
|
786
|
+
if not isinstance(item, dict):
|
|
787
|
+
continue
|
|
788
|
+
line = item.get('line') if isinstance(item.get('line'), int) and not isinstance(item.get('line'), bool) else None
|
|
789
|
+
where = _text_or_none(item.get('file'))
|
|
790
|
+
detail = item.get('detail') if isinstance(item.get('detail'), dict) else {}
|
|
791
|
+
dropped.append(dict(task=_text_or_none(item.get('task'), 200), severity=_text_or_none(item.get('severity'), 8),
|
|
792
|
+
location=f'{where}:{line}' if where and line else where,
|
|
793
|
+
summary=_text_or_none((item.get('text') or '').split('\n')[0] if isinstance(item.get('text'), str) else None),
|
|
794
|
+
reason=_text_or_none(item.get('reason'), 40),
|
|
795
|
+
merged_since=[x for x in list(detail.get('merged_since') or []) if isinstance(x, str)][:20]))
|
|
796
|
+
at = obj.get('at')
|
|
797
|
+
return dict(at=float(at) if isinstance(at, (int, float)) and not isinstance(at, bool) else None,
|
|
798
|
+
severity=_text_or_none(obj.get('severity'), 8), plausible=obj.get('plausible') is True,
|
|
799
|
+
tasks=[task['id'] for task in fix], findings=len(found),
|
|
800
|
+
fixed=sum(1 for item in found if item['status'] == 'fixed'), dropped=dropped)
|
|
801
|
+
|
|
802
|
+
|
|
606
803
|
# The control files (CONTRACT.md) nothing else here reads. `forge control` appends control.log and writes the task's
|
|
607
804
|
# files without touching the run dir, so they are stat'd for `updated` only.
|
|
608
805
|
# Read only for their mtimes, so the run's `updated` stamp moves when a control changes.
|
|
@@ -1061,9 +1258,11 @@ def _solo_detail(reader, source):
|
|
|
1061
1258
|
dwarf_tail=reader.cap(reader.text('dwarf.last'), 'tasks/solo/dwarf_tail', 4000, True),
|
|
1062
1259
|
executions=execs, merged_at=None, findings=executions.summary_of(qa),
|
|
1063
1260
|
gate=_gate(reader, 'qa.gate'), known_issues=_nonempty(reader, 'known_issues.md'),
|
|
1064
|
-
fail_first=_fail_first(reader, 'failfirst.json')
|
|
1261
|
+
fail_first=_fail_first(reader, 'failfirst.json'),
|
|
1262
|
+
now=_now(reader, '', execs) if status == 'RUNNING' else None, waiting=None, sweep=None, swept=[])
|
|
1065
1263
|
result.update(timeline=_timeline(execs, [], []), integration=None, final_review=None, final_reviews=[],
|
|
1066
|
-
deferrals=[], findings_available=findings.available(), fractal=fractal.summary(reader)
|
|
1264
|
+
deferrals=[], findings_available=findings.available(), fractal=fractal.summary(reader),
|
|
1265
|
+
scheduler=None, sweep=None)
|
|
1067
1266
|
result.update(tasks=[task], warnings=reader.warnings, truncated=reader.truncated, updated=reader.updated)
|
|
1068
1267
|
return result
|
|
1069
1268
|
|
|
@@ -1102,6 +1301,9 @@ def detail(path, source='plan') -> dict:
|
|
|
1102
1301
|
pool += _task_detail(reader, task, result['run_id'], wave_map, branches)
|
|
1103
1302
|
for name in _RUN_CONTROLS:
|
|
1104
1303
|
reader.stat(name)
|
|
1304
|
+
result['scheduler'] = _scheduler(reader)
|
|
1305
|
+
_waiting(reader, tasks, result['scheduler'])
|
|
1306
|
+
result['sweep'] = _sweep(reader, tasks)
|
|
1105
1307
|
run_execs = _run_execs(reader)
|
|
1106
1308
|
result['verification'] = _verification(reader, result['verification_status'],
|
|
1107
1309
|
[item for item in run_execs if item['role'] == 'verification'])
|
|
@@ -1264,16 +1466,7 @@ def execution_transcript(path, name, source='plan'):
|
|
|
1264
1466
|
item, owner, owner_dir = found
|
|
1265
1467
|
role, running = item['role'], item['state'] == 'running'
|
|
1266
1468
|
# A finished execution's log is its copy; the owner dir's is the one being written, or the next one's.
|
|
1267
|
-
|
|
1268
|
-
log = None
|
|
1269
|
-
try:
|
|
1270
|
-
real = Path(os.path.realpath(reader.path / rel))
|
|
1271
|
-
if executions.inside(reader.path, str(real)) and stat.S_ISREG(real.stat().st_mode):
|
|
1272
|
-
log = real
|
|
1273
|
-
elif real.exists():
|
|
1274
|
-
reader.warn(rel, 'outside the run dir or not a regular file')
|
|
1275
|
-
except (OSError, ValueError):
|
|
1276
|
-
pass
|
|
1469
|
+
log = _agent_log(reader, item, owner_dir)
|
|
1277
1470
|
resolved = executions.resolved_of(reader, f'{item.rel}/{role}.resolved')
|
|
1278
1471
|
if resolved is None and running:
|
|
1279
1472
|
resolved = executions.parse_resolved(reader.text(posixpath.join(owner_dir, role + '.resolved'))) or None
|
|
@@ -1285,6 +1478,141 @@ def execution_transcript(path, name, source='plan'):
|
|
|
1285
1478
|
return result
|
|
1286
1479
|
|
|
1287
1480
|
|
|
1481
|
+
def _agent_log(reader, item, owner_dir):
|
|
1482
|
+
"""The log of a dwarf or reviewer execution: its copy once it ended, the one being written while it runs."""
|
|
1483
|
+
role = item['role']
|
|
1484
|
+
return _log_path(reader, posixpath.join(owner_dir, role + '.log') if item['state'] == 'running' else f'{item.rel}/{role}.log')
|
|
1485
|
+
|
|
1486
|
+
|
|
1487
|
+
def _checks_of(reader, item, owner_dir):
|
|
1488
|
+
"""checks.analyze() of one dwarf or reviewer execution, with what it is and, while it runs, when its log moved."""
|
|
1489
|
+
log = _agent_log(reader, item, owner_dir)
|
|
1490
|
+
model = item['model'] or {}
|
|
1491
|
+
running = item['state'] == 'running'
|
|
1492
|
+
result = transcripts.transcript(log, model.get('harness'), running)
|
|
1493
|
+
found = checks.analyze(result['events'])
|
|
1494
|
+
moved = None
|
|
1495
|
+
if running and log is not None:
|
|
1496
|
+
try:
|
|
1497
|
+
moved = log.stat().st_mtime
|
|
1498
|
+
except OSError:
|
|
1499
|
+
pass
|
|
1500
|
+
found.update(execution=item['id'], role=item['role'], state=item['state'], attempt=item['attempt'],
|
|
1501
|
+
spec=model.get('spec'), harness=model.get('harness'), source=result['source'],
|
|
1502
|
+
truncated=result['truncated'], last_output_at=moved)
|
|
1503
|
+
return found
|
|
1504
|
+
|
|
1505
|
+
|
|
1506
|
+
def _brief_dir(kind, owner):
|
|
1507
|
+
"""Where the brief of an execution's owner is, or None for a final review or a shadow."""
|
|
1508
|
+
if owner['kind'] == 'task':
|
|
1509
|
+
return '' if owner['id'] == 'solo' and kind == 'solo' else f"tasks/{owner['id']}"
|
|
1510
|
+
return None
|
|
1511
|
+
|
|
1512
|
+
|
|
1513
|
+
def execution_checks(path, name, source='plan'):
|
|
1514
|
+
"""ExecutionChecks: the checks a dwarf or reviewer ran, the call it makes now, the environment problems it met
|
|
1515
|
+
and, for a task's execution, its brief's acceptance-criteria commands against them. None for another role."""
|
|
1516
|
+
reader = _Read(path)
|
|
1517
|
+
found = _execution(reader, name)
|
|
1518
|
+
if found is None or found[0]['role'] not in ('dwarf', 'qa'):
|
|
1519
|
+
return None
|
|
1520
|
+
item, owner, owner_dir = found
|
|
1521
|
+
result = _checks_of(reader, item, owner_dir)
|
|
1522
|
+
brief = _brief_dir(_kind(reader.path), owner)
|
|
1523
|
+
wanted = checks.criteria(reader.text(posixpath.join(brief, 'prompt.md'))) if brief is not None else []
|
|
1524
|
+
result.update(run=run_key(reader.path), owner=owner,
|
|
1525
|
+
criteria=checks.coverage(wanted, [(c['command'], dict(index=c['index'])) for c in result['checks']]),
|
|
1526
|
+
warnings=reader.warnings)
|
|
1527
|
+
return result
|
|
1528
|
+
|
|
1529
|
+
|
|
1530
|
+
def _owners(reader):
|
|
1531
|
+
"""(task id, owner dir, executions) of each task of the run (the one `solo` of a solo run), or None."""
|
|
1532
|
+
kind = _kind(reader.path)
|
|
1533
|
+
if kind == 'solo':
|
|
1534
|
+
return [('solo', '', _solo_execs(reader, _solo_status(reader), _history(reader, 'attempts.tsv')))]
|
|
1535
|
+
if kind != 'plan':
|
|
1536
|
+
return None
|
|
1537
|
+
out = []
|
|
1538
|
+
for task in _tasks(reader):
|
|
1539
|
+
task['attempts'], task['attempt'] = _attempt_state(reader, f"tasks/{task['id']}")
|
|
1540
|
+
out.append((task['id'], f"tasks/{task['id']}", _task_execs(reader, task)))
|
|
1541
|
+
return out
|
|
1542
|
+
|
|
1543
|
+
|
|
1544
|
+
def task_checks(path, task_id, source='plan'):
|
|
1545
|
+
"""TaskChecks: attempt by attempt, the checks each dwarf and reviewer ran, and which of the commands the task's
|
|
1546
|
+
acceptance criteria name ran, ran another way, or did not run."""
|
|
1547
|
+
reader = _Read(path)
|
|
1548
|
+
owners = _owners(reader)
|
|
1549
|
+
owner = next((item for item in owners or [] if item[0] == task_id), None)
|
|
1550
|
+
if owner is None:
|
|
1551
|
+
return None
|
|
1552
|
+
_, owner_dir, execs = owner
|
|
1553
|
+
wanted = checks.criteria(reader.text(posixpath.join(owner_dir, 'prompt.md')))
|
|
1554
|
+
by_attempt = {}
|
|
1555
|
+
for item in execs:
|
|
1556
|
+
if item['role'] in ('dwarf', 'qa') and not item['shadow']:
|
|
1557
|
+
by_attempt.setdefault(item['attempt'], []).append(_checks_of(reader, item, owner_dir))
|
|
1558
|
+
attempts = []
|
|
1559
|
+
for attempt in sorted(by_attempt, key=lambda value: (value is None, value or 0)):
|
|
1560
|
+
runs = by_attempt[attempt]
|
|
1561
|
+
ran = [(c['command'], dict(execution=r['execution'], role=r['role'], index=c['index'])) for r in runs for c in r['checks']]
|
|
1562
|
+
attempts.append(dict(attempt=attempt, running=any(r['state'] == 'running' for r in runs), executions=runs,
|
|
1563
|
+
criteria=checks.coverage(wanted, ran)))
|
|
1564
|
+
return dict(run=run_key(reader.path), task=task_id, criteria=wanted, attempts=attempts,
|
|
1565
|
+
truncated=reader.truncated, warnings=reader.warnings)
|
|
1566
|
+
|
|
1567
|
+
|
|
1568
|
+
_ENVIRONMENT_HITS = 50 # a problem's hits answered (its tasks are all named)
|
|
1569
|
+
_ENV_CACHE = executions._SigCache(4096)
|
|
1570
|
+
|
|
1571
|
+
|
|
1572
|
+
def _environment_of(reader, item, owner_dir):
|
|
1573
|
+
"""The environment problems one execution's failed commands met, cached while its log is unchanged."""
|
|
1574
|
+
log = _agent_log(reader, item, owner_dir)
|
|
1575
|
+
if log is None:
|
|
1576
|
+
return []
|
|
1577
|
+
try:
|
|
1578
|
+
info = log.stat()
|
|
1579
|
+
except OSError:
|
|
1580
|
+
return []
|
|
1581
|
+
clock = log.with_name(log.stem + '.clock')
|
|
1582
|
+
sig = (executions._signature(info), item['state'], transcripts._signature(clock))
|
|
1583
|
+
hit = _ENV_CACHE.get(('environment', str(log)), sig)
|
|
1584
|
+
if hit is None:
|
|
1585
|
+
result = transcripts.transcript(log, (item['model'] or {}).get('harness'), item['state'] == 'running')
|
|
1586
|
+
hit = checks.analyze(result['events'])['environment']
|
|
1587
|
+
_ENV_CACHE.put(('environment', str(log)), sig, hit)
|
|
1588
|
+
return hit
|
|
1589
|
+
|
|
1590
|
+
|
|
1591
|
+
def run_environment(path, source='plan'):
|
|
1592
|
+
"""RunEnvironment: each environment problem the run's dwarfs and reviewers met (Docker, a sandbox's EPERM, a
|
|
1593
|
+
port in use, …), with the tasks it hit and where: the commands that failed on it."""
|
|
1594
|
+
reader = _Read(path)
|
|
1595
|
+
owners = _owners(reader)
|
|
1596
|
+
if owners is None:
|
|
1597
|
+
return None
|
|
1598
|
+
found = {}
|
|
1599
|
+
for task_id, owner_dir, execs in owners:
|
|
1600
|
+
for item in execs:
|
|
1601
|
+
if item['role'] not in ('dwarf', 'qa'):
|
|
1602
|
+
continue
|
|
1603
|
+
for hit in _environment_of(reader, item, owner_dir):
|
|
1604
|
+
entry = found.setdefault(hit['problem'], dict(problem=hit['problem'], label=checks.LABELS[hit['problem']],
|
|
1605
|
+
tasks=[], count=0, hits=[]))
|
|
1606
|
+
entry['count'] += 1
|
|
1607
|
+
if task_id not in entry['tasks']:
|
|
1608
|
+
entry['tasks'].append(task_id)
|
|
1609
|
+
if len(entry['hits']) < _ENVIRONMENT_HITS:
|
|
1610
|
+
entry['hits'].append(dict(task=task_id, attempt=item['attempt'], role=item['role'], execution=item['id'],
|
|
1611
|
+
index=hit['index'], command=hit['command'], line=hit['line']))
|
|
1612
|
+
problems = [found[key] for key, _, _ in checks.ENVIRONMENT if key in found]
|
|
1613
|
+
return dict(run=run_key(reader.path), problems=problems, warnings=reader.warnings)
|
|
1614
|
+
|
|
1615
|
+
|
|
1288
1616
|
def final_review_detail(path, name, source='plan'):
|
|
1289
1617
|
"""FinalReviewDetail of final-review-<e>-<p> or integrate-<e>-<p>, or None."""
|
|
1290
1618
|
reader = _Read(path)
|
|
@@ -1892,6 +2220,15 @@ class Catalog:
|
|
|
1892
2220
|
def transcript(self, key, name):
|
|
1893
2221
|
return self._find(key, execution_transcript, name)
|
|
1894
2222
|
|
|
2223
|
+
def execution_checks(self, key, name):
|
|
2224
|
+
return self._find(key, execution_checks, name)
|
|
2225
|
+
|
|
2226
|
+
def task_checks(self, key, task_id):
|
|
2227
|
+
return self._find(key, task_checks, task_id)
|
|
2228
|
+
|
|
2229
|
+
def environment(self, key):
|
|
2230
|
+
return self._find(key, run_environment)
|
|
2231
|
+
|
|
1895
2232
|
def final_review_diff(self, key, name):
|
|
1896
2233
|
return self._find(key, final_review_diff, name)
|
|
1897
2234
|
|
package/ui/forge_ui/server.py
CHANGED
|
@@ -41,6 +41,9 @@ _REVIEW_PATH = re.compile(r'/api/runs/([0-9a-f]{12})/final-reviews/((?:final-rev
|
|
|
41
41
|
_TASK_DIFF_PATH = re.compile(_TASK_PATH.pattern + r'/diff(?:/(current|prev|committed|existing))?')
|
|
42
42
|
_EXEC_DIFF_PATH = re.compile(_EXEC_PATH.pattern + '/diff')
|
|
43
43
|
_TRANSCRIPT_PATH = re.compile(_EXEC_PATH.pattern + '/transcript')
|
|
44
|
+
_EXEC_CHECKS_PATH = re.compile(_EXEC_PATH.pattern + '/checks')
|
|
45
|
+
_TASK_CHECKS_PATH = re.compile(_TASK_PATH.pattern + '/checks')
|
|
46
|
+
_ENVIRONMENT_PATH = re.compile(r'/api/runs/([0-9a-f]{12})/environment')
|
|
44
47
|
_REVIEW_DIFF_PATH = re.compile(_REVIEW_PATH.pattern + '/diff')
|
|
45
48
|
_FILES_PATH = re.compile(r'/api/runs/([0-9a-f]{12})/files')
|
|
46
49
|
_FINDINGS_PATH = re.compile(r'/api/runs/([0-9a-f]{12})/findings')
|
|
@@ -144,6 +147,16 @@ def api_get(catalog, path):
|
|
|
144
147
|
match = _TRANSCRIPT_PATH.fullmatch(path)
|
|
145
148
|
if match:
|
|
146
149
|
return catalog.transcript(*match.groups())
|
|
150
|
+
match = _EXEC_CHECKS_PATH.fullmatch(path)
|
|
151
|
+
if match:
|
|
152
|
+
return catalog.execution_checks(*match.groups())
|
|
153
|
+
match = _TASK_CHECKS_PATH.fullmatch(path)
|
|
154
|
+
if match:
|
|
155
|
+
task_id = _task_id(match.group(2))
|
|
156
|
+
return None if task_id is None else catalog.task_checks(match.group(1), task_id)
|
|
157
|
+
match = _ENVIRONMENT_PATH.fullmatch(path)
|
|
158
|
+
if match:
|
|
159
|
+
return catalog.environment(match.group(1))
|
|
147
160
|
match = _FILES_PATH.fullmatch(path)
|
|
148
161
|
if match:
|
|
149
162
|
return catalog.files(match.group(1))
|
|
@@ -64,8 +64,8 @@ window.ForgeApp = (() => {
|
|
|
64
64
|
if (spec.kind === 'fractal') return `${base}/tasks/${e(spec.task)}/fractal/${e(spec.node)}/diff${file}`;
|
|
65
65
|
return `${base}/tasks/${e(spec.task)}/diff${spec.source && spec.source !== 'current' ? '/' + e(spec.source) : ''}${file}`;
|
|
66
66
|
}
|
|
67
|
-
// an execution's conversation, in the stage's place like a diff
|
|
68
|
-
const convoHash = (key, sel) => hashFor(key, sel) + '/conversation';
|
|
67
|
+
// an execution's conversation, in the stage's place like a diff; opened at one of its events when given
|
|
68
|
+
const convoHash = (key, sel, event) => hashFor(key, sel) + '/conversation' + (Number.isInteger(event) && event >= 0 ? '/event/' + event : '');
|
|
69
69
|
function cloudHash(sel, focus) {
|
|
70
70
|
if (sel) return '#/cloud/runs/' + encodeURIComponent(sel);
|
|
71
71
|
return focus ? '#/cloud/projects/' + encodeURIComponent(focus) : '#/cloud';
|
|
@@ -83,11 +83,11 @@ window.ForgeApp = (() => {
|
|
|
83
83
|
if ((r = rest.match(/^\/tasks\/([^/]+)\/diff(?:\/(?!file\/|finding\/)([^/]+))?(?:\/finding\/([^/]+))?(?:\/file\/(.+?))?\/?$/))) return { key: d(m[1]), sel: { kind: 'task', id: d(r[1]) }, diff: { kind: 'task', task: d(r[1]), source: r[2] ? d(r[2]) : 'current', finding: r[3] ? d(r[3]) : null, file: r[4] ? d(r[4]) : null } };
|
|
84
84
|
if ((r = rest.match(/^\/tasks\/([^/]+)\/fractal\/([^/]+)\/diff(?:\/file\/(.+?))?\/?$/))) return { key: d(m[1]), sel: { kind: 'task', id: d(r[1]) }, diff: { kind: 'fractal', task: d(r[1]), node: d(r[2]), file: r[3] ? d(r[3]) : null } };
|
|
85
85
|
if ((r = rest.match(/^\/final-review\/([^/]+)\/diff(?:\/finding\/([^/]+))?(?:\/file\/(.+?))?\/?$/))) return { key: d(m[1]), sel: { kind: 'final', name: d(r[1]) }, diff: { kind: 'final', name: d(r[1]), finding: r[2] ? d(r[2]) : null, file: r[3] ? d(r[3]) : null } };
|
|
86
|
-
if ((r = rest.match(/^\/(?:tasks\/([^/]+)\/)?executions\/([^/]+)\/conversation
|
|
86
|
+
if ((r = rest.match(/^\/(?:tasks\/([^/]+)\/)?executions\/([^/]+)\/conversation(?:\/event\/(\d{1,7}))?\/?$/))) {
|
|
87
87
|
const s = r[1] ? { kind: 'execution', task: d(r[1]), id: d(r[1]), exec: d(r[2]) } : { kind: 'execution', task: null, exec: d(r[2]) };
|
|
88
88
|
const run = s.task && state.cache.get(d(m[1]))?.data, t = run && list(run.tasks).find(x => x.id === s.task);
|
|
89
89
|
if (t && list(t.shadow).some(x => x.execution === s.exec)) s.shadow = true;
|
|
90
|
-
return { key: d(m[1]), sel: s, convo: { task: s.task, exec: s.exec } };
|
|
90
|
+
return { key: d(m[1]), sel: s, convo: { task: s.task, exec: s.exec, event: r[3] ? Number(r[3]) : null } };
|
|
91
91
|
}
|
|
92
92
|
if ((r = rest.match(/^\/tasks\/([^/]+)\/executions\/([^/]+)\/?$/))) sel = { kind: 'execution', task: d(r[1]), id: d(r[1]), exec: d(r[2]) };
|
|
93
93
|
if (sel && sel.kind === 'execution' && sel.task) {
|
|
@@ -740,6 +740,10 @@ window.ForgeApp = (() => {
|
|
|
740
740
|
if (run.updated != null) { upd.dataset.epoch = run.updated; upd.dataset.short = ''; }
|
|
741
741
|
desc.append(upd);
|
|
742
742
|
row.append(lamp, title, where, desc); head.append(row);
|
|
743
|
+
// an environment problem several tasks met, read lazily
|
|
744
|
+
if (window.ForgeChecks && !solo) window.ForgeChecks.banner(head, { run, fetchJSON: path => fetchJSON(path).then(r => r.data),
|
|
745
|
+
rerender: () => { const cur = state.cache.get(state.key)?.data; if (cur && cur.key === run.key) renderHeader(cur); },
|
|
746
|
+
hash: s => hashFor(run.key, s), convoHash: (s, event) => convoHash(run.key, s, event) });
|
|
743
747
|
if (list(run.warnings).length) details(head, `Reader warnings (${run.warnings.length})`, run.warnings.join('\n'), 'warnings');
|
|
744
748
|
if (list(run.truncated).length) details(head, 'Truncated fields', run.truncated.join('\n'), 'truncated');
|
|
745
749
|
scoped(head, run.key + ':');
|
|
@@ -756,6 +760,8 @@ window.ForgeApp = (() => {
|
|
|
756
760
|
{ id: 'difficulty', label: 'Difficulty', value: t => DIFF_RANK[t.difficulty] ?? null, cell: t => display(t.difficulty) },
|
|
757
761
|
{ id: 'wave', label: 'Wave', value: t => Number.isFinite(Number(t.wave)) && t.wave !== null && t.wave !== '' ? Number(t.wave) : null, cell: t => display(t.wave) },
|
|
758
762
|
{ id: 'status', label: 'Status', value: t => RM.taskStatus(t), cell: t => chip(RM.taskStatus(t)) },
|
|
763
|
+
...(window.ForgeChecks ? [{ id: 'now', label: 'Now', title: 'What a running task is doing, or why one that is not running waits',
|
|
764
|
+
value: t => window.ForgeChecks.nowRank(t), cell: t => window.ForgeChecks.cell(t, now(), { hash: s => hashFor(run.key, s) }) }] : []),
|
|
759
765
|
{ id: 'dwarf', label: 'Dwarf', value: t => t.dwarf, cell: t => window.ForgeIcons.modelPlate(t.dwarf) },
|
|
760
766
|
{ id: 'qa', label: 'QA', value: t => t.qa, cell: t => window.ForgeIcons.modelPlate(t.qa) },
|
|
761
767
|
{ id: 'attempt', label: 'Attempt', value: t => Number(t.attempt) || null, cell: t => display(t.attempt) },
|
|
@@ -802,7 +808,7 @@ window.ForgeApp = (() => {
|
|
|
802
808
|
fetchJSON: path => fetchJSON(path).then(r => r.data),
|
|
803
809
|
rerender: () => { const r = state.cache.get(state.key)?.data; if (r) renderInspector(r); },
|
|
804
810
|
hash: s => hashFor(run.key, s), onSelect: s => select(s), diffHash: spec => diffHash(run.key, spec),
|
|
805
|
-
convoHash: s => convoHash(run.key, s),
|
|
811
|
+
convoHash: (s, event) => convoHash(run.key, s, event),
|
|
806
812
|
onFractal: (id, data) => { if (state.stage && state.stage.setFractal) state.stage.setFractal(id, data); },
|
|
807
813
|
});
|
|
808
814
|
scoped(host, run.key + ':');
|
|
@@ -874,7 +880,7 @@ window.ForgeApp = (() => {
|
|
|
874
880
|
if (kind === 'convo') {
|
|
875
881
|
const sel = state.sel, task = sel.task ? list(run.tasks).find(t => t.id === sel.task) : run.kind === 'solo' ? list(run.tasks)[0] : null;
|
|
876
882
|
const brief = list(task && task.executions).find(e => e.id === state.convo.exec) || null;
|
|
877
|
-
window.ForgeConvo.render(host, { run, spec: { task: task ? task.id : null, exec: state.convo.exec }, brief, live: !SNAP,
|
|
883
|
+
window.ForgeConvo.render(host, { run, spec: { task: task ? task.id : null, exec: state.convo.exec }, brief, live: !SNAP, focus: state.convo.event,
|
|
878
884
|
fetchJSON: path => fetchJSON(path).then(r => r.data), rerender, diffHash: spec => diffHash(run.key, spec), closeHref: hashFor(run.key, state.sel) });
|
|
879
885
|
return;
|
|
880
886
|
}
|
|
@@ -1076,6 +1082,7 @@ window.ForgeApp = (() => {
|
|
|
1076
1082
|
if (state.models) loadModels();
|
|
1077
1083
|
if (state.settings) state.settingsView?.poll();
|
|
1078
1084
|
for (const node of document.querySelectorAll('[data-epoch]')) { const t = relative(node.dataset.epoch); node.textContent = node.dataset.short !== undefined ? t.replace(/^updated /, '') : t; }
|
|
1085
|
+
if (window.ForgeChecks) window.ForgeChecks.tick(document, now());
|
|
1079
1086
|
}
|
|
1080
1087
|
// Poll faster while something runs, slower otherwise; never with refresh off, and a hidden tab only to notify.
|
|
1081
1088
|
function schedule() {
|