mergestory 0.0.0-stage → 1.0.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 (474) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +2 -0
  3. package/README.md +48 -2
  4. package/assets/kokoro-plugin/package-lock.json +1139 -0
  5. package/dist/analyzer/analyze.d.ts +8 -0
  6. package/dist/analyzer/analyze.js +328 -0
  7. package/dist/analyzer/components.d.ts +18 -0
  8. package/dist/analyzer/components.js +266 -0
  9. package/dist/analyzer/dependencies.d.ts +13 -0
  10. package/dist/analyzer/dependencies.js +349 -0
  11. package/dist/analyzer/evidence.d.ts +15 -0
  12. package/dist/analyzer/evidence.js +73 -0
  13. package/dist/analyzer/hunks.d.ts +21 -0
  14. package/dist/analyzer/hunks.js +88 -0
  15. package/dist/analyzer/imports.d.ts +46 -0
  16. package/dist/analyzer/imports.js +87 -0
  17. package/dist/analyzer/index.d.ts +14 -0
  18. package/dist/analyzer/index.js +16 -0
  19. package/dist/analyzer/languages/go.d.ts +2 -0
  20. package/dist/analyzer/languages/go.js +76 -0
  21. package/dist/analyzer/languages/index.d.ts +18 -0
  22. package/dist/analyzer/languages/index.js +72 -0
  23. package/dist/analyzer/languages/javascript.d.ts +2 -0
  24. package/dist/analyzer/languages/javascript.js +336 -0
  25. package/dist/analyzer/languages/jvm.d.ts +2 -0
  26. package/dist/analyzer/languages/jvm.js +157 -0
  27. package/dist/analyzer/languages/others.d.ts +2 -0
  28. package/dist/analyzer/languages/others.js +40 -0
  29. package/dist/analyzer/languages/php.d.ts +2 -0
  30. package/dist/analyzer/languages/php.js +81 -0
  31. package/dist/analyzer/languages/python.d.ts +2 -0
  32. package/dist/analyzer/languages/python.js +180 -0
  33. package/dist/analyzer/languages/ruby.d.ts +2 -0
  34. package/dist/analyzer/languages/ruby.js +99 -0
  35. package/dist/analyzer/languages/rust.d.ts +2 -0
  36. package/dist/analyzer/languages/rust.js +164 -0
  37. package/dist/analyzer/languages/shared.d.ts +35 -0
  38. package/dist/analyzer/languages/shared.js +43 -0
  39. package/dist/analyzer/languages/types.d.ts +78 -0
  40. package/dist/analyzer/languages/types.js +2 -0
  41. package/dist/analyzer/pack-format.d.ts +27 -0
  42. package/dist/analyzer/pack-format.js +139 -0
  43. package/dist/analyzer/pack.d.ts +26 -0
  44. package/dist/analyzer/pack.js +498 -0
  45. package/dist/analyzer/relationships.d.ts +17 -0
  46. package/dist/analyzer/relationships.js +34 -0
  47. package/dist/analyzer/risk-rules.d.ts +287 -0
  48. package/dist/analyzer/risk-rules.js +373 -0
  49. package/dist/analyzer/risks.d.ts +36 -0
  50. package/dist/analyzer/risks.js +480 -0
  51. package/dist/analyzer/roles.d.ts +11 -0
  52. package/dist/analyzer/roles.js +280 -0
  53. package/dist/analyzer/scan.d.ts +26 -0
  54. package/dist/analyzer/scan.js +157 -0
  55. package/dist/analyzer/signals.d.ts +20 -0
  56. package/dist/analyzer/signals.js +51 -0
  57. package/dist/analyzer/symbol-changes.d.ts +11 -0
  58. package/dist/analyzer/symbol-changes.js +101 -0
  59. package/dist/analyzer/symbol-types.d.ts +17 -0
  60. package/dist/analyzer/symbol-types.js +9 -0
  61. package/dist/analyzer/symbols.d.ts +4 -0
  62. package/dist/analyzer/symbols.js +16 -0
  63. package/dist/analyzer/trivial.d.ts +13 -0
  64. package/dist/analyzer/trivial.js +137 -0
  65. package/dist/analyzer/util.d.ts +6 -0
  66. package/dist/analyzer/util.js +24 -0
  67. package/dist/cli/commands/authoring.d.ts +9 -0
  68. package/dist/cli/commands/authoring.js +98 -0
  69. package/dist/cli/commands/cache.d.ts +4 -0
  70. package/dist/cli/commands/cache.js +37 -0
  71. package/dist/cli/commands/doctor.d.ts +5 -0
  72. package/dist/cli/commands/doctor.js +37 -0
  73. package/dist/cli/commands/generate.d.ts +8 -0
  74. package/dist/cli/commands/generate.js +69 -0
  75. package/dist/cli/commands/jobs.d.ts +8 -0
  76. package/dist/cli/commands/jobs.js +70 -0
  77. package/dist/cli/commands/publish.d.ts +8 -0
  78. package/dist/cli/commands/publish.js +120 -0
  79. package/dist/cli/commands/serve.d.ts +4 -0
  80. package/dist/cli/commands/serve.js +69 -0
  81. package/dist/cli/commands/setup.d.ts +14 -0
  82. package/dist/cli/commands/setup.js +108 -0
  83. package/dist/cli/commands/shared.d.ts +18 -0
  84. package/dist/cli/commands/shared.js +24 -0
  85. package/dist/cli/files.d.ts +26 -0
  86. package/dist/cli/files.js +98 -0
  87. package/dist/cli/format.d.ts +55 -0
  88. package/dist/cli/format.js +295 -0
  89. package/dist/cli/inputs.d.ts +23 -0
  90. package/dist/cli/inputs.js +96 -0
  91. package/dist/cli/io.d.ts +19 -0
  92. package/dist/cli/io.js +31 -0
  93. package/dist/cli/main.d.ts +2 -0
  94. package/dist/cli/main.js +15 -0
  95. package/dist/cli/options.d.ts +105 -0
  96. package/dist/cli/options.js +324 -0
  97. package/dist/cli/program.d.ts +12 -0
  98. package/dist/cli/program.js +146 -0
  99. package/dist/cli/runtime.d.ts +59 -0
  100. package/dist/cli/runtime.js +83 -0
  101. package/dist/cli/style.d.ts +13 -0
  102. package/dist/cli/style.js +27 -0
  103. package/dist/core/binaries.d.ts +7 -0
  104. package/dist/core/binaries.js +33 -0
  105. package/dist/core/binary-paths.d.ts +5 -0
  106. package/dist/core/binary-paths.js +92 -0
  107. package/dist/core/cache.d.ts +14 -0
  108. package/dist/core/cache.js +43 -0
  109. package/dist/core/child-env.d.ts +9 -0
  110. package/dist/core/child-env.js +61 -0
  111. package/dist/core/concurrency.d.ts +13 -0
  112. package/dist/core/concurrency.js +58 -0
  113. package/dist/core/config.d.ts +223 -0
  114. package/dist/core/config.js +454 -0
  115. package/dist/core/context.d.ts +39 -0
  116. package/dist/core/context.js +44 -0
  117. package/dist/core/cost.d.ts +46 -0
  118. package/dist/core/cost.js +108 -0
  119. package/dist/core/diagram-metrics.d.ts +57 -0
  120. package/dist/core/diagram-metrics.js +63 -0
  121. package/dist/core/diff-view.d.ts +44 -0
  122. package/dist/core/diff-view.js +136 -0
  123. package/dist/core/errors.d.ts +47 -0
  124. package/dist/core/errors.js +94 -0
  125. package/dist/core/ids.d.ts +11 -0
  126. package/dist/core/ids.js +36 -0
  127. package/dist/core/json.d.ts +8 -0
  128. package/dist/core/json.js +17 -0
  129. package/dist/core/languages.d.ts +19 -0
  130. package/dist/core/languages.js +292 -0
  131. package/dist/core/logger.d.ts +29 -0
  132. package/dist/core/logger.js +68 -0
  133. package/dist/core/net.d.ts +16 -0
  134. package/dist/core/net.js +80 -0
  135. package/dist/core/path-policy.d.ts +20 -0
  136. package/dist/core/path-policy.js +202 -0
  137. package/dist/core/paths.d.ts +18 -0
  138. package/dist/core/paths.js +53 -0
  139. package/dist/core/posix.d.ts +12 -0
  140. package/dist/core/posix.js +50 -0
  141. package/dist/core/process.d.ts +22 -0
  142. package/dist/core/process.js +117 -0
  143. package/dist/core/providers.d.ts +204 -0
  144. package/dist/core/providers.js +2 -0
  145. package/dist/core/redact.d.ts +11 -0
  146. package/dist/core/redact.js +70 -0
  147. package/dist/core/render-plan.d.ts +307 -0
  148. package/dist/core/render-plan.js +7 -0
  149. package/dist/core/retry.d.ts +54 -0
  150. package/dist/core/retry.js +116 -0
  151. package/dist/core/run-folder.d.ts +74 -0
  152. package/dist/core/run-folder.js +129 -0
  153. package/dist/core/secrets.d.ts +56 -0
  154. package/dist/core/secrets.js +301 -0
  155. package/dist/core/storyboard-facts.d.ts +22 -0
  156. package/dist/core/storyboard-facts.js +61 -0
  157. package/dist/core/storyboard-schema.d.ts +1279 -0
  158. package/dist/core/storyboard-schema.js +342 -0
  159. package/dist/core/text.d.ts +43 -0
  160. package/dist/core/text.js +94 -0
  161. package/dist/core/types.d.ts +459 -0
  162. package/dist/core/types.js +17 -0
  163. package/dist/doctor/check.d.ts +6 -0
  164. package/dist/doctor/check.js +18 -0
  165. package/dist/doctor/deps.d.ts +2 -0
  166. package/dist/doctor/deps.js +90 -0
  167. package/dist/doctor/format.d.ts +9 -0
  168. package/dist/doctor/format.js +19 -0
  169. package/dist/doctor/github.d.ts +2 -0
  170. package/dist/doctor/github.js +13 -0
  171. package/dist/doctor/home.d.ts +2 -0
  172. package/dist/doctor/home.js +26 -0
  173. package/dist/doctor/index.d.ts +18 -0
  174. package/dist/doctor/index.js +81 -0
  175. package/dist/doctor/llm.d.ts +2 -0
  176. package/dist/doctor/llm.js +32 -0
  177. package/dist/doctor/publish.d.ts +2 -0
  178. package/dist/doctor/publish.js +16 -0
  179. package/dist/doctor/s3.d.ts +2 -0
  180. package/dist/doctor/s3.js +125 -0
  181. package/dist/doctor/speech.d.ts +2 -0
  182. package/dist/doctor/speech.js +112 -0
  183. package/dist/doctor/tools.d.ts +5 -0
  184. package/dist/doctor/tools.js +58 -0
  185. package/dist/doctor/types.d.ts +92 -0
  186. package/dist/doctor/types.js +2 -0
  187. package/dist/doctor/youtube.d.ts +2 -0
  188. package/dist/doctor/youtube.js +73 -0
  189. package/dist/github/client.d.ts +108 -0
  190. package/dist/github/client.js +499 -0
  191. package/dist/github/errors.d.ts +37 -0
  192. package/dist/github/errors.js +155 -0
  193. package/dist/github/index.d.ts +13 -0
  194. package/dist/github/index.js +9 -0
  195. package/dist/github/linked-issues.d.ts +37 -0
  196. package/dist/github/linked-issues.js +131 -0
  197. package/dist/github/model.d.ts +81 -0
  198. package/dist/github/model.js +114 -0
  199. package/dist/github/notify.d.ts +27 -0
  200. package/dist/github/notify.js +118 -0
  201. package/dist/github/pr-url.d.ts +27 -0
  202. package/dist/github/pr-url.js +122 -0
  203. package/dist/github/token.d.ts +16 -0
  204. package/dist/github/token.js +69 -0
  205. package/dist/index.d.ts +29 -0
  206. package/dist/index.js +19 -0
  207. package/dist/jobs/input-rules.d.ts +20 -0
  208. package/dist/jobs/input-rules.js +100 -0
  209. package/dist/jobs/model.d.ts +47 -0
  210. package/dist/jobs/model.js +18 -0
  211. package/dist/jobs/runner.d.ts +43 -0
  212. package/dist/jobs/runner.js +165 -0
  213. package/dist/jobs/store.d.ts +67 -0
  214. package/dist/jobs/store.js +314 -0
  215. package/dist/jobs/view.d.ts +48 -0
  216. package/dist/jobs/view.js +111 -0
  217. package/dist/jobs/worker.d.ts +24 -0
  218. package/dist/jobs/worker.js +47 -0
  219. package/dist/llm/anthropic.d.ts +11 -0
  220. package/dist/llm/anthropic.js +225 -0
  221. package/dist/llm/index.d.ts +10 -0
  222. package/dist/llm/index.js +27 -0
  223. package/dist/llm/openai-compatible.d.ts +33 -0
  224. package/dist/llm/openai-compatible.js +378 -0
  225. package/dist/llm/prices.d.ts +26 -0
  226. package/dist/llm/prices.js +41 -0
  227. package/dist/llm/shared.d.ts +30 -0
  228. package/dist/llm/shared.js +115 -0
  229. package/dist/narration/assemble.d.ts +36 -0
  230. package/dist/narration/assemble.js +282 -0
  231. package/dist/narration/audio.d.ts +61 -0
  232. package/dist/narration/audio.js +301 -0
  233. package/dist/narration/captions.d.ts +37 -0
  234. package/dist/narration/captions.js +195 -0
  235. package/dist/narration/chunking.d.ts +6 -0
  236. package/dist/narration/chunking.js +46 -0
  237. package/dist/narration/convert.d.ts +9 -0
  238. package/dist/narration/convert.js +90 -0
  239. package/dist/narration/elevenlabs.d.ts +5 -0
  240. package/dist/narration/elevenlabs.js +53 -0
  241. package/dist/narration/http-errors.d.ts +14 -0
  242. package/dist/narration/http-errors.js +74 -0
  243. package/dist/narration/index.d.ts +21 -0
  244. package/dist/narration/index.js +22 -0
  245. package/dist/narration/kokoro-install.d.ts +30 -0
  246. package/dist/narration/kokoro-install.js +284 -0
  247. package/dist/narration/kokoro-model.d.ts +54 -0
  248. package/dist/narration/kokoro-model.js +168 -0
  249. package/dist/narration/kokoro-plugin.d.ts +78 -0
  250. package/dist/narration/kokoro-plugin.js +245 -0
  251. package/dist/narration/kokoro.d.ts +22 -0
  252. package/dist/narration/kokoro.js +231 -0
  253. package/dist/narration/openai.d.ts +4 -0
  254. package/dist/narration/openai.js +54 -0
  255. package/dist/narration/pricing.d.ts +8 -0
  256. package/dist/narration/pricing.js +17 -0
  257. package/dist/narration/remote-speech.d.ts +53 -0
  258. package/dist/narration/remote-speech.js +100 -0
  259. package/dist/narration/say.d.ts +28 -0
  260. package/dist/narration/say.js +178 -0
  261. package/dist/narration/select.d.ts +27 -0
  262. package/dist/narration/select.js +80 -0
  263. package/dist/narration/silent.d.ts +2 -0
  264. package/dist/narration/silent.js +18 -0
  265. package/dist/narration/speakable.d.ts +20 -0
  266. package/dist/narration/speakable.js +398 -0
  267. package/dist/narration/synthesize.d.ts +25 -0
  268. package/dist/narration/synthesize.js +220 -0
  269. package/dist/narration/wav.d.ts +37 -0
  270. package/dist/narration/wav.js +170 -0
  271. package/dist/pipeline/authoring.d.ts +8 -0
  272. package/dist/pipeline/authoring.js +117 -0
  273. package/dist/pipeline/commands.d.ts +9 -0
  274. package/dist/pipeline/commands.js +21 -0
  275. package/dist/pipeline/fit-duration.d.ts +41 -0
  276. package/dist/pipeline/fit-duration.js +150 -0
  277. package/dist/pipeline/index.d.ts +9 -0
  278. package/dist/pipeline/index.js +9 -0
  279. package/dist/pipeline/inputs.d.ts +42 -0
  280. package/dist/pipeline/inputs.js +171 -0
  281. package/dist/pipeline/plan.d.ts +8 -0
  282. package/dist/pipeline/plan.js +85 -0
  283. package/dist/pipeline/planned-egress.d.ts +21 -0
  284. package/dist/pipeline/planned-egress.js +43 -0
  285. package/dist/pipeline/prepare.d.ts +26 -0
  286. package/dist/pipeline/prepare.js +84 -0
  287. package/dist/pipeline/presentation.d.ts +26 -0
  288. package/dist/pipeline/presentation.js +110 -0
  289. package/dist/pipeline/publish-run.d.ts +71 -0
  290. package/dist/pipeline/publish-run.js +295 -0
  291. package/dist/pipeline/run.d.ts +7 -0
  292. package/dist/pipeline/run.js +196 -0
  293. package/dist/pipeline/storyboard-choice.d.ts +34 -0
  294. package/dist/pipeline/storyboard-choice.js +129 -0
  295. package/dist/pipeline/types.d.ts +76 -0
  296. package/dist/pipeline/types.js +2 -0
  297. package/dist/publish/access-probe.d.ts +55 -0
  298. package/dist/publish/access-probe.js +249 -0
  299. package/dist/publish/bundle.d.ts +20 -0
  300. package/dist/publish/bundle.js +57 -0
  301. package/dist/publish/comment.d.ts +10 -0
  302. package/dist/publish/comment.js +184 -0
  303. package/dist/publish/content-types.d.ts +15 -0
  304. package/dist/publish/content-types.js +41 -0
  305. package/dist/publish/index.d.ts +18 -0
  306. package/dist/publish/index.js +30 -0
  307. package/dist/publish/keys.d.ts +10 -0
  308. package/dist/publish/keys.js +30 -0
  309. package/dist/publish/local.d.ts +33 -0
  310. package/dist/publish/local.js +143 -0
  311. package/dist/publish/privacy.d.ts +20 -0
  312. package/dist/publish/privacy.js +21 -0
  313. package/dist/publish/s3/bucket.d.ts +22 -0
  314. package/dist/publish/s3/bucket.js +82 -0
  315. package/dist/publish/s3/client.d.ts +33 -0
  316. package/dist/publish/s3/client.js +134 -0
  317. package/dist/publish/s3/failures.d.ts +22 -0
  318. package/dist/publish/s3/failures.js +110 -0
  319. package/dist/publish/s3/index.d.ts +5 -0
  320. package/dist/publish/s3/index.js +6 -0
  321. package/dist/publish/s3/links.d.ts +38 -0
  322. package/dist/publish/s3/links.js +60 -0
  323. package/dist/publish/s3/protected-links.d.ts +29 -0
  324. package/dist/publish/s3/protected-links.js +67 -0
  325. package/dist/publish/s3/publisher.d.ts +32 -0
  326. package/dist/publish/s3/publisher.js +123 -0
  327. package/dist/publish/s3/settings.d.ts +29 -0
  328. package/dist/publish/s3/settings.js +64 -0
  329. package/dist/publish/s3/upload.d.ts +29 -0
  330. package/dist/publish/s3/upload.js +145 -0
  331. package/dist/publish/severity.d.ts +9 -0
  332. package/dist/publish/severity.js +18 -0
  333. package/dist/publish/text.d.ts +23 -0
  334. package/dist/publish/text.js +94 -0
  335. package/dist/publish/types.d.ts +67 -0
  336. package/dist/publish/types.js +12 -0
  337. package/dist/publish/vtt.d.ts +9 -0
  338. package/dist/publish/vtt.js +43 -0
  339. package/dist/publish/watch-page.d.ts +4 -0
  340. package/dist/publish/watch-page.js +463 -0
  341. package/dist/publish/youtube/credentials.d.ts +33 -0
  342. package/dist/publish/youtube/credentials.js +162 -0
  343. package/dist/publish/youtube/description.d.ts +56 -0
  344. package/dist/publish/youtube/description.js +197 -0
  345. package/dist/publish/youtube/google-api.d.ts +95 -0
  346. package/dist/publish/youtube/google-api.js +339 -0
  347. package/dist/publish/youtube/index.d.ts +7 -0
  348. package/dist/publish/youtube/index.js +8 -0
  349. package/dist/publish/youtube/loopback.d.ts +13 -0
  350. package/dist/publish/youtube/loopback.js +144 -0
  351. package/dist/publish/youtube/oauth.d.ts +68 -0
  352. package/dist/publish/youtube/oauth.js +159 -0
  353. package/dist/publish/youtube/prompt.d.ts +27 -0
  354. package/dist/publish/youtube/prompt.js +94 -0
  355. package/dist/publish/youtube/publisher.d.ts +38 -0
  356. package/dist/publish/youtube/publisher.js +346 -0
  357. package/dist/publish/youtube/scopes.d.ts +32 -0
  358. package/dist/publish/youtube/scopes.js +55 -0
  359. package/dist/publish/youtube/sign-in.d.ts +37 -0
  360. package/dist/publish/youtube/sign-in.js +137 -0
  361. package/dist/publish/youtube/upload.d.ts +43 -0
  362. package/dist/publish/youtube/upload.js +210 -0
  363. package/dist/render/browser.d.ts +23 -0
  364. package/dist/render/browser.js +219 -0
  365. package/dist/render/chromium-renderer.d.ts +56 -0
  366. package/dist/render/chromium-renderer.js +519 -0
  367. package/dist/render/ffmpeg.d.ts +55 -0
  368. package/dist/render/ffmpeg.js +212 -0
  369. package/dist/render/fonts.d.ts +10 -0
  370. package/dist/render/fonts.js +42 -0
  371. package/dist/render/index.d.ts +9 -0
  372. package/dist/render/index.js +11 -0
  373. package/dist/render/page.d.ts +46 -0
  374. package/dist/render/page.js +123 -0
  375. package/dist/render/playwright.d.ts +3 -0
  376. package/dist/render/playwright.js +6 -0
  377. package/dist/render/runtime-bundle.d.ts +2 -0
  378. package/dist/render/runtime-bundle.js +72 -0
  379. package/dist/runtime/runtime.js +1626 -0
  380. package/dist/server/auth.d.ts +17 -0
  381. package/dist/server/auth.js +58 -0
  382. package/dist/server/http.d.ts +43 -0
  383. package/dist/server/http.js +119 -0
  384. package/dist/server/index.d.ts +46 -0
  385. package/dist/server/index.js +310 -0
  386. package/dist/server/queue.d.ts +30 -0
  387. package/dist/server/queue.js +76 -0
  388. package/dist/server/schema.d.ts +103 -0
  389. package/dist/server/schema.js +121 -0
  390. package/dist/server/source.d.ts +17 -0
  391. package/dist/server/source.js +100 -0
  392. package/dist/sources/assemble.d.ts +86 -0
  393. package/dist/sources/assemble.js +117 -0
  394. package/dist/sources/diff-parser.d.ts +14 -0
  395. package/dist/sources/diff-parser.js +84 -0
  396. package/dist/sources/git.d.ts +28 -0
  397. package/dist/sources/git.js +108 -0
  398. package/dist/sources/github.d.ts +20 -0
  399. package/dist/sources/github.js +192 -0
  400. package/dist/sources/hunk-selection.d.ts +25 -0
  401. package/dist/sources/hunk-selection.js +46 -0
  402. package/dist/sources/index.d.ts +23 -0
  403. package/dist/sources/index.js +62 -0
  404. package/dist/sources/limits.d.ts +27 -0
  405. package/dist/sources/limits.js +22 -0
  406. package/dist/sources/local.d.ts +34 -0
  407. package/dist/sources/local.js +555 -0
  408. package/dist/sources/reader.d.ts +13 -0
  409. package/dist/sources/reader.js +45 -0
  410. package/dist/sources/remote.d.ts +13 -0
  411. package/dist/sources/remote.js +41 -0
  412. package/dist/sources/repo-context.d.ts +34 -0
  413. package/dist/sources/repo-context.js +144 -0
  414. package/dist/sources/text.d.ts +25 -0
  415. package/dist/sources/text.js +71 -0
  416. package/dist/storyboard/authoring.d.ts +108 -0
  417. package/dist/storyboard/authoring.js +196 -0
  418. package/dist/storyboard/claims.d.ts +35 -0
  419. package/dist/storyboard/claims.js +318 -0
  420. package/dist/storyboard/coderef.d.ts +28 -0
  421. package/dist/storyboard/coderef.js +118 -0
  422. package/dist/storyboard/generate.d.ts +25 -0
  423. package/dist/storyboard/generate.js +194 -0
  424. package/dist/storyboard/heuristic-code.d.ts +91 -0
  425. package/dist/storyboard/heuristic-code.js +524 -0
  426. package/dist/storyboard/heuristic-context.d.ts +42 -0
  427. package/dist/storyboard/heuristic-context.js +102 -0
  428. package/dist/storyboard/heuristic-facts.d.ts +106 -0
  429. package/dist/storyboard/heuristic-facts.js +415 -0
  430. package/dist/storyboard/heuristic-overview.d.ts +4 -0
  431. package/dist/storyboard/heuristic-overview.js +151 -0
  432. package/dist/storyboard/heuristic-review.d.ts +10 -0
  433. package/dist/storyboard/heuristic-review.js +158 -0
  434. package/dist/storyboard/heuristic-scenes.d.ts +8 -0
  435. package/dist/storyboard/heuristic-scenes.js +357 -0
  436. package/dist/storyboard/heuristic-shared.d.ts +43 -0
  437. package/dist/storyboard/heuristic-shared.js +136 -0
  438. package/dist/storyboard/heuristic.d.ts +15 -0
  439. package/dist/storyboard/heuristic.js +324 -0
  440. package/dist/storyboard/identifiers.d.ts +51 -0
  441. package/dist/storyboard/identifiers.js +195 -0
  442. package/dist/storyboard/index.d.ts +10 -0
  443. package/dist/storyboard/index.js +10 -0
  444. package/dist/storyboard/prompts.d.ts +16 -0
  445. package/dist/storyboard/prompts.js +61 -0
  446. package/dist/storyboard/run.d.ts +82 -0
  447. package/dist/storyboard/run.js +332 -0
  448. package/dist/storyboard/text.d.ts +16 -0
  449. package/dist/storyboard/text.js +103 -0
  450. package/dist/storyboard/types.d.ts +47 -0
  451. package/dist/storyboard/types.js +2 -0
  452. package/dist/storyboard/urls.d.ts +15 -0
  453. package/dist/storyboard/urls.js +83 -0
  454. package/dist/storyboard/validate.d.ts +8 -0
  455. package/dist/storyboard/validate.js +525 -0
  456. package/dist/storyboard/visuals.d.ts +23 -0
  457. package/dist/storyboard/visuals.js +324 -0
  458. package/dist/version.d.ts +2 -0
  459. package/dist/version.js +3 -0
  460. package/dist/visuals/code.d.ts +68 -0
  461. package/dist/visuals/code.js +385 -0
  462. package/dist/visuals/highlight.d.ts +17 -0
  463. package/dist/visuals/highlight.js +85 -0
  464. package/dist/visuals/image.d.ts +12 -0
  465. package/dist/visuals/image.js +96 -0
  466. package/dist/visuals/index.d.ts +10 -0
  467. package/dist/visuals/index.js +10 -0
  468. package/dist/visuals/layout.d.ts +89 -0
  469. package/dist/visuals/layout.js +506 -0
  470. package/dist/visuals/plan.d.ts +33 -0
  471. package/dist/visuals/plan.js +511 -0
  472. package/dist/visuals/timeline.d.ts +31 -0
  473. package/dist/visuals/timeline.js +96 -0
  474. package/package.json +74 -4
