@gobing-ai/knowledge-kit 0.1.25 → 0.1.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/dist/index.js +115 -21
  3. package/package.json +1 -1
  4. package/plugins/kk/plugin.json +1 -1
  5. package/plugins/kk/scripts/cn-lead-gate.ts +494 -0
  6. package/plugins/kk/scripts/daily-stages.ts +416 -134
  7. package/plugins/kk/scripts/kk-workflow-stages.ts +53 -3
  8. package/plugins/kk/skills/news-editorial/SKILL.md +20 -3
  9. package/plugins/kk/skills/news-editorial/references/selection.md +42 -0
  10. package/plugins/publishings/bilibili-pub/dist/index.js +33 -2
  11. package/plugins/publishings/bilibili-pub/dist/profile-check.js +33 -2
  12. package/plugins/publishings/cnblogs-pub/dist/index.js +33 -2
  13. package/plugins/publishings/cnblogs-pub/dist/profile-check.js +33 -2
  14. package/plugins/publishings/csdn-pub/dist/index.js +33 -2
  15. package/plugins/publishings/csdn-pub/dist/profile-check.js +33 -2
  16. package/plugins/publishings/infoq-pub/dist/index.js +33 -2
  17. package/plugins/publishings/infoq-pub/dist/profile-check.js +33 -2
  18. package/plugins/publishings/jike-pub/dist/index.js +33 -2
  19. package/plugins/publishings/jike-pub/dist/profile-check.js +33 -2
  20. package/plugins/publishings/juejin-pub/dist/index.js +33 -2
  21. package/plugins/publishings/juejin-pub/dist/profile-check.js +33 -2
  22. package/plugins/publishings/linkedin-pub/dist/index.js +84 -13
  23. package/plugins/publishings/linkedin-pub/dist/profile-check.js +50 -5
  24. package/plugins/publishings/linkedin-pub/src/index.ts +126 -9
  25. package/plugins/publishings/medium-pub/dist/index.js +33 -2
  26. package/plugins/publishings/medium-pub/dist/profile-check.js +33 -2
  27. package/plugins/publishings/shipinhao-pub/dist/index.js +33 -2
  28. package/plugins/publishings/shipinhao-pub/dist/profile-check.js +33 -2
  29. package/plugins/publishings/sspai-pub/dist/index.js +33 -2
  30. package/plugins/publishings/sspai-pub/dist/profile-check.js +33 -2
  31. package/plugins/publishings/substack-pub/dist/index.js +33 -2
  32. package/plugins/publishings/substack-pub/dist/profile-check.js +33 -2
  33. package/plugins/publishings/surfdash-pub/dist/index.js +53 -15
  34. package/plugins/publishings/surfdash-pub/src/index.ts +31 -4
  35. package/plugins/publishings/surfdash-pub/src/patch.ts +81 -12
  36. package/plugins/publishings/threads-pub/dist/index.js +33 -2
  37. package/plugins/publishings/threads-pub/dist/profile-check.js +33 -2
  38. package/plugins/publishings/wechatmp-pub/dist/index.js +65 -3
  39. package/plugins/publishings/wechatmp-pub/dist/profile-check.js +67 -3
  40. package/plugins/publishings/wechatmp-pub/src/index.ts +64 -1
  41. package/plugins/publishings/weibo-pub/dist/index.js +56 -8
  42. package/plugins/publishings/weibo-pub/dist/profile-check.js +55 -8
  43. package/plugins/publishings/weibo-pub/plugin.json +1 -1
  44. package/plugins/publishings/weibo-pub/src/index.ts +76 -8
  45. package/plugins/publishings/x-pub/dist/index.js +33 -2
  46. package/plugins/publishings/x-pub/dist/profile-check.js +33 -2
  47. package/plugins/publishings/xhs-pub/dist/index.js +33 -2
  48. package/plugins/publishings/xhs-pub/dist/profile-check.js +33 -2
  49. package/plugins/publishings/xiaoyuzhou-pub/dist/index.js +33 -2
  50. package/plugins/publishings/xiaoyuzhou-pub/dist/profile-check.js +33 -2
@@ -67,6 +67,7 @@ import {
67
67
  writeFileSync,
68
68
  } from 'node:fs';
69
69
  import { basename, isAbsolute, join, resolve } from 'node:path';
