@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.
- package/.claude-plugin/marketplace.json +1 -1
- package/dist/board/collect/index.js +1 -0
- package/dist/board/daily-voice/index.js +1279 -261
- package/dist/board/itc/index.js +1 -0
- package/dist/index.js +13938 -8966
- 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/gemini-tts/dist/index.js +47 -7
- package/plugins/generations/gemini-tts/src/gemini-client.ts +34 -6
- package/plugins/generations/music-gen/README.md +277 -0
- package/plugins/generations/music-gen/dist/index.js +23580 -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 +36 -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 +35 -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 +927 -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 +951 -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/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 +31 -1
- package/plugins/generations/voice-gen/src/voicebox-client.ts +50 -1
- package/plugins/generations/voxcpm-tts/dist/index.js +81 -9
- 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/kk/README.md +21 -0
- package/plugins/kk/decisions/kk-safety.yaml +5 -2
- package/plugins/kk/plugin.json +1 -1
- package/plugins/kk/schedules/kk-serve.launchd.plist.tmpl +14 -2
- 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 +933 -60
- package/plugins/kk/scripts/episode-identity.ts +180 -0
- package/plugins/kk/scripts/kk-workflow-stages.ts +111 -12
- package/plugins/kk/scripts/music-stages.ts +624 -0
- package/plugins/kk/scripts/news-editorial-ledger.ts +906 -0
- package/plugins/kk/scripts/safety-artifact-check.ts +28 -5
- 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/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/workflows/kk-daily-ai-voice.yaml +12 -11
- package/plugins/kk/workflows/kk-daily-ai-voice2.yaml +13 -12
- package/plugins/kk/workflows/kk-daily-safety.yaml +12 -10
- package/plugins/kk/workflows/kk-music.yaml +332 -0
- package/plugins/kk/workflows/kk-news-generate.yaml +81 -6
- package/plugins/kk/workflows/kk-publish.yaml +4 -1
- 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 +62 -10
- package/plugins/publishings/linkedin-pub/dist/profile-check.js +16 -1
- package/plugins/publishings/linkedin-pub/src/index.ts +99 -12
- 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 +59 -8
- package/plugins/publishings/shipinhao-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/shipinhao-pub/src/audio-flow.ts +105 -6
- 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 +80 -24
- package/plugins/publishings/surfdash-pub/src/digest-check.ts +7 -3
- package/plugins/publishings/surfdash-pub/src/index.ts +107 -18
- package/plugins/publishings/surfdash-pub/src/patch.ts +21 -3
- package/plugins/publishings/surfdash-pub/src/topic-claims.ts +3 -1
- package/plugins/publishings/threads-pub/dist/index.js +58 -6
- package/plugins/publishings/threads-pub/dist/profile-check.js +18 -2
- package/plugins/publishings/threads-pub/src/post-rail.ts +101 -4
- package/plugins/publishings/wechatmp-pub/dist/index.js +105 -35
- package/plugins/publishings/wechatmp-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/wechatmp-pub/src/cgi-draft.ts +87 -53
- package/plugins/publishings/wechatmp-pub/src/enrich.ts +61 -3
- package/plugins/publishings/wechatmp-pub/src/flow.ts +28 -0
- package/plugins/publishings/weibo-pub/dist/index.js +11 -1
- package/plugins/publishings/weibo-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/x-pub/dist/index.js +95 -10
- package/plugins/publishings/x-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/x-pub/src/post-rail.ts +154 -12
- 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
|
@@ -67,6 +67,12 @@ import {
|
|
|
67
67
|
writeFileSync,
|
|
68
68
|
} from 'node:fs';
|
|
69
69
|
import { basename, isAbsolute, join, resolve } from 'node:path';
|
|
70
|
+
import {
|
|
71
|
+
EPISODE_IDENTITY_KEY,
|
|
72
|
+
type EpisodeIdentity,
|
|
73
|
+
freezeEpisodeIdentity,
|
|
74
|
+
identityFromMetadata,
|
|
75
|
+
} from './episode-identity.ts';
|
|
70
76
|
import {
|
|
71
77
|
ADMISSION_CRITERIA,
|
|
72
78
|
applyTopicBoundary,
|
|
@@ -114,8 +120,21 @@ import {
|
|
|
114
120
|
type XhsCard,
|
|
115
121
|
xhsPlan,
|
|
116
122
|
} from './kk-workflow-stages.ts';
|
|
123
|
+
import {
|
|
124
|
+
type AlignmentProposal,
|
|
125
|
+
commitAlignment,
|
|
126
|
+
dropReselectedJudgments,
|
|
127
|
+
type LockPort,
|
|
128
|
+
} from './news-editorial-ledger.ts';
|
|
117
129
|
import { splitSentences } from './sentences.ts';
|
|
118
130
|
import { normalizeSeriesNames } from './series-names.ts';
|
|
131
|
+
import { resolveSourceCitation } from './source-citation.ts';
|
|
132
|
+
import {
|
|
133
|
+
readSelectionAttempts,
|
|
134
|
+
recordSelectionAttempt,
|
|
135
|
+
recordSelectionStage,
|
|
136
|
+
selectionAttemptsPath,
|
|
137
|
+
} from './topic-selection-attempts.ts';
|
|
119
138
|
|
|
120
139
|
export function dailyQcContent(args: string[]): void {
|
|
121
140
|
const [
|
|
@@ -242,6 +261,40 @@ export function dailyQcContent(args: string[]): void {
|
|
|
242
261
|
sted('write', candidates, () => writeJsonText(candidates, dedupedContent));
|
|
243
262
|
console.error(`qc: dropped ${dropped.length} near-duplicate candidate(s): ${dropped.join(', ')}`);
|
|
244
263
|
}
|
|
264
|
+
// Task 0392 R2: the raw pool entering QC, captured OUTSIDE the timed block so a cached rerun
|
|
265
|
+
// still records it (`10-collect/pool.json` is a different artifact — this is the plan snapshot
|
|
266
|
+
// the QC filter actually reads). The QC drops are named by ID difference, so the stage's own
|
|
267
|
+
// arithmetic holds instead of being inferred.
|
|
268
|
+
const poolDocs = metadataOf(readJson(planContent)).docs;
|
|
269
|
+
const poolIds = (Array.isArray(poolDocs) ? poolDocs : []).map((doc) => String((doc as { id?: unknown }).id ?? ''));
|
|
270
|
+
const boundaryIds = new Set(boundaryDocs.map((doc) => String((doc as { id?: unknown }).id ?? '')));
|
|
271
|
+
const qcDropped = poolIds.filter((id) => !boundaryIds.has(id));
|
|
272
|
+
// Task 0392 R2: one record per stage that ran, so each stage is provable on its own
|
|
273
|
+
// (`input === kept + dropped`) instead of being inferred from one cross-stage sum.
|
|
274
|
+
const selectionPath = selectionAttemptsPath(workDir);
|
|
275
|
+
sted('write', selectionPath, () => {
|
|
276
|
+
const attemptOrdinal = (readSelectionAttempts(workDir)?.attempts.length ?? 0) + 1;
|
|
277
|
+
const keptDocs = dropped.length > 0 ? deduped : currentDocs;
|
|
278
|
+
recordSelectionAttempt(workDir, {
|
|
279
|
+
runDate,
|
|
280
|
+
attemptId: `${runDate}#${attemptOrdinal}`,
|
|
281
|
+
spec: readTopicBoundary(),
|
|
282
|
+
stages: [
|
|
283
|
+
{ stage: 'qc', input: poolIds.length, kept: boundaryDocs.length, dropped: qcDropped },
|
|
284
|
+
// The boundary's drops are rule-tagged, not just counted: the exclusions carry them.
|
|
285
|
+
{
|
|
286
|
+
stage: 'topicBoundary',
|
|
287
|
+
input: boundaryDocs.length,
|
|
288
|
+
kept: currentDocs.length,
|
|
289
|
+
dropped: excluded.map((entry) => entry.id),
|
|
290
|
+
},
|
|
291
|
+
{ stage: 'dedup', input: currentDocs.length, kept: keptDocs.length, dropped },
|
|
292
|
+
],
|
|
293
|
+
// Post-dedup survivors, so the recorded kept set is what later stages actually receive.
|
|
294
|
+
keptIds: keptDocs.map((doc) => String((doc as { id?: unknown }).id ?? '')),
|
|
295
|
+
excluded,
|
|
296
|
+
});
|
|
297
|
+
});
|
|
245
298
|
// Last, not inside the timed block above: the estimate must see the pool every shrink pass has
|
|
246
299
|
// already produced. 2026-10-22 cleared the floor on a 4-item pool (21.0 min estimated) that the
|
|
247
300
|
// topic boundary then cut to 3 (14.4 min), so the run paid for a full synthesis the measured
|
|
@@ -540,10 +593,20 @@ function applyFloorGate(
|
|
|
540
593
|
} = estimateSpokenMinutes(docs, vdriver, keptRatio.ratio);
|
|
541
594
|
if (estimatedSeconds >= floor * 60) {
|
|
542
595
|
if (clearStaleRefusal && isFile(refusal)) unlinkSync(refusal);
|
|
596
|
+
// Task 0392 R2: the floor gate observed this pool and admitted it — a stage that ran and
|
|
597
|
+
// dropped nothing is evidence, not silence.
|
|
598
|
+
recordSelectionStage(workDir, runDate, {
|
|
599
|
+
stages: [{ stage: 'floor', input: docs.length, kept: docs.length, dropped: [] }],
|
|
600
|
+
});
|
|
543
601
|
console.log(`floor gate: estimated ${estimatedMinutes} min from ${chars} chars — above the ${floor} min floor`);
|
|
544
602
|
return;
|
|
545
603
|
}
|
|
546
604
|
const ids = docs.map((doc) => String((doc as Record<string, unknown> | null)?.id ?? ''));
|
|
605
|
+
// A refusal drops the whole pool: recording it as `kept 0` keeps the stage identity true and
|
|
606
|
+
// tells the report the day ended here rather than leaving the stage unknown.
|
|
607
|
+
recordSelectionStage(workDir, runDate, {
|
|
608
|
+
stages: [{ stage: 'floor', input: docs.length, kept: 0, dropped: ids }],
|
|
609
|
+
});
|
|
547
610
|
sted('write', refusal, () =>
|
|
548
611
|
writeJqText(refusal, {
|
|
549
612
|
estimatedMinutes,
|
|
@@ -604,9 +667,22 @@ function formatWindowMs(ms: number): string {
|
|
|
604
667
|
* and dedup), so it is an upper bound: the ladder can stop one step early, never one late.
|
|
605
668
|
*/
|
|
606
669
|
export function dailyExtract(args: string[]): void {
|
|
607
|
-
const [workDir = '', topic = '', window = '', minMinutes = '', vdriver = ''] = args;
|
|
670
|
+
const [workDir = '', topic = '', window = '', minMinutes = '', vdriver = '', limitArg = ''] = args;
|
|
608
671
|
if (!workDir) fail('missing work_dir');
|
|
609
672
|
if (!topic) fail('missing topic');
|
|
673
|
+
// 2026-11-20: `kk store extract --limit` defaults to the profile's cap (else 20), and this stage
|
|
674
|
+
// passed no `--limit` at all — so the plan cap (`plan_max_items`, 40) never reached the store and
|
|
675
|
+
// the pool was pre-trimmed to the default before the quota existed. Measured on the production
|
|
676
|
+
// store: 56 category-allowed, importance>=3, unpublished items sat in the 168h window, the
|
|
677
|
+
// extract returned 24, QC admitted 13, the writer kept 3 and the day refused at the TTS gate;
|
|
678
|
+
// at `--limit 40` the same window yields 30 items and 23 survive QC. The extract bound must be
|
|
679
|
+
// at least the plan bound or the plan can never fill.
|
|
680
|
+
const extractedLimit = Number(limitArg);
|
|
681
|
+
const limit =
|
|
682
|
+
limitArg !== '' && Number.isInteger(extractedLimit) && extractedLimit > 0
|
|
683
|
+
? ['--limit', String(extractedLimit)]
|
|
684
|
+
: [];
|
|
685
|
+
if (limitArg !== '' && limit.length === 0) fail(`extract: invalid limit: ${limitArg}`);
|
|
610
686
|
const poolPath = join(workDir, '10-collect', 'pool.json');
|
|
611
687
|
const base = parseWindowMs(window === '' ? '24h' : window);
|
|
612
688
|
if (base === null) fail(`extract: invalid window: ${window || '(empty)'}`);
|
|
@@ -643,7 +719,7 @@ export function dailyExtract(args: string[]): void {
|
|
|
643
719
|
for (const ms of windows) {
|
|
644
720
|
const label = formatWindowMs(ms);
|
|
645
721
|
const attempt = join(workDir, '10-collect', `.pool-${label}.json`);
|
|
646
|
-
kk(['store', 'extract', '--topic', topic, '--window', label, '--out', attempt]);
|
|
722
|
+
kk(['store', 'extract', '--topic', topic, '--window', label, '--out', attempt, ...limit]);
|
|
647
723
|
const parsed = readJson(attempt);
|
|
648
724
|
const docs = Array.isArray(parsed) ? (parsed as unknown[]) : [];
|
|
649
725
|
const estimate = estimateSpokenMinutes(docs, vdriver, ratio.ratio);
|
|
@@ -675,6 +751,64 @@ export function dailyExtract(args: string[]): void {
|
|
|
675
751
|
});
|
|
676
752
|
}
|
|
677
753
|
|
|
754
|
+
/**
|
|
755
|
+
* 0385 R4: the one frozen episode identity a bundle ships, read from the Content provenance first
|
|
756
|
+
* (a retry or a replay republishes what the episode already carried) and from the slot
|
|
757
|
+
* `daily-editorial-render` freezes second. `null` means "no identity recorded" — the caller leaves
|
|
758
|
+
* whatever title the artifact already has.
|
|
759
|
+
*/
|
|
760
|
+
function episodeIdentityFor(workDir: string, runDate: string, content: unknown): EpisodeIdentity | null {
|
|
761
|
+
return (
|
|
762
|
+
identityFromMetadata(metadataOf(content)) ??
|
|
763
|
+
identityFromMetadata({
|
|
764
|
+
[EPISODE_IDENTITY_KEY]: readJson(join(workDir, '21-plan', `${runDate}_05_script_identity.json`)),
|
|
765
|
+
})
|
|
766
|
+
);
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
/**
|
|
770
|
+
* 0385 R4: stamp the frozen title into one article Content — `title`, the H1 of the body, and the
|
|
771
|
+
* `metadata.episodeIdentity` record every later target reads. A withheld identity (`title: null`)
|
|
772
|
+
* leaves the Content untouched: there is no title to share, and inventing one is the bug.
|
|
773
|
+
*
|
|
774
|
+
* Both articles seams call this — `daily-article` after it derives (first run) and
|
|
775
|
+
* `daily-editorial-render` after the body is rewritten (retry) — so the stamp cannot be a no-op on
|
|
776
|
+
* one order and be wiped on the other.
|
|
777
|
+
*/
|
|
778
|
+
function stampEpisodeIdentity(articleContentPath: string, identity: EpisodeIdentity): boolean {
|
|
779
|
+
if (identity.title === null) return false;
|
|
780
|
+
const articleContent = readJson(articleContentPath);
|
|
781
|
+
if (articleContent === null) return false;
|
|
782
|
+
const priorBody = typeof articleContent.body === 'string' ? articleContent.body : '';
|
|
783
|
+
const body = priorBody.replace(/^#(?!#)[^\n]*/u, `# ${identity.title}`);
|
|
784
|
+
sted('write', articleContentPath, () =>
|
|
785
|
+
writeJsonText(articleContentPath, {
|
|
786
|
+
...articleContent,
|
|
787
|
+
title: identity.title,
|
|
788
|
+
body,
|
|
789
|
+
metadata: { ...metadataOf(articleContent), [EPISODE_IDENTITY_KEY]: identity },
|
|
790
|
+
}),
|
|
791
|
+
);
|
|
792
|
+
return true;
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
/**
|
|
796
|
+
* 0385 R4: the article seam's one entry point — read the bundle's frozen identity for this run and
|
|
797
|
+
* stamp it into the article Content. `daily-article` calls it right after it derives the Content
|
|
798
|
+
* (first run) and after a `proseStale` re-derivation (retry), which is the only thing that keeps the
|
|
799
|
+
* stamp `daily-editorial-render` wrote from being wiped. Returns the identity it applied (or null).
|
|
800
|
+
*/
|
|
801
|
+
export function applyEpisodeIdentityToArticle(
|
|
802
|
+
workDir: string,
|
|
803
|
+
runDate: string,
|
|
804
|
+
articleContentPath: string,
|
|
805
|
+
): EpisodeIdentity | null {
|
|
806
|
+
const identity = episodeIdentityFor(workDir, runDate, readJson(articleContentPath));
|
|
807
|
+
if (identity === null) return null;
|
|
808
|
+
stampEpisodeIdentity(articleContentPath, identity);
|
|
809
|
+
return identity;
|
|
810
|
+
}
|
|
811
|
+
|
|
678
812
|
export function dailyArticle(args: string[]): void {
|
|
679
813
|
const [workDir = '', runDate = '', pluginsPath = ''] = args;
|
|
680
814
|
const articleMd = join(workDir, '22-article', `${runDate}_06_article_article.md`);
|
|
@@ -771,6 +905,11 @@ export function dailyArticle(args: string[]): void {
|
|
|
771
905
|
},
|
|
772
906
|
},
|
|
773
907
|
);
|
|
908
|
+
// 0385 R4: `generate-render` order is script → editorial-render → article → cover, so this
|
|
909
|
+
// is the FIRST seam where the Content exists; `daily-editorial-render`'s own stamp would be a
|
|
910
|
+
// no-op here. Stamping now — and re-stamping here after a `proseStale` re-derivation — is what
|
|
911
|
+
// keeps the article (surfdash) and the show notes on the same frozen title as podcast/ID3.
|
|
912
|
+
applyEpisodeIdentityToArticle(workDir, runDate, articleContent);
|
|
774
913
|
const body = readJson(articleContent)?.body;
|
|
775
914
|
if (typeof body !== 'string') failWith(1, `article: ${articleContent} has no string body`);
|
|
776
915
|
sted('write', articleMd, () => writeRaw(articleMd, body));
|
|
@@ -1240,6 +1379,8 @@ export function dailyGenerate(args: string[]): void {
|
|
|
1240
1379
|
voicebox: 'voice-gen',
|
|
1241
1380
|
gemini: 'gemini-tts',
|
|
1242
1381
|
voxcpm: 'voxcpm-tts',
|
|
1382
|
+
'vibe-voice': 'vibe-voice-tts',
|
|
1383
|
+
vibevoice: 'vibe-voice-tts',
|
|
1243
1384
|
};
|
|
1244
1385
|
let voiceGenerator = VOICE_DRIVERS[vdriver];
|
|
1245
1386
|
if (!voiceGenerator) {
|
|
@@ -1561,13 +1702,18 @@ export function dailyGenerate(args: string[]): void {
|
|
|
1561
1702
|
plans = computePlans(voiceGenerator);
|
|
1562
1703
|
}
|
|
1563
1704
|
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1705
|
+
const stampSidecarHash = (plan: (typeof plans)[number]): void => {
|
|
1706
|
+
try {
|
|
1707
|
+
const sidecar = readJson(plan.jsonPath) as Record<string, unknown>;
|
|
1708
|
+
sidecar.hash = plan.hash;
|
|
1709
|
+
if (sidecar.metadata && typeof sidecar.metadata === 'object') {
|
|
1710
|
+
(sidecar.metadata as Record<string, unknown>).hash = plan.hash;
|
|
1711
|
+
}
|
|
1712
|
+
writeJsonText(plan.jsonPath, sidecar);
|
|
1713
|
+
} catch {}
|
|
1714
|
+
};
|
|
1715
|
+
|
|
1716
|
+
const buildSectionDocIn = (plan: (typeof plans)[number]): string => {
|
|
1571
1717
|
const secScript = { ...script, segments: plan.def.segments };
|
|
1572
1718
|
const secDocIn = join(secDir, `.${plan.def.stem}_in.json`);
|
|
1573
1719
|
const doc = {
|
|
@@ -1579,40 +1725,111 @@ export function dailyGenerate(args: string[]): void {
|
|
|
1579
1725
|
metadata: { voiceProfile },
|
|
1580
1726
|
};
|
|
1581
1727
|
writeJsonText(secDocIn, [doc]);
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1728
|
+
return secDocIn;
|
|
1729
|
+
};
|
|
1730
|
+
|
|
1731
|
+
const BATCH_MANIFEST_CONFIG: Record<string, { envKey: string; filename: string; label: string }> = {
|
|
1732
|
+
'voxcpm-tts': { envKey: 'VOXCPM_BATCH_MANIFEST', filename: '.voxcpm_batch.json', label: 'voxcpm' },
|
|
1733
|
+
'vibe-voice-tts': {
|
|
1734
|
+
envKey: 'VIBEVOICE_BATCH_MANIFEST',
|
|
1735
|
+
filename: '.vibe-voice_batch.json',
|
|
1736
|
+
label: 'vibe-voice',
|
|
1737
|
+
},
|
|
1738
|
+
};
|
|
1739
|
+
const batchConfig = BATCH_MANIFEST_CONFIG[voiceGenerator];
|
|
1740
|
+
if (batchConfig && anySynthesisNeeded) {
|
|
1741
|
+
const pendingPlans = plans.filter((p) => p.needsSynthesis);
|
|
1742
|
+
for (const plan of plans) {
|
|
1743
|
+
if (!plan.needsSynthesis) {
|
|
1744
|
+
console.log(`generate: section cached: ${plan.def.stem}`);
|
|
1745
|
+
}
|
|
1746
|
+
}
|
|
1747
|
+
const secInputs = pendingPlans.map((p) => ({ plan: p, inPath: buildSectionDocIn(p) }));
|
|
1748
|
+
const batchManifestPath = join(secDir, batchConfig.filename);
|
|
1749
|
+
const runBatch = (items: typeof secInputs): number => {
|
|
1750
|
+
writeJsonText(
|
|
1751
|
+
batchManifestPath,
|
|
1752
|
+
items.map((item) => ({ in: item.inPath, out: item.plan.jsonPath })),
|
|
1753
|
+
);
|
|
1754
|
+
return kk(voiceExecutorArgs(voiceGenerator, items[0].inPath, items[0].plan.jsonPath, pluginsPath), {
|
|
1755
|
+
env: { VOICE_GEN_MP3: transcodeMp3, [batchConfig.envKey]: batchManifestPath },
|
|
1591
1756
|
soft: true,
|
|
1592
1757
|
});
|
|
1758
|
+
};
|
|
1759
|
+
try {
|
|
1760
|
+
console.log(
|
|
1761
|
+
`generate: synthesizing ${secInputs.length} ${batchConfig.label} section(s) in single-worker batch: ${secInputs.map((i) => i.plan.def.stem).join(', ')}`,
|
|
1762
|
+
);
|
|
1763
|
+
let status = runBatch(secInputs);
|
|
1764
|
+
for (const item of secInputs) {
|
|
1765
|
+
if (existsSync(item.plan.jsonPath) && validNativeAudio(item.plan.wavPath)) {
|
|
1766
|
+
stampSidecarHash(item.plan);
|
|
1767
|
+
}
|
|
1768
|
+
}
|
|
1593
1769
|
if (status !== 0) {
|
|
1594
|
-
|
|
1595
|
-
|
|
1770
|
+
const remaining = secInputs.filter(
|
|
1771
|
+
(item) => !existsSync(item.plan.jsonPath) || !validNativeAudio(item.plan.wavPath),
|
|
1596
1772
|
);
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1773
|
+
if (remaining.length > 0) {
|
|
1774
|
+
console.log(
|
|
1775
|
+
`generate: ${batchConfig.label} batch failed (exit ${status}) — retrying ${remaining.length} remaining section(s) once`,
|
|
1776
|
+
);
|
|
1777
|
+
status = runBatch(remaining);
|
|
1778
|
+
for (const item of remaining) {
|
|
1779
|
+
if (existsSync(item.plan.jsonPath) && validNativeAudio(item.plan.wavPath)) {
|
|
1780
|
+
stampSidecarHash(item.plan);
|
|
1781
|
+
}
|
|
1782
|
+
}
|
|
1783
|
+
} else {
|
|
1784
|
+
status = 0;
|
|
1785
|
+
}
|
|
1601
1786
|
}
|
|
1602
1787
|
if (status !== 0) {
|
|
1603
|
-
failWith(status, `generate: section synthesis failed
|
|
1788
|
+
failWith(status, `generate: ${batchConfig.label} batch section synthesis failed`);
|
|
1604
1789
|
}
|
|
1605
1790
|
} finally {
|
|
1606
|
-
rmSync(
|
|
1791
|
+
rmSync(batchManifestPath, { force: true });
|
|
1792
|
+
for (const item of secInputs) {
|
|
1793
|
+
rmSync(item.inPath, { force: true });
|
|
1794
|
+
}
|
|
1607
1795
|
}
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
if (
|
|
1612
|
-
(
|
|
1796
|
+
} else {
|
|
1797
|
+
// Synthesize sections sequentially (concurrency 1)
|
|
1798
|
+
for (const plan of plans) {
|
|
1799
|
+
if (!plan.needsSynthesis) {
|
|
1800
|
+
console.log(`generate: section cached: ${plan.def.stem}`);
|
|
1801
|
+
continue;
|
|
1613
1802
|
}
|
|
1614
|
-
|
|
1615
|
-
|
|
1803
|
+
console.log(`generate: synthesizing section: ${plan.def.stem}`);
|
|
1804
|
+
const secDocIn = buildSectionDocIn(plan);
|
|
1805
|
+
try {
|
|
1806
|
+
// 0269-shaped hardening (20261012): one retry for a failed section. The design already
|
|
1807
|
+
// bounds the episode's risk with the pre-flight quota probe and the per-section cache,
|
|
1808
|
+
// but a failure that arrives MID-render (a 429 once the window drains, a network blip)
|
|
1809
|
+
// still cost the whole episode — the one step nothing can publish without. The retry is
|
|
1810
|
+
// cheap and bounded: the successful sections are cache hits, so at most one extra
|
|
1811
|
+
// request per failed section is issued, and a persistent failure still fails loud.
|
|
1812
|
+
let status = kk(voiceExecutorArgs(voiceGenerator, secDocIn, plan.jsonPath, pluginsPath), {
|
|
1813
|
+
env: { VOICE_GEN_MP3: transcodeMp3 },
|
|
1814
|
+
soft: true,
|
|
1815
|
+
});
|
|
1816
|
+
if (status !== 0) {
|
|
1817
|
+
console.log(
|
|
1818
|
+
`generate: section ${plan.def.stem} synthesis failed (exit ${status}) — retrying it once`,
|
|
1819
|
+
);
|
|
1820
|
+
status = kk(voiceExecutorArgs(voiceGenerator, secDocIn, plan.jsonPath, pluginsPath), {
|
|
1821
|
+
env: { VOICE_GEN_MP3: transcodeMp3 },
|
|
1822
|
+
soft: true,
|
|
1823
|
+
});
|
|
1824
|
+
}
|
|
1825
|
+
if (status !== 0) {
|
|
1826
|
+
failWith(status, `generate: section synthesis failed for ${plan.def.stem}`);
|
|
1827
|
+
}
|
|
1828
|
+
} finally {
|
|
1829
|
+
rmSync(secDocIn, { force: true });
|
|
1830
|
+
}
|
|
1831
|
+
stampSidecarHash(plan);
|
|
1832
|
+
}
|
|
1616
1833
|
}
|
|
1617
1834
|
|
|
1618
1835
|
// Join sections with ffmpeg
|
|
@@ -1706,6 +1923,62 @@ export function dailyGenerate(args: string[]): void {
|
|
|
1706
1923
|
});
|
|
1707
1924
|
}
|
|
1708
1925
|
|
|
1926
|
+
/**
|
|
1927
|
+
* Delete a published episode's lossless audio intermediates: every section render (the synthesis
|
|
1928
|
+
* cache `dailyGenerate` reads), the joined final, and the `<stem>.intro.wav` merge output.
|
|
1929
|
+
*
|
|
1930
|
+
* Measured 2026-11-20: 987 MB of WAV across six daily runs — 80% of `.works/kk-news-generate` — for
|
|
1931
|
+
* 13–20 MB of MP3 per day. Nothing outside the run reads them: the podcast enclosure, `publish-prep`
|
|
1932
|
+
* and every retry window read the MP3, and `daily-intro` merged its copy inside the run.
|
|
1933
|
+
*
|
|
1934
|
+
* Guarded on the delivered artifact, never on a run status: a missing MP3 means the transcode
|
|
1935
|
+
* failed, and pruning then would turn the rebuild into a paid re-synthesis. Re-entering
|
|
1936
|
+
* `daily-generate` after a prune re-synthesizes the sections — the intended trade, since a
|
|
1937
|
+
* published day is not regenerated.
|
|
1938
|
+
*/
|
|
1939
|
+
export function dailyAudioPrune(args: string[]): void {
|
|
1940
|
+
const [workDir = ''] = args;
|
|
1941
|
+
if (!workDir) fail('missing work_dir');
|
|
1942
|
+
const audioDir = join(workDir, '30-audio');
|
|
1943
|
+
if (!existsSync(audioDir)) {
|
|
1944
|
+
console.log(`audio-prune: no ${audioDir} — nothing to prune`);
|
|
1945
|
+
return;
|
|
1946
|
+
}
|
|
1947
|
+
const contentName = readdirSync(audioDir)
|
|
1948
|
+
.filter((entry) => /^\d{8}_11_generate_content\.json$/.test(entry))
|
|
1949
|
+
.sort()
|
|
1950
|
+
.at(-1);
|
|
1951
|
+
if (contentName === undefined) {
|
|
1952
|
+
console.log('audio-prune: no episode content in 30-audio — nothing to prune');
|
|
1953
|
+
return;
|
|
1954
|
+
}
|
|
1955
|
+
const content = readJson(join(audioDir, contentName));
|
|
1956
|
+
const recorded = [metadataOf(content).mp3Path, content?.mp3Path].find(
|
|
1957
|
+
(candidate): candidate is string => typeof candidate === 'string' && candidate !== '',
|
|
1958
|
+
);
|
|
1959
|
+
if (recorded === undefined || !isFile(resolve(recorded))) {
|
|
1960
|
+
console.log('audio-prune: publish MP3 not on disk — keeping the WAV intermediates');
|
|
1961
|
+
return;
|
|
1962
|
+
}
|
|
1963
|
+
const wavs: string[] = [];
|
|
1964
|
+
const collect = (dir: string): void => {
|
|
1965
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
1966
|
+
const path = join(dir, entry.name);
|
|
1967
|
+
if (entry.isDirectory()) collect(path);
|
|
1968
|
+
else if (entry.name.endsWith('.wav')) wavs.push(path);
|
|
1969
|
+
}
|
|
1970
|
+
};
|
|
1971
|
+
collect(audioDir);
|
|
1972
|
+
let freed = 0;
|
|
1973
|
+
for (const wav of wavs) {
|
|
1974
|
+
freed += statSync(wav).size;
|
|
1975
|
+
sted('remove', wav, () => rmSync(wav, { force: true }));
|
|
1976
|
+
}
|
|
1977
|
+
console.log(
|
|
1978
|
+
`audio-prune: removed ${wavs.length} WAV intermediate${wavs.length === 1 ? '' : 's'} (${(freed / 1048576).toFixed(1)} MB), kept ${basename(resolve(recorded))}`,
|
|
1979
|
+
);
|
|
1980
|
+
}
|
|
1981
|
+
|
|
1709
1982
|
/**
|
|
1710
1983
|
* 20260917 review #7: prepend the show's 8s intro sting to the generated audio.
|
|
1711
1984
|
* `intro_music` empty -> skip. Writes `<stem>.intro.wav` (original render kept), points
|
|
@@ -1914,7 +2187,12 @@ const WECHAT_OUTRO = '\n\n欲听往期节目,可至小宇宙、Apple Podcast
|
|
|
1914
2187
|
/** The brand strings this daily show pins on every 公众号 draft. */
|
|
1915
2188
|
const WECHAT_BRAND = {
|
|
1916
2189
|
author: '冰原奔狼',
|
|
1917
|
-
|
|
2190
|
+
// WX-03 (verified 2026-11-11): 《标识办法》第十条 + 微信 2025-08-31 公告 make the AI-generation
|
|
2191
|
+
// declaration a publish-time metadata duty, and 创作来源 is that declaration entry. The stance
|
|
2192
|
+
// label (`个人观点,仅供参考`, the 2026-10-10 choice) declares nothing about AI generation, so the
|
|
2193
|
+
// variants safety gate blocked every daily run (2026-11-19). The article is AI-drafted and the
|
|
2194
|
+
// audio is AI-synthesized; declare it. The field is single-select — one label per draft.
|
|
2195
|
+
claimSource: '内容由AI生成',
|
|
1918
2196
|
coverSource: 'library',
|
|
1919
2197
|
} as const;
|
|
1920
2198
|
|
|
@@ -1943,12 +2221,20 @@ export function buildWechatArticleContent(
|
|
|
1943
2221
|
): Record<string, unknown> {
|
|
1944
2222
|
const wechatmp: Record<string, unknown> = {
|
|
1945
2223
|
original: true,
|
|
1946
|
-
// 赞赏 is
|
|
1947
|
-
//
|
|
2224
|
+
// 赞赏 is NOT requested: measured 2026-11-20 on a fresh 文章 draft, this account's row renders
|
|
2225
|
+
// `不开启 … 无法开启赞赏,因为还没有赞赏账户授权给本公众号` with a 0×0 box — the platform has not
|
|
2226
|
+
// authorized a 赞赏 account for 咸话咸说, so no selector, probe or retry can enable it, and asking
|
|
2227
|
+
// for it only converted a healthy draft into `ok:false` until `WECHATMP_ALLOW_PARTIAL_ENRICH=1`
|
|
2228
|
+
// was set by hand (11-16, 11-18, 11-19). Evidence:
|
|
2229
|
+
// `.spur/run/dogfood/2026-11-20-wechatmp-reward/survey-dom.json` (5806: reward row text + box).
|
|
2230
|
+
// If the operator opens 赞赏 later, flip this line back together with the probe in
|
|
2231
|
+
// `plugins/publishings/wechatmp-pub/src/enrich.ts` (`REWARD_STATE`).
|
|
2232
|
+
// 2026-11-20 operator request: 赞赏 ON. `WECHATMP_ALLOW_PARTIAL_ENRICH=1` is set, so a
|
|
2233
|
+
// still-unauthorized account warns once and keeps the healthy draft instead of failing it.
|
|
1948
2234
|
reward: true,
|
|
1949
2235
|
author: WECHAT_BRAND.author,
|
|
1950
2236
|
collection: options.collection,
|
|
1951
|
-
// 创作来源 is the
|
|
2237
|
+
// 创作来源 is the platform's AI-declaration entry (WX-03); the label declares AI generation.
|
|
1952
2238
|
claimSource: WECHAT_BRAND.claimSource,
|
|
1953
2239
|
// 封面 comes from 图片库: the episode cover is uploaded there as the audio material's cover.
|
|
1954
2240
|
coverSource: WECHAT_BRAND.coverSource,
|
|
@@ -2053,21 +2339,46 @@ export function buildPodcastContent(
|
|
|
2053
2339
|
* (surfdash-pub/src/index.ts), so the run's cover rides along exactly as the episode/wechat
|
|
2054
2340
|
* builders stamp it. voice2's prepare mode never exercised this gate; the frozen-bundle matrix
|
|
2055
2341
|
* send surfaced it on 2026-11-05 (empty run → 'digest post has no cover image').
|
|
2342
|
+
*
|
|
2343
|
+
* 0409: `metadata.surfdash.locales` carries the en/ja translations the localize step wrote, so the
|
|
2344
|
+
* frozen variant — and therefore the safety review and the freeze digest — covers them. They are
|
|
2345
|
+
* read from the files at variant-build time so the variant is the single source the publisher reads.
|
|
2056
2346
|
*/
|
|
2057
2347
|
export function buildSurfdashContent(
|
|
2058
2348
|
article: Record<string, unknown>,
|
|
2059
2349
|
_links: PublishLinks,
|
|
2060
|
-
options: { coverPath?: string } = {},
|
|
2350
|
+
options: { coverPath?: string; locales?: Partial<Record<'en' | 'ja', { title: string; body: string }>> } = {},
|
|
2061
2351
|
): Record<string, unknown> {
|
|
2062
2352
|
return {
|
|
2063
2353
|
...article,
|
|
2064
2354
|
metadata: {
|
|
2065
2355
|
...metadataOf(article),
|
|
2066
2356
|
...(options.coverPath === undefined ? {} : { coverImage: options.coverPath }),
|
|
2357
|
+
...(options.locales === undefined ? {} : { surfdash: { locales: options.locales } }),
|
|
2067
2358
|
},
|
|
2068
2359
|
};
|
|
2069
2360
|
}
|
|
2070
2361
|
|
|
2362
|
+
/**
|
|
2363
|
+
* Reads `${workDir}/22-article/locales/{en,ja}.md` (first line `# <title>`, rest the body) into the
|
|
2364
|
+
* payload shape `surfdash-pub` consumes. A locale whose file is missing or untitled is simply
|
|
2365
|
+
* absent — `news-localize-validate` is the gate that refuses it, and the publisher refuses a digest
|
|
2366
|
+
* payload that lacks one, so silent partial data never reaches a live publish.
|
|
2367
|
+
*/
|
|
2368
|
+
function readArticleLocales(workDir: string): Partial<Record<'en' | 'ja', { title: string; body: string }>> {
|
|
2369
|
+
const locales: Partial<Record<'en' | 'ja', { title: string; body: string }>> = {};
|
|
2370
|
+
for (const locale of ['en', 'ja'] as const) {
|
|
2371
|
+
const file = join(workDir, '22-article', 'locales', `${locale}.md`);
|
|
2372
|
+
if (!isFile(file)) continue;
|
|
2373
|
+
const [firstLine = '', ...rest] = readFileSync(file, 'utf-8').split('\n');
|
|
2374
|
+
const title = firstLine.startsWith('# ') ? firstLine.slice(2).trim() : '';
|
|
2375
|
+
const body = rest.join('\n').trim();
|
|
2376
|
+
if (title === '' || body === '') continue;
|
|
2377
|
+
locales[locale] = { title, body };
|
|
2378
|
+
}
|
|
2379
|
+
return locales;
|
|
2380
|
+
}
|
|
2381
|
+
|
|
2071
2382
|
/**
|
|
2072
2383
|
* One channel's short copy as a Content (task 0327 R3): the body is the authored post text and the
|
|
2073
2384
|
* episode cover rides along as `metadata.coverImage`.
|
|
@@ -2225,8 +2536,15 @@ export function dailyBundleVariants(args: string[]): void {
|
|
|
2225
2536
|
: '';
|
|
2226
2537
|
if (article === null) skipped.push('article (no 22-article content)');
|
|
2227
2538
|
else {
|
|
2228
|
-
|
|
2229
|
-
|
|
2539
|
+
// 0409: the frozen variant carries the en/ja translations, so the safety review and the
|
|
2540
|
+
// freeze digest cover them and the publisher writes what was reviewed.
|
|
2541
|
+
const articleLocales = readArticleLocales(workDir);
|
|
2542
|
+
const articleOptions = {
|
|
2543
|
+
coverPath: cover,
|
|
2544
|
+
...(Object.keys(articleLocales).length > 0 ? { locales: articleLocales } : {}),
|
|
2545
|
+
};
|
|
2546
|
+
write('article', buildSurfdashContent(article, links, articleOptions));
|
|
2547
|
+
write('article@surfdash-pub', buildSurfdashContent(article, links, articleOptions));
|
|
2230
2548
|
write('article@xhs-pub', buildXhsArticleContent(article, { publishStatus: 'draft' }));
|
|
2231
2549
|
// The article carries the episode audio at the top (operator request 2026-11-15): the
|
|
2232
2550
|
// 公众号 播客 row is off, so without this the MP draft had no player at all. Same source
|
|
@@ -2428,6 +2746,45 @@ function planItemsForPodcast(workDir: string, runDate: string): Array<{ title: s
|
|
|
2428
2746
|
return items;
|
|
2429
2747
|
}
|
|
2430
2748
|
|
|
2749
|
+
/**
|
|
2750
|
+
* 0396 R2 — the other channels' dispatch rows, shaped for podcast-pub's delivery classifier.
|
|
2751
|
+
*
|
|
2752
|
+
* Read from the 0388 ledger (the authority on what was dispatched for this frozen date). Capability
|
|
2753
|
+
* is deliberately NOT asserted: an unknown content surface must surface as `unsupported` with its
|
|
2754
|
+
* documented reason rather than a delivery nobody verified.
|
|
2755
|
+
*/
|
|
2756
|
+
export function correctionTargetRows(ledgerPath: string): Array<Record<string, unknown>> {
|
|
2757
|
+
const ledger = readJson(ledgerPath);
|
|
2758
|
+
const entries =
|
|
2759
|
+
ledger !== null && Array.isArray((ledger as { entries?: unknown }).entries)
|
|
2760
|
+
? ((ledger as { entries: unknown[] }).entries as Array<Record<string, unknown>>)
|
|
2761
|
+
: [];
|
|
2762
|
+
const rows: Array<Record<string, unknown>> = [];
|
|
2763
|
+
for (const entry of entries) {
|
|
2764
|
+
// The 0388 ledger keys a row by `id` (`plugin[@operation]`) with `plugin` beside it — NOT by a
|
|
2765
|
+
// `target` field. Reading a non-existent field silently produced zero rows and made this whole
|
|
2766
|
+
// seam inert (0396 review), so the id is the identity here and `plugin` is the fallback.
|
|
2767
|
+
// The self row is identified by PLUGIN, not by id: the writer keys an entry as
|
|
2768
|
+
// `plugin.operation` (`podcast-pub.episode`), so comparing the id let the podcast's own row
|
|
2769
|
+
// through and the operator saw a "not delivered to podcast-pub.episode" warning for the target
|
|
2770
|
+
// that actually received it (0396 review).
|
|
2771
|
+
const plugin = typeof entry?.plugin === 'string' ? entry.plugin.trim() : '';
|
|
2772
|
+
const id = typeof entry?.id === 'string' ? entry.id.trim() : '';
|
|
2773
|
+
const target = id !== '' ? id : plugin;
|
|
2774
|
+
if (plugin === 'podcast-pub' || target === '' || target === 'podcast-pub') continue;
|
|
2775
|
+
const blockedBy = Array.isArray(entry.blockedBy) ? entry.blockedBy.filter((id) => typeof id === 'string') : [];
|
|
2776
|
+
rows.push({
|
|
2777
|
+
target,
|
|
2778
|
+
...(typeof entry.state === 'string' ? { state: entry.state } : {}),
|
|
2779
|
+
...(typeof entry.mode === 'string' ? { mode: entry.mode } : {}),
|
|
2780
|
+
...(typeof entry.manualStep === 'string' ? { manualStep: entry.manualStep } : {}),
|
|
2781
|
+
...(typeof entry.lastError === 'string' ? { lastError: entry.lastError } : {}),
|
|
2782
|
+
...(blockedBy.length > 0 ? { blockedBy } : {}),
|
|
2783
|
+
});
|
|
2784
|
+
}
|
|
2785
|
+
return rows;
|
|
2786
|
+
}
|
|
2787
|
+
|
|
2431
2788
|
export function dailyPublishPodcast(args: string[]): void {
|
|
2432
2789
|
const [workDir = '', runDate = '', pluginsPath = ''] = args;
|
|
2433
2790
|
const prep = join(workDir, '31-publish', `${runDate}_13_publish-prep_content.json`);
|
|
@@ -2458,6 +2815,18 @@ export function dailyPublishPodcast(args: string[]): void {
|
|
|
2458
2815
|
showNotes,
|
|
2459
2816
|
...(Object.keys(podcast).length > 0 ? { podcast } : {}),
|
|
2460
2817
|
});
|
|
2818
|
+
// 0396 R2: the plugin records a delivery per TARGET, so the dispatch state of the other
|
|
2819
|
+
// channels has to reach it. The prep file's top-level `options` IS the channel the plugin
|
|
2820
|
+
// documents, and the 0388 ledger is the authority on those rows — no capability is
|
|
2821
|
+
// asserted here, so an unknown surface comes back as `unsupported` with its exact reason
|
|
2822
|
+
// instead of a claimed delivery.
|
|
2823
|
+
const siblingTargets = correctionTargetRows(join(workDir, '4-publish', 'dispatch-ledger.json'));
|
|
2824
|
+
if (siblingTargets.length > 0) {
|
|
2825
|
+
merged.options = {
|
|
2826
|
+
...((merged.options as Record<string, unknown>) ?? {}),
|
|
2827
|
+
correctionTargets: siblingTargets,
|
|
2828
|
+
};
|
|
2829
|
+
}
|
|
2461
2830
|
sted('write', prep, () => writeJsonText(prep, merged));
|
|
2462
2831
|
kk(
|
|
2463
2832
|
[
|
|
@@ -2474,6 +2843,22 @@ export function dailyPublishPodcast(args: string[]): void {
|
|
|
2474
2843
|
{
|
|
2475
2844
|
unset: ['SPUR_WORKFLOW_RUN_ACTIVE'],
|
|
2476
2845
|
soft: true,
|
|
2846
|
+
// 0396 R1: the publish dispatch is where a correction's delivery is REAL, so the
|
|
2847
|
+
// frozen snapshot rides with it too. Without this the per-target delivery record
|
|
2848
|
+
// could never be written by a production run (only the show-notes render saw the
|
|
2849
|
+
// snapshot). `kk executor fan-out` exposes no options channel, so the env is the
|
|
2850
|
+
// seam the plugin already documents.
|
|
2851
|
+
env: {
|
|
2852
|
+
...(isFile(join(workDir, '21-plan', `${runDate}_judgment-snapshot.json`))
|
|
2853
|
+
? {
|
|
2854
|
+
PODCAST_PUB_CORRECTIONS: join(
|
|
2855
|
+
workDir,
|
|
2856
|
+
'21-plan',
|
|
2857
|
+
`${runDate}_judgment-snapshot.json`,
|
|
2858
|
+
),
|
|
2859
|
+
}
|
|
2860
|
+
: {}),
|
|
2861
|
+
},
|
|
2477
2862
|
},
|
|
2478
2863
|
);
|
|
2479
2864
|
} catch (error) {
|
|
@@ -2494,6 +2879,24 @@ export function dailyPublishPrep(args: string[]): void {
|
|
|
2494
2879
|
const coverPath = join(workDir, '23-cover', `${runDate}_07_cover_cover.png`);
|
|
2495
2880
|
timed(workDir, 'publish-prep', () => {
|
|
2496
2881
|
const article = requireJson(articlePath, 'publish-prep');
|
|
2882
|
+
// 0385 R4: the last seam before anything is dispatched is also the seam that proves the whole
|
|
2883
|
+
// run shares ONE episode identity. It is read from the bundle's metadata first (a retry or a
|
|
2884
|
+
// historical replay republishes the identity the episode already shipped), then from the slot
|
|
2885
|
+
// `editorial-render` froze; a bundle that carries neither keeps the title it already has.
|
|
2886
|
+
const identity =
|
|
2887
|
+
identityFromMetadata(metadataOf(article)) ??
|
|
2888
|
+
identityFromMetadata({
|
|
2889
|
+
[EPISODE_IDENTITY_KEY]: readJson(join(workDir, '21-plan', `${runDate}_05_script_identity.json`)),
|
|
2890
|
+
});
|
|
2891
|
+
if (identity !== null && identity.status === 'support-removed') {
|
|
2892
|
+
// The withhold path of R4: never publish a headline admission no longer backs, and never
|
|
2893
|
+
// silently publish the legacy title in its place — a human has to regenerate the point.
|
|
2894
|
+
failWith(
|
|
2895
|
+
1,
|
|
2896
|
+
`publish-prep: episode title withheld — admission dropped the headline's supporting source(s) (${identity.supportingSourceIds.join(', ')}); regenerate the headline from an admitted story before publishing`,
|
|
2897
|
+
);
|
|
2898
|
+
}
|
|
2899
|
+
const episodeTitle = identity?.title ?? (typeof article.title === 'string' ? article.title : '');
|
|
2497
2900
|
const audioMeta = metadataOf(readJson(audioPath));
|
|
2498
2901
|
const rawFile = audioMeta.mp3Path ?? audioMeta.audioPath;
|
|
2499
2902
|
if (typeof rawFile !== 'string' || rawFile === '') {
|
|
@@ -2505,7 +2908,7 @@ export function dailyPublishPrep(args: string[]): void {
|
|
|
2505
2908
|
if (!audioFile.endsWith('.mp3')) {
|
|
2506
2909
|
failWith(1, `publish-prep: resolved audio is not an MP3 (transcode_mp3 must be "true"): ${audioFile}`);
|
|
2507
2910
|
}
|
|
2508
|
-
stampId3Tags(audioFile,
|
|
2911
|
+
stampId3Tags(audioFile, episodeTitle, runDate, artist, album);
|
|
2509
2912
|
const resolvedCover = resolve(coverPath);
|
|
2510
2913
|
const hasCover = existsSync(resolvedCover);
|
|
2511
2914
|
// Daily-show itunes convention: season = year, episode = day-of-year. run_date arrives
|
|
@@ -2523,10 +2926,18 @@ export function dailyPublishPrep(args: string[]): void {
|
|
|
2523
2926
|
// alone was silently dropped by the mapper — episodes published without a cover.
|
|
2524
2927
|
const merged = {
|
|
2525
2928
|
...article,
|
|
2929
|
+
// Every publish target (podcast, ID3, show notes, surfdash) reads this one title.
|
|
2930
|
+
title: episodeTitle,
|
|
2526
2931
|
metadata: {
|
|
2527
2932
|
...metadataOf(article),
|
|
2528
2933
|
audioFile,
|
|
2529
2934
|
runDate,
|
|
2935
|
+
...(identity !== null
|
|
2936
|
+
? {
|
|
2937
|
+
[EPISODE_IDENTITY_KEY]: identity,
|
|
2938
|
+
...(identity.coverHeadline !== null ? { coverHeadline: identity.coverHeadline } : {}),
|
|
2939
|
+
}
|
|
2940
|
+
: {}),
|
|
2530
2941
|
...(hasCover ? { coverImage: resolvedCover } : {}),
|
|
2531
2942
|
...(episode > 0 ? { itunes: { season, episode } } : {}),
|
|
2532
2943
|
},
|
|
@@ -3639,6 +4050,23 @@ export function dailySafetyGate(args: string[]): void {
|
|
|
3639
4050
|
unlinkSync(infraMarker);
|
|
3640
4051
|
}
|
|
3641
4052
|
sted('write', statusFile, () => writeRaw(statusFile, status));
|
|
4053
|
+
// Task 0392 R2: the channel-admission decisions this run actually reached, keyed by target
|
|
4054
|
+
// and scope. A channel outcome is not a candidate drop — it never touches the totals.
|
|
4055
|
+
// Unobserved (no platforms array) leaves the stage unknown instead of claiming zero blocks.
|
|
4056
|
+
if (platforms.length > 0) {
|
|
4057
|
+
recordSelectionStage(workDir, runDate, {
|
|
4058
|
+
channelAdmission: [
|
|
4059
|
+
{
|
|
4060
|
+
scope: scopeDir === '' ? 'drafts' : scopeDir,
|
|
4061
|
+
targets: platforms.map((platform) => ({
|
|
4062
|
+
target: String(platform?.platform ?? ''),
|
|
4063
|
+
decision: String(platform?.decision ?? ''),
|
|
4064
|
+
})),
|
|
4065
|
+
status,
|
|
4066
|
+
},
|
|
4067
|
+
],
|
|
4068
|
+
});
|
|
4069
|
+
}
|
|
3642
4070
|
console.log(`safety: status=${status} (${reason}); routing is transition-owned`);
|
|
3643
4071
|
});
|
|
3644
4072
|
}
|
|
@@ -3713,8 +4141,9 @@ export function dailyPreflight(args: string[]): void {
|
|
|
3713
4141
|
*
|
|
3714
4142
|
* The gate stays authoritative on `block`/`revise`; the decision can only refuse an outcome the gate
|
|
3715
4143
|
* already admitted. The decision replaced the judge's self-reported `confidence` field, which the
|
|
3716
|
-
* accept guard used to re-parse in shell:
|
|
3717
|
-
*
|
|
4144
|
+
* accept guard used to re-parse in shell: a JUDGED `escalate` now needs a human (the accept guard
|
|
4145
|
+
* refuses it for an unattended run), while an ABSTAINED row (`source: "default"` — the maker failed
|
|
4146
|
+
* and nothing was judged) is named on stderr and leaves the gate's own verdict in charge.
|
|
3718
4147
|
*
|
|
3719
4148
|
* Writes `24-script/<date>_09_safety-verdict.status` = `accept`, or `refuse` after naming the
|
|
3720
4149
|
* offending value on stderr. Never exits non-zero: routing belongs to the transitions.
|
|
@@ -3733,9 +4162,22 @@ export function dailySafetyVerdict(args: string[]): void {
|
|
|
3733
4162
|
// A missing/unreadable decision row is a refusal, never an approval: `onError: continue` on
|
|
3734
4163
|
// the decide action is what can leave it absent.
|
|
3735
4164
|
let verdict = '';
|
|
4165
|
+
// A maker that cannot answer does not silently vanish: it lands on the catalog fallback with
|
|
4166
|
+
// `source: "default"`, so name the abstention where the run report and triage can see it.
|
|
4167
|
+
// (2026-11-20: fm-local refuses safety-report text, so this is the caveat, not an edge case.)
|
|
4168
|
+
let abstention = '';
|
|
3736
4169
|
if (isFile(decisionFile)) {
|
|
3737
|
-
const row = JSON.parse(readFileSync(decisionFile, 'utf-8')) as {
|
|
4170
|
+
const row = JSON.parse(readFileSync(decisionFile, 'utf-8')) as {
|
|
4171
|
+
value?: unknown;
|
|
4172
|
+
source?: unknown;
|
|
4173
|
+
degraded?: unknown;
|
|
4174
|
+
backend?: unknown;
|
|
4175
|
+
reason?: unknown;
|
|
4176
|
+
};
|
|
3738
4177
|
verdict = String(row.value ?? '');
|
|
4178
|
+
if (row.source === 'default' || row.degraded === true) {
|
|
4179
|
+
abstention = `kk-daily-safety.judge.decision-abstained: kk-safety-verdict fell back to [${verdict}] (${String(row.backend ?? 'maker')}: ${String(row.reason ?? 'unknown')}) — nothing was judged, so the gate's [${status}] verdict stands alone`;
|
|
4180
|
+
}
|
|
3739
4181
|
}
|
|
3740
4182
|
let refusal = '';
|
|
3741
4183
|
if (!ADMITTED.has(status)) {
|
|
@@ -3784,6 +4226,7 @@ export function dailySafetyVerdict(args: string[]): void {
|
|
|
3784
4226
|
}
|
|
3785
4227
|
}
|
|
3786
4228
|
if (refusal !== '') console.error(refusal);
|
|
4229
|
+
else if (abstention !== '') console.error(abstention);
|
|
3787
4230
|
sted('write', token, () => writeRaw(token, refusal === '' ? 'accept' : 'refuse'));
|
|
3788
4231
|
if (evidence !== null) {
|
|
3789
4232
|
const evidencePath = join(scopeDirOf(workDir, scopeDir), 'safety.json');
|
|
@@ -3923,6 +4366,63 @@ export function dailySafetyManifest(args: string[]): void {
|
|
|
3923
4366
|
* skill's reference files, never here. 0331: an optional trailing scope_dir re-roots the whole
|
|
3924
4367
|
* artifact set for the variants review (see the scope machinery above).
|
|
3925
4368
|
*/
|
|
4369
|
+
function buildSafetyDigest(
|
|
4370
|
+
workDir: string,
|
|
4371
|
+
scopeDir: string,
|
|
4372
|
+
runDate: string,
|
|
4373
|
+
targets: string[],
|
|
4374
|
+
digest: string,
|
|
4375
|
+
content: unknown[],
|
|
4376
|
+
): string {
|
|
4377
|
+
const drafts = isDraftsScope(scopeDir);
|
|
4378
|
+
const lines: string[] = [
|
|
4379
|
+
`# Safety Review Digest (${runDate})`,
|
|
4380
|
+
'',
|
|
4381
|
+
`- Scope: ${drafts ? 'drafts' : 'variants'}`,
|
|
4382
|
+
`- Platforms: ${targets.join(', ')}`,
|
|
4383
|
+
`- Digest: \`${digest}\``,
|
|
4384
|
+
'',
|
|
4385
|
+
];
|
|
4386
|
+
const maxCharsPerItem = 4000;
|
|
4387
|
+
for (const entry of content) {
|
|
4388
|
+
if (typeof entry === 'string') {
|
|
4389
|
+
if (!isFile(entry)) continue;
|
|
4390
|
+
const raw = readFileSync(entry, 'utf-8');
|
|
4391
|
+
let body = raw;
|
|
4392
|
+
if (entry.endsWith('.yaml') || entry.endsWith('.yml')) {
|
|
4393
|
+
try {
|
|
4394
|
+
const parsed = Bun.YAML.parse(raw) as {
|
|
4395
|
+
title?: string;
|
|
4396
|
+
segments?: Array<{ text?: string; speaker?: string }>;
|
|
4397
|
+
};
|
|
4398
|
+
const segs = Array.isArray(parsed?.segments)
|
|
4399
|
+
? parsed.segments.map((s, idx) => `${idx + 1}. ${s.text ?? ''}`).join('\n')
|
|
4400
|
+
: raw;
|
|
4401
|
+
body = `${parsed?.title ? `Title: ${parsed.title}\n\n` : ''}${segs}`;
|
|
4402
|
+
} catch {}
|
|
4403
|
+
}
|
|
4404
|
+
const truncated = body.length > maxCharsPerItem ? `${body.slice(0, maxCharsPerItem)}\n…[truncated]` : body;
|
|
4405
|
+
lines.push(`## ${entry} (${raw.length} chars)`, '', truncated, '');
|
|
4406
|
+
} else if (entry && typeof entry === 'object') {
|
|
4407
|
+
const item = entry as { key?: string; path?: string };
|
|
4408
|
+
const rel = item.path ?? '';
|
|
4409
|
+
const abs = rel ? join(workDir, rel) : '';
|
|
4410
|
+
if (!abs || !isFile(abs)) continue;
|
|
4411
|
+
const raw = readFileSync(abs, 'utf-8');
|
|
4412
|
+
let summary = raw;
|
|
4413
|
+
try {
|
|
4414
|
+
const parsed = JSON.parse(raw) as { title?: string; body?: string; format?: string };
|
|
4415
|
+
const text = typeof parsed.body === 'string' ? parsed.body : raw;
|
|
4416
|
+
summary = `Title: ${parsed.title ?? ''}\nFormat: ${parsed.format ?? ''}\n\n${text}`;
|
|
4417
|
+
} catch {}
|
|
4418
|
+
const truncated =
|
|
4419
|
+
summary.length > maxCharsPerItem ? `${summary.slice(0, maxCharsPerItem)}\n…[truncated]` : summary;
|
|
4420
|
+
lines.push(`## ${item.key ?? rel} (${rel}, ${raw.length} chars)`, '', truncated, '');
|
|
4421
|
+
}
|
|
4422
|
+
}
|
|
4423
|
+
return lines.join('\n');
|
|
4424
|
+
}
|
|
4425
|
+
|
|
3926
4426
|
export function dailySafetyPrep(args: string[]): void {
|
|
3927
4427
|
const [workDir = '', runDate = '', platforms = '', scopeDir = ''] = args;
|
|
3928
4428
|
const drafts = isDraftsScope(scopeDir);
|
|
@@ -3951,6 +4451,7 @@ export function dailySafetyPrep(args: string[]): void {
|
|
|
3951
4451
|
}
|
|
3952
4452
|
for (const name of [
|
|
3953
4453
|
'safety-review_report.json',
|
|
4454
|
+
'safety-review_digest.md',
|
|
3954
4455
|
'safety-judge_verdict.json',
|
|
3955
4456
|
'safety-judge_status.txt',
|
|
3956
4457
|
'safety-judge_stamp.json',
|
|
@@ -3968,17 +4469,23 @@ export function dailySafetyPrep(args: string[]): void {
|
|
|
3968
4469
|
if (isFile(stale)) unlinkSync(stale);
|
|
3969
4470
|
}
|
|
3970
4471
|
const request = scopeArtifact(workDir, scopeDir, runDate, 'safety-review_request.json');
|
|
4472
|
+
const digestFile = scopeArtifact(workDir, scopeDir, runDate, 'safety-review_digest.md');
|
|
3971
4473
|
const targets = platforms
|
|
3972
4474
|
.split(',')
|
|
3973
4475
|
.map((platform) => platform.trim())
|
|
3974
4476
|
.filter(Boolean);
|
|
4477
|
+
const content = scopeContent(workDir, scopeDir, runDate);
|
|
4478
|
+
sted('write', digestFile, () =>
|
|
4479
|
+
writeRaw(digestFile, buildSafetyDigest(workDir, scopeDir, runDate, targets, digest, content)),
|
|
4480
|
+
);
|
|
3975
4481
|
sted('write', request, () =>
|
|
3976
4482
|
writeJsonText(request, {
|
|
3977
4483
|
digest,
|
|
4484
|
+
digestFile,
|
|
3978
4485
|
platforms: targets,
|
|
3979
4486
|
mode: 'detect-only',
|
|
3980
4487
|
scope: drafts ? 'drafts' : 'variants',
|
|
3981
|
-
content
|
|
4488
|
+
content,
|
|
3982
4489
|
}),
|
|
3983
4490
|
);
|
|
3984
4491
|
});
|
|
@@ -4192,7 +4699,7 @@ function spokenCharRate(vdriver: string): number {
|
|
|
4192
4699
|
// voxcpm measured the same day on a 12-section zh+en episode: 6,772 chars / 1,297.7 s speech
|
|
4193
4700
|
// (5.19 字/秒). The provisional 5.6 borrowed from voicebox let the fit budget reach 7,683 chars
|
|
4194
4701
|
// — 24.6 min of audio, 18 s inside the 25-min gate. 5.2 puts a full-budget script at ~22.9 min.
|
|
4195
|
-
if (vdriver === 'voxcpm') return 5.2;
|
|
4702
|
+
if (vdriver === 'voxcpm' || vdriver === 'vibe-voice' || vdriver === 'vibevoice') return 5.2;
|
|
4196
4703
|
return 5.6;
|
|
4197
4704
|
}
|
|
4198
4705
|
|
|
@@ -4377,6 +4884,11 @@ export function dailyScriptStyle(args: string[]): void {
|
|
|
4377
4884
|
* `24-script/<date>_08_script-write_errors.json` ([{itemId, rule}]) when the plan is absent or
|
|
4378
4885
|
* rejected, and removes it when the plan is accepted. The trial build goes to a scratch path so the
|
|
4379
4886
|
* `script` stage's isFile cache is never primed by a check.
|
|
4887
|
+
*
|
|
4888
|
+
* 0385 AC R2/R3: an ACCEPTED plan can still carry advisory editorial findings
|
|
4889
|
+
* (`metadata.scriptPlanAdvisories` from the generator's `analyzeEditorialClaims`). Those are written
|
|
4890
|
+
* to `24-script/<date>_08_script-write_advisories.json` and logged — a separate file, because the
|
|
4891
|
+
* acceptance verdict they describe is not a rejection and must not trigger the fix pass.
|
|
4380
4892
|
*/
|
|
4381
4893
|
export function dailyScriptCheck(args: string[]): void {
|
|
4382
4894
|
const [workDir = '', runDate = '', pluginsPath = ''] = args;
|
|
@@ -4409,7 +4921,19 @@ export function dailyScriptCheck(args: string[]): void {
|
|
|
4409
4921
|
}
|
|
4410
4922
|
if (source === 'plan') {
|
|
4411
4923
|
if (isFile(errorsOut)) unlinkSync(errorsOut);
|
|
4412
|
-
|
|
4924
|
+
// 0385 AC R2/R3: the editorial findings are advisory — an accepted plan stays accepted,
|
|
4925
|
+
// so they land in their own file and never re-open the fix loop that `errorsOut` drives.
|
|
4926
|
+
const advisoriesOut = join(workDir, '24-script', `${runDate}_08_script-write_advisories.json`);
|
|
4927
|
+
const advisories = Array.isArray(metadata.scriptPlanAdvisories) ? metadata.scriptPlanAdvisories : [];
|
|
4928
|
+
if (advisories.length > 0) {
|
|
4929
|
+
sted('write', advisoriesOut, () => writeJsonText(advisoriesOut, advisories));
|
|
4930
|
+
console.log(
|
|
4931
|
+
`script plan accepted by the validator (${advisories.length} advisory finding(s)): ${advisoriesOut}`,
|
|
4932
|
+
);
|
|
4933
|
+
} else {
|
|
4934
|
+
if (isFile(advisoriesOut)) unlinkSync(advisoriesOut);
|
|
4935
|
+
console.log('script plan accepted by the validator');
|
|
4936
|
+
}
|
|
4413
4937
|
return;
|
|
4414
4938
|
}
|
|
4415
4939
|
writeErrors(Array.isArray(metadata.scriptPlanErrors) ? metadata.scriptPlanErrors : []);
|
|
@@ -4454,6 +4978,14 @@ export function dailyCurateCheck(args: string[]): void {
|
|
|
4454
4978
|
sted('write', planFile, () => writeJsonText(planFile, candidateDocs));
|
|
4455
4979
|
sted('write', excludedFile, () => writeJsonText(excludedFile, []));
|
|
4456
4980
|
if (isFile(errFile)) unlinkSync(errFile);
|
|
4981
|
+
// Task 0392 R2: the recorded fallback IS the curation evidence for this attempt — the
|
|
4982
|
+
// agent's split was rejected, so the plan is every candidate and nothing was excluded.
|
|
4983
|
+
recordSelectionStage(workDir, runDate, {
|
|
4984
|
+
stages: [
|
|
4985
|
+
{ stage: 'curation', input: candidateIds.length, kept: candidateDocs.length, dropped: [] },
|
|
4986
|
+
{ stage: 'plan', input: candidateDocs.length, kept: candidateDocs.length, dropped: [] },
|
|
4987
|
+
],
|
|
4988
|
+
});
|
|
4457
4989
|
return;
|
|
4458
4990
|
}
|
|
4459
4991
|
sted('write', errFile, () => writeJsonText(errFile, errors));
|
|
@@ -4564,6 +5096,9 @@ export function dailyCurateCheck(args: string[]): void {
|
|
|
4564
5096
|
return;
|
|
4565
5097
|
}
|
|
4566
5098
|
|
|
5099
|
+
// Captured before the check's own dedup pass: `curation` records what the AGENT handed over,
|
|
5100
|
+
// `plan` records what the validation then kept, so the two stages never double-count a drop.
|
|
5101
|
+
const agentExcluded = excludedItems.map((entry) => entry.id);
|
|
4567
5102
|
const { kept, dropped } = dedupPlanByTitle(planDocs);
|
|
4568
5103
|
if (dropped.length > 0) {
|
|
4569
5104
|
sted('write', planFile, () => writeJsonText(planFile, kept));
|
|
@@ -4580,18 +5115,201 @@ export function dailyCurateCheck(args: string[]): void {
|
|
|
4580
5115
|
}
|
|
4581
5116
|
|
|
4582
5117
|
if (isFile(errFile)) unlinkSync(errFile);
|
|
5118
|
+
// Task 0392 R2: curation is authoritative only after this validation passed — that is why the
|
|
5119
|
+
// evidence is written here and not by the agent. `curation` is the agent's split as handed over;
|
|
5120
|
+
// `plan` is the validated plan after the check's own near-duplicate pass, so the two stages
|
|
5121
|
+
// chain (`curation.kept` → `plan.input`) and each one's arithmetic holds.
|
|
5122
|
+
recordSelectionStage(workDir, runDate, {
|
|
5123
|
+
stages: [
|
|
5124
|
+
{
|
|
5125
|
+
stage: 'curation',
|
|
5126
|
+
input: candidateIds.length,
|
|
5127
|
+
kept: planDocs.length,
|
|
5128
|
+
dropped: agentExcluded,
|
|
5129
|
+
},
|
|
5130
|
+
{ stage: 'plan', input: planDocs.length, kept: kept.length, dropped },
|
|
5131
|
+
],
|
|
5132
|
+
curationExcluded: excludedItems.map((entry) => ({ id: entry.id, reason: entry.reason })),
|
|
5133
|
+
});
|
|
4583
5134
|
console.log(`curate-check: accepted (${kept.length} kept, ${excludedItems.length} excluded)`);
|
|
4584
5135
|
}
|
|
4585
5136
|
|
|
4586
|
-
|
|
4587
|
-
|
|
4588
|
-
|
|
4589
|
-
|
|
5137
|
+
/**
|
|
5138
|
+
* 0394 R1/R16 — the citation line for one curated item, or `''` when the doc carries no verifiable
|
|
5139
|
+
* link. Resolution (corroborated original → retrieval URL → explicit aggregator fallback) is owned
|
|
5140
|
+
* by `./source-citation.ts` so the same rule can serve the notes paths without a second convention.
|
|
5141
|
+
*/
|
|
5142
|
+
function sourceLineForDoc(doc: Record<string, unknown>, sourceUri: string): string {
|
|
5143
|
+
const citation = resolveSourceCitation(doc, sourceUri);
|
|
5144
|
+
return citation === null ? '' : `[来源:${citation.label}](${citation.url})`;
|
|
5145
|
+
}
|
|
5146
|
+
|
|
5147
|
+
/**
|
|
5148
|
+
* What the `editorial-commit` stage reports instead of the ledger module's raw status: the two
|
|
5149
|
+
* "nothing to fix" outcomes collapse to `committed` / `reused`, the two refusals stay verbatim.
|
|
5150
|
+
*/
|
|
5151
|
+
export type EditorialCommitSummary = 'committed' | 'reused' | 'conflict' | 'stop';
|
|
5152
|
+
|
|
5153
|
+
/**
|
|
5154
|
+
* The existing kk store single-flight claim as the ledger's `LockPort` (ADR-054/0384 R10): the
|
|
5155
|
+
* same `kk lock acquire/release` the collect workflow shells, scoped to the ledger's own name. A
|
|
5156
|
+
* second locking mechanism is deliberately not invented — the store's `LocksDao` owns the claim,
|
|
5157
|
+
* its TTL and its re-entrancy.
|
|
5158
|
+
*/
|
|
5159
|
+
function kkLedgerLockPort(): LockPort {
|
|
5160
|
+
const kkLock = (argv: string[]): { status: number; stdout: string; stderr: string } => {
|
|
5161
|
+
const result = spawnSync('kk', argv, { encoding: 'utf-8' });
|
|
5162
|
+
if (result.error !== undefined) failWith(127, `kk: ${result.error.message}`);
|
|
5163
|
+
return { status: result.status ?? 1, stdout: result.stdout ?? '', stderr: result.stderr ?? '' };
|
|
5164
|
+
};
|
|
5165
|
+
return {
|
|
5166
|
+
acquire: async (name: string, run: string) => {
|
|
5167
|
+
// stdout IS the lock contract: `{"acquired":true}` or `{"skipped":"locked",…}` (exit 0).
|
|
5168
|
+
const claimed = kkLock(['lock', 'acquire', '--name', name, '--run', run]);
|
|
5169
|
+
if (claimed.status !== 0) failWith(claimed.status, `lock acquire failed: ${claimed.stderr.trim()}`);
|
|
5170
|
+
return claimed.stdout.includes('"acquired":true');
|
|
5171
|
+
},
|
|
5172
|
+
release: async (name: string, run: string) => {
|
|
5173
|
+
const released = kkLock(['lock', 'release', '--name', name, '--run', run]);
|
|
5174
|
+
if (released.status !== 0) {
|
|
5175
|
+
console.error(`editorial-commit: lock release failed: ${released.stderr.trim()}`);
|
|
5176
|
+
}
|
|
5177
|
+
},
|
|
5178
|
+
};
|
|
5179
|
+
}
|
|
5180
|
+
|
|
5181
|
+
/** Selected ids from the plan `curate-final` settled — the only ids a judgment may cite (0393). */
|
|
5182
|
+
function selectedIdsOf(planRaw: unknown): Set<string> {
|
|
5183
|
+
const docs: Record<string, unknown>[] = Array.isArray(planRaw)
|
|
5184
|
+
? (planRaw as Record<string, unknown>[])
|
|
5185
|
+
: Array.isArray(metadataOf(planRaw).docs)
|
|
5186
|
+
? (metadataOf(planRaw).docs as Record<string, unknown>[])
|
|
5187
|
+
: [];
|
|
5188
|
+
const ids = new Set<string>();
|
|
5189
|
+
for (const doc of docs) {
|
|
5190
|
+
if (doc !== null && typeof doc === 'object' && typeof doc.id === 'string' && doc.id.trim() !== '') {
|
|
5191
|
+
ids.add(doc.id.trim());
|
|
5192
|
+
}
|
|
4590
5193
|
}
|
|
4591
|
-
|
|
4592
|
-
|
|
4593
|
-
|
|
4594
|
-
|
|
5194
|
+
return ids;
|
|
5195
|
+
}
|
|
5196
|
+
|
|
5197
|
+
/**
|
|
5198
|
+
* 0384 R4/R10 — the deterministic judgment commit between final selection and drafting: the
|
|
5199
|
+
* `align` agent's proposal in, a validated ledger commit and an immutable run snapshot out.
|
|
5200
|
+
*
|
|
5201
|
+
* news-editorial-commit <work_dir> <run_date> <run_id> [proposal_file] [ledger_file]
|
|
5202
|
+
*
|
|
5203
|
+
* `<proposal_file>` defaults to `21-plan/<date>_judgment-proposal.json` (absent file = the documented
|
|
5204
|
+
* "nothing new" case, an empty proposal); `<ledger_file>` defaults to the run directory's parent
|
|
5205
|
+
* `<works_dir>/kk-news-generate/conclusion.md` (ADR-054). Outputs — both beside the plan:
|
|
5206
|
+
* `judgment-snapshot.json` (what 0385 drafts from and 0396 corrects from) and
|
|
5207
|
+
* `judgment-commit-receipt.json` (written on every exit path, including the refusals).
|
|
5208
|
+
*
|
|
5209
|
+
* Reselect tolerance: the proposal is authored in `curate`, but `curate-check`/`curate-fix`/`--final`
|
|
5210
|
+
* settle the plan afterwards, so a judgment may cite a selected id the settled plan no longer holds.
|
|
5211
|
+
* Such judgments are dropped *here* (never inside the ledger API, whose unknown-id refusal stays) and
|
|
5212
|
+
* the ids go into the receipt's `droppedByReselection` plus a printed line — the surviving judgments
|
|
5213
|
+
* still commit, and a proposal with nothing committable left behaves exactly like the documented
|
|
5214
|
+
* empty proposal (this run's legal snapshot is reused). Never silent, never a hard stop for reselection alone.
|
|
5215
|
+
*
|
|
5216
|
+
* Exit: `committed` / `reused` exit 0; `conflict` and `stop` print the recovery path and exit 1, so
|
|
5217
|
+
* a refused ledger commit can never be drafted against. `KK_EDITORIAL_COMMIT_OFFLINE=1` runs the
|
|
5218
|
+
* commit without the store claim (the documented `NULL_LOCK` seam; tests and offline replay).
|
|
5219
|
+
*/
|
|
5220
|
+
export async function newsEditorialCommit(args: string[]): Promise<void> {
|
|
5221
|
+
const [workDir = '', runDate = '', runId = '', proposalArg = '', ledgerArg = ''] = args;
|
|
5222
|
+
if (!workDir) fail('missing work_dir');
|
|
5223
|
+
if (!runDate) fail('missing run_date');
|
|
5224
|
+
if (!runId) fail('missing run_id');
|
|
5225
|
+
// 0384: judged artifacts live beside the plan, NOT under `20-editorial/` — that directory is the
|
|
5226
|
+
// per-run writer-skill snapshot (design §2.2 keeps the skill read in place, and the DAG contract
|
|
5227
|
+
// forbids agent prompts naming a copy there).
|
|
5228
|
+
const planDir = join(workDir, '21-plan');
|
|
5229
|
+
const proposalPath = proposalArg || join(planDir, `${runDate}_judgment-proposal.json`);
|
|
5230
|
+
const ledgerPath = ledgerArg || resolve(join(workDir, '..', 'conclusion.md'));
|
|
5231
|
+
const snapshotPath = join(planDir, `${runDate}_judgment-snapshot.json`);
|
|
5232
|
+
const receiptPath = join(planDir, `${runDate}_judgment-commit-receipt.json`);
|
|
5233
|
+
const planFile = join(workDir, '21-plan', `${runDate}_03_plan_plan.json`);
|
|
5234
|
+
|
|
5235
|
+
const planRaw = readJson(planFile);
|
|
5236
|
+
if (planRaw === null) {
|
|
5237
|
+
failWith(1, `editorial-commit: no selected plan at ${planFile} — refusing to commit judgments`);
|
|
5238
|
+
}
|
|
5239
|
+
const selectedIds = selectedIdsOf(planRaw);
|
|
5240
|
+
|
|
5241
|
+
let proposal: AlignmentProposal;
|
|
5242
|
+
if (isFile(proposalPath)) {
|
|
5243
|
+
try {
|
|
5244
|
+
const parsed = JSON.parse(readFileSync(proposalPath, 'utf-8')) as AlignmentProposal;
|
|
5245
|
+
if (parsed === null || typeof parsed !== 'object' || !Array.isArray(parsed.judgments)) {
|
|
5246
|
+
failWith(1, `editorial-commit: ${proposalPath} has no judgments array — re-run the align pass`);
|
|
5247
|
+
}
|
|
5248
|
+
proposal = parsed;
|
|
5249
|
+
} catch (error) {
|
|
5250
|
+
failWith(1, `editorial-commit: ${proposalPath} is not valid JSON: ${(error as Error).message}`);
|
|
5251
|
+
}
|
|
5252
|
+
} else {
|
|
5253
|
+
// An empty proposal is the normal case (skill `align` rule 4), not a failure.
|
|
5254
|
+
proposal = { version: 1, judgments: [] };
|
|
5255
|
+
console.log(`editorial-commit: no proposal at ${proposalPath} — committing this run's ledger as-is`);
|
|
5256
|
+
}
|
|
5257
|
+
|
|
5258
|
+
// The plan is settled by now (`curate-check`/`curate-fix`/`--final`), so an id the proposal cited
|
|
5259
|
+
// from the pre-settlement plan may be gone: drop those judgments and record them (never silent).
|
|
5260
|
+
const reselected = dropReselectedJudgments(proposal, selectedIds);
|
|
5261
|
+
if (reselected.dropped.length > 0) {
|
|
5262
|
+
// Same stream as the sibling drop reports (`curate-check`, `qc`): a drop is loud, not fatal.
|
|
5263
|
+
console.error(
|
|
5264
|
+
`editorial-commit: dropped ${reselected.dropped.length} judgment(s) the settled plan no longer carries: ${reselected.dropped.join(', ')}`,
|
|
5265
|
+
);
|
|
5266
|
+
}
|
|
5267
|
+
|
|
5268
|
+
sted('mkdir', planDir, () => mkdirSync(planDir, { recursive: true }));
|
|
5269
|
+
// Offline means NO lock port at all (the ledger's documented `NULL_LOCK` default), so the
|
|
5270
|
+
// receipt says `lock: none` — passing NULL_LOCK explicitly would report a claim it never took.
|
|
5271
|
+
const receipt = await commitAlignment({
|
|
5272
|
+
ledgerPath,
|
|
5273
|
+
snapshotPath,
|
|
5274
|
+
receiptPath,
|
|
5275
|
+
proposal: reselected.proposal,
|
|
5276
|
+
selectedIds,
|
|
5277
|
+
runDate,
|
|
5278
|
+
runId,
|
|
5279
|
+
now: new Date().toISOString(),
|
|
5280
|
+
droppedByReselection: reselected.dropped,
|
|
5281
|
+
...(process.env.KK_EDITORIAL_COMMIT_OFFLINE === '1' ? {} : { lock: kkLedgerLockPort() }),
|
|
5282
|
+
});
|
|
5283
|
+
|
|
5284
|
+
const summary: EditorialCommitSummary =
|
|
5285
|
+
receipt.status === 'applied'
|
|
5286
|
+
? 'committed'
|
|
5287
|
+
: receipt.status === 'no-op'
|
|
5288
|
+
? 'reused'
|
|
5289
|
+
: receipt.status === 'conflict'
|
|
5290
|
+
? 'conflict'
|
|
5291
|
+
: 'stop';
|
|
5292
|
+
const counts = [
|
|
5293
|
+
`appended=${receipt.appended.length}`,
|
|
5294
|
+
`superseded=${receipt.superseded.length}`,
|
|
5295
|
+
`corrections=${receipt.correctionIds.length}`,
|
|
5296
|
+
`dropped=${receipt.droppedByReselection.length}`,
|
|
5297
|
+
`lock=${receipt.lock}`,
|
|
5298
|
+
`snapshot=${receipt.snapshotReused ? 'reused' : 'frozen'}`,
|
|
5299
|
+
].join(' ');
|
|
5300
|
+
console.log(
|
|
5301
|
+
`editorial-commit: ${summary} — ${receipt.reason} (${counts}; ledger=${receipt.ledgerPath}; receipt=${receiptPath})`,
|
|
5302
|
+
);
|
|
5303
|
+
if (receipt.correctionIds.length > 0) {
|
|
5304
|
+
console.log(`editorial-commit: corrections owed by the draft: ${receipt.correctionIds.join(', ')}`);
|
|
5305
|
+
}
|
|
5306
|
+
if (summary === 'conflict' || summary === 'stop') {
|
|
5307
|
+
const recovery = receipt.recovery;
|
|
5308
|
+
const where = recovery?.backupPath ? ` backup=${recovery.backupPath}` : '';
|
|
5309
|
+
failWith(
|
|
5310
|
+
1,
|
|
5311
|
+
`editorial-commit: ${summary} — ${receipt.reason}${where} (${recovery?.action ?? 'see the receipt'})`,
|
|
5312
|
+
);
|
|
4595
5313
|
}
|
|
4596
5314
|
}
|
|
4597
5315
|
|
|
@@ -4659,11 +5377,19 @@ export function dailyEditorialRender(args: string[]): void {
|
|
|
4659
5377
|
const title = typeof doc?.title === 'string' ? doc.title.trim() : '';
|
|
4660
5378
|
const body = typeof doc?.body === 'string' ? doc.body.trim() : '';
|
|
4661
5379
|
const lead = typeof item?.lead === 'string' ? item.lead.trim() : '';
|
|
5380
|
+
// 0385 R3: a comment-free item is legal, so a blank insight drops the comment sentence
|
|
5381
|
+
// only — dropping the whole item would publish an episode the plan says to speak.
|
|
4662
5382
|
const insight = typeof item?.insight === 'string' ? item.insight.trim() : '';
|
|
4663
|
-
if (!title || !body || !lead
|
|
5383
|
+
if (!title || !body || !lead) continue;
|
|
4664
5384
|
const sourceUri = typeof doc?.sourceUri === 'string' ? doc.sourceUri.trim() : '';
|
|
4665
|
-
const sourceLine = sourceUri ?
|
|
4666
|
-
const parts = [
|
|
5385
|
+
const sourceLine = sourceUri ? sourceLineForDoc(doc ?? {}, sourceUri) : '';
|
|
5386
|
+
const parts = [
|
|
5387
|
+
`## ${title}`,
|
|
5388
|
+
lead,
|
|
5389
|
+
body,
|
|
5390
|
+
...(insight !== '' ? [insight] : []),
|
|
5391
|
+
...(sourceLine ? [sourceLine] : []),
|
|
5392
|
+
];
|
|
4667
5393
|
articleSections.push(parts.join('\n\n'));
|
|
4668
5394
|
}
|
|
4669
5395
|
if (articleSections.length > 0 && outro !== '') {
|
|
@@ -4693,8 +5419,73 @@ export function dailyEditorialRender(args: string[]): void {
|
|
|
4693
5419
|
const leadId = orderedIds[0];
|
|
4694
5420
|
const leadDoc = leadId !== undefined ? docById.get(leadId) : undefined;
|
|
4695
5421
|
const leadStoryTitle = typeof leadDoc?.title === 'string' ? leadDoc.title.trim() : '';
|
|
5422
|
+
// 0385 R4: freeze ONE episode identity (run date + one point + the source ids the point rests
|
|
5423
|
+
// on) for every publishing surface. The point is the script plan's cover headline and the cover
|
|
5424
|
+
// reuses it verbatim, never a second wording. Two non-frozen outcomes are explicit: an existing
|
|
5425
|
+
// frozen record wins (a retry or a historical replay keeps the identity the bundle shipped), and
|
|
5426
|
+
// a point whose supporting sources admission dropped is WITHHELD — no title, no cover point, so
|
|
5427
|
+
// nothing downstream can publish a headline the settled plan no longer backs.
|
|
5428
|
+
const rawCoverSupport =
|
|
5429
|
+
rawCover !== null && typeof rawCover === 'object' ? (rawCover as Record<string, unknown>).sourceIds : undefined;
|
|
5430
|
+
// 0385 R4/P3: "admitted" means the episode actually covers the id — the plan docs MINUS the drop
|
|
5431
|
+
// signals downstream already honours (the article boundary drop `metadata.excludedIds` and the
|
|
5432
|
+
// script plan's own `excluded` list). Comparing against the raw plan set made the withhold
|
|
5433
|
+
// guarantee structurally unreachable: the lead is always in the plan it came from.
|
|
5434
|
+
const droppedIds = new Set<string>();
|
|
5435
|
+
const articleMetaExcluded = metadataOf(
|
|
5436
|
+
readJson(join(workDir, '22-article', `${runDate}_06_article_content.json`)),
|
|
5437
|
+
)?.excludedIds;
|
|
5438
|
+
if (Array.isArray(articleMetaExcluded)) {
|
|
5439
|
+
for (const id of articleMetaExcluded) if (typeof id === 'string' && id !== '') droppedIds.add(id);
|
|
5440
|
+
}
|
|
5441
|
+
if (Array.isArray(master.excluded)) {
|
|
5442
|
+
for (const entry of master.excluded as unknown[]) {
|
|
5443
|
+
const id = entry !== null && typeof entry === 'object' ? (entry as { id?: unknown }).id : undefined;
|
|
5444
|
+
if (typeof id === 'string' && id !== '') droppedIds.add(id);
|
|
5445
|
+
}
|
|
5446
|
+
}
|
|
5447
|
+
const admittedSourceIds = [...docById.keys()].filter((id) => !droppedIds.has(id));
|
|
5448
|
+
// The point's support is the cover's own `sourceIds` when the writer named them (the documented
|
|
5449
|
+
// producer, 0385 R4), otherwise the admitted lead — the story the point is about.
|
|
5450
|
+
const supportIds = Array.isArray(rawCoverSupport)
|
|
5451
|
+
? rawCoverSupport.filter((id): id is string => typeof id === 'string' && id.trim() !== '')
|
|
5452
|
+
: leadId !== undefined
|
|
5453
|
+
? [leadId]
|
|
5454
|
+
: [];
|
|
5455
|
+
const identityPath = join(workDir, '21-plan', `${runDate}_05_script_identity.json`);
|
|
5456
|
+
const priorIdentity = identityFromMetadata({ [EPISODE_IDENTITY_KEY]: readJson(identityPath) });
|
|
5457
|
+
const identity =
|
|
5458
|
+
priorIdentity !== null && priorIdentity.status === 'frozen'
|
|
5459
|
+
? priorIdentity
|
|
5460
|
+
: freezeEpisodeIdentity({
|
|
5461
|
+
date: runDate,
|
|
5462
|
+
headline: coverHeadline,
|
|
5463
|
+
supportingSourceIds: supportIds,
|
|
5464
|
+
admittedSourceIds,
|
|
5465
|
+
legacyTitle: leadStoryTitle,
|
|
5466
|
+
});
|
|
5467
|
+
if (priorIdentity === null || priorIdentity.status !== 'frozen') {
|
|
5468
|
+
sted('mkdir', join(workDir, '21-plan'), () => mkdirSync(join(workDir, '21-plan'), { recursive: true }));
|
|
5469
|
+
sted('write', identityPath, () => writeJsonText(identityPath, identity));
|
|
5470
|
+
}
|
|
5471
|
+
if (identity.status === 'frozen') {
|
|
5472
|
+
console.log(`editorial-render: episode identity frozen: ${identity.title} (${identityPath})`);
|
|
5473
|
+
} else if (identity.status === 'support-removed') {
|
|
5474
|
+
// The point lost its support in admission: withhold it and its cover copy (never a fallback
|
|
5475
|
+
// title here — the fallback below would smuggle back a point the plan no longer admits).
|
|
5476
|
+
console.error(
|
|
5477
|
+
`editorial-render: WITHHELD episode identity — admission dropped the headline's support (${identity.supportingSourceIds.join(', ')}); the title and the cover point are withheld (see ${identityPath})`,
|
|
5478
|
+
);
|
|
5479
|
+
coverHeadline = '';
|
|
5480
|
+
}
|
|
5481
|
+
// Every target reads the frozen title from the bundle, so the article Content (surfdash, ID3,
|
|
5482
|
+
// show notes) carries the same one the podcast and the cover do. A withheld identity leaves the
|
|
5483
|
+
// article title untouched: there is no title to share. On a first run the Content does not exist
|
|
5484
|
+
// yet (this stage precedes `daily-article`) and the stamp is a no-op — `daily-article` re-applies
|
|
5485
|
+
// it after it derives, so both orders converge on one title.
|
|
5486
|
+
stampEpisodeIdentity(join(workDir, '22-article', `${runDate}_06_article_content.json`), identity);
|
|
4696
5487
|
if (coverSubject !== '') {
|
|
4697
|
-
if (coverHeadline === '' && leadStoryTitle !== '') {
|
|
5488
|
+
if (coverHeadline === '' && leadStoryTitle !== '' && identity.status !== 'support-removed') {
|
|
4698
5489
|
coverHeadline = leadStoryTitle;
|
|
4699
5490
|
}
|
|
4700
5491
|
const coverDir = join(workDir, '23-cover');
|
|
@@ -4703,8 +5494,11 @@ export function dailyEditorialRender(args: string[]): void {
|
|
|
4703
5494
|
sted('write', coverOut, () =>
|
|
4704
5495
|
writeJsonText(coverOut, {
|
|
4705
5496
|
subject: coverSubject,
|
|
4706
|
-
|
|
5497
|
+
// The cover reuses the frozen point verbatim (0385 R4); `episodeIdentity` carries the
|
|
5498
|
+
// title so a retry or a replay re-renders the same episode identity.
|
|
5499
|
+
headline: identity.coverHeadline ?? coverHeadline,
|
|
4707
5500
|
leadStoryTitle,
|
|
5501
|
+
episodeIdentity: identity,
|
|
4708
5502
|
}),
|
|
4709
5503
|
);
|
|
4710
5504
|
console.log(`editorial-render: wrote cover brief: ${coverOut}`);
|
|
@@ -4916,12 +5710,29 @@ export function dailyShowNotes(args: string[]): void {
|
|
|
4916
5710
|
}
|
|
4917
5711
|
}
|
|
4918
5712
|
}
|
|
5713
|
+
// 0386 R1 — the card manifest (already in published order) rides along as a file path, and
|
|
5714
|
+
// its problems are recorded beside the notes, never inside them. When no receipt exists yet
|
|
5715
|
+
// the render is explicitly allowed to run link-free: the notes are reviewable before the
|
|
5716
|
+
// article URL is known, and the article link is added only from a real receipt `postPath`.
|
|
5717
|
+
const cardsManifest = join(workDir, '25-xhs', 'cards.json');
|
|
5718
|
+
const cardsDiagnostics = join(workDir, '31-publish', `${runDate}_15_show-notes_cards-diagnostics.json`);
|
|
4919
5719
|
kk(['executor', 'run', 'podcast-pub', '--in', planIn, '--out', out, ...pluginsArgs(pluginsPath)], {
|
|
4920
5720
|
env: {
|
|
4921
5721
|
PODCAST_PUB_TITLE: titleArg,
|
|
4922
5722
|
PODCAST_PUB_RUN_DATE: runDate,
|
|
4923
5723
|
PODCAST_PUB_BRIEF_MODE: 'true',
|
|
5724
|
+
...(isFile(cardsManifest) ? { PODCAST_PUB_CARDS: cardsManifest } : {}),
|
|
5725
|
+
PODCAST_PUB_CARDS_DIAGNOSTICS: cardsDiagnostics,
|
|
5726
|
+
...(postPath === '' ? { PODCAST_PUB_BRIEF_WITHOUT_RECEIPT: 'true' } : {}),
|
|
4924
5727
|
PODCAST_PUB_ARTICLE_POST_PATH: postPath,
|
|
5728
|
+
// 0396 R1: the frozen 0384 judgment snapshot is what the correction block is read
|
|
5729
|
+
// from (stable correction id, prior-episode reference, evidence). Passing the path
|
|
5730
|
+
// only when the snapshot exists keeps a run without corrections byte-identical, and
|
|
5731
|
+
// a snapshot that cannot be read fails the render instead of dropping an owed
|
|
5732
|
+
// correction silently.
|
|
5733
|
+
...(isFile(join(workDir, '21-plan', `${runDate}_judgment-snapshot.json`))
|
|
5734
|
+
? { PODCAST_PUB_CORRECTIONS: join(workDir, '21-plan', `${runDate}_judgment-snapshot.json`) }
|
|
5735
|
+
: {}),
|
|
4925
5736
|
// 2026-10-08: the column settings carry the AI-production note. Do not append the
|
|
4926
5737
|
// stock closer to show notes (or the article, or the spoken sign-off).
|
|
4927
5738
|
...(isFile(audioContent) ? { PODCAST_PUB_AUDIO_CONTENT: audioContent } : {}),
|
|
@@ -5258,6 +6069,68 @@ export function dailyTranslateValidate(args: string[]): void {
|
|
|
5258
6069
|
});
|
|
5259
6070
|
}
|
|
5260
6071
|
|
|
6072
|
+
/** CJK ideographs and kana: present in a zh draft, absent from a real en translation. */
|
|
6073
|
+
const CJK_TEXT = /[\u3040-\u30ff\u3400-\u4dbf\u4e00-\u9fff\uff66-\uff9f]/u;
|
|
6074
|
+
/** Kana only: a ja translation always carries hiragana/katakana; a zh copy of the draft never does. */
|
|
6075
|
+
const KANA_TEXT = /[\u3040-\u309f\u30a0-\u30ff]/u;
|
|
6076
|
+
|
|
6077
|
+
/**
|
|
6078
|
+
* `news-localize-validate <workDir>` — the pre-freeze gate on the news pipeline's en/ja translations
|
|
6079
|
+
* (task 0409 R1).
|
|
6080
|
+
*
|
|
6081
|
+
* The `localize` agent node writes `${workDir}/22-article/locales/{en,ja}.md` (first line
|
|
6082
|
+
* `# <title>`, rest the body) between `review` and `variants`. This stage refuses a locale that is
|
|
6083
|
+
* missing, empty, untitled, or still Chinese — an untranslated locale is not a locale — so no bundle
|
|
6084
|
+
* can freeze half-localized. Translating after the freeze would break ADR-053's "publish exactly what
|
|
6085
|
+
* was safety-reviewed and frozen", and translating inside the plugin would put a model call in a
|
|
6086
|
+
* deterministic step, so the gate lives here.
|
|
6087
|
+
*/
|
|
6088
|
+
export function newsLocalizeValidate(args: string[]): void {
|
|
6089
|
+
const [workDir = ''] = args;
|
|
6090
|
+
timed(workDir, 'localize-validate', () => {
|
|
6091
|
+
const localesDir = join(workDir, '22-article', 'locales');
|
|
6092
|
+
const accepted: string[] = [];
|
|
6093
|
+
const problems: string[] = [];
|
|
6094
|
+
for (const locale of ['en', 'ja'] as const) {
|
|
6095
|
+
const file = join(localesDir, `${locale}.md`);
|
|
6096
|
+
if (!isFile(file)) {
|
|
6097
|
+
problems.push(`${locale}: file missing (${file})`);
|
|
6098
|
+
continue;
|
|
6099
|
+
}
|
|
6100
|
+
const raw = readFileSync(file, 'utf-8');
|
|
6101
|
+
if (raw.trim() === '') {
|
|
6102
|
+
problems.push(`${locale}: file is empty`);
|
|
6103
|
+
continue;
|
|
6104
|
+
}
|
|
6105
|
+
const [firstLine = '', ...rest] = raw.split('\n');
|
|
6106
|
+
const title = firstLine.startsWith('# ') ? firstLine.slice(2).trim() : '';
|
|
6107
|
+
if (title === '') {
|
|
6108
|
+
problems.push(`${locale}: first line must be "# <title>", got "${firstLine.trim().slice(0, 60)}"`);
|
|
6109
|
+
continue;
|
|
6110
|
+
}
|
|
6111
|
+
if (rest.join('\n').trim() === '') {
|
|
6112
|
+
problems.push(`${locale}: body is empty after the title line`);
|
|
6113
|
+
continue;
|
|
6114
|
+
}
|
|
6115
|
+
const untranslated = locale === 'en' ? CJK_TEXT.test(raw) : !KANA_TEXT.test(raw);
|
|
6116
|
+
if (untranslated) {
|
|
6117
|
+
problems.push(
|
|
6118
|
+
`${locale}: untranslated — ${locale === 'en' ? 'the document still carries CJK text' : 'the document has no kana, so it is not Japanese'}`,
|
|
6119
|
+
);
|
|
6120
|
+
continue;
|
|
6121
|
+
}
|
|
6122
|
+
accepted.push(locale);
|
|
6123
|
+
}
|
|
6124
|
+
if (problems.length > 0) {
|
|
6125
|
+
failWith(1, `localize-validate: ${problems.join('; ')} — repair the translation before freezing`);
|
|
6126
|
+
}
|
|
6127
|
+
sted('write', join(localesDir, 'localize-validate.json'), () =>
|
|
6128
|
+
writeJsonText(join(localesDir, 'localize-validate.json'), { ok: true, locales: accepted }),
|
|
6129
|
+
);
|
|
6130
|
+
console.log(`localize-validate: ${accepted.join('/')} translations ready for the freeze`);
|
|
6131
|
+
});
|
|
6132
|
+
}
|
|
6133
|
+
|
|
5261
6134
|
export function dailyTranslateSync(args: string[]): void {
|
|
5262
6135
|
const [workDir = '', runDate = '', pluginsPath = '', zhPathFile = ''] = args;
|
|
5263
6136
|
const sync = join(workDir, '31-publish', `${runDate}_24_translate-sync_sync.json`);
|