@bastani/atomic 0.8.26-alpha.5 → 0.8.26-alpha.7

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 (264) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/README.md +7 -4
  3. package/dist/builtin/intercom/CHANGELOG.md +12 -0
  4. package/dist/builtin/intercom/package.json +2 -2
  5. package/dist/builtin/mcp/CHANGELOG.md +12 -0
  6. package/dist/builtin/mcp/package.json +3 -3
  7. package/dist/builtin/subagents/CHANGELOG.md +12 -0
  8. package/dist/builtin/subagents/agents/codebase-online-researcher.md +9 -9
  9. package/dist/builtin/subagents/agents/debugger.md +6 -6
  10. package/dist/builtin/subagents/package.json +4 -4
  11. package/dist/builtin/subagents/prompts/parallel-handoff-plan.md +1 -1
  12. package/dist/builtin/subagents/skills/browser/EXAMPLES.md +151 -0
  13. package/dist/builtin/subagents/skills/browser/LICENSE.txt +21 -0
  14. package/dist/builtin/subagents/skills/browser/REFERENCE.md +451 -0
  15. package/dist/builtin/subagents/skills/browser/SKILL.md +170 -0
  16. package/dist/builtin/subagents/skills/subagent/SKILL.md +4 -4
  17. package/dist/builtin/subagents/src/runs/background/subagent-runner.ts +48 -10
  18. package/dist/builtin/subagents/src/runs/foreground/execution.ts +30 -9
  19. package/dist/builtin/subagents/src/runs/shared/final-drain.ts +34 -0
  20. package/dist/builtin/subagents/src/runs/shared/model-fallback.ts +416 -7
  21. package/dist/builtin/web-access/CHANGELOG.md +12 -0
  22. package/dist/builtin/web-access/package.json +2 -2
  23. package/dist/builtin/workflows/CHANGELOG.md +17 -0
  24. package/dist/builtin/workflows/builtin/deep-research-codebase.ts +4 -1
  25. package/dist/builtin/workflows/builtin/goal.ts +127 -99
  26. package/dist/builtin/workflows/builtin/open-claude-design.ts +224 -147
  27. package/dist/builtin/workflows/builtin/ralph.ts +160 -197
  28. package/dist/builtin/workflows/package.json +2 -2
  29. package/dist/builtin/workflows/skills/research-codebase/SKILL.md +1 -1
  30. package/dist/builtin/workflows/src/extension/index.ts +10 -2
  31. package/dist/builtin/workflows/src/extension/runtime.ts +35 -3
  32. package/dist/builtin/workflows/src/runs/background/status.ts +52 -6
  33. package/dist/builtin/workflows/src/runs/foreground/executor.ts +441 -15
  34. package/dist/builtin/workflows/src/runs/foreground/stage-runner.ts +69 -8
  35. package/dist/builtin/workflows/src/runs/shared/model-fallback.ts +402 -8
  36. package/dist/builtin/workflows/src/shared/persistence-restore.ts +182 -6
  37. package/dist/builtin/workflows/src/shared/persistence-session-entries.ts +76 -6
  38. package/dist/builtin/workflows/src/shared/stage-prompt.ts +33 -2
  39. package/dist/builtin/workflows/src/shared/store-types.ts +31 -0
  40. package/dist/builtin/workflows/src/shared/store.ts +99 -11
  41. package/dist/builtin/workflows/src/shared/workflow-failures.ts +758 -132
  42. package/dist/builtin/workflows/src/tui/stage-chat-view.ts +9 -0
  43. package/dist/core/agent-session.d.ts +28 -1
  44. package/dist/core/agent-session.d.ts.map +1 -1
  45. package/dist/core/agent-session.js +110 -28
  46. package/dist/core/agent-session.js.map +1 -1
  47. package/dist/core/compaction/branch-summarization.d.ts +1 -1
  48. package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
  49. package/dist/core/compaction/branch-summarization.js +6 -3
  50. package/dist/core/compaction/branch-summarization.js.map +1 -1
  51. package/dist/core/compaction/compaction.d.ts.map +1 -1
  52. package/dist/core/compaction/compaction.js +23 -10
  53. package/dist/core/compaction/compaction.js.map +1 -1
  54. package/dist/core/compaction/context-compaction.d.ts +61 -0
  55. package/dist/core/compaction/context-compaction.d.ts.map +1 -0
  56. package/dist/core/compaction/context-compaction.js +602 -0
  57. package/dist/core/compaction/context-compaction.js.map +1 -0
  58. package/dist/core/compaction/index.d.ts +1 -0
  59. package/dist/core/compaction/index.d.ts.map +1 -1
  60. package/dist/core/compaction/index.js +1 -0
  61. package/dist/core/compaction/index.js.map +1 -1
  62. package/dist/core/index.d.ts +1 -1
  63. package/dist/core/index.d.ts.map +1 -1
  64. package/dist/core/index.js.map +1 -1
  65. package/dist/core/session-manager.d.ts +41 -1
  66. package/dist/core/session-manager.d.ts.map +1 -1
  67. package/dist/core/session-manager.js +146 -7
  68. package/dist/core/session-manager.js.map +1 -1
  69. package/dist/core/slash-commands.d.ts.map +1 -1
  70. package/dist/core/slash-commands.js +1 -0
  71. package/dist/core/slash-commands.js.map +1 -1
  72. package/dist/core/tools/ask-user-question/tool/format-answer.d.ts +5 -5
  73. package/dist/core/tools/ask-user-question/tool/format-answer.d.ts.map +1 -1
  74. package/dist/core/tools/ask-user-question/tool/format-answer.js +5 -5
  75. package/dist/core/tools/ask-user-question/tool/format-answer.js.map +1 -1
  76. package/dist/core/tools/ask-user-question/tool/response-envelope.d.ts +16 -3
  77. package/dist/core/tools/ask-user-question/tool/response-envelope.d.ts.map +1 -1
  78. package/dist/core/tools/ask-user-question/tool/response-envelope.js +21 -3
  79. package/dist/core/tools/ask-user-question/tool/response-envelope.js.map +1 -1
  80. package/dist/index.d.ts +3 -3
  81. package/dist/index.d.ts.map +1 -1
  82. package/dist/index.js +2 -2
  83. package/dist/index.js.map +1 -1
  84. package/dist/modes/index.d.ts +1 -1
  85. package/dist/modes/index.d.ts.map +1 -1
  86. package/dist/modes/index.js.map +1 -1
  87. package/dist/modes/interactive/components/chat-session-host.d.ts.map +1 -1
  88. package/dist/modes/interactive/components/chat-session-host.js +17 -0
  89. package/dist/modes/interactive/components/chat-session-host.js.map +1 -1
  90. package/dist/modes/interactive/interactive-mode.d.ts +1 -0
  91. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  92. package/dist/modes/interactive/interactive-mode.js +74 -0
  93. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  94. package/dist/modes/rpc/rpc-client.d.ts +12 -7
  95. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  96. package/dist/modes/rpc/rpc-client.js +8 -1
  97. package/dist/modes/rpc/rpc-client.js.map +1 -1
  98. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  99. package/dist/modes/rpc/rpc-mode.js +4 -0
  100. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  101. package/dist/modes/rpc/rpc-types.d.ts +13 -2
  102. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  103. package/dist/modes/rpc/rpc-types.js.map +1 -1
  104. package/docs/compaction.md +42 -23
  105. package/docs/custom-provider.md +11 -9
  106. package/docs/extensions.md +35 -35
  107. package/docs/index.md +1 -8
  108. package/docs/json.md +14 -11
  109. package/docs/packages.md +2 -0
  110. package/docs/providers.md +4 -1
  111. package/docs/quickstart.md +5 -12
  112. package/docs/rpc.md +44 -8
  113. package/docs/sdk.md +1 -8
  114. package/docs/session-format.md +25 -12
  115. package/docs/sessions.md +2 -1
  116. package/docs/skills.md +1 -15
  117. package/docs/termux.md +9 -10
  118. package/docs/themes.md +2 -2
  119. package/docs/tmux.md +3 -3
  120. package/docs/tui.md +19 -32
  121. package/docs/usage.md +2 -0
  122. package/docs/workflows.md +44 -2
  123. package/package.json +4 -12
  124. package/dist/builtin/subagents/skills/browser-use/SKILL.md +0 -234
  125. package/dist/builtin/subagents/skills/browser-use/references/cdp-python.md +0 -76
  126. package/dist/builtin/subagents/skills/browser-use/references/multi-session.md +0 -92
  127. package/node_modules/@earendil-works/pi-tui/README.md +0 -779
  128. package/node_modules/@earendil-works/pi-tui/dist/autocomplete.d.ts +0 -54
  129. package/node_modules/@earendil-works/pi-tui/dist/autocomplete.d.ts.map +0 -1
  130. package/node_modules/@earendil-works/pi-tui/dist/autocomplete.js +0 -632
  131. package/node_modules/@earendil-works/pi-tui/dist/autocomplete.js.map +0 -1
  132. package/node_modules/@earendil-works/pi-tui/dist/components/box.d.ts +0 -22
  133. package/node_modules/@earendil-works/pi-tui/dist/components/box.d.ts.map +0 -1
  134. package/node_modules/@earendil-works/pi-tui/dist/components/box.js +0 -104
  135. package/node_modules/@earendil-works/pi-tui/dist/components/box.js.map +0 -1
  136. package/node_modules/@earendil-works/pi-tui/dist/components/cancellable-loader.d.ts +0 -22
  137. package/node_modules/@earendil-works/pi-tui/dist/components/cancellable-loader.d.ts.map +0 -1
  138. package/node_modules/@earendil-works/pi-tui/dist/components/cancellable-loader.js +0 -35
  139. package/node_modules/@earendil-works/pi-tui/dist/components/cancellable-loader.js.map +0 -1
  140. package/node_modules/@earendil-works/pi-tui/dist/components/editor.d.ts +0 -249
  141. package/node_modules/@earendil-works/pi-tui/dist/components/editor.d.ts.map +0 -1
  142. package/node_modules/@earendil-works/pi-tui/dist/components/editor.js +0 -1857
  143. package/node_modules/@earendil-works/pi-tui/dist/components/editor.js.map +0 -1
  144. package/node_modules/@earendil-works/pi-tui/dist/components/image.d.ts +0 -28
  145. package/node_modules/@earendil-works/pi-tui/dist/components/image.d.ts.map +0 -1
  146. package/node_modules/@earendil-works/pi-tui/dist/components/image.js +0 -89
  147. package/node_modules/@earendil-works/pi-tui/dist/components/image.js.map +0 -1
  148. package/node_modules/@earendil-works/pi-tui/dist/components/input.d.ts +0 -37
  149. package/node_modules/@earendil-works/pi-tui/dist/components/input.d.ts.map +0 -1
  150. package/node_modules/@earendil-works/pi-tui/dist/components/input.js +0 -378
  151. package/node_modules/@earendil-works/pi-tui/dist/components/input.js.map +0 -1
  152. package/node_modules/@earendil-works/pi-tui/dist/components/loader.d.ts +0 -31
  153. package/node_modules/@earendil-works/pi-tui/dist/components/loader.d.ts.map +0 -1
  154. package/node_modules/@earendil-works/pi-tui/dist/components/loader.js +0 -69
  155. package/node_modules/@earendil-works/pi-tui/dist/components/loader.js.map +0 -1
  156. package/node_modules/@earendil-works/pi-tui/dist/components/markdown.d.ts +0 -96
  157. package/node_modules/@earendil-works/pi-tui/dist/components/markdown.d.ts.map +0 -1
  158. package/node_modules/@earendil-works/pi-tui/dist/components/markdown.js +0 -644
  159. package/node_modules/@earendil-works/pi-tui/dist/components/markdown.js.map +0 -1
  160. package/node_modules/@earendil-works/pi-tui/dist/components/select-list.d.ts +0 -50
  161. package/node_modules/@earendil-works/pi-tui/dist/components/select-list.d.ts.map +0 -1
  162. package/node_modules/@earendil-works/pi-tui/dist/components/select-list.js +0 -159
  163. package/node_modules/@earendil-works/pi-tui/dist/components/select-list.js.map +0 -1
  164. package/node_modules/@earendil-works/pi-tui/dist/components/settings-list.d.ts +0 -50
  165. package/node_modules/@earendil-works/pi-tui/dist/components/settings-list.d.ts.map +0 -1
  166. package/node_modules/@earendil-works/pi-tui/dist/components/settings-list.js +0 -185
  167. package/node_modules/@earendil-works/pi-tui/dist/components/settings-list.js.map +0 -1
  168. package/node_modules/@earendil-works/pi-tui/dist/components/spacer.d.ts +0 -12
  169. package/node_modules/@earendil-works/pi-tui/dist/components/spacer.d.ts.map +0 -1
  170. package/node_modules/@earendil-works/pi-tui/dist/components/spacer.js +0 -23
  171. package/node_modules/@earendil-works/pi-tui/dist/components/spacer.js.map +0 -1
  172. package/node_modules/@earendil-works/pi-tui/dist/components/text.d.ts +0 -19
  173. package/node_modules/@earendil-works/pi-tui/dist/components/text.d.ts.map +0 -1
  174. package/node_modules/@earendil-works/pi-tui/dist/components/text.js +0 -89
  175. package/node_modules/@earendil-works/pi-tui/dist/components/text.js.map +0 -1
  176. package/node_modules/@earendil-works/pi-tui/dist/components/truncated-text.d.ts +0 -13
  177. package/node_modules/@earendil-works/pi-tui/dist/components/truncated-text.d.ts.map +0 -1
  178. package/node_modules/@earendil-works/pi-tui/dist/components/truncated-text.js +0 -51
  179. package/node_modules/@earendil-works/pi-tui/dist/components/truncated-text.js.map +0 -1
  180. package/node_modules/@earendil-works/pi-tui/dist/editor-component.d.ts +0 -39
  181. package/node_modules/@earendil-works/pi-tui/dist/editor-component.d.ts.map +0 -1
  182. package/node_modules/@earendil-works/pi-tui/dist/editor-component.js +0 -2
  183. package/node_modules/@earendil-works/pi-tui/dist/editor-component.js.map +0 -1
  184. package/node_modules/@earendil-works/pi-tui/dist/fuzzy.d.ts +0 -16
  185. package/node_modules/@earendil-works/pi-tui/dist/fuzzy.d.ts.map +0 -1
  186. package/node_modules/@earendil-works/pi-tui/dist/fuzzy.js +0 -110
  187. package/node_modules/@earendil-works/pi-tui/dist/fuzzy.js.map +0 -1
  188. package/node_modules/@earendil-works/pi-tui/dist/index.d.ts +0 -23
  189. package/node_modules/@earendil-works/pi-tui/dist/index.d.ts.map +0 -1
  190. package/node_modules/@earendil-works/pi-tui/dist/index.js +0 -32
  191. package/node_modules/@earendil-works/pi-tui/dist/index.js.map +0 -1
  192. package/node_modules/@earendil-works/pi-tui/dist/keybindings.d.ts +0 -193
  193. package/node_modules/@earendil-works/pi-tui/dist/keybindings.d.ts.map +0 -1
  194. package/node_modules/@earendil-works/pi-tui/dist/keybindings.js +0 -174
  195. package/node_modules/@earendil-works/pi-tui/dist/keybindings.js.map +0 -1
  196. package/node_modules/@earendil-works/pi-tui/dist/keys.d.ts +0 -184
  197. package/node_modules/@earendil-works/pi-tui/dist/keys.d.ts.map +0 -1
  198. package/node_modules/@earendil-works/pi-tui/dist/keys.js +0 -1173
  199. package/node_modules/@earendil-works/pi-tui/dist/keys.js.map +0 -1
  200. package/node_modules/@earendil-works/pi-tui/dist/kill-ring.d.ts +0 -28
  201. package/node_modules/@earendil-works/pi-tui/dist/kill-ring.d.ts.map +0 -1
  202. package/node_modules/@earendil-works/pi-tui/dist/kill-ring.js +0 -44
  203. package/node_modules/@earendil-works/pi-tui/dist/kill-ring.js.map +0 -1
  204. package/node_modules/@earendil-works/pi-tui/dist/native-modifiers.d.ts +0 -3
  205. package/node_modules/@earendil-works/pi-tui/dist/native-modifiers.d.ts.map +0 -1
  206. package/node_modules/@earendil-works/pi-tui/dist/native-modifiers.js +0 -53
  207. package/node_modules/@earendil-works/pi-tui/dist/native-modifiers.js.map +0 -1
  208. package/node_modules/@earendil-works/pi-tui/dist/stdin-buffer.d.ts +0 -50
  209. package/node_modules/@earendil-works/pi-tui/dist/stdin-buffer.d.ts.map +0 -1
  210. package/node_modules/@earendil-works/pi-tui/dist/stdin-buffer.js +0 -361
  211. package/node_modules/@earendil-works/pi-tui/dist/stdin-buffer.js.map +0 -1
  212. package/node_modules/@earendil-works/pi-tui/dist/terminal-image.d.ts +0 -90
  213. package/node_modules/@earendil-works/pi-tui/dist/terminal-image.d.ts.map +0 -1
  214. package/node_modules/@earendil-works/pi-tui/dist/terminal-image.js +0 -366
  215. package/node_modules/@earendil-works/pi-tui/dist/terminal-image.js.map +0 -1
  216. package/node_modules/@earendil-works/pi-tui/dist/terminal.d.ts +0 -113
  217. package/node_modules/@earendil-works/pi-tui/dist/terminal.d.ts.map +0 -1
  218. package/node_modules/@earendil-works/pi-tui/dist/terminal.js +0 -472
  219. package/node_modules/@earendil-works/pi-tui/dist/terminal.js.map +0 -1
  220. package/node_modules/@earendil-works/pi-tui/dist/tui.d.ts +0 -227
  221. package/node_modules/@earendil-works/pi-tui/dist/tui.d.ts.map +0 -1
  222. package/node_modules/@earendil-works/pi-tui/dist/tui.js +0 -1106
  223. package/node_modules/@earendil-works/pi-tui/dist/tui.js.map +0 -1
  224. package/node_modules/@earendil-works/pi-tui/dist/undo-stack.d.ts +0 -17
  225. package/node_modules/@earendil-works/pi-tui/dist/undo-stack.d.ts.map +0 -1
  226. package/node_modules/@earendil-works/pi-tui/dist/undo-stack.js +0 -25
  227. package/node_modules/@earendil-works/pi-tui/dist/undo-stack.js.map +0 -1
  228. package/node_modules/@earendil-works/pi-tui/dist/utils.d.ts +0 -84
  229. package/node_modules/@earendil-works/pi-tui/dist/utils.d.ts.map +0 -1
  230. package/node_modules/@earendil-works/pi-tui/dist/utils.js +0 -1029
  231. package/node_modules/@earendil-works/pi-tui/dist/utils.js.map +0 -1
  232. package/node_modules/@earendil-works/pi-tui/dist/word-navigation.d.ts +0 -25
  233. package/node_modules/@earendil-works/pi-tui/dist/word-navigation.d.ts.map +0 -1
  234. package/node_modules/@earendil-works/pi-tui/dist/word-navigation.js +0 -96
  235. package/node_modules/@earendil-works/pi-tui/dist/word-navigation.js.map +0 -1
  236. package/node_modules/@earendil-works/pi-tui/native/darwin/prebuilds/darwin-arm64/darwin-modifiers.node +0 -0
  237. package/node_modules/@earendil-works/pi-tui/native/darwin/prebuilds/darwin-x64/darwin-modifiers.node +0 -0
  238. package/node_modules/@earendil-works/pi-tui/native/win32/prebuilds/win32-arm64/win32-console-mode.node +0 -0
  239. package/node_modules/@earendil-works/pi-tui/native/win32/prebuilds/win32-x64/win32-console-mode.node +0 -0
  240. package/node_modules/@earendil-works/pi-tui/package.json +0 -47
  241. package/node_modules/get-east-asian-width/index.d.ts +0 -60
  242. package/node_modules/get-east-asian-width/index.js +0 -30
  243. package/node_modules/get-east-asian-width/license +0 -9
  244. package/node_modules/get-east-asian-width/lookup-data.js +0 -21
  245. package/node_modules/get-east-asian-width/lookup.js +0 -138
  246. package/node_modules/get-east-asian-width/package.json +0 -71
  247. package/node_modules/get-east-asian-width/readme.md +0 -65
  248. package/node_modules/get-east-asian-width/utilities.js +0 -24
  249. package/node_modules/marked/LICENSE.md +0 -44
  250. package/node_modules/marked/README.md +0 -106
  251. package/node_modules/marked/bin/main.js +0 -282
  252. package/node_modules/marked/bin/marked.js +0 -15
  253. package/node_modules/marked/lib/marked.cjs +0 -2211
  254. package/node_modules/marked/lib/marked.cjs.map +0 -7
  255. package/node_modules/marked/lib/marked.d.cts +0 -728
  256. package/node_modules/marked/lib/marked.d.ts +0 -728
  257. package/node_modules/marked/lib/marked.esm.js +0 -2189
  258. package/node_modules/marked/lib/marked.esm.js.map +0 -7
  259. package/node_modules/marked/lib/marked.umd.js +0 -2213
  260. package/node_modules/marked/lib/marked.umd.js.map +0 -7
  261. package/node_modules/marked/man/marked.1 +0 -111
  262. package/node_modules/marked/man/marked.1.md +0 -92
  263. package/node_modules/marked/marked.min.js +0 -69
  264. package/node_modules/marked/package.json +0 -111
