@giamme/forge 0.20.0 → 0.22.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 +36 -0
- package/README.md +13 -3
- package/VERSION +1 -1
- package/bin/forge.js +104 -0
- package/docs/README.md +1 -0
- package/docs/development.md +1 -1
- package/docs/install.md +91 -2
- package/docs/reviews.md +6 -4
- package/docs/troubleshooting.md +1 -1
- package/forge +4 -0
- package/forge.cmd +56 -0
- package/package.json +5 -3
- package/scripts/forge-artifact.sh +5 -1
- package/scripts/forge-config.py +10 -9
- package/scripts/forge-control.py +61 -38
- package/scripts/forge-dispatch.sh +108 -31
- package/scripts/forge-group.py +2 -1
- package/scripts/forge-guard.py +207 -38
- package/scripts/forge-handoff.py +14 -17
- package/scripts/forge-install.sh +82 -9
- package/scripts/forge-issues.py +5 -2
- package/scripts/forge-lib-env.sh +158 -0
- package/scripts/forge-lib-group.sh +5 -5
- package/scripts/forge-lib-plans.sh +8 -3
- package/scripts/forge-lib-task.sh +40 -15
- package/scripts/forge-memory.sh +2 -0
- package/scripts/forge-metrics.sh +6 -1
- package/scripts/forge-parallel.sh +174 -53
- package/scripts/forge-planner.py +28 -2
- package/scripts/forge-pre-review.py +11 -4
- package/scripts/forge-ripwire.py +68 -22
- package/scripts/forge-route.py +10 -3
- package/scripts/forge-runs-compact.py +3 -2
- package/scripts/forge-runs-rm.py +14 -14
- package/scripts/forge-runtime.py +38 -21
- package/scripts/forge-schedule.py +90 -56
- package/scripts/forge-shadow.py +16 -9
- package/scripts/forge-solo.sh +6 -2
- package/scripts/forge-summarize.py +7 -3
- package/scripts/forge-sweep.py +8 -3
- package/scripts/forge-ui.py +8 -13
- package/scripts/forge-update.sh +6 -1
- package/scripts/forge-verify.py +30 -23
- package/scripts/forge-win.sh +156 -0
- package/scripts/forge_brief/__init__.py +7 -2
- package/scripts/forge_brief/proposals.py +13 -3
- package/scripts/forge_decide/budget.py +18 -8
- package/scripts/forge_decide/replay.py +15 -5
- package/scripts/forge_findings/apply.py +2 -1
- package/scripts/forge_findings/store.py +16 -4
- package/scripts/forge_findings/triage.py +6 -15
- package/scripts/forge_flock.py +102 -0
- package/scripts/forge_fractal/__init__.py +7 -3
- package/scripts/forge_fractal/cli.py +7 -2
- package/scripts/forge_fractal/execution.py +14 -14
- package/scripts/forge_fractal/invocation.py +3 -2
- package/scripts/forge_fractal/pipeline.py +2 -1
- package/scripts/forge_fractal/selection.py +2 -1
- package/scripts/forge_identity.py +2 -1
- package/scripts/forge_locations.py +14 -4
- package/scripts/forge_posix.py +125 -0
- package/scripts/forge_proc.py +507 -0
- package/scripts/forge_registry.py +17 -8
- package/scripts/forge_retro/__init__.py +8 -2
- package/scripts/forge_retro/issues.py +2 -1
- package/scripts/forge_side/__init__.py +32 -14
- package/scripts/forge_storage.py +11 -1
- package/ui/forge_ui/control.py +42 -14
- package/ui/forge_ui/reader.py +24 -18
- package/ui/forge_ui/server.py +10 -1
- package/ui/forge_ui/static/scene3d.js +23 -2
|
@@ -36,7 +36,6 @@ does not keep running after `run` returns.
|
|
|
36
36
|
"""
|
|
37
37
|
from __future__ import annotations
|
|
38
38
|
|
|
39
|
-
import fcntl
|
|
40
39
|
import os
|
|
41
40
|
from pathlib import Path
|
|
42
41
|
import re
|
|
@@ -45,10 +44,14 @@ import stat
|
|
|
45
44
|
import subprocess
|
|
46
45
|
import sys
|
|
47
46
|
|
|
47
|
+
SCRIPTS = Path(__file__).resolve().parent.parent
|
|
48
|
+
if str(SCRIPTS) not in sys.path:
|
|
49
|
+
sys.path.insert(0, str(SCRIPTS))
|
|
50
|
+
import forge_flock as fcntl # noqa: E402
|
|
51
|
+
import forge_proc # noqa: E402
|
|
48
52
|
from forge_decide import load_user
|
|
49
53
|
from forge_decide.providers import privacy_floor
|
|
50
54
|
|
|
51
|
-
SCRIPTS = Path(__file__).resolve().parent.parent
|
|
52
55
|
DISPATCH = SCRIPTS / 'forge-dispatch.sh'
|
|
53
56
|
|
|
54
57
|
KINDS = ('brief', 'brief-change', 'summary', 'triage')
|
|
@@ -250,6 +253,13 @@ def _count(kind_dir: Path) -> int:
|
|
|
250
253
|
return total
|
|
251
254
|
|
|
252
255
|
|
|
256
|
+
def _slot_number(name: str) -> int | None:
|
|
257
|
+
"""Parse an ASCII base-10 slot directory name, ignoring Unicode digits like `²`."""
|
|
258
|
+
if not (name.isascii() and name.isdigit()):
|
|
259
|
+
return None
|
|
260
|
+
return int(name)
|
|
261
|
+
|
|
262
|
+
|
|
253
263
|
def _next_n(kind_dir: Path, task: str) -> int:
|
|
254
264
|
"""1 + the highest numeric `<n>` already under this task. Other tasks have their own count."""
|
|
255
265
|
highest = 0
|
|
@@ -260,8 +270,9 @@ def _next_n(kind_dir: Path, task: str) -> int:
|
|
|
260
270
|
except OSError:
|
|
261
271
|
children = []
|
|
262
272
|
for child in children:
|
|
263
|
-
|
|
264
|
-
|
|
273
|
+
number = _slot_number(child.name)
|
|
274
|
+
if number is not None and child.is_dir():
|
|
275
|
+
highest = max(highest, number)
|
|
265
276
|
return highest + 1
|
|
266
277
|
|
|
267
278
|
|
|
@@ -354,7 +365,8 @@ def _triage_slots(home: Path) -> tuple[int, int]:
|
|
|
354
365
|
except OSError:
|
|
355
366
|
return 0, 0
|
|
356
367
|
for child in children:
|
|
357
|
-
|
|
368
|
+
number = _slot_number(child.name)
|
|
369
|
+
if number is None:
|
|
358
370
|
continue
|
|
359
371
|
try:
|
|
360
372
|
info = child.lstat()
|
|
@@ -364,7 +376,7 @@ def _triage_slots(home: Path) -> tuple[int, int]:
|
|
|
364
376
|
raise ValueError('triage dispatch dir must be a real directory, not a symlink')
|
|
365
377
|
if not stat.S_ISDIR(info.st_mode):
|
|
366
378
|
continue
|
|
367
|
-
highest = max(highest,
|
|
379
|
+
highest = max(highest, number)
|
|
368
380
|
count += 1
|
|
369
381
|
return highest, count
|
|
370
382
|
|
|
@@ -478,6 +490,9 @@ def _finish(plan, task, kind, spec, ok, last, directory, reason) -> dict:
|
|
|
478
490
|
|
|
479
491
|
def _signal_group(pgid: int, sig: int, proc: subprocess.Popen) -> None:
|
|
480
492
|
"""Signal the dispatch's session. Never this process's own group."""
|
|
493
|
+
if forge_proc.IS_WINDOWS:
|
|
494
|
+
forge_proc.kill_tree(proc.pid, force=(sig == forge_proc.SIGKILL))
|
|
495
|
+
return
|
|
481
496
|
if pgid == os.getpgrp():
|
|
482
497
|
try:
|
|
483
498
|
proc.send_signal(sig)
|
|
@@ -505,17 +520,20 @@ def _stop_dispatch(proc: subprocess.Popen) -> None:
|
|
|
505
520
|
trap as well.
|
|
506
521
|
"""
|
|
507
522
|
try:
|
|
508
|
-
|
|
509
|
-
pgid = os.getpgid(proc.pid)
|
|
510
|
-
except OSError:
|
|
523
|
+
if forge_proc.IS_WINDOWS:
|
|
511
524
|
pgid = proc.pid
|
|
525
|
+
else:
|
|
526
|
+
try:
|
|
527
|
+
pgid = os.getpgid(proc.pid)
|
|
528
|
+
except OSError:
|
|
529
|
+
pgid = proc.pid
|
|
512
530
|
_signal_group(pgid, signal.SIGTERM, proc)
|
|
513
531
|
try:
|
|
514
532
|
proc.wait(timeout=_STOP_GRACE_S)
|
|
515
533
|
except subprocess.TimeoutExpired:
|
|
516
534
|
pass
|
|
517
535
|
# The shell can be gone while a preflight child is still in the session.
|
|
518
|
-
_signal_group(pgid,
|
|
536
|
+
_signal_group(pgid, forge_proc.SIGKILL, proc)
|
|
519
537
|
try:
|
|
520
538
|
proc.wait(timeout=_STOP_GRACE_S)
|
|
521
539
|
except subprocess.TimeoutExpired:
|
|
@@ -539,14 +557,14 @@ def _dispatch_and_wait(dest: Path, repo, prompt, spec, limit: int, event_dir, ta
|
|
|
539
557
|
return _finish(event_dir, task, kind, spec, False, None, dest, 'error')
|
|
540
558
|
if not repo:
|
|
541
559
|
return _finish(event_dir, task, kind, spec, False, None, dest, 'error')
|
|
542
|
-
argv =
|
|
543
|
-
|
|
544
|
-
|
|
560
|
+
argv = forge_proc.bash_cmd(DISPATCH, 'side', '' if spec is None else str(spec),
|
|
561
|
+
'--repo', str(repo), '--run-dir', str(dest), '--prompt-file', str(dest / 'prompt.txt'),
|
|
562
|
+
'--timeout', str(max(0, limit)))
|
|
545
563
|
# Own session, so a timeout can stop the preflight with the shell.
|
|
546
564
|
try:
|
|
547
565
|
proc = subprocess.Popen(
|
|
548
566
|
argv, stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
|
|
549
|
-
|
|
567
|
+
close_fds=True, **forge_proc.popen_group_kwargs())
|
|
550
568
|
except (OSError, subprocess.SubprocessError):
|
|
551
569
|
return _finish(event_dir, task, kind, spec, False, _last(dest), dest, 'error')
|
|
552
570
|
wait = None if limit <= 0 else limit + _DISPATCH_GRACE_S
|
package/scripts/forge_storage.py
CHANGED
|
@@ -36,9 +36,15 @@ import os
|
|
|
36
36
|
import re
|
|
37
37
|
import shutil
|
|
38
38
|
import stat
|
|
39
|
+
import sys
|
|
39
40
|
import time
|
|
40
41
|
from pathlib import Path
|
|
41
42
|
|
|
43
|
+
_SCRIPTS = str(Path(__file__).resolve().parent)
|
|
44
|
+
if _SCRIPTS not in sys.path:
|
|
45
|
+
sys.path.insert(0, _SCRIPTS)
|
|
46
|
+
import forge_posix # noqa: E402
|
|
47
|
+
|
|
42
48
|
DEP_DIRS = frozenset('node_modules bower_components .venv venv vendor .bundle Pods deps _build .dart_tool elm-stuff .build'.split())
|
|
43
49
|
LOG_MIN = 64 << 10 # a smaller log gains next to nothing from gzip
|
|
44
50
|
LOG_ROLES = ('dwarf', 'qa')
|
|
@@ -241,7 +247,11 @@ def compress_log(path) -> tuple[int, str | None]:
|
|
|
241
247
|
except OSError as error:
|
|
242
248
|
return 0, 'cannot remove %s: %s' % (part, error.strerror or error)
|
|
243
249
|
try:
|
|
244
|
-
fd =
|
|
250
|
+
fd = forge_posix.open_nofollow(
|
|
251
|
+
part,
|
|
252
|
+
os.O_WRONLY | os.O_CREAT | os.O_EXCL | forge_posix.O_NOFOLLOW,
|
|
253
|
+
stat.S_IMODE(before.st_mode),
|
|
254
|
+
)
|
|
245
255
|
with os.fdopen(fd, 'wb') as raw, open(path, 'rb') as source:
|
|
246
256
|
with gzip.GzipFile(filename=os.path.basename(path), mode='wb', fileobj=raw, compresslevel=6,
|
|
247
257
|
mtime=int(before.st_mtime)) as packed:
|
package/ui/forge_ui/control.py
CHANGED
|
@@ -17,11 +17,22 @@ import re
|
|
|
17
17
|
import shutil
|
|
18
18
|
import signal
|
|
19
19
|
import subprocess
|
|
20
|
+
import sys
|
|
20
21
|
import tempfile
|
|
21
22
|
import threading
|
|
22
23
|
import time
|
|
23
24
|
import urllib.parse
|
|
24
25
|
|
|
26
|
+
_SCRIPTS = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))), 'scripts')
|
|
27
|
+
_inserted = _SCRIPTS not in sys.path
|
|
28
|
+
if _inserted:
|
|
29
|
+
sys.path.insert(0, _SCRIPTS)
|
|
30
|
+
try:
|
|
31
|
+
import forge_proc # noqa: E402
|
|
32
|
+
finally:
|
|
33
|
+
if _inserted and _SCRIPTS in sys.path:
|
|
34
|
+
sys.path.remove(_SCRIPTS)
|
|
35
|
+
|
|
25
36
|
|
|
26
37
|
TIMEOUT_S = 60 # one CLI call; a test sets a shorter one
|
|
27
38
|
TERM_WAIT_S = 5 # between SIGTERM and SIGKILL of a timed-out call's process group
|
|
@@ -63,6 +74,7 @@ MAX_DECIDE_VALUE = 256
|
|
|
63
74
|
# The profile object written to `forge config profile … --file -`. The HTTP body is already capped
|
|
64
75
|
# at 64 KiB by the server; this caps the stdin text itself, which a re-encode can make larger.
|
|
65
76
|
MAX_PROFILE_BODY = 64 * 1024
|
|
77
|
+
MAX_PROFILE_DEPTH = 64 # a profile is a few levels deep
|
|
66
78
|
# A brief answer, in characters. The CLI then keeps the leading 4 KiB of what remains after it
|
|
67
79
|
# strips control characters; this bound is the one the route enforces before that call.
|
|
68
80
|
MAX_ANSWER = 4096
|
|
@@ -160,6 +172,9 @@ class CliResult:
|
|
|
160
172
|
|
|
161
173
|
|
|
162
174
|
def _signal_group(pgid, sig):
|
|
175
|
+
if forge_proc.IS_WINDOWS:
|
|
176
|
+
forge_proc.kill_tree(pgid, force=(sig == forge_proc.SIGKILL))
|
|
177
|
+
return
|
|
163
178
|
try:
|
|
164
179
|
os.killpg(pgid, sig)
|
|
165
180
|
except (ProcessLookupError, PermissionError):
|
|
@@ -180,7 +195,7 @@ def run_cli(argv, timeout, stdin=None):
|
|
|
180
195
|
try:
|
|
181
196
|
proc = subprocess.Popen(argv, stdin=subprocess.PIPE if stdin is not None else subprocess.DEVNULL,
|
|
182
197
|
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
|
|
183
|
-
|
|
198
|
+
close_fds=True, env=env, **forge_proc.popen_group_kwargs())
|
|
184
199
|
except OSError as exc:
|
|
185
200
|
return CliResult(error=f'cannot run the forge CLI: {exc.strerror or exc}')
|
|
186
201
|
try:
|
|
@@ -192,14 +207,14 @@ def run_cli(argv, timeout, stdin=None):
|
|
|
192
207
|
while proc.poll() is None and time.monotonic() < deadline:
|
|
193
208
|
time.sleep(0.05)
|
|
194
209
|
# Children that outlive the leader (or ignore SIGTERM) die here; the leader is reaped by wait().
|
|
195
|
-
_signal_group(pgid,
|
|
210
|
+
_signal_group(pgid, forge_proc.SIGKILL)
|
|
196
211
|
proc.wait()
|
|
197
212
|
for pipe in (proc.stdin, proc.stdout, proc.stderr):
|
|
198
213
|
if pipe:
|
|
199
214
|
pipe.close()
|
|
200
215
|
return CliResult(timed_out=True)
|
|
201
216
|
except BaseException:
|
|
202
|
-
_signal_group(proc.pid,
|
|
217
|
+
_signal_group(proc.pid, forge_proc.SIGKILL)
|
|
203
218
|
proc.wait()
|
|
204
219
|
raise
|
|
205
220
|
return CliResult(code=proc.returncode, stdout=out.decode('utf-8', 'replace'), stderr=err.decode('utf-8', 'replace'))
|
|
@@ -334,7 +349,9 @@ class Context:
|
|
|
334
349
|
`limit` is the route's timeout; a timeout given to `dispatch` (a test's) replaces it.
|
|
335
350
|
`stdin` is bytes for a call that uses `--file -`, or None. `json_stdout` is false when a
|
|
336
351
|
successful CLI prints text (a brief answer, including a late-answer notice)."""
|
|
337
|
-
|
|
352
|
+
raw = [str(self.cli), *args]
|
|
353
|
+
argv = forge_proc.resolve_win_command(raw)[1] if forge_proc.IS_WINDOWS else raw
|
|
354
|
+
result = run_cli(argv, self.timeout or limit or TIMEOUT_S, stdin=stdin)
|
|
338
355
|
return map_exit(result) if json_stdout else _text_exit(result)
|
|
339
356
|
|
|
340
357
|
def locked(self, work):
|
|
@@ -838,10 +855,26 @@ def _profile_value(value):
|
|
|
838
855
|
return value
|
|
839
856
|
|
|
840
857
|
|
|
858
|
+
def _nested_deeper_than(value, limit):
|
|
859
|
+
"""Whether lists and objects nest more than `limit` levels, checked without recursion."""
|
|
860
|
+
stack = [(value, 1)]
|
|
861
|
+
while stack:
|
|
862
|
+
item, depth = stack.pop()
|
|
863
|
+
if isinstance(item, (dict, list)):
|
|
864
|
+
if depth > limit:
|
|
865
|
+
return True
|
|
866
|
+
stack.extend((child, depth + 1) for child in (item.values() if isinstance(item, dict) else item))
|
|
867
|
+
return False
|
|
868
|
+
|
|
869
|
+
|
|
841
870
|
def _profile_stdin(value):
|
|
842
871
|
"""The bytes `--file -` reads. A re-encode can be larger than the HTTP body, so it is capped on its own."""
|
|
843
872
|
if not isinstance(value, dict):
|
|
844
873
|
raise BadBody('body must be a JSON object')
|
|
874
|
+
# Up to Python 3.11 json.dumps raises RecursionError on a deep enough value; from 3.12 it
|
|
875
|
+
# goes much deeper, so the limit is explicit.
|
|
876
|
+
if _nested_deeper_than(value, MAX_PROFILE_DEPTH):
|
|
877
|
+
raise BadBody(f'body is nested more than {MAX_PROFILE_DEPTH} levels deep')
|
|
845
878
|
try:
|
|
846
879
|
raw = json.dumps(value, allow_nan=False).encode('utf-8')
|
|
847
880
|
except (TypeError, ValueError, RecursionError):
|
|
@@ -1416,15 +1449,7 @@ def _scheduler_live(path):
|
|
|
1416
1449
|
pid = json.load(handle).get('pid')
|
|
1417
1450
|
except (OSError, ValueError, AttributeError, RecursionError):
|
|
1418
1451
|
return False
|
|
1419
|
-
|
|
1420
|
-
return False
|
|
1421
|
-
try:
|
|
1422
|
-
os.kill(pid, 0)
|
|
1423
|
-
except PermissionError:
|
|
1424
|
-
return True
|
|
1425
|
-
except (OSError, OverflowError):
|
|
1426
|
-
return False
|
|
1427
|
-
return True
|
|
1452
|
+
return forge_proc.pid_alive(pid)
|
|
1428
1453
|
|
|
1429
1454
|
|
|
1430
1455
|
def _task_answer(ctx):
|
|
@@ -1920,7 +1945,10 @@ def _specs_check(ctx):
|
|
|
1920
1945
|
spec = _triage_spec(params['spec'])
|
|
1921
1946
|
except BadBody as exc:
|
|
1922
1947
|
return _invalid(str(exc))
|
|
1923
|
-
|
|
1948
|
+
argv = forge_proc.bash_cmd(_DISPATCH, 'doctor', '--spec', spec, '--role', 'side') if forge_proc.IS_WINDOWS else [
|
|
1949
|
+
'bash', _DISPATCH, 'doctor', '--spec', spec, '--role', 'side',
|
|
1950
|
+
]
|
|
1951
|
+
result = run_cli(argv, ctx.timeout or TIMEOUT_S)
|
|
1924
1952
|
if result.timed_out:
|
|
1925
1953
|
return 504, {'error': 'timeout', 'detail': TIMEOUT_DETAIL}
|
|
1926
1954
|
if result.error:
|
package/ui/forge_ui/reader.py
CHANGED
|
@@ -14,6 +14,17 @@ import sys
|
|
|
14
14
|
import time
|
|
15
15
|
import urllib.parse
|
|
16
16
|
|
|
17
|
+
_SCRIPTS = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))), 'scripts')
|
|
18
|
+
_inserted = _SCRIPTS not in sys.path
|
|
19
|
+
if _inserted:
|
|
20
|
+
sys.path.insert(0, _SCRIPTS)
|
|
21
|
+
try:
|
|
22
|
+
import forge_posix # noqa: E402
|
|
23
|
+
import forge_proc # noqa: E402
|
|
24
|
+
finally:
|
|
25
|
+
if _inserted and _SCRIPTS in sys.path:
|
|
26
|
+
sys.path.remove(_SCRIPTS)
|
|
27
|
+
|
|
17
28
|
from forge_ui import checks, diffs, executions, findings, fractal, groups, links, repos, transcripts
|
|
18
29
|
from forge_ui.findings import verdict as _verdict
|
|
19
30
|
|
|
@@ -357,7 +368,12 @@ def _created(path, names):
|
|
|
357
368
|
info = os.stat(path / name)
|
|
358
369
|
except (OSError, ValueError):
|
|
359
370
|
continue
|
|
360
|
-
|
|
371
|
+
birth = getattr(info, 'st_birthtime', None)
|
|
372
|
+
if birth and sys.platform in ('win32', 'cygwin'):
|
|
373
|
+
# Windows keeps a file's creation time when its mtime is set earlier, where macOS moves
|
|
374
|
+
# the birth time back with it: the earlier of the two is the start there too.
|
|
375
|
+
birth = min(birth, info.st_mtime)
|
|
376
|
+
value = birth or info.st_mtime
|
|
361
377
|
if math.isfinite(value):
|
|
362
378
|
times.append(float(value))
|
|
363
379
|
return min(times) if times else None
|
|
@@ -702,15 +718,7 @@ def _scheduler(reader):
|
|
|
702
718
|
"""RunDetail.scheduler: whether a scheduler runs this plan now, and, while one does, what holds it: a drain, a
|
|
703
719
|
stop, infrastructure pauses (scheduler-written infra.paused) and the capacity it dispatches up to."""
|
|
704
720
|
pid = (reader.object('scheduler.live') or {}).get('pid') if reader.exists('scheduler.live') else None
|
|
705
|
-
live =
|
|
706
|
-
if type(pid) is int and pid > 0:
|
|
707
|
-
try:
|
|
708
|
-
os.kill(pid, 0)
|
|
709
|
-
live = True
|
|
710
|
-
except PermissionError:
|
|
711
|
-
live = True
|
|
712
|
-
except (OSError, OverflowError):
|
|
713
|
-
live = False
|
|
721
|
+
live = forge_proc.pid_alive(pid)
|
|
714
722
|
result = dict(live=live, drained=False, stopping=None, pauses=[], max_parallel=None)
|
|
715
723
|
if not live:
|
|
716
724
|
return result
|
|
@@ -955,14 +963,9 @@ def _brief_writer_alive(reader):
|
|
|
955
963
|
"""brief.pid names a running process: the question writer `run` started has not finished."""
|
|
956
964
|
try:
|
|
957
965
|
pid = int((reader.text('brief.pid') or '').split()[0])
|
|
958
|
-
if pid > 0:
|
|
959
|
-
os.kill(pid, 0)
|
|
960
|
-
return True
|
|
961
|
-
except PermissionError:
|
|
962
|
-
return True
|
|
963
966
|
except (OSError, ValueError, IndexError):
|
|
964
|
-
|
|
965
|
-
return
|
|
967
|
+
return False
|
|
968
|
+
return forge_proc.pid_alive(pid)
|
|
966
969
|
|
|
967
970
|
|
|
968
971
|
def _brief_wait(reader, ident):
|
|
@@ -3287,7 +3290,10 @@ def _log_name(lane, k, retry=False):
|
|
|
3287
3290
|
def _open_log(path, name):
|
|
3288
3291
|
"""The open log and its stat, or None: a missing file, a symlink, anything not regular."""
|
|
3289
3292
|
try:
|
|
3290
|
-
fd =
|
|
3293
|
+
fd = forge_posix.open_nofollow(
|
|
3294
|
+
os.path.join(os.path.realpath(path), name),
|
|
3295
|
+
os.O_RDONLY | forge_posix.O_NOFOLLOW | forge_posix.O_NONBLOCK,
|
|
3296
|
+
)
|
|
3291
3297
|
except OSError:
|
|
3292
3298
|
return None
|
|
3293
3299
|
try:
|
package/ui/forge_ui/server.py
CHANGED
|
@@ -15,6 +15,7 @@ import os
|
|
|
15
15
|
from pathlib import Path
|
|
16
16
|
import re
|
|
17
17
|
import secrets
|
|
18
|
+
import socketserver
|
|
18
19
|
import sys
|
|
19
20
|
import threading
|
|
20
21
|
import time
|
|
@@ -460,8 +461,16 @@ class Handler(BaseHTTPRequestHandler):
|
|
|
460
461
|
pass # the client hung up (BrokenPipeError, ConnectionResetError, ...): nothing to tell it
|
|
461
462
|
|
|
462
463
|
|
|
464
|
+
class _Server(ThreadingHTTPServer):
|
|
465
|
+
def server_bind(self):
|
|
466
|
+
# HTTPServer.server_bind sets server_name from socket.getfqdn(host), a reverse DNS lookup
|
|
467
|
+
# that can take many seconds on macOS. forge-ui serves loopback only and never reads it.
|
|
468
|
+
socketserver.TCPServer.server_bind(self)
|
|
469
|
+
self.server_name, self.server_port = self.server_address[:2]
|
|
470
|
+
|
|
471
|
+
|
|
463
472
|
def make_server(catalog, host='127.0.0.1', port=0, static_dir=None, quiet=False, read_only=False):
|
|
464
|
-
server =
|
|
473
|
+
server = _Server((host, port), Handler)
|
|
465
474
|
server.catalog = catalog
|
|
466
475
|
server.read_only = read_only
|
|
467
476
|
server.token = secrets.token_urlsafe(32) # per process; only the page this process serves carries it
|
|
@@ -19,6 +19,16 @@ const clamp = v => Math.max(0, Math.min(1, v));
|
|
|
19
19
|
const segT = (v, a, b) => clamp((v - a) / (b - a));
|
|
20
20
|
const ez = t => t < .5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2;
|
|
21
21
|
const back = t => t <= 0 ? 0 : t >= 1 ? 1 : 1 + 2.2 * Math.pow(t - 1, 3) + 1.2 * Math.pow(t - 1, 2);
|
|
22
|
+
// Opening stagger window on the parent task's progress p (0..1): keeps step 0.05 through
|
|
23
|
+
// 8 slots (maxIdx <= 7) and scales down above that so the last part's window still ends at 1.
|
|
24
|
+
export function partWindow(idx, maxIdx) {
|
|
25
|
+
const step = maxIdx > 7 ? .36 / maxIdx : .05;
|
|
26
|
+
return [.34 + idx * step, .64 + idx * step];
|
|
27
|
+
}
|
|
28
|
+
export function partRise(p, idx, maxIdx) {
|
|
29
|
+
const [a, b] = partWindow(idx, maxIdx);
|
|
30
|
+
return back(segT(p, a, b));
|
|
31
|
+
}
|
|
22
32
|
const MODEL_PALETTE = ['#4e9af1', '#f08c3a', '#6cc070', '#c46fd8', '#e0c341', '#4fc2c0', '#e06a8c', '#9a8cff', '#a3b84a', '#d98f6b'];
|
|
23
33
|
const KIND_H = { dwarf: 24, qa: 13, shadow: 12 };
|
|
24
34
|
|
|
@@ -351,6 +361,8 @@ export async function createStage(host, cb = {}) {
|
|
|
351
361
|
const padX = 10, padT = 22, padB = 10, gx = 8, gy = 7;
|
|
352
362
|
const cw = (w - 2 * padX - (C - 1) * gx) / C, ch = Math.min(46, (d - padT - padB - (R - 1) * gy) / R);
|
|
353
363
|
el.zoneEls = [];
|
|
364
|
+
const partEls = [];
|
|
365
|
+
let maxIdx = 0;
|
|
354
366
|
tp.zones.forEach((z, ci) => {
|
|
355
367
|
const zx = x + padX + ci * (cw + gx), zy = y + padT;
|
|
356
368
|
const zm = E.lmat({ dashed: true, dashSize: 4 * TS, gapSize: 3 * TS });
|
|
@@ -365,7 +377,9 @@ export async function createStage(host, cb = {}) {
|
|
|
365
377
|
const part = tp.parts.find(p => p.id === pid);
|
|
366
378
|
const ph = KIND_H[part.kind] || 14;
|
|
367
379
|
const n = { x: zx, y: zy + ri * (ch + gy), w: cw, d: ch, h: ph };
|
|
368
|
-
const
|
|
380
|
+
const idx = ri + ci * R;
|
|
381
|
+
maxIdx = Math.max(maxIdx, idx);
|
|
382
|
+
const k = newEl('p:' + task.id + ':' + part.id, 'part', G, n, { part, task: task.id, parent: el.id, idx, maxIdx: 0 });
|
|
369
383
|
el.root.remove(k.root); G.add(k.root);
|
|
370
384
|
setStatus(k, part.planned ? 'PENDING' : part.status);
|
|
371
385
|
const r = part.kind === 'qa' ? Math.min(cw, ch) * .3 : Math.min(4, Math.min(cw, ch) * .07);
|
|
@@ -380,9 +394,11 @@ export async function createStage(host, cb = {}) {
|
|
|
380
394
|
const fs = pt.exec && pt.exec.findings || pt.shadow && pt.shadow.findings;
|
|
381
395
|
if (fs && fs.worst) chip(cx, s, Cc, pad, ch - pad - 6 * 1.6, `${fs.worst}×${fs[fs.worst]}`, E.sevHex(fs.worst), { f: Math.min(5, ch * .14) });
|
|
382
396
|
}, 'cover', { x: zx, y: n.y, z: ph });
|
|
397
|
+
partEls.push(k);
|
|
383
398
|
el.kids.push(k);
|
|
384
399
|
});
|
|
385
400
|
});
|
|
401
|
+
for (const k of partEls) k.data.maxIdx = maxIdx;
|
|
386
402
|
el.innerFlows = [];
|
|
387
403
|
for (const l of tp.links) {
|
|
388
404
|
const a = EL.get('p:' + task.id + ':' + l.from), b = EL.get('p:' + task.id + ':' + l.to); if (!a || !b) continue;
|
|
@@ -952,7 +968,7 @@ export async function createStage(host, cb = {}) {
|
|
|
952
968
|
let lift = 0, ob = 1, ol = 1;
|
|
953
969
|
const pr = PROG.get(el.id);
|
|
954
970
|
if (pr) { const p = pr.p; lift = ez(segT(p, .04, .46)); ob = 1 - segT(p, .06, .3); ol = 1 - segT(p, .14, .46); }
|
|
955
|
-
if (el.kind === 'part') { const par = EL.get(el.data.parent), pp = par && PROG.get(par.id); const p = pp ? pp.p : 0; const
|
|
971
|
+
if (el.kind === 'part') { const par = EL.get(el.data.parent), pp = par && PROG.get(par.id); const p = pp ? pp.p : 0; const q = partRise(p, el.data.idx, el.data.maxIdx); el.q = q; el.root.visible = q > .001; el.cover.scale.y = Math.max(.001, q); }
|
|
956
972
|
el.cover.visible = ol > .003;
|
|
957
973
|
el.cover.position.y = (el.kind === 'task' ? 120 : 0) * lift * TS;
|
|
958
974
|
if (el.kind === 'task' || el.kind === 'finish') el.cover.scale.y = Math.max(.05, c.hk);
|
|
@@ -1440,6 +1456,11 @@ export async function createStage(host, cb = {}) {
|
|
|
1440
1456
|
return {
|
|
1441
1457
|
view: st.view, mode: st.mode, rebuilds: st.rebuilds, sel: st.sel, prog: [...PROG].map(([id, p]) => [id, p.p, p.t]), fade: !!st.fade,
|
|
1442
1458
|
nodes: [...EL.values()].map(el => ({ id: el.id, kind: el.kind, status: el.status, sel: el.tgt.sel, vis: el.tgt.vis })),
|
|
1459
|
+
parts(taskId) {
|
|
1460
|
+
const prefix = 'p:' + taskId + ':';
|
|
1461
|
+
return [...EL.values()].filter(el => el.kind === 'part' && el.id.startsWith(prefix))
|
|
1462
|
+
.map(el => ({ id: el.id, idx: el.data.idx, maxIdx: el.data.maxIdx, q: el.q, visible: el.root.visible, scaleY: el.cover.scale.y }));
|
|
1463
|
+
},
|
|
1443
1464
|
screenPos(id) { const el = EL.get(id); if (!el) return null; const r = E.canvas.getBoundingClientRect(); const p = E.project(el.n.x + el.n.w / 2, el.n.y + el.n.d / 2, el.n.h); return { x: r.left + p.x, y: r.top + p.y, on: p.on }; },
|
|
1444
1465
|
settle() { for (const el of EL.values()) Object.assign(el.cur, el.tgt); for (const pr of PROG.values()) pr.p = pr.t; E.invalidate(); },
|
|
1445
1466
|
beaconScale: () => ({ unit: BEACONS.unit, ppu: E.pxPerUnit() }),
|