@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
@@ -11987,7 +11987,7 @@ var init_file_system_node = () => {};
11987
11987
  import { createHash } from "crypto";
11988
11988
  import { readFileSync as readFileSync3, writeFileSync as writeFileSync2 } from "fs";
11989
11989
  import { readFile } from "fs/promises";
11990
- import { basename, dirname as dirname2, extname as extname2, join } from "path";
11990
+ import { basename, dirname as dirname2, extname as extname2, join as join2 } from "path";
11991
11991
  import { parseArgs } from "util";
11992
11992
 
11993
11993
  // ../../packages/kk-core/src/content-limits.ts
@@ -13795,9 +13795,362 @@ async function runBackfill(client, options, config) {
13795
13795
  });
13796
13796
  }
13797
13797
 
13798
+ // ../../plugins/publishings/podcast-pub/src/corrections.ts
13799
+ import { join } from "path";
13800
+ var EMPTY = [];
13801
+ var NO_DELIVERIES = [];
13802
+ function asRecord3(value) {
13803
+ return value !== null && typeof value === "object" && !Array.isArray(value) ? value : null;
13804
+ }
13805
+ function asString(value) {
13806
+ return typeof value === "string" ? value.trim() : "";
13807
+ }
13808
+ function priorEpisodeReference(retired) {
13809
+ const digits = retired.date.replaceAll(/\D/g, "");
13810
+ if (digits.length < 8)
13811
+ return `\u8BE5\u671F\uFF08${retired.date.trim()}\uFF09`;
13812
+ const day = digits.slice(0, 8);
13813
+ const iso = `${day.slice(0, 4)}-${day.slice(4, 6)}-${day.slice(6, 8)}`;
13814
+ return `\u7B2C${day.slice(-6)}\u671F\uFF08${iso}\uFF09`;
13815
+ }
13816
+ function readCorrection(raw, index) {
13817
+ const entry = asRecord3(raw);
13818
+ if (entry === null)
13819
+ return { reason: `corrections[${index}] is not an object` };
13820
+ const correctionId = asString(entry.correctionId);
13821
+ if (correctionId === "")
13822
+ return { reason: `corrections[${index}] has no correctionId` };
13823
+ const retiredRaw = asRecord3(entry.retired);
13824
+ if (retiredRaw === null)
13825
+ return { reason: `corrections[${index}] (${correctionId}) has no retired record` };
13826
+ const date = asString(retiredRaw.date);
13827
+ const fact = asString(retiredRaw.fact);
13828
+ if (date === "" || fact === "") {
13829
+ return { reason: `corrections[${index}] (${correctionId}) has no retired date/fact to name the prior episode` };
13830
+ }
13831
+ const evidenceRaw = asRecord3(entry.evidence);
13832
+ const wording = asString(entry.wording);
13833
+ const text = asString(entry.text);
13834
+ return {
13835
+ correction: {
13836
+ correctionId,
13837
+ supersedes: asString(entry.supersedes) || asString(retiredRaw.id),
13838
+ judgmentId: asString(entry.judgmentId),
13839
+ selectedId: asString(entry.selectedId) || null,
13840
+ wording,
13841
+ text: text || `\u300C${fact}\u300D\u7ECF\u6838\u9A8C\u6709\u8BEF\uFF0C\u73B0\u66F4\u6B63\u4E3A\uFF1A${wording || "\uFF08\u65B0\u5224\u65AD\uFF09"}`,
13842
+ retired: {
13843
+ id: asString(retiredRaw.id),
13844
+ date,
13845
+ fact,
13846
+ attribution: asString(retiredRaw.attribution) || null
13847
+ },
13848
+ evidence: {
13849
+ url: asString(evidenceRaw?.url),
13850
+ checkedAt: asString(evidenceRaw?.checkedAt) || null
13851
+ }
13852
+ }
13853
+ };
13854
+ }
13855
+ function readFrozenCorrections(raw, options = {}) {
13856
+ const runDateFromOptions = options.runDate ?? null;
13857
+ const snapshot = asRecord3(raw);
13858
+ if (snapshot === null) {
13859
+ return {
13860
+ runDate: runDateFromOptions,
13861
+ corrections: EMPTY,
13862
+ preamble: null,
13863
+ diagnostics: ["correction snapshot is not an object: no corrections carried"]
13864
+ };
13865
+ }
13866
+ const runDate = asString(snapshot.runDate) || runDateFromOptions;
13867
+ const rawCorrections = Array.isArray(snapshot.corrections) ? snapshot.corrections : [];
13868
+ const corrections = [];
13869
+ const diagnostics = [];
13870
+ const seen = new Set;
13871
+ for (const [index, entry] of rawCorrections.entries()) {
13872
+ const parsed = readCorrection(entry, index);
13873
+ if ("reason" in parsed) {
13874
+ diagnostics.push(parsed.reason);
13875
+ continue;
13876
+ }
13877
+ const { correctionId } = parsed.correction;
13878
+ if (seen.has(correctionId)) {
13879
+ diagnostics.push(`duplicate correction id "${correctionId}" at corrections[${index}] ignored`);
13880
+ continue;
13881
+ }
13882
+ seen.add(correctionId);
13883
+ corrections.push(parsed.correction);
13884
+ }
13885
+ return {
13886
+ runDate,
13887
+ corrections,
13888
+ preamble: asString(snapshot.preamble) || null,
13889
+ diagnostics
13890
+ };
13891
+ }
13892
+ var CORRECTIONS_TAG = "<!--kk:corrections-->";
13893
+ function renderCorrectionsBlock(set) {
13894
+ if (set.corrections.length === 0)
13895
+ return null;
13896
+ const lines = ["## \u672C\u671F\u66F4\u6B63\u8BF4\u660E", "", CORRECTIONS_TAG, ""];
13897
+ if (set.preamble !== null && set.preamble !== "")
13898
+ lines.push(set.preamble, "");
13899
+ lines.push("\u6B64\u524D\u8282\u76EE\u4E2D\u7684\u4E00\u5904\u5224\u65AD\u7ECF\u6838\u9A8C\u6709\u8BEF\uFF0C\u6211\u4EEC\u5728\u6B64\u66F4\u6B63\u5E76\u81F4\u6B49\u3002", "");
13900
+ for (const correction of set.corrections) {
13901
+ lines.push(`- **\u66F4\u6B63 ${correction.correctionId}** \xB7 \u4E0A\u671F\u8282\u76EE ${priorEpisodeReference(correction.retired)}`, ` - \u539F\u5224\u65AD\uFF1A\u300C${correction.retired.fact}\u300D`, ` - \u66F4\u6B63\u4E3A\uFF1A${correction.wording !== "" ? correction.wording : correction.text}`, ` - ${evidenceLine(correction)}`);
13902
+ }
13903
+ return `${lines.join(`
13904
+ `)}
13905
+ `;
13906
+ }
13907
+ function evidenceLine(correction) {
13908
+ const { url, checkedAt } = correction.evidence;
13909
+ if (url === "")
13910
+ return `\u4F9D\u636E\uFF1A\u5224\u65AD\u8BB0\u5F55 ${correction.retired.id || correction.supersedes}`;
13911
+ return `\u4F9D\u636E\uFF1A${url}${checkedAt === null ? "" : `\uFF08\u6838\u9A8C\u4E8E ${checkedAt}\uFF09`}`;
13912
+ }
13913
+ var DELIVERED_KEY = (delivery) => `${delivery.correctionId}\x00${delivery.target}`;
13914
+ function delivery(correction, target, runDate, state, reason, deliveredAt, url) {
13915
+ return {
13916
+ correctionId: correction.correctionId,
13917
+ target: target.target,
13918
+ runDate,
13919
+ state,
13920
+ reason,
13921
+ deliveredAt: state === "delivered" ? deliveredAt : null,
13922
+ ...state === "delivered" && url !== undefined && url !== "" ? { url } : {}
13923
+ };
13924
+ }
13925
+ function isSelfTarget(target) {
13926
+ return target === SELF_TARGET;
13927
+ }
13928
+ var SELF_TARGET = "podcast-pub";
13929
+ function classifyCorrectionTarget(correction, target, options = {}) {
13930
+ const runDate = options.runDate ?? null;
13931
+ const now = options.now ?? new Date().toISOString();
13932
+ const id = correction.correctionId;
13933
+ const prior = (options.prior ?? NO_DELIVERIES).find((entry) => entry.correctionId === id && entry.target === target.target && entry.state === "delivered");
13934
+ if (prior !== undefined) {
13935
+ return delivery(correction, target, runDate, "delivered", `target "${target.target}" already received correction ${id} (delivered ${prior.deliveredAt ?? "earlier"}); not re-sent`, prior.deliveredAt ?? now);
13936
+ }
13937
+ if (target.mode === "off") {
13938
+ return delivery(correction, target, runDate, "unsupported", `target "${target.target}" is off in the authorization matrix (mode=off): correction ${id} cannot be delivered there`, now);
13939
+ }
13940
+ if (target.manualStep !== undefined && target.manualStep !== "") {
13941
+ return delivery(correction, target, runDate, "manual", `target "${target.target}" requires the manual step "${target.manualStep}": correction ${id} stays a pending operator step until it is confirmed`, now);
13942
+ }
13943
+ if (target.state === "blocked") {
13944
+ const blockers = (target.blockedBy ?? []).join(", ");
13945
+ return delivery(correction, target, runDate, "blocked", `target "${target.target}" is blocked by unsatisfied dependenc${(target.blockedBy ?? []).length === 1 ? "y" : "ies"} ${blockers === "" ? "(unspecified)" : blockers}: correction ${id} is not delivered yet`, now);
13946
+ }
13947
+ if (target.state === "retry") {
13948
+ return delivery(correction, target, runDate, "blocked", `target "${target.target}" failed its last dispatch (${target.lastError ?? "dispatch failed"}): correction ${id} is not delivered`, now);
13949
+ }
13950
+ if (target.state === "deferred") {
13951
+ return delivery(correction, target, runDate, "pending", `target "${target.target}" dispatches in its own, later window: correction ${id} is carried when that window runs`, now);
13952
+ }
13953
+ if (!target.supportsCorrections) {
13954
+ return delivery(correction, target, runDate, "unsupported", `target "${target.target}" cannot carry an episode correction (${target.capabilityReason ?? "no correction-capable content surface with same-item update"}): correction ${id} is unsupported there`, now);
13955
+ }
13956
+ if (target.state === "dispatched") {
13957
+ const evidence = target.deliveryEvidence?.trim() ?? "";
13958
+ if (isSelfTarget(target.target) || evidence !== "") {
13959
+ return delivery(correction, target, runDate, "delivered", `target "${target.target}" dispatched${runDate === null ? "" : ` on ${runDate}`} with the episode: correction ${id} travelled in its approved content${evidence === "" ? "" : ` (evidence: ${evidence})`}`, now, evidence === "" ? undefined : evidence);
13960
+ }
13961
+ return delivery(correction, target, runDate, "blocked", `target "${target.target}" dispatched${runDate === null ? "" : ` on ${runDate}`} but carries no delivery evidence for correction ${id}: the block's presence in that content is unverified, so the correction is not recorded as delivered`, now);
13962
+ }
13963
+ return delivery(correction, target, runDate, "pending", `target "${target.target}" has not dispatched yet: correction ${id} is queued with the next eligible episode`, now);
13964
+ }
13965
+ function planCorrectionDeliveries(set, targets, options = {}) {
13966
+ const deliveries = [];
13967
+ for (const correction of set.corrections) {
13968
+ for (const target of targets) {
13969
+ deliveries.push(classifyCorrectionTarget(correction, target, options));
13970
+ }
13971
+ }
13972
+ return deliveries;
13973
+ }
13974
+ function recordCorrectionDeliveries(ledger, deliveries) {
13975
+ const kept = [...ledger.deliveries];
13976
+ const recorded = [];
13977
+ const skipped = [];
13978
+ const deliveredKeys = new Set(kept.filter((entry) => entry.state === "delivered").map(DELIVERED_KEY));
13979
+ for (const entry of deliveries) {
13980
+ const key = DELIVERED_KEY(entry);
13981
+ const index = kept.findIndex((existing) => DELIVERED_KEY(existing) === key);
13982
+ if (entry.state === "delivered") {
13983
+ if (deliveredKeys.has(key)) {
13984
+ skipped.push(entry);
13985
+ continue;
13986
+ }
13987
+ deliveredKeys.add(key);
13988
+ recorded.push(entry);
13989
+ if (index === -1)
13990
+ kept.push(entry);
13991
+ else
13992
+ kept[index] = entry;
13993
+ continue;
13994
+ }
13995
+ recorded.push(entry);
13996
+ if (index === -1)
13997
+ kept.push(entry);
13998
+ else if (kept[index]?.state !== "delivered")
13999
+ kept[index] = entry;
14000
+ }
14001
+ return { ledger: { ...ledger, deliveries: kept }, recorded, skipped };
14002
+ }
14003
+ function emptyDeliveryLedger(runDate) {
14004
+ return { schemaVersion: 1, runDate, deliveries: [] };
14005
+ }
14006
+ function correctionDeliveryPath(workDir, runDate) {
14007
+ return join(workDir, "31-publish", `${runDate}_16_corrections-delivery.json`);
14008
+ }
14009
+ async function readCorrectionDeliveries(path, runDate = null) {
14010
+ try {
14011
+ const parsed = await readJsonFile(path);
14012
+ const record = asRecord3(parsed);
14013
+ const deliveries = Array.isArray(record?.deliveries) ? record.deliveries : [];
14014
+ return {
14015
+ schemaVersion: 1,
14016
+ runDate: asString(record?.runDate) || runDate,
14017
+ deliveries: deliveries.filter((entry) => {
14018
+ const candidate = asRecord3(entry);
14019
+ return candidate !== null && asString(candidate.correctionId) !== "" && asString(candidate.target) !== "" && ["delivered", "pending", "manual", "blocked", "unsupported"].includes(asString(candidate.state));
14020
+ })
14021
+ };
14022
+ } catch {
14023
+ return emptyDeliveryLedger(runDate);
14024
+ }
14025
+ }
14026
+ async function writeCorrectionDeliveries(path, ledger) {
14027
+ await ensureDirForFile(path);
14028
+ await writeJsonFile(path, ledger);
14029
+ return path;
14030
+ }
14031
+
13798
14032
  // ../../plugins/publishings/podcast-pub/src/map.ts
