@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.
Files changed (117) hide show
  1. package/CHANGELOG.md +77 -0
  2. package/README.md +1 -1
  3. package/SKILL.md +31 -12
  4. package/VERSION +1 -1
  5. package/docs/add-ons.md +11 -6
  6. package/docs/artifacts.md +18 -6
  7. package/docs/commands.md +189 -17
  8. package/docs/decomposed-runs.md +13 -5
  9. package/docs/forge-ui.md +34 -4
  10. package/docs/memory.md +2 -1
  11. package/docs/models.md +4 -2
  12. package/docs/reviews.md +81 -19
  13. package/docs/troubleshooting.md +3 -1
  14. package/forge +17 -1
  15. package/package.json +1 -1
  16. package/references/dataset.md +40 -14
  17. package/references/decision-models.md +759 -0
  18. package/references/decompose.md +197 -28
  19. package/references/harnesses.md +10 -3
  20. package/references/planning.md +8 -0
  21. package/references/solo.md +13 -3
  22. package/references/ui.md +11 -0
  23. package/scripts/forge-artifact.sh +30 -4
  24. package/scripts/forge-config.py +238 -29
  25. package/scripts/forge-contract.py +127 -58
  26. package/scripts/forge-control.py +40 -9
  27. package/scripts/forge-decide.py +6 -0
  28. package/scripts/forge-dispatch.sh +47 -15
  29. package/scripts/forge-fail-first.py +2 -2
  30. package/scripts/forge-gate-addressed.sh +40 -0
  31. package/scripts/forge-gate-message.sh +64 -0
  32. package/scripts/forge-issues.py +368 -36
  33. package/scripts/forge-jev-options.sh +269 -42
  34. package/scripts/forge-lib-attribute.sh +447 -0
  35. package/scripts/forge-lib-gates.sh +32 -0
  36. package/scripts/forge-lib-plans.sh +17 -6
  37. package/scripts/forge-lib-review.sh +24 -19
  38. package/scripts/forge-lib-task.sh +219 -39
  39. package/scripts/forge-lib-verify.sh +45 -8
  40. package/scripts/forge-memory.sh +3 -3
  41. package/scripts/forge-parallel-options.sh +44 -5
  42. package/scripts/forge-parallel.sh +503 -304
  43. package/scripts/forge-plan-check.py +35 -1
  44. package/scripts/forge-pre-review.py +437 -0
  45. package/scripts/forge-prompt.py +25 -5
  46. package/scripts/forge-route.py +2 -2
  47. package/scripts/forge-runtime.py +55 -1
  48. package/scripts/forge-schedule.py +70 -9
  49. package/scripts/forge-shadow.py +2 -2
  50. package/scripts/forge-solo.sh +41 -10
  51. package/scripts/forge-submodules.py +389 -0
  52. package/scripts/forge-sweep.py +542 -0
  53. package/scripts/forge_dataset/cli.py +12 -6
  54. package/scripts/forge_dataset/export.py +55 -45
  55. package/scripts/forge_dataset/forecast.py +4 -1
  56. package/scripts/forge_dataset/harvest.py +33 -5
  57. package/scripts/{forge_jev/outcome.py → forge_dataset/states.py} +21 -7
  58. package/scripts/forge_decide/__init__.py +141 -0
  59. package/scripts/forge_decide/budget.py +149 -0
  60. package/scripts/forge_decide/cache.py +66 -0
  61. package/scripts/forge_decide/cli.py +953 -0
  62. package/scripts/forge_decide/doctor.py +221 -0
  63. package/scripts/forge_decide/label_addressed.py +75 -0
  64. package/scripts/forge_decide/label_attribution.py +62 -0
  65. package/scripts/forge_decide/label_coverage.py +81 -0
  66. package/scripts/forge_decide/label_message.py +38 -0
  67. package/scripts/forge_decide/label_prompt.py +139 -0
  68. package/scripts/forge_decide/labels.py +328 -0
  69. package/scripts/forge_decide/metrics.py +125 -0
  70. package/scripts/forge_decide/migrate.py +226 -0
  71. package/scripts/forge_decide/providers.py +292 -0
  72. package/scripts/forge_decide/replay.py +350 -0
  73. package/scripts/forge_decide/report.py +382 -0
  74. package/scripts/forge_decide/resolve.py +397 -0
  75. package/scripts/forge_decide/sites.py +377 -0
  76. package/scripts/forge_jev/__init__.py +202 -104
  77. package/scripts/forge_jev/addressed.py +171 -0
  78. package/scripts/forge_jev/attribution.py +198 -0
  79. package/scripts/forge_jev/cli.py +460 -382
  80. package/scripts/forge_jev/client.py +155 -77
  81. package/scripts/forge_jev/coupling.py +19 -87
  82. package/scripts/forge_jev/coverage.py +303 -0
  83. package/scripts/forge_jev/findings.py +219 -0
  84. package/scripts/forge_jev/gates.py +225 -27
  85. package/scripts/forge_jev/memory.py +65 -4
  86. package/scripts/forge_jev/message.py +134 -0
  87. package/scripts/forge_jev/plan_gates.py +294 -0
  88. package/scripts/forge_jev/questions.py +173 -313
  89. package/scripts/forge_jev/verify.py +130 -104
  90. package/ui/README.md +41 -10
  91. package/ui/docs/api.md +212 -44
  92. package/ui/forge_ui/checks.py +331 -0
  93. package/ui/forge_ui/control.py +60 -11
  94. package/ui/forge_ui/export.py +8 -3
  95. package/ui/forge_ui/models.py +1 -0
  96. package/ui/forge_ui/reader.py +436 -26
  97. package/ui/forge_ui/server.py +13 -0
  98. package/ui/forge_ui/static/app.js +15 -8
  99. package/ui/forge_ui/static/checksview.js +449 -0
  100. package/ui/forge_ui/static/controls.js +20 -13
  101. package/ui/forge_ui/static/convo.js +11 -2
  102. package/ui/forge_ui/static/findingsview.js +6 -4
  103. package/ui/forge_ui/static/index.html +1 -0
  104. package/ui/forge_ui/static/panel.js +105 -17
  105. package/ui/forge_ui/static/runmodel.js +40 -2
  106. package/ui/forge_ui/static/scene3d.js +2 -15
  107. package/ui/forge_ui/static/settings.js +336 -41
  108. package/ui/forge_ui/static/style.css +72 -7
  109. package/ui/forge_ui/transcripts.py +225 -54
  110. package/references/jev.md +0 -865
  111. package/scripts/forge_jev/backtest.py +0 -322
  112. package/scripts/forge_jev/corpus.py +0 -156
  113. package/scripts/forge_jev/features.py +0 -24
  114. package/scripts/forge_jev/predict.py +0 -204
  115. package/scripts/forge_jev/review.py +0 -73
  116. package/scripts/forge_jev/routing.py +0 -271
  117. package/scripts/forge_jev/subset.py +0 -123
