@lingjingai/scriptctl 0.49.16 → 0.51.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (525) hide show
  1. package/README.md +8 -2
  2. package/changes/0.50.0.md +63 -0
  3. package/changes/0.51.0.md +24 -0
  4. package/dist/cli/register-batch.d.ts +3 -0
  5. package/dist/cli/register-batch.js +28 -0
  6. package/dist/cli/register-batch.js.map +1 -0
  7. package/dist/cli/register-edits.d.ts +4 -0
  8. package/dist/cli/register-edits.js +226 -0
  9. package/dist/cli/register-edits.js.map +1 -0
  10. package/dist/cli/register-query.d.ts +4 -0
  11. package/dist/cli/register-query.js +93 -0
  12. package/dist/cli/register-query.js.map +1 -0
  13. package/dist/cli/register-tools.d.ts +3 -0
  14. package/dist/cli/register-tools.js +23 -0
  15. package/dist/cli/register-tools.js.map +1 -0
  16. package/dist/cli/register-workflows.d.ts +4 -0
  17. package/dist/cli/register-workflows.js +71 -0
  18. package/dist/cli/register-workflows.js.map +1 -0
  19. package/dist/cli/registry.d.ts +14 -0
  20. package/dist/cli/registry.js +65 -0
  21. package/dist/cli/registry.js.map +1 -0
  22. package/dist/cli.d.ts +3 -0
  23. package/dist/cli.js +146 -575
  24. package/dist/cli.js.map +1 -1
  25. package/dist/common.d.ts +12 -38
  26. package/dist/common.js +5 -11
  27. package/dist/common.js.map +1 -1
  28. package/dist/domain/authoring/apply.d.ts +1 -33
  29. package/dist/domain/authoring/apply.js +1 -783
  30. package/dist/domain/authoring/apply.js.map +1 -1
  31. package/dist/domain/authoring/export.d.ts +1 -7
  32. package/dist/domain/authoring/export.js +1 -84
  33. package/dist/domain/authoring/export.js.map +1 -1
  34. package/dist/domain/authoring/parser.d.ts +2 -3
  35. package/dist/domain/authoring/parser.js +2 -914
  36. package/dist/domain/authoring/parser.js.map +1 -1
  37. package/dist/domain/authoring/serializer.d.ts +1 -2
  38. package/dist/domain/authoring/serializer.js +1 -243
  39. package/dist/domain/authoring/serializer.js.map +1 -1
  40. package/dist/domain/authoring/shared/bracket.d.ts +4 -0
  41. package/dist/domain/authoring/shared/bracket.js +95 -0
  42. package/dist/domain/authoring/shared/bracket.js.map +1 -0
  43. package/dist/domain/authoring/shared/types.d.ts +12 -0
  44. package/dist/domain/authoring/shared/types.js +2 -0
  45. package/dist/domain/authoring/shared/types.js.map +1 -0
  46. package/dist/domain/authoring/types.d.ts +2 -87
  47. package/dist/domain/authoring/types.js +2 -1
  48. package/dist/domain/authoring/types.js.map +1 -1
  49. package/dist/domain/authoring/v3/apply.d.ts +33 -0
  50. package/dist/domain/authoring/v3/apply.js +784 -0
  51. package/dist/domain/authoring/v3/apply.js.map +1 -0
  52. package/dist/domain/authoring/v3/export.d.ts +7 -0
  53. package/dist/domain/authoring/v3/export.js +85 -0
  54. package/dist/domain/authoring/v3/export.js.map +1 -0
  55. package/dist/domain/authoring/v3/parser.d.ts +3 -0
  56. package/dist/domain/authoring/v3/parser.js +823 -0
  57. package/dist/domain/authoring/v3/parser.js.map +1 -0
  58. package/dist/domain/authoring/v3/serializer.d.ts +2 -0
  59. package/dist/domain/authoring/v3/serializer.js +244 -0
  60. package/dist/domain/authoring/v3/serializer.js.map +1 -0
  61. package/dist/domain/authoring/v3/types.d.ts +76 -0
  62. package/dist/domain/authoring/v3/types.js +2 -0
  63. package/dist/domain/authoring/v3/types.js.map +1 -0
  64. package/dist/domain/authoring/v4/apply.d.ts +40 -0
  65. package/dist/domain/authoring/v4/apply.js +451 -0
  66. package/dist/domain/authoring/v4/apply.js.map +1 -0
  67. package/dist/domain/authoring/v4/parser.d.ts +2 -0
  68. package/dist/domain/authoring/v4/parser.js +729 -0
  69. package/dist/domain/authoring/v4/parser.js.map +1 -0
  70. package/dist/domain/authoring/v4/serializer.d.ts +6 -0
  71. package/dist/domain/authoring/v4/serializer.js +280 -0
  72. package/dist/domain/authoring/v4/serializer.js.map +1 -0
  73. package/dist/domain/authoring/v4/types.d.ts +50 -0
  74. package/dist/domain/authoring/v4/types.js +2 -0
  75. package/dist/domain/authoring/v4/types.js.map +1 -0
  76. package/dist/domain/ingest/apply-plan.d.ts +1 -1
  77. package/dist/domain/ingest/assembler.d.ts +9 -0
  78. package/dist/domain/ingest/assembler.js +98 -36
  79. package/dist/domain/ingest/assembler.js.map +1 -1
  80. package/dist/domain/ingest/asset-audit.d.ts +50 -0
  81. package/dist/domain/ingest/asset-audit.js +196 -0
  82. package/dist/domain/ingest/asset-audit.js.map +1 -0
  83. package/dist/domain/ingest/production-validation.d.ts +5 -4
  84. package/dist/domain/ingest/production-validation.js +10 -25
  85. package/dist/domain/ingest/production-validation.js.map +1 -1
  86. package/dist/domain/ingest/records.d.ts +1 -1
  87. package/dist/domain/ingest/records.js +1 -1
  88. package/dist/domain/ingest/records.js.map +1 -1
  89. package/dist/domain/ingest/serial-context.d.ts +1 -1
  90. package/dist/domain/ingest/validation.d.ts +1 -11
  91. package/dist/domain/ingest/validation.js +1 -199
  92. package/dist/domain/ingest/validation.js.map +1 -1
  93. package/dist/domain/ingest/video-apply.js +68 -45
  94. package/dist/domain/ingest/video-apply.js.map +1 -1
  95. package/dist/domain/script/address.d.ts +1 -32
  96. package/dist/domain/script/address.js +1 -144
  97. package/dist/domain/script/address.js.map +1 -1
  98. package/dist/domain/script/dispatch.d.ts +14 -0
  99. package/dist/domain/script/dispatch.js +45 -0
  100. package/dist/domain/script/dispatch.js.map +1 -0
  101. package/dist/domain/script/lookups.d.ts +1 -33
  102. package/dist/domain/script/lookups.js +1 -316
  103. package/dist/domain/script/lookups.js.map +1 -1
  104. package/dist/domain/script/parse.d.ts +1 -3
  105. package/dist/domain/script/parse.js +1 -164
  106. package/dist/domain/script/parse.js.map +1 -1
  107. package/dist/domain/script/patch/apply.d.ts +1 -2
  108. package/dist/domain/script/patch/apply.js +1 -30
  109. package/dist/domain/script/patch/apply.js.map +1 -1
  110. package/dist/domain/script/patch/helpers.d.ts +1 -17
  111. package/dist/domain/script/patch/helpers.js +1 -210
  112. package/dist/domain/script/patch/helpers.js.map +1 -1
  113. package/dist/domain/script/patch/inline-speaker.d.ts +1 -2
  114. package/dist/domain/script/patch/inline-speaker.js +1 -49
  115. package/dist/domain/script/patch/inline-speaker.js.map +1 -1
  116. package/dist/domain/script/patch/ops-action.d.ts +1 -12
  117. package/dist/domain/script/patch/ops-action.js +1 -366
  118. package/dist/domain/script/patch/ops-action.js.map +1 -1
  119. package/dist/domain/script/patch/ops-asset.d.ts +1 -14
  120. package/dist/domain/script/patch/ops-asset.js +1 -364
  121. package/dist/domain/script/patch/ops-asset.js.map +1 -1
  122. package/dist/domain/script/patch/ops-dialogue.d.ts +1 -2
  123. package/dist/domain/script/patch/ops-dialogue.js +1 -25
  124. package/dist/domain/script/patch/ops-dialogue.js.map +1 -1
  125. package/dist/domain/script/patch/ops-extend.d.ts +1 -8
  126. package/dist/domain/script/patch/ops-extend.js +1 -110
  127. package/dist/domain/script/patch/ops-extend.js.map +1 -1
  128. package/dist/domain/script/patch/ops-meta.d.ts +1 -5
  129. package/dist/domain/script/patch/ops-meta.js +1 -81
  130. package/dist/domain/script/patch/ops-meta.js.map +1 -1
  131. package/dist/domain/script/patch/ops-scene.d.ts +1 -6
  132. package/dist/domain/script/patch/ops-scene.js +1 -350
  133. package/dist/domain/script/patch/ops-scene.js.map +1 -1
  134. package/dist/domain/script/patch/ops-state.d.ts +1 -8
  135. package/dist/domain/script/patch/ops-state.js +1 -164
  136. package/dist/domain/script/patch/ops-state.js.map +1 -1
  137. package/dist/domain/script/patch/registry.d.ts +1 -2
  138. package/dist/domain/script/patch/registry.js +1 -52
  139. package/dist/domain/script/patch/registry.js.map +1 -1
  140. package/dist/domain/script/patch/types.d.ts +1 -10
  141. package/dist/domain/script/patch/types.js +1 -1
  142. package/dist/domain/script/patch/types.js.map +1 -1
  143. package/dist/domain/script/refs.d.ts +1 -4
  144. package/dist/domain/script/refs.js +1 -63
  145. package/dist/domain/script/refs.js.map +1 -1
  146. package/dist/domain/script/scene-refs.d.ts +1 -3
  147. package/dist/domain/script/scene-refs.js +1 -34
  148. package/dist/domain/script/scene-refs.js.map +1 -1
  149. package/dist/domain/script/schema.d.ts +1 -6
  150. package/dist/domain/script/schema.js +1 -55
  151. package/dist/domain/script/schema.js.map +1 -1
  152. package/dist/domain/script/selector.d.ts +1 -45
  153. package/dist/domain/script/selector.js +1 -184
  154. package/dist/domain/script/selector.js.map +1 -1
  155. package/dist/domain/script/shared/regex.d.ts +2 -0
  156. package/dist/domain/script/shared/regex.js +7 -0
  157. package/dist/domain/script/shared/regex.js.map +1 -0
  158. package/dist/domain/script/shared/types.d.ts +18 -0
  159. package/dist/domain/script/shared/types.js +9 -0
  160. package/dist/domain/script/shared/types.js.map +1 -0
  161. package/dist/domain/script/shared/validation.d.ts +10 -0
  162. package/dist/domain/script/shared/validation.js +2 -0
  163. package/dist/domain/script/shared/validation.js.map +1 -0
  164. package/dist/domain/script/shared.js +4 -6
  165. package/dist/domain/script/shared.js.map +1 -1
  166. package/dist/domain/script/types.d.ts +1 -123
  167. package/dist/domain/script/types.js +1 -8
  168. package/dist/domain/script/types.js.map +1 -1
  169. package/dist/domain/script/v3/address.d.ts +32 -0
  170. package/dist/domain/script/v3/address.js +136 -0
  171. package/dist/domain/script/v3/address.js.map +1 -0
  172. package/dist/domain/script/v3/lookups.d.ts +33 -0
  173. package/dist/domain/script/v3/lookups.js +316 -0
  174. package/dist/domain/script/v3/lookups.js.map +1 -0
  175. package/dist/domain/script/v3/ordinal.d.ts +8 -0
  176. package/dist/domain/script/v3/ordinal.js +91 -0
  177. package/dist/domain/script/v3/ordinal.js.map +1 -0
  178. package/dist/domain/script/v3/parse.d.ts +3 -0
  179. package/dist/domain/script/v3/parse.js +164 -0
  180. package/dist/domain/script/v3/parse.js.map +1 -0
  181. package/dist/domain/script/v3/patch/apply.d.ts +2 -0
  182. package/dist/domain/script/v3/patch/apply.js +31 -0
  183. package/dist/domain/script/v3/patch/apply.js.map +1 -0
  184. package/dist/domain/script/v3/patch/helpers.d.ts +17 -0
  185. package/dist/domain/script/v3/patch/helpers.js +209 -0
  186. package/dist/domain/script/v3/patch/helpers.js.map +1 -0
  187. package/dist/domain/script/v3/patch/inline-speaker.d.ts +2 -0
  188. package/dist/domain/script/v3/patch/inline-speaker.js +50 -0
  189. package/dist/domain/script/v3/patch/inline-speaker.js.map +1 -0
  190. package/dist/domain/script/v3/patch/ops-action.d.ts +12 -0
  191. package/dist/domain/script/v3/patch/ops-action.js +367 -0
  192. package/dist/domain/script/v3/patch/ops-action.js.map +1 -0
  193. package/dist/domain/script/v3/patch/ops-asset.d.ts +14 -0
  194. package/dist/domain/script/v3/patch/ops-asset.js +365 -0
  195. package/dist/domain/script/v3/patch/ops-asset.js.map +1 -0
  196. package/dist/domain/script/v3/patch/ops-dialogue.d.ts +2 -0
  197. package/dist/domain/script/v3/patch/ops-dialogue.js +26 -0
  198. package/dist/domain/script/v3/patch/ops-dialogue.js.map +1 -0
  199. package/dist/domain/script/v3/patch/ops-extend.d.ts +8 -0
  200. package/dist/domain/script/v3/patch/ops-extend.js +111 -0
  201. package/dist/domain/script/v3/patch/ops-extend.js.map +1 -0
  202. package/dist/domain/script/v3/patch/ops-meta.d.ts +5 -0
  203. package/dist/domain/script/v3/patch/ops-meta.js +82 -0
  204. package/dist/domain/script/v3/patch/ops-meta.js.map +1 -0
  205. package/dist/domain/script/v3/patch/ops-scene.d.ts +6 -0
  206. package/dist/domain/script/v3/patch/ops-scene.js +351 -0
  207. package/dist/domain/script/v3/patch/ops-scene.js.map +1 -0
  208. package/dist/domain/script/v3/patch/ops-state.d.ts +8 -0
  209. package/dist/domain/script/v3/patch/ops-state.js +165 -0
  210. package/dist/domain/script/v3/patch/ops-state.js.map +1 -0
  211. package/dist/domain/script/v3/patch/registry.d.ts +2 -0
  212. package/dist/domain/script/v3/patch/registry.js +53 -0
  213. package/dist/domain/script/v3/patch/registry.js.map +1 -0
  214. package/dist/domain/script/v3/patch/types.d.ts +10 -0
  215. package/dist/domain/script/v3/patch/types.js +2 -0
  216. package/dist/domain/script/v3/patch/types.js.map +1 -0
  217. package/dist/domain/script/v3/refs.d.ts +4 -0
  218. package/dist/domain/script/v3/refs.js +64 -0
  219. package/dist/domain/script/v3/refs.js.map +1 -0
  220. package/dist/domain/script/v3/scene-refs.d.ts +3 -0
  221. package/dist/domain/script/v3/scene-refs.js +35 -0
  222. package/dist/domain/script/v3/scene-refs.js.map +1 -0
  223. package/dist/domain/script/v3/schema.d.ts +6 -0
  224. package/dist/domain/script/v3/schema.js +56 -0
  225. package/dist/domain/script/v3/schema.js.map +1 -0
  226. package/dist/domain/script/v3/selector.d.ts +44 -0
  227. package/dist/domain/script/v3/selector.js +178 -0
  228. package/dist/domain/script/v3/selector.js.map +1 -0
  229. package/dist/domain/script/v3/types.d.ts +106 -0
  230. package/dist/domain/script/v3/types.js +2 -0
  231. package/dist/domain/script/v3/types.js.map +1 -0
  232. package/dist/domain/script/v3/validation.d.ts +3 -0
  233. package/dist/domain/script/v3/validation.js +200 -0
  234. package/dist/domain/script/v3/validation.js.map +1 -0
  235. package/dist/domain/script/v4/address.d.ts +61 -0
  236. package/dist/domain/script/v4/address.js +99 -0
  237. package/dist/domain/script/v4/address.js.map +1 -0
  238. package/dist/domain/script/v4/factory.d.ts +2 -0
  239. package/dist/domain/script/v4/factory.js +13 -0
  240. package/dist/domain/script/v4/factory.js.map +1 -0
  241. package/dist/domain/script/v4/from-v3.d.ts +29 -0
  242. package/dist/domain/script/v4/from-v3.js +307 -0
  243. package/dist/domain/script/v4/from-v3.js.map +1 -0
  244. package/dist/domain/script/v4/ids.d.ts +27 -0
  245. package/dist/domain/script/v4/ids.js +62 -0
  246. package/dist/domain/script/v4/ids.js.map +1 -0
  247. package/dist/domain/script/v4/ordinal.d.ts +3 -0
  248. package/dist/domain/script/v4/ordinal.js +66 -0
  249. package/dist/domain/script/v4/ordinal.js.map +1 -0
  250. package/dist/domain/script/v4/parse.d.ts +3 -0
  251. package/dist/domain/script/v4/parse.js +17 -0
  252. package/dist/domain/script/v4/parse.js.map +1 -0
  253. package/dist/domain/script/v4/patch/apply.d.ts +3 -0
  254. package/dist/domain/script/v4/patch/apply.js +24 -0
  255. package/dist/domain/script/v4/patch/apply.js.map +1 -0
  256. package/dist/domain/script/v4/patch/helpers.d.ts +32 -0
  257. package/dist/domain/script/v4/patch/helpers.js +138 -0
  258. package/dist/domain/script/v4/patch/helpers.js.map +1 -0
  259. package/dist/domain/script/v4/patch/ops-action.d.ts +13 -0
  260. package/dist/domain/script/v4/patch/ops-action.js +376 -0
  261. package/dist/domain/script/v4/patch/ops-action.js.map +1 -0
  262. package/dist/domain/script/v4/patch/ops-asset.d.ts +17 -0
  263. package/dist/domain/script/v4/patch/ops-asset.js +617 -0
  264. package/dist/domain/script/v4/patch/ops-asset.js.map +1 -0
  265. package/dist/domain/script/v4/patch/ops-extend.d.ts +11 -0
  266. package/dist/domain/script/v4/patch/ops-extend.js +86 -0
  267. package/dist/domain/script/v4/patch/ops-extend.js.map +1 -0
  268. package/dist/domain/script/v4/patch/ops-meta.d.ts +5 -0
  269. package/dist/domain/script/v4/patch/ops-meta.js +49 -0
  270. package/dist/domain/script/v4/patch/ops-meta.js.map +1 -0
  271. package/dist/domain/script/v4/patch/ops-scene-ref.d.ts +3 -0
  272. package/dist/domain/script/v4/patch/ops-scene-ref.js +98 -0
  273. package/dist/domain/script/v4/patch/ops-scene-ref.js.map +1 -0
  274. package/dist/domain/script/v4/patch/ops-structure.d.ts +6 -0
  275. package/dist/domain/script/v4/patch/ops-structure.js +236 -0
  276. package/dist/domain/script/v4/patch/ops-structure.js.map +1 -0
  277. package/dist/domain/script/v4/patch/registry.d.ts +2 -0
  278. package/dist/domain/script/v4/patch/registry.js +50 -0
  279. package/dist/domain/script/v4/patch/registry.js.map +1 -0
  280. package/dist/domain/script/v4/patch/schema.d.ts +7 -0
  281. package/dist/domain/script/v4/patch/schema.js +75 -0
  282. package/dist/domain/script/v4/patch/schema.js.map +1 -0
  283. package/dist/domain/script/v4/patch/types.d.ts +10 -0
  284. package/dist/domain/script/v4/patch/types.js +2 -0
  285. package/dist/domain/script/v4/patch/types.js.map +1 -0
  286. package/dist/domain/script/v4/selector.d.ts +11 -0
  287. package/dist/domain/script/v4/selector.js +124 -0
  288. package/dist/domain/script/v4/selector.js.map +1 -0
  289. package/dist/domain/script/v4/types.d.ts +120 -0
  290. package/dist/domain/script/v4/types.js +2 -0
  291. package/dist/domain/script/v4/types.js.map +1 -0
  292. package/dist/domain/script/v4/validation.d.ts +2 -0
  293. package/dist/domain/script/v4/validation.js +378 -0
  294. package/dist/domain/script/v4/validation.js.map +1 -0
  295. package/dist/infra/ingest/video-discovery.js +7 -4
  296. package/dist/infra/ingest/video-discovery.js.map +1 -1
  297. package/dist/infra/script-output-store.js +6 -11
  298. package/dist/infra/script-output-store.js.map +1 -1
  299. package/dist/infra/script-working-copy.js +15 -16
  300. package/dist/infra/script-working-copy.js.map +1 -1
  301. package/dist/llm/config.js +5 -4
  302. package/dist/llm/config.js.map +1 -1
  303. package/dist/llm/registry.d.ts +1 -0
  304. package/dist/llm/registry.js +3 -0
  305. package/dist/llm/registry.js.map +1 -1
  306. package/dist/llm/router.js +6 -8
  307. package/dist/llm/router.js.map +1 -1
  308. package/dist/llm/tasks/ingest/asset-audit.d.ts +6 -0
  309. package/dist/llm/tasks/ingest/asset-audit.js +164 -0
  310. package/dist/llm/tasks/ingest/asset-audit.js.map +1 -0
  311. package/dist/llm/tasks/ingest/asset-curate.d.ts +1 -1
  312. package/dist/llm/tasks/ingest/text-normalize.js +3 -3
  313. package/dist/llm/tasks/ingest/text-normalize.js.map +1 -1
  314. package/dist/llm/tasks/ingest/video-serial.js +3 -3
  315. package/dist/llm/tasks/ingest/video-serial.js.map +1 -1
  316. package/dist/llm/types.d.ts +1 -1
  317. package/dist/llm/types.js.map +1 -1
  318. package/dist/output.d.ts +2 -3
  319. package/dist/output.js +72 -109
  320. package/dist/output.js.map +1 -1
  321. package/dist/usecases/changelog.d.ts +2 -2
  322. package/dist/usecases/changelog.js +28 -36
  323. package/dist/usecases/changelog.js.map +1 -1
  324. package/dist/usecases/doctor.d.ts +2 -2
  325. package/dist/usecases/doctor.js +3 -5
  326. package/dist/usecases/doctor.js.map +1 -1
  327. package/dist/usecases/ingest/command.d.ts +2 -2
  328. package/dist/usecases/ingest/command.js +23 -6
  329. package/dist/usecases/ingest/command.js.map +1 -1
  330. package/dist/usecases/ingest/final-asset-audit.d.ts +39 -0
  331. package/dist/usecases/ingest/final-asset-audit.js +88 -0
  332. package/dist/usecases/ingest/final-asset-audit.js.map +1 -0
  333. package/dist/usecases/ingest/pass5-extract.js +5 -4
  334. package/dist/usecases/ingest/pass5-extract.js.map +1 -1
  335. package/dist/usecases/ingest/pass5-govern.js +13 -11
  336. package/dist/usecases/ingest/pass5-govern.js.map +1 -1
  337. package/dist/usecases/ingest/pipeline.js +77 -23
  338. package/dist/usecases/ingest/pipeline.js.map +1 -1
  339. package/dist/usecases/ingest/serial-govern.d.ts +2 -1
  340. package/dist/usecases/ingest/serial-govern.js +16 -8
  341. package/dist/usecases/ingest/serial-govern.js.map +1 -1
  342. package/dist/usecases/ingest/status.d.ts +2 -2
  343. package/dist/usecases/ingest/status.js +1 -1
  344. package/dist/usecases/ingest/status.js.map +1 -1
  345. package/dist/usecases/ingest/video-pipeline.js +121 -29
  346. package/dist/usecases/ingest/video-pipeline.js.map +1 -1
  347. package/dist/usecases/ingest/view-command.d.ts +2 -2
  348. package/dist/usecases/ingest/view-command.js +7 -6
  349. package/dist/usecases/ingest/view-command.js.map +1 -1
  350. package/dist/usecases/ingest/view-server.d.ts +2 -2
  351. package/dist/usecases/ingest/view-server.js +9 -7
  352. package/dist/usecases/ingest/view-server.js.map +1 -1
  353. package/dist/usecases/script/actions.d.ts +2 -2
  354. package/dist/usecases/script/actions.js +106 -11
  355. package/dist/usecases/script/actions.js.map +1 -1
  356. package/dist/usecases/script/actor.d.ts +2 -2
  357. package/dist/usecases/script/actor.js +3 -4
  358. package/dist/usecases/script/actor.js.map +1 -1
  359. package/dist/usecases/script/actors.d.ts +2 -2
  360. package/dist/usecases/script/actors.js +18 -9
  361. package/dist/usecases/script/actors.js.map +1 -1
  362. package/dist/usecases/script/add-actor.d.ts +2 -2
  363. package/dist/usecases/script/add-episode.d.ts +2 -2
  364. package/dist/usecases/script/add-location.d.ts +2 -2
  365. package/dist/usecases/script/add-prop.d.ts +2 -2
  366. package/dist/usecases/script/alias.d.ts +2 -2
  367. package/dist/usecases/script/alias.js +13 -14
  368. package/dist/usecases/script/alias.js.map +1 -1
  369. package/dist/usecases/script/assets.d.ts +2 -2
  370. package/dist/usecases/script/assets.js +29 -5
  371. package/dist/usecases/script/assets.js.map +1 -1
  372. package/dist/usecases/script/audit-assets.d.ts +4 -0
  373. package/dist/usecases/script/audit-assets.js +37 -0
  374. package/dist/usecases/script/audit-assets.js.map +1 -0
  375. package/dist/usecases/script/command-constraints.d.ts +36 -0
  376. package/dist/usecases/script/command-constraints.js +114 -0
  377. package/dist/usecases/script/command-constraints.js.map +1 -0
  378. package/dist/usecases/script/context.d.ts +2 -2
  379. package/dist/usecases/script/context.js +34 -8
  380. package/dist/usecases/script/context.js.map +1 -1
  381. package/dist/usecases/script/create.d.ts +2 -2
  382. package/dist/usecases/script/create.js +5 -6
  383. package/dist/usecases/script/create.js.map +1 -1
  384. package/dist/usecases/script/delete.d.ts +2 -2
  385. package/dist/usecases/script/delete.js +15 -15
  386. package/dist/usecases/script/delete.js.map +1 -1
  387. package/dist/usecases/script/describe.d.ts +2 -2
  388. package/dist/usecases/script/describe.js +13 -12
  389. package/dist/usecases/script/describe.js.map +1 -1
  390. package/dist/usecases/script/dialogue.d.ts +2 -2
  391. package/dist/usecases/script/dialogue.js +18 -9
  392. package/dist/usecases/script/dialogue.js.map +1 -1
  393. package/dist/usecases/script/dispatch.d.ts +3 -0
  394. package/dist/usecases/script/dispatch.js +10 -0
  395. package/dist/usecases/script/dispatch.js.map +1 -0
  396. package/dist/usecases/script/do.d.ts +2 -2
  397. package/dist/usecases/script/do.js +105 -45
  398. package/dist/usecases/script/do.js.map +1 -1
  399. package/dist/usecases/script/emotion.d.ts +2 -2
  400. package/dist/usecases/script/emotion.js +14 -3
  401. package/dist/usecases/script/emotion.js.map +1 -1
  402. package/dist/usecases/script/episodes.d.ts +2 -2
  403. package/dist/usecases/script/episodes.js +19 -8
  404. package/dist/usecases/script/episodes.js.map +1 -1
  405. package/dist/usecases/script/export-authoring.d.ts +2 -2
  406. package/dist/usecases/script/export-authoring.js +47 -26
  407. package/dist/usecases/script/export-authoring.js.map +1 -1
  408. package/dist/usecases/script/extend.d.ts +2 -2
  409. package/dist/usecases/script/extend.js +43 -31
  410. package/dist/usecases/script/extend.js.map +1 -1
  411. package/dist/usecases/script/ids.d.ts +2 -2
  412. package/dist/usecases/script/ids.js +68 -21
  413. package/dist/usecases/script/ids.js.map +1 -1
  414. package/dist/usecases/script/importance.d.ts +2 -2
  415. package/dist/usecases/script/importance.js +3 -4
  416. package/dist/usecases/script/importance.js.map +1 -1
  417. package/dist/usecases/script/insert.d.ts +2 -2
  418. package/dist/usecases/script/insert.js +80 -46
  419. package/dist/usecases/script/insert.js.map +1 -1
  420. package/dist/usecases/script/issues.d.ts +2 -2
  421. package/dist/usecases/script/issues.js +10 -2
  422. package/dist/usecases/script/issues.js.map +1 -1
  423. package/dist/usecases/script/lib.d.ts +62 -7
  424. package/dist/usecases/script/lib.js +782 -184
  425. package/dist/usecases/script/lib.js.map +1 -1
  426. package/dist/usecases/script/locations.d.ts +2 -2
  427. package/dist/usecases/script/locations.js +18 -9
  428. package/dist/usecases/script/locations.js.map +1 -1
  429. package/dist/usecases/script/merge.d.ts +2 -2
  430. package/dist/usecases/script/merge.js +17 -17
  431. package/dist/usecases/script/merge.js.map +1 -1
  432. package/dist/usecases/script/move.d.ts +2 -2
  433. package/dist/usecases/script/move.js +30 -13
  434. package/dist/usecases/script/move.js.map +1 -1
  435. package/dist/usecases/script/parenthetical.d.ts +3 -0
  436. package/dist/usecases/script/parenthetical.js +52 -0
  437. package/dist/usecases/script/parenthetical.js.map +1 -0
  438. package/dist/usecases/script/props.d.ts +2 -2
  439. package/dist/usecases/script/props.js +18 -9
  440. package/dist/usecases/script/props.js.map +1 -1
  441. package/dist/usecases/script/refs.d.ts +2 -2
  442. package/dist/usecases/script/refs.js +61 -11
  443. package/dist/usecases/script/refs.js.map +1 -1
  444. package/dist/usecases/script/rename.d.ts +2 -2
  445. package/dist/usecases/script/rename.js +13 -12
  446. package/dist/usecases/script/rename.js.map +1 -1
  447. package/dist/usecases/script/replace.d.ts +2 -2
  448. package/dist/usecases/script/replace.js +6 -8
  449. package/dist/usecases/script/replace.js.map +1 -1
  450. package/dist/usecases/script/role.d.ts +2 -2
  451. package/dist/usecases/script/role.js +3 -4
  452. package/dist/usecases/script/role.js.map +1 -1
  453. package/dist/usecases/script/scenes.d.ts +2 -2
  454. package/dist/usecases/script/scenes.js +35 -7
  455. package/dist/usecases/script/scenes.js.map +1 -1
  456. package/dist/usecases/script/script-patch.d.ts +2 -2
  457. package/dist/usecases/script/script-patch.js +219 -72
  458. package/dist/usecases/script/script-patch.js.map +1 -1
  459. package/dist/usecases/script/script-validate.d.ts +2 -2
  460. package/dist/usecases/script/script-validate.js +11 -7
  461. package/dist/usecases/script/script-validate.js.map +1 -1
  462. package/dist/usecases/script/session.d.ts +3 -0
  463. package/dist/usecases/script/session.js +74 -65
  464. package/dist/usecases/script/session.js.map +1 -1
  465. package/dist/usecases/script/split.d.ts +2 -2
  466. package/dist/usecases/script/split.js +18 -14
  467. package/dist/usecases/script/split.js.map +1 -1
  468. package/dist/usecases/script/state-add.d.ts +2 -2
  469. package/dist/usecases/script/state-add.js +3 -4
  470. package/dist/usecases/script/state-add.js.map +1 -1
  471. package/dist/usecases/script/state-delete.d.ts +2 -2
  472. package/dist/usecases/script/state-delete.js +3 -4
  473. package/dist/usecases/script/state-delete.js.map +1 -1
  474. package/dist/usecases/script/state-rename.d.ts +2 -2
  475. package/dist/usecases/script/state-rename.js +3 -4
  476. package/dist/usecases/script/state-rename.js.map +1 -1
  477. package/dist/usecases/script/states.d.ts +2 -2
  478. package/dist/usecases/script/states.js +91 -20
  479. package/dist/usecases/script/states.js.map +1 -1
  480. package/dist/usecases/script/summary.d.ts +2 -2
  481. package/dist/usecases/script/summary.js +21 -2
  482. package/dist/usecases/script/summary.js.map +1 -1
  483. package/dist/usecases/script/synopsis-generate.d.ts +2 -2
  484. package/dist/usecases/script/synopsis-generate.js +38 -39
  485. package/dist/usecases/script/synopsis-generate.js.map +1 -1
  486. package/dist/usecases/script/synopsis.d.ts +2 -2
  487. package/dist/usecases/script/synopsis.js +20 -16
  488. package/dist/usecases/script/synopsis.js.map +1 -1
  489. package/dist/usecases/script/transition.d.ts +2 -2
  490. package/dist/usecases/script/transition.js +3 -4
  491. package/dist/usecases/script/transition.js.map +1 -1
  492. package/dist/usecases/script/type.d.ts +2 -2
  493. package/dist/usecases/script/type.js +3 -4
  494. package/dist/usecases/script/type.js.map +1 -1
  495. package/dist/usecases/script/v3/mutations.d.ts +2 -0
  496. package/dist/usecases/script/v3/mutations.js +5 -0
  497. package/dist/usecases/script/v3/mutations.js.map +1 -0
  498. package/dist/usecases/script/v4/mutations.d.ts +2 -0
  499. package/dist/usecases/script/v4/mutations.js +6 -0
  500. package/dist/usecases/script/v4/mutations.js.map +1 -0
  501. package/dist/usecases/script/v4/queries.d.ts +15 -0
  502. package/dist/usecases/script/v4/queries.js +191 -0
  503. package/dist/usecases/script/v4/queries.js.map +1 -0
  504. package/dist/usecases/script/working-copy.d.ts +4 -4
  505. package/dist/usecases/script/working-copy.js +98 -94
  506. package/dist/usecases/script/working-copy.js.map +1 -1
  507. package/dist/usecases/script/worldview.d.ts +2 -2
  508. package/dist/usecases/script/worldview.js +3 -4
  509. package/dist/usecases/script/worldview.js.map +1 -1
  510. package/dist/usecases/script/write-authoring.d.ts +2 -2
  511. package/dist/usecases/script/write-authoring.js +125 -50
  512. package/dist/usecases/script/write-authoring.js.map +1 -1
  513. package/dist/usecases/update.d.ts +2 -2
  514. package/dist/usecases/update.js +32 -47
  515. package/dist/usecases/update.js.map +1 -1
  516. package/package.json +3 -2
  517. package/skills/scriptctl/SKILL.md +128 -282
  518. package/skills/scriptctl/references/atomic-edit-workflow.md +23 -38
  519. package/skills/scriptctl/references/bulk-authoring.md +35 -154
  520. package/skills/scriptctl/references/ingest-workflow.md +12 -11
  521. package/skills/scriptctl/references/production-writing-standard.md +38 -67
  522. package/skills/scriptctl/references/state-reference-repair.md +19 -42
  523. package/dist/help-text.d.ts +0 -2
  524. package/dist/help-text.js +0 -1112
  525. package/dist/help-text.js.map +0 -1
