@giamme/forge 0.12.1 → 0.13.1

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 (111) hide show
  1. package/CHANGELOG.md +66 -0
  2. package/README.md +1 -1
  3. package/SKILL.md +29 -12
  4. package/VERSION +1 -1
  5. package/docs/add-ons.md +11 -6
  6. package/docs/artifacts.md +12 -6
  7. package/docs/commands.md +179 -17
  8. package/docs/decomposed-runs.md +13 -5
  9. package/docs/forge-ui.md +14 -4
  10. package/docs/memory.md +2 -1
  11. package/docs/models.md +4 -2
  12. package/docs/reviews.md +49 -20
  13. package/docs/troubleshooting.md +3 -1
  14. package/forge +17 -1
  15. package/package.json +1 -1
  16. package/references/dataset.md +39 -13
  17. package/references/decision-models.md +763 -0
  18. package/references/decompose.md +166 -29
  19. package/references/harnesses.md +10 -3
  20. package/references/planning.md +8 -0
  21. package/references/solo.md +13 -3
  22. package/scripts/forge-artifact.sh +30 -4
  23. package/scripts/forge-config.py +238 -29
  24. package/scripts/forge-contract.py +95 -56
  25. package/scripts/forge-control.py +40 -9
  26. package/scripts/forge-decide.py +6 -0
  27. package/scripts/forge-dispatch.sh +38 -16
  28. package/scripts/forge-fail-first.py +2 -2
  29. package/scripts/forge-gate-addressed.sh +40 -0
  30. package/scripts/forge-gate-message.sh +64 -0
  31. package/scripts/forge-issues.py +321 -33
  32. package/scripts/forge-jev-options.sh +269 -42
  33. package/scripts/forge-lib-attribute.sh +447 -0
  34. package/scripts/forge-lib-gates.sh +32 -0
  35. package/scripts/forge-lib-plans.sh +22 -6
  36. package/scripts/forge-lib-review.sh +22 -17
  37. package/scripts/forge-lib-task.sh +217 -38
  38. package/scripts/forge-lib-verify.sh +45 -8
  39. package/scripts/forge-memory.sh +3 -3
  40. package/scripts/forge-parallel-options.sh +18 -5
  41. package/scripts/forge-parallel.sh +457 -303
  42. package/scripts/forge-plan-check.py +35 -1
  43. package/scripts/forge-pre-review.py +437 -0
  44. package/scripts/forge-prompt.py +25 -5
  45. package/scripts/forge-route.py +2 -2
  46. package/scripts/forge-runtime.py +10 -4
  47. package/scripts/forge-schedule.py +21 -5
  48. package/scripts/forge-shadow.py +2 -2
  49. package/scripts/forge-solo.sh +39 -9
  50. package/scripts/forge-submodules.py +389 -0
  51. package/scripts/forge-ui-options.sh +25 -0
  52. package/scripts/forge_dataset/cli.py +12 -6
  53. package/scripts/forge_dataset/export.py +140 -84
  54. package/scripts/forge_dataset/harvest.py +33 -5
  55. package/scripts/{forge_jev/outcome.py → forge_dataset/states.py} +21 -7
  56. package/scripts/forge_decide/__init__.py +141 -0
  57. package/scripts/forge_decide/budget.py +180 -0
  58. package/scripts/forge_decide/cache.py +66 -0
  59. package/scripts/forge_decide/cli.py +953 -0
  60. package/scripts/forge_decide/doctor.py +270 -0
  61. package/scripts/forge_decide/label_addressed.py +75 -0
  62. package/scripts/forge_decide/label_attribution.py +62 -0
  63. package/scripts/forge_decide/label_coverage.py +81 -0
  64. package/scripts/forge_decide/label_message.py +38 -0
  65. package/scripts/forge_decide/label_prompt.py +139 -0
  66. package/scripts/forge_decide/labels.py +328 -0
  67. package/scripts/forge_decide/metrics.py +125 -0
  68. package/scripts/forge_decide/migrate.py +226 -0
  69. package/scripts/forge_decide/providers.py +292 -0
  70. package/scripts/forge_decide/replay.py +350 -0
  71. package/scripts/forge_decide/report.py +382 -0
  72. package/scripts/forge_decide/resolve.py +397 -0
  73. package/scripts/forge_decide/sites.py +377 -0
  74. package/scripts/forge_jev/__init__.py +202 -104
  75. package/scripts/forge_jev/addressed.py +171 -0
  76. package/scripts/forge_jev/attribution.py +198 -0
  77. package/scripts/forge_jev/cli.py +460 -382
  78. package/scripts/forge_jev/client.py +155 -77
  79. package/scripts/forge_jev/coupling.py +19 -87
  80. package/scripts/forge_jev/coverage.py +303 -0
  81. package/scripts/forge_jev/findings.py +219 -0
  82. package/scripts/forge_jev/gates.py +225 -27
  83. package/scripts/forge_jev/memory.py +65 -4
  84. package/scripts/forge_jev/message.py +134 -0
  85. package/scripts/forge_jev/plan_gates.py +294 -0
  86. package/scripts/forge_jev/questions.py +173 -313
  87. package/scripts/forge_jev/verify.py +130 -104
  88. package/ui/README.md +2 -2
  89. package/ui/docs/api.md +92 -39
  90. package/ui/forge_ui/control.py +71 -14
  91. package/ui/forge_ui/export.py +2 -1
  92. package/ui/forge_ui/models.py +17 -16
  93. package/ui/forge_ui/reader.py +132 -21
  94. package/ui/forge_ui/repos.py +428 -0
  95. package/ui/forge_ui/static/app.js +24 -5
  96. package/ui/forge_ui/static/cloudmodel.js +8 -5
  97. package/ui/forge_ui/static/controls.js +20 -13
  98. package/ui/forge_ui/static/modelstats.js +12 -8
  99. package/ui/forge_ui/static/panel.js +63 -17
  100. package/ui/forge_ui/static/runmodel.js +48 -7
  101. package/ui/forge_ui/static/scene3d.js +2 -15
  102. package/ui/forge_ui/static/settings.js +481 -68
  103. package/ui/forge_ui/static/style.css +56 -9
  104. package/references/jev.md +0 -865
  105. package/scripts/forge_jev/backtest.py +0 -322
  106. package/scripts/forge_jev/corpus.py +0 -156
  107. package/scripts/forge_jev/features.py +0 -24
  108. package/scripts/forge_jev/predict.py +0 -204
  109. package/scripts/forge_jev/review.py +0 -73
  110. package/scripts/forge_jev/routing.py +0 -271
  111. package/scripts/forge_jev/subset.py +0 -123
