@cloud411716/fancy-webnovel 4.30.40 → 4.30.41
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.
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# 名字已锁定:只写 note / derivation
|
|
2
|
+
|
|
3
|
+
本批 `ability_name` 的名字已经通过 name-only 盲评锁定。
|
|
4
|
+
如果本节与基础提示词 3.5(生成流程)或 3.6(来源覆盖)冲突,以本节为准。
|
|
5
|
+
|
|
6
|
+
- 不得改名、增删、替换。
|
|
7
|
+
- 每条记录必须原样使用给定名字。
|
|
8
|
+
- note / derivation 不能再解释名字为什么成立;要给出新的机制、代价、限制、漏洞。
|
|
9
|
+
- `08-naming-method.md` 的公式只用于事后结构审计,不要用它改名、补名或要求名字符合某个公式。
|
|
10
|
+
|
|
11
|
+
## 来源选择(第二阶段)
|
|
12
|
+
|
|
13
|
+
名字已经锁定,来源不能反过来影响名字。
|
|
14
|
+
|
|
15
|
+
优先级:
|
|
16
|
+
|
|
17
|
+
1. 来源 3:神话/道教/佛教/民俗/术数——神格权责、仪式、禁忌、因果账本。
|
|
18
|
+
2. 来源 5:历史/制度/律法/经济/社会——制度漏洞、债务、身份、层层成本。
|
|
19
|
+
3. 来源 6:科学/技术/医学/认知科学——硬约束、代偿、反馈、损耗。
|
|
20
|
+
4. 来源 7:艺术/感官/器物/工艺/媒介——材质、工艺、媒介局限。
|
|
21
|
+
5. 来源 8:日常/职业/城市/网络/现代空间——设施、流程死角、隐性规矩。
|
|
22
|
+
6. 来源 9:心理学/哲学/梦境原型——认知陷阱、身份分裂、执念闭环。
|
|
23
|
+
7. 来源 11:成套符号/序列原型——成组权柄、等级、同源能力。
|
|
24
|
+
|
|
25
|
+
中相关:来源 2(古器物/奇物约束)、4(原型/异化)、10(闭环/替身/归还)。
|
|
26
|
+
|
|
27
|
+
低相关:来源 1(诗词意象)。除非本批是诗词/古风命名,不优先。
|
|
28
|
+
|
|
29
|
+
## 相关性测试
|
|
30
|
+
|
|
31
|
+
每个来源必须能回答:
|
|
32
|
+
|
|
33
|
+
> 它给这条名字提供了什么**具体机制 / 物象 / 代价**?
|
|
34
|
+
|
|
35
|
+
只能提供氛围、名词或“古老感”的,不算有效来源。
|
|
36
|
+
|
|
37
|
+
- 优先 2–3 个高相关来源。
|
|
38
|
+
- 不要求来源覆盖数量。
|
|
39
|
+
- 不为了凑来源硬贴。
|
|
40
|
+
- 如果找不到高相关来源,`derivation` 标 `原创/综合`,写清核心机制即可。
|
|
41
|
+
|
|
42
|
+
## note / derivation
|
|
43
|
+
|
|
44
|
+
- `note` 180–250 字:效果、代价、限制、漏洞。
|
|
45
|
+
- `derivation` 180–300 字:来源库、映射链、核心机制、换世界时可替换的接口。
|
|
46
|
+
- 名字已经成立,note 不能只是复述名字。
|
|
47
|
+
- 同批不要连续复用同一个物象或同一条代价模板。
|
package/package.json
CHANGED
|
@@ -69,6 +69,7 @@ import {
|
|
|
69
69
|
validateTeamModels,
|
|
70
70
|
writeTeamConfig,
|
|
71
71
|
} from './team.js';
|
|
72
|
+
import { runNameStage } from './name-stage.js';
|
|
72
73
|
import { nextBatchRequest } from './queue.js';
|
|
73
74
|
import { ABILITY_CORE_KINDS, buildGenerationItems, planGenerationQueue } from './plan.js';
|
|
74
75
|
import { deployMaterialTools } from './tool-deploy.js';
|
|
@@ -1373,6 +1374,29 @@ function kindBlockForItem(item) {
|
|
|
1373
1374
|
return renderKindBlock(item.kind);
|
|
1374
1375
|
}
|
|
1375
1376
|
|
|
1377
|
+
function renderLockedNamesBlock(rows) {
|
|
1378
|
+
const lines = [
|
|
1379
|
+
'## 本批名字已锁定(最高优先级)',
|
|
1380
|
+
'',
|
|
1381
|
+
'以下名字已经通过 name-only 盲评,不得改名、增删、替换。每条记录必须原样使用给定 name。',
|
|
1382
|
+
'名字已经成立,note/derivation 要给出新的机制、代价、限制、漏洞,不要只复述名字。',
|
|
1383
|
+
'',
|
|
1384
|
+
];
|
|
1385
|
+
rows.forEach((row, index) => {
|
|
1386
|
+
const promise = row && row.promise ? ' — ' + row.promise : '';
|
|
1387
|
+
lines.push(`${index + 1}. \`${row.name}\`${promise}`);
|
|
1388
|
+
});
|
|
1389
|
+
lines.push(
|
|
1390
|
+
'',
|
|
1391
|
+
'## 来源选择(第二阶段)',
|
|
1392
|
+
'',
|
|
1393
|
+
'名字已经锁定,来源不能反过来影响名字。优先从 3(神话/民俗/术数)、5(制度/经济)、6(科学/技术/医学)、7(工艺/媒介)、8(城市/日常)、9(心理/哲学)、11(成套符号)里选 1–2 个高相关来源。',
|
|
1394
|
+
'每个来源必须能提供具体机制/物象/代价;只能给氛围或名词的不算。找不到高相关来源时,derivation 标 `原创/综合`,不要硬凑。',
|
|
1395
|
+
'不要求来源覆盖数量;宁少勿凑。',
|
|
1396
|
+
);
|
|
1397
|
+
return lines.join('\n');
|
|
1398
|
+
}
|
|
1399
|
+
|
|
1376
1400
|
export async function runGenerationWithPlan(ctx, invocation, session, taskList, opts = {}) {
|
|
1377
1401
|
const root = opts.root || workspaceOf(session);
|
|
1378
1402
|
const team = readTeamConfig(root);
|
|
@@ -1617,7 +1641,7 @@ export async function runGenerationWithPlan(ctx, invocation, session, taskList,
|
|
|
1617
1641
|
let fatal = false;
|
|
1618
1642
|
let kindFailureStreak = 0;
|
|
1619
1643
|
|
|
1620
|
-
const validateBatch = async (file, item, groupId) => {
|
|
1644
|
+
const validateBatch = async (file, item, groupId, options = {}) => {
|
|
1621
1645
|
const checked = await checkFile(file);
|
|
1622
1646
|
if (checked.code !== 0) return { ok: false, detail: scriptDetail(checked) };
|
|
1623
1647
|
const genreProblem = genreCoverageProblem(file, genres);
|
|
@@ -1638,10 +1662,26 @@ export async function runGenerationWithPlan(ctx, invocation, session, taskList,
|
|
|
1638
1662
|
});
|
|
1639
1663
|
if (metadataProblem) return { ok: false, detail: metadataProblem };
|
|
1640
1664
|
const records = readJsonlRecords(file);
|
|
1665
|
+
if (options.expectedNames) {
|
|
1666
|
+
const expected = options.expectedNames;
|
|
1667
|
+
const actual = new Set(records.map((record) => String(record.name || '').trim()).filter(Boolean));
|
|
1668
|
+
const missing = [...expected].filter((name) => !actual.has(name));
|
|
1669
|
+
const extra = [...actual].filter((name) => !expected.has(name));
|
|
1670
|
+
if (missing.length || extra.length) {
|
|
1671
|
+
const parts = [];
|
|
1672
|
+
if (missing.length) parts.push('缺少 ' + missing.join('、'));
|
|
1673
|
+
if (extra.length) parts.push('多出 ' + extra.join('、'));
|
|
1674
|
+
return {
|
|
1675
|
+
ok: false,
|
|
1676
|
+
detail: '名字已锁定,必须原样使用:' + parts.join(';')
|
|
1677
|
+
+ '。锁定名单:' + [...expected].join('、'),
|
|
1678
|
+
};
|
|
1679
|
+
}
|
|
1680
|
+
}
|
|
1641
1681
|
return { ok: true, records };
|
|
1642
1682
|
};
|
|
1643
1683
|
|
|
1644
|
-
const filterTeamBatch = (file, item, groupId) => {
|
|
1684
|
+
const filterTeamBatch = (file, item, groupId, options = {}) => {
|
|
1645
1685
|
const records = readJsonlRecords(file);
|
|
1646
1686
|
const kept = [];
|
|
1647
1687
|
const dropped = [];
|
|
@@ -1660,6 +1700,7 @@ export async function runGenerationWithPlan(ctx, invocation, session, taskList,
|
|
|
1660
1700
|
const expectedGroup = item.group_id || groupId;
|
|
1661
1701
|
if (expectedGroup && record.group_id !== expectedGroup) reasons.push('group_id');
|
|
1662
1702
|
if (typeof record.name !== 'string' || !record.name.trim()) reasons.push('name');
|
|
1703
|
+
if (options.expectedNames && !options.expectedNames.has(String(record.name || '').trim())) reasons.push('locked-name');
|
|
1663
1704
|
if (reasons.length) dropped.push((record.name || '未命名') + '(' + reasons.join('、') + ')');
|
|
1664
1705
|
else kept.push(record);
|
|
1665
1706
|
}
|
|
@@ -1735,7 +1776,7 @@ export async function runGenerationWithPlan(ctx, invocation, session, taskList,
|
|
|
1735
1776
|
String(index + 1).padStart(3, '0') + '_' + (item.kind || item.mode) + '_' + String(batchNo).padStart(2, '0') + '.jsonl',
|
|
1736
1777
|
);
|
|
1737
1778
|
const includeBase = batchNo === 1 || batchNo % FULL_PROMPT_EVERY === 1;
|
|
1738
|
-
|
|
1779
|
+
let manualBlock = item.mode === 'kind'
|
|
1739
1780
|
? renderManualBlock({
|
|
1740
1781
|
kind: item.kind,
|
|
1741
1782
|
subkind: item.subkind || '',
|
|
@@ -1745,6 +1786,51 @@ export async function runGenerationWithPlan(ctx, invocation, session, taskList,
|
|
|
1745
1786
|
})
|
|
1746
1787
|
: '';
|
|
1747
1788
|
const useTeam = team.enabled && item.mode === 'kind';
|
|
1789
|
+
const nameStage = team.nameStage || {};
|
|
1790
|
+
const useNameStage = useTeam
|
|
1791
|
+
&& nameStage.enabled !== false
|
|
1792
|
+
&& Array.isArray(nameStage.applyKinds)
|
|
1793
|
+
&& nameStage.applyKinds.includes(item.kind);
|
|
1794
|
+
let lockedNames = [];
|
|
1795
|
+
let lockedNameSet = null;
|
|
1796
|
+
if (useNameStage) {
|
|
1797
|
+
const nameOut = await runNameStage({
|
|
1798
|
+
ctx,
|
|
1799
|
+
parent: invocation.agent,
|
|
1800
|
+
root,
|
|
1801
|
+
runDir,
|
|
1802
|
+
team,
|
|
1803
|
+
signal: invocation.signal,
|
|
1804
|
+
worldBlock,
|
|
1805
|
+
styleSummary,
|
|
1806
|
+
genres,
|
|
1807
|
+
kind: item.kind,
|
|
1808
|
+
subkind: item.subkind || '',
|
|
1809
|
+
existingFile: existing.file,
|
|
1810
|
+
extraNames: rememberedNames(item),
|
|
1811
|
+
batchId,
|
|
1812
|
+
batchNo,
|
|
1813
|
+
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))),
|
|
1815
|
+
anchorNames: item.generated === 0 ? (Array.isArray(nameStage.anchorNames) ? nameStage.anchorNames : []) : [],
|
|
1816
|
+
});
|
|
1817
|
+
if (!nameOut.ok) {
|
|
1818
|
+
fatal = true;
|
|
1819
|
+
stopReason = 'name-stage 失败:' + nameOut.error;
|
|
1820
|
+
lastReason = stopReason;
|
|
1821
|
+
break;
|
|
1822
|
+
}
|
|
1823
|
+
lockedNames = nameOut.names;
|
|
1824
|
+
lockedNameSet = new Set(lockedNames.map((row) => row.name));
|
|
1825
|
+
manualBlock = renderManualBlock({
|
|
1826
|
+
kind: item.kind,
|
|
1827
|
+
subkind: item.subkind || '',
|
|
1828
|
+
genres,
|
|
1829
|
+
seed: `${batchId}:${item.key || item.kind}:${batchNo}`,
|
|
1830
|
+
compact: false,
|
|
1831
|
+
lockedNames: true,
|
|
1832
|
+
}) + '\n\n' + renderLockedNamesBlock(lockedNames);
|
|
1833
|
+
}
|
|
1748
1834
|
let attemptDetail = '';
|
|
1749
1835
|
let accepted = false;
|
|
1750
1836
|
|
|
@@ -1857,8 +1943,8 @@ export async function runGenerationWithPlan(ctx, invocation, session, taskList,
|
|
|
1857
1943
|
manualBlock,
|
|
1858
1944
|
team,
|
|
1859
1945
|
signal: invocation.signal,
|
|
1860
|
-
validate: (candidate) => validateBatch(candidate, item, groupId),
|
|
1861
|
-
filter: (candidate) => filterTeamBatch(candidate, item, groupId),
|
|
1946
|
+
validate: (candidate) => validateBatch(candidate, item, groupId, { expectedNames: lockedNameSet }),
|
|
1947
|
+
filter: (candidate) => filterTeamBatch(candidate, item, groupId, { expectedNames: lockedNameSet }),
|
|
1862
1948
|
batchLabel: item.kind + (item.subkind ? '_' + item.subkind : ''),
|
|
1863
1949
|
batchId,
|
|
1864
1950
|
batchNo,
|
|
@@ -1882,7 +1968,7 @@ export async function runGenerationWithPlan(ctx, invocation, session, taskList,
|
|
|
1882
1968
|
}
|
|
1883
1969
|
if (!waited.ok && waited.code === 'TIMEOUT') {
|
|
1884
1970
|
if (fs.existsSync(file)) {
|
|
1885
|
-
const checked = await validateBatch(file, item, groupId);
|
|
1971
|
+
const checked = await validateBatch(file, item, groupId, { expectedNames: lockedNameSet });
|
|
1886
1972
|
if (checked.ok) {
|
|
1887
1973
|
const acceptedResult = await acceptBatch(file, item, groupId);
|
|
1888
1974
|
if (acceptedResult.fatal) {
|
|
@@ -1925,12 +2011,12 @@ export async function runGenerationWithPlan(ctx, invocation, session, taskList,
|
|
|
1925
2011
|
}
|
|
1926
2012
|
}
|
|
1927
2013
|
|
|
1928
|
-
let checked = await validateBatch(file, item, groupId);
|
|
2014
|
+
let checked = await validateBatch(file, item, groupId, { expectedNames: lockedNameSet });
|
|
1929
2015
|
if (!checked.ok && useTeam) {
|
|
1930
|
-
const filtered = filterTeamBatch(file, item, groupId);
|
|
2016
|
+
const filtered = filterTeamBatch(file, item, groupId, { expectedNames: lockedNameSet });
|
|
1931
2017
|
if (filtered.dropped > 0) {
|
|
1932
2018
|
attemptDetail = 'Team 过滤 ' + filtered.dropped + ' 条未过校验:' + filtered.detail;
|
|
1933
|
-
if (filtered.ok) checked = await validateBatch(file, item, groupId);
|
|
2019
|
+
if (filtered.ok) checked = await validateBatch(file, item, groupId, { expectedNames: lockedNameSet });
|
|
1934
2020
|
}
|
|
1935
2021
|
}
|
|
1936
2022
|
if (!checked.ok) {
|
|
@@ -2104,6 +2190,8 @@ function teamText(root, config) {
|
|
|
2104
2190
|
`最多审查轮次:${config.maxReviewRounds}`,
|
|
2105
2191
|
`最多 agent 调用:${config.maxTotalCalls}`,
|
|
2106
2192
|
`5 轮未通过交裁判:${config.judgeOnMaxRounds ? '是' : '否'}`,
|
|
2193
|
+
`ability_name 名字阶段:${config.nameStage?.enabled ? '开启' : '关闭'}(池 ${config.nameStage?.poolSize || 80} / 留 ${config.nameStage?.keep || 20} / 裁判 ${config.nameStage?.judges || 3})`,
|
|
2194
|
+
`锚点名字:${(config.nameStage?.anchorNames || []).join('、') || '(无)'}`,
|
|
2107
2195
|
'',
|
|
2108
2196
|
`配置文件:${teamConfigPath(root)}`,
|
|
2109
2197
|
'',
|
|
@@ -2161,7 +2249,7 @@ async function handleTeamCommand(ctx, session, tokens) {
|
|
|
2161
2249
|
const key = String(tokens[1] || '').toLowerCase();
|
|
2162
2250
|
const value = tokens.slice(2);
|
|
2163
2251
|
if (!key) {
|
|
2164
|
-
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>');
|
|
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>');
|
|
2165
2253
|
}
|
|
2166
2254
|
if (key === 'a' || key === 'b' || key === 'judge') {
|
|
2167
2255
|
if (value.length < 2) {
|
|
@@ -2222,6 +2310,39 @@ async function handleTeamCommand(ctx, session, tokens) {
|
|
|
2222
2310
|
writeTeamConfig(root, config);
|
|
2223
2311
|
return notify(session, 'success', `✅ 5 轮未通过交裁判:${config.judgeOnMaxRounds ? '是' : '否'}。`);
|
|
2224
2312
|
}
|
|
2313
|
+
if (key === 'name-stage') {
|
|
2314
|
+
const on = String(value[0] || '').toLowerCase();
|
|
2315
|
+
if (on !== 'on' && on !== 'off') return notify(session, 'error', 'name-stage 只能是 on 或 off。');
|
|
2316
|
+
config.nameStage.enabled = on === 'on';
|
|
2317
|
+
writeTeamConfig(root, config);
|
|
2318
|
+
return notify(session, 'success', `✅ ability_name 名字阶段已${config.nameStage.enabled ? '开启' : '关闭'}。`);
|
|
2319
|
+
}
|
|
2320
|
+
if (key === 'anchors') {
|
|
2321
|
+
config.nameStage.anchorNames = value.join(' ').split(/[,,\s]+/).map((item) => item.trim()).filter(Boolean);
|
|
2322
|
+
writeTeamConfig(root, config);
|
|
2323
|
+
return notify(session, 'success', `✅ 已设置 ${config.nameStage.anchorNames.length} 个锚点名字。`);
|
|
2324
|
+
}
|
|
2325
|
+
if (key === 'rejected') {
|
|
2326
|
+
config.nameStage.rejectedNames = value.join(' ').split(/[,,\s]+/).map((item) => item.trim()).filter(Boolean);
|
|
2327
|
+
writeTeamConfig(root, config);
|
|
2328
|
+
return notify(session, 'success', `✅ 已设置 ${config.nameStage.rejectedNames.length} 个反例名字。`);
|
|
2329
|
+
}
|
|
2330
|
+
if (key === 'name-pool' || key === 'name-keep' || key === 'name-judges') {
|
|
2331
|
+
const n = Number.parseInt(value[0], 10);
|
|
2332
|
+
if (!Number.isFinite(n) || n < 1) return notify(session, 'error', key + ' 必须是正整数。');
|
|
2333
|
+
if (key === 'name-pool') {
|
|
2334
|
+
if (n < 20 || n > 200) return notify(session, 'error', 'name-pool 必须是 20–200。');
|
|
2335
|
+
config.nameStage.poolSize = n;
|
|
2336
|
+
} else if (key === 'name-keep') {
|
|
2337
|
+
if (n < 1 || n > 100) return notify(session, 'error', 'name-keep 必须是 1–100。');
|
|
2338
|
+
config.nameStage.keep = n;
|
|
2339
|
+
} else {
|
|
2340
|
+
if (n < 1 || n > 5) return notify(session, 'error', 'name-judges 必须是 1–5。');
|
|
2341
|
+
config.nameStage.judges = n;
|
|
2342
|
+
}
|
|
2343
|
+
writeTeamConfig(root, config);
|
|
2344
|
+
return notify(session, 'success', `✅ ${key} 已设为 ${n}。`);
|
|
2345
|
+
}
|
|
2225
2346
|
return notify(session, 'error', `未知 team 设置:${key}`);
|
|
2226
2347
|
}
|
|
2227
2348
|
return notify(session, 'error', '用法:/fancy-material team show|models [provider]|on|off|reset|set ...');
|
|
@@ -121,13 +121,14 @@ export function selectFailures({ kind = '', limit = 2 } = {}) {
|
|
|
121
121
|
* @param options.seed - stable batch seed for case/pattern rotation
|
|
122
122
|
* @param options.compact - true after the first batch to reduce prompt size
|
|
123
123
|
*/
|
|
124
|
-
export function renderManualBlock({ kind = '', subkind = '', genres = [], seed = '', compact = false } = {}) {
|
|
124
|
+
export function renderManualBlock({ kind = '', subkind = '', genres = [], seed = '', compact = false, lockedNames = false } = {}) {
|
|
125
125
|
const core = readFile(path.join(MANUAL_DIR, '00-core.md'));
|
|
126
126
|
const carrier = compact ? '' : readFile(path.join(MANUAL_DIR, '01-carrier.md'));
|
|
127
|
-
const naming = compact ? '' : readFile(path.join(MANUAL_DIR, '04-naming.md'));
|
|
127
|
+
const naming = (compact || lockedNames) ? '' : readFile(path.join(MANUAL_DIR, '04-naming.md'));
|
|
128
128
|
const surprise = compact ? '' : readFile(path.join(MANUAL_DIR, '07-surprise.md'));
|
|
129
129
|
const method = readFile(path.join(MANUAL_DIR, '08-naming-method.md'));
|
|
130
|
-
|
|
130
|
+
const locked = lockedNames ? readFile(path.join(MANUAL_DIR, '09-name-locked.md')) : '';
|
|
131
|
+
if (!core && !carrier && !naming && !surprise && !method && !locked) return '';
|
|
131
132
|
|
|
132
133
|
const lines = [
|
|
133
134
|
'# 创作手册(本批必读)',
|
|
@@ -140,5 +141,6 @@ export function renderManualBlock({ kind = '', subkind = '', genres = [], seed =
|
|
|
140
141
|
if (naming) lines.push(naming, '');
|
|
141
142
|
if (surprise) lines.push(surprise, '');
|
|
142
143
|
if (method) lines.push(method, '');
|
|
144
|
+
if (locked) lines.push(locked, '');
|
|
143
145
|
return lines.join('\n').trim();
|
|
144
146
|
}
|
|
@@ -0,0 +1,490 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ability-name stage: free name pool -> name-only screening -> selected names.
|
|
3
|
+
*
|
|
4
|
+
* This stage intentionally never reads note/derivation/source fields. The
|
|
5
|
+
* material stage receives the selected names and writes the actual settings.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import fs from 'node:fs';
|
|
9
|
+
import path from 'node:path';
|
|
10
|
+
import { callTeamAgent } from './team.js';
|
|
11
|
+
|
|
12
|
+
const NAME_SCREEN_SCHEMA = {
|
|
13
|
+
type: 'object',
|
|
14
|
+
properties: {
|
|
15
|
+
top: { type: 'array', items: { type: 'string' } },
|
|
16
|
+
},
|
|
17
|
+
required: ['top'],
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const NAME_SCORE_SCHEMA = {
|
|
21
|
+
type: 'object',
|
|
22
|
+
properties: {
|
|
23
|
+
scores: {
|
|
24
|
+
type: 'array',
|
|
25
|
+
items: {
|
|
26
|
+
type: 'object',
|
|
27
|
+
properties: {
|
|
28
|
+
name: { type: 'string' },
|
|
29
|
+
hook: { type: 'number' },
|
|
30
|
+
distinct: { type: 'number' },
|
|
31
|
+
image: { type: 'number' },
|
|
32
|
+
},
|
|
33
|
+
required: ['name', 'hook', 'distinct', 'image'],
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
required: ['scores'],
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const BANNED_NAME_PARTS = [
|
|
41
|
+
'日历', '邮戳', '票根', '病历', '手术', '门牌', '声带', '安检', '围墙',
|
|
42
|
+
'唢呐', '井盖', '退货', '倒期', '照号', '跳号', '换牙',
|
|
43
|
+
];
|
|
44
|
+
|
|
45
|
+
function readJsonl(file) {
|
|
46
|
+
let text;
|
|
47
|
+
try { text = fs.readFileSync(file, 'utf8'); } catch { return []; }
|
|
48
|
+
const rows = [];
|
|
49
|
+
for (const line of text.split(/\r?\n/)) {
|
|
50
|
+
if (!line.trim()) continue;
|
|
51
|
+
try {
|
|
52
|
+
const value = JSON.parse(line);
|
|
53
|
+
if (value && typeof value === 'object' && !Array.isArray(value)) rows.push(value);
|
|
54
|
+
} catch { /* skip malformed line */ }
|
|
55
|
+
}
|
|
56
|
+
return rows;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function writeJsonl(file, rows) {
|
|
60
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
61
|
+
fs.writeFileSync(file, rows.map((row) => JSON.stringify(row)).join('\n') + (rows.length ? '\n' : ''), 'utf8');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function writeJson(file, value) {
|
|
65
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
66
|
+
fs.writeFileSync(file, JSON.stringify(value, null, 2) + '\n', 'utf8');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function shuffle(list, seed) {
|
|
70
|
+
const out = [...list];
|
|
71
|
+
let state = (Number(seed) || 1) >>> 0;
|
|
72
|
+
const next = () => {
|
|
73
|
+
state = (state * 1664525 + 1013904223) >>> 0;
|
|
74
|
+
return state;
|
|
75
|
+
};
|
|
76
|
+
for (let i = out.length - 1; i > 0; i -= 1) {
|
|
77
|
+
const j = next() % (i + 1);
|
|
78
|
+
[out[i], out[j]] = [out[j], out[i]];
|
|
79
|
+
}
|
|
80
|
+
return out;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function charLength(value) {
|
|
84
|
+
return Array.from(String(value || '')).length;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function normalizeName(value) {
|
|
88
|
+
return String(value || '').replace(/\s+/g, '').trim();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function readExistingNames(file) {
|
|
92
|
+
const names = new Set();
|
|
93
|
+
for (const row of readJsonl(file)) {
|
|
94
|
+
const name = normalizeName(row.name);
|
|
95
|
+
if (name) names.add(name);
|
|
96
|
+
}
|
|
97
|
+
return names;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function validName(name, { anchors, rejected, existing, extra }) {
|
|
101
|
+
if (!name) return false;
|
|
102
|
+
const length = charLength(name);
|
|
103
|
+
if (length < 3 || length > 5) return false;
|
|
104
|
+
if (!/^[\u4e00-\u9fa5]+$/.test(name)) return false;
|
|
105
|
+
if (anchors.has(name) || rejected.has(name) || existing.has(name) || extra.has(name)) return false;
|
|
106
|
+
if (BANNED_NAME_PARTS.some((part) => name.includes(part))) return false;
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function buildNamePrompt({
|
|
111
|
+
role,
|
|
112
|
+
targetFile,
|
|
113
|
+
worldBlock,
|
|
114
|
+
styleSummary,
|
|
115
|
+
genres,
|
|
116
|
+
kind,
|
|
117
|
+
subkind,
|
|
118
|
+
count,
|
|
119
|
+
anchors,
|
|
120
|
+
rejected,
|
|
121
|
+
}) {
|
|
122
|
+
const lines = [];
|
|
123
|
+
lines.push(`你是能力名生成者 ${role}。本阶段只生成名字池,不写 note、不写 derivation、不写来源。`);
|
|
124
|
+
lines.push('');
|
|
125
|
+
lines.push('# 世界');
|
|
126
|
+
lines.push(worldBlock || '香火有主:城市靠注册神维持规则,神靠居民的愿活着;借神权必须替神完成一桩活人的愿。');
|
|
127
|
+
lines.push('');
|
|
128
|
+
if (styleSummary) {
|
|
129
|
+
lines.push('# 写法');
|
|
130
|
+
lines.push(styleSummary);
|
|
131
|
+
lines.push('');
|
|
132
|
+
}
|
|
133
|
+
lines.push('# 任务');
|
|
134
|
+
lines.push(`生成 ${count} 个 \`${kind}\`${subkind ? `(${subkind})` : ''} 候选名。`);
|
|
135
|
+
lines.push(`题材:${(genres || []).join('、') || '按世界设定'}。`);
|
|
136
|
+
lines.push('');
|
|
137
|
+
lines.push('不要按题材/子域分类,不要列内容清单,不要按公式逐条填。直接从“物象”出发。');
|
|
138
|
+
lines.push('');
|
|
139
|
+
lines.push('# 物象标准');
|
|
140
|
+
lines.push('不是功能对象,而是被选中的细节:带质感、痕迹、仪式、禁忌、记忆或反常的具体形象。');
|
|
141
|
+
lines.push('- 日历是对象;忌日那页、撕不掉的旧历是物象。');
|
|
142
|
+
lines.push('- 邮戳是对象;退信戳、盖糊名字的戳是物象。');
|
|
143
|
+
lines.push('- 棺材是对象;空棺是物象。');
|
|
144
|
+
lines.push('- 面具是对象;傩面是物象。');
|
|
145
|
+
lines.push('- 下水道是对象;暗渠是物象。');
|
|
146
|
+
lines.push('');
|
|
147
|
+
lines.push('名字结构:**物象 + 强动词 + 神圣/身份对象或巨大后果**。');
|
|
148
|
+
lines.push('名字单看就要有“这怎么可能/代价是什么”的张力;不读 note 也能猜出能力方向。');
|
|
149
|
+
lines.push('');
|
|
150
|
+
if (anchors.length) {
|
|
151
|
+
lines.push('# 用户认可的名字(只学结构,不要直接复用)');
|
|
152
|
+
lines.push(anchors.join('、'));
|
|
153
|
+
lines.push('');
|
|
154
|
+
}
|
|
155
|
+
if (rejected.length) {
|
|
156
|
+
lines.push('# 用户否掉的名字(不要复用,也不要换字复用结构)');
|
|
157
|
+
lines.push(rejected.join('、'));
|
|
158
|
+
lines.push('');
|
|
159
|
+
}
|
|
160
|
+
lines.push('# 硬规则');
|
|
161
|
+
lines.push('- 3–5 个汉字,4 字优先;不要“的”字句。');
|
|
162
|
+
lines.push('- 不要功能对象名、流程名、业务名:日历、邮戳、票根、病历、手术刀、门牌、声带、安检门、围墙、唢呐、井盖、退货、倒期、照号、跳号、换牙。');
|
|
163
|
+
lines.push('- 不要大路货:元素+掌控、绝对+防御、超级+速度、记忆+修改、隐身、读心、时间暂停、影子换位、分身、瞬移、预知、不死、言出法随。');
|
|
164
|
+
lines.push('- 不要复用当前素材库已有名字。生成时不要读 note/derivation,不要写设定解释。');
|
|
165
|
+
lines.push('- 同批注意物象差异,不要连续用同一个中心物象。');
|
|
166
|
+
lines.push('');
|
|
167
|
+
lines.push('# 输出');
|
|
168
|
+
lines.push(`写到 \`${targetFile}\`。`);
|
|
169
|
+
lines.push('每行一个 JSON 对象:');
|
|
170
|
+
lines.push('{"name":"四字名","promise":"一句话能力承诺:角色可以做什么违反常识的事,但必须付出什么代价/限制","image":"名字里的物象是什么,为什么它是物象不是对象","why":"为什么这个名字单看就有 hook"}');
|
|
171
|
+
lines.push('');
|
|
172
|
+
lines.push('只写 JSONL,不要 Markdown 围栏,不要解释。完成后只回复:已写入目标文件。');
|
|
173
|
+
return lines.join('\n');
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function buildScreenPrompt(names) {
|
|
177
|
+
const list = names.map((name, index) => `${index + 1}. ${name}`).join('\n');
|
|
178
|
+
return [
|
|
179
|
+
'你是能力名盲评裁判。下面只有名字,没有 note、没有设定、没有来源。',
|
|
180
|
+
'',
|
|
181
|
+
'只按名字本身,选出整体潜力最高的前若干个。标准:',
|
|
182
|
+
'- 第一眼 hook:想不想知道这个能力是什么',
|
|
183
|
+
'- 物象感:名字里有没有一个带质感/痕迹/仪式/禁忌的具体细节',
|
|
184
|
+
'- 独特:不像大路货,也不像流程名',
|
|
185
|
+
'',
|
|
186
|
+
list,
|
|
187
|
+
'',
|
|
188
|
+
'只返回 JSON:{"top":["名字1","名字2",...]}。不要解释,不要改写名字。',
|
|
189
|
+
].join('\n');
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function buildScorePrompt(names) {
|
|
193
|
+
const list = names.map((name, index) => `${index + 1}. ${name}`).join('\n');
|
|
194
|
+
return [
|
|
195
|
+
'你是能力名盲评裁判。下面只有名字,没有 note、没有设定、没有来源。',
|
|
196
|
+
'',
|
|
197
|
+
'对每个名字按 1–5 分评分(允许 0.5):',
|
|
198
|
+
'- hook:第一眼吸引力。5 = 一眼记住;4.5 = 很强;4 = 好但眼熟;3 = 普通。',
|
|
199
|
+
'- distinct:独特性。5 = 不常见且不可替换;4.5 = 有明显辨识度;4 = 同类里常见。',
|
|
200
|
+
'- image:物象感。5 = 有一个带质感/痕迹/仪式/禁忌的具体物象;4 = 有画面但偏普通;3 = 功能对象或流程词。',
|
|
201
|
+
'',
|
|
202
|
+
list,
|
|
203
|
+
'',
|
|
204
|
+
'只返回 JSON:{"scores":[{"name":"名字","hook":0,"distinct":0,"image":0}]}。不要解释,不要改写名字。',
|
|
205
|
+
].join('\n');
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function average(values) {
|
|
209
|
+
const list = values.filter((value) => Number.isFinite(value));
|
|
210
|
+
if (!list.length) return 0;
|
|
211
|
+
return list.reduce((sum, value) => sum + value, 0) / list.length;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export async function runNameStage({
|
|
215
|
+
ctx,
|
|
216
|
+
parent,
|
|
217
|
+
root,
|
|
218
|
+
runDir,
|
|
219
|
+
team,
|
|
220
|
+
signal,
|
|
221
|
+
worldBlock = '',
|
|
222
|
+
styleSummary = '',
|
|
223
|
+
genres = [],
|
|
224
|
+
kind = '',
|
|
225
|
+
subkind = '',
|
|
226
|
+
existingFile = '',
|
|
227
|
+
extraNames = [],
|
|
228
|
+
batchId = '',
|
|
229
|
+
batchNo = 1,
|
|
230
|
+
keep: keepOverride = 0,
|
|
231
|
+
poolSize: poolOverride = 0,
|
|
232
|
+
anchorNames: anchorNamesOverride = undefined,
|
|
233
|
+
}) {
|
|
234
|
+
const config = team && team.nameStage ? team.nameStage : {};
|
|
235
|
+
const poolSize = Math.max(20, Number(poolOverride) || Number(config.poolSize) || 80);
|
|
236
|
+
const keep = Math.max(1, Number(keepOverride) || Number(config.keep) || 20);
|
|
237
|
+
const screeningTop = Math.max(10, Number(config.screeningTop) || 30);
|
|
238
|
+
const judgeCount = Math.max(1, Math.min(5, Number(config.judges) || 3));
|
|
239
|
+
const rawAnchors = Array.isArray(anchorNamesOverride)
|
|
240
|
+
? anchorNamesOverride
|
|
241
|
+
: (Array.isArray(config.anchorNames) ? config.anchorNames : []);
|
|
242
|
+
const anchorList = rawAnchors.map(normalizeName).filter(Boolean);
|
|
243
|
+
const anchors = [...new Set(anchorList)].slice(0, keep);
|
|
244
|
+
const rejectedList = Array.isArray(config.rejectedNames) ? config.rejectedNames.map(normalizeName).filter(Boolean) : [];
|
|
245
|
+
const anchorSet = new Set(anchors);
|
|
246
|
+
const rejectedSet = new Set(rejectedList);
|
|
247
|
+
const existing = readExistingNames(existingFile);
|
|
248
|
+
const extra = new Set((Array.isArray(extraNames) ? extraNames : []).map(normalizeName).filter(Boolean));
|
|
249
|
+
const requiredNew = Math.max(0, keep - anchors.length);
|
|
250
|
+
const startedAt = new Date().toISOString();
|
|
251
|
+
const perSide = Math.ceil(poolSize / 2);
|
|
252
|
+
const aFile = path.join(runDir, 'name-a.jsonl');
|
|
253
|
+
const bFile = path.join(runDir, 'name-b.jsonl');
|
|
254
|
+
const poolFile = path.join(runDir, 'name-pool.jsonl');
|
|
255
|
+
const selectedFile = path.join(runDir, 'names-selected.jsonl');
|
|
256
|
+
const metaFile = path.join(runDir, 'name-stage-meta.json');
|
|
257
|
+
const warnings = [];
|
|
258
|
+
let calls = 0;
|
|
259
|
+
|
|
260
|
+
if (!team || !team.generatorA || !team.generatorB || !team.judge) {
|
|
261
|
+
return { ok: false, error: 'name-stage 需要 generatorA / generatorB / judge 三条模型路由。' };
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const promptA = buildNamePrompt({
|
|
265
|
+
role: 'A',
|
|
266
|
+
targetFile: aFile,
|
|
267
|
+
worldBlock,
|
|
268
|
+
styleSummary,
|
|
269
|
+
genres,
|
|
270
|
+
kind,
|
|
271
|
+
subkind,
|
|
272
|
+
count: perSide,
|
|
273
|
+
anchors,
|
|
274
|
+
rejected: rejectedList,
|
|
275
|
+
});
|
|
276
|
+
const promptB = buildNamePrompt({
|
|
277
|
+
role: 'B',
|
|
278
|
+
targetFile: bFile,
|
|
279
|
+
worldBlock,
|
|
280
|
+
styleSummary,
|
|
281
|
+
genres,
|
|
282
|
+
kind,
|
|
283
|
+
subkind,
|
|
284
|
+
count: perSide,
|
|
285
|
+
anchors,
|
|
286
|
+
rejected: rejectedList,
|
|
287
|
+
});
|
|
288
|
+
fs.mkdirSync(runDir, { recursive: true });
|
|
289
|
+
fs.writeFileSync(path.join(runDir, 'name-prompt-a.txt'), promptA + '\n', 'utf8');
|
|
290
|
+
fs.writeFileSync(path.join(runDir, 'name-prompt-b.txt'), promptB + '\n', 'utf8');
|
|
291
|
+
for (const stale of [aFile, bFile, poolFile, selectedFile]) {
|
|
292
|
+
try { fs.unlinkSync(stale); } catch { /* first run */ }
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
const [genA, genB] = await Promise.all([
|
|
296
|
+
callTeamAgent({ ctx, parent, prompt: promptA, route: team.generatorA, label: 'name-gen-a', signal }),
|
|
297
|
+
callTeamAgent({ ctx, parent, prompt: promptB, route: team.generatorB, label: 'name-gen-b', signal }),
|
|
298
|
+
]);
|
|
299
|
+
calls += 2;
|
|
300
|
+
if (!genA.ok && !genB.ok) {
|
|
301
|
+
writeJson(metaFile, {
|
|
302
|
+
batchId, batchNo, startedAt, finishedAt: new Date().toISOString(), calls,
|
|
303
|
+
error: '两个生成者都没有完成名字池:' + (genA.error || genB.error),
|
|
304
|
+
});
|
|
305
|
+
return { ok: false, error: 'name-stage 两个生成者都失败:' + (genA.error || genB.error) };
|
|
306
|
+
}
|
|
307
|
+
if (!genA.ok) warnings.push('生成者 A 失败,只用 B 的名字池:' + genA.error);
|
|
308
|
+
if (!genB.ok) warnings.push('生成者 B 失败,只用 A 的名字池:' + genB.error);
|
|
309
|
+
|
|
310
|
+
const merged = [];
|
|
311
|
+
const seen = new Set();
|
|
312
|
+
for (const file of [aFile, bFile]) {
|
|
313
|
+
for (const row of readJsonl(file)) {
|
|
314
|
+
const name = normalizeName(row.name);
|
|
315
|
+
if (!validName(name, { anchors: anchorSet, rejected: rejectedSet, existing, extra })) continue;
|
|
316
|
+
if (seen.has(name)) continue;
|
|
317
|
+
seen.add(name);
|
|
318
|
+
merged.push({
|
|
319
|
+
name,
|
|
320
|
+
promise: String(row.promise || '').trim(),
|
|
321
|
+
image: String(row.image || '').trim(),
|
|
322
|
+
why: String(row.why || '').trim(),
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
writeJsonl(poolFile, merged);
|
|
327
|
+
if (merged.length < requiredNew) {
|
|
328
|
+
writeJson(metaFile, {
|
|
329
|
+
batchId, batchNo, startedAt, finishedAt: new Date().toISOString(), calls,
|
|
330
|
+
poolSize: merged.length, anchors: anchors.length, keep, requiredNew, warnings,
|
|
331
|
+
error: '有效名字不足:' + merged.length + ' < ' + requiredNew,
|
|
332
|
+
});
|
|
333
|
+
return { ok: false, error: 'name-stage 有效名字不足:' + merged.length + ' < ' + requiredNew };
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
const targetTop = Math.min(Math.max(screeningTop, keep), merged.length);
|
|
337
|
+
let screeningOrder = merged.map((row) => row.name);
|
|
338
|
+
if (merged.length > targetTop) {
|
|
339
|
+
const shuffled = shuffle(screeningOrder, Number(batchNo) * 7919 + 17);
|
|
340
|
+
const screened = await callTeamAgent({
|
|
341
|
+
ctx,
|
|
342
|
+
parent,
|
|
343
|
+
prompt: buildScreenPrompt(shuffled),
|
|
344
|
+
route: team.judge,
|
|
345
|
+
label: 'name-screen',
|
|
346
|
+
schema: NAME_SCREEN_SCHEMA,
|
|
347
|
+
signal,
|
|
348
|
+
});
|
|
349
|
+
calls += 1;
|
|
350
|
+
if (screened.ok && screened.value && Array.isArray(screened.value.top)) {
|
|
351
|
+
const poolSet = new Set(merged.map((row) => row.name));
|
|
352
|
+
const picked = [];
|
|
353
|
+
for (const raw of screened.value.top) {
|
|
354
|
+
const name = normalizeName(raw);
|
|
355
|
+
if (poolSet.has(name) && !picked.includes(name)) picked.push(name);
|
|
356
|
+
}
|
|
357
|
+
for (const name of screeningOrder) {
|
|
358
|
+
if (picked.length >= targetTop) break;
|
|
359
|
+
if (!picked.includes(name)) picked.push(name);
|
|
360
|
+
}
|
|
361
|
+
screeningOrder = picked;
|
|
362
|
+
} else {
|
|
363
|
+
warnings.push('初筛裁判失败,按生成顺序取前 ' + targetTop + ':' + (screened.error || '无结果'));
|
|
364
|
+
screeningOrder = screeningOrder.slice(0, targetTop);
|
|
365
|
+
}
|
|
366
|
+
} else {
|
|
367
|
+
screeningOrder = screeningOrder.slice(0, targetTop);
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
const panelNames = screeningOrder.slice(0, targetTop);
|
|
371
|
+
const scoreMap = new Map();
|
|
372
|
+
const panelResults = await Promise.all(
|
|
373
|
+
Array.from({ length: judgeCount }, (_, index) => {
|
|
374
|
+
const shuffled = shuffle(panelNames, Number(batchNo) * 104729 + index * 97 + 31);
|
|
375
|
+
return callTeamAgent({
|
|
376
|
+
ctx,
|
|
377
|
+
parent,
|
|
378
|
+
prompt: buildScorePrompt(shuffled),
|
|
379
|
+
route: team.judge,
|
|
380
|
+
label: `name-judge-${index + 1}`,
|
|
381
|
+
schema: NAME_SCORE_SCHEMA,
|
|
382
|
+
signal,
|
|
383
|
+
});
|
|
384
|
+
}),
|
|
385
|
+
);
|
|
386
|
+
calls += judgeCount;
|
|
387
|
+
for (const result of panelResults) {
|
|
388
|
+
if (!result.ok || !result.value || !Array.isArray(result.value.scores)) {
|
|
389
|
+
warnings.push('名字评分裁判失败:' + (result.error || '无结果'));
|
|
390
|
+
continue;
|
|
391
|
+
}
|
|
392
|
+
for (const row of result.value.scores) {
|
|
393
|
+
const name = normalizeName(row.name);
|
|
394
|
+
if (!panelNames.includes(name)) continue;
|
|
395
|
+
if (!scoreMap.has(name)) scoreMap.set(name, { hook: [], distinct: [], image: [] });
|
|
396
|
+
const scores = scoreMap.get(name);
|
|
397
|
+
for (const key of ['hook', 'distinct', 'image']) {
|
|
398
|
+
const value = Number(row[key]);
|
|
399
|
+
if (Number.isFinite(value)) scores[key].push(value);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
const screeningRank = new Map(screeningOrder.map((name, index) => [name, index]));
|
|
405
|
+
const ranked = panelNames
|
|
406
|
+
.map((name) => {
|
|
407
|
+
const scores = scoreMap.get(name) || { hook: [], distinct: [], image: [] };
|
|
408
|
+
const hook = average(scores.hook);
|
|
409
|
+
const distinct = average(scores.distinct);
|
|
410
|
+
const image = average(scores.image);
|
|
411
|
+
return {
|
|
412
|
+
name,
|
|
413
|
+
hook,
|
|
414
|
+
distinct,
|
|
415
|
+
image,
|
|
416
|
+
total: hook + distinct + image,
|
|
417
|
+
rank: screeningRank.get(name) ?? 999,
|
|
418
|
+
};
|
|
419
|
+
})
|
|
420
|
+
.sort((a, b) => (b.total - a.total) || (a.rank - b.rank));
|
|
421
|
+
|
|
422
|
+
const needed = Math.max(0, keep - anchors.length);
|
|
423
|
+
const selectedNew = [];
|
|
424
|
+
for (const row of ranked) {
|
|
425
|
+
if (selectedNew.length >= needed) break;
|
|
426
|
+
if (anchorSet.has(row.name)) continue;
|
|
427
|
+
selectedNew.push(row.name);
|
|
428
|
+
}
|
|
429
|
+
if (selectedNew.length < needed) {
|
|
430
|
+
for (const name of screeningOrder) {
|
|
431
|
+
if (selectedNew.length >= needed) break;
|
|
432
|
+
if (anchorSet.has(name) || selectedNew.includes(name)) continue;
|
|
433
|
+
selectedNew.push(name);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
if (selectedNew.length < needed) {
|
|
437
|
+
for (const row of merged) {
|
|
438
|
+
if (selectedNew.length >= needed) break;
|
|
439
|
+
if (anchorSet.has(row.name) || selectedNew.includes(row.name)) continue;
|
|
440
|
+
selectedNew.push(row.name);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
const selectedNames = [...anchors, ...selectedNew].filter((name, index, list) => list.indexOf(name) === index);
|
|
445
|
+
if (selectedNames.length < keep) {
|
|
446
|
+
writeJson(metaFile, {
|
|
447
|
+
batchId, batchNo, startedAt, finishedAt: new Date().toISOString(), calls,
|
|
448
|
+
poolSize: merged.length, anchors: anchors.length, keep, screeningTop: targetTop, judges: judgeCount,
|
|
449
|
+
selected: selectedNames, warnings,
|
|
450
|
+
error: '选中的名字不足:' + selectedNames.length + ' < ' + keep,
|
|
451
|
+
});
|
|
452
|
+
return { ok: false, error: 'name-stage 选中的名字不足:' + selectedNames.length + ' < ' + keep };
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
const byName = new Map(merged.map((row) => [row.name, row]));
|
|
456
|
+
const scoreByName = new Map(ranked.map((row) => [row.name, row]));
|
|
457
|
+
const selected = selectedNames.map((name) => {
|
|
458
|
+
const row = byName.get(name) || { name, promise: '', image: '', why: '' };
|
|
459
|
+
const score = scoreByName.get(name);
|
|
460
|
+
return {
|
|
461
|
+
...row,
|
|
462
|
+
anchor: anchorSet.has(name),
|
|
463
|
+
...(score ? { score: { hook: score.hook, distinct: score.distinct, image: score.image } } : {}),
|
|
464
|
+
};
|
|
465
|
+
});
|
|
466
|
+
writeJsonl(selectedFile, selected);
|
|
467
|
+
const finishedAt = new Date().toISOString();
|
|
468
|
+
const meta = {
|
|
469
|
+
batchId,
|
|
470
|
+
batchNo,
|
|
471
|
+
startedAt,
|
|
472
|
+
finishedAt,
|
|
473
|
+
poolSize: merged.length,
|
|
474
|
+
requestedPoolSize: poolSize,
|
|
475
|
+
anchors: anchors.length,
|
|
476
|
+
rejected: rejectedList.length,
|
|
477
|
+
keep,
|
|
478
|
+
screeningTop: targetTop,
|
|
479
|
+
judges: judgeCount,
|
|
480
|
+
calls,
|
|
481
|
+
selected: selected.map((row) => row.name),
|
|
482
|
+
warnings,
|
|
483
|
+
generatorA: team.generatorA,
|
|
484
|
+
generatorB: team.generatorB,
|
|
485
|
+
judge: team.judge,
|
|
486
|
+
files: { aFile, bFile, poolFile, selectedFile },
|
|
487
|
+
};
|
|
488
|
+
writeJson(metaFile, meta);
|
|
489
|
+
return { ok: true, names: selected, meta, files: meta.files, warnings };
|
|
490
|
+
}
|
|
@@ -21,6 +21,16 @@ const DEFAULT_TEAM = Object.freeze({
|
|
|
21
21
|
generatorA: null,
|
|
22
22
|
generatorB: null,
|
|
23
23
|
judge: null,
|
|
24
|
+
nameStage: {
|
|
25
|
+
enabled: true,
|
|
26
|
+
applyKinds: ['ability_name'],
|
|
27
|
+
poolSize: 80,
|
|
28
|
+
keep: 20,
|
|
29
|
+
screeningTop: 30,
|
|
30
|
+
judges: 3,
|
|
31
|
+
anchorNames: [],
|
|
32
|
+
rejectedNames: [],
|
|
33
|
+
},
|
|
24
34
|
});
|
|
25
35
|
|
|
26
36
|
export function teamConfigPath(root) {
|
|
@@ -45,6 +55,17 @@ export function readTeamConfig(root) {
|
|
|
45
55
|
out.maxReviewRounds = clampInt(out.maxReviewRounds, 1, 10, 5);
|
|
46
56
|
out.maxTotalCalls = clampInt(out.maxTotalCalls, 6, 40, 12);
|
|
47
57
|
out.judgeOnMaxRounds = out.judgeOnMaxRounds !== false;
|
|
58
|
+
const ns = raw && raw.nameStage && typeof raw.nameStage === 'object' ? raw.nameStage : {};
|
|
59
|
+
out.nameStage = {
|
|
60
|
+
enabled: ns.enabled !== false,
|
|
61
|
+
applyKinds: stringArray(ns.applyKinds, ['ability_name']),
|
|
62
|
+
poolSize: clampInt(ns.poolSize, 20, 200, 80),
|
|
63
|
+
keep: clampInt(ns.keep, 1, 100, 20),
|
|
64
|
+
screeningTop: clampInt(ns.screeningTop, 10, 200, 30),
|
|
65
|
+
judges: clampInt(ns.judges, 1, 5, 3),
|
|
66
|
+
anchorNames: stringArray(ns.anchorNames, []),
|
|
67
|
+
rejectedNames: stringArray(ns.rejectedNames, []),
|
|
68
|
+
};
|
|
48
69
|
for (const key of ['generatorA', 'generatorB', 'judge']) out[key] = normalizeRoute(out[key]);
|
|
49
70
|
return out;
|
|
50
71
|
}
|
|
@@ -65,6 +86,11 @@ function clampInt(value, min, max, fallback) {
|
|
|
65
86
|
return Math.max(min, Math.min(max, n));
|
|
66
87
|
}
|
|
67
88
|
|
|
89
|
+
function stringArray(value, fallback) {
|
|
90
|
+
if (!Array.isArray(value)) return [...fallback];
|
|
91
|
+
return value.map((item) => String(item || '').trim()).filter(Boolean);
|
|
92
|
+
}
|
|
93
|
+
|
|
68
94
|
function normalizeRoute(value) {
|
|
69
95
|
if (!value || typeof value !== 'object') return null;
|
|
70
96
|
const provider = String(value.provider || '').trim();
|
|
@@ -441,6 +467,15 @@ async function callSubagent({ ctx, subagents, parent, prompt, route, label, sche
|
|
|
441
467
|
}
|
|
442
468
|
}
|
|
443
469
|
|
|
470
|
+
/** Public wrapper used by the name-only stage. */
|
|
471
|
+
export async function callTeamAgent({ ctx, parent, prompt, route, label, schema, signal }) {
|
|
472
|
+
const subagents = service(ctx, 'subagents');
|
|
473
|
+
if (!subagents || typeof subagents.startActivation !== 'function') {
|
|
474
|
+
return { ok: false, error: 'team 模式需要 subagents 服务,但当前 profile 没有加载 subagent。' };
|
|
475
|
+
}
|
|
476
|
+
return callSubagent({ ctx, subagents, parent, prompt, route, label, schema, signal });
|
|
477
|
+
}
|
|
478
|
+
|
|
444
479
|
const genPrompt = (promptFile, ownFile, otherFile, role) =>
|
|
445
480
|
'你是生成者 ' + role + '。先读取并严格执行 ' + promptFile + '。' +
|
|
446
481
|
'只写 ' + ownFile + ',不要修改 ' + otherFile + '。' +
|