@giamme/forge 0.18.0 → 0.20.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 (93) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/README.md +1 -0
  3. package/SKILL.md +19 -2
  4. package/VERSION +1 -1
  5. package/docs/artifacts.md +25 -1
  6. package/docs/commands.md +217 -18
  7. package/docs/decomposed-runs.md +114 -1
  8. package/docs/development.md +2 -1
  9. package/docs/forge-ui.md +138 -18
  10. package/docs/memory.md +25 -4
  11. package/docs/models.md +8 -0
  12. package/docs/reviews.md +122 -0
  13. package/forge +26 -3
  14. package/package.json +2 -1
  15. package/references/dataset.md +20 -1
  16. package/references/decompose.md +641 -41
  17. package/references/harnesses.md +18 -3
  18. package/references/memory.md +30 -5
  19. package/references/planning.md +43 -14
  20. package/references/ui.md +53 -6
  21. package/registry.tsv +8 -3
  22. package/scripts/forge-brief.py +88 -3
  23. package/scripts/forge-compare.py +4 -3
  24. package/scripts/forge-contract.py +202 -27
  25. package/scripts/forge-control.py +117 -5
  26. package/scripts/forge-dispatch.sh +34 -5
  27. package/scripts/forge-findings.py +675 -0
  28. package/scripts/forge-group.py +496 -0
  29. package/scripts/forge-groups.py +89 -0
  30. package/scripts/forge-handoff.py +1128 -0
  31. package/scripts/forge-issues.py +228 -97
  32. package/scripts/forge-lib-group.sh +641 -0
  33. package/scripts/forge-lib-plans.sh +339 -3
  34. package/scripts/forge-lib-task.sh +197 -4
  35. package/scripts/forge-memory.sh +711 -17
  36. package/scripts/forge-parallel.sh +721 -38
  37. package/scripts/forge-planner.py +104 -8
  38. package/scripts/forge-route.py +190 -12
  39. package/scripts/forge-runs.py +9 -5
  40. package/scripts/forge-schedule.py +417 -52
  41. package/scripts/forge-solo.sh +2 -0
  42. package/scripts/forge-sweep.py +199 -44
  43. package/scripts/forge-worktrees.py +243 -0
  44. package/scripts/forge_brief/__init__.py +294 -50
  45. package/scripts/forge_brief/answers.py +58 -11
  46. package/scripts/forge_brief/proposals.py +1630 -0
  47. package/scripts/forge_dataset/efforts.py +4 -3
  48. package/scripts/forge_dataset/export.py +24 -12
  49. package/scripts/forge_dataset/facts.py +5 -3
  50. package/scripts/forge_dataset/forecast.py +8 -18
  51. package/scripts/forge_dataset/harvest.py +204 -9
  52. package/scripts/forge_dataset/history.py +11 -6
  53. package/scripts/forge_dataset/importer.py +65 -1
  54. package/scripts/forge_dataset/names.py +66 -0
  55. package/scripts/forge_dataset/reviewers.py +5 -2
  56. package/scripts/forge_dataset/risk.py +6 -3
  57. package/scripts/forge_dataset/routing.py +6 -1
  58. package/scripts/forge_findings/__init__.py +17 -0
  59. package/scripts/forge_findings/apply.py +441 -0
  60. package/scripts/forge_findings/status.py +43 -0
  61. package/scripts/forge_findings/store.py +583 -0
  62. package/scripts/forge_findings/tags.py +53 -0
  63. package/scripts/forge_findings/triage.py +603 -0
  64. package/scripts/forge_groups/__init__.py +308 -0
  65. package/scripts/forge_groups/attribute.py +289 -0
  66. package/scripts/forge_groups/review.py +286 -0
  67. package/scripts/forge_identity.py +327 -0
  68. package/scripts/forge_memory_list.py +7 -3
  69. package/scripts/forge_owner.py +152 -0
  70. package/scripts/forge_side/__init__.py +228 -38
  71. package/ui/docs/api.md +303 -29
  72. package/ui/forge_ui/control.py +1018 -6
  73. package/ui/forge_ui/executions.py +8 -1
  74. package/ui/forge_ui/export.py +31 -4
  75. package/ui/forge_ui/groups.py +264 -0
  76. package/ui/forge_ui/models.py +70 -8
  77. package/ui/forge_ui/projects.py +209 -22
  78. package/ui/forge_ui/reader.py +262 -19
  79. package/ui/forge_ui/server.py +4 -0
  80. package/ui/forge_ui/static/app.js +93 -13
  81. package/ui/forge_ui/static/briefview.js +350 -47
  82. package/ui/forge_ui/static/diffview.js +86 -1
  83. package/ui/forge_ui/static/findingsactions.js +201 -0
  84. package/ui/forge_ui/static/groupsview.js +332 -0
  85. package/ui/forge_ui/static/index.html +3 -0
  86. package/ui/forge_ui/static/panel.js +127 -7
  87. package/ui/forge_ui/static/projectsview.js +764 -30
  88. package/ui/forge_ui/static/runmodel.js +14 -3
  89. package/ui/forge_ui/static/storageview.js +91 -10
  90. package/ui/forge_ui/static/style.css +138 -5
  91. package/ui/forge_ui/static/triageview.js +423 -0
  92. package/ui/forge_ui/static/worktreesview.js +233 -12
  93. package/ui/forge_ui/storage.py +14 -0
