@biunow/agent-biutalk 1.1.6 → 1.1.8

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 (112) hide show
  1. package/_shared/.tmp-panel-smoke/art/smoke.mp4 +0 -0
  2. package/_shared/.tmp-panel-smoke/art-pipe/out/biuart-01_cave-mwq5kfpm.mp4 +0 -0
  3. package/_shared/.tmp-panel-smoke/art-pipe/panel-delivery.json +7 -0
  4. package/_shared/.tmp-panel-smoke/reel-pipe/film/index.html +7 -0
  5. package/_shared/.tmp-panel-smoke/reel-pipe/film/main.js +68 -0
  6. package/_shared/.tmp-panel-smoke/reel-pipe/film/panel-beats.json +20 -0
  7. package/_shared/.tmp-panel-smoke/reel-pipe/style-demo/CREDITS +20 -0
  8. package/_shared/.tmp-panel-smoke/reel-pipe/style-demo/build.sh +17 -0
  9. package/_shared/.tmp-panel-smoke/reel-pipe/style-demo/ease.js +43 -0
  10. package/_shared/.tmp-panel-smoke/reel-pipe/style-demo/events.json +1 -0
  11. package/_shared/.tmp-panel-smoke/reel-pipe/style-demo/film.js +533 -0
  12. package/_shared/.tmp-panel-smoke/reel-pipe/style-demo/fonts/OFL-Archivo.txt +93 -0
  13. package/_shared/.tmp-panel-smoke/reel-pipe/style-demo/fonts/OFL-DMSerifDisplay.txt +93 -0
  14. package/_shared/.tmp-panel-smoke/reel-pipe/style-demo/fonts/OFL-UnifrakturMaguntia.txt +94 -0
  15. package/_shared/.tmp-panel-smoke/reel-pipe/style-demo/fonts/fonts.css +3 -0
  16. package/_shared/.tmp-panel-smoke/reel-pipe/style-demo/index.html +6 -0
  17. package/_shared/.tmp-panel-smoke/reel-pipe/style-demo/lines.json +10 -0
  18. package/_shared/.tmp-panel-smoke/reel-pipe/style-demo/main.js +15 -0
  19. package/_shared/.tmp-panel-smoke/reel-pipe/style-demo/mix.py +116 -0
  20. package/_shared/.tmp-panel-smoke/reel-pipe/style-demo/music/score.py +168 -0
  21. package/_shared/.tmp-panel-smoke/reel-pipe/style-demo/music/score_meta.json +59 -0
  22. package/_shared/.tmp-panel-smoke/reel-pipe/style-demo/score.json +235 -0
  23. package/_shared/.tmp-panel-smoke/reel-pipe/style-demo/stills/styleframe.jpg +0 -0
  24. package/_shared/.tmp-panel-smoke/reel-pipe/style-demo/tools/fonts.sh +17 -0
  25. package/_shared/.tmp-panel-smoke/reel-pipe/style-demo/tools/subs.py +11 -0
  26. package/_shared/.tmp-panel-smoke/reel-pipe/style-demo/tools/words.py +20 -0
  27. package/_shared/.tmp-panel-smoke/reel-pipe/style-demo/voices/dur.json +10 -0
  28. package/_shared/.tmp-panel-smoke/reel-pipe/style-demo/voices/words.json +213 -0
  29. package/_shared/.tmp-panel-smoke/reel-pipe/style-demo/voices/words_rel.json +56 -0
  30. package/_shared/.tmp-panel-smoke/reel-pipe/style-ref.json +5 -0
  31. package/_shared/.tmp-panel-smoke/reel-pipe2/film/index.html +7 -0
  32. package/_shared/.tmp-panel-smoke/reel-pipe2/film/main.js +68 -0
  33. package/_shared/.tmp-panel-smoke/reel-pipe2/film/panel-beats.json +20 -0
  34. package/_shared/.tmp-panel-smoke/reel-pipe2/out/video.mp4 +0 -0
  35. package/_shared/.tmp-panel-smoke/reel-pipe2/panel-delivery.json +8 -0
  36. package/_shared/.tmp-panel-smoke/reel-pipe2/style-demo/CREDITS +20 -0
  37. package/_shared/.tmp-panel-smoke/reel-pipe2/style-demo/build.sh +17 -0
  38. package/_shared/.tmp-panel-smoke/reel-pipe2/style-demo/ease.js +43 -0
  39. package/_shared/.tmp-panel-smoke/reel-pipe2/style-demo/events.json +1 -0
  40. package/_shared/.tmp-panel-smoke/reel-pipe2/style-demo/film.js +533 -0
  41. package/_shared/.tmp-panel-smoke/reel-pipe2/style-demo/fonts/OFL-Archivo.txt +93 -0
  42. package/_shared/.tmp-panel-smoke/reel-pipe2/style-demo/fonts/OFL-DMSerifDisplay.txt +93 -0
  43. package/_shared/.tmp-panel-smoke/reel-pipe2/style-demo/fonts/OFL-UnifrakturMaguntia.txt +94 -0
  44. package/_shared/.tmp-panel-smoke/reel-pipe2/style-demo/fonts/fonts.css +3 -0
  45. package/_shared/.tmp-panel-smoke/reel-pipe2/style-demo/index.html +6 -0
  46. package/_shared/.tmp-panel-smoke/reel-pipe2/style-demo/lines.json +10 -0
  47. package/_shared/.tmp-panel-smoke/reel-pipe2/style-demo/main.js +15 -0
  48. package/_shared/.tmp-panel-smoke/reel-pipe2/style-demo/mix.py +116 -0
  49. package/_shared/.tmp-panel-smoke/reel-pipe2/style-demo/music/score.py +168 -0
  50. package/_shared/.tmp-panel-smoke/reel-pipe2/style-demo/music/score_meta.json +59 -0
  51. package/_shared/.tmp-panel-smoke/reel-pipe2/style-demo/score.json +235 -0
  52. package/_shared/.tmp-panel-smoke/reel-pipe2/style-demo/stills/styleframe.jpg +0 -0
  53. package/_shared/.tmp-panel-smoke/reel-pipe2/style-demo/tools/fonts.sh +17 -0
  54. package/_shared/.tmp-panel-smoke/reel-pipe2/style-demo/tools/subs.py +11 -0
  55. package/_shared/.tmp-panel-smoke/reel-pipe2/style-demo/tools/words.py +20 -0
  56. package/_shared/.tmp-panel-smoke/reel-pipe2/style-demo/voices/dur.json +10 -0
  57. package/_shared/.tmp-panel-smoke/reel-pipe2/style-demo/voices/words.json +213 -0
  58. package/_shared/.tmp-panel-smoke/reel-pipe2/style-demo/voices/words_rel.json +56 -0
  59. package/_shared/.tmp-panel-smoke/reel-pipe2/style-ref.json +5 -0
  60. package/_shared/.tmp-panel-smoke/remo-pipe/brief.md +2 -0
  61. package/_shared/.tmp-panel-smoke/remo-pipe/remo-job.json +4 -0
  62. package/_shared/.tmp-panel-smoke/remo-pipe2/brief.md +1 -0
  63. package/_shared/.tmp-panel-smoke/remo-pipe2/out/final.mp4 +0 -0
  64. package/_shared/.tmp-panel-smoke/remo-pipe2/panel-delivery.json +8 -0
  65. package/_shared/.tmp-panel-smoke/remo-pipe2/remo-job.json +4 -0
  66. package/_shared/.tmp-panel-smoke/vibe-pipe-ok/ep00-demo.mp4 +0 -0
  67. package/_shared/.tmp-panel-smoke/vibe-pipe-ok/out/ep00-demo.mp4 +0 -0
  68. package/_shared/.tmp-panel-smoke/vibe-pipe-ok/panel-delivery.json +7 -0
  69. package/_shared/.tmp-panel-smoke/vibe-pipe-ok/publish.json +10 -0
  70. package/_shared/.tmp-panel-smoke/vibe-still.jpg +0 -0
  71. package/_shared/.tmp-panel-smoke/vibe-still.log +6 -0
  72. package/_shared/.tmp-panel-smoke/vibe-still.log.err +0 -0
  73. package/_shared/.tmp-panel-smoke/vibe-still2.log +26 -0
  74. package/_shared/.tmp-panel-smoke/vibe-still2.log.err +0 -0
  75. package/_shared/lib/film-locate.mjs +203 -0
  76. package/_shared/lib/voice-catalog.mjs +127 -0
  77. package/_shared/scripts/apply-upload-limits.mjs +62 -0
  78. package/_shared/scripts/patch-film-hosts.mjs +233 -0
  79. package/_shared/scripts/patch-voice-options.mjs +41 -0
  80. package/_shared/scripts/sync-local-agents.mjs +67 -0
  81. package/_shared/scripts/wire-film-bridge.mjs +24 -0
  82. package/_shared/scripts/wire-voice-plus.mjs +68 -0
  83. package/_shared/studio/assert-panel-permit.mjs +67 -0
  84. package/_shared/studio/composer.css +559 -0
  85. package/_shared/studio/composer.js +728 -0
  86. package/_shared/studio/optimize-prompt.mjs +84 -0
  87. package/_shared/studio/optimize-prompt.test.mjs +47 -0
  88. package/_shared/studio/recipes.mjs +87 -0
  89. package/_shared/studio/select-menu.js +450 -0
  90. package/_shared/studio/to-english-prompt.mjs +165 -0
  91. package/_shared/studio/to-english-prompt.test.mjs +72 -0
  92. package/bin/server.js +52 -36
  93. package/data/looks.json +8 -0
  94. package/lib/film-bridge.mjs +1 -0
  95. package/lib/host.mjs +149 -264
  96. package/lib/voice-bridge.mjs +2 -0
  97. package/manifest.json +4 -3
  98. package/package.json +1 -1
  99. package/skills/biutalk/EXEC.md +69 -0
  100. package/skills/biutalk/SKILL.md +12 -10
  101. package/skills/biutalk/scripts/doctor.mjs +124 -0
  102. package/skills/biutalk/scripts/qc.mjs +129 -0
  103. package/skills/biutalk/scripts/scaffold.mjs +205 -0
  104. package/studio/app.js +17 -1
  105. package/studio/composer.css +115 -1
  106. package/studio/composer.js +389 -10
  107. package/studio/index.html +5 -1
  108. package/studio/optimize-prompt.mjs +84 -0
  109. package/studio/optimize-prompt.test.mjs +47 -0
  110. package/studio/recipes.mjs +1 -0
  111. package/studio/to-english-prompt.mjs +165 -0
  112. package/studio/to-english-prompt.test.mjs +72 -0
