@gobing-ai/knowledge-kit 0.1.22 → 0.1.24

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 (117) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/dist/index.js +282 -147
  3. package/package.json +5 -5
  4. package/plugins/generations/content-gen/dist/index.js +9 -9
  5. package/plugins/generations/core-facts-gen/dist/index.js +12 -12
  6. package/plugins/generations/daily-article-gen/dist/index.js +12 -12
  7. package/plugins/generations/dailynews-gen/dist/index.js +11 -11
  8. package/plugins/generations/dailynews-gen/src/script-plan.ts +2 -2
  9. package/plugins/generations/episode-plan-gen/dist/index.js +12 -12
  10. package/plugins/generations/gemini-tts/dist/index.js +56 -16
  11. package/plugins/generations/gemini-tts/src/gemini-client.ts +34 -6
  12. package/plugins/generations/image-gen/dist/index.js +9 -9
  13. package/plugins/generations/music-gen/README.md +2 -2
  14. package/plugins/generations/music-gen/dist/index.js +62 -26
  15. package/plugins/generations/music-gen/presets/formats/song.yaml +6 -1
  16. package/plugins/generations/music-gen/presets/themes/synthwave.yaml +6 -1
  17. package/plugins/generations/music-gen/src/adapter/instance.ts +34 -11
  18. package/plugins/generations/music-gen/src/presets.ts +36 -3
  19. package/plugins/generations/news-report-gen/dist/index.js +12 -12
  20. package/plugins/generations/omni-voice-gen/uv.toml +5 -0
  21. package/plugins/generations/vibe-voice-tts/README.md +64 -0
  22. package/plugins/generations/vibe-voice-tts/dist/index.js +14259 -0
  23. package/plugins/generations/vibe-voice-tts/package.json +16 -0
  24. package/plugins/generations/vibe-voice-tts/plugin.json +6 -0
  25. package/plugins/generations/vibe-voice-tts/profiles.json +10 -0
  26. package/plugins/generations/vibe-voice-tts/pyproject.toml +9 -0
  27. package/plugins/generations/vibe-voice-tts/python/worker.py +566 -0
  28. package/plugins/generations/vibe-voice-tts/src/index.ts +88 -0
  29. package/plugins/generations/vibe-voice-tts/src/vibevoice-client.ts +828 -0
  30. package/plugins/generations/vibe-voice-tts/tsconfig.json +8 -0
  31. package/plugins/generations/vibe-voice-tts/uv.lock +1767 -0
  32. package/plugins/generations/vibe-voice-tts/uv.toml +4 -0
  33. package/plugins/generations/voice-gen/dist/index.js +40 -10
  34. package/plugins/generations/voice-gen/src/voicebox-client.ts +50 -1
  35. package/plugins/generations/voxcpm-tts/dist/index.js +90 -18
  36. package/plugins/generations/voxcpm-tts/python/worker.py +9 -0
  37. package/plugins/generations/voxcpm-tts/src/index.ts +41 -0
  38. package/plugins/generations/voxcpm-tts/src/voxcpm-client.ts +32 -11
  39. package/plugins/generations/voxcpm-tts/uv.toml +5 -0
  40. package/plugins/ingestions/aihot-ingest/dist/index.js +12 -12
  41. package/plugins/ingestions/horizon-ingest/dist/index.js +12 -12
  42. package/plugins/ingestions/karakeep-local/dist/index.js +13 -13
  43. package/plugins/ingestions/last30days-ingest/dist/index.js +12 -12
  44. package/plugins/ingestions/web-search/dist/index.js +10 -10
  45. package/plugins/kk/README.md +21 -0
  46. package/plugins/kk/decisions/kk-safety.yaml +5 -2
  47. package/plugins/kk/plugin.json +1 -1
  48. package/plugins/kk/publish-presets/daily-ai-voice.json +16 -16
  49. package/plugins/kk/schedules/kk-serve.launchd.plist.tmpl +12 -1
  50. package/plugins/kk/scripts/cover-compositor.ts +104 -26
  51. package/plugins/kk/scripts/daily-stages.ts +481 -63
  52. package/plugins/kk/scripts/kk-workflow-stages.ts +218 -17
  53. package/plugins/kk/scripts/safety-artifact-check.ts +28 -5
  54. package/plugins/kk/scripts/series-names.ts +16 -3
  55. package/plugins/kk/skills/news-editorial/SKILL.md +1 -1
  56. package/plugins/kk/skills/news-editorial/references/style-contract.zh.md +3 -3
  57. package/plugins/kk/workflows/kk-daily-ai-voice.yaml +4 -3
  58. package/plugins/kk/workflows/kk-daily-ai-voice2.yaml +6 -5
  59. package/plugins/kk/workflows/kk-daily-safety.yaml +12 -10
  60. package/plugins/kk/workflows/kk-music.yaml +20 -16
  61. package/plugins/kk/workflows/kk-news-generate.yaml +26 -3
  62. package/plugins/kk/workflows/kk-publish.yaml +4 -1
  63. package/plugins/publishings/bilibili-pub/dist/index.js +22 -22
  64. package/plugins/publishings/bilibili-pub/dist/profile-check.js +22 -22
  65. package/plugins/publishings/cnblogs-pub/dist/index.js +22 -22
  66. package/plugins/publishings/cnblogs-pub/dist/profile-check.js +22 -22
  67. package/plugins/publishings/csdn-pub/dist/index.js +22 -22
  68. package/plugins/publishings/csdn-pub/dist/profile-check.js +22 -22
  69. package/plugins/publishings/emdash-pub/dist/index.js +9 -9
  70. package/plugins/publishings/infoq-pub/dist/index.js +22 -22
  71. package/plugins/publishings/infoq-pub/dist/profile-check.js +22 -22
  72. package/plugins/publishings/jike-pub/dist/index.js +22 -22
  73. package/plugins/publishings/jike-pub/dist/profile-check.js +22 -22
  74. package/plugins/publishings/juejin-pub/dist/index.js +22 -22
  75. package/plugins/publishings/juejin-pub/dist/profile-check.js +22 -22
  76. package/plugins/publishings/linkedin-pub/dist/index.js +133 -33
  77. package/plugins/publishings/linkedin-pub/dist/profile-check.js +27 -22
  78. package/plugins/publishings/linkedin-pub/src/index.ts +192 -18
  79. package/plugins/publishings/medium-pub/dist/index.js +9 -9
  80. package/plugins/publishings/podcast-pub/dist/index.js +240 -37
  81. package/plugins/publishings/podcast-pub/src/index.ts +154 -3
  82. package/plugins/publishings/podcast-pub/src/seo.ts +25 -8
  83. package/plugins/publishings/podcast-pub/src/show-notes-brief.ts +93 -23
  84. package/plugins/publishings/podcast-pub/src/show-notes.ts +26 -6
  85. package/plugins/publishings/qiita-pub/dist/index.js +9 -9
  86. package/plugins/publishings/shipinhao-pub/dist/index.js +23 -23
  87. package/plugins/publishings/shipinhao-pub/dist/profile-check.js +23 -23
  88. package/plugins/publishings/shipinhao-pub/src/selectors.ts +2 -1
  89. package/plugins/publishings/sspai-pub/dist/index.js +22 -22
  90. package/plugins/publishings/sspai-pub/dist/profile-check.js +22 -22
  91. package/plugins/publishings/substack-pub/dist/index.js +22 -22
  92. package/plugins/publishings/substack-pub/dist/profile-check.js +22 -22
  93. package/plugins/publishings/surfdash-pub/dist/index.js +207 -95
  94. package/plugins/publishings/surfdash-pub/src/digest-check.ts +30 -1
  95. package/plugins/publishings/surfdash-pub/src/index.ts +101 -76
  96. package/plugins/publishings/surfdash-pub/src/media-upload.ts +83 -0
  97. package/plugins/publishings/surfdash-pub/src/patch.ts +49 -26
  98. package/plugins/publishings/surfdash-pub/src/topic-claims.ts +12 -4
  99. package/plugins/publishings/threads-pub/dist/index.js +83 -27
  100. package/plugins/publishings/threads-pub/dist/profile-check.js +34 -23
  101. package/plugins/publishings/threads-pub/src/post-rail.ts +121 -4
  102. package/plugins/publishings/wechatmp-pub/dist/index.js +274 -98
  103. package/plugins/publishings/wechatmp-pub/dist/profile-check.js +27 -23
  104. package/plugins/publishings/wechatmp-pub/src/cgi-draft.ts +87 -53
  105. package/plugins/publishings/wechatmp-pub/src/enrich.ts +117 -13
  106. package/plugins/publishings/wechatmp-pub/src/flow.ts +183 -43
  107. package/plugins/publishings/wechatmp-pub/src/modes.ts +30 -12
  108. package/plugins/publishings/weibo-pub/dist/index.js +22 -22
  109. package/plugins/publishings/weibo-pub/dist/profile-check.js +22 -22
  110. package/plugins/publishings/x-pub/dist/index.js +113 -32
  111. package/plugins/publishings/x-pub/dist/profile-check.js +22 -22
  112. package/plugins/publishings/x-pub/src/post-rail.ts +155 -20
  113. package/plugins/publishings/xhs-pub/dist/index.js +22 -22
  114. package/plugins/publishings/xhs-pub/dist/profile-check.js +22 -22
  115. package/plugins/publishings/xiaoyuzhou-pub/dist/index.js +22 -22
  116. package/plugins/publishings/xiaoyuzhou-pub/dist/profile-check.js +22 -22
  117. package/plugins/publishings/zenn-pub/dist/index.js +9 -9
