@giamme/forge 0.11.1 → 0.12.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 (54) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/SKILL.md +7 -3
  3. package/VERSION +1 -1
  4. package/docs/artifacts.md +50 -11
  5. package/docs/commands.md +56 -8
  6. package/docs/decomposed-runs.md +43 -2
  7. package/docs/forge-ui.md +55 -8
  8. package/docs/reviews.md +64 -6
  9. package/package.json +1 -1
  10. package/references/dataset.md +4 -2
  11. package/references/decompose.md +191 -17
  12. package/references/harnesses.md +13 -1
  13. package/references/ui.md +25 -4
  14. package/scripts/forge-contract.py +37 -7
  15. package/scripts/forge-control.py +268 -25
  16. package/scripts/forge-dispatch.sh +90 -3
  17. package/scripts/forge-guard.py +156 -15
  18. package/scripts/forge-issues.py +47 -3
  19. package/scripts/forge-lib-plans.sh +9 -3
  20. package/scripts/forge-lib-review.sh +24 -5
  21. package/scripts/forge-lib-task.sh +53 -5
  22. package/scripts/forge-lib-verify.sh +137 -6
  23. package/scripts/forge-parallel-options.sh +85 -0
  24. package/scripts/forge-parallel.sh +262 -31
  25. package/scripts/forge-ripwire.py +1 -1
  26. package/scripts/forge-route.py +157 -5
  27. package/scripts/forge-runtime.py +49 -1
  28. package/scripts/forge-schedule.py +735 -53
  29. package/scripts/forge-solo.sh +3 -1
  30. package/scripts/forge-sweep.py +542 -0
  31. package/scripts/forge-verify.py +878 -0
  32. package/scripts/forge_dataset/forecast.py +33 -5
  33. package/scripts/forge_dataset/harvest.py +10 -4
  34. package/scripts/forge_verify_reports.py +225 -0
  35. package/ui/README.md +58 -12
  36. package/ui/docs/api.md +277 -28
  37. package/ui/forge_ui/checks.py +331 -0
  38. package/ui/forge_ui/control.py +12 -2
  39. package/ui/forge_ui/export.py +25 -8
  40. package/ui/forge_ui/reader.py +657 -24
  41. package/ui/forge_ui/server.py +29 -0
  42. package/ui/forge_ui/static/app.js +15 -7
  43. package/ui/forge_ui/static/checksview.js +449 -0
  44. package/ui/forge_ui/static/controls.js +217 -33
  45. package/ui/forge_ui/static/convo.js +11 -2
  46. package/ui/forge_ui/static/findingsview.js +6 -4
  47. package/ui/forge_ui/static/gantt.js +14 -9
  48. package/ui/forge_ui/static/index.html +2 -0
  49. package/ui/forge_ui/static/panel.js +44 -1
  50. package/ui/forge_ui/static/runmodel.js +109 -12
  51. package/ui/forge_ui/static/scene3d.js +9 -5
  52. package/ui/forge_ui/static/style.css +113 -0
  53. package/ui/forge_ui/static/verifyview.js +324 -0
  54. package/ui/forge_ui/transcripts.py +225 -54
@@ -1,12 +1,66 @@
1
1
  #!/usr/bin/env bash
2
2
  # Verification helpers for forge-parallel.sh. Sourced; functions only.
3
3
 