@@ -37,31 +37,140 @@ if [ -z "${FORGE_JEV_ENV_CAPTURED:-}" ]; then
37
37
  fi
38
38
 
39
39
  JEV_CHOICE="" # "" | on | off
40
- JEV_ACT=0 # --jev-act
40
+ JEV_ACT=0 # --jev-act: still frozen as "act", no longer exported
41
41
  JEV_SHADOW=0 # --jev-shadow
42
42
  JEV_CAPS=() # entries like "tests=on" / "routing=off"
43
+ # Decision-model gate flags (#36): the resolver's run-flag level, read from
44
+ # FORGE_DECIDE_FLAGS (scripts/forge_decide/resolve.py, level 6).
45
+ DECIDE_GATES=() # --gate entries like "drift=on", in order; a later one wins
46
+ DECIDE_NO_GATES=0 # --no-gates
47
+ DECIDE_BUDGET_TOKENS="" # --decide-budget tokens=N
48
+ DECIDE_BUDGET_USD="" # --decide-budget usd=X
49
+ # forge_decide.GATES and MODES; tests/test_decide_flags.py keeps these in sync.
50
+ FORGE_DECIDE_GATE_NAMES="drift forward prompt memory-curate memory-slice memory-stale verify-discover \
51
+ coverage retry-addressed dwarf-message attribution findings"
52
+ FORGE_DECIDE_MODE_NAMES="off shadow on"
43
53
 
