cozyclay 1.0.0 → 1.2.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/README.md +59 -24
- package/THIRD_PARTY_NOTICES.md +31 -0
- package/bin/cozyclay.mjs +105 -11
- package/dist/CNAME +1 -0
- package/dist/app/index.html +57 -0
- package/dist/assets/app-Cgpk2hwX.js +4803 -0
- package/dist/assets/app-DgZvaAE1.css +1 -0
- package/dist/favicon.ico +0 -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 +406 -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 +9 -0
- package/dist/sw.js +127 -0
- package/package.json +15 -3
- package/src/App.jsx +1393 -648
- package/src/ardy/client.js +5 -4
- package/src/ardy/mp4-duration.js +102 -0
- package/src/ardy/timeline-coordinates.js +11 -0
- package/src/ardy/timeline.jsx +528 -67
- package/src/ardy/waypoints.js +14 -9
- 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/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 +9 -17
- package/src/hierarchy-panel.jsx +170 -23
- package/src/locale-toggle.jsx +18 -0
- package/src/locale.js +34 -0
- package/src/main.jsx +5 -0
- package/src/object-catalog.jsx +32 -3
- package/src/planview.jsx +174 -66
- package/src/pose-extract/browser.js +42 -0
- package/src/pose-extract/fit.js +194 -0
- package/src/pose-extract/index.js +53 -0
- package/src/pose-extract/keyframes.js +74 -0
- package/src/pose-extract/landmarks.js +162 -0
- package/src/poses.js +114 -0
- package/src/posestudio.jsx +75 -13
- package/src/pwa.js +42 -0
- package/src/result-modal.jsx +124 -0
- package/src/scenes.js +223 -0
- package/src/shot-authoring.js +204 -77
- package/src/shot.js +8 -4
- package/src/styles.css +839 -38
- package/src/ui.jsx +54 -5
- package/tools/ardy/BRIDGE.md +70 -4
- package/tools/ardy/README.md +55 -0
- package/tools/ardy/bridge.mjs +89 -389
- package/tools/ardy/cclay_constrained_generate.py +449 -0
- package/tools/ardy/cclay_motion_edit.py +74 -9
- package/tools/ardy/cclay_sequence_generate.py +68 -7
- package/tools/ardy/cclay_worker.py +304 -0
- package/tools/ardy/merge-text-encoder.py +160 -0
- package/tools/ardy/run-local.mjs +233 -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 +246 -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/bridge.mjs
CHANGED
|
@@ -41,15 +41,12 @@ import { basename, dirname, join, resolve, sep } from "node:path";
|
|
|
41
41
|
import { fileURLToPath } from "node:url";
|
|
42
42
|
import { decodeMotionNpz } from "../../src/ardy/npz.js";
|
|
43
43
|
import { motionArraysToNpzMembers, replaceMotionSegment, writeNpz } from "./npz.mjs";
|
|
44
|
+
import { globalChildren, killGroup, runStreaming, track } from "./runners/proc.mjs";
|
|
45
|
+
import { createRunner } from "./runners/index.mjs";
|
|
44
46
|
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
45
47
|
const REPO = resolve(HERE, "../..");
|
|
46
48
|
const OUT_DIR = join(HERE, "out");
|
|
47
|
-
const REFS_DIR = join(OUT_DIR, "refs");
|
|
48
|
-
const DUMP_SCRIPT = join(HERE, "dump-npz.py");
|
|
49
49
|
const POSE_TO_NPZ = join(HERE, "pose-to-npz.mjs");
|
|
50
|
-
const RUN_ON_BOX = join(HERE, "run-on-box.sh");
|
|
51
|
-
const RUN_SEQUENCE_ON_BOX = join(HERE, "run-sequence-on-box.sh");
|
|
52
|
-
const RUN_EDIT_ON_BOX = join(HERE, "run-edit-on-box.sh");
|
|
53
50
|
|
|
54
51
|
const BIND_HOST = "127.0.0.1"; // loopback only: this process shells out
|
|
55
52
|
const DEFAULT_PORT = 5181;
|
|
@@ -74,29 +71,14 @@ const MOTION_ALLOWLIST_MAX = 64; // newest runs only; evicted ids become stale 4
|
|
|
74
71
|
// path-free (the id is a lookup key, never a path).
|
|
75
72
|
const MOTION_ID = /^[0-9]+-[0-9a-f]{6}$/;
|
|
76
73
|
|
|
77
|
-
//
|
|
78
|
-
//
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
// Numpy-only read paths (bases listing, reference dumps) use the CPU venv on
|
|
84
|
-
// purpose: the box's two venvs are NOT interchangeable, and this is the one
|
|
85
|
-
// the dump tooling is verified under.
|
|
86
|
-
const DUMP_PY = "~/ardy/.venv/bin/python";
|
|
74
|
+
// The runner is the ONLY part of the bridge that knows where generation
|
|
75
|
+
// actually happens. Selection (runners/index.mjs): CCLAY_ARDY_MODE=local or
|
|
76
|
+
// remote when set; otherwise remote when CCLAY_ARDY_HOST is configured, local
|
|
77
|
+
// otherwise. Everything below the runner boundary — validation, caching,
|
|
78
|
+
// streaming, the motion allowlist — is backend-agnostic.
|
|
79
|
+
let runner; // assigned after CLI parsing, before the server starts
|
|
87
80
|
|
|
88
|
-
//
|
|
89
|
-
// dead host; ServerAlive* drops a wedged connection (same set run-on-box.sh
|
|
90
|
-
// uses).
|
|
91
|
-
const SSH_OPTS = [
|
|
92
|
-
"-o", "BatchMode=yes",
|
|
93
|
-
"-o", "ConnectTimeout=10",
|
|
94
|
-
"-o", "ServerAliveInterval=30",
|
|
95
|
-
"-o", "ServerAliveCountMax=240",
|
|
96
|
-
];
|
|
97
|
-
const SCP_OPTS = ["-o", "BatchMode=yes", "-o", "ConnectTimeout=10"];
|
|
98
|
-
|
|
99
|
-
// A box base path is produced by the box's own `ls outputs/*.npz` /
|
|
81
|
+
// A base path is produced by the backend's own `ls outputs/*.npz` /
|
|
100
82
|
// `ls outputs/omb/*.npz` and is still whitelisted before it is embedded in a
|
|
101
83
|
// remote shell string: only a plain, metacharacter-free relative npz path is
|
|
102
84
|
// ever allowed through.
|
|
@@ -104,220 +86,14 @@ const SAFE_BASE_PATH = /^outputs\/(?:omb\/)?[A-Za-z0-9._-]+\.npz$/;
|
|
|
104
86
|
const SAFE_BASE_ID = /^[A-Za-z0-9._-]+$/;
|
|
105
87
|
|
|
106
88
|
// ---------------------------------------------------------------------------
|
|
107
|
-
//
|
|
89
|
+
// backend probes (health, bases) with caching
|
|
108
90
|
// ---------------------------------------------------------------------------
|
|
109
91
|
|
|
110
|
-
//
|
|
111
|
-
//
|
|
112
|
-
//
|
|
113
|
-
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
function track(child) {
|
|
117
|
-
globalChildren.add(child);
|
|
118
|
-
child.once("close", () => globalChildren.delete(child));
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
function killGroup(child) {
|
|
122
|
-
try {
|
|
123
|
-
process.kill(-child.pid, "SIGTERM");
|
|
124
|
-
} catch {
|
|
125
|
-
/* process group already gone */
|
|
126
|
-
}
|
|
127
|
-
// SIGKILL backup for anything that ignores SIGTERM; unref'd so it never
|
|
128
|
-
// keeps the bridge alive on its own.
|
|
129
|
-
const backup = setTimeout(() => {
|
|
130
|
-
try {
|
|
131
|
-
process.kill(-child.pid, "SIGKILL");
|
|
132
|
-
} catch {
|
|
133
|
-
/* gone */
|
|
134
|
-
}
|
|
135
|
-
}, 3000);
|
|
136
|
-
backup.unref();
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// Run a short, non-streaming child (ssh/scp probes) to completion.
|
|
140
|
-
function run(argv, { timeoutMs = 0 } = {}) {
|
|
141
|
-
return new Promise((resolvePromise, reject) => {
|
|
142
|
-
const child = spawn(argv[0], argv.slice(1), { stdio: ["ignore", "pipe", "pipe"] });
|
|
143
|
-
let stdout = "";
|
|
144
|
-
let stderr = "";
|
|
145
|
-
let settled = false;
|
|
146
|
-
let timer = null;
|
|
147
|
-
const finish = (err, code) => {
|
|
148
|
-
if (settled) return;
|
|
149
|
-
settled = true;
|
|
150
|
-
if (timer) clearTimeout(timer);
|
|
151
|
-
if (err) reject(err);
|
|
152
|
-
else resolvePromise({ code, stdout, stderr });
|
|
153
|
-
};
|
|
154
|
-
child.stdout.setEncoding("utf8");
|
|
155
|
-
child.stderr.setEncoding("utf8");
|
|
156
|
-
child.stdout.on("data", (chunk) => {
|
|
157
|
-
stdout += chunk;
|
|
158
|
-
});
|
|
159
|
-
child.stderr.on("data", (chunk) => {
|
|
160
|
-
stderr += chunk;
|
|
161
|
-
});
|
|
162
|
-
child.on("error", (err) => finish(err));
|
|
163
|
-
child.on("close", (code) => finish(null, code));
|
|
164
|
-
if (timeoutMs > 0) {
|
|
165
|
-
timer = setTimeout(() => {
|
|
166
|
-
try {
|
|
167
|
-
child.kill("SIGKILL");
|
|
168
|
-
} catch {
|
|
169
|
-
/* gone */
|
|
170
|
-
}
|
|
171
|
-
finish(new Error(`timed out after ${timeoutMs} ms`));
|
|
172
|
-
}, timeoutMs);
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
// Split a child's stdout/stderr into lines as they arrive; empty lines are
|
|
178
|
-
// dropped. The trailing partial line is flushed on end so the generator's
|
|
179
|
-
// last line is never lost.
|
|
180
|
-
function streamLines(stream, onLine) {
|
|
181
|
-
let buffer = "";
|
|
182
|
-
stream.setEncoding("utf8");
|
|
183
|
-
stream.on("data", (chunk) => {
|
|
184
|
-
buffer += chunk;
|
|
185
|
-
let idx;
|
|
186
|
-
while ((idx = buffer.indexOf("\n")) !== -1) {
|
|
187
|
-
const line = buffer.slice(0, idx).replace(/\r$/, "");
|
|
188
|
-
buffer = buffer.slice(idx + 1);
|
|
189
|
-
if (line) onLine(line);
|
|
190
|
-
}
|
|
191
|
-
});
|
|
192
|
-
stream.on("end", () => {
|
|
193
|
-
const rest = buffer.replace(/\r$/, "");
|
|
194
|
-
if (rest) onLine(rest);
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
// Resolves with the exit code; rejects when the child could not be started.
|
|
199
|
-
function runStreaming(child, onLine) {
|
|
200
|
-
return new Promise((resolvePromise, reject) => {
|
|
201
|
-
let settled = false;
|
|
202
|
-
const finish = (fn, value) => {
|
|
203
|
-
if (!settled) {
|
|
204
|
-
settled = true;
|
|
205
|
-
fn(value);
|
|
206
|
-
}
|
|
207
|
-
};
|
|
208
|
-
child.on("error", (err) => finish(reject, err));
|
|
209
|
-
child.on("close", (code) => finish(resolvePromise, code));
|
|
210
|
-
for (const [streamName, stream] of [
|
|
211
|
-
["stdout", child.stdout],
|
|
212
|
-
["stderr", child.stderr],
|
|
213
|
-
]) {
|
|
214
|
-
streamLines(stream, (line) => onLine(line, streamName));
|
|
215
|
-
}
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
function lastLine(text) {
|
|
220
|
-
const lines = text
|
|
221
|
-
.split("\n")
|
|
222
|
-
.map((line) => line.trim())
|
|
223
|
-
.filter((line) => line.length > 0);
|
|
224
|
-
return lines.length ? lines[lines.length - 1] : "";
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
// ---------------------------------------------------------------------------
|
|
228
|
-
// box probes (health, bases) with caching
|
|
229
|
-
// ---------------------------------------------------------------------------
|
|
230
|
-
|
|
231
|
-
// One ssh round trip covers everything health needs: the host answering is
|
|
232
|
-
// the ssh call itself, then the encoder HTTP code and the device the
|
|
233
|
-
// generator venv would pick are read on the box with the same env the
|
|
234
|
-
// generator runs under. The device line mirrors run-on-box.sh's probe
|
|
235
|
-
// exactly, so what health reports is what the generation will use.
|
|
236
|
-
function healthRemoteCmd() {
|
|
237
|
-
return [
|
|
238
|
-
`ENC="$(curl -s -o /dev/null -w '%{http_code}' -m 10 ${ENCODER_URL})"`,
|
|
239
|
-
'[ -n "$ENC" ] || ENC="000"',
|
|
240
|
-
`DEV="$(cd ${REMOTE} && ${VENV_PY} -c 'import torch; print("cuda:0" if torch.cuda.is_available() else "cpu")')"`,
|
|
241
|
-
`printf 'encoder=%s\\ndevice=%s\\n' "$ENC" "$DEV"`,
|
|
242
|
-
].join(" && ");
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
async function probeHealth() {
|
|
246
|
-
const { code, stdout, stderr } = await run(
|
|
247
|
-
["ssh", ...SSH_OPTS, HOST, healthRemoteCmd()],
|
|
248
|
-
{ timeoutMs: 60_000 }
|
|
249
|
-
);
|
|
250
|
-
if (code !== 0) {
|
|
251
|
-
throw new Error(`ssh probe on ${HOST} failed (exit ${code}): ${lastLine(stderr)}`);
|
|
252
|
-
}
|
|
253
|
-
const fields = {};
|
|
254
|
-
for (const line of stdout.split("\n")) {
|
|
255
|
-
const match = /^(encoder|device)=(.*)$/.exec(line.trim());
|
|
256
|
-
if (match) fields[match[1]] = match[2];
|
|
257
|
-
}
|
|
258
|
-
if (!("encoder" in fields)) {
|
|
259
|
-
throw new Error(`encoder probe on ${HOST} produced no answer`);
|
|
260
|
-
}
|
|
261
|
-
if (fields.encoder !== "200") {
|
|
262
|
-
throw new Error(`text encoder at ${ENCODER_URL} answered ${fields.encoder}, not 200`);
|
|
263
|
-
}
|
|
264
|
-
if (!("device" in fields) || fields.device === "") {
|
|
265
|
-
const tail = lastLine(stderr);
|
|
266
|
-
throw new Error(
|
|
267
|
-
`device probe on ${HOST} produced no answer${tail ? `: ${tail}` : ""}`
|
|
268
|
-
);
|
|
269
|
-
}
|
|
270
|
-
if (!/^(cpu|cuda:\d+)$/.test(fields.device)) {
|
|
271
|
-
throw new Error(
|
|
272
|
-
`device probe on ${HOST} returned unexpected ${JSON.stringify(fields.device)}`
|
|
273
|
-
);
|
|
274
|
-
}
|
|
275
|
-
return { ok: true, host: HOST, encoder: Number(fields.encoder), device: fields.device };
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
// Frame counts come from a real load of each npz, in ONE ssh call: the script
|
|
279
|
-
// is fed to the box's python over a quoted heredoc (no local shell step), and
|
|
280
|
-
// entries that fail to load are skipped with a note on the box stderr instead
|
|
281
|
-
// of failing the whole listing.
|
|
282
|
-
function basesRemoteCmd() {
|
|
283
|
-
const script = [
|
|
284
|
-
"import glob, json, sys",
|
|
285
|
-
"import numpy as np",
|
|
286
|
-
"entries = []",
|
|
287
|
-
'for pattern in ("outputs/*.npz", "outputs/omb/*.npz"):',
|
|
288
|
-
" for path in sorted(glob.glob(pattern)):",
|
|
289
|
-
" try:",
|
|
290
|
-
' data = np.load(path, allow_pickle=False)',
|
|
291
|
-
' frames = int(data["posed_joints"].shape[0])',
|
|
292
|
-
" data.close()",
|
|
293
|
-
" except Exception as exc:",
|
|
294
|
-
' print("bases: skipping %s: %s" % (path, exc), file=sys.stderr)',
|
|
295
|
-
" continue",
|
|
296
|
-
' entries.append({"id": path.rsplit("/", 1)[-1][:-4], "path": path, "frames": frames})',
|
|
297
|
-
"print(json.dumps(entries))",
|
|
298
|
-
].join("\n");
|
|
299
|
-
return `cd ${REMOTE} && ${DUMP_PY} - <<'COZYCLAY_PY_EOF'\n${script}\nCOZYCLAY_PY_EOF`;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
async function listBases() {
|
|
303
|
-
const { code, stdout, stderr } = await run(
|
|
304
|
-
["ssh", ...SSH_OPTS, HOST, basesRemoteCmd()],
|
|
305
|
-
{ timeoutMs: 120_000 }
|
|
306
|
-
);
|
|
307
|
-
if (code !== 0) {
|
|
308
|
-
throw new Error(`bases listing on ${HOST} failed (exit ${code}): ${lastLine(stderr)}`);
|
|
309
|
-
}
|
|
310
|
-
let entries;
|
|
311
|
-
try {
|
|
312
|
-
entries = JSON.parse(stdout);
|
|
313
|
-
} catch (err) {
|
|
314
|
-
throw new Error(
|
|
315
|
-
`bases listing on ${HOST} did not parse as JSON: ${lastLine(stderr) || err.message}`
|
|
316
|
-
);
|
|
317
|
-
}
|
|
318
|
-
if (!Array.isArray(entries)) {
|
|
319
|
-
throw new Error(`bases listing on ${HOST} was not an array`);
|
|
320
|
-
}
|
|
92
|
+
// The raw listing comes from the runner (a box's `ls outputs/*.npz` over ssh,
|
|
93
|
+
// or a local directory scan); the bridge sanitizes every entry the same way
|
|
94
|
+
// regardless of backend before anything downstream can see it.
|
|
95
|
+
async function fetchBases() {
|
|
96
|
+
const entries = await runner.listBases();
|
|
321
97
|
const bases = [];
|
|
322
98
|
for (const entry of entries) {
|
|
323
99
|
if (
|
|
@@ -328,18 +104,18 @@ async function listBases() {
|
|
|
328
104
|
!Number.isInteger(entry.frames) ||
|
|
329
105
|
entry.frames < 0
|
|
330
106
|
) {
|
|
331
|
-
console.error(`[bridge] skipping malformed bases entry
|
|
107
|
+
console.error(`[bridge] skipping malformed bases entry: ${JSON.stringify(entry)}`);
|
|
332
108
|
continue;
|
|
333
109
|
}
|
|
334
110
|
if (!SAFE_BASE_ID.test(entry.id) || !SAFE_BASE_PATH.test(entry.path)) {
|
|
335
|
-
console.error(`[bridge] skipping unsafe bases entry
|
|
111
|
+
console.error(`[bridge] skipping unsafe bases entry: ${JSON.stringify(entry)}`);
|
|
336
112
|
continue;
|
|
337
113
|
}
|
|
338
114
|
bases.push({ id: entry.id, path: entry.path, frames: entry.frames });
|
|
339
115
|
}
|
|
340
116
|
// Duplicate ids (same name under outputs/ and outputs/omb/) are kept as-is;
|
|
341
|
-
// generate matches the first, which is exactly the lookup order
|
|
342
|
-
//
|
|
117
|
+
// generate matches the first, which is exactly the lookup order the
|
|
118
|
+
// generation path uses, so the two cannot pick different files.
|
|
343
119
|
return { bases };
|
|
344
120
|
}
|
|
345
121
|
|
|
@@ -355,7 +131,7 @@ async function getHealth() {
|
|
|
355
131
|
return healthCache.value;
|
|
356
132
|
}
|
|
357
133
|
if (!healthInflight) {
|
|
358
|
-
healthInflight = probeHealth()
|
|
134
|
+
healthInflight = runner.probeHealth()
|
|
359
135
|
.then((value) => {
|
|
360
136
|
healthCache = { at: Date.now(), value };
|
|
361
137
|
return value;
|
|
@@ -381,7 +157,7 @@ async function getBases() {
|
|
|
381
157
|
return basesCache.value;
|
|
382
158
|
}
|
|
383
159
|
if (!basesInflight) {
|
|
384
|
-
basesInflight =
|
|
160
|
+
basesInflight = fetchBases()
|
|
385
161
|
.then((value) => {
|
|
386
162
|
basesCache = { at: Date.now(), value };
|
|
387
163
|
return value;
|
|
@@ -397,75 +173,6 @@ async function getBases() {
|
|
|
397
173
|
return basesInflight;
|
|
398
174
|
}
|
|
399
175
|
|
|
400
|
-
// ---------------------------------------------------------------------------
|
|
401
|
-
// reference frame dumps
|
|
402
|
-
// ---------------------------------------------------------------------------
|
|
403
|
-
|
|
404
|
-
// The synthetic pose borrows its skeleton proportions and root from the base
|
|
405
|
-
// clip, so a frame dump of the chosen base is required by pose-to-npz.mjs.
|
|
406
|
-
// Dumps are cached on disk under tools/ardy/out/refs/<base>.json and produced
|
|
407
|
-
// by running tools/ardy/dump-npz.py on the box (copied to /tmp, never into
|
|
408
|
-
// ~/ardy, removed afterwards). Concurrent requests for the same base share
|
|
409
|
-
// one dump via refInflight.
|
|
410
|
-
const refInflight = new Map();
|
|
411
|
-
|
|
412
|
-
function ensureReference(baseId, basePath) {
|
|
413
|
-
mkdirSync(REFS_DIR, { recursive: true });
|
|
414
|
-
const cachePath = join(REFS_DIR, `${baseId}.json`);
|
|
415
|
-
if (existsSync(cachePath)) {
|
|
416
|
-
try {
|
|
417
|
-
const cached = JSON.parse(readFileSync(cachePath, "utf8"));
|
|
418
|
-
if (cached && cached.schema === "ardy.frame.v1") return Promise.resolve(cachePath);
|
|
419
|
-
console.error(`[bridge] cached reference ${cachePath} is not ardy.frame.v1; re-dumping`);
|
|
420
|
-
} catch {
|
|
421
|
-
console.error(`[bridge] cached reference ${cachePath} is unreadable; re-dumping`);
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
if (refInflight.has(baseId)) return refInflight.get(baseId);
|
|
425
|
-
const promise = dumpReference(baseId, basePath, cachePath).finally(() => {
|
|
426
|
-
refInflight.delete(baseId);
|
|
427
|
-
});
|
|
428
|
-
refInflight.set(baseId, promise);
|
|
429
|
-
return promise;
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
async function dumpReference(baseId, basePath, cachePath) {
|
|
433
|
-
// basePath is already whitelisted by SAFE_BASE_PATH, so it cannot carry
|
|
434
|
-
// shell metacharacters into the remote command below.
|
|
435
|
-
const suffix = `${process.pid}-${randomBytes(4).toString("hex")}`;
|
|
436
|
-
const remoteScript = `/tmp/cozyclay-dump-${suffix}.py`;
|
|
437
|
-
try {
|
|
438
|
-
await run(
|
|
439
|
-
["scp", "-q", ...SCP_OPTS, DUMP_SCRIPT, `${HOST}:${remoteScript}`],
|
|
440
|
-
{ timeoutMs: 30_000 }
|
|
441
|
-
);
|
|
442
|
-
const { stdout, stderr } = await run(
|
|
443
|
-
["ssh", ...SSH_OPTS, HOST, `cd ${REMOTE} && ${DUMP_PY} ${remoteScript} ${basePath} 0`],
|
|
444
|
-
{ timeoutMs: 120_000 }
|
|
445
|
-
);
|
|
446
|
-
let parsed;
|
|
447
|
-
try {
|
|
448
|
-
parsed = JSON.parse(stdout);
|
|
449
|
-
} catch (err) {
|
|
450
|
-
throw new Error(
|
|
451
|
-
`reference dump for ${baseId} produced no JSON: ${lastLine(stderr) || err.message}`
|
|
452
|
-
);
|
|
453
|
-
}
|
|
454
|
-
if (!parsed || parsed.schema !== "ardy.frame.v1") {
|
|
455
|
-
throw new Error(
|
|
456
|
-
`reference dump for ${baseId} has schema ${JSON.stringify(parsed && parsed.schema)}`
|
|
457
|
-
);
|
|
458
|
-
}
|
|
459
|
-
writeFileSync(cachePath, stdout);
|
|
460
|
-
return cachePath;
|
|
461
|
-
} finally {
|
|
462
|
-
// Cleanup failure must never mask the real result.
|
|
463
|
-
await run(["ssh", ...SSH_OPTS, HOST, `rm -f ${remoteScript}`], { timeoutMs: 30_000 }).catch(
|
|
464
|
-
(err) => console.error(`[bridge] could not remove ${remoteScript} on ${HOST}: ${err.message}`)
|
|
465
|
-
);
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
|
|
469
176
|
// ---------------------------------------------------------------------------
|
|
470
177
|
// request validation
|
|
471
178
|
// ---------------------------------------------------------------------------
|
|
@@ -774,18 +481,6 @@ function tryParseReport(line) {
|
|
|
774
481
|
return parsed;
|
|
775
482
|
}
|
|
776
483
|
|
|
777
|
-
// Force the same box config onto run-on-box.sh even when the bridge was
|
|
778
|
-
// started with different env values; they must not disagree.
|
|
779
|
-
function boxEnv() {
|
|
780
|
-
return {
|
|
781
|
-
...process.env,
|
|
782
|
-
CCLAY_ARDY_HOST: HOST,
|
|
783
|
-
CCLAY_ARDY_REPO: REMOTE,
|
|
784
|
-
CCLAY_ARDY_VENV: VENV_PY,
|
|
785
|
-
CCLAY_ARDY_ENCODER_URL: ENCODER_URL,
|
|
786
|
-
};
|
|
787
|
-
}
|
|
788
|
-
|
|
789
484
|
// ---------------------------------------------------------------------------
|
|
790
485
|
// generated-motion delivery
|
|
791
486
|
// ---------------------------------------------------------------------------
|
|
@@ -906,7 +601,7 @@ async function handleGenerate(req, res) {
|
|
|
906
601
|
try {
|
|
907
602
|
bases = await getBases();
|
|
908
603
|
} catch (err) {
|
|
909
|
-
sendJson(res, 503, { ok: false, reason: `cannot list base motions
|
|
604
|
+
sendJson(res, 503, { ok: false, reason: `cannot list base motions: ${err.message}` });
|
|
910
605
|
finish(503);
|
|
911
606
|
return;
|
|
912
607
|
}
|
|
@@ -1017,22 +712,21 @@ async function handleGenerate(req, res) {
|
|
|
1017
712
|
})),
|
|
1018
713
|
};
|
|
1019
714
|
writeFileSync(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`, { mode: 0o600 });
|
|
1020
|
-
const
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
for (const posePath of poseNpzPaths) args.push("--pose", posePath);
|
|
715
|
+
const cmd = await runner.editCommand({
|
|
716
|
+
source: sourceMotionPath,
|
|
717
|
+
manifest: manifestPath,
|
|
718
|
+
prompt: body.prompt,
|
|
719
|
+
contextBefore: body.motionEdit.contextBefore,
|
|
720
|
+
contextAfter: body.motionEdit.contextAfter,
|
|
721
|
+
seed: body.seed,
|
|
722
|
+
poseNpzPaths,
|
|
723
|
+
output: outNpzPath,
|
|
724
|
+
});
|
|
1031
725
|
sendStatus(
|
|
1032
726
|
`[bridge] editing frames ${body.motionEdit.startFrame}..${body.motionEdit.endFrame - 1} ` +
|
|
1033
727
|
"with ARDY history and sparse constraints"
|
|
1034
728
|
);
|
|
1035
|
-
const box = spawnTracked(
|
|
729
|
+
const box = spawnTracked(cmd.command, cmd.args, { cwd: REPO, detached: true, env: cmd.env });
|
|
1036
730
|
const last = { stderr: "", stdout: "" };
|
|
1037
731
|
let report = null;
|
|
1038
732
|
let done = null;
|
|
@@ -1044,7 +738,7 @@ async function handleGenerate(req, res) {
|
|
|
1044
738
|
report = parsed;
|
|
1045
739
|
return;
|
|
1046
740
|
}
|
|
1047
|
-
const marker =
|
|
741
|
+
const marker = cmd.doneRe.exec(line);
|
|
1048
742
|
if (marker) {
|
|
1049
743
|
done = { path: marker[1], bytes: Number(marker[2]) };
|
|
1050
744
|
return;
|
|
@@ -1053,10 +747,10 @@ async function handleGenerate(req, res) {
|
|
|
1053
747
|
sendStatus(line);
|
|
1054
748
|
});
|
|
1055
749
|
children.delete(box);
|
|
1056
|
-
if (code !== 0) throw new Error(
|
|
1057
|
-
if (!done || done.path !== outNpzPath) throw new Error(
|
|
750
|
+
if (code !== 0) throw new Error(`${cmd.label} failed (exit ${code}): ${last.stderr || last.stdout || "no output"}`);
|
|
751
|
+
if (!done || done.path !== outNpzPath) throw new Error(`${cmd.label} did not return the requested output`);
|
|
1058
752
|
const finalSize = statSync(outNpzPath).size;
|
|
1059
|
-
if (finalSize !== done.bytes) throw new Error(
|
|
753
|
+
if (finalSize !== done.bytes) throw new Error(`${cmd.label} output size mismatch`);
|
|
1060
754
|
if (report) send({ event: "report", report });
|
|
1061
755
|
registerMotion(stamp, outNpzPath);
|
|
1062
756
|
send({ event: "done", output: outNpzPath, bytes: finalSize, motionUrl: `/ardy/motions/${stamp}` });
|
|
@@ -1067,29 +761,25 @@ async function handleGenerate(req, res) {
|
|
|
1067
761
|
return;
|
|
1068
762
|
}
|
|
1069
763
|
if (body.segments) {
|
|
1070
|
-
const args = [RUN_SEQUENCE_ON_BOX];
|
|
1071
|
-
for (const segment of segments) {
|
|
1072
|
-
args.push(
|
|
1073
|
-
"--segment",
|
|
1074
|
-
segment.prompt,
|
|
1075
|
-
String((segment.endFrame - segment.startFrame) / FPS)
|
|
1076
|
-
);
|
|
1077
|
-
}
|
|
1078
764
|
// Root waypoints ride the same chained rollout (rollout-global
|
|
1079
765
|
// frames): the sequence generator slices the constraint set per
|
|
1080
766
|
// segment call, so a path and a prompt schedule coexist.
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
767
|
+
const cmd = await runner.sequenceCommand({
|
|
768
|
+
segments: segments.map((segment) => ({
|
|
769
|
+
prompt: segment.prompt,
|
|
770
|
+
durationS: (segment.endFrame - segment.startFrame) / FPS,
|
|
771
|
+
})),
|
|
772
|
+
waypoints: body.waypoints,
|
|
773
|
+
seed: body.seed,
|
|
774
|
+
cpu: body.cpu,
|
|
775
|
+
output: outNpzPath,
|
|
776
|
+
});
|
|
1087
777
|
sendStatus(
|
|
1088
778
|
`[bridge] generating ${segments.length} blocks in one autoregressive ARDY session` +
|
|
1089
779
|
(body.waypoints?.length ? ` with a ${body.waypoints.length}-pin root path` : "")
|
|
1090
780
|
);
|
|
1091
781
|
|
|
1092
|
-
const box = spawnTracked(
|
|
782
|
+
const box = spawnTracked(cmd.command, cmd.args, { cwd: REPO, detached: true, env: cmd.env });
|
|
1093
783
|
const last = { stderr: "", stdout: "" };
|
|
1094
784
|
let finalReport = null;
|
|
1095
785
|
let done = null;
|
|
@@ -1101,7 +791,7 @@ async function handleGenerate(req, res) {
|
|
|
1101
791
|
finalReport = parsed;
|
|
1102
792
|
return;
|
|
1103
793
|
}
|
|
1104
|
-
const marker =
|
|
794
|
+
const marker = cmd.doneRe.exec(line);
|
|
1105
795
|
if (marker) {
|
|
1106
796
|
done = { path: marker[1], bytes: Number(marker[2]) };
|
|
1107
797
|
return;
|
|
@@ -1111,13 +801,13 @@ async function handleGenerate(req, res) {
|
|
|
1111
801
|
});
|
|
1112
802
|
children.delete(box);
|
|
1113
803
|
if (code !== 0) {
|
|
1114
|
-
throw new Error(
|
|
804
|
+
throw new Error(`${cmd.label} failed (exit ${code}): ${last.stderr || last.stdout || "no output"}`);
|
|
1115
805
|
}
|
|
1116
|
-
if (!done) throw new Error(
|
|
1117
|
-
if (done.path !== outNpzPath) throw new Error(
|
|
806
|
+
if (!done) throw new Error(`${cmd.label} exited 0 without a "done" marker`);
|
|
807
|
+
if (done.path !== outNpzPath) throw new Error(`${cmd.label} returned unexpected output ${done.path}`);
|
|
1118
808
|
const finalSize = statSync(outNpzPath).size;
|
|
1119
809
|
if (finalSize === 0 || finalSize !== done.bytes) {
|
|
1120
|
-
throw new Error(
|
|
810
|
+
throw new Error(`${cmd.label} output size mismatch for ${outNpzPath}`);
|
|
1121
811
|
}
|
|
1122
812
|
if (finalReport) send({ event: "report", report: finalReport });
|
|
1123
813
|
registerMotion(stamp, outNpzPath);
|
|
@@ -1136,26 +826,23 @@ async function handleGenerate(req, res) {
|
|
|
1136
826
|
throw new Error("generation has no pose constraint");
|
|
1137
827
|
}
|
|
1138
828
|
const segmentFrames = segment.endFrame - segment.startFrame;
|
|
1139
|
-
const
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
args.push("--root-2d", String(wp.frame), String(wp.x), String(wp.z), wp.heading === null ? "none" : String(wp.heading));
|
|
1154
|
-
}
|
|
1155
|
-
args.push("--output", outputPath);
|
|
829
|
+
const cmd = await runner.singleCommand({
|
|
830
|
+
poseFroms: localPoses.map((entry) => ({
|
|
831
|
+
npz: poseNpzPaths[entry.poseIndex],
|
|
832
|
+
srcFrame: 0,
|
|
833
|
+
dstFrame: entry.frame - segment.startFrame,
|
|
834
|
+
})),
|
|
835
|
+
basePath: match ? match.path : null,
|
|
836
|
+
prompt: segment.prompt,
|
|
837
|
+
durationS: segmentFrames / FPS,
|
|
838
|
+
seed: body.seed,
|
|
839
|
+
cpu: body.cpu,
|
|
840
|
+
waypoints: body.waypoints,
|
|
841
|
+
output: outputPath,
|
|
842
|
+
});
|
|
1156
843
|
sendStatus(`[bridge] generating frames ${segment.startFrame}..${segment.endFrame - 1}`);
|
|
1157
844
|
|
|
1158
|
-
const box = spawnTracked(
|
|
845
|
+
const box = spawnTracked(cmd.command, cmd.args, { cwd: REPO, detached: true, env: cmd.env });
|
|
1159
846
|
const last = { stderr: "", stdout: "" };
|
|
1160
847
|
let report = null;
|
|
1161
848
|
let done = null;
|
|
@@ -1167,7 +854,7 @@ async function handleGenerate(req, res) {
|
|
|
1167
854
|
report = parsed;
|
|
1168
855
|
return;
|
|
1169
856
|
}
|
|
1170
|
-
const marker =
|
|
857
|
+
const marker = cmd.doneRe.exec(line);
|
|
1171
858
|
if (marker) {
|
|
1172
859
|
done = { path: marker[1], bytes: Number(marker[2]) };
|
|
1173
860
|
return;
|
|
@@ -1176,11 +863,11 @@ async function handleGenerate(req, res) {
|
|
|
1176
863
|
sendStatus(line);
|
|
1177
864
|
});
|
|
1178
865
|
children.delete(box);
|
|
1179
|
-
if (code !== 0) throw new Error(
|
|
1180
|
-
if (!done) throw new Error(
|
|
1181
|
-
if (done.path !== outputPath) throw new Error(
|
|
866
|
+
if (code !== 0) throw new Error(`${cmd.label} failed (exit ${code}): ${last.stderr || last.stdout || "no output"}`);
|
|
867
|
+
if (!done) throw new Error(`${cmd.label} exited 0 without a "done" marker`);
|
|
868
|
+
if (done.path !== outputPath) throw new Error(`${cmd.label} returned unexpected output ${done.path}`);
|
|
1182
869
|
const size = statSync(outputPath).size;
|
|
1183
|
-
if (size === 0 || size !== done.bytes) throw new Error(
|
|
870
|
+
if (size === 0 || size !== done.bytes) throw new Error(`${cmd.label} output size mismatch for ${outputPath}`);
|
|
1184
871
|
return report;
|
|
1185
872
|
};
|
|
1186
873
|
|
|
@@ -1286,10 +973,19 @@ Dev-only HTTP sidecar for the ARDY loop. See tools/ardy/BRIDGE.md.
|
|
|
1286
973
|
|
|
1287
974
|
env:
|
|
1288
975
|
COZYCLAY_BRIDGE_PORT same as --port (default 5181)
|
|
1289
|
-
|
|
976
|
+
CCLAY_ARDY_MODE "local" or "remote"; default: remote when
|
|
977
|
+
CCLAY_ARDY_HOST is set, local otherwise
|
|
978
|
+
|
|
979
|
+
remote mode (generation on an ssh box):
|
|
980
|
+
CCLAY_ARDY_HOST ssh destination for the ARDY host
|
|
1290
981
|
CCLAY_ARDY_REPO ARDY checkout on the box (default $HOME/ardy)
|
|
1291
982
|
CCLAY_ARDY_VENV generator venv python on the box (default ~/ardy/.venv-cuda/bin/python)
|
|
1292
983
|
CCLAY_ARDY_ENCODER_URL text encoder service (default http://127.0.0.1:9550/)
|
|
984
|
+
|
|
985
|
+
local mode (generation on this machine; run tools/ardy/setup-local.sh once):
|
|
986
|
+
CCLAY_ARDY_LOCAL_DIR local ARDY checkout (default ~/.cozyclay/ardy)
|
|
987
|
+
CCLAY_ARDY_LOCAL_VENV generator venv python (default <local-dir>/.venv/bin/python)
|
|
988
|
+
CCLAY_ARDY_ENCODER_URL text encoder service (default http://127.0.0.1:9550/)
|
|
1293
989
|
`);
|
|
1294
990
|
}
|
|
1295
991
|
|
|
@@ -1323,7 +1019,11 @@ if (process.env.COZYCLAY_BRIDGE_PORT !== undefined) {
|
|
|
1323
1019
|
}
|
|
1324
1020
|
|
|
1325
1021
|
const port = resolvePort(process.argv.slice(2));
|
|
1326
|
-
|
|
1022
|
+
try {
|
|
1023
|
+
runner = createRunner();
|
|
1024
|
+
} catch (err) {
|
|
1025
|
+
die(err.message);
|
|
1026
|
+
}
|
|
1327
1027
|
|
|
1328
1028
|
const server = createServer((req, res) => {
|
|
1329
1029
|
const started = Date.now();
|
|
@@ -1408,7 +1108,7 @@ server.on("clientError", (err, socket) => {
|
|
|
1408
1108
|
server.listen(port, BIND_HOST, () => {
|
|
1409
1109
|
console.log(`[bridge] ARDY dev bridge listening on http://${BIND_HOST}:${port}`);
|
|
1410
1110
|
console.log("[bridge] dev-only sidecar: the static dist/ build does not need it; stop with Ctrl-C");
|
|
1411
|
-
console.log(`[bridge]
|
|
1111
|
+
console.log(`[bridge] ${runner.mode} backend: ${runner.describe()}`);
|
|
1412
1112
|
});
|
|
1413
1113
|
|
|
1414
1114
|
server.on("error", (err) => {
|