@cloud411716/fancy-webnovel 0.1.76 → 0.1.77
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/infra.js +26 -21
- package/package.json +1 -1
- package/plugins/fancy-bootstrap/index.js +4 -2
- package/plugins/fancy-scan/index.js +1 -2
package/infra.js
CHANGED
|
@@ -5,13 +5,14 @@
|
|
|
5
5
|
* notify(session, text) — 打印消息给用户(不触发 LLM)
|
|
6
6
|
* llmFollowup(invocation, prompt) — 发送消息给 LLM,让 LLM 继续处理
|
|
7
7
|
* spawnScript(cmd, args, opts) — spawn 子进程,解析 stdout JSON
|
|
8
|
+
* startActivity(session) — 开始 Activity Line 计时,返回 stop 函数
|
|
8
9
|
*
|
|
9
10
|
* 所有 fancy-* 插件均直接 import 此文件。
|
|
10
11
|
*/
|
|
11
12
|
|
|
12
|
-
//
|
|
13
|
+
// --------------------------------------------------------------------------
|
|
13
14
|
// notify — 打印消息给用户(queueMicrotask 避免打断 LLM 输出顺序)
|
|
14
|
-
//
|
|
15
|
+
// --------------------------------------------------------------------------
|
|
15
16
|
|
|
16
17
|
export function notify(session, text) {
|
|
17
18
|
queueMicrotask(() => {
|
|
@@ -25,7 +26,7 @@ export function notify(session, text) {
|
|
|
25
26
|
|
|
26
27
|
// --------------------------------------------------------------------------
|
|
27
28
|
// llmFollowup
|
|
28
|
-
//
|
|
29
|
+
// --------------------------------------------------------------------------
|
|
29
30
|
|
|
30
31
|
export function llmFollowup(invocation, content) {
|
|
31
32
|
const prompt = typeof content === 'string' ? content : JSON.stringify(content);
|
|
@@ -35,19 +36,37 @@ export function llmFollowup(invocation, content) {
|
|
|
35
36
|
});
|
|
36
37
|
}
|
|
37
38
|
|
|
38
|
-
//
|
|
39
|
+
// --------------------------------------------------------------------------
|
|
40
|
+
// startActivity — Activity Line 计时器(显示 Running… + 实时计时)
|
|
41
|
+
// 调用 startActivity() 返回 stop 函数,进入新阶段时先 stop 再 start
|
|
42
|
+
// --------------------------------------------------------------------------
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @param {import('@deepseek-ai/dsh-session').Session} session
|
|
46
|
+
* @returns {() => void} stop — 调用后停止计时
|
|
47
|
+
*/
|
|
48
|
+
export function startActivity(session) {
|
|
49
|
+
session.append('turn/start', { source: 'fancy-plugin' });
|
|
50
|
+
return () => session.append('turn/end', { source: 'fancy-plugin' });
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// --------------------------------------------------------------------------
|
|
39
54
|
// spawnScript — spawn 子进程,stdout 只收集 JSON,stderr 单独收集
|
|
40
|
-
//
|
|
55
|
+
// opts.stop() 会在进程终止时自动调用(用于清理 turn/start)
|
|
56
|
+
// --------------------------------------------------------------------------
|
|
41
57
|
|
|
42
|
-
export function spawnScript(cmd, args, { timeout = 30000, cwd } = {}) {
|
|
58
|
+
export function spawnScript(cmd, args, { timeout = 30000, cwd, stop } = {}) {
|
|
43
59
|
return new Promise(async (resolve) => {
|
|
44
60
|
const { spawn } = await import('child_process');
|
|
45
61
|
const proc = spawn(cmd, args, { timeout, cwd, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
46
62
|
const outParts = [], errParts = [];
|
|
47
63
|
proc.stdout.on('data', (d) => { outParts.push(d.toString()); });
|
|
48
64
|
proc.stderr.on('data', (d) => { errParts.push(d.toString()); });
|
|
65
|
+
|
|
66
|
+
const cleanup = () => { try { stop?.(); } catch (_) {} };
|
|
49
67
|
proc.on('close', (code) => {
|
|
50
68
|
const stdout = outParts.join(''), stderr = errParts.join('');
|
|
69
|
+
cleanup();
|
|
51
70
|
try {
|
|
52
71
|
const parsed = JSON.parse(stdout);
|
|
53
72
|
resolve({
|
|
@@ -63,20 +82,6 @@ export function spawnScript(cmd, args, { timeout = 30000, cwd } = {}) {
|
|
|
63
82
|
resolve({ ok: false, output: stdout, error: stderr || ('exit ' + code) });
|
|
64
83
|
}
|
|
65
84
|
});
|
|
66
|
-
proc.on('error', (err) => resolve({ ok: false, output: '', error: err.message }));
|
|
85
|
+
proc.on('error', (err) => { cleanup(); resolve({ ok: false, output: '', error: err.message }); });
|
|
67
86
|
});
|
|
68
87
|
}
|
|
69
|
-
|
|
70
|
-
// --------------------------------------------------------------------------
|
|
71
|
-
// activity — Activity Line 计时器(显示 Running… + 实时计时)
|
|
72
|
-
// 调用 startActivity() 返回 stop 函数,进入新阶段时先 stop 再 start
|
|
73
|
-
// --------------------------------------------------------------------------
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* @param {import('@deepseek-ai/dsh-session').Session} session
|
|
77
|
-
* @returns {() => void} stop — 调用后停止计时
|
|
78
|
-
*/
|
|
79
|
-
export function startActivity(session) {
|
|
80
|
-
session.append('turn/start', { source: 'fancy-plugin' });
|
|
81
|
-
return () => session.append('turn/end', { source: 'fancy-plugin' });
|
|
82
|
-
}
|
package/package.json
CHANGED
|
@@ -80,8 +80,10 @@ export async function apply(ctx) {
|
|
|
80
80
|
|
|
81
81
|
notify(session, bootstrap.notify({ type: 'initializing', projectRoot }));
|
|
82
82
|
const stopActivity = startActivity(session);
|
|
83
|
-
const result = await spawnScript('node', [join(SCRIPTS_DIR, 'init.js'), projectRoot], {
|
|
84
|
-
|
|
83
|
+
const result = await spawnScript('node', [join(SCRIPTS_DIR, 'init.js'), projectRoot], {
|
|
84
|
+
timeout: 30000,
|
|
85
|
+
stop: stopActivity,
|
|
86
|
+
});
|
|
85
87
|
|
|
86
88
|
if (result.ok) {
|
|
87
89
|
notify(session, bootstrap.notify({ type: 'success' }));
|
|
@@ -97,9 +97,8 @@ export async function apply(ctx) {
|
|
|
97
97
|
'node',
|
|
98
98
|
[join(SCAN_SCRIPTS_DIR, 'run-scan.js'),
|
|
99
99
|
'--project-root', projectRoot, '--platform', platform, '--length', length],
|
|
100
|
-
{ timeout: 120000 }
|
|
100
|
+
{ timeout: 120000, stop: stopActivity }
|
|
101
101
|
);
|
|
102
|
-
stopActivity();
|
|
103
102
|
|
|
104
103
|
if (!scriptResult.ok) {
|
|
105
104
|
const err = (typeof scriptResult.error === 'object' && scriptResult.error !== null)
|