@giamme/forge 0.18.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.
Files changed (78) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/README.md +1 -0
  3. package/SKILL.md +16 -2
  4. package/VERSION +1 -1
  5. package/docs/artifacts.md +25 -1
  6. package/docs/commands.md +81 -14
  7. package/docs/decomposed-runs.md +114 -1
  8. package/docs/development.md +2 -1
  9. package/docs/forge-ui.md +84 -15
  10. package/docs/memory.md +25 -4
  11. package/docs/models.md +8 -0
  12. package/docs/reviews.md +122 -0
  13. package/forge +20 -3
  14. package/package.json +2 -1
  15. package/references/dataset.md +20 -1
  16. package/references/decompose.md +621 -33
  17. package/references/harnesses.md +18 -3
  18. package/references/planning.md +43 -14
  19. package/references/ui.md +53 -6
  20. package/registry.tsv +8 -3
  21. package/scripts/forge-brief.py +88 -3
  22. package/scripts/forge-compare.py +4 -3
  23. package/scripts/forge-contract.py +202 -27
  24. package/scripts/forge-control.py +117 -5
  25. package/scripts/forge-dispatch.sh +34 -5
  26. package/scripts/forge-group.py +496 -0
  27. package/scripts/forge-groups.py +89 -0
  28. package/scripts/forge-handoff.py +1128 -0
  29. package/scripts/forge-lib-group.sh +641 -0
  30. package/scripts/forge-lib-plans.sh +339 -3
  31. package/scripts/forge-lib-task.sh +197 -4
  32. package/scripts/forge-memory.sh +245 -3
  33. package/scripts/forge-parallel.sh +715 -34
  34. package/scripts/forge-planner.py +104 -8
  35. package/scripts/forge-route.py +190 -12
  36. package/scripts/forge-runs.py +9 -5
  37. package/scripts/forge-schedule.py +354 -45
  38. package/scripts/forge-solo.sh +2 -0
  39. package/scripts/forge-worktrees.py +243 -0
  40. package/scripts/forge_brief/__init__.py +294 -50
  41. package/scripts/forge_brief/answers.py +58 -11
  42. package/scripts/forge_brief/proposals.py +1630 -0
  43. package/scripts/forge_dataset/efforts.py +4 -3
  44. package/scripts/forge_dataset/export.py +24 -12
  45. package/scripts/forge_dataset/facts.py +5 -3
  46. package/scripts/forge_dataset/forecast.py +8 -18
  47. package/scripts/forge_dataset/harvest.py +204 -9
  48. package/scripts/forge_dataset/history.py +11 -6
  49. package/scripts/forge_dataset/importer.py +65 -1
  50. package/scripts/forge_dataset/names.py +66 -0
  51. package/scripts/forge_dataset/reviewers.py +5 -2
  52. package/scripts/forge_dataset/risk.py +6 -3
  53. package/scripts/forge_dataset/routing.py +6 -1
  54. package/scripts/forge_groups/__init__.py +308 -0
  55. package/scripts/forge_groups/attribute.py +289 -0
  56. package/scripts/forge_groups/review.py +286 -0
  57. package/scripts/forge_owner.py +152 -0
  58. package/scripts/forge_side/__init__.py +12 -7
  59. package/ui/docs/api.md +173 -17
  60. package/ui/forge_ui/control.py +361 -2
  61. package/ui/forge_ui/executions.py +8 -1
  62. package/ui/forge_ui/export.py +31 -4
  63. package/ui/forge_ui/groups.py +264 -0
  64. package/ui/forge_ui/models.py +70 -8
  65. package/ui/forge_ui/reader.py +262 -19
  66. package/ui/forge_ui/server.py +4 -0
  67. package/ui/forge_ui/static/app.js +93 -13
  68. package/ui/forge_ui/static/briefview.js +350 -47
  69. package/ui/forge_ui/static/diffview.js +86 -1
  70. package/ui/forge_ui/static/groupsview.js +332 -0
  71. package/ui/forge_ui/static/index.html +1 -0
  72. package/ui/forge_ui/static/panel.js +127 -7
  73. package/ui/forge_ui/static/projectsview.js +189 -10
  74. package/ui/forge_ui/static/runmodel.js +14 -3
  75. package/ui/forge_ui/static/storageview.js +91 -10
  76. package/ui/forge_ui/static/style.css +79 -5
  77. package/ui/forge_ui/static/worktreesview.js +233 -12
  78. package/ui/forge_ui/storage.py +14 -0
