@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_flock.py
CHANGED
|
@@ -11,6 +11,7 @@ from __future__ import annotations
|
|
|
11
11
|
|
|
12
12
|
import errno
|
|
13
13
|
import os
|
|
14
|
+
import sys
|
|
14
15
|
import time
|
|
15
16
|
|
|
16
17
|
try:
|
|
@@ -33,6 +34,11 @@ else:
|
|
|
33
34
|
|
|
34
35
|
_LOCK_OFFSET = 0x40000000 # 1 GiB sentinel byte; msvcrt does not extend file size
|
|
35
36
|
|
|
37
|
+
# Cygwin (Windows MSYS2 mode): flock sometimes fails with EFAULT when threads of one process lock
|
|
38
|
+
# the same file at the same moment, and the same call succeeds when repeated.
|
|
39
|
+
_CYGWIN = sys.platform == 'cygwin'
|
|
40
|
+
_CYGWIN_EFAULT_TRIES = 100 # 10 ms apart: about a second
|
|
41
|
+
|
|
36
42
|
_BUSY_ERRNOS = frozenset(
|
|
37
43
|
getattr(errno, name)
|
|
38
44
|
for name in ('EACCES', 'EAGAIN', 'EWOULDBLOCK', 'EDEADLK')
|
|
@@ -57,8 +63,17 @@ def _msvcrt_lock_sentinel(fd: int, mode: int) -> None:
|
|
|
57
63
|
def flock(fd_or_file, operation: int) -> None:
|
|
58
64
|
"""Acquire or release an advisory lock matching ``fcntl.flock`` semantics."""
|
|
59
65
|
if _fcntl is not None:
|
|
60
|
-
|
|
61
|
-
|
|
66
|
+
if not _CYGWIN:
|
|
67
|
+
_fcntl.flock(fd_or_file, operation)
|
|
68
|
+
return
|
|
69
|
+
for attempt in range(_CYGWIN_EFAULT_TRIES):
|
|
70
|
+
try:
|
|
71
|
+
_fcntl.flock(fd_or_file, operation)
|
|
72
|
+
return
|
|
73
|
+
except OSError as exc:
|
|
74
|
+
if exc.errno != errno.EFAULT or attempt == _CYGWIN_EFAULT_TRIES - 1:
|
|
75
|
+
raise
|
|
76
|
+
time.sleep(0.01)
|
|
62
77
|
|
|
63
78
|
fd = _fileno(fd_or_file)
|
|
64
79
|
nonblocking = bool(operation & LOCK_NB)
|
|
@@ -181,6 +181,9 @@ def prompt(plan: Path, gid: str, threshold) -> str:
|
|
|
181
181
|
earlier = _earlier(gdir)
|
|
182
182
|
contract = attribute._contract()
|
|
183
183
|
out = [contract.qa_text('head', 'group').rstrip('\n'), '']
|
|
184
|
+
deps = _read(gdir / 'review.deps').strip('\n')
|
|
185
|
+
if deps:
|
|
186
|
+
out += [deps, '']
|
|
184
187
|
out += ['# Group %s: %s' % (gid, group.title if group.title != '-' else gid)]
|
|
185
188
|
if group.goal != '-':
|
|
186
189
|
out += ['', 'Goal of the group: %s' % group.goal]
|
|
@@ -193,7 +196,9 @@ def prompt(plan: Path, gid: str, threshold) -> str:
|
|
|
193
196
|
out += [_finding_text(f, blocks) for f in loose] + ['']
|
|
194
197
|
for task in group.members:
|
|
195
198
|
out += _member(plan, repo, task, tasks.get(task, []), gdir, current, earlier, history) + ['']
|
|
196
|
-
|
|
199
|
+
raw_mins = _read(plan / 'qa_test_minutes').strip()
|
|
200
|
+
test_minutes = int(raw_mins) if raw_mins.isdigit() else None
|
|
201
|
+
out += [contract.qa_text('tail', 'group', threshold, test_minutes).rstrip('\n'), '']
|
|
197
202
|
out += ['```diff', _combined(repo, gdir, base, commit).rstrip('\n'), '```']
|
|
198
203
|
return '\n'.join(out) + '\n'
|
|
199
204
|
|
|
@@ -114,7 +114,7 @@ SITE_CAPABILITY = {
|
|
|
114
114
|
RETIRED_CAPABILITIES = frozenset(('routing',))
|
|
115
115
|
|
|
116
116
|
# Loaded via importlib rather than a package-relative import: forge-runtime.py lives one
|
|
117
|
-
# directory up and is not itself part of a package
|
|
117
|
+
# directory up and is not itself part of a package.
|
|
118
118
|
_runtime_spec = importlib.util.spec_from_file_location('forge_runtime', SCRIPTS / 'forge-runtime.py')
|
|
119
119
|
_runtime = importlib.util.module_from_spec(_runtime_spec)
|
|
120
120
|
_runtime_spec.loader.exec_module(_runtime)
|
package/scripts/forge_jev/cli.py
CHANGED
|
@@ -886,7 +886,7 @@ def cmd_memory_curate(args) -> int:
|
|
|
886
886
|
from . import memory as memory_module
|
|
887
887
|
|
|
888
888
|
existing = []
|
|
889
|
-
path =
|
|
889
|
+
path = _memory_md(args.repo)
|
|
890
890
|
if path.is_file():
|
|
891
891
|
try:
|
|
892
892
|
existing = [line.strip(' -') for line in path.read_text(errors='replace').splitlines()
|
|
@@ -1056,3 +1056,12 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
1056
1056
|
return 3
|
|
1057
1057
|
finally:
|
|
1058
1058
|
use_repo(None)
|
|
1059
|
+
|
|
1060
|
+
|
|
1061
|
+
def _memory_md(repo) -> Path:
|
|
1062
|
+
"""repo's .forge/memory.md, in the main checkout when repo is a linked worktree (#159)."""
|
|
1063
|
+
try:
|
|
1064
|
+
import forge_memory_home
|
|
1065
|
+
except ImportError:
|
|
1066
|
+
return Path(repo) / '.forge' / 'memory.md'
|
|
1067
|
+
return forge_memory_home.memory_file(repo)
|
|
@@ -88,7 +88,7 @@ def _excerpt(repo: Path, files: str) -> dict:
|
|
|
88
88
|
|
|
89
89
|
|
|
90
90
|
def _memory(repo: Path) -> str:
|
|
91
|
-
path = repo
|
|
91
|
+
path = _memory_md(repo)
|
|
92
92
|
try:
|
|
93
93
|
return path.read_text(errors='replace')[:MEMORY_CHARS] if path.is_file() else ''
|
|
94
94
|
except OSError:
|
|
@@ -296,3 +296,12 @@ def predict_drift(repo, *, goal: str, task_id: str, title: str, declared: str,
|
|
|
296
296
|
predicted.append((name, round(probability, 3)))
|
|
297
297
|
predicted.sort(key=lambda item: item[1], reverse=True)
|
|
298
298
|
return predicted
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
def _memory_md(repo) -> Path:
|
|
302
|
+
"""repo's .forge/memory.md, in the main checkout when repo is a linked worktree (#159)."""
|
|
303
|
+
try:
|
|
304
|
+
import forge_memory_home
|
|
305
|
+
except ImportError:
|
|
306
|
+
return Path(repo) / '.forge' / 'memory.md'
|
|
307
|
+
return forge_memory_home.memory_file(repo)
|
|
@@ -242,7 +242,7 @@ def _remembered_commands(fact: str) -> list[str]:
|
|
|
242
242
|
|
|
243
243
|
|
|
244
244
|
def _memory_verify(repo: Path, found, seen) -> None:
|
|
245
|
-
path = repo
|
|
245
|
+
path = _memory_md(repo)
|
|
246
246
|
for fact in _memory_facts(repo, 'verify'):
|
|
247
247
|
# A memory fact is prose ("pytest -q runs the suite; make test also lints and
|
|
248
248
|
# is 4x slower"), not a bare command -- pull out anything that looks like a
|
|
@@ -289,7 +289,7 @@ _MEMORY_SECTIONS = {'verify': '## Verify', 'trap': '## Known traps',
|
|
|
289
289
|
def _memory_facts(repo: Path, category: str) -> list[str]:
|
|
290
290
|
"""The `- ` bullets under one heading of a rendered .forge/memory.md."""
|
|
291
291
|
heading = _MEMORY_SECTIONS.get(category)
|
|
292
|
-
path =
|
|
292
|
+
path = _memory_md(repo)
|
|
293
293
|
if not heading or not path.is_file():
|
|
294
294
|
return []
|
|
295
295
|
try:
|
|
@@ -477,3 +477,11 @@ def discover(repo, *, config=None, run_dir=None) -> dict | None:
|
|
|
477
477
|
runtime_level=runtime_level, source=picked_candidate['source'],
|
|
478
478
|
evidence=picked_candidate['evidence'], coverage=coverage)
|
|
479
479
|
|
|
480
|
+
|
|
481
|
+
def _memory_md(repo) -> Path:
|
|
482
|
+
"""repo's .forge/memory.md, in the main checkout when repo is a linked worktree (#159)."""
|
|
483
|
+
try:
|
|
484
|
+
import forge_memory_home
|
|
485
|
+
except ImportError:
|
|
486
|
+
return Path(repo) / '.forge' / 'memory.md'
|
|
487
|
+
return forge_memory_home.memory_file(repo)
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"""Old-record compatibility for runs made before forge 0.23 removed Fractal (#154).
|
|
2
|
+
|
|
3
|
+
Fractal was an opt-in execution backend driven through an external runtime. forge no longer
|
|
4
|
+
has it: task decomposition is forge's own (references/decompose.md). What stays here is only
|
|
5
|
+
what reading an old run needs:
|
|
6
|
+
|
|
7
|
+
* a plan or solo directory whose `fractal-selection.json` says `enabled` ran under Fractal. It is
|
|
8
|
+
still listed and readable from what forge recorded, and it cannot be resumed;
|
|
9
|
+
* plans made before 0.23 keep their dwarf tier pools in `fractal-routing.json`. New plans write
|
|
10
|
+
`dwarf-routing.json`; readers take the new file, then the old one.
|
|
11
|
+
|
|
12
|
+
Command line, for the shell runners:
|
|
13
|
+
forge_legacy.py pools <dir> the pools file to read (the new name when neither exists)
|
|
14
|
+
forge_legacy.py was-fractal <dir> exit 0 when the directory ran under Fractal
|
|
15
|
+
"""
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
18
|
+
import json
|
|
19
|
+
import os
|
|
20
|
+
import sys
|
|
21
|
+
from pathlib import Path
|
|
22
|
+
|
|
23
|
+
REMOVED_IN = '0.23'
|
|
24
|
+
OLD_SELECTION = 'fractal-selection.json'
|
|
25
|
+
OLD_POOLS = 'fractal-routing.json'
|
|
26
|
+
POOLS = 'dwarf-routing.json'
|
|
27
|
+
# Where the removed runtime kept its own state: $XDG_STATE_HOME/forge/<this>.
|
|
28
|
+
OLD_STATE_DIR = 'fractal'
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def pools_path(plan) -> Path:
|
|
32
|
+
"""The plan's dwarf tier pools: dwarf-routing.json, else the file an old plan has."""
|
|
33
|
+
plan = Path(plan)
|
|
34
|
+
new, old = plan / POOLS, plan / OLD_POOLS
|
|
35
|
+
if not new.exists() and old.exists():
|
|
36
|
+
return old
|
|
37
|
+
return new
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def was_fractal(directory) -> bool:
|
|
41
|
+
"""True when this plan or solo directory ran under Fractal. An unreadable selection counts:
|
|
42
|
+
nothing may resume a run whose backend cannot be told."""
|
|
43
|
+
path = Path(directory) / OLD_SELECTION
|
|
44
|
+
try:
|
|
45
|
+
raw = path.read_text()
|
|
46
|
+
except FileNotFoundError:
|
|
47
|
+
return False
|
|
48
|
+
except OSError:
|
|
49
|
+
return True
|
|
50
|
+
if not raw.strip():
|
|
51
|
+
return False
|
|
52
|
+
try:
|
|
53
|
+
data = json.loads(raw)
|
|
54
|
+
except ValueError:
|
|
55
|
+
return True
|
|
56
|
+
return not isinstance(data, dict) or bool(data.get('enabled', True))
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def removed_note() -> str:
|
|
60
|
+
return 'made with Fractal, which forge %s removed' % REMOVED_IN
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def refusal(what: str = 'this run') -> str:
|
|
64
|
+
"""Why an old Fractal run is not resumed, in one sentence."""
|
|
65
|
+
return ('%s was made with Fractal, which forge %s removed: it can still be read (forge runs, forge-ui) '
|
|
66
|
+
'but not run, retried or resumed. Start a new run for the work that is left.' % (what, REMOVED_IN))
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def state_dir() -> Path:
|
|
70
|
+
"""The removed runtime's state directory (it may not exist). An empty XDG_STATE_HOME counts as unset."""
|
|
71
|
+
base = os.environ.get('XDG_STATE_HOME') or str(Path.home() / '.local' / 'state')
|
|
72
|
+
return Path(base).expanduser() / 'forge' / OLD_STATE_DIR
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def main(argv: list) -> int:
|
|
76
|
+
if len(argv) == 2 and argv[0] == 'pools':
|
|
77
|
+
print(pools_path(argv[1]))
|
|
78
|
+
return 0
|
|
79
|
+
if len(argv) == 2 and argv[0] == 'was-fractal':
|
|
80
|
+
return 0 if was_fractal(argv[1]) else 1
|
|
81
|
+
print(__doc__.strip(), file=sys.stderr)
|
|
82
|
+
return 2
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
if __name__ == '__main__':
|
|
86
|
+
sys.exit(main(sys.argv[1:]))
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"""Where a checkout's project memory lives (#159), for the Python readers of `.forge/memory.md`.
|
|
2
|
+
|
|
3
|
+
forge-memory.sh's `memory_home` decides it for every write; this is the same rule for the readers that
|
|
4
|
+
open the file themselves (the decision-model gates, the run dataset). A linked worktree (`git worktree
|
|
5
|
+
add`) whose `.forge/memory.md` and `.forge/ledger.tsv` are not tracked keeps its memory in the main
|
|
6
|
+
checkout's `.forge/`: `git worktree remove` deletes ignored files without a word, and the main checkout is
|
|
7
|
+
where later runs start. Everything else keeps it in the checkout itself: the main checkout, a tracked
|
|
8
|
+
`.forge/` (git refuses to remove a worktree with changes to it), a bare repository's worktree, a path
|
|
9
|
+
outside git, or FORGE_MEMORY_PER_CHECKOUT=1.
|
|
10
|
+
"""
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import os
|
|
14
|
+
from pathlib import Path
|
|
15
|
+
import subprocess
|
|
16
|
+
|
|
17
|
+
_TIMEOUT = 10
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _git(repo, *args) -> str | None:
|
|
21
|
+
try:
|
|
22
|
+
done = subprocess.run(['git', '-C', str(repo), *args], capture_output=True, text=True,
|
|
23
|
+
stdin=subprocess.DEVNULL, timeout=_TIMEOUT)
|
|
24
|
+
except (OSError, subprocess.SubprocessError):
|
|
25
|
+
return None
|
|
26
|
+
return done.stdout if done.returncode == 0 else None
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def memory_root(repo) -> Path:
|
|
30
|
+
"""The directory whose `.forge/` holds `repo`'s project memory."""
|
|
31
|
+
repo = Path(repo)
|
|
32
|
+
if os.environ.get('FORGE_MEMORY_PER_CHECKOUT') == '1':
|
|
33
|
+
return repo
|
|
34
|
+
git_dir, common = _git(repo, 'rev-parse', '--git-dir'), _git(repo, 'rev-parse', '--git-common-dir')
|
|
35
|
+
if git_dir is None or common is None:
|
|
36
|
+
return repo
|
|
37
|
+
try:
|
|
38
|
+
if (repo / git_dir.strip()).resolve() == (repo / common.strip()).resolve():
|
|
39
|
+
return repo # the main checkout, or no linked worktree
|
|
40
|
+
except OSError:
|
|
41
|
+
return repo
|
|
42
|
+
listing = _git(repo, 'worktree', 'list', '--porcelain') or ''
|
|
43
|
+
blocks = listing.split('\n\n')
|
|
44
|
+
first = blocks[0].splitlines() if blocks and blocks[0] else []
|
|
45
|
+
if not first or not first[0].startswith('worktree ') or 'bare' in first:
|
|
46
|
+
return repo
|
|
47
|
+
main = Path(first[0][len('worktree '):])
|
|
48
|
+
if not main.is_dir():
|
|
49
|
+
return repo
|
|
50
|
+
if (_git(repo, 'ls-files', '--', '.forge/memory.md', '.forge/ledger.tsv') or '').strip():
|
|
51
|
+
return repo # tracked: git already protects it
|
|
52
|
+
return main
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def memory_file(repo) -> Path:
|
|
56
|
+
"""`repo`'s `.forge/memory.md`, wherever its memory lives."""
|
|
57
|
+
return memory_root(repo) / '.forge' / 'memory.md'
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""The model a spec runs, said in words people can check: `sol:high` is gpt-6.2-sol on codex.
|
|
3
|
+
|
|
4
|
+
An alias is one model on every harness (registry.tsv, #187), but the alias alone does not say
|
|
5
|
+
which version that is today. Everywhere a person picks or confirms a model (the approval table,
|
|
6
|
+
forge-ui's pickers, `forge setup`) shows the model id the spec resolves to, so nobody has to know
|
|
7
|
+
that `astra` moved from gpt-6-astra to gpt-6.2-astra.
|
|
8
|
+
|
|
9
|
+
forge_models.py describe SPEC... one line per spec: `SPEC = MODEL on HARNESS`
|
|
10
|
+
forge_models.py legend TASKS_TSV the approval table's models block for a plan's specs
|
|
11
|
+
forge_models.py json SPEC... {spec: {alias, harness, model, effort, known, label}}
|
|
12
|
+
|
|
13
|
+
Resolution is forge-dispatch.sh's: the first row of an alias is its default harness,
|
|
14
|
+
alias:effort:harness picks that harness's row, and an unknown alias with a harness is a literal
|
|
15
|
+
model id. Standard library only; never reads anything but the registry.
|
|
16
|
+
"""
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
import json
|
|
20
|
+
import os
|
|
21
|
+
import sys
|
|
22
|
+
from pathlib import Path
|
|
23
|
+
|
|
24
|
+
SKILL = Path(__file__).resolve().parent.parent
|
|
25
|
+
|
|
26
|
+
# CLI names that are not model versions: the CLI maps them to its current model of that family.
|
|
27
|
+
MOVING_NAMES = {'opus': 'Opus', 'sonnet': 'Sonnet', 'haiku': 'Haiku', 'fable': 'Fable'}
|
|
28
|
+
NOT_MODELS = ('', '-', 'UNASSIGNED', 'script')
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def registry_rows(path=None) -> list:
|
|
32
|
+
path = path or os.environ.get('FORGE_REGISTRY') or str(SKILL / 'registry.tsv')
|
|
33
|
+
rows = []
|
|
34
|
+
try:
|
|
35
|
+
text = Path(path).read_text(encoding='utf-8', errors='replace')
|
|
36
|
+
except OSError:
|
|
37
|
+
return rows
|
|
38
|
+
for line in text.splitlines():
|
|
39
|
+
if not line.strip() or line.startswith('#'):
|
|
40
|
+
continue
|
|
41
|
+
cells = line.split('\t')
|
|
42
|
+
if len(cells) >= 3:
|
|
43
|
+
rows.append(cells)
|
|
44
|
+
return rows
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def resolve(spec: str, rows: list | None = None) -> dict | None:
|
|
48
|
+
"""{alias, effort, harness, model, known} for one spec, or None when it names no model
|
|
49
|
+
(empty, `script`, a pool) or cannot be resolved (an unknown alias with no harness)."""
|
|
50
|
+
spec = (spec or '').strip()
|
|
51
|
+
if spec in NOT_MODELS or ',' in spec:
|
|
52
|
+
return None
|
|
53
|
+
rows = registry_rows() if rows is None else rows
|
|
54
|
+
parts = spec.split(':')
|
|
55
|
+
alias = parts[0]
|
|
56
|
+
effort = parts[1] if len(parts) > 1 else ''
|
|
57
|
+
harness = ':'.join(parts[2:]) if len(parts) > 2 else ''
|
|
58
|
+
if not alias:
|
|
59
|
+
return None
|
|
60
|
+
for row in rows:
|
|
61
|
+
if row[0] == alias and (not harness or row[1] == harness):
|
|
62
|
+
return dict(alias=alias, effort=effort, harness=row[1], model=row[2], known=True)
|
|
63
|
+
if harness:
|
|
64
|
+
return dict(alias=alias, effort=effort, harness=harness, model=alias, known=False)
|
|
65
|
+
return None
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def label(resolved: dict | None) -> str:
|
|
69
|
+
"""`gpt-6.2-sol on codex`; `opus on claude (the CLI's current Opus)`; `kimi-x on opencode
|
|
70
|
+
(literal id, not in the registry)`; `unresolved` for None."""
|
|
71
|
+
if not resolved:
|
|
72
|
+
return 'unresolved'
|
|
73
|
+
text = '%s on %s' % (resolved['model'], resolved['harness'])
|
|
74
|
+
family = MOVING_NAMES.get(resolved['model'])
|
|
75
|
+
if family:
|
|
76
|
+
text += " (the CLI's current %s)" % family
|
|
77
|
+
elif not resolved['known']:
|
|
78
|
+
text += ' (literal id, not in the registry)'
|
|
79
|
+
return text
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def describe(spec: str, rows: list | None = None) -> str:
|
|
83
|
+
return label(resolve(spec, rows))
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def pool(cell: str) -> list:
|
|
87
|
+
"""The specs of a tasks.tsv dwarf or qa cell: one spec, or a comma-separated pool."""
|
|
88
|
+
return [s.strip() for s in (cell or '').split(',') if s.strip() and s.strip() not in NOT_MODELS]
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def plan_specs(tasks_tsv) -> list:
|
|
92
|
+
"""Every distinct spec in a plan's dwarf and qa columns, in first-seen order."""
|
|
93
|
+
seen = []
|
|
94
|
+
try:
|
|
95
|
+
lines = Path(tasks_tsv).read_text(encoding='utf-8', errors='replace').splitlines()
|
|
96
|
+
except OSError:
|
|
97
|
+
return seen
|
|
98
|
+
for line in lines:
|
|
99
|
+
if not line.strip() or line.startswith('#'):
|
|
100
|
+
continue
|
|
101
|
+
cells = line.split('\t')
|
|
102
|
+
for column in (4, 5):
|
|
103
|
+
if len(cells) > column:
|
|
104
|
+
for spec in pool(cells[column]):
|
|
105
|
+
if spec not in seen:
|
|
106
|
+
seen.append(spec)
|
|
107
|
+
return seen
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def legend(specs: list, rows: list | None = None) -> list:
|
|
111
|
+
"""` sol:high gpt-6.2-sol on codex` lines, aligned, for each spec that names a model."""
|
|
112
|
+
rows = registry_rows() if rows is None else rows
|
|
113
|
+
if not specs:
|
|
114
|
+
return []
|
|
115
|
+
width = max(len(s) for s in specs)
|
|
116
|
+
return [' %-*s %s' % (width, s, describe(s, rows)) for s in specs]
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def main(argv=None) -> int:
|
|
120
|
+
argv = list(sys.argv[1:] if argv is None else argv)
|
|
121
|
+
if not argv or argv[0] in ('-h', '--help'):
|
|
122
|
+
print(__doc__.strip())
|
|
123
|
+
return 0 if argv else 2
|
|
124
|
+
command, args = argv[0], argv[1:]
|
|
125
|
+
rows = registry_rows()
|
|
126
|
+
if command == 'describe':
|
|
127
|
+
for spec in args:
|
|
128
|
+
print('%s = %s' % (spec, describe(spec, rows)))
|
|
129
|
+
return 0
|
|
130
|
+
if command == 'legend':
|
|
131
|
+
if len(args) != 1:
|
|
132
|
+
print('usage: forge_models.py legend TASKS_TSV', file=sys.stderr)
|
|
133
|
+
return 2
|
|
134
|
+
lines = legend(plan_specs(args[0]), rows)
|
|
135
|
+
if lines:
|
|
136
|
+
print('models (what each spec runs today):')
|
|
137
|
+
print('\n'.join(lines))
|
|
138
|
+
return 0
|
|
139
|
+
if command == 'json':
|
|
140
|
+
out = {}
|
|
141
|
+
for spec in args:
|
|
142
|
+
found = resolve(spec, rows)
|
|
143
|
+
out[spec] = dict(found, label=label(found)) if found else dict(label=label(None))
|
|
144
|
+
print(json.dumps(out, indent=2, sort_keys=True))
|
|
145
|
+
return 0
|
|
146
|
+
print('forge_models.py: unknown command %r (describe, legend, json)' % command, file=sys.stderr)
|
|
147
|
+
return 2
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
if __name__ == '__main__':
|
|
151
|
+
sys.exit(main())
|
package/scripts/forge_posix.py
CHANGED
|
@@ -9,8 +9,12 @@ from __future__ import annotations
|
|
|
9
9
|
|
|
10
10
|
import errno
|
|
11
11
|
import os
|
|
12
|
+
import re
|
|
12
13
|
import stat
|
|
13
14
|
|
|
15
|
+
IS_WINDOWS = os.name == 'nt'
|
|
16
|
+
_MSYS_PATH_RE = re.compile(r'^/([a-zA-Z])(?:/(.*))?$')
|
|
17
|
+
|
|
14
18
|
O_NOFOLLOW = getattr(os, 'O_NOFOLLOW', 0)
|
|
15
19
|
O_NONBLOCK = getattr(os, 'O_NONBLOCK', 0)
|
|
16
20
|
O_CLOEXEC = getattr(os, 'O_CLOEXEC', 0)
|
|
@@ -106,3 +110,16 @@ def unlink_at(handle: int | str, leaf: str) -> None:
|
|
|
106
110
|
os.unlink(leaf, dir_fd=handle)
|
|
107
111
|
else:
|
|
108
112
|
os.unlink(os.path.join(handle, leaf))
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def host_path(path: os.PathLike | str) -> str:
|
|
116
|
+
"""Convert an MSYS/Git-Bash `/c/...` path to `C:/...` on native Windows."""
|
|
117
|
+
text = os.fspath(path)
|
|
118
|
+
if IS_WINDOWS and text:
|
|
119
|
+
if text.startswith('\\\\?\\') and len(text) >= 6 and text[5] == ':':
|
|
120
|
+
text = text[4:]
|
|
121
|
+
m = _MSYS_PATH_RE.fullmatch(text)
|
|
122
|
+
if m:
|
|
123
|
+
rest = m.group(2) or ''
|
|
124
|
+
return f'{m.group(1).upper()}:/{rest}'
|
|
125
|
+
return text
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""The `forge setup` answers that have no other home (#162), in ${XDG_CONFIG_HOME:-~/.config}/forge/setup.json.
|
|
3
|
+
|
|
4
|
+
Models, the review threshold, brief, summaries, retro and storage live where they always did
|
|
5
|
+
(decide.json's default profile and `features`), and a repository's memory choice lives in its git
|
|
6
|
+
config (`forge.memory`). This file keeps the rest: what the skill asks at each run (forge-ui,
|
|
7
|
+
`--file-issues`, `--sweep`, `--reviewer-session`), the update check, whether to offer Ripwire, and
|
|
8
|
+
when setup last ran. A missing or unreadable file means every default below.
|
|
9
|
+
|
|
10
|
+
forge_prefs.py get KEY the saved value of KEY, or its default
|
|
11
|
+
forge_prefs.py done exit 0 when setup has run on this machine, 1 when not
|
|
12
|
+
|
|
13
|
+
Standard library only.
|
|
14
|
+
"""
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
import json
|
|
18
|
+
import os
|
|
19
|
+
import sys
|
|
20
|
+
import tempfile
|
|
21
|
+
from pathlib import Path
|
|
22
|
+
|
|
23
|
+
VERSION = 1
|
|
24
|
+
# key -> (allowed values, or None for free text checked by the caller; the default)
|
|
25
|
+
PREFS = {
|
|
26
|
+
'ui': (('ask', 'always', 'never'), 'ask'),
|
|
27
|
+
'ui_controls': (('on', 'off'), 'on'),
|
|
28
|
+
'file_issues': (('ask', 'auto', 'off'), 'ask'),
|
|
29
|
+
'sweep': (('off', 'P0', 'P1', 'P2', 'P3'), 'off'),
|
|
30
|
+
'reviewer_session': (None, 'off'), # off, on, or a share between 0 and 1
|
|
31
|
+
'update_check': (('on', 'off'), 'on'),
|
|
32
|
+
'ripwire': (('ask', 'install', 'never'), 'ask'),
|
|
33
|
+
'decide': (('off', 'on'), 'off'),
|
|
34
|
+
'models_base': (None, ''), # what the `setup` profile was built from
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def config_dir() -> Path:
|
|
39
|
+
value = os.environ.get('XDG_CONFIG_HOME') or ''
|
|
40
|
+
base = Path(value).expanduser() if value else None
|
|
41
|
+
if base is None or not base.is_absolute():
|
|
42
|
+
base = Path.home() / '.config'
|
|
43
|
+
return base / 'forge'
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def path() -> Path:
|
|
47
|
+
return config_dir() / 'setup.json'
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def load() -> dict:
|
|
51
|
+
"""The whole file: {version, done_at, prefs}; {} when missing or not a JSON object."""
|
|
52
|
+
try:
|
|
53
|
+
data = json.loads(path().read_text(encoding='utf-8'))
|
|
54
|
+
except (OSError, ValueError):
|
|
55
|
+
return {}
|
|
56
|
+
return data if isinstance(data, dict) else {}
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def valid(key: str, value) -> bool:
|
|
60
|
+
if key not in PREFS or not isinstance(value, str):
|
|
61
|
+
return False
|
|
62
|
+
allowed, _default = PREFS[key]
|
|
63
|
+
if allowed is not None:
|
|
64
|
+
return value in allowed
|
|
65
|
+
if key == 'reviewer_session':
|
|
66
|
+
return value in ('off', 'on') or share(value)
|
|
67
|
+
return True
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def share(value) -> bool:
|
|
71
|
+
try:
|
|
72
|
+
number = float(value)
|
|
73
|
+
except (TypeError, ValueError):
|
|
74
|
+
return False
|
|
75
|
+
return 0 < number <= 1
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def prefs(data: dict | None = None) -> dict:
|
|
79
|
+
"""Every pref: the saved value when it is valid, else its default."""
|
|
80
|
+
data = load() if data is None else data
|
|
81
|
+
saved = data.get('prefs') if isinstance(data.get('prefs'), dict) else {}
|
|
82
|
+
return {key: saved[key] if valid(key, saved.get(key)) else default for key, (_a, default) in PREFS.items()}
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def get(key: str) -> str:
|
|
86
|
+
return prefs()[key]
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def done(data: dict | None = None) -> bool:
|
|
90
|
+
data = load() if data is None else data
|
|
91
|
+
return bool(data.get('done_at'))
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def save(values: dict, mark_done: bool = True) -> Path:
|
|
95
|
+
"""Merge `values` (already valid) into the file, atomically; mark_done records this run."""
|
|
96
|
+
data = load()
|
|
97
|
+
stored = data.get('prefs') if isinstance(data.get('prefs'), dict) else {}
|
|
98
|
+
stored.update(values)
|
|
99
|
+
data['prefs'] = stored
|
|
100
|
+
data['version'] = VERSION
|
|
101
|
+
if mark_done:
|
|
102
|
+
import time
|
|
103
|
+
data['done_at'] = time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime())
|
|
104
|
+
target = path()
|
|
105
|
+
target.parent.mkdir(parents=True, exist_ok=True)
|
|
106
|
+
fd, tmp = tempfile.mkstemp(prefix='.setup.', suffix='.json', dir=str(target.parent))
|
|
107
|
+
try:
|
|
108
|
+
with os.fdopen(fd, 'w', encoding='utf-8') as out:
|
|
109
|
+
json.dump(data, out, indent=2, sort_keys=True)
|
|
110
|
+
out.write('\n')
|
|
111
|
+
os.replace(tmp, target)
|
|
112
|
+
except BaseException:
|
|
113
|
+
try:
|
|
114
|
+
os.unlink(tmp)
|
|
115
|
+
except OSError:
|
|
116
|
+
pass
|
|
117
|
+
raise
|
|
118
|
+
return target
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def update_check_off() -> bool:
|
|
122
|
+
"""`forge setup` turned the update check off (FORGE_UPDATE_CHECK=off still works on its own)."""
|
|
123
|
+
return get('update_check') == 'off'
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def main(argv=None) -> int:
|
|
127
|
+
argv = list(sys.argv[1:] if argv is None else argv)
|
|
128
|
+
if argv[:1] == ['get'] and len(argv) == 2 and argv[1] in PREFS:
|
|
129
|
+
print(get(argv[1]))
|
|
130
|
+
return 0
|
|
131
|
+
if argv == ['done']:
|
|
132
|
+
return 0 if done() else 1
|
|
133
|
+
print(__doc__.strip(), file=sys.stderr)
|
|
134
|
+
return 2
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
if __name__ == '__main__':
|
|
138
|
+
sys.exit(main())
|