@cloud411716/fancy-webnovel 4.27.1 → 4.27.3
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/lib/task-list.js
CHANGED
|
@@ -23,6 +23,8 @@
|
|
|
23
23
|
* 不手动清空 —— 用户还能看到刚才做了哪些事,下一次对话开始时
|
|
24
24
|
* DSH 自己会清掉。失败时已完成步骤保持 completed,当前及后续
|
|
25
25
|
* 保持 pending,不谎报完成。
|
|
26
|
+
* 4. **长时间本地任务**:agent 一直 idle 时每 60 秒补写一次列表,
|
|
27
|
+
* 避免 UI 把长时间没有更新的任务栏收起。
|
|
26
28
|
*/
|
|
27
29
|
|
|
28
30
|
import { installCommandRecovery, registerManagedCommand } from './command-recovery.js';
|
|
@@ -227,7 +229,7 @@ class TaskListController {
|
|
|
227
229
|
* 写回命令自己的版本。
|
|
228
230
|
*
|
|
229
231
|
* @param {object} invocation DSH command invocation
|
|
230
|
-
* @param {{onTurnEnd?: Function, stopAfterFirstEnd?: boolean}} [opts]
|
|
232
|
+
* @param {{onTurnEnd?: Function, stopAfterFirstEnd?: boolean, keepAliveMs?: number}} [opts]
|
|
231
233
|
*/
|
|
232
234
|
watchTurns(invocation, opts = {}) {
|
|
233
235
|
const agent = invocation && invocation.agent;
|
|
@@ -235,14 +237,21 @@ class TaskListController {
|
|
|
235
237
|
const onTurnEnd = typeof opts.onTurnEnd === 'function' ? opts.onTurnEnd : null;
|
|
236
238
|
const stopAfterFirstEnd = opts.stopAfterFirstEnd === true;
|
|
237
239
|
const timeoutMs = Number(opts.timeoutMs) > 0 ? Number(opts.timeoutMs) : 0;
|
|
240
|
+
// 长时间本地采集时 agent 一直是 idle,DSH 的 UI 可能把任务栏收起。
|
|
241
|
+
// 每 60 秒补写一次(只在 idle 时),让任务栏在整段采集中保持可见。
|
|
242
|
+
const keepAliveMs = Number(opts.keepAliveMs) > 0 ? Number(opts.keepAliveMs) : 60 * 1000;
|
|
238
243
|
const startedAt = Date.now();
|
|
244
|
+
let lastWriteAt = Date.now();
|
|
239
245
|
|
|
240
246
|
this._stopWatcher();
|
|
241
247
|
let running = agent.status === 'running';
|
|
242
248
|
this._watchState = { running };
|
|
243
249
|
// 启动时如果已经在 running,说明 turn/start 已经发生过,
|
|
244
250
|
// 当前列表可能刚被清空;先补写一次。
|
|
245
|
-
if (running)
|
|
251
|
+
if (running) {
|
|
252
|
+
this._write();
|
|
253
|
+
lastWriteAt = Date.now();
|
|
254
|
+
}
|
|
246
255
|
|
|
247
256
|
this._watcher = setInterval(() => {
|
|
248
257
|
if (this.closed) {
|
|
@@ -260,9 +269,11 @@ class TaskListController {
|
|
|
260
269
|
if (current && !running) {
|
|
261
270
|
// turn/start:DSH 已把列表投影清空,立刻写回
|
|
262
271
|
this._write();
|
|
272
|
+
lastWriteAt = Date.now();
|
|
263
273
|
} else if (!current && running) {
|
|
264
274
|
// turn/end:写回命令自己的列表,再执行调用方的收尾回调
|
|
265
275
|
this._write();
|
|
276
|
+
lastWriteAt = Date.now();
|
|
266
277
|
if (onTurnEnd) {
|
|
267
278
|
try { onTurnEnd(this); } catch (e) {
|
|
268
279
|
console.error('[task-list] onTurnEnd 失败:' + (e && e.message ? e.message : String(e)));
|
|
@@ -273,6 +284,13 @@ class TaskListController {
|
|
|
273
284
|
return;
|
|
274
285
|
}
|
|
275
286
|
}
|
|
287
|
+
// 长时间没有 turn(本地 OCR/采集)时也要定期刷新,否则 UI 可能
|
|
288
|
+
// 把任务栏当作过期内容隐藏。只在 idle 时写,running 期间不抢
|
|
289
|
+
// 模型自己的 todo。
|
|
290
|
+
if (!current && keepAliveMs > 0 && Date.now() - lastWriteAt >= keepAliveMs) {
|
|
291
|
+
this._write();
|
|
292
|
+
lastWriteAt = Date.now();
|
|
293
|
+
}
|
|
276
294
|
running = current;
|
|
277
295
|
}, WATCH_INTERVAL_MS);
|
|
278
296
|
if (this._watcher && typeof this._watcher.unref === 'function') this._watcher.unref();
|
package/package.json
CHANGED
|
@@ -316,13 +316,6 @@ function retryPrompt(target, detail) {
|
|
|
316
316
|
].join('\n');
|
|
317
317
|
}
|
|
318
318
|
|
|
319
|
-
export function expectedItemCount(title) {
|
|
320
|
-
const match = String(title || '').match(/(\d+)\s*\+?\s*(?:个|种|条)/);
|
|
321
|
-
if (!match) return 0;
|
|
322
|
-
const count = Number(match[1]);
|
|
323
|
-
return Number.isFinite(count) && count >= 5 ? count : 0;
|
|
324
|
-
}
|
|
325
|
-
|
|
326
319
|
const CJK_RE = /[\u3400-\u9fff\uf900-\ufaff]/;
|
|
327
320
|
|
|
328
321
|
/**
|
|
@@ -346,28 +339,6 @@ export function kindLanguageProblem(file) {
|
|
|
346
339
|
+ '不要写 color_word、person_appearance 这类英文内部标识。请改写后重新写入同一个文件。';
|
|
347
340
|
}
|
|
348
341
|
|
|
349
|
-
/**
|
|
350
|
-
* 清单类作品(标题里写“100个/100种”)必须按条目数量逐条提取,
|
|
351
|
-
* 并额外产出 10 条同 kind + 同 subkind 的扩写素材。
|
|
352
|
-
* 只有格式校验不够:模型可能只提炼了 20 条创作句,却完全漏掉原清单。
|
|
353
|
-
*/
|
|
354
|
-
export function coverageProblem(file, title) {
|
|
355
|
-
const expected = expectedItemCount(title);
|
|
356
|
-
if (!expected) return '';
|
|
357
|
-
const required = expected + 10;
|
|
358
|
-
let records;
|
|
359
|
-
try {
|
|
360
|
-
records = readJsonl(file);
|
|
361
|
-
} catch {
|
|
362
|
-
return '';
|
|
363
|
-
}
|
|
364
|
-
if (records.length >= required) return '';
|
|
365
|
-
return '作品标题写着 ' + expected + ' 条清单,加上同 kind + 同 subkind 的 10 条扩写素材,'
|
|
366
|
-
+ '至少应有 ' + required + ' 条,但当前只有 ' + records.length
|
|
367
|
-
+ ' 条。清单类内容必须逐条输出:name 保留原文条目,不要只提炼一部分或改写成意象句;'
|
|
368
|
-
+ '补全原始条目和 10 条扩写素材后,重新写入同一个文件。';
|
|
369
|
-
}
|
|
370
|
-
|
|
371
342
|
function parseFirstJsonObject(text) {
|
|
372
343
|
let cleaned = String(text || '').replace(/^\uFEFF/, '').trim();
|
|
373
344
|
cleaned = cleaned
|
|
@@ -522,7 +493,7 @@ async function detectCapabilities(ctx, invocation, session, taskList, root, runD
|
|
|
522
493
|
return { ok: false, error: 'LLM 没有返回可解析的能力自检结果' };
|
|
523
494
|
}
|
|
524
495
|
|
|
525
|
-
async function finalizeMaterialFile({ root, target,
|
|
496
|
+
async function finalizeMaterialFile({ root, target, materialTools }) {
|
|
526
497
|
const skip = readSkipMarker(target);
|
|
527
498
|
if (skip) {
|
|
528
499
|
return {
|
|
@@ -542,8 +513,6 @@ async function finalizeMaterialFile({ root, target, title, materialTools }) {
|
|
|
542
513
|
if (!checked.ok) return { ok: false, detail: checked.detail };
|
|
543
514
|
const kindProblem = kindLanguageProblem(target);
|
|
544
515
|
if (kindProblem) return { ok: false, detail: kindProblem };
|
|
545
|
-
const coverage = coverageProblem(target, title);
|
|
546
|
-
if (coverage) return { ok: false, detail: coverage };
|
|
547
516
|
try {
|
|
548
517
|
const result = await importOtherMaterials(root, target);
|
|
549
518
|
return { ok: true, ...result };
|
|
@@ -553,7 +522,7 @@ async function finalizeMaterialFile({ root, target, title, materialTools }) {
|
|
|
553
522
|
}
|
|
554
523
|
|
|
555
524
|
async function analyzeMaterials(ctx, invocation, session, {
|
|
556
|
-
root, prompt, target,
|
|
525
|
+
root, prompt, target, materialTools, taskList,
|
|
557
526
|
}) {
|
|
558
527
|
const waitForTurn = makeWaitForTurn(invocation, {
|
|
559
528
|
timeoutMs: ANALYSIS_TIMEOUT_MS,
|
|
@@ -594,7 +563,7 @@ async function analyzeMaterials(ctx, invocation, session, {
|
|
|
594
563
|
continue;
|
|
595
564
|
}
|
|
596
565
|
|
|
597
|
-
const finalized = await finalizeMaterialFile({ root, target,
|
|
566
|
+
const finalized = await finalizeMaterialFile({ root, target, materialTools });
|
|
598
567
|
if (finalized.ok) return finalized;
|
|
599
568
|
if (finalized.error) return finalized;
|
|
600
569
|
detail = finalized.detail;
|
|
@@ -618,7 +587,6 @@ async function analyzeNote(ctx, invocation, session, {
|
|
|
618
587
|
root,
|
|
619
588
|
prompt,
|
|
620
589
|
target,
|
|
621
|
-
title: note.title,
|
|
622
590
|
materialTools,
|
|
623
591
|
taskList,
|
|
624
592
|
});
|
|
@@ -689,7 +657,6 @@ async function analyzeVideo(ctx, invocation, session, {
|
|
|
689
657
|
root,
|
|
690
658
|
prompt,
|
|
691
659
|
target,
|
|
692
|
-
title: video.title,
|
|
693
660
|
materialTools,
|
|
694
661
|
taskList,
|
|
695
662
|
});
|
|
@@ -710,7 +677,6 @@ async function analyzeArticle(ctx, invocation, session, {
|
|
|
710
677
|
root,
|
|
711
678
|
prompt,
|
|
712
679
|
target: target,
|
|
713
|
-
title: article.title,
|
|
714
680
|
materialTools,
|
|
715
681
|
taskList,
|
|
716
682
|
});
|
|
@@ -1090,7 +1056,6 @@ async function runCrawl(ctx, invocation, session, taskList) {
|
|
|
1090
1056
|
analyzed = await finalizeMaterialFile({
|
|
1091
1057
|
root,
|
|
1092
1058
|
target: job.target,
|
|
1093
|
-
title: job.title,
|
|
1094
1059
|
materialTools,
|
|
1095
1060
|
});
|
|
1096
1061
|
}
|
|
@@ -207,10 +207,6 @@ function buildBooksSelfCheckPrompt({ request, resultPath, platform, rank }) {
|
|
|
207
207
|
'',
|
|
208
208
|
'## 第二步:读取截图',
|
|
209
209
|
'',
|
|
210
|
-
`平台:${platform}`,
|
|
211
|
-
`榜单:${rank}`,
|
|
212
|
-
`页面地址:${request.url || ''}`,
|
|
213
|
-
'',
|
|
214
210
|
'请用 read 工具读取以下截图(绝对路径):',
|
|
215
211
|
'',
|
|
216
212
|
...screenshots.map((file, index) => `${index + 1}. \`${file}\``),
|
|
@@ -236,6 +232,8 @@ function buildBooksSelfCheckPrompt({ request, resultPath, platform, rank }) {
|
|
|
236
232
|
}, null, 2),
|
|
237
233
|
'```',
|
|
238
234
|
'',
|
|
235
|
+
'上面只是格式示例,实际值必须按截图如实抄录。',
|
|
236
|
+
'',
|
|
239
237
|
'抄录规则:',
|
|
240
238
|
'- 按截图中显示的中文原文抄录,不要翻译、改写、概括或补全。',
|
|
241
239
|
'- 看不清的字段填空字符串 `""`,不要猜。',
|