@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
@@ -25,8 +25,8 @@ plugins/generations/video-gen/
25
25
  props.ts # composition props (the shell's contract, asserted in the fast tier)
26
26
  render.ts # asset staging + render call + artifact verification
27
27
  visual-provider.ts # VisualProvider seam: local-kb, wan21-i2v, musetalk, echomimic-v2
28
- colab-runner.ts # colab new/upload/exec/download/stop + budget guard + ledger line
29
- ccu-ledger.ts # rolling 30-day CCU estimate and monthly cap
28
+ colab-runner.ts # colab new/upload/exec/download/stop + reserve/settle accounting
29
+ ccu-ledger.ts # rolling 30-day CCU estimate, paired reserve/settle lines, monthly cap
30
30
  process.ts / fs.ts # ts-runtime seams (every spawn and every file op goes through them)
31
31
  remotion/ # Root registry + EditorialReel, AvatarReel, HybridPipReel, captions,
32
32
  # waveform, safe-zone frame, AI生成 label; engine.ts owns Remotion itself
@@ -85,6 +85,75 @@ Mode/provider agreement is checked before anything is spawned:
85
85
  | `hybrid-pip` + `echomimic-v2` | Refused — the PiP bubble is a MuseTalk overlay only. |
86
86
  | `avatar`/`hybrid-pip` where synthesis fails | Exits nonzero, writes no Content. Avatar modes have **no** fallback: a missing presenter is a broken video, and the workflow node's `onError: continue` keeps the episode alive. |
87
87
 
