@gobing-ai/knowledge-kit 0.1.23 → 0.1.25

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 (106) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/dist/index.js +418 -114
  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 +59 -18
  10. package/plugins/generations/episode-plan-gen/src/index.ts +71 -7
  11. package/plugins/generations/gemini-tts/dist/index.js +9 -9
  12. package/plugins/generations/image-gen/dist/index.js +9 -9
  13. package/plugins/generations/music-gen/dist/index.js +33 -29
  14. package/plugins/generations/music-gen/src/audio/measure.ts +25 -20
  15. package/plugins/generations/news-report-gen/dist/index.js +12 -12
  16. package/plugins/generations/vibe-voice-tts/dist/index.js +9 -9
  17. package/plugins/generations/voice-gen/dist/index.js +9 -9
  18. package/plugins/generations/voxcpm-tts/dist/index.js +9 -9
  19. package/plugins/ingestions/aihot-ingest/dist/index.js +12 -12
  20. package/plugins/ingestions/horizon-ingest/dist/index.js +12 -12
  21. package/plugins/ingestions/karakeep-local/dist/index.js +13 -13
  22. package/plugins/ingestions/last30days-ingest/dist/index.js +12 -12
  23. package/plugins/ingestions/web-search/dist/index.js +10 -10
  24. package/plugins/kk/decisions/extract/ai-news.yaml +8 -1
  25. package/plugins/kk/plugin.json +1 -1
  26. package/plugins/kk/publish-presets/daily-ai-voice.json +20 -20
  27. package/plugins/kk/publish-presets/itc-main.json +39 -23
  28. package/plugins/kk/scripts/cover-compositor.ts +104 -26
  29. package/plugins/kk/scripts/daily-stages.ts +704 -53
  30. package/plugins/kk/scripts/kk-workflow-stages.ts +149 -6
  31. package/plugins/kk/scripts/series-names.ts +16 -3
  32. package/plugins/kk/skills/content-safety/references/platforms/apple-podcasts.md +12 -5
  33. package/plugins/kk/skills/content-safety/references/platforms/wechatmp.md +8 -0
  34. package/plugins/kk/skills/content-safety/references/platforms/xiaoyuzhou.md +5 -0
  35. package/plugins/kk/skills/daily-news-cover/SKILL.md +96 -0
  36. package/plugins/kk/skills/daily-news-illustrations/SKILL.md +123 -0
  37. package/plugins/kk/skills/news-editorial/SKILL.md +5 -3
  38. package/plugins/kk/skills/news-editorial/references/daily-visual-composition.md +150 -0
  39. package/plugins/kk/skills/news-editorial/references/style-contract.zh.md +3 -3
  40. package/plugins/kk/workflows/kk-article-generate.yaml +13 -1
  41. package/plugins/kk/workflows/kk-daily-ai-voice.yaml +6 -3
  42. package/plugins/kk/workflows/kk-daily-ai-voice2.yaml +6 -4
  43. package/plugins/kk/workflows/kk-news-generate.yaml +74 -1
  44. package/plugins/publishings/bilibili-pub/dist/index.js +25 -24
  45. package/plugins/publishings/bilibili-pub/dist/profile-check.js +25 -24
  46. package/plugins/publishings/cnblogs-pub/dist/index.js +25 -24
  47. package/plugins/publishings/cnblogs-pub/dist/profile-check.js +25 -24
  48. package/plugins/publishings/csdn-pub/dist/index.js +25 -24
  49. package/plugins/publishings/csdn-pub/dist/profile-check.js +25 -24
  50. package/plugins/publishings/emdash-pub/dist/index.js +9 -9
  51. package/plugins/publishings/infoq-pub/dist/index.js +25 -24
  52. package/plugins/publishings/infoq-pub/dist/profile-check.js +25 -24
  53. package/plugins/publishings/jike-pub/dist/index.js +25 -24
  54. package/plugins/publishings/jike-pub/dist/profile-check.js +25 -24
  55. package/plugins/publishings/juejin-pub/dist/index.js +25 -24
  56. package/plugins/publishings/juejin-pub/dist/profile-check.js +25 -24
  57. package/plugins/publishings/linkedin-pub/dist/index.js +85 -26
  58. package/plugins/publishings/linkedin-pub/dist/profile-check.js +25 -24
  59. package/plugins/publishings/linkedin-pub/src/index.ts +93 -6
  60. package/plugins/publishings/medium-pub/dist/index.js +9206 -287
  61. package/plugins/publishings/medium-pub/dist/profile-check.js +21174 -0
  62. package/plugins/publishings/medium-pub/package.json +3 -1
  63. package/plugins/publishings/medium-pub/plugin.json +6 -1
  64. package/plugins/publishings/medium-pub/src/browser-rail.ts +280 -0
  65. package/plugins/publishings/medium-pub/src/index.ts +17 -1
  66. package/plugins/publishings/medium-pub/src/profile-check.ts +27 -0
  67. package/plugins/publishings/podcast-pub/dist/index.js +240 -37
  68. package/plugins/publishings/podcast-pub/src/index.ts +154 -3
  69. package/plugins/publishings/podcast-pub/src/seo.ts +25 -8
  70. package/plugins/publishings/podcast-pub/src/show-notes-brief.ts +93 -23
  71. package/plugins/publishings/podcast-pub/src/show-notes.ts +26 -6
  72. package/plugins/publishings/qiita-pub/dist/index.js +9 -9
  73. package/plugins/publishings/shipinhao-pub/dist/index.js +29 -26
  74. package/plugins/publishings/shipinhao-pub/dist/profile-check.js +28 -26
  75. package/plugins/publishings/shipinhao-pub/src/flow.ts +5 -0
  76. package/plugins/publishings/shipinhao-pub/src/selectors.ts +13 -5
  77. package/plugins/publishings/sspai-pub/dist/index.js +25 -24
  78. package/plugins/publishings/sspai-pub/dist/profile-check.js +25 -24
  79. package/plugins/publishings/substack-pub/dist/index.js +25 -24
  80. package/plugins/publishings/substack-pub/dist/profile-check.js +25 -24
  81. package/plugins/publishings/surfdash-pub/dist/index.js +200 -92
  82. package/plugins/publishings/surfdash-pub/src/digest-check.ts +30 -1
  83. package/plugins/publishings/surfdash-pub/src/index.ts +94 -75
  84. package/plugins/publishings/surfdash-pub/src/media-upload.ts +83 -0
  85. package/plugins/publishings/surfdash-pub/src/patch.ts +28 -23
  86. package/plugins/publishings/surfdash-pub/src/topic-claims.ts +12 -4
  87. package/plugins/publishings/threads-pub/dist/index.js +39 -24
  88. package/plugins/publishings/threads-pub/dist/profile-check.js +30 -24
  89. package/plugins/publishings/threads-pub/src/post-rail.ts +20 -0
  90. package/plugins/publishings/wechatmp-pub/dist/index.js +438 -102
  91. package/plugins/publishings/wechatmp-pub/dist/profile-check.js +30 -25
  92. package/plugins/publishings/wechatmp-pub/src/enrich.ts +56 -10
  93. package/plugins/publishings/wechatmp-pub/src/flow.ts +589 -83
  94. package/plugins/publishings/wechatmp-pub/src/index.ts +4 -1
  95. package/plugins/publishings/wechatmp-pub/src/modes.ts +30 -12
  96. package/plugins/publishings/wechatmp-pub/src/page.ts +8 -0
  97. package/plugins/publishings/weibo-pub/dist/index.js +25 -24
  98. package/plugins/publishings/weibo-pub/dist/profile-check.js +25 -24
  99. package/plugins/publishings/x-pub/dist/index.js +54 -47
  100. package/plugins/publishings/x-pub/dist/profile-check.js +25 -24
  101. package/plugins/publishings/x-pub/src/post-rail.ts +40 -47
  102. package/plugins/publishings/xhs-pub/dist/index.js +25 -24
  103. package/plugins/publishings/xhs-pub/dist/profile-check.js +25 -24
  104. package/plugins/publishings/xiaoyuzhou-pub/dist/index.js +25 -24
  105. package/plugins/publishings/xiaoyuzhou-pub/dist/profile-check.js +25 -24
  106. package/plugins/publishings/zenn-pub/dist/index.js +9 -9
