@womp/spark-agent 17.7.2 → 17.8.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.
@@ -0,0 +1,293 @@
1
+ import { KakapoAPI } from "@womp/kakapo-sdk";
2
+ import { type BenchBounds } from "./bench-camera.js";
3
+ import type { SparkRunSettings } from "./server/types.js";
4
+ export declare const QUALITY_CASES_DIR: string;
5
+ /** Standardized multi-view turntable rendered around the matched front side (used by --ab pairwise judging on any object). */
6
+ export declare const TURNTABLE_VIEWS: QualityView[];
7
+ /** A close-up framed on part of the build, from the side it faces turned by `turn` degrees about +Y. */
8
+ export interface QualityView {
9
+ name: string;
10
+ /** What the close-up shows, for the judge (e.g. "shoulders, three-quarter view"); defaults to `name`. */
11
+ label?: string;
12
+ /** Frame the parts in this band of the build's height (0 = lowest point, 1 = highest)... */
13
+ band?: [number, number];
14
+ /** ...or the parts whose name matches this pattern (case-insensitive), minus `exclude`. */
15
+ match?: string;
16
+ exclude?: string;
17
+ /** With `match`: keep the parts on one side of the build (a = its right, b = its left), e.g. one hand. */
18
+ half?: "a" | "b";
19
+ turn: number;
20
+ /** Camera height: up component of the view direction. */
21
+ tilt?: number;
22
+ }
23
+ /**
24
+ * A judged check: close-ups of the build, and the parts the judge compares with the reference picture. Each item maps
25
+ * a part key to the part's name as the judge should find it, e.g. "left shoulder (where the left-hand sleeve meets
26
+ * the jacket)". The judge rates each part 0-3 (matches / minor detail / visible join or wrong shape / wrong); the
27
+ * check's score is the share of parts that pass.
28
+ */
29
+ export interface QualityCheck {
30
+ id: string;
31
+ views: QualityView[];
32
+ items: Record<string, string>;
33
+ }
34
+ export interface QualityCase {
35
+ id: string;
36
+ /** Optional benchmark split ("tune" for prompt iteration, "holdout" for regression gating). */
37
+ split?: "tune" | "holdout";
38
+ prompt: string;
39
+ /** Attached to the prompt, relative to the case directory. */
40
+ images: string[];
41
+ /** Picture the judges compare against (usually the front view), relative to the case directory. */
42
+ reference: string;
43
+ /** Parts the likeness judge scores 0-10, front render against the reference. */
44
+ likeness: string[];
45
+ checks: QualityCheck[];
46
+ }
47
+ export interface QualityBenchOptions {
48
+ cases: string[];
49
+ repeat: number;
50
+ parallel: number;
51
+ kakapoUrl: string;
52
+ settings: SparkRunSettings;
53
+ output: string;
54
+ /** Run AI vision judges (likeness + close-up checks); defaults to false for fast visual sheet comparison. */
55
+ judge?: boolean;
56
+ timeoutMs: number;
57
+ signal: AbortSignal;
58
+ log?: (line: string) => void;
59
+ }
60
+ export declare function loadQualityCaseSpec(id: string): Promise<QualityCase & {
61
+ dir: string;
62
+ }>;
63
+ export declare function loadQualityCase(id: string): Promise<QualityCase & {
64
+ dir: string;
65
+ }>;
66
+ export declare function listQualityCases(): Promise<string[]>;
67
+ /**
68
+ * A new Womp project's scene properties: swan-frontend src/utils/scene/data.tsx `defaultSceneProperty`, lit by the
69
+ * leadenhall_market environment. Builds start from these so they are lit as in the editor. Kakapo's own default
70
+ * environment, `sunset_small` (code/Modeller/Scene.h), is in no data tree, so a scene taken from a freshly started
71
+ * engine has no environment light and renders nearly black.
72
+ */
73
+ export declare const WOMP_SCENE_PROPERTIES: {
74
+ readonly backdrop_color1: {
75
+ readonly x: 1;
76
+ readonly y: 1;
77
+ readonly z: 1;
78
+ };
79
+ readonly backdrop_color2: {
80
+ readonly x: 1;
81
+ readonly y: 1;
82
+ readonly z: 1;
83
+ };
84
+ readonly backdrop_grad_offset: {
85
+ readonly x: 1;
86
+ readonly y: 1;
87
+ };
88
+ readonly backdrop_multiplier: 0.8489999771118164;
89
+ readonly backdrop_name: "dfsd_gaby";
90
+ readonly flags: 0;
91
+ readonly floor_blend_begin: 0;
92
+ readonly floor_blend_end: 1;
93
+ readonly floor_blending_factor: 0.5870000123977661;
94
+ readonly hdr_multiplier: 1.2999999523162842;
95
+ readonly hdr_name: "leadenhall_market";
96
+ readonly hdr_orientation: {
97
+ readonly x: 0;
98
+ readonly y: 0;
99
+ };
100
+ readonly render_flags: 59;
101
+ readonly dynamic_resolution: 1;
102
+ readonly outline: {
103
+ readonly x: 0;
104
+ readonly y: 0;
105
+ readonly z: 0;
106
+ readonly w: 2;
107
+ };
108
+ readonly outline_mode: 0;
109
+ readonly cel_shading_levels: 0;
110
+ readonly exposure: 1;
111
+ readonly tonemapper: 0;
112
+ readonly use_image_background: false;
113
+ };
114
+ /**
115
+ * A saved scene with its environment made renderable: one still on Kakapo's missing default environment (builds made
116
+ * before the bench seeded WOMP_SCENE_PROPERTIES) gets the Womp default environment; any other scene is unchanged.
117
+ */
118
+ export declare function withWompEnvironment(scene: any): any;
119
+ /**
120
+ * Ensures Kakapo has a valid minimal scene (with `nodes["0"]`) before connecting `KakapoAPI` (prevents
121
+ * `Cannot convert undefined or null to object` when Kakapo is open with no project loaded).
122
+ * When `reset` is true, always replaces the engine scene with a clean empty root scene with a new Womp project's
123
+ * properties, so `KakapoMux` templates inherit neither stale scenes nor the engine's unlit default environment.
124
+ */
125
+ export declare function ensureKakapoScene(url: string, reset?: boolean): Promise<void>;
126
+ /** Runs every case `repeat` times, `parallel` builds at once, and writes report.json and report.md to `output`. */
127
+ export declare function runQualityBench(options: QualityBenchOptions): Promise<QualityReport>;
128
+ export interface QualityTimings {
129
+ buildMs: number;
130
+ renderMs: number;
131
+ judgeMs: number;
132
+ }
133
+ export interface QualityRunResult {
134
+ case: string;
135
+ run: number;
136
+ status: string;
137
+ error?: string;
138
+ costUsd: number | null;
139
+ durationMs: number;
140
+ timings?: QualityTimings;
141
+ steps: number;
142
+ likeness?: Judged & {
143
+ side: string;
144
+ };
145
+ /** The side render the judge named as the build's front (`DEFAULT_FRONT` without a judge); turntable views turn from it. */
146
+ front?: string;
147
+ checks: Record<string, Judged>;
148
+ structure?: SceneStructure;
149
+ }
150
+ interface Judged {
151
+ scores: Record<string, number>;
152
+ mean: number;
153
+ notes?: unknown;
154
+ }
155
+ /** Spark's public +Z is forward and maps to renderer -X, so a build that follows the convention faces the `nx` side. */
156
+ export declare const DEFAULT_FRONT = "nx";
157
+ /** Fixed Spark-space perspective shots (`benchCamera`), fitted to Kakapo's native world bounding box. */
158
+ export declare function renderFixedCameras(api: KakapoAPI, dir: string): Promise<string[]>;
159
+ /** The part of `box` inside `to`, or undefined when they do not overlap. */
160
+ export declare function clipBox(box: BenchBounds, to: BenchBounds): BenchBounds | undefined;
161
+ /** The side a front answer names; "none", an unknown label or a malformed answer keeps Spark's convention. */
162
+ export declare function frontFromAnswer(answer: unknown, keys: string[]): string;
163
+ export interface PairwiseResult {
164
+ winner: "A" | "B" | "tie";
165
+ consistent: boolean;
166
+ reason: string;
167
+ aFlaws: string;
168
+ bFlaws: string;
169
+ }
170
+ /** Resolves order-swapped forward (A, B) and reverse (B, A) pairwise judgements; disagreement becomes a tie. */
171
+ export declare function resolvePairwiseSwap(forward: {
172
+ winner: "A" | "B" | "tie";
173
+ reason?: string;
174
+ a_flaws?: string;
175
+ b_flaws?: string;
176
+ }, reverse: {
177
+ winner: "A" | "B" | "tie";
178
+ reason?: string;
179
+ a_flaws?: string;
180
+ b_flaws?: string;
181
+ }): PairwiseResult;
182
+ /**
183
+ * Blinded order-swapped pairwise judge (Gemini 4 Neon, low thinking): runs (A, B) and (B, A) in parallel so position
184
+ * bias cancels out into a tie. Works on any reference image or focused close-up view set.
185
+ */
186
+ export declare function judgePairwise(referenceFile: string, shotsA: {
187
+ name: string;
188
+ label?: string;
189
+ file?: string;
190
+ }[], shotsB: {
191
+ name: string;
192
+ label?: string;
193
+ file?: string;
194
+ }[], focus?: string): Promise<PairwiseResult>;
195
+ /**
196
+ * Stitches 4 turntable renders (front, quarter-l, back, top) into a single labeled 1280x720 2x2 contact sheet JPEG so
197
+ * pairwise VLM calls see only 3 images total (Reference, Build A grid, Build B grid) without image-overload bias.
198
+ */
199
+ export declare function buildContactSheet(shots: {
200
+ name: string;
201
+ file?: string;
202
+ }[], outFile: string): Promise<string | null>;
203
+ export interface PairwiseComparisonReport {
204
+ baselineDir: string;
205
+ candidateDir: string;
206
+ focus?: string;
207
+ finishedAt: string;
208
+ judge: string;
209
+ overall: {
210
+ pairs: number;
211
+ candidateWins: number;
212
+ baselineWins: number;
213
+ ties: number;
214
+ consistent: number;
215
+ };
216
+ cases: Record<string, {
217
+ pairs: number;
218
+ candidateWins: number;
219
+ baselineWins: number;
220
+ ties: number;
221
+ consistent: number;
222
+ skipped?: string[];
223
+ runs: (PairwiseResult & {
224
+ pair: string;
225
+ baselineRun: string;
226
+ candidateRun: string;
227
+ })[];
228
+ }>;
229
+ }
230
+ /** Blinded order-swapped all-vs-all pairwise comparison of two completed quality-bench output directories (A = baseline, B = candidate). */
231
+ export declare function compareQualityRuns(baselineDir: string, candidateDir: string, options?: {
232
+ focus?: string;
233
+ viewFilter?: string;
234
+ allPairs?: boolean;
235
+ }): Promise<PairwiseComparisonReport>;
236
+ export declare function pairwiseReportMarkdown(report: PairwiseComparisonReport): string;
237
+ /**
238
+ * Recovers and scores an existing bench output directory from its saved `scene.json` files (e.g. after a Kakapo crash),
239
+ * rendering any missing views/grids and reusing existing judge JSONs so completed Spark builds are never wasted.
240
+ */
241
+ export declare function scoreExistingBenchRun(outputDir: string, options: {
242
+ kakapoUrl: string;
243
+ baseline?: QualityReport;
244
+ log?: (line: string) => void;
245
+ }): Promise<QualityReport>;
246
+ export interface SceneStructure {
247
+ /** Top-level Areas (outermost Area in each visible branch). */
248
+ areas: number;
249
+ curves: number;
250
+ points: number;
251
+ primitives: number;
252
+ /** Cube primitives that add material (informational: expected on CAD, unusual on organic builds). */
253
+ cubes: number;
254
+ /** Pairs of top-level Areas holding overlapping parts of the same material: Areas never blend, so these show seams. */
255
+ seams: number;
256
+ /** Largest estimated ridge depth (x1000 scene units) across visible V3 Bezier curves; higher means visible ribbing. */
257
+ ribbingDepth: number;
258
+ /** Count of visible V3 Bezier curves with noticeable spacing ribbing (ratio > 1.5 and depth > 0.002). */
259
+ ribbedCurves: number;
260
+ /** Disconnected additive geometry clusters (1 = single connected solid; >1 = detached/floating pieces). */
261
+ floatingClusters: number;
262
+ }
263
+ /** Estimates spacing ribbing on a V3 Bezier curve (mirrors Kakapo CurveBezier.cpp spacing logic). */
264
+ export declare function curveRibbing(node: any, scale?: number): {
265
+ ratio: number;
266
+ depth: number;
267
+ prims: number;
268
+ density: number;
269
+ } | null;
270
+ export declare function sceneStructure(scene: any): SceneStructure;
271
+ export interface QualityReport {
272
+ version: 1;
273
+ finishedAt: string;
274
+ settings: SparkRunSettings;
275
+ judge: string;
276
+ repeat: number;
277
+ cases: Record<string, {
278
+ runs: number;
279
+ failed: number;
280
+ metrics: Record<string, {
281
+ mean: number;
282
+ sd: number;
283
+ n: number;
284
+ }>;
285
+ costUsd: number;
286
+ durationS: number;
287
+ }>;
288
+ }
289
+ /** Generates or regenerates per-repeat `sheet-run-<n>.png` files for an existing bench output directory without running builds. */
290
+ export declare function generateBenchSheet(outputDir: string): Promise<string[]>;
291
+ /** Markdown table per case; with a baseline report, each metric's change and whether it is beyond noise. */
292
+ export declare function reportMarkdown(report: QualityReport, baseline?: QualityReport): string;
293
+ export {};