44
54
  forge_jev_help() {
45
55
  cat <<'HELP'
46
56
  Optional Jev (TypeSafe System One) advisory judgments (solo or parallel run):
47
57
  --jev | --no-jev Explicit choice; unattended defaults off
48
- --jev-act Kept for old commands: only marks judgments as acting
58
+ --jev-act (no effect; kept for old commands)
49
59
  --jev-shadow Record judgments only; changes nothing
50
60
  --jev-<cap> | --no-jev-<cap> Per-capability on/off: routing tests gates memory
51
- FORGE_JEV=off is a hard kill switch and wins over every other setting.
52
- Setup, status, doctor and enable/disable live under ./forge jev --help.
61
+ Decision-model gates for this run (frozen at plan time; win over every config level):
62
+ --gate NAME=MODE[,NAME=MODE...] Set gates off, shadow or on; repeatable, a later one wins
63
+ gates: drift forward prompt memory-curate memory-slice
64
+ memory-stale verify-discover coverage retry-addressed
65
+ dwarf-message attribution findings
66
+ --no-gates Every gate off: no decision-model request at all
67
+ --decide-budget tokens=N[,usd=X] Cap this run's decision-model spend
68
+ FORGE_JEV=off is a hard kill switch and wins over every other setting, and a repo's
69
+ privacy floor (.forge/decide.json) wins over that.
70
+ Setup, status, doctor and enable/disable live under ./forge jev --help and ./forge decide --help.
53
71
  HELP
54
72
  }
55
73
 
74
+ # _forge_decide_word <word> <list> — succeeds when <word> is one of the
75
+ # space-separated <list>.
76
+ _forge_decide_word() {
77
+ case " $2 " in *" $1 "*) return 0 ;; esac
78
+ return 1
79
+ }
80
+
81
+ # _forge_decide_gate_list <list> — validate and append `name=mode[,name=mode...]` to
82
+ # DECIDE_GATES. Nothing is appended unless every entry is valid.
83
+ _forge_decide_gate_list() {
84
+ local list="$1" entry name mode added=()
85
+ if [ -z "$list" ]; then
86
+ echo "--gate needs name=mode[,name=mode...]; gates: $FORGE_DECIDE_GATE_NAMES; modes: $FORGE_DECIDE_MODE_NAMES" >&2
87
+ return 2
88
+ fi
89
+ local IFS=,
90
+ for entry in $list; do
91
+ name="${entry%%=*}"; mode="${entry#*=}"
92
+ if [ "$name" = "$entry" ] || [ -z "$name" ]; then
93
+ echo "--gate: '$entry' is not name=mode; gates: $FORGE_DECIDE_GATE_NAMES; modes: $FORGE_DECIDE_MODE_NAMES" >&2
94
+ return 2
95
+ fi
96
+ if ! _forge_decide_word "$name" "$FORGE_DECIDE_GATE_NAMES"; then
97
+ echo "--gate: unknown gate '$name'; gates: $FORGE_DECIDE_GATE_NAMES" >&2
98
+ return 2
99
+ fi
100
+ if ! _forge_decide_word "$mode" "$FORGE_DECIDE_MODE_NAMES"; then
101
+ echo "--gate: $name=$mode is not a mode; modes: $FORGE_DECIDE_MODE_NAMES" >&2
102
+ return 2
103
+ fi
104
+ added+=("$name=$mode")
105
+ done
106
+ if [ "${#added[@]}" -eq 0 ]; then
107
+ echo "--gate needs name=mode[,name=mode...]; gates: $FORGE_DECIDE_GATE_NAMES; modes: $FORGE_DECIDE_MODE_NAMES" >&2
108
+ return 2
109
+ fi
110
+ DECIDE_GATES+=("${added[@]}")
111
+ return 0
112
+ }
113
+
114
+ # _forge_decide_budget_spec <spec> — validate `tokens=N[,usd=X]` into
115
+ # DECIDE_BUDGET_TOKENS / DECIDE_BUDGET_USD; a field it does not name is kept.
116
+ _forge_decide_budget_spec() {
117
+ local spec="$1" part field value tokens="$DECIDE_BUDGET_TOKENS" usd="$DECIDE_BUDGET_USD"
118
+ local usage="--decide-budget expects tokens=N[,usd=X] (N a whole number, X a number, both >= 0)"
119
+ [ -n "$spec" ] || { echo "$usage" >&2; return 2; }
120
+ local IFS=,
121
+ for part in $spec; do
122
+ field="${part%%=*}"; value="${part#*=}"
123
+ [ "$field" != "$part" ] || { echo "$usage; got '$part'" >&2; return 2; }
124
+ case "$field" in
125
+ tokens)
126
+ printf '%s' "$value" | grep -Eq '^[0-9]+$' || { echo "$usage; got tokens=$value" >&2; return 2; }
127
+ tokens="$value" ;;
128
+ usd)
129
+ printf '%s' "$value" | grep -Eq '^([0-9]+(\.[0-9]*)?|\.[0-9]+)$' || { echo "$usage; got usd=$value" >&2; return 2; }
130
+ usd="$value" ;;
131
+ *) echo "$usage; got '$part'" >&2; return 2 ;;
132
+ esac
133
+ done
134
+ DECIDE_BUDGET_TOKENS="$tokens"; DECIDE_BUDGET_USD="$usd"
135
+ return 0
136
+ }
137
+
138
+ # Any of the decide flags was given (or restored).
139
+ _forge_decide_flags_set() {
140
+ [ "${#DECIDE_GATES[@]}" -gt 0 ] || [ "$DECIDE_NO_GATES" = 1 ] \
141
+ || [ -n "$DECIDE_BUDGET_TOKENS" ] || [ -n "$DECIDE_BUDGET_USD" ]
142
+ }
143
+
56
144
  # forge_jev_flag "$@" — parse ONE option from the front of the argument list.
