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.
Files changed (138) hide show
  1. package/CHANGELOG.md +85 -0
  2. package/README.md +91 -25
  3. package/THIRD_PARTY_NOTICES.md +68 -1
  4. package/bin/cozyclay.mjs +71 -8
  5. package/dist/CNAME +1 -0
  6. package/dist/ai-camera-control/index.html +406 -0
  7. package/dist/app/index.html +57 -0
  8. package/dist/assets/app-B3U5aut1.js +4811 -0
  9. package/dist/assets/app-BrRF0wso.css +1 -0
  10. package/dist/assets/vision_bundle-jFkh-fIS.js +41 -0
  11. package/dist/favicon.ico +0 -0
  12. package/dist/fonts/InstrumentSerif-OFL.txt +93 -0
  13. package/dist/fonts/Inter-OFL.txt +92 -0
  14. package/dist/fonts/README.md +15 -0
  15. package/dist/icons/apple-touch-icon.png +0 -0
  16. package/dist/icons/icon-192.png +0 -0
  17. package/dist/icons/icon-32.png +0 -0
  18. package/dist/icons/icon-512.png +0 -0
  19. package/dist/icons/icon-maskable-512.png +0 -0
  20. package/dist/index.html +450 -5
  21. package/dist/manifest.webmanifest +42 -0
  22. package/dist/media/cozyclay-demo-poster.jpg +0 -0
  23. package/dist/media/cozyclay-logo.png +0 -0
  24. package/dist/robots.txt +4 -0
  25. package/dist/sitemap.xml +15 -0
  26. package/dist/sw.js +127 -0
  27. package/mcp/LIVE-PROTOCOL.md +63 -0
  28. package/mcp/README.md +142 -0
  29. package/mcp/ardy-prompts.mjs +170 -0
  30. package/mcp/live-hub.mjs +105 -0
  31. package/mcp/package.json +24 -0
  32. package/mcp/server.mjs +1394 -0
  33. package/package.json +122 -78
  34. package/src/App.jsx +4235 -1047
  35. package/src/ardy/client.js +5 -4
  36. package/src/ardy/cskel27.js +7 -2
  37. package/src/ardy/ik.js +25 -15
  38. package/src/ardy/mp4-duration.js +102 -0
  39. package/src/ardy/npz.js +64 -3
  40. package/src/ardy/playback.js +31 -1
  41. package/src/ardy/prompt-clips.js +7 -2
  42. package/src/ardy/retime.js +211 -0
  43. package/src/ardy/timeline-coordinates.js +24 -0
  44. package/src/ardy/timeline.jsx +650 -70
  45. package/src/ardy/to-cskel27.js +34 -12
  46. package/src/ardy/trim.js +33 -0
  47. package/src/ardy/waypoints.js +14 -9
  48. package/src/asset-pane.jsx +36 -0
  49. package/src/camera-block.js +60 -0
  50. package/src/camera-follow.js +49 -10
  51. package/src/camera-rail-schedule.js +176 -0
  52. package/src/controls.jsx +16 -2
  53. package/src/cuts.js +184 -0
  54. package/src/dualview.jsx +14 -8
  55. package/src/generation/client.js +56 -0
  56. package/src/generation/session.js +47 -0
  57. package/src/generation/shot-spec.js +40 -0
  58. package/src/generation/use-generation.js +55 -0
  59. package/src/hierarchy-model.js +104 -30
  60. package/src/hierarchy-panel.jsx +306 -26
  61. package/src/live-control.js +122 -0
  62. package/src/locale-toggle.jsx +18 -0
  63. package/src/locale.js +34 -0
  64. package/src/main.jsx +5 -0
  65. package/src/matte-editor.js +543 -0
  66. package/src/matte.js +503 -0
  67. package/src/multimodel-ingest.js +344 -0
  68. package/src/object-catalog.jsx +32 -3
  69. package/src/object-gizmo.jsx +43 -15
  70. package/src/planview.jsx +208 -89
  71. package/src/pose-extract/browser.js +42 -0
  72. package/src/pose-extract/detector.js +75 -0
  73. package/src/pose-extract/fit.js +194 -0
  74. package/src/pose-extract/index.js +56 -0
  75. package/src/pose-extract/keyframes.js +74 -0
  76. package/src/pose-extract/landmarks.js +162 -0
  77. package/src/pose-extract/take.js +87 -0
  78. package/src/pose-extract/video-frames.js +91 -0
  79. package/src/pose-thumbs.js +152 -0
  80. package/src/poses.js +114 -0
  81. package/src/posestudio.jsx +434 -22
  82. package/src/project-browser.jsx +135 -0
  83. package/src/project.js +289 -0
  84. package/src/props.jsx +69 -3
  85. package/src/pwa.js +42 -0
  86. package/src/result-modal.jsx +124 -0
  87. package/src/room.jsx +14 -35
  88. package/src/scene-asset-cache.js +125 -0
  89. package/src/scene-assets.js +288 -0
  90. package/src/scene-objects.js +245 -7
  91. package/src/scenes.js +404 -0
  92. package/src/shot-authoring.js +246 -77
  93. package/src/shot.js +8 -4
  94. package/src/styles.css +2151 -183
  95. package/src/ui.jsx +54 -5
  96. package/tools/ardy/BRIDGE.md +73 -6
  97. package/tools/ardy/README.md +64 -5
  98. package/tools/ardy/bridge.mjs +146 -390
  99. package/tools/ardy/bvh-cskel27.mjs +1209 -0
  100. package/tools/ardy/cclay_constrained_generate.py +561 -0
  101. package/tools/ardy/cclay_motion_edit.py +74 -9
  102. package/tools/ardy/cclay_sequence_generate.py +117 -7
  103. package/tools/ardy/cclay_worker.py +304 -0
  104. package/tools/ardy/extract.mjs +367 -0
  105. package/tools/ardy/footage.mjs +462 -0
  106. package/tools/ardy/merge-text-encoder.py +160 -0
  107. package/tools/ardy/npz.mjs +74 -9
  108. package/tools/ardy/run-local.mjs +233 -0
  109. package/tools/ardy/run-on-box.sh +25 -0
  110. package/tools/ardy/run-sequence-on-box.sh +15 -0
  111. package/tools/ardy/runners/index.mjs +23 -0
  112. package/tools/ardy/runners/local.mjs +452 -0
  113. package/tools/ardy/runners/proc.mjs +125 -0
  114. package/tools/ardy/runners/remote.mjs +252 -0
  115. package/tools/ardy/setup-local.mjs +189 -0
  116. package/tools/ardy/setup-text-encoder-on-box.sh +93 -0
  117. package/tools/ardy/setup-text-encoder.py +296 -0
  118. package/tools/generation/README.md +29 -0
  119. package/tools/generation/bridge.mjs +149 -0
  120. package/tools/generation/job-store.mjs +51 -0
  121. package/tools/generation/providers/kling.mjs +76 -0
  122. package/tools/generation/providers/runway.mjs +101 -0
  123. package/tools/generation/providers/seedance.mjs +87 -0
  124. package/tools/generation/providers/shared.mjs +49 -0
  125. package/tools/generation/providers/veo.mjs +84 -0
  126. package/tools/metrics/archive-traffic.mjs +138 -0
  127. package/dist/assets/index-BW_S1YRy.js +0 -4395
  128. package/dist/assets/index-nRmmJgap.css +0 -1
  129. package/tools/ardy/__pycache__/cclay_sequence_generate.cpython-313.pyc +0 -0
  130. package/tools/ardy/out/gen-1786443326924-c6019e-generated.npz +0 -0
  131. package/tools/ardy/out/gen-1786443609325-0053db-generated.npz +0 -0
  132. package/tools/ardy/out/gen-1786443835628-749ed1-generated.npz +0 -0
  133. package/tools/ardy/out/gen-1786462605247-03cb19-generated.npz +0 -0
  134. package/tools/qa-browser.mjs +0 -84
  135. package/tools/qa-crop3.mjs +0 -22
  136. package/tools/qa-playview.mjs +0 -49
  137. package/tools/qa-screenshot.mjs +0 -24
  138. package/tools/qa-visual.mjs +0 -51
