@gobing-ai/knowledge-kit 0.1.23 → 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 (84) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/dist/index.js +117 -56
  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 +9 -9
  11. package/plugins/generations/image-gen/dist/index.js +9 -9
  12. package/plugins/generations/music-gen/dist/index.js +16 -16
  13. package/plugins/generations/news-report-gen/dist/index.js +12 -12
  14. package/plugins/generations/vibe-voice-tts/dist/index.js +9 -9
  15. package/plugins/generations/voice-gen/dist/index.js +9 -9
  16. package/plugins/generations/voxcpm-tts/dist/index.js +9 -9
  17. package/plugins/ingestions/aihot-ingest/dist/index.js +12 -12
  18. package/plugins/ingestions/horizon-ingest/dist/index.js +12 -12
  19. package/plugins/ingestions/karakeep-local/dist/index.js +13 -13
  20. package/plugins/ingestions/last30days-ingest/dist/index.js +12 -12
  21. package/plugins/ingestions/web-search/dist/index.js +10 -10
  22. package/plugins/kk/plugin.json +1 -1
  23. package/plugins/kk/publish-presets/daily-ai-voice.json +16 -16
  24. package/plugins/kk/scripts/cover-compositor.ts +104 -26
  25. package/plugins/kk/scripts/daily-stages.ts +217 -33
  26. package/plugins/kk/scripts/kk-workflow-stages.ts +144 -6
  27. package/plugins/kk/scripts/series-names.ts +16 -3
  28. package/plugins/kk/skills/news-editorial/SKILL.md +1 -1
  29. package/plugins/kk/skills/news-editorial/references/style-contract.zh.md +3 -3
  30. package/plugins/kk/workflows/kk-news-generate.yaml +3 -0
  31. package/plugins/publishings/bilibili-pub/dist/index.js +22 -22
  32. package/plugins/publishings/bilibili-pub/dist/profile-check.js +22 -22
  33. package/plugins/publishings/cnblogs-pub/dist/index.js +22 -22
  34. package/plugins/publishings/cnblogs-pub/dist/profile-check.js +22 -22
  35. package/plugins/publishings/csdn-pub/dist/index.js +22 -22
  36. package/plugins/publishings/csdn-pub/dist/profile-check.js +22 -22
  37. package/plugins/publishings/emdash-pub/dist/index.js +9 -9
  38. package/plugins/publishings/infoq-pub/dist/index.js +22 -22
  39. package/plugins/publishings/infoq-pub/dist/profile-check.js +22 -22
  40. package/plugins/publishings/jike-pub/dist/index.js +22 -22
  41. package/plugins/publishings/jike-pub/dist/profile-check.js +22 -22
  42. package/plugins/publishings/juejin-pub/dist/index.js +22 -22
  43. package/plugins/publishings/juejin-pub/dist/profile-check.js +22 -22
  44. package/plugins/publishings/linkedin-pub/dist/index.js +82 -24
  45. package/plugins/publishings/linkedin-pub/dist/profile-check.js +22 -22
  46. package/plugins/publishings/linkedin-pub/src/index.ts +93 -6
  47. package/plugins/publishings/medium-pub/dist/index.js +9 -9
  48. package/plugins/publishings/podcast-pub/dist/index.js +240 -37
  49. package/plugins/publishings/podcast-pub/src/index.ts +154 -3
  50. package/plugins/publishings/podcast-pub/src/seo.ts +25 -8
  51. package/plugins/publishings/podcast-pub/src/show-notes-brief.ts +93 -23
  52. package/plugins/publishings/podcast-pub/src/show-notes.ts +26 -6
  53. package/plugins/publishings/qiita-pub/dist/index.js +9 -9
  54. package/plugins/publishings/shipinhao-pub/dist/index.js +23 -23
  55. package/plugins/publishings/shipinhao-pub/dist/profile-check.js +23 -23
  56. package/plugins/publishings/shipinhao-pub/src/selectors.ts +2 -1
  57. package/plugins/publishings/sspai-pub/dist/index.js +22 -22
  58. package/plugins/publishings/sspai-pub/dist/profile-check.js +22 -22
  59. package/plugins/publishings/substack-pub/dist/index.js +22 -22
  60. package/plugins/publishings/substack-pub/dist/profile-check.js +22 -22
  61. package/plugins/publishings/surfdash-pub/dist/index.js +200 -92
  62. package/plugins/publishings/surfdash-pub/src/digest-check.ts +30 -1
  63. package/plugins/publishings/surfdash-pub/src/index.ts +94 -75
  64. package/plugins/publishings/surfdash-pub/src/media-upload.ts +83 -0
  65. package/plugins/publishings/surfdash-pub/src/patch.ts +28 -23
  66. package/plugins/publishings/surfdash-pub/src/topic-claims.ts +12 -4
  67. package/plugins/publishings/threads-pub/dist/index.js +36 -22
  68. package/plugins/publishings/threads-pub/dist/profile-check.js +27 -22
  69. package/plugins/publishings/threads-pub/src/post-rail.ts +20 -0
  70. package/plugins/publishings/wechatmp-pub/dist/index.js +180 -64
  71. package/plugins/publishings/wechatmp-pub/dist/profile-check.js +27 -23
  72. package/plugins/publishings/wechatmp-pub/src/enrich.ts +56 -10
  73. package/plugins/publishings/wechatmp-pub/src/flow.ts +155 -43
  74. package/plugins/publishings/wechatmp-pub/src/modes.ts +30 -12
  75. package/plugins/publishings/weibo-pub/dist/index.js +22 -22
  76. package/plugins/publishings/weibo-pub/dist/profile-check.js +22 -22
  77. package/plugins/publishings/x-pub/dist/index.js +51 -45
  78. package/plugins/publishings/x-pub/dist/profile-check.js +22 -22
  79. package/plugins/publishings/x-pub/src/post-rail.ts +40 -47
  80. package/plugins/publishings/xhs-pub/dist/index.js +22 -22
  81. package/plugins/publishings/xhs-pub/dist/profile-check.js +22 -22
  82. package/plugins/publishings/xiaoyuzhou-pub/dist/index.js +22 -22
  83. package/plugins/publishings/xiaoyuzhou-pub/dist/profile-check.js +22 -22
  84. package/plugins/publishings/zenn-pub/dist/index.js +9 -9
