@waterwx/dsh-novel-forge 2.0.1-alpha → 2.1.0-alpha

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.
Files changed (135) hide show
  1. package/README.md +97 -2
  2. package/lib/client.js +3291 -752
  3. package/lib/index.js +3557 -237
  4. package/lib/types/assets.d.ts +16 -3
  5. package/lib/types/assistant.d.ts +4 -0
  6. package/lib/types/client/api.d.ts +89 -0
  7. package/lib/types/client/llmLive.d.ts +33 -0
  8. package/lib/types/client/locales.d.ts +3 -3
  9. package/lib/types/client/panel/AdaptModeView.d.ts +1 -1
  10. package/lib/types/client/panel/AssetsTab.d.ts +1 -1
  11. package/lib/types/client/panel/AssistantTab.d.ts +1 -1
  12. package/lib/types/client/panel/AuthorAssetsView.d.ts +1 -1
  13. package/lib/types/client/panel/AuthorHome.d.ts +4 -2
  14. package/lib/types/client/panel/BookAnalysisView.d.ts +4 -0
  15. package/lib/types/client/panel/BookshelfBar.d.ts +1 -1
  16. package/lib/types/client/panel/CreateBookView.d.ts +6 -2
  17. package/lib/types/client/panel/DirectorView.d.ts +7 -0
  18. package/lib/types/client/panel/FlowGuide.d.ts +1 -1
  19. package/lib/types/client/panel/GlobalAssetLibraryView.d.ts +1 -1
  20. package/lib/types/client/panel/IdeaInspirationView.d.ts +6 -0
  21. package/lib/types/client/panel/ImportModal.d.ts +1 -1
  22. package/lib/types/client/panel/KnowledgeBaseView.d.ts +4 -0
  23. package/lib/types/client/panel/LiveFeedLog.d.ts +5 -0
  24. package/lib/types/client/panel/MangaRoleLibrary.d.ts +1 -1
  25. package/lib/types/client/panel/MangaWorkspace.d.ts +1 -1
  26. package/lib/types/client/panel/MarketRadarView.d.ts +5 -0
  27. package/lib/types/client/panel/NovelPanel.d.ts +2 -2
  28. package/lib/types/client/panel/ProgressConsole.d.ts +1 -1
  29. package/lib/types/client/panel/ProgressHomeView.d.ts +1 -1
  30. package/lib/types/client/panel/PropLibrary.d.ts +1 -1
  31. package/lib/types/client/panel/ReaderView.d.ts +1 -1
  32. package/lib/types/client/panel/RunPanel.d.ts +1 -1
  33. package/lib/types/client/panel/SceneLibrary.d.ts +1 -1
  34. package/lib/types/client/panel/SettingsView.d.ts +1 -1
  35. package/lib/types/client/panel/ShelfView.d.ts +1 -1
  36. package/lib/types/client/panel/StoryboardTab.d.ts +1 -1
  37. package/lib/types/client/panel/StyleCard.d.ts +1 -1
  38. package/lib/types/client/panel/StyleGallery.d.ts +1 -1
  39. package/lib/types/client/panel/WorldTab.d.ts +1 -1
  40. package/lib/types/engine.d.ts +29 -1
  41. package/lib/types/global-assets.d.ts +6 -0
  42. package/lib/types/index.d.ts +6 -0
  43. package/lib/types/llm-live.d.ts +44 -0
  44. package/lib/types/market-radar-scan.d.ts +19 -0
  45. package/lib/types/market-radar-sources.d.ts +31 -0
  46. package/lib/types/prompting.d.ts +35 -0
  47. package/lib/types/protocol.d.ts +364 -8
  48. package/lib/types/run.d.ts +1 -1
  49. package/lib/types/src/ai-scan.d.ts +36 -0
  50. package/lib/types/src/assets.d.ts +37 -0
  51. package/lib/types/src/assistant.d.ts +45 -0
  52. package/lib/types/src/author-assets.d.ts +25 -0
  53. package/lib/types/src/bookshelf.d.ts +42 -0
  54. package/lib/types/src/client/api.d.ts +234 -0
  55. package/lib/types/src/client/docx.d.ts +15 -0
  56. package/lib/types/src/client/index.d.ts +14 -0
  57. package/lib/types/src/client/locales.d.ts +212 -0
  58. package/lib/types/src/client/mount.d.ts +9 -0
  59. package/lib/types/src/client/panel/AdaptModeView.d.ts +5 -0
  60. package/lib/types/src/client/panel/AssetsTab.d.ts +12 -0
  61. package/lib/types/src/client/panel/AssistantTab.d.ts +7 -0
  62. package/lib/types/src/client/panel/AuthorAssetsView.d.ts +4 -0
  63. package/lib/types/src/client/panel/AuthorHome.d.ts +32 -0
  64. package/lib/types/src/client/panel/BookshelfBar.d.ts +11 -0
  65. package/lib/types/src/client/panel/CreateBookView.d.ts +9 -0
  66. package/lib/types/src/client/panel/FlowGuide.d.ts +22 -0
  67. package/lib/types/src/client/panel/GlobalAssetLibraryView.d.ts +4 -0
  68. package/lib/types/src/client/panel/ImportModal.d.ts +7 -0
  69. package/lib/types/src/client/panel/MangaRoleLibrary.d.ts +20 -0
  70. package/lib/types/src/client/panel/MangaWorkspace.d.ts +12 -0
  71. package/lib/types/src/client/panel/ModelManager.d.ts +14 -0
  72. package/lib/types/src/client/panel/NovelPanel.d.ts +13 -0
  73. package/lib/types/src/client/panel/ProgressConsole.d.ts +17 -0
  74. package/lib/types/src/client/panel/ProgressHomeView.d.ts +5 -0
  75. package/lib/types/src/client/panel/PropLibrary.d.ts +8 -0
  76. package/lib/types/src/client/panel/ReaderView.d.ts +8 -0
  77. package/lib/types/src/client/panel/ReasoningSection.d.ts +10 -0
  78. package/lib/types/src/client/panel/RunPanel.d.ts +5 -0
  79. package/lib/types/src/client/panel/SceneLibrary.d.ts +16 -0
  80. package/lib/types/src/client/panel/SettingsView.d.ts +16 -0
  81. package/lib/types/src/client/panel/ShelfView.d.ts +15 -0
  82. package/lib/types/src/client/panel/StoryboardTab.d.ts +19 -0
  83. package/lib/types/src/client/panel/StyleCard.d.ts +8 -0
  84. package/lib/types/src/client/panel/StyleGallery.d.ts +1 -0
  85. package/lib/types/src/client/panel/WorldTab.d.ts +10 -0
  86. package/lib/types/src/client/panel/controller.d.ts +19 -0
  87. package/lib/types/src/client/panel/helpers.d.ts +18 -0
  88. package/lib/types/src/client/panel/views.d.ts +77 -0
  89. package/lib/types/src/client/sidebar-entry.d.ts +13 -0
  90. package/lib/types/src/client/text.d.ts +9 -0
  91. package/lib/types/src/comic-presets.d.ts +12 -0
  92. package/lib/types/src/docx.d.ts +19 -0
  93. package/lib/types/src/engine.d.ts +402 -0
  94. package/lib/types/src/index.d.ts +79 -0
  95. package/lib/types/src/manga-genre-rules.d.ts +22 -0
  96. package/lib/types/src/novel-context.d.ts +80 -0
  97. package/lib/types/src/prompt-utils.d.ts +35 -0
  98. package/lib/types/src/protocol.d.ts +2176 -0
  99. package/lib/types/src/review-policy.d.ts +97 -0
  100. package/lib/types/src/routes.d.ts +29 -0
  101. package/lib/types/src/run.d.ts +32 -0
  102. package/lib/types/src/shot-language.d.ts +46 -0
  103. package/lib/types/src/story-beat-language.d.ts +35 -0
  104. package/lib/types/src/style-library.d.ts +33 -0
  105. package/package.json +1 -1
  106. package/src/assets.ts +1774 -879
  107. package/src/assistant.ts +154 -9
  108. package/src/client/api.ts +105 -6
  109. package/src/client/llmLive.ts +101 -0
  110. package/src/client/locales.ts +4 -4
  111. package/src/client/panel/AdaptModeView.tsx +18 -3
  112. package/src/client/panel/AssistantTab.tsx +41 -3
  113. package/src/client/panel/AuthorHome.tsx +51 -20
  114. package/src/client/panel/BookAnalysisView.tsx +60 -0
  115. package/src/client/panel/CreateBookView.tsx +22 -3
  116. package/src/client/panel/DirectorView.tsx +200 -0
  117. package/src/client/panel/IdeaInspirationView.tsx +71 -0
  118. package/src/client/panel/KnowledgeBaseView.tsx +73 -0
  119. package/src/client/panel/LiveFeedLog.tsx +76 -0
  120. package/src/client/panel/MarketRadarView.tsx +374 -0
  121. package/src/client/panel/NovelPanel.tsx +117 -16
  122. package/src/client/panel/ProgressConsole.tsx +5 -6
  123. package/src/client/panel/SettingsView.tsx +3 -0
  124. package/src/client/panel/panel.module.css +2 -3
  125. package/src/engine.ts +459 -23
  126. package/src/global-assets.ts +59 -0
  127. package/src/index.ts +17 -1
  128. package/src/llm-live.ts +68 -0
  129. package/src/market-radar-scan.ts +41 -0
  130. package/src/market-radar-sources.ts +173 -0
  131. package/src/prompting.ts +159 -0
  132. package/src/protocol.ts +340 -8
  133. package/src/routes.ts +579 -59
  134. package/src/run.ts +15 -8
  135. package/skills/chapter-batch/SKILL.md +0 -81
