@giamme/forge 0.13.1 → 0.14.1
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 +38 -0
- package/SKILL.md +17 -11
- package/VERSION +1 -1
- package/docs/artifacts.md +2 -0
- package/docs/commands.md +134 -8
- package/docs/development.md +3 -0
- package/docs/reviews.md +2 -0
- package/docs/troubleshooting.md +5 -1
- package/forge +28 -1
- package/package.json +1 -1
- package/references/dataset.md +3 -1
- package/references/decompose.md +201 -61
- package/references/harnesses.md +4 -1
- package/references/runtime.md +29 -0
- package/references/ui.md +10 -0
- package/scripts/forge-compare.py +491 -0
- package/scripts/forge-config.py +3 -3
- package/scripts/forge-contract.py +34 -8
- package/scripts/forge-control.py +105 -13
- package/scripts/forge-dispatch.sh +85 -25
- package/scripts/forge-jev-options.sh +17 -4
- package/scripts/forge-ledger.py +387 -0
- package/scripts/forge-lib-plans.sh +11 -2
- package/scripts/forge-lib-task.sh +390 -28
- package/scripts/forge-parallel-options.sh +20 -4
- package/scripts/forge-parallel.sh +123 -17
- package/scripts/forge-plan-check.py +68 -3
- package/scripts/forge-pr.py +276 -0
- package/scripts/forge-route.py +403 -38
- package/scripts/forge-runs.py +18 -1
- package/scripts/forge-runtime.py +94 -8
- package/scripts/forge-schedule.py +303 -46
- package/scripts/forge-verify-failed.py +111 -0
- package/scripts/forge-watch.py +372 -0
- package/scripts/forge_dataset/harvest.py +3 -1
- package/scripts/forge_fractal/cli.py +23 -6
- package/scripts/forge_infra.py +274 -0
- package/scripts/forge_jev/client.py +13 -9
- package/ui/docs/api.md +51 -8
- package/ui/forge_ui/export.py +6 -2
- package/ui/forge_ui/reader.py +172 -6
- package/ui/forge_ui/static/app.js +2 -2
- package/ui/forge_ui/static/checksview.js +20 -7
- package/ui/forge_ui/static/controls.js +6 -3
- package/ui/forge_ui/static/panel.js +69 -4
- package/ui/forge_ui/static/runmodel.js +30 -4
- package/ui/forge_ui/static/scene3d.js +3 -2
- package/ui/forge_ui/static/style.css +11 -4
package/scripts/forge-runs.py
CHANGED
|
@@ -11,6 +11,10 @@ forge-ui and never writes anything.
|
|
|
11
11
|
`forge runs rm <run-dir> [--dry-run] [--yes] [--no-archive] [--worktrees] [--branches] [--json]`
|
|
12
12
|
is the one thing here that changes anything: it deletes a run, after its traces are in the dataset
|
|
13
13
|
and an archive exists (scripts/forge-runs-rm.py).
|
|
14
|
+
|
|
15
|
+
`forge runs rerun <run-dir> --dwarf SPEC` and `forge runs compare <run-dir-A> <run-dir-B>` (scripts/forge-compare.py)
|
|
16
|
+
run a plan again under another implementer, from the same starting commit and never merging, and set two runs
|
|
17
|
+
side by side per task. Starting the rerun spends tokens, so it takes `--run --yes` after it has shown the forecast.
|
|
14
18
|
"""
|
|
15
19
|
from __future__ import annotations
|
|
16
20
|
|
|
@@ -100,12 +104,25 @@ def remove(argv) -> int:
|
|
|
100
104
|
return module.main(argv)
|
|
101
105
|
|
|
102
106
|
|
|
107
|
+
def compare_runs(argv) -> int:
|
|
108
|
+
"""`forge runs rerun` and `forge runs compare`: loaded on demand, like rm."""
|
|
109
|
+
import importlib.util
|
|
110
|
+
spec = importlib.util.spec_from_file_location('forge_compare', Path(__file__).resolve().with_name('forge-compare.py'))
|
|
111
|
+
module = importlib.util.module_from_spec(spec)
|
|
112
|
+
sys.modules['forge_compare'] = module
|
|
113
|
+
spec.loader.exec_module(module)
|
|
114
|
+
return module.main(argv)
|
|
115
|
+
|
|
116
|
+
|
|
103
117
|
def main(argv=None) -> int:
|
|
104
118
|
argv = sys.argv[1:] if argv is None else list(argv)
|
|
105
119
|
if argv[:1] == ['rm']:
|
|
106
120
|
return remove(argv[1:])
|
|
121
|
+
if argv[:1] in (['rerun'], ['compare']):
|
|
122
|
+
return compare_runs(argv)
|
|
107
123
|
parser = argparse.ArgumentParser(prog='forge runs', description="This repo's recent forge runs, newest first. Listing is read-only.",
|
|
108
|
-
epilog='Delete a run, keeping its traces: forge runs rm <run-dir> (forge runs rm --help)'
|
|
124
|
+
epilog='Delete a run, keeping its traces: forge runs rm <run-dir> (forge runs rm --help). Rerun a plan with another '
|
|
125
|
+
'implementer and compare: forge runs rerun --help, forge runs compare --help')
|
|
109
126
|
which = parser.add_mutually_exclusive_group()
|
|
110
127
|
which.add_argument('--repo', type=Path, metavar='DIR', help='the repo whose runs to list (default: the Git top level of the current directory)')
|
|
111
128
|
which.add_argument('--all', action='store_true', help='list the runs of every repo')
|
package/scripts/forge-runtime.py
CHANGED
|
@@ -306,7 +306,7 @@ def _finish(attempt: Path, root: Path, role: str, harness: str, rc: str) -> None
|
|
|
306
306
|
session_path.unlink(missing_ok=True)
|
|
307
307
|
if found is not None:
|
|
308
308
|
session_path.write_text(found + '\n')
|
|
309
|
-
for suffix in ('prompt', 'last', 'log', 'clock', 'resolved', 'cmd', 'timedout', 'infra', 'orphans',
|
|
309
|
+
for suffix in ('prompt', 'last', 'log', 'clock', 'resolved', 'cmd', 'timedout', 'settled', 'infra', 'orphans',
|
|
310
310
|
'session', 'continue'):
|
|
311
311
|
if suffix == 'prompt' and not prompt_ready:
|
|
312
312
|
continue
|
|
@@ -348,7 +348,10 @@ INFRA_PATTERNS = (
|
|
|
348
348
|
_P(r"\b(?:no|missing) api[ _-]?key\b|\bcould not resolve authentication method\b", re.I),
|
|
349
349
|
_P(_HTTP_CODE % '40[13]' + r"|\b40[13]\b\W{0,3}(?:unauthori[sz]ed|forbidden)\b", re.I),
|
|
350
350
|
)),
|
|
351
|
-
(
|
|
351
|
+
# Order is priority: the first class with a matching phrase wins (auth > usage_limit > budget >
|
|
352
|
+
# capacity > rate_limit > provider_down > network). A usage limit that also mentions credits
|
|
353
|
+
# is a usage limit: the window resets, the money does not run out.
|
|
354
|
+
('usage_limit', (
|
|
352
355
|
_P(r"\busage[ _-]?limit\b", re.I),
|
|
353
356
|
# "You've hit your limit", "hit your session limit", "reached the weekly limit"; but not
|
|
354
357
|
# "reached the context limit", which is the model's problem rather than the account's.
|
|
@@ -356,31 +359,44 @@ INFRA_PATTERNS = (
|
|
|
356
359
|
r"5-hour|five-hour|spend\w*|credit|token|message|request|plan|org\w*) )?limits?\b", re.I),
|
|
357
360
|
_P(r"(?<!context )(?<!rate )(?<!rate-)(?<!rate_)\blimit (?:reached|exceeded)\b", re.I),
|
|
358
361
|
_P(r"\b(?:session|weekly|daily|monthly|5-hour|five-hour) limit\b", re.I),
|
|
362
|
+
)),
|
|
363
|
+
# Money that is gone. A bare "billing" is not a phrase: it would match "billing.ts" in a stack trace.
|
|
364
|
+
('budget', (
|
|
359
365
|
_P(r"\bquota (?:exceeded|exhausted|reached)\b|\bexceeded (?:your |the )?(?:current )?quota\b|\binsufficient[ _-]quota\b|\bout of (?:credits|quota)\b", re.I),
|
|
360
366
|
_P(r"\binsufficient (?:balance|credits?|funds)\b", re.I),
|
|
361
367
|
_P(r"\bcredit balance (?:is )?too low\b", re.I),
|
|
362
368
|
_P(r"\bpayment required\b|\bbilling (?:hard )?limit\b|\bbilling (?:issue|error|details|not active)\b|\bcheck your (?:plan and )?billing\b", re.I),
|
|
369
|
+
_P(_HTTP_CODE % '402', re.I),
|
|
363
370
|
)),
|
|
371
|
+
# A model at capacity for everyone who asks it.
|
|
372
|
+
('capacity', (
|
|
373
|
+
_P(r"\boverloaded\b", re.I),
|
|
374
|
+
_P(r"\bat capacity\b", re.I),
|
|
375
|
+
_P(_HTTP_CODE % '529', re.I),
|
|
376
|
+
)),
|
|
377
|
+
# An account sending too fast.
|
|
364
378
|
('rate_limit', (
|
|
365
379
|
_P(r"\brate[ _-]?limit(?:s|ed|ing)?\b", re.I),
|
|
366
380
|
_P(r"\btoo many requests\b", re.I),
|
|
367
|
-
_P(r"\boverloaded\b", re.I),
|
|
368
|
-
_P(r"\bat capacity\b", re.I),
|
|
369
381
|
_P(_HTTP_CODE % '429' + r"|\b429\b\W{0,3}too many\b", re.I),
|
|
370
382
|
)),
|
|
383
|
+
# One provider failing, while the connection itself works.
|
|
384
|
+
('provider_down', (
|
|
385
|
+
_P(r"\bbad gateway\b|\bservice unavailable\b|\bgateway time-?out\b", re.I),
|
|
386
|
+
_P(_HTTP_CODE % '50[234]', re.I),
|
|
387
|
+
)),
|
|
371
388
|
('network', (
|
|
372
389
|
_P(r"\b(?:ECONNRESET|ETIMEDOUT|ENOTFOUND|ECONNREFUSED|EAI_AGAIN|EHOSTUNREACH|ENETUNREACH|ENETDOWN)\b"),
|
|
373
390
|
_P(r"\bgetaddrinfo\b", re.I),
|
|
374
391
|
_P(r"\bconnection (?:refused|reset|timed out)\b|\bnetwork is unreachable\b|\bsocket hang up\b", re.I),
|
|
375
392
|
_P(r"\bcan['’]?t reach the api server\b|\bunable to connect\b|\bfailed to connect\b|\bfetch failed\b", re.I),
|
|
376
393
|
_P(r"\btemporary failure in name resolution\b|\bname or service not known\b", re.I),
|
|
377
|
-
_P(r"\bbad gateway\b|\bservice unavailable\b|\bgateway time-?out\b", re.I),
|
|
378
394
|
_P(r"\binvalid peer certificate\b", re.I),
|
|
379
395
|
)),
|
|
380
396
|
)
|
|
381
397
|
# api_error_status as claude reports it, used only when the text itself matched nothing.
|
|
382
|
-
STATUS_CLASS = {401: 'auth', 403: 'auth', 402: '
|
|
383
|
-
502: '
|
|
398
|
+
STATUS_CLASS = {401: 'auth', 403: 'auth', 402: 'budget', 429: 'rate_limit', 529: 'capacity',
|
|
399
|
+
502: 'provider_down', 503: 'provider_down', 504: 'provider_down'}
|
|
384
400
|
|
|
385
401
|
_MONTHS = {m: i + 1 for i, m in enumerate(
|
|
386
402
|
('jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'))}
|
|
@@ -470,7 +486,7 @@ def _one_line(text: str, limit: int = DETAIL_MAX) -> str:
|
|
|
470
486
|
|
|
471
487
|
|
|
472
488
|
def classify_text(text: str, status: object = None, now: float | None = None):
|
|
473
|
-
"""(class, retry_after_or_None, detail) for failure text, or None.
|
|
489
|
+
"""(class, retry_after_or_None, detail) for failure text, or None. The order is INFRA_PATTERNS'."""
|
|
474
490
|
for name, patterns in INFRA_PATTERNS:
|
|
475
491
|
for pattern in patterns:
|
|
476
492
|
match = pattern.search(text)
|
|
@@ -639,6 +655,72 @@ def classify(log: str, harness: str, rc: object, last: str = '', role: str = '',
|
|
|
639
655
|
return None
|
|
640
656
|
|
|
641
657
|
|
|
658
|
+
# --- a final result the CLI stays open after (#110) ----------------------------------
|
|
659
|
+
# claude -p (and openclaude) stays up while a background task its session started is still open,
|
|
660
|
+
# even after the model's final result: one dwarf sat 47 minutes on a finished answer until the
|
|
661
|
+
# watchdog killed it as TIMEOUT. A result is not always the end, though: a background task that
|
|
662
|
+
# completes wakes the session for another turn, sometimes after a long wait (an hour and more on a
|
|
663
|
+
# slow suite). A new turn always opens with system/init, and until one does the only events after
|
|
664
|
+
# a result are the background tasks' own.
|
|
665
|
+
BACKGROUND_EVENTS = ('task_updated', 'task_notification', 'background_tasks_changed', 'hook_started', 'hook_response')
|
|
666
|
+
SETTLE_POLL_S = 5.0
|
|
667
|
+
|
|
668
|
+
|
|
669
|
+
def settled_result(text: str) -> dict | None:
|
|
670
|
+
"""The last `result` event when only background-task events follow it: the model ended its turn and
|
|
671
|
+
began no other. None when the log has no result, or a turn is under way after it."""
|
|
672
|
+
found = None
|
|
673
|
+
for event in _events(text)[0]:
|
|
674
|
+
if event.get('type') == 'result':
|
|
675
|
+
found = event
|
|
676
|
+
elif not (event.get('type') == 'system' and event.get('subtype') in BACKGROUND_EVENTS):
|
|
677
|
+
found = None
|
|
678
|
+
return found
|
|
679
|
+
|
|
680
|
+
|
|
681
|
+
def settle(log: str, grace: str, pid: str) -> None:
|
|
682
|
+
"""Returns once the harness log ends in a settled result (settled_result) and has not grown for `grace`
|
|
683
|
+
seconds of the machine's awake time; exits 1 once process `pid`, the harness, is gone. dispatch then ends
|
|
684
|
+
the harness: its answer is in, and only a background task keeps it open. An idle log whose last turn is
|
|
685
|
+
still under way (a long command) is never ended here; that is the watchdog's."""
|
|
686
|
+
grace_s, target = float(grace), int(pid)
|
|
687
|
+
poll = min(SETTLE_POLL_S, max(grace_s / 4, 0.05))
|
|
688
|
+
size, since, judged = None, time.monotonic(), None
|
|
689
|
+
while True:
|
|
690
|
+
try:
|
|
691
|
+
os.kill(target, 0)
|
|
692
|
+
except ProcessLookupError:
|
|
693
|
+
sys.exit(1)
|
|
694
|
+
except PermissionError:
|
|
695
|
+
pass
|
|
696
|
+
try:
|
|
697
|
+
now = os.stat(log).st_size
|
|
698
|
+
except OSError:
|
|
699
|
+
now = None
|
|
700
|
+
if now != size:
|
|
701
|
+
size, since = now, time.monotonic()
|
|
702
|
+
elif judged != size and time.monotonic() - since >= grace_s:
|
|
703
|
+
judged = size # read once per size: an idle log mid-turn is not read again and again
|
|
704
|
+
try:
|
|
705
|
+
text = Path(log).read_text(errors='replace')
|
|
706
|
+
except OSError:
|
|
707
|
+
text = ''
|
|
708
|
+
if settled_result(text) is not None:
|
|
709
|
+
return
|
|
710
|
+
time.sleep(poll)
|
|
711
|
+
|
|
712
|
+
|
|
713
|
+
def settled_command(log: str) -> None:
|
|
714
|
+
"""Prints `ok`, or `error` for an is_error result, when LOG ends in a settled result; exits 1 otherwise."""
|
|
715
|
+
try:
|
|
716
|
+
event = settled_result(Path(log).read_text(errors='replace'))
|
|
717
|
+
except OSError:
|
|
718
|
+
event = None
|
|
719
|
+
if event is None:
|
|
720
|
+
sys.exit(1)
|
|
721
|
+
print('error' if event.get('is_error') is True else 'ok')
|
|
722
|
+
|
|
723
|
+
|
|
642
724
|
def classify_command(log: str, harness: str, rc: str, last: str = '', role: str = '') -> None:
|
|
643
725
|
try:
|
|
644
726
|
hit = classify(log, harness, rc, last, role)
|
|
@@ -675,6 +757,10 @@ def main() -> None:
|
|
|
675
757
|
classify_command(*args)
|
|
676
758
|
elif command == 'clock':
|
|
677
759
|
clock(*args)
|
|
760
|
+
elif command == 'settle':
|
|
761
|
+
settle(*args)
|
|
762
|
+
elif command == 'settled':
|
|
763
|
+
settled_command(*args)
|
|
678
764
|
else:
|
|
679
765
|
raise ValueError('unknown runtime command: ' + command)
|
|
680
766
|
except (OSError, ValueError, RuntimeError) as error:
|