@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
package/dist/cli.js CHANGED
@@ -2,614 +2,185 @@ import * as fs from "node:fs";
2
2
  import * as path from "node:path";
3
3
  import { fileURLToPath } from "node:url";
4
4
  import { Command, CommanderError } from "commander";
5
- import { CliError, EXIT_OK, EXIT_USAGE, scriptJsonPath } from "./common.js";
6
- import { getHelp } from "./help-text.js";
5
+ import { CliError, EXIT_OK, EXIT_USAGE } from "./common.js";
6
+ import { registerBatchCommands } from "./cli/register-batch.js";
7
+ import { registerEditCommands } from "./cli/register-edits.js";
8
+ import { registerQueryCommands } from "./cli/register-query.js";
9
+ import { registerToolCommands } from "./cli/register-tools.js";
10
+ import { registerWorkflowCommands } from "./cli/register-workflows.js";
7
11
  import { loadLocalEnv } from "./infra/env.js";
8
- import { emit, emitError } from "./output.js";
9
12
  import { PRODUCTION_LLM_COMPOSITION } from "./llm/composition.js";
10
- import { commandIngest } from "./usecases/ingest/command.js";
11
- import { commandIngestStatus } from "./usecases/ingest/status.js";
12
- import { commandView } from "./usecases/ingest/view-command.js";
13
- import { withScriptFileLock } from "./infra/script-working-copy.js";
14
- import { commandDoctor } from "./usecases/doctor.js";
15
- import { commandUpdate } from "./usecases/update.js";
16
- import { commandChangelog } from "./usecases/changelog.js";
17
- import { commandActions } from "./usecases/script/actions.js";
18
- import { commandActor } from "./usecases/script/actor.js";
19
- import { commandActors } from "./usecases/script/actors.js";
20
- import { commandAddEpisode } from "./usecases/script/add-episode.js";
21
- import { commandAddLocation } from "./usecases/script/add-location.js";
22
- import { commandAddProp } from "./usecases/script/add-prop.js";
23
- import { commandAddActor } from "./usecases/script/add-actor.js";
24
- import { commandAlias } from "./usecases/script/alias.js";
25
- import { commandAssets } from "./usecases/script/assets.js";
26
- import { commandContext } from "./usecases/script/context.js";
27
- import { commandCreate } from "./usecases/script/create.js";
28
- import { commandDelete } from "./usecases/script/delete.js";
29
- import { commandDescribe } from "./usecases/script/describe.js";
30
- import { commandExtend } from "./usecases/script/extend.js";
31
- import { commandDialogue } from "./usecases/script/dialogue.js";
32
- import { commandImportance } from "./usecases/script/importance.js";
33
- import { commandDo } from "./usecases/script/do.js";
34
- import { commandEmotion } from "./usecases/script/emotion.js";
35
- import { commandEpisodes } from "./usecases/script/episodes.js";
36
- import { commandInsert } from "./usecases/script/insert.js";
37
- import { commandIssues } from "./usecases/script/issues.js";
38
- import { commandLocations } from "./usecases/script/locations.js";
39
- import { commandMerge } from "./usecases/script/merge.js";
40
- import { commandMove } from "./usecases/script/move.js";
41
- import { commandProps } from "./usecases/script/props.js";
42
- import { commandRefs } from "./usecases/script/refs.js";
43
- import { commandRename } from "./usecases/script/rename.js";
44
- import { commandReplace } from "./usecases/script/replace.js";
45
- import { commandRole } from "./usecases/script/role.js";
46
- import { commandScenes } from "./usecases/script/scenes.js";
47
- import { commandScriptPatch } from "./usecases/script/script-patch.js";
48
- import { commandScriptValidate } from "./usecases/script/script-validate.js";
49
- import { commandSplit } from "./usecases/script/split.js";
50
- import { commandStates } from "./usecases/script/states.js";
51
- import { commandStateAdd } from "./usecases/script/state-add.js";
52
- import { commandStateDelete } from "./usecases/script/state-delete.js";
53
- import { commandStateRename } from "./usecases/script/state-rename.js";
54
- import { commandSummary } from "./usecases/script/summary.js";
55
- import { commandSynopsis } from "./usecases/script/synopsis.js";
56
- import { commandSynopsisGenerate } from "./usecases/script/synopsis-generate.js";
57
- import { commandTransition } from "./usecases/script/transition.js";
58
- import { commandType } from "./usecases/script/type.js";
59
- import { commandWorldview } from "./usecases/script/worldview.js";
60
- import { commandWriteAuthoring } from "./usecases/script/write-authoring.js";
61
- import { commandExportAuthoring } from "./usecases/script/export-authoring.js";
62
- import { commandIds } from "./usecases/script/ids.js";
63
- import { commandCheckout, commandWorkingCopyPublish, commandWorkingCopyStatus, } from "./usecases/script/working-copy.js";
64
- function packageRoot() {
65
- const here = fileURLToPath(import.meta.url);
66
- return path.resolve(path.dirname(here), "..");
67
- }
13
+ import { emitError } from "./output.js";
68
14
  function readPackageVersion() {
69
- try {
70
- const pkgPath = path.join(packageRoot(), "package.json");
71
- const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
72
- return pkg.version ?? "0.0.0";
73
- }
74
- catch {
75
- return "0.0.0";
76
- }
77
- }
78
- const KNOWN_COMMANDS = new Set([
79
- "doctor",
80
- "update",
81
- "changelog",
82
- // Workflow
83
- "ingest",
84
- "ingest.status",
85
- "view",
86
- "checkout",
87
- "status",
88
- "publish",
89
- "write",
90
- "ids",
91
- "export",
92
- "export.script",
93
- "export.episodes",
94
- "export.episode-spans",
95
- "export.scenes",
96
- "export.scene-spans",
97
- "export.action-spans",
98
- // Query (plural-noun)
99
- "summary", "episodes", "scenes", "actions", "actors", "locations", "props",
100
- "assets", "states", "issues", "refs", "validate",
101
- // Create + add entities
102
- "create", "add-actor", "add-location", "add-prop", "add-episode",
103
- // Edit content
104
- "replace", "type", "actor", "emotion",
105
- // Structure (multipolar)
106
- "insert", "delete", "move", "split", "merge",
107
- // Scene refs & transitions on actions
108
- "transition", "scene-ref",
109
- // Asset metadata
110
- "rename", "describe", "alias", "role", "importance", "worldview", "synopsis", "synopsis.generate",
111
- // Free-form namespace (any dimension)
112
- "extend",
113
- // State management
114
- "state-add", "state-rename", "state-delete",
115
- // Dialogue speaker / patch
116
- "dialogue",
117
- "patch", "do",
118
- ]);
119
- // Groups are command nodes that exist only to host subcommands. Extra non-flag
120
- // tokens after a group path indicate an unknown subcommand (e.g. `direct nope` → error).
121
- // Leaves are real commands that can accept positional arguments.
122
- const GROUP_COMMANDS = new Set(["export"]);
123
- function extractLeadingPath(args) {
124
- // Collect leading non-flag tokens, then take only as many as form the longest known
125
- // command prefix. Trailing tokens are treated as either:
126
- // - positional arguments (when the matched node is a leaf, e.g. `episode draft 1`)
127
- // - unknown subcommands (when the matched node is a group, e.g. `direct nope`)
128
- const allNonFlag = [];
129
- for (const tok of args) {
130
- if (tok.startsWith("-"))
131
- break;
132
- allNonFlag.push(tok);
133
- if (allNonFlag.length >= 5)
134
- break;
135
- }
136
- const matchLen = longestKnownPrefix(allNonFlag);
137
- if (matchLen === 0) {
138
- // No known command at all — return up to 3 tokens for a readable error.
139
- return allNonFlag.slice(0, 3);
140
- }
141
- const matchedKey = allNonFlag.slice(0, matchLen).join(".");
142
- const isGroup = GROUP_COMMANDS.has(matchedKey);
143
- if (isGroup && allNonFlag.length > matchLen) {
144
- // Group + extra tokens = unknown subcommand. Return the truncated path so the
145
- // validator (knownLen < cmdPath.length) reports an error.
146
- return allNonFlag.slice(0, Math.min(allNonFlag.length, 3));
147
- }
148
- return allNonFlag.slice(0, matchLen);
149
- }
150
- function longestKnownPrefix(path) {
151
- for (let len = path.length; len > 0; len--) {
152
- if (KNOWN_COMMANDS.has(path.slice(0, len).join(".")))
153
- return len;
154
- }
155
- return 0;
156
- }
157
- function commandPath(cmd) {
158
- const parts = [];
159
- let c = cmd;
160
- while (c) {
161
- const name = c.name();
162
- if (!name || name === "scriptctl")
163
- break;
164
- parts.unshift(name);
165
- c = c.parent;
166
- }
167
- return parts;
168
- }
169
- function camelToSnake(s) {
170
- return s.replace(/([A-Z])/g, "_$1").toLowerCase();
171
- }
172
- function normalizeOpts(opts) {
173
- const out = {};
174
- for (const [k, v] of Object.entries(opts))
175
- out[camelToSnake(k)] = v;
176
- return out;
177
- }
178
- function mergedCommandOpts(cmd) {
179
- const chain = [];
180
- let current = cmd;
181
- while (current) {
182
- chain.unshift(current);
183
- current = current.parent;
184
- }
185
- const merged = {};
186
- for (const item of chain) {
187
- Object.assign(merged, item.opts());
188
- }
189
- return merged;
190
- }
191
- const SCRIPT_ACCESS = new WeakMap();
192
- function dispatch(handler, state) {
193
- return async (...args) => {
194
- const cmd = args[args.length - 1];
195
- const positionals = args.slice(0, -2).filter((p) => p !== undefined);
196
- const normalized = normalizeOpts(mergedCommandOpts(cmd));
197
- if (positionals.length > 0)
198
- normalized._args = positionals;
199
- const invoke = async () => handler(normalized);
200
- const result = SCRIPT_ACCESS.get(cmd) === "write"
201
- ? await withScriptFileLock(scriptJsonPath(normalized), invoke)
202
- : await invoke();
203
- const [report, exitCode] = result;
204
- emit(report, exitCode, state.jsonMode, state.format);
205
- state.exitCode = exitCode;
206
- };
207
- }
208
- function showGroupHelp(commandPathParts, state) {
209
- return () => {
210
- process.stdout.write(getHelp(commandPathParts) ?? getHelp([]) ?? "");
211
- state.exitCode = EXIT_OK;
212
- };
213
- }
214
- const appendStr = (value, prev) => [...prev, value];
215
- function withScriptOpts(cmd, access = "write") {
216
- SCRIPT_ACCESS.set(cmd, access);
217
- return cmd.option("--script-path <path>");
218
- }
219
- function withWorkingCopyOpts(cmd) {
220
- SCRIPT_ACCESS.set(cmd, "write");
221
- return cmd
222
- .option("--script-path <path>")
223
- .option("--project-group-no <no>");
224
- }
225
- // Selection flags shared by query commands and selector-driven write verbs:
226
- // the SAME vocabulary reads and writes. `--in` scopes by address (range /
227
- // region / '*' = whole script); the predicates AND-refine within scope.
228
- // On write verbs, `--apply` commits (default is a dry-run that reports the
229
- // blast radius and writes nothing); `--dry-run` is accepted as a no-op (it is
230
- // already the default) for symmetry.
231
- function withSelection(cmd) {
232
- return cmd
233
- .option("--in <selector>")
234
- .option("--type <type>")
235
- .option("--actor <id>")
236
- .option("--grep <pattern>")
237
- .option("--has <facet>")
238
- .option("--apply")
239
- .option("--dry-run");
15
+ const here = fileURLToPath(import.meta.url);
16
+ const packagePath = path.resolve(path.dirname(here), "..", "package.json");
17
+ const packageJson = JSON.parse(fs.readFileSync(packagePath, "utf-8"));
18
+ return packageJson.version;
240
19
  }