4
- # The verify command a plan would run: --verify (persisted in the plan) first, then the
5
- # repository's own .forge/verify. Prints nothing when neither is configured.
4
+ # A lanes directory counts once it holds a lane file (dot files and backups are skipped,
5
+ # as forge-verify.py skips them).
6
+ verify_lanes_present() { # verify_lanes_present <dir>
7
+ local f
8
+ [ -d "$1" ] || return 1
9
+ for f in "$1"/*; do
10
+ [ -e "$f" ] || continue
11
+ case "${f##*/}" in *~) continue ;; esac
12
+ return 0
13
+ done
14
+ return 1
15
+ }
16
+
17
+ # Where a plan's verification comes from, in this order: the plan's lanes (--verify-lane,
18
+ # $PLAN/verify.d/), the plan's --verify, the repository's lanes (.forge/verify.d/), the
19
+ # repository's .forge/verify. Prints "<kind><TAB><location>" with kind lanes:plan,
20
+ # command:plan, lanes:repo or command:repo, or nothing when none is configured.
21
+ verify_source_for() { # verify_source_for <plan> <repo>
22
+ if verify_lanes_present "$1/verify.d"; then printf 'lanes:plan\t%s\n' "$1/verify.d"
23
+ elif [ -s "$1/verify_cmd" ]; then printf 'command:plan\t%s\n' "$1/verify_cmd"
24
+ elif verify_lanes_present "$2/.forge/verify.d"; then printf 'lanes:repo\t%s\n' "$2/.forge/verify.d"
25
+ elif [ -s "$2/.forge/verify" ]; then printf 'command:repo\t%s\n' "$2/.forge/verify"
26
+ fi
27
+ return 0
28
+ }
29
+
30
+ # The verify command a plan would run, as text: the command itself, or for lanes every
31
+ # lane's command (its #forge: option lines left out), one after another. Prints nothing
32
+ # when nothing is configured.
6
33
  verify_command_for() { # verify_command_for <plan> <repo>
7
- if [ -s "$1/verify_cmd" ]; then cat "$1/verify_cmd"
8
- elif [ -s "$2/.forge/verify" ]; then cat "$2/.forge/verify"
34
+ local src loc f
35
+ src="$(verify_source_for "$1" "$2")"
36
+ loc="${src#*$'\t'}"
37
+ case "$src" in
38
+ command:*) cat "$loc" ;;
39
+ lanes:*)
40
+ for f in "$loc"/*; do
41
+ [ -f "$f" ] || continue
42
+ case "${f##*/}" in *~) continue ;; esac
43
+ awk 'body || !/^#forge:/ { body = 1; print }' "$f"
44
+ done ;;
45
+ esac
46
+ return 0
47
+ }
48
+
49
+ # Lanes are checked before any model is paid for: the runner's own validation, against the
50
+ # checkout the lanes will run in (baseline= files exist, reports= and baseline= stay inside).
51
+ # Dies with exit 2 and the runner's messages on an invalid source; a single command, or
52
+ # nothing, passes.
53
+ verify_lanes_check() { # verify_lanes_check <plan> <repo> <checkout>
54
+ local src loc out
55
+ src="$(verify_source_for "$1" "$2")"
56
+ case "$src" in lanes:*) ;; *) return 0 ;; esac
57
+ loc="${src#*$'\t'}"
58
+ if [ "${src%%$'\t'*}" = lanes:repo ] && [ -s "$2/.forge/verify" ]; then
59
+ note ".forge/verify is ignored: the repository declares verification lanes in .forge/verify.d/"
9
60
  fi
61
+ out="$(python3 "$SKILL_DIR/scripts/forge-verify.py" lanes --lanes-dir "$loc" --checkout "$3" 2>&1 >/dev/null)" \
62
+ || die "invalid verification lanes in $loc:
63
+ $out"
10
64
  return 0
11
65
  }
12
66
 
