@gobing-ai/knowledge-kit 0.1.20 → 0.1.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/dist/board/collect/index.js +1 -0
  3. package/dist/board/daily-voice/index.js +1279 -261
  4. package/dist/board/itc/index.js +1 -0
  5. package/dist/index.js +13938 -8966
  6. package/package.json +1 -1
  7. package/plugins/generations/dailynews-gen/dist/index.js +285 -16
  8. package/plugins/generations/dailynews-gen/src/editorial-claims.ts +215 -0
  9. package/plugins/generations/dailynews-gen/src/index.ts +23 -4
  10. package/plugins/generations/dailynews-gen/src/script-builder.ts +10 -3
  11. package/plugins/generations/dailynews-gen/src/script-plan.ts +74 -14
  12. package/plugins/generations/gemini-tts/dist/index.js +47 -7
  13. package/plugins/generations/gemini-tts/src/gemini-client.ts +34 -6
  14. package/plugins/generations/music-gen/README.md +277 -0
  15. package/plugins/generations/music-gen/dist/index.js +23580 -0
  16. package/plugins/generations/music-gen/package.json +24 -0
  17. package/plugins/generations/music-gen/plugin.json +23 -0
  18. package/plugins/generations/music-gen/presets/SOURCE.md +39 -0
  19. package/plugins/generations/music-gen/presets/formats/clip.yaml +21 -0
  20. package/plugins/generations/music-gen/presets/formats/jingle.yaml +22 -0
  21. package/plugins/generations/music-gen/presets/formats/loop.yaml +21 -0
  22. package/plugins/generations/music-gen/presets/formats/song.yaml +36 -0
  23. package/plugins/generations/music-gen/presets/formats/underscore.yaml +22 -0
  24. package/plugins/generations/music-gen/presets/themes/ambient-tech.yaml +30 -0
  25. package/plugins/generations/music-gen/presets/themes/cinematic.yaml +30 -0
  26. package/plugins/generations/music-gen/presets/themes/lofi.yaml +30 -0
  27. package/plugins/generations/music-gen/presets/themes/synthwave.yaml +35 -0
  28. package/plugins/generations/music-gen/scripts/gen-preset-index.ts +181 -0
  29. package/plugins/generations/music-gen/scripts/resolve-preset.ts +64 -0
  30. package/plugins/generations/music-gen/src/adapter/index.ts +35 -0
  31. package/plugins/generations/music-gen/src/adapter/instance.ts +927 -0
  32. package/plugins/generations/music-gen/src/adapter/offline.ts +124 -0
  33. package/plugins/generations/music-gen/src/artifact.ts +223 -0
  34. package/plugins/generations/music-gen/src/audio/checks.ts +618 -0
  35. package/plugins/generations/music-gen/src/audio/master.ts +267 -0
  36. package/plugins/generations/music-gen/src/audio/measure.ts +507 -0
  37. package/plugins/generations/music-gen/src/audio/profile.ts +131 -0
  38. package/plugins/generations/music-gen/src/audio.ts +122 -0
  39. package/plugins/generations/music-gen/src/brief.ts +191 -0
  40. package/plugins/generations/music-gen/src/config.ts +451 -0
  41. package/plugins/generations/music-gen/src/content.ts +199 -0
  42. package/plugins/generations/music-gen/src/digest.ts +100 -0
  43. package/plugins/generations/music-gen/src/index.ts +147 -0
  44. package/plugins/generations/music-gen/src/job.ts +131 -0
  45. package/plugins/generations/music-gen/src/plugin.ts +371 -0
  46. package/plugins/generations/music-gen/src/presets.ts +951 -0
  47. package/plugins/generations/music-gen/src/render.ts +87 -0
  48. package/plugins/generations/music-gen/src/request.ts +102 -0
  49. package/plugins/generations/music-gen/src/spend.ts +495 -0
  50. package/plugins/generations/music-gen/tsconfig.json +8 -0
  51. package/plugins/generations/omni-voice-gen/uv.toml +5 -0
  52. package/plugins/generations/vibe-voice-tts/README.md +64 -0
  53. package/plugins/generations/vibe-voice-tts/dist/index.js +14259 -0
  54. package/plugins/generations/vibe-voice-tts/package.json +16 -0
  55. package/plugins/generations/vibe-voice-tts/plugin.json +6 -0
  56. package/plugins/generations/vibe-voice-tts/profiles.json +10 -0
  57. package/plugins/generations/vibe-voice-tts/pyproject.toml +9 -0
  58. package/plugins/generations/vibe-voice-tts/python/worker.py +566 -0
  59. package/plugins/generations/vibe-voice-tts/src/index.ts +88 -0
  60. package/plugins/generations/vibe-voice-tts/src/vibevoice-client.ts +828 -0
  61. package/plugins/generations/vibe-voice-tts/tsconfig.json +8 -0
  62. package/plugins/generations/vibe-voice-tts/uv.lock +1767 -0
  63. package/plugins/generations/vibe-voice-tts/uv.toml +4 -0
  64. package/plugins/generations/voice-gen/dist/index.js +31 -1
  65. package/plugins/generations/voice-gen/src/voicebox-client.ts +50 -1
  66. package/plugins/generations/voxcpm-tts/dist/index.js +81 -9
  67. package/plugins/generations/voxcpm-tts/python/worker.py +9 -0
  68. package/plugins/generations/voxcpm-tts/src/index.ts +41 -0
  69. package/plugins/generations/voxcpm-tts/src/voxcpm-client.ts +32 -11
  70. package/plugins/generations/voxcpm-tts/uv.toml +5 -0
  71. package/plugins/kk/README.md +21 -0
  72. package/plugins/kk/decisions/kk-safety.yaml +5 -2
  73. package/plugins/kk/plugin.json +1 -1
  74. package/plugins/kk/schedules/kk-serve.launchd.plist.tmpl +14 -2
  75. package/plugins/kk/scripts/cover-compositor.ts +380 -32
  76. package/plugins/kk/scripts/daily-cover-mock.ts +40 -3
  77. package/plugins/kk/scripts/daily-stages.ts +933 -60
  78. package/plugins/kk/scripts/episode-identity.ts +180 -0
  79. package/plugins/kk/scripts/kk-workflow-stages.ts +111 -12
  80. package/plugins/kk/scripts/music-stages.ts +624 -0
  81. package/plugins/kk/scripts/news-editorial-ledger.ts +906 -0
  82. package/plugins/kk/scripts/safety-artifact-check.ts +28 -5
  83. package/plugins/kk/scripts/source-citation.ts +187 -0
  84. package/plugins/kk/scripts/topic-selection-attempts.ts +446 -0
  85. package/plugins/kk/scripts/topic-selection-calibration.ts +161 -0
  86. package/plugins/kk/skills/content-judge/SKILL.md +11 -6
  87. package/plugins/kk/skills/content-judge/references/music-quality-rubric.md +147 -0
  88. package/plugins/kk/skills/content-judge/references/rubrics.md +15 -0
  89. package/plugins/kk/skills/content-safety/SKILL.md +12 -0
  90. package/plugins/kk/skills/music-authoring/SKILL.md +276 -0
  91. package/plugins/kk/skills/music-authoring/references/judge-input.md +117 -0
  92. package/plugins/kk/skills/news-editorial/SKILL.md +102 -15
  93. package/plugins/kk/skills/news-editorial/references/selection.md +4 -0
  94. package/plugins/kk/skills/news-editorial/references/style-contract.zh.md +58 -11
  95. package/plugins/kk/workflows/kk-daily-ai-voice.yaml +12 -11
  96. package/plugins/kk/workflows/kk-daily-ai-voice2.yaml +13 -12
  97. package/plugins/kk/workflows/kk-daily-safety.yaml +12 -10
  98. package/plugins/kk/workflows/kk-music.yaml +332 -0
  99. package/plugins/kk/workflows/kk-news-generate.yaml +81 -6
  100. package/plugins/kk/workflows/kk-publish.yaml +4 -1
  101. package/plugins/publishings/bilibili-pub/dist/index.js +11 -1
  102. package/plugins/publishings/bilibili-pub/dist/profile-check.js +11 -1
  103. package/plugins/publishings/cnblogs-pub/dist/index.js +11 -1
  104. package/plugins/publishings/cnblogs-pub/dist/profile-check.js +11 -1
  105. package/plugins/publishings/csdn-pub/dist/index.js +11 -1
  106. package/plugins/publishings/csdn-pub/dist/profile-check.js +11 -1
  107. package/plugins/publishings/infoq-pub/dist/index.js +11 -1
  108. package/plugins/publishings/infoq-pub/dist/profile-check.js +11 -1
  109. package/plugins/publishings/jike-pub/dist/index.js +11 -1
  110. package/plugins/publishings/jike-pub/dist/profile-check.js +11 -1
  111. package/plugins/publishings/juejin-pub/dist/index.js +11 -1
  112. package/plugins/publishings/juejin-pub/dist/profile-check.js +11 -1
  113. package/plugins/publishings/linkedin-pub/dist/index.js +62 -10
  114. package/plugins/publishings/linkedin-pub/dist/profile-check.js +16 -1
  115. package/plugins/publishings/linkedin-pub/src/index.ts +99 -12
  116. package/plugins/publishings/podcast-pub/dist/index.js +586 -20
  117. package/plugins/publishings/podcast-pub/src/corrections.ts +509 -0
  118. package/plugins/publishings/podcast-pub/src/index.ts +257 -5
  119. package/plugins/publishings/podcast-pub/src/show-notes-brief.ts +240 -0
  120. package/plugins/publishings/podcast-pub/src/show-notes.ts +69 -13
  121. package/plugins/publishings/shipinhao-pub/dist/index.js +59 -8
  122. package/plugins/publishings/shipinhao-pub/dist/profile-check.js +11 -1
  123. package/plugins/publishings/shipinhao-pub/src/audio-flow.ts +105 -6
  124. package/plugins/publishings/sspai-pub/dist/index.js +11 -1
  125. package/plugins/publishings/sspai-pub/dist/profile-check.js +11 -1
  126. package/plugins/publishings/substack-pub/dist/index.js +11 -1
  127. package/plugins/publishings/substack-pub/dist/profile-check.js +11 -1
  128. package/plugins/publishings/surfdash-pub/dist/index.js +80 -24
  129. package/plugins/publishings/surfdash-pub/src/digest-check.ts +7 -3
  130. package/plugins/publishings/surfdash-pub/src/index.ts +107 -18
  131. package/plugins/publishings/surfdash-pub/src/patch.ts +21 -3
  132. package/plugins/publishings/surfdash-pub/src/topic-claims.ts +3 -1
  133. package/plugins/publishings/threads-pub/dist/index.js +58 -6
  134. package/plugins/publishings/threads-pub/dist/profile-check.js +18 -2
  135. package/plugins/publishings/threads-pub/src/post-rail.ts +101 -4
  136. package/plugins/publishings/wechatmp-pub/dist/index.js +105 -35
  137. package/plugins/publishings/wechatmp-pub/dist/profile-check.js +11 -1
  138. package/plugins/publishings/wechatmp-pub/src/cgi-draft.ts +87 -53
  139. package/plugins/publishings/wechatmp-pub/src/enrich.ts +61 -3
  140. package/plugins/publishings/wechatmp-pub/src/flow.ts +28 -0
  141. package/plugins/publishings/weibo-pub/dist/index.js +11 -1
  142. package/plugins/publishings/weibo-pub/dist/profile-check.js +11 -1
  143. package/plugins/publishings/x-pub/dist/index.js +95 -10
  144. package/plugins/publishings/x-pub/dist/profile-check.js +11 -1
  145. package/plugins/publishings/x-pub/src/post-rail.ts +154 -12
  146. package/plugins/publishings/xhs-pub/dist/index.js +11 -1
  147. package/plugins/publishings/xhs-pub/dist/profile-check.js +11 -1
  148. package/plugins/publishings/xiaoyuzhou-pub/dist/index.js +11 -1
  149. package/plugins/publishings/xiaoyuzhou-pub/dist/profile-check.js +11 -1
