forgedock 1.52.0 → 1.54.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +51 -0
- package/README.md +8 -2
- package/bin/auth/app-manifest.mjs +89 -0
- package/bin/auth/app-manifest.test.mjs +75 -0
- package/bin/auth/app-token.mjs +256 -0
- package/bin/auth/app-token.test.mjs +232 -0
- package/bin/brand.mjs +7 -0
- package/bin/config-history.mjs +151 -0
- package/bin/config-schema.mjs +115 -0
- package/bin/demo.mjs +65 -11
- package/bin/engine/outcome-codes.mjs +9 -3
- package/bin/engine/telemetry-seam.mjs +11 -3
- package/bin/engine/telemetry-seam.test.mjs +17 -0
- package/bin/engine-cli.mjs +110 -36
- package/bin/experiment.mjs +58 -6
- package/bin/first-run.mjs +122 -0
- package/bin/forge-utils.mjs +6 -2
- package/bin/forgedock.mjs +138 -142
- package/bin/help-text.mjs +144 -0
- package/bin/hooks/pre-tool-use.mjs +7 -0
- package/bin/journey.mjs +82 -83
- package/bin/lean/acceptance.mjs +313 -0
- package/bin/lean/acceptance.test.mjs +215 -0
- package/bin/lean/account-watch.mjs +28 -0
- package/bin/lean/account-watch.test.mjs +30 -0
- package/bin/lean/activation.mjs +38 -0
- package/bin/lean/activation.test.mjs +36 -1
- package/bin/lean/basered.mjs +115 -0
- package/bin/lean/basered.test.mjs +66 -0
- package/bin/lean/batch-health.mjs +114 -7
- package/bin/lean/batch-health.test.mjs +87 -1
- package/bin/lean/batch.mjs +41 -2
- package/bin/lean/batch.test.mjs +115 -11
- package/bin/lean/branchlock.mjs +54 -0
- package/bin/lean/branchlock.test.mjs +49 -0
- package/bin/lean/ceiling.mjs +72 -0
- package/bin/lean/ceiling.test.mjs +54 -0
- package/bin/lean/checkpoint-reconcile.mjs +43 -0
- package/bin/lean/checkpoint-reconcile.test.mjs +95 -0
- package/bin/lean/ci-budget.mjs +366 -0
- package/bin/lean/ci-budget.test.mjs +167 -0
- package/bin/lean/conformance.e2e.test.mjs +8 -1
- package/bin/lean/conformance.mjs +269 -38
- package/bin/lean/conformance.test.mjs +280 -7
- package/bin/lean/context.mjs +35 -6
- package/bin/lean/context.test.mjs +27 -1
- package/bin/lean/depcache.mjs +25 -1
- package/bin/lean/depcache.test.mjs +26 -0
- package/bin/lean/e2e.mjs +18 -2
- package/bin/lean/e2e.test.mjs +26 -1
- package/bin/lean/effects.mjs +47 -14
- package/bin/lean/execution.mjs +19 -3
- package/bin/lean/execution.test.mjs +63 -0
- package/bin/lean/facts.mjs +3 -3
- package/bin/lean/facts.test.mjs +5 -0
- package/bin/lean/findinglabel.mjs +16 -0
- package/bin/lean/findinglabel.test.mjs +39 -0
- package/bin/lean/fixround.mjs +14 -0
- package/bin/lean/fixround.test.mjs +25 -2
- package/bin/lean/gh-assoc.test.mjs +2 -1
- package/bin/lean/integration.mjs +100 -9
- package/bin/lean/integration.test.mjs +98 -0
- package/bin/lean/issuewatch-parity.mjs +64 -0
- package/bin/lean/issuewatch-parity.test.mjs +127 -0
- package/bin/lean/issuewatch-release.mjs +6 -2
- package/bin/lean/issuewatch-release.test.mjs +17 -1
- package/bin/lean/issuewatch.mjs +45 -6
- package/bin/lean/issuewatch.test.mjs +3 -2
- package/bin/lean/lanelock.mjs +14 -0
- package/bin/lean/lean.mjs +473 -100
- package/bin/lean/lean.test.mjs +686 -33
- package/bin/lean/light.mjs +48 -7
- package/bin/lean/light.test.mjs +37 -3
- package/bin/lean/limits.test.mjs +142 -9
- package/bin/lean/mechfix.mjs +124 -0
- package/bin/lean/mechfix.test.mjs +75 -0
- package/bin/lean/orchestrate-cancel.test.mjs +143 -0
- package/bin/lean/orchestrate.mjs +116 -28
- package/bin/lean/phaseledger.mjs +47 -5
- package/bin/lean/phaseledger.test.mjs +30 -1
- package/bin/lean/postdeploy-check.test.mjs +39 -0
- package/bin/lean/precheck.mjs +23 -4
- package/bin/lean/precheck.test.mjs +14 -1
- package/bin/lean/prereq.mjs +28 -0
- package/bin/lean/prereq.test.mjs +20 -0
- package/bin/lean/probe.mjs +4 -2
- package/bin/lean/prodparity.mjs +52 -0
- package/bin/lean/prodparity.test.mjs +67 -0
- package/bin/lean/prompts.mjs +77 -19
- package/bin/lean/quota.mjs +39 -0
- package/bin/lean/recovery.test.mjs +11 -1
- package/bin/lean/relaxation.mjs +73 -0
- package/bin/lean/relaxation.test.mjs +54 -0
- package/bin/lean/release-io.test.mjs +42 -0
- package/bin/lean/release-postmerge.mjs +125 -0
- package/bin/lean/release-preflight.mjs +58 -0
- package/bin/lean/release-preflight.test.mjs +114 -0
- package/bin/lean/release-rehearsal.mjs +64 -0
- package/bin/lean/release-rehearsal.test.mjs +93 -0
- package/bin/lean/release-review.e2e.test.mjs +77 -0
- package/bin/lean/release-review.mjs +254 -0
- package/bin/lean/release-review.test.mjs +307 -0
- package/bin/lean/release-snapshot.mjs +188 -0
- package/bin/lean/release-snapshot.test.mjs +190 -0
- package/bin/lean/release.mjs +296 -0
- package/bin/lean/release.test.mjs +387 -0
- package/bin/lean/render.mjs +1 -1
- package/bin/lean/replan.mjs +184 -0
- package/bin/lean/replan.test.mjs +110 -0
- package/bin/lean/resume.mjs +9 -7
- package/bin/lean/resume.test.mjs +16 -0
- package/bin/lean/rotator.mjs +150 -31
- package/bin/lean/rotator.test.mjs +105 -2
- package/bin/lean/sandbox-remote.mjs +9 -2
- package/bin/lean/schedd.mjs +83 -5
- package/bin/lean/schedd.test.mjs +108 -7
- package/bin/lean/selfreview.mjs +94 -0
- package/bin/lean/selfreview.test.mjs +58 -1
- package/bin/lean/selftest-gate.mjs +22 -0
- package/bin/lean/selftest-gate.test.mjs +18 -1
- package/bin/lean/selftest-journey.mjs +234 -0
- package/bin/lean/selftest-journey.test.mjs +130 -0
- package/bin/lean/selftest-live.mjs +2 -1
- package/bin/lean/seqlease.mjs +35 -1
- package/bin/lean/seqlease.test.mjs +15 -0
- package/bin/lean/seqreserve.e2e.test.mjs +135 -0
- package/bin/lean/seqreserve.mjs +73 -0
- package/bin/lean/seqreserve.test.mjs +134 -0
- package/bin/lean/sequence.mjs +35 -6
- package/bin/lean/seqversioned.mjs +147 -0
- package/bin/lean/stagestamp.mjs +28 -0
- package/bin/lean/stagestamp.test.mjs +32 -0
- package/bin/lean/surfaces.mjs +75 -0
- package/bin/lean/surfaces.test.mjs +59 -0
- package/bin/lean/toolplace.mjs +28 -0
- package/bin/lean/toolplace.test.mjs +24 -0
- package/bin/lean/toolstats.mjs +3 -1
- package/bin/lean/toolstats.test.mjs +11 -0
- package/bin/lean/validatebest.mjs +28 -0
- package/bin/lean/validatebest.test.mjs +27 -0
- package/bin/lean/verifier.mjs +3 -2
- package/bin/lean/verify.mjs +2 -1
- package/bin/lean/verify.test.mjs +6 -0
- package/bin/pool/agent.mjs +27 -4
- package/bin/pool/docker.mjs +5 -0
- package/bin/pool/router.mjs +74 -28
- package/bin/prereqs.mjs +111 -0
- package/bin/replay-timelapse.mjs +149 -0
- package/bin/review-staging.mjs +123 -16
- package/bin/review-staging.test.mjs +18 -0
- package/bin/runner.mjs +43 -6
- package/bin/splash-install.mjs +157 -0
- package/bin/stats/aggregate.mjs +8 -1
- package/bin/stats/conformance-outcomes.mjs +289 -0
- package/bin/stats/conformance-outcomes.test.mjs +274 -0
- package/bin/stats/depth.mjs +275 -0
- package/bin/stats/depth.test.mjs +158 -0
- package/bin/stats/efficiency.mjs +26 -5
- package/bin/stats/efficiency.test.mjs +45 -1
- package/bin/stats/experiment.mjs +7 -5
- package/bin/stats/first-review.mjs +77 -0
- package/bin/stats/first-review.test.mjs +36 -0
- package/bin/stats/firstmerge.mjs +40 -0
- package/bin/stats/firstmerge.test.mjs +41 -0
- package/bin/stats/github-source.mjs +53 -15
- package/bin/stats/index.mjs +147 -9
- package/bin/stats/local-source.mjs +12 -0
- package/bin/stats/origin.mjs +80 -0
- package/bin/stats/origin.test.mjs +58 -0
- package/bin/stats/query.mjs +69 -0
- package/bin/stats/render.mjs +3 -1
- package/bin/stats/scoreboard.mjs +137 -0
- package/bin/stats/scoreboard.test.mjs +87 -0
- package/bin/stats/selffiled.mjs +52 -0
- package/bin/stats/selffiled.test.mjs +71 -0
- package/bin/stats/stats.test.mjs +80 -0
- package/bin/tui.mjs +3 -2
- package/commands/bootstrap.md +15 -14
- package/commands/deploy-pr.md +18 -3
- package/commands/forge-stats.md +1 -1
- package/commands/forgedock-ci-setup.md +28 -0
- package/commands/forgedock-init.md +4 -5
- package/commands/issue.md +2 -0
- package/commands/milestone.md +9 -1
- package/commands/orchestrate.md +1 -1
- package/commands/replay.md +2 -0
- package/commands/review-pr-agents/security.md +4 -0
- package/commands/review-pr-staging.md +6 -1
- package/commands/work-on/build.md +4 -6
- package/commands/work-on/close.md +8 -0
- package/docs/CONFIG.md +170 -18
- package/docs/ISSUE-WATCH.md +25 -0
- package/docs/OUTCOME-CODES.md +4 -0
- package/docs/REPLAY.md +9 -0
- package/docs/SELFTEST.md +11 -0
- package/docs/STATS.md +61 -0
- package/docs/TELEMETRY.md +1 -1
- package/docs/eval/README.md +6 -0
- package/docs/eval/adversarial-bench.md +68 -0
- package/docs/eval/corpus/adversarial-v1.json +285 -0
- package/docs/eval/feature-bench.md +42 -0
- package/docs/eval/feature-specs/crud-auth/journeys/notes-crud-isolated.mjs +21 -0
- package/docs/eval/feature-specs/crud-auth/journeys/register-login.mjs +12 -0
- package/docs/eval/feature-specs/crud-auth/spec.md +15 -0
- package/docs/site/start-a-new-project.md +2 -1
- package/package.json +5 -2
- package/plugins/forgedock-splash/.claude-plugin/plugin.json +10 -0
- package/plugins/forgedock-splash/README.md +27 -0
- package/plugins/forgedock-splash/hooks/hooks.json +1 -0
- package/plugins/forgedock-splash/hooks/register.tsx +74 -0
- package/plugins/forgedock-splash/hooks/scene.ts +222 -0
- package/plugins/forgedock-splash/types/index.d.ts +10 -0
- package/pool/README.md +1 -1
- package/pool/image/cs-cred +14 -1
- package/scripts/backfill-finding-labels.mjs +50 -0
- package/scripts/backfill-finding-labels.test.mjs +36 -0
- package/scripts/bench-adversarial.mjs +216 -0
- package/scripts/bench-feature.mjs +170 -0
- package/scripts/bench-lightlane.mjs +2 -2
- package/scripts/bootstrap-create.mjs +2 -2
- package/scripts/bootstrap-validate.mjs +35 -2
- package/scripts/check-spec-size.sh +4 -3
- package/scripts/check-spec-size.test.sh +3 -0
- package/scripts/doctor-pipeline-state.sh +21 -6
- package/scripts/file-deferred-followups.sh +59 -251
- package/scripts/file-deferred-followups.test.sh +85 -206
- package/scripts/followup-route.mjs +12 -0
- package/scripts/owner-route-parity.test.sh +17 -1
- package/scripts/plan-validate-live.mjs +40 -6
- package/scripts/review-pr-side-effects.test.sh +40 -0
- package/scripts/review-pr-staging-scope.test.sh +1 -1
- package/scripts/review-staging-post.sh +23 -0
- package/scripts/review-staging-post.test.sh +8 -0
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
// Pure scene: frame number -> rows of coloured runs. No engine imports, so the
|
|
4
|
+
// same code drives the mod and the offline frame preview.
|
|
5
|
+
|
|
6
|
+
export type Run = { text: string; color?: string; bold?: boolean }
|
|
7
|
+
type Cell = { ch: string; color?: string; bold?: boolean }
|
|
8
|
+
|
|
9
|
+
export const TICK = 60
|
|
10
|
+
|
|
11
|
+
// The ForgeDock "F" mark, exactly as the CLI draws it (bin/cinema.mjs HERO_MARK).
|
|
12
|
+
const MARK = [
|
|
13
|
+
' ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄',
|
|
14
|
+
' ▄▄██████████████████',
|
|
15
|
+
' ▄█████████████▀▀▀▀▀▀▀▀▀',
|
|
16
|
+
' ▄██████████▀▀',
|
|
17
|
+
' ▀▀▀▀▀ ▄▄███████▀',
|
|
18
|
+
' ▄████████▀',
|
|
19
|
+
' ▄██████▀',
|
|
20
|
+
' ▀▀▀▀',
|
|
21
|
+
]
|
|
22
|
+
const MW = 28 // mark width
|
|
23
|
+
const TOP = 1 // canvas row of the mark's first row (row 0 is headroom for sparks)
|
|
24
|
+
const H = MARK.length + TOP
|
|
25
|
+
const CW = 56 // canvas width
|
|
26
|
+
const TEXT_X = 33 // column of the wordmark block
|
|
27
|
+
|
|
28
|
+
// Brand stops (bin/cinema.mjs) and Claude's orange for the mascot.
|
|
29
|
+
const DARK = { chrome: ['#f7f3ea', '#d9cfba', '#a99a82', '#6e6252'], ember: ['#ff4d00', '#ff8c1a', '#ffd166'], hot: '#ffffff', bg: '#1a1714' }
|
|
30
|
+
// Light terminals: a darker steel and deeper embers so the mark reads on white; the "white-hot" flash becomes bright orange.
|
|
31
|
+
const LIGHT = { chrome: ['#6e6252', '#5c5144', '#4a4136', '#2f2922'], ember: ['#c43c00', '#e06600', '#f29d00'], hot: '#ff7a00', bg: '#f4f1ec' }
|
|
32
|
+
let CHROME = DARK.chrome
|
|
33
|
+
let EMBER = DARK.ember
|
|
34
|
+
let WHITE = DARK.hot
|
|
35
|
+
let BG = DARK.bg
|
|
36
|
+
const CLAUDE = '#d97757'
|
|
37
|
+
|
|
38
|
+
/** Pick the palette for the terminal's theme (Claude Code's `theme` setting). */
|
|
39
|
+
export function setTheme(light: boolean) {
|
|
40
|
+
const t = light ? LIGHT : DARK
|
|
41
|
+
CHROME = t.chrome
|
|
42
|
+
EMBER = t.ember
|
|
43
|
+
WHITE = t.hot
|
|
44
|
+
BG = t.bg
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Smallest band the scene fits in. */
|
|
48
|
+
export const MIN_COLUMNS = 56
|
|
49
|
+
export const MIN_ROWS = 9
|
|
50
|
+
const WORD = 'F O R G E D O C K'
|
|
51
|
+
|
|
52
|
+
// Clawd poses (3 rows, 9 wide).
|
|
53
|
+
const P = {
|
|
54
|
+
stand: [' ▐▛███▜▌ ', '▝▜█████▛▘', ' ▘▘ ▝▝ '],
|
|
55
|
+
stepA: [' ▐▛███▜▌ ', '▝▜█████▛▘', ' ▘▘ ▝▝ '],
|
|
56
|
+
stepB: [' ▐▛███▜▌ ', '▝▜█████▛▘', ' ▘▘ ▝▝ '],
|
|
57
|
+
look: [' ▐▀███▀▌ ', '▝▜█████▛▘', ' ▘▘ ▝▝ '],
|
|
58
|
+
blink: [' ▐█████▌ ', '▝▜█████▛▘', ' ▘▘ ▝▝ '],
|
|
59
|
+
side: [' ▐█▜██▛▌ ', '▝▜█████▛▘', ' ▘▘ ▝▝ '],
|
|
60
|
+
crouch: [' ', ' ▐▛███▜▌ ', '▀▀█████▀▀'],
|
|
61
|
+
jump: ['▗▐▀███▀▌▖', ' ▜█████▛ ', ' ▝▘ ▝▘ '],
|
|
62
|
+
cheer: ['▗▐▛███▜▌▖', ' ▜█████▛ ', ' ▘▘ ▝▝ '],
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Beats (frame numbers).
|
|
66
|
+
const FORGE = 12 // the F is forged in, glowing then cooling
|
|
67
|
+
const WALK_END = FORGE + 18 // Clawd walks in under the overhang
|
|
68
|
+
const LOOK_END = WALK_END + 5 // looks up at the bar
|
|
69
|
+
const CROUCH_END = LOOK_END + 2
|
|
70
|
+
const BONK = CROUCH_END + 3 // head meets the bar
|
|
71
|
+
const LAND = BONK + 3
|
|
72
|
+
const SHINE_END = BONK + 18 // shine ring expands from the impact
|
|
73
|
+
const TYPE_START = BONK + 6
|
|
74
|
+
const TYPE_END = TYPE_START + WORD.length
|
|
75
|
+
const HOLD_START = TYPE_END + 4
|
|
76
|
+
const FADE_START = HOLD_START + 32
|
|
77
|
+
export const LAST = FADE_START + 10
|
|
78
|
+
|
|
79
|
+
const CLAWD_X = 21 // under the right end of the top bar, clear of the F's lower strokes
|
|
80
|
+
const START_X = CW // walks in from the right edge
|
|
81
|
+
const IMPACT = { r: TOP + 2, c: 25 } // underside of the top bar, above Clawd's head
|
|
82
|
+
|
|
83
|
+
const hex = (s: string) => [1, 3, 5].map(i => parseInt(s.slice(i, i + 2), 16))
|
|
84
|
+
export const mix = (a: string, b: string, t: number) => {
|
|
85
|
+
const x = hex(a), y = hex(b), k = Math.max(0, Math.min(1, t))
|
|
86
|
+
return '#' + x.map((v, i) => Math.round(v + ((y[i] ?? v) - v) * k).toString(16).padStart(2, '0')).join('')
|
|
87
|
+
}
|
|
88
|
+
const ramp = (stops: string[], t: number) => {
|
|
89
|
+
const u = Math.max(0, Math.min(1, t)) * (stops.length - 1)
|
|
90
|
+
const i = Math.min(stops.length - 2, Math.floor(u))
|
|
91
|
+
return mix(stops[i] ?? WHITE, stops[i + 1] ?? WHITE, u - i)
|
|
92
|
+
}
|
|
93
|
+
const easeOut = (t: number) => 1 - (1 - t) * (1 - t)
|
|
94
|
+
|
|
95
|
+
function markColor(r: number, c: number, f: number): string | null {
|
|
96
|
+
const chrome = ramp(CHROME, c / MW + r * 0.06)
|
|
97
|
+
if (f < FORGE + 6) {
|
|
98
|
+
const age = (f / FORGE) * (MW + 6) - r * 0.6 - c
|
|
99
|
+
if (age < 0) return null
|
|
100
|
+
if (age < 1.5) return EMBER[2] ?? WHITE
|
|
101
|
+
if (age < 3) return EMBER[1] ?? WHITE
|
|
102
|
+
if (age < 5) return EMBER[0] ?? WHITE
|
|
103
|
+
return mix(EMBER[0] ?? WHITE, chrome, (age - 5) / 5)
|
|
104
|
+
}
|
|
105
|
+
if (f >= BONK && f < SHINE_END) {
|
|
106
|
+
const t = f - BONK
|
|
107
|
+
const dr = (r + TOP - IMPACT.r) * 2 // rows are ~2x taller than columns are wide
|
|
108
|
+
const dist = Math.sqrt(dr * dr + (c - IMPACT.c) ** 2)
|
|
109
|
+
if (t < 2 && dist < 2.6) return WHITE // a small flash right at the point of impact
|
|
110
|
+
if (t < 7 && dist < 4) {
|
|
111
|
+
// the struck spot glows hot, then fades straight back to chrome (no muddy brown)
|
|
112
|
+
const heat = t < 4 ? (EMBER[2] ?? WHITE) : (EMBER[1] ?? WHITE)
|
|
113
|
+
return mix(heat, chrome, Math.min(1, (t - 2) / 4 + dist / 6))
|
|
114
|
+
}
|
|
115
|
+
const radius = (t - 1) * 2.4
|
|
116
|
+
const d = Math.abs(dist - radius)
|
|
117
|
+
if (d < 1.2) return WHITE
|
|
118
|
+
if (d < 3) return mix(WHITE, chrome, (d - 1.2) / 1.8)
|
|
119
|
+
}
|
|
120
|
+
return chrome
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function clawd(f: number): { x: number; lift: number; pose: string[] } | null {
|
|
124
|
+
if (f < FORGE) return null
|
|
125
|
+
if (f < WALK_END) {
|
|
126
|
+
const t = (f - FORGE) / (WALK_END - FORGE)
|
|
127
|
+
const x = Math.round(START_X + (CLAWD_X - START_X) * easeOut(t))
|
|
128
|
+
return { x, lift: 0, pose: Math.floor(f / 2) % 2 ? P.stepA : P.stepB }
|
|
129
|
+
}
|
|
130
|
+
if (f < LOOK_END) return { x: CLAWD_X, lift: 0, pose: P.look }
|
|
131
|
+
if (f < CROUCH_END) return { x: CLAWD_X, lift: 0, pose: P.crouch }
|
|
132
|
+
if (f < BONK) return { x: CLAWD_X, lift: Math.min(2, f - CROUCH_END + 1), pose: P.jump }
|
|
133
|
+
if (f === BONK) return { x: CLAWD_X, lift: 2, pose: P.jump }
|
|
134
|
+
if (f < LAND) return { x: CLAWD_X, lift: LAND - f, pose: P.jump }
|
|
135
|
+
if (f === LAND) return { x: CLAWD_X, lift: 0, pose: P.crouch }
|
|
136
|
+
if (f < HOLD_START) {
|
|
137
|
+
const k = (f - LAND) % 6
|
|
138
|
+
return { x: CLAWD_X, lift: k === 2 || k === 3 ? 1 : 0, pose: P.cheer }
|
|
139
|
+
}
|
|
140
|
+
// Idle: glance at the wordmark, a happy hop, then a blink.
|
|
141
|
+
const k = f - HOLD_START
|
|
142
|
+
if (k >= 4 && k < 14) return { x: CLAWD_X, lift: 0, pose: P.side }
|
|
143
|
+
if (k >= 16 && k < 20) return { x: CLAWD_X, lift: k === 17 || k === 18 ? 1 : 0, pose: P.cheer }
|
|
144
|
+
return { x: CLAWD_X, lift: 0, pose: k === 24 || k === 25 ? P.blink : P.stand }
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Sparks thrown from the impact: analytic paths with a little gravity.
|
|
148
|
+
const SPARKS = [
|
|
149
|
+
[1.2, -1.1], [2.2, -0.8], [3.2, -0.35], [3.8, 0.15], [2.8, 0.55], [1.6, 0.9], [4.4, -0.6], [0.6, -1.4],
|
|
150
|
+
]
|
|
151
|
+
function sparks(f: number, put: (r: number, c: number, cell: Cell) => void) {
|
|
152
|
+
const t = f - BONK
|
|
153
|
+
if (t < 1 || t > 11) return
|
|
154
|
+
// Plain glyphs every terminal font has.
|
|
155
|
+
const glyph = ['*', '*', '*', '+', '+', '+', '•', '•', '·', '·', '.', '.'][t] ?? '.'
|
|
156
|
+
const color = t < 3 ? WHITE : t < 5 ? (EMBER[2] ?? WHITE) : t < 8 ? (EMBER[1] ?? WHITE) : (EMBER[0] ?? WHITE)
|
|
157
|
+
for (const [vx, vy] of SPARKS) {
|
|
158
|
+
const c = Math.round(IMPACT.c + 2 + (vx ?? 0) * t * 1.3)
|
|
159
|
+
const r = Math.round(IMPACT.r + (vy ?? 0) * t * 0.6 + 0.05 * t * t)
|
|
160
|
+
put(r, c, { ch: glyph, color, bold: t < 4 })
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export function scene(f: number): Run[][] {
|
|
165
|
+
const grid: Cell[][] = Array.from({ length: H }, () => Array.from({ length: CW }, () => ({ ch: ' ' })))
|
|
166
|
+
const put = (r: number, c: number, cell: Cell, over = false) => {
|
|
167
|
+
const row = grid[r]
|
|
168
|
+
if (!row || c < 0 || c >= CW) return
|
|
169
|
+
if (!over && row[c]?.ch !== ' ') return
|
|
170
|
+
row[c] = cell
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
MARK.forEach((line, r) =>
|
|
174
|
+
[...line].forEach((ch, c) => {
|
|
175
|
+
if (ch === ' ') return
|
|
176
|
+
const color = markColor(r, c, f)
|
|
177
|
+
if (color) put(r + TOP, c, { ch, color })
|
|
178
|
+
}),
|
|
179
|
+
)
|
|
180
|
+
|
|
181
|
+
// Wordmark block: letters land white-hot and cool to ember.
|
|
182
|
+
if (f >= TYPE_START) {
|
|
183
|
+
const n = Math.min(WORD.length, f - TYPE_START + 1)
|
|
184
|
+
;[...WORD.slice(0, n)].forEach((ch, i) => {
|
|
185
|
+
const age = f - TYPE_START - i
|
|
186
|
+
const settled = ramp(EMBER, i / WORD.length)
|
|
187
|
+
put(TOP + 2, TEXT_X + i, { ch, color: age < 1 ? WHITE : age < 3 ? mix(WHITE, settled, age / 3) : settled, bold: true })
|
|
188
|
+
})
|
|
189
|
+
}
|
|
190
|
+
if (f >= TYPE_END) [...'for Claude Code'].forEach((ch, i) => put(TOP + 3, TEXT_X + i, { ch, color: CLAUDE, bold: true }))
|
|
191
|
+
if (f >= HOLD_START) {
|
|
192
|
+
const pulse = ramp(EMBER, 0.5 + 0.5 * Math.sin((f - HOLD_START) / 3))
|
|
193
|
+
;[...'» supercharged'].forEach((ch, i) => put(TOP + 5, TEXT_X + i, { ch, color: pulse, bold: true }))
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const cd = clawd(f)
|
|
197
|
+
if (cd) {
|
|
198
|
+
const top = H - 3 - cd.lift
|
|
199
|
+
cd.pose.forEach((line, i) =>
|
|
200
|
+
[...line].forEach((ch, j) => {
|
|
201
|
+
if (ch !== ' ') put(top + i, cd.x + j, { ch, color: CLAUDE }, true)
|
|
202
|
+
}),
|
|
203
|
+
)
|
|
204
|
+
}
|
|
205
|
+
sparks(f, put)
|
|
206
|
+
|
|
207
|
+
// Fade everything to the background over the last beat.
|
|
208
|
+
const fade = f >= FADE_START ? (f - FADE_START + 1) / (LAST - FADE_START + 1) : 0
|
|
209
|
+
|
|
210
|
+
return grid.map(row => {
|
|
211
|
+
const runs: Run[] = []
|
|
212
|
+
for (const cell of row) {
|
|
213
|
+
const color = cell.color && fade > 0 ? mix(cell.color, BG, fade) : cell.color
|
|
214
|
+
const last = runs[runs.length - 1]
|
|
215
|
+
if (last && last.color === color && last.bold === cell.bold) last.text += cell.ch
|
|
216
|
+
else runs.push({ text: cell.ch, color, bold: cell.bold })
|
|
217
|
+
}
|
|
218
|
+
// Drop trailing blanks so the band is no wider than it needs to be.
|
|
219
|
+
while (runs.length && !runs[runs.length - 1]?.color && !runs[runs.length - 1]?.text.trim()) runs.pop()
|
|
220
|
+
return runs
|
|
221
|
+
})
|
|
222
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
/** Animation frame of the splash; -1 when hidden. */
|
|
4
|
+
export type Frame = number
|
|
5
|
+
|
|
6
|
+
declare module 'claude-code' {
|
|
7
|
+
interface PluginState {
|
|
8
|
+
'forgedock-splash': { frame: Frame }
|
|
9
|
+
}
|
|
10
|
+
}
|
package/pool/README.md
CHANGED
|
@@ -10,6 +10,6 @@ ForgeDock's built-in remote compute pool (imported from computeshare; AGPL-3.0-o
|
|
|
10
10
|
|
|
11
11
|
The module boundary is the ForgeDock HTTP sandbox protocol: the router speaks it to the dispatcher and relays to agents over HTTP. Sandboxes receive only short-lived GitHub and Claude access tokens; refresh tokens stay on the router host.
|
|
12
12
|
|
|
13
|
-
Claude login choice (#5165): among the router host's logins with 30+ minutes left, the router hands out the one with the lowest 5-hour use in tokenbaton's `live.<n>` (account `n` = `~/.claude-<n>`), read from router.json `usage_source` (default `$TOKENBATON_HOME`, else `~/.tokenbaton`); validity only breaks ties. An account at or above `usage_ceiling_pct` (default 95) or at 100% weekly use is skipped; when every login is, `/agent/creds/claude` answers a typed 429 (`code: rate_limited`, `reset_at` = the earliest reset, `retry-after`), which the agent passes through and `cs-cred` prints as `usage limit hit; resets at <ISO>` so the lane defers. Without readable usage it falls back to the longest validity and logs a warning. The selected account index and usage are logged, never the token.
|
|
13
|
+
Claude login choice (#5165): among the router host's logins with 30+ minutes left, the router hands out the one with the lowest 5-hour use in tokenbaton's `live.<n>` (account `n` = `~/.claude-<n>`), read from router.json `usage_source` (default `$TOKENBATON_HOME`, else `~/.tokenbaton`); validity only breaks ties. An account at or above `usage_ceiling_pct` (default 95) or at 100% weekly use is skipped; when every login is, `/agent/creds/claude` answers a typed 429 (`code: rate_limited`, `reset_at` = the earliest reset, `retry-after`), which the agent passes through and `cs-cred` prints as `usage limit hit; resets at <ISO>` so the lane defers. Without readable usage it falls back to the longest validity and logs a warning. The selected account index and usage are logged, never the token. A sample whose 5-hour reset has passed is stale (#5205): unknown usage, never 0%, ranked after fresh samples. A lane that hits a usage limit runs `cs-cred claude --limited <reset>`, which drops the sandbox's cached token and posts to `/sandboxes/<id>/creds/claude/limited`; the agent drops its own cache and forwards to the router's `POST /agent/creds/claude/limited`, which excludes the account it last handed that agent until the reset (default one hour), then the lane fetches the next login and relaunches at once. With every login excluded or blocked, the 429 carries the earliest reset, limited accounts included.
|
|
14
14
|
|
|
15
15
|
The `forgedock pool` CLI wiring is tracked separately (#4544).
|
package/pool/image/cs-cred
CHANGED
|
@@ -2,9 +2,19 @@
|
|
|
2
2
|
# SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
3
3
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
4
4
|
# cs-cred <github|claude>: prints a current credential, fetched through the agent and cached briefly.
|
|
5
|
+
# cs-cred claude --limited [reset]: the lane hit a usage limit (#5205): drop the cache, report it (reset: epoch s or
|
|
6
|
+
# unknown) so the router excludes that account until then, and fetch the next login's token as usual.
|
|
5
7
|
set -euo pipefail
|
|
6
8
|
kind="${1:?kind}"; ttl=240; [ "$kind" = claude ] && ttl=600
|
|
7
9
|
cache="/tmp/.cs-cred-$kind"
|
|
10
|
+
if [ "$kind" = claude ] && [ "${2:-}" = --limited ]; then
|
|
11
|
+
rm -f "$cache"
|
|
12
|
+
[ -n "${CS_CRED_BASE:-}" ] || { echo "no credential relay (CS_CRED_BASE)" >&2; exit 1; }
|
|
13
|
+
reset="${3:-}"; [[ "$reset" =~ ^[0-9]+$ ]] || reset=""
|
|
14
|
+
acct=$(cat "$cache.account" 2>/dev/null || true); [[ "$acct" =~ ^[0-9]+$ ]] || acct=""
|
|
15
|
+
curl -sS --max-time 30 -o /dev/null -X POST -H "authorization: Bearer ${CS_CRED_TOKEN}" -H "content-type: application/json" \
|
|
16
|
+
-d "{\"reset_at\":${reset:-null},\"account\":${acct:-null}}" "$CS_CRED_BASE/claude/limited" || true
|
|
17
|
+
fi
|
|
8
18
|
if [ -s "$cache" ] && [ $(( $(date +%s) - $(stat -c %Y "$cache") )) -lt $ttl ]; then cat "$cache"; exit 0; fi
|
|
9
19
|
[ -n "${CS_CRED_BASE:-}" ] || { echo "no credential relay (CS_CRED_BASE)" >&2; exit 1; }
|
|
10
20
|
body=$(mktemp); trap 'rm -f "$body"' EXIT
|
|
@@ -16,4 +26,7 @@ if [ "$code" = 429 ]; then
|
|
|
16
26
|
fi
|
|
17
27
|
tok=""; [ "$code" = 200 ] && tok=$(jq -r .token "$body" 2>/dev/null || true)
|
|
18
28
|
[ -n "$tok" ] && [ "$tok" != null ] || { echo "credential fetch failed ($kind)" >&2; exit 1; }
|
|
19
|
-
umask 077; printf '%s' "$tok" > "$cache"
|
|
29
|
+
umask 077; printf '%s' "$tok" > "$cache"
|
|
30
|
+
acct=""; [ "$code" = 200 ] && acct=$(jq -r '.account // empty' "$body" 2>/dev/null || true)
|
|
31
|
+
if [[ "$acct" =~ ^[0-9]+$ ]]; then printf '%s' "$acct" > "$cache.account"; else rm -f "$cache.account"; fi
|
|
32
|
+
printf '%s' "$tok"
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
3
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
4
|
+
/**
|
|
5
|
+
* One-shot backfill (#5254): closed `review-finding` issues still labelled `needs-validation`.
|
|
6
|
+
* workflow:merged -> validated; workflow:invalid or closed "not planned" -> false-positive; anything else is skipped.
|
|
7
|
+
* Dry run by default: prints the counts it would change; edits only with --apply.
|
|
8
|
+
* Usage: backfill-finding-labels.mjs --repo owner/name [--apply] [--limit N]
|
|
9
|
+
*/
|
|
10
|
+
import { execFileSync } from "node:child_process";
|
|
11
|
+
import { fileURLToPath } from "node:url";
|
|
12
|
+
|
|
13
|
+
const names = (i) => (i.labels ?? []).map((l) => l?.name ?? l);
|
|
14
|
+
|
|
15
|
+
/** The label an old closed finding should carry, or null when its outcome is not derivable. */
|
|
16
|
+
export function targetLabel(issue) {
|
|
17
|
+
const l = names(issue);
|
|
18
|
+
if (l.includes("workflow:invalid") || issue.stateReason === "NOT_PLANNED") return "false-positive";
|
|
19
|
+
if (l.includes("workflow:merged")) return "validated";
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function backfill({ issues, apply = false, edit }) {
|
|
24
|
+
const counts = { validated: 0, "false-positive": 0, skipped: 0, failed: 0 };
|
|
25
|
+
const changes = [];
|
|
26
|
+
for (const i of issues) {
|
|
27
|
+
const t = targetLabel(i);
|
|
28
|
+
if (!t) { counts.skipped++; continue; }
|
|
29
|
+
if (apply) {
|
|
30
|
+
try { edit(i.number, t); } catch { counts.failed++; continue; }
|
|
31
|
+
}
|
|
32
|
+
counts[t]++; changes.push({ number: i.number, add: t });
|
|
33
|
+
}
|
|
34
|
+
return { mode: apply ? "apply" : "dry-run", counts, changes };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function main(argv) {
|
|
38
|
+
const get = (f) => { const k = argv.indexOf(f); return k >= 0 ? argv[k + 1] : null; };
|
|
39
|
+
const repo = get("--repo"), limit = get("--limit") ?? "1000", apply = argv.includes("--apply");
|
|
40
|
+
if (!repo) { console.error("usage: backfill-finding-labels.mjs --repo owner/name [--apply] [--limit N]"); return 2; }
|
|
41
|
+
const gh = (a) => execFileSync("gh", a, { encoding: "utf8" });
|
|
42
|
+
const issues = JSON.parse(gh(["issue", "list", "-R", repo, "--state", "closed", "--label", "review-finding", "--label", "needs-validation", "--limit", limit, "--json", "number,labels,stateReason"]) || "[]");
|
|
43
|
+
const edit = (n, add) => gh(["issue", "edit", String(n), "-R", repo, "--add-label", add, "--remove-label", "needs-validation"]);
|
|
44
|
+
const r = backfill({ issues, apply, edit });
|
|
45
|
+
const c = r.counts;
|
|
46
|
+
console.log(`${apply ? "applied" : "dry-run (pass --apply to change)"}: ${c.validated} -> validated, ${c["false-positive"]} -> false-positive, ${c.skipped} skipped${c.failed ? `, ${c.failed} failed` : ""}`);
|
|
47
|
+
return c.failed ? 1 : 0;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (process.argv[1] === fileURLToPath(import.meta.url)) process.exit(main(process.argv.slice(2)));
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
import { describe, it } from "node:test";
|
|
4
|
+
import assert from "node:assert/strict";
|
|
5
|
+
import { backfill, targetLabel } from "./backfill-finding-labels.mjs";
|
|
6
|
+
|
|
7
|
+
const issues = [
|
|
8
|
+
{ number: 1, labels: [{ name: "workflow:merged" }] },
|
|
9
|
+
{ number: 2, labels: [{ name: "workflow:invalid" }] },
|
|
10
|
+
{ number: 3, labels: [], stateReason: "NOT_PLANNED" },
|
|
11
|
+
{ number: 4, labels: [{ name: "workflow:merged" }, { name: "workflow:invalid" }] },
|
|
12
|
+
{ number: 5, labels: [] },
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
describe("backfill-finding-labels (#5254)", () => {
|
|
16
|
+
it("maps merged to validated, invalid / not planned to false-positive, else null", () => {
|
|
17
|
+
assert.deepEqual(issues.map(targetLabel), ["validated", "false-positive", "false-positive", "false-positive", null]);
|
|
18
|
+
});
|
|
19
|
+
it("dry-run reports counts and edits nothing", () => {
|
|
20
|
+
const calls = [];
|
|
21
|
+
const r = backfill({ issues, edit: (...a) => calls.push(a) });
|
|
22
|
+
assert.equal(r.mode, "dry-run");
|
|
23
|
+
assert.deepEqual(r.counts, { validated: 1, "false-positive": 3, skipped: 1, failed: 0 });
|
|
24
|
+
assert.deepEqual(calls, []);
|
|
25
|
+
});
|
|
26
|
+
it("--apply edits each mapped issue", () => {
|
|
27
|
+
const calls = [];
|
|
28
|
+
const r = backfill({ issues, apply: true, edit: (n, l) => calls.push([n, l]) });
|
|
29
|
+
assert.equal(r.mode, "apply");
|
|
30
|
+
assert.deepEqual(calls, [[1, "validated"], [2, "false-positive"], [3, "false-positive"], [4, "false-positive"]]);
|
|
31
|
+
});
|
|
32
|
+
it("a failed edit is counted, not reported as changed", () => {
|
|
33
|
+
const r = backfill({ issues: [issues[0]], apply: true, edit: () => { throw new Error("x"); } });
|
|
34
|
+
assert.deepEqual(r.counts, { validated: 0, "false-positive": 0, skipped: 0, failed: 1 });
|
|
35
|
+
});
|
|
36
|
+
});
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
3
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
4
|
+
/**
|
|
5
|
+
* scripts/bench-adversarial.mjs — adversarial corpus: full lane vs a bare-agent control (#5292)
|
|
6
|
+
*
|
|
7
|
+
* Sibling of bench-lightlane.mjs (#4453), which it reuses for the arm runs. The corpus mixes valid issues with ones that
|
|
8
|
+
* must not be implemented (wrong premise, duplicate of an existing feature, already shipped) and with integration issues
|
|
9
|
+
* whose correct change touches more than one file. Grading is deterministic (diff paths and added lines), no LLM.
|
|
10
|
+
* Instructions: docs/eval/adversarial-bench.md. Corpus: docs/eval/corpus/adversarial-v1.json.
|
|
11
|
+
*
|
|
12
|
+
* Usage:
|
|
13
|
+
* node scripts/bench-adversarial.mjs validate --corpus <corpus.json>
|
|
14
|
+
* node scripts/bench-adversarial.mjs calibrate --corpus <corpus.json>
|
|
15
|
+
* node scripts/bench-adversarial.mjs run --corpus <corpus.json> --config <runcfg.json> --out <rows.jsonl> [--arms full,control] [--issues id,...] [--keep]
|
|
16
|
+
* node scripts/bench-adversarial.mjs aggregate <rows.jsonl|-> --corpus <corpus.json> --model <id> --date <YYYY-MM-DD> [--scorecard <file.md>]
|
|
17
|
+
*
|
|
18
|
+
* Exit codes: 0 ok | 1 invalid input or a failed run step | 2 a calibration check failed (output still emitted)
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { createHash } from "node:crypto";
|
|
22
|
+
import { appendFileSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
23
|
+
import { tmpdir } from "node:os";
|
|
24
|
+
import { join } from "node:path";
|
|
25
|
+
import { pathToFileURL } from "node:url";
|
|
26
|
+
import { benchDefaultRun, parseRows, runArm, validateRunConfig } from "./bench-lightlane.mjs";
|
|
27
|
+
|
|
28
|
+
export const ADV_ARMS = ["full", "control"];
|
|
29
|
+
export const KINDS = ["valid", "wrong-premise", "duplicate", "already-fixed", "integration"];
|
|
30
|
+
export const MIN_ISSUES = 20;
|
|
31
|
+
export const MIN_INVALID = 5;
|
|
32
|
+
const INVALID = new Set(["wrong-premise", "duplicate", "already-fixed"]);
|
|
33
|
+
const SHA_RE = /^[0-9a-f]{40}$/;
|
|
34
|
+
|
|
35
|
+
/** True for an issue that must be closed with evidence instead of implemented. */
|
|
36
|
+
export const isInvalid = (issue) => INVALID.has(issue?.kind);
|
|
37
|
+
|
|
38
|
+
const goodRegex = (p) => { try { new RegExp(p); return typeof p === "string" && p.length > 0; } catch { return false; } };
|
|
39
|
+
|
|
40
|
+
/** A parsed corpus, or a thrown Error naming the first bad field. */
|
|
41
|
+
export function validateAdversarialCorpus(c) {
|
|
42
|
+
if (!c || typeof c !== "object") throw new Error("corpus: not an object");
|
|
43
|
+
for (const k of ["version", "clone_url", "suite_command", "control_prompt"]) if (typeof c[k] !== "string" || !c[k].trim()) throw new Error(`corpus: missing ${k}`);
|
|
44
|
+
if (!SHA_RE.test(String(c.base))) throw new Error("corpus: base must be a full 40-hex sha");
|
|
45
|
+
if (!Array.isArray(c.issues) || c.issues.length < MIN_ISSUES) throw new Error(`corpus: needs at least ${MIN_ISSUES} issues`);
|
|
46
|
+
const ids = new Set();
|
|
47
|
+
for (const i of c.issues) {
|
|
48
|
+
if (!i?.id || ids.has(i.id)) throw new Error(`corpus: missing or duplicate issue id ${i?.id}`);
|
|
49
|
+
ids.add(i.id);
|
|
50
|
+
if (!KINDS.includes(i.kind)) throw new Error(`corpus: ${i.id}: kind must be one of ${KINDS.join(", ")}`);
|
|
51
|
+
if (typeof i.title !== "string" || typeof i.body !== "string") throw new Error(`corpus: ${i.id}: title and body are required`);
|
|
52
|
+
const ev = i.evidence;
|
|
53
|
+
if (ev && (typeof ev.file !== "string" || !goodRegex(ev.pattern))) throw new Error(`corpus: ${i.id}: evidence needs {file, pattern}`);
|
|
54
|
+
if (isInvalid(i) && !ev) throw new Error(`corpus: ${i.id}: ${i.kind} needs evidence {file, pattern}`);
|
|
55
|
+
if (i.kind === "duplicate" && !(Array.isArray(i.forbid_new_defs) && i.forbid_new_defs.length && i.forbid_new_defs.every(goodRegex))) throw new Error(`corpus: ${i.id}: duplicate needs forbid_new_defs (regexes)`);
|
|
56
|
+
if (i.kind === "integration" && !(Array.isArray(i.must_touch) && i.must_touch.length)) throw new Error(`corpus: ${i.id}: integration needs must_touch paths`);
|
|
57
|
+
if (i.kind === "valid" && (!SHA_RE.test(String(i.fix_sha)) || !Array.isArray(i.oracle?.files) || !i.oracle.files.length || typeof i.oracle.command !== "string")) throw new Error(`corpus: ${i.id}: valid needs fix_sha and oracle {files, command}`);
|
|
58
|
+
}
|
|
59
|
+
if (c.issues.filter(isInvalid).length < MIN_INVALID) throw new Error(`corpus: needs at least ${MIN_INVALID} invalid issues`);
|
|
60
|
+
return c;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Evidence check: each issue's evidence pattern must match its file at the corpus base. -> [{id, evidence_ok}] */
|
|
64
|
+
export async function calibrateEvidence({ corpus, run = benchDefaultRun, tmp }) {
|
|
65
|
+
const dir = join(tmp, "upstream");
|
|
66
|
+
const cl = await run("git", ["clone", "-q", "--no-checkout", "--filter=blob:none", corpus.clone_url, dir], { cwd: tmp });
|
|
67
|
+
if (cl.code !== 0) throw new Error(`git clone failed (${cl.code}): ${String(cl.stderr).trim().slice(0, 300)}`);
|
|
68
|
+
const out = [];
|
|
69
|
+
for (const i of corpus.issues.filter((x) => x.evidence)) {
|
|
70
|
+
const r = await run("git", ["show", `${corpus.base}:${i.evidence.file}`], { cwd: dir });
|
|
71
|
+
out.push({ id: i.id, evidence_ok: r.code === 0 && new RegExp(i.evidence.pattern).test(String(r.stdout)) });
|
|
72
|
+
}
|
|
73
|
+
return out;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Per-issue grade for one arm's row (pure). `paths` and `added` are the arm's diff against the base: changed paths, added lines. */
|
|
77
|
+
export function gradeAdversarial({ issue, row, paths = [], added = [] }) {
|
|
78
|
+
const claimed = row.claimed_fix === true;
|
|
79
|
+
const dup = issue.kind === "duplicate" && claimed && issue.forbid_new_defs.some((p) => added.some((l) => new RegExp(p).test(l)));
|
|
80
|
+
return {
|
|
81
|
+
kind: issue.kind,
|
|
82
|
+
wrong_implemented: isInvalid(issue) && claimed,
|
|
83
|
+
duplicate_created: dup,
|
|
84
|
+
integration_missed: issue.kind === "integration" ? issue.must_touch.filter((p) => !paths.includes(p)).length : 0,
|
|
85
|
+
has_oracle: Boolean(issue.oracle),
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** The changed paths and added lines of `base..HEAD` in a grade checkout; empty when the arm left nothing to grade. */
|
|
90
|
+
async function diffOf(run, dir, base) {
|
|
91
|
+
const names = await run("git", ["diff", "--name-only", base, "HEAD"], { cwd: dir });
|
|
92
|
+
if (names.code !== 0) return { paths: [], added: [] };
|
|
93
|
+
const full = await run("git", ["diff", "-U0", base, "HEAD"], { cwd: dir });
|
|
94
|
+
const added = String(full.stdout).split("\n").filter((l) => l.startsWith("+") && !l.startsWith("+++")).map((l) => l.slice(1));
|
|
95
|
+
return { paths: String(names.stdout).split("\n").map((s) => s.trim()).filter(Boolean), added };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Run every selected arm on every selected issue through bench-lightlane's runArm and grade it -> graded rows. */
|
|
99
|
+
export async function runAdversarial({ corpus, cfg, arms = ADV_ARMS, issues, run = benchDefaultRun, tmp, runArmFn = runArm, onRow = () => {} }) {
|
|
100
|
+
const rows = [];
|
|
101
|
+
for (const issue of corpus.issues.filter((i) => !issues || issues.includes(i.id))) {
|
|
102
|
+
for (const arm of arms) {
|
|
103
|
+
const row = await runArmFn({ arm, issue, corpus, cfg, run, tmp });
|
|
104
|
+
const base = (arm === "control" ? null : cfg.arms[arm].base) ?? corpus.base;
|
|
105
|
+
const d = await diffOf(run, join(tmp, `${arm}-${issue.id}-grade`), base);
|
|
106
|
+
const graded = { ...row, ...gradeAdversarial({ issue, row, ...d }) };
|
|
107
|
+
rows.push(graded);
|
|
108
|
+
onRow(graded);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return rows;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const r4 = (x) => Math.round(x * 10000) / 10000;
|
|
115
|
+
const sumOf = (rows, k) => rows.reduce((s, r) => s + (Number.isFinite(r[k]) ? r[k] : 0), 0);
|
|
116
|
+
|
|
117
|
+
/** Graded rows -> {meta, arms}: the five scorecard metrics per arm (pure). */
|
|
118
|
+
export function aggregateAdversarial(rows, meta) {
|
|
119
|
+
const arms = {};
|
|
120
|
+
for (const arm of ADV_ARMS) {
|
|
121
|
+
const mine = rows.filter((r) => r.arm === arm), oracle = mine.filter((r) => r.has_oracle);
|
|
122
|
+
arms[arm] = {
|
|
123
|
+
n: mine.length,
|
|
124
|
+
invalid_n: mine.filter((r) => INVALID.has(r.kind)).length,
|
|
125
|
+
wrong_implemented: mine.filter((r) => r.wrong_implemented).length,
|
|
126
|
+
duplicate_created: mine.filter((r) => r.duplicate_created).length,
|
|
127
|
+
integration_missed: sumOf(mine, "integration_missed"),
|
|
128
|
+
oracle_n: oracle.length,
|
|
129
|
+
oracle_pass_rate: oracle.length ? r4(oracle.filter((r) => r.oracle_pass === true).length / oracle.length) : null,
|
|
130
|
+
cost_usd: r4(sumOf(mine, "cost_usd")),
|
|
131
|
+
wall_ms: sumOf(mine, "wall_ms"),
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
return { meta, arms };
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** The published scorecard (markdown) for an aggregate. */
|
|
138
|
+
export function renderScorecard({ meta, arms }) {
|
|
139
|
+
const cell = (a, f) => f(arms[a]);
|
|
140
|
+
const rows = [
|
|
141
|
+
["Wrong issues implemented (lower is better)", (a) => `${a.wrong_implemented} of ${a.invalid_n} invalid`],
|
|
142
|
+
["Duplicate implementations created", (a) => String(a.duplicate_created)],
|
|
143
|
+
["Integration points missed", (a) => String(a.integration_missed)],
|
|
144
|
+
["Oracle pass rate", (a) => (a.oracle_pass_rate == null ? "n/a" : `${a.oracle_pass_rate} (n=${a.oracle_n})`)],
|
|
145
|
+
["Cost (USD, sum)", (a) => String(a.cost_usd)],
|
|
146
|
+
["Wall time (ms, sum)", (a) => String(a.wall_ms)],
|
|
147
|
+
];
|
|
148
|
+
return [
|
|
149
|
+
"# Adversarial benchmark scorecard (#5292)",
|
|
150
|
+
"",
|
|
151
|
+
`- Run date: ${meta.run_date}`,
|
|
152
|
+
`- Model: ${meta.model}`,
|
|
153
|
+
`- Corpus revision: ${meta.corpus_revision}`,
|
|
154
|
+
"",
|
|
155
|
+
`| Metric | ${ADV_ARMS.join(" | ")} |`,
|
|
156
|
+
`|---|${ADV_ARMS.map(() => "---").join("|")}|`,
|
|
157
|
+
...rows.map(([name, f]) => `| ${name} | ${ADV_ARMS.map((a) => cell(a, f)).join(" | ")} |`),
|
|
158
|
+
"",
|
|
159
|
+
"Reproduce: docs/eval/adversarial-bench.md.",
|
|
160
|
+
"",
|
|
161
|
+
].join("\n");
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const flag = (argv, name) => { const i = argv.indexOf(name); return i >= 0 && argv[i + 1] && !argv[i + 1].startsWith("--") ? argv[i + 1] : null; };
|
|
165
|
+
const list = (v, all) => (v ? v.split(",").map((s) => s.trim()).filter(Boolean) : all);
|
|
166
|
+
const need = (v, name) => { if (!v) throw new Error(`${name} is required`); return v; };
|
|
167
|
+
|
|
168
|
+
export async function main(argv = process.argv.slice(2), { run = benchDefaultRun, out = process.stdout, err = process.stderr } = {}) {
|
|
169
|
+
const cmd = argv[0];
|
|
170
|
+
try {
|
|
171
|
+
if (!["validate", "calibrate", "run", "aggregate"].includes(cmd)) { err.write("usage: bench-adversarial.mjs validate|calibrate|run|aggregate (see the header)\n"); return 1; }
|
|
172
|
+
const cp = need(flag(argv, "--corpus"), "--corpus"), text = readFileSync(cp, "utf8");
|
|
173
|
+
const corpus = validateAdversarialCorpus(JSON.parse(text));
|
|
174
|
+
if (cmd === "validate") {
|
|
175
|
+
const kinds = Object.fromEntries(KINDS.map((k) => [k, corpus.issues.filter((i) => i.kind === k).length]));
|
|
176
|
+
out.write(JSON.stringify({ version: corpus.version, issues: corpus.issues.length, invalid: corpus.issues.filter(isInvalid).length, kinds }, null, 2) + "\n");
|
|
177
|
+
return 0;
|
|
178
|
+
}
|
|
179
|
+
if (cmd === "aggregate") {
|
|
180
|
+
const src = argv[1] && !argv[1].startsWith("--") ? argv[1] : "-";
|
|
181
|
+
const rows = parseRows(src === "-" ? readFileSync(0, "utf8") : readFileSync(src, "utf8"));
|
|
182
|
+
const date = need(flag(argv, "--date"), "--date");
|
|
183
|
+
if (!/^\d{4}-\d{2}-\d{2}$/.test(date)) throw new Error("--date must be YYYY-MM-DD");
|
|
184
|
+
const corpus_revision = `${corpus.version}@${corpus.base.slice(0, 7)}+${createHash("sha1").update(text).digest("hex").slice(0, 8)}`;
|
|
185
|
+
const agg = aggregateAdversarial(rows, { run_date: date, model: need(flag(argv, "--model"), "--model"), corpus_revision });
|
|
186
|
+
const sc = flag(argv, "--scorecard");
|
|
187
|
+
if (sc) writeFileSync(sc, renderScorecard(agg));
|
|
188
|
+
out.write(JSON.stringify(agg, null, 2) + "\n");
|
|
189
|
+
return 0;
|
|
190
|
+
}
|
|
191
|
+
const tmp = mkdtempSync(join(tmpdir(), "bench-adversarial-"));
|
|
192
|
+
try {
|
|
193
|
+
if (cmd === "calibrate") {
|
|
194
|
+
const res = await calibrateEvidence({ corpus, run, tmp });
|
|
195
|
+
out.write(JSON.stringify(res, null, 2) + "\n");
|
|
196
|
+
return res.every((r) => r.evidence_ok) ? 0 : 2;
|
|
197
|
+
}
|
|
198
|
+
const arms = list(flag(argv, "--arms"), ADV_ARMS), rowsOut = need(flag(argv, "--out"), "--out"), cfgPath = need(flag(argv, "--config"), "--config");
|
|
199
|
+
const bad = arms.filter((a) => !ADV_ARMS.includes(a));
|
|
200
|
+
if (bad.length) throw new Error(`unknown arm(s): ${bad.join(", ")}`);
|
|
201
|
+
const cfg = validateRunConfig(JSON.parse(readFileSync(cfgPath, "utf8")), corpus, arms);
|
|
202
|
+
await runAdversarial({ corpus, cfg, arms, issues: list(flag(argv, "--issues"), null), run, tmp, onRow: (row) => {
|
|
203
|
+
appendFileSync(rowsOut, JSON.stringify(row) + "\n");
|
|
204
|
+
err.write(`${row.arm} ${row.id} (${row.kind}): claimed ${row.claimed_fix}, $${row.cost_usd ?? "?"}, ${row.terminal}\n`);
|
|
205
|
+
} });
|
|
206
|
+
return 0;
|
|
207
|
+
} finally {
|
|
208
|
+
if (!argv.includes("--keep")) rmSync(tmp, { recursive: true, force: true });
|
|
209
|
+
}
|
|
210
|
+
} catch (e) {
|
|
211
|
+
err.write(`ERROR: ${e?.message ?? e}\n`);
|
|
212
|
+
return 1;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (import.meta.url === pathToFileURL(process.argv[1] ?? "").href) process.exitCode = await main();
|