@gobing-ai/knowledge-kit 0.1.29 → 0.1.30

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 (114) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/dist/board/api.js +8724 -3861
  3. package/dist/board/collect/index.js +69 -1
  4. package/dist/board/daily-voice/index.js +474 -265
  5. package/dist/board/itc/index.js +69 -1
  6. package/dist/board/wiki/index.css +1305 -0
  7. package/dist/board/wiki/index.js +1621 -0
  8. package/dist/index.js +34689 -28532
  9. package/package.json +1 -1
  10. package/plugins/generations/content-gen/dist/index.js +14 -1
  11. package/plugins/generations/core-facts-gen/dist/index.js +14 -1
  12. package/plugins/generations/daily-article-gen/dist/index.js +14 -1
  13. package/plugins/generations/dailynews-gen/dist/index.js +14 -1
  14. package/plugins/generations/episode-plan-gen/dist/index.js +32 -2
  15. package/plugins/generations/episode-plan-gen/src/index.ts +19 -1
  16. package/plugins/generations/gemini-tts/dist/index.js +14 -1
  17. package/plugins/generations/image-gen/dist/index.js +14 -1
  18. package/plugins/generations/music-gen/dist/index.js +15 -2
  19. package/plugins/generations/news-report-gen/dist/index.js +14 -1
  20. package/plugins/generations/vibe-voice-tts/dist/index.js +14 -1
  21. package/plugins/generations/video-gen/README.md +245 -8
  22. package/plugins/generations/video-gen/dist/index.js +22447 -4763
  23. package/plugins/generations/video-gen/package.json +1 -0
  24. package/plugins/generations/video-gen/presets/formats/avatar.yaml +5 -0
  25. package/plugins/generations/video-gen/presets/formats/editorial.yaml +6 -0
  26. package/plugins/generations/video-gen/presets/formats/hybrid-pip.yaml +5 -0
  27. package/plugins/generations/video-gen/presets/styles/daily-ai.yaml +5 -0
  28. package/plugins/generations/video-gen/presets/styles/neutral.yaml +3 -0
  29. package/plugins/generations/video-gen/python/colab_comfyui_h3.py +322 -0
  30. package/plugins/generations/video-gen/python/comfyui-h3-i2v-api.json +47 -0
  31. package/plugins/generations/video-gen/python/comfyui-h3-models.json +32 -0
  32. package/plugins/generations/video-gen/python/comfyui_model_cache.py +388 -0
  33. package/plugins/generations/video-gen/python/drive_client.py +187 -0
  34. package/plugins/generations/video-gen/src/brief-cli.ts +65 -0
  35. package/plugins/generations/video-gen/src/brief.ts +464 -0
  36. package/plugins/generations/video-gen/src/ccu-ledger.ts +206 -3
  37. package/plugins/generations/video-gen/src/colab-runner.ts +346 -35
  38. package/plugins/generations/video-gen/src/index.ts +141 -109
  39. package/plugins/generations/video-gen/src/inputs.ts +162 -4
  40. package/plugins/generations/video-gen/src/layout.ts +33 -0
  41. package/plugins/generations/video-gen/src/props.ts +27 -3
  42. package/plugins/generations/video-gen/src/remotion/AvatarReel.tsx +17 -1
  43. package/plugins/generations/video-gen/src/remotion/EditorialReel.tsx +17 -1
  44. package/plugins/generations/video-gen/src/remotion/Root.tsx +2 -0
  45. package/plugins/generations/video-gen/src/remotion/engine.ts +3 -7
  46. package/plugins/generations/video-gen/src/render.ts +25 -0
  47. package/plugins/generations/video-gen/src/request.ts +150 -20
  48. package/plugins/generations/video-gen/src/visual-provider.ts +116 -3
  49. package/plugins/generations/voice-gen/dist/index.js +14 -1
  50. package/plugins/generations/voxcpm-tts/dist/index.js +14 -1
  51. package/plugins/ingestions/aihot-ingest/dist/index.js +14 -1
  52. package/plugins/ingestions/horizon-ingest/dist/index.js +14 -1
  53. package/plugins/ingestions/last30days-ingest/dist/index.js +14 -1
  54. package/plugins/ingestions/web-search/dist/index.js +14 -1
  55. package/plugins/kk/config.example.yaml +1 -1
  56. package/plugins/kk/mcp-tools.yaml +47 -0
  57. package/plugins/kk/plugin.json +1 -1
  58. package/plugins/kk/publish-presets/itc-surfdash-locales.json +42 -0
  59. package/plugins/kk/scripts/daily-stages.ts +87 -6
  60. package/plugins/kk/scripts/kk-workflow-stages.ts +64 -9
  61. package/plugins/kk/scripts/video-stages.ts +332 -0
  62. package/plugins/kk/scripts/wiki-normalize-audio.ts +354 -0
  63. package/plugins/kk/scripts/wiki-normalize-document.ts +495 -0
  64. package/plugins/kk/scripts/wiki-normalize-stages.ts +96 -0
  65. package/plugins/kk/scripts/wiki-stage-runtime.ts +39 -0
  66. package/plugins/kk/skills/news-editorial/SKILL.md +2 -1
  67. package/plugins/kk/workflows/kk-collect.yaml +10 -0
  68. package/plugins/kk/workflows/kk-news-generate.yaml +70 -8
  69. package/plugins/kk/workflows/kk-smart-seo.yaml +8 -0
  70. package/plugins/kk/workflows/kk-storm-research.yaml +10 -0
  71. package/plugins/kk/workflows/kk-video-generate.yaml +169 -0
  72. package/plugins/kk/workflows/kk-wiki-digest.yaml +49 -0
  73. package/plugins/publishings/bilibili-pub/dist/index.js +281 -268
  74. package/plugins/publishings/bilibili-pub/dist/profile-check.js +202 -0
  75. package/plugins/publishings/cnblogs-pub/dist/index.js +281 -268
  76. package/plugins/publishings/cnblogs-pub/dist/profile-check.js +202 -0
  77. package/plugins/publishings/csdn-pub/dist/index.js +281 -268
  78. package/plugins/publishings/csdn-pub/dist/profile-check.js +216 -1
  79. package/plugins/publishings/emdash-pub/dist/index.js +33 -3
  80. package/plugins/publishings/infoq-pub/dist/index.js +281 -268
  81. package/plugins/publishings/infoq-pub/dist/profile-check.js +216 -1
  82. package/plugins/publishings/jike-pub/dist/index.js +281 -268
  83. package/plugins/publishings/jike-pub/dist/profile-check.js +216 -1
  84. package/plugins/publishings/juejin-pub/dist/index.js +281 -268
  85. package/plugins/publishings/juejin-pub/dist/profile-check.js +216 -1
  86. package/plugins/publishings/linkedin-pub/dist/index.js +281 -268
  87. package/plugins/publishings/linkedin-pub/dist/profile-check.js +216 -1
  88. package/plugins/publishings/medium-pub/dist/index.js +281 -268
  89. package/plugins/publishings/medium-pub/dist/profile-check.js +216 -1
  90. package/plugins/publishings/podcast-pub/dist/index.js +39 -9
  91. package/plugins/publishings/qiita-pub/dist/index.js +33 -3
  92. package/plugins/publishings/shipinhao-pub/dist/index.js +281 -268
  93. package/plugins/publishings/shipinhao-pub/dist/profile-check.js +175 -0
  94. package/plugins/publishings/sspai-pub/dist/index.js +281 -268
  95. package/plugins/publishings/sspai-pub/dist/profile-check.js +202 -0
  96. package/plugins/publishings/substack-pub/dist/index.js +281 -268
  97. package/plugins/publishings/substack-pub/dist/profile-check.js +216 -1
  98. package/plugins/publishings/surfdash-pub/dist/index.js +99 -39
  99. package/plugins/publishings/surfdash-pub/plugin.json +54 -0
  100. package/plugins/publishings/surfdash-pub/src/index.ts +36 -5
  101. package/plugins/publishings/threads-pub/dist/index.js +281 -268
  102. package/plugins/publishings/threads-pub/dist/profile-check.js +216 -1
  103. package/plugins/publishings/wechatmp-pub/dist/index.js +665 -451
  104. package/plugins/publishings/wechatmp-pub/dist/profile-check.js +215 -3
  105. package/plugins/publishings/weibo-pub/dist/index.js +281 -268
  106. package/plugins/publishings/weibo-pub/dist/profile-check.js +189 -1
  107. package/plugins/publishings/x-pub/dist/index.js +281 -268
  108. package/plugins/publishings/x-pub/dist/profile-check.js +216 -1
  109. package/plugins/publishings/xhs-pub/dist/index.js +281 -268
  110. package/plugins/publishings/xhs-pub/dist/profile-check.js +119 -1
  111. package/plugins/publishings/xiaoyuzhou-pub/dist/index.js +281 -268
  112. package/plugins/publishings/xiaoyuzhou-pub/dist/profile-check.js +202 -0
  113. package/plugins/publishings/youtube-pub/dist/index.js +14 -1
  114. package/plugins/publishings/zenn-pub/dist/index.js +37 -7
