@giamme/forge 0.14.0 → 0.15.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 (44) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/SKILL.md +47 -14
  3. package/VERSION +1 -1
  4. package/docs/artifacts.md +2 -1
  5. package/docs/commands.md +301 -7
  6. package/docs/models.md +53 -0
  7. package/package.json +1 -1
  8. package/references/dataset.md +12 -3
  9. package/references/decompose.md +108 -7
  10. package/references/harnesses.md +21 -1
  11. package/references/planning.md +59 -0
  12. package/references/ui.md +39 -1
  13. package/scripts/forge-compare.py +6 -3
  14. package/scripts/forge-config.py +531 -4
  15. package/scripts/forge-dispatch.sh +132 -22
  16. package/scripts/forge-lib-plans.sh +19 -2
  17. package/scripts/forge-lib-review.sh +5 -3
  18. package/scripts/forge-lib-task.sh +119 -0
  19. package/scripts/forge-parallel-options.sh +12 -6
  20. package/scripts/forge-parallel.sh +572 -26
  21. package/scripts/forge-plan-check.py +591 -8
  22. package/scripts/forge-planner.py +480 -0
  23. package/scripts/forge-route.py +72 -23
  24. package/scripts/forge-runtime.py +157 -1
  25. package/scripts/forge-shadow.py +51 -7
  26. package/scripts/forge-solo.sh +81 -7
  27. package/scripts/forge_dataset/cli.py +10 -0
  28. package/scripts/forge_dataset/efforts.py +215 -0
  29. package/scripts/forge_dataset/harvest.py +44 -0
  30. package/scripts/forge_decide/__init__.py +19 -1
  31. package/scripts/forge_decide/builtin_profiles.json +25 -0
  32. package/scripts/forge_decide/cli.py +12 -0
  33. package/scripts/forge_decide/profiles.py +866 -0
  34. package/scripts/forge_decide/resolve.py +38 -6
  35. package/ui/docs/api.md +87 -8
  36. package/ui/forge_ui/control.py +173 -12
  37. package/ui/forge_ui/executions.py +28 -8
  38. package/ui/forge_ui/models.py +60 -1
  39. package/ui/forge_ui/reader.py +21 -1
  40. package/ui/forge_ui/static/leaderboard.js +5 -1
  41. package/ui/forge_ui/static/modelstats.js +25 -1
  42. package/ui/forge_ui/static/panel.js +19 -2
  43. package/ui/forge_ui/static/settings.js +788 -25
  44. package/ui/forge_ui/static/style.css +23 -0
@@ -15,6 +15,11 @@
15
15
  # (claude, openclaude)
16
16
  # any role: [--no-ripwire] [--ripwire-query-file <requirements>]
17
17
  # any role: [--timeout <seconds>] 0 disables the watchdog
18
+ # any role: [--service-tier fast] codex and claude only; any other harness exits 3
19
+ # before it runs. doctor --spec takes the same option.
20
+ # forge-dispatch.sh doctor --spec <spec> [--role dwarf|qa|planner] [--service-tier fast]
21
+ # A measured slowdown is `forge: note: …` on stderr, never in
22
+ # the resolved block. A plain dispatch does not print it.
18
23
  # forge-dispatch.sh efforts --spec <spec>
19
24
  # the efforts this pairing accepts, weakest first, one per
20
25
  # line. Prints nothing when the pairing has no ladder or no
@@ -33,9 +38,16 @@
33
38
  # Environment: FORGE_REGISTRY alternate registry file (default: <skill>/registry.tsv)
34
39
  # FORGE_ORPHAN_GUARD off = do not run the harness in its own process group
35
40
  # (default on; also skipped under FORGE_FRACTAL_RUN)
41
+ # FORGE_RESULT_GRACE claude/openclaude: seconds a log that ends in the model's final
42
+ # result may stay silent before forge ends the harness (an open
43
+ # background task keeps it up); default 1800, 0 = off. Either way
44
+ # a dispatch killed after that result is not a timeout.
36
45
  #
37
46
  # Exit codes: 0 ok | 2 usage/resolution error | 3 harness missing or unusable
47
+ # (including a --service-tier fast the harness cannot take per invocation)
38
48
  # 4 backend ran but failed | 7 backend exceeded --timeout and was killed
49
+ # (not when its log ended in a final result and only background tasks kept it up:
50
+ # that result stands, as after FORGE_RESULT_GRACE; $ROLE.settled says which)
39
51
  # 8 infrastructure failure (auth, usage_limit, budget, capacity, rate_limit,
40
52
  # provider_down, network, or an empty answer; forge_infra.py says what each
41
53
  # means): the model never got to do its work. $ROLE.infra says which.
@@ -200,7 +212,7 @@ if [ "$ROLE" = report ]; then python3 "$RUNTIME" report "${1:?report needs a run
200
212
  PREFLIGHT=0
201
213
  if [ "$ROLE" = doctor ]; then