package/src/run.ts CHANGED
@@ -80,21 +80,22 @@ export class ProductionRunner {
80
80
  }
81
81
 
82
82
  /** 启动/续跑生产单:startNo..endNo 区间,endNo 超出计划时先自动补计划。 */
83
- async start(startNo: number, endNo: number): Promise<RunState> {
83
+ async start(startNo: number, endNo: number, runDir?: string): Promise<RunState> {
84
84
  const config = this.deps.getConfig()
85
85
  if (this.working) throw new Error('生产单正在运行中,请先暂停或停止')
86
- let project = loadProject(config.outputDir)
86
+ const outputDir = runDir ?? config.outputDir
87
+ let project = loadProject(outputDir)
87
88
  if (project === undefined) throw new Error('输出目录中没有项目')
88
89
 
89
90
  // 计划补足:目标区间超出已有计划 → 续写规划追加。
90
91
  if (endNo > project.chapters.length) {
91
92
  const need = endNo - project.chapters.length
92
93
  this.log(`计划不足,追加 ${need} 章计划…`)
93
- const chapters = await planChapters(this.deps.ctx, config, project, need, undefined, config.outputDir)
94
- mergeVolatileFromDisk(config.outputDir, project)
94
+ const chapters = await planChapters(this.deps.ctx, config, project, need, undefined, outputDir)
95
+ mergeVolatileFromDisk(outputDir, project)
95
96
  project.chapters.push(...chapters)
96
97
  project.updatedAt = new Date().toISOString()
97
- saveProject(config.outputDir, project)
98
+ saveProject(outputDir, project)
98
99
  this.log(`计划已追加,全书 ${project.chapters.length} 章`)
99
100
  }
100
101
 
@@ -113,7 +114,7 @@ export class ProductionRunner {
113
114
  this.pauseRequested = false
114
115
  this.stopRequested = false
115
116
  // 绑定生产单目录(快照):运行期间切书不影响本单的读写目标。
116
- this.bookDir = config.outputDir
117
+ this.bookDir = outputDir
117
118
  this.working = true
118
119
  this.persist()
119
120
  void this.loop()
@@ -215,7 +216,7 @@ export class ProductionRunner {
215
216
  chapter.generatingAt = new Date().toISOString()
216
217
  mergeVolatileFromDisk(outputDir, project)
217
218
  saveProject(outputDir, project)
218
- this.log(wasError ? `第${no}章《${chapter.title}》重新生成…` : `第${no}章《${chapter.title}》生成…`)
219
+ this.log(`${wasError ? '重新生成' : '生成'} 第${no}章《${chapter.title}》…(模型 ${config.generateModel || config.model})`)
219
220
  try {
220
221
  for await (const step of generateChapterStream(ctx, config, project, outputDir, no)) { /* drain */ }
221
222
  try { await summarizeAndExtractFacts(ctx, config, project, outputDir, no) } catch (e) { console.warn('[dsh-novel-forge] run summary/facts:', (e as Error).message) }
@@ -223,7 +224,7 @@ export class ProductionRunner {
223
224
  if (config.autoReview ?? true) {
224
225
  const report = await reviewChapter(ctx, config, project, outputDir, no)
225
226
  if (this.state !== null) this.state.stats[wasError ? 'regenerated' : 'generated']++
226
- this.log(`第${no}章 审稿 ${report.score}分 ${report.passed ? '✅ 通过' : '⚠️ 被拒'}`)
227
+ this.log(`第${no}章 审稿 ${report.score}分 ${report.passed ? '✅ 通过' : '⚠️ 被拒'}(模型 ${config.reviewModel || config.model})`)
227
228
  } else {
228
229
  chapter.status = 'approved'
229
230
  mergeVolatileFromDisk(outputDir, project)
@@ -241,6 +242,12 @@ export class ProductionRunner {
241
242
  const review = await authorReviewChapter(ctx, config, project, no, body, prevTail)
242
243
  chapter.authorReview = review
243
244
  if (review.advancedLines !== undefined) autoLinkPlotlines(project, no, review.advancedLines)
245
+ // 结果回灌:把本章状态变化/新线索写进编年录事实库,供后续计划与整本控制用。
246
+ const backfillFacts: string[] = [...(review.stateChanges ?? []), ...(review.clues ?? [])]
247
+ if (backfillFacts.length > 0) {
248
+ project.facts ??= []
249
+ for (const text of backfillFacts) project.facts.push({ chapterNo: no, text })
250
+ }
244
251
  mergeVolatileFromDisk(outputDir, project)
245
252
  saveProject(outputDir, project)
246
253
  }
@@ -1,81 +0,0 @@
1
- ---
2
- name: novel-forge-chapter-batch
3
- description: 批量生成小说章节并值守处理审稿未过的章节。当用户说「生成 N 章」「连写」「批量生成」「继续写章节」「值守处理未过章节」时使用。依赖 dsh-novel-forge 插件(http://127.0.0.1:3080/api/dsh-novel-forge/*)。
4
- ---
5
-
6
- # 小说章节批量生产与值守处理
7
-
8
- 把「批量生成章节 + 审稿未过处理」固化为可复现流程。所有操作通过 dsh-novel-forge 的 HTTP API 执行。
9
-
10
- ## 0. 值守纪律(最高优先级,违反即空转)
11
-
12
- 1. **启动后台任务后立即停下,不轮询、不连续 wait、不做无意义动作**——后台任务(批量生成/处理)由运行时在完成时自动通知。
13
- 2. 只有收到「任务完成」通知或用户新消息时,才继续下一步(读结果 → 处理未过 → 汇报)。
14
- 3. 等待期间可以做「与当前任务无关」的其他有用工作(如用户提出的其他问题、代码改进),但不得为等任务而空转。
15
- 4. 任务因 web 重启中断时:等用户确认或检测到 3080 恢复后,复位卡死章节(generating/error → reset)再续跑,并向用户说明中断原因。
16
-
17
- ## 1. 前置检查(每次必做)
18
-
19
- 1. 确认服务在跑:`GET /api/dsh-novel-forge/status` 返回 200,读 `project.chapters` 数量与书名。
20
- 2. 确认目标章节状态:列出 `pending`(待生成)章节号区间,避免重复生成已 approved/rejected 的章。
21
- 3. **串行执行,禁止并行写 project.json**——多个脚本同时调 API 会造成状态互相覆盖(实测教训:第 166 章曾被并发回滚成 rejected)。
22
-
23
- ## 2. 批量生成
24
-
25
- 对目标章节区间(如 181-205)逐章串行调用:
26
-
27
- ```
28
- POST /api/dsh-novel-forge/generate
29
- { "chapterNo": N, "skipReview": false }
30
- ```
31
-
32
- - `skipReview: false` 走完整质量门(生成 → 摘要+编年录 → AI 审稿 → 作者复盘)。
33
- - 响应为 NDJSON 流;找 `{"type":"review","report":{...}}` 帧取 `score`/`passed`。
34
- - 每章 2-5 分钟;失败自动重试 1 次(间隔 3 秒)。
35
- - 预估总时长并告知用户(25 章 ≈ 45-75 分钟),放后台跑,期间可并行做别的(只读操作不受影响)。
36
- - 推荐用 Node 脚本(fetch + 逐章循环),避免 PowerShell 的引号/UTF-8 转义坑;脚本用完删除。
37
-
38
- ## 2. 未过章节处理(分级策略)
39
-
40
- 生成完成后汇总:通过 / 未过(rejected)/ 失败(error)。对未过章按此分级:
41
-
42
- ### A. 无 high(全是 medium/low 主观项)→ 豁免通过
43
- ```
44
- POST /api/dsh-novel-forge/chapter/approve { "chapterNo": N }
45
- ```
46
- 主观项(套话/节奏/比喻/心理描写)不值得逐章磨,直接通过。
47
-
48
- ### B. 有 high 且问题明确(逻辑/设定/时间线/用词)→ 按意见修订 + 验证模式
49
- 1. 取 review 的 high(无 high 取前 3 条 medium),拼指令:
50
- `按审稿意见修订(优先处理):\n[severity] item → suggestion`
51
- 2. `POST /rewrite` `{ chapterNo, instructions }` → 产出 pendingDraft
52
- 3. **验证模式**:`POST /chapter/check` `{ chapterNo, text: draft, previousReport: review }`——携带上一轮报告,LLM 只核对原意见是否解决 + 只挑新增 high,不全新找茬
53
- 4. 判定:`passed || issues 全非 high` → 可接受
54
- 5. 可接受 → `POST /draft/apply` `{ chapterNo, report: { score: max(score,70), passed: true, issues: [], ... } }` 落盘为 approved
55
- 6. 不可接受 → 看剩余 high 是否明确可修 → 第二轮修订(指令更精确,如「把第 141 章的养伤时间线统一为七天」)→ 再验证
56
- 7. **每章最多修订 2 轮**,仍不过 → 保留草稿,标记「待人工」,不硬来
57
-
58
- ### C. 有 high 但结构性(修订改不好,如逻辑矛盾被坐实)→ 重新生成
59
- - `POST /draft/discard` 清草稿 → `POST /generate` 整章重写
60
- - 重新生成后若只剩主观项 → 走 A 豁免
61
-
62
- ### D. error 状态(无审稿、chars 丢失)→ 重置重生成
63
- - `POST /chapter/reset` `{ chapterNo }` → `POST /generate`
64
-
65
- ### 特殊注意
66
- - **approved 但 review 有 high**:已通过状态保留,不折腾(high 可能已被正文处理或审稿误标)。
67
- - **修订指令越精确越有效**:具体数字/行为(如「茶梗尺寸统一为半截指节」)一次就过;泛泛的「修正矛盾」容易改不到位。
68
-
69
- ## 3. 收尾
70
-
71
- 1. 最终验证:`GET /status` 读目标区间全部 approved。
72
- 2. 可选:对涉及剧情的章节刷新剧情线进度(`POST /plotlines` `{ op:'refresh', id }`)——注意刷新函数只读最近 8 章摘要,早期章节的线可能刷不准,必要时手动 update progress + link 章节。
73
- 3. 向用户汇报:通过/未过/失败数量 + 每章处理方式 + 遗留待人工项。
74
-
75
- ## 4. 已知陷阱(血泪教训)
76
-
77
- - **并发写 project.json 会互相覆盖**——多个生成/处理任务必须串行。
78
- - **rewrite 的草稿可能不落盘**(偶发 500 或时序)——应用前检查 `pendingDraft` 是否存在,不存在则重跑 rewrite。
79
- - **PowerShell 调 API 的引号/中文转义是坑**——统一用 Node 脚本。
80
- - **status 接口会做数据快照**——以磁盘 novel-project.json 为准复核关键状态。
81
- - **验证模式 500 偶发**——重试一次即可(LLM 瞬时错误)。