@cloud411716/fancy-webnovel 4.30.41 → 4.30.43

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloud411716/fancy-webnovel",
3
- "version": "4.30.41",
3
+ "version": "4.30.43",
4
4
  "type": "module",
5
5
  "main": "index.js",
6
6
  "exports": {
@@ -938,6 +938,62 @@ function answerSingle(answer) {
938
938
  return Array.isArray(answer.selected) ? String(answer.selected[0] || '').trim() : '';
939
939
  }
940
940
 
941
+ function materialPreviewText(records) {
942
+ const lines = [
943
+ `## 待确认入库(${records.length} 条)`,
944
+ '',
945
+ '以下素材已经通过 Team 交叉审查和裁判,但**还没有写入数据库**。',
946
+ '',
947
+ ];
948
+ records.forEach((record, index) => {
949
+ lines.push(`### ${index + 1}. ${record.name || '未命名'}`);
950
+ lines.push(`- note:${record.note || ''}`);
951
+ lines.push(`- derivation:${record.derivation || ''}`);
952
+ lines.push('');
953
+ });
954
+ return lines.join('\n');
955
+ }
956
+
957
+ async function confirmMaterialImport(ctx, invocation, session, records, previewFile = '') {
958
+ const preview = materialPreviewText(records) + (previewFile ? `\n\n预览文件:${previewFile}` : '');
959
+ await notify(session, 'success', preview);
960
+ const first = await askOne(ctx, invocation, {
961
+ id: 'material_import_confirm',
962
+ header: '素材入库',
963
+ question: `以上 ${records.length} 条素材要写入数据库吗?`,
964
+ options: [
965
+ { label: '全部写入', description: '把全部素材写入数据库' },
966
+ { label: '选择部分', description: '逐条选择要写入的素材' },
967
+ { label: '全部不写入', description: '保留文件,不写数据库' },
968
+ ],
969
+ });
970
+ if (!first.ok) return first;
971
+ const choice = answerSingle(first.answer);
972
+ if (choice === '全部写入') {
973
+ return { ok: true, selected: new Set(records.map((record) => record.name)) };
974
+ }
975
+ if (choice === '全部不写入') {
976
+ return { ok: true, selected: new Set() };
977
+ }
978
+ if (choice !== '选择部分') {
979
+ return { ok: false, message: '未识别的入库选择:' + (choice || '空') };
980
+ }
981
+ const second = await askOne(ctx, invocation, {
982
+ id: 'material_import_select',
983
+ header: '选择素材',
984
+ question: `选择要写入数据库的素材(可多选,共 ${records.length} 条)`,
985
+ multiple: true,
986
+ options: records.map((record) => ({
987
+ label: record.name || '未命名',
988
+ description: String(record.note || '').slice(0, 80),
989
+ })),
990
+ });
991
+ if (!second.ok) return second;
992
+ const known = new Set(records.map((record) => record.name));
993
+ const selected = new Set(answerList(second.answer).filter((name) => known.has(name)));
994
+ return { ok: true, selected };
995
+ }
996
+
941
997
  function facetStateFromLabels(facetLabels) {
942
998
  const facets = {};
943
999
  for (const step of FACET_STEPS) {
@@ -1811,7 +1867,7 @@ export async function runGenerationWithPlan(ctx, invocation, session, taskList,
1811
1867
  batchId,
1812
1868
  batchNo,
1813
1869
  keep: Math.min(next.requestCount, Math.max(0, item.target - item.generated)),
1814
- poolSize: Math.max(30, Math.min(Number(nameStage.poolSize) || 80, Math.max(30, Math.min(next.requestCount, Math.max(0, item.target - item.generated)) * 4))),
1870
+ poolSize: Math.max(30, Math.min(Number(nameStage.poolSize) || 80, Math.max(30, Math.min(next.requestCount, Math.max(0, item.target - item.generated)) * 6))),
1815
1871
  anchorNames: item.generated === 0 ? (Array.isArray(nameStage.anchorNames) ? nameStage.anchorNames : []) : [],
1816
1872
  });
1817
1873
  if (!nameOut.ok) {
@@ -2023,7 +2079,42 @@ export async function runGenerationWithPlan(ctx, invocation, session, taskList,
2023
2079
  attemptDetail = checked.detail || attemptDetail;
2024
2080
  continue;
2025
2081
  }
2026
- const acceptedResult = await acceptBatch(file, item, groupId);
2082
+ let importFile = file;
2083
+ let reviewResult = null;
2084
+ if (useTeam && team.reviewBeforeImport) {
2085
+ const recordsForReview = readJsonlRecords(file);
2086
+ if (recordsForReview.length) {
2087
+ const previewFile = file.replace(/\.jsonl$/, '.review.md');
2088
+ fs.writeFileSync(previewFile, materialPreviewText(recordsForReview) + '\n', 'utf8');
2089
+ reviewResult = await confirmMaterialImport(ctx, invocation, session, recordsForReview, previewFile);
2090
+ if (!reviewResult.ok) {
2091
+ fatal = true;
2092
+ stopReason = reviewResult.message;
2093
+ lastReason = stopReason;
2094
+ await notify(session, 'error', reviewResult.message + '\n未写入数据库。文件:' + file);
2095
+ break;
2096
+ }
2097
+ if (!reviewResult.selected.size) {
2098
+ fatal = true;
2099
+ stopReason = '用户未选择入库素材';
2100
+ lastReason = stopReason;
2101
+ await notify(session, 'success', '未写入数据库。文件保留:' + file);
2102
+ break;
2103
+ }
2104
+ if (reviewResult.selected.size < recordsForReview.length) {
2105
+ const selectedFile = file.replace(/\.jsonl$/, '.selected.jsonl');
2106
+ const selectedRecords = recordsForReview.filter((record) => reviewResult.selected.has(record.name));
2107
+ fs.writeFileSync(selectedFile, selectedRecords.map((record) => JSON.stringify(record)).join('\n') + '\n', 'utf8');
2108
+ const selectedCheck = await validateBatch(selectedFile, item, groupId);
2109
+ if (!selectedCheck.ok) {
2110
+ attemptDetail = selectedCheck.detail || '用户选择的素材未通过校验';
2111
+ continue;
2112
+ }
2113
+ importFile = selectedFile;
2114
+ }
2115
+ }
2116
+ }
2117
+ const acceptedResult = await acceptBatch(importFile, item, groupId);
2027
2118
  if (acceptedResult.fatal) {
2028
2119
  fatal = true;
2029
2120
  stopReason = '导入数据库失败:' + acceptedResult.detail;
@@ -2040,6 +2131,7 @@ export async function runGenerationWithPlan(ctx, invocation, session, taskList,
2040
2131
  group_id: groupId || item.group_id || '',
2041
2132
  batch: batchNo,
2042
2133
  file,
2134
+ ...(importFile !== file ? { selected_file: importFile } : {}),
2043
2135
  request_count: next.requestCount,
2044
2136
  imported: acceptedResult.imported,
2045
2137
  generated: item.generated,
@@ -2047,6 +2139,9 @@ export async function runGenerationWithPlan(ctx, invocation, session, taskList,
2047
2139
  attempts: attempt,
2048
2140
  }) + '\n');
2049
2141
  } catch { /* best effort */ }
2142
+ if (reviewResult && reviewResult.selected.size) {
2143
+ await notify(session, 'success', `✅ 已写入 ${acceptedResult.imported} 条素材(${item.label})。`);
2144
+ }
2050
2145
  if (acceptedResult.imported === 0) {
2051
2146
  stalled += 1;
2052
2147
  attemptDetail = '本批没有新增素材(可能全是重复),必须写库中不存在的新素材';
@@ -2190,7 +2285,8 @@ function teamText(root, config) {
2190
2285
  `最多审查轮次:${config.maxReviewRounds}`,
2191
2286
  `最多 agent 调用:${config.maxTotalCalls}`,
2192
2287
  `5 轮未通过交裁判:${config.judgeOnMaxRounds ? '是' : '否'}`,
2193
- `ability_name 名字阶段:${config.nameStage?.enabled ? '开启' : '关闭'}(池 ${config.nameStage?.poolSize || 80} / 留 ${config.nameStage?.keep || 20} / 裁判 ${config.nameStage?.judges || 3})`,
2288
+ `入库前人工确认:${config.reviewBeforeImport ? '开启' : '关闭'}`,
2289
+ `ability_name 名字阶段:${config.nameStage?.enabled ? '开启' : '关闭'}(池 ${config.nameStage?.poolSize || 80} / 留 ${config.nameStage?.keep || 20} / 裁判 ${config.nameStage?.judges || 3} / 达标 ${config.nameStage?.minScore || 4.5})`,
2194
2290
  `锚点名字:${(config.nameStage?.anchorNames || []).join('、') || '(无)'}`,
2195
2291
  '',
2196
2292
  `配置文件:${teamConfigPath(root)}`,
@@ -2249,7 +2345,7 @@ async function handleTeamCommand(ctx, session, tokens) {
2249
2345
  const key = String(tokens[1] || '').toLowerCase();
2250
2346
  const value = tokens.slice(2);
2251
2347
  if (!key) {
2252
- return notify(session, 'error', '用法:/fancy-material team set a|b|judge <provider> <model> [thinking] | rounds <n> | max-calls <n> | mode <cross|oneway> | judge-on-max <true|false> | name-stage on|off | anchors <名字...> | rejected <名字...> | name-pool <n> | name-keep <n> | name-judges <n>');
2348
+ return notify(session, 'error', '用法:/fancy-material team set a|b|judge <provider> <model> [thinking] | rounds <n> | max-calls <n> | mode <cross|oneway> | judge-on-max <true|false> | review-before-import on|off | name-stage on|off | anchors <名字...> | rejected <名字...> | name-pool <n> | name-keep <n> | name-judges <n>');
2253
2349
  }
2254
2350
  if (key === 'a' || key === 'b' || key === 'judge') {
2255
2351
  if (value.length < 2) {
@@ -2310,6 +2406,13 @@ async function handleTeamCommand(ctx, session, tokens) {
2310
2406
  writeTeamConfig(root, config);
2311
2407
  return notify(session, 'success', `✅ 5 轮未通过交裁判:${config.judgeOnMaxRounds ? '是' : '否'}。`);
2312
2408
  }
2409
+ if (key === 'review-before-import') {
2410
+ const on = String(value[0] || '').toLowerCase();
2411
+ if (on !== 'on' && on !== 'off') return notify(session, 'error', 'review-before-import 只能是 on 或 off。');
2412
+ config.reviewBeforeImport = on === 'on';
2413
+ writeTeamConfig(root, config);
2414
+ return notify(session, 'success', `✅ 入库前人工确认已${config.reviewBeforeImport ? '开启' : '关闭'}。`);
2415
+ }
2313
2416
  if (key === 'name-stage') {
2314
2417
  const on = String(value[0] || '').toLowerCase();
2315
2418
  if (on !== 'on' && on !== 'off') return notify(session, 'error', 'name-stage 只能是 on 或 off。');
@@ -29,8 +29,12 @@ const NAME_SCORE_SCHEMA = {
29
29
  hook: { type: 'number' },
30
30
  distinct: { type: 'number' },
31
31
  image: { type: 'number' },
32
+ clarity: { type: 'number' },
33
+ natural: { type: 'number' },
34
+ coldRead: { type: 'number' },
35
+ interpretation: { type: 'string' },
32
36
  },
33
- required: ['name', 'hook', 'distinct', 'image'],
37
+ required: ['name', 'hook', 'distinct', 'image', 'clarity', 'natural', 'coldRead'],
34
38
  },
35
39
  },
36
40
  },
@@ -144,8 +148,14 @@ function buildNamePrompt({
144
148
  lines.push('- 面具是对象;傩面是物象。');
145
149
  lines.push('- 下水道是对象;暗渠是物象。');
146
150
  lines.push('');
147
- lines.push('名字结构:**物象 + 强动词 + 神圣/身份对象或巨大后果**。');
148
- lines.push('名字单看就要有“这怎么可能/代价是什么”的张力;不读 note 也能猜出能力方向。');
151
+ lines.push('名字结构优先:');
152
+ lines.push('1. **物象 + 结果/状态**:`灯烬名灭`、`门槛吃岁`');
153
+ lines.push('2. **主体 + 动作**:`工牌借脸`、`檐灰点眼`');
154
+ lines.push('3. **条件 + 后果**:`灯灭名断`');
155
+ lines.push('');
156
+ lines.push('避免:**物象 + 动词 + 隐含对象**的三截压缩,例如 `灯烬点名`、`旧牌借脸`——读者要先补主语/宾语才知道发生了什么。');
157
+ lines.push('名字单看就要有“这怎么可能/代价是什么”的张力;不读 note 也能在一眼里猜出能力方向。');
158
+ lines.push('读一遍要顺。不要为了凑四字把词压成不自然的缩写:`旧工牌` 不要压成 `旧牌`,`点眼` 不要写成 `点主`。');
149
159
  lines.push('');
150
160
  if (anchors.length) {
151
161
  lines.push('# 用户认可的名字(只学结构,不要直接复用)');
@@ -198,10 +208,15 @@ function buildScorePrompt(names) {
198
208
  '- hook:第一眼吸引力。5 = 一眼记住;4.5 = 很强;4 = 好但眼熟;3 = 普通。',
199
209
  '- distinct:独特性。5 = 不常见且不可替换;4.5 = 有明显辨识度;4 = 同类里常见。',
200
210
  '- image:物象感。5 = 有一个带质感/痕迹/仪式/禁忌的具体物象;4 = 有画面但偏普通;3 = 功能对象或流程词。',
211
+ '- clarity:第一读能不能说出能力方向。5 = 一遍就懂;4.5 = 稍一停顿就懂;4 = 需要补一步;3 = 要读 note 才懂。',
212
+ '- natural:像不像自然中文。5 = 顺口自然;4.5 = 略压缩但顺;4 = 像代号/标题;3 = 生硬、需要硬脑补。',
213
+ '- coldRead:只看名字,能不能用一句话说出“这能力干什么”。5 = 能;4.5 = 接近;4 = 只能说个大概;3 = 只能感到气氛。',
214
+ '',
215
+ '同时给每个名字写一句 `interpretation`:你只看名字时,第一反应它是什么能力。不要补设定。',
201
216
  '',
202
217
  list,
203
218
  '',
204
- '只返回 JSON:{"scores":[{"name":"名字","hook":0,"distinct":0,"image":0}]}。不要解释,不要改写名字。',
219
+ '只返回 JSON:{"scores":[{"name":"名字","hook":0,"distinct":0,"image":0,"clarity":0,"natural":0,"coldRead":0,"interpretation":"一句话"}]}。不要解释,不要改写名字。',
205
220
  ].join('\n');
206
221
  }
207
222
 
@@ -369,6 +384,7 @@ export async function runNameStage({
369
384
 
370
385
  const panelNames = screeningOrder.slice(0, targetTop);
371
386
  const scoreMap = new Map();
387
+ const interpretations = new Map();
372
388
  const panelResults = await Promise.all(
373
389
  Array.from({ length: judgeCount }, (_, index) => {
374
390
  const shuffled = shuffle(panelNames, Number(batchNo) * 104729 + index * 97 + 31);
@@ -392,40 +408,64 @@ export async function runNameStage({
392
408
  for (const row of result.value.scores) {
393
409
  const name = normalizeName(row.name);
394
410
  if (!panelNames.includes(name)) continue;
395
- if (!scoreMap.has(name)) scoreMap.set(name, { hook: [], distinct: [], image: [] });
411
+ if (!scoreMap.has(name)) {
412
+ scoreMap.set(name, { hook: [], distinct: [], image: [], clarity: [], natural: [], coldRead: [] });
413
+ }
396
414
  const scores = scoreMap.get(name);
397
- for (const key of ['hook', 'distinct', 'image']) {
415
+ for (const key of ['hook', 'distinct', 'image', 'clarity', 'natural', 'coldRead']) {
398
416
  const value = Number(row[key]);
399
417
  if (Number.isFinite(value)) scores[key].push(value);
400
418
  }
419
+ if (typeof row.interpretation === 'string' && row.interpretation.trim() && !interpretations.has(name)) {
420
+ interpretations.set(name, row.interpretation.trim());
421
+ }
401
422
  }
402
423
  }
403
424
 
404
425
  const screeningRank = new Map(screeningOrder.map((name, index) => [name, index]));
426
+ const minScore = Math.max(1, Math.min(5, Number(config.minScore) || 4.5));
405
427
  const ranked = panelNames
406
428
  .map((name) => {
407
- const scores = scoreMap.get(name) || { hook: [], distinct: [], image: [] };
429
+ const scores = scoreMap.get(name) || { hook: [], distinct: [], image: [], clarity: [], natural: [], coldRead: [] };
408
430
  const hook = average(scores.hook);
409
431
  const distinct = average(scores.distinct);
410
432
  const image = average(scores.image);
433
+ const clarity = average(scores.clarity);
434
+ const natural = average(scores.natural);
435
+ const coldRead = average(scores.coldRead);
411
436
  return {
412
437
  name,
413
438
  hook,
414
439
  distinct,
415
440
  image,
416
- total: hook + distinct + image,
441
+ clarity,
442
+ natural,
443
+ coldRead,
444
+ min: Math.min(hook, distinct, clarity, natural, coldRead),
445
+ total: hook + distinct + image + clarity + natural + coldRead,
417
446
  rank: screeningRank.get(name) ?? 999,
447
+ interpretation: interpretations.get(name) || '',
418
448
  };
419
449
  })
420
- .sort((a, b) => (b.total - a.total) || (a.rank - b.rank));
450
+ .sort((a, b) => (b.min - a.min) || (b.total - a.total) || (a.rank - b.rank));
421
451
 
422
452
  const needed = Math.max(0, keep - anchors.length);
423
453
  const selectedNew = [];
424
- for (const row of ranked) {
454
+ const strictlyQualified = ranked.filter((row) => row.min >= minScore);
455
+ for (const row of strictlyQualified) {
425
456
  if (selectedNew.length >= needed) break;
426
457
  if (anchorSet.has(row.name)) continue;
427
458
  selectedNew.push(row.name);
428
459
  }
460
+ if (selectedNew.length < needed) {
461
+ warnings.push('clarity/natural/cold-read 全达标的候选不足,使用次优补位:'
462
+ + selectedNew.length + '/' + needed);
463
+ for (const row of ranked) {
464
+ if (selectedNew.length >= needed) break;
465
+ if (anchorSet.has(row.name) || selectedNew.includes(row.name)) continue;
466
+ selectedNew.push(row.name);
467
+ }
468
+ }
429
469
  if (selectedNew.length < needed) {
430
470
  for (const name of screeningOrder) {
431
471
  if (selectedNew.length >= needed) break;
@@ -460,11 +500,31 @@ export async function runNameStage({
460
500
  return {
461
501
  ...row,
462
502
  anchor: anchorSet.has(name),
463
- ...(score ? { score: { hook: score.hook, distinct: score.distinct, image: score.image } } : {}),
503
+ ...(score ? {
504
+ score: {
505
+ hook: score.hook,
506
+ distinct: score.distinct,
507
+ image: score.image,
508
+ clarity: score.clarity,
509
+ natural: score.natural,
510
+ coldRead: score.coldRead,
511
+ },
512
+ ...(score.interpretation ? { interpretation: score.interpretation } : {}),
513
+ } : {}),
464
514
  };
465
515
  });
466
516
  writeJsonl(selectedFile, selected);
467
517
  const finishedAt = new Date().toISOString();
518
+ const belowThreshold = selected
519
+ .filter((row) => row.score)
520
+ .filter((row) => Math.min(
521
+ row.score.hook,
522
+ row.score.distinct,
523
+ row.score.clarity,
524
+ row.score.natural,
525
+ row.score.coldRead,
526
+ ) < minScore)
527
+ .map((row) => row.name);
468
528
  const meta = {
469
529
  batchId,
470
530
  batchNo,
@@ -477,6 +537,8 @@ export async function runNameStage({
477
537
  keep,
478
538
  screeningTop: targetTop,
479
539
  judges: judgeCount,
540
+ minScore,
541
+ belowThreshold,
480
542
  calls,
481
543
  selected: selected.map((row) => row.name),
482
544
  warnings,
@@ -18,6 +18,7 @@ const DEFAULT_TEAM = Object.freeze({
18
18
  maxReviewRounds: 5,
19
19
  maxTotalCalls: 12,
20
20
  judgeOnMaxRounds: true,
21
+ reviewBeforeImport: true,
21
22
  generatorA: null,
22
23
  generatorB: null,
23
24
  judge: null,
@@ -28,6 +29,7 @@ const DEFAULT_TEAM = Object.freeze({
28
29
  keep: 20,
29
30
  screeningTop: 30,
30
31
  judges: 3,
32
+ minScore: 4.5,
31
33
  anchorNames: [],
32
34
  rejectedNames: [],
33
35
  },
@@ -55,6 +57,7 @@ export function readTeamConfig(root) {
55
57
  out.maxReviewRounds = clampInt(out.maxReviewRounds, 1, 10, 5);
56
58
  out.maxTotalCalls = clampInt(out.maxTotalCalls, 6, 40, 12);
57
59
  out.judgeOnMaxRounds = out.judgeOnMaxRounds !== false;
60
+ out.reviewBeforeImport = out.reviewBeforeImport !== false;
58
61
  const ns = raw && raw.nameStage && typeof raw.nameStage === 'object' ? raw.nameStage : {};
59
62
  out.nameStage = {
60
63
  enabled: ns.enabled !== false,
@@ -63,6 +66,7 @@ export function readTeamConfig(root) {
63
66
  keep: clampInt(ns.keep, 1, 100, 20),
64
67
  screeningTop: clampInt(ns.screeningTop, 10, 200, 30),
65
68
  judges: clampInt(ns.judges, 1, 5, 3),
69
+ minScore: Math.max(1, Math.min(5, Number(ns.minScore) || 4.5)),
66
70
  anchorNames: stringArray(ns.anchorNames, []),
67
71
  rejectedNames: stringArray(ns.rejectedNames, []),
68
72
  };