@@ -0,0 +1,284 @@
1
+ /**
2
+ * Installing the Kokoro voice when a run needs it, one install at a time. Runs in one process
3
+ * (the server, the job runner, library callers) share one install. Separate processes take turns
4
+ * through a lock file in the MergeStory home, so two installs never write the plugin folder at once.
5
+ */
6
+ import { link, mkdir, open, readFile, rename, rm, stat } from 'node:fs/promises';
7
+ import { join } from 'node:path';
8
+ import { setTimeout as sleep } from 'node:timers/promises';
9
+ import { abortedError, assertNotAborted, MergeStoryError } from '../core/errors.js';
10
+ import { randomToken } from '../core/ids.js';
11
+ import { isKokoroModelCached, KOKORO_MODEL_HOST, kokoroDownloadMb, kokoroDtype, } from './kokoro-model.js';
12
+ import { installKokoro, isKokoroInstalled, KOKORO_INSTALL_TIMEOUT_MS, KOKORO_PACKAGES_HOST, KOKORO_PACKAGES_MB, kokoroManualInstall, kokoroStatus, pluginsDir, } from './kokoro-plugin.js';
13
+ export const KOKORO_INSTALL_LOCK = 'kokoro-install.lock';
14
+ /** A lock that cannot be read this long after it was written was left by a process that died while writing it. */
15
+ const UNREADABLE_LOCK_STALE_MS = 30_000;
16
+ /** Time after the install timeout before a lock counts as stale, so the holder's npm has stopped. */
17
+ const STALE_MARGIN_MS = 60_000;
18
+ function processAlive(pid) {
19
+ try {
20
+ process.kill(pid, 0);
21
+ return true;
22
+ }
23
+ catch (err) {
24
+ // EPERM: the process exists but belongs to another user.
25
+ return err.code === 'EPERM';
26
+ }
27
+ }
28
+ function lockPath(ctx) {
29
+ return join(ctx.home.home, KOKORO_INSTALL_LOCK);
30
+ }
31
+ function parseLock(text) {
32
+ try {
33
+ const value = JSON.parse(text);
34
+ if (Number.isInteger(value.pid) &&
35
+ value.pid > 0 &&
36
+ typeof value.startedAt === 'number' &&
37
+ typeof value.token === 'string') {
38
+ return value;
39
+ }
40
+ }
41
+ catch {
42
+ // not a lock this code wrote, or one that is still being written
43
+ }
44
+ return null;
45
+ }
46
+ /** A lock whose process has ended, or that is older than the longest install, is stale. */
47
+ async function isStale(path, text, deps) {
48
+ const now = (deps.now ?? Date.now)();
49
+ const info = parseLock(text);
50
+ if (!info) {
51
+ try {
52
+ return now - (await stat(path)).mtimeMs > UNREADABLE_LOCK_STALE_MS;
53
+ }
54
+ catch {
55
+ return true;
56
+ }
57
+ }
58
+ if (now - info.startedAt > KOKORO_INSTALL_TIMEOUT_MS + STALE_MARGIN_MS)
59
+ return true;
60
+ return !(deps.isAlive ?? processAlive)(info.pid);
61
+ }
62
+ /**
63
+ * Move a stale lock aside, so a new one can be created. The move is one step, so of two runs that
64
+ * both find the same stale lock only one moves it. If the lock moved aside turns out to be a new
65
+ * one (another run took over in between), it is put back.
66
+ * shortcut: while it is put back, a third run can create its own lock, so in that instant two runs could
67
+ * both hold it; this needs three runs at once on a lock left by a crash. Use an OS file lock if it is seen.
68
+ */
69
+ async function takeOver(path, staleText) {
70
+ const aside = `${path}.${randomToken(4)}.stale`;
71
+ try {
72
+ await rename(path, aside);
73
+ }
74
+ catch {
75
+ return; // already gone
76
+ }
77
+ try {
78
+ const moved = await readFile(aside, 'utf8').catch(() => '');
79
+ if (moved !== staleText)
80
+ await link(aside, path).catch(() => undefined);
81
+ }
82
+ finally {
83
+ await rm(aside, { force: true });
84
+ }
85
+ }
86
+ async function writeLock(path, info) {
87
+ let handle;
88
+ try {
89
+ // The exclusive flag: creating the file fails when it already exists.
90
+ handle = await open(path, 'wx', 0o600);
91
+ }
92
+ catch (err) {
93
+ if (err.code === 'EEXIST')
94
+ return false;
95
+ throw err;
96
+ }
97
+ try {
98
+ await handle.writeFile(JSON.stringify(info));
99
+ }
100
+ catch (err) {
101
+ await handle.close();
102
+ await rm(path, { force: true });
103
+ throw err;
104
+ }
105
+ await handle.close();
106
+ return true;
107
+ }
108
+ /** Take the install lock, waiting while a live process holds it. `waited` says whether it had to wait. */
109
+ async function acquire(ctx, deps) {
110
+ const path = lockPath(ctx);
111
+ const info = { pid: process.pid, startedAt: (deps.now ?? Date.now)(), token: randomToken(8) };
112
+ let waited = false;
113
+ await mkdir(ctx.home.home, { recursive: true, mode: 0o700 });
114
+ for (;;) {
115
+ assertNotAborted(ctx.signal);
116
+ // The lock's age counts from when it is taken, not from when this run began to wait.
117
+ info.startedAt = (deps.now ?? Date.now)();
118
+ if (await writeLock(path, info))
119
+ break;
120
+ const text = await readFile(path, 'utf8').catch(() => null);
121
+ if (text === null)
122
+ continue; // released in between
123
+ if (await isStale(path, text, deps)) {
124
+ await takeOver(path, text);
125
+ continue;
126
+ }
127
+ if (!waited) {
128
+ ctx.progress({
129
+ stage: 'narrate',
130
+ status: 'start',
131
+ message: 'Another MergeStory run is installing the Kokoro voice. Waiting for it to finish.',
132
+ });
133
+ waited = true;
134
+ }
135
+ try {
136
+ await sleep(deps.pollMs ?? 1000, undefined, { signal: ctx.signal });
137
+ }
138
+ catch (err) {
139
+ throw ctx.signal.aborted ? abortedError(err) : err;
140
+ }
141
+ }
142
+ return {
143
+ waited,
144
+ release: async () => {
145
+ const current = parseLock((await readFile(path, 'utf8').catch(() => null)) ?? '');
146
+ // Only our own lock: a stale one taken over by another run is no longer ours.
147
+ if (current?.token === info.token)
148
+ await rm(path, { force: true });
149
+ },
150
+ };
151
+ }
152
+ /**
153
+ * Run `install` while holding the install lock. After waiting for another process, the install it
154
+ * finished is used, not installed again.
155
+ */
156
+ async function underLock(ctx, deps, alwaysInstall, before) {
157
+ const lock = await acquire(ctx, deps);
158
+ try {
159
+ if ((!alwaysInstall || lock.waited) && (await isKokoroInstalled(ctx)))
160
+ return kokoroStatus(ctx);
161
+ await before();
162
+ return await (deps.install ?? installKokoro)(ctx, { platform: deps.platform });
163
+ }
164
+ finally {
165
+ await lock.release();
166
+ }
167
+ }
168
+ /** `mergestory setup kokoro`: install (or repair) the voice, taking turns with any run that installs it. */
169
+ export function setupKokoro(ctx, deps = {}) {
170
+ return underLock(ctx, deps, true, async () => undefined);
171
+ }
172
+ /** The error for a missing voice on Windows, where it cannot install itself yet. */
173
+ export function kokoroWindowsError(ctx) {
174
+ return new MergeStoryError('TTS_FAILED', 'The Kokoro voice is not installed, and it cannot install itself on Windows yet.', { hint: `${kokoroManualInstall(pluginsDir(ctx))} Or choose --tts none for this run.` });
175
+ }
176
+ function safeDtype() {
177
+ try {
178
+ return kokoroDtype();
179
+ }
180
+ catch {
181
+ // A bad MERGESTORY_KOKORO_DTYPE is reported when the voice is used.
182
+ return kokoroDtype({});
183
+ }
184
+ }
185
+ /** What the install downloads, in words: the packages, and the voice model unless it is there already. */
186
+ async function downloadsInWords(ctx) {
187
+ const dtype = safeDtype();
188
+ const packages = `about ${KOKORO_PACKAGES_MB} MB of packages from ${KOKORO_PACKAGES_HOST}`;
189
+ if (await isKokoroModelCached(ctx.home.models, dtype))
190
+ return packages;
191
+ return `${packages}, then the voice model (${kokoroDownloadMb(dtype)} MB) from ${KOKORO_MODEL_HOST}`;
192
+ }
193
+ /**
194
+ * For the dry-run plan: what the first real run does when the Kokoro voice is not installed yet,
195
+ * or null when it is installed.
196
+ */
197
+ export async function kokoroInstallNote(ctx) {
198
+ if (await isKokoroInstalled(ctx))
199
+ return null;
200
+ return ('The free Kokoro voice is not installed yet. The first real run installs it once: ' +
201
+ `${await downloadsInWords(ctx)}. Nothing from the change is sent.`);
202
+ }
203
+ /** The error a run stops with when the voice could not be installed. Never a silent fallback. */
204
+ function installFailed(err) {
205
+ const reason = (err instanceof Error ? err.message : String(err))
206
+ .replace(/^Installing the Kokoro voice failed: /, '')
207
+ .slice(0, 300);
208
+ // A failure that says itself what to do (a damaged MergeStory install) keeps its own advice.
209
+ const own = err instanceof MergeStoryError ? err.hint : undefined;
210
+ return new MergeStoryError('TTS_FAILED', `The free Kokoro voice could not be installed: ${reason}`, {
211
+ hint: `${own ?? 'Check the network and that npm works, then run `mergestory setup kokoro` to try again.'} Or choose --tts say (macOS) or --tts none for this run.`,
212
+ cause: err,
213
+ });
214
+ }
215
+ const inFlight = new Map();
216
+ /** Wait for `promise`, but stop waiting when this run is cancelled. */
217
+ function untilAborted(promise, signal) {
218
+ if (signal.aborted)
219
+ return Promise.reject(abortedError());
220
+ return new Promise((resolve, reject) => {
221
+ const onAbort = () => reject(abortedError());
222
+ signal.addEventListener('abort', onAbort, { once: true });
223
+ promise.then((value) => {
224
+ signal.removeEventListener('abort', onAbort);
225
+ resolve(value);
226
+ }, (err) => {
227
+ signal.removeEventListener('abort', onAbort);
228
+ reject(err);
229
+ });
230
+ });
231
+ }
232
+ /**
233
+ * Make sure the Kokoro voice is installed, installing it when it is not. Tells the person first
234
+ * what happens and how long it takes. A failure stops the run with TTS_FAILED.
235
+ */
236
+ export async function ensureKokoroInstalled(ctx, deps = {}) {
237
+ const dir = pluginsDir(ctx);
238
+ const platform = deps.platform ?? process.platform;
239
+ for (;;) {
240
+ if (await isKokoroInstalled(ctx))
241
+ return;
242
+ if (platform === 'win32')
243
+ throw kokoroWindowsError(ctx);
244
+ let entry = inFlight.get(dir);
245
+ if (entry) {
246
+ ctx.progress({
247
+ stage: 'narrate',
248
+ status: 'start',
249
+ message: 'Another run in this process is installing the Kokoro voice. Waiting for it to finish.',
250
+ });
251
+ }
252
+ else {
253
+ const promise = underLock(ctx, deps, false, async () => {
254
+ ctx.progress({
255
+ stage: 'narrate',
256
+ status: 'start',
257
+ message: 'The free Kokoro voice is not installed yet, so MergeStory installs it now. This happens once: ' +
258
+ `${await downloadsInWords(ctx)}. It takes a minute or two.`,
259
+ });
260
+ });
261
+ const created = { promise, signal: ctx.signal };
262
+ inFlight.set(dir, created);
263
+ const forget = () => {
264
+ if (inFlight.get(dir) === created)
265
+ inFlight.delete(dir);
266
+ };
267
+ promise.then(forget, forget);
268
+ entry = created;
269
+ }
270
+ try {
271
+ await untilAborted(entry.promise, ctx.signal);
272
+ return;
273
+ }
274
+ catch (err) {
275
+ if (ctx.signal.aborted)
276
+ throw abortedError(err);
277
+ // The run that was installing was cancelled, not this one: install again.
278
+ if (entry.signal !== ctx.signal && entry.signal.aborted)
279
+ continue;
280
+ throw installFailed(err);
281
+ }
282
+ }
283
+ }
284
+ //# sourceMappingURL=kokoro-install.js.map
@@ -0,0 +1,54 @@
1
+ export declare const KOKORO_MODEL_ID = "onnx-community/Kokoro-82M-v1.0-ONNX";
2
+ /** Hugging Face commit that the model files are pinned to. */
3
+ export declare const KOKORO_MODEL_REVISION = "1939ad2a8e416c0acfeecc08a694d14ef25f2231";
4
+ export declare const KOKORO_MODEL_HOST = "huggingface.co";
5
+ export type KokoroDtype = 'fp32' | 'q8';
6
+ export interface ModelFile {
7
+ /** Path inside the model repository. */
8
+ path: string;
9
+ bytes: number;
10
+ sha256: string;
11
+ }
12
+ /** Files needed for one precision. */
13
+ export declare function kokoroModelFiles(dtype: KokoroDtype): ModelFile[];
14
+ /** Size of the download for one precision, in megabytes (rounded). */
15
+ export declare function kokoroDownloadMb(dtype: KokoroDtype): number;
16
+ /**
17
+ * Precision to use. fp32 is two to three times faster on Apple Silicon; q8 is a much smaller
18
+ * download elsewhere. MERGESTORY_KOKORO_DTYPE overrides ("fp32" or "q8").
19
+ */
20
+ export declare function kokoroDtype(env?: NodeJS.ProcessEnv, platform?: NodeJS.Platform, arch?: string): KokoroDtype;
21
+ /** Folder inside the models folder where transformers.js looks for this model. */
22
+ export declare function kokoroModelDir(modelsRoot: string): string;
23
+ /** Cheap check for status displays: every file exists with the expected size (no hashing). */
24
+ export declare function isKokoroModelCached(modelsRoot: string, dtype: KokoroDtype): Promise<boolean>;
25
+ export interface DownloadProgress {
26
+ file: string;
27
+ loaded: number;
28
+ total: number;
29
+ }
30
+ export interface EnsureModelOptions {
31
+ modelsRoot: string;
32
+ /** Files to check, usually kokoroModelFiles(dtype). */
33
+ files: ModelFile[];
34
+ /** Base URL of the pinned model revision; defaults to the pinned Hugging Face commit. */
35
+ baseUrl?: string;
36
+ signal?: AbortSignal;
37
+ onProgress?: (progress: DownloadProgress) => void;
38
+ onDownloadStart?: (file: ModelFile) => void;
39
+ /** Retry settings for the HTTP request (tests use short delays). */
40
+ retry?: {
41
+ attempts?: number;
42
+ minDelayMs?: number;
43
+ maxDelayMs?: number;
44
+ };
45
+ }
46
+ /**
47
+ * Make sure every model file is present and matches its digest. Existing files are hashed
48
+ * (a few hundred milliseconds), so a damaged file is never loaded.
49
+ *
50
+ * Safe when several processes download at once: each one writes its own temporary file, checks
51
+ * its hash and renames it over the target in one step. The target is never deleted first, so a
52
+ * file that another process has just finished is never removed while it is being loaded.
53
+ */
54
+ export declare function ensureModelFiles(options: EnsureModelOptions): Promise<void>;
@@ -0,0 +1,168 @@
1
+ /**
2
+ * The Kokoro speech model files: where they live, how they are downloaded and how they are
3
+ * checked. Files come from one pinned Hugging Face commit and each one must match a known
4
+ * SHA-256 digest before it is used. A file that is missing or damaged is downloaded again; a
5
+ * download that does not match is refused.
6
+ */
7
+ import { createHash } from 'node:crypto';
8
+ import { createReadStream, createWriteStream } from 'node:fs';
9
+ import { mkdir, rename, rm, stat } from 'node:fs/promises';
10
+ import { dirname, join } from 'node:path';
11
+ import { Readable } from 'node:stream';
12
+ import { pipeline } from 'node:stream/promises';
13
+ import { MergeStoryError } from '../core/errors.js';
14
+ import { randomToken } from '../core/ids.js';
15
+ import { fetchWithRetry } from '../core/retry.js';
16
+ export const KOKORO_MODEL_ID = 'onnx-community/Kokoro-82M-v1.0-ONNX';
17
+ /** Hugging Face commit that the model files are pinned to. */
18
+ export const KOKORO_MODEL_REVISION = '1939ad2a8e416c0acfeecc08a694d14ef25f2231';
19
+ export const KOKORO_MODEL_HOST = 'huggingface.co';
20
+ const COMMON_FILES = [
21
+ {
22
+ path: 'config.json',
23
+ bytes: 44,
24
+ sha256: 'df34b4f930b23447cd4dc410fabfb42eb3f24e803e6c3f97d618fb359380a36f',
25
+ },
26
+ {
27
+ path: 'tokenizer.json',
28
+ bytes: 3497,
29
+ sha256: '77a02c8e164413299b4b4c403b14f8e0e1c1b727db4d46a09d6327b861060a34',
30
+ },
31
+ {
32
+ path: 'tokenizer_config.json',
33
+ bytes: 113,
34
+ sha256: 'be1cb066d6ef6b074b3f15e6a6dd21ac88ff3cdaedf325f0aaed686c70f75d20',
35
+ },
36
+ ];
37
+ const ONNX_FILES = {
38
+ fp32: {
39
+ path: 'onnx/model.onnx',
40
+ bytes: 325_532_232,
41
+ sha256: '8fbea51ea711f2af382e88c833d9e288c6dc82ce5e98421ea61c058ce21a34cb',
42
+ },
43
+ q8: {
44
+ path: 'onnx/model_quantized.onnx',
45
+ bytes: 92_361_116,
46
+ sha256: 'fbae9257e1e05ffc727e951ef9b9c98418e6d79f1c9b6b13bd59f5c9028a1478',
47
+ },
48
+ };
49
+ /** Files needed for one precision. */
50
+ export function kokoroModelFiles(dtype) {
51
+ return [...COMMON_FILES, ONNX_FILES[dtype]];
52
+ }
53
+ /** Size of the download for one precision, in megabytes (rounded). */
54
+ export function kokoroDownloadMb(dtype) {
55
+ return Math.round(ONNX_FILES[dtype].bytes / 1_000_000);
56
+ }
57
+ /**
58
+ * Precision to use. fp32 is two to three times faster on Apple Silicon; q8 is a much smaller
59
+ * download elsewhere. MERGESTORY_KOKORO_DTYPE overrides ("fp32" or "q8").
60
+ */
61
+ export function kokoroDtype(env = process.env, platform = process.platform, arch = process.arch) {
62
+ const requested = env.MERGESTORY_KOKORO_DTYPE?.trim().toLowerCase();
63
+ if (requested) {
64
+ if (requested === 'fp32' || requested === 'q8')
65
+ return requested;
66
+ throw new MergeStoryError('CONFIG_INVALID', `MERGESTORY_KOKORO_DTYPE must be "fp32" or "q8", not "${requested.slice(0, 20)}".`, {
67
+ hint: 'fp32 is faster and needs a 326 MB download; q8 needs 92 MB.',
68
+ });
69
+ }
70
+ return platform === 'darwin' && arch === 'arm64' ? 'fp32' : 'q8';
71
+ }
72
+ /** Folder inside the models folder where transformers.js looks for this model. */
73
+ export function kokoroModelDir(modelsRoot) {
74
+ return join(modelsRoot, ...KOKORO_MODEL_ID.split('/'));
75
+ }
76
+ /** Cheap check for status displays: every file exists with the expected size (no hashing). */
77
+ export async function isKokoroModelCached(modelsRoot, dtype) {
78
+ for (const file of kokoroModelFiles(dtype)) {
79
+ try {
80
+ const info = await stat(join(kokoroModelDir(modelsRoot), file.path));
81
+ if (info.size !== file.bytes)
82
+ return false;
83
+ }
84
+ catch {
85
+ return false;
86
+ }
87
+ }
88
+ return true;
89
+ }
90
+ async function sha256OfFile(path) {
91
+ const hash = createHash('sha256');
92
+ for await (const chunk of createReadStream(path))
93
+ hash.update(chunk);
94
+ return hash.digest('hex');
95
+ }
96
+ async function matchesExpected(path, file) {
97
+ try {
98
+ if ((await stat(path)).size !== file.bytes)
99
+ return false;
100
+ return (await sha256OfFile(path)) === file.sha256;
101
+ }
102
+ catch {
103
+ return false;
104
+ }
105
+ }
106
+ function checksumError(file) {
107
+ return new MergeStoryError('TTS_FAILED', `The downloaded Kokoro model file ${file.path} does not match its expected checksum, so it was not used.`, {
108
+ hint: 'Run again. If it keeps failing, the download source may be blocked or altered; use another speech provider.',
109
+ });
110
+ }
111
+ async function downloadVerified(file, target, options) {
112
+ const base = options.baseUrl ?? `https://${KOKORO_MODEL_HOST}/${KOKORO_MODEL_ID}/resolve/${KOKORO_MODEL_REVISION}`;
113
+ await mkdir(dirname(target), { recursive: true, mode: 0o700 });
114
+ const partial = `${target}.${randomToken(4)}.part`;
115
+ try {
116
+ const response = await fetchWithRetry(`${base}/${file.path}`, {}, { signal: options.signal, timeoutMs: 30 * 60_000, ...options.retry });
117
+ if (!response.body) {
118
+ throw new MergeStoryError('TTS_FAILED', 'The model download returned no data.', {
119
+ hint: 'Check the network connection and run again.',
120
+ });
121
+ }
122
+ const hash = createHash('sha256');
123
+ const total = Number(response.headers.get('content-length')) || file.bytes;
124
+ let loaded = 0;
125
+ await pipeline(Readable.fromWeb(response.body), async function* (chunks) {
126
+ for await (const chunk of chunks) {
127
+ hash.update(chunk);
128
+ loaded += chunk.length;
129
+ options.onProgress?.({ file: file.path, loaded, total });
130
+ yield chunk;
131
+ }
132
+ }, createWriteStream(partial, { mode: 0o600 }), options.signal ? { signal: options.signal } : {});
133
+ if (loaded !== file.bytes || hash.digest('hex') !== file.sha256)
134
+ throw checksumError(file);
135
+ await rename(partial, target);
136
+ }
137
+ finally {
138
+ await rm(partial, { force: true });
139
+ }
140
+ }
141
+ /**
142
+ * Make sure every model file is present and matches its digest. Existing files are hashed
143
+ * (a few hundred milliseconds), so a damaged file is never loaded.
144
+ *
145
+ * Safe when several processes download at once: each one writes its own temporary file, checks
146
+ * its hash and renames it over the target in one step. The target is never deleted first, so a
147
+ * file that another process has just finished is never removed while it is being loaded.
148
+ */
149
+ export async function ensureModelFiles(options) {
150
+ for (const file of options.files) {
151
+ const target = join(kokoroModelDir(options.modelsRoot), file.path);
152
+ if (await matchesExpected(target, file))
153
+ continue;
154
+ options.onDownloadStart?.(file);
155
+ try {
156
+ await downloadVerified(file, target, options);
157
+ }
158
+ catch (err) {
159
+ if (err instanceof MergeStoryError || options.signal?.aborted)
160
+ throw err;
161
+ throw new MergeStoryError('TTS_FAILED', `The Kokoro voice model could not be downloaded: ${err.message}`, {
162
+ hint: `The first run needs access to ${KOKORO_MODEL_HOST}. Check the network, or use another speech provider with --tts.`,
163
+ cause: err,
164
+ });
165
+ }
166
+ }
167
+ }
168
+ //# sourceMappingURL=kokoro-model.js.map
@@ -0,0 +1,78 @@
1
+ import type { RunContext } from '../core/context.ts';
2
+ import { runCommand } from '../core/process.ts';
3
+ export interface LocalVoiceStatus {
4
+ installed: boolean;
5
+ /** Plugin directory under $MERGESTORY_HOME. */
6
+ location: string;
7
+ version: string | null;
8
+ modelCached: boolean;
9
+ }
10
+ /**
11
+ * Exact versions of the plugin packages. The packages they depend on are pinned by the lockfile
12
+ * that ships with MergeStory (KOKORO_PLUGIN_LOCKFILE), which `npm ci` installs exactly, with an
13
+ * integrity hash for every package.
14
+ */
15
+ export declare const KOKORO_PLUGIN_PACKAGES: {
16
+ readonly '@huggingface/transformers': '3.8.1';
17
+ readonly 'kokoro-js': '1.2.1';
18
+ readonly phonemizer: '1.2.1';
19
+ };
20
+ /**
21
+ * Packages held at a newer version than the plugin packages ask for. transformers.js pulls in the
22
+ * image library sharp, which speech never uses; this release carries the security fixes of the
23
+ * image libraries bundled with it.
24
+ */
25
+ export declare const KOKORO_PLUGIN_OVERRIDES: {
26
+ readonly sharp: '0.35.5';
27
+ };
28
+ /** The plugin's package-lock.json, in the assets folder of the MergeStory package. */
29
+ export declare const KOKORO_PLUGIN_LOCKFILE: string;
30
+ /**
31
+ * A short fingerprint of the shipped lockfile. The completion marker keeps it, so an install made
32
+ * from an older lockfile (for example one with a package that has since been fixed) counts as out
33
+ * of date and is installed again.
34
+ */
35
+ export declare function kokoroLockFingerprint(): string;
36
+ /**
37
+ * Written last by an install. A plugin folder without it, or with another version in it, is an
38
+ * install that was cut off (killed, crashed, disk full) or is out of date, so it counts as missing.
39
+ */
40
+ export declare const KOKORO_INSTALLED_MARKER = "mergestory-kokoro-installed.json";
41
+ /** Where the plugin packages are downloaded from (the hosts in the shipped lockfile). */
42
+ export declare const KOKORO_PACKAGES_HOST = "registry.npmjs.org";
43
+ /** Rough size of the plugin packages, in megabytes. */
44
+ export declare const KOKORO_PACKAGES_MB = 400;
45
+ /** The longest an install may take. A lock older than this belongs to an install that hung. */
46
+ export declare const KOKORO_INSTALL_TIMEOUT_MS: number;
47
+ export declare function pluginsDir(ctx: Pick<RunContext, 'home'>): string;
48
+ /**
49
+ * Version of the installed plugin, or null when it is not installed: the packages are missing,
50
+ * the completion marker is missing, either one is not the pinned version, or the install was made
51
+ * from another lockfile.
52
+ */
53
+ export declare function installedKokoroVersion(dir: string): Promise<string | null>;
54
+ /** Whether the Kokoro voice is installed and complete. */
55
+ export declare function isKokoroInstalled(ctx: Pick<RunContext, 'home'>): Promise<boolean>;
56
+ /** Write the loader module if it is missing or out of date. Returns its path. */
57
+ export declare function ensureLoaderFile(dir: string): Promise<string>;
58
+ export declare function kokoroStatus(ctx: RunContext): Promise<LocalVoiceStatus>;
59
+ /** What a finished install writes last: the pinned version and the lockfile it was made from. */
60
+ export declare function completionMarker(): {
61
+ version: string;
62
+ lock: string;
63
+ };
64
+ /** How to install the plugin by hand, where the automatic install is not available. */
65
+ export declare function kokoroManualInstall(dir: string): string;
66
+ export interface InstallDeps {
67
+ run?: typeof runCommand;
68
+ platform?: NodeJS.Platform;
69
+ }
70
+ /** The shipped lockfile, after checking that it locks exactly the pinned packages. */
71
+ export declare function readKokoroLockfile(path?: string): Promise<string>;
72
+ /**
73
+ * Install the locked Kokoro packages into the plugin folder with `npm ci`, which installs exactly
74
+ * the package tree of the shipped lockfile and checks every download against its hash. Install
75
+ * scripts are skipped: the ONNX runtime ships its CPU binaries inside the package (its script only
76
+ * fetches optional GPU libraries), and the image library is not used for speech.
77
+ */
78
+ export declare function installKokoro(ctx: RunContext, deps?: InstallDeps): Promise<LocalVoiceStatus>;