claude-code-session-manager 0.142.0 → 0.143.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/.claude-plugin/marketplace.json +1 -1
- package/README.md +20 -107
- package/dist/assets/{AppSettings-BcZgIvvY.js → AppSettings-BO4jDVGO.js} +1 -1
- package/dist/assets/{History-DpZuJXi1.js → History-DTttbvPb.js} +1 -1
- package/dist/assets/{HomeClaudeConfig-D32ZJtU-.js → HomeClaudeConfig-DADP5bfn.js} +2 -2
- package/dist/assets/{Panel-BjdJjhqt.js → Panel-B_D4Bg7L.js} +1 -1
- package/dist/assets/{ProjectClaudeConfig-BTClYV6i.js → ProjectClaudeConfig-DPnDJKcr.js} +1 -1
- package/dist/assets/{Scheduler-DPobKx1Z.js → Scheduler-CNLjn90m.js} +8 -8
- package/dist/assets/{SkillReferenceGraph-Cqyu4mef.js → SkillReferenceGraph-D1b2aiol.js} +1 -1
- package/dist/assets/{Skills-vv0noNVI.js → Skills-cfV7sgk6.js} +1 -1
- package/dist/assets/{TiptapBody-CXi8Pvut.js → TiptapBody-DVXtEIVy.js} +1 -1
- package/dist/assets/{Toggle-CiYCWLjh.js → Toggle-CYajnSdx.js} +1 -1
- package/dist/assets/{VoiceButton-4NKKd1sC.js → VoiceButton-DJ4gGRuE.js} +1 -1
- package/dist/assets/{historyTotals-DDunb8Ch.js → historyTotals-D3MoHY2U.js} +1 -1
- package/dist/assets/{index-Cn5E9958.js → index-CdTppjKR.js} +436 -436
- package/dist/index.html +1 -1
- package/dist-web/app.js +356 -356
- package/package.json +3 -3
- package/plugins/session-manager-dev/.claude-plugin/plugin.json +1 -1
- package/plugins/session-manager-dev/skills/builder/SKILL.md +5 -0
- package/plugins/session-manager-dev/skills/develop/SKILL.md +9 -3
- package/scripts/README.md +1 -0
- package/scripts/scheduler-mcp-server.cjs +304 -6
- package/src/main/adminRouteRegistry.cjs +10 -0
- package/src/main/build-info.json +4 -4
- package/src/main/chatRunner.cjs +105 -7
- package/src/main/config.cjs +5 -1
- package/src/main/health.cjs +38 -2
- package/src/main/index.cjs +12 -4
- package/src/main/ipcSchemas.cjs +11 -0
- package/src/main/lib/demo-video-kit/cast.md +10 -1
- package/src/main/lib/demo-video-kit/character.cjs +77 -21
- package/src/main/lib/demo-video-kit/kind-tiktok.md +5 -1
- package/src/main/lib/demo-video-kit/projectSounds.cjs +191 -0
- package/src/main/lib/demo-video-kit/seedKit.cjs +3 -3
- package/src/main/lib/demo-video-kit/sound.cjs +166 -9
- package/src/main/lib/demo-video-kit/standalone.cjs +231 -0
- package/src/main/lib/epic/activeIndexMerge.cjs +5 -0
- package/src/main/lib/epic/artifactRetention.cjs +55 -9
- package/src/main/lib/epic/artifactStore.cjs +78 -35
- package/src/main/lib/epic/delegationReadiness.cjs +10 -3
- package/src/main/lib/epic/epicEventLog.cjs +45 -1
- package/src/main/lib/epic/epicStateEmitter.cjs +248 -0
- package/src/main/lib/epic/epicValidationHook.cjs +13 -2
- package/src/main/lib/externalContract.cjs +12 -1
- package/src/main/lib/feedback-remote/autoStartedSession.cjs +1 -1
- package/src/main/lib/feedback-remote/crossProjectReply.cjs +96 -8
- package/src/main/lib/feedback-remote/macroAdminRoutes.cjs +30 -0
- package/src/main/lib/feedback-remote/pendingReplies.cjs +18 -0
- package/src/main/lib/feedback-remote/projectHomeAdminRoutes.cjs +94 -4
- package/src/main/lib/feedback-remote/replyClaims.cjs +159 -0
- package/src/main/lib/git/gitWorktree.cjs +8 -0
- package/src/main/lib/git/runtimeStateUntrack.cjs +15 -1
- package/src/main/lib/git/worktreeDeps.cjs +113 -10
- package/src/main/lib/mcpToolCatalog.cjs +102 -8
- package/src/main/lib/opsOwnership.cjs +113 -28
- package/src/main/lib/persona-macro/shippedPersonaSeeds.cjs +46 -0
- package/src/main/lib/prd/prdCreate.cjs +350 -227
- package/src/main/lib/prd/prdCriteria.cjs +7 -4
- package/src/main/lib/project-pages/videoPressLines.cjs +145 -0
- package/src/main/lib/project-pages/videoScriptPress.cjs +260 -0
- package/src/main/lib/project-pages/videoScriptRunRoute.cjs +351 -0
- package/src/main/lib/project-pages/videoScriptSwitchIpc.cjs +49 -0
- package/src/main/lib/project-pages/videoScriptSwitchRoute.cjs +173 -0
- package/src/main/lib/scheduler/criteriaChecks.cjs +164 -20
- package/src/main/lib/scheduler/heldSchedulerTurns.cjs +238 -0
- package/src/main/lib/scheduler/jobMemoryStats.cjs +13 -2
- package/src/main/lib/scheduler/planRecordHarvest.cjs +120 -52
- package/src/main/lib/scheduler/prdOutcomeRecord.cjs +60 -2
- package/src/main/lib/scheduler/queueStore.cjs +16 -0
- package/src/main/lib/scheduler/rcaReport.cjs +79 -15
- package/src/main/lib/scheduler/scheduleJobSchema.cjs +13 -0
- package/src/main/lib/scheduler/schedulerPaths.cjs +9 -0
- package/src/main/lib/scheduler/slotsRoute.cjs +101 -87
- package/src/main/lib/scheduler/usageHoldRoute.cjs +97 -0
- package/src/main/lib/scheduler/validatorVerdictSchema.cjs +16 -5
- package/src/main/lib/tasks/memoryConsolidation.cjs +14 -2
- package/src/main/lib/tasks/mitigationReview.cjs +21 -1
- package/src/main/lib/tasks/taskAdminRoutes.cjs +78 -3
- package/src/main/lib/tasks/taskLedger.cjs +2 -2
- package/src/main/lib/telemetry/auditEvents.cjs +21 -24
- package/src/main/lib/telemetry/auditLog.cjs +6 -2
- package/src/main/lib/util/atomicFs.cjs +2 -2
- package/src/main/promptSessionEvents.cjs +16 -1
- package/src/main/pty.cjs +11 -2
- package/src/main/queueOps.cjs +1 -1
- package/src/main/runVerify.cjs +1 -1
- package/src/main/scheduler/utilizationHold.cjs +96 -6
- package/src/main/scheduler.cjs +533 -39
- package/src/main/templates/PRD_AUTHORING.md +7 -2
- package/src/preload/api.d.ts +47 -1
- package/src/preload/apiSurface.json +14 -0
- package/src/preload/index.cjs +2 -0
- package/src/seed/agents/demo-video-builder.md +15 -8
- package/src/seed/agents/validator.md +20 -19
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// Demo-video kit project sounds: a persona's own named sound effects and music beds —
|
|
3
|
+
// the `sounds` block of character.json ({ sfx: [{name,note}], beds: [{name,note,command}] })
|
|
4
|
+
// and a cast member's `sfx` (names of built-in effects or sounds.sfx entries).
|
|
5
|
+
// Every sfx entry and every bed without `command` is file-backed: its WAV lives in
|
|
6
|
+
// videos/_character/sounds/<name>.wav (see soundFile), written only by
|
|
7
|
+
// POST /admin/project-home/character/write as writer 'project-home'.
|
|
8
|
+
// Seeded with the kit, so it loads standalone: node built-ins and this folder only.
|
|
9
|
+
// sound.cjs and character.cjs are required lazily inside functions (both may require
|
|
10
|
+
// this module at load).
|
|
11
|
+
const path = require('node:path');
|
|
12
|
+
|
|
13
|
+
const SOUND_NAME_RE = /^[a-z][a-z0-9-]{0,31}$/;
|
|
14
|
+
const MAX_PROJECT_SFX = 16;
|
|
15
|
+
const MAX_PROJECT_BEDS = 8;
|
|
16
|
+
const MAX_MEMBER_SFX = 8;
|
|
17
|
+
const SOUND_NOTE_MAX = 200;
|
|
18
|
+
const MAX_SFX_WAV_BYTES = 1048576;
|
|
19
|
+
const MAX_BED_WAV_BYTES = 12582912;
|
|
20
|
+
const MAX_SOUNDS_TOTAL_BYTES = 33554432;
|
|
21
|
+
const WINDOWS_RESERVED = /^(con|prn|aux|nul|com[1-9]|lpt[1-9])$/;
|
|
22
|
+
|
|
23
|
+
const SFX_KEYS = Object.freeze(['name', 'note']);
|
|
24
|
+
const BED_KEYS = Object.freeze(['name', 'note', 'command']);
|
|
25
|
+
|
|
26
|
+
/** The kit's built-in effect and style names, from sound.cjs. */
|
|
27
|
+
function builtinNames() {
|
|
28
|
+
const { SFX_NAMES, STYLES } = require('./sound.cjs');
|
|
29
|
+
return { sfx: [...SFX_NAMES], styles: Object.keys(STYLES) };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function isPlainObject(v) {
|
|
33
|
+
return !!v && typeof v === 'object' && !Array.isArray(v);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** -> null when `sounds` is a valid character.json `sounds` block, else a reason (first failure wins). */
|
|
37
|
+
function validateSounds(sounds) {
|
|
38
|
+
if (!isPlainObject(sounds)) return 'sounds must be an object with optional sfx and beds arrays';
|
|
39
|
+
for (const k of Object.keys(sounds)) {
|
|
40
|
+
if (k !== 'sfx' && k !== 'beds') return `sounds.${k} is not a known key (sfx, beds)`;
|
|
41
|
+
}
|
|
42
|
+
if ('sfx' in sounds && (!Array.isArray(sounds.sfx) || sounds.sfx.length > MAX_PROJECT_SFX)) {
|
|
43
|
+
return `sounds.sfx must be an array of at most ${MAX_PROJECT_SFX} sound effects`;
|
|
44
|
+
}
|
|
45
|
+
if ('beds' in sounds && (!Array.isArray(sounds.beds) || sounds.beds.length > MAX_PROJECT_BEDS)) {
|
|
46
|
+
return `sounds.beds must be an array of at most ${MAX_PROJECT_BEDS} music beds`;
|
|
47
|
+
}
|
|
48
|
+
const builtin = builtinNames();
|
|
49
|
+
const styleKeys = builtin.styles.map((s) => s.toLowerCase());
|
|
50
|
+
const seen = new Map();
|
|
51
|
+
const groups = [['sfx', SFX_KEYS], ['beds', BED_KEYS]];
|
|
52
|
+
for (const [group, keys] of groups) {
|
|
53
|
+
const items = sounds[group] || [];
|
|
54
|
+
for (let i = 0; i < items.length; i++) {
|
|
55
|
+
const item = items[i];
|
|
56
|
+
const label = `sounds.${group}[${i}]`;
|
|
57
|
+
if (!isPlainObject(item)) return `${label} must be an object`;
|
|
58
|
+
for (const k of Object.keys(item)) {
|
|
59
|
+
if (!keys.includes(k)) return `${label}.${k} is not a known key (${keys.join(', ')})`;
|
|
60
|
+
}
|
|
61
|
+
const n = item.name;
|
|
62
|
+
if (typeof n !== 'string' || !SOUND_NAME_RE.test(n)) return `${label}.name must match ${SOUND_NAME_RE}`;
|
|
63
|
+
if (WINDOWS_RESERVED.test(n)) return `${label}.name "${n}" is a reserved file name`;
|
|
64
|
+
if (builtin.sfx.includes(n)) return `${label}.name "${n}" is a built-in sound (${builtin.sfx.join(', ')})`;
|
|
65
|
+
if (styleKeys.includes(n.toLowerCase())) return `${label}.name "${n}" is a built-in style (${builtin.styles.join(', ')})`;
|
|
66
|
+
if (seen.has(n)) return `${label}.name "${n}" duplicates ${seen.get(n)}.name`;
|
|
67
|
+
seen.set(n, label);
|
|
68
|
+
if ('note' in item && (typeof item.note !== 'string' || item.note.length < 1 || item.note.length > SOUND_NOTE_MAX)) {
|
|
69
|
+
return `${label}.note must be a 1-${SOUND_NOTE_MAX} char string`;
|
|
70
|
+
}
|
|
71
|
+
if (group === 'beds' && 'command' in item) {
|
|
72
|
+
const cmd = item.command;
|
|
73
|
+
if (!Array.isArray(cmd) || cmd.length === 0 || !cmd.every((a) => typeof a === 'string')) {
|
|
74
|
+
return `${label}.command must be a non-empty string[]`;
|
|
75
|
+
}
|
|
76
|
+
if (!cmd[0]) return `${label}.command[0] must be a program name`;
|
|
77
|
+
if (!cmd.some((a) => a.includes('{lengthS}'))) return `${label}.command must contain a {lengthS} placeholder`;
|
|
78
|
+
if (!cmd.some((a) => a.includes('{out}'))) return `${label}.command must contain an {out} placeholder`;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** -> null when a cast member's `sfx` names 1-8 distinct built-in effects or sounds.sfx
|
|
86
|
+
* names, else a reason prefixed with `label`. `sounds` may be undefined. */
|
|
87
|
+
function validateMemberSfx(sfx, label, sounds) {
|
|
88
|
+
if (!Array.isArray(sfx) || sfx.length < 1 || sfx.length > MAX_MEMBER_SFX || !sfx.every((n) => typeof n === 'string')) {
|
|
89
|
+
return `${label} must be an array of 1-${MAX_MEMBER_SFX} sound names`;
|
|
90
|
+
}
|
|
91
|
+
const builtin = builtinNames().sfx;
|
|
92
|
+
const own = sounds && Array.isArray(sounds.sfx) ? sounds.sfx.map((e) => e && e.name).filter((n) => typeof n === 'string') : [];
|
|
93
|
+
const firstAt = new Map();
|
|
94
|
+
for (let j = 0; j < sfx.length; j++) {
|
|
95
|
+
const n = sfx[j];
|
|
96
|
+
if (!builtin.includes(n) && !own.includes(n)) {
|
|
97
|
+
return `${label}[${j}] "${n}" is not a built-in sound (${builtin.join(', ')}) or one of sounds.sfx (${own.length ? own.join(', ') : 'none'})`;
|
|
98
|
+
}
|
|
99
|
+
if (firstAt.has(n)) return `${label}[${j}] "${n}" repeats ${label}[${firstAt.get(n)}]`;
|
|
100
|
+
firstAt.set(n, j);
|
|
101
|
+
}
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Names of every file-backed sound in character `c`: each sfx, then each bed without `command`. */
|
|
106
|
+
function fileBackedSoundNames(c) {
|
|
107
|
+
const s = c && isPlainObject(c.sounds) ? c.sounds : null;
|
|
108
|
+
if (!s) return [];
|
|
109
|
+
const out = [];
|
|
110
|
+
if (Array.isArray(s.sfx)) for (const e of s.sfx) if (e && typeof e.name === 'string') out.push(e.name);
|
|
111
|
+
if (Array.isArray(s.beds)) for (const e of s.beds) if (e && typeof e.name === 'string' && !('command' in e)) out.push(e.name);
|
|
112
|
+
return out;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** -> { kind: 'sfx' | 'bed', entry } for the project sound named `name` in character `c`, else null. */
|
|
116
|
+
function findProjectSound(c, name) {
|
|
117
|
+
const s = c && isPlainObject(c.sounds) ? c.sounds : null;
|
|
118
|
+
if (!s) return null;
|
|
119
|
+
const sfx = Array.isArray(s.sfx) ? s.sfx.find((e) => e && e.name === name) : undefined;
|
|
120
|
+
if (sfx) return { kind: 'sfx', entry: sfx };
|
|
121
|
+
const bed = Array.isArray(s.beds) ? s.beds.find((e) => e && e.name === name) : undefined;
|
|
122
|
+
if (bed) return { kind: 'bed', entry: bed };
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** -> null when `buf` is a readable PCM / IEEE-float WAV (headers only), else a reason prefixed with `label`. */
|
|
127
|
+
function wavFormatError(buf, label) {
|
|
128
|
+
if (!Buffer.isBuffer(buf) || buf.length < 12 || buf.toString('ascii', 0, 4) !== 'RIFF' || buf.toString('ascii', 8, 12) !== 'WAVE') {
|
|
129
|
+
return `${label} is not a RIFF WAV`;
|
|
130
|
+
}
|
|
131
|
+
let fmt = null;
|
|
132
|
+
let data = null;
|
|
133
|
+
let pos = 12;
|
|
134
|
+
while (pos + 8 <= buf.length) {
|
|
135
|
+
const id = buf.toString('ascii', pos, pos + 4);
|
|
136
|
+
const size = buf.readUInt32LE(pos + 4);
|
|
137
|
+
const body = pos + 8;
|
|
138
|
+
if (id === 'fmt ' && !fmt && size >= 16 && body + 16 <= buf.length) {
|
|
139
|
+
fmt = { tag: buf.readUInt16LE(body), ch: buf.readUInt16LE(body + 2), sr: buf.readUInt32LE(body + 4), bits: buf.readUInt16LE(body + 14) };
|
|
140
|
+
}
|
|
141
|
+
if (id === 'data' && !data) data = { bytes: Math.min(size, buf.length - body) };
|
|
142
|
+
pos = body + size + (size % 2);
|
|
143
|
+
}
|
|
144
|
+
if (!fmt) return `${label} has no fmt chunk`;
|
|
145
|
+
if (![1, 3, 0xfffe].includes(fmt.tag)) return `${label} WAV format tag ${fmt.tag} is not PCM or IEEE float`;
|
|
146
|
+
if (fmt.ch < 1 || fmt.ch > 2) return `${label} WAV must be mono or stereo, not ${fmt.ch} channels`;
|
|
147
|
+
if (fmt.sr < 8000 || fmt.sr > 192000) return `${label} WAV sample rate ${fmt.sr} Hz is outside 8000-192000`;
|
|
148
|
+
if (![8, 16, 24, 32, 64].includes(fmt.bits)) return `${label} WAV has ${fmt.bits}-bit samples`;
|
|
149
|
+
if (!data) return `${label} has no data chunk`;
|
|
150
|
+
if (data.bytes < (fmt.ch * fmt.bits) / 8) return `${label} has no audio samples`;
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** -> null when `buf` is a usable WAV within the byte cap for `kind` ('sfx' | 'bed'), else a reason. */
|
|
155
|
+
function checkSoundWav(buf, label, kind) {
|
|
156
|
+
const cap = kind === 'sfx' ? MAX_SFX_WAV_BYTES : MAX_BED_WAV_BYTES;
|
|
157
|
+
if (Buffer.isBuffer(buf) && buf.length > cap) {
|
|
158
|
+
return `${label} is ${buf.length} bytes, over the ${cap}-byte limit for a ${kind === 'sfx' ? 'sound effect' : 'music bed'}`;
|
|
159
|
+
}
|
|
160
|
+
return wavFormatError(buf, label);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** <characterDir(root)>/sounds — where every file-backed project sound's WAV lives. */
|
|
164
|
+
function soundsDir(root) {
|
|
165
|
+
return path.join(require('./character.cjs').characterDir(root), 'sounds');
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** <soundsDir(root)>/<name>.wav; throws for a name not matching SOUND_NAME_RE. */
|
|
169
|
+
function soundFile(root, name) {
|
|
170
|
+
if (typeof name !== 'string' || !SOUND_NAME_RE.test(name)) throw new Error(`soundFile: invalid sound name "${name}"`);
|
|
171
|
+
return path.join(soundsDir(root), `${name}.wav`);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
module.exports = {
|
|
175
|
+
validateSounds,
|
|
176
|
+
validateMemberSfx,
|
|
177
|
+
fileBackedSoundNames,
|
|
178
|
+
findProjectSound,
|
|
179
|
+
wavFormatError,
|
|
180
|
+
checkSoundWav,
|
|
181
|
+
soundsDir,
|
|
182
|
+
soundFile,
|
|
183
|
+
SOUND_NAME_RE,
|
|
184
|
+
MAX_PROJECT_SFX,
|
|
185
|
+
MAX_PROJECT_BEDS,
|
|
186
|
+
MAX_MEMBER_SFX,
|
|
187
|
+
SOUND_NOTE_MAX,
|
|
188
|
+
MAX_SFX_WAV_BYTES,
|
|
189
|
+
MAX_BED_WAV_BYTES,
|
|
190
|
+
MAX_SOUNDS_TOTAL_BYTES,
|
|
191
|
+
};
|
|
@@ -19,10 +19,10 @@ const path = require('node:path');
|
|
|
19
19
|
const { schedulerHome } = require('../scheduler/schedulerPaths.cjs');
|
|
20
20
|
const { writeTextAtomic } = require('../util/atomicFs.cjs');
|
|
21
21
|
|
|
22
|
-
const KIT_VERSION = '
|
|
22
|
+
const KIT_VERSION = '45';
|
|
23
23
|
// sha256 of kitDigest(__dirname). Update together with a KIT_VERSION bump.
|
|
24
|
-
const KIT_DIGEST = '
|
|
25
|
-
const KIT_FILES = Object.freeze(['checks.cjs', 'sound.cjs', 'capture.cjs', 'frames.cjs', 'character.cjs', 'playwrightLoader.cjs', 'export.cjs', 'kind-tiktok.md', 'kind-marketing.md', 'cast.md', 'project-home-html.md', 'resumableRun.cjs', 'voiceLibrary.cjs', 'voiceLane.cjs', 'kokoroSay.cjs']);
|
|
24
|
+
const KIT_DIGEST = 'd1735e9ad8044d68d81ba52fd4d95f5b80f763f2811a8674211d25ef5d49f482';
|
|
25
|
+
const KIT_FILES = Object.freeze(['checks.cjs', 'sound.cjs', 'capture.cjs', 'frames.cjs', 'character.cjs', 'playwrightLoader.cjs', 'export.cjs', 'kind-tiktok.md', 'kind-marketing.md', 'cast.md', 'project-home-html.md', 'resumableRun.cjs', 'voiceLibrary.cjs', 'voiceLane.cjs', 'kokoroSay.cjs', 'projectSounds.cjs', 'standalone.cjs']);
|
|
26
26
|
const STAMP_FILE = 'KIT_VERSION';
|
|
27
27
|
|
|
28
28
|
/** The single list of kit files (paths relative to the kit dir) the seeder copies. */
|
|
@@ -261,21 +261,178 @@ function duckEnvelope(narr) {
|
|
|
261
261
|
return { gain, speechS: active * 0.02 };
|
|
262
262
|
}
|
|
263
263
|
|
|
264
|
+
/** Decode any audio file to mono 44.1 kHz float samples (non-finite samples -> 0). */
|
|
265
|
+
function decodeMono(file, dir, tag) {
|
|
266
|
+
const f32 = path.join(dir, `${tag}.f32.wav`);
|
|
267
|
+
runFfmpeg(['-hide_banner', '-nostats', '-y', '-i', file, '-vn', '-ac', '1', '-ar', String(SR), '-c:a', 'pcm_f32le', f32]);
|
|
268
|
+
const x = decodeWavF32(fs.readFileSync(f32));
|
|
269
|
+
// A single NaN in the buffer handed to ffmpeg makes libmp3lame assert (0-byte mp3).
|
|
270
|
+
for (let i = 0; i < x.length; i++) if (!Number.isFinite(x[i])) x[i] = 0;
|
|
271
|
+
return x;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
const BUILTIN_LIST = SFX_NAMES.join(', ');
|
|
275
|
+
|
|
276
|
+
// Mutable so a test can shorten the limit; production never changes it.
|
|
277
|
+
const BED_COMMAND_LIMITS = { timeoutMs: 300000 };
|
|
278
|
+
const BED_STDERR_TAIL = 500;
|
|
279
|
+
|
|
280
|
+
/** Lazy, memoised persona reader for the cue/bed pre-pass; throws when character.json exists but is unusable. */
|
|
281
|
+
function personaLoader(projectRoot) {
|
|
282
|
+
let persona;
|
|
283
|
+
return () => {
|
|
284
|
+
if (persona === undefined) {
|
|
285
|
+
const { inspectCharacter } = require('./character.cjs');
|
|
286
|
+
persona = inspectCharacter(projectRoot);
|
|
287
|
+
if (!persona.ok && persona.exists) throw new Error(`project persona unusable: ${persona.error}`);
|
|
288
|
+
}
|
|
289
|
+
return persona;
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
const hasRoot = (projectRoot) => projectRoot !== undefined && projectRoot !== null;
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Resolve every cue name before any audio work: built-ins map to null, a persona
|
|
297
|
+
* sounds.sfx name to its WAV path. Throws a named reason for anything else.
|
|
298
|
+
* The persona is read only when some cue is not built-in.
|
|
299
|
+
*/
|
|
300
|
+
function resolveCueFiles(cues, projectRoot, getPersona) {
|
|
301
|
+
const files = new Map();
|
|
302
|
+
for (const cue of cues) {
|
|
303
|
+
const name = cue && cue.name;
|
|
304
|
+
if (SFX_NAMES.includes(name) || files.has(name)) continue;
|
|
305
|
+
if (!hasRoot(projectRoot)) {
|
|
306
|
+
throw new Error(`unknown sfx: ${name} (built-in: ${BUILTIN_LIST}; pass projectRoot to use the persona's own sounds)`);
|
|
307
|
+
}
|
|
308
|
+
const { findProjectSound, soundFile, checkSoundWav } = require('./projectSounds.cjs');
|
|
309
|
+
const persona = getPersona();
|
|
310
|
+
const found = persona.ok ? findProjectSound(persona.json, name) : null;
|
|
311
|
+
if (!found || found.kind !== 'sfx') {
|
|
312
|
+
const s = persona.ok && persona.json.sounds && Array.isArray(persona.json.sounds.sfx) ? persona.json.sounds.sfx : [];
|
|
313
|
+
const names = s.map((e) => e && e.name).filter((n) => typeof n === 'string').join(', ');
|
|
314
|
+
throw new Error(`unknown sfx: ${name} (built-in: ${BUILTIN_LIST}; persona sounds.sfx: ${names || 'none'})`);
|
|
315
|
+
}
|
|
316
|
+
const file = soundFile(projectRoot, name);
|
|
317
|
+
if (!fs.existsSync(file)) {
|
|
318
|
+
throw new Error(`project sfx '${name}' has no WAV at ${file} (save the persona again with its sound files)`);
|
|
319
|
+
}
|
|
320
|
+
const reason = checkSoundWav(fs.readFileSync(file), `project sfx '${name}' (${file})`, 'sfx');
|
|
321
|
+
if (reason) throw new Error(reason);
|
|
322
|
+
files.set(name, file);
|
|
323
|
+
}
|
|
324
|
+
return files;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* Resolve spec.bed before any audio work -> {style} for a built-in bed, {name, file}
|
|
329
|
+
* for a file-backed persona bed, {name, command} for a command bed. Throws a named reason.
|
|
330
|
+
*/
|
|
331
|
+
function resolveBed(bed, style, projectRoot, getPersona) {
|
|
332
|
+
if (bed === undefined || bed === null) return { style };
|
|
333
|
+
if (Object.prototype.hasOwnProperty.call(STYLES, bed)) return { style: bed };
|
|
334
|
+
const styles = Object.keys(STYLES).join(', ');
|
|
335
|
+
if (!hasRoot(projectRoot)) {
|
|
336
|
+
throw new Error(`unknown bed: ${bed} (built-in styles: ${styles}; pass projectRoot to use the persona's own beds)`);
|
|
337
|
+
}
|
|
338
|
+
const { findProjectSound, soundFile, checkSoundWav } = require('./projectSounds.cjs');
|
|
339
|
+
const persona = getPersona();
|
|
340
|
+
const found = persona.ok ? findProjectSound(persona.json, bed) : null;
|
|
341
|
+
if (!found || found.kind !== 'bed') {
|
|
342
|
+
const b = persona.ok && persona.json.sounds && Array.isArray(persona.json.sounds.beds) ? persona.json.sounds.beds : [];
|
|
343
|
+
const names = b.map((e) => e && e.name).filter((n) => typeof n === 'string').join(', ');
|
|
344
|
+
throw new Error(`unknown bed: ${bed} (built-in styles: ${styles}; persona sounds.beds: ${names || 'none'})`);
|
|
345
|
+
}
|
|
346
|
+
const name = bed;
|
|
347
|
+
if (Array.isArray(found.entry.command)) return { name, command: [...found.entry.command] };
|
|
348
|
+
const file = soundFile(projectRoot, name);
|
|
349
|
+
if (!fs.existsSync(file)) {
|
|
350
|
+
throw new Error(`project bed '${name}' has no WAV at ${file} (save the persona again with its sound files)`);
|
|
351
|
+
}
|
|
352
|
+
const reason = checkSoundWav(fs.readFileSync(file), `project bed '${name}' (${file})`, 'bed');
|
|
353
|
+
if (reason) throw new Error(reason);
|
|
354
|
+
return { name, file };
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/** A file bed looped end to end to n samples with bedSamples' edge fades. */
|
|
358
|
+
function loopFileBed(file, dir, n) {
|
|
359
|
+
const s = decodeMono(file, dir, 'bed');
|
|
360
|
+
const out = new Float32Array(n);
|
|
361
|
+
if (s.length > 0) for (let i = 0; i < n; i++) out[i] = s[i % s.length];
|
|
362
|
+
const fade = Math.min(Math.round(1.0 * SR), Math.floor(n / 2));
|
|
363
|
+
for (let i = 0; i < fade; i++) { const g = i / fade; out[i] *= g; out[n - 1 - i] *= g; }
|
|
364
|
+
return out;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/** Render a command bed of n samples via the project's own command (no shell, cwd = projectRoot). */
|
|
368
|
+
function renderCommandBed({ name, command }, { dir, n, seed, projectRoot }) {
|
|
369
|
+
const { wavFormatError } = require('./projectSounds.cjs');
|
|
370
|
+
const outWav = path.join(dir, `bed-${name}.wav`);
|
|
371
|
+
const lengthS = (n / SR).toFixed(3);
|
|
372
|
+
const subs = { '{name}': name, '{lengthS}': lengthS, '{seed}': String(seed), '{out}': outWav };
|
|
373
|
+
const argv = command.map((a) => {
|
|
374
|
+
let v = a;
|
|
375
|
+
for (const [k, val] of Object.entries(subs)) v = v.split(k).join(val);
|
|
376
|
+
return v;
|
|
377
|
+
});
|
|
378
|
+
const r = spawnSync(argv[0], argv.slice(1), {
|
|
379
|
+
cwd: projectRoot,
|
|
380
|
+
shell: false,
|
|
381
|
+
stdio: ['ignore', 'ignore', 'pipe'],
|
|
382
|
+
timeout: BED_COMMAND_LIMITS.timeoutMs,
|
|
383
|
+
maxBuffer: 16 * 1024 * 1024,
|
|
384
|
+
});
|
|
385
|
+
const stderr = r.stderr ? r.stderr.toString('utf8').trim().slice(-BED_STDERR_TAIL) : '';
|
|
386
|
+
const withStderr = (msg) => (stderr ? `${msg}: ${stderr}` : msg);
|
|
387
|
+
const label = `project bed '${name}' command`;
|
|
388
|
+
if (r.error && r.error.code === 'ETIMEDOUT') throw new Error(withStderr(`${label} killed at its ${BED_COMMAND_LIMITS.timeoutMs / 1000} s limit`));
|
|
389
|
+
if (r.error) throw new Error(withStderr(`${label} failed to run: ${r.error.message}`));
|
|
390
|
+
if (r.status !== 0) {
|
|
391
|
+
const why = r.signal ? `killed by ${r.signal}` : `exit ${r.status}`;
|
|
392
|
+
throw new Error(withStderr(`${label} failed (${why})`));
|
|
393
|
+
}
|
|
394
|
+
if (!fs.existsSync(outWav)) throw new Error(withStderr(`${label} wrote no WAV to ${outWav}`));
|
|
395
|
+
const reason = wavFormatError(fs.readFileSync(outWav), `${label} output (${outWav})`);
|
|
396
|
+
if (reason) throw new Error(reason);
|
|
397
|
+
const s = decodeMono(outWav, dir, 'bed');
|
|
398
|
+
if (s.length < Math.round((n / SR - 0.05) * SR)) {
|
|
399
|
+
throw new Error(`${label} wrote ${(s.length / SR).toFixed(3)} s of audio; the mix needs at least ${(n / SR - 0.05).toFixed(3)} s (${lengthS} s less the 0.05 s tolerance)`);
|
|
400
|
+
}
|
|
401
|
+
if (s.length >= n) return s.subarray(0, n);
|
|
402
|
+
const out = new Float32Array(n);
|
|
403
|
+
out.set(s);
|
|
404
|
+
return out;
|
|
405
|
+
}
|
|
406
|
+
|
|
264
407
|
/**
|
|
265
408
|
* Mix narration + ducked music bed + SFX cues, then loudnorm to -14 LUFS / -1.5 dBTP.
|
|
266
|
-
* cues: [{name, t}] (t in seconds; `at` also accepted).
|
|
267
|
-
*
|
|
409
|
+
* cues: [{name, t}] (t in seconds; `at` also accepted). A name that is not a built-in
|
|
410
|
+
* effect is read from the persona's sounds.sfx under projectRoot (absolute).
|
|
411
|
+
* bed: absent -> the style's built-in bed; a STYLES key -> that built-in bed; any other
|
|
412
|
+
* name -> the persona's sounds.beds entry (a WAV looped to length, or rendered by its
|
|
413
|
+
* command). Output length is the longer of lengthS and the narration.
|
|
414
|
+
* Returns {lufs, truePeakDb, speechS}.
|
|
268
415
|
*/
|
|
269
|
-
function mix({ narrationWav, cues = [], style, lengthS, out, seed = 1 }) {
|
|
416
|
+
function mix({ narrationWav, cues = [], style, bed: bedName, lengthS, out, seed = 1, projectRoot }) {
|
|
417
|
+
if (hasRoot(projectRoot) && (typeof projectRoot !== 'string' || !path.isAbsolute(projectRoot))) {
|
|
418
|
+
throw new Error('spec.projectRoot must be an absolute path');
|
|
419
|
+
}
|
|
420
|
+
const getPersona = personaLoader(projectRoot);
|
|
421
|
+
const cueFiles = resolveCueFiles(cues, projectRoot, getPersona);
|
|
422
|
+
const bedSpec = resolveBed(bedName, style, projectRoot, getPersona);
|
|
270
423
|
const dir = fs.mkdtempSync(path.join(require('os').tmpdir(), 'dvk-sound-'));
|
|
271
424
|
try {
|
|
272
|
-
const
|
|
273
|
-
runFfmpeg(['-hide_banner', '-nostats', '-y', '-i', narrationWav, '-vn', '-ac', '1', '-ar', String(SR), '-c:a', 'pcm_f32le', narrF32]);
|
|
274
|
-
const narr = decodeWavF32(fs.readFileSync(narrF32));
|
|
425
|
+
const narr = decodeMono(narrationWav, dir, 'narration');
|
|
275
426
|
const n = Math.max(narr.length, Math.round(Number(lengthS) * SR));
|
|
276
|
-
|
|
427
|
+
let bed;
|
|
428
|
+
if (bedSpec.file) bed = loopFileBed(bedSpec.file, dir, n);
|
|
429
|
+
else if (bedSpec.command) bed = renderCommandBed(bedSpec, { dir, n, seed, projectRoot });
|
|
430
|
+
else bed = bedSamples({ style: bedSpec.style, lengthS: n / SR, seed });
|
|
277
431
|
// A single NaN in the buffer handed to ffmpeg makes libmp3lame assert (0-byte mp3).
|
|
278
432
|
for (let i = 0; i < bed.length; i++) if (!Number.isFinite(bed[i])) bed[i] = 0;
|
|
433
|
+
const projectSfx = new Map();
|
|
434
|
+
let k = 0;
|
|
435
|
+
for (const [name, file] of cueFiles) projectSfx.set(name, decodeMono(file, dir, `sfx-${k++}`));
|
|
279
436
|
const { gain, speechS } = duckEnvelope(narr);
|
|
280
437
|
const bedGain = dbToGain(BED_BASE_DB);
|
|
281
438
|
const mixed = new Float32Array(n);
|
|
@@ -286,7 +443,7 @@ function mix({ narrationWav, cues = [], style, lengthS, out, seed = 1 }) {
|
|
|
286
443
|
const sfxGain = dbToGain(-10);
|
|
287
444
|
for (const cue of cues) {
|
|
288
445
|
const at = Math.round(Number(cue.t ?? cue.at ?? 0) * SR);
|
|
289
|
-
const s = sfxSamples(cue.name);
|
|
446
|
+
const s = projectSfx.get(cue.name) || sfxSamples(cue.name);
|
|
290
447
|
for (let i = 0; i < s.length && at + i < n; i++) if (at + i >= 0) mixed[at + i] += s[i] * sfxGain;
|
|
291
448
|
}
|
|
292
449
|
const pre = path.join(dir, 'premix.f32.wav');
|
|
@@ -299,7 +456,7 @@ function mix({ narrationWav, cues = [], style, lengthS, out, seed = 1 }) {
|
|
|
299
456
|
}
|
|
300
457
|
}
|
|
301
458
|
|
|
302
|
-
module.exports = { buildMusicBed, buildSfx, mix, measure, parseEbur128, runFfmpeg, decodeWavF32, STYLES, SFX_NAMES, TARGET };
|
|
459
|
+
module.exports = { buildMusicBed, buildSfx, mix, measure, parseEbur128, runFfmpeg, decodeWavF32, STYLES, SFX_NAMES, TARGET, BED_COMMAND_LIMITS };
|
|
303
460
|
|
|
304
461
|
if (require.main === module) {
|
|
305
462
|
try {
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// Demo-video kit standalone check: load one built demo-video HTML file in headless Chromium the
|
|
3
|
+
// way bilko.run embeds a Blog post video (sandboxed iframe mounted after a click, plus the same
|
|
4
|
+
// page opened top-level via "Open in new tab") and report whether it plays on its own with no
|
|
5
|
+
// host player. Copied standalone into ~/.claude/session-manager/demo-video-kit/, so Node builtins
|
|
6
|
+
// plus ./playwrightLoader.cjs only. CLI: node standalone.cjs <file.html> -> JSON array on stdout,
|
|
7
|
+
// exit 0 all pass, 1 any fail, 2 usage error / Playwright unavailable.
|
|
8
|
+
const fs = require('fs');
|
|
9
|
+
const http = require('http');
|
|
10
|
+
const path = require('path');
|
|
11
|
+
const { loadPlaywright: defaultLoader } = require('./playwrightLoader.cjs');
|
|
12
|
+
|
|
13
|
+
// Copied verbatim from bilko.run server/security-headers.ts BLOG_VIDEO_CSP (2026-11-24).
|
|
14
|
+
const BLOG_VIDEO_CSP = "default-src 'none'; script-src 'unsafe-inline'; style-src 'unsafe-inline'; img-src data: blob:; media-src data: blob:; font-src data:; connect-src 'none'; frame-ancestors 'self'; base-uri 'none'; form-action 'none'; sandbox allow-scripts";
|
|
15
|
+
const AUTOPLAY_ARG = '--autoplay-policy=document-user-activation-required';
|
|
16
|
+
const VIEWPORT = { width: 1280, height: 800 };
|
|
17
|
+
const FRAME_SIZE = { width: 960, height: 540 };
|
|
18
|
+
const EMBED_READS_MS = [2500, 4000];
|
|
19
|
+
const MAX_SCENE_S = 15;
|
|
20
|
+
const TAP_WINDOW_MS = 1500;
|
|
21
|
+
const TAP_SETTLE_MS = 1000;
|
|
22
|
+
|
|
23
|
+
class StandaloneUsageError extends Error {}
|
|
24
|
+
|
|
25
|
+
function slugFor(htmlPath) {
|
|
26
|
+
const base = path.basename(htmlPath).toLowerCase() === 'index.html'
|
|
27
|
+
? path.basename(path.dirname(path.resolve(htmlPath)))
|
|
28
|
+
: path.basename(htmlPath, path.extname(htmlPath));
|
|
29
|
+
return String(base).toLowerCase().replace(/[^a-z0-9-]+/g, '-').replace(/^-+|-+$/g, '') || 'video';
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function parentPage(slug) {
|
|
33
|
+
return `<!DOCTYPE html><html><head><meta charset="utf-8"><title>post</title>
|
|
34
|
+
<style>body{margin:0;background:#fff}#cover{display:block;width:${FRAME_SIZE.width}px;height:${FRAME_SIZE.height}px;margin:20px}#slot iframe{display:block;border:0;width:${FRAME_SIZE.width}px;height:${FRAME_SIZE.height}px;margin:20px}</style>
|
|
35
|
+
</head><body><div id="slot"><button id="cover" type="button">Play video</button></div>
|
|
36
|
+
<script>
|
|
37
|
+
document.getElementById('cover').addEventListener('click', (e) => {
|
|
38
|
+
if (!e.isTrusted) return;
|
|
39
|
+
const f = document.createElement('iframe');
|
|
40
|
+
f.id = 'video';
|
|
41
|
+
f.setAttribute('sandbox', 'allow-scripts');
|
|
42
|
+
f.setAttribute('allow', 'autoplay; fullscreen');
|
|
43
|
+
f.src = '/blog-videos/${slug}/';
|
|
44
|
+
const slot = document.getElementById('slot');
|
|
45
|
+
slot.replaceChildren(f);
|
|
46
|
+
});
|
|
47
|
+
</script></body></html>`;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** One loopback server: /blog-videos/<slug>/ = the file's bytes + BLOG_VIDEO_CSP; /post/<slug>/ = parent. */
|
|
51
|
+
function startServer(bytes, slug) {
|
|
52
|
+
const server = http.createServer((req, res) => {
|
|
53
|
+
const url = String(req.url || '').split('?')[0];
|
|
54
|
+
if (url === `/blog-videos/${slug}/`) {
|
|
55
|
+
res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8', 'Content-Security-Policy': BLOG_VIDEO_CSP, 'Cache-Control': 'no-store' });
|
|
56
|
+
res.end(bytes);
|
|
57
|
+
} else if (url === `/post/${slug}/`) {
|
|
58
|
+
res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8', 'Cache-Control': 'no-store' });
|
|
59
|
+
res.end(parentPage(slug));
|
|
60
|
+
} else {
|
|
61
|
+
res.writeHead(404, { 'Content-Type': 'text/plain' });
|
|
62
|
+
res.end('not found');
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
return new Promise((resolve, reject) => {
|
|
66
|
+
server.once('error', reject);
|
|
67
|
+
server.listen(0, '127.0.0.1', () => resolve({ server, base: `http://127.0.0.1:${server.address().port}` }));
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, Math.max(0, ms)));
|
|
72
|
+
const until = (t0, ms) => sleep(t0 + ms - Date.now());
|
|
73
|
+
|
|
74
|
+
/** Read the document's first <audio> element. */
|
|
75
|
+
function readAudio(target) {
|
|
76
|
+
return target.evaluate(() => {
|
|
77
|
+
const a = document.querySelector('audio');
|
|
78
|
+
if (!a) return { present: false };
|
|
79
|
+
return { present: true, paused: a.paused, muted: a.muted, volume: a.volume, currentTime: a.currentTime };
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const fmt = (s) => (s && s.present
|
|
84
|
+
? `paused=${s.paused} muted=${s.muted} volume=${s.volume} t=${Number(s.currentTime).toFixed(2)}`
|
|
85
|
+
: 'no <audio> element');
|
|
86
|
+
const audible = (s) => !!(s && s.present && !s.paused && !s.muted && s.volume > 0);
|
|
87
|
+
|
|
88
|
+
/** Problems with two audio reads (empty = playing, unmuted and advancing). */
|
|
89
|
+
function audioProblems(a, b) {
|
|
90
|
+
const out = [];
|
|
91
|
+
if (!a || !a.present) return ['no <audio> element in the document'];
|
|
92
|
+
if (!audible(a)) out.push(`first read not playing (${fmt(a)})`);
|
|
93
|
+
if (!audible(b)) out.push(`second read not playing (${fmt(b)})`);
|
|
94
|
+
if (!(b && b.currentTime > a.currentTime)) out.push(`currentTime did not advance (${Number(a.currentTime).toFixed(2)} -> ${Number(b && b.currentTime).toFixed(2)})`);
|
|
95
|
+
return out;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Click the parent's cover, return { frame, handle, t0 } for the mounted sandboxed iframe. */
|
|
99
|
+
async function mountEmbed(page, base, slug) {
|
|
100
|
+
await page.goto(`${base}/post/${slug}/`, { waitUntil: 'load', timeout: 30000 });
|
|
101
|
+
await page.click('#cover');
|
|
102
|
+
const t0 = Date.now();
|
|
103
|
+
const handle = await page.waitForSelector('#video', { timeout: 10000 });
|
|
104
|
+
const frame = await handle.contentFrame();
|
|
105
|
+
if (!frame) throw new Error('iframe has no content frame');
|
|
106
|
+
await frame.waitForLoadState('load', { timeout: 30000 });
|
|
107
|
+
return { frame, handle, t0 };
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
async function embedCheck(browser, base, slug) {
|
|
111
|
+
const context = await browser.newContext({ viewport: VIEWPORT });
|
|
112
|
+
try {
|
|
113
|
+
const page = await context.newPage();
|
|
114
|
+
const { frame, handle, t0 } = await mountEmbed(page, base, slug);
|
|
115
|
+
const reads = []; const shots = [];
|
|
116
|
+
for (const ms of EMBED_READS_MS) {
|
|
117
|
+
await until(t0, ms);
|
|
118
|
+
reads.push(await readAudio(frame));
|
|
119
|
+
shots.push(await handle.screenshot({ type: 'png' }));
|
|
120
|
+
}
|
|
121
|
+
const problems = audioProblems(reads[0], reads[1]);
|
|
122
|
+
if (shots[0].equals(shots[1])) problems.push('frame picture identical at 2.5 s and 4 s');
|
|
123
|
+
return { id: 'standalone-embed', ok: problems.length === 0, detail: problems.length ? problems.join('; ') : `plays after the click (${fmt(reads[0])} -> t=${Number(reads[1].currentTime).toFixed(2)}) and the picture moves` };
|
|
124
|
+
} finally { await context.close(); }
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
async function reducedMotionCheck(browser, base, slug) {
|
|
128
|
+
const context = await browser.newContext({ viewport: VIEWPORT, reducedMotion: 'reduce' });
|
|
129
|
+
try {
|
|
130
|
+
const page = await context.newPage();
|
|
131
|
+
const { frame, handle, t0 } = await mountEmbed(page, base, slug);
|
|
132
|
+
const start = await frame.evaluate(() => {
|
|
133
|
+
const d = window.smDemo;
|
|
134
|
+
const src = d && Array.isArray(d.scenes) ? d.scenes : [];
|
|
135
|
+
const e = src[1];
|
|
136
|
+
const v = typeof e === 'number' ? e : (e && typeof e === 'object' ? (typeof e.t === 'number' ? e.t : e.start) : undefined);
|
|
137
|
+
return typeof v === 'number' && isFinite(v) ? v : null;
|
|
138
|
+
});
|
|
139
|
+
if (start === null) return { id: 'standalone-reduced-motion', ok: false, detail: 'window.smDemo.scenes has no second scene start to compare across' };
|
|
140
|
+
const s = Math.min(Math.max(start, 0), MAX_SCENE_S);
|
|
141
|
+
const beforeS = Math.max(1, s - 1.5); const afterS = s + 1.5;
|
|
142
|
+
await until(t0, beforeS * 1000);
|
|
143
|
+
const a = await readAudio(frame); const before = await handle.screenshot({ type: 'png' });
|
|
144
|
+
await until(t0, afterS * 1000);
|
|
145
|
+
const b = await readAudio(frame); const after = await handle.screenshot({ type: 'png' });
|
|
146
|
+
const problems = audioProblems(a, b);
|
|
147
|
+
if (before.equals(after)) problems.push(`picture identical at ${beforeS.toFixed(1)} s and ${afterS.toFixed(1)} s (frozen across scene 2 at ${s} s)`);
|
|
148
|
+
return { id: 'standalone-reduced-motion', ok: problems.length === 0, detail: problems.length ? `under prefers-reduced-motion: ${problems.join('; ')}` : `under prefers-reduced-motion it plays and cuts to scene 2 at ${s} s` };
|
|
149
|
+
} finally { await context.close(); }
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
async function tapForSoundCheck(browser, base, slug) {
|
|
153
|
+
const context = await browser.newContext({ viewport: VIEWPORT });
|
|
154
|
+
try {
|
|
155
|
+
const page = await context.newPage();
|
|
156
|
+
await page.goto(`${base}/blog-videos/${slug}/`, { waitUntil: 'load', timeout: 30000 });
|
|
157
|
+
await sleep(TAP_SETTLE_MS);
|
|
158
|
+
const pre = await readAudio(page);
|
|
159
|
+
if (!pre.present) return { id: 'standalone-tap-for-sound', ok: false, detail: 'no <audio> element in the document' };
|
|
160
|
+
if (!pre.paused) return { id: 'standalone-tap-for-sound', ok: false, detail: `expected the audio paused before any gesture when opened top-level (${fmt(pre)})` };
|
|
161
|
+
await page.mouse.click(Math.round(VIEWPORT.width / 2), Math.round(VIEWPORT.height / 2));
|
|
162
|
+
const t0 = Date.now();
|
|
163
|
+
let first = null; let last = pre;
|
|
164
|
+
while (Date.now() - t0 <= TAP_WINDOW_MS) {
|
|
165
|
+
await sleep(100);
|
|
166
|
+
last = await readAudio(page);
|
|
167
|
+
if (audible(last)) {
|
|
168
|
+
if (first && last.currentTime > first.currentTime) {
|
|
169
|
+
return { id: 'standalone-tap-for-sound', ok: true, detail: `one tap starts sound within ${Date.now() - t0} ms (${fmt(last)})` };
|
|
170
|
+
}
|
|
171
|
+
if (!first) first = last;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return { id: 'standalone-tap-for-sound', ok: false, detail: `opened top-level, one tap did not start unmuted, advancing audio within ${TAP_WINDOW_MS} ms (${fmt(last)}); add a pointerdown/keydown fallback that calls audio.play() after a refused play()` };
|
|
175
|
+
} finally { await context.close(); }
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
async function runScenario(fn, id, browser, base, slug) {
|
|
179
|
+
try { return await fn(browser, base, slug); } catch (e) { return { id, ok: false, detail: `check errored: ${e && e.message ? e.message.split('\n')[0] : String(e)}` }; }
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Resolves to [{ id, ok, detail }] for standalone-embed, standalone-reduced-motion and
|
|
184
|
+
* standalone-tap-for-sound. Rejects with StandaloneUsageError when the file is unreadable or
|
|
185
|
+
* Playwright/Chromium cannot be loaded.
|
|
186
|
+
*/
|
|
187
|
+
async function checkStandalone({ htmlPath, loadPlaywright } = {}) {
|
|
188
|
+
if (!htmlPath) throw new StandaloneUsageError('htmlPath is required');
|
|
189
|
+
let bytes;
|
|
190
|
+
try { bytes = fs.readFileSync(path.resolve(htmlPath)); } catch (e) { throw new StandaloneUsageError(`cannot read ${htmlPath}: ${e.message}`); }
|
|
191
|
+
const pw = (loadPlaywright || (() => defaultLoader()))();
|
|
192
|
+
const resolved = pw && typeof pw.then === 'function' ? await pw : pw;
|
|
193
|
+
const chromium = resolved && resolved.chromium;
|
|
194
|
+
if (!chromium) throw new StandaloneUsageError('Playwright is not installed (looked in cwd, global npm root and the npx cache)');
|
|
195
|
+
const slug = slugFor(htmlPath);
|
|
196
|
+
const { server, base } = await startServer(bytes, slug);
|
|
197
|
+
try {
|
|
198
|
+
let browser;
|
|
199
|
+
try { browser = await chromium.launch({ headless: true, args: [AUTOPLAY_ARG] }); } catch (e) {
|
|
200
|
+
throw new StandaloneUsageError(`Chromium could not launch: ${e && e.message ? e.message.split('\n')[0] : String(e)}`);
|
|
201
|
+
}
|
|
202
|
+
try {
|
|
203
|
+
return [
|
|
204
|
+
await runScenario(embedCheck, 'standalone-embed', browser, base, slug),
|
|
205
|
+
await runScenario(reducedMotionCheck, 'standalone-reduced-motion', browser, base, slug),
|
|
206
|
+
await runScenario(tapForSoundCheck, 'standalone-tap-for-sound', browser, base, slug),
|
|
207
|
+
];
|
|
208
|
+
} finally { await browser.close(); }
|
|
209
|
+
} finally {
|
|
210
|
+
await new Promise((r) => server.close(() => r()));
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
async function main(argv) {
|
|
215
|
+
const file = argv[0];
|
|
216
|
+
if (!file || argv.length > 1) { process.stderr.write('usage: node standalone.cjs <file.html>\n'); return 2; }
|
|
217
|
+
try {
|
|
218
|
+
const results = await checkStandalone({ htmlPath: file });
|
|
219
|
+
process.stdout.write(`${JSON.stringify(results, null, 2)}\n`);
|
|
220
|
+
return results.every((r) => r.ok) ? 0 : 1;
|
|
221
|
+
} catch (e) {
|
|
222
|
+
process.stderr.write(`${e && e.message ? e.message : String(e)}\n`);
|
|
223
|
+
return 2;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
if (require.main === module) {
|
|
228
|
+
main(process.argv.slice(2)).then((code) => { process.exitCode = code; });
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
module.exports = { checkStandalone, BLOG_VIDEO_CSP, AUTOPLAY_ARG, StandaloneUsageError, slugFor };
|
|
@@ -181,6 +181,11 @@ async function mergeActiveIndex(cwd, { sessions: rawMemorySessions = {}, events:
|
|
|
181
181
|
Promise.resolve()
|
|
182
182
|
.then(() => stopPreview(id))
|
|
183
183
|
.catch((e) => console.warn(`[activeIndexMerge] app preview stop failed for ${id}`, e));
|
|
184
|
+
// Outside-state poke: a deleted open Epic leaves the index here and
|
|
185
|
+
// writes no event-log kind the emitter listens for, so it yields 'gone'.
|
|
186
|
+
Promise.resolve()
|
|
187
|
+
.then(() => require('./epicStateEmitter.cjs').pokeEpicState(cwd, id))
|
|
188
|
+
.catch((e) => console.warn(`[activeIndexMerge] epic state poke failed for ${id}`, e));
|
|
184
189
|
}
|
|
185
190
|
// Status mirror (epicStatusMirror.cjs) — this IPC handler is the
|
|
186
191
|
// renderer-driven persist path (persistActiveIndex), the write site for
|