novelforge-agent 0.1.0 → 0.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.
- package/README.md +82 -14
- package/dist/src/cli/index.js +92 -2
- package/dist/src/cli/install.js +224 -0
- package/dist/src/core/bibleStore.js +36 -0
- package/dist/src/core/characterStore.js +74 -0
- package/dist/src/core/contextBuilder.js +44 -1
- package/dist/src/core/fileNames.js +4 -0
- package/dist/src/core/index.js +4 -0
- package/dist/src/core/projectOps.js +187 -0
- package/dist/src/core/projectStore.js +11 -0
- package/dist/src/core/prompts/en-US.js +117 -13
- package/dist/src/core/prompts/zh-CN.js +116 -12
- package/dist/src/core/retrieval/index.js +8 -0
- package/dist/src/core/schemas.js +98 -1
- package/dist/src/core/steps/architecture.js +7 -1
- package/dist/src/core/steps/chapter.js +11 -1
- package/dist/src/core/steps/chapterReview.js +25 -1
- package/dist/src/core/steps/chapterRevision.js +17 -0
- package/dist/src/core/steps/memoryCard.js +4 -0
- package/dist/src/core/steps/novelMetadata.js +4 -2
- package/dist/src/core/threadStore.js +150 -0
- package/dist/src/core/workflow.js +3 -3
- package/dist/src/mcp/tools.js +198 -18
- package/package.json +5 -1
- package/src/cli/index.ts +94 -1
- package/src/cli/install.ts +275 -0
- package/src/core/bibleStore.ts +57 -0
- package/src/core/characterStore.ts +93 -0
- package/src/core/contextBuilder.ts +44 -4
- package/src/core/fileNames.ts +5 -0
- package/src/core/index.ts +4 -0
- package/src/core/projectOps.ts +243 -0
- package/src/core/projectStore.ts +11 -0
- package/src/core/prompts/en-US.ts +126 -22
- package/src/core/prompts/types.ts +2 -1
- package/src/core/prompts/zh-CN.ts +118 -14
- package/src/core/retrieval/index.ts +10 -0
- package/src/core/schemas.ts +108 -1
- package/src/core/steps/architecture.ts +7 -1
- package/src/core/steps/chapter.ts +11 -1
- package/src/core/steps/chapterReview.ts +27 -1
- package/src/core/steps/chapterRevision.ts +18 -0
- package/src/core/steps/memoryCard.ts +4 -0
- package/src/core/steps/novelMetadata.ts +4 -2
- package/src/core/threadStore.ts +173 -0
- package/src/core/types.ts +102 -1
- package/src/core/workflow.ts +3 -3
- package/src/mcp/tools.ts +322 -19
|
@@ -101,6 +101,18 @@ ${input.context ? `## 已有上下文\n${input.context}\n` : ''}## 输出要求
|
|
|
101
101
|
"order": 1
|
|
102
102
|
}
|
|
103
103
|
],
|
|
104
|
+
"volumePacing": [
|
|
105
|
+
{
|
|
106
|
+
"volumeId": "v1",
|
|
107
|
+
"start": "本卷起点:主角/世界/冲突处于什么状态",
|
|
108
|
+
"promise": "本卷向读者承诺的核心看点或问题",
|
|
109
|
+
"keyTurns": ["关键转折1", "关键转折2"],
|
|
110
|
+
"midpoint": "本卷中点转折或认知变化",
|
|
111
|
+
"climax": "本卷高潮",
|
|
112
|
+
"payoffs": ["本卷计划回收的伏笔或承诺"],
|
|
113
|
+
"lingeringMysteries": ["卷末仍要保留的悬念"]
|
|
114
|
+
}
|
|
115
|
+
],
|
|
104
116
|
"chapters": [
|
|
105
117
|
{
|
|
106
118
|
"chapterNumber": 1,
|
|
@@ -116,35 +128,49 @@ ${input.context ? `## 已有上下文\n${input.context}\n` : ''}## 输出要求
|
|
|
116
128
|
- chapters.length 必须大于等于 ${input.state.targetChapters}。
|
|
117
129
|
- chapterNumber 从 1 开始连续递增。
|
|
118
130
|
- volumeId 必须引用 volumes 中存在的 id。
|
|
131
|
+
- volumePacing 必须为每个 volume 提供节奏板。
|
|
119
132
|
- requiredBeats 至少 1 条,且必须具体可执行。
|
|
120
133
|
${strictJsonOutputRules()}`,
|
|
121
134
|
};
|
|
122
135
|
}
|
|
123
136
|
function buildChapterPrompt(input) {
|
|
137
|
+
const ch = input.state.currentChapter;
|
|
138
|
+
const isFirstChapter = ch <= 1;
|
|
124
139
|
return {
|
|
125
140
|
purpose: 'chapter',
|
|
126
141
|
expectedFormat: 'Markdown',
|
|
127
|
-
prompt: `你是一位擅长创作长篇网络小说的职业作者。请直接完成第 ${
|
|
142
|
+
prompt: `你是一位擅长创作长篇网络小说的职业作者。请直接完成第 ${ch} 章正文。
|
|
128
143
|
|
|
129
144
|
## 执行优先级
|
|
130
|
-
1.
|
|
131
|
-
2.
|
|
132
|
-
3.
|
|
145
|
+
1. 先严格遵守"本章架构、用户补充要求、故事圣经硬约束、上一章承接"。
|
|
146
|
+
2. 再参考"历史相关记忆、历史原文证据、活跃伏笔"保证一致性。
|
|
147
|
+
3. 最后才参考"全本/本卷远场规划",且不得提前写出尚未发生的情节。
|
|
148
|
+
|
|
149
|
+
## 字数目标
|
|
150
|
+
- 默认目标 3000 字(±20%)。如果本章架构里指定了 targetWords,按那个目标。
|
|
151
|
+
- 不要为了凑字数注水;也不要为了简洁牺牲冲突推进。
|
|
133
152
|
|
|
134
|
-
##
|
|
153
|
+
## 结构要求
|
|
154
|
+
${isFirstChapter
|
|
155
|
+
? '- 这是第 1 章,不需要"上回提要"。开篇直接立人物、立情境。'
|
|
156
|
+
: '- 章首需要 2-3 句"上回提要"或"承接段",让没读上一章的读者能续上(除非本章架构 requireRecap=false)。要自然带入,不要写成"上一章里……"的元叙述。'}
|
|
157
|
+
- 章末必须有清晰的"钩子":可以是悬念、反转、剧情承诺、情绪余韵或卷末高潮——按本章架构 endHookFocus 字段决定。如果未指定,默认用悬念。
|
|
158
|
+
|
|
159
|
+
## 风格
|
|
135
160
|
- 文风必须与本书题材、世界观、人物身份、情感基调一致。
|
|
136
|
-
-
|
|
137
|
-
-
|
|
138
|
-
-
|
|
139
|
-
-
|
|
161
|
+
- 语言自然、稳定、可读,优先服务叙事推进、人物塑造和情绪积累。
|
|
162
|
+
- 对话符合人物身份、关系和处境;重要情绪通过动作、神态、节奏、潜台词体现。
|
|
163
|
+
- 场景描写有必要的感官细节与氛围支撑,但篇幅服务剧情。
|
|
164
|
+
- POV 严格按本章架构 povCharacter(如有),中途不切换视角。
|
|
140
165
|
|
|
141
166
|
## 执行规则
|
|
142
167
|
- 只写本章架构明确覆盖的内容,不得提前写后续章节具体事件或人物揭示。
|
|
143
|
-
-
|
|
168
|
+
- 不得新增本章架构未授权的主要人物;功能性角色轻描淡写。
|
|
144
169
|
- 所有人物称谓、物品、场景、能力、时间线必须与既有设定一致。
|
|
145
170
|
- 如果上一章结尾仍在动作、对话或同一场景中,本章开头必须连续衔接。
|
|
171
|
+
- 活跃伏笔列表中的条目本章可以"推进"或"回收",但**不得无声无息地删除**——若选择不触碰也要让它仍然成立。
|
|
146
172
|
- 禁止无代价越级碾压、强行降智配角、突兀机械反转、硬灌设定、空洞抒情。
|
|
147
|
-
-
|
|
173
|
+
- 禁止总结腔、条目腔、说教腔,不要输出解释性前言或"我修改了什么"之类的元文本。
|
|
148
174
|
|
|
149
175
|
${input.context ? `## 生成上下文\n${input.context}\n` : ''}## 输出要求
|
|
150
176
|
- 输出 Markdown。
|
|
@@ -184,13 +210,41 @@ ${input.context ? `## 当前章上下文\n${input.context}\n` : ''}## 输出要
|
|
|
184
210
|
"after": "变化后"
|
|
185
211
|
}
|
|
186
212
|
],
|
|
187
|
-
"openThreads": ["尚未解决的伏笔、承诺、危险或疑问"]
|
|
213
|
+
"openThreads": ["尚未解决的伏笔、承诺、危险或疑问"],
|
|
214
|
+
"wordCount": 本章实际字数(整数估算即可),
|
|
215
|
+
"threadActions": [
|
|
216
|
+
{
|
|
217
|
+
"kind": "plant | build | pay | drop",
|
|
218
|
+
"threadId": "已有伏笔的 id(如果是 plant 留空让系统分配;build/pay/drop 必须填活跃伏笔列表里的 id)",
|
|
219
|
+
"description": "新伏笔的描述(plant 时必填)或本章如何推进/回收/丢弃这条伏笔的一句话"
|
|
220
|
+
}
|
|
221
|
+
],
|
|
222
|
+
"characterUpdates": [
|
|
223
|
+
{
|
|
224
|
+
"name": "人物姓名",
|
|
225
|
+
"role": "角色定位(如本章确认或改变)",
|
|
226
|
+
"goal": "本章结束时的当前目标",
|
|
227
|
+
"belief": "本章结束时影响其行动的核心认知/信念",
|
|
228
|
+
"relationships": [
|
|
229
|
+
{ "name": "相关人物", "dynamic": "本章结束时的关系状态" }
|
|
230
|
+
],
|
|
231
|
+
"abilities": ["本章结束时确认拥有的能力、资源或限制"],
|
|
232
|
+
"secrets": ["本章结束时仍未公开或只被部分人知道的秘密"],
|
|
233
|
+
"emotionalState": "本章结束时的情绪状态"
|
|
234
|
+
}
|
|
235
|
+
]
|
|
188
236
|
}
|
|
189
237
|
|
|
190
238
|
要求:
|
|
191
239
|
- 只记录已经在本章发生或被确认的信息。
|
|
192
240
|
- 不要推测后续剧情。
|
|
193
241
|
- facts 和 stateChanges 要具体,便于后续章节引用。
|
|
242
|
+
- wordCount 用中文字符数(去掉空格和 Markdown 标记),近似估算即可。
|
|
243
|
+
- threadActions 是关键:
|
|
244
|
+
· 任何"上下文里 Active Foreshadow Threads"列出的活跃伏笔,如果本章推进了,请发 kind="build";如果本章正式回收/兑现,请发 kind="pay";如果本章决定放弃,请发 kind="drop"。这三种情况 threadId 必填。
|
|
245
|
+
· 本章新埋设的伏笔,请发 kind="plant",description 写清楚是什么伏笔。
|
|
246
|
+
· 活跃伏笔本章没动也没关系,不需要为它发动作;但**不要悄悄删除**——只要不发 drop,它就继续保留活跃。
|
|
247
|
+
- characterUpdates 用于维护独立角色状态表:只输出本章有明确变化或被重新确认的重要人物;目标、信念、关系、能力、秘密、情绪状态必须以本章结尾为准。
|
|
194
248
|
${strictJsonOutputRules()}`,
|
|
195
249
|
};
|
|
196
250
|
}
|
|
@@ -240,6 +294,12 @@ function buildChapterReviewPrompt(input) {
|
|
|
240
294
|
prompt: `你是一名严格的章节审稿编辑。请审阅指定章节是否存在内部问题以及与既有设定的冲突。
|
|
241
295
|
|
|
242
296
|
${input.context ? `## 审阅上下文\n${input.context}\n` : ''}## 审阅重点
|
|
297
|
+
- 这是强制章节验收门槛:只要任一验收项 fail,status 必须是 "issues_found",不能进入下一章。
|
|
298
|
+
- requiredBeats 是否全部完成;缺失项必须写入 acceptance.requiredBeats.missingBeats。
|
|
299
|
+
- 本章是否推进主线、人物状态或活跃伏笔;如果完全原地踏步,narrativeProgress/characterProgress/foreshadowProgress 至少一项必须 fail。
|
|
300
|
+
- 是否违反故事圣经、角色状态表、卷级节奏板或历史记忆。
|
|
301
|
+
- 章末是否有清晰钩子,且符合本章 endHookFocus。
|
|
302
|
+
- 是否重复之前章节已经完成的桥段、冲突结构、信息揭示或对话功能。
|
|
243
303
|
- 人物声音、动机、状态是否符合故事圣经与历史记忆。
|
|
244
304
|
- 世界规则、物品归属、能力边界是否被破坏。
|
|
245
305
|
- 时间线、地点、与上一章结尾的衔接是否一致。
|
|
@@ -251,6 +311,37 @@ ${input.context ? `## 审阅上下文\n${input.context}\n` : ''}## 审阅重点
|
|
|
251
311
|
{
|
|
252
312
|
"chapterNumber": ${chapter},
|
|
253
313
|
"status": "clean",
|
|
314
|
+
"acceptance": {
|
|
315
|
+
"requiredBeats": {
|
|
316
|
+
"status": "pass | fail",
|
|
317
|
+
"evidence": "逐条说明 requiredBeats 完成证据",
|
|
318
|
+
"missingBeats": []
|
|
319
|
+
},
|
|
320
|
+
"narrativeProgress": {
|
|
321
|
+
"status": "pass | fail",
|
|
322
|
+
"evidence": "本章如何推进主线/阶段目标"
|
|
323
|
+
},
|
|
324
|
+
"characterProgress": {
|
|
325
|
+
"status": "pass | fail",
|
|
326
|
+
"evidence": "本章如何改变或确认关键人物目标、信念、关系、能力、秘密或情绪"
|
|
327
|
+
},
|
|
328
|
+
"foreshadowProgress": {
|
|
329
|
+
"status": "pass | fail",
|
|
330
|
+
"evidence": "本章如何埋设、推进、回收或有意识保留伏笔"
|
|
331
|
+
},
|
|
332
|
+
"storyBibleConsistency": {
|
|
333
|
+
"status": "pass | fail",
|
|
334
|
+
"evidence": "是否符合故事圣经、角色状态表和世界规则"
|
|
335
|
+
},
|
|
336
|
+
"endingHook": {
|
|
337
|
+
"status": "pass | fail",
|
|
338
|
+
"evidence": "章末钩子的具体段落和作用"
|
|
339
|
+
},
|
|
340
|
+
"repetition": {
|
|
341
|
+
"status": "pass | fail",
|
|
342
|
+
"evidence": "是否重复既有桥段;无重复也要说明依据"
|
|
343
|
+
}
|
|
344
|
+
},
|
|
254
345
|
"issues": [
|
|
255
346
|
{
|
|
256
347
|
"severity": "low | medium | high",
|
|
@@ -265,6 +356,8 @@ ${input.context ? `## 审阅上下文\n${input.context}\n` : ''}## 审阅重点
|
|
|
265
356
|
要求:
|
|
266
357
|
- 没有问题时 status 为 "clean",issues 输出空数组。
|
|
267
358
|
- 有问题时 status 为 "issues_found"。
|
|
359
|
+
- 只有所有 acceptance 项都是 "pass" 时,status 才能为 "clean"。
|
|
360
|
+
- 任一 acceptance 项为 "fail" 时,必须在 issues 中写出对应问题与修复建议。
|
|
268
361
|
- evidence 必须具体,不能写"疑似"、"可能"。
|
|
269
362
|
${strictJsonOutputRules()}`,
|
|
270
363
|
};
|
|
@@ -348,6 +441,17 @@ function buildPromptForStep(input) {
|
|
|
348
441
|
return buildChapterRevisionPrompt(input);
|
|
349
442
|
case 'cross_chapter_review':
|
|
350
443
|
return buildCrossChapterReviewPrompt(input);
|
|
444
|
+
case 'story_bible_amend':
|
|
445
|
+
return {
|
|
446
|
+
purpose: 'story_bible',
|
|
447
|
+
expectedFormat: 'Markdown',
|
|
448
|
+
prompt: `请基于当前已有故事圣经与本次反馈,输出"修订后的完整故事圣经 Markdown"。
|
|
449
|
+
|
|
450
|
+
${input.context ? `## 修订上下文\n${input.context}\n` : ''}## 输出要求
|
|
451
|
+
- 输出完整的 story-bible.md 内容,覆盖式替换旧版(旧版会自动归档到 story-bible-versions/)。
|
|
452
|
+
- 保留旧版仍然成立的内容,仅修改 / 新增 / 删除有明确依据的部分。
|
|
453
|
+
- 不要输出 diff、变更说明、bullet 总结,直接输出新 bible 全文。`,
|
|
454
|
+
};
|
|
351
455
|
case 'complete':
|
|
352
456
|
return {
|
|
353
457
|
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 [];
|
package/dist/src/core/schemas.js
CHANGED
|
@@ -18,18 +18,83 @@ export const VolumeArchitectureSchema = z.object({
|
|
|
18
18
|
summary: z.string().min(1),
|
|
19
19
|
order: z.number().int().positive(),
|
|
20
20
|
});
|
|
21
|
+
export const VolumePacingBoardSchema = z.object({
|
|
22
|
+
volumeId: z.string().min(1),
|
|
23
|
+
start: z.string().min(1),
|
|
24
|
+
promise: z.string().min(1),
|
|
25
|
+
keyTurns: z.array(z.string().min(1)).min(1),
|
|
26
|
+
midpoint: z.string().min(1),
|
|
27
|
+
climax: z.string().min(1),
|
|
28
|
+
payoffs: z.array(z.string().min(1)),
|
|
29
|
+
lingeringMysteries: z.array(z.string().min(1)),
|
|
30
|
+
});
|
|
31
|
+
export const EndHookFocusSchema = z.enum([
|
|
32
|
+
'cliffhanger',
|
|
33
|
+
'mystery',
|
|
34
|
+
'emotional',
|
|
35
|
+
'reveal',
|
|
36
|
+
'volume_close',
|
|
37
|
+
'gentle',
|
|
38
|
+
]);
|
|
21
39
|
export const ChapterArchitectureSchema = z.object({
|
|
22
40
|
chapterNumber: z.number().int().positive(),
|
|
23
41
|
title: z.string().min(1),
|
|
24
42
|
volumeId: z.string().min(1),
|
|
25
43
|
summary: z.string().min(1),
|
|
26
44
|
requiredBeats: z.array(z.string().min(1)).min(1),
|
|
45
|
+
targetWords: z.number().int().positive().optional(),
|
|
46
|
+
requireRecap: z.boolean().optional(),
|
|
47
|
+
endHookFocus: EndHookFocusSchema.optional(),
|
|
48
|
+
povCharacter: z.string().min(1).optional(),
|
|
27
49
|
});
|
|
28
50
|
export const ArchitecturePayloadSchema = z.object({
|
|
29
51
|
full: z.string().min(1),
|
|
30
52
|
volumes: z.array(VolumeArchitectureSchema).min(1),
|
|
53
|
+
volumePacing: z.array(VolumePacingBoardSchema).optional(),
|
|
31
54
|
chapters: z.array(ChapterArchitectureSchema).min(1),
|
|
32
55
|
});
|
|
56
|
+
export const ThreadActionSchema = z.object({
|
|
57
|
+
kind: z.enum(['plant', 'build', 'pay', 'drop']),
|
|
58
|
+
threadId: z.string().min(1).optional(),
|
|
59
|
+
description: z.string().min(1),
|
|
60
|
+
});
|
|
61
|
+
export const ThreadStatusSchema = z.enum(['planted', 'building', 'paid', 'dropped']);
|
|
62
|
+
export const ThreadSchema = z.object({
|
|
63
|
+
id: z.string().min(1),
|
|
64
|
+
description: z.string().min(1),
|
|
65
|
+
status: ThreadStatusSchema,
|
|
66
|
+
plantedAt: z.number().int().positive(),
|
|
67
|
+
lastTouchedAt: z.number().int().positive(),
|
|
68
|
+
plannedPayoffAt: z.number().int().positive().optional(),
|
|
69
|
+
paidOffAt: z.number().int().positive().optional(),
|
|
70
|
+
droppedAt: z.number().int().positive().optional(),
|
|
71
|
+
notes: z.string().optional(),
|
|
72
|
+
});
|
|
73
|
+
export const CharacterRelationshipStateSchema = z.object({
|
|
74
|
+
name: z.string().min(1),
|
|
75
|
+
dynamic: z.string().min(1),
|
|
76
|
+
});
|
|
77
|
+
export const CharacterStateSchema = z.object({
|
|
78
|
+
name: z.string().min(1),
|
|
79
|
+
role: z.string().min(1).optional(),
|
|
80
|
+
goal: z.string().min(1),
|
|
81
|
+
belief: z.string().min(1),
|
|
82
|
+
relationships: z.array(CharacterRelationshipStateSchema),
|
|
83
|
+
abilities: z.array(z.string().min(1)),
|
|
84
|
+
secrets: z.array(z.string().min(1)),
|
|
85
|
+
emotionalState: z.string().min(1),
|
|
86
|
+
lastUpdatedAt: z.number().int().nonnegative(),
|
|
87
|
+
});
|
|
88
|
+
export const CharacterStateUpdateSchema = z.object({
|
|
89
|
+
name: z.string().min(1),
|
|
90
|
+
role: z.string().min(1).optional(),
|
|
91
|
+
goal: z.string().min(1).optional(),
|
|
92
|
+
belief: z.string().min(1).optional(),
|
|
93
|
+
relationships: z.array(CharacterRelationshipStateSchema).optional(),
|
|
94
|
+
abilities: z.array(z.string().min(1)).optional(),
|
|
95
|
+
secrets: z.array(z.string().min(1)).optional(),
|
|
96
|
+
emotionalState: z.string().min(1).optional(),
|
|
97
|
+
});
|
|
33
98
|
export const MemoryCardSchema = z.object({
|
|
34
99
|
summary: z.string().min(1),
|
|
35
100
|
keyEvents: z.array(z.string().min(1)),
|
|
@@ -49,6 +114,9 @@ export const MemoryCardSchema = z.object({
|
|
|
49
114
|
after: z.string().min(1),
|
|
50
115
|
})),
|
|
51
116
|
openThreads: z.array(z.string().min(1)),
|
|
117
|
+
wordCount: z.number().int().nonnegative().optional(),
|
|
118
|
+
threadActions: z.array(ThreadActionSchema).optional(),
|
|
119
|
+
characterUpdates: z.array(CharacterStateUpdateSchema).optional(),
|
|
52
120
|
});
|
|
53
121
|
export const ContinuityReviewSchema = z.object({
|
|
54
122
|
range: z.object({
|
|
@@ -65,14 +133,43 @@ export const ContinuityReviewSchema = z.object({
|
|
|
65
133
|
});
|
|
66
134
|
export const ChapterReviewIssueSchema = z.object({
|
|
67
135
|
severity: z.enum(['low', 'medium', 'high']),
|
|
68
|
-
category: z.enum([
|
|
136
|
+
category: z.enum([
|
|
137
|
+
'character',
|
|
138
|
+
'world',
|
|
139
|
+
'timeline',
|
|
140
|
+
'item',
|
|
141
|
+
'knowledge',
|
|
142
|
+
'pacing',
|
|
143
|
+
'style',
|
|
144
|
+
'architecture',
|
|
145
|
+
'plot',
|
|
146
|
+
'foreshadow',
|
|
147
|
+
'hook',
|
|
148
|
+
'repetition',
|
|
149
|
+
]),
|
|
69
150
|
description: z.string().min(1),
|
|
70
151
|
evidence: z.string().min(1),
|
|
71
152
|
suggestion: z.string().min(1),
|
|
72
153
|
});
|
|
154
|
+
export const ChapterAcceptanceCheckSchema = z.object({
|
|
155
|
+
status: z.enum(['pass', 'fail']),
|
|
156
|
+
evidence: z.string().min(1),
|
|
157
|
+
});
|
|
158
|
+
export const ChapterAcceptanceGateSchema = z.object({
|
|
159
|
+
requiredBeats: ChapterAcceptanceCheckSchema.extend({
|
|
160
|
+
missingBeats: z.array(z.string().min(1)),
|
|
161
|
+
}),
|
|
162
|
+
narrativeProgress: ChapterAcceptanceCheckSchema,
|
|
163
|
+
characterProgress: ChapterAcceptanceCheckSchema,
|
|
164
|
+
foreshadowProgress: ChapterAcceptanceCheckSchema,
|
|
165
|
+
storyBibleConsistency: ChapterAcceptanceCheckSchema,
|
|
166
|
+
endingHook: ChapterAcceptanceCheckSchema,
|
|
167
|
+
repetition: ChapterAcceptanceCheckSchema,
|
|
168
|
+
});
|
|
73
169
|
export const ChapterReviewSchema = z.object({
|
|
74
170
|
chapterNumber: z.number().int().positive(),
|
|
75
171
|
status: z.enum(['clean', 'issues_found']),
|
|
172
|
+
acceptance: ChapterAcceptanceGateSchema,
|
|
76
173
|
issues: z.array(ChapterReviewIssueSchema),
|
|
77
174
|
});
|
|
78
175
|
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: {
|
|
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
|
};
|
|
@@ -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: {
|
|
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
|
};
|
|
@@ -8,9 +8,33 @@ export const chapterReviewHandler = async (state, content) => {
|
|
|
8
8
|
const target = state.pendingAction?.chapterNumber ?? parsed.chapterNumber;
|
|
9
9
|
const relative = join('reviews/chapter', chapterReviewFileName(target));
|
|
10
10
|
const path = await saveJsonFile(state.projectPath, relative, parsed);
|
|
11
|
+
if (state.pendingAction?.mode === 'side_track') {
|
|
12
|
+
return {
|
|
13
|
+
savedPaths: [path],
|
|
14
|
+
fileEntries: { [`review-chapter-${target}`]: relative },
|
|
15
|
+
next: { kind: 'sideTrackReturn' },
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
if (parsed.status === 'clean') {
|
|
19
|
+
return {
|
|
20
|
+
savedPaths: [path],
|
|
21
|
+
fileEntries: { [`review-chapter-${target}`]: relative },
|
|
22
|
+
next: { kind: 'linear', nextStep: 'memory_card' },
|
|
23
|
+
};
|
|
24
|
+
}
|
|
11
25
|
return {
|
|
12
26
|
savedPaths: [path],
|
|
13
27
|
fileEntries: { [`review-chapter-${target}`]: relative },
|
|
14
|
-
next: {
|
|
28
|
+
next: {
|
|
29
|
+
kind: 'linear',
|
|
30
|
+
nextStep: 'chapter_revision',
|
|
31
|
+
statePatch: {
|
|
32
|
+
pendingAction: {
|
|
33
|
+
step: 'chapter_revision',
|
|
34
|
+
mode: 'gate',
|
|
35
|
+
chapterNumber: target,
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
},
|
|
15
39
|
};
|
|
16
40
|
};
|
|
@@ -12,6 +12,23 @@ export const chapterRevisionHandler = async (state, content) => {
|
|
|
12
12
|
const savedPaths = archived ? [archived] : [];
|
|
13
13
|
savedPaths.push(await saveMarkdownFile(state.projectPath, chapterRelative, content));
|
|
14
14
|
await indexChapter(state.projectPath, target, content);
|
|
15
|
+
if (state.pendingAction?.mode === 'gate') {
|
|
16
|
+
return {
|
|
17
|
+
savedPaths,
|
|
18
|
+
fileEntries: { [`chapter-${target}`]: chapterRelative },
|
|
19
|
+
next: {
|
|
20
|
+
kind: 'linear',
|
|
21
|
+
nextStep: 'chapter_review',
|
|
22
|
+
statePatch: {
|
|
23
|
+
pendingAction: {
|
|
24
|
+
step: 'chapter_review',
|
|
25
|
+
mode: 'gate',
|
|
26
|
+
chapterNumber: target,
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
15
32
|
return {
|
|
16
33
|
savedPaths,
|
|
17
34
|
fileEntries: { [`chapter-${target}`]: chapterRelative },
|
|
@@ -3,12 +3,16 @@ import { MemoryCardSchema } from '../schemas.js';
|
|
|
3
3
|
import { saveJsonFile } from '../projectStore.js';
|
|
4
4
|
import { memoryFileName } from '../fileNames.js';
|
|
5
5
|
import { indexMemoryCard } from '../retrieval/index.js';
|
|
6
|
+
import { ingestMemoryCardThreads } from '../threadStore.js';
|
|
7
|
+
import { applyCharacterUpdates } from '../characterStore.js';
|
|
6
8
|
import { parseJson } from './types.js';
|
|
7
9
|
export const memoryCardHandler = async (state, content) => {
|
|
8
10
|
const parsed = MemoryCardSchema.parse(parseJson(content));
|
|
9
11
|
const relative = join('memory', memoryFileName(state.currentChapter));
|
|
10
12
|
const path = await saveJsonFile(state.projectPath, relative, parsed);
|
|
11
13
|
await indexMemoryCard(state.projectPath, state.currentChapter, parsed);
|
|
14
|
+
await ingestMemoryCardThreads(state.projectPath, state.currentChapter, parsed.threadActions);
|
|
15
|
+
await applyCharacterUpdates(state.projectPath, state.currentChapter, parsed.characterUpdates);
|
|
12
16
|
const nextChapter = state.currentChapter + 1;
|
|
13
17
|
return {
|
|
14
18
|
savedPaths: [path],
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { NovelMetadataSchema } from '../schemas.js';
|
|
2
2
|
import { saveJsonFile } from '../projectStore.js';
|
|
3
|
+
import { initializeCharacterStates } from '../characterStore.js';
|
|
3
4
|
import { parseJson } from './types.js';
|
|
4
5
|
export const novelMetadataHandler = async (state, content) => {
|
|
5
6
|
const parsed = NovelMetadataSchema.parse(parseJson(content));
|
|
6
7
|
const path = await saveJsonFile(state.projectPath, 'novel.json', parsed);
|
|
8
|
+
const charactersPath = await initializeCharacterStates(state.projectPath, parsed.coreCast);
|
|
7
9
|
return {
|
|
8
|
-
savedPaths: [path],
|
|
9
|
-
fileEntries: { novel: 'novel.json' },
|
|
10
|
+
savedPaths: [path, charactersPath],
|
|
11
|
+
fileEntries: { novel: 'novel.json', characters: 'characters.json' },
|
|
10
12
|
next: { kind: 'linear', nextStep: 'story_bible' },
|
|
11
13
|
};
|
|
12
14
|
};
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { randomBytes } from 'node:crypto';
|
|
2
|
+
import { readFile, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
const THREADS_FILE = 'threads.json';
|
|
5
|
+
export async function loadThreads(projectPath) {
|
|
6
|
+
try {
|
|
7
|
+
const raw = await readFile(join(projectPath, THREADS_FILE), 'utf8');
|
|
8
|
+
const parsed = JSON.parse(raw);
|
|
9
|
+
return Array.isArray(parsed.threads) ? parsed.threads : [];
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
return [];
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export async function saveThreads(projectPath, threads) {
|
|
16
|
+
const fullPath = join(projectPath, THREADS_FILE);
|
|
17
|
+
const bundle = { threads };
|
|
18
|
+
await writeFile(fullPath, `${JSON.stringify(bundle, null, 2)}\n`, 'utf8');
|
|
19
|
+
return fullPath;
|
|
20
|
+
}
|
|
21
|
+
function newThreadId(existing) {
|
|
22
|
+
let candidate = `t_${randomBytes(3).toString('hex')}`;
|
|
23
|
+
while (existing.has(candidate)) {
|
|
24
|
+
candidate = `t_${randomBytes(3).toString('hex')}`;
|
|
25
|
+
}
|
|
26
|
+
return candidate;
|
|
27
|
+
}
|
|
28
|
+
function findByDescription(threads, description) {
|
|
29
|
+
const target = description.trim();
|
|
30
|
+
return threads.find((t) => t.description.trim() === target);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Apply the threadActions emitted by a memory_card for chapter `chapterNumber`.
|
|
34
|
+
* Behavior:
|
|
35
|
+
* - 'plant' → create new thread (or reuse if identical description already planted)
|
|
36
|
+
* - 'build' → mark existing thread status = 'building', bump lastTouchedAt
|
|
37
|
+
* - 'pay' → mark existing thread status = 'paid', set paidOffAt
|
|
38
|
+
* - 'drop' → mark existing thread status = 'dropped', set droppedAt
|
|
39
|
+
* Unknown threadIds for non-plant actions are tolerated (a new thread is created and marked appropriately, so we never lose user intent).
|
|
40
|
+
*/
|
|
41
|
+
export function applyThreadActions(existing, chapterNumber, actions) {
|
|
42
|
+
if (!actions || !actions.length)
|
|
43
|
+
return existing;
|
|
44
|
+
const next = existing.map((t) => ({ ...t }));
|
|
45
|
+
const byId = new Map(next.map((t) => [t.id, t]));
|
|
46
|
+
const usedIds = new Set(next.map((t) => t.id));
|
|
47
|
+
for (const action of actions) {
|
|
48
|
+
if (action.kind === 'plant') {
|
|
49
|
+
const dup = findByDescription(next, action.description);
|
|
50
|
+
if (dup) {
|
|
51
|
+
dup.lastTouchedAt = Math.max(dup.lastTouchedAt, chapterNumber);
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
const id = action.threadId && !usedIds.has(action.threadId)
|
|
55
|
+
? action.threadId
|
|
56
|
+
: newThreadId(usedIds);
|
|
57
|
+
usedIds.add(id);
|
|
58
|
+
const planted = {
|
|
59
|
+
id,
|
|
60
|
+
description: action.description.trim(),
|
|
61
|
+
status: 'planted',
|
|
62
|
+
plantedAt: chapterNumber,
|
|
63
|
+
lastTouchedAt: chapterNumber,
|
|
64
|
+
};
|
|
65
|
+
next.push(planted);
|
|
66
|
+
byId.set(id, planted);
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
// build / pay / drop need an existing thread
|
|
70
|
+
let target = action.threadId ? byId.get(action.threadId) : undefined;
|
|
71
|
+
if (!target) {
|
|
72
|
+
target = findByDescription(next, action.description);
|
|
73
|
+
}
|
|
74
|
+
if (!target) {
|
|
75
|
+
// Create a placeholder so the user intent is captured; mark planted+touched on this chapter
|
|
76
|
+
const id = newThreadId(usedIds);
|
|
77
|
+
usedIds.add(id);
|
|
78
|
+
target = {
|
|
79
|
+
id,
|
|
80
|
+
description: action.description.trim(),
|
|
81
|
+
status: 'planted',
|
|
82
|
+
plantedAt: chapterNumber,
|
|
83
|
+
lastTouchedAt: chapterNumber,
|
|
84
|
+
notes: `Auto-created from a ${action.kind} action without a known threadId.`,
|
|
85
|
+
};
|
|
86
|
+
next.push(target);
|
|
87
|
+
byId.set(id, target);
|
|
88
|
+
}
|
|
89
|
+
target.lastTouchedAt = chapterNumber;
|
|
90
|
+
if (action.kind === 'build') {
|
|
91
|
+
target.status = 'building';
|
|
92
|
+
}
|
|
93
|
+
else if (action.kind === 'pay') {
|
|
94
|
+
target.status = 'paid';
|
|
95
|
+
target.paidOffAt = chapterNumber;
|
|
96
|
+
}
|
|
97
|
+
else if (action.kind === 'drop') {
|
|
98
|
+
target.status = 'dropped';
|
|
99
|
+
target.droppedAt = chapterNumber;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return next;
|
|
103
|
+
}
|
|
104
|
+
export function activeThreads(threads) {
|
|
105
|
+
return threads.filter((t) => t.status === 'planted' || t.status === 'building');
|
|
106
|
+
}
|
|
107
|
+
export async function ingestMemoryCardThreads(projectPath, chapterNumber, actions) {
|
|
108
|
+
if (!actions || !actions.length)
|
|
109
|
+
return loadThreads(projectPath);
|
|
110
|
+
const existing = await loadThreads(projectPath);
|
|
111
|
+
const next = applyThreadActions(existing, chapterNumber, actions);
|
|
112
|
+
await saveThreads(projectPath, next);
|
|
113
|
+
return next;
|
|
114
|
+
}
|
|
115
|
+
export async function updateThread(projectPath, id, patch) {
|
|
116
|
+
const existing = await loadThreads(projectPath);
|
|
117
|
+
const target = existing.find((t) => t.id === id);
|
|
118
|
+
if (!target)
|
|
119
|
+
throw new Error(`Thread not found: ${id}`);
|
|
120
|
+
if (patch.status)
|
|
121
|
+
target.status = patch.status;
|
|
122
|
+
if (patch.description)
|
|
123
|
+
target.description = patch.description.trim();
|
|
124
|
+
if (Object.prototype.hasOwnProperty.call(patch, 'plannedPayoffAt')) {
|
|
125
|
+
if (patch.plannedPayoffAt === null)
|
|
126
|
+
delete target.plannedPayoffAt;
|
|
127
|
+
else if (typeof patch.plannedPayoffAt === 'number')
|
|
128
|
+
target.plannedPayoffAt = patch.plannedPayoffAt;
|
|
129
|
+
}
|
|
130
|
+
if (Object.prototype.hasOwnProperty.call(patch, 'paidOffAt')) {
|
|
131
|
+
if (patch.paidOffAt === null)
|
|
132
|
+
delete target.paidOffAt;
|
|
133
|
+
else if (typeof patch.paidOffAt === 'number')
|
|
134
|
+
target.paidOffAt = patch.paidOffAt;
|
|
135
|
+
}
|
|
136
|
+
if (Object.prototype.hasOwnProperty.call(patch, 'droppedAt')) {
|
|
137
|
+
if (patch.droppedAt === null)
|
|
138
|
+
delete target.droppedAt;
|
|
139
|
+
else if (typeof patch.droppedAt === 'number')
|
|
140
|
+
target.droppedAt = patch.droppedAt;
|
|
141
|
+
}
|
|
142
|
+
if (Object.prototype.hasOwnProperty.call(patch, 'notes')) {
|
|
143
|
+
if (patch.notes === null)
|
|
144
|
+
delete target.notes;
|
|
145
|
+
else if (typeof patch.notes === 'string')
|
|
146
|
+
target.notes = patch.notes;
|
|
147
|
+
}
|
|
148
|
+
await saveThreads(projectPath, existing);
|
|
149
|
+
return target;
|
|
150
|
+
}
|
|
@@ -83,19 +83,19 @@ function buildPendingAction(state, input) {
|
|
|
83
83
|
case 'chapter_review': {
|
|
84
84
|
if (!input.chapterNumber)
|
|
85
85
|
throw new Error('chapter_review requires chapterNumber');
|
|
86
|
-
return { step: 'chapter_review', chapterNumber: input.chapterNumber };
|
|
86
|
+
return { step: 'chapter_review', mode: 'side_track', chapterNumber: input.chapterNumber };
|
|
87
87
|
}
|
|
88
88
|
case 'chapter_revision': {
|
|
89
89
|
if (!input.chapterNumber)
|
|
90
90
|
throw new Error('chapter_revision requires chapterNumber');
|
|
91
|
-
return { step: 'chapter_revision', chapterNumber: input.chapterNumber, feedback: input.feedback };
|
|
91
|
+
return { step: 'chapter_revision', mode: 'side_track', chapterNumber: input.chapterNumber, feedback: input.feedback };
|
|
92
92
|
}
|
|
93
93
|
case 'cross_chapter_review': {
|
|
94
94
|
const max = maxExistingChapter(state);
|
|
95
95
|
const range = input.range ?? { start: 1, end: max || state.currentChapter };
|
|
96
96
|
if (range.start < 1 || range.end < range.start)
|
|
97
97
|
throw new Error('Invalid range');
|
|
98
|
-
return { step: 'cross_chapter_review', range };
|
|
98
|
+
return { step: 'cross_chapter_review', mode: 'side_track', range };
|
|
99
99
|
}
|
|
100
100
|
default:
|
|
101
101
|
throw new Error(`Unknown side-track step: ${input.step}`);
|