@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
@@ -1,31 +1,31 @@
1
1
  import { dirname, join } from 'node:path';
2
2
  import { fileURLToPath } from 'node:url';
3
3
  import { parseArgs } from 'node:util';
4
- import { videoGenContentSchema } from '@gobing-ai/kk-core';
4
+ import { type RenderProvenance, videoGenContentSchema } from '@gobing-ai/kk-core';
5
5
  import type { FileSystem } from '@gobing-ai/ts-runtime';
6
6
  import { echoError } from '@gobing-ai/ts-utils';
7
7
  import { transcribeWords } from './captions';
8
- import { resolveLedgerPath } from './ccu-ledger';
8
+ import { type BudgetLock, resolveLedgerPath } from './ccu-ledger';
9
9
  import { type ColabJob, runColabJob } from './colab-runner';
10
10
  import { nodeFileSystem } from './fs';
11
11
  import { probeAudioDuration, sliceHookAudio } from './hook-slicer';
12
- import { resolveVideoInputs, type VideoInputs } from './inputs';
12
+ import { OUTPUT_DIR_NAME, type RenderInput, resolveRenderInput } from './inputs';
13
13
  import {
14
14
  AVATAR_COMPOSITION_ID,
15
15
  COMPOSITION_ID,
16
16
  chunkCaptions,
17
17
  HYBRID_PIP_COMPOSITION_ID,
18
18
  resolveHookWindow,
19
+ resolveStandaloneWindow,
19
20
  VIDEO,
20
21
  } from './layout';
21
22
  import { type RunProcess, runtimeRunProcess } from './process';
22
23
  import { buildAvatarProps, buildEditorialProps, buildHybridPipProps } from './props';
23
- import { type RenderVideo, renderReel, stageAssets } from './render';
24
- import { parseVideoGenRequestInput, type VideoGenRequest } from './request';
25
- import { localKenBurns, prepareVisualLayer, resolveAvatarProvider } from './visual-provider';
24
+ import { type RenderVideo, renderReel, stageAssets, stageAudio } from './render';
25
+ import { parseVideoGenRequestInput } from './request';
26
+ import { prepareVisualLayer, resolveAvatarProvider } from './visual-provider';
26
27
 
27
- /** Directory the plugin writes every artifact into, relative to the daily run's work dir. */
28
- export const OUTPUT_DIR_NAME = '32-video';
28
+ export { OUTPUT_DIR_NAME };
29
29
 
30
30
  /** Injected dependencies: the process seam, the filesystem seam and the Remotion renderer. */