@@ -15,10 +69,16 @@ verify_command_for() { # verify_command_for <plan> <repo>
15
69
  # configuration and say which suites the command does not run. Advisory by design — it
16
70
  # prints and records, it never changes an outcome, and a failure of the checker is silent.
17
71
  verify_coverage_report() { # verify_coverage_report <checkout> <command> <out-file>
18
- local dir="$1" cmd="$2" out="$3" line
72
+ local dir="$1" cmd="$2" out="$3" line file
19
73
  [ -f "$SKILL_DIR/scripts/forge-verify-coverage.py" ] || return 0
20
74
  rm -f "$out"
21
- if [ -n "$cmd" ]; then
75
+ if [[ "$cmd" == *$'\n'* ]]; then
76
+ # Several lines (every lane's command, or a multi-line script): through a file.
77
+ file="$(mktemp "${TMPDIR:-/tmp}/forge-verify-cmd.XXXXXX")" || return 0
78
+ printf '%s\n' "$cmd" > "$file"
79
+ python3 "$SKILL_DIR/scripts/forge-verify-coverage.py" check --repo "$dir" --command-file "$file" --out "$out" >/dev/null 2>&1
80
+ rm -f "$file"
81
+ elif [ -n "$cmd" ]; then
22
82
  python3 "$SKILL_DIR/scripts/forge-verify-coverage.py" check --repo "$dir" --command="$cmd" --out "$out" >/dev/null 2>&1
23
83
  else
24
84
  python3 "$SKILL_DIR/scripts/forge-verify-coverage.py" check --repo "$dir" --none --out "$out" >/dev/null 2>&1
@@ -28,3 +88,74 @@ verify_coverage_report() { # verify_coverage_report <checkout> <command> <out-fi
28
88
  fi
29
89
  return 0
30
90
  }
91
+
92
+ # Lanes mode of verify_result: the lane runner (forge-verify.py) through the same stoppable
93
+ # path as a single command, then verification.* from what it wrote. No whole-command rerun
94
+ # and no Jev triage: the runner reruns a failed lane itself. Returns 0 pass, 1 fail, 130
95
+ # interrupted.
96
+ verify_lanes_run() { # verify_lanes_run <plan> <checkout> <out> <lanes dir> <retries>
97
+ local plan="$1" wt="$2" out="$3" dir="$4" retries="$5" parallel rc=0 cmd fpcmd
98
+ parallel="$(cat "$plan/verify_parallel" 2>/dev/null)"
99
+ case "$parallel" in ''|*[!0-9]*) parallel=3 ;; esac
100
+ [ "$retries" -le 9 ] 2>/dev/null || retries=9 # the runner takes 0 to 9
101
+ python3 "$SKILL_DIR/scripts/forge-verify.py" lanes --lanes-dir "$dir" 2>/dev/null \
102
+ | awk -F'\t' '{ print $1 ": " $3 }' > "$out/verification.command"
103
+ verify_coverage_report "$wt" "$(verify_command_for "$plan" "$(cat "$plan/repo")")" "$out/verification.coverage.txt"
104
+ forge_fingerprint "$wt" > "$out/verification.fingerprint" || return 1
105
+ # The runner judges "a lane changed the checkout" by forge's own fingerprint.
106
+ fpcmd="source $(printf %q "$SKILL_DIR/scripts/forge-artifact.sh") && forge_fingerprint ."
107
+ cmd="exec python3 $(printf %q "$SKILL_DIR/scripts/forge-verify.py") run --checkout $(printf %q "$wt")"
108
+ cmd="$cmd --out $(printf %q "$out") --lanes-dir $(printf %q "$dir") --parallel $parallel --retries $retries"
109
+ cmd="$cmd --fingerprint-cmd $(printf %q "$fpcmd")"
110
+ verify_stopped "$out" && return 130
111
+ # The runner stops its own lanes (TERM, then KILL 5 s later; each lane is a session the
112
+ # outer KILL cannot reach), so its grace here outlasts that.
113
+ verify_exec "$wt" "$cmd" "$out/verification.log" 15 || rc=$?
114
+ [ "$FORGE_VERIFY_STOP" = 1 ] && rc=130
115
+ echo "$rc" > "$out/verification.exit"
116
+ # verification.flaky per flaky lane; then each failed lane's last 200 lines under the summary
117
+ python3 - "$out" <<'PY'
118
+ import json, os, sys
119
+ out = sys.argv[1]
120
+ try:
121
+ with open(os.path.join(out, 'verification.lanes.json'), encoding='utf-8') as fh:
122
+ doc = json.load(fh)
123
+ except (OSError, ValueError):
124
+ sys.exit(0)
125
+ lanes = [l for l in doc.get('lanes') or [] if isinstance(l, dict) and l.get('name')]
126
+ flaky = [l for l in lanes if l.get('state') == 'flaky']
127
+ if flaky:
128
+ with open(os.path.join(out, 'verification.flaky'), 'w', encoding='utf-8') as fh:
129
+ fh.write('lanes=%s\n' % ','.join(l['name'] for l in flaky))
130
+ for l in flaky:
131
+ runs = l.get('runs') or [{}]
132
+ fh.write('%s.first_exit=%s\n%s.retries_used=%d\n' % (l['name'], runs[0].get('exit'), l['name'], len(runs) - 1))
133
+
134
+ def tail(name, lines=200, size=256 << 10):
135
+ try:
136
+ with open(os.path.join(out, os.path.basename(name or '')), 'rb') as fh:
137
+ fh.seek(max(0, os.fstat(fh.fileno()).st_size - size))
138
+ return fh.read().decode('utf-8', 'replace').splitlines()[-lines:]
139
+ except OSError:
140
+ return []
141
+
142
+ with open(os.path.join(out, 'verification.log'), 'a', encoding='utf-8') as fh:
143
+ for l in lanes:
144
+ if l.get('state') != 'fail':
145
+ continue
146
+ runs = l.get('runs') or []
147
+ lines = tail(runs[-1].get('log') if runs else l.get('log'))
148
+ fh.write('\n== lane %s failed (exit %s); the last %d lines of its output:\n' % (l['name'], l.get('exit'), len(lines)))
149
+ fh.write(''.join(line + '\n' for line in lines))
150
+ PY
151
+ case "$rc" in
152
+ 0) echo PASS > "$out/verification.status" ;;
153
+ 130) verify_mark_interrupted "$out"; return 130 ;;
154
+ *) echo FAIL > "$out/verification.status" ;;
155
+ esac
156
+ local flaky; flaky="$(sed -n 's/^lanes=//p' "$out/verification.flaky" 2>/dev/null)"
157
+ [ -z "$flaky" ] || note "FLAKY: lane ${flaky//,/, lane } failed once and passed on rerun; this is not a clean pass"
158
+ [ "$rc" = 0 ] && return 0
159
+ note "verification failed ($( [ "$rc" = 2 ] && echo 'the lane runner refused its configuration' || echo 'see the lanes below' )): $out/verification.log"
160
+ return 1
161
+ }
@@ -21,15 +21,56 @@
21
21
  # --timeout S run retry $PLAN/timeout dispatch timeout, seconds (0 = none)
