novelforge-agent 0.1.1 → 0.3.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.
Files changed (56) hide show
  1. package/README.md +45 -18
  2. package/dist/src/cli/index.js +81 -4
  3. package/dist/src/core/bibleStore.js +36 -0
  4. package/dist/src/core/characterStore.js +74 -0
  5. package/dist/src/core/contextBuilder.js +76 -1
  6. package/dist/src/core/fileNames.js +4 -0
  7. package/dist/src/core/index.js +4 -0
  8. package/dist/src/core/projectDiscovery.js +1 -0
  9. package/dist/src/core/projectOps.js +193 -0
  10. package/dist/src/core/projectStore.js +15 -1
  11. package/dist/src/core/prompts/en-US.js +247 -16
  12. package/dist/src/core/prompts/zh-CN.js +246 -15
  13. package/dist/src/core/retrieval/index.js +8 -0
  14. package/dist/src/core/schemas.js +121 -1
  15. package/dist/src/core/steps/architecture.js +7 -1
  16. package/dist/src/core/steps/architectureExtension.js +72 -0
  17. package/dist/src/core/steps/chapter.js +11 -1
  18. package/dist/src/core/steps/chapterReview.js +26 -1
  19. package/dist/src/core/steps/chapterRevision.js +17 -0
  20. package/dist/src/core/steps/index.js +4 -0
  21. package/dist/src/core/steps/memoryCard.js +26 -1
  22. package/dist/src/core/steps/novelMetadata.js +4 -2
  23. package/dist/src/core/steps/storyBible.js +1 -1
  24. package/dist/src/core/steps/styleGuide.js +12 -0
  25. package/dist/src/core/threadStore.js +150 -0
  26. package/dist/src/core/workflow.js +5 -3
  27. package/dist/src/mcp/tools.js +228 -20
  28. package/package.json +5 -1
  29. package/src/cli/index.ts +84 -3
  30. package/src/core/bibleStore.ts +57 -0
  31. package/src/core/characterStore.ts +93 -0
  32. package/src/core/contextBuilder.ts +74 -4
  33. package/src/core/fileNames.ts +5 -0
  34. package/src/core/index.ts +4 -0
  35. package/src/core/projectDiscovery.ts +2 -0
  36. package/src/core/projectOps.ts +251 -0
  37. package/src/core/projectStore.ts +19 -1
  38. package/src/core/prompts/en-US.ts +258 -25
  39. package/src/core/prompts/types.ts +4 -1
  40. package/src/core/prompts/zh-CN.ts +250 -17
  41. package/src/core/retrieval/index.ts +10 -0
  42. package/src/core/schemas.ts +133 -1
  43. package/src/core/steps/architecture.ts +7 -1
  44. package/src/core/steps/architectureExtension.ts +88 -0
  45. package/src/core/steps/chapter.ts +11 -1
  46. package/src/core/steps/chapterReview.ts +28 -1
  47. package/src/core/steps/chapterRevision.ts +18 -0
  48. package/src/core/steps/index.ts +4 -0
  49. package/src/core/steps/memoryCard.ts +27 -1
  50. package/src/core/steps/novelMetadata.ts +4 -2
  51. package/src/core/steps/storyBible.ts +1 -1
  52. package/src/core/steps/styleGuide.ts +13 -0
  53. package/src/core/threadStore.ts +173 -0
  54. package/src/core/types.ts +134 -1
  55. package/src/core/workflow.ts +5 -3
  56. package/src/mcp/tools.ts +351 -21
