indusagi 0.12.18 → 0.12.20

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 (518) hide show
  1. package/README.md +17 -37
  2. package/dist/agent/agent-loop.d.ts +3 -9
  3. package/dist/agent/agent-loop.d.ts.map +1 -1
  4. package/dist/agent/agent-loop.js +19 -58
  5. package/dist/agent/agent-loop.js.map +1 -1
  6. package/dist/agent/agent.d.ts +9 -10
  7. package/dist/agent/agent.d.ts.map +1 -1
  8. package/dist/agent/agent.js +182 -129
  9. package/dist/agent/agent.js.map +1 -1
  10. package/dist/agent/error-handler.d.ts.map +1 -1
  11. package/dist/agent/error-handler.js.map +1 -1
  12. package/dist/agent/event-bus.d.ts.map +1 -1
  13. package/dist/agent/event-bus.js +1 -3
  14. package/dist/agent/event-bus.js.map +1 -1
  15. package/dist/agent/index.d.ts.map +1 -1
  16. package/dist/agent/index.js +0 -6
  17. package/dist/agent/index.js.map +1 -1
  18. package/dist/agent/messages.d.ts +1 -1
  19. package/dist/agent/messages.d.ts.map +1 -1
  20. package/dist/agent/proxy.d.ts +1 -14
  21. package/dist/agent/proxy.d.ts.map +1 -1
  22. package/dist/agent/proxy.js +67 -148
  23. package/dist/agent/proxy.js.map +1 -1
  24. package/dist/agent/session-manager.d.ts +10 -10
  25. package/dist/agent/session-manager.d.ts.map +1 -1
  26. package/dist/agent/session-manager.js +20 -16
  27. package/dist/agent/session-manager.js.map +1 -1
  28. package/dist/agent/state-manager.d.ts +1 -1
  29. package/dist/agent/state-manager.d.ts.map +1 -1
  30. package/dist/agent/state-manager.js +1 -0
  31. package/dist/agent/state-manager.js.map +1 -1
  32. package/dist/agent/telemetry.d.ts.map +1 -1
  33. package/dist/agent/telemetry.js +1 -3
  34. package/dist/agent/telemetry.js.map +1 -1
  35. package/dist/agent/tools/bash.d.ts.map +1 -1
  36. package/dist/agent/tools/bash.js +143 -118
  37. package/dist/agent/tools/bash.js.map +1 -1
  38. package/dist/agent/tools/edit-diff.d.ts +1 -1
  39. package/dist/agent/tools/edit-diff.d.ts.map +1 -1
  40. package/dist/agent/tools/edit-diff.js +189 -175
  41. package/dist/agent/tools/edit-diff.js.map +1 -1
  42. package/dist/agent/tools/edit.d.ts.map +1 -1
  43. package/dist/agent/tools/edit.js +137 -121
  44. package/dist/agent/tools/edit.js.map +1 -1
  45. package/dist/agent/tools/find.d.ts.map +1 -1
  46. package/dist/agent/tools/find.js +100 -65
  47. package/dist/agent/tools/find.js.map +1 -1
  48. package/dist/agent/tools/grep.d.ts.map +1 -1
  49. package/dist/agent/tools/grep.js +126 -97
  50. package/dist/agent/tools/grep.js.map +1 -1
  51. package/dist/agent/tools/index.d.ts +53 -40
  52. package/dist/agent/tools/index.d.ts.map +1 -1
  53. package/dist/agent/tools/index.js +19 -12
  54. package/dist/agent/tools/index.js.map +1 -1
  55. package/dist/agent/tools/ls.d.ts +2 -1
  56. package/dist/agent/tools/ls.d.ts.map +1 -1
  57. package/dist/agent/tools/ls.js +145 -94
  58. package/dist/agent/tools/ls.js.map +1 -1
  59. package/dist/agent/tools/path-utils.d.ts.map +1 -1
  60. package/dist/agent/tools/path-utils.js +48 -29
  61. package/dist/agent/tools/path-utils.js.map +1 -1
  62. package/dist/agent/tools/process-controller.d.ts +15 -0
  63. package/dist/agent/tools/process-controller.d.ts.map +1 -0
  64. package/dist/agent/tools/process-controller.js +39 -0
  65. package/dist/agent/tools/process-controller.js.map +1 -0
  66. package/dist/agent/tools/process-manager.d.ts +60 -0
  67. package/dist/agent/tools/process-manager.d.ts.map +1 -0
  68. package/dist/agent/tools/process-manager.js +485 -0
  69. package/dist/agent/tools/process-manager.js.map +1 -0
  70. package/dist/agent/tools/process-types.d.ts +74 -0
  71. package/dist/agent/tools/process-types.d.ts.map +1 -0
  72. package/dist/agent/tools/process-types.js +7 -0
  73. package/dist/agent/tools/process-types.js.map +1 -0
  74. package/dist/agent/tools/process.d.ts +38 -0
  75. package/dist/agent/tools/process.d.ts.map +1 -0
  76. package/dist/agent/tools/process.js +360 -0
  77. package/dist/agent/tools/process.js.map +1 -0
  78. package/dist/agent/tools/read.d.ts.map +1 -1
  79. package/dist/agent/tools/read.js +157 -135
  80. package/dist/agent/tools/read.js.map +1 -1
  81. package/dist/agent/tools/registry.js +2 -4
  82. package/dist/agent/tools/registry.js.map +1 -1
  83. package/dist/agent/tools/teams/activity-tracker.d.ts +66 -0
  84. package/dist/agent/tools/teams/activity-tracker.d.ts.map +1 -0
  85. package/dist/agent/tools/teams/activity-tracker.js +480 -0
  86. package/dist/agent/tools/teams/activity-tracker.js.map +1 -0
  87. package/dist/agent/tools/teams/cleanup.d.ts +51 -0
  88. package/dist/agent/tools/teams/cleanup.d.ts.map +1 -0
  89. package/dist/agent/tools/teams/cleanup.js +219 -0
  90. package/dist/agent/tools/teams/cleanup.js.map +1 -0
  91. package/dist/agent/tools/teams/fs-lock.d.ts +12 -0
  92. package/dist/agent/tools/teams/fs-lock.d.ts.map +1 -0
  93. package/dist/agent/tools/teams/fs-lock.js +74 -0
  94. package/dist/agent/tools/teams/fs-lock.js.map +1 -0
  95. package/dist/agent/tools/teams/index.d.ts +12 -0
  96. package/dist/agent/tools/teams/index.d.ts.map +1 -0
  97. package/dist/agent/tools/teams/index.js +12 -0
  98. package/dist/agent/tools/teams/index.js.map +1 -0
  99. package/dist/agent/tools/teams/mailbox.d.ts +21 -0
  100. package/dist/agent/tools/teams/mailbox.d.ts.map +1 -0
  101. package/dist/agent/tools/teams/mailbox.js +106 -0
  102. package/dist/agent/tools/teams/mailbox.js.map +1 -0
  103. package/dist/agent/tools/teams/model-policy.d.ts +23 -0
  104. package/dist/agent/tools/teams/model-policy.d.ts.map +1 -0
  105. package/dist/agent/tools/teams/model-policy.js +113 -0
  106. package/dist/agent/tools/teams/model-policy.js.map +1 -0
  107. package/dist/agent/tools/teams/names.d.ts +28 -0
  108. package/dist/agent/tools/teams/names.d.ts.map +1 -0
  109. package/dist/agent/tools/teams/names.js +109 -0
  110. package/dist/agent/tools/teams/names.js.map +1 -0
  111. package/dist/agent/tools/teams/protocol.d.ts +75 -0
  112. package/dist/agent/tools/teams/protocol.d.ts.map +1 -0
  113. package/dist/agent/tools/teams/protocol.js +205 -0
  114. package/dist/agent/tools/teams/protocol.js.map +1 -0
  115. package/dist/agent/tools/teams/task-store.d.ts +89 -0
  116. package/dist/agent/tools/teams/task-store.d.ts.map +1 -0
  117. package/dist/agent/tools/teams/task-store.js +445 -0
  118. package/dist/agent/tools/teams/task-store.js.map +1 -0
  119. package/dist/agent/tools/teams/team-attach-claim.d.ts +36 -0
  120. package/dist/agent/tools/teams/team-attach-claim.d.ts.map +1 -0
  121. package/dist/agent/tools/teams/team-attach-claim.js +144 -0
  122. package/dist/agent/tools/teams/team-attach-claim.js.map +1 -0
  123. package/dist/agent/tools/teams/team-config.d.ts +55 -0
  124. package/dist/agent/tools/teams/team-config.d.ts.map +1 -0
  125. package/dist/agent/tools/teams/team-config.js +252 -0
  126. package/dist/agent/tools/teams/team-config.js.map +1 -0
  127. package/dist/agent/tools/teams/worktree.d.ts +40 -0
  128. package/dist/agent/tools/teams/worktree.d.ts.map +1 -0
  129. package/dist/agent/tools/teams/worktree.js +213 -0
  130. package/dist/agent/tools/teams/worktree.js.map +1 -0
  131. package/dist/agent/tools/todo-store.js +2 -1
  132. package/dist/agent/tools/todo-store.js.map +1 -1
  133. package/dist/agent/tools/todo.d.ts +2 -2
  134. package/dist/agent/tools/todo.js +2 -2
  135. package/dist/agent/tools/truncate.d.ts.map +1 -1
  136. package/dist/agent/tools/truncate.js +150 -134
  137. package/dist/agent/tools/truncate.js.map +1 -1
  138. package/dist/agent/tools/utils/hook-runner.d.ts +9 -10
  139. package/dist/agent/tools/utils/hook-runner.d.ts.map +1 -1
  140. package/dist/agent/tools/utils/hook-runner.js +18 -16
  141. package/dist/agent/tools/utils/hook-runner.js.map +1 -1
  142. package/dist/agent/tools/utils/image-resize.d.ts +1 -14
  143. package/dist/agent/tools/utils/image-resize.d.ts.map +1 -1
  144. package/dist/agent/tools/utils/image-resize.js +80 -34
  145. package/dist/agent/tools/utils/image-resize.js.map +1 -1
  146. package/dist/agent/tools/utils/mime.d.ts +0 -8
  147. package/dist/agent/tools/utils/mime.d.ts.map +1 -1
  148. package/dist/agent/tools/utils/mime.js +43 -32
  149. package/dist/agent/tools/utils/mime.js.map +1 -1
  150. package/dist/agent/tools/utils/shell.d.ts +1 -23
  151. package/dist/agent/tools/utils/shell.d.ts.map +1 -1
  152. package/dist/agent/tools/utils/shell.js +43 -86
  153. package/dist/agent/tools/utils/shell.js.map +1 -1
  154. package/dist/agent/tools/write.d.ts.map +1 -1
  155. package/dist/agent/tools/write.js +105 -62
  156. package/dist/agent/tools/write.js.map +1 -1
  157. package/dist/agent/types.d.ts +69 -64
  158. package/dist/agent/types.d.ts.map +1 -1
  159. package/dist/agent/types.js +38 -23
  160. package/dist/agent/types.js.map +1 -1
  161. package/dist/agent.d.ts +4 -0
  162. package/dist/agent.d.ts.map +1 -1
  163. package/dist/agent.js +4 -0
  164. package/dist/agent.js.map +1 -1
  165. package/dist/ai/api-registry.d.ts.map +1 -1
  166. package/dist/ai/api-registry.js +3 -4
  167. package/dist/ai/api-registry.js.map +1 -1
  168. package/dist/ai/cli.js +62 -82
  169. package/dist/ai/cli.js.map +1 -1
  170. package/dist/ai/env-api-keys.d.ts.map +1 -1
  171. package/dist/ai/env-api-keys.js +78 -81
  172. package/dist/ai/env-api-keys.js.map +1 -1
  173. package/dist/ai/index.d.ts +6 -0
  174. package/dist/ai/index.d.ts.map +1 -1
  175. package/dist/ai/index.js +6 -0
  176. package/dist/ai/index.js.map +1 -1
  177. package/dist/ai/models.d.ts +7 -17
  178. package/dist/ai/models.d.ts.map +1 -1
  179. package/dist/ai/models.generated.d.ts +87 -244
  180. package/dist/ai/models.generated.d.ts.map +1 -1
  181. package/dist/ai/models.generated.js +82 -241
  182. package/dist/ai/models.generated.js.map +1 -1
  183. package/dist/ai/models.js +17 -11
  184. package/dist/ai/models.js.map +1 -1
  185. package/dist/ai/providers/amazon-bedrock.d.ts.map +1 -1
  186. package/dist/ai/providers/amazon-bedrock.js +319 -248
  187. package/dist/ai/providers/amazon-bedrock.js.map +1 -1
  188. package/dist/ai/providers/anthropic.d.ts.map +1 -1
  189. package/dist/ai/providers/anthropic.js +378 -324
  190. package/dist/ai/providers/anthropic.js.map +1 -1
  191. package/dist/ai/providers/azure-openai-responses.d.ts.map +1 -1
  192. package/dist/ai/providers/azure-openai-responses.js +164 -123
  193. package/dist/ai/providers/azure-openai-responses.js.map +1 -1
  194. package/dist/ai/providers/google-shared.d.ts +0 -18
  195. package/dist/ai/providers/google-shared.d.ts.map +1 -1
  196. package/dist/ai/providers/google-shared.js +224 -225
  197. package/dist/ai/providers/google-shared.js.map +1 -1
  198. package/dist/ai/providers/google-vertex.d.ts.map +1 -1
  199. package/dist/ai/providers/google-vertex.js +244 -226
  200. package/dist/ai/providers/google-vertex.js.map +1 -1
  201. package/dist/ai/providers/google.d.ts +3 -0
  202. package/dist/ai/providers/google.d.ts.map +1 -1
  203. package/dist/ai/providers/google.js +232 -210
  204. package/dist/ai/providers/google.js.map +1 -1
  205. package/dist/ai/providers/kimi.js +1 -0
  206. package/dist/ai/providers/kimi.js.map +1 -1
  207. package/dist/ai/providers/mock.d.ts +10 -0
  208. package/dist/ai/providers/mock.d.ts.map +1 -0
  209. package/dist/ai/providers/mock.js +64 -0
  210. package/dist/ai/providers/mock.js.map +1 -0
  211. package/dist/ai/providers/openai-codex-responses.d.ts.map +1 -1
  212. package/dist/ai/providers/openai-codex-responses.js +178 -133
  213. package/dist/ai/providers/openai-codex-responses.js.map +1 -1
  214. package/dist/ai/providers/openai-completions.d.ts.map +1 -1
  215. package/dist/ai/providers/openai-completions.js +468 -387
  216. package/dist/ai/providers/openai-completions.js.map +1 -1
  217. package/dist/ai/providers/openai-responses-shared.d.ts.map +1 -1
  218. package/dist/ai/providers/openai-responses-shared.js +187 -166
  219. package/dist/ai/providers/openai-responses-shared.js.map +1 -1
  220. package/dist/ai/providers/openai-responses.d.ts.map +1 -1
  221. package/dist/ai/providers/openai-responses.js +108 -85
  222. package/dist/ai/providers/openai-responses.js.map +1 -1
  223. package/dist/ai/providers/openai-scaffold.d.ts +4 -0
  224. package/dist/ai/providers/openai-scaffold.d.ts.map +1 -0
  225. package/dist/ai/providers/openai-scaffold.js +33 -0
  226. package/dist/ai/providers/openai-scaffold.js.map +1 -0
  227. package/dist/ai/providers/register-builtins.d.ts.map +1 -1
  228. package/dist/ai/providers/register-builtins.js +109 -42
  229. package/dist/ai/providers/register-builtins.js.map +1 -1
  230. package/dist/ai/providers/simple-options.js +2 -0
  231. package/dist/ai/providers/simple-options.js.map +1 -1
  232. package/dist/ai/providers/transform-messages.js +3 -9
  233. package/dist/ai/providers/transform-messages.js.map +1 -1
  234. package/dist/ai/stream.d.ts +4 -14
  235. package/dist/ai/stream.d.ts.map +1 -1
  236. package/dist/ai/stream.js +0 -36
  237. package/dist/ai/stream.js.map +1 -1
  238. package/dist/ai/types.d.ts +22 -3
  239. package/dist/ai/types.d.ts.map +1 -1
  240. package/dist/ai/types.js +154 -77
  241. package/dist/ai/types.js.map +1 -1
  242. package/dist/ai/utils/base-stream-handler.js +1 -0
  243. package/dist/ai/utils/base-stream-handler.js.map +1 -1
  244. package/dist/ai/utils/event-stream.d.ts +2 -0
  245. package/dist/ai/utils/event-stream.d.ts.map +1 -1
  246. package/dist/ai/utils/event-stream.js +22 -5
  247. package/dist/ai/utils/event-stream.js.map +1 -1
  248. package/dist/ai/utils/json-parse.d.ts +3 -0
  249. package/dist/ai/utils/json-parse.d.ts.map +1 -1
  250. package/dist/ai/utils/json-parse.js +8 -5
  251. package/dist/ai/utils/json-parse.js.map +1 -1
  252. package/dist/ai/utils/oauth/anthropic.d.ts.map +1 -1
  253. package/dist/ai/utils/oauth/anthropic.js +110 -65
  254. package/dist/ai/utils/oauth/anthropic.js.map +1 -1
  255. package/dist/ai/utils/oauth/github-copilot.d.ts +8 -16
  256. package/dist/ai/utils/oauth/github-copilot.d.ts.map +1 -1
  257. package/dist/ai/utils/oauth/github-copilot.js +218 -227
  258. package/dist/ai/utils/oauth/github-copilot.js.map +1 -1
  259. package/dist/ai/utils/oauth/openai-codex.d.ts +4 -2
  260. package/dist/ai/utils/oauth/openai-codex.d.ts.map +1 -1
  261. package/dist/ai/utils/oauth/openai-codex.js +221 -236
  262. package/dist/ai/utils/oauth/openai-codex.js.map +1 -1
  263. package/dist/ai/utils/oauth/pkce.d.ts +6 -5
  264. package/dist/ai/utils/oauth/pkce.d.ts.map +1 -1
  265. package/dist/ai/utils/oauth/pkce.js +24 -21
  266. package/dist/ai/utils/oauth/pkce.js.map +1 -1
  267. package/dist/ai/utils/oauth/types.d.ts +31 -12
  268. package/dist/ai/utils/oauth/types.d.ts.map +1 -1
  269. package/dist/ai/utils/oauth/types.js +10 -1
  270. package/dist/ai/utils/oauth/types.js.map +1 -1
  271. package/dist/ai/utils/overflow.d.ts.map +1 -1
  272. package/dist/ai/utils/overflow.js +49 -21
  273. package/dist/ai/utils/overflow.js.map +1 -1
  274. package/dist/ai/utils/provider-adapter.js +9 -0
  275. package/dist/ai/utils/provider-adapter.js.map +1 -1
  276. package/dist/ai/utils/provider-client-builder.js +1 -1
  277. package/dist/ai/utils/provider-client-builder.js.map +1 -1
  278. package/dist/ai/utils/provider-errors.js +2 -0
  279. package/dist/ai/utils/provider-errors.js.map +1 -1
  280. package/dist/ai/utils/sanitize-unicode.d.ts +0 -20
  281. package/dist/ai/utils/sanitize-unicode.d.ts.map +1 -1
  282. package/dist/ai/utils/sanitize-unicode.js +35 -17
  283. package/dist/ai/utils/sanitize-unicode.js.map +1 -1
  284. package/dist/ai/utils/stream-event-helper.js +3 -0
  285. package/dist/ai/utils/stream-event-helper.js.map +1 -1
  286. package/dist/ai/utils/stream-handler-types.js +5 -0
  287. package/dist/ai/utils/stream-handler-types.js.map +1 -1
  288. package/dist/ai/utils/streaming-state-manager.js +4 -2
  289. package/dist/ai/utils/streaming-state-manager.js.map +1 -1
  290. package/dist/ai/utils/typebox-helpers.d.ts +6 -4
  291. package/dist/ai/utils/typebox-helpers.d.ts.map +1 -1
  292. package/dist/ai/utils/typebox-helpers.js +25 -7
  293. package/dist/ai/utils/typebox-helpers.js.map +1 -1
  294. package/dist/ai/utils/validation.d.ts.map +1 -1
  295. package/dist/ai/utils/validation.js +67 -34
  296. package/dist/ai/utils/validation.js.map +1 -1
  297. package/dist/ai.d.ts +4 -0
  298. package/dist/ai.d.ts.map +1 -1
  299. package/dist/ai.js +4 -0
  300. package/dist/ai.js.map +1 -1
  301. package/dist/cli.d.ts +3 -0
  302. package/dist/cli.d.ts.map +1 -0
  303. package/dist/cli.js +3 -0
  304. package/dist/cli.js.map +1 -0
  305. package/dist/index.d.ts +1 -0
  306. package/dist/index.d.ts.map +1 -1
  307. package/dist/index.js +1 -0
  308. package/dist/index.js.map +1 -1
  309. package/dist/mcp/client-pool.js +3 -2
  310. package/dist/mcp/client-pool.js.map +1 -1
  311. package/dist/mcp/client.js +19 -6
  312. package/dist/mcp/client.js.map +1 -1
  313. package/dist/mcp/config.d.ts +6 -6
  314. package/dist/mcp/config.js +17 -17
  315. package/dist/mcp/config.js.map +1 -1
  316. package/dist/mcp/errors.js +8 -0
  317. package/dist/mcp/errors.js.map +1 -1
  318. package/dist/mcp/index.d.ts +5 -5
  319. package/dist/mcp/index.js +5 -5
  320. package/dist/mcp/schema-converter.d.ts +1 -1
  321. package/dist/mcp/schema-converter.js +1 -1
  322. package/dist/mcp/server.d.ts +4 -4
  323. package/dist/mcp/server.js +12 -7
  324. package/dist/mcp/server.js.map +1 -1
  325. package/dist/mcp/tool-factory.d.ts +2 -2
  326. package/dist/mcp/tool-factory.js +2 -2
  327. package/dist/mcp.d.ts +0 -4
  328. package/dist/mcp.d.ts.map +1 -1
  329. package/dist/mcp.js +0 -4
  330. package/dist/mcp.js.map +1 -1
  331. package/dist/observability.d.ts +2 -0
  332. package/dist/observability.d.ts.map +1 -0
  333. package/dist/observability.js +2 -0
  334. package/dist/observability.js.map +1 -0
  335. package/dist/tui/autocomplete.d.ts +14 -18
  336. package/dist/tui/autocomplete.d.ts.map +1 -1
  337. package/dist/tui/autocomplete.js +290 -402
  338. package/dist/tui/autocomplete.js.map +1 -1
  339. package/dist/tui/components/box.d.ts +1 -6
  340. package/dist/tui/components/box.d.ts.map +1 -1
  341. package/dist/tui/components/box.js +98 -67
  342. package/dist/tui/components/box.js.map +1 -1
  343. package/dist/tui/components/cancellable-loader.d.ts +6 -3
  344. package/dist/tui/components/cancellable-loader.d.ts.map +1 -1
  345. package/dist/tui/components/cancellable-loader.js +8 -9
  346. package/dist/tui/components/cancellable-loader.js.map +1 -1
  347. package/dist/tui/components/editor.d.ts +18 -0
  348. package/dist/tui/components/editor.d.ts.map +1 -1
  349. package/dist/tui/components/editor.js +356 -354
  350. package/dist/tui/components/editor.js.map +1 -1
  351. package/dist/tui/components/image.d.ts +2 -0
  352. package/dist/tui/components/image.d.ts.map +1 -1
  353. package/dist/tui/components/image.js +79 -37
  354. package/dist/tui/components/image.js.map +1 -1
  355. package/dist/tui/components/input.d.ts +4 -8
  356. package/dist/tui/components/input.d.ts.map +1 -1
  357. package/dist/tui/components/input.js +236 -232
  358. package/dist/tui/components/input.js.map +1 -1
  359. package/dist/tui/components/loader.d.ts +5 -5
  360. package/dist/tui/components/loader.d.ts.map +1 -1
  361. package/dist/tui/components/loader.js +22 -19
  362. package/dist/tui/components/loader.js.map +1 -1
  363. package/dist/tui/components/markdown.d.ts +2 -32
  364. package/dist/tui/components/markdown.d.ts.map +1 -1
  365. package/dist/tui/components/markdown.js +338 -357
  366. package/dist/tui/components/markdown.js.map +1 -1
  367. package/dist/tui/components/select-list.d.ts +1 -0
  368. package/dist/tui/components/select-list.d.ts.map +1 -1
  369. package/dist/tui/components/select-list.js +83 -82
  370. package/dist/tui/components/select-list.js.map +1 -1
  371. package/dist/tui/components/settings-list.d.ts +10 -10
  372. package/dist/tui/components/settings-list.d.ts.map +1 -1
  373. package/dist/tui/components/settings-list.js +48 -40
  374. package/dist/tui/components/settings-list.js.map +1 -1
  375. package/dist/tui/components/spacer.d.ts +1 -0
  376. package/dist/tui/components/spacer.d.ts.map +1 -1
  377. package/dist/tui/components/spacer.js +20 -5
  378. package/dist/tui/components/spacer.js.map +1 -1
  379. package/dist/tui/components/text.d.ts.map +1 -1
  380. package/dist/tui/components/text.js +47 -20
  381. package/dist/tui/components/text.js.map +1 -1
  382. package/dist/tui/components/truncated-text.d.ts +8 -4
  383. package/dist/tui/components/truncated-text.d.ts.map +1 -1
  384. package/dist/tui/components/truncated-text.js +15 -12
  385. package/dist/tui/components/truncated-text.js.map +1 -1
  386. package/dist/tui/editor-component.d.ts +87 -23
  387. package/dist/tui/editor-component.d.ts.map +1 -1
  388. package/dist/tui/fuzzy.d.ts.map +1 -1
  389. package/dist/tui/fuzzy.js +101 -50
  390. package/dist/tui/fuzzy.js.map +1 -1
  391. package/dist/tui/keybindings.d.ts +3 -3
  392. package/dist/tui/keybindings.d.ts.map +1 -1
  393. package/dist/tui/keybindings.js +137 -111
  394. package/dist/tui/keybindings.js.map +1 -1
  395. package/dist/tui/keys.d.ts +46 -43
  396. package/dist/tui/keys.d.ts.map +1 -1
  397. package/dist/tui/keys.js +493 -411
  398. package/dist/tui/keys.js.map +1 -1
  399. package/dist/tui/stdin-buffer.d.ts.map +1 -1
  400. package/dist/tui/stdin-buffer.js +162 -159
  401. package/dist/tui/stdin-buffer.js.map +1 -1
  402. package/dist/tui/terminal-image.d.ts +10 -5
  403. package/dist/tui/terminal-image.d.ts.map +1 -1
  404. package/dist/tui/terminal-image.js +53 -51
  405. package/dist/tui/terminal-image.js.map +1 -1
  406. package/dist/tui/terminal.d.ts +4 -27
  407. package/dist/tui/terminal.d.ts.map +1 -1
  408. package/dist/tui/terminal.js +123 -121
  409. package/dist/tui/terminal.js.map +1 -1
  410. package/dist/tui/tui.d.ts +14 -1
  411. package/dist/tui/tui.d.ts.map +1 -1
  412. package/dist/tui/tui.js +185 -145
  413. package/dist/tui/tui.js.map +1 -1
  414. package/dist/tui/utils.d.ts.map +1 -1
  415. package/dist/tui/utils.js +235 -216
  416. package/dist/tui/utils.js.map +1 -1
  417. package/dist/tui.d.ts +4 -0
  418. package/dist/tui.d.ts.map +1 -1
  419. package/dist/tui.js +4 -0
  420. package/dist/tui.js.map +1 -1
  421. package/package.json +23 -43
  422. package/LICENSE.md +0 -22
  423. package/dist/agent/tools/task-types.d.ts +0 -74
  424. package/dist/agent/tools/task-types.d.ts.map +0 -1
  425. package/dist/agent/tools/task-types.js +0 -8
  426. package/dist/agent/tools/task-types.js.map +0 -1
  427. package/dist/agent/tools/task.d.ts +0 -84
  428. package/dist/agent/tools/task.d.ts.map +0 -1
  429. package/dist/agent/tools/task.js +0 -184
  430. package/dist/agent/tools/task.js.map +0 -1
  431. package/dist/memory/embedder/base.d.ts +0 -41
  432. package/dist/memory/embedder/base.d.ts.map +0 -1
  433. package/dist/memory/embedder/base.js +0 -10
  434. package/dist/memory/embedder/base.js.map +0 -1
  435. package/dist/memory/embedder/index.d.ts +0 -8
  436. package/dist/memory/embedder/index.d.ts.map +0 -1
  437. package/dist/memory/embedder/index.js +0 -6
  438. package/dist/memory/embedder/index.js.map +0 -1
  439. package/dist/memory/embedder/openai.d.ts +0 -35
  440. package/dist/memory/embedder/openai.d.ts.map +0 -1
  441. package/dist/memory/embedder/openai.js +0 -103
  442. package/dist/memory/embedder/openai.js.map +0 -1
  443. package/dist/memory/index.d.ts +0 -33
  444. package/dist/memory/index.d.ts.map +0 -1
  445. package/dist/memory/index.js +0 -31
  446. package/dist/memory/index.js.map +0 -1
  447. package/dist/memory/memory.d.ts +0 -126
  448. package/dist/memory/memory.d.ts.map +0 -1
  449. package/dist/memory/memory.js +0 -280
  450. package/dist/memory/memory.js.map +0 -1
  451. package/dist/memory/processors/base.d.ts +0 -42
  452. package/dist/memory/processors/base.d.ts.map +0 -1
  453. package/dist/memory/processors/base.js +0 -6
  454. package/dist/memory/processors/base.js.map +0 -1
  455. package/dist/memory/processors/index.d.ts +0 -16
  456. package/dist/memory/processors/index.d.ts.map +0 -1
  457. package/dist/memory/processors/index.js +0 -18
  458. package/dist/memory/processors/index.js.map +0 -1
  459. package/dist/memory/processors/message-history.d.ts +0 -35
  460. package/dist/memory/processors/message-history.d.ts.map +0 -1
  461. package/dist/memory/processors/message-history.js +0 -51
  462. package/dist/memory/processors/message-history.js.map +0 -1
  463. package/dist/memory/processors/observational-memory/index.d.ts +0 -82
  464. package/dist/memory/processors/observational-memory/index.d.ts.map +0 -1
  465. package/dist/memory/processors/observational-memory/index.js +0 -234
  466. package/dist/memory/processors/observational-memory/index.js.map +0 -1
  467. package/dist/memory/processors/observational-memory/observer-agent.d.ts +0 -64
  468. package/dist/memory/processors/observational-memory/observer-agent.d.ts.map +0 -1
  469. package/dist/memory/processors/observational-memory/observer-agent.js +0 -362
  470. package/dist/memory/processors/observational-memory/observer-agent.js.map +0 -1
  471. package/dist/memory/processors/observational-memory/reflector-agent.d.ts +0 -38
  472. package/dist/memory/processors/observational-memory/reflector-agent.d.ts.map +0 -1
  473. package/dist/memory/processors/observational-memory/reflector-agent.js +0 -213
  474. package/dist/memory/processors/observational-memory/reflector-agent.js.map +0 -1
  475. package/dist/memory/processors/observational-memory/token-counter.d.ts +0 -35
  476. package/dist/memory/processors/observational-memory/token-counter.d.ts.map +0 -1
  477. package/dist/memory/processors/observational-memory/token-counter.js +0 -90
  478. package/dist/memory/processors/observational-memory/token-counter.js.map +0 -1
  479. package/dist/memory/processors/semantic-recall.d.ts +0 -55
  480. package/dist/memory/processors/semantic-recall.d.ts.map +0 -1
  481. package/dist/memory/processors/semantic-recall.js +0 -143
  482. package/dist/memory/processors/semantic-recall.js.map +0 -1
  483. package/dist/memory/processors/working-memory.d.ts +0 -41
  484. package/dist/memory/processors/working-memory.d.ts.map +0 -1
  485. package/dist/memory/processors/working-memory.js +0 -82
  486. package/dist/memory/processors/working-memory.js.map +0 -1
  487. package/dist/memory/storage/base.d.ts +0 -288
  488. package/dist/memory/storage/base.d.ts.map +0 -1
  489. package/dist/memory/storage/base.js +0 -211
  490. package/dist/memory/storage/base.js.map +0 -1
  491. package/dist/memory/storage/index.d.ts +0 -9
  492. package/dist/memory/storage/index.d.ts.map +0 -1
  493. package/dist/memory/storage/index.js +0 -7
  494. package/dist/memory/storage/index.js.map +0 -1
  495. package/dist/memory/storage/inmemory.d.ts +0 -93
  496. package/dist/memory/storage/inmemory.d.ts.map +0 -1
  497. package/dist/memory/storage/inmemory.js +0 -646
  498. package/dist/memory/storage/inmemory.js.map +0 -1
  499. package/dist/memory/tools/working-memory.d.ts +0 -100
  500. package/dist/memory/tools/working-memory.d.ts.map +0 -1
  501. package/dist/memory/tools/working-memory.js +0 -237
  502. package/dist/memory/tools/working-memory.js.map +0 -1
  503. package/dist/memory/types.d.ts +0 -386
  504. package/dist/memory/types.d.ts.map +0 -1
  505. package/dist/memory/types.js +0 -58
  506. package/dist/memory/types.js.map +0 -1
  507. package/dist/memory/vector/base.d.ts +0 -145
  508. package/dist/memory/vector/base.d.ts.map +0 -1
  509. package/dist/memory/vector/base.js +0 -83
  510. package/dist/memory/vector/base.js.map +0 -1
  511. package/dist/memory/vector/index.d.ts +0 -8
  512. package/dist/memory/vector/index.d.ts.map +0 -1
  513. package/dist/memory/vector/index.js +0 -7
  514. package/dist/memory/vector/index.js.map +0 -1
  515. package/dist/memory/vector/inmemory.d.ts +0 -47
  516. package/dist/memory/vector/inmemory.d.ts.map +0 -1
  517. package/dist/memory/vector/inmemory.js +0 -234
  518. package/dist/memory/vector/inmemory.js.map +0 -1
