cozyclay 1.1.0 → 1.3.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/CHANGELOG.md +85 -0
- package/README.md +91 -25
- package/THIRD_PARTY_NOTICES.md +68 -1
- package/bin/cozyclay.mjs +71 -8
- package/dist/CNAME +1 -0
- package/dist/ai-camera-control/index.html +406 -0
- package/dist/app/index.html +57 -0
- package/dist/assets/app-B3U5aut1.js +4811 -0
- package/dist/assets/app-BrRF0wso.css +1 -0
- package/dist/assets/vision_bundle-jFkh-fIS.js +41 -0
- package/dist/favicon.ico +0 -0
- package/dist/fonts/InstrumentSerif-OFL.txt +93 -0
- package/dist/fonts/Inter-OFL.txt +92 -0
- package/dist/fonts/README.md +15 -0
- package/dist/icons/apple-touch-icon.png +0 -0
- package/dist/icons/icon-192.png +0 -0
- package/dist/icons/icon-32.png +0 -0
- package/dist/icons/icon-512.png +0 -0
- package/dist/icons/icon-maskable-512.png +0 -0
- package/dist/index.html +450 -5
- package/dist/manifest.webmanifest +42 -0
- package/dist/media/cozyclay-demo-poster.jpg +0 -0
- package/dist/media/cozyclay-logo.png +0 -0
- package/dist/robots.txt +4 -0
- package/dist/sitemap.xml +15 -0
- package/dist/sw.js +127 -0
- package/mcp/LIVE-PROTOCOL.md +63 -0
- package/mcp/README.md +142 -0
- package/mcp/ardy-prompts.mjs +170 -0
- package/mcp/live-hub.mjs +105 -0
- package/mcp/package.json +24 -0
- package/mcp/server.mjs +1394 -0
- package/package.json +122 -78
- package/src/App.jsx +4235 -1047
- package/src/ardy/client.js +5 -4
- package/src/ardy/cskel27.js +7 -2
- package/src/ardy/ik.js +25 -15
- package/src/ardy/mp4-duration.js +102 -0
- package/src/ardy/npz.js +64 -3
- package/src/ardy/playback.js +31 -1
- package/src/ardy/prompt-clips.js +7 -2
- package/src/ardy/retime.js +211 -0
- package/src/ardy/timeline-coordinates.js +24 -0
- package/src/ardy/timeline.jsx +650 -70
- package/src/ardy/to-cskel27.js +34 -12
- package/src/ardy/trim.js +33 -0
- package/src/ardy/waypoints.js +14 -9
- package/src/asset-pane.jsx +36 -0
- package/src/camera-block.js +60 -0
- package/src/camera-follow.js +49 -10
- package/src/camera-rail-schedule.js +176 -0
- package/src/controls.jsx +16 -2
- package/src/cuts.js +184 -0
- package/src/dualview.jsx +14 -8
- package/src/generation/client.js +56 -0
- package/src/generation/session.js +47 -0
- package/src/generation/shot-spec.js +40 -0
- package/src/generation/use-generation.js +55 -0
- package/src/hierarchy-model.js +104 -30
- package/src/hierarchy-panel.jsx +306 -26
- package/src/live-control.js +122 -0
- package/src/locale-toggle.jsx +18 -0
- package/src/locale.js +34 -0
- package/src/main.jsx +5 -0
- package/src/matte-editor.js +543 -0
- package/src/matte.js +503 -0
- package/src/multimodel-ingest.js +344 -0
- package/src/object-catalog.jsx +32 -3
- package/src/object-gizmo.jsx +43 -15
- package/src/planview.jsx +208 -89
- package/src/pose-extract/browser.js +42 -0
- package/src/pose-extract/detector.js +75 -0
- package/src/pose-extract/fit.js +194 -0
- package/src/pose-extract/index.js +56 -0
- package/src/pose-extract/keyframes.js +74 -0
- package/src/pose-extract/landmarks.js +162 -0
- package/src/pose-extract/take.js +87 -0
- package/src/pose-extract/video-frames.js +91 -0
- package/src/pose-thumbs.js +152 -0
- package/src/poses.js +114 -0
- package/src/posestudio.jsx +434 -22
- package/src/project-browser.jsx +135 -0
- package/src/project.js +289 -0
- package/src/props.jsx +69 -3
- package/src/pwa.js +42 -0
- package/src/result-modal.jsx +124 -0
- package/src/room.jsx +14 -35
- package/src/scene-asset-cache.js +125 -0
- package/src/scene-assets.js +288 -0
- package/src/scene-objects.js +245 -7
- package/src/scenes.js +404 -0
- package/src/shot-authoring.js +246 -77
- package/src/shot.js +8 -4
- package/src/styles.css +2151 -183
- package/src/ui.jsx +54 -5
- package/tools/ardy/BRIDGE.md +73 -6
- package/tools/ardy/README.md +64 -5
- package/tools/ardy/bridge.mjs +146 -390
- package/tools/ardy/bvh-cskel27.mjs +1209 -0
- package/tools/ardy/cclay_constrained_generate.py +561 -0
- package/tools/ardy/cclay_motion_edit.py +74 -9
- package/tools/ardy/cclay_sequence_generate.py +117 -7
- package/tools/ardy/cclay_worker.py +304 -0
- package/tools/ardy/extract.mjs +367 -0
- package/tools/ardy/footage.mjs +462 -0
- package/tools/ardy/merge-text-encoder.py +160 -0
- package/tools/ardy/npz.mjs +74 -9
- package/tools/ardy/run-local.mjs +233 -0
- package/tools/ardy/run-on-box.sh +25 -0
- package/tools/ardy/run-sequence-on-box.sh +15 -0
- package/tools/ardy/runners/index.mjs +23 -0
- package/tools/ardy/runners/local.mjs +452 -0
- package/tools/ardy/runners/proc.mjs +125 -0
- package/tools/ardy/runners/remote.mjs +252 -0
- package/tools/ardy/setup-local.mjs +189 -0
- package/tools/ardy/setup-text-encoder-on-box.sh +93 -0
- package/tools/ardy/setup-text-encoder.py +296 -0
- package/tools/generation/README.md +29 -0
- package/tools/generation/bridge.mjs +149 -0
- package/tools/generation/job-store.mjs +51 -0
- package/tools/generation/providers/kling.mjs +76 -0
- package/tools/generation/providers/runway.mjs +101 -0
- package/tools/generation/providers/seedance.mjs +87 -0
- package/tools/generation/providers/shared.mjs +49 -0
- package/tools/generation/providers/veo.mjs +84 -0
- package/tools/metrics/archive-traffic.mjs +138 -0
- package/dist/assets/index-BW_S1YRy.js +0 -4395
- package/dist/assets/index-nRmmJgap.css +0 -1
- package/tools/ardy/__pycache__/cclay_sequence_generate.cpython-313.pyc +0 -0
- package/tools/ardy/out/gen-1786443326924-c6019e-generated.npz +0 -0
- package/tools/ardy/out/gen-1786443609325-0053db-generated.npz +0 -0
- package/tools/ardy/out/gen-1786443835628-749ed1-generated.npz +0 -0
- package/tools/ardy/out/gen-1786462605247-03cb19-generated.npz +0 -0
- package/tools/qa-browser.mjs +0 -84
- package/tools/qa-crop3.mjs +0 -22
- package/tools/qa-playview.mjs +0 -49
- package/tools/qa-screenshot.mjs +0 -24
- package/tools/qa-visual.mjs +0 -51
package/tools/ardy/npz.mjs
CHANGED
|
@@ -13,8 +13,9 @@
|
|
|
13
13
|
* runs its own FK. poseArraysToNpzMembers turns one CozyClay frame into
|
|
14
14
|
* that exact 1-frame member set, so a hand-blocked pose can be materialized
|
|
15
15
|
* as a standalone npz without ever hardcoding a rest skeleton: proportions
|
|
16
|
-
* come from the base clip (deriveBoneOffsets)
|
|
17
|
-
*
|
|
16
|
+
* come from the base clip (deriveBoneOffsets), the 8 joints CozyClay does not
|
|
17
|
+
* author stay IDENTITY, and an optional int32 rotation mask prevents those
|
|
18
|
+
* identity placeholders from becoming rotation constraints.
|
|
18
19
|
*/
|
|
19
20
|
import { writeFileSync } from "node:fs";
|
|
20
21
|
|
|
@@ -199,8 +200,12 @@ export function writeNpz(path, arrays) {
|
|
|
199
200
|
* is the frames axis, so the generator's `[frame]` / `[frame, root_idx]`
|
|
200
201
|
* indexing works unchanged.
|
|
201
202
|
*/
|
|
202
|
-
export function poseArraysToNpzMembers({
|
|
203
|
-
|
|
203
|
+
export function poseArraysToNpzMembers({
|
|
204
|
+
local_rot_mats,
|
|
205
|
+
posed_joints,
|
|
206
|
+
rotation_constraint_indices,
|
|
207
|
+
}) {
|
|
208
|
+
const members = {
|
|
204
209
|
local_rot_mats: {
|
|
205
210
|
data: flattenToF32(local_rot_mats, [27, 3, 3], "local_rot_mats"),
|
|
206
211
|
shape: [1, 27, 3, 3],
|
|
@@ -210,6 +215,23 @@ export function poseArraysToNpzMembers({ local_rot_mats, posed_joints }) {
|
|
|
210
215
|
shape: [1, 27, 3],
|
|
211
216
|
},
|
|
212
217
|
};
|
|
218
|
+
if (rotation_constraint_indices !== undefined) {
|
|
219
|
+
if (
|
|
220
|
+
!Array.isArray(rotation_constraint_indices) ||
|
|
221
|
+
rotation_constraint_indices.some(
|
|
222
|
+
(index) => !Number.isInteger(index) || index < 0 || index >= 27
|
|
223
|
+
)
|
|
224
|
+
) {
|
|
225
|
+
throw new Error(
|
|
226
|
+
"poseArraysToNpzMembers: rotation_constraint_indices must contain joint indices in 0..26"
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
members.rotation_constraint_indices = {
|
|
230
|
+
data: Int32Array.from(rotation_constraint_indices),
|
|
231
|
+
shape: [rotation_constraint_indices.length],
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
return members;
|
|
213
235
|
}
|
|
214
236
|
|
|
215
237
|
/**
|
|
@@ -247,8 +269,23 @@ function flattenToF32(value, dims, name) {
|
|
|
247
269
|
}
|
|
248
270
|
|
|
249
271
|
|
|
250
|
-
/**
|
|
251
|
-
|
|
272
|
+
/**
|
|
273
|
+
* Convert decoded ARDY motion arrays into writer members.
|
|
274
|
+
*
|
|
275
|
+
* `personScale` (the filmed performer's leg length as a fraction of the
|
|
276
|
+
* canonical body, from bvhToCskel27Motion) is written as a `person_scale`
|
|
277
|
+
* scalar when the source estimated one. It has to live IN the archive: the
|
|
278
|
+
* conversion already divided the root translation by it, so the trajectory is
|
|
279
|
+
* only metrically right once the character is scaled by the same number. A
|
|
280
|
+
* take whose stature travelled separately from its frames replays a filmed
|
|
281
|
+
* stride at canonical size and skates the feet.
|
|
282
|
+
*
|
|
283
|
+
* The member is APPENDED and only when present: an ARDY-generated take has no
|
|
284
|
+
* filmed performer, so its archive stays byte-identical to before, and a
|
|
285
|
+
* reader that ignores the extra member (numpy, dump-npz.py, the generators)
|
|
286
|
+
* sees the original four unchanged and in the original order.
|
|
287
|
+
*/
|
|
288
|
+
export function motionArraysToNpzMembers({ frames, fps, rotMats, rootPos, posedJoints, personScale }) {
|
|
252
289
|
if (!Number.isInteger(frames) || frames < 1) throw new Error("motionArraysToNpzMembers: frames must be positive");
|
|
253
290
|
if (!Number.isInteger(fps) || fps < 1) throw new Error("motionArraysToNpzMembers: fps must be positive");
|
|
254
291
|
const requireLength = (array, length, label) => {
|
|
@@ -259,12 +296,27 @@ export function motionArraysToNpzMembers({ frames, fps, rotMats, rootPos, posedJ
|
|
|
259
296
|
requireLength(rotMats, frames * 27 * 9, "rotMats");
|
|
260
297
|
requireLength(rootPos, frames * 3, "rootPos");
|
|
261
298
|
requireLength(posedJoints, frames * 27 * 3, "posedJoints");
|
|
262
|
-
|
|
299
|
+
const members = {
|
|
263
300
|
local_rot_mats: { data: rotMats, shape: [frames, 27, 3, 3] },
|
|
264
301
|
root_positions: { data: rootPos, shape: [frames, 3] },
|
|
265
302
|
posed_joints: { data: posedJoints, shape: [frames, 27, 3] },
|
|
266
303
|
fps: { data: Int32Array.of(fps), shape: [] },
|
|
267
304
|
};
|
|
305
|
+
if (personScale !== undefined && personScale !== null) {
|
|
306
|
+
if (!Number.isFinite(personScale) || personScale <= 0) {
|
|
307
|
+
throw new Error(
|
|
308
|
+
`motionArraysToNpzMembers: personScale must be a positive finite number, got ${personScale}`
|
|
309
|
+
);
|
|
310
|
+
}
|
|
311
|
+
// 1 is the canonical body — the reader's own default — so recording it
|
|
312
|
+
// would add a member that says nothing. Keeping it out means a
|
|
313
|
+
// generated take that passes through a decode/edit/rewrite round trip
|
|
314
|
+
// (bridge.mjs's motion edit reads person_scale back as 1) still writes
|
|
315
|
+
// the same four members it always did.
|
|
316
|
+
// float32 scalar, same 0-d shape convention as fps.
|
|
317
|
+
if (personScale !== 1) members.person_scale = { data: Float32Array.of(personScale), shape: [] };
|
|
318
|
+
}
|
|
319
|
+
return members;
|
|
268
320
|
}
|
|
269
321
|
|
|
270
322
|
/** Concatenate contiguous, already world-aligned generated blocks. */
|
|
@@ -276,6 +328,13 @@ export function stitchMotionSegments(segments) {
|
|
|
276
328
|
if (!segments.every((segment) => segment.fps === fps)) {
|
|
277
329
|
throw new Error("stitchMotionSegments: every segment must use the same fps");
|
|
278
330
|
}
|
|
331
|
+
// One performer per stitch: the segments are consecutive blocks of the same
|
|
332
|
+
// body, so two different statures here means two different people were
|
|
333
|
+
// concatenated into one trajectory and the travel of at least one is wrong.
|
|
334
|
+
const scales = new Set(segments.map((segment) => segment.personScale).filter((value) => Number.isFinite(value)));
|
|
335
|
+
if (scales.size > 1) {
|
|
336
|
+
throw new Error("stitchMotionSegments: segments disagree on personScale");
|
|
337
|
+
}
|
|
279
338
|
const frames = segments.reduce((sum, segment) => sum + segment.frames, 0);
|
|
280
339
|
const concat = (key, stride) => {
|
|
281
340
|
const out = new Float32Array(frames * stride);
|
|
@@ -290,13 +349,15 @@ export function stitchMotionSegments(segments) {
|
|
|
290
349
|
}
|
|
291
350
|
return out;
|
|
292
351
|
};
|
|
293
|
-
|
|
352
|
+
const stitched = {
|
|
294
353
|
frames,
|
|
295
354
|
fps,
|
|
296
355
|
rotMats: concat("rotMats", 27 * 9),
|
|
297
356
|
rootPos: concat("rootPos", 3),
|
|
298
357
|
posedJoints: concat("posedJoints", 27 * 3),
|
|
299
358
|
};
|
|
359
|
+
if (scales.size === 1) stitched.personScale = [...scales][0];
|
|
360
|
+
return stitched;
|
|
300
361
|
}
|
|
301
362
|
|
|
302
363
|
/** Return a copy of a motion with one equal-fps replacement written at startFrame. */
|
|
@@ -325,11 +386,15 @@ export function replaceMotionSegment(base, replacement, startFrame) {
|
|
|
325
386
|
out.set(patch, startFrame * stride);
|
|
326
387
|
return out;
|
|
327
388
|
};
|
|
328
|
-
|
|
389
|
+
const edited = {
|
|
329
390
|
frames: base.frames,
|
|
330
391
|
fps: base.fps,
|
|
331
392
|
rotMats: copyAndReplace("rotMats", 27 * 9),
|
|
332
393
|
rootPos: copyAndReplace("rootPos", 3),
|
|
333
394
|
posedJoints: copyAndReplace("posedJoints", 27 * 3),
|
|
334
395
|
};
|
|
396
|
+
// The base clip is still the same body after an edited span is written into
|
|
397
|
+
// it, and its root travel is still expressed against that stature.
|
|
398
|
+
if (Number.isFinite(base.personScale)) edited.personScale = base.personScale;
|
|
399
|
+
return edited;
|
|
335
400
|
}
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* run-local.mjs - generate an ARDY clip on THIS machine.
|
|
4
|
+
*
|
|
5
|
+
* run-local.mjs single [--pose-from NPZ SRC DST]... --prompt P --duration S
|
|
6
|
+
* [--seed N] [--root-2d F X Z H]... --output OUT.npz
|
|
7
|
+
* run-local.mjs sequence --segment PROMPT SECONDS [--segment ...]...
|
|
8
|
+
* [--root-2d F X Z H]... [--seed N] --output OUT.npz
|
|
9
|
+
* run-local.mjs edit --source SRC.npz --manifest M.json --prompt P
|
|
10
|
+
* --context-before N --context-after N [--seed N]
|
|
11
|
+
* [--pose POSE.npz]... --output OUT.npz
|
|
12
|
+
*
|
|
13
|
+
* The local twin of run-on-box.sh / run-sequence-on-box.sh /
|
|
14
|
+
* run-edit-on-box.sh: same modes, same success marker
|
|
15
|
+
*
|
|
16
|
+
* run-local: done - <output> (<bytes> bytes)
|
|
17
|
+
*
|
|
18
|
+
* minus every ssh/scp/temp-dir round trip — the generator scripts run in
|
|
19
|
+
* place from this repo against the ARDY checkout's venv. Device selection
|
|
20
|
+
* lives in the python side (cclay_pick_device: CCLAY_ARDY_DEVICE override,
|
|
21
|
+
* else cuda > mps > cpu). The text encoder is the bridge's lazy sidecar; a
|
|
22
|
+
* dead encoder degrades to ARDY's in-process fallback rather than failing.
|
|
23
|
+
*
|
|
24
|
+
* env (set by runners/local.mjs; usable standalone too):
|
|
25
|
+
* CCLAY_ARDY_LOCAL_DIR ARDY checkout (default ~/.cozyclay/ardy)
|
|
26
|
+
* CCLAY_ARDY_LOCAL_VENV venv python (default <dir>/.venv/bin/python)
|
|
27
|
+
* TEXT_ENCODER_URL encoder service (default http://127.0.0.1:9550/)
|
|
28
|
+
* TEXT_ENCODERS_DIR encoder weights dir (default ~/.cozyclay/text-encoders)
|
|
29
|
+
* CCLAY_ARDY_DEVICE force a torch device (cpu|mps|cuda[:N])
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
import { spawn } from "node:child_process";
|
|
33
|
+
import { cpSync, existsSync, mkdtempSync, rmSync, statSync } from "node:fs";
|
|
34
|
+
import { createConnection } from "node:net";
|
|
35
|
+
import { homedir, tmpdir } from "node:os";
|
|
36
|
+
import { basename, dirname, join } from "node:path";
|
|
37
|
+
import { fileURLToPath } from "node:url";
|
|
38
|
+
|
|
39
|
+
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
40
|
+
const LOCAL_DIR = process.env.CCLAY_ARDY_LOCAL_DIR || join(homedir(), ".cozyclay", "ardy");
|
|
41
|
+
const VENV_PY =
|
|
42
|
+
process.env.CCLAY_ARDY_LOCAL_VENV ||
|
|
43
|
+
join(LOCAL_DIR, ".venv", process.platform === "win32" ? "Scripts\\python.exe" : "bin/python");
|
|
44
|
+
const WORKER_PORT = Number(process.env.CCLAY_ARDY_WORKER_PORT) || 9552;
|
|
45
|
+
// A sequence job can legitimately run a long time; the watchdog only guards
|
|
46
|
+
// against a worker that stopped talking entirely.
|
|
47
|
+
const WORKER_SILENCE_TIMEOUT_MS = 60 * 60_000;
|
|
48
|
+
|
|
49
|
+
const GENERATORS = {
|
|
50
|
+
single: join(HERE, "cclay_constrained_generate.py"),
|
|
51
|
+
sequence: join(HERE, "cclay_sequence_generate.py"),
|
|
52
|
+
edit: join(HERE, "cclay_motion_edit.py"),
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
function die(message) {
|
|
56
|
+
console.error(`run-local: ${message}`);
|
|
57
|
+
process.exit(2);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function usage() {
|
|
61
|
+
console.error("usage: run-local.mjs <single|sequence|edit> [flags] --output OUT.npz");
|
|
62
|
+
console.error("see the header of tools/ardy/run-local.mjs for the full grammar");
|
|
63
|
+
process.exit(2);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// The bridge builds these argv arrays itself, so parsing here is deliberately
|
|
67
|
+
// shallow: pull out the handful of values run-local needs (--output always;
|
|
68
|
+
// --cpu, --pose/--manifest for staging) and pass everything else through to
|
|
69
|
+
// the python generator untouched.
|
|
70
|
+
function parseArgs(argv) {
|
|
71
|
+
const passthrough = [];
|
|
72
|
+
let output = "";
|
|
73
|
+
let cpu = false;
|
|
74
|
+
const poses = [];
|
|
75
|
+
let manifest = "";
|
|
76
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
77
|
+
const arg = argv[i];
|
|
78
|
+
if (arg === "--output") {
|
|
79
|
+
output = argv[++i] ?? "";
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
if (arg === "--cpu") {
|
|
83
|
+
cpu = true;
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
if (arg === "--pose") {
|
|
87
|
+
poses.push(argv[++i] ?? "");
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
if (arg === "--manifest") {
|
|
91
|
+
manifest = argv[++i] ?? "";
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
passthrough.push(arg);
|
|
95
|
+
}
|
|
96
|
+
if (!output) die("--output is required");
|
|
97
|
+
return { passthrough, output, cpu, poses, manifest };
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Try to run the job on the persistent worker (tools/ardy/cclay_worker.py).
|
|
102
|
+
*
|
|
103
|
+
* Resolves {code} when the worker accepted and finished the job (its stdout
|
|
104
|
+
* lines have already been relayed), or null when the worker is unavailable
|
|
105
|
+
* or died mid-job — the caller falls back to a direct spawn, which is always
|
|
106
|
+
* correct because the job is idempotent (same --output, overwritten).
|
|
107
|
+
*/
|
|
108
|
+
function runViaWorker(mode, flagArgs) {
|
|
109
|
+
return new Promise((resolvePromise) => {
|
|
110
|
+
const sock = createConnection({ host: "127.0.0.1", port: WORKER_PORT });
|
|
111
|
+
let buffer = "";
|
|
112
|
+
let settled = false;
|
|
113
|
+
const finish = (value) => {
|
|
114
|
+
if (!settled) {
|
|
115
|
+
settled = true;
|
|
116
|
+
sock.destroy();
|
|
117
|
+
resolvePromise(value);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
sock.setTimeout(WORKER_SILENCE_TIMEOUT_MS, () => finish(null));
|
|
121
|
+
sock.on("error", () => finish(null));
|
|
122
|
+
sock.on("close", () => finish(null));
|
|
123
|
+
sock.on("connect", () => {
|
|
124
|
+
sock.write(`${JSON.stringify({ mode, argv: flagArgs })}\n`);
|
|
125
|
+
});
|
|
126
|
+
sock.on("data", (chunk) => {
|
|
127
|
+
buffer += chunk.toString("utf8");
|
|
128
|
+
let nl;
|
|
129
|
+
while ((nl = buffer.indexOf("\n")) !== -1) {
|
|
130
|
+
const line = buffer.slice(0, nl);
|
|
131
|
+
buffer = buffer.slice(nl + 1);
|
|
132
|
+
const marker = /^worker: exit (\d+)$/.exec(line);
|
|
133
|
+
if (marker) {
|
|
134
|
+
finish({ code: Number(marker[1]) });
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
if (line) console.log(line);
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
async function main() {
|
|
144
|
+
const [mode, ...rest] = process.argv.slice(2);
|
|
145
|
+
if (!mode || mode === "-h" || mode === "--help") usage();
|
|
146
|
+
const generator = GENERATORS[mode];
|
|
147
|
+
if (!generator) die(`unknown mode '${mode}' (expected single, sequence, or edit)`);
|
|
148
|
+
if (!existsSync(VENV_PY)) {
|
|
149
|
+
die(`venv python not found at ${VENV_PY}; run \`node tools/ardy/setup-local.mjs\` once`);
|
|
150
|
+
}
|
|
151
|
+
if (!existsSync(LOCAL_DIR)) {
|
|
152
|
+
die(`ARDY checkout not found at ${LOCAL_DIR}; run \`node tools/ardy/setup-local.mjs\` once`);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const { passthrough, output, cpu, poses, manifest } = parseArgs(rest);
|
|
156
|
+
|
|
157
|
+
const flagArgs = [...passthrough];
|
|
158
|
+
let stagingDir = null;
|
|
159
|
+
if (mode === "edit") {
|
|
160
|
+
if (!manifest) die("--manifest is required in edit mode");
|
|
161
|
+
if (poses.length === 0) die("edit mode needs at least one --pose");
|
|
162
|
+
// cclay_motion_edit.py resolves the manifest's relative pose_path
|
|
163
|
+
// entries against the manifest's own directory, expecting pose-<i>.npz
|
|
164
|
+
// siblings (the layout run-edit-on-box.sh created with scp). Stage the
|
|
165
|
+
// same layout in a fresh temp dir.
|
|
166
|
+
stagingDir = mkdtempSync(join(tmpdir(), "cozyclay-edit-"));
|
|
167
|
+
cpSync(manifest, join(stagingDir, "manifest.json"));
|
|
168
|
+
poses.forEach((posePath, index) => {
|
|
169
|
+
cpSync(posePath, join(stagingDir, `pose-${index}.npz`));
|
|
170
|
+
});
|
|
171
|
+
flagArgs.push("--manifest", join(stagingDir, "manifest.json"));
|
|
172
|
+
} else if (manifest) {
|
|
173
|
+
flagArgs.push("--manifest", manifest);
|
|
174
|
+
}
|
|
175
|
+
flagArgs.push("--output", output);
|
|
176
|
+
|
|
177
|
+
const env = { ...process.env };
|
|
178
|
+
if (cpu) env.CCLAY_ARDY_DEVICE = "cpu";
|
|
179
|
+
|
|
180
|
+
// Prefer the warm worker; a forced device (--cpu / CCLAY_ARDY_DEVICE)
|
|
181
|
+
// bypasses it because the worker's model already lives on the auto-picked
|
|
182
|
+
// device. null = worker unavailable, fall through to a direct spawn.
|
|
183
|
+
let code = null;
|
|
184
|
+
const forcedDevice = cpu || Boolean(process.env.CCLAY_ARDY_DEVICE);
|
|
185
|
+
if (!forcedDevice) {
|
|
186
|
+
const workerResult = await runViaWorker(mode, flagArgs);
|
|
187
|
+
if (workerResult) {
|
|
188
|
+
console.log("run-local: served by warm worker");
|
|
189
|
+
code = workerResult.code;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
if (code === null) {
|
|
193
|
+
console.log(`run-local: ${mode} generation with ${basename(VENV_PY)} (${LOCAL_DIR})`);
|
|
194
|
+
const child = spawn(VENV_PY, [generator, ...flagArgs], {
|
|
195
|
+
cwd: LOCAL_DIR, // keeps any generator-relative paths (outputs/, HF cache) out of this repo
|
|
196
|
+
stdio: ["ignore", "inherit", "inherit"],
|
|
197
|
+
env,
|
|
198
|
+
});
|
|
199
|
+
code = await new Promise((resolvePromise, reject) => {
|
|
200
|
+
child.on("error", reject);
|
|
201
|
+
child.on("close", resolvePromise);
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
if (stagingDir) {
|
|
205
|
+
// Cleanup failure must never mask the real result.
|
|
206
|
+
try {
|
|
207
|
+
rmSync(stagingDir, { recursive: true, force: true });
|
|
208
|
+
} catch (err) {
|
|
209
|
+
console.error(`run-local: could not remove ${stagingDir}: ${err.message}`);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
if (code !== 0) {
|
|
213
|
+
console.error(`run-local: generator exited with code ${code}`);
|
|
214
|
+
process.exit(code || 1);
|
|
215
|
+
}
|
|
216
|
+
let size;
|
|
217
|
+
try {
|
|
218
|
+
size = statSync(output).size;
|
|
219
|
+
} catch {
|
|
220
|
+
console.error(`run-local: generator exited 0 but ${output} does not exist`);
|
|
221
|
+
process.exit(1);
|
|
222
|
+
}
|
|
223
|
+
if (size === 0) {
|
|
224
|
+
console.error(`run-local: generator produced an empty file at ${output}`);
|
|
225
|
+
process.exit(1);
|
|
226
|
+
}
|
|
227
|
+
console.log(`run-local: done - ${output} (${size} bytes)`);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
main().catch((err) => {
|
|
231
|
+
console.error(`run-local: ${err.stack || err}`);
|
|
232
|
+
process.exit(1);
|
|
233
|
+
});
|
package/tools/ardy/run-on-box.sh
CHANGED
|
@@ -139,6 +139,9 @@ EOF
|
|
|
139
139
|
|
|
140
140
|
POSE_NPZ="" # legacy positional pose; normalized into POSE_ARGS after parsing
|
|
141
141
|
POSE_ARGS=() # repeatable triples: LOCAL_NPZ SRC_FRAME DST_FRAME
|
|
142
|
+
ROOT_MARGIN=""
|
|
143
|
+
CONTACT_THRESHOLD=""
|
|
144
|
+
HISTORY_FRAMES=""
|
|
142
145
|
BASE=""
|
|
143
146
|
PROMPT=""
|
|
144
147
|
DURATION=""
|
|
@@ -182,6 +185,15 @@ while [[ $# -gt 0 ]]; do
|
|
|
182
185
|
ROOT_2D_ARGS+=("$2" "$3" "$4" "$5"); shift 5 ;;
|
|
183
186
|
--cpu)
|
|
184
187
|
FORCE_CPU=1; shift ;;
|
|
188
|
+
--root-margin)
|
|
189
|
+
[[ $# -ge 2 && "$2" =~ ^[0-9]+([.][0-9]+)?$ ]] || { echo "run-on-box: --root-margin needs a non-negative number" >&2; usage; }
|
|
190
|
+
ROOT_MARGIN="$2"; shift 2 ;;
|
|
191
|
+
--history-frames)
|
|
192
|
+
[[ $# -ge 2 && "$2" =~ ^[0-9]+$ ]] || { echo "run-on-box: --history-frames needs a non-negative integer" >&2; usage; }
|
|
193
|
+
HISTORY_FRAMES="$2"; shift 2 ;;
|
|
194
|
+
--contact-threshold)
|
|
195
|
+
[[ $# -ge 2 && "$2" =~ ^[0-9]+([.][0-9]+)?$ ]] || { echo "run-on-box: --contact-threshold needs a non-negative number" >&2; usage; }
|
|
196
|
+
CONTACT_THRESHOLD="$2"; shift 2 ;;
|
|
185
197
|
--output)
|
|
186
198
|
[[ $# -ge 2 ]] || { echo "run-on-box: --output needs a path" >&2; usage; }
|
|
187
199
|
OUTPUT="$2"; shift 2 ;;
|
|
@@ -353,6 +365,16 @@ if ! ssh "${SSH_OPTS[@]}" "$HOST" "$GEN_CHECK" </dev/null; then
|
|
|
353
365
|
echo "run-on-box: ${HOST} is missing ${VENV_PY} or ${GEN_LABEL}; sync the ARDY sources to the box first (CozyClay scripts/ardy/sync-to-box --apply)" >&2
|
|
354
366
|
exit 1
|
|
355
367
|
fi
|
|
368
|
+
|
|
369
|
+
# The constrained generator is cclay-owned: the repo copy next to this
|
|
370
|
+
# script is the source of truth, synced up on every run so the box can
|
|
371
|
+
# never drift behind it (same pattern as run-sequence-on-box.sh).
|
|
372
|
+
if ! ssh "${SSH_OPTS[@]}" "$HOST" "cat > ${REMOTE}/scripts/cclay_constrained_generate.py" \
|
|
373
|
+
< "${HERE}/cclay_constrained_generate.py"; then
|
|
374
|
+
echo "run-on-box: could not sync cclay_constrained_generate.py to ${HOST}" >&2
|
|
375
|
+
exit 1
|
|
376
|
+
fi
|
|
377
|
+
echo "run-on-box: constrained generator synced to ${HOST}"
|
|
356
378
|
echo "run-on-box: venv python and generator script present on ${HOST}"
|
|
357
379
|
|
|
358
380
|
|
|
@@ -478,6 +500,9 @@ build_remote_cmd() {
|
|
|
478
500
|
cmd+=" $(printf '%q' "${ROOT_2D_ARGS[$((i + 2))]}")"
|
|
479
501
|
cmd+=" $(printf '%q' "${ROOT_2D_ARGS[$((i + 3))]}")"
|
|
480
502
|
done
|
|
503
|
+
[[ -z "$ROOT_MARGIN" ]] || cmd+=" --root-margin $(printf '%q' "$ROOT_MARGIN")"
|
|
504
|
+
[[ -z "$CONTACT_THRESHOLD" ]] || cmd+=" --contact-threshold $(printf '%q' "$CONTACT_THRESHOLD")"
|
|
505
|
+
[[ -z "$HISTORY_FRAMES" ]] || cmd+=" --history_frames $(printf '%q' "$HISTORY_FRAMES")"
|
|
481
506
|
cmd+=" --output $(printf '%q' "${tmp_dir}/out")"
|
|
482
507
|
if [[ -n "$SEED" ]]; then
|
|
483
508
|
cmd+=" --seed $(printf '%q' "$SEED")"
|
|
@@ -29,6 +29,9 @@ ROOT2D=()
|
|
|
29
29
|
SEED=""
|
|
30
30
|
OUTPUT=""
|
|
31
31
|
DRY_RUN=0
|
|
32
|
+
ROOT_MARGIN=""
|
|
33
|
+
CONTACT_THRESHOLD=""
|
|
34
|
+
HISTORY_FRAMES=""
|
|
32
35
|
|
|
33
36
|
while [[ $# -gt 0 ]]; do
|
|
34
37
|
case "$1" in
|
|
@@ -54,6 +57,15 @@ while [[ $# -gt 0 ]]; do
|
|
|
54
57
|
SEED="$2"; shift 2 ;;
|
|
55
58
|
--cpu)
|
|
56
59
|
FORCE_CPU=1; shift ;;
|
|
60
|
+
--root-margin)
|
|
61
|
+
[[ $# -ge 2 && "$2" =~ ^[0-9]+([.][0-9]+)?$ ]] || { echo "run-sequence-on-box: --root-margin needs a non-negative number" >&2; usage; }
|
|
62
|
+
ROOT_MARGIN="$2"; shift 2 ;;
|
|
63
|
+
--history-frames)
|
|
64
|
+
[[ $# -ge 2 && "$2" =~ ^[0-9]+$ ]] || { echo "run-sequence-on-box: --history-frames needs a non-negative integer" >&2; usage; }
|
|
65
|
+
HISTORY_FRAMES="$2"; shift 2 ;;
|
|
66
|
+
--contact-threshold)
|
|
67
|
+
[[ $# -ge 2 && "$2" =~ ^[0-9]+([.][0-9]+)?$ ]] || { echo "run-sequence-on-box: --contact-threshold needs a non-negative number" >&2; usage; }
|
|
68
|
+
CONTACT_THRESHOLD="$2"; shift 2 ;;
|
|
57
69
|
--output)
|
|
58
70
|
[[ $# -ge 2 ]] || { echo "run-sequence-on-box: --output needs a path" >&2; usage; }
|
|
59
71
|
OUTPUT="$2"; shift 2 ;;
|
|
@@ -132,6 +144,9 @@ build_remote_cmd() {
|
|
|
132
144
|
done
|
|
133
145
|
cmd+=" --output $(printf '%q' "${tmp_dir}/out")"
|
|
134
146
|
[[ -z "$SEED" ]] || cmd+=" --seed $(printf '%q' "$SEED")"
|
|
147
|
+
[[ -z "$ROOT_MARGIN" ]] || cmd+=" --root-margin $(printf '%q' "$ROOT_MARGIN")"
|
|
148
|
+
[[ -z "$CONTACT_THRESHOLD" ]] || cmd+=" --contact-threshold $(printf '%q' "$CONTACT_THRESHOLD")"
|
|
149
|
+
[[ -z "$HISTORY_FRAMES" ]] || cmd+=" --history_frames $(printf '%q' "$HISTORY_FRAMES")"
|
|
135
150
|
printf '%s' "$cmd"
|
|
136
151
|
}
|
|
137
152
|
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runner selection for the ARDY bridge.
|
|
3
|
+
*
|
|
4
|
+
* Exactly one backend drives generation for the bridge's lifetime:
|
|
5
|
+
*
|
|
6
|
+
* CCLAY_ARDY_MODE=local | remote explicit choice
|
|
7
|
+
* (unset) remote when CCLAY_ARDY_HOST is set,
|
|
8
|
+
* local otherwise
|
|
9
|
+
*
|
|
10
|
+
* so an operator with a configured box keeps today's behavior untouched, and
|
|
11
|
+
* everyone else gets local generation with zero configuration.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { createLocalRunner } from "./local.mjs";
|
|
15
|
+
import { createRemoteRunner } from "./remote.mjs";
|
|
16
|
+
|
|
17
|
+
export function createRunner() {
|
|
18
|
+
const mode = (process.env.CCLAY_ARDY_MODE || "").trim().toLowerCase();
|
|
19
|
+
if (mode === "remote") return createRemoteRunner();
|
|
20
|
+
if (mode === "local") return createLocalRunner();
|
|
21
|
+
if (mode) throw new Error(`unknown CCLAY_ARDY_MODE "${mode}" (expected "local" or "remote")`);
|
|
22
|
+
return process.env.CCLAY_ARDY_HOST?.trim() ? createRemoteRunner() : createLocalRunner();
|
|
23
|
+
}
|