@giamme/forge 0.21.0 → 0.23.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 +81 -0
- package/README.md +25 -15
- package/SKILL.md +137 -216
- package/VERSION +1 -1
- package/bin/forge.js +104 -0
- package/docs/README.md +2 -3
- package/docs/add-ons.md +5 -3
- package/docs/artifacts.md +17 -2
- package/docs/commands.md +85 -63
- package/docs/decomposed-runs.md +195 -21
- package/docs/development.md +12 -10
- package/docs/forge-ui.md +33 -4
- package/docs/install.md +127 -6
- package/docs/memory.md +6 -1
- package/docs/models.md +36 -10
- package/docs/reviews.md +50 -29
- package/docs/safety.md +27 -2
- package/docs/troubleshooting.md +8 -11
- package/forge +29 -4
- package/forge.cmd +56 -0
- package/package.json +6 -3
- package/references/dataset.md +10 -9
- package/references/decompose-integration.md +337 -0
- package/references/decompose-opt-in.md +527 -0
- package/references/decompose-recovery.md +569 -0
- package/references/decompose-review.md +256 -0
- package/references/decompose.md +99 -1606
- package/references/findings.md +68 -0
- package/references/harnesses.md +7 -12
- package/references/memory.md +13 -2
- package/references/planning.md +48 -18
- package/references/ripwire.md +38 -13
- package/references/runtime.md +22 -33
- package/references/setup.md +90 -0
- package/references/solo.md +13 -42
- package/references/ui.md +12 -5
- package/registry.tsv +40 -22
- package/scripts/forge-artifact.sh +148 -13
- package/scripts/forge-compare.py +5 -15
- package/scripts/forge-config.py +14 -1
- package/scripts/forge-contract.py +216 -53
- package/scripts/forge-control.py +781 -51
- package/scripts/forge-dispatch.sh +202 -42
- package/scripts/forge-du.py +13 -3
- package/scripts/forge-guard.py +137 -6
- package/scripts/forge-handoff.py +221 -39
- package/scripts/forge-install-ripwire.sh +100 -24
- package/scripts/forge-install.sh +100 -41
- package/scripts/forge-issues.py +6 -4
- package/scripts/forge-jev-options.sh +3 -5
- package/scripts/forge-lib-adopt.sh +169 -5
- package/scripts/forge-lib-attribute.sh +10 -3
- package/scripts/forge-lib-decompose.sh +454 -0
- package/scripts/forge-lib-env.sh +179 -0
- package/scripts/forge-lib-group.sh +9 -6
- package/scripts/forge-lib-plans.sh +38 -21
- package/scripts/forge-lib-review.sh +28 -8
- package/scripts/forge-lib-task.sh +263 -69
- package/scripts/forge-lib-verify.sh +59 -10
- package/scripts/forge-memory.sh +83 -4
- package/scripts/forge-metrics.sh +10 -3
- package/scripts/forge-parallel-options.sh +23 -4
- package/scripts/forge-parallel.sh +602 -217
- package/scripts/forge-plan-check.py +71 -8
- package/scripts/forge-planner.py +303 -17
- package/scripts/forge-pr.py +9 -1
- package/scripts/forge-prompt.py +2 -2
- package/scripts/forge-review-links.py +248 -0
- package/scripts/forge-ripwire.py +234 -16
- package/scripts/forge-route.py +19 -27
- package/scripts/forge-runs-rm.py +92 -21
- package/scripts/forge-runs.py +46 -5
- package/scripts/forge-runtime.py +39 -14
- package/scripts/forge-schedule.py +141 -33
- package/scripts/forge-setup-stale.py +236 -0
- package/scripts/forge-setup.py +804 -0
- package/scripts/forge-shadow.py +2 -20
- package/scripts/forge-solo-lock.py +46 -0
- package/scripts/forge-solo.sh +39 -58
- package/scripts/forge-sweep.py +3 -2
- package/scripts/forge-ui.py +8 -1
- package/scripts/forge-update.sh +8 -3
- package/scripts/forge-verify.py +17 -1
- package/scripts/forge-version.py +13 -1
- package/scripts/forge-watch.py +7 -2
- package/scripts/forge-win.sh +156 -0
- package/scripts/forge_brief/__init__.py +6 -1
- package/scripts/forge_brief/proposals.py +6 -1
- package/scripts/forge_dataset/__init__.py +1 -1
- package/scripts/forge_dataset/capture.py +0 -34
- package/scripts/forge_dataset/checks.py +0 -1
- package/scripts/forge_dataset/cli.py +5 -1
- package/scripts/forge_dataset/export.py +28 -6
- package/scripts/forge_dataset/facts.py +1 -2
- package/scripts/forge_dataset/forecast.py +1 -1
- package/scripts/forge_dataset/harvest.py +107 -7
- package/scripts/forge_dataset/importer.py +3 -2
- package/scripts/forge_dataset/pairs.py +3 -3
- package/scripts/forge_dataset/reviewers.py +4 -3
- package/scripts/forge_dataset/routing.py +6 -3
- package/scripts/forge_dataset/tiers.py +1 -1
- package/scripts/forge_decide/__init__.py +1 -1
- package/scripts/forge_decide/budget.py +12 -7
- package/scripts/forge_decide/profiles.py +11 -14
- package/scripts/forge_decide/replay.py +9 -4
- package/scripts/forge_decompose.py +987 -0
- package/scripts/forge_flock.py +17 -2
- package/scripts/forge_groups/review.py +6 -1
- package/scripts/forge_jev/__init__.py +1 -1
- package/scripts/forge_jev/cli.py +10 -1
- package/scripts/forge_jev/gates.py +10 -1
- package/scripts/forge_jev/verify.py +10 -2
- package/scripts/forge_legacy.py +86 -0
- package/scripts/forge_memory_home.py +57 -0
- package/scripts/forge_models.py +151 -0
- package/scripts/forge_posix.py +17 -0
- package/scripts/forge_prefs.py +138 -0
- package/scripts/forge_proc.py +108 -0
- package/scripts/forge_registry.py +2 -2
- package/scripts/forge_side/__init__.py +23 -4
- package/scripts/forge_storage.py +28 -15
- package/ui/README.md +22 -10
- package/ui/docs/api.md +121 -99
- package/ui/forge_ui/control.py +53 -16
- package/ui/forge_ui/export.py +0 -10
- package/ui/forge_ui/models.py +15 -2
- package/ui/forge_ui/projects.py +4 -1
- package/ui/forge_ui/reader.py +462 -60
- package/ui/forge_ui/server.py +0 -10
- package/ui/forge_ui/static/app.js +28 -9
- package/ui/forge_ui/static/checksview.js +12 -3
- package/ui/forge_ui/static/controls.js +147 -11
- package/ui/forge_ui/static/convo.js +5 -2
- package/ui/forge_ui/static/diffview.js +4 -5
- package/ui/forge_ui/static/panel.js +180 -77
- package/ui/forge_ui/static/projectsview.js +16 -2
- package/ui/forge_ui/static/runmodel.js +18 -4
- package/ui/forge_ui/static/scene3d.js +52 -31
- package/ui/forge_ui/static/settings.js +1 -1
- package/ui/forge_ui/static/storageview.js +2 -2
- package/ui/forge_ui/static/style.css +23 -6
- package/ui/forge_ui/static/worktreesview.js +8 -4
- package/ui/forge_ui/transcripts.py +6 -0
- package/ui/forge_ui/worktrees.py +13 -1
- package/docs/fractal.md +0 -181
- package/references/fractal-dashboard.md +0 -21
- package/references/fractal.md +0 -307
- package/scripts/forge-fractal-dispatch.sh +0 -4
- package/scripts/forge-fractal-options.sh +0 -54
- package/scripts/forge-fractal.py +0 -6
- package/scripts/forge-install-fractal.sh +0 -4
- package/scripts/forge_fractal/__init__.py +0 -88
- package/scripts/forge_fractal/bridge.py +0 -46
- package/scripts/forge_fractal/cli.py +0 -224
- package/scripts/forge_fractal/dashboard.css +0 -138
- package/scripts/forge_fractal/dashboard.html +0 -41
- package/scripts/forge_fractal/dashboard.js +0 -687
- package/scripts/forge_fractal/decomposition.py +0 -262
- package/scripts/forge_fractal/execution.py +0 -659
- package/scripts/forge_fractal/inspection.py +0 -261
- package/scripts/forge_fractal/install.py +0 -158
- package/scripts/forge_fractal/invocation.py +0 -95
- package/scripts/forge_fractal/pipeline.py +0 -125
- package/scripts/forge_fractal/selection.py +0 -180
- package/ui/forge_ui/fractal.py +0 -582
package/scripts/forge-runs-rm.py
CHANGED
|
@@ -261,10 +261,58 @@ class Run:
|
|
|
261
261
|
self.removable = set() # paths of the worktrees --worktrees removes (or prunes, when missing on disk)
|
|
262
262
|
self.wt_root = None
|
|
263
263
|
self.owners = {} # worktree path -> forge_worktrees kind (None: foreign), for the dataset events
|
|
264
|
+
# The run and, after it, every sub-plan under it (#153: the subtasks of a split task run as a plan of
|
|
265
|
+
# their own, with its own run id, branches and worktree folder): dict(run_id, tasks, wt_root, path).
|
|
266
|
+
self.members = []
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
SUB_DEPTH = 8 # the depth limit of a run's decomposition tops out at 6
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
def plan_tasks(path, ignored=None):
|
|
273
|
+
"""The task ids of a plan dir's tasks.tsv that are safe as file names and ref components."""
|
|
274
|
+
tasks, seen = [], set()
|
|
275
|
+
for line in (read_text(os.path.join(path, 'tasks.tsv')) or '').splitlines():
|
|
276
|
+
if not line.strip() or line.startswith('#'):
|
|
277
|
+
continue
|
|
278
|
+
task = line.split('\t', 1)[0]
|
|
279
|
+
if not TASK_ID.fullmatch(task):
|
|
280
|
+
if ignored is not None:
|
|
281
|
+
ignored.append(task)
|
|
282
|
+
elif task not in seen:
|
|
283
|
+
seen.add(task)
|
|
284
|
+
tasks.append(task)
|
|
285
|
+
return tasks
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
def sub_members(run, path, tasks, depth=0):
|
|
289
|
+
"""The sub-plans under a plan dir, as members. One whose run id is not safe, or whose worktree folder
|
|
290
|
+
would overlap the run dir, is left out: nothing of it is touched."""
|
|
291
|
+
found = []
|
|
292
|
+
if depth >= SUB_DEPTH:
|
|
293
|
+
return found
|
|
294
|
+
for task in tasks:
|
|
295
|
+
sub = os.path.join(path, 'tasks', task, 'sub')
|
|
296
|
+
if os.path.islink(sub) or not os.path.isfile(os.path.join(sub, 'tasks.tsv')):
|
|
297
|
+
continue
|
|
298
|
+
run_id = first_line(os.path.join(sub, 'run_id')) or ''
|
|
299
|
+
if not RUN_ID.fullmatch(run_id) or not run_id.startswith(run.run_id + '--'):
|
|
300
|
+
continue
|
|
301
|
+
root = forge_worktrees.wt_root(run.repo, run_id)
|
|
302
|
+
if contains(run.path, root) or contains(root, run.path):
|
|
303
|
+
continue
|
|
304
|
+
below = plan_tasks(sub)
|
|
305
|
+
found.append(dict(run_id=run_id, tasks=below, wt_root=root, path=sub))
|
|
306
|
+
found += sub_members(run, sub, below, depth + 1)
|
|
307
|
+
return found
|
|
264
308
|
|
|
265
309
|
|
|
266
310
|
def identify(target):
|
|
267
311
|
path = target.path
|
|
312
|
+
if os.path.basename(path) == 'sub' and os.path.basename(os.path.dirname(os.path.dirname(path))) == 'tasks' \
|
|
313
|
+
and os.path.isfile(os.path.join(path, 'parent.json')):
|
|
314
|
+
raise Refused('%s holds the subtasks of a split task: it is deleted with the run it belongs to, not by itself'
|
|
315
|
+
% path)
|
|
268
316
|
if path == '/' or any(contains(path, home) for home in homes()):
|
|
269
317
|
raise Refused('refusing to delete %s: it is, or contains, the home directory' % path)
|
|
270
318
|
if os.path.lexists(os.path.join(path, '.git')):
|
|
@@ -286,20 +334,14 @@ def identify(target):
|
|
|
286
334
|
if contains(path, run.repo_real) or contains(path, os.path.abspath(run.repo)):
|
|
287
335
|
raise Refused('refusing to delete %s: it is, or contains, the run\'s repo %s' % (path, run.repo))
|
|
288
336
|
if run.kind == 'plan':
|
|
289
|
-
|
|
290
|
-
for line in (read_text(os.path.join(path, 'tasks.tsv')) or '').splitlines():
|
|
291
|
-
if not line.strip() or line.startswith('#'):
|
|
292
|
-
continue
|
|
293
|
-
task = line.split('\t', 1)[0]
|
|
294
|
-
if not TASK_ID.fullmatch(task):
|
|
295
|
-
run.ignored_tasks.append(task)
|
|
296
|
-
elif task not in seen:
|
|
297
|
-
seen.add(task)
|
|
298
|
-
run.tasks.append(task)
|
|
337
|
+
run.tasks = plan_tasks(path, run.ignored_tasks)
|
|
299
338
|
# forge-parallel.sh: wt_root="$(cd "$REPO/.." && pwd)/.forge-worktrees/$run_id", a logical cd
|
|
300
339
|
run.wt_root = forge_worktrees.wt_root(run.repo, run.run_id)
|
|
301
340
|
if contains(path, run.wt_root) or contains(run.wt_root, path):
|
|
302
341
|
raise Refused('refusing to delete %s: it overlaps the run\'s worktree root %s' % (path, run.wt_root))
|
|
342
|
+
run.members = [dict(run_id=run.run_id, tasks=run.tasks, wt_root=run.wt_root, path=path)]
|
|
343
|
+
if run.kind == 'plan':
|
|
344
|
+
run.members += sub_members(run, path, run.tasks)
|
|
303
345
|
return run
|
|
304
346
|
|
|
305
347
|
|
|
@@ -444,17 +486,24 @@ def inspect_git(run):
|
|
|
444
486
|
except Failed as error:
|
|
445
487
|
run.git_error = str(error)
|
|
446
488
|
return
|
|
447
|
-
|
|
448
|
-
branch_refs
|
|
489
|
+
# The run's own branches and those of every sub-plan under it (a split task's subtasks, #153).
|
|
490
|
+
branch_refs = set()
|
|
491
|
+
for member in run.members:
|
|
492
|
+
branch_refs |= {'refs/heads/forge/%s/%s' % (member['run_id'], task) for task in member['tasks']}
|
|
493
|
+
branch_refs.add('refs/heads/forge/%s-integration' % member['run_id'])
|
|
449
494
|
for wt in listed:
|
|
450
495
|
real = os.path.realpath(wt['path'])
|
|
451
|
-
in_root = real !=
|
|
496
|
+
in_root = any(real != member['wt_root'] and contains(member['wt_root'], real) for member in run.members)
|
|
452
497
|
ours = wt['branch'] in branch_refs
|
|
453
498
|
if not in_root and not ours:
|
|
454
499
|
continue # the main worktree, or another run's: not this command's business
|
|
455
500
|
# forge_worktrees.owner is the rule forge-ui's Worktrees screen uses too: a task or integration branch in
|
|
456
501
|
# the run's folder, or a scratch worktree integrate or the culprit search left there.
|
|
457
|
-
kind =
|
|
502
|
+
kind = None
|
|
503
|
+
for member in run.members:
|
|
504
|
+
kind = forge_worktrees.owner(wt['path'], wt['branch'], member['run_id'], member['tasks'], member['wt_root'])
|
|
505
|
+
if kind:
|
|
506
|
+
break
|
|
458
507
|
run.owners[wt['path']] = kind
|
|
459
508
|
entry = dict(path=wt['path'], branch=(wt['branch'] or '').replace('refs/heads/', '', 1) or None,
|
|
460
509
|
kind='run' if kind else 'foreign', dirty=None, removed=False, note='')
|
|
@@ -486,6 +535,21 @@ def inspect_git(run):
|
|
|
486
535
|
run.branches.append(dict(name=ref.replace('refs/heads/', '', 1), sha=sha, merged=merged,
|
|
487
536
|
status='merged' if merged else 'UNMERGED', checked_out=checked_out.get(ref),
|
|
488
537
|
stays_checked_out=checked_out.get(ref), deleted=False, note=''))
|
|
538
|
+
# What a split that started over set aside (retry --decide split=fresh): refs, not branches, listed and
|
|
539
|
+
# deleted with them under their full name.
|
|
540
|
+
for member in run.members:
|
|
541
|
+
code, out, err = git(run.repo, 'for-each-ref', '--format=%(refname) %(objectname)',
|
|
542
|
+
'refs/forge/kept/%s/' % member['run_id'])
|
|
543
|
+
if code != 0:
|
|
544
|
+
run.git_error = 'git for-each-ref failed in %s: %s' % (run.repo, err or 'exit %d' % code)
|
|
545
|
+
return
|
|
546
|
+
for line in sorted(out.splitlines()):
|
|
547
|
+
ref, _, sha = line.rpartition(' ')
|
|
548
|
+
if ref.rsplit('/', 1)[-1] not in member['tasks']:
|
|
549
|
+
continue
|
|
550
|
+
merged = git(run.repo, 'merge-base', '--is-ancestor', sha, 'HEAD')[0] == 0
|
|
551
|
+
run.branches.append(dict(name=ref, sha=sha, merged=merged, status='merged' if merged else 'UNMERGED',
|
|
552
|
+
checked_out=None, stays_checked_out=None, deleted=False, note=''))
|
|
489
553
|
|
|
490
554
|
|
|
491
555
|
# ------------------------------------------------------------------------------ the steps
|
|
@@ -607,11 +671,13 @@ def remove_worktrees(run):
|
|
|
607
671
|
code, _, err = git(run.repo, 'worktree', 'prune')
|
|
608
672
|
if code != 0:
|
|
609
673
|
problems.append('git worktree prune: ' + (err or 'exit %d' % code))
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
674
|
+
for member in run.members:
|
|
675
|
+
root = member['wt_root']
|
|
676
|
+
if os.path.isdir(root) and not os.path.islink(root):
|
|
677
|
+
try:
|
|
678
|
+
os.rmdir(root) # only succeeds when it is empty: a foreign worktree keeps it
|
|
679
|
+
except OSError:
|
|
680
|
+
pass
|
|
615
681
|
return '; '.join(problems) or None
|
|
616
682
|
|
|
617
683
|
|
|
@@ -624,10 +690,15 @@ def delete_branches(run):
|
|
|
624
690
|
if where:
|
|
625
691
|
branch['note'] = 'kept: checked out in ' + where
|
|
626
692
|
continue
|
|
627
|
-
|
|
693
|
+
if branch['name'].startswith('refs/'):
|
|
694
|
+
code, _, err = git(run.repo, 'update-ref', '-d', branch['name'], branch['sha'])
|
|
695
|
+
restore = 'git update-ref %s %s' % (branch['name'], branch['sha'])
|
|
696
|
+
else:
|
|
697
|
+
code, _, err = git(run.repo, 'branch', '-D', branch['name'])
|
|
698
|
+
restore = 'git branch %s %s' % (branch['name'], branch['sha'])
|
|
628
699
|
if code == 0:
|
|
629
700
|
branch['deleted'] = True
|
|
630
|
-
branch['note'] = 'was %s; restore with:
|
|
701
|
+
branch['note'] = 'was %s; restore with: %s' % (branch['sha'][:12], restore)
|
|
631
702
|
else:
|
|
632
703
|
branch['note'] = err or 'git branch -D exit %d' % code
|
|
633
704
|
problems.append('%s: %s' % (branch['name'], branch['note']))
|
package/scripts/forge-runs.py
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
"""forge runs [--repo DIR | --all] [--limit N] [--json]: this repo's recent runs, in the terminal.
|
|
3
3
|
|
|
4
4
|
Every solo run, `plan` and `run` registers its run dir (forge_registry.py); this lists them newest
|
|
5
|
-
first, one line each (run id, kind, age, task states, verification, final review, goal,
|
|
6
|
-
`after <run>` when the plan was chained
|
|
5
|
+
first, one line each (run id, kind, age, task states, verification, final review, goal,
|
|
6
|
+
`after <run>` when the plan was chained, and `made with Fractal, removed in v0.23` for a run of
|
|
7
|
+
that removed backend) with the run dir under it, so you can see what happened
|
|
7
8
|
without a browser and get the dir to resume, retry or open with `forge ui open`. The repo is the
|
|
8
9
|
Git top level of the current directory unless
|
|
9
10
|
`--repo` names one; `--all` lists the runs of every repo. It reads the same run summaries as
|
|
@@ -15,6 +16,11 @@ deletes a run, after its traces are in the dataset and an archive exists (script
|
|
|
15
16
|
keeps every run and takes back what it holds for nothing: leftover review snapshots and, with
|
|
16
17
|
--logs, gzipped log copies (scripts/forge-runs-compact.py). Both change things; listing never does.
|
|
17
18
|
|
|
19
|
+
`forge runs tree <run-dir> [--json]` prints a run's tasks and, under each task that was split, its subtasks
|
|
20
|
+
through every level, with the decision recorded for each (split, kept whole, or kept whole at a limit) and
|
|
21
|
+
the run's limits. A split task's subtasks are a plan of their own under it, `<run-dir>/tasks/<id>/sub`:
|
|
22
|
+
the list above counts them on the run's line and never lists them as runs.
|
|
23
|
+
|
|
18
24
|
`forge runs rerun <run-dir> --dwarf SPEC` and `forge runs compare <run-dir-A> <run-dir-B>` (scripts/forge-compare.py)
|
|
19
25
|
run a plan again under another implementer, from the same starting commit and never merging, and set two runs
|
|
20
26
|
side by side per task. Starting the rerun spends tokens, so it takes `--run --yes` after it has shown the forecast.
|
|
@@ -37,7 +43,7 @@ import forge_registry # noqa: E402
|
|
|
37
43
|
from forge_ui import reader # noqa: E402
|
|
38
44
|
|
|
39
45
|
FIELDS = ('key', 'run_id', 'kind', 'goal', 'repo', 'path', 'created', 'updated', 'task_count', 'counts',
|
|
40
|
-
'verification_status', 'final_review', 'after')
|
|
46
|
+
'verification_status', 'final_review', 'after', 'removed', 'decomposition')
|
|
41
47
|
|
|
42
48
|
|
|
43
49
|
def repo_of(start: Path) -> Path:
|
|
@@ -97,7 +103,14 @@ def line(run: dict, now: float, with_repo: bool = False) -> str:
|
|
|
97
103
|
if len(goal) > 72:
|
|
98
104
|
goal = goal[:71] + '…'
|
|
99
105
|
repo = f" {Path(run['repo']).name or run['repo']}" if with_repo and run.get('repo') else ''
|
|
100
|
-
|
|
106
|
+
# A run of a backend forge no longer has (Fractal): still listed and readable, never run again.
|
|
107
|
+
gone = run.get('removed') or {}
|
|
108
|
+
removed = f" made with {gone.get('name')}, removed in v{gone.get('since')}" if gone else ''
|
|
109
|
+
# Tasks that were split (#153): their subtasks are plans of their own under the run dir, counted here.
|
|
110
|
+
tree = run.get('decomposition') or {}
|
|
111
|
+
split = f" {tree['subtasks']} subtasks in {tree['split']} split task{'' if tree['split'] == 1 else 's'}" if tree.get('split') else ''
|
|
112
|
+
return (f"{run['run_id'] or run['key']} {run['kind']}{repo} {age(run['updated'], now)} {counts}{split}{checks}{chain}{removed}"
|
|
113
|
+
f" {goal}\n {run['path']}")
|
|
101
114
|
|
|
102
115
|
|
|
103
116
|
def remove(argv) -> int:
|
|
@@ -130,16 +143,44 @@ def compare_runs(argv) -> int:
|
|
|
130
143
|
return module.main(argv)
|
|
131
144
|
|
|
132
145
|
|
|
146
|
+
def tree(argv) -> int:
|
|
147
|
+
"""`forge runs tree <run-dir> [--json]`: the run's tasks and, under each task that was split, its
|
|
148
|
+
subtasks through every level (#153), with the decision recorded for each and the run's limits."""
|
|
149
|
+
import forge_decompose
|
|
150
|
+
parser = argparse.ArgumentParser(prog='forge runs tree', description="A run's tasks and the subtasks of every task that was "
|
|
151
|
+
'split, through every level, with the decision recorded for each. Read-only.')
|
|
152
|
+
parser.add_argument('run_dir', type=Path, metavar='RUN_DIR', help='the plan dir (the one with tasks.tsv)')
|
|
153
|
+
parser.add_argument('--json', action='store_true', help='print {limits, nodes} as JSON, for scripts and agents')
|
|
154
|
+
args = parser.parse_args(argv)
|
|
155
|
+
if not (args.run_dir / 'tasks.tsv').is_file():
|
|
156
|
+
parser.error(f'{args.run_dir} is not a plan dir (no tasks.tsv); a solo run has one task and no tree')
|
|
157
|
+
nodes = forge_decompose.tree(args.run_dir)
|
|
158
|
+
limits = dict(forge_decompose.limits(args.run_dir), frozen=forge_decompose.is_frozen(args.run_dir))
|
|
159
|
+
if args.json:
|
|
160
|
+
json.dump(dict(limits=limits, nodes=nodes), sys.stdout, indent=2)
|
|
161
|
+
sys.stdout.write('\n')
|
|
162
|
+
return 0
|
|
163
|
+
print('decomposition limits: ' + forge_decompose.describe(limits) + (' (frozen)' if limits['frozen'] else ''))
|
|
164
|
+
print(forge_decompose.render(args.run_dir))
|
|
165
|
+
for node in nodes:
|
|
166
|
+
if node['children']:
|
|
167
|
+
print(f"subtasks of {node['id']}: {forge_decompose.sub_dir(node['plan'], node['task'])}")
|
|
168
|
+
return 0
|
|
169
|
+
|
|
170
|
+
|
|
133
171
|
def main(argv=None) -> int:
|
|
134
172
|
argv = sys.argv[1:] if argv is None else list(argv)
|
|
135
173
|
if argv[:1] == ['rm']:
|
|
136
174
|
return remove(argv[1:])
|
|
175
|
+
if argv[:1] == ['tree']:
|
|
176
|
+
return tree(argv[1:])
|
|
137
177
|
if argv[:1] == ['compact']:
|
|
138
178
|
return compact(argv[1:])
|
|
139
179
|
if argv[:1] in (['rerun'], ['compare']):
|
|
140
180
|
return compare_runs(argv)
|
|
141
181
|
parser = argparse.ArgumentParser(prog='forge runs', description="This repo's recent forge runs, newest first. Listing is read-only.",
|
|
142
|
-
epilog='
|
|
182
|
+
epilog='The subtasks of a run\'s split tasks: forge runs tree <run-dir>. '
|
|
183
|
+
'Delete a run, keeping its traces: forge runs rm <run-dir> (forge runs rm --help). Take back the space runs '
|
|
143
184
|
'hold for nothing, keeping every run: forge runs compact --help. Rerun a plan with another '
|
|
144
185
|
'implementer and compare: forge runs rerun --help, forge runs compare --help')
|
|
145
186
|
which = parser.add_mutually_exclusive_group()
|
package/scripts/forge-runtime.py
CHANGED
|
@@ -47,7 +47,7 @@ def _dataset(hook: str, *args) -> None:
|
|
|
47
47
|
|
|
48
48
|
|
|
49
49
|
def capability_help(cache: str, registry: str, recipe: str, command: list[str]) -> str:
|
|
50
|
-
binary =
|
|
50
|
+
binary, exec_command = forge_proc.resolve_win_command(command)
|
|
51
51
|
stat = binary.stat()
|
|
52
52
|
identity = [
|
|
53
53
|
str(binary), stat.st_dev, stat.st_ino, stat.st_size,
|
|
@@ -61,7 +61,7 @@ def capability_help(cache: str, registry: str, recipe: str, command: list[str])
|
|
|
61
61
|
path = root / key
|
|
62
62
|
if path.exists():
|
|
63
63
|
return path.read_text()
|
|
64
|
-
result = subprocess.run(
|
|
64
|
+
result = subprocess.run(exec_command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
|
65
65
|
if result.returncode:
|
|
66
66
|
raise RuntimeError(result.stdout.decode(errors='replace'))
|
|
67
67
|
temporary = root / (key + '.' + uuid.uuid4().hex)
|
|
@@ -796,14 +796,32 @@ def settled_result(text: str) -> dict | None:
|
|
|
796
796
|
return found
|
|
797
797
|
|
|
798
798
|
|
|
799
|
-
def
|
|
799
|
+
def open_background(text: str) -> bool:
|
|
800
|
+
"""Whether the session's last list of background tasks (system/background_tasks_changed) names any. A log
|
|
801
|
+
that never lists them has none open."""
|
|
802
|
+
tasks = []
|
|
803
|
+
for event in _events(text)[0]:
|
|
804
|
+
if event.get('type') == 'system' and event.get('subtype') == 'background_tasks_changed':
|
|
805
|
+
tasks = event.get('tasks') if isinstance(event.get('tasks'), list) else []
|
|
806
|
+
return bool(tasks)
|
|
807
|
+
|
|
808
|
+
|
|
809
|
+
def settle(log: str, grace: str, pid: str, quick: str = '') -> None:
|
|
800
810
|
"""Returns once the harness log ends in a settled result (settled_result) and has not grown for `grace`
|
|
801
811
|
seconds of the machine's awake time; exits 1 once process `pid`, the harness, is gone. dispatch then ends
|
|
802
812
|
the harness: its answer is in, and only a background task keeps it open. An idle log whose last turn is
|
|
803
|
-
still under way (a long command) is never ended here; that is the watchdog's.
|
|
813
|
+
still under way (a long command) is never ended here; that is the watchdog's.
|
|
814
|
+
|
|
815
|
+
`quick` (live steering, #252): a CLI whose input forge holds open never exits after its result, so with no
|
|
816
|
+
background task open the wait is `quick` seconds instead. A grace of 0 then means only the quick path.
|
|
817
|
+
Prints which wait ended it: quick or grace."""
|
|
804
818
|
grace_s, target = float(grace), int(pid)
|
|
805
|
-
|
|
806
|
-
|
|
819
|
+
quick_s = float(quick) if quick else None
|
|
820
|
+
waits = [w for w in (grace_s if grace_s > 0 else None, quick_s) if w is not None]
|
|
821
|
+
if not waits:
|
|
822
|
+
raise ValueError('settle needs a grace or a quick grace')
|
|
823
|
+
poll = min(SETTLE_POLL_S, max(min(waits) / 4, 0.05))
|
|
824
|
+
size, since, verdict = None, time.monotonic(), None # verdict: (settled, background open) of this size
|
|
807
825
|
while True:
|
|
808
826
|
if forge_proc.IS_WINDOWS:
|
|
809
827
|
if not forge_proc.pid_alive(target):
|
|
@@ -820,14 +838,21 @@ def settle(log: str, grace: str, pid: str) -> None:
|
|
|
820
838
|
except OSError:
|
|
821
839
|
now = None
|
|
822
840
|
if now != size:
|
|
823
|
-
size, since = now, time.monotonic()
|
|
824
|
-
elif
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
841
|
+
size, since, verdict = now, time.monotonic(), None
|
|
842
|
+
elif time.monotonic() - since >= min(waits):
|
|
843
|
+
if verdict is None: # read once per size: an idle log mid-turn is not read again and again
|
|
844
|
+
try:
|
|
845
|
+
text = Path(log).read_text(errors='replace')
|
|
846
|
+
except OSError:
|
|
847
|
+
text = ''
|
|
848
|
+
settled = settled_result(text) is not None
|
|
849
|
+
verdict = (settled, settled and open_background(text))
|
|
850
|
+
idle = time.monotonic() - since
|
|
851
|
+
if verdict[0] and quick_s is not None and idle >= quick_s and not verdict[1]:
|
|
852
|
+
print('quick')
|
|
853
|
+
return
|
|
854
|
+
if verdict[0] and grace_s > 0 and idle >= grace_s:
|
|
855
|
+
print('grace')
|
|
831
856
|
return
|
|
832
857
|
time.sleep(poll)
|
|
833
858
|
|