@@ -74,6 +74,55 @@ ${input.context ? `## 已有上下文\n${input.context}\n` : ''}## 输出结构
74
74
  - 不要输出 JSON。`,
75
75
  };
76
76
  }
77
+ function buildStyleGuidePrompt(input) {
78
+ return {
79
+ purpose: 'style_guide',
80
+ expectedFormat: 'JSON matching StyleGuideSchema',
81
+ prompt: `你是一名长篇小说文风主编。请根据用户提示、metadata 和故事圣经,生成可被每章写作与审稿长期执行的风格圣经。
82
+
83
+ ## 用户提示词
84
+ ${input.state.initialPrompt}
85
+
86
+ ${input.context ? `## 已有上下文\n${input.context}\n` : ''}## 输出要求
87
+ 请只输出合法 JSON,格式如下:
88
+ {
89
+ "narrativeVoice": "叙事人称、视角距离、旁白气质、情绪温度",
90
+ "pacing": "开章、转场、冲突推进、章末钩子的节奏规则",
91
+ "diction": "词汇选择、句式密度、题材术语使用边界",
92
+ "dialogueRules": [
93
+ "核心人物对白的长度、语气、潜台词、称谓规则"
94
+ ],
95
+ "prohibitedPatterns": [
96
+ "禁止出现的现代梗、解释型旁白、设定堆砌、口吻漂移等"
97
+ ],
98
+ "proseRhythm": {
99
+ "sentenceRhythm": "短句、中句、长句的使用原则;短句应服务转折、危险、情绪落点,而不是默认叙述单位",
100
+ "paragraphing": "段落应形成完整叙事单元;避免连续单句成段、靠频繁换行制造伪节奏",
101
+ "interiorityMode": "心理活动如何通过动作、迟疑、感官反应折射;避免频繁直接解释人物想法",
102
+ "emphasisBudget": "重复句、破折号、孤立短句等强调资源的使用预算",
103
+ "antiPatterns": [
104
+ "连续 3 个以上单句短段",
105
+ "用大量短句模拟紧张感",
106
+ "每个动作后立刻解释心理",
107
+ "重复同一句式制造伪节奏"
108
+ ]
109
+ },
110
+ "sampleParagraph": "一段 120-250 字的目标风格示例,不要写成剧情大纲",
111
+ "consistencyChecks": [
112
+ "后续章节审稿时用于判断风格是否跑偏的具体检查项"
113
+ ]
114
+ }
115
+
116
+ 要求:
117
+ - 风格必须匹配 genre、premise、人物身份和目标读者预期。
118
+ - 不要只写抽象形容词;每个字段都要能指导实际行文。
119
+ - proseRhythm 不要写成固定字数规则;要描述可审稿的节奏原则和反模式。
120
+ - sampleParagraph 只展示语言质感,不要提前泄露后续剧情。
121
+ - prohibitedPatterns 至少 3 条,consistencyChecks 至少 3 条。
122
+ - proseRhythm.antiPatterns 至少 4 条。
123
+ ${strictJsonOutputRules()}`,
124
+ };
125
+ }
77
126
  function buildArchitecturePrompt(input) {
78
127
  return {
79
128
  purpose: 'architecture',
@@ -84,7 +133,7 @@ function buildArchitecturePrompt(input) {
84
133
  ${input.state.initialPrompt}
85
134
 
86
135
  ## 目标
87
- - 本次至少生成 ${input.state.targetChapters} 个章架构。
136
+ - 全本目标约 ${input.state.plannedTotalChapters ?? input.state.targetChapters} 章;本次只生成首批 ${input.state.targetChapters} 个章架构。
88
137
  - 全本架构负责长期主线和结局方向。
89
138
  - 卷架构负责阶段冲突、高潮和卷尾钩子。
90
139
  - 章架构必须只覆盖本章应发生的内容,不要提前泄露后续具体事件。
@@ -101,6 +150,18 @@ ${input.context ? `## 已有上下文\n${input.context}\n` : ''}## 输出要求
101
150
  "order": 1
102
151
  }
103
152
  ],
