openhorse 0.1.5

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 (587) hide show
  1. package/README.md +460 -0
  2. package/bin/openhorse +56 -0
  3. package/dist/agents/coder.d.ts +12 -0
  4. package/dist/agents/coder.d.ts.map +1 -0
  5. package/dist/agents/coder.js +48 -0
  6. package/dist/agents/coder.js.map +1 -0
  7. package/dist/agents/leader.d.ts +12 -0
  8. package/dist/agents/leader.d.ts.map +1 -0
  9. package/dist/agents/leader.js +49 -0
  10. package/dist/agents/leader.js.map +1 -0
  11. package/dist/agents/router.d.ts +59 -0
  12. package/dist/agents/router.d.ts.map +1 -0
  13. package/dist/agents/router.js +193 -0
  14. package/dist/agents/router.js.map +1 -0
  15. package/dist/cli-ink.d.ts +7 -0
  16. package/dist/cli-ink.d.ts.map +1 -0
  17. package/dist/cli-ink.js +135 -0
  18. package/dist/cli-ink.js.map +1 -0
  19. package/dist/cli.d.ts +7 -0
  20. package/dist/cli.d.ts.map +1 -0
  21. package/dist/cli.js +638 -0
  22. package/dist/cli.js.map +1 -0
  23. package/dist/commands/index.d.ts +12 -0
  24. package/dist/commands/index.d.ts.map +1 -0
  25. package/dist/commands/index.js +1095 -0
  26. package/dist/commands/index.js.map +1 -0
  27. package/dist/commands/parser.d.ts +26 -0
  28. package/dist/commands/parser.d.ts.map +1 -0
  29. package/dist/commands/parser.js +61 -0
  30. package/dist/commands/parser.js.map +1 -0
  31. package/dist/commands/types.d.ts +61 -0
  32. package/dist/commands/types.d.ts.map +1 -0
  33. package/dist/commands/types.js +32 -0
  34. package/dist/commands/types.js.map +1 -0
  35. package/dist/core/agent.d.ts +66 -0
  36. package/dist/core/agent.d.ts.map +1 -0
  37. package/dist/core/agent.js +55 -0
  38. package/dist/core/agent.js.map +1 -0
  39. package/dist/core/brain.d.ts +41 -0
  40. package/dist/core/brain.d.ts.map +1 -0
  41. package/dist/core/brain.js +92 -0
  42. package/dist/core/brain.js.map +1 -0
  43. package/dist/core/cost-tracker.d.ts +107 -0
  44. package/dist/core/cost-tracker.d.ts.map +1 -0
  45. package/dist/core/cost-tracker.js +199 -0
  46. package/dist/core/cost-tracker.js.map +1 -0
  47. package/dist/core/strategy-tracker.d.ts +61 -0
  48. package/dist/core/strategy-tracker.d.ts.map +1 -0
  49. package/dist/core/strategy-tracker.js +124 -0
  50. package/dist/core/strategy-tracker.js.map +1 -0
  51. package/dist/framework/index.d.ts +20 -0
  52. package/dist/framework/index.d.ts.map +1 -0
  53. package/dist/framework/index.js +29 -0
  54. package/dist/framework/index.js.map +1 -0
  55. package/dist/framework/prompt.d.ts +40 -0
  56. package/dist/framework/prompt.d.ts.map +1 -0
  57. package/dist/framework/prompt.js +112 -0
  58. package/dist/framework/prompt.js.map +1 -0
  59. package/dist/framework/query.d.ts +86 -0
  60. package/dist/framework/query.d.ts.map +1 -0
  61. package/dist/framework/query.js +177 -0
  62. package/dist/framework/query.js.map +1 -0
  63. package/dist/framework/store.d.ts +64 -0
  64. package/dist/framework/store.d.ts.map +1 -0
  65. package/dist/framework/store.js +78 -0
  66. package/dist/framework/store.js.map +1 -0
  67. package/dist/framework/tool-state.d.ts +22 -0
  68. package/dist/framework/tool-state.d.ts.map +1 -0
  69. package/dist/framework/tool-state.js +40 -0
  70. package/dist/framework/tool-state.js.map +1 -0
  71. package/dist/framework/tool.d.ts +88 -0
  72. package/dist/framework/tool.d.ts.map +1 -0
  73. package/dist/framework/tool.js +60 -0
  74. package/dist/framework/tool.js.map +1 -0
  75. package/dist/harness/harness.d.ts +96 -0
  76. package/dist/harness/harness.d.ts.map +1 -0
  77. package/dist/harness/harness.js +224 -0
  78. package/dist/harness/harness.js.map +1 -0
  79. package/dist/harness/safety.d.ts +89 -0
  80. package/dist/harness/safety.d.ts.map +1 -0
  81. package/dist/harness/safety.js +178 -0
  82. package/dist/harness/safety.js.map +1 -0
  83. package/dist/index.d.ts +30 -0
  84. package/dist/index.d.ts.map +1 -0
  85. package/dist/index.js +57 -0
  86. package/dist/index.js.map +1 -0
  87. package/dist/init.d.ts +178 -0
  88. package/dist/init.d.ts.map +1 -0
  89. package/dist/init.js +473 -0
  90. package/dist/init.js.map +1 -0
  91. package/dist/ink/bidi.d.ts +16 -0
  92. package/dist/ink/bidi.d.ts.map +1 -0
  93. package/dist/ink/bidi.js +124 -0
  94. package/dist/ink/bidi.js.map +1 -0
  95. package/dist/ink/clearTerminal.d.ts +14 -0
  96. package/dist/ink/clearTerminal.d.ts.map +1 -0
  97. package/dist/ink/clearTerminal.js +63 -0
  98. package/dist/ink/clearTerminal.js.map +1 -0
  99. package/dist/ink/colorize.d.ts +17 -0
  100. package/dist/ink/colorize.d.ts.map +1 -0
  101. package/dist/ink/colorize.js +208 -0
  102. package/dist/ink/colorize.js.map +1 -0
  103. package/dist/ink/components/App.d.ts +73 -0
  104. package/dist/ink/components/App.d.ts.map +1 -0
  105. package/dist/ink/components/App.js +646 -0
  106. package/dist/ink/components/App.js.map +1 -0
  107. package/dist/ink/components/AppContext.d.ts +12 -0
  108. package/dist/ink/components/AppContext.d.ts.map +1 -0
  109. package/dist/ink/components/AppContext.js +14 -0
  110. package/dist/ink/components/AppContext.js.map +1 -0
  111. package/dist/ink/components/Box.d.ts +44 -0
  112. package/dist/ink/components/Box.d.ts.map +1 -0
  113. package/dist/ink/components/Box.js +191 -0
  114. package/dist/ink/components/Box.js.map +1 -0
  115. package/dist/ink/components/ClockContext.d.ts +9 -0
  116. package/dist/ink/components/ClockContext.d.ts.map +1 -0
  117. package/dist/ink/components/ClockContext.js +146 -0
  118. package/dist/ink/components/ClockContext.js.map +1 -0
  119. package/dist/ink/components/CursorDeclarationContext.d.ts +23 -0
  120. package/dist/ink/components/CursorDeclarationContext.d.ts.map +1 -0
  121. package/dist/ink/components/CursorDeclarationContext.js +6 -0
  122. package/dist/ink/components/CursorDeclarationContext.js.map +1 -0
  123. package/dist/ink/components/ErrorOverview.d.ts +6 -0
  124. package/dist/ink/components/ErrorOverview.d.ts.map +1 -0
  125. package/dist/ink/components/ErrorOverview.js +27 -0
  126. package/dist/ink/components/ErrorOverview.js.map +1 -0
  127. package/dist/ink/components/Newline.d.ts +13 -0
  128. package/dist/ink/components/Newline.d.ts.map +1 -0
  129. package/dist/ink/components/Newline.js +36 -0
  130. package/dist/ink/components/Newline.js.map +1 -0
  131. package/dist/ink/components/NoSelect.d.ts +20 -0
  132. package/dist/ink/components/NoSelect.d.ts.map +1 -0
  133. package/dist/ink/components/NoSelect.js +63 -0
  134. package/dist/ink/components/NoSelect.js.map +1 -0
  135. package/dist/ink/components/RawAnsi.d.ts +17 -0
  136. package/dist/ink/components/RawAnsi.d.ts.map +1 -0
  137. package/dist/ink/components/RawAnsi.js +52 -0
  138. package/dist/ink/components/RawAnsi.js.map +1 -0
  139. package/dist/ink/components/Spacer.d.ts +6 -0
  140. package/dist/ink/components/Spacer.d.ts.map +1 -0
  141. package/dist/ink/components/Spacer.js +26 -0
  142. package/dist/ink/components/Spacer.js.map +1 -0
  143. package/dist/ink/components/StdinContext.d.ts +28 -0
  144. package/dist/ink/components/StdinContext.d.ts.map +1 -0
  145. package/dist/ink/components/StdinContext.js +19 -0
  146. package/dist/ink/components/StdinContext.js.map +1 -0
  147. package/dist/ink/components/TerminalFocusContext.d.ts +10 -0
  148. package/dist/ink/components/TerminalFocusContext.d.ts.map +1 -0
  149. package/dist/ink/components/TerminalFocusContext.js +81 -0
  150. package/dist/ink/components/TerminalFocusContext.js.map +1 -0
  151. package/dist/ink/components/TerminalSizeContext.d.ts +6 -0
  152. package/dist/ink/components/TerminalSizeContext.d.ts.map +1 -0
  153. package/dist/ink/components/TerminalSizeContext.js +6 -0
  154. package/dist/ink/components/TerminalSizeContext.js.map +1 -0
  155. package/dist/ink/components/Text.d.ts +56 -0
  156. package/dist/ink/components/Text.d.ts.map +1 -0
  157. package/dist/ink/components/Text.js +201 -0
  158. package/dist/ink/components/Text.js.map +1 -0
  159. package/dist/ink/constants.d.ts +2 -0
  160. package/dist/ink/constants.d.ts.map +1 -0
  161. package/dist/ink/constants.js +6 -0
  162. package/dist/ink/constants.js.map +1 -0
  163. package/dist/ink/devtools.d.ts +3 -0
  164. package/dist/ink/devtools.d.ts.map +1 -0
  165. package/dist/ink/devtools.js +5 -0
  166. package/dist/ink/devtools.js.map +1 -0
  167. package/dist/ink/dom.d.ts +77 -0
  168. package/dist/ink/dom.d.ts.map +1 -0
  169. package/dist/ink/dom.js +322 -0
  170. package/dist/ink/dom.js.map +1 -0
  171. package/dist/ink/events/click-event.d.ts +32 -0
  172. package/dist/ink/events/click-event.d.ts.map +1 -0
  173. package/dist/ink/events/click-event.js +30 -0
  174. package/dist/ink/events/click-event.js.map +1 -0
  175. package/dist/ink/events/dispatcher.d.ts +41 -0
  176. package/dist/ink/events/dispatcher.d.ts.map +1 -0
  177. package/dist/ink/events/dispatcher.js +181 -0
  178. package/dist/ink/events/dispatcher.js.map +1 -0
  179. package/dist/ink/events/emitter.d.ts +6 -0
  180. package/dist/ink/events/emitter.d.ts.map +1 -0
  181. package/dist/ink/events/emitter.js +36 -0
  182. package/dist/ink/events/emitter.js.map +1 -0
  183. package/dist/ink/events/event-handlers.d.ts +47 -0
  184. package/dist/ink/events/event-handlers.d.ts.map +1 -0
  185. package/dist/ink/events/event-handlers.js +34 -0
  186. package/dist/ink/events/event-handlers.js.map +1 -0
  187. package/dist/ink/events/event.d.ts +6 -0
  188. package/dist/ink/events/event.d.ts.map +1 -0
  189. package/dist/ink/events/event.js +16 -0
  190. package/dist/ink/events/event.js.map +1 -0
  191. package/dist/ink/events/focus-event.d.ts +14 -0
  192. package/dist/ink/events/focus-event.d.ts.map +1 -0
  193. package/dist/ink/events/focus-event.js +20 -0
  194. package/dist/ink/events/focus-event.js.map +1 -0
  195. package/dist/ink/events/input-event.d.ts +31 -0
  196. package/dist/ink/events/input-event.d.ts.map +1 -0
  197. package/dist/ink/events/input-event.js +163 -0
  198. package/dist/ink/events/input-event.js.map +1 -0
  199. package/dist/ink/events/keyboard-event.d.ts +20 -0
  200. package/dist/ink/events/keyboard-event.d.ts.map +1 -0
  201. package/dist/ink/events/keyboard-event.js +44 -0
  202. package/dist/ink/events/keyboard-event.js.map +1 -0
  203. package/dist/ink/events/terminal-event.d.ts +55 -0
  204. package/dist/ink/events/terminal-event.d.ts.map +1 -0
  205. package/dist/ink/events/terminal-event.js +79 -0
  206. package/dist/ink/events/terminal-event.js.map +1 -0
  207. package/dist/ink/events/terminal-focus-event.d.ts +14 -0
  208. package/dist/ink/events/terminal-focus-event.d.ts.map +1 -0
  209. package/dist/ink/events/terminal-focus-event.js +19 -0
  210. package/dist/ink/events/terminal-focus-event.js.map +1 -0
  211. package/dist/ink/focus.d.ts +44 -0
  212. package/dist/ink/focus.d.ts.map +1 -0
  213. package/dist/ink/focus.js +164 -0
  214. package/dist/ink/focus.js.map +1 -0
  215. package/dist/ink/frame.d.ts +95 -0
  216. package/dist/ink/frame.d.ts.map +1 -0
  217. package/dist/ink/frame.js +35 -0
  218. package/dist/ink/frame.js.map +1 -0
  219. package/dist/ink/get-max-width.d.ts +18 -0
  220. package/dist/ink/get-max-width.d.ts.map +1 -0
  221. package/dist/ink/get-max-width.js +26 -0
  222. package/dist/ink/get-max-width.js.map +1 -0
  223. package/dist/ink/hit-test.d.ts +34 -0
  224. package/dist/ink/hit-test.d.ts.map +1 -0
  225. package/dist/ink/hit-test.js +119 -0
  226. package/dist/ink/hit-test.js.map +1 -0
  227. package/dist/ink/hooks/use-animation-frame.d.ts +27 -0
  228. package/dist/ink/hooks/use-animation-frame.d.ts.map +1 -0
  229. package/dist/ink/hooks/use-animation-frame.js +52 -0
  230. package/dist/ink/hooks/use-animation-frame.js.map +1 -0
  231. package/dist/ink/hooks/use-app.d.ts +6 -0
  232. package/dist/ink/hooks/use-app.d.ts.map +1 -0
  233. package/dist/ink/hooks/use-app.js +13 -0
  234. package/dist/ink/hooks/use-app.js.map +1 -0
  235. package/dist/ink/hooks/use-declared-cursor.d.ts +27 -0
  236. package/dist/ink/hooks/use-declared-cursor.d.ts.map +1 -0
  237. package/dist/ink/hooks/use-declared-cursor.js +67 -0
  238. package/dist/ink/hooks/use-declared-cursor.js.map +1 -0
  239. package/dist/ink/hooks/use-input.d.ts +38 -0
  240. package/dist/ink/hooks/use-input.d.ts.map +1 -0
  241. package/dist/ink/hooks/use-input.js +86 -0
  242. package/dist/ink/hooks/use-input.js.map +1 -0
  243. package/dist/ink/hooks/use-interval.d.ts +19 -0
  244. package/dist/ink/hooks/use-interval.d.ts.map +1 -0
  245. package/dist/ink/hooks/use-interval.js +59 -0
  246. package/dist/ink/hooks/use-interval.js.map +1 -0
  247. package/dist/ink/hooks/use-search-highlight.d.ts +31 -0
  248. package/dist/ink/hooks/use-search-highlight.d.ts.map +1 -0
  249. package/dist/ink/hooks/use-search-highlight.js +39 -0
  250. package/dist/ink/hooks/use-search-highlight.js.map +1 -0
  251. package/dist/ink/hooks/use-selection.d.ts +40 -0
  252. package/dist/ink/hooks/use-selection.d.ts.map +1 -0
  253. package/dist/ink/hooks/use-selection.js +68 -0
  254. package/dist/ink/hooks/use-selection.js.map +1 -0
  255. package/dist/ink/hooks/use-stdin.d.ts +6 -0
  256. package/dist/ink/hooks/use-stdin.d.ts.map +1 -0
  257. package/dist/ink/hooks/use-stdin.js +13 -0
  258. package/dist/ink/hooks/use-stdin.js.map +1 -0
  259. package/dist/ink/hooks/use-tab-status.d.ts +14 -0
  260. package/dist/ink/hooks/use-tab-status.d.ts.map +1 -0
  261. package/dist/ink/hooks/use-tab-status.js +61 -0
  262. package/dist/ink/hooks/use-tab-status.js.map +1 -0
  263. package/dist/ink/hooks/use-terminal-focus.d.ts +11 -0
  264. package/dist/ink/hooks/use-terminal-focus.d.ts.map +1 -0
  265. package/dist/ink/hooks/use-terminal-focus.js +22 -0
  266. package/dist/ink/hooks/use-terminal-focus.js.map +1 -0
  267. package/dist/ink/hooks/use-terminal-title.d.ts +13 -0
  268. package/dist/ink/hooks/use-terminal-title.d.ts.map +1 -0
  269. package/dist/ink/hooks/use-terminal-title.js +36 -0
  270. package/dist/ink/hooks/use-terminal-title.js.map +1 -0
  271. package/dist/ink/hooks/use-terminal-viewport.d.ts +30 -0
  272. package/dist/ink/hooks/use-terminal-viewport.d.ts.map +1 -0
  273. package/dist/ink/hooks/use-terminal-viewport.js +81 -0
  274. package/dist/ink/hooks/use-terminal-viewport.js.map +1 -0
  275. package/dist/ink/index.d.ts +54 -0
  276. package/dist/ink/index.d.ts.map +1 -0
  277. package/dist/ink/index.js +111 -0
  278. package/dist/ink/index.js.map +1 -0
  279. package/dist/ink/ink.d.ts +371 -0
  280. package/dist/ink/ink.d.ts.map +1 -0
  281. package/dist/ink/ink.js +1686 -0
  282. package/dist/ink/ink.js.map +1 -0
  283. package/dist/ink/instances.d.ts +4 -0
  284. package/dist/ink/instances.d.ts.map +1 -0
  285. package/dist/ink/instances.js +10 -0
  286. package/dist/ink/instances.js.map +1 -0
  287. package/dist/ink/line-width-cache.d.ts +2 -0
  288. package/dist/ink/line-width-cache.d.ts.map +1 -0
  289. package/dist/ink/line-width-cache.js +23 -0
  290. package/dist/ink/line-width-cache.js.map +1 -0
  291. package/dist/ink/log-update.d.ts +18 -0
  292. package/dist/ink/log-update.d.ts.map +1 -0
  293. package/dist/ink/log-update.js +637 -0
  294. package/dist/ink/log-update.js.map +1 -0
  295. package/dist/ink/measure-element.d.ts +17 -0
  296. package/dist/ink/measure-element.d.ts.map +1 -0
  297. package/dist/ink/measure-element.js +11 -0
  298. package/dist/ink/measure-element.js.map +1 -0
  299. package/dist/ink/measure-text.d.ts +7 -0
  300. package/dist/ink/measure-text.d.ts.map +1 -0
  301. package/dist/ink/measure-text.js +38 -0
  302. package/dist/ink/measure-text.js.map +1 -0
  303. package/dist/ink/node-cache.d.ts +21 -0
  304. package/dist/ink/node-cache.d.ts.map +1 -0
  305. package/dist/ink/node-cache.js +36 -0
  306. package/dist/ink/node-cache.js.map +1 -0
  307. package/dist/ink/optimizer.d.ts +16 -0
  308. package/dist/ink/optimizer.d.ts.map +1 -0
  309. package/dist/ink/optimizer.js +85 -0
  310. package/dist/ink/optimizer.js.map +1 -0
  311. package/dist/ink/output.d.ts +120 -0
  312. package/dist/ink/output.d.ts.map +1 -0
  313. package/dist/ink/output.js +559 -0
  314. package/dist/ink/output.js.map +1 -0
  315. package/dist/ink/parse-keypress.d.ts +112 -0
  316. package/dist/ink/parse-keypress.d.ts.map +1 -0
  317. package/dist/ink/parse-keypress.js +719 -0
  318. package/dist/ink/parse-keypress.js.map +1 -0
  319. package/dist/ink/parse-keypress.test.d.ts +2 -0
  320. package/dist/ink/parse-keypress.test.d.ts.map +1 -0
  321. package/dist/ink/parse-keypress.test.js +37 -0
  322. package/dist/ink/parse-keypress.test.js.map +1 -0
  323. package/dist/ink/reconciler.d.ts +12 -0
  324. package/dist/ink/reconciler.d.ts.map +1 -0
  325. package/dist/ink/reconciler.js +456 -0
  326. package/dist/ink/reconciler.js.map +1 -0
  327. package/dist/ink/render-border.d.ts +25 -0
  328. package/dist/ink/render-border.d.ts.map +1 -0
  329. package/dist/ink/render-border.js +141 -0
  330. package/dist/ink/render-border.js.map +1 -0
  331. package/dist/ink/render-node-to-output.d.ts +46 -0
  332. package/dist/ink/render-node-to-output.d.ts.map +1 -0
  333. package/dist/ink/render-node-to-output.js +1257 -0
  334. package/dist/ink/render-node-to-output.js.map +1 -0
  335. package/dist/ink/render-to-screen.d.ts +47 -0
  336. package/dist/ink/render-to-screen.d.ts.map +1 -0
  337. package/dist/ink/render-to-screen.js +213 -0
  338. package/dist/ink/render-to-screen.js.map +1 -0
  339. package/dist/ink/renderer.d.ts +15 -0
  340. package/dist/ink/renderer.d.ts.map +1 -0
  341. package/dist/ink/renderer.js +169 -0
  342. package/dist/ink/renderer.js.map +1 -0
  343. package/dist/ink/root.d.ts +75 -0
  344. package/dist/ink/root.d.ts.map +1 -0
  345. package/dist/ink/root.js +89 -0
  346. package/dist/ink/root.js.map +1 -0
  347. package/dist/ink/screen.d.ts +270 -0
  348. package/dist/ink/screen.d.ts.map +1 -0
  349. package/dist/ink/screen.js +1194 -0
  350. package/dist/ink/screen.js.map +1 -0
  351. package/dist/ink/searchHighlight.d.ts +21 -0
  352. package/dist/ink/searchHighlight.d.ts.map +1 -0
  353. package/dist/ink/searchHighlight.js +82 -0
  354. package/dist/ink/searchHighlight.js.map +1 -0
  355. package/dist/ink/selection.d.ts +230 -0
  356. package/dist/ink/selection.d.ts.map +1 -0
  357. package/dist/ink/selection.js +814 -0
  358. package/dist/ink/selection.js.map +1 -0
  359. package/dist/ink/squash-text-nodes.d.ts +23 -0
  360. package/dist/ink/squash-text-nodes.d.ts.map +1 -0
  361. package/dist/ink/squash-text-nodes.js +60 -0
  362. package/dist/ink/squash-text-nodes.js.map +1 -0
  363. package/dist/ink/stringWidth.d.ts +2 -0
  364. package/dist/ink/stringWidth.d.ts.map +1 -0
  365. package/dist/ink/stringWidth.js +207 -0
  366. package/dist/ink/stringWidth.js.map +1 -0
  367. package/dist/ink/styles.d.ts +307 -0
  368. package/dist/ink/styles.d.ts.map +1 -0
  369. package/dist/ink/styles.js +302 -0
  370. package/dist/ink/styles.js.map +1 -0
  371. package/dist/ink/supports-hyperlinks.d.ts +14 -0
  372. package/dist/ink/supports-hyperlinks.d.ts.map +1 -0
  373. package/dist/ink/supports-hyperlinks.js +48 -0
  374. package/dist/ink/supports-hyperlinks.js.map +1 -0
  375. package/dist/ink/tabstops.d.ts +2 -0
  376. package/dist/ink/tabstops.d.ts.map +1 -0
  377. package/dist/ink/tabstops.js +43 -0
  378. package/dist/ink/tabstops.js.map +1 -0
  379. package/dist/ink/terminal-focus-state.d.ts +7 -0
  380. package/dist/ink/terminal-focus-state.d.ts.map +1 -0
  381. package/dist/ink/terminal-focus-state.js +43 -0
  382. package/dist/ink/terminal-focus-state.js.map +1 -0
  383. package/dist/ink/terminal-querier.d.ts +130 -0
  384. package/dist/ink/terminal-querier.d.ts.map +1 -0
  385. package/dist/ink/terminal-querier.js +184 -0
  386. package/dist/ink/terminal-querier.js.map +1 -0
  387. package/dist/ink/terminal.d.ts +56 -0
  388. package/dist/ink/terminal.d.ts.map +1 -0
  389. package/dist/ink/terminal.js +249 -0
  390. package/dist/ink/terminal.js.map +1 -0
  391. package/dist/ink/termio/csi.d.ts +166 -0
  392. package/dist/ink/termio/csi.d.ts.map +1 -0
  393. package/dist/ink/termio/csi.js +285 -0
  394. package/dist/ink/termio/csi.js.map +1 -0
  395. package/dist/ink/termio/dec.d.ts +38 -0
  396. package/dist/ink/termio/dec.d.ts.map +1 -0
  397. package/dist/ink/termio/dec.js +59 -0
  398. package/dist/ink/termio/dec.js.map +1 -0
  399. package/dist/ink/termio.d.ts +25 -0
  400. package/dist/ink/termio.d.ts.map +1 -0
  401. package/dist/ink/termio.js +32 -0
  402. package/dist/ink/termio.js.map +1 -0
  403. package/dist/ink/useTerminalNotification.d.ts +27 -0
  404. package/dist/ink/useTerminalNotification.d.ts.map +1 -0
  405. package/dist/ink/useTerminalNotification.js +62 -0
  406. package/dist/ink/useTerminalNotification.js.map +1 -0
  407. package/dist/ink/warn.d.ts +2 -0
  408. package/dist/ink/warn.d.ts.map +1 -0
  409. package/dist/ink/warn.js +14 -0
  410. package/dist/ink/warn.js.map +1 -0
  411. package/dist/ink/widest-line.d.ts +2 -0
  412. package/dist/ink/widest-line.d.ts.map +1 -0
  413. package/dist/ink/widest-line.js +18 -0
  414. package/dist/ink/widest-line.js.map +1 -0
  415. package/dist/ink/wrap-text.d.ts +3 -0
  416. package/dist/ink/wrap-text.d.ts.map +1 -0
  417. package/dist/ink/wrap-text.js +61 -0
  418. package/dist/ink/wrap-text.js.map +1 -0
  419. package/dist/ink/wrapAnsi.d.ts +8 -0
  420. package/dist/ink/wrapAnsi.d.ts.map +1 -0
  421. package/dist/ink/wrapAnsi.js +13 -0
  422. package/dist/ink/wrapAnsi.js.map +1 -0
  423. package/dist/memory/embeddings.d.ts +33 -0
  424. package/dist/memory/embeddings.d.ts.map +1 -0
  425. package/dist/memory/embeddings.js +123 -0
  426. package/dist/memory/embeddings.js.map +1 -0
  427. package/dist/memory/index.d.ts +14 -0
  428. package/dist/memory/index.d.ts.map +1 -0
  429. package/dist/memory/index.js +31 -0
  430. package/dist/memory/index.js.map +1 -0
  431. package/dist/memory/prompts.d.ts +12 -0
  432. package/dist/memory/prompts.d.ts.map +1 -0
  433. package/dist/memory/prompts.js +117 -0
  434. package/dist/memory/prompts.js.map +1 -0
  435. package/dist/memory/semantic-search.d.ts +45 -0
  436. package/dist/memory/semantic-search.d.ts.map +1 -0
  437. package/dist/memory/semantic-search.js +112 -0
  438. package/dist/memory/semantic-search.js.map +1 -0
  439. package/dist/memory/storage.d.ts +79 -0
  440. package/dist/memory/storage.d.ts.map +1 -0
  441. package/dist/memory/storage.js +285 -0
  442. package/dist/memory/storage.js.map +1 -0
  443. package/dist/memory/store.d.ts +103 -0
  444. package/dist/memory/store.d.ts.map +1 -0
  445. package/dist/memory/store.js +226 -0
  446. package/dist/memory/store.js.map +1 -0
  447. package/dist/memory/types.d.ts +40 -0
  448. package/dist/memory/types.d.ts.map +1 -0
  449. package/dist/memory/types.js +71 -0
  450. package/dist/memory/types.js.map +1 -0
  451. package/dist/memory/validation.d.ts +28 -0
  452. package/dist/memory/validation.d.ts.map +1 -0
  453. package/dist/memory/validation.js +147 -0
  454. package/dist/memory/validation.js.map +1 -0
  455. package/dist/memory/vector-store.d.ts +49 -0
  456. package/dist/memory/vector-store.d.ts.map +1 -0
  457. package/dist/memory/vector-store.js +259 -0
  458. package/dist/memory/vector-store.js.map +1 -0
  459. package/dist/screens/REPL.d.ts +21 -0
  460. package/dist/screens/REPL.d.ts.map +1 -0
  461. package/dist/screens/REPL.js +139 -0
  462. package/dist/screens/REPL.js.map +1 -0
  463. package/dist/services/agent-runner.d.ts +68 -0
  464. package/dist/services/agent-runner.d.ts.map +1 -0
  465. package/dist/services/agent-runner.js +186 -0
  466. package/dist/services/agent-runner.js.map +1 -0
  467. package/dist/services/atomic-write.d.ts +12 -0
  468. package/dist/services/atomic-write.d.ts.map +1 -0
  469. package/dist/services/atomic-write.js +27 -0
  470. package/dist/services/atomic-write.js.map +1 -0
  471. package/dist/services/config-dir.d.ts +55 -0
  472. package/dist/services/config-dir.d.ts.map +1 -0
  473. package/dist/services/config-dir.js +136 -0
  474. package/dist/services/config-dir.js.map +1 -0
  475. package/dist/services/config.d.ts +54 -0
  476. package/dist/services/config.d.ts.map +1 -0
  477. package/dist/services/config.js +98 -0
  478. package/dist/services/config.js.map +1 -0
  479. package/dist/services/file-glob.d.ts +26 -0
  480. package/dist/services/file-glob.d.ts.map +1 -0
  481. package/dist/services/file-glob.js +134 -0
  482. package/dist/services/file-glob.js.map +1 -0
  483. package/dist/services/global-config.d.ts +109 -0
  484. package/dist/services/global-config.d.ts.map +1 -0
  485. package/dist/services/global-config.js +211 -0
  486. package/dist/services/global-config.js.map +1 -0
  487. package/dist/services/llm.d.ts +139 -0
  488. package/dist/services/llm.d.ts.map +1 -0
  489. package/dist/services/llm.js +376 -0
  490. package/dist/services/llm.js.map +1 -0
  491. package/dist/services/memory.d.ts +39 -0
  492. package/dist/services/memory.d.ts.map +1 -0
  493. package/dist/services/memory.js +88 -0
  494. package/dist/services/memory.js.map +1 -0
  495. package/dist/services/session-storage.d.ts +136 -0
  496. package/dist/services/session-storage.d.ts.map +1 -0
  497. package/dist/services/session-storage.js +304 -0
  498. package/dist/services/session-storage.js.map +1 -0
  499. package/dist/services/task-manager.d.ts +154 -0
  500. package/dist/services/task-manager.d.ts.map +1 -0
  501. package/dist/services/task-manager.js +288 -0
  502. package/dist/services/task-manager.js.map +1 -0
  503. package/dist/services/yaml-config.d.ts +57 -0
  504. package/dist/services/yaml-config.d.ts.map +1 -0
  505. package/dist/services/yaml-config.js +176 -0
  506. package/dist/services/yaml-config.js.map +1 -0
  507. package/dist/skills/discovery.d.ts +22 -0
  508. package/dist/skills/discovery.d.ts.map +1 -0
  509. package/dist/skills/discovery.js +75 -0
  510. package/dist/skills/discovery.js.map +1 -0
  511. package/dist/skills/index.d.ts +10 -0
  512. package/dist/skills/index.d.ts.map +1 -0
  513. package/dist/skills/index.js +26 -0
  514. package/dist/skills/index.js.map +1 -0
  515. package/dist/skills/loader.d.ts +48 -0
  516. package/dist/skills/loader.d.ts.map +1 -0
  517. package/dist/skills/loader.js +231 -0
  518. package/dist/skills/loader.js.map +1 -0
  519. package/dist/skills/registry.d.ts +37 -0
  520. package/dist/skills/registry.d.ts.map +1 -0
  521. package/dist/skills/registry.js +134 -0
  522. package/dist/skills/registry.js.map +1 -0
  523. package/dist/skills/types.d.ts +89 -0
  524. package/dist/skills/types.d.ts.map +1 -0
  525. package/dist/skills/types.js +24 -0
  526. package/dist/skills/types.js.map +1 -0
  527. package/dist/tools/bash_security.d.ts +64 -0
  528. package/dist/tools/bash_security.d.ts.map +1 -0
  529. package/dist/tools/bash_security.js +291 -0
  530. package/dist/tools/bash_security.js.map +1 -0
  531. package/dist/tools/index.d.ts +23 -0
  532. package/dist/tools/index.d.ts.map +1 -0
  533. package/dist/tools/index.js +965 -0
  534. package/dist/tools/index.js.map +1 -0
  535. package/dist/tools/mcp.d.ts +72 -0
  536. package/dist/tools/mcp.d.ts.map +1 -0
  537. package/dist/tools/mcp.js +422 -0
  538. package/dist/tools/mcp.js.map +1 -0
  539. package/dist/tools/plan.d.ts +18 -0
  540. package/dist/tools/plan.d.ts.map +1 -0
  541. package/dist/tools/plan.js +75 -0
  542. package/dist/tools/plan.js.map +1 -0
  543. package/dist/tools/todo.d.ts +18 -0
  544. package/dist/tools/todo.d.ts.map +1 -0
  545. package/dist/tools/todo.js +153 -0
  546. package/dist/tools/todo.js.map +1 -0
  547. package/dist/tools/web.d.ts +13 -0
  548. package/dist/tools/web.d.ts.map +1 -0
  549. package/dist/tools/web.js +377 -0
  550. package/dist/tools/web.js.map +1 -0
  551. package/dist/ui/box.d.ts +56 -0
  552. package/dist/ui/box.d.ts.map +1 -0
  553. package/dist/ui/box.js +241 -0
  554. package/dist/ui/box.js.map +1 -0
  555. package/dist/ui/command-panel.d.ts +55 -0
  556. package/dist/ui/command-panel.d.ts.map +1 -0
  557. package/dist/ui/command-panel.js +212 -0
  558. package/dist/ui/command-panel.js.map +1 -0
  559. package/dist/ui/file-completion.d.ts +62 -0
  560. package/dist/ui/file-completion.d.ts.map +1 -0
  561. package/dist/ui/file-completion.js +209 -0
  562. package/dist/ui/file-completion.js.map +1 -0
  563. package/dist/ui/markdown.d.ts +12 -0
  564. package/dist/ui/markdown.d.ts.map +1 -0
  565. package/dist/ui/markdown.js +215 -0
  566. package/dist/ui/markdown.js.map +1 -0
  567. package/dist/ui/multiline-input.d.ts +47 -0
  568. package/dist/ui/multiline-input.d.ts.map +1 -0
  569. package/dist/ui/multiline-input.js +94 -0
  570. package/dist/ui/multiline-input.js.map +1 -0
  571. package/dist/ui/status-bar.d.ts +33 -0
  572. package/dist/ui/status-bar.d.ts.map +1 -0
  573. package/dist/ui/status-bar.js +96 -0
  574. package/dist/ui/status-bar.js.map +1 -0
  575. package/dist/ui/stream-markdown.d.ts +35 -0
  576. package/dist/ui/stream-markdown.d.ts.map +1 -0
  577. package/dist/ui/stream-markdown.js +138 -0
  578. package/dist/ui/stream-markdown.js.map +1 -0
  579. package/dist/ui/suggestions.d.ts +35 -0
  580. package/dist/ui/suggestions.d.ts.map +1 -0
  581. package/dist/ui/suggestions.js +118 -0
  582. package/dist/ui/suggestions.js.map +1 -0
  583. package/dist/ui/tool-preview.d.ts +34 -0
  584. package/dist/ui/tool-preview.d.ts.map +1 -0
  585. package/dist/ui/tool-preview.js +128 -0
  586. package/dist/ui/tool-preview.js.map +1 -0
  587. package/package.json +93 -0
