@gobing-ai/knowledge-kit 0.1.20 → 0.1.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/dist/board/collect/index.js +1 -0
  3. package/dist/board/daily-voice/index.js +1279 -261
  4. package/dist/board/itc/index.js +1 -0
  5. package/dist/index.js +13938 -8966
  6. package/package.json +1 -1
  7. package/plugins/generations/dailynews-gen/dist/index.js +285 -16
  8. package/plugins/generations/dailynews-gen/src/editorial-claims.ts +215 -0
  9. package/plugins/generations/dailynews-gen/src/index.ts +23 -4
  10. package/plugins/generations/dailynews-gen/src/script-builder.ts +10 -3
  11. package/plugins/generations/dailynews-gen/src/script-plan.ts +74 -14
  12. package/plugins/generations/gemini-tts/dist/index.js +47 -7
  13. package/plugins/generations/gemini-tts/src/gemini-client.ts +34 -6
  14. package/plugins/generations/music-gen/README.md +277 -0
  15. package/plugins/generations/music-gen/dist/index.js +23580 -0
  16. package/plugins/generations/music-gen/package.json +24 -0
  17. package/plugins/generations/music-gen/plugin.json +23 -0
  18. package/plugins/generations/music-gen/presets/SOURCE.md +39 -0
  19. package/plugins/generations/music-gen/presets/formats/clip.yaml +21 -0
  20. package/plugins/generations/music-gen/presets/formats/jingle.yaml +22 -0
  21. package/plugins/generations/music-gen/presets/formats/loop.yaml +21 -0
  22. package/plugins/generations/music-gen/presets/formats/song.yaml +36 -0
  23. package/plugins/generations/music-gen/presets/formats/underscore.yaml +22 -0
  24. package/plugins/generations/music-gen/presets/themes/ambient-tech.yaml +30 -0
  25. package/plugins/generations/music-gen/presets/themes/cinematic.yaml +30 -0
  26. package/plugins/generations/music-gen/presets/themes/lofi.yaml +30 -0
  27. package/plugins/generations/music-gen/presets/themes/synthwave.yaml +35 -0
  28. package/plugins/generations/music-gen/scripts/gen-preset-index.ts +181 -0
  29. package/plugins/generations/music-gen/scripts/resolve-preset.ts +64 -0
  30. package/plugins/generations/music-gen/src/adapter/index.ts +35 -0
  31. package/plugins/generations/music-gen/src/adapter/instance.ts +927 -0
  32. package/plugins/generations/music-gen/src/adapter/offline.ts +124 -0
  33. package/plugins/generations/music-gen/src/artifact.ts +223 -0
  34. package/plugins/generations/music-gen/src/audio/checks.ts +618 -0
  35. package/plugins/generations/music-gen/src/audio/master.ts +267 -0
  36. package/plugins/generations/music-gen/src/audio/measure.ts +507 -0
  37. package/plugins/generations/music-gen/src/audio/profile.ts +131 -0
  38. package/plugins/generations/music-gen/src/audio.ts +122 -0
  39. package/plugins/generations/music-gen/src/brief.ts +191 -0
  40. package/plugins/generations/music-gen/src/config.ts +451 -0
  41. package/plugins/generations/music-gen/src/content.ts +199 -0
  42. package/plugins/generations/music-gen/src/digest.ts +100 -0
  43. package/plugins/generations/music-gen/src/index.ts +147 -0
  44. package/plugins/generations/music-gen/src/job.ts +131 -0
  45. package/plugins/generations/music-gen/src/plugin.ts +371 -0
  46. package/plugins/generations/music-gen/src/presets.ts +951 -0
  47. package/plugins/generations/music-gen/src/render.ts +87 -0
  48. package/plugins/generations/music-gen/src/request.ts +102 -0
  49. package/plugins/generations/music-gen/src/spend.ts +495 -0
  50. package/plugins/generations/music-gen/tsconfig.json +8 -0
  51. package/plugins/generations/omni-voice-gen/uv.toml +5 -0
  52. package/plugins/generations/vibe-voice-tts/README.md +64 -0
  53. package/plugins/generations/vibe-voice-tts/dist/index.js +14259 -0
  54. package/plugins/generations/vibe-voice-tts/package.json +16 -0
  55. package/plugins/generations/vibe-voice-tts/plugin.json +6 -0
  56. package/plugins/generations/vibe-voice-tts/profiles.json +10 -0
  57. package/plugins/generations/vibe-voice-tts/pyproject.toml +9 -0
  58. package/plugins/generations/vibe-voice-tts/python/worker.py +566 -0
  59. package/plugins/generations/vibe-voice-tts/src/index.ts +88 -0
  60. package/plugins/generations/vibe-voice-tts/src/vibevoice-client.ts +828 -0
  61. package/plugins/generations/vibe-voice-tts/tsconfig.json +8 -0
  62. package/plugins/generations/vibe-voice-tts/uv.lock +1767 -0
  63. package/plugins/generations/vibe-voice-tts/uv.toml +4 -0
  64. package/plugins/generations/voice-gen/dist/index.js +31 -1
  65. package/plugins/generations/voice-gen/src/voicebox-client.ts +50 -1
  66. package/plugins/generations/voxcpm-tts/dist/index.js +81 -9
  67. package/plugins/generations/voxcpm-tts/python/worker.py +9 -0
  68. package/plugins/generations/voxcpm-tts/src/index.ts +41 -0
  69. package/plugins/generations/voxcpm-tts/src/voxcpm-client.ts +32 -11
  70. package/plugins/generations/voxcpm-tts/uv.toml +5 -0
  71. package/plugins/kk/README.md +21 -0
  72. package/plugins/kk/decisions/kk-safety.yaml +5 -2
  73. package/plugins/kk/plugin.json +1 -1
  74. package/plugins/kk/schedules/kk-serve.launchd.plist.tmpl +14 -2
  75. package/plugins/kk/scripts/cover-compositor.ts +380 -32
  76. package/plugins/kk/scripts/daily-cover-mock.ts +40 -3
  77. package/plugins/kk/scripts/daily-stages.ts +933 -60
  78. package/plugins/kk/scripts/episode-identity.ts +180 -0
  79. package/plugins/kk/scripts/kk-workflow-stages.ts +111 -12
  80. package/plugins/kk/scripts/music-stages.ts +624 -0
  81. package/plugins/kk/scripts/news-editorial-ledger.ts +906 -0
  82. package/plugins/kk/scripts/safety-artifact-check.ts +28 -5
  83. package/plugins/kk/scripts/source-citation.ts +187 -0
  84. package/plugins/kk/scripts/topic-selection-attempts.ts +446 -0
  85. package/plugins/kk/scripts/topic-selection-calibration.ts +161 -0
  86. package/plugins/kk/skills/content-judge/SKILL.md +11 -6
  87. package/plugins/kk/skills/content-judge/references/music-quality-rubric.md +147 -0
  88. package/plugins/kk/skills/content-judge/references/rubrics.md +15 -0
  89. package/plugins/kk/skills/content-safety/SKILL.md +12 -0
  90. package/plugins/kk/skills/music-authoring/SKILL.md +276 -0
  91. package/plugins/kk/skills/music-authoring/references/judge-input.md +117 -0
  92. package/plugins/kk/skills/news-editorial/SKILL.md +102 -15
  93. package/plugins/kk/skills/news-editorial/references/selection.md +4 -0
  94. package/plugins/kk/skills/news-editorial/references/style-contract.zh.md +58 -11
  95. package/plugins/kk/workflows/kk-daily-ai-voice.yaml +12 -11
  96. package/plugins/kk/workflows/kk-daily-ai-voice2.yaml +13 -12
  97. package/plugins/kk/workflows/kk-daily-safety.yaml +12 -10
  98. package/plugins/kk/workflows/kk-music.yaml +332 -0
  99. package/plugins/kk/workflows/kk-news-generate.yaml +81 -6
  100. package/plugins/kk/workflows/kk-publish.yaml +4 -1
  101. package/plugins/publishings/bilibili-pub/dist/index.js +11 -1
  102. package/plugins/publishings/bilibili-pub/dist/profile-check.js +11 -1
  103. package/plugins/publishings/cnblogs-pub/dist/index.js +11 -1
  104. package/plugins/publishings/cnblogs-pub/dist/profile-check.js +11 -1
  105. package/plugins/publishings/csdn-pub/dist/index.js +11 -1
  106. package/plugins/publishings/csdn-pub/dist/profile-check.js +11 -1
  107. package/plugins/publishings/infoq-pub/dist/index.js +11 -1
  108. package/plugins/publishings/infoq-pub/dist/profile-check.js +11 -1
  109. package/plugins/publishings/jike-pub/dist/index.js +11 -1
  110. package/plugins/publishings/jike-pub/dist/profile-check.js +11 -1
  111. package/plugins/publishings/juejin-pub/dist/index.js +11 -1
  112. package/plugins/publishings/juejin-pub/dist/profile-check.js +11 -1
  113. package/plugins/publishings/linkedin-pub/dist/index.js +62 -10
  114. package/plugins/publishings/linkedin-pub/dist/profile-check.js +16 -1
  115. package/plugins/publishings/linkedin-pub/src/index.ts +99 -12
  116. package/plugins/publishings/podcast-pub/dist/index.js +586 -20
  117. package/plugins/publishings/podcast-pub/src/corrections.ts +509 -0
  118. package/plugins/publishings/podcast-pub/src/index.ts +257 -5
  119. package/plugins/publishings/podcast-pub/src/show-notes-brief.ts +240 -0
  120. package/plugins/publishings/podcast-pub/src/show-notes.ts +69 -13
  121. package/plugins/publishings/shipinhao-pub/dist/index.js +59 -8
  122. package/plugins/publishings/shipinhao-pub/dist/profile-check.js +11 -1
  123. package/plugins/publishings/shipinhao-pub/src/audio-flow.ts +105 -6
  124. package/plugins/publishings/sspai-pub/dist/index.js +11 -1
  125. package/plugins/publishings/sspai-pub/dist/profile-check.js +11 -1
  126. package/plugins/publishings/substack-pub/dist/index.js +11 -1
  127. package/plugins/publishings/substack-pub/dist/profile-check.js +11 -1
  128. package/plugins/publishings/surfdash-pub/dist/index.js +80 -24
  129. package/plugins/publishings/surfdash-pub/src/digest-check.ts +7 -3
  130. package/plugins/publishings/surfdash-pub/src/index.ts +107 -18
  131. package/plugins/publishings/surfdash-pub/src/patch.ts +21 -3
  132. package/plugins/publishings/surfdash-pub/src/topic-claims.ts +3 -1
  133. package/plugins/publishings/threads-pub/dist/index.js +58 -6
  134. package/plugins/publishings/threads-pub/dist/profile-check.js +18 -2
  135. package/plugins/publishings/threads-pub/src/post-rail.ts +101 -4
  136. package/plugins/publishings/wechatmp-pub/dist/index.js +105 -35
  137. package/plugins/publishings/wechatmp-pub/dist/profile-check.js +11 -1
  138. package/plugins/publishings/wechatmp-pub/src/cgi-draft.ts +87 -53
  139. package/plugins/publishings/wechatmp-pub/src/enrich.ts +61 -3
  140. package/plugins/publishings/wechatmp-pub/src/flow.ts +28 -0
  141. package/plugins/publishings/weibo-pub/dist/index.js +11 -1
  142. package/plugins/publishings/weibo-pub/dist/profile-check.js +11 -1
  143. package/plugins/publishings/x-pub/dist/index.js +95 -10
  144. package/plugins/publishings/x-pub/dist/profile-check.js +11 -1
  145. package/plugins/publishings/x-pub/src/post-rail.ts +154 -12
  146. package/plugins/publishings/xhs-pub/dist/index.js +11 -1
  147. package/plugins/publishings/xhs-pub/dist/profile-check.js +11 -1
  148. package/plugins/publishings/xiaoyuzhou-pub/dist/index.js +11 -1
  149. package/plugins/publishings/xiaoyuzhou-pub/dist/profile-check.js +11 -1