57
145
  # Echoes nothing. Returns 0 and sets JEV_SHIFT to the number of argv items
58
- # consumed (always 1 for our flags) when the option is ours; returns 1 and sets
59
- # JEV_SHIFT=0 when the first argument is not one of ours; returns 2 on a usage
60
- # error (message on stderr), also with JEV_SHIFT unset/irrelevant.
146
+ # consumed (2 for `--gate LIST` and `--decide-budget SPEC`, else 1) when the option
147
+ # is ours; returns 1 and sets JEV_SHIFT=0 when the first argument is not one of ours;
148
+ # returns 2 on a usage error (message on stderr), also with JEV_SHIFT unset/irrelevant.
61
149
  forge_jev_flag() {
62
150
  local opt="$1"
63
151
  JEV_SHIFT=0
64
152
  case "$opt" in
153
+ --gate)
154
+ [ $# -ge 2 ] || { echo "--gate needs name=mode[,name=mode...]; gates: $FORGE_DECIDE_GATE_NAMES; modes: $FORGE_DECIDE_MODE_NAMES" >&2; return 2; }
155
+ _forge_decide_gate_list "$2" || return 2
156
+ JEV_SHIFT=2; return 0
157
+ ;;
158
+ --gate=*)
159
+ _forge_decide_gate_list "${opt#--gate=}" || return 2
160
+ JEV_SHIFT=1; return 0
161
+ ;;
162
+ --no-gates)
163
+ DECIDE_NO_GATES=1; JEV_SHIFT=1; return 0
164
+ ;;
165
+ --decide-budget)
166
+ [ $# -ge 2 ] || { echo "--decide-budget expects tokens=N[,usd=X]" >&2; return 2; }
167
+ _forge_decide_budget_spec "$2" || return 2
168
+ JEV_SHIFT=2; return 0
169
+ ;;
170
+ --decide-budget=*)
171
+ _forge_decide_budget_spec "${opt#--decide-budget=}" || return 2
172
+ JEV_SHIFT=1; return 0
173
+ ;;
65
174
  --jev)
66
175
  [ -z "$JEV_CHOICE" ] || [ "$JEV_CHOICE" = on ] || { echo '--jev and --no-jev are mutually exclusive' >&2; return 2; }