package/lib/host.mjs CHANGED
@@ -9,6 +9,9 @@ import path from 'node:path';
9
9
  import { fileURLToPath } from 'node:url';
10
10
  import { spawn } from 'node:child_process';
11
11
  import crypto from 'node:crypto';
12
+ import { optimizePrompt } from '../studio/optimize-prompt.mjs';
13
+ import { isIntermediateMp4, rescueMissingFilm, findLatestMp4, locateFilm, locateJobFilm, chooseDeliverableFilm, filmHitFields } from './film-bridge.mjs';
14
+ import { buildVoiceOptionsFromEnv } from './voice-bridge.mjs';
12
15
 
13
16
  export function env() {
14
17
  return {
@@ -23,6 +26,7 @@ export function env() {
23
26
  callbackUrl: process.env.PANEL_CALLBACK_URL || '',
24
27
  callbackToken: process.env.PANEL_CALLBACK_TOKEN || '',
25
28
  canExport: process.env.PANEL_CAN_EXPORT !== '0',
29
+ member: process.env.PANEL_MEMBER === '1',
26
30
  product: process.env.PANEL_PRODUCT || '',
27
31
  };
28
32
  }
@@ -98,13 +102,13 @@ export async function readBody(req, limit = 32 * 1024 * 1024) {
98
102
  }
99
103
 
100
104
  export async function readJsonBody(req) {
101
- // 20MB 原文件 base64 后约 27MB,留余量给文案和字段
105
+ // 本地上传:视频≤200MB base64 后约 267MB;合计≤250MB,JSON body 放宽到 300MB
102
106
  let buf;
103
107
  try {
104
- buf = await readBody(req, 30 * 1024 * 1024);
108
+ buf = await readBody(req, 300 * 1024 * 1024);
105
109
  } catch (error) {
106
110
  if (error.status === 413) {
107
- throw Object.assign(new Error('附件超过 20MB,请压缩或裁短后再上传'), { status: 413 });
111
+ throw Object.assign(new Error('附件过大:图文/PDF≤50MB,音频≤100MB,视频≤200MB,合计≤250MB'), { status: 413 });
108
112
  }
109
113
  throw error;
110
114
  }
@@ -249,6 +253,19 @@ export async function reportProgress(cfg, payload) {
249
253
  }
250
254
  }
251
255
 
256
+ /** 面板重载后会签发新 taskId,必须回填,避免后续进度再次创建镜像任务。 */
257
+ export async function reportJobProgress(cfg, jobs, jobId, payload) {
258
+ const result = await reportProgress(cfg, {
259
+ ...payload,
260
+ taskId: jobs.get(jobId)?.panelTaskId,
261
+ });
262
+ const taskId = String(result?.taskId || '').trim();
263
+ if (taskId && taskId !== jobs.get(jobId)?.panelTaskId) {
264
+ jobs.update(jobId, { panelTaskId: taskId });
265
+ }
266
+ return result;
267
+ }
268
+
252
269
  /** Ask panel host to open a DSH conversation with this Agent's skill + prompt. */
253
270
  export async function requestKickoff(cfg, payload) {
254
271
  if (!cfg.callbackUrl || !cfg.callbackToken) return null;
@@ -292,238 +309,84 @@ export async function requestRunPermit(cfg, { projectPath, jobId }) {
292
309
 
293
310
  /** Seed packaged skill into project so cwd-local DSH discovery finds it. */
294
311
  export function seedSkillIntoProject(projectDir, packageRoot, skillId) {
295
- const src = path.join(packageRoot, 'skills', skillId, 'SKILL.md');
296
- if (!projectDir || !fs.existsSync(src)) return null;
312
+ const src = path.join(packageRoot, 'skills', skillId);
313
+ if (!projectDir || !fs.existsSync(path.join(src, 'SKILL.md'))) return null;
297
314
  const destDir = ensureDir(path.join(projectDir, '.agents', 'skills', skillId));
298
- const dest = path.join(destDir, 'SKILL.md');
299
- fs.copyFileSync(src, dest);
300
- return dest;
315
+ // 整个 skill 目录一起播种:EXEC.md 与 scripts 才能被项目内 Agent 直接调用
316
+ fs.cpSync(src, destDir, { recursive: true, force: true });
317
+ return path.join(destDir, 'SKILL.md');
301
318
  }
302
319
 
303
320
  /** explainroo 的成片是 out/video.mp4。build/segments/seg-05.mp4 和 draft 渲完会删,不能当成片。 */
304
- export function isIntermediateMp4(filePath) {
305
- const base = path.basename(String(filePath || '')).toLowerCase();
306
- if (/^seg[-_]\d+\.mp4$/.test(base)) return true;
307
- if (/^draft([-.]|$)/.test(base)) return true;
308
- const parts = String(filePath || '').split(/[/\\]/).map((part) => part.toLowerCase());
309
- return parts.includes('build') || parts.includes('segments');
310
- }
311
-
312
- /** 记录里的文件被删掉或改名时,在同一目录找「原名开头」的现片。 */
313
- export function rescueMissingFilm(filePath) {
314
- const file = String(filePath || '');
315
- if (!file) return '';
316
- if (fs.existsSync(file) && !isIntermediateMp4(file)) return file;
317
- const dir = path.dirname(file);
318
- if (!fs.existsSync(dir)) return '';
319
- const stem = path.basename(file, path.extname(file)).toLowerCase();
320
- if (!stem) return '';
321
- let best = null;
322
- let names = [];
323
- try { names = fs.readdirSync(dir); } catch { return ''; }
324
- for (const name of names) {
325
- if (!name.toLowerCase().endsWith('.mp4')) continue;
326
- if (!name.toLowerCase().startsWith(stem)) continue;
327
- const full = path.join(dir, name);
328
- if (isIntermediateMp4(full)) continue;
329
- let st;
330
- try { st = fs.statSync(full); } catch { continue; }
331
- if (!st.isFile()) continue;
332
- if (!best || st.mtimeMs > best.mtimeMs) best = { path: full, mtimeMs: st.mtimeMs, size: st.size };
333
- }
334
- return best ? best.path : '';
335
- }
336
-
337
- function collectMp4(rootDir, maxDepth) {
338
- const found = [];
339
- if (!rootDir || !fs.existsSync(rootDir)) return found;
340
- const walk = (dir, depth) => {
341
- if (depth > maxDepth) return;
342
- let entries;
343
- try {
344
- entries = fs.readdirSync(dir, { withFileTypes: true });
345
- } catch {
346
- return;
347
- }
348
- for (const ent of entries) {
349
- if (ent.name === 'node_modules' || ent.name === '.git' || ent.name === '.venv') continue;
350
- const full = path.join(dir, ent.name);
351
- if (ent.isDirectory()) walk(full, depth + 1);
352
- else if (ent.isFile() && /\.mp4$/i.test(ent.name)) {
353
- try {
354
- const st = fs.statSync(full);
355
- found.push({ path: full, mtime: st.mtimeMs, size: st.size });
356
- } catch {
357
- /* skip */
358
- }
359
- }
360
- }
361
- };
362
- walk(rootDir, 0);
363
- return found;
364
- }
365
321
 
366
- function pickFilm(found) {
367
- if (!found.length) return null;
368
- found.sort((a, b) => {
369
- const ai = isIntermediateMp4(a.path) ? 1 : 0;
370
- const bi = isIntermediateMp4(b.path) ? 1 : 0;
371
- if (ai !== bi) return ai - bi;
372
- return b.mtime - a.mtime;
373
- });
374
- const best = found[0];
375
- if (!best || isIntermediateMp4(best.path)) return null;
376
- return best;
377
- }
378
-
379
- /** Newest deliverable MP4. Root-level `<name>.mp4` wins over `out/video.mp4`. */
380
- export function findLatestMp4(rootDir, { maxDepth = 6, sinceMs = 0 } = {}) {
381
- const since = Number(sinceMs) || 0;
382
- const found = collectMp4(rootDir, maxDepth).filter((hit) => !since || hit.mtime >= since);
383
- return pickFilm(found);
384
- }
322
+ export { isIntermediateMp4, rescueMissingFilm, findLatestMp4, locateFilm, locateJobFilm, chooseDeliverableFilm, filmHitFields };
385
323
 
386
- /** roots: directory string, or { dir, sinceMs, maxDepth }. */
387
- export function locateFilm(roots) {
388
- const found = [];
389
- for (const root of roots || []) {
390
- const dir = typeof root === 'string' ? root : root?.dir;
391
- const sinceMs = typeof root === 'string' ? 0 : Number(root?.sinceMs) || 0;
392
- const maxDepth = typeof root === 'string' ? 6 : root?.maxDepth || 6;
393
- found.push(...collectMp4(dir, maxDepth).filter((hit) => !sinceMs || hit.mtime >= sinceMs));
394
- }
395
- return pickFilm(found);
396
- }
397
-
398
- export function locateJobFilm(job, cfg) {
399
- if (!job) return null;
400
- const roots = Array.isArray(job.filmRoots) && job.filmRoots.length
401
- ? [...job.filmRoots]
402
- : [];
403
- const dir = job.projectPath || (job.artifact && !String(job.artifact).toLowerCase().endsWith('.mp4') ? job.artifact : '');
404
- if (dir && !roots.some((root) => (typeof root === 'string' ? root : root?.dir) === dir)) {
405
- roots.unshift({ dir, sinceMs: 0 });
406
- }
407
- const sinceMs = Date.parse(job.createdAt);
408
- if (cfg?.engineRoot && Number.isFinite(sinceMs)) {
409
- const engineFilms = path.join(cfg.engineRoot, 'films');
410
- if (!roots.some((root) => (typeof root === 'string' ? root : root?.dir) === engineFilms)) {
411
- roots.push({ dir: engineFilms, sinceMs });
412
- }
413
- }
414
- return locateFilm(roots);
415
- }
416
-
417
- /** Poll until an MP4 appears; updates job + panel progress. */
324
+ /** 监视成片:支持改名 / 二次生成;首次就绪后仍短时跟踪更新的文件。 */
418
325
  export function watchForFilm(cfg, jobs, jobId, {
419
326
  projectPath,
420
327
  title,
421
328
  intervalMs = 4000,
422
329
  timeoutMs = 2 * 60 * 60 * 1000,
330
+ followNewerMs = 20 * 60 * 1000,
423
331
  } = {}) {
424
332
  const started = Date.now();
333
+ let firstReadyAt = 0;
334
+ const adopt = async (hit) => {
335
+ if (!hit?.path) return false;
336
+ const job = jobs.get(jobId);
337
+ if (!job) return false;
338
+ if (job.outputMp4 === hit.path && job.status === 'done' && job.phase === 'film') return true;
339
+ const fields = filmHitFields(hit);
340
+ jobs.update(jobId, fields);
341
+ await reportJobProgress(cfg, jobs, jobId, {
342
+ title: title || jobs.get(jobId)?.title,
343
+ progress: 100,
344
+ message: fields.message,
345
+ done: true,
346
+ artifact: hit.path,
347
+ });
348
+ if (!firstReadyAt) firstReadyAt = Date.now();
349
+ return true;
350
+ };
425
351
  const tick = async () => {
426
352
  const job = jobs.get(jobId);
427
353
  if (!job || job.status === 'failed' || job.status === 'cancelled') return;
428
- const current = String(job.outputMp4 || '');
429
- if (current && fs.existsSync(current) && !isIntermediateMp4(current)) return;
430
- if (current && !fs.existsSync(current)) {
431
- const rescued = rescueMissingFilm(current);
432
- if (rescued) {
433
- const message = `成片已就绪 · ${path.basename(rescued)}`;
434
- const size = fs.statSync(rescued).size;
435
- jobs.update(jobId, {
436
- status: 'done',
437
- progress: 100,
438
- phase: 'film',
439
- message,
440
- outputMp4: rescued,
441
- artifact: rescued,
442
- filmBytes: size,
443
- filmAt: new Date().toISOString(),
444
- });
445
- await reportProgress(cfg, {
446
- taskId: jobs.get(jobId)?.panelTaskId,
447
- title: title || jobs.get(jobId)?.title,
448
- progress: 100,
449
- message,
450
- done: true,
451
- artifact: rescued,
452
- });
354
+ const probe = { ...job, projectPath: projectPath || job.projectPath, artifact: job.artifact };
355
+ const hit = chooseDeliverableFilm(probe, cfg);
356
+ if (hit) {
357
+ const changed = hit.path !== String(job.outputMp4 || '');
358
+ await adopt(hit);
359
+ const followUntil = (firstReadyAt || Date.now()) + followNewerMs;
360
+ if (Date.now() < followUntil || changed) {
361
+ setTimeout(() => void tick(), intervalMs);
453
362
  return;
454
363
  }
364
+ return;
455
365
  }
456
- const hit = locateJobFilm({ ...job, projectPath: projectPath || job.projectPath, artifact: job.artifact }, cfg);
457
- if (hit && !isIntermediateMp4(hit.path)) {
458
- const message = `成片已就绪 · ${path.basename(hit.path)}`;
366
+ if (Date.now() - started > timeoutMs) {
459
367
  jobs.update(jobId, {
460
368
  status: 'done',
461
369
  progress: 100,
462
- phase: 'film',
463
- message,
464
- outputMp4: hit.path,
465
- artifact: hit.path,
466
- filmBytes: hit.size,
467
- filmAt: new Date().toISOString(),
370
+ phase: 'stalled',
371
+ message: '等待成片超时 · 可打开工程目录或 DSH 会话查看',
468
372
  });
469
- await reportProgress(cfg, {
470
- taskId: jobs.get(jobId)?.panelTaskId,
471
- title: title || jobs.get(jobId)?.title,
373
+ await reportJobProgress(cfg, jobs, jobId, {
472
374
  progress: 100,
473
- message,
375
+ message: '等待成片超时',
474
376
  done: true,
475
- artifact: hit.path,
377
+ artifact: projectPath || job.projectPath,
476
378
  });
477
379
  return;
478
380
  }
479
- if (Date.now() - started > timeoutMs) {
480
- if (hit) {
481
- const message = `成片已就绪 · ${path.basename(hit.path)}`;
482
- jobs.update(jobId, {
483
- status: 'done',
484
- progress: 100,
485
- phase: 'film',
486
- message,
487
- outputMp4: hit.path,
488
- artifact: hit.path,
489
- filmBytes: hit.size,
490
- filmAt: new Date().toISOString(),
491
- });
492
- await reportProgress(cfg, {
493
- taskId: jobs.get(jobId)?.panelTaskId,
494
- title: title || jobs.get(jobId)?.title,
495
- progress: 100,
496
- message,
497
- done: true,
498
- artifact: hit.path,
499
- });
500
- } else {
501
- jobs.update(jobId, {
502
- status: 'done',
503
- progress: 100,
504
- phase: 'stalled',
505
- message: '等待成片超时 · 可打开工程目录或 DSH 会话查看',
506
- });
507
- await reportProgress(cfg, {
508
- taskId: jobs.get(jobId)?.panelTaskId,
509
- progress: 100,
510
- message: '等待成片超时',
511
- done: true,
512
- artifact: projectPath,
513
- });
514
- }
515
- return;
516
- }
517
- if (job.status === 'running' || job.phase === 'dsh') {
381
+ if (job.status === 'running' || job.phase === 'dsh' || job.phase === 'inpanel') {
518
382
  jobs.update(jobId, {
519
- phase: 'dsh',
383
+ phase: job.phase === 'inpanel' ? 'inpanel' : 'dsh',
520
384
  message: job.kickoffOk === false
521
385
  ? (job.message || '等待手动开拍 / 成片')
522
- : 'DSH 创作中 · 完成后将自动显示成片路径',
386
+ : (job.message && String(job.message).includes('面板') ? job.message : '创作中 · 完成后将自动显示成片'),
523
387
  progress: Math.min(90, Math.max(Number(job.progress) || 50, 50)),
524
388
  });
525
- await reportProgress(cfg, {
526
- taskId: jobs.get(jobId)?.panelTaskId,
389
+ await reportJobProgress(cfg, jobs, jobId, {
527
390
  progress: jobs.get(jobId)?.progress ?? 55,
528
391
  message: jobs.get(jobId)?.message,
529
392
  });
@@ -574,54 +437,33 @@ export function createAgentServer({ root, studioDir, api }) {
574
437
  const jobs = new JobStore(cfg.workspace);
575
438
  const studio = studioDir || path.join(root, 'studio');
576
439
 
577
- // 进程重启后:已有成片则收口;否则恢复 watch,避免面板/Studio 任务永远「处理中」
440
+ // 进程重启后:重扫成片(改名/二次生成/路径失效),否则恢复 watch
578
441
  for (const j of jobs.list()) {
579
- const filmMissing = j.outputMp4 && !fs.existsSync(j.outputMp4);
580
- const filmBad = j.outputMp4 && isIntermediateMp4(j.outputMp4);
581
- if (filmMissing || filmBad || (j.status === 'done' && !j.outputMp4)) {
582
- const rescued = filmMissing ? rescueMissingFilm(j.outputMp4) : '';
583
- const late = rescued
584
- ? { path: rescued, size: fs.statSync(rescued).size }
585
- : locateJobFilm(j, cfg);
586
- if (late && late.path && fs.existsSync(late.path) && !isIntermediateMp4(late.path)) {
587
- jobs.update(j.id, {
588
- status: 'done',
442
+ const hit = chooseDeliverableFilm(j, cfg);
443
+ const missing = j.outputMp4 && !fs.existsSync(j.outputMp4);
444
+ const bad = j.outputMp4 && isIntermediateMp4(j.outputMp4);
445
+ const shouldAdopt = hit && (
446
+ missing || bad || !j.outputMp4 || j.outputMp4 !== hit.path
447
+ || j.status === 'running'
448
+ );
449
+ if (shouldAdopt && hit) {
450
+ const fields = filmHitFields(hit);
451
+ jobs.update(j.id, fields);
452
+ if (j.status === 'running') {
453
+ void reportJobProgress(cfg, jobs, j.id, {
454
+ title: j.title,
589
455
  progress: 100,
590
- phase: 'film',
591
- message: `成片已就绪 · ${path.basename(late.path)}`,
592
- outputMp4: late.path,
593
- artifact: late.path,
594
- filmBytes: late.size,
595
- filmAt: new Date().toISOString(),
456
+ message: fields.message,
457
+ done: true,
458
+ artifact: hit.path,
596
459
  });
597
- continue;
598
460
  }
599
- if (j.status === 'done') continue;
461
+ continue;
600
462
  }
601
463
  const waiting = j.status === 'running' || (j.outputMp4 && isIntermediateMp4(j.outputMp4));
602
464
  if (!waiting) continue;
603
465
  const projectPath = j.projectPath || (j.artifact && !String(j.artifact).endsWith('.mp4') ? j.artifact : null);
604
- const hit = locateJobFilm(j, cfg);
605
- if (hit && !isIntermediateMp4(hit.path)) {
606
- jobs.update(j.id, {
607
- status: 'done',
608
- progress: 100,
609
- phase: 'film',
610
- message: `成片已就绪 · ${path.basename(hit.path)}`,
611
- outputMp4: hit.path,
612
- artifact: hit.path,
613
- filmBytes: hit.size,
614
- filmAt: new Date().toISOString(),
615
- });
616
- void reportProgress(cfg, {
617
- taskId: j.panelTaskId,
618
- title: j.title,
619
- progress: 100,
620
- message: `成片已就绪 · ${path.basename(hit.path)}`,
621
- done: true,
622
- artifact: hit.path,
623
- });
624
- } else if (projectPath && fs.existsSync(projectPath)) {
466
+ if (projectPath && fs.existsSync(projectPath)) {
625
467
  jobs.update(j.id, {
626
468
  phase: 'dsh',
627
469
  message: '进程已恢复 · 继续等待成片',
@@ -635,8 +477,7 @@ export function createAgentServer({ root, studioDir, api }) {
635
477
  message: '进程中断 · 无法恢复监视(工程目录缺失)',
636
478
  progress: Number(j.progress) || 0,
637
479
  });
638
- void reportProgress(cfg, {
639
- taskId: j.panelTaskId,
480
+ void reportJobProgress(cfg, jobs, j.id, {
640
481
  progress: Number(j.progress) || 0,
641
482
  message: '进程中断 · 任务已标记失败',
642
483
  failed: true,
@@ -665,39 +506,44 @@ export function createAgentServer({ root, studioDir, api }) {
665
506
  version: cfg.version,
666
507
  product: cfg.product,
667
508
  canExport: cfg.canExport,
509
+ member: cfg.member === true,
668
510
  engineRoot: cfg.engineRoot || null,
669
511
  enginePresent: !!(cfg.engineRoot && fs.existsSync(cfg.engineRoot)),
670
512
  workspace: cfg.workspace,
671
513
  });
672
514
  }
673
515
 
516
+ if (pathname === '/api/voice-options' && req.method === 'GET') {
517
+ return sendJson(res, 200, buildVoiceOptionsFromEnv(process.env));
518
+ }
519
+
520
+
674
521
  if (pathname === '/api/jobs' && req.method === 'GET') {
675
- return sendJson(res, 200, { jobs: jobs.list().map(fillFromBrief) });
522
+ const list = jobs.list().map((j) => {
523
+ const hit = chooseDeliverableFilm(j, cfg);
524
+ if (hit && (!j.outputMp4 || !fs.existsSync(j.outputMp4) || isIntermediateMp4(j.outputMp4) || hit.path !== j.outputMp4)) {
525
+ jobs.update(j.id, filmHitFields(hit));
526
+ return fillFromBrief(jobs.get(j.id) || j);
527
+ }
528
+ return fillFromBrief(j);
529
+ });
530
+ return sendJson(res, 200, { jobs: list });
676
531
  }
677
532
  if (req.method === 'GET' && /^\/api\/jobs\/[^/]+\/film$/.test(pathname)) {
678
533
  const id = decodeURIComponent(pathname.slice('/api/jobs/'.length, -'/film'.length));
679
534
  const job = jobs.get(id);
680
- let file = job ? String(job.outputMp4 || '') : '';
681
- if (job && (!file || !fs.existsSync(file) || isIntermediateMp4(file))) {
682
- const rescued = file && !fs.existsSync(file) ? rescueMissingFilm(file) : '';
683
- const late = rescued
684
- ? { path: rescued, size: fs.statSync(rescued).size }
685
- : locateJobFilm(job, cfg);
686
- if (late && late.path && fs.existsSync(late.path) && !isIntermediateMp4(late.path)) {
687
- jobs.update(job.id, {
688
- status: 'done',
689
- progress: 100,
690
- phase: 'film',
691
- message: `成片已就绪 · ${path.basename(late.path)}`,
692
- outputMp4: late.path,
693
- artifact: late.path,
694
- filmBytes: late.size,
695
- filmAt: new Date().toISOString(),
696
- });
697
- file = late.path;
535
+ if (!job) return sendJson(res, 404, { error: 'job not found' });
536
+ let file = String(job.outputMp4 || '');
537
+ if (!file || !fs.existsSync(file) || isIntermediateMp4(file)) {
538
+ const hit = chooseDeliverableFilm(job, cfg);
539
+ if (hit) {
540
+ jobs.update(id, filmHitFields(hit));
541
+ file = hit.path;
698
542
  }
699
543
  }
700
- if (!file || !file.toLowerCase().endsWith('.mp4') || !fs.existsSync(file)) return sendJson(res, 404, { error: '成片还没有' });
544
+ if (!file || !file.toLowerCase().endsWith('.mp4') || !fs.existsSync(file)) {
545
+ return sendJson(res, 404, { error: '成片还没有' });
546
+ }
701
547
  return serveLocalFile(req, res, file);
702
548
  }
703
549
  if (pathname.startsWith('/api/jobs/') && req.method === 'GET') {
@@ -713,6 +559,45 @@ export function createAgentServer({ root, studioDir, api }) {
713
559
  return sendJson(res, 200, { ok: true, id });
714
560
  }
715
561
 
562
+
563
+ if (pathname === '/api/panel/run' && req.method === 'POST') {
564
+ try {
565
+ const { startPanelRun } = await import('../_shared/lib/panel-run-route.mjs');
566
+ const body = await readJsonBody(req);
567
+ const result = await startPanelRun({
568
+ cfg,
569
+ jobs,
570
+ packageRoot: root,
571
+ skillId: cfg.agentId,
572
+ body,
573
+ reportProgress,
574
+ reportJobProgress,
575
+ requestRunPermit,
576
+ seedSkillIntoProject,
577
+ ensureDir,
578
+ writeJson,
579
+ });
580
+ sendJson(res, 202, result);
581
+ } catch (error) {
582
+ sendJson(res, error.status || 400, { error: error.message || String(error), code: error.code });
583
+ }
584
+ return;
585
+ }
586
+ if (pathname === '/api/optimize-prompt' && req.method === 'POST') {
587
+ if (cfg.member !== true) {
588
+ sendJson(res, 403, { error: '会员专属,请先开通会员' });
589
+ return;
590
+ }
591
+ try {
592
+ const body = await readJsonBody(req);
593
+ sendJson(res, 200, optimizePrompt(body));
594
+ } catch (error) {
595
+ const message = error instanceof SyntaxError ? '请求无法读取' : (error.message || '无法优化提示词');
596
+ sendJson(res, error.status || 400, { error: message });
597
+ }
598
+ return;
599
+ }
600
+
716
601
  if (api) {
717
602
  const handled = await api({ req, res, url, pathname, cfg, jobs, root, sendJson, readJsonBody, readBody });
718
603
  if (handled) return;
@@ -0,0 +1,2 @@
1
+ export { buildVoiceOptionsFromEnv, FREE_VOICES, VOICE_RATES, normalizeVoicePick, voiceKickoffLine } from '../_shared/lib/voice-catalog.mjs';
2
+
package/manifest.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "schemaVersion": 1,
3
3
  "id": "biutalk",
4
4
  "name": "BiuTalk",
5
- "version": "1.1.6",
5
+ "version": "1.1.8",
6
6
  "publisher": "Biunow",
7
7
  "description": "BiuTalk 解说视频 Studio:模板、尺寸、附件与本地渲染引擎。",
8
8
  "entry": {
@@ -18,6 +18,7 @@
18
18
  "shared": [
19
19
  "ffmpeg@7",
20
20
  "chromium@131",
21
+ "bn-npm@1",
21
22
  "biutalk-npm@1"
22
23
  ]
23
24
  },
@@ -47,8 +48,8 @@
47
48
  "requiresEntitlement": "export"
48
49
  },
49
50
  "integrity": {
50
- "sha256": "f79dd26331f094a7dccf7ee2488816974f27023015ccace09c6197e308e46665",
51
- "signature": "jNNb+a6UDunDfTtCmySzU1/pYpikYTWzCXnIFRVE4t4C6wUdsHk7Ey+CRYh6aOXBmteOzve5TZG8KiXWbUV5AQ==",
51
+ "sha256": "e059abe2a9bd9c9cba735468854160d3f8129ae84c57903aa1d23a92e4610e7d",
52
+ "signature": "aEV/nHAgM3C+RzlYJmH29PIrsDMXdhRs/YDfooym6iQbjS8NzYz8dbszEk5sqABCp3vr8kpJtC9Cr00IfQoNAA==",
52
53
  "signedBy": "publisher-key"
53
54
  }
54
55
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@biunow/agent-biutalk",
3
- "version": "1.1.6",
3
+ "version": "1.1.8",
4
4
  "description": "BiuTalk",
5
5
  "license": "UNLICENSED",
6
6
  "publishConfig": {
@@ -0,0 +1,69 @@
1
+ # BiuTalk 执行卡(先读这张)
2
+
3
+ 变量:`SKILL` = 本文件所在目录;`ENGINE` = `brief.json.engineRoot` 或面板 settings.engineRoots.biutalk;成片工程 = 含 `video.json` 的目录(通常是 `videos/<projectSlug>`)。
4
+
5
+ ## 0. 开工前
6
+ - 没有 `run-permit.json` 不许开工;直聊无 permit → `POST /agents/gate/begin` 后停止。
7
+ - `brief.json` 是合同:不追问 intake,不改 title / look / size / pace。
8
+ - 只读:`brief.json`、`PROMPT.md`、`PROJECT_CARD.md`。
9
+ - **禁止整份打开** `ENGINE/AGENTS.md`(71KB)。需要 API 细节时按关键词检索 20–40 行:
10
+ `rg -n "### Text|### Shapes|s\.box|s\.arrow" "$ENGINE/AGENTS.md"`(Windows 用 `Select-String -Context 2,12`)。
11
+ - 一次只写一个文件:先 `script.md`,再 `scenes.js`。
12
+
13
+ ## 1. 预检(必须 ok:true)
14
+ ```bash
15
+ node "$SKILL/scripts/doctor.mjs" --project . --engine "$ENGINE" --json
16
+ ```
17
+ `ok:false` 按 `hint` 修。模型未下载只在首次 `voice` 时联网拉取,不算失败。
18
+
19
+ ## 2. 工程骨架(幂等,只跑一次)
20
+ ```bash
21
+ node "$SKILL/scripts/scaffold.mjs" --project . --engine "$ENGINE" --json
22
+ ```
23
+ 输出 `projectPath`、`mainFile: scenes.js`、`scriptFile: script.md`。已有 `video.json` 不覆盖;重置才加 `--force`。
24
+
25
+ ## 3. 口播稿 script.md(先写,决定全片时长)
26
+ - 每镜 `## scene-id`,id 必须与 `scenes.js` 函数同名;从 `hook / steps / outro` 起步。
27
+ - 每镜 1–3 句、4–15 秒;全片 45–120 秒。中文约 200 字/分钟,英文 150 词/分钟。
28
+ - 短句、口语、只讲事实;不编数字,不用破折号、口号、三段排比。
29
+ - 每个句子至少一个 `[#marker]`,让画面按时切换。
30
+ - 易读错处写成 `{CLI|C L I}`、`{v2.1|version two point one}`、`{example.com|example dot com}`。
31
+ - 场景参数:`## intro {hold=1.5 min=3 transition=wipe}`;`>` 开头的行不朗读。
32
+
33
+ ## 4. 画面 scenes.js(只改这个文件)
34
+ - 一个函数一镜,所有元素给 `at`(秒 / 单词 / `#marker`),需要时给 `out`。
35
+ - 复用模板已有写法;禁止新建渲染器,禁止改引擎 `core/` 或 `video.json` 之外的配置。
36
+ - 布局在 `s.safe` 内:标题 80–110px,标签 40–56px,小字 ≥32px;同屏 ≤6 个元素;每 2–4 秒出现新变化。
37
+ - 常用 API:`s.title / s.subtitle / s.text({size,font,at,out})`、`s.box / s.icon / s.arrow(idA,idB)`、`s.number`、`s.row / s.col / s.grid`。
38
+ - 关键帧优先 `at: 'word'` 或 `at: '#marker'`,不要写死秒数。
39
+
40
+ ## 5. 配音 → 机检(不看图)
41
+ ```bash
42
+ node "$ENGINE/bin/explainroo.js" voice .
43
+ node "$ENGINE/bin/explainroo.js" check . --json
44
+ node "$SKILL/scripts/qc.mjs" --project . --engine "$ENGINE" --json
45
+ ```
46
+ `check` 的 error / warn 必须清零;`qc.ok:false` 只读 `findings[].hint` 修,不要描述图片。
47
+
48
+ 需要人看画面时只生成静帧和接触表,交给用户看:
49
+ ```bash
50
+ node "$ENGINE/bin/explainroo.js" still .
51
+ node "$ENGINE/bin/explainroo.js" sheet .
52
+ ```
53
+
54
+ ## 6. 草稿 → 终版 → 验收
55
+ ```bash
56
+ node "$ENGINE/bin/explainroo.js" render . --draft --workers 6
57
+ node "$SKILL/scripts/qc.mjs" --project . --engine "$ENGINE" --video ./out/draft.mp4 --json
58
+ node "$ENGINE/bin/explainroo.js" render . --workers 6
59
+ node "$ENGINE/bin/explainroo.js" verify . --json
60
+ ```
61
+ `qc.ok:true` 且 `verify` 无 error 才算完成;无音轨、响度偏差、黑帧按 hint 修。
62
+
63
+ ## 7. 交付
64
+ - 成片:`out/video.mp4`(多尺寸为 `out/video-<size>.mp4`),同目录带 `.srt` 和 `.cover.jpg`。
65
+ - 回复只给:路径、时长、分辨率、`qc.ok`、verify 的响度与口播清晰度。不贴渲染日志。
66
+
67
+ ## 硬禁令
68
+ - 不生图、不下载素材、不换主题;不整份读 AGENTS.md;不先渲整片;不加 watermark。
69
+ - 输出最多 20 行。