@hypersocial/decks-cli 0.9.22 → 0.9.23

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hypersocial/decks-cli",
3
- "version": "0.9.22",
3
+ "version": "0.9.23",
4
4
  "description": "Command-line client for Hypersocial Decks live analytics and share management.",
5
5
  "type": "module",
6
6
  "main": "./src/commands.mjs",
@@ -2,7 +2,7 @@
2
2
  name: hyperdecks
3
3
  description: Use when asked to make, narrate, check or ship a deck ("make me a narrated deck", "turn this into a deck and send it"), or when working with Hypersocial Decks, Hyperdecks CLI, production deck analytics, recipient share links, deck activity, MCP deck tools, or real-world/customer-facing deck checks. Prefer production for real activity and analytics; use development only for local implementation/testing when explicitly requested.
4
4
  metadata:
5
- version: "0.9.22"
5
+ version: "0.9.23"
6
6
  ---
7
7
 
8
8
  # Hyperdecks
@@ -314,6 +314,40 @@ async function within(promise, ms, fallback) {
314
314
  finally { clearTimeout(timer); }
315
315
  }
316
316
 
317
+ // Stepped heads (packages/player/stepped-heads.js): a player whose Minimoji
318
+ // bundle has createManualClock publishes window.__hdExportHeads, and each head
319
+ // draws only when the recorder steps its clock. Real milliseconds a head may
320
+ // take to report ready: the player's export head budget (HEAD_BUDGET).
321
+ export const HEAD_READY_MS = 30000;
322
+
323
+ // Waits until every stepped head the page has can draw (`clock.ready`, the
324
+ // SDK's word), then draws each one's current frame (a step of 0). A page
325
+ // without stepped heads (an older bundle, no head) passes at once. A head that
326
+ // is not ready in `ms` fails the export with a plain message (as would a
327
+ // rejected ready, though the SDK's settles even on a failed load).
328
+ export async function waitForHeads(page, ms = HEAD_READY_MS, { draw = true } = {}) {
329
+ const said = await within(page.evaluate(async (draw) => {
330
+ const heads = window.__hdExportHeads;
331
+ if (!heads) return { count: 0 };
332
+ try {
333
+ const count = await heads.ready();
334
+ // Before the first frame (real time still runs): each head measures its settled box (stepped-heads.js remeasure).
335
+ if (draw) { await heads.remeasure?.(); heads.step(0); }
336
+ return { count };
337
+ } catch (e) { return { error: String(e?.message ?? e) }; }
338
+ }, draw), ms, null);
339
+ if (!said) throw new Error(`the deck's live head was not ready to draw after ${Math.round(ms / 1000)}s (its model, or its narration lines still loading); nothing more was recorded`);
340
+ if (said.error) throw new Error(`the deck's live head could not draw: ${said.error}`);
341
+ return said.count;
342
+ }
343
+
344
+ // Freezes the page clock once every stepped head is ready: frame 0 is the deck
345
+ // as it starts, with its heads drawn. Returns the clock's epoch ms at freeze.
346
+ export async function freezeWhenHeadsReady(page, ms = HEAD_READY_MS) {
347
+ await waitForHeads(page, ms);
348
+ return page.evaluate(() => performance.timeOrigin + window.__hdFrameClock.freeze());
349
+ }
350
+
317
351
  // The player's export log, read without trusting the page to answer quickly.
318
352
  // undefined when it did not answer within `ms`.