31
31
  export interface VideoGenDeps {
@@ -34,6 +34,8 @@ export interface VideoGenDeps {
34
34
  fs: FileSystem;
35
35
  /** Clock for the CCU ledger's rolling window and job durations (tests pin it). */
36
36
  now: () => number;
37
+ /** Admission claim seam; production uses `kk lock` against the works-root store. */
38
+ budgetLock?: BudgetLock;
37
39
  }
38
40
 
39
41
  const DEFAULT_PLUGIN_ROOT = fileURLToPath(new URL('..', import.meta.url));
@@ -45,40 +47,39 @@ function resolveOutputOutPath(values: { out?: string | undefined }): string {
45
47
  return values.out;
46
48
  }
47
49
 
48
- /** Write the video Content (shared by the editorial and avatar paths). */
50
+ /** Write the video Content (shared by the daily and standalone paths). */
49
51
  async function emitContent(args: {
50
52
  fs: FileSystem;
51
53
  outPath: string;
52
- videoPath: string;
53
- inputs: VideoInputs;
54
- request: VideoGenRequest;
54
+ input: RenderInput;
55
55
  durationSec: number;
56
- wordsPath: string;
57
- headline: string;
58
56
  providerId: string;
57
+ renderProvenance?: RenderProvenance;
59
58
  fallbackUsed?: boolean;
60
59
  warnings?: string[];
61
60
  syntheticPresenter?: boolean;
62
61
  }): Promise<number> {
63
62
  const content = videoGenContentSchema.parse({
64
- title: args.headline,
65
- body: args.inputs.plan.items.map((item) => item.lead).join('\n\n'),
63
+ title: args.input.title,
64
+ body: args.input.body,
66
65
  format: 'video',
67
66
  metadata: {
68
67
  generator: 'kk:video-gen',
69
- videoPath: args.videoPath,
70
- coverPath: args.inputs.coverPath,
68
+ videoPath: args.input.artifacts.videoPath,
69
+ ...(args.input.coverPath === undefined ? {} : { coverPath: args.input.coverPath }),
71
70
  width: VIDEO.width,
72
71
  height: VIDEO.height,
73
72
  fps: VIDEO.fps,
74
73
  durationSec: args.durationSec,
75
- visualMode: args.request.visualMode,
74
+ visualMode: args.input.visualMode,
76
75
  renderProvider: args.providerId,
76
+ ...(args.renderProvenance === undefined ? {} : { renderProvenance: args.renderProvenance }),
77
77
  ...(args.fallbackUsed === true ? { fallbackUsed: true } : {}),
78
78
  ...(args.warnings === undefined || args.warnings.length === 0 ? {} : { warnings: args.warnings }),
79
- captionsPath: args.wordsPath,
79
+ // Captions ship under every layout, including `captionStyle: off`.
80
+ captionsPath: args.input.artifacts.wordsPath,
80
81
  ...(args.syntheticPresenter === true ? { syntheticPresenter: true } : {}),
81
- ...(args.inputs.plan.tags.length > 0 ? { tags: args.inputs.plan.tags } : {}),
82
+ ...(args.input.tags.length > 0 ? { tags: args.input.tags } : {}),
82
83
  },
83
84
  });
84
85
  await args.fs.ensureDir(dirname(args.outPath));
@@ -87,12 +88,30 @@ async function emitContent(args: {
87
88
  }
88
89
 
89
90
  /**
90
- * `kk executor run video-gen --in <request.json> --out <content.json>`: render a 9:16 editorial
91
- * teaser from a completed daily AI news run and emit `videoGenContentSchema` Content.
91
+ * The teaser window for this run: a standalone brief obeys its own duration target and source
92
+ * bounds, while the daily path keeps the 45–60s cadence in `resolveHookWindow` (D91 R2).
93
+ */
94
+ function resolveWindow(input: RenderInput, sourceDurationSec: number) {
95
+ if (input.inputKind === 'daily') return resolveHookWindow(input.hook, sourceDurationSec);
96
+ const durationTargetSec = input.durationTargetSec;
97
+ if (durationTargetSec === undefined) {
98
+ throw new Error('video-gen: standalone brief is missing durationTargetSec');
99
+ }
100
+ return resolveStandaloneWindow({
101
+ hook: input.hook,
102
+ durationTargetSec,
103
+ sourceDurationSec,
104
+ });
105
+ }
106
+
107
+ /**
108
+ * `kk executor run video-gen --in <request.json> --out <content.json>`: render a 9:16 short from
109
+ * either a completed daily AI news run or a standalone brief, and emit `videoGenContentSchema`
110
+ * Content.
92
111
  *
93
- * Order is the fail-closed contract: request → inputs → teaser window → artifact dir. Nothing is
94
- * spawned (no ffprobe/ffmpeg/uv/Chromium) until every input that can be checked without a render has
95
- * been checked.
112
+ * Order is the fail-closed contract: request → normalized inputs → teaser window → artifact dir.
113
+ * Nothing is spawned (no ffprobe/ffmpeg/uv/Chromium) until every input that can be checked without
114
+ * a render has been checked.
96
115
  */
97
116
  export async function main(argv: string[] = process.argv.slice(2), deps?: Partial<VideoGenDeps>): Promise<number> {
98
117
  const { values } = parseArgs({ args: argv, options: { in: { type: 'string' }, out: { type: 'string' } } });
@@ -105,102 +124,111 @@ export async function main(argv: string[] = process.argv.slice(2), deps?: Partia
105
124
  throw new Error('video-gen: missing --in <request.json>');
106
125
  }
107
126
  const outPath = resolveOutputOutPath(values);
108
- const request = parseVideoGenRequestInput(JSON.parse(await fs.readFile(values.in)) as unknown);
109
- const portraitPath = request.visualMode === 'editorial' ? undefined : request.hostPortraitPath;
110
- if (portraitPath !== undefined) {
111
- try {
112
- const portrait = await fs.stat(portraitPath);
113
- if (
114
- portrait === null ||
115
- !portrait.isFile() ||
116
- (await Bun.file(portraitPath).slice(0, 1).arrayBuffer()).byteLength === 0
117
- ) {
118
- throw new Error('no readable portrait bytes');
119
- }
120
- } catch {
121
- throw new Error(`video-gen: host portrait ${portraitPath} is missing or unreadable`);
122
- }
123
- }
124
- const inputs = await resolveVideoInputs(request.workDir, request.runDate, fs);
127
+ // A standalone brief's relative paths resolve from the request file's own directory.
128
+ const requestInput = parseVideoGenRequestInput(
129
+ JSON.parse(await fs.readFile(values.in)) as unknown,
130
+ dirname(values.in),
131
+ );
132
+ const input = await resolveRenderInput(requestInput, fs);
133
+ const portraitPath = input.visualMode === 'editorial' ? undefined : input.hostPortraitPath;
125
134
 
126
- const audioDurationSec = await probeAudioDuration(inputs.audioPath, runProcess);
127
- const window = resolveHookWindow(request.hook, audioDurationSec);
135
+ const audioDurationSec = await probeAudioDuration(input.audioPath, runProcess);
136
+ const window = resolveWindow(input, audioDurationSec);
128
137
 
129
- const outputDir = join(request.workDir, OUTPUT_DIR_NAME);
130
- const publicDir = join(outputDir, 'public');
131
- await fs.ensureDir(publicDir);
132
- const hookPath = join(outputDir, `${request.runDate}_hook.wav`);
133
- const wordsPath = join(outputDir, `${request.runDate}_words.json`);
134
- const videoPath = join(outputDir, `${request.runDate}_video.mp4`);
135
-
136
- await sliceHookAudio({ audioPath: inputs.audioPath, outputPath: hookPath, window, runProcess });
138
+ const { artifacts } = input;
139
+ await fs.ensureDir(artifacts.publicDir);
140
+ await sliceHookAudio({
141
+ audioPath: input.audioPath,
142
+ outputPath: artifacts.hookPath,
143
+ window,
144
+ runProcess,
145
+ });
137
146
  const { words, waveform } = await transcribeWords({
138
147
  pluginRoot,
139
- audioPath: hookPath,
140
- outputPath: wordsPath,
148
+ audioPath: artifacts.hookPath,
149
+ outputPath: artifacts.wordsPath,
141
150
  runProcess,
142
151
  });
143
152
  const captions = chunkCaptions(words);
144
153
 
145
154
  // Loaded after the fail-closed checks: a rejected request never pays the Remotion import.
146
155
  const render = deps?.render ?? (await import('./remotion/engine')).remotionRender;
147
- const headline = inputs.plan.headline ?? inputs.plan.items[0]?.lead ?? request.runDate;
148
156
  const colabDeps = {
149
157
  runProcess,
150
158
  fs,
151
- ledgerPath: resolveLedgerPath(request.workDir),
152
- outputDir,
153
- maxMonthlyCcu: request.colab?.maxMonthlyCcu,
159
+ // `KK_WORKS_DIR` is planted by the kk invocation boundary as an absolute path, so the
160
+ // daily and standalone paths share one ledger; a direct caller keeps the legacy
161
+ // `<workDir>/..` fallback (D91 R8).
162
+ ledgerPath: resolveLedgerPath(input.ledgerWorkDir, process.env),
163
+ outputDir: input.outputDir,
164
+ maxMonthlyCcu: input.colab?.maxMonthlyCcu,
154
165
  now: deps?.now,
155
- ...(request.colab?.cacheDir === undefined ? {} : { cacheDir: request.colab.cacheDir }),
166
+ ...(deps?.budgetLock === undefined ? {} : { budgetLock: deps.budgetLock }),
167
+ ...(input.colab?.cacheDir === undefined ? {} : { cacheDir: input.colab.cacheDir }),
168
+ // Managed external job (0464 R2): the supervisor plants this so every session row it
169
+ // creates is attributable. A direct `kk executor run` has none and records a null job id.
170
+ ...(process.env.KK_EXTERNAL_JOB_ID === undefined || process.env.KK_EXTERNAL_JOB_ID === ''
171
+ ? {}
172
+ : { jobId: process.env.KK_EXTERNAL_JOB_ID }),
156
173
  };
157
174
  const runJob = (job: ColabJob) => runColabJob(job, colabDeps);
158
175
 
159
176
  if (portraitPath !== undefined) {
160
177
  // 0452: avatar modes have NO fallback — a missing presenter is a broken video, so a
161
178
  // failure exits nonzero (the daily node's `onError: continue` keeps the episode alive).
162
- const avatar = resolveAvatarProvider(request.provider ?? 'musetalk', {
179
+ const avatar = resolveAvatarProvider(input.provider ?? 'musetalk', {
163
180
  runJob,
164
- outputDir,
165
- runDate: request.runDate,
181
+ outputDir: input.outputDir,
182
+ runDate: input.providerNameBase,
166
183
  script: join(
167
184
  pluginRoot,
168
185
  'python',
169
- request.provider === 'echomimic-v2' ? 'colab_echomimic_v2.py' : 'colab_musetalk.py',
186
+ input.provider === 'echomimic-v2' ? 'colab_echomimic_v2.py' : 'colab_musetalk.py',
170
187
  ),
171
188
  remoteDir: '/content/kk-video',
172
189
  portraitPath,
173
- audioPath: hookPath,
190
+ audioPath: artifacts.hookPath,
174
191
  exists: async (path: string) => (await fs.exists(path)) === true,
175
- ...(request.colab?.gpu === undefined ? {} : { gpu: request.colab.gpu }),
176
- ...(request.colab?.timeoutMs === undefined ? {} : { timeoutMs: request.colab.timeoutMs }),
177
- env: { KK_COLAB_CACHE_DIR: request.colab?.cacheDir ?? '/content/drive/MyDrive/kk-video-cache' },
192
+ ...(input.colab?.gpu === undefined ? {} : { gpu: input.colab.gpu }),
193
+ ...(input.colab?.timeoutMs === undefined ? {} : { timeoutMs: input.colab.timeoutMs }),
194
+ env: { KK_COLAB_CACHE_DIR: input.colab?.cacheDir ?? '/content/drive/MyDrive/kk-video-cache' },
178
195
  });
179
196
  const presenterLayer = await avatar.prepare({ images: [] });
180
197
  const stagedPresenter = await stageAssets({
181
198
  images: presenterLayer.kind === 'clips' ? presenterLayer.clips : [],
182
- audioPath: hookPath,
183
- publicDir,
184
- fs,
185
- });
186
- const editorialLayer = await localKenBurns.prepare({ images: [inputs.coverPath, ...inputs.cardPaths] });
187
- const stagedEditorial = await stageAssets({
188
- images: editorialLayer.kind === 'stills' ? editorialLayer.images : [],
189
- audioPath: hookPath,
190
- publicDir,
199
+ audioPath: artifacts.hookPath,
200
+ publicDir: artifacts.publicDir,
191
201
  fs,
192
202
  });
203
+ // An avatar brief may carry no stills at all; the presenter clip is the whole frame.
204
+ const stagedEditorial =
205
+ input.imagePaths.length === 0
206
+ ? {
207
+ imageNames: [] as string[],
208
+ audioName: await stageAudio({
209
+ audioPath: artifacts.hookPath,
210
+ publicDir: artifacts.publicDir,
211
+ fs,
212
+ }),
213
+ }
214
+ : await stageAssets({
215
+ images: input.imagePaths,
216
+ audioPath: artifacts.hookPath,
217
+ publicDir: artifacts.publicDir,
218
+ fs,
219
+ });
193
220
  const shared = {
194
221
  captions,
195
222
  waveform,
196
- headline,
223
+ headline: input.title,
197
224
  audioName: stagedEditorial.audioName,
198
225
  durationSec: window.durationSec,
199
226
  width: VIDEO.width,
200
227
  height: VIDEO.height,
201
228
  fps: VIDEO.fps,
229
+ presentation: input.presentation,
202
230
  };
203
- const isAvatar = request.visualMode === 'avatar';
231
+ const isAvatar = input.visualMode === 'avatar';
204
232
  const props = isAvatar
205
233
  ? buildAvatarProps({
206
234
  layer: { kind: 'clips', clips: stagedPresenter.imageNames },
@@ -214,8 +242,8 @@ export async function main(argv: string[] = process.argv.slice(2), deps?: Partia
214
242
  await renderReel({
215
243
  compositionId: isAvatar ? AVATAR_COMPOSITION_ID : HYBRID_PIP_COMPOSITION_ID,
216
244
  props,
217
- publicDir,
218
- outputPath: videoPath,
245
+ publicDir: artifacts.publicDir,
246
+ outputPath: artifacts.videoPath,
219
247
  entryPoint: join(pluginRoot, 'src', 'remotion', 'index.tsx'),
220
248
  render,
221
249
  fs,
@@ -223,45 +251,51 @@ export async function main(argv: string[] = process.argv.slice(2), deps?: Partia
223
251
  return await emitContent({
224
252
  fs,
225
253
  outPath,
226
- videoPath,
227
- inputs,
228
- request,
254
+ input,
229
255
  durationSec: window.durationSec,
230
- wordsPath,
231
- headline,
232
- providerId: request.provider ?? 'musetalk',
256
+ providerId: input.provider ?? 'musetalk',
233
257
  syntheticPresenter: true,
234
258
  });
235
259
  }
236
260
 
237
- const wantedProvider = request.provider ?? 'local-ken-burns';
261
+ const wantedProvider = input.provider ?? 'local-ken-burns';
262
+ // Both GPU editorial providers take the same seam: a worker script, its output dir and the
263
+ // job runner. Only the script differs (D91 R7).
264
+ const gpuEditorial = wantedProvider === 'wan21-i2v' || wantedProvider === 'comfyui-minimax-h3';
238
265
  const prepared = await prepareVisualLayer({
239
- mode: request.visualMode,
266
+ mode: input.visualMode,
240
267
  providerId: wantedProvider,
241
- images: [inputs.coverPath, ...inputs.cardPaths],
242
- ...(wantedProvider === 'wan21-i2v'
268
+ images: input.imagePaths,
269
+ allowFallback: input.allowEditorialFallback,
270
+ ...(gpuEditorial
243
271
  ? {
244
272
  wan21: {
245
273
  runJob,
246
- outputDir,
247
- runDate: request.runDate,
248
- script: join(pluginRoot, 'python', 'colab_wan21_i2v.py'),
274
+ outputDir: input.outputDir,
275
+ runDate: input.providerNameBase,
276
+ script: join(
277
+ pluginRoot,
278
+ 'python',
279
+ wantedProvider === 'comfyui-minimax-h3' ? 'colab_comfyui_h3.py' : 'colab_wan21_i2v.py',
280
+ ),
249
281
  remoteDir: '/content/kk-video',
250
282
  exists: async (path: string) => (await fs.exists(path)) === true,
251
- ...(request.colab?.gpu === undefined ? {} : { gpu: request.colab.gpu }),
252
- ...(request.colab?.timeoutMs === undefined ? {} : { timeoutMs: request.colab.timeoutMs }),
283
+ ...(input.colab?.gpu === undefined ? {} : { gpu: input.colab.gpu }),
284
+ ...(input.colab?.timeoutMs === undefined ? {} : { timeoutMs: input.colab.timeoutMs }),
253
285
  env: {
254
- KK_COLAB_CACHE_DIR: request.colab?.cacheDir ?? '/content/drive/MyDrive/kk-video-cache',
286
+ KK_COLAB_CACHE_DIR: input.colab?.cacheDir ?? '/content/drive/MyDrive/kk-video-cache',
255
287
  },
256
288
  },
257
289
  }
258
290
  : {}),
259
291
  });
260
292
  const layer = prepared.layer;
261
- const staged =
262
- layer.kind === 'stills'
263
- ? await stageAssets({ images: layer.images, audioPath: hookPath, publicDir, fs })
264
- : await stageAssets({ images: layer.clips, audioPath: hookPath, publicDir, fs });
293
+ const staged = await stageAssets({
294
+ images: layer.kind === 'stills' ? layer.images : layer.clips,
295
+ audioPath: artifacts.hookPath,
296
+ publicDir: artifacts.publicDir,
297
+ fs,
298
+ });
265
299
 
266
300
  const props = buildEditorialProps({
267
301
  // The shell renders the staged names, not the source paths the provider resolved.
@@ -271,19 +305,20 @@ export async function main(argv: string[] = process.argv.slice(2), deps?: Partia
271
305
  : { kind: 'clips', clips: staged.imageNames },
272
306
  captions,
273
307
  waveform,
274
- headline: inputs.plan.headline ?? inputs.plan.items[0]?.lead ?? request.runDate,
308
+ headline: input.title,
275
309
  audioName: staged.audioName,
276
310
  durationSec: window.durationSec,
277
311
  width: VIDEO.width,
278
312
  height: VIDEO.height,
279
313
  fps: VIDEO.fps,
314
+ presentation: input.presentation,
280
315
  });
281
316
 
282
317
  await renderReel({
283
318
  compositionId: COMPOSITION_ID,
284
319
  props,
285
- publicDir,
286
- outputPath: videoPath,
320
+ publicDir: artifacts.publicDir,
321
+ outputPath: artifacts.videoPath,
287
322
  entryPoint: join(pluginRoot, 'src', 'remotion', 'index.tsx'),
288
323
  render,
289
324
  fs,
@@ -292,13 +327,10 @@ export async function main(argv: string[] = process.argv.slice(2), deps?: Partia
292
327
  return await emitContent({
293
328
  fs,
294
329
  outPath,
295
- videoPath,
296
- inputs,
297
- request,
330
+ input,
298
331
  durationSec: window.durationSec,
299
- wordsPath,
300
- headline,
301
332
  providerId: prepared.providerId,
333
+ ...(layer.kind === 'clips' && layer.provenance !== undefined ? { renderProvenance: layer.provenance } : {}),
302
334
  fallbackUsed: prepared.fallbackUsed,
303
335
  warnings: prepared.warnings,
304
336
  });
@@ -1,13 +1,30 @@
1
- import { isAbsolute, join, resolve } from 'node:path';
1
+ import { dirname, isAbsolute, join, resolve } from 'node:path';
2
+ import type { VideoRenderProvider, VideoVisualMode } from '@gobing-ai/kk-core';
2
3
  import type { FileSystem } from '@gobing-ai/ts-runtime';
3
4
  import { nodeFileSystem } from './fs';
5
+ import type { HookWindow } from './layout';
6
+ import type {
7
+ ColabRequest,
8
+ ExplicitVideoRequest,
9
+ VideoGenRequest,
10
+ VideoGenRequestInput,
11
+ VideoPresentation,
12
+ } from './request';
4
13
 
5
14
  /**
6
- * Input resolution for one daily AI news run: the plugin reads the same work-dir artifacts the
7
- * voice and cover stages already wrote (no second source of truth, no re-encode). All IO goes
8
- * through the ts-runtime FileSystem seam, which is also the tests' injection point.
15
+ * Input resolution for one render: the daily work-dir artifacts or a standalone brief, both
16
+ * normalized into the single {@link RenderInput} the renderer consumes (D91 R1).
17
+ *
18
+ * WHY one shape: the daily path already had nine steps reading its own fields; giving the standalone
19
+ * path a second set would fork every one of them. The adapter is the only place that knows which
20
+ * request shape arrived, so every downstream step is shared (R1/R2).
21
+ *
22
+ * All IO goes through the ts-runtime FileSystem seam, which is also the tests' injection point.
9
23
  */
10
24
 
25
+ /** Directory the daily path writes every artifact into, relative to the daily run's work dir. */
26
+ export const OUTPUT_DIR_NAME = '32-video';
27
+
11
28
  /** One curated plan item; `lead` is the fact sentence the teaser hook is cut from. */
12
29
  export interface ScriptPlanItem {
13
30
  id: string;
@@ -31,6 +48,46 @@ export interface VideoInputs {
31
48
  cardPaths: string[];
32
49
  }
33
50
 
51
+ /** Where this run's artifacts land; daily keeps the run-date names, standalone uses the brief's own. */
52
+ export interface RenderArtifacts {
53
+ hookPath: string;
54
+ wordsPath: string;
55
+ videoPath: string;
56
+ publicDir: string;
57
+ }
58
+
59
+ /**
60
+ * The normalized render input — the one shape every later step consumes, whichever request arrived.
61
+ */
62
+ export interface RenderInput {
63
+ inputKind: 'daily' | 'explicit';
64
+ /** Absolute audio the teaser is cut from. */
65
+ audioPath: string;
66
+ /** Absolute stills in play order; the first one is the Content cover when there is one. */
67
+ imagePaths: string[];
68
+ /** The Content cover; absent for an avatar reel rendered from a portrait alone. */
69
+ coverPath?: string;
70
+ title: string;
71
+ body: string;
72
+ tags: string[];
73
+ outputDir: string;
74
+ /** The daily run dir (ledger anchor) or the standalone output dir's parent. */
75
+ ledgerWorkDir: string;
76
+ visualMode: VideoVisualMode;
77
+ provider?: VideoRenderProvider;
78
+ colab?: ColabRequest;
79
+ hostPortraitPath?: string;
80
+ /** Standalone only: reel length when the brief names no window. */
81
+ durationTargetSec?: number;
82
+ hook?: HookWindow;
83
+ presentation: VideoPresentation;
84
+ /** `false` makes a standalone editorial GPU failure fail the run instead of falling back. */
85
+ allowEditorialFallback: boolean;
86
+ /** Basename base for intermediate provider outputs (`<runDate>` daily, `standalone` otherwise). */
87
+ providerNameBase: string;
88
+ artifacts: RenderArtifacts;
89
+ }
90
+
34
91
  function asRecord(value: unknown): Record<string, unknown> | null {
35
92
  return typeof value === 'object' && value !== null && !Array.isArray(value)
36
93
  ? (value as Record<string, unknown>)
@@ -148,3 +205,104 @@ export async function resolveVideoInputs(
148
205
 
149
206
  return { audioPath, planPath, plan, coverPath, cardPaths };
150
207
  }
208
+
209
+ /** Throw unless `path` is a readable, non-empty file. */
210
+ async function assertReadableFile(fs: FileSystem, path: string, label: string): Promise<void> {
211
+ try {
212
+ const stat = await fs.stat(path);
213
+ if (stat === null || !stat.isFile() || (await Bun.file(path).slice(0, 1).arrayBuffer()).byteLength === 0) {
214
+ throw new Error('no readable bytes');
215
+ }
216
+ } catch {
217
+ throw new Error(`video-gen: ${label} ${path} is missing or unreadable`);
218
+ }
219
+ }
220
+
221
+ /**
222
+ * Daily adapter (R2): resolve the work-dir artifacts and map them onto {@link RenderInput}, keeping
223
+ * the run-date artifact names, the derived title/tags and the shipped kinetic presentation.
224
+ */
225
+ async function resolveDailyRenderInput(request: VideoGenRequest, fs: FileSystem): Promise<RenderInput> {
226
+ const inputs = await resolveVideoInputs(request.workDir, request.runDate, fs);
227
+ if (request.hostPortraitPath !== undefined) {
228
+ await assertReadableFile(fs, request.hostPortraitPath, 'host portrait');
229
+ }
230
+ const outputDir = join(request.workDir, OUTPUT_DIR_NAME);
231
+ return {
232
+ inputKind: 'daily',
233
+ audioPath: inputs.audioPath,
234
+ imagePaths: [inputs.coverPath, ...inputs.cardPaths],
235
+ coverPath: inputs.coverPath,
236
+ title: inputs.plan.headline ?? inputs.plan.items[0]?.lead ?? request.runDate,
237
+ body: inputs.plan.items.map((item) => item.lead).join('\n\n'),
238
+ tags: inputs.plan.tags,
239
+ outputDir,
240
+ ledgerWorkDir: request.workDir,
241
+ visualMode: request.visualMode,
242
+ ...(request.provider === undefined ? {} : { provider: request.provider }),
243
+ ...(request.colab === undefined ? {} : { colab: request.colab }),
244
+ ...(request.hostPortraitPath === undefined ? {} : { hostPortraitPath: request.hostPortraitPath }),
245
+ ...(request.hook === undefined ? {} : { hook: request.hook }),
246
+ presentation: { captionStyle: 'kinetic' },
247
+ // The daily cron must always get a video, so its Wan2.1 failures keep falling back.
248
+ allowEditorialFallback: true,
249
+ providerNameBase: request.runDate,
250
+ artifacts: {
251
+ hookPath: join(outputDir, `${request.runDate}_hook.wav`),
252
+ wordsPath: join(outputDir, `${request.runDate}_words.json`),
253
+ videoPath: join(outputDir, `${request.runDate}_video.mp4`),
254
+ publicDir: join(outputDir, 'public'),
255
+ },
256
+ };
257
+ }
258
+
259
+ /**
260
+ * Standalone adapter (R1): validate the brief's own media before any spawn, then map it onto
261
+ * {@link RenderInput} with the brief's artifact names (`hook.wav`, `words.json`, `video.mp4`).
262
+ */
263
+ async function resolveExplicitRenderInput(request: ExplicitVideoRequest, fs: FileSystem): Promise<RenderInput> {
264
+ await assertReadableFile(fs, request.audioPath, 'standalone audio');
265
+ for (const [position, imagePath] of request.imagePaths.entries()) {
266
+ await assertReadableFile(fs, imagePath, `standalone image ${position + 1}`);
267
+ }
268
+ if (request.hostPortraitPath !== undefined) {
269
+ await assertReadableFile(fs, request.hostPortraitPath, 'host portrait');
270
+ }
271
+ const [coverPath] = request.imagePaths;
272
+ return {
273
+ inputKind: 'explicit',
274
+ audioPath: request.audioPath,
275
+ imagePaths: request.imagePaths,
276
+ ...(coverPath === undefined ? {} : { coverPath }),
277
+ title: request.title,
278
+ body: request.description ?? request.title,
279
+ tags: [],
280
+ outputDir: request.outputDir,
281
+ ledgerWorkDir: dirname(request.outputDir),
282
+ visualMode: request.visualMode,
283
+ ...(request.provider === undefined ? {} : { provider: request.provider }),
284
+ ...(request.colab === undefined ? {} : { colab: request.colab }),
285
+ ...(request.hostPortraitPath === undefined ? {} : { hostPortraitPath: request.hostPortraitPath }),
286
+ durationTargetSec: request.durationTargetSec,
287
+ ...(request.hook === undefined ? {} : { hook: request.hook }),
288
+ presentation: request.presentation,
289
+ allowEditorialFallback: request.allowEditorialFallback === true,
290
+ providerNameBase: 'standalone',
291
+ artifacts: {
292
+ hookPath: join(request.outputDir, 'hook.wav'),
293
+ wordsPath: join(request.outputDir, 'words.json'),
294
+ videoPath: join(request.outputDir, 'video.mp4'),
295
+ publicDir: join(request.outputDir, 'public'),
296
+ },
297
+ };
298
+ }
299
+
300
+ /** Normalize either parsed request shape into the one {@link RenderInput}. */
301
+ export async function resolveRenderInput(
302
+ input: VideoGenRequestInput,
303
+ fs: FileSystem = nodeFileSystem,
304
+ ): Promise<RenderInput> {
305
+ return input.inputKind === 'explicit'
306
+ ? resolveExplicitRenderInput(input.request, fs)
307
+ : resolveDailyRenderInput(input.request, fs);
308
+ }
@@ -152,6 +152,39 @@ export function resolveHookWindow(
152
152
  return { ...window, durationSec: window.endSec - window.startSec };
153
153
  }
154
154
 
155
+ /**
156
+ * Standalone clip policy (D91 R1): a brief is not a 45–60s daily teaser, so it names its own length.
157
+ * A supplied window must be ordered and inside the source; otherwise take the head of the source up
158
+ * to the target. Both rules run before `ffmpeg`, which is why this is pure math.
159
+ */
160
+ export function resolveStandaloneWindow(args: {
161
+ hook: HookWindow | undefined;
162
+ durationTargetSec: number;
163
+ sourceDurationSec: number;
164
+ }): HookWindow & { durationSec: number } {
165
+ assertPositiveFinite(args.durationTargetSec, 'durationTargetSec');
166
+ assertPositiveFinite(args.sourceDurationSec, 'source duration');
167
+ const hook = args.hook;
168
+ if (hook === undefined) {
169
+ const endSec = Math.min(args.sourceDurationSec, args.durationTargetSec);
170
+ return { startSec: 0, endSec, durationSec: endSec };
171
+ }
172
+ if (!Number.isFinite(hook.startSec) || hook.startSec < 0) {
173
+ throw new Error(`video-gen: hook.startSec must be >= 0 (got ${hook.startSec})`);
174
+ }
175
+ if (!Number.isFinite(hook.endSec) || hook.endSec <= hook.startSec) {
176
+ throw new Error(
177
+ `video-gen: hook window must end after it starts (start ${hook.startSec}s, end ${hook.endSec}s)`,
178
+ );
179
+ }
180
+ if (hook.endSec > args.sourceDurationSec) {
181
+ throw new Error(
182
+ `video-gen: hook window ends at ${hook.endSec}s but the standalone audio is only ${args.sourceDurationSec.toFixed(1)}s`,
183
+ );
184
+ }
185
+ return { startSec: hook.startSec, endSec: hook.endSec, durationSec: hook.endSec - hook.startSec };
186
+ }
187
+
155
188
  /**
156
189
  * Group aligned words into caption bursts: a new burst starts at a sentence end, after a silence
157
190
  * longer than {@link CAPTION_MAX_GAP_SEC}, or when the next word would overflow