@@ -14,7 +14,7 @@ import sys
14
14
  import time
15
15
  import urllib.parse
16
16
 
17
- from forge_ui import checks, diffs, executions, findings, fractal, links, repos, transcripts
17
+ from forge_ui import checks, diffs, executions, findings, fractal, groups, links, repos, transcripts
18
18
  from forge_ui.findings import verdict as _verdict
19
19
 
20
20
 
@@ -319,6 +319,11 @@ def _nullable(value):
319
319
  return None if value in ('', '-', 'UNASSIGNED') else value
320
320
 
321
321
 
322
+ def _model_name(spec):
323
+ """A dwarf or qa cell that names a model. `script` runs tasks/<id>/run, so it is not one."""
324
+ return None if not spec or spec == 'script' else spec
325
+
326
+
322
327
  def _tasks(reader):
323
328
  tasks = []
324
329
  for label, row in reader.rows('tasks.tsv', 7):
@@ -362,6 +367,75 @@ def _brief(title):
362
367
  return title if len(title) <= _TITLE_CAP else title[:_TITLE_CAP] + '…'
363
368
 
364
369
 
370
+ def _real_path(value):
371
+ try:
372
+ return os.path.realpath(value)
373
+ except (OSError, ValueError):
374
+ return os.fspath(value)
375
+
376
+
377
+ def _first_line(directory, name):
378
+ """The first line of `directory/name`, or None when the file cannot be read.
379
+
380
+ One open. A missing file, a missing directory and a directory in the way are all None:
381
+ a chain link is never worth an exception.
382
+ """
383
+ try:
384
+ with open(os.path.join(os.fspath(directory), name), encoding='utf-8', errors='replace') as stream:
385
+ line = stream.readline()
386
+ except OSError:
387
+ return None
388
+ return line.strip() or None
389
+
390
+
391
+ def _predecessor(reader):
392
+ """`{key, run_id, path}` of the plan this run follows, from its `after` file, or None.
393
+
394
+ `reader.line` is the one read: a run with no `after` file costs that one failed stat and
395
+ nothing else. A named directory that is gone still yields a key and a path, with `run_id`
396
+ null, so the chain stays visible.
397
+ """
398
+ named = reader.line('after')
399
+ if not named:
400
+ return None
401
+ path = _real_path(named)
402
+ return dict(key=run_key(path), run_id=_first_line(path, 'run_id'), path=path)
403
+
404
+
405
+ def _note_followers(runs):
406
+ """Set `followed_by` on each listed run: `{key, run_id}` of the runs whose `after` names it.
407
+
408
+ Paths are the resolved ones `_predecessor` stored, so a symlink in an `after` file still matches.
409
+ """
410
+ by_predecessor = {}
411
+ for run in runs:
412
+ after = run.get('after')
413
+ if not after or not after.get('path'):
414
+ continue
415
+ by_predecessor.setdefault(after['path'], []).append(dict(key=run['key'], run_id=run['run_id']))
416
+ for run in runs:
417
+ run['followed_by'] = by_predecessor.get(run['path'], [])
418
+
419
+
420
+ def _followers(listed, target):
421
+ """`{key, run_id}` of the listed runs whose `after` names `target`, in list order.
422
+
423
+ Reads each other dir's `after` file and, on a hit, its `run_id`. Does not summarize them.
424
+ Skips `target` itself: its `after` was already read to fill the predecessor, and a dir with
425
+ no `after` file must not be read twice.
426
+ """
427
+ want = _real_path(target)
428
+ found = []
429
+ for path, _source, _entry in listed:
430
+ if _real_path(path) == want:
431
+ continue
432
+ named = _first_line(path, 'after')
433
+ if named is None or _real_path(named) != want:
434
+ continue
435
+ found.append(dict(key=run_key(path), run_id=_first_line(path, 'run_id')))
436
+ return found
437
+
438
+
365
439
  def _summary(reader, source):