153
+ "volumePacing": [
154
+ {
155
+ "volumeId": "v1",
156
+ "start": "本卷起点:主角/世界/冲突处于什么状态",
157
+ "promise": "本卷向读者承诺的核心看点或问题",
158
+ "keyTurns": ["关键转折1", "关键转折2"],
159
+ "midpoint": "本卷中点转折或认知变化",
160
+ "climax": "本卷高潮",
161
+ "payoffs": ["本卷计划回收的伏笔或承诺"],
162
+ "lingeringMysteries": ["卷末仍要保留的悬念"]
163
+ }
164
+ ],
104
165
  "chapters": [
105
166
  {
106
167
  "chapterNumber": 1,
@@ -114,37 +175,119 @@ ${input.context ? `## 已有上下文\n${input.context}\n` : ''}## 输出要求
114
175
 
115
176
  要求:
116
177
  - chapters.length 必须大于等于 ${input.state.targetChapters}。
178
+ - chapters 不需要一次覆盖全本;后续写到边界时会进入 architecture_extension 续规划。
117
179
  - chapterNumber 从 1 开始连续递增。
118
180
  - volumeId 必须引用 volumes 中存在的 id。
181
+ - volumePacing 必须为每个 volume 提供节奏板。
182
+ - requiredBeats 至少 1 条,且必须具体可执行。
183
+ ${strictJsonOutputRules()}`,
184
+ };
185
+ }
186
+ function buildArchitectureExtensionPrompt(input) {
187
+ const start = input.state.currentChapter;
188
+ const total = input.state.plannedTotalChapters ?? input.state.targetChapters;
189
+ const end = Math.min(total, start + input.state.targetChapters - 1);
190
+ return {
191
+ purpose: 'architecture_extension',
192
+ expectedFormat: 'JSON matching ArchitectureExtensionPayloadSchema',
193
+ prompt: `你是一名长篇小说总架构师。当前已写到既有章纲边界,请基于已有内容续写后续章架构。
194
+
195
+ ## 续规划范围
196
+ - 从第 ${start} 章开始。
197
+ - 本批最多规划到第 ${end} 章。
198
+ - 全本目标到第 ${total} 章结束。
199
+
200
+ ## 续规划原则
201
+ - 不要改写已经存在的章节架构;只追加新的 chapter architecture。
202
+ - 新增章节必须承接最近记忆、角色状态表、活跃伏笔和卷级节奏板。
203
+ - 如果后续章节进入新卷,可以新增 volumes 和 volumePacing;如果仍在旧卷,可以补充/更新该卷节奏板。
204
+ - 如果全本方向因已写内容需要微调,可以输出 fullUpdate;fullUpdate 必须是可覆盖 architecture/full.md 的完整更新版,而不是变更说明。
205
+ - 章架构必须只覆盖本章应发生的内容,不要提前泄露更后面的具体事件。
206
+
207
+ ${input.context ? `## 已有上下文\n${input.context}\n` : ''}## 输出要求
208
+ 请只输出合法 JSON,格式如下:
209
+ {
210
+ "fullUpdate": "可选:完整更新后的全本架构 Markdown/文本",
211
+ "volumes": [
212
+ {
213
+ "id": "v2",
214
+ "title": "新增或更新卷标题",
215
+ "summary": "本卷目标、冲突、高潮和卷尾钩子",
216
+ "order": 2
217
+ }
218
+ ],
219
+ "volumePacing": [
220
+ {
221
+ "volumeId": "v2",
222
+ "start": "本卷起点",
223
+ "promise": "本卷承诺",
224
+ "keyTurns": ["关键转折1", "关键转折2"],
225
+ "midpoint": "中点转折",
226
+ "climax": "本卷高潮",
227
+ "payoffs": ["计划回收点"],
228
+ "lingeringMysteries": ["遗留悬念"]
229
+ }
230
+ ],
231
+ "chapters": [
232
+ {
233
+ "chapterNumber": ${start},
234
+ "title": "章标题",
235
+ "volumeId": "v1",
236
+ "summary": "本章剧情摘要",
237
+ "requiredBeats": ["必须完成的情节点1"]
238
+ }
239
+ ]
240
+ }
241
+
242
+ 要求:
243
+ - chapters[0].chapterNumber 必须等于 ${start}。
244
+ - chapterNumber 必须连续递增,且不能超过 ${total}。
245
+ - chapters.length 建议为 ${end - start + 1},除非已经到全本结尾。
119
246
  - requiredBeats 至少 1 条,且必须具体可执行。
247
+ - volumeId 必须引用已有或本次新增 volumes 中存在的 id。
120
248
  ${strictJsonOutputRules()}`,
121
249
  };
122
250
  }
123
251
  function buildChapterPrompt(input) {
252
+ const ch = input.state.currentChapter;
253
+ const isFirstChapter = ch <= 1;
124
254
  return {
125
255
  purpose: 'chapter',
126
256
  expectedFormat: 'Markdown',
127
- prompt: `你是一位擅长创作长篇网络小说的职业作者。请直接完成第 ${input.state.currentChapter} 章正文。
257
+ prompt: `你是一位擅长创作长篇网络小说的职业作者。请直接完成第 ${ch} 章正文。
128
258
 
129
259
  ## 执行优先级
130
- 1. 先严格遵守“本章架构、用户补充要求、故事圣经硬约束、上一章承接”。
131
- 2. 再参考“历史相关记忆、历史原文证据”保证一致性。
132
- 3. 最后才参考“全本/本卷远场规划”,且不得提前写出尚未发生的情节。
133
-
134
- ## 风格与字数
260
+ 1. 先严格遵守"本章架构、用户补充要求、故事圣经硬约束、风格圣经、上一章承接"。
261
+ 2. 再参考"历史相关记忆、历史原文证据、活跃伏笔"保证一致性。
262
+ 3. 最后才参考"全本/本卷远场规划",且不得提前写出尚未发生的情节。
263
+
264
+ ## 字数目标
265
+ - 默认目标 3000 字(±20%)。如果本章架构里指定了 targetWords,按那个目标。
266
+ - 不要为了凑字数注水;也不要为了简洁牺牲冲突推进。
267
+
268
+ ## 结构要求
269
+ ${isFirstChapter
270
+ ? '- 这是第 1 章,不需要"上回提要"。开篇直接立人物、立情境。'
271
+ : '- 章首需要 2-3 句"上回提要"或"承接段",让没读上一章的读者能续上(除非本章架构 requireRecap=false)。要自然带入,不要写成"上一章里……"的元叙述。'}
272
+ - 章末必须有清晰的"钩子":可以是悬念、反转、剧情承诺、情绪余韵或卷末高潮——按本章架构 endHookFocus 字段决定。如果未指定,默认用悬念。
273
+
274
+ ## 风格
275
+ - 严格执行上下文中的 Style Guide;sampleParagraph 只作为语言质感参考,不要复写其内容。
276
+ - 严格执行 Style Guide.proseRhythm:短句、单句段、重复句、破折号是强调资源,不是默认叙述单位;常规叙述要形成自然句群。
135
277
  - 文风必须与本书题材、世界观、人物身份、情感基调一致。
136
- - 语言要自然、稳定、可读,优先服务叙事推进、人物塑造和情绪积累。
137
- - 对话必须符合人物身份、关系和处境;重要情绪尽量通过动作、神态、节奏、潜台词体现。
138
- - 场景描写要有必要的感官细节与氛围支撑,但篇幅服务剧情,不要空转。
139
- - 冲突、转折、悬念和章末钩子要清晰,保证阅读推进感。
278
+ - 语言自然、稳定、可读,优先服务叙事推进、人物塑造和情绪积累。
279
+ - 对话符合人物身份、关系和处境;重要情绪通过动作、神态、节奏、潜台词体现。
280
+ - 场景描写有必要的感官细节与氛围支撑,但篇幅服务剧情。
281
+ - POV 严格按本章架构 povCharacter(如有),中途不切换视角。
140
282
 
141
283
  ## 执行规则
142
284
  - 只写本章架构明确覆盖的内容,不得提前写后续章节具体事件或人物揭示。
143
- - 不得新增本章架构未授权的主要人物;功能性角色只能轻描淡写。
285
+ - 不得新增本章架构未授权的主要人物;功能性角色轻描淡写。
144
286
  - 所有人物称谓、物品、场景、能力、时间线必须与既有设定一致。
145
287
  - 如果上一章结尾仍在动作、对话或同一场景中,本章开头必须连续衔接。
288
+ - 活跃伏笔列表中的条目本章可以"推进"或"回收",但**不得无声无息地删除**——若选择不触碰也要让它仍然成立。
146
289
  - 禁止无代价越级碾压、强行降智配角、突兀机械反转、硬灌设定、空洞抒情。
147
- - 禁止总结腔、条目腔、说教腔,不要输出解释性前言。
290
+ - 禁止总结腔、条目腔、说教腔,不要输出解释性前言或"我修改了什么"之类的元文本。
148
291
 
149
292
  ${input.context ? `## 生成上下文\n${input.context}\n` : ''}## 输出要求
150
293
  - 输出 Markdown。
@@ -184,18 +327,46 @@ ${input.context ? `## 当前章上下文\n${input.context}\n` : ''}## 输出要
184
327
  "after": "变化后"
185
328
  }
186
329
  ],
