@giamme/forge 0.16.0 → 0.18.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.
- package/CHANGELOG.md +43 -0
- package/SKILL.md +16 -3
- package/VERSION +1 -1
- package/docs/artifacts.md +8 -0
- package/docs/commands.md +70 -6
- package/docs/dataset.md +13 -0
- package/docs/decomposed-runs.md +8 -0
- package/docs/forge-ui.md +23 -2
- package/docs/memory.md +2 -0
- package/docs/reviews.md +15 -1
- package/docs/safety.md +8 -0
- package/forge +24 -1
- package/package.json +1 -1
- package/references/dataset.md +143 -5
- package/references/decision-models.md +15 -2
- package/references/decompose.md +180 -11
- package/references/planning.md +3 -2
- package/references/solo.md +2 -1
- package/references/ui.md +5 -2
- package/scripts/forge-artifact.sh +14 -0
- package/scripts/forge-brief.py +132 -0
- package/scripts/forge-compare.py +11 -1
- package/scripts/forge-config.py +176 -9
- package/scripts/forge-contract.py +98 -4
- package/scripts/forge-control.py +86 -13
- package/scripts/forge-dispatch.sh +14 -10
- package/scripts/forge-du.py +167 -0
- package/scripts/forge-issues.py +4 -3
- package/scripts/forge-ledger.py +3 -1
- package/scripts/forge-lib-adopt.sh +8 -1
- package/scripts/forge-lib-plans.sh +5 -2
- package/scripts/forge-lib-review.sh +29 -1
- package/scripts/forge-metrics.sh +29 -3
- package/scripts/forge-parallel-options.sh +4 -0
- package/scripts/forge-parallel.sh +506 -10
- package/scripts/forge-plan-check.py +25 -2
- package/scripts/forge-planner.py +20 -6
- package/scripts/forge-prompt.py +120 -0
- package/scripts/forge-retro.py +115 -0
- package/scripts/forge-runs-compact.py +443 -0
- package/scripts/forge-runs-rm.py +2 -0
- package/scripts/forge-runs.py +18 -3
- package/scripts/forge-schedule.py +279 -4
- package/scripts/forge-shadow.py +35 -10
- package/scripts/forge-solo.sh +2 -0
- package/scripts/forge-summarize.py +698 -0
- package/scripts/forge-sweep.py +25 -10
- package/scripts/forge-ui-options.sh +10 -0
- package/scripts/forge_brief/__init__.py +587 -0
- package/scripts/forge_brief/answers.py +459 -0
- package/scripts/forge_dataset/__init__.py +10 -0
- package/scripts/forge_dataset/cli.py +83 -0
- package/scripts/forge_dataset/export.py +18 -4
- package/scripts/forge_dataset/facts.py +280 -0
- package/scripts/forge_dataset/harvest.py +56 -9
- package/scripts/forge_dataset/history.py +5 -3
- package/scripts/forge_dataset/outcomes.py +206 -58
- package/scripts/forge_dataset/pairs.py +174 -0
- package/scripts/forge_dataset/risk.py +108 -0
- package/scripts/forge_dataset/tiers.py +427 -0
- package/scripts/forge_decide/__init__.py +11 -1
- package/scripts/forge_decide/cli.py +23 -2
- package/scripts/forge_decide/labels.py +30 -6
- package/scripts/forge_decide/replay.py +10 -4
- package/scripts/forge_locations.py +366 -0
- package/scripts/forge_registry.py +19 -0
- package/scripts/forge_retro/__init__.py +417 -0
- package/scripts/forge_retro/issues.py +1193 -0
- package/scripts/forge_retro/report.py +671 -0
- package/scripts/forge_side/__init__.py +477 -0
- package/scripts/forge_storage.py +515 -0
- package/ui/README.md +68 -8
- package/ui/docs/api.md +217 -20
- package/ui/forge_ui/control.py +92 -11
- package/ui/forge_ui/export.py +31 -5
- package/ui/forge_ui/findings.py +4 -2
- package/ui/forge_ui/links.py +337 -0
- package/ui/forge_ui/models.py +57 -4
- package/ui/forge_ui/projects.py +4 -1
- package/ui/forge_ui/reader.py +732 -34
- package/ui/forge_ui/server.py +8 -0
- package/ui/forge_ui/static/app.js +92 -5
- package/ui/forge_ui/static/briefview.js +302 -0
- package/ui/forge_ui/static/checksview.js +6 -2
- package/ui/forge_ui/static/controls.js +5 -0
- package/ui/forge_ui/static/diffview.js +7 -3
- package/ui/forge_ui/static/index.html +3 -0
- package/ui/forge_ui/static/panel.js +311 -4
- package/ui/forge_ui/static/runmodel.js +13 -1
- package/ui/forge_ui/static/storageview.js +271 -0
- package/ui/forge_ui/static/style.css +100 -3
- package/ui/forge_ui/static/worktreesview.js +3 -3
- package/ui/forge_ui/storage.py +136 -0
- package/ui/forge_ui/transcripts.py +35 -10
- package/ui/forge_ui/worktrees.py +154 -13
|
@@ -34,11 +34,13 @@ from __future__ import annotations
|
|
|
34
34
|
|
|
35
35
|
import bisect
|
|
36
36
|
from datetime import datetime
|
|
37
|
+
import gzip
|
|
37
38
|
import json
|
|
38
39
|
import os
|
|
39
40
|
from pathlib import Path
|
|
40
41
|
import re
|
|
41
42
|
import stat
|
|
43
|
+
import zlib
|
|
42
44
|
|
|
43
45
|
TEXT_CAP = 20000 # characters kept of one message, reasoning or result
|
|
44
46
|
OUTPUT_CAP = 8000 # of a command's or tool's output: the head and the tail
|
|
@@ -562,31 +564,54 @@ def session_file(session_id, home=None, environ=None):
|
|
|
562
564
|
|
|
563
565
|
# ---------- one execution's transcript ----------
|
|
564
566
|
|
|
567
|
+
GZ_CAP = 512 << 20 # bytes a gzipped log may expand to before it is refused
|
|
568
|
+
|
|
569
|
+
|
|
565
570
|
def _read(path):
|
|
566
|
-
"""The log's text (its end when it is over LOG_CAP), whether it was cut, and the byte offset it starts at.
|
|
571
|
+
"""The log's text (its end when it is over LOG_CAP), whether it was cut, and the byte offset it starts at.
|
|
572
|
+
|
|
573
|
+
A `.gz` log (an execution record's copy that `forge runs compact --logs` gzipped, #139) reads as the
|
|
574
|
+
plain log it was: the same text and the same offsets, so its clock still places every line."""
|
|
567
575
|
base = 0
|
|
568
576
|
try:
|
|
569
|
-
|
|
570
|
-
|
|
577
|
+
if path.name.endswith('.gz'):
|
|
578
|
+
with gzip.open(path, 'rb') as fh:
|
|
579
|
+
data = fh.read(GZ_CAP + 1)
|
|
580
|
+
if len(data) > GZ_CAP:
|
|
581
|
+
return None, False, 0
|
|
582
|
+
size = len(data)
|
|
571
583
|
if size > LOG_CAP:
|
|
572
|
-
|
|
573
|
-
data = fh.read()
|
|
584
|
+
data = data[size - LOG_CAP:]
|
|
574
585
|
skip = data.find(b'\n') + 1
|
|
575
586
|
data, base = data[skip:], size - LOG_CAP + skip
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
587
|
+
else:
|
|
588
|
+
size = path.stat().st_size
|
|
589
|
+
with open(path, 'rb') as fh:
|
|
590
|
+
if size > LOG_CAP:
|
|
591
|
+
fh.seek(size - LOG_CAP)
|
|
592
|
+
data = fh.read()
|
|
593
|
+
skip = data.find(b'\n') + 1
|
|
594
|
+
data, base = data[skip:], size - LOG_CAP + skip
|
|
595
|
+
else:
|
|
596
|
+
data = fh.read()
|
|
597
|
+
except (OSError, EOFError, zlib.error):
|
|
579
598
|
return None, False, 0
|
|
580
599
|
return data.decode('utf-8', 'replace'), size > LOG_CAP, base
|
|
581
600
|
|
|
582
601
|
|
|
602
|
+
def clock_path(log):
|
|
603
|
+
"""`<role>.clock` beside `<role>.log` or `<role>.log.gz`."""
|
|
604
|
+
name = log.name[:-3] if log.name.endswith('.gz') else log.name
|
|
605
|
+
return log.with_name(name.rsplit('.', 1)[0] + '.clock')
|
|
606
|
+
|
|
607
|
+
|
|
583
608
|
CLOCK_CAP = 8 << 20 # bytes of a clock read
|
|
584
609
|
|
|
585
610
|
|
|
586
611
|
def clock_of(log):
|
|
587
612
|
"""The clock beside `log` (`<role>.clock` for `<role>.log`) as (sizes, times), sizes ascending; None without one."""
|
|
588
613
|
try:
|
|
589
|
-
path =
|
|
614
|
+
path = clock_path(log)
|
|
590
615
|
with open(path, 'rb') as fh:
|
|
591
616
|
if not stat.S_ISREG(os.fstat(fh.fileno()).st_mode):
|
|
592
617
|
return None
|
|
@@ -644,7 +669,7 @@ def transcript(log, harness=None, running=False, home=None, environ=None):
|
|
|
644
669
|
if st is None or not stat.S_ISREG(st.st_mode):
|
|
645
670
|
out['warnings'].append(f'{log.name} is not readable')
|
|
646
671
|
return out
|
|
647
|
-
key = (str(log), st.st_size, st.st_mtime_ns, harness, running, _signature(
|
|
672
|
+
key = (str(log), st.st_size, st.st_mtime_ns, harness, running, _signature(clock_path(log)))
|
|
648
673
|
if key in _CACHE:
|
|
649
674
|
answer, sid, seen = _CACHE[key]
|
|
650
675
|
if sid is None or _signature(session_file(sid, home, environ)) == seen:
|
package/ui/forge_ui/worktrees.py
CHANGED
|
@@ -35,6 +35,7 @@ import time
|
|
|
35
35
|
from forge_ui import reader
|
|
36
36
|
|
|
37
37
|
RULES = Path(__file__).resolve().parents[2] / 'scripts' / 'forge_worktrees.py'
|
|
38
|
+
LOCATIONS = Path(__file__).resolve().parents[2] / 'scripts' / 'forge_locations.py'
|
|
38
39
|
CACHE_S = 60
|
|
39
40
|
_GIT_TIMEOUT = 10
|
|
40
41
|
_SIZE_BUDGET_S = 120 # one tree's walk stops here and its size is a lower bound
|
|
@@ -67,22 +68,82 @@ def rules():
|
|
|
67
68
|
return _STATE['rules']
|
|
68
69
|
|
|
69
70
|
|
|
71
|
+
_LAST_ERROR = threading.local()
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def locations():
|
|
75
|
+
"""forge's location list module (scripts/forge_locations.py), loaded read-only, or None. Only its `load` is used:
|
|
76
|
+
forge-ui never writes the list."""
|
|
77
|
+
with _LOCK:
|
|
78
|
+
if 'locations' not in _STATE:
|
|
79
|
+
try:
|
|
80
|
+
spec = importlib.util.spec_from_file_location(
|
|
81
|
+
'forge_locations_for_ui', LOCATIONS, loader=_ReadOnlyLoader('forge_locations_for_ui', str(LOCATIONS)))
|
|
82
|
+
module = importlib.util.module_from_spec(spec)
|
|
83
|
+
spec.loader.exec_module(module)
|
|
84
|
+
if not callable(module.load):
|
|
85
|
+
raise TypeError('not the forge location module')
|
|
86
|
+
_STATE['locations'] = module
|
|
87
|
+
except Exception:
|
|
88
|
+
_STATE['locations'] = None
|
|
89
|
+
return _STATE['locations']
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def _located():
|
|
93
|
+
"""The location list's worktree entries, [{path, checkout, root, run_id, task, branch, wt_kind, created, gone}]."""
|
|
94
|
+
module = locations()
|
|
95
|
+
if module is None:
|
|
96
|
+
return []
|
|
97
|
+
try:
|
|
98
|
+
return [e for e in module.load().values() if e.get('kind') == 'worktree']
|
|
99
|
+
except Exception:
|
|
100
|
+
return []
|
|
101
|
+
|
|
102
|
+
|
|
70
103
|
def _git(cwd, *args, timeout=_GIT_TIMEOUT):
|
|
71
|
-
"""(returncode, stdout text) of `git -C cwd <args>`, or (None, '') when git could not run.
|
|
104
|
+
"""(returncode, stdout text) of `git -C cwd <args>`, or (None, '') when git could not run. The first line of
|
|
105
|
+
what git said on stderr is kept in _LAST_ERROR.text, for a note when a listing fails."""
|
|
106
|
+
_LAST_ERROR.text = ''
|
|
72
107
|
try:
|
|
73
108
|
done = subprocess.run(['git', '--no-optional-locks', '-C', cwd, *args], stdin=subprocess.DEVNULL,
|
|
74
|
-
stdout=subprocess.PIPE, stderr=subprocess.
|
|
109
|
+
stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=timeout, check=False,
|
|
75
110
|
env=dict(os.environ, GIT_TERMINAL_PROMPT='0', LC_ALL='C'))
|
|
76
|
-
except
|
|
111
|
+
except subprocess.TimeoutExpired:
|
|
112
|
+
_LAST_ERROR.text = 'git took over %d s' % timeout
|
|
113
|
+
return None, ''
|
|
114
|
+
except (OSError, ValueError, subprocess.SubprocessError) as exc:
|
|
115
|
+
_LAST_ERROR.text = str(exc)
|
|
77
116
|
return None, ''
|
|
117
|
+
if done.returncode:
|
|
118
|
+
_LAST_ERROR.text = done.stderr.decode('utf-8', 'replace').strip().split('\n')[0][:300]
|
|
78
119
|
return done.returncode, done.stdout.decode('utf-8', 'surrogateescape')
|
|
79
120
|
|
|
80
121
|
|
|
81
122
|
def _isdir(path):
|
|
123
|
+
"""An absolute path to a directory, through symlinks: a repository is often reached through one."""
|
|
124
|
+
try:
|
|
125
|
+
return os.path.isabs(path) and os.path.isdir(path)
|
|
126
|
+
except (OSError, ValueError):
|
|
127
|
+
return False
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def _leftover(path):
|
|
131
|
+
"""True when the folder is no git worktree any more: no `.git`, or a `.git` file whose gitdir is gone."""
|
|
132
|
+
dotgit = os.path.join(path, '.git')
|
|
82
133
|
try:
|
|
83
|
-
|
|
134
|
+
if not os.path.lexists(dotgit):
|
|
135
|
+
return True
|
|
136
|
+
if os.path.isdir(dotgit):
|
|
137
|
+
return False
|
|
138
|
+
with open(dotgit, 'r', encoding='utf-8', errors='replace') as stream:
|
|
139
|
+
line = stream.read(4096).strip()
|
|
84
140
|
except (OSError, ValueError):
|
|
85
141
|
return False
|
|
142
|
+
if not line.startswith('gitdir:'):
|
|
143
|
+
return False
|
|
144
|
+
target = line[len('gitdir:'):].strip()
|
|
145
|
+
target = target if os.path.isabs(target) else os.path.join(path, target)
|
|
146
|
+
return not os.path.exists(target)
|
|
86
147
|
|
|
87
148
|
|
|
88
149
|
def _exists(path):
|
|
@@ -110,6 +171,9 @@ def commands(row):
|
|
|
110
171
|
return [dict(label='see what is uncommitted', command='git -C %s status' % quote(path))]
|
|
111
172
|
if st == 'missing' and repo:
|
|
112
173
|
return [dict(label='forget the missing folder', command='git -C %s worktree prune' % quote(repo))]
|
|
174
|
+
if st == 'unknown' and row.get('leftover'):
|
|
175
|
+
return [dict(label='delete the leftover folder: git no longer knows it as a worktree (look inside first)',
|
|
176
|
+
command='rm -rf -- %s' % quote(path))]
|
|
113
177
|
if st in ('failed', 'finished') and repo:
|
|
114
178
|
out = [dict(label='remove the worktree', command='git -C %s worktree remove %s' % (quote(repo), quote(path)))]
|
|
115
179
|
if st == 'finished' and branch and row.get('merged'):
|
|
@@ -133,7 +197,9 @@ def _note(row):
|
|
|
133
197
|
if st == 'foreign':
|
|
134
198
|
return row.get('why') or "not forge's: it fails forge's ownership rule"
|
|
135
199
|
if st == 'unknown':
|
|
136
|
-
|
|
200
|
+
if row.get('leftover'):
|
|
201
|
+
return 'a folder left where a worktree was: git no longer knows it, and nothing of forge reads it'
|
|
202
|
+
return row.get('why') or 'a folder git does not list as a worktree'
|
|
137
203
|
if st == 'removed':
|
|
138
204
|
if row.get('derived'):
|
|
139
205
|
return 'derived from the run dir or the dataset; removed at an unknown date'
|
|
@@ -168,19 +234,35 @@ def _runs(catalog):
|
|
|
168
234
|
|
|
169
235
|
# ---- the computation ---------------------------------------------------------------------------
|
|
170
236
|
|
|
171
|
-
def _repo_listing(R, repo):
|
|
172
|
-
"""(main working tree, [worktree records]) of the repository holding `repo`, or (None, []).
|
|
237
|
+
def _repo_listing(R, repo, failures=None):
|
|
238
|
+
"""(main working tree, [worktree records]) of the repository holding `repo`, or (None, []). A failure is added
|
|
239
|
+
to `failures` as {repo: why}."""
|
|
173
240
|
code, out = _git(repo, 'worktree', 'list', '--porcelain', '-z')
|
|
174
241
|
z = True
|
|
175
242
|
if code == 129:
|
|
176
243
|
code, out = _git(repo, 'worktree', 'list', '--porcelain')
|
|
177
244
|
z = False
|
|
178
245
|
if code != 0:
|
|
246
|
+
if failures is not None:
|
|
247
|
+
failures[repo] = _LAST_ERROR.text or ('exit %s' % code if code is not None else 'git could not run')
|
|
179
248
|
return None, []
|
|
180
249
|
found = R.parse_porcelain(out, z=z)
|
|
181
250
|
return (found[0]['path'], found) if found else (None, [])
|
|
182
251
|
|
|
183
252
|
|
|
253
|
+
def _forge_folders(folders):
|
|
254
|
+
"""The worktree folders on disk under each `.forge-worktrees` folder: `<folder>/<run id>/<name>` and
|
|
255
|
+
`<folder>/<name>` that hold a `.git` whose repository is still there (a leftover is no repository to ask)."""
|
|
256
|
+
out = []
|
|
257
|
+
for folder in sorted(folders):
|
|
258
|
+
for first in _children(folder):
|
|
259
|
+
if _exists(os.path.join(first, '.git')):
|
|
260
|
+
out += [] if _leftover(first) else [first]
|
|
261
|
+
continue
|
|
262
|
+
out += [second for second in _children(first) if _exists(os.path.join(second, '.git')) and not _leftover(second)]
|
|
263
|
+
return out
|
|
264
|
+
|
|
265
|
+
|
|
184
266
|
def _layout(path):
|
|
185
267
|
"""(the `.forge-worktrees` folder, run id, name) when `path` is `<x>/.forge-worktrees/<run id>/<name>`,
|
|
186
268
|
(folder, None, name) when it sits directly in that folder, else None."""
|
|
@@ -212,6 +294,11 @@ def compute(catalog, history):
|
|
|
212
294
|
if isinstance(a, dict) and a.get('repo_path') and a.get('run_id') and a.get('task'):
|
|
213
295
|
dataset_tasks.setdefault((R.wt_root(a['repo_path'], a['run_id']), a['repo_path'], a['run_id']), set()).add(a['task'])
|
|
214
296
|
events = [e for e in (hist or {}).get('events') or [] if isinstance(e, dict) and isinstance(e.get('path'), str)]
|
|
297
|
+
located = _located()
|
|
298
|
+
located_tasks = {} # real wt_root -> task ids the location list names
|
|
299
|
+
for e in located:
|
|
300
|
+
if e.get('task'):
|
|
301
|
+
located_tasks.setdefault(os.path.dirname(e['path']), set()).add(e['task'])
|
|
215
302
|
|
|
216
303
|
# every repository to ask: run checkouts and roots, then the dataset's
|
|
217
304
|
candidates = []
|
|
@@ -223,11 +310,31 @@ def compute(catalog, history):
|
|
|
223
310
|
for e in events:
|
|
224
311
|
if e.get('repo_path'):
|
|
225
312
|
candidates.append(e['repo_path'])
|
|
226
|
-
|
|
313
|
+
# The repositories forge's location list names: each one's main working tree, then the checkout a run used.
|
|
314
|
+
for e in located:
|
|
315
|
+
candidates += [p for p in (e.get('root'), e.get('checkout')) if isinstance(p, str)]
|
|
316
|
+
# Then every worktree folder on disk, asked through its own .git: a checkout the dataset names may have
|
|
317
|
+
# been deleted by hand, and git answers for the whole repository from any of its worktrees.
|
|
318
|
+
known_folders = set()
|
|
319
|
+
for repo in candidates:
|
|
320
|
+
if repo and os.path.isabs(repo):
|
|
321
|
+
known_folders.add(os.path.join(os.path.dirname(_real(repo)), '.forge-worktrees'))
|
|
322
|
+
for e in events:
|
|
323
|
+
where = _layout(e['path']) if os.path.isabs(e['path']) else None
|
|
324
|
+
if where:
|
|
325
|
+
known_folders.add(where[0])
|
|
326
|
+
for (wroot, _repo, _rid) in dataset_tasks:
|
|
327
|
+
known_folders.add(os.path.dirname(wroot))
|
|
328
|
+
for e in located:
|
|
329
|
+
where = _layout(e['path'])
|
|
330
|
+
if where:
|
|
331
|
+
known_folders.add(where[0])
|
|
332
|
+
candidates += _forge_folders(known_folders)
|
|
333
|
+
roots, listed, asked, failures = {}, {}, set(), {}
|
|
227
334
|
for repo in candidates:
|
|
228
335
|
if not repo or not _isdir(repo) or _real(repo) in asked:
|
|
229
336
|
continue
|
|
230
|
-
root, found = _repo_listing(R, repo)
|
|
337
|
+
root, found = _repo_listing(R, repo, failures)
|
|
231
338
|
for wt in found:
|
|
232
339
|
asked.add(_real(wt['path']))
|
|
233
340
|
asked.add(_real(repo))
|
|
@@ -242,8 +349,8 @@ def compute(catalog, history):
|
|
|
242
349
|
def tasks_of(root_key, repo, run_id):
|
|
243
350
|
run = by_root.get(root_key)
|
|
244
351
|
if run is not None:
|
|
245
|
-
return set(run['tasks']), run
|
|
246
|
-
out = set()
|
|
352
|
+
return set(run['tasks']) | located_tasks.get(root_key, set()), run
|
|
353
|
+
out = set(located_tasks.get(root_key, set()))
|
|
247
354
|
for (wroot, _repo, _rid), ids in dataset_tasks.items():
|
|
248
355
|
if wroot == root_key:
|
|
249
356
|
out |= ids
|
|
@@ -275,6 +382,9 @@ def compute(catalog, history):
|
|
|
275
382
|
else:
|
|
276
383
|
wroot = os.path.join(folder, run_id)
|
|
277
384
|
ids, run = tasks_of(wroot, root, run_id)
|
|
385
|
+
if wt['branch'] == 'refs/heads/forge/%s/%s' % (run_id, name):
|
|
386
|
+
# forge names a task's worktree and branch after it: a task split or dropped since is still the run's
|
|
387
|
+
ids = set(ids) | {name}
|
|
278
388
|
kind = R.owner(wt['path'], wt['branch'], run_id, ids, wroot)
|
|
279
389
|
if run is not None:
|
|
280
390
|
row.update(run=run['key'], run_path=run['path'])
|
|
@@ -336,6 +446,7 @@ def compute(catalog, history):
|
|
|
336
446
|
folders.add(where[0])
|
|
337
447
|
for run in runs:
|
|
338
448
|
folders.add(os.path.join(os.path.dirname(_real(run['repo'])), '.forge-worktrees'))
|
|
449
|
+
folders |= {_real(f) for f in known_folders if _isdir(f)}
|
|
339
450
|
for folder in sorted(folders):
|
|
340
451
|
for first in _children(folder):
|
|
341
452
|
if _real(first) in listed:
|
|
@@ -365,6 +476,13 @@ def compute(catalog, history):
|
|
|
365
476
|
rows[real]['created'] = created['ts']
|
|
366
477
|
continue
|
|
367
478
|
e = created or removed
|
|
479
|
+
if os.path.isabs(e['path']) and _exists(e['path']):
|
|
480
|
+
# on disk, yet no repository listed it: never call it removed
|
|
481
|
+
_unknown(rows, e['path'], e.get('run_id'), by_root)
|
|
482
|
+
rows[real].update(repo=rows[real]['repo'] or e.get('repo_path'), task=rows[real]['task'] or e.get('task'),
|
|
483
|
+
branch=e.get('branch'), created=created['ts'] if created else None,
|
|
484
|
+
why='on disk, but git did not list it as a worktree of %s' % (e.get('repo_path') or 'its repository'))
|
|
485
|
+
continue
|
|
368
486
|
root_key = R.wt_root(e['repo_path'], e['run_id']) if e.get('repo_path') and e.get('run_id') else None
|
|
369
487
|
run = by_root.get(root_key) if root_key else None
|
|
370
488
|
rows[real] = dict(path=e['path'], repo=e.get('repo_path'), git_dir=None, run=run['key'] if run else None,
|
|
@@ -372,6 +490,25 @@ def compute(catalog, history):
|
|
|
372
490
|
branch=e.get('branch'), kind=e.get('kind'), status='removed', merged=None, head=None,
|
|
373
491
|
commit=None, created=created['ts'] if created else None,
|
|
374
492
|
removed=removed['ts'] if removed else None, derived=False, locked=None, size=None, why=None)
|
|
493
|
+
# what forge's location list recorded: its dates, and the worktrees it added that are not on disk any more
|
|
494
|
+
for e in located:
|
|
495
|
+
real = e['path']
|
|
496
|
+
if real in rows:
|
|
497
|
+
if rows[real]['created'] is None:
|
|
498
|
+
rows[real]['created'] = e.get('created')
|
|
499
|
+
continue
|
|
500
|
+
root_key = os.path.dirname(real)
|
|
501
|
+
run = by_root.get(root_key)
|
|
502
|
+
repo = e.get('root') or e.get('checkout')
|
|
503
|
+
if _exists(real):
|
|
504
|
+
_unknown(rows, real, e.get('run_id'), by_root)
|
|
505
|
+
rows[real].update(repo=rows[real]['repo'] or repo, branch=e.get('branch'), created=e.get('created'),
|
|
506
|
+
why='on disk, but git did not list it as a worktree of %s' % (repo or 'its repository'))
|
|
507
|
+
continue
|
|
508
|
+
rows[real] = dict(path=real, repo=repo, git_dir=None, run=run['key'] if run else None, run_id=e.get('run_id'),
|
|
509
|
+
run_path=run['path'] if run else None, task=e.get('task'), branch=e.get('branch'),
|
|
510
|
+
kind=e.get('wt_kind'), status='removed', merged=None, head=None, commit=None,
|
|
511
|
+
created=e.get('created'), removed=e.get('gone'), derived=False, locked=None, size=None, why=None)
|
|
375
512
|
for run in runs:
|
|
376
513
|
wroot = R.wt_root(run['repo'], run['run_id'])
|
|
377
514
|
names = [t for t, s in run['tasks'].items() if s not in ('PENDING', 'BLOCKED', None)]
|
|
@@ -399,7 +536,11 @@ def compute(catalog, history):
|
|
|
399
536
|
if not run['live'] and _isdir(run['path']):
|
|
400
537
|
group['command'] = 'forge runs rm %s --worktrees --branches --dry-run' % quote(run['path'])
|
|
401
538
|
run_groups.append(group)
|
|
402
|
-
|
|
539
|
+
# A path that is no repository any more (a checkout deleted and its folder reused) has nothing to list; a real
|
|
540
|
+
# failure (a timeout, git's safe.directory refusal) is named, since it hides that repository's worktrees.
|
|
541
|
+
notes = ['git could not list the worktrees of %s (%s): its worktrees are shown from what is on disk and the dataset'
|
|
542
|
+
% (repo, why) for repo, why in sorted(failures.items())
|
|
543
|
+
if _real(repo) not in roots and 'not a git repository' not in why]
|
|
403
544
|
if hist is None:
|
|
404
545
|
notes.append('the dataset could not be read: only what git and the run dirs say is listed')
|
|
405
546
|
elif not hist.get('enabled'):
|
|
@@ -451,7 +592,7 @@ def _unknown(rows, path, run_id, by_root):
|
|
|
451
592
|
rows[real] = dict(path=path, repo=run['root'] if run else None, git_dir=None, run=run['key'] if run else None,
|
|
452
593
|
run_id=run_id, run_path=run['path'] if run else None, task=name if kind == 'task' else None,
|
|
453
594
|
branch=None, kind=kind, status='unknown', merged=None, head=None, commit=None, created=None,
|
|
454
|
-
removed=None, derived=False, locked=None, size=None, why=None)
|
|
595
|
+
removed=None, derived=False, locked=None, size=None, why=None, leftover=_leftover(path))
|
|
455
596
|
|
|
456
597
|
|
|
457
598
|
def _derived(rows, path, repo, run_id, name, run):
|