366
440
  result = dict(key=run_key(reader.path), path=str(reader.path), source=source, kind='plan',
367
441
  run_id=reader.line('run_id'), repo=reader.line('repo'),
@@ -372,17 +446,20 @@ def _summary(reader, source):
372
446
  for task in tasks:
373
447
  counts[task['status']] = counts.get(task['status'], 0) + 1
374
448
  final_review = reader.word('final-review.verdict')
375
- dwarf_models = sorted({task['dwarf'] for task in tasks if task['dwarf']})
376
- qa_models = sorted({task['qa'] for task in tasks if task['qa']})
449
+ dwarf_models = sorted({task['dwarf'] for task in tasks if _model_name(task['dwarf'])})
450
+ qa_models = sorted({task['qa'] for task in tasks if _model_name(task['qa'])})
451
+ scripted = sum(1 for task in tasks if task['dwarf'] == 'script')
377
452
  # Before snapshotting `updated`: these reads are files the summary read, so a newer
378
453
  # accepted.integration (or the published verdict / review.meta) moves the activity time.
379
454
  final_review_outdated = _published_outdated(reader, tasks)
455
+ after = _predecessor(reader)
380
456
  result.update(updated=reader.updated, created=_created(reader.path, _PLAN_START_FILES),
381
457
  task_count=len(tasks), counts=counts,
382
458
  task_statuses=[dict(id=task['id'], status=task['status'], difficulty=task['difficulty'] or None,
383
459
  title=_brief(task['title']), accepted=task['accepted']) for task in tasks],
384
460
  models=sorted(set(dwarf_models) | set(qa_models)), dwarf_models=dwarf_models, qa_models=qa_models,
385
- final_review=final_review, final_review_outdated=final_review_outdated)
461
+ scripted=scripted, final_review=final_review, final_review_outdated=final_review_outdated,
462
+ after=after)
386
463
  return result, tasks
387
464
 
388
465
 
@@ -407,7 +484,11 @@ def _solo_summary(reader, source):
407
484
  reader.exists('dwarf.log')
408
485
  reader.exists('qa.log')
409
486
  dwarf, qa = _role_spec(reader, 'dwarf'), _role_spec(reader, 'qa')
487
+ # The task payload keeps a dwarf spec of `script`. The model lists do not: it is not a model.
488
+ model_dwarf, model_qa = _model_name(dwarf), _model_name(qa)
410
489
  goal = reader.line('goal.txt')
490
+ # Before `updated` is copied out: a present `after` file is part of what the summary read.
491
+ after = _predecessor(reader)
411
492
  return dict(key=run_key(reader.path), path=str(reader.path), source=source, kind='solo',
412
493
  run_id=reader.path.name, repo=reader.line('repo'), goal=goal,
413
494
  decompose_level=None, verification_status=None, updated=reader.updated,
@@ -415,8 +496,10 @@ def _solo_summary(reader, source):
415
496
  task_count=1, counts={status: 1},
416
497
  task_statuses=[dict(id='solo', status=status, difficulty=None, title=_brief(goal or 'Solo run'),
417
498
  accepted=False)],
418
- models=sorted({dwarf, qa} - {None}), dwarf_models=[dwarf] if dwarf else [],
419
- qa_models=[qa] if qa else [], final_review=None, final_review_outdated=None)
499
+ models=sorted({model_dwarf, model_qa} - {None}),
500
+ dwarf_models=[model_dwarf] if model_dwarf else [],
501
+ qa_models=[model_qa] if model_qa else [], scripted=1 if dwarf == 'script' else 0,
502
+ final_review=None, final_review_outdated=None, after=after)
420
503
 
421
504
 
422
505
  def summarize(path, source='plan') -> dict:
@@ -495,7 +578,8 @@ def _nonempty(reader, name):
495
578
 