@@ -24,7 +24,7 @@ import {
24
24
  WechatCgiDraftError,
25
25
  } from './cgi-draft';
26
26
  import { prepareArticleMedia, type WechatArticleMedia } from './cgi-media';
27
- import { enrichArticle } from './enrich';
27
+ import { enrichArticleDetailed } from './enrich';
28
28
  import {
29
29
  artifactPaths,
30
30
  CREATE_TYPES,
@@ -1270,12 +1270,7 @@ export async function setCover(
1270
1270
  * seeded. The flow *does* attach that file as the first body image, so 从正文选择 resolves it with no
1271
1271
  * library dependency — which is the route a cover-carrying article should take (2026-11-12).
1272
1272
  */
1273
- function coverSourceOf(content: Content): 'library' | 'body' {
1274
- const meta = content.metadata?.wechatmp;
1275
- if (meta !== null && typeof meta === 'object' && !Array.isArray(meta)) {
1276
- const declared = (meta as Record<string, unknown>).coverSource;
1277
- if (declared === 'body' || declared === 'library') return declared;
1278
- }
1273
+ function genericCoverPathOf(content: Content): string | undefined {
1279
1274
  const generic = content.metadata?.coverImage;
1280
1275
  const genericPath =
1281
1276
  typeof generic === 'string'
@@ -1283,7 +1278,25 @@ function coverSourceOf(content: Content): 'library' | 'body' {
1283
1278
  : typeof (generic as { path?: unknown } | undefined)?.path === 'string'
1284
1279
  ? (generic as { path: string }).path
1285
1280
  : undefined;
1286
- return genericPath !== undefined && genericPath.length > 0 ? 'body' : 'library';
1281
+ return genericPath !== undefined && genericPath.length > 0 ? genericPath : undefined;
1282
+ }
1283
+
1284
+ function libraryCoverFallback(content: Content): string | undefined {
1285
+ const meta = content.metadata?.wechatmp;
1286
+ if (meta !== null && typeof meta === 'object' && !Array.isArray(meta)) {
1287
+ const coverPath = (meta as Record<string, unknown>).coverPath;
1288
+ if (typeof coverPath === 'string' && coverPath.trim().length > 0) return coverPath.trim();
1289
+ }
1290
+ return genericCoverPathOf(content);
1291
+ }
1292
+
1293
+ function coverSourceOf(content: Content): 'library' | 'body' {
1294
+ const meta = content.metadata?.wechatmp;
1295
+ if (meta !== null && typeof meta === 'object' && !Array.isArray(meta)) {
1296
+ const declared = (meta as Record<string, unknown>).coverSource;
1297
+ if (declared === 'body' || declared === 'library') return declared;
1298
+ }
1299
+ return genericCoverPathOf(content) !== undefined ? 'body' : 'library';
1287
1300
  }
1288
1301
 
1289
1302
  /** The audio-embed block of `metadata.wechatmp`, or null when this run embeds no audio. Shared by
@@ -1311,12 +1324,14 @@ export async function enrichArticleDraft(
1311
1324
  page: WechatPage,
1312
1325
  content: Content,
1313
1326
  stepTimeoutMs: number,
1314
- ): Promise<{ enrichWarnings: string[]; coverWarnings: string[] }> {
1327
+ ): Promise<{ enrichWarnings: string[]; capabilityWarnings: string[]; coverWarnings: string[] }> {
1315
1328
  const enrichMeta = content.metadata?.wechatmp;
1316
1329
  if (enrichMeta === undefined || typeof enrichMeta !== 'object' || Array.isArray(enrichMeta))
1317
- return { enrichWarnings: [], coverWarnings: [] };
1330
+ return { enrichWarnings: [], capabilityWarnings: [], coverWarnings: [] };
1318
1331
  const meta = enrichMeta as Record<string, unknown>;
1319
- const enrichWarnings = await enrichArticle(page, meta);
1332
+ const detailed = await enrichArticleDetailed(page, meta);
1333
+ const enrichWarnings = [...detailed.warnings];
1334
+ const capabilityWarnings = [...detailed.capabilityWarnings];
1320
1335
  const audio = audioBlockOf(content);
1321
1336
  let audioFailed = false;
1322
1337
  let coverSeeded = false;
@@ -1347,7 +1362,7 @@ export async function enrichArticleDraft(
1347
1362
  if (cover !== null) coverWarnings.push(cover);
1348
1363
  }
1349
1364
  }
1350
- return { enrichWarnings, coverWarnings };
1365
+ return { enrichWarnings, capabilityWarnings, coverWarnings };
1351
1366
  }
1352
1367
 
1353
1368
  /** Compose 文章 (createType 0): body images, title, body + 一键排版, 摘要, 作者, cover, settings. */
@@ -1363,8 +1378,9 @@ async function composeArticle(
1363
1378
  // Images go in AFTER the body: the v2 editor's own `execCommand('insertHTML')` body path
1364
1379
  // REPLACES the document, so an image attached first is silently wiped — and with it the
1365
1380
  // 默认首图为封面 / 从正文选择 material (measured 2026-11-12: bodyImgs 2 → 0, then 2 again when
1366
- // re-attached after the body). A cover-carrying article lost its cover exactly this way.
1367
- await attachImages(page, input.images, deps);
1381
+ // re-attached after the body). Only attach body images when non-empty (`coverSource: 'library'`
1382
+ // with no body illustrations keeps input.images empty so the cover never lands in the body).
1383
+ if (input.images.length > 0) await attachImages(page, input.images, deps);
1368
1384
  for (const warning of [
1369
1385
  await fillOptional(page, DIGEST_INPUT, input.digest ?? '', '摘要', deps),
1370
1386
  await fillOptional(page, AUTHOR_INPUT, authorOf(deps.content), '作者', deps),
@@ -1379,21 +1395,25 @@ async function composeArticle(
1379
1395
  const audioRuns = audioBlockOf(deps.content) !== null;
1380
1396
  if (!(coverSource === 'library' && audioRuns)) {
1381
1397
  const cover = await setCover(page, coverSource, deps, {
1382
- // Requested identity = the article's first body image (the 默认首图为封面 semantics of
1383
- // modes.coverPath). No audio ran, so the library binding is unknown — only an exposed
1384
- // exact filename can match.
1385
- requested: input.images[0],
1398
+ // Requested identity = the article's first body image (从正文选择), or
1399
+ // `metadata.wechatmp.coverPath` / `metadata.coverImage` when `coverSource: 'library'`
1400
+ // omits body attachment and no audio uploaded it cleanly first.
1401
+ requested: input.images[0] ?? libraryCoverFallback(deps.content),
1386
1402
  });
1387
1403
  if (cover !== null) warnings.push(cover);
1388
1404
  }
1389
- const { enrichWarnings, coverWarnings } = await enrichArticleDraft(page, deps.content, deps.stepTimeoutMs);
1405
+ const { enrichWarnings, capabilityWarnings, coverWarnings } = await enrichArticleDraft(
1406
+ page,
1407
+ deps.content,
1408
+ deps.stepTimeoutMs,
1409
+ );
1390
1410
  warnings.push(...coverWarnings);
1391
1411
  // Layout is deliberately last: 原文链接, media insertion, and cover commitment must be part of
1392
1412
  // the body the platform formats, and the native auto-save acknowledgement must settle before
1393
1413
  // 保存为草稿 or the public saved-editor readback begins.
1394
1414
  const layout = await applyLayout(page, deps);
1395
1415
  if (layout !== null) warnings.push(layout);
1396
- return { warnings, titlePath, enrichWarnings };
1416
+ return { warnings, titlePath, enrichWarnings, capabilityWarnings };
1397
1417
  }
1398
1418
 
1399
1419
  /** Compose 贴图 (createType 8): ≥1 image is the message; title and body are 选填. */
@@ -1694,6 +1714,7 @@ interface ComposeReport {
1694
1714
  warnings: string[];
1695
1715
  titlePath: 'absent' | 'mirror-agreed' | 'mirror-unread';
1696
1716
  enrichWarnings: string[];
1717
+ capabilityWarnings?: string[];
1697
1718
  }
1698
1719
 
1699
1720
  /** Compose the requested mode's post. Exhaustive over {@link ModeInput}. */
@@ -2585,6 +2606,11 @@ async function runCgiDraft(input: ModeInput, deps: ModeRunDeps): Promise<Result
2585
2606
  publishStatus: deps.publishStatus,
2586
2607
  stage: error.stage,
2587
2608
  ...(error.metadata.ambiguousSubmission === true ? { ambiguousSubmission: true } : {}),
2609
+ // 0406 R4: the duplicate refusal dispatched nothing, so the row is honestly
2610
+ // `effect: none` — a bounded retry (not an operator resend) is the right next step.
2611
+ ...(error.code === 'duplicate-draft'
2612
+ ? { itcDelivery: { schemaVersion: 1, effect: 'none' as const } }
2613
+ : {}),
2588
2614
  },
2589
2615
  });
2590
2616
  }
@@ -2622,17 +2648,22 @@ export async function runMode(input: ModeInput, deps: ModeRunDeps): Promise<Resu
2622
2648
  if (!result.ok && diagnostics.length > 0) {
2623
2649
  return { ...result, error: `${result.error} — compose diagnostics: ${diagnostics.join(' | ')}` };
2624
2650
  }
2625
- // Requested enrichment that did not take is a FAILURE, not a warning (2026-11-15). The daily
2626
- // draft was saved 原创/赞赏/原文链接-free and the row still reported ok:true, so the receipt
2627
- // said 'succeeded' while the article was incomplete and only a human noticed. The draft
2628
- // exists — that is a real, visible effect — so the operator is told exactly what is missing
2629
- // and where it is. WECHATMP_ALLOW_PARTIAL_ENRICH=1 restores the old warn-and-continue shape
2630
- // for an account that genuinely cannot offer one of these fields.
2631
- if (result.ok && composed.enrichWarnings.length > 0 && process.env.WECHATMP_ALLOW_PARTIAL_ENRICH !== '1') {
2651
+ // Requested enrichment that did not take is a FAILURE, not a warning (2026-11-15).
2652
+ // WECHATMP_ALLOW_PARTIAL_ENRICH=1 tolerates ONLY account capability refusals (赞赏账户,
2653
+ // 原文链接行不存在) — never real non-capability failures (音频, 原创声明, 原文链接保存失败,
2654
+ // 合集, 创作来源).
2655
+ const capabilitySet = new Set(composed.capabilityWarnings ?? []);
2656
+ const blockingEnrichWarnings = composed.enrichWarnings.filter((warning) => !capabilitySet.has(warning));
2657
+ const partialAllowed = process.env.WECHATMP_ALLOW_PARTIAL_ENRICH === '1';
2658
+ const fatalEnrichWarnings = partialAllowed ? blockingEnrichWarnings : composed.enrichWarnings;
2659
+ if (result.ok && fatalEnrichWarnings.length > 0) {
2660
+ const capabilityOnly = blockingEnrichWarnings.length === 0;
2632
2661
  return {
2633
2662
  ...result,
2634
2663
  ok: false,
2635
- error: `draft saved but enrichment did not apply — ${composed.enrichWarnings.join(' | ')} (set WECHATMP_ALLOW_PARTIAL_ENRICH=1 to accept a partial draft)`,
2664
+ error: `draft saved but enrichment did not apply — ${fatalEnrichWarnings.join(' | ')}${
2665
+ capabilityOnly ? ' (set WECHATMP_ALLOW_PARTIAL_ENRICH=1 to accept a partial draft)' : ''
2666
+ }`,
2636
2667
  };
2637
2668
  }
2638
2669
  return result;
@@ -2739,6 +2770,14 @@ function escapeHtml(text: string): string {
2739
2770
  return text.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
2740
2771
  }
2741
2772
 
2773
+ async function evalOrFallback(page: WechatPage, script: string, fallback: string): Promise<string> {
2774
+ try {
2775
+ return String((await page.evaluate(script)) ?? fallback);
2776
+ } catch {
2777
+ return fallback;
2778
+ }
2779
+ }
2780
+
2742
2781
  /**
2743
2782
  * Audio at the article top (operator request 2026-09-29; upload path added 2026-10-10).
2744
2783
  *
@@ -2754,7 +2793,17 @@ function escapeHtml(text: string): string {
2754
2793
  export async function insertAudioMaterial(
2755
2794
  page: WechatPage,
2756
2795
  input: { title: string; audioPath: string; coverPath: string },
2796
+ timing: {
2797
+ uploadWaitMs?: number;
2798
+ saveCloseWaitMs?: number;
2799
+ saveDispatchWaitMs?: number;
2800
+ rowRetries?: number;
2801
+ } = {},
2757
2802
  ): Promise<{ warning: string; coverSeeded: boolean }> {
2803
+ const uploadWaitMs = timing.uploadWaitMs ?? 120_000;
2804
+ const saveCloseWaitMs = timing.saveCloseWaitMs ?? 30_000;
2805
+ const saveDispatchWaitMs = timing.saveDispatchWaitMs ?? 10_000;
2806
+ const postUploadRowRetries = timing.rowRetries ?? 15;
2758
2807
  const { title, audioPath, coverPath } = input;
2759
2808
  // The library demonstrably holds the episode cover once the picker verified the unique same-name
2760
2809
  // row (0260 R1 refined 2026-11-09): failures AFTER that point must not suppress the deferred
@@ -2837,17 +2886,46 @@ export async function insertAudioMaterial(
2837
2886
  })()`;
2838
2887
 
2839
2888
  /** Upload the audio + its cover, acknowledge the rules, and 保存. Returns a structured outcome. */
2840
- const upload = async (): Promise<{ warning: string; coverSeeded: boolean }> => {
2889
+ const upload = async (): Promise<{ warning: string; coverSeeded: boolean; sawLiveUpload: boolean }> => {
2890
+ let sawLiveUpload = false;
2891
+ const failUpload = (warning: string) => ({ ...result(warning), sawLiveUpload });
2892
+ const uploadDialog = '.weui-desktop-dialog:visible:has(h3.weui-desktop-dialog__title:text-is("上传音频"))';
2893
+ const isLiveUploadForm = async (): Promise<boolean> => {
2894
+ if ((await page.locator(uploadDialog).count()) === 0) return false;
2895
+ try {
2896
+ const titleText =
2897
+ (await page.locator(`${uploadDialog} h3.weui-desktop-dialog__title`).first().textContent?.()) ?? '';
2898
+ return titleText.trim() === '上传音频';
2899
+ } catch {
2900
+ return false;
2901
+ }
2902
+ };
2841
2903
  const uploadControl = await trySelectors(page, UPLOAD_AUDIO);
2842
- if (!uploadControl.found) return result('音频: 上传音频 control not found in the audio dialog');
2904
+ if (!uploadControl.found) return failUpload('音频: 上传音频 control not found in the audio dialog');
2843
2905
  // Click the winner, never a joined union: `text=…, css…` mixes selector engines and
2844
2906
  // Playwright parses the whole string as CSS — zero matches (DOM fixture 0260).
2845
2907
  await clickSelector(page, uploadControl.selector ?? UPLOAD_AUDIO[0] ?? 'text=上传音频', 8_000);
2846
2908
  const audioInput = await trySelectors(page, AUDIO_UPLOAD_INPUT, { visible: false });
2847
- if (!audioInput.found) return result('音频: no audio file input appeared');
2909
+ if (!audioInput.found) return failUpload('音频: no audio file input appeared');
2848
2910
  await uploadFile(asPlaywrightPage(page), audioInput.selector ?? AUDIO_UPLOAD_INPUT.join(', '), audioPath, {
2849
- timeoutMs: 60_000,
2911
+ timeoutMs: 120_000,
2850
2912
  });
2913
+ sawLiveUpload = await isLiveUploadForm();
2914
+ if (sawLiveUpload) {
2915
+ const uploaded = await waitUntil(
2916
+ async () =>
2917
+ (await page.locator(`${uploadDialog} button:has-text("重新上传")`).count()) > 0 &&
2918
+ /100%/.test(
2919
+ await evalOrFallback(
2920
+ page,
2921
+ `(() => { const d = [...document.querySelectorAll('.weui-desktop-dialog')].find((el) => el.offsetWidth > 0 && el.querySelector('input[name=audio_id]')); return d ? (d.textContent ?? '') : ''; })()`,
2922
+ '',
2923
+ ),
2924
+ ),
2925
+ uploadWaitMs,
2926
+ );
2927
+ if (!uploaded) return failUpload('音频: 音频文件上传未完成(未达到 100%),未保存音频');
2928
+ }
2851
2929
  // The form requires a cover before it will save.
2852
2930
  const coverControl = await trySelectors(page, UPLOAD_COVER);
2853
2931
  if (coverControl.found) {
@@ -2868,13 +2946,13 @@ export async function insertAudioMaterial(
2868
2946
  ),
2869
2947
  5_000,
2870
2948
  );
2871
- if (!libraryReady) return result('音频: 封面素材库加载未完成,未上传重复封面');
2949
+ if (!libraryReady) return failUpload('音频: 封面素材库加载未完成,未上传重复封面');
2872
2950
  existing = Number(
2873
2951
  await page.evaluate(
2874
2952
  `([...document.querySelectorAll('.weui-desktop-img-picker__item')].filter(row => row.offsetWidth > 0 && row.querySelector('.weui-desktop-img-picker__img-title')?.textContent?.trim() === ${JSON.stringify(coverName)})).length`,
2875
2953
  ),
2876
2954
  );
2877
- if (existing > 1) return result('音频: 内容绑定封面存在多个同名素材,未猜测选择');
2955
+ if (existing > 1) return failUpload('音频: 内容绑定封面存在多个同名素材,未猜测选择');
2878
2956
  }
2879
2957
  let uploadPath = coverPath;
2880
2958
  let temporaryDir: string | undefined;
@@ -2911,7 +2989,7 @@ export async function insertAudioMaterial(
2911
2989
  ),
2912
2990
  30_000,
2913
2991
  );
2914
- if (!selected) return result('音频: 上传封面未出现唯一已选中的同名图片,未提交封面');
2992
+ if (!selected) return failUpload('音频: 上传封面未出现唯一已选中的同名图片,未提交封面');
2915
2993
  // The picker just proved the library holds the unique same-name cover; every
2916
2994
  // failure past this point leaves the cover in the 图片库 (cover rescue valid).
2917
2995
  libraryHasCover = true;
@@ -2922,6 +3000,9 @@ export async function insertAudioMaterial(
2922
3000
  30_000,
2923
3001
  );
2924
3002
  await clickSelector(page, next, 8_000);
3003
+ if (sawLiveUpload && (await page.locator(`${chooser} button:has-text("上一步")`).count()) > 0) {
3004
+ await page.waitForTimeout?.(2_000);
3005
+ }
2925
3006
  const finish = await findSelector(
2926
3007
  page,
2927
3008
  [`${chooser} button:has-text("完成"):not(.weui-desktop-btn_disabled)`],
@@ -2945,12 +3026,35 @@ export async function insertAudioMaterial(
2945
3026
  );
2946
3027
  }
2947
3028
  }
3029
+ if (!closed) {
3030
+ // 2026-11-20: the `完成` walk can leave the picker on screen (a
3031
+ // crop-confirm page whose 确定 sits outside the chooser subtree). Close
3032
+ // the PICKER only — the audio dialog behind it still holds the uploaded
3033
+ // file and the material title, so a global dialog sweep would discard
3034
+ // the audio we came for.
3035
+ const pickerClose = await tryFindSelector(
3036
+ page,
3037
+ [
3038
+ `${chooser} .weui-desktop-dialog__close-btn`,
3039
+ `${chooser} .weui-desktop-dialog__close`,
3040
+ `${chooser} button:has-text("取消")`,
3041
+ ],
3042
+ 3_000,
3043
+ );
3044
+ if (pickerClose !== undefined) {
3045
+ await clickSelector(page, pickerClose, 3_000);
3046
+ closed = await waitUntil(
3047
+ async () => !(await page.locator(chooser).first().isVisible()),
3048
+ 10_000,
3049
+ );
3050
+ }
3051
+ }
2948
3052
  if (!closed) {
2949
3053
  // Live 2026-11-09 this stall is real — capture WHAT is on screen (the
2950
3054
  // confirm dialog may not nest under the chooser selector, which would
2951
3055
  // explain the 确定 retry missing it) before giving up on the audio save.
2952
3056
  const inventory = await openDialogInventory(page);
2953
- return result(
3057
+ return failUpload(
2954
3058
  `音频: 封面选择器完成后未关闭,未保存音频${inventory ? ` (dialogs: ${inventory})` : ''}`,
2955
3059
  );
2956
3060
  }
@@ -2966,15 +3070,42 @@ export async function insertAudioMaterial(
2966
3070
  const titleInput = await trySelectors(page, AUDIO_TITLE_INPUT);
2967
3071
  if (titleInput.found) await fillSelector(page, titleInput.selector ?? AUDIO_TITLE_INPUT.join(', '), title);
2968
3072
  const agreed = String(await page.evaluate(AGREE));
2969
- if (agreed !== 'checked') return result(`音频: 服务规则勾选失败 (${agreed})`);
3073
+ if (agreed !== 'checked') return failUpload(`音频: 服务规则勾选失败 (${agreed})`);
2970
3074
  const save = await findSelector(
2971
3075
  page,
2972
3076
  UPLOAD_SAVE.map((selector) => `${selector}:not(.weui-desktop-btn_disabled):not([disabled])`),
2973
3077
  '音频上传完成且封面已提交后的保存按钮',
2974
3078
  90_000,
2975
3079
  );
3080
+ if (sawLiveUpload) {
3081
+ await evalOrFallback(
3082
+ page,
3083
+ '(() => { window.__kkToasts = []; new MutationObserver(() => { const t = document.querySelector(".weui-desktop-toast"); if (t && t.textContent) window.__kkToasts.push(t.textContent.trim().slice(0, 200)); }).observe(document.body, { subtree: true, childList: true, characterData: true }); })()',
3084
+ '',
3085
+ );
3086
+ }
2976
3087
  await clickSelector(page, save, 8_000);
2977
- return result('');
3088
+ if (sawLiveUpload) {
3089
+ let formClosed = await waitUntil(async () => !(await isLiveUploadForm()), saveCloseWaitMs);
3090
+ if (!formClosed) {
3091
+ const dispatched = await evalOrFallback(
3092
+ page,
3093
+ '(() => { const form = [...document.querySelectorAll(".weui-desktop-dialog")].find((d) => d.querySelector(".title_form_wrp")); const btn = form && [...form.querySelectorAll("button")].find((b) => (b.textContent ?? "").trim() === "保存"); if (!btn) return "no-btn"; btn.click(); return btn.disabled ? "was-disabled" : "clicked"; })()',
3094
+ 'null',
3095
+ );
3096
+ formClosed = await waitUntil(async () => !(await isLiveUploadForm()), saveDispatchWaitMs);
3097
+ if (!formClosed) {
3098
+ const saveDiagnostics = `(() => {
3099
+ const form = [...document.querySelectorAll(".weui-desktop-dialog")].find((d) => d.querySelector(".title_form_wrp"));
3100
+ const btn = form && [...form.querySelectorAll("button")].find((b) => (b.textContent ?? "").trim() === "保存");
3101
+ return JSON.stringify({ btn: btn ? { disabled: btn.disabled, offW: btn.offsetWidth } : null, toasts: (window.__kkToasts ?? []).slice(-3) });
3102
+ })()`;
3103
+ const diag = (await evalOrFallback(page, saveDiagnostics, '')).slice(0, 400);
3104
+ return failUpload(`音频: 保存失败,上传弹窗未关闭(dispatch=${dispatched} ${diag})`);
3105
+ }
3106
+ }
3107
+ }
3108
+ return failUpload('');
2978
3109
  };
2979
3110
 
2980
3111
  /** One MATCH read; a throwing probe stays 'error' (unknown, never treated as missing). */
@@ -2986,9 +3117,9 @@ export async function insertAudioMaterial(
2986
3117
  }
2987
3118
  };
2988
3119
  /** Poll the picker while rows stream in; 'missing' keeps polling, JSON answers settle it. */
2989
- const awaitMatch = async (): Promise<string> => {
3120
+ const awaitMatch = async (retries: number = AUDIO_ROW_RETRIES): Promise<string> => {
2990
3121
  let match = await matchOnce();
2991
- for (let i = 0; match === 'missing' && i < AUDIO_ROW_RETRIES; i += 1) {
3122
+ for (let i = 0; match === 'missing' && i < retries; i += 1) {
2992
3123
  await page.waitForTimeout?.(AUDIO_ROW_SETTLE_MS);
2993
3124
  match = await matchOnce();
2994
3125
  }
@@ -3005,16 +3136,18 @@ export async function insertAudioMaterial(
3005
3136
  await page.evaluate(`document.querySelector(${JSON.stringify(AUDIO_MENU)})?.click()`);
3006
3137
  await waitForVisible(page, AUDIO_DIALOG, AUDIO_DIALOG_TIMEOUT_MS);
3007
3138
  let match = await awaitMatch();
3139
+ let postSavePoll = false;
3008
3140
  if (match === 'missing') {
3009
3141
  // No reusable material: upload one, then POLL until the new row actually exists — never
3010
3142
  // assume the upload auto-selected a default row (task 0260 AC2).
3011
3143
  const uploadResult = await upload();
3144
+ postSavePoll = uploadResult.sawLiveUpload;
3012
3145
  if (uploadResult.warning !== '') {
3013
- await page.evaluate(CANCEL);
3146
+ if (!uploadResult.sawLiveUpload) await page.evaluate(CANCEL);
3014
3147
  return result(uploadResult.warning);
3015
3148
  }
3016
3149
  await waitForVisible(page, AUDIO_DIALOG, AUDIO_DIALOG_TIMEOUT_MS);
3017
- match = await awaitMatch();
3150
+ match = await awaitMatch(postSavePoll ? postUploadRowRetries : AUDIO_ROW_RETRIES);
3018
3151
  if (match === 'missing') {
3019
3152
  await page.evaluate(CANCEL);
3020
3153
  return result(`音频: 保存后素材列表未出现「${title}」,未插入音频`);
@@ -3042,7 +3175,14 @@ export async function insertAudioMaterial(
3042
3175
  await page.evaluate(CANCEL);
3043
3176
  return result('音频: 素材匹配探测返回未知结果,未插入音频');
3044
3177
  }
3045
- if ((await page.evaluate(INSERT)) !== true) {
3178
+ let inserted = (await page.evaluate(INSERT)) === true;
3179
+ if (!inserted && postSavePoll) {
3180
+ for (let i = 0; !inserted && i < 5; i += 1) {
3181
+ await page.waitForTimeout?.(500);
3182
+ inserted = (await page.evaluate(INSERT)) === true;
3183
+ }
3184
+ }
3185
+ if (!inserted) {
3046
3186
  await page.evaluate(CANCEL);
3047
3187
  return result('音频: 插入按钮未找到,请手动插入');
3048
3188
  }
@@ -208,14 +208,29 @@ async function resolveMediaPath(content: Content, spec: MediaSpec): Promise<{ pa
208
208
  return { path };
209
209
  }
210
210
 
211
+ /** Whether `content.metadata.wechatmp.coverSource === 'library'`. */
212
+ export function isLibraryCover(content: Content): boolean {
213
+ const wechatmp = content.metadata?.wechatmp;
214
+ return (
215
+ typeof wechatmp === 'object' &&
216
+ wechatmp !== null &&
217
+ !Array.isArray(wechatmp) &&
218
+ (wechatmp as Record<string, unknown>).coverSource === 'library'
219
+ );
220
+ }
221
+
211
222
  /**
212
223
  * The body-image set for the two image-carrying modes, in attachment order.
213
224
  *
214
- * `metadata.images` is the repo's ordered convention (xhs reads the same key). The daily MP stage
215
- * instead supplies `metadata.wechatmp.coverPath` — the operator's cover — which is attached FIRST
216
- * because the cover panel states 默认首图为封面 (discovery §5.2): the first body image is the cover.
225
+ * `metadata.images` is the repo's ordered convention (xhs reads the same key). When `coverSource`
226
+ * is `'library'` (the daily 文章 + audio rail), the cover comes from 图片库 via the audio upload's
227
+ * seeded cover — validating `coverPath`/`coverImage` stays active, but the cover file is NOT
228
+ * injected into the article body. When `coverSource` is `'body'` or omitted, `coverPath`/`coverImage`
229
+ * are prepended so 默认首图为封面 resolves the cover from the first body image (discovery §5.2).
217
230
  */
218
- async function resolveBodyImages(content: Content): Promise<{ paths?: string[]; error?: string }> {
231
+ async function resolveBodyImages(
232
+ content: Content,
233
+ ): Promise<{ paths?: string[]; hasValidatedCover?: boolean; error?: string }> {
219
234
  const ordered = content.metadata?.images;
220
235
  if (ordered !== undefined && !Array.isArray(ordered)) {
221
236
  return { error: 'images validation: metadata.images must be an array' };
@@ -225,9 +240,9 @@ async function resolveBodyImages(content: Content): Promise<{ paths?: string[];
225
240
  typeof content.metadata?.wechatmp === 'object' && content.metadata.wechatmp !== null
226
241
  ? (content.metadata.wechatmp as Record<string, unknown>).coverPath
227
242
  : undefined;
228
- const candidates: Array<{ path: string; what: string }> = [];
243
+ const candidates: Array<{ path: string; what: string; coverOnly: boolean }> = [];
229
244
  if (typeof cover === 'string' && cover.length > 0)
230
- candidates.push({ path: cover, what: 'metadata.wechatmp.coverPath' });
245
+ candidates.push({ path: cover, what: 'metadata.wechatmp.coverPath', coverOnly: true });
231
246
  // Repo-wide single-cover convention (itc pipeline writes this; surfdash/xhs read it too).
232
247
  const genericCover = content.metadata?.coverImage;
233
248
  const genericCoverPath =
@@ -237,17 +252,19 @@ async function resolveBodyImages(content: Content): Promise<{ paths?: string[];
237
252
  ? (genericCover as { path: string }).path
238
253
  : undefined;
239
254
  if (genericCoverPath !== undefined && genericCoverPath.length > 0)
240
- candidates.push({ path: genericCoverPath, what: 'metadata.coverImage' });
255
+ candidates.push({ path: genericCoverPath, what: 'metadata.coverImage', coverOnly: true });
241
256
  for (const [index, image] of descriptors.entries()) {
242
257
  const path = typeof image === 'string' ? image : (image as { path?: unknown })?.path;
243
258
  if (typeof path !== 'string' || path.length === 0) {
244
259
  return { error: `images validation: images[${index}] carries no path` };
245
260
  }
246
- candidates.push({ path, what: `metadata.images[${index}]` });
261
+ candidates.push({ path, what: `metadata.images[${index}]`, coverOnly: false });
247
262
  }
248
263
 
264
+ const skipCoverInBody = isLibraryCover(content);
249
265
  const paths: string[] = [];
250
- for (const { path, what } of candidates) {
266
+ let hasValidatedCover = false;
267
+ for (const { path, what, coverOnly } of candidates) {
251
268
  if (!isAbsolute(path)) {
252
269
  return { error: `images validation: ${what} must be absolute, got '${path}'` };
253
270
  }
@@ -259,9 +276,10 @@ async function resolveBodyImages(content: Content): Promise<{ paths?: string[];
259
276
  if (!(await createNodeFileSystem().exists(path))) {
260
277
  return { error: `images validation: ${what} does not exist: '${path}'` };
261
278
  }
262
- paths.push(path);
279
+ if (coverOnly) hasValidatedCover = true;
280
+ if (!(skipCoverInBody && coverOnly)) paths.push(path);
263
281
  }
264
- return { paths };
282
+ return { paths, hasValidatedCover };
265
283
  }
266
284
 
267
285
  /**
@@ -359,7 +377,7 @@ export async function validateModeInput(operation: WechatmpOperation, content: C
359
377
  if (digest.error) return { error: digest.error };
360
378
  const images = await resolveBodyImages(content);
361
379
  if (images.error) return { error: images.error };
362
- if ((images.paths ?? []).length === 0) {
380
+ if ((images.paths ?? []).length === 0 && !(isLibraryCover(content) && images.hasValidatedCover === true)) {
363
381
  return {
364
382
  error: 'cover validation: 文章 takes its cover from a body image (默认首图为封面) but none was supplied — set metadata.wechatmp.coverPath, metadata.coverImage or metadata.images[]',
365
383
  };