@gobing-ai/knowledge-kit 0.1.22 → 0.1.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +1 -1
- package/dist/index.js +282 -147
- package/package.json +5 -5
- package/plugins/generations/content-gen/dist/index.js +9 -9
- package/plugins/generations/core-facts-gen/dist/index.js +12 -12
- package/plugins/generations/daily-article-gen/dist/index.js +12 -12
- package/plugins/generations/dailynews-gen/dist/index.js +11 -11
- package/plugins/generations/dailynews-gen/src/script-plan.ts +2 -2
- package/plugins/generations/episode-plan-gen/dist/index.js +12 -12
- package/plugins/generations/gemini-tts/dist/index.js +56 -16
- package/plugins/generations/gemini-tts/src/gemini-client.ts +34 -6
- package/plugins/generations/image-gen/dist/index.js +9 -9
- package/plugins/generations/music-gen/README.md +2 -2
- package/plugins/generations/music-gen/dist/index.js +62 -26
- package/plugins/generations/music-gen/presets/formats/song.yaml +6 -1
- package/plugins/generations/music-gen/presets/themes/synthwave.yaml +6 -1
- package/plugins/generations/music-gen/src/adapter/instance.ts +34 -11
- package/plugins/generations/music-gen/src/presets.ts +36 -3
- package/plugins/generations/news-report-gen/dist/index.js +12 -12
- package/plugins/generations/omni-voice-gen/uv.toml +5 -0
- package/plugins/generations/vibe-voice-tts/README.md +64 -0
- package/plugins/generations/vibe-voice-tts/dist/index.js +14259 -0
- package/plugins/generations/vibe-voice-tts/package.json +16 -0
- package/plugins/generations/vibe-voice-tts/plugin.json +6 -0
- package/plugins/generations/vibe-voice-tts/profiles.json +10 -0
- package/plugins/generations/vibe-voice-tts/pyproject.toml +9 -0
- package/plugins/generations/vibe-voice-tts/python/worker.py +566 -0
- package/plugins/generations/vibe-voice-tts/src/index.ts +88 -0
- package/plugins/generations/vibe-voice-tts/src/vibevoice-client.ts +828 -0
- package/plugins/generations/vibe-voice-tts/tsconfig.json +8 -0
- package/plugins/generations/vibe-voice-tts/uv.lock +1767 -0
- package/plugins/generations/vibe-voice-tts/uv.toml +4 -0
- package/plugins/generations/voice-gen/dist/index.js +40 -10
- package/plugins/generations/voice-gen/src/voicebox-client.ts +50 -1
- package/plugins/generations/voxcpm-tts/dist/index.js +90 -18
- package/plugins/generations/voxcpm-tts/python/worker.py +9 -0
- package/plugins/generations/voxcpm-tts/src/index.ts +41 -0
- package/plugins/generations/voxcpm-tts/src/voxcpm-client.ts +32 -11
- package/plugins/generations/voxcpm-tts/uv.toml +5 -0
- package/plugins/ingestions/aihot-ingest/dist/index.js +12 -12
- package/plugins/ingestions/horizon-ingest/dist/index.js +12 -12
- package/plugins/ingestions/karakeep-local/dist/index.js +13 -13
- package/plugins/ingestions/last30days-ingest/dist/index.js +12 -12
- package/plugins/ingestions/web-search/dist/index.js +10 -10
- package/plugins/kk/README.md +21 -0
- package/plugins/kk/decisions/kk-safety.yaml +5 -2
- package/plugins/kk/plugin.json +1 -1
- package/plugins/kk/publish-presets/daily-ai-voice.json +16 -16
- package/plugins/kk/schedules/kk-serve.launchd.plist.tmpl +12 -1
- package/plugins/kk/scripts/cover-compositor.ts +104 -26
- package/plugins/kk/scripts/daily-stages.ts +481 -63
- package/plugins/kk/scripts/kk-workflow-stages.ts +218 -17
- package/plugins/kk/scripts/safety-artifact-check.ts +28 -5
- package/plugins/kk/scripts/series-names.ts +16 -3
- package/plugins/kk/skills/news-editorial/SKILL.md +1 -1
- package/plugins/kk/skills/news-editorial/references/style-contract.zh.md +3 -3
- package/plugins/kk/workflows/kk-daily-ai-voice.yaml +4 -3
- package/plugins/kk/workflows/kk-daily-ai-voice2.yaml +6 -5
- package/plugins/kk/workflows/kk-daily-safety.yaml +12 -10
- package/plugins/kk/workflows/kk-music.yaml +20 -16
- package/plugins/kk/workflows/kk-news-generate.yaml +26 -3
- package/plugins/kk/workflows/kk-publish.yaml +4 -1
- package/plugins/publishings/bilibili-pub/dist/index.js +22 -22
- package/plugins/publishings/bilibili-pub/dist/profile-check.js +22 -22
- package/plugins/publishings/cnblogs-pub/dist/index.js +22 -22
- package/plugins/publishings/cnblogs-pub/dist/profile-check.js +22 -22
- package/plugins/publishings/csdn-pub/dist/index.js +22 -22
- package/plugins/publishings/csdn-pub/dist/profile-check.js +22 -22
- package/plugins/publishings/emdash-pub/dist/index.js +9 -9
- package/plugins/publishings/infoq-pub/dist/index.js +22 -22
- package/plugins/publishings/infoq-pub/dist/profile-check.js +22 -22
- package/plugins/publishings/jike-pub/dist/index.js +22 -22
- package/plugins/publishings/jike-pub/dist/profile-check.js +22 -22
- package/plugins/publishings/juejin-pub/dist/index.js +22 -22
- package/plugins/publishings/juejin-pub/dist/profile-check.js +22 -22
- package/plugins/publishings/linkedin-pub/dist/index.js +133 -33
- package/plugins/publishings/linkedin-pub/dist/profile-check.js +27 -22
- package/plugins/publishings/linkedin-pub/src/index.ts +192 -18
- package/plugins/publishings/medium-pub/dist/index.js +9 -9
- package/plugins/publishings/podcast-pub/dist/index.js +240 -37
- package/plugins/publishings/podcast-pub/src/index.ts +154 -3
- package/plugins/publishings/podcast-pub/src/seo.ts +25 -8
- package/plugins/publishings/podcast-pub/src/show-notes-brief.ts +93 -23
- package/plugins/publishings/podcast-pub/src/show-notes.ts +26 -6
- package/plugins/publishings/qiita-pub/dist/index.js +9 -9
- package/plugins/publishings/shipinhao-pub/dist/index.js +23 -23
- package/plugins/publishings/shipinhao-pub/dist/profile-check.js +23 -23
- package/plugins/publishings/shipinhao-pub/src/selectors.ts +2 -1
- package/plugins/publishings/sspai-pub/dist/index.js +22 -22
- package/plugins/publishings/sspai-pub/dist/profile-check.js +22 -22
- package/plugins/publishings/substack-pub/dist/index.js +22 -22
- package/plugins/publishings/substack-pub/dist/profile-check.js +22 -22
- package/plugins/publishings/surfdash-pub/dist/index.js +207 -95
- package/plugins/publishings/surfdash-pub/src/digest-check.ts +30 -1
- package/plugins/publishings/surfdash-pub/src/index.ts +101 -76
- package/plugins/publishings/surfdash-pub/src/media-upload.ts +83 -0
- package/plugins/publishings/surfdash-pub/src/patch.ts +49 -26
- package/plugins/publishings/surfdash-pub/src/topic-claims.ts +12 -4
- package/plugins/publishings/threads-pub/dist/index.js +83 -27
- package/plugins/publishings/threads-pub/dist/profile-check.js +34 -23
- package/plugins/publishings/threads-pub/src/post-rail.ts +121 -4
- package/plugins/publishings/wechatmp-pub/dist/index.js +274 -98
- package/plugins/publishings/wechatmp-pub/dist/profile-check.js +27 -23
- package/plugins/publishings/wechatmp-pub/src/cgi-draft.ts +87 -53
- package/plugins/publishings/wechatmp-pub/src/enrich.ts +117 -13
- package/plugins/publishings/wechatmp-pub/src/flow.ts +183 -43
- package/plugins/publishings/wechatmp-pub/src/modes.ts +30 -12
- package/plugins/publishings/weibo-pub/dist/index.js +22 -22
- package/plugins/publishings/weibo-pub/dist/profile-check.js +22 -22
- package/plugins/publishings/x-pub/dist/index.js +113 -32
- package/plugins/publishings/x-pub/dist/profile-check.js +22 -22
- package/plugins/publishings/x-pub/src/post-rail.ts +155 -20
- package/plugins/publishings/xhs-pub/dist/index.js +22 -22
- package/plugins/publishings/xhs-pub/dist/profile-check.js +22 -22
- package/plugins/publishings/xiaoyuzhou-pub/dist/index.js +22 -22
- package/plugins/publishings/xiaoyuzhou-pub/dist/profile-check.js +22 -22
- package/plugins/publishings/zenn-pub/dist/index.js +9 -9
|
@@ -12,38 +12,24 @@
|
|
|
12
12
|
* `bun run check:content` in the surfdash checkout. The surfdash site gate is the authoritative
|
|
13
13
|
* validation suite before deployment.
|
|
14
14
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* A build/retitle failure fails the run before anything is committed or pushed. See
|
|
20
|
-
* `./topic-claims` for the file work.
|
|
21
|
-
*
|
|
22
|
-
* Environment variables:
|
|
23
|
-
* - `SURFDASH_LISTEN_BACKFILL`:
|
|
24
|
-
* - `off`: skips the listen-link backfill command.
|
|
25
|
-
* - `SURFDASH_DIGEST_CHECK`:
|
|
26
|
-
* - unset / default: fail-loud on gate failure; commit and push are blocked.
|
|
27
|
-
* - `warn`: echoes gate failures via `echoError` prefixed with `site gate (warn):` and continues.
|
|
28
|
-
* - `off`: bypasses the gate check.
|
|
29
|
-
* - Both escape hatches are IGNORED while this run pushes to surfdash `main`
|
|
30
|
-
* (`SURFDASH_AUTO_PUSH !== '0'` and the checkout is on `main`): a failing gate always
|
|
31
|
-
* blocks there, and `off` still runs the gate.
|
|
32
|
-
* - `SURFDASH_AUTO_PUSH`:
|
|
33
|
-
* - '0': disables auto-commit and push (used in tests and offline runs).
|
|
15
|
+
* Cover hosting:
|
|
16
|
+
* Digests share remote `https://podcast-media.salty.vip/...` covers rather than committing
|
|
17
|
+
* `assets/cover.png` binaries into git. Local fallback covers upload to Microfeed via
|
|
18
|
+
* `./media-upload` before frontmatter is written.
|
|
34
19
|
*/
|
|
35
20
|
import { createHash } from 'node:crypto';
|
|
36
21
|
import { existsSync, readFileSync } from 'node:fs';
|
|
37
|
-
import {
|
|
38
|
-
import { dirname, extname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
22
|
+
import { writeFile } from 'node:fs/promises';
|
|
23
|
+
import { basename, dirname, extname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
39
24
|
import { parseArgs } from 'node:util';
|
|
40
25
|
import { type Content, ContentSchema, type Result, ResultSchema } from '@gobing-ai/kk-core';
|
|
41
26
|
import type { PublishTransport, PublishTransportPayload } from '@gobing-ai/publish-harness';
|
|
42
27
|
import { createNodeFileSystem } from '@gobing-ai/ts-runtime';
|
|
43
28
|
import { echoError } from '@gobing-ai/ts-utils';
|
|
44
29
|
// The plugin's public digest-contract surface (2026-10-24).
|
|
45
|
-
import { checkDigestFrontmatter, DIGEST_TAG, type DigestLocale } from './digest-check';
|
|
46
|
-
import {
|
|
30
|
+
import { checkDigestFrontmatter, DIGEST_TAG, type DigestLocale, isEpisodeIdentityTitle } from './digest-check';
|
|
31
|
+
import { uploadCoverToMicrofeed } from './media-upload';
|
|
32
|
+
import { crossLinkFor, localeIndexPath, PATCH_LOCALES, type PatchPostOutcome, patchPostFiles } from './patch';
|
|
47
33
|
import { buildDailyTopicsEntry, isDigestMarkdown, slugFromPostPath, upsertDailyTopicsEntry } from './topic-claims';
|
|
48
34
|
|
|
49
35
|
export { checkDigestFrontmatter, DIGEST_TAG, type DigestLocale } from './digest-check';
|
|
@@ -97,6 +83,8 @@ interface SurfdashPubOptions {
|
|
|
97
83
|
localCover?: unknown;
|
|
98
84
|
/** `patch`: `YYYY-MM-DD` episode date for the cross-link text. */
|
|
99
85
|
dateIso?: unknown;
|
|
86
|
+
/** `patch`: the episode's frozen identity title (0385 R4); the zh post's `episode_title`. */
|
|
87
|
+
episodeTitle?: unknown;
|
|
100
88
|
}
|
|
101
89
|
|
|
102
90
|
/**
|
|
@@ -105,10 +93,12 @@ interface SurfdashPubOptions {
|
|
|
105
93
|
export interface MapContentOptions {
|
|
106
94
|
/** Target publishing site name or base URL. Defaults to 'surfdash'. */
|
|
107
95
|
targetName?: string;
|
|
108
|
-
/** Frontmatter
|
|
96
|
+
/** Frontmatter remote cover URL (`https://podcast-media.salty.vip/...`); written to `image` and `og_image`. */
|
|
109
97
|
image?: string;
|
|
110
98
|
/** ISO date for publishDate; defaults to today. */
|
|
111
99
|
publishDate?: string;
|
|
100
|
+
/** Locale directory this post belongs to (`zh` / `en` / `ja`). Defaults to `zh`. */
|
|
101
|
+
locale?: SupportedLocale;
|
|
112
102
|
}
|
|
113
103
|
|
|
114
104
|
/**
|
|
@@ -193,6 +183,25 @@ export function mapContentToSurfingMarkdown(content: Content, options: MapConten
|
|
|
193
183
|
// source and would have dropped the post out of the sitemap if surfdash's refine step had
|
|
194
184
|
// not overwritten it. See docs/00_ADR.md ADR-008: the generator supplies content, the site
|
|
195
185
|
// supplies identity.
|
|
186
|
+
const postLocale = options.locale ?? 'zh';
|
|
187
|
+
const rawEpisodeTitle =
|
|
188
|
+
typeof content.metadata?.episodeTitle === 'string' && content.metadata.episodeTitle.trim() !== ''
|
|
189
|
+
? content.metadata.episodeTitle.trim()
|
|
190
|
+
: typeof content.metadata?.episode_title === 'string' && content.metadata.episode_title.trim() !== ''
|
|
191
|
+
? content.metadata.episode_title.trim()
|
|
192
|
+
: '';
|
|
193
|
+
const podcastUrl =
|
|
194
|
+
typeof content.metadata?.podcastUrl === 'string' && /^https:\/\//.test(content.metadata.podcastUrl)
|
|
195
|
+
? content.metadata.podcastUrl
|
|
196
|
+
: '';
|
|
197
|
+
|
|
198
|
+
const episodeTitleForLocale =
|
|
199
|
+
postLocale === 'zh'
|
|
200
|
+
? rawEpisodeTitle || (isEpisodeIdentityTitle(title, 'zh') ? title : '')
|
|
201
|
+
: isEpisodeIdentityTitle(title, postLocale)
|
|
202
|
+
? title
|
|
203
|
+
: '';
|
|
204
|
+
|
|
196
205
|
const frontmatterObj: Record<string, unknown> = {
|
|
197
206
|
title,
|
|
198
207
|
description,
|
|
@@ -200,10 +209,15 @@ export function mapContentToSurfingMarkdown(content: Content, options: MapConten
|
|
|
200
209
|
publishDate: isoDate,
|
|
201
210
|
draft,
|
|
202
211
|
...(options.image ? { image: options.image, og_image: options.image } : {}),
|
|
212
|
+
...(episodeTitleForLocale !== '' ? { episode_title: episodeTitleForLocale } : {}),
|
|
203
213
|
};
|
|
204
214
|
|
|
205
215
|
const yamlLines = ['---', ...Object.entries(frontmatterObj).map(([k, v]) => `${k}: ${JSON.stringify(v)}`), '---'];
|
|
206
|
-
|
|
216
|
+
let bodyText = content.body.trim();
|
|
217
|
+
if (podcastUrl !== '' && !bodyText.includes(podcastUrl)) {
|
|
218
|
+
bodyText = `${bodyText}\n\n${crossLinkFor(postLocale, isoDate, podcastUrl, rawEpisodeTitle)}`;
|
|
219
|
+
}
|
|
220
|
+
return `${yamlLines.join('\n')}\n\n${bodyText}\n`;
|
|
207
221
|
}
|
|
208
222
|
|
|
209
223
|
/** True when the content's tag sources (contentTags) mark it as a daily digest post. */
|
|
@@ -904,10 +918,6 @@ async function scaffoldLocale(options: SurfdashPubOptions): Promise<Result> {
|
|
|
904
918
|
if (!existsSync(draftPath)) {
|
|
905
919
|
return fail(`sd translate reported success but the draft is missing: ${draftPath}`);
|
|
906
920
|
}
|
|
907
|
-
const assetsDir = join(dirname(postPath.postPath), 'assets');
|
|
908
|
-
if (existsSync(assetsDir)) {
|
|
909
|
-
await cp(assetsDir, join(dirname(draftPath), 'assets'), { recursive: true });
|
|
910
|
-
}
|
|
911
921
|
return ResultSchema.parse({
|
|
912
922
|
ok: true,
|
|
913
923
|
target: TARGET,
|
|
@@ -1001,7 +1011,10 @@ async function syncPost(options: SurfdashPubOptions): Promise<Result> {
|
|
|
1001
1011
|
}
|
|
1002
1012
|
|
|
1003
1013
|
/** `options.<key>` when it is a string, trimmed; else ''. `patch`'s four optional fields read this way. */
|
|
1004
|
-
function strOption(
|
|
1014
|
+
function strOption(
|
|
1015
|
+
options: SurfdashPubOptions,
|
|
1016
|
+
key: 'coverUrl' | 'showNotesUrl' | 'localCover' | 'dateIso' | 'episodeTitle',
|
|
1017
|
+
): string {
|
|
1005
1018
|
const raw = options[key];
|
|
1006
1019
|
return typeof raw === 'string' ? raw.trim() : '';
|
|
1007
1020
|
}
|
|
@@ -1036,26 +1049,15 @@ async function patchPost(options: SurfdashPubOptions): Promise<Result> {
|
|
|
1036
1049
|
showNotesUrl: strOption(options, 'showNotesUrl'),
|
|
1037
1050
|
localCover: strOption(options, 'localCover'),
|
|
1038
1051
|
dateIso: strOption(options, 'dateIso'),
|
|
1052
|
+
episodeTitle: strOption(options, 'episodeTitle'),
|
|
1053
|
+
uploadLocalCover: uploadCoverToMicrofeed,
|
|
1039
1054
|
});
|
|
1040
1055
|
} catch (error: unknown) {
|
|
1041
1056
|
return fail(`patch error: ${error instanceof Error ? error.message : String(error)}`);
|
|
1042
1057
|
}
|
|
1043
1058
|
if (outcome.changed === 0) echoError(`patch: no post bytes changed for ${outcome.slug}`);
|
|
1044
|
-
// Daily-topics map + retitle run before the CMS sync so the synced rows carry the retitled
|
|
1045
|
-
// frontmatter; a failure here must not commit or push a half-synced post.
|
|
1046
|
-
const topics = await runDailyTopicsSync(surfdashRoot, postPath.postPath);
|
|
1047
|
-
if (!topics.ok) return fail(topics.error);
|
|
1048
1059
|
const synced = await syncPost({ postPath: postPath.postPath });
|
|
1049
1060
|
const commitPaths = new Set(outcome.written.map((path) => relative(surfdashRoot, path)));
|
|
1050
|
-
for (const p of topics.paths) commitPaths.add(p);
|
|
1051
|
-
for (const locale of PATCH_LOCALES) {
|
|
1052
|
-
const indexMd = localeIndexPath(postPath.postPath, locale);
|
|
1053
|
-
if (!indexMd) continue;
|
|
1054
|
-
const assetsDir = join(dirname(indexMd), 'assets');
|
|
1055
|
-
if (existsSync(assetsDir)) {
|
|
1056
|
-
commitPaths.add(relative(surfdashRoot, assetsDir));
|
|
1057
|
-
}
|
|
1058
|
-
}
|
|
1059
1061
|
if (process.env.SURFDASH_AUTO_PUSH !== '0') {
|
|
1060
1062
|
const backfilled = await runListenLinkBackfill(surfdashRoot);
|
|
1061
1063
|
for (const p of backfilled) commitPaths.add(p);
|
|
@@ -1313,7 +1315,8 @@ function readLocaleDrafts(content: Content): Partial<Record<(typeof LOCAL_DRAFTS
|
|
|
1313
1315
|
async function mintLocalePost(options: {
|
|
1314
1316
|
postDir: string;
|
|
1315
1317
|
content: Content;
|
|
1316
|
-
|
|
1318
|
+
coverUrl?: string;
|
|
1319
|
+
locale?: SupportedLocale;
|
|
1317
1320
|
publishDate?: string;
|
|
1318
1321
|
}): Promise<void> {
|
|
1319
1322
|
const filePath = join(options.postDir, 'index.md');
|
|
@@ -1322,16 +1325,9 @@ async function mintLocalePost(options: {
|
|
|
1322
1325
|
return;
|
|
1323
1326
|
}
|
|
1324
1327
|
await createNodeFileSystem().ensureDir(options.postDir);
|
|
1325
|
-
let imageFrontmatter: string | undefined;
|
|
1326
|
-
if (options.coverPath !== undefined) {
|
|
1327
|
-
const assetsDir = join(options.postDir, 'assets');
|
|
1328
|
-
await createNodeFileSystem().ensureDir(assetsDir);
|
|
1329
|
-
const coverName = `cover${extname(options.coverPath).toLowerCase()}`;
|
|
1330
|
-
await copyFile(options.coverPath, join(assetsDir, coverName));
|
|
1331
|
-
imageFrontmatter = `./assets/${coverName}`;
|
|
1332
|
-
}
|
|
1333
1328
|
const markdown = mapContentToSurfingMarkdown(options.content, {
|
|
1334
|
-
image:
|
|
1329
|
+
image: options.coverUrl,
|
|
1330
|
+
locale: options.locale,
|
|
1335
1331
|
publishDate: options.publishDate,
|
|
1336
1332
|
});
|
|
1337
1333
|
await createNodeFileSystem().writeFile(filePath, markdown);
|
|
@@ -1380,17 +1376,44 @@ async function preparePost(payload: PublishTransportPayload): Promise<PrepareOut
|
|
|
1380
1376
|
return { ok: false, result: failNotSent(`post path escapes ${articlesRoot}`) };
|
|
1381
1377
|
}
|
|
1382
1378
|
|
|
1383
|
-
const
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1379
|
+
const rawCover = payload.content.metadata?.coverImage;
|
|
1380
|
+
let coverUrl: string | undefined;
|
|
1381
|
+
if (typeof rawCover === 'string' && rawCover.trim() !== '') {
|
|
1382
|
+
const trimmedCover = rawCover.trim();
|
|
1383
|
+
if (/^https:\/\//.test(trimmedCover)) {
|
|
1384
|
+
coverUrl = trimmedCover;
|
|
1385
|
+
} else {
|
|
1386
|
+
if (!existsSync(trimmedCover)) {
|
|
1387
|
+
return { ok: false, result: failNotSent(`metadata.coverImage not found: ${trimmedCover}`) };
|
|
1388
|
+
}
|
|
1389
|
+
if (!COVER_EXTS.has(extname(trimmedCover).toLowerCase())) {
|
|
1390
|
+
return {
|
|
1391
|
+
ok: false,
|
|
1392
|
+
result: failNotSent(`metadata.coverImage must be one of ${[...COVER_EXTS].join(', ')}`),
|
|
1393
|
+
};
|
|
1394
|
+
}
|
|
1395
|
+
const optsObj =
|
|
1396
|
+
payload.options !== undefined && typeof payload.options === 'object' && payload.options !== null
|
|
1397
|
+
? (payload.options as Record<string, unknown>)
|
|
1398
|
+
: {};
|
|
1399
|
+
const isDryRun = optsObj.dryRun === true || process.env.KNOWLEDGE_KIT_PUBLISH_TRANSPORT === 'fake';
|
|
1400
|
+
if (isDryRun) {
|
|
1401
|
+
const safeName = basename(trimmedCover).replace(/[^a-zA-Z0-9._-]/g, '_') || 'cover.png';
|
|
1402
|
+
coverUrl = `https://podcast-media.salty.vip/production/images/dry-run-${safeName}`;
|
|
1403
|
+
} else {
|
|
1404
|
+
try {
|
|
1405
|
+
coverUrl = await uploadCoverToMicrofeed(trimmedCover);
|
|
1406
|
+
} catch (err: unknown) {
|
|
1407
|
+
return {
|
|
1408
|
+
ok: false,
|
|
1409
|
+
result: failNotSent(
|
|
1410
|
+
`Failed to upload cover image to podcast-media: ${err instanceof Error ? err.message : String(err)}`,
|
|
1411
|
+
),
|
|
1412
|
+
};
|
|
1413
|
+
}
|
|
1414
|
+
}
|
|
1415
|
+
}
|
|
1416
|
+
} else if (isDigestContent(payload.content)) {
|
|
1394
1417
|
return { ok: false, result: failNotSent('digest post has no cover image (metadata.coverImage)') };
|
|
1395
1418
|
}
|
|
1396
1419
|
|
|
@@ -1413,18 +1436,18 @@ async function preparePost(payload: PublishTransportPayload): Promise<PrepareOut
|
|
|
1413
1436
|
|
|
1414
1437
|
const filePath = join(postDir, 'index.md');
|
|
1415
1438
|
const publishDate = runDate ? `${runDate.slice(0, 4)}-${runDate.slice(4, 6)}-${runDate.slice(6, 8)}` : undefined;
|
|
1416
|
-
const
|
|
1439
|
+
const mintedDirs = [join('content', 'posts', 'articles', locale, slug)];
|
|
1417
1440
|
try {
|
|
1418
1441
|
// A post the site's own refine step already marked is not ours to clobber: re-minting it
|
|
1419
1442
|
// replaces the refined canonical frontmatter (refine owns `refined`, `seo_title`, …) with
|
|
1420
1443
|
// generator defaults and flips an already-published day back to a draft. Keep the file and
|
|
1421
1444
|
// reuse it; only genuinely fresh days (no marker) get minted (2026-11-05 tier-0 rerun).
|
|
1422
|
-
await mintLocalePost({ postDir, content: payload.content,
|
|
1423
|
-
for (const
|
|
1424
|
-
const draft = drafts[
|
|
1445
|
+
await mintLocalePost({ postDir, content: payload.content, coverUrl, locale, publishDate });
|
|
1446
|
+
for (const draftLocale of LOCAL_DRAFTS) {
|
|
1447
|
+
const draft = drafts[draftLocale];
|
|
1425
1448
|
if (draft === undefined) continue;
|
|
1426
|
-
const siblingDir = resolve(articlesRoot,
|
|
1427
|
-
if (dirname(resolve(siblingDir)) !== resolve(articlesRoot,
|
|
1449
|
+
const siblingDir = resolve(articlesRoot, draftLocale, slug);
|
|
1450
|
+
if (dirname(resolve(siblingDir)) !== resolve(articlesRoot, draftLocale)) {
|
|
1428
1451
|
return { ok: false, result: failNotSent(`post path escapes ${articlesRoot}`) };
|
|
1429
1452
|
}
|
|
1430
1453
|
// The zh Body and title are replaced by the translation; the frontmatter fields the
|
|
@@ -1433,9 +1456,11 @@ async function preparePost(payload: PublishTransportPayload): Promise<PrepareOut
|
|
|
1433
1456
|
await mintLocalePost({
|
|
1434
1457
|
postDir: siblingDir,
|
|
1435
1458
|
content: { ...payload.content, title: draft.title, body: draft.body },
|
|
1436
|
-
|
|
1459
|
+
coverUrl,
|
|
1460
|
+
locale: draftLocale,
|
|
1437
1461
|
publishDate,
|
|
1438
1462
|
});
|
|
1463
|
+
mintedDirs.push(join('content', 'posts', 'articles', draftLocale, slug));
|
|
1439
1464
|
}
|
|
1440
1465
|
} catch (err: unknown) {
|
|
1441
1466
|
return {
|
|
@@ -1457,6 +1482,7 @@ async function preparePost(payload: PublishTransportPayload): Promise<PrepareOut
|
|
|
1457
1482
|
slug,
|
|
1458
1483
|
filePath,
|
|
1459
1484
|
relPostDir: join('content', 'posts', 'articles', locale, slug),
|
|
1485
|
+
relPostDirs: mintedDirs,
|
|
1460
1486
|
articleUrl,
|
|
1461
1487
|
},
|
|
1462
1488
|
};
|
|
@@ -1550,18 +1576,17 @@ async function publishPreparedFile(
|
|
|
1550
1576
|
},
|
|
1551
1577
|
});
|
|
1552
1578
|
}
|
|
1553
|
-
const topics = await runDailyTopicsSync(surfdashRoot, filePath);
|
|
1554
|
-
if (!topics.ok) return failUncertain(topics.error);
|
|
1555
1579
|
const backfilled = await runListenLinkBackfill(surfdashRoot);
|
|
1556
1580
|
const commitPaths = relPostDirs ?? [relPostDir];
|
|
1557
|
-
const gate = await runSiteGate(surfdashRoot, [...commitPaths, ...backfilled
|
|
1581
|
+
const gate = await runSiteGate(surfdashRoot, [...commitPaths, ...backfilled]);
|
|
1558
1582
|
if (!gate.ok) return failUncertain(gate.error);
|
|
1559
|
-
const commitLocales: SupportedLocale[] =
|
|
1583
|
+
const commitLocales: SupportedLocale[] =
|
|
1584
|
+
relPostDirs !== undefined && relPostDirs.length > 1 ? ['zh', 'en', 'ja'] : [locale];
|
|
1560
1585
|
const pushed = await pushPostGit(
|
|
1561
1586
|
surfdashRoot,
|
|
1562
1587
|
commitPaths,
|
|
1563
1588
|
`content: daily AI news ${dateStamp} (${commitLocales.join(', ')})`,
|
|
1564
|
-
|
|
1589
|
+
backfilled,
|
|
1565
1590
|
);
|
|
1566
1591
|
if (!pushed.ok) return failUncertain(pushed.error);
|
|
1567
1592
|
const live = await awaitArticleLive(articleUrl);
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { basename, extname } from 'node:path';
|
|
2
|
+
|
|
3
|
+
export type FetchLike = (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
|
|
4
|
+
|
|
5
|
+
export interface MicrofeedUploadOptions {
|
|
6
|
+
baseUrl?: string;
|
|
7
|
+
apiKey?: string;
|
|
8
|
+
fetchImpl?: FetchLike;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function contentTypeForImage(filePath: string): string {
|
|
12
|
+
const ext = extname(filePath).toLowerCase();
|
|
13
|
+
if (ext === '.jpg' || ext === '.jpeg') return 'image/jpeg';
|
|
14
|
+
if (ext === '.webp') return 'image/webp';
|
|
15
|
+
return 'image/png';
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async function readErrorBody(res: Response): Promise<string> {
|
|
19
|
+
try {
|
|
20
|
+
return (await res.text()).slice(0, 200);
|
|
21
|
+
} catch {
|
|
22
|
+
return '';
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Upload a local cover image to Microfeed's media bucket (`podcast-media.salty.vip`) via its
|
|
28
|
+
* presigned URL endpoint and return the public `https://` `media_url`.
|
|
29
|
+
*
|
|
30
|
+
* Used by `surfdash-pub` only as a fallback when a caller supplies a local cover path rather than a
|
|
31
|
+
* pre-published podcast `imageUrl`, so `surfdash` never commits cover binaries to git.
|
|
32
|
+
*/
|
|
33
|
+
export async function uploadCoverToMicrofeed(filePath: string, options: MicrofeedUploadOptions = {}): Promise<string> {
|
|
34
|
+
const baseUrl = (options.baseUrl ?? process.env.MICROFEED_BASE_URL ?? '').trim().replace(/\/$/, '');
|
|
35
|
+
const apiKey = (options.apiKey ?? process.env.MICROFEED_API_KEY ?? '').trim();
|
|
36
|
+
if (!baseUrl) {
|
|
37
|
+
throw new Error('MICROFEED_BASE_URL is required to upload a local cover image to podcast-media');
|
|
38
|
+
}
|
|
39
|
+
if (!apiKey) {
|
|
40
|
+
throw new Error('MICROFEED_API_KEY is required to upload a local cover image to podcast-media');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const mime = contentTypeForImage(filePath);
|
|
44
|
+
const bytes = await Bun.file(filePath).arrayBuffer();
|
|
45
|
+
const doFetch = options.fetchImpl ?? fetch;
|
|
46
|
+
|
|
47
|
+
const presignRes = await doFetch(`${baseUrl}/api/v1/media_files/presigned_urls`, {
|
|
48
|
+
method: 'POST',
|
|
49
|
+
headers: {
|
|
50
|
+
Authorization: `Bearer ${apiKey}`,
|
|
51
|
+
Origin: baseUrl,
|
|
52
|
+
'Content-Type': 'application/json',
|
|
53
|
+
},
|
|
54
|
+
body: JSON.stringify({
|
|
55
|
+
category: 'image',
|
|
56
|
+
full_local_file_path: basename(filePath),
|
|
57
|
+
size: bytes.byteLength,
|
|
58
|
+
type: mime,
|
|
59
|
+
}),
|
|
60
|
+
});
|
|
61
|
+
if (!presignRes.ok) {
|
|
62
|
+
const body = await readErrorBody(presignRes);
|
|
63
|
+
throw new Error(`Microfeed cover presign failed (${presignRes.status}): ${body}`);
|
|
64
|
+
}
|
|
65
|
+
const { presigned_url, media_url } = (await presignRes.json()) as {
|
|
66
|
+
presigned_url?: string;
|
|
67
|
+
media_url?: string;
|
|
68
|
+
};
|
|
69
|
+
if (!presigned_url || !media_url || !/^https:\/\//.test(media_url)) {
|
|
70
|
+
throw new Error(`Microfeed cover presign returned incomplete media_url: ${String(media_url)}`);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const putRes = await doFetch(presigned_url, {
|
|
74
|
+
method: 'PUT',
|
|
75
|
+
headers: { 'Content-Type': mime },
|
|
76
|
+
body: bytes,
|
|
77
|
+
});
|
|
78
|
+
if (!putRes.ok) {
|
|
79
|
+
const body = await readErrorBody(putRes);
|
|
80
|
+
throw new Error(`Microfeed cover PUT upload failed (${putRes.status}): ${body}`);
|
|
81
|
+
}
|
|
82
|
+
return media_url;
|
|
83
|
+
}
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* This module owns only the file work (deterministic, no network); the caller (`./index`) owns the
|
|
12
12
|
* branch guard, the CMS re-sync and the git commit, in that order.
|
|
13
13
|
*/
|
|
14
|
-
import { basename, dirname,
|
|
14
|
+
import { basename, dirname, sep } from 'node:path';
|
|
15
15
|
import { createNodeFileSystem } from '@gobing-ai/ts-runtime';
|
|
16
16
|
|
|
17
17
|
/** The locales a daily post carries; zh is the primary whose directory anchors the other two. */
|
|
@@ -22,14 +22,23 @@ export type PatchLocale = (typeof PATCH_LOCALES)[number];
|
|
|
22
22
|
export interface PatchPostRequest {
|
|
23
23
|
/** Absolute `<root>/content/posts/articles/zh/<slug>/index.md` — the primary post. */
|
|
24
24
|
postPath: string;
|
|
25
|
-
/** Podcast-hosted cover URL; empty
|
|
25
|
+
/** Podcast-hosted cover URL (`https://...`); empty preserves an existing `https://` `image:` or uses {@link uploadLocalCover}. */
|
|
26
26
|
coverUrl: string;
|
|
27
27
|
/** Podcast episode URL for the cross-link line; empty → no cross-link. */
|
|
28
28
|
showNotesUrl: string;
|
|
29
|
-
/**
|
|
29
|
+
/** Optional local cover path uploaded via {@link uploadLocalCover} when no `https://` cover exists yet. */
|
|
30
30
|
localCover: string;
|
|
31
31
|
/** `YYYY-MM-DD` episode date used in the cross-link text. */
|
|
32
32
|
dateIso: string;
|
|
33
|
+
/**
|
|
34
|
+
* The episode's frozen identity title (0385 R4), e.g. `第261120期 · Anthropic 上市,估值口径成为焦点`.
|
|
35
|
+
* Written to the zh post's `episode_title` frontmatter and used for the zh cross-link text, so the
|
|
36
|
+
* article states the same episode identity the podcast ships. Empty → the older series · date
|
|
37
|
+
* wording, which is what pre-0385 bundles carry.
|
|
38
|
+
*/
|
|
39
|
+
episodeTitle?: string;
|
|
40
|
+
/** Optional uploader converting a local cover into an `https://` remote URL (e.g. Microfeed R2). */
|
|
41
|
+
uploadLocalCover?: (filePath: string) => Promise<string>;
|
|
33
42
|
}
|
|
34
43
|
|
|
35
44
|
/** What the file pass changed; the caller commits exactly {@link PatchPostOutcome.written}. */
|
|
@@ -71,10 +80,16 @@ export const SERIES_NAMES: Record<PatchLocale, string> = {
|
|
|
71
80
|
ja: 'デイリーAIシチュー',
|
|
72
81
|
};
|
|
73
82
|
|
|
74
|
-
export function crossLinkFor(locale: PatchLocale, dateIso: string, showNotesUrl: string): string {
|
|
83
|
+
export function crossLinkFor(locale: PatchLocale, dateIso: string, showNotesUrl: string, episodeTitle = ''): string {
|
|
75
84
|
const series = SERIES_NAMES[locale];
|
|
85
|
+
// The zh episode's frozen identity (0385) rides after the link, never inside the anchor: the site's
|
|
86
|
+
// `listen-link-series-name` gate requires the anchor text to name the canonical series and nothing
|
|
87
|
+
// else series-like. en/ja have no localized identity, so they keep the series · date wording.
|
|
76
88
|
const links: Record<PatchLocale, string> = {
|
|
77
|
-
zh:
|
|
89
|
+
zh:
|
|
90
|
+
episodeTitle !== ''
|
|
91
|
+
? `🎧 本期已同步制作为播客节目,[点击收听《${series} · ${dateIso}》](${showNotesUrl}):${episodeTitle}。`
|
|
92
|
+
: `🎧 本期已同步制作为播客节目,[点击收听《${series} · ${dateIso}》](${showNotesUrl})。`,
|
|
78
93
|
en: `🎧 This episode is also available as a podcast: [listen to ${series} · ${dateIso}](${showNotesUrl}).`,
|
|
79
94
|
ja: `🎧 本エピソードはポッドキャストでも配信中:[${series} · ${dateIso} を聴く](${showNotesUrl})。`,
|
|
80
95
|
};
|
|
@@ -116,17 +131,18 @@ export async function patchPostFiles(request: PatchPostRequest): Promise<PatchPo
|
|
|
116
131
|
const absent: PatchLocale[] = [];
|
|
117
132
|
const images: Record<string, string> = {};
|
|
118
133
|
let changed = 0;
|
|
134
|
+
let uploadedFallbackCover: string | undefined;
|
|
119
135
|
for (const locale of PATCH_LOCALES) {
|
|
120
136
|
const indexMd = localeIndexPath(request.postPath, locale);
|
|
121
137
|
if (indexMd === undefined || !(await fs.exists(indexMd))) {
|
|
122
138
|
absent.push(locale);
|
|
123
139
|
continue;
|
|
124
140
|
}
|
|
125
|
-
const dir = dirname(indexMd);
|
|
126
141
|
const before = await fs.readFile(indexMd);
|
|
127
142
|
let md = before;
|
|
128
143
|
const end = frontmatterEnd(md);
|
|
129
144
|
const fm = end < 0 ? md : md.slice(0, end);
|
|
145
|
+
const existingImage = /^image:\s*['"]?([^'"\n]+)['"]?/m.exec(fm)?.[1]?.trim() ?? '';
|
|
130
146
|
if (request.coverUrl !== '') {
|
|
131
147
|
// A relative or http:// cover would ship an unservable OG card — the deployed worker
|
|
132
148
|
// only serves absolute https URLs (prod feedback 2026-09-29).
|
|
@@ -136,29 +152,40 @@ export async function patchPostFiles(request: PatchPostRequest): Promise<PatchPo
|
|
|
136
152
|
md = upsertFrontmatterKey(md, 'image', request.coverUrl);
|
|
137
153
|
md = upsertFrontmatterKey(md, 'og_image', request.coverUrl);
|
|
138
154
|
images[locale] = request.coverUrl;
|
|
139
|
-
} else if (
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
155
|
+
} else if (/^https:\/\//.test(existingImage)) {
|
|
156
|
+
md = upsertFrontmatterKey(md, 'og_image', existingImage);
|
|
157
|
+
images[locale] = existingImage;
|
|
158
|
+
} else if (
|
|
159
|
+
request.uploadLocalCover !== undefined &&
|
|
160
|
+
request.localCover !== '' &&
|
|
161
|
+
(await fs.exists(request.localCover))
|
|
162
|
+
) {
|
|
163
|
+
if (uploadedFallbackCover === undefined) {
|
|
164
|
+
const uploaded = await request.uploadLocalCover(request.localCover);
|
|
165
|
+
if (!/^https:\/\//.test(uploaded)) {
|
|
166
|
+
throw new Error(`uploaded cover must be an absolute https:// URL, got: ${uploaded}`);
|
|
167
|
+
}
|
|
168
|
+
uploadedFallbackCover = uploaded;
|
|
147
169
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
170
|
+
md = upsertFrontmatterKey(md, 'image', uploadedFallbackCover);
|
|
171
|
+
md = upsertFrontmatterKey(md, 'og_image', uploadedFallbackCover);
|
|
172
|
+
images[locale] = uploadedFallbackCover;
|
|
173
|
+
} else {
|
|
174
|
+
throw new Error(
|
|
175
|
+
`${locale} post has no remote https:// cover: coverUrl is empty and frontmatter has no https:// image key`,
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
if (locale === 'zh' && (request.episodeTitle ?? '') !== '') {
|
|
179
|
+
// The article states the episode identity the podcast ships (0385). The site renders it
|
|
180
|
+
// under the H1; its SEO title stays the digest shape, so this is additive, not a rename.
|
|
181
|
+
md = upsertFrontmatterKey(md, 'episode_title', request.episodeTitle as string);
|
|
155
182
|
}
|
|
156
183
|
if (request.showNotesUrl !== '') {
|
|
157
184
|
// 2026-10-23: a previous run may have left a 🎧 cross-link line carrying a retired
|
|
158
185
|
// series name — refresh that line in place instead of keeping it forever (the URL it
|
|
159
186
|
// carries made a fresh append a no-op). A non-cross-link line mentioning the URL is
|
|
160
187
|
// left alone; the fresh link is only appended when no line carries the URL at all.
|
|
161
|
-
const link = crossLinkFor(locale, request.dateIso, request.showNotesUrl);
|
|
188
|
+
const link = crossLinkFor(locale, request.dateIso, request.showNotesUrl, request.episodeTitle ?? '');
|
|
162
189
|
const lines = md.split('\n');
|
|
163
190
|
const carriesUrl = lines.some((line) => line.includes(request.showNotesUrl));
|
|
164
191
|
if (!carriesUrl) {
|
|
@@ -174,10 +201,6 @@ export async function patchPostFiles(request: PatchPostRequest): Promise<PatchPo
|
|
|
174
201
|
if (md !== before) {
|
|
175
202
|
await fs.writeFile(indexMd, md);
|
|
176
203
|
written.push(indexMd);
|
|
177
|
-
const assetsDir = join(dir, 'assets');
|
|
178
|
-
if ((await fs.exists(assetsDir)) && !written.includes(join(assetsDir, 'cover.png'))) {
|
|
179
|
-
written.push(assetsDir);
|
|
180
|
-
}
|
|
181
204
|
changed += 1;
|
|
182
205
|
}
|
|
183
206
|
}
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
import { dirname } from 'node:path';
|
|
12
12
|
import { createNodeFileSystem, type FileSystem } from '@gobing-ai/ts-runtime';
|
|
13
|
-
import { DIGEST_TAG, parseFrontmatterScalars } from './digest-check';
|
|
13
|
+
import { DIGEST_TAG, isEpisodeIdentityTitle, parseFrontmatterScalars } from './digest-check';
|
|
14
14
|
import { PATCH_LOCALES, type PatchLocale, SERIES_NAMES } from './patch';
|
|
15
15
|
|
|
16
16
|
/** One locale's topic-map fields. `claim_basis` is stamped later by retitle. */
|
|
@@ -106,8 +106,9 @@ function buildLocaleEntry(markdown: string, locale: PatchLocale): DailyTopicsLoc
|
|
|
106
106
|
}
|
|
107
107
|
const frontmatter = parseFrontmatterScalars(markdown);
|
|
108
108
|
const title = scalar(frontmatter, 'title') ?? '';
|
|
109
|
-
const
|
|
110
|
-
|
|
109
|
+
const episodeIdentity = isEpisodeIdentityTitle(title, locale);
|
|
110
|
+
const parsedHeadlines = episodeIdentity ? undefined : parseTitleHeadlines(title, locale);
|
|
111
|
+
if (!episodeIdentity && !parsedHeadlines) {
|
|
111
112
|
return `${locale}: title is not "<series> · YYYY-MM-DD${titleSepFor(locale)}h1${listSepFor(locale)}h2"`;
|
|
112
113
|
}
|
|
113
114
|
const description = (scalar(frontmatter, 'description') ?? scalar(frontmatter, 'seo_description') ?? '').trim();
|
|
@@ -122,11 +123,18 @@ function buildLocaleEntry(markdown: string, locale: PatchLocale): DailyTopicsLoc
|
|
|
122
123
|
if (!parts) {
|
|
123
124
|
return `${locale}: key_points must be "label — sentence"`;
|
|
124
125
|
}
|
|
126
|
+
const headlines = episodeIdentity ? parts.labels.slice(0, 2) : (parsedHeadlines ?? []);
|
|
127
|
+
if (headlines.length === 0) {
|
|
128
|
+
return `${locale}: key_points has no labels to derive headlines`;
|
|
129
|
+
}
|
|
125
130
|
// The title names the TOP stories; the key-point box carries up to four. The site's own
|
|
126
131
|
// generator emits exactly that shape (`scripts/commands/seo/retitle.ts`: title = "top story 1,
|
|
127
132
|
// story 2", key_points = up to four bullets), so demanding a one-to-one match made every
|
|
128
133
|
// crefitable digest fail the sync. The title must be the leading labels, in order.
|
|
129
|
-
if (
|
|
134
|
+
if (
|
|
135
|
+
!episodeIdentity &&
|
|
136
|
+
(headlines.length > parts.labels.length || headlines.some((headline, i) => headline !== parts.labels[i]))
|
|
137
|
+
) {
|
|
130
138
|
return `${locale}: title headlines do not match the leading key_points labels`;
|
|
131
139
|
}
|
|
132
140
|
const claims = parts.sentences;
|