496
579
 
497
580
  def _task_execs(reader, task):
498
- execs = executions.scan(reader, f'tasks/{task["id"]}/attempts', task['status'] == 'RUNNING', ('task', 'dwarf', 'qa'))
581
+ execs = executions.scan(reader, f'tasks/{task["id"]}/attempts', task['status'] == 'RUNNING',
582
+ ('task', 'dwarf', 'qa', 'script'))
499
583
  executions.nest(execs)
500
584
  return executions.assign_attempts(execs, task['attempts'], task['attempt'])
501
585
 
@@ -593,7 +677,7 @@ def _now(reader, owner_dir, execs):
593
677
  """Task.now: where a running task (or solo run) is. The dwarf or reviewer running in it, with the call it is
594
678
  making and when its log last moved; else the task execution's own phase."""
595
679
  running = [item for item in execs if item['state'] == 'running' and not item['shadow']]
596
- agent = next((item for item in reversed(running) if item['role'] in ('dwarf', 'qa')), None)
680
+ agent = next((item for item in reversed(running) if item['role'] in ('dwarf', 'qa', 'script')), None)
597
681
  item = agent or next((item for item in reversed(running) if item['role'] in executions.CONTAINERS), None)
598
682
  if item is None:
599
683
  return None
@@ -649,7 +733,39 @@ def _scheduler(reader):
649
733
 
650
734
 
651
735
  # Not NEEDS_INPUT or NEEDS_DECISION: those wait for the user, so a task that depends on one waits rather than stops.
736
+ # IMPLEMENTED is not here either: the member's own work is in and it waits for the group's review.
737
+ # A task that depends on one waits, it does not stop.
652
738
  _STOPPED = ('FAIL', 'BLOCKED', 'INFRA', 'INTERRUPTED', 'TIMEOUT', 'ERROR', 'CONFLICT', 'NOCHANGES', 'INVALIDATED', 'UNKNOWN')
739
+
740
+ # How status_class, and through it _waiting, reads a status.
741
+ # done is MERGED only. PASS is saved and not merged yet, so a dependent still lists it.
742
+ # NOCHANGES is failed: it is in _STOPPED and will not merge. The page paints PASS and NOCHANGES
743
+ # as finished; this reader does not, because a dependent is not free of either.
744
+ # IMPLEMENTED is waiting, with NEEDS_INPUT and NEEDS_DECISION: awaiting the group's review.
745
+ # It is not done, not active and not failed.
746
+ _DONE_STATUS = frozenset(('MERGED',))
747
+ _ACTIVE_STATUS = frozenset(('RUNNING',))
748
+ _WAITING_STATUS = frozenset(('NEEDS_INPUT', 'NEEDS_DECISION', 'IMPLEMENTED'))
749
+
750
+
751
+ def status_class(status):
752
+ """'done', 'active', 'waiting' or 'failed', or None for a status in none of those buckets.
753
+
754
+ `_waiting` uses this for a dependency: 'done' drops it from `on`, 'failed' puts it in
755
+ `stopped`, and 'waiting' leaves it in `on` only. PENDING is None (not started). PASS is
756
+ None too (saved, not merged). IMPLEMENTED is 'waiting': awaiting group review.
757
+ """
758
+ if status in _DONE_STATUS:
759
+ return 'done'
760
+ if status in _ACTIVE_STATUS:
761
+ return 'active'
762
+ if status in _WAITING_STATUS:
763
+ return 'waiting'
764
+ if status in _STOPPED:
765
+ return 'failed'
766
+ return None
767
+
768
+
653
769
  _DETAIL_CAP = 400 # characters of an infra stop's detail, a short text
654
770
  _ATTEMPT_CAP = 8 # a plan without a max_attempts file
655
771
  _LEDGER_KEEP = 50 # the newest ledger rows a task keeps
@@ -889,9 +1005,10 @@ def _waiting(reader, tasks, scheduler):
889
1005
  continue
890
1006
  if task['status'] != 'PENDING':
891
1007
  continue