@@ -4827,7 +4827,7 @@ var init_zod = __esm(() => {
4827
4827
  init_external();
4828
4828
  });
4829
4829
 
4830
- // ../../node_modules/.bun/@gobing-ai+ts-utils@0.5.32/node_modules/@gobing-ai/ts-utils/dist/errors.js
4830
+ // ../../node_modules/.bun/@gobing-ai+ts-utils@0.8.4/node_modules/@gobing-ai/ts-utils/dist/errors.js
4831
4831
  var ErrorCode;
4832
4832
  var init_errors3 = __esm(() => {
4833
4833
  ErrorCode = {
@@ -4838,7 +4838,7 @@ var init_errors3 = __esm(() => {
4838
4838
  };
4839
4839
  });
4840
4840
 
4841
- // ../../node_modules/.bun/@gobing-ai+ts-utils@0.5.32/node_modules/@gobing-ai/ts-utils/dist/api-response.js
4841
+ // ../../node_modules/.bun/@gobing-ai+ts-utils@0.8.4/node_modules/@gobing-ai/ts-utils/dist/api-response.js
4842
4842
  var API_ERROR_CODES, ERROR_CODE_TO_HTTP, CLIENT_SAFE_CODES;
4843
4843
  var init_api_response = __esm(() => {
4844
4844
  init_errors3();
@@ -4861,13 +4861,13 @@ var init_api_response = __esm(() => {
4861
4861
  CLIENT_SAFE_CODES = new Set([ErrorCode.NotFound, ErrorCode.Validation, ErrorCode.Conflict]);
4862
4862
  });
4863
4863
 
4864
- // ../../node_modules/.bun/@gobing-ai+ts-utils@0.5.32/node_modules/@gobing-ai/ts-utils/dist/cursor.js
4864
+ // ../../node_modules/.bun/@gobing-ai+ts-utils@0.8.4/node_modules/@gobing-ai/ts-utils/dist/cursor.js
4865
4865
  var init_cursor = () => {};
4866
4866
 
4867
- // ../../node_modules/.bun/@gobing-ai+ts-utils@0.5.32/node_modules/@gobing-ai/ts-utils/dist/event-severity.js
4867
+ // ../../node_modules/.bun/@gobing-ai+ts-utils@0.8.4/node_modules/@gobing-ai/ts-utils/dist/event-severity.js
4868
4868
  var init_event_severity = () => {};
4869
4869
 
4870
- // ../../node_modules/.bun/@gobing-ai+ts-utils@0.5.32/node_modules/@gobing-ai/ts-utils/dist/output.js
4870
+ // ../../node_modules/.bun/@gobing-ai+ts-utils@0.8.4/node_modules/@gobing-ai/ts-utils/dist/output.js
4871
4871
  function processStream(name) {
4872
4872
  const proc = globalThis.process;
4873
4873
  const stream = proc?.[name];
@@ -4885,7 +4885,7 @@ function echoError(message, target = defaultStderrTarget ?? processStream("stder
4885
4885
  }
4886
4886
  var defaultStderrTarget;
4887
4887
 
4888
- // ../../node_modules/.bun/@gobing-ai+ts-utils@0.5.32/node_modules/@gobing-ai/ts-utils/dist/index.js
4888
+ // ../../node_modules/.bun/@gobing-ai+ts-utils@0.8.4/node_modules/@gobing-ai/ts-utils/dist/index.js
4889
4889
  var init_dist = __esm(() => {
4890
4890
  init_api_response();
4891
4891
  init_cursor();
@@ -11883,7 +11883,7 @@ var init_dist2 = __esm(() => {
11883
11883
  $visitAsync = visit.visitAsync;
11884
11884
  });
11885
11885
 
11886
- // ../../node_modules/.bun/@gobing-ai+ts-runtime@0.5.32+180a6e424da77181/node_modules/@gobing-ai/ts-runtime/dist/config.js
11886
+ // ../../node_modules/.bun/@gobing-ai+ts-runtime@0.8.4+b85a65bb895e3074/node_modules/@gobing-ai/ts-runtime/dist/config.js
11887
11887
  var configSchema;
11888
11888
  var init_config = __esm(() => {
11889
11889
  init_dist2();
@@ -11907,7 +11907,7 @@ var init_config = __esm(() => {
11907
11907
  });
11908
11908
  });
11909
11909
 
11910
- // ../../node_modules/.bun/@gobing-ai+ts-runtime@0.5.32+180a6e424da77181/node_modules/@gobing-ai/ts-runtime/dist/file-system-node.js
11910
+ // ../../node_modules/.bun/@gobing-ai+ts-runtime@0.8.4+b85a65bb895e3074/node_modules/@gobing-ai/ts-runtime/dist/file-system-node.js
11911
11911
  import { appendFileSync, cpSync, createReadStream, createWriteStream, existsSync, mkdirSync, readdirSync, readFileSync, realpathSync, renameSync, rmSync, statSync, writeFileSync } from "fs";
11912
11912
  import { dirname, resolve as resolvePath } from "path";
11913
11913
  function createNodeFileSystem(root, paths) {
@@ -12269,7 +12269,7 @@ var PluginManifestSchema = PluginManifestSchemaBase.superRefine((manifest, ctx)
12269
12269
  });
12270
12270
  }
12271
12271
  });
12272
- // ../../node_modules/.bun/@gobing-ai+ts-runtime@0.5.32+180a6e424da77181/node_modules/@gobing-ai/ts-runtime/dist/index.js
12272
+ // ../../node_modules/.bun/@gobing-ai+ts-runtime@0.8.4+b85a65bb895e3074/node_modules/@gobing-ai/ts-runtime/dist/index.js
12273
12273
  init_file_system_node();
12274
12274
  init_config();
12275
12275
 
@@ -14404,7 +14404,7 @@ var ConfigError = class extends Error {
14404
14404
  }
14405
14405
  };
14406
14406
 
14407
- // ../../node_modules/.bun/@gobing-ai+ts-infra@0.5.32+7037256b2d91fd75/node_modules/@gobing-ai/ts-infra/dist/logger.js
14407
+ // ../../node_modules/.bun/@gobing-ai+ts-infra@0.8.4+5042690a1c1c0ae5/node_modules/@gobing-ai/ts-infra/dist/logger.js
14408
14408
  var ROOT_CATEGORY = "app";
14409
14409
  function toLogTapeLevel(level) {
14410
14410
  return level === "warn" ? "warning" : level;
@@ -39,4 +39,11 @@ where:
39
39
  # the pool shrinks rather than admitting an unjudged item. Chinese companies/models/industry do
40
40
  # not trip the gate: they score 0.
41
41
  kk-item-china-politics: { lte: 1 }
42
- order: [kk-item-urgency desc, kk-item-impact desc, first_seen_at desc]
42
+ # 2026-11-23: `kk-item-importance` sits between urgency and impact. With only
43
+ # `[urgency, impact]` a same-day tie was broken by raw engagement, so 60 last30days
44
+ # YouTube videos (importance 2, impact 5 from view counts) evicted every rss/hackernews
45
+ # story (importance 3, impact 1) from the capped pool: the day's 40-item pool held 35
46
+ # videos and 5 news items, QC then kept 5, and the episode refused at the 13 min floor.
47
+ # Importance IS the source-tier dimension, so it ranks above engagement; impact stays
48
+ # the tie-breaker inside one tier.
49
+ order: [kk-item-urgency desc, kk-item-importance desc, kk-item-impact desc, first_seen_at desc]
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "kk",
3
- "version": "0.1.23",
3
+ "version": "0.1.25",
4
4
  "description": "knowledge-kit Claude Code plugin: skills, commands, subagents, hooks, and rules"
5
5
  }
@@ -3,18 +3,18 @@
3
3
  "name": "daily-ai-voice",
4
4
  "targets": [
5
5
  {
6
- "plugin": "surfdash-pub",
7
- "operation": "post",
8
- "variant": "article",
6
+ "plugin": "podcast-pub",
7
+ "operation": "episode",
8
+ "variant": "episode",
9
9
  "tier": 0,
10
10
  "window": "after-generate",
11
11
  "mode": "live",
12
12
  "required": true
13
13
  },
14
14
  {
15
- "plugin": "podcast-pub",
16
- "operation": "episode",
17
- "variant": "episode",
15
+ "plugin": "surfdash-pub",
16
+ "operation": "post",
17
+ "variant": "article",
18
18
  "tier": 0,
19
19
  "window": "after-generate",
20
20
  "mode": "live",
@@ -72,7 +72,7 @@
72
72
  "variant": "article",
73
73
  "tier": 2,
74
74
  "window": "cn-peak",
75
- "mode": "live"
75
+ "mode": "off"
76
76
  },
77
77
  {
78
78
  "plugin": "xhs-pub",
@@ -95,7 +95,7 @@
95
95
  "operation": "post",
96
96
  "variant": "social:x",
97
97
  "tier": 3,
98
- "window": "overseas-rss",
98
+ "window": "after-generate",
99
99
  "mode": "live"
100
100
  },
101
101
  {
@@ -103,7 +103,7 @@
103
103
  "operation": "post",
104
104
  "variant": "social:weibo",
105
105
  "tier": 3,
106
- "window": "overseas-rss",
106
+ "window": "cn-peak",
107
107
  "mode": "live"
108
108
  },
109
109
  {
@@ -111,7 +111,7 @@
111
111
  "operation": "post",
112
112
  "variant": "social:threads",
113
113
  "tier": 3,
114
- "window": "overseas-rss",
114
+ "window": "after-generate",
115
115
  "mode": "live"
116
116
  },
117
117
  {
@@ -119,7 +119,7 @@
119
119
  "operation": "post",
120
120
  "variant": "social:linkedin",
121
121
  "tier": 3,
122
- "window": "overseas-rss",
122
+ "window": "after-generate",
123
123
  "mode": "live"
124
124
  },
125
125
  {
@@ -143,7 +143,7 @@
143
143
  "operation": "post",
144
144
  "variant": "social:jike",
145
145
  "tier": 3,
146
- "window": "overseas-rss",
146
+ "window": "after-generate",
147
147
  "mode": "live"
148
148
  }
149
149
  ],
@@ -152,29 +152,29 @@
152
152
  "plugin": "x-pub",
153
153
  "operation": "post",
154
154
  "mode": "live",
155
- "reason": "operator instruction 2026-11-15: publish to all available platforms for the dogfood run; no draftable rail exists, so this is a recorded exception to ADR-022",
156
- "until": "2026-11-16 dogfood run"
155
+ "reason": "operator instruction 2026-11-21: publish illustrated promo post linking unified {{podcast_url}} (temporary until RSS sync lag resolved); no draftable rail exists, so this is a recorded exception to ADR-022",
156
+ "until": "until Xiaoyuzhou/Apple Podcasts RSS sync lag resolved"
157
157
  },
158
158
  {
159
159
  "plugin": "weibo-pub",
160
160
  "operation": "post",
161
161
  "mode": "live",
162
- "reason": "operator instruction 2026-11-15: publish to all available platforms for the dogfood run; no draftable rail exists, so this is a recorded exception to ADR-022",
163
- "until": "2026-11-16 dogfood run"
162
+ "reason": "operator instruction 2026-11-21: replace long article with illustrated promo post linking unified {{podcast_url}} in cn-peak (temporary until RSS sync lag resolved); no draftable rail exists, so this is a recorded exception to ADR-022",
163
+ "until": "until Xiaoyuzhou/Apple Podcasts RSS sync lag resolved"
164
164
  },
165
165
  {
166
166
  "plugin": "threads-pub",
167
167
  "operation": "post",
168
168
  "mode": "live",
169
- "reason": "operator instruction 2026-11-15: publish to all available platforms for the dogfood run; no draftable rail exists, so this is a recorded exception to ADR-022",
170
- "until": "2026-11-16 dogfood run"
169
+ "reason": "operator instruction 2026-11-21: publish illustrated promo post linking unified {{podcast_url}} (temporary until RSS sync lag resolved); no draftable rail exists, so this is a recorded exception to ADR-022",
170
+ "until": "until Xiaoyuzhou/Apple Podcasts RSS sync lag resolved"
171
171
  },
172
172
  {
173
173
  "plugin": "linkedin-pub",
174
174
  "operation": "post",
175
175
  "mode": "live",
176
- "reason": "operator instruction 2026-11-15: publish to all available platforms for the dogfood run; no draftable rail exists, so this is a recorded exception to ADR-022",
177
- "until": "2026-11-16 dogfood run"
176
+ "reason": "operator instruction 2026-11-21: publish illustrated promo post linking unified {{podcast_url}} (temporary until RSS sync lag resolved); no draftable rail exists, so this is a recorded exception to ADR-022",
177
+ "until": "until Xiaoyuzhou/Apple Podcasts RSS sync lag resolved"
178
178
  }
179
179
  ]
180
180
  }
@@ -12,58 +12,74 @@
12
12
  {
13
13
  "plugin": "infoq-pub",
14
14
  "profile": "article",
15
- "variant": "article",
16
- "tier": 0,
17
- "required": true
15
+ "variant": "zh-article",
16
+ "tier": 2,
17
+ "required": false,
18
+ "transport": "browser"
18
19
  },
19
20
  {
20
21
  "plugin": "juejin-pub",
21
22
  "profile": "article",
22
- "variant": "article",
23
- "tier": 0,
24
- "required": true
23
+ "variant": "zh-article",
24
+ "tier": 2,
25
+ "required": false,
26
+ "transport": "browser"
25
27
  },
26
28
  {
27
29
  "plugin": "wechatmp-pub",
28
30
  "profile": "article",
29
- "variant": "article",
30
- "tier": 0,
31
- "required": true
31
+ "operation": "文章",
32
+ "variant": "zh-article",
33
+ "tier": 2,
34
+ "required": false,
35
+ "transport": "browser"
32
36
  },
33
37
  {
34
38
  "plugin": "x-pub",
35
39
  "profile": "article-zh",
40
+ "operation": "article",
36
41
  "variant": "zh-article",
37
- "tier": 0,
38
- "required": true
42
+ "tier": 2,
43
+ "required": false,
44
+ "transport": "browser"
39
45
  },
40
46
  {
41
47
  "plugin": "zenn-pub",
42
48
  "profile": "article",
43
- "variant": "article",
44
- "tier": 0,
45
- "required": true
49
+ "variant": "ja-article",
50
+ "tier": 2,
51
+ "required": false
46
52
  },
47
53
  {
48
54
  "plugin": "qiita-pub",
49
55
  "profile": "article",
50
- "variant": "article",
51
- "tier": 0,
52
- "required": true
56
+ "variant": "ja-article",
57
+ "tier": 2,
58
+ "required": false
53
59
  },
54
60
  {
55
61
  "plugin": "medium-pub",
56
62
  "profile": "article",
57
- "variant": "article",
58
- "tier": 0,
59
- "required": true
63
+ "variant": "en-article",
64
+ "tier": 2,
65
+ "required": false
60
66
  },
61
67
  {
62
68
  "plugin": "substack-pub",
63
69
  "profile": "article",
64
- "variant": "article",
65
- "tier": 0,
66
- "required": true
70
+ "variant": "en-article",
71
+ "tier": 2,
72
+ "required": false,
73
+ "transport": "browser"
74
+ },
75
+ {
76
+ "plugin": "weibo-pub",
77
+ "profile": "article",
78
+ "operation": "article",
79
+ "variant": "zh-article",
80
+ "tier": 2,
81
+ "required": false,
82
+ "transport": "browser"
67
83
  }
68
84
  ]