88
+ ## 1a. A standalone brief (`brief.yaml`)
89
+
90
+ A brief renders a short from its own media — no daily run required. `kk executor run video-gen --in`
91
+ still receives the request; 0457's workflow calls `resolveVideoBrief` (`src/brief.ts`) to turn the
92
+ brief into that request.
93
+
94
+ ```yaml
95
+ # brief.yaml — paths resolve against this file's directory
96
+ title: 一个短视频
97
+ audio: media/episode.wav
98
+ images: [media/cover.png, media/diagram.png] # optional for `avatar` only
99
+ format: editorial # editorial | avatar | hybrid-pip (default editorial)
100
+ style: daily-ai # neutral | daily-ai (default neutral)
101
+ description: 一句话说明 # optional; becomes the Content body
102
+ portrait: media/host.png # required by avatar and hybrid-pip
103
+ clip: { startSec: 2, endSec: 22 } # optional; must sit inside the probed audio
104
+ presentation: { captionStyle: off } # optional; kinetic | off, brandLabel, cta
105
+ ```
106
+
107
+ The schema is strict: an unknown key fails the run. Resolution order:
108
+
109
+ 1. **Presentation** — brief → style → format → built-ins (`captionStyle: kinetic`, the shell's own
110
+ podcast CTA). `resolveVideoBrief().sources.presentation` names the winning layer per field.
111
+ 2. **Format/style** — shipped portable presets only: `presets/formats/{editorial,avatar,hybrid-pip}.yaml`
112
+ and `presets/styles/{neutral,daily-ai}.yaml`. An unknown name is refused by name, and a name that
113
+ is not one lowercase path segment (separators, `..`, dots) is refused before any read.
114
+ 3. **Runtime** — explicit `runtime_file` > the operator config's `video:` key (`KK_CONFIG`, else
115
+ `~/.config/kk/config.yaml`) > safe defaults. Runtime fields: `provider`,
116
+ `allowEditorialFallback`, `colab: { gpu, timeoutMs, maxMonthlyCcu, cacheDir }`. Provider, GPU and
117
+ credentials never live in a brief or a preset.
118
+
119
+ Preflight refusals (all before a renderer or GPU exists): missing/empty audio, image or portrait;
120
+ `editorial`/`hybrid-pip` without a still; `avatar`/`hybrid-pip` without a portrait or without a named
121
+ presenter provider; any GPU provider without `colab.gpu`; a clip outside the probed source; an
122
+ unknown format/style/preset key. Standalone editorial GPU failures propagate unless the runtime sets
123
+ `allowEditorialFallback: true` — the daily path keeps its unconditional Wan→Ken-Burns fallback.
124
+
125
+ Artifacts land in the brief's `outputDir` (default `<brief dir>/output`) as `hook.wav`, `words.json`,
126
+ `video.mp4`, `public/` and the `--out` Content — never the daily `<date>_*` names.
127
+
128
+ ### The standalone workflow (`kk-video-generate`)
129
+
130
+ `plugins/kk/workflows/kk-video-generate.yaml` runs a brief end to end: `prepare` resolves it into
131
+ `<run_dir>/<__runId>/request.json` (`kk stage run video-prepare`), `render` submits that request as a
132
+ durable Spur external job (`kind: job.await`, `wait: daemon`, `resource: colab-gpu`) whose
133
+ `content_path` is bound back into the run and asserted to be this run's own `content.json`, and
134
+ `verify` (`kk stage run video-verify`)
135
+ proves the MP4 is this run's file — Content `videoPath` resolves to it, the media is newer than the
136
+ request, and one bounded `ffprobe` reports H.264 1080×1920 ~30 fps + AAC with a duration within 0.25 s
137
+ of the Content metadata — then writes `verification.json`. Any miss fails the run; the receipt only
138
+ exists after every check passes.
139
+
140
+ ```bash
141
+ # vars: brief_file, run_dir, works_root (absolute), optional runtime_file (provider / colab)
142
+ # The render is a daemon-wait external job: settle it with `spur self serve` or
143
+ # `spur workflow continue <run-id> --wait`.
144
+ spur workflow run plugins/kk/workflows/kk-video-generate.yaml \
145
+ --vars '{"brief_file":"/abs/brief.yaml","run_dir":"/abs/runs","works_root":"/abs/works"}'
146
+
147
+ # from a checkout, exercise the checkout's stages (the installed kk keeps its own copy):
148
+ bun apps/cli/src/index.ts stage run video-prepare /abs/brief.yaml /abs/runs <run-id>
149
+ bun apps/cli/src/index.ts executor run video-gen --in /abs/runs/<run-id>/request.json --out /abs/runs/<run-id>/content.json
150
+ bun apps/cli/src/index.ts stage run video-verify /abs/runs <run-id>
151
+ ```
152
+
153
+ `run_dir` holds one directory per workflow run, so a retry never reads a previous run's render. The
154
+ default is local editorial; a GPU provider needs `provider` plus `colab.gpu` in the runtime file or
155
+ the operator config, and the brief resolver refuses it otherwise before anything is allocated.
156
+
88
157
  ## 2. Inputs read from the daily run
89
158
 
90
159
  The plugin reads what earlier stages already wrote — no second source of truth, no re-encode:
