@gobing-ai/knowledge-kit 0.1.19 → 0.1.20

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 (54) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/dist/board/daily-voice/index.js +40 -7
  3. package/dist/index.js +1379 -378
  4. package/package.json +1 -1
  5. package/plugins/generations/image-gen/README.md +31 -31
  6. package/plugins/generations/image-gen/assets/sample/provenance.json +314 -0
  7. package/plugins/generations/image-gen/config.example.yaml +3 -0
  8. package/plugins/generations/image-gen/dist/index.js +154 -14
  9. package/plugins/generations/image-gen/presets/SOURCE.md +65 -0
  10. package/plugins/generations/image-gen/scripts/eval-style-presets.ts +513 -0
  11. package/plugins/generations/image-gen/scripts/gen-samples.ts +57 -7
  12. package/plugins/generations/image-gen/src/presets.ts +6 -5
  13. package/plugins/generations/image-gen/src/providers/h3-local.ts +196 -0
  14. package/plugins/generations/image-gen/src/providers/types.ts +11 -1
  15. package/plugins/kk/config.example.yaml +3 -0
  16. package/plugins/kk/decisions/extract/ai-news.yaml +5 -2
  17. package/plugins/kk/plugin.json +1 -1
  18. package/plugins/kk/publish-presets/daily-ai-voice.json +48 -7
  19. package/plugins/kk/scripts/daily-stages.ts +238 -14
  20. package/plugins/kk/skills/image-authoring/SKILL.md +7 -3
  21. package/plugins/kk/skills/image-authoring/references/providers.md +27 -0
  22. package/plugins/kk/skills/image-authoring/references/style-extraction.md +1 -1
  23. package/plugins/kk/skills/publish/SKILL.md +11 -0
  24. package/plugins/kk/skills/web-automation/SKILL.md +31 -1
  25. package/plugins/kk/workflows/kk-collect.yaml +8 -4
  26. package/plugins/kk/workflows/kk-daily-ai-voice.yaml +2 -1
  27. package/plugins/kk/workflows/kk-daily-ai-voice2.yaml +4 -2
  28. package/plugins/publishings/linkedin-pub/dist/index.js +43 -6
  29. package/plugins/publishings/linkedin-pub/dist/profile-check.js +32 -5
  30. package/plugins/publishings/linkedin-pub/src/index.ts +52 -6
  31. package/plugins/publishings/shipinhao-pub/dist/index.js +385 -31
  32. package/plugins/publishings/shipinhao-pub/dist/profile-check.js +3 -1
  33. package/plugins/publishings/shipinhao-pub/plugin.json +1 -1
  34. package/plugins/publishings/shipinhao-pub/src/audio-flow.ts +393 -0
  35. package/plugins/publishings/shipinhao-pub/src/flow.ts +227 -12
  36. package/plugins/publishings/shipinhao-pub/src/selectors.ts +13 -0
  37. package/plugins/publishings/surfdash-pub/dist/index.js +50 -8
  38. package/plugins/publishings/surfdash-pub/src/index.ts +59 -8
  39. package/plugins/publishings/surfdash-pub/src/topic-claims.ts +34 -3
  40. package/plugins/publishings/threads-pub/dist/index.js +9196 -296
  41. package/plugins/publishings/threads-pub/dist/profile-check.js +21139 -0
  42. package/plugins/publishings/threads-pub/package.json +3 -1
  43. package/plugins/publishings/threads-pub/plugin.json +6 -1
  44. package/plugins/publishings/threads-pub/src/index.ts +8 -1
  45. package/plugins/publishings/threads-pub/src/post-rail.ts +357 -0
  46. package/plugins/publishings/threads-pub/src/profile-check.ts +17 -0
  47. package/plugins/publishings/wechatmp-pub/dist/index.js +7 -0
  48. package/plugins/publishings/wechatmp-pub/src/flow.ts +13 -0
  49. package/plugins/publishings/weibo-pub/dist/index.js +46 -2
  50. package/plugins/publishings/weibo-pub/src/index.ts +74 -2
  51. package/plugins/publishings/x-pub/dist/index.js +263 -43
  52. package/plugins/publishings/x-pub/dist/profile-check.js +3 -1
  53. package/plugins/publishings/x-pub/src/index.ts +15 -1
  54. package/plugins/publishings/x-pub/src/post-rail.ts +334 -0