69
85
  }
@@ -26,10 +26,14 @@ export interface CoverCompositorOptions {
26
26
  outputPath: string;
27
27
  width?: number; // default 1344
28
28
  height?: number; // default 576
29
+ /** Raster output format passed to macOS `sips` (default `'png'`). */
30
+ format?: 'png' | 'jpeg';
29
31
  }
30
32
 
31
33
  export const COVER_WIDTH = 1344;
32
34
  export const COVER_HEIGHT = 576;
35
+ export const SOCIAL_COVER_WIDTH = 1200;
36
+ export const SOCIAL_COVER_HEIGHT = 630;
33
37
  /** Max Chinese characters per headline line (news-editorial style contract, 0347). */
34
38
  export const HEADLINE_LINE_CAP = 25;
35
39
  const FONT_STACK = `PingFang SC, Hiragino Sans GB, 'Noto Sans CJK SC', sans-serif`;
@@ -381,6 +385,33 @@ function backgroundDataUri(path: string): string {
381
385
  return `data:${mime};base64,${readFileSync(path).toString('base64')}`;
382
386
  }
383
387
 
388
+ function runSips(
389
+ args: string[],
390
+ outputPath: string,
391
+ messages: { notFound: string; failed: (status: number) => string; missingOutput: string },
392
+ ): void {
393
+ const sips = spawnSync('sips', args, { stdio: 'ignore' });
394
+ // Bun reports a missing binary as `status: undefined` (older versions: `null`) plus an `error` object.
395
+ if (sips.error !== undefined || typeof sips.status !== 'number') {
396
+ throw new Error(messages.notFound);
397
+ }
398
+ if (sips.status !== 0) {
399
+ throw new Error(messages.failed(sips.status));
400
+ }
401
+ // sips exits 0 even when it silently fails to place the output (missing parent dir).
402
+ if (!existsSync(outputPath)) {
403
+ throw new Error(messages.missingOutput);
404
+ }
405
+ }
406
+
407
+ function sipsErrorMessages(noun: string, verb: string, outputPath: string) {
408
+ return {
409
+ notFound: `cover compositor: sips not found; cannot ${noun} (macOS required)`,
410
+ failed: (status: number) => `cover compositor: sips ${verb} failed (status ${status}); ${outputPath} missing`,
411
+ missingOutput: `cover compositor: sips reported success but ${outputPath} is missing`,
412
+ };
413
+ }
414
+
384
415
  export function compositeCover(options: CoverCompositorOptions): string {
385
416
  const svgPath = join(tmpdir(), `cover-composite-${Date.now()}.svg`);
386
417
  writeFileSync(
@@ -388,28 +419,80 @@ export function compositeCover(options: CoverCompositorOptions): string {
388
419
  buildCoverSvg({ ...options, backgroundUri: backgroundDataUri(options.backgroundImagePath) }),
389
420
  'utf-8',
390
421
  );
422
+ const sipsArgs =
423
+ options.format === 'jpeg'
424
+ ? ['-s', 'format', 'jpeg', '-s', 'formatOptions', '88', svgPath, '--out', options.outputPath]
425
+ : ['-s', 'format', 'png', svgPath, '--out', options.outputPath];
391
426
  try {
392
- const sips = spawnSync('sips', ['-s', 'format', 'png', svgPath, '--out', options.outputPath], {
393
- stdio: 'ignore',
427
+ runSips(sipsArgs, options.outputPath, {
428
+ notFound: 'cover compositor: sips not found; cannot render the cover overlay (macOS required)',
429
+ failed: (status) => `cover compositor: sips failed (status ${status}); overlay did not render`,
430
+ missingOutput: `cover compositor: sips reported success but ${options.outputPath} is missing`,
394
431
  });
395
- // Bun reports a missing binary as `status: undefined` plus an `error` object.
396
- if (sips.error !== undefined || typeof sips.status !== 'number') {
397
- throw new Error('cover compositor: sips not found; cannot render the cover overlay (macOS required)');
398
- }
399
- if (sips.status !== 0) {
400
- throw new Error(`cover compositor: sips failed (status ${sips.status}); overlay did not render`);
401
- }
402
- // sips exits 0 even when it silently fails to place the output (missing parent dir) —
403
- // a render that claims success without a file would leave a stale cover downstream.
404
- if (!existsSync(options.outputPath)) {
405
- throw new Error(`cover compositor: sips reported success but ${options.outputPath} is missing`);
406
- }
407
432
  } finally {
408
433
  rmSync(svgPath, { force: true });
409
434
  }
410
435
  return options.outputPath;
411
436
  }
412
437
 
438
+ /**
439
+ * Render the 1200×630 JPEG Open Graph / Twitter social card derivative from the same raw background
440
+ * and frozen Chinese headline so `podcast-pub` populates `_microfeed.seo.social_image`.
441
+ */
442
+ export function compositeSocialCover(options: Omit<CoverCompositorOptions, 'width' | 'height' | 'format'>): string {
443
+ return compositeCover({
444
+ ...options,
445
+ width: SOCIAL_COVER_WIDTH,
446
+ height: SOCIAL_COVER_HEIGHT,
447
+ format: 'jpeg',
448
+ });
449
+ }
450
+
451
+ /**
452
+ * Derive a 1200×630 JPEG social card from an already-rendered raster cover via centered aspect crop
453
+ * + resize (used for backfilling historical episodes without regenerating raw diffusion backgrounds).
454
+ */
455
+ export function deriveSocialCoverFromImage(sourcePath: string, outputPath: string): string {
456
+ const probe = spawnSync('sips', ['-g', 'pixelWidth', '-g', 'pixelHeight', sourcePath], { encoding: 'utf-8' });
457
+ const width = Number(/pixelWidth:\s*(\d+)/.exec(probe.stdout ?? '')?.[1] ?? '0');
458
+ const height = Number(/pixelHeight:\s*(\d+)/.exec(probe.stdout ?? '')?.[1] ?? '0');
459
+ if (
460
+ probe.error !== undefined ||
461
+ typeof probe.status !== 'number' ||
462
+ probe.status !== 0 ||
463
+ width < 1 ||
464
+ height < 1
465
+ ) {
466
+ throw new Error(`cover compositor: cannot probe dimensions of ${sourcePath}`);
467
+ }
468
+ const rect = centerCropRect(width, height, SOCIAL_COVER_WIDTH / SOCIAL_COVER_HEIGHT);
469
+ const croppedPng = join(tmpdir(), `cover-social-crop-${Date.now()}.png`);
470
+ try {
471
+ cropPng(sourcePath, rect, croppedPng);
472
+ runSips(
473
+ [
474
+ '-z',
475
+ String(SOCIAL_COVER_HEIGHT),
476
+ String(SOCIAL_COVER_WIDTH),
477
+ '-s',
478
+ 'format',
479
+ 'jpeg',
480
+ '-s',
481
+ 'formatOptions',
482
+ '88',
483
+ croppedPng,
484
+ '--out',
485
+ outputPath,
486
+ ],
487
+ outputPath,
488
+ sipsErrorMessages('transcode social cover', 'transcode', outputPath),
489
+ );
490
+ } finally {
491
+ rmSync(croppedPng, { force: true });
492
+ }
493
+ return outputPath;
494
+ }
495
+
413
496
  /** One platform crop preview written next to the full cover. */
414
497
  export interface CoverCropPreview {
415
498
  platform: PlatformCrop['platform'];
@@ -451,8 +534,7 @@ export interface CoverPreviewOptions extends CoverCompositorOptions {
451
534
 
452
535
  /** Center-crop a rendered PNG to `rect` via `sips` (macOS-only, same tool as the render itself). */
453
536
  function cropPng(source: string, rect: Rect, outputPath: string): void {
454
- const sips = spawnSync(
455
- 'sips',
537
+ runSips(
456
538
  [
457
539
  '-c',
458
540
  String(rect.height),
@@ -464,17 +546,13 @@ function cropPng(source: string, rect: Rect, outputPath: string): void {
464
546
  '--out',
465
547
  outputPath,
466
548
  ],
467
- { stdio: 'ignore' },
549
+ outputPath,
550
+ {
551
+ notFound: 'cover compositor: sips not found; cannot write the crop previews (macOS required)',
552
+ failed: (status) => `cover compositor: sips crop failed (status ${status}); preview ${outputPath} missing`,
553
+ missingOutput: `cover compositor: sips reported success but crop preview ${outputPath} is missing`,
554
+ },
468
555
  );
469
- if (sips.error !== undefined || typeof sips.status !== 'number') {
470
- throw new Error('cover compositor: sips not found; cannot write the crop previews (macOS required)');
471
- }
472
- if (sips.status !== 0) {
473
- throw new Error(`cover compositor: sips crop failed (status ${sips.status}); preview ${outputPath} missing`);
474
- }
475
- if (!existsSync(outputPath)) {
476
- throw new Error(`cover compositor: sips reported success but crop preview ${outputPath} is missing`);
477
- }
478
556
  }
479
557
 
480
558
  /** The top-right corner window the reference-blend preview zooms into (emblem + its surroundings). */