202
214
  if [ $# = 0 ]; then doctor; exit $?; fi
203
- [ "${1:-}" = --spec ] || die "doctor accepts --spec <spec> [--role dwarf|qa|planner]"
215
+ [ "${1:-}" = --spec ] || die "doctor accepts --spec <spec> [--role dwarf|qa|planner] [--service-tier fast]"
204
216
  SPEC_CHECK="${2:?--spec needs a spec}"; shift 2
205
217
  ROLE=dwarf
206
218
  if [ "${1:-}" = --role ]; then ROLE="${2:?}"; shift 2; fi
@@ -221,7 +233,7 @@ SPEC="$1"; shift
221
233
 
222
234
  RIPWIRE_QUERY=""
223
235
  OUTPUT=full
224
- REPO="$PWD"; RUN_DIR=""; PROMPT_FILE=""; YOLO=0; DRY=0; REVIEW_BASE=""; PROMPT_VIA_STDIN=0; NATIVE_REVIEW=0; CONTINUE_ID=""; CONTINUE_GIVEN=0; AGY_TIMEOUT="30m"; TIMEOUT_FLAG=""
236
+ REPO="$PWD"; RUN_DIR=""; PROMPT_FILE=""; YOLO=0; DRY=0; REVIEW_BASE=""; PROMPT_VIA_STDIN=0; NATIVE_REVIEW=0; CONTINUE_ID=""; CONTINUE_GIVEN=0; AGY_TIMEOUT="30m"; TIMEOUT_FLAG=""; SERVICE_TIER=""
225
237
  while [ $# -gt 0 ]; do
226
238
  case "$1" in
227
239
  --no-ripwire) export FORGE_RIPWIRE=off; shift ;;
@@ -235,6 +247,7 @@ while [ $# -gt 0 ]; do
235
247
  --continue-session) [ $# -ge 2 ] || die "--continue-session needs a session id"; CONTINUE_ID="$2"; CONTINUE_GIVEN=1; shift 2 ;;
236
248
  --agy-timeout) AGY_TIMEOUT="${2:?--agy-timeout needs a value}"; shift 2 ;;
237
249
  --timeout) TIMEOUT_FLAG="${2:?--timeout needs a value in seconds, 0 to disable}"; shift 2 ;;
250
+ --service-tier) [ $# -ge 2 ] || die "--service-tier needs a value"; [ "$2" = fast ] || die "--service-tier accepts only fast"; SERVICE_TIER=fast; shift 2 ;;
238
251
  --yolo) YOLO=1; shift ;;
239
252
  --dry-run) DRY=1; shift ;;
240
253
  *) die "unknown option '$1'" ;;
@@ -348,6 +361,13 @@ if [ -n "$EFFORT" ] && [ -n "$LADDER" ] && [ "$(idx_in "$EFFORT" "$LADDER")" -lt
348
361
  die "invalid effort '$EFFORT' for $HARNESS"
349
362
  fi
350
363
 
364
+ # codex and claude can ask for the fast tier on this invocation. The others cannot
365
+ # (opencode's fast mode is per-model config; the rest have none). Refuse before
366
+ # preflight, so doctor --spec and a dispatch both stop before those CLIs start.
367
+ if [ "$SERVICE_TIER" = fast ] && [ "$HARNESS" != codex ] && [ "$HARNESS" != claude ]; then
368
+ die "$HARNESS has no per-invocation fast tier (#68); drop the fast tier for the $ROLE role or pick a codex or claude spec" 3
369
+ fi
370
+
351
371
  # --- resolve timeout ----------------------------------------------------------
352
372
  # Explicit (--timeout, FORGE_TIMEOUT) wins as given, including 0. Otherwise the registry
353
373
  # row's `timeout` column, then 2700. Only those two defaults scale with the resolved
@@ -371,6 +391,15 @@ if [ "$LIMIT_SOURCE" = registry ] || [ "$LIMIT_SOURCE" = default ]; then
371
391
  fi
372
392
  fi
373
393
 
394
+ # --- the grace after a final result (#110) --------------------------------------
395
+ # claude and openclaude stay up while a background task of the session is open, even after the
396
+ # model's final result. Once the log ends in that result and stays silent this long, forge ends
397
+ # the harness and the result stands. Long on purpose: a background test run can wake the session
398
+ # for another turn many minutes later.
399
+ RESULT_GRACE="${FORGE_RESULT_GRACE:-1800}"
400
+ case "$RESULT_GRACE" in ''|*[!0-9]*) die "FORGE_RESULT_GRACE must be a nonnegative integer" ;; esac
401
+ [ "${#RESULT_GRACE}" -gt 9 ] || RESULT_GRACE=$((10#$RESULT_GRACE))
402
+
374
403
  # --- run dir & prompt ---------------------------------------------------------
375
404
  [ -d "$REPO" ] || die "--repo '$REPO' is not a directory"
376
405
  REPO="$(cd "$REPO" && pwd)"
@@ -388,7 +417,7 @@ write_continue() { :; } # redefined below once there is an attempt to archive
388
417
  ATTEMPT=""
389
418
  if [ "$PREFLIGHT" != 1 ] && [ "$DRY" != 1 ]; then
390
419
  ATTEMPT="$(python3 "$RUNTIME" begin "$RUN_DIR" "$ROLE")" || exit 3
391
- rm -f "$RUN_DIR/$ROLE.last" "$RUN_DIR/$ROLE.log" "$RUN_DIR/$ROLE.clock" "$RUN_DIR/$ROLE.resolved" "$RUN_DIR/$ROLE.cmd" "$RUN_DIR/$ROLE.timedout" "$RUN_DIR/$ROLE.infra" "$RUN_DIR/$ROLE.orphans" "$RUN_DIR/$ROLE.session" "$RUN_DIR/$ROLE.continue" "$RUN_DIR/$ROLE.harness"
420
+ rm -f "$RUN_DIR/$ROLE.last" "$RUN_DIR/$ROLE.log" "$RUN_DIR/$ROLE.clock" "$RUN_DIR/$ROLE.resolved" "$RUN_DIR/$ROLE.cmd" "$RUN_DIR/$ROLE.timedout" "$RUN_DIR/$ROLE.settled" "$RUN_DIR/$ROLE.infra" "$RUN_DIR/$ROLE.orphans" "$RUN_DIR/$ROLE.session" "$RUN_DIR/$ROLE.continue" "$RUN_DIR/$ROLE.harness"
392
421
  trap 'exit 143' TERM
393
422
  trap 'exit 130' INT
394
423
  # GUARD_ON is 1 only when the harness was started in its own process group (see the
@@ -404,7 +433,7 @@ if [ "$PREFLIGHT" != 1 ] && [ "$DRY" != 1 ]; then
404
433
  # Interrupted after the harness exited but before the normal reap.
405
434
  python3 "$GUARD" reap "$hpid" "$RUN_DIR/$ROLE.orphans" >/dev/null 2>&1
406
435
  fi
407
- if [ -n "${wpid:-}" ]; then pkill -P "$wpid" 2>/dev/null; kill "$wpid" 2>/dev/null; fi
436
+ for watcher in ${wpid:-} ${spid:-}; do pkill -P "$watcher" 2>/dev/null; kill "$watcher" 2>/dev/null; done
408
437
  [ -z "${cpid:-}" ] || kill "$cpid" 2>/dev/null
409
438
  rm -f "$RUN_DIR/$ROLE.harness"
410
439
  }
@@ -505,6 +534,7 @@ build_cmd() {
505
534
  # subshell cd below.
506
535
  CMD=(codex exec review --json -m "$MODEL" --skip-git-repo-check -o "$LAST")
507
536
  [ -n "$EFFORT" ] && CMD+=(-c "model_reasoning_effort=$EFFORT")
537
+ [ "$SERVICE_TIER" = fast ] && CMD+=(-c "service_tier=fast")
508
538
  if [ -n "$REVIEW_BASE" ]; then CMD+=(--base "$REVIEW_BASE"); else CMD+=(--uncommitted); fi
509
539
  if [ "$YOLO" = 1 ]; then CMD+=(--dangerously-bypass-approvals-and-sandbox); fi
510
540
  elif [ -n "$CONTINUE_ID" ]; then
@@ -516,6 +546,7 @@ build_cmd() {
516
546
  case "$CONTINUE_ID" in -*) ;; *) CMD+=("$CONTINUE_ID") ;; esac
517
547
  CMD+=(--json -m "$MODEL" --skip-git-repo-check -o "$LAST")
518
548
  [ -n "$EFFORT" ] && CMD+=(-c "model_reasoning_effort=$EFFORT")
549
+ [ "$SERVICE_TIER" = fast ] && CMD+=(-c "service_tier=fast")
519
550
  if [ "$YOLO" = 1 ]; then CMD+=(--dangerously-bypass-approvals-and-sandbox)
520
551
  else CMD+=(-c 'sandbox_mode="read-only"'); fi
521
552
  case "$CONTINUE_ID" in -*) CMD+=(-- "$CONTINUE_ID") ;; esac