892
- on = [dep for dep in task['deps'] if status.get(dep) != 'MERGED']
1008
+ on = [dep for dep in task['deps'] if status_class(status.get(dep)) != 'done']
893
1009
  if on:
894
- task['waiting'] = dict(kind='deps', on=on, stopped=[dep for dep in on if status.get(dep) in _STOPPED])
1010
+ task['waiting'] = dict(kind='deps', on=on,
1011
+ stopped=[dep for dep in on if status_class(status.get(dep)) == 'failed'])
895
1012
  elif scheduler['stopping']:
896
1013
  task['waiting'] = dict(kind='stopping', mode=scheduler['stopping'])
897
1014
  elif scheduler['drained']:
@@ -1280,8 +1397,12 @@ def _run_summaries(reader):
1280
1397
 
1281
1398
 
1282
1399
  # --- brief mode (#135): tasks/<id>/brief.json, parked questions, answers and late answers ---------
1400
+ # Proposals and affected markers (#136) are read only while brief is on. Off leaves them unread, so a
1401
+ # plan without brief keeps the run JSON it had.
1283
1402
 
1284
1403
  _BRIEF_LEVELS = ('advisory', 'gated', 'strict')
1404
+ # CLI proposal dirs are p1, p2, … with no leading zero (PID_RE). p0 and p0001 are not proposals.
1405
+ _PID_DIR = re.compile(r'^p[1-9][0-9]{0,5}$')
1285
1406
 
1286
1407
 
1287
1408
  def _brief_level(reader):
@@ -1350,7 +1471,11 @@ def _brief_rows(reader, prefix, body, answers, late, parked):
1350
1471
  possibly_stale=file_stale or question.get('possibly_stale') is True)
1351
1472
  if parked:
1352
1473
  scope = question.get('scope')
1474
+ group = question.get('group')
1353
1475
  row['scope'] = scope if isinstance(scope, str) else None
1476
+ row['group'] = group if isinstance(group, str) and group else None
1477
+ # Parked answers live in brief.parked.answers.json, passed in as `answers`.
1478
+ row['answer'] = _cap_str(reader, _entry_text(answers.get(qid)), stem + '.answer')
1354
1479
  else:
1355
1480
  row['state'] = state
1356
1481
  row['answer'] = _cap_str(reader, _entry_text(entry), stem + '.answer')
@@ -1384,8 +1509,11 @@ def _task_brief(reader, ident):
1384
1509
  parked = reader.object(paths['parked']) if present['parked'] else None
1385
1510
  late = _answer_map(reader.object(paths['late']) if present['late'] else None)
1386
1511
  answers = _answer_map(reader.object(f'{prefix}/brief.answers.json'))
1512
+ # Missing parked answers are no answers. The file is not read when this task has no parked questions,
1513
+ # and a missing file is not tracked, so `updated` does not move.
1514
+ parked_answers = _answer_map(reader.object(f'{prefix}/brief.parked.answers.json')) if present['parked'] else {}
1387
1515
  return dict(questions=_brief_rows(reader, prefix, brief, answers, late, False),
1388
- parked=_brief_rows(reader, prefix, parked, {}, {}, True),
1516
+ parked=_brief_rows(reader, prefix, parked, parked_answers, {}, True),
1389
1517
  late=_late_rows(reader, prefix, late))
1390
1518
 
1391
1519
 
@@ -1406,10 +1534,79 @@ def _run_brief(level, tasks):
1406
1534
  return dict(level=level, open=open_n, flagged=flagged)
1407
1535
 
1408
1536
 