@@ -15,8 +15,11 @@ Sources, run dirs first:
15
15
  dataset `forge dataset history --json` for runs whose dir is gone and checkouts that are gone; those rows
16
16
  say so and link to no run page or diff
17
17
 
18
- Finding statuses: open, filed, fixed, swept, dismissed (as on a run's Open findings page) and superseded: a later
19
- review of the same task (or a later final review) passed. That does not claim the finding was fixed.
18
+ Finding statuses come from forge_findings.status.effective (the one rule the CLI and the sweep share): the finding
19
+ record first (duplicate, dismissed, fixed, filed, to-file), then the issue's state in `forge issues` (online, so a
20
+ closed issue is `fixed`; offline when GitHub cannot be asked), then the review row: shadow, unlabelled, superseded
21
+ (a later review of the same task, or a later final review, passed: that does not claim the finding was fixed).
22
+ Only `open` and `to-file` are worked on.
20
23
 
21
24
  Cost: nothing here runs on the page's poll. Each tab's endpoint is read when the tab opens; a run's findings
22
25
  are cached by its `updated` time, the CLI answers for CACHE_S, and ?refresh=1 reads everything again.
@@ -25,15 +28,19 @@ from __future__ import annotations
25
28
 
26
29
  import importlib.machinery
27
30
  import importlib.util
31
+ import inspect
28
32
  import os
29
33
  from pathlib import Path
34
+ import sys
30
35
  import threading
31
36
  import time
32
37
 
33
38
  from forge_ui import executions, findings as F, models, reader, repos
34
39
 
35
40
  ISSUES = Path(__file__).resolve().parents[2] / 'scripts' / 'forge-issues.py'
41
+ SCRIPTS = ISSUES.parent
36
42
  CACHE_S = 300
43
+ ONLINE_S = 60 # the online listing may take this long before the offline one is read instead
37
44
  _SEVERITIES = ('P0', 'P1', 'P2', 'P3')
38
45
  _STATE = {}
39
46
  _LOCK = threading.Lock()
@@ -71,8 +78,8 @@ def project_id(root):
71
78
  return '%08x' % h
72
79
 
73
80
 
74
- def fingerprint(first_line):
75
- """`forge issues`' key for a finding whose first line it can parse, else None (such rows never collapse).
81
+ def parsed_finding(first_line):
82
+ """The finding `forge issues` parses from a first line ({file, text, ...}), else None.
76
83
  The canonical `[P1][CONFIRMED] path:line — text` form first, then the other forms forge issues reads from a
