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,10 @@
1
+ /** The review scene: what the author asks to check and what the analysis flags, with values and places. */
2
+ import { type ReviewItem, type Scene } from '../core/storyboard-schema.ts';
3
+ import { type Build } from './heuristic-shared.ts';
4
+ export interface Review {
5
+ scene: Scene;
6
+ items: ReviewItem[];
7
+ firstSubject: string | null;
8
+ firstEvidence: string[];
9
+ }
10
+ export declare function reviewScene(b: Build): Review | null;
@@ -0,0 +1,158 @@
1
+ /** The review scene: what the author asks to check and what the analysis flags, with values and places. */
2
+ import { changedLinesAt, shrinkRange } from '../core/diff-view.js';
3
+ import { isShowable } from '../core/path-policy.js';
4
+ import { basename } from '../core/posix.js';
5
+ import { STORYBOARD_LIMITS as LIMITS, } from '../core/storyboard-schema.js';
6
+ import { naturalList, plural } from '../core/text.js';
7
+ import { proseName, sideFor } from './heuristic-code.js';
8
+ import { cite, safeText } from './heuristic-context.js';
9
+ import { affectedNames, dependencySentences, numericFacts, numericSentences, reviewHint, } from './heuristic-facts.js';
10
+ import { fitWords, scene, sizeText, topFiles } from './heuristic-shared.js';
11
+ import { ordinal, truncateText } from './text.js';
12
+ // ---------------------------------------------------------------------------
13
+ // Review
14
+ // ---------------------------------------------------------------------------
15
+ const SEVERITY_ORDER = { high: 0, medium: 1, low: 2, info: 3 };
16
+ /** Among risks of one severity, the ones with values or names to say come first. */
17
+ function concreteness(risk) {
18
+ return numericFacts(risk).length > 0 || affectedNames(risk).length > 0 ? 0 : 1;
19
+ }
20
+ /** A reference that the validator will accept: a changed file that can be shown, on a side that exists. */
21
+ function safeRef(ctx, ref) {
22
+ if (!ref)
23
+ return null;
24
+ const file = ctx.fileByPath.get(ref.path) ?? ctx.changeSet.files.find((f) => f.oldPath === ref.path);
25
+ if (!file || !isShowable(file) || ref.startLine < 1 || ref.endLine < ref.startLine)
26
+ return null;
27
+ const side = sideFor(file, ref.side);
28
+ const [start, end] = shrinkRange(ref.startLine, ref.endLine, LIMITS.maxCodeLines, changedLinesAt(file, side), null);
29
+ return { path: file.path, side, startLine: start, endLine: end };
30
+ }
31
+ function shortDetail(ctx, text) {
32
+ const clean = safeText(ctx, text) ?? '';
33
+ // The detail may end with values such as "retries: new value 3", which are lower case after the full stop.
34
+ const first = clean.length <= 160 ? clean : (clean.split(/(?<=[.!?])\s+(?=[A-Z0-9])/)[0] ?? clean);
35
+ return truncateText(first, 160);
36
+ }
37
+ /** Where a risk sits, as a name that may be said: the symbol it was found in, or else the file. */
38
+ function placeOf(ctx, risk, ref) {
39
+ for (const id of risk.evidence) {
40
+ const symbol = ctx.analysis.symbols.find((s) => s.id === id);
41
+ const name = symbol ? safeText(ctx, symbol.name) : null;
42
+ const file = symbol ? ctx.fileById.get(symbol.fileId) : undefined;
43
+ if (symbol && name && file && isShowable(file))
44
+ return proseName(symbol.kind, name);
45
+ }
46
+ return ref ? basename(ref.path) : null;
47
+ }
48
+ function riskSentence(ctx, risk, item, index) {
49
+ const affected = affectedNames(risk)
50
+ .map((name) => safeText(ctx, name))
51
+ .filter((name) => name !== null);
52
+ const values = numericFacts(risk);
53
+ const found = affected.length > 0 ? null : placeOf(ctx, risk, item.ref);
54
+ // "in TOKEN_TTL_SECONDS" adds nothing when the next sentence says what TOKEN_TTL_SECONDS is set to.
55
+ const place = found !== null && values.some((fact) => fact.name === found) ? null : found;
56
+ const rated = risk.severity === 'high' || risk.severity === 'medium';
57
+ const facts = numericSentences(values, null);
58
+ const extras = [
59
+ ...(affected.length > 0 ? [`It affects ${naturalList(affected.slice(0, 3))}.`] : []),
60
+ ...facts,
61
+ ...dependencySentences(risk, (name) => safeText(ctx, name)),
62
+ ];
63
+ const head = `${ordinal(index)}: ${item.title}${place ? `, in ${place}` : ''}.${rated ? ` The analysis rates it ${risk.severity}.` : ''}`;
64
+ // Every line stays within the limit for a caption: the values and names that do not fit are left out.
65
+ return fitWords([head, ...extras], LIMITS.maxWordsPerNarrationLine);
66
+ }
67
+ export function reviewScene(b) {
68
+ const { ctx, level } = b;
69
+ const hint = level.quotes ? reviewHint(ctx) : null;
70
+ const risks = [...ctx.analysis.risks]
71
+ .sort((a, z) => SEVERITY_ORDER[a.severity] - SEVERITY_ORDER[z.severity] ||
72
+ concreteness(a) - concreteness(z) ||
73
+ a.id.localeCompare(z.id))
74
+ .slice(0, Math.min(level.reviewItems - (hint ? 1 : 0), LIMITS.maxChecklistItems));
75
+ if (risks.length > 0 || hint) {
76
+ const items = [];
77
+ const lines = [];
78
+ // The line that names each item: the checklist shows an item when its line is spoken.
79
+ const beats = [];
80
+ const riskItems = risks.map((risk) => ({
81
+ title: truncateText(safeText(ctx, risk.title) ?? `Check the ${risk.category} signal`, 80),
82
+ detail: shortDetail(ctx, risk.detail),
83
+ severity: risk.severity,
84
+ ref: safeRef(ctx, risk.ref),
85
+ evidence: cite(ctx, risk.id, ...risk.evidence.slice(0, 2)),
86
+ }));
87
+ if (risks.length > 0) {
88
+ const counts = ['high', 'medium', 'low', 'info']
89
+ .map((severity) => [severity, risks.filter((risk) => risk.severity === severity).length])
90
+ .filter(([, count]) => count > 0)
91
+ .map(([severity, count]) => `${count} ${severity}`);
92
+ const total = ctx.analysis.risks.length;
93
+ lines.push({
94
+ text: `The analysis found ${plural(total, 'review signal')}${total === risks.length && total > 1 ? `: ${naturalList(counts)}` : ''}.`,
95
+ evidence: cite(ctx, ...risks.slice(0, 3).map((risk) => risk.id)),
96
+ });
97
+ }
98
+ if (hint) {
99
+ b.quoted = true;
100
+ items.push({
101
+ title: hint.title,
102
+ detail: hint.detail,
103
+ severity: 'medium',
104
+ ref: null,
105
+ evidence: cite(ctx, hint.source),
106
+ });
107
+ beats.push(lines.length);
108
+ lines.push({
109
+ text: `${hint.stripped ? 'The notes flag this for review' : 'The notes say'}: ${hint.spoken}`,
110
+ evidence: cite(ctx, hint.source),
111
+ });
112
+ }
113
+ items.push(...riskItems);
114
+ risks.forEach((risk, index) => {
115
+ const item = riskItems[index];
116
+ beats.push(lines.length);
117
+ lines.push({ text: riskSentence(ctx, risk, item, index), evidence: item.evidence });
118
+ });
119
+ const visualItems = items.map((item, index) => ({ ...item, beat: beats[index] ?? 0 }));
120
+ return {
121
+ scene: scene('review', 'What to review', lines, { type: 'checklist', items: visualItems }, 'A checklist of the points to review, with the author notes and the signals the analysis flags.', 'fade'),
122
+ items,
123
+ firstSubject: items[0].title,
124
+ firstEvidence: items[0].evidence,
125
+ };
126
+ }
127
+ const files = topFiles(ctx, Math.min(level.reviewItems, 3));
128
+ if (files.length === 0)
129
+ return null;
130
+ const items = files.map((file) => {
131
+ const hunk = ctx.analysis.keyHunks.find((k) => k.fileId === file.id);
132
+ return {
133
+ title: `Largest change: ${basename(file.path)}`,
134
+ detail: sizeText(file.additions, file.deletions) === 'no changed lines'
135
+ ? 'The file was renamed or moved.'
136
+ : `${sizeText(file.additions, file.deletions)}.`,
137
+ severity: 'info',
138
+ ref: hunk
139
+ ? safeRef(ctx, { path: file.path, side: hunk.side, startLine: hunk.startLine, endLine: hunk.endLine })
140
+ : null,
141
+ evidence: cite(ctx, file.id, hunk?.id),
142
+ };
143
+ });
144
+ const names = files.map((file) => basename(file.path));
145
+ const lines = [
146
+ {
147
+ text: `The largest changes are in ${naturalList(names)}.`,
148
+ evidence: cite(ctx, ...files.map((f) => f.id)),
149
+ },
150
+ ];
151
+ return {
152
+ scene: scene('review', 'What to review', lines, { type: 'checklist', items: items.map((item) => ({ ...item, beat: 0 })) }, 'A checklist of the largest changes to read first.', 'fade'),
153
+ items,
154
+ firstSubject: names[0] ?? null,
155
+ firstEvidence: items[0].evidence,
156
+ };
157
+ }
158
+ //# sourceMappingURL=heuristic-review.js.map
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The code scenes: a window of code around the most important symbol of a hunk, or the old and new
3
+ * lines of one small modified function side by side. The narration says only what the lines on
4
+ * screen show.
5
+ */
6
+ import { type Scene } from '../core/storyboard-schema.ts';
7
+ import { type Build } from './heuristic-shared.ts';
8
+ export declare function codeScenes(b: Build): Scene[];
@@ -0,0 +1,357 @@
1
+ /**
2
+ * The code scenes: a window of code around the most important symbol of a hunk, or the old and new
3
+ * lines of one small modified function side by side. The narration says only what the lines on
4
+ * screen show.
5
+ */
6
+ import { changedLinesAt } from '../core/diff-view.js';
7
+ import { basename } from '../core/posix.js';
8
+ import { STORYBOARD_LIMITS as LIMITS } from '../core/storyboard-schema.js';
9
+ import { naturalList, plural } from '../core/text.js';
10
+ import { beforeAfterOf, callNames, changedRuns, declarationEnd, findReferences, planWindows, proseName, SYMBOL_WORD, sideLines, } from './heuristic-code.js';
11
+ import { cite, symbolName } from './heuristic-context.js';
12
+ import { numericFacts, numericSentences, pickStatement, quoteLine, } from './heuristic-facts.js';
13
+ import { scene, sizeText } from './heuristic-shared.js';
14
+ import { capitalise, escapeRegExp, truncateText } from './text.js';
15
+ // ---------------------------------------------------------------------------
16
+ // Code scenes
17
+ // ---------------------------------------------------------------------------
18
+ const CHANGE_LABEL = {
19
+ added: 'New',
20
+ modified: 'Changed',
21
+ removed: 'Removed',
22
+ };
23
+ /** "exported" in languages that have exports, "public" in the others. */
24
+ function visibility(path) {
25
+ return /\.(?:[mc]?[jt]sx?|go)$/i.test(path) ? 'exported' : 'public';
26
+ }
27
+ function anchorText(b, lead, view, path) {
28
+ const { symbol, name } = view;
29
+ const word = SYMBOL_WORD[symbol.kind];
30
+ const note = b.ctx.config.style === 'product' || !symbol.exported ? null : visibility(path);
31
+ if (symbol.change === 'added')
32
+ return `${lead}, the ${word} ${name} is new${note ? ` and ${note}` : ''}.`;
33
+ if (symbol.change === 'modified')
34
+ return `${lead}, the ${word} ${name} was changed${note ? ` and is ${note}` : ''}.`;
35
+ return `${lead}, the ${word} ${name} was removed.${note ? ` It was ${note}.` : ''}`;
36
+ }
37
+ /** The other symbols on screen, grouped by what happened to them. */
38
+ function othersText(views) {
39
+ const phrase = {
40
+ added: ['is new', 'are new'],
41
+ modified: ['was changed', 'were changed'],
42
+ removed: ['was removed', 'were removed'],
43
+ };
44
+ const sentences = [];
45
+ for (const change of ['added', 'modified', 'removed']) {
46
+ const group = views.filter((view) => view.symbol.change === change);
47
+ if (group.length === 0)
48
+ continue;
49
+ const names = naturalList(group.map((view) => `the ${SYMBOL_WORD[view.symbol.kind]} ${view.name}`));
50
+ sentences.push(`${capitalise(names)} ${phrase[change][group.length === 1 ? 0 : 1]} too.`);
51
+ }
52
+ return sentences.join(' ');
53
+ }
54
+ /** The name that starts a sentence. A name from code keeps its case: "withRetry calls ...", not "WithRetry". */
55
+ function sentenceSubject(view) {
56
+ const subject = proseName(view.symbol.kind, view.name);
57
+ return subject.startsWith('the ') ? capitalise(subject) : subject;
58
+ }
59
+ /** What the symbol `subject` calls, creates and uses. The line names its subject: another line may come before it. */
60
+ function referencesText(subject, references) {
61
+ const sentences = [];
62
+ for (const kind of ['calls', 'creates', 'uses']) {
63
+ const group = references.filter((reference) => reference.kind === kind);
64
+ if (group.length === 0)
65
+ continue;
66
+ sentences.push(`${sentences.length > 0 ? 'It also' : subject} ${kind} ${naturalList(group.map((r) => r.name))}.`);
67
+ }
68
+ return sentences.join(' ');
69
+ }
70
+ /** The lines to highlight for a symbol: all of it when it is short, otherwise its declaration or its changed lines. */
71
+ function symbolFocus(lines, changed, view, window) {
72
+ const { startLine, endLine } = view.symbol;
73
+ const first = Math.max(startLine, window.from);
74
+ const last = Math.min(endLine, window.to);
75
+ const note = `${CHANGE_LABEL[view.symbol.change]} ${SYMBOL_WORD[view.symbol.kind]} ${view.name}`;
76
+ if (last - first + 1 <= 4)
77
+ return { startLine: first, endLine: last, note };
78
+ if (startLine >= window.from) {
79
+ return { startLine, endLine: Math.min(declarationEnd(lines, view.symbol), window.to), note };
80
+ }
81
+ // The signature is off screen: point at the first lines this change touches.
82
+ const run = changedRuns(changed, first, last)[0];
83
+ return run
84
+ ? { startLine: run[0], endLine: Math.min(run[1], run[0] + 5), note }
85
+ : { startLine: first, endLine: first, note };
86
+ }
87
+ /** One highlight per line that mentions other changed symbols, with the symbols in its note. */
88
+ function referenceFocus(references) {
89
+ const byLine = new Map();
90
+ for (const reference of references) {
91
+ byLine.set(reference.line, [...(byLine.get(reference.line) ?? []), reference]);
92
+ }
93
+ return [...byLine.entries()]
94
+ .sort(([a], [z]) => a - z)
95
+ .map(([line, group]) => {
96
+ const kinds = ['calls', 'creates', 'uses'];
97
+ const note = kinds
98
+ .map((kind) => [kind, group.filter((reference) => reference.kind === kind)])
99
+ .filter(([, found]) => found.length > 0)
100
+ .map(([kind, found]) => `${capitalise(kind)} ${naturalList(found.map((reference) => reference.name))}`)
101
+ .join('; ');
102
+ return { startLine: line, endLine: line, note };
103
+ });
104
+ }
105
+ /**
106
+ * Values the analysis found on a line that is on screen, as sentences about the symbol that holds
107
+ * them. A value outside every symbol on screen (a top-level constant) belongs to the file.
108
+ */
109
+ function valuesOnScreen(ctx, window) {
110
+ if (window.side !== 'head')
111
+ return null;
112
+ for (const risk of ctx.analysis.risks) {
113
+ const ref = risk.ref;
114
+ if (ref?.side !== 'head' || ref.path !== window.file.path)
115
+ continue;
116
+ if (ref.startLine < window.from || ref.startLine > window.to)
117
+ continue;
118
+ const facts = numericFacts(risk);
119
+ if (facts.length === 0)
120
+ continue;
121
+ const subject = window.inView.find((view) => view.symbol.startLine <= ref.startLine && view.symbol.endLine >= ref.startLine) ?? null;
122
+ return {
123
+ risk,
124
+ sentences: numericSentences(facts, subject?.name ?? basename(window.file.path)),
125
+ line: ref.startLine,
126
+ subject,
127
+ };
128
+ }
129
+ return null;
130
+ }
131
+ /** The first line on screen that mentions a name as a whole word, or null. */
132
+ function firstLineWith(lines, window, name) {
133
+ const word = new RegExp(`(?<![\\w$])${escapeRegExp(name)}(?![\\w$])`);
134
+ for (let n = window.from; n <= window.to; n++) {
135
+ if (word.test(lines.text.get(n) ?? ''))
136
+ return n;
137
+ }
138
+ return null;
139
+ }
140
+ function codeScene(b, window, shown) {
141
+ const { ctx, level } = b;
142
+ const { file, keyHunk, side } = window;
143
+ const name = basename(file.path);
144
+ const sourceLines = sideLines(file, side);
145
+ const changed = changedLinesAt(file, side);
146
+ const lead = shown.has(file.id) ? `Also in ${name}` : `In ${name}`;
147
+ shown.add(file.id);
148
+ const drafts = [];
149
+ let title;
150
+ let description;
151
+ const anchor = window.anchor;
152
+ if (anchor === null) {
153
+ const hunk = file.hunks.find((h) => h.id === keyHunk.id);
154
+ const adds = hunk ? hunk.lines.filter((l) => l.kind === 'add').length : 0;
155
+ const dels = hunk ? hunk.lines.filter((l) => l.kind === 'del').length : 0;
156
+ drafts.push({
157
+ text: file.status === 'deleted'
158
+ ? `${name} is deleted, which removes ${plural(dels, 'line')}.`
159
+ : `${name} changes here, with ${sizeText(adds, dels)}.`,
160
+ evidence: cite(ctx, keyHunk.id, file.id),
161
+ focus: changedRuns(changed, window.from, window.to)
162
+ .slice(0, 3)
163
+ .map(([a, z]) => ({ startLine: a, endLine: z, note: null })),
164
+ priority: 0,
165
+ order: 0,
166
+ });
167
+ title = lead.startsWith('Also') ? `More in ${name}` : `Inside ${name}`;
168
+ description = `The ${window.mode === 'diff' ? 'diff' : 'code'} of ${name} with the changed lines highlighted.`;
169
+ }
170
+ else {
171
+ const hunkId = keyHunk.id;
172
+ drafts.push({
173
+ text: anchorText(b, lead, anchor, file.path),
174
+ evidence: cite(ctx, hunkId, anchor.symbol.id),
175
+ focus: [symbolFocus(sourceLines, changed, anchor, window)],
176
+ priority: 0,
177
+ order: 0,
178
+ });
179
+ const others = window.inView.filter((view) => view !== anchor);
180
+ if (others.length > 0) {
181
+ drafts.push({
182
+ text: othersText(others),
183
+ evidence: cite(ctx, hunkId, ...others.map((view) => view.symbol.id)),
184
+ focus: others.map((view) => symbolFocus(sourceLines, changed, view, window)),
185
+ priority: 1,
186
+ order: 1,
187
+ });
188
+ }
189
+ const references = findReferences(ctx, file, anchor, window);
190
+ if (references.length > 0) {
191
+ drafts.push({
192
+ text: referencesText(sentenceSubject(anchor), references),
193
+ evidence: cite(ctx, hunkId, anchor.symbol.id, ...references.map((r) => r.symbol.id)),
194
+ focus: referenceFocus(references),
195
+ priority: 4,
196
+ order: 2,
197
+ });
198
+ }
199
+ const values = valuesOnScreen(ctx, window);
200
+ if (values) {
201
+ drafts.push({
202
+ text: values.sentences.join(' '),
203
+ evidence: cite(ctx, values.risk.id, hunkId, values.subject?.symbol.id ?? anchor.symbol.id),
204
+ focus: [{ startLine: values.line, endLine: values.line, note: 'Values found by the analysis' }],
205
+ priority: 2,
206
+ order: 3,
207
+ });
208
+ }
209
+ if (level.quotes) {
210
+ const text = [];
211
+ for (let n = window.from; n <= window.to; n++)
212
+ text.push(sourceLines.text.get(n) ?? '');
213
+ const names = window.inView.flatMap((view) => [view.name, ...view.name.split('.')]);
214
+ const match = pickStatement(b.statements, { code: text.join('\n'), names }, b.used);
215
+ if (match) {
216
+ // Point at a name from the code first; the symbols' own names are marked by their declarations.
217
+ const symbolNames = new Set(names);
218
+ const mentioned = [...match.shared].sort((a, z) => Number(symbolNames.has(a)) - Number(symbolNames.has(z)));
219
+ const hit = mentioned
220
+ .map((shared) => ({ shared, line: firstLineWith(sourceLines, window, shared) }))
221
+ .find((found) => found.line !== null);
222
+ drafts.push({
223
+ ...quoteLine(ctx, match.statement, hunkId, anchor.symbol.id),
224
+ focus: hit?.line
225
+ ? [
226
+ {
227
+ startLine: hit.line,
228
+ endLine: hit.line,
229
+ note: `Notes mention ${hit.shared}`,
230
+ optional: true,
231
+ },
232
+ ]
233
+ : [],
234
+ priority: 3,
235
+ order: 4,
236
+ quote: match,
237
+ });
238
+ }
239
+ }
240
+ title = truncateText(`${anchor.name} in ${name}`, LIMITS.maxTitleLength);
241
+ description = `The code of ${anchor.name} in ${name}, with the lines that matter highlighted in turn.`;
242
+ }
243
+ // Keep the most useful lines when there is not room for all of them, in reading order.
244
+ const max = Math.max(1, level.codeLines);
245
+ const kept = (drafts.length <= max ? drafts : [...drafts].sort((a, z) => a.priority - z.priority).slice(0, max)).sort((a, z) => a.order - z.order);
246
+ for (const draft of kept) {
247
+ if (draft.quote) {
248
+ b.used.add(draft.quote.statement.full);
249
+ b.quoted = true;
250
+ }
251
+ }
252
+ const clipped = kept.flatMap((draft, index) => draft.focus.flatMap((f) => {
253
+ const startLine = Math.max(window.from, Math.min(f.startLine, f.endLine));
254
+ const endLine = Math.min(window.to, Math.max(f.startLine, f.endLine));
255
+ return startLine <= endLine
256
+ ? [{ startLine, endLine, note: f.note, beat: index, optional: f.optional }]
257
+ : [];
258
+ }));
259
+ const focus = clipped
260
+ .filter((f) => !f.optional ||
261
+ !clipped.some((o) => o !== f && !o.optional && o.startLine <= f.startLine && o.endLine >= f.endLine))
262
+ .map(({ optional: _optional, ...f }) => f);
263
+ const ref = { path: file.path, side, startLine: window.from, endLine: window.to };
264
+ return scene('under-the-hood', title, kept.map((draft) => ({ text: draft.text, evidence: draft.evidence })), { type: 'code', ref, mode: window.mode, focus, caption: null }, description, 'slide');
265
+ }
266
+ /** The before and after of the one function a window is about, when it is a modified function that is small enough. */
267
+ function singleFunction(window) {
268
+ const { anchor } = window;
269
+ if (anchor === null || window.inView.length !== 1 || window.inView[0] !== anchor)
270
+ return null;
271
+ return beforeAfterOf(window.file, anchor);
272
+ }
273
+ function beforeAfterScene(b, ba) {
274
+ const { ctx, level } = b;
275
+ const { file, view } = ba;
276
+ const { symbol, name } = view;
277
+ const word = SYMBOL_WORD[symbol.kind];
278
+ const adds = changedLinesAt(file, 'head').filter((n) => n >= ba.head[0] && n <= ba.head[1]).length;
279
+ const dels = changedLinesAt(file, 'base').filter((n) => n >= ba.base[0] && n <= ba.base[1]).length;
280
+ const baseLength = ba.base[1] - ba.base[0] + 1;
281
+ const headLength = ba.head[1] - ba.head[0] + 1;
282
+ const hunkIds = file.hunks
283
+ .filter((h) => h.newStart <= ba.head[1] && h.newStart + Math.max(h.newLines, 1) - 1 >= ba.head[0])
284
+ .map((h) => h.id);
285
+ // What the two versions call, as far as the changed lines show it.
286
+ const headRange = { from: ba.head[0], to: ba.head[1] };
287
+ const baseRange = { from: ba.base[0], to: ba.base[1] };
288
+ const headLines = sideLines(file, 'head');
289
+ const baseLines = sideLines(file, 'base');
290
+ const own = name.split('.').pop() ?? name;
291
+ const headCalls = new Set(callNames(headLines, headRange, ['add', 'ctx']));
292
+ const baseCalls = new Set(callNames(baseLines, baseRange, ['del', 'ctx']));
293
+ const newCalls = callNames(headLines, headRange, ['add'])
294
+ .filter((call) => !baseCalls.has(call) && call !== own)
295
+ .slice(0, 3);
296
+ const oldCalls = callNames(baseLines, baseRange, ['del'])
297
+ .filter((call) => !headCalls.has(call) && call !== own)
298
+ .slice(0, 3);
299
+ // A call that is a symbol of this change is cited, unless that symbol lives in a file that may not be shown.
300
+ const idsOf = (calls) => calls.flatMap((call) => ctx.analysis.symbols.filter((s) => s.name === call && symbolName(ctx, s) !== null).map((s) => s.id));
301
+ const lines = [
302
+ {
303
+ text: oldCalls.length > 0
304
+ ? `Before, the ${word} ${name} called ${naturalList(oldCalls)}.`
305
+ : `Before, the ${word} ${name} was ${plural(baseLength, 'line')} long.`,
306
+ evidence: cite(ctx, ...hunkIds.slice(0, 2), symbol.id, ...idsOf(oldCalls)),
307
+ },
308
+ {
309
+ text: newCalls.length > 0
310
+ ? `Now it calls ${naturalList(newCalls)}${oldCalls.length > 0 ? ' instead' : ''}.`
311
+ : `Now it is ${plural(headLength, 'line')} long, with ${sizeText(adds, dels)} in it.`,
312
+ evidence: cite(ctx, ...hunkIds.slice(0, 2), symbol.id, ...idsOf(newCalls)),
313
+ },
314
+ ];
315
+ if (level.codeLines >= 3 && (oldCalls.length > 0 || newCalls.length > 0)) {
316
+ lines.push({
317
+ text: baseLength === headLength
318
+ ? `It is still ${plural(headLength, 'line')} long.`
319
+ : `It went from ${baseLength} to ${plural(headLength, 'line')}.`,
320
+ evidence: cite(ctx, ...hunkIds.slice(0, 2), symbol.id),
321
+ });
322
+ }
323
+ const panel = (label, side, range) => ({
324
+ label,
325
+ kind: 'code',
326
+ codeRef: { path: file.path, side, startLine: range[0], endLine: range[1] },
327
+ bullets: [],
328
+ terminal: [],
329
+ screenshotId: null,
330
+ });
331
+ return scene('before-after', truncateText(`${name} before and after`, LIMITS.maxTitleLength), lines, {
332
+ type: 'before-after',
333
+ before: panel('Before', 'base', ba.base),
334
+ after: panel('After', 'head', ba.head),
335
+ caption: null,
336
+ }, `The old and the new version of ${name} side by side.`, 'slide');
337
+ }
338
+ export function codeScenes(b) {
339
+ const { ctx, level } = b;
340
+ const shown = new Set();
341
+ const scenes = [];
342
+ let beforeAfter = false;
343
+ for (const window of planWindows(ctx, level.codeScenes)) {
344
+ // One small modified function is clearer as two panels than as a window of code.
345
+ const ba = beforeAfter ? null : singleFunction(window);
346
+ if (ba) {
347
+ beforeAfter = true;
348
+ shown.add(window.file.id);
349
+ scenes.push(beforeAfterScene(b, ba));
350
+ }
351
+ else {
352
+ scenes.push(codeScene(b, window, shown));
353
+ }
354
+ }
355
+ return scenes;
356
+ }
357
+ //# sourceMappingURL=heuristic-scenes.js.map
@@ -0,0 +1,43 @@
1
+ /**
2
+ * What the scene builders of the offline storyboard share: the settings of a level, the state of one
3
+ * attempt, and the wording for files and components.
4
+ */
5
+ import type { NodeKind, Scene } from '../core/storyboard-schema.ts';
6
+ import type { ChangedFile, Component, ComponentKind } from '../core/types.ts';
7
+ import { type Ctx, type Line } from './heuristic-context.ts';
8
+ import type { Statement } from './heuristic-facts.ts';
9
+ export interface Level {
10
+ codeScenes: number;
11
+ /** The most narration lines one code scene may have. */
12
+ codeLines: number;
13
+ reviewItems: number;
14
+ missionLines: number;
15
+ bigPictureLines: number;
16
+ conclusionLines: number;
17
+ /** Quote the notes and the description next to the code they mention. */
18
+ quotes: boolean;
19
+ }
20
+ /** State for one attempt at one level. */
21
+ export interface Build {
22
+ ctx: Ctx;
23
+ level: Level;
24
+ statements: Statement[];
25
+ /** Statements that are already quoted somewhere, by their text. */
26
+ used: Set<string>;
27
+ quoted: boolean;
28
+ }
29
+ /** Files worth talking about, biggest change first. */
30
+ export declare function topFiles(ctx: Ctx, count: number): ChangedFile[];
31
+ export declare function meaningfulComponents(ctx: Ctx): Component[];
32
+ export declare const NODE_KIND: Record<ComponentKind, NodeKind>;
33
+ export declare function componentName(ctx: Ctx, component: Component): string;
34
+ /** "the http module", "the docs", "the project files". */
35
+ export declare function componentPhrase(ctx: Ctx, component: Component): string;
36
+ export declare function sizeText(additions: number, deletions: number): string;
37
+ /** "retry.ts, which is new, with 36 lines added". */
38
+ export declare function fileClause(file: ChangedFile): string;
39
+ /** "retry.ts (new, 36 lines added)": a short mention in a list. */
40
+ export declare function fileBrief(file: ChangedFile): string;
41
+ export declare function scene(role: Scene['role'], title: string, lines: Line[], visual: Scene['visual'], description: string, transition: Scene['transition']): Scene;
42
+ /** The sentences joined, as many as fit in `max` words. The first one always stays. */
43
+ export declare function fitWords(sentences: readonly string[], max: number): string;