187
- "openThreads": ["尚未解决的伏笔、承诺、危险或疑问"]
330
+ "openThreads": ["尚未解决的伏笔、承诺、危险或疑问"],
331
+ "wordCount": 本章实际字数(整数估算即可),
332
+ "threadActions": [
333
+ {
334
+ "kind": "plant | build | pay | drop",
335
+ "threadId": "已有伏笔的 id(如果是 plant 留空让系统分配;build/pay/drop 必须填活跃伏笔列表里的 id)",
336
+ "description": "新伏笔的描述(plant 时必填)或本章如何推进/回收/丢弃这条伏笔的一句话"
337
+ }
338
+ ],
339
+ "characterUpdates": [
340
+ {
341
+ "name": "人物姓名",
342
+ "role": "角色定位(如本章确认或改变)",
343
+ "goal": "本章结束时的当前目标",
344
+ "belief": "本章结束时影响其行动的核心认知/信念",
345
+ "relationships": [
346
+ { "name": "相关人物", "dynamic": "本章结束时的关系状态" }
347
+ ],
348
+ "abilities": ["本章结束时确认拥有的能力、资源或限制"],
349
+ "secrets": ["本章结束时仍未公开或只被部分人知道的秘密"],
350
+ "emotionalState": "本章结束时的情绪状态"
351
+ }
352
+ ]
188
353
  }
189
354
 
190
355
  要求:
191
356
  - 只记录已经在本章发生或被确认的信息。
192
357
  - 不要推测后续剧情。
193
358
  - facts 和 stateChanges 要具体,便于后续章节引用。
359
+ - wordCount 用中文字符数(去掉空格和 Markdown 标记),近似估算即可。
360
+ - threadActions 是关键:
361
+ · 任何"上下文里 Active Foreshadow Threads"列出的活跃伏笔,如果本章推进了,请发 kind="build";如果本章正式回收/兑现,请发 kind="pay";如果本章决定放弃,请发 kind="drop"。这三种情况 threadId 必填。
362
+ · 本章新埋设的伏笔,请发 kind="plant",description 写清楚是什么伏笔。
363
+ · 活跃伏笔本章没动也没关系,不需要为它发动作;但**不要悄悄删除**——只要不发 drop,它就继续保留活跃。
364
+ - characterUpdates 用于维护独立角色状态表:只输出本章有明确变化或被重新确认的重要人物;目标、信念、关系、能力、秘密、情绪状态必须以本章结尾为准。
194
365
  ${strictJsonOutputRules()}`,
195
366
  };
196
367
  }
197
368
  function buildContinuityReviewPrompt(input) {
198
- const end = Math.max(input.state.targetChapters, input.state.currentChapter - 1);
369
+ const end = Math.max(input.state.plannedTotalChapters ?? input.state.targetChapters, input.state.currentChapter - 1);
199
370
  return {
200
371
  purpose: 'continuity_review',
201
372
  expectedFormat: 'JSON matching ContinuityReviewSchema',
@@ -240,6 +411,14 @@ function buildChapterReviewPrompt(input) {
240
411
  prompt: `你是一名严格的章节审稿编辑。请审阅指定章节是否存在内部问题以及与既有设定的冲突。
241
412
 
242
413
  ${input.context ? `## 审阅上下文\n${input.context}\n` : ''}## 审阅重点