70
+ import { checkCnLeadPlan, enforceCnLead } from './cn-lead-gate.ts';
70
71
  import {
71
72
  EPISODE_IDENTITY_KEY,
72
73
  type EpisodeIdentity,
@@ -161,7 +162,10 @@ export function dailyQcContent(args: string[]): void {
161
162
  ? String(
162
163
  Math.max(
163
164
  0,
164
- Math.ceil(((floorMinutes * 60 - 8) * spokenCharRate(vdriver)) / readKeptRatio(workDir).ratio),
165
+ Math.ceil(
166
+ ((floorMinutes * 60 - 8) * spokenCharRate(vdriver)) /
167
+ readSpokenCalibration(workDir).keptRatio,
168
+ ),
165
169
  ),
166
170
  )
167
171
  : '';
@@ -384,119 +388,120 @@ const SPEAK_CHAR_EXPANSION = 1.4;
384
388
  * (0377).
385
389
  *
386
390
  * This constant is only the fallback: both gates prefer the ratio a previous run recorded, and the
387
- * two records carry DIFFERENT denominators (see `readKeptRatio` — using one ratio for both was the
388
- * 2026-11-16 refusal of a 23-min episode).
391
+ * two records carry DIFFERENT denominators (see `readSpokenCalibration` — using one ratio for both
392
+ * was the 2026-11-16 refusal of a 23-min episode).
389
393
  */
390
394
  const SPEAK_CHAR_EXPANSION_FLOOR = 0.28;
391
395
 
392
396
  /**
393
- * Where a run records the ratios it actually delivered (0377 R2/R3). Two denominators, because the
394
- * two pre-spend consumers measure different sets: `ratio` is spoken/pool (the ladder, which judges
395
- * the raw extracted pool) and `keptRatio` is spoken/kept-candidate chars (the floor gate, which
396
- * judges what QC actually admitted). The gates read the newest record from the sibling run
397
- * directories, so they judge today's material by what the writer really produced last time instead
398
- * of a constant that was calibrated once.
397
+ * Where a run records the measures it actually delivered (0377 R2/R3, extended by 0434). Three
398
+ * numbers, because the two pre-spend consumers measure different sets and the ladder has to bridge
399
+ * them: `ratio` is spoken/pool, `keptRatio` is spoken/kept-candidate chars (the floor gate's
400
+ * denominator), and `keepRate` is kept/pool — the admission rate that converts one into the other.
401
+ * The gates read the newest record from the sibling run directories, so they judge today's material
402
+ * by what the writer really produced last time instead of a constant that was calibrated once.
399
403
  */
400
404
  const SPOKEN_RATIO_SUFFIX = '_09_spoken-ratio.json';
401
405
 
402
- /** The measured ratio one run delivered, and where it came from. */
403
- interface SpokenRatio {
404
- ratio: number;
406
+ /**
407
+ * The cold-start QC admission rate — kept-candidate chars over raw pool chars — the widen ladder
408
+ * projects with when no run has recorded one (0434).
409
+ *
410
+ * Measured: 2026-11-16 13,963/38,241 kept = 0.37, 2026-11-24 12,937/42,925 = 0.30. The LOW end, by
411
+ * the same "worst measured" argument the ratio constants make above: the ladder's cheap error is a
412
+ * rung too many, and its expensive one is an authoring pass the floor gate then refuses because the
413
+ * admitted set was never as large as the pool suggested.
414
+ */
415
+ const KEEP_RATE_FLOOR = 0.3;
416
+
417
+ /**
418
+ * How far today's QC admission rate may move from the rate the estimate projected with before the
419
+ * run reports it (0434 R3). The 2026-11-24 run moved 22 points below its recorded day and nothing
420
+ * said so: the ladder's 22.8 min estimate was absorbed as if it were still calibrated.
421
+ */
422
+ const KEEP_RATE_DRIFT_BOUND = 0.05;
423
+
424
+ /** One measured rate and where it came from — every artifact prints the pair (0434 R2). */
425
+ interface KeepRate {
426
+ rate: number;
405
427
  source: string;
406
428
  }
407
429
 
430
+ /**
431
+ * A run's recorded calibration, read in one scan: both denominators the gates multiply by, and the
432
+ * admission rate that converts a raw pool into the set the floor gate measures (0434 R1).
433
+ *
434
+ * `poolRatio` is spoken/raw pool chars, `keptRatio` is spoken/kept-candidate chars, and `keepRate` is
435
+ * kept-candidate/raw pool chars, so `poolRatio === keepRate × keptRatio` for a self-consistent
436
+ * record. The ladder projects `poolChars × keepRate` and multiplies by `keptRatio`; the floor gate
437
+ * multiplies the chars it actually sees by `keptRatio`. One arithmetic, one denominator.
438
+ */
439
+ interface SpokenCalibration {
440
+ /** spoken / raw pool chars. */
441
+ poolRatio: number;
442
+ /** spoken / kept-candidate chars — what every kept-set estimate multiplies by. */
443
+ keptRatio: number;
444
+ /** kept-candidate chars / raw pool chars. */
445
+ keepRate: number;
446
+ poolRatioSource: string;
447
+ keptRatioSource: string;
448
+ keepRateSource: string;
449
+ }
450
+
408
451
  /** Clamp a recorded ratio into a plausible band: a corrupt file must not freeze or flood the ladder. */
409
452
  function clampRatio(value: number): number {
410
453
  return Math.min(2, Math.max(0.05, value));
411
454
  }
412
455
 
413
- /**
414
- * The newest recorded spoken/raw ratio across this workflow's run directories, or the calibrated
415
- * floor constant when no run has recorded one yet. `workDir` is one run directory, so its parent is
416
- * the workflow directory the sibling runs live in.
417
- */
418
- function readSpokenRatio(workDir: string): SpokenRatio {
419
- const base = resolve(workDir, '..');
420
- let newest: { at: number; ratio: number; from: string } | null = null;
421
- let entries: string[] = [];
422
- try {
423
- entries = readdirSync(base);
424
- } catch {
425
- return { ratio: SPEAK_CHAR_EXPANSION_FLOOR, source: 'default 0.28 (no sibling runs)' };
426
- }
427
- // Best-effort calibration only: a test workdir or an operator scratch dir may sit directly in a
428
- // shared temp parent with hundreds of thousands of entries. Scanning each one took 20–40s per QC
429
- // stage (measured 2026-11-23 on a 556k-entry tempdir), so skip the sibling calibration instead of
430
- // blocking the run. Normal works roots have far fewer runs and keep the newest-ratio behavior.
431
- if (entries.length > 5_000)
432
- return {
433
- ratio: SPEAK_CHAR_EXPANSION_FLOOR,
434
- source: `default 0.28 (sibling scan skipped: ${entries.length} entries)`,
435
- };
436
- for (const entry of entries) {
437
- const dir = join(base, entry, '21-plan');
438
- let files: string[] = [];
439
- try {
440
- files = readdirSync(dir).filter((file) => file.endsWith(SPOKEN_RATIO_SUFFIX));
441
- } catch {
442
- continue;
443
- }
444
- for (const file of files) {
445
- const path = join(dir, file);
446
- try {
447
- const parsed = readJson(path) as Record<string, unknown> | null;
448
- const ratio = Number(parsed?.ratio);
449
- if (!Number.isFinite(ratio) || ratio <= 0) continue;
450
- const at = statSync(path).mtimeMs;
451
- if (newest === null || at > newest.at) newest = { at, ratio, from: path };
452
- } catch {
453
- // A malformed record is not evidence; the next run overwrites it.
454
- }
455
- }
456
- }
457
- if (newest === null) return { ratio: SPEAK_CHAR_EXPANSION_FLOOR, source: 'default 0.28 (no recorded run)' };
458
- return { ratio: clampRatio(newest.ratio), source: `${newest.from} (${newest.ratio.toFixed(2)}x)` };
456
+ /** Clamp a recorded admission rate: zero admits nothing, and >1 is not an admission rate. */
457
+ function clampKeepRate(value: number): number {
458
+ return Math.min(1, Math.max(0.01, value));
459
+ }
460
+
461
+ /** One recorded ratio file, parsed into the three measures the gates need. Null fields are absent. */
462
+ interface RatioRecord {
463
+ path: string;
464
+ at: number;
465
+ poolRatio: number | null;
466
+ keptRatio: number | null;
467
+ keepRate: number | null;
459
468
  }
460
469
 
461
470
  /**
462
- * The newest recorded spoken/KEPT ratio across sibling runs, or the cold-start constant.
471
+ * The newest recorded spoken-ratio artifacts across this workflow's sibling run directories.
463
472
  *
464
- * WHY this is separate from `readSpokenRatio` (2026-11-16): one constant was applied to two
465
- * different denominators. The ladder multiplies the raw pool (38,241 chars that day) while this gate
466
- * multiplies the kept candidates (13,963 chars — planning admitted 37% of the pool), so the same
467
- * 0.28 read as a 34.5 min "clears" in the ladder and a 12.7 min "refusing" at the gate, and the run
468
- * paid for the planning pass to discover it. The writer then delivered 7,194 spoken chars ≈ 23 min:
469
- * the refusal discounted the planning shrink twice. `keptRatio` for that run is 0.515.
473
+ * One scan serves all three measures (0434): the two ratio readers it replaces used to walk the
474
+ * same directories separately with two different size guards, so a large workspace could calibrate
475
+ * the ladder from one run and the floor gate from another.
470
476
  */
471
- function readKeptRatio(workDir: string): SpokenRatio {
477
+ function ratioRecords(workDir: string): RatioRecord[] {
478
+ // `workDir` is one run directory, so its parent is the workflow directory the siblings live in.
472
479
  const base = resolve(workDir, '..');
473
- let newest: { at: number; ratio: number; from: string } | null = null;
474
480
  let entries: string[] = [];
475
481
  try {
476
- // A shared temp parent can hold hundreds of thousands of directories. Read names once and
477
- // open only run-shaped candidates past the small-workspace threshold; opening every one took
478
- // 20–40s per QC stage (556k entries measured 2026-11-23).
479
482
  entries = readdirSync(base);
480
483
  } catch {
481
- return { ratio: SPEAK_CHAR_EXPANSION_FLOOR, source: 'default 0.28 (no sibling runs)' };
484
+ return [];
482
485
  }
483
- const ratioFiles: string[] = [];
486
+ const paths: string[] = [];
484
487
  if (entries.length > 5_000) {
485
- // Native globbing skips the non-run directories instead of opening each of them in JS. The
486
- // `kk-*` form measured ~2s on that same parent; a bare `*` can hit broken symlinks.
488
+ // A shared temp parent can hold hundreds of thousands of directories. Read names once and
489
+ // let native globbing skip the non-run ones instead of opening each in JS; the `kk-*` form
490
+ // measured ~2s on a 556k-entry parent while opening every entry took 20–40s per stage
491
+ // (2026-11-23). A bare `*` can hit broken symlinks, so the two run-shaped patterns are it.
487
492
  for (const pattern of [`kk-*/21-plan/*${SPOKEN_RATIO_SUFFIX}`, `20??????/21-plan/*${SPOKEN_RATIO_SUFFIX}`]) {
488
493
  try {
489
- ratioFiles.push(...new Bun.Glob(pattern).scanSync({ cwd: base, onlyFiles: true, absolute: true }));
494
+ paths.push(...new Bun.Glob(pattern).scanSync({ cwd: base, onlyFiles: true, absolute: true }));
490
495
  } catch {
491
496
  // Best-effort calibration: a shared temp parent holds dangling symlinks and dirs that
492
- // vanish mid-scan (ENOENT from the glob walk), which must never fail the QC stage.
497
+ // vanish mid-scan (ENOENT from the glob walk), which must never fail a stage.
493
498
  }
494
499
  }
495
500
  } else {
496
501
  for (const entry of entries) {
497
502
  const dir = join(base, entry, '21-plan');
498
503
  try {
499
- ratioFiles.push(
504
+ paths.push(
500
505
  ...readdirSync(dir)
501
506
  .filter((file) => file.endsWith(SPOKEN_RATIO_SUFFIX))
502
507
  .map((file) => join(dir, file)),
@@ -506,27 +511,157 @@ function readKeptRatio(workDir: string): SpokenRatio {
506
511
  }
507
512
  }
508
513
  }
509
- for (const path of ratioFiles) {
514
+ const records: RatioRecord[] = [];
515
+ for (const path of paths) {
510
516
  try {
511
517
  const parsed = readJson(path) as Record<string, unknown> | null;
512
- // A pre-2026-11-16 record carries no kept ratio at all: skip it rather than divide by
513
- // its pool figure, which is what produced the double discount.
514
- const ratio = Number(parsed?.keptRatio);
515
- if (!Number.isFinite(ratio) || ratio <= 0) continue;
516
- const at = statSync(path).mtimeMs;
517
- if (newest === null || at > newest.at) newest = { at, ratio, from: path };
518
+ if (parsed === null || typeof parsed !== 'object') continue;
519
+ const positive = (value: unknown): number | null => {
520
+ const number = Number(value);
521
+ return Number.isFinite(number) && number > 0 ? number : null;
522
+ };
523
+ const poolChars = positive(parsed.poolChars);
524
+ const keptChars = positive(parsed.keptChars);
525
+ const poolRatio = positive(parsed.ratio);
526
+ const keptRatio = positive(parsed.keptRatio);
527
+ records.push({
528
+ path,
529
+ at: statSync(path).mtimeMs,
530
+ poolRatio,
531
+ keptRatio,
532
+ keepRate: recordKeepRate(parsed, poolChars, keptChars, poolRatio, keptRatio),
533
+ });
518
534
  } catch {
519
535
  // A malformed record is not evidence; the next run overwrites it.
520
536
  }
521
537
  }
522
- if (newest === null) return { ratio: SPEAK_CHAR_EXPANSION_FLOOR, source: 'default 0.28 (no recorded kept ratio)' };
523
- return { ratio: clampRatio(newest.ratio), source: `${newest.from} (${newest.ratio.toFixed(2)}x)` };
538
+ return records;
524
539
  }
525
540
 
526
541
  /**
527
- * Record what this run delivered — spoken script chars over raw pool chars, and over the kept
528
- * candidates — and warn when it drifted from the ratio the widen decision used. A refused script
529
- * records too: a thin day teaches the ladder even though it produced no episode.
542
+ * The QC admission rate one record implies: kept/pool when both char counts were recorded, else the
543
+ * quotient of the two ratios (`spoken/pool ÷ spoken/kept`), else a rate a later writer stamped.
544
+ * A pre-2026-11-16 record carries only the pool ratio, so it yields no admission rate — which is
545
+ * exactly right: it never measured one (the double discount of 2026-11-16).
546
+ */
547
+ function recordKeepRate(
548
+ parsed: Record<string, unknown>,
549
+ poolChars: number | null,
550
+ keptChars: number | null,
551
+ poolRatio: number | null,
552
+ keptRatio: number | null,
553
+ ): number | null {
554
+ if (poolChars !== null && keptChars !== null) return clampKeepRate(keptChars / poolChars);
555
+ if (poolRatio !== null && keptRatio !== null) return clampKeepRate(poolRatio / keptRatio);
556
+ const stamped = Number(parsed.keepRate);
557
+ return Number.isFinite(stamped) && stamped > 0 ? clampKeepRate(stamped) : null;
558
+ }
559
+
560
+ /**
561
+ * The calibration the pre-spend estimates use, each measure taken from the newest record that
562
+ * carries it and each falling back to its cold-start constant with a `default …` provenance.
563
+ *
564
+ * WHY one record for all three (0434): the ladder and the floor gate must multiply the SAME
565
+ * denominator. A pool-denominated ratio applied to the admitted set discounted planning's shrink
566
+ * twice (2026-11-16: gate said 12.7 min, the writer delivered 23); a pool ratio the ladder reads
567
+ * alone is only the gate's arithmetic when today's admission rate matches the recorded day
568
+ * (2026-11-24: ladder 22.8 min, gate 13.1, delivered 12.6).
569
+ */
570
+ function readSpokenCalibration(workDir: string): SpokenCalibration {
571
+ const records = ratioRecords(workDir);
572
+ /** The value and path of the newest record that measured `field`, or null when none did. */
573
+ const newestWith = (field: 'poolRatio' | 'keptRatio' | 'keepRate'): { value: number; path: string } | null => {
574
+ let newest: RatioRecord | null = null;
575
+ for (const record of records) {
576
+ if (record[field] === null) continue;
577
+ if (newest === null || record.at > newest.at) newest = record;
578
+ }
579
+ if (newest === null) return null;
580
+ const value = newest[field];
581
+ return value === null ? null : { value, path: newest.path };
582
+ };
583
+ const pool = newestWith('poolRatio');
584
+ const kept = newestWith('keptRatio');
585
+ const rate = newestWith('keepRate');
586
+ const fallback = SPEAK_CHAR_EXPANSION_FLOOR.toFixed(2);
587
+ return {
588
+ poolRatio: pool === null ? SPEAK_CHAR_EXPANSION_FLOOR : clampRatio(pool.value),
589
+ poolRatioSource:
590
+ pool === null ? `default ${fallback} (no recorded pool ratio)` : `${pool.path} (${pool.value.toFixed(2)}x)`,
591
+ keptRatio: kept === null ? SPEAK_CHAR_EXPANSION_FLOOR : clampRatio(kept.value),
592
+ keptRatioSource:
593
+ kept === null ? `default ${fallback} (no recorded kept ratio)` : `${kept.path} (${kept.value.toFixed(2)}x)`,
594
+ keepRate: rate === null ? KEEP_RATE_FLOOR : rate.value,
595
+ keepRateSource:
596
+ rate === null
597
+ ? `default ${KEEP_RATE_FLOOR.toFixed(2)} (no recorded keep rate)`
598
+ : `${rate.path} (kept ${rate.value.toFixed(2)} of pool)`,
599
+ };
600
+ }
601
+
602
+ /**
603
+ * The keep rate the widen ladder projected today's admitted set from — the assumption every
604
+ * downstream estimate inherits. Read from the ladder artifact itself (what actually ran), falling
605
+ * back to the recorded calibration when the extract stage left no ladder behind.
606
+ */
607
+ function assumedKeepRate(workDir: string, calibration: SpokenCalibration): KeepRate {
608
+ const ladder = readJson(join(workDir, '10-collect', 'ladder.json')) as Record<string, unknown> | null;
609
+ const rate = Number(ladder?.keepRate);
610
+ if (Number.isFinite(rate) && rate > 0) {
611
+ const source = typeof ladder?.keepRateSource === 'string' ? ladder.keepRateSource : 'ladder.json';
612
+ return { rate: clampKeepRate(rate), source };
613
+ }
614
+ return { rate: calibration.keepRate, source: calibration.keepRateSource };
615
+ }
616
+
617
+ /**
618
+ * The admission rate this run achieved, measured from the pool it extracted and the set QC admitted
619
+ * — null when either artifact is missing (a workspace that never ran extract has no pool to divide).
620
+ */
621
+ function observedKeepRate(workDir: string, keptChars: number): KeepRate | null {
622
+ const poolPath = join(workDir, '10-collect', 'pool.json');
623
+ if (!isFile(poolPath) || keptChars <= 0) return null;
624
+ const pool = readJson(poolPath);
625
+ const poolChars = rawChars(Array.isArray(pool) ? pool : []);
626
+ if (poolChars <= 0) return null;
627
+ return { rate: keptChars / poolChars, source: `${poolPath} (${keptChars} kept of ${poolChars})` };
628
+ }
629
+
630
+ /** A measured admission rate, the rate an estimate assumed, and how far apart they are (0434 R3). */
631
+ interface KeepRateDrift {
632
+ observed: KeepRate;
633
+ assumed: KeepRate;
634
+ /** observed − assumed: negative means QC admitted less than the estimate believed. */
635
+ delta: number;
636
+ beyondBound: boolean;
637
+ }
638
+
639
+ /**
640
+ * Compare the keep rate an estimate assumed against the one this run measured, and REPORT the
641
+ * difference beyond `KEEP_RATE_DRIFT_BOUND` instead of letting the estimate absorb it (0434 R3).
642
+ *
643
+ * A silently absorbed drift is what made the 2026-11-24 recovery decision impossible: 63 pool items
644
+ * forecast 22.8 min, the admitted 18 could make 13.1, and the run measured 12.6 — three numbers a
645
+ * human had to reconcile by hand.
646
+ */
647
+ function keepRateDrift(assumed: KeepRate, observed: KeepRate | null, label: string): KeepRateDrift | null {
648
+ if (observed === null) return null;
649
+ const delta = observed.rate - assumed.rate;
650
+ const beyondBound = Math.abs(delta) > KEEP_RATE_DRIFT_BOUND;
651
+ if (beyondBound) {
652
+ const direction = delta < 0 ? 'over-predicts' : 'under-predicts';
653
+ console.error(
654
+ `keep rate drifted: QC admitted ${Math.round(observed.rate * 100)}% of the pool, the ${label} estimate assumed ${Math.round(assumed.rate * 100)}% (${assumed.source}) — the estimate ${direction} the episode by ~${Math.round((Math.abs(delta) / assumed.rate) * 100)}%; re-read it before trusting it`,
655
+ );
656
+ }
657
+ return { observed, assumed, delta, beyondBound };
658
+ }
659
+
660
+ /**
661
+ * Record what this run delivered — spoken script chars over raw pool chars, over the kept
662
+ * candidates, and the admission rate between them — and warn when it drifted from the estimate the
663
+ * widen decision used. A refused script records too: a thin day teaches the ladder even though it
664
+ * produced no episode.
530
665
  */
531
666
  function recordSpokenRatio(workDir: string, runDate: string, spokenChars: number): void {
532
667
  const poolPath = join(workDir, '10-collect', 'pool.json');
@@ -545,23 +680,34 @@ function recordSpokenRatio(workDir: string, runDate: string, spokenChars: number
545
680
  writeJsonText(out, {
546
681
  runDate,
547
682
  poolChars,
548
- ...(keptChars > 0 ? { keptChars, keptRatio: round3(spokenChars / keptChars) } : {}),
683
+ // The admission rate is recorded explicitly (0434) so the next day's ladder projects the
684
+ // admitted set from a measured number instead of re-deriving it from the two ratios.
685
+ ...(keptChars > 0
686
+ ? { keptChars, keptRatio: round3(spokenChars / keptChars), keepRate: round3(keptChars / poolChars) }
687
+ : {}),
549
688
  spokenChars,
550
689
  ratio,
551
690
  });
552
- // Drift warning: the ladder judged this pool with some ratio; the writer just delivered a
553
- // different one. A wide gap means the next run's ladder is working from a stale measure.
691
+ // Drift warning: the ladder projected this pool at some spoken-chars-per-pool-char; the writer
692
+ // just delivered a different one. A wide gap means the next run's ladder is working from a stale
693
+ // measure. Compare against the projection the ladder actually made (keep rate × kept ratio) and
694
+ // fall back to the pool ratio a pre-0434 ladder recorded.
554
695
  let used: number | null = null;
555
696
  try {
556
697
  const ladder = readJson(join(workDir, '10-collect', 'ladder.json')) as Record<string, unknown> | null;
557
- const candidate = Number(ladder?.ratioUsed);
558
- if (Number.isFinite(candidate) && candidate > 0) used = candidate;
698
+ for (const key of ['spokenPerPoolChar', 'ratioUsed']) {
699
+ const candidate = Number(ladder?.[key]);
700
+ if (Number.isFinite(candidate) && candidate > 0) {
701
+ used = candidate;
702
+ break;
703
+ }
704
+ }
559
705
  } catch {
560
706
  used = null;
561
707
  }
562
708
  if (used !== null && Math.abs(ratio / used - 1) > 0.25) {
563
709
  console.error(
564
- `spoken ratio drifted: this run delivered ${ratio.toFixed(2)}x of the pool, the ladder widened on ${used.toFixed(2)}x (see ${out})`,
710
+ `spoken ratio drifted: this run delivered ${ratio.toFixed(2)}x of the pool, the ladder projected ${used.toFixed(2)}x (see ${out})`,
565
711
  );
566
712
  }
567
713
  }
@@ -575,24 +721,47 @@ function rawChars(docs: unknown[]): number {
575
721
  }
576
722
 
577
723
  /**
578
- * The calibrated estimate over a kept pool (title+body characters × the recorded spoken/kept ratio,
579
- * over the driver's measured char rate, plus the 8 s intro sting) — shared by the pre-spend floor
580
- * gate (applyFloorGate) and the post-spend duration refusal (dailyEpisodeDuration, 0266), so both
581
- * artifacts report the same arithmetic. `seconds` is unrounded: the floor gate compares seconds.
724
+ * THE spoken-length arithmetic (0434): a spoken-char count × the ratio that set is denominated in,
725
+ * over the driver's measured char rate, plus the 8 s intro sting. Every estimate in this file is
726
+ * this one function — the floor gate and the post-spend refusal hand it the chars QC admitted, the
727
+ * ladder hands it the chars it projects QC will admit. `seconds` is unrounded: the floor gate
728
+ * compares seconds, the artifacts report minutes.
729
+ */
730
+ function spokenLength(
731
+ chars: number,
732
+ expansion: number,
733
+ vdriver: string,
734
+ ): { minutes: number; seconds: number; chars: number } {
735
+ const seconds = 8 + (chars * expansion) / spokenCharRate(vdriver);
736
+ return { minutes: Math.round((seconds / 60) * 10) / 10, seconds, chars };
737
+ }
738
+
739
+ /**
740
+ * The calibrated estimate over a kept pool (title+body characters × the recorded spoken/kept ratio)
741
+ * — shared by the pre-spend floor gate (applyFloorGate) and the post-spend duration refusal
742
+ * (dailyEpisodeDuration, 0266), so both artifacts report the same arithmetic.
582
743
  *
583
- * Both callers must pass `readKeptRatio(...).ratio`. The 1.4 default is the pre-2026-11-16
584
- * raw-script expansion and is ~4.5x too high for the scripted writer: leaving it on the duration
585
- * refusal made the 2026-11-24 artifact claim a "pre-spend estimate 58.2 min" beside a measured
586
- * 12.6 min, which is the number an operator reads when deciding whether to recover the day.
744
+ * Both callers must pass `readSpokenCalibration(...).keptRatio`: this measures the ADMITTED set,
745
+ * which is what the kept ratio was measured on. The 1.4 default is the pre-2026-11-16 raw-script
746
+ * expansion and is ~4.5x too high for the scripted writer: leaving it on the duration refusal made
747
+ * the 2026-11-24 artifact claim a "pre-spend estimate 58.2 min" beside a measured 12.6 min, which is
748
+ * the number an operator reads when deciding whether to recover the day.
587
749
  */
588
750
  function estimateSpokenMinutes(
589
751
  docs: unknown[],
590
752
  vdriver: string,
591
753
  expansion: number = SPEAK_CHAR_EXPANSION,
592
754
  ): { minutes: number; seconds: number; chars: number } {
593
- const chars = rawChars(docs);
594
- const seconds = 8 + (chars * expansion) / spokenCharRate(vdriver);
595
- return { minutes: Math.round((seconds / 60) * 10) / 10, seconds, chars };
755
+ return spokenLength(rawChars(docs), expansion, vdriver);
756
+ }
757
+
758
+ /**
759
+ * The admitted set a raw pool should yield (0434 R1): the ladder's denominator bridge. A pool is not
760
+ * an episode — QC admits a share of it, and multiplying the whole pool by a spoken/pool ratio only
761
+ * matches the floor gate's arithmetic on the day the admission rate was recorded.
762
+ */
763
+ function projectKeptChars(poolChars: number, keepRate: number): number {
764
+ return Math.round(poolChars * keepRate);
596
765
  }
597
766
 
598
767
  /**
@@ -606,9 +775,12 @@ function estimateSpokenMinutes(
606
775
  * closes through run-report and the ledger exactly like an empty pool. The estimate and its inputs
607
776
  * land in a refusal artifact next to the candidates.
608
777
  *
609
- * The ratio comes from `readKeptRatio`, NOT the pool-denominated one the ladder uses: this gate
610
- * measures the admitted set, and applying the pool ratio to it discounted the planning shrink twice
611
- * (2026-11-16: estimated 12.7 min, the writer delivered 23).
778
+ * The ratio comes from `readSpokenCalibration(...).keptRatio`, NOT the pool-denominated one: this
779
+ * gate measures the admitted set, and applying the pool ratio to it discounted the planning shrink
780
+ * twice (2026-11-16: estimated 12.7 min, the writer delivered 23). The extraction ladder projects
781
+ * that same admitted set with the same ratio (0434), so the two artifacts agree by construction; the
782
+ * one number the projection cannot know is today's admission rate, which this gate measures and
783
+ * reports when it drifts past `KEEP_RATE_DRIFT_BOUND`.
612
784
  */
613
785
  function applyFloorGate(
614
786
  candidates: string,
@@ -630,12 +802,20 @@ function applyFloorGate(
630
802
  if (clearStaleRefusal && isFile(refusal)) unlinkSync(refusal);
631
803
  return;
632
804
  }
633
- const keptRatio = readKeptRatio(workDir);
805
+ const calibration = readSpokenCalibration(workDir);
634
806
  const {
635
807
  minutes: estimatedMinutes,
636
808
  seconds: estimatedSeconds,
637
809
  chars,
638
- } = estimateSpokenMinutes(docs, vdriver, keptRatio.ratio);
810
+ } = estimateSpokenMinutes(docs, vdriver, calibration.keptRatio);
811
+ // 0434 R3: today's admitted share of the pool is measurable here for the first time — the ladder
812
+ // projected it from the recorded day. A drift beyond the bound is reported, never absorbed.
813
+ const assumed = assumedKeepRate(workDir, calibration);
814
+ const observed = observedKeepRate(workDir, chars);
815
+ const drift = keepRateDrift(assumed, observed, 'ladder');
816
+ // 0434 R2: one line an operator can compare against the ladder artifact without recomputing —
817
+ // the ratio, the path it came from, and the admission rate the estimate was built on.
818
+ const basis = `${calibration.keptRatio.toFixed(2)}x kept ratio (${calibration.keptRatioSource}), keep rate ${Math.round((observed?.rate ?? assumed.rate) * 100)}%`;
639
819
  if (estimatedSeconds >= floor * 60) {
640
820
  if (clearStaleRefusal && isFile(refusal)) unlinkSync(refusal);
641
821
  // Task 0392 R2: the floor gate observed this pool and admitted it — a stage that ran and
@@ -643,7 +823,9 @@ function applyFloorGate(
643
823
  recordSelectionStage(workDir, runDate, {
644
824
  stages: [{ stage: 'floor', input: docs.length, kept: docs.length, dropped: [] }],
645
825
  });
646
- console.log(`floor gate: estimated ${estimatedMinutes} min from ${chars} chars — above the ${floor} min floor`);
826
+ console.log(
827
+ `floor gate: estimated ${estimatedMinutes} min from ${chars} chars at ${basis} — above the ${floor} min floor`,
828
+ );
647
829
  return;
648
830
  }
649
831
  const ids = docs.map((doc) => String((doc as Record<string, unknown> | null)?.id ?? ''));
@@ -659,18 +841,25 @@ function applyFloorGate(
659
841
  candidateChars: chars,
660
842
  // The ratio this refusal actually used, and where it came from (0377; 2026-11-16): the
661
843
  // gate measures the KEPT set, so a pool-denominated ratio under-predicts it badly.
662
- expansion: keptRatio.ratio,
663
- expansionSource: keptRatio.source,
844
+ expansion: calibration.keptRatio,
845
+ expansionSource: calibration.keptRatioSource,
846
+ // 0434 R2/R3: the admission rate this run achieved, the rate the ladder projected with,
847
+ // and the gap — so the refusal and the ladder artifact explain each other.
848
+ keepRate: observed?.rate ?? null,
849
+ keepRateSource: observed?.source ?? null,
850
+ keepRateAssumed: assumed.rate,
851
+ keepRateAssumedSource: assumed.source,
852
+ keepRateDrift: drift?.delta ?? null,
664
853
  charRate: spokenCharRate(vdriver),
665
854
  ids,
666
- reason: `a ${docs.length}-item pool estimates ${estimatedMinutes} min of speech, below the ${floor} min floor — refusing before any TTS spend`,
855
+ reason: `a ${docs.length}-item pool estimates ${estimatedMinutes} min of speech at ${basis}, below the ${floor} min floor — refusing before any TTS spend`,
667
856
  }),
668
857
  );
669
858
  sted('write', candidates, () =>
670
859
  writeJsonText(candidates, { ...(content ?? {}), metadata: { ...metadataOf(content), docs: [] } }),
671
860
  );
672
861
  console.error(
673
- `floor gate: ${docs.length} candidates estimate ${estimatedMinutes} min < ${floor} min — candidates emptied, the run closes as no-content (see ${refusal})`,
862
+ `floor gate: ${docs.length} candidates estimate ${estimatedMinutes} min at ${basis} < ${floor} min — candidates emptied, the run closes as no-content (see ${refusal})`,
674
863
  );
675
864
  }
676
865
 
@@ -756,36 +945,68 @@ export function dailyExtract(args: string[]): void {
756
945
  console.error(`extract: plan already authored — keeping the frozen pool (${poolPath})`);
757
946
  return;
758
947
  }
759
- // 0377 R2: judge the pool by what the writer actually delivered last time. The calibrated
760
- // 0.28 constant is only the fallback for a workflow that has never recorded a ratio.
761
- const ratio = readSpokenRatio(workDir);
948
+ // 0377 R2 + 0434 R1: judge the pool by what the writer actually delivered last time, in the
949
+ // denominator the floor gate measures. The calibrated constants are only the fallback for a
950
+ // workflow that has never recorded either ratio.
951
+ const calibration = readSpokenCalibration(workDir);
762
952
  let chosen: { window: string; docs: unknown[] } | null = null;
763
- const rungs: Array<{ window: string; items: number; chars: number; minutes: number; clears: boolean }> = [];
953
+ const rungs: Array<{
954
+ window: string;
955
+ items: number;
956
+ chars: number;
957
+ keptChars: number;
958
+ minutes: number;
959
+ clears: boolean;
960
+ }> = [];
764
961
  for (const ms of windows) {
765
962
  const label = formatWindowMs(ms);
766
963
  const attempt = join(workDir, '10-collect', `.pool-${label}.json`);
767
964
  kk(['store', 'extract', '--topic', topic, '--window', label, '--out', attempt, ...limit]);
768
965
  const parsed = readJson(attempt);
769
966
  const docs = Array.isArray(parsed) ? (parsed as unknown[]) : [];
770
- const estimate = estimateSpokenMinutes(docs, vdriver, ratio.ratio);
967
+ // 0434 R1: a pool is not an episode. Estimate the set QC will ADMIT — the pool projected
968
+ // through the recording run's admission rate — and convert it at the spoken/kept ratio,
969
+ // which is the same arithmetic the floor gate applies to the set it actually receives.
970
+ // Multiplying the whole pool by a spoken/pool ratio only agrees with the gate on a day
971
+ // whose admission rate matches the recorded one: 2026-11-24 forecast 22.8 min off a
972
+ // 42,925-char pool while the admitted 12,937 chars could make 13.1 and the run measured
973
+ // 12.6, a "clears" that was already under the floor.
974
+ const poolChars = rawChars(docs);
975
+ const keptChars = projectKeptChars(poolChars, calibration.keepRate);
976
+ const estimate = spokenLength(keptChars, calibration.keptRatio, vdriver);
771
977
  const clears = estimate.seconds >= floor * 60;
772
- rungs.push({ window: label, items: docs.length, chars: estimate.chars, minutes: estimate.minutes, clears });
978
+ rungs.push({
979
+ window: label,
980
+ items: docs.length,
981
+ chars: poolChars,
982
+ keptChars,
983
+ minutes: estimate.minutes,
984
+ clears,
985
+ });
773
986
  chosen = { window: label, docs };
774
987
  const verdict = gated
775
- ? `estimated ${estimate.minutes} min at ${ratio.ratio.toFixed(2)}x — ${clears ? 'clears' : 'below'} the ${floor} min floor`
988
+ ? `estimated ${estimate.minutes} min from ${keptChars} projected kept chars of ${poolChars} at ${calibration.keptRatio.toFixed(2)}x kept ratio, keep rate ${Math.round(calibration.keepRate * 100)}% (${calibration.keepRateSource}) — ${clears ? 'clears' : 'below'} the ${floor} min floor`
776
989
  : 'floor gate off';
777
990
  console.error(`extract: ${label} pool ${docs.length} item(s), ${verdict}`);
778
991
  if (!gated || clears) break;
779
992
  rmSync(attempt, { force: true });
780
993
  }
781
994
  const picked = chosen ?? { window: formatWindowMs(base), docs: [] as unknown[] };
782
- // 0377 R3: the decision is an artifact, not just a stderr line — the run report and
783
- // `kk news status` read which measure drove it, the rung chosen and the estimate at each rung.
995
+ // 0377 R3 + 0434 R2: the decision is an artifact, not just a stderr line — the run report and
996
+ // `kk news status` read which measure drove it, the rung chosen and the estimate at each rung,
997
+ // and every measure prints the path it came from so two artifacts compare without recomputing.
998
+ // `ratioUsed`/`ratioSource` stay as the recorded spoken/pool ratio (the writer's drift
999
+ // anchor); `spokenPerPoolChar` is the pool-denominated number the rung minutes actually used.
784
1000
  sted('write', join(workDir, '10-collect', 'ladder.json'), () =>
785
1001
  writeJsonText(join(workDir, '10-collect', 'ladder.json'), {
786
1002
  floorMinutes: gated ? floor : null,
787
- ratioUsed: ratio.ratio,
788
- ratioSource: ratio.source,
1003
+ ratioUsed: calibration.poolRatio,
1004
+ ratioSource: calibration.poolRatioSource,
1005
+ keptRatio: calibration.keptRatio,
1006
+ keptRatioSource: calibration.keptRatioSource,
1007
+ keepRate: calibration.keepRate,
1008
+ keepRateSource: calibration.keepRateSource,
1009
+ spokenPerPoolChar: Math.round(calibration.keepRate * calibration.keptRatio * 1000) / 1000,
789
1010
  chosen: picked.window,
790
1011
  rungs,
791
1012
  }),
@@ -1180,8 +1401,11 @@ export function dailyEpisodeDuration(args: string[]): void {
1180
1401
  console.error(`episode-duration: duration refusal already recorded (${refusal}) — nothing to do`);
1181
1402
  return;
1182
1403
  }
1183
- const estimated = estimateSpokenMinutes(docs, vdriver, readKeptRatio(workDir).ratio);
1404
+ const calibration = readSpokenCalibration(workDir);
1405
+ const estimated = estimateSpokenMinutes(docs, vdriver, calibration.keptRatio);
1184
1406
  const measuredMinutes = Math.round(minutes * 10) / 10;
1407
+ const observed = observedKeepRate(workDir, estimated.chars);
1408
+ const assumed = assumedKeepRate(workDir, calibration);
1185
1409
  sted('write', refusal, () =>
1186
1410
  writeJqText(refusal, {
1187
1411
  measuredMinutes,
@@ -1189,7 +1413,15 @@ export function dailyEpisodeDuration(args: string[]): void {
1189
1413
  minMinutes,
1190
1414
  keptCount: docs.length,
1191
1415
  candidateChars: estimated.chars,
1192
- reason: `the episode ran ${shown} min of speech, below the ${minMinutes} min floor (pre-spend estimate ${estimated.minutes} min) — refusing after synthesis`,
1416
+ // 0434 R2: same three measures the floor gate and the ladder print, so all three
1417
+ // artifacts for one episode compare without recomputation.
1418
+ expansion: calibration.keptRatio,
1419
+ expansionSource: calibration.keptRatioSource,
1420
+ keepRate: observed?.rate ?? null,
1421
+ keepRateSource: observed?.source ?? null,
1422
+ keepRateAssumed: assumed.rate,
1423
+ keepRateAssumedSource: assumed.source,
1424
+ reason: `the episode ran ${shown} min of speech, below the ${minMinutes} min floor (pre-spend estimate ${estimated.minutes} min at ${calibration.keptRatio.toFixed(2)}x kept ratio) — refusing after synthesis`,
1193
1425
  }),
1194
1426
  );
1195
1427
  emptyCandidates(workDir, runDate);
@@ -5560,8 +5792,13 @@ export function dailyScriptCheck(args: string[]): void {
5560
5792
  * `21-plan/<date>_03_curate_excluded.json`) against the QC candidates
5561
5793
  * (`21-plan/<date>_04_quality-control-content_candidates.json`). Unwraps a `Content` envelope and
5562
5794
  * dedups near-duplicate titles in place before `write` reads the plan. Writes
5563
- * `21-plan/<date>_03_curate_errors.json` (`[{itemId, rule}]`) on failure and removes it on success.
5564
- * With `--final`, falls back to the untranslated candidates and `[]` exclusions on failure.
5795
+ * `21-plan/<date>_03_curate_errors.json` (`[{itemId, rule, detail?}]`) on failure and removes it on
5796
+ * success. With `--final`, falls back to the untranslated candidates and `[]` exclusions on failure.
5797
+ *
5798
+ * 0433 R3/R4 adds one rule to that set: `cn-lead:XY-02` — the lead may not carry a 时政/贸易管制/
5799
+ * 公共安全审查 mainline on a CN-distributed cut (see `./cn-lead-gate.ts`). It is checked here, in the
5800
+ * plan stage, because here is the last place before the TTS spend that reads the order the episode will
5801
+ * be spoken and titled in.
5565
5802
  */
5566
5803
  export function dailyCurateCheck(args: string[]): void {
5567
5804
  const [workDir = '', runDate = '', flag = ''] = args;
@@ -5572,6 +5809,8 @@ export function dailyCurateCheck(args: string[]): void {
5572
5809
  const planFile = join(workDir, '21-plan', `${runDate}_03_plan_plan.json`);
5573
5810
  const excludedFile = join(workDir, '21-plan', `${runDate}_03_curate_excluded.json`);
5574
5811
  const errFile = join(workDir, '21-plan', `${runDate}_03_curate_errors.json`);
5812
+ // 0433 R3/R4: the CN-lead refusal record — written only when no candidate can lead a CN cut.
5813
+ const cnLeadRefusal = join(workDir, '21-plan', `${runDate}_03_cn-lead-refusal.json`);
5575
5814
 
5576
5815
  const candRaw = readJson(candidatesFile);
5577
5816
  const candidateDocs: Record<string, unknown>[] = Array.isArray(candRaw)
@@ -5582,13 +5821,45 @@ export function dailyCurateCheck(args: string[]): void {
5582
5821
  const candidateIds = candidateDocs.map((doc) => (typeof doc?.id === 'string' ? doc.id.trim() : '')).filter(Boolean);
5583
5822
  const candidateIdSet = new Set(candidateIds);
5584
5823
 
5585
- const handleErrors = (errors: { itemId: string; rule: string }[]): void => {
5824
+ const handleErrors = (errors: { itemId: string; rule: string; detail?: string }[]): void => {
5586
5825
  if (isFinal) {
5587
5826
  const reason = errors.map((e) => `${e.itemId}:${e.rule}`).join(', ');
5588
5827
  console.error(
5589
5828
  `curate-check: final check failed (${reason}) — falling back to ${candidateDocs.length} untranslated candidate(s)`,
5590
5829
  );
5591
- sted('write', planFile, () => writeJsonText(planFile, candidateDocs));
5830
+ // 0433 R2/R4: this path has no agent left — the `curate --fix` pass either never ran or did
5831
+ // not deliver, so the plan falls back to the raw candidates and nobody would remove a
5832
+ // CN-blocked lead from it. Apply the same demotion deterministically. A pool where EVERY
5833
+ // candidate trips has no lead this cut may carry: refuse here, before the TTS spend, instead
5834
+ // of paying for an episode the CN rows would drop (2026-11-24: 12.6 min of audio, two rows
5835
+ // excluded afterwards — the exact cost R4 exists to remove).
5836
+ const enforced = enforceCnLead(candidateDocs);
5837
+ const blocked = enforced.blocked;
5838
+ if (blocked !== null) {
5839
+ sted('write', cnLeadRefusal, () =>
5840
+ writeJqText(cnLeadRefusal, {
5841
+ rule: 'cn-lead:XY-02',
5842
+ ruleIds: ['XY-02', 'WX-01'],
5843
+ leadId: blocked.id,
5844
+ candidateIds,
5845
+ message: blocked.message,
5846
+ reason: `every one of the ${candidateDocs.length} candidate(s) trips the CN-blocked mainline vocabulary on the lead surface — refusing before any TTS spend, because no lead this cut may carry exists`,
5847
+ }),
5848
+ );
5849
+ if (isFile(errFile)) unlinkSync(errFile);
5850
+ failWith(1, blocked.message);
5851
+ }
5852
+ if (enforced.demoted !== null) {
5853
+ console.error(
5854
+ `curate-check: ${enforced.demoted.id} demoted from lead to position ${enforced.demoted.to} — the CN-blocked lead this cut may not carry (see cn-lead-gate.ts)`,
5855
+ );
5856
+ }
5857
+ if (enforced.weakLead !== null) {
5858
+ console.error(
5859
+ `curate-check: weak lead ${enforced.weakLead.id} (${enforced.weakLead.terms.join(', ')}) — no clean candidate, and it trips only the two-signal heuristic, so it leads instead of refusing the day (0438 R4)`,
5860
+ );
5861
+ }
5862
+ sted('write', planFile, () => writeJsonText(planFile, enforced.docs));
5592
5863
  sted('write', excludedFile, () => writeJsonText(excludedFile, []));
5593
5864
  if (isFile(errFile)) unlinkSync(errFile);
5594
5865
  // Task 0392 R2: the recorded fallback IS the curation evidence for this attempt — the
@@ -5673,7 +5944,7 @@ export function dailyCurateCheck(args: string[]): void {
5673
5944
  }
5674
5945
  }
5675
5946
 
5676
- const errors: { itemId: string; rule: string }[] = [];
5947
+ const errors: { itemId: string; rule: string; detail?: string }[] = [];
5677
5948
  if (planDocs.length === 0) {
5678
5949
  errors.push({ itemId: 'episode', rule: 'empty-plan' });
5679
5950
  }
@@ -5704,7 +5975,18 @@ export function dailyCurateCheck(args: string[]): void {
5704
5975
  }
5705
5976
  }
5706
5977
 
5978
+ // 0433 R3/R4: the CN-platform lead constraint, enforced deterministically BEFORE the TTS spend.
5979
+ // The curator's biggest story can be the one `XY-02`/`WX-01` block, and the post-spend variants
5980
+ // review is where that used to surface (2026-11-24: 12.6 min of audio, two CN rows excluded).
5981
+ // Only the lead position is gated — the same story stays in scope as a body item (SKILL.md
5982
+ // shared rule 2), which is what the `curate --fix` pass does with this rule.
5983
+ const cnLead = checkCnLeadPlan(planDocs);
5984
+ if (!cnLead.ok) {
5985
+ errors.push({ itemId: cnLead.leadId ?? 'episode', rule: 'cn-lead:XY-02', detail: cnLead.message });
5986
+ }
5987
+
5707
5988
  if (errors.length > 0) {
5989
+ if (!cnLead.ok) console.error(`curate-check: ${cnLead.message}`);
5708
5990
  handleErrors(errors);
5709
5991
  return;
5710
5992
  }