@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
package/scripts/forge-config.py
CHANGED
|
@@ -1,19 +1,29 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
2
|
"""forge config <command>: one view of every config source, and safe edits for the per-repo ones.
|
|
3
3
|
|
|
4
|
-
show [--repo DIR] [--json]
|
|
5
|
-
set <key> <value> --repo DIR [--json] repo.verify | repo.setup | repo.verify-subset |
|
|
6
|
-
unset <key> --repo DIR [--json] repo.verify | repo.setup | repo.verify-subset
|
|
7
|
-
|
|
8
|
-
A value of `-` reads stdin. repo.verify-subset must contain `{files}
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
show [--repo DIR] [--json] registry, Jev, decide, the repo's .forge files, dataset and FORGE_* env
|
|
5
|
+
set <key> <value> [--repo DIR] [--json] repo.verify | repo.setup | repo.verify-subset | decide.gate.<gate>[.provider|.model]
|
|
6
|
+
unset <key> [--repo DIR] [--json] repo.verify | repo.setup | repo.verify-subset
|
|
7
|
+
|
|
8
|
+
A value of `-` reads stdin for the per-repo files. repo.verify-subset must contain `{files}` (the
|
|
9
|
+
selected test files) or `{changed}` (the changed paths, for a runner with a related-tests mode).
|
|
10
|
+
decide.gate.<gate> (off, shadow or on) is delegated to `forge decide gate` and writes the user
|
|
11
|
+
level. decide.gate.<gate>.provider and decide.gate.<gate>.model write the user level with no mode,
|
|
12
|
+
so the gate keeps the mode the other levels give it. Unset of those keys is refused: set the mode
|
|
13
|
+
to off. jev.enabled is gone; set a gate with decide.gate.<gate>. The registry is
|
|
14
|
+
read-only here: the skill dir is often a live symlink to a checkout, so an edit would change
|
|
15
|
+
runs already in progress; edit the checkout.
|
|
11
16
|
|
|
12
17
|
Only the three per-repo files are ever read for content; cloudflare.env never is. Values of FORGE_*
|
|
13
|
-
variables whose name contains TOKEN, KEY, SECRET or PASSWORD show as "<set>".
|
|
18
|
+
variables whose name contains TOKEN, KEY, SECRET or PASSWORD show as "<set>". A provider key never
|
|
19
|
+
appears in show.
|
|
20
|
+
|
|
21
|
+
A provider or model written to a gate that is `on` and not forced needs a passing replay of the
|
|
22
|
+
new provider and model, as `forge decide gate G on` does; without one nothing is written and the
|
|
23
|
+
exit code is 3 (with --json, an error object on stdout too).
|
|
14
24
|
|
|
15
|
-
Exit codes: 0 ok, 2 usage or invalid input (including an unsafe path)
|
|
16
|
-
CLI's own, passed through.
|
|
25
|
+
Exit codes: 0 ok, 2 usage or invalid input (including an unsafe path), 3 refused by the promotion
|
|
26
|
+
rule; any other code is the decide CLI's own, passed through.
|
|
17
27
|
"""
|
|
18
28
|
from __future__ import annotations
|
|
19
29
|
|
|
@@ -21,6 +31,7 @@ import argparse
|
|
|
21
31
|
import json
|
|
22
32
|
import os
|
|
23
33
|
from pathlib import Path
|
|
34
|
+
import re
|
|
24
35
|
import stat
|
|
25
36
|
import subprocess
|
|
26
37
|
import sys
|
|
@@ -28,14 +39,26 @@ import sys
|
|
|
28
39
|
SKILL = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
|
|
29
40
|
sys.path.insert(0, os.path.join(SKILL, 'scripts'))
|
|
30
41
|
|
|
42
|
+
from forge_decide import GATES, MODES, load_user, save_user, user_path
|
|
43
|
+
from forge_decide.migrate import run as migrate_run
|
|
44
|
+
from forge_decide.providers import spec_for_site
|
|
45
|
+
|
|
31
46
|
REPO_FILES = ('verify', 'setup', 'verify-subset')
|
|
32
|
-
KEYS = tuple('repo.' + n for n in REPO_FILES)
|
|
47
|
+
KEYS = tuple('repo.' + n for n in REPO_FILES)
|
|
48
|
+
# decide.gate.<gate>, and the same with .provider or .model. The gate is checked against GATES.
|
|
49
|
+
_DECIDE_KEY = re.compile(r'^decide\.gate\.([A-Za-z0-9_-]+?)(?:\.(provider|model))?$')
|
|
50
|
+
MAX_DECIDE_VALUE = 256
|
|
51
|
+
_SECRET_PROVIDER_FIELDS = ('key', 'key_source', 'key_file', 'key_env')
|
|
33
52
|
CONTENT_MAX = 64 * 1024
|
|
34
53
|
SECRET_WORDS = ('TOKEN', 'KEY', 'SECRET', 'PASSWORD')
|
|
35
54
|
REGISTRY_NOTE = ('read-only here: the skill dir is often a live symlink to a checkout, so an edit '
|
|
36
55
|
'changes runs already in progress; edit registry.tsv in the checkout instead')
|
|
37
56
|
|
|
38
57
|
|
|
58
|
+
class Refused(Exception):
|
|
59
|
+
"""A change the promotion rule refuses (#37): exit 3."""
|
|
60
|
+
|
|
61
|
+
|
|
39
62
|
class Invalid(Exception):
|
|
40
63
|
"""Usage or invalid input, an unsafe path included: exit 2."""
|
|
41
64
|
|
|
@@ -170,6 +193,47 @@ def jev_block():
|
|
|
170
193
|
return dict(path=str(path), exists=path.is_file(), enabled=bool(load_config().get('enabled')))
|
|
171
194
|
|
|
172
195
|
|
|
196
|
+
def _gate_ready(gate, providers):
|
|
197
|
+
"""A gate can run when it is shadow or on, nothing skips it, and its provider is local or has a key.
|
|
198
|
+
|
|
199
|
+
With no provider the run uses the legacy client, so the gate is ready when that client has a key.
|
|
200
|
+
"""
|
|
201
|
+
if gate.get('mode') not in ('shadow', 'on') or gate.get('skip'):
|
|
202
|
+
return False
|
|
203
|
+
if not gate.get('provider'):
|
|
204
|
+
# resolved={} names no provider, so spec_for_site gives the legacy spec the run would use
|
|
205
|
+
try:
|
|
206
|
+
return bool(spec_for_site(gate['site'], resolved={}).get('key'))
|
|
207
|
+
except Exception: # a legacy config the run cannot describe; show must still print (resolve.py too)
|
|
208
|
+
return False
|
|
209
|
+
row = providers.get(gate['provider'])
|
|
210
|
+
if not isinstance(row, dict):
|
|
211
|
+
return False
|
|
212
|
+
if row.get('local') is True:
|
|
213
|
+
return True
|
|
214
|
+
return row.get('key') == 'present'
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
def decide_block(root):
|
|
218
|
+
"""The full `forge decide status --json` object for `root`, plus `ready` on each gate.
|
|
219
|
+
|
|
220
|
+
Provider rows drop every key field. `ready` is computed before that, so a hosted provider
|
|
221
|
+
with a key on file still counts. The key itself is never copied.
|
|
222
|
+
"""
|
|
223
|
+
from forge_decide.cli import status_data
|
|
224
|
+
data = status_data(root)
|
|
225
|
+
full = data.get('providers') if isinstance(data.get('providers'), dict) else {}
|
|
226
|
+
gates = data.get('gates') if isinstance(data.get('gates'), dict) else {}
|
|
227
|
+
for gate in gates.values():
|
|
228
|
+
if isinstance(gate, dict):
|
|
229
|
+
gate['ready'] = _gate_ready(gate, full)
|
|
230
|
+
data['providers'] = {
|
|
231
|
+
name: {k: v for k, v in row.items() if k not in _SECRET_PROVIDER_FIELDS}
|
|
232
|
+
for name, row in full.items() if isinstance(row, dict)
|
|
233
|
+
}
|
|
234
|
+
return data
|
|
235
|
+
|
|
236
|
+
|
|
173
237
|
def repo_block(root):
|
|
174
238
|
files = {}
|
|
175
239
|
for name in REPO_FILES:
|
|
@@ -218,9 +282,54 @@ def env_block():
|
|
|
218
282
|
return out
|
|
219
283
|
|
|
220
284
|
|
|
285
|
+
def _print_decide(decide):
|
|
286
|
+
"""The human view of a status object. A provider key is not among these fields."""
|
|
287
|
+
privacy = decide.get('privacy') if isinstance(decide.get('privacy'), dict) else {}
|
|
288
|
+
print('decide: %s (%s, migrated %s, privacy floor %s)' % (
|
|
289
|
+
decide.get('user_path'), 'present' if decide.get('migrated') else 'absent',
|
|
290
|
+
'yes' if decide.get('migrated') else 'no',
|
|
291
|
+
'yes' if privacy.get('floor') else 'no'))
|
|
292
|
+
gates = decide.get('gates') if isinstance(decide.get('gates'), dict) else {}
|
|
293
|
+
for name, gate in gates.items():
|
|
294
|
+
if not isinstance(gate, dict):
|
|
295
|
+
print(' gate %s: %s' % (name, gate))
|
|
296
|
+
continue
|
|
297
|
+
bits = [str(gate.get('mode')), 'source %s' % gate.get('source')]
|
|
298
|
+
if gate.get('provider'):
|
|
299
|
+
bits.append('provider %s' % gate['provider'])
|
|
300
|
+
if gate.get('model'):
|
|
301
|
+
bits.append('model %s' % gate['model'])
|
|
302
|
+
if gate.get('skip'):
|
|
303
|
+
bits.append('skip %s' % gate['skip'])
|
|
304
|
+
bits.append('ready %s' % ('yes' if gate.get('ready') else 'no'))
|
|
305
|
+
print(' gate %s: %s' % (name, ', '.join(bits)))
|
|
306
|
+
providers = decide.get('providers') if isinstance(decide.get('providers'), dict) else {}
|
|
307
|
+
if providers:
|
|
308
|
+
parts = []
|
|
309
|
+
for name, row in providers.items():
|
|
310
|
+
row = row if isinstance(row, dict) else {}
|
|
311
|
+
kind = row.get('type') or ''
|
|
312
|
+
local = ' local' if row.get('local') else ''
|
|
313
|
+
parts.append('%s (%s%s)' % (name, kind, local) if kind or row.get('local') else name)
|
|
314
|
+
print(' providers: %s' % ', '.join(parts))
|
|
315
|
+
else:
|
|
316
|
+
print(' providers: none')
|
|
317
|
+
budget = decide.get('budget') if isinstance(decide.get('budget'), dict) else {}
|
|
318
|
+
caps = budget.get('caps') if isinstance(budget.get('caps'), dict) else {}
|
|
319
|
+
shown = ', '.join('%s=%s' % (key, value) for key, value in caps.items() if value is not None)
|
|
320
|
+
print(' budget: %s' % (shown or 'none'))
|
|
321
|
+
spend = budget.get('spend') if isinstance(budget.get('spend'), dict) else None
|
|
322
|
+
if spend and isinstance(spend.get('today'), dict):
|
|
323
|
+
today = spend['today']
|
|
324
|
+
print(' today (%s): %s tokens, $%s' % (spend.get('date'), today.get('tokens'), today.get('usd')))
|
|
325
|
+
for entry in decide.get('shadowed') or []:
|
|
326
|
+
if isinstance(entry, dict):
|
|
327
|
+
print(' shadowed: %s: repo %r, user %r' % (entry.get('key'), entry.get('repo'), entry.get('user')))
|
|
328
|
+
|
|
329
|
+
|
|
221
330
|
def cmd_show(args):
|
|
222
331
|
root = repo_root(args.repo, required=False)
|
|
223
|
-
data = dict(registry=registry_block(), jev=jev_block())
|
|
332
|
+
data = dict(registry=registry_block(), jev=jev_block(), decide=decide_block(root))
|
|
224
333
|
if root:
|
|
225
334
|
data['repo'] = repo_block(root)
|
|
226
335
|
data['dataset'] = dataset_block()
|
|
@@ -236,6 +345,7 @@ def cmd_show(args):
|
|
|
236
345
|
jev = data['jev']
|
|
237
346
|
print('jev: %s (%s, %s)' % ('enabled' if jev['enabled'] else 'disabled', jev['path'],
|
|
238
347
|
'present' if jev['exists'] else 'absent'))
|
|
348
|
+
_print_decide(data['decide'])
|
|
239
349
|
if root:
|
|
240
350
|
print('repo: %s' % root)
|
|
241
351
|
for name, entry in data['repo']['files'].items():
|
|
@@ -252,7 +362,85 @@ def cmd_show(args):
|
|
|
252
362
|
|
|
253
363
|
def check_key(key):
|
|
254
364
|
if key not in KEYS:
|
|
255
|
-
raise Invalid('unknown key %r; valid keys: %s
|
|
365
|
+
raise Invalid('unknown key %r; valid keys: %s, decide.gate.<gate>, '
|
|
366
|
+
'decide.gate.<gate>.provider, decide.gate.<gate>.model' % (key, ', '.join(KEYS)))
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
def decide_target(key):
|
|
370
|
+
"""(gate, field) for a decide key. field is None, 'provider' or 'model'.
|
|
371
|
+
|
|
372
|
+
None when `key` is not that shape. Invalid when the shape names a gate that does not exist.
|
|
373
|
+
"""
|
|
374
|
+
match = _DECIDE_KEY.fullmatch(key or '')
|
|
375
|
+
if not match:
|
|
376
|
+
return None
|
|
377
|
+
gate, field = match.group(1), match.group(2)
|
|
378
|
+
if gate not in GATES:
|
|
379
|
+
raise Invalid('unknown gate %r; gates: %s' % (gate, ', '.join(GATES)))
|
|
380
|
+
return gate, field
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
def _no_control(value):
|
|
384
|
+
return not any(ord(ch) < 32 or ord(ch) == 127 or 0xD800 <= ord(ch) <= 0xDFFF for ch in value)
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
def _decide_value(field, value):
|
|
388
|
+
"""The mode, or a provider or model name. A decide value is never read from stdin."""
|
|
389
|
+
if field is None:
|
|
390
|
+
if value not in MODES:
|
|
391
|
+
raise Invalid('mode must be off, shadow or on')
|
|
392
|
+
return value
|
|
393
|
+
if (not isinstance(value, str) or not value or value != value.strip()
|
|
394
|
+
or len(value) > MAX_DECIDE_VALUE or value.startswith('-') or not _no_control(value)):
|
|
395
|
+
raise Invalid('short single-line text, not starting with "-"')
|
|
396
|
+
return value
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
def _check_replayed(gate, entry, providers):
|
|
400
|
+
"""Refuse (before anything is written) an `on` entry, not forced, whose provider and model, as
|
|
401
|
+
`entry` will have them, have no passing replay: the rule `forge decide gate G on` applies."""
|
|
402
|
+
if entry.get('mode') != 'on' or entry.get('force'):
|
|
403
|
+
return
|
|
404
|
+
from forge_decide import GATE_SITE
|
|
405
|
+
from forge_decide.providers import identity
|
|
406
|
+
from forge_decide.replay import recorded
|
|
407
|
+
site = GATE_SITE[gate]
|
|
408
|
+
provider, model = identity(site, entry, providers=providers, env={})
|
|
409
|
+
stored = recorded(gate, provider, model)
|
|
410
|
+
if stored is not None and stored.get('passes') is True:
|
|
411
|
+
return
|
|
412
|
+
raise Refused('%s is on and has no passing replay on provider %s, model %s.\n'
|
|
413
|
+
'Run `forge decide replay --site %s --provider %s --model %s --send`, '
|
|
414
|
+
'or turn it on without one with `forge decide gate %s on --force` (shown as forced).' % (gate, provider, model, site, provider, model, gate))
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
def _write_user_field(gate, field, value):
|
|
418
|
+
"""Set a gate's provider or model in the user file, storing no mode.
|
|
419
|
+
|
|
420
|
+
`forge decide gate` always writes a mode, and a mode written here would outlive the repo, profile
|
|
421
|
+
or environment variable that set it. So the field is written here, after the jev.json migration
|
|
422
|
+
and the provider check that `forge decide gate` makes. A mode the user file holds is kept as it is.
|
|
423
|
+
"""
|
|
424
|
+
result = migrate_run()
|
|
425
|
+
if result['status'] == 'migrated':
|
|
426
|
+
print('forge config: migrated jev.json into %s first' % user_path(), file=sys.stderr)
|
|
427
|
+
data, error = load_user()
|
|
428
|
+
if error:
|
|
429
|
+
raise Invalid(error)
|
|
430
|
+
providers = data.get('providers')
|
|
431
|
+
providers = providers if isinstance(providers, dict) else {}
|
|
432
|
+
if field == 'provider' and value not in providers:
|
|
433
|
+
raise Invalid('unknown provider %r; configured: %s (add one with `forge decide provider add`)'
|
|
434
|
+
% (value, ', '.join(sorted(providers)) or 'none'))
|
|
435
|
+
gates = data.get('gates') if isinstance(data.get('gates'), dict) else {}
|
|
436
|
+
entry = gates.get(gate)
|
|
437
|
+
entry = dict(mode=entry) if isinstance(entry, str) else dict(entry) if isinstance(entry, dict) else {}
|
|
438
|
+
entry[field] = value
|
|
439
|
+
_check_replayed(gate, entry, providers)
|
|
440
|
+
gates[gate] = entry
|
|
441
|
+
data['gates'] = gates
|
|
442
|
+
data.setdefault('version', 1)
|
|
443
|
+
save_user(data)
|
|
256
444
|
|
|
257
445
|
|
|
258
446
|
def emit(args, key, previous, value):
|
|
@@ -263,9 +451,10 @@ def emit(args, key, previous, value):
|
|
|
263
451
|
|
|
264
452
|
|
|
265
453
|
def cmd_set(args):
|
|
266
|
-
check_key(args.key)
|
|
267
454
|
if args.key == 'jev.enabled':
|
|
268
|
-
|
|
455
|
+
raise Invalid('jev.enabled is gone; set a gate with decide.gate.<gate>')
|
|
456
|
+
if args.key not in KEYS:
|
|
457
|
+
return set_decide(args)
|
|
269
458
|
root = repo_root(args.repo, required=True)
|
|
270
459
|
if root is None:
|
|
271
460
|
raise Invalid('--repo DIR is required for %s' % args.key)
|
|
@@ -273,8 +462,8 @@ def cmd_set(args):
|
|
|
273
462
|
name = args.key[len('repo.'):]
|
|
274
463
|
if not value.strip():
|
|
275
464
|
raise Invalid('empty value; use `forge config unset %s` to remove it' % args.key)
|
|
276
|
-
if name == 'verify-subset' and '{files}' not in value:
|
|
277
|
-
raise Invalid('repo.verify-subset must contain {files}')
|
|
465
|
+
if name == 'verify-subset' and '{files}' not in value and '{changed}' not in value:
|
|
466
|
+
raise Invalid('repo.verify-subset must contain {files} or {changed}')
|
|
278
467
|
d, target = safe_target(root, name)
|
|
279
468
|
previous = read_small(target)[0] if d else None
|
|
280
469
|
if not value.endswith('\n'):
|
|
@@ -285,9 +474,11 @@ def cmd_set(args):
|
|
|
285
474
|
|
|
286
475
|
|
|
287
476
|
def cmd_unset(args):
|
|
288
|
-
check_key(args.key)
|
|
289
477
|
if args.key == 'jev.enabled':
|
|
290
|
-
raise Invalid('jev.enabled
|
|
478
|
+
raise Invalid('jev.enabled is gone; set a gate with decide.gate.<gate>')
|
|
479
|
+
if decide_target(args.key):
|
|
480
|
+
raise Invalid('set the mode to off')
|
|
481
|
+
check_key(args.key)
|
|
291
482
|
root = repo_root(args.repo, required=True)
|
|
292
483
|
if root is None:
|
|
293
484
|
raise Invalid('--repo DIR is required for %s' % args.key)
|
|
@@ -303,16 +494,29 @@ def cmd_unset(args):
|
|
|
303
494
|
return 0
|
|
304
495
|
|
|
305
496
|
|
|
306
|
-
def
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
497
|
+
def set_decide(args):
|
|
498
|
+
"""Write one decide key at the user level: a mode through `forge decide gate`, a provider or model
|
|
499
|
+
through _write_user_field. --repo is only the repo whose effective settings are read for `previous`."""
|
|
500
|
+
found = decide_target(args.key)
|
|
501
|
+
if found is None:
|
|
502
|
+
check_key(args.key)
|
|
503
|
+
gate, field = found
|
|
504
|
+
value = _decide_value(field, args.value)
|
|
505
|
+
root = repo_root(args.repo, required=True) if args.repo is not None else None
|
|
506
|
+
from forge_decide.cli import status_data
|
|
507
|
+
before = status_data(root)
|
|
508
|
+
row = (before.get('gates') or {}).get(gate) or {}
|
|
509
|
+
if field is None:
|
|
510
|
+
previous = row.get('mode')
|
|
511
|
+
script = os.path.join(SKILL, 'scripts', 'forge-decide.py')
|
|
512
|
+
run = subprocess.run([sys.executable, script, 'gate', gate, value],
|
|
513
|
+
stdout=subprocess.DEVNULL, stderr=None)
|
|
514
|
+
if run.returncode != 0:
|
|
515
|
+
return run.returncode
|
|
516
|
+
else:
|
|
517
|
+
previous = row.get(field)
|
|
518
|
+
_write_user_field(gate, field, value)
|
|
519
|
+
emit(args, args.key, previous, value)
|
|
316
520
|
return 0
|
|
317
521
|
|
|
318
522
|
|
|
@@ -344,6 +548,11 @@ def main(argv=None):
|
|
|
344
548
|
except Invalid as err:
|
|
345
549
|
print('forge config: %s' % err, file=sys.stderr)
|
|
346
550
|
return 2
|
|
551
|
+
except Refused as err:
|
|
552
|
+
print('forge config: %s' % err, file=sys.stderr)
|
|
553
|
+
if getattr(args, 'json', False):
|
|
554
|
+
print(json.dumps(dict(ok=False, key=args.key, error=str(err))))
|
|
555
|
+
return 3
|
|
347
556
|
|
|
348
557
|
|
|
349
558
|
if __name__ == '__main__':
|