dsh-novel-beat 0.0.0-stage → 0.5.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 DrizzleGig
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,74 @@
1
- # Temporary Holding Version
1
+ # dsh-novel-beat
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ **决策点问询**:写正文之前,把所有会改变剧情走向的节点逐条交给作者拍板。
4
+
5
+ ## 它解决什么问题
6
+
7
+ 用 DSH 写小说时,模型在「细纲 → 正文」之间有一大片自由发挥的空间:细纲只写「林砚在拍卖会拍下玉佩」,怎么加价、谁在场、旧敌什么反应、玉佩什么来历,全由模型自己编。
8
+
9
+ novel-forge 的门禁是「整章细纲 批/不批」——粒度是一章,批准时方案已经成型,小细节早就定了。
10
+
11
+ 本插件把粒度下沉到**决策点**,并在生成正文之前就问。
12
+
13
+ ## 判定规则(唯一标准)
14
+
15
+ > **会改变故事状态的,都要问;只描述世界的,不用问。**
16
+
17
+ 能落进账本的状态变更 = 决策点:
18
+
19
+ | 类型 | 例子 |
20
+ |---|---|
21
+ | 动作 | 他动手了 / 他忍住了 |
22
+ | 知情 | 谁知道 / 谁不知道 |
23
+ | 关系 | 结盟 / 翻脸 / 欠人情 |
24
+ | 得失 | 钱、物、功法、证据 |
25
+ | 状态 | 在哪、伤没伤、几层 |
26
+ | 承诺 | 答应 / 违约 / 期限 |
27
+ | 时序 | 先发生还是后发生 |
28
+ | 分叉 | 门口遇到谁 |
29
+
30
+ 风、光、温度、比喻、氛围 → 不进清单,模型自己决定。
31
+
32
+ ## 五个工具
33
+
34
+ | 工具 | 作用 |
35
+ |---|---|
36
+ | `beat_plan` | 列出本章决策点(每个必须有 `change`:谁/什么 从 A 变成 B) |
37
+ | `beat_list` | 查看拍板进度 |
38
+ | `beat_decide` | 记录作者的选择 |
39
+ | `beat_gate` | 写正文前体检:还有没拍板的就 `pass: false` |
40
+ | `beat_compile` | 编译成 novel-forge 的 `## 本章必写场景` / `## 本章禁止偏离项` |
41
+
42
+ ## 工作流
43
+
44
+ ```
45
+ beat_plan(列决策点)
46
+ ↓ 逐个 ask_user_question 问作者
47
+ beat_decide × N
48
+ ↓
49
+ beat_gate → PASS
50
+ ↓
51
+ beat_compile → 细纲片段
52
+ ↓
53
+ novel_outline save_chapter + approve
54
+ ↓
55
+ novel_write_chapter
56
+ ```
57
+
58
+ ## 数据落盘
59
+
60
+ ```
61
+ <工作区>/.dsh-novel-beat/<书名>/ch012.json
62
+ ```
63
+
64
+ 每章一个文件,包含全部决策点的选项、影响与发展、作者选择、拍板时间。
65
+
66
+ **不依赖任何其他插件**:五个工具只读写自己这个目录,不需要 novel-forge、不需要已有大纲或细纲。装了 novel-forge 可以把 `beat_compile` 的结果直接塞进 `novel_outline save_chapter`;没装就把它当写作提纲用,一样能走完。
67
+
68
+ ## 安装
69
+
70
+ ```powershell
71
+ # 改完代码要「先卸再装」才会重载
72
+ plugin_manager remove_bundle target=dsh-novel-beat
73
+ plugin_manager install_bundle target=D:\插件\plugins\novel-beat
74
+ ```
@@ -0,0 +1,3 @@
1
+ - insert:
2
+ - id: novel-beat
3
+ name: 'dsh-novel-beat'
package/icon.svg ADDED
@@ -0,0 +1,7 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" width="64" height="64" role="img" aria-label="Novel Beat">
2
+ <rect x="2" y="2" width="60" height="60" rx="14" fill="#6b46c1"/>
3
+ <path d="M20 46 V34 Q20 26 28 26 H34" fill="none" stroke="#ffffff" stroke-width="5" stroke-linecap="round"/>
4
+ <path d="M20 26 H34" fill="none" stroke="#ffffff" stroke-width="5" opacity="0.45" stroke-linecap="round"/>
5
+ <circle cx="42" cy="26" r="6" fill="#7ee787"/>
6
+ <circle cx="42" cy="46" r="6" fill="#ffffff" opacity="0.5"/>
7
+ </svg>
package/index.js ADDED
@@ -0,0 +1,500 @@
1
+ /**
2
+ * dsh-novel-beat — 决策点问询(v0.5)
3
+ *
4
+ * 判定规则(作者定的标准):
5
+ * 凡是会改变故事状态的节点,都必须由作者拍板;
6
+ * 只描述世界(风光、温度、比喻、环境)的节点,模型自行决定。
7
+ *
8
+ * 两种起点都支持:
9
+ * - 空白书:作者只给一句创意,边推演边用 append 逐层登记,拍板后再往下推;
10
+ * - 已有细纲:读细纲,逐拍登记。
11
+ *
12
+ * 落地方式:决策点 = 会往「账本」里写一条的状态变更。
13
+ * 拍板结果落盘到 <dir>/.dsh-novel-beat/<书>/ch<NNN>.json,
14
+ * 再由 beat_compile 编译成 novel-forge 认识的细纲片段。
15
+ */
16
+ import { mkdir, readFile, writeFile } from 'node:fs/promises'
17
+ import { dirname, join } from 'node:path'
18
+
19
+ export const inject = ['tools']
20
+
21
+ const KINDS = ['动作', '知情', '关系', '得失', '状态', '承诺', '时序', '分叉']
22
+ const ROOT = '.dsh-novel-beat'
23
+
24
+ /**
25
+ * 随插件一起安装的技能:让模型自己想起来「该用它」。
26
+ * 注册进 skills 服务的 runtime 层,装完插件即生效,不需要额外安装任何东西。
27
+ */
28
+ const SKILL = {
29
+ name: 'novel-beat',
30
+ description: '小说创作中实时拦截剧情分叉:每遇到一个会改变故事走向的节点,就登记成决策点、给出 2-4 个真分叉让作者拍板,没拍板不许往下写。空白书从一句创意开始就能用,不依赖已有大纲或细纲。当用户说「我想写一个…」「写第 N 章」「继续写」「接下来怎么发展」,或任何一次要推进剧情的时候使用。',
31
+ whenToUse: '任何时候要往下推进剧情——从开书的第一句创意,到续写某一章的中段。只要有"接下来发生什么"要定,就用它拦一下。',
32
+ source: 'runtime',
33
+ content: [
34
+ '# novel-beat:往下写之前先拍板',
35
+ '',
36
+ '## 唯一判定规则',
37
+ '',
38
+ '**会改变故事状态的节点,必须问作者;只描述世界的,模型自己决定。**',
39
+ '',
40
+ '- 要问:谁死谁活、谁知道了什么、**信息揭露到什么程度**、关系变了、得到或失去了什么、位置时间跳了、承诺立了、剧情分叉了、金手指或世界观规则变了。',
41
+ '- 尤其要问「这一段把这个秘密抖多少」——信息给到什么程度本身就是剧情决策,不是修辞节奏。',
42
+ '- 不问:风、光、温度、气味、比喻、房间陈设、说话时手放在哪。',
43
+ '- 代码层的等价说法:**凡是能往事实账本里写一条的,都是决策点。**',
44
+ '',
45
+ '## 两种起点',
46
+ '',
47
+ '**空白书(最常见)**:作者只给了一句创意、一个题材、一个金手指的念头。没有大纲、没有细纲、没有前文。',
48
+ '决策点不是"扫"出来的,是**在往下推演的过程中"截"出来的**——你每决定一步"接下来发生什么",就在动手之前把这一步里变了的东西登记下来。',
49
+ '',
50
+ '**已有细纲**:先读细纲,再逐拍登记。',
51
+ '',
52
+ '## 实时拦截协议(空白书必须遵守)',
53
+ '',
54
+ '1. 作者给创意 → 先把**最上游**的分叉问掉(主角是谁 / 金手指是什么 / 开局在哪个位置 / 第一个对手是谁),一次 1–3 个,不要一口气抛十个。',
55
+ '2. 每拿到一个答案,用 beat_plan(append: true) 补登记下一层分叉,再问下一批。**边推边问,不要先把整章想完再回头拆。**',
56
+ '3. 只要"接下来写什么"里有任何一处会改变状态,就**先登记、先问**,再动笔。',
57
+ '4. 当某个已拍板的答案改写了上游设定(例如作者说"删掉这个金手指"),停下来告诉作者这会波及哪些已写的设定,再继续。',
58
+ '',
59
+ '## 一次推进的流程',
60
+ '',
61
+ '1. **登记** — beat_plan(dir, book, chapter, beats[], context?)',
62
+ ' - change 必须写成「谁/什么 从 A 变成 B」,少于 4 个字会被拒绝。',
63
+ ' - kind 八选一:动作 / 知情 / 关系 / 得失 / 状态 / 承诺 / 时序 / 分叉。',
64
+ ' - **数量由节点定,没有上下限**:节点密就多,节点疏就少。字数和它无关,别为凑数把环境描写拆成决策点。',
65
+ ' - 分几次登记用 append: true,已拍板的不会动;整章重排才用 reset: true。',
66
+ ' - 空白书第一次调用时把创意原文塞进 context,后面翻记录时能对上。',
67
+ '',
68
+ '2. **问人** — 把每个决策点的 2–4 个选项摆给作者(ask_user_question)',
69
+ ' - 选项要真能改变走向,不要「他走过去 / 他慢慢走过去」这种假分叉。',
70
+ ' - 每个选项都要写 impact:**选了之后会发生什么**——对人物和关系的影响、可能引出的后续发展、代价与后患、顺手埋下的伏笔。不是只写代价。',
71
+ ' - **不替作者选**,不写「我建议选 A 就 A 吧」。',
72
+ '',
73
+ '3. **记录** — beat_decide(dir, book, chapter, id, choice)',
74
+ ' - 作者选了你给的选项,就传它的 label;他自己写的内容就照原话传。',
75
+ ' - 作者自己写的内容如果否定了这个节点本身(例如"干脆删掉这个设定"),编译时会被标成「作者改写」,不会照抄原来的状态变更。',
76
+ '',
77
+ '4. **查闸** — beat_gate,pass 之前**绝对不许写正文**。',
78
+ '',
79
+ '5. **编译** — beat_compile,产出「## 本章必写场景」与「## 本章禁止偏离项」。',
80
+ '',
81
+ '6. **接回写作** — 把编译结果当写作约束;装了 novel-forge 就贴进 novel_outline save_chapter,没装就直接当提示词约束用。',
82
+ '',
83
+ '## 不要做的事',
84
+ '',
85
+ '- 不要在 gate 没通过时「先写一版看看」。',
86
+ '- 不要先写完剧情再回头补问。',
87
+ '- 不要用环境描写充当决策点凑数。',
88
+ '- 分批只是交互节奏(一次抛太多作者看不过来),不是数量上限。',
89
+ ].join('\n'),
90
+ }
91
+
92
+ const toText = (value) => [{
93
+ type: 'text',
94
+ text: typeof value === 'string' ? value : JSON.stringify(value, null, 2),
95
+ }]
96
+
97
+ function chapterPath(dir, book, chapter) {
98
+ const safeBook = String(book).replace(/[\\/:*?"<>|]/g, '_')
99
+ return join(dir, ROOT, safeBook, `ch${String(chapter).padStart(3, '0')}.json`)
100
+ }
101
+
102
+ async function loadChapter(dir, book, chapter) {
103
+ const path = chapterPath(dir, book, chapter)
104
+ try {
105
+ return JSON.parse(await readFile(path, 'utf8'))
106
+ } catch (error) {
107
+ if (error.code === 'ENOENT') return null
108
+ throw error
109
+ }
110
+ }
111
+
112
+ async function saveChapter(dir, book, chapter, data) {
113
+ const path = chapterPath(dir, book, chapter)
114
+ await mkdir(dirname(path), { recursive: true })
115
+ data.updatedAt = new Date().toISOString()
116
+ await writeFile(path, JSON.stringify(data, null, 2), 'utf8')
117
+ return path
118
+ }
119
+
120
+ function requireChapter(data, book, chapter) {
121
+ if (!data) {
122
+ throw new Error(`第 ${chapter} 章还没有决策点清单(${book})。先调用 beat_plan 列出本章会改变剧情走向的节点。`)
123
+ }
124
+ return data
125
+ }
126
+
127
+ const planOutput = {
128
+ type: 'object',
129
+ properties: {
130
+ book: { type: 'string' },
131
+ chapter: { type: 'number' },
132
+ total: { type: 'number' },
133
+ pending: { type: 'number' },
134
+ path: { type: 'string' },
135
+ beats: { type: 'array', items: { type: 'object', properties: {} } },
136
+ },
137
+ }
138
+
139
+ const listOutput = {
140
+ type: 'object',
141
+ properties: {
142
+ book: { type: 'string' },
143
+ chapter: { type: 'number' },
144
+ total: { type: 'number' },
145
+ decided: { type: 'number' },
146
+ pending: { type: 'number' },
147
+ beats: { type: 'array', items: { type: 'object', properties: {} } },
148
+ },
149
+ }
150
+
151
+ const gateOutput = {
152
+ type: 'object',
153
+ properties: {
154
+ pass: { type: 'boolean' },
155
+ chapter: { type: 'number' },
156
+ total: { type: 'number' },
157
+ pending: { type: 'array', items: { type: 'object', properties: {} } },
158
+ message: { type: 'string' },
159
+ },
160
+ }
161
+
162
+ const decideOutput = {
163
+ type: 'object',
164
+ properties: {
165
+ id: { type: 'string' },
166
+ status: { type: 'string' },
167
+ choice: { type: 'string' },
168
+ remaining: { type: 'number' },
169
+ total: { type: 'number' },
170
+ },
171
+ }
172
+
173
+ const compileOutput = {
174
+ type: 'object',
175
+ properties: {
176
+ markdown: { type: 'string' },
177
+ scenes: { type: 'number' },
178
+ missing: { type: 'array', items: { type: 'string' } },
179
+ },
180
+ }
181
+
182
+ function summarize(data) {
183
+ const beats = data.beats ?? []
184
+ const decided = beats.filter((beat) => beat.status === 'decided').length
185
+ return {
186
+ book: data.book,
187
+ chapter: data.chapter,
188
+ total: beats.length,
189
+ decided,
190
+ pending: beats.length - decided,
191
+ beats: beats.map((beat) => ({
192
+ id: beat.id,
193
+ title: beat.title,
194
+ kind: beat.kind ?? '动作',
195
+ change: beat.change,
196
+ status: beat.status,
197
+ choice: beat.choice ?? null,
198
+ options: beat.options ?? [],
199
+ })),
200
+ }
201
+ }
202
+
203
+ export function apply(ctx) {
204
+ ctx.effect(() => ctx.tools.register({
205
+ name: 'beat_plan',
206
+ description: [
207
+ '把「接下来这一段里会改变故事状态」的分叉登记成决策点,逐个等作者拍板。往下写正文之前必须先过这一关。',
208
+ '**空白书也能用**:作者只给一句创意时,先登记最上游的几个分叉,拍板后再 append 下一层,边推边问,不要先把剧情想完再回头拆。',
209
+ '判定标准:会影响剧情走向、人物关系、信息知情、持有得失、位置状态的,一律列入;',
210
+ '纯环境描写、比喻、氛围渲染不列入——那些模型自己决定。',
211
+ '每个决策点必须写清 change(谁/什么 从什么变成什么),并给出 2-4 个走向不同的选项;每个选项用 impact 写清「选了会发生什么」(影响、可能的发展、代价、伏笔)。',
212
+ '决策点的数量**没有上下限**,由实际的状态变更节点决定:节点密就多,节点疏就少。',
213
+ ].join(''),
214
+ parameters: {
215
+ type: 'object',
216
+ properties: {
217
+ dir: { type: 'string', description: '工作区目录(绝对路径),决策点记录落在其下的 .dsh-novel-beat/ 里' },
218
+ book: { type: 'string', description: '书名' },
219
+ chapter: { type: 'number', description: '章号' },
220
+ append: { type: 'boolean', description: '往已有清单末尾追加(不动已拍板的),用来逐个补点。数量由本章实际的状态变更节点决定,没有上下限' },
221
+ beats: {
222
+ type: 'array',
223
+ description: '决策点列表,按剧情顺序排列',
224
+ items: {
225
+ type: 'object',
226
+ properties: {
227
+ title: { type: 'string', description: '一句话标题,如「玉佩怎么到手」' },
228
+ kind: { type: 'string', enum: KINDS, description: '决策类型:动作/知情/关系/得失/状态/承诺/时序/分叉' },
229
+ change: { type: 'string', description: '这一拍会改变什么状态。写清「谁/什么 从 A 变成 B」,写不出状态变更的就不该列入' },
230
+ options: {
231
+ type: 'array',
232
+ description: '给作者的选项,2-4 个;每个都要有 impact,不能是等价选项',
233
+ items: {
234
+ type: 'object',
235
+ properties: {
236
+ label: { type: 'string', description: '选项描述' },
237
+ impact: { type: 'string', description: '选了它会发生什么:对人物/关系/节奏的影响、可能引出的后续发展、代价与后患、埋下的伏笔(一段话写全,不要只写代价)' },
238
+ },
239
+ required: ['label'],
240
+ additionalProperties: false,
241
+ },
242
+ },
243
+ },
244
+ required: ['title', 'change'],
245
+ additionalProperties: false,
246
+ },
247
+ },
248
+ context: { type: 'string', description: '可选:这一步的创作背景/创意原文(空白书第一次登记时把作者给的创意、题材、金手指念头塞进来,后续翻记录时能对上)' },
249
+ reset: { type: 'boolean', description: '本章已有拍板记录时,传 true 才会覆盖重排' },
250
+ },
251
+ required: ['dir', 'book', 'chapter', 'beats'],
252
+ additionalProperties: false,
253
+ },
254
+ output: {
255
+ schema: planOutput,
256
+ render: (_args, value) => toText(
257
+ `已登记 ${value.total} 个决策点(第 ${value.chapter} 章),待拍板 ${value.pending} 个。\n` +
258
+ `接下来逐个问作者:对每个决策点调用 ask_user_question,把选项原文列给他,用 beat_decide 记录他的选择。\n` +
259
+ `记录文件:${value.path}`,
260
+ ),
261
+ },
262
+ async execute(args) {
263
+ const beats = Array.isArray(args.beats) ? args.beats : []
264
+ if (beats.length === 0) throw new Error('beats 不能为空:本章至少要有一个会改变剧情走向的决策点')
265
+
266
+ const existing = await loadChapter(args.dir, args.book, args.chapter)
267
+ const append = args.append === true && existing != null
268
+ if (existing && !append && existing.beats?.some((beat) => beat.status === 'decided') && args.reset !== true) {
269
+ throw new Error(
270
+ `第 ${args.chapter} 章已有拍板记录(${existing.beats.filter((b) => b.status === 'decided').length} 条),` +
271
+ '重新列清单会丢掉作者已经拍过的板。要往后补点请传 append: true;确认整章重排请传 reset: true。',
272
+ )
273
+ }
274
+ const base = append ? (existing.beats ?? []) : []
275
+
276
+ const normalized = beats.map((beat, index) => {
277
+ const title = String(beat.title ?? '').trim()
278
+ const change = String(beat.change ?? '').trim()
279
+ if (!title) throw new Error(`第 ${index + 1} 个决策点缺少 title`)
280
+ if (change.length < 4) {
281
+ throw new Error(`决策点「${title}」的 change 太短:必须写清「谁/什么 从 A 变成 B」,写不出状态变更的节点不该列入`)
282
+ }
283
+ const options = Array.isArray(beat.options) ? beat.options : []
284
+ const readImpact = (option) => String(option?.impact ?? option?.cost ?? '').trim()
285
+ if (options.length > 0 && options.some((option) => !readImpact(option))) {
286
+ throw new Error(`决策点「${title}」有选项没写 impact:每个选项都要说清「选了会发生什么」`)
287
+ }
288
+ return {
289
+ id: `b${base.length + index + 1}`,
290
+ title,
291
+ kind: beat.kind ?? '动作',
292
+ change,
293
+ options: options.map((option) => ({
294
+ label: String(option?.label ?? '').trim(),
295
+ impact: readImpact(option),
296
+ })).filter((option) => option.label),
297
+ status: 'pending',
298
+ choice: null,
299
+ note: null,
300
+ decidedAt: null,
301
+ }
302
+ })
303
+
304
+ const merged = append ? [...base, ...normalized] : normalized
305
+ const context = String(args.context ?? '').trim() || existing?.context || null
306
+ const data = { book: args.book, chapter: args.chapter, context, beats: merged }
307
+ const path = await saveChapter(args.dir, args.book, args.chapter, data)
308
+ const summary = summarize(data)
309
+ return { ...summary, path }
310
+ },
311
+ }))
312
+
313
+ ctx.effect(() => ctx.tools.register({
314
+ name: 'beat_list',
315
+ description: '查看某章已登记的决策点与拍板状态。不传 chapter 则只看待办统计。',
316
+ parameters: {
317
+ type: 'object',
318
+ properties: {
319
+ dir: { type: 'string', description: '工作区目录(绝对路径)' },
320
+ book: { type: 'string', description: '书名' },
321
+ chapter: { type: 'number', description: '章号' },
322
+ onlyPending: { type: 'boolean', description: 'true 只看还没拍板的' },
323
+ },
324
+ required: ['dir', 'book', 'chapter'],
325
+ additionalProperties: false,
326
+ },
327
+ output: {
328
+ schema: listOutput,
329
+ render: (_args, value) => {
330
+ const lines = value.beats.map((beat) => {
331
+ const mark = beat.status === 'decided' ? '✓' : '○'
332
+ const choice = beat.choice ? ` → ${beat.choice}` : ''
333
+ return `${mark} ${beat.id} [${beat.kind}] ${beat.title}${choice}`
334
+ })
335
+ return toText(
336
+ `第 ${value.chapter} 章:共 ${value.total} 个决策点,已拍板 ${value.decided},待拍板 ${value.pending}\n` +
337
+ (lines.length ? lines.join('\n') : '(没有匹配的决策点)'),
338
+ )
339
+ },
340
+ },
341
+ async execute(args) {
342
+ const data = requireChapter(await loadChapter(args.dir, args.book, args.chapter), args.book, args.chapter)
343
+ const summary = summarize(data)
344
+ if (args.onlyPending) summary.beats = summary.beats.filter((beat) => beat.status !== 'decided')
345
+ return summary
346
+ },
347
+ }))
348
+
349
+ ctx.effect(() => ctx.tools.register({
350
+ name: 'beat_decide',
351
+ description: '记录作者对某个决策点的拍板结果。作者选了哪个 option 就把它的 label 传进来;他自己写的内容就原样传 choice。',
352
+ parameters: {
353
+ type: 'object',
354
+ properties: {
355
+ dir: { type: 'string', description: '工作区目录(绝对路径)' },
356
+ book: { type: 'string', description: '书名' },
357
+ chapter: { type: 'number', description: '章号' },
358
+ id: { type: 'string', description: '决策点 id(b1、b2…)' },
359
+ choice: { type: 'string', description: '作者的选择:选项 label,或作者自己写的内容' },
360
+ note: { type: 'string', description: '补充说明(可选)' },
361
+ },
362
+ required: ['dir', 'book', 'chapter', 'id', 'choice'],
363
+ additionalProperties: false,
364
+ },
365
+ output: {
366
+ schema: decideOutput,
367
+ render: (_args, value) => toText(
368
+ value.remaining > 0
369
+ ? `${value.id} 已记录:${value.choice}\n还剩 ${value.remaining} 个决策点待拍板(共 ${value.total})。`
370
+ : `${value.id} 已记录:${value.choice}\n本章 ${value.total} 个决策点全部拍板,可以 beat_compile 编译细纲了。`,
371
+ ),
372
+ },
373
+ async execute(args) {
374
+ const data = requireChapter(await loadChapter(args.dir, args.book, args.chapter), args.book, args.chapter)
375
+ const beat = data.beats.find((item) => item.id === args.id)
376
+ if (!beat) throw new Error(`找不到决策点 ${args.id}(第 ${args.chapter} 章)`)
377
+ const choice = String(args.choice ?? '').trim()
378
+ if (!choice) throw new Error('choice 不能为空')
379
+ beat.status = 'decided'
380
+ beat.choice = choice
381
+ beat.note = args.note ? String(args.note).trim() : null
382
+ beat.decidedAt = new Date().toISOString()
383
+ await saveChapter(args.dir, args.book, args.chapter, data)
384
+ const remaining = data.beats.filter((item) => item.status !== 'decided').length
385
+ return { id: beat.id, status: beat.status, choice: beat.choice, remaining, total: data.beats.length }
386
+ },
387
+ }))
388
+
389
+ ctx.effect(() => ctx.tools.register({
390
+ name: 'beat_gate',
391
+ description: '写正文前的体检:本章决策点是否全部拍板。有未拍板的就返回 pass=false 并列出,此时不许写正文。',
392
+ parameters: {
393
+ type: 'object',
394
+ properties: {
395
+ dir: { type: 'string', description: '工作区目录(绝对路径)' },
396
+ book: { type: 'string', description: '书名' },
397
+ chapter: { type: 'number', description: '章号' },
398
+ },
399
+ required: ['dir', 'book', 'chapter'],
400
+ additionalProperties: false,
401
+ },
402
+ output: {
403
+ schema: gateOutput,
404
+ render: (_args, value) => toText(value.message),
405
+ },
406
+ async execute(args) {
407
+ const data = await loadChapter(args.dir, args.book, args.chapter)
408
+ if (!data) {
409
+ return {
410
+ pass: false,
411
+ chapter: args.chapter,
412
+ total: 0,
413
+ pending: [],
414
+ message: `第 ${args.chapter} 章还没有决策点清单。写正文之前必须先 beat_plan 列出会改变剧情走向的节点,并逐个让作者拍板。`,
415
+ }
416
+ }
417
+ const summary = summarize(data)
418
+ const pending = summary.beats.filter((beat) => beat.status !== 'decided')
419
+ if (summary.total === 0) {
420
+ return { pass: false, chapter: args.chapter, total: 0, pending: [], message: `第 ${args.chapter} 章的决策点清单是空的。` }
421
+ }
422
+ if (pending.length > 0) {
423
+ return {
424
+ pass: false,
425
+ chapter: args.chapter,
426
+ total: summary.total,
427
+ pending,
428
+ message:
429
+ `还有 ${pending.length} 个决策点没拍板,不许写正文:\n` +
430
+ pending.map((beat) => `- ${beat.id} [${beat.kind}] ${beat.title}`).join('\n'),
431
+ }
432
+ }
433
+ return {
434
+ pass: true,
435
+ chapter: args.chapter,
436
+ total: summary.total,
437
+ pending: [],
438
+ message: `第 ${args.chapter} 章 ${summary.total} 个决策点全部拍板,可以写正文了。`,
439
+ }
440
+ },
441
+ }))
442
+
443
+ ctx.effect(() => ctx.tools.register({
444
+ name: 'beat_compile',
445
+ description: '把已拍板的决策点编译成 novel-forge 认识的细纲片段(## 本章必写场景 / ## 本章禁止偏离项),供 novel_outline save_chapter 直接使用。',
446
+ parameters: {
447
+ type: 'object',
448
+ properties: {
449
+ dir: { type: 'string', description: '工作区目录(绝对路径)' },
450
+ book: { type: 'string', description: '书名' },
451
+ chapter: { type: 'number', description: '章号' },
452
+ },
453
+ required: ['dir', 'book', 'chapter'],
454
+ additionalProperties: false,
455
+ },
456
+ output: {
457
+ schema: compileOutput,
458
+ render: (_args, value) => toText(
459
+ value.missing.length
460
+ ? `还有 ${value.missing.length} 个决策点未拍板,先补齐再编译:${value.missing.join('、')}`
461
+ : value.markdown,
462
+ ),
463
+ },
464
+ async execute(args) {
465
+ const data = requireChapter(await loadChapter(args.dir, args.book, args.chapter), args.book, args.chapter)
466
+ const pending = data.beats.filter((beat) => beat.status !== 'decided')
467
+ if (pending.length > 0) {
468
+ return { markdown: '', scenes: 0, missing: pending.map((beat) => `${beat.id} ${beat.title}`) }
469
+ }
470
+ const pickedOption = (beat) => (beat.options ?? []).find((option) => option.label === beat.choice) ?? null
471
+ const sceneLine = (beat) => {
472
+ const picked = pickedOption(beat)
473
+ // 作者在我们给的选项里选了一个:节点原义成立,附上走向。
474
+ if (picked) {
475
+ return `- ${beat.title}:${beat.change}${picked.impact ? `(走向:${picked.impact})` : ''}`
476
+ }
477
+ // 作者自己写的内容 —— 可能直接否定了这个节点(如「删掉这个金手指」)。
478
+ // 这时绝不能照抄 change,否则细纲会自相矛盾;以拍板结果为准。
479
+ return `- ${beat.title}:${beat.choice}(作者改写了这个节点,原始状态变更为「${beat.change}」,以拍板为准)`
480
+ }
481
+ const scenes = data.beats.map(sceneLine)
482
+ const forbidden = data.beats.map((beat) => `- 不得改写已拍板决策:${beat.title} → ${beat.choice}`)
483
+ const markdown = [
484
+ '## 本章必写场景',
485
+ ...scenes,
486
+ '',
487
+ '## 本章禁止偏离项',
488
+ ...forbidden,
489
+ '- 环境、天气、比喻、氛围等不影响走向的描写可自由发挥,但不得改变上述任何一条已拍板决策',
490
+ ].join('\n')
491
+ return { markdown, scenes: data.beats.length, missing: [] }
492
+ },
493
+ }))
494
+
495
+ // 技能随插件安装即生效;skills 服务不存在时静默跳过,不让整个插件挂掉。
496
+ const skills = ctx.get('skills')
497
+ if (skills) {
498
+ ctx.effect(() => skills.register(SKILL))
499
+ }
500
+ }
package/package.json CHANGED
@@ -1,6 +1,41 @@
1
1
  {
2
2
  "name": "dsh-novel-beat",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.5.0",
4
+ "description": "决策点问询:每遇到一个会改变剧情走向的节点就交给作者拍板(含信息揭露程度),数量由实际节点密度决定、无上下限;空白书从一句创意开始就能用,边推演边拦截;每个选项写清选了会发生什么,拍板结果落账并编译成细纲。",
5
+ "type": "module",
6
+ "main": "index.js",
7
+ "exports": {
8
+ ".": "./index.js",
9
+ "./icon": "./icon.svg"
10
+ },
11
+ "files": [
12
+ "index.js",
13
+ "cordis.patch.yml",
14
+ "icon.svg",
15
+ "README.md",
16
+ "LICENSE"
17
+ ],
18
+ "keywords": [
19
+ "dsh",
20
+ "deepseek-harness",
21
+ "dsh-plugin",
22
+ "novel",
23
+ "plot",
24
+ "workflow"
25
+ ],
26
+ "license": "MIT",
27
+ "author": "DrizzleGig",
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "git+ssh://git@github.com/DrizzleGig/dsh-novel-beat.git"
31
+ },
32
+ "homepage": "https://github.com/DrizzleGig/dsh-novel-beat",
33
+ "bugs": {
34
+ "url": "https://github.com/DrizzleGig/dsh-novel-beat/issues"
35
+ },
36
+ "dsh": {
37
+ "bundle": {
38
+ "patch": "./cordis.patch.yml"
39
+ }
40
+ }
41
+ }