@aria-cli/cli 1.0.56 → 1.0.58

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 (622) hide show
  1. package/bin/aria.mjs +2 -2
  2. package/package.json +17 -76
  3. package/dist/.tsbuildinfo +0 -1
  4. package/dist/attached-local-control-client.js +0 -826
  5. package/dist/attached-local-control-client.js.map +0 -1
  6. package/dist/bootstrap-local-control-client.js +0 -2
  7. package/dist/bootstrap-local-control-client.js.map +0 -1
  8. package/dist/capability-aware-method-proxy.js +0 -42
  9. package/dist/capability-aware-method-proxy.js.map +0 -1
  10. package/dist/cli-context.js +0 -160
  11. package/dist/cli-context.js.map +0 -1
  12. package/dist/commands/arions.js +0 -174
  13. package/dist/commands/arions.js.map +0 -1
  14. package/dist/commands/auth.js +0 -123
  15. package/dist/commands/auth.js.map +0 -1
  16. package/dist/commands/daemon.js +0 -367
  17. package/dist/commands/daemon.js.map +0 -1
  18. package/dist/commands/definitions.js +0 -176
  19. package/dist/commands/definitions.js.map +0 -1
  20. package/dist/commands/index.js +0 -80
  21. package/dist/commands/index.js.map +0 -1
  22. package/dist/commands/login-handler.js +0 -1108
  23. package/dist/commands/login-handler.js.map +0 -1
  24. package/dist/commands/logout-handler.js +0 -92
  25. package/dist/commands/logout-handler.js.map +0 -1
  26. package/dist/commands/memory-handlers.js +0 -89
  27. package/dist/commands/memory-handlers.js.map +0 -1
  28. package/dist/commands/pairing.js +0 -60
  29. package/dist/commands/pairing.js.map +0 -1
  30. package/dist/commands/runtime-cutover-reset-command.js +0 -12
  31. package/dist/commands/runtime-cutover-reset-command.js.map +0 -1
  32. package/dist/commands/runtime-cutover-reset.js +0 -265
  33. package/dist/commands/runtime-cutover-reset.js.map +0 -1
  34. package/dist/commands/terminal-setup.js +0 -84
  35. package/dist/commands/terminal-setup.js.map +0 -1
  36. package/dist/config/aria-config.js +0 -238
  37. package/dist/config/aria-config.js.map +0 -1
  38. package/dist/config/index.js +0 -3
  39. package/dist/config/index.js.map +0 -1
  40. package/dist/config/loader.js +0 -97
  41. package/dist/config/loader.js.map +0 -1
  42. package/dist/config.js +0 -142
  43. package/dist/config.js.map +0 -1
  44. package/dist/daemon-info.js +0 -10
  45. package/dist/daemon-info.js.map +0 -1
  46. package/dist/ensure-daemon.js +0 -128
  47. package/dist/ensure-daemon.js.map +0 -1
  48. package/dist/entrypoints/command-mode.js +0 -5
  49. package/dist/entrypoints/command-mode.js.map +0 -1
  50. package/dist/entrypoints/daemon.js +0 -50
  51. package/dist/entrypoints/daemon.js.map +0 -1
  52. package/dist/entrypoints/headless-stdio.js +0 -25
  53. package/dist/entrypoints/headless-stdio.js.map +0 -1
  54. package/dist/entrypoints/interactive.d.ts.map +0 -1
  55. package/dist/entrypoints/interactive.js +0 -80
  56. package/dist/entrypoints/interactive.js.map +0 -1
  57. package/dist/event-loop-watchdog.js +0 -73
  58. package/dist/event-loop-watchdog.js.map +0 -1
  59. package/dist/headless/auth-orchestrator.js +0 -508
  60. package/dist/headless/auth-orchestrator.js.map +0 -1
  61. package/dist/headless/auth-service.js +0 -43
  62. package/dist/headless/auth-service.js.map +0 -1
  63. package/dist/headless/bootstrap-fast-path.js +0 -112
  64. package/dist/headless/bootstrap-fast-path.js.map +0 -1
  65. package/dist/headless/call-command.js +0 -143
  66. package/dist/headless/call-command.js.map +0 -1
  67. package/dist/headless/daemon-service.js +0 -318
  68. package/dist/headless/daemon-service.js.map +0 -1
  69. package/dist/headless/hook-actions.js +0 -235
  70. package/dist/headless/hook-actions.js.map +0 -1
  71. package/dist/headless/hook-service.js +0 -42
  72. package/dist/headless/hook-service.js.map +0 -1
  73. package/dist/headless/kernel-services.js +0 -216
  74. package/dist/headless/kernel-services.js.map +0 -1
  75. package/dist/headless/kernel.js +0 -785
  76. package/dist/headless/kernel.js.map +0 -1
  77. package/dist/headless/operations/arion.js +0 -119
  78. package/dist/headless/operations/arion.js.map +0 -1
  79. package/dist/headless/operations/auth.js +0 -45
  80. package/dist/headless/operations/auth.js.map +0 -1
  81. package/dist/headless/operations/client.js +0 -31
  82. package/dist/headless/operations/client.js.map +0 -1
  83. package/dist/headless/operations/config.js +0 -69
  84. package/dist/headless/operations/config.js.map +0 -1
  85. package/dist/headless/operations/daemon.js +0 -47
  86. package/dist/headless/operations/daemon.js.map +0 -1
  87. package/dist/headless/operations/hook.js +0 -56
  88. package/dist/headless/operations/hook.js.map +0 -1
  89. package/dist/headless/operations/index.js +0 -11
  90. package/dist/headless/operations/index.js.map +0 -1
  91. package/dist/headless/operations/memory.js +0 -102
  92. package/dist/headless/operations/memory.js.map +0 -1
  93. package/dist/headless/operations/message.js +0 -279
  94. package/dist/headless/operations/message.js.map +0 -1
  95. package/dist/headless/operations/model.js +0 -100
  96. package/dist/headless/operations/model.js.map +0 -1
  97. package/dist/headless/operations/peer.js +0 -56
  98. package/dist/headless/operations/peer.js.map +0 -1
  99. package/dist/headless/operations/run.js +0 -24
  100. package/dist/headless/operations/run.js.map +0 -1
  101. package/dist/headless/operations/session.js +0 -90
  102. package/dist/headless/operations/session.js.map +0 -1
  103. package/dist/headless/operations/system.js +0 -19
  104. package/dist/headless/operations/system.js.map +0 -1
  105. package/dist/headless/operations/utils.js +0 -35
  106. package/dist/headless/operations/utils.js.map +0 -1
  107. package/dist/headless/run-orchestrator.js +0 -703
  108. package/dist/headless/run-orchestrator.js.map +0 -1
  109. package/dist/headless/stdio-server.js +0 -439
  110. package/dist/headless/stdio-server.js.map +0 -1
  111. package/dist/history/SessionHistory.js +0 -8
  112. package/dist/history/SessionHistory.js.map +0 -1
  113. package/dist/history/SessionHistoryClient.js +0 -186
  114. package/dist/history/SessionHistoryClient.js.map +0 -1
  115. package/dist/history/conversation-message.js +0 -112
  116. package/dist/history/conversation-message.js.map +0 -1
  117. package/dist/history/index.js +0 -8
  118. package/dist/history/index.js.map +0 -1
  119. package/dist/history/jsonl-replay.js +0 -154
  120. package/dist/history/jsonl-replay.js.map +0 -1
  121. package/dist/history/repair-tool-pairing.js +0 -84
  122. package/dist/history/repair-tool-pairing.js.map +0 -1
  123. package/dist/history/stall-phase-bridge.js +0 -11
  124. package/dist/history/stall-phase-bridge.js.map +0 -1
  125. package/dist/history/turn-accumulator.js +0 -427
  126. package/dist/history/turn-accumulator.js.map +0 -1
  127. package/dist/index.d.ts.map +0 -1
  128. package/dist/index.js +0 -7
  129. package/dist/index.js.map +0 -1
  130. package/dist/ink-repl.d.ts.map +0 -1
  131. package/dist/ink-repl.js +0 -4183
  132. package/dist/ink-repl.js.map +0 -1
  133. package/dist/local-control-bootstrap.js +0 -26
  134. package/dist/local-control-bootstrap.js.map +0 -1
  135. package/dist/local-control-client.js +0 -2
  136. package/dist/local-control-client.js.map +0 -1
  137. package/dist/local-control-error-reporting.js +0 -34
  138. package/dist/local-control-error-reporting.js.map +0 -1
  139. package/dist/local-control-http-client.js +0 -362
  140. package/dist/local-control-http-client.js.map +0 -1
  141. package/dist/local-control-lazy-wrapper.js +0 -363
  142. package/dist/local-control-lazy-wrapper.js.map +0 -1
  143. package/dist/local-control-manager.js +0 -146
  144. package/dist/local-control-manager.js.map +0 -1
  145. package/dist/main.d.ts.map +0 -1
  146. package/dist/main.js +0 -62
  147. package/dist/main.js.map +0 -1
  148. package/dist/network-security.js +0 -62
  149. package/dist/network-security.js.map +0 -1
  150. package/dist/networking-server.js +0 -38
  151. package/dist/networking-server.js.map +0 -1
  152. package/dist/peer-identity.js +0 -23
  153. package/dist/peer-identity.js.map +0 -1
  154. package/dist/polling-subscription.js +0 -34
  155. package/dist/polling-subscription.js.map +0 -1
  156. package/dist/relaunch.d.ts +0 -63
  157. package/dist/relaunch.d.ts.map +0 -1
  158. package/dist/relaunch.js +0 -617
  159. package/dist/relaunch.js.map +0 -1
  160. package/dist/release-notes.js +0 -35
  161. package/dist/release-notes.js.map +0 -1
  162. package/dist/repl-cleanup.js +0 -47
  163. package/dist/repl-cleanup.js.map +0 -1
  164. package/dist/runtime/configure-bun-sqlite.js +0 -3
  165. package/dist/runtime/configure-bun-sqlite.js.map +0 -1
  166. package/dist/runtime/crash-handlers.js +0 -111
  167. package/dist/runtime/crash-handlers.js.map +0 -1
  168. package/dist/runtime/interactive-invocation.js +0 -39
  169. package/dist/runtime/interactive-invocation.js.map +0 -1
  170. package/dist/runtime/internal-mode.js +0 -14
  171. package/dist/runtime/internal-mode.js.map +0 -1
  172. package/dist/runtime/launch-spec.js +0 -64
  173. package/dist/runtime/launch-spec.js.map +0 -1
  174. package/dist/runtime/owner-lease.js +0 -44
  175. package/dist/runtime/owner-lease.js.map +0 -1
  176. package/dist/runtime/public-mode.js +0 -20
  177. package/dist/runtime/public-mode.js.map +0 -1
  178. package/dist/runtime/run-internal-mode.d.ts.map +0 -1
  179. package/dist/runtime/run-internal-mode.js +0 -18
  180. package/dist/runtime/run-internal-mode.js.map +0 -1
  181. package/dist/runtime/runtime-kind.js +0 -32
  182. package/dist/runtime/runtime-kind.js.map +0 -1
  183. package/dist/runtime/spawn-aria.js +0 -38
  184. package/dist/runtime/spawn-aria.js.map +0 -1
  185. package/dist/selectable-client.js +0 -2
  186. package/dist/selectable-client.js.map +0 -1
  187. package/dist/selectable-peer.js +0 -2
  188. package/dist/selectable-peer.js.map +0 -1
  189. package/dist/session.js +0 -203
  190. package/dist/session.js.map +0 -1
  191. package/dist/slash-commands.js +0 -80
  192. package/dist/slash-commands.js.map +0 -1
  193. package/dist/sounds.js +0 -210
  194. package/dist/sounds.js.map +0 -1
  195. package/dist/ui/App.js +0 -526
  196. package/dist/ui/App.js.map +0 -1
  197. package/dist/ui/components/AnthropicMethodPicker.js +0 -6
  198. package/dist/ui/components/AnthropicMethodPicker.js.map +0 -1
  199. package/dist/ui/components/ArionPrompt.js +0 -15
  200. package/dist/ui/components/ArionPrompt.js.map +0 -1
  201. package/dist/ui/components/AutocompleteDropdown.js +0 -23
  202. package/dist/ui/components/AutocompleteDropdown.js.map +0 -1
  203. package/dist/ui/components/AutonomySelector.js +0 -55
  204. package/dist/ui/components/AutonomySelector.js.map +0 -1
  205. package/dist/ui/components/Banner.js +0 -98
  206. package/dist/ui/components/Banner.js.map +0 -1
  207. package/dist/ui/components/ConversationHistory.js +0 -175
  208. package/dist/ui/components/ConversationHistory.js.map +0 -1
  209. package/dist/ui/components/CopilotDeviceLoginFlow.js +0 -88
  210. package/dist/ui/components/CopilotDeviceLoginFlow.js.map +0 -1
  211. package/dist/ui/components/CopilotSourcePicker.js +0 -50
  212. package/dist/ui/components/CopilotSourcePicker.js.map +0 -1
  213. package/dist/ui/components/Cost.js +0 -10
  214. package/dist/ui/components/Cost.js.map +0 -1
  215. package/dist/ui/components/CustomSelect/option-map.js +0 -30
  216. package/dist/ui/components/CustomSelect/option-map.js.map +0 -1
  217. package/dist/ui/components/CustomSelect/select-option.js +0 -13
  218. package/dist/ui/components/CustomSelect/select-option.js.map +0 -1
  219. package/dist/ui/components/CustomSelect/select.js +0 -42
  220. package/dist/ui/components/CustomSelect/select.js.map +0 -1
  221. package/dist/ui/components/CustomSelect/use-select-state.js +0 -179
  222. package/dist/ui/components/CustomSelect/use-select-state.js.map +0 -1
  223. package/dist/ui/components/CustomSelect/use-select.js +0 -15
  224. package/dist/ui/components/CustomSelect/use-select.js.map +0 -1
  225. package/dist/ui/components/ErrorDisplay.js +0 -35
  226. package/dist/ui/components/ErrorDisplay.js.map +0 -1
  227. package/dist/ui/components/FallbackToolUseRejectedMessage.js +0 -7
  228. package/dist/ui/components/FallbackToolUseRejectedMessage.js.map +0 -1
  229. package/dist/ui/components/FileEditToolUpdatedMessage.js +0 -57
  230. package/dist/ui/components/FileEditToolUpdatedMessage.js.map +0 -1
  231. package/dist/ui/components/HandoffMarker.js +0 -18
  232. package/dist/ui/components/HandoffMarker.js.map +0 -1
  233. package/dist/ui/components/HighlightedCode.js +0 -21
  234. package/dist/ui/components/HighlightedCode.js.map +0 -1
  235. package/dist/ui/components/InputArea.js +0 -187
  236. package/dist/ui/components/InputArea.js.map +0 -1
  237. package/dist/ui/components/Message.js +0 -25
  238. package/dist/ui/components/Message.js.map +0 -1
  239. package/dist/ui/components/OAuthLoginFlow.js +0 -113
  240. package/dist/ui/components/OAuthLoginFlow.js.map +0 -1
  241. package/dist/ui/components/OutputTruncation.js +0 -35
  242. package/dist/ui/components/OutputTruncation.js.map +0 -1
  243. package/dist/ui/components/PermissionPrompt.js +0 -79
  244. package/dist/ui/components/PermissionPrompt.js.map +0 -1
  245. package/dist/ui/components/PipelineTimingPanel.js +0 -15
  246. package/dist/ui/components/PipelineTimingPanel.js.map +0 -1
  247. package/dist/ui/components/ProviderMethodPicker.js +0 -61
  248. package/dist/ui/components/ProviderMethodPicker.js.map +0 -1
  249. package/dist/ui/components/ProviderPicker.js +0 -63
  250. package/dist/ui/components/ProviderPicker.js.map +0 -1
  251. package/dist/ui/components/RenderItemView.js +0 -71
  252. package/dist/ui/components/RenderItemView.js.map +0 -1
  253. package/dist/ui/components/Spinner.js +0 -46
  254. package/dist/ui/components/Spinner.js.map +0 -1
  255. package/dist/ui/components/StatusBar.js +0 -95
  256. package/dist/ui/components/StatusBar.js.map +0 -1
  257. package/dist/ui/components/StreamingIndicator.js +0 -55
  258. package/dist/ui/components/StreamingIndicator.js.map +0 -1
  259. package/dist/ui/components/StructuredDiff.js +0 -168
  260. package/dist/ui/components/StructuredDiff.js.map +0 -1
  261. package/dist/ui/components/TextInputOverlay.js +0 -43
  262. package/dist/ui/components/TextInputOverlay.js.map +0 -1
  263. package/dist/ui/components/ThinkingBlock.js +0 -82
  264. package/dist/ui/components/ThinkingBlock.js.map +0 -1
  265. package/dist/ui/components/ToolCost.js +0 -17
  266. package/dist/ui/components/ToolCost.js.map +0 -1
  267. package/dist/ui/components/ToolExecution.js +0 -61
  268. package/dist/ui/components/ToolExecution.js.map +0 -1
  269. package/dist/ui/components/ToolHeader.js +0 -51
  270. package/dist/ui/components/ToolHeader.js.map +0 -1
  271. package/dist/ui/components/ToolRenderLayoutContext.js +0 -14
  272. package/dist/ui/components/ToolRenderLayoutContext.js.map +0 -1
  273. package/dist/ui/components/ToolResultWrapper.js +0 -6
  274. package/dist/ui/components/ToolResultWrapper.js.map +0 -1
  275. package/dist/ui/components/ToolUseLoader.js +0 -35
  276. package/dist/ui/components/ToolUseLoader.js.map +0 -1
  277. package/dist/ui/components/TraceWaterfall.js +0 -91
  278. package/dist/ui/components/TraceWaterfall.js.map +0 -1
  279. package/dist/ui/components/index.js +0 -33
  280. package/dist/ui/components/index.js.map +0 -1
  281. package/dist/ui/components/messages/AssistantTextMessage.js +0 -25
  282. package/dist/ui/components/messages/AssistantTextMessage.js.map +0 -1
  283. package/dist/ui/components/messages/UserImageMessage.js +0 -12
  284. package/dist/ui/components/messages/UserImageMessage.js.map +0 -1
  285. package/dist/ui/components/messages/UserTextMessage.js +0 -12
  286. package/dist/ui/components/messages/UserTextMessage.js.map +0 -1
  287. package/dist/ui/components/overlays/ArionSelector.js +0 -68
  288. package/dist/ui/components/overlays/ArionSelector.js.map +0 -1
  289. package/dist/ui/components/overlays/ClientSelector.js +0 -62
  290. package/dist/ui/components/overlays/ClientSelector.js.map +0 -1
  291. package/dist/ui/components/overlays/CommandPalette.js +0 -67
  292. package/dist/ui/components/overlays/CommandPalette.js.map +0 -1
  293. package/dist/ui/components/overlays/DaemonControl.js +0 -87
  294. package/dist/ui/components/overlays/DaemonControl.js.map +0 -1
  295. package/dist/ui/components/overlays/InviteShareOverlay.js +0 -15
  296. package/dist/ui/components/overlays/InviteShareOverlay.js.map +0 -1
  297. package/dist/ui/components/overlays/JoinInviteOverlay.js +0 -32
  298. package/dist/ui/components/overlays/JoinInviteOverlay.js.map +0 -1
  299. package/dist/ui/components/overlays/MemoryBrowser.js +0 -100
  300. package/dist/ui/components/overlays/MemoryBrowser.js.map +0 -1
  301. package/dist/ui/components/overlays/MessageSelector.js +0 -123
  302. package/dist/ui/components/overlays/MessageSelector.js.map +0 -1
  303. package/dist/ui/components/overlays/ModelSelector.js +0 -211
  304. package/dist/ui/components/overlays/ModelSelector.js.map +0 -1
  305. package/dist/ui/components/overlays/PairRequestOverlay.js +0 -42
  306. package/dist/ui/components/overlays/PairRequestOverlay.js.map +0 -1
  307. package/dist/ui/components/overlays/PeerSelector.js +0 -84
  308. package/dist/ui/components/overlays/PeerSelector.js.map +0 -1
  309. package/dist/ui/components/overlays/SessionSelector.js +0 -102
  310. package/dist/ui/components/overlays/SessionSelector.js.map +0 -1
  311. package/dist/ui/components/overlays/SoundSelector.js +0 -86
  312. package/dist/ui/components/overlays/SoundSelector.js.map +0 -1
  313. package/dist/ui/components/overlays/ThemeSelector.js +0 -139
  314. package/dist/ui/components/overlays/ThemeSelector.js.map +0 -1
  315. package/dist/ui/components/overlays/index.js +0 -15
  316. package/dist/ui/components/overlays/index.js.map +0 -1
  317. package/dist/ui/components/permissions/BashPermissionRequest/BashPermissionRequest.js +0 -53
  318. package/dist/ui/components/permissions/BashPermissionRequest/BashPermissionRequest.js.map +0 -1
  319. package/dist/ui/components/permissions/FallbackPermissionRequest.js +0 -56
  320. package/dist/ui/components/permissions/FallbackPermissionRequest.js.map +0 -1
  321. package/dist/ui/components/permissions/FileEditPermissionRequest/FileEditPermissionRequest.js +0 -76
  322. package/dist/ui/components/permissions/FileEditPermissionRequest/FileEditPermissionRequest.js.map +0 -1
  323. package/dist/ui/components/permissions/FileEditPermissionRequest/FileEditToolDiff.js +0 -18
  324. package/dist/ui/components/permissions/FileEditPermissionRequest/FileEditToolDiff.js.map +0 -1
  325. package/dist/ui/components/permissions/FileWritePermissionRequest/FileWritePermissionRequest.js +0 -64
  326. package/dist/ui/components/permissions/FileWritePermissionRequest/FileWritePermissionRequest.js.map +0 -1
  327. package/dist/ui/components/permissions/FileWritePermissionRequest/FileWriteToolDiff.js +0 -26
  328. package/dist/ui/components/permissions/FileWritePermissionRequest/FileWriteToolDiff.js.map +0 -1
  329. package/dist/ui/components/permissions/FilesystemPermissionRequest/FilesystemPermissionRequest.js +0 -141
  330. package/dist/ui/components/permissions/FilesystemPermissionRequest/FilesystemPermissionRequest.js.map +0 -1
  331. package/dist/ui/components/permissions/PermissionRequest.js +0 -70
  332. package/dist/ui/components/permissions/PermissionRequest.js.map +0 -1
  333. package/dist/ui/components/permissions/PermissionRequestTitle.js +0 -41
  334. package/dist/ui/components/permissions/PermissionRequestTitle.js.map +0 -1
  335. package/dist/ui/components/permissions/hooks.js +0 -10
  336. package/dist/ui/components/permissions/hooks.js.map +0 -1
  337. package/dist/ui/components/permissions/toolUseOptions.js +0 -68
  338. package/dist/ui/components/permissions/toolUseOptions.js.map +0 -1
  339. package/dist/ui/components/permissions/utils.js +0 -10
  340. package/dist/ui/components/permissions/utils.js.map +0 -1
  341. package/dist/ui/components/text-input/Cursor.js +0 -326
  342. package/dist/ui/components/text-input/Cursor.js.map +0 -1
  343. package/dist/ui/components/text-input/TextInput.js +0 -231
  344. package/dist/ui/components/text-input/TextInput.js.map +0 -1
  345. package/dist/ui/components/text-input/imagePaste.js +0 -28
  346. package/dist/ui/components/text-input/imagePaste.js.map +0 -1
  347. package/dist/ui/components/text-input/index.js +0 -6
  348. package/dist/ui/components/text-input/index.js.map +0 -1
  349. package/dist/ui/components/text-input/useDoublePress.js +0 -30
  350. package/dist/ui/components/text-input/useDoublePress.js.map +0 -1
  351. package/dist/ui/components/text-input/useTextInput.js +0 -245
  352. package/dist/ui/components/text-input/useTextInput.js.map +0 -1
  353. package/dist/ui/components/tool-types.js +0 -9
  354. package/dist/ui/components/tool-types.js.map +0 -1
  355. package/dist/ui/constants/figures.js +0 -4
  356. package/dist/ui/constants/figures.js.map +0 -1
  357. package/dist/ui/constants/index.js +0 -3
  358. package/dist/ui/constants/index.js.map +0 -1
  359. package/dist/ui/display-mode.js +0 -93
  360. package/dist/ui/display-mode.js.map +0 -1
  361. package/dist/ui/display-policy.js +0 -19
  362. package/dist/ui/display-policy.js.map +0 -1
  363. package/dist/ui/hooks/index.js +0 -6
  364. package/dist/ui/hooks/index.js.map +0 -1
  365. package/dist/ui/hooks/useCommandAutocomplete.js +0 -93
  366. package/dist/ui/hooks/useCommandAutocomplete.js.map +0 -1
  367. package/dist/ui/hooks/useDoublePress.js +0 -37
  368. package/dist/ui/hooks/useDoublePress.js.map +0 -1
  369. package/dist/ui/hooks/useIndicatorState.js +0 -55
  370. package/dist/ui/hooks/useIndicatorState.js.map +0 -1
  371. package/dist/ui/hooks/useInterval.js +0 -23
  372. package/dist/ui/hooks/useInterval.js.map +0 -1
  373. package/dist/ui/hooks/useKeyboardShortcuts.js +0 -127
  374. package/dist/ui/hooks/useKeyboardShortcuts.js.map +0 -1
  375. package/dist/ui/hooks/useTerminalSize.js +0 -55
  376. package/dist/ui/hooks/useTerminalSize.js.map +0 -1
  377. package/dist/ui/hooks/useUnifiedMessages.js +0 -117
  378. package/dist/ui/hooks/useUnifiedMessages.js.map +0 -1
  379. package/dist/ui/indicator-state.js +0 -44
  380. package/dist/ui/indicator-state.js.map +0 -1
  381. package/dist/ui/markdown/highlight.js +0 -44
  382. package/dist/ui/markdown/highlight.js.map +0 -1
  383. package/dist/ui/markdown/index.js +0 -1460
  384. package/dist/ui/markdown/index.js.map +0 -1
  385. package/dist/ui/markdown/tokenizer.js +0 -24
  386. package/dist/ui/markdown/tokenizer.js.map +0 -1
  387. package/dist/ui/render-item.js +0 -5
  388. package/dist/ui/render-item.js.map +0 -1
  389. package/dist/ui/screens/REPL.js +0 -119
  390. package/dist/ui/screens/REPL.js.map +0 -1
  391. package/dist/ui/screens/approval-lifecycle.js +0 -38
  392. package/dist/ui/screens/approval-lifecycle.js.map +0 -1
  393. package/dist/ui/status-line.js +0 -72
  394. package/dist/ui/status-line.js.map +0 -1
  395. package/dist/ui/theme/index.js +0 -51
  396. package/dist/ui/theme/index.js.map +0 -1
  397. package/dist/ui/theme/themes/claude-dark-daltonized.js +0 -51
  398. package/dist/ui/theme/themes/claude-dark-daltonized.js.map +0 -1
  399. package/dist/ui/theme/themes/claude-dark.js +0 -50
  400. package/dist/ui/theme/themes/claude-dark.js.map +0 -1
  401. package/dist/ui/theme/themes/claude-light-daltonized.js +0 -51
  402. package/dist/ui/theme/themes/claude-light-daltonized.js.map +0 -1
  403. package/dist/ui/theme/themes/claude-light.js +0 -50
  404. package/dist/ui/theme/themes/claude-light.js.map +0 -1
  405. package/dist/ui/theme/themes/dark-accessible.js +0 -18
  406. package/dist/ui/theme/themes/dark-accessible.js.map +0 -1
  407. package/dist/ui/theme/themes/dark.js +0 -49
  408. package/dist/ui/theme/themes/dark.js.map +0 -1
  409. package/dist/ui/theme/themes/light-accessible.js +0 -18
  410. package/dist/ui/theme/themes/light-accessible.js.map +0 -1
  411. package/dist/ui/theme/themes/light.js +0 -49
  412. package/dist/ui/theme/themes/light.js.map +0 -1
  413. package/dist/ui/theme/types.js +0 -3
  414. package/dist/ui/theme/types.js.map +0 -1
  415. package/dist/ui/theme.js +0 -142
  416. package/dist/ui/theme.js.map +0 -1
  417. package/dist/ui/to-render-items.js +0 -145
  418. package/dist/ui/to-render-items.js.map +0 -1
  419. package/dist/ui/tools/AgentTool/index.js +0 -30
  420. package/dist/ui/tools/AgentTool/index.js.map +0 -1
  421. package/dist/ui/tools/ArchitectTool/index.js +0 -31
  422. package/dist/ui/tools/ArchitectTool/index.js.map +0 -1
  423. package/dist/ui/tools/AskUserTool/index.js +0 -46
  424. package/dist/ui/tools/AskUserTool/index.js.map +0 -1
  425. package/dist/ui/tools/BashTool/BashToolResultMessage.js +0 -11
  426. package/dist/ui/tools/BashTool/BashToolResultMessage.js.map +0 -1
  427. package/dist/ui/tools/BashTool/OutputLine.js +0 -21
  428. package/dist/ui/tools/BashTool/OutputLine.js.map +0 -1
  429. package/dist/ui/tools/BashTool/index.js +0 -91
  430. package/dist/ui/tools/BashTool/index.js.map +0 -1
  431. package/dist/ui/tools/BrowseTool/index.js +0 -43
  432. package/dist/ui/tools/BrowseTool/index.js.map +0 -1
  433. package/dist/ui/tools/BrowserTool/index.js +0 -47
  434. package/dist/ui/tools/BrowserTool/index.js.map +0 -1
  435. package/dist/ui/tools/CbmTool/index.js +0 -188
  436. package/dist/ui/tools/CbmTool/index.js.map +0 -1
  437. package/dist/ui/tools/CheckDelegationTool/index.js +0 -46
  438. package/dist/ui/tools/CheckDelegationTool/index.js.map +0 -1
  439. package/dist/ui/tools/CheckMessagesTool/index.js +0 -85
  440. package/dist/ui/tools/CheckMessagesTool/index.js.map +0 -1
  441. package/dist/ui/tools/CreateQuipTool/index.js +0 -30
  442. package/dist/ui/tools/CreateQuipTool/index.js.map +0 -1
  443. package/dist/ui/tools/CreateSkillTool/index.js +0 -22
  444. package/dist/ui/tools/CreateSkillTool/index.js.map +0 -1
  445. package/dist/ui/tools/CreateToolTool/index.js +0 -31
  446. package/dist/ui/tools/CreateToolTool/index.js.map +0 -1
  447. package/dist/ui/tools/DelegateRemoteTool/index.js +0 -42
  448. package/dist/ui/tools/DelegateRemoteTool/index.js.map +0 -1
  449. package/dist/ui/tools/DeployTool/index.js +0 -47
  450. package/dist/ui/tools/DeployTool/index.js.map +0 -1
  451. package/dist/ui/tools/FffTool/index.js +0 -103
  452. package/dist/ui/tools/FffTool/index.js.map +0 -1
  453. package/dist/ui/tools/FileEditTool/index.js +0 -67
  454. package/dist/ui/tools/FileEditTool/index.js.map +0 -1
  455. package/dist/ui/tools/FileReadTool/index.js +0 -68
  456. package/dist/ui/tools/FileReadTool/index.js.map +0 -1
  457. package/dist/ui/tools/FileWriteTool/index.js +0 -61
  458. package/dist/ui/tools/FileWriteTool/index.js.map +0 -1
  459. package/dist/ui/tools/ForkTool/index.js +0 -47
  460. package/dist/ui/tools/ForkTool/index.js.map +0 -1
  461. package/dist/ui/tools/FrgTool/index.js +0 -96
  462. package/dist/ui/tools/FrgTool/index.js.map +0 -1
  463. package/dist/ui/tools/GetThreadTool/index.js +0 -39
  464. package/dist/ui/tools/GetThreadTool/index.js.map +0 -1
  465. package/dist/ui/tools/GlobTool/index.js +0 -50
  466. package/dist/ui/tools/GlobTool/index.js.map +0 -1
  467. package/dist/ui/tools/GrepTool/index.js +0 -84
  468. package/dist/ui/tools/GrepTool/index.js.map +0 -1
  469. package/dist/ui/tools/HatchArionTool/index.js +0 -36
  470. package/dist/ui/tools/HatchArionTool/index.js.map +0 -1
  471. package/dist/ui/tools/LearnSkillTool/index.js +0 -22
  472. package/dist/ui/tools/LearnSkillTool/index.js.map +0 -1
  473. package/dist/ui/tools/LearnTool/index.js +0 -43
  474. package/dist/ui/tools/LearnTool/index.js.map +0 -1
  475. package/dist/ui/tools/LearnToolTool/index.js +0 -22
  476. package/dist/ui/tools/LearnToolTool/index.js.map +0 -1
  477. package/dist/ui/tools/ListClientsTool/index.js +0 -39
  478. package/dist/ui/tools/ListClientsTool/index.js.map +0 -1
  479. package/dist/ui/tools/LspTool/index.js +0 -261
  480. package/dist/ui/tools/LspTool/index.js.map +0 -1
  481. package/dist/ui/tools/MCPTool/index.js +0 -33
  482. package/dist/ui/tools/MCPTool/index.js.map +0 -1
  483. package/dist/ui/tools/ManageNetworkTool/index.js +0 -53
  484. package/dist/ui/tools/ManageNetworkTool/index.js.map +0 -1
  485. package/dist/ui/tools/MemoryReadTool/index.js +0 -64
  486. package/dist/ui/tools/MemoryReadTool/index.js.map +0 -1
  487. package/dist/ui/tools/MemoryWriteTool/index.js +0 -20
  488. package/dist/ui/tools/MemoryWriteTool/index.js.map +0 -1
  489. package/dist/ui/tools/NotebookEditTool/index.js +0 -33
  490. package/dist/ui/tools/NotebookEditTool/index.js.map +0 -1
  491. package/dist/ui/tools/NotebookReadTool/index.js +0 -25
  492. package/dist/ui/tools/NotebookReadTool/index.js.map +0 -1
  493. package/dist/ui/tools/OutlookReadTool/index.js +0 -66
  494. package/dist/ui/tools/OutlookReadTool/index.js.map +0 -1
  495. package/dist/ui/tools/OutlookReplyTool/index.js +0 -49
  496. package/dist/ui/tools/OutlookReplyTool/index.js.map +0 -1
  497. package/dist/ui/tools/OutlookSendTool/index.js +0 -49
  498. package/dist/ui/tools/OutlookSendTool/index.js.map +0 -1
  499. package/dist/ui/tools/PauseDelegationTool/index.js +0 -35
  500. package/dist/ui/tools/PauseDelegationTool/index.js.map +0 -1
  501. package/dist/ui/tools/ProbeTool/index.js +0 -121
  502. package/dist/ui/tools/ProbeTool/index.js.map +0 -1
  503. package/dist/ui/tools/ProcessTool/index.js +0 -66
  504. package/dist/ui/tools/ProcessTool/index.js.map +0 -1
  505. package/dist/ui/tools/QuestListTool/index.js +0 -46
  506. package/dist/ui/tools/QuestListTool/index.js.map +0 -1
  507. package/dist/ui/tools/QuestReportTool/index.js +0 -49
  508. package/dist/ui/tools/QuestReportTool/index.js.map +0 -1
  509. package/dist/ui/tools/QuestUpdateTool/index.js +0 -87
  510. package/dist/ui/tools/QuestUpdateTool/index.js.map +0 -1
  511. package/dist/ui/tools/QuipCommentTool/index.js +0 -69
  512. package/dist/ui/tools/QuipCommentTool/index.js.map +0 -1
  513. package/dist/ui/tools/QuipReadTool/index.js +0 -71
  514. package/dist/ui/tools/QuipReadTool/index.js.map +0 -1
  515. package/dist/ui/tools/RestArionTool/index.js +0 -32
  516. package/dist/ui/tools/RestArionTool/index.js.map +0 -1
  517. package/dist/ui/tools/RestartTool/index.js +0 -35
  518. package/dist/ui/tools/RestartTool/index.js.map +0 -1
  519. package/dist/ui/tools/ResumeDelegationTool/index.js +0 -35
  520. package/dist/ui/tools/ResumeDelegationTool/index.js.map +0 -1
  521. package/dist/ui/tools/RetireArionTool/index.js +0 -32
  522. package/dist/ui/tools/RetireArionTool/index.js.map +0 -1
  523. package/dist/ui/tools/RgTool/index.js +0 -73
  524. package/dist/ui/tools/RgTool/index.js.map +0 -1
  525. package/dist/ui/tools/SearchKnowledgeTool/index.js +0 -43
  526. package/dist/ui/tools/SearchKnowledgeTool/index.js.map +0 -1
  527. package/dist/ui/tools/SearchMessagesTool/index.js +0 -43
  528. package/dist/ui/tools/SearchMessagesTool/index.js.map +0 -1
  529. package/dist/ui/tools/SelfDiagnoseTool/index.js +0 -61
  530. package/dist/ui/tools/SelfDiagnoseTool/index.js.map +0 -1
  531. package/dist/ui/tools/SendMessageTool/index.js +0 -45
  532. package/dist/ui/tools/SendMessageTool/index.js.map +0 -1
  533. package/dist/ui/tools/SerenaTool/index.js +0 -124
  534. package/dist/ui/tools/SerenaTool/index.js.map +0 -1
  535. package/dist/ui/tools/SessionHistoryTool/index.js +0 -52
  536. package/dist/ui/tools/SessionHistoryTool/index.js.map +0 -1
  537. package/dist/ui/tools/SgTool/index.js +0 -80
  538. package/dist/ui/tools/SgTool/index.js.map +0 -1
  539. package/dist/ui/tools/SlackReactTool/index.js +0 -41
  540. package/dist/ui/tools/SlackReactTool/index.js.map +0 -1
  541. package/dist/ui/tools/SlackReadTool/index.js +0 -48
  542. package/dist/ui/tools/SlackReadTool/index.js.map +0 -1
  543. package/dist/ui/tools/SlackSendTool/index.js +0 -45
  544. package/dist/ui/tools/SlackSendTool/index.js.map +0 -1
  545. package/dist/ui/tools/SpawnWorkerTool/index.js +0 -33
  546. package/dist/ui/tools/SpawnWorkerTool/index.js.map +0 -1
  547. package/dist/ui/tools/StickerRequestTool/index.js +0 -19
  548. package/dist/ui/tools/StickerRequestTool/index.js.map +0 -1
  549. package/dist/ui/tools/ThinkTool/index.js +0 -17
  550. package/dist/ui/tools/ThinkTool/index.js.map +0 -1
  551. package/dist/ui/tools/UgTool/index.js +0 -108
  552. package/dist/ui/tools/UgTool/index.js.map +0 -1
  553. package/dist/ui/tools/UseSkillTool/index.js +0 -22
  554. package/dist/ui/tools/UseSkillTool/index.js.map +0 -1
  555. package/dist/ui/tools/WakeArionTool/index.js +0 -32
  556. package/dist/ui/tools/WakeArionTool/index.js.map +0 -1
  557. package/dist/ui/tools/WebFetchTool/index.js +0 -56
  558. package/dist/ui/tools/WebFetchTool/index.js.map +0 -1
  559. package/dist/ui/tools/WebSearchTool/index.js +0 -44
  560. package/dist/ui/tools/WebSearchTool/index.js.map +0 -1
  561. package/dist/ui/tools/lsTool/index.js +0 -58
  562. package/dist/ui/tools/lsTool/index.js.map +0 -1
  563. package/dist/ui/tools/registry.js +0 -197
  564. package/dist/ui/tools/registry.js.map +0 -1
  565. package/dist/ui/tools/tool-renderer.js +0 -11
  566. package/dist/ui/tools/tool-renderer.js.map +0 -1
  567. package/dist/ui/tools/truncation.js +0 -35
  568. package/dist/ui/tools/truncation.js.map +0 -1
  569. package/dist/ui/types/anthropic.js +0 -4
  570. package/dist/ui/types/anthropic.js.map +0 -1
  571. package/dist/ui/types/index.js +0 -2
  572. package/dist/ui/types/index.js.map +0 -1
  573. package/dist/ui/types/message.js +0 -3
  574. package/dist/ui/types/message.js.map +0 -1
  575. package/dist/ui/types/tool.js +0 -4
  576. package/dist/ui/types/tool.js.map +0 -1
  577. package/dist/ui/utils/array.js +0 -4
  578. package/dist/ui/utils/array.js.map +0 -1
  579. package/dist/ui/utils/cursor.js +0 -131
  580. package/dist/ui/utils/cursor.js.map +0 -1
  581. package/dist/ui/utils/diff.js +0 -120
  582. package/dist/ui/utils/diff.js.map +0 -1
  583. package/dist/ui/utils/format.js +0 -42
  584. package/dist/ui/utils/format.js.map +0 -1
  585. package/dist/ui/utils/fuzzy.js +0 -59
  586. package/dist/ui/utils/fuzzy.js.map +0 -1
  587. package/dist/ui/utils/index.js +0 -11
  588. package/dist/ui/utils/index.js.map +0 -1
  589. package/dist/ui/utils/keys.js +0 -8
  590. package/dist/ui/utils/keys.js.map +0 -1
  591. package/dist/ui/utils/patch.js +0 -17
  592. package/dist/ui/utils/patch.js.map +0 -1
  593. package/dist/ui/utils/risk.js +0 -114
  594. package/dist/ui/utils/risk.js.map +0 -1
  595. package/dist/ui/utils/terminal-image.js +0 -70
  596. package/dist/ui/utils/terminal-image.js.map +0 -1
  597. package/dist/ui/utils/validation.js +0 -48
  598. package/dist/ui/utils/validation.js.map +0 -1
  599. package/dist/ui/verb-pairs.js +0 -248
  600. package/dist/ui/verb-pairs.js.map +0 -1
  601. package/dist/ui.js +0 -131
  602. package/dist/ui.js.map +0 -1
  603. package/src/entrypoints/command-mode.ts +0 -5
  604. package/src/entrypoints/daemon.ts +0 -54
  605. package/src/entrypoints/headless-stdio.ts +0 -27
  606. package/src/entrypoints/interactive.ts +0 -112
  607. package/src/main.ts +0 -72
  608. package/src/runtime/configure-bun-sqlite.ts +0 -3
  609. package/src/runtime/crash-handlers.ts +0 -128
  610. package/src/runtime/interactive-invocation.test.ts +0 -42
  611. package/src/runtime/interactive-invocation.ts +0 -51
  612. package/src/runtime/internal-mode.test.ts +0 -19
  613. package/src/runtime/internal-mode.ts +0 -24
  614. package/src/runtime/launch-spec.test.ts +0 -26
  615. package/src/runtime/launch-spec.ts +0 -84
  616. package/src/runtime/owner-lease.ts +0 -52
  617. package/src/runtime/public-mode.test.ts +0 -18
  618. package/src/runtime/public-mode.ts +0 -19
  619. package/src/runtime/run-internal-mode.ts +0 -19
  620. package/src/runtime/runtime-kind.test.ts +0 -23
  621. package/src/runtime/runtime-kind.ts +0 -41
  622. package/src/runtime/spawn-aria.ts +0 -62
