@giamme/forge 0.19.0 → 0.21.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 +32 -0
- package/README.md +7 -0
- package/SKILL.md +3 -0
- package/VERSION +1 -1
- package/docs/README.md +1 -0
- package/docs/commands.md +137 -5
- package/docs/development.md +1 -1
- package/docs/forge-ui.md +70 -19
- package/forge +8 -2
- package/package.json +1 -1
- package/references/decompose.md +20 -8
- package/references/memory.md +30 -5
- package/scripts/forge-config.py +10 -9
- package/scripts/forge-control.py +51 -35
- package/scripts/forge-findings.py +675 -0
- package/scripts/forge-group.py +2 -1
- package/scripts/forge-guard.py +71 -33
- package/scripts/forge-handoff.py +14 -17
- package/scripts/forge-issues.py +233 -99
- package/scripts/forge-memory.sh +471 -19
- package/scripts/forge-parallel.sh +24 -14
- 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 +36 -19
- package/scripts/forge-schedule.py +135 -62
- package/scripts/forge-shadow.py +16 -9
- package/scripts/forge-summarize.py +7 -3
- package/scripts/forge-sweep.py +206 -46
- package/scripts/forge-ui.py +8 -13
- package/scripts/forge-verify.py +29 -23
- package/scripts/forge_brief/__init__.py +1 -1
- package/scripts/forge_brief/proposals.py +7 -2
- package/scripts/forge_decide/budget.py +6 -1
- package/scripts/forge_decide/replay.py +6 -1
- package/scripts/forge_findings/__init__.py +17 -0
- package/scripts/forge_findings/apply.py +442 -0
- package/scripts/forge_findings/status.py +43 -0
- package/scripts/forge_findings/store.py +595 -0
- package/scripts/forge_findings/tags.py +53 -0
- package/scripts/forge_findings/triage.py +594 -0
- package/scripts/forge_flock.py +87 -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 +328 -0
- package/scripts/forge_locations.py +14 -4
- package/scripts/forge_memory_list.py +7 -3
- package/scripts/forge_posix.py +108 -0
- package/scripts/forge_proc.py +399 -0
- package/scripts/forge_registry.py +15 -6
- package/scripts/forge_retro/__init__.py +8 -2
- package/scripts/forge_retro/issues.py +2 -1
- package/scripts/forge_side/__init__.py +232 -38
- package/scripts/forge_storage.py +11 -1
- package/ui/docs/api.md +130 -12
- package/ui/forge_ui/control.py +693 -17
- package/ui/forge_ui/export.py +1 -1
- package/ui/forge_ui/projects.py +209 -22
- package/ui/forge_ui/reader.py +18 -17
- package/ui/forge_ui/server.py +10 -1
- package/ui/forge_ui/static/findingsactions.js +201 -0
- package/ui/forge_ui/static/index.html +2 -0
- package/ui/forge_ui/static/projectsview.js +600 -45
- package/ui/forge_ui/static/style.css +59 -0
- package/ui/forge_ui/static/triageview.js +423 -0
|
@@ -20,6 +20,12 @@ Precedence for each switch, first match wins:
|
|
|
20
20
|
A `brief-change` dispatch (a wave-scoped proposal, #136) follows the brief settings: the same
|
|
21
21
|
level, `FORGE_BRIEF=off`, model, `never-send` floor and its own cap.
|
|
22
22
|
|
|
23
|
+
A `triage` dispatch reads one repository's open findings from outside any plan. It is a
|
|
24
|
+
kind, but it has no plan dir: `allowed` and `run` raise ValueError (`use the triage
|
|
25
|
+
functions`). `triage_home` and `allocate_triage` place it at
|
|
26
|
+
`${XDG_STATE_HOME:-~/.local/state}/forge/triage/<key>/<n>/`. An empty or relative
|
|
27
|
+
`XDG_STATE_HOME` counts as unset. `triage_allowed` and `run_triage` are the entry points.
|
|
28
|
+
|
|
23
29
|
`allowed` refuses with `env`, `off`, `never-send` (the plan repo's privacy floor),
|
|
24
30
|
`no-model` or `cap`, in that order. For a summary, `tasks/<task>/summaries` (`on` or
|
|
25
31
|
`off`) overrides the plan's mode and nothing else. The cap is
|
|
@@ -30,22 +36,30 @@ does not keep running after `run` returns.
|
|
|
30
36
|
"""
|
|
31
37
|
from __future__ import annotations
|
|
32
38
|
|
|
33
|
-
import fcntl
|
|
34
39
|
import os
|
|
35
40
|
from pathlib import Path
|
|
41
|
+
import re
|
|
36
42
|
import signal
|
|
43
|
+
import stat
|
|
37
44
|
import subprocess
|
|
38
45
|
import sys
|
|
39
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
|
|
40
52
|
from forge_decide import load_user
|
|
41
53
|
from forge_decide.providers import privacy_floor
|
|
42
54
|
|
|
43
|
-
SCRIPTS = Path(__file__).resolve().parent.parent
|
|
44
55
|
DISPATCH = SCRIPTS / 'forge-dispatch.sh'
|
|
45
56
|
|
|
46
|
-
KINDS = ('brief', 'brief-change', 'summary')
|
|
57
|
+
KINDS = ('brief', 'brief-change', 'summary', 'triage')
|
|
47
58
|
# Kinds that follow the brief settings: `FORGE_BRIEF=off`, the plan's brief level and brief model.
|
|
48
59
|
BRIEF_KINDS = ('brief', 'brief-change')
|
|
60
|
+
# Numbered triage dispatch dirs one repository key may keep. A non-numeric sibling is not one.
|
|
61
|
+
_TRIAGE_CAP = 200
|
|
62
|
+
_TRIAGE_KEY = re.compile(r'^[0-9a-f]{16}$')
|
|
49
63
|
ON_OFF = ('off', 'on')
|
|
50
64
|
BRIEF_LEVELS = ('off', 'advisory', 'gated', 'strict')
|
|
51
65
|
BRIEF_SCOPES = ('task', 'wave', 'plan')
|
|
@@ -65,6 +79,10 @@ class _Capped(Exception):
|
|
|
65
79
|
"""The per-kind dispatch cap is already full. Not an error for the caller."""
|
|
66
80
|
|
|
67
81
|
|
|
82
|
+
class TriageCapped(Exception):
|
|
83
|
+
"""This repository key already holds 200 triage dispatch dirs."""
|
|
84
|
+
|
|
85
|
+
|
|
68
86
|
def _read(path: Path) -> str | None:
|
|
69
87
|
try:
|
|
70
88
|
text = Path(path).read_text(encoding='utf-8')
|
|
@@ -287,11 +305,105 @@ def _allocate(plan: Path, kind: str, task: str) -> Path:
|
|
|
287
305
|
os.close(fd)
|
|
288
306
|
|
|
289
307
|
|
|
308
|
+
def _state_root() -> Path:
|
|
309
|
+
"""Absolute `XDG_STATE_HOME`, or `~/.local/state`. Empty or relative counts as unset.
|
|
310
|
+
|
|
311
|
+
A relative state home would name a directory below the current one, usually the
|
|
312
|
+
repository. The same rule as forge-issues' findings store.
|
|
313
|
+
"""
|
|
314
|
+
for candidate in (os.environ.get('XDG_STATE_HOME') or '', '~/.local/state'):
|
|
315
|
+
try:
|
|
316
|
+
base = Path(candidate).expanduser() if candidate else None
|
|
317
|
+
except RuntimeError: # no home directory to expand "~" against
|
|
318
|
+
base = None
|
|
319
|
+
if base is not None and base.is_absolute():
|
|
320
|
+
return base
|
|
321
|
+
raise ValueError('cannot place the triage home: no home directory and no absolute XDG_STATE_HOME')
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
def triage_home(key) -> Path:
|
|
325
|
+
"""`${XDG_STATE_HOME:-~/.local/state}/forge/triage/<key>`.
|
|
326
|
+
|
|
327
|
+
`key` is 16 lowercase hex characters, the repository identity computed elsewhere.
|
|
328
|
+
This does not create the directory and does not import that computation.
|
|
329
|
+
"""
|
|
330
|
+
if not isinstance(key, str) or _TRIAGE_KEY.fullmatch(key) is None:
|
|
331
|
+
raise ValueError('triage key must be 16 lowercase hex chars, not %r' % (key,))
|
|
332
|
+
return _state_root() / 'forge' / 'triage' / key
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
def _refuse_symlink(path: Path, what: str) -> None:
|
|
336
|
+
"""Raise ValueError when `path` is a symlink. A path that is not there yet is fine."""
|
|
337
|
+
try:
|
|
338
|
+
info = path.lstat()
|
|
339
|
+
except FileNotFoundError:
|
|
340
|
+
return
|
|
341
|
+
except OSError as exc:
|
|
342
|
+
raise ValueError('%s: %s' % (what, exc.strerror or exc)) from exc
|
|
343
|
+
if stat.S_ISLNK(info.st_mode):
|
|
344
|
+
raise ValueError('%s must be a real directory, not a symlink' % what)
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
def _triage_slots(home: Path) -> tuple[int, int]:
|
|
348
|
+
"""`(highest numeric n, how many real numeric dirs)`.
|
|
349
|
+
|
|
350
|
+
A sibling whose name is not numeric takes no number, as `_next_n` does, and is not
|
|
351
|
+
a dispatch dir. A symlinked numeric directory is refused rather than followed.
|
|
352
|
+
"""
|
|
353
|
+
highest = 0
|
|
354
|
+
count = 0
|
|
355
|
+
try:
|
|
356
|
+
children = list(home.iterdir())
|
|
357
|
+
except OSError:
|
|
358
|
+
return 0, 0
|
|
359
|
+
for child in children:
|
|
360
|
+
if not child.name.isdigit():
|
|
361
|
+
continue
|
|
362
|
+
try:
|
|
363
|
+
info = child.lstat()
|
|
364
|
+
except OSError:
|
|
365
|
+
continue
|
|
366
|
+
if stat.S_ISLNK(info.st_mode):
|
|
367
|
+
raise ValueError('triage dispatch dir must be a real directory, not a symlink')
|
|
368
|
+
if not stat.S_ISDIR(info.st_mode):
|
|
369
|
+
continue
|
|
370
|
+
highest = max(highest, int(child.name))
|
|
371
|
+
count += 1
|
|
372
|
+
return highest, count
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
def allocate_triage(key) -> Path:
|
|
376
|
+
"""Create the next `<triage_home(key)>/<n>/` under an flock on `<home>/.lock`.
|
|
377
|
+
|
|
378
|
+
n starts at 1. A non-numeric sibling takes no number and does not count toward the
|
|
379
|
+
cap of 200 dispatch dirs. Past the cap this raises `TriageCapped`. A symlinked home
|
|
380
|
+
or numeric directory raises ValueError, and nothing is written through the link.
|
|
381
|
+
"""
|
|
382
|
+
home = triage_home(key)
|
|
383
|
+
_refuse_symlink(home, 'triage home')
|
|
384
|
+
fd = _lock(home)
|
|
385
|
+
try:
|
|
386
|
+
_refuse_symlink(home, 'triage home')
|
|
387
|
+
highest, count = _triage_slots(home)
|
|
388
|
+
if count >= _TRIAGE_CAP:
|
|
389
|
+
raise TriageCapped('200 triage dispatch dirs already exist for this repository')
|
|
390
|
+
dest = home / str(highest + 1)
|
|
391
|
+
_refuse_symlink(dest, 'triage dispatch dir')
|
|
392
|
+
dest.mkdir()
|
|
393
|
+
_refuse_symlink(dest, 'triage dispatch dir')
|
|
394
|
+
return dest
|
|
395
|
+
finally:
|
|
396
|
+
os.close(fd)
|
|
397
|
+
|
|
398
|
+
|
|
290
399
|
def allowed(kind, plan, task=None):
|
|
291
400
|
"""`(ok, reason)` for a `brief`, `brief-change` or `summary` dispatch. `reason` is None when it may run.
|
|
292
401
|
|
|
293
402
|
Reasons, in the order they are decided: `env`, `off`, `never-send`, `no-model`, `cap`.
|
|
403
|
+
`triage` is not a plan dispatch: it raises ValueError (`use the triage functions`).
|
|
294
404
|
"""
|
|
405
|
+
if kind == 'triage':
|
|
406
|
+
raise ValueError('use the triage functions')
|
|
295
407
|
if kind not in KINDS:
|
|
296
408
|
raise ValueError('kind must be brief, brief-change or summary, not %r' % (kind,))
|
|
297
409
|
plan = Path(plan)
|
|
@@ -318,6 +430,22 @@ def allowed(kind, plan, task=None):
|
|
|
318
430
|
return True, None
|
|
319
431
|
|
|
320
432
|
|
|
433
|
+
def triage_allowed(repo, spec):
|
|
434
|
+
"""`(ok, reason)` for a triage dispatch. `reason` is None when it may run.
|
|
435
|
+
|
|
436
|
+
Decided in order. No settings file is read: the caller names the spec each time.
|
|
437
|
+
`env` when `FORGE_TRIAGE` is off, `never-send` when `privacy_floor(repo)` says so,
|
|
438
|
+
`no-model` when `spec` is empty.
|
|
439
|
+
"""
|
|
440
|
+
if _env_off('FORGE_TRIAGE'):
|
|
441
|
+
return False, 'env'
|
|
442
|
+
if privacy_floor(repo):
|
|
443
|
+
return False, 'never-send'
|
|
444
|
+
if spec is None or (isinstance(spec, str) and not spec.strip()):
|
|
445
|
+
return False, 'no-model'
|
|
446
|
+
return True, None
|
|
447
|
+
|
|
448
|
+
|
|
321
449
|
def _last(dest: Path):
|
|
322
450
|
path = dest / 'side.last'
|
|
323
451
|
try:
|
|
@@ -353,6 +481,9 @@ def _finish(plan, task, kind, spec, ok, last, directory, reason) -> dict:
|
|
|
353
481
|
|
|
354
482
|
def _signal_group(pgid: int, sig: int, proc: subprocess.Popen) -> None:
|
|
355
483
|
"""Signal the dispatch's session. Never this process's own group."""
|
|
484
|
+
if forge_proc.IS_WINDOWS:
|
|
485
|
+
forge_proc.kill_tree(proc.pid, force=(sig == forge_proc.SIGKILL))
|
|
486
|
+
return
|
|
356
487
|
if pgid == os.getpgrp():
|
|
357
488
|
try:
|
|
358
489
|
proc.send_signal(sig)
|
|
@@ -380,17 +511,20 @@ def _stop_dispatch(proc: subprocess.Popen) -> None:
|
|
|
380
511
|
trap as well.
|
|
381
512
|
"""
|
|
382
513
|
try:
|
|
383
|
-
|
|
384
|
-
pgid = os.getpgid(proc.pid)
|
|
385
|
-
except OSError:
|
|
514
|
+
if forge_proc.IS_WINDOWS:
|
|
386
515
|
pgid = proc.pid
|
|
516
|
+
else:
|
|
517
|
+
try:
|
|
518
|
+
pgid = os.getpgid(proc.pid)
|
|
519
|
+
except OSError:
|
|
520
|
+
pgid = proc.pid
|
|
387
521
|
_signal_group(pgid, signal.SIGTERM, proc)
|
|
388
522
|
try:
|
|
389
523
|
proc.wait(timeout=_STOP_GRACE_S)
|
|
390
524
|
except subprocess.TimeoutExpired:
|
|
391
525
|
pass
|
|
392
526
|
# The shell can be gone while a preflight child is still in the session.
|
|
393
|
-
_signal_group(pgid,
|
|
527
|
+
_signal_group(pgid, forge_proc.SIGKILL, proc)
|
|
394
528
|
try:
|
|
395
529
|
proc.wait(timeout=_STOP_GRACE_S)
|
|
396
530
|
except subprocess.TimeoutExpired:
|
|
@@ -399,6 +533,52 @@ def _stop_dispatch(proc: subprocess.Popen) -> None:
|
|
|
399
533
|
pass
|
|
400
534
|
|
|
401
535
|
|
|
536
|
+
def _dispatch_and_wait(dest: Path, repo, prompt, spec, limit: int, event_dir, task, kind) -> dict:
|
|
537
|
+
"""Write `prompt.txt` and run `forge-dispatch.sh side` in its own session.
|
|
538
|
+
|
|
539
|
+
Shared by `run` and `run_triage`. `event_dir` is the run dir on the `side_dispatch`
|
|
540
|
+
event: the plan, or the triage dest. Returns `{ok, last, dir, reason}` and does not
|
|
541
|
+
raise. A dispatch that outlives `limit` plus `_DISPATCH_GRACE_S` is stopped with
|
|
542
|
+
its session, including a preflight that has not exited.
|
|
543
|
+
"""
|
|
544
|
+
try:
|
|
545
|
+
text = prompt if isinstance(prompt, str) else ('' if prompt is None else str(prompt))
|
|
546
|
+
(dest / 'prompt.txt').write_text(text, encoding='utf-8')
|
|
547
|
+
except (OSError, UnicodeError):
|
|
548
|
+
return _finish(event_dir, task, kind, spec, False, None, dest, 'error')
|
|
549
|
+
if not repo:
|
|
550
|
+
return _finish(event_dir, task, kind, spec, False, None, dest, 'error')
|
|
551
|
+
argv = forge_proc.bash_cmd(DISPATCH, 'side', '' if spec is None else str(spec),
|
|
552
|
+
'--repo', str(repo), '--run-dir', str(dest), '--prompt-file', str(dest / 'prompt.txt'),
|
|
553
|
+
'--timeout', str(max(0, limit)))
|
|
554
|
+
# Own session, so a timeout can stop the preflight with the shell.
|
|
555
|
+
try:
|
|
556
|
+
proc = subprocess.Popen(
|
|
557
|
+
argv, stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
|
|
558
|
+
close_fds=True, **forge_proc.popen_group_kwargs())
|
|
559
|
+
except (OSError, subprocess.SubprocessError):
|
|
560
|
+
return _finish(event_dir, task, kind, spec, False, _last(dest), dest, 'error')
|
|
561
|
+
wait = None if limit <= 0 else limit + _DISPATCH_GRACE_S
|
|
562
|
+
try:
|
|
563
|
+
proc.wait(timeout=wait)
|
|
564
|
+
except subprocess.TimeoutExpired:
|
|
565
|
+
_stop_dispatch(proc)
|
|
566
|
+
return _finish(event_dir, task, kind, spec, False, _last(dest), dest, 'timeout')
|
|
567
|
+
except (OSError, subprocess.SubprocessError):
|
|
568
|
+
_stop_dispatch(proc)
|
|
569
|
+
return _finish(event_dir, task, kind, spec, False, _last(dest), dest, 'error')
|
|
570
|
+
ok = proc.returncode == 0
|
|
571
|
+
reason = None if ok else ('timeout' if proc.returncode == 7 else 'error')
|
|
572
|
+
return _finish(event_dir, task, kind, spec, ok, _last(dest), dest, reason)
|
|
573
|
+
|
|
574
|
+
|
|
575
|
+
def _seconds(timeout, default: int) -> int:
|
|
576
|
+
try:
|
|
577
|
+
return int(timeout)
|
|
578
|
+
except (TypeError, ValueError):
|
|
579
|
+
return default
|
|
580
|
+
|
|
581
|
+
|
|
402
582
|
def run(kind, plan, task, prompt, spec, timeout=900) -> dict:
|
|
403
583
|
"""Dispatch once. Returns `{ok, last, dir, reason}` and never raises on a failure.
|
|
404
584
|
|
|
@@ -408,7 +588,10 @@ def run(kind, plan, task, prompt, spec, timeout=900) -> dict:
|
|
|
408
588
|
when this kind is already at its limit, `timeout` when the dispatch times out,
|
|
409
589
|
`missing` when the dispatch script is not there, and `error` otherwise. A timeout
|
|
410
590
|
stops the dispatch's session, including a preflight that has not exited.
|
|
591
|
+
`triage` is not a plan dispatch: it raises ValueError (`use the triage functions`).
|
|
411
592
|
"""
|
|
593
|
+
if kind == 'triage':
|
|
594
|
+
raise ValueError('use the triage functions')
|
|
412
595
|
if kind not in KINDS:
|
|
413
596
|
raise ValueError('kind must be brief, brief-change or summary, not %r' % (kind,))
|
|
414
597
|
plan = Path(plan)
|
|
@@ -416,46 +599,57 @@ def run(kind, plan, task, prompt, spec, timeout=900) -> dict:
|
|
|
416
599
|
return _finish(plan, task, kind, spec, False, None, None, 'error')
|
|
417
600
|
if not DISPATCH.is_file():
|
|
418
601
|
return _finish(plan, task, kind, spec, False, None, None, 'missing')
|
|
419
|
-
try:
|
|
420
|
-
limit = int(timeout)
|
|
421
|
-
except (TypeError, ValueError):
|
|
422
|
-
limit = 900
|
|
423
602
|
try:
|
|
424
603
|
dest = _allocate(plan, kind, task)
|
|
425
604
|
except _Capped:
|
|
426
605
|
return _finish(plan, task, kind, spec, False, None, None, 'cap')
|
|
427
606
|
except OSError:
|
|
428
607
|
return _finish(plan, task, kind, spec, False, None, None, 'error')
|
|
608
|
+
return _dispatch_and_wait(dest, _read(plan / 'repo'), prompt, spec, _seconds(timeout, 900),
|
|
609
|
+
plan, task, kind)
|
|
610
|
+
|
|
611
|
+
|
|
612
|
+
def _path_or_none(value):
|
|
429
613
|
try:
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
614
|
+
return Path(value)
|
|
615
|
+
except (TypeError, ValueError):
|
|
616
|
+
return None
|
|
617
|
+
|
|
618
|
+
|
|
619
|
+
def _repo_text(repo) -> str:
|
|
620
|
+
if isinstance(repo, Path):
|
|
621
|
+
return str(repo)
|
|
622
|
+
if isinstance(repo, str):
|
|
623
|
+
return repo.strip()
|
|
624
|
+
return '' if repo is None else str(repo).strip()
|
|
625
|
+
|
|
626
|
+
|
|
627
|
+
def run_triage(dest, repo, prompt, spec, timeout=3600) -> dict:
|
|
628
|
+
"""Dispatch one triage read into an already allocated `dest`. Never raises.
|
|
629
|
+
|
|
630
|
+
The caller writes `findings.json` there first. `triage_allowed` is checked first
|
|
631
|
+
(`env`, `never-send`, `no-model`) and then nothing is started. Otherwise this is
|
|
632
|
+
the same `side` dispatch as `run`: `prompt.txt`, its own session, the grace past
|
|
633
|
+
the watchdog, and a session stop on timeout. `reason` is one of those, or
|
|
634
|
+
`timeout`, `missing` or `error`. The `side_dispatch` event has kind `triage`,
|
|
635
|
+
task None, and `dest` as its run dir.
|
|
636
|
+
"""
|
|
637
|
+
directory = _path_or_none(dest)
|
|
441
638
|
try:
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
return _finish(
|
|
447
|
-
|
|
639
|
+
ok, reason = triage_allowed(repo, spec)
|
|
640
|
+
except Exception:
|
|
641
|
+
return _finish(directory, None, 'triage', spec, False, None, None, 'error')
|
|
642
|
+
if not ok:
|
|
643
|
+
return _finish(directory, None, 'triage', spec, False, None, None, reason)
|
|
644
|
+
if directory is None:
|
|
645
|
+
return _finish(None, None, 'triage', spec, False, None, None, 'error')
|
|
646
|
+
if not DISPATCH.is_file():
|
|
647
|
+
return _finish(directory, None, 'triage', spec, False, None, None, 'missing')
|
|
448
648
|
try:
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
return _finish(
|
|
453
|
-
except (OSError, subprocess.SubprocessError):
|
|
454
|
-
_stop_dispatch(proc)
|
|
455
|
-
return _finish(plan, task, kind, spec, False, _last(dest), dest, 'error')
|
|
456
|
-
ok = proc.returncode == 0
|
|
457
|
-
reason = None if ok else ('timeout' if proc.returncode == 7 else 'error')
|
|
458
|
-
return _finish(plan, task, kind, spec, ok, _last(dest), dest, reason)
|
|
649
|
+
return _dispatch_and_wait(directory, _repo_text(repo), prompt, spec, _seconds(timeout, 3600),
|
|
650
|
+
directory, None, 'triage')
|
|
651
|
+
except Exception:
|
|
652
|
+
return _finish(directory, None, 'triage', spec, False, None, directory, 'error')
|
|
459
653
|
|
|
460
654
|
|
|
461
655
|
def cap(text, limit) -> str:
|
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/docs/api.md
CHANGED
|
@@ -305,11 +305,26 @@ its last 20,000 behind a leading `…`. Their `truncated` lists the field names
|
|
|
305
305
|
| `POST /api/runs/<key>/tasks/<id>/answer` | answer a task that waits for input (`forge control retry … --answer-file -`); authenticated, see Controls |
|
|
306
306
|
| `POST /api/worktrees/remove` | remove chosen worktrees (`forge worktrees rm`); authenticated, 900 s timeout |
|
|
307
307
|
| `POST /api/projects/<id>/memories/forget` | forget learnings in a project's checkouts (`forge memory forget`); authenticated |
|
|
308
|
+
| `POST /api/projects/<id>/memories/add` | add a learning in a project's checkouts (`forge memory add`); body `{path?, category, text, paths?}`; authenticated |
|
|
309
|
+
| `POST /api/projects/<id>/memories/edit` | replace a learning's text in a project's checkouts (`forge memory edit`); body `{path?, key, text}`; authenticated |
|
|
310
|
+
| `POST /api/projects/<id>/findings/fix` | mark findings fixed (`forge findings fix`); body `{fps, commit?, reason?}`; authenticated |
|
|
311
|
+
| `POST /api/projects/<id>/findings/dismiss` | dismiss findings (`forge findings dismiss`); body `{fps, reason}`; authenticated |
|
|
312
|
+
| `POST /api/projects/<id>/findings/reopen` | reopen findings (`forge findings reopen`); body `{fps}`; authenticated |
|
|
313
|
+
| `POST /api/projects/<id>/findings/to-file` | mark findings to-file and keep a draft (`forge findings to-file`); body `{fps, title?, body?}`; authenticated |
|
|
314
|
+
| `POST /api/projects/<id>/findings/dup` | mark one finding a duplicate (`forge findings dup`); body `{fps: [one], of}`; authenticated |
|
|
315
|
+
| `POST /api/projects/<id>/findings/tag` | add or remove tags (`forge findings tag`); body `{fps, tags, remove?}`; authenticated |
|
|
316
|
+
| `POST /api/projects/<id>/findings/note` | set or clear one finding's note (`forge findings note`); body `{fps: [one], text}`; authenticated |
|
|
317
|
+
| `POST /api/projects/<id>/findings/edit` | edit one finding's severity or text (`forge findings edit`); body `{fps: [one], severity?, text?}`; authenticated |
|
|
318
|
+
| `POST /api/projects/<id>/triage` | start a detached triage (`forge findings triage --spec S --detach`); body `{spec, max_findings?}`; authenticated |
|
|
319
|
+
| `GET /api/projects/<id>/triage[?n=N]` | `200 {state, proposals}` from `forge findings triage-status` and `proposals`, read each time |
|
|
320
|
+
| `POST /api/projects/<id>/triage/<n>/<pid>/apply` | approve one proposal (`forge findings apply --approve HASH`); body `{hash, plan_dir?}`; authenticated |
|
|
321
|
+
| `POST /api/projects/<id>/triage/<n>/<pid>/reject` | reject one proposal (`forge findings reject`); body `{reason?}`; authenticated |
|
|
322
|
+
| `GET /api/specs/check?spec=S` | `200 {ok: true, resolved}` or `{ok: false, error}` from `bash scripts/forge-dispatch.sh doctor --spec S --role side`; no model call; answered in read-only mode |
|
|
308
323
|
| `POST /api/storage/compact` | compact one run or all (`forge runs compact --logs`); authenticated, 900 s timeout |
|
|
309
324
|
| `GET /api/models/reviewers` | `200` the `forge dataset reviewers --json` report (how each reviewer's PASSed work held up); no parameters |
|
|
310
325
|
| `GET /api/projects` | `200 {projects: [ProjectRow]}`: one row per repository (see Projects) |
|
|
311
326
|
| `GET /api/projects/<id>` | `200 Project`, `404` for an unknown id |
|
|
312
|
-
| `GET /api/projects/<id>/findings[?refresh=1]` | `200 ProjectFindings`: every review's findings with
|
|
327
|
+
| `GET /api/projects/<id>/findings[?refresh=1]` | `200 ProjectFindings`: every review's findings with status, tags, record and draft |
|
|
313
328
|
| `GET /api/projects/<id>/memories[?refresh=1]` | `200 ProjectMemories`: what each checkout's memory gives models and every learning's state |
|
|
314
329
|
| `GET /api/worktrees[?refresh=1]` | `200 Worktrees`: every worktree forge created, with its status and the commands to remove it; cached 60 s (see Worktrees) |
|
|
315
330
|
| `GET /api/storage[?refresh=1]` | `200 Storage`: what forge takes on disk and the commands that take it back, measured in the background; cached 600 s (see Storage) |
|
|
@@ -1772,6 +1787,93 @@ false; when every checkout failed the first failure is the answer. A project wit
|
|
|
1772
1787
|
checkout is `409`. A server-wide lock (`409 busy`); timeout 60 s per checkout. A real forget drops
|
|
1773
1788
|
the project screen's memory answers. Refused under `--read-only` and without the token.
|
|
1774
1789
|
|
|
1790
|
+
### `POST /api/projects/<id>/memories/add` and `/memories/edit`
|
|
1791
|
+
|
|
1792
|
+
The project is `<id>` of `GET /api/projects` (`404` when unknown). Without `path` the call runs in every
|
|
1793
|
+
checkout of the project that exists; `path` must be one of them (`400` otherwise). A project with no
|
|
1794
|
+
existing checkout is `409`.
|
|
1795
|
+
|
|
1796
|
+
`add` body: `{"path": string, "category": "verify"|"trap"|"finding", "text": string, "paths": [string]}`.
|
|
1797
|
+
`text` is one line of 1 to 300 characters with no control character. `paths` is at most 20 relative
|
|
1798
|
+
paths (no `..`, no comma, no `[` or `]`, each at most 300 characters); omit it or pass `[]` for none.
|
|
1799
|
+
Runs `memory add <checkout> --category C --text T [--path P]… --actor ui --json` once per checkout.
|
|
1800
|
+
|
|
1801
|
+
`edit` body: `{"path": string, "key": "category:key", "text": string}`, the same text rule. Runs
|
|
1802
|
+
`memory edit <checkout> <key> --text T --actor ui --json` once per checkout. The route takes no
|
|
1803
|
+
`paths` field.
|
|
1804
|
+
|
|
1805
|
+
Both answer `200 {"ok", "checkouts": [{"path", "result"}]}`, `result` being that CLI's object. A
|
|
1806
|
+
checkout whose call failed has `result: null` plus `status` and `error`, and `ok` is false; when
|
|
1807
|
+
every checkout failed the first failure is the answer. A server-wide lock (`409 busy`); timeout 60 s
|
|
1808
|
+
per checkout. The project screen's memory answers are dropped after the calls. Refused under
|
|
1809
|
+
`--read-only` and without the token.
|
|
1810
|
+
|
|
1811
|
+
### `POST /api/projects/<id>/findings/<op>`
|
|
1812
|
+
|
|
1813
|
+
`<op>` is `fix`, `dismiss`, `reopen`, `to-file`, `dup`, `tag`, `note` or `edit`. The project is `<id>`
|
|
1814
|
+
of `GET /api/projects` (`404` when unknown, or when it has no root). Runs `findings <op> <root> … --actor
|
|
1815
|
+
ui --json`. `dup`, `note` and `edit` take exactly one fingerprint; the others take 1 to 200, and a
|
|
1816
|
+
repeated fingerprint is one finding. Every fingerprint is 12 lowercase hex characters. `200` with the
|
|
1817
|
+
CLI's object (`ok`, `op`, `changed`, `unchanged`). Exit 2 is `400`, exit 3 is `409` with the CLI's
|
|
1818
|
+
message. A server-wide findings lock (`409 {"error": "busy"}`); timeout 60 s. A successful call drops
|
|
1819
|
+
the project screen's findings listings and its run cache. Refused under `--read-only` and without the
|
|
1820
|
+
token. Unknown fields are `400`.
|
|
1821
|
+
|
|
1822
|
+
| `<op>` | Body | What the CLI receives |
|
|
1823
|
+
| --- | --- | --- |
|
|
1824
|
+
| `fix` | `{fps, commit?, reason?}`. At least one of `commit` (7 to 40 lowercase hex) and `reason` (at most 500 characters, no NUL) | `--commit`, `--reason` |
|
|
1825
|
+
| `dismiss` | `{fps, reason}` (`reason` required, same limit) | `--reason` |
|
|
1826
|
+
| `reopen` | `{fps}` | the fingerprints only |
|
|
1827
|
+
| `to-file` | `{fps, title?, body?}`. `title` at most 200 characters, no NUL. `body` at most 20000 characters, written to a private file | `--title`, `--body-file` |
|
|
1828
|
+
| `dup` | `{fps: [one], of}` (`of` is 12 lowercase hex) | `--of` |
|
|
1829
|
+
| `tag` | `{fps, tags, remove?}`. `tags` is 1 to 8 values matching `^[a-z][a-z0-9-]{0,23}$`. `remove` true selects `--remove`, otherwise `--add` | `-- TAG… --add` or `-- TAG… --remove` |
|
|
1830
|
+
| `note` | `{fps: [one], text}` (`text` at most 2000 characters, no NUL; empty clears the note) | the text as the positional argument |
|
|
1831
|
+
| `edit` | `{fps: [one], severity?, text?}`. At least one. `severity` is `P0`, `P1`, `P2` or `P3`. `text` at most 4000 characters, written to a private file | `--severity`, `--text-file` |
|
|
1832
|
+
|
|
1833
|
+
### `POST /api/projects/<id>/triage`, `GET /api/projects/<id>/triage`, apply and reject
|
|
1834
|
+
|
|
1835
|
+
The repository is the project's root when that directory exists, otherwise the first checkout that
|
|
1836
|
+
still exists. An unknown project is `404 {"error": "not found"}`; a project with no directory left
|
|
1837
|
+
on this machine is `404 {"error": "no checkout"}`.
|
|
1838
|
+
|
|
1839
|
+
`POST /api/projects/<id>/triage` body: `{"spec": string, "max_findings": int}`. `spec` is 1 to 120
|
|
1840
|
+
characters of letters, digits and `. _ : / @ + -`. `max_findings`, when present, is an integer from
|
|
1841
|
+
1 to 2000. Runs `findings triage <repo> --spec S [--max-findings N] --detach --actor ui --json` and
|
|
1842
|
+
answers `200` with the CLI's object (`triage`, `state`). `--detach` returns at once; this is the one
|
|
1843
|
+
route whose CLI starts a model. Exit 3 is `409` with the CLI's message. It does not take the findings
|
|
1844
|
+
lock. Timeout 60 s. Refused under `--read-only` and without the token.
|
|
1845
|
+
|
|
1846
|
+
`GET /api/projects/<id>/triage[?n=N]` runs `findings triage-status <repo> [N] --json` and `findings
|
|
1847
|
+
proposals <repo> [N] --json` on every request, with no cache. `N` is 1 to 9 digits. No triage yet
|
|
1848
|
+
(the status command exits 3 with that message) is `200 {"state": null, "proposals": null}`. A triage
|
|
1849
|
+
with no proposals yet leaves `proposals` null and still returns the state. Any other query parameter
|
|
1850
|
+
is `400`. Read-only servers answer this GET. Timeout 60 s per CLI call.
|
|
1851
|
+
|
|
1852
|
+
`POST …/triage/<n>/<pid>/apply` body: `{"hash": string, "plan_dir": string}`. `<n>` is 1 to 9 digits,
|
|
1853
|
+
`<pid>` matches `^p[0-9]{1,4}$`, and `hash` is 12 lowercase hex characters (the proposal's hash; a
|
|
1854
|
+
mismatch is the CLI's refusal). `plan_dir`, when present, is an absolute path. Runs `findings apply
|
|
1855
|
+
<repo> N PID --approve HASH [--plan-dir D] --actor ui --json`. `200` with the CLI's object. For a
|
|
1856
|
+
`plan` proposal that object carries `plan_dir` and `next` (`bash scripts/forge-parallel.sh plan DIR
|
|
1857
|
+
--repo CHECKOUT`); nothing is dispatched. An `issue` proposal only marks findings `to-file` with the
|
|
1858
|
+
draft.
|
|
1859
|
+
|
|
1860
|
+
`POST …/triage/<n>/<pid>/reject` body: `{"reason": string}`. `reason`, when present, is at most 500
|
|
1861
|
+
characters (newline and tab allowed; blank is omitted). Runs `findings reject <repo> N PID [--reason
|
|
1862
|
+
T] --actor ui --json`.
|
|
1863
|
+
|
|
1864
|
+
Apply and reject hold the server-wide findings lock (`409 {"error": "busy"}`). Exit 2 is `400`, exit
|
|
1865
|
+
3 is `409` with the CLI's message. A successful call drops the project screen's findings listings and
|
|
1866
|
+
its run cache. Timeout 60 s. Refused under `--read-only` and without the token.
|
|
1867
|
+
|
|
1868
|
+
### `GET /api/specs/check?spec=S`
|
|
1869
|
+
|
|
1870
|
+
Runs `bash scripts/forge-dispatch.sh doctor --spec S --role side` and answers `200 {"ok": true,
|
|
1871
|
+
"resolved": {key: value}}` from the doctor's `key=value` lines, or `200 {"ok": false, "error"}` when
|
|
1872
|
+
the doctor refuses. The check finished either way; no model is called. `spec` is required and uses
|
|
1873
|
+
the same 1-to-120-character check as triage start: a spec that fails it is `400` and the doctor is
|
|
1874
|
+
not run. A literal `+` in the query is a plus. Any other query parameter is `400`. Read-only servers
|
|
1875
|
+
answer this GET. Timeout 60 s.
|
|
1876
|
+
|
|
1775
1877
|
### `POST /api/storage/compact`
|
|
1776
1878
|
|
|
1777
1879
|
Body: `{"run": "<12-hex run key>"}` or `{"all": true}` (exactly one), and `"dry_run": bool (false)`.
|
|
@@ -1810,14 +1912,20 @@ cloud's (cloudmodel.js `hashId`: FNV-1a over the root's UTF-16 code units, 8 hex
|
|
|
1810
1912
|
|
|
1811
1913
|
```
|
|
1812
1914
|
ProjectRow = {id, name, root, exists, runs, live, last, path_only (runs tied by path only), checkouts,
|
|
1813
|
-
memory_lines (lines of <root>/.forge/memory.md, null when absent),
|
|
1915
|
+
memory_lines (lines of <root>/.forge/memory.md, null when absent),
|
|
1916
|
+
open_findings (rows the record and the review rules call open or to-file; this list does not
|
|
1917
|
+
ask GitHub, so a filed or swept finding can still be counted)}
|
|
1814
1918
|
Project = {id, name, root, exists, live, last, path_only, memory_off_runs,
|
|
1815
1919
|
checkouts: [{path, exists, branch, runs, root}], runs: [RunSummary + identity_source, dataset_uid, no_memory]}
|
|
1816
|
-
ProjectFindings = {id, rows: [Finding], notes: [text], runs, dataset_runs, computed, available
|
|
1920
|
+
ProjectFindings = {id, rows: [Finding], notes: [text], runs, dataset_runs, computed, available,
|
|
1921
|
+
issues_online (true when that listing was the online one), issues_read_at (unix time the listing was read, or null)}
|
|
1817
1922
|
Finding = {source: run|dataset, run (key or null), run_id, task, final_review (its dir name, 'final' from the
|
|
1818
1923
|
dataset), attempt, kind: primary|shadow|final, reviewer, verdict, at, id, severity, confidence, location,
|
|
1819
|
-
summary, text, fp (forge issues' key, null when it cannot parse the line),
|
|
1820
|
-
|
|
1924
|
+
summary, text, fp (forge issues' key, null when it cannot parse the line), record_fp (the finding
|
|
1925
|
+
record's 12-hex key, or null when the row cannot be keyed), record (that record entry, or null),
|
|
1926
|
+
tags (the entry's tags, or the default for the path when none are stored), draft (the to-file
|
|
1927
|
+
draft, or null), count, occurrences: [{run, run_id, task, attempt, kind, reviewer, at, href}],
|
|
1928
|
+
status, fileable, origin, href (the diff at the finding)}
|
|
1821
1929
|
ProjectMemories = {id, sources: [{path, root, branch, ok, ledger, memory, rebuilt_differs, max_lines}], differs,
|
|
1822
1930
|
learnings: [{category, key, text, count, states: {source path: state}, rows, last, dataset_only}],
|
|
1823
1931
|
notes, memory_off_runs, runs, computed}
|
|
@@ -1825,13 +1933,23 @@ ProjectMemories = {id, sources: [{path, root, branch, ok, ledger, memory, rebuil
|
|
|
1825
1933
|
|
|
1826
1934
|
Findings come from every review of every run dir (parsed by forge-contract.py through `findings.py`), and
|
|
1827
1935
|
from `dataset history --json` for runs whose dir is gone (their base commit ties a run whose checkout is
|
|
1828
|
-
gone to the project, as `repos.py` does).
|
|
1829
|
-
|
|
1830
|
-
`
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1936
|
+
gone to the project, as `repos.py` does). Repeats within a task collapse by `forge issues`' own key; a
|
|
1937
|
+
line it cannot parse is its own row. `status` is `forge_findings.status.effective`: the record when it is
|
|
1938
|
+
`duplicate`, `dismissed`, `fixed`, `filed` or `to-file`; otherwise the `forge issues` entry (filed and
|
|
1939
|
+
`CLOSED` is `fixed`, any other filed issue is `filed`, and, unless the record reopened it, swept is
|
|
1940
|
+
`swept` and an old dismissal is `dismissed`); otherwise the review row (`shadow`, `unlabelled` when the
|
|
1941
|
+
confidence is `UNSTATED`, `superseded` when a later review of the same task or a later final review
|
|
1942
|
+
passed); otherwise `open`. Only `open` and `to-file` count as open. `tags` are the record's tags when it
|
|
1943
|
+
has any, otherwise the default for the file (`tests`, `docs`, `infra`, `ui` or `backend`; no path gives
|
|
1944
|
+
none). `draft` is the record entry's draft, or null. The issues listing is `issues <path> --json
|
|
1945
|
+
--all-runs --include-plausible --include-dismissed`, asked of the repository root first and then of up
|
|
1946
|
+
to three of its run dirs: online (no `--offline`, so GitHub can say an issue is closed), and with
|
|
1947
|
+
`--offline` when that fails or takes over 60 s. `notes` says
|
|
1948
|
+
when the dataset, `forge issues` or the finding record could not be read, and when issue states were not
|
|
1949
|
+
read from GitHub (a filed finding may then show as open). Memories run `memory learnings <checkout>
|
|
1950
|
+
--json` for the root and each checkout a run started in that still exists. A run's findings are cached
|
|
1951
|
+
by its `updated` time, the CLI's answers for 300 s; `refresh=1` reads everything again; any other
|
|
1952
|
+
parameter is a `400`.
|
|
1835
1953
|
|
|
1836
1954
|
### `GET /api/worktrees`
|
|
1837
1955
|
|