@@ -156,11 +225,157 @@ visible. Workers expect prepared upstream checkouts at `KK_MUSETALK_REPO` / `KK_
156
225
  `KK_WAN21_MODEL` / `KK_WAN21_STEPS` tune the Wan2.1 worker.
157
226
 
158
227
  Every job appends `{timestamp, gpu, durationSec, estimatedCcu, jobType, status}` to
159
- `colab-ccu-ledger.jsonl` **at the works root** — `<workDir>/..`, or `KK_WORKS_DIR` when set, because a
160
- per-run ledger would reset the rolling window every day. Before launching, the runner sums the last
161
- 30 days against `maxMonthlyCcu` (default `180`) using conservative burn factors (T4 ≈ 2, L4 ≈ 3,
162
- A100 ≈ 7 CCU/hour). A refusal launches nothing and costs nothing, and for `wan21-i2v` it becomes the
163
- fallback warning; the estimate is intentionally approximate — Google exposes no per-job CCU query.
228
+ `colab-ccu-ledger.jsonl` **at the works root** — `KK_WORKS_DIR` when set, else `<workDir>/..` for a
229
+ direct caller, because a per-run ledger would reset the rolling window every day. Before launching,
230
+ the runner sums the last 30 days against `maxMonthlyCcu` (default `180`) using conservative burn
231
+ factors (T4 ≈ 2, L4 ≈ 3, A100 ≈ 7 CCU/hour). A refusal launches nothing and costs nothing, and for
232
+ `wan21-i2v` it becomes the fallback warning; the estimate is intentionally approximate — Google
233
+ exposes no per-job CCU query.
234
+
235
+ **One budget across every video workflow (D91 R8).** The kk invocation boundary
236
+ (`apps/cli/src/invoke.ts`) hands every plugin child an absolute `KK_WORKS_DIR` resolved at the kk
237
+ invocation root, so the daily run and a standalone brief share one ledger and one admission claim even
238
+ though plugin children run with `cwd` = their package dir. Admission is serialized by an owner-checked
239
+ claim in the works-root `kk.db` (`colab-video-budget`, taken with `kk lock acquire --db
240
+ <works>/kk.db --name colab-video-budget --run <attempt-session> --ttl <ms>` and released with
241
+ `kk lock release` in a `finally`). The claim is held across the ledger read, the projected-cost check,
242
+ the whole Colab lifecycle, teardown and the ledger append, so the next run sees what this one spent.
243
+ A held claim is a **pre-allocation refusal** naming the holder; a claim whose release fails is
244
+ reported, and the lease expires on its own after the crash budget. The lease TTL and the projected
245
+ spend are the same bounded window — job deadline + kill grace + teardown cap + settlement allowance,
246
+ plus the two bounded lock operations for the lease — so admission and accounting cannot disagree.
247
+
248
+ ## 5a. ComfyUI model cache (`python/comfyui_model_cache.py`)
249
+
250
+ The H3 provider's weights are pinned in `python/comfyui-h3-models.json` — the four MiniMax H3 FL2VA
251
+ files at `Comfy-Org/MiniMax-H3@4b53a35…`, each with its byte count and SHA-256. Two operations keep a
252
+ verified Drive cache without ever fetching from the upstream source:
253
+
254
+ ```bash
255
+ uv run --project . --offline --no-dev python python/comfyui_model_cache.py manifest --manifest python/comfyui-h3-models.json
256
+ uv run --project . --offline --no-dev python python/comfyui_model_cache.py populate \
257
+ --manifest python/comfyui-h3-models.json --dest /content/ComfyUI/models --state /content/ComfyUI/models/.cache-uploads.json
258
+ uv run --project . --offline --no-dev python python/comfyui_model_cache.py restore \
259
+ --manifest python/comfyui-h3-models.json --dest /content/ComfyUI/models --receipt /content/ComfyUI/models/restore.json
260
+ ```
261
+
262
+ - **manifest** — strict: unknown fields, unsafe relative paths (absolute, `..`, a foreign separator), a
263
+ repeated path and a non-64-hex digest are refused; the pinned digest is the only thing a receipt
264
+ reports.
265
+ - **populate** — refuses when the *cache* lacks room for the missing bytes (Drive quota), verifies each
266
+ local weight's size and SHA-256 against the pin before uploading, resumes an interrupted upload from
267
+ Drive's confirmed offset (session ids persisted owner-only on the VM), and re-verifies the object's
268
+ reported size/digest after upload. An expired session adopts an already-completed object instead of
269
+ re-uploading.
270
+ - **restore** — adopts a local weight that already matches, otherwise streams into a sibling `.part`
271
+ file, verifies size + SHA-256 and promotes atomically with `os.replace`. A corrupt or missing object
272
+ fails naming the model path and the `populate` recovery step; nothing partial survives.
273
+ - Credentials come from the runtime's approved secret file (`KK_DRIVE_TOKEN_FILE`, default
274
+ `~/.config/kk/drive-token.json`) with the `drive.file` scope; no token, upload-session URL or weight
275
+ byte ever reaches a receipt. `python/tests/test_comfyui_model_cache.py` runs the whole contract
276
+ against an in-memory Drive (`plugins/generations/video-gen/tests/comfyui-cache.test.ts` in the heavy
277
+ tier).
278
+
279
+ ## 5b. MiniMax H3 editorial provider (opt-in)
280
+
281
+ `provider: comfyui-minimax-h3` renders the editorial reel from first-frame → motion clips through a
282
+ **pinned ComfyUI API graph** on Colab, using the weights 0458 pins. It is opt-in and never selected
283
+ implicitly: the brief's runtime layer (or the operator `video:` config) must name it *and* a GPU class.
284
+ A100 is the default; `T4` is refused (the pruned int8 graph plus the resident text encoder do not fit
285
+ 16 GB). The daily path keeps its Wan→Ken-Burns fallback; a standalone brief propagates the failure
286
+ unless `allowEditorialFallback: true` is set.
287
+
288
+ | Piece | Where |
289
+ | --- | --- |
290
+ | Provider seam | `src/visual-provider.ts` — returns a `clips` layer exactly like Wan2.1 |
291
+ | Runner contract | `src/colab-runner.ts` — `remoteArtifactName()` names `clip-N.mp4` for H3 (previously every non-Wan job fetched `presenter.mp4`), and only unique, expected basenames are transferred |
292
+ | Pinned graph | `python/comfyui-h3-i2v-api.json` — `Comfy-Org/ComfyUI@5f0d863a` (ships `comfy_extras/nodes_minimax_h3.py`), required nodes (`/object_info` preflight), fixed motion prompt, 736×416 @24 fps, 73 frames (H3's 17k+5 grid), 20 `res_multistep` steps; the upstream `Image to Video (MiniMax H3)` blueprint without the turbo LoRA or audio decode, saved as H.264 MP4 |
293
+ | Worker | `python/colab_comfyui_h3.py` — restores the verified cache into `$KK_COMFYUI_ROOT/models` (override `KK_COMFYUI_MODELS`), starts ComfyUI on loopback, checks the nodes, submits `/prompt`, polls `/history/<id>` under one deadline, copies exactly one expected clip |
294
+
295
+ Narration is never regenerated: the worker receives no audio path, and the shell keeps the episode
296
+ audio and captions. Content metadata records `renderProvider`, `captionsPath` and a typed
297
+ `renderProvenance` — `{ cache, comfyuiCommit, comfyuiRuntimeCommit, modelCache: { verified, restored } }`
298
+ — so a publisher can tell an H3 run from a local one and a rehearsal can prove which ComfyUI ran and that
299
+ the weights came from the verified cache. `python/tests/test_colab_comfyui_h3.py` covers the graph pin,
300
+ the node preflight, the submitted prompt, artifact selection, provenance and the CLI refusals.
301
+
302
+ `colab exec --file` ships only the worker source, so the runner stages its four siblings
303
+ (`drive_client.py`, `comfyui_model_cache.py`, the graph and the model manifest) into
304
+ `/content/kk-support/` (`KK_COLAB_SUPPORT_DIR`) first. The worker reads its argv from `KK_COLAB_ARGS`
305
+ and copies the first frame into `$KK_COMFYUI_ROOT/input/`, the only place `LoadImage` resolves names.
306
+ The live rehearsal is deferred to a deployment step; see §5c.
307
+
308
+ ## 5c. Live cold/warm rehearsal (deferred from 0459 to 0463)
309
+
310
+ The fixtures prove the graph, the worker contract and the provenance. Only a live run proves that H3
311
+ renders on the intended China setup. **The rehearsal cannot run yet.** The runner allocates a fresh
312
+ VM for every attempt, so nothing can be prepared on it in advance, and two pieces never reach it:
313
+
314
+ | Gap | Why a fresh VM fails | Fix (task 0463) |
315
+ | --- | --- | --- |
316
+ | Drive credential | `drive_client.py` reads `~/.config/kk/drive-token.json` and `KK_DRIVE_CACHE_FOLDER_ID` **on the VM**, but the runner forwards only `KK_COLAB_CACHE_DIR` and uploads no secret | Runner uploads `KK_DRIVE_TOKEN_FILE` to the VM's `~/.config/kk/drive-token.json` (mode 600; it is the operator's own VM, destroyed at `stop`) and forwards `KK_DRIVE_CACHE_FOLDER_ID` |
317
+ | ComfyUI checkout | The worker refuses when `$KK_COMFYUI_ROOT/main.py` is missing | Worker clones `Comfy-Org/ComfyUI`, checks out the pin and runs `pip install -r requirements.txt` when the checkout is absent. That is source and Python packages only; weights still come only from the verified cache |
318
+
319
+ Once those land, the operator supplies five things:
320
+
321
+ 1. **Colab CLI login.** Run `colab usage`. The first run goes through the CLI's OAuth browser flow,
322
+ and the output shows the compute-unit balance. Use `colab pay` to top it up.
323
+ 2. **CCU authorization.** The H3 job runs on an A100 (≈ 7 CCU/h, §5) under a 1800 s deadline, so each
324
+ run costs at most ≈ 3.5 CCU and the cold + warm pair ≈ 7 CCU. The pair stays well inside the
325
+ default `maxMonthlyCcu: 180`, and the runner refuses before allocating if the 30-day total would
326
+ pass the cap.
327
+ 3. **Drive credential (`drive.file`).**
328
+ - Create a Desktop OAuth client in a Google Cloud project with the Drive API enabled.
329
+ - Create an empty Drive folder for the cache. Its ID, the last segment of the folder's URL,
330
+ becomes `KK_DRIVE_CACHE_FOLDER_ID`.
331
+ - Mint the token and save it:
332
+
333
+ ```bash
334
+ gcloud auth application-default login --client-id-file=client_secret.json \
335
+ --scopes=https://www.googleapis.com/auth/drive.file,https://www.googleapis.com/auth/cloud-platform
336
+ install -m 600 /dev/null ~/.config/kk/drive-token.json
337
+ printf '{"access_token":"%s"}' "$(gcloud auth application-default print-access-token)" > ~/.config/kk/drive-token.json
338
+ ```
339
+
340
+ - `drive.file` only sees objects created by the **same OAuth client**, so populate and restore must
341
+ use one client.
342
+ - The access token lasts about an hour and `drive_client.py` does not refresh it. Mint it right
343
+ before each run.
344
+ 4. **Pinned weights, local, for the cold populate.** `populate` never downloads from upstream, so
345
+ fetch the four manifest paths at the pinned revision, then upload them to the cache. Populate talks
346
+ to the Drive API directly, so it can run on the operator machine:
347
+
348
+ ```bash
349
+ hf download Comfy-Org/MiniMax-H3 \
350
+ diffusion_models/minimax_h3_fl2va_pruned_int8_convrot.safetensors \
351
+ text_encoders/qwen3vl_32b_minimax_h3_nvfp4_awq.safetensors \
352
+ vae/minimax_h3_video_vae_int8_convrot.safetensors vae/minimax_h3_audio_vae_fp32.safetensors \
353
+ --revision 4b53a35191437de05370da548e59aeabe2a5a09a --local-dir ~/kk-h3-models
354
+ KK_DRIVE_CACHE_FOLDER_ID=<folder-id> uv run --project . --offline --no-dev python python/comfyui_model_cache.py \
355
+ populate --manifest python/comfyui-h3-models.json --dest ~/kk-h3-models --receipt populate.json
356
+ ```
357
+
358
+ 5. **The China runtime, named.** Task 0459 asks for evidence on "the intended China setup". Record
359
+ which host runs `kk`, its network egress (direct or proxy) to Colab, Drive and GitHub, and the
360
+ date. Rehearse on that host, not on a convenience machine.
361
+
362
+ **Procedure.** Write a brief whose runtime file sets
363
+ `provider: comfyui-minimax-h3, colab: { gpu: A100 }`, then run the standalone workflow (§1a) twice:
364
+
365
+ - **Cold** — the first run right after `populate`.
366
+ - **Warm** — a second run on a new VM. No populate; the cache is already verified.
367
+
368
+ Each run allocates its own VM, so the warm run proves that a fresh runtime renders from the cache alone.
369
+
370
+ **Evidence to keep** (per run, in task 0463's `## Testing`):
371
+ - `verification.json` from `video-verify`.
372
+ - `content.json` → `metadata.renderProvenance`:
373
+ - `comfyuiRuntimeCommit` equals `comfyuiCommit`;
374
+ - `modelCache.verified: true`;
375
+ - `cache: "drive"`.
376
+ - The `colab-ccu-ledger.jsonl` lines.
377
+ - The populate receipt (cold only).
378
+ - An `ffprobe` of the MP4.
164
379
 
