@lingjingai/scriptctl 0.1.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/dist/bin.d.ts +2 -0
- package/dist/bin.js +12 -0
- package/dist/bin.js.map +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +433 -0
- package/dist/cli.js.map +1 -0
- package/dist/common.d.ts +124 -0
- package/dist/common.js +337 -0
- package/dist/common.js.map +1 -0
- package/dist/domain/direct-core.d.ts +114 -0
- package/dist/domain/direct-core.js +3040 -0
- package/dist/domain/direct-core.js.map +1 -0
- package/dist/domain/script-core.d.ts +18 -0
- package/dist/domain/script-core.js +1886 -0
- package/dist/domain/script-core.js.map +1 -0
- package/dist/help-text.d.ts +2 -0
- package/dist/help-text.js +399 -0
- package/dist/help-text.js.map +1 -0
- package/dist/infra/converters.d.ts +10 -0
- package/dist/infra/converters.js +560 -0
- package/dist/infra/converters.js.map +1 -0
- package/dist/infra/env.d.ts +2 -0
- package/dist/infra/env.js +81 -0
- package/dist/infra/env.js.map +1 -0
- package/dist/infra/providers.d.ts +25 -0
- package/dist/infra/providers.js +330 -0
- package/dist/infra/providers.js.map +1 -0
- package/dist/infra/script-output-api.d.ts +44 -0
- package/dist/infra/script-output-api.js +160 -0
- package/dist/infra/script-output-api.js.map +1 -0
- package/dist/infra/storage.d.ts +35 -0
- package/dist/infra/storage.js +91 -0
- package/dist/infra/storage.js.map +1 -0
- package/dist/output.d.ts +4 -0
- package/dist/output.js +55 -0
- package/dist/output.js.map +1 -0
- package/dist/usecases/direct.d.ts +13 -0
- package/dist/usecases/direct.js +1679 -0
- package/dist/usecases/direct.js.map +1 -0
- package/dist/usecases/doctor.d.ts +2 -0
- package/dist/usecases/doctor.js +75 -0
- package/dist/usecases/doctor.js.map +1 -0
- package/dist/usecases/script.d.ts +32 -0
- package/dist/usecases/script.js +949 -0
- package/dist/usecases/script.js.map +1 -0
- package/package.json +50 -0
|
@@ -0,0 +1,1886 @@
|
|
|
1
|
+
import { ACTION_TYPE_VALUES, CliError, DELIVERY_VALUES, EFFECTIVE_FROM_VALUES, EXIT_INPUT, EXIT_USAGE, ROLE_TYPE_VALUES, SCRIPT_SCHEMA_VERSION, SCRIPT_TARGET_KINDS, SPEAKER_SOURCE_KINDS, WORLDVIEW_VALUES, directDir, exists, fmtId, readJson, readText, writeJson, } from "../common.js";
|
|
2
|
+
import { cleanName, contentHasSpeakerPrefix, inferNonActorSpeakerKind, isTechnicalEpisodeTitle, sceneContext, setSceneContext, stateLabelError, stateRejectionReason, } from "./direct-core.js";
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
function strOf(v) {
|
|
5
|
+
if (v === null || v === undefined)
|
|
6
|
+
return "";
|
|
7
|
+
return String(v);
|
|
8
|
+
}
|
|
9
|
+
function isDict(v) {
|
|
10
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
11
|
+
}
|
|
12
|
+
function isList(v) {
|
|
13
|
+
return Array.isArray(v);
|
|
14
|
+
}
|
|
15
|
+
function asList(v) {
|
|
16
|
+
return Array.isArray(v) ? v : [];
|
|
17
|
+
}
|
|
18
|
+
// ---------------------------------------------------------------------------
|
|
19
|
+
// Find helpers
|
|
20
|
+
// ---------------------------------------------------------------------------
|
|
21
|
+
export function findAction(script, epId, sceneId, actionIndex) {
|
|
22
|
+
for (const ep of asList(script["episodes"])) {
|
|
23
|
+
if (ep["episode_id"] !== epId)
|
|
24
|
+
continue;
|
|
25
|
+
for (const scene of asList(ep["scenes"])) {
|
|
26
|
+
if (scene["scene_id"] === sceneId) {
|
|
27
|
+
const actions = asList(scene["actions"]);
|
|
28
|
+
if (actionIndex >= 0 && actionIndex < actions.length)
|
|
29
|
+
return actions[actionIndex];
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
throw new CliError("PATCH BLOCKED: Action not found", "Action not found.", {
|
|
34
|
+
exitCode: EXIT_USAGE,
|
|
35
|
+
required: ["existing episode_id, scene_id, action_index"],
|
|
36
|
+
received: [`${epId} ${sceneId} ${actionIndex}`],
|
|
37
|
+
nextSteps: ["Inspect episodes and fix the patch."],
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
export function findEpisode(script, epId) {
|
|
41
|
+
for (const ep of asList(script["episodes"])) {
|
|
42
|
+
if (ep["episode_id"] === epId)
|
|
43
|
+
return ep;
|
|
44
|
+
}
|
|
45
|
+
throw new CliError("PATCH BLOCKED: Episode not found", "Episode not found.", {
|
|
46
|
+
exitCode: EXIT_USAGE,
|
|
47
|
+
required: ["existing episode_id"],
|
|
48
|
+
received: [epId],
|
|
49
|
+
nextSteps: ["Inspect episodes and fix the patch."],
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
export function findScene(script, epId, sceneId) {
|
|
53
|
+
const ep = findEpisode(script, epId);
|
|
54
|
+
for (const scene of asList(ep["scenes"])) {
|
|
55
|
+
if (scene["scene_id"] === sceneId)
|
|
56
|
+
return scene;
|
|
57
|
+
}
|
|
58
|
+
throw new CliError("PATCH BLOCKED: Scene not found", "Scene not found.", {
|
|
59
|
+
exitCode: EXIT_USAGE,
|
|
60
|
+
required: ["existing episode_id and scene_id"],
|
|
61
|
+
received: [`${epId} ${sceneId}`],
|
|
62
|
+
nextSteps: ["Inspect episodes and fix the patch."],
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
// ---------------------------------------------------------------------------
|
|
66
|
+
// validate_script
|
|
67
|
+
// ---------------------------------------------------------------------------
|
|
68
|
+
export function validateScript(workspace, scriptPath = null, opts = {}) {
|
|
69
|
+
const requireSource = opts.requireSource ?? true;
|
|
70
|
+
const dd = directDir(workspace);
|
|
71
|
+
const sourcePath = path.join(workspace, "source.txt");
|
|
72
|
+
const finalScriptPath = scriptPath ?? path.join(dd, "script.initial.json");
|
|
73
|
+
if (requireSource && !exists(sourcePath)) {
|
|
74
|
+
throw new CliError("VALIDATE BLOCKED: source.txt not found", "source.txt not found.", {
|
|
75
|
+
exitCode: EXIT_INPUT,
|
|
76
|
+
required: ["workspace/source.txt"],
|
|
77
|
+
received: [sourcePath],
|
|
78
|
+
nextSteps: ["Run scriptctl direct init first."],
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
if (!exists(finalScriptPath)) {
|
|
82
|
+
throw new CliError("VALIDATE BLOCKED: script not found", "Script JSON not found.", {
|
|
83
|
+
exitCode: EXIT_INPUT,
|
|
84
|
+
required: ["script.initial.json or --script-path"],
|
|
85
|
+
received: [finalScriptPath],
|
|
86
|
+
nextSteps: ["Run scriptctl direct init first."],
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
if (exists(sourcePath))
|
|
90
|
+
readText(sourcePath); // touch, mirror Python
|
|
91
|
+
let script;
|
|
92
|
+
try {
|
|
93
|
+
script = readJson(finalScriptPath);
|
|
94
|
+
}
|
|
95
|
+
catch (exc) {
|
|
96
|
+
throw new CliError("VALIDATE BLOCKED: script JSON invalid", "Script JSON invalid.", {
|
|
97
|
+
exitCode: EXIT_INPUT,
|
|
98
|
+
required: ["valid script JSON"],
|
|
99
|
+
received: [`${finalScriptPath}: ${exc.message}`],
|
|
100
|
+
nextSteps: ["Fix script.initial.json or rerun init."],
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
const issues = [];
|
|
104
|
+
const metadataPath = path.join(dd, "asset_metadata.json");
|
|
105
|
+
if (exists(metadataPath)) {
|
|
106
|
+
let metadata = {};
|
|
107
|
+
try {
|
|
108
|
+
metadata = readJson(metadataPath);
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
metadata = {};
|
|
112
|
+
}
|
|
113
|
+
if (isDict(metadata) && metadata["confidence"] === "low") {
|
|
114
|
+
issues.push({
|
|
115
|
+
code: "LOW_CONFIDENCE_METADATA",
|
|
116
|
+
severity: "error",
|
|
117
|
+
summary: "AI metadata confidence is low.",
|
|
118
|
+
repair_hint: "Inspect assets and patch worldview, role_type, or descriptions explicitly.",
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
for (const field of ["version", "title", "worldview", "style", "actors", "locations", "props", "speakers", "episodes"]) {
|
|
123
|
+
if (!(field in script)) {
|
|
124
|
+
issues.push({
|
|
125
|
+
code: "SCHEMA_TOP_FIELD_MISSING",
|
|
126
|
+
severity: "error",
|
|
127
|
+
summary: `Top-level field missing: ${field}`,
|
|
128
|
+
repair_hint: "Patch script.json or rerun init.",
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (script["version"] !== SCRIPT_SCHEMA_VERSION && script["version"] !== String(SCRIPT_SCHEMA_VERSION)) {
|
|
133
|
+
issues.push({
|
|
134
|
+
code: "SCHEMA_VERSION_UNSUPPORTED",
|
|
135
|
+
severity: "warning",
|
|
136
|
+
summary: `script version should be ${SCRIPT_SCHEMA_VERSION}.`,
|
|
137
|
+
repair_hint: "Update the internal numeric version when migrating script.json.",
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
const actorIds = new Set();
|
|
141
|
+
for (const item of asList(script["actors"])) {
|
|
142
|
+
const id = strOf(item["actor_id"]);
|
|
143
|
+
if (id)
|
|
144
|
+
actorIds.add(id);
|
|
145
|
+
}
|
|
146
|
+
const locationIds = new Set();
|
|
147
|
+
for (const item of asList(script["locations"])) {
|
|
148
|
+
const id = strOf(item["location_id"]);
|
|
149
|
+
if (id)
|
|
150
|
+
locationIds.add(id);
|
|
151
|
+
}
|
|
152
|
+
const propIds = new Set();
|
|
153
|
+
for (const item of asList(script["props"])) {
|
|
154
|
+
const id = strOf(item["prop_id"]);
|
|
155
|
+
if (id)
|
|
156
|
+
propIds.add(id);
|
|
157
|
+
}
|
|
158
|
+
const speakerDisplayNames = new Set();
|
|
159
|
+
for (const item of asList(script["speakers"])) {
|
|
160
|
+
if (!isDict(item))
|
|
161
|
+
continue;
|
|
162
|
+
const name = strOf(item["display_name"]).trim();
|
|
163
|
+
if (name)
|
|
164
|
+
speakerDisplayNames.add(cleanName(name));
|
|
165
|
+
}
|
|
166
|
+
const actors = asList(script["actors"]);
|
|
167
|
+
for (let idx = 0; idx < actors.length; idx++) {
|
|
168
|
+
const actor = actors[idx];
|
|
169
|
+
if (!isDict(actor)) {
|
|
170
|
+
issues.push({
|
|
171
|
+
code: "SCHEMA_ENTITY_FIELD_MISSING",
|
|
172
|
+
severity: "error",
|
|
173
|
+
summary: `actors[${idx}] is not an object.`,
|
|
174
|
+
repair_hint: "Patch actor entry.",
|
|
175
|
+
});
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
const actorName = strOf(actor["actor_name"]).trim();
|
|
179
|
+
for (const field of ["actor_id", "actor_name", "description"]) {
|
|
180
|
+
if (!strOf(actor[field]).trim()) {
|
|
181
|
+
issues.push({
|
|
182
|
+
code: "SCHEMA_ENTITY_FIELD_MISSING",
|
|
183
|
+
severity: "error",
|
|
184
|
+
summary: `Actor missing ${field}: ${actor["actor_id"] || idx}`,
|
|
185
|
+
repair_hint: "Patch actor metadata.",
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
if (actorName && cleanName(actorName) !== actorName) {
|
|
190
|
+
issues.push({
|
|
191
|
+
code: "ASSET_NAME_HAS_STATE_ANNOTATION",
|
|
192
|
+
severity: "error",
|
|
193
|
+
summary: `Actor name contains state annotation: ${actorName}`,
|
|
194
|
+
repair_hint: "Keep actor_name canonical and move state text to states[] or action content only if reusable.",
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
if (actorName && inferNonActorSpeakerKind(actorName) !== "actor") {
|
|
198
|
+
issues.push({
|
|
199
|
+
code: "NONHUMAN_AS_ACTOR",
|
|
200
|
+
severity: "error",
|
|
201
|
+
summary: `Non-human speaker is registered as actor: ${actorName}`,
|
|
202
|
+
repair_hint: "Use speakers[] with source_kind system/broadcast/prop/group/other; do not create an actor.",
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
if (actor["role_type"] && !ROLE_TYPE_VALUES.includes(strOf(actor["role_type"]))) {
|
|
206
|
+
issues.push({
|
|
207
|
+
code: "ENUM_ROLE_TYPE",
|
|
208
|
+
severity: "error",
|
|
209
|
+
summary: `Actor role_type invalid: ${actor["role_type"]}`,
|
|
210
|
+
repair_hint: "Patch role_type to 主角 or 配角.",
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
const locations = asList(script["locations"]);
|
|
215
|
+
for (let idx = 0; idx < locations.length; idx++) {
|
|
216
|
+
const loc = locations[idx];
|
|
217
|
+
if (!isDict(loc)) {
|
|
218
|
+
issues.push({
|
|
219
|
+
code: "SCHEMA_ENTITY_FIELD_MISSING",
|
|
220
|
+
severity: "error",
|
|
221
|
+
summary: `locations[${idx}] is not an object.`,
|
|
222
|
+
repair_hint: "Patch location entry.",
|
|
223
|
+
});
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
const locationName = strOf(loc["location_name"]).trim();
|
|
227
|
+
for (const field of ["location_id", "location_name", "description"]) {
|
|
228
|
+
if (!strOf(loc[field]).trim()) {
|
|
229
|
+
issues.push({
|
|
230
|
+
code: "SCHEMA_ENTITY_FIELD_MISSING",
|
|
231
|
+
severity: "error",
|
|
232
|
+
summary: `Location missing ${field}: ${loc["location_id"] || idx}`,
|
|
233
|
+
repair_hint: "Patch location metadata.",
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
if (locationName && cleanName(locationName) !== locationName) {
|
|
238
|
+
issues.push({
|
|
239
|
+
code: "ASSET_NAME_HAS_STATE_ANNOTATION",
|
|
240
|
+
severity: "error",
|
|
241
|
+
summary: `Location name contains state annotation: ${locationName}`,
|
|
242
|
+
repair_hint: "Keep location_name canonical and move durable visual variants to states[] only when reusable.",
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
const propsArr = asList(script["props"]);
|
|
247
|
+
for (let idx = 0; idx < propsArr.length; idx++) {
|
|
248
|
+
const prop = propsArr[idx];
|
|
249
|
+
if (!isDict(prop)) {
|
|
250
|
+
issues.push({
|
|
251
|
+
code: "SCHEMA_ENTITY_FIELD_MISSING",
|
|
252
|
+
severity: "error",
|
|
253
|
+
summary: `props[${idx}] is not an object.`,
|
|
254
|
+
repair_hint: "Patch prop entry.",
|
|
255
|
+
});
|
|
256
|
+
continue;
|
|
257
|
+
}
|
|
258
|
+
const propName = strOf(prop["prop_name"]).trim();
|
|
259
|
+
for (const field of ["prop_id", "prop_name", "description"]) {
|
|
260
|
+
if (!strOf(prop[field]).trim()) {
|
|
261
|
+
issues.push({
|
|
262
|
+
code: "SCHEMA_ENTITY_FIELD_MISSING",
|
|
263
|
+
severity: "error",
|
|
264
|
+
summary: `Prop missing ${field}: ${prop["prop_id"] || idx}`,
|
|
265
|
+
repair_hint: "Patch prop metadata.",
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
if (propName && cleanName(propName) !== propName) {
|
|
270
|
+
issues.push({
|
|
271
|
+
code: "ASSET_NAME_HAS_STATE_ANNOTATION",
|
|
272
|
+
severity: "error",
|
|
273
|
+
summary: `Prop name contains state annotation: ${propName}`,
|
|
274
|
+
repair_hint: "Keep prop_name canonical and move durable visual variants to states[] only when reusable.",
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
const stateIdsByAsset = new Map();
|
|
279
|
+
for (const [collection, idKey] of [["actors", "actor_id"], ["locations", "location_id"], ["props", "prop_id"]]) {
|
|
280
|
+
const targetKind = { actors: "actor", locations: "location", props: "prop" }[collection];
|
|
281
|
+
for (const asset of asList(script[collection])) {
|
|
282
|
+
const assetId = strOf(asset[idKey]);
|
|
283
|
+
const rawStates = asset["states"];
|
|
284
|
+
stateIdsByAsset.set(assetId, new Set());
|
|
285
|
+
const seenStateNames = new Set();
|
|
286
|
+
// Mirror Python `asset.get("states", []) or []`: absent/null → empty list (no issue)
|
|
287
|
+
if (rawStates !== undefined && rawStates !== null && !isList(rawStates)) {
|
|
288
|
+
issues.push({
|
|
289
|
+
code: "SCHEMA_STATE_LIST_INVALID",
|
|
290
|
+
severity: "error",
|
|
291
|
+
summary: `${collection} ${assetId} states must be an array.`,
|
|
292
|
+
repair_hint: "Patch states to an array.",
|
|
293
|
+
});
|
|
294
|
+
continue;
|
|
295
|
+
}
|
|
296
|
+
const states = isList(rawStates) ? rawStates : [];
|
|
297
|
+
for (const state of states) {
|
|
298
|
+
if (!isDict(state)) {
|
|
299
|
+
issues.push({
|
|
300
|
+
code: "SCHEMA_STATE_INVALID",
|
|
301
|
+
severity: "error",
|
|
302
|
+
summary: `${collection} ${assetId} contains a non-object state.`,
|
|
303
|
+
repair_hint: "Patch or remove the invalid state.",
|
|
304
|
+
});
|
|
305
|
+
continue;
|
|
306
|
+
}
|
|
307
|
+
const sid = strOf(state["state_id"]);
|
|
308
|
+
const sname = strOf(state["state_name"] || state["name"]);
|
|
309
|
+
if (!sid || !sname) {
|
|
310
|
+
issues.push({
|
|
311
|
+
code: "SCHEMA_STATE_FIELD_MISSING",
|
|
312
|
+
severity: "error",
|
|
313
|
+
summary: `${collection} ${assetId} state missing state_id or state_name.`,
|
|
314
|
+
repair_hint: "Patch state_id/state_name.",
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
if (sid && stateIdsByAsset.get(assetId).has(sid)) {
|
|
318
|
+
issues.push({
|
|
319
|
+
code: "DUPLICATE_STATE_ID",
|
|
320
|
+
severity: "error",
|
|
321
|
+
summary: `Duplicate state_id in ${assetId}: ${sid}`,
|
|
322
|
+
repair_hint: "Rename or merge duplicate states.",
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
if (sname && seenStateNames.has(sname)) {
|
|
326
|
+
issues.push({
|
|
327
|
+
code: "DUPLICATE_STATE_NAME",
|
|
328
|
+
severity: "warning",
|
|
329
|
+
summary: `Duplicate state_name in ${assetId}: ${sname}`,
|
|
330
|
+
repair_hint: "Rename duplicate states if they are different shapes.",
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
const reason = stateRejectionReason(targetKind, sname);
|
|
334
|
+
if (sname && reason) {
|
|
335
|
+
issues.push({
|
|
336
|
+
code: "STATE_LABEL_INVALID",
|
|
337
|
+
severity: "error",
|
|
338
|
+
summary: `${collection} ${assetId} state label invalid: ${sname}`,
|
|
339
|
+
repair_hint: "Use one clear state label; do not combine multiple states into one label.",
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
if (sid)
|
|
343
|
+
stateIdsByAsset.get(assetId).add(sid);
|
|
344
|
+
if (sname)
|
|
345
|
+
seenStateNames.add(sname);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
const speakerIds = new Set();
|
|
350
|
+
const speakersArr = asList(script["speakers"]);
|
|
351
|
+
for (let idx = 0; idx < speakersArr.length; idx++) {
|
|
352
|
+
const speaker = speakersArr[idx];
|
|
353
|
+
if (!isDict(speaker)) {
|
|
354
|
+
issues.push({
|
|
355
|
+
code: "SCHEMA_SPEAKER_INVALID",
|
|
356
|
+
severity: "error",
|
|
357
|
+
summary: `speakers[${idx}] is not an object.`,
|
|
358
|
+
repair_hint: "Patch speaker entry.",
|
|
359
|
+
});
|
|
360
|
+
continue;
|
|
361
|
+
}
|
|
362
|
+
const speakerId = strOf(speaker["speaker_id"]);
|
|
363
|
+
const sourceKind = strOf(speaker["source_kind"]);
|
|
364
|
+
const sourceId = speaker["source_id"];
|
|
365
|
+
if (!speakerId || !strOf(speaker["display_name"]).trim()) {
|
|
366
|
+
issues.push({
|
|
367
|
+
code: "SCHEMA_SPEAKER_FIELD_MISSING",
|
|
368
|
+
severity: "error",
|
|
369
|
+
summary: `Speaker missing speaker_id or display_name: ${idx}`,
|
|
370
|
+
repair_hint: "Patch speaker metadata.",
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
if (speakerIds.has(speakerId)) {
|
|
374
|
+
issues.push({
|
|
375
|
+
code: "DUPLICATE_SPEAKER_ID",
|
|
376
|
+
severity: "error",
|
|
377
|
+
summary: `Duplicate speaker_id: ${speakerId}`,
|
|
378
|
+
repair_hint: "Rename or merge duplicate speakers.",
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
if (speakerId)
|
|
382
|
+
speakerIds.add(speakerId);
|
|
383
|
+
if (!SPEAKER_SOURCE_KINDS.has(sourceKind)) {
|
|
384
|
+
issues.push({
|
|
385
|
+
code: "ENUM_SPEAKER_SOURCE_KIND",
|
|
386
|
+
severity: "error",
|
|
387
|
+
summary: `speaker.source_kind invalid: ${sourceKind || "<empty>"}`,
|
|
388
|
+
repair_hint: "Use actor/location/prop/system/broadcast/group/other.",
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
if (sourceKind === "actor" && !actorIds.has(strOf(sourceId))) {
|
|
392
|
+
issues.push({
|
|
393
|
+
code: "DANGLING_SPEAKER_SOURCE_REF",
|
|
394
|
+
severity: "error",
|
|
395
|
+
summary: `Speaker actor source not found: ${sourceId}`,
|
|
396
|
+
repair_hint: "Patch source_id or source_kind.",
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
if (sourceKind === "location" && !locationIds.has(strOf(sourceId))) {
|
|
400
|
+
issues.push({
|
|
401
|
+
code: "DANGLING_SPEAKER_SOURCE_REF",
|
|
402
|
+
severity: "error",
|
|
403
|
+
summary: `Speaker location source not found: ${sourceId}`,
|
|
404
|
+
repair_hint: "Patch source_id or source_kind.",
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
if (sourceKind === "prop" && !propIds.has(strOf(sourceId))) {
|
|
408
|
+
issues.push({
|
|
409
|
+
code: "DANGLING_SPEAKER_SOURCE_REF",
|
|
410
|
+
severity: "error",
|
|
411
|
+
summary: `Speaker prop source not found: ${sourceId}`,
|
|
412
|
+
repair_hint: "Patch source_id or source_kind.",
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
const planPath = path.join(dd, "episode_plan.json");
|
|
417
|
+
if (exists(planPath)) {
|
|
418
|
+
const plan = readJson(planPath);
|
|
419
|
+
if (plan["boundary_confidence"] === "low") {
|
|
420
|
+
issues.push({
|
|
421
|
+
code: "LOW_CONFIDENCE_EPISODE_PLAN",
|
|
422
|
+
severity: "warning",
|
|
423
|
+
summary: "Episode plan used a single-episode fallback.",
|
|
424
|
+
repair_hint: "Inspect the initial script and adjust structure with patch if needed.",
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
const episodes = asList(script["episodes"]);
|
|
429
|
+
if (episodes.length === 0) {
|
|
430
|
+
issues.push({ code: "NO_EPISODES", severity: "blocking", summary: "No episodes in script.", repair_hint: "Rerun init or patch episodes." });
|
|
431
|
+
}
|
|
432
|
+
let totalScenes = 0;
|
|
433
|
+
let totalActions = 0;
|
|
434
|
+
let lastSceneNum = 0;
|
|
435
|
+
for (const ep of episodes) {
|
|
436
|
+
const epTitle = strOf(ep["title"]).trim();
|
|
437
|
+
if (!epTitle || isTechnicalEpisodeTitle(epTitle)) {
|
|
438
|
+
issues.push({
|
|
439
|
+
code: "EPISODE_TITLE_INVALID",
|
|
440
|
+
severity: "warning",
|
|
441
|
+
episode: ep["episode_id"],
|
|
442
|
+
summary: `Episode title is missing or technical: ${epTitle || "<empty>"}`,
|
|
443
|
+
repair_hint: 'Rerun `direct init` to regenerate, or `script patch episode <episode_id> --field title --value "第N集:短标题"`.',
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
const scenes = asList(ep["scenes"]);
|
|
447
|
+
if (scenes.length === 0) {
|
|
448
|
+
issues.push({
|
|
449
|
+
code: "EPISODE_WITHOUT_SCENES",
|
|
450
|
+
severity: "error",
|
|
451
|
+
episode: ep["episode_id"],
|
|
452
|
+
summary: "Episode has no scenes.",
|
|
453
|
+
repair_hint: "Patch at least one scene into the episode.",
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
for (const scene of scenes) {
|
|
457
|
+
totalScenes += 1;
|
|
458
|
+
const rawSceneId = strOf(scene["scene_id"]);
|
|
459
|
+
const match = /^scn_(\d+)$/.exec(rawSceneId);
|
|
460
|
+
if (match) {
|
|
461
|
+
const sceneNum = parseInt(match[1], 10);
|
|
462
|
+
if (sceneNum <= lastSceneNum) {
|
|
463
|
+
issues.push({
|
|
464
|
+
code: "REF_SCENE_ID_NONMONO",
|
|
465
|
+
severity: "error",
|
|
466
|
+
episode: ep["episode_id"],
|
|
467
|
+
scene: rawSceneId,
|
|
468
|
+
summary: `scene_id must increase globally: ${rawSceneId}`,
|
|
469
|
+
repair_hint: "Rerun init or patch scene ids to a global monotonic sequence.",
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
lastSceneNum = Math.max(lastSceneNum, sceneNum);
|
|
473
|
+
}
|
|
474
|
+
else {
|
|
475
|
+
issues.push({
|
|
476
|
+
code: "REF_SCENE_ID_INVALID",
|
|
477
|
+
severity: "error",
|
|
478
|
+
episode: ep["episode_id"],
|
|
479
|
+
scene: rawSceneId || null,
|
|
480
|
+
summary: "scene_id must use scn_### format.",
|
|
481
|
+
repair_hint: "Patch scene_id to scn_###.",
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
const ctx = sceneContext(scene);
|
|
485
|
+
const ctxLocations = asList(ctx["locations"]);
|
|
486
|
+
if (ctxLocations.length === 0) {
|
|
487
|
+
issues.push({
|
|
488
|
+
code: "SCENE_WITHOUT_LOCATION",
|
|
489
|
+
severity: "error",
|
|
490
|
+
episode: ep["episode_id"],
|
|
491
|
+
scene: scene["scene_id"],
|
|
492
|
+
summary: "Scene has no location.",
|
|
493
|
+
repair_hint: "Patch scene.locations with a registered location_id.",
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
for (const ref of ctxLocations) {
|
|
497
|
+
const locationId = strOf(ref["location_id"]);
|
|
498
|
+
const stateId = strOf(ref["state_id"]);
|
|
499
|
+
if (!locationIds.has(locationId)) {
|
|
500
|
+
issues.push({
|
|
501
|
+
code: "DANGLING_LOCATION_REF",
|
|
502
|
+
severity: "error",
|
|
503
|
+
episode: ep["episode_id"],
|
|
504
|
+
scene: scene["scene_id"],
|
|
505
|
+
summary: `Location ref not found: ${locationId || "<empty>"}`,
|
|
506
|
+
repair_hint: "Patch scene location to an existing location_id.",
|
|
507
|
+
});
|
|
508
|
+
}
|
|
509
|
+
if (stateId && !(stateIdsByAsset.get(locationId) ?? new Set()).has(stateId)) {
|
|
510
|
+
issues.push({
|
|
511
|
+
code: "DANGLING_LOCATION_STATE_REF",
|
|
512
|
+
severity: "error",
|
|
513
|
+
episode: ep["episode_id"],
|
|
514
|
+
scene: scene["scene_id"],
|
|
515
|
+
summary: `Location state ref not found: ${stateId}`,
|
|
516
|
+
repair_hint: "Patch location state_id or asset states.",
|
|
517
|
+
});
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
for (const ref of asList(ctx["actors"])) {
|
|
521
|
+
const actorId = strOf(ref["actor_id"]);
|
|
522
|
+
const stateId = strOf(ref["state_id"]);
|
|
523
|
+
if (!actorIds.has(actorId)) {
|
|
524
|
+
issues.push({
|
|
525
|
+
code: "DANGLING_ACTOR_REF",
|
|
526
|
+
severity: "error",
|
|
527
|
+
episode: ep["episode_id"],
|
|
528
|
+
scene: scene["scene_id"],
|
|
529
|
+
summary: `Actor ref not found: ${actorId || "<empty>"}`,
|
|
530
|
+
repair_hint: "Patch scene actor refs to existing actor_id.",
|
|
531
|
+
});
|
|
532
|
+
}
|
|
533
|
+
if (stateId && !(stateIdsByAsset.get(actorId) ?? new Set()).has(stateId)) {
|
|
534
|
+
issues.push({
|
|
535
|
+
code: "DANGLING_ACTOR_STATE_REF",
|
|
536
|
+
severity: "error",
|
|
537
|
+
episode: ep["episode_id"],
|
|
538
|
+
scene: scene["scene_id"],
|
|
539
|
+
summary: `Actor state ref not found: ${stateId}`,
|
|
540
|
+
repair_hint: "Patch actor state_id or asset states.",
|
|
541
|
+
});
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
for (const ref of asList(ctx["props"])) {
|
|
545
|
+
const propId = strOf(ref["prop_id"]);
|
|
546
|
+
const stateId = strOf(ref["state_id"]);
|
|
547
|
+
if (!propIds.has(propId)) {
|
|
548
|
+
issues.push({
|
|
549
|
+
code: "DANGLING_PROP_REF",
|
|
550
|
+
severity: "error",
|
|
551
|
+
episode: ep["episode_id"],
|
|
552
|
+
scene: scene["scene_id"],
|
|
553
|
+
summary: `Prop ref not found: ${propId || "<empty>"}`,
|
|
554
|
+
repair_hint: "Patch scene prop refs to existing prop_id.",
|
|
555
|
+
});
|
|
556
|
+
}
|
|
557
|
+
if (stateId && !(stateIdsByAsset.get(propId) ?? new Set()).has(stateId)) {
|
|
558
|
+
issues.push({
|
|
559
|
+
code: "DANGLING_PROP_STATE_REF",
|
|
560
|
+
severity: "error",
|
|
561
|
+
episode: ep["episode_id"],
|
|
562
|
+
scene: scene["scene_id"],
|
|
563
|
+
summary: `Prop state ref not found: ${stateId}`,
|
|
564
|
+
repair_hint: "Patch prop state_id or asset states.",
|
|
565
|
+
});
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
const actionsArr = asList(scene["actions"]);
|
|
569
|
+
if (actionsArr.length === 0) {
|
|
570
|
+
issues.push({
|
|
571
|
+
code: "SCENE_WITHOUT_ACTIONS",
|
|
572
|
+
severity: "error",
|
|
573
|
+
episode: ep["episode_id"],
|
|
574
|
+
scene: scene["scene_id"],
|
|
575
|
+
summary: "Scene has no actions.",
|
|
576
|
+
repair_hint: "Patch actions from source spans.",
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
for (let actionIndex = 0; actionIndex < actionsArr.length; actionIndex++) {
|
|
580
|
+
const action = actionsArr[actionIndex];
|
|
581
|
+
totalActions += 1;
|
|
582
|
+
const kind = strOf(action["type"]).trim();
|
|
583
|
+
if (!ACTION_TYPE_VALUES.has(kind)) {
|
|
584
|
+
issues.push({
|
|
585
|
+
code: "ENUM_ACTION_TYPE",
|
|
586
|
+
severity: "error",
|
|
587
|
+
episode: ep["episode_id"],
|
|
588
|
+
scene: scene["scene_id"],
|
|
589
|
+
action_index: actionIndex,
|
|
590
|
+
summary: `action.type invalid: ${kind || "<empty>"}`,
|
|
591
|
+
repair_hint: "Patch action.type to dialogue, inner_thought, or action.",
|
|
592
|
+
});
|
|
593
|
+
}
|
|
594
|
+
const content = strOf(action["content"]).trim();
|
|
595
|
+
const hasOverlapLines = action["delivery"] === "overlap" && isList(action["lines"]) && action["lines"].length > 0;
|
|
596
|
+
if (!content && !hasOverlapLines) {
|
|
597
|
+
issues.push({
|
|
598
|
+
code: "EMPTY_ACTION_CONTENT",
|
|
599
|
+
severity: "error",
|
|
600
|
+
episode: ep["episode_id"],
|
|
601
|
+
scene: scene["scene_id"],
|
|
602
|
+
action_index: actionIndex,
|
|
603
|
+
summary: "Action content is empty.",
|
|
604
|
+
repair_hint: "Patch content from a source span.",
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
if (content && contentHasSpeakerPrefix(content, speakerDisplayNames)) {
|
|
608
|
+
issues.push({
|
|
609
|
+
code: "DIALOGUE_CONTENT_SPEAKER_PREFIX",
|
|
610
|
+
severity: "error",
|
|
611
|
+
episode: ep["episode_id"],
|
|
612
|
+
scene: scene["scene_id"],
|
|
613
|
+
action_index: actionIndex,
|
|
614
|
+
summary: "Dialogue content appears to contain speaker prefixes.",
|
|
615
|
+
repair_hint: "Move speaker labels into speaker_id/speakers/lines and keep content as spoken text only.",
|
|
616
|
+
});
|
|
617
|
+
}
|
|
618
|
+
if (action["type"] === "dialogue") {
|
|
619
|
+
const delivery = strOf(action["delivery"] || "single");
|
|
620
|
+
if (!DELIVERY_VALUES.has(delivery)) {
|
|
621
|
+
issues.push({
|
|
622
|
+
code: "ENUM_DIALOGUE_DELIVERY",
|
|
623
|
+
severity: "error",
|
|
624
|
+
episode: ep["episode_id"],
|
|
625
|
+
scene: scene["scene_id"],
|
|
626
|
+
action_index: actionIndex,
|
|
627
|
+
summary: `dialogue.delivery invalid: ${delivery}`,
|
|
628
|
+
repair_hint: "Use single, simultaneous, overlap, or group.",
|
|
629
|
+
});
|
|
630
|
+
}
|
|
631
|
+
if (delivery === "overlap") {
|
|
632
|
+
const lines = asList(action["lines"]);
|
|
633
|
+
if (lines.length === 0) {
|
|
634
|
+
issues.push({
|
|
635
|
+
code: "DIALOGUE_OVERLAP_LINES_EMPTY",
|
|
636
|
+
severity: "error",
|
|
637
|
+
episode: ep["episode_id"],
|
|
638
|
+
scene: scene["scene_id"],
|
|
639
|
+
action_index: actionIndex,
|
|
640
|
+
summary: "Overlapping dialogue has no lines.",
|
|
641
|
+
repair_hint: "Add lines with speaker_id and content.",
|
|
642
|
+
});
|
|
643
|
+
}
|
|
644
|
+
for (let lineIdx = 0; lineIdx < lines.length; lineIdx++) {
|
|
645
|
+
const line = lines[lineIdx] ?? {};
|
|
646
|
+
const sid = strOf(line["speaker_id"]);
|
|
647
|
+
const lineContent = strOf(line["content"]).trim();
|
|
648
|
+
if (!speakerIds.has(sid)) {
|
|
649
|
+
issues.push({
|
|
650
|
+
code: "DANGLING_DIALOGUE_SPEAKER_REF",
|
|
651
|
+
severity: "error",
|
|
652
|
+
episode: ep["episode_id"],
|
|
653
|
+
scene: scene["scene_id"],
|
|
654
|
+
action_index: actionIndex,
|
|
655
|
+
summary: `Overlap line speaker not found: ${sid || "<empty>"}`,
|
|
656
|
+
repair_hint: "Patch speaker_id or add a speaker.",
|
|
657
|
+
});
|
|
658
|
+
}
|
|
659
|
+
if (!lineContent) {
|
|
660
|
+
issues.push({
|
|
661
|
+
code: "EMPTY_DIALOGUE_LINE",
|
|
662
|
+
severity: "error",
|
|
663
|
+
episode: ep["episode_id"],
|
|
664
|
+
scene: scene["scene_id"],
|
|
665
|
+
action_index: actionIndex,
|
|
666
|
+
summary: `Overlap line ${lineIdx} content is empty.`,
|
|
667
|
+
repair_hint: "Patch line content.",
|
|
668
|
+
});
|
|
669
|
+
}
|
|
670
|
+
else if (contentHasSpeakerPrefix(lineContent, speakerDisplayNames)) {
|
|
671
|
+
issues.push({
|
|
672
|
+
code: "DIALOGUE_CONTENT_SPEAKER_PREFIX",
|
|
673
|
+
severity: "error",
|
|
674
|
+
episode: ep["episode_id"],
|
|
675
|
+
scene: scene["scene_id"],
|
|
676
|
+
action_index: actionIndex,
|
|
677
|
+
summary: `Overlap line ${lineIdx} content contains a speaker prefix.`,
|
|
678
|
+
repair_hint: "Keep each overlap line content as spoken text only.",
|
|
679
|
+
});
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
else if (action["speakers"]) {
|
|
684
|
+
const speakersInAction = asList(action["speakers"]);
|
|
685
|
+
if (speakersInAction.length === 0) {
|
|
686
|
+
issues.push({
|
|
687
|
+
code: "DIALOGUE_SPEAKERS_INVALID",
|
|
688
|
+
severity: "error",
|
|
689
|
+
episode: ep["episode_id"],
|
|
690
|
+
scene: scene["scene_id"],
|
|
691
|
+
action_index: actionIndex,
|
|
692
|
+
summary: "dialogue.speakers must be an array.",
|
|
693
|
+
repair_hint: "Patch speakers list.",
|
|
694
|
+
});
|
|
695
|
+
}
|
|
696
|
+
for (const speaker of speakersInAction) {
|
|
697
|
+
const sid = strOf(speaker["speaker_id"]);
|
|
698
|
+
if (!speakerIds.has(sid)) {
|
|
699
|
+
issues.push({
|
|
700
|
+
code: "DANGLING_DIALOGUE_SPEAKER_REF",
|
|
701
|
+
severity: "error",
|
|
702
|
+
episode: ep["episode_id"],
|
|
703
|
+
scene: scene["scene_id"],
|
|
704
|
+
action_index: actionIndex,
|
|
705
|
+
summary: `Dialogue speaker not found: ${sid || "<empty>"}`,
|
|
706
|
+
repair_hint: "Patch speaker_id or add a speaker.",
|
|
707
|
+
});
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
else if (action["speaker_id"]) {
|
|
712
|
+
const sid = strOf(action["speaker_id"]);
|
|
713
|
+
if (!speakerIds.has(sid)) {
|
|
714
|
+
issues.push({
|
|
715
|
+
code: "DANGLING_DIALOGUE_SPEAKER_REF",
|
|
716
|
+
severity: "error",
|
|
717
|
+
episode: ep["episode_id"],
|
|
718
|
+
scene: scene["scene_id"],
|
|
719
|
+
action_index: actionIndex,
|
|
720
|
+
summary: `Dialogue speaker not found: ${sid}`,
|
|
721
|
+
repair_hint: "Patch speaker_id or add a speaker.",
|
|
722
|
+
});
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
else if (!action["actor_id"]) {
|
|
726
|
+
issues.push({
|
|
727
|
+
code: "DIALOGUE_WITHOUT_SPEAKER",
|
|
728
|
+
severity: "error",
|
|
729
|
+
episode: ep["episode_id"],
|
|
730
|
+
scene: scene["scene_id"],
|
|
731
|
+
action_index: actionIndex,
|
|
732
|
+
summary: "Dialogue has no speaker.",
|
|
733
|
+
repair_hint: "Patch speaker_id, speakers, lines, or legacy actor_id.",
|
|
734
|
+
});
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
if (action["type"] === "inner_thought") {
|
|
738
|
+
const sid = strOf(action["speaker_id"]);
|
|
739
|
+
if (sid && !speakerIds.has(sid)) {
|
|
740
|
+
issues.push({
|
|
741
|
+
code: "DANGLING_DIALOGUE_SPEAKER_REF",
|
|
742
|
+
severity: "error",
|
|
743
|
+
episode: ep["episode_id"],
|
|
744
|
+
scene: scene["scene_id"],
|
|
745
|
+
action_index: actionIndex,
|
|
746
|
+
summary: `Inner thought speaker not found: ${sid}`,
|
|
747
|
+
repair_hint: "Patch speaker_id or add a speaker.",
|
|
748
|
+
});
|
|
749
|
+
}
|
|
750
|
+
if (!action["actor_id"] && !sid) {
|
|
751
|
+
issues.push({
|
|
752
|
+
code: "DIALOGUE_WITHOUT_ACTOR",
|
|
753
|
+
severity: "error",
|
|
754
|
+
episode: ep["episode_id"],
|
|
755
|
+
scene: scene["scene_id"],
|
|
756
|
+
action_index: actionIndex,
|
|
757
|
+
summary: "Inner thought has no actor_id or speaker_id.",
|
|
758
|
+
repair_hint: "Patch actor_id, speaker_id, or speaker registry.",
|
|
759
|
+
});
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
if (action["actor_id"] && !actorIds.has(strOf(action["actor_id"]))) {
|
|
763
|
+
issues.push({
|
|
764
|
+
code: "DANGLING_ACTION_ACTOR_REF",
|
|
765
|
+
severity: "error",
|
|
766
|
+
episode: ep["episode_id"],
|
|
767
|
+
scene: scene["scene_id"],
|
|
768
|
+
action_index: actionIndex,
|
|
769
|
+
summary: `Action actor_id not found: ${action["actor_id"]}`,
|
|
770
|
+
repair_hint: "Patch action actor_id to an existing actor.",
|
|
771
|
+
});
|
|
772
|
+
}
|
|
773
|
+
for (const change of asList(action["state_changes"])) {
|
|
774
|
+
const targetKind = strOf(change["target_kind"]);
|
|
775
|
+
const targetId = strOf(change["target_id"]);
|
|
776
|
+
const fromStateId = strOf(change["from_state_id"]);
|
|
777
|
+
const toStateId = strOf(change["to_state_id"]);
|
|
778
|
+
const effectiveFrom = strOf(change["effective_from"] || "after_action");
|
|
779
|
+
if (!SCRIPT_TARGET_KINDS.has(targetKind)) {
|
|
780
|
+
issues.push({
|
|
781
|
+
code: "STATE_CHANGE_TARGET_KIND_INVALID",
|
|
782
|
+
severity: "error",
|
|
783
|
+
episode: ep["episode_id"],
|
|
784
|
+
scene: scene["scene_id"],
|
|
785
|
+
action_index: actionIndex,
|
|
786
|
+
summary: `state_changes target_kind invalid: ${targetKind || "<empty>"}`,
|
|
787
|
+
repair_hint: "Use actor, location, or prop.",
|
|
788
|
+
});
|
|
789
|
+
continue;
|
|
790
|
+
}
|
|
791
|
+
const validIds = { actor: actorIds, location: locationIds, prop: propIds }[targetKind];
|
|
792
|
+
if (!validIds.has(targetId)) {
|
|
793
|
+
issues.push({
|
|
794
|
+
code: "DANGLING_STATE_CHANGE_TARGET_REF",
|
|
795
|
+
severity: "error",
|
|
796
|
+
episode: ep["episode_id"],
|
|
797
|
+
scene: scene["scene_id"],
|
|
798
|
+
action_index: actionIndex,
|
|
799
|
+
summary: `State change target not found: ${targetKind}:${targetId}`,
|
|
800
|
+
repair_hint: "Patch target_id.",
|
|
801
|
+
});
|
|
802
|
+
}
|
|
803
|
+
for (const [label, sid] of [["from_state_id", fromStateId], ["to_state_id", toStateId]]) {
|
|
804
|
+
if (sid && !(stateIdsByAsset.get(targetId) ?? new Set()).has(sid)) {
|
|
805
|
+
issues.push({
|
|
806
|
+
code: "DANGLING_STATE_CHANGE_STATE_REF",
|
|
807
|
+
severity: "error",
|
|
808
|
+
episode: ep["episode_id"],
|
|
809
|
+
scene: scene["scene_id"],
|
|
810
|
+
action_index: actionIndex,
|
|
811
|
+
summary: `State change ${label} not found: ${sid}`,
|
|
812
|
+
repair_hint: "Patch state change or asset states.",
|
|
813
|
+
});
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
if (!EFFECTIVE_FROM_VALUES.has(effectiveFrom)) {
|
|
817
|
+
issues.push({
|
|
818
|
+
code: "ENUM_STATE_CHANGE_EFFECTIVE_FROM",
|
|
819
|
+
severity: "error",
|
|
820
|
+
episode: ep["episode_id"],
|
|
821
|
+
scene: scene["scene_id"],
|
|
822
|
+
action_index: actionIndex,
|
|
823
|
+
summary: `effective_from invalid: ${effectiveFrom}`,
|
|
824
|
+
repair_hint: "Use before_action or after_action.",
|
|
825
|
+
});
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
const transition = action["transition_prompt"];
|
|
829
|
+
if (transition !== null && transition !== undefined) {
|
|
830
|
+
if (!isDict(transition)) {
|
|
831
|
+
issues.push({
|
|
832
|
+
code: "TRANSITION_PROMPT_INVALID",
|
|
833
|
+
severity: "error",
|
|
834
|
+
episode: ep["episode_id"],
|
|
835
|
+
scene: scene["scene_id"],
|
|
836
|
+
action_index: actionIndex,
|
|
837
|
+
summary: "transition_prompt must be an object.",
|
|
838
|
+
repair_hint: "Patch or clear transition_prompt.",
|
|
839
|
+
});
|
|
840
|
+
}
|
|
841
|
+
else {
|
|
842
|
+
const targetKind = strOf(transition["target_kind"]);
|
|
843
|
+
const targetId = strOf(transition["target_id"]);
|
|
844
|
+
if (!SCRIPT_TARGET_KINDS.has(targetKind)) {
|
|
845
|
+
issues.push({
|
|
846
|
+
code: "TRANSITION_PROMPT_TARGET_KIND_INVALID",
|
|
847
|
+
severity: "error",
|
|
848
|
+
episode: ep["episode_id"],
|
|
849
|
+
scene: scene["scene_id"],
|
|
850
|
+
action_index: actionIndex,
|
|
851
|
+
summary: `transition target_kind invalid: ${targetKind || "<empty>"}`,
|
|
852
|
+
repair_hint: "Use actor, location, or prop.",
|
|
853
|
+
});
|
|
854
|
+
}
|
|
855
|
+
else {
|
|
856
|
+
const validIds = { actor: actorIds, location: locationIds, prop: propIds }[targetKind];
|
|
857
|
+
if (!validIds.has(targetId)) {
|
|
858
|
+
issues.push({
|
|
859
|
+
code: "DANGLING_TRANSITION_TARGET_REF",
|
|
860
|
+
severity: "error",
|
|
861
|
+
episode: ep["episode_id"],
|
|
862
|
+
scene: scene["scene_id"],
|
|
863
|
+
action_index: actionIndex,
|
|
864
|
+
summary: `Transition target not found: ${targetKind}:${targetId}`,
|
|
865
|
+
repair_hint: "Patch transition target.",
|
|
866
|
+
});
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
const hasBlocking = issues.some((it) => it["severity"] === "blocking");
|
|
875
|
+
const hasErrors = issues.some((it) => it["severity"] === "error");
|
|
876
|
+
const validation = {
|
|
877
|
+
passed: !hasBlocking && !hasErrors,
|
|
878
|
+
has_blocking: hasBlocking,
|
|
879
|
+
issues,
|
|
880
|
+
stats: {
|
|
881
|
+
episodes: episodes.length,
|
|
882
|
+
scenes: totalScenes,
|
|
883
|
+
actions: totalActions,
|
|
884
|
+
actors: asList(script["actors"]).length,
|
|
885
|
+
locations: asList(script["locations"]).length,
|
|
886
|
+
props: asList(script["props"]).length,
|
|
887
|
+
speakers: asList(script["speakers"]).length,
|
|
888
|
+
},
|
|
889
|
+
script_path: finalScriptPath,
|
|
890
|
+
validated_at: new Date().toISOString().replace(/\.\d+Z$/, "Z"),
|
|
891
|
+
};
|
|
892
|
+
writeJson(path.join(dd, "validation.json"), validation);
|
|
893
|
+
return validation;
|
|
894
|
+
}
|
|
895
|
+
// ---------------------------------------------------------------------------
|
|
896
|
+
// Resolve/lookup helpers
|
|
897
|
+
// ---------------------------------------------------------------------------
|
|
898
|
+
function resolveAsset(items, idKey, nameKey, raw) {
|
|
899
|
+
for (const item of items) {
|
|
900
|
+
if (raw === item[idKey] || raw === item[nameKey])
|
|
901
|
+
return item;
|
|
902
|
+
}
|
|
903
|
+
return null;
|
|
904
|
+
}
|
|
905
|
+
const ASSET_KEY_MAP = {
|
|
906
|
+
actor: ["actors", "actor_id", "actor_name"],
|
|
907
|
+
location: ["locations", "location_id", "location_name"],
|
|
908
|
+
prop: ["props", "prop_id", "prop_name"],
|
|
909
|
+
};
|
|
910
|
+
export function assetKeys(assetType) {
|
|
911
|
+
const entry = ASSET_KEY_MAP[assetType];
|
|
912
|
+
if (!entry) {
|
|
913
|
+
throw new CliError("PATCH BLOCKED: Asset type invalid", "Asset type invalid.", {
|
|
914
|
+
exitCode: EXIT_USAGE,
|
|
915
|
+
required: ["asset_type: actor, location, or prop"],
|
|
916
|
+
received: [`asset_type: ${assetType}`],
|
|
917
|
+
nextSteps: ["Fix the patch operation and rerun patch."],
|
|
918
|
+
});
|
|
919
|
+
}
|
|
920
|
+
return entry;
|
|
921
|
+
}
|
|
922
|
+
function resolvePatchAsset(script, op, assetType = null) {
|
|
923
|
+
const kind = strOf(assetType || op["asset_type"]);
|
|
924
|
+
const [key, idKey, nameKey] = assetKeys(kind);
|
|
925
|
+
const raw = op[idKey] ?? op["id"] ?? op["name"] ?? op[nameKey];
|
|
926
|
+
const asset = resolveAsset(asList(script[key]), idKey, nameKey, strOf(raw));
|
|
927
|
+
if (!asset) {
|
|
928
|
+
throw new CliError("PATCH BLOCKED: Asset not found", "Asset not found.", {
|
|
929
|
+
exitCode: EXIT_USAGE,
|
|
930
|
+
required: [`existing ${idKey} or ${nameKey}`],
|
|
931
|
+
received: [JSON.stringify(op)],
|
|
932
|
+
nextSteps: ["Inspect assets and fix the patch."],
|
|
933
|
+
});
|
|
934
|
+
}
|
|
935
|
+
return [asset, idKey, nameKey];
|
|
936
|
+
}
|
|
937
|
+
function nextStateId(script) {
|
|
938
|
+
let maxSeen = 0;
|
|
939
|
+
for (const key of ["actors", "locations", "props"]) {
|
|
940
|
+
for (const asset of asList(script[key])) {
|
|
941
|
+
for (const state of asList(asset["states"])) {
|
|
942
|
+
const m = /^st_(\d+)$/.exec(strOf(state["state_id"]));
|
|
943
|
+
if (m)
|
|
944
|
+
maxSeen = Math.max(maxSeen, parseInt(m[1], 10));
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
return fmtId("st", maxSeen + 1);
|
|
949
|
+
}
|
|
950
|
+
function normalizeStates(script, rawStates, assetKind = "") {
|
|
951
|
+
if (!isList(rawStates)) {
|
|
952
|
+
throw new CliError("PATCH BLOCKED: States invalid", "States invalid.", {
|
|
953
|
+
exitCode: EXIT_USAGE,
|
|
954
|
+
required: ["states: array of state names or {state_id,state_name} objects"],
|
|
955
|
+
received: [typeof rawStates],
|
|
956
|
+
nextSteps: ["Fix the patch operation and rerun patch."],
|
|
957
|
+
});
|
|
958
|
+
}
|
|
959
|
+
let maxSeen = 0;
|
|
960
|
+
for (const key of ["actors", "locations", "props"]) {
|
|
961
|
+
for (const asset of asList(script[key])) {
|
|
962
|
+
for (const state of asList(asset["states"])) {
|
|
963
|
+
const m = /^st_(\d+)$/.exec(strOf(state["state_id"]));
|
|
964
|
+
if (m)
|
|
965
|
+
maxSeen = Math.max(maxSeen, parseInt(m[1], 10));
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
const states = [];
|
|
970
|
+
const seenNames = new Set();
|
|
971
|
+
for (const raw of rawStates) {
|
|
972
|
+
let name = "";
|
|
973
|
+
let sid = "";
|
|
974
|
+
if (typeof raw === "string") {
|
|
975
|
+
name = raw.trim();
|
|
976
|
+
maxSeen += 1;
|
|
977
|
+
sid = fmtId("st", maxSeen);
|
|
978
|
+
}
|
|
979
|
+
else if (isDict(raw)) {
|
|
980
|
+
name = strOf(raw["state_name"] || raw["name"]).trim();
|
|
981
|
+
sid = strOf(raw["state_id"] || raw["id"]).trim();
|
|
982
|
+
if (!sid) {
|
|
983
|
+
maxSeen += 1;
|
|
984
|
+
sid = fmtId("st", maxSeen);
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
else
|
|
988
|
+
continue;
|
|
989
|
+
if (!name || seenNames.has(name))
|
|
990
|
+
continue;
|
|
991
|
+
if (assetKind === "actor") {
|
|
992
|
+
const reason = stateLabelError(name);
|
|
993
|
+
if (reason) {
|
|
994
|
+
throw new CliError("PATCH BLOCKED: State label invalid", "State label invalid.", {
|
|
995
|
+
exitCode: EXIT_USAGE,
|
|
996
|
+
required: ["one clear state label"],
|
|
997
|
+
received: [name],
|
|
998
|
+
nextSteps: ["Do not combine multiple states into one label."],
|
|
999
|
+
errorCode: "STATE_LABEL_INVALID",
|
|
1000
|
+
});
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
seenNames.add(name);
|
|
1004
|
+
states.push({ state_id: sid, state_name: name });
|
|
1005
|
+
}
|
|
1006
|
+
return states;
|
|
1007
|
+
}
|
|
1008
|
+
export function ensureRefId(script, assetType, rawId, opts = {}) {
|
|
1009
|
+
const allowNone = opts.allowNone ?? false;
|
|
1010
|
+
if (rawId === null && allowNone)
|
|
1011
|
+
return null;
|
|
1012
|
+
const value = strOf(rawId).trim();
|
|
1013
|
+
if (!value && allowNone)
|
|
1014
|
+
return null;
|
|
1015
|
+
const [key, idKey] = assetKeys(assetType);
|
|
1016
|
+
const valid = new Set();
|
|
1017
|
+
for (const item of asList(script[key]))
|
|
1018
|
+
valid.add(strOf(item[idKey]));
|
|
1019
|
+
if (!valid.has(value)) {
|
|
1020
|
+
throw new CliError("PATCH BLOCKED: Reference target not found", "Reference target not found.", {
|
|
1021
|
+
exitCode: EXIT_USAGE,
|
|
1022
|
+
required: [`existing ${idKey}`],
|
|
1023
|
+
received: [`${idKey}: ${value || "<empty>"}`],
|
|
1024
|
+
nextSteps: ["Inspect assets and fix the patch."],
|
|
1025
|
+
});
|
|
1026
|
+
}
|
|
1027
|
+
return value;
|
|
1028
|
+
}
|
|
1029
|
+
function idKeyForKind(kind) {
|
|
1030
|
+
const map = { actor: "actor_id", location: "location_id", prop: "prop_id" };
|
|
1031
|
+
return map[kind];
|
|
1032
|
+
}
|
|
1033
|
+
function pluralForKind(kind) {
|
|
1034
|
+
const map = { actor: "actors", location: "locations", prop: "props" };
|
|
1035
|
+
return map[kind];
|
|
1036
|
+
}
|
|
1037
|
+
export function parseAssetTarget(raw) {
|
|
1038
|
+
const value = strOf(raw).trim();
|
|
1039
|
+
if (!value.includes(":")) {
|
|
1040
|
+
throw new CliError("SCRIPT OP BLOCKED: Target invalid", "Target invalid.", {
|
|
1041
|
+
exitCode: EXIT_USAGE,
|
|
1042
|
+
required: ["target: actor:<id>, location:<id>, or prop:<id>"],
|
|
1043
|
+
received: [value || "<empty>"],
|
|
1044
|
+
nextSteps: ["Use a concrete asset target."],
|
|
1045
|
+
errorCode: "TARGET_INVALID",
|
|
1046
|
+
});
|
|
1047
|
+
}
|
|
1048
|
+
const idx = value.indexOf(":");
|
|
1049
|
+
const kind = value.slice(0, idx).trim();
|
|
1050
|
+
const targetId = value.slice(idx + 1).trim();
|
|
1051
|
+
if (!SCRIPT_TARGET_KINDS.has(kind) || !targetId) {
|
|
1052
|
+
throw new CliError("SCRIPT OP BLOCKED: Target invalid", "Target invalid.", {
|
|
1053
|
+
exitCode: EXIT_USAGE,
|
|
1054
|
+
required: ["target: actor:<id>, location:<id>, or prop:<id>"],
|
|
1055
|
+
received: [value],
|
|
1056
|
+
nextSteps: ["Use actor, location, or prop with a non-empty id."],
|
|
1057
|
+
errorCode: "TARGET_INVALID",
|
|
1058
|
+
});
|
|
1059
|
+
}
|
|
1060
|
+
return [kind, targetId];
|
|
1061
|
+
}
|
|
1062
|
+
export function parseStateTarget(raw) {
|
|
1063
|
+
const value = strOf(raw).trim();
|
|
1064
|
+
if (!value.includes("/")) {
|
|
1065
|
+
throw new CliError("SCRIPT OP BLOCKED: State target invalid", "State target invalid.", {
|
|
1066
|
+
exitCode: EXIT_USAGE,
|
|
1067
|
+
required: ["state target: actor:<id>/<state_id>"],
|
|
1068
|
+
received: [value || "<empty>"],
|
|
1069
|
+
nextSteps: ["Use a concrete state target."],
|
|
1070
|
+
errorCode: "STATE_TARGET_INVALID",
|
|
1071
|
+
});
|
|
1072
|
+
}
|
|
1073
|
+
const lastSlash = value.lastIndexOf("/");
|
|
1074
|
+
const assetRaw = value.slice(0, lastSlash);
|
|
1075
|
+
const stateId = value.slice(lastSlash + 1).trim();
|
|
1076
|
+
const [kind, targetId] = parseAssetTarget(assetRaw);
|
|
1077
|
+
if (!stateId) {
|
|
1078
|
+
throw new CliError("SCRIPT OP BLOCKED: State target invalid", "State target invalid.", {
|
|
1079
|
+
exitCode: EXIT_USAGE,
|
|
1080
|
+
required: ["state_id after '/'"],
|
|
1081
|
+
received: [value],
|
|
1082
|
+
nextSteps: ["Use a non-empty state_id."],
|
|
1083
|
+
errorCode: "STATE_TARGET_INVALID",
|
|
1084
|
+
});
|
|
1085
|
+
}
|
|
1086
|
+
return [kind, targetId, stateId];
|
|
1087
|
+
}
|
|
1088
|
+
export function parseSceneRef(raw) {
|
|
1089
|
+
const value = strOf(raw).trim();
|
|
1090
|
+
if (!value.includes("/")) {
|
|
1091
|
+
throw new CliError("SCRIPT OP BLOCKED: Scene ref invalid", "Scene ref invalid.", {
|
|
1092
|
+
exitCode: EXIT_USAGE,
|
|
1093
|
+
required: ["scene ref: ep_001/scn_001"],
|
|
1094
|
+
received: [value || "<empty>"],
|
|
1095
|
+
nextSteps: ["Use ep_id/scn_id."],
|
|
1096
|
+
errorCode: "SCENE_REF_INVALID",
|
|
1097
|
+
});
|
|
1098
|
+
}
|
|
1099
|
+
const idx = value.indexOf("/");
|
|
1100
|
+
return [value.slice(0, idx).trim(), value.slice(idx + 1).trim()];
|
|
1101
|
+
}
|
|
1102
|
+
export function parseActionRef(raw) {
|
|
1103
|
+
const value = strOf(raw).trim();
|
|
1104
|
+
if (!value.includes("#")) {
|
|
1105
|
+
throw new CliError("SCRIPT OP BLOCKED: Action ref invalid", "Action ref invalid.", {
|
|
1106
|
+
exitCode: EXIT_USAGE,
|
|
1107
|
+
required: ["action ref: ep_001/scn_001#4"],
|
|
1108
|
+
received: [value || "<empty>"],
|
|
1109
|
+
nextSteps: ["Use ep_id/scn_id#action_index."],
|
|
1110
|
+
errorCode: "ACTION_REF_INVALID",
|
|
1111
|
+
});
|
|
1112
|
+
}
|
|
1113
|
+
const lastHash = value.lastIndexOf("#");
|
|
1114
|
+
const sceneRaw = value.slice(0, lastHash);
|
|
1115
|
+
const indexRaw = value.slice(lastHash + 1);
|
|
1116
|
+
const [epId, sceneId] = parseSceneRef(sceneRaw);
|
|
1117
|
+
const actionIndex = parseInt(indexRaw, 10);
|
|
1118
|
+
if (Number.isNaN(actionIndex)) {
|
|
1119
|
+
throw new CliError("SCRIPT OP BLOCKED: Action index invalid", "Action index invalid.", {
|
|
1120
|
+
exitCode: EXIT_USAGE,
|
|
1121
|
+
required: ["integer action index after '#'"],
|
|
1122
|
+
received: [value],
|
|
1123
|
+
nextSteps: ["Use a zero-based action index."],
|
|
1124
|
+
errorCode: "ACTION_INDEX_INVALID",
|
|
1125
|
+
});
|
|
1126
|
+
}
|
|
1127
|
+
return [epId, sceneId, actionIndex];
|
|
1128
|
+
}
|
|
1129
|
+
function resolveAssetByTarget(script, kind, targetId) {
|
|
1130
|
+
const [key, idKey] = assetKeys(kind);
|
|
1131
|
+
for (const item of asList(script[key])) {
|
|
1132
|
+
if (strOf(item[idKey]) === targetId)
|
|
1133
|
+
return item;
|
|
1134
|
+
}
|
|
1135
|
+
throw new CliError("SCRIPT OP BLOCKED: Asset not found", "Asset not found.", {
|
|
1136
|
+
exitCode: EXIT_USAGE,
|
|
1137
|
+
required: [`existing ${kind} id`],
|
|
1138
|
+
received: [`${kind}:${targetId}`],
|
|
1139
|
+
nextSteps: ["Inspect assets and fix the target."],
|
|
1140
|
+
errorCode: "ASSET_NOT_FOUND",
|
|
1141
|
+
});
|
|
1142
|
+
}
|
|
1143
|
+
function resolveState(script, kind, targetId, stateId) {
|
|
1144
|
+
const asset = resolveAssetByTarget(script, kind, targetId);
|
|
1145
|
+
for (const state of asList(asset["states"])) {
|
|
1146
|
+
if (strOf(state["state_id"]) === stateId)
|
|
1147
|
+
return state;
|
|
1148
|
+
}
|
|
1149
|
+
throw new CliError("SCRIPT OP BLOCKED: State not found", "State not found.", {
|
|
1150
|
+
exitCode: EXIT_USAGE,
|
|
1151
|
+
required: ["existing state_id on the target asset"],
|
|
1152
|
+
received: [`${kind}:${targetId}/${stateId}`],
|
|
1153
|
+
nextSteps: ["Inspect states and fix the target."],
|
|
1154
|
+
errorCode: "STATE_NOT_FOUND",
|
|
1155
|
+
});
|
|
1156
|
+
}
|
|
1157
|
+
function validateStateForTarget(script, kind, targetId, stateId) {
|
|
1158
|
+
const value = strOf(stateId).trim();
|
|
1159
|
+
if (!value)
|
|
1160
|
+
return null;
|
|
1161
|
+
resolveState(script, kind, targetId, value);
|
|
1162
|
+
return value;
|
|
1163
|
+
}
|
|
1164
|
+
function nextSpeakerId(script, sourceKind, sourceId = null) {
|
|
1165
|
+
const existing = new Set();
|
|
1166
|
+
for (const item of asList(script["speakers"]))
|
|
1167
|
+
existing.add(strOf(item["speaker_id"]));
|
|
1168
|
+
if (sourceKind === "actor" && sourceId) {
|
|
1169
|
+
const candidate = `spk_${sourceId}`;
|
|
1170
|
+
if (!existing.has(candidate))
|
|
1171
|
+
return candidate;
|
|
1172
|
+
}
|
|
1173
|
+
let maxSeen = 0;
|
|
1174
|
+
const prefix = `spk_${sourceKind}_`;
|
|
1175
|
+
for (const id of existing) {
|
|
1176
|
+
if (id.startsWith(prefix)) {
|
|
1177
|
+
const m = new RegExp(`^${prefix.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}(\\d+)$`).exec(id);
|
|
1178
|
+
if (m)
|
|
1179
|
+
maxSeen = Math.max(maxSeen, parseInt(m[1], 10));
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
return `${prefix}${String(maxSeen + 1).padStart(3, "0")}`;
|
|
1183
|
+
}
|
|
1184
|
+
function speakerSourceActorId(script, speakerId) {
|
|
1185
|
+
for (const speaker of asList(script["speakers"])) {
|
|
1186
|
+
if (strOf(speaker["speaker_id"]) === speakerId && speaker["source_kind"] === "actor") {
|
|
1187
|
+
return strOf(speaker["source_id"]).trim() || null;
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
return null;
|
|
1191
|
+
}
|
|
1192
|
+
function ensureSpeakerId(script, speakerId) {
|
|
1193
|
+
const value = strOf(speakerId).trim();
|
|
1194
|
+
const valid = new Set();
|
|
1195
|
+
for (const item of asList(script["speakers"]))
|
|
1196
|
+
valid.add(strOf(item["speaker_id"]));
|
|
1197
|
+
if (!valid.has(value)) {
|
|
1198
|
+
throw new CliError("SCRIPT OP BLOCKED: Speaker not found", "Speaker not found.", {
|
|
1199
|
+
exitCode: EXIT_USAGE,
|
|
1200
|
+
required: ["existing speaker_id"],
|
|
1201
|
+
received: [value || "<empty>"],
|
|
1202
|
+
nextSteps: ["Add a speaker first, or fix the dialogue patch."],
|
|
1203
|
+
errorCode: "SPEAKER_NOT_FOUND",
|
|
1204
|
+
});
|
|
1205
|
+
}
|
|
1206
|
+
return value;
|
|
1207
|
+
}
|
|
1208
|
+
function contextRefsForKind(context, kind) {
|
|
1209
|
+
return asList(context[pluralForKind(kind)]);
|
|
1210
|
+
}
|
|
1211
|
+
function findContextRef(context, kind, targetId) {
|
|
1212
|
+
const idKey = idKeyForKind(kind);
|
|
1213
|
+
for (const ref of contextRefsForKind(context, kind)) {
|
|
1214
|
+
if (strOf(ref[idKey]) === targetId)
|
|
1215
|
+
return ref;
|
|
1216
|
+
}
|
|
1217
|
+
return null;
|
|
1218
|
+
}
|
|
1219
|
+
function setContextState(script, epId, sceneId, kind, targetId, stateId) {
|
|
1220
|
+
ensureRefId(script, kind, targetId);
|
|
1221
|
+
const normalizedState = validateStateForTarget(script, kind, targetId, stateId);
|
|
1222
|
+
const scene = findScene(script, epId, sceneId);
|
|
1223
|
+
const ctx = sceneContext(scene);
|
|
1224
|
+
const refs = [...contextRefsForKind(ctx, kind)];
|
|
1225
|
+
const idKey = idKeyForKind(kind);
|
|
1226
|
+
const existing = refs.find((ref) => strOf(ref[idKey]) === targetId);
|
|
1227
|
+
if (existing) {
|
|
1228
|
+
existing["state_id"] = normalizedState;
|
|
1229
|
+
}
|
|
1230
|
+
else {
|
|
1231
|
+
refs.push({ [idKey]: targetId, state_id: normalizedState });
|
|
1232
|
+
}
|
|
1233
|
+
ctx[pluralForKind(kind)] = refs;
|
|
1234
|
+
setSceneContext(scene, ctx);
|
|
1235
|
+
}
|
|
1236
|
+
function inferStateBeforeAction(script, epId, sceneId, actionIndex, kind, targetId) {
|
|
1237
|
+
const scene = findScene(script, epId, sceneId);
|
|
1238
|
+
const ctx = sceneContext(scene);
|
|
1239
|
+
let current = null;
|
|
1240
|
+
const ref = findContextRef(ctx, kind, targetId);
|
|
1241
|
+
if (ref)
|
|
1242
|
+
current = strOf(ref["state_id"]).trim() || null;
|
|
1243
|
+
const actions = asList(scene["actions"]);
|
|
1244
|
+
for (let i = 0; i < actionIndex && i < actions.length; i++) {
|
|
1245
|
+
for (const change of asList(actions[i]["state_changes"])) {
|
|
1246
|
+
if (strOf(change["target_kind"]) === kind && strOf(change["target_id"]) === targetId) {
|
|
1247
|
+
const toState = strOf(change["to_state_id"]).trim();
|
|
1248
|
+
if (toState)
|
|
1249
|
+
current = toState;
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
return current;
|
|
1254
|
+
}
|
|
1255
|
+
function stateRefSummary(kind, targetId, stateId, location, role) {
|
|
1256
|
+
return { target: `${kind}:${targetId}/${stateId}`, location, role };
|
|
1257
|
+
}
|
|
1258
|
+
export function collectStateRefs(script, kind, targetId, stateId) {
|
|
1259
|
+
const refs = [];
|
|
1260
|
+
const idKey = idKeyForKind(kind);
|
|
1261
|
+
for (const ep of asList(script["episodes"])) {
|
|
1262
|
+
const epId = strOf(ep["episode_id"]);
|
|
1263
|
+
for (const scene of asList(ep["scenes"])) {
|
|
1264
|
+
const sceneId = strOf(scene["scene_id"]);
|
|
1265
|
+
const ctx = sceneContext(scene);
|
|
1266
|
+
const refsList = contextRefsForKind(ctx, kind);
|
|
1267
|
+
for (let idx = 0; idx < refsList.length; idx++) {
|
|
1268
|
+
const ref = refsList[idx];
|
|
1269
|
+
if (strOf(ref[idKey]) === targetId && strOf(ref["state_id"]) === stateId) {
|
|
1270
|
+
refs.push(stateRefSummary(kind, targetId, stateId, `${epId}/${sceneId}.context.${pluralForKind(kind)}[${idx}]`, "scene_initial_state"));
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1273
|
+
const actions = asList(scene["actions"]);
|
|
1274
|
+
for (let actionIdx = 0; actionIdx < actions.length; actionIdx++) {
|
|
1275
|
+
const changes = asList(actions[actionIdx]["state_changes"]);
|
|
1276
|
+
for (let changeIdx = 0; changeIdx < changes.length; changeIdx++) {
|
|
1277
|
+
const change = changes[changeIdx];
|
|
1278
|
+
if (strOf(change["target_kind"]) !== kind || strOf(change["target_id"]) !== targetId)
|
|
1279
|
+
continue;
|
|
1280
|
+
if (strOf(change["from_state_id"]) === stateId) {
|
|
1281
|
+
refs.push(stateRefSummary(kind, targetId, stateId, `${epId}/${sceneId}#${actionIdx}.state_changes[${changeIdx}].from_state_id`, "state_change_from"));
|
|
1282
|
+
}
|
|
1283
|
+
if (strOf(change["to_state_id"]) === stateId) {
|
|
1284
|
+
refs.push(stateRefSummary(kind, targetId, stateId, `${epId}/${sceneId}#${actionIdx}.state_changes[${changeIdx}].to_state_id`, "state_change_to"));
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
}
|
|
1290
|
+
return refs;
|
|
1291
|
+
}
|
|
1292
|
+
function nextSceneId(script) {
|
|
1293
|
+
let maxSeen = 0;
|
|
1294
|
+
for (const ep of asList(script["episodes"])) {
|
|
1295
|
+
for (const scene of asList(ep["scenes"])) {
|
|
1296
|
+
const m = /^scn_(\d+)$/.exec(strOf(scene["scene_id"]));
|
|
1297
|
+
if (m)
|
|
1298
|
+
maxSeen = Math.max(maxSeen, parseInt(m[1], 10));
|
|
1299
|
+
}
|
|
1300
|
+
}
|
|
1301
|
+
return fmtId("scn", maxSeen + 1);
|
|
1302
|
+
}
|
|
1303
|
+
function sceneIdExists(script, sceneId) {
|
|
1304
|
+
for (const ep of asList(script["episodes"])) {
|
|
1305
|
+
for (const scene of asList(ep["scenes"])) {
|
|
1306
|
+
if (scene["scene_id"] === sceneId)
|
|
1307
|
+
return true;
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1310
|
+
return false;
|
|
1311
|
+
}
|
|
1312
|
+
function renumberSceneIds(script) {
|
|
1313
|
+
let counter = 0;
|
|
1314
|
+
for (const ep of asList(script["episodes"])) {
|
|
1315
|
+
for (const scene of asList(ep["scenes"])) {
|
|
1316
|
+
counter += 1;
|
|
1317
|
+
scene["scene_id"] = fmtId("scn", counter);
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1320
|
+
}
|
|
1321
|
+
// ---------------------------------------------------------------------------
|
|
1322
|
+
// apply_patch_operations
|
|
1323
|
+
// ---------------------------------------------------------------------------
|
|
1324
|
+
function opErr(title, message, opts = {}) {
|
|
1325
|
+
return new CliError(title, message, {
|
|
1326
|
+
exitCode: opts.exitCode ?? EXIT_USAGE,
|
|
1327
|
+
required: opts.required,
|
|
1328
|
+
received: opts.received,
|
|
1329
|
+
nextSteps: opts.nextSteps,
|
|
1330
|
+
op: opts.op,
|
|
1331
|
+
errorCode: opts.errorCode,
|
|
1332
|
+
hint: opts.hint,
|
|
1333
|
+
});
|
|
1334
|
+
}
|
|
1335
|
+
export function applyPatchOperations(script, sourceText, operations) {
|
|
1336
|
+
const applied = [];
|
|
1337
|
+
for (const op of operations) {
|
|
1338
|
+
const kind = strOf(op["op"]);
|
|
1339
|
+
if (kind === "state.add") {
|
|
1340
|
+
const [targetKind, targetId] = parseAssetTarget(op["target"]);
|
|
1341
|
+
const asset = resolveAssetByTarget(script, targetKind, targetId);
|
|
1342
|
+
const name = strOf(op["name"] || op["state_name"]).trim();
|
|
1343
|
+
const description = strOf(op["description"]).trim();
|
|
1344
|
+
const stateId = strOf(op["state_id"]).trim() || nextStateId(script);
|
|
1345
|
+
if (!name) {
|
|
1346
|
+
throw opErr("SCRIPT OP BLOCKED: State name empty", "State name empty.", {
|
|
1347
|
+
required: ["name"], received: [JSON.stringify(op)],
|
|
1348
|
+
nextSteps: ["Provide a state name."], op: kind, errorCode: "STATE_NAME_EMPTY",
|
|
1349
|
+
});
|
|
1350
|
+
}
|
|
1351
|
+
const reason = stateRejectionReason(targetKind, name);
|
|
1352
|
+
if (reason) {
|
|
1353
|
+
throw opErr("SCRIPT OP BLOCKED: State label invalid", "State label invalid.", {
|
|
1354
|
+
required: ["one clear state label"], received: [name],
|
|
1355
|
+
nextSteps: ["Do not combine multiple states into one label."], op: kind, errorCode: "STATE_LABEL_INVALID",
|
|
1356
|
+
});
|
|
1357
|
+
}
|
|
1358
|
+
if (!isList(asset["states"]))
|
|
1359
|
+
asset["states"] = [];
|
|
1360
|
+
const existingStates = asset["states"];
|
|
1361
|
+
if (existingStates.some((s) => strOf(s["state_id"]) === stateId)) {
|
|
1362
|
+
throw opErr("SCRIPT OP BLOCKED: State id exists", "State id exists.", { required: ["unused state_id"], received: [stateId], nextSteps: ["Use another state_id or edit the existing state."], op: kind, errorCode: "STATE_ID_EXISTS" });
|
|
1363
|
+
}
|
|
1364
|
+
if (existingStates.some((s) => strOf(s["state_name"] || s["name"]) === name)) {
|
|
1365
|
+
throw opErr("SCRIPT OP BLOCKED: State name exists", "State name exists.", { required: ["unused state name"], received: [name], nextSteps: ["Rename the existing state or choose another name."], op: kind, errorCode: "STATE_NAME_EXISTS" });
|
|
1366
|
+
}
|
|
1367
|
+
const state = { state_id: stateId, state_name: name };
|
|
1368
|
+
if (description)
|
|
1369
|
+
state["description"] = description;
|
|
1370
|
+
existingStates.push(state);
|
|
1371
|
+
op["state_id"] = stateId;
|
|
1372
|
+
applied.push(kind);
|
|
1373
|
+
}
|
|
1374
|
+
else if (kind === "state.rename") {
|
|
1375
|
+
const [targetKind, targetId, stateId] = parseStateTarget(op["target"]);
|
|
1376
|
+
const state = resolveState(script, targetKind, targetId, stateId);
|
|
1377
|
+
const name = strOf(op["name"] || op["state_name"]).trim();
|
|
1378
|
+
if (!name) {
|
|
1379
|
+
throw opErr("SCRIPT OP BLOCKED: State name empty", "State name empty.", { required: ["name"], received: [JSON.stringify(op)], nextSteps: ["Provide a state name."], op: kind, errorCode: "STATE_NAME_EMPTY" });
|
|
1380
|
+
}
|
|
1381
|
+
const reason = stateRejectionReason(targetKind, name);
|
|
1382
|
+
if (reason) {
|
|
1383
|
+
throw opErr("SCRIPT OP BLOCKED: State label invalid", "State label invalid.", { required: ["one clear state label"], received: [name], nextSteps: ["Do not combine multiple states into one label."], op: kind, errorCode: "STATE_LABEL_INVALID" });
|
|
1384
|
+
}
|
|
1385
|
+
state["state_name"] = name;
|
|
1386
|
+
applied.push(kind);
|
|
1387
|
+
}
|
|
1388
|
+
else if (kind === "state.describe") {
|
|
1389
|
+
const [targetKind, targetId, stateId] = parseStateTarget(op["target"]);
|
|
1390
|
+
const state = resolveState(script, targetKind, targetId, stateId);
|
|
1391
|
+
state["description"] = strOf(op["description"]).trim();
|
|
1392
|
+
applied.push(kind);
|
|
1393
|
+
}
|
|
1394
|
+
else if (kind === "state.delete") {
|
|
1395
|
+
const [targetKind, targetId, stateId] = parseStateTarget(op["target"]);
|
|
1396
|
+
const asset = resolveAssetByTarget(script, targetKind, targetId);
|
|
1397
|
+
resolveState(script, targetKind, targetId, stateId);
|
|
1398
|
+
const strategy = strOf(op["strategy"]).trim();
|
|
1399
|
+
const replacement = strOf(op["replacement"]).trim();
|
|
1400
|
+
if (strategy !== "replace" && strategy !== "remove") {
|
|
1401
|
+
throw opErr("SCRIPT OP BLOCKED: Delete strategy invalid", "Delete strategy invalid.", { required: ["strategy: replace or remove"], received: [strategy || "<empty>"], nextSteps: ["Choose replace with --replacement, or remove."], op: kind, errorCode: "DELETE_STRATEGY_INVALID" });
|
|
1402
|
+
}
|
|
1403
|
+
if (strategy === "replace") {
|
|
1404
|
+
if (!replacement) {
|
|
1405
|
+
throw opErr("SCRIPT OP BLOCKED: Replacement missing", "Replacement missing.", { required: ["replacement state_id"], received: ["<empty>"], nextSteps: ["Pass --replacement with an existing state_id."], op: kind, errorCode: "REPLACEMENT_MISSING" });
|
|
1406
|
+
}
|
|
1407
|
+
validateStateForTarget(script, targetKind, targetId, replacement);
|
|
1408
|
+
}
|
|
1409
|
+
const contextField = pluralForKind(targetKind);
|
|
1410
|
+
const idKey = idKeyForKind(targetKind);
|
|
1411
|
+
for (const ep of asList(script["episodes"])) {
|
|
1412
|
+
for (const scene of asList(ep["scenes"])) {
|
|
1413
|
+
const ctx = sceneContext(scene);
|
|
1414
|
+
for (const ref of contextRefsForKind(ctx, targetKind)) {
|
|
1415
|
+
if (strOf(ref[idKey]) === targetId && strOf(ref["state_id"]) === stateId) {
|
|
1416
|
+
ref["state_id"] = strategy === "replace" ? replacement : null;
|
|
1417
|
+
}
|
|
1418
|
+
}
|
|
1419
|
+
ctx[contextField] = contextRefsForKind(ctx, targetKind);
|
|
1420
|
+
setSceneContext(scene, ctx);
|
|
1421
|
+
for (const action of asList(scene["actions"])) {
|
|
1422
|
+
const nextChanges = [];
|
|
1423
|
+
for (const change of asList(action["state_changes"])) {
|
|
1424
|
+
if (strOf(change["target_kind"]) === targetKind && strOf(change["target_id"]) === targetId) {
|
|
1425
|
+
let touched = false;
|
|
1426
|
+
for (const stateField of ["from_state_id", "to_state_id"]) {
|
|
1427
|
+
if (strOf(change[stateField]) === stateId) {
|
|
1428
|
+
touched = true;
|
|
1429
|
+
if (strategy === "replace")
|
|
1430
|
+
change[stateField] = replacement;
|
|
1431
|
+
}
|
|
1432
|
+
}
|
|
1433
|
+
if (strategy === "remove" && touched)
|
|
1434
|
+
continue;
|
|
1435
|
+
}
|
|
1436
|
+
nextChanges.push(change);
|
|
1437
|
+
}
|
|
1438
|
+
if (action["state_changes"] !== undefined && action["state_changes"] !== null) {
|
|
1439
|
+
if (nextChanges.length > 0)
|
|
1440
|
+
action["state_changes"] = nextChanges;
|
|
1441
|
+
else
|
|
1442
|
+
delete action["state_changes"];
|
|
1443
|
+
}
|
|
1444
|
+
}
|
|
1445
|
+
}
|
|
1446
|
+
}
|
|
1447
|
+
asset["states"] = asList(asset["states"]).filter((s) => strOf(s["state_id"]) !== stateId);
|
|
1448
|
+
applied.push(kind);
|
|
1449
|
+
}
|
|
1450
|
+
else if (kind === "context.set") {
|
|
1451
|
+
const [epId, sceneId] = parseSceneRef(op["at"]);
|
|
1452
|
+
const [targetKind, targetId] = parseAssetTarget(op["target"]);
|
|
1453
|
+
setContextState(script, epId, sceneId, targetKind, targetId, strOf(op["state"] || op["state_id"]).trim());
|
|
1454
|
+
applied.push(kind);
|
|
1455
|
+
}
|
|
1456
|
+
else if (kind === "context.clear") {
|
|
1457
|
+
const [epId, sceneId] = parseSceneRef(op["at"]);
|
|
1458
|
+
const [targetKind, targetId] = parseAssetTarget(op["target"]);
|
|
1459
|
+
setContextState(script, epId, sceneId, targetKind, targetId, null);
|
|
1460
|
+
applied.push(kind);
|
|
1461
|
+
}
|
|
1462
|
+
else if (kind === "action.state.change") {
|
|
1463
|
+
const [epId, sceneId, actionIndex] = parseActionRef(op["at"]);
|
|
1464
|
+
const [targetKind, targetId] = parseAssetTarget(op["target"]);
|
|
1465
|
+
ensureRefId(script, targetKind, targetId);
|
|
1466
|
+
const toState = validateStateForTarget(script, targetKind, targetId, strOf(op["to"] || op["to_state_id"]).trim());
|
|
1467
|
+
if (!toState) {
|
|
1468
|
+
throw opErr("SCRIPT OP BLOCKED: Target state missing", "Target state missing.", { required: ["to state_id"], received: [JSON.stringify(op)], nextSteps: ["Pass --to with an existing state_id."], op: kind, errorCode: "TO_STATE_MISSING" });
|
|
1469
|
+
}
|
|
1470
|
+
const fromStateExplicit = strOf(op["from"] || op["from_state_id"]).trim();
|
|
1471
|
+
const fromState = fromStateExplicit || inferStateBeforeAction(script, epId, sceneId, actionIndex, targetKind, targetId);
|
|
1472
|
+
if (!fromState) {
|
|
1473
|
+
throw opErr("SCRIPT OP BLOCKED: From state ambiguous", "Unable to infer current state before this action.", { required: ["scene initial state or --from"], received: [`${op["at"]} ${op["target"]}`], nextSteps: ["Set scene context first, or pass --from explicitly."], op: kind, errorCode: "FROM_STATE_AMBIGUOUS", hint: "先设置场景初始状态,或修复前序状态变化。" });
|
|
1474
|
+
}
|
|
1475
|
+
validateStateForTarget(script, targetKind, targetId, fromState);
|
|
1476
|
+
const effective = strOf(op["effective"] || op["effective_from"] || "after").trim();
|
|
1477
|
+
const effectiveFrom = effective === "after" ? "after_action" : effective === "before" ? "before_action" : effective;
|
|
1478
|
+
if (!EFFECTIVE_FROM_VALUES.has(effectiveFrom)) {
|
|
1479
|
+
throw opErr("SCRIPT OP BLOCKED: Effective invalid", "Effective invalid.", { required: ["effective: after or before"], received: [effective], nextSteps: ["Use after or before."], op: kind, errorCode: "EFFECTIVE_INVALID" });
|
|
1480
|
+
}
|
|
1481
|
+
const action = findAction(script, epId, sceneId, actionIndex);
|
|
1482
|
+
const changes = asList(action["state_changes"]).filter((c) => !(strOf(c["target_kind"]) === targetKind && strOf(c["target_id"]) === targetId));
|
|
1483
|
+
changes.push({
|
|
1484
|
+
target_kind: targetKind,
|
|
1485
|
+
target_id: targetId,
|
|
1486
|
+
from_state_id: fromState,
|
|
1487
|
+
to_state_id: toState,
|
|
1488
|
+
effective_from: effectiveFrom,
|
|
1489
|
+
});
|
|
1490
|
+
action["state_changes"] = changes;
|
|
1491
|
+
applied.push(kind);
|
|
1492
|
+
}
|
|
1493
|
+
else if (kind === "action.state.remove") {
|
|
1494
|
+
const [epId, sceneId, actionIndex] = parseActionRef(op["at"]);
|
|
1495
|
+
const [targetKind, targetId] = parseAssetTarget(op["target"]);
|
|
1496
|
+
const action = findAction(script, epId, sceneId, actionIndex);
|
|
1497
|
+
const changes = asList(action["state_changes"]).filter((c) => !(strOf(c["target_kind"]) === targetKind && strOf(c["target_id"]) === targetId));
|
|
1498
|
+
if (changes.length > 0)
|
|
1499
|
+
action["state_changes"] = changes;
|
|
1500
|
+
else
|
|
1501
|
+
delete action["state_changes"];
|
|
1502
|
+
applied.push(kind);
|
|
1503
|
+
}
|
|
1504
|
+
else if (kind === "action.transition.set") {
|
|
1505
|
+
const [epId, sceneId, actionIndex] = parseActionRef(op["at"]);
|
|
1506
|
+
const [targetKind, targetId] = parseAssetTarget(op["target"]);
|
|
1507
|
+
ensureRefId(script, targetKind, targetId);
|
|
1508
|
+
const process = strOf(op["process"]).trim();
|
|
1509
|
+
const contrast = strOf(op["contrast"]).trim();
|
|
1510
|
+
if (!process || !contrast) {
|
|
1511
|
+
throw opErr("SCRIPT OP BLOCKED: Transition prompt incomplete", "Transition prompt incomplete.", { required: ["process and contrast"], received: [JSON.stringify(op)], nextSteps: ["Provide both process and contrast."], op: kind, errorCode: "TRANSITION_PROMPT_INCOMPLETE" });
|
|
1512
|
+
}
|
|
1513
|
+
const action = findAction(script, epId, sceneId, actionIndex);
|
|
1514
|
+
action["transition_prompt"] = { target_kind: targetKind, target_id: targetId, process, contrast };
|
|
1515
|
+
applied.push(kind);
|
|
1516
|
+
}
|
|
1517
|
+
else if (kind === "action.transition.clear") {
|
|
1518
|
+
const [epId, sceneId, actionIndex] = parseActionRef(op["at"]);
|
|
1519
|
+
const [targetKind, targetId] = parseAssetTarget(op["target"]);
|
|
1520
|
+
const action = findAction(script, epId, sceneId, actionIndex);
|
|
1521
|
+
const transition = action["transition_prompt"];
|
|
1522
|
+
if (isDict(transition) && strOf(transition["target_kind"]) === targetKind && strOf(transition["target_id"]) === targetId) {
|
|
1523
|
+
delete action["transition_prompt"];
|
|
1524
|
+
}
|
|
1525
|
+
applied.push(kind);
|
|
1526
|
+
}
|
|
1527
|
+
else if (kind === "speaker.add") {
|
|
1528
|
+
const sourceKind = strOf(op["kind"] || op["source_kind"]).trim();
|
|
1529
|
+
if (!SPEAKER_SOURCE_KINDS.has(sourceKind)) {
|
|
1530
|
+
throw opErr("SCRIPT OP BLOCKED: Speaker kind invalid", "Speaker kind invalid.", { required: ["kind: actor/location/prop/system/broadcast/group/other"], received: [sourceKind || "<empty>"], nextSteps: ["Use a supported speaker kind."], op: kind, errorCode: "SPEAKER_KIND_INVALID" });
|
|
1531
|
+
}
|
|
1532
|
+
const name = strOf(op["name"] || op["display_name"]).trim();
|
|
1533
|
+
if (!name) {
|
|
1534
|
+
throw opErr("SCRIPT OP BLOCKED: Speaker name empty", "Speaker name empty.", { required: ["name"], received: [JSON.stringify(op)], nextSteps: ["Provide display name."], op: kind, errorCode: "SPEAKER_NAME_EMPTY" });
|
|
1535
|
+
}
|
|
1536
|
+
const sourceId = strOf(op["source_id"]).trim() || null;
|
|
1537
|
+
if (SCRIPT_TARGET_KINDS.has(sourceKind)) {
|
|
1538
|
+
if (!sourceId) {
|
|
1539
|
+
throw opErr("SCRIPT OP BLOCKED: Speaker source missing", "Speaker source missing.", { required: ["source_id for actor/location/prop speakers"], received: ["<empty>"], nextSteps: ["Pass --source-id."], op: kind, errorCode: "SPEAKER_SOURCE_MISSING" });
|
|
1540
|
+
}
|
|
1541
|
+
ensureRefId(script, sourceKind, sourceId);
|
|
1542
|
+
}
|
|
1543
|
+
const speakerId = strOf(op["speaker_id"]).trim() || nextSpeakerId(script, sourceKind, sourceId);
|
|
1544
|
+
if (asList(script["speakers"]).some((s) => strOf(s["speaker_id"]) === speakerId)) {
|
|
1545
|
+
throw opErr("SCRIPT OP BLOCKED: Speaker id exists", "Speaker id exists.", { required: ["unused speaker_id"], received: [speakerId], nextSteps: ["Use another speaker_id."], op: kind, errorCode: "SPEAKER_ID_EXISTS" });
|
|
1546
|
+
}
|
|
1547
|
+
if (!isList(script["speakers"]))
|
|
1548
|
+
script["speakers"] = [];
|
|
1549
|
+
script["speakers"].push({
|
|
1550
|
+
speaker_id: speakerId,
|
|
1551
|
+
display_name: name,
|
|
1552
|
+
source_kind: sourceKind,
|
|
1553
|
+
source_id: sourceId,
|
|
1554
|
+
voice_desc: strOf(op["voice_desc"]).trim(),
|
|
1555
|
+
});
|
|
1556
|
+
applied.push(kind);
|
|
1557
|
+
}
|
|
1558
|
+
else if (kind === "dialogue.speakers") {
|
|
1559
|
+
const [epId, sceneId, actionIndex] = parseActionRef(op["at"]);
|
|
1560
|
+
const delivery = strOf(op["delivery"] || "simultaneous").trim();
|
|
1561
|
+
if (delivery !== "single" && delivery !== "simultaneous" && delivery !== "group") {
|
|
1562
|
+
throw opErr("SCRIPT OP BLOCKED: Delivery invalid", "Delivery invalid.", { required: ["delivery: single, simultaneous, or group"], received: [delivery], nextSteps: ["Use a supported delivery."], op: kind, errorCode: "DELIVERY_INVALID" });
|
|
1563
|
+
}
|
|
1564
|
+
let rawSpeakers = op["speakers"] ?? op["speaker"] ?? [];
|
|
1565
|
+
if (typeof rawSpeakers === "string")
|
|
1566
|
+
rawSpeakers = [rawSpeakers];
|
|
1567
|
+
if (!isList(rawSpeakers) || rawSpeakers.length === 0) {
|
|
1568
|
+
throw opErr("SCRIPT OP BLOCKED: Speakers empty", "Speakers empty.", { required: ["speaker list"], received: [JSON.stringify(op)], nextSteps: ["Pass at least one --speaker."], op: kind, errorCode: "SPEAKERS_EMPTY" });
|
|
1569
|
+
}
|
|
1570
|
+
const speakerIds = rawSpeakers.map((sid) => ensureSpeakerId(script, strOf(sid)));
|
|
1571
|
+
const action = findAction(script, epId, sceneId, actionIndex);
|
|
1572
|
+
action["type"] = "dialogue";
|
|
1573
|
+
action["delivery"] = delivery;
|
|
1574
|
+
action["speakers"] = speakerIds.map((sid) => ({ speaker_id: sid }));
|
|
1575
|
+
delete action["lines"];
|
|
1576
|
+
const actorId = speakerIds.length === 1 ? speakerSourceActorId(script, speakerIds[0]) : null;
|
|
1577
|
+
if (actorId) {
|
|
1578
|
+
action["actor_id"] = actorId;
|
|
1579
|
+
action["speaker_id"] = speakerIds[0];
|
|
1580
|
+
}
|
|
1581
|
+
else {
|
|
1582
|
+
delete action["actor_id"];
|
|
1583
|
+
delete action["speaker_id"];
|
|
1584
|
+
}
|
|
1585
|
+
applied.push(kind);
|
|
1586
|
+
}
|
|
1587
|
+
else if (kind === "dialogue.overlap") {
|
|
1588
|
+
const [epId, sceneId, actionIndex] = parseActionRef(op["at"]);
|
|
1589
|
+
let rawLines = op["lines"] ?? op["line"] ?? [];
|
|
1590
|
+
if (typeof rawLines === "string")
|
|
1591
|
+
rawLines = [rawLines];
|
|
1592
|
+
if (!isList(rawLines) || rawLines.length === 0) {
|
|
1593
|
+
throw opErr("SCRIPT OP BLOCKED: Lines empty", "Lines empty.", { required: ["line list"], received: [JSON.stringify(op)], nextSteps: ["Pass at least one --line speaker_id:content."], op: kind, errorCode: "LINES_EMPTY" });
|
|
1594
|
+
}
|
|
1595
|
+
const lines = [];
|
|
1596
|
+
for (const line of rawLines) {
|
|
1597
|
+
let speakerId;
|
|
1598
|
+
let content;
|
|
1599
|
+
if (isDict(line)) {
|
|
1600
|
+
speakerId = ensureSpeakerId(script, strOf(line["speaker_id"]));
|
|
1601
|
+
content = strOf(line["content"]).trim();
|
|
1602
|
+
}
|
|
1603
|
+
else {
|
|
1604
|
+
const rawLine = strOf(line);
|
|
1605
|
+
if (!rawLine.includes(":") && !rawLine.includes(":")) {
|
|
1606
|
+
throw opErr("SCRIPT OP BLOCKED: Line invalid", "Line invalid.", { required: ["speaker_id:content"], received: [rawLine], nextSteps: ["Use --line spk_xxx:对白."], op: kind, errorCode: "LINE_INVALID" });
|
|
1607
|
+
}
|
|
1608
|
+
const m = /^([^::]+)[::](.*)$/.exec(rawLine);
|
|
1609
|
+
if (!m) {
|
|
1610
|
+
throw opErr("SCRIPT OP BLOCKED: Line invalid", "Line invalid.", { required: ["speaker_id:content"], received: [rawLine], nextSteps: ["Use --line spk_xxx:对白."], op: kind, errorCode: "LINE_INVALID" });
|
|
1611
|
+
}
|
|
1612
|
+
speakerId = ensureSpeakerId(script, m[1]);
|
|
1613
|
+
content = m[2].trim();
|
|
1614
|
+
}
|
|
1615
|
+
if (!content) {
|
|
1616
|
+
throw opErr("SCRIPT OP BLOCKED: Line content empty", "Line content empty.", { required: ["non-empty line content"], received: [JSON.stringify(line)], nextSteps: ["Provide line content."], op: kind, errorCode: "LINE_CONTENT_EMPTY" });
|
|
1617
|
+
}
|
|
1618
|
+
lines.push({ speaker_id: speakerId, content });
|
|
1619
|
+
}
|
|
1620
|
+
const action = findAction(script, epId, sceneId, actionIndex);
|
|
1621
|
+
action["type"] = "dialogue";
|
|
1622
|
+
action["delivery"] = "overlap";
|
|
1623
|
+
action["lines"] = lines;
|
|
1624
|
+
action["content"] = lines.map((l) => l["content"]).join(" / ");
|
|
1625
|
+
delete action["speakers"];
|
|
1626
|
+
delete action["actor_id"];
|
|
1627
|
+
delete action["speaker_id"];
|
|
1628
|
+
applied.push(kind);
|
|
1629
|
+
}
|
|
1630
|
+
else if (kind === "set_worldview") {
|
|
1631
|
+
const worldview = strOf(op["worldview"]).trim();
|
|
1632
|
+
if (!WORLDVIEW_VALUES.includes(worldview)) {
|
|
1633
|
+
throw opErr("PATCH BLOCKED: Worldview invalid", "Worldview invalid.", { required: [`worldview: one of ${WORLDVIEW_VALUES.join(", ")}`], received: [worldview || "<empty>"], nextSteps: ["Use a supported worldview enum."] });
|
|
1634
|
+
}
|
|
1635
|
+
script["worldview"] = worldview;
|
|
1636
|
+
if ("worldview_raw" in op)
|
|
1637
|
+
script["worldview_raw"] = strOf(op["worldview_raw"]).trim();
|
|
1638
|
+
applied.push(kind);
|
|
1639
|
+
}
|
|
1640
|
+
else if (kind === "set_actor_role_type") {
|
|
1641
|
+
const [asset] = resolvePatchAsset(script, op, "actor");
|
|
1642
|
+
const roleType = strOf(op["role_type"]).trim();
|
|
1643
|
+
if (!ROLE_TYPE_VALUES.includes(roleType)) {
|
|
1644
|
+
throw opErr("PATCH BLOCKED: Role type invalid", "Role type invalid.", { required: ["role_type: 主角 or 配角"], received: [roleType || "<empty>"], nextSteps: ["Use a supported actor role_type."] });
|
|
1645
|
+
}
|
|
1646
|
+
asset["role_type"] = roleType;
|
|
1647
|
+
applied.push(kind);
|
|
1648
|
+
}
|
|
1649
|
+
else if (kind === "set_asset_description") {
|
|
1650
|
+
const [asset] = resolvePatchAsset(script, op);
|
|
1651
|
+
const description = strOf(op["description"]).trim();
|
|
1652
|
+
if (!description) {
|
|
1653
|
+
throw opErr("PATCH BLOCKED: Description empty", "Description empty.", { required: ["description: non-empty string"], received: [JSON.stringify(op)], nextSteps: ["Provide a concise grounded description."] });
|
|
1654
|
+
}
|
|
1655
|
+
asset["description"] = description;
|
|
1656
|
+
applied.push(kind);
|
|
1657
|
+
}
|
|
1658
|
+
else if (kind === "set_action_type") {
|
|
1659
|
+
const actionIndex = op["action_index"];
|
|
1660
|
+
if (typeof actionIndex !== "number" || !Number.isInteger(actionIndex)) {
|
|
1661
|
+
throw opErr("PATCH BLOCKED: Action index invalid", "Action index invalid.", { required: ["action_index: integer"], received: [JSON.stringify(op)], nextSteps: ["Inspect episodes and fix the patch."] });
|
|
1662
|
+
}
|
|
1663
|
+
const actionType = strOf(op["action_type"] || op["type"]).trim();
|
|
1664
|
+
if (!ACTION_TYPE_VALUES.has(actionType)) {
|
|
1665
|
+
throw opErr("PATCH BLOCKED: Action type invalid", "Action type invalid.", { required: ["action_type: dialogue, inner_thought, or action"], received: [actionType || "<empty>"], nextSteps: ["Use a supported action type."] });
|
|
1666
|
+
}
|
|
1667
|
+
const action = findAction(script, strOf(op["episode_id"]), strOf(op["scene_id"]), actionIndex);
|
|
1668
|
+
action["type"] = actionType;
|
|
1669
|
+
applied.push(kind);
|
|
1670
|
+
}
|
|
1671
|
+
else if (kind === "rename_actor" || kind === "rename_location" || kind === "rename_prop") {
|
|
1672
|
+
const map = {
|
|
1673
|
+
rename_actor: ["actors", "actor_id", "actor_name"],
|
|
1674
|
+
rename_location: ["locations", "location_id", "location_name"],
|
|
1675
|
+
rename_prop: ["props", "prop_id", "prop_name"],
|
|
1676
|
+
};
|
|
1677
|
+
const [key, idKey, nameKey] = map[kind];
|
|
1678
|
+
const raw = op[idKey] ?? op["id"] ?? op["name"];
|
|
1679
|
+
const newName = op["new_name"] ?? op[nameKey];
|
|
1680
|
+
const asset = resolveAsset(asList(script[key]), idKey, nameKey, strOf(raw));
|
|
1681
|
+
if (!asset || !newName) {
|
|
1682
|
+
throw opErr("PATCH BLOCKED: Rename target invalid", "Rename target invalid.", { required: [`${idKey} or name, and new_name`], received: [JSON.stringify(op)], nextSteps: ["Fix the patch operation and rerun patch."] });
|
|
1683
|
+
}
|
|
1684
|
+
asset[nameKey] = String(newName);
|
|
1685
|
+
applied.push(kind);
|
|
1686
|
+
}
|
|
1687
|
+
else if (kind === "set_asset_aliases") {
|
|
1688
|
+
const [asset] = resolvePatchAsset(script, op);
|
|
1689
|
+
const aliases = op["aliases"];
|
|
1690
|
+
if (!isList(aliases) || aliases.some((it) => typeof it !== "string")) {
|
|
1691
|
+
throw opErr("PATCH BLOCKED: Aliases invalid", "Aliases invalid.", { required: ["aliases: array of strings"], received: [JSON.stringify(op)], nextSteps: ["Fix the patch operation and rerun patch."] });
|
|
1692
|
+
}
|
|
1693
|
+
const seen = new Set();
|
|
1694
|
+
const cleanedAliases = [];
|
|
1695
|
+
for (const item of aliases) {
|
|
1696
|
+
const alias = item.trim();
|
|
1697
|
+
if (alias && !seen.has(alias)) {
|
|
1698
|
+
seen.add(alias);
|
|
1699
|
+
cleanedAliases.push(alias);
|
|
1700
|
+
}
|
|
1701
|
+
}
|
|
1702
|
+
asset["aliases"] = cleanedAliases;
|
|
1703
|
+
applied.push(kind);
|
|
1704
|
+
}
|
|
1705
|
+
else if (kind === "set_asset_states") {
|
|
1706
|
+
const [asset] = resolvePatchAsset(script, op);
|
|
1707
|
+
const assetKind = strOf(op["asset_type"]).trim();
|
|
1708
|
+
asset["states"] = normalizeStates(script, op["states"], assetKind);
|
|
1709
|
+
applied.push(kind);
|
|
1710
|
+
}
|
|
1711
|
+
else if (kind === "merge_actor" || kind === "merge_location" || kind === "merge_prop") {
|
|
1712
|
+
const map = {
|
|
1713
|
+
merge_actor: ["actors", "actor_id", "actors"],
|
|
1714
|
+
merge_location: ["locations", "location_id", "locations"],
|
|
1715
|
+
merge_prop: ["props", "prop_id", "props"],
|
|
1716
|
+
};
|
|
1717
|
+
const [key, idKey, refKey] = map[kind];
|
|
1718
|
+
const sourceId = op["source_id"];
|
|
1719
|
+
const targetId = op["target_id"];
|
|
1720
|
+
if (!sourceId || !targetId) {
|
|
1721
|
+
throw opErr("PATCH BLOCKED: Merge target invalid", "Merge target invalid.", { required: ["source_id and target_id"], received: [JSON.stringify(op)], nextSteps: ["Fix the patch operation and rerun patch."] });
|
|
1722
|
+
}
|
|
1723
|
+
script[key] = asList(script[key]).filter((it) => it[idKey] !== sourceId);
|
|
1724
|
+
for (const ep of asList(script["episodes"])) {
|
|
1725
|
+
for (const scene of asList(ep["scenes"])) {
|
|
1726
|
+
for (const ref of asList(scene[refKey])) {
|
|
1727
|
+
if (ref[idKey] === sourceId)
|
|
1728
|
+
ref[idKey] = targetId;
|
|
1729
|
+
}
|
|
1730
|
+
for (const action of asList(scene["actions"])) {
|
|
1731
|
+
if (idKey === "actor_id" && action["actor_id"] === sourceId)
|
|
1732
|
+
action["actor_id"] = targetId;
|
|
1733
|
+
}
|
|
1734
|
+
}
|
|
1735
|
+
}
|
|
1736
|
+
applied.push(kind);
|
|
1737
|
+
}
|
|
1738
|
+
else if (kind === "set_scene_actor_ref" || kind === "set_scene_location_ref" || kind === "set_scene_prop_ref") {
|
|
1739
|
+
const epId = strOf(op["episode_id"]);
|
|
1740
|
+
const sceneId = strOf(op["scene_id"]);
|
|
1741
|
+
const scene = findScene(script, epId, sceneId);
|
|
1742
|
+
const ctx = sceneContext(scene);
|
|
1743
|
+
if (kind === "set_scene_actor_ref") {
|
|
1744
|
+
const actorId = ensureRefId(script, "actor", op["actor_id"]);
|
|
1745
|
+
const stateId = strOf(op["state_id"]).trim() || null;
|
|
1746
|
+
if (!isList(ctx["actors"]))
|
|
1747
|
+
ctx["actors"] = [];
|
|
1748
|
+
const refs = ctx["actors"];
|
|
1749
|
+
const existing = refs.find((r) => r["actor_id"] === actorId);
|
|
1750
|
+
if (existing)
|
|
1751
|
+
existing["state_id"] = stateId;
|
|
1752
|
+
else
|
|
1753
|
+
refs.push({ actor_id: actorId, state_id: stateId });
|
|
1754
|
+
}
|
|
1755
|
+
else if (kind === "set_scene_location_ref") {
|
|
1756
|
+
const locationId = ensureRefId(script, "location", op["location_id"]);
|
|
1757
|
+
const stateId = strOf(op["state_id"]).trim() || null;
|
|
1758
|
+
ctx["locations"] = [{ location_id: locationId, state_id: stateId }];
|
|
1759
|
+
}
|
|
1760
|
+
else {
|
|
1761
|
+
const propId = ensureRefId(script, "prop", op["prop_id"]);
|
|
1762
|
+
const stateId = strOf(op["state_id"]).trim() || null;
|
|
1763
|
+
if (!isList(ctx["props"]))
|
|
1764
|
+
ctx["props"] = [];
|
|
1765
|
+
const refs = ctx["props"];
|
|
1766
|
+
const existing = refs.find((r) => r["prop_id"] === propId);
|
|
1767
|
+
if (existing)
|
|
1768
|
+
existing["state_id"] = stateId;
|
|
1769
|
+
else
|
|
1770
|
+
refs.push({ prop_id: propId, state_id: stateId });
|
|
1771
|
+
}
|
|
1772
|
+
setSceneContext(scene, ctx);
|
|
1773
|
+
applied.push(kind);
|
|
1774
|
+
}
|
|
1775
|
+
else if (kind === "set_action_actor") {
|
|
1776
|
+
const actorId = ensureRefId(script, "actor", op["actor_id"], { allowNone: Boolean(op["allow_null"]) });
|
|
1777
|
+
const actionIndex = op["action_index"];
|
|
1778
|
+
if (typeof actionIndex !== "number" || !Number.isInteger(actionIndex)) {
|
|
1779
|
+
throw opErr("PATCH BLOCKED: Action index invalid", "Action index invalid.", { required: ["action_index: integer"], received: [JSON.stringify(op)], nextSteps: ["Inspect episodes and fix the patch."] });
|
|
1780
|
+
}
|
|
1781
|
+
const action = findAction(script, strOf(op["episode_id"]), strOf(op["scene_id"]), actionIndex);
|
|
1782
|
+
if (actorId === null)
|
|
1783
|
+
delete action["actor_id"];
|
|
1784
|
+
else
|
|
1785
|
+
action["actor_id"] = actorId;
|
|
1786
|
+
applied.push(kind);
|
|
1787
|
+
}
|
|
1788
|
+
else if (kind === "set_action_content_from_span") {
|
|
1789
|
+
const epId = op["episode_id"];
|
|
1790
|
+
const sceneId = op["scene_id"];
|
|
1791
|
+
const actionIndex = op["action_index"];
|
|
1792
|
+
const start = op["start"];
|
|
1793
|
+
const end = op["end"];
|
|
1794
|
+
if (typeof actionIndex !== "number" || !Number.isInteger(actionIndex) ||
|
|
1795
|
+
typeof start !== "number" || !Number.isInteger(start) ||
|
|
1796
|
+
typeof end !== "number" || !Number.isInteger(end) ||
|
|
1797
|
+
start < 0 || end <= start || end > sourceText.length) {
|
|
1798
|
+
throw opErr("PATCH BLOCKED: Source span invalid", "Source span invalid.", { required: ["episode_id, scene_id, action_index, start, end"], received: [JSON.stringify(op)], nextSteps: ["Use a valid source.txt character span."] });
|
|
1799
|
+
}
|
|
1800
|
+
const action = findAction(script, strOf(epId), strOf(sceneId), actionIndex);
|
|
1801
|
+
action["content"] = sourceText.slice(start, end);
|
|
1802
|
+
applied.push(kind);
|
|
1803
|
+
}
|
|
1804
|
+
else if (kind === "merge_scenes") {
|
|
1805
|
+
const epId = strOf(op["episode_id"]);
|
|
1806
|
+
const keepId = strOf(op["keep_scene_id"]);
|
|
1807
|
+
const removeId = strOf(op["remove_scene_id"]);
|
|
1808
|
+
const ep = asList(script["episodes"]).find((e) => e["episode_id"] === epId);
|
|
1809
|
+
if (!ep) {
|
|
1810
|
+
throw opErr("PATCH BLOCKED: Episode not found", "Episode not found.", { required: ["existing episode_id"], received: [epId], nextSteps: ["Inspect episodes and fix the patch."] });
|
|
1811
|
+
}
|
|
1812
|
+
const scenes = asList(ep["scenes"]);
|
|
1813
|
+
const keep = scenes.find((s) => s["scene_id"] === keepId);
|
|
1814
|
+
const remove = scenes.find((s) => s["scene_id"] === removeId);
|
|
1815
|
+
if (!keep || !remove) {
|
|
1816
|
+
throw opErr("PATCH BLOCKED: Scene not found", "Scene not found.", { required: ["existing keep_scene_id and remove_scene_id"], received: [JSON.stringify(op)], nextSteps: ["Inspect episodes and fix the patch."] });
|
|
1817
|
+
}
|
|
1818
|
+
keep["actions"].push(...asList(remove["actions"]));
|
|
1819
|
+
const keepCtx = sceneContext(keep);
|
|
1820
|
+
const removeCtx = sceneContext(remove);
|
|
1821
|
+
for (const [field, idKey] of [["actors", "actor_id"], ["locations", "location_id"], ["props", "prop_id"]]) {
|
|
1822
|
+
const existingIds = new Set();
|
|
1823
|
+
for (const ref of asList(keepCtx[field]))
|
|
1824
|
+
existingIds.add(ref[idKey]);
|
|
1825
|
+
for (const ref of asList(removeCtx[field])) {
|
|
1826
|
+
if (!existingIds.has(ref[idKey])) {
|
|
1827
|
+
if (!isList(keepCtx[field]))
|
|
1828
|
+
keepCtx[field] = [];
|
|
1829
|
+
keepCtx[field].push(ref);
|
|
1830
|
+
}
|
|
1831
|
+
}
|
|
1832
|
+
}
|
|
1833
|
+
setSceneContext(keep, keepCtx);
|
|
1834
|
+
ep["scenes"] = scenes.filter((s) => s !== remove);
|
|
1835
|
+
applied.push(kind);
|
|
1836
|
+
}
|
|
1837
|
+
else if (kind === "split_scene") {
|
|
1838
|
+
const epId = strOf(op["episode_id"]);
|
|
1839
|
+
const sceneId = strOf(op["scene_id"]);
|
|
1840
|
+
const splitAt = op["action_index"];
|
|
1841
|
+
if (typeof splitAt !== "number" || !Number.isInteger(splitAt)) {
|
|
1842
|
+
throw opErr("PATCH BLOCKED: Split index invalid", "Split index invalid.", { required: ["action_index: integer between existing actions"], received: [JSON.stringify(op)], nextSteps: ["Inspect episode actions and fix the patch."] });
|
|
1843
|
+
}
|
|
1844
|
+
const ep = findEpisode(script, epId);
|
|
1845
|
+
const scenes = asList(ep["scenes"]);
|
|
1846
|
+
const index = scenes.findIndex((s) => s["scene_id"] === sceneId);
|
|
1847
|
+
if (index < 0) {
|
|
1848
|
+
throw opErr("PATCH BLOCKED: Scene not found", "Scene not found.", { required: ["existing scene_id"], received: [sceneId], nextSteps: ["Inspect episodes and fix the patch."] });
|
|
1849
|
+
}
|
|
1850
|
+
const scene = scenes[index];
|
|
1851
|
+
const actions = asList(scene["actions"]);
|
|
1852
|
+
if (splitAt <= 0 || splitAt >= actions.length) {
|
|
1853
|
+
throw opErr("PATCH BLOCKED: Split index invalid", "Split index invalid.", { required: ["0 < action_index < action count"], received: [`action_index: ${splitAt}, actions: ${actions.length}`], nextSteps: ["Choose an action boundary inside the scene."] });
|
|
1854
|
+
}
|
|
1855
|
+
const newSceneId = strOf(op["new_scene_id"]) || nextSceneId(script);
|
|
1856
|
+
if (sceneIdExists(script, newSceneId)) {
|
|
1857
|
+
throw opErr("PATCH BLOCKED: New scene id exists", "New scene id exists.", { required: ["unused new_scene_id"], received: [newSceneId], nextSteps: ["Choose an unused scene id or omit new_scene_id."] });
|
|
1858
|
+
}
|
|
1859
|
+
const ctx = sceneContext(scene);
|
|
1860
|
+
const newScene = {
|
|
1861
|
+
scene_id: newSceneId,
|
|
1862
|
+
environment: { ...(isDict(scene["environment"]) ? scene["environment"] : {}) },
|
|
1863
|
+
context: ctx,
|
|
1864
|
+
locations: [...asList(ctx["locations"])],
|
|
1865
|
+
actors: [...asList(ctx["actors"])],
|
|
1866
|
+
props: [...asList(ctx["props"])],
|
|
1867
|
+
actions: actions.slice(splitAt),
|
|
1868
|
+
};
|
|
1869
|
+
scene["actions"] = actions.slice(0, splitAt);
|
|
1870
|
+
scenes.splice(index + 1, 0, newScene);
|
|
1871
|
+
applied.push(kind);
|
|
1872
|
+
}
|
|
1873
|
+
else {
|
|
1874
|
+
throw opErr("PATCH BLOCKED: Unsupported operation", "Unsupported patch operation.", {
|
|
1875
|
+
required: [
|
|
1876
|
+
"supported op: set_worldview, set_actor_role_type, set_asset_description, set_action_type, rename_*, merge_*, set_asset_aliases, set_asset_states, set_scene_*_ref, set_action_actor, merge_scenes, split_scene, set_action_content_from_span",
|
|
1877
|
+
],
|
|
1878
|
+
received: [kind],
|
|
1879
|
+
nextSteps: ["Use a supported patch operation."],
|
|
1880
|
+
});
|
|
1881
|
+
}
|
|
1882
|
+
}
|
|
1883
|
+
renumberSceneIds(script);
|
|
1884
|
+
return applied;
|
|
1885
|
+
}
|
|
1886
|
+
//# sourceMappingURL=script-core.js.map
|