@@ -0,0 +1,196 @@
1
+ import { spawn } from 'node:child_process';
2
+ import { randomBytes } from 'node:crypto';
3
+ import { mkdir, rm } from 'node:fs/promises';
4
+ import { tmpdir } from 'node:os';
5
+ import { resolve } from 'node:path';
6
+ import { readBytes } from '../bytes';
7
+ import type { ImageProvider, ImageRequest, ImageResult, ProviderFactory, ProviderOptions } from './types';
8
+
9
+ /**
10
+ * no-direct-fs-io / no-direct-process-spawn exemption is recorded as per-file
11
+ * exclusions in .spur/rules/strict/runtime-boundaries.yaml: this provider's transport
12
+ * IS spawning the local `h3gen.sh` wrapper and staging one temp output file for it
13
+ * (same vendor-CLI-boundary class as codex-cli).
14
+ */
15
+
16
+ /**
17
+ * h3-local adapter (task 0379, feature K2) — Robin's local Apple Silicon MLX image runtime,
18
+ * reached through its `h3gen.sh` wrapper. Never auto-selected: a 6-minute-per-image local
19
+ * render must be an explicit operator choice, and the wrapper's readiness (venv, 49 GB of
20
+ * weights, a mounted external volume) cannot be expressed as env presence.
21
+ *
22
+ * Why a subprocess and not an import: the runtime is a Python venv (`../gitops/apps/h3-image-mlx`),
23
+ * so shelling out to its documented wrapper is the whole integration. `h3gen.sh` forwards every
24
+ * unknown flag to `h3-image-mlx generate`, resolves a relative `--output` against the caller's
25
+ * cwd, and echoes the written path.
26
+ */
27
+
28
+ const DEFAULT_MODEL = 'h3';
29
+
30
+ /** H3 accepts multiples of 32 within 256–4096 (h3-image-mlx README). */
31
+ const H3_DIM_MIN = 256;
32
+ const H3_DIM_MAX = 4096;
33
+ const H3_DIM_STEP = 32;
34
+
35
+ /**
36
+ * Default timeout is the measured worst case, not a guess: a cold 1024² text-to-image render is
37
+ * ~6–7 min and a two-reference edit measured 27 min 46 s (h3gen.sh README table). Anything
38
+ * tighter would kill paid-for work; `H3_LOCAL_TIMEOUT_MS` overrides per machine.
39
+ */
40
+ const DEFAULT_TIMEOUT_MS = 30 * 60 * 1000;
41
+
42
+ /** The canvas an aspect-only request lands on: 1024 on the short side, snapped and clamped. */
43
+ function snapDim(value: number): number {
44
+ const snapped = Math.round(value / H3_DIM_STEP) * H3_DIM_STEP;
45
+ return Math.min(H3_DIM_MAX, Math.max(H3_DIM_MIN, snapped));
46
+ }
47
+
48
+ /** True when both dimensions are canvases H3 can actually render. */
49
+ export function h3ExactSize(width: number, height: number): boolean {
50
+ if (!Number.isFinite(width) || !Number.isFinite(height)) return false;
51
+ const legal = (value: number): boolean =>
52
+ Number.isInteger(value) && value % H3_DIM_STEP === 0 && value >= H3_DIM_MIN && value <= H3_DIM_MAX;
53
+ return legal(width) && legal(height);
54
+ }
55
+
56
+ /**
57
+ * Translate an aspect-only request ("3:4", "21:9") into a legal H3 canvas. Returns null when the
58
+ * ratio is missing or unparseable, so the caller can fall back to a square instead of guessing.
59
+ */
60
+ export function h3Canvas(aspectRatio: string | undefined): { width: number; height: number } | null {
61
+ const match = /^(\d+(?:\.\d+)?):(\d+(?:\.\d+)?)$/.exec(aspectRatio?.trim() ?? '');
62
+ if (match === null) return null;
63
+ const ratioWidth = Number(match[1]);
64
+ const ratioHeight = Number(match[2]);
65
+ if (!(ratioWidth > 0) || !(ratioHeight > 0)) return null;
66
+ const height = snapDim(1024);
67
+ return { width: snapDim((1024 * ratioWidth) / ratioHeight), height };
68
+ }
69
+
70
+ interface SpawnResult {
71
+ stdout: string;
72
+ stderr: string;
73
+ code: number;
74
+ timedOut: boolean;
75
+ }
76
+
77
+ function spawnWrapper(command: string, args: string[], timeoutMs: number): Promise<SpawnResult> {
78
+ return new Promise((resolveSpawn, rejectSpawn) => {
79
+ // Detached: a timeout must kill the wrapper AND the python runtime it spawned, or a
80
+ // timed-out render keeps burning the GPU after the caller has moved on.
81
+ const child = spawn(command, args, { stdio: ['ignore', 'pipe', 'pipe'], detached: true });
82
+ let stdout = '';
83
+ let stderr = '';
84
+ let timedOut = false;
85
+ const timer = setTimeout(() => {
86
+ timedOut = true;
87
+ try {
88
+ if (child.pid !== undefined) process.kill(-child.pid, 'SIGKILL');
89
+ } catch {
90
+ // The group is already gone (ESRCH) — nothing left to kill.
91
+ }
92
+ }, timeoutMs);
93
+ child.stdout.on('data', (chunk: Buffer) => {
94
+ stdout += chunk.toString('utf8');
95
+ });
96
+ child.stderr.on('data', (chunk: Buffer) => {
97
+ stderr += chunk.toString('utf8');
98
+ });
99
+ child.on('error', (err) => {
100
+ clearTimeout(timer);
101
+ rejectSpawn(err);
102
+ });
103
+ child.on('close', (code) => {
104
+ clearTimeout(timer);
105
+ resolveSpawn({ stdout, stderr, code: code ?? 1, timedOut });
106
+ });
107
+ });
108
+ }
109
+
110
+ /** Keep thrown messages short but diagnostic: the tail is what a fallback reader needs. */
111
+ function stderrTail(text: string): string {
112
+ const trimmed = text.trim();
113
+ if (trimmed === '') return '';
114
+ return `; ${trimmed.slice(-800)}`;
115
+ }
116
+
117
+ function positiveInt(value: string): number | null {
118
+ if (value === '') return null;
119
+ const parsed = Number.parseInt(value, 10);
120
+ return Number.isFinite(parsed) && parsed > 0 ? parsed : null;
121
+ }
122
+
123
+ export const createH3Local: ProviderFactory = (options?: ProviderOptions): ImageProvider => {
124
+ const env = options?.env ?? process.env;
125
+ const readEnv = (key: string): string => env[key] ?? '';
126
+ const timeoutMs = options?.timeoutMs ?? positiveInt(readEnv('H3_LOCAL_TIMEOUT_MS')) ?? DEFAULT_TIMEOUT_MS;
127
+
128
+ return {
129
+ name: 'h3-local',
130
+ defaultModel: () => DEFAULT_MODEL,
131
+ // Env presence only: probing the venv, the weights or the external volume here would turn
132
+ // a synchronous selection into a multi-second filesystem stall on every run.
133
+ isAvailable: () => readEnv('H3_IMAGE_MLX_BIN') !== '',
134
+ supportsReferenceImages: () => true,
135
+ exactSize: (_model: string, width: number, height: number): boolean => h3ExactSize(width, height),
136
+ validate(req: ImageRequest): void {
137
+ if ((req.n ?? 1) > 1) {
138
+ throw new Error('h3-local provider supports only n=1 (the wrapper renders one image per call).');
139
+ }
140
+ },
141
+ async generate(req: ImageRequest): Promise<ImageResult> {
142
+ const wrapper = readEnv('H3_IMAGE_MLX_BIN');
143
+ if (wrapper === '') {
144
+ throw new Error(
145
+ 'h3-local provider requires H3_IMAGE_MLX_BIN pointing at an executable h3gen.sh (or set the provider explicitly with IMAGE_GEN_PROVIDER).',
146
+ );
147
+ }
148
+
149
+ const canvas =
150
+ req.width !== undefined && req.height !== undefined && h3ExactSize(req.width, req.height)
151
+ ? { width: req.width, height: req.height }
152
+ : (h3Canvas(req.aspectRatio) ?? { width: 1024, height: 1024 });
153
+
154
+ const sessionDir = resolve(tmpdir(), 'kk-image-gen-h3-local');
155
+ await mkdir(sessionDir, { recursive: true });
156
+ const tmpOutput = resolve(sessionDir, `out-${randomBytes(8).toString('hex')}.png`);
157
+
158
+ const args: string[] = [
159
+ '--prompt',
160
+ req.prompt,
161
+ '--output',
162
+ tmpOutput,
163
+ '--width',
164
+ String(canvas.width),
165
+ '--height',
166
+ String(canvas.height),
167
+ ];
168
+ for (const ref of req.referenceImages ?? []) {
169
+ args.push('--reference', resolve(ref));
170
+ }
171
+
172
+ try {
173
+ const spawnResult = await spawnWrapper(wrapper, args, timeoutMs);
174
+ if (spawnResult.timedOut) {
175
+ throw new Error(
176
+ `h3-local wrapper timed out after ${timeoutMs}ms (${canvas.width}x${canvas.height})${stderrTail(spawnResult.stderr)}`,
177
+ );
178
+ }
179
+ if (spawnResult.code !== 0) {
180
+ throw new Error(
181
+ `h3-local wrapper exited with code ${spawnResult.code}${stderrTail(spawnResult.stderr)}`,
182
+ );
183
+ }
184
+ const bytes = await readBytes(tmpOutput).catch(() => null);
185
+ if (bytes === null) {
186
+ throw new Error(
187
+ `h3-local wrapper wrote no output at ${tmpOutput}${stderrTail(spawnResult.stderr)}`,
188
+ );
189
+ }
190
+ return { bytes, extension: 'png', provider: 'h3-local', model: req.model };
191
+ } finally {
192
+ await rm(tmpOutput, { force: true }).catch(() => undefined);
193
+ }
194
+ },
195
+ };
196
+ };
@@ -14,6 +14,7 @@ import { createAzure } from './azure';
14
14
  import { createCodexCli } from './codex-cli';