165
380
  ## 6. Output Content
166
381
 
@@ -185,7 +400,7 @@ fallback warning; the estimate is intentionally approximate — Google exposes n
185
400
  }
186
401
  ```
187
402
 
188
- `fallbackUsed` and `warnings[]` appear only when a Colab run failed and the local reel took over;
403
+ `renderProvenance` appears only for Colab providers that report it (H3). `fallbackUsed` and `warnings[]` appear only when a Colab run failed and the local reel took over;
189
404
  `syntheticPresenter: true` marks the avatar modes. `ccuEstimated` is reserved in the schema but this
190
405
  build reports spend through the ledger, not the Content.
191
406
 
@@ -237,3 +452,25 @@ Colab runner against a fake CLI — including teardown-per-attempt, timeout, bud
237
452
  append. `tests/render-e2e.test.ts`, `render-wan-e2e.test.ts` and `render-avatar-e2e.test.ts` are
238
453
  registered in `scripts/test-suites.ts` as heavy-tier: they render real Chromium output and verify the
239
454
  MP4 with `ffprobe`. No test spends Colab compute or network.
455
+
456
+ ## 5. Budget accounting and external jobs (0464, ADR-066)
457
+
458
+ `runColabJob` takes the shared `colab-video-budget` claim twice for SHORT critical sections, never for
459
+ the render:
460
+
461
+ 1. **reserve** — read the rolling 30-day window, refuse when `rolling + full projected window`
462
+ exceeds `maxMonthlyCcu`, append a typed `reserve` line keyed by the Colab session name, and record
463
+ that session row (with its reservation) in `<works>/kk.db` BEFORE `colab new`, so an uncertain
464
+ allocation is still stoppable.
465
+ 2. **settle** — after confirmed teardown, mark the session settled exactly once under the same claim
466
+ and append one `settle` line whose `estimatedCcu` is the DELTA against the reservation.
467
+
468
+ `readRolling30d` pairs the two lines by `ref` and accounts the pair at the reservation's timestamp:
469
+ legacy untyped lines are summed exactly as before, an orphan `settle` is ignored, an aged-out
470
+ reservation contributes nothing, and each pair is clamped at zero. A reservation whose remote stop
471
+ could not be confirmed is never refunded.
472
+
473
+ The plugin therefore depends on `@gobing-ai/kk-store` (public package imports only) and is driven by
474
+ `kk job submit` when it runs as a Spur external job: the managed child receives
475
+ `KK_EXTERNAL_JOB_ID` and an absolute `KK_WORKS_DIR`, while a direct `kk executor run video-gen`
476
+ caller keeps its normal works-root resolution and a null `job_id`.