@@ -524,6 +555,7 @@ build_cmd() {
524
555
  else
525
556
  CMD=(codex exec --json -m "$MODEL" -C "$REPO" --skip-git-repo-check -o "$LAST")
526
557
  [ -n "$EFFORT" ] && CMD+=(-c "model_reasoning_effort=$EFFORT")
558
+ [ "$SERVICE_TIER" = fast ] && CMD+=(-c "service_tier=fast")
527
559
  # --approve-for-me and --dangerously-bypass-... are mutually exclusive.
528
560
  if [ "$YOLO" = 1 ]; then CMD+=(--dangerously-bypass-approvals-and-sandbox)
529
561
  elif [ "$ROLE" = "dwarf" ]; then CMD+=(--approve-for-me)
@@ -542,6 +574,9 @@ build_cmd() {
542
574
  # takes the final message and the tokens from. stream-json needs --verbose with -p.
543
575
  CMD+=(--output-format stream-json --verbose)
544
576
  [ -n "$EFFORT" ] && CMD+=(--effort "$EFFORT")
577
+ # Hidden: claude --help does not list it. openclaude has no per-invocation tier
578
+ # and is refused before build_cmd; this guard keeps the flag off its argv too.
579
+ [ "$SERVICE_TIER" = fast ] && [ "$HARNESS" = claude ] && CMD+=(--fast-mode on)
545
580
  # Before the variadic flags below, which would otherwise swallow it.
546
581
  # --resume takes an optional value, so an id that starts with '-' is joined with '='.
547
582
  case "$CONTINUE_ID" in
@@ -652,6 +687,8 @@ unadvertised_flag() { # unadvertised_flag <help text>
652
687
  -*) flag="${arg%%=*}"
653
688
  # grok's help hides this one; preflight_command checks it with a probe instead.
654
689
  [ "$HARNESS $flag" = "grok --background-wait-timeout" ] && continue
690
+ # claude's help hides this one. Unlike grok's, nothing probes it: this exemption is the whole check.
691
+ [ "$HARNESS $flag" = "claude --fast-mode" ] && continue
655
692
  printf '%s\n' "$1" | grep -E -- "(^|[[:space:],|])$flag([=[:space:],|]|$)" >/dev/null || { printf '%s' "$flag"; return 0; } ;;
656
693
  esac
657
694
  done
@@ -700,11 +737,13 @@ if [ "$DRY" != 1 ] || [ "$PREFLIGHT" = 1 ]; then preflight_command; fi
700
737
  echo "harness=$HARNESS"
701
738
  echo "model=$MODEL"
702
739
  echo "effort=${EFFORT:-<harness default>}"
740
+ [ "$SERVICE_TIER" = fast ] && echo "service_tier=fast"
703
741
  echo "yolo=$([ "$YOLO" = 1 ] && echo ON || echo off)"
704
742
  echo "passthrough=$([ "$PASSTHRU" = 1 ] && echo yes || echo no)"
705
743
  [ -n "$CLAMPED" ] && echo "clamped=$CLAMPED"
706
744
  echo "timeout=$LIMIT"
707
745
  echo "timeout_source=$LIMIT_SOURCE"
746
+ case "$HARNESS" in claude|openclaude) echo "result_grace=$RESULT_GRACE" ;; esac
708
747
  # Native review ignores the assembled prompt, so whether it reached the model is a fact
709
748
  # worth recording rather than inferring from the role and harness later.
710
749
  echo "delivery=$([ "$NATIVE_REVIEW" = 1 ] && echo native_review || echo custom)"
@@ -713,6 +752,31 @@ if [ "$DRY" != 1 ] || [ "$PREFLIGHT" = 1 ]; then preflight_command; fi
713
752
  } | tee "$RUN_DIR/$ROLE.resolved"