67
176
  JEV_CHOICE=on; JEV_SHIFT=1; return 0
@@ -71,7 +180,15 @@ forge_jev_flag() {
71
180
  JEV_CHOICE=off; JEV_SHIFT=1; return 0
72
181
  ;;
73
182
  --jev-act)
74
- JEV_ACT=1; JEV_SHIFT=1; return 0
183
+ # Once per command. Restore and settle of a frozen selection set JEV_ACT
184
+ # without coming through here, so they stay silent.
185
+ JEV_ACT=1
186
+ if [ "${JEV_ACT_WARNED:-}" != 1 ]; then
187
+ echo "forge: --jev-act no longer does anything; decision models never change a task's tier or model" >&2
188
+ JEV_ACT_WARNED=1
189
+ fi
190
+ JEV_SHIFT=1
191
+ return 0
75
192
  ;;
76
193
  --jev-shadow)
77
194
  JEV_SHADOW=1; JEV_SHIFT=1; return 0
@@ -126,8 +243,39 @@ forge_jev_export() {
126
243
  memory) export FORGE_JEV_MEMORY="$val" ;;
127
244
  esac
128
245
  done
129
- if [ "$JEV_ACT" = 1 ]; then export FORGE_JEV_ACT=on; else unset FORGE_JEV_ACT 2>/dev/null || true; fi
246
+ # Recorded in jev-selection.json and never exported: nothing reads it any more.
247
+ unset FORGE_JEV_ACT 2>/dev/null || true
130
248
  if [ "$JEV_SHADOW" = 1 ]; then export FORGE_JEV_SHADOW=on; else unset FORGE_JEV_SHADOW 2>/dev/null || true; fi
249
+ # The run-flag level of the gate resolver. Unset with no decide flag, so a run
250
+ # without them never carries an earlier command's choice.
251
+ if _forge_decide_flags_set; then
252
+ FORGE_DECIDE_FLAGS="$(_forge_decide_flags_json)" || return $?
253
+ export FORGE_DECIDE_FLAGS
254
+ else
255
+ unset FORGE_DECIDE_FLAGS 2>/dev/null || true
256
+ fi
257
+ }
258
+
259
+ # _forge_decide_flags_json — the parsed decide flags as one JSON object,
260
+ # {"gates": {gate: mode}, "no_gates": bool, "budget": {"run_tokens": N, "run_usd": X}},
261
+ # the shape FORGE_DECIDE_FLAGS and jev-selection.json hold. A later --gate for the
262
+ # same gate wins.
263
+ _forge_decide_flags_json() {
264
+ python3 -c '
265
+ import json, sys
266
+ no_gates, tokens, usd = sys.argv[1:4]
267
+ gates = {}
268
+ for entry in sys.argv[4:]:
269
+ name, _, mode = entry.partition("=")
270
+ gates[name] = mode
271
+ budget = {}
272
+ if tokens:
273
+ budget["run_tokens"] = int(tokens)
274
+ if usd:
275
+ budget["run_usd"] = float(usd)
276
+ print(json.dumps(dict(gates=gates, no_gates=no_gates == "1", budget=budget), sort_keys=True))
277
+ ' "$DECIDE_NO_GATES" "$DECIDE_BUDGET_TOKENS" "$DECIDE_BUDGET_USD" \
278
+ ${DECIDE_GATES[@]+"${DECIDE_GATES[@]}"}
131
279
  }
132
280
 
133
281
  # forge_jev_record <run-dir> — freeze the resolved selection into
