@bubblebrain-ai/bubble 0.0.52 → 0.0.53

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 (481) hide show
  1. package/README.md +4 -12
  2. package/dist/agent/routing-catalog.js +3 -2
  3. package/dist/agent/subagent/router.js +5 -0
  4. package/dist/agent/subagent/runtime.d.ts +1 -0
  5. package/dist/agent/subagent/runtime.js +13 -1
  6. package/dist/agent/subagent-control.d.ts +4 -0
  7. package/dist/agent/subagent-control.js +1 -0
  8. package/dist/agent/subagent-store.js +2 -0
  9. package/dist/agent/workflow/control.d.ts +2 -0
  10. package/dist/agent/workflow/runs.d.ts +1 -0
  11. package/dist/agent/workflow/runs.js +3 -0
  12. package/dist/agent.d.ts +11 -1
  13. package/dist/agent.js +158 -57
  14. package/dist/bin.js +2 -44
  15. package/dist/config.d.ts +14 -1
  16. package/dist/config.js +45 -4
  17. package/dist/context/budget.d.ts +7 -1
  18. package/dist/context/budget.js +25 -2
  19. package/dist/context/compact-llm.d.ts +1 -1
  20. package/dist/context/compact-llm.js +5 -2
  21. package/dist/context/overflow.js +2 -0
  22. package/dist/context/projector.d.ts +8 -0
  23. package/dist/context/projector.js +55 -6
  24. package/dist/context/tool-output-truncate.d.ts +17 -1
  25. package/dist/context/tool-output-truncate.js +171 -49
  26. package/dist/feishu/agent-host/run-driver.js +3 -0
  27. package/dist/feishu/serve.js +2 -0
  28. package/dist/goal/command.d.ts +1 -1
  29. package/dist/goal/command.js +7 -2
  30. package/dist/main.d.ts +1 -1
  31. package/dist/main.js +38 -8
  32. package/dist/memory/db.js +0 -7
  33. package/dist/model-catalog.js +25 -6
  34. package/dist/model-config.js +3 -2
  35. package/dist/model-pricing.d.ts +24 -5
  36. package/dist/model-pricing.js +0 -0
  37. package/dist/model-selection.js +13 -4
  38. package/dist/network/chatgpt-transport.js +0 -34
  39. package/dist/network/errors.d.ts +19 -0
  40. package/dist/network/errors.js +24 -0
  41. package/dist/network/provider-transport.d.ts +0 -4
  42. package/dist/network/provider-transport.js +3 -35
  43. package/dist/network/retry.d.ts +6 -1
  44. package/dist/network/retry.js +9 -0
  45. package/dist/provider-model-policy.d.ts +16 -0
  46. package/dist/provider-model-policy.js +33 -0
  47. package/dist/provider-registry.d.ts +1 -1
  48. package/dist/provider-registry.js +73 -10
  49. package/dist/provider-transform.js +32 -4
  50. package/dist/provider.d.ts +6 -2
  51. package/dist/provider.js +95 -6
  52. package/dist/question/controller.js +5 -4
  53. package/dist/question/normalize.d.ts +6 -0
  54. package/dist/question/normalize.js +11 -0
  55. package/dist/rewind.d.ts +20 -0
  56. package/dist/rewind.js +29 -0
  57. package/dist/sdk/index.d.ts +1 -1
  58. package/dist/sdk/index.js +11 -3
  59. package/dist/session.d.ts +7 -0
  60. package/dist/session.js +20 -0
  61. package/dist/skills/discovery.js +18 -0
  62. package/dist/skills/registry.d.ts +12 -2
  63. package/dist/skills/registry.js +40 -5
  64. package/dist/skills/types.d.ts +2 -0
  65. package/dist/slash-commands/commands.js +120 -81
  66. package/dist/slash-commands/registry.d.ts +2 -1
  67. package/dist/slash-commands/registry.js +3 -0
  68. package/dist/slash-commands/types.d.ts +22 -4
  69. package/dist/stats/usage.d.ts +3 -1
  70. package/dist/stats/usage.js +22 -13
  71. package/dist/tasks/manager.d.ts +4 -2
  72. package/dist/tasks/manager.js +34 -9
  73. package/dist/tasks/promotion.d.ts +2 -2
  74. package/dist/tasks/promotion.js +2 -2
  75. package/dist/tools/agent-lifecycle.js +4 -0
  76. package/dist/tools/bash.d.ts +3 -1
  77. package/dist/tools/bash.js +13 -2
  78. package/dist/tools/grep.d.ts +5 -1
  79. package/dist/tools/grep.js +318 -69
  80. package/dist/tools/index.d.ts +3 -1
  81. package/dist/tools/index.js +1 -0
  82. package/dist/tools/question.js +5 -4
  83. package/dist/tools/read.js +40 -21
  84. package/dist/tui/animation-clock.d.ts +14 -0
  85. package/dist/tui/animation-clock.js +34 -0
  86. package/dist/tui/app.d.ts +176 -0
  87. package/dist/tui/app.js +1647 -0
  88. package/dist/tui/components/approval-dialog.d.ts +43 -0
  89. package/dist/tui/components/approval-dialog.js +247 -0
  90. package/dist/tui/components/bottom-sheet.d.ts +9 -0
  91. package/dist/tui/components/bottom-sheet.js +32 -0
  92. package/dist/tui/components/context-info.d.ts +54 -0
  93. package/dist/tui/components/context-info.js +388 -0
  94. package/dist/tui/components/feedback-dialog.d.ts +56 -0
  95. package/dist/tui/components/feedback-dialog.js +262 -0
  96. package/dist/tui/components/feishu-setup-dialog.d.ts +65 -0
  97. package/dist/tui/components/feishu-setup-dialog.js +332 -0
  98. package/dist/tui/components/image-preview.d.ts +32 -0
  99. package/dist/tui/components/image-preview.js +130 -0
  100. package/dist/tui/components/plan-dialog.d.ts +34 -0
  101. package/dist/tui/components/plan-dialog.js +196 -0
  102. package/dist/tui/components/provider-key-input.d.ts +18 -0
  103. package/dist/tui/components/provider-key-input.js +49 -0
  104. package/dist/tui/components/question-dialog.d.ts +25 -0
  105. package/dist/tui/components/question-dialog.js +263 -0
  106. package/dist/tui/components/responsive-transcript.d.ts +31 -0
  107. package/dist/tui/components/responsive-transcript.js +77 -0
  108. package/dist/tui/components/rewind-picker.d.ts +62 -0
  109. package/dist/tui/components/rewind-picker.js +317 -0
  110. package/dist/tui/components/session-picker.d.ts +49 -0
  111. package/dist/tui/components/session-picker.js +303 -0
  112. package/dist/tui/components/skills-panel.d.ts +59 -0
  113. package/dist/tui/components/skills-panel.js +568 -0
  114. package/dist/tui/components/stats-panel.d.ts +40 -0
  115. package/dist/tui/components/stats-panel.js +301 -0
  116. package/dist/tui/components/streaming-message.d.ts +69 -0
  117. package/dist/tui/components/streaming-message.js +393 -0
  118. package/dist/tui/components/subagent-inspector.d.ts +28 -0
  119. package/dist/tui/components/subagent-inspector.js +127 -0
  120. package/dist/tui/components/task-inspector.d.ts +26 -0
  121. package/dist/tui/components/task-inspector.js +70 -0
  122. package/dist/tui/components/tasks-pane.d.ts +88 -0
  123. package/dist/tui/components/tasks-pane.js +416 -0
  124. package/dist/tui/components/transcript.d.ts +96 -0
  125. package/dist/tui/components/transcript.js +771 -0
  126. package/dist/tui/components/welcome.d.ts +20 -0
  127. package/dist/tui/components/welcome.js +133 -0
  128. package/dist/tui/components/workflow-inspector.d.ts +30 -0
  129. package/dist/tui/components/workflow-inspector.js +136 -0
  130. package/dist/tui/composer-autocomplete.d.ts +61 -0
  131. package/dist/tui/composer-autocomplete.js +383 -0
  132. package/dist/tui/composer-style.d.ts +7 -0
  133. package/dist/tui/composer-style.js +29 -0
  134. package/dist/tui/controller/agent-event-reducer.d.ts +75 -0
  135. package/dist/tui/controller/agent-event-reducer.js +238 -0
  136. package/dist/tui/controller/composer-controller.d.ts +95 -0
  137. package/dist/tui/controller/composer-controller.js +502 -0
  138. package/dist/tui/controller/controller.d.ts +194 -0
  139. package/dist/tui/controller/controller.js +1035 -0
  140. package/dist/tui/controller/effects.d.ts +71 -0
  141. package/dist/tui/controller/effects.js +1 -0
  142. package/dist/tui/controller/goal-runtime-controller.d.ts +47 -0
  143. package/dist/tui/controller/goal-runtime-controller.js +202 -0
  144. package/dist/tui/controller/input-queue-machine.d.ts +71 -0
  145. package/dist/tui/controller/input-queue-machine.js +121 -0
  146. package/dist/tui/controller/intents.d.ts +56 -0
  147. package/dist/tui/controller/intents.js +6 -0
  148. package/dist/tui/controller/overlay-controller.d.ts +64 -0
  149. package/dist/tui/controller/overlay-controller.js +129 -0
  150. package/dist/tui/controller/ports.d.ts +57 -0
  151. package/dist/tui/controller/ports.js +9 -0
  152. package/dist/tui/controller/session-transition.d.ts +54 -0
  153. package/dist/tui/controller/session-transition.js +68 -0
  154. package/dist/tui/controller/state.d.ts +14 -0
  155. package/dist/tui/controller/state.js +36 -0
  156. package/dist/tui/controller/task-runtime-controller.d.ts +66 -0
  157. package/dist/tui/controller/task-runtime-controller.js +158 -0
  158. package/dist/tui/footer.d.ts +37 -0
  159. package/dist/tui/footer.js +80 -0
  160. package/dist/{tui-ink → tui/formatting}/edit-diff.d.ts +1 -1
  161. package/dist/{tui-ink → tui/formatting}/edit-diff.js +1 -1
  162. package/dist/{tui-ink/app-helpers.d.ts → tui/formatting/summary.d.ts} +4 -4
  163. package/dist/{tui-ink/app-helpers.js → tui/formatting/summary.js} +2 -2
  164. package/dist/tui/fullscreen.d.ts +48 -0
  165. package/dist/tui/fullscreen.js +255 -0
  166. package/dist/tui/image-display.d.ts +4 -0
  167. package/dist/tui/image-display.js +30 -12
  168. package/dist/tui/markdown-style.d.ts +5 -0
  169. package/dist/tui/markdown-style.js +23 -0
  170. package/dist/{tui-ink → tui/model}/composer-buffer.js +1 -1
  171. package/dist/tui/model/composer-types.d.ts +17 -0
  172. package/dist/tui/model/composer-types.js +1 -0
  173. package/dist/{tui-ink → tui/model}/display-history.d.ts +7 -1
  174. package/dist/{tui-ink → tui/model}/display-reconstruct.d.ts +1 -1
  175. package/dist/{tui-ink → tui/model}/display-reconstruct.js +54 -6
  176. package/dist/{tui-ink → tui/model}/file-mentions.d.ts +2 -0
  177. package/dist/{tui-ink → tui/model}/file-mentions.js +4 -0
  178. package/dist/tui/model/image-attachment.d.ts +15 -0
  179. package/dist/tui/model/image-attachment.js +1 -0
  180. package/dist/{tui-ink → tui/model}/image-paste.d.ts +7 -1
  181. package/dist/{tui-ink → tui/model}/image-paste.js +46 -0
  182. package/dist/tui/model/input-history.d.ts +1 -0
  183. package/dist/tui/model/input-history.js +1 -0
  184. package/dist/{tui-ink → tui/model}/input-queue.d.ts +1 -1
  185. package/dist/{tui-ink → tui/model}/recent-activity.js +1 -1
  186. package/dist/{tui-ink → tui/model}/subagent-view.d.ts +17 -2
  187. package/dist/{tui-ink → tui/model}/subagent-view.js +125 -4
  188. package/dist/{tui-ink → tui/model}/submit-dedupe.d.ts +1 -1
  189. package/dist/tui/model/theme-style.d.ts +10 -0
  190. package/dist/tui/model/theme-style.js +79 -0
  191. package/dist/{tui-ink → tui/model}/theme.d.ts +11 -23
  192. package/dist/{tui-ink → tui/model}/theme.js +23 -38
  193. package/dist/{tui-ink → tui/model}/trace-groups.d.ts +2 -0
  194. package/dist/{tui-ink → tui/model}/trace-groups.js +91 -30
  195. package/dist/tui/model/trace-interaction.d.ts +63 -0
  196. package/dist/tui/model/trace-interaction.js +87 -0
  197. package/dist/tui/model-picker-data.d.ts +1 -2
  198. package/dist/tui/model-picker-data.js +8 -1
  199. package/dist/tui/model-switch.js +2 -0
  200. package/dist/{tui-ink → tui}/run-session-picker.d.ts +2 -3
  201. package/dist/tui/run-session-picker.js +64 -0
  202. package/dist/tui/run.d.ts +72 -0
  203. package/dist/tui/run.js +139 -0
  204. package/dist/tui/terminal/multiplexer.d.ts +5 -0
  205. package/dist/tui/terminal/multiplexer.js +14 -0
  206. package/dist/tui/testing/fake-agent.d.ts +24 -0
  207. package/dist/tui/testing/fake-agent.js +22 -0
  208. package/dist/tui/testing/spy-host.d.ts +21 -0
  209. package/dist/tui/testing/spy-host.js +55 -0
  210. package/dist/tui/trace-groups.js +27 -6
  211. package/dist/types.d.ts +7 -0
  212. package/node_modules/@bubblebrain-ai/pi-tui/LICENSE +21 -0
  213. package/node_modules/@bubblebrain-ai/pi-tui/README.md +854 -0
  214. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/alt-screen-search.d.ts +26 -0
  215. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/alt-screen-search.d.ts.map +1 -0
  216. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/alt-screen-search.js +121 -0
  217. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/alt-screen-search.js.map +1 -0
  218. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/autocomplete.d.ts +86 -0
  219. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/autocomplete.d.ts.map +1 -0
  220. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/autocomplete.js +649 -0
  221. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/autocomplete.js.map +1 -0
  222. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/alt-screen-flash.d.ts +13 -0
  223. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/alt-screen-flash.d.ts.map +1 -0
  224. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/alt-screen-flash.js +36 -0
  225. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/alt-screen-flash.js.map +1 -0
  226. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/box.d.ts +22 -0
  227. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/box.d.ts.map +1 -0
  228. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/box.js +99 -0
  229. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/box.js.map +1 -0
  230. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/cancellable-loader.d.ts +22 -0
  231. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/cancellable-loader.d.ts.map +1 -0
  232. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/cancellable-loader.js +36 -0
  233. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/cancellable-loader.js.map +1 -0
  234. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/editor.d.ts +330 -0
  235. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/editor.d.ts.map +1 -0
  236. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/editor.js +2344 -0
  237. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/editor.js.map +1 -0
  238. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/h-stack.d.ts +7 -0
  239. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/h-stack.d.ts.map +1 -0
  240. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/h-stack.js +43 -0
  241. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/h-stack.js.map +1 -0
  242. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/image.d.ts +28 -0
  243. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/image.d.ts.map +1 -0
  244. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/image.js +82 -0
  245. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/image.js.map +1 -0
  246. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/input.d.ts +48 -0
  247. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/input.d.ts.map +1 -0
  248. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/input.js +390 -0
  249. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/input.js.map +1 -0
  250. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/loader.d.ts +31 -0
  251. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/loader.d.ts.map +1 -0
  252. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/loader.js +67 -0
  253. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/loader.js.map +1 -0
  254. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/markdown.d.ts +103 -0
  255. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/markdown.d.ts.map +1 -0
  256. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/markdown.js +797 -0
  257. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/markdown.js.map +1 -0
  258. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/scroll-view.d.ts +56 -0
  259. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/scroll-view.d.ts.map +1 -0
  260. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/scroll-view.js +179 -0
  261. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/scroll-view.js.map +1 -0
  262. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/select-list.d.ts +53 -0
  263. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/select-list.d.ts.map +1 -0
  264. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/select-list.js +175 -0
  265. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/select-list.js.map +1 -0
  266. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/settings-list.d.ts +50 -0
  267. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/settings-list.d.ts.map +1 -0
  268. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/settings-list.js +174 -0
  269. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/settings-list.js.map +1 -0
  270. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/spacer.d.ts +12 -0
  271. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/spacer.d.ts.map +1 -0
  272. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/spacer.js +22 -0
  273. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/spacer.js.map +1 -0
  274. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/stack.d.ts +32 -0
  275. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/stack.d.ts.map +1 -0
  276. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/stack.js +109 -0
  277. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/stack.js.map +1 -0
  278. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/text.d.ts +19 -0
  279. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/text.d.ts.map +1 -0
  280. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/text.js +81 -0
  281. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/text.js.map +1 -0
  282. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/truncated-text.d.ts +13 -0
  283. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/truncated-text.d.ts.map +1 -0
  284. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/truncated-text.js +48 -0
  285. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/truncated-text.js.map +1 -0
  286. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/v-stack.d.ts +8 -0
  287. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/v-stack.d.ts.map +1 -0
  288. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/v-stack.js +26 -0
  289. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/components/v-stack.js.map +1 -0
  290. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/editor-component.d.ts +39 -0
  291. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/editor-component.d.ts.map +1 -0
  292. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/editor-component.js +2 -0
  293. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/editor-component.js.map +1 -0
  294. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/fuzzy.d.ts +16 -0
  295. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/fuzzy.d.ts.map +1 -0
  296. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/fuzzy.js +110 -0
  297. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/fuzzy.js.map +1 -0
  298. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/index.d.ts +31 -0
  299. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/index.d.ts.map +1 -0
  300. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/index.js +42 -0
  301. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/index.js.map +1 -0
  302. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/keybindings.d.ts +273 -0
  303. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/keybindings.d.ts.map +1 -0
  304. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/keybindings.js +231 -0
  305. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/keybindings.js.map +1 -0
  306. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/keys.d.ts +184 -0
  307. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/keys.d.ts.map +1 -0
  308. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/keys.js +1174 -0
  309. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/keys.js.map +1 -0
  310. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/kill-ring.d.ts +28 -0
  311. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/kill-ring.d.ts.map +1 -0
  312. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/kill-ring.js +46 -0
  313. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/kill-ring.js.map +1 -0
  314. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/latex.d.ts +10 -0
  315. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/latex.d.ts.map +1 -0
  316. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/latex.js +1268 -0
  317. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/latex.js.map +1 -0
  318. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/layout-node.d.ts +40 -0
  319. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/layout-node.d.ts.map +1 -0
  320. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/layout-node.js +6 -0
  321. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/layout-node.js.map +1 -0
  322. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/layout.d.ts +42 -0
  323. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/layout.d.ts.map +1 -0
  324. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/layout.js +335 -0
  325. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/layout.js.map +1 -0
  326. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/native-modifiers.d.ts +3 -0
  327. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/native-modifiers.d.ts.map +1 -0
  328. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/native-modifiers.js +60 -0
  329. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/native-modifiers.js.map +1 -0
  330. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/stdin-buffer.d.ts +56 -0
  331. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/stdin-buffer.d.ts.map +1 -0
  332. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/stdin-buffer.js +363 -0
  333. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/stdin-buffer.js.map +1 -0
  334. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/terminal-colors.d.ts +10 -0
  335. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/terminal-colors.d.ts.map +1 -0
  336. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/terminal-colors.js +59 -0
  337. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/terminal-colors.js.map +1 -0
  338. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/terminal-image.d.ts +116 -0
  339. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/terminal-image.d.ts.map +1 -0
  340. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/terminal-image.js +518 -0
  341. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/terminal-image.js.map +1 -0
  342. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/terminal.d.ts +142 -0
  343. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/terminal.d.ts.map +1 -0
  344. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/terminal.js +544 -0
  345. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/terminal.js.map +1 -0
  346. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/testing.d.ts +11 -0
  347. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/testing.d.ts.map +1 -0
  348. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/testing.js +11 -0
  349. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/testing.js.map +1 -0
  350. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/tui-alt-screen.d.ts +140 -0
  351. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/tui-alt-screen.d.ts.map +1 -0
  352. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/tui-alt-screen.js +1334 -0
  353. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/tui-alt-screen.js.map +1 -0
  354. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/tui-main-screen.d.ts +39 -0
  355. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/tui-main-screen.d.ts.map +1 -0
  356. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/tui-main-screen.js +536 -0
  357. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/tui-main-screen.js.map +1 -0
  358. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/tui.d.ts +338 -0
  359. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/tui.d.ts.map +1 -0
  360. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/tui.js +1016 -0
  361. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/tui.js.map +1 -0
  362. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/undo-stack.d.ts +17 -0
  363. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/undo-stack.d.ts.map +1 -0
  364. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/undo-stack.js +27 -0
  365. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/undo-stack.js.map +1 -0
  366. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/utils.d.ts +96 -0
  367. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/utils.d.ts.map +1 -0
  368. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/utils.js +1193 -0
  369. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/utils.js.map +1 -0
  370. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/word-navigation.d.ts +25 -0
  371. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/word-navigation.d.ts.map +1 -0
  372. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/word-navigation.js +96 -0
  373. package/node_modules/@bubblebrain-ai/pi-tui/dist/src/word-navigation.js.map +1 -0
  374. package/node_modules/@bubblebrain-ai/pi-tui/dist/test/virtual-terminal.d.ts +73 -0
  375. package/node_modules/@bubblebrain-ai/pi-tui/dist/test/virtual-terminal.d.ts.map +1 -0
  376. package/node_modules/@bubblebrain-ai/pi-tui/dist/test/virtual-terminal.js +188 -0
  377. package/node_modules/@bubblebrain-ai/pi-tui/dist/test/virtual-terminal.js.map +1 -0
  378. package/node_modules/@bubblebrain-ai/pi-tui/native/darwin/README.md +20 -0
  379. package/node_modules/@bubblebrain-ai/pi-tui/native/darwin/build.sh +62 -0
  380. package/node_modules/@bubblebrain-ai/pi-tui/native/darwin/prebuilds/darwin-arm64/darwin-modifiers.node +0 -0
  381. package/node_modules/@bubblebrain-ai/pi-tui/native/darwin/prebuilds/darwin-x64/darwin-modifiers.node +0 -0
  382. package/node_modules/@bubblebrain-ai/pi-tui/native/darwin/src/darwin-modifiers.c +70 -0
  383. package/node_modules/@bubblebrain-ai/pi-tui/native/win32/README.md +22 -0
  384. package/node_modules/@bubblebrain-ai/pi-tui/native/win32/build.mjs +229 -0
  385. package/node_modules/@bubblebrain-ai/pi-tui/native/win32/prebuilds/win32-arm64/win32-console-mode.node +0 -0
  386. package/node_modules/@bubblebrain-ai/pi-tui/native/win32/prebuilds/win32-x64/win32-console-mode.node +0 -0
  387. package/node_modules/@bubblebrain-ai/pi-tui/native/win32/src/win32-console-mode.c +119 -0
  388. package/node_modules/@bubblebrain-ai/pi-tui/package.json +66 -0
  389. package/node_modules/get-east-asian-width/index.d.ts +60 -0
  390. package/node_modules/get-east-asian-width/index.js +30 -0
  391. package/node_modules/get-east-asian-width/license +9 -0
  392. package/node_modules/get-east-asian-width/lookup-data.js +21 -0
  393. package/node_modules/get-east-asian-width/lookup.js +138 -0
  394. package/node_modules/get-east-asian-width/package.json +71 -0
  395. package/node_modules/get-east-asian-width/readme.md +65 -0
  396. package/node_modules/get-east-asian-width/utilities.js +24 -0
  397. package/package.json +23 -10
  398. package/packages/pi-tui/node_modules/marked/LICENSE +44 -0
  399. package/packages/pi-tui/node_modules/marked/README.md +115 -0
  400. package/packages/pi-tui/node_modules/marked/bin/main.js +284 -0
  401. package/packages/pi-tui/node_modules/marked/bin/marked.js +16 -0
  402. package/packages/pi-tui/node_modules/marked/lib/marked.d.ts +760 -0
  403. package/packages/pi-tui/node_modules/marked/lib/marked.esm.js +77 -0
  404. package/packages/pi-tui/node_modules/marked/lib/marked.esm.js.map +7 -0
  405. package/packages/pi-tui/node_modules/marked/lib/marked.umd.js +79 -0
  406. package/packages/pi-tui/node_modules/marked/lib/marked.umd.js.map +7 -0
  407. package/packages/pi-tui/node_modules/marked/man/marked.1 +113 -0
  408. package/packages/pi-tui/node_modules/marked/man/marked.1.md +93 -0
  409. package/packages/pi-tui/node_modules/marked/package.json +103 -0
  410. package/dist/tui-ink/app.d.ts +0 -76
  411. package/dist/tui-ink/app.js +0 -2377
  412. package/dist/tui-ink/approval/approval-dialog.d.ts +0 -13
  413. package/dist/tui-ink/approval/approval-dialog.js +0 -184
  414. package/dist/tui-ink/approval/diff-view.d.ts +0 -7
  415. package/dist/tui-ink/approval/diff-view.js +0 -44
  416. package/dist/tui-ink/approval/select.d.ts +0 -35
  417. package/dist/tui-ink/approval/select.js +0 -98
  418. package/dist/tui-ink/code-highlight.d.ts +0 -8
  419. package/dist/tui-ink/code-highlight.js +0 -121
  420. package/dist/tui-ink/command-palette.d.ts +0 -32
  421. package/dist/tui-ink/command-palette.js +0 -158
  422. package/dist/tui-ink/compaction-progress.d.ts +0 -19
  423. package/dist/tui-ink/compaction-progress.js +0 -74
  424. package/dist/tui-ink/detect-theme.d.ts +0 -1
  425. package/dist/tui-ink/detect-theme.js +0 -1
  426. package/dist/tui-ink/feedback-dialog.d.ts +0 -19
  427. package/dist/tui-ink/feedback-dialog.js +0 -133
  428. package/dist/tui-ink/feishu-setup-picker.d.ts +0 -5
  429. package/dist/tui-ink/feishu-setup-picker.js +0 -271
  430. package/dist/tui-ink/footer.d.ts +0 -26
  431. package/dist/tui-ink/footer.js +0 -51
  432. package/dist/tui-ink/input-box.d.ts +0 -189
  433. package/dist/tui-ink/input-box.js +0 -1279
  434. package/dist/tui-ink/input-history.d.ts +0 -1
  435. package/dist/tui-ink/input-history.js +0 -1
  436. package/dist/tui-ink/markdown.d.ts +0 -103
  437. package/dist/tui-ink/markdown.js +0 -747
  438. package/dist/tui-ink/message-list.d.ts +0 -49
  439. package/dist/tui-ink/message-list.js +0 -841
  440. package/dist/tui-ink/model-picker.d.ts +0 -143
  441. package/dist/tui-ink/model-picker.js +0 -966
  442. package/dist/tui-ink/plan-confirm.d.ts +0 -7
  443. package/dist/tui-ink/plan-confirm.js +0 -115
  444. package/dist/tui-ink/question-dialog.d.ts +0 -8
  445. package/dist/tui-ink/question-dialog.js +0 -135
  446. package/dist/tui-ink/rewind-picker.d.ts +0 -8
  447. package/dist/tui-ink/rewind-picker.js +0 -102
  448. package/dist/tui-ink/run-session-picker.js +0 -22
  449. package/dist/tui-ink/run.d.ts +0 -62
  450. package/dist/tui-ink/run.js +0 -103
  451. package/dist/tui-ink/session-picker.d.ts +0 -10
  452. package/dist/tui-ink/session-picker.js +0 -113
  453. package/dist/tui-ink/stats-panel.d.ts +0 -11
  454. package/dist/tui-ink/stats-panel.js +0 -65
  455. package/dist/tui-ink/subagent-inspector.d.ts +0 -21
  456. package/dist/tui-ink/subagent-inspector.js +0 -205
  457. package/dist/tui-ink/use-terminal-size.d.ts +0 -4
  458. package/dist/tui-ink/use-terminal-size.js +0 -48
  459. package/dist/tui-ink/waiting-indicator.d.ts +0 -12
  460. package/dist/tui-ink/waiting-indicator.js +0 -129
  461. package/dist/tui-ink/welcome.d.ts +0 -25
  462. package/dist/tui-ink/welcome.js +0 -88
  463. package/dist/tui-ink/wordmark.d.ts +0 -8
  464. package/dist/tui-ink/wordmark.js +0 -103
  465. /package/dist/{tui-ink → tui/model}/composer-buffer.d.ts +0 -0
  466. /package/dist/{tui-ink → tui/model}/display-history.js +0 -0
  467. /package/dist/{tui-ink → tui/model}/input-queue.js +0 -0
  468. /package/dist/{tui-ink → tui/model}/key-events.d.ts +0 -0
  469. /package/dist/{tui-ink → tui/model}/key-events.js +0 -0
  470. /package/dist/{tui-ink → tui/model}/paste-operation-tracker.d.ts +0 -0
  471. /package/dist/{tui-ink → tui/model}/paste-operation-tracker.js +0 -0
  472. /package/dist/{tui-ink → tui/model}/recent-activity.d.ts +0 -0
  473. /package/dist/{tui-ink → tui/model}/submit-dedupe.js +0 -0
  474. /package/dist/{tui-ink → tui/model}/sync-output.d.ts +0 -0
  475. /package/dist/{tui-ink → tui/model}/sync-output.js +0 -0
  476. /package/dist/{tui-ink → tui/model}/terminal-env.d.ts +0 -0
  477. /package/dist/{tui-ink → tui/model}/terminal-env.js +0 -0
  478. /package/dist/{tui-ink → tui/model}/terminal-mouse.d.ts +0 -0
  479. /package/dist/{tui-ink → tui/model}/terminal-mouse.js +0 -0
  480. /package/dist/{tui-ink → tui/model}/width.d.ts +0 -0
  481. /package/dist/{tui-ink → tui/model}/width.js +0 -0
