@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.
- package/.claude-plugin/marketplace.json +1 -1
- package/dist/board/daily-voice/index.js +40 -7
- package/dist/index.js +1379 -378
- package/package.json +1 -1
- package/plugins/generations/image-gen/README.md +31 -31
- package/plugins/generations/image-gen/assets/sample/provenance.json +314 -0
- package/plugins/generations/image-gen/config.example.yaml +3 -0
- package/plugins/generations/image-gen/dist/index.js +154 -14
- package/plugins/generations/image-gen/presets/SOURCE.md +65 -0
- package/plugins/generations/image-gen/scripts/eval-style-presets.ts +513 -0
- package/plugins/generations/image-gen/scripts/gen-samples.ts +57 -7
- package/plugins/generations/image-gen/src/presets.ts +6 -5
- package/plugins/generations/image-gen/src/providers/h3-local.ts +196 -0
- package/plugins/generations/image-gen/src/providers/types.ts +11 -1
- package/plugins/kk/config.example.yaml +3 -0
- package/plugins/kk/decisions/extract/ai-news.yaml +5 -2
- package/plugins/kk/plugin.json +1 -1
- package/plugins/kk/publish-presets/daily-ai-voice.json +48 -7
- package/plugins/kk/scripts/daily-stages.ts +238 -14
- package/plugins/kk/skills/image-authoring/SKILL.md +7 -3
- package/plugins/kk/skills/image-authoring/references/providers.md +27 -0
- package/plugins/kk/skills/image-authoring/references/style-extraction.md +1 -1
- package/plugins/kk/skills/publish/SKILL.md +11 -0
- package/plugins/kk/skills/web-automation/SKILL.md +31 -1
- package/plugins/kk/workflows/kk-collect.yaml +8 -4
- package/plugins/kk/workflows/kk-daily-ai-voice.yaml +2 -1
- package/plugins/kk/workflows/kk-daily-ai-voice2.yaml +4 -2
- package/plugins/publishings/linkedin-pub/dist/index.js +43 -6
- package/plugins/publishings/linkedin-pub/dist/profile-check.js +32 -5
- package/plugins/publishings/linkedin-pub/src/index.ts +52 -6
- package/plugins/publishings/shipinhao-pub/dist/index.js +385 -31
- package/plugins/publishings/shipinhao-pub/dist/profile-check.js +3 -1
- package/plugins/publishings/shipinhao-pub/plugin.json +1 -1
- package/plugins/publishings/shipinhao-pub/src/audio-flow.ts +393 -0
- package/plugins/publishings/shipinhao-pub/src/flow.ts +227 -12
- package/plugins/publishings/shipinhao-pub/src/selectors.ts +13 -0
- package/plugins/publishings/surfdash-pub/dist/index.js +50 -8
- package/plugins/publishings/surfdash-pub/src/index.ts +59 -8
- package/plugins/publishings/surfdash-pub/src/topic-claims.ts +34 -3
- package/plugins/publishings/threads-pub/dist/index.js +9196 -296
- package/plugins/publishings/threads-pub/dist/profile-check.js +21139 -0
- package/plugins/publishings/threads-pub/package.json +3 -1
- package/plugins/publishings/threads-pub/plugin.json +6 -1
- package/plugins/publishings/threads-pub/src/index.ts +8 -1
- package/plugins/publishings/threads-pub/src/post-rail.ts +357 -0
- package/plugins/publishings/threads-pub/src/profile-check.ts +17 -0
- package/plugins/publishings/wechatmp-pub/dist/index.js +7 -0
- package/plugins/publishings/wechatmp-pub/src/flow.ts +13 -0
- package/plugins/publishings/weibo-pub/dist/index.js +46 -2
- package/plugins/publishings/weibo-pub/src/index.ts +74 -2
- package/plugins/publishings/x-pub/dist/index.js +263 -43
- package/plugins/publishings/x-pub/dist/profile-check.js +3 -1
- package/plugins/publishings/x-pub/src/index.ts +15 -1
- package/plugins/publishings/x-pub/src/post-rail.ts +334 -0
|
@@ -0,0 +1,513 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* K3/task-0380: render and score blind format × subject comparisons for six
|
|
3
|
+
* candidate styles. Default mode renders only missing pairs; --dry-run validates
|
|
4
|
+
* the 48-call plan without spawning kk; --report unblinds a completed scores file.
|
|
5
|
+
*
|
|
6
|
+
* Run from the repo root:
|
|
7
|
+
* bun plugins/generations/image-gen/scripts/eval-style-presets.ts --dry-run
|
|
8
|
+
* bun plugins/generations/image-gen/scripts/eval-style-presets.ts
|
|
9
|
+
* bun plugins/generations/image-gen/scripts/eval-style-presets.ts --provider google \
|
|
10
|
+
* --candidates .works/tmp/k3-style-eval/presets-v2 --concurrency 1
|
|
11
|
+
* bun plugins/generations/image-gen/scripts/eval-style-presets.ts --provider google \
|
|
12
|
+
* --candidates .works/tmp/k3-style-eval/presets-v2 --report
|
|
13
|
+
* bun plugins/generations/image-gen/scripts/eval-style-presets.ts --provider h3-local \
|
|
14
|
+
* --candidates .works/tmp/k3-style-eval/presets-v2 --only handcrafted-clay-character --concurrency 1
|
|
15
|
+
* Provider/model defaults come from the registry. Work dirs are provider-namespaced by default.
|
|
16
|
+
*/
|
|
17
|
+
import { createHash } from 'node:crypto';
|
|
18
|
+
import { existsSync, mkdirSync, readFileSync } from 'node:fs';
|
|
19
|
+
import { homedir } from 'node:os';
|
|
20
|
+
import { dirname, join, resolve } from 'node:path';
|
|
21
|
+
import { StylePresetSchema } from '../src/presets';
|
|
22
|
+
import { PROVIDERS } from '../src/providers/types';
|
|
23
|
+
|
|
24
|
+
const DIMENSIONS = [
|
|
25
|
+
'subjectFidelity',
|
|
26
|
+
'composition',
|
|
27
|
+
'visualCoherence',
|
|
28
|
+
'constraintAdherence',
|
|
29
|
+
'artifactControl',
|
|
30
|
+
] as const;
|
|
31
|
+
type Dimension = (typeof DIMENSIONS)[number];
|
|
32
|
+
type Arm = 'candidate' | 'baseline';
|
|
33
|
+
type Side = 'A' | 'B';
|
|
34
|
+
type Format = 'free' | 'cover';
|
|
35
|
+
type ScoreArm = Record<Dimension, number | null>;
|
|
36
|
+
type CompleteScoreArm = Record<Dimension, number>;
|
|
37
|
+
|
|
38
|
+
interface Candidate {
|
|
39
|
+
name: string;
|
|
40
|
+
baseline: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
interface Subject {
|
|
44
|
+
id: string;
|
|
45
|
+
free: string;
|
|
46
|
+
cover: { title: string; subtitle: string; topics: string };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
interface Job {
|
|
50
|
+
pair: string;
|
|
51
|
+
candidate: string;
|
|
52
|
+
baseline: string;
|
|
53
|
+
format: Format;
|
|
54
|
+
subject: Subject;
|
|
55
|
+
arm: Arm;
|
|
56
|
+
side: Side;
|
|
57
|
+
style: string;
|
|
58
|
+
runDir: string;
|
|
59
|
+
input: string;
|
|
60
|
+
output: string;
|
|
61
|
+
blindImage: string;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
interface PairScore {
|
|
65
|
+
pair: string;
|
|
66
|
+
preferred: Side | 'tie' | null;
|
|
67
|
+
scores: Record<Side, ScoreArm>;
|
|
68
|
+
critical: Record<Side, string[]>;
|
|
69
|
+
notes: string;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
interface ScoreFile {
|
|
73
|
+
reviewer: string;
|
|
74
|
+
reviewedAt: string;
|
|
75
|
+
pairs: PairScore[];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const CANDIDATES: Candidate[] = [
|
|
79
|
+
{ name: 'limited-ink-risograph-editorial', baseline: 'editorial' },
|
|
80
|
+
{ name: 'layered-papercraft-diorama', baseline: 'sketch' },
|
|
81
|
+
{ name: 'minimalist-ink-wash-negative-space', baseline: 'minimalist' },
|
|
82
|
+
{ name: 'notion-editorial-line-art', baseline: 'technical-diagram' },
|
|
83
|
+
{ name: 'product-exploded-identity', baseline: 'technical-diagram' },
|
|
84
|
+
{ name: 'handcrafted-clay-character', baseline: 'cute' },
|
|
85
|
+
];
|
|
86
|
+
const SUBJECTS: Subject[] = [
|
|
87
|
+
{
|
|
88
|
+
id: 'microservices',
|
|
89
|
+
free: 'a request flowing through an API gateway to three microservices',
|
|
90
|
+
cover: {
|
|
91
|
+
title: 'Building Reliable AI Agents',
|
|
92
|
+
subtitle: 'Patterns for production',
|
|
93
|
+
topics: 'AI agents, API gateways, microservices',
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
id: 'semiconductor',
|
|
98
|
+
free: 'a robotic arm inspecting a glowing semiconductor wafer in a dark cleanroom',
|
|
99
|
+
cover: {
|
|
100
|
+
title: 'Inside Modern Semiconductors',
|
|
101
|
+
subtitle: 'From wafer to package',
|
|
102
|
+
topics: 'semiconductor manufacturing, robotic inspection, advanced packaging',
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
];
|
|
106
|
+
const FORMATS: Format[] = ['free', 'cover'];
|
|
107
|
+
|
|
108
|
+
const args = process.argv.slice(2);
|
|
109
|
+
const flag = (name: string): boolean => args.includes(name);
|
|
110
|
+
const option = (name: string, fallback: string): string => {
|
|
111
|
+
const index = args.indexOf(name);
|
|
112
|
+
return index >= 0 && args[index + 1] !== undefined ? args[index + 1] : fallback;
|
|
113
|
+
};
|
|
114
|
+
const REPO_ROOT = join(import.meta.dir, '..', '..', '..', '..');
|
|
115
|
+
const PLUGIN_DIR = join(import.meta.dir, '..');
|
|
116
|
+
const PROVIDER = option('--provider', 'minimax');
|
|
117
|
+
const registration = PROVIDERS[PROVIDER];
|
|
118
|
+
if (registration === undefined) {
|
|
119
|
+
throw new Error(`Unknown provider '${PROVIDER}'. Valid providers: ${Object.keys(PROVIDERS).sort().join(', ')}`);
|
|
120
|
+
}
|
|
121
|
+
const MODEL = option('--model', registration.defaultModel);
|
|
122
|
+
const CONCURRENCY = Number(option('--concurrency', '3'));
|
|
123
|
+
if (!Number.isInteger(CONCURRENCY) || CONCURRENCY < 1 || CONCURRENCY > 10) {
|
|
124
|
+
throw new Error('--concurrency must be an integer from 1 to 10');
|
|
125
|
+
}
|
|
126
|
+
const WORK = resolve(option('--work', join(REPO_ROOT, '.works', 'tmp', `k3-style-eval-${PROVIDER}`)));
|
|
127
|
+
const CANDIDATE_ROOT = resolve(option('--candidates', join(REPO_ROOT, '.works', 'tmp', 'k3-style-eval', 'presets')));
|
|
128
|
+
const BLIND = join(WORK, 'blind');
|
|
129
|
+
const SCORES = resolve(option('--scores', join(BLIND, 'scores.json')));
|
|
130
|
+
const ONLY = option('--only', '');
|
|
131
|
+
if (ONLY !== '' && !CANDIDATES.some((candidate) => candidate.name === ONLY)) {
|
|
132
|
+
throw new Error(
|
|
133
|
+
`Unknown candidate '${ONLY}'. Valid candidates: ${CANDIDATES.map((candidate) => candidate.name).join(', ')}`,
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function readYaml(path: string): unknown {
|
|
138
|
+
return Bun.YAML.parse(readFileSync(path, 'utf8'));
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function blankArm(): ScoreArm {
|
|
142
|
+
return Object.fromEntries(DIMENSIONS.map((dimension) => [dimension, null])) as ScoreArm;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function buildJobs(): Job[] {
|
|
146
|
+
for (const candidate of CANDIDATES) {
|
|
147
|
+
const path = join(CANDIDATE_ROOT, 'styles', `${candidate.name}.yaml`);
|
|
148
|
+
const style = StylePresetSchema.parse(readYaml(path));
|
|
149
|
+
const operative = `${style.modifiers}\n${style.negative ?? ''}`;
|
|
150
|
+
if (
|
|
151
|
+
/[{[](?:SUBJECT|PRODUCT|ASPECT RATIO|USE|PLACE|CITY|WORD|CHARACTERS|ACCENT|PALETTE|SAFE AREA)/.test(
|
|
152
|
+
operative,
|
|
153
|
+
)
|
|
154
|
+
) {
|
|
155
|
+
throw new Error(`${candidate.name}: unexpanded upstream slot`);
|
|
156
|
+
}
|
|
157
|
+
if (/(?:21:9|16:9|4:5|4:3|3:4|1:1)/.test(operative)) {
|
|
158
|
+
throw new Error(`${candidate.name}: aspect-ratio override`);
|
|
159
|
+
}
|
|
160
|
+
if (!style.negative) throw new Error(`${candidate.name}: negative constraints required`);
|
|
161
|
+
StylePresetSchema.parse(readYaml(join(PLUGIN_DIR, 'presets', 'styles', `${candidate.baseline}.yaml`)));
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const jobs: Job[] = [];
|
|
165
|
+
let sequence = 0;
|
|
166
|
+
for (const candidate of CANDIDATES) {
|
|
167
|
+
for (const subject of SUBJECTS) {
|
|
168
|
+
for (const format of FORMATS) {
|
|
169
|
+
sequence++;
|
|
170
|
+
const pair = `P${String(sequence).padStart(2, '0')}`;
|
|
171
|
+
const digest = createHash('sha256').update(`${candidate.name}:${subject.id}:${format}`).digest();
|
|
172
|
+
const candidateSide: Side = digest[0] % 2 === 0 ? 'A' : 'B';
|
|
173
|
+
for (const arm of ['candidate', 'baseline'] as const) {
|
|
174
|
+
const side: Side = arm === 'candidate' ? candidateSide : candidateSide === 'A' ? 'B' : 'A';
|
|
175
|
+
const runDir = join(WORK, 'runs', pair, arm);
|
|
176
|
+
jobs.push({
|
|
177
|
+
pair,
|
|
178
|
+
candidate: candidate.name,
|
|
179
|
+
baseline: candidate.baseline,
|
|
180
|
+
format,
|
|
181
|
+
subject,
|
|
182
|
+
arm,
|
|
183
|
+
side,
|
|
184
|
+
style: arm === 'candidate' ? candidate.name : candidate.baseline,
|
|
185
|
+
runDir,
|
|
186
|
+
input: join(runDir, 'in.json'),
|
|
187
|
+
output: join(runDir, 'content.json'),
|
|
188
|
+
blindImage: join(BLIND, pair, `${side}.jpg`),
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
if (jobs.length !== 48 || new Set(jobs.map((job) => job.pair)).size !== 24) {
|
|
195
|
+
throw new Error(
|
|
196
|
+
`evaluation plan drifted: ${jobs.length} jobs / ${new Set(jobs.map((job) => job.pair)).size} pairs`,
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
for (const candidate of CANDIDATES) {
|
|
200
|
+
const cells = jobs.filter((job) => job.candidate === candidate.name && job.arm === 'candidate');
|
|
201
|
+
if (cells.length !== 4 || new Set(cells.map((job) => job.side)).size !== 2) {
|
|
202
|
+
throw new Error(`${candidate.name}: expected four cells and both blind sides`);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return jobs;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
async function writeJson(path: string, value: unknown): Promise<void> {
|
|
209
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
210
|
+
await Bun.write(path, `${JSON.stringify(value, null, 2)}\n`);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function envelope(job: Job): unknown[] {
|
|
214
|
+
const imageGen: Record<string, unknown> = {
|
|
215
|
+
job: job.format,
|
|
216
|
+
format: job.format,
|
|
217
|
+
style: job.style,
|
|
218
|
+
provider: PROVIDER,
|
|
219
|
+
model: MODEL,
|
|
220
|
+
maxImages: 1,
|
|
221
|
+
};
|
|
222
|
+
if (job.format === 'free') imageGen.vars = { subject: job.subject.free };
|
|
223
|
+
else imageGen.vars = job.subject.cover;
|
|
224
|
+
return [
|
|
225
|
+
{
|
|
226
|
+
id: `${job.pair}-${job.arm}`,
|
|
227
|
+
title: job.subject.cover.title,
|
|
228
|
+
body: job.format === 'free' ? job.subject.free : '',
|
|
229
|
+
metadata: { imageGen },
|
|
230
|
+
},
|
|
231
|
+
];
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
async function render(job: Job): Promise<void> {
|
|
235
|
+
if (!flag('--force') && existsSync(job.output) && existsSync(job.blindImage)) {
|
|
236
|
+
console.log(`skip ${job.pair}/${job.arm}`);
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
mkdirSync(job.runDir, { recursive: true });
|
|
240
|
+
mkdirSync(dirname(job.blindImage), { recursive: true });
|
|
241
|
+
await writeJson(job.input, envelope(job));
|
|
242
|
+
const operatorConfig = process.env.KK_CONFIG ?? join(homedir(), '.config', 'kk', 'config.yaml');
|
|
243
|
+
const home = join(WORK, 'home');
|
|
244
|
+
const project = join(WORK, 'project');
|
|
245
|
+
mkdirSync(home, { recursive: true });
|
|
246
|
+
mkdirSync(project, { recursive: true });
|
|
247
|
+
const run = Bun.spawn(['kk', 'executor', 'run', 'image-gen', '--in', job.input, '--out', job.output], {
|
|
248
|
+
cwd: REPO_ROOT,
|
|
249
|
+
env: {
|
|
250
|
+
...process.env,
|
|
251
|
+
HOME: home,
|
|
252
|
+
KK_CONFIG: operatorConfig,
|
|
253
|
+
KNOWLEDGE_KIT_PROJECT_ROOT: project,
|
|
254
|
+
KK_IMAGE_PRESET_PATH: CANDIDATE_ROOT,
|
|
255
|
+
},
|
|
256
|
+
stdout: 'pipe',
|
|
257
|
+
stderr: 'pipe',
|
|
258
|
+
});
|
|
259
|
+
const [code, stderr] = await Promise.all([run.exited, new Response(run.stderr).text()]);
|
|
260
|
+
if (code !== 0) throw new Error(`kk exited ${code}: ${stderr.trim().split('\n').slice(-3).join(' | ')}`);
|
|
261
|
+
const output = (await Bun.file(job.output).json()) as {
|
|
262
|
+
metadata?: { images?: Array<{ path?: string }> };
|
|
263
|
+
};
|
|
264
|
+
const source = output.metadata?.images?.[0]?.path;
|
|
265
|
+
if (!source) throw new Error(`${job.output}: metadata.images[0].path missing`);
|
|
266
|
+
const thumb = Bun.spawnSync([
|
|
267
|
+
'sips',
|
|
268
|
+
'-Z',
|
|
269
|
+
'900',
|
|
270
|
+
'-s',
|
|
271
|
+
'format',
|
|
272
|
+
'jpeg',
|
|
273
|
+
'-s',
|
|
274
|
+
'formatOptions',
|
|
275
|
+
'85',
|
|
276
|
+
source,
|
|
277
|
+
'--out',
|
|
278
|
+
job.blindImage,
|
|
279
|
+
]);
|
|
280
|
+
if (thumb.exitCode !== 0)
|
|
281
|
+
throw new Error(`sips failed for ${job.pair}/${job.arm}: ${thumb.stderr.toString().trim()}`);
|
|
282
|
+
console.log(`ok ${job.pair}/${job.arm} → ${job.side}`);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
async function writeReviewPackage(jobs: Job[]): Promise<number> {
|
|
286
|
+
const mappingPath = join(WORK, 'mapping.json');
|
|
287
|
+
let allJobs = [...jobs];
|
|
288
|
+
if (existsSync(mappingPath)) {
|
|
289
|
+
const previous = JSON.parse(readFileSync(mappingPath, 'utf8')) as { jobs?: Job[] };
|
|
290
|
+
const incoming = new Set(jobs.map((job) => `${job.pair}/${job.arm}`));
|
|
291
|
+
allJobs = [...(previous.jobs ?? []).filter((job) => !incoming.has(`${job.pair}/${job.arm}`)), ...jobs];
|
|
292
|
+
}
|
|
293
|
+
allJobs.sort((left, right) => left.pair.localeCompare(right.pair) || left.arm.localeCompare(right.arm));
|
|
294
|
+
const pairs = [...new Set(allJobs.map((job) => job.pair))].sort();
|
|
295
|
+
const ready = pairs.filter((pair) => ['A', 'B'].every((side) => existsSync(join(BLIND, pair, `${side}.jpg`))));
|
|
296
|
+
const manifest = ready.map((pair) => {
|
|
297
|
+
const jobsForPair = allJobs.filter((job) => job.pair === pair);
|
|
298
|
+
return {
|
|
299
|
+
pair,
|
|
300
|
+
format: jobsForPair[0]?.format,
|
|
301
|
+
subject: jobsForPair[0]?.subject.id,
|
|
302
|
+
A: `${pair}/A.jpg`,
|
|
303
|
+
B: `${pair}/B.jpg`,
|
|
304
|
+
};
|
|
305
|
+
});
|
|
306
|
+
await writeJson(join(BLIND, 'manifest.json'), { schema_version: 'k3-blind-v1', pairs: manifest });
|
|
307
|
+
await writeJson(mappingPath, {
|
|
308
|
+
schema_version: 'k3-mapping-v1',
|
|
309
|
+
provider: PROVIDER,
|
|
310
|
+
model: MODEL,
|
|
311
|
+
jobs: allJobs,
|
|
312
|
+
});
|
|
313
|
+
const scores: ScoreFile = existsSync(SCORES)
|
|
314
|
+
? (JSON.parse(readFileSync(SCORES, 'utf8')) as ScoreFile)
|
|
315
|
+
: { reviewer: '', reviewedAt: '', pairs: [] };
|
|
316
|
+
const present = new Set(scores.pairs.map((score) => score.pair));
|
|
317
|
+
for (const pair of ready) {
|
|
318
|
+
if (!present.has(pair)) {
|
|
319
|
+
scores.pairs.push({
|
|
320
|
+
pair,
|
|
321
|
+
preferred: null,
|
|
322
|
+
scores: { A: blankArm(), B: blankArm() },
|
|
323
|
+
critical: { A: [], B: [] },
|
|
324
|
+
notes: '',
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
scores.pairs.sort((left, right) => left.pair.localeCompare(right.pair));
|
|
329
|
+
await writeJson(SCORES, scores);
|
|
330
|
+
return ready.length;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
function completeArm(arm: ScoreArm, pair: string, side: Side): CompleteScoreArm {
|
|
334
|
+
for (const dimension of DIMENSIONS) {
|
|
335
|
+
const score = arm[dimension];
|
|
336
|
+
if (typeof score !== 'number' || score < 1 || score > 5) {
|
|
337
|
+
throw new Error(`${pair}/${side}.${dimension} must be a number from 1 to 5`);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
return arm as CompleteScoreArm;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
function average(scores: CompleteScoreArm[]): CompleteScoreArm {
|
|
344
|
+
return Object.fromEntries(
|
|
345
|
+
DIMENSIONS.map((dimension) => [
|
|
346
|
+
dimension,
|
|
347
|
+
Math.round((scores.reduce((sum, score) => sum + score[dimension], 0) / scores.length) * 100) / 100,
|
|
348
|
+
]),
|
|
349
|
+
) as CompleteScoreArm;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
async function report(jobs: Job[]): Promise<void> {
|
|
353
|
+
const scoreFile = JSON.parse(await Bun.file(SCORES).text()) as ScoreFile;
|
|
354
|
+
const scoreByPair = new Map(scoreFile.pairs.map((score) => [score.pair, score]));
|
|
355
|
+
const rows = [];
|
|
356
|
+
for (const candidate of CANDIDATES) {
|
|
357
|
+
const candidateJobs = jobs.filter((job) => job.candidate === candidate.name && job.arm === 'candidate');
|
|
358
|
+
const cells = [];
|
|
359
|
+
let wins = 0;
|
|
360
|
+
let baselineWins = 0;
|
|
361
|
+
let ties = 0;
|
|
362
|
+
let reviewed = 0;
|
|
363
|
+
const critical: object[] = [];
|
|
364
|
+
const candidateScores: CompleteScoreArm[] = [];
|
|
365
|
+
const baselineScores: CompleteScoreArm[] = [];
|
|
366
|
+
for (const candidateJob of candidateJobs) {
|
|
367
|
+
const score = scoreByPair.get(candidateJob.pair);
|
|
368
|
+
if (!score?.preferred && flag('--allow-partial')) {
|
|
369
|
+
cells.push({
|
|
370
|
+
pair: candidateJob.pair,
|
|
371
|
+
format: candidateJob.format,
|
|
372
|
+
subject: candidateJob.subject.id,
|
|
373
|
+
preferred: 'not-evaluated',
|
|
374
|
+
candidateCritical: [],
|
|
375
|
+
baselineCritical: [],
|
|
376
|
+
notes: 'generation or blind review not completed',
|
|
377
|
+
});
|
|
378
|
+
continue;
|
|
379
|
+
}
|
|
380
|
+
if (!score?.preferred) throw new Error(`${candidateJob.pair}: missing preferred A/B/tie`);
|
|
381
|
+
reviewed++;
|
|
382
|
+
const candidateSide = candidateJob.side;
|
|
383
|
+
const baselineSide: Side = candidateSide === 'A' ? 'B' : 'A';
|
|
384
|
+
const candidateScore = completeArm(score.scores[candidateSide], score.pair, candidateSide);
|
|
385
|
+
const baselineScore = completeArm(score.scores[baselineSide], score.pair, baselineSide);
|
|
386
|
+
candidateScores.push(candidateScore);
|
|
387
|
+
baselineScores.push(baselineScore);
|
|
388
|
+
const preferred =
|
|
389
|
+
score.preferred === 'tie' ? 'tie' : score.preferred === candidateSide ? 'candidate' : 'baseline';
|
|
390
|
+
if (preferred === 'candidate') wins++;
|
|
391
|
+
else if (preferred === 'baseline') baselineWins++;
|
|
392
|
+
else ties++;
|
|
393
|
+
if (score.critical[candidateSide].length > 0) {
|
|
394
|
+
critical.push({
|
|
395
|
+
pair: score.pair,
|
|
396
|
+
format: candidateJob.format,
|
|
397
|
+
subject: candidateJob.subject.id,
|
|
398
|
+
violations: score.critical[candidateSide],
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
cells.push({
|
|
402
|
+
pair: score.pair,
|
|
403
|
+
format: candidateJob.format,
|
|
404
|
+
subject: candidateJob.subject.id,
|
|
405
|
+
preferred,
|
|
406
|
+
candidateScores: candidateScore,
|
|
407
|
+
baselineScores: baselineScore,
|
|
408
|
+
candidateCritical: score.critical[candidateSide],
|
|
409
|
+
baselineCritical: score.critical[baselineSide],
|
|
410
|
+
notes: score.notes,
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
const complete = reviewed === candidateJobs.length;
|
|
414
|
+
const accepted = complete && wins >= 3 && critical.length === 0;
|
|
415
|
+
const rejected = critical.length > 0 || (complete && wins < 3);
|
|
416
|
+
rows.push({
|
|
417
|
+
candidate: candidate.name,
|
|
418
|
+
baseline: candidate.baseline,
|
|
419
|
+
decision: accepted ? 'generation-reviewed / accepted' : rejected ? 'rejected' : 'not-evaluated / blocked',
|
|
420
|
+
reviewed,
|
|
421
|
+
wins,
|
|
422
|
+
baselineWins,
|
|
423
|
+
ties,
|
|
424
|
+
critical,
|
|
425
|
+
candidateAverage: candidateScores.length > 0 ? average(candidateScores) : null,
|
|
426
|
+
baselineAverage: baselineScores.length > 0 ? average(baselineScores) : null,
|
|
427
|
+
cells,
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
const accepted = rows.filter((row) => row.decision.includes('accepted')).map((row) => row.candidate);
|
|
431
|
+
const rejected = rows.filter((row) => row.decision === 'rejected').map((row) => row.candidate);
|
|
432
|
+
const pending = rows.filter((row) => row.decision.startsWith('not-evaluated')).map((row) => row.candidate);
|
|
433
|
+
const payload = {
|
|
434
|
+
schema_version: 'k3-evaluation-v1',
|
|
435
|
+
provider: PROVIDER,
|
|
436
|
+
model: MODEL,
|
|
437
|
+
reviewer: scoreFile.reviewer,
|
|
438
|
+
reviewedAt: scoreFile.reviewedAt,
|
|
439
|
+
gate: 'candidate wins >= 3 of 4 cells and zero candidate critical violations',
|
|
440
|
+
crossProviderClaim: false,
|
|
441
|
+
acceptedCandidates: accepted,
|
|
442
|
+
rejectedCandidates: rejected,
|
|
443
|
+
pendingCandidates: pending,
|
|
444
|
+
results: rows,
|
|
445
|
+
};
|
|
446
|
+
const markdown = [
|
|
447
|
+
'# K3 image-style evaluation',
|
|
448
|
+
'',
|
|
449
|
+
`- Provider/model: \`${PROVIDER}/${MODEL}\` (single-provider run; no cross-provider claim)`,
|
|
450
|
+
`- Reviewer: ${scoreFile.reviewer || 'unrecorded'}; reviewed at: ${scoreFile.reviewedAt || 'unrecorded'}`,
|
|
451
|
+
'- Gate: candidate wins at least 3 of 4 pairwise cells and has zero critical violations.',
|
|
452
|
+
'',
|
|
453
|
+
'| Candidate | Baseline | Reviewed | Wins | Baseline wins | Ties | Critical groups | Decision |',
|
|
454
|
+
'| --- | --- | ---: | ---: | ---: | ---: | ---: | --- |',
|
|
455
|
+
...rows.map(
|
|
456
|
+
(row) =>
|
|
457
|
+
`| \`${row.candidate}\` | \`${row.baseline}\` | ${row.reviewed}/4 | ${row.wins} | ${row.baselineWins} | ${row.ties} | ${row.critical.length} | ${row.decision} |`,
|
|
458
|
+
),
|
|
459
|
+
'',
|
|
460
|
+
'## Cell details',
|
|
461
|
+
'',
|
|
462
|
+
'| Candidate | Pair | Format | Subject | Preferred | Candidate critical | Notes |',
|
|
463
|
+
'| --- | --- | --- | --- | --- | --- | --- |',
|
|
464
|
+
...rows.flatMap((row) =>
|
|
465
|
+
row.cells.map(
|
|
466
|
+
(cell) =>
|
|
467
|
+
`| \`${row.candidate}\` | ${cell.pair} | ${cell.format} | ${cell.subject} | ${cell.preferred} | ${cell.candidateCritical.join('; ') || 'none'} | ${cell.notes.replaceAll('|', '\\|')} |`,
|
|
468
|
+
),
|
|
469
|
+
),
|
|
470
|
+
'',
|
|
471
|
+
'Exact prompts and raw provider artifacts are under `runs/`; blind A/B assignment is in `mapping.json`.',
|
|
472
|
+
'',
|
|
473
|
+
].join('\n');
|
|
474
|
+
await writeJson(join(WORK, 'evaluation-report.json'), payload);
|
|
475
|
+
await Bun.write(join(WORK, 'evaluation-report.md'), markdown);
|
|
476
|
+
for (const row of rows)
|
|
477
|
+
console.log(`${row.decision}: ${row.candidate} (${row.wins}/4 wins; ${row.reviewed}/4 reviewed)`);
|
|
478
|
+
console.log(`wrote ${join(WORK, 'evaluation-report.md')}`);
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
const jobs = buildJobs().filter((job) => ONLY === '' || job.candidate === ONLY);
|
|
482
|
+
if (ONLY !== '' && jobs.length !== 8) throw new Error(`${ONLY}: expected eight jobs / four pairs`);
|
|
483
|
+
if (flag('--dry-run')) {
|
|
484
|
+
console.log(
|
|
485
|
+
`evaluation plan OK: ${jobs.length} provider calls / ${new Set(jobs.map((job) => job.pair)).size} blind pairs`,
|
|
486
|
+
);
|
|
487
|
+
console.log(`provider/model: ${PROVIDER}/${MODEL}; work: ${WORK}; candidates: ${CANDIDATE_ROOT}`);
|
|
488
|
+
for (const candidate of CANDIDATES.filter((candidate) => ONLY === '' || candidate.name === ONLY))
|
|
489
|
+
console.log(`${candidate.name} vs ${candidate.baseline}: free + cover × microservices + semiconductor`);
|
|
490
|
+
} else if (flag('--report')) {
|
|
491
|
+
if (ONLY !== '') throw new Error('--report cannot be combined with --only');
|
|
492
|
+
await report(jobs);
|
|
493
|
+
} else {
|
|
494
|
+
const queue = [...jobs];
|
|
495
|
+
const failed: string[] = [];
|
|
496
|
+
const worker = async (): Promise<void> => {
|
|
497
|
+
for (let job = queue.shift(); job !== undefined; job = queue.shift()) {
|
|
498
|
+
try {
|
|
499
|
+
await render(job);
|
|
500
|
+
} catch (error) {
|
|
501
|
+
failed.push(`${job.pair}/${job.arm}`);
|
|
502
|
+
console.error(`FAIL ${job.pair}/${job.arm}: ${error instanceof Error ? error.message : error}`);
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
};
|
|
506
|
+
await Promise.all(Array.from({ length: CONCURRENCY }, worker));
|
|
507
|
+
const ready = await writeReviewPackage(jobs);
|
|
508
|
+
console.log(`${ready}/24 blind pairs ready; scores: ${SCORES}`);
|
|
509
|
+
if (failed.length > 0) {
|
|
510
|
+
console.error(`failed jobs: ${failed.join(', ')}`);
|
|
511
|
+
process.exit(1);
|
|
512
|
+
}
|
|
513
|
+
}
|
|
@@ -7,22 +7,45 @@
|
|
|
7
7
|
* bun plugins/generations/image-gen/scripts/gen-samples.ts --force # re-render every pair
|
|
8
8
|
* bun plugins/generations/image-gen/scripts/gen-samples.ts --readme-only # README from samples on disk
|
|
9
9
|
* bun plugins/generations/image-gen/scripts/gen-samples.ts --provider gemini --model <m>
|
|
10
|
+
* bun plugins/generations/image-gen/scripts/gen-samples.ts --provider google --concurrency 1
|
|
11
|
+
* Provider/model defaults come from the provider registry. assets/sample/provenance.json records
|
|
12
|
+
* the actual provider/model for every thumbnail, so mixed-provider galleries remain truthful.
|
|
10
13
|
*
|
|
11
14
|
* Only the builtin presets/ root is read — user/project preset roots never leak
|
|
12
15
|
* into the shipped index. A finished sample is never overwritten without --force,
|
|
13
16
|
* so a run that dies on pair 37 resumes from pair 37. Failed pairs are named and
|
|
14
17
|
* the script exits 1.
|
|
15
18
|
*/
|
|
16
|
-
import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync } from 'node:fs';
|
|
19
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
17
20
|
import { join } from 'node:path';
|
|
18
21
|
import { type FormatPreset, FormatPresetSchema, type StylePreset, StylePresetSchema } from '../src/presets';
|
|
22
|
+
import { PROVIDERS } from '../src/providers/types';
|
|
19
23
|
|
|
20
24
|
const PLUGIN_DIR = join(import.meta.dir, '..');
|
|
21
25
|
const SAMPLE_DIR = join(PLUGIN_DIR, 'assets', 'sample');
|
|
22
26
|
const README = join(PLUGIN_DIR, 'README.md');
|
|
23
27
|
const WORK_DIR = join(process.cwd(), '.works', 'tmp', 'test-samples');
|
|
24
28
|
const THUMB_PX = 640;
|
|
25
|
-
const
|
|
29
|
+
const PROVENANCE_PATH = join(SAMPLE_DIR, 'provenance.json');
|
|
30
|
+
|
|
31
|
+
interface SampleOrigin {
|
|
32
|
+
provider: string;
|
|
33
|
+
model: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const provenance: Record<string, SampleOrigin> = existsSync(PROVENANCE_PATH)
|
|
37
|
+
? (JSON.parse(readFileSync(PROVENANCE_PATH, 'utf8')) as Record<string, SampleOrigin>)
|
|
38
|
+
: {};
|
|
39
|
+
|
|
40
|
+
function saveProvenance(): void {
|
|
41
|
+
mkdirSync(SAMPLE_DIR, { recursive: true });
|
|
42
|
+
writeFileSync(PROVENANCE_PATH, `${JSON.stringify(provenance, null, 4)}\n`);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Existing K1 samples predate the sidecar and were all MiniMax image-01 (task 0340). */
|
|
46
|
+
function originFor(file: string): SampleOrigin {
|
|
47
|
+
return provenance[file] ?? { provider: 'minimax', model: 'image-01' };
|
|
48
|
+
}
|
|
26
49
|
|
|
27
50
|
/** Fixed per-job inputs so every style is compared on the same subject. */
|
|
28
51
|
const SAMPLE_SUBJECT = 'a request flowing through an API gateway to three microservices';
|
|
@@ -39,7 +62,15 @@ const option = (name: string, fallback: string): string => {
|
|
|
39
62
|
return index >= 0 && args[index + 1] !== undefined ? args[index + 1] : fallback;
|
|
40
63
|
};
|
|
41
64
|
const provider = option('--provider', 'minimax');
|
|
42
|
-
const
|
|
65
|
+
const registration = PROVIDERS[provider];
|
|
66
|
+
if (registration === undefined) {
|
|
67
|
+
throw new Error(`Unknown provider '${provider}'. Valid providers: ${Object.keys(PROVIDERS).sort().join(', ')}`);
|
|
68
|
+
}
|
|
69
|
+
const model = option('--model', registration.defaultModel);
|
|
70
|
+
const concurrency = Number(option('--concurrency', '3'));
|
|
71
|
+
if (!Number.isInteger(concurrency) || concurrency < 1 || concurrency > 10) {
|
|
72
|
+
throw new Error('--concurrency must be an integer from 1 to 10');
|
|
73
|
+
}
|
|
43
74
|
|
|
44
75
|
function loadBuiltin<T>(axis: string, schema: { parse(value: unknown): T }): T[] {
|
|
45
76
|
const dir = join(PLUGIN_DIR, 'presets', axis);
|
|
@@ -94,7 +125,11 @@ async function render(format: FormatPreset, style: StylePreset): Promise<void> {
|
|
|
94
125
|
if (code !== 0) {
|
|
95
126
|
throw new Error(`kk exited ${code}: ${stderr.trim().split('\n').slice(-3).join(' | ')}`);
|
|
96
127
|
}
|
|
97
|
-
const
|
|
128
|
+
const content = (await Bun.file(output).json()) as {
|
|
129
|
+
metadata?: { images?: Array<{ path?: string; provider?: string; model?: string }> };
|
|
130
|
+
};
|
|
131
|
+
const artifact = content.metadata?.images?.[0];
|
|
132
|
+
const image = artifact?.path;
|
|
98
133
|
if (image === undefined) {
|
|
99
134
|
throw new Error('executor output carries no metadata.images[0].path');
|
|
100
135
|
}
|
|
@@ -117,6 +152,11 @@ async function render(format: FormatPreset, style: StylePreset): Promise<void> {
|
|
|
117
152
|
if (sips.exitCode !== 0) {
|
|
118
153
|
throw new Error(`sips failed: ${sips.stderr.toString().trim()}`);
|
|
119
154
|
}
|
|
155
|
+
provenance[sampleName(format.name, style.name)] = {
|
|
156
|
+
provider: artifact?.provider ?? provider,
|
|
157
|
+
model: artifact?.model ?? model,
|
|
158
|
+
};
|
|
159
|
+
saveProvenance();
|
|
120
160
|
}
|
|
121
161
|
|
|
122
162
|
async function renderAll(): Promise<string[]> {
|
|
@@ -140,7 +180,7 @@ async function renderAll(): Promise<string[]> {
|
|
|
140
180
|
}
|
|
141
181
|
}
|
|
142
182
|
};
|
|
143
|
-
await Promise.all(Array.from({ length:
|
|
183
|
+
await Promise.all(Array.from({ length: concurrency }, worker));
|
|
144
184
|
return failed;
|
|
145
185
|
}
|
|
146
186
|
|
|
@@ -159,7 +199,7 @@ function readme(): string {
|
|
|
159
199
|
"`--format` / `--style` to the `kk:image-generate` skill. Omitting the style uses the format's",
|
|
160
200
|
'default (★ below).',
|
|
161
201
|
'',
|
|
162
|
-
`Samples: provider
|
|
202
|
+
`Samples: provider/model shown per cell, downscaled to ${THUMB_PX}px JPEG. Inputs are fixed per`,
|
|
163
203
|
`job — subject “${SAMPLE_SUBJECT}”; cover title “${COVER_VARS.title}”. Regenerate with`,
|
|
164
204
|
'`bun plugins/generations/image-gen/scripts/gen-samples.ts` (see its header for flags).',
|
|
165
205
|
'',
|
|
@@ -189,8 +229,9 @@ function readme(): string {
|
|
|
189
229
|
const cells = styles.slice(i, i + columns).map((style) => {
|
|
190
230
|
const file = sampleName(format.name, style.name);
|
|
191
231
|
const label = `\`${style.name}\`${style.name === format.defaultStyle ? ' ★' : ''}`;
|
|
232
|
+
const origin = originFor(file);
|
|
192
233
|
return existsSync(join(SAMPLE_DIR, file))
|
|
193
|
-
? `<img src="assets/sample/${file}" alt="${format.name} × ${style.name}" width="260"><br>${label}
|
|
234
|
+
? `<img src="assets/sample/${file}" alt="${format.name} × ${style.name}" width="260"><br>${label}<br><small>${origin.provider}/${origin.model}</small>`
|
|
194
235
|
: `_not rendered_<br>${label}`;
|
|
195
236
|
});
|
|
196
237
|
lines.push(`| ${cells.join(' | ')} |`);
|
|
@@ -200,6 +241,15 @@ function readme(): string {
|
|
|
200
241
|
}
|
|
201
242
|
|
|
202
243
|
const failed = flag('--readme-only') ? [] : await renderAll();
|
|
244
|
+
for (const format of formats) {
|
|
245
|
+
for (const style of styles) {
|
|
246
|
+
const file = sampleName(format.name, style.name);
|
|
247
|
+
if (existsSync(join(SAMPLE_DIR, file)) && provenance[file] === undefined) {
|
|
248
|
+
provenance[file] = originFor(file);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
saveProvenance();
|
|
203
253
|
await Bun.write(README, readme());
|
|
204
254
|
console.log(`wrote ${README}`);
|
|
205
255
|
if (failed.length > 0) {
|
|
@@ -86,7 +86,7 @@ export interface StylePreset {
|
|
|
86
86
|
typography?: string;
|
|
87
87
|
visualElements?: string[];
|
|
88
88
|
bestFor?: string;
|
|
89
|
-
/**
|
|
89
|
+
/** Appended as `avoid: …` to every composed provider prompt (K3). */
|
|
90
90
|
negative?: string;
|
|
91
91
|
source?: PresetSource;
|
|
92
92
|
}
|
|
@@ -248,9 +248,9 @@ export function renderTemplate(template: string, vars: Record<string, string>, f
|
|
|
248
248
|
/**
|
|
249
249
|
* R2 — the frozen composition rule, wt's order as built
|
|
250
250
|
* (`template_engine.py:174-190`): rendered body → keywords → style modifiers
|
|
251
|
-
* → caller extra, empty segments dropped.
|
|
252
|
-
*
|
|
253
|
-
*
|
|
251
|
+
* → optional `avoid: …` (K3) → caller extra, empty segments dropped. The
|
|
252
|
+
* negative segment implements 0102's provider-independent fallback without
|
|
253
|
+
* changing prompts for styles that declare none.
|
|
254
254
|
*/
|
|
255
255
|
export function composePrompt(
|
|
256
256
|
format: FormatPreset,
|
|
@@ -259,7 +259,8 @@ export function composePrompt(
|
|
|
259
259
|
extra?: string,
|
|
260
260
|
): string {
|
|
261
261
|
const body = renderTemplate(format.template, mergeVars(format.variables, vars), format.name);
|
|
262
|
-
|
|
262
|
+
const negative = style.negative ? `avoid: ${style.negative}` : undefined;
|
|
263
|
+
return [body, format.keywords.join(', '), style.modifiers, negative, extra].filter(Boolean).join(', ');
|
|
263
264
|
}
|
|
264
265
|
|
|
265
266
|
/** Discovery diagnostic, mirroring kk-core's `DiscoveryDiagnostic` shape. */
|