@@ -143,19 +291,27 @@ forge_jev_record() {
143
291
  else caps_json="$caps_json, \"$cap\": \"$val\""; fi
144
292
  done
145
293
  [ "$first" = 1 ] || caps_json="$caps_json}"
294
+ local decide_json
295
+ decide_json="$(_forge_decide_flags_json)" || return $?
146
296
  python3 -c '
147
297
  import json, sys
148
- run, choice, act, shadow, caps_json = sys.argv[1:6]
298
+ run, choice, act, shadow, caps_json, decide_json = sys.argv[1:7]
299
+ decide = json.loads(decide_json)
149
300
  data = {
150
301
  "choice": choice if choice else None,
151
302
  "act": act == "1",
152
303
  "shadow": shadow == "1",
153
304
  "capabilities": json.loads(caps_json),
305
+ # The decide run flags (--gate, --no-gates, --decide-budget). A file without
306
+ # these keys, from an older plan, restores as no flags.
307
+ "gates": decide["gates"],
308
+ "no_gates": decide["no_gates"],
309
+ "decide_budget": decide["budget"],
154
310
  }
155
311
  with open(run + "/jev-selection.json", "w") as fh:
156
312
  json.dump(data, fh, indent=2, sort_keys=True)
157
313
  fh.write("\n")
158
- ' "$run" "$JEV_CHOICE" "$JEV_ACT" "$JEV_SHADOW" "$caps_json"
314
+ ' "$run" "$JEV_CHOICE" "$JEV_ACT" "$JEV_SHADOW" "$caps_json" "$decide_json"
159
315
  }
160
316
 
161
317
  # forge_jev_restore <run-dir> — re-export a previously frozen selection, for
@@ -170,9 +326,14 @@ forge_jev_restore() {
170
326
  selection="$run/jev-selection.json"
171
327
  [ -f "$selection" ] || return 0
172
328
  JEV_CAPS=()
329
+ DECIDE_GATES=(); DECIDE_NO_GATES=0; DECIDE_BUDGET_TOKENS=""; DECIDE_BUDGET_USD=""
173
330
  local parsed
331
+ # After the three fixed lines, each line is tagged: cap:, gate:, no_gates:, tokens:
332
+ # or usd:. A value the flags could not have produced is dropped, as the resolver
333
+ # would drop it.
174
334
  parsed="$(python3 -c '
175
335
  import json, sys
336
+ gate_names, mode_names = sys.argv[2].split(), sys.argv[3].split()
176
337
  with open(sys.argv[1]) as fh:
177
338
  data = json.load(fh)
178
339
  choice = data.get("choice") or ""
@@ -180,15 +341,36 @@ print(choice)
180
341
  print("1" if data.get("act") else "0")
181
342
  print("1" if data.get("shadow") else "0")
182
343
  for cap, val in sorted((data.get("capabilities") or {}).items()):
183
- print(cap + "=" + val)
184
- ' "$selection")" || return $?
344
+ print("cap:" + cap + "=" + val)
345
+ gates = data.get("gates")
346
+ for name, mode in sorted((gates if isinstance(gates, dict) else {}).items()):
347
+ if name in gate_names and mode in mode_names:
348
+ print("gate:" + name + "=" + mode)
349
+ if data.get("no_gates") is True:
350
+ print("no_gates:1")
351
+ budget = data.get("decide_budget")
352
+ budget = budget if isinstance(budget, dict) else {}
353
+ tokens, usd = budget.get("run_tokens"), budget.get("run_usd")
354
+ if isinstance(tokens, int) and not isinstance(tokens, bool) and tokens >= 0:
355
+ print("tokens:%d" % tokens)
356
+ if isinstance(usd, (int, float)) and not isinstance(usd, bool) and 0 <= usd < float("inf"):
357
+ print("usd:%r" % float(usd))
358
+ ' "$selection" "$FORGE_DECIDE_GATE_NAMES" "$FORGE_DECIDE_MODE_NAMES")" || return $?
185
359
  local i=0
186
360
  while IFS= read -r line; do
187
361
  case "$i" in
188
362
  0) JEV_CHOICE="$line" ;;
189
363
  1) JEV_ACT="$line" ;;
190
364
  2) JEV_SHADOW="$line" ;;
191
- *) [ -z "$line" ] || JEV_CAPS+=("$line") ;;
365
+ *)
366
+ case "$line" in
367
+ cap:*) JEV_CAPS+=("${line#cap:}") ;;
368
+ gate:*) DECIDE_GATES+=("${line#gate:}") ;;
369
+ no_gates:1) DECIDE_NO_GATES=1 ;;
370
+ tokens:*) DECIDE_BUDGET_TOKENS="${line#tokens:}" ;;
371
+ usd:*) DECIDE_BUDGET_USD="${line#usd:}" ;;
372
+ esac
373
+ ;;
192
374
  esac