13799
14033
  import { extname } from "path";
13800
14034
 
14035
+ // ../../plugins/publishings/podcast-pub/src/show-notes-brief.ts
14036
+ var ARTICLE_PLACEHOLDER = '<p class="kk-tl-more">\u5B8C\u6574\u56FE\u6587\u7248\uFF1A\u5F85\u6587\u7AE0\u53D1\u5E03\u56DE\u6267</p>';
14037
+ var CARDS_STYLE = `<style>
14038
+ .kk-cards{display:grid;grid-template-columns:repeat(auto-fill,minmax(180px,1fr));gap:12px;margin:1em 0}
14039
+ .kk-card{margin:0;border:1px solid rgba(128,128,128,.25);border-radius:10px;overflow:hidden}
14040
+ .kk-card img{display:block;width:100%;height:auto}
14041
+ .kk-card figcaption{padding:8px 10px;font-size:.9em;color:#444}
14042
+ .kk-card-n{font-weight:700;color:#0969da;margin-right:6px}
14043
+ @media (max-width:420px){.kk-cards{grid-template-columns:1fr}}
14044
+ </style>`;
14045
+ var isHttpUrl = (value) => typeof value === "string" && /^https?:\/\//i.test(value.trim());
14046
+ function textOf(value) {
14047
+ return typeof value === "string" ? value.trim() : "";
14048
+ }
14049
+ function planCards(raw) {
14050
+ const entries = Array.isArray(raw) ? raw : raw !== null && typeof raw === "object" && Array.isArray(raw.cards) ? raw.cards : [];
14051
+ const cards = [];
14052
+ const diagnostics = [];
14053
+ entries.forEach((entry, position) => {
14054
+ if (entry === null || typeof entry !== "object") {
14055
+ diagnostics.push({ index: position + 1, reason: "malformed", detail: "card entry is not an object" });
14056
+ return;
14057
+ }
14058
+ const card = entry;
14059
+ const index = typeof card.index === "number" && Number.isFinite(card.index) && card.index > 0 ? Math.trunc(card.index) : position + 1;
14060
+ const uploadStatus = textOf(card.uploadStatus);
14061
+ const uploadError = textOf(card.uploadError);
14062
+ const url = isHttpUrl(card.url) ? card.url.trim() : isHttpUrl(card.imageUrl) ? card.imageUrl.trim() : "";
14063
+ if (uploadStatus === "failed" || uploadError !== "") {
14064
+ diagnostics.push({ index, reason: "upload-failed", detail: uploadError || "upload reported failed" });
14065
+ } else if (textOf(card.status) !== "rendered") {
14066
+ diagnostics.push({
14067
+ index,
14068
+ reason: "asset-missing",
14069
+ detail: `card status is "${textOf(card.status) || "unknown"}"`
14070
+ });
14071
+ }
14072
+ const copy = textOf(card.copy);
14073
+ const sourcePoint = textOf(card.sourcePoint);
14074
+ const alt = textOf(card.alt) || copy || sourcePoint || `\u672C\u671F\u5361\u7247 ${index}`;
14075
+ cards.push({ index, alt, imageUrl: uploadStatus === "failed" ? "" : url, text: copy || sourcePoint || alt });
14076
+ });
14077
+ return { cards, diagnostics };
14078
+ }
14079
+ function renderCardsRegion(cards) {
14080
+ if (cards.length === 0)
14081
+ return "";
14082
+ const figures = cards.map((card) => {
14083
+ const img = card.imageUrl === "" ? "" : `<img src="${escapeHtml(card.imageUrl)}" alt="${escapeHtml(card.alt)}" loading="lazy">`;
14084
+ return `
14085
+ <figure class="kk-card">${img}<figcaption><span class="kk-card-n">${card.index}</span>${escapeHtml(card.text)}</figcaption></figure>`;
14086
+ }).join("");
14087
+ return `<!--kk:cards-->
14088
+ ${CARDS_STYLE}
14089
+ <div class="kk-cards">${figures}
14090
+ </div>
14091
+ <!--/kk:cards-->`;
14092
+ }
14093
+ function renderBriefShowNotes(input) {
14094
+ const { cards, diagnostics } = planCards(input.cards);
14095
+ const offsets = computeAudioOffsets(input.docs, input.audioSegments);
14096
+ const rows = input.docs.map((doc, i) => {
14097
+ const title = escapeHtml(doc.title ?? `\u6761\u76EE ${i + 1}`);
14098
+ const brief = escapeHtml(itemBrief(doc));
14099
+ const at = formatOffset(offsets[i] ?? Number.NaN);
14100
+ const label = escapeHtml(sourceLabelFor(doc));
14101
+ const link = isHttpUrl(doc.sourceUri) ? ` <a href="${escapeHtml(doc.sourceUri)}" target="_blank" rel="noopener">\u6765\u6E90\uFF1A${label}</a>` : ` <span class="kk-tl-src">\u6765\u6E90\uFF1A${label}</span>`;
14102
+ return `
14103
+ <div class="kk-tl-row"><div class="kk-tl-t">${at}</div><div class="kk-tl-body"><div class="kk-tl-title">${i + 1}. ${title}${link}</div><p class="kk-tl-brief">${brief}</p></div></div>`;
14104
+ }).join("");
14105
+ const articleEntry = input.articleUrl !== undefined && isHttpUrl(input.articleUrl) ? `<p class="kk-tl-more">\u5B8C\u6574\u56FE\u6587\u7248\uFF1A<a href="${escapeHtml(input.articleUrl.trim())}" target="_blank" rel="noopener">\u672C\u671F\u5B8C\u6574\u6587\u7AE0</a></p>` : ARTICLE_PLACEHOLDER;
14106
+ const lines = [];
14107
+ if (input.title !== undefined && input.title !== "")
14108
+ lines.push(`# ${input.title}`, "");
14109
+ if (input.docs.length > 0) {
14110
+ lines.push(`<!--kk:timeline-->
14111
+ <div class="kk-tl">${rows}
14112
+ </div>
14113
+ ${articleEntry}
14114
+ <!--/kk:timeline-->`, "");
14115
+ }
14116
+ const cardRegion = renderCardsRegion(cards);
14117
+ if (cardRegion !== "")
14118
+ lines.push(cardRegion, "");
14119
+ return { markdown: lines.join(`
14120
+ `), diagnostics };
14121
+ }
14122
+ function receiptSlug(receipt) {
14123
+ const entries = Array.isArray(receipt) ? receipt : receipt !== null && typeof receipt === "object" && Array.isArray(receipt.targets) ? receipt.targets : receipt !== null && typeof receipt === "object" ? [receipt] : [];
14124
+ for (const entry of entries) {
14125
+ if (entry === null || typeof entry !== "object")
14126
+ continue;
14127
+ const record = entry;
14128
+ if (record.ok === false)
14129
+ continue;
14130
+ const metadata = record.metadata !== null && typeof record.metadata === "object" ? record.metadata : record;
14131
+ const postPath = textOf(metadata.postPath);
14132
+ if (postPath === "")
14133
+ continue;
14134
+ const segments = postPath.split(/[\\/]/).filter((s) => s.length > 0);
14135
+ const slug = segments.length >= 2 ? segments[segments.length - 2] ?? "" : "";
14136
+ if (slug !== "" && slug !== "posts")
14137
+ return `${slug}\x00${segments.find((s) => ["zh", "en", "ja"].includes(s)) ?? "zh"}`;
14138
+ }
14139
+ return "";
14140
+ }
14141
+ function applyArticleReceipt(markdown, receipt, articleBaseUrl = "https://surfing.salty.vip") {
14142
+ const proven = receiptSlug(receipt);
14143
+ if (proven === "" || !markdown.includes(ARTICLE_PLACEHOLDER))
14144
+ return { markdown, enriched: false };
14145
+ const [slug = "", locale = "zh"] = proven.split("\x00");
14146
+ const prefix = locale === "en" ? "" : `/${locale}`;
14147
+ const url = `${articleBaseUrl.replace(/\/+$/, "")}${prefix}/posts/${slug}`;
14148
+ return {
14149
+ markdown: markdown.replace(ARTICLE_PLACEHOLDER, `<p class="kk-tl-more">\u5B8C\u6574\u56FE\u6587\u7248\uFF1A<a href="${escapeHtml(url)}" target="_blank" rel="noopener">\u672C\u671F\u5B8C\u6574\u6587\u7AE0</a></p>`),
14150
+ enriched: true
14151
+ };
14152
+ }
14153
+
13801
14154
  // ../../plugins/publishings/podcast-pub/src/show-notes.ts