22
22
  # --retry-failed N run (this run only) automatic reviewer-driven retries
23
23
  # --infra-retries M run (this run only) waits out quota/auth/network stops
24
+ # --infra-backoff SHAPE run $PLAN/infra_backoff waits between those stops: exp:B[,C],
25
+ # linear:S,T[,C] or list:a,b,... (default exp:60)
26
+ # --infra-fallback run $PLAN/infra_fallback a dwarf's capacity stop moves it to the next healthy
27
+ # --no-infra-fallback model of its tier pool (off by default)
24
28
  # --qa-threshold Pn|none run retry $PLAN/qa_threshold least severe finding that still blocks
25
29
  # --verify-retries N run retry integrate $PLAN/verify_retries reruns of a failed verify command
26
30
  # --escalate-after N run retry $PLAN/escalate_after failed attempts on one model before the
27
31
  # next goes a tier up (default 3; 0 = off)
32
+ # --escalate-effort run retry $PLAN/escalate_effort on: before the stop, retry the same
33
+ # model at the next effort its pairing accepts;
34
+ # tasks already stopped are decided again
35
+ # --no-escalate-effort run retry (removes the file) turn that step off (the default)
28
36
  # --final-review SPEC integrate $PLAN/final_qa QA spec for the whole-run review
37
+ # --sweep Pn run (this run only) once every task merged, fix the open findings
38
+ # at Pn or worse in a few tasks, one per file
39
+ # --sweep-plausible run (this run only) the sweep takes PLAUSIBLE findings too
40
+ # --sweep-max N run (this run only) at most N sweep tasks (default 5)
41
+ # --sweep-ahead run $PLAN/sweep_ahead a task is told the open findings in files it
42
+ # --no-sweep-ahead owns, to fix on its way (off by default)
43
+ # --verify-lane L=CMD run retry $PLAN/verify.d/<L> a verification lane: name[options]=command,
44
+ # options as in a lane file (group=g,first,...);
45
+ # repeatable; replaces --verify and the lanes
46
+ # of an earlier invocation
47
+ # --verify-parallel N run retry integrate $PLAN/verify_parallel lanes run at once (1-32, default 3)
29
48
  PP_SHIFT=2
