@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,5 +1,6 @@
1
1
  import { dirname, join, resolve } from 'node:path';
2
2
  import type { FileSystem } from '@gobing-ai/ts-runtime';
3
+ import type { RunProcess } from './process';
3
4
 
4
5
  /**
5
6
  * Rolling Colab compute-unit ledger (`0451 R3`).
@@ -24,6 +25,14 @@ export interface CcuLedgerEntry {
24
25
  estimatedCcu: number;
25
26
  jobType: string;
26
27
  status: 'ok' | 'failed' | 'timeout';
28
+ /**
29
+ * Typed accounting (task 0464 R5). Omitted on every legacy line, which is summed exactly as
30
+ * before. `reserve` is the full projected budget window written BEFORE allocation; `settle` is
31
+ * the once-only delta between what the render actually spent and that reservation.
32
+ */
33
+ kind?: 'reserve' | 'settle';
34
+ /** Session reservation this line belongs to; the pairing key of the rolling window. */
35
+ ref?: string;
27
36
  }
28
37
 
29
38
  /** Ledger file name under the works root. */
@@ -64,6 +73,8 @@ function asEntry(raw: unknown): CcuLedgerEntry | null {
64
73
  if (typeof estimated !== 'number' || !Number.isFinite(estimated)) return null;
65
74
  const timestamp = typeof record.timestamp === 'string' ? record.timestamp : '';
66
75
  if (Number.isNaN(Date.parse(timestamp))) return null;
76
+ const kind = record.kind === 'reserve' || record.kind === 'settle' ? record.kind : undefined;
77
+ const ref = typeof record.ref === 'string' && record.ref !== '' ? record.ref : undefined;
67
78
  return {
68
79
  timestamp,
69
80
  gpu: (typeof record.gpu === 'string' ? record.gpu : 'T4') as ColabGpu,
@@ -71,9 +82,47 @@ function asEntry(raw: unknown): CcuLedgerEntry | null {
71
82
  estimatedCcu: estimated,
72
83
  jobType: typeof record.jobType === 'string' ? record.jobType : 'unknown',
73
84
  status: record.status === 'ok' || record.status === 'timeout' ? record.status : 'failed',
85
+ ...(kind === undefined || ref === undefined ? {} : { kind, ref }),
74
86
  };
75
87
  }
76
88
 
89
+ /**
90
+ * What one reservation actually costs the window.
91
+ *
92
+ * A reservation is accounted at the moment it was TAKEN, and its settle line only corrects that
93
+ * same reservation — never the current window. That is what stops an expired reservation from
94
+ * turning into a negative credit months later: an orphan `settle` (no visible `reserve`) is
95
+ * ignored, and a pair whose reserve is outside the window contributes nothing at all.
96
+ */
97
+ export function reservationCost(entries: readonly CcuLedgerEntry[], cutoff: number): number {
98
+ const reserves = new Map<string, CcuLedgerEntry>();
99
+ const settles = new Map<string, CcuLedgerEntry>();
100
+ for (const entry of entries) {
101
+ if (entry.kind === undefined || entry.ref === undefined) continue;
102
+ if (entry.kind === 'reserve') {
103
+ const existing = reserves.get(entry.ref);
104
+ // The earliest reserve is the one that guarded admission; later replays are noise.
105
+ if (existing === undefined || Date.parse(entry.timestamp) < Date.parse(existing.timestamp)) {
106
+ reserves.set(entry.ref, entry);
107
+ }
108
+ continue;
109
+ }
110
+ // At most one settle per reservation: the first one wins.
111
+ if (!settles.has(entry.ref)) settles.set(entry.ref, entry);
112
+ }
113
+ let total = 0;
114
+ for (const [ref, reserve] of reserves) {
115
+ const reserveAt = Date.parse(reserve.timestamp);
116
+ // An aged-out reservation is out of the window entirely — no reserve, no settle credit.
117
+ if (reserveAt < cutoff) continue;
118
+ const settle = settles.get(ref);
119
+ const settleDelta = settle === undefined ? 0 : settle.estimatedCcu;
120
+ // Clamp per reservation so a corrupted settle can never create budget headroom.
121
+ total += Math.max(reserve.estimatedCcu + settleDelta, 0);
122
+ }
123
+ return Number(total.toFixed(4));
124
+ }
125
+
77
126
  /**
78
127
  * Sum the ledger's estimate over the rolling 30 days ending at `now`. A missing file reads as 0; a
79
128
  * malformed line is skipped rather than failing the run (the ledger is an estimate, not evidence).
@@ -86,8 +135,9 @@ export async function readRolling30d(
86
135
  if (!(await fs.exists(path))) return { totalCcu: 0, entries: 0 };
87
136
  const text = await fs.readFile(path);
88
137
  const cutoff = now - LEDGER_WINDOW_DAYS * 24 * 60 * 60 * 1000;
89
- let totalCcu = 0;
138
+ let legacyCcu = 0;
90
139
  let entries = 0;
140
+ const typed: CcuLedgerEntry[] = [];
91
141
  for (const line of text.split('\n')) {
92
142
  const trimmed = line.trim();
93
143
  if (trimmed === '') continue;
@@ -99,10 +149,19 @@ export async function readRolling30d(
99
149
  }
100
150
  const entry = asEntry(parsed);
101
151
  if (entry === null) continue;
102
- if (Date.parse(entry.timestamp) < cutoff) continue;
103
- totalCcu += entry.estimatedCcu;
152
+ if (entry.kind === undefined || entry.ref === undefined) {
153
+ // `entries` keeps its pre-0464 meaning: ledger LINES inside the window.
154
+ if (Date.parse(entry.timestamp) < cutoff) continue;
155
+ legacyCcu += entry.estimatedCcu;
156
+ entries += 1;
157
+ continue;
158
+ }
104
159
  entries += 1;
160
+ typed.push(entry);
105
161
  }
162
+ // Typed lines are paired (reserve + its one settle) instead of summed; legacy lines keep the
163
+ // pre-0464 behaviour so an existing ledger reads identically.
164
+ const totalCcu = legacyCcu + reservationCost(typed, cutoff);
106
165
  return { totalCcu: Number(totalCcu.toFixed(4)), entries };
107
166
  }
108
167
 
@@ -132,3 +191,147 @@ export function assertBudget(args: {
132
191
  }
133
192
  return { ok: true };
134
193
  }
194
+
195
+ // ── shared GPU admission (D91 R8, 0456) ──────────────────────────────────────
196
+
197
+ /**
198
+ * The works-root claim that serializes GPU admission across every video workflow.
199
+ *
200
+ * WHY a lock and not just the ledger: the ledger is read-then-appended, so two concurrent runs can
201
+ * both see headroom and both spend it. The claim is taken in the works root's `kk.db` (the same
202
+ * owner-checked lock table the scheduler uses), held across read → projection → lifecycle →
203
+ * teardown → append, and released in a `finally`.
204
+ */
205
+ export const BUDGET_LOCK_NAME = 'colab-video-budget';
206
+
207
+ /** The store the claim lives in, under the works root. */
208
+ export const LOCK_DB_NAME = 'kk.db';
209
+
210
+ /** The teardown cap the runner applies to `colab stop` (see `runColabJob`). */
211
+ export const TEARDOWN_CAP_MS = 60_000;
212
+ /** Deposit/settlement allowance after teardown (ledger append + rounding). */
213
+ export const SETTLEMENT_ALLOWANCE_MS = 15_000;
214
+ /** Per-call allowance for the bounded `kk lock` operations themselves. */
215
+ export const LOCK_OP_ALLOWANCE_MS = 15_000;
216
+
217
+ /**
218
+ * The worst-case wall clock one attempt can hold the claim: the job deadline, the kill grace, the
219
+ * teardown cap and the settlement allowance. Projected spend uses this same window, so admission and
220
+ * accounting agree on what an attempt may cost.
221
+ */
222
+ export function budgetWindowMs(jobWindowMs: number, killGraceMs: number): number {
223
+ return jobWindowMs + killGraceMs + TEARDOWN_CAP_MS + SETTLEMENT_ALLOWANCE_MS;
224
+ }
225
+
226
+ /** The claim's lease TTL: the budget window plus the two bounded lock operations. */
227
+ export function budgetLeaseTtlMs(jobWindowMs: number, killGraceMs: number): number {
228
+ return budgetWindowMs(jobWindowMs, killGraceMs) + 2 * LOCK_OP_ALLOWANCE_MS;
229
+ }
230
+
231
+ /** One claim attempt's outcome. `holder` names the run that holds it (for the refusal message). */
232
+ export interface BudgetClaim {
233
+ acquired: boolean;
234
+ holder?: string | null;
235
+ }
236
+
237
+ /** Claim/release seam, so a test can contend on its own store without spawning `kk`. */
238
+ export interface BudgetLock {
239
+ acquire(args: { name: string; owner: string; ttlMs: number }): Promise<BudgetClaim>;
240
+ release(args: { name: string; owner: string }): Promise<boolean>;
241
+ }
242
+
243
+ /** `kk lock acquire` argv — argv-based, never a shell string (owner-checked release symmetric). */
244
+ export function buildLockAcquireArgv(args: {
245
+ kkBin: string;
246
+ dbPath: string;
247
+ name: string;
248
+ owner: string;
249
+ ttlMs: number;
250
+ }): string[] {
251
+ return [
252
+ args.kkBin,
253
+ 'lock',
254
+ 'acquire',
255
+ '--db',
256
+ args.dbPath,
257
+ '--name',
258
+ args.name,
259
+ '--run',
260
+ args.owner,
261
+ '--ttl',
262
+ String(args.ttlMs),
263
+ ];
264
+ }
265
+
266
+ /** `kk lock release` argv. */
267
+ export function buildLockReleaseArgv(args: { kkBin: string; dbPath: string; name: string; owner: string }): string[] {
268
+ return [args.kkBin, 'lock', 'release', '--db', args.dbPath, '--name', args.name, '--run', args.owner];
269
+ }
270
+
271
+ /**
272
+ * Parse `kk lock acquire` stdout. Both outcomes exit 0 by design, so the runner must read the
273
+ * payload: `{"acquired":true}` or `{"skipped":"locked","holder":"<run>"}`.
274
+ */
275
+ export function parseLockAcquire(stdout: string): BudgetClaim | null {
276
+ for (const line of stdout.split('\n')) {
277
+ const trimmed = line.trim();
278
+ if (!trimmed.startsWith('{')) continue;
279
+ try {
280
+ const parsed = JSON.parse(trimmed) as Record<string, unknown>;
281
+ if (parsed.acquired === true) return { acquired: true };
282
+ if (parsed.skipped === 'locked') {
283
+ return { acquired: false, holder: typeof parsed.holder === 'string' ? parsed.holder : null };
284
+ }
285
+ } catch {}
286
+ }
287
+ return null;
288
+ }
289
+
290
+ /**
291
+ * The production claim: `kk lock acquire|release` against `<worksRoot>/kk.db`. A spawn failure or an
292
+ * unparseable response is a refusal — admitting a job on a broken guard would spend budget nobody
293
+ * can account for.
294
+ */
295
+ export function createKkBudgetLock(args: {
296
+ runProcess: RunProcess;
297
+ dbPath: string;
298
+ kkBin?: string;
299
+ timeoutMs?: number;
300
+ }): BudgetLock {
301
+ const kkBin = args.kkBin ?? process.env.KK_BIN ?? 'kk';
302
+ const timeoutMs = args.timeoutMs ?? LOCK_OP_ALLOWANCE_MS;
303
+ return {
304
+ acquire: async ({ name, owner, ttlMs }) => {
305
+ const result = await args.runProcess(
306
+ buildLockAcquireArgv({ kkBin, dbPath: args.dbPath, name, owner, ttlMs }),
307
+ {
308
+ timeoutMs,
309
+ },
310
+ );
311
+ if (result.code !== 0) {
312
+ throw new Error(
313
+ `colab budget claim failed (${kkBin} lock acquire, exit ${result.code}): ${result.stderr.trim() || 'no stderr'}`,
314
+ );
315
+ }
316
+ const parsed = parseLockAcquire(result.stdout);
317
+ if (parsed === null) {
318
+ throw new Error(
319
+ `colab budget claim failed: ${kkBin} lock acquire printed no claim result (${result.stdout.trim() || 'empty'})`,
320
+ );
321
+ }
322
+ return parsed;
323
+ },
324
+ release: async ({ name, owner }) => {
325
+ const result = await args.runProcess(buildLockReleaseArgv({ kkBin, dbPath: args.dbPath, name, owner }), {
326
+ timeoutMs,
327
+ });
328
+ if (result.code !== 0) {
329
+ throw new Error(
330
+ `colab budget claim release failed (exit ${result.code}): ${result.stderr.trim() || 'no stderr'}`,
331
+ );
332
+ }
333
+ // `released:false` means the lease was stolen past its TTL — nothing to free.
334
+ return /"released"\s*:\s*true/.test(result.stdout);
335
+ },
336
+ };
337
+ }