@@ -0,0 +1,252 @@
1
+ /**
2
+ * Remote (ssh) runner for the ARDY bridge.
3
+ *
4
+ * This is the original box-driven backend extracted verbatim from bridge.mjs:
5
+ * health and bases probes go over one ssh round trip each, reference dumps
6
+ * scp a python script to the box's /tmp, and generation shells out to the
7
+ * run-*-on-box.sh wrappers, which push inputs, run the generator remotely and
8
+ * pull the npz back.
9
+ *
10
+ * The runner interface (shared with runners/local.mjs) is deliberately small:
11
+ *
12
+ * describe() one-line startup log
13
+ * probeHealth() -> { ok:true, host, encoder, device } | throws
14
+ * listBases() -> raw entries [{id, path, frames}] | throws
15
+ * singleCommand(request) -> { command, args, env, doneRe }
16
+ * sequenceCommand(request) -> { command, args, env, doneRe }
17
+ * editCommand(request) -> { command, args, env, doneRe }
18
+ *
19
+ * The bridge owns validation, caching, streaming and the motion allowlist;
20
+ * a runner only knows how to probe its backend and how to build the argv for
21
+ * one generation child whose stdout carries a `doneRe`-matching marker line
22
+ * (`<marker>: done - <path> (<bytes> bytes)`) on success.
23
+ */
24
+
25
+ import { dirname, join } from "node:path";
26
+ import { fileURLToPath } from "node:url";
27
+ import { lastLine, run } from "./proc.mjs";
28
+
29
+ const HERE = dirname(fileURLToPath(import.meta.url));
30
+ const TOOLS_ARDY = join(HERE, "..");
31
+ const RUN_ON_BOX = join(TOOLS_ARDY, "run-on-box.sh");
32
+ const RUN_SEQUENCE_ON_BOX = join(TOOLS_ARDY, "run-sequence-on-box.sh");
33
+ const RUN_EDIT_ON_BOX = join(TOOLS_ARDY, "run-edit-on-box.sh");
34
+
35
+ // BatchMode: never hang on a password prompt. ConnectTimeout fails fast on a
36
+ // dead host; ServerAlive* drops a wedged connection (same set run-on-box.sh
37
+ // uses).
38
+ const SSH_OPTS = [
39
+ "-o", "BatchMode=yes",
40
+ "-o", "ConnectTimeout=10",
41
+ "-o", "ServerAliveInterval=30",
42
+ "-o", "ServerAliveCountMax=240",
43
+ ];
44
+
45
+ export function createRemoteRunner() {
46
+ // Same env var names as run-on-box.sh, so health, the bases listing and
47
+ // generation all talk to one operator-configured host/venv/encoder.
48
+ const HOST = process.env.CCLAY_ARDY_HOST?.trim() || "";
49
+ const REMOTE = process.env.CCLAY_ARDY_REPO || "$HOME/ardy"; // literal $HOME: the REMOTE shell expands it
50
+ const VENV_PY = process.env.CCLAY_ARDY_VENV || "~/ardy/.venv-cuda/bin/python"; // generator venv (tilde expands on the box)
51
+ const ENCODER_URL = process.env.CCLAY_ARDY_ENCODER_URL || "http://127.0.0.1:9550/";
52
+ // Numpy-only read paths (bases listing, reference dumps) use the CPU venv
53
+ // on purpose: the box's two venvs are NOT interchangeable, and this is the
54
+ // one the dump tooling is verified under.
55
+ const DUMP_PY = "~/ardy/.venv/bin/python";
56
+
57
+ if (!HOST) {
58
+ throw new Error("CCLAY_ARDY_HOST is required for the remote runner (for example: user@ardy-host)");
59
+ }
60
+
61
+ // Force the same box config onto the run-*-on-box.sh wrappers even when
62
+ // the bridge was started with different env values; they must not disagree.
63
+ function boxEnv() {
64
+ return {
65
+ ...process.env,
66
+ CCLAY_ARDY_HOST: HOST,
67
+ CCLAY_ARDY_REPO: REMOTE,
68
+ CCLAY_ARDY_VENV: VENV_PY,
69
+ CCLAY_ARDY_ENCODER_URL: ENCODER_URL,
70
+ };
71
+ }
72
+
73
+ // One ssh round trip covers everything health needs: the host answering is
74
+ // the ssh call itself, then the encoder HTTP code and the device the
75
+ // generator venv would pick are read on the box with the same env the
76
+ // generator runs under. The device line mirrors run-on-box.sh's probe
77
+ // exactly, so what health reports is what the generation will use.
78
+ function healthRemoteCmd() {
79
+ return [
80
+ `ENC="$(curl -s -o /dev/null -w '%{http_code}' -m 10 ${ENCODER_URL})"`,
81
+ '[ -n "$ENC" ] || ENC="000"',
82
+ `DEV="$(cd ${REMOTE} && ${VENV_PY} -c 'import torch; print("cuda:0" if torch.cuda.is_available() else "cpu")')"`,
83
+ `printf 'encoder=%s\\ndevice=%s\\n' "$ENC" "$DEV"`,
84
+ ].join(" && ");
85
+ }
86
+
87
+ async function probeHealth() {
88
+ const { code, stdout, stderr } = await run(
89
+ ["ssh", ...SSH_OPTS, HOST, healthRemoteCmd()],
90
+ { timeoutMs: 60_000 }
91
+ );
92
+ if (code !== 0) {
93
+ throw new Error(`ssh probe on ${HOST} failed (exit ${code}): ${lastLine(stderr)}`);
94
+ }
95
+ const fields = {};
96
+ for (const line of stdout.split("\n")) {
97
+ const match = /^(encoder|device)=(.*)$/.exec(line.trim());
98
+ if (match) fields[match[1]] = match[2];
99
+ }
100
+ if (!("encoder" in fields)) {
101
+ throw new Error(`encoder probe on ${HOST} produced no answer`);
102
+ }
103
+ if (fields.encoder !== "200") {
104
+ throw new Error(`text encoder at ${ENCODER_URL} answered ${fields.encoder}, not 200`);
105
+ }
106
+ if (!("device" in fields) || fields.device === "") {
107
+ const tail = lastLine(stderr);
108
+ throw new Error(
109
+ `device probe on ${HOST} produced no answer${tail ? `: ${tail}` : ""}`
110
+ );
111
+ }
112
+ if (!/^(cpu|cuda:\d+)$/.test(fields.device)) {
113
+ throw new Error(
114
+ `device probe on ${HOST} returned unexpected ${JSON.stringify(fields.device)}`
115
+ );
116
+ }
117
+ return { ok: true, host: HOST, encoder: Number(fields.encoder), device: fields.device };
118
+ }
119
+
120
+ // Frame counts come from a real load of each npz, in ONE ssh call: the
121
+ // script is fed to the box's python over a quoted heredoc (no local shell
122
+ // step), and entries that fail to load are skipped with a note on the box
123
+ // stderr instead of failing the whole listing.
124
+ function basesRemoteCmd() {
125
+ const script = [
126
+ "import glob, json, sys",
127
+ "import numpy as np",
128
+ "entries = []",
129
+ 'for pattern in ("outputs/*.npz", "outputs/omb/*.npz"):',
130
+ " for path in sorted(glob.glob(pattern)):",
131
+ " try:",
132
+ ' data = np.load(path, allow_pickle=False)',
133
+ ' frames = int(data["posed_joints"].shape[0])',
134
+ " data.close()",
135
+ " except Exception as exc:",
136
+ ' print("bases: skipping %s: %s" % (path, exc), file=sys.stderr)',
137
+ " continue",
138
+ ' entries.append({"id": path.rsplit("/", 1)[-1][:-4], "path": path, "frames": frames})',
139
+ "print(json.dumps(entries))",
140
+ ].join("\n");
141
+ return `cd ${REMOTE} && ${DUMP_PY} - <<'COZYCLAY_PY_EOF'\n${script}\nCOZYCLAY_PY_EOF`;
142
+ }
143
+
144
+ async function listBases() {
145
+ const { code, stdout, stderr } = await run(
146
+ ["ssh", ...SSH_OPTS, HOST, basesRemoteCmd()],
147
+ { timeoutMs: 120_000 }
148
+ );
149
+ if (code !== 0) {
150
+ throw new Error(`bases listing on ${HOST} failed (exit ${code}): ${lastLine(stderr)}`);
151
+ }
152
+ let entries;
153
+ try {
154
+ entries = JSON.parse(stdout);
155
+ } catch (err) {
156
+ throw new Error(
157
+ `bases listing on ${HOST} did not parse as JSON: ${lastLine(stderr) || err.message}`
158
+ );
159
+ }
160
+ if (!Array.isArray(entries)) {
161
+ throw new Error(`bases listing on ${HOST} was not an array`);
162
+ }
163
+ return entries;
164
+ }
165
+
166
+ // --- generation argv builders -----------------------------------------
167
+ // Each returns what the bridge needs to spawn ONE child whose stdout ends
168
+ // in a done marker: pose/waypoint/free single runs, autoregressive
169
+ // sequence runs, and context-aware motion edits.
170
+
171
+ function singleCommand({ poseFroms, basePath, prompt, durationS, seed, cpu, waypoints, rootMargin, contactThreshold, historyFrames, output }) {
172
+ const args = [RUN_ON_BOX];
173
+ for (const entry of poseFroms) {
174
+ args.push("--pose-from", entry.npz, String(entry.srcFrame), String(entry.dstFrame));
175
+ }
176
+ if (basePath) args.push("--base", basePath);
177
+ args.push("--prompt", prompt, "--duration", String(durationS));
178
+ if (Number.isInteger(seed)) args.push("--seed", String(seed));
179
+ if (cpu === true) args.push("--cpu");
180
+ for (const wp of waypoints || []) {
181
+ args.push("--root-2d", String(wp.frame), String(wp.x), String(wp.z), wp.heading === null ? "none" : String(wp.heading));
182
+ }
183
+ if (Number.isFinite(rootMargin)) args.push("--root-margin", String(rootMargin));
184
+ if (Number.isFinite(contactThreshold)) args.push("--contact-threshold", String(contactThreshold));
185
+ if (Number.isInteger(historyFrames)) args.push("--history-frames", String(historyFrames));
186
+ args.push("--output", output);
187
+ return {
188
+ command: "bash",
189
+ args,
190
+ env: boxEnv(),
191
+ doneRe: /^run-on-box: done - (.+) \((\d+) bytes\)$/,
192
+ label: "run-on-box",
193
+ };
194
+ }
195
+
196
+ function sequenceCommand({ segments, waypoints, seed, cpu, rootMargin, contactThreshold, historyFrames, output }) {
197
+ const args = [RUN_SEQUENCE_ON_BOX];
198
+ for (const segment of segments) {
199
+ args.push("--segment", segment.prompt, String(segment.durationS));
200
+ }
201
+ // Root waypoints ride the same chained rollout (rollout-global frames):
202
+ // the sequence generator slices the constraint set per segment call, so
203
+ // a path and a prompt schedule coexist.
204
+ for (const wp of waypoints || []) {
205
+ args.push("--root-2d", String(wp.frame), String(wp.x), String(wp.z), wp.heading === null ? "none" : String(wp.heading));
206
+ }
207
+ if (Number.isInteger(seed)) args.push("--seed", String(seed));
208
+ if (cpu === true) args.push("--cpu");
209
+ if (Number.isFinite(rootMargin)) args.push("--root-margin", String(rootMargin));
210
+ if (Number.isFinite(contactThreshold)) args.push("--contact-threshold", String(contactThreshold));
211
+ if (Number.isInteger(historyFrames)) args.push("--history-frames", String(historyFrames));
212
+ args.push("--output", output);
213
+ return {
214
+ command: "bash",
215
+ args,
216
+ env: boxEnv(),
217
+ doneRe: /^run-sequence-on-box: done - (.+) \((\d+) bytes\)$/,
218
+ label: "run-sequence-on-box",
219
+ };
220
+ }
221
+
222
+ function editCommand({ source, manifest, prompt, contextBefore, contextAfter, seed, poseNpzPaths, output }) {
223
+ const args = [
224
+ RUN_EDIT_ON_BOX,
225
+ "--source", source,
226
+ "--manifest", manifest,
227
+ "--prompt", prompt,
228
+ "--context-before", String(contextBefore),
229
+ "--context-after", String(contextAfter),
230
+ "--output", output,
231
+ ];
232
+ if (Number.isInteger(seed)) args.push("--seed", String(seed));
233
+ for (const posePath of poseNpzPaths) args.push("--pose", posePath);
234
+ return {
235
+ command: "bash",
236
+ args,
237
+ env: boxEnv(),
238
+ doneRe: /^run-edit-on-box: done - (.+) \((\d+) bytes\)$/,
239
+ label: "run-edit-on-box",
240
+ };
241
+ }
242
+
243
+ return {
244
+ mode: "remote",
245
+ describe: () => `box ${HOST} (repo ${REMOTE}, generator venv ${VENV_PY}, encoder ${ENCODER_URL})`,
246
+ probeHealth,
247
+ listBases,
248
+ singleCommand,
249
+ sequenceCommand,
250
+ editCommand,
251
+ };
252
+ }
@@ -0,0 +1,189 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * setup-local.mjs - provision local ARDY motion generation for CozyClay.
4
+ *
5
+ * node tools/ardy/setup-local.mjs [--skip-checkpoint] [--skip-encoder]
6
+ *
7
+ * Everything lands OUTSIDE this repo, in a per-user directory; the repo
8
+ * never contains model weights. All downloads come from their official
9
+ * sources, pinned or content-verified:
10
+ *
11
+ * ~/.cozyclay/ardy git clone of github.com/nv-tlabs/ardy
12
+ * (Apache-2.0) + a python venv with torch,
13
+ * ardy, gradio
14
+ * HF hub cache nvidia/ARDY-Core-RP-20FPS-Horizon40 motion
15
+ * checkpoint via huggingface_hub (NVIDIA Open
16
+ * Model License)
17
+ * ~/.cozyclay/text-encoders Llama-3-8B + LLM2Vec encoder stack from
18
+ * public, ungated mirrors, every shard
19
+ * SHA-256-verified (setup-text-encoder.py),
20
+ * then LoRA-merged in place
21
+ * (merge-text-encoder.py); ~16.4 GB, resumable
22
+ *
23
+ * Every step is idempotent: re-running verifies and fills gaps only.
24
+ * Overrides: CCLAY_ARDY_LOCAL_DIR, CCLAY_ARDY_ENCODERS_DIR, CCLAY_ARDY_PYTHON.
25
+ *
26
+ * torch note: `pip install torch` gives CUDA wheels on Linux and MPS wheels
27
+ * on Apple Silicon out of the box. On Windows, install a CUDA build first if
28
+ * you want GPU generation:
29
+ * <venv>\Scripts\python -m pip install torch --index-url https://download.pytorch.org/whl/cu126
30
+ */
31
+
32
+ import { spawnSync } from "node:child_process";
33
+ import { existsSync } from "node:fs";
34
+ import { homedir } from "node:os";
35
+ import { dirname, join } from "node:path";
36
+ import { fileURLToPath } from "node:url";
37
+
38
+ const HERE = dirname(fileURLToPath(import.meta.url));
39
+ const ARDY_GIT_URL = "https://github.com/nv-tlabs/ardy.git";
40
+ const ARDY_CHECKPOINT = "nvidia/ARDY-Core-RP-20FPS-Horizon40";
41
+ const LOCAL_DIR = process.env.CCLAY_ARDY_LOCAL_DIR || join(homedir(), ".cozyclay", "ardy");
42
+ const ENCODERS_DIR = process.env.CCLAY_ARDY_ENCODERS_DIR || join(homedir(), ".cozyclay", "text-encoders");
43
+ const IS_WIN = process.platform === "win32";
44
+ const VENV_DIR = join(LOCAL_DIR, ".venv");
45
+ const VENV_PY = join(VENV_DIR, IS_WIN ? "Scripts\\python.exe" : "bin/python");
46
+
47
+ const skipCheckpoint = process.argv.includes("--skip-checkpoint");
48
+ const skipEncoder = process.argv.includes("--skip-encoder");
49
+
50
+ function log(message) {
51
+ console.log(`setup-local: ${message}`);
52
+ }
53
+
54
+ function die(message) {
55
+ console.error(`setup-local: ${message}`);
56
+ process.exit(1);
57
+ }
58
+
59
+ // Run a step to completion with output visible; die with context on failure.
60
+ function run(label, argv, options = {}) {
61
+ log(label);
62
+ const result = spawnSync(argv[0], argv.slice(1), { stdio: "inherit", ...options });
63
+ if (result.error) die(`${label} failed: ${result.error.message}`);
64
+ if (result.status !== 0) die(`${label} failed (exit ${result.status})`);
65
+ }
66
+
67
+ function probe(argv) {
68
+ const result = spawnSync(argv[0], argv.slice(1), { encoding: "utf8" });
69
+ return result.status === 0 ? (result.stdout || "").trim() : null;
70
+ }
71
+
72
+ // --- prerequisites ----------------------------------------------------------
73
+
74
+ if (!probe(["git", "--version"])) die("git is required (https://git-scm.com)");
75
+ if (!probe(["cmake", "--version"])) {
76
+ die(
77
+ "cmake is required to build ARDY's motion-correction extension.\n" +
78
+ " macOS: brew install cmake\n" +
79
+ " Linux: apt/dnf install cmake\n" +
80
+ " Windows: winget install Kitware.CMake"
81
+ );
82
+ }
83
+
84
+ // Python 3.10+ — ARDY's floor. Prefer an explicit override, then the newest
85
+ // commonly-installed minor, then the bare python3.
86
+ function findPython() {
87
+ const candidates = process.env.CCLAY_ARDY_PYTHON
88
+ ? [process.env.CCLAY_ARDY_PYTHON]
89
+ : ["python3.12", "python3.11", "python3.10", "python3", "python"];
90
+ for (const candidate of candidates) {
91
+ const version = probe([candidate, "-c", "import sys; print('%d.%d' % sys.version_info[:2])"]);
92
+ if (!version) continue;
93
+ const [major, minor] = version.split(".").map(Number);
94
+ if (major === 3 && minor >= 10) return { python: candidate, version };
95
+ }
96
+ return null;
97
+ }
98
+
99
+ const found = findPython();
100
+ if (!found) {
101
+ die(
102
+ "python 3.10+ not found (ARDY requires >=3.10).\n" +
103
+ " install one (e.g. `brew install python@3.12` / `uv python install 3.12`)\n" +
104
+ " or point CCLAY_ARDY_PYTHON at an interpreter"
105
+ );
106
+ }
107
+ log(`using ${found.python} (${found.version})`);
108
+
109
+ // --- ARDY checkout + venv ----------------------------------------------------
110
+
111
+ if (existsSync(join(LOCAL_DIR, "pyproject.toml"))) {
112
+ log(`ARDY checkout already present at ${LOCAL_DIR}`);
113
+ } else if (existsSync(LOCAL_DIR)) {
114
+ die(`${LOCAL_DIR} exists but is not an ARDY checkout; move it aside or set CCLAY_ARDY_LOCAL_DIR`);
115
+ } else {
116
+ run(`cloning ${ARDY_GIT_URL} -> ${LOCAL_DIR}`, ["git", "clone", "--depth", "1", ARDY_GIT_URL, LOCAL_DIR]);
117
+ }
118
+
119
+ if (existsSync(VENV_PY)) {
120
+ log(`venv already present at ${VENV_DIR}`);
121
+ } else {
122
+ run(`creating venv at ${VENV_DIR}`, [found.python, "-m", "venv", VENV_DIR]);
123
+ }
124
+
125
+ function pipHas(module) {
126
+ return probe([VENV_PY, "-c", `import ${module}`]) !== null;
127
+ }
128
+
129
+ run("upgrading pip", [VENV_PY, "-m", "pip", "install", "--quiet", "--upgrade", "pip"]);
130
+ if (pipHas("torch")) {
131
+ log("torch already installed");
132
+ } else {
133
+ // Default wheels: CUDA on Linux, MPS on Apple Silicon, CPU on Windows
134
+ // (see the header for the Windows CUDA index-url).
135
+ run("installing torch (this downloads a large wheel)", [VENV_PY, "-m", "pip", "install", "torch"]);
136
+ }
137
+ if (pipHas("ardy")) {
138
+ log("ardy package already installed");
139
+ } else {
140
+ // Core only — never [all]: the trt extra is Linux/CUDA-only and the demo
141
+ // extra is not needed for generation. The C++ extension builds here
142
+ // (cmake); it may fetch pybind11/Eigen/sse2neon from their upstreams.
143
+ run("installing ARDY into the venv (builds a small C++ extension)", [
144
+ VENV_PY, "-m", "pip", "install", "-e", LOCAL_DIR,
145
+ ]);
146
+ }
147
+ if (pipHas("gradio")) {
148
+ log("gradio already installed");
149
+ } else {
150
+ // Only the text-encoder *server* needs gradio; the generator's client side
151
+ // (gradio_client) is an ARDY core dependency already.
152
+ run("installing gradio (text-encoder service)", [VENV_PY, "-m", "pip", "install", "gradio"]);
153
+ }
154
+
155
+ // --- ARDY motion checkpoint (HF hub, auto-cached) ----------------------------
156
+
157
+ if (skipCheckpoint) {
158
+ log("skipping motion checkpoint download (--skip-checkpoint)");
159
+ } else {
160
+ run(`fetching motion checkpoint ${ARDY_CHECKPOINT} into the HF cache`, [
161
+ VENV_PY,
162
+ "-c",
163
+ [
164
+ "from huggingface_hub import snapshot_download",
165
+ `path = snapshot_download(repo_id=${JSON.stringify(ARDY_CHECKPOINT)})`,
166
+ "print('checkpoint at', path)",
167
+ ].join("\n"),
168
+ ]);
169
+ }
170
+
171
+ // --- text-encoder weights (public mirrors, SHA-256 pinned) -------------------
172
+
173
+ if (skipEncoder) {
174
+ log("skipping text-encoder weights (--skip-encoder)");
175
+ } else {
176
+ run(`downloading/verifying encoder stack under ${ENCODERS_DIR} (~16.4 GB, resumable)`, [
177
+ VENV_PY, join(HERE, "setup-text-encoder.py"), "--dest", ENCODERS_DIR,
178
+ ]);
179
+ // Bake the MNTP LoRA into a full model (idempotent via MERGE_MANIFEST):
180
+ // transformers v5 cannot chase adapter dirs the way ARDY's loader expects.
181
+ run("merging MNTP LoRA into the base weights (one-time, needs RAM)", [
182
+ VENV_PY, join(HERE, "merge-text-encoder.py"), "--dest", ENCODERS_DIR,
183
+ ], { cwd: LOCAL_DIR });
184
+ }
185
+
186
+ log("done. start CozyClay with `npm run dev` — the bridge auto-selects local mode");
187
+ log(` ARDY: ${LOCAL_DIR}`);
188
+ log(` encoder: ${ENCODERS_DIR} (lazy service on first generation)`);
189
+ log(" remote box users: CCLAY_ARDY_HOST keeps selecting the ssh backend");
@@ -0,0 +1,93 @@
1
+ #!/usr/bin/env bash
2
+ # setup-text-encoder-on-box.sh - provision the ARDY text-encoder models on the
3
+ # remote box WITHOUT a Hugging Face account, gated-access approval, or token.
4
+ #
5
+ # CCLAY_ARDY_HOST=user@gpu-box tools/ardy/setup-text-encoder-on-box.sh
6
+ # ... --verify-only re-hash an existing tree on the box, download nothing
7
+ #
8
+ # Copies setup-text-encoder.py to a fresh remote temp dir (nothing is written
9
+ # inside the ARDY checkout, same rule as run-on-box.sh), runs it with the
10
+ # box's python3, and removes the script afterwards. The models land under
11
+ # CCLAY_ARDY_ENCODERS_DIR (default ~/cclay-text-encoders on the box, kept
12
+ # across re-runs; re-running only verifies and fills gaps).
13
+ #
14
+ # env (names shared with run-on-box.sh / sync-to-box):
15
+ # CCLAY_ARDY_HOST ssh destination for the ARDY host (required)
16
+ # CCLAY_ARDY_ENCODERS_DIR TEXT_ENCODERS_DIR on the box
17
+ # (default $HOME/cclay-text-encoders, box-side)
18
+ # CCLAY_ARDY_REPO ARDY checkout on the box (default $HOME/ardy)
19
+ # CCLAY_ARDY_ENC_VENV encoder venv python on the box
20
+ # (default ~/ardy/.venv/bin/python — the CPU
21
+ # text-encoder venv, NOT the .venv-cuda generator)
22
+ set -euo pipefail
23
+
24
+ HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
25
+ HOST="${CCLAY_ARDY_HOST:-}"
26
+ # Escaped so the REMOTE shell expands $HOME, the same trick run-on-box.sh uses.
27
+ ENCODERS_DIR="${CCLAY_ARDY_ENCODERS_DIR:-\$HOME/cclay-text-encoders}"
28
+ REPO="${CCLAY_ARDY_REPO:-\$HOME/ardy}"
29
+ # Literal ~ so the REMOTE shell tilde-expands it, like run-on-box.sh's VENV_PY.
30
+ VENV_PY="${CCLAY_ARDY_ENC_VENV:-~/ardy/.venv/bin/python}"
31
+
32
+ [[ -n "$HOST" ]] || {
33
+ echo "setup-text-encoder-on-box: set CCLAY_ARDY_HOST (e.g. user@gpu-box)" >&2
34
+ exit 1
35
+ }
36
+
37
+ SSH_OPTS=(-o BatchMode=yes -o ConnectTimeout=10 -o ServerAliveInterval=30 -o ServerAliveCountMax=240)
38
+ SCP_OPTS=(-o BatchMode=yes -o ConnectTimeout=10)
39
+
40
+ if ! ssh "${SSH_OPTS[@]}" "$HOST" ":" </dev/null; then
41
+ echo "setup-text-encoder-on-box: cannot ssh to ${HOST}" >&2
42
+ exit 1
43
+ fi
44
+ echo "setup-text-encoder-on-box: ssh to ${HOST} ok"
45
+
46
+ if ! REMOTE_TMP="$(ssh "${SSH_OPTS[@]}" "$HOST" "mktemp -d" </dev/null)"; then
47
+ echo "setup-text-encoder-on-box: mktemp on ${HOST} failed" >&2
48
+ exit 1
49
+ fi
50
+ [[ "$REMOTE_TMP" == /* ]] || {
51
+ echo "setup-text-encoder-on-box: remote mktemp returned non-absolute '${REMOTE_TMP}'; aborting" >&2
52
+ exit 1
53
+ }
54
+ trap 'ssh "${SSH_OPTS[@]}" "$HOST" "rm -rf ${REMOTE_TMP}" </dev/null >/dev/null 2>&1 || true' EXIT
55
+
56
+ scp -q "${SCP_OPTS[@]}" "${HERE}/setup-text-encoder.py" "$HOST:${REMOTE_TMP}/setup-text-encoder.py"
57
+ scp -q "${SCP_OPTS[@]}" "${HERE}/merge-text-encoder.py" "$HOST:${REMOTE_TMP}/merge-text-encoder.py"
58
+
59
+ # Forward optional flags (--verify-only / --print-plan) verbatim; each one is
60
+ # %q-quoted like every other remote arg in this toolset.
61
+ EXTRA=""
62
+ for arg in "$@"; do
63
+ EXTRA+=" $(printf '%q' "$arg")"
64
+ done
65
+
66
+ # shellcheck disable=SC2029 # ENCODERS_DIR/REMOTE_TMP expand remotely by design
67
+ ssh "${SSH_OPTS[@]}" "$HOST" \
68
+ "python3 ${REMOTE_TMP}/setup-text-encoder.py --dest \"${ENCODERS_DIR}\"${EXTRA}" </dev/null
69
+
70
+ # Bake the MNTP merge unless this was a flag-only run (--verify-only /
71
+ # --print-plan download nothing, so there is nothing new to merge). The merge
72
+ # runs inside the ARDY checkout under the encoder venv (torch + peft + the
73
+ # ardy package) and is idempotent: it no-ops when the merged model already
74
+ # matches the adapter hash.
75
+ if [[ -z "$EXTRA" ]]; then
76
+ # shellcheck disable=SC2029 # remote expansion by design
77
+ ssh "${SSH_OPTS[@]}" "$HOST" \
78
+ "cd ${REPO} && ${VENV_PY} ${REMOTE_TMP}/merge-text-encoder.py --dest \"${ENCODERS_DIR}\"" </dev/null
79
+ fi
80
+
81
+ cat <<'EOF'
82
+
83
+ setup-text-encoder-on-box: done.
84
+
85
+ Restart the text-encoder service on the box with TEXT_ENCODERS_DIR set, e.g.:
86
+
87
+ ssh $CCLAY_ARDY_HOST
88
+ cd ~/ardy
89
+ TEXT_ENCODERS_DIR=$HOME/cclay-text-encoders \
90
+ .venv/bin/python scripts/run_text_encoder_server.py
91
+
92
+ No Hugging Face login or token is needed on the box from now on.
93
+ EOF