30
49
  PP_RETRY_FAILED=0
31
50
  PP_INFRA_RETRIES=0
32
51
  PP_FINAL_REVIEW=""
52
+ PP_SWEEP=""
53
+ PP_SWEEP_MAX=5
54
+ PP_SWEEP_MAX_SET=0
55
+ PP_SWEEP_PLAUSIBLE=0
56
+ PP_LANES_FRESH=0 # the first --verify-lane of an invocation, or the first after a --verify, starts a fresh verify.d/
57
+
58
+ # --verify-lane 'name[opt,opt]=command' -> $PLAN/verify.d/name: the options become the lane
59
+ # file's first line, `#forge: opt opt`, and the command follows, as in a lane file.
60
+ pp_lane() { # pp_lane <plan> <argument>
61
+ local plan="$1" arg="$2" re='^([A-Za-z0-9][A-Za-z0-9_-]{0,63})(\[([^]]*)\])?=(.*)$'
62
+ [[ "$arg" =~ $re ]] \
63
+ || die "--verify-lane '$arg': expected name[options]=command (a name of letters, digits, _ and -, at most 64; options in closed brackets)"
64
+ local name="${BASH_REMATCH[1]}" opts="${BASH_REMATCH[3]}" cmd="${BASH_REMATCH[4]}"
65
+ [ -n "${cmd//[[:space:]]/}" ] || die "--verify-lane '$arg': the command is empty"
66
+ if [ "$PP_LANES_FRESH" = 0 ]; then
67
+ rm -rf "$plan/verify.d" && mkdir "$plan/verify.d" || die "could not create $plan/verify.d"
68
+ PP_LANES_FRESH=1
69
+ fi
70
+ { [ -z "$opts" ] || printf '#forge: %s\n' "${opts//,/ }"; printf '%s\n' "$cmd"; } > "$plan/verify.d/$name" \
71
+ || die "could not write $plan/verify.d/$name"
72
+ rm -f "$plan/verify_cmd"
73
+ }
33
74
 
34
75
  pp_nonneg() { # pp_nonneg <flag> <value>
35
76
  case "$2" in ''|*[!0-9]*) die "$1 needs a non-negative integer" ;; esac
@@ -49,6 +90,16 @@ forge_pp_flag() {
49
90
  --infra-retries)
50
91
  [ "$cmd" = run ] || return 1
51
92
  pp_nonneg --infra-retries "${2:-}"; PP_INFRA_RETRIES="$2" ;;
