plugsuits 1.0.0

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 (560) hide show
  1. package/cli.js +3 -0
  2. package/dist/agent-reasoning-default.test.d.ts +2 -0
  3. package/dist/agent-reasoning-default.test.d.ts.map +1 -0
  4. package/dist/agent-reasoning-default.test.js +38 -0
  5. package/dist/agent-reasoning-default.test.js.map +1 -0
  6. package/dist/agent.d.ts +61 -0
  7. package/dist/agent.d.ts.map +1 -0
  8. package/dist/agent.js +308 -0
  9. package/dist/agent.js.map +1 -0
  10. package/dist/agent.test.d.ts +2 -0
  11. package/dist/agent.test.d.ts.map +1 -0
  12. package/dist/agent.test.js +38 -0
  13. package/dist/agent.test.js.map +1 -0
  14. package/dist/cli-args.d.ts +15 -0
  15. package/dist/cli-args.d.ts.map +1 -0
  16. package/dist/cli-args.js +63 -0
  17. package/dist/cli-args.js.map +1 -0
  18. package/dist/cli-args.test.d.ts +2 -0
  19. package/dist/cli-args.test.d.ts.map +1 -0
  20. package/dist/cli-args.test.js +105 -0
  21. package/dist/cli-args.test.js.map +1 -0
  22. package/dist/commands/aliases-and-tool-fallback.test.d.ts +2 -0
  23. package/dist/commands/aliases-and-tool-fallback.test.d.ts.map +1 -0
  24. package/dist/commands/aliases-and-tool-fallback.test.js +132 -0
  25. package/dist/commands/aliases-and-tool-fallback.test.js.map +1 -0
  26. package/dist/commands/clear.d.ts +3 -0
  27. package/dist/commands/clear.d.ts.map +1 -0
  28. package/dist/commands/clear.js +12 -0
  29. package/dist/commands/clear.js.map +1 -0
  30. package/dist/commands/factories/create-toggle-command.d.ts +13 -0
  31. package/dist/commands/factories/create-toggle-command.d.ts.map +1 -0
  32. package/dist/commands/factories/create-toggle-command.js +38 -0
  33. package/dist/commands/factories/create-toggle-command.js.map +1 -0
  34. package/dist/commands/help.d.ts +3 -0
  35. package/dist/commands/help.d.ts.map +1 -0
  36. package/dist/commands/help.js +23 -0
  37. package/dist/commands/help.js.map +1 -0
  38. package/dist/commands/index.d.ts +18 -0
  39. package/dist/commands/index.d.ts.map +1 -0
  40. package/dist/commands/index.js +82 -0
  41. package/dist/commands/index.js.map +1 -0
  42. package/dist/commands/model.d.ts +15 -0
  43. package/dist/commands/model.d.ts.map +1 -0
  44. package/dist/commands/model.js +100 -0
  45. package/dist/commands/model.js.map +1 -0
  46. package/dist/commands/reasoning-mode.d.ts +3 -0
  47. package/dist/commands/reasoning-mode.d.ts.map +1 -0
  48. package/dist/commands/reasoning-mode.js +47 -0
  49. package/dist/commands/reasoning-mode.js.map +1 -0
  50. package/dist/commands/render.d.ts +19 -0
  51. package/dist/commands/render.d.ts.map +1 -0
  52. package/dist/commands/render.js +140 -0
  53. package/dist/commands/render.js.map +1 -0
  54. package/dist/commands/render.test.d.ts +2 -0
  55. package/dist/commands/render.test.d.ts.map +1 -0
  56. package/dist/commands/render.test.js +36 -0
  57. package/dist/commands/render.test.js.map +1 -0
  58. package/dist/commands/tool-fallback.d.ts +3 -0
  59. package/dist/commands/tool-fallback.d.ts.map +1 -0
  60. package/dist/commands/tool-fallback.js +38 -0
  61. package/dist/commands/tool-fallback.js.map +1 -0
  62. package/dist/commands/translate.d.ts +3 -0
  63. package/dist/commands/translate.d.ts.map +1 -0
  64. package/dist/commands/translate.js +12 -0
  65. package/dist/commands/translate.js.map +1 -0
  66. package/dist/commands/translate.test.d.ts +2 -0
  67. package/dist/commands/translate.test.d.ts.map +1 -0
  68. package/dist/commands/translate.test.js +49 -0
  69. package/dist/commands/translate.test.js.map +1 -0
  70. package/dist/commands/types.d.ts +17 -0
  71. package/dist/commands/types.d.ts.map +1 -0
  72. package/dist/commands/types.js +2 -0
  73. package/dist/commands/types.js.map +1 -0
  74. package/dist/context/environment-context.d.ts +2 -0
  75. package/dist/context/environment-context.d.ts.map +1 -0
  76. package/dist/context/environment-context.js +11 -0
  77. package/dist/context/environment-context.js.map +1 -0
  78. package/dist/context/paths.d.ts +3 -0
  79. package/dist/context/paths.d.ts.map +1 -0
  80. package/dist/context/paths.js +3 -0
  81. package/dist/context/paths.js.map +1 -0
  82. package/dist/context/session.d.ts +4 -0
  83. package/dist/context/session.d.ts.map +1 -0
  84. package/dist/context/session.js +16 -0
  85. package/dist/context/session.js.map +1 -0
  86. package/dist/context/skill-command-prefix.d.ts +4 -0
  87. package/dist/context/skill-command-prefix.d.ts.map +1 -0
  88. package/dist/context/skill-command-prefix.js +15 -0
  89. package/dist/context/skill-command-prefix.js.map +1 -0
  90. package/dist/context/skills-integration.test.d.ts +2 -0
  91. package/dist/context/skills-integration.test.d.ts.map +1 -0
  92. package/dist/context/skills-integration.test.js +87 -0
  93. package/dist/context/skills-integration.test.js.map +1 -0
  94. package/dist/context/skills.d.ts +18 -0
  95. package/dist/context/skills.d.ts.map +1 -0
  96. package/dist/context/skills.js +431 -0
  97. package/dist/context/skills.js.map +1 -0
  98. package/dist/context/skills.test.d.ts +2 -0
  99. package/dist/context/skills.test.d.ts.map +1 -0
  100. package/dist/context/skills.test.js +20 -0
  101. package/dist/context/skills.test.js.map +1 -0
  102. package/dist/context/system-prompt.d.ts +2 -0
  103. package/dist/context/system-prompt.d.ts.map +1 -0
  104. package/dist/context/system-prompt.js +100 -0
  105. package/dist/context/system-prompt.js.map +1 -0
  106. package/dist/context/translation-integration.test.d.ts +2 -0
  107. package/dist/context/translation-integration.test.d.ts.map +1 -0
  108. package/dist/context/translation-integration.test.js +138 -0
  109. package/dist/context/translation-integration.test.js.map +1 -0
  110. package/dist/context/translation.d.ts +21 -0
  111. package/dist/context/translation.d.ts.map +1 -0
  112. package/dist/context/translation.js +82 -0
  113. package/dist/context/translation.js.map +1 -0
  114. package/dist/context/translation.test.d.ts +2 -0
  115. package/dist/context/translation.test.d.ts.map +1 -0
  116. package/dist/context/translation.test.js +129 -0
  117. package/dist/context/translation.test.js.map +1 -0
  118. package/dist/entrypoints/cli-input-rendering.test.d.ts +2 -0
  119. package/dist/entrypoints/cli-input-rendering.test.d.ts.map +1 -0
  120. package/dist/entrypoints/cli-input-rendering.test.js +192 -0
  121. package/dist/entrypoints/cli-input-rendering.test.js.map +1 -0
  122. package/dist/entrypoints/cli.d.ts +3 -0
  123. package/dist/entrypoints/cli.d.ts.map +1 -0
  124. package/dist/entrypoints/cli.js +1268 -0
  125. package/dist/entrypoints/cli.js.map +1 -0
  126. package/dist/entrypoints/headless-agent-config.d.ts +21 -0
  127. package/dist/entrypoints/headless-agent-config.d.ts.map +1 -0
  128. package/dist/entrypoints/headless-agent-config.js +15 -0
  129. package/dist/entrypoints/headless-agent-config.js.map +1 -0
  130. package/dist/entrypoints/headless-agent-config.test.d.ts +2 -0
  131. package/dist/entrypoints/headless-agent-config.test.d.ts.map +1 -0
  132. package/dist/entrypoints/headless-agent-config.test.js +63 -0
  133. package/dist/entrypoints/headless-agent-config.test.js.map +1 -0
  134. package/dist/entrypoints/headless.d.ts +3 -0
  135. package/dist/entrypoints/headless.d.ts.map +1 -0
  136. package/dist/entrypoints/headless.js +396 -0
  137. package/dist/entrypoints/headless.js.map +1 -0
  138. package/dist/env.d.ts +8 -0
  139. package/dist/env.d.ts.map +1 -0
  140. package/dist/env.js +14 -0
  141. package/dist/env.js.map +1 -0
  142. package/dist/friendli-models.d.ts +21 -0
  143. package/dist/friendli-models.d.ts.map +1 -0
  144. package/dist/friendli-models.js +57 -0
  145. package/dist/friendli-models.js.map +1 -0
  146. package/dist/friendli-reasoning.d.ts +10 -0
  147. package/dist/friendli-reasoning.d.ts.map +1 -0
  148. package/dist/friendli-reasoning.js +181 -0
  149. package/dist/friendli-reasoning.js.map +1 -0
  150. package/dist/friendli-reasoning.test.d.ts +2 -0
  151. package/dist/friendli-reasoning.test.d.ts.map +1 -0
  152. package/dist/friendli-reasoning.test.js +77 -0
  153. package/dist/friendli-reasoning.test.js.map +1 -0
  154. package/dist/index.d.ts +3 -0
  155. package/dist/index.d.ts.map +1 -0
  156. package/dist/index.js +3 -0
  157. package/dist/index.js.map +1 -0
  158. package/dist/interaction/colors.d.ts +22 -0
  159. package/dist/interaction/colors.d.ts.map +1 -0
  160. package/dist/interaction/colors.js +24 -0
  161. package/dist/interaction/colors.js.map +1 -0
  162. package/dist/interaction/pi-tui-stream-renderer.d.ts +19 -0
  163. package/dist/interaction/pi-tui-stream-renderer.d.ts.map +1 -0
  164. package/dist/interaction/pi-tui-stream-renderer.js +1509 -0
  165. package/dist/interaction/pi-tui-stream-renderer.js.map +1 -0
  166. package/dist/interaction/pi-tui-stream-renderer.test.d.ts +2 -0
  167. package/dist/interaction/pi-tui-stream-renderer.test.d.ts.map +1 -0
  168. package/dist/interaction/pi-tui-stream-renderer.test.js +1314 -0
  169. package/dist/interaction/pi-tui-stream-renderer.test.js.map +1 -0
  170. package/dist/interaction/spinner.d.ts +13 -0
  171. package/dist/interaction/spinner.d.ts.map +1 -0
  172. package/dist/interaction/spinner.js +51 -0
  173. package/dist/interaction/spinner.js.map +1 -0
  174. package/dist/middleware/index.d.ts +7 -0
  175. package/dist/middleware/index.d.ts.map +1 -0
  176. package/dist/middleware/index.js +15 -0
  177. package/dist/middleware/index.js.map +1 -0
  178. package/dist/middleware/todo-continuation.d.ts +11 -0
  179. package/dist/middleware/todo-continuation.d.ts.map +1 -0
  180. package/dist/middleware/todo-continuation.js +103 -0
  181. package/dist/middleware/todo-continuation.js.map +1 -0
  182. package/dist/middleware/trim-leading-newlines.d.ts +3 -0
  183. package/dist/middleware/trim-leading-newlines.d.ts.map +1 -0
  184. package/dist/middleware/trim-leading-newlines.js +49 -0
  185. package/dist/middleware/trim-leading-newlines.js.map +1 -0
  186. package/dist/reasoning-mode.d.ts +5 -0
  187. package/dist/reasoning-mode.d.ts.map +1 -0
  188. package/dist/reasoning-mode.js +30 -0
  189. package/dist/reasoning-mode.js.map +1 -0
  190. package/dist/reasoning-mode.test.d.ts +2 -0
  191. package/dist/reasoning-mode.test.d.ts.map +1 -0
  192. package/dist/reasoning-mode.test.js +22 -0
  193. package/dist/reasoning-mode.test.js.map +1 -0
  194. package/dist/tool-fallback-mode.d.ts +6 -0
  195. package/dist/tool-fallback-mode.d.ts.map +1 -0
  196. package/dist/tool-fallback-mode.js +25 -0
  197. package/dist/tool-fallback-mode.js.map +1 -0
  198. package/dist/tools/execute/shell-execute.d.ts +17 -0
  199. package/dist/tools/execute/shell-execute.d.ts.map +1 -0
  200. package/dist/tools/execute/shell-execute.js +55 -0
  201. package/dist/tools/execute/shell-execute.js.map +1 -0
  202. package/dist/tools/execute/shell-execute.test.d.ts +2 -0
  203. package/dist/tools/execute/shell-execute.test.d.ts.map +1 -0
  204. package/dist/tools/execute/shell-execute.test.js +86 -0
  205. package/dist/tools/execute/shell-execute.test.js.map +1 -0
  206. package/dist/tools/execute/shell-interact.d.ts +10 -0
  207. package/dist/tools/execute/shell-interact.d.ts.map +1 -0
  208. package/dist/tools/execute/shell-interact.js +122 -0
  209. package/dist/tools/execute/shell-interact.js.map +1 -0
  210. package/dist/tools/execute/shell-interact.test.d.ts +2 -0
  211. package/dist/tools/execute/shell-interact.test.d.ts.map +1 -0
  212. package/dist/tools/execute/shell-interact.test.js +175 -0
  213. package/dist/tools/execute/shell-interact.test.js.map +1 -0
  214. package/dist/tools/explore/glob.d.ts +15 -0
  215. package/dist/tools/explore/glob.d.ts.map +1 -0
  216. package/dist/tools/explore/glob.js +107 -0
  217. package/dist/tools/explore/glob.js.map +1 -0
  218. package/dist/tools/explore/glob.test.d.ts +2 -0
  219. package/dist/tools/explore/glob.test.d.ts.map +1 -0
  220. package/dist/tools/explore/glob.test.js +183 -0
  221. package/dist/tools/explore/glob.test.js.map +1 -0
  222. package/dist/tools/explore/grep.d.ts +27 -0
  223. package/dist/tools/explore/grep.d.ts.map +1 -0
  224. package/dist/tools/explore/grep.js +203 -0
  225. package/dist/tools/explore/grep.js.map +1 -0
  226. package/dist/tools/explore/grep.test.d.ts +2 -0
  227. package/dist/tools/explore/grep.test.d.ts.map +1 -0
  228. package/dist/tools/explore/grep.test.js +132 -0
  229. package/dist/tools/explore/grep.test.js.map +1 -0
  230. package/dist/tools/explore/read-file.d.ts +23 -0
  231. package/dist/tools/explore/read-file.d.ts.map +1 -0
  232. package/dist/tools/explore/read-file.js +84 -0
  233. package/dist/tools/explore/read-file.js.map +1 -0
  234. package/dist/tools/explore/read-file.test.d.ts +2 -0
  235. package/dist/tools/explore/read-file.test.d.ts.map +1 -0
  236. package/dist/tools/explore/read-file.test.js +278 -0
  237. package/dist/tools/explore/read-file.test.js.map +1 -0
  238. package/dist/tools/index.d.ts +71 -0
  239. package/dist/tools/index.d.ts.map +1 -0
  240. package/dist/tools/index.js +26 -0
  241. package/dist/tools/index.js.map +1 -0
  242. package/dist/tools/modify/delete-file.d.ts +19 -0
  243. package/dist/tools/modify/delete-file.d.ts.map +1 -0
  244. package/dist/tools/modify/delete-file.js +71 -0
  245. package/dist/tools/modify/delete-file.js.map +1 -0
  246. package/dist/tools/modify/delete-file.test.d.ts +2 -0
  247. package/dist/tools/modify/delete-file.test.d.ts.map +1 -0
  248. package/dist/tools/modify/delete-file.test.js +136 -0
  249. package/dist/tools/modify/delete-file.test.js.map +1 -0
  250. package/dist/tools/modify/edit-file-diagnostics.d.ts +17 -0
  251. package/dist/tools/modify/edit-file-diagnostics.d.ts.map +1 -0
  252. package/dist/tools/modify/edit-file-diagnostics.js +157 -0
  253. package/dist/tools/modify/edit-file-diagnostics.js.map +1 -0
  254. package/dist/tools/modify/edit-file-repair.d.ts +13 -0
  255. package/dist/tools/modify/edit-file-repair.d.ts.map +1 -0
  256. package/dist/tools/modify/edit-file-repair.js +135 -0
  257. package/dist/tools/modify/edit-file-repair.js.map +1 -0
  258. package/dist/tools/modify/edit-file-stress.test.d.ts +2 -0
  259. package/dist/tools/modify/edit-file-stress.test.d.ts.map +1 -0
  260. package/dist/tools/modify/edit-file-stress.test.js +163 -0
  261. package/dist/tools/modify/edit-file-stress.test.js.map +1 -0
  262. package/dist/tools/modify/edit-file-validation.d.ts +9 -0
  263. package/dist/tools/modify/edit-file-validation.d.ts.map +1 -0
  264. package/dist/tools/modify/edit-file-validation.js +86 -0
  265. package/dist/tools/modify/edit-file-validation.js.map +1 -0
  266. package/dist/tools/modify/edit-file-whitespace.test.d.ts +2 -0
  267. package/dist/tools/modify/edit-file-whitespace.test.d.ts.map +1 -0
  268. package/dist/tools/modify/edit-file-whitespace.test.js +90 -0
  269. package/dist/tools/modify/edit-file-whitespace.test.js.map +1 -0
  270. package/dist/tools/modify/edit-file.d.ts +33 -0
  271. package/dist/tools/modify/edit-file.d.ts.map +1 -0
  272. package/dist/tools/modify/edit-file.js +177 -0
  273. package/dist/tools/modify/edit-file.js.map +1 -0
  274. package/dist/tools/modify/edit-file.test.d.ts +2 -0
  275. package/dist/tools/modify/edit-file.test.d.ts.map +1 -0
  276. package/dist/tools/modify/edit-file.test.js +948 -0
  277. package/dist/tools/modify/edit-file.test.js.map +1 -0
  278. package/dist/tools/modify/write-file.d.ts +17 -0
  279. package/dist/tools/modify/write-file.d.ts.map +1 -0
  280. package/dist/tools/modify/write-file.js +39 -0
  281. package/dist/tools/modify/write-file.js.map +1 -0
  282. package/dist/tools/modify/write-file.test.d.ts +2 -0
  283. package/dist/tools/modify/write-file.test.d.ts.map +1 -0
  284. package/dist/tools/modify/write-file.test.js +168 -0
  285. package/dist/tools/modify/write-file.test.js.map +1 -0
  286. package/dist/tools/planning/load-skill.d.ts +13 -0
  287. package/dist/tools/planning/load-skill.d.ts.map +1 -0
  288. package/dist/tools/planning/load-skill.js +101 -0
  289. package/dist/tools/planning/load-skill.js.map +1 -0
  290. package/dist/tools/planning/load-skill.test.d.ts +2 -0
  291. package/dist/tools/planning/load-skill.test.d.ts.map +1 -0
  292. package/dist/tools/planning/load-skill.test.js +37 -0
  293. package/dist/tools/planning/load-skill.test.js.map +1 -0
  294. package/dist/tools/planning/todo-write.d.ts +49 -0
  295. package/dist/tools/planning/todo-write.d.ts.map +1 -0
  296. package/dist/tools/planning/todo-write.js +118 -0
  297. package/dist/tools/planning/todo-write.js.map +1 -0
  298. package/dist/tools/planning/todo-write.test.d.ts +2 -0
  299. package/dist/tools/planning/todo-write.test.d.ts.map +1 -0
  300. package/dist/tools/planning/todo-write.test.js +82 -0
  301. package/dist/tools/planning/todo-write.test.js.map +1 -0
  302. package/dist/tools/utils/execute/format-utils.d.ts +4 -0
  303. package/dist/tools/utils/execute/format-utils.d.ts.map +1 -0
  304. package/dist/tools/utils/execute/format-utils.js +31 -0
  305. package/dist/tools/utils/execute/format-utils.js.map +1 -0
  306. package/dist/tools/utils/execute/format-utils.test.d.ts +2 -0
  307. package/dist/tools/utils/execute/format-utils.test.d.ts.map +1 -0
  308. package/dist/tools/utils/execute/format-utils.test.js +40 -0
  309. package/dist/tools/utils/execute/format-utils.test.js.map +1 -0
  310. package/dist/tools/utils/execute/noninteractive-wrapper.d.ts +12 -0
  311. package/dist/tools/utils/execute/noninteractive-wrapper.d.ts.map +1 -0
  312. package/dist/tools/utils/execute/noninteractive-wrapper.js +269 -0
  313. package/dist/tools/utils/execute/noninteractive-wrapper.js.map +1 -0
  314. package/dist/tools/utils/execute/noninteractive-wrapper.test.d.ts +2 -0
  315. package/dist/tools/utils/execute/noninteractive-wrapper.test.d.ts.map +1 -0
  316. package/dist/tools/utils/execute/noninteractive-wrapper.test.js +233 -0
  317. package/dist/tools/utils/execute/noninteractive-wrapper.test.js.map +1 -0
  318. package/dist/tools/utils/execute/output-handler.d.ts +14 -0
  319. package/dist/tools/utils/execute/output-handler.d.ts.map +1 -0
  320. package/dist/tools/utils/execute/output-handler.js +71 -0
  321. package/dist/tools/utils/execute/output-handler.js.map +1 -0
  322. package/dist/tools/utils/execute/output-handler.test.d.ts +2 -0
  323. package/dist/tools/utils/execute/output-handler.test.d.ts.map +1 -0
  324. package/dist/tools/utils/execute/output-handler.test.js +58 -0
  325. package/dist/tools/utils/execute/output-handler.test.js.map +1 -0
  326. package/dist/tools/utils/execute/process-manager.d.ts +17 -0
  327. package/dist/tools/utils/execute/process-manager.d.ts.map +1 -0
  328. package/dist/tools/utils/execute/process-manager.js +229 -0
  329. package/dist/tools/utils/execute/process-manager.js.map +1 -0
  330. package/dist/tools/utils/execute/process-manager.test.d.ts +2 -0
  331. package/dist/tools/utils/execute/process-manager.test.d.ts.map +1 -0
  332. package/dist/tools/utils/execute/process-manager.test.js +139 -0
  333. package/dist/tools/utils/execute/process-manager.test.js.map +1 -0
  334. package/dist/tools/utils/execute/shell-detection.d.ts +3 -0
  335. package/dist/tools/utils/execute/shell-detection.d.ts.map +1 -0
  336. package/dist/tools/utils/execute/shell-detection.js +56 -0
  337. package/dist/tools/utils/execute/shell-detection.js.map +1 -0
  338. package/dist/tools/utils/execute/shell-detection.test.d.ts +2 -0
  339. package/dist/tools/utils/execute/shell-detection.test.d.ts.map +1 -0
  340. package/dist/tools/utils/execute/shell-detection.test.js +86 -0
  341. package/dist/tools/utils/execute/shell-detection.test.js.map +1 -0
  342. package/dist/tools/utils/hashline/autocorrect-replacement-lines.d.ts +5 -0
  343. package/dist/tools/utils/hashline/autocorrect-replacement-lines.d.ts.map +1 -0
  344. package/dist/tools/utils/hashline/autocorrect-replacement-lines.js +113 -0
  345. package/dist/tools/utils/hashline/autocorrect-replacement-lines.js.map +1 -0
  346. package/dist/tools/utils/hashline/constants.d.ts +5 -0
  347. package/dist/tools/utils/hashline/constants.d.ts.map +1 -0
  348. package/dist/tools/utils/hashline/constants.js +11 -0
  349. package/dist/tools/utils/hashline/constants.js.map +1 -0
  350. package/dist/tools/utils/hashline/diff-utils.d.ts +7 -0
  351. package/dist/tools/utils/hashline/diff-utils.d.ts.map +1 -0
  352. package/dist/tools/utils/hashline/diff-utils.js +50 -0
  353. package/dist/tools/utils/hashline/diff-utils.js.map +1 -0
  354. package/dist/tools/utils/hashline/diff-utils.test.d.ts +2 -0
  355. package/dist/tools/utils/hashline/diff-utils.test.d.ts.map +1 -0
  356. package/dist/tools/utils/hashline/diff-utils.test.js +46 -0
  357. package/dist/tools/utils/hashline/diff-utils.test.js.map +1 -0
  358. package/dist/tools/utils/hashline/edit-deduplication.d.ts +6 -0
  359. package/dist/tools/utils/hashline/edit-deduplication.d.ts.map +1 -0
  360. package/dist/tools/utils/hashline/edit-deduplication.js +32 -0
  361. package/dist/tools/utils/hashline/edit-deduplication.js.map +1 -0
  362. package/dist/tools/utils/hashline/edit-operation-primitives.d.ts +11 -0
  363. package/dist/tools/utils/hashline/edit-operation-primitives.d.ts.map +1 -0
  364. package/dist/tools/utils/hashline/edit-operation-primitives.js +93 -0
  365. package/dist/tools/utils/hashline/edit-operation-primitives.js.map +1 -0
  366. package/dist/tools/utils/hashline/edit-operations.d.ts +9 -0
  367. package/dist/tools/utils/hashline/edit-operations.d.ts.map +1 -0
  368. package/dist/tools/utils/hashline/edit-operations.js +101 -0
  369. package/dist/tools/utils/hashline/edit-operations.js.map +1 -0
  370. package/dist/tools/utils/hashline/edit-operations.test.d.ts +2 -0
  371. package/dist/tools/utils/hashline/edit-operations.test.d.ts.map +1 -0
  372. package/dist/tools/utils/hashline/edit-operations.test.js +135 -0
  373. package/dist/tools/utils/hashline/edit-operations.test.js.map +1 -0
  374. package/dist/tools/utils/hashline/edit-ordering.d.ts +5 -0
  375. package/dist/tools/utils/hashline/edit-ordering.d.ts.map +1 -0
  376. package/dist/tools/utils/hashline/edit-ordering.js +54 -0
  377. package/dist/tools/utils/hashline/edit-ordering.js.map +1 -0
  378. package/dist/tools/utils/hashline/edit-text-normalization.d.ts +9 -0
  379. package/dist/tools/utils/hashline/edit-text-normalization.d.ts.map +1 -0
  380. package/dist/tools/utils/hashline/edit-text-normalization.js +135 -0
  381. package/dist/tools/utils/hashline/edit-text-normalization.js.map +1 -0
  382. package/dist/tools/utils/hashline/file-text-canonicalization.d.ts +8 -0
  383. package/dist/tools/utils/hashline/file-text-canonicalization.d.ts.map +1 -0
  384. package/dist/tools/utils/hashline/file-text-canonicalization.js +42 -0
  385. package/dist/tools/utils/hashline/file-text-canonicalization.js.map +1 -0
  386. package/dist/tools/utils/hashline/hash-computation.d.ts +14 -0
  387. package/dist/tools/utils/hashline/hash-computation.d.ts.map +1 -0
  388. package/dist/tools/utils/hashline/hash-computation.js +158 -0
  389. package/dist/tools/utils/hashline/hash-computation.js.map +1 -0
  390. package/dist/tools/utils/hashline/hash-computation.test.d.ts +2 -0
  391. package/dist/tools/utils/hashline/hash-computation.test.d.ts.map +1 -0
  392. package/dist/tools/utils/hashline/hash-computation.test.js +63 -0
  393. package/dist/tools/utils/hashline/hash-computation.test.js.map +1 -0
  394. package/dist/tools/utils/hashline/hashline-chunk-formatter.d.ts +11 -0
  395. package/dist/tools/utils/hashline/hashline-chunk-formatter.d.ts.map +1 -0
  396. package/dist/tools/utils/hashline/hashline-chunk-formatter.js +41 -0
  397. package/dist/tools/utils/hashline/hashline-chunk-formatter.js.map +1 -0
  398. package/dist/tools/utils/hashline/hashline-edit-diff.d.ts +2 -0
  399. package/dist/tools/utils/hashline/hashline-edit-diff.d.ts.map +1 -0
  400. package/dist/tools/utils/hashline/hashline-edit-diff.js +27 -0
  401. package/dist/tools/utils/hashline/hashline-edit-diff.js.map +1 -0
  402. package/dist/tools/utils/hashline/index.d.ts +14 -0
  403. package/dist/tools/utils/hashline/index.d.ts.map +1 -0
  404. package/dist/tools/utils/hashline/index.js +11 -0
  405. package/dist/tools/utils/hashline/index.js.map +1 -0
  406. package/dist/tools/utils/hashline/merge-expansion.d.ts +4 -0
  407. package/dist/tools/utils/hashline/merge-expansion.d.ts.map +1 -0
  408. package/dist/tools/utils/hashline/merge-expansion.js +105 -0
  409. package/dist/tools/utils/hashline/merge-expansion.js.map +1 -0
  410. package/dist/tools/utils/hashline/normalize-edits.d.ts +11 -0
  411. package/dist/tools/utils/hashline/normalize-edits.d.ts.map +1 -0
  412. package/dist/tools/utils/hashline/normalize-edits.js +81 -0
  413. package/dist/tools/utils/hashline/normalize-edits.js.map +1 -0
  414. package/dist/tools/utils/hashline/types.d.ts +18 -0
  415. package/dist/tools/utils/hashline/types.d.ts.map +1 -0
  416. package/dist/tools/utils/hashline/types.js +2 -0
  417. package/dist/tools/utils/hashline/types.js.map +1 -0
  418. package/dist/tools/utils/hashline/validation.d.ts +19 -0
  419. package/dist/tools/utils/hashline/validation.d.ts.map +1 -0
  420. package/dist/tools/utils/hashline/validation.js +161 -0
  421. package/dist/tools/utils/hashline/validation.js.map +1 -0
  422. package/dist/tools/utils/hashline/validation.test.d.ts +2 -0
  423. package/dist/tools/utils/hashline/validation.test.d.ts.map +1 -0
  424. package/dist/tools/utils/hashline/validation.test.js +86 -0
  425. package/dist/tools/utils/hashline/validation.test.js.map +1 -0
  426. package/dist/tools/utils/safety-utils.d.ts +66 -0
  427. package/dist/tools/utils/safety-utils.d.ts.map +1 -0
  428. package/dist/tools/utils/safety-utils.js +681 -0
  429. package/dist/tools/utils/safety-utils.js.map +1 -0
  430. package/dist/utils/tools-manager.d.ts +16 -0
  431. package/dist/utils/tools-manager.d.ts.map +1 -0
  432. package/dist/utils/tools-manager.js +257 -0
  433. package/dist/utils/tools-manager.js.map +1 -0
  434. package/package.json +49 -0
  435. package/src/AGENTS.md +52 -0
  436. package/src/agent-reasoning-default.test.ts +48 -0
  437. package/src/agent.test.ts +49 -0
  438. package/src/agent.ts +455 -0
  439. package/src/cli-args.test.ts +152 -0
  440. package/src/cli-args.ts +90 -0
  441. package/src/commands/aliases-and-tool-fallback.test.ts +172 -0
  442. package/src/commands/clear.ts +14 -0
  443. package/src/commands/factories/create-toggle-command.ts +68 -0
  444. package/src/commands/help.ts +30 -0
  445. package/src/commands/index.ts +125 -0
  446. package/src/commands/model.ts +146 -0
  447. package/src/commands/reasoning-mode.ts +55 -0
  448. package/src/commands/render.test.ts +47 -0
  449. package/src/commands/render.ts +205 -0
  450. package/src/commands/tool-fallback.ts +47 -0
  451. package/src/commands/translate.test.ts +62 -0
  452. package/src/commands/translate.ts +14 -0
  453. package/src/commands/types.ts +18 -0
  454. package/src/context/environment-context.ts +11 -0
  455. package/src/context/paths.ts +2 -0
  456. package/src/context/session.ts +18 -0
  457. package/src/context/skill-command-prefix.ts +18 -0
  458. package/src/context/skills-integration.test.ts +113 -0
  459. package/src/context/skills.test.ts +25 -0
  460. package/src/context/skills.ts +566 -0
  461. package/src/context/system-prompt.ts +100 -0
  462. package/src/context/translation-integration.test.ts +194 -0
  463. package/src/context/translation.test.ts +186 -0
  464. package/src/context/translation.ts +122 -0
  465. package/src/entrypoints/AGENTS.md +33 -0
  466. package/src/entrypoints/cli-input-rendering.test.ts +236 -0
  467. package/src/entrypoints/cli.ts +1845 -0
  468. package/src/entrypoints/headless-agent-config.test.ts +82 -0
  469. package/src/entrypoints/headless-agent-config.ts +42 -0
  470. package/src/entrypoints/headless.ts +622 -0
  471. package/src/env.ts +14 -0
  472. package/src/friendli-models.ts +81 -0
  473. package/src/friendli-reasoning.test.ts +147 -0
  474. package/src/friendli-reasoning.ts +280 -0
  475. package/src/index.ts +3 -0
  476. package/src/interaction/colors.ts +24 -0
  477. package/src/interaction/pi-tui-stream-renderer.test.ts +1471 -0
  478. package/src/interaction/pi-tui-stream-renderer.ts +2150 -0
  479. package/src/interaction/spinner.ts +61 -0
  480. package/src/middleware/index.ts +32 -0
  481. package/src/middleware/todo-continuation.ts +128 -0
  482. package/src/middleware/trim-leading-newlines.ts +66 -0
  483. package/src/reasoning-mode.test.ts +24 -0
  484. package/src/reasoning-mode.ts +40 -0
  485. package/src/skills/example/SKILL.md +44 -0
  486. package/src/skills/example/references/api.md +37 -0
  487. package/src/skills/example/scripts/setup.sh +13 -0
  488. package/src/skills/git-workflow.md +405 -0
  489. package/src/tool-fallback-mode.ts +34 -0
  490. package/src/tools/AGENTS.md +44 -0
  491. package/src/tools/execute/shell-execute.test.ts +114 -0
  492. package/src/tools/execute/shell-execute.ts +74 -0
  493. package/src/tools/execute/shell-execute.txt +27 -0
  494. package/src/tools/execute/shell-interact.test.ts +236 -0
  495. package/src/tools/execute/shell-interact.ts +151 -0
  496. package/src/tools/execute/shell-interact.txt +15 -0
  497. package/src/tools/explore/glob-files.txt +8 -0
  498. package/src/tools/explore/glob.test.ts +217 -0
  499. package/src/tools/explore/glob.ts +137 -0
  500. package/src/tools/explore/grep-files.txt +12 -0
  501. package/src/tools/explore/grep.test.ts +183 -0
  502. package/src/tools/explore/grep.ts +266 -0
  503. package/src/tools/explore/read-file.test.ts +355 -0
  504. package/src/tools/explore/read-file.ts +102 -0
  505. package/src/tools/explore/read-file.txt +24 -0
  506. package/src/tools/index.ts +29 -0
  507. package/src/tools/modify/AGENTS.md +38 -0
  508. package/src/tools/modify/delete-file.test.ts +200 -0
  509. package/src/tools/modify/delete-file.ts +95 -0
  510. package/src/tools/modify/delete-file.txt +9 -0
  511. package/src/tools/modify/edit-file-diagnostics.ts +210 -0
  512. package/src/tools/modify/edit-file-repair.ts +183 -0
  513. package/src/tools/modify/edit-file-stress.test.ts +200 -0
  514. package/src/tools/modify/edit-file-validation.ts +134 -0
  515. package/src/tools/modify/edit-file-whitespace.test.ts +117 -0
  516. package/src/tools/modify/edit-file.test.ts +1231 -0
  517. package/src/tools/modify/edit-file.ts +252 -0
  518. package/src/tools/modify/edit-file.txt +73 -0
  519. package/src/tools/modify/write-file.test.ts +240 -0
  520. package/src/tools/modify/write-file.ts +56 -0
  521. package/src/tools/modify/write-file.txt +9 -0
  522. package/src/tools/planning/load-skill.test.ts +48 -0
  523. package/src/tools/planning/load-skill.ts +136 -0
  524. package/src/tools/planning/load-skill.txt +6 -0
  525. package/src/tools/planning/todo-write.test.ts +91 -0
  526. package/src/tools/planning/todo-write.ts +141 -0
  527. package/src/tools/planning/todo-write.txt +7 -0
  528. package/src/tools/utils/execute/format-utils.test.ts +53 -0
  529. package/src/tools/utils/execute/format-utils.ts +37 -0
  530. package/src/tools/utils/execute/noninteractive-wrapper.test.ts +306 -0
  531. package/src/tools/utils/execute/noninteractive-wrapper.ts +314 -0
  532. package/src/tools/utils/execute/output-handler.test.ts +72 -0
  533. package/src/tools/utils/execute/output-handler.ts +101 -0
  534. package/src/tools/utils/execute/process-manager.test.ts +175 -0
  535. package/src/tools/utils/execute/process-manager.ts +310 -0
  536. package/src/tools/utils/execute/shell-detection.test.ts +112 -0
  537. package/src/tools/utils/execute/shell-detection.ts +72 -0
  538. package/src/tools/utils/hashline/autocorrect-replacement-lines.ts +159 -0
  539. package/src/tools/utils/hashline/constants.ts +13 -0
  540. package/src/tools/utils/hashline/diff-utils.test.ts +61 -0
  541. package/src/tools/utils/hashline/diff-utils.ts +64 -0
  542. package/src/tools/utils/hashline/edit-deduplication.ts +40 -0
  543. package/src/tools/utils/hashline/edit-operation-primitives.ts +149 -0
  544. package/src/tools/utils/hashline/edit-operations.test.ts +154 -0
  545. package/src/tools/utils/hashline/edit-operations.ts +132 -0
  546. package/src/tools/utils/hashline/edit-ordering.ts +60 -0
  547. package/src/tools/utils/hashline/edit-text-normalization.ts +180 -0
  548. package/src/tools/utils/hashline/file-text-canonicalization.ts +58 -0
  549. package/src/tools/utils/hashline/hash-computation.test.ts +82 -0
  550. package/src/tools/utils/hashline/hash-computation.ts +199 -0
  551. package/src/tools/utils/hashline/hashline-chunk-formatter.ts +61 -0
  552. package/src/tools/utils/hashline/hashline-edit-diff.ts +35 -0
  553. package/src/tools/utils/hashline/index.ts +55 -0
  554. package/src/tools/utils/hashline/merge-expansion.ts +120 -0
  555. package/src/tools/utils/hashline/normalize-edits.ts +127 -0
  556. package/src/tools/utils/hashline/types.ts +20 -0
  557. package/src/tools/utils/hashline/validation.test.ts +109 -0
  558. package/src/tools/utils/hashline/validation.ts +212 -0
  559. package/src/tools/utils/safety-utils.ts +938 -0
  560. package/src/utils/tools-manager.ts +353 -0