@@ -0,0 +1,1257 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.resetLayoutShifted = resetLayoutShifted;
7
+ exports.didLayoutShift = didLayoutShift;
8
+ exports.resetScrollHint = resetScrollHint;
9
+ exports.getScrollHint = getScrollHint;
10
+ exports.resetScrollDrainNode = resetScrollDrainNode;
11
+ exports.getScrollDrainNode = getScrollDrainNode;
12
+ exports.consumeFollowScroll = consumeFollowScroll;
13
+ exports.buildCharToSegmentMap = buildCharToSegmentMap;
14
+ exports.applyStylesToWrappedText = applyStylesToWrappedText;
15
+ const indent_string_1 = __importDefault(require("indent-string"));
16
+ const colorize_js_1 = require("./colorize.js");
17
+ const get_max_width_js_1 = __importDefault(require("./get-max-width.js"));
18
+ const node_js_1 = require("./layout/node.js");
19
+ const node_cache_js_1 = require("./node-cache.js");
20
+ const render_border_js_1 = __importDefault(require("./render-border.js"));
21
+ const squash_text_nodes_js_1 = require("./squash-text-nodes.js");
22
+ const terminal_js_1 = require("./terminal.js");
23
+ const widest_line_js_1 = require("./widest-line.js");
24
+ const wrap_text_js_1 = __importDefault(require("./wrap-text.js"));
25
+ // Matches detectXtermJsWheel() in ScrollKeybindingHandler.tsx — the curve
26
+ // and drain must agree on terminal detection. TERM_PROGRAM check is the sync
27
+ // fallback; isXtermJs() is the authoritative XTVERSION-probe result.
28
+ function isXtermJsHost() {
29
+ return process.env.TERM_PROGRAM === 'vscode' || (0, terminal_js_1.isXtermJs)();
30
+ }
31
+ // Per-frame scratch: set when any node's yoga position/size differs from
32
+ // its cached value, or a child was removed. Read by ink.tsx to decide
33
+ // whether the full-damage sledgehammer (PR #20120) is needed this frame.
34
+ // Applies on both alt-screen and main-screen. Steady-state frames
35
+ // (spinner tick, clock tick, text append into a fixed-height box) don't
36
+ // shift layout → narrow damage bounds → O(changed cells) diff instead of
37
+ // O(rows×cols).
38
+ let layoutShifted = false;
39
+ function resetLayoutShifted() {
40
+ layoutShifted = false;
41
+ }
42
+ function didLayoutShift() {
43
+ return layoutShifted;
44
+ }
45
+ let scrollHint = null;
46
+ // Rects of position:absolute nodes from the PREVIOUS frame, used by
47
+ // ScrollBox's blit+shift third-pass repair (see usage site). Recorded at
48
+ // three paths — full-render nodeCache.set, node-level blit early-return,
49
+ // blitEscapingAbsoluteDescendants — so clean-overlay consecutive scrolls
50
+ // still have the rect.
51
+ let absoluteRectsPrev = [];
52
+ let absoluteRectsCur = [];
53
+ function resetScrollHint() {
54
+ scrollHint = null;
55
+ absoluteRectsPrev = absoluteRectsCur;
56
+ absoluteRectsCur = [];
57
+ }
58
+ function getScrollHint() {
59
+ return scrollHint;
60
+ }
61
+ // The ScrollBox DOM node (if any) with pendingScrollDelta left after this
62
+ // frame's drain. renderer.ts calls markDirty(it) post-render so the NEXT
63
+ // frame's root blit check fails and we descend to continue draining.
64
+ // Without this, after the scrollbox's dirty flag is cleared (line ~721),
65
+ // the next frame blits root and never reaches the scrollbox — drain stalls.
66
+ let scrollDrainNode = null;
67
+ function resetScrollDrainNode() {
68
+ scrollDrainNode = null;
69
+ }
70
+ function getScrollDrainNode() {
71
+ return scrollDrainNode;
72
+ }
73
+ let followScroll = null;
74
+ function consumeFollowScroll() {
75
+ const f = followScroll;
76
+ followScroll = null;
77
+ return f;
78
+ }
79
+ // ── Native terminal drain (iTerm2/Ghostty/etc. — proportional events) ──
80
+ // Minimum rows applied per frame. Above this, drain is proportional (~3/4
81
+ // of remaining) so big bursts catch up in log₄ frames while the tail
82
+ // decelerates smoothly. Hard cap is innerHeight-1 so DECSTBM hint fires.
83
+ const SCROLL_MIN_PER_FRAME = 4;
84
+ // ── xterm.js (VS Code) smooth drain ──
85
+ // Low pending (≤5) drains ALL in one frame — slow wheel clicks should be
86
+ // instant (click → visible jump → done), not micro-stutter 1-row frames.
87
+ // Higher pending drains at a small fixed step so fast-scroll animation
88
+ // stays smooth (no big jumps). Pending >MAX snaps excess.
89
+ const SCROLL_INSTANT_THRESHOLD = 5; // ≤ this: drain all at once
90
+ const SCROLL_HIGH_PENDING = 12; // threshold for HIGH step
91
+ const SCROLL_STEP_MED = 2; // pending (INSTANT, HIGH): catch-up
92
+ const SCROLL_STEP_HIGH = 3; // pending ≥ HIGH: fast flick
93
+ const SCROLL_MAX_PENDING = 30; // snap excess beyond this
94
+ // xterm.js adaptive drain. Returns rows applied; mutates pendingScrollDelta.
95
+ function drainAdaptive(node, pending, innerHeight) {
96
+ const sign = pending > 0 ? 1 : -1;
97
+ let abs = Math.abs(pending);
98
+ let applied = 0;
99
+ // Snap excess beyond animation window so big flicks don't coast.
100
+ if (abs > SCROLL_MAX_PENDING) {
101
+ applied += sign * (abs - SCROLL_MAX_PENDING);
102
+ abs = SCROLL_MAX_PENDING;
103
+ }
104
+ // ≤5: drain all (slow click = instant). Above: small fixed step.
105
+ const step = abs <= SCROLL_INSTANT_THRESHOLD
106
+ ? abs
107
+ : abs < SCROLL_HIGH_PENDING
108
+ ? SCROLL_STEP_MED
109
+ : SCROLL_STEP_HIGH;
110
+ applied += sign * step;
111
+ const rem = abs - step;
112
+ // Cap total at innerHeight-1 so DECSTBM blit+shift fast path fires
113
+ // (matches drainProportional). Excess stays in pendingScrollDelta.
114
+ const cap = Math.max(1, innerHeight - 1);
115
+ const totalAbs = Math.abs(applied);
116
+ if (totalAbs > cap) {
117
+ const excess = totalAbs - cap;
118
+ node.pendingScrollDelta = sign * (rem + excess);
119
+ return sign * cap;
120
+ }
121
+ node.pendingScrollDelta = rem > 0 ? sign * rem : undefined;
122
+ return applied;
123
+ }
124
+ // Native proportional drain. step = max(MIN, floor(abs*3/4)), capped at
125
+ // innerHeight-1 so DECSTBM + blit+shift fast path fire.
126
+ function drainProportional(node, pending, innerHeight) {
127
+ const abs = Math.abs(pending);
128
+ const cap = Math.max(1, innerHeight - 1);
129
+ const step = Math.min(cap, Math.max(SCROLL_MIN_PER_FRAME, (abs * 3) >> 2));
130
+ if (abs <= step) {
131
+ node.pendingScrollDelta = undefined;
132
+ return pending;
133
+ }
134
+ const applied = pending > 0 ? step : -step;
135
+ node.pendingScrollDelta = pending - applied;
136
+ return applied;
137
+ }
138
+ // OSC 8 hyperlink escape sequences. Empty params (;;) — ansi-tokenize only
139
+ // recognizes this exact prefix. The id= param (for grouping wrapped lines)
140
+ // is added at terminal-output time in termio/osc.ts link().
141
+ const OSC = '\u001B]';
142
+ const BEL = '\u0007';
143
+ function wrapWithOsc8Link(text, url) {
144
+ return `${OSC}8;;${url}${BEL}${text}${OSC}8;;${BEL}`;
145
+ }
146
+ /**
147
+ * Build a mapping from each character position in the plain text to its segment index.
148
+ * Returns an array where charToSegment[i] is the segment index for character i.
149
+ */
150
+ function buildCharToSegmentMap(segments) {
151
+ const map = [];
152
+ for (let i = 0; i < segments.length; i++) {
153
+ const len = segments[i].text.length;
154
+ for (let j = 0; j < len; j++) {
155
+ map.push(i);
156
+ }
157
+ }
158
+ return map;
159
+ }
160
+ /**
161
+ * Apply styles to wrapped text by mapping each character back to its original segment.
162
+ * This preserves per-segment styles even when text wraps across lines.
163
+ *
164
+ * @param trimEnabled - Whether whitespace trimming is enabled (wrap-trim mode).
165
+ * When true, we skip whitespace in the original that was trimmed from the output.
166
+ * When false (wrap mode), all whitespace is preserved so no skipping is needed.
167
+ */
168
+ function applyStylesToWrappedText(wrappedPlain, segments, charToSegment, originalPlain, trimEnabled = false) {
169
+ const lines = wrappedPlain.split('\n');
170
+ const resultLines = [];
171
+ let charIndex = 0;
172
+ for (let lineIdx = 0; lineIdx < lines.length; lineIdx++) {
173
+ const line = lines[lineIdx];
174
+ // In trim mode, skip leading whitespace that was trimmed from this line.
175
+ // Only skip if the original has whitespace but the output line doesn't start
176
+ // with whitespace (meaning it was trimmed). If both have whitespace, the
177
+ // whitespace was preserved and we shouldn't skip.
178
+ if (trimEnabled && line.length > 0) {
179
+ const lineStartsWithWhitespace = /\s/.test(line[0]);
180
+ const originalHasWhitespace = charIndex < originalPlain.length && /\s/.test(originalPlain[charIndex]);
181
+ // Only skip if original has whitespace but line doesn't
182
+ if (originalHasWhitespace && !lineStartsWithWhitespace) {
183
+ while (charIndex < originalPlain.length &&
184
+ /\s/.test(originalPlain[charIndex])) {
185
+ charIndex++;
186
+ }
187
+ }
188
+ }
189
+ let styledLine = '';
190
+ let runStart = 0;
191
+ let runSegmentIndex = charToSegment[charIndex] ?? 0;
192
+ for (let i = 0; i < line.length; i++) {
193
+ const currentSegmentIndex = charToSegment[charIndex] ?? runSegmentIndex;
194
+ if (currentSegmentIndex !== runSegmentIndex) {
195
+ // Flush the current run
196
+ const runText = line.slice(runStart, i);
197
+ const segment = segments[runSegmentIndex];
198
+ if (segment) {
199
+ let styled = (0, colorize_js_1.applyTextStyles)(runText, segment.styles);
200
+ if (segment.hyperlink) {
201
+ styled = wrapWithOsc8Link(styled, segment.hyperlink);
202
+ }
203
+ styledLine += styled;
204
+ }
205
+ else {
206
+ styledLine += runText;
207
+ }
208
+ runStart = i;
209
+ runSegmentIndex = currentSegmentIndex;
210
+ }
211
+ charIndex++;
212
+ }
213
+ // Flush the final run
214
+ const runText = line.slice(runStart);
215
+ const segment = segments[runSegmentIndex];
216
+ if (segment) {
217
+ let styled = (0, colorize_js_1.applyTextStyles)(runText, segment.styles);
218
+ if (segment.hyperlink) {
219
+ styled = wrapWithOsc8Link(styled, segment.hyperlink);
220
+ }
221
+ styledLine += styled;
222
+ }
223
+ else {
224
+ styledLine += runText;
225
+ }
226
+ resultLines.push(styledLine);
227
+ // Skip newline character in original that corresponds to this line break.
228
+ // This is needed when the original text contains actual newlines (not just
229
+ // wrapping-inserted newlines). Without this, charIndex gets out of sync
230
+ // because the newline is in originalPlain/charToSegment but not in the
231
+ // split lines.
232
+ if (charIndex < originalPlain.length && originalPlain[charIndex] === '\n') {
233
+ charIndex++;
234
+ }
235
+ // In trim mode, skip whitespace that was replaced by newline when wrapping.
236
+ // We skip whitespace in the original until we reach a character that matches
237
+ // the first character of the next line. This handles cases like:
238
+ // - "AB \tD" wrapped to "AB\n\tD" - skip spaces until we hit the tab
239
+ // In non-trim mode, whitespace is preserved so no skipping is needed.
240
+ if (trimEnabled && lineIdx < lines.length - 1) {
241
+ const nextLine = lines[lineIdx + 1];
242
+ const nextLineFirstChar = nextLine.length > 0 ? nextLine[0] : null;
243
+ // Skip whitespace until we hit a char that matches the next line's first char
244
+ while (charIndex < originalPlain.length &&
245
+ /\s/.test(originalPlain[charIndex])) {
246
+ // Stop if we found the character that starts the next line
247
+ if (nextLineFirstChar !== null &&
248
+ originalPlain[charIndex] === nextLineFirstChar) {
249
+ break;
250
+ }
251
+ charIndex++;
252
+ }
253
+ }
254
+ }
255
+ return resultLines.join('\n');
256
+ }
257
+ /**
258
+ * Wrap text and record which output lines are soft-wrap continuations
259
+ * (i.e. the `\n` before them was inserted by word-wrap, not in the
260
+ * source). wrapAnsi already processes each input line independently, so
261
+ * wrapping per-input-line here gives identical output to a single
262
+ * whole-string wrap while letting us mark per-piece provenance.
263
+ * Truncate modes never add newlines (cli-truncate is whole-string) so
264
+ * they fall through with softWrap undefined — no tracking, no behavior
265
+ * change from the pre-softWrap path.
266
+ */
267
+ function wrapWithSoftWrap(plainText, maxWidth, textWrap) {
268
+ if (textWrap !== 'wrap' && textWrap !== 'wrap-trim') {
269
+ return {
270
+ wrapped: (0, wrap_text_js_1.default)(plainText, maxWidth, textWrap),
271
+ softWrap: undefined,
272
+ };
273
+ }
274
+ const origLines = plainText.split('\n');
275
+ const outLines = [];
276
+ const softWrap = [];
277
+ for (const orig of origLines) {
278
+ const pieces = (0, wrap_text_js_1.default)(orig, maxWidth, textWrap).split('\n');
279
+ for (let i = 0; i < pieces.length; i++) {
280
+ outLines.push(pieces[i]);
281
+ softWrap.push(i > 0);
282
+ }
283
+ }
284
+ return { wrapped: outLines.join('\n'), softWrap };
285
+ }
286
+ // If parent container is `<Box>`, text nodes will be treated as separate nodes in
287
+ // the tree and will have their own coordinates in the layout.
288
+ // To ensure text nodes are aligned correctly, take X and Y of the first text node
289
+ // and use it as offset for the rest of the nodes
290
+ // Only first node is taken into account, because other text nodes can't have margin or padding,
291
+ // so their coordinates will be relative to the first node anyway
292
+ function applyPaddingToText(node, text, softWrap) {
293
+ const yogaNode = node.childNodes[0]?.yogaNode;
294
+ if (yogaNode) {
295
+ const offsetX = yogaNode.getComputedLeft();
296
+ const offsetY = yogaNode.getComputedTop();
297
+ text = '\n'.repeat(offsetY) + (0, indent_string_1.default)(text, offsetX);
298
+ if (softWrap && offsetY > 0) {
299
+ // Prepend `false` for each padding line so indices stay aligned
300
+ // with text.split('\n'). Mutate in place — caller owns the array.
301
+ softWrap.unshift(...Array(offsetY).fill(false));
302
+ }
303
+ }
304
+ return text;
305
+ }
306
+ function isElementNode(node) {
307
+ return Boolean(node && node.nodeName !== '#text');
308
+ }
309
+ function isRenderableElementNode(node) {
310
+ if (!node || typeof node !== 'object')
311
+ return false;
312
+ const candidate = node;
313
+ return (candidate.nodeName !== undefined &&
314
+ candidate.nodeName !== '#text' &&
315
+ candidate.style !== undefined &&
316
+ typeof candidate.style === 'object' &&
317
+ typeof candidate.dirty === 'boolean' &&
318
+ Array.isArray(candidate.childNodes));
319
+ }
320
+ // After nodes are laid out, render each to output object, which later gets rendered to terminal
321
+ function renderNodeToOutput(node, output, { offsetX = 0, offsetY = 0, prevScreen, skipSelfBlit = false, inheritedBackgroundColor, }) {
322
+ const { yogaNode } = node;
323
+ if (yogaNode) {
324
+ if (yogaNode.getDisplay() === node_js_1.LayoutDisplay.None) {
325
+ // Clear old position if node was visible before becoming hidden
326
+ if (node.dirty) {
327
+ const cached = node_cache_js_1.nodeCache.get(node);
328
+ if (cached) {
329
+ output.clear({
330
+ x: Math.floor(cached.x),
331
+ y: Math.floor(cached.y),
332
+ width: Math.floor(cached.width),
333
+ height: Math.floor(cached.height),
334
+ });
335
+ // Drop descendants' cache too — hideInstance's markDirty walks UP
336
+ // only, so descendants' .dirty stays false. Their nodeCache entries
337
+ // survive with pre-hide rects. On unhide, if position didn't shift,
338
+ // the blit check at line ~432 passes and copies EMPTY cells from
339
+ // prevScreen (cleared here) → content vanishes.
340
+ dropSubtreeCache(node);
341
+ layoutShifted = true;
342
+ }
343
+ }
344
+ return;
345
+ }
346
+ // Left and top positions in Yoga are relative to their parent node
347
+ const x = offsetX + yogaNode.getComputedLeft();
348
+ const yogaTop = yogaNode.getComputedTop();
349
+ let y = offsetY + yogaTop;
350
+ const width = yogaNode.getComputedWidth();
351
+ const height = yogaNode.getComputedHeight();
352
+ // Absolute-positioned overlays (e.g. autocomplete menus with bottom='100%')
353
+ // can compute negative screen y when they extend above the viewport. Without
354
+ // clamping, setCellAt drops cells at y<0, clipping the TOP of the content
355
+ // (best matches in an autocomplete). By clamping to 0, we shift the element
356
+ // down so the top rows are visible and the bottom overflows below — the
357
+ // opaque prop ensures it paints over whatever is underneath.
358
+ if (y < 0 && node.style.position === 'absolute') {
359
+ y = 0;
360
+ }
361
+ // Check if we can skip this subtree (clean node with unchanged layout).
362
+ // Blit cells from previous screen instead of re-rendering.
363
+ const cached = node_cache_js_1.nodeCache.get(node);
364
+ if (!node.dirty &&
365
+ !skipSelfBlit &&
366
+ node.pendingScrollDelta === undefined &&
367
+ cached &&
368
+ cached.x === x &&
369
+ cached.y === y &&
370
+ cached.width === width &&
371
+ cached.height === height &&
372
+ prevScreen) {
373
+ const fx = Math.floor(x);
374
+ const fy = Math.floor(y);
375
+ const fw = Math.floor(width);
376
+ const fh = Math.floor(height);
377
+ output.blit(prevScreen, fx, fy, fw, fh);
378
+ if (node.style.position === 'absolute') {
379
+ absoluteRectsCur.push(cached);
380
+ }
381
+ // Absolute descendants can paint outside this node's layout bounds
382
+ // (e.g. a slash menu with position='absolute' bottom='100%' floats
383
+ // above). If a dirty clipped sibling re-rendered and overwrote those
384
+ // cells, the blit above only restored this node's own rect — the
385
+ // absolute descendants' cells are lost. Re-blit them from prevScreen
386
+ // so the overlays survive.
387
+ blitEscapingAbsoluteDescendants(node, output, prevScreen, fx, fy, fw, fh);
388
+ return;
389
+ }
390
+ // Clear stale content from the old position when re-rendering.
391
+ // Dirty: content changed. Moved: position/size changed (e.g., sibling
392
+ // above changed height), old cells still on the terminal.
393
+ const positionChanged = cached !== undefined &&
394
+ (cached.x !== x ||
395
+ cached.y !== y ||
396
+ cached.width !== width ||
397
+ cached.height !== height);
398
+ if (positionChanged) {
399
+ layoutShifted = true;
400
+ }
401
+ if (cached && (node.dirty || positionChanged)) {
402
+ output.clear({
403
+ x: Math.floor(cached.x),
404
+ y: Math.floor(cached.y),
405
+ width: Math.floor(cached.width),
406
+ height: Math.floor(cached.height),
407
+ }, node.style.position === 'absolute');
408
+ }
409
+ // Read before deleting — hasRemovedChild disables prevScreen blitting
410
+ // for siblings to prevent stale overflow content from being restored.
411
+ const clears = node_cache_js_1.pendingClears.get(node);
412
+ const hasRemovedChild = clears !== undefined;
413
+ if (hasRemovedChild) {
414
+ layoutShifted = true;
415
+ for (const rect of clears) {
416
+ output.clear({
417
+ x: Math.floor(rect.x),
418
+ y: Math.floor(rect.y),
419
+ width: Math.floor(rect.width),
420
+ height: Math.floor(rect.height),
421
+ });
422
+ }
423
+ node_cache_js_1.pendingClears.delete(node);
424
+ }
425
+ // Yoga squeezed this node to zero height (overflow in a height-constrained
426
+ // parent) AND a sibling lands at the same y. Skip rendering — both would
427
+ // write to the same row; if the sibling's content is shorter, this node's
428
+ // tail chars ghost (e.g. "false" + "true" = "truee"). The clear above
429
+ // already handled the visible→squeezed transition.
430
+ //
431
+ // The sibling-overlap check is load-bearing: Yoga's pixel-grid rounding
432
+ // can give a box h=0 while still leaving a row for it (next sibling at
433
+ // y+1, not y). HelpV2's third shortcuts column hits this — skipping
434
+ // unconditionally drops "ctrl + z to suspend" from /help output.
435
+ if (height === 0 && siblingSharesY(node, yogaNode)) {
436
+ node_cache_js_1.nodeCache.set(node, { x, y, width, height, top: yogaTop });
437
+ node.dirty = false;
438
+ return;
439
+ }
440
+ if (node.nodeName === 'ink-raw-ansi') {
441
+ // Pre-rendered ANSI content. The producer already wrapped to width and
442
+ // emitted terminal-ready escape codes. Skip squash, measure, wrap, and
443
+ // style re-application — output.write() parses ANSI directly into cells.
444
+ const text = node.attributes['rawText'];
445
+ if (text) {
446
+ output.write(x, y, text);
447
+ }
448
+ }
449
+ else if (node.nodeName === 'ink-text') {
450
+ const segments = (0, squash_text_nodes_js_1.squashTextNodesToSegments)(node, inheritedBackgroundColor
451
+ ? { backgroundColor: inheritedBackgroundColor }
452
+ : undefined);
453
+ // First, get plain text to check if wrapping is needed
454
+ const plainText = segments.map(s => s.text).join('');
455
+ if (plainText.length > 0) {
456
+ // Upstream Ink uses getMaxWidth(yogaNode) unclamped here. That
457
+ // width comes from Yoga's AtMost pass and can exceed the actual
458
+ // screen space (see getMaxWidth docstring). Yoga's height for this
459
+ // node already reflects the constrained Exactly pass, so clamping
460
+ // the wrap width here keeps line count consistent with layout.
461
+ // Without this, characters past the screen edge are dropped by
462
+ // setCellAt's bounds check.
463
+ const maxWidth = Math.min((0, get_max_width_js_1.default)(yogaNode), output.width - x);
464
+ const textWrap = node.style.textWrap ?? 'wrap';
465
+ // Check if wrapping is needed
466
+ const needsWrapping = (0, widest_line_js_1.widestLine)(plainText) > maxWidth;
467
+ let text;
468
+ let softWrap;
469
+ if (needsWrapping && segments.length === 1) {
470
+ // Single segment: wrap plain text first, then apply styles to each line
471
+ const segment = segments[0];
472
+ const w = wrapWithSoftWrap(plainText, maxWidth, textWrap);
473
+ softWrap = w.softWrap;
474
+ text = w.wrapped
475
+ .split('\n')
476
+ .map(line => {
477
+ let styled = (0, colorize_js_1.applyTextStyles)(line, segment.styles);
478
+ // Apply OSC 8 hyperlink per-line so each line is independently
479
+ // clickable. output.ts splits on newlines and tokenizes each
480
+ // line separately, so a single wrapper around the whole block
481
+ // would only apply the hyperlink to the first line.
482
+ if (segment.hyperlink) {
483
+ styled = wrapWithOsc8Link(styled, segment.hyperlink);
484
+ }
485
+ return styled;
486
+ })
487
+ .join('\n');
488
+ }
489
+ else if (needsWrapping) {
490
+ // Multiple segments with wrapping: wrap plain text first, then re-apply
491
+ // each segment's styles based on character positions. This preserves
492
+ // per-segment styles even when text wraps across lines.
493
+ const w = wrapWithSoftWrap(plainText, maxWidth, textWrap);
494
+ softWrap = w.softWrap;
495
+ const charToSegment = buildCharToSegmentMap(segments);
496
+ text = applyStylesToWrappedText(w.wrapped, segments, charToSegment, plainText, textWrap === 'wrap-trim');
497
+ // Hyperlinks are handled per-run in applyStylesToWrappedText via
498
+ // wrapWithOsc8Link, similar to how styles are applied per-run.
499
+ }
500
+ else {
501
+ // No wrapping needed: apply styles directly
502
+ text = segments
503
+ .map(segment => {
504
+ let styledText = (0, colorize_js_1.applyTextStyles)(segment.text, segment.styles);
505
+ if (segment.hyperlink) {
506
+ styledText = wrapWithOsc8Link(styledText, segment.hyperlink);
507
+ }
508
+ return styledText;
509
+ })
510
+ .join('');
511
+ }
512
+ text = applyPaddingToText(node, text, softWrap);
513
+ output.write(x, y, text, softWrap);
514
+ }
515
+ }
516
+ else if (node.nodeName === 'ink-box') {
517
+ const boxBackgroundColor = node.style.backgroundColor ?? inheritedBackgroundColor;
518
+ // Mark this box's region as non-selectable (fullscreen text
519
+ // selection). noSelect ops are applied AFTER blits/writes in
520
+ // output.get(), so this wins regardless of what's rendered into
521
+ // the region — including blits from prevScreen when the box is
522
+ // clean (the op is emitted on both the dirty-render path here
523
+ // AND on the blit fast-path at line ~235 since blitRegion copies
524
+ // the noSelect bitmap alongside cells).
525
+ //
526
+ // 'from-left-edge' extends the exclusion from col 0 so any
527
+ // upstream indentation (tool prefix, tree lines) is covered too
528
+ // — a multi-row drag over a diff gutter shouldn't pick up the
529
+ // ` └ ` prefix on row 0 or the blank cells under it on row 1+.
530
+ if (node.style.noSelect) {
531
+ const boxX = Math.floor(x);
532
+ const fromEdge = node.style.noSelect === 'from-left-edge';
533
+ output.noSelect({
534
+ x: fromEdge ? 0 : boxX,
535
+ y: Math.floor(y),
536
+ width: fromEdge ? boxX + Math.floor(width) : Math.floor(width),
537
+ height: Math.floor(height),
538
+ });
539
+ }
540
+ const overflowX = node.style.overflowX ?? node.style.overflow;
541
+ const overflowY = node.style.overflowY ?? node.style.overflow;
542
+ const clipHorizontally = overflowX === 'hidden' || overflowX === 'scroll';
543
+ const clipVertically = overflowY === 'hidden' || overflowY === 'scroll';
544
+ const isScrollY = overflowY === 'scroll';
545
+ const needsClip = clipHorizontally || clipVertically;
546
+ let y1;
547
+ let y2;
548
+ if (needsClip) {
549
+ const x1 = clipHorizontally
550
+ ? x + yogaNode.getComputedBorder(node_js_1.LayoutEdge.Left)
551
+ : undefined;
552
+ const x2 = clipHorizontally
553
+ ? x +
554
+ yogaNode.getComputedWidth() -
555
+ yogaNode.getComputedBorder(node_js_1.LayoutEdge.Right)
556
+ : undefined;
557
+ y1 = clipVertically
558
+ ? y + yogaNode.getComputedBorder(node_js_1.LayoutEdge.Top)
559
+ : undefined;
560
+ y2 = clipVertically
561
+ ? y +
562
+ yogaNode.getComputedHeight() -
563
+ yogaNode.getComputedBorder(node_js_1.LayoutEdge.Bottom)
564
+ : undefined;
565
+ output.clip({ x1, x2, y1, y2 });
566
+ }
567
+ if (isScrollY) {
568
+ // Scroll containers follow the ScrollBox component structure:
569
+ // a single content-wrapper child with flexShrink:0 (doesn't shrink
570
+ // to fit), whose children are the scrollable items. scrollHeight
571
+ // comes from the wrapper's intrinsic Yoga height. The wrapper is
572
+ // rendered with its Y translated by -scrollTop; its children are
573
+ // culled against the visible window.
574
+ const padTop = yogaNode.getComputedPadding(node_js_1.LayoutEdge.Top);
575
+ const innerHeight = Math.max(0, (y2 ?? y + height) -
576
+ (y1 ?? y) -
577
+ padTop -
578
+ yogaNode.getComputedPadding(node_js_1.LayoutEdge.Bottom));
579
+ const content = node.childNodes.find((c) => isElementNode(c) && c.yogaNode !== undefined);
580
+ const contentYoga = content?.yogaNode;
581
+ // scrollHeight is the intrinsic height of the content wrapper.
582
+ // Do NOT add getComputedTop() — that's the wrapper's offset
583
+ // within the viewport (equal to the scroll container's
584
+ // paddingTop), and innerHeight already subtracts padding, so
585
+ // including it double-counts padding and inflates maxScroll.
586
+ const scrollHeight = contentYoga?.getComputedHeight() ?? 0;
587
+ // Capture previous scroll bounds BEFORE overwriting — the at-bottom
588
+ // follow check compares against last frame's max.
589
+ const prevScrollHeight = node.scrollHeight ?? scrollHeight;
590
+ const prevInnerHeight = node.scrollViewportHeight ?? innerHeight;
591
+ node.scrollHeight = scrollHeight;
592
+ node.scrollViewportHeight = innerHeight;
593
+ // Absolute screen-buffer row where the scrollable area (inside
594
+ // padding) begins. Exposed via ScrollBoxHandle.getViewportTop() so
595
+ // drag-to-scroll can detect when the drag leaves the scroll viewport.
596
+ node.scrollViewportTop = (y1 ?? y) + padTop;
597
+ const maxScroll = Math.max(0, scrollHeight - innerHeight);
598
+ // scrollAnchor: scroll so the anchored element's top is at the
599
+ // viewport top (plus offset). Yoga is FRESH — same calculateLayout
600
+ // pass that just produced scrollHeight. Deterministic alternative
601
+ // to scrollTo(N) which bakes a number that's stale by the throttled
602
+ // render; the element ref defers the read to now. One-shot snap.
603
+ // A prior eased-seek version (proportional drain over ~5 frames)
604
+ // moved scrollTop without firing React's notify → parent's quantized
605
+ // store snapshot never updated → StickyTracker got stale range props
606
+ // → firstVisible wrong. Also: SCROLL_MIN_PER_FRAME=4 with snap-at-1
607
+ // ping-ponged forever at delta=2. Smooth needs drain-end notify
608
+ // plumbing; shipping instant first. stickyScroll overrides.
609
+ if (node.scrollAnchor) {
610
+ const anchorTop = node.scrollAnchor.el.yogaNode?.getComputedTop();
611
+ if (anchorTop != null) {
612
+ node.scrollTop = anchorTop + node.scrollAnchor.offset;
613
+ node.pendingScrollDelta = undefined;
614
+ }
615
+ node.scrollAnchor = undefined;
616
+ }
617
+ // At-bottom follow. Positional: if scrollTop was at (or past) the
618
+ // previous max, pin to the new max. Scroll away → stop following;
619
+ // scroll back (or scrollToBottom/sticky attr) → resume. The sticky
620
+ // flag is OR'd in for cold start (scrollTop=0 before first layout)
621
+ // and scrollToBottom-from-far-away (flag set before scrollTop moves)
622
+ // — the imperative field takes precedence over the attribute so
623
+ // scrollTo/scrollBy can break stickiness. pendingDelta<0 guard:
624
+ // don't cancel an in-flight scroll-up when content races in.
625
+ // Capture scrollTop before follow so ink.tsx can translate any
626
+ // active text selection by the same delta (native terminal behavior:
627
+ // view keeps scrolling, highlight walks up with the text).
628
+ const scrollTopBeforeFollow = node.scrollTop ?? 0;
629
+ const sticky = node.stickyScroll ?? Boolean(node.attributes['stickyScroll']);
630
+ const prevMaxScroll = Math.max(0, prevScrollHeight - prevInnerHeight);
631
+ // Positional check only valid when content grew — virtualization can
632
+ // transiently SHRINK scrollHeight (tail unmount + stale heightCache
633
+ // spacer) making scrollTop >= prevMaxScroll true by artifact, not
634
+ // because the user was at bottom.
635
+ const grew = scrollHeight >= prevScrollHeight;
636
+ const atBottom = sticky || (grew && scrollTopBeforeFollow >= prevMaxScroll);
637
+ if (atBottom && (node.pendingScrollDelta ?? 0) >= 0) {
638
+ node.scrollTop = maxScroll;
639
+ node.pendingScrollDelta = undefined;
640
+ // Sync flag so useVirtualScroll's isSticky() agrees with positional
641
+ // state — sticky-broken-but-at-bottom (wheel tremor, click-select
642
+ // at max) otherwise leaves useVirtualScroll's clamp holding the
643
+ // viewport short of new streaming content. scrollTo/scrollBy set
644
+ // false; this restores true, same as scrollToBottom() would.
645
+ // Only restore when (a) positionally at bottom and (b) the flag
646
+ // was explicitly broken (===false) by scrollTo/scrollBy. When
647
+ // undefined (never set by user action) leave it alone — setting it
648
+ // would make the sticky flag sticky-by-default and lock out
649
+ // direct scrollTop writes (e.g. the alt-screen-perf test).
650
+ if (node.stickyScroll === false &&
651
+ scrollTopBeforeFollow >= prevMaxScroll) {
652
+ node.stickyScroll = true;
653
+ }
654
+ }
655
+ const followDelta = (node.scrollTop ?? 0) - scrollTopBeforeFollow;
656
+ if (followDelta > 0) {
657
+ const vpTop = node.scrollViewportTop ?? 0;
658
+ followScroll = {
659
+ delta: followDelta,
660
+ viewportTop: vpTop,
661
+ viewportBottom: vpTop + innerHeight - 1,
662
+ };
663
+ }
664
+ // Drain pendingScrollDelta. Native terminals (proportional burst
665
+ // events) use proportional drain; xterm.js (VS Code, sparse events +
666
+ // app-side accel curve) uses adaptive small-step drain. isXtermJs()
667
+ // depends on the async XTVERSION probe, but by the time this runs
668
+ // (pendingScrollDelta is only set by wheel events, >>50ms after
669
+ // startup) the probe has resolved — same timing guarantee the
670
+ // wheel-accel curve relies on.
671
+ let cur = node.scrollTop ?? 0;
672
+ const pending = node.pendingScrollDelta;
673
+ const cMin = node.scrollClampMin;
674
+ const cMax = node.scrollClampMax;
675
+ const haveClamp = cMin !== undefined && cMax !== undefined;
676
+ if (pending !== undefined && pending !== 0) {
677
+ // Drain continues even past the clamp — the render-clamp below
678
+ // holds the VISUAL at the mounted edge regardless. Hard-stopping
679
+ // here caused stop-start jutter: drain hits edge → pause → React
680
+ // commits → clamp widens → drain resumes → edge again. Letting
681
+ // scrollTop advance smoothly while the clamp lags gives continuous
682
+ // visual scroll at React's commit rate (the clamp catches up each
683
+ // commit). But THROTTLE the drain when already past the clamp so
684
+ // scrollTop doesn't race 5000 rows ahead of the mounted range
685
+ // (slide-cap would then take 200 commits to catch up = long
686
+ // perceived stall at the edge). Past-clamp drain caps at ~4 rows/
687
+ // frame, roughly matching React's slide rate so the gap stays
688
+ // bounded and catch-up is quick once input stops.
689
+ const pastClamp = haveClamp &&
690
+ ((pending < 0 && cur < cMin) || (pending > 0 && cur > cMax));
691
+ const eff = pastClamp ? Math.min(4, innerHeight >> 3) : innerHeight;
692
+ cur += isXtermJsHost()
693
+ ? drainAdaptive(node, pending, eff)
694
+ : drainProportional(node, pending, eff);
695
+ }
696
+ else if (pending === 0) {
697
+ // Opposite scrollBy calls cancelled to zero — clear so we don't
698
+ // schedule an infinite loop of no-op drain frames.
699
+ node.pendingScrollDelta = undefined;
700
+ }
701
+ let scrollTop = Math.max(0, Math.min(cur, maxScroll));
702
+ // Virtual-scroll clamp: if scrollTop raced past the currently-mounted
703
+ // range (burst PageUp before React re-renders), render at the EDGE of
704
+ // the mounted children instead of blank spacer. Do NOT write back to
705
+ // node.scrollTop — the clamped value is for this paint only; the real
706
+ // scrollTop stays so React's next commit sees the target and mounts
707
+ // the right range. Not scheduling scrollDrainNode here keeps the
708
+ // clamp passive — React's commit → resetAfterCommit → onRender will
709
+ // paint again with fresh bounds.
710
+ const clamped = haveClamp
711
+ ? Math.max(cMin, Math.min(scrollTop, cMax))
712
+ : scrollTop;
713
+ node.scrollTop = scrollTop;
714
+ // Clamp hitting top/bottom consumes any remainder. Set drainPending
715
+ // only after clamp so a wasted no-op frame isn't scheduled.
716
+ if (scrollTop !== cur)
717
+ node.pendingScrollDelta = undefined;
718
+ if (node.pendingScrollDelta !== undefined)
719
+ scrollDrainNode = node;
720
+ scrollTop = clamped;
721
+ if (content && contentYoga) {
722
+ // Compute content wrapper's absolute render position with scroll
723
+ // offset applied, then render its children with culling.
724
+ const contentX = x + contentYoga.getComputedLeft();
725
+ const contentY = y + contentYoga.getComputedTop() - scrollTop;
726
+ // layoutShifted detection gap: when scrollTop moves by >= viewport
727
+ // height (batched PageUps, fast wheel), every visible child gets
728
+ // culled (cache dropped) and every newly-visible child has no
729
+ // cache — so the children's positionChanged check can't fire.
730
+ // The content wrapper's cached y (which encodes -scrollTop) is
731
+ // the only node that survives to witness the scroll.
732
+ const contentCached = node_cache_js_1.nodeCache.get(content);
733
+ let hint = null;
734
+ if (contentCached && contentCached.y !== contentY) {
735
+ // delta = newScrollTop - oldScrollTop (positive = scrolled down).
736
+ // Capture a DECSTBM hint if the container itself didn't move
737
+ // and the shift fits within the viewport — otherwise the full
738
+ // rewrite is needed anyway, and layoutShifted stays the fallback.
739
+ const delta = contentCached.y - contentY;
740
+ const regionTop = Math.floor(y + contentYoga.getComputedTop());
741
+ const regionBottom = regionTop + innerHeight - 1;
742
+ if (cached?.y === y &&
743
+ cached.height === height &&
744
+ innerHeight > 0 &&
745
+ Math.abs(delta) < innerHeight) {
746
+ hint = { top: regionTop, bottom: regionBottom, delta };
747
+ scrollHint = hint;
748
+ }
749
+ else {
750
+ layoutShifted = true;
751
+ }
752
+ }
753
+ // Fast path: scroll (hint captured) with usable prevScreen.
754
+ // Blit prevScreen's scroll region into next.screen, shift in-place
755
+ // by delta (mirrors DECSTBM), then render ONLY the edge rows. The
756
+ // nested clip keeps child writes out of stable rows — a tall child
757
+ // that spans edge+stable still renders but stable cells are
758
+ // clipped, preserving the blit. Avoids re-rendering every visible
759
+ // child (expensive for long syntax-highlighted transcripts).
760
+ //
761
+ // When content.dirty (e.g. streaming text at the bottom of the
762
+ // scroll), we still use the fast path — the dirty child is almost
763
+ // always in the edge rows (the bottom, where new content appears).
764
+ // After edge rendering, any dirty children in stable rows are
765
+ // re-rendered in a second pass to avoid showing stale blitted
766
+ // content.
767
+ //
768
+ // Guard: the fast path only handles pure scroll or bottom-append.
769
+ // Child removal/insertion changes the content height in a way that
770
+ // doesn't match the scroll delta — fall back to the full path so
771
+ // removed children don't leave stale cells and shifted siblings
772
+ // render at their new positions.
773
+ const scrollHeight = contentYoga.getComputedHeight();
774
+ const prevHeight = contentCached?.height ?? scrollHeight;
775
+ const heightDelta = scrollHeight - prevHeight;
776
+ const safeForFastPath = !hint ||
777
+ heightDelta === 0 ||
778
+ (hint.delta > 0 && heightDelta === hint.delta);
779
+ // scrollHint is set above when hint is captured. If safeForFastPath
780
+ // is false the full path renders a next.screen that doesn't match
781
+ // the DECSTBM shift — emitting DECSTBM leaves stale rows (seen as
782
+ // content bleeding through during scroll-up + streaming). Clear it.
783
+ if (!safeForFastPath)
784
+ scrollHint = null;
785
+ if (hint && prevScreen && safeForFastPath) {
786
+ const { top, bottom, delta } = hint;
787
+ const w = Math.floor(width);
788
+ output.blit(prevScreen, Math.floor(x), top, w, bottom - top + 1);
789
+ output.shift(top, bottom, delta);
790
+ // Edge rows: new content entering the viewport.
791
+ const edgeTop = delta > 0 ? bottom - delta + 1 : top;
792
+ const edgeBottom = delta > 0 ? bottom : top - delta - 1;
793
+ output.clear({
794
+ x: Math.floor(x),
795
+ y: edgeTop,
796
+ width: w,
797
+ height: edgeBottom - edgeTop + 1,
798
+ });
799
+ output.clip({
800
+ x1: undefined,
801
+ x2: undefined,
802
+ y1: edgeTop,
803
+ y2: edgeBottom + 1,
804
+ });
805
+ // Snapshot dirty children before the first pass — the first
806
+ // pass clears dirty flags, and edge-spanning children would be
807
+ // missed by the second pass without this snapshot.
808
+ const dirtyChildren = content.dirty
809
+ ? new Set(content.childNodes.filter((c) => isElementNode(c) && c.dirty))
810
+ : null;
811
+ renderScrolledChildren(content, output, contentX, contentY, hasRemovedChild, undefined,
812
+ // Cull to edge in child-local coords (inverse of contentY offset).
813
+ edgeTop - contentY, edgeBottom + 1 - contentY, boxBackgroundColor, true);
814
+ output.unclip();
815
+ // Second pass: re-render children in stable rows whose screen
816
+ // position doesn't match where the shift put their old pixels.
817
+ // Covers TWO cases:
818
+ // 1. Dirty children — their content changed, blitted pixels are
819
+ // stale regardless of position.
820
+ // 2. Clean children BELOW a middle-growth point — when a dirty
821
+ // sibling above them grows, their yogaTop increases but
822
+ // scrollTop increases by the same amount (sticky), so their
823
+ // screenY is CONSTANT. The shift moved their old pixels to
824
+ // screenY-delta (wrong); they should stay at screenY. Without
825
+ // this, the spinner/tmux-monitor ghost at shifted positions
826
+ // during streaming (e.g. triple spinner, pill duplication).
827
+ // For bottom-append (the common case), all clean children are
828
+ // ABOVE the growth point; their screenY decreased by delta and
829
+ // the shift put them at the right place — skipped here, fast
830
+ // path preserved.
831
+ if (dirtyChildren) {
832
+ const edgeTopLocal = edgeTop - contentY;
833
+ const edgeBottomLocal = edgeBottom + 1 - contentY;
834
+ const spaces = ' '.repeat(w);
835
+ // Track cumulative height change of children iterated so far.
836
+ // A clean child's yogaTop is unchanged iff this is zero (no
837
+ // sibling above it grew/shrank/mounted). When zero, the skip
838
+ // check cached.y−delta === screenY reduces to delta === delta
839
+ // (tautology) → skip without yoga reads. Restores O(dirty)
840
+ // that #24536 traded away: for bottom-append the dirty child
841
+ // is last (all clean children skip); for virtual-scroll range
842
+ // shift the topSpacer shrink + new-item heights self-balance
843
+ // to zero before reaching the clean block. Middle-growth
844
+ // leaves shift non-zero → clean children after the growth
845
+ // point fall through to yoga + the fine-grained check below,
846
+ // preserving the ghost-box fix.
847
+ let cumHeightShift = 0;
848
+ for (const childNode of content.childNodes) {
849
+ if (!isElementNode(childNode))
850
+ continue;
851
+ const childElem = childNode;
852
+ const isDirty = dirtyChildren.has(childNode);
853
+ if (!isDirty && cumHeightShift === 0) {
854
+ if (node_cache_js_1.nodeCache.has(childElem))
855
+ continue;
856
+ // Uncached = culled last frame, now re-entering. blit
857
+ // never painted it → fall through to yoga + render.
858
+ // Height unchanged (clean), so cumHeightShift stays 0.
859
+ }
860
+ const cy = childElem.yogaNode;
861
+ if (!cy)
862
+ continue;
863
+ const childTop = cy.getComputedTop();
864
+ const childH = cy.getComputedHeight();
865
+ const childBottom = childTop + childH;
866
+ if (isDirty) {
867
+ const prev = node_cache_js_1.nodeCache.get(childElem);
868
+ cumHeightShift += childH - (prev ? prev.height : 0);
869
+ }
870
+ // Skip culled children (outside viewport)
871
+ if (childBottom <= scrollTop ||
872
+ childTop >= scrollTop + innerHeight)
873
+ continue;
874
+ // Skip children entirely within edge rows (already rendered)
875
+ if (childTop >= edgeTopLocal && childBottom <= edgeBottomLocal)
876
+ continue;
877
+ const screenY = Math.floor(contentY + childTop);
878
+ // Clean children reaching here have cumHeightShift ≠ 0 OR
879
+ // no cache. Re-check precisely: cached.y − delta is where
880
+ // the shift left old pixels; if it equals new screenY the
881
+ // blit is correct (shift re-balanced at this child, or
882
+ // yogaTop happens to net out). No cache → blit never
883
+ // painted it → render.
884
+ if (!isDirty) {
885
+ const childCached = node_cache_js_1.nodeCache.get(childElem);
886
+ if (childCached &&
887
+ Math.floor(childCached.y) - delta === screenY) {
888
+ continue;
889
+ }
890
+ }
891
+ // Wipe this child's region with spaces to overwrite stale
892
+ // blitted content — output.clear() only expands damage and
893
+ // cannot zero cells that the blit already wrote.
894
+ const screenBottom = Math.min(Math.floor(contentY + childBottom), Math.floor((y1 ?? y) + padTop + innerHeight));
895
+ if (screenY < screenBottom) {
896
+ const fill = Array(screenBottom - screenY)
897
+ .fill(spaces)
898
+ .join('\n');
899
+ output.write(Math.floor(x), screenY, fill);
900
+ output.clip({
901
+ x1: undefined,
902
+ x2: undefined,
903
+ y1: screenY,
904
+ y2: screenBottom,
905
+ });
906
+ renderNodeToOutput(childElem, output, {
907
+ offsetX: contentX,
908
+ offsetY: contentY,
909
+ prevScreen: undefined,
910
+ inheritedBackgroundColor: boxBackgroundColor,
911
+ });
912
+ output.unclip();
913
+ }
914
+ }
915
+ }
916
+ // Third pass: repair rows where shifted copies of absolute
917
+ // overlays landed. The blit copied prevScreen cells INCLUDING
918
+ // overlay pixels (overlays render AFTER this ScrollBox so they
919
+ // painted into prevScreen's scroll region). After shift, those
920
+ // pixels sit at (rect.y - delta) — neither edge render nor the
921
+ // overlay's own re-render covers them. Wipe and re-render
922
+ // ScrollBox content so the diff writes correct cells.
923
+ const spaces = absoluteRectsPrev.length ? ' '.repeat(w) : '';
924
+ for (const r of absoluteRectsPrev) {
925
+ if (r.y >= bottom + 1 || r.y + r.height <= top)
926
+ continue;
927
+ const shiftedTop = Math.max(top, Math.floor(r.y) - delta);
928
+ const shiftedBottom = Math.min(bottom + 1, Math.floor(r.y + r.height) - delta);
929
+ // Skip if entirely within edge rows (already rendered).
930
+ if (shiftedTop >= edgeTop && shiftedBottom <= edgeBottom + 1)
931
+ continue;
932
+ if (shiftedTop >= shiftedBottom)
933
+ continue;
934
+ const fill = Array(shiftedBottom - shiftedTop)
935
+ .fill(spaces)
936
+ .join('\n');
937
+ output.write(Math.floor(x), shiftedTop, fill);
938
+ output.clip({
939
+ x1: undefined,
940
+ x2: undefined,
941
+ y1: shiftedTop,
942
+ y2: shiftedBottom,
943
+ });
944
+ renderScrolledChildren(content, output, contentX, contentY, hasRemovedChild, undefined, shiftedTop - contentY, shiftedBottom - contentY, boxBackgroundColor, true);
945
+ output.unclip();
946
+ }
947
+ }
948
+ else {
949
+ // Full path. Two sub-cases:
950
+ //
951
+ // Scrolled without a usable hint (big jump, container moved):
952
+ // child positions in prevScreen are stale. Clear the viewport
953
+ // and disable blit so children don't restore shifted content.
954
+ //
955
+ // No scroll (spinner tick, content edit): child positions in
956
+ // prevScreen are still valid. Skip the viewport clear and pass
957
+ // prevScreen so unchanged children blit. Dirty children already
958
+ // self-clear via their own cached-rect clear. Without this, a
959
+ // spinner inside ScrollBox forces a full-content rewrite every
960
+ // frame — on wide terminals over tmux (no BSU/ESU) the
961
+ // bandwidth crosses the chunk boundary and the frame tears.
962
+ const scrolled = contentCached && contentCached.y !== contentY;
963
+ if (scrolled && y1 !== undefined && y2 !== undefined) {
964
+ output.clear({
965
+ x: Math.floor(x),
966
+ y: Math.floor(y1),
967
+ width: Math.floor(width),
968
+ height: Math.floor(y2 - y1),
969
+ });
970
+ }
971
+ // positionChanged (ScrollBox height shrunk — pill mount) means a
972
+ // child spanning the old bottom edge would blit its full cached
973
+ // rect past the new clip. output.ts clips blits now, but also
974
+ // disable prevScreen here so the partial-row child re-renders at
975
+ // correct bounds instead of blitting a clipped (truncated) old
976
+ // rect.
977
+ renderScrolledChildren(content, output, contentX, contentY, hasRemovedChild, scrolled || positionChanged ? undefined : prevScreen, scrollTop, scrollTop + innerHeight, boxBackgroundColor);
978
+ }
979
+ node_cache_js_1.nodeCache.set(content, {
980
+ x: contentX,
981
+ y: contentY,
982
+ width: contentYoga.getComputedWidth(),
983
+ height: contentYoga.getComputedHeight(),
984
+ });
985
+ content.dirty = false;
986
+ }
987
+ }
988
+ else {
989
+ // Fill interior with background color before rendering children.
990
+ // This covers padding areas and empty space; child text inherits
991
+ // the color via inheritedBackgroundColor so written cells also
992
+ // get the background.
993
+ // Disable prevScreen for children: the fill overwrites the entire
994
+ // interior each render, so child blits from prevScreen would restore
995
+ // stale cells (wrong bg if it changed) on top of the fresh fill.
996
+ const ownBackgroundColor = node.style.backgroundColor;
997
+ if (ownBackgroundColor || node.style.opaque) {
998
+ const borderLeft = yogaNode.getComputedBorder(node_js_1.LayoutEdge.Left);
999
+ const borderRight = yogaNode.getComputedBorder(node_js_1.LayoutEdge.Right);
1000
+ const borderTop = yogaNode.getComputedBorder(node_js_1.LayoutEdge.Top);
1001
+ const borderBottom = yogaNode.getComputedBorder(node_js_1.LayoutEdge.Bottom);
1002
+ const innerWidth = Math.floor(width) - borderLeft - borderRight;
1003
+ const innerHeight = Math.floor(height) - borderTop - borderBottom;
1004
+ if (innerWidth > 0 && innerHeight > 0) {
1005
+ const spaces = ' '.repeat(innerWidth);
1006
+ const fillLine = ownBackgroundColor
1007
+ ? (0, colorize_js_1.applyTextStyles)(spaces, { backgroundColor: ownBackgroundColor })
1008
+ : spaces;
1009
+ const fill = Array(innerHeight).fill(fillLine).join('\n');
1010
+ output.write(x + borderLeft, y + borderTop, fill);
1011
+ }
1012
+ }
1013
+ renderChildren(node, output, x, y, hasRemovedChild,
1014
+ // backgroundColor and opaque both disable child blit: the fill
1015
+ // overwrites the entire interior each render, so any child whose
1016
+ // layout position shifted would blit stale cells from prevScreen
1017
+ // on top of the fresh fill. Previously opaque kept blit enabled
1018
+ // on the assumption that plain-space fill + unchanged children =
1019
+ // valid composite, but children CAN reposition (ScrollBox remeasure
1020
+ // on re-render → /permissions body blanked on Down arrow, #25436).
1021
+ ownBackgroundColor || node.style.opaque ? undefined : prevScreen, boxBackgroundColor);
1022
+ }
1023
+ if (needsClip) {
1024
+ output.unclip();
1025
+ }
1026
+ // Render border AFTER children to ensure it's not overwritten by child
1027
+ // clearing operations. When a child shrinks, it clears its old area,
1028
+ // which may overlap with where the parent's border now is.
1029
+ (0, render_border_js_1.default)(x, y, node, output);
1030
+ }
1031
+ else if (node.nodeName === 'ink-root') {
1032
+ renderChildren(node, output, x, y, hasRemovedChild, prevScreen, inheritedBackgroundColor);
1033
+ }
1034
+ // Cache layout bounds for dirty tracking
1035
+ const rect = { x, y, width, height, top: yogaTop };
1036
+ node_cache_js_1.nodeCache.set(node, rect);
1037
+ if (node.style.position === 'absolute') {
1038
+ absoluteRectsCur.push(rect);
1039
+ }
1040
+ node.dirty = false;
1041
+ }
1042
+ }
1043
+ // Overflow contamination: content overflows right/down, so clean siblings
1044
+ // AFTER a dirty/removed sibling can contain stale overflow in prevScreen.
1045
+ // Disable blit for siblings after a dirty child — but still pass prevScreen
1046
+ // TO the dirty child itself so its clean descendants can blit. The dirty
1047
+ // child's own blit check already fails (node.dirty=true at line 216), so
1048
+ // passing prevScreen only benefits its subtree.
1049
+ // For removed children we don't know their original position, so
1050
+ // conservatively disable blit for all.
1051
+ //
1052
+ // Clipped children (overflow hidden/scroll on both axes) cannot overflow
1053
+ // onto later siblings — their content is confined to their layout bounds.
1054
+ // Skip the contamination guard for them so later siblings can still blit.
1055
+ // Without this, a spinner inside a ScrollBox dirties the wrapper on every
1056
+ // tick and the bottom prompt section never blits → 100% writes every frame.
1057
+ //
1058
+ // Exception: absolute-positioned clipped children may have layout bounds
1059
+ // that overlap arbitrary siblings, so the clipping does not help.
1060
+ //
1061
+ // Overlap contamination (seenDirtyClipped): a later ABSOLUTE sibling whose
1062
+ // rect sits inside a dirty clipped child's bounds would blit stale cells
1063
+ // from prevScreen — the clipped child just rewrote those cells this frame.
1064
+ // The clipsBothAxes skip only protects against OVERFLOW (clipped child
1065
+ // painting outside its bounds), not overlap (absolute sibling painting
1066
+ // inside them). For non-opaque absolute siblings, skipSelfBlit forces
1067
+ // descent (the full-width rect has transparent gaps → stale blit) while
1068
+ // still passing prevScreen so opaque descendants can blit their narrower
1069
+ // rects (NewMessagesPill's inner Text with backgroundColor). Opaque
1070
+ // absolute siblings fill their entire rect — direct blit is safe.
1071
+ function renderChildren(node, output, offsetX, offsetY, hasRemovedChild, prevScreen, inheritedBackgroundColor) {
1072
+ let seenDirtyChild = false;
1073
+ let seenDirtyClipped = false;
1074
+ for (const childNode of node.childNodes) {
1075
+ if (!isRenderableElementNode(childNode)) {
1076
+ continue;
1077
+ }
1078
+ const childElem = childNode;
1079
+ // Capture dirty before rendering — renderNodeToOutput clears the flag
1080
+ const wasDirty = childElem.dirty;
1081
+ const isAbsolute = childElem.style.position === 'absolute';
1082
+ renderNodeToOutput(childElem, output, {
1083
+ offsetX,
1084
+ offsetY,
1085
+ prevScreen: hasRemovedChild || seenDirtyChild ? undefined : prevScreen,
1086
+ // Short-circuits on seenDirtyClipped (false in the common case) so
1087
+ // the opaque/bg reads don't happen per-child per-frame.
1088
+ skipSelfBlit: seenDirtyClipped &&
1089
+ isAbsolute &&
1090
+ !childElem.style.opaque &&
1091
+ childElem.style.backgroundColor === undefined,
1092
+ inheritedBackgroundColor,
1093
+ });
1094
+ if (wasDirty && !seenDirtyChild) {
1095
+ if (!clipsBothAxes(childElem) || isAbsolute) {
1096
+ seenDirtyChild = true;
1097
+ }
1098
+ else {
1099
+ seenDirtyClipped = true;
1100
+ }
1101
+ }
1102
+ }
1103
+ }
1104
+ function clipsBothAxes(node) {
1105
+ const ox = node.style.overflowX ?? node.style.overflow;
1106
+ const oy = node.style.overflowY ?? node.style.overflow;
1107
+ return ((ox === 'hidden' || ox === 'scroll') && (oy === 'hidden' || oy === 'scroll'));
1108
+ }
1109
+ // When Yoga squeezes a box to h=0, the ghost only happens if a sibling
1110
+ // lands at the same computed top — then both write to that row and the
1111
+ // shorter content leaves the longer's tail visible. Yoga's pixel-grid
1112
+ // rounding can give h=0 while still advancing the next sibling's top
1113
+ // (HelpV2's third shortcuts column), so h=0 alone isn't sufficient.
1114
+ function siblingSharesY(node, yogaNode) {
1115
+ const parent = node.parentNode;
1116
+ if (!parent)
1117
+ return false;
1118
+ const myTop = yogaNode.getComputedTop();
1119
+ const siblings = parent.childNodes;
1120
+ const idx = siblings.indexOf(node);
1121
+ for (let i = idx + 1; i < siblings.length; i++) {
1122
+ const sibling = siblings[i];
1123
+ if (!isElementNode(sibling))
1124
+ continue;
1125
+ const sib = sibling.yogaNode;
1126
+ if (!sib)
1127
+ continue;
1128
+ return sib.getComputedTop() === myTop;
1129
+ }
1130
+ // No next sibling with a yoga node — check previous. A run of h=0 boxes
1131
+ // at the tail would all share y with each other.
1132
+ for (let i = idx - 1; i >= 0; i--) {
1133
+ const sibling = siblings[i];
1134
+ if (!isElementNode(sibling))
1135
+ continue;
1136
+ const sib = sibling.yogaNode;
1137
+ if (!sib)
1138
+ continue;
1139
+ return sib.getComputedTop() === myTop;
1140
+ }
1141
+ return false;
1142
+ }
1143
+ // When a node blits, its absolute-positioned descendants that paint outside
1144
+ // the node's layout bounds are NOT covered by the blit (which only copies
1145
+ // the node's own rect). If a dirty sibling re-rendered and overwrote those
1146
+ // cells, we must re-blit them from prevScreen so the overlays survive.
1147
+ // Example: PromptInputFooter's slash menu uses position='absolute' bottom='100%'
1148
+ // to float above the prompt; a spinner tick in the ScrollBox above re-renders
1149
+ // and overwrites those cells. Without this, the menu vanishes on the next frame.
1150
+ function blitEscapingAbsoluteDescendants(node, output, prevScreen, px, py, pw, ph) {
1151
+ const pr = px + pw;
1152
+ const pb = py + ph;
1153
+ for (const child of node.childNodes) {
1154
+ if (child.nodeName === '#text')
1155
+ continue;
1156
+ const elem = child;
1157
+ if (elem.style.position === 'absolute') {
1158
+ const cached = node_cache_js_1.nodeCache.get(elem);
1159
+ if (cached) {
1160
+ absoluteRectsCur.push(cached);
1161
+ const cx = Math.floor(cached.x);
1162
+ const cy = Math.floor(cached.y);
1163
+ const cw = Math.floor(cached.width);
1164
+ const ch = Math.floor(cached.height);
1165
+ // Only blit rects that extend outside the parent's layout bounds —
1166
+ // cells within the parent rect are already covered by the parent blit.
1167
+ if (cx < px || cy < py || cx + cw > pr || cy + ch > pb) {
1168
+ output.blit(prevScreen, cx, cy, cw, ch);
1169
+ }
1170
+ }
1171
+ }
1172
+ // Recurse — absolute descendants can be nested arbitrarily deep
1173
+ blitEscapingAbsoluteDescendants(elem, output, prevScreen, px, py, pw, ph);
1174
+ }
1175
+ }
1176
+ // Render children of a scroll container with viewport culling.
1177
+ // scrollTopY..scrollBottomY are the visible window in CHILD-LOCAL Yoga coords
1178
+ // (i.e. what getComputedTop() returns). Children entirely outside this window
1179
+ // are skipped; their nodeCache entry is deleted so if they re-enter the
1180
+ // viewport later they don't emit a stale clear for a position now occupied
1181
+ // by a sibling.
1182
+ function renderScrolledChildren(node, output, offsetX, offsetY, hasRemovedChild, prevScreen, scrollTopY, scrollBottomY, inheritedBackgroundColor,
1183
+ // When true (DECSTBM fast path), culled children keep their cache —
1184
+ // the blit+shift put stable rows in next.screen so stale cache is
1185
+ // never read. Avoids walking O(total_children * subtree_depth) per frame.
1186
+ preserveCulledCache = false) {
1187
+ let seenDirtyChild = false;
1188
+ // Track cumulative height shift of dirty children iterated so far. When
1189
+ // zero, a clean child's yogaTop is unchanged (no sibling above it grew),
1190
+ // so cached.top is fresh and the cull check skips yoga. Bottom-append
1191
+ // has the dirty child last → all prior clean children hit cache →
1192
+ // O(dirty) not O(mounted). Middle-growth leaves shift non-zero after
1193
+ // the dirty child → subsequent children yoga-read (needed for correct
1194
+ // culling since their yogaTop shifted).
1195
+ let cumHeightShift = 0;
1196
+ for (const childNode of node.childNodes) {
1197
+ if (!isRenderableElementNode(childNode)) {
1198
+ continue;
1199
+ }
1200
+ const childElem = childNode;
1201
+ const cy = childElem.yogaNode;
1202
+ if (cy) {
1203
+ const cached = node_cache_js_1.nodeCache.get(childElem);
1204
+ let top;
1205
+ let height;
1206
+ if (cached?.top !== undefined &&
1207
+ !childElem.dirty &&
1208
+ cumHeightShift === 0) {
1209
+ top = cached.top;
1210
+ height = cached.height;
1211
+ }
1212
+ else {
1213
+ top = cy.getComputedTop();
1214
+ height = cy.getComputedHeight();
1215
+ if (childElem.dirty) {
1216
+ cumHeightShift += height - (cached ? cached.height : 0);
1217
+ }
1218
+ // Refresh cached top so next frame's cumShift===0 path stays
1219
+ // correct. For culled children with preserveCulledCache=true this
1220
+ // is the ONLY refresh point — without it, a middle-growth frame
1221
+ // leaves stale tops that misfire next frame.
1222
+ if (cached)
1223
+ cached.top = top;
1224
+ }
1225
+ const bottom = top + height;
1226
+ if (bottom <= scrollTopY || top >= scrollBottomY) {
1227
+ // Culled — outside visible window. Drop stale cache entries from
1228
+ // the subtree so when this child re-enters it doesn't fire clears
1229
+ // at positions now occupied by siblings. The viewport-clear on
1230
+ // scroll-change handles the visible-area repaint.
1231
+ if (!preserveCulledCache)
1232
+ dropSubtreeCache(childElem);
1233
+ continue;
1234
+ }
1235
+ }
1236
+ const wasDirty = childElem.dirty;
1237
+ renderNodeToOutput(childElem, output, {
1238
+ offsetX,
1239
+ offsetY,
1240
+ prevScreen: hasRemovedChild || seenDirtyChild ? undefined : prevScreen,
1241
+ inheritedBackgroundColor,
1242
+ });
1243
+ if (wasDirty) {
1244
+ seenDirtyChild = true;
1245
+ }
1246
+ }
1247
+ }
1248
+ function dropSubtreeCache(node) {
1249
+ node_cache_js_1.nodeCache.delete(node);
1250
+ for (const child of node.childNodes) {
1251
+ if (child.nodeName !== '#text') {
1252
+ dropSubtreeCache(child);
1253
+ }
1254
+ }
1255
+ }
1256
+ exports.default = renderNodeToOutput;
1257
+ //# sourceMappingURL=render-node-to-output.js.map