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,1194 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.OSC8_PREFIX = exports.StylePool = exports.HyperlinkPool = exports.CharPool = void 0;
37
+ exports.isEmptyCellAt = isEmptyCellAt;
38
+ exports.isCellEmpty = isCellEmpty;
39
+ exports.createScreen = createScreen;
40
+ exports.resetScreen = resetScreen;
41
+ exports.migrateScreenPools = migrateScreenPools;
42
+ exports.cellAt = cellAt;
43
+ exports.cellAtIndex = cellAtIndex;
44
+ exports.visibleCellAtIndex = visibleCellAtIndex;
45
+ exports.charInCellAt = charInCellAt;
46
+ exports.setCellAt = setCellAt;
47
+ exports.setCellStyleId = setCellStyleId;
48
+ exports.blitRegion = blitRegion;
49
+ exports.clearRegion = clearRegion;
50
+ exports.shiftRows = shiftRows;
51
+ exports.extractHyperlinkFromStyles = extractHyperlinkFromStyles;
52
+ exports.filterOutHyperlinkStyles = filterOutHyperlinkStyles;
53
+ exports.diff = diff;
54
+ exports.diffEach = diffEach;
55
+ exports.markNoSelectRegion = markNoSelectRegion;
56
+ const ansi_tokenize_1 = require("@alcalzone/ansi-tokenize");
57
+ const geometry_js_1 = require("./layout/geometry.js");
58
+ const ansi_js_1 = require("./termio/ansi.js");
59
+ const warn = __importStar(require("./warn.js"));
60
+ // --- Shared Pools (interning for memory efficiency) ---
61
+ // Character string pool shared across all screens.
62
+ // With a shared pool, interned char IDs are valid across screens,
63
+ // so blitRegion can copy IDs directly (no re-interning) and
64
+ // diffEach can compare IDs as integers (no string lookup).
65
+ class CharPool {
66
+ constructor() {
67
+ this.strings = [' ', '']; // Index 0 = space, 1 = empty (spacer)
68
+ this.stringMap = new Map([
69
+ [' ', 0],
70
+ ['', 1],
71
+ ]);
72
+ this.ascii = initCharAscii(); // charCode → index, -1 = not interned
73
+ }
74
+ intern(char) {
75
+ // ASCII fast-path: direct array lookup instead of Map.get
76
+ if (char.length === 1) {
77
+ const code = char.charCodeAt(0);
78
+ if (code < 128) {
79
+ const cached = this.ascii[code];
80
+ if (cached !== -1)
81
+ return cached;
82
+ const index = this.strings.length;
83
+ this.strings.push(char);
84
+ this.ascii[code] = index;
85
+ return index;
86
+ }
87
+ }
88
+ const existing = this.stringMap.get(char);
89
+ if (existing !== undefined)
90
+ return existing;
91
+ const index = this.strings.length;
92
+ this.strings.push(char);
93
+ this.stringMap.set(char, index);
94
+ return index;
95
+ }
96
+ get(index) {
97
+ return this.strings[index] ?? ' ';
98
+ }
99
+ }
100
+ exports.CharPool = CharPool;
101
+ // Hyperlink string pool shared across all screens.
102
+ // Index 0 = no hyperlink.
103
+ class HyperlinkPool {
104
+ constructor() {
105
+ this.strings = ['']; // Index 0 = no hyperlink
106
+ this.stringMap = new Map();
107
+ }
108
+ intern(hyperlink) {
109
+ if (!hyperlink)
110
+ return 0;
111
+ let id = this.stringMap.get(hyperlink);
112
+ if (id === undefined) {
113
+ id = this.strings.length;
114
+ this.strings.push(hyperlink);
115
+ this.stringMap.set(hyperlink, id);
116
+ }
117
+ return id;
118
+ }
119
+ get(id) {
120
+ return id === 0 ? undefined : this.strings[id];
121
+ }
122
+ }
123
+ exports.HyperlinkPool = HyperlinkPool;
124
+ // SGR 7 (inverse) as an AnsiCode. endCode '\x1b[27m' flags VISIBLE_ON_SPACE
125
+ // so bit 0 of the resulting styleId is set → renderer won't skip inverted
126
+ // spaces as invisible.
127
+ const INVERSE_CODE = {
128
+ type: 'ansi',
129
+ code: '\x1b[7m',
130
+ endCode: '\x1b[27m',
131
+ };
132
+ // Bold (SGR 1) — stacks cleanly, no reflow in monospace. endCode 22
133
+ // also cancels dim (SGR 2); harmless here since we never add dim.
134
+ const BOLD_CODE = {
135
+ type: 'ansi',
136
+ code: '\x1b[1m',
137
+ endCode: '\x1b[22m',
138
+ };
139
+ // Underline (SGR 4). Kept alongside yellow+bold — the underline is the
140
+ // unambiguous visible-on-any-theme marker. Yellow-bg-via-inverse can
141
+ // clash with existing bg colors (user-prompt style, tool chrome, syntax
142
+ // bg). If you see underline but no yellow, the yellow is being lost in
143
+ // the existing cell styling — the overlay IS finding the match.
144
+ const UNDERLINE_CODE = {
145
+ type: 'ansi',
146
+ code: '\x1b[4m',
147
+ endCode: '\x1b[24m',
148
+ };
149
+ // fg→yellow (SGR 33). With inverse already in the stack, the terminal
150
+ // swaps fg↔bg at render — so yellow-fg becomes yellow-BG. Original bg
151
+ // becomes fg (readable on most themes: dark-bg → dark-text on yellow).
152
+ // endCode 39 is 'default fg' — cancels any prior fg color cleanly.
153
+ const YELLOW_FG_CODE = {
154
+ type: 'ansi',
155
+ code: '\x1b[33m',
156
+ endCode: '\x1b[39m',
157
+ };
158
+ class StylePool {
159
+ constructor() {
160
+ this.ids = new Map();
161
+ this.styles = [];
162
+ this.transitionCache = new Map();
163
+ /**
164
+ * Intern a style that is `base + inverse`. Cached by base ID so
165
+ * repeated calls for the same underlying style don't re-scan the
166
+ * AnsiCode[] array. Used by the selection overlay.
167
+ */
168
+ this.inverseCache = new Map();
169
+ /** Inverse + bold + yellow-bg-via-fg-swap for the CURRENT search match.
170
+ * OTHER matches are plain inverse — bg inherits from the theme. Current
171
+ * gets a distinct yellow bg (via fg-then-inverse swap) plus bold weight
172
+ * so it stands out in a sea of inverse. Underline was too subtle. Zero
173
+ * reflow risk: all pure SGR overlays, per-cell, post-layout. The yellow
174
+ * overrides any existing fg (syntax highlighting) on those cells — fine,
175
+ * the "you are here" signal IS the point, syntax color can yield. */
176
+ this.currentMatchCache = new Map();
177
+ /**
178
+ * Selection overlay: REPLACE the cell's background with a solid color
179
+ * while preserving its foreground (color, bold, italic, dim, underline).
180
+ * Matches native terminal selection — a dedicated bg color, not SGR-7
181
+ * inverse. Inverse swaps fg/bg per-cell, which fragments visually over
182
+ * syntax-highlighted text (every fg color becomes a different bg stripe).
183
+ *
184
+ * Strips any existing bg (endCode 49m — REPLACES, so diff-added green
185
+ * etc. don't bleed through) and any existing inverse (endCode 27m —
186
+ * inverse on top of a solid bg would re-swap and look wrong).
187
+ *
188
+ * bg is set via setSelectionBg(); null → fallback to withInverse() so the
189
+ * overlay still works before theme wiring sets a color (tests, first frame).
190
+ * Cache is keyed by baseId only — setSelectionBg() clears it on change.
191
+ */
192
+ this.selectionBgCode = null;
193
+ this.selectionBgCache = new Map();
194
+ this.none = this.intern([]);
195
+ }
196
+ /**
197
+ * Intern a style and return its ID. Bit 0 of the ID encodes whether the
198
+ * style has a visible effect on space characters (background, inverse,
199
+ * underline, etc.). Foreground-only styles get even IDs; styles visible
200
+ * on spaces get odd IDs. This lets the renderer skip invisible spaces
201
+ * with a single bitmask check on the packed word.
202
+ */
203
+ intern(styles) {
204
+ const key = styles.length === 0 ? '' : styles.map(s => s.code).join('\0');
205
+ let id = this.ids.get(key);
206
+ if (id === undefined) {
207
+ const rawId = this.styles.length;
208
+ this.styles.push(styles.length === 0 ? [] : styles);
209
+ id =
210
+ (rawId << 1) |
211
+ (styles.length > 0 && hasVisibleSpaceEffect(styles) ? 1 : 0);
212
+ this.ids.set(key, id);
213
+ }
214
+ return id;
215
+ }
216
+ /** Recover styles from an encoded ID. Strips the bit-0 flag via >>> 1. */
217
+ get(id) {
218
+ return this.styles[id >>> 1] ?? [];
219
+ }
220
+ /**
221
+ * Returns the pre-serialized ANSI string to transition from one style to
222
+ * another. Cached by (fromId, toId) — zero allocations after first call
223
+ * for a given pair.
224
+ */
225
+ transition(fromId, toId) {
226
+ if (fromId === toId)
227
+ return '';
228
+ const key = fromId * 0x100000 + toId;
229
+ let str = this.transitionCache.get(key);
230
+ if (str === undefined) {
231
+ str = (0, ansi_tokenize_1.ansiCodesToString)((0, ansi_tokenize_1.diffAnsiCodes)(this.get(fromId), this.get(toId)));
232
+ this.transitionCache.set(key, str);
233
+ }
234
+ return str;
235
+ }
236
+ withInverse(baseId) {
237
+ let id = this.inverseCache.get(baseId);
238
+ if (id === undefined) {
239
+ const baseCodes = this.get(baseId);
240
+ // If already inverted, use as-is (avoids SGR 7 stacking)
241
+ const hasInverse = baseCodes.some(c => c.endCode === '\x1b[27m');
242
+ id = hasInverse ? baseId : this.intern([...baseCodes, INVERSE_CODE]);
243
+ this.inverseCache.set(baseId, id);
244
+ }
245
+ return id;
246
+ }
247
+ withCurrentMatch(baseId) {
248
+ let id = this.currentMatchCache.get(baseId);
249
+ if (id === undefined) {
250
+ const baseCodes = this.get(baseId);
251
+ // Filter BOTH fg + bg so yellow-via-inverse is unambiguous.
252
+ // User-prompt cells have an explicit bg (grey box); with that bg
253
+ // still set, inverse swaps yellow-fg↔grey-bg → grey-on-yellow on
254
+ // SOME terminals, yellow-on-grey on others (inverse semantics vary
255
+ // when both colors are explicit). Filtering both gives clean
256
+ // yellow-bg + terminal-default-fg everywhere. Bold/dim/italic
257
+ // coexist — keep those.
258
+ const codes = baseCodes.filter(c => c.endCode !== '\x1b[39m' && c.endCode !== '\x1b[49m');
259
+ // fg-yellow FIRST so inverse swaps it to bg. Bold after inverse is
260
+ // fine — SGR 1 is fg-attribute-only, order-independent vs 7.
261
+ codes.push(YELLOW_FG_CODE);
262
+ if (!baseCodes.some(c => c.endCode === '\x1b[27m'))
263
+ codes.push(INVERSE_CODE);
264
+ if (!baseCodes.some(c => c.endCode === '\x1b[22m'))
265
+ codes.push(BOLD_CODE);
266
+ // Underline as the unambiguous marker — yellow-bg can clash with
267
+ // existing bg styling (user-prompt bg, syntax bg). If you see
268
+ // underline but no yellow on a match, the overlay IS finding it;
269
+ // the yellow is just losing a styling fight.
270
+ if (!baseCodes.some(c => c.endCode === '\x1b[24m'))
271
+ codes.push(UNDERLINE_CODE);
272
+ id = this.intern(codes);
273
+ this.currentMatchCache.set(baseId, id);
274
+ }
275
+ return id;
276
+ }
277
+ setSelectionBg(bg) {
278
+ if (this.selectionBgCode?.code === bg?.code)
279
+ return;
280
+ this.selectionBgCode = bg;
281
+ this.selectionBgCache.clear();
282
+ }
283
+ withSelectionBg(baseId) {
284
+ const bg = this.selectionBgCode;
285
+ if (bg === null)
286
+ return this.withInverse(baseId);
287
+ let id = this.selectionBgCache.get(baseId);
288
+ if (id === undefined) {
289
+ // Keep everything except bg (49m) and inverse (27m). Fg, bold, dim,
290
+ // italic, underline, strikethrough all preserved.
291
+ const kept = this.get(baseId).filter(c => c.endCode !== '\x1b[49m' && c.endCode !== '\x1b[27m');
292
+ kept.push(bg);
293
+ id = this.intern(kept);
294
+ this.selectionBgCache.set(baseId, id);
295
+ }
296
+ return id;
297
+ }
298
+ }
299
+ exports.StylePool = StylePool;
300
+ // endCodes that produce visible effects on space characters
301
+ const VISIBLE_ON_SPACE = new Set([
302
+ '\x1b[49m', // background color
303
+ '\x1b[27m', // inverse
304
+ '\x1b[24m', // underline
305
+ '\x1b[29m', // strikethrough
306
+ '\x1b[55m', // overline
307
+ ]);
308
+ function hasVisibleSpaceEffect(styles) {
309
+ for (const style of styles) {
310
+ if (VISIBLE_ON_SPACE.has(style.endCode))
311
+ return true;
312
+ }
313
+ return false;
314
+ }
315
+ // Constants for empty/spacer cells to enable fast comparisons
316
+ // These are indices into the charStrings table, not codepoints
317
+ const EMPTY_CHAR_INDEX = 0; // ' ' (space)
318
+ const SPACER_CHAR_INDEX = 1; // '' (empty string for spacer cells)
319
+ // Unwritten cells are [EMPTY_CHAR_INDEX=0, packWord1(emptyStyleId=0,0,0)=0].
320
+ // Since StylePool.none is always 0 (first intern), unwritten cells are
321
+ // indistinguishable from explicitly-cleared cells in the packed array.
322
+ // This is intentional: diffEach can compare raw ints with zero normalization.
323
+ // isEmptyCellByIndex checks if both words are 0 to identify "never visually written" cells.
324
+ function initCharAscii() {
325
+ const table = new Int32Array(128);
326
+ table.fill(-1);
327
+ table[32] = EMPTY_CHAR_INDEX; // ' ' (space)
328
+ return table;
329
+ }
330
+ // --- Packed cell layout ---
331
+ // Each cell is 2 consecutive Int32 elements in the cells array:
332
+ // word0 (cells[ci]): charId (full 32 bits)
333
+ // word1 (cells[ci + 1]): styleId[31:17] | hyperlinkId[16:2] | width[1:0]
334
+ const STYLE_SHIFT = 17;
335
+ const HYPERLINK_SHIFT = 2;
336
+ const HYPERLINK_MASK = 0x7fff; // 15 bits
337
+ const WIDTH_MASK = 3; // 2 bits
338
+ // Pack styleId, hyperlinkId, and width into a single Int32
339
+ function packWord1(styleId, hyperlinkId, width) {
340
+ return (styleId << STYLE_SHIFT) | (hyperlinkId << HYPERLINK_SHIFT) | width;
341
+ }
342
+ // Unwritten cell as BigInt64 — both words are 0, so the 64-bit value is 0n.
343
+ // Used by BigInt64Array.fill() for bulk clears (resetScreen, clearRegion).
344
+ // Not used for comparison — BigInt element reads cause heap allocation.
345
+ const EMPTY_CELL_VALUE = 0n;
346
+ function isEmptyCellByIndex(screen, index) {
347
+ // An empty/unwritten cell has both words === 0:
348
+ // word0 = EMPTY_CHAR_INDEX (0), word1 = packWord1(emptyStyleId=0, 0, 0) = 0.
349
+ const ci = index << 1;
350
+ return screen.cells[ci] === 0 && screen.cells[ci | 1] === 0;
351
+ }
352
+ function isEmptyCellAt(screen, x, y) {
353
+ if (x < 0 || y < 0 || x >= screen.width || y >= screen.height)
354
+ return true;
355
+ return isEmptyCellByIndex(screen, y * screen.width + x);
356
+ }
357
+ /**
358
+ * Check if a Cell (view object) represents an empty cell.
359
+ */
360
+ function isCellEmpty(screen, cell) {
361
+ // Check if cell looks like an empty cell (space, empty style, narrow, no link).
362
+ // Note: After cellAt mapping, unwritten cells have emptyStyleId, so this
363
+ // returns true for both unwritten AND cleared cells. Use isEmptyCellAt
364
+ // for the internal distinction.
365
+ return (cell.char === ' ' &&
366
+ cell.styleId === screen.emptyStyleId &&
367
+ cell.width === 0 /* CellWidth.Narrow */ &&
368
+ !cell.hyperlink);
369
+ }
370
+ // Intern a hyperlink string and return its ID (0 = no hyperlink)
371
+ function internHyperlink(screen, hyperlink) {
372
+ return screen.hyperlinkPool.intern(hyperlink);
373
+ }
374
+ // ---
375
+ function createScreen(width, height, styles, charPool, hyperlinkPool) {
376
+ // Warn if dimensions are not valid integers (likely bad yoga layout output)
377
+ warn.ifNotInteger(width, 'createScreen width');
378
+ warn.ifNotInteger(height, 'createScreen height');
379
+ // Ensure width and height are valid integers to prevent crashes
380
+ if (!Number.isInteger(width) || width < 0) {
381
+ width = Math.max(0, Math.floor(width) || 0);
382
+ }
383
+ if (!Number.isInteger(height) || height < 0) {
384
+ height = Math.max(0, Math.floor(height) || 0);
385
+ }
386
+ const size = width * height;
387
+ // Allocate one buffer, two views: Int32Array for per-word access,
388
+ // BigInt64Array for bulk fill in resetScreen/clearRegion.
389
+ // ArrayBuffer is zero-filled, which is exactly the empty cell value:
390
+ // [EMPTY_CHAR_INDEX=0, packWord1(emptyStyleId=0,0,0)=0].
391
+ const buf = new ArrayBuffer(size << 3); // 8 bytes per cell
392
+ const cells = new Int32Array(buf);
393
+ const cells64 = new BigInt64Array(buf);
394
+ return {
395
+ width,
396
+ height,
397
+ cells,
398
+ cells64,
399
+ charPool,
400
+ hyperlinkPool,
401
+ emptyStyleId: styles.none,
402
+ damage: undefined,
403
+ noSelect: new Uint8Array(size),
404
+ softWrap: new Int32Array(height),
405
+ };
406
+ }
407
+ /**
408
+ * Reset an existing screen for reuse, avoiding allocation of new typed arrays.
409
+ * Resizes if needed and clears all cells to empty/unwritten state.
410
+ *
411
+ * For double-buffering, this allows swapping between front and back buffers
412
+ * without allocating new Screen objects each frame.
413
+ */
414
+ function resetScreen(screen, width, height) {
415
+ // Warn if dimensions are not valid integers
416
+ warn.ifNotInteger(width, 'resetScreen width');
417
+ warn.ifNotInteger(height, 'resetScreen height');
418
+ // Ensure width and height are valid integers to prevent crashes
419
+ if (!Number.isInteger(width) || width < 0) {
420
+ width = Math.max(0, Math.floor(width) || 0);
421
+ }
422
+ if (!Number.isInteger(height) || height < 0) {
423
+ height = Math.max(0, Math.floor(height) || 0);
424
+ }
425
+ const size = width * height;
426
+ // Resize if needed (only grow, to avoid reallocations)
427
+ if (screen.cells64.length < size) {
428
+ const buf = new ArrayBuffer(size << 3);
429
+ screen.cells = new Int32Array(buf);
430
+ screen.cells64 = new BigInt64Array(buf);
431
+ screen.noSelect = new Uint8Array(size);
432
+ }
433
+ if (screen.softWrap.length < height) {
434
+ screen.softWrap = new Int32Array(height);
435
+ }
436
+ // Reset all cells — single fill call, no loop
437
+ screen.cells64.fill(EMPTY_CELL_VALUE, 0, size);
438
+ screen.noSelect.fill(0, 0, size);
439
+ screen.softWrap.fill(0, 0, height);
440
+ // Update dimensions
441
+ screen.width = width;
442
+ screen.height = height;
443
+ // Shared pools accumulate — no clearing needed. Unique char/hyperlink sets are bounded.
444
+ // Clear damage tracking
445
+ screen.damage = undefined;
446
+ }
447
+ /**
448
+ * Re-intern a screen's char and hyperlink IDs into new pools.
449
+ * Used for generational pool reset — after migrating, the screen's
450
+ * typed arrays contain valid IDs for the new pools, and the old pools
451
+ * can be GC'd.
452
+ *
453
+ * O(width * height) but only called occasionally (e.g., between conversation turns).
454
+ */
455
+ function migrateScreenPools(screen, charPool, hyperlinkPool) {
456
+ const oldCharPool = screen.charPool;
457
+ const oldHyperlinkPool = screen.hyperlinkPool;
458
+ if (oldCharPool === charPool && oldHyperlinkPool === hyperlinkPool)
459
+ return;
460
+ const size = screen.width * screen.height;
461
+ const cells = screen.cells;
462
+ // Re-intern chars and hyperlinks in a single pass, stride by 2
463
+ for (let ci = 0; ci < size << 1; ci += 2) {
464
+ // Re-intern charId (word0)
465
+ const oldCharId = cells[ci];
466
+ cells[ci] = charPool.intern(oldCharPool.get(oldCharId));
467
+ // Re-intern hyperlinkId (packed in word1)
468
+ const word1 = cells[ci + 1];
469
+ const oldHyperlinkId = (word1 >>> HYPERLINK_SHIFT) & HYPERLINK_MASK;
470
+ if (oldHyperlinkId !== 0) {
471
+ const oldStr = oldHyperlinkPool.get(oldHyperlinkId);
472
+ const newHyperlinkId = hyperlinkPool.intern(oldStr);
473
+ // Repack word1 with new hyperlinkId, preserving styleId and width
474
+ const styleId = word1 >>> STYLE_SHIFT;
475
+ const width = word1 & WIDTH_MASK;
476
+ cells[ci + 1] = packWord1(styleId, newHyperlinkId, width);
477
+ }
478
+ }
479
+ screen.charPool = charPool;
480
+ screen.hyperlinkPool = hyperlinkPool;
481
+ }
482
+ /**
483
+ * Get a Cell view at the given position. Returns a new object each call -
484
+ * this is intentional as cells are stored packed, not as objects.
485
+ */
486
+ function cellAt(screen, x, y) {
487
+ if (x < 0 || y < 0 || x >= screen.width || y >= screen.height)
488
+ return undefined;
489
+ return cellAtIndex(screen, y * screen.width + x);
490
+ }
491
+ /**
492
+ * Get a Cell view by pre-computed array index. Skips bounds checks and
493
+ * index computation — caller must ensure index is valid.
494
+ */
495
+ function cellAtIndex(screen, index) {
496
+ const ci = index << 1;
497
+ const word1 = screen.cells[ci + 1];
498
+ const hid = (word1 >>> HYPERLINK_SHIFT) & HYPERLINK_MASK;
499
+ return {
500
+ // Unwritten cells have charIndex=0 (EMPTY_CHAR_INDEX); charPool.get(0) returns ' '
501
+ char: screen.charPool.get(screen.cells[ci]),
502
+ styleId: word1 >>> STYLE_SHIFT,
503
+ width: word1 & WIDTH_MASK,
504
+ hyperlink: hid === 0 ? undefined : screen.hyperlinkPool.get(hid),
505
+ };
506
+ }
507
+ /**
508
+ * Get a Cell at the given index, or undefined if it has no visible content.
509
+ * Returns undefined for spacer cells (charId 1), empty unstyled spaces, and
510
+ * fg-only styled spaces that match lastRenderedStyleId (cursor-forward
511
+ * produces an identical visual result, avoiding a Cell allocation).
512
+ *
513
+ * @param lastRenderedStyleId - styleId of the last rendered cell on this
514
+ * line, or -1 if none yet.
515
+ */
516
+ function visibleCellAtIndex(cells, charPool, hyperlinkPool, index, lastRenderedStyleId) {
517
+ const ci = index << 1;
518
+ const charId = cells[ci];
519
+ if (charId === 1)
520
+ return undefined; // spacer
521
+ const word1 = cells[ci + 1];
522
+ // For spaces: 0x3fffc masks bits 2-17 (hyperlinkId + styleId visibility
523
+ // bit). If zero, the space has no hyperlink and at most a fg-only style.
524
+ // Then word1 >>> STYLE_SHIFT is the foreground style — skip if it's zero
525
+ // (truly invisible) or matches the last rendered style on this line.
526
+ if (charId === 0 && (word1 & 0x3fffc) === 0) {
527
+ const fgStyle = word1 >>> STYLE_SHIFT;
528
+ if (fgStyle === 0 || fgStyle === lastRenderedStyleId)
529
+ return undefined;
530
+ }
531
+ const hid = (word1 >>> HYPERLINK_SHIFT) & HYPERLINK_MASK;
532
+ return {
533
+ char: charPool.get(charId),
534
+ styleId: word1 >>> STYLE_SHIFT,
535
+ width: word1 & WIDTH_MASK,
536
+ hyperlink: hid === 0 ? undefined : hyperlinkPool.get(hid),
537
+ };
538
+ }
539
+ /**
540
+ * Write cell data into an existing Cell object to avoid allocation.
541
+ * Caller must ensure index is valid.
542
+ */
543
+ function cellAtCI(screen, ci, out) {
544
+ const w1 = ci | 1;
545
+ const word1 = screen.cells[w1];
546
+ out.char = screen.charPool.get(screen.cells[ci]);
547
+ out.styleId = word1 >>> STYLE_SHIFT;
548
+ out.width = word1 & WIDTH_MASK;
549
+ const hid = (word1 >>> HYPERLINK_SHIFT) & HYPERLINK_MASK;
550
+ out.hyperlink = hid === 0 ? undefined : screen.hyperlinkPool.get(hid);
551
+ }
552
+ function charInCellAt(screen, x, y) {
553
+ if (x < 0 || y < 0 || x >= screen.width || y >= screen.height)
554
+ return undefined;
555
+ const ci = (y * screen.width + x) << 1;
556
+ return screen.charPool.get(screen.cells[ci]);
557
+ }
558
+ /**
559
+ * Set a cell, optionally creating a spacer for wide characters.
560
+ *
561
+ * Wide characters (CJK, emoji) occupy 2 cells in the buffer:
562
+ * 1. First cell: Contains the actual character with width = Wide
563
+ * 2. Second cell: Spacer cell with width = SpacerTail (empty, not rendered)
564
+ *
565
+ * If the cell has width = Wide, this function automatically creates the
566
+ * corresponding SpacerTail in the next column. This two-cell model keeps
567
+ * the buffer aligned to visual columns, making cursor positioning
568
+ * straightforward.
569
+ *
570
+ * TODO: When soft-wrapping is implemented, SpacerHead cells will be explicitly
571
+ * placed by the wrapping logic at line-end positions where wide characters
572
+ * wrap to the next line. This function doesn't need to handle SpacerHead
573
+ * automatically - it will be set directly by the wrapping code.
574
+ */
575
+ function setCellAt(screen, x, y, cell) {
576
+ if (x < 0 || y < 0 || x >= screen.width || y >= screen.height)
577
+ return;
578
+ const ci = (y * screen.width + x) << 1;
579
+ const cells = screen.cells;
580
+ // When a Wide char is overwritten by a Narrow char, its SpacerTail remains
581
+ // as a ghost cell that the diff/render pipeline skips, causing stale content
582
+ // to leak through from previous frames.
583
+ const prevWidth = cells[ci + 1] & WIDTH_MASK;
584
+ if (prevWidth === 1 /* CellWidth.Wide */ && cell.width !== 1 /* CellWidth.Wide */) {
585
+ const spacerX = x + 1;
586
+ if (spacerX < screen.width) {
587
+ const spacerCI = ci + 2;
588
+ if ((cells[spacerCI + 1] & WIDTH_MASK) === 2 /* CellWidth.SpacerTail */) {
589
+ cells[spacerCI] = EMPTY_CHAR_INDEX;
590
+ cells[spacerCI + 1] = packWord1(screen.emptyStyleId, 0, 0 /* CellWidth.Narrow */);
591
+ }
592
+ }
593
+ }
594
+ // Track cleared Wide position for damage expansion below
595
+ let clearedWideX = -1;
596
+ if (prevWidth === 2 /* CellWidth.SpacerTail */ &&
597
+ cell.width !== 2 /* CellWidth.SpacerTail */) {
598
+ // Overwriting a SpacerTail: clear the orphaned Wide char at (x-1).
599
+ // Keeping the wide character with Narrow width would cause the terminal
600
+ // to still render it with width 2, desyncing the cursor model.
601
+ if (x > 0) {
602
+ const wideCI = ci - 2;
603
+ if ((cells[wideCI + 1] & WIDTH_MASK) === 1 /* CellWidth.Wide */) {
604
+ cells[wideCI] = EMPTY_CHAR_INDEX;
605
+ cells[wideCI + 1] = packWord1(screen.emptyStyleId, 0, 0 /* CellWidth.Narrow */);
606
+ clearedWideX = x - 1;
607
+ }
608
+ }
609
+ }
610
+ // Pack cell data into cells array
611
+ cells[ci] = internCharString(screen, cell.char);
612
+ cells[ci + 1] = packWord1(cell.styleId, internHyperlink(screen, cell.hyperlink), cell.width);
613
+ // Track damage - expand bounds in place instead of allocating new objects
614
+ // Include the main cell position and any cleared orphan cells
615
+ const minX = clearedWideX >= 0 ? Math.min(x, clearedWideX) : x;
616
+ const damage = screen.damage;
617
+ if (damage) {
618
+ const right = damage.x + damage.width;
619
+ const bottom = damage.y + damage.height;
620
+ if (minX < damage.x) {
621
+ damage.width += damage.x - minX;
622
+ damage.x = minX;
623
+ }
624
+ else if (x >= right) {
625
+ damage.width = x - damage.x + 1;
626
+ }
627
+ if (y < damage.y) {
628
+ damage.height += damage.y - y;
629
+ damage.y = y;
630
+ }
631
+ else if (y >= bottom) {
632
+ damage.height = y - damage.y + 1;
633
+ }
634
+ }
635
+ else {
636
+ screen.damage = { x: minX, y, width: x - minX + 1, height: 1 };
637
+ }
638
+ // If this is a wide character, create a spacer in the next column
639
+ if (cell.width === 1 /* CellWidth.Wide */) {
640
+ const spacerX = x + 1;
641
+ if (spacerX < screen.width) {
642
+ const spacerCI = ci + 2;
643
+ // If the cell we're overwriting with our SpacerTail is itself Wide,
644
+ // clear ITS SpacerTail at x+2 too. Otherwise the orphan SpacerTail
645
+ // makes diffEach report it as `added` and log-update's skip-spacer
646
+ // rule prevents clearing whatever prev content was at that column.
647
+ // Scenario: [a, 💻, spacer] → [本, spacer, ORPHAN spacer] when
648
+ // yoga squishes a💻 to height 0 and 本 renders at the same y.
649
+ if ((cells[spacerCI + 1] & WIDTH_MASK) === 1 /* CellWidth.Wide */) {
650
+ const orphanCI = spacerCI + 2;
651
+ if (spacerX + 1 < screen.width &&
652
+ (cells[orphanCI + 1] & WIDTH_MASK) === 2 /* CellWidth.SpacerTail */) {
653
+ cells[orphanCI] = EMPTY_CHAR_INDEX;
654
+ cells[orphanCI + 1] = packWord1(screen.emptyStyleId, 0, 0 /* CellWidth.Narrow */);
655
+ }
656
+ }
657
+ cells[spacerCI] = SPACER_CHAR_INDEX;
658
+ cells[spacerCI + 1] = packWord1(screen.emptyStyleId, 0, 2 /* CellWidth.SpacerTail */);
659
+ // Expand damage to include SpacerTail so diff() scans it
660
+ const d = screen.damage;
661
+ if (d && spacerX >= d.x + d.width) {
662
+ d.width = spacerX - d.x + 1;
663
+ }
664
+ }
665
+ }
666
+ }
667
+ /**
668
+ * Replace the styleId of a cell in-place without disturbing char, width,
669
+ * or hyperlink. Preserves empty cells as-is (char stays ' '). Tracks damage
670
+ * for the cell so diffEach picks up the change.
671
+ */
672
+ function setCellStyleId(screen, x, y, styleId) {
673
+ if (x < 0 || y < 0 || x >= screen.width || y >= screen.height)
674
+ return;
675
+ const ci = (y * screen.width + x) << 1;
676
+ const cells = screen.cells;
677
+ const word1 = cells[ci + 1];
678
+ const width = word1 & WIDTH_MASK;
679
+ // Skip spacer cells — inverse on the head cell visually covers both columns
680
+ if (width === 2 /* CellWidth.SpacerTail */ || width === 3 /* CellWidth.SpacerHead */)
681
+ return;
682
+ const hid = (word1 >>> HYPERLINK_SHIFT) & HYPERLINK_MASK;
683
+ cells[ci + 1] = packWord1(styleId, hid, width);
684
+ // Expand damage so diffEach scans this cell
685
+ const d = screen.damage;
686
+ if (d) {
687
+ screen.damage = (0, geometry_js_1.unionRect)(d, { x, y, width: 1, height: 1 });
688
+ }
689
+ else {
690
+ screen.damage = { x, y, width: 1, height: 1 };
691
+ }
692
+ }
693
+ /**
694
+ * Intern a character string via the screen's shared CharPool.
695
+ * Supports grapheme clusters like family emoji.
696
+ */
697
+ function internCharString(screen, char) {
698
+ return screen.charPool.intern(char);
699
+ }
700
+ /**
701
+ * Bulk-copy a rectangular region from src to dst using TypedArray.set().
702
+ * Single cells.set() call per row (or one call for contiguous blocks).
703
+ * Damage is computed once for the whole region.
704
+ *
705
+ * Clamps negative regionX/regionY to 0 (matching clearRegion) — absolute-
706
+ * positioned overlays in tiny terminals can compute negative screen coords.
707
+ * maxX/maxY should already be clamped to both screen bounds by the caller.
708
+ */
709
+ function blitRegion(dst, src, regionX, regionY, maxX, maxY) {
710
+ regionX = Math.max(0, regionX);
711
+ regionY = Math.max(0, regionY);
712
+ if (regionX >= maxX || regionY >= maxY)
713
+ return;
714
+ const rowLen = maxX - regionX;
715
+ const srcStride = src.width << 1;
716
+ const dstStride = dst.width << 1;
717
+ const rowBytes = rowLen << 1; // 2 Int32s per cell
718
+ const srcCells = src.cells;
719
+ const dstCells = dst.cells;
720
+ const srcNoSel = src.noSelect;
721
+ const dstNoSel = dst.noSelect;
722
+ // softWrap is per-row — copy the row range regardless of stride/width.
723
+ // Partial-width blits still carry the row's wrap provenance since the
724
+ // blitted content (a cached ink-text node) is what set the bit.
725
+ dst.softWrap.set(src.softWrap.subarray(regionY, maxY), regionY);
726
+ // Fast path: contiguous memory when copying full-width rows at same stride
727
+ if (regionX === 0 && maxX === src.width && src.width === dst.width) {
728
+ const srcStart = regionY * srcStride;
729
+ const totalBytes = (maxY - regionY) * srcStride;
730
+ dstCells.set(srcCells.subarray(srcStart, srcStart + totalBytes), srcStart);
731
+ // noSelect is 1 byte/cell vs cells' 8 — same region, different scale
732
+ const nsStart = regionY * src.width;
733
+ const nsLen = (maxY - regionY) * src.width;
734
+ dstNoSel.set(srcNoSel.subarray(nsStart, nsStart + nsLen), nsStart);
735
+ }
736
+ else {
737
+ // Per-row copy for partial-width or mismatched-stride regions
738
+ let srcRowCI = regionY * srcStride + (regionX << 1);
739
+ let dstRowCI = regionY * dstStride + (regionX << 1);
740
+ let srcRowNS = regionY * src.width + regionX;
741
+ let dstRowNS = regionY * dst.width + regionX;
742
+ for (let y = regionY; y < maxY; y++) {
743
+ dstCells.set(srcCells.subarray(srcRowCI, srcRowCI + rowBytes), dstRowCI);
744
+ dstNoSel.set(srcNoSel.subarray(srcRowNS, srcRowNS + rowLen), dstRowNS);
745
+ srcRowCI += srcStride;
746
+ dstRowCI += dstStride;
747
+ srcRowNS += src.width;
748
+ dstRowNS += dst.width;
749
+ }
750
+ }
751
+ // Compute damage once for the whole region
752
+ const regionRect = {
753
+ x: regionX,
754
+ y: regionY,
755
+ width: rowLen,
756
+ height: maxY - regionY,
757
+ };
758
+ if (dst.damage) {
759
+ dst.damage = (0, geometry_js_1.unionRect)(dst.damage, regionRect);
760
+ }
761
+ else {
762
+ dst.damage = regionRect;
763
+ }
764
+ // Handle wide char at right edge: spacer might be outside blit region
765
+ // but still within dst bounds. Per-row check only at the boundary column.
766
+ if (maxX < dst.width) {
767
+ let srcLastCI = (regionY * src.width + (maxX - 1)) << 1;
768
+ let dstSpacerCI = (regionY * dst.width + maxX) << 1;
769
+ let wroteSpacerOutsideRegion = false;
770
+ for (let y = regionY; y < maxY; y++) {
771
+ if ((srcCells[srcLastCI + 1] & WIDTH_MASK) === 1 /* CellWidth.Wide */) {
772
+ dstCells[dstSpacerCI] = SPACER_CHAR_INDEX;
773
+ dstCells[dstSpacerCI + 1] = packWord1(dst.emptyStyleId, 0, 2 /* CellWidth.SpacerTail */);
774
+ wroteSpacerOutsideRegion = true;
775
+ }
776
+ srcLastCI += srcStride;
777
+ dstSpacerCI += dstStride;
778
+ }
779
+ // Expand damage to include SpacerTail column if we wrote any
780
+ if (wroteSpacerOutsideRegion && dst.damage) {
781
+ const rightEdge = dst.damage.x + dst.damage.width;
782
+ if (rightEdge === maxX) {
783
+ dst.damage = { ...dst.damage, width: dst.damage.width + 1 };
784
+ }
785
+ }
786
+ }
787
+ }
788
+ /**
789
+ * Bulk-clear a rectangular region of the screen.
790
+ * Uses BigInt64Array.fill() for fast row clears.
791
+ * Handles wide character boundary cleanup at region edges.
792
+ */
793
+ function clearRegion(screen, regionX, regionY, regionWidth, regionHeight) {
794
+ const startX = Math.max(0, regionX);
795
+ const startY = Math.max(0, regionY);
796
+ const maxX = Math.min(regionX + regionWidth, screen.width);
797
+ const maxY = Math.min(regionY + regionHeight, screen.height);
798
+ if (startX >= maxX || startY >= maxY)
799
+ return;
800
+ const cells = screen.cells;
801
+ const cells64 = screen.cells64;
802
+ const screenWidth = screen.width;
803
+ const rowBase = startY * screenWidth;
804
+ let damageMinX = startX;
805
+ let damageMaxX = maxX;
806
+ // EMPTY_CELL_VALUE (0n) matches the zero-initialized state:
807
+ // word0=EMPTY_CHAR_INDEX(0), word1=packWord1(0,0,0)=0
808
+ if (startX === 0 && maxX === screenWidth) {
809
+ // Full-width: single fill, no boundary checks needed
810
+ cells64.fill(EMPTY_CELL_VALUE, rowBase, rowBase + (maxY - startY) * screenWidth);
811
+ }
812
+ else {
813
+ // Partial-width: single loop handles boundary cleanup and fill per row.
814
+ const stride = screenWidth << 1; // 2 Int32s per cell
815
+ const rowLen = maxX - startX;
816
+ const checkLeft = startX > 0;
817
+ const checkRight = maxX < screenWidth;
818
+ let leftEdge = (rowBase + startX) << 1;
819
+ let rightEdge = (rowBase + maxX - 1) << 1;
820
+ let fillStart = rowBase + startX;
821
+ for (let y = startY; y < maxY; y++) {
822
+ // Left boundary: if cell at startX is a SpacerTail, the Wide char
823
+ // at startX-1 (outside the region) will be orphaned. Clear it.
824
+ if (checkLeft) {
825
+ // leftEdge points to word0 of cell at startX; +1 is its word1
826
+ if ((cells[leftEdge + 1] & WIDTH_MASK) === 2 /* CellWidth.SpacerTail */) {
827
+ // word1 of cell at startX-1 is leftEdge-1; word0 is leftEdge-2
828
+ const prevW1 = leftEdge - 1;
829
+ if ((cells[prevW1] & WIDTH_MASK) === 1 /* CellWidth.Wide */) {
830
+ cells[prevW1 - 1] = EMPTY_CHAR_INDEX;
831
+ cells[prevW1] = packWord1(screen.emptyStyleId, 0, 0 /* CellWidth.Narrow */);
832
+ damageMinX = startX - 1;
833
+ }
834
+ }
835
+ }
836
+ // Right boundary: if cell at maxX-1 is Wide, its SpacerTail at maxX
837
+ // (outside the region) will be orphaned. Clear it.
838
+ if (checkRight) {
839
+ // rightEdge points to word0 of cell at maxX-1; +1 is its word1
840
+ if ((cells[rightEdge + 1] & WIDTH_MASK) === 1 /* CellWidth.Wide */) {
841
+ // word1 of cell at maxX is rightEdge+3 (+2 to next word0, +1 to word1)
842
+ const nextW1 = rightEdge + 3;
843
+ if ((cells[nextW1] & WIDTH_MASK) === 2 /* CellWidth.SpacerTail */) {
844
+ cells[nextW1 - 1] = EMPTY_CHAR_INDEX;
845
+ cells[nextW1] = packWord1(screen.emptyStyleId, 0, 0 /* CellWidth.Narrow */);
846
+ damageMaxX = maxX + 1;
847
+ }
848
+ }
849
+ }
850
+ cells64.fill(EMPTY_CELL_VALUE, fillStart, fillStart + rowLen);
851
+ leftEdge += stride;
852
+ rightEdge += stride;
853
+ fillStart += screenWidth;
854
+ }
855
+ }
856
+ // Update damage once for the whole region
857
+ const regionRect = {
858
+ x: damageMinX,
859
+ y: startY,
860
+ width: damageMaxX - damageMinX,
861
+ height: maxY - startY,
862
+ };
863
+ if (screen.damage) {
864
+ screen.damage = (0, geometry_js_1.unionRect)(screen.damage, regionRect);
865
+ }
866
+ else {
867
+ screen.damage = regionRect;
868
+ }
869
+ }
870
+ /**
871
+ * Shift full-width rows within [top, bottom] (inclusive, 0-indexed) by n.
872
+ * n > 0 shifts UP (simulating CSI n S); n < 0 shifts DOWN (CSI n T).
873
+ * Vacated rows are cleared. Does NOT update damage. Both cells and the
874
+ * noSelect bitmap are shifted so text-selection markers stay aligned when
875
+ * this is applied to next.screen during scroll fast path.
876
+ */
877
+ function shiftRows(screen, top, bottom, n) {
878
+ if (n === 0 || top < 0 || bottom >= screen.height || top > bottom)
879
+ return;
880
+ const w = screen.width;
881
+ const cells64 = screen.cells64;
882
+ const noSel = screen.noSelect;
883
+ const sw = screen.softWrap;
884
+ const absN = Math.abs(n);
885
+ if (absN > bottom - top) {
886
+ cells64.fill(EMPTY_CELL_VALUE, top * w, (bottom + 1) * w);
887
+ noSel.fill(0, top * w, (bottom + 1) * w);
888
+ sw.fill(0, top, bottom + 1);
889
+ return;
890
+ }
891
+ if (n > 0) {
892
+ // SU: row top+n..bottom → top..bottom-n; clear bottom-n+1..bottom
893
+ cells64.copyWithin(top * w, (top + n) * w, (bottom + 1) * w);
894
+ noSel.copyWithin(top * w, (top + n) * w, (bottom + 1) * w);
895
+ sw.copyWithin(top, top + n, bottom + 1);
896
+ cells64.fill(EMPTY_CELL_VALUE, (bottom - n + 1) * w, (bottom + 1) * w);
897
+ noSel.fill(0, (bottom - n + 1) * w, (bottom + 1) * w);
898
+ sw.fill(0, bottom - n + 1, bottom + 1);
899
+ }
900
+ else {
901
+ // SD: row top..bottom+n → top-n..bottom; clear top..top-n-1
902
+ cells64.copyWithin((top - n) * w, top * w, (bottom + n + 1) * w);
903
+ noSel.copyWithin((top - n) * w, top * w, (bottom + n + 1) * w);
904
+ sw.copyWithin(top - n, top, bottom + n + 1);
905
+ cells64.fill(EMPTY_CELL_VALUE, top * w, (top - n) * w);
906
+ noSel.fill(0, top * w, (top - n) * w);
907
+ sw.fill(0, top, top - n);
908
+ }
909
+ }
910
+ // Matches OSC 8 ; ; URI BEL
911
+ const OSC8_REGEX = new RegExp(`^${ansi_js_1.ESC}\\]8${ansi_js_1.SEP}${ansi_js_1.SEP}([^${ansi_js_1.BEL}]*)${ansi_js_1.BEL}$`);
912
+ // OSC8 prefix: ESC ] 8 ; — cheap check to skip regex for the vast majority of styles (SGR = ESC [)
913
+ exports.OSC8_PREFIX = `${ansi_js_1.ESC}]8${ansi_js_1.SEP}`;
914
+ function extractHyperlinkFromStyles(styles) {
915
+ for (const style of styles) {
916
+ const code = style.code;
917
+ if (code.length < 5 || !code.startsWith(exports.OSC8_PREFIX))
918
+ continue;
919
+ const match = code.match(OSC8_REGEX);
920
+ if (match) {
921
+ return match[1] || null;
922
+ }
923
+ }
924
+ return null;
925
+ }
926
+ function filterOutHyperlinkStyles(styles) {
927
+ return styles.filter(style => !style.code.startsWith(exports.OSC8_PREFIX) || !OSC8_REGEX.test(style.code));
928
+ }
929
+ // ---
930
+ /**
931
+ * Returns an array of all changes between two screens. Used by tests.
932
+ * Production code should use diffEach() to avoid allocations.
933
+ */
934
+ function diff(prev, next) {
935
+ const output = [];
936
+ diffEach(prev, next, (x, y, removed, added) => {
937
+ // Copy cells since diffEach reuses the objects
938
+ output.push([
939
+ { x, y },
940
+ removed ? { ...removed } : undefined,
941
+ added ? { ...added } : undefined,
942
+ ]);
943
+ });
944
+ return output;
945
+ }
946
+ /**
947
+ * Like diff(), but calls a callback for each change instead of building an array.
948
+ * Reuses two Cell objects to avoid per-change allocations. The callback must not
949
+ * retain references to the Cell objects — their contents are overwritten each call.
950
+ *
951
+ * Returns true if the callback ever returned true (early exit signal).
952
+ */
953
+ function diffEach(prev, next, cb) {
954
+ const prevWidth = prev.width;
955
+ const nextWidth = next.width;
956
+ const prevHeight = prev.height;
957
+ const nextHeight = next.height;
958
+ let region;
959
+ if (prevWidth === 0 && prevHeight === 0) {
960
+ region = { x: 0, y: 0, width: nextWidth, height: nextHeight };
961
+ }
962
+ else if (next.damage) {
963
+ region = next.damage;
964
+ if (prev.damage) {
965
+ region = (0, geometry_js_1.unionRect)(region, prev.damage);
966
+ }
967
+ }
968
+ else if (prev.damage) {
969
+ region = prev.damage;
970
+ }
971
+ else {
972
+ region = { x: 0, y: 0, width: 0, height: 0 };
973
+ }
974
+ if (prevHeight > nextHeight) {
975
+ region = (0, geometry_js_1.unionRect)(region, {
976
+ x: 0,
977
+ y: nextHeight,
978
+ width: prevWidth,
979
+ height: prevHeight - nextHeight,
980
+ });
981
+ }
982
+ if (prevWidth > nextWidth) {
983
+ region = (0, geometry_js_1.unionRect)(region, {
984
+ x: nextWidth,
985
+ y: 0,
986
+ width: prevWidth - nextWidth,
987
+ height: prevHeight,
988
+ });
989
+ }
990
+ const maxHeight = Math.max(prevHeight, nextHeight);
991
+ const maxWidth = Math.max(prevWidth, nextWidth);
992
+ const endY = Math.min(region.y + region.height, maxHeight);
993
+ const endX = Math.min(region.x + region.width, maxWidth);
994
+ if (prevWidth === nextWidth) {
995
+ return diffSameWidth(prev, next, region.x, endX, region.y, endY, cb);
996
+ }
997
+ return diffDifferentWidth(prev, next, region.x, endX, region.y, endY, cb);
998
+ }
999
+ /**
1000
+ * Scan for the next cell that differs between two Int32Arrays.
1001
+ * Returns the number of matching cells before the first difference,
1002
+ * or `count` if all cells match. Tiny and pure for JIT inlining.
1003
+ */
1004
+ function findNextDiff(a, b, w0, count) {
1005
+ for (let i = 0; i < count; i++, w0 += 2) {
1006
+ const w1 = w0 | 1;
1007
+ if (a[w0] !== b[w0] || a[w1] !== b[w1])
1008
+ return i;
1009
+ }
1010
+ return count;
1011
+ }
1012
+ /**
1013
+ * Diff one row where both screens are in bounds.
1014
+ * Scans for differences with findNextDiff, unpacks and calls cb for each.
1015
+ */
1016
+ function diffRowBoth(prevCells, nextCells, prev, next, ci, y, startX, endX, prevCell, nextCell, cb) {
1017
+ let x = startX;
1018
+ while (x < endX) {
1019
+ const skip = findNextDiff(prevCells, nextCells, ci, endX - x);
1020
+ x += skip;
1021
+ ci += skip << 1;
1022
+ if (x >= endX)
1023
+ break;
1024
+ cellAtCI(prev, ci, prevCell);
1025
+ cellAtCI(next, ci, nextCell);
1026
+ if (cb(x, y, prevCell, nextCell))
1027
+ return true;
1028
+ x++;
1029
+ ci += 2;
1030
+ }
1031
+ return false;
1032
+ }
1033
+ /**
1034
+ * Emit removals for a row that only exists in prev (height shrank).
1035
+ * Cannot skip empty cells — the terminal still has content from the
1036
+ * previous frame that needs to be cleared.
1037
+ */
1038
+ function diffRowRemoved(prev, ci, y, startX, endX, prevCell, cb) {
1039
+ for (let x = startX; x < endX; x++, ci += 2) {
1040
+ cellAtCI(prev, ci, prevCell);
1041
+ if (cb(x, y, prevCell, undefined))
1042
+ return true;
1043
+ }
1044
+ return false;
1045
+ }
1046
+ /**
1047
+ * Emit additions for a row that only exists in next (height grew).
1048
+ * Skips empty/unwritten cells.
1049
+ */
1050
+ function diffRowAdded(nextCells, next, ci, y, startX, endX, nextCell, cb) {
1051
+ for (let x = startX; x < endX; x++, ci += 2) {
1052
+ if (nextCells[ci] === 0 && nextCells[ci | 1] === 0)
1053
+ continue;
1054
+ cellAtCI(next, ci, nextCell);
1055
+ if (cb(x, y, undefined, nextCell))
1056
+ return true;
1057
+ }
1058
+ return false;
1059
+ }
1060
+ /**
1061
+ * Diff two screens with identical width.
1062
+ * Dispatches each row to a small, JIT-friendly function.
1063
+ */
1064
+ function diffSameWidth(prev, next, startX, endX, startY, endY, cb) {
1065
+ const prevCells = prev.cells;
1066
+ const nextCells = next.cells;
1067
+ const width = prev.width;
1068
+ const prevHeight = prev.height;
1069
+ const nextHeight = next.height;
1070
+ const stride = width << 1;
1071
+ const prevCell = {
1072
+ char: ' ',
1073
+ styleId: 0,
1074
+ width: 0 /* CellWidth.Narrow */,
1075
+ hyperlink: undefined,
1076
+ };
1077
+ const nextCell = {
1078
+ char: ' ',
1079
+ styleId: 0,
1080
+ width: 0 /* CellWidth.Narrow */,
1081
+ hyperlink: undefined,
1082
+ };
1083
+ const rowEndX = Math.min(endX, width);
1084
+ let rowCI = (startY * width + startX) << 1;
1085
+ for (let y = startY; y < endY; y++) {
1086
+ const prevIn = y < prevHeight;
1087
+ const nextIn = y < nextHeight;
1088
+ if (prevIn && nextIn) {
1089
+ if (diffRowBoth(prevCells, nextCells, prev, next, rowCI, y, startX, rowEndX, prevCell, nextCell, cb))
1090
+ return true;
1091
+ }
1092
+ else if (prevIn) {
1093
+ if (diffRowRemoved(prev, rowCI, y, startX, rowEndX, prevCell, cb))
1094
+ return true;
1095
+ }
1096
+ else if (nextIn) {
1097
+ if (diffRowAdded(nextCells, next, rowCI, y, startX, rowEndX, nextCell, cb))
1098
+ return true;
1099
+ }
1100
+ rowCI += stride;
1101
+ }
1102
+ return false;
1103
+ }
1104
+ /**
1105
+ * Fallback: diff two screens with different widths (resize).
1106
+ * Separate indices for prev and next cells arrays.
1107
+ */
1108
+ function diffDifferentWidth(prev, next, startX, endX, startY, endY, cb) {
1109
+ const prevWidth = prev.width;
1110
+ const nextWidth = next.width;
1111
+ const prevCells = prev.cells;
1112
+ const nextCells = next.cells;
1113
+ const prevCell = {
1114
+ char: ' ',
1115
+ styleId: 0,
1116
+ width: 0 /* CellWidth.Narrow */,
1117
+ hyperlink: undefined,
1118
+ };
1119
+ const nextCell = {
1120
+ char: ' ',
1121
+ styleId: 0,
1122
+ width: 0 /* CellWidth.Narrow */,
1123
+ hyperlink: undefined,
1124
+ };
1125
+ const prevStride = prevWidth << 1;
1126
+ const nextStride = nextWidth << 1;
1127
+ let prevRowCI = (startY * prevWidth + startX) << 1;
1128
+ let nextRowCI = (startY * nextWidth + startX) << 1;
1129
+ for (let y = startY; y < endY; y++) {
1130
+ const prevIn = y < prev.height;
1131
+ const nextIn = y < next.height;
1132
+ const prevEndX = prevIn ? Math.min(endX, prevWidth) : startX;
1133
+ const nextEndX = nextIn ? Math.min(endX, nextWidth) : startX;
1134
+ const bothEndX = Math.min(prevEndX, nextEndX);
1135
+ let prevCI = prevRowCI;
1136
+ let nextCI = nextRowCI;
1137
+ for (let x = startX; x < bothEndX; x++) {
1138
+ if (prevCells[prevCI] === nextCells[nextCI] &&
1139
+ prevCells[prevCI + 1] === nextCells[nextCI + 1]) {
1140
+ prevCI += 2;
1141
+ nextCI += 2;
1142
+ continue;
1143
+ }
1144
+ cellAtCI(prev, prevCI, prevCell);
1145
+ cellAtCI(next, nextCI, nextCell);
1146
+ prevCI += 2;
1147
+ nextCI += 2;
1148
+ if (cb(x, y, prevCell, nextCell))
1149
+ return true;
1150
+ }
1151
+ if (prevEndX > bothEndX) {
1152
+ prevCI = prevRowCI + ((bothEndX - startX) << 1);
1153
+ for (let x = bothEndX; x < prevEndX; x++) {
1154
+ cellAtCI(prev, prevCI, prevCell);
1155
+ prevCI += 2;
1156
+ if (cb(x, y, prevCell, undefined))
1157
+ return true;
1158
+ }
1159
+ }
1160
+ if (nextEndX > bothEndX) {
1161
+ nextCI = nextRowCI + ((bothEndX - startX) << 1);
1162
+ for (let x = bothEndX; x < nextEndX; x++) {
1163
+ if (nextCells[nextCI] === 0 && nextCells[nextCI | 1] === 0) {
1164
+ nextCI += 2;
1165
+ continue;
1166
+ }
1167
+ cellAtCI(next, nextCI, nextCell);
1168
+ nextCI += 2;
1169
+ if (cb(x, y, undefined, nextCell))
1170
+ return true;
1171
+ }
1172
+ }
1173
+ prevRowCI += prevStride;
1174
+ nextRowCI += nextStride;
1175
+ }
1176
+ return false;
1177
+ }
1178
+ /**
1179
+ * Mark a rectangular region as noSelect (exclude from text selection).
1180
+ * Clamps to screen bounds. Called from output.ts when a <NoSelect> box
1181
+ * renders. No damage tracking — noSelect doesn't affect terminal output,
1182
+ * only getSelectedText/applySelectionOverlay which read it directly.
1183
+ */
1184
+ function markNoSelectRegion(screen, x, y, width, height) {
1185
+ const maxX = Math.min(x + width, screen.width);
1186
+ const maxY = Math.min(y + height, screen.height);
1187
+ const noSel = screen.noSelect;
1188
+ const stride = screen.width;
1189
+ for (let row = Math.max(0, y); row < maxY; row++) {
1190
+ const rowStart = row * stride;
1191
+ noSel.fill(1, rowStart + Math.max(0, x), rowStart + maxX);
1192
+ }
1193
+ }
1194
+ //# sourceMappingURL=screen.js.map