714
753
 
715
754
  if [ "$PREFLIGHT" = 1 ]; then
755
+ # Stderr only, and only here: the block above is parsed from stdout and $ROLE.resolved,
756
+ # and a dispatch would repeat this at every task's preflight. A failure to say it
757
+ # changes nothing, including the exit code. The module's cwd is scripts/, so a
758
+ # relative FORGE_REGISTRY or FORGE_DATA_HOME is the caller's path made absolute first.
759
+ # Opened from scripts/, the registry would miss the file this shell already resolved
760
+ # (the note would vanish) and the dataset would miss the caller's store (the built-in
761
+ # table would speak over measured rows). A FORGE_DATA_HOME that starts with ~ is left
762
+ # for Python's expanduser; prefixing $PWD would point it at a directory named "~".
763
+ _slow_registry="${FORGE_REGISTRY:-}"
764
+ case "$_slow_registry" in
765
+ ""|/*) ;;
766
+ *) _slow_registry="$PWD/$_slow_registry" ;;
767
+ esac
768
+ _slow_home="${FORGE_DATA_HOME:-}"
769
+ case "$_slow_home" in
770
+ ""|/*|~*) ;;
771
+ *) _slow_home="$PWD/$_slow_home" ;;
772
+ esac
773
+ _slow="$(
774
+ cd "$SKILL_DIR/scripts" || exit 1
775
+ if [ -n "$_slow_registry" ]; then export FORGE_REGISTRY="$_slow_registry"; fi
776
+ if [ -n "$_slow_home" ]; then export FORGE_DATA_HOME="$_slow_home"; fi
777
+ python3 -m forge_dataset.efforts "$SPEC" 2>/dev/null
778
+ )" || _slow=""
779
+ if [ -n "$_slow" ]; then note "note: $_slow"; fi
716
780
  echo "offline preflight passed; authentication, quota and live model availability unverified"
717
781
  exit 0
718
782
  fi
@@ -744,7 +808,7 @@ fi
744
808
  # when a stale $LAST is already there. That is harmless when each run gets a fresh
745
809
  # run-dir, and silently wrong for `forge-parallel.sh retry`, which reuses the task
746
810
  # directory — it would read the first attempt's result and never notice.
747
- rm -f "$LAST" "$LOG" "$RUN_DIR/$ROLE.clock" "$RUN_DIR/$ROLE.clock.stop" "$RUN_DIR/$ROLE.timedout" "$RUN_DIR/$ROLE.infra" "$RUN_DIR/$ROLE.orphans" "$RUN_DIR/$ROLE.harness"
811
+ rm -f "$LAST" "$LOG" "$RUN_DIR/$ROLE.clock" "$RUN_DIR/$ROLE.clock.stop" "$RUN_DIR/$ROLE.timedout" "$RUN_DIR/$ROLE.settled" "$RUN_DIR/$ROLE.infra" "$RUN_DIR/$ROLE.orphans" "$RUN_DIR/$ROLE.harness"
748
812
  python3 "$RUNTIME" phase "$ATTEMPT" model
749
813
  t0="$(date +%s)"
750
814
  # Process-group guard. A dwarf that starts `npm test &` and ends its turn leaves that
@@ -785,6 +849,19 @@ if [ "$GUARD_ON" = 1 ]; then
785
849
  fi
786
850
  fi
787
851
 
852
+ # Ends the harness: the whole process group first when the harness has its own (GUARD_ON),
853
+ # then children, then the process itself, then SIGKILL for a CLI that traps TERM and takes
854
+ # its time. Without the guard there is no group to signal as a unit.
855
+ stop_harness() {
856
+ [ "$GUARD_ON" != 1 ] || kill -s TERM -- "-$hpid" 2>/dev/null
857
+ pkill -TERM -P "$hpid" 2>/dev/null
858
+ kill -TERM "$hpid" 2>/dev/null
859
+ sleep 5
860
+ [ "$GUARD_ON" != 1 ] || kill -s KILL -- "-$hpid" 2>/dev/null
861
+ pkill -KILL -P "$hpid" 2>/dev/null
862
+ kill -KILL "$hpid" 2>/dev/null
863
+ }
864
+
788
865
  # Watchdog. Only antigravity has a time bound of its own, and `timeout` is not
789
866
  # present on stock macOS, so without this a hung backend blocks forever — and under
790
867
  # forge-parallel's `xargs -P` one hung task silently stalls its whole wave. The
@@ -796,19 +873,24 @@ if [ "${LIMIT:-0}" != "0" ]; then
796
873
  sleep "$LIMIT"
797
874
  kill -0 "$hpid" 2>/dev/null || exit 0
798
875
  : > "$RUN_DIR/$ROLE.timedout"
799
- # The whole process group first when the harness has its own (GUARD_ON), then
800
- # children, then the process itself, then SIGKILL for a CLI that traps TERM and
801
- # takes its time. Without the guard there is no group to signal as a unit.
802
- [ "$GUARD_ON" != 1 ] || kill -s TERM -- "-$hpid" 2>/dev/null
803
- pkill -TERM -P "$hpid" 2>/dev/null
804
- kill -TERM "$hpid" 2>/dev/null
805
- sleep 5
806
- [ "$GUARD_ON" != 1 ] || kill -s KILL -- "-$hpid" 2>/dev/null
807
- pkill -KILL -P "$hpid" 2>/dev/null
808
- kill -KILL "$hpid" 2>/dev/null
876
+ stop_harness
809
877
  ) >/dev/null 2>&1 &
810
878
  wpid=$!
811
879
  fi
880
+ # A final result the CLI stays open after (#110): once the log ends in it and has been silent for
881
+ # the grace, the harness is ended like a timeout, but the result stands (see below).
882
+ spid=""
883
+ case "$HARNESS" in claude|openclaude)
884
+ if [ "$RESULT_GRACE" != 0 ]; then
885
+ (
886
+ python3 "$RUNTIME" settle "$LOG" "$RESULT_GRACE" "$hpid" </dev/null || exit 0
887
+ kill -0 "$hpid" 2>/dev/null || exit 0
888
+ : > "$RUN_DIR/$ROLE.settled"
889
+ stop_harness
890
+ ) >/dev/null 2>&1 &
891
+ spid=$!
892
+ fi ;;
893
+ esac
812
894
 
813
895
  wait "$hpid"; rc=$?
814
896
  # Its last sample is in before `finish` copies the clock into the attempt. A stop file, not a TERM:
@@ -819,13 +901,13 @@ if [ -n "$cpid" ]; then
819
901
  { : > "$RUN_DIR/$ROLE.clock.stop"; } 2>/dev/null || kill -TERM "$cpid" 2>/dev/null
820
902
  wait "$cpid" 2>/dev/null; cpid=""; rm -f "$RUN_DIR/$ROLE.clock.stop"
821
903
  fi
822
- if [ -n "$wpid" ]; then
823
- # The watchdog is asleep in a child of its own; kill that too or it outlives the
824
- # run as an orphan holding the timer.
825
- pkill -P "$wpid" 2>/dev/null
826
- kill "$wpid" 2>/dev/null
827
- wait "$wpid" 2>/dev/null
828
- fi
904
+ for watcher in $wpid $spid; do
905
+ # The watchdog is asleep in a child of its own, and so is the grace watcher; kill that
906
+ # too or it outlives the run as an orphan holding the timer.
907
+ pkill -P "$watcher" 2>/dev/null
908
+ kill "$watcher" 2>/dev/null
909
+ wait "$watcher" 2>/dev/null
910
+ done
829
911
  # Anything the harness left running in its group is an abandoned background job. Kill it
830
912
  # before reading the tree, and leave the list for the caller. Bounded (~3s) and advisory:
831
913
  # a reaper failure changes nothing about the exit code.
@@ -835,11 +917,39 @@ if [ "$GUARD_ON" = 1 ]; then
835
917
  fi
836
918
  reaped=1
837
919
  rm -f "$RUN_DIR/$ROLE.harness"
920
+ # Neither CLI refuses a fast request it cannot honour: it runs slower and still exits 0.
921
+ # One note when the log shows that. The exit below stays the one the harness already returned.
922
+ if [ "$SERVICE_TIER" = fast ]; then
923
+ slow="$(python3 "$RUNTIME" speed "$LOG" "$HARNESS" 2>/dev/null)" || slow=""
924
+ [ -z "$slow" ] || note "$slow"
925
+ fi
838
926
  python3 "$RUNTIME" phase "$ATTEMPT" finalization
839
927
  DURATION=$(( $(date +%s) - t0 ))
840
928
  echo "duration_s=$DURATION" >> "$RUN_DIR/$ROLE.resolved"
841
929
  [ "$OUTPUT" != full ] || cat "$LOG"
842
930
  [ "$OUTPUT" != summary ] || echo "forge: role=$ROLE backend_exit=$rc final=$LAST log=$LOG metrics=$ATTEMPT/metrics.json"
931
+ # Ended by forge after the model's final result, with only background tasks open: the answer was
932
+ # in, so the role finished and its result stands, whether the grace or the watchdog ended it. The
933
+ # exit is the one the CLI gives for that result. A turn that began while forge was ending it is cut
934
+ # off, as by a timeout.
935
+ if [ -f "$RUN_DIR/$ROLE.settled" ] || [ -f "$RUN_DIR/$ROLE.timedout" ]; then
936
+ case "$HARNESS" in claude|openclaude)
937
+ if verdict="$(python3 "$RUNTIME" settled "$LOG" 2>/dev/null)"; then
938
+ # The marker is written before the harness is stopped, so it says the grace came first.
939
+ if [ -f "$RUN_DIR/$ROLE.settled" ]; then after="${RESULT_GRACE}s of silence"; ended_by=grace
940
+ else after="the ${LIMIT}s timeout"; ended_by=timeout; fi
941
+ printf 'ended_by=%s\nbackend_exit=%s\n' "$ended_by" "$rc" > "$RUN_DIR/$ROLE.settled"
942
+ rm -f "$RUN_DIR/$ROLE.timedout"
943
+ if [ "$verdict" = error ]; then rc=1; else rc=0; fi
944
+ note "$HARNESS gave its final result, then stayed open on a background task; forge ended it after $after — the result stands"
945
+ elif [ -f "$RUN_DIR/$ROLE.settled" ]; then
946
+ rm -f "$RUN_DIR/$ROLE.settled"; : > "$RUN_DIR/$ROLE.timedout"
947
+ note "$HARNESS began another turn while forge was ending it after its final result — see $LOG"
948
+ write_continue failed timeout
949
+ exit 7
950
+ fi ;;
951
+ esac
952
+ fi
843
953
  if [ -f "$RUN_DIR/$ROLE.timedout" ]; then
844
954
  note "$HARNESS exceeded the ${LIMIT}s timeout and was killed after ${DURATION}s — see $LOG"
845
955
  write_continue failed timeout
@@ -130,7 +130,7 @@ plans_make_integration() { # plans_make_integration <repo> <branch> <commit> <wt
130
130
 
131
131
  # Per-plan option files carried to a derived plan. The cost-bearing choices a user made
132
132
  # for this plan apply to the plan made from it; `planner` does not (nothing plans again).
133
- PLANS_OPTION_FILES="no_ripwire no_memory yolo_dwarf yolo_qa reviewer_session implementer_session pre_review_tests pre_review_parallel qa_threshold timeout verify_retries verify_cmd verify_parallel setup_cmd final_qa shadow_qa shadow_rate explore escalate_after fractal-routing.json fractal-selection.json jev-selection.json"
133
+ PLANS_OPTION_FILES="no_ripwire no_memory yolo_dwarf yolo_qa reviewer_session implementer_session fast pre_review_tests pre_review_parallel qa_threshold timeout verify_retries verify_cmd verify_parallel setup_cmd final_qa shadow_qa shadow_rate explore escalate_after fractal-routing.json fractal-selection.json jev-selection.json profile.json routed.json"
134
134
 
135
135
  # --- accept ---------------------------------------------------------------------
136
136
  # A reviewer's FAIL is the QA gate; overriding it is the user's call and never forge's or
@@ -547,7 +547,7 @@ Retry or accept them (or split them off into their own plan) first." 3
547
547
  done
548
548
  all=1; for p in "${SRC[@]}"; do [ -f "$p/pre_review_tests" ] || all=0; done
549
549
  [ "$all" = 1 ] && : > "$NEW/pre_review_tests"
550
- for f in qa_threshold timeout verify_retries verify_parallel pre_review_parallel; do
550
+ for f in qa_threshold timeout verify_retries verify_parallel pre_review_parallel fast; do
551
551
  same=1
552
552
  for p in "${SRC[@]}"; do
553
553
  if [ ! -f "$p/$f" ] || ! cmp -s "$p/$f" "${SRC[0]}/$f"; then same=0; fi
@@ -559,6 +559,23 @@ Retry or accept them (or split them off into their own plan) first." 3
559
559
  done
560
560
  fi
561
561
  done
562
+ # A frozen profile (#48) carries over when every source froze the same one: its name, level and
563
+ # body (the time it was frozen and the flags that replaced a value do not tell profiles apart).
564
+ same=1
565
+ for p in "${SRC[@]}"; do
566
+ [ -f "$p/profile.json" ] && python3 -c '
567
+ import json, sys
568
+ def key(path):
569
+ data = json.load(open(path))
570
+ return [data.get(k) for k in ("name", "level", "body")]
571
+ sys.exit(0 if key(sys.argv[1]) == key(sys.argv[2]) else 1)' "$p/profile.json" "${SRC[0]}/profile.json" 2>/dev/null || same=0
572
+ done
573
+ if [ "$same" = 1 ]; then cp -p "${SRC[0]}/profile.json" "$NEW/profile.json"
574
+ else
575
+ for p in "${SRC[@]}"; do
576
+ if [ -f "$p/profile.json" ]; then note "the plans do not agree on profile.json; the combined plan leaves it unset"; break; fi
577
+ done
578
+ fi
562
579
  # The integration worktree needs a setup step to build and test the combined result, and
563
580
  # no task is ever dispatched here, so the first source's is as good as any.
564
581
  for p in "${SRC[@]}"; do [ -s "$p/setup_cmd" ] && { cp -p "$p/setup_cmd" "$NEW/setup_cmd"; break; }; done
@@ -359,7 +359,7 @@ PY
359
359
  # it is called from inside do_integrate.
360
360
  final_review() {
361
361
  local plan="$1" base="$2" tip="$3" src="$4" out="$5" spec="$6" yolo="${7:-}"
362
- local review n rc verdict thr gate_line gate_forced source_fp review_fp vdir tflag="" inline=1 diff_n
362
+ local review n rc verdict thr gate_line gate_forced source_fp review_fp vdir tflag="" inline=1 diff_n ft
363
363
  local plan_real prev="" prev_rel=none prev_tip="" since=none integration="" prev_note=""
364
364
  [ -n "$yolo" ] && yolo=--yolo
365
365
  [ -n "$spec" ] || { note "final review: no QA spec given"; return 3; }
@@ -378,8 +378,10 @@ final_review() {
378
378
  fi
379
379
 
380
380
  # Offline, and before anything is built or paid for: a spec that cannot resolve fails here.
381
+ # The fast-file role is review; dispatch's own role stays qa (a review is a read-only pass).
382
+ ft="$(forge_fast_tier "$plan" review)"
381
383
  FORGE_CAPABILITY_CACHE="${FORGE_CAPABILITY_CACHE:-$plan/capabilities}" \
382
- /bin/bash "$DISPATCH" doctor --spec "$spec" --role qa $yolo > "$out/doctor.out" 2>&1
384
+ /bin/bash "$DISPATCH" doctor --spec "$spec" --role qa $yolo $ft > "$out/doctor.out" 2>&1
383
385
  rc=$?
384
386
  if [ "$rc" -ne 0 ]; then
385
387
  cat "$out/doctor.out" >&2
@@ -497,7 +499,7 @@ final_review() {
497
499
  fi
498
500
  local qa_cmd=(/bin/bash "$DISPATCH" qa "$spec" --repo "$review" --run-dir "$out"
499
501
  --review-base "$(cat "$out/review.base")" --ripwire-query-file "$out/context.md"
500
- --prompt-file "$out/qa.input" ${yolo:+"$yolo"} $tflag --output "${FORGE_OUTPUT:-summary}")
502
+ --prompt-file "$out/qa.input" ${yolo:+"$yolo"} $ft $tflag --output "${FORGE_OUTPUT:-summary}")
501
503
  FORGE_CAPABILITY_CACHE="${FORGE_CAPABILITY_CACHE:-$plan/capabilities}" \
502
504
  "${qa_cmd[@]}" ${rs_cont[@]+"${rs_cont[@]}"} > "$out/qa.out" 2>&1
503
505
  rc=$?
@@ -89,6 +89,125 @@ except Exception:
89
89
  sys.exit(1)' "$1/fractal-selection.json"
90
90
  }
91
91
 
92
+ # --- fast service tier (--fast, #68) ---------------------------------------------------
93
+ # A plan or solo run keeps the roles that should ask for the fast tier in <dir>/fast,
94
+ # one role per line, in the order dwarf, qa, planner, review. Specs never change: the
95
+ # dispatch and its preflight doctor get `--service-tier fast` only for a listed role.
96
+ # Fractal dispatches through its own runner and ignores the file.
97
+ #
98
+ # forge_fast_parse sets FAST_PARSED (dynamic scope: the caller's local, when it has one)
99
+ # to `none` or the roles. forge_fast_store writes that when --fast was given this time;
100
+ # a re-plan that omits the flag leaves the file alone.
101
+ forge_fast_parse() { # forge_fast_parse <roles> <plan|solo>
102
+ local raw="$1" mode="$2" token rest seen="" w more=0
103
+ # Trim the ends only. A space inside a token is part of it: "dwa rf" is not the
104
+ # role dwarf, and deleting every space would turn that typo into a billed role.
105
+ raw="${raw#"${raw%%[![:space:]]*}"}"
106
+ raw="${raw%"${raw##*[![:space:]]}"}"
107
+ [ -n "$raw" ] || die "--fast needs a comma list of roles (dwarf, qa, planner, review), all or none"
108
+ case "$mode" in
109
+ plan|solo) ;;
110
+ *) die "--fast: internal mode '$mode'" ;;
111
+ esac
112
+ case "$raw" in
113
+ none) FAST_PARSED=none; return 0 ;;
114
+ all)
115
+ # `all` is the four plan roles. A solo run has no planner or review, so it cannot
116
+ # mean the same thing there; the user names dwarf and qa instead.
117
+ if [ "$mode" = solo ]; then
118
+ die "--fast: 'all' includes planner and review, which a solo run does not dispatch (expected dwarf, qa or none)"
119
+ fi
120
+ FAST_PARSED="dwarf
121
+ qa
122
+ planner
123
+ review"
124
+ return 0 ;;
125
+ esac
126
+ rest="$raw"
127
+ while true; do
128
+ token="${rest%%,*}"
129
+ token="${token#"${token%%[![:space:]]*}"}"
130
+ token="${token%"${token##*[![:space:]]}"}"
131
+ # A trailing comma is an empty role (`dwarf,`), so the loop must visit that field too.
132
+ case "$rest" in
133
+ *,*) rest="${rest#*,}"; more=1 ;;
134
+ *) rest=""; more=0 ;;
135
+ esac
136
+ if [ -z "$token" ]; then
137
+ if [ "$mode" = solo ]; then
138
+ die "--fast: '' is not a role of a solo run (expected dwarf, qa or none)"
139
+ fi
140
+ die "--fast: '' is not a role (expected dwarf, qa, planner, review, all or none)"
141
+ fi
142
+ if [ "$token" = all ] || [ "$token" = none ]; then
143
+ die "--fast: '$token' must be the whole value, not combined with other roles"
144
+ fi
145
+ case "$mode" in
146
+ solo) case "$token" in dwarf|qa) ;; *) die "--fast: '$token' is not a role of a solo run (expected dwarf, qa or none)" ;; esac ;;
147
+ *) case "$token" in dwarf|qa|planner|review) ;; *) die "--fast: '$token' is not a role (expected dwarf, qa, planner, review, all or none)" ;; esac ;;
148
+ esac
149
+ case " $seen " in
150
+ *" $token "*) ;;
151
+ *) seen="$seen $token" ;;
152
+ esac
153
+ [ "$more" = 1 ] || break
154
+ done
155
+ # Canonical order, whatever order the user typed. A solo run never stores planner or review.
156
+ FAST_PARSED=""
157
+ for w in dwarf qa planner review; do
158
+ [ "$mode" = solo ] && case "$w" in planner|review) continue ;; esac
159
+ case " $seen " in
160
+ *" $w "*)
161
+ if [ -n "$FAST_PARSED" ]; then FAST_PARSED="$FAST_PARSED
162
+ $w"
163
+ else FAST_PARSED="$w"; fi ;;
164
+ esac
165
+ done
166
+ }
167
+
168
+ forge_fast_store() { # forge_fast_store <dir> — honour FAST_GIVEN / FAST_PARSED from the caller
169
+ [ "${FAST_GIVEN:-0}" = 1 ] || return 0
170
+ if [ "$FAST_PARSED" = none ]; then
171
+ rm -f "$1/fast"
172
+ else
173
+ printf '%s\n' "$FAST_PARSED" > "$1/fast" || die "could not write $1/fast"
174
+ fi
175
+ }
176
+
177
+ # Prints `--service-tier fast` when <role> is listed in <dir>/fast, and nothing otherwise.
178
+ # Fractal's runner does not take the option. That is FORGE_FRACTAL_RUN once the runner is
179
+ # selected, and also a saved selection: retry preflights before the runner is selected, so
180
+ # the variable is still unset. A whole-run review is not a Fractal dispatch and still asks.
181
+ forge_fast_tier() { # forge_fast_tier <dir> <role>
182
+ local line found=0
183
+ [ -n "${FORGE_FRACTAL_RUN:-}" ] && return 0
184
+ [ -f "$1/fast" ] || return 0
185
+ while IFS= read -r line || [ -n "$line" ]; do
186
+ line="${line%$'\r'}"
187
+ line="${line#"${line%%[![:space:]]*}"}"
188
+ line="${line%"${line##*[![:space:]]}"}"
189
+ if [ "$line" = "$2" ]; then found=1; break; fi
190
+ done < "$1/fast"
191
+ [ "$found" = 1 ] || return 0
192
+ if [ "$2" != review ] && forge_plan_is_fractal "$1"; then return 0; fi
193
+ printf '%s %s\n' --service-tier fast
194
+ }
195
+
196
+ # One note per invocation, and only where this invocation's dispatches go through Fractal
197
+ # (FORGE_FRACTAL_RUN already set) or are about to (a retry of a plan whose selection is on).
198
+ # A whole-run review is not one of those dispatches, so it still asks for the tier.
199
+ # No fast file, or no fractal selection to consult, returns before any python.
200
+ forge_fast_fractal_note() { # forge_fast_fractal_note <dir>
201
+ [ -s "$1/fast" ] || return 0
202
+ [ -n "${FORGE_FAST_FRACTAL_NOTED:-}" ] && return 0
203
+ if [ -z "${FORGE_FRACTAL_RUN:-}" ]; then
204
+ [ -s "$1/fractal-selection.json" ] || return 0
205
+ forge_plan_is_fractal "$1" || return 0
206
+ fi
207
+ export FORGE_FAST_FRACTAL_NOTED=1
208
+ note "fast tier is not applied to Fractal dispatches"
209
+ }
210
+
92
211
  # The pin's spec: the first line, trimmed, a single token (it lands in a TSV column).
93
212
  # Prints nothing when the file is not a regular file or holds no usable spec.
94
213
  pin_spec() { # pin_spec <file>
@@ -11,6 +11,10 @@
11
11
  # 1 not ours, or not accepted by this subcommand
12
12
  # A malformed value exits through die (2).
13
13
  #
14
+ # A profile (plan --profile, frozen as $PLAN/profile.json) supplies --retry-failed and
15
+ # --infra-retries when `run` or `retry` is not given them; a flag wins. On `retry` they are
16
+ # the further attempts after this one (while its review fails) and the waits out of an infrastructure stop.
17
+ #
14
18
  # Persisted options become files in the plan dir, like --verify and --setup, so a later
15
19
  # `retry` or the scheduler's task processes see them. Cost-bearing options that change
16
20
  # what a run is allowed to spend (--retry-failed, --infra-retries) are deliberately NOT
@@ -19,8 +23,8 @@
19
23
  # `forge control` can change them live; the scheduler removes those files when it exits.
20
24
  #
21
25
  # --timeout S run retry $PLAN/timeout dispatch timeout, seconds (0 = none)
22
- # --retry-failed N run (this run only) automatic reviewer-driven retries
23
- # --infra-retries M run (this run only) waits out quota/auth/network stops
26
+ # --retry-failed N run retry (this run only) automatic reviewer-driven retries
27
+ # --infra-retries M run retry (this run only) waits out quota/auth/network stops
24
28
  # --infra-backoff SHAPE run $PLAN/infra_backoff waits between those stops: exp:B[,C],
25
29
  # linear:S,T[,C] or list:a,b,... (default exp:60)
26
30
  # --infra-fallback run $PLAN/infra_fallback a dwarf's stop that another model can take (capacity,
@@ -60,6 +64,8 @@
60
64
  PP_SHIFT=2
61
65
  PP_RETRY_FAILED=0
62
66
  PP_INFRA_RETRIES=0
67
+ PP_RETRY_FAILED_SET=0 # given on this command line, so a frozen profile's value does not replace it
68
+ PP_INFRA_RETRIES_SET=0
63
69
  PP_FINAL_REVIEW=""
64
70
  PP_SWEEP=""
65
71
  PP_SWEEP_MAX=5
@@ -97,11 +103,11 @@ forge_pp_flag() {
97
103
  pp_nonneg --timeout "${2:-}"
98
104
  printf '%s' "$2" > "$plan/timeout" ;;
99
105
  --retry-failed)
100
- [ "$cmd" = run ] || return 1
101
- pp_nonneg --retry-failed "${2:-}"; PP_RETRY_FAILED="$2" ;;
106
+ [ "$cmd" = run ] || [ "$cmd" = retry ] || return 1
107
+ pp_nonneg --retry-failed "${2:-}"; PP_RETRY_FAILED="$2"; PP_RETRY_FAILED_SET=1 ;;
102
108
  --infra-retries)
103
- [ "$cmd" = run ] || return 1
104
- pp_nonneg --infra-retries "${2:-}"; PP_INFRA_RETRIES="$2" ;;
109
+ [ "$cmd" = run ] || [ "$cmd" = retry ] || return 1
110
+ pp_nonneg --infra-retries "${2:-}"; PP_INFRA_RETRIES="$2"; PP_INFRA_RETRIES_SET=1 ;;
105
111
  --infra-fallback)
106
112
  [ "$cmd" = run ] || return 1
107
113
  PP_SHIFT=1; printf 'on\n' > "$plan/infra_fallback" ;;