319
353
  const readLog = (page, ms = 5000) => within(page.evaluate(() => {
@@ -439,6 +473,8 @@ export async function recordVideo(config, { log = () => {}, chromium: injected,
439
473
  // A range opens on its first slide (export-mode.js exportRangeStart).
440
474
  if (config.range?.from > 0) await context.addInitScript((from) => { window.__hdExportFrom = from; }, config.range.from);
441
475
  await context.addInitScript(() => {
476
+ // This recorder steps stepped heads' clocks (waitForHeads, the frame loop): the player may use them.
477
+ window.__hdStepsHeads = true;
442
478
  navigator.sendBeacon = () => false;
443
479
  window.open = () => null;
444
480
  // The player's export mode waits for this before it plays (export-mode.js).
@@ -559,26 +595,42 @@ export async function recordVideo(config, { log = () => {}, chromium: injected,
559
595
  written.catch(() => {});
560
596
  };
561
597
  // Frame 0 is the deck as it starts; frame n shows it n/fps seconds later on the page clock.
562
- const markMs = await page.evaluate(() => performance.timeOrigin + window.__hdFrameClock.freeze());
598
+ // Not before every stepped head is ready (waitForHeads).
599
+ const markMs = await freezeWhenHeadsReady(page);
563
600
  // Each clip ends where its real audio does (the manifest's length can be off), as <audio> would end it.
564
601
  // A range's tour ends after its last slide (export-mode.js exportRangeEnd).
565
602
  await page.evaluate(({ lengths, to }) => { window.__hdExportClipLengths = lengths; if (to != null) window.__hdExportTo = to; window.__hdExportGo(); return window.__hdFrameClock.settle(); }, { lengths: clipLengths, to: range ? to : null });
566
603
  const firstFrame = frameCount;
567
604
  await capture();
568
605
  const secondsOf = new Map(plan.ids.map((id, i) => [id, plan.seconds[i]]));
569
- let shown = 0, progress = 0, movedAt = 0, end = Infinity;
606
+ let shown = 0, progress = 0, movedAt = 0, end = Infinity, waited = 0;
570
607
  // A segment's seam frames (SEAM_FRAMES): recorded past its end, dropped from its start.
571
608
  const tail = segment && to < last ? SEAM_FRAMES : 0, skip = segment && from > 0 ? SEAM_FRAMES : 0;
572
609
  // Stuck: no slide landed and no clip started for longer than the current
573
610
  // slide's planned clip and hold (unknown for a data-clip deck) plus a grace, on the page clock.
574
611
  for (let n = 1; n < end; n++) {
612
+ // Each stepped head moves by the same 1/fps after the page clock, once
613
+ // per frame (a stepped head ignores requestAnimationFrame). One that
614
+ // mounted this frame (a guest's slide came near) is waited for first.
575
615
  const step = await within(page.evaluate(async (ms) => {
576
616
  const t = window.__hdFrameClock.step(ms);
577
617
  await window.__hdFrameClock.settle();
618
+ const heads = window.__hdExportHeads;
619
+ // A line that started loading this frame finishes before the heads move (bounded by FRAME_TIMEOUT_MS).
620
+ await heads?.settled?.();
621
+ const waiting = heads ? !(await heads.idle().catch(() => false)) : false;
622
+ if (heads && !waiting) heads.step(ms / 1000);
578
623
  const l = window.__hdExport;
579
- return { t, moved: l.slides.length + l.clips.length, errors: l.errors.length, done: l.done };
624
+ return { t, moved: l.slides.length + l.clips.length, errors: l.errors.length, done: l.done, waiting };
580
625
  }, 1000 / fps), FRAME_TIMEOUT_MS, null);
581
626
  if (!step) throw new Error(`the page stopped answering (a frame took over ${FRAME_TIMEOUT_MS / 1000}s to draw)${pageSaid()}`);
627
+ if (step.waiting) {
628
+ // No extra draw: a step of 0 still moves a head's smoothing, so a frame that waited would differ.
629
+ waited++;
630
+ await waitForHeads(page, HEAD_READY_MS, { draw: false });
631
+ const stepped = await within(page.evaluate((s) => window.__hdExportHeads.step(s), 1 / fps), FRAME_TIMEOUT_MS, null);
632
+ if (stepped == null) throw new Error(`the page stopped answering (a head took over ${FRAME_TIMEOUT_MS / 1000}s to draw)${pageSaid()}`);
633
+ }
582
634
  await capture();
583
635
  const at = n / fps;
584
636
  if (step.moved !== progress || step.errors || (step.done && end === Infinity)) {
@@ -605,6 +657,7 @@ export async function recordVideo(config, { log = () => {}, chromium: injected,
605
657
  const seconds = frames / fps;
606
658
  const wall = (Date.now() - startedAt) / 1000;
607
659
  log(`rendered ${frames} frames (${clock(seconds)}) in ${clock(wall)}: ${(frames / Math.max(0.001, wall)).toFixed(1)} frames a second, ${(wall / Math.max(0.001, seconds)).toFixed(1)}× the video's length`);
660
+ if (waited) log(`waited for a head to finish loading on ${waited} frame(s)`);
608
661
  // Drift means something only when every clip's planned length is known (a data-clip deck's are not).
609
662
  const drift = (state.plan ?? []).every((s) => !s.audio || s.duration > 0) ? timelineDrift(state, markMs) : [];
610
663
  const worst = drift.reduce((a, d) => (Math.abs(d.drift) > Math.abs(a.drift) ? d : a), { drift: 0 });
@@ -236,13 +236,17 @@ export function installFrameClock(win) {
236
236
  step(ms) {
237
237
  if (!frozen) throw new Error('the frame clock is not frozen');
238
238
  const target = t + Math.max(0, Number(ms) || 0);
239
+ // A timer due on the frame's edge (a clip that ends on a frame time) fires in this frame
240
+ // whatever float noise the clock's origin (the real time at freeze) leaves in `due`:
241
+ // otherwise one export ends a line a frame later than another.
242
+ const EDGE_MS = 0.001;
239
243
  // A timer that keeps re-arming itself at 0 ms must not hang the step: it is reported, as a page error.
240
244
  for (let guard = 0; ; guard++) {
241
245
  let next = null, nextId = 0;
242
- for (const [id, x] of timers) if (x.due <= target && (!next || x.due < next.due || (x.due === next.due && id < nextId))) { next = x; nextId = id; }
246
+ for (const [id, x] of timers) if (x.due <= target + EDGE_MS && (!next || x.due < next.due || (x.due === next.due && id < nextId))) { next = x; nextId = id; }
243
247
  if (!next) break;
244
248
  if (guard === 100000) { report(new Error('a timer re-armed itself 100000 times in one video frame; the rest wait for the next frame')); break; }
245
- t = Math.max(t, next.due);
249
+ t = Math.min(target, Math.max(t, next.due));
246
250
  fire(nextId);
247
251
  }
248
252
  t = target;
@@ -17,7 +17,7 @@ import { mkdtemp, readFile, rm, writeFile } from 'node:fs/promises';
17
17
  import { tmpdir } from 'node:os';
18
18
  import { extname, join } from 'node:path';
19
19
  import { installFrameClock } from './frame-clock.mjs';
20
- import { exportPageUrl, launchRecorder, planTimeline } from './export-video.mjs';
20
+ import { exportPageUrl, launchRecorder, planTimeline, waitForHeads } from './export-video.mjs';
21
21
  import { recorderArgs, redactCaptureUrl, routeCaptureRequest } from './preview-capture.mjs';
22
22
 
23
23
  // Page-clock milliseconds per step while seeking to `start`: timers fire in
@@ -145,6 +145,8 @@ export async function recordMoment(config, { chromium, serveSource, dir, net = {
145
145
  }
146
146
  await context.routeWebSocket('**/*', (ws) => ws.close());
147
147
  await context.addInitScript({ content: `(${installFrameClock.toString()})(window);` });
148
+ // This recorder steps stepped heads' clocks (stepped-heads.js) with the page clock.
149
+ await context.addInitScript(() => { window.__hdStepsHeads = true; });
148
150
  // The player opens on __hdExportFrom, read once its slides are in the page:
149
151
  // the scene's index among them, as the player lists them (section.slide in order).
150
152
  // An unknown scene opens the first slide; seekTarget then refuses it by name.
@@ -171,7 +173,9 @@ export async function recordMoment(config, { chromium, serveSource, dir, net = {
171
173
  if (answer === none) throw new Error(`the page stopped answering ${what} (over 30s)`);
172
174
  return answer;
173
175
  };
174
- const step = (ms, what) => ask(async (ms) => { window.__hdFrameClock.step(ms); await window.__hdFrameClock.settle(); return window.__hdExport; }, ms, what);
176
+ // A stepped head (a bundle with createManualClock, packages/player/stepped-heads.js) draws only
177
+ // when its clock steps: it moves with the page clock, after it, as in the video export.
178
+ const step = (ms, what) => ask(async (ms) => { window.__hdFrameClock.step(ms); await window.__hdFrameClock.settle(); window.__hdExportHeads?.step(ms / 1000); return window.__hdExport; }, ms, what);
175
179
  phase = 'page load';
176
180
  await page.goto(pageUrl, { waitUntil: 'domcontentloaded', timeout: 30000 });
177
181
  phase = 'player ready';
@@ -230,6 +234,10 @@ export async function recordMoment(config, { chromium, serveSource, dir, net = {
230
234
  phase = 'heads';
231
235
  await headsSettled({ retries: true });
232
236
 
237
+ // A stepped head reports ready only once its model and textures are in (the head-slot
238
+ // state says ready at mount); it draws its first frame here, before the clock freezes.
239
+ await waitForHeads(page);
240
+
233
241
  phase = 'seek';
234
242
  // Clip lengths come from the manifest (player.js clipLength), as a recipient's <audio> would roughly end them.
235
243
  await ask(async () => {
package/src/runtime.mjs CHANGED
@@ -9,7 +9,7 @@ import { ConvexHttpClient } from "convex/browser";
9
9
  import { makeFunctionReference } from "convex/server";
10
10
  import { recordSkillInstall } from "./skillFreshness.mjs";
11
11
 
12
- export const VERSION = "0.9.22";
12
+ export const VERSION = "0.9.23";
13
13
 
14
14
  // Sent on the CLI's calls to our routes and to Convex, so the server can see
15
15
  // which CLI versions are still out there (not used to refuse anything).