@ninkch/dsh-infinite-canvas 0.19.21 → 0.20.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ninkch/dsh-infinite-canvas",
3
- "version": "0.19.21",
3
+ "version": "0.20.1",
4
4
  "description": "无限画布(Infinite Canvas)for DeepSeek Harness:节点式创作工作室(剧本/分镜/生成/成片),内置「媒体创作」预设模式(导演第一视角 + 引导工作坊)。Version-agnostic: reads the live catalog from the installed package at load time.",
5
5
  "keywords": [
6
6
  "dsh",
@@ -39,6 +39,7 @@
39
39
  "files": [
40
40
  "index.js",
41
41
  "client.js",
42
+ "production.js",
42
43
  "icon.svg",
43
44
  "cordis.patch.yml",
44
45
  "locale/*.json",
package/production.js ADDED
@@ -0,0 +1,427 @@
1
+ /**
2
+ * @ninkch/dsh-infinite-canvas — 制作阶段机与流程闸门(0.20.0)
3
+ *
4
+ * 设计原则(借自 dsh-superagent-prototype):
5
+ * 「提示词负责解释,代码负责禁止」——凡可机械判定的流程规则都在这里用代码强制,
6
+ * 提示词(canvas-studio / canvas-production 技能)只负责解释"为什么"与"怎么补"。
7
+ *
8
+ * 两条铁律:
9
+ * 1. **流程规范 ≠ 内容模板**:本模块只规定"操作顺序"与"花钱/毁数据前的检查",
10
+ * 绝不规定故事内容——剧情走向永远是作者(用户)的。
11
+ * 2. **用户显式指令永远优先**:每道闸门都可用 override(用户原话)越过,越界行为
12
+ * 全部记入审计(overrides),事后可查。
13
+ *
14
+ * 阶段机(每个画布 = 一集,独立状态,存 <projectHomeDir>/production/<canvasKey>.json):
15
+ * brief → bible → assets → script → storyboard → shots_ready → generating → qc → post → delivered
16
+ * - floor:工具事件只会**抬高**它(写设定集 ≥bible、写剧本 ≥script、出镜头 ≥storyboard…)
17
+ * - explicit:productionAdvance 显式设定(可回退 = 返工),回退同时下调 floor
18
+ * - 生效阶段 = explicit ?? max(floor, inferred);旧项目无状态文件时从文档内容**推断**,不阻塞
19
+ */
20
+
21
+ import { existsSync, readFileSync, mkdirSync, copyFileSync, writeFileSync, renameSync } from 'node:fs';
22
+ import path from 'node:path';
23
+
24
+ /** 阶段枚举(顺序即优先级,index 越大越靠后)。 */
25
+ export const PRODUCTION_STAGES = ['brief', 'bible', 'assets', 'script', 'storyboard', 'shots_ready', 'generating', 'qc', 'post', 'delivered'];
26
+ export const PRODUCTION_STAGE_ZH = {
27
+ brief: '立项', bible: '设定集', assets: '参考图', script: '剧本', storyboard: '分镜',
28
+ shots_ready: '分镜定稿', generating: '生成中', qc: '质检', post: '后期', delivered: '已交付',
29
+ };
30
+ const STAGE_INDEX = Object.fromEntries(PRODUCTION_STAGES.map((s, i) => [s, i]));
31
+
32
+ /** 景别规范词(画面描述必须含其一,否则"景别不具体")。 */
33
+ const SHOTSIZE_WORDS = ['大特写', '特写', '近景', '中近景', '中景', '中全景', '全景', '远景'];
34
+ /** seg 规范取值(canvas_update_node 已做归一化,这里只认规范值)。 */
35
+ const SEG_CANON = new Set(['opening', 'continuation', 'scene_change', 'new_character', 'closeup']);
36
+ /** 状态上限:history / overrides 各自最多保留条数。 */
37
+ const CAP = 40;
38
+
39
+ /**
40
+ * 创建制作状态管理器。deps 全部来自 index.js 的模块内函数(运行时才调用,无循环导入问题):
41
+ * projectHomeDir(pid) 项目落盘目录(工作区内嵌 / 数据根)
42
+ * readToolDoc({projectId,canvasId}) 画布文档(项目级字段已合并)
43
+ * readDoc(pid) 项目文档(bible 的权威源)
44
+ * normalizeCanvasId(v) 画布 id 规范化
45
+ */
46
+ export function createProduction(deps) {
47
+ const homeOf = (pid) => {
48
+ try { return deps.projectHomeDir(pid) || null; } catch { return null; }
49
+ };
50
+ const dirOf = (pid) => {
51
+ const home = homeOf(pid);
52
+ return home ? path.join(home, 'production') : null;
53
+ };
54
+ const keyOf = (cid) => {
55
+ let k = 'default';
56
+ try { k = deps.normalizeCanvasId(cid) || 'default'; } catch { k = 'default'; }
57
+ return k;
58
+ };
59
+ const fileOf = (pid, cid) => {
60
+ const d = dirOf(pid);
61
+ return d ? path.join(d, keyOf(cid) + '.json') : null;
62
+ };
63
+
64
+ /** 读状态;缺失/损坏一律容错为 null(调用方走推断路径)。 */
65
+ function readState(pid, cid) {
66
+ const f = fileOf(pid, cid);
67
+ if (!f || !existsSync(f)) return null;
68
+ try {
69
+ const m = JSON.parse(readFileSync(f, 'utf8'));
70
+ if (m && typeof m === 'object' && Number.isFinite(m.floor)) return m;
71
+ } catch { /* 损坏 → 视同缺失 */ }
72
+ return null;
73
+ }
74
+
75
+ /** 原子写状态:覆盖前留 .backup.json(上次良好状态)。 */
76
+ function writeState(pid, cid, state) {
77
+ const f = fileOf(pid, cid);
78
+ if (!f) return null;
79
+ mkdirSync(path.dirname(f), { recursive: true });
80
+ try { if (existsSync(f)) copyFileSync(f, f + '.backup.json'); } catch { /* 备份失败不阻塞 */ }
81
+ const tmp = f + '.' + process.pid + '.tmp';
82
+ writeFileSync(tmp, JSON.stringify(state, null, 1), 'utf8');
83
+ renameSync(tmp, f);
84
+ return f;
85
+ }
86
+
87
+ const push = (list, entry) => [...(list || []), entry].slice(-CAP);
88
+
89
+ /** 从文档内容推断阶段(旧项目/无状态文件时用):取所有信号的**最大值**。 */
90
+ function inferStage(doc, projectDoc) {
91
+ const nodes = Object.values((doc && doc.nodes) || {});
92
+ let idx = 0; // brief
93
+ const bible = (projectDoc && projectDoc.bible) || (doc && doc.bible) || {};
94
+ const bibleFull = String(bible.worldview || '').trim() && String(bible.style || '').trim() && (bible.characters || []).length > 0;
95
+ const bibleAny = String(bible.worldview || '').trim() || String(bible.style || '').trim() || (bible.characters || []).length > 0;
96
+ if (bibleAny) idx = Math.max(idx, STAGE_INDEX.bible);
97
+ const isDone = (n) => String((n && n.data && n.data.status) || '') === 'done';
98
+ if (nodes.some((n) => n.type === 'image' && (n.data && (n.data.assetId || isDone(n))))) idx = Math.max(idx, STAGE_INDEX.assets);
99
+ if (nodes.some((n) => n.type === 'script')) idx = Math.max(idx, STAGE_INDEX.script);
100
+ const sbWithShots = nodes.filter((n) => n.type === 'storyboard' && Array.isArray(n.data && n.data.shots) && n.data.shots.length);
101
+ if (sbWithShots.length) {
102
+ idx = Math.max(idx, STAGE_INDEX.storyboard);
103
+ // 推断时顺手跑质量闸门:全部通过才承认 shots_ready(历史数据按现状评估)
104
+ if (sbWithShots.every((n) => gateStoryboard(n.data.shots).ok)) idx = Math.max(idx, STAGE_INDEX.shots_ready);
105
+ }
106
+ if (nodes.some((n) => n.type === 'video' && ['running', 'generating'].includes(String(n.data && n.data.status)))) idx = Math.max(idx, STAGE_INDEX.generating);
107
+ if (nodes.some((n) => n.type === 'video' && isDone(n))) idx = Math.max(idx, STAGE_INDEX.qc);
108
+ if (nodes.some((n) => n.type === 'finalcut' && isDone(n))) idx = Math.max(idx, STAGE_INDEX.post);
109
+ if (bibleFull && idx < STAGE_INDEX.bible) idx = STAGE_INDEX.bible;
110
+ return idx;
111
+ }
112
+
113
+ /**
114
+ * 生效阶段(不落盘):有状态文件 → 以状态为准(floor 由工具事件抬升、explicit 可回退);
115
+ * 无状态文件(老项目)→ 纯文档推断,绝不阻塞。推断结果在首次 note/advance 时固化进 floor。
116
+ */
117
+ function stageOf(pid, cid) {
118
+ let doc = null;
119
+ let projectDoc = null;
120
+ try { doc = deps.readToolDoc({ projectId: pid, canvasId: cid }); } catch { doc = null; }
121
+ try { projectDoc = deps.readDoc(pid); } catch { projectDoc = null; }
122
+ const inferred = inferStage(doc, projectDoc);
123
+ const state = readState(pid, cid);
124
+ const floor = state ? Math.max(Number(state.floor) || 0, 0) : inferred;
125
+ const explicit = state && Number.isFinite(state.explicit) ? state.explicit : null;
126
+ const idx = explicit != null ? Math.max(explicit, floor) : floor;
127
+ return { idx, stage: PRODUCTION_STAGES[idx], floor, explicit, inferred, state, doc, projectDoc };
128
+ }
129
+
130
+ /** 工具事件汇报:只抬高 floor(历史追加)。why 是机器可读的事件名(bible/script/video_run…)。 */
131
+ function noteStage(pid, cid, stageName, why) {
132
+ const to = STAGE_INDEX[stageName];
133
+ if (!Number.isFinite(to)) return null;
134
+ const cur = stageOf(pid, cid);
135
+ const state = cur.state || {
136
+ version: 1, projectId: pid, canvasKey: keyOf(cid),
137
+ floor: cur.inferred, explicit: null, createdAt: Date.now(), updatedAt: 0, history: [], overrides: [],
138
+ };
139
+ const from = Math.max(Number(state.floor) || 0, 0);
140
+ state.floor = Math.max(from, to);
141
+ state.updatedAt = Date.now();
142
+ if (to !== from) {
143
+ state.history = push(state.history, { at: Date.now(), from: PRODUCTION_STAGES[from], to: stageName, why: String(why || ''), by: 'auto' });
144
+ } else if (!cur.state) {
145
+ state.history = push(state.history, { at: Date.now(), from: PRODUCTION_STAGES[from], to: PRODUCTION_STAGES[from], why: 'init', by: 'auto' });
146
+ }
147
+ writeState(pid, cid, state);
148
+ return state;
149
+ }
150
+
151
+ /** 显式推进/回退(返工):同时改 explicit 与 floor(authoritative),必带 reason,进历史。 */
152
+ function advance(pid, cid, toName, reason, by) {
153
+ const to = STAGE_INDEX[toName];
154
+ if (!Number.isFinite(to)) return { ok: false, error: '未知阶段: ' + toName + '(可选:' + PRODUCTION_STAGES.join(' / ') + ')' };
155
+ const why = String((reason || '').trim());
156
+ if (!why) return { ok: false, error: '缺少 reason:显式推进/回退必须说明原因(审计要求)' };
157
+ const cur = stageOf(pid, cid);
158
+ const state = cur.state || {
159
+ version: 1, projectId: pid, canvasKey: keyOf(cid),
160
+ floor: cur.inferred, explicit: null, createdAt: Date.now(), updatedAt: 0, history: [], overrides: [],
161
+ };
162
+ const from = cur.idx;
163
+ state.explicit = to;
164
+ state.floor = to;
165
+ state.updatedAt = Date.now();
166
+ state.history = push(state.history, { at: Date.now(), from: PRODUCTION_STAGES[from], to: toName, why, by: String(by || 'user') });
167
+ writeState(pid, cid, state);
168
+ return { ok: true, from: PRODUCTION_STAGES[from], to: toName, stage: toName };
169
+ }
170
+
171
+ /** 审计一条越闸记录(override)。gate=闸门代码,quote=用户原话。 */
172
+ function recordOverride(pid, cid, gate, quote, extra) {
173
+ const cur = stageOf(pid, cid);
174
+ const state = cur.state || {
175
+ version: 1, projectId: pid, canvasKey: keyOf(cid),
176
+ floor: cur.inferred, explicit: null, createdAt: Date.now(), updatedAt: 0, history: [], overrides: [],
177
+ };
178
+ state.overrides = push(state.overrides, { at: Date.now(), gate: String(gate || ''), quote: String(quote || '').slice(0, 200), ...(extra || {}) });
179
+ state.updatedAt = Date.now();
180
+ writeState(pid, cid, state);
181
+ }
182
+
183
+ // ── A1 两段式:预算单与一次性批准令牌 ────────────────────────────────
184
+
185
+ /** 稳定指纹:同样的镜头/时长/单价 → 同一个 quoteId;任何一项变了 → 指纹变(旧批准自动失效)。 */
186
+ function fingerprint(payload) {
187
+ let h = 5381;
188
+ const s = JSON.stringify(payload);
189
+ for (let i = 0; i < s.length; i++) h = ((h * 33) ^ s.charCodeAt(i)) >>> 0;
190
+ return 'q' + h.toString(36) + '-' + s.length.toString(36);
191
+ }
192
+
193
+ /**
194
+ * 预算单(免费段终点):只统计"将要花钱"的东西——每个分镜表一次视频调用、总秒数、场/镜数。
195
+ * 单价由调用方传入(画布设置里的单价,未配置则不给金额,只给调用次数与秒数)。
196
+ */
197
+ function quote(pid, cid, unitPricePerSecond) {
198
+ const st = stageOf(pid, cid);
199
+ const doc = st.doc || { nodes: {} };
200
+ const nodes = Object.values(doc.nodes || {});
201
+ const sbs = nodes.filter((n) => n.type === 'storyboard' && Array.isArray(n.data && n.data.shots) && n.data.shots.length);
202
+ const videoNodes = nodes.filter((n) => n.type === 'video');
203
+ let totalSeconds = 0;
204
+ const scenes = sbs.map((n, i) => {
205
+ const shots = n.data.shots || [];
206
+ const secs = shots.reduce((a, s) => a + (Number(s && s.duration) || 0), 0);
207
+ totalSeconds += secs;
208
+ return {
209
+ scene: i + 1,
210
+ storyboardId: n.id,
211
+ name: String((n.data && n.data.label) || n.id),
212
+ shots: shots.length,
213
+ seconds: Math.round(secs * 10) / 10,
214
+ hasVideo: videoNodes.some((v) => (doc.edges || []).some((e) => e.fromNode === n.id && e.toNode === v.id)),
215
+ };
216
+ });
217
+ const pending = scenes.filter((s) => !s.hasVideo).length;
218
+ const price = Number(unitPricePerSecond);
219
+ const payload = { pid, cid: keyOf(cid), scenes: scenes.map((s) => [s.storyboardId, s.shots, s.seconds]), pending };
220
+ return {
221
+ ok: true, quoteId: fingerprint(payload),
222
+ projectId: pid, canvasId: keyOf(cid) === 'default' ? null : keyOf(cid),
223
+ stage: st.stage,
224
+ scenes, sceneCount: scenes.length, shotCount: scenes.reduce((a, s) => a + s.shots, 0),
225
+ totalSeconds: Math.round(totalSeconds * 10) / 10,
226
+ videoCalls: pending,
227
+ unitPricePerSecond: Number.isFinite(price) && price > 0 ? price : null,
228
+ estimatedCost: Number.isFinite(price) && price > 0 ? Math.round(price * totalSeconds * 100) / 100 : null,
229
+ note: pending === 0 ? '全部分镜表都已有视频节点:本次只做重生成,不产生新调用' : '批准后只按差分镜表各调用一次视频接口(按秒计费)',
230
+ };
231
+ }
232
+
233
+ /** 批准(一次性令牌):quoteId 必须与当前文档指纹一致,否则拒绝(镜头变了就得重新看预算)。 */
234
+ function approve(pid, cid, quoteId, confirm, unitPricePerSecond) {
235
+ const q = quote(pid, cid, unitPricePerSecond);
236
+ const given = String(quoteId || '').trim();
237
+ if (!given) return { ok: false, error: '缺少 quoteId:先调 autoQuote 生成预算单,用户看过后再批准' };
238
+ if (given !== q.quoteId) return { ok: false, expired: true, error: '预算单已过期(镜头/时长/新增分镜表发生了变化)——请重新 autoQuote 并让用户复核后再批准', current: q.quoteId };
239
+ const words = String(confirm || '').trim();
240
+ if (!words) return { ok: false, error: '缺少 confirm:批准付费生成必须携带用户确认原话(审计要求)' };
241
+ const cur = stageOf(pid, cid);
242
+ const state = cur.state || {
243
+ version: 1, projectId: pid, canvasKey: keyOf(cid),
244
+ floor: cur.inferred, explicit: null, createdAt: Date.now(), updatedAt: 0, history: [], overrides: [],
245
+ };
246
+ state.approval = { quoteId: q.quoteId, at: Date.now(), by: 'user', confirm: words.slice(0, 200), videoCalls: q.videoCalls, totalSeconds: q.totalSeconds };
247
+ state.updatedAt = Date.now();
248
+ writeState(pid, cid, state);
249
+ return { ok: true, approved: true, quoteId: q.quoteId, videoCalls: q.videoCalls, totalSeconds: q.totalSeconds };
250
+ }
251
+
252
+ /** 当前批准是否仍然有效(预算指纹未变);返回 null 表示没有批准。 */
253
+ function approvalOf(pid, cid, unitPricePerSecond) {
254
+ const state = readState(pid, cid);
255
+ if (!state || !state.approval) return null;
256
+ const q = quote(pid, cid, unitPricePerSecond);
257
+ const valid = state.approval.quoteId === q.quoteId;
258
+ return { ...state.approval, valid, currentQuoteId: q.quoteId };
259
+ }
260
+
261
+ // ── 闸门 ────────────────────────────────────────────────────────────────
262
+
263
+ /**
264
+ * G1 设定集先行(拦**生成**,不拦节点搭建):剧本/分镜表真正生成内容前,
265
+ * 设定集必须有世界观 + 风格 + ≥1 角色。返回 missing 清单供补全。
266
+ */
267
+ function gateBible(bible) {
268
+ const b = bible || {};
269
+ const missing = [];
270
+ if (!String(b.worldview || '').trim()) missing.push('worldview(世界观/核心设定)');
271
+ if (!String(b.style || '').trim()) missing.push('style(风格基调)');
272
+ if (!Array.isArray(b.characters) || !b.characters.length) missing.push('characters(至少 1 个角色)');
273
+ return { ok: missing.length === 0, code: 'G1', missing };
274
+ }
275
+
276
+ /**
277
+ * G2 分镜质量闸门(建/跑视频节点前):只查**机械可判定**项;
278
+ * 冲突点/因果钩子这类需要创作判断的项放 warns(由 canvas-craft 技能与自检清单负责)。
279
+ */
280
+ function gateStoryboard(shots) {
281
+ const fails = [];
282
+ const warns = [];
283
+ const arr = Array.isArray(shots) ? shots : [];
284
+ if (!arr.length) {
285
+ fails.push('分镜表还没有任何镜头(shots 为空)——先 canvas_run_node 分镜表生成镜头,绝不手工编造镜头表');
286
+ return { ok: false, code: 'G2', fails, warns };
287
+ }
288
+ if (arr.length > 24) fails.push('镜头 ' + arr.length + ' 个超过单表上限 24——请按场景拆分为多个分镜表');
289
+ const normMotion = (s) => String((s && s.motion) || '').trim().toLowerCase();
290
+ arr.forEach((s, i) => {
291
+ const no = '镜' + (i + 1);
292
+ const visual = String((s && s.visual) || '').trim();
293
+ if (!(Number(s && s.duration) > 0)) fails.push(no + ' 缺少时长(duration 必须为正数)');
294
+ if (!visual) fails.push(no + ' 缺少画面描述(visual)');
295
+ else if (!SHOTSIZE_WORDS.some((w) => visual.includes(w))) fails.push(no + ' 景别不具体(画面需含 大特写/特写/近景/中近景/中景/中全景/全景/远景 之一)');
296
+ const seg = String((s && s.seg) || '').trim().toLowerCase();
297
+ if (seg && !SEG_CANON.has(seg)) fails.push(no + ' seg 取值非法:' + seg + '(只能是 opening/continuation/scene_change/new_character/closeup)');
298
+ if (!seg || !String((s && s.tail) || '').trim() || !String((s && s.cam) || '').trim()) {
299
+ warns.push(no + ' 缺衔接字段(' + (['seg', 'tail', 'cam'].filter((k) => !String((s && s[k]) || '').trim()).join('/')) + ')——跨段接戏靠这四个字段,建议 canvas_update_node 补齐');
300
+ }
301
+ const dlg = s && s.dialogue;
302
+ const dlgText = typeof dlg === 'string' ? dlg : Array.isArray(dlg) ? dlg.join(' ') : '';
303
+ if (dlgText.trim() && !dlgText.includes(':') && !dlgText.includes(':')) warns.push(no + ' 台词建议逐行「角色:台词」格式(音画同步依赖它)');
304
+ });
305
+ if (arr.length && !arr.some((s) => String((s && s.visual) || '').includes('大特写'))) {
306
+ fails.push('全表没有一个「大特写」——每场至少 1 个大特写(分镜自检硬项)');
307
+ }
308
+ for (let i = 0; i + 2 < arr.length; i++) {
309
+ const a = normMotion(arr[i]);
310
+ if (a && a === normMotion(arr[i + 1]) && a === normMotion(arr[i + 2])) {
311
+ fails.push('镜' + (i + 1) + '–' + (i + 3) + ' 连续三镜运动完全相同(「' + String(arr[i].motion).trim() + '」)——连续三镜必须不同运动');
312
+ break;
313
+ }
314
+ }
315
+ return { ok: fails.length === 0, code: 'G2', fails, warns };
316
+ }
317
+
318
+ /** G6 阶段越序:付费/重操作要求生效阶段到达某一步。 */
319
+ function gateStage(pid, cid, needName) {
320
+ const need = STAGE_INDEX[needName];
321
+ const cur = stageOf(pid, cid);
322
+ return {
323
+ ok: cur.idx >= need, code: 'G6',
324
+ at: cur.stage, atIdx: cur.idx, need: needName, needIdx: need,
325
+ };
326
+ }
327
+
328
+ /** G4 禁止逐镜节点:名字含「镜N」的图片/视频节点 = 走错路(一致性靠参考图资产,不靠逐镜节点)。 */
329
+ function gateShotNodeName(name, type) {
330
+ if (type !== 'image' && type !== 'video') return { ok: true };
331
+ if (/[镜]\s*\d+/.test(String(name || ''))) {
332
+ return {
333
+ ok: false, code: 'G4',
334
+ error: '「' + String(name).slice(0, 40) + '」是逐镜节点命名——多镜头一致性靠角色/场景参考图资产(@资产名@ 自动挂载),视频一次生成全部镜头,不要为单个镜头建节点。最多为开场首帧或 1–2 个关键镜头补定帧图(命名不带「镜N」)。',
335
+ };
336
+ }
337
+ return { ok: true };
338
+ }
339
+
340
+ /** G3 一表一视频:同一分镜表下已存在视频节点 → 拒绝再建第二个。 */
341
+ function gateOneVideoPerStoryboard(doc, storyboardId) {
342
+ if (!storyboardId) return { ok: true };
343
+ const edges = (doc && doc.edges) || [];
344
+ const fromSb = new Set(edges.filter((e) => e && e.fromNode === storyboardId).map((e) => e.toNode));
345
+ const nodes = (doc && doc.nodes) || {};
346
+ const existing = Object.values(nodes).filter((n) => n && n.type === 'video' && fromSb.has(n.id));
347
+ if (existing.length) {
348
+ return {
349
+ ok: false, code: 'G3',
350
+ error: '该分镜表已有视频节点「' + (existing[0].data && existing[0].data.label || existing[0].id) + '」(一个分镜表 = 一个完整视频)。改提示词/参数用 canvas_update_node 重生成,不要新建第二个视频节点。',
351
+ existingVideoId: existing[0].id,
352
+ };
353
+ }
354
+ return { ok: true };
355
+ }
356
+
357
+ /**
358
+ * 状态汇报:模型宣称"完成/可交付"前必须以此为据(ready:true 才允许说完成)。
359
+ * next 按**当前阶段**给下一步建议——只管操作顺序,不管内容。
360
+ */
361
+ function status(pid, cid) {
362
+ const st = stageOf(pid, cid);
363
+ const doc = st.doc || { nodes: {}, edges: [] };
364
+ const nodes = Object.values(doc.nodes || {});
365
+ const bible = (doc && doc.bible) || {};
366
+ const g1 = gateBible(bible);
367
+ const sbs = nodes.filter((n) => n.type === 'storyboard' && Array.isArray(n.data && n.data.shots) && n.data.shots.length);
368
+ const lastSb = sbs.length ? sbs[sbs.length - 1] : null;
369
+ const g2 = lastSb ? gateStoryboard(lastSb.data.shots) : { ok: false, code: 'G2', fails: ['还没有任何分镜表产出镜头'], warns: [] };
370
+ const videos = nodes.filter((n) => n.type === 'video');
371
+ const finalcuts = nodes.filter((n) => n.type === 'finalcut');
372
+ const blockers = [];
373
+ if (!g1.ok) blockers.push({ gate: 'G1', detail: g1.missing });
374
+ if (st.idx >= STAGE_INDEX.storyboard && !g2.ok) blockers.push({ gate: 'G2', detail: g2.fails });
375
+ const NEXT_BY_STAGE = {
376
+ brief: '补全设定集(canvas_update_bible):世界观/风格/角色/场景/道具——这是全片一致性的唯一依据',
377
+ bible: '写剧本节点(idea → canvas_run_node 生成成稿);参考图资产可并行生成',
378
+ assets: '写剧本节点;已有参考图的实体直接 @资产名@ 引用',
379
+ script: '按【场N】把剧本铺开到场景文本节点,再逐场建分镜表(源端=场景文本,tail→prev 串联)',
380
+ storyboard: 'canvas_run_node 分镜表生成 shots,读回后按六条自检核对(判定以本工具 gates.storyboard 为准)',
381
+ shots_ready: '过质量闸门后逐场建视频节点(一表一视频)并 canvas_generate_node;生成前本工具会给出预算要素',
382
+ generating: '等待视频完成(canvas_node_status),注意 genWarn 与接缝校验结果',
383
+ qc: '核对一致性告警/接缝/口型;用户验收后进入后期(ArtCraft 家族)',
384
+ post: 'ArtCraft 后期(调色/混音/成片渲染);执行按钮在画布 UI 上',
385
+ delivered: '本集已交付;开工新一集前先 canvas_read_memory 读调度索引',
386
+ };
387
+ return {
388
+ ok: true,
389
+ projectId: pid,
390
+ canvasId: deps.normalizeCanvasId(cid) || null,
391
+ stage: st.stage,
392
+ stageZh: PRODUCTION_STAGE_ZH[st.stage],
393
+ stageIndex: st.idx,
394
+ explicit: st.explicit != null ? PRODUCTION_STAGES[st.explicit] : null,
395
+ inferred: PRODUCTION_STAGES[st.inferred],
396
+ gates: { bible: g1, storyboard: g2 },
397
+ blockers,
398
+ ready: st.idx >= STAGE_INDEX.shots_ready && g1.ok && g2.ok,
399
+ brief: st.state && st.state.brief,
400
+ evidence: {
401
+ characters: (bible.characters || []).length,
402
+ scenes: (bible.scenes || []).length,
403
+ props: (bible.props || []).length,
404
+ scripts: nodes.filter((n) => n.type === 'script').length,
405
+ scriptsDone: nodes.filter((n) => n.type === 'script' && String((n.data && n.data.output) || '').trim()).length,
406
+ storyboards: nodes.filter((n) => n.type === 'storyboard').length,
407
+ storyboardsWithShots: sbs.length,
408
+ shotsTotal: sbs.reduce((a, n) => a + (n.data.shots || []).length, 0),
409
+ images: nodes.filter((n) => n.type === 'image').length,
410
+ imagesDone: nodes.filter((n) => n.type === 'image' && (n.data && (n.data.assetId || String(n.data.status) === 'done'))).length,
411
+ videos: videos.length,
412
+ videosDone: videos.filter((n) => String((n.data && n.data.status) || '') === 'done').length,
413
+ finalcuts: finalcuts.length,
414
+ },
415
+ next: NEXT_BY_STAGE[st.stage] || '',
416
+ history: (st.state && st.state.history) || [],
417
+ overrides: (st.state && st.state.overrides) || [],
418
+ };
419
+ }
420
+
421
+ return {
422
+ readState, writeState, inferStage, stageOf, noteStage, advance, recordOverride, status,
423
+ gateBible, gateStoryboard, gateStage, gateShotNodeName, gateOneVideoPerStoryboard,
424
+ quote, approve, approvalOf,
425
+ stageIndex: (name) => STAGE_INDEX[name], stageName: (idx) => PRODUCTION_STAGES[idx] || null,
426
+ };
427
+ }
package/skill-pack.js CHANGED
@@ -12,12 +12,20 @@ import { normalizeSkillProfile } from './index-core-skill-profile.js';
12
12
  /** moves 永远随 storyboard/prompt 走(运镜是这两类生成的必需品)。 */
13
13
  const MOVES_FOR_KIND = {
14
14
  script: [],
15
- // 分镜要调度动作,运镜 + 打斗节奏两张卡都带;提示词只需运镜。
16
- storyboard: ['camera-moves', 'fight-rhythm'],
15
+ // 分镜要调度动作,运镜必备;打斗节奏卡只在动作/冲突类题材下跟随注入(悬疑/日常等非动作题材
16
+ // 带它 = 4.9KB 纯浪费且稀释正文)。提示词只需运镜。
17
+ storyboard: ['camera-moves'],
17
18
  prompt: ['camera-moves'],
18
19
  assets: [],
19
20
  };
20
21
 
22
+ /** 动作/冲突强度高的题材 → 分镜链路额外带「打斗节奏」卡(它讲的是打斗/追逐场面的镜头组织)。 */
23
+ const FIGHT_RHYTHM_GENRES = new Set([
24
+ 'action-mission', 'wuxia', 'gunstandoff', 'adventure', 'crime-police', 'hk-retro',
25
+ 'wasteland-chase', 'mo-lei-tau', 'revenge-face-slap', 'multi-thread-caper',
26
+ 'neon-dystopia', 'rebirth-transmigration',
27
+ ]);
28
+
21
29
  /**
22
30
  * 构建某生成能力下的注入文本。
23
31
  * @param {object} opts
@@ -69,7 +77,12 @@ export async function buildSkillPack(opts) {
69
77
  // 运镜只在「已经有层卡命中」时才跟随注入。
70
78
  // 否则四层全空的项目也会被塞进 5KB 运镜词典 —— 违反「未配置不注入」(老项目零变化)。
71
79
  if (items.length) {
72
- for (const mid of (MOVES_FOR_KIND[kind] || [])) {
80
+ const moves = [...(MOVES_FOR_KIND[kind] || [])];
81
+ // 打斗节奏:仅分镜链路 + 选了动作/冲突类题材时追加(它是打斗场面的镜头组织教材)
82
+ if (kind === 'storyboard' && (profile.genres || []).some((g) => FIGHT_RHYTHM_GENRES.has(g))) {
83
+ moves.push('fight-rhythm');
84
+ }
85
+ for (const mid of moves) {
73
86
  const mv = (inv.moves || []).find((x) => x.id === mid);
74
87
  if (!mv) continue;
75
88
  const md = readMove(hereDir, mv.file);