@@ -0,0 +1,397 @@
1
+ """Resolve every gate's effective setting from the six configuration levels.
2
+
3
+ resolve(repo=None, *, profile=None, env=None, flags=None, user_data=None, repo_data=None) -> dict
4
+
5
+ Levels, lowest to highest; each sets a gate's fields only where it names them:
6
+
7
+ 1. default -- every gate `off`.
8
+ 2. repo -- <repo>/.forge/decide.json: `gates` and `budget.run_*`.
9
+ 3. user -- ~/.config/forge/decide.json: `gates` and all of `budget`. When that file does
10
+ not exist the legacy level takes its place (source `legacy`): it reproduces
11
+ forge_jev.enabled(capability) from jev.json and the FORGE_JEV* variables, and
12
+ turns a gate `on` when its capability is enabled. It never sets `off`, and a
13
+ gate with no capability (None) is never turned on there.
14
+ 4. profile -- `profile`, else FORGE_DECIDE_PROFILE; looked up in the user file's `profiles`
15
+ first, then the repo file's. Sets `gates` and `budget` (`budget.daily_*` only
16
+ from a user-file profile).
17
+ 5. env -- FORGE_DECIDE_GATE_<NAME>=off|shadow|on (NAME upper-cased, `-` -> `_`). Once a
18
+ user decide.json exists, the legacy FORGE_JEV_<CAP> variables can only restrict:
19
+ `off` turns that capability's gates off, and any `on` turns off the gates of
20
+ every capability not named `on` (a gate with no capability included).
21
+ FORGE_JEV_SHADOW=on turns `on` into `shadow`, except, with no user decide.json,
22
+ a gate the legacy level turned on.
23
+ 6. flags -- `flags`, else json.loads(env['FORGE_DECIDE_FLAGS']), shaped
24
+ {"gates": {gate: mode}, "no_gates": bool, "budget": {"run_tokens", "run_usd"}}.
25
+ `no_gates` turns every gate off, after `gates` is applied.
26
+
27
+ Then FORGE_JEV=off turns every gate off with skip 'kill', and a repo file's
28
+ "privacy": "never-send" turns every gate off with skip 'privacy' (the floor wins when both
29
+ apply). `privacy` counts only in the repo file, and `providers` and `budget.daily_*` only in
30
+ the user file; anywhere else they are ignored and reported in `errors`.
31
+
32
+ Choices the interface left open:
33
+ - `source` is the level that last set the gate's mode; a gate's other fields may come from
34
+ other levels. The kill switch, the floor and FORGE_JEV_SHADOW keep the source and record why
35
+ in `skip` (kill, privacy) or by setting the source to `env` (shadow).
36
+ - The legacy level labels every gate it leaves at the default with source `legacy` too, but
37
+ only when there is something legacy to read: a jev.json, or FORGE_JEV / FORGE_JEV_<CAP> set
38
+ to on or off. A fresh install therefore reports source `default`.
39
+ - A user decide.json that exists but is malformed counts as an empty user level, not as
40
+ missing: the legacy level does not come back because the file broke.
41
+ - A gate may be a bare mode string or an object. A null field counts as not set. Thresholds
42
+ merge name by name across levels. `force` (a bool: the gate was turned on with --force, without
43
+ a passing replay) is kept like any other field, but is not a value the repo and user files can
44
+ disagree on, so it is never reported as shadowed. Budgets are numbers >= 0; null means not set.
45
+ - `repo=None` means no repo level and no privacy floor.
46
+ - `user_data` / `repo_data` stand in for the user / repo decide.json as a writer is about to
47
+ save it (`user_data` counts as an existing user file), so the effect of a write can be
48
+ checked before anything is written.
49
+ - `profile` in the result is the selected profile's name, or None when none was selected or
50
+ the name was not found.
51
+ - A profile in the user file sets all of `budget`; one in the repo file sets only `run_*`,
52
+ like the repo file itself.
53
+ - Budgets are any int, or a finite float; a value too large for a float is still a valid
54
+ budget, but not a valid threshold.
55
+
56
+ Pure apart from reading the two decide.json files and jev.json: never writes, never touches
57
+ the network, never raises.
58
+ """
59
+ from __future__ import annotations
60
+
61
+ import json
62
+ import math
63
+ import os
64
+
65
+ from . import GATE_CAPABILITY, GATES, MODES, load_repo, load_user, repo_path, user_path
66
+
67
+ LEGACY_CAPABILITIES = ('routing', 'tests', 'gates', 'memory')
68
+ GATE_FIELDS = ('mode', 'provider', 'model', 'thresholds_model')
69
+ RUN_BUDGET = ('run_tokens', 'run_usd')
70
+ DAILY_BUDGET = ('daily_tokens', 'daily_usd')
71
+ PRIVACY_FLOOR = 'never-send'
72
+
73
+
74
+ def _gate_default() -> dict:
75
+ return dict(mode='off', source='default', provider=None, model=None, thresholds={},
76
+ thresholds_model=None, skip=None, force=False)
77
+
78
+
79
+ def _result(errors: list) -> dict:
80
+ return dict(gates={g: _gate_default() for g in GATES},
81
+ budget={k: None for k in RUN_BUDGET + DAILY_BUDGET},
82
+ privacy=dict(floor=None, path=None), profile=None, shadowed=[], errors=errors)
83
+
84
+
85
+ def _number(value) -> bool:
86
+ """A finite JSON number. An int of any size counts: math.isfinite would overflow on it."""
87
+ if isinstance(value, bool):
88
+ return False
89
+ return isinstance(value, int) or (isinstance(value, float) and math.isfinite(value))
90
+
91
+
92
+ def _threshold(value):
93
+ """`value` as a finite float, or None when it is not a number or too large for one."""
94
+ if not _number(value):
95
+ return None
96
+ try:
97
+ return float(value)
98
+ except OverflowError:
99
+ return None
100
+
101
+
102
+ def _parse_gates(obj, label: str, errors: list) -> dict:
103
+ """{gate: {field: value, 'thresholds': {name: float}}} of the valid values in `obj`."""
104
+ if obj is None:
105
+ return {}
106
+ if not isinstance(obj, dict):
107
+ errors.append(f'{label}: gates is not an object')
108
+ return {}
109
+ out = {}
110
+ for name, value in obj.items():
111
+ if name not in GATES:
112
+ errors.append(f'{label}: unknown gate {name!r}')
113
+ continue
114
+ if isinstance(value, str):
115
+ value = dict(mode=value)
116
+ if not isinstance(value, dict):
117
+ errors.append(f'{label}: gates.{name} is not a mode or an object')
118
+ continue
119
+ parsed = {}
120
+ mode = value.get('mode')
121
+ if mode is not None:
122
+ if mode in MODES:
123
+ parsed['mode'] = mode
124
+ else:
125
+ errors.append(f'{label}: gates.{name}.mode {mode!r} is not one of {", ".join(MODES)}')
126
+ for field in ('provider', 'model', 'thresholds_model'):
127
+ field_value = value.get(field)
128
+ if field_value is None:
129
+ continue
130
+ if isinstance(field_value, str):
131
+ parsed[field] = field_value
132
+ else:
133
+ errors.append(f'{label}: gates.{name}.{field} is not a string')
134
+ force = value.get('force')
135
+ if force is not None:
136
+ if isinstance(force, bool):
137
+ parsed['force'] = force
138
+ else:
139
+ errors.append(f'{label}: gates.{name}.force is not true or false')
140
+ thresholds = value.get('thresholds')
141
+ if thresholds is not None:
142
+ if not isinstance(thresholds, dict):
143
+ errors.append(f'{label}: gates.{name}.thresholds is not an object')
144
+ else:
145
+ kept = {}
146
+ for key, number in thresholds.items():
147
+ number = _threshold(number)
148
+ if number is not None:
149
+ kept[key] = number
150
+ else:
151
+ errors.append(f'{label}: gates.{name}.thresholds.{key} is not a number')
152
+ if kept:
153
+ parsed['thresholds'] = kept
154
+ out[name] = parsed
155
+ return out
156
+
157
+
158
+ def _parse_budget(obj, label: str, errors: list, keys: tuple) -> dict:
159
+ if obj is None:
160
+ return {}
161
+ if not isinstance(obj, dict):
162
+ errors.append(f'{label}: budget is not an object')
163
+ return {}
164
+ out = {}
165
+ for key in keys:
166
+ value = obj.get(key)
167
+ if value is None:
168
+ continue
169
+ if _number(value) and value >= 0:
170
+ out[key] = value
171
+ else:
172
+ errors.append(f'{label}: budget.{key} is not a number >= 0')
173
+ return out
174
+
175
+
176
+ def _apply(result: dict, gates: dict, budget: dict, source: str) -> None:
177
+ for name, parsed in gates.items():
178
+ gate = result['gates'][name]
179
+ for field, value in parsed.items():
180
+ if field == 'thresholds':
181
+ gate['thresholds'] = dict(gate['thresholds'], **value)
182
+ else:
183
+ gate[field] = value
184
+ if 'mode' in parsed:
185
+ gate['source'] = source
186
+ result['budget'].update(budget)
187
+
188
+
189
+ def _set_mode(result: dict, name: str, mode: str, source: str) -> None:
190
+ result['gates'][name]['mode'] = mode
191
+ result['gates'][name]['source'] = source
192
+
193
+
194
+ def _legacy_overrides(env) -> dict:
195
+ out = {}
196
+ for cap in LEGACY_CAPABILITIES:
197
+ value = env.get('FORGE_JEV_' + cap.upper())
198
+ if value in ('on', 'off'):
199
+ out[cap] = value
200
+ return out
201
+
202
+
203
+ def _legacy_enabled(capability: str, env, config: dict) -> bool:
204
+ """forge_jev.enabled(capability), against `env` instead of os.environ."""
205
+ if env.get('FORGE_JEV') == 'off':
206
+ return False
207
+ overrides = _legacy_overrides(env)
208
+ # Naming one capability on is an allowlist.
209
+ if 'on' in overrides.values():
210
+ return overrides.get(capability) == 'on'
211
+ if overrides.get(capability) == 'off':
212
+ return False
213
+ if env.get('FORGE_JEV') != 'on' and not config.get('enabled'):
214
+ return False
215
+ capabilities = config.get('capabilities')
216
+ if not isinstance(capabilities, dict):
217
+ return True
218
+ return bool(capabilities.get(capability, True))
219
+
220
+
221
+ def _legacy(result: dict, env, errors: list) -> None:
222
+ try:
223
+ import forge_jev
224
+ config = forge_jev.load_config()
225
+ has_file = forge_jev.config_path().exists()
226
+ except Exception as exc: # a broken forge_jev must not stop resolution
227
+ errors.append(f'legacy jev.json: {exc!r}')
228
+ config, has_file = {}, False
229
+ active = (has_file or env.get('FORGE_JEV') in ('on', 'off')
230
+ or bool(_legacy_overrides(env)))
231
+ if not active:
232
+ return
233
+ for name in GATES:
234
+ capability = GATE_CAPABILITY[name]
235
+ # A gate with no legacy capability is outside the legacy level: it keeps source `default`.
236
+ if capability is None:
237
+ continue
238
+ if _legacy_enabled(capability, env, config):
239
+ _set_mode(result, name, 'on', 'legacy')
240
+ elif result['gates'][name]['source'] == 'default':
241
+ result['gates'][name]['source'] = 'legacy'
242
+
243
+
244
+ def _shadowed(repo_gates: dict, repo_budget: dict, user_gates: dict, user_budget: dict) -> list:
245
+ out = []
246
+ for name in GATES:
247
+ repo, user = repo_gates.get(name, {}), user_gates.get(name, {})
248
+ for field in GATE_FIELDS:
249
+ if field in repo and field in user and repo[field] != user[field]:
250
+ out.append(dict(key=f'gates.{name}.{field}', repo=repo[field], user=user[field]))
251
+ repo_t, user_t = repo.get('thresholds', {}), user.get('thresholds', {})
252
+ for key in sorted(set(repo_t) & set(user_t)):
253
+ if repo_t[key] != user_t[key]:
254
+ out.append(dict(key=f'gates.{name}.thresholds.{key}', repo=repo_t[key], user=user_t[key]))
255
+ for key in RUN_BUDGET:
256
+ if key in repo_budget and key in user_budget and repo_budget[key] != user_budget[key]:
257
+ out.append(dict(key=f'budget.{key}', repo=repo_budget[key], user=user_budget[key]))
258
+ return out
259
+
260
+
261
+ def _resolve(repo, profile, env, flags, errors: list, user_data=None, repo_data=None) -> dict:
262
+ result = _result(errors)
263
+
264
+ # 2. repo
265
+ override, repo_data, repo_label = repo_data, {}, None
266
+ if repo is not None:
267
+ repo_label = str(repo_path(repo))
268
+ repo_data, error = (override, None) if override is not None else load_repo(repo)
269
+ if error:
270
+ errors.append(error)
271
+ if 'providers' in repo_data:
272
+ errors.append(f'{repo_label}: providers are read from the user file only; ignored')
273
+ budget = repo_data.get('budget')
274
+ if isinstance(budget, dict):
275
+ for key in DAILY_BUDGET:
276
+ if key in budget:
277
+ errors.append(f'{repo_label}: budget.{key} is read from the user file only; ignored')
278
+ privacy = repo_data.get('privacy')
279
+ if privacy == PRIVACY_FLOOR:
280
+ result['privacy'] = dict(floor=PRIVACY_FLOOR, path=repo_label)
281
+ elif privacy is not None:
282
+ errors.append(f'{repo_label}: privacy {privacy!r} is not {PRIVACY_FLOOR!r}; ignored')
283
+ repo_gates = _parse_gates(repo_data.get('gates'), repo_label, errors)
284
+ repo_budget = _parse_budget(repo_data.get('budget'), repo_label, errors, RUN_BUDGET)
285
+ _apply(result, repo_gates, repo_budget, 'repo')
286
+
287
+ # 3. user, or legacy in its place
288
+ user_label = str(user_path())
289
+ migrated = user_data is not None or user_path().exists()
290
+ user_data, error = (user_data, None) if user_data is not None else load_user()
291
+ if error:
292
+ errors.append(error)
293
+ user_gates, user_budget = {}, {}
294
+ if migrated:
295
+ if 'privacy' in user_data:
296
+ errors.append(f'{user_label}: privacy counts only in a repo file; ignored')
297
+ user_gates = _parse_gates(user_data.get('gates'), user_label, errors)
298
+ user_budget = _parse_budget(user_data.get('budget'), user_label, errors, RUN_BUDGET + DAILY_BUDGET)
299
+ _apply(result, user_gates, user_budget, 'user')
300
+ else:
301
+ _legacy(result, env, errors)
302
+ result['shadowed'] = _shadowed(repo_gates, repo_budget, user_gates, user_budget)
303
+
304
+ # 4. profile
305
+ name = profile if profile is not None else (env.get('FORGE_DECIDE_PROFILE') or None)
306
+ if name is not None:
307
+ found = None
308
+ for data, label, in_user in ((user_data, user_label, True), (repo_data, repo_label, False)):
309
+ profiles = data.get('profiles')
310
+ if isinstance(profiles, dict) and name in profiles:
311
+ found = (profiles[name], f'{label}: profile {name!r}', in_user)
312
+ break
313
+ if found is None:
314
+ errors.append(f'profile {name!r} not found; ignored')
315
+ elif not isinstance(found[0], dict):
316
+ errors.append(f'{found[1]} is not an object; ignored')
317
+ else:
318
+ body, label, in_user = found
319
+ if 'privacy' in body:
320
+ errors.append(f'{label}: privacy counts only in a repo file; ignored')
321
+ budget_keys = RUN_BUDGET + DAILY_BUDGET if in_user else RUN_BUDGET
322
+ budget = body.get('budget')
323
+ if not in_user and isinstance(budget, dict):
324
+ for key in DAILY_BUDGET:
325
+ if key in budget:
326
+ errors.append(f'{label}: budget.{key} is read from the user file only; ignored')
327
+ result['profile'] = name
328
+ _apply(result, _parse_gates(body.get('gates'), label, errors),
329
+ _parse_budget(budget, label, errors, budget_keys), 'profile')
330
+
331
+ # 5. env
332
+ for gate in GATES:
333
+ var = 'FORGE_DECIDE_GATE_' + gate.upper().replace('-', '_')
334
+ value = env.get(var)
335
+ if value is None:
336
+ continue
337
+ if value in MODES:
338
+ _set_mode(result, gate, value, 'env')
339
+ else:
340
+ errors.append(f'{var}={value!r} is not one of {", ".join(MODES)}; ignored')
341
+ if migrated:
342
+ overrides = _legacy_overrides(env)
343
+ allowlist = 'on' in overrides.values()
344
+ for gate in GATES:
345
+ cap = GATE_CAPABILITY[gate]
346
+ if result['gates'][gate]['mode'] == 'off':
347
+ continue
348
+ if overrides.get(cap) == 'off' or (allowlist and overrides.get(cap) != 'on'):
349
+ _set_mode(result, gate, 'off', 'env')
350
+ # --jev-shadow turns `on` into `shadow`, except, before migration, a gate the legacy level
351
+ # turned on: that one acts as it always did, and its records are marked shadow
352
+ # (client._gate_fields).
353
+ if env.get('FORGE_JEV_SHADOW') == 'on':
354
+ for gate in GATES:
355
+ state = result['gates'][gate]
356
+ if state['mode'] == 'on' and (migrated or state['source'] != 'legacy'):
357
+ _set_mode(result, gate, 'shadow', 'env')
358
+
359
+ # 6. flags
360
+ if flags is None and env.get('FORGE_DECIDE_FLAGS'):
361
+ try:
362
+ flags = json.loads(env['FORGE_DECIDE_FLAGS'])
363
+ except (ValueError, RecursionError) as exc:
364
+ errors.append(f'FORGE_DECIDE_FLAGS: not valid JSON ({exc}); ignored')
365
+ flags = None
366
+ if flags is not None:
367
+ if not isinstance(flags, dict):
368
+ errors.append('flags: not an object; ignored')
369
+ else:
370
+ _apply(result, _parse_gates(flags.get('gates'), 'flags', errors),
371
+ _parse_budget(flags.get('budget'), 'flags', errors, RUN_BUDGET), 'flags')
372
+ if flags.get('no_gates') is True:
373
+ for gate in GATES:
374
+ _set_mode(result, gate, 'off', 'flags')
375
+
376
+ # Overrides: the kill switch, then the privacy floor.
377
+ if env.get('FORGE_JEV') == 'off':
378
+ for gate in result['gates'].values():
379
+ gate['mode'], gate['skip'] = 'off', 'kill'
380
+ if result['privacy']['floor'] == PRIVACY_FLOOR:
381
+ for gate in result['gates'].values():
382
+ gate['mode'], gate['skip'] = 'off', 'privacy'
383
+ return result
384
+
385
+
386
+ def resolve(repo=None, *, profile=None, env=None, flags=None, user_data=None, repo_data=None) -> dict:
387
+ """Every gate's effective mode, provider, model and thresholds, the budget, the privacy
388
+ floor, the selected profile, the repo values the user file shadows, and every problem
389
+ found on the way. `env` defaults to os.environ. Never raises: an unexpected failure
390
+ returns every gate off, with the failure in `errors`."""
391
+ env = os.environ if env is None else env
392
+ errors: list = []
393
+ try:
394
+ return _resolve(repo, profile, env, flags, errors, user_data, repo_data)
395
+ except Exception as exc:
396
+ errors.append(f'resolve failed: {exc!r}; every gate off')
397
+ return _result(errors)