claude-code-session-manager 0.127.0 → 0.128.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 (76) hide show
  1. package/dist/assets/{AgentLibrary-DKQznr7o.js → AgentLibrary-cNQU5YWy.js} +1 -1
  2. package/dist/assets/{Button-CZXqmIiM.js → Button-9dIPAOBg.js} +1 -1
  3. package/dist/assets/{DataModel-piyV33To.js → DataModel-DrDJ6ysw.js} +1 -1
  4. package/dist/assets/{History-BxwtrKF2.js → History-4rrDdWNP.js} +1 -1
  5. package/dist/assets/{Hooks-DogeSPII.js → Hooks-Bj_jF5Pa.js} +1 -1
  6. package/dist/assets/{Library-BDt6EeQQ.js → Library-D-Wsxrh7.js} +1 -1
  7. package/dist/assets/{ListDetail-CwS-LKar.js → ListDetail-D7Om0H8j.js} +1 -1
  8. package/dist/assets/{McpServers-D2HVljgS.js → McpServers-CbIbSd5o.js} +1 -1
  9. package/dist/assets/{Memory-hNzuOGn8.js → Memory-DgQlvQrO.js} +1 -1
  10. package/dist/assets/{Panel-BLDrsUeq.js → Panel-DZHiD8Ar.js} +1 -1
  11. package/dist/assets/{Permissions-DzZ5vaJW.js → Permissions-CfzduF4B.js} +1 -1
  12. package/dist/assets/{Plugins-Cz9yaxzG.js → Plugins-D-AG5nAo.js} +2 -2
  13. package/dist/assets/{ProvenanceBadge-CCgLO4m9.js → ProvenanceBadge-B9JSEjll.js} +1 -1
  14. package/dist/assets/{SaveBar-Shmn699J.js → SaveBar-mVKig6hL.js} +1 -1
  15. package/dist/assets/{Scheduler-Bqr0WHNd.js → Scheduler-DFTCnh60.js} +1 -1
  16. package/dist/assets/{ScopeSwitcher-CBx1fB5g.js → ScopeSwitcher-s8J-yr7Z.js} +1 -1
  17. package/dist/assets/{Settings-Ci8in-yF.js → Settings-BTmxRMaP.js} +1 -1
  18. package/dist/assets/{SkillReferenceGraph-BWwljba8.js → SkillReferenceGraph-C5lKqf5y.js} +1 -1
  19. package/dist/assets/{Skills-BON6o-c4.js → Skills-CxOacq0k.js} +1 -1
  20. package/dist/assets/{SystemPrompt-D5epIYYs.js → SystemPrompt-BCWg5FAz.js} +1 -1
  21. package/dist/assets/{TagLibrary-C2qDZROJ.js → TagLibrary-BnF0_PkG.js} +1 -1
  22. package/dist/assets/{TiptapBody-SZhI3-bW.js → TiptapBody-C2Iu6rZd.js} +1 -1
  23. package/dist/assets/{Toggle-C_qFDG0g.js → Toggle-C-oD66BG.js} +1 -1
  24. package/dist/assets/{ViewTabs-C9q5WCEd.js → ViewTabs-Cs4v7vLY.js} +1 -1
  25. package/dist/assets/{historyTotals-BCl7IOhY.js → historyTotals-CbRSLD8f.js} +1 -1
  26. package/dist/assets/{index-BnKaYERU.css → index-DtdWBGrI.css} +1 -1
  27. package/dist/assets/index-DzY_GXYY.js +3081 -0
  28. package/dist/assets/{settingsSchema-BBrRBrBr.js → settingsSchema-bSBfHuan.js} +1 -1
  29. package/dist/assets/{skillFrontmatter-B01qJk6N.js → skillFrontmatter-BEseWm8r.js} +1 -1
  30. package/dist/assets/{useAgentsDirWatch-CuR3GSjS.js → useAgentsDirWatch-CdyHxKCI.js} +1 -1
  31. package/dist/index.html +2 -2
  32. package/dist-web/app.css +1 -1
  33. package/dist-web/app.js +343 -341
  34. package/package.json +1 -1
  35. package/scripts/scheduler-mcp-server.cjs +170 -6
  36. package/src/main/build-info.json +4 -4
  37. package/src/main/index.cjs +14 -0
  38. package/src/main/ipcSchemas.cjs +107 -0
  39. package/src/main/lib/claude/agentModelResolve.cjs +26 -7
  40. package/src/main/lib/claude/personaToolScope.cjs +40 -2
  41. package/src/main/lib/demo-video-kit/capture.cjs +113 -0
  42. package/src/main/lib/demo-video-kit/character.cjs +97 -0
  43. package/src/main/lib/demo-video-kit/checks.cjs +150 -0
  44. package/src/main/lib/demo-video-kit/frames.cjs +200 -0
  45. package/src/main/lib/demo-video-kit/seedKit.cjs +52 -0
  46. package/src/main/lib/demo-video-kit/sound.cjs +312 -0
  47. package/src/main/lib/epic/epicValidationHook.cjs +17 -1
  48. package/src/main/lib/feedback-remote/projectHomeAdminRoutes.cjs +185 -34
  49. package/src/main/lib/feedback-remote/remoteIpcDispatch.cjs +15 -0
  50. package/src/main/lib/mcpToolCatalog.cjs +71 -11
  51. package/src/main/lib/opsOwnership.cjs +9 -5
  52. package/src/main/lib/persona-macro/builtinMacros.cjs +19 -5
  53. package/src/main/lib/persona-macro/macroJobDispatch.cjs +116 -0
  54. package/src/main/lib/persona-macro/macroJobIpc.cjs +50 -0
  55. package/src/main/lib/persona-macro/macroJobStatus.cjs +112 -0
  56. package/src/main/lib/persona-macro/macroLibrary.cjs +16 -0
  57. package/src/main/lib/persona-macro/shippedPersonaSeeds.cjs +89 -0
  58. package/src/main/lib/prd/prdCreate.cjs +12 -1
  59. package/src/main/lib/prd/prdFrontmatter.cjs +7 -2
  60. package/src/main/lib/project-pages/pagesLibrary.cjs +171 -0
  61. package/src/main/lib/project-pages/playerBridge.cjs +129 -0
  62. package/src/main/lib/scheduler/scheduleJobSchema.cjs +2 -0
  63. package/src/main/lib/smfileHeaders.cjs +11 -3
  64. package/src/main/projectPages.cjs +107 -30
  65. package/src/main/promptSessionsIpc.cjs +131 -0
  66. package/src/main/scheduler/prdParser.cjs +2 -0
  67. package/src/main/scheduler.cjs +26 -9
  68. package/src/main/seedSchedulerMcp.cjs +10 -1
  69. package/src/main/transcripts.cjs +8 -0
  70. package/src/main/webRemote.cjs +3 -1
  71. package/src/preload/api.d.ts +101 -5
  72. package/src/preload/apiSurface.json +70 -0
  73. package/src/preload/index.cjs +13 -0
  74. package/src/seed/agents/demo-video-builder.md +86 -36
  75. package/src/seed/agents/project-home-builder.md +26 -13
  76. package/dist/assets/index-CMIYLbPb.js +0 -3079
