@gobing-ai/knowledge-kit 0.1.19 → 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.
- package/.claude-plugin/marketplace.json +1 -1
- package/dist/board/collect/index.js +1 -0
- package/dist/board/daily-voice/index.js +1315 -264
- package/dist/board/itc/index.js +1 -0
- package/dist/index.js +14674 -8775
- package/package.json +1 -1
- package/plugins/generations/dailynews-gen/dist/index.js +285 -16
- package/plugins/generations/dailynews-gen/src/editorial-claims.ts +215 -0
- package/plugins/generations/dailynews-gen/src/index.ts +23 -4
- package/plugins/generations/dailynews-gen/src/script-builder.ts +10 -3
- package/plugins/generations/dailynews-gen/src/script-plan.ts +74 -14
- package/plugins/generations/image-gen/README.md +31 -31
- package/plugins/generations/image-gen/assets/sample/provenance.json +314 -0
- package/plugins/generations/image-gen/config.example.yaml +3 -0
- package/plugins/generations/image-gen/dist/index.js +154 -14
- package/plugins/generations/image-gen/presets/SOURCE.md +65 -0
- package/plugins/generations/image-gen/scripts/eval-style-presets.ts +513 -0
- package/plugins/generations/image-gen/scripts/gen-samples.ts +57 -7
- package/plugins/generations/image-gen/src/presets.ts +6 -5
- package/plugins/generations/image-gen/src/providers/h3-local.ts +196 -0
- package/plugins/generations/image-gen/src/providers/types.ts +11 -1
- package/plugins/generations/music-gen/README.md +277 -0
- package/plugins/generations/music-gen/dist/index.js +23544 -0
- package/plugins/generations/music-gen/package.json +24 -0
- package/plugins/generations/music-gen/plugin.json +23 -0
- package/plugins/generations/music-gen/presets/SOURCE.md +39 -0
- package/plugins/generations/music-gen/presets/formats/clip.yaml +21 -0
- package/plugins/generations/music-gen/presets/formats/jingle.yaml +22 -0
- package/plugins/generations/music-gen/presets/formats/loop.yaml +21 -0
- package/plugins/generations/music-gen/presets/formats/song.yaml +31 -0
- package/plugins/generations/music-gen/presets/formats/underscore.yaml +22 -0
- package/plugins/generations/music-gen/presets/themes/ambient-tech.yaml +30 -0
- package/plugins/generations/music-gen/presets/themes/cinematic.yaml +30 -0
- package/plugins/generations/music-gen/presets/themes/lofi.yaml +30 -0
- package/plugins/generations/music-gen/presets/themes/synthwave.yaml +30 -0
- package/plugins/generations/music-gen/scripts/gen-preset-index.ts +181 -0
- package/plugins/generations/music-gen/scripts/resolve-preset.ts +64 -0
- package/plugins/generations/music-gen/src/adapter/index.ts +35 -0
- package/plugins/generations/music-gen/src/adapter/instance.ts +904 -0
- package/plugins/generations/music-gen/src/adapter/offline.ts +124 -0
- package/plugins/generations/music-gen/src/artifact.ts +223 -0
- package/plugins/generations/music-gen/src/audio/checks.ts +618 -0
- package/plugins/generations/music-gen/src/audio/master.ts +267 -0
- package/plugins/generations/music-gen/src/audio/measure.ts +507 -0
- package/plugins/generations/music-gen/src/audio/profile.ts +131 -0
- package/plugins/generations/music-gen/src/audio.ts +122 -0
- package/plugins/generations/music-gen/src/brief.ts +191 -0
- package/plugins/generations/music-gen/src/config.ts +451 -0
- package/plugins/generations/music-gen/src/content.ts +199 -0
- package/plugins/generations/music-gen/src/digest.ts +100 -0
- package/plugins/generations/music-gen/src/index.ts +147 -0
- package/plugins/generations/music-gen/src/job.ts +131 -0
- package/plugins/generations/music-gen/src/plugin.ts +371 -0
- package/plugins/generations/music-gen/src/presets.ts +918 -0
- package/plugins/generations/music-gen/src/render.ts +87 -0
- package/plugins/generations/music-gen/src/request.ts +102 -0
- package/plugins/generations/music-gen/src/spend.ts +495 -0
- package/plugins/generations/music-gen/tsconfig.json +8 -0
- package/plugins/kk/config.example.yaml +3 -0
- package/plugins/kk/decisions/extract/ai-news.yaml +5 -2
- package/plugins/kk/plugin.json +1 -1
- package/plugins/kk/publish-presets/daily-ai-voice.json +48 -7
- package/plugins/kk/schedules/kk-serve.launchd.plist.tmpl +2 -1
- package/plugins/kk/scripts/cover-compositor.ts +380 -32
- package/plugins/kk/scripts/daily-cover-mock.ts +40 -3
- package/plugins/kk/scripts/daily-stages.ts +897 -34
- package/plugins/kk/scripts/episode-identity.ts +180 -0
- package/plugins/kk/scripts/kk-workflow-stages.ts +37 -1
- package/plugins/kk/scripts/music-stages.ts +624 -0
- package/plugins/kk/scripts/news-editorial-ledger.ts +906 -0
- package/plugins/kk/scripts/source-citation.ts +187 -0
- package/plugins/kk/scripts/topic-selection-attempts.ts +446 -0
- package/plugins/kk/scripts/topic-selection-calibration.ts +161 -0
- package/plugins/kk/skills/content-judge/SKILL.md +11 -6
- package/plugins/kk/skills/content-judge/references/music-quality-rubric.md +147 -0
- package/plugins/kk/skills/content-judge/references/rubrics.md +15 -0
- package/plugins/kk/skills/content-safety/SKILL.md +12 -0
- package/plugins/kk/skills/image-authoring/SKILL.md +7 -3
- package/plugins/kk/skills/image-authoring/references/providers.md +27 -0
- package/plugins/kk/skills/image-authoring/references/style-extraction.md +1 -1
- package/plugins/kk/skills/music-authoring/SKILL.md +276 -0
- package/plugins/kk/skills/music-authoring/references/judge-input.md +117 -0
- package/plugins/kk/skills/news-editorial/SKILL.md +102 -15
- package/plugins/kk/skills/news-editorial/references/selection.md +4 -0
- package/plugins/kk/skills/news-editorial/references/style-contract.zh.md +58 -11
- package/plugins/kk/skills/publish/SKILL.md +11 -0
- package/plugins/kk/skills/web-automation/SKILL.md +31 -1
- package/plugins/kk/workflows/kk-collect.yaml +8 -4
- package/plugins/kk/workflows/kk-daily-ai-voice.yaml +10 -9
- package/plugins/kk/workflows/kk-daily-ai-voice2.yaml +11 -9
- package/plugins/kk/workflows/kk-music.yaml +328 -0
- package/plugins/kk/workflows/kk-news-generate.yaml +58 -3
- package/plugins/publishings/bilibili-pub/dist/index.js +11 -1
- package/plugins/publishings/bilibili-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/cnblogs-pub/dist/index.js +11 -1
- package/plugins/publishings/cnblogs-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/csdn-pub/dist/index.js +11 -1
- package/plugins/publishings/csdn-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/infoq-pub/dist/index.js +11 -1
- package/plugins/publishings/infoq-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/jike-pub/dist/index.js +11 -1
- package/plugins/publishings/jike-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/juejin-pub/dist/index.js +11 -1
- package/plugins/publishings/juejin-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/linkedin-pub/dist/index.js +54 -7
- package/plugins/publishings/linkedin-pub/dist/profile-check.js +43 -6
- package/plugins/publishings/linkedin-pub/src/index.ts +52 -6
- package/plugins/publishings/podcast-pub/dist/index.js +586 -20
- package/plugins/publishings/podcast-pub/src/corrections.ts +509 -0
- package/plugins/publishings/podcast-pub/src/index.ts +257 -5
- package/plugins/publishings/podcast-pub/src/show-notes-brief.ts +240 -0
- package/plugins/publishings/podcast-pub/src/show-notes.ts +69 -13
- package/plugins/publishings/shipinhao-pub/dist/index.js +437 -32
- package/plugins/publishings/shipinhao-pub/dist/profile-check.js +14 -2
- package/plugins/publishings/shipinhao-pub/plugin.json +1 -1
- package/plugins/publishings/shipinhao-pub/src/audio-flow.ts +492 -0
- package/plugins/publishings/shipinhao-pub/src/flow.ts +227 -12
- package/plugins/publishings/shipinhao-pub/src/selectors.ts +13 -0
- package/plugins/publishings/sspai-pub/dist/index.js +11 -1
- package/plugins/publishings/sspai-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/substack-pub/dist/index.js +11 -1
- package/plugins/publishings/substack-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/surfdash-pub/dist/index.js +122 -28
- package/plugins/publishings/surfdash-pub/src/digest-check.ts +7 -3
- package/plugins/publishings/surfdash-pub/src/index.ts +159 -25
- package/plugins/publishings/surfdash-pub/src/topic-claims.ts +37 -4
- package/plugins/publishings/threads-pub/dist/index.js +9206 -296
- package/plugins/publishings/threads-pub/dist/profile-check.js +21149 -0
- package/plugins/publishings/threads-pub/package.json +3 -1
- package/plugins/publishings/threads-pub/plugin.json +6 -1
- package/plugins/publishings/threads-pub/src/index.ts +8 -1
- package/plugins/publishings/threads-pub/src/post-rail.ts +357 -0
- package/plugins/publishings/threads-pub/src/profile-check.ts +17 -0
- package/plugins/publishings/wechatmp-pub/dist/index.js +18 -1
- package/plugins/publishings/wechatmp-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/wechatmp-pub/src/flow.ts +13 -0
- package/plugins/publishings/weibo-pub/dist/index.js +57 -3
- package/plugins/publishings/weibo-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/weibo-pub/src/index.ts +74 -2
- package/plugins/publishings/x-pub/dist/index.js +274 -44
- package/plugins/publishings/x-pub/dist/profile-check.js +14 -2
- package/plugins/publishings/x-pub/src/index.ts +15 -1
- package/plugins/publishings/x-pub/src/post-rail.ts +334 -0
- package/plugins/publishings/xhs-pub/dist/index.js +11 -1
- package/plugins/publishings/xhs-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/xiaoyuzhou-pub/dist/index.js +11 -1
- package/plugins/publishings/xiaoyuzhou-pub/dist/profile-check.js +11 -1
|
@@ -12609,9 +12609,8 @@ function checkDigestFrontmatter(markdown, locale) {
|
|
|
12609
12609
|
} else {
|
|
12610
12610
|
const rest = match[2] ?? "";
|
|
12611
12611
|
const heads = locale === "en" ? rest.split(", ") : rest.split("\u3001");
|
|
12612
|
-
|
|
12613
|
-
|
|
12614
|
-
problems.push(`title: expected exactly two non-empty headlines joined "${listSep}", got "${rest}"`);
|
|
12612
|
+
if (heads.length < 1 || heads.length > 2 || heads.some((head) => head.trim() === "")) {
|
|
12613
|
+
problems.push(`title: expected one or two non-empty headlines joined "${listSep}", got ${heads.length} in "${rest}"`);
|
|
12615
12614
|
}
|
|
12616
12615
|
}
|
|
12617
12616
|
const seoTitle = `${title} | Surfing`;
|
|
@@ -12705,7 +12704,7 @@ function parseTitleHeadlines(title, locale) {
|
|
|
12705
12704
|
if (!match?.[2])
|
|
12706
12705
|
return;
|
|
12707
12706
|
const heads = match[2].split(listSep).map((head) => head.trim());
|
|
12708
|
-
if (heads.length < 2 || heads.some((head) => head === ""))
|
|
12707
|
+
if (heads.length < 1 || heads.length > 2 || heads.some((head) => head === ""))
|
|
12709
12708
|
return;
|
|
12710
12709
|
return heads;
|
|
12711
12710
|
}
|
|
@@ -12755,8 +12754,8 @@ function buildLocaleEntry(markdown, locale) {
|
|
|
12755
12754
|
if (!parts) {
|
|
12756
12755
|
return `${locale}: key_points must be "label \u2014 sentence"`;
|
|
12757
12756
|
}
|
|
12758
|
-
if (
|
|
12759
|
-
return `${locale}: title headlines do not match key_points labels`;
|
|
12757
|
+
if (headlines.length > parts.labels.length || headlines.some((headline, i) => headline !== parts.labels[i])) {
|
|
12758
|
+
return `${locale}: title headlines do not match the leading key_points labels`;
|
|
12760
12759
|
}
|
|
12761
12760
|
const claims = parts.sentences;
|
|
12762
12761
|
const shortClaims = splitDescriptionParts(description, headlines.length) ?? claims;
|
|
@@ -12801,11 +12800,25 @@ async function upsertDailyTopicsEntry(mapPath, slug, entry, fileSystem = createN
|
|
|
12801
12800
|
existing = parsed;
|
|
12802
12801
|
}
|
|
12803
12802
|
}
|
|
12804
|
-
existing[slug]
|
|
12803
|
+
const prior = existing[slug];
|
|
12804
|
+
existing[slug] = prior === null || typeof prior !== "object" || Array.isArray(prior) ? entry : keepCurated(prior, entry);
|
|
12805
12805
|
await fileSystem.ensureDir(dirname3(mapPath));
|
|
12806
12806
|
await fileSystem.writeFile(mapPath, `${JSON.stringify(existing, null, "\t")}
|
|
12807
12807
|
`);
|
|
12808
12808
|
}
|
|
12809
|
+
function keepCurated(curated, derived) {
|
|
12810
|
+
const merged = { ...derived, ...curated };
|
|
12811
|
+
const isEmpty = (value) => value === undefined || value === null || value === "" || Array.isArray(value) && value.length === 0;
|
|
12812
|
+
for (const [key, value] of Object.entries(derived)) {
|
|
12813
|
+
const current = curated[key];
|
|
12814
|
+
if (isEmpty(current))
|
|
12815
|
+
continue;
|
|
12816
|
+
if (value !== null && typeof value === "object" && !Array.isArray(value) && !isEmpty(current)) {
|
|
12817
|
+
merged[key] = keepCurated(current, value);
|
|
12818
|
+
}
|
|
12819
|
+
}
|
|
12820
|
+
return merged;
|
|
12821
|
+
}
|
|
12809
12822
|
|
|
12810
12823
|
// ../../plugins/publishings/surfdash-pub/src/index.ts
|
|
12811
12824
|
var TARGET = "surfdash";
|
|
@@ -13008,6 +13021,32 @@ function digestCheckGate(filePath, locale) {
|
|
|
13008
13021
|
}
|
|
13009
13022
|
return `digest frontmatter check failed: ${problems.join("; ")}`;
|
|
13010
13023
|
}
|
|
13024
|
+
function localeSiblings(postPath) {
|
|
13025
|
+
const segments = postPath.split(sep2);
|
|
13026
|
+
let index = -1;
|
|
13027
|
+
for (let i = segments.length - 1;i >= 0; i--) {
|
|
13028
|
+
if (segments[i] === "zh" || segments[i] === "en" || segments[i] === "ja") {
|
|
13029
|
+
index = i;
|
|
13030
|
+
break;
|
|
13031
|
+
}
|
|
13032
|
+
}
|
|
13033
|
+
if (index < 0)
|
|
13034
|
+
return [];
|
|
13035
|
+
return PATCH_LOCALES.map((locale) => ({
|
|
13036
|
+
filePath: [...segments.slice(0, index), locale, ...segments.slice(index + 1)].join(sep2),
|
|
13037
|
+
locale
|
|
13038
|
+
}));
|
|
13039
|
+
}
|
|
13040
|
+
function digestCheckLocaleSet(postPath) {
|
|
13041
|
+
for (const { filePath, locale } of localeSiblings(postPath)) {
|
|
13042
|
+
if (!existsSync2(filePath))
|
|
13043
|
+
continue;
|
|
13044
|
+
const problem = digestCheckGate(filePath, locale);
|
|
13045
|
+
if (problem)
|
|
13046
|
+
return `${locale}: ${problem}`;
|
|
13047
|
+
}
|
|
13048
|
+
return;
|
|
13049
|
+
}
|
|
13011
13050
|
function parsePorcelainPaths(stdout) {
|
|
13012
13051
|
return stdout.split(`
|
|
13013
13052
|
`).map((line) => line.trimEnd()).filter((line) => line.length > 3).map((line) => {
|
|
@@ -13091,7 +13130,9 @@ async function runDailyTopicsSync(surfdashRoot, zhPostPath) {
|
|
|
13091
13130
|
}
|
|
13092
13131
|
var SITE_GATE_COMMANDS = [
|
|
13093
13132
|
["bun", "run", "sd", "check", "digest"],
|
|
13094
|
-
["bun", "run", "check:content"]
|
|
13133
|
+
["bun", "run", "check:content"],
|
|
13134
|
+
["bun", "run", "check:body"],
|
|
13135
|
+
["bun", "run", "check:seo"]
|
|
13095
13136
|
];
|
|
13096
13137
|
function extractFailingPostHint(text) {
|
|
13097
13138
|
const match = text.match(/(?:content[\\/])?posts[\\/][^\s:)]+/);
|
|
@@ -13353,9 +13394,8 @@ async function syncPost(options) {
|
|
|
13353
13394
|
if (spawned.exitCode !== 0) {
|
|
13354
13395
|
return fail(`publish-orchestrator sync failed (exit ${spawned.exitCode}): ${withEmdashTokenHint(cliErrorText(spawned))}`);
|
|
13355
13396
|
}
|
|
13356
|
-
|
|
13357
|
-
|
|
13358
|
-
const digestProblem = digestCheckGate(postPath.postPath, localeInPath[1]);
|
|
13397
|
+
if (/[\\/]content[\\/]posts[\\/]articles[\\/](?:zh|en|ja)[\\/]/.test(postPath.postPath)) {
|
|
13398
|
+
const digestProblem = digestCheckLocaleSet(postPath.postPath);
|
|
13359
13399
|
if (digestProblem)
|
|
13360
13400
|
return fail(digestProblem);
|
|
13361
13401
|
}
|
|
@@ -13574,6 +13614,49 @@ function resolvePreparedPost(options) {
|
|
|
13574
13614
|
identity: identity.value
|
|
13575
13615
|
};
|
|
13576
13616
|
}
|
|
13617
|
+
var LOCAL_DRAFTS = ["en", "ja"];
|
|
13618
|
+
function readLocaleDrafts(content) {
|
|
13619
|
+
const drafts = {};
|
|
13620
|
+
const surfdash = content.metadata?.surfdash;
|
|
13621
|
+
if (typeof surfdash !== "object" || surfdash === null)
|
|
13622
|
+
return drafts;
|
|
13623
|
+
const locales = surfdash.locales;
|
|
13624
|
+
if (typeof locales !== "object" || locales === null)
|
|
13625
|
+
return drafts;
|
|
13626
|
+
for (const locale of LOCAL_DRAFTS) {
|
|
13627
|
+
const entry = locales[locale];
|
|
13628
|
+
if (typeof entry !== "object" || entry === null)
|
|
13629
|
+
continue;
|
|
13630
|
+
const { title, body } = entry;
|
|
13631
|
+
if (typeof title !== "string" || title.trim() === "")
|
|
13632
|
+
continue;
|
|
13633
|
+
if (typeof body !== "string" || body.trim() === "")
|
|
13634
|
+
continue;
|
|
13635
|
+
drafts[locale] = { title, body };
|
|
13636
|
+
}
|
|
13637
|
+
return drafts;
|
|
13638
|
+
}
|
|
13639
|
+
async function mintLocalePost(options) {
|
|
13640
|
+
const filePath = join2(options.postDir, "index.md");
|
|
13641
|
+
if (readRefinedSnapshot(filePath) !== undefined) {
|
|
13642
|
+
echoError(`surfdash-pub: keeping existing refined post at ${filePath} (not re-minting)`);
|
|
13643
|
+
return;
|
|
13644
|
+
}
|
|
13645
|
+
await createNodeFileSystem().ensureDir(options.postDir);
|
|
13646
|
+
let imageFrontmatter;
|
|
13647
|
+
if (options.coverPath !== undefined) {
|
|
13648
|
+
const assetsDir = join2(options.postDir, "assets");
|
|
13649
|
+
await createNodeFileSystem().ensureDir(assetsDir);
|
|
13650
|
+
const coverName = `cover${extname(options.coverPath).toLowerCase()}`;
|
|
13651
|
+
await copyFile(options.coverPath, join2(assetsDir, coverName));
|
|
13652
|
+
imageFrontmatter = `./assets/${coverName}`;
|
|
13653
|
+
}
|
|
13654
|
+
const markdown = mapContentToSurfingMarkdown(options.content, {
|
|
13655
|
+
image: imageFrontmatter,
|
|
13656
|
+
publishDate: options.publishDate
|
|
13657
|
+
});
|
|
13658
|
+
await createNodeFileSystem().writeFile(filePath, markdown);
|
|
13659
|
+
}
|
|
13577
13660
|
async function preparePost(payload) {
|
|
13578
13661
|
const surfdashRoot = resolveSurfdashRoot();
|
|
13579
13662
|
if (!surfdashRoot) {
|
|
@@ -13613,25 +13696,35 @@ async function preparePost(payload) {
|
|
|
13613
13696
|
if (isDigestContent(payload.content) && typeof coverPath !== "string") {
|
|
13614
13697
|
return { ok: false, result: failNotSent("digest post has no cover image (metadata.coverImage)") };
|
|
13615
13698
|
}
|
|
13699
|
+
const drafts = readLocaleDrafts(payload.content);
|
|
13700
|
+
if (isDigestContent(payload.content)) {
|
|
13701
|
+
const missing = LOCAL_DRAFTS.filter((locale) => drafts[locale] === undefined);
|
|
13702
|
+
if (missing.length > 0) {
|
|
13703
|
+
return {
|
|
13704
|
+
ok: false,
|
|
13705
|
+
result: failNotSent(`digest post is missing metadata.surfdash.locales for ${missing.join(", ")} \u2014 the site refuses a digest with a missing locale file; re-run the localize step before publishing`)
|
|
13706
|
+
};
|
|
13707
|
+
}
|
|
13708
|
+
}
|
|
13616
13709
|
const filePath = join2(postDir, "index.md");
|
|
13710
|
+
const publishDate = runDate ? `${runDate.slice(0, 4)}-${runDate.slice(4, 6)}-${runDate.slice(6, 8)}` : undefined;
|
|
13711
|
+
const cover = typeof coverPath === "string" ? coverPath : undefined;
|
|
13617
13712
|
try {
|
|
13618
|
-
|
|
13619
|
-
|
|
13620
|
-
|
|
13621
|
-
if (
|
|
13622
|
-
|
|
13623
|
-
|
|
13624
|
-
|
|
13625
|
-
|
|
13626
|
-
|
|
13627
|
-
|
|
13628
|
-
|
|
13629
|
-
|
|
13630
|
-
|
|
13713
|
+
await mintLocalePost({ postDir, content: payload.content, coverPath: cover, publishDate });
|
|
13714
|
+
for (const locale of LOCAL_DRAFTS) {
|
|
13715
|
+
const draft = drafts[locale];
|
|
13716
|
+
if (draft === undefined)
|
|
13717
|
+
continue;
|
|
13718
|
+
const siblingDir = resolve(articlesRoot, locale, slug);
|
|
13719
|
+
if (dirname4(resolve(siblingDir)) !== resolve(articlesRoot, locale)) {
|
|
13720
|
+
return { ok: false, result: failNotSent(`post path escapes ${articlesRoot}`) };
|
|
13721
|
+
}
|
|
13722
|
+
await mintLocalePost({
|
|
13723
|
+
postDir: siblingDir,
|
|
13724
|
+
content: { ...payload.content, title: draft.title, body: draft.body },
|
|
13725
|
+
coverPath: cover,
|
|
13726
|
+
publishDate
|
|
13631
13727
|
});
|
|
13632
|
-
await createNodeFileSystem().writeFile(filePath, markdown);
|
|
13633
|
-
} else {
|
|
13634
|
-
echoError(`surfdash-pub: keeping existing refined post at ${filePath} (not re-minting)`);
|
|
13635
13728
|
}
|
|
13636
13729
|
} catch (err) {
|
|
13637
13730
|
return {
|
|
@@ -13694,7 +13787,7 @@ async function publishPreparedFile(prepared, identity) {
|
|
|
13694
13787
|
const notRefined = requireRefined(filePath);
|
|
13695
13788
|
if (notRefined)
|
|
13696
13789
|
return failUncertain(notRefined);
|
|
13697
|
-
const digestProblem =
|
|
13790
|
+
const digestProblem = digestCheckLocaleSet(filePath);
|
|
13698
13791
|
if (digestProblem)
|
|
13699
13792
|
return failUncertain(digestProblem);
|
|
13700
13793
|
const refined = readRefinedSnapshot(filePath);
|
|
@@ -13883,6 +13976,7 @@ export {
|
|
|
13883
13976
|
commitPostPaths,
|
|
13884
13977
|
contentTags,
|
|
13885
13978
|
digestCheckGate,
|
|
13979
|
+
digestCheckLocaleSet,
|
|
13886
13980
|
extractFailingPostHint,
|
|
13887
13981
|
fastForwardToOrigin,
|
|
13888
13982
|
getPublishTransport,
|
|
@@ -222,9 +222,13 @@ export function checkDigestFrontmatter(markdown: string, locale: DigestLocale):
|
|
|
222
222
|
} else {
|
|
223
223
|
const rest = match[2] ?? '';
|
|
224
224
|
const heads = locale === 'en' ? rest.split(', ') : rest.split('、');
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
225
|
+
// 1..2, not "exactly 2": the site's `seo retitle` legitimately collapses a title to one
|
|
226
|
+
// headline when two do not fit its SEO budget (surfdash `check-digest.ts`), and that
|
|
227
|
+
// budget verdict is the site's (ADR-008). kk mirrors only the structural range.
|
|
228
|
+
if (heads.length < 1 || heads.length > 2 || heads.some((head) => head.trim() === '')) {
|
|
229
|
+
problems.push(
|
|
230
|
+
`title: expected one or two non-empty headlines joined "${listSep}", got ${heads.length} in "${rest}"`,
|
|
231
|
+
);
|
|
228
232
|
}
|
|
229
233
|
}
|
|
230
234
|
const seoTitle = `${title} | Surfing`;
|
|
@@ -434,6 +434,46 @@ export function digestCheckGate(filePath: string, locale: DigestLocale): string
|
|
|
434
434
|
return `digest frontmatter check failed: ${problems.join('; ')}`;
|
|
435
435
|
}
|
|
436
436
|
|
|
437
|
+
/**
|
|
438
|
+
* Every locale file of one post that exists on disk, in `PATCH_LOCALES` order.
|
|
439
|
+
* The locale is the last `zh`/`en`/`ja` directory in the path; no such segment → []
|
|
440
|
+
* (a path outside the locale tree has no set to check).
|
|
441
|
+
*/
|
|
442
|
+
function localeSiblings(postPath: string): Array<{ filePath: string; locale: DigestLocale }> {
|
|
443
|
+
const segments = postPath.split(sep);
|
|
444
|
+
let index = -1;
|
|
445
|
+
for (let i = segments.length - 1; i >= 0; i--) {
|
|
446
|
+
if (segments[i] === 'zh' || segments[i] === 'en' || segments[i] === 'ja') {
|
|
447
|
+
index = i;
|
|
448
|
+
break;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
if (index < 0) return [];
|
|
452
|
+
return PATCH_LOCALES.map((locale) => ({
|
|
453
|
+
filePath: [...segments.slice(0, index), locale, ...segments.slice(index + 1)].join(sep),
|
|
454
|
+
locale,
|
|
455
|
+
}));
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
/**
|
|
459
|
+
* Digest gate over the whole locale set instead of the primary file alone (2026-11-16, GH #191).
|
|
460
|
+
*
|
|
461
|
+
* An untranslated sibling — the zh title, description and key points sitting under `/en/` or `/ja/`
|
|
462
|
+
* — passes a zh-only check here and then fails the site's check-digest three ways: the locale's own
|
|
463
|
+
* series name, the body language, and the regenerated-frontmatter drift. `sync` hands all three
|
|
464
|
+
* locales to the CMS and a prepared publish commits all three, so every existing file is checked.
|
|
465
|
+
* Missing files stay skipped (the pre-translation `prepare` path has no siblings yet), and
|
|
466
|
+
* `SURFDASH_DIGEST_CHECK` keeps governing the gate itself.
|
|
467
|
+
*/
|
|
468
|
+
export function digestCheckLocaleSet(postPath: string): string | undefined {
|
|
469
|
+
for (const { filePath, locale } of localeSiblings(postPath)) {
|
|
470
|
+
if (!existsSync(filePath)) continue;
|
|
471
|
+
const problem = digestCheckGate(filePath, locale);
|
|
472
|
+
if (problem) return `${locale}: ${problem}`;
|
|
473
|
+
}
|
|
474
|
+
return undefined;
|
|
475
|
+
}
|
|
476
|
+
|
|
437
477
|
/**
|
|
438
478
|
* Helper to parse file paths from `git status --porcelain` output.
|
|
439
479
|
*/
|
|
@@ -560,10 +600,20 @@ export async function runDailyTopicsSync(surfdashRoot: string, zhPostPath: strin
|
|
|
560
600
|
/** Outcome of {@link runSiteGate}. */
|
|
561
601
|
export type SiteGateOutcome = { ok: true } | { ok: false; error: string };
|
|
562
602
|
|
|
563
|
-
/**
|
|
603
|
+
/**
|
|
604
|
+
* Commands executed by the surfdash site gate before commit and push to main.
|
|
605
|
+
*
|
|
606
|
+
* This list must stay equal to the content suite surfdash's own deploy gate runs
|
|
607
|
+
* (`bun run check:all` = check:content + check:body + check:seo) plus the digest reporter.
|
|
608
|
+
* It used to stop at `check:content`, so a body-rule violation or a localized cover asset that
|
|
609
|
+
* `check:seo` reports as `image-asset-missing` passed here and failed the site's CI right after
|
|
610
|
+
* the push (GH #191, `docs(articles): add more articles`, 2026-11-15).
|
|
611
|
+
*/
|
|
564
612
|
const SITE_GATE_COMMANDS: readonly (readonly string[])[] = [
|
|
565
613
|
['bun', 'run', 'sd', 'check', 'digest'],
|
|
566
614
|
['bun', 'run', 'check:content'],
|
|
615
|
+
['bun', 'run', 'check:body'],
|
|
616
|
+
['bun', 'run', 'check:seo'],
|
|
567
617
|
];
|
|
568
618
|
|
|
569
619
|
/**
|
|
@@ -932,11 +982,11 @@ async function syncPost(options: SurfdashPubOptions): Promise<Result> {
|
|
|
932
982
|
`publish-orchestrator sync failed (exit ${spawned.exitCode}): ${withEmdashTokenHint(cliErrorText(spawned))}`,
|
|
933
983
|
);
|
|
934
984
|
}
|
|
935
|
-
// Digest contract (2026-10-24):
|
|
936
|
-
//
|
|
937
|
-
|
|
938
|
-
if (
|
|
939
|
-
const digestProblem =
|
|
985
|
+
// Digest contract (2026-10-24; locale set 2026-11-16): the orchestrator syncs all three
|
|
986
|
+
// locale files to the CMS, so verify the synced post AND its siblings. Paths outside
|
|
987
|
+
// content/posts/articles/<zh|en|ja>/ carry no digest series to check.
|
|
988
|
+
if (/[\\/]content[\\/]posts[\\/]articles[\\/](?:zh|en|ja)[\\/]/.test(postPath.postPath)) {
|
|
989
|
+
const digestProblem = digestCheckLocaleSet(postPath.postPath);
|
|
940
990
|
if (digestProblem) return fail(digestProblem);
|
|
941
991
|
}
|
|
942
992
|
return ResultSchema.parse({
|
|
@@ -1221,6 +1271,72 @@ function resolvePreparedPost(
|
|
|
1221
1271
|
|
|
1222
1272
|
type PrepareOutcome = { ok: true; prepared: PreparedPost } | { ok: false; result: Result };
|
|
1223
1273
|
|
|
1274
|
+
/** The non-primary locales a digest post carries (`metadata.surfdash.locales`); zh is the primary. */
|
|
1275
|
+
const LOCAL_DRAFTS = ['en', 'ja'] as const;
|
|
1276
|
+
|
|
1277
|
+
/** One localized sibling's authored text, as the workflow's `localize` step delivers it. */
|
|
1278
|
+
interface LocaleDraft {
|
|
1279
|
+
title: string;
|
|
1280
|
+
body: string;
|
|
1281
|
+
}
|
|
1282
|
+
|
|
1283
|
+
/**
|
|
1284
|
+
* Reads `metadata.surfdash.locales.{en,ja}` off the article Content (0409 Q&A: the payload shape the
|
|
1285
|
+
* localize step and the article variant agree on). A blank title or body is not a locale: an
|
|
1286
|
+
* untranslated file must read as missing, so the digest refusal fires instead of publishing zh
|
|
1287
|
+
* text under `/en/` or `/ja/`.
|
|
1288
|
+
*/
|
|
1289
|
+
function readLocaleDrafts(content: Content): Partial<Record<(typeof LOCAL_DRAFTS)[number], LocaleDraft>> {
|
|
1290
|
+
const drafts: Partial<Record<(typeof LOCAL_DRAFTS)[number], LocaleDraft>> = {};
|
|
1291
|
+
const surfdash = content.metadata?.surfdash;
|
|
1292
|
+
if (typeof surfdash !== 'object' || surfdash === null) return drafts;
|
|
1293
|
+
const locales = (surfdash as Record<string, unknown>).locales;
|
|
1294
|
+
if (typeof locales !== 'object' || locales === null) return drafts;
|
|
1295
|
+
for (const locale of LOCAL_DRAFTS) {
|
|
1296
|
+
const entry = (locales as Record<string, unknown>)[locale];
|
|
1297
|
+
if (typeof entry !== 'object' || entry === null) continue;
|
|
1298
|
+
const { title, body } = entry as Record<string, unknown>;
|
|
1299
|
+
if (typeof title !== 'string' || title.trim() === '') continue;
|
|
1300
|
+
if (typeof body !== 'string' || body.trim() === '') continue;
|
|
1301
|
+
drafts[locale] = { title, body };
|
|
1302
|
+
}
|
|
1303
|
+
return drafts;
|
|
1304
|
+
}
|
|
1305
|
+
|
|
1306
|
+
/**
|
|
1307
|
+
* Mints one locale's `index.md` (frontmatter + body) and copies the cover into its `assets/`.
|
|
1308
|
+
*
|
|
1309
|
+
* A file the site's own refine step already marked is not ours to clobber: re-minting replaces the
|
|
1310
|
+
* refined frontmatter (`refined`, `seo_title`, …) with generator defaults and flips a published day
|
|
1311
|
+
* back to a draft — so a refined file is kept and reused (2026-11-05 tier-0 rerun).
|
|
1312
|
+
*/
|
|
1313
|
+
async function mintLocalePost(options: {
|
|
1314
|
+
postDir: string;
|
|
1315
|
+
content: Content;
|
|
1316
|
+
coverPath?: string;
|
|
1317
|
+
publishDate?: string;
|
|
1318
|
+
}): Promise<void> {
|
|
1319
|
+
const filePath = join(options.postDir, 'index.md');
|
|
1320
|
+
if (readRefinedSnapshot(filePath) !== undefined) {
|
|
1321
|
+
echoError(`surfdash-pub: keeping existing refined post at ${filePath} (not re-minting)`);
|
|
1322
|
+
return;
|
|
1323
|
+
}
|
|
1324
|
+
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
|
+
const markdown = mapContentToSurfingMarkdown(options.content, {
|
|
1334
|
+
image: imageFrontmatter,
|
|
1335
|
+
publishDate: options.publishDate,
|
|
1336
|
+
});
|
|
1337
|
+
await createNodeFileSystem().writeFile(filePath, markdown);
|
|
1338
|
+
}
|
|
1339
|
+
|
|
1224
1340
|
/**
|
|
1225
1341
|
* Materializes the local post without invoking the external publishing FSM.
|
|
1226
1342
|
*
|
|
@@ -1278,31 +1394,48 @@ async function preparePost(payload: PublishTransportPayload): Promise<PrepareOut
|
|
|
1278
1394
|
return { ok: false, result: failNotSent('digest post has no cover image (metadata.coverImage)') };
|
|
1279
1395
|
}
|
|
1280
1396
|
|
|
1397
|
+
// 0409 R2: the site requires the full locale set for a digest before it will sync
|
|
1398
|
+
// (`publish-orchestrator.ts` `discoverLocaleFiles` + the `sub-category:ai-daily` guard), so a
|
|
1399
|
+
// missing translation is refused here with effect none — never as the site's opaque
|
|
1400
|
+
// "missing locale file(s)" failure after the spawn.
|
|
1401
|
+
const drafts = readLocaleDrafts(payload.content);
|
|
1402
|
+
if (isDigestContent(payload.content)) {
|
|
1403
|
+
const missing = LOCAL_DRAFTS.filter((locale) => drafts[locale] === undefined);
|
|
1404
|
+
if (missing.length > 0) {
|
|
1405
|
+
return {
|
|
1406
|
+
ok: false,
|
|
1407
|
+
result: failNotSent(
|
|
1408
|
+
`digest post is missing metadata.surfdash.locales for ${missing.join(', ')} — the site refuses a digest with a missing locale file; re-run the localize step before publishing`,
|
|
1409
|
+
),
|
|
1410
|
+
};
|
|
1411
|
+
}
|
|
1412
|
+
}
|
|
1413
|
+
|
|
1281
1414
|
const filePath = join(postDir, 'index.md');
|
|
1415
|
+
const publishDate = runDate ? `${runDate.slice(0, 4)}-${runDate.slice(4, 6)}-${runDate.slice(6, 8)}` : undefined;
|
|
1416
|
+
const cover = typeof coverPath === 'string' ? coverPath : undefined;
|
|
1282
1417
|
try {
|
|
1283
1418
|
// A post the site's own refine step already marked is not ours to clobber: re-minting it
|
|
1284
1419
|
// replaces the refined canonical frontmatter (refine owns `refined`, `seo_title`, …) with
|
|
1285
1420
|
// generator defaults and flips an already-published day back to a draft. Keep the file and
|
|
1286
1421
|
// reuse it; only genuinely fresh days (no marker) get minted (2026-11-05 tier-0 rerun).
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
if (
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
await copyFile(coverPath, join(assetsDir, coverName));
|
|
1295
|
-
imageFrontmatter = `./assets/${coverName}`;
|
|
1422
|
+
await mintLocalePost({ postDir, content: payload.content, coverPath: cover, publishDate });
|
|
1423
|
+
for (const locale of LOCAL_DRAFTS) {
|
|
1424
|
+
const draft = drafts[locale];
|
|
1425
|
+
if (draft === undefined) continue;
|
|
1426
|
+
const siblingDir = resolve(articlesRoot, locale, slug);
|
|
1427
|
+
if (dirname(resolve(siblingDir)) !== resolve(articlesRoot, locale)) {
|
|
1428
|
+
return { ok: false, result: failNotSent(`post path escapes ${articlesRoot}`) };
|
|
1296
1429
|
}
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1430
|
+
// The zh Body and title are replaced by the translation; the frontmatter fields the
|
|
1431
|
+
// site owns (refined, seo_title, …) are rewritten by its own refine/retitle, exactly as
|
|
1432
|
+
// for zh — so a locale file is the same Content shape with a localized title/body.
|
|
1433
|
+
await mintLocalePost({
|
|
1434
|
+
postDir: siblingDir,
|
|
1435
|
+
content: { ...payload.content, title: draft.title, body: draft.body },
|
|
1436
|
+
coverPath: cover,
|
|
1437
|
+
publishDate,
|
|
1302
1438
|
});
|
|
1303
|
-
await createNodeFileSystem().writeFile(filePath, markdown);
|
|
1304
|
-
} else {
|
|
1305
|
-
echoError(`surfdash-pub: keeping existing refined post at ${filePath} (not re-minting)`);
|
|
1306
1439
|
}
|
|
1307
1440
|
} catch (err: unknown) {
|
|
1308
1441
|
return {
|
|
@@ -1389,8 +1522,9 @@ async function publishPreparedFile(
|
|
|
1389
1522
|
// Contract check (ADR-008): the site, not this plugin, owns SEO metadata.
|
|
1390
1523
|
const notRefined = requireRefined(filePath);
|
|
1391
1524
|
if (notRefined) return failUncertain(notRefined);
|
|
1392
|
-
// Digest contract (2026-10-24): the refined values themselves must
|
|
1393
|
-
|
|
1525
|
+
// Digest contract (2026-10-24; locale set 2026-11-16): the refined values themselves must
|
|
1526
|
+
// hold for every locale this publish commits, before any push.
|
|
1527
|
+
const digestProblem = digestCheckLocaleSet(filePath);
|
|
1394
1528
|
if (digestProblem) return failUncertain(digestProblem);
|
|
1395
1529
|
const refined = readRefinedSnapshot(filePath);
|
|
1396
1530
|
|
|
@@ -68,7 +68,9 @@ function parseTitleHeadlines(title: string, locale: PatchLocale): string[] | und
|
|
|
68
68
|
const match = title.match(new RegExp(`^${escapeRe(series)} · (\\d{4}-\\d{2}-\\d{2})${escapeRe(titleSep)}(.+)$`));
|
|
69
69
|
if (!match?.[2]) return undefined;
|
|
70
70
|
const heads = match[2].split(listSep).map((head) => head.trim());
|
|
71
|
-
|
|
71
|
+
// 1..2 structural headlines: the site may collapse a title to one when two do not fit its
|
|
72
|
+
// SEO budget, so a single headline is a valid derivation source (task 0408).
|
|
73
|
+
if (heads.length < 1 || heads.length > 2 || heads.some((head) => head === '')) return undefined;
|
|
72
74
|
return heads;
|
|
73
75
|
}
|
|
74
76
|
|
|
@@ -120,8 +122,12 @@ function buildLocaleEntry(markdown: string, locale: PatchLocale): DailyTopicsLoc
|
|
|
120
122
|
if (!parts) {
|
|
121
123
|
return `${locale}: key_points must be "label — sentence"`;
|
|
122
124
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
+
// The title names the TOP stories; the key-point box carries up to four. The site's own
|
|
126
|
+
// generator emits exactly that shape (`scripts/commands/seo/retitle.ts`: title = "top story 1,
|
|
127
|
+
// story 2", key_points = up to four bullets), so demanding a one-to-one match made every
|
|
128
|
+
// crefitable digest fail the sync. The title must be the leading labels, in order.
|
|
129
|
+
if (headlines.length > parts.labels.length || headlines.some((headline, i) => headline !== parts.labels[i])) {
|
|
130
|
+
return `${locale}: title headlines do not match the leading key_points labels`;
|
|
125
131
|
}
|
|
126
132
|
const claims = parts.sentences;
|
|
127
133
|
const shortClaims = splitDescriptionParts(description, headlines.length) ?? claims;
|
|
@@ -183,7 +189,34 @@ export async function upsertDailyTopicsEntry(
|
|
|
183
189
|
existing = parsed as Record<string, unknown>;
|
|
184
190
|
}
|
|
185
191
|
}
|
|
186
|
-
|
|
192
|
+
// A curated entry WINS. The site's runbook (docs/runbook-seo-geo-operations.md §10) sanctions
|
|
193
|
+
// editing a slug's claims/short_claims by hand, and re-deriving them from the posts on every
|
|
194
|
+
// publish silently reverted that fix (2026-11-16: a curated 20261116 entry was replaced, retitle
|
|
195
|
+
// then re-broke the descriptions, and the gate failed again on the next attempt). Derivation only
|
|
196
|
+
// fills what the map does not already state.
|
|
197
|
+
const prior = existing[slug];
|
|
198
|
+
existing[slug] =
|
|
199
|
+
prior === null || typeof prior !== 'object' || Array.isArray(prior)
|
|
200
|
+
? entry
|
|
201
|
+
: keepCurated(prior as Record<string, unknown>, entry as unknown as Record<string, unknown>);
|
|
187
202
|
await fileSystem.ensureDir(dirname(mapPath));
|
|
188
203
|
await fileSystem.writeFile(mapPath, `${JSON.stringify(existing, null, '\t')}\n`);
|
|
189
204
|
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Merges a derived entry under an existing one, keeping every non-empty curated value and taking the
|
|
208
|
+
* derived value only where the map states nothing (a missing locale, a new field).
|
|
209
|
+
*/
|
|
210
|
+
function keepCurated(curated: Record<string, unknown>, derived: Record<string, unknown>): Record<string, unknown> {
|
|
211
|
+
const merged: Record<string, unknown> = { ...derived, ...curated };
|
|
212
|
+
const isEmpty = (value: unknown): boolean =>
|
|
213
|
+
value === undefined || value === null || value === '' || (Array.isArray(value) && value.length === 0);
|
|
214
|
+
for (const [key, value] of Object.entries(derived)) {
|
|
215
|
+
const current = curated[key];
|
|
216
|
+
if (isEmpty(current)) continue;
|
|
217
|
+
if (value !== null && typeof value === 'object' && !Array.isArray(value) && !isEmpty(current)) {
|
|
218
|
+
merged[key] = keepCurated(current as Record<string, unknown>, value as Record<string, unknown>);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
return merged;
|
|
222
|
+
}
|