414
+ - 这是强制章节验收门槛:只要任一验收项 fail,status 必须是 "issues_found",不能进入下一章。
415
+ - requiredBeats 是否全部完成;缺失项必须写入 acceptance.requiredBeats.missingBeats。
416
+ - 本章是否推进主线、人物状态或活跃伏笔;如果完全原地踏步,narrativeProgress/characterProgress/foreshadowProgress 至少一项必须 fail。
417
+ - 是否违反故事圣经、角色状态表、卷级节奏板或历史记忆。
418
+ - 是否违反 Style Guide:叙事声音、句式密度、题材词汇、对白规则和禁用模式。
419
+ - 是否违反 Style Guide.proseRhythm:短句密度过高、连续单句短段、靠换行制造伪节奏、心理解释过直白、重复同一句式。
420
+ - 章末是否有清晰钩子,且符合本章 endHookFocus。
421
+ - 是否重复之前章节已经完成的桥段、冲突结构、信息揭示或对话功能。
243
422
  - 人物声音、动机、状态是否符合故事圣经与历史记忆。
244
423
  - 世界规则、物品归属、能力边界是否被破坏。
245
424
  - 时间线、地点、与上一章结尾的衔接是否一致。
@@ -251,6 +430,41 @@ ${input.context ? `## 审阅上下文\n${input.context}\n` : ''}## 审阅重点
251
430
  {
252
431
  "chapterNumber": ${chapter},
253
432
  "status": "clean",
433
+ "acceptance": {
434
+ "requiredBeats": {
435
+ "status": "pass | fail",
436
+ "evidence": "逐条说明 requiredBeats 完成证据",
437
+ "missingBeats": []
438
+ },
439
+ "narrativeProgress": {
440
+ "status": "pass | fail",
441
+ "evidence": "本章如何推进主线/阶段目标"
442
+ },
443
+ "characterProgress": {
444
+ "status": "pass | fail",
445
+ "evidence": "本章如何改变或确认关键人物目标、信念、关系、能力、秘密或情绪"
446
+ },
447
+ "foreshadowProgress": {
448
+ "status": "pass | fail",
449
+ "evidence": "本章如何埋设、推进、回收或有意识保留伏笔"
450
+ },
451
+ "storyBibleConsistency": {
452
+ "status": "pass | fail",
453
+ "evidence": "是否符合故事圣经、角色状态表和世界规则"
454
+ },
455
+ "proseRhythm": {
456
+ "status": "pass | fail",
457
+ "evidence": "是否符合 Style Guide.proseRhythm;说明短句/单句段/重复句/心理解释是否被合理控制"
458
+ },
459
+ "endingHook": {
460
+ "status": "pass | fail",
461
+ "evidence": "章末钩子的具体段落和作用"
462
+ },
463
+ "repetition": {
464
+ "status": "pass | fail",
465
+ "evidence": "是否重复既有桥段;无重复也要说明依据"
466
+ }
467
+ },
254
468
  "issues": [
255
469
  {
256
470
  "severity": "low | medium | high",
@@ -265,6 +479,8 @@ ${input.context ? `## 审阅上下文\n${input.context}\n` : ''}## 审阅重点
265
479
  要求:
266
480
  - 没有问题时 status 为 "clean",issues 输出空数组。
267
481
  - 有问题时 status 为 "issues_found"。
482
+ - 只有所有 acceptance 项都是 "pass" 时,status 才能为 "clean"。
483
+ - 任一 acceptance 项为 "fail" 时,必须在 issues 中写出对应问题与修复建议。
268
484
  - evidence 必须具体,不能写"疑似"、"可能"。
269
485
  ${strictJsonOutputRules()}`,
270
486
  };
@@ -334,8 +550,12 @@ function buildPromptForStep(input) {
334
550
  return buildMetadataPrompt(input);
335
551
  case 'story_bible':
336
552
  return buildStoryBiblePrompt(input);
553
+ case 'style_guide':
554
+ return buildStyleGuidePrompt(input);
337
555
  case 'architecture':
338
556
  return buildArchitecturePrompt(input);
557
+ case 'architecture_extension':
558
+ return buildArchitectureExtensionPrompt(input);
339
559
  case 'chapter':
340
560
  return buildChapterPrompt(input);
341
561
  case 'memory_card':
@@ -348,6 +568,17 @@ function buildPromptForStep(input) {
348
568
  return buildChapterRevisionPrompt(input);
349
569
  case 'cross_chapter_review':
350
570
  return buildCrossChapterReviewPrompt(input);
571
+ case 'story_bible_amend':
572
+ return {
573
+ purpose: 'story_bible',
574
+ expectedFormat: 'Markdown',
575
+ prompt: `请基于当前已有故事圣经与本次反馈,输出"修订后的完整故事圣经 Markdown"。
576
+
577
+ ${input.context ? `## 修订上下文\n${input.context}\n` : ''}## 输出要求
578
+ - 输出完整的 story-bible.md 内容,覆盖式替换旧版(旧版会自动归档到 story-bible-versions/)。
579
+ - 保留旧版仍然成立的内容,仅修改 / 新增 / 删除有明确依据的部分。
580
+ - 不要输出 diff、变更说明、bullet 总结,直接输出新 bible 全文。`,
581
+ };
351
582
  case 'complete':
352
583
  return {
353
584
  purpose: 'continuity_review',
@@ -82,6 +82,14 @@ export async function indexMemoryCard(projectPath, chapterNumber, card) {
82
82
  const id = `memory:${chapterNumber}`;
83
83
  await upsert(projectPath, (existing) => existing === id, chunkMemoryCard(chapterNumber, card));
84
84
  }
85
+ export async function removeChapterFromIndex(projectPath, chapterNumber) {
86
+ const prefix = `chapter:${chapterNumber}:`;
87
+ await upsert(projectPath, (id) => id.startsWith(prefix), []);
88
+ }
89
+ export async function removeMemoryCardFromIndex(projectPath, chapterNumber) {
90
+ const id = `memory:${chapterNumber}`;
91
+ await upsert(projectPath, (existing) => existing === id, []);
92
+ }
85
93
  export async function retrieve(projectPath, query, options = {}) {
86
94
  if (!query.trim())
87
95
  return [];
@@ -12,24 +12,111 @@ export const NovelMetadataSchema = z.object({
12
12
  style: z.string().min(1).default('清晰、连贯、适合长篇连载'),
13
13
  coreCast: z.array(CoreCastMemberSchema).min(1),
14
14
  });
15
+ export const StyleGuideSchema = z.object({
16
+ narrativeVoice: z.string().min(1),
17
+ pacing: z.string().min(1),
18
+ diction: z.string().min(1),
19
+ dialogueRules: z.array(z.string().min(1)).min(1),
20
+ prohibitedPatterns: z.array(z.string().min(1)).min(1),
21
+ proseRhythm: z.object({
22
+ sentenceRhythm: z.string().min(1),
23
+ paragraphing: z.string().min(1),
24
+ interiorityMode: z.string().min(1),
25
+ emphasisBudget: z.string().min(1),
26
+ antiPatterns: z.array(z.string().min(1)).min(1),
27
+ }),
28
+ sampleParagraph: z.string().min(1),
29
+ consistencyChecks: z.array(z.string().min(1)).min(1),
30
+ });
15
31
  export const VolumeArchitectureSchema = z.object({
16
32
  id: z.string().min(1),
17
33
  title: z.string().min(1),
18
34
  summary: z.string().min(1),
19
35
  order: z.number().int().positive(),
20
36
  });
37
+ export const VolumePacingBoardSchema = z.object({
38
+ volumeId: z.string().min(1),
39
+ start: z.string().min(1),
40
+ promise: z.string().min(1),
41
+ keyTurns: z.array(z.string().min(1)).min(1),
42
+ midpoint: z.string().min(1),
43
+ climax: z.string().min(1),
44
+ payoffs: z.array(z.string().min(1)),
45
+ lingeringMysteries: z.array(z.string().min(1)),
46
+ });
47
+ export const EndHookFocusSchema = z.enum([
48
+ 'cliffhanger',
49
+ 'mystery',
50
+ 'emotional',
51
+ 'reveal',
52
+ 'volume_close',
53
+ 'gentle',
54
+ ]);
21
55
  export const ChapterArchitectureSchema = z.object({
22
56
  chapterNumber: z.number().int().positive(),
23
57
  title: z.string().min(1),
24
58
  volumeId: z.string().min(1),
25
59
  summary: z.string().min(1),
26
60
  requiredBeats: z.array(z.string().min(1)).min(1),
61
+ targetWords: z.number().int().positive().optional(),
62
+ requireRecap: z.boolean().optional(),
63
+ endHookFocus: EndHookFocusSchema.optional(),
64
+ povCharacter: z.string().min(1).optional(),
27
65
  });
28
66
  export const ArchitecturePayloadSchema = z.object({
29
67
  full: z.string().min(1),
30
68
  volumes: z.array(VolumeArchitectureSchema).min(1),
69
+ volumePacing: z.array(VolumePacingBoardSchema).optional(),
70
+ chapters: z.array(ChapterArchitectureSchema).min(1),
71
+ });
72
+ export const ArchitectureExtensionPayloadSchema = z.object({
73
+ fullUpdate: z.string().min(1).optional(),
74
+ volumes: z.array(VolumeArchitectureSchema).optional(),
75
+ volumePacing: z.array(VolumePacingBoardSchema).optional(),
31
76
  chapters: z.array(ChapterArchitectureSchema).min(1),
32
77
  });
78
+ export const ThreadActionSchema = z.object({
79
+ kind: z.enum(['plant', 'build', 'pay', 'drop']),
80
+ threadId: z.string().min(1).optional(),
81
+ description: z.string().min(1),
82
+ });
83
+ export const ThreadStatusSchema = z.enum(['planted', 'building', 'paid', 'dropped']);
84
+ export const ThreadSchema = z.object({
85
+ id: z.string().min(1),
86
+ description: z.string().min(1),
87
+ status: ThreadStatusSchema,
88
+ plantedAt: z.number().int().positive(),
89
+ lastTouchedAt: z.number().int().positive(),
90
+ plannedPayoffAt: z.number().int().positive().optional(),
91
+ paidOffAt: z.number().int().positive().optional(),
92
+ droppedAt: z.number().int().positive().optional(),
93
+ notes: z.string().optional(),
94
+ });
95
+ export const CharacterRelationshipStateSchema = z.object({
96
+ name: z.string().min(1),
97
+ dynamic: z.string().min(1),
98
+ });
99
+ export const CharacterStateSchema = z.object({
100
+ name: z.string().min(1),
101
+ role: z.string().min(1).optional(),
102
+ goal: z.string().min(1),
103
+ belief: z.string().min(1),
104
+ relationships: z.array(CharacterRelationshipStateSchema),
105
+ abilities: z.array(z.string().min(1)),
106
+ secrets: z.array(z.string().min(1)),
107
+ emotionalState: z.string().min(1),
108
+ lastUpdatedAt: z.number().int().nonnegative(),
109
+ });
110
+ export const CharacterStateUpdateSchema = z.object({
111
+ name: z.string().min(1),
112
+ role: z.string().min(1).optional(),
113
+ goal: z.string().min(1).optional(),
114
+ belief: z.string().min(1).optional(),
115
+ relationships: z.array(CharacterRelationshipStateSchema).optional(),
116
+ abilities: z.array(z.string().min(1)).optional(),
117
+ secrets: z.array(z.string().min(1)).optional(),
118
+ emotionalState: z.string().min(1).optional(),
119
+ });
33
120
  export const MemoryCardSchema = z.object({
34
121
  summary: z.string().min(1),
35
122
  keyEvents: z.array(z.string().min(1)),
@@ -49,6 +136,9 @@ export const MemoryCardSchema = z.object({
49
136
  after: z.string().min(1),
50
137
  })),
51
138
  openThreads: z.array(z.string().min(1)),
139
+ wordCount: z.number().int().nonnegative().optional(),
140
+ threadActions: z.array(ThreadActionSchema).optional(),
141
+ characterUpdates: z.array(CharacterStateUpdateSchema).optional(),
52
142
  });
53
143
  export const ContinuityReviewSchema = z.object({
54
144
  range: z.object({
@@ -65,14 +155,44 @@ export const ContinuityReviewSchema = z.object({
65
155
  });
66
156
  export const ChapterReviewIssueSchema = z.object({
67
157
  severity: z.enum(['low', 'medium', 'high']),
68
- category: z.enum(['character', 'world', 'timeline', 'item', 'knowledge', 'pacing', 'style', 'architecture']),
158
+ category: z.enum([
159
+ 'character',
160
+ 'world',
161
+ 'timeline',
162
+ 'item',
163
+ 'knowledge',
164
+ 'pacing',
165
+ 'style',
166
+ 'architecture',
167
+ 'plot',
168
+ 'foreshadow',
169
+ 'hook',
170
+ 'repetition',
171
+ ]),
69
172
  description: z.string().min(1),
70
173
  evidence: z.string().min(1),
71
174
  suggestion: z.string().min(1),
72
175
  });
176
+ export const ChapterAcceptanceCheckSchema = z.object({
177
+ status: z.enum(['pass', 'fail']),
178
+ evidence: z.string().min(1),
179
+ });
180
+ export const ChapterAcceptanceGateSchema = z.object({
181
+ requiredBeats: ChapterAcceptanceCheckSchema.extend({
182
+ missingBeats: z.array(z.string().min(1)),
183
+ }),
184
+ narrativeProgress: ChapterAcceptanceCheckSchema,
185
+ characterProgress: ChapterAcceptanceCheckSchema,
186
+ foreshadowProgress: ChapterAcceptanceCheckSchema,
187
+ storyBibleConsistency: ChapterAcceptanceCheckSchema,
188
+ proseRhythm: ChapterAcceptanceCheckSchema,
189
+ endingHook: ChapterAcceptanceCheckSchema,
190
+ repetition: ChapterAcceptanceCheckSchema,
191
+ });
73
192
  export const ChapterReviewSchema = z.object({
74
193
  chapterNumber: z.number().int().positive(),
75
194
  status: z.enum(['clean', 'issues_found']),
195
+ acceptance: ChapterAcceptanceGateSchema,
76
196
  issues: z.array(ChapterReviewIssueSchema),
77
197
  });
78
198
  export const CrossChapterReviewSchema = z.object({
@@ -8,9 +8,15 @@ export const architectureHandler = async (state, content) => {
8
8
  await saveJsonFile(state.projectPath, 'architecture/volumes.json', parsed.volumes),
9
9
  await saveJsonFile(state.projectPath, 'architecture/chapters.json', parsed.chapters),
10
10
  ];
11
+ if (parsed.volumePacing) {
12
+ savedPaths.push(await saveJsonFile(state.projectPath, 'architecture/volume-pacing.json', parsed.volumePacing));
13
+ }
11
14
  return {
12
15
  savedPaths,
13
- fileEntries: { architecture: 'architecture/chapters.json' },
16
+ fileEntries: {
17
+ architecture: 'architecture/chapters.json',
18
+ ...(parsed.volumePacing ? { volumePacing: 'architecture/volume-pacing.json' } : {}),
19
+ },
14
20
  next: { kind: 'linear', nextStep: 'chapter' },
15
21
  };
16
22
  };
@@ -0,0 +1,72 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ import { join } from 'node:path';
3
+ import { ArchitectureExtensionPayloadSchema } from '../schemas.js';
4
+ import { saveJsonFile, saveMarkdownFile } from '../projectStore.js';
5
+ import { parseJson } from './types.js';
6
+ async function readJsonArray(projectPath, relativePath) {
7
+ try {
8
+ const raw = await readFile(join(projectPath, relativePath), 'utf8');
9
+ const parsed = JSON.parse(raw);
10
+ return Array.isArray(parsed) ? parsed : [];
11
+ }
12
+ catch {
13
+ return [];
14
+ }
15
+ }
16
+ function assertContiguousExtension(state, existing, nextChapters) {
17
+ const expectedStart = state.currentChapter;
18
+ const total = state.plannedTotalChapters ?? state.targetChapters;
19
+ const existingNumbers = new Set(existing.map((chapter) => chapter.chapterNumber));
20
+ for (let index = 0; index < nextChapters.length; index += 1) {
21
+ const chapter = nextChapters[index];
22
+ const expected = expectedStart + index;
23
+ if (chapter.chapterNumber !== expected) {
24
+ throw new Error(`architecture_extension chapters must start at chapter ${expectedStart} and be contiguous; expected ${expected}, got ${chapter.chapterNumber}`);
25
+ }
26
+ if (chapter.chapterNumber > total) {
27
+ throw new Error(`architecture_extension chapter ${chapter.chapterNumber} exceeds plannedTotalChapters ${total}`);
28
+ }
29
+ if (existingNumbers.has(chapter.chapterNumber)) {
30
+ throw new Error(`architecture_extension cannot overwrite existing chapter architecture ${chapter.chapterNumber}`);
31
+ }
32
+ }
33
+ }
34
+ function mergeByKey(existing, incoming, keyOf) {
35
+ const map = new Map();
36
+ for (const item of existing)
37
+ map.set(keyOf(item), item);
38
+ for (const item of incoming ?? [])
39
+ map.set(keyOf(item), item);
40
+ return [...map.values()];
41
+ }
42
+ export const architectureExtensionHandler = async (state, content) => {
43
+ const parsed = ArchitectureExtensionPayloadSchema.parse(parseJson(content));
44
+ const existingChapters = await readJsonArray(state.projectPath, 'architecture/chapters.json');
45
+ assertContiguousExtension(state, existingChapters, parsed.chapters);
46
+ const chapters = [...existingChapters, ...parsed.chapters]
47
+ .sort((a, b) => a.chapterNumber - b.chapterNumber);
48
+ const existingVolumes = await readJsonArray(state.projectPath, 'architecture/volumes.json');
49
+ const volumes = mergeByKey(existingVolumes, parsed.volumes, (volume) => volume.id)
50
+ .sort((a, b) => a.order - b.order);
51
+ const existingPacing = await readJsonArray(state.projectPath, 'architecture/volume-pacing.json');
52
+ const volumePacing = mergeByKey(existingPacing, parsed.volumePacing, (board) => board.volumeId);
53
+ const savedPaths = [
54
+ await saveJsonFile(state.projectPath, 'architecture/chapters.json', chapters),
55
+ await saveJsonFile(state.projectPath, 'architecture/volumes.json', volumes),
56
+ ];
57
+ const hasVolumePacing = Boolean(parsed.volumePacing || existingPacing.length);
58
+ if (hasVolumePacing) {
59
+ savedPaths.push(await saveJsonFile(state.projectPath, 'architecture/volume-pacing.json', volumePacing));
60
+ }
61
+ if (parsed.fullUpdate) {
62
+ savedPaths.push(await saveMarkdownFile(state.projectPath, 'architecture/full.md', parsed.fullUpdate));
63
+ }
64
+ return {
65
+ savedPaths,
66
+ fileEntries: {
67
+ architecture: 'architecture/chapters.json',
68
+ ...(hasVolumePacing ? { volumePacing: 'architecture/volume-pacing.json' } : {}),
69
+ },
70
+ next: { kind: 'linear', nextStep: 'chapter' },
71
+ };
72
+ };
@@ -11,6 +11,16 @@ export const chapterHandler = async (state, content) => {
11
11
  return {
12
12
  savedPaths: [path],
13
13
  fileEntries: { [`chapter-${state.currentChapter}`]: relative },
14
- next: { kind: 'linear', nextStep: 'memory_card' },
14
+ next: {
15
+ kind: 'linear',
16
+ nextStep: 'chapter_review',
17
+ statePatch: {
18
+ pendingAction: {
19
+ step: 'chapter_review',
20
+ mode: 'gate',
21
+ chapterNumber: state.currentChapter,
22
+ },
23
+ },
24
+ },
15
25
  };
16
26
  };