1537
+ def _affected(reader, ident):
1538
+ """`tasks/<id>/brief.affected` as `{pid, reason, flag_only}`, or None when the marker is absent or not one.
1539
+
1540
+ `t` stays on disk. `flag_only` is true only when the file says exactly that: a task that had already
1541
+ started when the proposal was applied. A bad object is warned about here, or already by the JSON read.
1542
+ """
1543
+ label = f'tasks/{ident}/brief.affected'
1544
+ body = reader.object(label)
1545
+ if body is None:
1546
+ return None
1547
+ pid, reason = body.get('pid'), body.get('reason')
1548
+ if not isinstance(pid, str) or not pid or len(pid) > 32 or not isinstance(reason, str) or not reason:
1549
+ reader.warn(label, 'not an affected marker')
1550
+ return None
1551
+ return dict(pid=pid, reason=reader.cap(reason, label + '.reason', 500),
1552
+ flag_only=body.get('flag_only') is True)
1553
+
1554
+
1555
+ def _as_str(value):
1556
+ return value if isinstance(value, str) else None
1557
+
1558
+
1559
+ def _proposals(reader):
1560
+ """`<plan>/proposals/<pid>/` in numeric order: the public record, the hash, and the diff.
1561
+
1562
+ The diff is capped like every other text. `truncated` is true when the shown diff is not the file.
1563
+ The hash is not capped: Approve sends the hash the page shows. `answer` and the edit lists stay in
1564
+ the file; the run JSON does not carry them. A directory that is not a proposal id is skipped.
1565
+ """
1566
+ names = []
1567
+ for path in reader.children('proposals'):
1568
+ if not _PID_DIR.fullmatch(path.name):
1569
+ continue
1570
+ try:
1571
+ if not path.is_dir():
1572
+ continue
1573
+ except (OSError, ValueError) as exc:
1574
+ reader.warn(f'proposals/{path.name}', f'cannot stat ({type(exc).__name__})')
1575
+ continue
1576
+ names.append(path.name)
1577
+ names.sort(key=lambda name: int(name[1:]))
1578
+ rows = []
1579
+ for pid in names:
1580
+ prefix = f'proposals/{pid}'
1581
+ body = reader.object(f'{prefix}/proposal.json')
1582
+ if body is None:
1583
+ continue
1584
+ if body.get('pid') != pid:
1585
+ reader.warn(f'{prefix}/proposal.json', 'pid does not match the directory')
1586
+ raw = reader.text(f'{prefix}/diff.patch')
1587
+ if raw is None:
1588
+ diff, cut = '', False
1589
+ else:
1590
+ diff = reader.cap(raw, f'{prefix}/diff')
1591
+ cut = diff != raw
1592
+ raw_hash = reader.text(f'{prefix}/hash')
1593
+ digest = raw_hash.strip() if isinstance(raw_hash, str) else ''
1594
+ rows.append(dict(pid=pid, scope=_as_str(body.get('scope')), group=_as_str(body.get('group')),
1595
+ task=_as_str(body.get('task')), qid=_as_str(body.get('qid')),
1596
+ summary=_cap_str(reader, body.get('summary'), f'{prefix}/summary'),
1597
+ state=_as_str(body.get('state')),
1598
+ reason=_cap_str(reader, body.get('reason'), f'{prefix}/reason'),
1599
+ created=_as_str(body.get('created')), hash=digest or None, diff=diff, truncated=cut))
1600
+ return rows
1601
+
1602
+
1409
1603
  def _attach_brief(reader, tasks):
