@cloud411716/fancy-webnovel 4.30.19 → 4.30.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/package.json
CHANGED
|
@@ -122,8 +122,12 @@ function service(ctx, name) {
|
|
|
122
122
|
if (!ctx) return undefined;
|
|
123
123
|
if (typeof ctx.get === 'function') {
|
|
124
124
|
try {
|
|
125
|
-
const
|
|
126
|
-
if (
|
|
125
|
+
const active = ctx.get(name);
|
|
126
|
+
if (active !== undefined) return active;
|
|
127
|
+
} catch { /* optional service */ }
|
|
128
|
+
try {
|
|
129
|
+
const any = ctx.get(name, false);
|
|
130
|
+
if (any !== undefined) return any;
|
|
127
131
|
} catch { /* optional service */ }
|
|
128
132
|
}
|
|
129
133
|
try {
|
|
@@ -146,6 +150,11 @@ function writePromptFile(file, text) {
|
|
|
146
150
|
fs.writeFileSync(file, String(text || '').trim() + '\n', 'utf8');
|
|
147
151
|
}
|
|
148
152
|
|
|
153
|
+
function writeJsonFile(file, value) {
|
|
154
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
155
|
+
fs.writeFileSync(file, JSON.stringify(value, null, 2) + '\n', 'utf8');
|
|
156
|
+
}
|
|
157
|
+
|
|
149
158
|
const TEAM_RUBRIC = `
|
|
150
159
|
# Team 评审 rubric
|
|
151
160
|
|
|
@@ -166,14 +175,7 @@ PASS 仅当没有 blocker/major。minor 可以记录但不阻塞。
|
|
|
166
175
|
{ "verdict": "PASS" | "CHANGES", "issues": [{ "severity": "blocker|major|minor", "why": "...", "fix": "..." }] }
|
|
167
176
|
`;
|
|
168
177
|
|
|
169
|
-
|
|
170
|
-
const {
|
|
171
|
-
promptAFile, promptBFile, fileA, fileB, finalFile, rubricFile,
|
|
172
|
-
providerA, modelA, providerB, modelB, providerC, modelC,
|
|
173
|
-
maxRounds, maxCalls, reviewMode,
|
|
174
|
-
} = args
|
|
175
|
-
|
|
176
|
-
const reviewSchema = {
|
|
178
|
+
const REVIEW_SCHEMA = {
|
|
177
179
|
type: 'object',
|
|
178
180
|
properties: {
|
|
179
181
|
verdict: { type: 'string', enum: ['PASS', 'CHANGES'] },
|
|
@@ -193,9 +195,9 @@ const reviewSchema = {
|
|
|
193
195
|
},
|
|
194
196
|
required: ['verdict', 'issues'],
|
|
195
197
|
additionalProperties: false,
|
|
196
|
-
}
|
|
198
|
+
};
|
|
197
199
|
|
|
198
|
-
const
|
|
200
|
+
const RESPONSE_SCHEMA = {
|
|
199
201
|
type: 'object',
|
|
200
202
|
properties: {
|
|
201
203
|
decision: { type: 'string', enum: ['ACCEPT', 'REJECT'] },
|
|
@@ -203,9 +205,9 @@ const responseSchema = {
|
|
|
203
205
|
},
|
|
204
206
|
required: ['decision', 'reason'],
|
|
205
207
|
additionalProperties: false,
|
|
206
|
-
}
|
|
208
|
+
};
|
|
207
209
|
|
|
208
|
-
const
|
|
210
|
+
const VERDICT_SCHEMA = {
|
|
209
211
|
type: 'object',
|
|
210
212
|
properties: {
|
|
211
213
|
verdict: { type: 'string', enum: ['PASS', 'MAINTAIN'] },
|
|
@@ -213,9 +215,9 @@ const verdictSchema = {
|
|
|
213
215
|
},
|
|
214
216
|
required: ['verdict', 'reason'],
|
|
215
217
|
additionalProperties: false,
|
|
216
|
-
}
|
|
218
|
+
};
|
|
217
219
|
|
|
218
|
-
const
|
|
220
|
+
const REVISE_SCHEMA = {
|
|
219
221
|
type: 'object',
|
|
220
222
|
properties: {
|
|
221
223
|
changed: { type: 'boolean' },
|
|
@@ -223,9 +225,9 @@ const reviseSchema = {
|
|
|
223
225
|
},
|
|
224
226
|
required: ['changed', 'summary'],
|
|
225
227
|
additionalProperties: false,
|
|
226
|
-
}
|
|
228
|
+
};
|
|
227
229
|
|
|
228
|
-
const
|
|
230
|
+
const JUDGE_SCHEMA = {
|
|
229
231
|
type: 'object',
|
|
230
232
|
properties: {
|
|
231
233
|
decision: { type: 'string', enum: ['PICK_A', 'PICK_B', 'MERGE', 'REJECT'] },
|
|
@@ -233,151 +235,86 @@ const judgeSchema = {
|
|
|
233
235
|
},
|
|
234
236
|
required: ['decision', 'rationale'],
|
|
235
237
|
additionalProperties: false,
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
function textFromBlocks(blocks) {
|
|
241
|
+
return (Array.isArray(blocks) ? blocks : [])
|
|
242
|
+
.filter((block) => block && block.type === 'text')
|
|
243
|
+
.map((block) => String(block.text || ''))
|
|
244
|
+
.join('');
|
|
236
245
|
}
|
|
237
246
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
247
|
+
async function callSubagent({ subagents, parent, prompt, route, label, schema, signal }) {
|
|
248
|
+
let activation;
|
|
249
|
+
try {
|
|
250
|
+
activation = await subagents.startActivation({
|
|
251
|
+
provider: 'spawn',
|
|
252
|
+
label,
|
|
253
|
+
prompt: [{ type: 'text', text: prompt }],
|
|
254
|
+
parent,
|
|
255
|
+
signal,
|
|
256
|
+
delivery: 'caller',
|
|
257
|
+
agentOptions: { provider: route.provider, model: route.model },
|
|
258
|
+
...(schema ? { outputSchema: schema } : {}),
|
|
259
|
+
});
|
|
260
|
+
} catch (err) {
|
|
261
|
+
return { ok: false, error: err && err.message ? err.message : String(err) };
|
|
262
|
+
}
|
|
263
|
+
try {
|
|
264
|
+
const result = await activation.result;
|
|
265
|
+
if (!result || result.stopReason !== 'completed') {
|
|
266
|
+
return { ok: false, error: (result && (result.diagnostic || result.stopReason)) || '子 agent 未完成' };
|
|
267
|
+
}
|
|
268
|
+
if (schema) {
|
|
269
|
+
if (result.structured === undefined) return { ok: false, error: '子 agent 没有返回结构化结果' };
|
|
270
|
+
return { ok: true, value: result.structured };
|
|
271
|
+
}
|
|
272
|
+
return { ok: true, value: textFromBlocks(result.output) };
|
|
273
|
+
} finally {
|
|
274
|
+
try { await activation.dispose(); } catch { /* best effort */ }
|
|
275
|
+
}
|
|
244
276
|
}
|
|
245
277
|
|
|
246
278
|
const genPrompt = (promptFile, ownFile, otherFile, role) =>
|
|
247
279
|
'你是生成者 ' + role + '。先读取并严格执行 ' + promptFile + '。' +
|
|
248
280
|
'只写 ' + ownFile + ',不要修改 ' + otherFile + '。' +
|
|
249
|
-
'不要输出解释;完成后只回复:已写入 ' + ownFile
|
|
281
|
+
'不要输出解释;完成后只回复:已写入 ' + ownFile;
|
|
250
282
|
|
|
251
|
-
const reviewPrompt = (targetFile, role, round) =>
|
|
283
|
+
const reviewPrompt = (targetFile, role, round, rubricFile) =>
|
|
252
284
|
'你是审查者 ' + role + '。先读取 ' + rubricFile + ' 和 ' + targetFile + '。' +
|
|
253
285
|
'不要修改 ' + targetFile + '。这是第 ' + round + ' 轮审查。' +
|
|
254
286
|
'逐条检查,PASS 仅当没有 blocker/major。必须只返回 JSON:' +
|
|
255
|
-
'{"verdict":"PASS|CHANGES","issues":[{"severity":"blocker|major|minor","why":"...","fix":"..."}]}'
|
|
287
|
+
'{"verdict":"PASS|CHANGES","issues":[{"severity":"blocker|major|minor","why":"...","fix":"..."}]}';
|
|
256
288
|
|
|
257
289
|
const responsePrompt = (ownFile, review, role) =>
|
|
258
290
|
'你是作者 ' + role + '。读取 ' + ownFile + ' 和以下审查意见:\n' + JSON.stringify(review) +
|
|
259
291
|
'\n如果接受,返回 {"decision":"ACCEPT","reason":"..."};如果认为审查有误,返回 {"decision":"REJECT","reason":"..."}。' +
|
|
260
|
-
'不要修改文件,只返回 JSON。'
|
|
292
|
+
'不要修改文件,只返回 JSON。';
|
|
261
293
|
|
|
262
294
|
const revisePrompt = (ownFile, review, role) =>
|
|
263
295
|
'你是作者 ' + role + '。读取 ' + ownFile + ',按以下审查意见修改。' +
|
|
264
296
|
'保留已经通过的内容,只写 JSONL 到 ' + ownFile + '。\n' + JSON.stringify(review) +
|
|
265
|
-
'\n完成后只返回 {"changed":true|false,"summary":"..."}。'
|
|
297
|
+
'\n完成后只返回 {"changed":true|false,"summary":"..."}。';
|
|
266
298
|
|
|
267
299
|
const rebuttalPrompt = (targetFile, review, response, role) =>
|
|
268
300
|
'你是审查者 ' + role + '。作者对你的审查提出反驳:\n' +
|
|
269
301
|
JSON.stringify({ review, response }) +
|
|
270
302
|
'\n读取 ' + targetFile + ' 当前版本。如果反驳成立,返回 {"verdict":"PASS","reason":"..."};' +
|
|
271
|
-
'否则返回 {"verdict":"MAINTAIN","reason":"..."}。只返回 JSON。'
|
|
303
|
+
'否则返回 {"verdict":"MAINTAIN","reason":"..."}。只返回 JSON。';
|
|
272
304
|
|
|
273
|
-
const judgePrompt = (round, aPassed, bPassed, history) =>
|
|
305
|
+
const judgePrompt = (round, aPassed, bPassed, history, fileA, fileB, finalFile, rubricFile) =>
|
|
274
306
|
'你是主编。读取 ' + rubricFile + '、' + fileA + '、' + fileB + '。' +
|
|
275
307
|
'第 ' + round + ' 轮结束:A=' + (aPassed ? 'PASS' : 'OPEN') + ',B=' + (bPassed ? 'PASS' : 'OPEN') + '。' +
|
|
276
308
|
'交叉审查记录:\n' + JSON.stringify(history).slice(0, 16000) + '\n' +
|
|
277
309
|
'必须选择 PICK_A / PICK_B / MERGE / REJECT,不能和稀泥。' +
|
|
278
310
|
'如果选择 PICK_A、PICK_B 或 MERGE,把最终 JSONL 写到 ' + finalFile + '。' +
|
|
279
|
-
'返回 {"decision":"...","rationale":"..."}。'
|
|
280
|
-
|
|
281
|
-
phase('generate')
|
|
282
|
-
const generated = await parallel([
|
|
283
|
-
() => call(genPrompt(promptAFile, fileA, fileB, 'A'), {
|
|
284
|
-
provider: providerA, model: modelA, label: 'gen-a',
|
|
285
|
-
}),
|
|
286
|
-
() => call(genPrompt(promptBFile, fileB, fileA, 'B'), {
|
|
287
|
-
provider: providerB, model: modelB, label: 'gen-b',
|
|
288
|
-
}),
|
|
289
|
-
])
|
|
290
|
-
if (generated[0] === null || generated[1] === null) {
|
|
291
|
-
throw new Error('generator A or B failed')
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
let aPassed = false
|
|
295
|
-
let bPassed = false
|
|
296
|
-
let round = 0
|
|
297
|
-
const history = []
|
|
298
|
-
|
|
299
|
-
while (round < maxRounds && !(aPassed && bPassed) && calls < totalCap - 4) {
|
|
300
|
-
round += 1
|
|
301
|
-
phase('review-' + round)
|
|
302
|
-
log('cross-review round ' + round)
|
|
303
|
-
let reviewB
|
|
304
|
-
let reviewA
|
|
305
|
-
if (reviewMode === 'oneway') {
|
|
306
|
-
reviewB = await call(reviewPrompt(fileB, 'A', round), {
|
|
307
|
-
provider: providerA, model: modelA, schema: reviewSchema, label: 'review-b-' + round,
|
|
308
|
-
})
|
|
309
|
-
reviewA = { verdict: 'PASS', issues: [] }
|
|
310
|
-
} else {
|
|
311
|
-
[reviewB, reviewA] = await parallel([
|
|
312
|
-
() => call(reviewPrompt(fileB, 'A', round), {
|
|
313
|
-
provider: providerA, model: modelA, schema: reviewSchema, label: 'review-b-' + round,
|
|
314
|
-
}),
|
|
315
|
-
() => call(reviewPrompt(fileA, 'B', round), {
|
|
316
|
-
provider: providerB, model: modelB, schema: reviewSchema, label: 'review-a-' + round,
|
|
317
|
-
}),
|
|
318
|
-
])
|
|
319
|
-
}
|
|
320
|
-
history.push({ round, reviewB, reviewA })
|
|
321
|
-
|
|
322
|
-
if (!reviewB) {
|
|
323
|
-
bPassed = false
|
|
324
|
-
} else if (reviewB.verdict === 'PASS') {
|
|
325
|
-
bPassed = true
|
|
326
|
-
} else {
|
|
327
|
-
const response = await call(responsePrompt(fileB, reviewB, 'B'), {
|
|
328
|
-
provider: providerB, model: modelB, schema: responseSchema, label: 'response-b-' + round,
|
|
329
|
-
})
|
|
330
|
-
history.push({ round, responseB: response })
|
|
331
|
-
if (response && response.decision === 'ACCEPT') {
|
|
332
|
-
const revised = await call(revisePrompt(fileB, reviewB, 'B'), {
|
|
333
|
-
provider: providerB, model: modelB, schema: reviseSchema, label: 'revise-b-' + round,
|
|
334
|
-
})
|
|
335
|
-
history.push({ round, revisedB: revised })
|
|
336
|
-
bPassed = false
|
|
337
|
-
} else if (response) {
|
|
338
|
-
const decision = await call(rebuttalPrompt(fileB, reviewB, response, 'A'), {
|
|
339
|
-
provider: providerA, model: modelA, schema: verdictSchema, label: 'rebuttal-b-' + round,
|
|
340
|
-
})
|
|
341
|
-
history.push({ round, decisionB: decision })
|
|
342
|
-
bPassed = Boolean(decision && decision.verdict === 'PASS')
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
if (!reviewA) {
|
|
347
|
-
aPassed = false
|
|
348
|
-
} else if (reviewA.verdict === 'PASS') {
|
|
349
|
-
aPassed = true
|
|
350
|
-
} else {
|
|
351
|
-
const response = await call(responsePrompt(fileA, reviewA, 'A'), {
|
|
352
|
-
provider: providerB, model: modelB, schema: responseSchema, label: 'response-a-' + round,
|
|
353
|
-
})
|
|
354
|
-
history.push({ round, responseA: response })
|
|
355
|
-
if (response && response.decision === 'ACCEPT') {
|
|
356
|
-
const revised = await call(revisePrompt(fileA, reviewA, 'A'), {
|
|
357
|
-
provider: providerA, model: modelA, schema: reviseSchema, label: 'revise-a-' + round,
|
|
358
|
-
})
|
|
359
|
-
history.push({ round, revisedA: revised })
|
|
360
|
-
aPassed = false
|
|
361
|
-
} else if (response) {
|
|
362
|
-
const decision = await call(rebuttalPrompt(fileA, reviewA, response, 'B'), {
|
|
363
|
-
provider: providerB, model: modelB, schema: verdictSchema, label: 'rebuttal-a-' + round,
|
|
364
|
-
})
|
|
365
|
-
history.push({ round, decisionA: decision })
|
|
366
|
-
aPassed = Boolean(decision && decision.verdict === 'PASS')
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
log('round ' + round + ': A=' + (aPassed ? 'PASS' : 'OPEN') + ', B=' + (bPassed ? 'PASS' : 'OPEN'))
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
phase('judge')
|
|
374
|
-
const judge = await call(judgePrompt(round, aPassed, bPassed, history), {
|
|
375
|
-
provider: providerC, model: modelC, schema: judgeSchema, label: 'judge',
|
|
376
|
-
})
|
|
377
|
-
|
|
378
|
-
return { round, aPassed, bPassed, calls, judge, fileA, fileB, finalFile }
|
|
379
|
-
`;
|
|
311
|
+
'返回 {"decision":"...","rationale":"..."}。';
|
|
380
312
|
|
|
313
|
+
/**
|
|
314
|
+
* Run one batch through two generators, bounded cross-review, and a judge.
|
|
315
|
+
* Uses the host subagent service directly so the plugin does not depend on a
|
|
316
|
+
* preset-scoped workflow engine.
|
|
317
|
+
*/
|
|
381
318
|
export async function runTeamBatch({
|
|
382
319
|
ctx,
|
|
383
320
|
parent,
|
|
@@ -387,12 +324,13 @@ export async function runTeamBatch({
|
|
|
387
324
|
prompt,
|
|
388
325
|
manualBlock = '',
|
|
389
326
|
team,
|
|
327
|
+
signal,
|
|
390
328
|
batchId = '',
|
|
391
329
|
batchNo = 1,
|
|
392
330
|
}) {
|
|
393
|
-
const
|
|
394
|
-
if (!
|
|
395
|
-
return { ok: false, error: 'team 模式需要
|
|
331
|
+
const subagents = service(ctx, 'subagents');
|
|
332
|
+
if (!subagents || typeof subagents.startActivation !== 'function') {
|
|
333
|
+
return { ok: false, error: 'team 模式需要 subagents 服务,但当前 profile 没有加载 subagent。' };
|
|
396
334
|
}
|
|
397
335
|
const problem = teamConfigProblem(team);
|
|
398
336
|
if (problem) return { ok: false, error: problem };
|
|
@@ -410,61 +348,177 @@ export async function runTeamBatch({
|
|
|
410
348
|
writePromptFile(promptBFile, appendTeamRole(retargetPrompt(prompt, file, bFile), 'B', bFile, aFile));
|
|
411
349
|
writePromptFile(rubricFile, `${manualBlock || ''}\n\n${TEAM_RUBRIC}`);
|
|
412
350
|
|
|
413
|
-
let
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
modelB: team.generatorB.model,
|
|
432
|
-
providerC: team.judge.provider,
|
|
433
|
-
modelC: team.judge.model,
|
|
434
|
-
maxRounds: team.maxReviewRounds,
|
|
435
|
-
maxCalls: team.maxTotalCalls,
|
|
436
|
-
reviewMode: team.reviewMode,
|
|
437
|
-
batchId,
|
|
438
|
-
batchNo,
|
|
439
|
-
},
|
|
440
|
-
parent,
|
|
441
|
-
});
|
|
442
|
-
} catch (err) {
|
|
443
|
-
return { ok: false, error: '无法启动 team workflow:' + (err && err.message ? err.message : String(err)) };
|
|
351
|
+
let calls = 0;
|
|
352
|
+
const maxCalls = Math.max(6, Number(team.maxTotalCalls) || 12);
|
|
353
|
+
const call = async (promptText, route, label, schema) => {
|
|
354
|
+
if (calls >= maxCalls) return { ok: false, error: 'team workflow reached maxTotalCalls' };
|
|
355
|
+
calls += 1;
|
|
356
|
+
return callSubagent({ subagents, parent, prompt: promptText, route, label, schema });
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
const [genA, genB] = await Promise.all([
|
|
360
|
+
call(genPrompt(promptAFile, aFile, bFile, 'A'), team.generatorA, 'gen-a'),
|
|
361
|
+
call(genPrompt(promptBFile, bFile, aFile, 'B'), team.generatorB, 'gen-b'),
|
|
362
|
+
]);
|
|
363
|
+
if (!genA.ok) return { ok: false, error: '生成者 A 失败:' + genA.error };
|
|
364
|
+
if (!genB.ok) return { ok: false, error: '生成者 B 失败:' + genB.error };
|
|
365
|
+
for (const [label, candidate] of [['A', aFile], ['B', bFile]]) {
|
|
366
|
+
if (!fs.existsSync(candidate) || fs.statSync(candidate).size === 0) {
|
|
367
|
+
return { ok: false, error: `生成者 ${label} 没有写出文件:${candidate}` };
|
|
368
|
+
}
|
|
444
369
|
}
|
|
445
370
|
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
371
|
+
const metaFile = path.join(runDir, 'team-meta.json');
|
|
372
|
+
const reviewFile = path.join(runDir, 'team-review.json');
|
|
373
|
+
const parentSignal = signal || new AbortController().signal;
|
|
374
|
+
let aPassed = false;
|
|
375
|
+
let bPassed = false;
|
|
376
|
+
let round = 0;
|
|
377
|
+
let stopReason = '';
|
|
378
|
+
const history = [];
|
|
379
|
+
const meta = {
|
|
380
|
+
batchId,
|
|
381
|
+
batchNo,
|
|
382
|
+
startedAt: new Date().toISOString(),
|
|
383
|
+
generatorA: team.generatorA,
|
|
384
|
+
generatorB: team.generatorB,
|
|
385
|
+
judge: team.judge,
|
|
386
|
+
reviewMode: team.reviewMode,
|
|
387
|
+
maxReviewRounds: team.maxReviewRounds,
|
|
388
|
+
maxTotalCalls: maxCalls,
|
|
389
|
+
};
|
|
390
|
+
writeJsonFile(metaFile, meta);
|
|
391
|
+
|
|
392
|
+
// Keep one call in reserve for the judge. A full review-response-revision
|
|
393
|
+
// round costs up to six calls, so the budget check happens before each stage.
|
|
394
|
+
const canSpend = (n) => calls + n <= maxCalls - 1;
|
|
395
|
+
|
|
396
|
+
const saveReview = () => writeJsonFile(reviewFile, { round, aPassed, bPassed, calls, stopReason, history });
|
|
397
|
+
|
|
398
|
+
const settleSide = async (side, review, ownFile, authorRoute, reviewerRoute) => {
|
|
399
|
+
if (review.verdict === 'PASS') return { passed: true };
|
|
400
|
+
if (!canSpend(2)) {
|
|
401
|
+
stopReason = '预算不足,保留未解决意见交裁判';
|
|
402
|
+
return { passed: false };
|
|
403
|
+
}
|
|
404
|
+
const tag = side.toLowerCase();
|
|
405
|
+
const entry = history[history.length - 1];
|
|
406
|
+
const response = await call(
|
|
407
|
+
responsePrompt(ownFile, review, side),
|
|
408
|
+
authorRoute,
|
|
409
|
+
`response-${tag}-${round}`,
|
|
410
|
+
RESPONSE_SCHEMA,
|
|
411
|
+
);
|
|
412
|
+
if (!response.ok) return { error: `作者 ${side} 回应审查失败:${response.error}` };
|
|
413
|
+
entry[`response${side}`] = response.value;
|
|
414
|
+
saveReview();
|
|
415
|
+
if (response.value.decision === 'ACCEPT') {
|
|
416
|
+
const revised = await call(
|
|
417
|
+
revisePrompt(ownFile, review, side),
|
|
418
|
+
authorRoute,
|
|
419
|
+
`revise-${tag}-${round}`,
|
|
420
|
+
REVISE_SCHEMA,
|
|
421
|
+
);
|
|
422
|
+
if (!revised.ok) return { error: `作者 ${side} 修改失败:${revised.error}` };
|
|
423
|
+
entry[`revised${side}`] = revised.value;
|
|
424
|
+
saveReview();
|
|
425
|
+
return { passed: false };
|
|
426
|
+
}
|
|
427
|
+
const decision = await call(
|
|
428
|
+
rebuttalPrompt(ownFile, review, response.value, side === 'A' ? 'B' : 'A'),
|
|
429
|
+
reviewerRoute,
|
|
430
|
+
`rebuttal-${tag}-${round}`,
|
|
431
|
+
VERDICT_SCHEMA,
|
|
432
|
+
);
|
|
433
|
+
if (!decision.ok) return { error: `作者 ${side} 反驳裁决失败:${decision.error}` };
|
|
434
|
+
entry[`decision${side}`] = decision.value;
|
|
435
|
+
saveReview();
|
|
436
|
+
return { passed: decision.value.verdict === 'PASS' };
|
|
437
|
+
};
|
|
438
|
+
|
|
439
|
+
while (round < team.maxReviewRounds && !(aPassed && bPassed)) {
|
|
440
|
+
const cross = team.reviewMode !== 'oneway';
|
|
441
|
+
if (!canSpend(cross ? 2 : 1)) {
|
|
442
|
+
stopReason = '预算不足,提前交裁判';
|
|
443
|
+
break;
|
|
444
|
+
}
|
|
445
|
+
round += 1;
|
|
446
|
+
history.push({ round });
|
|
447
|
+
const [reviewB, reviewA] = await Promise.all([
|
|
448
|
+
bPassed
|
|
449
|
+
? Promise.resolve({ ok: true, value: { verdict: 'PASS', issues: [] } })
|
|
450
|
+
: call(reviewPrompt(bFile, 'A', round, rubricFile), team.generatorA, `review-b-${round}`, REVIEW_SCHEMA),
|
|
451
|
+
!cross || aPassed
|
|
452
|
+
? Promise.resolve({ ok: true, value: { verdict: 'PASS', issues: [] } })
|
|
453
|
+
: call(reviewPrompt(aFile, 'B', round, rubricFile), team.generatorB, `review-a-${round}`, REVIEW_SCHEMA),
|
|
454
|
+
]);
|
|
455
|
+
if (!reviewB.ok || !reviewA.ok) {
|
|
456
|
+
return { ok: false, error: '交叉审查失败:' + ((reviewB.error || reviewA.error) || '未知错误') };
|
|
457
|
+
}
|
|
458
|
+
history[history.length - 1].reviewB = reviewB.value;
|
|
459
|
+
history[history.length - 1].reviewA = reviewA.value;
|
|
460
|
+
saveReview();
|
|
461
|
+
|
|
462
|
+
if (!bPassed) {
|
|
463
|
+
const settled = await settleSide('B', reviewB.value, bFile, team.generatorB, team.generatorA);
|
|
464
|
+
if (settled.error) return { ok: false, error: settled.error };
|
|
465
|
+
bPassed = settled.passed;
|
|
466
|
+
}
|
|
467
|
+
if (!aPassed) {
|
|
468
|
+
const settled = await settleSide('A', reviewA.value, aFile, team.generatorA, team.generatorB);
|
|
469
|
+
if (settled.error) return { ok: false, error: settled.error };
|
|
470
|
+
aPassed = settled.passed;
|
|
471
|
+
}
|
|
472
|
+
saveReview();
|
|
451
473
|
}
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
474
|
+
|
|
475
|
+
saveReview();
|
|
476
|
+
meta.round = round;
|
|
477
|
+
meta.aPassed = aPassed;
|
|
478
|
+
meta.bPassed = bPassed;
|
|
479
|
+
meta.calls = calls;
|
|
480
|
+
meta.stopReason = stopReason;
|
|
481
|
+
writeJsonFile(metaFile, meta);
|
|
482
|
+
|
|
483
|
+
if (!team.judgeOnMaxRounds && !(aPassed && bPassed)) {
|
|
484
|
+
const error = `交叉审查达到 ${round} 轮仍未全部通过,且 judgeOnMaxRounds=false。`;
|
|
485
|
+
meta.error = error;
|
|
486
|
+
writeJsonFile(metaFile, meta);
|
|
487
|
+
return { ok: false, error };
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
const judge = await call(
|
|
491
|
+
judgePrompt(round, aPassed, bPassed, history, aFile, bFile, finalFile, rubricFile),
|
|
492
|
+
team.judge,
|
|
493
|
+
'judge',
|
|
494
|
+
JUDGE_SCHEMA,
|
|
495
|
+
);
|
|
496
|
+
if (!judge.ok) {
|
|
497
|
+
meta.error = '裁判失败:' + judge.error;
|
|
498
|
+
writeJsonFile(metaFile, meta);
|
|
499
|
+
return { ok: false, error: meta.error };
|
|
457
500
|
}
|
|
501
|
+
meta.judge = judge.value;
|
|
502
|
+
meta.decision = judge.value && judge.value.decision;
|
|
503
|
+
meta.calls = calls;
|
|
504
|
+
meta.finishedAt = new Date().toISOString();
|
|
458
505
|
|
|
459
506
|
if (fs.existsSync(finalFile)) {
|
|
460
507
|
fs.copyFileSync(finalFile, file);
|
|
461
|
-
|
|
508
|
+
meta.finalFile = finalFile;
|
|
509
|
+
writeJsonFile(metaFile, meta);
|
|
510
|
+
return { ok: true, result: { round, aPassed, bPassed, calls, judge: judge.value }, finalFile };
|
|
462
511
|
}
|
|
463
|
-
const decision =
|
|
512
|
+
const decision = judge.value && judge.value.decision;
|
|
464
513
|
const fallback = decision === 'PICK_A' ? aFile : decision === 'PICK_B' ? bFile : '';
|
|
465
514
|
if (fallback && fs.existsSync(fallback)) {
|
|
466
515
|
fs.copyFileSync(fallback, file);
|
|
467
|
-
|
|
516
|
+
meta.finalFile = fallback;
|
|
517
|
+
meta.fallback = true;
|
|
518
|
+
writeJsonFile(metaFile, meta);
|
|
519
|
+
return { ok: true, result: { round, aPassed, bPassed, calls, judge: judge.value }, finalFile: fallback, fallback: true };
|
|
468
520
|
}
|
|
469
|
-
|
|
521
|
+
meta.error = '裁判没有写出 final.jsonl(decision=' + (decision || 'none') + ')';
|
|
522
|
+
writeJsonFile(metaFile, meta);
|
|
523
|
+
return { ok: false, error: 'team workflow 完成,但' + meta.error + '。' };
|
|
470
524
|
}
|