@@ -17441,7 +17441,19 @@ var omniVoiceGenContentSchema = ContentSchema.extend({
17441
17441
  })
17442
17442
  });
17443
17443
  var VideoVisualModeSchema = _enum(["editorial", "avatar", "hybrid-pip"]);
17444
- var VideoRenderProviderSchema = _enum(["local-ken-burns", "wan21-i2v", "musetalk", "echomimic-v2"]);
17444
+ var VideoRenderProviderSchema = _enum([
17445
+ "local-ken-burns",
17446
+ "wan21-i2v",
17447
+ "comfyui-minimax-h3",
17448
+ "musetalk",
17449
+ "echomimic-v2"
17450
+ ]);
17451
+ var RenderProvenanceSchema = object2({
17452
+ cache: _enum(["drive", "local"]),
17453
+ comfyuiCommit: string2().min(1).optional(),
17454
+ comfyuiRuntimeCommit: string2().min(1).nullable().optional(),
17455
+ modelCache: object2({ verified: boolean2(), restored: number2().int().nonnegative() }).optional()
17456
+ });
17445
17457
  var videoGenContentSchema = ContentSchema.extend({
17446
17458
  format: literal("video"),
17447
17459
  metadata: looseObject({
@@ -17454,6 +17466,7 @@ var videoGenContentSchema = ContentSchema.extend({
17454
17466
  durationSec: number2().positive(),
17455
17467
  visualMode: VideoVisualModeSchema,
17456
17468
  renderProvider: VideoRenderProviderSchema,
17469
+ renderProvenance: RenderProvenanceSchema.optional(),
17457
17470
  fallbackUsed: boolean2().optional(),
17458
17471
  warnings: array(string2()).optional(),
17459
17472
  ccuEstimated: number2().nonnegative().optional(),
@@ -17838,7 +17838,19 @@ var omniVoiceGenContentSchema = ContentSchema.extend({
17838
17838
  })
17839
17839
  });
17840
17840
  var VideoVisualModeSchema = _enum(["editorial", "avatar", "hybrid-pip"]);
17841
- var VideoRenderProviderSchema = _enum(["local-ken-burns", "wan21-i2v", "musetalk", "echomimic-v2"]);
17841
+ var VideoRenderProviderSchema = _enum([
17842
+ "local-ken-burns",
17843
+ "wan21-i2v",
17844
+ "comfyui-minimax-h3",
17845
+ "musetalk",
17846
+ "echomimic-v2"
17847
+ ]);
17848
+ var RenderProvenanceSchema = object({
17849
+ cache: _enum(["drive", "local"]),
17850
+ comfyuiCommit: string2().min(1).optional(),
17851
+ comfyuiRuntimeCommit: string2().min(1).nullable().optional(),
17852
+ modelCache: object({ verified: boolean2(), restored: number2().int().nonnegative() }).optional()
17853
+ });
17842
17854
  var videoGenContentSchema = ContentSchema.extend({
17843
17855
  format: literal("video"),
17844
17856
  metadata: looseObject({
@@ -17851,6 +17863,7 @@ var videoGenContentSchema = ContentSchema.extend({
17851
17863
  durationSec: number2().positive(),
17852
17864
  visualMode: VideoVisualModeSchema,
17853
17865
  renderProvider: VideoRenderProviderSchema,
17866
+ renderProvenance: RenderProvenanceSchema.optional(),
17854
17867
  fallbackUsed: boolean2().optional(),
17855
17868
  warnings: array(string2()).optional(),
17856
17869
  ccuEstimated: number2().nonnegative().optional(),
@@ -17439,7 +17439,19 @@ var omniVoiceGenContentSchema = ContentSchema.extend({
17439
17439
  })
17440
17440
  });
17441
17441
  var VideoVisualModeSchema = _enum(["editorial", "avatar", "hybrid-pip"]);
17442
- var VideoRenderProviderSchema = _enum(["local-ken-burns", "wan21-i2v", "musetalk", "echomimic-v2"]);
17442
+ var VideoRenderProviderSchema = _enum([
17443
+ "local-ken-burns",
17444
+ "wan21-i2v",
17445
+ "comfyui-minimax-h3",
17446
+ "musetalk",
17447
+ "echomimic-v2"
17448
+ ]);
17449
+ var RenderProvenanceSchema = object({
17450
+ cache: _enum(["drive", "local"]),
17451
+ comfyuiCommit: string2().min(1).optional(),
17452
+ comfyuiRuntimeCommit: string2().min(1).nullable().optional(),
17453
+ modelCache: object({ verified: boolean2(), restored: number2().int().nonnegative() }).optional()
17454
+ });
17443
17455
  var videoGenContentSchema = ContentSchema.extend({
17444
17456
  format: literal("video"),
17445
17457
  metadata: looseObject({
@@ -17452,6 +17464,7 @@ var videoGenContentSchema = ContentSchema.extend({
17452
17464
  durationSec: number2().positive(),
17453
17465
  visualMode: VideoVisualModeSchema,
17454
17466
  renderProvider: VideoRenderProviderSchema,
17467
+ renderProvenance: RenderProvenanceSchema.optional(),
17455
17468
  fallbackUsed: boolean2().optional(),
17456
17469
  warnings: array(string2()).optional(),
17457
17470
  ccuEstimated: number2().nonnegative().optional(),
@@ -17440,7 +17440,19 @@ var omniVoiceGenContentSchema = ContentSchema.extend({
17440
17440
  })
17441
17441
  });
17442
17442
  var VideoVisualModeSchema = _enum(["editorial", "avatar", "hybrid-pip"]);
17443
- var VideoRenderProviderSchema = _enum(["local-ken-burns", "wan21-i2v", "musetalk", "echomimic-v2"]);
17443
+ var VideoRenderProviderSchema = _enum([
17444
+ "local-ken-burns",
17445
+ "wan21-i2v",
17446
+ "comfyui-minimax-h3",
17447
+ "musetalk",
17448
+ "echomimic-v2"
17449
+ ]);
17450
+ var RenderProvenanceSchema = object({
17451
+ cache: _enum(["drive", "local"]),
17452
+ comfyuiCommit: string2().min(1).optional(),
17453
+ comfyuiRuntimeCommit: string2().min(1).nullable().optional(),
17454
+ modelCache: object({ verified: boolean2(), restored: number2().int().nonnegative() }).optional()
17455
+ });
17444
17456
  var videoGenContentSchema = ContentSchema.extend({
17445
17457
  format: literal("video"),
17446
17458
  metadata: looseObject({
@@ -17453,6 +17465,7 @@ var videoGenContentSchema = ContentSchema.extend({
17453
17465
  durationSec: number2().positive(),
17454
17466
  visualMode: VideoVisualModeSchema,
17455
17467
  renderProvider: VideoRenderProviderSchema,
17468
+ renderProvenance: RenderProvenanceSchema.optional(),
17456
17469
  fallbackUsed: boolean2().optional(),
17457
17470
  warnings: array(string2()).optional(),
17458
17471
  ccuEstimated: number2().nonnegative().optional(),
@@ -17459,7 +17459,19 @@ var omniVoiceGenContentSchema = ContentSchema.extend({
17459
17459
  })
17460
17460
  });
17461
17461
  var VideoVisualModeSchema = _enum(["editorial", "avatar", "hybrid-pip"]);
17462
- var VideoRenderProviderSchema = _enum(["local-ken-burns", "wan21-i2v", "musetalk", "echomimic-v2"]);
17462
+ var VideoRenderProviderSchema = _enum([
17463
+ "local-ken-burns",
17464
+ "wan21-i2v",
17465
+ "comfyui-minimax-h3",
17466
+ "musetalk",
17467
+ "echomimic-v2"
17468
+ ]);
17469
+ var RenderProvenanceSchema = object({
17470
+ cache: _enum(["drive", "local"]),
17471
+ comfyuiCommit: string2().min(1).optional(),
17472
+ comfyuiRuntimeCommit: string2().min(1).nullable().optional(),
17473
+ modelCache: object({ verified: boolean2(), restored: number2().int().nonnegative() }).optional()
17474
+ });
17463
17475
  var videoGenContentSchema = ContentSchema.extend({
17464
17476
  format: literal("video"),
17465
17477
  metadata: looseObject({
@@ -17472,6 +17484,7 @@ var videoGenContentSchema = ContentSchema.extend({
17472
17484
  durationSec: number2().positive(),
17473
17485
  visualMode: VideoVisualModeSchema,
17474
17486
  renderProvider: VideoRenderProviderSchema,
17487
+ renderProvenance: RenderProvenanceSchema.optional(),
17475
17488
  fallbackUsed: boolean2().optional(),
17476
17489
  warnings: array(string2()).optional(),
17477
17490
  ccuEstimated: number2().nonnegative().optional(),
@@ -109,7 +109,7 @@ plugins:
109
109
  KK_IMAGE_DRY_RUN: "" # optional — "1" composes every prompt, selects the provider, spends nothing
110
110
  gemini-tts:
111
111
  env:
112
- GEMINI_API_KEY: ""
112
+ GEMINI_API_KEY: "" # also read by the operator's `gemini-api` CLI wrapper (single source)
113
113
  GOOGLE_BASE_URL: "https://generativelanguage.googleapis.com"
114
114
  GEMINI_TTS_MODEL: "gemini-3.8-flash-tts"
115
115
  GEMINI_TTS_PROFILES: "/Users/robin/.config/kk/gemini-tts-profiles.json"
@@ -0,0 +1,47 @@
1
+ # MCP tool registration surface (task 0428) — consumed by Spur's embedded MCP server (spur-new 1447).
2
+ # Read-only verbs only: the namespace `kk` comes from plugins/kk/plugin.json, so a tool named
3
+ # `store_stats` is exposed as `kk_store_stats`. Mutating verbs are deliberately absent — Spur has
4
+ # no per-tool confirmation hook, so a write tool would bypass operator authorization.
5
+ # `command` stays on checkout source: the installed `kk` is known to drift from this tree.
6
+ schema_version: 1
7
+ tools:
8
+ - name: plugin_status
9
+ description: List discovered kk plugins grouped by kind, with health marks.
10
+ annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true }
11
+ params:
12
+ kind: { type: string, enum: [ingestion, generator, publish], description: Filter by plugin kind }
13
+ command: [bun, apps/cli/src/index.ts, plugin, status, --json]
14
+ args:
15
+ kind: ['--kind', '{value}']
16
+ output: json
17
+ - name: store_stats
18
+ description: New-item yield per local day and per source channel.
19
+ annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true }
20
+ params:
21
+ days: { type: number, description: Trailing window in days }
22
+ command: [bun, apps/cli/src/index.ts, store, stats, --json]
23
+ args:
24
+ days: ['--days', '{value}']
25
+ output: json
26
+ - name: wiki_query
27
+ description: Rank wiki vault pages against a prompt.
28
+ annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true }
29
+ params:
30
+ prompt: { type: string, required: true, description: Search prompt }
31
+ limit: { type: number, description: Maximum hits (default 10) }
32
+ command: [bun, apps/cli/src/index.ts, wiki, query, --json]
33
+ args:
34
+ prompt: ['{value}']
35
+ limit: ['--limit', '{value}']
36
+ output: json
37
+ - name: wiki_context
38
+ description: Pack a wiki topic page and its graph neighbours into one Markdown block.
39
+ annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true }
40
+ params:
41
+ topic: { type: string, required: true, description: Topic title or slug }
42
+ depth: { type: number, description: Neighbour depth (default 1) }
43
+ command: [bun, apps/cli/src/index.ts, wiki, context, --json]
44
+ args:
45
+ topic: ['{value}']
46
+ depth: ['--depth', '{value}']
47
+ output: json
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "kk",
3
- "version": "0.1.29",
3
+ "version": "0.1.30",
4
4
  "description": "knowledge-kit Claude Code plugin: skills, commands, subagents, hooks, and rules"
5
5
  }
@@ -0,0 +1,42 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "name": "itc-surfdash-locales",
4
+ "targets": [
5
+ {
6
+ "plugin": "surfdash-pub",
7
+ "profile": "article-zh",
8
+ "id": "surfdash-pub.article-zh",
9
+ "variant": "zh-article",
10
+ "tier": 0,
11
+ "mode": "draft",
12
+ "required": false,
13
+ "metadata": {
14
+ "locale": "zh"
15
+ }
16
+ },
17
+ {
18
+ "plugin": "surfdash-pub",
19
+ "profile": "article-ja",
20
+ "id": "surfdash-pub.article-ja",
21
+ "variant": "ja-article",
22
+ "tier": 0,
23
+ "mode": "draft",
24
+ "required": false,
25
+ "metadata": {
26
+ "locale": "ja"
27
+ }
28
+ },
29
+ {
30
+ "plugin": "surfdash-pub",
31
+ "profile": "article-en",
32
+ "id": "surfdash-pub.article-en",
33
+ "variant": "en-article",
34
+ "tier": 0,
35
+ "mode": "draft",
36
+ "required": false,
37
+ "metadata": {
38
+ "locale": "en"
39
+ }
40
+ }
41
+ ]
42
+ }
@@ -179,6 +179,7 @@ export function dailyQcContent(args: string[]): void {
179
179
  minMinutes,
180
180
  vdriver,
181
181
  qcMinChars,
182
+ backfillAfterShrink: true,
182
183
  });
183
184
  let recomputed = false;
184
185
  timed(workDir, 'quality-control-content', () => {
@@ -277,34 +278,112 @@ export function dailyQcContent(args: string[]): void {
277
278
  sted('write', candidates, () => writeJsonText(candidates, dedupedContent));
278
279
  console.error(`qc: dropped ${dropped.length} near-duplicate candidate(s): ${dropped.join(', ')}`);
279
280
  }
281
+ let keptDocs = dropped.length > 0 ? deduped : currentDocs;
282
+ const backfillIds = new Set<string>();
283
+ if (minMinutes !== '' && Number.isFinite(floorMinutes) && floorMinutes > 0) {
284
+ const keptRatio = readSpokenCalibration(workDir).keptRatio;
285
+ const rejectedPath = candidates.replace(/\.json$/, '.rejected.json');
286
+ const rejectedEnvelope = isFile(rejectedPath)
287
+ ? (readJson(rejectedPath) as Record<string, unknown> | null)
288
+ : null;
289
+ const rejectedList = Array.isArray(rejectedEnvelope?.rejected)
290
+ ? (rejectedEnvelope.rejected as Array<{ doc?: Record<string, unknown>; reasons?: unknown[] }>)
291
+ : [];
292
+ if (
293
+ rejectedList.length > 0 &&
294
+ estimateSpokenMinutes(keptDocs, vdriver, keptRatio).seconds < floorMinutes * 60
295
+ ) {
296
+ const spec = readTopicBoundary();
297
+ const remainingRejected: typeof rejectedList = [];
298
+ for (const entry of rejectedList) {
299
+ const doc = entry?.doc;
300
+ const reasons = Array.isArray(entry?.reasons) ? entry.reasons : [];
301
+ const importanceOnly =
302
+ doc !== null &&
303
+ typeof doc === 'object' &&
304
+ reasons.length > 0 &&
305
+ reasons.every((r) => String(r).startsWith('importance:'));
306
+ if (
307
+ !importanceOnly ||
308
+ estimateSpokenMinutes(keptDocs, vdriver, keptRatio).seconds >= floorMinutes * 60
309
+ ) {
310
+ remainingRejected.push(entry);
311
+ continue;
312
+ }
313
+ const { excluded: bExcl } = applyTopicBoundary([doc], runDate, spec);
314
+ if (bExcl.length > 0) {
315
+ remainingRejected.push(entry);
316
+ continue;
317
+ }
318
+ const { dropped: dDrop } = dedupPlanByTitle([...keptDocs, doc] as Array<{
319
+ id?: unknown;
320
+ title?: unknown;
321
+ }>);
322
+ const docId = String(doc.id ?? '');
323
+ if (dDrop.includes(docId)) {
324
+ remainingRejected.push(entry);
325
+ continue;
326
+ }
327
+ const docMeta =
328
+ doc.metadata !== null && typeof doc.metadata === 'object'
329
+ ? (doc.metadata as Record<string, unknown>)
330
+ : {};
331
+ const admittedDoc = { ...doc, metadata: { ...docMeta, backfilled: true } };
332
+ keptDocs = [...keptDocs, admittedDoc];
333
+ backfillIds.add(docId);
334
+ }
335
+ if (backfillIds.size > 0) {
336
+ const cContent = requireJson(candidates, 'qc-backfill');
337
+ const cMeta = cContent.metadata;
338
+ if (cMeta === null || typeof cMeta !== 'object') {
339
+ failWith(1, 'qc-backfill: candidates content carries no metadata object');
340
+ }
341
+ (cMeta as Record<string, unknown>).docs = keptDocs;
342
+ sted('write', candidates, () => writeJsonText(candidates, cContent));
343
+ sted('write', rejectedPath, () =>
344
+ writeJsonText(rejectedPath, { ...rejectedEnvelope, rejected: remainingRejected }),
345
+ );
346
+ console.error(
347
+ `qc: backfilled ${backfillIds.size} importance-only reject(s) after boundary/dedup shrink`,
348
+ );
349
+ }
350
+ }
351
+ }
280
352
  // Task 0392 R2: the raw pool entering QC, captured OUTSIDE the timed block so a cached rerun
281
353
  // still records it (`10-collect/pool.json` is a different artifact — this is the plan snapshot
282
354
  // the QC filter actually reads). The QC drops are named by ID difference, so the stage's own
283
355
  // arithmetic holds instead of being inferred.
284
356
  const poolDocs = metadataOf(readJson(planContent)).docs;
285
357
  const poolIds = (Array.isArray(poolDocs) ? poolDocs : []).map((doc) => String((doc as { id?: unknown }).id ?? ''));
286
- const boundaryIds = new Set(boundaryDocs.map((doc) => String((doc as { id?: unknown }).id ?? '')));
358
+ const boundaryIds = new Set([
359
+ ...boundaryDocs.map((doc) => String((doc as { id?: unknown }).id ?? '')),
360
+ ...backfillIds,
361
+ ]);
287
362
  const qcDropped = poolIds.filter((id) => !boundaryIds.has(id));
288
363
  // Task 0392 R2: one record per stage that ran, so each stage is provable on its own
289
364
  // (`input === kept + dropped`) instead of being inferred from one cross-stage sum.
290
365
  const selectionPath = selectionAttemptsPath(workDir);
291
366
  sted('write', selectionPath, () => {
292
367
  const attemptOrdinal = (readSelectionAttempts(workDir)?.attempts.length ?? 0) + 1;
293
- const keptDocs = dropped.length > 0 ? deduped : currentDocs;
294
368
  recordSelectionAttempt(workDir, {
295
369
  runDate,
296
370
  attemptId: `${runDate}#${attemptOrdinal}`,
297
371
  spec: readTopicBoundary(),
298
372
  stages: [
299
- { stage: 'qc', input: poolIds.length, kept: boundaryDocs.length, dropped: qcDropped },
373
+ {
374
+ stage: 'qc',
375
+ input: poolIds.length,
376
+ kept: boundaryDocs.length + backfillIds.size,
377
+ dropped: qcDropped,
378
+ },
300
379
  // The boundary's drops are rule-tagged, not just counted: the exclusions carry them.
301
380
  {
302
381
  stage: 'topicBoundary',
303
- input: boundaryDocs.length,
304
- kept: currentDocs.length,
382
+ input: boundaryDocs.length + backfillIds.size,
383
+ kept: currentDocs.length + backfillIds.size,
305
384
  dropped: excluded.map((entry) => entry.id),
306
385
  },
307
- { stage: 'dedup', input: currentDocs.length, kept: keptDocs.length, dropped },
386
+ { stage: 'dedup', input: currentDocs.length + backfillIds.size, kept: keptDocs.length, dropped },
308
387
  ],
309
388
  // Post-dedup survivors, so the recorded kept set is what later stages actually receive.
310
389
  keptIds: keptDocs.map((doc) => String((doc as { id?: unknown }).id ?? '')),
@@ -2398,6 +2477,7 @@ export function dailyPlan(args: string[]): void {
2398
2477
  runDate,
2399
2478
  planMaxItems,
2400
2479
  perSourceCap,
2480
+ backfillCapped: 'true',
2401
2481
  deferPlanDocs,
2402
2482
  });
2403
2483
  timed(workDir, 'plan', () => {
@@ -2426,6 +2506,7 @@ export function dailyPlan(args: string[]): void {
2426
2506
  env: {
2427
2507
  EPISODE_PLAN_MAX_ITEMS: planMaxItems,
2428
2508
  EPISODE_PLAN_PER_SOURCE_CAP: perSourceCap,
2509
+ EPISODE_PLAN_BACKFILL_CAPPED: 'true',
2429
2510
  EPISODE_PLAN_DATE: runDate,
2430
2511
  },
2431
2512
  },
@@ -20,6 +20,9 @@
20
20
  * itc-publish-next <work_dir> (0151, sibling)
21
21
  * music-* (0403, body in the sibling music-stages.ts): prepare/explore/select/
22
22
  * analyze/judge-input/finalize for plugins/kk/workflows/kk-music.yaml
23
+ * video-prepare / video-verify (0457, body in the sibling video-stages.ts): resolve an authored
24
+ * brief into the executor's request, then prove the rendered MP4 matches the
25
+ * Content and write the verification receipt
23
26
  *
24
27
  * `validate` / `wrap` / `render-storm` resolve the shipped sibling sidecars and delegate to them;
25
28
  * nothing about those sidecars changed. The `prepare-*` verbs and `duration` keep the logic that
@@ -49,6 +52,7 @@ import {
49
52
  copyFileSync,
50
53
  existsSync,
51
54
  mkdirSync,
55
+ readdirSync,
52
56
  readFileSync,
53
57
  realpathSync,
54
58
  renameSync,
@@ -124,6 +128,16 @@ export function fail(message: string): never {
124
128
  * apps/cli/tests/kk-workflow-stages.test.ts) from installs where the sibling may be absent, so
125
129
  * the itc-* stages fail loud with a remediation path instead of breaking every stage at load.
126
130
  */
131
+ async function loadVideoStages(): Promise<typeof import('./video-stages.ts')> {
132
+ try {
133
+ return await import('./video-stages.ts');
134
+ } catch {
135
+ fail(
136
+ 'video-stages.ts not found next to kk-workflow-stages.ts — install or refresh the kk package (bun link in a checkout)',
137
+ );
138
+ }
139
+ }
140
+
127
141
  async function loadItcStages(): Promise<typeof import('./itc-stages.ts')> {
128
142
  try {
129
143
  return await import('./itc-stages.ts');
@@ -1570,6 +1584,21 @@ function coverPatchWarning(metadata: Record<string, unknown>, fallbackPageUrl =
1570
1584
  * fabricated link. `KK_SURFDASH_PATCH_OFFLINE=1` keeps rehearsal runs hermetic the same way the
1571
1585
  * legacy voice2 stage does.
1572
1586
  */
1587
+ function findMatrixRowId(
1588
+ publishDir: string,
1589
+ outcome: { rows?: Array<{ id?: string }> } | null,
1590
+ prefix: string,
1591
+ ): string | undefined {
1592
+ const fromOutcome = (outcome?.rows ?? []).map((row) => row.id ?? '').find((id) => id.startsWith(prefix));
1593
+ if (fromOutcome !== undefined) return fromOutcome;
1594
+ const receiptsDir = join(publishDir, 'receipts');
1595
+ if (!existsSync(receiptsDir)) return undefined;
1596
+ const match = readdirSync(receiptsDir)
1597
+ .filter((name) => name.startsWith(prefix) && name.endsWith('.json'))
1598
+ .sort()[0];
1599
+ return match !== undefined ? match.slice(0, -'.json'.length) : undefined;
1600
+ }
1601
+
1573
1602
  function publishMatrixPatchSurfdash(args: string[]): void {
1574
1603
  const flag = (name: string): string | undefined => {
1575
1604
  const i = args.indexOf(name);
@@ -1599,10 +1628,8 @@ function publishMatrixPatchSurfdash(args: string[]): void {
1599
1628
  const outcome = readJson(join(publishDir, `outcome.${window}.json`)) as {
1600
1629
  rows?: Array<{ id?: string }>;
1601
1630
  } | null;
1602
- const rowId = (prefix: string): string | undefined =>
1603
- (outcome?.rows ?? []).map((row) => row.id ?? '').find((id) => id.startsWith(prefix));
1604
- const sdId = rowId('surfdash-pub');
1605
- const podId = rowId('podcast-pub');
1631
+ const sdId = findMatrixRowId(publishDir, outcome, 'surfdash-pub');
1632
+ const podId = findMatrixRowId(publishDir, outcome, 'podcast-pub');
1606
1633
  if (sdId === undefined) {
1607
1634
  const error = 'skipped: no surfdash target in this window — nothing to patch';
1608
1635
  writeResult({ ok: false, target: 'surfdash-pub', error });
@@ -1764,10 +1791,8 @@ function publishMatrixPatchPodcast(args: string[]): void {
1764
1791
  const outcome = readJson(join(publishDir, `outcome.${window}.json`)) as {
1765
1792
  rows?: Array<{ id?: string }>;
1766
1793
  } | null;
1767
- const rowId = (prefix: string): string | undefined =>
1768
- (outcome?.rows ?? []).map((row) => row.id ?? '').find((id) => id.startsWith(prefix));
1769
- const podId = rowId('podcast-pub');
1770
- const sdId = rowId('surfdash-pub');
1794
+ const podId = findMatrixRowId(publishDir, outcome, 'podcast-pub');
1795
+ const sdId = findMatrixRowId(publishDir, outcome, 'surfdash-pub');
1771
1796
  if (podId === undefined || sdId === undefined) {
1772
1797
  const error = 'skipped: requires both podcast-pub and surfdash-pub targets in this window';
1773
1798
  writeResult({ ok: false, target: 'podcast-pub', error });
@@ -2407,6 +2432,18 @@ if (import.meta.main)
2407
2432
  itcAdaptVerify(rest);
2408
2433
  break;
2409
2434
  }
2435
+ case 'video-prepare':
2436
+ case 'video-verify': {
2437
+ const { videoPrepare, videoVerify } = await loadVideoStages();
2438
+ try {
2439
+ if (stage === 'video-prepare') videoPrepare(rest);
2440
+ else videoVerify(rest);
2441
+ } catch (error: unknown) {
2442
+ // The stage module throws its own refusal type; one status line, then exit.
2443
+ fail(error instanceof Error ? error.message.replace(/^video-stage: /, '') : String(error));
2444
+ }
2445
+ break;
2446
+ }
2410
2447
  case 'music-prepare':
2411
2448
  case 'music-explore':
2412
2449
  case 'music-select':
@@ -2434,8 +2471,26 @@ if (import.meta.main)
2434
2471
  }
2435
2472
  break;
2436
2473
  }
2474
+ case 'wiki-normalize': {
2475
+ const { runWikiNormalizeStage } = await import(join(SCRIPTS_DIR, 'wiki-normalize-stages.ts'));
2476
+ try {
2477
+ await runWikiNormalizeStage(rest);
2478
+ } catch (err: unknown) {
2479
+ fail(err instanceof Error ? err.message : String(err));
2480
+ }
2481
+ break;
2482
+ }
2483
+ case 'wiki-normalize-probe': {
2484
+ const { runWikiNormalizeProbeStage } = await import(join(SCRIPTS_DIR, 'wiki-normalize-stages.ts'));
2485
+ try {
2486
+ await runWikiNormalizeProbeStage();
2487
+ } catch (err: unknown) {
2488
+ fail(err instanceof Error ? err.message : String(err));
2489
+ }
2490
+ break;
2491
+ }
2437
2492
  default:
2438
2493
  fail(
2439
- `unknown stage: ${stage ?? '(none)'} (expected prepare-itc|prepare-solo|prepare-storm|validate|wrap|duration|render-storm|itc-*|daily-*|seo-*|music-*)`,
2494
+ `unknown stage: ${stage ?? '(none)'} (expected prepare-itc|prepare-solo|prepare-storm|validate|wrap|duration|render-storm|itc-*|daily-*|seo-*|music-*|video-*)`,
2440
2495
  );
2441
2496
  }