@gobing-ai/knowledge-kit 0.1.20 → 0.1.22

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 (115) 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 +13893 -8995
  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/music-gen/README.md +277 -0
  13. package/plugins/generations/music-gen/dist/index.js +23544 -0
  14. package/plugins/generations/music-gen/package.json +24 -0
  15. package/plugins/generations/music-gen/plugin.json +23 -0
  16. package/plugins/generations/music-gen/presets/SOURCE.md +39 -0
  17. package/plugins/generations/music-gen/presets/formats/clip.yaml +21 -0
  18. package/plugins/generations/music-gen/presets/formats/jingle.yaml +22 -0
  19. package/plugins/generations/music-gen/presets/formats/loop.yaml +21 -0
  20. package/plugins/generations/music-gen/presets/formats/song.yaml +31 -0
  21. package/plugins/generations/music-gen/presets/formats/underscore.yaml +22 -0
  22. package/plugins/generations/music-gen/presets/themes/ambient-tech.yaml +30 -0
  23. package/plugins/generations/music-gen/presets/themes/cinematic.yaml +30 -0
  24. package/plugins/generations/music-gen/presets/themes/lofi.yaml +30 -0
  25. package/plugins/generations/music-gen/presets/themes/synthwave.yaml +30 -0
  26. package/plugins/generations/music-gen/scripts/gen-preset-index.ts +181 -0
  27. package/plugins/generations/music-gen/scripts/resolve-preset.ts +64 -0
  28. package/plugins/generations/music-gen/src/adapter/index.ts +35 -0
  29. package/plugins/generations/music-gen/src/adapter/instance.ts +904 -0
  30. package/plugins/generations/music-gen/src/adapter/offline.ts +124 -0
  31. package/plugins/generations/music-gen/src/artifact.ts +223 -0
  32. package/plugins/generations/music-gen/src/audio/checks.ts +618 -0
  33. package/plugins/generations/music-gen/src/audio/master.ts +267 -0
  34. package/plugins/generations/music-gen/src/audio/measure.ts +507 -0
  35. package/plugins/generations/music-gen/src/audio/profile.ts +131 -0
  36. package/plugins/generations/music-gen/src/audio.ts +122 -0
  37. package/plugins/generations/music-gen/src/brief.ts +191 -0
  38. package/plugins/generations/music-gen/src/config.ts +451 -0
  39. package/plugins/generations/music-gen/src/content.ts +199 -0
  40. package/plugins/generations/music-gen/src/digest.ts +100 -0
  41. package/plugins/generations/music-gen/src/index.ts +147 -0
  42. package/plugins/generations/music-gen/src/job.ts +131 -0
  43. package/plugins/generations/music-gen/src/plugin.ts +371 -0
  44. package/plugins/generations/music-gen/src/presets.ts +918 -0
  45. package/plugins/generations/music-gen/src/render.ts +87 -0
  46. package/plugins/generations/music-gen/src/request.ts +102 -0
  47. package/plugins/generations/music-gen/src/spend.ts +495 -0
  48. package/plugins/generations/music-gen/tsconfig.json +8 -0
  49. package/plugins/kk/plugin.json +1 -1
  50. package/plugins/kk/schedules/kk-serve.launchd.plist.tmpl +2 -1
  51. package/plugins/kk/scripts/cover-compositor.ts +380 -32
  52. package/plugins/kk/scripts/daily-cover-mock.ts +40 -3
  53. package/plugins/kk/scripts/daily-stages.ts +659 -20
  54. package/plugins/kk/scripts/episode-identity.ts +180 -0
  55. package/plugins/kk/scripts/kk-workflow-stages.ts +37 -1
  56. package/plugins/kk/scripts/music-stages.ts +624 -0
  57. package/plugins/kk/scripts/news-editorial-ledger.ts +906 -0
  58. package/plugins/kk/scripts/source-citation.ts +187 -0
  59. package/plugins/kk/scripts/topic-selection-attempts.ts +446 -0
  60. package/plugins/kk/scripts/topic-selection-calibration.ts +161 -0
  61. package/plugins/kk/skills/content-judge/SKILL.md +11 -6
  62. package/plugins/kk/skills/content-judge/references/music-quality-rubric.md +147 -0
  63. package/plugins/kk/skills/content-judge/references/rubrics.md +15 -0
  64. package/plugins/kk/skills/content-safety/SKILL.md +12 -0
  65. package/plugins/kk/skills/music-authoring/SKILL.md +276 -0
  66. package/plugins/kk/skills/music-authoring/references/judge-input.md +117 -0
  67. package/plugins/kk/skills/news-editorial/SKILL.md +102 -15
  68. package/plugins/kk/skills/news-editorial/references/selection.md +4 -0
  69. package/plugins/kk/skills/news-editorial/references/style-contract.zh.md +58 -11
  70. package/plugins/kk/workflows/kk-daily-ai-voice.yaml +8 -8
  71. package/plugins/kk/workflows/kk-daily-ai-voice2.yaml +7 -7
  72. package/plugins/kk/workflows/kk-music.yaml +328 -0
  73. package/plugins/kk/workflows/kk-news-generate.yaml +58 -3
  74. package/plugins/publishings/bilibili-pub/dist/index.js +11 -1
  75. package/plugins/publishings/bilibili-pub/dist/profile-check.js +11 -1
  76. package/plugins/publishings/cnblogs-pub/dist/index.js +11 -1
  77. package/plugins/publishings/cnblogs-pub/dist/profile-check.js +11 -1
  78. package/plugins/publishings/csdn-pub/dist/index.js +11 -1
  79. package/plugins/publishings/csdn-pub/dist/profile-check.js +11 -1
  80. package/plugins/publishings/infoq-pub/dist/index.js +11 -1
  81. package/plugins/publishings/infoq-pub/dist/profile-check.js +11 -1
  82. package/plugins/publishings/jike-pub/dist/index.js +11 -1
  83. package/plugins/publishings/jike-pub/dist/profile-check.js +11 -1
  84. package/plugins/publishings/juejin-pub/dist/index.js +11 -1
  85. package/plugins/publishings/juejin-pub/dist/profile-check.js +11 -1
  86. package/plugins/publishings/linkedin-pub/dist/index.js +11 -1
  87. package/plugins/publishings/linkedin-pub/dist/profile-check.js +11 -1
  88. package/plugins/publishings/podcast-pub/dist/index.js +586 -20
  89. package/plugins/publishings/podcast-pub/src/corrections.ts +509 -0
  90. package/plugins/publishings/podcast-pub/src/index.ts +257 -5
  91. package/plugins/publishings/podcast-pub/src/show-notes-brief.ts +240 -0
  92. package/plugins/publishings/podcast-pub/src/show-notes.ts +69 -13
  93. package/plugins/publishings/shipinhao-pub/dist/index.js +59 -8
  94. package/plugins/publishings/shipinhao-pub/dist/profile-check.js +11 -1
  95. package/plugins/publishings/shipinhao-pub/src/audio-flow.ts +105 -6
  96. package/plugins/publishings/sspai-pub/dist/index.js +11 -1
  97. package/plugins/publishings/sspai-pub/dist/profile-check.js +11 -1
  98. package/plugins/publishings/substack-pub/dist/index.js +11 -1
  99. package/plugins/publishings/substack-pub/dist/profile-check.js +11 -1
  100. package/plugins/publishings/surfdash-pub/dist/index.js +72 -20
  101. package/plugins/publishings/surfdash-pub/src/digest-check.ts +7 -3
  102. package/plugins/publishings/surfdash-pub/src/index.ts +100 -17
  103. package/plugins/publishings/surfdash-pub/src/topic-claims.ts +3 -1
  104. package/plugins/publishings/threads-pub/dist/index.js +11 -1
  105. package/plugins/publishings/threads-pub/dist/profile-check.js +11 -1
  106. package/plugins/publishings/wechatmp-pub/dist/index.js +11 -1
  107. package/plugins/publishings/wechatmp-pub/dist/profile-check.js +11 -1
  108. package/plugins/publishings/weibo-pub/dist/index.js +11 -1
  109. package/plugins/publishings/weibo-pub/dist/profile-check.js +11 -1
  110. package/plugins/publishings/x-pub/dist/index.js +11 -1
  111. package/plugins/publishings/x-pub/dist/profile-check.js +11 -1
  112. package/plugins/publishings/xhs-pub/dist/index.js +11 -1
  113. package/plugins/publishings/xhs-pub/dist/profile-check.js +11 -1
  114. package/plugins/publishings/xiaoyuzhou-pub/dist/index.js +11 -1
  115. package/plugins/publishings/xiaoyuzhou-pub/dist/profile-check.js +11 -1
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "kk",
3
- "version": "0.1.20",
3
+ "version": "0.1.22",
4
4
  "description": "knowledge-kit Claude Code plugin: skills, commands, subagents, hooks, and rules"