77
84
  known_issues.md (`parse_known`), so a tolerated finding written another way still finds its entry."""
78
85
  module = issues_module()
@@ -82,7 +89,77 @@ def fingerprint(first_line):
82
89
  parsed = module.parse_findings(first_line)
83
90
  if not parsed and callable(getattr(module, 'parse_known', None)):
84
91
  parsed = module.parse_known(first_line)
85
- return module.finding_key(parsed[0]) if parsed else None
92
+ return parsed[0] if parsed else None
93
+ except Exception:
94
+ return None
95
+
96
+
97
+ def fingerprint(first_line):
98
+ """`forge issues`' key for a finding whose first line it can parse, else None (such rows never collapse)."""
99
+ parsed = parsed_finding(first_line)
100
+ if parsed is None:
101
+ return None
102
+ try:
103
+ return issues_module().finding_key(parsed)
104
+ except Exception:
105
+ return None
106
+
107
+
108
+ class _Record:
109
+ """forge_findings' store, status and tags and forge_identity, loaded read-only like models.py loads forge_dataset."""
110
+
111
+ def __init__(self, store, status, tags, identity):
112
+ self.store, self.status, self.tags, self.identity = store, status, tags, identity
113
+
114
+
115
+ def record_modules():
116
+ """The finding record's modules, or None when they cannot be loaded (rows then keep the old status)."""
117
+ with _LOCK:
118
+ if 'record' in _STATE:
119
+ return _STATE['record']
120
+ found = None
121
+ scripts = str(SCRIPTS)
122
+ inserted = scripts not in sys.path
123
+ if inserted:
124
+ sys.path.insert(0, scripts)
125
+ try:
126
+ import forge_identity
127
+ loaded = {}
128
+ for name in ('status', 'tags', 'store'):
129
+ path = SCRIPTS / 'forge_findings' / (name + '.py')
130
+ module_name = 'forge_findings_%s_for_ui' % name
131
+ spec = importlib.util.spec_from_file_location(
132
+ module_name, path, loader=_ReadOnlyLoader(module_name, str(path)))
133
+ module = importlib.util.module_from_spec(spec)
134
+ spec.loader.exec_module(module)
135
+ loaded[name] = module
136
+ if not (callable(loaded['status'].effective) and callable(loaded['tags'].tags_for)
137
+ and callable(loaded['store'].load) and callable(forge_identity.identity)):
138
+ raise TypeError('not the finding record')
139
+ found = _Record(loaded['store'], loaded['status'], loaded['tags'], forge_identity)
140
+ except Exception:
141
+ found = None
142
+ finally:
143
+ if inserted and scripts in sys.path:
144
+ sys.path.remove(scripts)
145
+ _STATE['record'] = found
146
+ return found
147
+
148
+
149
+ def read_record(root):
150
+ """(ident, {fingerprint: entry}) of the repository at `root`; entries are {} when it has no identity or no
151
+ record yet. None when the record cannot be read at all (not loadable, corrupt, no state directory)."""
152
+ modules = record_modules()
153
+ if modules is None or not root:
154
+ return None
155
+ try:
156
+ ident = modules.identity.identity(root)
157
+ if ident is None:
158
+ return None, {}
159
+ data = modules.store.load(ident)
160
+ if isinstance(data, dict) and data.get('version') == 1 and isinstance(data.get('findings'), dict):
161
+ data = data['findings']
162
+ return ident, dict(data) if isinstance(data, dict) else {}
86
163
  except Exception:
87
164
  return None
88
165
 
@@ -340,6 +417,27 @@ def issue_for(index, row, run_path):
340
417
  return found
341
418
 
342
419
 
420
+ def _first_of(row):
421
+ return (row.get('text') or '').split('\n', 1)[0]
422
+
423
+
424
+ def _slug_of(ident):
425
+ try:
426
+ return record_modules().identity.github_slug(ident) or ''
427
+ except Exception:
428
+ return ''
429
+
430
+
431
+ def _issues_call(issues, path, online):
432
+ """issues(path, online=...) when the callable takes `online`, else issues(path) (it knows one way to ask)."""
433
+ try:
434
+ params = inspect.signature(issues).parameters
435
+ takes = 'online' in params or any(q.kind == q.VAR_KEYWORD for q in params.values())
436
+ except (TypeError, ValueError):
437
+ takes = False
438
+ return issues(path, online=online) if takes else issues(path)
439
+
440
+
343
441
  # ---- the cached screen -----------------------------------------------------------------------------
344
442
 
345
443
  class Screen:
@@ -350,13 +448,29 @@ class Screen:
350
448
  self.runs = {} # run path -> (updated, occurrences)
351
449
  self.cli = {} # key -> (time, value)
352
450
 
353
- def _cli(self, key, call, refresh, now):
451
+ def _cli_at(self, key, call, refresh, now):
452
+ """(value, the time it was read) of a CLI answer, cached for CACHE_S."""
354
453
  hit = self.cli.get(key)
355
454
  if not refresh and hit is not None and now - hit[0] < CACHE_S:
356
- return hit[1]
455
+ return hit[1], hit[0]
357
456
  value = call()
358
457
  self.cli[key] = (now, value)