@@ -1,107 +1,22 @@
1
1
  import { marked } from "marked";
2
2
  import { ComponentBase } from "../tui.js";
3
3
  import { applyBackgroundToLine, visibleWidth, wrapTextWithAnsi } from "../utils.js";
4
- export class Markdown extends ComponentBase {
5
- constructor(text, paddingX, paddingY, theme, defaultTextStyle) {
6
- super();
7
- this.text = text;
8
- this.paddingX = paddingX;
9
- this.paddingY = paddingY;
4
+ class InlineStyleEngine {
5
+ theme;
6
+ defaultTextStyle;
7
+ stylePrefixCache;
8
+ constructor(theme, defaultTextStyle) {
10
9
  this.theme = theme;
11
10
  this.defaultTextStyle = defaultTextStyle;
12
11
  }
13
- setText(text) {
14
- this.text = text;
15
- this.invalidate();
16
- }
17
- invalidate() {
18
- super.invalidate();
19
- this.cachedText = undefined;
20
- this.cachedWidth = undefined;
21
- this.cachedLines = undefined;
22
- }
23
- render(width) {
24
- if (this.cachedLines && this.cachedText === this.text && this.cachedWidth === width) {
25
- return this.cachedLines;
26
- }
27
- return this.renderCached(width, () => {
28
- // Calculate available width for content (subtract horizontal padding)
29
- const contentWidth = Math.max(1, width - this.paddingX * 2);
30
- // Don't render anything if there's no actual text
31
- if (!this.text || this.text.trim() === "") {
32
- const result = [];
33
- // Update cache
34
- this.cachedText = this.text;
35
- this.cachedWidth = width;
36
- this.cachedLines = result;
37
- return result;
38
- }
39
- // Replace tabs with 3 spaces for consistent rendering
40
- const normalizedText = this.text.replace(/\t/g, " ");
41
- // Parse markdown to HTML-like tokens
42
- const tokens = marked.lexer(normalizedText);
43
- // Convert tokens to styled terminal output
44
- const renderedLines = [];
45
- for (let i = 0; i < tokens.length; i++) {
46
- const token = tokens[i];
47
- const nextToken = tokens[i + 1];
48
- const tokenLines = this.renderToken(token, contentWidth, nextToken?.type);
49
- renderedLines.push(...tokenLines);
50
- }
51
- // Wrap lines (NO padding, NO background yet)
52
- const wrappedLines = [];
53
- for (const line of renderedLines) {
54
- wrappedLines.push(...wrapTextWithAnsi(line, contentWidth));
55
- }
56
- // Add margins and background to each wrapped line
57
- const leftMargin = " ".repeat(this.paddingX);
58
- const rightMargin = " ".repeat(this.paddingX);
59
- const bgFn = this.defaultTextStyle?.bgColor;
60
- const contentLines = [];
61
- for (const line of wrappedLines) {
62
- const lineWithMargins = leftMargin + line + rightMargin;
63
- if (bgFn) {
64
- contentLines.push(applyBackgroundToLine(lineWithMargins, width, bgFn));
65
- }
66
- else {
67
- // No background - just pad to width
68
- const visibleLen = visibleWidth(lineWithMargins);
69
- const paddingNeeded = Math.max(0, width - visibleLen);
70
- contentLines.push(lineWithMargins + " ".repeat(paddingNeeded));
71
- }
72
- }
73
- // Add top/bottom padding (empty lines)
74
- const emptyLine = " ".repeat(width);
75
- const emptyLines = [];
76
- for (let i = 0; i < this.paddingY; i++) {
77
- const line = bgFn ? applyBackgroundToLine(emptyLine, width, bgFn) : emptyLine;
78
- emptyLines.push(line);
79
- }
80
- // Combine top padding, content, and bottom padding
81
- const result = [...emptyLines, ...contentLines, ...emptyLines];
82
- // Update cache
83
- this.cachedText = this.text;
84
- this.cachedWidth = width;
85
- this.cachedLines = result;
86
- return result.length > 0 ? result : [""];
87
- });
88
- }
89
- /**
90
- * Apply default text style to a string.
91
- * This is the base styling applied to all text content.
92
- * NOTE: Background color is NOT applied here - it's applied at the padding stage
93
- * to ensure it extends to the full line width.
94
- */
95
- applyDefaultStyle(text) {
12
+ applyDefault(text) {
96
13
  if (!this.defaultTextStyle) {
97
14
  return text;
98
15
  }
99
16
  let styled = text;
100
- // Apply foreground color (NOT background - that's applied at padding stage)
101
17
  if (this.defaultTextStyle.color) {
102
18
  styled = this.defaultTextStyle.color(styled);
103
19
  }
104
- // Apply text decorations using this.theme
105
20
  if (this.defaultTextStyle.bold) {
106
21
  styled = this.theme.bold(styled);
107
22
  }
@@ -116,12 +31,12 @@ export class Markdown extends ComponentBase {
116
31
  }
117
32
  return styled;
118
33
  }
119
- getDefaultStylePrefix() {
34
+ getStylePrefix() {
120
35
  if (!this.defaultTextStyle) {
121
36
  return "";
122
37
  }
123
- if (this.defaultStylePrefix !== undefined) {
124
- return this.defaultStylePrefix;
38
+ if (this.stylePrefixCache !== undefined) {
39
+ return this.stylePrefixCache;
125
40
  }
126
41
  const sentinel = "\u0000";
127
42
  let styled = sentinel;
@@ -141,16 +56,224 @@ export class Markdown extends ComponentBase {
141
56
  styled = this.theme.underline(styled);
142
57
  }
143
58
  const sentinelIndex = styled.indexOf(sentinel);
144
- this.defaultStylePrefix = sentinelIndex >= 0 ? styled.slice(0, sentinelIndex) : "";
145
- return this.defaultStylePrefix;
59
+ this.stylePrefixCache = sentinelIndex >= 0 ? styled.slice(0, sentinelIndex) : "";
60
+ return this.stylePrefixCache;
61
+ }
62
+ }
63
+ class MarkdownListRenderer {
64
+ theme;
65
+ renderInlineTokenList;
66
+ constructor(theme, renderInlineTokenList) {
67
+ this.theme = theme;
68
+ this.renderInlineTokenList = renderInlineTokenList;
69
+ }
70
+ render(token, depth) {
71
+ const lines = [];
72
+ const indent = " ".repeat(depth);
73
+ const startNumber = token.start ?? 1;
74
+ for (let i = 0; i < token.items.length; i++) {
75
+ const item = token.items[i];
76
+ const bullet = token.ordered ? `${startNumber + i}. ` : "- ";
77
+ const itemLines = this.renderListItemTokens(item.tokens || [], depth);
78
+ if (itemLines.length > 0) {
79
+ const firstLine = itemLines[0];
80
+ const isNestedList = /^\s+\x1b\[36m[-\d]/.test(firstLine);
81
+ if (isNestedList) {
82
+ lines.push(firstLine);
83
+ }
84
+ else {
85
+ lines.push(indent + this.theme.listBullet(bullet) + firstLine);
86
+ }
87
+ for (let j = 1; j < itemLines.length; j++) {
88
+ const line = itemLines[j];
89
+ const isNestedListLine = /^\s+\x1b\[36m[-\d]/.test(line);
90
+ if (isNestedListLine) {
91
+ lines.push(line);
92
+ }
93
+ else {
94
+ lines.push(`${indent} ${line}`);
95
+ }
96
+ }
97
+ }
98
+ else {
99
+ lines.push(indent + this.theme.listBullet(bullet));
100
+ }
101
+ }
102
+ return lines;
103
+ }
104
+ renderListItemTokens(tokens, parentDepth) {
105
+ const lines = [];
106
+ for (const token of tokens) {
107
+ if (token.type === "list") {
108
+ const nestedLines = this.render(token, parentDepth + 1);
109
+ lines.push(...nestedLines);
110
+ continue;
111
+ }
112
+ if (token.type === "text") {
113
+ const text = token.tokens && token.tokens.length > 0
114
+ ? this.renderInlineTokenList(token.tokens)
115
+ : (token.text ?? "");
116
+ lines.push(text);
117
+ continue;
118
+ }
119
+ if (token.type === "paragraph") {
120
+ lines.push(this.renderInlineTokenList(token.tokens || []));
121
+ continue;
122
+ }
123
+ if (token.type === "code") {
124
+ const codeIndent = this.theme.codeBlockIndent ?? " ";
125
+ lines.push(this.theme.codeBlockBorder(`\`\`\`${token.lang || ""}`));
126
+ if (this.theme.highlightCode) {
127
+ const highlightedLines = this.theme.highlightCode(token.text, token.lang);
128
+ for (const highlightedLine of highlightedLines) {
129
+ lines.push(`${codeIndent}${highlightedLine}`);
130
+ }
131
+ }
132
+ else {
133
+ for (const rawLine of token.text.split("\n")) {
134
+ lines.push(`${codeIndent}${this.theme.codeBlock(rawLine)}`);
135
+ }
136
+ }
137
+ lines.push(this.theme.codeBlockBorder("```"));
138
+ continue;
139
+ }
140
+ const fallbackText = this.renderInlineTokenList([token]);
141
+ if (fallbackText) {
142
+ lines.push(fallbackText);
143
+ }
144
+ }
145
+ return lines;
146
146
  }
147
- renderToken(token, width, nextTokenType) {
147
+ }
148
+ class MarkdownTableRenderer {
149
+ theme;
150
+ renderInlineTokenList;
151
+ constructor(theme, renderInlineTokenList) {
152
+ this.theme = theme;
153
+ this.renderInlineTokenList = renderInlineTokenList;
154
+ }
155
+ wrapCellText(text, maxWidth) {
156
+ return wrapTextWithAnsi(text, Math.max(1, maxWidth));
157
+ }
158
+ render(token, availableWidth) {
159
+ const lines = [];
160
+ const columnCount = token.header.length;
161
+ if (columnCount === 0) {
162
+ return lines;
163
+ }
164
+ const borderOverhead = 3 * columnCount + 1;
165
+ const minTableWidth = borderOverhead + columnCount;
166
+ if (availableWidth < minTableWidth) {
167
+ const fallbackLines = token.raw ? wrapTextWithAnsi(token.raw, availableWidth) : [];
168
+ fallbackLines.push("");
169
+ return fallbackLines;
170
+ }
171
+ const naturalWidths = [];
172
+ for (let i = 0; i < columnCount; i++) {
173
+ const headerText = this.renderInlineTokenList(token.header[i].tokens || []);
174
+ naturalWidths[i] = visibleWidth(headerText);
175
+ }
176
+ for (const row of token.rows) {
177
+ for (let i = 0; i < row.length; i++) {
178
+ const cellText = this.renderInlineTokenList(row[i].tokens || []);
179
+ naturalWidths[i] = Math.max(naturalWidths[i] || 0, visibleWidth(cellText));
180
+ }
181
+ }
182
+ const totalNaturalWidth = naturalWidths.reduce((a, b) => a + b, 0) + borderOverhead;
183
+ let columnWidths;
184
+ if (totalNaturalWidth <= availableWidth) {
185
+ columnWidths = naturalWidths;
186
+ }
187
+ else {
188
+ const availableForCells = availableWidth - borderOverhead;
189
+ if (availableForCells <= columnCount) {
190
+ columnWidths = naturalWidths.map(() => Math.max(1, Math.floor(availableForCells / columnCount)));
191
+ }
192
+ else {
193
+ const totalNatural = naturalWidths.reduce((a, b) => a + b, 0);
194
+ columnWidths = naturalWidths.map((width) => {
195
+ const proportion = width / totalNatural;
196
+ return Math.max(1, Math.floor(proportion * availableForCells));
197
+ });
198
+ const allocated = columnWidths.reduce((a, b) => a + b, 0);
199
+ let remaining = availableForCells - allocated;
200
+ for (let i = 0; remaining > 0 && i < columnCount; i++) {
201
+ columnWidths[i]++;
202
+ remaining--;
203
+ }
204
+ }
205
+ }
206
+ const topBorderCells = columnWidths.map((w) => "─".repeat(w));
207
+ lines.push(`┌─${topBorderCells.join("─┬─")}─┐`);
208
+ const headerCellLines = token.header.map((cell, i) => {
209
+ const text = this.renderInlineTokenList(cell.tokens || []);
210
+ return this.wrapCellText(text, columnWidths[i]);
211
+ });
212
+ const headerLineCount = Math.max(...headerCellLines.map((cellLines) => cellLines.length));
213
+ for (let lineIndex = 0; lineIndex < headerLineCount; lineIndex++) {
214
+ const rowParts = headerCellLines.map((cellLines, columnIndex) => {
215
+ const text = cellLines[lineIndex] || "";
216
+ const padded = text + " ".repeat(Math.max(0, columnWidths[columnIndex] - visibleWidth(text)));
217
+ return this.theme.bold(padded);
218
+ });
219
+ lines.push(`│ ${rowParts.join(" │ ")} │`);
220
+ }
221
+ const separatorCells = columnWidths.map((w) => "─".repeat(w));
222
+ lines.push(`├─${separatorCells.join("─┼─")}─┤`);
223
+ for (const row of token.rows) {
224
+ const rowCellLines = row.map((cell, i) => {
225
+ const text = this.renderInlineTokenList(cell.tokens || []);
226
+ return this.wrapCellText(text, columnWidths[i]);
227
+ });
228
+ const rowLineCount = Math.max(...rowCellLines.map((cellLines) => cellLines.length));
229
+ for (let lineIndex = 0; lineIndex < rowLineCount; lineIndex++) {
230
+ const rowParts = rowCellLines.map((cellLines, columnIndex) => {
231
+ const text = cellLines[lineIndex] || "";
232
+ return text + " ".repeat(Math.max(0, columnWidths[columnIndex] - visibleWidth(text)));
233
+ });
234
+ lines.push(`│ ${rowParts.join(" │ ")} │`);
235
+ }
236
+ }
237
+ const bottomBorderCells = columnWidths.map((w) => "─".repeat(w));
238
+ lines.push(`└─${bottomBorderCells.join("─┴─")}─┘`);
239
+ lines.push("");
240
+ return lines;
241
+ }
242
+ }
243
+ class MarkdownRenderEngine {
244
+ theme;
245
+ defaultTextStyle;
246
+ paddingX;
247
+ paddingY;
248
+ inlineStyleEngine;
249
+ listRenderer;
250
+ tableRenderer;
251
+ constructor(theme, defaultTextStyle, paddingX, paddingY) {
252
+ this.theme = theme;
253
+ this.defaultTextStyle = defaultTextStyle;
254
+ this.paddingX = paddingX;
255
+ this.paddingY = paddingY;
256
+ this.inlineStyleEngine = new InlineStyleEngine(theme, defaultTextStyle);
257
+ this.listRenderer = new MarkdownListRenderer(theme, (tokens) => this.renderInlineTokenList(tokens));
258
+ this.tableRenderer = new MarkdownTableRenderer(theme, (tokens) => this.renderInlineTokenList(tokens));
259
+ }
260
+ renderTokens(tokens, contentWidth) {
261
+ const blockLines = [];
262
+ for (let i = 0; i < tokens.length; i++) {
263
+ const token = tokens[i];
264
+ const nextTokenType = tokens[i + 1]?.type;
265
+ const tokenLines = this.renderBlockToken(token, contentWidth, nextTokenType);
266
+ blockLines.push(...tokenLines);
267
+ }
268
+ return blockLines;
269
+ }
270
+ renderBlockToken(token, width, nextTokenType) {
148
271
  const lines = [];
149
272
  switch (token.type) {
150
273
  case "heading": {
151
274
  const headingLevel = token.depth;
152
275
  const headingPrefix = `${"#".repeat(headingLevel)} `;
153
- const headingText = this.renderInlineTokens(token.tokens || []);
276
+ const headingText = this.renderInlineTokenList(token.tokens || []);
154
277
  let styledHeading;
155
278
  if (headingLevel === 1) {
156
279
  styledHeading = this.theme.heading(this.theme.bold(this.theme.underline(headingText)));
@@ -163,133 +286,116 @@ export class Markdown extends ComponentBase {
163
286
  }
164
287
  lines.push(styledHeading);
165
288
  if (nextTokenType !== "space") {
166
- lines.push(""); // Add spacing after headings (unless space token follows)
289
+ lines.push("");
167
290
  }
168
291
  break;
169
292
  }
170
293
  case "paragraph": {
171
- const paragraphText = this.renderInlineTokens(token.tokens || []);
172
- lines.push(paragraphText);
173
- // Don't add spacing if next token is space or list
294
+ lines.push(this.renderInlineTokenList(token.tokens || []));
174
295
  if (nextTokenType && nextTokenType !== "list" && nextTokenType !== "space") {
175
296
  lines.push("");
176
297
  }
177
298
  break;
178
299
  }
179
300
  case "code": {
180
- const indent = this.theme.codeBlockIndent ?? " ";
301
+ const codeIndent = this.theme.codeBlockIndent ?? " ";
181
302
  lines.push(this.theme.codeBlockBorder(`\`\`\`${token.lang || ""}`));
182
303
  if (this.theme.highlightCode) {
183
- const highlightedLines = this.theme.highlightCode(token.text, token.lang);
184
- for (const hlLine of highlightedLines) {
185
- lines.push(`${indent}${hlLine}`);
304
+ for (const highlightedLine of this.theme.highlightCode(token.text, token.lang)) {
305
+ lines.push(`${codeIndent}${highlightedLine}`);
186
306
  }
187
307
  }
188
308
  else {
189
- // Split code by newlines and style each line
190
- const codeLines = token.text.split("\n");
191
- for (const codeLine of codeLines) {
192
- lines.push(`${indent}${this.theme.codeBlock(codeLine)}`);
309
+ for (const rawLine of token.text.split("\n")) {
310
+ lines.push(`${codeIndent}${this.theme.codeBlock(rawLine)}`);
193
311
  }
194
312
  }
195
313
  lines.push(this.theme.codeBlockBorder("```"));
196
314
  if (nextTokenType !== "space") {
197
- lines.push(""); // Add spacing after code blocks (unless space token follows)
315
+ lines.push("");
198
316
  }
199
317
  break;
200
318
  }
201
319
  case "list": {
202
- const listLines = this.renderList(token, 0);
203
- lines.push(...listLines);
204
- // Don't add spacing after lists if a space token follows
205
- // (the space token will handle it)
320
+ lines.push(...this.listRenderer.render(token, 0));
206
321
  break;
207
322
  }
208
323
  case "table": {
209
- const tableLines = this.renderTable(token, width);
210
- lines.push(...tableLines);
324
+ lines.push(...this.tableRenderer.render(token, width));
211
325
  break;
212
326
  }
213
327
  case "blockquote": {
214
- const quoteText = this.renderInlineTokens(token.tokens || []);
215
- const quoteLines = quoteText.split("\n");
216
- for (const quoteLine of quoteLines) {
328
+ const quoteText = this.renderInlineTokenList(token.tokens || []);
329
+ for (const quoteLine of quoteText.split("\n")) {
217
330
  lines.push(this.theme.quoteBorder("│ ") + this.theme.quote(this.theme.italic(quoteLine)));
218
331
  }
219
332
  if (nextTokenType !== "space") {
220
- lines.push(""); // Add spacing after blockquotes (unless space token follows)
333
+ lines.push("");
221
334
  }
222
335
  break;
223
336
  }
224
- case "hr":
337
+ case "hr": {
225
338
  lines.push(this.theme.hr("─".repeat(Math.min(width, 80))));
226
339
  if (nextTokenType !== "space") {
227
- lines.push(""); // Add spacing after horizontal rules (unless space token follows)
340
+ lines.push("");
228
341
  }
229
342
  break;
230
- case "html":
231
- // Render HTML as plain text (escaped for terminal)
343
+ }
344
+ case "html": {
232
345
  if ("raw" in token && typeof token.raw === "string") {
233
- lines.push(this.applyDefaultStyle(token.raw.trim()));
346
+ lines.push(this.inlineStyleEngine.applyDefault(token.raw.trim()));
234
347
  }
235
348
  break;
236
- case "space":
237
- // Space tokens represent blank lines in markdown
349
+ }
350
+ case "space": {
238
351
  lines.push("");
239
352
  break;
240
- default:
241
- // Handle any other token types as plain text
353
+ }
354
+ default: {
242
355
  if ("text" in token && typeof token.text === "string") {
243
356
  lines.push(token.text);
244
357
  }
358
+ }
245
359
  }
246
360
  return lines;
247
361
  }
248
- renderInlineTokens(tokens) {
362
+ renderInlineTokenList(tokens) {
249
363
  let result = "";
250
364
  for (const token of tokens) {
251
365
  switch (token.type) {
252
366
  case "text":
253
- // Text tokens in list items can have nested tokens for inline formatting
254
367
  if (token.tokens && token.tokens.length > 0) {
255
- result += this.renderInlineTokens(token.tokens);
368
+ result += this.renderInlineTokenList(token.tokens);
256
369
  }
257
370
  else {
258
- // Apply default style to plain text
259
- result += this.applyDefaultStyle(token.text);
371
+ result += this.inlineStyleEngine.applyDefault(token.text);
260
372
  }
261
373
  break;
262
374
  case "strong": {
263
- // Apply bold, then reapply default style after
264
- const boldContent = this.renderInlineTokens(token.tokens || []);
265
- result += this.theme.bold(boldContent) + this.getDefaultStylePrefix();
375
+ const strongContent = this.renderInlineTokenList(token.tokens || []);
376
+ result += this.theme.bold(strongContent) + this.inlineStyleEngine.getStylePrefix();
266
377
  break;
267
378
  }
268
379
  case "em": {
269
- // Apply italic, then reapply default style after
270
- const italicContent = this.renderInlineTokens(token.tokens || []);
271
- result += this.theme.italic(italicContent) + this.getDefaultStylePrefix();
380
+ const emphasizedContent = this.renderInlineTokenList(token.tokens || []);
381
+ result += this.theme.italic(emphasizedContent) + this.inlineStyleEngine.getStylePrefix();
272
382
  break;
273
383
  }
274
384
  case "codespan":
275
- // Apply code styling without backticks
276
- result += this.theme.code(token.text) + this.getDefaultStylePrefix();
385
+ result += this.theme.code(token.text) + this.inlineStyleEngine.getStylePrefix();
277
386
  break;
278
387
  case "link": {
279
- const linkText = this.renderInlineTokens(token.tokens || []);
280
- // If link text matches href, only show the link once
281
- // Compare raw text (token.text) not styled text (linkText) since linkText has ANSI codes
282
- // For mailto: links, strip the prefix before comparing (autolinked emails have
283
- // text="foo@bar.com" but href="mailto:foo@bar.com")
388
+ const linkText = this.renderInlineTokenList(token.tokens || []);
284
389
  const hrefForComparison = token.href.startsWith("mailto:") ? token.href.slice(7) : token.href;
285
390
  if (token.text === token.href || token.text === hrefForComparison) {
286
- result += this.theme.link(this.theme.underline(linkText)) + this.getDefaultStylePrefix();
391
+ result +=
392
+ this.theme.link(this.theme.underline(linkText)) + this.inlineStyleEngine.getStylePrefix();
287
393
  }
288
394
  else {
289
395
  result +=
290
396
  this.theme.link(this.theme.underline(linkText)) +
291
397
  this.theme.linkUrl(` (${token.href})`) +
292
- this.getDefaultStylePrefix();
398
+ this.inlineStyleEngine.getStylePrefix();
293
399
  }
294
400
  break;
295
401
  }
@@ -297,234 +403,109 @@ export class Markdown extends ComponentBase {
297
403
  result += "\n";
298
404
  break;
299
405
  case "del": {
300
- const delContent = this.renderInlineTokens(token.tokens || []);
301
- result += this.theme.strikethrough(delContent) + this.getDefaultStylePrefix();
406
+ const deletedContent = this.renderInlineTokenList(token.tokens || []);
407
+ result += this.theme.strikethrough(deletedContent) + this.inlineStyleEngine.getStylePrefix();
302
408
  break;
303
409
  }
304
- case "html":
305
- // Render inline HTML as plain text
410
+ case "html": {
306
411
  if ("raw" in token && typeof token.raw === "string") {
307
- result += this.applyDefaultStyle(token.raw);
412
+ result += this.inlineStyleEngine.applyDefault(token.raw);
308
413
  }
309
414
  break;
310
- default:
311
- // Handle any other inline token types as plain text
415
+ }
416
+ default: {
312
417
  if ("text" in token && typeof token.text === "string") {
313
- result += this.applyDefaultStyle(token.text);
418
+ result += this.inlineStyleEngine.applyDefault(token.text);
314
419
  }
420
+ }
315
421
  }
316
422
  }
317
423
  return result;
318
424
  }
319
- /**
320
- * Render a list with proper nesting support
321
- */
322
- renderList(token, depth) {
323
- const lines = [];
324
- const indent = " ".repeat(depth);
325
- // Use the list's start property (defaults to 1 for ordered lists)
326
- const startNumber = token.start ?? 1;
327
- for (let i = 0; i < token.items.length; i++) {
328
- const item = token.items[i];
329
- const bullet = token.ordered ? `${startNumber + i}. ` : "- ";
330
- // Process item tokens to handle nested lists
331
- const itemLines = this.renderListItem(item.tokens || [], depth);
332
- if (itemLines.length > 0) {
333
- // First line - check if it's a nested list
334
- // A nested list will start with indent (spaces) followed by cyan bullet
335
- const firstLine = itemLines[0];
336
- const isNestedList = /^\s+\x1b\[36m[-\d]/.test(firstLine); // starts with spaces + cyan + bullet char
337
- if (isNestedList) {
338
- // This is a nested list, just add it as-is (already has full indent)
339
- lines.push(firstLine);
340
- }
341
- else {
342
- // Regular text content - add indent and bullet
343
- lines.push(indent + this.theme.listBullet(bullet) + firstLine);
344
- }
345
- // Rest of the lines
346
- for (let j = 1; j < itemLines.length; j++) {
347
- const line = itemLines[j];
348
- const isNestedListLine = /^\s+\x1b\[36m[-\d]/.test(line); // starts with spaces + cyan + bullet char
349
- if (isNestedListLine) {
350
- // Nested list line - already has full indent
351
- lines.push(line);
352
- }
353
- else {
354
- // Regular content - add parent indent + 2 spaces for continuation
355
- lines.push(`${indent} ${line}`);
356
- }
357
- }
358
- }
359
- else {
360
- lines.push(indent + this.theme.listBullet(bullet));
361
- }
425
+ finalizeLines(blockLines, width) {
426
+ const flowWrappedLines = [];
427
+ for (const line of blockLines) {
428
+ flowWrappedLines.push(...wrapTextWithAnsi(line, Math.max(1, width - this.paddingX * 2)));
362
429
  }
363
- return lines;
364
- }
365
- /**
366
- * Render list item tokens, handling nested lists
367
- * Returns lines WITHOUT the parent indent (renderList will add it)
368
- */
369
- renderListItem(tokens, parentDepth) {
370
- const lines = [];
371
- for (const token of tokens) {
372
- if (token.type === "list") {
373
- // Nested list - render with one additional indent level
374
- // These lines will have their own indent, so we just add them as-is
375
- const nestedLines = this.renderList(token, parentDepth + 1);
376
- lines.push(...nestedLines);
377
- }
378
- else if (token.type === "text") {
379
- // Text content (may have inline tokens)
380
- const text = token.tokens && token.tokens.length > 0 ? this.renderInlineTokens(token.tokens) : token.text || "";
381
- lines.push(text);
382
- }
383
- else if (token.type === "paragraph") {
384
- // Paragraph in list item
385
- const text = this.renderInlineTokens(token.tokens || []);
386
- lines.push(text);
387
- }
388
- else if (token.type === "code") {
389
- // Code block in list item
390
- const indent = this.theme.codeBlockIndent ?? " ";
391
- lines.push(this.theme.codeBlockBorder(`\`\`\`${token.lang || ""}`));
392
- if (this.theme.highlightCode) {
393
- const highlightedLines = this.theme.highlightCode(token.text, token.lang);
394
- for (const hlLine of highlightedLines) {
395
- lines.push(`${indent}${hlLine}`);
396
- }
397
- }
398
- else {
399
- const codeLines = token.text.split("\n");
400
- for (const codeLine of codeLines) {
401
- lines.push(`${indent}${this.theme.codeBlock(codeLine)}`);
402
- }
403
- }
404
- lines.push(this.theme.codeBlockBorder("```"));
430
+ const leftMargin = " ".repeat(this.paddingX);
431
+ const rightMargin = " ".repeat(this.paddingX);
432
+ const backgroundFn = this.defaultTextStyle?.bgColor;
433
+ const composedLines = [];
434
+ for (const line of flowWrappedLines) {
435
+ const withMargins = leftMargin + line + rightMargin;
436
+ if (backgroundFn) {
437
+ composedLines.push(applyBackgroundToLine(withMargins, width, backgroundFn));
405
438
  }
406
439
  else {
407
- // Other token types - try to render as inline
408
- const text = this.renderInlineTokens([token]);
409
- if (text) {
410
- lines.push(text);
411
- }
440
+ const visibleLen = visibleWidth(withMargins);
441
+ const trailingPadding = Math.max(0, width - visibleLen);
442
+ composedLines.push(withMargins + " ".repeat(trailingPadding));
412
443
  }
413
444
  }
414
- return lines;
445
+ const blankLine = " ".repeat(width);
446
+ const verticalPaddingLines = [];
447
+ for (let i = 0; i < this.paddingY; i++) {
448
+ verticalPaddingLines.push(backgroundFn ? applyBackgroundToLine(blankLine, width, backgroundFn) : blankLine);
449
+ }
450
+ return [...verticalPaddingLines, ...composedLines, ...verticalPaddingLines];
415
451
  }
416
- /**
417
- * Wrap a table cell to fit into a column.
418
- *
419
- * Delegates to wrapTextWithAnsi() so ANSI codes + long tokens are handled
420
- * consistently with the rest of the renderer.
421
- */
422
- wrapCellText(text, maxWidth) {
423
- return wrapTextWithAnsi(text, Math.max(1, maxWidth));
452
+ }
453
+ export class Markdown extends ComponentBase {
454
+ text;
455
+ paddingX;
456
+ paddingY;
457
+ defaultTextStyle;
458
+ theme;
459
+ cachedText;
460
+ cachedWidth;
461
+ cachedLines;
462
+ constructor(text, paddingX, paddingY, theme, defaultTextStyle) {
463
+ super();
464
+ this.text = text;
465
+ this.paddingX = paddingX;
466
+ this.paddingY = paddingY;
467
+ this.theme = theme;
468
+ this.defaultTextStyle = defaultTextStyle;
424
469
  }
425
- /**
426
- * Render a table with width-aware cell wrapping.
427
- * Cells that don't fit are wrapped to multiple lines.
428
- */
429
- renderTable(token, availableWidth) {
430
- const lines = [];
431
- const numCols = token.header.length;
432
- if (numCols === 0) {
433
- return lines;
434
- }
435
- // Calculate border overhead: "│ " + (n-1) * " │ " + " │"
436
- // = 2 + (n-1) * 3 + 2 = 3n + 1
437
- const borderOverhead = 3 * numCols + 1;
438
- // Minimum width for a bordered table with at least 1 char per column.
439
- const minTableWidth = borderOverhead + numCols;
440
- if (availableWidth < minTableWidth) {
441
- // Too narrow to render a stable table. Fall back to raw markdown.
442
- const fallbackLines = token.raw ? wrapTextWithAnsi(token.raw, availableWidth) : [];
443
- fallbackLines.push("");
444
- return fallbackLines;
445
- }
446
- // Calculate natural column widths (what each column needs without constraints)
447
- const naturalWidths = [];
448
- for (let i = 0; i < numCols; i++) {
449
- const headerText = this.renderInlineTokens(token.header[i].tokens || []);
450
- naturalWidths[i] = visibleWidth(headerText);
451
- }
452
- for (const row of token.rows) {
453
- for (let i = 0; i < row.length; i++) {
454
- const cellText = this.renderInlineTokens(row[i].tokens || []);
455
- naturalWidths[i] = Math.max(naturalWidths[i] || 0, visibleWidth(cellText));
456
- }
457
- }
458
- // Calculate column widths that fit within available width
459
- const totalNaturalWidth = naturalWidths.reduce((a, b) => a + b, 0) + borderOverhead;
460
- let columnWidths;
461
- if (totalNaturalWidth <= availableWidth) {
462
- // Everything fits naturally
463
- columnWidths = naturalWidths;
464
- }
465
- else {
466
- // Need to shrink columns to fit
467
- const availableForCells = availableWidth - borderOverhead;
468
- if (availableForCells <= numCols) {
469
- // Extremely narrow - give each column at least 1 char
470
- columnWidths = naturalWidths.map(() => Math.max(1, Math.floor(availableForCells / numCols)));
471
- }
472
- else {
473
- // Distribute space proportionally based on natural widths
474
- const totalNatural = naturalWidths.reduce((a, b) => a + b, 0);
475
- columnWidths = naturalWidths.map((w) => {
476
- const proportion = w / totalNatural;
477
- return Math.max(1, Math.floor(proportion * availableForCells));
478
- });
479
- // Adjust for rounding errors - distribute remaining space
480
- const allocated = columnWidths.reduce((a, b) => a + b, 0);
481
- let remaining = availableForCells - allocated;
482
- for (let i = 0; remaining > 0 && i < numCols; i++) {
483
- columnWidths[i]++;
484
- remaining--;
485
- }
486
- }
470
+ setText(text) {
471
+ this.text = text;
472
+ this.invalidate();
473
+ }
474
+ invalidate() {
475
+ super.invalidate();
476
+ this.cachedText = undefined;
477
+ this.cachedWidth = undefined;
478
+ this.cachedLines = undefined;
479
+ }
480
+ readCache(width) {
481
+ if (this.cachedLines && this.cachedText === this.text && this.cachedWidth === width) {
482
+ return this.cachedLines;
487
483
  }
488
- // Render top border
489
- const topBorderCells = columnWidths.map((w) => "─".repeat(w));
490
- lines.push(`┌─${topBorderCells.join("─┬─")}─┐`);
491
- // Render header with wrapping
492
- const headerCellLines = token.header.map((cell, i) => {
493
- const text = this.renderInlineTokens(cell.tokens || []);
494
- return this.wrapCellText(text, columnWidths[i]);
495
- });
496
- const headerLineCount = Math.max(...headerCellLines.map((c) => c.length));
497
- for (let lineIdx = 0; lineIdx < headerLineCount; lineIdx++) {
498
- const rowParts = headerCellLines.map((cellLines, colIdx) => {
499
- const text = cellLines[lineIdx] || "";
500
- const padded = text + " ".repeat(Math.max(0, columnWidths[colIdx] - visibleWidth(text)));
501
- return this.theme.bold(padded);
502
- });
503
- lines.push(`│ ${rowParts.join(" │ ")} │`);
484
+ return undefined;
485
+ }
486
+ updateCache(width, lines) {
487
+ this.cachedText = this.text;
488
+ this.cachedWidth = width;
489
+ this.cachedLines = lines;
490
+ }
491
+ render(width) {
492
+ const cacheHit = this.readCache(width);
493
+ if (cacheHit) {
494
+ return cacheHit;
504
495
  }
505
- // Render separator
506
- const separatorCells = columnWidths.map((w) => "─".repeat(w));
507
- lines.push(`├─${separatorCells.join("─┼─")}─┤`);
508
- // Render rows with wrapping
509
- for (const row of token.rows) {
510
- const rowCellLines = row.map((cell, i) => {
511
- const text = this.renderInlineTokens(cell.tokens || []);
512
- return this.wrapCellText(text, columnWidths[i]);
513
- });
514
- const rowLineCount = Math.max(...rowCellLines.map((c) => c.length));
515
- for (let lineIdx = 0; lineIdx < rowLineCount; lineIdx++) {
516
- const rowParts = rowCellLines.map((cellLines, colIdx) => {
517
- const text = cellLines[lineIdx] || "";
518
- return text + " ".repeat(Math.max(0, columnWidths[colIdx] - visibleWidth(text)));
519
- });
520
- lines.push(`│ ${rowParts.join(" │ ")} │`);
521
- }
496
+ if (!this.text || this.text.trim() === "") {
497
+ const emptyResult = [];
498
+ this.updateCache(width, emptyResult);
499
+ return emptyResult;
522
500
  }
523
- // Render bottom border
524
- const bottomBorderCells = columnWidths.map((w) => "".repeat(w));
525
- lines.push(`└─${bottomBorderCells.join("─┴─")}─┘`);
526
- lines.push(""); // Add spacing after table
527
- return lines;
501
+ const contentWidth = Math.max(1, width - this.paddingX * 2);
502
+ const normalizedText = this.text.replace(/\t/g, " ");
503
+ const tokens = marked.lexer(normalizedText);
504
+ const engine = new MarkdownRenderEngine(this.theme, this.defaultTextStyle, this.paddingX, this.paddingY);
505
+ const blockLines = engine.renderTokens(tokens, contentWidth);
506
+ const finalLines = engine.finalizeLines(blockLines, width);
507
+ this.updateCache(width, finalLines);
508
+ return finalLines.length > 0 ? finalLines : [""];
528
509
  }
529
510
  }
530
511
  //# sourceMappingURL=markdown.js.map