5
5
  }
@@ -3,7 +3,7 @@
3
3
  <!-- kk-serve — keeps the knowledge-kit Spur server alive whenever this user is logged in.
4
4
 
5
5
  WHY the keepalive is not optional: the daily job `kk-daily-ai-voice` (cron `30 4 * * *`) is
6
- enqueued by the job worker that lives INSIDE `spur serve` (`.spur/config.yaml`
6
+ enqueued by the job worker that lives INSIDE `spur self serve` (`.spur/config.yaml`
7
7
  `bootstrap.scheduler`). On 2026-10-12 that process was SIGTERM'd at 00:17 local and not
8
8
  restarted until 10:00, so the 04:30 tick never fired and the day produced no episode at all —
9
9
  no workspace, no ledger row, no run record. `crontab -l` is empty and nothing else supervises
@@ -34,6 +34,7 @@
34
34
  <key>ProgramArguments</key>
35
35
  <array>
36
36
  <string>spur</string>
37
+ <string>self</string>
37
38
  <string>serve</string>
38
39
  <string>--cwd</string>
39
40
  <string>{{repo}}</string>
@@ -1,5 +1,5 @@
1
1
  import { spawnSync } from 'node:child_process';
2
- import { existsSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
2
+ import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
3
3
  import { tmpdir } from 'node:os';
4
4
  import { join, resolve } from 'node:path';
5
5
 
@@ -34,6 +34,221 @@ export const COVER_HEIGHT = 576;
34
34
  export const HEADLINE_LINE_CAP = 25;
35
35
  const FONT_STACK = `PingFang SC, Hiragino Sans GB, 'Noto Sans CJK SC', sans-serif`;
36
36
 
37
+ /** 0387 R1 — inset (px) between the shared crop intersection and the headline block. */
38
+ export const SAFE_MARGIN = 32;
39
+ /** Rows the headline may occupy inside the safe area (a 25-char point needs 3 at the 1:1 width). */
40
+ export const HEADLINE_MAX_ROWS = 3;
41
+ /** First-row size cap and the legibility floor the fit loop may shrink to. */
42
+ export const HEADLINE_FIRST_SIZE = 46;
43
+ export const HEADLINE_MIN_SIZE = 26;
44
+ /**
45
+ * 0387 R1 — the emblem is scaled down (was 72x50) and sits in the TOP-RIGHT corner. It keeps its
46
+ * own alpha: the old dark plate behind it (`fill-opacity="0.7"`) is gone, so the transparent
47
+ * emblem blends over the AI background instead of sitting on a chrome rectangle.
48
+ */
49
+ export const LOGO_WIDTH = 56;
50
+ export const LOGO_HEIGHT = 38;
51
+ export const LOGO_MARGIN = 24;
52
+
53
+ /** An axis-aligned pixel rectangle, integer edges (the form `sips --cropOffset` and SVG take). */
54
+ export interface Rect {
55
+ x: number;
56
+ y: number;
57
+ width: number;
58
+ height: number;
59
+ }
60
+
61
+ /** One target platform's center crop of the full cover. */
62
+ export interface PlatformCrop {
63
+ platform: 'wechat-mp' | 'podcast-site';
64
+ label: string;
65
+ aspect: number;
66
+ }
67
+
68
+ /**
69
+ * 0387 R8 — the two platforms crop the 1344x576 cover at its CENTER, so the headline belongs in
70
+ * the intersection of those crops, not in the full 21:9 frame:
71
+ * - WeChat MP re-crops the uploaded cover to a 2.35:1 header and a 1:1 feed image
72
+ * (`plugins/publishings/wechatmp-pub/src/cgi.ts:20` `WIDE_COVER_ASPECT`, `centerCropRect`).
73
+ * - the podcast site shows the episode artwork square (channel artwork ships 1400x1400,
74
+ * `docs/design/podcast-pub.md`), i.e. a 1:1 center crop of the same frame.
75
+ * The 1:1 crop is the tight one: it keeps only x 384..960 of the 1344-wide canvas.
76
+ */
77
+ export const TARGET_CROPS: readonly PlatformCrop[] = [
78
+ { platform: 'wechat-mp', label: '微信公众号 2.35:1 头图', aspect: 2.35 },
79
+ { platform: 'podcast-site', label: '播客站点 1:1 封面', aspect: 1 },
80
+ ];
81
+
82
+ /**
83
+ * Centered cover-fit rectangle for one target aspect ratio, from ACTUAL image dimensions. The
84
+ * same geometry as WeChat's upload path (`wechatmp-pub/src/cgi.ts` `centerCropRect`, task 0289 R2)
85
+ * — the publisher computes the `crop_multi` boxes from the real upload, so the safe area here and
86
+ * the boxes there agree by construction instead of by hand-measured pixels.
87
+ */
88
+ export function centerCropRect(width: number, height: number, aspect: number): Rect {
89
+ if (!Number.isFinite(width) || !Number.isFinite(height) || width < 1 || height < 1) {
90
+ throw new TypeError(`cover compositor: image dimensions must be positive, got ${width}x${height}`);
91
+ }
92
+ if (!Number.isFinite(aspect) || aspect <= 0) {
93
+ throw new TypeError(`cover compositor: crop aspect must be positive, got ${aspect}`);
94
+ }
95
+ const cropWidth = width / height > aspect ? height * aspect : width;
96
+ const cropHeight = width / height > aspect ? height : width / aspect;
97
+ const x = Math.floor((width - cropWidth) / 2);
98
+ const y = Math.floor((height - cropHeight) / 2);
99
+ return {
100
+ x,
101
+ y,
102
+ width: Math.min(width, Math.round(cropWidth)),
103
+ height: Math.min(height, Math.round(cropHeight)),
104
+ };
105
+ }
106
+
107
+ /**
108
+ * The region EVERY target crop keeps, inset by `margin`: the only area the headline may occupy.
109
+ * For the 1344x576 cover that is x 416..928 (512 wide) — a 25-char point needs ~1150px on one
110
+ * line, which is why the headline is centered and wrapped to this width instead of left-aligned.
111
+ */
112
+ export function safeAreaRect(
113
+ width = COVER_WIDTH,
114
+ height = COVER_HEIGHT,
115
+ crops: readonly PlatformCrop[] = TARGET_CROPS,
116
+ margin = SAFE_MARGIN,
117
+ ): Rect {
118
+ if (crops.length === 0) throw new TypeError('cover compositor: at least one target crop is required');
119
+ const rects = crops.map((crop) => centerCropRect(width, height, crop.aspect));
120
+ const left = Math.max(...rects.map((rect) => rect.x));
121
+ const top = Math.max(...rects.map((rect) => rect.y));
122
+ const right = Math.min(...rects.map((rect) => rect.x + rect.width));
123
+ const bottom = Math.min(...rects.map((rect) => rect.y + rect.height));
124
+ const inset = Math.max(0, Math.min(margin, Math.floor((right - left) / 4), Math.floor((bottom - top) / 4)));
125
+ return { x: left + inset, y: top + inset, width: right - left - 2 * inset, height: bottom - top - 2 * inset };
126
+ }
127
+
128
+ /** Top-right emblem geometry on the full cover (outside the 1:1 crop by design — R1 names the
129
+ * full cover for the badge, the crops for the headline point). */
130
+ export function logoRect(width = COVER_WIDTH): Rect {
131
+ return { x: width - LOGO_MARGIN - LOGO_WIDTH, y: LOGO_MARGIN, width: LOGO_WIDTH, height: LOGO_HEIGHT };
132
+ }
133
+
134
+ /** One laid-out headline row: the text plus the exact baseline/anchor the SVG must draw. */
135
+ export interface HeadlineRow {
136
+ text: string;
137
+ x: number;
138
+ y: number;
139
+ size: number;
140
+ weight: number;
141
+ fill: string;
142
+ /** Estimated rendered width in px — the same per-code-point estimate the fit loop uses. */
143
+ width: number;
144
+ }
145
+
146
+ export interface HeadlineLayout {
147
+ rows: HeadlineRow[];
148
+ /** Bounding box of the drawn rows — asserted to sit inside `safe`. */
149
+ block: Rect;
150
+ safe: Rect;
151
+ size: number;
152
+ /** True when the row budget ran out before the text did (an ellipsis was appended). */
153
+ truncated: boolean;
154
+ }
155
+
156
+ /** Greedy code-point wrap to `maxWidth`, at most `maxRows` rows; the tail is ellipsized on overflow. */
157
+ function wrapToRows(
158
+ text: string,
159
+ maxWidth: number,
160
+ size: number,
161
+ maxRows: number,
162
+ ): { rows: string[]; truncated: boolean } {
163
+ const chars = Array.from(text.replaceAll(/\s+/g, ' ').trim());
164
+ const rows: string[] = [];
165
+ let current = '';
166
+ let index = 0;
167
+ while (index < chars.length) {
168
+ const candidate = current + chars[index];
169
+ if (current === '' || estimateWidth(candidate, size) <= maxWidth) {
170
+ current = candidate;
171
+ index += 1;
172
+ continue;
173
+ }
174
+ rows.push(current);
175
+ current = chars[index] === ' ' ? '' : chars[index];
176
+ index += 1;
177
+ if (rows.length === maxRows) {
178
+ const rest = (current + chars.slice(index).join('')).trim();
179
+ let base = rows[maxRows - 1];
180
+ while (base !== '' && estimateWidth(`${base}…`, size) > maxWidth)
181
+ base = Array.from(base).slice(0, -1).join('');
182
+ let keep = '';
183
+ for (const ch of Array.from(rest)) {
184
+ if (estimateWidth(`${base}${keep}${ch}…`, size) > maxWidth) break;
185
+ keep += ch;
186
+ }
187
+ rows[maxRows - 1] = `${base}${keep}…`;
188
+ return { rows, truncated: rest !== '' };
189
+ }
190
+ }
191
+ if (current.trim() !== '') rows.push(current);
192
+ return { rows, truncated: false };
193
+ }
194
+
195
+ /**
196
+ * 0387 R1 — lay the headline out so both platform center crops keep the WHOLE point: rows are
197
+ * centered on the canvas midline, wrapped to the safe-area width, and vertically centered inside
198
+ * the safe area. `wrapHeadline` still owns the content contract (≤2 x 25 chars, explicit breaks);
199
+ * this adds the geometric fit on top of it.
200
+ */
201
+ export function layoutHeadline(headline: string, width = COVER_WIDTH, height = COVER_HEIGHT): HeadlineLayout {
202
+ const safe = safeAreaRect(width, height);
203
+ const source = wrapHeadline(headline).join(' ').trim();
204
+ if (source === '') {
205
+ return {
206
+ rows: [],
207
+ block: { x: safe.x, y: safe.y, width: 0, height: 0 },
208
+ safe,
209
+ size: HEADLINE_MIN_SIZE,
210
+ truncated: false,
211
+ };
212
+ }
213
+ let size = HEADLINE_FIRST_SIZE;
214
+ let wrapped = wrapToRows(source, safe.width, size, HEADLINE_MAX_ROWS);
215
+ while (wrapped.truncated && size > HEADLINE_MIN_SIZE) {
216
+ size -= 2;
217
+ wrapped = wrapToRows(source, safe.width, size, HEADLINE_MAX_ROWS);
218
+ }
219
+ const texts = wrapped.rows.filter((row) => row.trim() !== '');
220
+ const sizes = texts.map((_row, index) =>
221
+ index === 0 ? size : Math.max(HEADLINE_MIN_SIZE, Math.round(size * 0.8)),
222
+ );
223
+ const lineHeights = sizes.map((lineSize) => Math.round(lineSize * 1.28));
224
+ const blockHeight = lineHeights.reduce((sum, lineHeight) => sum + lineHeight, 0);
225
+ const top = safe.y + Math.round((safe.height - blockHeight) / 2);
226
+ const centerX = Math.round(width / 2);
227
+ let cursor = top;
228
+ const rows: HeadlineRow[] = texts.map((text, index) => {
229
+ const lineSize = sizes[index];
230
+ const row: HeadlineRow = {
231
+ text,
232
+ x: centerX,
233
+ y: cursor + Math.round(lineSize * 0.82),
234
+ size: lineSize,
235
+ weight: index === 0 ? 800 : 700,
236
+ fill: index === 0 ? '#FFFFFF' : '#FFB800',
237
+ width: Math.round(estimateWidth(text, lineSize)),
238
+ };
239
+ cursor += lineHeights[index];
240
+ return row;
241
+ });
242
+ const blockWidth = Math.max(...rows.map((row) => row.width));
243
+ return {
244
+ rows,
245
+ block: { x: Math.round(centerX - blockWidth / 2), y: top, width: blockWidth, height: blockHeight },
246
+ safe,
247
+ size,
248
+ truncated: wrapped.truncated,
249
+ };
250
+ }
251
+
37
252
  /** XML-escape a text node or attribute value (headlines are model-authored, so assume the worst). */
38
253
  function esc(text: string): string {
39
254
  return text.replaceAll('&', '&amp;').replaceAll('<', '&lt;').replaceAll('>', '&gt;').replaceAll('"', '&quot;');
@@ -63,8 +278,9 @@ export function wrapHeadline(headline: string): string[] {
63
278
  /**
64
279
  * Estimated rendered width in px for the mixed CJK/Latin headline: `sips` has no text metrics we
65
280
  * can read back, so each code point is charged its rough advance (CJK ≈ 1em, Latin ≈ 0.55em,
66
- * space ≈ 0.28em). Used only to shrink a line until it fits — a clipped headline is worse than a
67
- * smaller one (the 2026-11-12 regeneration clipped "Anthropic" at the canvas edge).
281
+ * space ≈ 0.28em). Used only to shrink a row until it fits the crop-safe width — a clipped
282
+ * headline is worse than a smaller one (the 2026-11-12 regeneration clipped "Anthropic" at the
283
+ * canvas edge).
68
284
  */
69
285
  function estimateWidth(text: string, fontSize: number): number {
70
286
  let em = 0;
@@ -76,13 +292,6 @@ function estimateWidth(text: string, fontSize: number): number {
76
292
  return em * fontSize;
77
293
  }
78
294
 
79
- /** Largest size <= `baseSize` at which `text` fits `maxWidth`, floored so it stays legible. */
80
- export function fitFontSize(text: string, baseSize: number, maxWidth: number, floorSize = 24): number {
81
- let size = baseSize;
82
- while (size > floorSize && estimateWidth(text, size) > maxWidth) size -= 1;
83
- return size;
84
- }
85
-
86
295
  /** Fixed-width chunker for CJK headlines — code points, not UTF-16 units. */
87
296
  function chunk(text: string): string[] {
88
297
  const chars = Array.from(text);
@@ -113,32 +322,36 @@ export function logoBadgeSvg(logoPath: string, x: number, y: number, width: numb
113
322
  return `<svg x="${x}" y="${y}" width="${width}" height="${height}" viewBox="0 0 1095 760" preserveAspectRatio="xMidYMid meet">${inner}</svg>`;
114
323
  }
115
324
 
116
- /** Deterministic SVG overlay: background image, bottom scrim, logo badge, headline, podcast tag. */
325
+ /**
326
+ * The shipped emblem, resolved from THIS module (repo root is three levels up from `plugins/kk/scripts`)
327
+ * so the badge renders no matter the process CWD. `existsSync` treats a relative path as CWD-relative,
328
+ * which is exactly how the badge went missing from shipped covers.
329
+ */
330
+ export const DEFAULT_LOGO_PATH = resolve(import.meta.dir, '..', '..', '..', 'assets', 'general', 'xhxs.svg');
331
+
332
+ /** Deterministic SVG overlay: background image, bottom scrim, top-right emblem, centered headline. */
117
333
  export function buildCoverSvg(options: CoverCompositorOptions): string {
118
334
  const width = options.width ?? COVER_WIDTH;
119
335
  const height = options.height ?? COVER_HEIGHT;
120
- const lines = wrapHeadline(options.headline);
121
- const logo = logoBadgeSvg(options.logoPath ?? 'assets/general/xhxs.svg', 48, 40, 72, 50);
336
+ const layout = layoutHeadline(options.headline, width, height);
337
+ const badge = logoRect(width);
338
+ // Resolve the default emblem from this module, never the CWD: the production caller passes no
339
+ // path, so a CWD-relative default silently omitted the badge from every shipped cover (0387 R1).
340
+ const logo = logoBadgeSvg(options.logoPath ?? DEFAULT_LOGO_PATH, badge.x, badge.y, badge.width, badge.height);
122
341
 
123
342
  // 2026-11-12 regression: `sips` drops EVERY `<text>` that carries an SVG filter, so the
124
343
  // headline never rasterized (both the 11-11 and 11-12 covers shipped chrome with no headline).
125
- // Contrast comes from the bottom scrim plus a geometric shadow — the same text drawn once in
126
- // dark behind the visible line — because that is plain geometry, not a filter.
127
- const line = (text: string, y: number, size: number, weight: number, fill: string): string =>
128
- `<text x="48" y="${y + 3}" font-family="${FONT_STACK}" font-size="${size}" font-weight="${weight}" fill="#000000" fill-opacity="0.72">${esc(text)}</text>
129
- <text x="48" y="${y}" font-family="${FONT_STACK}" font-size="${size}" font-weight="${weight}" fill="${fill}">${esc(text)}</text>`;
130
- const textWidth = width - 96;
131
- const typography =
132
- lines.length === 1
133
- ? line(lines[0], 500, fitFontSize(lines[0], 46, textWidth), 800, '#FFFFFF')
134
- : `${line(lines[0], 472, fitFontSize(lines[0], 46, textWidth), 800, '#FFFFFF')}
135
- ${line(lines[1], 532, fitFontSize(lines[1], 32, textWidth), 700, '#FFB800')}`;
136
-
137
- const badge =
138
- logo !== ''
139
- ? `<rect x="36" y="30" width="96" height="70" rx="12" fill="#0a1424" fill-opacity="0.7" />
140
- ${logo}`
141
- : '';
344
+ // Contrast comes from the scrim plus a geometric shadow — the same text drawn once in dark
345
+ // behind the visible line — because that is plain geometry, not a filter.
346
+ const row = (line: HeadlineRow): string =>
347
+ `<text x="${line.x}" y="${line.y + 3}" text-anchor="middle" font-family="${FONT_STACK}" font-size="${line.size}" font-weight="${line.weight}" fill="#000000" fill-opacity="0.72">${esc(line.text)}</text>
348
+ <text x="${line.x}" y="${line.y}" text-anchor="middle" font-family="${FONT_STACK}" font-size="${line.size}" font-weight="${line.weight}" fill="${line.fill}">${esc(line.text)}</text>`;
349
+ const typography = layout.rows.map(row).join('\n ');
350
+ // 0387 R1: the emblem is drawn straight onto the background — no plate behind it — so its own
351
+ // alpha is what the audience sees (the old `rect fill-opacity="0.7"` chrome is gone).
352
+ // 0387 R1: the scrim starts at 20% height because the headline now sits mid-frame (centered in
353
+ // the crop-safe column) instead of in the lower third.
354
+ const scrimTop = Math.round(height * 0.2);
142
355
 
143
356
  return `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}">
144
357
  <image href="${options.backgroundUri ?? encodeURI(`file://${resolve(options.backgroundImagePath)}`)}" x="0" y="0" width="${width}" height="${height}" preserveAspectRatio="xMidYMid slice" />
@@ -148,8 +361,8 @@ export function buildCoverSvg(options: CoverCompositorOptions): string {
148
361
  <stop offset="1" stop-color="#0a1424" stop-opacity="0.92" />
149
362
  </linearGradient>
150
363
  </defs>
151
- <rect x="0" y="${Math.round(height * 0.45)}" width="${width}" height="${height - Math.round(height * 0.45)}" fill="url(#bottomScrim)" />
152
- ${badge}
364
+ <rect x="0" y="${scrimTop}" width="${width}" height="${height - scrimTop}" fill="url(#bottomScrim)" />
365
+ ${logo}
153
366
  ${typography}
154
367
  <text x="${width - 48}" y="${height - 40}" text-anchor="end" font-family="${FONT_STACK}" font-size="18" font-weight="600" letter-spacing="2" fill="#FFFFFF" fill-opacity="0.85">DAILY AI PODCAST</text>
155
368
  </svg>
@@ -196,3 +409,138 @@ export function compositeCover(options: CoverCompositorOptions): string {
196
409
  }
197
410
  return options.outputPath;
198
411
  }
412
+
413
+ /** One platform crop preview written next to the full cover. */
414
+ export interface CoverCropPreview {
415
+ platform: PlatformCrop['platform'];
416
+ label: string;
417
+ aspect: number;
418
+ /** The rectangle this preview keeps of the full cover (centered, from the real dimensions). */
419
+ rect: Rect;
420
+ path: string;
421
+ }
422
+
423
+ export interface CoverPreviewManifest {
424
+ coverPath: string;
425
+ width: number;
426
+ height: number;
427
+ safeArea: Rect;
428
+ headlineBlock: Rect;
429
+ rows: number;
430
+ truncated: boolean;
431
+ crops: CoverCropPreview[];
432
+ /** Full cover rendered with the reference emblem fused in ('' when no emblem was supplied). */
433
+ referenceCoverPath: string;
434
+ /** Zoomed top-right corner of the reference cover: the alpha blend an operator compares. */
435
+ referenceBlendPath: string;
436
+ /** The emblem the reference artifacts used — the checked-in alpha fixture, never a fake banner. */
437
+ referenceLogoPath: string;
438
+ }
439
+
440
+ export interface CoverPreviewOptions extends CoverCompositorOptions {
441
+ /** Directory the inspectable artifacts land in (created when missing). */
442
+ previewDir: string;
443
+ /**
444
+ * 0387 R1 — the reference emblem. The operator's banner is absent on the build machine, so the
445
+ * deterministic verification fuses the checked-in transparent fixture
446
+ * (`plugins/kk/tests/fixtures/alpha-logo.svg`) and the REAL reference comparison stays a
447
+ * separate operator check. Omitted ⇒ no reference artifacts are claimed.
448
+ */
449
+ referenceLogoPath?: string;
450
+ }
451
+
452
+ /** Center-crop a rendered PNG to `rect` via `sips` (macOS-only, same tool as the render itself). */
453
+ function cropPng(source: string, rect: Rect, outputPath: string): void {
454
+ const sips = spawnSync(
455
+ 'sips',
456
+ [
457
+ '-c',
458
+ String(rect.height),
459
+ String(rect.width),
460
+ '--cropOffset',
461
+ String(rect.y),
462
+ String(rect.x),
463
+ source,
464
+ '--out',
465
+ outputPath,
466
+ ],
467
+ { stdio: 'ignore' },
468
+ );
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
+ }
479
+
480
+ /** The top-right corner window the reference-blend preview zooms into (emblem + its surroundings). */
481
+ export function referenceBlendRect(width = COVER_WIDTH, height = COVER_HEIGHT): Rect {
482
+ const badge = logoRect(width);
483
+ const x = Math.max(0, badge.x - 180);
484
+ return {
485
+ x,
486
+ y: Math.max(0, badge.y - 16),
487
+ width: Math.min(width - x, badge.width + 260),
488
+ height: Math.min(height - Math.max(0, badge.y - 16), badge.height + 130),
489
+ };
490
+ }
491
+
492
+ /**
493
+ * 0387 R1 — write the inspectable verification artifacts: the full cover, one center-crop preview
494
+ * per target platform (the exact rectangles `TARGET_CROPS`/`safeAreaRect` reason about), and the
495
+ * reference blend (the full cover plus a zoom of the fused emblem). Every artifact is a real PNG
496
+ * produced by the production compositor path — nothing here is a mock of the render.
497
+ */
498
+ export function writeCoverPreviews(options: CoverPreviewOptions): CoverPreviewManifest {
499
+ const width = options.width ?? COVER_WIDTH;
500
+ const height = options.height ?? COVER_HEIGHT;
501
+ const previewDir = resolve(options.previewDir);
502
+ mkdirSync(previewDir, { recursive: true });
503
+
504
+ const coverPath = join(previewDir, 'cover-full.png');
505
+ compositeCover({ ...options, outputPath: coverPath });
506
+
507
+ const crops: CoverCropPreview[] = TARGET_CROPS.map((crop) => {
508
+ const rect = centerCropRect(width, height, crop.aspect);
509
+ const path = join(previewDir, `crop-${crop.platform}.png`);
510
+ cropPng(coverPath, rect, path);
511
+ return { platform: crop.platform, label: crop.label, aspect: crop.aspect, rect, path };
512
+ });
513
+
514
+ let referenceCoverPath = '';
515
+ let referenceBlendPath = '';
516
+ let referenceLogoPath = '';
517
+ if (options.referenceLogoPath !== undefined && options.referenceLogoPath !== '') {
518
+ referenceLogoPath = resolve(options.referenceLogoPath);
519
+ if (!existsSync(referenceLogoPath)) {
520
+ throw new Error(
521
+ `cover compositor: reference emblem missing (${referenceLogoPath}); refuse to fake the blend`,
522
+ );
523
+ }
524
+ referenceCoverPath = join(previewDir, 'cover-reference.png');
525
+ compositeCover({ ...options, outputPath: referenceCoverPath, logoPath: referenceLogoPath });
526
+ referenceBlendPath = join(previewDir, 'reference-logo-blend.png');
527
+ cropPng(referenceCoverPath, referenceBlendRect(width, height), referenceBlendPath);
528
+ }
529
+
530
+ const layout = layoutHeadline(options.headline, width, height);
531
+ const manifest: CoverPreviewManifest = {
532
+ coverPath,
533
+ width,
534
+ height,
535
+ safeArea: layout.safe,
536
+ headlineBlock: layout.block,
537
+ rows: layout.rows.length,
538
+ truncated: layout.truncated,
539
+ crops,
540
+ referenceCoverPath,
541
+ referenceBlendPath,
542
+ referenceLogoPath,
543
+ };
544
+ writeFileSync(join(previewDir, 'manifest.json'), `${JSON.stringify(manifest, null, 4)}\n`, 'utf-8');
545
+ return manifest;
546
+ }
@@ -11,7 +11,7 @@ import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'no
11
11
  import { tmpdir } from 'node:os';
12
12
  import { basename, dirname, join, resolve } from 'node:path';
13
13
  import { parseArgs } from 'node:util';
14
- import { COVER_HEIGHT, COVER_WIDTH, compositeCover } from './cover-compositor';
14
+ import { COVER_HEIGHT, COVER_WIDTH, compositeCover, writeCoverPreviews } from './cover-compositor';
15
15
 
16
16
  interface MockOptions {
17
17
  headline: string;
@@ -19,8 +19,17 @@ interface MockOptions {
19
19
  out: string;
20
20
  provider: string;
21
21
  mockBg: boolean;
22
+ /** 0387 R1: when set, the inspectable crop/reference previews are written into this directory. */
23
+ previews: string;
22
24
  }
23
25
 
26
+ /**
27
+ * 0387 R1 — the checked-in TRANSPARENT emblem used as the reference for the blend previews. The
28
+ * operator's banner is absent on the build machine, so verification fuses this fixture and the
29
+ * real reference comparison stays a separate operator check (never a fabricated banner).
30
+ */
31
+ export const REFERENCE_LOGO_FIXTURE = join(import.meta.dir, '../tests/fixtures/alpha-logo.svg');
32
+
24
33
  const MOCK_BG_SVG = `<?xml version="1.0" encoding="UTF-8"?>
25
34
  <svg xmlns="http://www.w3.org/2000/svg" width="${COVER_WIDTH}" height="${COVER_HEIGHT}" viewBox="0 0 ${COVER_WIDTH} ${COVER_HEIGHT}">
26
35
  <defs>
@@ -49,6 +58,7 @@ function parseMockArgs(args: string[]): MockOptions {
49
58
  out: { type: 'string', default: '/tmp/kk-cover-mock.png' },
50
59
  provider: { type: 'string', default: '' },
51
60
  'mock-bg': { type: 'boolean', default: false },
61
+ previews: { type: 'string', default: '' },
52
62
  },
53
63
  strict: true,
54
64
  });
@@ -58,6 +68,7 @@ function parseMockArgs(args: string[]): MockOptions {
58
68
  out: resolve(values.out ?? ''),
59
69
  provider: values.provider ?? '',
60
70
  mockBg: values['mock-bg'] ?? false,
71
+ previews: values.previews ?? '',
61
72
  };
62
73
  }
63
74
 
@@ -123,7 +134,13 @@ function verifyOutput(outPath: string): { width: number; height: number } {
123
134
  return { width, height };
124
135
  }
125
136
 
126
- export function runMock(args: string[]): { out: string; width: number; height: number; background: string } {
137
+ export function runMock(args: string[]): {
138
+ out: string;
139
+ width: number;
140
+ height: number;
141
+ background: string;
142
+ previewDir: string;
143
+ } {
127
144
  const options = parseMockArgs(args);
128
145
  const parent = dirname(options.out);
129
146
  if (!existsSync(parent)) {
@@ -149,10 +166,30 @@ export function runMock(args: string[]): { out: string; width: number; height: n
149
166
  outputPath: options.out,
150
167
  });
151
168
  const { width, height } = verifyOutput(options.out);
169
+ // 0387 R1: the crop previews + reference blend are the verification artifacts — rendered
170
+ // from the SAME composite path, into an inspectable directory the operator can open.
171
+ if (options.previews !== '') {
172
+ const manifest = writeCoverPreviews({
173
+ backgroundImagePath: background,
174
+ headline: options.headline,
175
+ outputPath: options.out,
176
+ previewDir: options.previews,
177
+ referenceLogoPath: REFERENCE_LOGO_FIXTURE,
178
+ });
179
+ console.error(
180
+ `daily-cover-mock: previews ${manifest.coverPath} crops=${manifest.crops.map((crop) => `${crop.platform}:${crop.rect.width}x${crop.rect.height}`).join(',')} blend=${manifest.referenceBlendPath}`,
181
+ );
182
+ }
152
183
  console.error(
153
184
  `daily-cover-mock: composited ${options.out} (${width}x${height}, background=${options.mockBg ? 'mock' : options.provider || 'default'})`,
154
185
  );
155
- return { out: options.out, width, height, background: options.mockBg ? 'mock' : 'live' };
186
+ return {
187
+ out: options.out,
188
+ width,
189
+ height,
190
+ background: options.mockBg ? 'mock' : 'live',
191
+ previewDir: options.previews === '' ? '' : resolve(options.previews),
192
+ };
156
193
  } finally {
157
194
  rmSync(tmp, { recursive: true, force: true });
158
195
  }