@@ -1,644 +0,0 @@
1
- import { Marked, Tokenizer } from "marked";
2
- import { getCapabilities, hyperlink, isImageLine } from "../terminal-image.js";
3
- import { applyBackgroundToLine, visibleWidth, wrapTextWithAnsi } from "../utils.js";
4
- const STRICT_STRIKETHROUGH_REGEX = /^(~~)(?=[^\s~])((?:\\.|[^\\])*?(?:\\.|[^\s~\\]))\1(?=[^~]|$)/;
5
- class StrictStrikethroughTokenizer extends Tokenizer {
6
- del(src) {
7
- const match = STRICT_STRIKETHROUGH_REGEX.exec(src);
8
- if (!match) {
9
- return undefined;
10
- }
11
- const text = match[2];
12
- return {
13
- type: "del",
14
- raw: match[0],
15
- text,
16
- tokens: this.lexer.inlineTokens(text),
17
- };
18
- }
19
- }
20
- const markdownParser = new Marked();
21
- markdownParser.setOptions({
22
- tokenizer: new StrictStrikethroughTokenizer(),
23
- });
24
- export class Markdown {
25
- text;
26
- paddingX; // Left/right padding
27
- paddingY; // Top/bottom padding
28
- defaultTextStyle;
29
- theme;
30
- options;
31
- defaultStylePrefix;
32
- // Cache for rendered output
33
- cachedText;
34
- cachedWidth;
35
- cachedLines;
36
- constructor(text, paddingX, paddingY, theme, defaultTextStyle, options) {
37
- this.text = text;
38
- this.paddingX = paddingX;
39
- this.paddingY = paddingY;
40
- this.theme = theme;
41
- this.defaultTextStyle = defaultTextStyle;
42
- this.options = options ? { ...options } : {};
43
- }
44
- setText(text) {
45
- this.text = text;
46
- this.invalidate();
47
- }
48
- invalidate() {
49
- this.cachedText = undefined;
50
- this.cachedWidth = undefined;
51
- this.cachedLines = undefined;
52
- }
53
- render(width) {
54
- // Check cache
55
- if (this.cachedLines && this.cachedText === this.text && this.cachedWidth === width) {
56
- return this.cachedLines;
57
- }
58
- // Calculate available width for content (subtract horizontal padding)
59
- const contentWidth = Math.max(1, width - this.paddingX * 2);
60
- // Don't render anything if there's no actual text
61
- if (!this.text || this.text.trim() === "") {
62
- const result = [];
63
- // Update cache
64
- this.cachedText = this.text;
65
- this.cachedWidth = width;
66
- this.cachedLines = result;
67
- return result;
68
- }
69
- // Replace tabs with 3 spaces for consistent rendering
70
- const normalizedText = this.text.replace(/\t/g, " ");
71
- // Parse markdown to HTML-like tokens
72
- const tokens = markdownParser.lexer(normalizedText);
73
- // Convert tokens to styled terminal output
74
- const renderedLines = [];
75
- for (let i = 0; i < tokens.length; i++) {
76
- const token = tokens[i];
77
- const nextToken = tokens[i + 1];
78
- const tokenLines = this.renderToken(token, contentWidth, nextToken?.type);
79
- for (const tokenLine of tokenLines) {
80
- renderedLines.push(tokenLine);
81
- }
82
- }
83
- // Wrap lines (NO padding, NO background yet)
84
- const wrappedLines = [];
85
- for (const line of renderedLines) {
86
- if (isImageLine(line)) {
87
- wrappedLines.push(line);
88
- }
89
- else {
90
- for (const wrappedLine of wrapTextWithAnsi(line, contentWidth)) {
91
- wrappedLines.push(wrappedLine);
92
- }
93
- }
94
- }
95
- // Add margins and background to each wrapped line
96
- const leftMargin = " ".repeat(this.paddingX);
97
- const rightMargin = " ".repeat(this.paddingX);
98
- const bgFn = this.defaultTextStyle?.bgColor;
99
- const contentLines = [];
100
- for (const line of wrappedLines) {
101
- if (isImageLine(line)) {
102
- contentLines.push(line);
103
- continue;
104
- }
105
- const lineWithMargins = leftMargin + line + rightMargin;
106
- if (bgFn) {
107
- contentLines.push(applyBackgroundToLine(lineWithMargins, width, bgFn));
108
- }
109
- else {
110
- // No background - just pad to width
111
- const visibleLen = visibleWidth(lineWithMargins);
112
- const paddingNeeded = Math.max(0, width - visibleLen);
113
- contentLines.push(lineWithMargins + " ".repeat(paddingNeeded));
114
- }
115
- }
116
- // Add top/bottom padding (empty lines)
117
- const emptyLine = " ".repeat(width);
118
- const emptyLines = [];
119
- for (let i = 0; i < this.paddingY; i++) {
120
- const line = bgFn ? applyBackgroundToLine(emptyLine, width, bgFn) : emptyLine;
121
- emptyLines.push(line);
122
- }
123
- // Combine top padding, content, and bottom padding
124
- const result = emptyLines.concat(contentLines, emptyLines);
125
- // Update cache
126
- this.cachedText = this.text;
127
- this.cachedWidth = width;
128
- this.cachedLines = result;
129
- return result.length > 0 ? result : [""];
130
- }
131
- /**
132
- * Apply default text style to a string.
133
- * This is the base styling applied to all text content.
134
- * NOTE: Background color is NOT applied here - it's applied at the padding stage
135
- * to ensure it extends to the full line width.
136
- */
137
- applyDefaultStyle(text) {
138
- if (!this.defaultTextStyle) {
139
- return text;
140
- }
141
- let styled = text;
142
- // Apply foreground color (NOT background - that's applied at padding stage)
143
- if (this.defaultTextStyle.color) {
144
- styled = this.defaultTextStyle.color(styled);
145
- }
146
- // Apply text decorations using this.theme
147
- if (this.defaultTextStyle.bold) {
148
- styled = this.theme.bold(styled);
149
- }
150
- if (this.defaultTextStyle.italic) {
151
- styled = this.theme.italic(styled);
152
- }
153
- if (this.defaultTextStyle.strikethrough) {
154
- styled = this.theme.strikethrough(styled);
155
- }
156
- if (this.defaultTextStyle.underline) {
157
- styled = this.theme.underline(styled);
158
- }
159
- return styled;
160
- }
161
- getDefaultStylePrefix() {
162
- if (!this.defaultTextStyle) {
163
- return "";
164
- }
165
- if (this.defaultStylePrefix !== undefined) {
166
- return this.defaultStylePrefix;
167
- }
168
- const sentinel = "\u0000";
169
- let styled = sentinel;
170
- if (this.defaultTextStyle.color) {
171
- styled = this.defaultTextStyle.color(styled);
172
- }
173
- if (this.defaultTextStyle.bold) {
174
- styled = this.theme.bold(styled);
175
- }
176
- if (this.defaultTextStyle.italic) {
177
- styled = this.theme.italic(styled);
178
- }
179
- if (this.defaultTextStyle.strikethrough) {
180
- styled = this.theme.strikethrough(styled);
181
- }
182
- if (this.defaultTextStyle.underline) {
183
- styled = this.theme.underline(styled);
184
- }
185
- const sentinelIndex = styled.indexOf(sentinel);
186
- this.defaultStylePrefix = sentinelIndex >= 0 ? styled.slice(0, sentinelIndex) : "";
187
- return this.defaultStylePrefix;
188
- }
189
- getStylePrefix(styleFn) {
190
- const sentinel = "\u0000";
191
- const styled = styleFn(sentinel);
192
- const sentinelIndex = styled.indexOf(sentinel);
193
- return sentinelIndex >= 0 ? styled.slice(0, sentinelIndex) : "";
194
- }
195
- getDefaultInlineStyleContext() {
196
- return {
197
- applyText: (text) => this.applyDefaultStyle(text),
198
- stylePrefix: this.getDefaultStylePrefix(),
199
- };
200
- }
201
- renderToken(token, width, nextTokenType, styleContext) {
202
- const lines = [];
203
- switch (token.type) {
204
- case "heading": {
205
- const headingLevel = token.depth;
206
- const headingPrefix = `${"#".repeat(headingLevel)} `;
207
- // Build a heading-specific style context so inline tokens (codespan, bold, etc.)
208
- // restore heading styling after their own ANSI resets instead of falling back to
209
- // the default text style.
210
- let headingStyleFn;
211
- if (headingLevel === 1) {
212
- headingStyleFn = (text) => this.theme.heading(this.theme.bold(this.theme.underline(text)));
213
- }
214
- else {
215
- headingStyleFn = (text) => this.theme.heading(this.theme.bold(text));
216
- }
217
- const headingStyleContext = {
218
- applyText: headingStyleFn,
219
- stylePrefix: this.getStylePrefix(headingStyleFn),
220
- };
221
- const headingText = this.renderInlineTokens(token.tokens || [], headingStyleContext);
222
- const styledHeading = headingLevel >= 3 ? headingStyleFn(headingPrefix) + headingText : headingText;
223
- lines.push(styledHeading);
224
- if (nextTokenType && nextTokenType !== "space") {
225
- lines.push(""); // Add spacing after headings (unless space token follows)
226
- }
227
- break;
228
- }
229
- case "paragraph": {
230
- const paragraphText = this.renderInlineTokens(token.tokens || [], styleContext);
231
- lines.push(paragraphText);
232
- // Don't add spacing if next token is space or list
233
- if (nextTokenType && nextTokenType !== "list" && nextTokenType !== "space") {
234
- lines.push("");
235
- }
236
- break;
237
- }
238
- case "text":
239
- lines.push(this.renderInlineTokens([token], styleContext));
240
- break;
241
- case "code": {
242
- const indent = this.theme.codeBlockIndent ?? " ";
243
- lines.push(this.theme.codeBlockBorder(`\`\`\`${token.lang || ""}`));
244
- if (this.theme.highlightCode) {
245
- const highlightedLines = this.theme.highlightCode(token.text, token.lang);
246
- for (const hlLine of highlightedLines) {
247
- lines.push(`${indent}${hlLine}`);
248
- }
249
- }
250
- else {
251
- // Split code by newlines and style each line
252
- const codeLines = token.text.split("\n");
253
- for (const codeLine of codeLines) {
254
- lines.push(`${indent}${this.theme.codeBlock(codeLine)}`);
255
- }
256
- }
257
- lines.push(this.theme.codeBlockBorder("```"));
258
- if (nextTokenType && nextTokenType !== "space") {
259
- lines.push(""); // Add spacing after code blocks (unless space token follows)
260
- }
261
- break;
262
- }
263
- case "list": {
264
- const listLines = this.renderList(token, 0, width, styleContext);
265
- lines.push(...listLines);
266
- // Don't add spacing after lists if a space token follows
267
- // (the space token will handle it)
268
- break;
269
- }
270
- case "table": {
271
- const tableLines = this.renderTable(token, width, nextTokenType, styleContext);
272
- lines.push(...tableLines);
273
- break;
274
- }
275
- case "blockquote": {
276
- const quoteStyle = (text) => this.theme.quote(this.theme.italic(text));
277
- const quoteStylePrefix = this.getStylePrefix(quoteStyle);
278
- const applyQuoteStyle = (line) => {
279
- if (!quoteStylePrefix) {
280
- return quoteStyle(line);
281
- }
282
- const lineWithReappliedStyle = line.replace(/\x1b\[0m/g, `\x1b[0m${quoteStylePrefix}`);
283
- return quoteStyle(lineWithReappliedStyle);
284
- };
285
- // Calculate available width for quote content (subtract border "│ " = 2 chars)
286
- const quoteContentWidth = Math.max(1, width - 2);
287
- // Blockquotes contain block-level tokens (paragraph, list, code, etc.), so render
288
- // children with renderToken() instead of renderInlineTokens().
289
- // Default message style should not apply inside blockquotes.
290
- const quoteInlineStyleContext = {
291
- applyText: (text) => text,
292
- stylePrefix: quoteStylePrefix,
293
- };
294
- const quoteTokens = token.tokens || [];
295
- const renderedQuoteLines = [];
296
- for (let i = 0; i < quoteTokens.length; i++) {
297
- const quoteToken = quoteTokens[i];
298
- const nextQuoteToken = quoteTokens[i + 1];
299
- renderedQuoteLines.push(...this.renderToken(quoteToken, quoteContentWidth, nextQuoteToken?.type, quoteInlineStyleContext));
300
- }
301
- // Avoid rendering an extra empty quote line before the outer blockquote spacing.
302
- while (renderedQuoteLines.length > 0 && renderedQuoteLines[renderedQuoteLines.length - 1] === "") {
303
- renderedQuoteLines.pop();
304
- }
305
- for (const quoteLine of renderedQuoteLines) {
306
- const styledLine = applyQuoteStyle(quoteLine);
307
- const wrappedLines = wrapTextWithAnsi(styledLine, quoteContentWidth);
308
- for (const wrappedLine of wrappedLines) {
309
- lines.push(this.theme.quoteBorder("│ ") + wrappedLine);
310
- }
311
- }
312
- if (nextTokenType && nextTokenType !== "space") {
313
- lines.push(""); // Add spacing after blockquotes (unless space token follows)
314
- }
315
- break;
316
- }
317
- case "hr":
318
- lines.push(this.theme.hr("─".repeat(Math.min(width, 80))));
319
- if (nextTokenType && nextTokenType !== "space") {
320
- lines.push(""); // Add spacing after horizontal rules (unless space token follows)
321
- }
322
- break;
323
- case "html":
324
- // Render HTML as plain text (escaped for terminal)
325
- if ("raw" in token && typeof token.raw === "string") {
326
- lines.push(this.applyDefaultStyle(token.raw.trim()));
327
- }
328
- break;
329
- case "space":
330
- // Space tokens represent blank lines in markdown
331
- lines.push("");
332
- break;
333
- default:
334
- // Handle any other token types as plain text
335
- if ("text" in token && typeof token.text === "string") {
336
- lines.push(token.text);
337
- }
338
- }
339
- return lines;
340
- }
341
- renderInlineTokens(tokens, styleContext) {
342
- let result = "";
343
- const resolvedStyleContext = styleContext ?? this.getDefaultInlineStyleContext();
344
- const { applyText, stylePrefix } = resolvedStyleContext;
345
- const applyTextWithNewlines = (text) => {
346
- const segments = text.split("\n");
347
- return segments.map((segment) => applyText(segment)).join("\n");
348
- };
349
- for (const token of tokens) {
350
- switch (token.type) {
351
- case "text":
352
- // Text tokens in list items can have nested tokens for inline formatting
353
- if (token.tokens && token.tokens.length > 0) {
354
- result += this.renderInlineTokens(token.tokens, resolvedStyleContext);
355
- }
356
- else {
357
- result += applyTextWithNewlines(token.text);
358
- }
359
- break;
360
- case "paragraph":
361
- // Paragraph tokens contain nested inline tokens
362
- result += this.renderInlineTokens(token.tokens || [], resolvedStyleContext);
363
- break;
364
- case "strong": {
365
- const boldContent = this.renderInlineTokens(token.tokens || [], resolvedStyleContext);
366
- result += this.theme.bold(boldContent) + stylePrefix;
367
- break;
368
- }
369
- case "em": {
370
- const italicContent = this.renderInlineTokens(token.tokens || [], resolvedStyleContext);
371
- result += this.theme.italic(italicContent) + stylePrefix;
372
- break;
373
- }
374
- case "codespan":
375
- result += this.theme.code(token.text) + stylePrefix;
376
- break;
377
- case "link": {
378
- const linkText = this.renderInlineTokens(token.tokens || [], resolvedStyleContext);
379
- const styledLink = this.theme.link(this.theme.underline(linkText));
380
- if (getCapabilities().hyperlinks) {
381
- // OSC 8: render as a clickable hyperlink. The URL is not printed inline,
382
- // so we always show only the link text regardless of whether it matches href.
383
- result += hyperlink(styledLink, token.href) + stylePrefix;
384
- }
385
- else {
386
- // Fallback: print URL in parentheses when text differs from href.
387
- // Compare raw token.text (not styled) against href for the equality check.
388
- // For mailto: links strip the prefix (autolinked emails use text="foo@bar.com"
389
- // but href="mailto:foo@bar.com").
390
- const hrefForComparison = token.href.startsWith("mailto:") ? token.href.slice(7) : token.href;
391
- if (token.text === token.href || token.text === hrefForComparison) {
392
- result += styledLink + stylePrefix;
393
- }
394
- else {
395
- result += styledLink + this.theme.linkUrl(` (${token.href})`) + stylePrefix;
396
- }
397
- }
398
- break;
399
- }
400
- case "br":
401
- result += "\n";
402
- break;
403
- case "del": {
404
- const delContent = this.renderInlineTokens(token.tokens || [], resolvedStyleContext);
405
- result += this.theme.strikethrough(delContent) + stylePrefix;
406
- break;
407
- }
408
- case "html":
409
- // Render inline HTML as plain text
410
- if ("raw" in token && typeof token.raw === "string") {
411
- result += applyTextWithNewlines(token.raw);
412
- }
413
- break;
414
- default:
415
- // Handle any other inline token types as plain text
416
- if ("text" in token && typeof token.text === "string") {
417
- result += applyTextWithNewlines(token.text);
418
- }
419
- }
420
- }
421
- while (stylePrefix && result.endsWith(stylePrefix)) {
422
- result = result.slice(0, -stylePrefix.length);
423
- }
424
- return result;
425
- }
426
- getOrderedListMarker(item) {
427
- const match = /^(?: {0,3})(\d{1,9}[.)])[ \t]+/.exec(item.raw);
428
- return match ? `${match[1]} ` : undefined;
429
- }
430
- /**
431
- * Render a list with proper nesting support
432
- */
433
- renderList(token, depth, width, styleContext) {
434
- const lines = [];
435
- const indent = " ".repeat(depth);
436
- // Use the list's start property (defaults to 1 for ordered lists)
437
- const startNumber = typeof token.start === "number" ? token.start : 1;
438
- for (let i = 0; i < token.items.length; i++) {
439
- const item = token.items[i];
440
- const bullet = token.ordered
441
- ? this.options.preserveOrderedListMarkers
442
- ? (this.getOrderedListMarker(item) ?? `${startNumber + i}. `)
443
- : `${startNumber + i}. `
444
- : "- ";
445
- const taskMarker = item.task ? `[${item.checked ? "x" : " "}] ` : "";
446
- const marker = bullet + taskMarker;
447
- const firstPrefix = indent + this.theme.listBullet(marker);
448
- const continuationPrefix = indent + " ".repeat(visibleWidth(marker));
449
- const itemWidth = Math.max(1, width - visibleWidth(firstPrefix));
450
- let renderedAnyLine = false;
451
- for (const itemToken of item.tokens) {
452
- if (itemToken.type === "list") {
453
- lines.push(...this.renderList(itemToken, depth + 1, width, styleContext));
454
- renderedAnyLine = true;
455
- continue;
456
- }
457
- const itemLines = this.renderToken(itemToken, itemWidth, undefined, styleContext);
458
- for (const line of itemLines) {
459
- for (const wrappedLine of wrapTextWithAnsi(line, itemWidth)) {
460
- const linePrefix = renderedAnyLine ? continuationPrefix : firstPrefix;
461
- lines.push(linePrefix + wrappedLine);
462
- renderedAnyLine = true;
463
- }
464
- }
465
- }
466
- if (!renderedAnyLine) {
467
- lines.push(firstPrefix);
468
- }
469
- }
470
- return lines;
471
- }
472
- /**
473
- * Get the visible width of the longest word in a string.
474
- */
475
- getLongestWordWidth(text, maxWidth) {
476
- const words = text.split(/\s+/).filter((word) => word.length > 0);
477
- let longest = 0;
478
- for (const word of words) {
479
- longest = Math.max(longest, visibleWidth(word));
480
- }
481
- if (maxWidth === undefined) {
482
- return longest;
483
- }
484
- return Math.min(longest, maxWidth);
485
- }
486
- /**
487
- * Wrap a table cell to fit into a column.
488
- *
489
- * Delegates to wrapTextWithAnsi() so ANSI codes + long tokens are handled
490
- * consistently with the rest of the renderer.
491
- */
492
- wrapCellText(text, maxWidth) {
493
- return wrapTextWithAnsi(text, Math.max(1, maxWidth));
494
- }
495
- /**
496
- * Render a table with width-aware cell wrapping.
497
- * Cells that don't fit are wrapped to multiple lines.
498
- */
499
- renderTable(token, availableWidth, nextTokenType, styleContext) {
500
- const lines = [];
501
- const numCols = token.header.length;
502
- if (numCols === 0) {
503
- return lines;
504
- }
505
- // Calculate border overhead: "│ " + (n-1) * " │ " + " │"
506
- // = 2 + (n-1) * 3 + 2 = 3n + 1
507
- const borderOverhead = 3 * numCols + 1;
508
- const availableForCells = availableWidth - borderOverhead;
509
- if (availableForCells < numCols) {
510
- // Too narrow to render a stable table. Fall back to raw markdown.
511
- const fallbackLines = token.raw ? wrapTextWithAnsi(token.raw, availableWidth) : [];
512
- if (nextTokenType && nextTokenType !== "space") {
513
- fallbackLines.push("");
514
- }
515
- return fallbackLines;
516
- }
517
- const maxUnbrokenWordWidth = 30;
518
- // Calculate natural column widths (what each column needs without constraints)
519
- const naturalWidths = [];
520
- const minWordWidths = [];
521
- for (let i = 0; i < numCols; i++) {
522
- const headerText = this.renderInlineTokens(token.header[i].tokens || [], styleContext);
523
- naturalWidths[i] = visibleWidth(headerText);
524
- minWordWidths[i] = Math.max(1, this.getLongestWordWidth(headerText, maxUnbrokenWordWidth));
525
- }
526
- for (const row of token.rows) {
527
- for (let i = 0; i < row.length; i++) {
528
- const cellText = this.renderInlineTokens(row[i].tokens || [], styleContext);
529
- naturalWidths[i] = Math.max(naturalWidths[i] || 0, visibleWidth(cellText));
530
- minWordWidths[i] = Math.max(minWordWidths[i] || 1, this.getLongestWordWidth(cellText, maxUnbrokenWordWidth));
531
- }
532
- }
533
- let minColumnWidths = minWordWidths;
534
- let minCellsWidth = minColumnWidths.reduce((a, b) => a + b, 0);
535
- if (minCellsWidth > availableForCells) {
536
- minColumnWidths = new Array(numCols).fill(1);
537
- const remaining = availableForCells - numCols;
538
- if (remaining > 0) {
539
- const totalWeight = minWordWidths.reduce((total, width) => total + Math.max(0, width - 1), 0);
540
- const growth = minWordWidths.map((width) => {
541
- const weight = Math.max(0, width - 1);
542
- return totalWeight > 0 ? Math.floor((weight / totalWeight) * remaining) : 0;
543
- });
544
- for (let i = 0; i < numCols; i++) {
545
- minColumnWidths[i] += growth[i] ?? 0;
546
- }
547
- const allocated = growth.reduce((total, width) => total + width, 0);
548
- let leftover = remaining - allocated;
549
- for (let i = 0; leftover > 0 && i < numCols; i++) {
550
- minColumnWidths[i]++;
551
- leftover--;
552
- }
553
- }
554
- minCellsWidth = minColumnWidths.reduce((a, b) => a + b, 0);
555
- }
556
- // Calculate column widths that fit within available width
557
- const totalNaturalWidth = naturalWidths.reduce((a, b) => a + b, 0) + borderOverhead;
558
- let columnWidths;
559
- if (totalNaturalWidth <= availableWidth) {
560
- // Everything fits naturally
561
- columnWidths = naturalWidths.map((width, index) => Math.max(width, minColumnWidths[index]));
562
- }
563
- else {
564
- // Need to shrink columns to fit
565
- const totalGrowPotential = naturalWidths.reduce((total, width, index) => {
566
- return total + Math.max(0, width - minColumnWidths[index]);
567
- }, 0);
568
- const extraWidth = Math.max(0, availableForCells - minCellsWidth);
569
- columnWidths = minColumnWidths.map((minWidth, index) => {
570
- const naturalWidth = naturalWidths[index];
571
- const minWidthDelta = Math.max(0, naturalWidth - minWidth);
572
- let grow = 0;
573
- if (totalGrowPotential > 0) {
574
- grow = Math.floor((minWidthDelta / totalGrowPotential) * extraWidth);
575
- }
576
- return minWidth + grow;
577
- });
578
- // Adjust for rounding errors - distribute remaining space
579
- const allocated = columnWidths.reduce((a, b) => a + b, 0);
580
- let remaining = availableForCells - allocated;
581
- while (remaining > 0) {
582
- let grew = false;
583
- for (let i = 0; i < numCols && remaining > 0; i++) {
584
- if (columnWidths[i] < naturalWidths[i]) {
585
- columnWidths[i]++;
586
- remaining--;
587
- grew = true;
588
- }
589
- }
590
- if (!grew) {
591
- break;
592
- }
593
- }
594
- }
595
- // Render top border
596
- const topBorderCells = columnWidths.map((w) => "─".repeat(w));
597
- lines.push(`┌─${topBorderCells.join("─┬─")}─┐`);
598
- // Render header with wrapping
599
- const headerCellLines = token.header.map((cell, i) => {
600
- const text = this.renderInlineTokens(cell.tokens || [], styleContext);
601
- return this.wrapCellText(text, columnWidths[i]);
602
- });
603
- const headerLineCount = Math.max(...headerCellLines.map((c) => c.length));
604
- for (let lineIdx = 0; lineIdx < headerLineCount; lineIdx++) {
605
- const rowParts = headerCellLines.map((cellLines, colIdx) => {
606
- const text = cellLines[lineIdx] || "";
607
- const padded = text + " ".repeat(Math.max(0, columnWidths[colIdx] - visibleWidth(text)));
608
- return this.theme.bold(padded);
609
- });
610
- lines.push(`│ ${rowParts.join(" │ ")} │`);
611
- }
612
- // Render separator
613
- const separatorCells = columnWidths.map((w) => "─".repeat(w));
614
- const separatorLine = `├─${separatorCells.join("─┼─")}─┤`;
615
- lines.push(separatorLine);
616
- // Render rows with wrapping
617
- for (let rowIndex = 0; rowIndex < token.rows.length; rowIndex++) {
618
- const row = token.rows[rowIndex];
619
- const rowCellLines = row.map((cell, i) => {
620
- const text = this.renderInlineTokens(cell.tokens || [], styleContext);
621
- return this.wrapCellText(text, columnWidths[i]);
622
- });
623
- const rowLineCount = Math.max(...rowCellLines.map((c) => c.length));
624
- for (let lineIdx = 0; lineIdx < rowLineCount; lineIdx++) {
625
- const rowParts = rowCellLines.map((cellLines, colIdx) => {
626
- const text = cellLines[lineIdx] || "";
627
- return text + " ".repeat(Math.max(0, columnWidths[colIdx] - visibleWidth(text)));
628
- });
629
- lines.push(`│ ${rowParts.join(" │ ")} │`);
630
- }
631
- if (rowIndex < token.rows.length - 1) {
632
- lines.push(separatorLine);
633
- }
634
- }
635
- // Render bottom border
636
- const bottomBorderCells = columnWidths.map((w) => "─".repeat(w));
637
- lines.push(`└─${bottomBorderCells.join("─┴─")}─┘`);
638
- if (nextTokenType && nextTokenType !== "space") {
639
- lines.push(""); // Add spacing after table
640
- }
641
- return lines;
642
- }
643
- }
644
- //# sourceMappingURL=markdown.js.map