93
+ --infra-fallback)
94
+ [ "$cmd" = run ] || return 1
95
+ PP_SHIFT=1; printf 'on\n' > "$plan/infra_fallback" ;;
96
+ --no-infra-fallback)
97
+ [ "$cmd" = run ] || return 1
98
+ PP_SHIFT=1; rm -f "$plan/infra_fallback" ;;
99
+ --infra-backoff)
100
+ [ "$cmd" = run ] || return 1
101
+ PP_MSG="$(python3 "$SKILL_DIR/scripts/forge-schedule.py" backoff-check "${2:-}" 2>&1)" || die "${PP_MSG#forge: }"
102
+ printf '%s\n' "$2" > "$plan/infra_backoff" ;;
52
103
  --qa-threshold)
53
104
  case "$cmd" in run|retry|review) ;; *) return 1 ;; esac
54
105
  case "${2:-}" in
@@ -64,10 +115,44 @@ forge_pp_flag() {
64
115
  if [ "$2" = 0 ]; then
65
116
  rm -f "$plan"/tasks/*/escalation.stop "$plan"/tasks/*/split.suggested "$plan"/tasks/*/escalation.next
66
117
  fi ;;
118
+ --escalate-effort)
119
+ case "$cmd" in run|retry) ;; *) return 1 ;; esac
120
+ PP_SHIFT=1 # a switch, not --escalate-after's N
121
+ printf 'on\n' > "$plan/escalate_effort"
122
+ # A task the policy stopped with the step off is decided again: the step may have a move.
123
+ rm -f "$plan"/tasks/*/escalation.stop "$plan"/tasks/*/split.suggested "$plan"/tasks/*/escalation.next ;;
124
+ --no-escalate-effort)
125
+ case "$cmd" in run|retry) ;; *) return 1 ;; esac
126
+ PP_SHIFT=1
127
+ rm -f "$plan/escalate_effort" ;;
67
128
  --verify-retries)
68
129
  case "$cmd" in run|retry|integrate) ;; *) return 1 ;; esac
69
130
  pp_nonneg --verify-retries "${2:-}"
70
131
  printf '%s' "$2" > "$plan/verify_retries" ;;
132
+ --verify-lane)
133
+ case "$cmd" in run|retry) ;; *) return 1 ;; esac
134
+ pp_lane "$plan" "${2-}" ;;
135
+ --verify-parallel)
136
+ case "$cmd" in run|retry|integrate) ;; *) return 1 ;; esac
137
+ case "${2:-}" in ''|*[!0-9]*) die "--verify-parallel needs an integer from 1 to 32" ;; esac
138
+ [ "$2" -ge 1 ] && [ "$2" -le 32 ] || die "--verify-parallel needs an integer from 1 to 32"
139
+ printf '%s' "$2" > "$plan/verify_parallel" ;;
140
+ --sweep)
141
+ [ "$cmd" = run ] || return 1
142
+ case "${2:-}" in P0|P1|P2|P3) PP_SWEEP="$2" ;; *) die "--sweep needs P0, P1, P2 or P3: the least severe finding it fixes" ;; esac ;;
143
+ --sweep-max)
144
+ [ "$cmd" = run ] || return 1
145
+ case "${2:-}" in ''|*[!0-9]*|0) die "--sweep-max needs a positive integer" ;; esac
146
+ PP_SWEEP_MAX="$2"; PP_SWEEP_MAX_SET=1 ;;
147
+ --sweep-plausible)
148
+ [ "$cmd" = run ] || return 1
149
+ PP_SHIFT=1; PP_SWEEP_PLAUSIBLE=1 ;;
150
+ --sweep-ahead)
151
+ [ "$cmd" = run ] || return 1
152
+ PP_SHIFT=1; printf 'on\n' > "$plan/sweep_ahead" ;;
153
+ --no-sweep-ahead)
154
+ [ "$cmd" = run ] || return 1
155
+ PP_SHIFT=1; rm -f "$plan/sweep_ahead" ;;
71
156
  --final-review)
72
157
  [ "$cmd" = integrate ] || return 1
73
158
  PP_FINAL_REVIEW="${2:?--final-review needs a QA spec}"