15
15
  import { createDashscope } from './dashscope';
16
16
  import { createGoogle } from './google';
17
+ import { createH3Local } from './h3-local';
17
18
  import { createHuggingface } from './huggingface';
18
19
  import { createJimeng } from './jimeng';
19
20
  import { createMinimax } from './minimax';
@@ -111,7 +112,7 @@ export type ProviderFactory = (options?: ProviderOptions) => ImageProvider;
111
112
  const IMAGE_GEN_PROVIDER_ENV = 'IMAGE_GEN_PROVIDER';
112
113
 
113
114
  /** Providers that may never be auto-selected, even if listed in AUTO_ORDER later (task 0103 R3). */
114
- const NEVER_AUTO: ReadonlySet<string> = new Set(['codex-cli']);
115
+ const NEVER_AUTO: ReadonlySet<string> = new Set(['codex-cli', 'h3-local']);
115
116
 
116
117
  /** Registry row: the availability facts an adapter must honour, verbatim from its baoyu source. */
117
118
  interface ProviderSpec {
@@ -170,6 +171,15 @@ export const PROVIDERS: Readonly<Record<string, ProviderRegistration>> = {
170
171
  ],
171
172
  create: createGoogle,
172
173
  },
174
+ 'h3-local': {
175
+ name: 'h3-local',
176
+ env: ['H3_IMAGE_MLX_BIN'],
177
+ defaultModel: 'h3',
178
+ // Local MLX runtime: readiness is the env var, but a render costs minutes of wall time,
179
+ // so it stays opt-in (never auto-selected) unless the operator pins it (0379, feature K2).
180
+ note: 'requires H3_IMAGE_MLX_BIN pointing at the local h3gen.sh wrapper (never auto-selected)',
181
+ create: createH3Local,
182
+ },
173
183
  huggingface: {
174
184
  name: 'huggingface',
175
185
  env: ['HUGGINGFACE_API_TOKEN'],
@@ -101,6 +101,9 @@ plugins:
101
101
  BAOYU_CODEX_IMAGEGEN_BIN: "" # optional — wrapper entrypoint override
102
102
  BAOYU_CODEX_IMAGEGEN_TIMEOUT_MS: "" # optional — per-call timeout (ms)
103
103
  BAOYU_CODEX_IMAGEGEN_RETRIES: "" # optional — retry count
104
+ # -- h3-local (local Apple Silicon MLX runtime; NEVER auto-selected — pin explicitly) --
105
+ H3_IMAGE_MLX_BIN: "" # absolute path to ../gitops/apps/h3-image-mlx/h3gen.sh — its presence IS readiness (0379)
106
+ H3_LOCAL_TIMEOUT_MS: "" # optional — per-render bound in ms; default 1800000 (30 min: a 2-reference edit measured 27m46s)
104
107
  # -- 0104 R6 runtime seams (behavior, not credentials; placeholder values only) --
105
108
  KK_IMAGE_MAX_IMAGES: "" # optional — per-run budget cap; default 4 (OPEN for the operator to set)
106
109
  KK_IMAGE_DRY_RUN: "" # optional — "1" composes every prompt, selects the provider, spends nothing
@@ -8,8 +8,11 @@
8
8
  #
9
9
  # Keys are decision ids from the sibling catalog (plugins/kk/decisions/kk-items.yaml);
10
10
  # an unknown key or decision id fails loud with `kk.store.profile.invalid`.
11
- # `limit` is omitted: the compiler's episode-cap default (20) applies unless
12
- # `kk store extract --limit` overrides it.
11
+ # `limit` 32 (2026-11-15, task 0377): the omitted default of 20 capped a week-wide pool at 20
12
+ # items, which after QC admitted ~11.4k chars = 10.3 min against the 15 min floor, so a thin week
13
+ # could never clear it however far the ladder widened. 32 items keeps the estimate inside the
14
+ # 15-25 min window (measured: 45,163 raw chars -> ~16.4 min) instead of refusing the day.
15
+ limit: 40
13
16
  topic: ai-news
14
17
  where:
15
18
  # 2026-10-21: the allowlist is the whole AI taxonomy, in lockstep with the workflow's
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "kk",
3
- "version": "0.1.19",
3
+ "version": "0.1.20",
4
4
  "description": "knowledge-kit Claude Code plugin: skills, commands, subagents, hooks, and rules"
5
5
  }