241
- function buildProgram(state, llm) {
20
+ export function buildProgram(state, llm = PRODUCTION_LLM_COMPOSITION) {
242
21
  const program = new Command("scriptctl")
22
+ .description("Read, edit, ingest, and publish structured scripts")
23
+ .usage("<command> [options]")
243
24
  .exitOverride()
244
25
  .allowExcessArguments(false)
245
26
  .allowUnknownOption(false)
27
+ .showHelpAfterError(false)
246
28
  .configureOutput({
247
- writeOut: (str) => process.stdout.write(str),
29
+ writeOut: (text) => process.stdout.write(text),
248
30
  writeErr: () => {
249
- /* swallowed; we emit our own envelope */
31
+ // Commander errors are emitted once through the scriptctl error model.
250
32
  },
251
33
  })
252
- .configureHelp({
253
- formatHelp: (cmd) => getHelp(commandPath(cmd)) ?? getHelp([]) ?? "",
254
- });
255
- program.command("doctor")
256
- .option("--llm-config <path>")
257
- .action(dispatch((o) => commandDoctor(o), state));
258
- program.command("update")
259
- .option("--dry-run")
260
- .option("--patch")
261
- .action(dispatch((o) => commandUpdate(o), state));
262
- program.command("changelog [version]")
263
- .option("--from <version>")
264
- .option("--to <version>")
265
- .option("--unreleased")
266
- .action(dispatch((o) => commandChangelog(o), state));
267
- const ingest = program.command("ingest")
268
- .option("--source-path <path>")
269
- .option("--workspace-path <path>", "", "workspace")
270
- .option("--llm-config <path>")
271
- .option("--concurrency <n>")
272
- .option("--fps <n>")
273
- .option("--force")
274
- .action(dispatch((options) => commandIngest(options, llm), state));
275
- // `ingest status` — derive progress from the workspace's real file state (no
276
- // model, no store). The runtime watcher / frontend consume `--json`.
277
- // NB: --workspace-path is inherited from the parent `ingest` command — if the
278
- // subcommand redeclared it, commander would attribute the user's value to the
279
- // parent and clobber it with the subcommand's default in mergedCommandOpts.
280
- ingest.command("status")
281
- .action(dispatch((options) => commandIngestStatus(options), state));
282
- program.command("view")
283
- .option("--workspace-path <path>", "", "workspace")
284
- .option("--watch")
285
- .option("--port <n>")
286
- .action(dispatch((options) => commandView(options), state));
287
- withWorkingCopyOpts(program.command("checkout"))
288
- .option("--discard-local")
289
- .action(dispatch(commandCheckout, state));
290
- withScriptOpts(program.command("status"))
291
- .action(dispatch(commandWorkingCopyStatus, state));
292
- withWorkingCopyOpts(program.command("publish"))
293
- .action(dispatch(commandWorkingCopyPublish, state));
294
- withScriptOpts(program.command("write <file>"))
295
- .option("--create")
296
- .option("--replace")
297
- .option("--apply")
298
- .option("--plan <digest>")
299
- .action(dispatch(commandWriteAuthoring, state));
300
- withScriptOpts(program.command("ids"), "read")
301
- .requiredOption("--kind <kind>")
302
- .requiredOption("--count <n>")
303
- .action(dispatch(commandIds, state));
304
- const exportCommand = program.command("export")
305
- .action(showGroupHelp(["export"], state));
306
- withScriptOpts(exportCommand.command("script"), "read")
307
- .requiredOption("--output <file>")
308
- .action(dispatch((opts) => commandExportAuthoring("script", opts), state));
309
- for (const kind of ["episodes", "episode-spans", "scenes", "scene-spans", "action-spans"]) {
310
- withScriptOpts(exportCommand.command(kind), "read")
311
- .requiredOption("--in <selector>")
312
- .requiredOption("--output <file>")
313
- .action(dispatch((opts) => commandExportAuthoring(kind, opts), state));
314
- }
315
- // ============================== query (plural-noun) ==============================
316
- withScriptOpts(program.command("summary"), "read")
317
- .action(dispatch(commandSummary, state));
318
- withScriptOpts(program.command("episodes"), "read")
319
- .option("--id <id>")
320
- .option("--in <addr>")
321
- .option("--min-chars <n>")
322
- .option("--max-chars <n>")
323
- .action(dispatch(commandEpisodes, state));
324
- withScriptOpts(program.command("scenes"), "read")
325
- .option("--in <addr>")
326
- .option("--has-actor <id>")
327
- .option("--has-location <id>")
328
- .option("--has-prop <id>")
329
- .action(dispatch(commandScenes, state));
330
- withScriptOpts(program.command("actions"), "read")
331
- .option("--in <addr>")
332
- .option("--grep <text>")
333
- .option("--type <type>")
334
- .option("--actor <id>")
335
- .option("--has <kind>")
336
- .option("--context <n>")
337
- .action(dispatch(commandActions, state));
338
- withScriptOpts(program.command("actors"), "read")
339
- .option("--id <id>")
340
- .option("--name <text>")
341
- .option("--in <addr>")
342
- .option("--counts")
343
- .action(dispatch(commandActors, state));
344
- withScriptOpts(program.command("locations"), "read")
345
- .option("--id <id>")
346
- .option("--name <text>")
347
- .option("--in <addr>")
348
- .option("--counts")
349
- .action(dispatch(commandLocations, state));
350
- withScriptOpts(program.command("props"), "read")
351
- .option("--id <id>")
352
- .option("--name <text>")
353
- .option("--in <addr>")
354
- .option("--counts")
355
- .action(dispatch(commandProps, state));
356
- withScriptOpts(program.command("assets"), "read")
357
- .option("--kind <kind>")
358
- .option("--id <id>")
359
- .option("--name <text>")
360
- .option("--in <addr>")
361
- .option("--counts")
362
- .action(dispatch(commandAssets, state));
363
- withScriptOpts(program.command("states <asset-addr>"), "read")
364
- .action(dispatch(commandStates, state));
365
- withScriptOpts(program.command("issues"), "read")
366
- .option("--severity <severity>")
367
- .option("--code <code>")
368
- .action(dispatch(commandIssues, state));
369
- withScriptOpts(program.command("refs <addr>"), "read")
370
- .option("--level <level>")
371
- .action(dispatch(commandRefs, state));
372
- withScriptOpts(program.command("validate"), "read")
373
- .action(dispatch(commandScriptValidate, state));
374
- // ============================== create + add entities ==============================
375
- withScriptOpts(program.command("create"))
376
- .option("--title <title>")
377
- .option("--force")
378
- .action(dispatch(commandCreate, state));
379
- withScriptOpts(program.command("add-actor <name>"))
380
- .option("--id <id>")
381
- .option("--role <role>")
382
- .option("--description <text>")
383
- .option("--alias <alias>", "", appendStr, [])
384
- .action(dispatch(commandAddActor, state));
385
- withScriptOpts(program.command("add-location <name>"))
386
- .option("--id <id>")
387
- .option("--description <text>")
388
- .action(dispatch(commandAddLocation, state));
389
- withScriptOpts(program.command("add-prop <name>"))
390
- .option("--id <id>")
391
- .option("--description <text>")
392
- .action(dispatch(commandAddProp, state));
393
- withScriptOpts(program.command("add-episode"))
394
- .option("--id <id>")
395
- .option("--title <title>")
396
- .action(dispatch(commandAddEpisode, state));
397
- // ============================== edit verbs ==============================
398
- // ----- content (single-point address OR a selection for a sweep) -----
399
- withSelection(withScriptOpts(program.command("replace [at]")))
400
- .requiredOption("--from <text>")
401
- .option("--to <text>", "", "")
402
- .option("--all")
403
- .option("--regex")
404
- .action(dispatch(commandReplace, state));
405
- withSelection(withScriptOpts(program.command("type [at] [type]")))
406
- .action(dispatch(commandType, state));
407
- withSelection(withScriptOpts(program.command("actor [at] [actor-id]")))
408
- .action(dispatch(commandActor, state));
409
- withSelection(withScriptOpts(program.command("emotion [at] [emotion]")))
410
- .option("--clear")
411
- .action(dispatch(commandEmotion, state));
412
- // ----- structure (multipolar by first-arg address format) -----
413
- withScriptOpts(program.command("insert <addr>"))
414
- .option("--type <type>")
415
- .option("--content <text>")
416
- .option("--emotion <emotion>")
417
- .option("--at <idx>")
418
- .option("--before <addr>")
419
- .option("--after <addr>")
420
- .option("--actor <id>")
421
- .option("--kind <kind>", "non-actor speaker: system|broadcast|offscreen|group")
422
- .option("--label <text>", "optional label for a non-actor speaker")
423
- .option("--location <id>")
424
- .option("--time <time>")
425
- .option("--space <space>")
426
- .option("--scene-id <id>")
427
- .action(dispatch(commandInsert, state));
428
- withScriptOpts(program.command("delete <addr>"))
429
- .option("--strategy <strategy>")
430
- .option("--replacement <addr>")
431
- .option("--force")
432
- .action(dispatch(commandDelete, state));
433
- withScriptOpts(program.command("move <addr> <to>"))
434
- .option("--at <idx>")
435
- .action(dispatch(commandMove, state));
436
- withScriptOpts(program.command("split <ep/scn>"))
437
- .requiredOption("--at <idx>")
438
- .option("--new-scene-id <id>")
439
- .action(dispatch(commandSplit, state));
440
- withScriptOpts(program.command("merge <src>"))
441
- .requiredOption("--into <dst>")
442
- .action(dispatch(commandMerge, state));
443
- // ----- transition / scene refs -----
444
- withSelection(withScriptOpts(program.command("transition [at] [target]")))
445
- .option("--process <text>")
446
- .option("--contrast <text>")
447
- .option("--clear")
448
- .action(dispatch(commandTransition, state));
449
- withScriptOpts(program.command("scene-ref <at> <target>"))
450
- .option("--state <id>")
451
- .option("--clear")
452
- .option("--remove")
453
- .option("--append")
454
- .option("--occurrence <n>")
455
- .action(dispatch(commandContext, state));
456
- // ----- asset metadata -----
457
- withScriptOpts(program.command("rename <target> <name>"))
458
- .action(dispatch(commandRename, state));
459
- withScriptOpts(program.command("describe <target> <text>"))
460
- .action(dispatch(commandDescribe, state));
461
- withScriptOpts(program.command("alias <target>"))
462
- .option("--add <alias>", "", appendStr, [])
463
- .option("--remove <alias>", "", appendStr, [])
464
- .action(dispatch(commandAlias, state));
465
- withScriptOpts(program.command("role <target> <role>"))
466
- .action(dispatch(commandRole, state));
467
- withScriptOpts(program.command("importance <target> <importance>"))
468
- .action(dispatch(commandImportance, state));
469
- withScriptOpts(program.command("worldview <value>"))
470
- .action(dispatch(commandWorldview, state));
471
- const synopsis = withScriptOpts(program.command("synopsis [target-or-text] [text]"))
472
- .action(dispatch(commandSynopsis, state));
473
- withScriptOpts(synopsis.command("generate"))
474
- .option("--llm-config <path>")
475
- .option("--concurrency <n>", "", "30")
476
- .option("--checkpoint <dir>")
477
- .option("--overwrite")
478
- .option("--apply")
479
- .option("--dry-run")
480
- .action(dispatch((options) => commandSynopsisGenerate(options, llm), state));
481
- // NB: the value-parsing flag is `--json-value`, NOT `--json` — the global
482
- // `--json` output-mode flag is stripped from argv before commander runs (see
483
- // main()), so it can never reach this subcommand.
484
- withScriptOpts(program.command("extend <addr> [key] [value]"))
485
- .option("--json-value", "parse value as JSON (number/bool/object/array)")
486
- .option("--clear", "delete the key (or the whole container if no key)")
487
- .action(dispatch(commandExtend, state));
488
- // ----- state management -----
489
- withScriptOpts(program.command("state-add <target> <name>"))
490
- .option("--description <text>", "", "")
491
- .option("--state-id <id>")
492
- .action(dispatch(commandStateAdd, state));
493
- withScriptOpts(program.command("state-rename <target> <name>"))
494
- .action(dispatch(commandStateRename, state));
495
- withScriptOpts(program.command("state-delete <target>"))
496
- .requiredOption("--strategy <strategy>")
497
- .option("--replacement <id>")
498
- .action(dispatch(commandStateDelete, state));
499
- // ----- dialogue speaker (v3: single inline speaker per line) -----
500
- withScriptOpts(program.command("dialogue <at>"))
501
- .option("--actor <id>", "set the line's speaker to an actor")
502
- .option("--kind <kind>", "non-actor speaker: system|broadcast|offscreen|group")
503
- .option("--label <text>", "optional label for a non-actor speaker")
504
- .action(dispatch(commandDialogue, state));
505
- // ----- do (verb-script transaction) -----
506
- withScriptOpts(program.command("do [file]"))
507
- .option("--apply")
508
- .option("--dry-run")
509
- .action(dispatch(commandDo, state));
510
- // ----- patch (machine / jq op interchange) -----
511
- // <file> is OPTIONAL because --schema dumps op schemas without a file.
512
- // When --schema is absent the patch / dry-run paths require <file>; the
513
- // handler enforces that.
514
- withScriptOpts(program.command("patch [file]"))
515
- .option("--schema [op]")
516
- .option("--dry-run")
517
- .action(dispatch((o) => {
518
- const args = o["_args"] || [];
519
- if (args[0])
520
- o["patch"] = args[0];
521
- return commandScriptPatch(o);
522
- }, state));
34
+ .option("-j, --json", "Output structured JSON")
35
+ .option("--format <format>", "Output format (addr)")
36
+ .version(readPackageVersion(), "-v, --version", "Show the scriptctl version");
37
+ registerWorkflowCommands(program, state, llm);
38
+ registerQueryCommands(program, state, llm);
39
+ registerEditCommands(program, state, llm);
40
+ registerBatchCommands(program, state);
41
+ registerToolCommands(program, state);
523
42
  return program;
524
43
  }
525
- export async function main(argv = null, llm = PRODUCTION_LLM_COMPOSITION) {
526
- loadLocalEnv();
527
- let args = argv ?? process.argv.slice(2);
528
- // `--format <fmt>` is a global output toggle (like --json). `addr` emits a bare
529
- // newline-delimited address stream from a query's rows[] clean xargs input.
530
- let format;
531
- for (let i = 0; i < args.length; i++) {
532
- const a = args[i];
533
- if (a.startsWith("--format=")) {
534
- format = a.slice("--format=".length);
535
- args.splice(i, 1);
536
- i--;
44
+ function optionFor(command, token) {
45
+ const flag = token.split("=", 1)[0];
46
+ let current = command;
47
+ while (current) {
48
+ const option = current.options.find((candidate) => candidate.short === flag || candidate.long === flag);
49
+ if (option)
50
+ return option;
51
+ current = current.parent;
52
+ }
53
+ return undefined;
54
+ }
55
+ function scanShortOptions(command, token) {
56
+ if (!token.startsWith("-") || token.startsWith("--") || token.length < 2) {
57
+ return { recognized: false, json: false, hasAttachedValue: false };
58
+ }
59
+ let json = false;
60
+ for (let index = 1; index < token.length; index += 1) {
61
+ const option = optionFor(command, `-${token[index]}`);
62
+ if (!option?.short) {
63
+ return { recognized: false, json: false, hasAttachedValue: false };
537
64
  }
538
- else if (a === "--format") {
539
- const v = args[i + 1];
540
- // Only consume the next token as the value when it isn't itself a flag —
541
- // otherwise `--format --json` would silently eat --json.
542
- if (v !== undefined && !v.startsWith("-")) {
543
- format = v;
544
- args.splice(i, 2);
545
- }
546
- else
547
- args.splice(i, 1);
548
- i--;
65
+ if (option.short === "-j")
66
+ json = true;
67
+ if (option.required || option.optional) {
68
+ return {
69
+ recognized: true,
70
+ json,
71
+ valueOption: option,
72
+ hasAttachedValue: index < token.length - 1,
73
+ };
549
74
  }
550
75
  }
551
- const state = { jsonMode: args.includes("--json"), exitCode: EXIT_OK, format };
552
- args = args.filter((a) => a !== "--json");
553
- if (args.includes("--version")) {
554
- process.stdout.write(`${readPackageVersion()}\n`);
555
- return EXIT_OK;
76
+ return { recognized: true, json, hasAttachedValue: false };
77
+ }
78
+ function isRecognizedOptionToken(command, token) {
79
+ if (token === "--")
80
+ return true;
81
+ if (token.startsWith("--"))
82
+ return optionFor(command, token) !== undefined;
83
+ return scanShortOptions(command, token).recognized;
84
+ }
85
+ function consumesNextValue(command, option, next) {
86
+ if (next === undefined || next === "--")
87
+ return false;
88
+ if (option.required)
89
+ return !isRecognizedOptionToken(command, next);
90
+ return option.optional && !next.startsWith("-");
91
+ }
92
+ function initialJsonMode(program, args) {
93
+ let command = program;
94
+ for (let index = 0; index < args.length; index += 1) {
95
+ const token = args[index];
96
+ if (token === "--")
97
+ break;
98
+ if (token.startsWith("--")) {
99
+ if (token === "--json")
100
+ return true;
101
+ const option = optionFor(command, token);
102
+ if (option
103
+ && !token.includes("=")
104
+ && consumesNextValue(command, option, args[index + 1]))
105
+ index += 1;
106
+ continue;
107
+ }
108
+ if (token.startsWith("-")) {
109
+ const scanned = scanShortOptions(command, token);
110
+ if (scanned.recognized && scanned.json)
111
+ return true;
112
+ if (scanned.recognized
113
+ && scanned.valueOption
114
+ && !scanned.hasAttachedValue
115
+ && consumesNextValue(command, scanned.valueOption, args[index + 1]))
116
+ index += 1;
117
+ continue;
118
+ }
119
+ const child = command.commands.find((candidate) => candidate.name() === token);
120
+ if (child)
121
+ command = child;
556
122
  }
557
- const wantsHelp = args.includes("--help") || args.includes("-h");
558
- const cmdPath = extractLeadingPath(args);
559
- if (cmdPath.length === 0) {
560
- if (args.length === 0 || wantsHelp) {
561
- process.stdout.write(getHelp([]) ?? "");
562
- return EXIT_OK;
123
+ return false;
124
+ }
125
+ function helpTarget(program, args) {
126
+ let command = program;
127
+ for (let index = 0; index < args.length; index += 1) {
128
+ const token = args[index];
129
+ if (token.startsWith("-")) {
130
+ const option = optionFor(command, token);
131
+ if (option && !token.includes("=") && (option.required || option.optional))
132
+ index += 1;
133
+ continue;
563
134
  }
564
- return emitError(new CliError("USAGE ERROR: Unknown command", "Unknown command.", {
565
- exitCode: EXIT_USAGE,
566
- required: ["valid scriptctl command"],
567
- received: [args.join(" ") || "<empty>"],
568
- nextSteps: ["Run: scriptctl --help"],
569
- }), state.jsonMode);
135
+ const child = command.commands.find((candidate) => candidate.name() === token);
136
+ if (!child)
137
+ break;
138
+ command = child;
570
139
  }
571
- const knownLen = longestKnownPrefix(cmdPath);
572
- if (knownLen < cmdPath.length) {
573
- return emitError(new CliError("USAGE ERROR: Unknown command", "Unknown command.", {
574
- exitCode: EXIT_USAGE,
575
- required: ["valid scriptctl command"],
576
- received: [cmdPath.join(" ")],
577
- nextSteps: ["Run: scriptctl --help"],
578
- }), state.jsonMode);
140
+ const names = [];
141
+ let current = command;
142
+ while (current && current.parent) {
143
+ names.unshift(current.name());
144
+ current = current.parent;
579
145
  }
580
- if (wantsHelp) {
581
- process.stdout.write(getHelp(cmdPath) ?? getHelp([]) ?? "");
146
+ return ["scriptctl", ...names, "--help"].join(" ");
147
+ }
148
+ function commanderMessage(error) {
149
+ return error.message.replace(/^error:\s*/i, "").replace(/\.$/, "");
150
+ }
151
+ export async function main(argv = null, llm = PRODUCTION_LLM_COMPOSITION) {
152
+ loadLocalEnv();
153
+ const args = argv ?? process.argv.slice(2);
154
+ const state = { jsonMode: false, exitCode: EXIT_OK };
155
+ const program = buildProgram(state, llm);
156
+ state.jsonMode = initialJsonMode(program, args);
157
+ if (args.length === 0) {
158
+ program.outputHelp();
582
159
  return EXIT_OK;
583
160
  }
584
- const program = buildProgram(state, llm);
585
161
  try {
586
162
  await program.parseAsync(args, { from: "user" });
587
163
  return state.exitCode;
588
164
  }
589
- catch (err) {
590
- if (err instanceof CommanderError) {
591
- const code = err.code;
592
- if (code === "commander.help" ||
593
- code === "commander.helpDisplayed" ||
594
- code === "commander.version") {
165
+ catch (error) {
166
+ if (error instanceof CommanderError) {
167
+ if (error.code === "commander.help"
168
+ || error.code === "commander.helpDisplayed"
169
+ || error.code === "commander.version") {
595
170
  return EXIT_OK;
596
171
  }
597
- const message = err.message || "Invalid arguments.";
598
- return emitError(new CliError("USAGE ERROR: Invalid arguments", "Invalid arguments.", {
172
+ return emitError(new CliError(commanderMessage(error), {
599
173
  exitCode: EXIT_USAGE,
600
- required: ["Run: scriptctl --help"],
601
- received: [message],
602
- nextSteps: ["Run: scriptctl --help"],
174
+ errorCode: "USAGE_ERROR",
175
+ hint: `Run '${helpTarget(program, args)}'.`,
603
176
  }), state.jsonMode);
604
177
  }
605
- if (err instanceof CliError)
606
- return emitError(err, state.jsonMode);
607
- const e = err;
608
- return emitError(new CliError("RUNTIME FAILED: Unexpected error", "Unexpected error.", {
178
+ if (error instanceof CliError)
179
+ return emitError(error, state.jsonMode);
180
+ const message = error instanceof Error ? error.message : String(error);
181
+ return emitError(new CliError(message, {
609
182
  exitCode: 70,
610
- required: ["successful command execution"],
611
- received: [e?.name ?? "Error"],
612
- nextSteps: ["Rerun with valid inputs or inspect workspace artifacts."],
183
+ errorCode: "RUNTIME_ERROR",
613
184
  }), state.jsonMode);
614
185
  }
615
186
  }