13802
14155
  function escapeHtml(value) {
13803
14156
  return value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;");
@@ -13861,7 +14214,7 @@ function computeAudioOffsets(docs, segments) {
13861
14214
  return fallback();
13862
14215
  return starts;
13863
14216
  }
13864
- var isHttpUrl = (u) => /^https?:\/\//i.test(u.trim());
14217
+ var isHttpUrl2 = (u) => /^https?:\/\//i.test(u.trim());
13865
14218
  var TIMELINE_STYLE = `<style>
13866
14219
  .kk-tl{margin:1em 0}
13867
14220
  .kk-tl-row{display:flex;gap:12px;padding:10px 0;border-bottom:1px solid rgba(128,128,128,.25)}
@@ -13882,11 +14235,11 @@ function renderTimelineHtml(docs, offsets, articleUrl, style) {
13882
14235
  const title = escapeHtml(d.title ?? `\u6761\u76EE ${i + 1}`);
13883
14236
  const brief = escapeHtml(itemBrief(d));
13884
14237
  const at = formatOffset(offsets[i] ?? Number.NaN);
13885
- const link = d.sourceUri && isHttpUrl(d.sourceUri) ? ` <a href="${escapeHtml(d.sourceUri)}" target="_blank" rel="noopener">\u6765\u6E90</a>` : "";
14238
+ const link = d.sourceUri && isHttpUrl2(d.sourceUri) ? ` <a href="${escapeHtml(d.sourceUri)}" target="_blank" rel="noopener">\u6765\u6E90</a>` : "";
13886
14239
  return `
13887
14240
  <div class="kk-tl-row"><div class="kk-tl-t">${at}</div><div class="kk-tl-body"><div class="kk-tl-title">${i + 1}. ${title}${link}</div><p class="kk-tl-brief">${brief}</p></div></div>`;
13888
14241
  }).join("");
13889
- const articleTail = isHttpUrl(articleUrl) ? `<p>\u5B8C\u6574\u56FE\u6587\u7248\uFF1A<a href="${escapeHtml(articleUrl)}" target="_blank" rel="noopener">${escapeHtml("\u672C\u671F\u5B8C\u6574\u6587\u7AE0")}</a></p>` : `<p>${escapeHtml("\u672C\u671F\u5B8C\u6574\u6587\u7AE0")}</p>`;
14242
+ const articleTail = isHttpUrl2(articleUrl) ? `<p>\u5B8C\u6574\u56FE\u6587\u7248\uFF1A<a href="${escapeHtml(articleUrl)}" target="_blank" rel="noopener">${escapeHtml("\u672C\u671F\u5B8C\u6574\u6587\u7AE0")}</a></p>` : `<p>${escapeHtml("\u672C\u671F\u5B8C\u6574\u6587\u7AE0")}</p>`;
13890
14243
  const styleBlock = style === "omit" ? "" : `${TIMELINE_STYLE}
13891
14244
  `;
13892
14245
  const before = style === "before" ? styleBlock : "";
@@ -13897,10 +14250,19 @@ ${before}<div class="kk-tl">${rows}
13897
14250
  ${after}${articleTail}
13898
14251
  <!--/kk:timeline-->`;
13899
14252
  }