193
375
  i=$((i + 1))
194
376
  done <<EOF
@@ -212,7 +394,7 @@ forge_jev_settle() {
212
394
  local plan="$1"
213
395
  if [ -f "$plan/jev-selection.json" ]; then
214
396
  if [ -n "$JEV_CHOICE" ] || [ "$JEV_ACT" = 1 ] || [ "$JEV_SHADOW" = 1 ] \
215
- || [ "${#JEV_CAPS[@]}" -gt 0 ]; then
397
+ || [ "${#JEV_CAPS[@]}" -gt 0 ] || _forge_decide_flags_set; then
216
398
  printf 'forge: jev: using the selection frozen at plan time; ignoring the flags given here\n' >&2
217
399
  fi
218
400
  forge_jev_restore "$plan"
@@ -222,38 +404,83 @@ forge_jev_settle() {
222
404
  fi
223
405
  }
224
406
 
225
- # forge_jev_active <capability> — succeeds (0) when Jev is enabled for that
226
- # capability AND a key is configured; fails (non-zero) otherwise, including when
227
- # the Python package is missing, the config is unreadable, or anything else goes
228
- # wrong. Silent (no stdout/stderr) and never blocks: it only reads local config
229
- # through `forge-jev.py status --json`, never the network.
407
+ # forge_decide_active <gate> — succeeds (0) when that gate's site can be asked:
408
+ # `forge-jev.py status --json` → gates.<gate>.ready, which means the gate is shadow or
409
+ # on after every level (run flags, the kill switch and the privacy floor included) and
410
+ # its provider has a key or is local. Fails (non-zero) otherwise, including when the
411
+ # Python package is missing, the config is unreadable, or anything else goes wrong.
412
+ # Silent (no stdout/stderr) and never blocks: it only reads local config, never the
413
+ # network. A shadowed gate passes too; the Python command asks it and prints nothing.
230
414
  #
231
415
  # The status JSON is fetched at most once per shell (cached in
232
- # FORGE_JEV_STATUS_JSON/FORGE_JEV_STATUS_FETCHED) so a caller checking several
233
- # capabilities, or the same capability more than once in one verify_result call,
234
- # pays for one subprocess instead of one per check.
235
- FORGE_JEV_STATUS_JSON=""
236
- FORGE_JEV_STATUS_FETCHED=0
237
- forge_jev_active() {
238
- local cap="$1"
239
- if [ "$FORGE_JEV_STATUS_FETCHED" != 1 ]; then
240
- FORGE_JEV_STATUS_FETCHED=1
241
- FORGE_JEV_STATUS_JSON="$(python3 "$SKILL_DIR/scripts/forge-jev.py" status --json 2>/dev/null)" \
242
- || FORGE_JEV_STATUS_JSON=""
416
+ # FORGE_DECIDE_STATUS_JSON/FORGE_DECIDE_STATUS_FETCHED) so a caller checking several
417
+ # gates, or the same gate more than once in one verify_result call, pays for one
418
+ # subprocess instead of one per check. It reads FORGE_DECIDE_FLAGS and
419
+ # FORGE_DECIDE_REPO, so the runners export both before the first check.
420
+ FORGE_DECIDE_STATUS_JSON=""
421
+ FORGE_DECIDE_STATUS_FETCHED=0
422
+ forge_decide_active() {
423
+ local gate="$1"
424
+ if [ "$FORGE_DECIDE_STATUS_FETCHED" != 1 ]; then
425
+ FORGE_DECIDE_STATUS_FETCHED=1
426
+ FORGE_DECIDE_STATUS_JSON="$(python3 "$SKILL_DIR/scripts/forge-jev.py" status --json 2>/dev/null)" \
427
+ || FORGE_DECIDE_STATUS_JSON=""
243
428
  fi
244
- [ -n "$FORGE_JEV_STATUS_JSON" ] || return 1
245
- printf '%s' "$FORGE_JEV_STATUS_JSON" | python3 -c '
429
+ [ -n "$FORGE_DECIDE_STATUS_JSON" ] || return 1
430
+ printf '%s' "$FORGE_DECIDE_STATUS_JSON" | python3 -c '
431
+ import json, sys
432
+ try:
433
+ gate = json.load(sys.stdin)["gates"][sys.argv[1]]
434
+ except Exception:
435
+ sys.exit(1)
436
+ sys.exit(0 if isinstance(gate, dict) and gate.get("ready") is True else 1)
437
+ ' "$gate" 2>/dev/null
438
+ }
439
+
440
+ # forge_decide_env <repo> <run-dir> — export what the privacy check and the budget's
441
+ # per-run counter read: FORGE_DECIDE_REPO (the repo's top level) and
442
+ # FORGE_DECIDE_RUN_DIR (the plan dir, or a solo run dir), both absolute. Call it
443
+ # before the first decision-model step; it drops the cached status, which depends on
444
+ # the repo.
445
+ forge_decide_env() {
446
+ local repo="$1" run="$2" top
447
+ top="$(git -C "$repo" rev-parse --show-toplevel 2>/dev/null)" || top=""
448
+ [ -n "$top" ] || top="$(cd "$repo" 2>/dev/null && pwd)" || top="$repo"
449
+ export FORGE_DECIDE_REPO="$top"
450
+ export FORGE_DECIDE_RUN_DIR="$(cd "$run" 2>/dev/null && pwd || printf '%s' "$run")"
451
+ FORGE_DECIDE_STATUS_FETCHED=0
452
+ FORGE_DECIDE_STATUS_JSON=""
453
+ }
454
+
455
+ # forge_decide_plan_lines <repo> — the advisory lines `plan` prints after its table:
456
+ # the repo's privacy floor, then which gates are on and in shadow. Prints nothing when
457
+ # neither applies, and nothing at all when they cannot be computed.
458
+ forge_decide_plan_lines() {
459
+ local repo="$1" status lines
460
+ status="$(python3 "$SKILL_DIR/scripts/forge-decide.py" status --repo "$repo" --json 2>/dev/null)" || return 0
461
+ [ -n "$status" ] || return 0
462
+ lines="$(printf '%s' "$status" | python3 -c '
246
463
  import json, sys
247
- cap = sys.argv[1]
464
+ repo = sys.argv[1]
248
465
  try:
249
466
  data = json.load(sys.stdin)
250
- except ValueError:
467
+ lines = []
468
+ privacy = data.get("privacy") or {}
469
+ if privacy.get("floor") is True:
470
+ lines.append("decide: %s is under a privacy floor (.forge/decide.json): "
471
+ "no decision-model request will be sent" % repo)
472
+ gates = data.get("gates") or {}
473
+ on = [name + (" (forced)" if gate.get("forced") else "")
474
+ for name, gate in gates.items() if gate.get("mode") == "on"]
475
+ shadow = [name for name, gate in gates.items() if gate.get("mode") == "shadow"]
476
+ if on or shadow:
477
+ lines.append("decide: on: %s; shadow: %s" % (", ".join(on) or "none",
478
+ ", ".join(shadow) or "none"))
479
+ except Exception:
251
480
  sys.exit(1)
252
- # capability_ready: some site of this capability has credentials for the provider it
253
- # uses (a Cloudflare-only setup has no TypeSafe key). Older status output lacks it.
254
- ready = data.get("capability_ready")
255
- if isinstance(ready, dict):
256
- sys.exit(0 if ready.get(cap) else 1)
257
- sys.exit(0 if data.get("key_present") and data.get("capabilities", {}).get(cap) else 1)
258
- ' "$cap" 2>/dev/null
481
+ for line in lines:
482
+ print(line)
483
+ ' "$repo" 2>/dev/null)" || return 0
484
+ [ -z "$lines" ] || printf '%s\n' "$lines" | sed 's/^/forge: /' >&2
485
+ return 0
259
486
  }