@giamme/forge 0.12.0 → 0.13.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 +77 -0
- package/README.md +1 -1
- package/SKILL.md +31 -12
- package/VERSION +1 -1
- package/docs/add-ons.md +11 -6
- package/docs/artifacts.md +18 -6
- package/docs/commands.md +189 -17
- package/docs/decomposed-runs.md +13 -5
- package/docs/forge-ui.md +34 -4
- package/docs/memory.md +2 -1
- package/docs/models.md +4 -2
- package/docs/reviews.md +81 -19
- package/docs/troubleshooting.md +3 -1
- package/forge +17 -1
- package/package.json +1 -1
- package/references/dataset.md +40 -14
- package/references/decision-models.md +759 -0
- package/references/decompose.md +197 -28
- package/references/harnesses.md +10 -3
- package/references/planning.md +8 -0
- package/references/solo.md +13 -3
- package/references/ui.md +11 -0
- package/scripts/forge-artifact.sh +30 -4
- package/scripts/forge-config.py +238 -29
- package/scripts/forge-contract.py +127 -58
- package/scripts/forge-control.py +40 -9
- package/scripts/forge-decide.py +6 -0
- package/scripts/forge-dispatch.sh +47 -15
- package/scripts/forge-fail-first.py +2 -2
- package/scripts/forge-gate-addressed.sh +40 -0
- package/scripts/forge-gate-message.sh +64 -0
- package/scripts/forge-issues.py +368 -36
- package/scripts/forge-jev-options.sh +269 -42
- package/scripts/forge-lib-attribute.sh +447 -0
- package/scripts/forge-lib-gates.sh +32 -0
- package/scripts/forge-lib-plans.sh +17 -6
- package/scripts/forge-lib-review.sh +24 -19
- package/scripts/forge-lib-task.sh +219 -39
- package/scripts/forge-lib-verify.sh +45 -8
- package/scripts/forge-memory.sh +3 -3
- package/scripts/forge-parallel-options.sh +44 -5
- package/scripts/forge-parallel.sh +503 -304
- package/scripts/forge-plan-check.py +35 -1
- package/scripts/forge-pre-review.py +437 -0
- package/scripts/forge-prompt.py +25 -5
- package/scripts/forge-route.py +2 -2
- package/scripts/forge-runtime.py +55 -1
- package/scripts/forge-schedule.py +70 -9
- package/scripts/forge-shadow.py +2 -2
- package/scripts/forge-solo.sh +41 -10
- package/scripts/forge-submodules.py +389 -0
- package/scripts/forge-sweep.py +542 -0
- package/scripts/forge_dataset/cli.py +12 -6
- package/scripts/forge_dataset/export.py +55 -45
- package/scripts/forge_dataset/forecast.py +4 -1
- package/scripts/forge_dataset/harvest.py +33 -5
- package/scripts/{forge_jev/outcome.py → forge_dataset/states.py} +21 -7
- package/scripts/forge_decide/__init__.py +141 -0
- package/scripts/forge_decide/budget.py +149 -0
- package/scripts/forge_decide/cache.py +66 -0
- package/scripts/forge_decide/cli.py +953 -0
- package/scripts/forge_decide/doctor.py +221 -0
- package/scripts/forge_decide/label_addressed.py +75 -0
- package/scripts/forge_decide/label_attribution.py +62 -0
- package/scripts/forge_decide/label_coverage.py +81 -0
- package/scripts/forge_decide/label_message.py +38 -0
- package/scripts/forge_decide/label_prompt.py +139 -0
- package/scripts/forge_decide/labels.py +328 -0
- package/scripts/forge_decide/metrics.py +125 -0
- package/scripts/forge_decide/migrate.py +226 -0
- package/scripts/forge_decide/providers.py +292 -0
- package/scripts/forge_decide/replay.py +350 -0
- package/scripts/forge_decide/report.py +382 -0
- package/scripts/forge_decide/resolve.py +397 -0
- package/scripts/forge_decide/sites.py +377 -0
- package/scripts/forge_jev/__init__.py +202 -104
- package/scripts/forge_jev/addressed.py +171 -0
- package/scripts/forge_jev/attribution.py +198 -0
- package/scripts/forge_jev/cli.py +460 -382
- package/scripts/forge_jev/client.py +155 -77
- package/scripts/forge_jev/coupling.py +19 -87
- package/scripts/forge_jev/coverage.py +303 -0
- package/scripts/forge_jev/findings.py +219 -0
- package/scripts/forge_jev/gates.py +225 -27
- package/scripts/forge_jev/memory.py +65 -4
- package/scripts/forge_jev/message.py +134 -0
- package/scripts/forge_jev/plan_gates.py +294 -0
- package/scripts/forge_jev/questions.py +173 -313
- package/scripts/forge_jev/verify.py +130 -104
- package/ui/README.md +41 -10
- package/ui/docs/api.md +212 -44
- package/ui/forge_ui/checks.py +331 -0
- package/ui/forge_ui/control.py +60 -11
- package/ui/forge_ui/export.py +8 -3
- package/ui/forge_ui/models.py +1 -0
- package/ui/forge_ui/reader.py +436 -26
- package/ui/forge_ui/server.py +13 -0
- package/ui/forge_ui/static/app.js +15 -8
- package/ui/forge_ui/static/checksview.js +449 -0
- package/ui/forge_ui/static/controls.js +20 -13
- package/ui/forge_ui/static/convo.js +11 -2
- package/ui/forge_ui/static/findingsview.js +6 -4
- package/ui/forge_ui/static/index.html +1 -0
- package/ui/forge_ui/static/panel.js +105 -17
- package/ui/forge_ui/static/runmodel.js +40 -2
- package/ui/forge_ui/static/scene3d.js +2 -15
- package/ui/forge_ui/static/settings.js +336 -41
- package/ui/forge_ui/static/style.css +72 -7
- package/ui/forge_ui/transcripts.py +225 -54
- package/references/jev.md +0 -865
- package/scripts/forge_jev/backtest.py +0 -322
- package/scripts/forge_jev/corpus.py +0 -156
- package/scripts/forge_jev/features.py +0 -24
- package/scripts/forge_jev/predict.py +0 -204
- package/scripts/forge_jev/review.py +0 -73
- package/scripts/forge_jev/routing.py +0 -271
- package/scripts/forge_jev/subset.py +0 -123
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
"""The checks an agent ran, read from its transcript (transcripts.py): each test, type check, lint or build command
|
|
2
|
+
with its exit, how long it took and the counts it printed; the call it is running now; the commands its brief's
|
|
3
|
+
acceptance criteria name that it never ran; and the environment problems its failed commands met (Docker, a
|
|
4
|
+
sandbox's EPERM, a port in use, …), which forge-ui groups across a run's tasks.
|
|
5
|
+
|
|
6
|
+
Nothing here opens a file: it reads the events transcripts.transcript() answers and the brief's text.
|
|
7
|
+
"""
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import re
|
|
11
|
+
|
|
12
|
+
KINDS = ('test', 'typecheck', 'lint', 'build')
|
|
13
|
+
COMMAND_CAP = 1000 # characters of a command kept in a check
|
|
14
|
+
LINE_CAP = 240 # of an environment problem's line
|
|
15
|
+
TAIL_LINES = 6 # of a failed check's output, its last non-empty lines
|
|
16
|
+
_ANSI = re.compile(r'\x1b\[[0-9;?]*[ -/]*[@-~]')
|
|
17
|
+
|
|
18
|
+
# ---------- what a command is ----------
|
|
19
|
+
|
|
20
|
+
_SPLIT = re.compile(r'\s*(?:&&|\|\||;|\||\n)\s*')
|
|
21
|
+
_WRAPPED = re.compile(r'''^(?:/\S+/)?(?:ba|z)?sh\s+-l?c\s+(['"])(.*)\1$''', re.S)
|
|
22
|
+
_PREFIX = re.compile(r'''^(?:[A-Za-z_][A-Za-z0-9_]*=(?:"[^"]*"|'[^']*'|\S*)\s+|env\s+|command\s+|exec\s+|time\s+|nice\s+(?:-n\s*-?\d+\s+)?
|
|
23
|
+
|timeout\s+(?:-\S+\s+)*\d+(?:\.\d+)?[smhd]?\s+|gtimeout\s+(?:-\S+\s+)*\d+[smhd]?\s+|xvfb-run\s+(?:-\S+\s+)*
|
|
24
|
+
|uv\s+run\s+(?:--?[A-Za-z-]+(?:[= ](?!-)\S+)?\s+)*|poetry\s+run\s+|pipenv\s+run\s+|hatch\s+run\s+|pdm\s+run\s+|rye\s+run\s+
|
|
25
|
+
|npx\s+(?:--yes\s+|-y\s+)?|pnpm\s+(?:exec|dlx)\s+|yarn\s+dlx\s+|bunx\s+|bundle\s+exec\s+|dotenv\s+(?:-\S+\s+)*--\s+)''', re.X)
|
|
26
|
+
_PY = r'(?:python(?:\d+(?:\.\d+)?)?|py)'
|
|
27
|
+
_PKG = r'(?:npm|pnpm|yarn|bun)'
|
|
28
|
+
# (kind, pattern), tried in this order on each part of a command
|
|
29
|
+
_PATTERNS = tuple((kind, re.compile(pattern)) for kind, pattern in (
|
|
30
|
+
('test', _PY + r'\s+-m\s+(?:pytest|unittest|nose2?|tox|nox|green)\b'),
|
|
31
|
+
('test', r'(?:pytest|py\.test|tox|nox|nose2?|ward)\b'),
|
|
32
|
+
('test', _PY + r'\s+(?:-\S+\s+)*(?:\S*/)?(?:test_\S*|\S*_tests?|run_?tests|runtests|tests)\.py\b'),
|
|
33
|
+
('test', _PKG + r'\s+(?:run(?:-script)?\s+)?(?:test|tests|t)(?:[:\-]\S*)?(?:\s|$)'),
|
|
34
|
+
('test', r'node\s+(?:--\S+\s+)*--test\b'),
|
|
35
|
+
('test', r'(?:jest|vitest|mocha|ava|tap|jasmine|karma|cypress\s+run|playwright\s+test|deno\s+test|bun\s+test)\b'),
|
|
36
|
+
('test', r'go\s+test\b|cargo\s+(?:test|nextest)\b|(?:make|just|task)\s+(?:-\S+\s+)*(?:test|tests|check|test-\S+|check-\S+)\b'),
|
|
37
|
+
('test', r'(?:\./)?(?:\S*/)?(?:test|tests|check|run-tests|run_tests)\.sh\b|(?:ba|z)?sh\s+(?:\S*/)?\S*(?:test|check)\S*\.sh\b'),
|
|
38
|
+
('test', r'(?:rspec|rake\s+test|phpunit|vendor/bin/phpunit|dotnet\s+test|mvn\s+(?:-\S+\s+)*(?:test|verify)\b|'
|
|
39
|
+
r'(?:\./)?gradlew?\s+(?:-\S+\s+)*(?:test|check)\b|swift\s+test|ctest|mix\s+test|stack\s+test|cabal\s+test)'),
|
|
40
|
+
('typecheck', r'(?:tsc|vue-tsc|mypy|dmypy|pyright|basedpyright|pyre|pytype|flow)\b|' + _PY + r'\s+-m\s+(?:mypy|pyright|py_compile|compileall)\b'),
|
|
41
|
+
('typecheck', _PKG + r'\s+(?:run\s+)?(?:typecheck|type-check|types|tsc|check-types|check:types)\b'),
|
|
42
|
+
('typecheck', r'cargo\s+check\b|go\s+vet\b|node\s+--check\b|(?:ba|z)?sh\s+-n\b'),
|
|
43
|
+
('lint', r'(?:eslint|ruff|flake8|pylint|pycodestyle|pyflakes|golangci-lint|shellcheck|stylelint|biome|rubocop|hadolint|'
|
|
44
|
+
r'markdownlint|yamllint|actionlint|oxlint|swiftlint|ktlint|tflint|deno\s+lint|cargo\s+clippy)\b'),
|
|
45
|
+
('lint', _PY + r'\s+-m\s+(?:ruff|flake8|pylint|pycodestyle)\b|' + _PKG + r'\s+(?:run\s+)?lint\S*'),
|
|
46
|
+
('lint', r'(?:prettier|black|isort|gofmt|rustfmt|cargo\s+fmt|ruff\s+format)\b.*(?:--check|--diff|\s-l\b|\s-d\b)'),
|
|
47
|
+
('build', _PKG + r'\s+(?:run\s+)?build\S*|(?:cargo|go|swift|dotnet|zig)\s+build\b|(?:\./)?gradlew?\s+(?:-\S+\s+)*build\b|'
|
|
48
|
+
r'mvn\s+(?:-\S+\s+)*(?:package|install|compile)\b|(?:vite|webpack|next|tsup|esbuild|rollup|parcel)\s+build\b|'
|
|
49
|
+
r'make(?:\s+-j\s*\d*)?(?:\s+(?:all|build))?$|docker\s+(?:compose\s+)?build\b'),
|
|
50
|
+
))
|
|
51
|
+
# programs that only read: a failed one says nothing about the environment
|
|
52
|
+
_READERS = frozenset(('rg', 'grep', 'egrep', 'fgrep', 'cat', 'sed', 'awk', 'head', 'tail', 'less', 'more', 'ls', 'find', 'fd',
|
|
53
|
+
'wc', 'nl', 'file', 'stat', 'tree', 'jq', 'diff', 'cmp', 'echo', 'printf', 'test', '[', 'which', 'type',
|
|
54
|
+
'git', 'pwd', 'cd', 'true', 'false', 'basename', 'dirname', 'realpath', 'readlink', 'sort', 'uniq', 'cut'))
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def parts(command):
|
|
58
|
+
"""The commands a shell line runs, each without its env assignments and wrappers (`timeout 600`, `uv run`,
|
|
59
|
+
`npx`, …); `cd` steps are left out."""
|
|
60
|
+
out = []
|
|
61
|
+
for part in _SPLIT.split(command or ''):
|
|
62
|
+
part = part.strip().strip('()').strip()
|
|
63
|
+
inner = _WRAPPED.match(part)
|
|
64
|
+
if inner:
|
|
65
|
+
out.extend(parts(inner.group(2)))
|
|
66
|
+
continue
|
|
67
|
+
while True:
|
|
68
|
+
m = _PREFIX.match(part)
|
|
69
|
+
if not m or not m.group(0):
|
|
70
|
+
break
|
|
71
|
+
part = part[m.end():]
|
|
72
|
+
if part and not re.match(r'(?:cd|pushd|popd|export|set|source|\.)\b', part):
|
|
73
|
+
out.append(part)
|
|
74
|
+
return out
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def classify(command):
|
|
78
|
+
"""test, typecheck, lint or build when some part of the command is one (the first of those, in that order),
|
|
79
|
+
else None."""
|
|
80
|
+
found = set()
|
|
81
|
+
for part in parts(command):
|
|
82
|
+
for kind, pattern in _PATTERNS:
|
|
83
|
+
if pattern.match(part):
|
|
84
|
+
found.add(kind)
|
|
85
|
+
break
|
|
86
|
+
return next((kind for kind in KINDS if kind in found), None)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def _readonly(command):
|
|
90
|
+
programs = [part.split()[0].rsplit('/', 1)[-1] for part in parts(command) if part.split()]
|
|
91
|
+
return bool(programs) and all(program in _READERS for program in programs)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
# ---------- what it printed ----------
|
|
95
|
+
|
|
96
|
+
_WORDS = {'passed': 'passed', 'passing': 'passed', 'pass': 'passed', 'xpassed': 'passed', 'ok': None,
|
|
97
|
+
'failed': 'failed', 'failing': 'failed', 'fail': 'failed', 'error': 'failed', 'errors': 'failed',
|
|
98
|
+
'skipped': 'skipped', 'pending': 'skipped', 'todo': 'skipped', 'xfailed': 'skipped', 'skip': 'skipped'}
|
|
99
|
+
_COUNTED = re.compile(r'(\d+)\s+(passed|failed|skipped|errors?|xfailed|xpassed|pending|todo)\b')
|
|
100
|
+
_SUMMARY = re.compile(r'^.*\b\d+\s+(?:passed|failed)\b.*$', re.M)
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def _ints(**values):
|
|
104
|
+
return {key: int(value) for key, value in values.items() if value is not None}
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def counts(output, kind=None):
|
|
108
|
+
"""What a check's output says it found: {passed, failed, skipped} for tests, {errors, warnings} for type
|
|
109
|
+
checks and linters, or None. Read from the end of the output, where the summaries are."""
|
|
110
|
+
text = _ANSI.sub('', output or '')[-8000:]
|
|
111
|
+
if not text.strip():
|
|
112
|
+
return None
|
|
113
|
+
if kind in ('lint', 'typecheck'):
|
|
114
|
+
return _problems(text) or _tests(text)
|
|
115
|
+
return _tests(text) or _problems(text)
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def _tests(text):
|
|
119
|
+
# cargo test: one line per test binary, summed
|
|
120
|
+
rows = re.findall(r'test result: \w+\. (\d+) passed; (\d+) failed; (\d+) ignored', text)
|
|
121
|
+
if rows:
|
|
122
|
+
return {key: sum(int(row[i]) for row in rows) for i, key in enumerate(('passed', 'failed', 'skipped'))}
|
|
123
|
+
# forge's tests/run_tests.py: "1639 tests in 312 classes: …; 75 skipped", then "OK" or "FAILED: 2 failures, 1 errors in …"
|
|
124
|
+
m = None
|
|
125
|
+
for m in re.finditer(r'^(\d+) tests in \d+ classes: .*; (\d+) skipped\s*\n(?:FAILED: (\d+) failures, (\d+) errors|OK)', text, re.M):
|
|
126
|
+
pass
|
|
127
|
+
if m:
|
|
128
|
+
total, skipped = int(m.group(1)), int(m.group(2))
|
|
129
|
+
failed = int(m.group(3) or 0) + int(m.group(4) or 0)
|
|
130
|
+
return {'passed': max(0, total - failed - skipped), 'failed': failed, 'skipped': skipped}
|
|
131
|
+
# unittest: "Ran 12 tests in 0.3s" then "OK (skipped=2)" or "FAILED (failures=1, errors=2)"
|
|
132
|
+
ran = list(re.finditer(r'^Ran (\d+) tests? in [\d.]+s\s*\n+\s*(OK|FAILED)\b(?: \(([^)]*)\))?', text, re.M))
|
|
133
|
+
if ran:
|
|
134
|
+
m = ran[-1]
|
|
135
|
+
detail = {key: int(value) for key, value in re.findall(r'(\w+)=(\d+)', m.group(3) or '')}
|
|
136
|
+
failed = detail.get('failures', 0) + detail.get('errors', 0) + detail.get('unexpected_successes', 0)
|
|
137
|
+
skipped = detail.get('skipped', 0) + detail.get('expected_failures', 0)
|
|
138
|
+
return {'passed': max(0, int(m.group(1)) - failed - skipped), 'failed': failed, 'skipped': skipped}
|
|
139
|
+
# node --test: "# pass 5", "# fail 1" (tap) or "ℹ pass 5" (spec)
|
|
140
|
+
node = dict(re.findall(r'^[#ℹ]\s+(pass|fail|skipped|todo|cancelled)\s+(\d+)\s*$', text, re.M))
|
|
141
|
+
if 'pass' in node:
|
|
142
|
+
n = lambda key: int(node.get(key, 0))
|
|
143
|
+
return {'passed': n('pass'), 'failed': n('fail') + n('cancelled'), 'skipped': n('skipped') + n('todo')}
|
|
144
|
+
# mocha: "5 passing (20ms)", "1 failing", "2 pending", each on its own line
|
|
145
|
+
mocha = dict((word, int(n)) for n, word in re.findall(r'^\s*(\d+) (passing|failing|pending)\b', text, re.M))
|
|
146
|
+
if 'passing' in mocha or 'failing' in mocha:
|
|
147
|
+
return {'passed': mocha.get('passing', 0), 'failed': mocha.get('failing', 0), 'skipped': mocha.get('pending', 0)}
|
|
148
|
+
# playwright: one line per outcome, the count first (" 1 failed", " 5 passed (10.2s)")
|
|
149
|
+
found = {}
|
|
150
|
+
for n, word in re.findall(r'^\s*(\d+) (passed|failed|flaky|skipped|did not run|interrupted)\b', '\n'.join(text.splitlines()[-40:]), re.M):
|
|
151
|
+
key = {'flaky': 'passed', 'did not run': 'skipped', 'interrupted': 'failed'}.get(word, word)
|
|
152
|
+
found[key] = found.get(key, 0) + int(n)
|
|
153
|
+
if found:
|
|
154
|
+
return {key: found.get(key, 0) for key in ('passed', 'failed', 'skipped')}
|
|
155
|
+
# pytest, jest ("Tests: 1 failed, 5 passed, 6 total"), vitest ("Tests 1 failed | 5 passed (6)"): the last line that
|
|
156
|
+
# counts passes or failures
|
|
157
|
+
lines = _SUMMARY.findall(text)
|
|
158
|
+
if lines:
|
|
159
|
+
found = {}
|
|
160
|
+
for n, word in _COUNTED.findall(lines[-1]):
|
|
161
|
+
key = _WORDS.get(word)
|
|
162
|
+
if key:
|
|
163
|
+
found[key] = found.get(key, 0) + int(n)
|
|
164
|
+
if found:
|
|
165
|
+
return {key: found.get(key, 0) for key in ('passed', 'failed', 'skipped')}
|
|
166
|
+
# go test: one line per test with -v, else one per package
|
|
167
|
+
go = re.findall(r'^\s*--- (PASS|FAIL|SKIP):', text, re.M)
|
|
168
|
+
if go:
|
|
169
|
+
return {'passed': go.count('PASS'), 'failed': go.count('FAIL'), 'skipped': go.count('SKIP')}
|
|
170
|
+
return None
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
def _problems(text):
|
|
174
|
+
m = None
|
|
175
|
+
for m in re.finditer(r'✖ (\d+) problems? \((\d+) errors?, (\d+) warnings?\)', text): # eslint
|
|
176
|
+
pass
|
|
177
|
+
if m:
|
|
178
|
+
return _ints(errors=m.group(2), warnings=m.group(3))
|
|
179
|
+
m = re.search(r'(\d+) errors?, (\d+) warnings?, \d+ (?:informations|notes)\s*$', text, re.M) # pyright
|
|
180
|
+
if m:
|
|
181
|
+
return _ints(errors=m.group(1), warnings=m.group(2))
|
|
182
|
+
found = re.findall(r'^Found (\d+) errors?\b', text, re.M) # tsc, mypy, ruff
|
|
183
|
+
if found:
|
|
184
|
+
return {'errors': int(found[-1])}
|
|
185
|
+
if re.search(r'^(?:Success: no issues found|All checks passed!|0 errors, 0 warnings)', text, re.M):
|
|
186
|
+
return {'errors': 0}
|
|
187
|
+
return None
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
def _tail(output):
|
|
191
|
+
lines = [line.rstrip() for line in _ANSI.sub('', output or '').splitlines() if line.strip()]
|
|
192
|
+
return '\n'.join(lines[-TAIL_LINES:]) or None
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
# ---------- environment problems ----------
|
|
196
|
+
|
|
197
|
+
# (id, label, pattern), in the order a banner lists them
|
|
198
|
+
ENVIRONMENT = tuple((key, label, re.compile(pattern, re.I | re.M)) for key, label, pattern in (
|
|
199
|
+
('docker-daemon', 'Docker is not running', r'Cannot connect to the Docker daemon|Is the docker daemon running|'
|
|
200
|
+
r'docker daemon is not running|error during connect:.*docker'),
|
|
201
|
+
('docker-pools', 'Docker ran out of network address pools', r'all predefined address pools have been fully subnetted|'
|
|
202
|
+
r'could not find an available, non-overlapping IPv4 address pool'),
|
|
203
|
+
('container', 'A container is missing or its name is taken', r'No such container|container name "[^"]*" is already in use|'
|
|
204
|
+
r'Conflict\. The container name'),
|
|
205
|
+
('port', 'A port is already in use', r'EADDRINUSE|address already in use|port is already allocated'),
|
|
206
|
+
('sandbox', 'The sandbox refused an operation (EPERM)', r'\bEPERM\b|Operation not permitted|PermissionError: \[Errno 1\]'),
|
|
207
|
+
('refused', 'A local service refused the connection', r'ECONNREFUSED|Connection refused|could not connect to server'),
|
|
208
|
+
('network', 'No network or DNS', r'Could not resolve host|getaddrinfo (?:ENOTFOUND|EAI_AGAIN)|Temporary failure in name '
|
|
209
|
+
r'resolution|Network is unreachable|ENETUNREACH|nodename nor servname provided'),
|
|
210
|
+
('disk', 'The disk is full', r'ENOSPC|No space left on device'),
|
|
211
|
+
('missing-tool', 'A command is not installed', r'command not found|^\S+: not found$|is not recognized as an internal or external command'),
|
|
212
|
+
))
|
|
213
|
+
LABELS = {key: label for key, label, _ in ENVIRONMENT}
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
def environment(output):
|
|
217
|
+
"""[(id, the first line that shows it)] for each environment problem in a failed command's output."""
|
|
218
|
+
text = _ANSI.sub('', output or '')
|
|
219
|
+
found = []
|
|
220
|
+
for key, _, pattern in ENVIRONMENT:
|
|
221
|
+
m = pattern.search(text)
|
|
222
|
+
if m:
|
|
223
|
+
start = text.rfind('\n', 0, m.start()) + 1
|
|
224
|
+
end = text.find('\n', m.end())
|
|
225
|
+
line = text[start:end if end >= 0 else len(text)].strip()
|
|
226
|
+
found.append((key, line[:LINE_CAP]))
|
|
227
|
+
return found
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
# ---------- one transcript ----------
|
|
231
|
+
|
|
232
|
+
def _failed(ev):
|
|
233
|
+
return bool(ev.get('error')) or ev.get('exit') not in (None, 0)
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
def _command(text):
|
|
237
|
+
text = text or ''
|
|
238
|
+
return text if len(text) <= COMMAND_CAP else text[:COMMAND_CAP] + '…'
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
def analyze(events):
|
|
242
|
+
"""{checks, call, environment} of one transcript's events.
|
|
243
|
+
|
|
244
|
+
checks: [{index, command, kind, exit, failed, running, started, ended, duration_s, counts, tail}], in order; index
|
|
245
|
+
is the event's place in the transcript (the conversation view's `ev-<index>`).
|
|
246
|
+
call: the call not answered yet ({index, kind: command|tool, command, tool, check, started}), the newest when
|
|
247
|
+
several run at once, or None.
|
|
248
|
+
environment: [{index, command, problem, label, line}] for each problem a failed command met.
|
|
249
|
+
"""
|
|
250
|
+
checks, problems, call = [], [], None
|
|
251
|
+
for index, ev in enumerate(events):
|
|
252
|
+
kind = ev.get('kind')
|
|
253
|
+
if kind not in ('command', 'tool', 'edit'):
|
|
254
|
+
continue
|
|
255
|
+
if ev.get('running'):
|
|
256
|
+
call = dict(index=index, kind=kind, command=_command(ev.get('command')) if kind == 'command' else None,
|
|
257
|
+
tool=ev.get('tool') or None, started=ev.get('t'),
|
|
258
|
+
check=classify(ev.get('command')) if kind == 'command' else None)
|
|
259
|
+
if kind != 'command':
|
|
260
|
+
continue
|
|
261
|
+
command, check = ev.get('command') or '', classify(ev.get('command'))
|
|
262
|
+
failed = not ev.get('running') and _failed(ev)
|
|
263
|
+
if check:
|
|
264
|
+
started, ended = ev.get('t'), ev.get('ended')
|
|
265
|
+
checks.append(dict(index=index, command=_command(command), kind=check, exit=ev.get('exit'), failed=failed,
|
|
266
|
+
running=bool(ev.get('running')), started=started, ended=ended,
|
|
267
|
+
duration_s=round(ended - started, 3) if started is not None and ended is not None else None,
|
|
268
|
+
counts=counts(ev.get('output'), check), tail=_tail(ev.get('output')) if failed else None))
|
|
269
|
+
if failed and not _readonly(command):
|
|
270
|
+
for key, line in environment(ev.get('output')):
|
|
271
|
+
problems.append(dict(index=index, command=_command(command), problem=key, label=LABELS[key], line=line))
|
|
272
|
+
return dict(checks=checks, call=call, environment=problems)
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
# ---------- the brief's acceptance criteria ----------
|
|
276
|
+
|
|
277
|
+
_HEADING = re.compile(r'^(#{1,6})\s+acceptance criteria\s*:?\s*$', re.I)
|
|
278
|
+
_ANY_HEADING = re.compile(r'^(#{1,6})\s')
|
|
279
|
+
_FENCE = re.compile(r'^\s*(```|~~~)')
|
|
280
|
+
_CODE = re.compile(r'(`+)(.+?)\1')
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
def criteria(brief):
|
|
284
|
+
"""The check commands an `## Acceptance criteria` section of a brief names: in `code` spans or in its fenced
|
|
285
|
+
blocks, each once, in order: [{command, kind}]."""
|
|
286
|
+
found, seen, level, fenced = [], set(), None, False
|
|
287
|
+
for line in (brief or '').splitlines():
|
|
288
|
+
if _FENCE.match(line):
|
|
289
|
+
fenced = not fenced
|
|
290
|
+
continue
|
|
291
|
+
heading = None if fenced else _ANY_HEADING.match(line)
|
|
292
|
+
if heading and level is not None and len(heading.group(1)) <= level:
|
|
293
|
+
level = None
|
|
294
|
+
if not fenced and _HEADING.match(line):
|
|
295
|
+
level = len(_HEADING.match(line).group(1))
|
|
296
|
+
continue
|
|
297
|
+
if level is None:
|
|
298
|
+
continue
|
|
299
|
+
candidates = [line.strip().lstrip('$ ').strip()] if fenced else [m.group(2).strip() for m in _CODE.finditer(line)]
|
|
300
|
+
for text in candidates:
|
|
301
|
+
kind = classify(text)
|
|
302
|
+
if kind and text not in seen:
|
|
303
|
+
seen.add(text)
|
|
304
|
+
found.append(dict(command=text, kind=kind))
|
|
305
|
+
return found
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
def _tokens(command):
|
|
309
|
+
out = []
|
|
310
|
+
for part in parts(command):
|
|
311
|
+
out.extend(re.sub(r'^python(?:\d+(?:\.\d+)?)?$', 'python', word.strip('\'"')) for word in part.split())
|
|
312
|
+
return out
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
def coverage(wanted, ran):
|
|
316
|
+
"""Each wanted check against the commands that ran: `ran` when one has every word of it, `similar` when one is
|
|
317
|
+
the same kind of check by the same program (the whole suite where one module was asked, say), else `missing`.
|
|
318
|
+
ran = [(command, info)]; the matching run's info rides along as `by`."""
|
|
319
|
+
out = []
|
|
320
|
+
runs = [(set(_tokens(command)), (_tokens(command) or [None])[0], classify(command), info) for command, info in ran]
|
|
321
|
+
for item in wanted:
|
|
322
|
+
words = _tokens(item['command'])
|
|
323
|
+
status, by = 'missing', None
|
|
324
|
+
for tokens, program, kind, info in runs:
|
|
325
|
+
if words and set(words) <= tokens:
|
|
326
|
+
status, by = 'ran', info
|
|
327
|
+
break
|
|
328
|
+
if status == 'missing' and words and program == words[0] and kind == item['kind']:
|
|
329
|
+
status, by = 'similar', info
|
|
330
|
+
out.append(dict(item, status=status, by=by))
|
|
331
|
+
return out
|
package/ui/forge_ui/control.py
CHANGED
|
@@ -29,9 +29,21 @@ MAX_LABELS = 5
|
|
|
29
29
|
MAX_LABEL = 50
|
|
30
30
|
MAX_REASON = 500
|
|
31
31
|
MAX_CONFIG_VALUE = 4096
|
|
32
|
+
MAX_DECIDE_VALUE = 256
|
|
32
33
|
FP_RE = re.compile(r'[0-9a-f]{12}')
|
|
33
|
-
|
|
34
|
+
# Mirrored from forge_decide.GATES and MODES. The ui tests do not put scripts/ on the path, so this
|
|
35
|
+
# module does not import forge_decide; ConfigTests.test_decide_names_match_forge_decide keeps them equal.
|
|
36
|
+
DECIDE_GATES = ('drift', 'forward', 'prompt', 'memory-curate', 'memory-slice', 'memory-stale',
|
|
37
|
+
'verify-discover', 'coverage', 'retry-addressed', 'dwarf-message', 'attribution',
|
|
38
|
+
'findings')
|
|
39
|
+
DECIDE_MODES = ('off', 'shadow', 'on')
|
|
40
|
+
REPO_CONFIG_KEYS = ('repo.verify', 'repo.setup', 'repo.verify-subset')
|
|
41
|
+
CONFIG_KEYS = REPO_CONFIG_KEYS
|
|
42
|
+
_DECIDE_KEY = re.compile(r'^decide\.gate\.([A-Za-z0-9_-]+?)(?:\.(provider|model))?$')
|
|
34
43
|
DETAIL_MAX = 300
|
|
44
|
+
# A refusal (exit 3) is forge's own message, kept whole: what was refused and why, then what to run
|
|
45
|
+
# instead (`forge decide replay ...`, `--force`), with a provider and model of up to 256 characters each.
|
|
46
|
+
REFUSAL_MAX = 2000
|
|
35
47
|
TIMEOUT_DETAIL = 'the operation may have partly completed; reload to see the current state'
|
|
36
48
|
|
|
37
49
|
# forge control's exit codes (scripts/forge-control.py) and the HTTP status each one gets.
|
|
@@ -151,11 +163,19 @@ def _stdout_object(text):
|
|
|
151
163
|
return value if isinstance(value, dict) else None
|
|
152
164
|
|
|
153
165
|
|
|
166
|
+
def _lines(text):
|
|
167
|
+
return [line.strip() for line in text.splitlines() if line.strip()]
|
|
168
|
+
|
|
169
|
+
|
|
154
170
|
def _last_line(text):
|
|
155
|
-
lines =
|
|
171
|
+
lines = _lines(text)
|
|
156
172
|
return lines[-1][:DETAIL_MAX] if lines else ''
|
|
157
173
|
|
|
158
174
|
|
|
175
|
+
def _message(text):
|
|
176
|
+
return '\n'.join(_lines(text))[:REFUSAL_MAX]
|
|
177
|
+
|
|
178
|
+
|
|
159
179
|
def map_exit(result):
|
|
160
180
|
"""(status, body) for a finished CliResult."""
|
|
161
181
|
if result.timed_out:
|
|
@@ -168,7 +188,8 @@ def map_exit(result):
|
|
|
168
188
|
return 502, {'error': 'bad gateway', 'detail': 'the forge CLI printed no JSON object'}
|
|
169
189
|
return 200, obj
|
|
170
190
|
status, error = _EXITS.get(result.code, (502, 'bad gateway'))
|
|
171
|
-
|
|
191
|
+
detail = _message(result.stderr) if result.code == 3 else _last_line(result.stderr)
|
|
192
|
+
body = {'error': error, 'detail': detail or f'the forge CLI exited {result.code}'}
|
|
172
193
|
if obj is not None:
|
|
173
194
|
body['result'] = obj
|
|
174
195
|
return status, body
|
|
@@ -511,20 +532,49 @@ def _config_get(ctx):
|
|
|
511
532
|
return ctx.call('config', 'show', '--repo', repo, '--json')
|
|
512
533
|
|
|
513
534
|
|
|
514
|
-
def
|
|
535
|
+
def _classify_config_key(key):
|
|
536
|
+
"""('repo'|'mode'|'provider'|'model', gate or None). BadBody when the key is not one of those shapes."""
|
|
537
|
+
if key == 'jev.enabled':
|
|
538
|
+
raise BadBody('jev.enabled is gone; set a gate with decide.gate.<gate>')
|
|
539
|
+
if key in REPO_CONFIG_KEYS:
|
|
540
|
+
return 'repo', None
|
|
541
|
+
if isinstance(key, str) and key.startswith('decide.'):
|
|
542
|
+
match = _DECIDE_KEY.fullmatch(key)
|
|
543
|
+
if match and match.group(1) in DECIDE_GATES:
|
|
544
|
+
return match.group(2) or 'mode', match.group(1)
|
|
545
|
+
if match:
|
|
546
|
+
raise BadBody('unknown gate %r; gates: %s' % (match.group(1), ', '.join(DECIDE_GATES)))
|
|
547
|
+
raise BadBody('key must be decide.gate.<gate>, decide.gate.<gate>.provider or decide.gate.<gate>.model')
|
|
548
|
+
raise BadBody('key must be one of ' + ', '.join(REPO_CONFIG_KEYS)
|
|
549
|
+
+ ', decide.gate.<gate>, decide.gate.<gate>.provider, decide.gate.<gate>.model')
|
|
550
|
+
|
|
551
|
+
|
|
552
|
+
def _decide_text(value):
|
|
553
|
+
"""A provider or model: one short line, so it cannot become an option on the decide CLI's argv."""
|
|
554
|
+
if (not isinstance(value, str) or not value or value != value.strip()
|
|
555
|
+
or len(value) > MAX_DECIDE_VALUE or value.startswith('-') or not _no_control_chars(value)):
|
|
556
|
+
raise BadBody('value must be short single-line text, not starting with "-"')
|
|
557
|
+
return value
|
|
558
|
+
|
|
559
|
+
|
|
560
|
+
def _config_value(key, body, kind):
|
|
515
561
|
if 'unset' in body:
|
|
516
562
|
if body['unset'] is not True or 'value' in body:
|
|
517
563
|
raise BadBody('give value, or unset: true, not both')
|
|
518
|
-
if
|
|
519
|
-
raise BadBody('
|
|
564
|
+
if kind != 'repo':
|
|
565
|
+
raise BadBody('set the mode to off')
|
|
520
566
|
return 'unset', None
|
|
521
567
|
value = body.get('value')
|
|
568
|
+
if kind == 'mode':
|
|
569
|
+
if value not in DECIDE_MODES:
|
|
570
|
+
raise BadBody('mode must be off, shadow or on')
|
|
571
|
+
return 'set', value
|
|
572
|
+
if kind in ('provider', 'model'):
|
|
573
|
+
return 'set', _decide_text(value)
|
|
522
574
|
if not isinstance(value, str) or not value.strip():
|
|
523
575
|
raise BadBody('value must be a non-empty string')
|
|
524
576
|
if len(value) > MAX_CONFIG_VALUE or value.startswith('-') or not _no_control_chars(value.replace('\n', ' ').replace('\t', ' ')):
|
|
525
577
|
raise BadBody('value is not an acceptable text')
|
|
526
|
-
if key == 'jev.enabled' and value not in ('true', 'false'):
|
|
527
|
-
raise BadBody('jev.enabled takes true or false')
|
|
528
578
|
if key == 'repo.verify-subset' and '{files}' not in value:
|
|
529
579
|
raise BadBody('repo.verify-subset must contain {files}')
|
|
530
580
|
return 'set', value
|
|
@@ -537,9 +587,8 @@ def _config_set(ctx):
|
|
|
537
587
|
try:
|
|
538
588
|
_check_fields(body, ('run', 'key', 'value', 'unset'))
|
|
539
589
|
key = body.get('key')
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
verb, value = _config_value(key, body)
|
|
590
|
+
kind, _gate = _classify_config_key(key)
|
|
591
|
+
verb, value = _config_value(key, body, kind)
|
|
543
592
|
except BadBody as exc:
|
|
544
593
|
return _invalid(str(exc))
|
|
545
594
|
repo, error = _config_run(ctx, body.get('run'))
|
package/ui/forge_ui/export.py
CHANGED
|
@@ -26,7 +26,7 @@ from forge_ui import __version__, reader, server
|
|
|
26
26
|
|
|
27
27
|
STATIC = server.STATIC_DIR
|
|
28
28
|
# what the exported page runs, in index.html's order; the cloud, the leaderboard and notifications need a server
|
|
29
|
-
SCRIPTS = ('theme.js', 'icons.js', 'datatable.js', 'shell.js', 'runmodel.js', 'cloudmodel.js', 'graph.js', 'gantt.js', 'verifyview.js', 'panel.js', 'diffview.js', 'convo.js', 'files.js', 'map3d.js',
|
|
29
|
+
SCRIPTS = ('theme.js', 'icons.js', 'datatable.js', 'shell.js', 'runmodel.js', 'cloudmodel.js', 'graph.js', 'gantt.js', 'verifyview.js', 'checksview.js', 'panel.js', 'diffview.js', 'convo.js', 'files.js', 'map3d.js',
|
|
30
30
|
'search.js', 'app.js')
|
|
31
31
|
MODULES = ('iso.js', 'cloud3d.js', 'findings3d.js', 'stagectl.js', 'scene3d.js') # bundled in dependency order
|
|
32
32
|
DIFF_CAP = 1 << 20 # one diff's JSON
|
|
@@ -37,7 +37,8 @@ _EXEC = re.compile(r'(?:task|dwarf|qa|solo|verification|parallel)-[0-9a-f]{32}')
|
|
|
37
37
|
# texts that can hold code, prompts or private notes: nulled unless texts=True
|
|
38
38
|
_TEXT_KEYS = frozenset(('prompt', 'last', 'request', 'log_tail', 'dwarf_tail', 'qa_tail', 'qa_last', 'qa_input',
|
|
39
39
|
'tasks_summary', 'known_issues', 'texts', 'text', 'planning_last', 'approach', 'retry_findings',
|
|
40
|
-
'dwarf_input', 'error', 'last_line', 'message', 'excerpt', 'tail', 'lines'
|
|
40
|
+
'dwarf_input', 'error', 'last_line', 'message', 'excerpt', 'tail', 'lines', 'call', 'split',
|
|
41
|
+
'needs_input'))
|
|
41
42
|
|
|
42
43
|
|
|
43
44
|
def _enc(value):
|
|
@@ -188,10 +189,14 @@ def build(catalog, key, texts=False, paths=False, now=None):
|
|
|
188
189
|
snap.add(url, cap=DIFF_CAP)
|
|
189
190
|
for name in reviews:
|
|
190
191
|
snap.add(f'{base}/final-reviews/{_enc(name)}/diff', cap=DIFF_CAP)
|
|
191
|
-
# what each dwarf and reviewer said and ran: its conversation is all text
|
|
192
|
+
# what each dwarf and reviewer said and ran: its conversation is all text, and so are the commands it ran
|
|
192
193
|
for name in names:
|
|
193
194
|
if name.startswith(('dwarf-', 'qa-')):
|
|
194
195
|
snap.add(f'{base}/executions/{name}/transcript', cap=TRANSCRIPT_CAP)
|
|
196
|
+
snap.add(f'{base}/executions/{name}/checks')
|
|
197
|
+
for task in tasks:
|
|
198
|
+
snap.add(f"{base}/tasks/{_enc(task['id'])}/checks")
|
|
199
|
+
snap.add(f'{base}/environment')
|
|
195
200
|
# the verification's log tails: its own, each lane's and each lane run's (line ranges stay out)
|
|
196
201
|
verification = run.get('verification') or {}
|
|
197
202
|
if verification:
|
package/ui/forge_ui/models.py
CHANGED
|
@@ -83,6 +83,7 @@ def _attempts(rows, execs, plan_spec):
|
|
|
83
83
|
verdict = reviews[-1]['verdict'] if reviews else None
|
|
84
84
|
result.append(dict(n=n, alias=model['alias'] if model else _alias(spec), spec=spec, source=source,
|
|
85
85
|
outcome=outcome, reason=reason, gate=outcome == 'pass' and verdict == 'FAIL',
|
|
86
|
+
gate_fail=outcome == 'fail' and verdict == 'PASS',
|
|
86
87
|
model_s=last['phases'].get('model') if last is not None else None,
|
|
87
88
|
duration_s=last['duration_s'] if last is not None else None,
|
|
88
89
|
tokens=dict(last['tokens']) if last is not None and last['tokens'] else None,
|