@@ -1,1460 +0,0 @@
1
- // packages/cli/src/ui/markdown/index.ts
2
- import chalk, { Chalk } from "chalk";
3
- import colorName from "color-name";
4
- import katex from "katex";
5
- import { Marked } from "marked";
6
- // @ts-expect-error marked-terminal has no type declarations
7
- import { markedTerminal } from "marked-terminal";
8
- import { highlightCode } from "./highlight.js";
9
- import { getTheme } from "../theme/index.js";
10
- const LIST_BULLETS = ["•", "◦", "▪", "▫"];
11
- /**
12
- * Render markdown string to terminal-formatted string
13
- */
14
- export function applyMarkdown(markdown, options = {}) {
15
- const normalizedMarkdown = normalizeSectionNumbering(markdown);
16
- const layoutStableMarkdown = options.mode === "streaming" ? demoteStreamingTables(normalizedMarkdown) : normalizedMarkdown;
17
- const { content: protectedMarkdown, placeholders } = protectMathSpans(layoutStableMarkdown);
18
- const colorWordMode = resolveColorWordMode(options.colorWordMode);
19
- const localMarked = new Marked();
20
- localMarked.use(markedTerminal({
21
- showSectionPrefix: false,
22
- reflowText: false,
23
- emoji: false,
24
- unescape: true,
25
- width: options.width ?? (process.stdout.columns || 80),
26
- tab: 2,
27
- // Horizontal rule — use our dim dash style
28
- hr: () => chalk.dim("─".repeat(options.width ?? 40)),
29
- }));
30
- // Override renderers for marked v17 compatibility and custom formatting
31
- localMarked.use({
32
- renderer: {
33
- // Fix: marked-terminal text() drops inline token children in marked v17.
34
- // Also apply color-word colorization here on raw text (before ANSI wrapping).
35
- text(token) {
36
- if ("tokens" in token && token.tokens) {
37
- return this.parser.parseInline(token.tokens);
38
- }
39
- return colorizeColorWords(token.text, colorWordMode);
40
- },
41
- // Paragraph — pass through without ANSI reset wrapping
42
- // (marked-terminal's default wraps with chalk.reset which adds \x1b[0m)
43
- paragraph(token) {
44
- return this.parser.parseInline(token.tokens) + "\n\n";
45
- },
46
- // Code blocks — use our syntax highlighter
47
- code(token) {
48
- const theme = getTheme();
49
- const language = token.lang || "text";
50
- try {
51
- return "\n" + highlightCode(token.text, language) + "\n\n";
52
- }
53
- catch {
54
- return "\n" + chalk.hex(theme.colors.info)(token.text) + "\n\n";
55
- }
56
- },
57
- // Inline code — use our theme color
58
- codespan(token) {
59
- const theme = getTheme();
60
- return chalk.hex(theme.colors.info)(token.text);
61
- },
62
- // Links — OSC 8 hyperlinks
63
- link(token) {
64
- const theme = getTheme();
65
- const text = this.parser.parseInline(token.tokens);
66
- const href = token.href;
67
- if (supportsHyperlinks()) {
68
- return `\x1b]8;;${href}\x07${chalk.hex(theme.colors.info).underline(text)}\x1b]8;;\x07`;
69
- }
70
- if (text === href) {
71
- return chalk.hex(theme.colors.info).underline(text);
72
- }
73
- return `${chalk.hex(theme.colors.info).underline(text)} (${chalk.dim(href)})`;
74
- },
75
- // Lists — custom bullets (•/◦/▪/▫) + ordered list start number preservation
76
- list(token) {
77
- const items = token.items;
78
- const ordered = token.ordered;
79
- const start = typeof token.start === "number" ? token.start : 1;
80
- const depth = this._listDepth ?? 0;
81
- const renderedItems = items.map((item, index) => {
82
- const bullet = ordered ? `${start + index}.` : LIST_BULLETS[depth % LIST_BULLETS.length];
83
- const indent = " ".repeat(depth);
84
- const prevDepth = this._listDepth;
85
- this._listDepth = depth + 1;
86
- // parser.parse handles checkbox tokens automatically
87
- const content = this.parser.parse(item.tokens).trim();
88
- this._listDepth = prevDepth;
89
- return `${indent}${bullet} ${content}`;
90
- });
91
- return "\n" + renderedItems.join("\n") + "\n\n";
92
- },
93
- // Blockquotes — │ prefix with dim italic styling
94
- blockquote(token) {
95
- const content = this.parser.parse(token.tokens);
96
- const lines = content.split("\n").filter((line) => line.trim());
97
- return lines.map((line) => chalk.dim.italic(`│ ${line}`)).join("\n") + "\n\n";
98
- },
99
- // Table — width-aware rendering, wraps cells to fit terminal
100
- table(token) {
101
- const termWidth = options.width ?? (process.stdout.columns || 80);
102
- const numCols = token.header.length;
103
- if (numCols === 0)
104
- return "\n";
105
- const headerTexts = token.header.map((cell) => this.parser.parseInline(cell.tokens));
106
- const bodyTexts = token.rows.map((row) => row.map((cell) => this.parser.parseInline(cell.tokens)));
107
- const colWidths = new Array(numCols).fill(0);
108
- const minColWidths = new Array(numCols).fill(0);
109
- for (let c = 0; c < numCols; c++) {
110
- const columnTexts = [headerTexts[c] ?? "", ...bodyTexts.map((row) => row[c] ?? "")];
111
- colWidths[c] = ansiStrippedLength(headerTexts[c] ?? "");
112
- for (const text of columnTexts) {
113
- colWidths[c] = Math.max(colWidths[c], ansiStrippedLength(text));
114
- }
115
- minColWidths[c] = getPreferredTableColumnWidth(columnTexts);
116
- }
117
- // overhead = │ borders (numCols+1) + 1 space padding each side (numCols*2)
118
- const overhead = numCols + 1 + numCols * 2;
119
- if (colWidths.reduce((a, b) => a + b, 0) + overhead > termWidth) {
120
- fitColumnsToWidth(colWidths, termWidth - overhead, minColWidths);
121
- }
122
- const hline = (l, m, r) => l + colWidths.map((w) => "─".repeat(w + 2)).join(m) + r;
123
- const out = [hline("┌", "┬", "┐")];
124
- out.push(...formatTableRow(headerTexts, colWidths, token.align));
125
- out.push(hline("├", "┼", "┤"));
126
- for (let r = 0; r < bodyTexts.length; r++) {
127
- out.push(...formatTableRow(bodyTexts[r], colWidths, token.align));
128
- if (r < bodyTexts.length - 1)
129
- out.push(hline("├", "┼", "┤"));
130
- }
131
- out.push(hline("└", "┴", "┘"));
132
- return out.join("\n") + "\n\n";
133
- },
134
- },
135
- });
136
- const rendered = localMarked.parse(protectedMarkdown);
137
- const restored = restoreMathSpans(rendered, placeholders, resolveMathRenderer(options.mathRenderer), colorWordMode);
138
- return restored.replace(/\n{3,}/g, "\n\n").trimEnd();
139
- }
140
- function supportsHyperlinks() {
141
- const term = process.env.TERM_PROGRAM ?? "";
142
- const supported = ["iTerm.app", "WezTerm", "Hyper", "vscode"];
143
- return supported.some((t) => term.includes(t));
144
- }
145
- function protectMathSpans(markdown) {
146
- const placeholders = [];
147
- let content = "";
148
- let i = 0;
149
- while (i < markdown.length) {
150
- const fencedCode = readFencedCodeBlock(markdown, i);
151
- if (fencedCode) {
152
- content += fencedCode.segment;
153
- i = fencedCode.end;
154
- continue;
155
- }
156
- const inlineCode = readInlineCodeSpan(markdown, i);
157
- if (inlineCode) {
158
- content += inlineCode.segment;
159
- i = inlineCode.end;
160
- continue;
161
- }
162
- const mathSpan = readMathSpan(markdown, i);
163
- if (mathSpan) {
164
- const marker = `ARIAMATHTOKEN${placeholders.length}X`;
165
- placeholders.push({ marker, original: mathSpan.segment, kind: mathSpan.kind });
166
- content += marker;
167
- i = mathSpan.end;
168
- continue;
169
- }
170
- const bareMath = readBareLatexExpression(markdown, i);
171
- if (bareMath) {
172
- const marker = `ARIAMATHTOKEN${placeholders.length}X`;
173
- placeholders.push({ marker, original: bareMath.segment, kind: "bare_math" });
174
- content += marker;
175
- i = bareMath.end;
176
- continue;
177
- }
178
- const latexCommand = readLatexCommand(markdown, i);
179
- if (latexCommand) {
180
- const marker = `ARIAMATHTOKEN${placeholders.length}X`;
181
- placeholders.push({ marker, original: latexCommand.segment, kind: "latex_command" });
182
- content += marker;
183
- i = latexCommand.end;
184
- continue;
185
- }
186
- content += markdown[i];
187
- i += 1;
188
- }
189
- return { content, placeholders };
190
- }
191
- function resolveMathRenderer(preferred) {
192
- if (preferred)
193
- return preferred;
194
- const env = (process.env.ARIA_MARKDOWN_MATH_RENDERER ?? "").trim().toLowerCase();
195
- if (env === "katex" || env === "fast")
196
- return env;
197
- return "fast";
198
- }
199
- function resolveColorWordMode(preferred) {
200
- if (preferred)
201
- return preferred;
202
- const env = (process.env.ARIA_MARKDOWN_COLOR_WORD_MODE ?? "").trim().toLowerCase();
203
- if (env === "always" || env === "never" || env === "auto") {
204
- return env;
205
- }
206
- return "auto";
207
- }
208
- function restoreMathSpans(rendered, placeholders, mathRenderer, colorWordMode) {
209
- const theme = getTheme();
210
- let restored = rendered;
211
- for (const placeholder of placeholders) {
212
- const math = renderMathPlaceholder(placeholder, mathRenderer);
213
- let replacement = math.style ? chalk.hex(theme.colors.info)(math.text) : math.text;
214
- replacement = colorizeColorWords(replacement, colorWordMode);
215
- restored = restored.split(placeholder.marker).join(replacement);
216
- }
217
- return restored;
218
- }
219
- function readMathSpan(text, start) {
220
- if (text[start] !== "$" || isEscaped(text, start))
221
- return null;
222
- // Display math: $$...$$ (may span multiple lines)
223
- if (text[start + 1] === "$" && !isEscaped(text, start + 1)) {
224
- const close = findUnescaped(text, "$$", start + 2);
225
- if (close === -1)
226
- return null;
227
- const inner = text.slice(start + 2, close);
228
- if (!inner.trim())
229
- return null;
230
- return { segment: text.slice(start, close + 2), end: close + 2, kind: "display_math" };
231
- }
232
- // Inline math: $...$ (must close on the same line)
233
- const close = findInlineMathClose(text, start + 1);
234
- if (close === -1)
235
- return null;
236
- const inner = text.slice(start + 1, close);
237
- if (!looksLikeInlineMath(inner))
238
- return null;
239
- return { segment: text.slice(start, close + 1), end: close + 1, kind: "inline_math" };
240
- }
241
- function findInlineMathClose(text, from) {
242
- for (let i = from; i < text.length; i += 1) {
243
- const ch = text[i];
244
- if (ch === "\n")
245
- return -1;
246
- if (ch === "$" && !isEscaped(text, i))
247
- return i;
248
- }
249
- return -1;
250
- }
251
- function findUnescaped(text, delimiter, from) {
252
- let index = text.indexOf(delimiter, from);
253
- while (index !== -1) {
254
- if (!isEscaped(text, index))
255
- return index;
256
- index = text.indexOf(delimiter, index + delimiter.length);
257
- }
258
- return -1;
259
- }
260
- function isEscaped(text, index) {
261
- let backslashCount = 0;
262
- for (let i = index - 1; i >= 0 && text[i] === "\\"; i -= 1) {
263
- backslashCount += 1;
264
- }
265
- return backslashCount % 2 === 1;
266
- }
267
- function looksLikeInlineMath(inner) {
268
- const trimmed = inner.trim();
269
- if (!trimmed)
270
- return false;
271
- if (/\\/.test(trimmed))
272
- return true;
273
- if (/[{}^_=<>+\-*/]/.test(trimmed))
274
- return true;
275
- return !/\s/.test(trimmed);
276
- }
277
- function readFencedCodeBlock(text, start) {
278
- if (!isLineStart(text, start))
279
- return null;
280
- const rest = text.slice(start);
281
- const match = rest.match(/^(```+|~~~+)[^\n]*\n/);
282
- if (!match)
283
- return null;
284
- const fence = match[1];
285
- let cursor = start + match[0].length;
286
- while (cursor < text.length) {
287
- const lineEnd = text.indexOf("\n", cursor);
288
- const end = lineEnd === -1 ? text.length : lineEnd;
289
- const line = text.slice(cursor, end).trim();
290
- if (line.startsWith(fence)) {
291
- const blockEnd = lineEnd === -1 ? text.length : lineEnd + 1;
292
- return { segment: text.slice(start, blockEnd), end: blockEnd };
293
- }
294
- if (lineEnd === -1)
295
- break;
296
- cursor = lineEnd + 1;
297
- }
298
- // Unterminated fence: preserve the remainder verbatim.
299
- return { segment: text.slice(start), end: text.length };
300
- }
301
- function readInlineCodeSpan(text, start) {
302
- if (text[start] !== "`")
303
- return null;
304
- let ticks = 1;
305
- while (text[start + ticks] === "`")
306
- ticks += 1;
307
- const delimiter = "`".repeat(ticks);
308
- const close = text.indexOf(delimiter, start + ticks);
309
- if (close === -1)
310
- return null;
311
- return { segment: text.slice(start, close + ticks), end: close + ticks };
312
- }
313
- function readLatexCommand(text, start) {
314
- if (text[start] !== "\\")
315
- return null;
316
- const next = text[start + 1];
317
- if (!next)
318
- return null;
319
- if (/[A-Za-z]/.test(next)) {
320
- let end = start + 2;
321
- while (end < text.length && /[A-Za-z]/.test(text[end])) {
322
- end += 1;
323
- }
324
- return { segment: text.slice(start, end), end };
325
- }
326
- // Common TeX control-symbol commands used in model output.
327
- if (/[,:;!{}%$#&_ ]/.test(next)) {
328
- return { segment: text.slice(start, start + 2), end: start + 2 };
329
- }
330
- return null;
331
- }
332
- function readBareLatexExpression(text, start) {
333
- if (text[start] !== "\\")
334
- return null;
335
- const first = readLatexCommand(text, start);
336
- if (!first)
337
- return null;
338
- const firstName = first.segment.slice(1);
339
- if (!isLikelyMathCommand(firstName))
340
- return null;
341
- let end = first.end;
342
- while (end < text.length) {
343
- const ch = text[end];
344
- if (ch === "\n" || ch === "$")
345
- break;
346
- if (ch === "\\") {
347
- const cmd = readLatexCommand(text, end);
348
- if (!cmd)
349
- break;
350
- end = cmd.end;
351
- continue;
352
- }
353
- if (/[A-Za-z0-9^_{}()[\]+\-*/=.,:; ]/.test(ch)) {
354
- end += 1;
355
- continue;
356
- }
357
- break;
358
- }
359
- const segment = text.slice(start, end).trimEnd();
360
- if (segment.length <= first.segment.length)
361
- return null;
362
- return { segment, end: start + segment.length };
363
- }
364
- function isLikelyMathCommand(name) {
365
- if (!name)
366
- return false;
367
- if (LATEX_SYMBOLS[name])
368
- return true;
369
- if (LATEX_FUNCTIONS.has(name))
370
- return true;
371
- return ["frac", "binom", "sqrt", "left", "right", "text"].includes(name);
372
- }
373
- const LATEX_SYMBOLS = {
374
- alpha: "α",
375
- beta: "β",
376
- gamma: "γ",
377
- delta: "δ",
378
- epsilon: "ε",
379
- varepsilon: "ε",
380
- zeta: "ζ",
381
- eta: "η",
382
- theta: "θ",
383
- vartheta: "ϑ",
384
- iota: "ι",
385
- kappa: "κ",
386
- lambda: "λ",
387
- mu: "μ",
388
- nu: "ν",
389
- xi: "ξ",
390
- pi: "π",
391
- varpi: "ϖ",
392
- rho: "ρ",
393
- varrho: "ϱ",
394
- sigma: "σ",
395
- varsigma: "ς",
396
- tau: "τ",
397
- upsilon: "υ",
398
- phi: "ϕ",
399
- varphi: "φ",
400
- chi: "χ",
401
- psi: "ψ",
402
- omega: "ω",
403
- Gamma: "Γ",
404
- Delta: "Δ",
405
- Theta: "Θ",
406
- Lambda: "Λ",
407
- Xi: "Ξ",
408
- Pi: "Π",
409
- Sigma: "Σ",
410
- Upsilon: "Υ",
411
- Phi: "Φ",
412
- Psi: "Ψ",
413
- Omega: "Ω",
414
- int: "∫",
415
- sum: "∑",
416
- prod: "∏",
417
- infty: "∞",
418
- partial: "∂",
419
- nabla: "∇",
420
- times: "×",
421
- cdot: "·",
422
- pm: "±",
423
- mp: "∓",
424
- leq: "≤",
425
- geq: "≥",
426
- neq: "≠",
427
- approx: "≈",
428
- sim: "∼",
429
- to: "→",
430
- leftarrow: "←",
431
- rightarrow: "→",
432
- leftrightarrow: "↔",
433
- mapsto: "↦",
434
- in: "∈",
435
- notin: "∉",
436
- subset: "⊂",
437
- subseteq: "⊆",
438
- supset: "⊃",
439
- supseteq: "⊇",
440
- cup: "∪",
441
- cap: "∩",
442
- forall: "∀",
443
- exists: "∃",
444
- neg: "¬",
445
- lnot: "¬",
446
- land: "∧",
447
- lor: "∨",
448
- };
449
- const LATEX_FUNCTIONS = new Set([
450
- "sin",
451
- "cos",
452
- "tan",
453
- "cot",
454
- "sec",
455
- "csc",
456
- "log",
457
- "ln",
458
- "exp",
459
- "max",
460
- "min",
461
- "lim",
462
- ]);
463
- const SUPERSCRIPT_MAP = {
464
- "0": "⁰",
465
- "1": "¹",
466
- "2": "²",
467
- "3": "³",
468
- "4": "⁴",
469
- "5": "⁵",
470
- "6": "⁶",
471
- "7": "⁷",
472
- "8": "⁸",
473
- "9": "⁹",
474
- "+": "⁺",
475
- "-": "⁻",
476
- "=": "⁼",
477
- "(": "⁽",
478
- ")": "⁾",
479
- n: "ⁿ",
480
- i: "ⁱ",
481
- a: "ᵃ",
482
- b: "ᵇ",
483
- c: "ᶜ",
484
- d: "ᵈ",
485
- e: "ᵉ",
486
- f: "ᶠ",
487
- g: "ᵍ",
488
- h: "ʰ",
489
- j: "ʲ",
490
- k: "ᵏ",
491
- l: "ˡ",
492
- m: "ᵐ",
493
- o: "ᵒ",
494
- p: "ᵖ",
495
- r: "ʳ",
496
- s: "ˢ",
497
- t: "ᵗ",
498
- u: "ᵘ",
499
- v: "ᵛ",
500
- w: "ʷ",
501
- x: "ˣ",
502
- y: "ʸ",
503
- z: "ᶻ",
504
- };
505
- const SUBSCRIPT_MAP = {
506
- "0": "₀",
507
- "1": "₁",
508
- "2": "₂",
509
- "3": "₃",
510
- "4": "₄",
511
- "5": "₅",
512
- "6": "₆",
513
- "7": "₇",
514
- "8": "₈",
515
- "9": "₉",
516
- "+": "₊",
517
- "-": "₋",
518
- "=": "₌",
519
- "(": "₍",
520
- ")": "₎",
521
- a: "ₐ",
522
- e: "ₑ",
523
- h: "ₕ",
524
- i: "ᵢ",
525
- j: "ⱼ",
526
- k: "ₖ",
527
- l: "ₗ",
528
- m: "ₘ",
529
- n: "ₙ",
530
- o: "ₒ",
531
- p: "ₚ",
532
- r: "ᵣ",
533
- s: "ₛ",
534
- t: "ₜ",
535
- u: "ᵤ",
536
- v: "ᵥ",
537
- x: "ₓ",
538
- };
539
- function renderMathPlaceholder(placeholder, mathRenderer) {
540
- if (mathRenderer === "katex") {
541
- const displayMode = placeholder.kind === "display_math";
542
- const source = placeholder.kind === "inline_math"
543
- ? placeholder.original.slice(1, -1)
544
- : placeholder.kind === "display_math"
545
- ? placeholder.original.slice(2, -2)
546
- : placeholder.original;
547
- const rendered = renderWithKatexMath(source, displayMode);
548
- if (rendered) {
549
- return { text: rendered, style: true };
550
- }
551
- }
552
- if (placeholder.kind === "inline_math") {
553
- const inner = placeholder.original.slice(1, -1);
554
- return { text: renderInlineMath(inner), style: true };
555
- }
556
- if (placeholder.kind === "display_math") {
557
- const inner = placeholder.original.slice(2, -2);
558
- return { text: renderDisplayMath(inner), style: true };
559
- }
560
- if (placeholder.kind === "bare_math") {
561
- return { text: renderInlineMath(placeholder.original), style: true };
562
- }
563
- const bare = renderBareLatexCommand(placeholder.original);
564
- const changed = bare !== placeholder.original;
565
- return { text: bare, style: changed };
566
- }
567
- const KATEX_TERMINAL_CACHE = new Map();
568
- const MATHML_WRAPPER_TAGS = new Set(["math", "semantics", "mrow", "mstyle"]);
569
- const MATHML_ENTITY_MAP = {
570
- amp: "&",
571
- lt: "<",
572
- gt: ">",
573
- quot: '"',
574
- apos: "'",
575
- nbsp: " ",
576
- ThinSpace: " ",
577
- NegativeThinSpace: "",
578
- MediumSpace: " ",
579
- ApplyFunction: "",
580
- InvisibleTimes: "·",
581
- InvisibleComma: ",",
582
- };
583
- function renderWithKatexMath(latex, displayMode) {
584
- const trimmed = latex.trim();
585
- if (!trimmed)
586
- return "";
587
- const key = `${displayMode ? "display" : "inline"}:${trimmed}`;
588
- const cached = KATEX_TERMINAL_CACHE.get(key);
589
- if (cached !== undefined) {
590
- return cached;
591
- }
592
- try {
593
- const mathmlHtml = katex.renderToString(trimmed, {
594
- displayMode,
595
- throwOnError: false,
596
- strict: "ignore",
597
- output: "mathml",
598
- });
599
- const rendered = renderMathMlAsTerminalText(mathmlHtml, displayMode);
600
- if (rendered != null && rendered.trim().length > 0) {
601
- const value = rendered.trimEnd();
602
- KATEX_TERMINAL_CACHE.set(key, value);
603
- return value;
604
- }
605
- }
606
- catch {
607
- // Fall through to fast renderer.
608
- }
609
- return null;
610
- }
611
- function renderMathMlAsTerminalText(mathmlHtml, displayMode) {
612
- const mathMatch = mathmlHtml.match(/<math[\s\S]*<\/math>/i);
613
- if (!mathMatch)
614
- return null;
615
- const withoutAnnotation = mathMatch[0].replace(/<annotation[\s\S]*?<\/annotation>/gi, "");
616
- const root = parseMathMl(withoutAnnotation);
617
- if (!root)
618
- return null;
619
- if (displayMode) {
620
- const top = unwrapMathMlNode(root);
621
- if (top?.name === "mfrac") {
622
- const children = childNodes(top);
623
- const numerator = children[0] ? renderMathMlNode(children[0], false).trim() : "";
624
- const denominator = children[1] ? renderMathMlNode(children[1], false).trim() : "";
625
- return renderStackedFraction(numerator, denominator);
626
- }
627
- }
628
- return renderMathMlNode(root, displayMode);
629
- }
630
- function parseMathMl(xml) {
631
- const root = { name: "__root__", attrs: {}, children: [] };
632
- const stack = [root];
633
- const tokenRegex = /<!--[\s\S]*?-->|<[^>]+>|[^<]+/g;
634
- let match;
635
- while ((match = tokenRegex.exec(xml)) !== null) {
636
- const token = match[0];
637
- if (!token)
638
- continue;
639
- if (token.startsWith("<!--") || token.startsWith("<?")) {
640
- continue;
641
- }
642
- if (token.startsWith("</")) {
643
- if (stack.length > 1) {
644
- stack.pop();
645
- }
646
- continue;
647
- }
648
- if (token.startsWith("<")) {
649
- const selfClosing = token.endsWith("/>");
650
- const inner = token.slice(1, token.length - (selfClosing ? 2 : 1)).trim();
651
- if (!inner)
652
- continue;
653
- const nameMatch = inner.match(/^([^\s/>]+)/);
654
- if (!nameMatch)
655
- continue;
656
- const rawName = nameMatch[1];
657
- if (!rawName)
658
- continue;
659
- const name = rawName.replace(/^.*:/, "").toLowerCase();
660
- const attrs = parseXmlAttributes(inner.slice(rawName.length));
661
- const node = { name, attrs, children: [] };
662
- const parent = stack[stack.length - 1];
663
- if (parent) {
664
- parent.children.push(node);
665
- }
666
- if (!selfClosing) {
667
- stack.push(node);
668
- }
669
- continue;
670
- }
671
- const decoded = decodeMathMlEntities(token);
672
- const normalized = normalizeMathMlText(decoded);
673
- if (!normalized)
674
- continue;
675
- const parent = stack[stack.length - 1];
676
- if (parent) {
677
- parent.children.push(normalized);
678
- }
679
- }
680
- const firstMath = childNodes(root).find((node) => node.name === "math");
681
- return firstMath ?? null;
682
- }
683
- function parseXmlAttributes(source) {
684
- const attrs = {};
685
- const regex = /([A-Za-z_:][A-Za-z0-9:._-]*)\s*=\s*("([^"]*)"|'([^']*)')/g;
686
- let match;
687
- while ((match = regex.exec(source)) !== null) {
688
- const rawName = match[1];
689
- if (!rawName)
690
- continue;
691
- const value = match[3] ?? match[4] ?? "";
692
- const name = rawName.replace(/^.*:/, "").toLowerCase();
693
- attrs[name] = decodeMathMlEntities(value);
694
- }
695
- return attrs;
696
- }
697
- function decodeMathMlEntities(input) {
698
- return input
699
- .replace(/&#x([0-9a-fA-F]+);/g, (_m, hex) => {
700
- const cp = Number.parseInt(hex, 16);
701
- return Number.isFinite(cp) ? String.fromCodePoint(cp) : "";
702
- })
703
- .replace(/&#([0-9]+);/g, (_m, dec) => {
704
- const cp = Number.parseInt(dec, 10);
705
- return Number.isFinite(cp) ? String.fromCodePoint(cp) : "";
706
- })
707
- .replace(/&([A-Za-z][A-Za-z0-9]+);/g, (_m, name) => MATHML_ENTITY_MAP[name] ?? name);
708
- }
709
- function normalizeMathMlText(input) {
710
- return input
711
- .replace(/[\u200b\u2061\u2062\u2063\u2064]/g, "")
712
- .replace(/\s+/g, " ")
713
- .trim();
714
- }
715
- function unwrapMathMlNode(node) {
716
- let current = node;
717
- while (MATHML_WRAPPER_TAGS.has(current.name)) {
718
- const nodes = childNodes(current);
719
- if (nodes.length !== 1)
720
- break;
721
- current = nodes[0];
722
- }
723
- return current;
724
- }
725
- function childNodes(node) {
726
- return node.children.filter((child) => typeof child !== "string");
727
- }
728
- function textChildren(node) {
729
- let out = "";
730
- for (const child of node.children) {
731
- if (typeof child === "string") {
732
- out += child;
733
- }
734
- else {
735
- out += textChildren(child);
736
- }
737
- }
738
- return normalizeMathMlText(out);
739
- }
740
- function renderMathMlNode(node, displayMode) {
741
- switch (node.name) {
742
- case "math":
743
- case "semantics":
744
- case "mrow":
745
- case "mstyle":
746
- case "mpadded":
747
- case "mphantom":
748
- case "none":
749
- return joinMathMlChildren(node, displayMode);
750
- case "mi":
751
- case "mn":
752
- case "mtext":
753
- return textChildren(node);
754
- case "mo": {
755
- const op = textChildren(node);
756
- return normalizeMathOperator(op);
757
- }
758
- case "mspace":
759
- return " ";
760
- case "mfrac": {
761
- const nodes = childNodes(node);
762
- const numerator = nodes[0] ? renderMathMlNode(nodes[0], false).trim() : "";
763
- const denominator = nodes[1] ? renderMathMlNode(nodes[1], false).trim() : "";
764
- return `${numerator}⁄${denominator}`.trim();
765
- }
766
- case "msup": {
767
- const nodes = childNodes(node);
768
- const base = nodes[0] ? renderMathMlNode(nodes[0], false) : "";
769
- const exponent = nodes[1] ? renderMathMlNode(nodes[1], false) : "";
770
- return `${base}${renderSuperscript(exponent)}`;
771
- }
772
- case "msub": {
773
- const nodes = childNodes(node);
774
- const base = nodes[0] ? renderMathMlNode(nodes[0], false) : "";
775
- const sub = nodes[1] ? renderMathMlNode(nodes[1], false) : "";
776
- return `${base}${renderSubscript(sub)}`;
777
- }
778
- case "msubsup": {
779
- const nodes = childNodes(node);
780
- const base = nodes[0] ? renderMathMlNode(nodes[0], false) : "";
781
- const sub = nodes[1] ? renderMathMlNode(nodes[1], false) : "";
782
- const sup = nodes[2] ? renderMathMlNode(nodes[2], false) : "";
783
- return `${base}${renderSubscript(sub)}${renderSuperscript(sup)}`;
784
- }
785
- case "msqrt": {
786
- const inner = joinMathMlChildren(node, false);
787
- return inner ? `√(${inner})` : "√";
788
- }
789
- case "mroot": {
790
- const nodes = childNodes(node);
791
- const body = nodes[0] ? renderMathMlNode(nodes[0], false) : "";
792
- const degree = nodes[1] ? renderMathMlNode(nodes[1], false) : "";
793
- return degree ? `${degree}√(${body})` : `√(${body})`;
794
- }
795
- case "mfenced": {
796
- const open = node.attrs.open ?? "(";
797
- const close = node.attrs.close ?? ")";
798
- const inner = joinMathMlChildren(node, false);
799
- return `${open}${inner}${close}`;
800
- }
801
- case "mtable": {
802
- const rows = childNodes(node).filter((child) => child.name === "mtr");
803
- const renderedRows = rows
804
- .map((row) => renderMathMlNode(row, displayMode).trim())
805
- .filter((row) => row.length > 0);
806
- if (renderedRows.length === 0)
807
- return "";
808
- if (displayMode) {
809
- return renderedRows.join("\n");
810
- }
811
- return `[${renderedRows.join("; ")}]`;
812
- }
813
- case "mtr": {
814
- const cols = childNodes(node)
815
- .filter((child) => child.name === "mtd")
816
- .map((cell) => renderMathMlNode(cell, displayMode).trim())
817
- .filter((cell) => cell.length > 0);
818
- return cols.join(" ");
819
- }
820
- case "mtd":
821
- return joinMathMlChildren(node, displayMode);
822
- case "annotation":
823
- return "";
824
- default:
825
- return joinMathMlChildren(node, displayMode);
826
- }
827
- }
828
- function joinMathMlChildren(node, displayMode) {
829
- const parts = node.children.map((child) => {
830
- if (typeof child === "string")
831
- return child;
832
- return renderMathMlNode(child, displayMode);
833
- });
834
- return normalizeMathSpacing(parts.join(""));
835
- }
836
- function normalizeMathOperator(input) {
837
- if (!input)
838
- return "";
839
- if (input === "−")
840
- return "-";
841
- return input;
842
- }
843
- function normalizeMathSpacing(input) {
844
- return input
845
- .replace(/[\u200b\u2061\u2062\u2063\u2064]/g, "")
846
- .replace(/([∫∑∏])([A-Za-z0-9α-ωΑ-Ω])/g, "$1 $2")
847
- .replace(/([\u00B2\u00B3\u00B9\u2070-\u209F])([A-Za-zα-ωΑ-Ω])/g, "$1 $2")
848
- .replace(/([)\]])([A-Za-zα-ωΑ-Ω])/g, "$1 $2")
849
- .replace(/\s*([+\-−=≈≠≤≥<>×÷·∪∩])\s*/g, " $1 ")
850
- .replace(/\s*,\s*/g, ", ")
851
- .replace(/\s*;\s*/g, "; ")
852
- .replace(/\s*:\s*/g, ": ")
853
- .replace(/\(\s+/g, "(")
854
- .replace(/\s+\)/g, ")")
855
- .replace(/\s+/g, " ")
856
- .trim();
857
- }
858
- function renderSuperscript(value) {
859
- const compact = value.replace(/\s+/g, "");
860
- if (!compact)
861
- return "";
862
- return convertScript(`{${compact}}`, SUPERSCRIPT_MAP, "^");
863
- }
864
- function renderSubscript(value) {
865
- const compact = value.replace(/\s+/g, "");
866
- if (!compact)
867
- return "";
868
- return convertScript(`{${compact}}`, SUBSCRIPT_MAP, "_");
869
- }
870
- function renderDisplayMath(latex) {
871
- const trimmed = latex.trim();
872
- if (!trimmed)
873
- return "";
874
- const wholeFraction = parseWholeBinaryCommand(trimmed, "frac");
875
- if (wholeFraction) {
876
- const numerator = renderInlineMath(wholeFraction.arg1).trim();
877
- const denominator = renderInlineMath(wholeFraction.arg2).trim();
878
- return renderStackedFraction(numerator, denominator);
879
- }
880
- return trimmed
881
- .split("\n")
882
- .map((line) => renderInlineMath(line))
883
- .join("\n");
884
- }
885
- function renderInlineMath(latex) {
886
- let rendered = latex.trim();
887
- rendered = normalizeLatexWhitespace(rendered);
888
- rendered = rendered.replace(/\\left\s*/g, "").replace(/\\right\s*/g, "");
889
- rendered = replaceUnaryLatexCommand(rendered, "text", (arg) => renderInlineMath(arg));
890
- rendered = replaceUnaryLatexCommand(rendered, "sqrt", (arg) => `√(${renderInlineMath(arg)})`);
891
- rendered = replaceUnaryLatexCommand(rendered, "mathrm", (arg) => renderInlineMath(arg));
892
- rendered = replaceUnaryLatexCommand(rendered, "mathbf", (arg) => renderInlineMath(arg));
893
- rendered = replaceUnaryLatexCommand(rendered, "mathit", (arg) => renderInlineMath(arg));
894
- rendered = replaceBinaryLatexCommand(rendered, "textcolor", (colorArg, textArg) => {
895
- return applyLatexColor(colorArg, renderInlineMath(textArg));
896
- });
897
- rendered = replaceBinaryLatexCommand(rendered, "color", (colorArg, textArg) => {
898
- return applyLatexColor(colorArg, renderInlineMath(textArg));
899
- });
900
- rendered = replaceBinaryLatexCommand(rendered, "colorbox", (colorArg, textArg) => {
901
- return applyLatexBgColor(colorArg, renderInlineMath(textArg));
902
- });
903
- rendered = replaceBinaryLatexCommand(rendered, "frac", (num, den) => {
904
- return `${renderInlineMath(num)}⁄${renderInlineMath(den)}`;
905
- });
906
- rendered = replaceBinaryLatexCommand(rendered, "binom", (top, bottom) => {
907
- return `C(${renderInlineMath(top)}, ${renderInlineMath(bottom)})`;
908
- });
909
- rendered = replaceCommandWords(rendered);
910
- rendered = replaceEscapedControlSymbols(rendered);
911
- rendered = stripGroupingBraces(rendered);
912
- rendered = applyScriptTransform(rendered);
913
- rendered = rendered.replace(/\s{2,}/g, " ").trim();
914
- return rendered;
915
- }
916
- function renderBareLatexCommand(command) {
917
- if (!command.startsWith("\\"))
918
- return command;
919
- const name = command.slice(1);
920
- if (command === "\\,")
921
- return " ";
922
- if (command === "\\;")
923
- return " ";
924
- if (command === "\\:")
925
- return " ";
926
- if (command === "\\!")
927
- return "";
928
- if (command === "\\ ")
929
- return " ";
930
- if (command === "\\{")
931
- return "{";
932
- if (command === "\\}")
933
- return "}";
934
- if (command === "\\%")
935
- return "%";
936
- if (command === "\\$")
937
- return "$";
938
- if (command === "\\#")
939
- return "#";
940
- if (command === "\\_")
941
- return "_";
942
- if (command === "\\&")
943
- return "&";
944
- if (LATEX_SYMBOLS[name])
945
- return LATEX_SYMBOLS[name];
946
- if (LATEX_FUNCTIONS.has(name))
947
- return name;
948
- return command;
949
- }
950
- function normalizeLatexWhitespace(input) {
951
- return input
952
- .replace(/\\,/g, " ")
953
- .replace(/\\;/g, " ")
954
- .replace(/\\:/g, " ")
955
- .replace(/\\!/g, "")
956
- .replace(/\\qquad/g, " ")
957
- .replace(/\\quad/g, " ")
958
- .replace(/~+/g, " ")
959
- .replace(/\\ /g, " ");
960
- }
961
- function replaceCommandWords(input) {
962
- let output = input;
963
- const symbolNames = Object.keys(LATEX_SYMBOLS).sort((a, b) => b.length - a.length);
964
- for (const name of symbolNames) {
965
- const symbol = LATEX_SYMBOLS[name];
966
- const regex = new RegExp(`\\\\${escapeRegExp(name)}\\b`, "g");
967
- output = output.replace(regex, symbol);
968
- }
969
- for (const name of LATEX_FUNCTIONS) {
970
- const regex = new RegExp(`\\\\${escapeRegExp(name)}\\b`, "g");
971
- output = output.replace(regex, name);
972
- }
973
- return output;
974
- }
975
- function replaceEscapedControlSymbols(input) {
976
- return input.replace(/\\([{}%$#&_])/g, "$1");
977
- }
978
- function stripGroupingBraces(input) {
979
- const openMarker = "__ARIA_ESCAPED_LBRACE__";
980
- const closeMarker = "__ARIA_ESCAPED_RBRACE__";
981
- return input
982
- .replace(/\\\{/g, openMarker)
983
- .replace(/\\\}/g, closeMarker)
984
- .replace(/[{}]/g, "")
985
- .replaceAll(openMarker, "{")
986
- .replaceAll(closeMarker, "}");
987
- }
988
- function applyScriptTransform(input) {
989
- let output = input;
990
- output = output.replace(/([A-Za-z0-9α-ωΑ-Ω)\]])\^(\{[^{}]*\}|.)/g, (_m, base, rawExp) => {
991
- return `${base}${convertScript(rawExp, SUPERSCRIPT_MAP, "^")}`;
992
- });
993
- output = output.replace(/([A-Za-z0-9α-ωΑ-Ω)\]])_(\{[^{}]*\}|.)/g, (_m, base, rawSub) => {
994
- return `${base}${convertScript(rawSub, SUBSCRIPT_MAP, "_")}`;
995
- });
996
- return output;
997
- }
998
- function convertScript(rawScript, table, fallbackPrefix) {
999
- const content = unwrapScript(rawScript);
1000
- if (!content)
1001
- return "";
1002
- let out = "";
1003
- for (const ch of content) {
1004
- const mapped = table[ch];
1005
- if (!mapped) {
1006
- return `${fallbackPrefix}(${content})`;
1007
- }
1008
- out += mapped;
1009
- }
1010
- return out;
1011
- }
1012
- function unwrapScript(rawScript) {
1013
- if (rawScript.startsWith("{") && rawScript.endsWith("}")) {
1014
- return rawScript.slice(1, -1);
1015
- }
1016
- return rawScript;
1017
- }
1018
- function replaceUnaryLatexCommand(input, command, replacer) {
1019
- let output = "";
1020
- let i = 0;
1021
- const token = `\\${command}`;
1022
- while (i < input.length) {
1023
- if (startsWithCommand(input, token, i)) {
1024
- const arg = parseLatexGroup(input, i + token.length);
1025
- if (arg) {
1026
- output += replacer(arg.value);
1027
- i = arg.end;
1028
- continue;
1029
- }
1030
- }
1031
- output += input[i];
1032
- i += 1;
1033
- }
1034
- return output;
1035
- }
1036
- function replaceBinaryLatexCommand(input, command, replacer) {
1037
- let output = "";
1038
- let i = 0;
1039
- const token = `\\${command}`;
1040
- while (i < input.length) {
1041
- if (startsWithCommand(input, token, i)) {
1042
- const first = parseLatexGroup(input, i + token.length);
1043
- if (first) {
1044
- const second = parseLatexGroup(input, first.end);
1045
- if (second) {
1046
- output += replacer(first.value, second.value);
1047
- i = second.end;
1048
- continue;
1049
- }
1050
- }
1051
- }
1052
- output += input[i];
1053
- i += 1;
1054
- }
1055
- return output;
1056
- }
1057
- function parseWholeBinaryCommand(input, command) {
1058
- const token = `\\${command}`;
1059
- const start = skipWhitespace(input, 0);
1060
- if (!startsWithCommand(input, token, start))
1061
- return null;
1062
- const first = parseLatexGroup(input, start + token.length);
1063
- if (!first)
1064
- return null;
1065
- const second = parseLatexGroup(input, first.end);
1066
- if (!second)
1067
- return null;
1068
- const end = skipWhitespace(input, second.end);
1069
- if (end !== input.length)
1070
- return null;
1071
- return { arg1: first.value, arg2: second.value };
1072
- }
1073
- function parseLatexGroup(input, start) {
1074
- let i = skipWhitespace(input, start);
1075
- if (i >= input.length)
1076
- return null;
1077
- if (input[i] === "{") {
1078
- const groupEnd = findMatchingBrace(input, i);
1079
- if (groupEnd === -1)
1080
- return null;
1081
- return { value: input.slice(i + 1, groupEnd), end: groupEnd + 1 };
1082
- }
1083
- if (input[i] === "\\") {
1084
- const cmd = readLatexCommand(input, i);
1085
- if (cmd) {
1086
- return { value: cmd.segment, end: cmd.end };
1087
- }
1088
- }
1089
- return { value: input[i], end: i + 1 };
1090
- }
1091
- function startsWithCommand(input, token, index) {
1092
- if (!input.startsWith(token, index))
1093
- return false;
1094
- const next = input[index + token.length];
1095
- return !next || !/[A-Za-z]/.test(next);
1096
- }
1097
- function skipWhitespace(input, start) {
1098
- let i = start;
1099
- while (i < input.length && /\s/.test(input[i])) {
1100
- i += 1;
1101
- }
1102
- return i;
1103
- }
1104
- function findMatchingBrace(input, openIndex) {
1105
- let depth = 0;
1106
- for (let i = openIndex; i < input.length; i += 1) {
1107
- const ch = input[i];
1108
- if (ch === "{" && !isEscaped(input, i))
1109
- depth += 1;
1110
- if (ch === "}" && !isEscaped(input, i)) {
1111
- depth -= 1;
1112
- if (depth === 0)
1113
- return i;
1114
- }
1115
- }
1116
- return -1;
1117
- }
1118
- function renderStackedFraction(numerator, denominator) {
1119
- const width = Math.max(visibleWidth(numerator), visibleWidth(denominator), 1);
1120
- const bar = "─".repeat(width);
1121
- const top = centerText(numerator, width);
1122
- const bottom = centerText(denominator, width);
1123
- return `${top}\n${bar}\n${bottom}`;
1124
- }
1125
- function visibleWidth(value) {
1126
- return Array.from(value).length;
1127
- }
1128
- function centerText(value, width) {
1129
- const len = visibleWidth(value);
1130
- if (len >= width)
1131
- return value;
1132
- const left = Math.floor((width - len) / 2);
1133
- const right = width - len - left;
1134
- return `${" ".repeat(left)}${value}${" ".repeat(right)}`;
1135
- }
1136
- function escapeRegExp(value) {
1137
- return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1138
- }
1139
- function buildColorWordRenderers(colorizer) {
1140
- const renderers = {};
1141
- const namedColors = colorName;
1142
- for (const [name, rgb] of Object.entries(namedColors)) {
1143
- const normalized = name.toLowerCase();
1144
- const [r, g, b] = rgb;
1145
- if (r === 0 && g === 0 && b === 0) {
1146
- // Pure black is unreadable on dark terminals; keep it visible.
1147
- renderers[normalized] = (word) => colorizer.blackBright(word);
1148
- continue;
1149
- }
1150
- renderers[normalized] = (word) => colorizer.rgb(r, g, b)(word);
1151
- }
1152
- // Defensive aliasing in case one spelling is absent in the source map.
1153
- if (renderers.gray && !renderers.grey) {
1154
- renderers.grey = renderers.gray;
1155
- }
1156
- if (renderers.grey && !renderers.gray) {
1157
- renderers.gray = renderers.grey;
1158
- }
1159
- return renderers;
1160
- }
1161
- const AUTO_COLOR_WORD_RENDERERS = buildColorWordRenderers(chalk);
1162
- const FORCED_COLOR_WORD_RENDERERS = buildColorWordRenderers(new Chalk({ level: 3 }));
1163
- const COLOR_WORD_NAMES = Object.keys(AUTO_COLOR_WORD_RENDERERS).sort((a, b) => b.length - a.length);
1164
- const COLOR_WORD_REGEX = new RegExp(`\\b(${COLOR_WORD_NAMES.join("|")})\\b`, "gi");
1165
- const FORCED_CHALK = new Chalk({ level: 3 });
1166
- function applyLatexColor(colorSpec, text) {
1167
- const name = colorSpec.trim().toLowerCase();
1168
- const render = FORCED_COLOR_WORD_RENDERERS[name];
1169
- if (render)
1170
- return render(text);
1171
- return text;
1172
- }
1173
- function applyLatexBgColor(colorSpec, text) {
1174
- const name = colorSpec.trim().toLowerCase();
1175
- const namedColors = colorName;
1176
- const rgb = namedColors[name];
1177
- if (rgb) {
1178
- const [r, g, b] = rgb;
1179
- return FORCED_CHALK.bgRgb(r, g, b)(text);
1180
- }
1181
- return text;
1182
- }
1183
- function colorizeColorWords(text, mode = "auto") {
1184
- if (mode === "never")
1185
- return text;
1186
- const renderers = mode === "always" ? FORCED_COLOR_WORD_RENDERERS : AUTO_COLOR_WORD_RENDERERS;
1187
- return text.replace(COLOR_WORD_REGEX, (word) => {
1188
- const render = renderers[word.toLowerCase()];
1189
- return render ? render(word) : word;
1190
- });
1191
- }
1192
- function normalizeSectionNumbering(markdown) {
1193
- const lines = markdown.split("\n");
1194
- return lines
1195
- .map((line, index) => {
1196
- const match = line.match(/^(\d+)\.\s+(.+)$/);
1197
- if (!match)
1198
- return line;
1199
- const prevBlank = index === 0 || !lines[index - 1].trim();
1200
- const nextBlank = index === lines.length - 1 || !lines[index + 1].trim();
1201
- if (!prevBlank || !nextBlank)
1202
- return line;
1203
- // Section-style numbered headers (`N. Title` with blank lines around)
1204
- // should remain literal text, not markdown ordered-list items.
1205
- return `${match[1]}\\. ${match[2]}`;
1206
- })
1207
- .join("\n");
1208
- }
1209
- function isLineStart(text, index) {
1210
- return index === 0 || text[index - 1] === "\n";
1211
- }
1212
- function demoteStreamingTables(markdown) {
1213
- const lines = markdown.split("\n");
1214
- const output = [];
1215
- for (let i = 0; i < lines.length; i += 1) {
1216
- const current = lines[i] ?? "";
1217
- const next = lines[i + 1] ?? "";
1218
- if (looksLikeMarkdownTableHeader(current) && looksLikeMarkdownTableSeparator(next)) {
1219
- let cursor = i;
1220
- while (cursor < lines.length && looksLikeMarkdownTableRow(lines[cursor] ?? "")) {
1221
- output.push(escapeMarkdownTableRow(lines[cursor]));
1222
- cursor += 1;
1223
- }
1224
- i = cursor - 1;
1225
- continue;
1226
- }
1227
- output.push(current);
1228
- }
1229
- return output.join("\n");
1230
- }
1231
- function looksLikeMarkdownTableHeader(line) {
1232
- const trimmed = line.trim();
1233
- if (!trimmed.includes("|"))
1234
- return false;
1235
- if (/^[-:|\s]+$/.test(trimmed))
1236
- return false;
1237
- const cells = splitMarkdownTableCells(trimmed);
1238
- return cells.length >= 2 && cells.some((cell) => cell.length > 0);
1239
- }
1240
- function looksLikeMarkdownTableSeparator(line) {
1241
- const cells = splitMarkdownTableCells(line.trim());
1242
- return cells.length >= 2 && cells.every((cell) => /^:?-{3,}:?$/.test(cell));
1243
- }
1244
- function looksLikeMarkdownTableRow(line) {
1245
- const trimmed = line.trim();
1246
- return trimmed.length > 0 && trimmed.includes("|");
1247
- }
1248
- function splitMarkdownTableCells(line) {
1249
- let normalized = line.trim();
1250
- if (normalized.startsWith("|"))
1251
- normalized = normalized.slice(1);
1252
- if (normalized.endsWith("|"))
1253
- normalized = normalized.slice(0, -1);
1254
- return normalized.split("|").map((cell) => cell.trim());
1255
- }
1256
- function escapeMarkdownTableRow(line) {
1257
- return line.replace(/\|/g, "\\|");
1258
- }
1259
- // ── Table rendering helpers ──────────────────────────────────────────
1260
- const ANSI_ESCAPE_RE = /\x1b\[[0-9;]*m|\x1b\]8;;[^\x07]*\x07/g;
1261
- function stripAnsiCodes(text) {
1262
- return text.replace(ANSI_ESCAPE_RE, "");
1263
- }
1264
- function ansiStrippedLength(text) {
1265
- return stripAnsiCodes(text).length;
1266
- }
1267
- function fitColumnsToWidth(colWidths, available, minColWidths) {
1268
- const MIN_COL = 3;
1269
- const total = colWidths.reduce((a, b) => a + b, 0);
1270
- if (total <= available)
1271
- return;
1272
- const adjustedMinWidths = shrinkPreferredTableMinWidths(minColWidths, available, MIN_COL);
1273
- const target = available;
1274
- const ratio = target / total;
1275
- for (let i = 0; i < colWidths.length; i++) {
1276
- colWidths[i] = Math.max(adjustedMinWidths[i] ?? MIN_COL, Math.floor(colWidths[i] * ratio));
1277
- }
1278
- // Pass 1: trim widest columns down to their preferred minimums
1279
- let current = colWidths.reduce((a, b) => a + b, 0);
1280
- while (current > target) {
1281
- let widest = 0;
1282
- for (let i = 1; i < colWidths.length; i++) {
1283
- if (colWidths[i] > colWidths[widest])
1284
- widest = i;
1285
- }
1286
- if (colWidths[widest] <= (adjustedMinWidths[widest] ?? MIN_COL))
1287
- break;
1288
- colWidths[widest]--;
1289
- current--;
1290
- }
1291
- // Pass 2: if still over budget, force-shrink past preferred mins to absolute MIN_COL
1292
- while (current > target) {
1293
- let widest = 0;
1294
- for (let i = 1; i < colWidths.length; i++) {
1295
- if (colWidths[i] > colWidths[widest])
1296
- widest = i;
1297
- }
1298
- if (colWidths[widest] <= MIN_COL)
1299
- break;
1300
- colWidths[widest]--;
1301
- current--;
1302
- }
1303
- }
1304
- function shrinkPreferredTableMinWidths(preferredMinWidths, available, absoluteMinWidth) {
1305
- const adjusted = preferredMinWidths.map((width) => Math.max(width, absoluteMinWidth));
1306
- let total = adjusted.reduce((sum, width) => sum + width, 0);
1307
- while (total > available) {
1308
- let widest = -1;
1309
- for (let i = 0; i < adjusted.length; i++) {
1310
- if (adjusted[i] <= absoluteMinWidth)
1311
- continue;
1312
- if (widest === -1 || adjusted[i] > adjusted[widest]) {
1313
- widest = i;
1314
- }
1315
- }
1316
- if (widest === -1)
1317
- break;
1318
- adjusted[widest]--;
1319
- total--;
1320
- }
1321
- return adjusted;
1322
- }
1323
- function getPreferredTableColumnWidth(texts) {
1324
- const ABSOLUTE_MIN = 3;
1325
- const SOFT_MIN_CAP = 24;
1326
- let naturalWidth = ABSOLUTE_MIN;
1327
- let longestWord = ABSOLUTE_MIN;
1328
- for (const text of texts) {
1329
- const normalized = normalizeTableCellText(text);
1330
- naturalWidth = Math.max(naturalWidth, ansiStrippedLength(normalized));
1331
- longestWord = Math.max(longestWord, longestWordLength(normalized));
1332
- }
1333
- // Prefer word-boundary wrapping up to SOFT_MIN_CAP; longer words get hard-broken
1334
- return Math.min(Math.max(ABSOLUTE_MIN, longestWord), SOFT_MIN_CAP);
1335
- }
1336
- function longestWordLength(text) {
1337
- return stripAnsiCodes(text)
1338
- .split(/\s+/)
1339
- .reduce((max, word) => Math.max(max, word.length), 0);
1340
- }
1341
- function wrapCellText(text, width) {
1342
- const normalizedText = normalizeTableCellText(text);
1343
- if (width <= 0 || !normalizedText)
1344
- return [normalizedText || ""];
1345
- // Handle explicit line breaks (from <br> in markdown cells) first
1346
- if (normalizedText.includes("\n")) {
1347
- const result = [];
1348
- for (const segment of normalizedText.split("\n")) {
1349
- result.push(...wrapCellText(segment, width));
1350
- }
1351
- return result;
1352
- }
1353
- if (ansiStrippedLength(normalizedText) <= width)
1354
- return [normalizedText];
1355
- // Tokenize into ANSI escapes and visible segments
1356
- const segments = [];
1357
- let last = 0;
1358
- const re = new RegExp(ANSI_ESCAPE_RE.source, "g");
1359
- let m;
1360
- while ((m = re.exec(normalizedText)) !== null) {
1361
- if (m.index > last)
1362
- segments.push({ ansi: false, value: normalizedText.slice(last, m.index) });
1363
- segments.push({ ansi: true, value: m[0] });
1364
- last = re.lastIndex;
1365
- }
1366
- if (last < normalizedText.length) {
1367
- segments.push({ ansi: false, value: normalizedText.slice(last) });
1368
- }
1369
- // Word-wrap visible segments, preserving ANSI codes
1370
- const lines = [];
1371
- let line = "";
1372
- let lineW = 0;
1373
- const hardBreak = (word) => {
1374
- for (let i = 0; i < word.length; i += width) {
1375
- if (line && lineW > 0)
1376
- lines.push(line);
1377
- line = word.slice(i, i + width);
1378
- lineW = line.length;
1379
- }
1380
- };
1381
- for (const seg of segments) {
1382
- if (seg.ansi) {
1383
- line += seg.value;
1384
- continue;
1385
- }
1386
- const words = seg.value.split(/(\s+)/);
1387
- for (const word of words) {
1388
- if (!word)
1389
- continue;
1390
- const wLen = word.length;
1391
- const isWs = !word.trim();
1392
- if (isWs && lineW === 0)
1393
- continue; // skip leading whitespace on new lines
1394
- if (lineW + wLen <= width) {
1395
- line += word;
1396
- lineW += wLen;
1397
- }
1398
- else if (lineW === 0) {
1399
- hardBreak(word);
1400
- }
1401
- else if (isWs) {
1402
- lines.push(line);
1403
- line = "";
1404
- lineW = 0;
1405
- }
1406
- else {
1407
- // Word overflows current line — start new line, hard-break if still too wide
1408
- lines.push(line);
1409
- line = "";
1410
- lineW = 0;
1411
- if (wLen > width) {
1412
- hardBreak(word);
1413
- }
1414
- else {
1415
- line = word;
1416
- lineW = wLen;
1417
- }
1418
- }
1419
- }
1420
- }
1421
- if (line || lines.length === 0)
1422
- lines.push(line);
1423
- return lines;
1424
- }
1425
- function normalizeTableCellText(text) {
1426
- return text
1427
- .replace(/\s*\n+\s*/g, " ")
1428
- .replace(/\(\s+/g, "(")
1429
- .replace(/\s+\)/g, ")")
1430
- .replace(/\[\s+/g, "[")
1431
- .replace(/\s+\]/g, "]")
1432
- .replace(/[ \t]{2,}/g, " ")
1433
- .trim();
1434
- }
1435
- function padCellText(text, width, align) {
1436
- const vis = ansiStrippedLength(text);
1437
- if (vis >= width)
1438
- return text;
1439
- const gap = width - vis;
1440
- if (align === "right")
1441
- return " ".repeat(gap) + text;
1442
- if (align === "center") {
1443
- const left = Math.floor(gap / 2);
1444
- return " ".repeat(left) + text + " ".repeat(gap - left);
1445
- }
1446
- return text + " ".repeat(gap);
1447
- }
1448
- function formatTableRow(cells, colWidths, align) {
1449
- const wrapped = cells.map((text, c) => wrapCellText(text, colWidths[c]));
1450
- const height = Math.max(...wrapped.map((w) => w.length), 1);
1451
- const result = [];
1452
- for (let ln = 0; ln < height; ln++) {
1453
- const parts = wrapped.map((cellLines, c) => padCellText(cellLines[ln] ?? "", colWidths[c], align[c] ?? null));
1454
- result.push("│ " + parts.join(" │ ") + " │");
1455
- }
1456
- return result;
1457
- }
1458
- export { tokenize } from "./tokenizer.js";
1459
- export { highlightCode, isLanguageSupported } from "./highlight.js";
1460
- //# sourceMappingURL=index.js.map