@cloud411716/fancy-webnovel 4.0.3 → 4.2.0

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.
@@ -10,6 +10,7 @@ import { existsSync, realpathSync, statSync } from 'fs';
10
10
  import { homedir } from 'os';
11
11
  import { basename, dirname, isAbsolute, join, resolve } from 'path';
12
12
  import { askUserQuestion, notify } from '#infra';
13
+ import { registerCommandWithTasks } from '#task-list';
13
14
  import { isSensitiveProjectPath, isValidProjectPath } from '#path-guard';
14
15
  import { readDeployedState, deployedStateProblemText, DEPLOYED_STATUS } from '#deployed-state';
15
16
  import { initWorkspaceDatabase } from '#db-init';
@@ -104,12 +105,20 @@ function formatWorkspace(root) {
104
105
  ].join('\n');
105
106
  }
106
107
 
108
+ function bootstrapTaskTitles(rawInput) {
109
+ const raw = String(rawInput || '').trim().toLowerCase();
110
+ if (raw === 'help') return ['显示初始化帮助'];
111
+ if (raw === 'status') return ['读取工作区状态', '探测 SurrealDB 服务'];
112
+ if (raw === 'list') return ['读取全局工作区注册表', '探测各工作区服务状态'];
113
+ return ['检查工作区路径与状态', '准备 SurrealDB', '初始化目录与数据库', '输出初始化结果'];
114
+ }
115
+
107
116
  export async function apply(ctx) {
108
- ctx.commands.register({
117
+ registerCommandWithTasks(ctx, {
109
118
  name: 'fancy-bootstrap',
110
119
  description: '📁 初始化 fancy-webnovel 工作区 ( usage: /fancy-bootstrap [目录] | status | list | help )',
111
120
  input: { hint: '[目录] | status | list' },
112
- handler: async (invocation) => {
121
+ handler: async (invocation, tasks) => {
113
122
  const session = invocation.agent.session;
114
123
  const rawInput = String(invocation.rawInput || '').trim();
115
124
 
@@ -147,6 +156,7 @@ export async function apply(ctx) {
147
156
  ? [currentEntry, ...entries.filter((entry) => entry !== currentEntry)]
148
157
  : entries;
149
158
 
159
+ tasks.advance(1);
150
160
  const details = await Promise.all(ordered.map(async (entry) => {
151
161
  let surreal = null;
152
162
  try { surreal = readWorkspace(entry.workspace).surreal || null; } catch { /* missing/lightweight */ }
@@ -275,6 +285,7 @@ export async function apply(ctx) {
275
285
  const choice = confirmed.answer?.answers?.[0]?.selected?.[0];
276
286
  if (choice !== '确认创建') return notify(session, 'error', '🚫 操作已取消。');
277
287
 
288
+ tasks.advance(1);
278
289
  try {
279
290
  // First init may need the standalone binary. Install it into the
280
291
  // workspace so it survives PATH changes and is easy to remove.
@@ -283,7 +294,9 @@ export async function apply(ctx) {
283
294
  notes.push('⏬ 未找到 surreal,已自动下载到工作区 .fancy/bin/。');
284
295
  await installSurreal(target);
285
296
  }
297
+ tasks.advance(2);
286
298
  const result = await initWorkspaceDatabase(target);
299
+ tasks.advance(3);
287
300
  return notify(session, 'success', [
288
301
  '✅ 工作区初始化完成',
289
302
  ...(notes.length ? ['', ...notes] : []),
@@ -309,5 +322,5 @@ export async function apply(ctx) {
309
322
  return notify(session, 'error', '❌ 初始化失败:' + (err && err.message ? err.message : String(err)));
310
323
  }
311
324
  },
312
- });
325
+ }, (invocation) => bootstrapTaskTitles(invocation.rawInput));
313
326
  }
@@ -11,6 +11,7 @@
11
11
  */
12
12
 
13
13
  import { askUserQuestion, notify } from '#infra';
14
+ import { registerCommandWithTasks } from '#task-list';
14
15
  import { readWorkspace, resolveWorkspace } from '#workspace';
15
16
  import { deleteProject, listProjects, getProject } from '#projects';
16
17
  import { initDatabases, initProjectDatabase, initWorkspaceDatabase } from '#db-init';
@@ -72,12 +73,31 @@ function formatProjects(projects) {
72
73
  return lines.join('\n');
73
74
  }
74
75
 
76
+ function dbTaskTitles(invocation) {
77
+ const tokens = String(invocation.rawInput || '').trim().split(/\s+/).filter(Boolean);
78
+ const command = (tokens[0] || 'status').toLowerCase();
79
+ if (command === 'help' || command === '?') return ['显示数据库帮助'];
80
+ if (command === 'status') return ['读取工作区', '探测 SurrealDB 状态'];
81
+ if (command === 'install') return ['读取工作区', '安装 SurrealDB'];
82
+ if (command === 'start') return ['读取工作区', '启动 SurrealDB', '探测服务状态'];
83
+ if (command === 'stop') return ['读取工作区', '停止 SurrealDB'];
84
+ if (command === 'list') return ['读取工作区', '读取项目库列表'];
85
+ if (command === 'remove') return ['读取工作区', '确认删除范围', '删除项目数据库', '清理项目目录'];
86
+ if (command === 'init') {
87
+ if ((tokens[1] || '').toLowerCase() === 'project') {
88
+ return ['读取工作区', '解析目标项目', '初始化项目库', '输出结果'];
89
+ }
90
+ return ['读取工作区', '初始化工作区数据库', '初始化素材库', '汇总结果'];
91
+ }
92
+ return ['读取工作区', '执行数据库操作'];
93
+ }
94
+
75
95
  export async function apply(ctx) {
76
- ctx.commands.register({
96
+ registerCommandWithTasks(ctx, {
77
97
  name: 'fancy-db',
78
98
  description: '🗄️ 数据库管理 ( usage: /fancy-db status|install|start|stop|init|list|remove | help )',
79
99
  input: { hint: '.' },
80
- handler: async (invocation) => {
100
+ handler: async (invocation, tasks) => {
81
101
  const session = invocation.agent.session;
82
102
  const raw = String(invocation.rawInput || '').trim();
83
103
  const tokens = raw.split(/\s+/).filter(Boolean);
@@ -92,6 +112,7 @@ export async function apply(ctx) {
92
112
  return notify(session, 'error', '❌ ' + (err && err.message ? err.message : String(err)));
93
113
  }
94
114
 
115
+ tasks.advance(1);
95
116
  try {
96
117
  if (command === 'status') {
97
118
  return notify(session, 'success', formatStatus(await serverStatus(root)));
@@ -104,6 +125,7 @@ export async function apply(ctx) {
104
125
 
105
126
  if (command === 'start') {
106
127
  const result = await startServer(root);
128
+ tasks.advance(2);
107
129
  return notify(session, 'success', (result.started ? '✅ 已启动' : 'ℹ️ 已在运行') + '\n' + formatStatus(await serverStatus(root)));
108
130
  }
109
131
 
@@ -117,10 +139,13 @@ export async function apply(ctx) {
117
139
  if (target === 'project') {
118
140
  const name = tokens.slice(2).join(' ').trim();
119
141
  if (!name) return notify(session, 'error', '用法:/fancy-db init project <名字|UUID>');
142
+ tasks.advance(2);
120
143
  const result = await initProjectDatabase(root, name);
144
+ tasks.advance(3);
121
145
  return notify(session, 'success', '✅ 已初始化项目库:' + result.project.name + '\n库:' + result.project.database + '\nschema ' + result.schema_version + ' / validation ' + result.validation_version);
122
146
  }
123
147
  const result = await initDatabases(root, { all: true });
148
+ tasks.advance(2);
124
149
  const failed = result.projects.filter((p) => !p.ok);
125
150
  return notify(session, failed.length ? 'error' : 'success', [
126
151
  '✅ 工作区数据库初始化完成',
@@ -156,10 +181,12 @@ export async function apply(ctx) {
156
181
  if (selected !== '删除数据库' && selected !== '删除数据库并清除目录') {
157
182
  return notify(session, 'success', '操作已取消。');
158
183
  }
184
+ tasks.advance(2);
159
185
  const result = await deleteProject(root, project.project_id, {
160
186
  confirm: true,
161
187
  purge: selected === '删除数据库并清除目录',
162
188
  });
189
+ tasks.advance(3);
163
190
  return notify(session, 'success', '✅ 已删除《' + result.project.name + '》的数据库' + (result.purged ? '和项目目录' : ',项目目录已移入 .fancy/trash'));
164
191
  }
165
192
 
@@ -168,5 +195,5 @@ export async function apply(ctx) {
168
195
  return notify(session, 'error', '❌ ' + (err && err.message ? err.message : String(err)));
169
196
  }
170
197
  },
171
- });
198
+ }, dbTaskTitles);
172
199
  }
@@ -14,6 +14,7 @@ import path from 'path';
14
14
  import { RecordId } from 'surrealdb';
15
15
 
16
16
  import { askUserQuestion, llmFollowup, notify, spawnScript } from '#infra';
17
+ import { registerCommandWithTasks } from '#task-list';
17
18
  import { readJsonFile, resolveWorkspace } from '#workspace';
18
19
  import { connectMaterial, ensureMaterialDatabase } from '#material-db';
19
20
  import { deployMaterialTools } from '../fancy-material/tool-deploy.js';
@@ -262,7 +263,7 @@ function retryPrompt(target, detail) {
262
263
  }
263
264
 
264
265
  async function analyzeNote(ctx, invocation, session, {
265
- root, note, screenshots, target, materialTools, paths,
266
+ root, note, screenshots, target, materialTools, paths, taskList,
266
267
  }) {
267
268
  const prompt = analysisPrompt({
268
269
  accountUrl: note.account_url,
@@ -334,7 +335,7 @@ async function analyzeNote(ctx, invocation, session, {
334
335
  return { ok: false, error: '素材没有通过校验:' + detail };
335
336
  }
336
337
 
337
- async function runCrawl(ctx, invocation, session) {
338
+ async function runCrawl(ctx, invocation, session, taskList) {
338
339
  const root = workspaceOf(session);
339
340
  const paths = ensureDouyinDir(root);
340
341
  const accounts = readAccounts(root);
@@ -358,6 +359,8 @@ async function runCrawl(ctx, invocation, session) {
358
359
  return notify(session, 'error', '❌ 启动 Chrome 失败:' + started.error);
359
360
  }
360
361
  const browser = { cdp: started.cdp, mode: started.mode };
362
+ taskList.advance(1);
363
+ taskList.watchTurns(invocation);
361
364
 
362
365
  try {
363
366
  const runDir = path.join(paths.output, stampOfNow());
@@ -396,6 +399,7 @@ async function runCrawl(ctx, invocation, session) {
396
399
  scannedAccounts += 1;
397
400
  const notes = Array.isArray(scan.json.notes) ? scan.json.notes : [];
398
401
  foundNotes += notes.length;
402
+ taskList.advance(2);
399
403
  for (const card of notes) {
400
404
  if (abortRequested(invocation)) { aborted = true; break outer; }
401
405
  const noteId = noteIdFromUrl(card.href);
@@ -429,6 +433,8 @@ async function runCrawl(ctx, invocation, session) {
429
433
  processedNotes += 1;
430
434
  note.account_url = account.url;
431
435
  const target = path.join(noteDir, 'materials.jsonl');
436
+ taskList.advance(3);
437
+ taskList.progress(`LLM 整理图文素材(${note.title || noteId})`);
432
438
  const analyzed = await analyzeNote(ctx, invocation, session, {
433
439
  root,
434
440
  note,
@@ -436,6 +442,7 @@ async function runCrawl(ctx, invocation, session) {
436
442
  target,
437
443
  materialTools,
438
444
  paths,
445
+ taskList,
439
446
  });
440
447
  if (!analyzed.ok) {
441
448
  failures.push({ id: noteId, url: card.href, reason: analyzed.error });
@@ -462,6 +469,7 @@ async function runCrawl(ctx, invocation, session) {
462
469
  }
463
470
  }
464
471
 
472
+ taskList.advance(4);
465
473
  return notify(session, (aborted || failures.length) ? 'error' : 'success', summaryText({
466
474
  accounts: accounts.length,
467
475
  scannedAccounts,
@@ -502,9 +510,10 @@ async function runList(session) {
502
510
  return notify(session, 'success', accountListText(root));
503
511
  }
504
512
 
505
- async function runRemove(session, selector) {
513
+ async function runRemove(session, selector, taskList) {
506
514
  const root = workspaceOf(session);
507
515
  try {
516
+ taskList.advance(1);
508
517
  const result = removeAccount(root, selector);
509
518
  return notify(session, 'success', '✅ 已删除账号:' + result.url);
510
519
  } catch (err) {
@@ -512,12 +521,22 @@ async function runRemove(session, selector) {
512
521
  }
513
522
  }
514
523
 
524
+ function douyinTaskTitles(invocation) {
525
+ const tokens = String(invocation.rawInput || '').trim().split(/\s+/).filter(Boolean);
526
+ const command = (tokens[0] || '').toLowerCase();
527
+ if (command === 'help' || command === '?') return ['显示抖音采集帮助'];
528
+ if (command === 'add') return ['解析主页地址', '保存账号'];
529
+ if (command === 'list') return ['读取账号列表'];
530
+ if (command === 'remove') return ['解析目标账号', '删除账号'];
531
+ return ['检查浏览器与素材库', '扫描账号主页', '采集笔记图片', 'LLM 整理图文素材', '写入素材库'];
532
+ }
533
+
515
534
  export async function apply(ctx) {
516
- ctx.commands.register({
535
+ registerCommandWithTasks(ctx, {
517
536
  name: 'fancy-douyin',
518
537
  description: '🎬 抖音图文采集 ( usage: /fancy-douyin [add <主页> | list | remove <序号|地址> | help] )',
519
538
  input: { hint: '[add <主页> | list | remove <序号|地址> | help]' },
520
- handler: async (invocation) => {
539
+ handler: async (invocation, taskList) => {
521
540
  const session = invocation.agent.session;
522
541
  const raw = String(invocation.rawInput || '').trim();
523
542
  const tokens = raw.split(/\s+/).filter(Boolean);
@@ -537,15 +556,15 @@ export async function apply(ctx) {
537
556
  }
538
557
  if (command === 'remove') {
539
558
  if (tokens.length < 2) return notify(session, 'error', '用法:/fancy-douyin remove <序号|主页地址>');
540
- return await runRemove(session, tokens.slice(1).join(' '));
559
+ return await runRemove(session, tokens.slice(1).join(' '), taskList);
541
560
  }
542
561
  if (command) {
543
562
  return notify(session, 'error', '未知子命令:' + command + '\n运行 /fancy-douyin help 查看用法。');
544
563
  }
545
- return await runCrawl(ctx, invocation, session);
564
+ return await runCrawl(ctx, invocation, session, taskList);
546
565
  } catch (err) {
547
566
  return notify(session, 'error', '❌ 抖音命令失败:' + (err && err.message ? err.message : String(err)));
548
567
  }
549
568
  },
550
- });
569
+ }, douyinTaskTitles);
551
570
  }
@@ -47,7 +47,7 @@ id / kind / name / tags / genres / note / source
47
47
  - `source` 固定写 `other`。
48
48
  - `kind` 不受内置列表限制;如果内容能归入下面的内置 kind,优先使用内置 kind。
49
49
  - `tags` 3–8 个短标签。
50
- - `genres` 1–3 个题材;拿不准就写 `["通用"]`。
50
+ - `genres` 1–5 个题材;如果素材同时适配多个题材/标签,把它们都写进去;拿不准就写 `["通用"]`。
51
51
  - `note` 可写一句补充,没有就写空字符串。
52
52
  - `id` 用小写字母、数字、下划线,格式建议:`<kind>_dy_<作品ID>_<序号>`,全局唯一。
53
53
 
@@ -7,6 +7,7 @@
7
7
  import fs from 'fs';
8
8
  import path from 'path';
9
9
  import { notify } from '#infra';
10
+ import { registerCommandWithTasks } from '#task-list';
10
11
  import { openStoryGraph } from '../fancy-story-builder/storydb/client.js';
11
12
  import { exportStoryGraph } from './exporter.js';
12
13
  import { resolveProject } from '../../lib/projects.js';
@@ -25,12 +26,19 @@ function cwdOf(session) {
25
26
  return session && session.header && session.header.cwd ? session.header.cwd : null;
26
27
  }
27
28
 
29
+ function exportTaskTitles(invocation) {
30
+ if (String(invocation.rawInput || '').trim().toLowerCase() === 'help') {
31
+ return ['显示导出帮助'];
32
+ }
33
+ return ['解析当前项目', '读取故事图', '导出 Markdown', '汇总导出结果'];
34
+ }
35
+
28
36
  export async function apply(ctx) {
29
- ctx.commands.register({
37
+ registerCommandWithTasks(ctx, {
30
38
  name: 'fancy-export',
31
39
  description: '📖 故事导出 ( usage: /fancy-export | help )',
32
40
  input: { hint: '.' },
33
- handler: async (invocation) => {
41
+ handler: async (invocation, tasks) => {
34
42
  const session = invocation.agent.session;
35
43
  const raw = String(invocation.rawInput || '').trim().toLowerCase();
36
44
  if (raw === 'help') return notify(session, 'success', helpText());
@@ -45,10 +53,13 @@ export async function apply(ctx) {
45
53
  return notify(session, 'error', '❌ ' + (err && err.message ? err.message : String(err)));
46
54
  }
47
55
 
56
+ tasks.advance(1);
48
57
  let sdb = null;
49
58
  try {
50
59
  sdb = await openStoryGraph(project.dir, { project });
60
+ tasks.advance(2);
51
61
  const result = await exportStoryGraph(sdb, project.dir);
62
+ tasks.advance(3);
52
63
  return notify(session, 'success', [
53
64
  '✅ 已导出到 ' + result.dir,
54
65
  '文件:' + result.files + ' 个 · 细纲:' + result.outlines + ' 章 · 正文:' + result.chapters + ' 章',
@@ -59,5 +70,5 @@ export async function apply(ctx) {
59
70
  if (sdb) await sdb.close();
60
71
  }
61
72
  },
62
- });
73
+ }, exportTaskTitles);
63
74
  }
@@ -26,6 +26,7 @@ import path from 'node:path';
26
26
  import { fileURLToPath } from 'node:url';
27
27
 
28
28
  import { llmFollowup, notify, spawnScript } from '#infra';
29
+ import { registerCommandWithTasks } from '#task-list';
29
30
  import { readDeployedConfig, ensureSetupId } from '#story-builder/index.js';
30
31
  import { phaseScriptFiles } from '#story-builder/deploy-manifest.js';
31
32
  import { makeWaitForTurn } from '#story-builder/writing-driver.js';
@@ -263,14 +264,27 @@ function importStamp() {
263
264
  /**
264
265
  * 导入阶段的命令入口。
265
266
  */
267
+ function importTaskTitles(invocation) {
268
+ if (String(invocation.rawInput || '').trim().toLowerCase() === 'help') {
269
+ return ['显示导入帮助'];
270
+ }
271
+ return [
272
+ '校验旧稿源与项目状态',
273
+ '扫描并切分章节',
274
+ '部署导入脚本与模板',
275
+ '逐轮反推设定与关系',
276
+ '汇总导入结果',
277
+ ];
278
+ }
279
+
266
280
  export async function apply(ctx) {
267
- ctx.commands.register({
281
+ registerCommandWithTasks(ctx, {
268
282
  name: 'fancy-import',
269
283
  description: '📥 旧稿导入 ( usage: /fancy-import <旧稿目录或文件> | help )',
270
284
  input: {
271
285
  hint: '旧稿目录或文件'
272
286
  },
273
- handler: async (invocation) => {
287
+ handler: async (invocation, tasks) => {
274
288
  const session = invocation.agent.session;
275
289
  const { signal } = invocation;
276
290
 
@@ -316,12 +330,14 @@ export async function apply(ctx) {
316
330
  }
317
331
 
318
332
  // 2. 扫描(确定性:切章保标题 + 统计实际规模)
333
+ tasks.advance(1);
319
334
  const scan = scanSource(sourcePath);
320
335
  if (!scan.ok) {
321
336
  return notify(session, 'error', importTemplates.notify({ type: 'no_source', err: scan.error }));
322
337
  }
323
338
 
324
339
  // 3. 部署导入要用的脚本 / 模板
340
+ tasks.advance(2);
325
341
  const deploy = deployImportFiles(projectRoot);
326
342
  if (!deploy.ok) {
327
343
  return notify(session, 'error', importTemplates.notify({
@@ -382,6 +398,8 @@ export async function apply(ctx) {
382
398
  projectRoot,
383
399
  };
384
400
 
401
+ tasks.advance(3);
402
+ tasks.watchTurns(invocation);
385
403
  const report = await runImportStage({
386
404
  projectRoot,
387
405
  dirs,
@@ -457,6 +475,7 @@ export async function apply(ctx) {
457
475
  backupDir: writeRes.backupDir
458
476
  });
459
477
  writeImportReport(dirs, reportMd);
478
+ tasks.advance(4);
460
479
 
461
480
  const progressSummary = progressNotes.length
462
481
  ? '导入进度:' + progressNotes.slice(-3).join(';')
@@ -487,7 +506,7 @@ export async function apply(ctx) {
487
506
  extra: [progressSummary, overwriteNote].filter(Boolean).join('\n\n')
488
507
  }));
489
508
  }
490
- });
509
+ }, importTaskTitles);
491
510
  }
492
511
 
493
512
  // ============================================================