1410
1604
  """Set each task's `brief` and return the run's `{level, open, flagged}`, or None when brief is off.
1411
1605
 
1412
- Off means the questions are not shown either: a file left from an earlier level stays on disk."""
1606
+ Off means the questions are not shown either: a file left from an earlier level stays on disk.
1607
+ Affected markers are attached only while brief is on, and only when the file is a real marker.
1608
+ The key is omitted otherwise, including when brief is off, so that run JSON does not grow a null.
1609
+ """
1413
1610
  level = _brief_level(reader)
1414
1611
  if level is None:
1415
1612
  for task in tasks:
@@ -1417,6 +1614,9 @@ def _attach_brief(reader, tasks):
1417
1614
  return None
1418
1615
  for task in tasks:
1419
1616
  task['brief'] = _task_brief(reader, task['id'])
1617
+ affected = _affected(reader, task['id'])
1618
+ if affected is not None:
1619
+ task['affected'] = affected
1420
1620
  return _run_brief(level, tasks)
1421
1621
 
1422
1622
 
@@ -2237,7 +2437,22 @@ def detail(path, source='plan') -> dict:
2237
2437
  result['deferrals'] = [line.strip() for line in (reader.text('deferrals.txt') or '').splitlines() if line.strip()]
2238
2438
  result['findings_available'] = findings.available()
2239
2439
  result['fractal'] = fractal.summary(reader)
2240
- result['brief'] = _attach_brief(reader, tasks)
2440
+ brief = _attach_brief(reader, tasks)
2441
+ result['brief'] = brief
2442
+ # Absent, not empty, when brief is off: proposals/ is not listed, so the run JSON does not change.
2443
+ if brief is not None:
2444
+ result['proposals'] = _proposals(reader)
2445
+ # No groups.tsv: the run JSON gains nothing. A plan that has one carries `groups` and, on
2446
+ # every task, `group` (its group id, or null when it is in none).
2447
+ if reader.exists('groups.tsv'):
2448
+ listed = groups.groups(reader)
2449
+ result['groups'] = listed
2450
+ owner = {}
2451
+ for item in listed:
2452
+ for member in item['members'] or []:
2453
+ owner.setdefault(member, item['id'])
2454
+ for task in tasks:
2455
+ task['group'] = owner.get(task['id'])
2241
2456
  result.update(tasks=tasks, warnings=reader.warnings, truncated=reader.truncated, updated=reader.updated)
2242
2457
  return result
2243
2458
 
@@ -2263,6 +2478,14 @@ def _review(kind, item, text):
2263
2478
  verdict=item['verdict'], state=item['state'], findings=findings.listing(text), tests=findings.tests(text))
2264
2479
 
2265
2480
 
2481
+ def group_detail(path, gid, source='plan'):
2482
+ """One group of a plan, with its review, or None when the plan has no such group."""
2483
+ reader = _Read(path)
2484
+ if _kind(reader.path) != 'plan':
2485
+ return None
2486
+ return groups.group(reader, gid)
2487
+
2488
+
2266
2489
  def task_detail(path, task_id, source='plan'):
2267
2490
  """TaskDetail of one task (`solo` for a solo run), or None when there is no such task."""
2268
2491
  reader = _Read(path)
@@ -2322,6 +2545,15 @@ def _execution(reader, name):
2322
2545
  owner, owner_dir = dict(kind='task', id='solo'), ''
2323
2546
  elif parts[0] == 'attempts':
2324
2547
  execs, owner, owner_dir = _run_execs(reader), dict(kind='run', id=None), ''
2548
+ elif parts[0] == 'groups' and len(parts) >= 4 and parts[2] == 'attempts':
2549
+ # A review=group group's QA dispatch lives in groups/<gid>/attempts, and its prompts in the group dir.
2550
+ gid = parts[1]
2551
+ if not groups.GID.fullmatch(gid):
2552
+ return None
2553
+ owner_dir = f'groups/{gid}'
2554
+ execs = executions.scan(reader, owner_dir + '/attempts',
2555
+ reader.word(owner_dir + '/status') == 'REVIEWING', ('qa',))
2556
+ owner = dict(kind='group', id=gid)
2325
2557
  elif parts[0] in ('tasks', 'shadow'):
2326
2558
  task = _plan_task(reader, tasks, parts[1])
2327
2559
  execs = _task_execs(reader, task)
@@ -2371,11 +2603,11 @@ def execution_detail(path, name, source='plan'):
2371
2603
 
2372
2604
 
2373
2605
  def execution_transcript(path, name, source='plan'):
2374
- """ExecutionTranscript of a dwarf or qa execution: its agent's conversation, read from its `.log`; None
2375
- when there is no such execution or it is of another role."""
2606
+ """ExecutionTranscript of a dwarf, qa or script execution, read from its `.log` (`script.log` for the
2607
+ command). None when there is no such execution or it is of another role."""
2376
2608
  reader = _Read(path)
2377
2609
  found = _execution(reader, name)
2378
- if found is None or found[0]['role'] not in ('dwarf', 'qa'):
2610
+ if found is None or found[0]['role'] not in ('dwarf', 'qa', 'script'):
2379
2611
  return None
2380
2612
  item, owner, owner_dir = found
2381
2613
  role, running = item['role'], item['state'] == 'running'
@@ -2393,7 +2625,7 @@ def execution_transcript(path, name, source='plan'):
2393
2625
 
2394
2626
 
2395
2627
  def _agent_log(reader, item, owner_dir):
2396
- """The log of a dwarf or reviewer execution: its copy once it ended, the one being written while it runs."""
2628
+ """The log of a dwarf, reviewer or script execution: its copy once it ended, the one being written while it runs."""
2397
2629
  role = item['role']
2398
2630
  if item['state'] == 'running':
2399
2631
  return _log_path(reader, posixpath.join(owner_dir, role + '.log'))
@@ -3177,7 +3409,13 @@ class Catalog:
3177
3409
  def runs(self):
3178
3410
  listed, identities = batch(discover(**self.options))
3179
3411
  runs = [_with_repo(summarize(path, source), identities[entry[0]]) for path, source, entry in listed]
3180
- return sorted(runs, key=lambda item: item['updated'] if item['updated'] is not None else float('-inf'), reverse=True)
3412
+ runs = sorted(runs, key=lambda item: item['updated'] if item['updated'] is not None else float('-inf'), reverse=True)
3413
+ _note_followers(runs)
3414
+ return runs
3415
+
3416
+ def keys(self):
3417
+ """The keys of every run the list shows, without summarizing any of them."""
3418
+ return {run_key(path) for path, _source in discover(**self.options)}
3181
3419
 
3182
3420
  def identity(self, key):
3183
3421
  """The identity of the run with this key, resolved in the same batch as the list; None for no such run."""
@@ -3208,12 +3446,17 @@ class Catalog:
3208
3446
  listed, identities = batch(discover(**self.options))
3209
3447
  for path, source, entry in listed:
3210
3448
  if run_key(path) == key:
3211
- return _with_repo(detail(path, source=source), identities[entry[0]])
3449
+ result = _with_repo(detail(path, source=source), identities[entry[0]])
3450
+ result['followed_by'] = _followers(listed, result['path'])
3451
+ return result
3212
3452
  return None
3213
3453
 
3214
3454
  def task(self, key, task_id):
3215
3455
  return self._find(key, task_detail, task_id)
3216
3456
 
3457
+ def group(self, key, gid):
3458
+ return self._find(key, group_detail, gid)
3459
+
3217
3460
  def execution(self, key, name):
3218
3461
  return self._find(key, execution_detail, name)
3219
3462
 
@@ -36,6 +36,7 @@ TOKEN_HEADER = 'X-Forge-UI-Token'
36
36
 
37
37
  _RUN_PATH = re.compile(r'/api/runs/([0-9a-f]{12})')
38
38
  _TASK_PATH = re.compile(r'/api/runs/([0-9a-f]{12})/tasks/([^/]+)')
39
+ _GROUP_PATH = re.compile(r'/api/runs/([0-9a-f]{12})/groups/([a-z0-9][a-z0-9-]{0,39})')
39
40
  _EXEC_PATH = re.compile(r'/api/runs/([0-9a-f]{12})/executions/((?:task|dwarf|qa|solo|verification|parallel)-[0-9a-f]{32})')
40
41
  _REVIEW_PATH = re.compile(r'/api/runs/([0-9a-f]{12})/final-reviews/((?:final-review|integrate)-[0-9]+-[0-9]+)')
41
42
  _TASK_DIFF_PATH = re.compile(_TASK_PATH.pattern + r'/diff(?:/(current|prev|committed|existing))?')
@@ -130,6 +131,9 @@ def api_get(catalog, path):
130
131
  if match:
131
132
  task_id = _task_id(match.group(2))
132
133
  return None if task_id is None else catalog.task(match.group(1), task_id)
134
+ match = _GROUP_PATH.fullmatch(path)
135
+ if match:
136
+ return catalog.group(*match.groups())
133
137
  match = _EXEC_PATH.fullmatch(path)
134
138
  if match:
135
139
  return catalog.execution(*match.groups())