@@ -26,7 +26,7 @@
26
26
  "variant": "episode",
27
27
  "tier": 1,
28
28
  "window": "after-generate",
29
- "mode": "live"
29
+ "mode": "off"
30
30
  },
31
31
  {
32
32
  "plugin": "xhs-pub",
@@ -42,7 +42,10 @@
42
42
  "variant": "episode",
43
43
  "tier": 1,
44
44
  "window": "after-generate",
45
- "mode": "live"
45
+ "mode": "live",
46
+ "options": {
47
+ "collection": "每日AI乱炖"
48
+ }
46
49
  },
47
50
  {
48
51
  "plugin": "wechatmp-pub",
@@ -50,7 +53,7 @@
50
53
  "variant": "article",
51
54
  "tier": 2,
52
55
  "window": "after-generate",
53
- "mode": "live",
56
+ "mode": "draft",
54
57
  "options": {
55
58
  "collection": "每日AI资讯"
56
59
  }
@@ -93,7 +96,7 @@
93
96
  "variant": "social:x",
94
97
  "tier": 3,
95
98
  "window": "overseas-rss",
96
- "mode": "dummy"
99
+ "mode": "live"
97
100
  },
98
101
  {
99
102
  "plugin": "weibo-pub",
@@ -101,7 +104,7 @@
101
104
  "variant": "social:weibo",
102
105
  "tier": 3,
103
106
  "window": "overseas-rss",
104
- "mode": "dummy"
107
+ "mode": "live"
105
108
  },