@@ -0,0 +1,1471 @@
1
+ import { describe, expect, it } from "bun:test";
2
+ import { Container, type MarkdownTheme } from "@mariozechner/pi-tui";
3
+ import type { TextStreamPart, ToolSet } from "ai";
4
+ import { computeLineHash } from "../tools/utils/hashline";
5
+ import {
6
+ type PiTuiStreamRenderOptions,
7
+ renderFullStreamWithPiTui,
8
+ } from "./pi-tui-stream-renderer";
9
+
10
+ type TestStreamPart = TextStreamPart<ToolSet>;
11
+
12
+ const LARGE_BLANK_GAP_REGEX = /\n[ \t]*\n[ \t]*\n[ \t]*\n/;
13
+ const EXECUTING_SPINNER_TEXT_REGEX = /[-\\|/] Executing\.\./;
14
+ const tagGrepLine = (
15
+ path: string,
16
+ lineNumber: number,
17
+ content: string
18
+ ): string => {
19
+ return `${path}:${lineNumber}#${computeLineHash(lineNumber, content)}|${content}`;
20
+ };
21
+ const tagReadLine = (lineNumber: number, content: string): string => {
22
+ return `${lineNumber}#${computeLineHash(lineNumber, content)}|${content}`;
23
+ };
24
+ const markdownTheme: MarkdownTheme = {
25
+ heading: (text) => text,
26
+ link: (text) => text,
27
+ linkUrl: (text) => text,
28
+ code: (text) => text,
29
+ codeBlock: (text) => text,
30
+ codeBlockBorder: (text) => text,
31
+ quote: (text) => text,
32
+ quoteBorder: (text) => text,
33
+ hr: (text) => text,
34
+ listBullet: (text) => text,
35
+ bold: (text) => text,
36
+ italic: (text) => text,
37
+ strikethrough: (text) => text,
38
+ underline: (text) => text,
39
+ };
40
+
41
+ interface RenderResult {
42
+ output: string;
43
+ renderCalls: number;
44
+ snapshots: string[];
45
+ }
46
+
47
+ interface RenderPartsOptions {
48
+ onFirstVisiblePart?: () => void;
49
+ showRawToolIo?: boolean;
50
+ }
51
+
52
+ const renderParts = async (
53
+ parts: TestStreamPart[],
54
+ overrides: RenderPartsOptions = {}
55
+ ): Promise<RenderResult> => {
56
+ const chatContainer = new Container();
57
+ let renderCalls = 0;
58
+ const snapshots: string[] = [];
59
+
60
+ const options: PiTuiStreamRenderOptions = {
61
+ chatContainer,
62
+ markdownTheme,
63
+ onFirstVisiblePart: overrides.onFirstVisiblePart,
64
+ ui: {
65
+ requestRender: () => {
66
+ renderCalls += 1;
67
+ snapshots.push(chatContainer.render(120).join("\n"));
68
+ },
69
+ },
70
+ showReasoning: true,
71
+ showSteps: false,
72
+ showFinishReason: false,
73
+ showToolResults: true,
74
+ showRawToolIo: overrides.showRawToolIo,
75
+ showSources: false,
76
+ showFiles: false,
77
+ };
78
+
79
+ async function* stream(): AsyncIterable<TestStreamPart> {
80
+ for (const part of parts) {
81
+ await Promise.resolve();
82
+ yield part;
83
+ }
84
+ }
85
+
86
+ await renderFullStreamWithPiTui(stream(), options);
87
+ const output = chatContainer.render(120).join("\n");
88
+
89
+ return { output, renderCalls, snapshots };
90
+ };
91
+
92
+ describe("renderFullStreamWithPiTui", () => {
93
+ it("calls onFirstVisiblePart exactly once", async () => {
94
+ let calls = 0;
95
+
96
+ await renderParts(
97
+ [
98
+ { type: "start" } as never,
99
+ { type: "text-start", id: "text_1" },
100
+ { type: "text-delta", id: "text_1", text: "Hello" },
101
+ { type: "text-delta", id: "text_1", text: " world" },
102
+ { type: "text-end", id: "text_1" },
103
+ ],
104
+ {
105
+ onFirstVisiblePart: () => {
106
+ calls += 1;
107
+ },
108
+ }
109
+ );
110
+
111
+ expect(calls).toBe(1);
112
+ });
113
+
114
+ it("does not call onFirstVisiblePart for ignored-only stream", async () => {
115
+ let calls = 0;
116
+
117
+ await renderParts(
118
+ [
119
+ { type: "start" } as never,
120
+ { type: "text-end", id: "text_1" },
121
+ { type: "reasoning-end", id: "reason_1" } as never,
122
+ { type: "abort" } as never,
123
+ ],
124
+ {
125
+ onFirstVisiblePart: () => {
126
+ calls += 1;
127
+ },
128
+ }
129
+ );
130
+
131
+ expect(calls).toBe(0);
132
+ });
133
+
134
+ it("streams markdown text into assistant view", async () => {
135
+ const { output, renderCalls } = await renderParts([
136
+ { type: "text-start", id: "text_1" },
137
+ { type: "text-delta", id: "text_1", text: "Hello" },
138
+ { type: "text-delta", id: "text_1", text: " world" },
139
+ { type: "text-end", id: "text_1" },
140
+ ]);
141
+
142
+ expect(output).toContain("Hello world");
143
+ expect(renderCalls).toBeGreaterThan(0);
144
+ });
145
+
146
+ it("preserves stream order between reasoning and text blocks", async () => {
147
+ const { output } = await renderParts([
148
+ { type: "reasoning-start", id: "reason_1" } as never,
149
+ { type: "reasoning-delta", id: "reason_1", text: "First thought" },
150
+ { type: "reasoning-end", id: "reason_1" } as never,
151
+ { type: "text-start", id: "text_2" },
152
+ { type: "text-delta", id: "text_2", text: "Final answer" },
153
+ { type: "text-end", id: "text_2" },
154
+ ]);
155
+
156
+ const reasoningIndex = output.indexOf("First thought");
157
+ const textIndex = output.indexOf("Final answer");
158
+
159
+ expect(reasoningIndex).toBeGreaterThan(-1);
160
+ expect(textIndex).toBeGreaterThan(-1);
161
+ expect(reasoningIndex).toBeLessThan(textIndex);
162
+ });
163
+
164
+ it("applies Pi-like muted italic styling to reasoning text", async () => {
165
+ const { output } = await renderParts([
166
+ { type: "reasoning-start", id: "reason_2" } as never,
167
+ { type: "reasoning-delta", id: "reason_2", text: "styled reasoning" },
168
+ { type: "reasoning-end", id: "reason_2" } as never,
169
+ ]);
170
+
171
+ expect(output).toContain("styled reasoning");
172
+ expect(output).toContain("\x1b[2m\x1b[3m\x1b[90m");
173
+ });
174
+
175
+ it("removes leading newlines from reasoning display", async () => {
176
+ const { output } = await renderParts([
177
+ { type: "reasoning-start", id: "reason_trim" } as never,
178
+ {
179
+ type: "reasoning-delta",
180
+ id: "reason_trim",
181
+ text: "\n\nreasoning without top blank lines",
182
+ },
183
+ { type: "reasoning-end", id: "reason_trim" } as never,
184
+ ]);
185
+
186
+ expect(output).toContain("reasoning without top blank lines");
187
+ expect(output).not.toContain("\x1b[2m\x1b[3m\x1b[90m\n");
188
+ });
189
+
190
+ it("avoids large gap between tool output and following reasoning", async () => {
191
+ const { output } = await renderParts([
192
+ {
193
+ type: "tool-call",
194
+ toolCallId: "call_gap",
195
+ toolName: "bash",
196
+ input: {
197
+ command: "pwd",
198
+ },
199
+ },
200
+ {
201
+ type: "tool-result",
202
+ toolCallId: "call_gap",
203
+ toolName: "bash",
204
+ input: {
205
+ command: "pwd",
206
+ },
207
+ output: "tool output line\n\n\n",
208
+ },
209
+ { type: "reasoning-start", id: "reason_gap" } as never,
210
+ {
211
+ type: "reasoning-delta",
212
+ id: "reason_gap",
213
+ text: "After tool output",
214
+ },
215
+ { type: "reasoning-end", id: "reason_gap" } as never,
216
+ ]);
217
+
218
+ const plain = output;
219
+ const start = plain.indexOf("tool output line");
220
+ const end = plain.indexOf("After tool output");
221
+ expect(start).toBeGreaterThan(-1);
222
+ expect(end).toBeGreaterThan(start);
223
+
224
+ const between = plain.slice(start, end);
225
+ expect(between).not.toMatch(LARGE_BLANK_GAP_REGEX);
226
+
227
+ const lines = plain.split("\n");
228
+ const reasoningLineIndex = lines.findIndex((line) =>
229
+ line.includes("After tool output")
230
+ );
231
+ expect(reasoningLineIndex).toBeGreaterThan(-1);
232
+
233
+ let previousNonEmptyLineIndex = -1;
234
+ for (let i = reasoningLineIndex - 1; i >= 0; i -= 1) {
235
+ if (lines[i].trim().length > 0) {
236
+ previousNonEmptyLineIndex = i;
237
+ break;
238
+ }
239
+ }
240
+
241
+ expect(previousNonEmptyLineIndex).toBeGreaterThan(-1);
242
+ expect(reasoningLineIndex).toBe(previousNonEmptyLineIndex + 1);
243
+ });
244
+
245
+ it("renders live diff preview for edit_file tool input", async () => {
246
+ const { output } = await renderParts([
247
+ {
248
+ type: "tool-input-start",
249
+ id: "call_edit",
250
+ toolName: "edit_file",
251
+ },
252
+ {
253
+ type: "tool-input-delta",
254
+ id: "call_edit",
255
+ delta:
256
+ '{"path":"src/demo.ts","old_str":"const value = 1;","new_str":"const value = 2;"}',
257
+ },
258
+ { type: "tool-input-end", id: "call_edit" },
259
+ {
260
+ type: "tool-call",
261
+ toolCallId: "call_edit",
262
+ toolName: "edit_file",
263
+ input: {
264
+ path: "src/demo.ts",
265
+ old_str: "const value = 1;",
266
+ new_str: "const value = 2;",
267
+ },
268
+ },
269
+ ]);
270
+
271
+ expect(output).toContain("Live diff preview");
272
+ expect(output).toContain("-const value = 1;");
273
+ expect(output).toContain("+const value = 2;");
274
+ });
275
+
276
+ it("renders read_file output as structured markdown", async () => {
277
+ const readOutput = [
278
+ "OK - read file",
279
+ "path: src/demo.ts",
280
+ "bytes: 48",
281
+ "last_modified: 2026-01-19T03:33:57.520Z",
282
+ "lines: 5 (returned: 4)",
283
+ "range: L2-L5",
284
+ "truncated: true",
285
+ "",
286
+ "======== demo.ts L2-L5 ========",
287
+ " 2 | const value = 2;",
288
+ " 3 | export { value };",
289
+ " 4 | ```md",
290
+ " 5 | ![Image 1](./img.png)",
291
+ "======== end ========",
292
+ ].join("\n");
293
+
294
+ const { output } = await renderParts([
295
+ {
296
+ type: "tool-call",
297
+ toolCallId: "call_read",
298
+ toolName: "read_file",
299
+ input: {
300
+ path: "src/demo.ts",
301
+ },
302
+ },
303
+ {
304
+ type: "tool-result",
305
+ toolCallId: "call_read",
306
+ toolName: "read_file",
307
+ input: {
308
+ path: "src/demo.ts",
309
+ },
310
+ output: readOutput,
311
+ },
312
+ ]);
313
+
314
+ expect(output).toContain("Read src/demo.ts L2-L5");
315
+ expect(output).toContain("2 | ");
316
+ expect(output).toContain("const value = 2;");
317
+ expect(output).toContain("![Image 1](./img.png)");
318
+ expect(output).toContain("... (1 more line, truncated)");
319
+ expect(output).not.toContain("4 | ```md");
320
+ expect(output).not.toContain("```md");
321
+ expect(output).not.toContain("Tool read_file");
322
+ expect(output).not.toContain("Output");
323
+ expect(output).not.toContain("OK - read file");
324
+ });
325
+
326
+ it("normalizes split hashline read line fragments", async () => {
327
+ const lineContent = "const value = 2;";
328
+ const lineTag = tagReadLine(2, lineContent).split("|")[0];
329
+ const readOutput = [
330
+ "OK - read file",
331
+ "path: src/demo.ts",
332
+ "bytes: 48",
333
+ "last_modified: 2026-01-19T03:33:57.520Z",
334
+ "lines: 5 (returned: 1)",
335
+ "range: L2-L2",
336
+ "truncated: false",
337
+ "",
338
+ "======== demo.ts L2-L2 ========",
339
+ ` ${lineTag}`,
340
+ "|",
341
+ lineContent,
342
+ "======== end ========",
343
+ ].join("\n");
344
+
345
+ const { output } = await renderParts([
346
+ {
347
+ type: "tool-call",
348
+ toolCallId: "call_read_split",
349
+ toolName: "read_file",
350
+ input: {
351
+ path: "src/demo.ts",
352
+ },
353
+ },
354
+ {
355
+ type: "tool-result",
356
+ toolCallId: "call_read_split",
357
+ toolName: "read_file",
358
+ input: {
359
+ path: "src/demo.ts",
360
+ },
361
+ output: readOutput,
362
+ },
363
+ ]);
364
+
365
+ expect(output).toContain(tagReadLine(2, lineContent));
366
+ expect(output).not.toContain(` ${lineTag}\n|\n${lineContent}`);
367
+ });
368
+
369
+ it("preserves intentionally empty hashline lines", async () => {
370
+ const headingLine = "# Code Editing Agent";
371
+ const paragraphLine = "A code-editing agent built with Vercel AI SDK.";
372
+ const readOutput = [
373
+ "OK - read file",
374
+ "path: README.md",
375
+ "bytes: 120",
376
+ "last_modified: 2026-02-23T01:00:00.000Z",
377
+ "lines: 3 (returned: 3)",
378
+ "range: L1-L3",
379
+ "truncated: false",
380
+ "",
381
+ "======== README.md L1-L3 ========",
382
+ tagReadLine(1, headingLine),
383
+ tagReadLine(2, ""),
384
+ tagReadLine(3, paragraphLine),
385
+ "======== end ========",
386
+ ].join("\n");
387
+
388
+ const { output } = await renderParts([
389
+ {
390
+ type: "tool-call",
391
+ toolCallId: "call_read_empty_line",
392
+ toolName: "read_file",
393
+ input: {
394
+ path: "README.md",
395
+ },
396
+ },
397
+ {
398
+ type: "tool-result",
399
+ toolCallId: "call_read_empty_line",
400
+ toolName: "read_file",
401
+ input: {
402
+ path: "README.md",
403
+ },
404
+ output: readOutput,
405
+ },
406
+ ]);
407
+
408
+ expect(output).toContain(tagReadLine(2, ""));
409
+ expect(output).toContain(tagReadLine(3, paragraphLine));
410
+ expect(output).not.toContain(
411
+ `${tagReadLine(2, "")}${tagReadLine(3, paragraphLine)}`
412
+ );
413
+ });
414
+
415
+ it("omits read_file content after 10 lines", async () => {
416
+ const numberedLines = Array.from({ length: 12 }, (_, index) => {
417
+ const lineNumber = index + 1;
418
+ return `${lineNumber.toString().padStart(4, " ")} | line ${lineNumber}`;
419
+ });
420
+
421
+ const readOutput = [
422
+ "OK - read file",
423
+ "path: src/long.txt",
424
+ "bytes: 120",
425
+ "last_modified: 2026-02-23T01:00:00.000Z",
426
+ "lines: 12 (returned: 12)",
427
+ "range: L1-L12",
428
+ "truncated: false",
429
+ "",
430
+ "======== long.txt L1-L12 ========",
431
+ ...numberedLines,
432
+ "======== end ========",
433
+ ].join("\n");
434
+
435
+ const { output } = await renderParts([
436
+ {
437
+ type: "tool-call",
438
+ toolCallId: "call_long",
439
+ toolName: "read_file",
440
+ input: {
441
+ path: "src/long.txt",
442
+ },
443
+ },
444
+ {
445
+ type: "tool-result",
446
+ toolCallId: "call_long",
447
+ toolName: "read_file",
448
+ input: {
449
+ path: "src/long.txt",
450
+ },
451
+ output: readOutput,
452
+ },
453
+ ]);
454
+
455
+ expect(output).toContain("Read src/long.txt L1-L12");
456
+ expect(output).toContain("10 | line 10");
457
+ expect(output).not.toContain("11 | line 11");
458
+ expect(output).toContain("... (2 more lines)");
459
+ });
460
+
461
+ it("truncates long read_file lines instead of wrapping", async () => {
462
+ const longTail = "X".repeat(180);
463
+ const readOutput = [
464
+ "OK - read file",
465
+ "path: src/wrap.txt",
466
+ "bytes: 999",
467
+ "last_modified: 2026-02-23T01:00:00.000Z",
468
+ "lines: 1 (returned: 1)",
469
+ "range: L1-L1",
470
+ "truncated: false",
471
+ "",
472
+ "======== wrap.txt L1-L1 ========",
473
+ ` 1 | prefix ${longTail}`,
474
+ "======== end ========",
475
+ ].join("\n");
476
+
477
+ const { output } = await renderParts([
478
+ {
479
+ type: "tool-call",
480
+ toolCallId: "call_wrap",
481
+ toolName: "read_file",
482
+ input: {
483
+ path: "src/wrap.txt",
484
+ },
485
+ },
486
+ {
487
+ type: "tool-result",
488
+ toolCallId: "call_wrap",
489
+ toolName: "read_file",
490
+ input: {
491
+ path: "src/wrap.txt",
492
+ },
493
+ output: readOutput,
494
+ },
495
+ ]);
496
+
497
+ expect(output).toContain("Read src/wrap.txt L1-L1");
498
+ expect(output).toContain("1 | prefix");
499
+ expect(output).not.toContain(longTail);
500
+ });
501
+
502
+ it("does not duplicate tool call blocks when input was streamed", async () => {
503
+ const { output } = await renderParts([
504
+ {
505
+ type: "tool-input-start",
506
+ id: "call_1",
507
+ toolName: "write_file",
508
+ },
509
+ {
510
+ type: "tool-input-delta",
511
+ id: "call_1",
512
+ delta: '{"path":"src/file.ts","content":"hello"}',
513
+ },
514
+ { type: "tool-input-end", id: "call_1" },
515
+ {
516
+ type: "tool-call",
517
+ toolCallId: "call_1",
518
+ toolName: "write_file",
519
+ input: {
520
+ path: "src/file.ts",
521
+ content: "hello",
522
+ },
523
+ },
524
+ ]);
525
+
526
+ expect(output).toContain("Write src/file.ts");
527
+ expect((output.match(/Write src\/file\.ts/g) ?? []).length).toBe(1);
528
+ });
529
+
530
+ it("supports toolCallId and inputTextDelta aliases", async () => {
531
+ const { output } = await renderParts([
532
+ {
533
+ type: "tool-input-start",
534
+ toolCallId: "call_3",
535
+ toolName: "write_file",
536
+ } as never,
537
+ {
538
+ type: "tool-input-delta",
539
+ toolCallId: "call_3",
540
+ inputTextDelta: '{"path":"src/big.ts","content":"chunk"}',
541
+ } as never,
542
+ {
543
+ type: "tool-input-end",
544
+ toolCallId: "call_3",
545
+ } as never,
546
+ {
547
+ type: "tool-call",
548
+ toolCallId: "call_3",
549
+ toolName: "write_file",
550
+ input: {
551
+ path: "src/big.ts",
552
+ content: "chunk",
553
+ },
554
+ } as never,
555
+ ]);
556
+
557
+ expect(output).toContain("Write src/big.ts");
558
+ });
559
+
560
+ it("streams full write_file content without preview truncation", async () => {
561
+ const contentLines = Array.from(
562
+ { length: 12 },
563
+ (_, index) => `line ${index + 1}`
564
+ );
565
+ const streamedContent = contentLines.join("\n");
566
+ const escapedContent = contentLines.join("\\n");
567
+
568
+ const { output } = await renderParts([
569
+ {
570
+ type: "tool-input-start",
571
+ id: "call_write_stream_full",
572
+ toolName: "write_file",
573
+ },
574
+ {
575
+ type: "tool-input-delta",
576
+ id: "call_write_stream_full",
577
+ delta: `{"path":"src/full-stream.ts","content":"${escapedContent}`,
578
+ },
579
+ {
580
+ type: "tool-input-delta",
581
+ id: "call_write_stream_full",
582
+ delta: '"}',
583
+ },
584
+ { type: "tool-input-end", id: "call_write_stream_full" },
585
+ {
586
+ type: "tool-call",
587
+ toolCallId: "call_write_stream_full",
588
+ toolName: "write_file",
589
+ input: {
590
+ path: "src/full-stream.ts",
591
+ content: streamedContent,
592
+ },
593
+ },
594
+ {
595
+ type: "tool-result",
596
+ toolCallId: "call_write_stream_full",
597
+ toolName: "write_file",
598
+ input: {
599
+ path: "src/full-stream.ts",
600
+ content: streamedContent,
601
+ },
602
+ output: "OK - created full-stream.ts\nbytes: 84, lines: 12",
603
+ },
604
+ ]);
605
+
606
+ expect(output).toContain("Write src/full-stream.ts");
607
+ expect(output).toContain("line 1");
608
+ expect(output).toContain("line 12");
609
+ expect(output).not.toContain("OK - created full-stream.ts");
610
+ expect(output).not.toContain("... (");
611
+ });
612
+
613
+ it("falls back to write result metadata for empty write_file content", async () => {
614
+ const { output } = await renderParts([
615
+ {
616
+ type: "tool-call",
617
+ toolCallId: "call_write_empty",
618
+ toolName: "write_file",
619
+ input: {
620
+ path: "src/empty.ts",
621
+ content: "",
622
+ },
623
+ },
624
+ {
625
+ type: "tool-result",
626
+ toolCallId: "call_write_empty",
627
+ toolName: "write_file",
628
+ input: {
629
+ path: "src/empty.ts",
630
+ content: "",
631
+ },
632
+ output: "OK - created empty.ts\nbytes: 0, lines: 1",
633
+ },
634
+ ]);
635
+
636
+ expect(output).toContain("Write src/empty.ts");
637
+ expect(output).toContain("OK - created empty.ts");
638
+ });
639
+
640
+ it("truncates very large write_file previews to keep rendering bounded", async () => {
641
+ const contentLines = Array.from(
642
+ { length: 210 },
643
+ (_, index) => `line ${index + 1}`
644
+ );
645
+ const streamedContent = contentLines.join("\n");
646
+
647
+ const { output } = await renderParts([
648
+ {
649
+ type: "tool-call",
650
+ toolCallId: "call_write_huge",
651
+ toolName: "write_file",
652
+ input: {
653
+ path: "src/huge.ts",
654
+ content: streamedContent,
655
+ },
656
+ },
657
+ {
658
+ type: "tool-result",
659
+ toolCallId: "call_write_huge",
660
+ toolName: "write_file",
661
+ input: {
662
+ path: "src/huge.ts",
663
+ content: streamedContent,
664
+ },
665
+ output: "OK - created huge.ts\nbytes: 2048, lines: 210",
666
+ },
667
+ ]);
668
+
669
+ expect(output).toContain("Write src/huge.ts");
670
+ expect(output).toContain("line 1");
671
+ expect(output).toContain("line 200");
672
+ expect(output).toContain("... (10 more lines)");
673
+ expect(output).not.toContain("line 210");
674
+ });
675
+
676
+ it("streams read_file pretty header from partial tool-input-delta", async () => {
677
+ const { output } = await renderParts([
678
+ {
679
+ type: "tool-input-start",
680
+ id: "call_stream_read",
681
+ toolName: "read_file",
682
+ },
683
+ {
684
+ type: "tool-input-delta",
685
+ id: "call_stream_read",
686
+ delta: '{"path":"src/streamed.ts"',
687
+ },
688
+ ]);
689
+
690
+ expect(output).toContain("Read src/streamed.ts");
691
+ expect(output).toContain("Executing..");
692
+ expect(EXECUTING_SPINNER_TEXT_REGEX.test(output)).toBe(true);
693
+ expect(output).not.toContain("\x1b[100m");
694
+ expect(output).not.toContain("Tool read_file");
695
+ });
696
+
697
+ it("suppresses transient empty-object raw flicker during streamed tool input", async () => {
698
+ const { output, snapshots } = await renderParts([
699
+ {
700
+ type: "tool-input-start",
701
+ id: "call_stream_flicker",
702
+ toolName: "read_file",
703
+ },
704
+ {
705
+ type: "tool-input-delta",
706
+ id: "call_stream_flicker",
707
+ delta: '{"p',
708
+ },
709
+ {
710
+ type: "tool-input-delta",
711
+ id: "call_stream_flicker",
712
+ delta: 'ath":"src/no-flicker.ts"',
713
+ },
714
+ ]);
715
+
716
+ expect(output).toContain("Read src/no-flicker.ts");
717
+ expect(output).toContain("Executing..");
718
+ expect(output).not.toContain("Tool read_file");
719
+ expect(snapshots.some((frame) => frame.includes("{}"))).toBe(false);
720
+ });
721
+
722
+ it("preserves requestRender this-context for pending spinner updates", async () => {
723
+ const chatContainer = new Container();
724
+ const renderTracker = {
725
+ renderCalls: 0,
726
+ doRender() {
727
+ this.renderCalls += 1;
728
+ },
729
+ requestRender() {
730
+ this.doRender();
731
+ },
732
+ };
733
+
734
+ async function* stream(): AsyncIterable<TestStreamPart> {
735
+ yield {
736
+ type: "tool-input-start",
737
+ id: "call_bound_request_render",
738
+ toolName: "read_file",
739
+ };
740
+ yield {
741
+ type: "tool-input-delta",
742
+ id: "call_bound_request_render",
743
+ delta: '{"path":"src/bound-context.ts"',
744
+ };
745
+ await new Promise((resolve) => setTimeout(resolve, 180));
746
+ }
747
+
748
+ await renderFullStreamWithPiTui(stream(), {
749
+ chatContainer,
750
+ markdownTheme,
751
+ ui: renderTracker,
752
+ showReasoning: true,
753
+ showSteps: false,
754
+ showFinishReason: false,
755
+ showToolResults: true,
756
+ showRawToolIo: false,
757
+ showSources: false,
758
+ showFiles: false,
759
+ });
760
+
761
+ const output = chatContainer.render(120).join("\n");
762
+ expect(output).toContain("Read src/bound-context.ts");
763
+ expect(output).toContain("Executing..");
764
+ expect(renderTracker.renderCalls).toBeGreaterThan(2);
765
+ });
766
+
767
+ it("streams shell_execute pretty header from partial tool-input-delta", async () => {
768
+ const { output } = await renderParts([
769
+ {
770
+ type: "tool-input-start",
771
+ id: "call_stream_shell",
772
+ toolName: "shell_execute",
773
+ },
774
+ {
775
+ type: "tool-input-delta",
776
+ id: "call_stream_shell",
777
+ delta: '{"command":"echo streamed"',
778
+ },
779
+ ]);
780
+
781
+ expect(output).toContain("Shell echo streamed");
782
+ expect(output).toContain("Executing..");
783
+ expect(EXECUTING_SPINNER_TEXT_REGEX.test(output)).toBe(true);
784
+ expect(output).not.toContain("Tool shell_execute");
785
+ });
786
+
787
+ it("waits to render non-raw tool input until tool name is known", async () => {
788
+ const { output } = await renderParts([
789
+ {
790
+ type: "tool-input-delta",
791
+ id: "call_late_name",
792
+ delta: '{"path":"src/late-name.ts"}',
793
+ } as never,
794
+ {
795
+ type: "tool-input-start",
796
+ id: "call_late_name",
797
+ toolName: "read_file",
798
+ },
799
+ ]);
800
+
801
+ expect(output).toContain("Read src/late-name.ts");
802
+ expect(output).toContain("Executing..");
803
+ expect(output).not.toContain("Tool tool");
804
+ });
805
+
806
+ it("does not render tool block on input-start before deltas in non-raw mode", async () => {
807
+ const { output } = await renderParts([
808
+ {
809
+ type: "tool-input-start",
810
+ id: "call_start_only",
811
+ toolName: "read_file",
812
+ },
813
+ ]);
814
+
815
+ expect(output).toBe("");
816
+ });
817
+
818
+ it("keeps unknown-name tool input visible in raw debug mode", async () => {
819
+ const { output } = await renderParts(
820
+ [
821
+ {
822
+ type: "tool-input-delta",
823
+ id: "call_unknown_raw",
824
+ delta: '{"path":"src/raw-mode.ts"}',
825
+ } as never,
826
+ ],
827
+ { showRawToolIo: true }
828
+ );
829
+
830
+ expect(output).toContain("Tool tool");
831
+ expect(output).toContain("src/raw-mode.ts");
832
+ });
833
+
834
+ it("keeps reasoning visible after tool blocks in stream order", async () => {
835
+ const { output } = await renderParts([
836
+ { type: "reasoning-start", id: "reason_before" } as never,
837
+ { type: "reasoning-delta", id: "reason_before", text: "Before tool" },
838
+ { type: "reasoning-end", id: "reason_before" } as never,
839
+ {
840
+ type: "tool-input-start",
841
+ id: "call_reason",
842
+ toolName: "bash",
843
+ },
844
+ {
845
+ type: "tool-input-delta",
846
+ id: "call_reason",
847
+ delta: '{"command":"ls"}',
848
+ },
849
+ { type: "tool-input-end", id: "call_reason" },
850
+ {
851
+ type: "tool-call",
852
+ toolCallId: "call_reason",
853
+ toolName: "bash",
854
+ input: {
855
+ command: "ls",
856
+ },
857
+ },
858
+ { type: "reasoning-start", id: "reason_after" } as never,
859
+ { type: "reasoning-delta", id: "reason_after", text: "After tool" },
860
+ { type: "reasoning-end", id: "reason_after" } as never,
861
+ ]);
862
+
863
+ const beforeIndex = output.indexOf("Before tool");
864
+ const toolIndex = output.indexOf("Shell ls");
865
+ const afterIndex = output.indexOf("After tool");
866
+
867
+ expect(beforeIndex).toBeGreaterThan(-1);
868
+ expect(toolIndex).toBeGreaterThan(-1);
869
+ expect(afterIndex).toBeGreaterThan(-1);
870
+ expect(beforeIndex).toBeLessThan(toolIndex);
871
+ expect(toolIndex).toBeLessThan(afterIndex);
872
+ });
873
+
874
+ it("keeps reasoning visible between two tool calls", async () => {
875
+ const { output } = await renderParts([
876
+ {
877
+ type: "tool-input-start",
878
+ id: "call_a",
879
+ toolName: "bash",
880
+ },
881
+ {
882
+ type: "tool-input-delta",
883
+ id: "call_a",
884
+ delta: '{"command":"pwd"}',
885
+ },
886
+ { type: "tool-input-end", id: "call_a" },
887
+ {
888
+ type: "tool-call",
889
+ toolCallId: "call_a",
890
+ toolName: "bash",
891
+ input: {
892
+ command: "pwd",
893
+ },
894
+ },
895
+ { type: "reasoning-start", id: "reason_mid" } as never,
896
+ { type: "reasoning-delta", id: "reason_mid", text: "Between tools" },
897
+ { type: "reasoning-end", id: "reason_mid" } as never,
898
+ {
899
+ type: "tool-input-start",
900
+ id: "call_b",
901
+ toolName: "bash",
902
+ },
903
+ {
904
+ type: "tool-input-delta",
905
+ id: "call_b",
906
+ delta: '{"command":"ls"}',
907
+ },
908
+ { type: "tool-input-end", id: "call_b" },
909
+ {
910
+ type: "tool-call",
911
+ toolCallId: "call_b",
912
+ toolName: "bash",
913
+ input: {
914
+ command: "ls",
915
+ },
916
+ },
917
+ ]);
918
+
919
+ const firstToolIndex = output.indexOf("Shell pwd");
920
+ const reasoningIndex = output.indexOf("Between tools");
921
+ const secondToolIndex = output.indexOf("Shell ls");
922
+
923
+ expect(firstToolIndex).toBeGreaterThan(-1);
924
+ expect(reasoningIndex).toBeGreaterThan(-1);
925
+ expect(secondToolIndex).toBeGreaterThan(-1);
926
+ expect(firstToolIndex).toBeLessThan(reasoningIndex);
927
+ expect(reasoningIndex).toBeLessThan(secondToolIndex);
928
+ });
929
+
930
+ it("keeps reasoning visible across unknown stream parts", async () => {
931
+ const { output } = await renderParts([
932
+ { type: "reasoning-start", id: "reason_unknown_before" } as never,
933
+ {
934
+ type: "reasoning-delta",
935
+ id: "reason_unknown_before",
936
+ text: "Before unknown",
937
+ },
938
+ { type: "reasoning-end", id: "reason_unknown_before" } as never,
939
+ {
940
+ type: "unknown-x",
941
+ payload: "mystery",
942
+ } as never,
943
+ { type: "reasoning-start", id: "reason_unknown_after" } as never,
944
+ {
945
+ type: "reasoning-delta",
946
+ id: "reason_unknown_after",
947
+ text: "After unknown",
948
+ },
949
+ { type: "reasoning-end", id: "reason_unknown_after" } as never,
950
+ ]);
951
+
952
+ const beforeIndex = output.indexOf("Before unknown");
953
+ const unknownIndex = output.indexOf("[unknown part]");
954
+ const afterIndex = output.indexOf("After unknown");
955
+
956
+ expect(beforeIndex).toBeGreaterThan(-1);
957
+ expect(unknownIndex).toBeGreaterThan(-1);
958
+ expect(afterIndex).toBeGreaterThan(-1);
959
+ expect(beforeIndex).toBeLessThan(unknownIndex);
960
+ expect(unknownIndex).toBeLessThan(afterIndex);
961
+ });
962
+
963
+ it("renders glob_files output as structured markdown", async () => {
964
+ const globOutput = [
965
+ "OK - glob",
966
+ 'pattern: "src/**/*.ts"',
967
+ "path: /project",
968
+ "respect_git_ignore: true",
969
+ "file_count: 12",
970
+ "truncated: false",
971
+ "sorted_by: mtime desc",
972
+ "",
973
+ "======== glob results ========",
974
+ "/project/file1.ts",
975
+ "/project/file2.ts",
976
+ "/project/file3.ts",
977
+ "/project/file4.ts",
978
+ "/project/file5.ts",
979
+ "/project/file6.ts",
980
+ "/project/file7.ts",
981
+ "/project/file8.ts",
982
+ "/project/file9.ts",
983
+ "/project/file10.ts",
984
+ "/project/file11.ts",
985
+ "/project/file12.ts",
986
+ "======== end ========",
987
+ ].join("\n");
988
+
989
+ const { output } = await renderParts([
990
+ {
991
+ type: "tool-call",
992
+ toolCallId: "call_glob",
993
+ toolName: "glob_files",
994
+ input: {
995
+ pattern: "src/**/*.ts",
996
+ },
997
+ },
998
+ {
999
+ type: "tool-result",
1000
+ toolCallId: "call_glob",
1001
+ toolName: "glob_files",
1002
+ input: {
1003
+ pattern: "src/**/*.ts",
1004
+ },
1005
+ output: globOutput,
1006
+ },
1007
+ ]);
1008
+
1009
+ expect(output).toContain("Glob src/**/*.ts");
1010
+ expect(output).toContain("/project/file1.ts");
1011
+ expect(output).toContain("... (2 more lines)");
1012
+ expect(output).not.toContain("Tool glob_files");
1013
+ expect(output).not.toContain("Output");
1014
+ });
1015
+
1016
+ it("renders glob_files no-match output in glob mode", async () => {
1017
+ const globOutput = [
1018
+ "OK - glob (no matches)",
1019
+ 'pattern: "*.xyz"',
1020
+ "path: /project",
1021
+ "respect_git_ignore: true",
1022
+ "file_count: 0",
1023
+ "truncated: false",
1024
+ "sorted_by: mtime desc",
1025
+ "",
1026
+ "======== glob results ========",
1027
+ "(no matches)",
1028
+ "======== end ========",
1029
+ ].join("\n");
1030
+
1031
+ const { output } = await renderParts([
1032
+ {
1033
+ type: "tool-call",
1034
+ toolCallId: "call_glob_empty",
1035
+ toolName: "glob_files",
1036
+ input: {
1037
+ pattern: "*.xyz",
1038
+ },
1039
+ },
1040
+ {
1041
+ type: "tool-result",
1042
+ toolCallId: "call_glob_empty",
1043
+ toolName: "glob_files",
1044
+ input: {
1045
+ pattern: "*.xyz",
1046
+ },
1047
+ output: globOutput,
1048
+ },
1049
+ ]);
1050
+
1051
+ expect(output).toContain("Glob *.xyz");
1052
+ expect(output).toContain("(no matches)");
1053
+ expect(output).not.toContain("Tool glob_files");
1054
+ expect(output).not.toContain("Output");
1055
+ });
1056
+
1057
+ it("shows truncated marker for glob files when model truncates", async () => {
1058
+ const globOutput = [
1059
+ "OK - glob",
1060
+ 'pattern: "src/**/*.ts"',
1061
+ "path: /project",
1062
+ "respect_git_ignore: true",
1063
+ "file_count: 12",
1064
+ "truncated: true",
1065
+ "sorted_by: mtime desc",
1066
+ "",
1067
+ "======== glob results ========",
1068
+ "/project/file1.ts",
1069
+ "/project/file2.ts",
1070
+ "/project/file3.ts",
1071
+ "/project/file4.ts",
1072
+ "/project/file5.ts",
1073
+ "/project/file6.ts",
1074
+ "/project/file7.ts",
1075
+ "/project/file8.ts",
1076
+ "/project/file9.ts",
1077
+ "/project/file10.ts",
1078
+ "/project/file11.ts",
1079
+ "/project/file12.ts",
1080
+ "======== end ========",
1081
+ ].join("\n");
1082
+
1083
+ const { output } = await renderParts([
1084
+ {
1085
+ type: "tool-call",
1086
+ toolCallId: "call_glob_truncated",
1087
+ toolName: "glob_files",
1088
+ input: {
1089
+ pattern: "src/**/*.ts",
1090
+ },
1091
+ },
1092
+ {
1093
+ type: "tool-result",
1094
+ toolCallId: "call_glob_truncated",
1095
+ toolName: "glob_files",
1096
+ input: {
1097
+ pattern: "src/**/*.ts",
1098
+ },
1099
+ output: globOutput,
1100
+ },
1101
+ ]);
1102
+
1103
+ expect(output).toContain("... (2 more lines, truncated)");
1104
+ expect(output).not.toContain("file_count (");
1105
+ expect(output).not.toContain("path: ");
1106
+ });
1107
+
1108
+ it("renders grep_files output as structured markdown", async () => {
1109
+ const grepOutput = [
1110
+ "OK - grep",
1111
+ 'pattern: "foo"',
1112
+ "path: /project",
1113
+ "include: *.ts",
1114
+ "case_sensitive: false",
1115
+ "fixed_strings: false",
1116
+ "match_count: 12",
1117
+ "truncated: false",
1118
+ "",
1119
+ "======== grep results ========",
1120
+ tagGrepLine("/project/a.ts", 1, "const foo = 1;"),
1121
+ tagGrepLine("/project/b.ts", 2, "const foo = 2;"),
1122
+ tagGrepLine("/project/c.ts", 3, "const foo = 3;"),
1123
+ tagGrepLine("/project/d.ts", 4, "const foo = 4;"),
1124
+ tagGrepLine("/project/e.ts", 5, "const foo = 5;"),
1125
+ tagGrepLine("/project/f.ts", 6, "const foo = 6;"),
1126
+ tagGrepLine("/project/g.ts", 7, "const foo = 7;"),
1127
+ tagGrepLine("/project/h.ts", 8, "const foo = 8;"),
1128
+ tagGrepLine("/project/i.ts", 9, "const foo = 9;"),
1129
+ tagGrepLine("/project/j.ts", 10, "const foo = 10;"),
1130
+ tagGrepLine("/project/k.ts", 11, "const foo = 11;"),
1131
+ tagGrepLine("/project/l.ts", 12, "const foo = 12;"),
1132
+ "======== end ========",
1133
+ ].join("\n");
1134
+
1135
+ const { output } = await renderParts([
1136
+ {
1137
+ type: "tool-call",
1138
+ toolCallId: "call_grep",
1139
+ toolName: "grep_files",
1140
+ input: {
1141
+ pattern: "foo",
1142
+ },
1143
+ },
1144
+ {
1145
+ type: "tool-result",
1146
+ toolCallId: "call_grep",
1147
+ toolName: "grep_files",
1148
+ input: {
1149
+ pattern: "foo",
1150
+ },
1151
+ output: grepOutput,
1152
+ },
1153
+ ]);
1154
+
1155
+ expect(output).toContain("Grep foo");
1156
+ expect(output).toContain(tagGrepLine("/project/a.ts", 1, "const foo = 1;"));
1157
+ expect(output).toContain("... (2 more lines)");
1158
+ expect(output).not.toContain("Tool grep_files");
1159
+ expect(output).not.toContain("Output");
1160
+ });
1161
+
1162
+ it("renders grep_files no-match output in grep mode", async () => {
1163
+ const grepOutput = [
1164
+ "OK - grep (no matches)",
1165
+ 'pattern: "foo"',
1166
+ "path: /project",
1167
+ "include: *.ts",
1168
+ "case_sensitive: false",
1169
+ "fixed_strings: false",
1170
+ "match_count: 0",
1171
+ "truncated: false",
1172
+ "",
1173
+ "======== grep results ========",
1174
+ "(no matches)",
1175
+ "======== end ========",
1176
+ ].join("\n");
1177
+
1178
+ const { output } = await renderParts([
1179
+ {
1180
+ type: "tool-call",
1181
+ toolCallId: "call_grep_empty",
1182
+ toolName: "grep_files",
1183
+ input: {
1184
+ pattern: "foo",
1185
+ },
1186
+ },
1187
+ {
1188
+ type: "tool-result",
1189
+ toolCallId: "call_grep_empty",
1190
+ toolName: "grep_files",
1191
+ input: {
1192
+ pattern: "foo",
1193
+ },
1194
+ output: grepOutput,
1195
+ },
1196
+ ]);
1197
+
1198
+ expect(output).toContain("Grep foo");
1199
+ expect(output).toContain("(no matches)");
1200
+ expect(output).not.toContain("Tool grep_files");
1201
+ expect(output).not.toContain("Output");
1202
+ });
1203
+
1204
+ it("shows truncated marker for grep files when model truncates", async () => {
1205
+ const grepOutput = [
1206
+ "OK - grep",
1207
+ 'pattern: "foo"',
1208
+ "path: /project",
1209
+ "include: *.ts",
1210
+ "case_sensitive: false",
1211
+ "fixed_strings: false",
1212
+ "match_count: 40",
1213
+ "truncated: true",
1214
+ "",
1215
+ "======== grep results ========",
1216
+ tagGrepLine("/project/a.ts", 1, "const foo = 1;"),
1217
+ tagGrepLine("/project/b.ts", 2, "const foo = 2;"),
1218
+ tagGrepLine("/project/c.ts", 3, "const foo = 3;"),
1219
+ tagGrepLine("/project/d.ts", 4, "const foo = 4;"),
1220
+ tagGrepLine("/project/e.ts", 5, "const foo = 5;"),
1221
+ tagGrepLine("/project/f.ts", 6, "const foo = 6;"),
1222
+ tagGrepLine("/project/g.ts", 7, "const foo = 7;"),
1223
+ tagGrepLine("/project/h.ts", 8, "const foo = 8;"),
1224
+ tagGrepLine("/project/i.ts", 9, "const foo = 9;"),
1225
+ tagGrepLine("/project/j.ts", 10, "const foo = 10;"),
1226
+ tagGrepLine("/project/k.ts", 11, "const foo = 11;"),
1227
+ tagGrepLine("/project/l.ts", 12, "const foo = 12;"),
1228
+ "======== end ========",
1229
+ ].join("\n");
1230
+
1231
+ const { output } = await renderParts([
1232
+ {
1233
+ type: "tool-call",
1234
+ toolCallId: "call_grep_truncated",
1235
+ toolName: "grep_files",
1236
+ input: {
1237
+ pattern: "foo",
1238
+ },
1239
+ },
1240
+ {
1241
+ type: "tool-result",
1242
+ toolCallId: "call_grep_truncated",
1243
+ toolName: "grep_files",
1244
+ input: {
1245
+ pattern: "foo",
1246
+ },
1247
+ output: grepOutput,
1248
+ },
1249
+ ]);
1250
+
1251
+ expect(output).toContain("... (30 more lines, truncated)");
1252
+ expect(output).toContain("match_count (40)");
1253
+ expect(output).toContain("truncated: true");
1254
+ });
1255
+
1256
+ it("renders read/glob/grep tool IO in raw mode when enabled", async () => {
1257
+ const cases = [
1258
+ {
1259
+ toolCallId: "call_read_raw",
1260
+ toolName: "read_file",
1261
+ input: { path: "src/demo.ts" },
1262
+ output: [
1263
+ "OK - read file",
1264
+ "path: src/demo.ts",
1265
+ "bytes: 12",
1266
+ "last_modified: 2026-02-23T01:00:00.000Z",
1267
+ "lines: 1 (returned: 1)",
1268
+ "range: L1-L1",
1269
+ "truncated: false",
1270
+ "",
1271
+ "======== demo.ts L1-L1 ========",
1272
+ " 1 | const x = 1;",
1273
+ "======== end ========",
1274
+ ].join("\n"),
1275
+ prettyHeading: "Read src/demo.ts",
1276
+ },
1277
+ {
1278
+ toolCallId: "call_glob_raw",
1279
+ toolName: "glob_files",
1280
+ input: { pattern: "src/**/*.ts" },
1281
+ output: [
1282
+ "OK - glob",
1283
+ 'pattern: "src/**/*.ts"',
1284
+ "path: /project",
1285
+ "respect_git_ignore: true",
1286
+ "file_count: 1",
1287
+ "truncated: false",
1288
+ "sorted_by: mtime desc",
1289
+ "",
1290
+ "======== glob results ========",
1291
+ "/project/file1.ts",
1292
+ "======== end ========",
1293
+ ].join("\n"),
1294
+ prettyHeading: "Glob src/**/*.ts",
1295
+ },
1296
+ {
1297
+ toolCallId: "call_grep_raw",
1298
+ toolName: "grep_files",
1299
+ input: { pattern: "foo" },
1300
+ output: [
1301
+ "OK - grep",
1302
+ 'pattern: "foo"',
1303
+ "path: /project",
1304
+ "include: *.ts",
1305
+ "case_sensitive: false",
1306
+ "fixed_strings: false",
1307
+ "match_count: 1",
1308
+ "truncated: false",
1309
+ "",
1310
+ "======== grep results ========",
1311
+ tagGrepLine("/project/file1.ts", 1, "const foo = 1;"),
1312
+ "======== end ========",
1313
+ ].join("\n"),
1314
+ prettyHeading: "Grep foo",
1315
+ },
1316
+ ] as const;
1317
+
1318
+ for (const testCase of cases) {
1319
+ const { output } = await renderParts(
1320
+ [
1321
+ {
1322
+ type: "tool-call",
1323
+ toolCallId: testCase.toolCallId,
1324
+ toolName: testCase.toolName,
1325
+ input: testCase.input,
1326
+ },
1327
+ {
1328
+ type: "tool-result",
1329
+ toolCallId: testCase.toolCallId,
1330
+ toolName: testCase.toolName,
1331
+ input: testCase.input,
1332
+ output: testCase.output,
1333
+ },
1334
+ ],
1335
+ { showRawToolIo: true }
1336
+ );
1337
+
1338
+ expect(output).toContain(`Tool ${testCase.toolName}`);
1339
+ expect(output).toContain("Input");
1340
+ expect(output).toContain("Output");
1341
+ expect(output).toContain(testCase.output.split("\n")[0]);
1342
+ expect(output).not.toContain(testCase.prettyHeading);
1343
+ }
1344
+ });
1345
+
1346
+ it("hides call id in raw shell headers", async () => {
1347
+ const { output } = await renderParts(
1348
+ [
1349
+ {
1350
+ type: "tool-call",
1351
+ toolCallId: "call_shell_raw",
1352
+ toolName: "bash",
1353
+ input: {
1354
+ command: "pwd",
1355
+ },
1356
+ },
1357
+ ],
1358
+ { showRawToolIo: true }
1359
+ );
1360
+
1361
+ expect(output).toContain("Tool bash");
1362
+ expect(output).not.toContain("call_shell_raw");
1363
+ });
1364
+
1365
+ it("renders dedicated pretty wrappers for all other tools", async () => {
1366
+ const cases = [
1367
+ {
1368
+ toolCallId: "call_shell_pretty",
1369
+ toolName: "shell_execute",
1370
+ input: {
1371
+ command: "echo hello",
1372
+ workdir: "/tmp",
1373
+ timeout_ms: 1000,
1374
+ },
1375
+ output: {
1376
+ exit_code: 0,
1377
+ output: "hello",
1378
+ },
1379
+ expectedHeading: "Shell echo hello",
1380
+ },
1381
+ {
1382
+ toolCallId: "call_interact_pretty",
1383
+ toolName: "shell_interact",
1384
+ input: {
1385
+ keystrokes: "<Enter>",
1386
+ },
1387
+ output: {
1388
+ success: true,
1389
+ output: "sent",
1390
+ },
1391
+ expectedHeading: "Interact <Enter>",
1392
+ },
1393
+ {
1394
+ toolCallId: "call_write_pretty",
1395
+ toolName: "write_file",
1396
+ input: {
1397
+ path: "src/new.ts",
1398
+ content: "const x = 1;",
1399
+ },
1400
+ output: "OK - created new.ts\nbytes: 12, lines: 1",
1401
+ expectedHeading: "Write src/new.ts",
1402
+ },
1403
+ {
1404
+ toolCallId: "call_edit_pretty",
1405
+ toolName: "edit_file",
1406
+ input: {
1407
+ path: "src/demo.ts",
1408
+ edits: [{ op: "replace", pos: "2#AB", lines: ["const x = 2;"] }],
1409
+ },
1410
+ output: "Updated src/demo.ts",
1411
+ expectedHeading: "Edit src/demo.ts",
1412
+ },
1413
+ {
1414
+ toolCallId: "call_delete_pretty",
1415
+ toolName: "delete_file",
1416
+ input: {
1417
+ path: "src/old.ts",
1418
+ },
1419
+ output: "OK - deleted file: old.ts\npath: src/old.ts",
1420
+ expectedHeading: "Delete src/old.ts",
1421
+ },
1422
+ {
1423
+ toolCallId: "call_skill_pretty",
1424
+ toolName: "load_skill",
1425
+ input: {
1426
+ skillName: "git-workflow",
1427
+ },
1428
+ output: "# Skill Loaded: git-workflow [Project]",
1429
+ expectedHeading: "Skill git-workflow",
1430
+ },
1431
+ {
1432
+ toolCallId: "call_todo_pretty",
1433
+ toolName: "todo_write",
1434
+ input: {
1435
+ todos: [
1436
+ { id: "1", content: "A", status: "pending", priority: "high" },
1437
+ {
1438
+ id: "2",
1439
+ content: "B",
1440
+ status: "completed",
1441
+ priority: "medium",
1442
+ },
1443
+ ],
1444
+ },
1445
+ output: "OK - updated todo list\ntotal: 2 tasks",
1446
+ expectedHeading: "Todo 2 tasks",
1447
+ },
1448
+ ] as const;
1449
+
1450
+ for (const testCase of cases) {
1451
+ const { output } = await renderParts([
1452
+ {
1453
+ type: "tool-call",
1454
+ toolCallId: testCase.toolCallId,
1455
+ toolName: testCase.toolName,
1456
+ input: testCase.input,
1457
+ },
1458
+ {
1459
+ type: "tool-result",
1460
+ toolCallId: testCase.toolCallId,
1461
+ toolName: testCase.toolName,
1462
+ input: testCase.input,
1463
+ output: testCase.output,
1464
+ },
1465
+ ]);
1466
+
1467
+ expect(output).toContain(testCase.expectedHeading);
1468
+ expect(output).not.toContain(`Tool ${testCase.toolName}`);
1469
+ }
1470
+ });
1471
+ });