@@ -0,0 +1,180 @@
1
+ /**
2
+ * 0385 R4 — the daily episode's canonical, frozen identity.
3
+ *
4
+ * One episode is identified by its run date plus one headline point (「当日要点」) anchored to the
5
+ * admitted lead story. Every publishing surface (Chinese title, cover headline, ID3/RSS title, show
6
+ * notes) reads that single frozen record instead of deriving its own title, so the episode cannot
7
+ * carry two identities. Two failure modes are explicit, never silent:
8
+ *
9
+ * - `support-removed`: admission dropped the source(s) the headline rests on. The headline — and
10
+ * every field derived from it — is withheld (`title: null`); the caller must regenerate the
11
+ * headline from an admitted story or refuse to publish. It never keeps a title it cannot support.
12
+ * - `no-headline`: no point was frozen at all (a legacy bundle or a run without a script plan).
13
+ * `legacyTitle` is carried through untouched, so replaying an old bundle reproduces what aired.
14
+ *
15
+ * Retries and historical replay reuse the record already stamped in the bundle's metadata
16
+ * ({@link identityFromMetadata}) verbatim: a replayed episode keeps the identity it shipped with
17
+ * even when today's admission would compute a different one.
18
+ *
19
+ * Pure string work, node builtins only — no I/O, so the render and publish seams share it.
20
+ */
21
+
22
+ /** The frozen record; `version` pins the shape so a future change fails loud instead of drifting. */
23
+ export interface EpisodeIdentity {
24
+ version: 1;
25
+ /** The run date exactly as the caller supplied it (the episode date is frozen, never re-derived). */
26
+ date: string;
27
+ /** ISO-ish issue number in the Chinese title: `20261120` / `2026-11-20` → `261120`. */
28
+ issue: string;
29
+ /** The frozen 当日要点 (one line, ≤ {@link MAX_HEADLINE_CHARS}), or null when withheld. */
30
+ headline: string | null;
31
+ /** `第<issue>期 · <headline>`, or null when the headline had to be withheld. */
32
+ title: string | null;
33
+ /** The cover reuses the same point — never a second wording of it. */
34
+ coverHeadline: string | null;
35
+ /** The admitted source ids the headline rests on (empty when the caller named none). */
36
+ supportingSourceIds: string[];
37
+ status: 'frozen' | 'no-headline' | 'support-removed';
38
+ }
39
+
40
+ export interface EpisodeIdentityInput {
41
+ /** Run date, `YYYYMMDD` or `YYYY-MM-DD`. */
42
+ date: string;
43
+ /** The candidate 当日要点 (may still carry line breaks from the writer). */
44
+ headline?: string | null;
45
+ /** Source ids the headline rests on. Omitted/empty means "no claim made about support". */
46
+ supportingSourceIds?: readonly string[] | null;
47
+ /** Source ids the settled plan (admission) actually keeps. */
48
+ admittedSourceIds?: readonly string[] | null;
49
+ /** Pre-0385 title of the same episode, preserved for legacy bundles and replay. */
50
+ legacyTitle?: string | null;
51
+ }
52
+
53
+ /** The style contract caps the cover headline at 25 chars per line (0347 R4); the point is one line. */
54
+ export const MAX_HEADLINE_CHARS = 25;
55
+
56
+ /** Trim, collapse whitespace (writers emit wrapped `\n`), and drop a trailing sentence stop. */
57
+ function normalizeHeadline(raw: string): string {
58
+ return raw
59
+ .replaceAll(/\s+/g, ' ')
60
+ .trim()
61
+ .replace(/[。..、,,;;::·]+$/u, '')
62
+ .trim();
63
+ }
64
+
65
+ /** Code-point slice — a UTF-16 slice could split a surrogate pair in the middle of the title. */
66
+ function clip(text: string, max: number): string {
67
+ const points = [...text];
68
+ return points.length <= max ? text : `${points.slice(0, max - 1).join('')}…`;
69
+ }
70
+
71
+ /** The issue number of the frozen episode date, or `''` when the date carries no digits at all. */
72
+ export function issueNumberOf(date: string): string {
73
+ const digits = date.replaceAll(/\D/g, '');
74
+ return digits.length >= 6 ? digits.slice(-6) : '';
75
+ }
76
+
77
+ /** `第261120期` — the title's stable prefix, derived from the episode date only. */
78
+ export function issueLabel(date: string): string {
79
+ const issue = issueNumberOf(date);
80
+ return issue === '' ? '' : `第${issue}期`;
81
+ }
82
+
83
+ /**
84
+ * The Chinese publish title of one episode: `第261120期 · 当日要点`. Returns `''` when the point
85
+ * is empty, so a caller can never emit a dangling `第261120期 · `.
86
+ */
87
+ export function composeEpisodeTitle(date: string, headline: string): string {
88
+ const label = issueLabel(date);
89
+ const point = clip(normalizeHeadline(headline), MAX_HEADLINE_CHARS);
90
+ return label === '' || point === '' ? '' : `${label} · ${point}`;
91
+ }
92
+
93
+ /**
94
+ * Freeze one episode's identity. Deterministic: the same inputs always produce the same record,
95
+ * and only admission can withhold the title — never a re-worded fallback.
96
+ */
97
+ export function freezeEpisodeIdentity(input: EpisodeIdentityInput): EpisodeIdentity {
98
+ const date = input.date.trim();
99
+ const issue = issueNumberOf(date);
100
+ const headline = normalizeHeadline(input.headline ?? '');
101
+ const supportingSourceIds = [...new Set((input.supportingSourceIds ?? []).map((id) => id.trim()))].filter(
102
+ (id) => id !== '',
103
+ );
104
+ const legacyTitle = (input.legacyTitle ?? '').trim();
105
+
106
+ if (headline === '' || issue === '') {
107
+ return {
108
+ version: 1,
109
+ date,
110
+ issue,
111
+ headline: null,
112
+ title: legacyTitle === '' ? null : legacyTitle,
113
+ coverHeadline: null,
114
+ supportingSourceIds: [],
115
+ status: 'no-headline',
116
+ };
117
+ }
118
+
119
+ // Admission is only consulted when the caller said what the headline rests on; "no ids named"
120
+ // is not evidence that the support vanished (legacy plans carry no id on the cover at all).
121
+ const admitted = new Set((input.admittedSourceIds ?? []).map((id) => id.trim()).filter((id) => id !== ''));
122
+ const supportRemoved = supportingSourceIds.length > 0 && !supportingSourceIds.some((id) => admitted.has(id));
123
+ if (supportRemoved) {
124
+ return {
125
+ version: 1,
126
+ date,
127
+ issue,
128
+ headline: null,
129
+ title: null,
130
+ coverHeadline: null,
131
+ supportingSourceIds,
132
+ status: 'support-removed',
133
+ };
134
+ }
135
+
136
+ const point = clip(headline, MAX_HEADLINE_CHARS);
137
+ return {
138
+ version: 1,
139
+ date,
140
+ issue,
141
+ headline: point,
142
+ title: `${issueLabel(date)} · ${point}`,
143
+ coverHeadline: point,
144
+ supportingSourceIds,
145
+ status: 'frozen',
146
+ };
147
+ }
148
+
149
+ /**
150
+ * The identity a bundle already ships, read back from its `metadata.episode-identity` — the retry
151
+ * and historical-replay path. Anything unrecognizable returns null (the caller freezes afresh)
152
+ * instead of throwing: an old bundle must still replay.
153
+ */
154
+ export function identityFromMetadata(metadata: unknown): EpisodeIdentity | null {
155
+ if (metadata === null || typeof metadata !== 'object') return null;
156
+ const raw = (metadata as Record<string, unknown>).episodeIdentity;
157
+ if (raw === null || typeof raw !== 'object' || Array.isArray(raw)) return null;
158
+ const record = raw as Record<string, unknown>;
159
+ if (record.version !== 1) return null;
160
+ const status = record.status;
161
+ if (status !== 'frozen' && status !== 'no-headline' && status !== 'support-removed') return null;
162
+ if (typeof record.date !== 'string' || record.date.trim() === '') return null;
163
+ const text = (value: unknown): string | null => (typeof value === 'string' && value.trim() !== '' ? value : null);
164
+ const ids = Array.isArray(record.supportingSourceIds)
165
+ ? record.supportingSourceIds.filter((id): id is string => typeof id === 'string')
166
+ : [];
167
+ return {
168
+ version: 1,
169
+ date: record.date.trim(),
170
+ issue: typeof record.issue === 'string' ? record.issue : issueNumberOf(record.date),
171
+ headline: text(record.headline),
172
+ title: text(record.title),
173
+ coverHeadline: text(record.coverHeadline),
174
+ supportingSourceIds: ids,
175
+ status,
176
+ };
177
+ }
178
+
179
+ /** The metadata field the record is stamped under, so reader and writer cannot disagree. */
180
+ export const EPISODE_IDENTITY_KEY = 'episodeIdentity';
@@ -18,6 +18,8 @@
18
18
  * itc-publish-plan <work_dir> <targets> <source_locale> <publish_live> (0150, sibling)
