@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.
- package/.claude-plugin/marketplace.json +1 -1
- package/dist/index.js +115 -21
- package/package.json +1 -1
- package/plugins/kk/plugin.json +1 -1
- package/plugins/kk/scripts/cn-lead-gate.ts +494 -0
- package/plugins/kk/scripts/daily-stages.ts +416 -134
- package/plugins/kk/scripts/kk-workflow-stages.ts +53 -3
- package/plugins/kk/skills/news-editorial/SKILL.md +20 -3
- package/plugins/kk/skills/news-editorial/references/selection.md +42 -0
- package/plugins/publishings/bilibili-pub/dist/index.js +33 -2
- package/plugins/publishings/bilibili-pub/dist/profile-check.js +33 -2
- package/plugins/publishings/cnblogs-pub/dist/index.js +33 -2
- package/plugins/publishings/cnblogs-pub/dist/profile-check.js +33 -2
- package/plugins/publishings/csdn-pub/dist/index.js +33 -2
- package/plugins/publishings/csdn-pub/dist/profile-check.js +33 -2
- package/plugins/publishings/infoq-pub/dist/index.js +33 -2
- package/plugins/publishings/infoq-pub/dist/profile-check.js +33 -2
- package/plugins/publishings/jike-pub/dist/index.js +33 -2
- package/plugins/publishings/jike-pub/dist/profile-check.js +33 -2
- package/plugins/publishings/juejin-pub/dist/index.js +33 -2
- package/plugins/publishings/juejin-pub/dist/profile-check.js +33 -2
- package/plugins/publishings/linkedin-pub/dist/index.js +84 -13
- package/plugins/publishings/linkedin-pub/dist/profile-check.js +50 -5
- package/plugins/publishings/linkedin-pub/src/index.ts +126 -9
- package/plugins/publishings/medium-pub/dist/index.js +33 -2
- package/plugins/publishings/medium-pub/dist/profile-check.js +33 -2
- package/plugins/publishings/shipinhao-pub/dist/index.js +33 -2
- package/plugins/publishings/shipinhao-pub/dist/profile-check.js +33 -2
- package/plugins/publishings/sspai-pub/dist/index.js +33 -2
- package/plugins/publishings/sspai-pub/dist/profile-check.js +33 -2
- package/plugins/publishings/substack-pub/dist/index.js +33 -2
- package/plugins/publishings/substack-pub/dist/profile-check.js +33 -2
- package/plugins/publishings/surfdash-pub/dist/index.js +53 -15
- package/plugins/publishings/surfdash-pub/src/index.ts +31 -4
- package/plugins/publishings/surfdash-pub/src/patch.ts +81 -12
- package/plugins/publishings/threads-pub/dist/index.js +33 -2
- package/plugins/publishings/threads-pub/dist/profile-check.js +33 -2
- package/plugins/publishings/wechatmp-pub/dist/index.js +65 -3
- package/plugins/publishings/wechatmp-pub/dist/profile-check.js +67 -3
- package/plugins/publishings/wechatmp-pub/src/index.ts +64 -1
- package/plugins/publishings/weibo-pub/dist/index.js +56 -8
- package/plugins/publishings/weibo-pub/dist/profile-check.js +55 -8
- package/plugins/publishings/weibo-pub/plugin.json +1 -1
- package/plugins/publishings/weibo-pub/src/index.ts +76 -8
- package/plugins/publishings/x-pub/dist/index.js +33 -2
- package/plugins/publishings/x-pub/dist/profile-check.js +33 -2
- package/plugins/publishings/xhs-pub/dist/index.js +33 -2
- package/plugins/publishings/xhs-pub/dist/profile-check.js +33 -2
- package/plugins/publishings/xiaoyuzhou-pub/dist/index.js +33 -2
- 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(
|
|
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 `
|
|
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
|
|
394
|
-
* two pre-spend consumers measure different sets
|
|
395
|
-
*
|
|
396
|
-
*
|
|
397
|
-
* directories, so they judge today's material
|
|
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
|
-
/**
|
|
403
|
-
|
|
404
|
-
|
|
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
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
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
|
|
471
|
+
* The newest recorded spoken-ratio artifacts across this workflow's sibling run directories.
|
|
463
472
|
*
|
|
464
|
-
*
|
|
465
|
-
*
|
|
466
|
-
*
|
|
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
|
|
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
|
|
484
|
+
return [];
|
|
482
485
|
}
|
|
483
|
-
const
|
|
486
|
+
const paths: string[] = [];
|
|
484
487
|
if (entries.length > 5_000) {
|
|
485
|
-
//
|
|
486
|
-
//
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
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
|
-
|
|
523
|
-
return { ratio: clampRatio(newest.ratio), source: `${newest.from} (${newest.ratio.toFixed(2)}x)` };
|
|
538
|
+
return records;
|
|
524
539
|
}
|
|
525
540
|
|
|
526
541
|
/**
|
|
527
|
-
*
|
|
528
|
-
*
|
|
529
|
-
*
|
|
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
|
-
|
|
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
|
|
553
|
-
// different one. A wide gap means the next run's ladder is working from a stale
|
|
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
|
|
558
|
-
|
|
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
|
|
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
|
-
*
|
|
579
|
-
* over the driver's measured char rate, plus the 8 s intro sting
|
|
580
|
-
* gate
|
|
581
|
-
*
|
|
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 `
|
|
584
|
-
*
|
|
585
|
-
*
|
|
586
|
-
*
|
|
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
|
-
|
|
594
|
-
|
|
595
|
-
|
|
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 `
|
|
610
|
-
* measures the admitted set, and applying the pool ratio to it discounted the planning shrink
|
|
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
|
|
805
|
+
const calibration = readSpokenCalibration(workDir);
|
|
634
806
|
const {
|
|
635
807
|
minutes: estimatedMinutes,
|
|
636
808
|
seconds: estimatedSeconds,
|
|
637
809
|
chars,
|
|
638
|
-
} = estimateSpokenMinutes(docs, vdriver, keptRatio
|
|
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(
|
|
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
|
|
663
|
-
expansionSource:
|
|
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
|
|
760
|
-
//
|
|
761
|
-
|
|
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<{
|
|
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
|
-
|
|
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({
|
|
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 ${
|
|
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:
|
|
788
|
-
ratioSource:
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
}
|