106
109
  {
107
110
  "plugin": "threads-pub",
@@ -109,7 +112,7 @@
109
112
  "variant": "social:threads",
110
113
  "tier": 3,
111
114
  "window": "overseas-rss",
112
- "mode": "dummy"
115
+ "mode": "live"
113
116
  },
114
117
  {
115
118
  "plugin": "linkedin-pub",
@@ -117,7 +120,7 @@
117
120
  "variant": "social:linkedin",
118
121
  "tier": 3,
119
122
  "window": "overseas-rss",
120
- "mode": "dummy"
123
+ "mode": "live"
121
124
  },
122
125
  {
123
126
  "plugin": "shipinhao-pub",
@@ -134,6 +137,44 @@
134
137
  "tier": 3,
135
138
  "window": "overseas-rss",
136
139
  "mode": "off"
140
+ },
141
+ {
142
+ "plugin": "jike-pub",
143
+ "operation": "post",
144
+ "variant": "social:jike",
145
+ "tier": 3,
146
+ "window": "overseas-rss",
147
+ "mode": "live"
148
+ }
149
+ ],
150
+ "overrides": [
151
+ {
152
+ "plugin": "x-pub",
153
+ "operation": "post",
154
+ "mode": "live",
155
+ "reason": "operator instruction 2026-11-15: publish to all available platforms for the dogfood run; no draftable rail exists, so this is a recorded exception to ADR-022",
156
+ "until": "2026-11-16 dogfood run"
157
+ },
158
+ {
159
+ "plugin": "weibo-pub",
160
+ "operation": "post",
161
+ "mode": "live",
162
+ "reason": "operator instruction 2026-11-15: publish to all available platforms for the dogfood run; no draftable rail exists, so this is a recorded exception to ADR-022",
163
+ "until": "2026-11-16 dogfood run"
164
+ },
165
+ {
166
+ "plugin": "threads-pub",
167
+ "operation": "post",
168
+ "mode": "live",
169
+ "reason": "operator instruction 2026-11-15: publish to all available platforms for the dogfood run; no draftable rail exists, so this is a recorded exception to ADR-022",
170
+ "until": "2026-11-16 dogfood run"
171
+ },
172
+ {
173
+ "plugin": "linkedin-pub",
174
+ "operation": "post",
175
+ "mode": "live",
176
+ "reason": "operator instruction 2026-11-15: publish to all available platforms for the dogfood run; no draftable rail exists, so this is a recorded exception to ADR-022",
177
+ "until": "2026-11-16 dogfood run"
137
178
  }
138
179
  ]
139
180
  }