19
19
  * itc-publish-fanout <work_dir> [--retry] (0151, sibling)
20
20
  * itc-publish-next <work_dir> (0151, sibling)
21
+ * music-* (0403, body in the sibling music-stages.ts): prepare/explore/select/
22
+ * analyze/judge-input/finalize for plugins/kk/workflows/kk-music.yaml
21
23
  *
22
24
  * `validate` / `wrap` / `render-storm` resolve the shipped sibling sidecars and delegate to them;
23
25
  * nothing about those sidecars changed. The `prepare-*` verbs and `duration` keep the logic that
@@ -55,7 +57,7 @@ import {
55
57
  writeFileSync,
56
58
  } from 'node:fs';
57
59
  import { homedir } from 'node:os';
58
- import { basename, dirname, join, resolve } from 'node:path';
60
+ import { basename, dirname, join, relative, resolve } from 'node:path';
59
61
  import { compositeCover } from './cover-compositor';
60
62
 
61
63
  export const SCRIPTS_DIR = import.meta.dir;
@@ -175,6 +177,19 @@ async function loadAudioQuality(): Promise<typeof import('./audio-quality.ts')>
175
177
  );
176
178
  }
177
179
  }
180
+ /**
181
+ * Load the music-* helper sibling lazily (task 0403): it owns the kk-music workflow's fan-out and
182
+ * artifact assembly, and an install that still ships only the core runner must not break on load.
183
+ */
184
+ async function loadMusicStages(): Promise<typeof import('./music-stages.ts')> {
185
+ try {
186
+ return await import('./music-stages.ts');
187
+ } catch {
188
+ return fail(
189
+ 'music-stages.ts not found next to kk-workflow-stages.ts — install or refresh the kk package (bun link in a checkout)',
190
+ );
191
+ }
192
+ }
178
193
  export const ERRNO_REASONS: Record<string, string> = {
179
194
  EACCES: 'Permission denied',
180
195
  EROFS: 'Read-only file system',
@@ -1646,6 +1661,35 @@ function publishMatrixPatchSurfdash(args: string[]): void {
1646
1661
  });