14253
+ var CARDS_TAG = /^<\/?(?:div|figure|figcaption|span|p|img)(?:\s+(?:class="kk-cards"|class="kk-card"|class="kk-card-n"|src="https?:\/\/[^"<>\s]*"|alt="[^"<>]*"|loading="lazy"))*\s*\/?>$/;
14254
+ function isGeneratedCards(block) {
14255
+ const rest = block.replace(CARDS_STYLE, "");
14256
+ if (rest.includes("<style") || rest.includes("<!--") || rest.includes("<script"))
14257
+ return false;
14258
+ return (rest.match(/<[^>]*>/g) ?? []).every((tag) => CARDS_TAG.test(tag)) && !/<(?![^>]*>)/.test(rest);
14259
+ }
13900
14260
  function renderShowNotesHtml(markdown) {
13901
14261
  const blocks = [];
13902
14262
  const timeline = [];
14263
+ const cards = [];
13903
14264
  let inTimeline = false;
14265
+ let inCards = false;
13904
14266
  let paragraph = [];
13905
14267
  const flush = () => {
13906
14268
  if (paragraph.length > 0) {
@@ -13925,6 +14287,32 @@ function renderShowNotesHtml(markdown) {
13925
14287
  inTimeline = true;
13926
14288
  continue;
13927
14289
  }
14290
+ if (line === "<!--kk:cards-->") {
14291
+ flush();
14292
+ inCards = true;
14293
+ continue;
14294
+ }
14295
+ if (inCards) {
14296
+ if (line === "<!--/kk:cards-->") {
14297
+ inCards = false;
14298
+ if (isGeneratedCards(cards.join(`
14299
+ `))) {
14300
+ blocks.push(cards.join(`
14301
+ `));
14302
+ } else {
14303
+ for (const l of cards) {
14304
+ const t = l.trim();
14305
+ if (t.length > 0)
14306
+ paragraph.push(t);
14307
+ }
14308
+ flush();
14309
+ }
14310
+ cards.length = 0;
14311
+ continue;
14312
+ }
14313
+ cards.push(rawLine);
14314
+ continue;
14315
+ }
13928
14316
  if (inTimeline) {
13929
14317
  if (line === "<!--/kk:timeline-->") {
13930
14318
  inTimeline = false;
@@ -13960,6 +14348,15 @@ function renderShowNotesHtml(markdown) {
13960
14348
  flush();
13961
14349
  if (timeline.length > 0)
13962
14350
  escapeBufferedTimeline();
14351
+ if (cards.length > 0) {
14352
+ for (const l of cards) {
14353
+ const t = l.trim();
14354
+ if (t.length > 0)
14355
+ paragraph.push(t);
14356
+ }
14357
+ cards.length = 0;
14358
+ flush();
14359
+ }
13963
14360
  return blocks.join(`
13964
14361
  `);
13965
14362
  }
@@ -13969,6 +14366,16 @@ function itemBrief(d) {
13969
14366
  return meta.brief.trim();
13970
14367
  return splitSentences((d.body ?? "").trim(), { cjkOnly: true }).slice(0, 2).join("");
13971
14368
  }
14369
+ function sourceLabelFor(doc) {
14370
+ const metadata = doc.metadata ?? {};
14371
+ if (typeof metadata.sourceName === "string" && metadata.sourceName.trim())
14372
+ return metadata.sourceName.trim();
14373
+ try {
14374
+ return new URL(doc.sourceUri ?? "").hostname.replace(/^www\./, "");
14375
+ } catch {
14376
+ return "\u6765\u6E90";
14377
+ }
14378
+ }
13972
14379
  function renderShowNotesMarkdown(docs, opts, warnings) {
13973
14380
  const slugify = (t) => {
13974
14381
  const s = t.toLowerCase().replace(/[^\w\s-]/g, "").trim().replace(/[\s_]+/g, "-");
@@ -13984,16 +14391,6 @@ function renderShowNotesMarkdown(docs, opts, warnings) {
13984
14391
  warn("brief mode requested but ARTICLE_POST_PATH is empty; using legacy layout", warnings);
13985
14392
  }
13986
14393
  const briefMode = opts.briefMode === true && postSlug.length > 0;
13987
- const sourceLabel = (d) => {
13988
- const m = d.metadata ?? {};
13989
- if (typeof m.sourceName === "string" && m.sourceName.trim())
13990
- return m.sourceName.trim();
13991
- try {
13992
- return new URL(d.sourceUri ?? "").hostname.replace(/^www\./, "");
13993
- } catch {
13994
- return "\u6765\u6E90";
13995
- }
13996
- };
13997
14394
  const offsets = computeAudioOffsets(docs, opts.audioSegments);
13998
14395
  const lines = [`# ${opts.title}`, ""];
13999
14396
  const summaryOn = opts.summaryParagraph !== false;
@@ -14036,7 +14433,7 @@ function renderShowNotesMarkdown(docs, opts, warnings) {
14036
14433
  docs.forEach((d, i) => {
14037
14434
  const body = (d.body ?? "").trim();
14038
14435
  const sentences = splitSentences(body, { cjkOnly: true }).slice(0, 2).join("");
14039
- lines.push(`## ${i + 1}. ${d.title ?? `\u6761\u76EE ${i + 1}`}`, "", sentences, "", `[\u6765\u6E90\uFF1A${sourceLabel(d)}](${d.sourceUri ?? ""})`, "");
14436
+ lines.push(`## ${i + 1}. ${d.title ?? `\u6761\u76EE ${i + 1}`}`, "", sentences, "", `[\u6765\u6E90\uFF1A${sourceLabelFor(d)}](${d.sourceUri ?? ""})`, "");
14040
14437
  });
14041
14438
  lines.push(`\u8BE6\u60C5\u89C1\u672C\u671F\u5B8C\u6574\u6587\u7AE0\uFF1A[ ${opts.title} ](${articleUrl})`, "");
14042
14439
  }
@@ -14360,6 +14757,36 @@ function resolveShowNotesRenderOptions(options) {
14360
14757
  }
14361
14758
  };
14362
14759
  }
14760
+ function resolveCorrectionSet() {
14761
+ const path = resolveOptionString(undefined, "PODCAST_PUB_CORRECTIONS");
14762
+ if (path === undefined)
14763
+ return null;
14764
+ try {
14765
+ const parsed = JSON.parse(readFileSync3(path, "utf-8"));
14766
+ return {
14767
+ set: readFrozenCorrections(parsed, {
14768
+ runDate: resolveOptionString(undefined, "PODCAST_PUB_RUN_DATE") ?? null
14769
+ })
14770
+ };
14771
+ } catch (error) {
14772
+ return {
14773
+ error: `corrections: cannot read the frozen judgment snapshot ${path} (${error instanceof Error ? error.message : String(error)}) \u2014 the correction block is NOT carried; fix the snapshot path before publishing`
14774
+ };
14775
+ }
14776
+ }
14777
+ function insertCorrectionBlock(markdown, block) {
14778
+ if (block === null)
14779
+ return markdown;
14780
+ const split = markdown.indexOf(`
14781
+ `);
14782
+ if (split === -1)
14783
+ return `${markdown}
14784
+
14785
+ ${block}`;
14786
+ return `${markdown.slice(0, split)}
14787
+
14788
+ ${block}${markdown.slice(split + 1)}`;
14789
+ }
14363
14790
  function renderShowNotesFromOptions(options) {
14364
14791
  const docs = DocListSchema.safeParse(options.docs);
14365
14792
  if (!docs.success) {
@@ -14370,7 +14797,64 @@ function renderShowNotesFromOptions(options) {
14370
14797
  if ("error" in renderOptions)
14371
14798
  return { error: renderOptions.error };
14372
14799
  const warnings = [];
14373
- return { markdown: renderShowNotesMarkdown(docs.data, renderOptions.renderOptions, warnings), warnings };
14800
+ const corrections = resolveCorrectionSet();
14801
+ if (corrections !== null && "error" in corrections)
14802
+ return { error: corrections.error };
14803
+ const block = corrections === null ? null : renderCorrectionsBlock(corrections.set);
14804
+ if (corrections !== null) {
14805
+ for (const diagnostic of corrections.set.diagnostics) {
14806
+ warnings.push(`WARN podcast-pub: correction ${diagnostic}`);
14807
+ }
14808
+ }
14809
+ const withCorrections = (markdown) => insertCorrectionBlock(markdown, block);
14810
+ const brief = resolveBriefNotes(docs.data, renderOptions.renderOptions, warnings);
14811
+ if (brief !== null)
14812
+ return { markdown: withCorrections(brief.markdown), warnings };
14813
+ return {
14814
+ markdown: withCorrections(renderShowNotesMarkdown(docs.data, renderOptions.renderOptions, warnings)),
14815
+ warnings
14816
+ };
14817
+ }
14818
+ function resolveBriefNotes(docs, renderOptions, warnings) {
14819
+ const cardsPath = resolveOptionString(undefined, "PODCAST_PUB_CARDS");
14820
+ const reviewMode = process.env.PODCAST_PUB_BRIEF_WITHOUT_RECEIPT === "true";
14821
+ if (renderOptions.briefMode !== true || cardsPath === undefined && !reviewMode)
14822
+ return null;
14823
+ let cards;
14824
+ if (cardsPath !== undefined) {
14825
+ try {
14826
+ cards = JSON.parse(readFileSync3(cardsPath, "utf-8"));
14827
+ } catch (error) {
14828
+ warnings.push(`WARN podcast-pub: unreadable card manifest ${cardsPath}: ${error.message}`);
14829
+ }
14830
+ }
14831
+ const rendered = renderBriefShowNotes({
14832
+ docs,
14833
+ ...renderOptions.title !== undefined ? { title: renderOptions.title } : {},
14834
+ ...renderOptions.audioSegments !== undefined ? { audioSegments: renderOptions.audioSegments } : {},
14835
+ ...cards !== undefined ? { cards } : {}
14836
+ });
14837
+ for (const diagnostic of rendered.diagnostics) {
14838
+ warnings.push(`WARN podcast-pub: card ${diagnostic.index} ${diagnostic.reason}: ${diagnostic.detail}`);
14839
+ }
14840
+ const diagnosticsPath = resolveOptionString(undefined, "PODCAST_PUB_CARDS_DIAGNOSTICS");
14841
+ if (diagnosticsPath !== undefined) {
14842
+ try {
14843
+ writeFileSync2(diagnosticsPath, `${JSON.stringify({ runDate: renderOptions.runDate, cards: rendered.diagnostics }, null, 2)}
14844
+ `, "utf-8");
14845
+ } catch (error) {
14846
+ warnings.push(`WARN podcast-pub: cannot write card diagnostics: ${error.message}`);
14847
+ }
14848
+ }
14849
+ const postPath = renderOptions.articlePostPath ?? "";
14850
+ const enriched = postPath === "" ? { markdown: rendered.markdown, enriched: false } : applyArticleReceipt(rendered.markdown, { ok: true, target: TARGET2, metadata: { postPath } }, renderOptions.articleBaseUrl);
14851
+ if (postPath === "") {
14852
+ warnings.push("WARN podcast-pub: no article receipt yet \u2014 notes rendered without an article link");
14853
+ }
14854
+ const footer = renderOptions.footerNote !== undefined ? `
14855
+ ${renderOptions.footerNote}
14856
+ ` : "";
14857
+ return { markdown: `${enriched.markdown}${footer}`, warnings };
14374
14858
  }
14375
14859
  function resolveAssemblyOptions(options) {
14376
14860
  const assembly = {};
@@ -14429,7 +14913,7 @@ function prepareTranscript(metadata, warnings, emit = (message) => warn(message,
14429
14913
  emit("transcript skipped: no local mp3Path/audioPath/audioFile to anchor the .vtt artifact next to");
14430
14914
  return;
14431
14915
  }
14432
- const vttPath = `${join(dirname2(source), basename(source).replace(/\.[^.]+$/, ""))}.vtt`;
14916
+ const vttPath = `${join2(dirname2(source), basename(source).replace(/\.[^.]+$/, ""))}.vtt`;
14433
14917
  try {
14434
14918
  writeFileSync2(vttPath, renderWebVtt(cues), "utf-8");
14435
14919
  } catch (error) {
@@ -14589,6 +15073,78 @@ function mappedValidateInput(content) {
14589
15073
  ...episodeExtras(shaped, policy.fields.seo)
14590
15074
  };
14591
15075
  }
15076
+ function readCorrectionTargets(raw) {
15077
+ if (!Array.isArray(raw))
15078
+ return [];
15079
+ const targets = [];
15080
+ for (const entry of raw) {
15081
+ if (entry === null || typeof entry !== "object")
15082
+ continue;
15083
+ const row = entry;
15084
+ const target = typeof row.target === "string" ? row.target.trim() : "";
15085
+ if (target === "")
15086
+ continue;
15087
+ const blockedBy = Array.isArray(row.blockedBy) ? row.blockedBy.filter((id) => typeof id === "string") : [];
15088
+ targets.push({
15089
+ target,
15090
+ ...typeof row.mode === "string" ? { mode: row.mode } : {},
15091
+ ...typeof row.state === "string" ? { state: row.state } : {},
15092
+ ...typeof row.manualStep === "string" ? { manualStep: row.manualStep } : {},
15093
+ ...typeof row.lastError === "string" ? { lastError: row.lastError } : {},
15094
+ ...blockedBy.length > 0 ? { blockedBy } : {},
15095
+ supportsCorrections: row.supportsCorrections === true,
15096
+ ...typeof row.capabilityReason === "string" ? { capabilityReason: row.capabilityReason } : {},
15097
+ ...typeof row.deliveryEvidence === "string" ? { deliveryEvidence: row.deliveryEvidence } : {}
15098
+ });
15099
+ }
15100
+ return targets;
15101
+ }
15102
+ async function recordCorrectionDelivery(options, episodeStatus, delivery, warnings) {
15103
+ const corrections = resolveCorrectionSet();
15104
+ if (corrections === null || "error" in corrections) {
15105
+ if (corrections !== null && "error" in corrections)
15106
+ warnings.push(`WARN podcast-pub: ${corrections.error}`);
15107
+ return null;
15108
+ }
15109
+ if (corrections.set.corrections.length === 0)
15110
+ return null;
15111
+ const runDate = corrections.set.runDate;
15112
+ const path = resolveOptionString(undefined, "PODCAST_PUB_CORRECTION_DELIVERY");
15113
+ const targets = [
15114
+ {
15115
+ target: TARGET2,
15116
+ state: episodeStatus === "published" ? "dispatched" : "pending",
15117
+ supportsCorrections: true
15118
+ },
15119
+ ...readCorrectionTargets(options.correctionTargets)
15120
+ ];
15121
+ const ledgerPath = path ?? (runDate === null ? undefined : correctionDeliveryPath(process.cwd(), runDate));
15122
+ const ledger = ledgerPath === undefined ? null : await readCorrectionDeliveries(ledgerPath, runDate);
15123
+ const planned = planCorrectionDeliveries(corrections.set, targets, {
15124
+ runDate,
15125
+ prior: ledger?.deliveries ?? []
15126
+ }).map((entry) => entry.state === "delivered" && entry.target === TARGET2 ? {
15127
+ ...entry,
15128
+ ...delivery.itemId === undefined ? {} : { itemId: delivery.itemId },
15129
+ ...delivery.url === undefined ? {} : { url: delivery.url }
15130
+ } : entry);
15131
+ for (const entry of planned) {
15132
+ if (entry.state === "delivered")
15133
+ continue;
15134
+ warnings.push(`WARN podcast-pub: correction ${entry.correctionId} not delivered to target "${entry.target}" \u2014 ${entry.reason}`);
15135
+ }
15136
+ if (ledger !== null && ledgerPath !== undefined) {
15137
+ const { ledger: next, skipped } = recordCorrectionDeliveries(ledger, planned);
15138
+ await writeCorrectionDeliveries(ledgerPath, next);
15139
+ for (const entry of skipped) {
15140
+ warnings.push(`WARN podcast-pub: correction ${entry.correctionId} already delivered to target "${entry.target}" \u2014 not re-sent`);
15141
+ }
15142
+ }
15143
+ return {
15144
+ correctionIds: corrections.set.corrections.map((entry) => entry.correctionId),
15145
+ delivered: planned.filter((entry) => entry.state === "delivered").map((entry) => entry.target)
15146
+ };
15147
+ }
14592
15148
  async function publishEpisode(client, payload, options) {
14593
15149
  const assembly = resolveAssemblyOptions(options);
14594
15150
  if ("error" in assembly)
@@ -14651,13 +15207,20 @@ async function publishEpisode(client, payload, options) {
14651
15207
  } catch {
14652
15208
  hostedItem = undefined;
14653
15209
  }
15210
+ const hostedUrl = publicItemUrl(hostedItem, itemId, client);
15211
+ const corrections = await recordCorrectionDelivery(options, String(episode.status), { itemId, url: hostedUrl }, fields.warnings);
14654
15212
  return ResultSchema.parse({
14655
15213
  ok: true,
14656
15214
  target: TARGET2,
14657
- url: publicItemUrl(hostedItem, itemId, client),
15215
+ url: hostedUrl,
14658
15216
  id: itemId,
14659
15217
  message: "Published successfully to microfeed (hosted audio, single-call create)",
14660
- ...fields.warnings.length > 0 ? { metadata: { warnings: fields.warnings } } : {}
15218
+ ...fields.warnings.length > 0 || corrections !== null ? {
15219
+ metadata: {
15220
+ ...corrections !== null ? { corrections } : {},
15221
+ ...fields.warnings.length > 0 ? { warnings: fields.warnings } : {}
15222
+ }
15223
+ } : {}
14661
15224
  });
14662
15225
  }
14663
15226
  const itemId = await createEpisodeItem(client, {
@@ -14697,15 +15260,18 @@ async function publishEpisode(client, payload, options) {
14697
15260
  ...imageUrl ? { image: imageUrl } : {},
14698
15261
  ...episodeExtras(episode, seo)
14699
15262
  });
15263
+ const publishedUrl = publicItemUrl(item, itemId, client);
15264
+ const corrections = await recordCorrectionDelivery(options, String(episode.status), { itemId, url: publishedUrl }, fields.warnings);
14700
15265
  return ResultSchema.parse({
14701
15266
  ok: true,
14702
15267
  target: TARGET2,
14703
- url: publicItemUrl(item, itemId, client),
15268
+ url: publishedUrl,
14704
15269
  id: itemId,
14705
15270
  message: "Published successfully to microfeed (two-phase upload + publish)",
14706
15271
  metadata: {
14707
15272
  itemId,
14708
15273
  imageUrl: imageUrl ?? null,
15274
+ ...corrections !== null ? { corrections } : {},
14709
15275
  ...fields.warnings.length > 0 ? { warnings: fields.warnings } : {}
14710
15276
  }
14711
15277
  });