@gobing-ai/knowledge-kit 0.1.19 → 0.1.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +1 -1
- package/dist/board/collect/index.js +1 -0
- package/dist/board/daily-voice/index.js +1315 -264
- package/dist/board/itc/index.js +1 -0
- package/dist/index.js +14674 -8775
- package/package.json +1 -1
- package/plugins/generations/dailynews-gen/dist/index.js +285 -16
- package/plugins/generations/dailynews-gen/src/editorial-claims.ts +215 -0
- package/plugins/generations/dailynews-gen/src/index.ts +23 -4
- package/plugins/generations/dailynews-gen/src/script-builder.ts +10 -3
- package/plugins/generations/dailynews-gen/src/script-plan.ts +74 -14
- package/plugins/generations/image-gen/README.md +31 -31
- package/plugins/generations/image-gen/assets/sample/provenance.json +314 -0
- package/plugins/generations/image-gen/config.example.yaml +3 -0
- package/plugins/generations/image-gen/dist/index.js +154 -14
- package/plugins/generations/image-gen/presets/SOURCE.md +65 -0
- package/plugins/generations/image-gen/scripts/eval-style-presets.ts +513 -0
- package/plugins/generations/image-gen/scripts/gen-samples.ts +57 -7
- package/plugins/generations/image-gen/src/presets.ts +6 -5
- package/plugins/generations/image-gen/src/providers/h3-local.ts +196 -0
- package/plugins/generations/image-gen/src/providers/types.ts +11 -1
- package/plugins/generations/music-gen/README.md +277 -0
- package/plugins/generations/music-gen/dist/index.js +23544 -0
- package/plugins/generations/music-gen/package.json +24 -0
- package/plugins/generations/music-gen/plugin.json +23 -0
- package/plugins/generations/music-gen/presets/SOURCE.md +39 -0
- package/plugins/generations/music-gen/presets/formats/clip.yaml +21 -0
- package/plugins/generations/music-gen/presets/formats/jingle.yaml +22 -0
- package/plugins/generations/music-gen/presets/formats/loop.yaml +21 -0
- package/plugins/generations/music-gen/presets/formats/song.yaml +31 -0
- package/plugins/generations/music-gen/presets/formats/underscore.yaml +22 -0
- package/plugins/generations/music-gen/presets/themes/ambient-tech.yaml +30 -0
- package/plugins/generations/music-gen/presets/themes/cinematic.yaml +30 -0
- package/plugins/generations/music-gen/presets/themes/lofi.yaml +30 -0
- package/plugins/generations/music-gen/presets/themes/synthwave.yaml +30 -0
- package/plugins/generations/music-gen/scripts/gen-preset-index.ts +181 -0
- package/plugins/generations/music-gen/scripts/resolve-preset.ts +64 -0
- package/plugins/generations/music-gen/src/adapter/index.ts +35 -0
- package/plugins/generations/music-gen/src/adapter/instance.ts +904 -0
- package/plugins/generations/music-gen/src/adapter/offline.ts +124 -0
- package/plugins/generations/music-gen/src/artifact.ts +223 -0
- package/plugins/generations/music-gen/src/audio/checks.ts +618 -0
- package/plugins/generations/music-gen/src/audio/master.ts +267 -0
- package/plugins/generations/music-gen/src/audio/measure.ts +507 -0
- package/plugins/generations/music-gen/src/audio/profile.ts +131 -0
- package/plugins/generations/music-gen/src/audio.ts +122 -0
- package/plugins/generations/music-gen/src/brief.ts +191 -0
- package/plugins/generations/music-gen/src/config.ts +451 -0
- package/plugins/generations/music-gen/src/content.ts +199 -0
- package/plugins/generations/music-gen/src/digest.ts +100 -0
- package/plugins/generations/music-gen/src/index.ts +147 -0
- package/plugins/generations/music-gen/src/job.ts +131 -0
- package/plugins/generations/music-gen/src/plugin.ts +371 -0
- package/plugins/generations/music-gen/src/presets.ts +918 -0
- package/plugins/generations/music-gen/src/render.ts +87 -0
- package/plugins/generations/music-gen/src/request.ts +102 -0
- package/plugins/generations/music-gen/src/spend.ts +495 -0
- package/plugins/generations/music-gen/tsconfig.json +8 -0
- package/plugins/kk/config.example.yaml +3 -0
- package/plugins/kk/decisions/extract/ai-news.yaml +5 -2
- package/plugins/kk/plugin.json +1 -1
- package/plugins/kk/publish-presets/daily-ai-voice.json +48 -7
- package/plugins/kk/schedules/kk-serve.launchd.plist.tmpl +2 -1
- package/plugins/kk/scripts/cover-compositor.ts +380 -32
- package/plugins/kk/scripts/daily-cover-mock.ts +40 -3
- package/plugins/kk/scripts/daily-stages.ts +897 -34
- package/plugins/kk/scripts/episode-identity.ts +180 -0
- package/plugins/kk/scripts/kk-workflow-stages.ts +37 -1
- package/plugins/kk/scripts/music-stages.ts +624 -0
- package/plugins/kk/scripts/news-editorial-ledger.ts +906 -0
- package/plugins/kk/scripts/source-citation.ts +187 -0
- package/plugins/kk/scripts/topic-selection-attempts.ts +446 -0
- package/plugins/kk/scripts/topic-selection-calibration.ts +161 -0
- package/plugins/kk/skills/content-judge/SKILL.md +11 -6
- package/plugins/kk/skills/content-judge/references/music-quality-rubric.md +147 -0
- package/plugins/kk/skills/content-judge/references/rubrics.md +15 -0
- package/plugins/kk/skills/content-safety/SKILL.md +12 -0
- package/plugins/kk/skills/image-authoring/SKILL.md +7 -3
- package/plugins/kk/skills/image-authoring/references/providers.md +27 -0
- package/plugins/kk/skills/image-authoring/references/style-extraction.md +1 -1
- package/plugins/kk/skills/music-authoring/SKILL.md +276 -0
- package/plugins/kk/skills/music-authoring/references/judge-input.md +117 -0
- package/plugins/kk/skills/news-editorial/SKILL.md +102 -15
- package/plugins/kk/skills/news-editorial/references/selection.md +4 -0
- package/plugins/kk/skills/news-editorial/references/style-contract.zh.md +58 -11
- package/plugins/kk/skills/publish/SKILL.md +11 -0
- package/plugins/kk/skills/web-automation/SKILL.md +31 -1
- package/plugins/kk/workflows/kk-collect.yaml +8 -4
- package/plugins/kk/workflows/kk-daily-ai-voice.yaml +10 -9
- package/plugins/kk/workflows/kk-daily-ai-voice2.yaml +11 -9
- package/plugins/kk/workflows/kk-music.yaml +328 -0
- package/plugins/kk/workflows/kk-news-generate.yaml +58 -3
- package/plugins/publishings/bilibili-pub/dist/index.js +11 -1
- package/plugins/publishings/bilibili-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/cnblogs-pub/dist/index.js +11 -1
- package/plugins/publishings/cnblogs-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/csdn-pub/dist/index.js +11 -1
- package/plugins/publishings/csdn-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/infoq-pub/dist/index.js +11 -1
- package/plugins/publishings/infoq-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/jike-pub/dist/index.js +11 -1
- package/plugins/publishings/jike-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/juejin-pub/dist/index.js +11 -1
- package/plugins/publishings/juejin-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/linkedin-pub/dist/index.js +54 -7
- package/plugins/publishings/linkedin-pub/dist/profile-check.js +43 -6
- package/plugins/publishings/linkedin-pub/src/index.ts +52 -6
- package/plugins/publishings/podcast-pub/dist/index.js +586 -20
- package/plugins/publishings/podcast-pub/src/corrections.ts +509 -0
- package/plugins/publishings/podcast-pub/src/index.ts +257 -5
- package/plugins/publishings/podcast-pub/src/show-notes-brief.ts +240 -0
- package/plugins/publishings/podcast-pub/src/show-notes.ts +69 -13
- package/plugins/publishings/shipinhao-pub/dist/index.js +437 -32
- package/plugins/publishings/shipinhao-pub/dist/profile-check.js +14 -2
- package/plugins/publishings/shipinhao-pub/plugin.json +1 -1
- package/plugins/publishings/shipinhao-pub/src/audio-flow.ts +492 -0
- package/plugins/publishings/shipinhao-pub/src/flow.ts +227 -12
- package/plugins/publishings/shipinhao-pub/src/selectors.ts +13 -0
- package/plugins/publishings/sspai-pub/dist/index.js +11 -1
- package/plugins/publishings/sspai-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/substack-pub/dist/index.js +11 -1
- package/plugins/publishings/substack-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/surfdash-pub/dist/index.js +122 -28
- package/plugins/publishings/surfdash-pub/src/digest-check.ts +7 -3
- package/plugins/publishings/surfdash-pub/src/index.ts +159 -25
- package/plugins/publishings/surfdash-pub/src/topic-claims.ts +37 -4
- package/plugins/publishings/threads-pub/dist/index.js +9206 -296
- package/plugins/publishings/threads-pub/dist/profile-check.js +21149 -0
- package/plugins/publishings/threads-pub/package.json +3 -1
- package/plugins/publishings/threads-pub/plugin.json +6 -1
- package/plugins/publishings/threads-pub/src/index.ts +8 -1
- package/plugins/publishings/threads-pub/src/post-rail.ts +357 -0
- package/plugins/publishings/threads-pub/src/profile-check.ts +17 -0
- package/plugins/publishings/wechatmp-pub/dist/index.js +18 -1
- package/plugins/publishings/wechatmp-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/wechatmp-pub/src/flow.ts +13 -0
- package/plugins/publishings/weibo-pub/dist/index.js +57 -3
- package/plugins/publishings/weibo-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/weibo-pub/src/index.ts +74 -2
- package/plugins/publishings/x-pub/dist/index.js +274 -44
- package/plugins/publishings/x-pub/dist/profile-check.js +14 -2
- package/plugins/publishings/x-pub/src/index.ts +15 -1
- package/plugins/publishings/x-pub/src/post-rail.ts +334 -0
- package/plugins/publishings/xhs-pub/dist/index.js +11 -1
- package/plugins/publishings/xhs-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/xiaoyuzhou-pub/dist/index.js +11 -1
- package/plugins/publishings/xiaoyuzhou-pub/dist/profile-check.js +11 -1
|
@@ -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
|
|
@@ -304,18 +357,196 @@ function authoredPlanDescendants(workDir: string, runDate: string): string[] {
|
|
|
304
357
|
*/
|
|
305
358
|
const SPEAK_CHAR_EXPANSION = 1.4;
|
|
306
359
|
|
|
360
|
+
/**
|
|
361
|
+
* The cold-start ratio the PRE-SPEND widen decision uses, and it is deliberately not 1.4.
|
|
362
|
+
*
|
|
363
|
+
* The consumers need opposite safe directions (the same argument `scriptFloorCharRate` makes about
|
|
364
|
+
* the char rate): the reported arithmetic wants the typical ratio, while the pre-spend gates want
|
|
365
|
+
* the *worst measured* ratio, because a cheap error is a rung too many and the expensive one is an
|
|
366
|
+
* authoring pass the TTS gate then refuses.
|
|
367
|
+
*
|
|
368
|
+
* Measured spoken/kept-candidate ratios: 2026-10-11 1,270/1,800 = 0.71 and 5,925/4,300 = 1.38;
|
|
369
|
+
* 2026-11-15 run `kk-news-generate-20261115-1794773860762` 2,053/7,244 = 0.28. Treating 1.4 as the
|
|
370
|
+
* floor ratio let that day pass the gate at 32.6 min, spend a full authoring pass, then refuse at
|
|
371
|
+
* 6.2 min — and the ladder that exists to fill a thin day from the backlog never climbed a rung
|
|
372
|
+
* (0377).
|
|
373
|
+
*
|
|
374
|
+
* This constant is only the fallback: both gates prefer the ratio a previous run recorded, and the
|
|
375
|
+
* two records carry DIFFERENT denominators (see `readKeptRatio` — using one ratio for both was the
|
|
376
|
+
* 2026-11-16 refusal of a 23-min episode).
|
|
377
|
+
*/
|
|
378
|
+
const SPEAK_CHAR_EXPANSION_FLOOR = 0.28;
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* Where a run records the ratios it actually delivered (0377 R2/R3). Two denominators, because the
|
|
382
|
+
* two pre-spend consumers measure different sets: `ratio` is spoken/pool (the ladder, which judges
|
|
383
|
+
* the raw extracted pool) and `keptRatio` is spoken/kept-candidate chars (the floor gate, which
|
|
384
|
+
* judges what QC actually admitted). The gates read the newest record from the sibling run
|
|
385
|
+
* directories, so they judge today's material by what the writer really produced last time instead
|
|
386
|
+
* of a constant that was calibrated once.
|
|
387
|
+
*/
|
|
388
|
+
const SPOKEN_RATIO_SUFFIX = '_09_spoken-ratio.json';
|
|
389
|
+
|
|
390
|
+
/** The measured ratio one run delivered, and where it came from. */
|
|
391
|
+
interface SpokenRatio {
|
|
392
|
+
ratio: number;
|
|
393
|
+
source: string;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/** Clamp a recorded ratio into a plausible band: a corrupt file must not freeze or flood the ladder. */
|
|
397
|
+
function clampRatio(value: number): number {
|
|
398
|
+
return Math.min(2, Math.max(0.05, value));
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* The newest recorded spoken/raw ratio across this workflow's run directories, or the calibrated
|
|
403
|
+
* floor constant when no run has recorded one yet. `workDir` is one run directory, so its parent is
|
|
404
|
+
* the workflow directory the sibling runs live in.
|
|
405
|
+
*/
|
|
406
|
+
function readSpokenRatio(workDir: string): SpokenRatio {
|
|
407
|
+
const base = resolve(workDir, '..');
|
|
408
|
+
let newest: { at: number; ratio: number; from: string } | null = null;
|
|
409
|
+
let entries: string[] = [];
|
|
410
|
+
try {
|
|
411
|
+
entries = readdirSync(base);
|
|
412
|
+
} catch {
|
|
413
|
+
return { ratio: SPEAK_CHAR_EXPANSION_FLOOR, source: 'default 0.28 (no sibling runs)' };
|
|
414
|
+
}
|
|
415
|
+
for (const entry of entries) {
|
|
416
|
+
const dir = join(base, entry, '21-plan');
|
|
417
|
+
let files: string[] = [];
|
|
418
|
+
try {
|
|
419
|
+
files = readdirSync(dir).filter((file) => file.endsWith(SPOKEN_RATIO_SUFFIX));
|
|
420
|
+
} catch {
|
|
421
|
+
continue;
|
|
422
|
+
}
|
|
423
|
+
for (const file of files) {
|
|
424
|
+
const path = join(dir, file);
|
|
425
|
+
try {
|
|
426
|
+
const parsed = readJson(path) as Record<string, unknown> | null;
|
|
427
|
+
const ratio = Number(parsed?.ratio);
|
|
428
|
+
if (!Number.isFinite(ratio) || ratio <= 0) continue;
|
|
429
|
+
const at = statSync(path).mtimeMs;
|
|
430
|
+
if (newest === null || at > newest.at) newest = { at, ratio, from: path };
|
|
431
|
+
} catch {
|
|
432
|
+
// A malformed record is not evidence; the next run overwrites it.
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
if (newest === null) return { ratio: SPEAK_CHAR_EXPANSION_FLOOR, source: 'default 0.28 (no recorded run)' };
|
|
437
|
+
return { ratio: clampRatio(newest.ratio), source: `${newest.from} (${newest.ratio.toFixed(2)}x)` };
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* The newest recorded spoken/KEPT ratio across sibling runs, or the cold-start constant.
|
|
442
|
+
*
|
|
443
|
+
* WHY this is separate from `readSpokenRatio` (2026-11-16): one constant was applied to two
|
|
444
|
+
* different denominators. The ladder multiplies the raw pool (38,241 chars that day) while this gate
|
|
445
|
+
* multiplies the kept candidates (13,963 chars — planning admitted 37% of the pool), so the same
|
|
446
|
+
* 0.28 read as a 34.5 min "clears" in the ladder and a 12.7 min "refusing" at the gate, and the run
|
|
447
|
+
* paid for the planning pass to discover it. The writer then delivered 7,194 spoken chars ≈ 23 min:
|
|
448
|
+
* the refusal discounted the planning shrink twice. `keptRatio` for that run is 0.515.
|
|
449
|
+
*/
|
|
450
|
+
function readKeptRatio(workDir: string): SpokenRatio {
|
|
451
|
+
const base = resolve(workDir, '..');
|
|
452
|
+
let newest: { at: number; ratio: number; from: string } | null = null;
|
|
453
|
+
let entries: string[] = [];
|
|
454
|
+
try {
|
|
455
|
+
entries = readdirSync(base);
|
|
456
|
+
} catch {
|
|
457
|
+
return { ratio: SPEAK_CHAR_EXPANSION_FLOOR, source: 'default 0.28 (no sibling runs)' };
|
|
458
|
+
}
|
|
459
|
+
for (const entry of entries) {
|
|
460
|
+
const dir = join(base, entry, '21-plan');
|
|
461
|
+
let files: string[] = [];
|
|
462
|
+
try {
|
|
463
|
+
files = readdirSync(dir).filter((file) => file.endsWith(SPOKEN_RATIO_SUFFIX));
|
|
464
|
+
} catch {
|
|
465
|
+
continue;
|
|
466
|
+
}
|
|
467
|
+
for (const file of files) {
|
|
468
|
+
const path = join(dir, file);
|
|
469
|
+
try {
|
|
470
|
+
const parsed = readJson(path) as Record<string, unknown> | null;
|
|
471
|
+
// A pre-2026-11-16 record carries no kept ratio at all: skip it rather than divide by
|
|
472
|
+
// its pool figure, which is what produced the double discount.
|
|
473
|
+
const ratio = Number(parsed?.keptRatio);
|
|
474
|
+
if (!Number.isFinite(ratio) || ratio <= 0) continue;
|
|
475
|
+
const at = statSync(path).mtimeMs;
|
|
476
|
+
if (newest === null || at > newest.at) newest = { at, ratio, from: path };
|
|
477
|
+
} catch {
|
|
478
|
+
// A malformed record is not evidence; the next run overwrites it.
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
if (newest === null) return { ratio: SPEAK_CHAR_EXPANSION_FLOOR, source: 'default 0.28 (no recorded kept ratio)' };
|
|
483
|
+
return { ratio: clampRatio(newest.ratio), source: `${newest.from} (${newest.ratio.toFixed(2)}x)` };
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
/**
|
|
487
|
+
* Record what this run delivered — spoken script chars over raw pool chars, and over the kept
|
|
488
|
+
* candidates — and warn when it drifted from the ratio the widen decision used. A refused script
|
|
489
|
+
* records too: a thin day teaches the ladder even though it produced no episode.
|
|
490
|
+
*/
|
|
491
|
+
function recordSpokenRatio(workDir: string, runDate: string, spokenChars: number): void {
|
|
492
|
+
const poolPath = join(workDir, '10-collect', 'pool.json');
|
|
493
|
+
if (!isFile(poolPath)) return;
|
|
494
|
+
const pool = readJson(poolPath);
|
|
495
|
+
const poolChars = rawChars(Array.isArray(pool) ? pool : []);
|
|
496
|
+
if (poolChars <= 0) return;
|
|
497
|
+
// The admitted set the floor gate measures, so the next pre-spend estimate discounts the planning
|
|
498
|
+
// shrink once instead of twice (2026-11-16).
|
|
499
|
+
const keptPath = join(workDir, '21-plan', `${runDate}_04_quality-control-content_candidates.json`);
|
|
500
|
+
const keptChars = isFile(keptPath) ? rawChars(metadataOf(readJson(keptPath)).docs ?? []) : 0;
|
|
501
|
+
const round3 = (value: number): number => Math.round(value * 1000) / 1000;
|
|
502
|
+
const ratio = round3(spokenChars / poolChars);
|
|
503
|
+
const out = join(workDir, '21-plan', `${runDate}${SPOKEN_RATIO_SUFFIX}`);
|
|
504
|
+
mkdirSync(join(workDir, '21-plan'), { recursive: true });
|
|
505
|
+
writeJsonText(out, {
|
|
506
|
+
runDate,
|
|
507
|
+
poolChars,
|
|
508
|
+
...(keptChars > 0 ? { keptChars, keptRatio: round3(spokenChars / keptChars) } : {}),
|
|
509
|
+
spokenChars,
|
|
510
|
+
ratio,
|
|
511
|
+
});
|
|
512
|
+
// Drift warning: the ladder judged this pool with some ratio; the writer just delivered a
|
|
513
|
+
// different one. A wide gap means the next run's ladder is working from a stale measure.
|
|
514
|
+
let used: number | null = null;
|
|
515
|
+
try {
|
|
516
|
+
const ladder = readJson(join(workDir, '10-collect', 'ladder.json')) as Record<string, unknown> | null;
|
|
517
|
+
const candidate = Number(ladder?.ratioUsed);
|
|
518
|
+
if (Number.isFinite(candidate) && candidate > 0) used = candidate;
|
|
519
|
+
} catch {
|
|
520
|
+
used = null;
|
|
521
|
+
}
|
|
522
|
+
if (used !== null && Math.abs(ratio / used - 1) > 0.25) {
|
|
523
|
+
console.error(
|
|
524
|
+
`spoken ratio drifted: this run delivered ${ratio.toFixed(2)}x of the pool, the ladder widened on ${used.toFixed(2)}x (see ${out})`,
|
|
525
|
+
);
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
/** Title+body characters of a Doc[] — the raw measure every spoken ratio here divides into. */
|
|
530
|
+
function rawChars(docs: unknown[]): number {
|
|
531
|
+
return docs.reduce((sum, doc) => {
|
|
532
|
+
const entry = (doc ?? {}) as Record<string, unknown>;
|
|
533
|
+
return sum + `${String(entry.title ?? '')}`.length + String(entry.body ?? '').length;
|
|
534
|
+
}, 0);
|
|
535
|
+
}
|
|
536
|
+
|
|
307
537
|
/**
|
|
308
538
|
* The calibrated pre-spend estimate over a kept pool (title+body characters × the 1.4 expansion,
|
|
309
539
|
* over the driver's measured char rate, plus the 8 s intro sting) — shared by the pre-spend floor
|
|
310
540
|
* gate (applyFloorGate) and the post-spend duration refusal (dailyEpisodeDuration, 0266), so both
|
|
311
541
|
* artifacts report the same arithmetic. `seconds` is unrounded: the floor gate compares seconds.
|
|
312
542
|
*/
|
|
313
|
-
function estimateSpokenMinutes(
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
const
|
|
543
|
+
function estimateSpokenMinutes(
|
|
544
|
+
docs: unknown[],
|
|
545
|
+
vdriver: string,
|
|
546
|
+
expansion: number = SPEAK_CHAR_EXPANSION,
|
|
547
|
+
): { minutes: number; seconds: number; chars: number } {
|
|
548
|
+
const chars = rawChars(docs);
|
|
549
|
+
const seconds = 8 + (chars * expansion) / spokenCharRate(vdriver);
|
|
319
550
|
return { minutes: Math.round((seconds / 60) * 10) / 10, seconds, chars };
|
|
320
551
|
}
|
|
321
552
|
|
|
@@ -329,6 +560,10 @@ function estimateSpokenMinutes(docs: unknown[], vdriver: string): { minutes: num
|
|
|
329
560
|
* `pool-count --min 1` guard then skips the content, audio, publish and XHS subtrees, and the run
|
|
330
561
|
* closes through run-report and the ledger exactly like an empty pool. The estimate and its inputs
|
|
331
562
|
* land in a refusal artifact next to the candidates.
|
|
563
|
+
*
|
|
564
|
+
* The ratio comes from `readKeptRatio`, NOT the pool-denominated one the ladder uses: this gate
|
|
565
|
+
* measures the admitted set, and applying the pool ratio to it discounted the planning shrink twice
|
|
566
|
+
* (2026-11-16: estimated 12.7 min, the writer delivered 23).
|
|
332
567
|
*/
|
|
333
568
|
function applyFloorGate(
|
|
334
569
|
candidates: string,
|
|
@@ -350,19 +585,37 @@ function applyFloorGate(
|
|
|
350
585
|
if (clearStaleRefusal && isFile(refusal)) unlinkSync(refusal);
|
|
351
586
|
return;
|
|
352
587
|
}
|
|
353
|
-
const
|
|
588
|
+
const keptRatio = readKeptRatio(workDir);
|
|
589
|
+
const {
|
|
590
|
+
minutes: estimatedMinutes,
|
|
591
|
+
seconds: estimatedSeconds,
|
|
592
|
+
chars,
|
|
593
|
+
} = estimateSpokenMinutes(docs, vdriver, keptRatio.ratio);
|
|
354
594
|
if (estimatedSeconds >= floor * 60) {
|
|
355
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
|
+
});
|
|
356
601
|
console.log(`floor gate: estimated ${estimatedMinutes} min from ${chars} chars — above the ${floor} min floor`);
|
|
357
602
|
return;
|
|
358
603
|
}
|
|
359
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
|
+
});
|
|
360
610
|
sted('write', refusal, () =>
|
|
361
611
|
writeJqText(refusal, {
|
|
362
612
|
estimatedMinutes,
|
|
363
613
|
minMinutes: floor,
|
|
364
614
|
candidateChars: chars,
|
|
365
|
-
|
|
615
|
+
// The ratio this refusal actually used, and where it came from (0377; 2026-11-16): the
|
|
616
|
+
// gate measures the KEPT set, so a pool-denominated ratio under-predicts it badly.
|
|
617
|
+
expansion: keptRatio.ratio,
|
|
618
|
+
expansionSource: keptRatio.source,
|
|
366
619
|
charRate: spokenCharRate(vdriver),
|
|
367
620
|
ids,
|
|
368
621
|
reason: `a ${docs.length}-item pool estimates ${estimatedMinutes} min of speech, below the ${floor} min floor — refusing before any TTS spend`,
|
|
@@ -445,29 +698,104 @@ export function dailyExtract(args: string[]): void {
|
|
|
445
698
|
console.error(`extract: plan already authored — keeping the frozen pool (${poolPath})`);
|
|
446
699
|
return;
|
|
447
700
|
}
|
|
701
|
+
// 0377 R2: judge the pool by what the writer actually delivered last time. The calibrated
|
|
702
|
+
// 0.28 constant is only the fallback for a workflow that has never recorded a ratio.
|
|
703
|
+
const ratio = readSpokenRatio(workDir);
|
|
448
704
|
let chosen: { window: string; docs: unknown[] } | null = null;
|
|
705
|
+
const rungs: Array<{ window: string; items: number; chars: number; minutes: number; clears: boolean }> = [];
|
|
449
706
|
for (const ms of windows) {
|
|
450
707
|
const label = formatWindowMs(ms);
|
|
451
708
|
const attempt = join(workDir, '10-collect', `.pool-${label}.json`);
|
|
452
709
|
kk(['store', 'extract', '--topic', topic, '--window', label, '--out', attempt]);
|
|
453
710
|
const parsed = readJson(attempt);
|
|
454
711
|
const docs = Array.isArray(parsed) ? (parsed as unknown[]) : [];
|
|
455
|
-
const estimate = estimateSpokenMinutes(docs, vdriver);
|
|
712
|
+
const estimate = estimateSpokenMinutes(docs, vdriver, ratio.ratio);
|
|
713
|
+
const clears = estimate.seconds >= floor * 60;
|
|
714
|
+
rungs.push({ window: label, items: docs.length, chars: estimate.chars, minutes: estimate.minutes, clears });
|
|
456
715
|
chosen = { window: label, docs };
|
|
457
716
|
const verdict = gated
|
|
458
|
-
? `estimated ${estimate.minutes} min
|
|
717
|
+
? `estimated ${estimate.minutes} min at ${ratio.ratio.toFixed(2)}x — ${clears ? 'clears' : 'below'} the ${floor} min floor`
|
|
459
718
|
: 'floor gate off';
|
|
460
719
|
console.error(`extract: ${label} pool ${docs.length} item(s), ${verdict}`);
|
|
461
|
-
if (!gated ||
|
|
720
|
+
if (!gated || clears) break;
|
|
462
721
|
rmSync(attempt, { force: true });
|
|
463
722
|
}
|
|
464
723
|
const picked = chosen ?? { window: formatWindowMs(base), docs: [] as unknown[] };
|
|
724
|
+
// 0377 R3: the decision is an artifact, not just a stderr line — the run report and
|
|
725
|
+
// `kk news status` read which measure drove it, the rung chosen and the estimate at each rung.
|
|
726
|
+
sted('write', join(workDir, '10-collect', 'ladder.json'), () =>
|
|
727
|
+
writeJsonText(join(workDir, '10-collect', 'ladder.json'), {
|
|
728
|
+
floorMinutes: gated ? floor : null,
|
|
729
|
+
ratioUsed: ratio.ratio,
|
|
730
|
+
ratioSource: ratio.source,
|
|
731
|
+
chosen: picked.window,
|
|
732
|
+
rungs,
|
|
733
|
+
}),
|
|
734
|
+
);
|
|
465
735
|
sted('write', poolPath, () => writeJsonText(poolPath, picked.docs));
|
|
466
736
|
for (const ms of windows)
|
|
467
737
|
rmSync(join(workDir, '10-collect', `.pool-${formatWindowMs(ms)}.json`), { force: true });
|
|
468
738
|
});
|
|
469
739
|
}
|
|
470
740
|
|
|
741
|
+
/**
|
|
742
|
+
* 0385 R4: the one frozen episode identity a bundle ships, read from the Content provenance first
|
|
743
|
+
* (a retry or a replay republishes what the episode already carried) and from the slot
|
|
744
|
+
* `daily-editorial-render` freezes second. `null` means "no identity recorded" — the caller leaves
|
|
745
|
+
* whatever title the artifact already has.
|
|
746
|
+
*/
|
|
747
|
+
function episodeIdentityFor(workDir: string, runDate: string, content: unknown): EpisodeIdentity | null {
|
|
748
|
+
return (
|
|
749
|
+
identityFromMetadata(metadataOf(content)) ??
|
|
750
|
+
identityFromMetadata({
|
|
751
|
+
[EPISODE_IDENTITY_KEY]: readJson(join(workDir, '21-plan', `${runDate}_05_script_identity.json`)),
|
|
752
|
+
})
|
|
753
|
+
);
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
/**
|
|
757
|
+
* 0385 R4: stamp the frozen title into one article Content — `title`, the H1 of the body, and the
|
|
758
|
+
* `metadata.episodeIdentity` record every later target reads. A withheld identity (`title: null`)
|
|
759
|
+
* leaves the Content untouched: there is no title to share, and inventing one is the bug.
|
|
760
|
+
*
|
|
761
|
+
* Both articles seams call this — `daily-article` after it derives (first run) and
|
|
762
|
+
* `daily-editorial-render` after the body is rewritten (retry) — so the stamp cannot be a no-op on
|
|
763
|
+
* one order and be wiped on the other.
|
|
764
|
+
*/
|
|
765
|
+
function stampEpisodeIdentity(articleContentPath: string, identity: EpisodeIdentity): boolean {
|
|
766
|
+
if (identity.title === null) return false;
|
|
767
|
+
const articleContent = readJson(articleContentPath);
|
|
768
|
+
if (articleContent === null) return false;
|
|
769
|
+
const priorBody = typeof articleContent.body === 'string' ? articleContent.body : '';
|
|
770
|
+
const body = priorBody.replace(/^#(?!#)[^\n]*/u, `# ${identity.title}`);
|
|
771
|
+
sted('write', articleContentPath, () =>
|
|
772
|
+
writeJsonText(articleContentPath, {
|
|
773
|
+
...articleContent,
|
|
774
|
+
title: identity.title,
|
|
775
|
+
body,
|
|
776
|
+
metadata: { ...metadataOf(articleContent), [EPISODE_IDENTITY_KEY]: identity },
|
|
777
|
+
}),
|
|
778
|
+
);
|
|
779
|
+
return true;
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
/**
|
|
783
|
+
* 0385 R4: the article seam's one entry point — read the bundle's frozen identity for this run and
|
|
784
|
+
* stamp it into the article Content. `daily-article` calls it right after it derives the Content
|
|
785
|
+
* (first run) and after a `proseStale` re-derivation (retry), which is the only thing that keeps the
|
|
786
|
+
* stamp `daily-editorial-render` wrote from being wiped. Returns the identity it applied (or null).
|
|
787
|
+
*/
|
|
788
|
+
export function applyEpisodeIdentityToArticle(
|
|
789
|
+
workDir: string,
|
|
790
|
+
runDate: string,
|
|
791
|
+
articleContentPath: string,
|
|
792
|
+
): EpisodeIdentity | null {
|
|
793
|
+
const identity = episodeIdentityFor(workDir, runDate, readJson(articleContentPath));
|
|
794
|
+
if (identity === null) return null;
|
|
795
|
+
stampEpisodeIdentity(articleContentPath, identity);
|
|
796
|
+
return identity;
|
|
797
|
+
}
|
|
798
|
+
|
|
471
799
|
export function dailyArticle(args: string[]): void {
|
|
472
800
|
const [workDir = '', runDate = '', pluginsPath = ''] = args;
|
|
473
801
|
const articleMd = join(workDir, '22-article', `${runDate}_06_article_article.md`);
|
|
@@ -564,6 +892,11 @@ export function dailyArticle(args: string[]): void {
|
|
|
564
892
|
},
|
|
565
893
|
},
|
|
566
894
|
);
|
|
895
|
+
// 0385 R4: `generate-render` order is script → editorial-render → article → cover, so this
|
|
896
|
+
// is the FIRST seam where the Content exists; `daily-editorial-render`'s own stamp would be a
|
|
897
|
+
// no-op here. Stamping now — and re-stamping here after a `proseStale` re-derivation — is what
|
|
898
|
+
// keeps the article (surfdash) and the show notes on the same frozen title as podcast/ID3.
|
|
899
|
+
applyEpisodeIdentityToArticle(workDir, runDate, articleContent);
|
|
567
900
|
const body = readJson(articleContent)?.body;
|
|
568
901
|
if (typeof body !== 'string') failWith(1, `article: ${articleContent} has no string body`);
|
|
569
902
|
sted('write', articleMd, () => writeRaw(articleMd, body));
|
|
@@ -1072,6 +1405,9 @@ export function dailyGenerate(args: string[]): void {
|
|
|
1072
1405
|
);
|
|
1073
1406
|
const charRate = scriptFloorCharRate(vdriver);
|
|
1074
1407
|
const seconds = 8 + chars / charRate;
|
|
1408
|
+
// Record what the writer delivered before judging it: a refused day still teaches the
|
|
1409
|
+
// next run's ladder what this pool really yielded (0377 R2/R3).
|
|
1410
|
+
recordSpokenRatio(workDir, runDate, chars);
|
|
1075
1411
|
if (seconds < minMinutes * 60) {
|
|
1076
1412
|
refuseScriptBelowFloor(workDir, runDate, { chars, charRate, seconds, minMinutes });
|
|
1077
1413
|
return;
|
|
@@ -1704,7 +2040,12 @@ const WECHAT_OUTRO = '\n\n欲听往期节目,可至小宇宙、Apple Podcast
|
|
|
1704
2040
|
/** The brand strings this daily show pins on every 公众号 draft. */
|
|
1705
2041
|
const WECHAT_BRAND = {
|
|
1706
2042
|
author: '冰原奔狼',
|
|
1707
|
-
|
|
2043
|
+
// WX-03 (verified 2026-11-11): 《标识办法》第十条 + 微信 2025-08-31 公告 make the AI-generation
|
|
2044
|
+
// declaration a publish-time metadata duty, and 创作来源 is that declaration entry. The stance
|
|
2045
|
+
// label (`个人观点,仅供参考`, the 2026-10-10 choice) declares nothing about AI generation, so the
|
|
2046
|
+
// variants safety gate blocked every daily run (2026-11-19). The article is AI-drafted and the
|
|
2047
|
+
// audio is AI-synthesized; declare it. The field is single-select — one label per draft.
|
|
2048
|
+
claimSource: '内容由AI生成',
|
|
1708
2049
|
coverSource: 'library',
|
|
1709
2050
|
} as const;
|
|
1710
2051
|
|
|
@@ -1738,7 +2079,7 @@ export function buildWechatArticleContent(
|
|
|
1738
2079
|
reward: true,
|
|
1739
2080
|
author: WECHAT_BRAND.author,
|
|
1740
2081
|
collection: options.collection,
|
|
1741
|
-
// 创作来源 is the
|
|
2082
|
+
// 创作来源 is the platform's AI-declaration entry (WX-03); the label declares AI generation.
|
|
1742
2083
|
claimSource: WECHAT_BRAND.claimSource,
|
|
1743
2084
|
// 封面 comes from 图片库: the episode cover is uploaded there as the audio material's cover.
|
|
1744
2085
|
coverSource: WECHAT_BRAND.coverSource,
|
|
@@ -1843,21 +2184,46 @@ export function buildPodcastContent(
|
|
|
1843
2184
|
* (surfdash-pub/src/index.ts), so the run's cover rides along exactly as the episode/wechat
|
|
1844
2185
|
* builders stamp it. voice2's prepare mode never exercised this gate; the frozen-bundle matrix
|
|
1845
2186
|
* send surfaced it on 2026-11-05 (empty run → 'digest post has no cover image').
|
|
2187
|
+
*
|
|
2188
|
+
* 0409: `metadata.surfdash.locales` carries the en/ja translations the localize step wrote, so the
|
|
2189
|
+
* frozen variant — and therefore the safety review and the freeze digest — covers them. They are
|
|
2190
|
+
* read from the files at variant-build time so the variant is the single source the publisher reads.
|
|
1846
2191
|
*/
|
|
1847
2192
|
export function buildSurfdashContent(
|
|
1848
2193
|
article: Record<string, unknown>,
|
|
1849
2194
|
_links: PublishLinks,
|
|
1850
|
-
options: { coverPath?: string } = {},
|
|
2195
|
+
options: { coverPath?: string; locales?: Partial<Record<'en' | 'ja', { title: string; body: string }>> } = {},
|
|
1851
2196
|
): Record<string, unknown> {
|
|
1852
2197
|
return {
|
|
1853
2198
|
...article,
|
|
1854
2199
|
metadata: {
|
|
1855
2200
|
...metadataOf(article),
|
|
1856
2201
|
...(options.coverPath === undefined ? {} : { coverImage: options.coverPath }),
|
|
2202
|
+
...(options.locales === undefined ? {} : { surfdash: { locales: options.locales } }),
|
|
1857
2203
|
},
|
|
1858
2204
|
};
|
|
1859
2205
|
}
|
|
1860
2206
|
|
|
2207
|
+
/**
|
|
2208
|
+
* Reads `${workDir}/22-article/locales/{en,ja}.md` (first line `# <title>`, rest the body) into the
|
|
2209
|
+
* payload shape `surfdash-pub` consumes. A locale whose file is missing or untitled is simply
|
|
2210
|
+
* absent — `news-localize-validate` is the gate that refuses it, and the publisher refuses a digest
|
|
2211
|
+
* payload that lacks one, so silent partial data never reaches a live publish.
|
|
2212
|
+
*/
|
|
2213
|
+
function readArticleLocales(workDir: string): Partial<Record<'en' | 'ja', { title: string; body: string }>> {
|
|
2214
|
+
const locales: Partial<Record<'en' | 'ja', { title: string; body: string }>> = {};
|
|
2215
|
+
for (const locale of ['en', 'ja'] as const) {
|
|
2216
|
+
const file = join(workDir, '22-article', 'locales', `${locale}.md`);
|
|
2217
|
+
if (!isFile(file)) continue;
|
|
2218
|
+
const [firstLine = '', ...rest] = readFileSync(file, 'utf-8').split('\n');
|
|
2219
|
+
const title = firstLine.startsWith('# ') ? firstLine.slice(2).trim() : '';
|
|
2220
|
+
const body = rest.join('\n').trim();
|
|
2221
|
+
if (title === '' || body === '') continue;
|
|
2222
|
+
locales[locale] = { title, body };
|
|
2223
|
+
}
|
|
2224
|
+
return locales;
|
|
2225
|
+
}
|
|
2226
|
+
|
|
1861
2227
|
/**
|
|
1862
2228
|
* One channel's short copy as a Content (task 0327 R3): the body is the authored post text and the
|
|
1863
2229
|
* episode cover rides along as `metadata.coverImage`.
|
|
@@ -1954,6 +2320,8 @@ const SOCIAL_LIMITS: Record<string, SocialLimit> = {
|
|
|
1954
2320
|
x: { max: 280, weighted: true },
|
|
1955
2321
|
weibo: { max: 2000 },
|
|
1956
2322
|
threads: { max: 500 },
|
|
2323
|
+
// 即刻's 动态 composer accepts long text; the shared short notice fits far below this.
|
|
2324
|
+
jike: { max: 2000 },
|
|
1957
2325
|
linkedin: { max: 3000 },
|
|
1958
2326
|
};
|
|
1959
2327
|
|
|
@@ -2007,11 +2375,29 @@ export function dailyBundleVariants(args: string[]): void {
|
|
|
2007
2375
|
|
|
2008
2376
|
// Generic variants first: a channel-specific variant wins over the shared one, so the
|
|
2009
2377
|
// shared copy must exist for the channels the preset does not specialise.
|
|
2378
|
+
const firstArticleLine =
|
|
2379
|
+
article !== null && typeof (article as Record<string, unknown>).title === 'string'
|
|
2380
|
+
? String((article as Record<string, unknown>).title)
|
|
2381
|
+
: '';
|
|
2010
2382
|
if (article === null) skipped.push('article (no 22-article content)');
|
|
2011
2383
|
else {
|
|
2012
|
-
|
|
2013
|
-
|
|
2384
|
+
// 0409: the frozen variant carries the en/ja translations, so the safety review and the
|
|
2385
|
+
// freeze digest cover them and the publisher writes what was reviewed.
|
|
2386
|
+
const articleLocales = readArticleLocales(workDir);
|
|
2387
|
+
const articleOptions = {
|
|
2388
|
+
coverPath: cover,
|
|
2389
|
+
...(Object.keys(articleLocales).length > 0 ? { locales: articleLocales } : {}),
|
|
2390
|
+
};
|
|
2391
|
+
write('article', buildSurfdashContent(article, links, articleOptions));
|
|
2392
|
+
write('article@surfdash-pub', buildSurfdashContent(article, links, articleOptions));
|
|
2014
2393
|
write('article@xhs-pub', buildXhsArticleContent(article, { publishStatus: 'draft' }));
|
|
2394
|
+
// The article carries the episode audio at the top (operator request 2026-11-15): the
|
|
2395
|
+
// 公众号 播客 row is off, so without this the MP draft had no player at all. Same source
|
|
2396
|
+
// as the episode variant — `publish-prep`'s rendered mp3 — so one episode has one audio.
|
|
2397
|
+
const articleAudio =
|
|
2398
|
+
prep !== null && typeof metadataOf(prep).audioFile === 'string'
|
|
2399
|
+
? String(metadataOf(prep).audioFile)
|
|
2400
|
+
: undefined;
|
|
2015
2401
|
write(
|
|
2016
2402
|
'article@wechatmp-pub',
|
|
2017
2403
|
buildWechatArticleContent(article, {
|
|
@@ -2019,6 +2405,7 @@ export function dailyBundleVariants(args: string[]): void {
|
|
|
2019
2405
|
publishStatus: 'draft',
|
|
2020
2406
|
collection: '每日AI资讯',
|
|
2021
2407
|
...(cover === undefined ? {} : { coverPath: cover }),
|
|
2408
|
+
...(articleAudio === undefined ? {} : { audioPath: articleAudio, audioTitle: firstArticleLine }),
|
|
2022
2409
|
}),
|
|
2023
2410
|
);
|
|
2024
2411
|
}
|
|
@@ -2204,6 +2591,45 @@ function planItemsForPodcast(workDir: string, runDate: string): Array<{ title: s
|
|
|
2204
2591
|
return items;
|
|
2205
2592
|
}
|
|
2206
2593
|
|
|
2594
|
+
/**
|
|
2595
|
+
* 0396 R2 — the other channels' dispatch rows, shaped for podcast-pub's delivery classifier.
|
|
2596
|
+
*
|
|
2597
|
+
* Read from the 0388 ledger (the authority on what was dispatched for this frozen date). Capability
|
|
2598
|
+
* is deliberately NOT asserted: an unknown content surface must surface as `unsupported` with its
|
|
2599
|
+
* documented reason rather than a delivery nobody verified.
|
|
2600
|
+
*/
|
|
2601
|
+
export function correctionTargetRows(ledgerPath: string): Array<Record<string, unknown>> {
|
|
2602
|
+
const ledger = readJson(ledgerPath);
|
|
2603
|
+
const entries =
|
|
2604
|
+
ledger !== null && Array.isArray((ledger as { entries?: unknown }).entries)
|
|
2605
|
+
? ((ledger as { entries: unknown[] }).entries as Array<Record<string, unknown>>)
|
|
2606
|
+
: [];
|
|
2607
|
+
const rows: Array<Record<string, unknown>> = [];
|
|
2608
|
+
for (const entry of entries) {
|
|
2609
|
+
// The 0388 ledger keys a row by `id` (`plugin[@operation]`) with `plugin` beside it — NOT by a
|
|
2610
|
+
// `target` field. Reading a non-existent field silently produced zero rows and made this whole
|
|
2611
|
+
// seam inert (0396 review), so the id is the identity here and `plugin` is the fallback.
|
|
2612
|
+
// The self row is identified by PLUGIN, not by id: the writer keys an entry as
|
|
2613
|
+
// `plugin.operation` (`podcast-pub.episode`), so comparing the id let the podcast's own row
|
|
2614
|
+
// through and the operator saw a "not delivered to podcast-pub.episode" warning for the target
|
|
2615
|
+
// that actually received it (0396 review).
|
|
2616
|
+
const plugin = typeof entry?.plugin === 'string' ? entry.plugin.trim() : '';
|
|
2617
|
+
const id = typeof entry?.id === 'string' ? entry.id.trim() : '';
|
|
2618
|
+
const target = id !== '' ? id : plugin;
|
|
2619
|
+
if (plugin === 'podcast-pub' || target === '' || target === 'podcast-pub') continue;
|
|
2620
|
+
const blockedBy = Array.isArray(entry.blockedBy) ? entry.blockedBy.filter((id) => typeof id === 'string') : [];
|
|
2621
|
+
rows.push({
|
|
2622
|
+
target,
|
|
2623
|
+
...(typeof entry.state === 'string' ? { state: entry.state } : {}),
|
|
2624
|
+
...(typeof entry.mode === 'string' ? { mode: entry.mode } : {}),
|
|
2625
|
+
...(typeof entry.manualStep === 'string' ? { manualStep: entry.manualStep } : {}),
|
|
2626
|
+
...(typeof entry.lastError === 'string' ? { lastError: entry.lastError } : {}),
|
|
2627
|
+
...(blockedBy.length > 0 ? { blockedBy } : {}),
|
|
2628
|
+
});
|
|
2629
|
+
}
|
|
2630
|
+
return rows;
|
|
2631
|
+
}
|
|
2632
|
+
|
|
2207
2633
|
export function dailyPublishPodcast(args: string[]): void {
|
|
2208
2634
|
const [workDir = '', runDate = '', pluginsPath = ''] = args;
|
|
2209
2635
|
const prep = join(workDir, '31-publish', `${runDate}_13_publish-prep_content.json`);
|
|
@@ -2234,6 +2660,18 @@ export function dailyPublishPodcast(args: string[]): void {
|
|
|
2234
2660
|
showNotes,
|
|
2235
2661
|
...(Object.keys(podcast).length > 0 ? { podcast } : {}),
|
|
2236
2662
|
});
|
|
2663
|
+
// 0396 R2: the plugin records a delivery per TARGET, so the dispatch state of the other
|
|
2664
|
+
// channels has to reach it. The prep file's top-level `options` IS the channel the plugin
|
|
2665
|
+
// documents, and the 0388 ledger is the authority on those rows — no capability is
|
|
2666
|
+
// asserted here, so an unknown surface comes back as `unsupported` with its exact reason
|
|
2667
|
+
// instead of a claimed delivery.
|
|
2668
|
+
const siblingTargets = correctionTargetRows(join(workDir, '4-publish', 'dispatch-ledger.json'));
|
|
2669
|
+
if (siblingTargets.length > 0) {
|
|
2670
|
+
merged.options = {
|
|
2671
|
+
...((merged.options as Record<string, unknown>) ?? {}),
|
|
2672
|
+
correctionTargets: siblingTargets,
|
|
2673
|
+
};
|
|
2674
|
+
}
|
|
2237
2675
|
sted('write', prep, () => writeJsonText(prep, merged));
|
|
2238
2676
|
kk(
|
|
2239
2677
|
[
|
|
@@ -2250,6 +2688,22 @@ export function dailyPublishPodcast(args: string[]): void {
|
|
|
2250
2688
|
{
|
|
2251
2689
|
unset: ['SPUR_WORKFLOW_RUN_ACTIVE'],
|
|
2252
2690
|
soft: true,
|
|
2691
|
+
// 0396 R1: the publish dispatch is where a correction's delivery is REAL, so the
|
|
2692
|
+
// frozen snapshot rides with it too. Without this the per-target delivery record
|
|
2693
|
+
// could never be written by a production run (only the show-notes render saw the
|
|
2694
|
+
// snapshot). `kk executor fan-out` exposes no options channel, so the env is the
|
|
2695
|
+
// seam the plugin already documents.
|
|
2696
|
+
env: {
|
|
2697
|
+
...(isFile(join(workDir, '21-plan', `${runDate}_judgment-snapshot.json`))
|
|
2698
|
+
? {
|
|
2699
|
+
PODCAST_PUB_CORRECTIONS: join(
|
|
2700
|
+
workDir,
|
|
2701
|
+
'21-plan',
|
|
2702
|
+
`${runDate}_judgment-snapshot.json`,
|
|
2703
|
+
),
|
|
2704
|
+
}
|
|
2705
|
+
: {}),
|
|
2706
|
+
},
|
|
2253
2707
|
},
|
|
2254
2708
|
);
|
|
2255
2709
|
} catch (error) {
|
|
@@ -2270,6 +2724,24 @@ export function dailyPublishPrep(args: string[]): void {
|
|
|
2270
2724
|
const coverPath = join(workDir, '23-cover', `${runDate}_07_cover_cover.png`);
|
|
2271
2725
|
timed(workDir, 'publish-prep', () => {
|
|
2272
2726
|
const article = requireJson(articlePath, 'publish-prep');
|
|
2727
|
+
// 0385 R4: the last seam before anything is dispatched is also the seam that proves the whole
|
|
2728
|
+
// run shares ONE episode identity. It is read from the bundle's metadata first (a retry or a
|
|
2729
|
+
// historical replay republishes the identity the episode already shipped), then from the slot
|
|
2730
|
+
// `editorial-render` froze; a bundle that carries neither keeps the title it already has.
|
|
2731
|
+
const identity =
|
|
2732
|
+
identityFromMetadata(metadataOf(article)) ??
|
|
2733
|
+
identityFromMetadata({
|
|
2734
|
+
[EPISODE_IDENTITY_KEY]: readJson(join(workDir, '21-plan', `${runDate}_05_script_identity.json`)),
|
|
2735
|
+
});
|
|
2736
|
+
if (identity !== null && identity.status === 'support-removed') {
|
|
2737
|
+
// The withhold path of R4: never publish a headline admission no longer backs, and never
|
|
2738
|
+
// silently publish the legacy title in its place — a human has to regenerate the point.
|
|
2739
|
+
failWith(
|
|
2740
|
+
1,
|
|
2741
|
+
`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`,
|
|
2742
|
+
);
|
|
2743
|
+
}
|
|
2744
|
+
const episodeTitle = identity?.title ?? (typeof article.title === 'string' ? article.title : '');
|
|
2273
2745
|
const audioMeta = metadataOf(readJson(audioPath));
|
|
2274
2746
|
const rawFile = audioMeta.mp3Path ?? audioMeta.audioPath;
|
|
2275
2747
|
if (typeof rawFile !== 'string' || rawFile === '') {
|
|
@@ -2281,7 +2753,7 @@ export function dailyPublishPrep(args: string[]): void {
|
|
|
2281
2753
|
if (!audioFile.endsWith('.mp3')) {
|
|
2282
2754
|
failWith(1, `publish-prep: resolved audio is not an MP3 (transcode_mp3 must be "true"): ${audioFile}`);
|
|
2283
2755
|
}
|
|
2284
|
-
stampId3Tags(audioFile,
|
|
2756
|
+
stampId3Tags(audioFile, episodeTitle, runDate, artist, album);
|
|
2285
2757
|
const resolvedCover = resolve(coverPath);
|
|
2286
2758
|
const hasCover = existsSync(resolvedCover);
|
|
2287
2759
|
// Daily-show itunes convention: season = year, episode = day-of-year. run_date arrives
|
|
@@ -2299,10 +2771,18 @@ export function dailyPublishPrep(args: string[]): void {
|
|
|
2299
2771
|
// alone was silently dropped by the mapper — episodes published without a cover.
|
|
2300
2772
|
const merged = {
|
|
2301
2773
|
...article,
|
|
2774
|
+
// Every publish target (podcast, ID3, show notes, surfdash) reads this one title.
|
|
2775
|
+
title: episodeTitle,
|
|
2302
2776
|
metadata: {
|
|
2303
2777
|
...metadataOf(article),
|
|
2304
2778
|
audioFile,
|
|
2305
2779
|
runDate,
|
|
2780
|
+
...(identity !== null
|
|
2781
|
+
? {
|
|
2782
|
+
[EPISODE_IDENTITY_KEY]: identity,
|
|
2783
|
+
...(identity.coverHeadline !== null ? { coverHeadline: identity.coverHeadline } : {}),
|
|
2784
|
+
}
|
|
2785
|
+
: {}),
|
|
2306
2786
|
...(hasCover ? { coverImage: resolvedCover } : {}),
|
|
2307
2787
|
...(episode > 0 ? { itunes: { season, episode } } : {}),
|
|
2308
2788
|
},
|
|
@@ -3415,6 +3895,23 @@ export function dailySafetyGate(args: string[]): void {
|
|
|
3415
3895
|
unlinkSync(infraMarker);
|
|
3416
3896
|
}
|
|
3417
3897
|
sted('write', statusFile, () => writeRaw(statusFile, status));
|
|
3898
|
+
// Task 0392 R2: the channel-admission decisions this run actually reached, keyed by target
|
|
3899
|
+
// and scope. A channel outcome is not a candidate drop — it never touches the totals.
|
|
3900
|
+
// Unobserved (no platforms array) leaves the stage unknown instead of claiming zero blocks.
|
|
3901
|
+
if (platforms.length > 0) {
|
|
3902
|
+
recordSelectionStage(workDir, runDate, {
|
|
3903
|
+
channelAdmission: [
|
|
3904
|
+
{
|
|
3905
|
+
scope: scopeDir === '' ? 'drafts' : scopeDir,
|
|
3906
|
+
targets: platforms.map((platform) => ({
|
|
3907
|
+
target: String(platform?.platform ?? ''),
|
|
3908
|
+
decision: String(platform?.decision ?? ''),
|
|
3909
|
+
})),
|
|
3910
|
+
status,
|
|
3911
|
+
},
|
|
3912
|
+
],
|
|
3913
|
+
});
|
|
3914
|
+
}
|
|
3418
3915
|
console.log(`safety: status=${status} (${reason}); routing is transition-owned`);
|
|
3419
3916
|
});
|
|
3420
3917
|
}
|
|
@@ -4153,6 +4650,11 @@ export function dailyScriptStyle(args: string[]): void {
|
|
|
4153
4650
|
* `24-script/<date>_08_script-write_errors.json` ([{itemId, rule}]) when the plan is absent or
|
|
4154
4651
|
* rejected, and removes it when the plan is accepted. The trial build goes to a scratch path so the
|
|
4155
4652
|
* `script` stage's isFile cache is never primed by a check.
|
|
4653
|
+
*
|
|
4654
|
+
* 0385 AC R2/R3: an ACCEPTED plan can still carry advisory editorial findings
|
|
4655
|
+
* (`metadata.scriptPlanAdvisories` from the generator's `analyzeEditorialClaims`). Those are written
|
|
4656
|
+
* to `24-script/<date>_08_script-write_advisories.json` and logged — a separate file, because the
|
|
4657
|
+
* acceptance verdict they describe is not a rejection and must not trigger the fix pass.
|
|
4156
4658
|
*/
|
|
4157
4659
|
export function dailyScriptCheck(args: string[]): void {
|
|
4158
4660
|
const [workDir = '', runDate = '', pluginsPath = ''] = args;
|
|
@@ -4185,7 +4687,19 @@ export function dailyScriptCheck(args: string[]): void {
|
|
|
4185
4687
|
}
|
|
4186
4688
|
if (source === 'plan') {
|
|
4187
4689
|
if (isFile(errorsOut)) unlinkSync(errorsOut);
|
|
4188
|
-
|
|
4690
|
+
// 0385 AC R2/R3: the editorial findings are advisory — an accepted plan stays accepted,
|
|
4691
|
+
// so they land in their own file and never re-open the fix loop that `errorsOut` drives.
|
|
4692
|
+
const advisoriesOut = join(workDir, '24-script', `${runDate}_08_script-write_advisories.json`);
|
|
4693
|
+
const advisories = Array.isArray(metadata.scriptPlanAdvisories) ? metadata.scriptPlanAdvisories : [];
|
|
4694
|
+
if (advisories.length > 0) {
|
|
4695
|
+
sted('write', advisoriesOut, () => writeJsonText(advisoriesOut, advisories));
|
|
4696
|
+
console.log(
|
|
4697
|
+
`script plan accepted by the validator (${advisories.length} advisory finding(s)): ${advisoriesOut}`,
|
|
4698
|
+
);
|
|
4699
|
+
} else {
|
|
4700
|
+
if (isFile(advisoriesOut)) unlinkSync(advisoriesOut);
|
|
4701
|
+
console.log('script plan accepted by the validator');
|
|
4702
|
+
}
|
|
4189
4703
|
return;
|
|
4190
4704
|
}
|
|
4191
4705
|
writeErrors(Array.isArray(metadata.scriptPlanErrors) ? metadata.scriptPlanErrors : []);
|
|
@@ -4230,6 +4744,14 @@ export function dailyCurateCheck(args: string[]): void {
|
|
|
4230
4744
|
sted('write', planFile, () => writeJsonText(planFile, candidateDocs));
|
|
4231
4745
|
sted('write', excludedFile, () => writeJsonText(excludedFile, []));
|
|
4232
4746
|
if (isFile(errFile)) unlinkSync(errFile);
|
|
4747
|
+
// Task 0392 R2: the recorded fallback IS the curation evidence for this attempt — the
|
|
4748
|
+
// agent's split was rejected, so the plan is every candidate and nothing was excluded.
|
|
4749
|
+
recordSelectionStage(workDir, runDate, {
|
|
4750
|
+
stages: [
|
|
4751
|
+
{ stage: 'curation', input: candidateIds.length, kept: candidateDocs.length, dropped: [] },
|
|
4752
|
+
{ stage: 'plan', input: candidateDocs.length, kept: candidateDocs.length, dropped: [] },
|
|
4753
|
+
],
|
|
4754
|
+
});
|
|
4233
4755
|
return;
|
|
4234
4756
|
}
|
|
4235
4757
|
sted('write', errFile, () => writeJsonText(errFile, errors));
|
|
@@ -4340,6 +4862,9 @@ export function dailyCurateCheck(args: string[]): void {
|
|
|
4340
4862
|
return;
|
|
4341
4863
|
}
|
|
4342
4864
|
|
|
4865
|
+
// Captured before the check's own dedup pass: `curation` records what the AGENT handed over,
|
|
4866
|
+
// `plan` records what the validation then kept, so the two stages never double-count a drop.
|
|
4867
|
+
const agentExcluded = excludedItems.map((entry) => entry.id);
|
|
4343
4868
|
const { kept, dropped } = dedupPlanByTitle(planDocs);
|
|
4344
4869
|
if (dropped.length > 0) {
|
|
4345
4870
|
sted('write', planFile, () => writeJsonText(planFile, kept));
|
|
@@ -4356,18 +4881,201 @@ export function dailyCurateCheck(args: string[]): void {
|
|
|
4356
4881
|
}
|
|
4357
4882
|
|
|
4358
4883
|
if (isFile(errFile)) unlinkSync(errFile);
|
|
4884
|
+
// Task 0392 R2: curation is authoritative only after this validation passed — that is why the
|
|
4885
|
+
// evidence is written here and not by the agent. `curation` is the agent's split as handed over;
|
|
4886
|
+
// `plan` is the validated plan after the check's own near-duplicate pass, so the two stages
|
|
4887
|
+
// chain (`curation.kept` → `plan.input`) and each one's arithmetic holds.
|
|
4888
|
+
recordSelectionStage(workDir, runDate, {
|
|
4889
|
+
stages: [
|
|
4890
|
+
{
|
|
4891
|
+
stage: 'curation',
|
|
4892
|
+
input: candidateIds.length,
|
|
4893
|
+
kept: planDocs.length,
|
|
4894
|
+
dropped: agentExcluded,
|
|
4895
|
+
},
|
|
4896
|
+
{ stage: 'plan', input: planDocs.length, kept: kept.length, dropped },
|
|
4897
|
+
],
|
|
4898
|
+
curationExcluded: excludedItems.map((entry) => ({ id: entry.id, reason: entry.reason })),
|
|
4899
|
+
});
|
|
4359
4900
|
console.log(`curate-check: accepted (${kept.length} kept, ${excludedItems.length} excluded)`);
|
|
4360
4901
|
}
|
|
4361
4902
|
|
|
4362
|
-
|
|
4363
|
-
|
|
4364
|
-
|
|
4365
|
-
|
|
4903
|
+
/**
|
|
4904
|
+
* 0394 R1/R16 — the citation line for one curated item, or `''` when the doc carries no verifiable
|
|
4905
|
+
* link. Resolution (corroborated original → retrieval URL → explicit aggregator fallback) is owned
|
|
4906
|
+
* by `./source-citation.ts` so the same rule can serve the notes paths without a second convention.
|
|
4907
|
+
*/
|
|
4908
|
+
function sourceLineForDoc(doc: Record<string, unknown>, sourceUri: string): string {
|
|
4909
|
+
const citation = resolveSourceCitation(doc, sourceUri);
|
|
4910
|
+
return citation === null ? '' : `[来源:${citation.label}](${citation.url})`;
|
|
4911
|
+
}
|
|
4912
|
+
|
|
4913
|
+
/**
|
|
4914
|
+
* What the `editorial-commit` stage reports instead of the ledger module's raw status: the two
|
|
4915
|
+
* "nothing to fix" outcomes collapse to `committed` / `reused`, the two refusals stay verbatim.
|
|
4916
|
+
*/
|
|
4917
|
+
export type EditorialCommitSummary = 'committed' | 'reused' | 'conflict' | 'stop';
|
|
4918
|
+
|
|
4919
|
+
/**
|
|
4920
|
+
* The existing kk store single-flight claim as the ledger's `LockPort` (ADR-054/0384 R10): the
|
|
4921
|
+
* same `kk lock acquire/release` the collect workflow shells, scoped to the ledger's own name. A
|
|
4922
|
+
* second locking mechanism is deliberately not invented — the store's `LocksDao` owns the claim,
|
|
4923
|
+
* its TTL and its re-entrancy.
|
|
4924
|
+
*/
|
|
4925
|
+
function kkLedgerLockPort(): LockPort {
|
|
4926
|
+
const kkLock = (argv: string[]): { status: number; stdout: string; stderr: string } => {
|
|
4927
|
+
const result = spawnSync('kk', argv, { encoding: 'utf-8' });
|
|
4928
|
+
if (result.error !== undefined) failWith(127, `kk: ${result.error.message}`);
|
|
4929
|
+
return { status: result.status ?? 1, stdout: result.stdout ?? '', stderr: result.stderr ?? '' };
|
|
4930
|
+
};
|
|
4931
|
+
return {
|
|
4932
|
+
acquire: async (name: string, run: string) => {
|
|
4933
|
+
// stdout IS the lock contract: `{"acquired":true}` or `{"skipped":"locked",…}` (exit 0).
|
|
4934
|
+
const claimed = kkLock(['lock', 'acquire', '--name', name, '--run', run]);
|
|
4935
|
+
if (claimed.status !== 0) failWith(claimed.status, `lock acquire failed: ${claimed.stderr.trim()}`);
|
|
4936
|
+
return claimed.stdout.includes('"acquired":true');
|
|
4937
|
+
},
|
|
4938
|
+
release: async (name: string, run: string) => {
|
|
4939
|
+
const released = kkLock(['lock', 'release', '--name', name, '--run', run]);
|
|
4940
|
+
if (released.status !== 0) {
|
|
4941
|
+
console.error(`editorial-commit: lock release failed: ${released.stderr.trim()}`);
|
|
4942
|
+
}
|
|
4943
|
+
},
|
|
4944
|
+
};
|
|
4945
|
+
}
|
|
4946
|
+
|
|
4947
|
+
/** Selected ids from the plan `curate-final` settled — the only ids a judgment may cite (0393). */
|
|
4948
|
+
function selectedIdsOf(planRaw: unknown): Set<string> {
|
|
4949
|
+
const docs: Record<string, unknown>[] = Array.isArray(planRaw)
|
|
4950
|
+
? (planRaw as Record<string, unknown>[])
|
|
4951
|
+
: Array.isArray(metadataOf(planRaw).docs)
|
|
4952
|
+
? (metadataOf(planRaw).docs as Record<string, unknown>[])
|
|
4953
|
+
: [];
|
|
4954
|
+
const ids = new Set<string>();
|
|
4955
|
+
for (const doc of docs) {
|
|
4956
|
+
if (doc !== null && typeof doc === 'object' && typeof doc.id === 'string' && doc.id.trim() !== '') {
|
|
4957
|
+
ids.add(doc.id.trim());
|
|
4958
|
+
}
|
|
4366
4959
|
}
|
|
4367
|
-
|
|
4368
|
-
|
|
4369
|
-
|
|
4370
|
-
|
|
4960
|
+
return ids;
|
|
4961
|
+
}
|
|
4962
|
+
|
|
4963
|
+
/**
|
|
4964
|
+
* 0384 R4/R10 — the deterministic judgment commit between final selection and drafting: the
|
|
4965
|
+
* `align` agent's proposal in, a validated ledger commit and an immutable run snapshot out.
|
|
4966
|
+
*
|
|
4967
|
+
* news-editorial-commit <work_dir> <run_date> <run_id> [proposal_file] [ledger_file]
|
|
4968
|
+
*
|
|
4969
|
+
* `<proposal_file>` defaults to `21-plan/<date>_judgment-proposal.json` (absent file = the documented
|
|
4970
|
+
* "nothing new" case, an empty proposal); `<ledger_file>` defaults to the run directory's parent
|
|
4971
|
+
* `<works_dir>/kk-news-generate/conclusion.md` (ADR-054). Outputs — both beside the plan:
|
|
4972
|
+
* `judgment-snapshot.json` (what 0385 drafts from and 0396 corrects from) and
|
|
4973
|
+
* `judgment-commit-receipt.json` (written on every exit path, including the refusals).
|
|
4974
|
+
*
|
|
4975
|
+
* Reselect tolerance: the proposal is authored in `curate`, but `curate-check`/`curate-fix`/`--final`
|
|
4976
|
+
* settle the plan afterwards, so a judgment may cite a selected id the settled plan no longer holds.
|
|
4977
|
+
* Such judgments are dropped *here* (never inside the ledger API, whose unknown-id refusal stays) and
|
|
4978
|
+
* the ids go into the receipt's `droppedByReselection` plus a printed line — the surviving judgments
|
|
4979
|
+
* still commit, and a proposal with nothing committable left behaves exactly like the documented
|
|
4980
|
+
* empty proposal (this run's legal snapshot is reused). Never silent, never a hard stop for reselection alone.
|
|
4981
|
+
*
|
|
4982
|
+
* Exit: `committed` / `reused` exit 0; `conflict` and `stop` print the recovery path and exit 1, so
|
|
4983
|
+
* a refused ledger commit can never be drafted against. `KK_EDITORIAL_COMMIT_OFFLINE=1` runs the
|
|
4984
|
+
* commit without the store claim (the documented `NULL_LOCK` seam; tests and offline replay).
|
|
4985
|
+
*/
|
|
4986
|
+
export async function newsEditorialCommit(args: string[]): Promise<void> {
|
|
4987
|
+
const [workDir = '', runDate = '', runId = '', proposalArg = '', ledgerArg = ''] = args;
|
|
4988
|
+
if (!workDir) fail('missing work_dir');
|
|
4989
|
+
if (!runDate) fail('missing run_date');
|
|
4990
|
+
if (!runId) fail('missing run_id');
|
|
4991
|
+
// 0384: judged artifacts live beside the plan, NOT under `20-editorial/` — that directory is the
|
|
4992
|
+
// per-run writer-skill snapshot (design §2.2 keeps the skill read in place, and the DAG contract
|
|
4993
|
+
// forbids agent prompts naming a copy there).
|
|
4994
|
+
const planDir = join(workDir, '21-plan');
|
|
4995
|
+
const proposalPath = proposalArg || join(planDir, `${runDate}_judgment-proposal.json`);
|
|
4996
|
+
const ledgerPath = ledgerArg || resolve(join(workDir, '..', 'conclusion.md'));
|
|
4997
|
+
const snapshotPath = join(planDir, `${runDate}_judgment-snapshot.json`);
|
|
4998
|
+
const receiptPath = join(planDir, `${runDate}_judgment-commit-receipt.json`);
|
|
4999
|
+
const planFile = join(workDir, '21-plan', `${runDate}_03_plan_plan.json`);
|
|
5000
|
+
|
|
5001
|
+
const planRaw = readJson(planFile);
|
|
5002
|
+
if (planRaw === null) {
|
|
5003
|
+
failWith(1, `editorial-commit: no selected plan at ${planFile} — refusing to commit judgments`);
|
|
5004
|
+
}
|
|
5005
|
+
const selectedIds = selectedIdsOf(planRaw);
|
|
5006
|
+
|
|
5007
|
+
let proposal: AlignmentProposal;
|
|
5008
|
+
if (isFile(proposalPath)) {
|
|
5009
|
+
try {
|
|
5010
|
+
const parsed = JSON.parse(readFileSync(proposalPath, 'utf-8')) as AlignmentProposal;
|
|
5011
|
+
if (parsed === null || typeof parsed !== 'object' || !Array.isArray(parsed.judgments)) {
|
|
5012
|
+
failWith(1, `editorial-commit: ${proposalPath} has no judgments array — re-run the align pass`);
|
|
5013
|
+
}
|
|
5014
|
+
proposal = parsed;
|
|
5015
|
+
} catch (error) {
|
|
5016
|
+
failWith(1, `editorial-commit: ${proposalPath} is not valid JSON: ${(error as Error).message}`);
|
|
5017
|
+
}
|
|
5018
|
+
} else {
|
|
5019
|
+
// An empty proposal is the normal case (skill `align` rule 4), not a failure.
|
|
5020
|
+
proposal = { version: 1, judgments: [] };
|
|
5021
|
+
console.log(`editorial-commit: no proposal at ${proposalPath} — committing this run's ledger as-is`);
|
|
5022
|
+
}
|
|
5023
|
+
|
|
5024
|
+
// The plan is settled by now (`curate-check`/`curate-fix`/`--final`), so an id the proposal cited
|
|
5025
|
+
// from the pre-settlement plan may be gone: drop those judgments and record them (never silent).
|
|
5026
|
+
const reselected = dropReselectedJudgments(proposal, selectedIds);
|
|
5027
|
+
if (reselected.dropped.length > 0) {
|
|
5028
|
+
// Same stream as the sibling drop reports (`curate-check`, `qc`): a drop is loud, not fatal.
|
|
5029
|
+
console.error(
|
|
5030
|
+
`editorial-commit: dropped ${reselected.dropped.length} judgment(s) the settled plan no longer carries: ${reselected.dropped.join(', ')}`,
|
|
5031
|
+
);
|
|
5032
|
+
}
|
|
5033
|
+
|
|
5034
|
+
sted('mkdir', planDir, () => mkdirSync(planDir, { recursive: true }));
|
|
5035
|
+
// Offline means NO lock port at all (the ledger's documented `NULL_LOCK` default), so the
|
|
5036
|
+
// receipt says `lock: none` — passing NULL_LOCK explicitly would report a claim it never took.
|
|
5037
|
+
const receipt = await commitAlignment({
|
|
5038
|
+
ledgerPath,
|
|
5039
|
+
snapshotPath,
|
|
5040
|
+
receiptPath,
|
|
5041
|
+
proposal: reselected.proposal,
|
|
5042
|
+
selectedIds,
|
|
5043
|
+
runDate,
|
|
5044
|
+
runId,
|
|
5045
|
+
now: new Date().toISOString(),
|
|
5046
|
+
droppedByReselection: reselected.dropped,
|
|
5047
|
+
...(process.env.KK_EDITORIAL_COMMIT_OFFLINE === '1' ? {} : { lock: kkLedgerLockPort() }),
|
|
5048
|
+
});
|
|
5049
|
+
|
|
5050
|
+
const summary: EditorialCommitSummary =
|
|
5051
|
+
receipt.status === 'applied'
|
|
5052
|
+
? 'committed'
|
|
5053
|
+
: receipt.status === 'no-op'
|
|
5054
|
+
? 'reused'
|
|
5055
|
+
: receipt.status === 'conflict'
|
|
5056
|
+
? 'conflict'
|
|
5057
|
+
: 'stop';
|
|
5058
|
+
const counts = [
|
|
5059
|
+
`appended=${receipt.appended.length}`,
|
|
5060
|
+
`superseded=${receipt.superseded.length}`,
|
|
5061
|
+
`corrections=${receipt.correctionIds.length}`,
|
|
5062
|
+
`dropped=${receipt.droppedByReselection.length}`,
|
|
5063
|
+
`lock=${receipt.lock}`,
|
|
5064
|
+
`snapshot=${receipt.snapshotReused ? 'reused' : 'frozen'}`,
|
|
5065
|
+
].join(' ');
|
|
5066
|
+
console.log(
|
|
5067
|
+
`editorial-commit: ${summary} — ${receipt.reason} (${counts}; ledger=${receipt.ledgerPath}; receipt=${receiptPath})`,
|
|
5068
|
+
);
|
|
5069
|
+
if (receipt.correctionIds.length > 0) {
|
|
5070
|
+
console.log(`editorial-commit: corrections owed by the draft: ${receipt.correctionIds.join(', ')}`);
|
|
5071
|
+
}
|
|
5072
|
+
if (summary === 'conflict' || summary === 'stop') {
|
|
5073
|
+
const recovery = receipt.recovery;
|
|
5074
|
+
const where = recovery?.backupPath ? ` backup=${recovery.backupPath}` : '';
|
|
5075
|
+
failWith(
|
|
5076
|
+
1,
|
|
5077
|
+
`editorial-commit: ${summary} — ${receipt.reason}${where} (${recovery?.action ?? 'see the receipt'})`,
|
|
5078
|
+
);
|
|
4371
5079
|
}
|
|
4372
5080
|
}
|
|
4373
5081
|
|
|
@@ -4381,7 +5089,7 @@ const EDITORIAL_ARTICLE_OPENING = '这里是由Robin为你带来的咸话咸说
|
|
|
4381
5089
|
* 1. `22-article/<date>_06_article-write_body.md`
|
|
4382
5090
|
* 2. `23-cover/<date>_07_cover-brief.json`
|
|
4383
5091
|
* 3. `25-xhs/<date>_18_xhs_plan.json` (only when `cards_enabled === 'true'`)
|
|
4384
|
-
* 4. `26-social/{x,threads}.md` (`social.short`)
|
|
5092
|
+
* 4. `26-social/{x,threads,jike}.md` (`social.short`)
|
|
4385
5093
|
* 5. `26-social/{weibo,linkedin}.md` (`social.long`)
|
|
4386
5094
|
* Missing master field -> skip that one artifact with a logged reason, write the others.
|
|
4387
5095
|
*/
|
|
@@ -4435,11 +5143,19 @@ export function dailyEditorialRender(args: string[]): void {
|
|
|
4435
5143
|
const title = typeof doc?.title === 'string' ? doc.title.trim() : '';
|
|
4436
5144
|
const body = typeof doc?.body === 'string' ? doc.body.trim() : '';
|
|
4437
5145
|
const lead = typeof item?.lead === 'string' ? item.lead.trim() : '';
|
|
5146
|
+
// 0385 R3: a comment-free item is legal, so a blank insight drops the comment sentence
|
|
5147
|
+
// only — dropping the whole item would publish an episode the plan says to speak.
|
|
4438
5148
|
const insight = typeof item?.insight === 'string' ? item.insight.trim() : '';
|
|
4439
|
-
if (!title || !body || !lead
|
|
5149
|
+
if (!title || !body || !lead) continue;
|
|
4440
5150
|
const sourceUri = typeof doc?.sourceUri === 'string' ? doc.sourceUri.trim() : '';
|
|
4441
|
-
const sourceLine = sourceUri ?
|
|
4442
|
-
const parts = [
|
|
5151
|
+
const sourceLine = sourceUri ? sourceLineForDoc(doc ?? {}, sourceUri) : '';
|
|
5152
|
+
const parts = [
|
|
5153
|
+
`## ${title}`,
|
|
5154
|
+
lead,
|
|
5155
|
+
body,
|
|
5156
|
+
...(insight !== '' ? [insight] : []),
|
|
5157
|
+
...(sourceLine ? [sourceLine] : []),
|
|
5158
|
+
];
|
|
4443
5159
|
articleSections.push(parts.join('\n\n'));
|
|
4444
5160
|
}
|
|
4445
5161
|
if (articleSections.length > 0 && outro !== '') {
|
|
@@ -4469,8 +5185,73 @@ export function dailyEditorialRender(args: string[]): void {
|
|
|
4469
5185
|
const leadId = orderedIds[0];
|
|
4470
5186
|
const leadDoc = leadId !== undefined ? docById.get(leadId) : undefined;
|
|
4471
5187
|
const leadStoryTitle = typeof leadDoc?.title === 'string' ? leadDoc.title.trim() : '';
|
|
5188
|
+
// 0385 R4: freeze ONE episode identity (run date + one point + the source ids the point rests
|
|
5189
|
+
// on) for every publishing surface. The point is the script plan's cover headline and the cover
|
|
5190
|
+
// reuses it verbatim, never a second wording. Two non-frozen outcomes are explicit: an existing
|
|
5191
|
+
// frozen record wins (a retry or a historical replay keeps the identity the bundle shipped), and
|
|
5192
|
+
// a point whose supporting sources admission dropped is WITHHELD — no title, no cover point, so
|
|
5193
|
+
// nothing downstream can publish a headline the settled plan no longer backs.
|
|
5194
|
+
const rawCoverSupport =
|
|
5195
|
+
rawCover !== null && typeof rawCover === 'object' ? (rawCover as Record<string, unknown>).sourceIds : undefined;
|
|
5196
|
+
// 0385 R4/P3: "admitted" means the episode actually covers the id — the plan docs MINUS the drop
|
|
5197
|
+
// signals downstream already honours (the article boundary drop `metadata.excludedIds` and the
|
|
5198
|
+
// script plan's own `excluded` list). Comparing against the raw plan set made the withhold
|
|
5199
|
+
// guarantee structurally unreachable: the lead is always in the plan it came from.
|
|
5200
|
+
const droppedIds = new Set<string>();
|
|
5201
|
+
const articleMetaExcluded = metadataOf(
|
|
5202
|
+
readJson(join(workDir, '22-article', `${runDate}_06_article_content.json`)),
|
|
5203
|
+
)?.excludedIds;
|
|
5204
|
+
if (Array.isArray(articleMetaExcluded)) {
|
|
5205
|
+
for (const id of articleMetaExcluded) if (typeof id === 'string' && id !== '') droppedIds.add(id);
|
|
5206
|
+
}
|
|
5207
|
+
if (Array.isArray(master.excluded)) {
|
|
5208
|
+
for (const entry of master.excluded as unknown[]) {
|
|
5209
|
+
const id = entry !== null && typeof entry === 'object' ? (entry as { id?: unknown }).id : undefined;
|
|
5210
|
+
if (typeof id === 'string' && id !== '') droppedIds.add(id);
|
|
5211
|
+
}
|
|
5212
|
+
}
|
|
5213
|
+
const admittedSourceIds = [...docById.keys()].filter((id) => !droppedIds.has(id));
|
|
5214
|
+
// The point's support is the cover's own `sourceIds` when the writer named them (the documented
|
|
5215
|
+
// producer, 0385 R4), otherwise the admitted lead — the story the point is about.
|
|
5216
|
+
const supportIds = Array.isArray(rawCoverSupport)
|
|
5217
|
+
? rawCoverSupport.filter((id): id is string => typeof id === 'string' && id.trim() !== '')
|
|
5218
|
+
: leadId !== undefined
|
|
5219
|
+
? [leadId]
|
|
5220
|
+
: [];
|
|
5221
|
+
const identityPath = join(workDir, '21-plan', `${runDate}_05_script_identity.json`);
|
|
5222
|
+
const priorIdentity = identityFromMetadata({ [EPISODE_IDENTITY_KEY]: readJson(identityPath) });
|
|
5223
|
+
const identity =
|
|
5224
|
+
priorIdentity !== null && priorIdentity.status === 'frozen'
|
|
5225
|
+
? priorIdentity
|
|
5226
|
+
: freezeEpisodeIdentity({
|
|
5227
|
+
date: runDate,
|
|
5228
|
+
headline: coverHeadline,
|
|
5229
|
+
supportingSourceIds: supportIds,
|
|
5230
|
+
admittedSourceIds,
|
|
5231
|
+
legacyTitle: leadStoryTitle,
|
|
5232
|
+
});
|
|
5233
|
+
if (priorIdentity === null || priorIdentity.status !== 'frozen') {
|
|
5234
|
+
sted('mkdir', join(workDir, '21-plan'), () => mkdirSync(join(workDir, '21-plan'), { recursive: true }));
|
|
5235
|
+
sted('write', identityPath, () => writeJsonText(identityPath, identity));
|
|
5236
|
+
}
|
|
5237
|
+
if (identity.status === 'frozen') {
|
|
5238
|
+
console.log(`editorial-render: episode identity frozen: ${identity.title} (${identityPath})`);
|
|
5239
|
+
} else if (identity.status === 'support-removed') {
|
|
5240
|
+
// The point lost its support in admission: withhold it and its cover copy (never a fallback
|
|
5241
|
+
// title here — the fallback below would smuggle back a point the plan no longer admits).
|
|
5242
|
+
console.error(
|
|
5243
|
+
`editorial-render: WITHHELD episode identity — admission dropped the headline's support (${identity.supportingSourceIds.join(', ')}); the title and the cover point are withheld (see ${identityPath})`,
|
|
5244
|
+
);
|
|
5245
|
+
coverHeadline = '';
|
|
5246
|
+
}
|
|
5247
|
+
// Every target reads the frozen title from the bundle, so the article Content (surfdash, ID3,
|
|
5248
|
+
// show notes) carries the same one the podcast and the cover do. A withheld identity leaves the
|
|
5249
|
+
// article title untouched: there is no title to share. On a first run the Content does not exist
|
|
5250
|
+
// yet (this stage precedes `daily-article`) and the stamp is a no-op — `daily-article` re-applies
|
|
5251
|
+
// it after it derives, so both orders converge on one title.
|
|
5252
|
+
stampEpisodeIdentity(join(workDir, '22-article', `${runDate}_06_article_content.json`), identity);
|
|
4472
5253
|
if (coverSubject !== '') {
|
|
4473
|
-
if (coverHeadline === '' && leadStoryTitle !== '') {
|
|
5254
|
+
if (coverHeadline === '' && leadStoryTitle !== '' && identity.status !== 'support-removed') {
|
|
4474
5255
|
coverHeadline = leadStoryTitle;
|
|
4475
5256
|
}
|
|
4476
5257
|
const coverDir = join(workDir, '23-cover');
|
|
@@ -4479,8 +5260,11 @@ export function dailyEditorialRender(args: string[]): void {
|
|
|
4479
5260
|
sted('write', coverOut, () =>
|
|
4480
5261
|
writeJsonText(coverOut, {
|
|
4481
5262
|
subject: coverSubject,
|
|
4482
|
-
|
|
5263
|
+
// The cover reuses the frozen point verbatim (0385 R4); `episodeIdentity` carries the
|
|
5264
|
+
// title so a retry or a replay re-renders the same episode identity.
|
|
5265
|
+
headline: identity.coverHeadline ?? coverHeadline,
|
|
4483
5266
|
leadStoryTitle,
|
|
5267
|
+
episodeIdentity: identity,
|
|
4484
5268
|
}),
|
|
4485
5269
|
);
|
|
4486
5270
|
console.log(`editorial-render: wrote cover brief: ${coverOut}`);
|
|
@@ -4589,11 +5373,11 @@ export function dailyEditorialRender(args: string[]): void {
|
|
|
4589
5373
|
const socialDir = join(workDir, '26-social');
|
|
4590
5374
|
if (socialShort !== '') {
|
|
4591
5375
|
sted('mkdir', socialDir, () => mkdirSync(socialDir, { recursive: true }));
|
|
4592
|
-
for (const name of ['x.md', 'threads.md', 'weibo.md']) {
|
|
5376
|
+
for (const name of ['x.md', 'threads.md', 'weibo.md', 'jike.md']) {
|
|
4593
5377
|
const out = join(socialDir, name);
|
|
4594
5378
|
sted('write', out, () => writeRaw(out, `${socialShort}\n`));
|
|
4595
5379
|
}
|
|
4596
|
-
console.log('editorial-render: wrote 26-social/{x,threads,weibo}.md');
|
|
5380
|
+
console.log('editorial-render: wrote 26-social/{x,threads,weibo,jike}.md');
|
|
4597
5381
|
} else if (socialLong !== '') {
|
|
4598
5382
|
sted('mkdir', socialDir, () => mkdirSync(socialDir, { recursive: true }));
|
|
4599
5383
|
const out = join(socialDir, 'weibo.md');
|
|
@@ -4692,12 +5476,29 @@ export function dailyShowNotes(args: string[]): void {
|
|
|
4692
5476
|
}
|
|
4693
5477
|
}
|
|
4694
5478
|
}
|
|
5479
|
+
// 0386 R1 — the card manifest (already in published order) rides along as a file path, and
|
|
5480
|
+
// its problems are recorded beside the notes, never inside them. When no receipt exists yet
|
|
5481
|
+
// the render is explicitly allowed to run link-free: the notes are reviewable before the
|
|
5482
|
+
// article URL is known, and the article link is added only from a real receipt `postPath`.
|
|
5483
|
+
const cardsManifest = join(workDir, '25-xhs', 'cards.json');
|
|
5484
|
+
const cardsDiagnostics = join(workDir, '31-publish', `${runDate}_15_show-notes_cards-diagnostics.json`);
|
|
4695
5485
|
kk(['executor', 'run', 'podcast-pub', '--in', planIn, '--out', out, ...pluginsArgs(pluginsPath)], {
|
|
4696
5486
|
env: {
|
|
4697
5487
|
PODCAST_PUB_TITLE: titleArg,
|
|
4698
5488
|
PODCAST_PUB_RUN_DATE: runDate,
|
|
4699
5489
|
PODCAST_PUB_BRIEF_MODE: 'true',
|
|
5490
|
+
...(isFile(cardsManifest) ? { PODCAST_PUB_CARDS: cardsManifest } : {}),
|
|
5491
|
+
PODCAST_PUB_CARDS_DIAGNOSTICS: cardsDiagnostics,
|
|
5492
|
+
...(postPath === '' ? { PODCAST_PUB_BRIEF_WITHOUT_RECEIPT: 'true' } : {}),
|
|
4700
5493
|
PODCAST_PUB_ARTICLE_POST_PATH: postPath,
|
|
5494
|
+
// 0396 R1: the frozen 0384 judgment snapshot is what the correction block is read
|
|
5495
|
+
// from (stable correction id, prior-episode reference, evidence). Passing the path
|
|
5496
|
+
// only when the snapshot exists keeps a run without corrections byte-identical, and
|
|
5497
|
+
// a snapshot that cannot be read fails the render instead of dropping an owed
|
|
5498
|
+
// correction silently.
|
|
5499
|
+
...(isFile(join(workDir, '21-plan', `${runDate}_judgment-snapshot.json`))
|
|
5500
|
+
? { PODCAST_PUB_CORRECTIONS: join(workDir, '21-plan', `${runDate}_judgment-snapshot.json`) }
|
|
5501
|
+
: {}),
|
|
4701
5502
|
// 2026-10-08: the column settings carry the AI-production note. Do not append the
|
|
4702
5503
|
// stock closer to show notes (or the article, or the spoken sign-off).
|
|
4703
5504
|
...(isFile(audioContent) ? { PODCAST_PUB_AUDIO_CONTENT: audioContent } : {}),
|
|
@@ -5034,6 +5835,68 @@ export function dailyTranslateValidate(args: string[]): void {
|
|
|
5034
5835
|
});
|
|
5035
5836
|
}
|
|
5036
5837
|
|
|
5838
|
+
/** CJK ideographs and kana: present in a zh draft, absent from a real en translation. */
|
|
5839
|
+
const CJK_TEXT = /[\u3040-\u30ff\u3400-\u4dbf\u4e00-\u9fff\uff66-\uff9f]/u;
|
|
5840
|
+
/** Kana only: a ja translation always carries hiragana/katakana; a zh copy of the draft never does. */
|
|
5841
|
+
const KANA_TEXT = /[\u3040-\u309f\u30a0-\u30ff]/u;
|
|
5842
|
+
|
|
5843
|
+
/**
|
|
5844
|
+
* `news-localize-validate <workDir>` — the pre-freeze gate on the news pipeline's en/ja translations
|
|
5845
|
+
* (task 0409 R1).
|
|
5846
|
+
*
|
|
5847
|
+
* The `localize` agent node writes `${workDir}/22-article/locales/{en,ja}.md` (first line
|
|
5848
|
+
* `# <title>`, rest the body) between `review` and `variants`. This stage refuses a locale that is
|
|
5849
|
+
* missing, empty, untitled, or still Chinese — an untranslated locale is not a locale — so no bundle
|
|
5850
|
+
* can freeze half-localized. Translating after the freeze would break ADR-053's "publish exactly what
|
|
5851
|
+
* was safety-reviewed and frozen", and translating inside the plugin would put a model call in a
|
|
5852
|
+
* deterministic step, so the gate lives here.
|
|
5853
|
+
*/
|
|
5854
|
+
export function newsLocalizeValidate(args: string[]): void {
|
|
5855
|
+
const [workDir = ''] = args;
|
|
5856
|
+
timed(workDir, 'localize-validate', () => {
|
|
5857
|
+
const localesDir = join(workDir, '22-article', 'locales');
|
|
5858
|
+
const accepted: string[] = [];
|
|
5859
|
+
const problems: string[] = [];
|
|
5860
|
+
for (const locale of ['en', 'ja'] as const) {
|
|
5861
|
+
const file = join(localesDir, `${locale}.md`);
|
|
5862
|
+
if (!isFile(file)) {
|
|
5863
|
+
problems.push(`${locale}: file missing (${file})`);
|
|
5864
|
+
continue;
|
|
5865
|
+
}
|
|
5866
|
+
const raw = readFileSync(file, 'utf-8');
|
|
5867
|
+
if (raw.trim() === '') {
|
|
5868
|
+
problems.push(`${locale}: file is empty`);
|
|
5869
|
+
continue;
|
|
5870
|
+
}
|
|
5871
|
+
const [firstLine = '', ...rest] = raw.split('\n');
|
|
5872
|
+
const title = firstLine.startsWith('# ') ? firstLine.slice(2).trim() : '';
|
|
5873
|
+
if (title === '') {
|
|
5874
|
+
problems.push(`${locale}: first line must be "# <title>", got "${firstLine.trim().slice(0, 60)}"`);
|
|
5875
|
+
continue;
|
|
5876
|
+
}
|
|
5877
|
+
if (rest.join('\n').trim() === '') {
|
|
5878
|
+
problems.push(`${locale}: body is empty after the title line`);
|
|
5879
|
+
continue;
|
|
5880
|
+
}
|
|
5881
|
+
const untranslated = locale === 'en' ? CJK_TEXT.test(raw) : !KANA_TEXT.test(raw);
|
|
5882
|
+
if (untranslated) {
|
|
5883
|
+
problems.push(
|
|
5884
|
+
`${locale}: untranslated — ${locale === 'en' ? 'the document still carries CJK text' : 'the document has no kana, so it is not Japanese'}`,
|
|
5885
|
+
);
|
|
5886
|
+
continue;
|
|
5887
|
+
}
|
|
5888
|
+
accepted.push(locale);
|
|
5889
|
+
}
|
|
5890
|
+
if (problems.length > 0) {
|
|
5891
|
+
failWith(1, `localize-validate: ${problems.join('; ')} — repair the translation before freezing`);
|
|
5892
|
+
}
|
|
5893
|
+
sted('write', join(localesDir, 'localize-validate.json'), () =>
|
|
5894
|
+
writeJsonText(join(localesDir, 'localize-validate.json'), { ok: true, locales: accepted }),
|
|
5895
|
+
);
|
|
5896
|
+
console.log(`localize-validate: ${accepted.join('/')} translations ready for the freeze`);
|
|
5897
|
+
});
|
|
5898
|
+
}
|
|
5899
|
+
|
|
5037
5900
|
export function dailyTranslateSync(args: string[]): void {
|
|
5038
5901
|
const [workDir = '', runDate = '', pluginsPath = '', zhPathFile = ''] = args;
|
|
5039
5902
|
const sync = join(workDir, '31-publish', `${runDate}_24_translate-sync_sync.json`);
|