1647
1662
  }
1648
1663
 
1664
+ /**
1665
+ * The day's zh post path when this run's content sits uncommitted in the surfdash checkout.
1666
+ *
1667
+ * `surfdash-pub` writes the post and its `assets/` into the checkout before it syncs the CMS, and the
1668
+ * daily patch stage is the only step that commits them. A publish that fails, or a window whose plan
1669
+ * excludes the surfdash target, leaves the write behind with no commit, so the deploy never sees the
1670
+ * post — its `./assets/cover.png` 404s on the live site while the run reports only a warning. This
1671
+ * finds that state (untracked or modified paths under `content/posts` whose slug starts with the run
1672
+ * date) so the patch can heal it instead of looking at a missing receipt and skipping.
1673
+ */
1674
+ function strandedSurfdashPost(root: string, runDate: string): string | undefined {
1675
+ const listed = spawnSync('git', ['-C', root, 'status', '--porcelain', '-z', '--', 'content/posts'], {
1676
+ encoding: 'utf-8',
1677
+ });
1678
+ if (listed.status !== 0) return undefined;
1679
+ const slugs = new Set<string>();
1680
+ // `-z` entries are `XY <path>` NUL-separated, so the status prefix plus its space is 3 chars.
1681
+ for (const entry of (listed.stdout ?? '').split('\u0000')) {
1682
+ const match = /content\/posts\/articles\/(?:zh|en|ja)\/([^/]+)/.exec(entry.slice(3));
1683
+ const slug = match?.[1];
1684
+ if (slug?.startsWith(runDate)) slugs.add(slug);
1685
+ }
1686
+ for (const slug of slugs) {
1687
+ const zh = join(root, 'content', 'posts', 'articles', 'zh', slug, 'index.md');
1688
+ if (isFile(zh)) return zh;
1689
+ }
1690
+ return undefined;
1691
+ }
1692
+
1649
1693
  function dailyPatchSurfdash(args: string[]): void {
1650
1694
  const [workDir = '', runDate = '', surfdashRoot = '', pluginsPath = ''] = args;
1651
1695
  if (!surfdashRoot || !existsSync(surfdashRoot)) {
@@ -1668,20 +1712,30 @@ function dailyPatchSurfdash(args: string[]): void {
1668
1712
  )
1669
1713
  );
1670
1714
  };