@@ -4850,7 +4850,7 @@ var init_zod = __esm(() => {
4850
4850
  init_external();
4851
4851
  });
4852
4852
 
4853
- // ../../node_modules/.bun/@gobing-ai+ts-utils@0.5.32/node_modules/@gobing-ai/ts-utils/dist/errors.js
4853
+ // ../../node_modules/.bun/@gobing-ai+ts-utils@0.8.4/node_modules/@gobing-ai/ts-utils/dist/errors.js
4854
4854
  var ErrorCode;
4855
4855
  var init_errors3 = __esm(() => {
4856
4856
  ErrorCode = {
@@ -4861,7 +4861,7 @@ var init_errors3 = __esm(() => {
4861
4861
  };
4862
4862
  });
4863
4863
 
4864
- // ../../node_modules/.bun/@gobing-ai+ts-utils@0.5.32/node_modules/@gobing-ai/ts-utils/dist/api-response.js
4864
+ // ../../node_modules/.bun/@gobing-ai+ts-utils@0.8.4/node_modules/@gobing-ai/ts-utils/dist/api-response.js
4865
4865
  var API_ERROR_CODES, ERROR_CODE_TO_HTTP, CLIENT_SAFE_CODES;
4866
4866
  var init_api_response = __esm(() => {
4867
4867
  init_errors3();
@@ -4884,13 +4884,13 @@ var init_api_response = __esm(() => {
4884
4884
  CLIENT_SAFE_CODES = new Set([ErrorCode.NotFound, ErrorCode.Validation, ErrorCode.Conflict]);
4885
4885
  });
4886
4886
 
4887
- // ../../node_modules/.bun/@gobing-ai+ts-utils@0.5.32/node_modules/@gobing-ai/ts-utils/dist/cursor.js
4887
+ // ../../node_modules/.bun/@gobing-ai+ts-utils@0.8.4/node_modules/@gobing-ai/ts-utils/dist/cursor.js
4888
4888
  var init_cursor = () => {};
4889
4889
 
4890
- // ../../node_modules/.bun/@gobing-ai+ts-utils@0.5.32/node_modules/@gobing-ai/ts-utils/dist/event-severity.js
4890
+ // ../../node_modules/.bun/@gobing-ai+ts-utils@0.8.4/node_modules/@gobing-ai/ts-utils/dist/event-severity.js
4891
4891
  var init_event_severity = () => {};
4892
4892
 
4893
- // ../../node_modules/.bun/@gobing-ai+ts-utils@0.5.32/node_modules/@gobing-ai/ts-utils/dist/output.js
4893
+ // ../../node_modules/.bun/@gobing-ai+ts-utils@0.8.4/node_modules/@gobing-ai/ts-utils/dist/output.js
4894
4894
  function processStream(name) {
4895
4895
  const proc = globalThis.process;
4896
4896
  const stream = proc?.[name];
@@ -4908,7 +4908,7 @@ function echoError(message, target = defaultStderrTarget ?? processStream("stder
4908
4908
  }
4909
4909
  var defaultStderrTarget;
4910
4910
 
4911
- // ../../node_modules/.bun/@gobing-ai+ts-utils@0.5.32/node_modules/@gobing-ai/ts-utils/dist/index.js
4911
+ // ../../node_modules/.bun/@gobing-ai+ts-utils@0.8.4/node_modules/@gobing-ai/ts-utils/dist/index.js
4912
4912
  var init_dist = __esm(() => {
4913
4913
  init_api_response();
4914
4914
  init_cursor();
@@ -11906,7 +11906,7 @@ var init_dist2 = __esm(() => {
11906
11906
  $visitAsync = visit.visitAsync;
11907
11907
  });
11908
11908
 
11909
- // ../../node_modules/.bun/@gobing-ai+ts-runtime@0.5.32+180a6e424da77181/node_modules/@gobing-ai/ts-runtime/dist/config.js
11909
+ // ../../node_modules/.bun/@gobing-ai+ts-runtime@0.8.4+b85a65bb895e3074/node_modules/@gobing-ai/ts-runtime/dist/config.js
11910
11910
  var configSchema;
11911
11911
  var init_config = __esm(() => {
11912
11912
  init_dist2();
@@ -11930,7 +11930,7 @@ var init_config = __esm(() => {
11930
11930
  });
11931
11931
  });
11932
11932
 
11933
- // ../../node_modules/.bun/@gobing-ai+ts-runtime@0.5.32+180a6e424da77181/node_modules/@gobing-ai/ts-runtime/dist/file-system-node.js
11933
+ // ../../node_modules/.bun/@gobing-ai+ts-runtime@0.8.4+b85a65bb895e3074/node_modules/@gobing-ai/ts-runtime/dist/file-system-node.js
11934
11934
  import { appendFileSync, cpSync, createReadStream, createWriteStream, existsSync, mkdirSync, readdirSync, readFileSync, realpathSync, renameSync, rmSync, statSync, writeFileSync } from "fs";
11935
11935
  import { dirname, resolve as resolvePath } from "path";
11936
11936
  function createNodeFileSystem(root, paths) {
@@ -12072,8 +12072,8 @@ var init_src = () => {};
12072
12072
  // ../../plugins/publishings/surfdash-pub/src/index.ts
12073
12073
  import { createHash } from "crypto";
12074
12074
  import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
12075
- import { copyFile, cp, writeFile } from "fs/promises";
12076
- import { dirname as dirname4, extname, isAbsolute, join as join2, relative, resolve, sep as sep2 } from "path";
12075
+ import { writeFile } from "fs/promises";
12076
+ import { basename as basename3, dirname as dirname4, extname as extname2, isAbsolute, join, relative, resolve, sep as sep2 } from "path";
12077
12077
  import { parseArgs } from "util";
12078
12078
 
12079
12079
  // ../../packages/kk-core/src/content-limits.ts
@@ -12340,7 +12340,7 @@ var PluginManifestSchema = PluginManifestSchemaBase.superRefine((manifest, ctx)
12340
12340
  });
12341
12341
  }
12342
12342
  });
12343
- // ../../node_modules/.bun/@gobing-ai+ts-runtime@0.5.32+180a6e424da77181/node_modules/@gobing-ai/ts-runtime/dist/index.js
12343
+ // ../../node_modules/.bun/@gobing-ai+ts-runtime@0.8.4+b85a65bb895e3074/node_modules/@gobing-ai/ts-runtime/dist/index.js
12344
12344
  init_file_system_node();
12345
12345
  init_config();
12346
12346
 
@@ -12354,7 +12354,7 @@ var ATTACHED_CLOSERS = new Set(["\u201D", "\u2019", "\u300D", "\u300F", "\uFF09"
12354
12354
  init_dist();
12355
12355
 
12356
12356
  // ../../plugins/publishings/surfdash-pub/src/patch.ts
12357
- import { basename, dirname as dirname2, join, sep } from "path";
12357
+ import { basename, dirname as dirname2, sep } from "path";
12358
12358
  var PATCH_LOCALES = ["zh", "en", "ja"];
12359
12359
  function localeIndexPath(postPath, locale) {
12360
12360
  if (locale === "zh")
@@ -12401,17 +12401,18 @@ async function patchPostFiles(request) {
12401
12401
  const absent = [];
12402
12402
  const images = {};
12403
12403
  let changed = 0;
12404
+ let uploadedFallbackCover;
12404
12405
  for (const locale of PATCH_LOCALES) {
12405
12406
  const indexMd = localeIndexPath(request.postPath, locale);
12406
12407
  if (indexMd === undefined || !await fs.exists(indexMd)) {
12407
12408
  absent.push(locale);
12408
12409
  continue;
12409
12410
  }
12410
- const dir = dirname2(indexMd);
12411
12411
  const before = await fs.readFile(indexMd);
12412
12412
  let md = before;
12413
12413
  const end = frontmatterEnd(md);
12414
12414
  const fm = end < 0 ? md : md.slice(0, end);
12415
+ const existingImage = /^image:\s*['"]?([^'"\n]+)['"]?/m.exec(fm)?.[1]?.trim() ?? "";
12415
12416
  if (request.coverUrl !== "") {
12416
12417
  if (!/^https:\/\//.test(request.coverUrl)) {
12417
12418
  throw new Error(`coverUrl must be an absolute https:// URL, got: ${request.coverUrl}`);
@@ -12419,17 +12420,22 @@ async function patchPostFiles(request) {
12419
12420
  md = upsertFrontmatterKey(md, "image", request.coverUrl);
12420
12421
  md = upsertFrontmatterKey(md, "og_image", request.coverUrl);
12421
12422
  images[locale] = request.coverUrl;
12422
- } else if (!/^image:/m.test(fm)) {
12423
- if (!await fs.exists(request.localCover)) {
12424
- throw new Error(`${locale} post has no cover: coverUrl is empty, the frontmatter has no image key, and localCover does not exist (${request.localCover})`);
12425
- }
12426
- const asset = join(dir, "assets", "cover.png");
12427
- await fs.ensureDir(dirname2(asset));
12428
- await fs.copy(request.localCover, asset);
12429
- written.push(asset);
12430
- md = upsertFrontmatterKey(md, "image", "./assets/cover.png");
12431
- md = upsertFrontmatterKey(md, "og_image", "./assets/cover.png");
12432
- images[locale] = "./assets/cover.png";
12423
+ } else if (/^https:\/\//.test(existingImage)) {
12424
+ md = upsertFrontmatterKey(md, "og_image", existingImage);
12425
+ images[locale] = existingImage;
12426
+ } else if (request.uploadLocalCover !== undefined && request.localCover !== "" && await fs.exists(request.localCover)) {
12427
+ if (uploadedFallbackCover === undefined) {
12428
+ const uploaded = await request.uploadLocalCover(request.localCover);
12429
+ if (!/^https:\/\//.test(uploaded)) {
12430
+ throw new Error(`uploaded cover must be an absolute https:// URL, got: ${uploaded}`);
12431
+ }
12432
+ uploadedFallbackCover = uploaded;
12433
+ }
12434
+ md = upsertFrontmatterKey(md, "image", uploadedFallbackCover);
12435
+ md = upsertFrontmatterKey(md, "og_image", uploadedFallbackCover);
12436
+ images[locale] = uploadedFallbackCover;
12437
+ } else {
12438
+ throw new Error(`${locale} post has no remote https:// cover: coverUrl is empty and frontmatter has no https:// image key`);
12433
12439
  }
12434
12440
  if (locale === "zh" && (request.episodeTitle ?? "") !== "") {
12435
12441
  md = upsertFrontmatterKey(md, "episode_title", request.episodeTitle);
@@ -12452,10 +12458,6 @@ ${link}
12452
12458
  if (md !== before) {
12453
12459
  await fs.writeFile(indexMd, md);
12454
12460
  written.push(indexMd);
12455
- const assetsDir = join(dir, "assets");
12456
- if (await fs.exists(assetsDir) && !written.includes(join(assetsDir, "cover.png"))) {
12457
- written.push(assetsDir);
12458
- }
12459
12461
  changed += 1;
12460
12462
  }
12461
12463
  }
@@ -12466,6 +12468,20 @@ ${link}
12466
12468
  var DIGEST_TAG = "sub-category:ai-daily";
12467
12469
  var PODCAST_INTROS = ["\u8FD9\u91CC\u662F\u7531Robin", "\u54B8\u8BDD\u54B8\u8BF4", "This is Robin", "Robin \u304C\u304A\u5C4A\u3051"];
12468
12470
  var SEO_TITLE_LIMIT = 60;
12471
+ var EPISODE_TITLE_MAX = 80;
12472
+ var EPISODE_IDENTITY_TITLE_RE = {
12473
+ zh: /^\u7B2C\d{6}\u671F\s*\u00B7\s*\S/u,
12474
+ en: /^Issue\s+\d{6}\s*\u00B7\s*\S/iu,
12475
+ ja: /^\u7B2C\d{6}\u56DE\s*\u00B7\s*\S/u
12476
+ };
12477
+ function isEpisodeIdentityTitle(title, locale) {
12478
+ const clean = title.trim();
12479
+ if (clean === "")
12480
+ return false;
12481
+ if (locale !== undefined)
12482
+ return EPISODE_IDENTITY_TITLE_RE[locale].test(clean);
12483
+ return Object.values(EPISODE_IDENTITY_TITLE_RE).some((re) => re.test(clean));
12484
+ }
12469
12485
  var KEY_LINE = /^([A-Za-z_][A-Za-z0-9_-]*):(.*)$/;
12470
12486
  var BLOCK_SCALAR = /^[>|][+-]?$/;
12471
12487
  var escapeRe = (token) => token.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
@@ -12605,6 +12621,21 @@ function checkDigestFrontmatter(markdown, locale) {
12605
12621
  const title = scalar(frontmatter, "title");
12606
12622
  if (title === undefined || title === "") {
12607
12623
  problems.push("title: missing");
12624
+ } else if (isEpisodeIdentityTitle(title, locale)) {
12625
+ const titleLength = Array.from(title).length;
12626
+ if (titleLength > EPISODE_TITLE_MAX) {
12627
+ problems.push(`title: ${titleLength} code points (max ${EPISODE_TITLE_MAX})`);
12628
+ }
12629
+ const explicitSeoTitle = scalar(frontmatter, "seo_title");
12630
+ const seoTitle = explicitSeoTitle !== undefined && explicitSeoTitle !== "" ? explicitSeoTitle : `${title} | Surfing`;
12631
+ const seoLength = Array.from(seoTitle).length;
12632
+ if (seoLength > SEO_TITLE_LIMIT) {
12633
+ problems.push(`seo_title: "${seoTitle}" is ${seoLength} code points (max ${SEO_TITLE_LIMIT})`);
12634
+ }
12635
+ if (title.includes("\u2026") || title.includes("..."))
12636
+ problems.push('title: contains "\u2026" or "..."');
12637
+ if (seoTitle.includes("\u2026") || seoTitle.includes("..."))
12638
+ problems.push('seo_title: contains "\u2026" or "..."');
12608
12639
  } else {
12609
12640
  const match = title.match(new RegExp(`^${escapeRe(series)} \xB7 (\\d{4}-\\d{2}-\\d{2})${escapeRe(titleSep)}(.+)$`));
12610
12641
  if (!match) {
@@ -12672,6 +12703,69 @@ function checkDigestFrontmatter(markdown, locale) {
12672
12703
  return problems;
12673
12704
  }
12674
12705
 
12706
+ // ../../plugins/publishings/surfdash-pub/src/media-upload.ts
12707
+ import { basename as basename2, extname } from "path";
12708
+ function contentTypeForImage(filePath) {
12709
+ const ext = extname(filePath).toLowerCase();
12710
+ if (ext === ".jpg" || ext === ".jpeg")
12711
+ return "image/jpeg";
12712
+ if (ext === ".webp")
12713
+ return "image/webp";
12714
+ return "image/png";
12715
+ }
12716
+ async function readErrorBody(res) {
12717
+ try {
12718
+ return (await res.text()).slice(0, 200);
12719
+ } catch {
12720
+ return "";
12721
+ }
12722
+ }
12723
+ async function uploadCoverToMicrofeed(filePath, options = {}) {
12724
+ const baseUrl = (options.baseUrl ?? process.env.MICROFEED_BASE_URL ?? "").trim().replace(/\/$/, "");
12725
+ const apiKey = (options.apiKey ?? process.env.MICROFEED_API_KEY ?? "").trim();
12726
+ if (!baseUrl) {
12727
+ throw new Error("MICROFEED_BASE_URL is required to upload a local cover image to podcast-media");
12728
+ }
12729
+ if (!apiKey) {
12730
+ throw new Error("MICROFEED_API_KEY is required to upload a local cover image to podcast-media");
12731
+ }
12732
+ const mime = contentTypeForImage(filePath);
12733
+ const bytes = await Bun.file(filePath).arrayBuffer();
12734
+ const doFetch = options.fetchImpl ?? fetch;
12735
+ const presignRes = await doFetch(`${baseUrl}/api/v1/media_files/presigned_urls`, {
12736
+ method: "POST",
12737
+ headers: {
12738
+ Authorization: `Bearer ${apiKey}`,
12739
+ Origin: baseUrl,
12740
+ "Content-Type": "application/json"
12741
+ },
12742
+ body: JSON.stringify({
12743
+ category: "image",
12744
+ full_local_file_path: basename2(filePath),
12745
+ size: bytes.byteLength,
12746
+ type: mime
12747
+ })
12748
+ });
12749
+ if (!presignRes.ok) {
12750
+ const body = await readErrorBody(presignRes);
12751
+ throw new Error(`Microfeed cover presign failed (${presignRes.status}): ${body}`);
12752
+ }
12753
+ const { presigned_url, media_url } = await presignRes.json();
12754
+ if (!presigned_url || !media_url || !/^https:\/\//.test(media_url)) {
12755
+ throw new Error(`Microfeed cover presign returned incomplete media_url: ${String(media_url)}`);
12756
+ }
12757
+ const putRes = await doFetch(presigned_url, {
12758
+ method: "PUT",
12759
+ headers: { "Content-Type": mime },
12760
+ body: bytes
12761
+ });
12762
+ if (!putRes.ok) {
12763
+ const body = await readErrorBody(putRes);
12764
+ throw new Error(`Microfeed cover PUT upload failed (${putRes.status}): ${body}`);
12765
+ }
12766
+ return media_url;
12767
+ }
12768
+
12675
12769
  // ../../plugins/publishings/surfdash-pub/src/topic-claims.ts
12676
12770
  import { dirname as dirname3 } from "path";
12677
12771
  var escapeRe2 = (token) => token.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
@@ -12741,8 +12835,9 @@ function buildLocaleEntry(markdown, locale) {
12741
12835
  }
12742
12836
  const frontmatter = parseFrontmatterScalars(markdown);
12743
12837
  const title = scalar2(frontmatter, "title") ?? "";
12744
- const headlines = parseTitleHeadlines(title, locale);
12745
- if (!headlines) {
12838
+ const episodeIdentity = isEpisodeIdentityTitle(title, locale);
12839
+ const parsedHeadlines = episodeIdentity ? undefined : parseTitleHeadlines(title, locale);
12840
+ if (!episodeIdentity && !parsedHeadlines) {
12746
12841
  return `${locale}: title is not "<series> \xB7 YYYY-MM-DD${titleSepFor(locale)}h1${listSepFor(locale)}h2"`;
12747
12842
  }
12748
12843
  const description = (scalar2(frontmatter, "description") ?? scalar2(frontmatter, "seo_description") ?? "").trim();
@@ -12757,7 +12852,11 @@ function buildLocaleEntry(markdown, locale) {
12757
12852
  if (!parts) {
12758
12853
  return `${locale}: key_points must be "label \u2014 sentence"`;
12759
12854
  }
12760
- if (headlines.length > parts.labels.length || headlines.some((headline, i) => headline !== parts.labels[i])) {
12855
+ const headlines = episodeIdentity ? parts.labels.slice(0, 2) : parsedHeadlines ?? [];
12856
+ if (headlines.length === 0) {
12857
+ return `${locale}: key_points has no labels to derive headlines`;
12858
+ }
12859
+ if (!episodeIdentity && (headlines.length > parts.labels.length || headlines.some((headline, i) => headline !== parts.labels[i]))) {
12761
12860
  return `${locale}: title headlines do not match the leading key_points labels`;
12762
12861
  }
12763
12862
  const claims = parts.sentences;
@@ -12867,19 +12966,30 @@ function mapContentToSurfingMarkdown(content, options = {}) {
12867
12966
  const tags = contentTags(content);
12868
12967
  const isoDate = options.publishDate ?? new Date().toISOString().slice(0, 10);
12869
12968
  const draft = typeof content.metadata?.published === "boolean" ? !content.metadata.published : false;
12969
+ const postLocale = options.locale ?? "zh";
12970
+ const rawEpisodeTitle = typeof content.metadata?.episodeTitle === "string" && content.metadata.episodeTitle.trim() !== "" ? content.metadata.episodeTitle.trim() : typeof content.metadata?.episode_title === "string" && content.metadata.episode_title.trim() !== "" ? content.metadata.episode_title.trim() : "";
12971
+ const podcastUrl = typeof content.metadata?.podcastUrl === "string" && /^https:\/\//.test(content.metadata.podcastUrl) ? content.metadata.podcastUrl : "";
12972
+ const episodeTitleForLocale = postLocale === "zh" ? rawEpisodeTitle || (isEpisodeIdentityTitle(title, "zh") ? title : "") : isEpisodeIdentityTitle(title, postLocale) ? title : "";
12870
12973
  const frontmatterObj = {
12871
12974
  title,
12872
12975
  description,
12873
12976
  tags,
12874
12977
  publishDate: isoDate,
12875
12978
  draft,
12876
- ...options.image ? { image: options.image, og_image: options.image } : {}
12979
+ ...options.image ? { image: options.image, og_image: options.image } : {},
12980
+ ...episodeTitleForLocale !== "" ? { episode_title: episodeTitleForLocale } : {}
12877
12981
  };
12878
12982
  const yamlLines = ["---", ...Object.entries(frontmatterObj).map(([k, v]) => `${k}: ${JSON.stringify(v)}`), "---"];
12983
+ let bodyText = content.body.trim();
12984
+ if (podcastUrl !== "" && !bodyText.includes(podcastUrl)) {
12985
+ bodyText = `${bodyText}
12986
+
12987
+ ${crossLinkFor(postLocale, isoDate, podcastUrl, rawEpisodeTitle)}`;
12988
+ }
12879
12989
  return `${yamlLines.join(`
12880
12990
  `)}
12881
12991
 
12882
- ${content.body.trim()}
12992
+ ${bodyText}
12883
12993
  `;
12884
12994
  }
12885
12995
  function isDigestContent(content) {
@@ -13109,7 +13219,7 @@ async function runDailyTopicsSync(surfdashRoot, zhPostPath) {
13109
13219
  if (!built.ok) {
13110
13220
  return { ok: false, error: `daily-topics sync failed: ${built.error}` };
13111
13221
  }
13112
- const mapPath = join2(surfdashRoot, "scripts", "seo", "daily-topics.json");
13222
+ const mapPath = join(surfdashRoot, "scripts", "seo", "daily-topics.json");
13113
13223
  const before = await spawnCli(["git", "status", "--porcelain", "--", ...DAILY_TOPICS_GIT_PATHS], surfdashRoot);
13114
13224
  const beforePaths = new Set(parsePorcelainPaths(before.stdout));
13115
13225
  try {
@@ -13345,10 +13455,6 @@ async function scaffoldLocale(options) {
13345
13455
  if (!existsSync2(draftPath)) {
13346
13456
  return fail(`sd translate reported success but the draft is missing: ${draftPath}`);
13347
13457
  }
13348
- const assetsDir = join2(dirname4(postPath.postPath), "assets");
13349
- if (existsSync2(assetsDir)) {
13350
- await cp(assetsDir, join2(dirname4(draftPath), "assets"), { recursive: true });
13351
- }
13352
13458
  return ResultSchema.parse({
13353
13459
  ok: true,
13354
13460
  target: TARGET,
@@ -13438,29 +13544,16 @@ async function patchPost(options) {
13438
13544
  showNotesUrl: strOption(options, "showNotesUrl"),
13439
13545
  localCover: strOption(options, "localCover"),
13440
13546
  dateIso: strOption(options, "dateIso"),
13441
- episodeTitle: strOption(options, "episodeTitle")
13547
+ episodeTitle: strOption(options, "episodeTitle"),
13548
+ uploadLocalCover: uploadCoverToMicrofeed
13442
13549
  });
13443
13550
  } catch (error) {
13444
13551
  return fail(`patch error: ${error instanceof Error ? error.message : String(error)}`);
13445
13552
  }
13446
13553
  if (outcome.changed === 0)
13447
13554
  echoError(`patch: no post bytes changed for ${outcome.slug}`);
13448
- const topics = await runDailyTopicsSync(surfdashRoot, postPath.postPath);
13449
- if (!topics.ok)
13450
- return fail(topics.error);
13451
13555
  const synced = await syncPost({ postPath: postPath.postPath });
13452
13556
  const commitPaths = new Set(outcome.written.map((path) => relative(surfdashRoot, path)));
13453
- for (const p of topics.paths)
13454
- commitPaths.add(p);
13455
- for (const locale of PATCH_LOCALES) {
13456
- const indexMd = localeIndexPath(postPath.postPath, locale);
13457
- if (!indexMd)
13458
- continue;
13459
- const assetsDir = join2(dirname4(indexMd), "assets");
13460
- if (existsSync2(assetsDir)) {
13461
- commitPaths.add(relative(surfdashRoot, assetsDir));
13462
- }
13463
- }
13464
13557
  if (process.env.SURFDASH_AUTO_PUSH !== "0") {
13465
13558
  const backfilled = await runListenLinkBackfill(surfdashRoot);
13466
13559
  for (const p of backfilled)
@@ -13611,8 +13704,8 @@ function resolvePreparedPost(options) {
13611
13704
  dateStamp: runDate,
13612
13705
  slug,
13613
13706
  filePath: preparedPath,
13614
- relPostDir: join2("content", "posts", "articles", "zh", slug),
13615
- relPostDirs: ["zh", "en", "ja"].map((locale) => join2("content", "posts", "articles", locale, slug)),
13707
+ relPostDir: join("content", "posts", "articles", "zh", slug),
13708
+ relPostDirs: ["zh", "en", "ja"].map((locale) => join("content", "posts", "articles", locale, slug)),
13616
13709
  articleUrl: `${baseUrl}/zh/posts/${slug}`
13617
13710
  },
13618
13711
  identity: identity.value
@@ -13641,22 +13734,15 @@ function readLocaleDrafts(content) {
13641
13734
  return drafts;
13642
13735
  }
13643
13736
  async function mintLocalePost(options) {
13644
- const filePath = join2(options.postDir, "index.md");
13737
+ const filePath = join(options.postDir, "index.md");
13645
13738
  if (readRefinedSnapshot(filePath) !== undefined) {
13646
13739
  echoError(`surfdash-pub: keeping existing refined post at ${filePath} (not re-minting)`);
13647
13740
  return;
13648
13741
  }
13649
13742
  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
13743
  const markdown = mapContentToSurfingMarkdown(options.content, {
13659
- image: imageFrontmatter,
13744
+ image: options.coverUrl,
13745
+ locale: options.locale,
13660
13746
  publishDate: options.publishDate
13661
13747
  });
13662
13748
  await createNodeFileSystem().writeFile(filePath, markdown);
@@ -13687,17 +13773,39 @@ async function preparePost(payload) {
13687
13773
  if (dirname4(localeRoot) !== articlesRoot || dirname4(postDir) !== localeRoot) {
13688
13774
  return { ok: false, result: failNotSent(`post path escapes ${articlesRoot}`) };
13689
13775
  }
13690
- const coverPath = payload.content.metadata?.coverImage;
13691
- if (typeof coverPath === "string" && !existsSync2(coverPath)) {
13692
- return { ok: false, result: failNotSent(`metadata.coverImage not found: ${coverPath}`) };
13693
- }
13694
- if (typeof coverPath === "string" && !COVER_EXTS.has(extname(coverPath).toLowerCase())) {
13695
- return {
13696
- ok: false,
13697
- result: failNotSent(`metadata.coverImage must be one of ${[...COVER_EXTS].join(", ")}`)
13698
- };
13699
- }
13700
- if (isDigestContent(payload.content) && typeof coverPath !== "string") {
13776
+ const rawCover = payload.content.metadata?.coverImage;
13777
+ let coverUrl;
13778
+ if (typeof rawCover === "string" && rawCover.trim() !== "") {
13779
+ const trimmedCover = rawCover.trim();
13780
+ if (/^https:\/\//.test(trimmedCover)) {
13781
+ coverUrl = trimmedCover;
13782
+ } else {
13783
+ if (!existsSync2(trimmedCover)) {
13784
+ return { ok: false, result: failNotSent(`metadata.coverImage not found: ${trimmedCover}`) };
13785
+ }
13786
+ if (!COVER_EXTS.has(extname2(trimmedCover).toLowerCase())) {
13787
+ return {
13788
+ ok: false,
13789
+ result: failNotSent(`metadata.coverImage must be one of ${[...COVER_EXTS].join(", ")}`)
13790
+ };
13791
+ }
13792
+ const optsObj = payload.options !== undefined && typeof payload.options === "object" && payload.options !== null ? payload.options : {};
13793
+ const isDryRun = optsObj.dryRun === true || process.env.KNOWLEDGE_KIT_PUBLISH_TRANSPORT === "fake";
13794
+ if (isDryRun) {
13795
+ const safeName = basename3(trimmedCover).replace(/[^a-zA-Z0-9._-]/g, "_") || "cover.png";
13796
+ coverUrl = `https://podcast-media.salty.vip/production/images/dry-run-${safeName}`;
13797
+ } else {
13798
+ try {
13799
+ coverUrl = await uploadCoverToMicrofeed(trimmedCover);
13800
+ } catch (err) {
13801
+ return {
13802
+ ok: false,
13803
+ result: failNotSent(`Failed to upload cover image to podcast-media: ${err instanceof Error ? err.message : String(err)}`)
13804
+ };
13805
+ }
13806
+ }
13807
+ }
13808
+ } else if (isDigestContent(payload.content)) {
13701
13809
  return { ok: false, result: failNotSent("digest post has no cover image (metadata.coverImage)") };
13702
13810
  }
13703
13811
  const drafts = readLocaleDrafts(payload.content);
@@ -13710,25 +13818,27 @@ async function preparePost(payload) {
13710
13818
  };
13711
13819
  }
13712
13820
  }
13713
- const filePath = join2(postDir, "index.md");
13821
+ const filePath = join(postDir, "index.md");
13714
13822
  const publishDate = runDate ? `${runDate.slice(0, 4)}-${runDate.slice(4, 6)}-${runDate.slice(6, 8)}` : undefined;
13715
- const cover = typeof coverPath === "string" ? coverPath : undefined;
13823
+ const mintedDirs = [join("content", "posts", "articles", locale, slug)];
13716
13824
  try {
13717
- await mintLocalePost({ postDir, content: payload.content, coverPath: cover, publishDate });
13718
- for (const locale of LOCAL_DRAFTS) {
13719
- const draft = drafts[locale];
13825
+ await mintLocalePost({ postDir, content: payload.content, coverUrl, locale, publishDate });
13826
+ for (const draftLocale of LOCAL_DRAFTS) {
13827
+ const draft = drafts[draftLocale];
13720
13828
  if (draft === undefined)
13721
13829
  continue;
13722
- const siblingDir = resolve(articlesRoot, locale, slug);
13723
- if (dirname4(resolve(siblingDir)) !== resolve(articlesRoot, locale)) {
13830
+ const siblingDir = resolve(articlesRoot, draftLocale, slug);
13831
+ if (dirname4(resolve(siblingDir)) !== resolve(articlesRoot, draftLocale)) {
13724
13832
  return { ok: false, result: failNotSent(`post path escapes ${articlesRoot}`) };
13725
13833
  }
13726
13834
  await mintLocalePost({
13727
13835
  postDir: siblingDir,
13728
13836
  content: { ...payload.content, title: draft.title, body: draft.body },
13729
- coverPath: cover,
13837
+ coverUrl,
13838
+ locale: draftLocale,
13730
13839
  publishDate
13731
13840
  });
13841
+ mintedDirs.push(join("content", "posts", "articles", draftLocale, slug));
13732
13842
  }
13733
13843
  } catch (err) {
13734
13844
  return {
@@ -13746,7 +13856,8 @@ async function preparePost(payload) {
13746
13856
  dateStamp,
13747
13857
  slug,
13748
13858
  filePath,
13749
- relPostDir: join2("content", "posts", "articles", locale, slug),
13859
+ relPostDir: join("content", "posts", "articles", locale, slug),
13860
+ relPostDirs: mintedDirs,
13750
13861
  articleUrl
13751
13862
  }
13752
13863
  };
@@ -13809,16 +13920,13 @@ async function publishPreparedFile(prepared, identity) {
13809
13920
  }
13810
13921
  });
13811
13922
  }
13812
- const topics = await runDailyTopicsSync(surfdashRoot, filePath);
13813
- if (!topics.ok)
13814
- return failUncertain(topics.error);
13815
13923
  const backfilled = await runListenLinkBackfill(surfdashRoot);
13816
13924
  const commitPaths = relPostDirs ?? [relPostDir];
13817
- const gate = await runSiteGate(surfdashRoot, [...commitPaths, ...backfilled, ...topics.paths]);
13925
+ const gate = await runSiteGate(surfdashRoot, [...commitPaths, ...backfilled]);
13818
13926
  if (!gate.ok)
13819
13927
  return failUncertain(gate.error);
13820
- const commitLocales = relPostDirs === undefined ? [locale] : ["zh", "en", "ja"];
13821
- const pushed = await pushPostGit(surfdashRoot, commitPaths, `content: daily AI news ${dateStamp} (${commitLocales.join(", ")})`, [...backfilled, ...topics.paths]);
13928
+ const commitLocales = relPostDirs !== undefined && relPostDirs.length > 1 ? ["zh", "en", "ja"] : [locale];
13929
+ const pushed = await pushPostGit(surfdashRoot, commitPaths, `content: daily AI news ${dateStamp} (${commitLocales.join(", ")})`, backfilled);
13822
13930
  if (!pushed.ok)
13823
13931
  return failUncertain(pushed.error);
13824
13932
  const live = await awaitArticleLive(articleUrl);
@@ -13849,7 +13957,7 @@ async function refinePreparedPost(options) {
13849
13957
  const resolved = resolvePreparedLocaleSet(options);
13850
13958
  if (!resolved.ok)
13851
13959
  return resolved.result;
13852
- const orchestrator = join2(resolved.value.surfdashRoot, "scripts", "publish-orchestrator.ts");
13960
+ const orchestrator = join(resolved.value.surfdashRoot, "scripts", "publish-orchestrator.ts");
13853
13961
  if (!existsSync2(orchestrator))
13854
13962
  return failNotSent(`Surfdash refine orchestrator is missing: ${orchestrator}`);
13855
13963
  try {
@@ -28,8 +28,23 @@ export const DIGEST_TAG = 'sub-category:ai-daily';
28
28
  /** Podcast-intro openings a digest description must not start with (case-insensitive). */
29
29
  const PODCAST_INTROS = ['这里是由Robin', '咸话咸说', 'This is Robin', 'Robin がお届け'] as const;
30
30
 
31
- /** Rendered `<title>` budget: title + " | Surfing" must fit (site SEO_TITLE_LIMIT). */
31
+ /** Rendered `<title>` budget: title + " | Surfing" (or bare episode title) must fit (site SEO_TITLE_LIMIT). */
32
32
  const SEO_TITLE_LIMIT = 60;
33
+ const EPISODE_TITLE_MAX = 80;
34
+
35
+ const EPISODE_IDENTITY_TITLE_RE: Record<DigestLocale, RegExp> = {
36
+ zh: /^第\d{6}期\s*·\s*\S/u,
37
+ en: /^Issue\s+\d{6}\s*·\s*\S/iu,
38
+ ja: /^第\d{6}回\s*·\s*\S/u,
39
+ };
40
+
41
+ /** True when `title` matches the 0385+ episode-identity format for `locale` (or any locale if omitted). */
42
+ export function isEpisodeIdentityTitle(title: string, locale?: DigestLocale): boolean {
43
+ const clean = title.trim();
44
+ if (clean === '') return false;
45
+ if (locale !== undefined) return EPISODE_IDENTITY_TITLE_RE[locale].test(clean);
46
+ return Object.values(EPISODE_IDENTITY_TITLE_RE).some((re) => re.test(clean));
47
+ }
33
48
 
34
49
  /** One parsed frontmatter entry: a scalar string or a block/flow list of strings. */
35
50
  type FrontmatterValue = string | string[];
@@ -211,6 +226,20 @@ export function checkDigestFrontmatter(markdown: string, locale: DigestLocale):
211
226
  const title = scalar(frontmatter, 'title');
212
227
  if (title === undefined || title === '') {
213
228
  problems.push('title: missing');
229
+ } else if (isEpisodeIdentityTitle(title, locale)) {
230
+ const titleLength = Array.from(title).length;
231
+ if (titleLength > EPISODE_TITLE_MAX) {
232
+ problems.push(`title: ${titleLength} code points (max ${EPISODE_TITLE_MAX})`);
233
+ }
234
+ const explicitSeoTitle = scalar(frontmatter, 'seo_title');
235
+ const seoTitle =
236
+ explicitSeoTitle !== undefined && explicitSeoTitle !== '' ? explicitSeoTitle : `${title} | Surfing`;
237
+ const seoLength = Array.from(seoTitle).length;
238
+ if (seoLength > SEO_TITLE_LIMIT) {
239
+ problems.push(`seo_title: "${seoTitle}" is ${seoLength} code points (max ${SEO_TITLE_LIMIT})`);
240
+ }
241
+ if (title.includes('…') || title.includes('...')) problems.push('title: contains "…" or "..."');
242
+ if (seoTitle.includes('…') || seoTitle.includes('...')) problems.push('seo_title: contains "…" or "..."');
214
243
  } else {
215
244
  const match = title.match(
216
245
  new RegExp(`^${escapeRe(series)} · (\\d{4}-\\d{2}-\\d{2})${escapeRe(titleSep)}(.+)$`),