@@ -12370,10 +12370,10 @@ var SERIES_NAMES = {
12370
12370
  en: "Daily AI Stew",
12371
12371
  ja: "\u30C7\u30A4\u30EA\u30FCAI\u30B7\u30C1\u30E5\u30FC"
12372
12372
  };
12373
- function crossLinkFor(locale, dateIso, showNotesUrl) {
12373
+ function crossLinkFor(locale, dateIso, showNotesUrl, episodeTitle = "") {
12374
12374
  const series = SERIES_NAMES[locale];
12375
12375
  const links = {
12376
- zh: `\uD83C\uDFA7 \u672C\u671F\u5DF2\u540C\u6B65\u5236\u4F5C\u4E3A\u64AD\u5BA2\u8282\u76EE\uFF0C[\u70B9\u51FB\u6536\u542C\u300A${series} \xB7 ${dateIso}\u300B](${showNotesUrl})\u3002`,
12376
+ zh: episodeTitle !== "" ? `\uD83C\uDFA7 \u672C\u671F\u5DF2\u540C\u6B65\u5236\u4F5C\u4E3A\u64AD\u5BA2\u8282\u76EE\uFF0C[\u70B9\u51FB\u6536\u542C\u300A${series} \xB7 ${dateIso}\u300B](${showNotesUrl})\uFF1A${episodeTitle}\u3002` : `\uD83C\uDFA7 \u672C\u671F\u5DF2\u540C\u6B65\u5236\u4F5C\u4E3A\u64AD\u5BA2\u8282\u76EE\uFF0C[\u70B9\u51FB\u6536\u542C\u300A${series} \xB7 ${dateIso}\u300B](${showNotesUrl})\u3002`,
12377
12377
  en: `\uD83C\uDFA7 This episode is also available as a podcast: [listen to ${series} \xB7 ${dateIso}](${showNotesUrl}).`,
12378
12378
  ja: `\uD83C\uDFA7 \u672C\u30A8\u30D4\u30BD\u30FC\u30C9\u306F\u30DD\u30C3\u30C9\u30AD\u30E3\u30B9\u30C8\u3067\u3082\u914D\u4FE1\u4E2D\uFF1A[${series} \xB7 ${dateIso} \u3092\u8074\u304F](${showNotesUrl})\u3002`
12379
12379
  };
@@ -12431,8 +12431,11 @@ async function patchPostFiles(request) {
12431
12431
  md = upsertFrontmatterKey(md, "og_image", "./assets/cover.png");
12432
12432
  images[locale] = "./assets/cover.png";
12433
12433
  }
12434
+ if (locale === "zh" && (request.episodeTitle ?? "") !== "") {
12435
+ md = upsertFrontmatterKey(md, "episode_title", request.episodeTitle);
12436
+ }
12434
12437
  if (request.showNotesUrl !== "") {
12435
- const link = crossLinkFor(locale, request.dateIso, request.showNotesUrl);
12438
+ const link = crossLinkFor(locale, request.dateIso, request.showNotesUrl, request.episodeTitle ?? "");
12436
12439
  const lines = md.split(`
12437
12440
  `);
12438
12441
  const carriesUrl = lines.some((line) => line.includes(request.showNotesUrl));
@@ -12609,9 +12612,8 @@ function checkDigestFrontmatter(markdown, locale) {
12609
12612
  } else {
12610
12613
  const rest = match[2] ?? "";
12611
12614
  const heads = locale === "en" ? rest.split(", ") : rest.split("\u3001");
12612
- const seps = locale === "en" ? (rest.match(/, /g) ?? []).length : (rest.match(/\u3001/g) ?? []).length;
12613
- if (seps !== 1 || heads.some((head) => head.trim() === "")) {
12614
- problems.push(`title: expected exactly two non-empty headlines joined "${listSep}", got "${rest}"`);
12615
+ if (heads.length < 1 || heads.length > 2 || heads.some((head) => head.trim() === "")) {
12616
+ problems.push(`title: expected one or two non-empty headlines joined "${listSep}", got ${heads.length} in "${rest}"`);
12615
12617
  }
12616
12618
  }
12617
12619
  const seoTitle = `${title} | Surfing`;
@@ -12705,7 +12707,7 @@ function parseTitleHeadlines(title, locale) {
12705
12707
  if (!match?.[2])
12706
12708
  return;
12707
12709
  const heads = match[2].split(listSep).map((head) => head.trim());
12708
- if (heads.length < 2 || heads.some((head) => head === ""))
12710
+ if (heads.length < 1 || heads.length > 2 || heads.some((head) => head === ""))
12709
12711
  return;
12710
12712
  return heads;
12711
12713
  }
@@ -13435,7 +13437,8 @@ async function patchPost(options) {
13435
13437
  coverUrl: strOption(options, "coverUrl"),
13436
13438
  showNotesUrl: strOption(options, "showNotesUrl"),
13437
13439
  localCover: strOption(options, "localCover"),
13438
- dateIso: strOption(options, "dateIso")
13440
+ dateIso: strOption(options, "dateIso"),
13441
+ episodeTitle: strOption(options, "episodeTitle")
13439
13442
  });
13440
13443
  } catch (error) {
13441
13444
  return fail(`patch error: ${error instanceof Error ? error.message : String(error)}`);
@@ -13615,6 +13618,49 @@ function resolvePreparedPost(options) {
13615
13618
  identity: identity.value
13616
13619
  };
13617
13620
  }
13621
+ var LOCAL_DRAFTS = ["en", "ja"];
13622
+ function readLocaleDrafts(content) {
13623
+ const drafts = {};
13624
+ const surfdash = content.metadata?.surfdash;
13625
+ if (typeof surfdash !== "object" || surfdash === null)
13626
+ return drafts;
13627
+ const locales = surfdash.locales;
13628
+ if (typeof locales !== "object" || locales === null)
13629
+ return drafts;
13630
+ for (const locale of LOCAL_DRAFTS) {
13631
+ const entry = locales[locale];
13632
+ if (typeof entry !== "object" || entry === null)
13633
+ continue;
13634
+ const { title, body } = entry;
13635
+ if (typeof title !== "string" || title.trim() === "")
13636
+ continue;
13637
+ if (typeof body !== "string" || body.trim() === "")
13638
+ continue;
13639
+ drafts[locale] = { title, body };
13640
+ }
13641
+ return drafts;
13642
+ }
13643
+ async function mintLocalePost(options) {
13644
+ const filePath = join2(options.postDir, "index.md");
13645
+ if (readRefinedSnapshot(filePath) !== undefined) {
13646
+ echoError(`surfdash-pub: keeping existing refined post at ${filePath} (not re-minting)`);
13647
+ return;
13648
+ }
13649
+ await createNodeFileSystem().ensureDir(options.postDir);
13650
+ let imageFrontmatter;
13651
+ if (options.coverPath !== undefined) {
13652
+ const assetsDir = join2(options.postDir, "assets");
13653
+ await createNodeFileSystem().ensureDir(assetsDir);
13654
+ const coverName = `cover${extname(options.coverPath).toLowerCase()}`;
13655
+ await copyFile(options.coverPath, join2(assetsDir, coverName));
13656
+ imageFrontmatter = `./assets/${coverName}`;
13657
+ }
13658
+ const markdown = mapContentToSurfingMarkdown(options.content, {
13659
+ image: imageFrontmatter,
13660
+ publishDate: options.publishDate
13661
+ });
13662
+ await createNodeFileSystem().writeFile(filePath, markdown);
13663
+ }
13618
13664
  async function preparePost(payload) {
13619
13665
  const surfdashRoot = resolveSurfdashRoot();
13620
13666
  if (!surfdashRoot) {
@@ -13654,25 +13700,35 @@ async function preparePost(payload) {
13654
13700
  if (isDigestContent(payload.content) && typeof coverPath !== "string") {
13655
13701
  return { ok: false, result: failNotSent("digest post has no cover image (metadata.coverImage)") };
13656
13702
  }
13703
+ const drafts = readLocaleDrafts(payload.content);
13704
+ if (isDigestContent(payload.content)) {
13705
+ const missing = LOCAL_DRAFTS.filter((locale) => drafts[locale] === undefined);
13706
+ if (missing.length > 0) {
13707
+ return {
13708
+ ok: false,
13709
+ result: failNotSent(`digest post is missing metadata.surfdash.locales for ${missing.join(", ")} \u2014 the site refuses a digest with a missing locale file; re-run the localize step before publishing`)
13710
+ };
13711
+ }
13712
+ }
13657
13713
  const filePath = join2(postDir, "index.md");
13714
+ const publishDate = runDate ? `${runDate.slice(0, 4)}-${runDate.slice(4, 6)}-${runDate.slice(6, 8)}` : undefined;
13715
+ const cover = typeof coverPath === "string" ? coverPath : undefined;
13658
13716
  try {
13659
- if (readRefinedSnapshot(filePath) === undefined) {
13660
- await createNodeFileSystem().ensureDir(postDir);
13661
- let imageFrontmatter;
13662
- if (typeof coverPath === "string") {
13663
- const assetsDir = join2(postDir, "assets");
13664
- await createNodeFileSystem().ensureDir(assetsDir);
13665
- const coverName = `cover${extname(coverPath).toLowerCase()}`;
13666
- await copyFile(coverPath, join2(assetsDir, coverName));
13667
- imageFrontmatter = `./assets/${coverName}`;
13668
- }
13669
- const markdown = mapContentToSurfingMarkdown(payload.content, {
13670
- image: imageFrontmatter,
13671
- publishDate: runDate ? `${runDate.slice(0, 4)}-${runDate.slice(4, 6)}-${runDate.slice(6, 8)}` : undefined
13717
+ await mintLocalePost({ postDir, content: payload.content, coverPath: cover, publishDate });
13718
+ for (const locale of LOCAL_DRAFTS) {
13719
+ const draft = drafts[locale];
13720
+ if (draft === undefined)
13721
+ continue;
13722
+ const siblingDir = resolve(articlesRoot, locale, slug);
13723
+ if (dirname4(resolve(siblingDir)) !== resolve(articlesRoot, locale)) {
13724
+ return { ok: false, result: failNotSent(`post path escapes ${articlesRoot}`) };
13725
+ }
13726
+ await mintLocalePost({
13727
+ postDir: siblingDir,
13728
+ content: { ...payload.content, title: draft.title, body: draft.body },
13729
+ coverPath: cover,
13730
+ publishDate
13672
13731
  });
13673
- await createNodeFileSystem().writeFile(filePath, markdown);
13674
- } else {
13675
- echoError(`surfdash-pub: keeping existing refined post at ${filePath} (not re-minting)`);
13676
13732
  }
13677
13733
  } catch (err) {
13678
13734
  return {
@@ -222,9 +222,13 @@ export function checkDigestFrontmatter(markdown: string, locale: DigestLocale):
222
222
  } else {
223
223
  const rest = match[2] ?? '';
224
224
  const heads = locale === 'en' ? rest.split(', ') : rest.split('、');
225
- const seps = locale === 'en' ? (rest.match(/, /g) ?? []).length : (rest.match(/、/g) ?? []).length;
226
- if (seps !== 1 || heads.some((head) => head.trim() === '')) {
227
- problems.push(`title: expected exactly two non-empty headlines joined "${listSep}", got "${rest}"`);
225
+ // 1..2, not "exactly 2": the site's `seo retitle` legitimately collapses a title to one
226
+ // headline when two do not fit its SEO budget (surfdash `check-digest.ts`), and that
227
+ // budget verdict is the site's (ADR-008). kk mirrors only the structural range.
228
+ if (heads.length < 1 || heads.length > 2 || heads.some((head) => head.trim() === '')) {
229
+ problems.push(
230
+ `title: expected one or two non-empty headlines joined "${listSep}", got ${heads.length} in "${rest}"`,
231
+ );
228
232
  }
229
233
  }
230
234
  const seoTitle = `${title} | Surfing`;
@@ -97,6 +97,8 @@ interface SurfdashPubOptions {
97
97
  localCover?: unknown;
98
98
  /** `patch`: `YYYY-MM-DD` episode date for the cross-link text. */
99
99
  dateIso?: unknown;
100
+ /** `patch`: the episode's frozen identity title (0385 R4); the zh post's `episode_title`. */
101
+ episodeTitle?: unknown;
100
102
  }
101
103
 
102
104
  /**
@@ -1001,7 +1003,10 @@ async function syncPost(options: SurfdashPubOptions): Promise<Result> {
1001
1003
  }
1002
1004
 
1003
1005
  /** `options.<key>` when it is a string, trimmed; else ''. `patch`'s four optional fields read this way. */
1004
- function strOption(options: SurfdashPubOptions, key: 'coverUrl' | 'showNotesUrl' | 'localCover' | 'dateIso'): string {
1006
+ function strOption(
1007
+ options: SurfdashPubOptions,
1008
+ key: 'coverUrl' | 'showNotesUrl' | 'localCover' | 'dateIso' | 'episodeTitle',
1009
+ ): string {
1005
1010
  const raw = options[key];
1006
1011
  return typeof raw === 'string' ? raw.trim() : '';
1007
1012
  }
@@ -1036,6 +1041,7 @@ async function patchPost(options: SurfdashPubOptions): Promise<Result> {
1036
1041
  showNotesUrl: strOption(options, 'showNotesUrl'),
1037
1042
  localCover: strOption(options, 'localCover'),
1038
1043
  dateIso: strOption(options, 'dateIso'),
1044
+ episodeTitle: strOption(options, 'episodeTitle'),
1039
1045
  });
1040
1046
  } catch (error: unknown) {
1041
1047
  return fail(`patch error: ${error instanceof Error ? error.message : String(error)}`);
@@ -1271,6 +1277,72 @@ function resolvePreparedPost(
1271
1277
 
1272
1278
  type PrepareOutcome = { ok: true; prepared: PreparedPost } | { ok: false; result: Result };
1273
1279
 
1280
+ /** The non-primary locales a digest post carries (`metadata.surfdash.locales`); zh is the primary. */
1281
+ const LOCAL_DRAFTS = ['en', 'ja'] as const;
1282
+
1283
+ /** One localized sibling's authored text, as the workflow's `localize` step delivers it. */
1284
+ interface LocaleDraft {
1285
+ title: string;
1286
+ body: string;
1287
+ }
1288
+
1289
+ /**
1290
+ * Reads `metadata.surfdash.locales.{en,ja}` off the article Content (0409 Q&A: the payload shape the
1291
+ * localize step and the article variant agree on). A blank title or body is not a locale: an
1292
+ * untranslated file must read as missing, so the digest refusal fires instead of publishing zh
1293
+ * text under `/en/` or `/ja/`.
1294
+ */
1295
+ function readLocaleDrafts(content: Content): Partial<Record<(typeof LOCAL_DRAFTS)[number], LocaleDraft>> {
1296
+ const drafts: Partial<Record<(typeof LOCAL_DRAFTS)[number], LocaleDraft>> = {};
1297
+ const surfdash = content.metadata?.surfdash;
1298
+ if (typeof surfdash !== 'object' || surfdash === null) return drafts;
1299
+ const locales = (surfdash as Record<string, unknown>).locales;
1300
+ if (typeof locales !== 'object' || locales === null) return drafts;
1301
+ for (const locale of LOCAL_DRAFTS) {
1302
+ const entry = (locales as Record<string, unknown>)[locale];
1303
+ if (typeof entry !== 'object' || entry === null) continue;
1304
+ const { title, body } = entry as Record<string, unknown>;
1305
+ if (typeof title !== 'string' || title.trim() === '') continue;
1306
+ if (typeof body !== 'string' || body.trim() === '') continue;
1307
+ drafts[locale] = { title, body };
1308
+ }
1309
+ return drafts;
1310
+ }
1311
+
1312
+ /**
1313
+ * Mints one locale's `index.md` (frontmatter + body) and copies the cover into its `assets/`.
1314
+ *
1315
+ * A file the site's own refine step already marked is not ours to clobber: re-minting replaces the
1316
+ * refined frontmatter (`refined`, `seo_title`, …) with generator defaults and flips a published day
1317
+ * back to a draft — so a refined file is kept and reused (2026-11-05 tier-0 rerun).
1318
+ */
1319
+ async function mintLocalePost(options: {
1320
+ postDir: string;
1321
+ content: Content;
1322
+ coverPath?: string;
1323
+ publishDate?: string;
1324
+ }): Promise<void> {
1325
+ const filePath = join(options.postDir, 'index.md');
1326
+ if (readRefinedSnapshot(filePath) !== undefined) {
1327
+ echoError(`surfdash-pub: keeping existing refined post at ${filePath} (not re-minting)`);
1328
+ return;
1329
+ }
1330
+ await createNodeFileSystem().ensureDir(options.postDir);
1331
+ let imageFrontmatter: string | undefined;
1332
+ if (options.coverPath !== undefined) {
1333
+ const assetsDir = join(options.postDir, 'assets');
1334
+ await createNodeFileSystem().ensureDir(assetsDir);
1335
+ const coverName = `cover${extname(options.coverPath).toLowerCase()}`;
1336
+ await copyFile(options.coverPath, join(assetsDir, coverName));
1337
+ imageFrontmatter = `./assets/${coverName}`;
1338
+ }
1339
+ const markdown = mapContentToSurfingMarkdown(options.content, {
1340
+ image: imageFrontmatter,
1341
+ publishDate: options.publishDate,
1342
+ });
1343
+ await createNodeFileSystem().writeFile(filePath, markdown);
1344
+ }
1345
+
1274
1346
  /**
1275
1347
  * Materializes the local post without invoking the external publishing FSM.
1276
1348
  *
@@ -1328,31 +1400,48 @@ async function preparePost(payload: PublishTransportPayload): Promise<PrepareOut
1328
1400
  return { ok: false, result: failNotSent('digest post has no cover image (metadata.coverImage)') };
1329
1401
  }
1330
1402
 
1403
+ // 0409 R2: the site requires the full locale set for a digest before it will sync
1404
+ // (`publish-orchestrator.ts` `discoverLocaleFiles` + the `sub-category:ai-daily` guard), so a
1405
+ // missing translation is refused here with effect none — never as the site's opaque
1406
+ // "missing locale file(s)" failure after the spawn.
1407
+ const drafts = readLocaleDrafts(payload.content);
1408
+ if (isDigestContent(payload.content)) {
1409
+ const missing = LOCAL_DRAFTS.filter((locale) => drafts[locale] === undefined);
1410
+ if (missing.length > 0) {
1411
+ return {
1412
+ ok: false,
1413
+ result: failNotSent(
1414
+ `digest post is missing metadata.surfdash.locales for ${missing.join(', ')} — the site refuses a digest with a missing locale file; re-run the localize step before publishing`,
1415
+ ),
1416
+ };
1417
+ }
1418
+ }
1419
+
1331
1420
  const filePath = join(postDir, 'index.md');
1421
+ const publishDate = runDate ? `${runDate.slice(0, 4)}-${runDate.slice(4, 6)}-${runDate.slice(6, 8)}` : undefined;
1422
+ const cover = typeof coverPath === 'string' ? coverPath : undefined;
1332
1423
  try {
1333
1424
  // A post the site's own refine step already marked is not ours to clobber: re-minting it
1334
1425
  // replaces the refined canonical frontmatter (refine owns `refined`, `seo_title`, …) with
1335
1426
  // generator defaults and flips an already-published day back to a draft. Keep the file and
1336
1427
  // reuse it; only genuinely fresh days (no marker) get minted (2026-11-05 tier-0 rerun).
1337
- if (readRefinedSnapshot(filePath) === undefined) {
1338
- await createNodeFileSystem().ensureDir(postDir);
1339
- let imageFrontmatter: string | undefined;
1340
- if (typeof coverPath === 'string') {
1341
- const assetsDir = join(postDir, 'assets');
1342
- await createNodeFileSystem().ensureDir(assetsDir);
1343
- const coverName = `cover${extname(coverPath).toLowerCase()}`;
1344
- await copyFile(coverPath, join(assetsDir, coverName));
1345
- imageFrontmatter = `./assets/${coverName}`;
1428
+ await mintLocalePost({ postDir, content: payload.content, coverPath: cover, publishDate });
1429
+ for (const locale of LOCAL_DRAFTS) {
1430
+ const draft = drafts[locale];
1431
+ if (draft === undefined) continue;
1432
+ const siblingDir = resolve(articlesRoot, locale, slug);
1433
+ if (dirname(resolve(siblingDir)) !== resolve(articlesRoot, locale)) {
1434
+ return { ok: false, result: failNotSent(`post path escapes ${articlesRoot}`) };
1346
1435
  }
1347
- const markdown = mapContentToSurfingMarkdown(payload.content, {
1348
- image: imageFrontmatter,
1349
- publishDate: runDate
1350
- ? `${runDate.slice(0, 4)}-${runDate.slice(4, 6)}-${runDate.slice(6, 8)}`
1351
- : undefined,
1436
+ // The zh Body and title are replaced by the translation; the frontmatter fields the
1437
+ // site owns (refined, seo_title, …) are rewritten by its own refine/retitle, exactly as
1438
+ // for zh — so a locale file is the same Content shape with a localized title/body.
1439
+ await mintLocalePost({
1440
+ postDir: siblingDir,
1441
+ content: { ...payload.content, title: draft.title, body: draft.body },
1442
+ coverPath: cover,
1443
+ publishDate,
1352
1444
  });
1353
- await createNodeFileSystem().writeFile(filePath, markdown);
1354
- } else {
1355
- echoError(`surfdash-pub: keeping existing refined post at ${filePath} (not re-minting)`);
1356
1445
  }
1357
1446
  } catch (err: unknown) {
1358
1447
  return {
@@ -30,6 +30,13 @@ export interface PatchPostRequest {
30
30
  localCover: string;
31
31
  /** `YYYY-MM-DD` episode date used in the cross-link text. */
32
32
  dateIso: string;
33
+ /**
34
+ * The episode's frozen identity title (0385 R4), e.g. `第261120期 · Anthropic 上市,估值口径成为焦点`.
35
+ * Written to the zh post's `episode_title` frontmatter and used for the zh cross-link text, so the
36
+ * article states the same episode identity the podcast ships. Empty → the older series · date
37
+ * wording, which is what pre-0385 bundles carry.
38
+ */
39
+ episodeTitle?: string;
33
40
  }
34
41
 
35
42
  /** What the file pass changed; the caller commits exactly {@link PatchPostOutcome.written}. */
@@ -71,10 +78,16 @@ export const SERIES_NAMES: Record<PatchLocale, string> = {
71
78
  ja: 'デイリーAIシチュー',
72
79
  };
73
80
 
74
- export function crossLinkFor(locale: PatchLocale, dateIso: string, showNotesUrl: string): string {
81
+ export function crossLinkFor(locale: PatchLocale, dateIso: string, showNotesUrl: string, episodeTitle = ''): string {
75
82
  const series = SERIES_NAMES[locale];
83
+ // The zh episode's frozen identity (0385) rides after the link, never inside the anchor: the site's
84
+ // `listen-link-series-name` gate requires the anchor text to name the canonical series and nothing
85
+ // else series-like. en/ja have no localized identity, so they keep the series · date wording.
76
86
  const links: Record<PatchLocale, string> = {
77
- zh: `🎧 本期已同步制作为播客节目,[点击收听《${series} · ${dateIso}》](${showNotesUrl})。`,
87
+ zh:
88
+ episodeTitle !== ''
89
+ ? `🎧 本期已同步制作为播客节目,[点击收听《${series} · ${dateIso}》](${showNotesUrl}):${episodeTitle}。`
90
+ : `🎧 本期已同步制作为播客节目,[点击收听《${series} · ${dateIso}》](${showNotesUrl})。`,
78
91
  en: `🎧 This episode is also available as a podcast: [listen to ${series} · ${dateIso}](${showNotesUrl}).`,
79
92
  ja: `🎧 本エピソードはポッドキャストでも配信中:[${series} · ${dateIso} を聴く](${showNotesUrl})。`,
80
93
  };
@@ -153,12 +166,17 @@ export async function patchPostFiles(request: PatchPostRequest): Promise<PatchPo
153
166
  md = upsertFrontmatterKey(md, 'og_image', './assets/cover.png');
154
167
  images[locale] = './assets/cover.png';
155
168
  }
169
+ if (locale === 'zh' && (request.episodeTitle ?? '') !== '') {
170
+ // The article states the episode identity the podcast ships (0385). The site renders it
171
+ // under the H1; its SEO title stays the digest shape, so this is additive, not a rename.
172
+ md = upsertFrontmatterKey(md, 'episode_title', request.episodeTitle as string);
173
+ }
156
174
  if (request.showNotesUrl !== '') {
157
175
  // 2026-10-23: a previous run may have left a 🎧 cross-link line carrying a retired
158
176
  // series name — refresh that line in place instead of keeping it forever (the URL it
159
177
  // carries made a fresh append a no-op). A non-cross-link line mentioning the URL is
160
178
  // left alone; the fresh link is only appended when no line carries the URL at all.
161
- const link = crossLinkFor(locale, request.dateIso, request.showNotesUrl);
179
+ const link = crossLinkFor(locale, request.dateIso, request.showNotesUrl, request.episodeTitle ?? '');
162
180
  const lines = md.split('\n');
163
181
  const carriesUrl = lines.some((line) => line.includes(request.showNotesUrl));
164
182
  if (!carriesUrl) {
@@ -68,7 +68,9 @@ function parseTitleHeadlines(title: string, locale: PatchLocale): string[] | und
68
68
  const match = title.match(new RegExp(`^${escapeRe(series)} · (\\d{4}-\\d{2}-\\d{2})${escapeRe(titleSep)}(.+)$`));
69
69
  if (!match?.[2]) return undefined;
70
70
  const heads = match[2].split(listSep).map((head) => head.trim());
71
- if (heads.length < 2 || heads.some((head) => head === '')) return undefined;
71
+ // 1..2 structural headlines: the site may collapse a title to one when two do not fit its
72
+ // SEO budget, so a single headline is a valid derivation source (task 0408).
73
+ if (heads.length < 1 || heads.length > 2 || heads.some((head) => head === '')) return undefined;
72
74
  return heads;
73
75
  }
74
76
 
@@ -20778,6 +20778,9 @@ async function ensureProfileDir2(profileDir, headless) {
20778
20778
  var MAX_QUEUED_BYTES = 8 * 1024 * 1024;
20779
20779
  // ../../packages/publish-harness/src/browser.ts
20780
20780
  var DEFAULT_CHECK_TIMEOUT_MS = 30000;
20781
+ var VERDICT_PRINT_MARGIN_MS = 2000;
20782
+ var MIN_PASS_BUDGET_MS = 5000;
20783
+ var PASS_LAUNCH_RESERVE_MS = 20000;
20781
20784
  var DEFAULT_STEP_TIMEOUT_MS = 30000;
20782
20785
  var DEFAULT_POLL_MS = 500;
20783
20786
  var ATTACH_POLL_MS = 100;
@@ -20902,14 +20905,21 @@ async function checkChannelSession(config, opts) {
20902
20905
  const timeoutMs = opts.timeoutMs ?? DEFAULT_CHECK_TIMEOUT_MS;
20903
20906
  const passes = opts.headedOnly ? [false] : opts.headedFallback === false ? [true] : [true, false];
20904
20907
  let lastDetail = `${config.channel} readiness was never probed`;
20908
+ const deadline = Date.now() + timeoutMs;
20909
+ const printMarginMs = Math.min(VERDICT_PRINT_MARGIN_MS, Math.floor(timeoutMs / 4));
20910
+ const minPassMs = Math.min(MIN_PASS_BUDGET_MS, Math.floor(timeoutMs / 3));
20911
+ const launchReserveMs = Math.min(PASS_LAUNCH_RESERVE_MS, Math.floor(timeoutMs / 3));
20905
20912
  for (const headless of passes) {
20913
+ const remainingMs = deadline - Date.now() - printMarginMs - launchReserveMs;
20914
+ if (remainingMs < minPassMs)
20915
+ break;
20906
20916
  try {
20907
20917
  await withProfilePage({
20908
20918
  profileDir: opts.profileDir,
20909
20919
  headless,
20910
20920
  url: config.homeUrl,
20911
20921
  isAuthenticated: config.isAuthenticated,
20912
- timeoutMs,
20922
+ timeoutMs: remainingMs,
20913
20923
  launcher: opts.launcher ?? kkBrowserLauncher
20914
20924
  }, async () => true);
20915
20925
  return {
@@ -21004,7 +21014,13 @@ var THREADS_POST_SELECTORS = {
21004
21014
  'div[aria-label^="Empty text field"]',
21005
21015
  'div[role="textbox"][contenteditable="true"]'
21006
21016
  ],
21007
- submit: ['div[role="button"]:text-is("Post"):visible', 'button:text-is("Post"):visible'],
21017
+ submit: [
21018
+ 'div[role="button"]:has(> div:text-is("Post")):visible',
21019
+ 'div[role="button"]:has(div:text-is("Post")):visible',
21020
+ 'div[role="button"]:text-is("Post"):visible',
21021
+ 'button:text-is("Post"):visible',
21022
+ 'div[role="button"][aria-label="Post"]:visible'
21023
+ ],
21008
21024
  mediaButton: ['div[role="button"]:text-is("Attach media")', 'div[aria-label*="Attach media" i]'],
21009
21025
  fileInput: ['input[type="file"]'],
21010
21026
  mediaPreview: ['div[role="dialog"] img[src*="cdninstagram"], div[role="dialog"] img[src*="fbcdn"]'],
@@ -21142,7 +21158,7 @@ class ThreadsPostBrowserTransport {
21142
21158
  await page.keyboard.type(text, { delay: 12 });
21143
21159
  await evidence(page, "04-typed");
21144
21160
  const readback = await expectOutcome(async () => {
21145
- const value = String(await editor.evaluate(`(() => { const el = arguments[0]; return (el.innerText || el.textContent || el.value || ''); })()`).catch(() => ""));
21161
+ const value = String(await editor.evaluate(`(el) => (el.innerText || el.textContent || el.value || '')`).catch(() => ""));
21146
21162
  return value.trim().length > 0 ? "text retained" : null;
21147
21163
  }, { timeoutMs: this.stepTimeoutMs, label: "threads post readback" });
21148
21164
  if (!readback.ok) {
@@ -21162,12 +21178,48 @@ class ThreadsPostBrowserTransport {
21162
21178
  }
21163
21179
  }
21164
21180
  const submit = await expectOutcome(async () => {
21181
+ const roleEngine = page;
21182
+ const byRole = roleEngine.getByRole?.("button", { name: "Post", exact: true });
21183
+ const roleCount = byRole === undefined ? 0 : await byRole.count().catch(() => 0);
21184
+ if (roleCount > 0)
21185
+ return `role:Post:${roleCount}`;
21165
21186
  const found = await trySelectors(page, THREADS_POST_SELECTORS.submit);
21166
21187
  return found.found ? found.selector ?? THREADS_POST_SELECTORS.submit[0] : null;
21167
21188
  }, { timeoutMs: this.stepTimeoutMs, label: "threads post submit" });
21168
- if (!submit.ok)
21169
- return fail(`threads post control never attached: ${submit.error}`);
21170
- await page.locator(submit.evidence).first().click();
21189
+ if (!submit.ok) {
21190
+ await evidence(page, "06-submit-missing");
21191
+ const observable = page;
21192
+ const inventory = await (observable.evaluate === undefined ? Promise.resolve(null) : observable.evaluate(`(() => {
21193
+ // Search the WHOLE document, not one dialog: the composer may not be the first
21194
+ // [role=dialog] in DOM order (which is why an earlier inventory listed the
21195
+ // composer's chips but not its Post control), and Post may carry no role at all.
21196
+ const hits = [...document.querySelectorAll('*')]
21197
+ .filter((n) => n.children.length === 0 && (n.textContent || '').trim() === 'Post')
21198
+ .map((n) => {
21199
+ const p = n.parentElement;
21200
+ return n.tagName + (n.getAttribute('role') ? '[role=' + n.getAttribute('role') + ']' : '')
21201
+ + (n.getAttribute('aria-label') ? '[aria=' + n.getAttribute('aria-label') + ']' : '')
21202
+ + ' < ' + (p?.tagName ?? '') + (p?.getAttribute('role') ? '[role=' + p.getAttribute('role') + ']' : '')
21203
+ + (p?.className ? '.' + String(p.className).split(/\\s+/).slice(0, 2).join('.') : '');
21204
+ });
21205
+ return hits.slice(0, 4).join(' | ') || 'no element whose text is exactly Post';
21206
+ })()`).catch(() => null));
21207
+ return fail(`threads post control never attached: ${submit.error}${inventory ? ` (dialog buttons: ${String(inventory)})` : ""}`);
21208
+ }
21209
+ const dismiss = await page.locator('div[role="button"]:text-is("Dismiss suggestions"), div[role="button"]:has(> div:text-is("Dismiss suggestions"))').first().click({ timeout: 3000 }).then(() => true).catch(() => false);
21210
+ if (dismiss)
21211
+ await page.waitForTimeout(500);
21212
+ const submitEvidence = String(submit.evidence);
21213
+ if (submitEvidence.startsWith("role:Post:")) {
21214
+ const rolePost = page.getByRole("button", { name: "Post", exact: true });
21215
+ await rolePost.last().click({ timeout: this.stepTimeoutMs });
21216
+ } else {
21217
+ await page.locator(submitEvidence).first().click({ timeout: this.stepTimeoutMs }).catch(async () => {
21218
+ await page.locator(submitEvidence).first().click({ force: true });
21219
+ });
21220
+ }
21221
+ await page.waitForTimeout(2500);
21222
+ await evidence(page, "07-post-clicked");
21171
21223
  const receipt = await expectOutcome(async () => {
21172
21224
  const id = await this.newestPostId(page, handle);
21173
21225
  if (id === null)
@@ -20482,6 +20482,9 @@ var MAX_QUEUED_BYTES = 8 * 1024 * 1024;
20482
20482
  var DEFAULT_LOGIN_TIMEOUT_MS = 180000;
20483
20483
  var DEFAULT_OPEN_NAV_TIMEOUT_MS = 30000;
20484
20484
  var DEFAULT_CHECK_TIMEOUT_MS = 30000;
20485
+ var VERDICT_PRINT_MARGIN_MS = 2000;
20486
+ var MIN_PASS_BUDGET_MS = 5000;
20487
+ var PASS_LAUNCH_RESERVE_MS = 20000;
20485
20488
  var DEFAULT_POLL_MS = 500;
20486
20489
  function isInstantBrowserDeath(message) {
20487
20490
  return /target page, context or browser has been closed|browser has been closed|target closed/i.test(message);
@@ -20604,14 +20607,21 @@ async function checkChannelSession(config, opts) {
20604
20607
  const timeoutMs = opts.timeoutMs ?? DEFAULT_CHECK_TIMEOUT_MS;
20605
20608
  const passes = opts.headedOnly ? [false] : opts.headedFallback === false ? [true] : [true, false];
20606
20609
  let lastDetail = `${config.channel} readiness was never probed`;
20610
+ const deadline = Date.now() + timeoutMs;
20611
+ const printMarginMs = Math.min(VERDICT_PRINT_MARGIN_MS, Math.floor(timeoutMs / 4));
20612
+ const minPassMs = Math.min(MIN_PASS_BUDGET_MS, Math.floor(timeoutMs / 3));
20613
+ const launchReserveMs = Math.min(PASS_LAUNCH_RESERVE_MS, Math.floor(timeoutMs / 3));
20607
20614
  for (const headless of passes) {
20615
+ const remainingMs = deadline - Date.now() - printMarginMs - launchReserveMs;
20616
+ if (remainingMs < minPassMs)
20617
+ break;
20608
20618
  try {
20609
20619
  await withProfilePage({
20610
20620
  profileDir: opts.profileDir,
20611
20621
  headless,
20612
20622
  url: config.homeUrl,
20613
20623
  isAuthenticated: config.isAuthenticated,
20614
- timeoutMs,
20624
+ timeoutMs: remainingMs,
20615
20625
  launcher: opts.launcher ?? kkBrowserLauncher
20616
20626
  }, async () => true);
20617
20627
  return {
@@ -21113,7 +21123,13 @@ var THREADS_POST_SELECTORS = {
21113
21123
  'div[aria-label^="Empty text field"]',
21114
21124
  'div[role="textbox"][contenteditable="true"]'
21115
21125
  ],
21116
- submit: ['div[role="button"]:text-is("Post"):visible', 'button:text-is("Post"):visible'],
21126
+ submit: [
21127
+ 'div[role="button"]:has(> div:text-is("Post")):visible',
21128
+ 'div[role="button"]:has(div:text-is("Post")):visible',
21129
+ 'div[role="button"]:text-is("Post"):visible',
21130
+ 'button:text-is("Post"):visible',
21131
+ 'div[role="button"][aria-label="Post"]:visible'
21132
+ ],
21117
21133
  mediaButton: ['div[role="button"]:text-is("Attach media")', 'div[aria-label*="Attach media" i]'],
21118
21134
  fileInput: ['input[type="file"]'],
21119
21135
  mediaPreview: ['div[role="dialog"] img[src*="cdninstagram"], div[role="dialog"] img[src*="fbcdn"]'],