1671
- if (invalidReceipt(sdResult) || invalidReceipt(podcastResult)) {
1672
- const error = 'patch-surfdash: malformed surfdash/podcast publish receipt — nothing to patch';
1673
- sted('write', resultPath, () => writeJqText(resultPath, { ok: false, target: 'surfdash-pub', error }));
1674
- console.error(error);
1675
- return;
1676
- }
1715
+ const sdUsable = !invalidReceipt(sdResult);
1716
+ const podUsable = !invalidReceipt(podcastResult);
1677
1717
  const targetOf = (path: string): Record<string, unknown> => {
1678
1718
  const parsed = readJson(path) as { targets?: Array<Record<string, unknown>> };
1679
1719
  return parsed.targets?.[0] ?? {};
1680
1720
  };
1681
- const sd = targetOf(sdResult);
1682
- const pod = targetOf(podcastResult);
1683
- const postPath = (sd.metadata as Record<string, unknown> | undefined)?.postPath;
1684
- if (typeof postPath !== 'string' || postPath === '') {
1721
+ const sd = sdUsable ? targetOf(sdResult) : {};
1722
+ const pod = podUsable ? targetOf(podcastResult) : {};
1723
+ const receiptPath = (sd.metadata as Record<string, unknown> | undefined)?.postPath;
1724
+ const fromReceipt = typeof receiptPath === 'string' && receiptPath !== '' ? receiptPath : undefined;
1725
+ // The publisher writes the post and its `assets/` into the checkout *before* it syncs the CMS,
1726
+ // and only this stage commits them. A publish that fails — or a window whose plan excludes the
1727
+ // surfdash target (2026-11-20: `not in --channels list`) — leaves that write behind with no
1728
+ // commit, so the deploy never sees the post and its `./assets/cover.png` 404s while the run
1729
+ // reports nothing worse than a warning. Heal that state instead of skipping it.
1730
+ const stranded = fromReceipt === undefined ? strandedSurfdashPost(surfdashRoot, runDate) : undefined;
1731
+ const postPath = fromReceipt ?? stranded;
1732
+ if (postPath === undefined) {
1733
+ if (!sdUsable || !podUsable) {
1734
+ const error = 'patch-surfdash: malformed surfdash/podcast publish receipt — nothing to patch';
1735
+ sted('write', resultPath, () => writeJqText(resultPath, { ok: false, target: 'surfdash-pub', error }));
1736
+ console.error(error);
1737
+ return;
1738
+ }
1685
1739
  // A surfdash publish that never landed (2026-10-21: its `git push` was rejected with
1686
1740
  // `fetch first`) leaves no postPath to patch. `publish-classify` has already recorded the
1687
1741
  // run as `partial`, and failing here turned a published podcast episode into a `failed`
@@ -1689,6 +1743,11 @@ function dailyPatchSurfdash(args: string[]): void {
1689
1743
  console.error('patch-surfdash: surfdash result carries no postPath — nothing to patch, skip');
1690
1744
  return;
1691
1745
  }
1746
+ if (fromReceipt === undefined) {
1747
+ console.error(
1748
+ `patch-surfdash: no surfdash publish receipt, but ${relative(surfdashRoot, postPath)} is uncommitted in the checkout — patching it so the deploy ships the post and its cover`,
1749
+ );
1750
+ }
1692
1751
  if (process.env.KK_SURFDASH_PATCH_OFFLINE === '1') {
1693
1752
  // The marker keeps the completeness report's cms-resync row honest in offline runs.
1694
1753
  const skipMarker = join(workDir, '31-publish', `${runDate}_23_patch-surfdash_emdash-resync.txt`);
@@ -1698,6 +1757,19 @@ function dailyPatchSurfdash(args: string[]): void {
1698
1757
  }
1699
1758
  const payload = join(workDir, '31-publish', `${runDate}_23_patch-surfdash_patch.json`);
1700
1759
  const podcastMeta = (pod.metadata ?? {}) as Record<string, unknown>;
1760
+ // 0385 R4: the episode's frozen identity title is what the podcast ships (`第<issue>期 · <headline>`).
1761
+ // The article states the same identity — the site renders it under its own SEO title, and the
1762
+ // zh cross-link names it — so the two surfaces cannot carry different episode names.
1763
+ const identity = readJson(join(workDir, '21-plan', `${runDate}_05_script_identity.json`)) as {
1764
+ title?: unknown;
1765
+ status?: unknown;
1766
+ } | null;
1767
+ const episodeTitle = identity?.status === 'frozen' && typeof identity.title === 'string' ? identity.title : '';
1768
+ if (episodeTitle === '') {
1769
+ console.error(
1770
+ `patch-surfdash: no frozen episode identity in 21-plan/${runDate}_05_script_identity.json — the article keeps the series · date wording`,
1771
+ );
1772
+ }
1701
1773
  sted('write', payload, () =>
1702
1774
  writeJqText(payload, {
1703
1775
  body: '',
@@ -1708,6 +1780,7 @@ function dailyPatchSurfdash(args: string[]): void {
1708
1780
  showNotesUrl: typeof pod.url === 'string' ? pod.url : '',
1709
1781
  dateIso: `${runDate.slice(0, 4)}-${runDate.slice(4, 6)}-${runDate.slice(6, 8)}`,
1710
1782
  localCover: join(workDir, '23-cover', `${runDate}_07_cover_cover.png`),
1783
+ episodeTitle,
1711
1784
  },
1712
1785
  }),
1713
1786
  );
@@ -1922,6 +1995,12 @@ if (import.meta.main)
1922
1995
  dailyEditorialRender(rest);
1923
1996
  break;
1924
1997
  }
1998
+ case 'news-editorial-commit': {
1999
+ // 0384 R4/R10: the judgment commit is async (the ledger's LockPort is promise-shaped).
2000
+ const { newsEditorialCommit } = await loadDailyStages();
2001
+ await newsEditorialCommit(rest);
2002
+ break;
2003
+ }
1925
2004
  case 'daily-script': {
1926
2005
  const { dailyScript } = await loadDailyStages();
1927
2006
  dailyScript(rest);
@@ -2043,6 +2122,11 @@ if (import.meta.main)
2043
2122
  case 'daily-publish-completeness':
2044
2123
  dailyPublishCompleteness(rest);
2045
2124
  break;
2125
+ case 'audio-prune': {
2126
+ const { dailyAudioPrune } = await loadDailyStages();
2127
+ dailyAudioPrune(rest);
2128
+ break;
2129
+ }
2046
2130
  case 'daily-patch-surfdash':
2047
2131
  dailyPatchSurfdash(rest);
2048
2132
  break;
@@ -2078,6 +2162,11 @@ if (import.meta.main)
2078
2162
  dailyTranslateValidate(rest);
2079
2163
  break;
2080
2164
  }
2165
+ case 'news-localize-validate': {
2166
+ const { newsLocalizeValidate } = await loadDailyStages();
2167
+ newsLocalizeValidate(rest);
2168
+ break;
2169
+ }
2081
2170
  case 'itc-outline-pick': {
2082
2171
  const { itcOutlinePick } = await loadItcStages();
2083
2172
  itcOutlinePick(rest);
@@ -2113,6 +2202,16 @@ if (import.meta.main)
2113
2202
  itcAdaptVerify(rest);
2114
2203
  break;
2115
2204
  }
2205
+ case 'music-prepare':
2206
+ case 'music-explore':
2207
+ case 'music-select':
2208
+ case 'music-analyze':
2209
+ case 'music-judge-input':
2210
+ case 'music-finalize': {
2211
+ const { runMusicStage } = await loadMusicStages();
2212
+ runMusicStage(stage, rest);
2213
+ break;
2214
+ }
2116
2215
  case 'seo-preflight':
2117
2216
  case 'seo-collect':
2118
2217
  case 'seo-check':
@@ -2132,6 +2231,6 @@ if (import.meta.main)
2132
2231
  }
2133
2232
  default:
2134
2233
  fail(
2135
- `unknown stage: ${stage ?? '(none)'} (expected prepare-itc|prepare-solo|prepare-storm|validate|wrap|duration|render-storm|itc-*|daily-*|seo-*)`,
2234
+ `unknown stage: ${stage ?? '(none)'} (expected prepare-itc|prepare-solo|prepare-storm|validate|wrap|duration|render-storm|itc-*|daily-*|seo-*|music-*)`,
2136
2235
  );
2137
2236
  }