@@ -0,0 +1,797 @@
1
+ import { Marked, Tokenizer } from "marked";
2
+ import { renderLatex } from "../latex.js";
3
+ import { getCapabilities, hyperlink, isImageLine } from "../terminal-image.js";
4
+ import { applyBackgroundToLine, visibleWidth, wrapTextWithAnsi } from "../utils.js";
5
+ const STRICT_STRIKETHROUGH_REGEX = /^(~~)(?=[^\s~])((?:\\.|[^\\])*?(?:\\.|[^\s~\\]))\1(?=[^~]|$)/;
6
+ class StrictStrikethroughTokenizer extends Tokenizer {
7
+ del(src) {
8
+ const match = STRICT_STRIKETHROUGH_REGEX.exec(src);
9
+ if (!match) {
10
+ return undefined;
11
+ }
12
+ const text = match[2];
13
+ return {
14
+ type: "del",
15
+ raw: match[0],
16
+ text,
17
+ tokens: this.lexer.inlineTokens(text),
18
+ };
19
+ }
20
+ }
21
+ function isEscaped(source, index) {
22
+ let backslashes = 0;
23
+ for (let position = index - 1; position >= 0 && source[position] === "\\"; position--) {
24
+ backslashes++;
25
+ }
26
+ return backslashes % 2 === 1;
27
+ }
28
+ function findClosingDelimiter(source, closing, start) {
29
+ let index = source.indexOf(closing, start);
30
+ while (index >= 0 && isEscaped(source, index)) {
31
+ index = source.indexOf(closing, index + closing.length);
32
+ }
33
+ return index;
34
+ }
35
+ function looksLikePendingDollarMath(source) {
36
+ return /\\[A-Za-z]+|[_^=+*/<>()[\]|±≤≥≠≈∈→⇒∞∫∑√-]/.test(source);
37
+ }
38
+ function tokenizeInlineLatex(source) {
39
+ let opening = "";
40
+ let closing = "";
41
+ if (source.startsWith("$$")) {
42
+ opening = "$$";
43
+ closing = "$$";
44
+ }
45
+ else if (source.startsWith("\\(")) {
46
+ opening = "\\(";
47
+ closing = "\\)";
48
+ }
49
+ else if (source.startsWith("\\[")) {
50
+ opening = "\\[";
51
+ closing = "\\]";
52
+ }
53
+ else if (source.startsWith("$") && !/^\$\s/.test(source)) {
54
+ opening = "$";
55
+ closing = "$";
56
+ }
57
+ else {
58
+ return undefined;
59
+ }
60
+ const closingIndex = findClosingDelimiter(source, closing, opening.length);
61
+ if (closingIndex >= 0 &&
62
+ opening === "$" &&
63
+ (/\s$/.test(source.slice(opening.length, closingIndex)) ||
64
+ /^\d/.test(source.slice(closingIndex + 1)) ||
65
+ (/^[A-Z_][A-Z0-9_]*(?:[^A-Za-z0-9_\s])?$/.test(source.slice(opening.length, closingIndex)) &&
66
+ /^[A-Za-z_][A-Za-z0-9_]*/.test(source.slice(closingIndex + 1))) ||
67
+ source.slice(opening.length, closingIndex).includes("`"))) {
68
+ return undefined;
69
+ }
70
+ if (closingIndex < 0) {
71
+ const pendingSource = source.slice(opening.length);
72
+ if (opening.startsWith("\\") || looksLikePendingDollarMath(pendingSource)) {
73
+ return { type: "latex", raw: source, text: pendingSource, pending: true };
74
+ }
75
+ return undefined;
76
+ }
77
+ const text = source.slice(opening.length, closingIndex);
78
+ if (!text || text.includes("\n")) {
79
+ return undefined;
80
+ }
81
+ const raw = source.slice(0, closingIndex + closing.length);
82
+ return { type: "latex", raw, text };
83
+ }
84
+ function tokenizeBlockLatex(source) {
85
+ const dollarMatch = /^ {0,3}\$\$[ \t]*(?:\n)?([\s\S]*?)\$\$[ \t]*(?:\n|$)/.exec(source);
86
+ if (dollarMatch?.[1]) {
87
+ return { type: "latexBlock", raw: dollarMatch[0], text: dollarMatch[1].trim() };
88
+ }
89
+ const bracketMatch = /^ {0,3}\\\[[ \t]*(?:\n)?([\s\S]*?)\\\][ \t]*(?:\n|$)/.exec(source);
90
+ if (bracketMatch?.[1]) {
91
+ return { type: "latexBlock", raw: bracketMatch[0], text: bracketMatch[1].trim() };
92
+ }
93
+ const pendingBracket = /^ {0,3}\\\[[ \t]*(?:\n)?([\s\S]*)$/.exec(source);
94
+ if (pendingBracket) {
95
+ return { type: "latexBlock", raw: pendingBracket[0], text: pendingBracket[1], pending: true };
96
+ }
97
+ const pendingDollar = /^ {0,3}\$\$[ \t]*(?:\n)?([\s\S]*)$/.exec(source);
98
+ if (pendingDollar?.[1] && looksLikePendingDollarMath(pendingDollar[1])) {
99
+ return { type: "latexBlock", raw: pendingDollar[0], text: pendingDollar[1], pending: true };
100
+ }
101
+ return undefined;
102
+ }
103
+ const LATEX_MARKDOWN_EXTENSIONS = [
104
+ {
105
+ name: "latexBlock",
106
+ level: "block",
107
+ start(source) {
108
+ const match = /(?:^|\n) {0,3}(?:\$\$|\\\[)/.exec(source);
109
+ return match ? match.index + (match[0].startsWith("\n") ? 1 : 0) : undefined;
110
+ },
111
+ tokenizer: tokenizeBlockLatex,
112
+ },
113
+ {
114
+ name: "latex",
115
+ level: "inline",
116
+ start(source) {
117
+ const indices = [source.indexOf("$"), source.indexOf("\\("), source.indexOf("\\[")].filter((index) => index >= 0);
118
+ return indices.length > 0 ? Math.min(...indices) : undefined;
119
+ },
120
+ tokenizer: tokenizeInlineLatex,
121
+ },
122
+ ];
123
+ function trimPartialClosingFences(tokens) {
124
+ const token = tokens[tokens.length - 1];
125
+ if (token?.type === "list") {
126
+ trimPartialClosingFences(token.items[token.items.length - 1]?.tokens ?? []);
127
+ return;
128
+ }
129
+ if (token?.type === "blockquote") {
130
+ trimPartialClosingFences(token.tokens ?? []);
131
+ return;
132
+ }
133
+ if (token?.type !== "code") {
134
+ return;
135
+ }
136
+ // Trim streamed partial closing fences so code blocks do not shrink/flicker
137
+ // when the final fence character arrives. See https://github.com/earendil-works/pi/issues/5825.
138
+ const marker = /^(`{3,}|~{3,})/.exec(token.raw)?.[1];
139
+ const lastLine = token.raw.split("\n").pop();
140
+ if (!marker || !lastLine || lastLine.length >= marker.length || lastLine !== marker[0]?.repeat(lastLine.length)) {
141
+ return;
142
+ }
143
+ token.text = token.text.slice(0, -lastLine.length).replace(/\n$/, "");
144
+ }
145
+ const markdownParser = new Marked();
146
+ markdownParser.setOptions({
147
+ tokenizer: new StrictStrikethroughTokenizer(),
148
+ });
149
+ markdownParser.use({ extensions: [...LATEX_MARKDOWN_EXTENSIONS] });
150
+ export class Markdown {
151
+ constructor(text, paddingX, paddingY, theme, defaultTextStyle, options) {
152
+ this.text = text;
153
+ this.paddingX = paddingX;
154
+ this.paddingY = paddingY;
155
+ this.theme = theme;
156
+ this.defaultTextStyle = defaultTextStyle;
157
+ this.options = options ? { ...options } : {};
158
+ }
159
+ setText(text) {
160
+ this.text = text;
161
+ this.invalidate();
162
+ }
163
+ invalidate() {
164
+ this.cachedText = undefined;
165
+ this.cachedWidth = undefined;
166
+ this.cachedLines = undefined;
167
+ }
168
+ render(width) {
169
+ // Check cache
170
+ if (this.cachedLines && this.cachedText === this.text && this.cachedWidth === width) {
171
+ return this.cachedLines;
172
+ }
173
+ // Calculate available width for content (subtract horizontal padding)
174
+ const contentWidth = Math.max(1, width - this.paddingX * 2);
175
+ const text = this.options.transform?.(this.text, contentWidth) ?? this.text;
176
+ // Don't render anything if there's no actual text
177
+ if (!text || text.trim() === "") {
178
+ const result = [];
179
+ // Update cache
180
+ this.cachedText = this.text;
181
+ this.cachedWidth = width;
182
+ this.cachedLines = result;
183
+ return result;
184
+ }
185
+ // Replace tabs with 3 spaces for consistent rendering
186
+ const normalizedText = text.replace(/\t/g, " ");
187
+ // Parse markdown to HTML-like tokens
188
+ const tokens = markdownParser.lexer(normalizedText);
189
+ trimPartialClosingFences(tokens);
190
+ // Convert tokens to styled terminal output
191
+ const renderedLines = [];
192
+ for (let i = 0; i < tokens.length; i++) {
193
+ const token = tokens[i];
194
+ const nextToken = tokens[i + 1];
195
+ const tokenLines = this.renderToken(token, contentWidth, nextToken?.type);
196
+ for (const tokenLine of tokenLines) {
197
+ renderedLines.push(tokenLine);
198
+ }
199
+ }
200
+ // Wrap lines (NO padding, NO background yet)
201
+ const wrappedLines = [];
202
+ for (const line of renderedLines) {
203
+ if (isImageLine(line)) {
204
+ wrappedLines.push(line);
205
+ }
206
+ else {
207
+ for (const wrappedLine of wrapTextWithAnsi(line, contentWidth)) {
208
+ wrappedLines.push(wrappedLine);
209
+ }
210
+ }
211
+ }
212
+ // Add margins and background to each wrapped line
213
+ const leftMargin = " ".repeat(this.paddingX);
214
+ const rightMargin = " ".repeat(this.paddingX);
215
+ const bgFn = this.defaultTextStyle?.bgColor;
216
+ const contentLines = [];
217
+ for (const line of wrappedLines) {
218
+ if (isImageLine(line)) {
219
+ contentLines.push(line);
220
+ continue;
221
+ }
222
+ const lineWithMargins = leftMargin + line + rightMargin;
223
+ if (bgFn) {
224
+ contentLines.push(applyBackgroundToLine(lineWithMargins, width, bgFn));
225
+ }
226
+ else {
227
+ // No background - just pad to width
228
+ const visibleLen = visibleWidth(lineWithMargins);
229
+ const paddingNeeded = Math.max(0, width - visibleLen);
230
+ contentLines.push(lineWithMargins + " ".repeat(paddingNeeded));
231
+ }
232
+ }
233
+ // Add top/bottom padding (empty lines)
234
+ const emptyLine = " ".repeat(width);
235
+ const emptyLines = [];
236
+ for (let i = 0; i < this.paddingY; i++) {
237
+ const line = bgFn ? applyBackgroundToLine(emptyLine, width, bgFn) : emptyLine;
238
+ emptyLines.push(line);
239
+ }
240
+ // Combine top padding, content, and bottom padding
241
+ const result = emptyLines.concat(contentLines, emptyLines);
242
+ // Update cache
243
+ this.cachedText = this.text;
244
+ this.cachedWidth = width;
245
+ this.cachedLines = result;
246
+ return result.length > 0 ? result : [""];
247
+ }
248
+ /**
249
+ * Apply default text style to a string.
250
+ * This is the base styling applied to all text content.
251
+ * NOTE: Background color is NOT applied here - it's applied at the padding stage
252
+ * to ensure it extends to the full line width.
253
+ */
254
+ applyDefaultStyle(text) {
255
+ if (!this.defaultTextStyle) {
256
+ return text;
257
+ }
258
+ let styled = text;
259
+ // Apply foreground color (NOT background - that's applied at padding stage)
260
+ if (this.defaultTextStyle.color) {
261
+ styled = this.defaultTextStyle.color(styled);
262
+ }
263
+ // Apply text decorations using this.theme
264
+ if (this.defaultTextStyle.bold) {
265
+ styled = this.theme.bold(styled);
266
+ }
267
+ if (this.defaultTextStyle.italic) {
268
+ styled = this.theme.italic(styled);
269
+ }
270
+ if (this.defaultTextStyle.strikethrough) {
271
+ styled = this.theme.strikethrough(styled);
272
+ }
273
+ if (this.defaultTextStyle.underline) {
274
+ styled = this.theme.underline(styled);
275
+ }
276
+ return styled;
277
+ }
278
+ getDefaultStylePrefix() {
279
+ if (!this.defaultTextStyle) {
280
+ return "";
281
+ }
282
+ if (this.defaultStylePrefix !== undefined) {
283
+ return this.defaultStylePrefix;
284
+ }
285
+ const sentinel = "\u0000";
286
+ let styled = sentinel;
287
+ if (this.defaultTextStyle.color) {
288
+ styled = this.defaultTextStyle.color(styled);
289
+ }
290
+ if (this.defaultTextStyle.bold) {
291
+ styled = this.theme.bold(styled);
292
+ }
293
+ if (this.defaultTextStyle.italic) {
294
+ styled = this.theme.italic(styled);
295
+ }
296
+ if (this.defaultTextStyle.strikethrough) {
297
+ styled = this.theme.strikethrough(styled);
298
+ }
299
+ if (this.defaultTextStyle.underline) {
300
+ styled = this.theme.underline(styled);
301
+ }
302
+ const sentinelIndex = styled.indexOf(sentinel);
303
+ this.defaultStylePrefix = sentinelIndex >= 0 ? styled.slice(0, sentinelIndex) : "";
304
+ return this.defaultStylePrefix;
305
+ }
306
+ getStylePrefix(styleFn) {
307
+ const sentinel = "\u0000";
308
+ const styled = styleFn(sentinel);
309
+ const sentinelIndex = styled.indexOf(sentinel);
310
+ return sentinelIndex >= 0 ? styled.slice(0, sentinelIndex) : "";
311
+ }
312
+ getDefaultInlineStyleContext() {
313
+ return {
314
+ applyText: (text) => this.applyDefaultStyle(text),
315
+ stylePrefix: this.getDefaultStylePrefix(),
316
+ };
317
+ }
318
+ renderToken(token, width, nextTokenType, styleContext) {
319
+ const lines = [];
320
+ switch (token.type) {
321
+ case "heading": {
322
+ const headingLevel = token.depth;
323
+ // Build a heading-specific style context so inline tokens (codespan, bold, etc.)
324
+ // restore heading styling after their own ANSI resets instead of falling back to
325
+ // the default text style.
326
+ let headingStyleFn;
327
+ if (headingLevel === 1) {
328
+ headingStyleFn = (text) => this.theme.heading(this.theme.bold(this.theme.underline(text)));
329
+ }
330
+ else {
331
+ headingStyleFn = (text) => this.theme.heading(this.theme.bold(text));
332
+ }
333
+ const headingStyleContext = {
334
+ applyText: headingStyleFn,
335
+ stylePrefix: this.getStylePrefix(headingStyleFn),
336
+ };
337
+ const headingText = this.renderInlineTokens(token.tokens || [], headingStyleContext);
338
+ // A rendered heading should express hierarchy through typography,
339
+ // not leak its source Markdown marker back into the transcript.
340
+ // Keeping ### on h3+ made correctly parsed model output look like
341
+ // plain text even while tables/lists were rendered normally.
342
+ lines.push(headingText);
343
+ if (nextTokenType && nextTokenType !== "space") {
344
+ lines.push(""); // Add spacing after headings (unless space token follows)
345
+ }
346
+ break;
347
+ }
348
+ case "paragraph": {
349
+ const paragraphText = this.renderInlineTokens(token.tokens || [], styleContext);
350
+ lines.push(paragraphText);
351
+ // Don't add spacing if next token is space or list
352
+ if (nextTokenType && nextTokenType !== "list" && nextTokenType !== "space") {
353
+ lines.push("");
354
+ }
355
+ break;
356
+ }
357
+ case "text":
358
+ lines.push(this.renderInlineTokens([token], styleContext));
359
+ break;
360
+ case "latexBlock": {
361
+ const latexToken = token;
362
+ const rendered = !latexToken.pending && this.options.renderLatex !== false
363
+ ? (renderLatex(latexToken.text, { display: true }) ?? latexToken.raw.trim())
364
+ : latexToken.raw.trim();
365
+ for (const line of rendered.split("\n")) {
366
+ lines.push(this.applyDefaultStyle(line));
367
+ }
368
+ if (nextTokenType && nextTokenType !== "space") {
369
+ lines.push("");
370
+ }
371
+ break;
372
+ }
373
+ case "code": {
374
+ const indent = this.theme.codeBlockIndent ?? " ";
375
+ lines.push(this.theme.codeBlockBorder(`\`\`\`${token.lang || ""}`));
376
+ if (this.theme.highlightCode) {
377
+ const highlightedLines = this.theme.highlightCode(token.text, token.lang);
378
+ for (const hlLine of highlightedLines) {
379
+ lines.push(`${indent}${hlLine}`);
380
+ }
381
+ }
382
+ else {
383
+ // Split code by newlines and style each line
384
+ const codeLines = token.text.split("\n");
385
+ for (const codeLine of codeLines) {
386
+ lines.push(`${indent}${this.theme.codeBlock(codeLine)}`);
387
+ }
388
+ }
389
+ lines.push(this.theme.codeBlockBorder("```"));
390
+ if (nextTokenType && nextTokenType !== "space") {
391
+ lines.push(""); // Add spacing after code blocks (unless space token follows)
392
+ }
393
+ break;
394
+ }
395
+ case "list": {
396
+ const listLines = this.renderList(token, 0, width, styleContext);
397
+ lines.push(...listLines);
398
+ // Don't add spacing after lists if a space token follows
399
+ // (the space token will handle it)
400
+ break;
401
+ }
402
+ case "table": {
403
+ const tableLines = this.renderTable(token, width, nextTokenType, styleContext);
404
+ lines.push(...tableLines);
405
+ break;
406
+ }
407
+ case "blockquote": {
408
+ const quoteStyle = (text) => this.theme.quote(this.theme.italic(text));
409
+ const quoteStylePrefix = this.getStylePrefix(quoteStyle);
410
+ const applyQuoteStyle = (line) => {
411
+ if (!quoteStylePrefix) {
412
+ return quoteStyle(line);
413
+ }
414
+ const lineWithReappliedStyle = line.replace(/\x1b\[0m/g, `\x1b[0m${quoteStylePrefix}`);
415
+ return quoteStyle(lineWithReappliedStyle);
416
+ };
417
+ // Calculate available width for quote content (subtract border "│ " = 2 chars)
418
+ const quoteContentWidth = Math.max(1, width - 2);
419
+ // Blockquotes contain block-level tokens (paragraph, list, code, etc.), so render
420
+ // children with renderToken() instead of renderInlineTokens().
421
+ // Default message style should not apply inside blockquotes.
422
+ const quoteInlineStyleContext = {
423
+ applyText: (text) => text,
424
+ stylePrefix: quoteStylePrefix,
425
+ };
426
+ const quoteTokens = token.tokens || [];
427
+ const renderedQuoteLines = [];
428
+ for (let i = 0; i < quoteTokens.length; i++) {
429
+ const quoteToken = quoteTokens[i];
430
+ const nextQuoteToken = quoteTokens[i + 1];
431
+ renderedQuoteLines.push(...this.renderToken(quoteToken, quoteContentWidth, nextQuoteToken?.type, quoteInlineStyleContext));
432
+ }
433
+ // Avoid rendering an extra empty quote line before the outer blockquote spacing.
434
+ while (renderedQuoteLines.length > 0 && renderedQuoteLines[renderedQuoteLines.length - 1] === "") {
435
+ renderedQuoteLines.pop();
436
+ }
437
+ for (const quoteLine of renderedQuoteLines) {
438
+ const styledLine = applyQuoteStyle(quoteLine);
439
+ const wrappedLines = wrapTextWithAnsi(styledLine, quoteContentWidth);
440
+ for (const wrappedLine of wrappedLines) {
441
+ lines.push(this.theme.quoteBorder("│ ") + wrappedLine);
442
+ }
443
+ }
444
+ if (nextTokenType && nextTokenType !== "space") {
445
+ lines.push(""); // Add spacing after blockquotes (unless space token follows)
446
+ }
447
+ break;
448
+ }
449
+ case "hr":
450
+ lines.push(this.theme.hr("─".repeat(Math.min(width, 80))));
451
+ if (nextTokenType && nextTokenType !== "space") {
452
+ lines.push(""); // Add spacing after horizontal rules (unless space token follows)
453
+ }
454
+ break;
455
+ case "html":
456
+ // Render HTML as plain text (escaped for terminal)
457
+ if ("raw" in token && typeof token.raw === "string") {
458
+ lines.push(this.applyDefaultStyle(token.raw.trim()));
459
+ }
460
+ break;
461
+ case "space":
462
+ // Space tokens represent blank lines in markdown
463
+ lines.push("");
464
+ break;
465
+ default:
466
+ // Handle any other token types as plain text
467
+ if ("text" in token && typeof token.text === "string") {
468
+ lines.push(token.text);
469
+ }
470
+ }
471
+ return lines;
472
+ }
473
+ renderInlineTokens(tokens, styleContext) {
474
+ let result = "";
475
+ const resolvedStyleContext = styleContext ?? this.getDefaultInlineStyleContext();
476
+ const { applyText, stylePrefix } = resolvedStyleContext;
477
+ const applyTextWithNewlines = (text) => {
478
+ const segments = text.split("\n");
479
+ return segments.map((segment) => applyText(segment)).join("\n");
480
+ };
481
+ for (const token of tokens) {
482
+ switch (token.type) {
483
+ case "latex": {
484
+ const latexToken = token;
485
+ const rendered = !latexToken.pending && this.options.renderLatex !== false
486
+ ? (renderLatex(latexToken.text) ?? latexToken.raw)
487
+ : latexToken.raw;
488
+ result += applyTextWithNewlines(rendered);
489
+ break;
490
+ }
491
+ case "escape":
492
+ result += applyTextWithNewlines(this.options.preserveBackslashEscapes ? token.raw : token.text);
493
+ break;
494
+ case "text":
495
+ // Text tokens in list items can have nested tokens for inline formatting
496
+ if (token.tokens && token.tokens.length > 0) {
497
+ result += this.renderInlineTokens(token.tokens, resolvedStyleContext);
498
+ }
499
+ else {
500
+ result += applyTextWithNewlines(token.text);
501
+ }
502
+ break;
503
+ case "paragraph":
504
+ // Paragraph tokens contain nested inline tokens
505
+ result += this.renderInlineTokens(token.tokens || [], resolvedStyleContext);
506
+ break;
507
+ case "strong": {
508
+ const boldContent = this.renderInlineTokens(token.tokens || [], resolvedStyleContext);
509
+ result += this.theme.bold(boldContent) + stylePrefix;
510
+ break;
511
+ }
512
+ case "em": {
513
+ const italicContent = this.renderInlineTokens(token.tokens || [], resolvedStyleContext);
514
+ result += this.theme.italic(italicContent) + stylePrefix;
515
+ break;
516
+ }
517
+ case "codespan":
518
+ result += this.theme.code(token.text) + stylePrefix;
519
+ break;
520
+ case "link": {
521
+ const linkText = this.renderInlineTokens(token.tokens || [], resolvedStyleContext);
522
+ const styledLink = this.theme.link(this.theme.underline(linkText));
523
+ if (getCapabilities().hyperlinks) {
524
+ // OSC 8: render as a clickable hyperlink. The URL is not printed inline,
525
+ // so we always show only the link text regardless of whether it matches href.
526
+ result += hyperlink(styledLink, token.href) + stylePrefix;
527
+ }
528
+ else {
529
+ // Fallback: print URL in parentheses when text differs from href.
530
+ // Compare raw token.text (not styled) against href for the equality check.
531
+ // For mailto: links strip the prefix (autolinked emails use text="foo@bar.com"
532
+ // but href="mailto:foo@bar.com").
533
+ const hrefForComparison = token.href.startsWith("mailto:") ? token.href.slice(7) : token.href;
534
+ if (token.text === token.href || token.text === hrefForComparison) {
535
+ result += styledLink + stylePrefix;
536
+ }
537
+ else {
538
+ result += styledLink + this.theme.linkUrl(` (${token.href})`) + stylePrefix;
539
+ }
540
+ }
541
+ break;
542
+ }
543
+ case "br":
544
+ result += "\n";
545
+ break;
546
+ case "del": {
547
+ const delContent = this.renderInlineTokens(token.tokens || [], resolvedStyleContext);
548
+ result += this.theme.strikethrough(delContent) + stylePrefix;
549
+ break;
550
+ }
551
+ case "html":
552
+ // Render inline HTML as plain text
553
+ if ("raw" in token && typeof token.raw === "string") {
554
+ result += applyTextWithNewlines(token.raw);
555
+ }
556
+ break;
557
+ default:
558
+ // Handle any other inline token types as plain text
559
+ if ("text" in token && typeof token.text === "string") {
560
+ result += applyTextWithNewlines(token.text);
561
+ }
562
+ }
563
+ }
564
+ while (stylePrefix && result.endsWith(stylePrefix)) {
565
+ result = result.slice(0, -stylePrefix.length);
566
+ }
567
+ return result;
568
+ }
569
+ getOrderedListMarker(item) {
570
+ const match = /^(?: {0,3})(\d{1,9}[.)])[ \t]+/.exec(item.raw);
571
+ return match ? `${match[1]} ` : undefined;
572
+ }
573
+ getUnorderedListMarker(item) {
574
+ const match = /^(?: {0,3})([-+*])(?:[ \t]+|(?=\r?\n|$))/.exec(item.raw);
575
+ return match ? `${match[1]} ` : undefined;
576
+ }
577
+ /**
578
+ * Render a list with proper nesting support
579
+ */
580
+ renderList(token, depth, width, styleContext) {
581
+ const lines = [];
582
+ const indent = " ".repeat(depth);
583
+ // Use the list's start property (defaults to 1 for ordered lists)
584
+ const startNumber = typeof token.start === "number" ? token.start : 1;
585
+ for (let i = 0; i < token.items.length; i++) {
586
+ const item = token.items[i];
587
+ const isLastItem = i === token.items.length - 1;
588
+ const bullet = token.ordered
589
+ ? this.options.preserveOrderedListMarkers
590
+ ? (this.getOrderedListMarker(item) ?? `${startNumber + i}. `)
591
+ : `${startNumber + i}. `
592
+ : this.options.preserveOrderedListMarkers
593
+ ? (this.getUnorderedListMarker(item) ?? "- ")
594
+ : "- ";
595
+ const taskMarker = item.task ? `[${item.checked ? "x" : " "}] ` : "";
596
+ const marker = bullet + taskMarker;
597
+ const firstPrefix = indent + this.theme.listBullet(marker);
598
+ const continuationPrefix = indent + " ".repeat(visibleWidth(marker));
599
+ const itemWidth = Math.max(1, width - visibleWidth(firstPrefix));
600
+ let renderedAnyLine = false;
601
+ for (const itemToken of item.tokens) {
602
+ if (itemToken.type === "list") {
603
+ lines.push(...this.renderList(itemToken, depth + 1, width, styleContext));
604
+ renderedAnyLine = true;
605
+ continue;
606
+ }
607
+ const itemLines = this.renderToken(itemToken, itemWidth, undefined, styleContext);
608
+ for (const line of itemLines) {
609
+ for (const wrappedLine of wrapTextWithAnsi(line, itemWidth)) {
610
+ const linePrefix = renderedAnyLine ? continuationPrefix : firstPrefix;
611
+ lines.push(linePrefix + wrappedLine);
612
+ renderedAnyLine = true;
613
+ }
614
+ }
615
+ }
616
+ if (!renderedAnyLine) {
617
+ lines.push(firstPrefix);
618
+ }
619
+ if (token.loose && !isLastItem) {
620
+ lines.push("");
621
+ }
622
+ }
623
+ return lines;
624
+ }
625
+ /**
626
+ * Get the visible width of the longest word in a string.
627
+ */
628
+ getLongestWordWidth(text, maxWidth) {
629
+ const words = text.split(/\s+/).filter((word) => word.length > 0);
630
+ let longest = 0;
631
+ for (const word of words) {
632
+ longest = Math.max(longest, visibleWidth(word));
633
+ }
634
+ if (maxWidth === undefined) {
635
+ return longest;
636
+ }
637
+ return Math.min(longest, maxWidth);
638
+ }
639
+ /**
640
+ * Wrap a table cell to fit into a column.
641
+ *
642
+ * Delegates to wrapTextWithAnsi() so ANSI codes + long tokens are handled
643
+ * consistently with the rest of the renderer.
644
+ */
645
+ wrapCellText(text, maxWidth) {
646
+ return wrapTextWithAnsi(text, Math.max(1, maxWidth));
647
+ }
648
+ /**
649
+ * Render a table with width-aware cell wrapping.
650
+ * Cells that don't fit are wrapped to multiple lines.
651
+ */
652
+ renderTable(token, availableWidth, nextTokenType, styleContext) {
653
+ const lines = [];
654
+ const numCols = token.header.length;
655
+ if (numCols === 0) {
656
+ return lines;
657
+ }
658
+ // Calculate border overhead: "│ " + (n-1) * " │ " + " │"
659
+ // = 2 + (n-1) * 3 + 2 = 3n + 1
660
+ const borderOverhead = 3 * numCols + 1;
661
+ const availableForCells = availableWidth - borderOverhead;
662
+ if (availableForCells < numCols) {
663
+ // Too narrow to render a stable table. Fall back to raw markdown.
664
+ const fallbackLines = token.raw ? wrapTextWithAnsi(token.raw, availableWidth) : [];
665
+ if (nextTokenType && nextTokenType !== "space") {
666
+ fallbackLines.push("");
667
+ }
668
+ return fallbackLines;
669
+ }
670
+ const maxUnbrokenWordWidth = 30;
671
+ // Calculate natural column widths (what each column needs without constraints)
672
+ const naturalWidths = [];
673
+ const minWordWidths = [];
674
+ for (let i = 0; i < numCols; i++) {
675
+ const headerText = this.renderInlineTokens(token.header[i].tokens || [], styleContext);
676
+ naturalWidths[i] = visibleWidth(headerText);
677
+ minWordWidths[i] = Math.max(1, this.getLongestWordWidth(headerText, maxUnbrokenWordWidth));
678
+ }
679
+ for (const row of token.rows) {
680
+ for (let i = 0; i < row.length; i++) {
681
+ const cellText = this.renderInlineTokens(row[i].tokens || [], styleContext);
682
+ naturalWidths[i] = Math.max(naturalWidths[i] || 0, visibleWidth(cellText));
683
+ minWordWidths[i] = Math.max(minWordWidths[i] || 1, this.getLongestWordWidth(cellText, maxUnbrokenWordWidth));
684
+ }
685
+ }
686
+ let minColumnWidths = minWordWidths;
687
+ let minCellsWidth = minColumnWidths.reduce((a, b) => a + b, 0);
688
+ if (minCellsWidth > availableForCells) {
689
+ minColumnWidths = new Array(numCols).fill(1);
690
+ const remaining = availableForCells - numCols;
691
+ if (remaining > 0) {
692
+ const totalWeight = minWordWidths.reduce((total, width) => total + Math.max(0, width - 1), 0);
693
+ const growth = minWordWidths.map((width) => {
694
+ const weight = Math.max(0, width - 1);
695
+ return totalWeight > 0 ? Math.floor((weight / totalWeight) * remaining) : 0;
696
+ });
697
+ for (let i = 0; i < numCols; i++) {
698
+ minColumnWidths[i] += growth[i] ?? 0;
699
+ }
700
+ const allocated = growth.reduce((total, width) => total + width, 0);
701
+ let leftover = remaining - allocated;
702
+ for (let i = 0; leftover > 0 && i < numCols; i++) {
703
+ minColumnWidths[i]++;
704
+ leftover--;
705
+ }
706
+ }
707
+ minCellsWidth = minColumnWidths.reduce((a, b) => a + b, 0);
708
+ }
709
+ // Calculate column widths that fit within available width
710
+ const totalNaturalWidth = naturalWidths.reduce((a, b) => a + b, 0) + borderOverhead;
711
+ let columnWidths;
712
+ if (totalNaturalWidth <= availableWidth) {
713
+ // Everything fits naturally
714
+ columnWidths = naturalWidths.map((width, index) => Math.max(width, minColumnWidths[index]));
715
+ }
716
+ else {
717
+ // Need to shrink columns to fit
718
+ const totalGrowPotential = naturalWidths.reduce((total, width, index) => {
719
+ return total + Math.max(0, width - minColumnWidths[index]);
720
+ }, 0);
721
+ const extraWidth = Math.max(0, availableForCells - minCellsWidth);
722
+ columnWidths = minColumnWidths.map((minWidth, index) => {
723
+ const naturalWidth = naturalWidths[index];
724
+ const minWidthDelta = Math.max(0, naturalWidth - minWidth);
725
+ let grow = 0;
726
+ if (totalGrowPotential > 0) {
727
+ grow = Math.floor((minWidthDelta / totalGrowPotential) * extraWidth);
728
+ }
729
+ return minWidth + grow;
730
+ });
731
+ // Adjust for rounding errors - distribute remaining space
732
+ const allocated = columnWidths.reduce((a, b) => a + b, 0);
733
+ let remaining = availableForCells - allocated;
734
+ while (remaining > 0) {
735
+ let grew = false;
736
+ for (let i = 0; i < numCols && remaining > 0; i++) {
737
+ if (columnWidths[i] < naturalWidths[i]) {
738
+ columnWidths[i]++;
739
+ remaining--;
740
+ grew = true;
741
+ }
742
+ }
743
+ if (!grew) {
744
+ break;
745
+ }
746
+ }
747
+ }
748
+ // Render top border
749
+ const topBorderCells = columnWidths.map((w) => "─".repeat(w));
750
+ lines.push(`┌─${topBorderCells.join("─┬─")}─┐`);
751
+ // Render header with wrapping
752
+ const headerCellLines = token.header.map((cell, i) => {
753
+ const text = this.renderInlineTokens(cell.tokens || [], styleContext);
754
+ return this.wrapCellText(text, columnWidths[i]);
755
+ });
756
+ const headerLineCount = Math.max(...headerCellLines.map((c) => c.length));
757
+ for (let lineIdx = 0; lineIdx < headerLineCount; lineIdx++) {
758
+ const rowParts = headerCellLines.map((cellLines, colIdx) => {
759
+ const text = cellLines[lineIdx] || "";
760
+ const padded = text + " ".repeat(Math.max(0, columnWidths[colIdx] - visibleWidth(text)));
761
+ return this.theme.bold(padded);
762
+ });
763
+ lines.push(`│ ${rowParts.join(" │ ")} │`);
764
+ }
765
+ // Render separator
766
+ const separatorCells = columnWidths.map((w) => "─".repeat(w));
767
+ const separatorLine = `├─${separatorCells.join("─┼─")}─┤`;
768
+ lines.push(separatorLine);
769
+ // Render rows with wrapping
770
+ for (let rowIndex = 0; rowIndex < token.rows.length; rowIndex++) {
771
+ const row = token.rows[rowIndex];
772
+ const rowCellLines = row.map((cell, i) => {
773
+ const text = this.renderInlineTokens(cell.tokens || [], styleContext);
774
+ return this.wrapCellText(text, columnWidths[i]);
775
+ });
776
+ const rowLineCount = Math.max(...rowCellLines.map((c) => c.length));
777
+ for (let lineIdx = 0; lineIdx < rowLineCount; lineIdx++) {
778
+ const rowParts = rowCellLines.map((cellLines, colIdx) => {
779
+ const text = cellLines[lineIdx] || "";
780
+ return text + " ".repeat(Math.max(0, columnWidths[colIdx] - visibleWidth(text)));
781
+ });
782
+ lines.push(`│ ${rowParts.join(" │ ")} │`);
783
+ }
784
+ if (rowIndex < token.rows.length - 1) {
785
+ lines.push(separatorLine);
786
+ }
787
+ }
788
+ // Render bottom border
789
+ const bottomBorderCells = columnWidths.map((w) => "─".repeat(w));
790
+ lines.push(`└─${bottomBorderCells.join("─┴─")}─┘`);
791
+ if (nextTokenType && nextTokenType !== "space") {
792
+ lines.push(""); // Add spacing after table
793
+ }
794
+ return lines;
795
+ }
796
+ }
797
+ //# sourceMappingURL=markdown.js.map