359
- return value
458
+ return value, now
459
+
460
+ def _cli(self, key, call, refresh, now):
461
+ return self._cli_at(key, call, refresh, now)[0]
462
+
463
+ def _cli_unlocked_at(self, key, call, refresh, now):
464
+ """`_cli_at` for a caller that does not hold the lock: the cache is read and written under it, the call runs
465
+ outside it, so a slow answer (GitHub, up to ONLINE_S) never holds up the other screens."""
466
+ with self.lock:
467
+ hit = self.cli.get(key)
468
+ if not refresh and hit is not None and now - hit[0] < CACHE_S:
469
+ return hit[1], hit[0]
470
+ value = call()
471
+ with self.lock:
472
+ self.cli[key] = (now, value)
473
+ return value, now
360
474
 
361
475
  def occurrences(self, run):
362
476
  hit = self.runs.get(run['path'])
@@ -377,9 +491,10 @@ class Screen:
377
491
  projects = self.projects(catalog)
378
492
  out = []
379
493
  for p in projects.values():
380
- # not superseded by a later passing review; dismissals and filed issues show on the Findings tab
381
- open_findings = sum(1 for row in collapse([o for run in p['runs'] for o in self.occurrences(run)])
382
- if not row['superseded'])
494
+ # Rows the finding record and the review rules call open (or to-file): not shadow, unlabelled,
495
+ # superseded, nor closed in the record. The listing of issues needs GitHub, so filed and swept
496
+ # findings are not known here: the Findings tab's own count can be lower still.
497
+ open_findings = self._open_findings(p, collapse([o for run in p['runs'] for o in self.occurrences(run)]))
383
498
  out.append(dict(id=p['id'], name=p['name'], root=p['root'], exists=p['exists'], runs=len(p['runs']),
384
499
  live=p['live'], last=p['last'], path_only=p['path_only'],
385
500
  checkouts=len(checkouts(p)), memory_lines=_memory_lines(p['root']) if p['exists'] else None,
@@ -387,6 +502,33 @@ class Screen:
387
502
  out.sort(key=lambda p: p['last'] or 0, reverse=True)
388
503
  return dict(projects=out)
389
504
 
505
+ def _open_findings(self, p, rows):
506
+ record = read_record(p['root']) if p['exists'] else (None, {})
507
+ modules = record_modules()
508
+ if modules is None or record is None:
509
+ return sum(1 for row in rows if not row['superseded'])
510
+ ident, entries = record
511
+ slug = _slug_of(ident) if ident and entries else ''
512
+ count = 0
513
+ for row in rows:
514
+ entry = entries.get(self._record_fp(slug, row)) if entries else None
515
+ if modules.status.effective(entry, None, row) in modules.status.OPEN:
516
+ count += 1
517
+ return count
518
+
519
+ @staticmethod
520
+ def _record_fp(slug, row, issue=None):
521
+ """The record's key of a row: its issues entry's `fp`, else the one forge-issues computes for its first line."""
522
+ if issue is not None and isinstance(issue.get('fp'), str) and issue['fp']:
523
+ return issue['fp']
524
+ parsed = parsed_finding(_first_of(row))
525
+ if parsed is None:
526
+ return None
527
+ try:
528
+ return issues_module().fingerprint(slug, parsed)
529
+ except Exception:
530
+ return None
531
+
390
532
  def detail(self, catalog, pid):
391
533
  p = self.project(catalog, pid)
392
534
  if p is None:
@@ -415,8 +557,39 @@ class Screen:
415
557
  out.add(run['run'])
416
558
  return out
417
559
 
560
+ def _read_issues(self, p, issues, refresh, now):
561
+ """(listing, online, read_at) of `forge issues` for the project: asked once of the repository's root, online
562
+ first (it knows which issues are closed), offline when that fails or takes over ONLINE_S. Only a root
563
+ that is no checkout, or that gave nothing, sends it through the project's runs (at most three).
564
+ Called without the lock."""
565
+ paths = []
566
+ if p['exists']:
567
+ paths.append(p['root'])
568
+ paths += [run['path'] for run in sorted(p['runs'], key=lambda r: (r.get('repo_worktree') is not None,
569
+ r.get('kind') != 'plan'))[:3]]
570
+ online_failed = False
571
+ for path in paths:
572
+ if not online_failed:
573
+ listing, at = self._cli_unlocked_at(('issues', path, True), lambda: _issues_call(issues, path, True),
574
+ refresh, now)
575
+ if listing is not None:
576
+ return listing, True, at
577
+ online_failed = True
578
+ listing, at = self._cli_unlocked_at(('issues', path, False), lambda: _issues_call(issues, path, False),
579
+ refresh, now)
580
+ if listing is not None:
581
+ return listing, False, at
582
+ return None, False, None
583
+
418
584
  def findings(self, catalog, pid, history, issues, refresh=False, now=None):
419
585
  now = time.time() if now is None else now
586
+ with self.lock:
587
+ p = self.projects(catalog).get(pid)
588
+ if p is None:
589
+ return None
590
+ # `forge issues` asks GitHub (up to ONLINE_S): never under the lock the project list, the Memories tab and
591
+ # every write's invalidation wait on
592
+ listing, online, read_at = self._read_issues(p, issues, refresh, now)
420
593
  with self.lock:
421
594
  projects = self.projects(catalog)
422
595
  p = projects.get(pid)
@@ -431,21 +604,31 @@ class Screen:
431
604
  gone = self._dataset_runs(p, hist, projects) if hist else set()
432
605
  if hist:
433
606
  occ += _dataset_occurrences(hist, gone)
434
- # forge issues reads every run of the repository (--all-runs) from any one of them, but needs that run's
435
- # checkout to name its GitHub repository: runs started in the root first, at most three tries.
436
- tried = sorted(p['runs'], key=lambda r: (r.get('repo_worktree') is not None, r.get('kind') != 'plan'))[:3]
437
- listing = None
438
- for run in tried:
439
- listing = self._cli(('issues', run['path']), lambda: issues(run['path']), refresh, now)
440
- if listing is not None:
441
- break
442
607
  index = issue_index(listing)
443
608
  paths = {run['key']: run['path'] for run in p['runs']}
444
609
  rows = collapse(occ)
610
+ record = read_record(p['root']) if p['exists'] else (None, {})
611
+ modules = record_modules()
612
+ ident, entries = record if record is not None else (None, {})
613
+ slug = (listing or {}).get('repo') if listing is not None else None
614
+ if not isinstance(slug, str):
615
+ slug = _slug_of(ident) if (ident and listing is None) else ''
445
616
  for row in rows:
446
617
  issue = issue_for(index, row, paths.get(row['run']))
447
- row['status'] = status_of(row, issue)
448
- row['fileable'] = issue is not None and row['status'] == 'open' and row['source'] == 'run'
618
+ row['record_fp'] = self._record_fp(slug, row, issue)
619
+ if modules is None or record is None:
620
+ row['status'], row['record'], row['tags'], row['draft'] = status_of(row, issue), None, [], None
621
+ else:
622
+ entry = entries.get(row['record_fp']) if row['record_fp'] else None
623
+ parsed = None if issue else parsed_finding(_first_of(row))
624
+ where = ((issue or {}).get('file') or (parsed or {}).get('file')
625
+ or str(row.get('location') or '').rsplit(':', 1)[0])
626
+ row['record'] = entry
627
+ row['status'] = modules.status.effective(entry, issue, row)
628
+ row['tags'] = modules.tags.tags_for(entry, where)
629
+ row['draft'] = entry.get('draft') if isinstance(entry, dict) else None
630
+ row['fileable'] = (issue is not None and row['status'] in ('open', 'to-file')
631
+ and row['source'] == 'run')
449
632
  row['origin'] = issue.get('origin') if issue else None
450
633
  rows.sort(key=lambda r: (_SEVERITIES.index(r['severity']) if r['severity'] in _SEVERITIES else 9, -(r['at'] or 0)))
451
634
  notes = []
@@ -455,8 +638,12 @@ class Screen:
455
638
  notes.append('the dataset is off (FORGE_DATASET=off): only the run directories that still exist are read')
456
639
  if listing is None:
457
640
  notes.append('forge issues could not be read: dismissed and filed findings show as open')
641
+ elif not online:
642
+ notes.append('issue states could not be read from GitHub: filed findings may show as open')
643
+ if modules is None or record is None:
644
+ notes.append('the finding record could not be read')
458
645
  return dict(id=pid, rows=rows, notes=notes, runs=len(p['runs']), dataset_runs=len(gone),
459
- computed=now, available=F.available())
646
+ computed=now, available=F.available(), issues_online=online, issues_read_at=read_at)
460
647
 
461
648
  def memories(self, catalog, pid, learnings, history, refresh=False, now=None):
462
649
  now = time.time() if now is None else now