@ikijs/mcp 0.29.0 → 0.31.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/dist/cli.js CHANGED
@@ -32,8 +32,8 @@ var import_mcp = require("@modelcontextprotocol/sdk/server/mcp.js");
32
32
  var import_zod = require("zod");
33
33
 
34
34
  // src/tools.ts
35
- var import_node_fs4 = require("fs");
36
- var import_node_path4 = __toESM(require("path"));
35
+ var import_node_fs5 = require("fs");
36
+ var import_node_path5 = __toESM(require("path"));
37
37
  var import_format9 = require("@ikijs/format");
38
38
  var import_editor3 = require("@ikijs/editor");
39
39
 
@@ -993,6 +993,7 @@ var HEAD_AND_GAZE = /* @__PURE__ */ new Set([
993
993
  var import_format6 = require("@ikijs/format");
994
994
 
995
995
  // ../engine/src/land.ts
996
+ var UNIT_QUAD = [-0.5, -0.5, 0.5, -0.5, -0.5, 0.5, 0.5, 0.5];
996
997
  function staticDeformers(model) {
997
998
  return (model.deformers ?? []).map(
998
999
  (d) => d.kind === "warp" ? { ...d, warps: void 0, warp2d: void 0 } : { ...d, bindings: void 0 }
@@ -1045,6 +1046,28 @@ function landPart(landing, store, { worlds, grids }) {
1045
1046
  }
1046
1047
  return landed;
1047
1048
  }
1049
+ function landParts(model, values, partIds) {
1050
+ const deformers = model.deformers ?? [];
1051
+ const restStore = new ParameterStore(model.parameters);
1052
+ const store = new ParameterStore(model.parameters);
1053
+ for (const [id, value] of Object.entries(values)) store.set(id, value);
1054
+ const { worlds } = resolveDeformers(staticDeformers(model), restStore);
1055
+ const resolved = resolveDeformers(deformers, store);
1056
+ const out = /* @__PURE__ */ new Map();
1057
+ for (const id of partIds) {
1058
+ const part = model.parts.find((p) => p.id === id);
1059
+ if (!part) continue;
1060
+ const landing = landedPart(
1061
+ part,
1062
+ part.mesh?.vertices ?? UNIT_QUAD,
1063
+ deformers,
1064
+ worlds,
1065
+ restStore
1066
+ );
1067
+ out.set(id, Float32Array.from(landPart(landing, store, resolved)));
1068
+ }
1069
+ return out;
1070
+ }
1048
1071
 
1049
1072
  // ../engine/src/folds.ts
1050
1073
  var FLIP = 0;
@@ -1446,7 +1469,6 @@ function stopsOf(model, parameter) {
1446
1469
  var DISPLACEMENT_PX = 1;
1447
1470
  var PINNED_FRAMES = 60;
1448
1471
  var TOLERANCE = 1e-9;
1449
- var UNIT_QUAD = [-0.5, -0.5, 0.5, -0.5, -0.5, 0.5, 0.5, 0.5];
1450
1472
  function checkPhysics(model) {
1451
1473
  const idle = idleRun(model);
1452
1474
  const displace = displacer(model);
@@ -1733,8 +1755,8 @@ function ratioText(ratio) {
1733
1755
  }
1734
1756
 
1735
1757
  // src/render-poses.ts
1736
- var import_node_fs3 = require("fs");
1737
- var import_node_path3 = __toESM(require("path"));
1758
+ var import_node_fs4 = require("fs");
1759
+ var import_node_path4 = __toESM(require("path"));
1738
1760
  var import_format8 = require("@ikijs/format");
1739
1761
 
1740
1762
  // src/limits.ts
@@ -2160,16 +2182,351 @@ async function withBrowser(executable, fn) {
2160
2182
  }
2161
2183
  }
2162
2184
 
2185
+ // src/sweep-report.ts
2186
+ var LADDER_MIN = -30;
2187
+ var LADDER_MAX = 30;
2188
+ var ZERO = -LADDER_MIN;
2189
+ var FLAT_SLOPE = 1e-4;
2190
+ var PARTS = ["face", "eye_L", "eye_R", "nose"];
2191
+ function box(pts, fw) {
2192
+ let x0 = Infinity;
2193
+ let x1 = -Infinity;
2194
+ let y0 = Infinity;
2195
+ let y1 = -Infinity;
2196
+ for (let i = 0; i < pts.length; i += 2) {
2197
+ x0 = Math.min(x0, pts[i]);
2198
+ x1 = Math.max(x1, pts[i]);
2199
+ y0 = Math.min(y0, pts[i + 1]);
2200
+ y1 = Math.max(y1, pts[i + 1]);
2201
+ }
2202
+ return {
2203
+ x: (x0 + x1) / 2 / fw,
2204
+ width: (x1 - x0) / fw,
2205
+ y: (y0 + y1) / 2 / fw
2206
+ };
2207
+ }
2208
+ function nearestVertex(face, fw, x, y) {
2209
+ let best = 0;
2210
+ let bestD = Infinity;
2211
+ for (let i = 0; i < face.length; i += 2) {
2212
+ const d = (face[i] / fw - x) ** 2 + (face[i + 1] / fw - y) ** 2;
2213
+ if (d < bestD) {
2214
+ bestD = d;
2215
+ best = i / 2;
2216
+ }
2217
+ }
2218
+ return best;
2219
+ }
2220
+ function kink(v) {
2221
+ const sMinus = (v[ZERO] - v[ZERO - 5]) / 5;
2222
+ const sPlus = (v[ZERO + 5] - v[ZERO]) / 5;
2223
+ const big = Math.max(Math.abs(sMinus), Math.abs(sPlus));
2224
+ if (big < FLAT_SLOPE) return null;
2225
+ return Math.abs(sPlus - sMinus) / big;
2226
+ }
2227
+ function pop(v) {
2228
+ let steps = 0;
2229
+ for (let i = 0; i + 1 < v.length; i++) steps += Math.abs(v[i + 1] - v[i]);
2230
+ const mean = steps / (v.length - 1);
2231
+ if (mean < 1e-9) return null;
2232
+ let most = 0;
2233
+ for (let i = 1; i + 1 < v.length; i++) {
2234
+ if (Math.abs(i - ZERO) <= 1) continue;
2235
+ most = Math.max(most, Math.abs(v[i + 1] - 2 * v[i] + v[i - 1]));
2236
+ }
2237
+ return most / mean;
2238
+ }
2239
+ function checkSweep(model) {
2240
+ const face = model.parts.find((p) => p.id === "face");
2241
+ if (!face) return { preset: "turn", unavailable: "no face part" };
2242
+ const hasEyes = ["eye_L", "eye_R"].every(
2243
+ (id) => model.parts.some((p) => p.id === id)
2244
+ );
2245
+ if (!hasEyes) {
2246
+ return { preset: "turn", unavailable: "no eye_L and eye_R parts" };
2247
+ }
2248
+ const fw = face.width;
2249
+ const ladder = Array.from(
2250
+ { length: LADDER_MAX - LADDER_MIN + 1 },
2251
+ (_, i) => landParts(model, { ParamAngleX: LADDER_MIN + i }, PARTS)
2252
+ );
2253
+ const at = (id, i) => ladder[i].get(id);
2254
+ const ids = ["eye_L", "eye_R", ...ladder[0].has("nose") ? ["nose"] : []];
2255
+ const landmarks = ids.map((id) => {
2256
+ const boxes = ladder.map((_, i) => box(at(id, i), fw));
2257
+ const xs = boxes.map((b) => b.x);
2258
+ const plateIndex2 = nearestVertex(
2259
+ at("face", ZERO),
2260
+ fw,
2261
+ boxes[ZERO].x,
2262
+ boxes[ZERO].y
2263
+ );
2264
+ const plate = ladder.map((_, i) => at("face", i)[plateIndex2 * 2] / fw);
2265
+ const lead = (i) => xs[i] - plate[i] - (xs[ZERO] - plate[ZERO]);
2266
+ return {
2267
+ id,
2268
+ amplitude: xs[xs.length - 1] - xs[0],
2269
+ xKink: kink(xs),
2270
+ widthKink: id === "nose" ? null : kink(boxes.map((b) => b.width)),
2271
+ lead: { m30: lead(0), p30: lead(xs.length - 1) },
2272
+ pop: pop(xs)
2273
+ };
2274
+ });
2275
+ const eyes = ["eye_L", "eye_R"].map((id) => box(at(id, ZERO), fw));
2276
+ const plateIndex = nearestVertex(
2277
+ at("face", ZERO),
2278
+ fw,
2279
+ (eyes[0].x + eyes[1].x) / 2,
2280
+ (eyes[0].y + eyes[1].y) / 2
2281
+ );
2282
+ const plateX = (i) => at("face", i)[plateIndex * 2] / fw;
2283
+ return {
2284
+ preset: "turn",
2285
+ unit: "fw",
2286
+ faceWidth: fw,
2287
+ plateAmplitude: plateX(ladder.length - 1) - plateX(0),
2288
+ landmarks
2289
+ };
2290
+ }
2291
+ var fw3 = (v) => {
2292
+ const s = v.toFixed(3);
2293
+ return s === "-0.000" ? "0.000" : s;
2294
+ };
2295
+ var signed = (v) => fw3(v).startsWith("-") ? fw3(v) : `+${fw3(v)}`;
2296
+ var two = (v) => v === null ? "n/a" : v.toFixed(2);
2297
+ function formatSweepReport(report) {
2298
+ if ("unavailable" in report) {
2299
+ return [`SWEEP: unavailable \u2014 ${report.unavailable}`];
2300
+ }
2301
+ return [
2302
+ ...report.landmarks.map(
2303
+ (l) => `SWEEP turn ${l.id}: amplitude ${fw3(l.amplitude)} fw, x kink ${two(l.xKink)}, width kink ${two(l.widthKink)}, lead -30 ${signed(l.lead.m30)} fw / +30 ${signed(l.lead.p30)} fw, pop ${two(l.pop)}`
2304
+ ),
2305
+ `SWEEP turn plate: amplitude ${fw3(report.plateAmplitude)} fw`
2306
+ ];
2307
+ }
2308
+
2309
+ // src/sweep.ts
2310
+ var import_node_fs3 = __toESM(require("fs"));
2311
+ var import_node_path3 = __toESM(require("path"));
2312
+ var SWEEP_CLOCK_HZ = 60;
2313
+ var SWEEP_FPS = 30;
2314
+ var SWEEP_DURATION_S = 3;
2315
+ var SWEEP_WARMUP_S = 0.5;
2316
+ var SWEEP_FRAME_MS = 1e3 / SWEEP_CLOCK_HZ * (1 + 1e-9);
2317
+ var SHEET_THETAS = [-30, -20, -10, -5, 0, 5, 10, 20, 30];
2318
+ var SHEET_MAX_SIDE = 2e3;
2319
+ var SHEET_MARGIN = 8;
2320
+ var SHEET_LABEL_BAND = 24;
2321
+ var KYMOGRAPH_BAND = 3;
2322
+ var SWEEP_PARAMETER = "ParamAngleX";
2323
+ var STEPS = SWEEP_CLOCK_HZ * SWEEP_DURATION_S;
2324
+ var CAPTURE_EVERY = SWEEP_CLOCK_HZ / SWEEP_FPS;
2325
+ var FRAMES = STEPS / CAPTURE_EVERY;
2326
+ var LEG_FROM_S = 0.75;
2327
+ var LEG_TO_S = 2.25;
2328
+ var AMPLITUDE_DEG = 30;
2329
+ function turnTheta(t) {
2330
+ return -AMPLITUDE_DEG * Math.sin(2 * Math.PI * t / SWEEP_DURATION_S);
2331
+ }
2332
+ function eyeRowModelPx(model) {
2333
+ const landed = landParts(model, {}, ["eye_L", "eye_R"]);
2334
+ const l = landed.get("eye_L");
2335
+ const r = landed.get("eye_R");
2336
+ if (!l || !r) return void 0;
2337
+ const centreY = (pts) => {
2338
+ let lo = Infinity;
2339
+ let hi = -Infinity;
2340
+ for (let i = 1; i < pts.length; i += 2) {
2341
+ lo = Math.min(lo, pts[i]);
2342
+ hi = Math.max(hi, pts[i]);
2343
+ }
2344
+ return (lo + hi) / 2;
2345
+ };
2346
+ return model.canvas.height / 2 - (centreY(l) + centreY(r)) / 2;
2347
+ }
2348
+ function physicsOutputIds(model) {
2349
+ const ids = /* @__PURE__ */ new Set();
2350
+ for (const rig of model.physics ?? []) ids.add(rig.output.parameter);
2351
+ for (const chain of model.physicsChains ?? []) {
2352
+ for (const seg of chain.segments) ids.add(seg.output.parameter);
2353
+ }
2354
+ return [...ids];
2355
+ }
2356
+ function sheetFrames(thetas) {
2357
+ const onLeg = [];
2358
+ for (let k = 0; k < FRAMES; k++) {
2359
+ const t = k / SWEEP_FPS;
2360
+ if (t >= LEG_FROM_S && t <= LEG_TO_S) onLeg.push(k);
2361
+ }
2362
+ const picked = [];
2363
+ for (const target2 of SHEET_THETAS) {
2364
+ let best = onLeg[0];
2365
+ for (const k of onLeg) {
2366
+ if (Math.abs(thetas[CAPTURE_EVERY * k] - target2) < Math.abs(thetas[CAPTURE_EVERY * best] - target2)) {
2367
+ best = k;
2368
+ }
2369
+ }
2370
+ if (!picked.includes(best)) picked.push(best);
2371
+ }
2372
+ return picked.sort((a, b) => a - b);
2373
+ }
2374
+ function sheetLabel(theta, t) {
2375
+ const rounded = Math.round(theta * 10) / 10 + 0;
2376
+ const deg = rounded.toFixed(1);
2377
+ const signed2 = rounded > 0 ? `+${deg}` : deg.replace("-", "\u2212");
2378
+ return `\u03B8 ${signed2}\xB0 t ${t.toFixed(2)} s`;
2379
+ }
2380
+ function sweepSpec(model, crop) {
2381
+ const thetas = Array.from(
2382
+ { length: STEPS },
2383
+ (_, j) => turnTheta(j / SWEEP_CLOCK_HZ)
2384
+ );
2385
+ const dw = crop ? crop.dw : BUST_SIZE;
2386
+ const dh = crop ? crop.dh : BUST_SIZE;
2387
+ const m = SHEET_MARGIN;
2388
+ const b = SHEET_LABEL_BAND;
2389
+ const scale2 = Math.min(
2390
+ 1,
2391
+ (SHEET_MAX_SIDE - 2 * m) / (3 * dw),
2392
+ (SHEET_MAX_SIDE - 2 * m - 3 * b) / (3 * dh)
2393
+ );
2394
+ const frames = sheetFrames(thetas);
2395
+ const { width: W, height: H } = model.canvas;
2396
+ const yModel = eyeRowModelPx(model);
2397
+ let row = Math.round(dh / 2);
2398
+ let at = "middle";
2399
+ if (yModel !== void 0) {
2400
+ const y0 = bustPadY(W, H);
2401
+ const s = BUST_SIZE / W;
2402
+ const eyeRow = Math.round(
2403
+ crop ? (y0 + yModel * s - crop.sy) * crop.dh / crop.sh : y0 + yModel * s
2404
+ );
2405
+ if (eyeRow >= 1 && eyeRow <= dh - 2) {
2406
+ row = eyeRow;
2407
+ at = "eye row";
2408
+ }
2409
+ }
2410
+ return {
2411
+ parameter: SWEEP_PARAMETER,
2412
+ frameMs: SWEEP_FRAME_MS,
2413
+ warmup: SWEEP_WARMUP_S * SWEEP_CLOCK_HZ,
2414
+ thetas,
2415
+ captureEvery: CAPTURE_EVERY,
2416
+ frames: FRAMES,
2417
+ frame: { width: dw, height: dh },
2418
+ physicsOutputs: physicsOutputIds(model),
2419
+ sheet: {
2420
+ frames,
2421
+ cell: {
2422
+ w: Math.max(1, Math.floor(dw * scale2)),
2423
+ h: Math.max(1, Math.floor(dh * scale2))
2424
+ },
2425
+ margin: m,
2426
+ labelBand: b,
2427
+ labels: frames.map(
2428
+ (k) => sheetLabel(thetas[CAPTURE_EVERY * k], k / SWEEP_FPS)
2429
+ )
2430
+ },
2431
+ kymograph: { row, band: KYMOGRAPH_BAND, at },
2432
+ crop
2433
+ };
2434
+ }
2435
+ function flipbookHtml(manifest) {
2436
+ const json = JSON.stringify(manifest).replace(/</g, "\\u003c");
2437
+ return `<!doctype html>
2438
+ <html lang="en">
2439
+ <head>
2440
+ <meta charset="utf-8">
2441
+ <title>turn sweep</title>
2442
+ <style>
2443
+ body { font: 14px system-ui, sans-serif; margin: 16px; background: #222; color: #eee; }
2444
+ .row { display: flex; gap: 16px; align-items: flex-start; }
2445
+ img { max-width: 48vw; height: auto; background: #444; }
2446
+ #b { display: none; }
2447
+ #controls { margin: 12px 0; display: flex; gap: 12px; align-items: center; }
2448
+ #scrub { flex: 1; max-width: 640px; }
2449
+ </style>
2450
+ </head>
2451
+ <body>
2452
+ <div class="row"><img id="a" alt="A"><img id="b" alt="B"></div>
2453
+ <div id="controls">
2454
+ <button id="play" type="button">pause</button>
2455
+ <input id="scrub" type="range" min="0" value="0" step="1">
2456
+ <span id="readout"></span>
2457
+ </div>
2458
+ <p>Add <code>?b=&lt;relative dir&gt;</code> to the address to show another sweep beside this one; it must be a sweep of the same preset, since frames are matched by file name.</p>
2459
+ <script id="manifest" type="application/json">${json}</script>
2460
+ <script>
2461
+ (function () {
2462
+ var m = JSON.parse(document.getElementById("manifest").textContent);
2463
+ var b = new URLSearchParams(location.search).get("b");
2464
+ var a = document.getElementById("a");
2465
+ var bi = document.getElementById("b");
2466
+ var scrub = document.getElementById("scrub");
2467
+ var readout = document.getElementById("readout");
2468
+ var play = document.getElementById("play");
2469
+ var n = m.frames.length;
2470
+ var i = 0;
2471
+ var playing = true;
2472
+ scrub.max = String(n - 1);
2473
+ if (b) { bi.style.display = "block"; }
2474
+ function show(k) {
2475
+ i = k;
2476
+ var f = m.frames[k];
2477
+ a.src = f.file;
2478
+ if (b) { bi.src = b.replace(/\\/$/, "") + "/" + f.file; }
2479
+ scrub.value = String(k);
2480
+ readout.textContent = "frame " + k + " \\u03b8 " + f.theta.toFixed(1) + "\\u00b0 t " + f.t.toFixed(2) + " s";
2481
+ }
2482
+ play.addEventListener("click", function () {
2483
+ playing = !playing;
2484
+ play.textContent = playing ? "pause" : "play";
2485
+ });
2486
+ scrub.addEventListener("input", function () {
2487
+ playing = false;
2488
+ play.textContent = "play";
2489
+ show(Number(scrub.value));
2490
+ });
2491
+ setInterval(function () { if (playing) { show((i + 1) % n); } }, 1000 / m.fps);
2492
+ show(0);
2493
+ })();
2494
+ </script>
2495
+ </body>
2496
+ </html>
2497
+ `;
2498
+ }
2499
+ function prepareSweepDir(outDir, name) {
2500
+ const dir = import_node_path3.default.join(outDir, name);
2501
+ try {
2502
+ import_node_fs3.default.mkdirSync(dir);
2503
+ } catch (e) {
2504
+ if (e.code !== "EEXIST") {
2505
+ throw new AutoRigInputError(`sweep dir: ${e.message}`);
2506
+ }
2507
+ }
2508
+ const stat = import_node_fs3.default.lstatSync(dir);
2509
+ if (stat.isSymbolicLink()) {
2510
+ throw new AutoRigInputError(`sweep.name names ${dir}, a symbolic link`);
2511
+ }
2512
+ if (!stat.isDirectory()) {
2513
+ throw new AutoRigInputError(`sweep.name names ${dir}, not a directory`);
2514
+ }
2515
+ const real = confineToWorkingDirectory(process.cwd(), dir, "sweep dir", name);
2516
+ return real;
2517
+ }
2518
+
2163
2519
  // src/render-poses.ts
2164
2520
  var FULL_BODY_VIEW_WIDTH = 2.5;
2165
2521
  var BUST_SIZE = 560;
2166
2522
  var CROP_WIDTH = 720;
2167
2523
  var CROP_MAX_HEIGHT = 8192;
2168
2524
  var POSE_NAME = /^[A-Za-z0-9_.-]+$/;
2525
+ var SWEEP_NAME = /^[A-Za-z0-9][A-Za-z0-9_.-]*$/;
2169
2526
  function bustPadY(width, height) {
2170
2527
  return Math.max(0, (BUST_SIZE - BUST_SIZE * height / width) / 2);
2171
2528
  }
2172
- function planRenders(model, requested) {
2529
+ function planRenders(model, requested, sweep) {
2173
2530
  const { width: W, height: H } = model.canvas;
2174
2531
  const fullBody = H > W;
2175
2532
  const canvas = fullBody ? {
@@ -2199,40 +2556,49 @@ function planRenders(model, requested) {
2199
2556
  name,
2200
2557
  values
2201
2558
  });
2559
+ const toRenderCrop = (crop, label) => {
2560
+ const left = Math.max(crop.x, 0);
2561
+ const top = Math.max(crop.y, 0);
2562
+ const w = Math.min(crop.x + crop.w, W) - left;
2563
+ const h = Math.min(crop.y + crop.h, H) - top;
2564
+ if (!(w > 0 && h > 0)) {
2565
+ throw new AutoRigInputError(
2566
+ `${label} does not overlap the model's ${W}x${H} canvas`
2567
+ );
2568
+ }
2569
+ const dh = Math.round(CROP_WIDTH * h / w);
2570
+ if (dh < 1 || dh > CROP_MAX_HEIGHT) {
2571
+ throw new AutoRigInputError(
2572
+ `${label} meets the canvas in ${w}x${h} model px, which ${CROP_WIDTH} px wide draws ${dh} px tall, outside 1..${CROP_MAX_HEIGHT}`
2573
+ );
2574
+ }
2575
+ return {
2576
+ sx: x0 + left * s,
2577
+ sy: y0 + top * s,
2578
+ sw: w * s,
2579
+ sh: h * s,
2580
+ dw: CROP_WIDTH,
2581
+ dh
2582
+ };
2583
+ };
2584
+ if (sweep && !SWEEP_NAME.test(sweep.name)) {
2585
+ throw new AutoRigInputError(
2586
+ `sweep.name must match ${SWEEP_NAME.source} (it names <outDir>/<name>/): ${JSON.stringify(sweep.name)}`
2587
+ );
2588
+ }
2589
+ const sweepCrop = sweep ? sweep.crop ? toRenderCrop(sweep.crop, "sweep.crop") : squareCrop : void 0;
2202
2590
  if (requested) {
2203
2591
  if (requested.length === 0) throw new AutoRigInputError("poses is empty");
2204
2592
  const poses2 = requested.map((pose, i) => {
2205
2593
  checkRequest(requested, i);
2206
2594
  if (!pose.crop) return square(pose.name, pose.values);
2207
- const left = Math.max(pose.crop.x, 0);
2208
- const top = Math.max(pose.crop.y, 0);
2209
- const w = Math.min(pose.crop.x + pose.crop.w, W) - left;
2210
- const h = Math.min(pose.crop.y + pose.crop.h, H) - top;
2211
- if (!(w > 0 && h > 0)) {
2212
- throw new AutoRigInputError(
2213
- `poses[${i}].crop does not overlap the model's ${W}x${H} canvas`
2214
- );
2215
- }
2216
- const dh = Math.round(CROP_WIDTH * h / w);
2217
- if (dh < 1 || dh > CROP_MAX_HEIGHT) {
2218
- throw new AutoRigInputError(
2219
- `poses[${i}].crop meets the canvas in ${w}x${h} model px, which ${CROP_WIDTH} px wide draws ${dh} px tall, outside 1..${CROP_MAX_HEIGHT}`
2220
- );
2221
- }
2222
2595
  return {
2223
2596
  name: pose.name,
2224
2597
  values: pose.values,
2225
- crop: {
2226
- sx: x0 + left * s,
2227
- sy: y0 + top * s,
2228
- sw: w * s,
2229
- sh: h * s,
2230
- dw: CROP_WIDTH,
2231
- dh
2232
- }
2598
+ crop: toRenderCrop(pose.crop, `poses[${i}].crop`)
2233
2599
  };
2234
2600
  });
2235
- return { canvas, view, fullBody, mouth, poses: poses2 };
2601
+ return { canvas, view, fullBody, mouth, poses: poses2, sweepCrop };
2236
2602
  }
2237
2603
  const bodyAngles = Object.fromEntries(
2238
2604
  [
@@ -2340,7 +2706,7 @@ function planRenders(model, requested) {
2340
2706
  );
2341
2707
  }
2342
2708
  }
2343
- return { canvas, view, fullBody, mouth, poses };
2709
+ return { canvas, view, fullBody, mouth, poses, sweepCrop };
2344
2710
  }
2345
2711
  function checkRequest(requested, i) {
2346
2712
  const { name, values } = requested[i];
@@ -2372,7 +2738,7 @@ var CAPTURE_MS = 15e3;
2372
2738
  function readPageScript() {
2373
2739
  const url = new URL("../dist/render-page.global.js", importMetaUrl);
2374
2740
  try {
2375
- return (0, import_node_fs3.readFileSync)(url, "utf8");
2741
+ return (0, import_node_fs4.readFileSync)(url, "utf8");
2376
2742
  } catch (cause) {
2377
2743
  throw new Error(
2378
2744
  "could not read the render page script; run `pnpm build` in packages/mcp",
@@ -2380,6 +2746,86 @@ function readPageScript() {
2380
2746
  );
2381
2747
  }
2382
2748
  }
2749
+ async function captureSweep(evaluate, model, plan, requested, dir, report) {
2750
+ const spec = sweepSpec(model, plan.sweepCrop);
2751
+ await evaluate(
2752
+ `window.__ikiRender.sweepBegin(${JSON.stringify(spec)})`,
2753
+ CAPTURE_MS
2754
+ );
2755
+ const frames = [];
2756
+ for (let k = 0; k < spec.frames; k++) {
2757
+ const { png, values } = await evaluate(
2758
+ "window.__ikiRender.sweepFrame()",
2759
+ CAPTURE_MS
2760
+ );
2761
+ if (typeof png !== "string" || !png.startsWith(PNG_PREFIX)) {
2762
+ throw new Error(
2763
+ `sweep ${requested.name} frame ${k}: the page returned no PNG`
2764
+ );
2765
+ }
2766
+ const file = `f${String(k).padStart(3, "0")}.png`;
2767
+ writeFileAtomic(
2768
+ import_node_path4.default.join(dir, file),
2769
+ Buffer.from(png.slice(PNG_PREFIX.length), "base64")
2770
+ );
2771
+ frames.push({
2772
+ i: k,
2773
+ file,
2774
+ t: k / SWEEP_FPS,
2775
+ theta: spec.thetas[spec.captureEvery * k],
2776
+ values
2777
+ });
2778
+ }
2779
+ const end = await evaluate("window.__ikiRender.sweepEnd()", CAPTURE_MS);
2780
+ for (const [what, url] of Object.entries(end)) {
2781
+ if (typeof url !== "string" || !url.startsWith(PNG_PREFIX)) {
2782
+ throw new Error(
2783
+ `sweep ${requested.name} ${what}: the page returned no PNG`
2784
+ );
2785
+ }
2786
+ }
2787
+ const sheet = import_node_path4.default.join(dir, "sheet.png");
2788
+ const kymograph = import_node_path4.default.join(dir, "kymograph.png");
2789
+ writeFileAtomic(
2790
+ sheet,
2791
+ Buffer.from(end.sheet.slice(PNG_PREFIX.length), "base64")
2792
+ );
2793
+ writeFileAtomic(
2794
+ kymograph,
2795
+ Buffer.from(end.kymograph.slice(PNG_PREFIX.length), "base64")
2796
+ );
2797
+ const manifest = {
2798
+ version: 1,
2799
+ preset: requested.preset,
2800
+ parameter: spec.parameter,
2801
+ fps: SWEEP_FPS,
2802
+ clockHz: SWEEP_CLOCK_HZ,
2803
+ warmupS: SWEEP_WARMUP_S,
2804
+ durationS: SWEEP_DURATION_S,
2805
+ crop: requested.crop ?? null,
2806
+ frame: spec.frame,
2807
+ kymographRow: { row: spec.kymograph.row, at: spec.kymograph.at },
2808
+ sheet: { frames: spec.sheet.frames, cell: spec.sheet.cell },
2809
+ physicsOutputs: spec.physicsOutputs,
2810
+ frames
2811
+ };
2812
+ const manifestPath = import_node_path4.default.join(dir, "manifest.json");
2813
+ const flipbook = import_node_path4.default.join(dir, "index.html");
2814
+ writeFileAtomic(manifestPath, JSON.stringify(manifest, null, 2) + "\n");
2815
+ writeFileAtomic(flipbook, flipbookHtml(manifest));
2816
+ return {
2817
+ name: requested.name,
2818
+ preset: requested.preset,
2819
+ dir,
2820
+ fps: SWEEP_FPS,
2821
+ frames: spec.frames,
2822
+ manifest: manifestPath,
2823
+ sheet,
2824
+ kymograph,
2825
+ flipbook,
2826
+ report
2827
+ };
2828
+ }
2383
2829
  async function renderPoses(input) {
2384
2830
  try {
2385
2831
  const modelFile = confineToWorkingDirectory(
@@ -2389,8 +2835,8 @@ async function renderPoses(input) {
2389
2835
  input.modelPath
2390
2836
  );
2391
2837
  const outDir = resolveOutputDir(input.outDir);
2392
- const model = (0, import_format8.loadIkiModel)((0, import_node_fs3.readFileSync)(modelFile, "utf8"));
2393
- const plan = planRenders(model, input.poses);
2838
+ const model = (0, import_format8.loadIkiModel)((0, import_node_fs4.readFileSync)(modelFile, "utf8"));
2839
+ const plan = planRenders(model, input.poses, input.sweep);
2394
2840
  const browser = findBrowser();
2395
2841
  if (!browser) return { ok: false, error: NO_BROWSER_MESSAGE };
2396
2842
  const pageScript = readPageScript();
@@ -2399,7 +2845,9 @@ async function renderPoses(input) {
2399
2845
  input.poses?.map((p) => p.values)
2400
2846
  );
2401
2847
  const physics = checkPhysics(model);
2402
- const { failedTextures, poses } = await withBrowser(
2848
+ const sweepDir = input.sweep ? prepareSweepDir(outDir, input.sweep.name) : void 0;
2849
+ const sweepReport = input.sweep ? checkSweep(model) : void 0;
2850
+ const { failedTextures, poses, sweep } = await withBrowser(
2403
2851
  browser,
2404
2852
  async (evaluate) => {
2405
2853
  await evaluate(pageScript, PAGE_SCRIPT_MS);
@@ -2416,14 +2864,22 @@ async function renderPoses(input) {
2416
2864
  if (typeof url !== "string" || !url.startsWith(PNG_PREFIX)) {
2417
2865
  throw new Error(`pose ${pose.name}: the page returned no PNG`);
2418
2866
  }
2419
- const file = import_node_path3.default.join(outDir, `${pose.name}.png`);
2867
+ const file = import_node_path4.default.join(outDir, `${pose.name}.png`);
2420
2868
  writeFileAtomic(
2421
2869
  file,
2422
2870
  Buffer.from(url.slice(PNG_PREFIX.length), "base64")
2423
2871
  );
2424
2872
  written.push({ name: pose.name, path: file });
2425
2873
  }
2426
- return { failedTextures: loaded.failedTextures, poses: written };
2874
+ const sweep2 = input.sweep && sweepDir && sweepReport ? await captureSweep(
2875
+ evaluate,
2876
+ model,
2877
+ plan,
2878
+ input.sweep,
2879
+ sweepDir,
2880
+ sweepReport
2881
+ ) : void 0;
2882
+ return { failedTextures: loaded.failedTextures, poses: written, sweep: sweep2 };
2427
2883
  }
2428
2884
  );
2429
2885
  return {
@@ -2436,7 +2892,8 @@ async function renderPoses(input) {
2436
2892
  poses,
2437
2893
  modelCanvas: model.canvas,
2438
2894
  folds,
2439
- physics
2895
+ physics,
2896
+ sweep
2440
2897
  };
2441
2898
  } catch (error) {
2442
2899
  if (error instanceof AutoRigInputError || error instanceof import_format8.IkiFormatError) {
@@ -2544,7 +3001,7 @@ function describeIki(model) {
2544
3001
  const padY = bustPadY(W, H);
2545
3002
  const tenth = (n) => Math.round(n * 10) / 10;
2546
3003
  const parts = m.parts.map((p) => {
2547
- const box = {
3004
+ const box2 = {
2548
3005
  x: W / 2 + p.transform.x - p.width / 2,
2549
3006
  y: H / 2 - p.transform.y - p.height / 2,
2550
3007
  w: p.width,
@@ -2553,12 +3010,12 @@ function describeIki(model) {
2553
3010
  const entry = {
2554
3011
  id: p.id,
2555
3012
  order: p.order,
2556
- box,
3013
+ box: box2,
2557
3014
  bustBox: {
2558
- x: tenth(box.x * bustScale),
2559
- y: tenth(padY + box.y * bustScale),
2560
- w: tenth(box.w * bustScale),
2561
- h: tenth(box.h * bustScale)
3015
+ x: tenth(box2.x * bustScale),
3016
+ y: tenth(padY + box2.y * bustScale),
3017
+ w: tenth(box2.w * bustScale),
3018
+ h: tenth(box2.h * bustScale)
2562
3019
  }
2563
3020
  };
2564
3021
  if (p.deformer !== void 0) entry.deformer = p.deformer;
@@ -2628,7 +3085,7 @@ function describeIkiAt(modelPath) {
2628
3085
  "model path",
2629
3086
  modelPath
2630
3087
  );
2631
- return describeIki((0, import_node_fs4.readFileSync)(modelFile, "utf8"));
3088
+ return describeIki((0, import_node_fs5.readFileSync)(modelFile, "utf8"));
2632
3089
  } catch (e) {
2633
3090
  if (e instanceof AutoRigInputError) return { ok: false, error: e.message };
2634
3091
  throw e;
@@ -2759,6 +3216,22 @@ var STANDARD_PARAMETER_INFO = [
2759
3216
  function listStandardParameters() {
2760
3217
  return STANDARD_PARAMETER_INFO.map((p) => ({ ...p }));
2761
3218
  }
3219
+ function describeRigPlan() {
3220
+ return { fields: [...import_editor3.RIG_PLAN_FIELDS] };
3221
+ }
3222
+ function formatRigPlanReport(r) {
3223
+ const fields = import_editor3.RIG_PLAN_FIELDS.map((f) => {
3224
+ const value = `${f.path}=${r.effective[f.path]}`;
3225
+ const clamp2 = r.clamped.find((c) => c.field === f.path);
3226
+ if (clamp2 !== void 0) {
3227
+ const asked = r.requested[f.group]?.[f.key] ?? f.default;
3228
+ return `${value} (requested ${asked}, clamped at ${clamp2.bound})`;
3229
+ }
3230
+ const cue = r.overriddenBy[f.path];
3231
+ return cue === void 0 ? value : `${value} (fitted by ${cue})`;
3232
+ });
3233
+ return `RIGPLAN: ${fields.join(" ")}`;
3234
+ }
2762
3235
  function expectInput(label, fn) {
2763
3236
  try {
2764
3237
  return fn();
@@ -2807,6 +3280,9 @@ async function autoRigFromLayers(input) {
2807
3280
  `quantizeColors must be an integer in 2..256, got ${String(quantizeColors)}`
2808
3281
  );
2809
3282
  }
3283
+ if (input.style !== void 0) {
3284
+ throw new AutoRigInputError((0, import_editor3.styleRemovedMessage)("style"));
3285
+ }
2810
3286
  const turnTargets = input.turnTargets;
2811
3287
  if (turnTargets !== void 0) {
2812
3288
  if (typeof turnTargets !== "object" || turnTargets === null || Array.isArray(turnTargets)) {
@@ -2820,7 +3296,7 @@ async function autoRigFromLayers(input) {
2820
3296
  }
2821
3297
  const resolvedLayers = layers.map((layer) => {
2822
3298
  const resolved = resolveInputPath(layer.path);
2823
- return { resolved, fileName: layer.fileName ?? import_node_path4.default.basename(resolved) };
3299
+ return { resolved, fileName: layer.fileName ?? import_node_path5.default.basename(resolved) };
2824
3300
  });
2825
3301
  const rolePairs = expectInput(
2826
3302
  "role parsing",
@@ -2882,6 +3358,7 @@ async function autoRigFromLayers(input) {
2882
3358
  )?.denseCore;
2883
3359
  let turn;
2884
3360
  let patches;
3361
+ let rigPlan;
2885
3362
  let model;
2886
3363
  try {
2887
3364
  model = (0, import_editor3.generateIkiFromLayerSet)(
@@ -2895,7 +3372,10 @@ async function autoRigFromLayers(input) {
2895
3372
  onTurnSolved: (report) => {
2896
3373
  turn = report;
2897
3374
  },
2898
- ...input.style === void 0 ? {} : { style: input.style },
3375
+ ...input.rigPlan === void 0 ? {} : { rigPlan: input.rigPlan },
3376
+ onRigPlanResolved: (report) => {
3377
+ rigPlan = report;
3378
+ },
2899
3379
  ...input.patches === void 0 ? {} : {
2900
3380
  patches: input.patches,
2901
3381
  onPatchesApplied: (reports) => {
@@ -2907,7 +3387,7 @@ async function autoRigFromLayers(input) {
2907
3387
  }
2908
3388
  );
2909
3389
  } catch (e) {
2910
- if (!(e instanceof import_editor3.TurnTargetError || e instanceof import_editor3.LayerGeometryError || e instanceof import_editor3.PatchError)) {
3390
+ if (!(e instanceof import_editor3.TurnTargetError || e instanceof import_editor3.LayerGeometryError || e instanceof import_editor3.PatchError || e instanceof import_editor3.RigPlanError)) {
2911
3391
  throw e;
2912
3392
  }
2913
3393
  throw new AutoRigInputError(e.message);
@@ -2970,7 +3450,8 @@ async function autoRigFromLayers(input) {
2970
3450
  ...turn === void 0 ? {} : { turn },
2971
3451
  folds,
2972
3452
  physics,
2973
- ...patches === void 0 ? {} : { patches }
3453
+ ...patches === void 0 ? {} : { patches },
3454
+ rigPlan
2974
3455
  };
2975
3456
  } catch (err) {
2976
3457
  if (err instanceof AutoRigInputError)
@@ -2980,8 +3461,8 @@ async function autoRigFromLayers(input) {
2980
3461
  }
2981
3462
 
2982
3463
  // src/compose.ts
2983
- var import_node_fs6 = __toESM(require("fs"));
2984
- var import_node_path9 = __toESM(require("path"));
3464
+ var import_node_fs7 = __toESM(require("fs"));
3465
+ var import_node_path10 = __toESM(require("path"));
2985
3466
  var import_sharp4 = __toESM(require("sharp"));
2986
3467
  var import_editor12 = require("@ikijs/editor");
2987
3468
 
@@ -3052,18 +3533,18 @@ function boxWithoutStraySpecks(rgba, W, H) {
3052
3533
  }
3053
3534
 
3054
3535
  // src/measure.ts
3055
- var import_node_fs5 = __toESM(require("fs"));
3056
- var import_node_path8 = __toESM(require("path"));
3536
+ var import_node_fs6 = __toESM(require("fs"));
3537
+ var import_node_path9 = __toESM(require("path"));
3057
3538
 
3058
3539
  // src/measure-arms.ts
3059
- var import_node_path5 = __toESM(require("path"));
3540
+ var import_node_path6 = __toESM(require("path"));
3060
3541
  var import_editor5 = require("@ikijs/editor");
3061
3542
  var ARM_ROLES = ["arm_L", "arm_R"];
3062
3543
  var CAP_OVERLAP = 0.5;
3063
3544
  var px = (v) => `${Number(v.toFixed(1))}`;
3064
3545
  async function measured(measurer, absDir, role) {
3065
3546
  const fileName = `${role}.png`;
3066
- const { rgba } = await decodePng(import_node_path5.default.join(absDir, fileName));
3547
+ const { rgba } = await decodePng(import_node_path6.default.join(absDir, fileName));
3067
3548
  return measurer.add({ role, fileName, rgba });
3068
3549
  }
3069
3550
  async function armWarnings(absDir, layers) {
@@ -3213,7 +3694,7 @@ function jointWarnings(pose, arm, stats, a, armLayer, b) {
3213
3694
  }
3214
3695
 
3215
3696
  // src/measure-lips.ts
3216
- var import_node_path6 = __toESM(require("path"));
3697
+ var import_node_path7 = __toESM(require("path"));
3217
3698
  var import_editor8 = require("@ikijs/editor");
3218
3699
 
3219
3700
  // src/compose-lips.ts
@@ -3247,7 +3728,7 @@ function components(mask, W, H) {
3247
3728
  for (let start = 0; start < n; start++) {
3248
3729
  if (!mask[start] || label[start] >= 0) continue;
3249
3730
  const id = sizes.length;
3250
- const box = { x0: W, y0: H, x1: -1, y1: -1 };
3731
+ const box2 = { x0: W, y0: H, x1: -1, y1: -1 };
3251
3732
  let size = 0;
3252
3733
  let depth = 0;
3253
3734
  label[start] = id;
@@ -3257,10 +3738,10 @@ function components(mask, W, H) {
3257
3738
  size++;
3258
3739
  const px2 = p % W;
3259
3740
  const py = (p - px2) / W;
3260
- box.x0 = Math.min(box.x0, px2);
3261
- box.x1 = Math.max(box.x1, px2);
3262
- box.y0 = Math.min(box.y0, py);
3263
- box.y1 = Math.max(box.y1, py);
3741
+ box2.x0 = Math.min(box2.x0, px2);
3742
+ box2.x1 = Math.max(box2.x1, px2);
3743
+ box2.y0 = Math.min(box2.y0, py);
3744
+ box2.y1 = Math.max(box2.y1, py);
3264
3745
  for (let y = Math.max(0, py - 1); y <= Math.min(H - 1, py + 1); y++) {
3265
3746
  for (let x = Math.max(0, px2 - 1); x <= Math.min(W - 1, px2 + 1); x++) {
3266
3747
  if (x !== px2 && y !== py) continue;
@@ -3273,7 +3754,7 @@ function components(mask, W, H) {
3273
3754
  }
3274
3755
  }
3275
3756
  sizes.push(size);
3276
- boxes.push(box);
3757
+ boxes.push(box2);
3277
3758
  }
3278
3759
  return { label, sizes, boxes };
3279
3760
  }
@@ -3510,14 +3991,14 @@ async function prepInterior(rgba, W, H) {
3510
3991
  for (let p = 0; p < cw * ch; p++) {
3511
3992
  if (label[p] >= 0 && rim[label[p]]) crop[p * 4 + 3] = 0;
3512
3993
  }
3513
- const box = drawingBox(crop, cw, ch);
3514
- if (box === null) throw empty;
3994
+ const box2 = drawingBox(crop, cw, ch);
3995
+ if (box2 === null) throw empty;
3515
3996
  const sum = [0, 0, 0];
3516
3997
  const all = [0, 0, 0];
3517
3998
  let dark = 0;
3518
3999
  let count = 0;
3519
- for (let y = box.y; y < box.y + box.h; y++) {
3520
- for (let x = box.x; x < box.x + box.w; x++) {
4000
+ for (let y = box2.y; y < box2.y + box2.h; y++) {
4001
+ for (let x = box2.x; x < box2.x + box2.w; x++) {
3521
4002
  const i = (y * cw + x) * 4;
3522
4003
  if (crop[i + 3] < import_editor7.ALPHA_OPAQUE) continue;
3523
4004
  count++;
@@ -3531,7 +4012,7 @@ async function prepInterior(rgba, W, H) {
3531
4012
  if (count === 0) throw empty;
3532
4013
  const [from, over] = dark > 0 ? [sum, dark] : [all, count];
3533
4014
  const cavity = from.map((v) => Math.round(v / over));
3534
- return { png: await cropToBuffer(crop, cw, ch, box), cavity };
4015
+ return { png: await cropToBuffer(crop, cw, ch, box2), cavity };
3535
4016
  }
3536
4017
  var rawOf = async (png) => (0, import_sharp2.default)(png).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
3537
4018
  var encode = (rgba, w, h) => (0, import_sharp2.default)(rgba, { raw: { width: w, height: h, channels: 4 } }).png().toBuffer();
@@ -3574,8 +4055,8 @@ function enclosedHole(frame, w, h) {
3574
4055
  `${KEYED_SRC}: the outline is not closed round the opening (the key reached the outside, or the line is broken or too thin at this size) \u2014 regenerate with ONE closed, bolder outline`
3575
4056
  );
3576
4057
  }
3577
- const box = boxes[main2];
3578
- const holeW = box.x1 - box.x0 + 1;
4058
+ const box2 = boxes[main2];
4059
+ const holeW = box2.x1 - box2.x0 + 1;
3579
4060
  if (holeW < MIN_OPENING_WIDTH * w) {
3580
4061
  throw new AutoRigInputError(
3581
4062
  `${KEYED_SRC}: the opening is only ${holeW} px wide of the mouth's ${w} \u2014 too small to fold; regenerate with the mouth open wider, or, if its outline is broken (only a small pocket of the opening was enclosed), with ONE closed, bolder outline`
@@ -3589,7 +4070,7 @@ function enclosedHole(frame, w, h) {
3589
4070
  `${KEYED_SRC}: the opening is not one connected region (${others.length + 1} holes: teeth or tongue drawn into the green?) \u2014 regenerate with nothing drawn inside the green`
3590
4071
  );
3591
4072
  }
3592
- return { label, main: main2, box };
4073
+ return { label, main: main2, box: box2 };
3593
4074
  }
3594
4075
  function measureLips(layers, w, h) {
3595
4076
  const measurer = (0, import_editor7.createLayerSetMeasurer)({ width: w, height: h });
@@ -3857,15 +4338,15 @@ async function lipWarnings(absDir, layers) {
3857
4338
  return { warnings };
3858
4339
  }
3859
4340
  }
3860
- const box = (m) => ({
4341
+ const box2 = (m) => ({
3861
4342
  x0: m.bboxCx - m.w / 2,
3862
4343
  x1: m.bboxCx + m.w / 2,
3863
4344
  y0: m.bboxCy - m.h / 2,
3864
4345
  y1: m.bboxCy + m.h / 2
3865
4346
  });
3866
- const cavity = box(inner);
4347
+ const cavity = box2(inner);
3867
4348
  for (const role of inside) {
3868
- const b = box(layers[role]);
4349
+ const b = box2(layers[role]);
3869
4350
  if (b.x0 < cavity.x0 || b.x1 > cavity.x1 || b.y0 < cavity.y0 || b.y1 > cavity.y1) {
3870
4351
  warnings.push(
3871
4352
  `${role}: its box leaves mouth_inner's \u2014 the cavity clips it away there. Recompose from mouth_keyed.png + mouth_interior.png (free).`
@@ -3880,7 +4361,7 @@ async function lipWarnings(absDir, layers) {
3880
4361
  const green = [];
3881
4362
  for (const role of import_editor8.LIP_ROLES) {
3882
4363
  const fileName = `${role}.png`;
3883
- const { rgba } = await decodePng(import_node_path6.default.join(absDir, fileName));
4364
+ const { rgba } = await decodePng(import_node_path7.default.join(absDir, fileName));
3884
4365
  set.set(role, measurer.add({ role, fileName, rgba }));
3885
4366
  for (let i = 0; i < rgba.length; i += 4) {
3886
4367
  if (rgba[i + 3] >= import_editor8.ALPHA_OPAQUE && rgba[i + 1] - Math.max(rgba[i], rgba[i + 2]) > GREEN_EXCESS) {
@@ -3984,7 +4465,7 @@ async function lipWarnings(absDir, layers) {
3984
4465
  }
3985
4466
 
3986
4467
  // src/measure-turn.ts
3987
- var import_node_path7 = __toESM(require("path"));
4468
+ var import_node_path8 = __toESM(require("path"));
3988
4469
  var import_editor9 = require("@ikijs/editor");
3989
4470
  var import_editor10 = require("@ikijs/editor");
3990
4471
  var DEFAULT_IRIS = { hueMin: 230, hueMax: 300, satMin: 0.22 };
@@ -4252,14 +4733,14 @@ function farNearWidths(m, turnSign) {
4252
4733
  return turnSign < 0 ? { far: m.irisL.w, near: m.irisR.w } : { far: m.irisR.w, near: m.irisL.w };
4253
4734
  }
4254
4735
  function overlaySvg(m) {
4255
- const box = (b, stroke) => `<rect x="${b.x0}" y="${b.y0}" width="${b.w}" height="${b.h}" fill="none" stroke="${stroke}" stroke-width="3"/>`;
4736
+ const box2 = (b, stroke) => `<rect x="${b.x0}" y="${b.y0}" width="${b.w}" height="${b.h}" fill="none" stroke="${stroke}" stroke-width="3"/>`;
4256
4737
  const tick = (x, half, stroke) => `<line x1="${x}" y1="${m.eyeRow - half}" x2="${x}" y2="${m.eyeRow + half}" stroke="${stroke}" stroke-width="3"/>`;
4257
- return `<svg width="${m.width}" height="${m.height}">` + box(m.irisL, "#ff0000") + box(m.irisR, "#00c000") + tick(m.head.left, 40, "#0000ff") + tick(m.head.right, 40, "#0000ff") + tick(m.head.cx, 60, "#ff8800") + tick(m.pairCx, 60, "#ff00ff") + "</svg>";
4738
+ return `<svg width="${m.width}" height="${m.height}">` + box2(m.irisL, "#ff0000") + box2(m.irisR, "#00c000") + tick(m.head.left, 40, "#0000ff") + tick(m.head.right, 40, "#0000ff") + tick(m.head.cx, 60, "#ff8800") + tick(m.pairCx, 60, "#ff00ff") + "</svg>";
4258
4739
  }
4259
4740
  async function writeOverlay(debugDir, label, m) {
4260
- const outPath = import_node_path7.default.join(
4741
+ const outPath = import_node_path8.default.join(
4261
4742
  debugDir,
4262
- `${label}-${import_node_path7.default.basename(m.file, ".png")}.debug.png`
4743
+ `${label}-${import_node_path8.default.basename(m.file, ".png")}.debug.png`
4263
4744
  );
4264
4745
  writeFileAtomic(outPath, await encodeOverlayPng(m.file, overlaySvg(m)));
4265
4746
  return outPath;
@@ -4451,7 +4932,7 @@ async function lashOffSclera(eyePath, lashPath) {
4451
4932
  return { opaque, off };
4452
4933
  }
4453
4934
  async function measureDir(absDir, noseSpeck) {
4454
- const files = import_node_fs5.default.readdirSync(absDir).filter((f) => f.endsWith(".png") && !f.startsWith("preview")).sort();
4935
+ const files = import_node_fs6.default.readdirSync(absDir).filter((f) => f.endsWith(".png") && !f.startsWith("preview")).sort();
4455
4936
  if (files.length === 0) {
4456
4937
  throw new AutoRigInputError(`no role layers in ${absDir}`);
4457
4938
  }
@@ -4463,8 +4944,8 @@ async function measureDir(absDir, noseSpeck) {
4463
4944
  const layers = {};
4464
4945
  const empty = [];
4465
4946
  for (const f of files) {
4466
- const role = import_node_path8.default.basename(f, ".png");
4467
- const m = await layerStats(import_node_path8.default.join(absDir, f));
4947
+ const role = import_node_path9.default.basename(f, ".png");
4948
+ const m = await layerStats(import_node_path9.default.join(absDir, f));
4468
4949
  if (!m) {
4469
4950
  empty.push(role);
4470
4951
  continue;
@@ -4542,8 +5023,8 @@ async function measureDir(absDir, noseSpeck) {
4542
5023
  }
4543
5024
  if (lash) {
4544
5025
  const { opaque, off } = await lashOffSclera(
4545
- import_node_path8.default.join(absDir, `eye_${side}.png`),
4546
- import_node_path8.default.join(absDir, `lash_${side}.png`)
5026
+ import_node_path9.default.join(absDir, `eye_${side}.png`),
5027
+ import_node_path9.default.join(absDir, `lash_${side}.png`)
4547
5028
  );
4548
5029
  const dTop = lash.marginTop - eye.marginTop;
4549
5030
  const faults = [
@@ -4569,7 +5050,7 @@ async function measureDir(absDir, noseSpeck) {
4569
5050
  if (noseSpeck !== void 0) {
4570
5051
  warnings.push(noseSpeckWarning(noseSpeck, "compose"));
4571
5052
  } else if (layers.nose !== void 0) {
4572
- const nose = await decodePng(import_node_path8.default.join(absDir, "nose.png"));
5053
+ const nose = await decodePng(import_node_path9.default.join(absDir, "nose.png"));
4573
5054
  const core = (0, import_editor10.denseCoreOf)(nose.rgba, nose.width, nose.height);
4574
5055
  if (core !== null) {
4575
5056
  const crop = detectAlphaBbox(nose.rgba, nose.width, nose.height);
@@ -5004,8 +5485,8 @@ async function trimmedPart(role, cfg, partsDir, inMemory, flipSource) {
5004
5485
  if (inMemory !== void 0) {
5005
5486
  img = (0, import_sharp4.default)(inMemory);
5006
5487
  } else {
5007
- const srcPath = import_node_path9.default.join(partsDir, cfg.src);
5008
- if (!import_node_fs6.default.existsSync(srcPath)) {
5488
+ const srcPath = import_node_path10.default.join(partsDir, cfg.src);
5489
+ if (!import_node_fs7.default.existsSync(srcPath)) {
5009
5490
  if (cfg.optional) return null;
5010
5491
  throw new AutoRigInputError(
5011
5492
  `missing part source for role "${role}": ${srcPath}` + (role === "mouth" ? " \u2014 draw mouth.png (with mouth_open.png), or the lip set's mouth_keyed.png + mouth_interior.png" : "")
@@ -5022,8 +5503,8 @@ async function trimmedPart(role, cfg, partsDir, inMemory, flipSource) {
5022
5503
  img = (0, import_sharp4.default)(kept.data, {
5023
5504
  raw: { width: keptW, height: keptH, channels: 4 }
5024
5505
  });
5025
- const box = boxWithoutStraySpecks(kept.data, keptW, keptH);
5026
- if (box !== null) img = img.extract(box);
5506
+ const box2 = boxWithoutStraySpecks(kept.data, keptW, keptH);
5507
+ if (box2 !== null) img = img.extract(box2);
5027
5508
  }
5028
5509
  if ((cfg.mirror ?? false) !== flipSource) img = img.flop();
5029
5510
  const trimmed = await img.png().toBuffer({ resolveWithObject: true });
@@ -5070,18 +5551,18 @@ function placement2(role, cfg, w, h, canvas) {
5070
5551
  assertOnCanvas(`layout.${role}.cx/cy`, w, h, left, top, canvas);
5071
5552
  return { left, top };
5072
5553
  }
5073
- function nosePlacement(layout, mouthKey, box, w, h, canvas) {
5554
+ function nosePlacement(layout, mouthKey, box2, w, h, canvas) {
5074
5555
  const { cx, cy } = layout.nose;
5075
- const left = Math.round(cx - (box.x + box.w / 2));
5556
+ const left = Math.round(cx - (box2.x + box2.w / 2));
5076
5557
  let top;
5077
5558
  if (cy !== void 0) {
5078
- top = Math.round(cy - (box.y + box.h / 2));
5559
+ top = Math.round(cy - (box2.y + box2.h / 2));
5079
5560
  } else {
5080
5561
  const eyeRow = (layout.eye_L.cy + layout.eye_R.cy) / 2;
5081
5562
  const tipRow = Math.round(
5082
5563
  eyeRow + NOSE_TIP_AT * (layout[mouthKey].cy - eyeRow)
5083
5564
  );
5084
- top = tipRow - (box.y + box.h - 1);
5565
+ top = tipRow - (box2.y + box2.h - 1);
5085
5566
  }
5086
5567
  assertOnCanvas(
5087
5568
  cy !== void 0 ? "layout.nose.cx/cy" : `layout.nose.cx/cy (cy unset: its tip row comes from layout.eye_L/eye_R/${mouthKey}.cy)`,
@@ -5189,8 +5670,8 @@ function detachedAboveWhite(rgba, W, H) {
5189
5670
  return detached;
5190
5671
  }
5191
5672
  async function prepEyeSplit(partsDir) {
5192
- const srcPath = import_node_path9.default.join(partsDir, EYEWHITE_SRC);
5193
- if (!import_node_fs6.default.existsSync(srcPath)) {
5673
+ const srcPath = import_node_path10.default.join(partsDir, EYEWHITE_SRC);
5674
+ if (!import_node_fs7.default.existsSync(srcPath)) {
5194
5675
  throw new AutoRigInputError(`missing eyewhite source: ${srcPath}`);
5195
5676
  }
5196
5677
  const { width: W, height: H, rgba: data } = await decodePng(srcPath);
@@ -5277,7 +5758,7 @@ function hasTransparency(rgba) {
5277
5758
  return false;
5278
5759
  }
5279
5760
  async function prepLipSources(partsDir, mirrored) {
5280
- const has = (name) => import_node_fs6.default.existsSync(import_node_path9.default.join(partsDir, name));
5761
+ const has = (name) => import_node_fs7.default.existsSync(import_node_path10.default.join(partsDir, name));
5281
5762
  const keyed = has(KEYED_SRC);
5282
5763
  const interior = has(INTERIOR_SRC);
5283
5764
  if (keyed && !interior) {
@@ -5297,13 +5778,13 @@ async function prepLipSources(partsDir, mirrored) {
5297
5778
  `${KEYED_SRC}/${INTERIOR_SRC} cannot be composed beside mouth.png/mouth_open.png (the lip set replaces the mouth drawings, and auto_rig_from_layers refuses the mix) \u2014 remove ${legacy.join(" and ")}`
5298
5779
  );
5299
5780
  }
5300
- const k = await decodePng(import_node_path9.default.join(partsDir, KEYED_SRC));
5781
+ const k = await decodePng(import_node_path10.default.join(partsDir, KEYED_SRC));
5301
5782
  const keyedRgba = keyGreen(
5302
5783
  hasTransparency(k.rgba) ? k.rgba : keyWhiteToAlpha(k.rgba),
5303
5784
  k.width,
5304
5785
  k.height
5305
5786
  );
5306
- const i = await decodePng(import_node_path9.default.join(partsDir, INTERIOR_SRC));
5787
+ const i = await decodePng(import_node_path10.default.join(partsDir, INTERIOR_SRC));
5307
5788
  const prepared = await prepInterior(
5308
5789
  hasTransparency(i.rgba) ? i.rgba : keyBorderWhite(i.rgba, i.width, i.height),
5309
5790
  i.width,
@@ -5320,7 +5801,7 @@ async function composeLayersFromParts(input) {
5320
5801
  try {
5321
5802
  const outDir = resolveOutputDir(input.outDir);
5322
5803
  const partsDir = resolveInputDir(input.partsDir);
5323
- if (import_node_fs6.default.realpathSync(partsDir) === outDir) {
5804
+ if (import_node_fs7.default.realpathSync(partsDir) === outDir) {
5324
5805
  throw new AutoRigInputError(
5325
5806
  `partsDir and outDir resolve to the same directory (${outDir}): composing would overwrite the source parts`
5326
5807
  );
@@ -5399,7 +5880,7 @@ async function composeLayersFromParts(input) {
5399
5880
  }
5400
5881
  if (key === "arm_L" || key === "arm_R") {
5401
5882
  const arm = layout[key];
5402
- if (!import_node_fs6.default.existsSync(import_node_path9.default.join(partsDir, arm.src))) continue;
5883
+ if (!import_node_fs7.default.existsSync(import_node_path10.default.join(partsDir, arm.src))) continue;
5403
5884
  const body = placed.find((p) => p.role === "body");
5404
5885
  if (body === void 0) {
5405
5886
  throw new AutoRigInputError(
@@ -5442,7 +5923,7 @@ async function composeLayersFromParts(input) {
5442
5923
  }
5443
5924
  if (key === "forearm_pose_L" || key === "forearm_pose_R") {
5444
5925
  const pose = layout[key];
5445
- if (!import_node_fs6.default.existsSync(import_node_path9.default.join(partsDir, pose.src))) continue;
5926
+ if (!import_node_fs7.default.existsSync(import_node_path10.default.join(partsDir, pose.src))) continue;
5446
5927
  const armRole = key === "forearm_pose_L" ? "arm_L" : "arm_R";
5447
5928
  const arm = placed.find((p) => p.role === armRole);
5448
5929
  if (arm?.elbow === void 0 || arm.elbowRun === void 0) {
@@ -5512,11 +5993,11 @@ async function composeLayersFromParts(input) {
5512
5993
  if (key === "nose") {
5513
5994
  noseSpeck = part.nose?.speck;
5514
5995
  const { core, bounds } = await coreAndBoundsOf(part.buf);
5515
- const box = part.nose?.whole ? bounds : core ?? bounds;
5996
+ const box2 = part.nose?.whole ? bounds : core ?? bounds;
5516
5997
  ({ left, top } = nosePlacement(
5517
5998
  layout,
5518
5999
  lips === void 0 ? "mouth" : "mouth_inner",
5519
- box,
6000
+ box2,
5520
6001
  part.w,
5521
6002
  part.h,
5522
6003
  canvas
@@ -5559,15 +6040,15 @@ async function composeLayersFromParts(input) {
5559
6040
  );
5560
6041
  for (const role of ORDER) {
5561
6042
  if (placed.some((p) => p.role === role)) continue;
5562
- import_node_fs6.default.rmSync(import_node_path9.default.join(outDir, `${role}.png`), { force: true });
6043
+ import_node_fs7.default.rmSync(import_node_path10.default.join(outDir, `${role}.png`), { force: true });
5563
6044
  }
5564
6045
  const posed = (role) => role === "forearm_pose_L" || role === "forearm_pose_R";
5565
6046
  if (!placed.some((p) => posed(p.role))) {
5566
- import_node_fs6.default.rmSync(import_node_path9.default.join(outDir, "preview-pose.png"), { force: true });
6047
+ import_node_fs7.default.rmSync(import_node_path10.default.join(outDir, "preview-pose.png"), { force: true });
5567
6048
  }
5568
6049
  const layers = [];
5569
6050
  for (const { role, part, left, top } of placed) {
5570
- const outPath = import_node_path9.default.join(outDir, `${role}.png`);
6051
+ const outPath = import_node_path10.default.join(outDir, `${role}.png`);
5571
6052
  writeFileAtomic(outPath, built.get(role));
5572
6053
  layers.push({
5573
6054
  role,
@@ -5598,7 +6079,7 @@ async function composeLayersFromParts(input) {
5598
6079
  background: { r: 245, g: 245, b: 248, alpha: 1 }
5599
6080
  }
5600
6081
  }).composite(preview).png().toBuffer();
5601
- const previewPath = import_node_path9.default.join(outDir, "preview.png");
6082
+ const previewPath = import_node_path10.default.join(outDir, "preview.png");
5602
6083
  writeFileAtomic(previewPath, previewPng);
5603
6084
  let previewPosePath;
5604
6085
  if (placed.some((p) => posed(p.role))) {
@@ -5627,7 +6108,7 @@ async function composeLayersFromParts(input) {
5627
6108
  background: { r: 245, g: 245, b: 248, alpha: 1 }
5628
6109
  }
5629
6110
  }).composite(pose).png().toBuffer();
5630
- previewPosePath = import_node_path9.default.join(outDir, "preview-pose.png");
6111
+ previewPosePath = import_node_path10.default.join(outDir, "preview-pose.png");
5631
6112
  writeFileAtomic(previewPosePath, posePng);
5632
6113
  }
5633
6114
  return {
@@ -5671,7 +6152,7 @@ function formatPatchReports(reports) {
5671
6152
  });
5672
6153
  }
5673
6154
  function createIkiMcpServer() {
5674
- const server = new import_mcp.McpServer({ name: "iki", version: "0.29.0" });
6155
+ const server = new import_mcp.McpServer({ name: "iki", version: "0.31.0" });
5675
6156
  server.registerTool(
5676
6157
  "validate_iki",
5677
6158
  {
@@ -5743,10 +6224,27 @@ function createIkiMcpServer() {
5743
6224
  };
5744
6225
  }
5745
6226
  );
6227
+ server.registerTool(
6228
+ "describe_rig_plan",
6229
+ {
6230
+ description: "Lists the fields of the `rigPlan` input of auto_rig_from_layers: each one's path, default, range, recommended span, step, unit, the poses it shows at, the report reading that shows it and the `turnTargets` cue that fits it when given. The one source of those numbers.",
6231
+ inputSchema: {}
6232
+ },
6233
+ async () => {
6234
+ const { fields } = describeRigPlan();
6235
+ const text = fields.map(
6236
+ (f) => `${f.path} default ${f.default} range ${f.range[0]}..${f.range[1]} recommended ${f.recommended[0]}..${f.recommended[1]} step ${f.step} ${f.unit} \u2014 ${f.what}; shows at ${f.poses.map((p) => JSON.stringify(p)).join(" ")}; cue ${f.cue ?? "none"}; fitted by ${f.fitBy ?? "none"}${f.provisional ? "; provisional" : ""}`
6237
+ ).join("\n");
6238
+ return {
6239
+ content: [{ type: "text", text }],
6240
+ structuredContent: { fields }
6241
+ };
6242
+ }
6243
+ );
5746
6244
  server.registerTool(
5747
6245
  "auto_rig_from_layers",
5748
6246
  {
5749
- description: "Auto-rigs role-named PNG layers (face, eye_L/eye_R and either mouth or the lip set (mouth_inner + lip_lower + lip_upper, a mouth that folds open instead of crossfading) required; iris_L/R, brow_L/R, hair_front, body, arm_L/arm_R, forearm_pose_L/forearm_pose_R, mouth_tongue/mouth_teeth (only with the lip set: drawn under its lips and clipped to mouth_inner), etc. optional; an arm needs the body, a pose forearm needs its arm, and a partial lip set, one mixed with mouth/mouth_open, or mouth_tongue/mouth_teeth without it is refused) into a renderable .iki written to disk. Pass full-canvas PNG file paths; returns the output path + summary (the model is NOT inlined). Filenames map to roles unless `fileName` is given. The result's `folds` is the written rig's fold report, printed after the path the way render_poses prints it, and report-only: a fold never refuses the rig. The `PHYSICS` lines follow the fold report (the result's `physics`), one per physics rig output \u2014 a spring's, or each chain segment's \u2014 reading ok, frozen or unstable with the step and idle amplitudes, or `PHYSICS: no rigs`; report-only too. `patches` (see its field) adds displacements to existing keyform stops of the freshly generated rig; each op then prints one line between the path and the fold report \u2014 `PATCH <i> <target> at <Param=v \u2026>: <moved> of <of> points (cols a-b, rows c-d), largest move <maxPx> model px`, with `(vertices)` in place of the columns and rows for a mesh part \u2014 and the result's `patches` carries the same reports (`index`, `target`, `at`, `moved`, `of`, `cols`/`rows` for a grid, `maxPx`), present whenever `patches` was passed, `[]` included. An op the input schema accepts but the rig refuses comes back as `INVALID: patches[i]\u2026` and nothing is written; an op with a missing field or a field of the wrong type is the SDK's input validation error.",
6247
+ description: "Auto-rigs role-named PNG layers (face, eye_L/eye_R and either mouth or the lip set (mouth_inner + lip_lower + lip_upper, a mouth that folds open instead of crossfading) required; iris_L/R, brow_L/R, hair_front, body, arm_L/arm_R, forearm_pose_L/forearm_pose_R, mouth_tongue/mouth_teeth (only with the lip set: drawn under its lips and clipped to mouth_inner), etc. optional; an arm needs the body, a pose forearm needs its arm, and a partial lip set, one mixed with mouth/mouth_open, or mouth_tongue/mouth_teeth without it is refused) into a renderable .iki written to disk. Pass full-canvas PNG file paths; returns the output path + summary (the model is NOT inlined). Filenames map to roles unless `fileName` is given. The result's `folds` is the written rig's fold report, printed after the path the way render_poses prints it, and report-only: a fold never refuses the rig. The `RIGPLAN:` line (the result's `rigPlan`: `effective`, `clamped`, `overriddenBy`) follows the path and precedes the `PATCH` lines. The `PHYSICS` lines follow the fold report (the result's `physics`), one per physics rig output \u2014 a spring's, or each chain segment's \u2014 reading ok, frozen or unstable with the step and idle amplitudes, or `PHYSICS: no rigs`; report-only too. `patches` (see its field) adds displacements to existing keyform stops of the freshly generated rig; each op then prints one line between the path and the fold report \u2014 `PATCH <i> <target> at <Param=v \u2026>: <moved> of <of> points (cols a-b, rows c-d), largest move <maxPx> model px`, with `(vertices)` in place of the columns and rows for a mesh part \u2014 and the result's `patches` carries the same reports (`index`, `target`, `at`, `moved`, `of`, `cols`/`rows` for a grid, `maxPx`), present whenever `patches` was passed, `[]` included. An op the input schema accepts but the rig refuses comes back as `INVALID: patches[i]\u2026` and nothing is written; an op with a missing field or a field of the wrong type is the SDK's input validation error.",
5750
6248
  inputSchema: {
5751
6249
  layers: import_zod.z.array(
5752
6250
  import_zod.z.object({
@@ -5771,15 +6269,24 @@ function createIkiMcpServer() {
5771
6269
  }).passthrough().optional().describe(
5772
6270
  "What the head turn is fitted to, as `measure_turn_reference` reports it off a front/turned reference pair. `eyeShift` (and the optional `noseShift`/`mouthShift`) is how far that feature slides across the head at full turn, as a fraction of the head's half-width \u2014 a MAGNITUDE: the rig turns both ways, so the sign is ignored. `farEyeRatio` is the far/near eye width at full turn over that same ratio at rest, `silhouetteRatio` the head's half-width turned over at rest. The half-width the shifts are fractions of is measured off the layers themselves, so it is not an input. An omitted field leaves that part of the turn at the profile the rig defaults to. A passed `eyeShift` is fitted by the turn's amount and clamped to the room the art leaves the far eye \u2014 the face plate's edge, or the bangs' side strand over the far iris (the result's `turn.clamped` lists every clamped field, `turn.achieved` what the rig reaches, and `turn.strandOverlap` how much of a far iris the bangs still cover). A passed `silhouetteRatio` is clamped too, only on a face drawn without hair and with ear islands, where narrowing the head that far would no longer cover the far ear's slide. Any other passed target this layer set cannot reach comes back as `INVALID: \u2026` naming the field and the attainable range, since it is a measurement rather than a preference. A field not named here is refused the same way."
5773
6271
  ),
5774
- style: import_zod.z.object({
5775
- turn: import_zod.z.number().optional(),
5776
- featureLead: import_zod.z.number().optional(),
5777
- hairFollow: import_zod.z.number().optional(),
5778
- outlineFollow: import_zod.z.number().optional(),
5779
- blink: import_zod.z.number().optional(),
5780
- sway: import_zod.z.number().optional()
6272
+ style: import_zod.z.unknown().optional().describe(
6273
+ "Removed in @ikijs/mcp 0.30.0: pass `rigPlan`. Any value here is refused with the field map."
6274
+ ),
6275
+ rigPlan: import_zod.z.object({
6276
+ turn: import_zod.z.object({
6277
+ amount: import_zod.z.number().optional(),
6278
+ featureLead: import_zod.z.number().optional(),
6279
+ eyeForeshorten: import_zod.z.number().optional(),
6280
+ noseLead: import_zod.z.number().optional()
6281
+ }).passthrough().optional(),
6282
+ hair: import_zod.z.object({
6283
+ follow: import_zod.z.number().optional(),
6284
+ outlineFollow: import_zod.z.number().optional(),
6285
+ sway: import_zod.z.number().optional()
6286
+ }).passthrough().optional(),
6287
+ eyes: import_zod.z.object({ blink: import_zod.z.number().optional() }).passthrough().optional()
5781
6288
  }).passthrough().optional().describe(
5782
- "Per-character tuning from the profile the rig defaults to: `turn` scales the whole head turn (plate, features, hair and the eyes' foreshortening; 0..3, 1 = the profile; ignored when `turnTargets.eyeShift` is given), `featureLead` how far the features lead the face plate (0..3, 1 = the profile), `hairFollow` the front hair's share of the face's turn (0..2, profile 1), `outlineFollow` its outer edge's share where the front hair draws the head's outline (0..2, profile 0: the outline holds), `blink` how far the upper lid comes down over the eye's height (0.1..1, profile 0.6), `sway` the hair sway amplitude (0..5, 1 = the profile). A value out of range, or a knob not named here, comes back as `INVALID: \u2026`."
6289
+ "Per-character tuning from the profile the rig defaults to, in three groups: `turn` (`amount`, `featureLead`, `eyeForeshorten`, `noseLead`: the last two turn only, the nod untouched, and fitted by `turnTargets.farEyeRatio` / `turnTargets.noseShift` when those are given, which the `RIGPLAN:` line then reports as overridden), `hair` (`follow`, `outlineFollow`, `sway`) and `eyes` (`blink`). `describe_rig_plan` lists every field's default, range, recommended span, step and poses. A value out of range, or a group or key not named there, comes back as `INVALID: rigPlan.<path> \u2026`; an object left out or `{}` is the profile. The result reports what the rig built with as `rigPlan` and a `RIGPLAN:` line."
5783
6290
  ),
5784
6291
  patches: import_zod.z.array(
5785
6292
  import_zod.z.object({
@@ -5797,7 +6304,7 @@ function createIkiMcpServer() {
5797
6304
  why: import_zod.z.string().optional()
5798
6305
  }).passthrough()
5799
6306
  ).optional().describe(
5800
- "Displacements ADDED to EXISTING keyform stops of the freshly generated rig, each op `{ target, at, region, by, falloff?, why? }`. They are replayed on every rig of these inputs, over whatever the rig now bakes, so they hold through a layout or `style` retune; ops on one stop add up, whatever their order. `target` is a feature grid \u2014 `eyeWarp_L`, `eyeWarp_R`, `browWarp_L`, `browWarp_R`, `noseWarp`, `mouthWarp`, whose `at` names both `ParamAngleX` and `ParamAngleY`, each -30, 0 or 30, never both 0 \u2014 or a mesh part with warps (`face`, `hair_front`, \u2026), whose `at` names exactly one parameter at one of that part's warp keyform values, never the parameter's default nor the stop where the rig shuts the part on purpose (`eye_*` and `lash_lower_*` at their `ParamEye*Open` 0, the lip set and its tongue and teeth at `ParamMouthOpenY` 0), which the fold check exempts, nor a `ParamAngleZ` or `ParamBodyAngleZ` stop (they roll the deformers the part hangs under, so a displacement there is turned off the screen axes). The rest pose is the drawn art and no patch changes it. `bodyWarp` and the matrix deformers are not targets, and a patch adds no stop and changes no parameter range. `region` `{ role, x: [from, to], y: [from, to] }` is a rectangle in fractions of the REST layer box (the opaque crop) of `role`, origin top-left, x right, y DOWN, and may reach past the box: the target's points whose REST position lies inside take the whole of `by`, those within `falloff` of it a smooth share, the rest nothing. `by` `{ dx, dy }` and `falloff` are in face widths (the `face` layer's crop width), on screen axes: +dx toward the viewer's right (a character's `_L` side), +dy DOWN. Between stops the engine blends linearly, so a fix at ParamAngleX -30 shows at half strength at -15 and none at rest. `why` is a note the rig ignores. An op this schema accepts but the rig refuses \u2014 an unknown key, target, role or stop, the rest stop or a shut stop, a region running backwards or catching none of the target's points \u2014 comes back as `INVALID: patches[i]\u2026`, listing the keys, targets, stops or roles there are, or where the target's points lie in the role's box, and nothing is written; a missing field or one of the wrong type is refused by the schema itself, as the SDK's input validation error."
6307
+ "Displacements ADDED to EXISTING keyform stops of the freshly generated rig, each op `{ target, at, region, by, falloff?, why? }`. They are replayed on every rig of these inputs, over whatever the rig now bakes, so they hold through a layout or `rigPlan` retune; ops on one stop add up, whatever their order. `target` is a feature grid \u2014 `eyeWarp_L`, `eyeWarp_R`, `browWarp_L`, `browWarp_R`, `noseWarp`, `mouthWarp`, whose `at` names both `ParamAngleX` and `ParamAngleY`, each -30, 0 or 30, never both 0 \u2014 or a mesh part with warps (`face`, `hair_front`, \u2026), whose `at` names exactly one parameter at one of that part's warp keyform values, never the parameter's default nor the stop where the rig shuts the part on purpose (`eye_*` and `lash_lower_*` at their `ParamEye*Open` 0, the lip set and its tongue and teeth at `ParamMouthOpenY` 0), which the fold check exempts, nor a `ParamAngleZ` or `ParamBodyAngleZ` stop (they roll the deformers the part hangs under, so a displacement there is turned off the screen axes). The rest pose is the drawn art and no patch changes it. `bodyWarp` and the matrix deformers are not targets, and a patch adds no stop and changes no parameter range. `region` `{ role, x: [from, to], y: [from, to] }` is a rectangle in fractions of the REST layer box (the opaque crop) of `role`, origin top-left, x right, y DOWN, and may reach past the box: the target's points whose REST position lies inside take the whole of `by`, those within `falloff` of it a smooth share, the rest nothing. `by` `{ dx, dy }` and `falloff` are in face widths (the `face` layer's crop width), on screen axes: +dx toward the viewer's right (a character's `_L` side), +dy DOWN. Between stops the engine blends linearly, so a fix at ParamAngleX -30 shows at half strength at -15 and none at rest. `why` is a note the rig ignores. An op this schema accepts but the rig refuses \u2014 an unknown key, target, role or stop, the rest stop or a shut stop, a region running backwards or catching none of the target's points \u2014 comes back as `INVALID: patches[i]\u2026`, listing the keys, targets, stops or roles there are, or where the target's points lie in the role's box, and nothing is written; a missing field or one of the wrong type is refused by the schema itself, as the SDK's input validation error."
5801
6308
  )
5802
6309
  }
5803
6310
  },
@@ -5811,6 +6318,7 @@ function createIkiMcpServer() {
5811
6318
  });
5812
6319
  const text = r.ok ? [
5813
6320
  r.path,
6321
+ formatRigPlanReport(r.rigPlan),
5814
6322
  ...formatPatchReports(r.patches ?? []),
5815
6323
  ...formatFoldReport(r.folds, r.canvas),
5816
6324
  ...formatPhysicsReport(r.physics)
@@ -5942,7 +6450,7 @@ function createIkiMcpServer() {
5942
6450
  server.registerTool(
5943
6451
  "render_poses",
5944
6452
  {
5945
- description: "Renders a rigged .iki into the character loop's pose PNGs with the real engine, through the installed Chrome, Edge or Chromium run headless (set CHROME_PATH to pick one). The model decides the set: a bust gets 560x560 shots (rest, turns, nod, blinks, gaze, combined \u2014 ParamAngleX/Y/Z all at 30 \u2014 and stress: ParamAngleX/Y/Z all at -30, ParamMouthOpenY 1, both eyes at 0.5, the brows at opposite extremes (ParamBrowLY -1, ParamBrowRY 1, ParamBrowLAngle 1, ParamBrowRAngle -1) and each body angle the model declares at -10); a mouth adds 720x480 mouth crops; a full body (taller than wide) adds the full-canvas body, arm and elbow poses on a 1400-wide canvas, and a model with a pose forearm adds the full-pose-* shots. Given `poses` (see its field), the standard set is not rendered: only those poses are, each crop clamped to the model's canvas. Writes <pose>.png files into outDir, overwriting same-named files in place; returns the written paths one per line, then the model's fold report (the result's `folds`), checked by the engine over its own pose set plus any `poses`, each of which a `FOLD` line names by its settings, not its PNG name: a `FOLD` line per warp deformer or mesh part that flips (ratio <= 0) or collapses (under 0.1) at some pose \u2014 its cell or triangle, the ratio of its area there to at rest, the pose as its parameter settings (`rest` for none) and where it rests, in model space and in model px from the top-left (the layer PNGs' own pixels, not a render's) \u2014 or `FOLDS: none over N poses`, then a `FOLDS expected:` line naming the closures the rig draws on purpose (an eye or the mouth shut), each by part id, ratio and the parameter that shuts it. Report-only: a fold never fails the render. The `PHYSICS` lines follow the fold report (the result's `physics`), one per physics rig output of the model's own rigs \u2014 `poses` do not enter it \u2014 reading ok, frozen or unstable with the step and idle amplitudes, or `PHYSICS: no rigs`; report-only too. Fails with INVALID when no browser is found or an input is refused; a browser that cannot start is a tool error.",
6453
+ description: "Renders a rigged .iki into the character loop's pose PNGs with the real engine, through the installed Chrome, Edge or Chromium run headless (set CHROME_PATH to pick one). The model decides the set: a bust gets 560x560 shots (rest, turns, nod, blinks, gaze, combined \u2014 ParamAngleX/Y/Z all at 30 \u2014 and stress: ParamAngleX/Y/Z all at -30, ParamMouthOpenY 1, both eyes at 0.5, the brows at opposite extremes (ParamBrowLY -1, ParamBrowRY 1, ParamBrowLAngle 1, ParamBrowRAngle -1) and each body angle the model declares at -10); a mouth adds 720x480 mouth crops; a full body (taller than wide) adds the full-canvas body, arm and elbow poses on a 1400-wide canvas, and a model with a pose forearm adds the full-pose-* shots. Given `poses` (see its field), the standard set is not rendered: only those poses are, each crop clamped to the model's canvas. Writes <pose>.png files into outDir, overwriting same-named files in place; returns the written paths one per line, then the model's fold report (the result's `folds`), checked by the engine over its own pose set plus any `poses`, each of which a `FOLD` line names by its settings, not its PNG name: a `FOLD` line per warp deformer or mesh part that flips (ratio <= 0) or collapses (under 0.1) at some pose \u2014 its cell or triangle, the ratio of its area there to at rest, the pose as its parameter settings (`rest` for none) and where it rests, in model space and in model px from the top-left (the layer PNGs' own pixels, not a render's) \u2014 or `FOLDS: none over N poses`, then a `FOLDS expected:` line naming the closures the rig draws on purpose (an eye or the mouth shut), each by part id, ratio and the parameter that shuts it. Report-only: a fold never fails the render. The `PHYSICS` lines follow the fold report (the result's `physics`), one per physics rig output of the model's own rigs \u2014 `poses` do not enter it \u2014 reading ok, frozen or unstable with the step and idle amplitudes, or `PHYSICS: no rigs`; report-only too. Given `sweep`, also renders an eased turn of the head (see its field) and prints its paths and `SWEEP` lines. Fails with INVALID when no browser is found or an input is refused; a browser that cannot start is a tool error.",
5946
6454
  inputSchema: {
5947
6455
  modelPath: import_zod.z.string().describe(
5948
6456
  "Rigged .iki file path (resolved against cwd; must sit under the working directory)."
@@ -5963,6 +6471,18 @@ function createIkiMcpServer() {
5963
6471
  })
5964
6472
  ).optional().describe(
5965
6473
  "Caller-named poses rendered INSTEAD of the standard set, each `{ name, values, crop? }`, in order. `name` becomes `<outDir>/<name>.png` and the result's pose name: letters, digits, `_`, `.` and `-` only, unique in the list ignoring case. `values` are parameter settings (every other parameter at its default; an id the model lacks is ignored). `crop` `{ x, y, w, h }` is a rectangle in model px from the top-left \u2014 the frame of describe_iki's boxes and of the `FOLD` lines \u2014 clamped to the model's canvas, then drawn 720 px wide at its own aspect; without one a pose is framed as the standard shots (560x560, the middle square on a full body). Each pose is also added to the fold sweep, after the engine's own poses. An empty list, a bad or repeated name, a non-finite value, or a crop that misses the canvas or would draw under 1 or over 8192 px tall comes back as `INVALID: poses\u2026` and nothing is rendered."
6474
+ ),
6475
+ sweep: import_zod.z.object({
6476
+ name: import_zod.z.string(),
6477
+ preset: import_zod.z.literal("turn"),
6478
+ crop: import_zod.z.object({
6479
+ x: import_zod.z.number(),
6480
+ y: import_zod.z.number(),
6481
+ w: import_zod.z.number(),
6482
+ h: import_zod.z.number()
6483
+ }).optional()
6484
+ }).optional().describe(
6485
+ "A turn sweep rendered IN ADDITION to the poses, `{ name, preset: \"turn\", crop? }`: an eased `ParamAngleX` turn (0 to -30 to +30 to 0 over 3 s, sinusoidal) at 30 fps on a 60 Hz physics clock, with the hair physics running and the idle off, every other parameter at its default. `crop` is a rectangle in model px as a pose's, fixed for every frame; without one the frames are framed as the standard shots. Written into `<outDir>/<name>/` (created; `name` starts with a letter or digit, then letters, digits, `_`, `.`, `-`): `fNNN.png` (90 frames), `manifest.json` (each frame's time, angle and effective values), `sheet.png` (nine frames of the -30 to +30 leg, labelled with angle and time, at most 2000 px a side), `kymograph.png` (the eye row of every frame stacked over time), `index.html` (a flipbook to open from disk; add `?b=<relative dir of another sweep>` for two side by side). The text then lists the paths and, after the `PHYSICS` lines, a `SWEEP turn` line per landmark (eyes, nose) from the engine's geometry: amplitude in face widths, the kink of x and of the eye width through angle 0, the lead over the local face plate at each end, and the pop \u2014 report-only, like `FOLD` and `PHYSICS`."
5966
6486
  )
5967
6487
  }
5968
6488
  },
@@ -5971,8 +6491,16 @@ function createIkiMcpServer() {
5971
6491
  const r = await renderPoses(args);
5972
6492
  const text = r.ok ? [
5973
6493
  ...r.poses.map((p) => p.path),
6494
+ ...r.sweep ? [
6495
+ r.sweep.dir,
6496
+ r.sweep.sheet,
6497
+ r.sweep.kymograph,
6498
+ r.sweep.flipbook,
6499
+ r.sweep.manifest
6500
+ ] : [],
5974
6501
  ...formatFoldReport(r.folds, r.modelCanvas),
5975
- ...formatPhysicsReport(r.physics)
6502
+ ...formatPhysicsReport(r.physics),
6503
+ ...r.sweep ? formatSweepReport(r.sweep.report) : []
5976
6504
  ].join("\n") : `INVALID: ${r.error}`;
5977
6505
  return { content: [{ type: "text", text }], structuredContent: r };
5978
6506
  } catch (err) {