@@ -0,0 +1,729 @@
1
+ import { CliError, EXIT_INPUT } from "../../../common.js";
2
+ import { parseBracketRecord } from "../shared/bracket.js";
3
+ import { isV4Id } from "../../script/v4/ids.js";
4
+ function invalid(message, line, received) {
5
+ throw new CliError(message, {
6
+ exitCode: EXIT_INPUT,
7
+ errorCode: "AUTHORING_SOURCE_INVALID",
8
+ data: { actual: [`line ${line}: ${received}`] },
9
+ });
10
+ }
11
+ function parseTag(raw, line) {
12
+ const text = raw.trim();
13
+ const close = /^<\/([a-z-]+)>$/.exec(text);
14
+ if (close)
15
+ return { name: close[1], closing: true, attrs: new Map(), line };
16
+ const open = /^<([a-z-]+)(?: ([^>]+))?>$/.exec(text);
17
+ if (!open)
18
+ return null;
19
+ const attrs = new Map();
20
+ const attrText = open[2] ?? "";
21
+ const tokens = attrText === "" ? [] : attrText.split(" ");
22
+ if (tokens.some((token) => token === ""))
23
+ invalid("Tag attributes need one-space separators.", line, text);
24
+ for (const token of tokens) {
25
+ const match = /^([a-z]+)=([A-Za-z0-9_./#:-]+)$/.exec(token);
26
+ if (!match || attrs.has(match[1]))
27
+ invalid("Tag attributes are invalid.", line, token);
28
+ attrs.set(match[1], match[2]);
29
+ }
30
+ return { name: open[1], closing: false, attrs, line };
31
+ }
32
+ function assertAttrs(tag, required, optional = []) {
33
+ const allowed = new Set([...required, ...optional]);
34
+ const unknown = [...tag.attrs.keys()].filter((key) => !allowed.has(key));
35
+ const missing = required.filter((key) => !tag.attrs.has(key));
36
+ if (unknown.length > 0 || missing.length > 0) {
37
+ invalid("Tag attributes do not match the canonical grammar.", tag.line, [
38
+ ...missing.map((key) => `missing:${key}`),
39
+ ...unknown.map((key) => `unknown:${key}`),
40
+ ].join(","));
41
+ }
42
+ }
43
+ class Cursor {
44
+ lines;
45
+ index = 0;
46
+ constructor(text) {
47
+ this.lines = text.split(/\r?\n/)
48
+ .map((raw, index) => ({
49
+ raw: raw.replace(/^\s+/, ""),
50
+ line: index + 1,
51
+ }))
52
+ .filter((item) => item.raw.trim() !== "");
53
+ }
54
+ peek() {
55
+ const item = this.lines[this.index];
56
+ if (!item)
57
+ invalid("Unexpected end of authoring file.", this.lines.at(-1)?.line ?? 1, "<eof>");
58
+ return item;
59
+ }
60
+ take() {
61
+ const item = this.peek();
62
+ this.index++;
63
+ return item;
64
+ }
65
+ tag(name, closing) {
66
+ const item = this.take();
67
+ const tag = parseTag(item.raw, item.line);
68
+ if (!tag || tag.name !== name || tag.closing !== closing) {
69
+ invalid(`Expected ${closing ? "</" : "<"}${name}>.`, item.line, item.raw);
70
+ }
71
+ return tag;
72
+ }
73
+ record() {
74
+ const item = this.take();
75
+ return parseBracketRecord(item.raw, item.line);
76
+ }
77
+ nextTag() {
78
+ const item = this.peek();
79
+ return parseTag(item.raw, item.line);
80
+ }
81
+ nextRecord() {
82
+ const item = this.peek();
83
+ return item.raw.startsWith("[") ? parseBracketRecord(item.raw, item.line) : null;
84
+ }
85
+ }
86
+ function jsonValue(value) {
87
+ if (value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean")
88
+ return true;
89
+ if (Array.isArray(value))
90
+ return value.every(jsonValue);
91
+ return typeof value === "object" && Object.values(value).every(jsonValue);
92
+ }
93
+ function modifiers(cursor) {
94
+ const result = {};
95
+ let next = cursor.nextRecord();
96
+ if (next?.type === "extensions") {
97
+ cursor.record();
98
+ const extend = {};
99
+ let previousKey = null;
100
+ while ((next = cursor.nextRecord())?.type === "extend") {
101
+ const record = cursor.record();
102
+ if (record.slots.length !== 1 || Object.hasOwn(extend, record.slots[0])) {
103
+ invalid("extend record is invalid or duplicated.", record.source.line, record.type);
104
+ }
105
+ const key = record.slots[0];
106
+ if (previousKey !== null && previousKey >= key) {
107
+ invalid("extend keys must use ascending canonical order.", record.source.line, key);
108
+ }
109
+ let value;
110
+ try {
111
+ value = JSON.parse(record.content);
112
+ }
113
+ catch {
114
+ invalid("extend content must be JSON.", record.source.line, record.content);
115
+ }
116
+ if (!jsonValue(value))
117
+ invalid("extend value must be JSON-compatible.", record.source.line, record.content);
118
+ extend[key] = value;
119
+ previousKey = key;
120
+ }
121
+ result.extend = extend;
122
+ }
123
+ next = cursor.nextRecord();
124
+ if (next?.type === "aliases") {
125
+ cursor.record();
126
+ const aliases = [];
127
+ while ((next = cursor.nextRecord())?.type === "alias") {
128
+ const record = cursor.record();
129
+ if (record.slots.length !== 0)
130
+ invalid("alias takes no slots.", record.source.line, record.type);
131
+ if (record.content === "")
132
+ invalid("alias must not be empty.", record.source.line, record.type);
133
+ if (aliases.includes(record.content))
134
+ invalid("alias must not be duplicated.", record.source.line, record.content);
135
+ aliases.push(record.content);
136
+ }
137
+ result.aliases = aliases;
138
+ }
139
+ next = cursor.nextRecord();
140
+ if (next?.type === "prompt") {
141
+ const record = cursor.record();
142
+ if (record.slots.length !== 3 || record.slots.some((slot) => slot === "")) {
143
+ invalid("prompt requires non-empty target, process, and contrast.", record.source.line, record.type);
144
+ }
145
+ const target = record.slots[0];
146
+ if (!isV4Id("actor", target) && !isV4Id("location", target) && !isV4Id("prop", target)) {
147
+ invalid("prompt target must be an asset ID.", record.source.line, target);
148
+ }
149
+ result.prompt = {
150
+ target,
151
+ process: record.slots[1],
152
+ contrast: record.slots[2],
153
+ };
154
+ }
155
+ return result;
156
+ }
157
+ function importance(raw, line) {
158
+ if (raw !== "featured" && raw !== "background")
159
+ invalid("Importance is invalid.", line, raw);
160
+ return raw;
161
+ }
162
+ function role(raw, line) {
163
+ if (raw === undefined)
164
+ return undefined;
165
+ if (raw !== "主角" && raw !== "配角")
166
+ invalid("Role type is invalid.", line, raw);
167
+ return raw;
168
+ }
169
+ function stateId(raw, line) {
170
+ if (raw === "default" || isV4Id("state", raw))
171
+ return raw;
172
+ return invalid("State ID is invalid.", line, raw);
173
+ }
174
+ function parseCreate(cursor) {
175
+ const opening = cursor.tag("create", false);
176
+ assertAttrs(opening, []);
177
+ const declarations = [];
178
+ const declaredAssets = new Map();
179
+ let activeNewAssetId = null;
180
+ let declarationPhase = 0;
181
+ const finishActiveAsset = (line) => {
182
+ if (activeNewAssetId === null)
183
+ return;
184
+ const asset = declaredAssets.get(activeNewAssetId);
185
+ if (!asset || asset.states.length === 0 || asset.states[0].state_id !== "default") {
186
+ invalid("A new asset must be followed immediately by its default state.", line, activeNewAssetId);
187
+ }
188
+ activeNewAssetId = null;
189
+ };
190
+ while (cursor.nextTag()?.name !== "create" || cursor.nextTag()?.closing !== true) {
191
+ const mod = modifiers(cursor);
192
+ const record = cursor.record();
193
+ if (record.type === "actor") {
194
+ if (declarationPhase > 0)
195
+ invalid("Create declarations are not in canonical order.", record.source.line, record.type);
196
+ finishActiveAsset(record.source.line);
197
+ if (mod.prompt !== undefined)
198
+ invalid("prompt cannot modify an asset.", record.source.line, record.type);
199
+ if (record.slots.length < 3 || record.slots.length > 4 || !isV4Id("actor", record.slots[0])) {
200
+ invalid("actor declaration is invalid.", record.source.line, record.type);
201
+ }
202
+ const roleType = role(record.slots[3], record.source.line);
203
+ const value = {
204
+ actor_id: record.slots[0],
205
+ actor_name: record.slots[1],
206
+ importance: importance(record.slots[2], record.source.line),
207
+ description: record.content,
208
+ states: [],
209
+ ...(roleType === undefined ? {} : { role_type: roleType }),
210
+ ...(mod.aliases === undefined ? {} : { aliases: mod.aliases }),
211
+ ...(mod.extend === undefined ? {} : { extend: mod.extend }),
212
+ };
213
+ if (value.aliases?.includes(value.actor_name)) {
214
+ invalid("An alias must differ from the asset name.", record.source.line, value.actor_name);
215
+ }
216
+ declarations.push({ kind: "actor", value });
217
+ declaredAssets.set(value.actor_id, value);
218
+ activeNewAssetId = value.actor_id;
219
+ }
220
+ else if (record.type === "location" || record.type === "prop") {
221
+ const nextPhase = record.type === "location" ? 1 : 2;
222
+ if (nextPhase < declarationPhase) {
223
+ invalid("Create declarations are not in canonical order.", record.source.line, record.type);
224
+ }
225
+ declarationPhase = nextPhase;
226
+ finishActiveAsset(record.source.line);
227
+ if (mod.prompt !== undefined)
228
+ invalid("prompt cannot modify an asset.", record.source.line, record.type);
229
+ const kind = record.type;
230
+ if (record.slots.length !== 3
231
+ || (kind === "location"
232
+ ? !isV4Id("location", record.slots[0])
233
+ : !isV4Id("prop", record.slots[0]))) {
234
+ invalid(`${kind} declaration is invalid.`, record.source.line, record.type);
235
+ }
236
+ if (kind === "location") {
237
+ const locationId = record.slots[0];
238
+ if (!isV4Id("location", locationId))
239
+ invalid("location ID is invalid.", record.source.line, locationId);
240
+ const value = {
241
+ location_id: locationId,
242
+ location_name: record.slots[1],
243
+ importance: importance(record.slots[2], record.source.line),
244
+ description: record.content,
245
+ states: [],
246
+ ...(mod.aliases === undefined ? {} : { aliases: mod.aliases }),
247
+ ...(mod.extend === undefined ? {} : { extend: mod.extend }),
248
+ };
249
+ if (value.aliases?.includes(value.location_name)) {
250
+ invalid("An alias must differ from the asset name.", record.source.line, value.location_name);
251
+ }
252
+ declarations.push({ kind, value });
253
+ declaredAssets.set(value.location_id, value);
254
+ activeNewAssetId = value.location_id;
255
+ }
256
+ else {
257
+ const propId = record.slots[0];
258
+ if (!isV4Id("prop", propId))
259
+ invalid("prop ID is invalid.", record.source.line, propId);
260
+ const value = {
261
+ prop_id: propId,
262
+ prop_name: record.slots[1],
263
+ importance: importance(record.slots[2], record.source.line),
264
+ description: record.content,
265
+ states: [],
266
+ ...(mod.aliases === undefined ? {} : { aliases: mod.aliases }),
267
+ ...(mod.extend === undefined ? {} : { extend: mod.extend }),
268
+ };
269
+ if (value.aliases?.includes(value.prop_name)) {
270
+ invalid("An alias must differ from the asset name.", record.source.line, value.prop_name);
271
+ }
272
+ declarations.push({ kind, value });
273
+ declaredAssets.set(value.prop_id, value);
274
+ activeNewAssetId = value.prop_id;
275
+ }
276
+ }
277
+ else if (record.type === "state") {
278
+ if (record.slots.length !== 3 || mod.aliases !== undefined || mod.prompt !== undefined) {
279
+ invalid("state declaration is invalid.", record.source.line, record.type);
280
+ }
281
+ const ownerId = record.slots[0];
282
+ const owner = declaredAssets.get(ownerId);
283
+ if (owner && activeNewAssetId !== ownerId) {
284
+ invalid("States for a new asset must immediately follow that asset.", record.source.line, ownerId);
285
+ }
286
+ if (!owner) {
287
+ finishActiveAsset(record.source.line);
288
+ declarationPhase = 3;
289
+ }
290
+ const value = {
291
+ state_id: stateId(record.slots[1], record.source.line),
292
+ state_name: record.slots[2],
293
+ description: record.content,
294
+ ...(mod.extend === undefined ? {} : { extend: mod.extend }),
295
+ };
296
+ if (owner) {
297
+ if (owner.states.length === 0 && value.state_id !== "default") {
298
+ invalid("The first state of a new asset must be default.", record.source.line, value.state_id);
299
+ }
300
+ owner.states.push(value);
301
+ }
302
+ else
303
+ declarations.push({ kind: "state", ownerId, value });
304
+ }
305
+ else {
306
+ finishActiveAsset(record.source.line);
307
+ invalid("Unknown create declaration.", record.source.line, record.type);
308
+ }
309
+ }
310
+ finishActiveAsset(cursor.peek().line);
311
+ const closing = cursor.tag("create", true);
312
+ assertAttrs(closing, []);
313
+ return declarations;
314
+ }
315
+ function speaker(raw, line) {
316
+ const slash = raw.indexOf("/");
317
+ const actor = slash < 0 ? raw : raw.slice(0, slash);
318
+ if (isV4Id("actor", actor)) {
319
+ return slash < 0
320
+ ? { actor_id: actor }
321
+ : { actor_id: actor, state_id: stateId(raw.slice(slash + 1), line) };
322
+ }
323
+ const colon = raw.indexOf(":");
324
+ const kind = (colon < 0 ? raw : raw.slice(0, colon));
325
+ if (!["system", "broadcast", "offscreen", "group"].includes(kind)) {
326
+ return invalid("Speaker is invalid.", line, raw);
327
+ }
328
+ return colon < 0 ? { kind } : { kind, label: raw.slice(colon + 1) };
329
+ }
330
+ function parseAction(cursor) {
331
+ const mod = modifiers(cursor);
332
+ if (mod.aliases !== undefined)
333
+ invalid("aliases cannot modify an Action.", cursor.peek().line, "aliases");
334
+ const record = cursor.record();
335
+ if (record.type === "act" || record.type === "trans") {
336
+ if (record.slots.length !== 1 || !isV4Id("action", record.slots[0])) {
337
+ invalid("Narrative Action record is invalid.", record.source.line, record.type);
338
+ }
339
+ return {
340
+ action_id: record.slots[0],
341
+ type: record.type === "act" ? "action" : "transition",
342
+ content: record.content,
343
+ ...(mod.extend === undefined ? {} : { extend: mod.extend }),
344
+ ...(mod.prompt === undefined ? {} : { transition_prompt: mod.prompt }),
345
+ };
346
+ }
347
+ if (record.type !== "dlg" && record.type !== "think") {
348
+ return invalid("Unknown Action record.", record.source.line, record.type);
349
+ }
350
+ if ((record.slots.length !== 2 && record.slots.length !== 3) || !isV4Id("action", record.slots[0])) {
351
+ invalid("Speaking Action record is invalid.", record.source.line, record.type);
352
+ }
353
+ return {
354
+ action_id: record.slots[0],
355
+ type: record.type === "dlg" ? "dialogue" : "inner_thought",
356
+ speaker: speaker(record.slots[1], record.source.line),
357
+ content: record.content,
358
+ ...(record.slots.length === 3 ? { parenthetical: record.slots[2] } : {}),
359
+ ...(mod.extend === undefined ? {} : { extend: mod.extend }),
360
+ ...(mod.prompt === undefined ? {} : { transition_prompt: mod.prompt }),
361
+ };
362
+ }
363
+ function stateSet(slots, line) {
364
+ if (slots.length === 0)
365
+ invalid("Scene reference needs at least one state.", line, "<empty>");
366
+ const values = slots.map((value) => stateId(value, line));
367
+ if (new Set(values).size !== values.length)
368
+ invalid("Scene reference repeats a state.", line, values.join(","));
369
+ return values.sort();
370
+ }
371
+ function parseScene(cursor, opening, outerParent, extend) {
372
+ assertAttrs(opening, outerParent === undefined ? ["id", "parent"] : ["id"]);
373
+ const id = opening.attrs.get("id") ?? "";
374
+ if (!isV4Id("scene", id))
375
+ invalid("Scene ID is invalid.", opening.line, id);
376
+ const parent = opening.attrs.get("parent") ?? outerParent;
377
+ if (parent !== undefined && !isV4Id("episode", parent)) {
378
+ invalid("Scene parent must be an Episode ID.", opening.line, parent);
379
+ }
380
+ let environment;
381
+ let location;
382
+ const actors = [];
383
+ const props = [];
384
+ const actorIds = new Set();
385
+ const propIds = new Set();
386
+ let phase = 0;
387
+ while (cursor.nextTag()?.name !== "body") {
388
+ const record = cursor.record();
389
+ const nextPhase = record.type === "environment" ? 0
390
+ : record.type === "location" ? 1
391
+ : record.type === "cast" ? 2
392
+ : record.type === "prop" ? 3
393
+ : -1;
394
+ if (nextPhase < phase) {
395
+ invalid("Scene records are not in canonical order.", record.source.line, record.type);
396
+ }
397
+ phase = nextPhase;
398
+ if (record.type === "environment") {
399
+ if (environment !== undefined)
400
+ invalid("Scene environment is duplicated.", record.source.line, record.type);
401
+ if (record.slots.length > 2)
402
+ invalid("environment has too many slots.", record.source.line, record.type);
403
+ environment = {
404
+ ...(record.slots[0] === undefined ? {} : { space: record.slots[0] }),
405
+ ...(record.slots[1] === undefined ? {} : { time: record.slots[1] }),
406
+ };
407
+ }
408
+ else if (record.type === "location") {
409
+ if (location !== undefined)
410
+ invalid("Scene location is duplicated.", record.source.line, record.type);
411
+ if (record.slots.length === 0)
412
+ location = null;
413
+ else {
414
+ if (!isV4Id("location", record.slots[0]))
415
+ invalid("Location ref ID is invalid.", record.source.line, record.slots[0]);
416
+ location = { location_id: record.slots[0], state_ids: stateSet(record.slots.slice(1), record.source.line) };
417
+ }
418
+ }
419
+ else if (record.type === "cast") {
420
+ if (!isV4Id("actor", record.slots[0]))
421
+ invalid("Cast ref ID is invalid.", record.source.line, record.slots[0] ?? "");
422
+ if (actorIds.has(record.slots[0]))
423
+ invalid("Scene repeats an actor reference.", record.source.line, record.slots[0]);
424
+ actorIds.add(record.slots[0]);
425
+ actors.push({ actor_id: record.slots[0], state_ids: stateSet(record.slots.slice(1), record.source.line) });
426
+ }
427
+ else if (record.type === "prop") {
428
+ if (!isV4Id("prop", record.slots[0]))
429
+ invalid("Prop ref ID is invalid.", record.source.line, record.slots[0] ?? "");
430
+ if (propIds.has(record.slots[0]))
431
+ invalid("Scene repeats a prop reference.", record.source.line, record.slots[0]);
432
+ propIds.add(record.slots[0]);
433
+ props.push({ prop_id: record.slots[0], state_ids: stateSet(record.slots.slice(1), record.source.line) });
434
+ }
435
+ else
436
+ invalid("Unknown scene header record.", record.source.line, record.type);
437
+ }
438
+ if (location === undefined)
439
+ invalid("Scene must declare location or [location].", cursor.peek().line, id);
440
+ const bodyOpening = cursor.tag("body", false);
441
+ assertAttrs(bodyOpening, []);
442
+ const actions = [];
443
+ while (cursor.nextTag()?.name !== "body" || cursor.nextTag()?.closing !== true)
444
+ actions.push(parseAction(cursor));
445
+ assertAttrs(cursor.tag("body", true), []);
446
+ assertAttrs(cursor.tag("scene", true), []);
447
+ return {
448
+ ...(parent === undefined ? {} : { parent }),
449
+ value: {
450
+ scene_id: id,
451
+ ...(environment === undefined ? {} : { environment }),
452
+ location,
453
+ actors,
454
+ props,
455
+ actions,
456
+ ...(extend === undefined ? {} : { extend }),
457
+ },
458
+ };
459
+ }
460
+ function parseEpisode(cursor, opening, extend) {
461
+ assertAttrs(opening, ["id"]);
462
+ const id = opening.attrs.get("id") ?? "";
463
+ if (!isV4Id("episode", id))
464
+ invalid("Episode ID is invalid.", opening.line, id);
465
+ let title;
466
+ let synopsis;
467
+ const scenes = [];
468
+ let phase = 0;
469
+ while (cursor.nextTag()?.name !== "episode" || cursor.nextTag()?.closing !== true) {
470
+ const mod = modifiers(cursor);
471
+ if (mod.aliases !== undefined || mod.prompt !== undefined) {
472
+ invalid("Invalid episode child modifier.", cursor.peek().line, "modifier");
473
+ }
474
+ const next = cursor.nextTag();
475
+ if (next?.name === "scene" && !next.closing) {
476
+ phase = 2;
477
+ cursor.take();
478
+ scenes.push(parseScene(cursor, next, id, mod.extend).value);
479
+ continue;
480
+ }
481
+ if (mod.extend !== undefined)
482
+ invalid("extend must precede a scene here.", cursor.peek().line, "extend");
483
+ const record = cursor.record();
484
+ const nextPhase = record.type === "title" ? 0 : record.type === "synopsis" ? 1 : -1;
485
+ if (nextPhase < phase)
486
+ invalid("Episode records are not in canonical order.", record.source.line, record.type);
487
+ phase = nextPhase;
488
+ if (record.type === "title") {
489
+ if (title !== undefined)
490
+ invalid("Episode title is duplicated.", record.source.line, record.type);
491
+ if (record.slots.length !== 0)
492
+ invalid("Episode title takes no slots.", record.source.line, record.type);
493
+ title = record.content;
494
+ }
495
+ else if (record.type === "synopsis") {
496
+ if (synopsis !== undefined)
497
+ invalid("Episode synopsis is duplicated.", record.source.line, record.type);
498
+ if (record.slots.length !== 0)
499
+ invalid("Episode synopsis takes no slots.", record.source.line, record.type);
500
+ synopsis = record.content;
501
+ }
502
+ else
503
+ invalid("Unknown episode record.", record.source.line, record.type);
504
+ }
505
+ assertAttrs(cursor.tag("episode", true), []);
506
+ return {
507
+ episode_id: id,
508
+ ...(title === undefined ? {} : { title }),
509
+ ...(synopsis === undefined ? {} : { synopsis }),
510
+ scenes,
511
+ ...(extend === undefined ? {} : { extend }),
512
+ };
513
+ }
514
+ function range(tag, kind) {
515
+ const value = tag.attrs.get("range") ?? "";
516
+ const pieces = value.split("..");
517
+ if (pieces.length !== 2
518
+ || !pieces[0]
519
+ || !pieces[1]
520
+ || !isV4Id(kind, pieces[0])
521
+ || !isV4Id(kind, pieces[1])) {
522
+ invalid(`Span range must contain two ${kind} IDs.`, tag.line, value);
523
+ }
524
+ return [pieces[0], pieces[1]];
525
+ }
526
+ function parseScriptTarget(cursor, opening, extend) {
527
+ assertAttrs(opening, []);
528
+ let title;
529
+ let worldview;
530
+ let worldview_raw;
531
+ let style;
532
+ let synopsis;
533
+ let logline;
534
+ let theme;
535
+ let main_characters;
536
+ const episodes = [];
537
+ let phase = 0;
538
+ while (cursor.nextTag()?.name !== "script" || cursor.nextTag()?.closing !== true) {
539
+ const mod = modifiers(cursor);
540
+ if (mod.aliases !== undefined || mod.prompt !== undefined) {
541
+ invalid("Invalid script child modifier.", cursor.peek().line, "modifier");
542
+ }
543
+ const next = cursor.nextTag();
544
+ if (next?.name === "episode" && !next.closing) {
545
+ phase = 8;
546
+ cursor.take();
547
+ episodes.push(parseEpisode(cursor, next, mod.extend));
548
+ continue;
549
+ }
550
+ if (mod.extend !== undefined)
551
+ invalid("extend must precede an episode here.", cursor.peek().line, "extend");
552
+ const record = cursor.record();
553
+ const nextPhase = record.type === "title" ? 0
554
+ : record.type === "worldview" ? 1
555
+ : record.type === "worldview-raw" ? 2
556
+ : record.type === "style" ? 3
557
+ : record.type === "synopsis" ? 4
558
+ : record.type === "logline" ? 5
559
+ : record.type === "theme" ? 6
560
+ : record.type === "main-characters" || record.type === "main-character" ? 7
561
+ : -1;
562
+ if (nextPhase < phase)
563
+ invalid("Script records are not in canonical order.", record.source.line, record.type);
564
+ phase = nextPhase;
565
+ if (record.type !== "main-character"
566
+ && record.slots.length !== 0) {
567
+ invalid("Script metadata record takes no slots.", record.source.line, record.type);
568
+ }
569
+ if (record.type === "title") {
570
+ if (title !== undefined)
571
+ invalid("Script title is duplicated.", record.source.line, record.type);
572
+ title = record.content;
573
+ }
574
+ else if (record.type === "worldview") {
575
+ if (worldview !== undefined)
576
+ invalid("Script worldview is duplicated.", record.source.line, record.type);
577
+ worldview = record.content;
578
+ }
579
+ else if (record.type === "worldview-raw") {
580
+ if (worldview_raw !== undefined)
581
+ invalid("Script worldview-raw is duplicated.", record.source.line, record.type);
582
+ worldview_raw = record.content;
583
+ }
584
+ else if (record.type === "style") {
585
+ if (style !== undefined)
586
+ invalid("Script style is duplicated.", record.source.line, record.type);
587
+ style = record.content;
588
+ }
589
+ else if (record.type === "synopsis") {
590
+ if (synopsis !== undefined)
591
+ invalid("Script synopsis is duplicated.", record.source.line, record.type);
592
+ synopsis = record.content;
593
+ }
594
+ else if (record.type === "logline") {
595
+ if (logline !== undefined)
596
+ invalid("Script logline is duplicated.", record.source.line, record.type);
597
+ logline = record.content;
598
+ }
599
+ else if (record.type === "theme") {
600
+ if (theme !== undefined)
601
+ invalid("Script theme is duplicated.", record.source.line, record.type);
602
+ theme = record.content;
603
+ }
604
+ else if (record.type === "main-characters") {
605
+ if (main_characters !== undefined)
606
+ invalid("Script main-characters is duplicated.", record.source.line, record.type);
607
+ main_characters = [];
608
+ }
609
+ else if (record.type === "main-character"
610
+ && main_characters !== undefined
611
+ && record.slots.length === 2
612
+ && record.content === "") {
613
+ main_characters.push({ name: record.slots[0], role: record.slots[1] });
614
+ }
615
+ else
616
+ invalid("Unknown script record.", record.source.line, record.type);
617
+ }
618
+ assertAttrs(cursor.tag("script", true), []);
619
+ if (title === undefined || worldview === undefined || style === undefined) {
620
+ invalid("Script target needs title, worldview, and style.", cursor.peek().line, "script");
621
+ }
622
+ return {
623
+ kind: "script",
624
+ value: {
625
+ title,
626
+ worldview,
627
+ style,
628
+ episodes,
629
+ ...(worldview_raw === undefined ? {} : { worldview_raw }),
630
+ ...(synopsis === undefined ? {} : { synopsis }),
631
+ ...(logline === undefined ? {} : { logline }),
632
+ ...(theme === undefined ? {} : { theme }),
633
+ ...(main_characters === undefined ? {} : { main_characters }),
634
+ ...(extend === undefined ? {} : { extend }),
635
+ },
636
+ };
637
+ }
638
+ export function parseAuthoringV4(text) {
639
+ const cursor = new Cursor(text);
640
+ const root = cursor.tag("authoring", false);
641
+ assertAttrs(root, ["version"]);
642
+ if (root.attrs.get("version") !== "1")
643
+ invalid("authoring version must be 1.", 1, root.attrs.get("version") ?? "<missing>");
644
+ const declarations = cursor.nextTag()?.name === "create" ? parseCreate(cursor) : [];
645
+ const targets = [];
646
+ while (cursor.nextTag()?.name !== "authoring" || cursor.nextTag()?.closing !== true) {
647
+ const mod = modifiers(cursor);
648
+ if (mod.aliases !== undefined || mod.prompt !== undefined) {
649
+ invalid("Invalid target modifier.", cursor.peek().line, "modifier");
650
+ }
651
+ const item = cursor.take();
652
+ const tag = parseTag(item.raw, item.line);
653
+ if (!tag || tag.closing)
654
+ invalid("Expected an authoring target.", item.line, item.raw);
655
+ if (tag.name === "script")
656
+ targets.push(parseScriptTarget(cursor, tag, mod.extend));
657
+ else if (tag.name === "episode")
658
+ targets.push({ kind: "episode", value: parseEpisode(cursor, tag, mod.extend) });
659
+ else if (tag.name === "scene") {
660
+ const parsed = parseScene(cursor, tag, undefined, mod.extend);
661
+ if (!parsed.parent)
662
+ invalid("Top-level scene needs parent.", item.line, item.raw);
663
+ targets.push({ kind: "scene", parent: parsed.parent, value: parsed.value });
664
+ }
665
+ else if (tag.name === "episode-span") {
666
+ if (mod.extend !== undefined)
667
+ invalid("A span cannot carry node extensions.", item.line, item.raw);
668
+ assertAttrs(tag, ["range"]);
669
+ const [from, through] = range(tag, "episode");
670
+ const values = [];
671
+ while (cursor.nextTag()?.name !== "episode-span" || cursor.nextTag()?.closing !== true) {
672
+ const childMod = modifiers(cursor);
673
+ if (childMod.aliases !== undefined || childMod.prompt !== undefined) {
674
+ invalid("Invalid episode child modifier.", cursor.peek().line, "modifier");
675
+ }
676
+ const open = cursor.tag("episode", false);
677
+ values.push(parseEpisode(cursor, open, childMod.extend));
678
+ }
679
+ assertAttrs(cursor.tag("episode-span", true), []);
680
+ targets.push({ kind: "episode-span", from, through, values });
681
+ }
682
+ else if (tag.name === "scene-span") {
683
+ if (mod.extend !== undefined)
684
+ invalid("A span cannot carry node extensions.", item.line, item.raw);
685
+ assertAttrs(tag, ["parent", "range"]);
686
+ const [from, through] = range(tag, "scene");
687
+ const parent = tag.attrs.get("parent") ?? invalid("scene-span needs parent.", item.line, item.raw);
688
+ if (!isV4Id("episode", parent))
689
+ invalid("scene-span parent must be an Episode ID.", item.line, parent);
690
+ const values = [];
691
+ while (cursor.nextTag()?.name !== "scene-span" || cursor.nextTag()?.closing !== true) {
692
+ const childMod = modifiers(cursor);
693
+ if (childMod.aliases !== undefined || childMod.prompt !== undefined) {
694
+ invalid("Invalid scene child modifier.", cursor.peek().line, "modifier");
695
+ }
696
+ const open = cursor.tag("scene", false);
697
+ values.push(parseScene(cursor, open, parent, childMod.extend).value);
698
+ }
699
+ assertAttrs(cursor.tag("scene-span", true), []);
700
+ targets.push({ kind: "scene-span", parent, from, through, values });
701
+ }
702
+ else if (tag.name === "action-span") {
703
+ if (mod.extend !== undefined)
704
+ invalid("A span cannot carry node extensions.", item.line, item.raw);
705
+ assertAttrs(tag, ["parent", "range"]);
706
+ const [from, through] = range(tag, "action");
707
+ const parent = tag.attrs.get("parent") ?? invalid("action-span needs parent.", item.line, item.raw);
708
+ if (!isV4Id("scene", parent))
709
+ invalid("action-span parent must be a Scene ID.", item.line, parent);
710
+ assertAttrs(cursor.tag("body", false), []);
711
+ const values = [];
712
+ while (cursor.nextTag()?.name !== "body" || cursor.nextTag()?.closing !== true)
713
+ values.push(parseAction(cursor));
714
+ assertAttrs(cursor.tag("body", true), []);
715
+ assertAttrs(cursor.tag("action-span", true), []);
716
+ targets.push({ kind: "action-span", parent, from, through, values });
717
+ }
718
+ else
719
+ invalid("Unknown authoring target.", item.line, tag.name);
720
+ }
721
+ assertAttrs(cursor.tag("authoring", true), []);
722
+ if (cursor.index !== cursor.lines.length || targets.length === 0)
723
+ invalid("Authoring file has trailing content or no targets.", cursor.peek().line, "<root>");
724
+ const targetKind = targets[0].kind;
725
+ if (!targets.every((target) => target.kind === targetKind))
726
+ invalid("All targets must have the same kind.", 1, targetKind);
727
+ return { declarations, targets, targetKind };
728
+ }
729
+ //# sourceMappingURL=parser.js.map