@@ -0,0 +1,312 @@
1
+ 'use strict';
2
+ // Demo-video kit sound helper: synthesized royalty-free music bed, small SFX set,
3
+ // ducked mix under narration, and two-pass ffmpeg loudnorm (-14 LUFS / -1.5 dBTP).
4
+ // Node builtins only; ffmpeg is spawned without a shell and every call has a timeout.
5
+ const fs = require('fs');
6
+ const path = require('path');
7
+ const { spawnSync } = require('child_process');
8
+
9
+ const SR = 44100;
10
+ const FFMPEG = process.env.SM_FFMPEG || 'ffmpeg';
11
+ const FFMPEG_TIMEOUT_MS = 120000;
12
+ const TARGET = { I: -14, TP: -1.5, LRA: 11 };
13
+ const DUCK_DB = 4;
14
+ const BED_BASE_DB = -16; // bed level under silence, relative to full scale before loudnorm
15
+
16
+ // Style presets: tempo, root (Hz), chord progression as semitone triads, timbre, pulse.
17
+ const STYLES = {
18
+ Professional: { bpm: 84, root: 130.81, prog: [[0, 4, 7], [5, 9, 12], [7, 11, 14], [0, 4, 7]], pad: 0.5, bass: 0.35, pulse: 0, pluck: 0.15, bright: 0.2 },
19
+ Fun: { bpm: 118, root: 196.0, prog: [[0, 4, 7], [7, 11, 14], [9, 12, 16], [5, 9, 12]], pad: 0.25, bass: 0.35, pulse: 0.5, pluck: 0.45, bright: 0.6 },
20
+ 'Animated whiteboard': { bpm: 100, root: 174.61, prog: [[0, 4, 7], [9, 12, 16], [5, 9, 12], [7, 11, 14]], pad: 0.3, bass: 0.3, pulse: 0.25, pluck: 0.5, bright: 0.45 },
21
+ 'Kinetic typography': { bpm: 124, root: 146.83, prog: [[0, 3, 7], [8, 12, 15], [5, 8, 12], [10, 14, 17]], pad: 0.25, bass: 0.5, pulse: 0.6, pluck: 0.3, bright: 0.5 },
22
+ };
23
+
24
+ function mulberry32(seed) {
25
+ let a = (Number(seed) >>> 0) || 1;
26
+ return () => {
27
+ a = (a + 0x6d2b79f5) >>> 0;
28
+ let t = a;
29
+ t = Math.imul(t ^ (t >>> 15), t | 1);
30
+ t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
31
+ return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
32
+ };
33
+ }
34
+
35
+ const semi = (root, n) => root * Math.pow(2, n / 12);
36
+ const dbToGain = (db) => Math.pow(10, db / 20);
37
+
38
+ /** Wrap mono Float32 samples in a WAV (IEEE float, format 3). */
39
+ function encodeWav(samples, sr = SR) {
40
+ const dataBytes = samples.length * 4;
41
+ const buf = Buffer.alloc(44 + dataBytes);
42
+ buf.write('RIFF', 0, 'ascii');
43
+ buf.writeUInt32LE(36 + dataBytes, 4);
44
+ buf.write('WAVE', 8, 'ascii');
45
+ buf.write('fmt ', 12, 'ascii');
46
+ buf.writeUInt32LE(16, 16);
47
+ buf.writeUInt16LE(3, 20);
48
+ buf.writeUInt16LE(1, 22);
49
+ buf.writeUInt32LE(sr, 24);
50
+ buf.writeUInt32LE(sr * 4, 28);
51
+ buf.writeUInt16LE(4, 32);
52
+ buf.writeUInt16LE(32, 34);
53
+ buf.write('data', 36, 'ascii');
54
+ buf.writeUInt32LE(dataBytes, 40);
55
+ for (let i = 0; i < samples.length; i++) buf.writeFloatLE(samples[i], 44 + i * 4);
56
+ return buf;
57
+ }
58
+
59
+ /** Read a mono 32-bit float WAV into Float32Array. */
60
+ function decodeWavF32(buf) {
61
+ if (buf.toString('ascii', 0, 4) !== 'RIFF' || buf.toString('ascii', 8, 12) !== 'WAVE') throw new Error('not a WAV file');
62
+ let pos = 12;
63
+ let fmt = null;
64
+ while (pos + 8 <= buf.length) {
65
+ const id = buf.toString('ascii', pos, pos + 4);
66
+ let size = buf.readUInt32LE(pos + 4);
67
+ const body = pos + 8;
68
+ if (id === 'fmt ') fmt = { tag: buf.readUInt16LE(body), ch: buf.readUInt16LE(body + 2), sr: buf.readUInt32LE(body + 4), bits: buf.readUInt16LE(body + 14) };
69
+ if (id === 'data') {
70
+ if (!fmt || fmt.tag !== 3 || fmt.bits !== 32 || fmt.ch !== 1) throw new Error('expected mono float32 WAV');
71
+ size = Math.min(size, buf.length - body);
72
+ const n = Math.floor(size / 4);
73
+ const out = new Float32Array(n);
74
+ for (let i = 0; i < n; i++) out[i] = buf.readFloatLE(body + i * 4);
75
+ return out;
76
+ }
77
+ pos = body + size + (size % 2);
78
+ }
79
+ throw new Error('WAV has no data chunk');
80
+ }
81
+
82
+ function softClipPeak(x, peak) {
83
+ let m = 0;
84
+ for (let i = 0; i < x.length; i++) { const a = Math.abs(x[i]); if (a > m) m = a; }
85
+ if (m > 0) { const g = peak / m; for (let i = 0; i < x.length; i++) x[i] *= g; }
86
+ }
87
+
88
+ function bedSamples({ style, lengthS, seed }) {
89
+ const p = STYLES[style];
90
+ if (!p) throw new Error(`unknown style: ${style} (expected one of ${Object.keys(STYLES).join(', ')})`);
91
+ const n = Math.max(1, Math.round(Number(lengthS) * SR));
92
+ const rnd = mulberry32(seed);
93
+ const out = new Float32Array(n);
94
+ const beat = 60 / p.bpm;
95
+ const barS = beat * 4;
96
+ // Seed picks a transposition and a pluck pattern so different seeds give different beds.
97
+ const transpose = Math.floor(rnd() * 5) - 2;
98
+ const pattern = Array.from({ length: 8 }, () => rnd() < 0.7);
99
+ const arpPick = Array.from({ length: 8 }, () => Math.floor(rnd() * 3));
100
+ const root = semi(p.root, transpose);
101
+ const TAU = 2 * Math.PI;
102
+ for (let i = 0; i < n; i++) {
103
+ const t = i / SR;
104
+ const bar = Math.floor(t / barS);
105
+ const chord = p.prog[bar % p.prog.length];
106
+ const tb = t - bar * barS; // time inside bar
107
+ // Pad: detuned sines with slow swell per bar.
108
+ const swell = Math.sin(Math.PI * Math.min(1, tb / barS)) ** 0.5;
109
+ let v = 0;
110
+ for (const st of chord) {
111
+ const f = semi(root, st);
112
+ v += p.pad * swell * (Math.sin(TAU * f * t) + Math.sin(TAU * f * 1.004 * t) * 0.6 + p.bright * 0.3 * Math.sin(TAU * f * 2 * t)) / 3;
113
+ }
114
+ // Bass on beats 1 and 3 of each bar.
115
+ const bf = semi(root, chord[0]) / 2;
116
+ const bt = tb % (beat * 2);
117
+ v += p.bass * Math.sin(TAU * bf * t) * Math.exp(-bt * 2.2) * 0.9;
118
+ // Eighth-note pluck arpeggio.
119
+ const eighth = beat / 2;
120
+ const step = Math.floor(tb / eighth);
121
+ if (p.pluck > 0 && pattern[step % 8]) {
122
+ const et = tb - step * eighth;
123
+ const pf = semi(root, chord[arpPick[step % 8]] + 12);
124
+ v += p.pluck * 0.5 * Math.sin(TAU * pf * t) * Math.exp(-et * 9);
125
+ }
126
+ // Soft pulse: kick-like thump on every beat.
127
+ if (p.pulse > 0) {
128
+ const kt = tb % beat;
129
+ v += p.pulse * 0.5 * Math.sin(TAU * (55 + 90 * Math.exp(-kt * 30)) * kt) * Math.exp(-kt * 10);
130
+ }
131
+ out[i] = v;
132
+ }
133
+ softClipPeak(out, 0.8);
134
+ // Fade in/out so the bed never clicks at the edges.
135
+ const fade = Math.min(Math.round(1.0 * SR), Math.floor(n / 2));
136
+ for (let i = 0; i < fade; i++) { const g = i / fade; out[i] *= g; out[n - 1 - i] *= g; }
137
+ return out;
138
+ }
139
+
140
+ /** Deterministic Float32 PCM WAV (mono, 44.1 kHz) music bed. */
141
+ function buildMusicBed({ style, lengthS, seed = 1 }) {
142
+ return encodeWav(bedSamples({ style, lengthS, seed }));
143
+ }
144
+
145
+ const SFX_NAMES = ['whoosh', 'pop', 'chime', 'click'];
146
+
147
+ function sfxSamples(name) {
148
+ if (!SFX_NAMES.includes(name)) throw new Error(`unknown sfx: ${name} (expected one of ${SFX_NAMES.join(', ')})`);
149
+ const TAU = 2 * Math.PI;
150
+ const rnd = mulberry32(0x5f3759df);
151
+ let durS;
152
+ switch (name) {
153
+ case 'whoosh': durS = 0.6; break;
154
+ case 'pop': durS = 0.15; break;
155
+ case 'chime': durS = 1.2; break;
156
+ default: durS = 0.05;
157
+ }
158
+ const n = Math.round(durS * SR);
159
+ const out = new Float32Array(n);
160
+ let lp = 0;
161
+ for (let i = 0; i < n; i++) {
162
+ const t = i / SR;
163
+ const x = t / durS;
164
+ if (name === 'whoosh') {
165
+ // Noise through a sweeping one-pole low-pass, bell-shaped envelope.
166
+ const a = 0.02 + 0.5 * Math.sin(Math.PI * x);
167
+ lp += a * ((rnd() * 2 - 1) - lp);
168
+ out[i] = lp * Math.sin(Math.PI * x) ** 2 * 1.6;
169
+ } else if (name === 'pop') {
170
+ out[i] = Math.sin(TAU * (180 + 520 * Math.exp(-t * 60)) * t) * Math.exp(-t * 28);
171
+ } else if (name === 'chime') {
172
+ let v = 0;
173
+ [[880, 1], [1318.5, 0.5], [1760, 0.3], [2637, 0.12]].forEach(([f, amp]) => { v += amp * Math.sin(TAU * f * t); });
174
+ out[i] = v * Math.exp(-t * 4) * Math.min(1, t * 400) * 0.45;
175
+ } else {
176
+ out[i] = ((rnd() * 2 - 1) * 0.6 + Math.sin(TAU * 2400 * t) * 0.4) * Math.exp(-t * 110);
177
+ }
178
+ }
179
+ softClipPeak(out, 0.7);
180
+ return out;
181
+ }
182
+
183
+ /** SFX as Float32 WAV. name: whoosh | pop | chime | click. */
184
+ function buildSfx(name) {
185
+ return encodeWav(sfxSamples(name));
186
+ }
187
+
188
+ function runFfmpeg(args) {
189
+ const r = spawnSync(FFMPEG, args, { encoding: 'utf8', timeout: FFMPEG_TIMEOUT_MS, maxBuffer: 64 * 1024 * 1024, shell: false });
190
+ if (r.error) throw new Error(`ffmpeg failed to run: ${r.error.message}`);
191
+ if (r.status !== 0) throw new Error(`ffmpeg exited ${r.status}: ${String(r.stderr).slice(-600)}`);
192
+ return String(r.stderr || '');
193
+ }
194
+
195
+ /** Parse ffmpeg `ebur128=peak=true` summary into {lufs, truePeakDb}. */
196
+ function parseEbur128(text) {
197
+ const s = String(text);
198
+ const i = s.lastIndexOf('Summary:');
199
+ const tail = i >= 0 ? s.slice(i) : s;
200
+ const num = (m) => (m ? (m[1] === '-inf' ? -Infinity : Number(m[1])) : null);
201
+ const lufs = num(/Integrated loudness:\s*I:\s*(-?inf|-?[\d.]+)\s*LUFS/.exec(tail));
202
+ const truePeakDb = num(/True peak:\s*Peak:\s*(-?inf|-?[\d.]+)\s*dBFS/.exec(tail));
203
+ if (lufs === null || truePeakDb === null) throw new Error('could not parse ebur128 output');
204
+ return { lufs, truePeakDb };
205
+ }
206
+
207
+ /** Measure integrated loudness and true peak of an audio/video file. */
208
+ function measure(file) {
209
+ const err = runFfmpeg(['-hide_banner', '-nostats', '-i', file, '-vn', '-af', 'ebur128=peak=true', '-f', 'null', '-']);
210
+ return parseEbur128(err);
211
+ }
212
+
213
+ /** Two-pass loudnorm of `input` into `output` at I=-14 TP=-1.5 LRA=11. */
214
+ function loudnorm(input, output) {
215
+ const base = `loudnorm=I=${TARGET.I}:TP=${TARGET.TP}:LRA=${TARGET.LRA}`;
216
+ const err1 = runFfmpeg(['-hide_banner', '-nostats', '-i', input, '-af', `${base}:print_format=json`, '-f', 'null', '-']);
217
+ const j = err1.slice(err1.lastIndexOf('{'), err1.lastIndexOf('}') + 1);
218
+ let m;
219
+ try { m = JSON.parse(j); } catch { throw new Error('could not parse loudnorm pass-1 output'); }
220
+ const f = (k) => {
221
+ const v = Number(m[k]);
222
+ if (!Number.isFinite(v)) throw new Error(`loudnorm pass-1 missing ${k}`);
223
+ return v;
224
+ };
225
+ const pass2 = `${base}:measured_I=${f('input_i')}:measured_TP=${f('input_tp')}:measured_LRA=${f('input_lra')}:measured_thresh=${f('input_thresh')}:offset=${f('target_offset')}:linear=true:print_format=summary`;
226
+ const codec = /\.wav$/i.test(output) ? ['-c:a', 'pcm_s16le'] : [];
227
+ runFfmpeg(['-hide_banner', '-nostats', '-y', '-i', input, '-af', pass2, '-ar', String(SR), ...codec, output]);
228
+ }
229
+
230
+ /** Per-sample gain (1 → -DUCK_DB) following speech activity; returns {gain, speechS}. */
231
+ function duckEnvelope(narr) {
232
+ const win = Math.round(0.02 * SR);
233
+ const nWin = Math.ceil(narr.length / win);
234
+ const speech = new Uint8Array(nWin);
235
+ let active = 0;
236
+ for (let w = 0; w < nWin; w++) {
237
+ let e = 0;
238
+ const end = Math.min(narr.length, (w + 1) * win);
239
+ for (let i = w * win; i < end; i++) e += narr[i] * narr[i];
240
+ const rms = Math.sqrt(e / Math.max(1, end - w * win));
241
+ if (rms > 0.01) { speech[w] = 1; active++; }
242
+ }
243
+ const hold = 15; // 300 ms hold bridges gaps between words
244
+ const target = new Float32Array(nWin).fill(1);
245
+ const low = dbToGain(-DUCK_DB);
246
+ let since = hold + 1;
247
+ for (let w = 0; w < nWin; w++) {
248
+ since = speech[w] ? 0 : since + 1;
249
+ if (since <= hold) target[w] = low;
250
+ }
251
+ const gain = new Float32Array(narr.length);
252
+ const atk = 1 - Math.exp(-1 / (0.05 * SR));
253
+ const rel = 1 - Math.exp(-1 / (0.3 * SR));
254
+ let g = 1;
255
+ for (let i = 0; i < narr.length; i++) {
256
+ const tg = target[Math.min(nWin - 1, Math.floor(i / win))];
257
+ g += (tg < g ? atk : rel) * (tg - g);
258
+ gain[i] = g;
259
+ }
260
+ return { gain, speechS: active * 0.02 };
261
+ }
262
+
263
+ /**
264
+ * Mix narration + ducked music bed + SFX cues, then loudnorm to -14 LUFS / -1.5 dBTP.
265
+ * cues: [{name, t}] (t in seconds; `at` also accepted). Output length is the longer of
266
+ * lengthS and the narration. Returns the measured {lufs, truePeakDb, speechS}.
267
+ */
268
+ function mix({ narrationWav, cues = [], style, lengthS, out, seed = 1 }) {
269
+ const dir = fs.mkdtempSync(path.join(require('os').tmpdir(), 'dvk-sound-'));
270
+ try {
271
+ const narrF32 = path.join(dir, 'narration.f32.wav');
272
+ runFfmpeg(['-hide_banner', '-nostats', '-y', '-i', narrationWav, '-vn', '-ac', '1', '-ar', String(SR), '-c:a', 'pcm_f32le', narrF32]);
273
+ const narr = decodeWavF32(fs.readFileSync(narrF32));
274
+ const n = Math.max(narr.length, Math.round(Number(lengthS) * SR));
275
+ const bed = bedSamples({ style, lengthS: n / SR, seed });
276
+ const { gain, speechS } = duckEnvelope(narr);
277
+ const bedGain = dbToGain(BED_BASE_DB);
278
+ const mixed = new Float32Array(n);
279
+ for (let i = 0; i < n; i++) {
280
+ const g = i < gain.length ? gain[i] : 1;
281
+ mixed[i] = (i < narr.length ? narr[i] : 0) + bed[i] * bedGain * g;
282
+ }
283
+ const sfxGain = dbToGain(-10);
284
+ for (const cue of cues) {
285
+ const at = Math.round(Number(cue.t ?? cue.at ?? 0) * SR);
286
+ const s = sfxSamples(cue.name);
287
+ for (let i = 0; i < s.length && at + i < n; i++) if (at + i >= 0) mixed[at + i] += s[i] * sfxGain;
288
+ }
289
+ const pre = path.join(dir, 'premix.f32.wav');
290
+ fs.writeFileSync(pre, encodeWav(mixed));
291
+ fs.mkdirSync(path.dirname(path.resolve(out)), { recursive: true });
292
+ loudnorm(pre, out);
293
+ return { ...measure(out), speechS };
294
+ } finally {
295
+ fs.rmSync(dir, { recursive: true, force: true });
296
+ }
297
+ }
298
+
299
+ module.exports = { buildMusicBed, buildSfx, mix, measure, parseEbur128, STYLES, SFX_NAMES, TARGET };
300
+
301
+ if (require.main === module) {
302
+ try {
303
+ const specPath = process.argv[2];
304
+ if (!specPath) throw new Error('usage: node sound.cjs <spec.json>');
305
+ const spec = JSON.parse(fs.readFileSync(specPath, 'utf8'));
306
+ const r = mix(spec);
307
+ process.stdout.write(JSON.stringify({ lufs: r.lufs, truePeakDb: r.truePeakDb, speechS: r.speechS }) + '\n');
308
+ } catch (e) {
309
+ process.stderr.write(`${e.message}\n`);
310
+ process.exit(1);
311
+ }
312
+ }
@@ -132,6 +132,19 @@ async function runEpicSettle({ cwd, epicId } = {}, deps = {}) {
132
132
  if (!settle.settled) return { action: 'none', reason: 'not-settled' };
133
133
  if (!settle.hasContent) return { action: 'none', reason: 'no-content' };
134
134
 
135
+ // Macro builds (rows carrying macroId): the artifact check and gate are the
136
+ // done-check; no sweep validator, no digest chat turn.
137
+ const macroSlugs = new Set();
138
+ let epicRows = 0;
139
+ for (const r of [...jobs, ...history]) {
140
+ if (!_rowInEpic(r, epicId)) continue;
141
+ epicRows++;
142
+ if (typeof r.macroId === 'string' && r.macroId.trim()) macroSlugs.add(bareSlug(r.slug));
143
+ }
144
+ if (epicRows > 0 && [...jobs, ...history].every((r) => !_rowInEpic(r, epicId) || (typeof r.macroId === 'string' && r.macroId.trim()))) {
145
+ return { action: 'none', reason: 'macro-build' };
146
+ }
147
+
135
148
  let newestDigest = null;
136
149
  for (const e of events) if (e && e.outcome === 'digest') newestDigest = e;
137
150
  if (newestDigest && newestDigest.digestKey === settle.digestKey) {
@@ -146,7 +159,10 @@ async function runEpicSettle({ cwd, epicId } = {}, deps = {}) {
146
159
  if (!_rowInEpic(r, epicId) || !isSweepValidatorSlug(r.slug) || !Array.isArray(r.dependsOn)) continue;
147
160
  for (const d of r.dependsOn) swept.add(bareSlug(d));
148
161
  }
149
- const candidates = settle.uncovered.filter((u) => !swept.has(u.bareSlug || bareSlug(u.slug)));
162
+ const candidates = settle.uncovered.filter((u) => {
163
+ const b = u.bareSlug || bareSlug(u.slug);
164
+ return !swept.has(b) && !macroSlugs.has(b);
165
+ });
150
166
  if (candidates.length) {
151
167
  const byBare = new Map();
152
168
  for (const h of history) {
@@ -1,9 +1,10 @@
1
1
  /**
2
- * projectHomeAdminRoutes.cjs — the two admin routes behind the
3
- * project_home_write MCP tool and its demo-video sibling:
4
- * POST /admin/project-home/write {cwd, html} -> project-pages/home.html
5
- * POST /admin/project-home/demo-video/write {cwd, html} -> project-pages/demo-video/index.html
6
- * both owned by writer 'project-home' (see opsOwnership.cjs). Registered
2
+ * projectHomeAdminRoutes.cjs — admin routes behind Project Home's library:
3
+ * POST /admin/project-home/pages/write -> project-pages/knowledge/<pageId>/{index.html,meta.json}
4
+ * POST /admin/project-home/videos/write -> project-pages/videos/<videoId>/{index.html,meta.json}
5
+ * POST /admin/project-home/write alias: {cwd, html} -> knowledge/overview/
6
+ * POST /admin/project-home/demo-video/write alias: {cwd, html} -> a new videos/vid-<id>/ project-demo entry
7
+ * all owned by writer 'project-home' (see opsOwnership.cjs). Registered
7
8
  * against the same injected localAdminHttp.cjs transport as
8
9
  * prdAdminRoutes.cjs.
9
10
  *
@@ -22,11 +23,15 @@
22
23
 
23
24
  const fs = require('node:fs');
24
25
  const path = require('node:path');
26
+ const crypto = require('node:crypto');
25
27
  const { readBody, sendJson } = require('./localAdminHttp.cjs');
26
28
  const { resolveProjectContext } = require('../projectRootResolve.cjs');
27
29
  const { opsPath, OPS_ROOT_DIR } = require('../opsOwnership.cjs');
28
30
  const config = require('../../config.cjs');
29
- const { schemas } = require('../../ipcSchemas.cjs');
31
+ const { schemas, ENTRY_ID_RE } = require('../../ipcSchemas.cjs');
32
+ const { validateCharacterJson, validateCharacterJs, readCharacter, characterDir, MAX_JS_BYTES: MAX_CHARACTER_JS_BYTES } = require('../demo-video-kit/character.cjs');
33
+ const { checkHtmlLimits } = require('../demo-video-kit/checks.cjs');
34
+ const { injectPlayerBridge } = require('../project-pages/playerBridge.cjs');
30
35
 
31
36
  const MAX_HTML_BYTES = 1024 * 1024;
32
37
  const MAX_DEMO_VIDEO_BYTES = 2 * 1024 * 1024;
@@ -72,7 +77,7 @@ const NETWORK_CHECKS = [
72
77
 
73
78
  const DURATION_META_RE = /<meta\b[^>]*\bname\s*=\s*["']sm-demo-duration["'][^>]*\bcontent\s*=\s*["'](\d+)["'][^>]*>/i;
74
79
  const MIN_DEMO_DURATION_S = 5;
75
- const MAX_DEMO_DURATION_S = 30;
80
+ const MAX_DEMO_DURATION_S = 60;
76
81
 
77
82
  const DEMO_VIDEO_CSP = '<meta http-equiv="Content-Security-Policy" content="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\'">';
78
83
 
@@ -87,9 +92,9 @@ function validateHomeHtml(html) {
87
92
  }
88
93
 
89
94
  /** -> null when `html` is acceptable, else a human-readable rejection reason. */
90
- function validateDemoVideoHtml(html) {
95
+ function validateDemoVideoHtml(html, maxBytes = MAX_DEMO_VIDEO_BYTES) {
91
96
  if (typeof html !== 'string' || html.trim().length === 0) return 'html must be a non-empty string';
92
- if (Buffer.byteLength(html, 'utf8') > MAX_DEMO_VIDEO_BYTES) return `html exceeds the ${MAX_DEMO_VIDEO_BYTES}-byte limit`;
97
+ if (Buffer.byteLength(html, 'utf8') > maxBytes) return `html exceeds the ${maxBytes}-byte limit`;
93
98
  for (const { re, message } of REMOTE_REFERENCE_CHECKS) {
94
99
  if (re.test(html)) return `html must be self-contained: ${message}`;
95
100
  }
@@ -162,19 +167,20 @@ function resolveCwd(rawCwd) {
162
167
  }
163
168
 
164
169
  /**
165
- * Builds a POST handler shared by both routes: read+parse the body, validate
166
- * against `schema`, resolve cwd, run `validate(html)`, optionally `transform`
167
- * the html (CSP injection), then write it atomically as writer 'project-home'.
170
+ * Builds a POST handler shared by every route: read+parse the body, validate
171
+ * against `schema`, resolve cwd, then `build(input)` -> {error} | {dir, html,
172
+ * meta}. The entry folder gets index.html then meta.json, both atomically as
173
+ * writer 'project-home'. Responds {ok, path (index.html), bytes}.
168
174
  */
169
- function makeWriteHandler({ schema, maxBytes, validate, transform, targetPath }) {
175
+ function makeWriteHandler({ schema, bodyLimit, build }) {
170
176
  return async (req, res) => {
171
- // Allow headroom over maxBytes for JSON escaping; the html byte limit
172
- // itself is enforced by `validate` below.
177
+ // Headroom over the html limit for JSON escaping; the html byte limit
178
+ // itself is enforced by `build`.
173
179
  let raw;
174
180
  try {
175
- raw = await readBody(req, maxBytes * 2 + 4096);
181
+ raw = await readBody(req, bodyLimit * 2 + 4096);
176
182
  } catch (e) {
177
- sendJson(res, 400, { ok: false, error: `request body rejected: ${e?.message ?? 'unreadable'} (html limit is ${maxBytes} bytes)` });
183
+ sendJson(res, 400, { ok: false, error: `request body rejected: ${e?.message ?? 'unreadable'} (html limit is ${bodyLimit} bytes)` });
178
184
  return;
179
185
  }
180
186
  let body;
@@ -196,43 +202,187 @@ function makeWriteHandler({ schema, maxBytes, validate, transform, targetPath })
196
202
  sendJson(res, resolved.status, { ok: false, error: resolved.error });
197
203
  return;
198
204
  }
199
- const rejection = validate(input.html);
200
- if (rejection) {
201
- sendJson(res, 400, { ok: false, error: rejection });
205
+ const built = build(input);
206
+ if (built.error) {
207
+ sendJson(res, 400, { ok: false, error: built.error });
202
208
  return;
203
209
  }
204
210
  // Only a route that is actually about to write widens config.cjs's
205
211
  // write boundary to this project root.
206
212
  config.addAllowedRoot(resolved.cwd);
207
- const finalHtml = transform ? transform(input.html) : input.html;
208
213
  try {
209
- const abs = targetPath(resolved.cwd);
210
- await fs.promises.mkdir(path.dirname(abs), { recursive: true });
211
- await config.writeTextAtomic(abs, finalHtml, { writer: 'project-home' });
212
- sendJson(res, 200, { ok: true, path: abs, bytes: Buffer.byteLength(finalHtml, 'utf8') });
214
+ const dir = opsPath(resolved.cwd, 'project-pages', ...built.dirParts);
215
+ await fs.promises.mkdir(dir, { recursive: true });
216
+ const abs = path.join(dir, 'index.html');
217
+ await config.writeTextAtomic(abs, built.html, { writer: 'project-home' });
218
+ await config.writeTextAtomic(path.join(dir, 'meta.json'), JSON.stringify(built.meta, null, 2) + '\n', { writer: 'project-home' });
219
+ sendJson(res, 200, { ok: true, path: abs, bytes: Buffer.byteLength(built.html, 'utf8'), id: built.meta.id });
213
220
  } catch (e) {
214
221
  sendJson(res, 500, { ok: false, error: e?.message ?? 'write failed' });
215
222
  }
216
223
  };
217
224
  }
218
225
 
226
+ /** Size cap for a video of `lengthS` seconds: 2 MiB per started 30 s. */
227
+ function maxVideoBytes(lengthS) {
228
+ return Math.ceil(lengthS / 30) * MAX_DEMO_VIDEO_BYTES;
229
+ }
230
+
231
+ function buildPage(input, { pageId, title, topic }) {
232
+ if (!ENTRY_ID_RE.test(pageId)) return { error: 'invalid pageId' };
233
+ const rejection = validateHomeHtml(input.html);
234
+ if (rejection) return { error: rejection };
235
+ return {
236
+ dirParts: ['knowledge', pageId],
237
+ html: input.html,
238
+ meta: schemas.projectPageMeta.parse({ id: pageId, title, topic, createdAt: new Date().toISOString(), model: '' }),
239
+ };
240
+ }
241
+
242
+ /** Shared video path. `meta` is the full video meta minus id/createdAt/report.bytes. */
243
+ function buildVideo(input, { videoId, title, kind, lengthS, meta }) {
244
+ if (!ENTRY_ID_RE.test(videoId)) return { error: 'invalid videoId' };
245
+ const cap = maxVideoBytes(lengthS);
246
+ const rejection = validateDemoVideoHtml(input.html, cap);
247
+ if (rejection) return { error: rejection };
248
+ const declared = Number(input.html.match(DURATION_META_RE)[1]);
249
+ if (declared !== lengthS) return { error: `sm-demo-duration (${declared}) must equal lengthS (${lengthS})` };
250
+ const html = injectPlayerBridge(injectCsp(input.html));
251
+ const bytes = Buffer.byteLength(html, 'utf8');
252
+ return {
253
+ dirParts: ['videos', videoId],
254
+ html,
255
+ meta: schemas.projectVideoMeta.parse({
256
+ ...meta,
257
+ id: videoId,
258
+ title,
259
+ kind,
260
+ lengthS,
261
+ createdAt: new Date().toISOString(),
262
+ report: { ...meta.report, bytes },
263
+ }),
264
+ };
265
+ }
266
+
267
+ function newVideoId() {
268
+ const alphabet = 'abcdefghijklmnopqrstuvwxyz0123456789';
269
+ const bytes = crypto.randomBytes(3);
270
+ let rnd = '';
271
+ for (const b of bytes) rnd += alphabet[b % alphabet.length];
272
+ return `vid-${Date.now().toString(36)}${rnd}`;
273
+ }
274
+
219
275
  function registerAdminRoute(adminHttp) {
220
- // POST /admin/project-home/write {cwd, html}
276
+ // POST /admin/project-home/pages/write {cwd, pageId, title, topic?, html}
277
+ adminHttp.registerRoute('POST', '/admin/project-home/pages/write', makeWriteHandler({
278
+ schema: schemas.projectPageAdminWriteBody,
279
+ bodyLimit: MAX_HTML_BYTES,
280
+ build: (i) => buildPage(i, { pageId: i.pageId, title: i.title, topic: i.topic ?? '' }),
281
+ }));
282
+
283
+ // POST /admin/project-home/videos/write {cwd, videoId, title, kind, lengthS, html, meta}
284
+ adminHttp.registerRoute('POST', '/admin/project-home/videos/write', makeWriteHandler({
285
+ schema: schemas.projectVideoAdminWriteBody,
286
+ bodyLimit: maxVideoBytes(MAX_DEMO_DURATION_S),
287
+ build: (i) => {
288
+ // Cheap kit checks re-run server-side; the alias route is exempt (Burrow sends no report).
289
+ const failed = (i.meta?.report?.checks ?? []).find((c) => c.ok === false);
290
+ if (failed) return { error: `report.checks failed: ${failed.id}${failed.detail ? ` (${failed.detail})` : ''}` };
291
+ const limits = checkHtmlLimits({ html: i.html, lengthS: i.lengthS });
292
+ if (!limits.ok) return { error: `${limits.id} check failed: ${limits.detail}` };
293
+ return buildVideo(i, i);
294
+ },
295
+ }));
296
+
297
+ // Alias: POST /admin/project-home/write {cwd, html} -> knowledge/overview/
221
298
  adminHttp.registerRoute('POST', '/admin/project-home/write', makeWriteHandler({
222
299
  schema: schemas.projectHomeAdminWriteBody,
223
- maxBytes: MAX_HTML_BYTES,
224
- validate: validateHomeHtml,
225
- targetPath: (cwd) => opsPath(cwd, 'project-pages', 'home.html'),
300
+ bodyLimit: MAX_HTML_BYTES,
301
+ build: (i) => buildPage(i, { pageId: 'overview', title: 'Overview', topic: 'overview' }),
226
302
  }));
227
303
 
228
- // POST /admin/project-home/demo-video/write {cwd, html}
304
+ // Alias: POST /admin/project-home/demo-video/write {cwd, html} -> a NEW videos/vid-*/ entry
229
305
  adminHttp.registerRoute('POST', '/admin/project-home/demo-video/write', makeWriteHandler({
230
306
  schema: schemas.projectDemoVideoAdminWriteBody,
231
- maxBytes: MAX_DEMO_VIDEO_BYTES,
232
- validate: validateDemoVideoHtml,
233
- transform: injectCsp,
234
- targetPath: (cwd) => opsPath(cwd, 'project-pages', 'demo-video', 'index.html'),
307
+ bodyLimit: maxVideoBytes(MAX_DEMO_DURATION_S),
308
+ build: (i) => {
309
+ const rejection = validateDemoVideoHtml(i.html, maxVideoBytes(MAX_DEMO_DURATION_S));
310
+ if (rejection) return { error: rejection };
311
+ const lengthS = Number(i.html.match(DURATION_META_RE)[1]);
312
+ return buildVideo(i, {
313
+ videoId: newVideoId(),
314
+ title: 'Demo video',
315
+ kind: 'project-demo',
316
+ lengthS,
317
+ meta: {
318
+ style: '',
319
+ character: null,
320
+ sources: [],
321
+ report: { lufs: null, truePeakDb: null, speechS: null, readingGrade: null, checks: [] },
322
+ macroVersion: 0,
323
+ seedVersion: 0,
324
+ model: '',
325
+ effort: '',
326
+ },
327
+ });
328
+ },
235
329
  }));
330
+
331
+ // POST /admin/project-home/character/write {cwd, json, js, replace?} -> videos/_character/
332
+ adminHttp.registerRoute('POST', '/admin/project-home/character/write', characterWriteHandler);
333
+ }
334
+
335
+ async function characterWriteHandler(req, res) {
336
+ let raw;
337
+ try {
338
+ raw = await readBody(req, MAX_CHARACTER_JS_BYTES * 2 + 64 * 1024);
339
+ } catch (e) {
340
+ sendJson(res, 400, { ok: false, error: `request body rejected: ${e?.message ?? 'unreadable'}` });
341
+ return;
342
+ }
343
+ let body;
344
+ try {
345
+ body = raw ? JSON.parse(raw) : {};
346
+ } catch {
347
+ sendJson(res, 400, { ok: false, error: 'invalid JSON body' });
348
+ return;
349
+ }
350
+ if (!body || typeof body !== 'object' || Array.isArray(body)) {
351
+ sendJson(res, 400, { ok: false, error: 'invalid payload' });
352
+ return;
353
+ }
354
+ const resolved = resolveCwd(body.cwd);
355
+ if (!resolved.ok) {
356
+ sendJson(res, resolved.status, { ok: false, error: resolved.error });
357
+ return;
358
+ }
359
+ const json = body.json;
360
+ const jsonObj = typeof json === 'string' ? (() => { try { return JSON.parse(json); } catch { return null; } })() : json;
361
+ const jsonErr = validateCharacterJson(jsonObj);
362
+ if (jsonErr) {
363
+ sendJson(res, 400, { ok: false, error: `character.json invalid: ${jsonErr}` });
364
+ return;
365
+ }
366
+ const jsErr = validateCharacterJs(body.js, [...REMOTE_REFERENCE_CHECKS, ...NETWORK_CHECKS]);
367
+ if (jsErr) {
368
+ sendJson(res, 400, { ok: false, error: jsErr });
369
+ return;
370
+ }
371
+ if (!body.replace && readCharacter(resolved.cwd)) {
372
+ sendJson(res, 409, { ok: false, error: 'a character already exists — pass replace: true to overwrite it' });
373
+ return;
374
+ }
375
+ config.addAllowedRoot(resolved.cwd);
376
+ try {
377
+ const dir = characterDir(resolved.cwd);
378
+ await fs.promises.mkdir(dir, { recursive: true });
379
+ const jsPath = path.join(dir, 'character.js');
380
+ await config.writeTextAtomic(jsPath, body.js, { writer: 'project-home' });
381
+ await config.writeTextAtomic(path.join(dir, 'character.json'), JSON.stringify(jsonObj, null, 2) + '\n', { writer: 'project-home' });
382
+ sendJson(res, 200, { ok: true, path: dir, bytes: Buffer.byteLength(body.js, 'utf8') });
383
+ } catch (e) {
384
+ sendJson(res, 500, { ok: false, error: e?.message ?? 'write failed' });
385
+ }
236
386
  }
237
387
 
238
388
  module.exports = {
@@ -240,6 +390,7 @@ module.exports = {
240
390
  validateHomeHtml,
241
391
  validateDemoVideoHtml,
242
392
  injectCsp,
393
+ maxVideoBytes,
243
394
  DEMO_VIDEO_CSP,
244
395
  MAX_HTML_BYTES,
245
396
  MAX_DEMO_VIDEO_BYTES,
@@ -27,6 +27,15 @@ function captureIpcHandlers(ipcMain) {
27
27
  handlers.set(channel, fn)
28
28
  return original(channel, fn)
29
29
  }
30
+ // Send-kind rows (renderer ipcRenderer.send, e.g. log:write) are served by ipcMain.on
31
+ // listeners. Capture the first listener per channel; an invoke handler always wins.
32
+ if (typeof ipcMain.on === 'function') {
33
+ const originalOn = ipcMain.on.bind(ipcMain)
34
+ ipcMain.on = (channel, fn) => {
35
+ if (!handlers.has(channel) && typeof fn === 'function') handlers.set(channel, fn)
36
+ return originalOn(channel, fn)
37
+ }
38
+ }
30
39
  return handlers
31
40
  }
32
41
 
@@ -44,7 +53,13 @@ const PATH_FENCED_CHANNELS = Object.freeze({
44
53
  'files:list': { field: 'path', mode: 'root', allowHomeListing: true },
45
54
  'transcript:readRef': { field: 'filePath', mode: 'secret' },
46
55
  'transcript:path': { field: 'cwd', mode: 'secret' },
56
+ 'transcript:exists': { field: 'cwd', mode: 'secret' },
47
57
  'memory:read': { field: 'cwd', mode: 'secret' },
58
+ // Sessions read tier (main/promptSessionsIpc.cjs): cwd must sit inside a registered project root.
59
+ 'promptSessions:load-active-index': { field: 'cwd', mode: 'root' },
60
+ 'promptSessions:list-archived': { field: 'cwd', mode: 'root' },
61
+ 'promptSessions:read-archived': { field: 'cwd', mode: 'root' },
62
+ 'promptSessions:read-session-transcript': { field: 'cwd', mode: 'root' },
48
63
  })
49
64
 
50
65
  const SECRET_DIRS = new Set(['.ssh', '.gnupg', '.aws', '.kube', '.docker', '.password-store', '.azure', '.terraform.d'])