iosm-cli 0.1.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 (729) hide show
  1. package/CHANGELOG.md +55 -0
  2. package/LICENSE +21 -0
  3. package/README.md +650 -0
  4. package/dist/cli/args.d.ts +54 -0
  5. package/dist/cli/args.d.ts.map +1 -0
  6. package/dist/cli/args.js +331 -0
  7. package/dist/cli/args.js.map +1 -0
  8. package/dist/cli/config-selector.d.ts +14 -0
  9. package/dist/cli/config-selector.d.ts.map +1 -0
  10. package/dist/cli/config-selector.js +31 -0
  11. package/dist/cli/config-selector.js.map +1 -0
  12. package/dist/cli/file-processor.d.ts +15 -0
  13. package/dist/cli/file-processor.d.ts.map +1 -0
  14. package/dist/cli/file-processor.js +79 -0
  15. package/dist/cli/file-processor.js.map +1 -0
  16. package/dist/cli/list-models.d.ts +9 -0
  17. package/dist/cli/list-models.d.ts.map +1 -0
  18. package/dist/cli/list-models.js +92 -0
  19. package/dist/cli/list-models.js.map +1 -0
  20. package/dist/cli/session-picker.d.ts +9 -0
  21. package/dist/cli/session-picker.d.ts.map +1 -0
  22. package/dist/cli/session-picker.js +34 -0
  23. package/dist/cli/session-picker.js.map +1 -0
  24. package/dist/cli.d.ts +3 -0
  25. package/dist/cli.d.ts.map +1 -0
  26. package/dist/cli.js +15 -0
  27. package/dist/cli.js.map +1 -0
  28. package/dist/config.d.ts +88 -0
  29. package/dist/config.d.ts.map +1 -0
  30. package/dist/config.js +262 -0
  31. package/dist/config.js.map +1 -0
  32. package/dist/core/agent-profiles.d.ts +29 -0
  33. package/dist/core/agent-profiles.d.ts.map +1 -0
  34. package/dist/core/agent-profiles.js +86 -0
  35. package/dist/core/agent-profiles.js.map +1 -0
  36. package/dist/core/agent-session.d.ts +688 -0
  37. package/dist/core/agent-session.d.ts.map +1 -0
  38. package/dist/core/agent-session.js +3112 -0
  39. package/dist/core/agent-session.js.map +1 -0
  40. package/dist/core/agent-teams.d.ts +41 -0
  41. package/dist/core/agent-teams.d.ts.map +1 -0
  42. package/dist/core/agent-teams.js +90 -0
  43. package/dist/core/agent-teams.js.map +1 -0
  44. package/dist/core/ask-user-tool.d.ts +22 -0
  45. package/dist/core/ask-user-tool.d.ts.map +1 -0
  46. package/dist/core/ask-user-tool.js +115 -0
  47. package/dist/core/ask-user-tool.js.map +1 -0
  48. package/dist/core/auth-storage.d.ts +133 -0
  49. package/dist/core/auth-storage.d.ts.map +1 -0
  50. package/dist/core/auth-storage.js +391 -0
  51. package/dist/core/auth-storage.js.map +1 -0
  52. package/dist/core/bash-executor.d.ts +49 -0
  53. package/dist/core/bash-executor.d.ts.map +1 -0
  54. package/dist/core/bash-executor.js +213 -0
  55. package/dist/core/bash-executor.js.map +1 -0
  56. package/dist/core/compaction/branch-summarization.d.ts +86 -0
  57. package/dist/core/compaction/branch-summarization.d.ts.map +1 -0
  58. package/dist/core/compaction/branch-summarization.js +242 -0
  59. package/dist/core/compaction/branch-summarization.js.map +1 -0
  60. package/dist/core/compaction/compaction.d.ts +121 -0
  61. package/dist/core/compaction/compaction.d.ts.map +1 -0
  62. package/dist/core/compaction/compaction.js +610 -0
  63. package/dist/core/compaction/compaction.js.map +1 -0
  64. package/dist/core/compaction/index.d.ts +7 -0
  65. package/dist/core/compaction/index.d.ts.map +1 -0
  66. package/dist/core/compaction/index.js +7 -0
  67. package/dist/core/compaction/index.js.map +1 -0
  68. package/dist/core/compaction/utils.d.ts +35 -0
  69. package/dist/core/compaction/utils.d.ts.map +1 -0
  70. package/dist/core/compaction/utils.js +138 -0
  71. package/dist/core/compaction/utils.js.map +1 -0
  72. package/dist/core/defaults.d.ts +3 -0
  73. package/dist/core/defaults.d.ts.map +1 -0
  74. package/dist/core/defaults.js +2 -0
  75. package/dist/core/defaults.js.map +1 -0
  76. package/dist/core/diagnostics.d.ts +15 -0
  77. package/dist/core/diagnostics.d.ts.map +1 -0
  78. package/dist/core/diagnostics.js +2 -0
  79. package/dist/core/diagnostics.js.map +1 -0
  80. package/dist/core/event-bus.d.ts +9 -0
  81. package/dist/core/event-bus.d.ts.map +1 -0
  82. package/dist/core/event-bus.js +25 -0
  83. package/dist/core/event-bus.js.map +1 -0
  84. package/dist/core/exec.d.ts +29 -0
  85. package/dist/core/exec.d.ts.map +1 -0
  86. package/dist/core/exec.js +71 -0
  87. package/dist/core/exec.js.map +1 -0
  88. package/dist/core/export-html/ansi-to-html.d.ts +22 -0
  89. package/dist/core/export-html/ansi-to-html.d.ts.map +1 -0
  90. package/dist/core/export-html/ansi-to-html.js +249 -0
  91. package/dist/core/export-html/ansi-to-html.js.map +1 -0
  92. package/dist/core/export-html/index.d.ts +34 -0
  93. package/dist/core/export-html/index.d.ts.map +1 -0
  94. package/dist/core/export-html/index.js +222 -0
  95. package/dist/core/export-html/index.js.map +1 -0
  96. package/dist/core/export-html/template.css +971 -0
  97. package/dist/core/export-html/template.html +54 -0
  98. package/dist/core/export-html/template.js +1590 -0
  99. package/dist/core/export-html/tool-renderer.d.ts +35 -0
  100. package/dist/core/export-html/tool-renderer.d.ts.map +1 -0
  101. package/dist/core/export-html/tool-renderer.js +63 -0
  102. package/dist/core/export-html/tool-renderer.js.map +1 -0
  103. package/dist/core/export-html/vendor/highlight.min.js +1213 -0
  104. package/dist/core/export-html/vendor/marked.min.js +6 -0
  105. package/dist/core/extensions/index.d.ts +11 -0
  106. package/dist/core/extensions/index.d.ts.map +1 -0
  107. package/dist/core/extensions/index.js +9 -0
  108. package/dist/core/extensions/index.js.map +1 -0
  109. package/dist/core/extensions/loader.d.ts +25 -0
  110. package/dist/core/extensions/loader.d.ts.map +1 -0
  111. package/dist/core/extensions/loader.js +447 -0
  112. package/dist/core/extensions/loader.js.map +1 -0
  113. package/dist/core/extensions/runner.d.ts +146 -0
  114. package/dist/core/extensions/runner.d.ts.map +1 -0
  115. package/dist/core/extensions/runner.js +652 -0
  116. package/dist/core/extensions/runner.js.map +1 -0
  117. package/dist/core/extensions/types.d.ts +1074 -0
  118. package/dist/core/extensions/types.d.ts.map +1 -0
  119. package/dist/core/extensions/types.js +35 -0
  120. package/dist/core/extensions/types.js.map +1 -0
  121. package/dist/core/extensions/wrapper.d.ts +27 -0
  122. package/dist/core/extensions/wrapper.d.ts.map +1 -0
  123. package/dist/core/extensions/wrapper.js +102 -0
  124. package/dist/core/extensions/wrapper.js.map +1 -0
  125. package/dist/core/footer-data-provider.d.ts +32 -0
  126. package/dist/core/footer-data-provider.d.ts.map +1 -0
  127. package/dist/core/footer-data-provider.js +134 -0
  128. package/dist/core/footer-data-provider.js.map +1 -0
  129. package/dist/core/hooks.d.ts +53 -0
  130. package/dist/core/hooks.d.ts.map +1 -0
  131. package/dist/core/hooks.js +332 -0
  132. package/dist/core/hooks.js.map +1 -0
  133. package/dist/core/index.d.ts +9 -0
  134. package/dist/core/index.d.ts.map +1 -0
  135. package/dist/core/index.js +9 -0
  136. package/dist/core/index.js.map +1 -0
  137. package/dist/core/keybindings.d.ts +55 -0
  138. package/dist/core/keybindings.d.ts.map +1 -0
  139. package/dist/core/keybindings.js +157 -0
  140. package/dist/core/keybindings.js.map +1 -0
  141. package/dist/core/mcp/cli.d.ts +27 -0
  142. package/dist/core/mcp/cli.d.ts.map +1 -0
  143. package/dist/core/mcp/cli.js +275 -0
  144. package/dist/core/mcp/cli.js.map +1 -0
  145. package/dist/core/mcp/config.d.ts +11 -0
  146. package/dist/core/mcp/config.d.ts.map +1 -0
  147. package/dist/core/mcp/config.js +310 -0
  148. package/dist/core/mcp/config.js.map +1 -0
  149. package/dist/core/mcp/index.d.ts +5 -0
  150. package/dist/core/mcp/index.d.ts.map +1 -0
  151. package/dist/core/mcp/index.js +4 -0
  152. package/dist/core/mcp/index.js.map +1 -0
  153. package/dist/core/mcp/runtime.d.ts +42 -0
  154. package/dist/core/mcp/runtime.d.ts.map +1 -0
  155. package/dist/core/mcp/runtime.js +387 -0
  156. package/dist/core/mcp/runtime.js.map +1 -0
  157. package/dist/core/mcp/types.d.ts +76 -0
  158. package/dist/core/mcp/types.d.ts.map +1 -0
  159. package/dist/core/mcp/types.js +2 -0
  160. package/dist/core/mcp/types.js.map +1 -0
  161. package/dist/core/memory.d.ts +27 -0
  162. package/dist/core/memory.d.ts.map +1 -0
  163. package/dist/core/memory.js +203 -0
  164. package/dist/core/memory.js.map +1 -0
  165. package/dist/core/messages.d.ts +84 -0
  166. package/dist/core/messages.d.ts.map +1 -0
  167. package/dist/core/messages.js +141 -0
  168. package/dist/core/messages.js.map +1 -0
  169. package/dist/core/model-registry.d.ts +115 -0
  170. package/dist/core/model-registry.d.ts.map +1 -0
  171. package/dist/core/model-registry.js +549 -0
  172. package/dist/core/model-registry.js.map +1 -0
  173. package/dist/core/model-resolver.d.ts +104 -0
  174. package/dist/core/model-resolver.d.ts.map +1 -0
  175. package/dist/core/model-resolver.js +448 -0
  176. package/dist/core/model-resolver.js.map +1 -0
  177. package/dist/core/package-manager.d.ts +156 -0
  178. package/dist/core/package-manager.d.ts.map +1 -0
  179. package/dist/core/package-manager.js +1465 -0
  180. package/dist/core/package-manager.js.map +1 -0
  181. package/dist/core/parallel-task-agent.d.ts +19 -0
  182. package/dist/core/parallel-task-agent.d.ts.map +1 -0
  183. package/dist/core/parallel-task-agent.js +482 -0
  184. package/dist/core/parallel-task-agent.js.map +1 -0
  185. package/dist/core/prompt-templates.d.ts +50 -0
  186. package/dist/core/prompt-templates.d.ts.map +1 -0
  187. package/dist/core/prompt-templates.js +251 -0
  188. package/dist/core/prompt-templates.js.map +1 -0
  189. package/dist/core/qwen-cli-provider.d.ts +10 -0
  190. package/dist/core/qwen-cli-provider.d.ts.map +1 -0
  191. package/dist/core/qwen-cli-provider.js +271 -0
  192. package/dist/core/qwen-cli-provider.js.map +1 -0
  193. package/dist/core/resolve-config-value.d.ts +17 -0
  194. package/dist/core/resolve-config-value.d.ts.map +1 -0
  195. package/dist/core/resolve-config-value.js +60 -0
  196. package/dist/core/resolve-config-value.js.map +1 -0
  197. package/dist/core/resource-loader.d.ts +195 -0
  198. package/dist/core/resource-loader.d.ts.map +1 -0
  199. package/dist/core/resource-loader.js +820 -0
  200. package/dist/core/resource-loader.js.map +1 -0
  201. package/dist/core/sdk.d.ts +106 -0
  202. package/dist/core/sdk.d.ts.map +1 -0
  203. package/dist/core/sdk.js +460 -0
  204. package/dist/core/sdk.js.map +1 -0
  205. package/dist/core/session-manager.d.ts +323 -0
  206. package/dist/core/session-manager.d.ts.map +1 -0
  207. package/dist/core/session-manager.js +1094 -0
  208. package/dist/core/session-manager.js.map +1 -0
  209. package/dist/core/settings-manager.d.ts +243 -0
  210. package/dist/core/settings-manager.d.ts.map +1 -0
  211. package/dist/core/settings-manager.js +691 -0
  212. package/dist/core/settings-manager.js.map +1 -0
  213. package/dist/core/skills.d.ts +58 -0
  214. package/dist/core/skills.d.ts.map +1 -0
  215. package/dist/core/skills.js +364 -0
  216. package/dist/core/skills.js.map +1 -0
  217. package/dist/core/slash-commands.d.ts +15 -0
  218. package/dist/core/slash-commands.d.ts.map +1 -0
  219. package/dist/core/slash-commands.js +64 -0
  220. package/dist/core/slash-commands.js.map +1 -0
  221. package/dist/core/subagent-runs.d.ts +16 -0
  222. package/dist/core/subagent-runs.d.ts.map +1 -0
  223. package/dist/core/subagent-runs.js +70 -0
  224. package/dist/core/subagent-runs.js.map +1 -0
  225. package/dist/core/subagents.d.ts +45 -0
  226. package/dist/core/subagents.d.ts.map +1 -0
  227. package/dist/core/subagents.js +467 -0
  228. package/dist/core/subagents.js.map +1 -0
  229. package/dist/core/system-prompt.d.ts +28 -0
  230. package/dist/core/system-prompt.d.ts.map +1 -0
  231. package/dist/core/system-prompt.js +196 -0
  232. package/dist/core/system-prompt.js.map +1 -0
  233. package/dist/core/task-plan.d.ts +32 -0
  234. package/dist/core/task-plan.d.ts.map +1 -0
  235. package/dist/core/task-plan.js +155 -0
  236. package/dist/core/task-plan.js.map +1 -0
  237. package/dist/core/timings.d.ts +7 -0
  238. package/dist/core/timings.d.ts.map +1 -0
  239. package/dist/core/timings.js +26 -0
  240. package/dist/core/timings.js.map +1 -0
  241. package/dist/core/tools/bash.d.ts +58 -0
  242. package/dist/core/tools/bash.d.ts.map +1 -0
  243. package/dist/core/tools/bash.js +275 -0
  244. package/dist/core/tools/bash.js.map +1 -0
  245. package/dist/core/tools/edit-diff.d.ts +63 -0
  246. package/dist/core/tools/edit-diff.d.ts.map +1 -0
  247. package/dist/core/tools/edit-diff.js +243 -0
  248. package/dist/core/tools/edit-diff.js.map +1 -0
  249. package/dist/core/tools/edit.d.ts +42 -0
  250. package/dist/core/tools/edit.d.ts.map +1 -0
  251. package/dist/core/tools/edit.js +158 -0
  252. package/dist/core/tools/edit.js.map +1 -0
  253. package/dist/core/tools/find.d.ts +39 -0
  254. package/dist/core/tools/find.d.ts.map +1 -0
  255. package/dist/core/tools/find.js +219 -0
  256. package/dist/core/tools/find.js.map +1 -0
  257. package/dist/core/tools/grep.d.ts +45 -0
  258. package/dist/core/tools/grep.d.ts.map +1 -0
  259. package/dist/core/tools/grep.js +254 -0
  260. package/dist/core/tools/grep.js.map +1 -0
  261. package/dist/core/tools/ignore-filter.d.ts +5 -0
  262. package/dist/core/tools/ignore-filter.d.ts.map +1 -0
  263. package/dist/core/tools/ignore-filter.js +97 -0
  264. package/dist/core/tools/ignore-filter.js.map +1 -0
  265. package/dist/core/tools/index.d.ts +97 -0
  266. package/dist/core/tools/index.d.ts.map +1 -0
  267. package/dist/core/tools/index.js +78 -0
  268. package/dist/core/tools/index.js.map +1 -0
  269. package/dist/core/tools/ls.d.ts +46 -0
  270. package/dist/core/tools/ls.d.ts.map +1 -0
  271. package/dist/core/tools/ls.js +136 -0
  272. package/dist/core/tools/ls.js.map +1 -0
  273. package/dist/core/tools/path-utils.d.ts +8 -0
  274. package/dist/core/tools/path-utils.d.ts.map +1 -0
  275. package/dist/core/tools/path-utils.js +81 -0
  276. package/dist/core/tools/path-utils.js.map +1 -0
  277. package/dist/core/tools/permissions.d.ts +8 -0
  278. package/dist/core/tools/permissions.d.ts.map +1 -0
  279. package/dist/core/tools/permissions.js +2 -0
  280. package/dist/core/tools/permissions.js.map +1 -0
  281. package/dist/core/tools/read.d.ts +39 -0
  282. package/dist/core/tools/read.d.ts.map +1 -0
  283. package/dist/core/tools/read.js +166 -0
  284. package/dist/core/tools/read.js.map +1 -0
  285. package/dist/core/tools/task.d.ts +109 -0
  286. package/dist/core/tools/task.d.ts.map +1 -0
  287. package/dist/core/tools/task.js +1065 -0
  288. package/dist/core/tools/task.js.map +1 -0
  289. package/dist/core/tools/todo.d.ts +42 -0
  290. package/dist/core/tools/todo.d.ts.map +1 -0
  291. package/dist/core/tools/todo.js +159 -0
  292. package/dist/core/tools/todo.js.map +1 -0
  293. package/dist/core/tools/truncate.d.ts +70 -0
  294. package/dist/core/tools/truncate.d.ts.map +1 -0
  295. package/dist/core/tools/truncate.js +205 -0
  296. package/dist/core/tools/truncate.js.map +1 -0
  297. package/dist/core/tools/write.d.ts +32 -0
  298. package/dist/core/tools/write.d.ts.map +1 -0
  299. package/dist/core/tools/write.js +90 -0
  300. package/dist/core/tools/write.js.map +1 -0
  301. package/dist/index.d.ts +30 -0
  302. package/dist/index.d.ts.map +1 -0
  303. package/dist/index.js +45 -0
  304. package/dist/index.js.map +1 -0
  305. package/dist/iosm/agent-verification.d.ts +16 -0
  306. package/dist/iosm/agent-verification.d.ts.map +1 -0
  307. package/dist/iosm/agent-verification.js +138 -0
  308. package/dist/iosm/agent-verification.js.map +1 -0
  309. package/dist/iosm/automation.d.ts +40 -0
  310. package/dist/iosm/automation.d.ts.map +1 -0
  311. package/dist/iosm/automation.js +76 -0
  312. package/dist/iosm/automation.js.map +1 -0
  313. package/dist/iosm/config.d.ts +151 -0
  314. package/dist/iosm/config.d.ts.map +1 -0
  315. package/dist/iosm/config.js +323 -0
  316. package/dist/iosm/config.js.map +1 -0
  317. package/dist/iosm/context-loader.d.ts +12 -0
  318. package/dist/iosm/context-loader.d.ts.map +1 -0
  319. package/dist/iosm/context-loader.js +50 -0
  320. package/dist/iosm/context-loader.js.map +1 -0
  321. package/dist/iosm/cycle.d.ts +51 -0
  322. package/dist/iosm/cycle.d.ts.map +1 -0
  323. package/dist/iosm/cycle.js +861 -0
  324. package/dist/iosm/cycle.js.map +1 -0
  325. package/dist/iosm/guide.d.ts +31 -0
  326. package/dist/iosm/guide.d.ts.map +1 -0
  327. package/dist/iosm/guide.js +101 -0
  328. package/dist/iosm/guide.js.map +1 -0
  329. package/dist/iosm/index.d.ts +12 -0
  330. package/dist/iosm/index.d.ts.map +1 -0
  331. package/dist/iosm/index.js +11 -0
  332. package/dist/iosm/index.js.map +1 -0
  333. package/dist/iosm/init.d.ts +58 -0
  334. package/dist/iosm/init.d.ts.map +1 -0
  335. package/dist/iosm/init.js +1221 -0
  336. package/dist/iosm/init.js.map +1 -0
  337. package/dist/iosm/metrics.d.ts +23 -0
  338. package/dist/iosm/metrics.d.ts.map +1 -0
  339. package/dist/iosm/metrics.js +336 -0
  340. package/dist/iosm/metrics.js.map +1 -0
  341. package/dist/iosm/paths.d.ts +24 -0
  342. package/dist/iosm/paths.d.ts.map +1 -0
  343. package/dist/iosm/paths.js +77 -0
  344. package/dist/iosm/paths.js.map +1 -0
  345. package/dist/iosm/runtime-context.d.ts +20 -0
  346. package/dist/iosm/runtime-context.d.ts.map +1 -0
  347. package/dist/iosm/runtime-context.js +170 -0
  348. package/dist/iosm/runtime-context.js.map +1 -0
  349. package/dist/iosm/types.d.ts +151 -0
  350. package/dist/iosm/types.d.ts.map +1 -0
  351. package/dist/iosm/types.js +3 -0
  352. package/dist/iosm/types.js.map +1 -0
  353. package/dist/main.d.ts +8 -0
  354. package/dist/main.d.ts.map +1 -0
  355. package/dist/main.js +1478 -0
  356. package/dist/main.js.map +1 -0
  357. package/dist/migrations.d.ts +33 -0
  358. package/dist/migrations.d.ts.map +1 -0
  359. package/dist/migrations.js +261 -0
  360. package/dist/migrations.js.map +1 -0
  361. package/dist/modes/index.d.ts +9 -0
  362. package/dist/modes/index.d.ts.map +1 -0
  363. package/dist/modes/index.js +8 -0
  364. package/dist/modes/index.js.map +1 -0
  365. package/dist/modes/interactive/components/armin.d.ts +34 -0
  366. package/dist/modes/interactive/components/armin.d.ts.map +1 -0
  367. package/dist/modes/interactive/components/armin.js +329 -0
  368. package/dist/modes/interactive/components/armin.js.map +1 -0
  369. package/dist/modes/interactive/components/ascii-logo.d.ts +11 -0
  370. package/dist/modes/interactive/components/ascii-logo.d.ts.map +1 -0
  371. package/dist/modes/interactive/components/ascii-logo.js +25 -0
  372. package/dist/modes/interactive/components/ascii-logo.js.map +1 -0
  373. package/dist/modes/interactive/components/assistant-message.d.ts +16 -0
  374. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -0
  375. package/dist/modes/interactive/components/assistant-message.js +92 -0
  376. package/dist/modes/interactive/components/assistant-message.js.map +1 -0
  377. package/dist/modes/interactive/components/bash-execution.d.ts +36 -0
  378. package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -0
  379. package/dist/modes/interactive/components/bash-execution.js +170 -0
  380. package/dist/modes/interactive/components/bash-execution.js.map +1 -0
  381. package/dist/modes/interactive/components/bordered-loader.d.ts +16 -0
  382. package/dist/modes/interactive/components/bordered-loader.d.ts.map +1 -0
  383. package/dist/modes/interactive/components/bordered-loader.js +48 -0
  384. package/dist/modes/interactive/components/bordered-loader.js.map +1 -0
  385. package/dist/modes/interactive/components/branch-summary-message.d.ts +16 -0
  386. package/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -0
  387. package/dist/modes/interactive/components/branch-summary-message.js +42 -0
  388. package/dist/modes/interactive/components/branch-summary-message.js.map +1 -0
  389. package/dist/modes/interactive/components/compaction-summary-message.d.ts +16 -0
  390. package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +1 -0
  391. package/dist/modes/interactive/components/compaction-summary-message.js +43 -0
  392. package/dist/modes/interactive/components/compaction-summary-message.js.map +1 -0
  393. package/dist/modes/interactive/components/config-selector.d.ts +71 -0
  394. package/dist/modes/interactive/components/config-selector.d.ts.map +1 -0
  395. package/dist/modes/interactive/components/config-selector.js +470 -0
  396. package/dist/modes/interactive/components/config-selector.js.map +1 -0
  397. package/dist/modes/interactive/components/countdown-timer.d.ts +14 -0
  398. package/dist/modes/interactive/components/countdown-timer.d.ts.map +1 -0
  399. package/dist/modes/interactive/components/countdown-timer.js +28 -0
  400. package/dist/modes/interactive/components/countdown-timer.js.map +1 -0
  401. package/dist/modes/interactive/components/custom-editor.d.ts +21 -0
  402. package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -0
  403. package/dist/modes/interactive/components/custom-editor.js +63 -0
  404. package/dist/modes/interactive/components/custom-editor.js.map +1 -0
  405. package/dist/modes/interactive/components/custom-message.d.ts +20 -0
  406. package/dist/modes/interactive/components/custom-message.d.ts.map +1 -0
  407. package/dist/modes/interactive/components/custom-message.js +74 -0
  408. package/dist/modes/interactive/components/custom-message.js.map +1 -0
  409. package/dist/modes/interactive/components/daxnuts.d.ts +23 -0
  410. package/dist/modes/interactive/components/daxnuts.d.ts.map +1 -0
  411. package/dist/modes/interactive/components/daxnuts.js +138 -0
  412. package/dist/modes/interactive/components/daxnuts.js.map +1 -0
  413. package/dist/modes/interactive/components/decrypt-loader.d.ts +25 -0
  414. package/dist/modes/interactive/components/decrypt-loader.d.ts.map +1 -0
  415. package/dist/modes/interactive/components/decrypt-loader.js +102 -0
  416. package/dist/modes/interactive/components/decrypt-loader.js.map +1 -0
  417. package/dist/modes/interactive/components/diff.d.ts +12 -0
  418. package/dist/modes/interactive/components/diff.d.ts.map +1 -0
  419. package/dist/modes/interactive/components/diff.js +133 -0
  420. package/dist/modes/interactive/components/diff.js.map +1 -0
  421. package/dist/modes/interactive/components/dynamic-border.d.ts +15 -0
  422. package/dist/modes/interactive/components/dynamic-border.d.ts.map +1 -0
  423. package/dist/modes/interactive/components/dynamic-border.js +20 -0
  424. package/dist/modes/interactive/components/dynamic-border.js.map +1 -0
  425. package/dist/modes/interactive/components/extension-editor.d.ts +20 -0
  426. package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -0
  427. package/dist/modes/interactive/components/extension-editor.js +105 -0
  428. package/dist/modes/interactive/components/extension-editor.js.map +1 -0
  429. package/dist/modes/interactive/components/extension-input.d.ts +23 -0
  430. package/dist/modes/interactive/components/extension-input.d.ts.map +1 -0
  431. package/dist/modes/interactive/components/extension-input.js +55 -0
  432. package/dist/modes/interactive/components/extension-input.js.map +1 -0
  433. package/dist/modes/interactive/components/extension-selector.d.ts +24 -0
  434. package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -0
  435. package/dist/modes/interactive/components/extension-selector.js +71 -0
  436. package/dist/modes/interactive/components/extension-selector.js.map +1 -0
  437. package/dist/modes/interactive/components/footer.d.ts +39 -0
  438. package/dist/modes/interactive/components/footer.d.ts.map +1 -0
  439. package/dist/modes/interactive/components/footer.js +285 -0
  440. package/dist/modes/interactive/components/footer.js.map +1 -0
  441. package/dist/modes/interactive/components/index.d.ts +33 -0
  442. package/dist/modes/interactive/components/index.d.ts.map +1 -0
  443. package/dist/modes/interactive/components/index.js +34 -0
  444. package/dist/modes/interactive/components/index.js.map +1 -0
  445. package/dist/modes/interactive/components/keybinding-hints.d.ts +50 -0
  446. package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -0
  447. package/dist/modes/interactive/components/keybinding-hints.js +85 -0
  448. package/dist/modes/interactive/components/keybinding-hints.js.map +1 -0
  449. package/dist/modes/interactive/components/login-dialog.d.ts +42 -0
  450. package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -0
  451. package/dist/modes/interactive/components/login-dialog.js +139 -0
  452. package/dist/modes/interactive/components/login-dialog.js.map +1 -0
  453. package/dist/modes/interactive/components/mcp-selector.d.ts +31 -0
  454. package/dist/modes/interactive/components/mcp-selector.d.ts.map +1 -0
  455. package/dist/modes/interactive/components/mcp-selector.js +171 -0
  456. package/dist/modes/interactive/components/mcp-selector.js.map +1 -0
  457. package/dist/modes/interactive/components/model-selector.d.ts +51 -0
  458. package/dist/modes/interactive/components/model-selector.d.ts.map +1 -0
  459. package/dist/modes/interactive/components/model-selector.js +292 -0
  460. package/dist/modes/interactive/components/model-selector.js.map +1 -0
  461. package/dist/modes/interactive/components/oauth-selector.d.ts +19 -0
  462. package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -0
  463. package/dist/modes/interactive/components/oauth-selector.js +134 -0
  464. package/dist/modes/interactive/components/oauth-selector.js.map +1 -0
  465. package/dist/modes/interactive/components/scoped-models-selector.d.ts +49 -0
  466. package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -0
  467. package/dist/modes/interactive/components/scoped-models-selector.js +271 -0
  468. package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -0
  469. package/dist/modes/interactive/components/session-selector-search.d.ts +23 -0
  470. package/dist/modes/interactive/components/session-selector-search.d.ts.map +1 -0
  471. package/dist/modes/interactive/components/session-selector-search.js +155 -0
  472. package/dist/modes/interactive/components/session-selector-search.js.map +1 -0
  473. package/dist/modes/interactive/components/session-selector.d.ts +95 -0
  474. package/dist/modes/interactive/components/session-selector.d.ts.map +1 -0
  475. package/dist/modes/interactive/components/session-selector.js +839 -0
  476. package/dist/modes/interactive/components/session-selector.js.map +1 -0
  477. package/dist/modes/interactive/components/settings-selector.d.ts +60 -0
  478. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -0
  479. package/dist/modes/interactive/components/settings-selector.js +311 -0
  480. package/dist/modes/interactive/components/settings-selector.js.map +1 -0
  481. package/dist/modes/interactive/components/show-images-selector.d.ts +10 -0
  482. package/dist/modes/interactive/components/show-images-selector.d.ts.map +1 -0
  483. package/dist/modes/interactive/components/show-images-selector.js +34 -0
  484. package/dist/modes/interactive/components/show-images-selector.js.map +1 -0
  485. package/dist/modes/interactive/components/skill-invocation-message.d.ts +17 -0
  486. package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -0
  487. package/dist/modes/interactive/components/skill-invocation-message.js +45 -0
  488. package/dist/modes/interactive/components/skill-invocation-message.js.map +1 -0
  489. package/dist/modes/interactive/components/subagent-message.d.ts +91 -0
  490. package/dist/modes/interactive/components/subagent-message.d.ts.map +1 -0
  491. package/dist/modes/interactive/components/subagent-message.js +306 -0
  492. package/dist/modes/interactive/components/subagent-message.js.map +1 -0
  493. package/dist/modes/interactive/components/task-plan-message.d.ts +12 -0
  494. package/dist/modes/interactive/components/task-plan-message.d.ts.map +1 -0
  495. package/dist/modes/interactive/components/task-plan-message.js +61 -0
  496. package/dist/modes/interactive/components/task-plan-message.js.map +1 -0
  497. package/dist/modes/interactive/components/theme-selector.d.ts +11 -0
  498. package/dist/modes/interactive/components/theme-selector.d.ts.map +1 -0
  499. package/dist/modes/interactive/components/theme-selector.js +44 -0
  500. package/dist/modes/interactive/components/theme-selector.js.map +1 -0
  501. package/dist/modes/interactive/components/thinking-selector.d.ts +11 -0
  502. package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -0
  503. package/dist/modes/interactive/components/thinking-selector.js +46 -0
  504. package/dist/modes/interactive/components/thinking-selector.js.map +1 -0
  505. package/dist/modes/interactive/components/tool-execution.d.ts +78 -0
  506. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -0
  507. package/dist/modes/interactive/components/tool-execution.js +880 -0
  508. package/dist/modes/interactive/components/tool-execution.js.map +1 -0
  509. package/dist/modes/interactive/components/tree-selector.d.ts +70 -0
  510. package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -0
  511. package/dist/modes/interactive/components/tree-selector.js +921 -0
  512. package/dist/modes/interactive/components/tree-selector.js.map +1 -0
  513. package/dist/modes/interactive/components/user-message-selector.d.ts +30 -0
  514. package/dist/modes/interactive/components/user-message-selector.d.ts.map +1 -0
  515. package/dist/modes/interactive/components/user-message-selector.js +110 -0
  516. package/dist/modes/interactive/components/user-message-selector.js.map +1 -0
  517. package/dist/modes/interactive/components/user-message.d.ts +9 -0
  518. package/dist/modes/interactive/components/user-message.d.ts.map +1 -0
  519. package/dist/modes/interactive/components/user-message.js +27 -0
  520. package/dist/modes/interactive/components/user-message.js.map +1 -0
  521. package/dist/modes/interactive/components/visual-truncate.d.ts +24 -0
  522. package/dist/modes/interactive/components/visual-truncate.d.ts.map +1 -0
  523. package/dist/modes/interactive/components/visual-truncate.js +33 -0
  524. package/dist/modes/interactive/components/visual-truncate.js.map +1 -0
  525. package/dist/modes/interactive/interactive-mode.d.ts +453 -0
  526. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -0
  527. package/dist/modes/interactive/interactive-mode.js +8669 -0
  528. package/dist/modes/interactive/interactive-mode.js.map +1 -0
  529. package/dist/modes/interactive/theme/dark.json +85 -0
  530. package/dist/modes/interactive/theme/light.json +84 -0
  531. package/dist/modes/interactive/theme/theme-schema.json +335 -0
  532. package/dist/modes/interactive/theme/theme.d.ts +78 -0
  533. package/dist/modes/interactive/theme/theme.d.ts.map +1 -0
  534. package/dist/modes/interactive/theme/theme.js +944 -0
  535. package/dist/modes/interactive/theme/theme.js.map +1 -0
  536. package/dist/modes/print-mode.d.ts +28 -0
  537. package/dist/modes/print-mode.d.ts.map +1 -0
  538. package/dist/modes/print-mode.js +101 -0
  539. package/dist/modes/print-mode.js.map +1 -0
  540. package/dist/modes/rpc/rpc-client.d.ts +217 -0
  541. package/dist/modes/rpc/rpc-client.d.ts.map +1 -0
  542. package/dist/modes/rpc/rpc-client.js +404 -0
  543. package/dist/modes/rpc/rpc-client.js.map +1 -0
  544. package/dist/modes/rpc/rpc-mode.d.ts +20 -0
  545. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -0
  546. package/dist/modes/rpc/rpc-mode.js +580 -0
  547. package/dist/modes/rpc/rpc-mode.js.map +1 -0
  548. package/dist/modes/rpc/rpc-types.d.ts +409 -0
  549. package/dist/modes/rpc/rpc-types.d.ts.map +1 -0
  550. package/dist/modes/rpc/rpc-types.js +8 -0
  551. package/dist/modes/rpc/rpc-types.js.map +1 -0
  552. package/dist/utils/changelog.d.ts +21 -0
  553. package/dist/utils/changelog.d.ts.map +1 -0
  554. package/dist/utils/changelog.js +87 -0
  555. package/dist/utils/changelog.js.map +1 -0
  556. package/dist/utils/clipboard-image.d.ts +11 -0
  557. package/dist/utils/clipboard-image.d.ts.map +1 -0
  558. package/dist/utils/clipboard-image.js +162 -0
  559. package/dist/utils/clipboard-image.js.map +1 -0
  560. package/dist/utils/clipboard-native.d.ts +7 -0
  561. package/dist/utils/clipboard-native.d.ts.map +1 -0
  562. package/dist/utils/clipboard-native.js +14 -0
  563. package/dist/utils/clipboard-native.js.map +1 -0
  564. package/dist/utils/clipboard.d.ts +2 -0
  565. package/dist/utils/clipboard.d.ts.map +1 -0
  566. package/dist/utils/clipboard.js +67 -0
  567. package/dist/utils/clipboard.js.map +1 -0
  568. package/dist/utils/frontmatter.d.ts +8 -0
  569. package/dist/utils/frontmatter.d.ts.map +1 -0
  570. package/dist/utils/frontmatter.js +26 -0
  571. package/dist/utils/frontmatter.js.map +1 -0
  572. package/dist/utils/git.d.ts +26 -0
  573. package/dist/utils/git.d.ts.map +1 -0
  574. package/dist/utils/git.js +163 -0
  575. package/dist/utils/git.js.map +1 -0
  576. package/dist/utils/image-convert.d.ts +9 -0
  577. package/dist/utils/image-convert.d.ts.map +1 -0
  578. package/dist/utils/image-convert.js +35 -0
  579. package/dist/utils/image-convert.js.map +1 -0
  580. package/dist/utils/image-resize.d.ts +36 -0
  581. package/dist/utils/image-resize.d.ts.map +1 -0
  582. package/dist/utils/image-resize.js +181 -0
  583. package/dist/utils/image-resize.js.map +1 -0
  584. package/dist/utils/mime.d.ts +2 -0
  585. package/dist/utils/mime.d.ts.map +1 -0
  586. package/dist/utils/mime.js +26 -0
  587. package/dist/utils/mime.js.map +1 -0
  588. package/dist/utils/photon.d.ts +21 -0
  589. package/dist/utils/photon.d.ts.map +1 -0
  590. package/dist/utils/photon.js +121 -0
  591. package/dist/utils/photon.js.map +1 -0
  592. package/dist/utils/shell.d.ts +26 -0
  593. package/dist/utils/shell.d.ts.map +1 -0
  594. package/dist/utils/shell.js +186 -0
  595. package/dist/utils/shell.js.map +1 -0
  596. package/dist/utils/sleep.d.ts +5 -0
  597. package/dist/utils/sleep.d.ts.map +1 -0
  598. package/dist/utils/sleep.js +17 -0
  599. package/dist/utils/sleep.js.map +1 -0
  600. package/dist/utils/tools-manager.d.ts +3 -0
  601. package/dist/utils/tools-manager.d.ts.map +1 -0
  602. package/dist/utils/tools-manager.js +251 -0
  603. package/dist/utils/tools-manager.js.map +1 -0
  604. package/docs/README.md +32 -0
  605. package/docs/cli-reference.md +342 -0
  606. package/docs/configuration.md +301 -0
  607. package/docs/development-and-testing.md +295 -0
  608. package/docs/extensions-packages-themes.md +415 -0
  609. package/docs/getting-started.md +246 -0
  610. package/docs/interactive-mode.md +272 -0
  611. package/docs/iosm-init-and-cycles.md +355 -0
  612. package/docs/orchestration-and-subagents.md +273 -0
  613. package/docs/rpc-json-sdk.md +353 -0
  614. package/docs/sessions-traces-export.md +260 -0
  615. package/examples/README.md +120 -0
  616. package/examples/extensions/README.md +306 -0
  617. package/examples/extensions/antigravity-image-gen.ts +415 -0
  618. package/examples/extensions/auto-commit-on-exit.ts +49 -0
  619. package/examples/extensions/bash-spawn-hook.ts +30 -0
  620. package/examples/extensions/bookmark.ts +50 -0
  621. package/examples/extensions/built-in-tool-renderer.ts +246 -0
  622. package/examples/extensions/claude-rules.ts +86 -0
  623. package/examples/extensions/commands.ts +72 -0
  624. package/examples/extensions/confirm-destructive.ts +59 -0
  625. package/examples/extensions/custom-compaction.ts +114 -0
  626. package/examples/extensions/custom-footer.ts +64 -0
  627. package/examples/extensions/custom-header.ts +73 -0
  628. package/examples/extensions/custom-provider-anthropic/index.ts +604 -0
  629. package/examples/extensions/custom-provider-anthropic/package-lock.json +24 -0
  630. package/examples/extensions/custom-provider-anthropic/package.json +19 -0
  631. package/examples/extensions/custom-provider-gitlab-duo/index.ts +349 -0
  632. package/examples/extensions/custom-provider-gitlab-duo/package.json +16 -0
  633. package/examples/extensions/custom-provider-gitlab-duo/test.ts +82 -0
  634. package/examples/extensions/custom-provider-qwen-cli/index.ts +345 -0
  635. package/examples/extensions/custom-provider-qwen-cli/package.json +16 -0
  636. package/examples/extensions/dirty-repo-guard.ts +56 -0
  637. package/examples/extensions/doom-overlay/README.md +46 -0
  638. package/examples/extensions/doom-overlay/doom/build/doom.js +21 -0
  639. package/examples/extensions/doom-overlay/doom/build/doom.wasm +0 -0
  640. package/examples/extensions/doom-overlay/doom/build.sh +152 -0
  641. package/examples/extensions/doom-overlay/doom/doomgeneric_pi.c +72 -0
  642. package/examples/extensions/doom-overlay/doom-component.ts +132 -0
  643. package/examples/extensions/doom-overlay/doom-engine.ts +173 -0
  644. package/examples/extensions/doom-overlay/doom-keys.ts +104 -0
  645. package/examples/extensions/doom-overlay/index.ts +74 -0
  646. package/examples/extensions/doom-overlay/wad-finder.ts +51 -0
  647. package/examples/extensions/dynamic-resources/SKILL.md +8 -0
  648. package/examples/extensions/dynamic-resources/dynamic.json +79 -0
  649. package/examples/extensions/dynamic-resources/dynamic.md +5 -0
  650. package/examples/extensions/dynamic-resources/index.ts +15 -0
  651. package/examples/extensions/dynamic-tools.ts +74 -0
  652. package/examples/extensions/event-bus.ts +43 -0
  653. package/examples/extensions/file-trigger.ts +41 -0
  654. package/examples/extensions/git-checkpoint.ts +53 -0
  655. package/examples/extensions/handoff.ts +150 -0
  656. package/examples/extensions/hello.ts +25 -0
  657. package/examples/extensions/inline-bash.ts +94 -0
  658. package/examples/extensions/input-transform.ts +43 -0
  659. package/examples/extensions/interactive-shell.ts +196 -0
  660. package/examples/extensions/mac-system-theme.ts +47 -0
  661. package/examples/extensions/message-renderer.ts +59 -0
  662. package/examples/extensions/minimal-mode.ts +426 -0
  663. package/examples/extensions/modal-editor.ts +85 -0
  664. package/examples/extensions/model-status.ts +31 -0
  665. package/examples/extensions/notify.ts +55 -0
  666. package/examples/extensions/overlay-qa-tests.ts +881 -0
  667. package/examples/extensions/overlay-test.ts +150 -0
  668. package/examples/extensions/permission-gate.ts +34 -0
  669. package/examples/extensions/pirate.ts +47 -0
  670. package/examples/extensions/plan-mode/README.md +65 -0
  671. package/examples/extensions/plan-mode/index.ts +340 -0
  672. package/examples/extensions/plan-mode/utils.ts +168 -0
  673. package/examples/extensions/preset.ts +398 -0
  674. package/examples/extensions/protected-paths.ts +30 -0
  675. package/examples/extensions/qna.ts +119 -0
  676. package/examples/extensions/question.ts +264 -0
  677. package/examples/extensions/questionnaire.ts +427 -0
  678. package/examples/extensions/rainbow-editor.ts +88 -0
  679. package/examples/extensions/reload-runtime.ts +37 -0
  680. package/examples/extensions/rpc-demo.ts +124 -0
  681. package/examples/extensions/sandbox/index.ts +318 -0
  682. package/examples/extensions/sandbox/package-lock.json +92 -0
  683. package/examples/extensions/sandbox/package.json +19 -0
  684. package/examples/extensions/send-user-message.ts +97 -0
  685. package/examples/extensions/session-name.ts +27 -0
  686. package/examples/extensions/shutdown-command.ts +63 -0
  687. package/examples/extensions/snake.ts +343 -0
  688. package/examples/extensions/space-invaders.ts +560 -0
  689. package/examples/extensions/ssh.ts +220 -0
  690. package/examples/extensions/status-line.ts +40 -0
  691. package/examples/extensions/subagent/README.md +172 -0
  692. package/examples/extensions/subagent/agents/planner.md +37 -0
  693. package/examples/extensions/subagent/agents/reviewer.md +35 -0
  694. package/examples/extensions/subagent/agents/scout.md +50 -0
  695. package/examples/extensions/subagent/agents/worker.md +24 -0
  696. package/examples/extensions/subagent/agents.ts +126 -0
  697. package/examples/extensions/subagent/index.ts +964 -0
  698. package/examples/extensions/subagent/prompts/implement-and-review.md +10 -0
  699. package/examples/extensions/subagent/prompts/implement.md +10 -0
  700. package/examples/extensions/subagent/prompts/scout-and-plan.md +9 -0
  701. package/examples/extensions/summarize.ts +195 -0
  702. package/examples/extensions/system-prompt-header.ts +17 -0
  703. package/examples/extensions/timed-confirm.ts +70 -0
  704. package/examples/extensions/titlebar-spinner.ts +58 -0
  705. package/examples/extensions/todo.ts +299 -0
  706. package/examples/extensions/tool-override.ts +143 -0
  707. package/examples/extensions/tools.ts +146 -0
  708. package/examples/extensions/trigger-compact.ts +40 -0
  709. package/examples/extensions/truncated-tool.ts +192 -0
  710. package/examples/extensions/widget-placement.ts +17 -0
  711. package/examples/extensions/with-deps/index.ts +36 -0
  712. package/examples/extensions/with-deps/package-lock.json +31 -0
  713. package/examples/extensions/with-deps/package.json +22 -0
  714. package/examples/rpc-extension-ui.ts +632 -0
  715. package/examples/sdk/01-minimal.ts +22 -0
  716. package/examples/sdk/02-custom-model.ts +49 -0
  717. package/examples/sdk/03-custom-prompt.ts +55 -0
  718. package/examples/sdk/04-skills.ts +46 -0
  719. package/examples/sdk/05-tools.ts +56 -0
  720. package/examples/sdk/06-extensions.ts +88 -0
  721. package/examples/sdk/07-context-files.ts +40 -0
  722. package/examples/sdk/08-prompt-templates.ts +47 -0
  723. package/examples/sdk/09-api-keys-and-oauth.ts +48 -0
  724. package/examples/sdk/10-settings.ts +51 -0
  725. package/examples/sdk/11-sessions.ts +48 -0
  726. package/examples/sdk/12-full-control.ts +82 -0
  727. package/examples/sdk/README.md +337 -0
  728. package/examples/tsconfig.json +3 -0
  729. package/package.json +107 -0
@@ -0,0 +1,880 @@
1
+ import * as os from "node:os";
2
+ import { Box, Container, getCapabilities, getImageDimensions, Image, imageFallback, Spacer, Text, truncateToWidth, } from "@mariozechner/pi-tui";
3
+ import stripAnsi from "strip-ansi";
4
+ import { computeEditDiff } from "../../../core/tools/edit-diff.js";
5
+ import { allTools } from "../../../core/tools/index.js";
6
+ import { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize } from "../../../core/tools/truncate.js";
7
+ import { convertToPng } from "../../../utils/image-convert.js";
8
+ import { sanitizeBinaryOutput } from "../../../utils/shell.js";
9
+ import { getLanguageFromPath, highlightCode, theme } from "../theme/theme.js";
10
+ import { renderDiff } from "./diff.js";
11
+ import { keyHint } from "./keybinding-hints.js";
12
+ import { truncateToVisualLines } from "./visual-truncate.js";
13
+ // Preview line limit for bash when not expanded
14
+ const BASH_PREVIEW_LINES = 5;
15
+ // During partial write tool-call streaming, re-highlight the first N lines fully
16
+ // to keep multiline tokenization mostly correct without re-highlighting the full file.
17
+ const WRITE_PARTIAL_FULL_HIGHLIGHT_LINES = 50;
18
+ /**
19
+ * Convert absolute path to tilde notation if it's in home directory
20
+ */
21
+ function shortenPath(path) {
22
+ if (typeof path !== "string")
23
+ return "";
24
+ const home = os.homedir();
25
+ if (path.startsWith(home)) {
26
+ return `~${path.slice(home.length)}`;
27
+ }
28
+ return path;
29
+ }
30
+ /**
31
+ * Replace tabs with spaces for consistent rendering
32
+ */
33
+ function replaceTabs(text) {
34
+ return text.replace(/\t/g, " ");
35
+ }
36
+ /**
37
+ * Normalize control characters for terminal preview rendering.
38
+ * Keep tool arguments unchanged, sanitize only display text.
39
+ */
40
+ function normalizeDisplayText(text) {
41
+ return text.replace(/\r/g, "");
42
+ }
43
+ /** Safely coerce value to string for display. Returns null if invalid type. */
44
+ function str(value) {
45
+ if (typeof value === "string")
46
+ return value;
47
+ if (value == null)
48
+ return "";
49
+ return null; // Invalid type
50
+ }
51
+ function toolBadge(label, state) {
52
+ const color = state === "error" ? "error" : state === "success" ? "accent" : "muted";
53
+ return theme.fg("dim", "[") + theme.fg(color, label) + theme.fg("dim", "]");
54
+ }
55
+ function toolHeader(label, subject, state, meta) {
56
+ const nestColor = state === "error" ? "error" : state === "success" ? "accent" : "dim";
57
+ const parts = [toolBadge(label, state)];
58
+ if (subject)
59
+ parts.push(subject);
60
+ if (meta)
61
+ parts.push(theme.fg("muted", meta));
62
+ return theme.fg(nestColor, "\u23BF ") + parts.join(" ");
63
+ }
64
+ function expandHint(remaining, total) {
65
+ const totalSuffix = total !== undefined ? `, ${total} total` : "";
66
+ return `${theme.fg("muted", `\n... (${remaining} more lines${totalSuffix},`)} ${keyHint("expandTools", "to expand")})`;
67
+ }
68
+ /**
69
+ * Component that renders a tool call with its result (updateable)
70
+ */
71
+ export class ToolExecutionComponent extends Container {
72
+ constructor(toolName, args, options = {}, toolDefinition, ui, cwd = process.cwd()) {
73
+ super();
74
+ this.imageComponents = [];
75
+ this.imageSpacers = [];
76
+ this.expanded = false;
77
+ this.isPartial = true;
78
+ // Cached converted images for Kitty protocol (which requires PNG), keyed by index
79
+ this.convertedImages = new Map();
80
+ // When true, this component intentionally renders no lines
81
+ this.hideComponent = false;
82
+ this.toolName = toolName;
83
+ this.args = args;
84
+ this.showImages = options.showImages ?? true;
85
+ this.toolDefinition = toolDefinition;
86
+ this.ui = ui;
87
+ this.cwd = cwd;
88
+ this.addChild(new Spacer(1));
89
+ // Always create both - contentBox for custom tools/bash, contentText for other built-ins
90
+ this.contentBox = new Box(1, 1, (text) => theme.bg("toolPendingBg", text));
91
+ this.contentText = new Text("", 1, 1, (text) => theme.bg("toolPendingBg", text));
92
+ // Use contentBox for bash (visual truncation) or custom tools with custom renderers
93
+ // Use contentText for built-in tools (including overrides without custom renderers)
94
+ if (toolName === "bash" || (toolDefinition && !this.shouldUseBuiltInRenderer())) {
95
+ this.addChild(this.contentBox);
96
+ }
97
+ else {
98
+ this.addChild(this.contentText);
99
+ }
100
+ this.updateDisplay();
101
+ }
102
+ /**
103
+ * Check if we should use built-in rendering for this tool.
104
+ * Returns true if the tool name is a built-in AND either there's no toolDefinition
105
+ * or the toolDefinition doesn't provide custom renderers.
106
+ */
107
+ shouldUseBuiltInRenderer() {
108
+ const isBuiltInName = this.toolName in allTools;
109
+ const hasCustomRenderers = this.toolDefinition?.renderCall || this.toolDefinition?.renderResult;
110
+ return isBuiltInName && !hasCustomRenderers;
111
+ }
112
+ updateArgs(args) {
113
+ this.args = args;
114
+ if (this.toolName === "write" && this.isPartial) {
115
+ this.updateWriteHighlightCacheIncremental();
116
+ }
117
+ this.updateDisplay();
118
+ }
119
+ highlightSingleLine(line, lang) {
120
+ const highlighted = highlightCode(line, lang);
121
+ return highlighted[0] ?? "";
122
+ }
123
+ refreshWriteHighlightPrefix(cache) {
124
+ const prefixCount = Math.min(WRITE_PARTIAL_FULL_HIGHLIGHT_LINES, cache.normalizedLines.length);
125
+ if (prefixCount === 0)
126
+ return;
127
+ const prefixSource = cache.normalizedLines.slice(0, prefixCount).join("\n");
128
+ const prefixHighlighted = highlightCode(prefixSource, cache.lang);
129
+ for (let i = 0; i < prefixCount; i++) {
130
+ cache.highlightedLines[i] =
131
+ prefixHighlighted[i] ?? this.highlightSingleLine(cache.normalizedLines[i] ?? "", cache.lang);
132
+ }
133
+ }
134
+ rebuildWriteHighlightCacheFull(rawPath, fileContent) {
135
+ const lang = rawPath ? getLanguageFromPath(rawPath) : undefined;
136
+ if (!lang) {
137
+ this.writeHighlightCache = undefined;
138
+ return;
139
+ }
140
+ const displayContent = normalizeDisplayText(fileContent);
141
+ const normalized = replaceTabs(displayContent);
142
+ this.writeHighlightCache = {
143
+ rawPath,
144
+ lang,
145
+ rawContent: fileContent,
146
+ normalizedLines: normalized.split("\n"),
147
+ highlightedLines: highlightCode(normalized, lang),
148
+ };
149
+ }
150
+ updateWriteHighlightCacheIncremental() {
151
+ const rawPath = str(this.args?.file_path ?? this.args?.path);
152
+ const fileContent = str(this.args?.content);
153
+ if (rawPath === null || fileContent === null) {
154
+ this.writeHighlightCache = undefined;
155
+ return;
156
+ }
157
+ const lang = rawPath ? getLanguageFromPath(rawPath) : undefined;
158
+ if (!lang) {
159
+ this.writeHighlightCache = undefined;
160
+ return;
161
+ }
162
+ if (!this.writeHighlightCache) {
163
+ this.rebuildWriteHighlightCacheFull(rawPath, fileContent);
164
+ return;
165
+ }
166
+ const cache = this.writeHighlightCache;
167
+ if (cache.lang !== lang || cache.rawPath !== rawPath) {
168
+ this.rebuildWriteHighlightCacheFull(rawPath, fileContent);
169
+ return;
170
+ }
171
+ if (!fileContent.startsWith(cache.rawContent)) {
172
+ this.rebuildWriteHighlightCacheFull(rawPath, fileContent);
173
+ return;
174
+ }
175
+ if (fileContent.length === cache.rawContent.length) {
176
+ return;
177
+ }
178
+ const deltaRaw = fileContent.slice(cache.rawContent.length);
179
+ const deltaDisplay = normalizeDisplayText(deltaRaw);
180
+ const deltaNormalized = replaceTabs(deltaDisplay);
181
+ cache.rawContent = fileContent;
182
+ if (cache.normalizedLines.length === 0) {
183
+ cache.normalizedLines.push("");
184
+ cache.highlightedLines.push("");
185
+ }
186
+ const segments = deltaNormalized.split("\n");
187
+ const lastIndex = cache.normalizedLines.length - 1;
188
+ cache.normalizedLines[lastIndex] += segments[0];
189
+ cache.highlightedLines[lastIndex] = this.highlightSingleLine(cache.normalizedLines[lastIndex], cache.lang);
190
+ for (let i = 1; i < segments.length; i++) {
191
+ cache.normalizedLines.push(segments[i]);
192
+ cache.highlightedLines.push(this.highlightSingleLine(segments[i], cache.lang));
193
+ }
194
+ this.refreshWriteHighlightPrefix(cache);
195
+ }
196
+ /**
197
+ * Signal that args are complete (tool is about to execute).
198
+ * This triggers diff computation for edit tool.
199
+ */
200
+ setArgsComplete() {
201
+ if (this.toolName === "write") {
202
+ const rawPath = str(this.args?.file_path ?? this.args?.path);
203
+ const fileContent = str(this.args?.content);
204
+ if (rawPath !== null && fileContent !== null) {
205
+ this.rebuildWriteHighlightCacheFull(rawPath, fileContent);
206
+ }
207
+ }
208
+ this.maybeComputeEditDiff();
209
+ }
210
+ /**
211
+ * Compute edit diff preview when we have complete args.
212
+ * This runs async and updates display when done.
213
+ */
214
+ maybeComputeEditDiff() {
215
+ if (this.toolName !== "edit")
216
+ return;
217
+ const path = this.args?.path;
218
+ const oldText = this.args?.oldText;
219
+ const newText = this.args?.newText;
220
+ // Need all three params to compute diff
221
+ if (!path || oldText === undefined || newText === undefined)
222
+ return;
223
+ // Create a key to track which args this computation is for
224
+ const argsKey = JSON.stringify({ path, oldText, newText });
225
+ // Skip if we already computed for these exact args
226
+ if (this.editDiffArgsKey === argsKey)
227
+ return;
228
+ this.editDiffArgsKey = argsKey;
229
+ // Compute diff async
230
+ computeEditDiff(path, oldText, newText, this.cwd).then((result) => {
231
+ // Only update if args haven't changed since we started
232
+ if (this.editDiffArgsKey === argsKey) {
233
+ this.editDiffPreview = result;
234
+ this.updateDisplay();
235
+ this.ui.requestRender();
236
+ }
237
+ });
238
+ }
239
+ updateResult(result, isPartial = false) {
240
+ this.result = result;
241
+ this.isPartial = isPartial;
242
+ if (this.toolName === "write" && !isPartial) {
243
+ const rawPath = str(this.args?.file_path ?? this.args?.path);
244
+ const fileContent = str(this.args?.content);
245
+ if (rawPath !== null && fileContent !== null) {
246
+ this.rebuildWriteHighlightCacheFull(rawPath, fileContent);
247
+ }
248
+ }
249
+ this.updateDisplay();
250
+ // Convert non-PNG images to PNG for Kitty protocol (async)
251
+ this.maybeConvertImagesForKitty();
252
+ }
253
+ /**
254
+ * Convert non-PNG images to PNG for Kitty graphics protocol.
255
+ * Kitty requires PNG format (f=100), so JPEG/GIF/WebP won't display.
256
+ */
257
+ maybeConvertImagesForKitty() {
258
+ const caps = getCapabilities();
259
+ // Only needed for Kitty protocol
260
+ if (caps.images !== "kitty")
261
+ return;
262
+ if (!this.result)
263
+ return;
264
+ const imageBlocks = this.result.content?.filter((c) => c.type === "image") || [];
265
+ for (let i = 0; i < imageBlocks.length; i++) {
266
+ const img = imageBlocks[i];
267
+ if (!img.data || !img.mimeType)
268
+ continue;
269
+ // Skip if already PNG or already converted
270
+ if (img.mimeType === "image/png")
271
+ continue;
272
+ if (this.convertedImages.has(i))
273
+ continue;
274
+ // Convert async
275
+ const index = i;
276
+ convertToPng(img.data, img.mimeType).then((converted) => {
277
+ if (converted) {
278
+ this.convertedImages.set(index, converted);
279
+ this.updateDisplay();
280
+ this.ui.requestRender();
281
+ }
282
+ });
283
+ }
284
+ }
285
+ setExpanded(expanded) {
286
+ this.expanded = expanded;
287
+ this.updateDisplay();
288
+ }
289
+ setShowImages(show) {
290
+ this.showImages = show;
291
+ this.updateDisplay();
292
+ }
293
+ invalidate() {
294
+ super.invalidate();
295
+ this.updateDisplay();
296
+ }
297
+ render(width) {
298
+ if (this.hideComponent) {
299
+ return [];
300
+ }
301
+ return super.render(width);
302
+ }
303
+ updateDisplay() {
304
+ // Set background based on state
305
+ const bgFn = this.isPartial
306
+ ? (text) => theme.bg("toolPendingBg", text)
307
+ : this.result?.isError
308
+ ? (text) => theme.bg("toolErrorBg", text)
309
+ : (text) => theme.bg("toolSuccessBg", text);
310
+ const useBuiltInRenderer = this.shouldUseBuiltInRenderer();
311
+ let customRendererHasContent = false;
312
+ this.hideComponent = false;
313
+ // Use built-in rendering for built-in tools (or overrides without custom renderers)
314
+ if (useBuiltInRenderer) {
315
+ if (this.toolName === "bash") {
316
+ // Bash uses Box with visual line truncation
317
+ this.contentBox.setBgFn(bgFn);
318
+ this.contentBox.clear();
319
+ this.renderBashContent();
320
+ }
321
+ else {
322
+ // Other built-in tools: use Text directly with caching
323
+ this.contentText.setCustomBgFn(bgFn);
324
+ this.contentText.setText(this.formatToolExecution());
325
+ }
326
+ }
327
+ else if (this.toolDefinition) {
328
+ // Custom tools use Box for flexible component rendering
329
+ this.contentBox.setBgFn(bgFn);
330
+ this.contentBox.clear();
331
+ // Render call component
332
+ if (this.toolDefinition.renderCall) {
333
+ try {
334
+ const callComponent = this.toolDefinition.renderCall(this.args, theme);
335
+ if (callComponent !== undefined) {
336
+ this.contentBox.addChild(callComponent);
337
+ customRendererHasContent = true;
338
+ }
339
+ }
340
+ catch {
341
+ // Fall back to default on error
342
+ this.contentBox.addChild(new Text(theme.fg("toolTitle", theme.bold(this.toolName)), 0, 0));
343
+ customRendererHasContent = true;
344
+ }
345
+ }
346
+ else {
347
+ // No custom renderCall, show tool name
348
+ this.contentBox.addChild(new Text(theme.fg("toolTitle", theme.bold(this.toolName)), 0, 0));
349
+ customRendererHasContent = true;
350
+ }
351
+ // Render result component if we have a result
352
+ if (this.result && this.toolDefinition.renderResult) {
353
+ try {
354
+ const resultComponent = this.toolDefinition.renderResult({ content: this.result.content, details: this.result.details }, { expanded: this.expanded, isPartial: this.isPartial }, theme);
355
+ if (resultComponent !== undefined) {
356
+ this.contentBox.addChild(resultComponent);
357
+ customRendererHasContent = true;
358
+ }
359
+ }
360
+ catch {
361
+ // Fall back to showing raw output on error
362
+ const output = this.getTextOutput();
363
+ if (output) {
364
+ this.contentBox.addChild(new Text(theme.fg("toolOutput", output), 0, 0));
365
+ customRendererHasContent = true;
366
+ }
367
+ }
368
+ }
369
+ else if (this.result) {
370
+ // Has result but no custom renderResult
371
+ const output = this.getTextOutput();
372
+ if (output) {
373
+ this.contentBox.addChild(new Text(theme.fg("toolOutput", output), 0, 0));
374
+ customRendererHasContent = true;
375
+ }
376
+ }
377
+ }
378
+ else {
379
+ // Unknown tool with no registered definition - show generic fallback
380
+ this.contentText.setCustomBgFn(bgFn);
381
+ this.contentText.setText(this.formatToolExecution());
382
+ }
383
+ // Handle images (same for both custom and built-in)
384
+ for (const img of this.imageComponents) {
385
+ this.removeChild(img);
386
+ }
387
+ this.imageComponents = [];
388
+ for (const spacer of this.imageSpacers) {
389
+ this.removeChild(spacer);
390
+ }
391
+ this.imageSpacers = [];
392
+ if (this.result) {
393
+ const imageBlocks = this.result.content?.filter((c) => c.type === "image") || [];
394
+ const caps = getCapabilities();
395
+ for (let i = 0; i < imageBlocks.length; i++) {
396
+ const img = imageBlocks[i];
397
+ if (caps.images && this.showImages && img.data && img.mimeType) {
398
+ // Use converted PNG for Kitty protocol if available
399
+ const converted = this.convertedImages.get(i);
400
+ const imageData = converted?.data ?? img.data;
401
+ const imageMimeType = converted?.mimeType ?? img.mimeType;
402
+ // For Kitty, skip non-PNG images that haven't been converted yet
403
+ if (caps.images === "kitty" && imageMimeType !== "image/png") {
404
+ continue;
405
+ }
406
+ const spacer = new Spacer(1);
407
+ this.addChild(spacer);
408
+ this.imageSpacers.push(spacer);
409
+ const imageComponent = new Image(imageData, imageMimeType, { fallbackColor: (s) => theme.fg("toolOutput", s) }, { maxWidthCells: 60 });
410
+ this.imageComponents.push(imageComponent);
411
+ this.addChild(imageComponent);
412
+ }
413
+ }
414
+ }
415
+ if (!useBuiltInRenderer && this.toolDefinition) {
416
+ this.hideComponent = !customRendererHasContent && this.imageComponents.length === 0;
417
+ }
418
+ }
419
+ /**
420
+ * Render bash content using visual line truncation (like bash-execution.ts).
421
+ * Uses compact Claude Code style: one-line header with ⎿ prefix.
422
+ */
423
+ renderBashContent() {
424
+ const command = str(this.args?.command);
425
+ const timeout = this.args?.timeout;
426
+ // Build the first line of the command (compact display)
427
+ const commandDisplay = command === null ? "[invalid arg]" : command ? command.split("\n")[0] : "...";
428
+ const timeoutSuffix = timeout ? ` (timeout ${timeout}s)` : "";
429
+ // Compact one-line header
430
+ let headerText;
431
+ if (this.isPartial) {
432
+ headerText = toolHeader("bash", `$ ${commandDisplay}${timeoutSuffix}`, "pending");
433
+ }
434
+ else if (this.result?.isError) {
435
+ const exitCode = this.result.details?.exitCode ?? 1;
436
+ headerText = toolHeader("bash", `$ ${commandDisplay}`, "error", `(exit ${exitCode})`);
437
+ }
438
+ else if (this.result) {
439
+ headerText = toolHeader("bash", `$ ${commandDisplay}`, "success", "(exit 0)");
440
+ }
441
+ else {
442
+ headerText = toolHeader("bash", `$ ${commandDisplay}${timeoutSuffix}`, "pending");
443
+ }
444
+ this.contentBox.addChild(new Text(headerText, 0, 0));
445
+ if (this.result) {
446
+ const output = this.getTextOutput().trim();
447
+ if (output) {
448
+ // Style each line for the output
449
+ const styledOutput = output
450
+ .split("\n")
451
+ .map((line) => theme.fg("toolOutput", line))
452
+ .join("\n");
453
+ if (this.expanded) {
454
+ // Show all lines when expanded
455
+ this.contentBox.addChild(new Text(`\n${styledOutput}`, 0, 0));
456
+ }
457
+ else {
458
+ // Use visual line truncation when collapsed with width-aware caching
459
+ let cachedWidth;
460
+ let cachedLines;
461
+ let cachedSkipped;
462
+ this.contentBox.addChild({
463
+ render: (width) => {
464
+ if (cachedLines === undefined || cachedWidth !== width) {
465
+ const result = truncateToVisualLines(styledOutput, BASH_PREVIEW_LINES, width);
466
+ cachedLines = result.visualLines;
467
+ cachedSkipped = result.skippedCount;
468
+ cachedWidth = width;
469
+ }
470
+ if (cachedSkipped && cachedSkipped > 0) {
471
+ const hint = expandHint(cachedSkipped);
472
+ return ["", truncateToWidth(hint, width, "..."), ...cachedLines];
473
+ }
474
+ // Add blank line for spacing (matches expanded case)
475
+ return ["", ...cachedLines];
476
+ },
477
+ invalidate: () => {
478
+ cachedWidth = undefined;
479
+ cachedLines = undefined;
480
+ cachedSkipped = undefined;
481
+ },
482
+ });
483
+ }
484
+ }
485
+ // Truncation warnings
486
+ const truncation = this.result.details?.truncation;
487
+ const fullOutputPath = this.result.details?.fullOutputPath;
488
+ if (truncation?.truncated || fullOutputPath) {
489
+ const warnings = [];
490
+ if (fullOutputPath) {
491
+ warnings.push(`Full output: ${fullOutputPath}`);
492
+ }
493
+ if (truncation?.truncated) {
494
+ if (truncation.truncatedBy === "lines") {
495
+ warnings.push(`Truncated: showing ${truncation.outputLines} of ${truncation.totalLines} lines`);
496
+ }
497
+ else {
498
+ warnings.push(`Truncated: ${truncation.outputLines} lines shown (${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit)`);
499
+ }
500
+ }
501
+ this.contentBox.addChild(new Text(`\n${theme.fg("warning", `[${warnings.join(". ")}]`)}`, 0, 0));
502
+ }
503
+ }
504
+ }
505
+ getTextOutput() {
506
+ if (!this.result)
507
+ return "";
508
+ const textBlocks = this.result.content?.filter((c) => c.type === "text") || [];
509
+ const imageBlocks = this.result.content?.filter((c) => c.type === "image") || [];
510
+ let output = textBlocks
511
+ .map((c) => {
512
+ // Use sanitizeBinaryOutput to handle binary data that crashes string-width
513
+ return sanitizeBinaryOutput(stripAnsi(c.text || "")).replace(/\r/g, "");
514
+ })
515
+ .join("\n");
516
+ const caps = getCapabilities();
517
+ if (imageBlocks.length > 0 && (!caps.images || !this.showImages)) {
518
+ const imageIndicators = imageBlocks
519
+ .map((img) => {
520
+ const dims = img.data ? (getImageDimensions(img.data, img.mimeType) ?? undefined) : undefined;
521
+ return imageFallback(img.mimeType, dims);
522
+ })
523
+ .join("\n");
524
+ output = output ? `${output}\n${imageIndicators}` : imageIndicators;
525
+ }
526
+ return output;
527
+ }
528
+ formatToolExecution() {
529
+ let text = "";
530
+ const invalidArg = theme.fg("error", "[invalid arg]");
531
+ if (this.toolName === "read") {
532
+ const rawPath = str(this.args?.file_path ?? this.args?.path);
533
+ const shortPath = rawPath !== null ? shortenPath(rawPath) : null;
534
+ const offset = this.args?.offset;
535
+ const limit = this.args?.limit;
536
+ const pathLabel = shortPath === null ? "[invalid arg]" : shortPath || "...";
537
+ // Build range suffix for path
538
+ let rangeSuffix = "";
539
+ if (offset !== undefined || limit !== undefined) {
540
+ const startLine = offset ?? 1;
541
+ const endLine = limit !== undefined ? startLine + limit - 1 : "";
542
+ rangeSuffix = `:${startLine}${endLine ? `-${endLine}` : ""}`;
543
+ }
544
+ if (this.isPartial) {
545
+ text = toolHeader("read", pathLabel + rangeSuffix, "pending");
546
+ }
547
+ else if (this.result?.isError) {
548
+ text = toolHeader("read", pathLabel + rangeSuffix, "error");
549
+ }
550
+ else if (this.result) {
551
+ const output = this.getTextOutput();
552
+ const lineCount = output ? output.split("\n").length : 0;
553
+ const subject = shortPath === null ? invalidArg : theme.fg("accent", pathLabel + rangeSuffix);
554
+ text = toolHeader("read", subject, "success", `(${lineCount} lines)`);
555
+ }
556
+ else {
557
+ text = toolHeader("read", pathLabel + rangeSuffix, "pending");
558
+ }
559
+ if (this.result && !this.result.isError) {
560
+ const output = this.getTextOutput();
561
+ const rawPathForLang = str(this.args?.file_path ?? this.args?.path);
562
+ const lang = rawPathForLang ? getLanguageFromPath(rawPathForLang) : undefined;
563
+ const lines = lang ? highlightCode(replaceTabs(output), lang) : output.split("\n");
564
+ const maxLines = this.expanded ? lines.length : 10;
565
+ const displayLines = lines.slice(0, maxLines);
566
+ const remaining = lines.length - maxLines;
567
+ text +=
568
+ "\n\n" +
569
+ displayLines
570
+ .map((line) => (lang ? replaceTabs(line) : theme.fg("toolOutput", replaceTabs(line))))
571
+ .join("\n");
572
+ if (remaining > 0) {
573
+ text += expandHint(remaining, lines.length);
574
+ }
575
+ const truncation = this.result.details?.truncation;
576
+ if (truncation?.truncated) {
577
+ if (truncation.firstLineExceedsLimit) {
578
+ text +=
579
+ "\n" +
580
+ theme.fg("warning", `[First line exceeds ${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit]`);
581
+ }
582
+ else if (truncation.truncatedBy === "lines") {
583
+ text +=
584
+ "\n" +
585
+ theme.fg("warning", `[Truncated: showing ${truncation.outputLines} of ${truncation.totalLines} lines (${truncation.maxLines ?? DEFAULT_MAX_LINES} line limit)]`);
586
+ }
587
+ else {
588
+ text +=
589
+ "\n" +
590
+ theme.fg("warning", `[Truncated: ${truncation.outputLines} lines shown (${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit)]`);
591
+ }
592
+ }
593
+ }
594
+ else if (this.result?.isError) {
595
+ const errorText = this.getTextOutput();
596
+ if (errorText) {
597
+ text += `\n\n${theme.fg("error", errorText)}`;
598
+ }
599
+ }
600
+ }
601
+ else if (this.toolName === "write") {
602
+ const rawPath = str(this.args?.file_path ?? this.args?.path);
603
+ const fileContent = str(this.args?.content);
604
+ const shortPath = rawPath !== null ? shortenPath(rawPath) : null;
605
+ const pathLabel = shortPath === null ? "[invalid arg]" : shortPath || "...";
606
+ if (this.isPartial) {
607
+ text = toolHeader("write", pathLabel, "pending");
608
+ }
609
+ else if (this.result?.isError) {
610
+ text = toolHeader("write", pathLabel, "error");
611
+ }
612
+ else if (this.result) {
613
+ // Count lines from args content (what was written)
614
+ const writtenLines = fileContent ? fileContent.split("\n").length : 0;
615
+ const subject = shortPath === null ? invalidArg : theme.fg("accent", pathLabel);
616
+ text = toolHeader("write", subject, "success", `(${writtenLines} lines)`);
617
+ }
618
+ else {
619
+ text = toolHeader("write", pathLabel, "pending");
620
+ }
621
+ if (fileContent === null) {
622
+ text += `\n\n${theme.fg("error", "[invalid content arg - expected string]")}`;
623
+ }
624
+ else if (fileContent) {
625
+ const lang = rawPath ? getLanguageFromPath(rawPath) : undefined;
626
+ let lines;
627
+ if (lang) {
628
+ const cache = this.writeHighlightCache;
629
+ if (cache && cache.lang === lang && cache.rawPath === rawPath && cache.rawContent === fileContent) {
630
+ lines = cache.highlightedLines;
631
+ }
632
+ else {
633
+ const displayContent = normalizeDisplayText(fileContent);
634
+ const normalized = replaceTabs(displayContent);
635
+ lines = highlightCode(normalized, lang);
636
+ this.writeHighlightCache = {
637
+ rawPath,
638
+ lang,
639
+ rawContent: fileContent,
640
+ normalizedLines: normalized.split("\n"),
641
+ highlightedLines: lines,
642
+ };
643
+ }
644
+ }
645
+ else {
646
+ lines = normalizeDisplayText(fileContent).split("\n");
647
+ this.writeHighlightCache = undefined;
648
+ }
649
+ const totalLines = lines.length;
650
+ const maxLines = this.expanded ? lines.length : 10;
651
+ const displayLines = lines.slice(0, maxLines);
652
+ const remaining = lines.length - maxLines;
653
+ text +=
654
+ "\n\n" +
655
+ displayLines.map((line) => (lang ? line : theme.fg("toolOutput", replaceTabs(line)))).join("\n");
656
+ if (remaining > 0) {
657
+ text += expandHint(remaining, totalLines);
658
+ }
659
+ }
660
+ // Show error if tool execution failed
661
+ if (this.result?.isError) {
662
+ const errorText = this.getTextOutput();
663
+ if (errorText) {
664
+ text += `\n\n${theme.fg("error", errorText)}`;
665
+ }
666
+ }
667
+ }
668
+ else if (this.toolName === "edit") {
669
+ const rawPath = str(this.args?.file_path ?? this.args?.path);
670
+ const shortPath = rawPath !== null ? shortenPath(rawPath) : null;
671
+ const pathLabel = shortPath === null ? "[invalid arg]" : shortPath || "...";
672
+ // Compute +X / -Y stats from diff if available
673
+ let diffStats = "";
674
+ const diff = this.result?.details?.diff ?? (this.editDiffPreview && !("error" in this.editDiffPreview) ? this.editDiffPreview.diff : undefined);
675
+ if (diff) {
676
+ const added = (diff.match(/^\+[^+]/mg) || []).length;
677
+ const removed = (diff.match(/^-[^-]/mg) || []).length;
678
+ if (added > 0 || removed > 0) {
679
+ diffStats = `(+${added} / -${removed} lines)`;
680
+ }
681
+ }
682
+ if (this.isPartial) {
683
+ text = toolHeader("edit", pathLabel, "pending");
684
+ }
685
+ else if (this.result?.isError) {
686
+ text = toolHeader("edit", pathLabel, "error", "(failed)");
687
+ }
688
+ else if (this.result) {
689
+ const subject = shortPath === null ? invalidArg : theme.fg("accent", pathLabel);
690
+ text = toolHeader("edit", subject, "success", diffStats || undefined);
691
+ }
692
+ else {
693
+ text = toolHeader("edit", pathLabel, "pending");
694
+ }
695
+ if (this.result?.isError) {
696
+ // Show error from result
697
+ const errorText = this.getTextOutput();
698
+ if (errorText) {
699
+ text += `\n\n${theme.fg("error", errorText)}`;
700
+ }
701
+ }
702
+ else if (this.result?.details?.diff) {
703
+ // Tool executed successfully - use the diff from result
704
+ text += `\n\n${renderDiff(this.result.details.diff, { filePath: rawPath ?? undefined })}`;
705
+ }
706
+ else if (this.editDiffPreview) {
707
+ // Use cached diff preview (before tool executes)
708
+ if ("error" in this.editDiffPreview) {
709
+ text += `\n\n${theme.fg("error", this.editDiffPreview.error)}`;
710
+ }
711
+ else if (this.editDiffPreview.diff) {
712
+ text += `\n\n${renderDiff(this.editDiffPreview.diff, { filePath: rawPath ?? undefined })}`;
713
+ }
714
+ }
715
+ }
716
+ else if (this.toolName === "ls") {
717
+ const rawPath = str(this.args?.path);
718
+ const shortPath = rawPath !== null ? shortenPath(rawPath || ".") : null;
719
+ const pathLabel = shortPath === null ? "[invalid arg]" : shortPath || ".";
720
+ if (this.isPartial) {
721
+ text = toolHeader("list", pathLabel, "pending");
722
+ }
723
+ else if (this.result?.isError) {
724
+ text = toolHeader("list", pathLabel, "error");
725
+ }
726
+ else if (this.result) {
727
+ const output = this.getTextOutput().trim();
728
+ const resultCount = output ? output.split("\n").filter(Boolean).length : 0;
729
+ const subject = shortPath === null ? invalidArg : theme.fg("accent", pathLabel);
730
+ text = toolHeader("list", subject, "success", `(${resultCount} entries)`);
731
+ }
732
+ else {
733
+ text = toolHeader("list", pathLabel, "pending");
734
+ }
735
+ if (this.result) {
736
+ const output = this.getTextOutput().trim();
737
+ if (output) {
738
+ const lines = output.split("\n");
739
+ const maxLines = this.expanded ? lines.length : 20;
740
+ const displayLines = lines.slice(0, maxLines);
741
+ const remaining = lines.length - maxLines;
742
+ text += `\n\n${displayLines.map((line) => theme.fg("toolOutput", line)).join("\n")}`;
743
+ if (remaining > 0) {
744
+ text += expandHint(remaining, lines.length);
745
+ }
746
+ }
747
+ const entryLimit = this.result.details?.entryLimitReached;
748
+ const truncation = this.result.details?.truncation;
749
+ if (entryLimit || truncation?.truncated) {
750
+ const warnings = [];
751
+ if (entryLimit) {
752
+ warnings.push(`${entryLimit} entries limit`);
753
+ }
754
+ if (truncation?.truncated) {
755
+ warnings.push(`${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit`);
756
+ }
757
+ text += `\n${theme.fg("warning", `[Truncated: ${warnings.join(", ")}]`)}`;
758
+ }
759
+ }
760
+ }
761
+ else if (this.toolName === "find") {
762
+ const pattern = str(this.args?.pattern);
763
+ const patternLabel = pattern === null ? "[invalid arg]" : pattern || "*";
764
+ const rawPath = str(this.args?.path);
765
+ const shortPath = rawPath !== null ? shortenPath(rawPath || ".") : null;
766
+ const pathLabel = shortPath === null ? "[invalid arg]" : shortPath || ".";
767
+ const subject = `${patternLabel} ${theme.fg("muted", "in")} ${shortPath === null ? invalidArg : theme.fg("accent", pathLabel)}`;
768
+ if (this.isPartial) {
769
+ text = toolHeader("find", subject, "pending");
770
+ }
771
+ else if (this.result?.isError) {
772
+ text = toolHeader("find", subject, "error");
773
+ }
774
+ else if (this.result) {
775
+ const output = this.getTextOutput().trim();
776
+ const resultCount = output ? output.split("\n").filter(Boolean).length : 0;
777
+ text = toolHeader("find", subject, "success", `(${resultCount} results)`);
778
+ }
779
+ else {
780
+ text = toolHeader("find", subject, "pending");
781
+ }
782
+ if (this.result) {
783
+ const output = this.getTextOutput().trim();
784
+ if (output) {
785
+ const lines = output.split("\n");
786
+ const maxLines = this.expanded ? lines.length : 20;
787
+ const displayLines = lines.slice(0, maxLines);
788
+ const remaining = lines.length - maxLines;
789
+ text += `\n\n${displayLines.map((line) => theme.fg("toolOutput", line)).join("\n")}`;
790
+ if (remaining > 0) {
791
+ text += expandHint(remaining, lines.length);
792
+ }
793
+ }
794
+ const resultLimit = this.result.details?.resultLimitReached;
795
+ const truncation = this.result.details?.truncation;
796
+ if (resultLimit || truncation?.truncated) {
797
+ const warnings = [];
798
+ if (resultLimit) {
799
+ warnings.push(`${resultLimit} results limit`);
800
+ }
801
+ if (truncation?.truncated) {
802
+ warnings.push(`${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit`);
803
+ }
804
+ text += `\n${theme.fg("warning", `[Truncated: ${warnings.join(", ")}]`)}`;
805
+ }
806
+ }
807
+ }
808
+ else if (this.toolName === "grep") {
809
+ const pattern = str(this.args?.pattern);
810
+ const patternLabel = pattern === null ? "[invalid arg]" : pattern || "";
811
+ const rawPath = str(this.args?.path);
812
+ const shortPath = rawPath !== null ? shortenPath(rawPath || ".") : null;
813
+ const glob = str(this.args?.glob);
814
+ const limit = this.args?.limit;
815
+ const locationContext = shortPath !== null ? ` in ${shortPath}` : "";
816
+ const globContext = glob ? ` (${glob})` : "";
817
+ const limitContext = limit !== undefined ? ` limit ${limit}` : "";
818
+ if (this.isPartial) {
819
+ text = toolHeader("grep", patternLabel, "pending", `${locationContext}${globContext}${limitContext}`.trim());
820
+ }
821
+ else if (this.result?.isError) {
822
+ text = toolHeader("grep", patternLabel, "error", `${locationContext}${globContext}${limitContext}`.trim());
823
+ }
824
+ else if (this.result) {
825
+ const output = this.getTextOutput().trim();
826
+ const matchCount = output ? output.split("\n").filter(Boolean).length : 0;
827
+ const subject = pattern === null ? invalidArg : theme.fg("accent", patternLabel);
828
+ const metaParts = [`(${matchCount} matches)`];
829
+ if (locationContext || globContext || limitContext) {
830
+ metaParts.push(`${locationContext}${globContext}${limitContext}`.trim());
831
+ }
832
+ text = toolHeader("grep", subject, "success", metaParts.join(" "));
833
+ }
834
+ else {
835
+ text = toolHeader("grep", patternLabel, "pending", `${locationContext}${globContext}${limitContext}`.trim());
836
+ }
837
+ if (this.result) {
838
+ const output = this.getTextOutput().trim();
839
+ if (output) {
840
+ const lines = output.split("\n");
841
+ const maxLines = this.expanded ? lines.length : 15;
842
+ const displayLines = lines.slice(0, maxLines);
843
+ const remaining = lines.length - maxLines;
844
+ text += `\n\n${displayLines.map((line) => theme.fg("toolOutput", line)).join("\n")}`;
845
+ if (remaining > 0) {
846
+ text += expandHint(remaining, lines.length);
847
+ }
848
+ }
849
+ const matchLimit = this.result.details?.matchLimitReached;
850
+ const truncation = this.result.details?.truncation;
851
+ const linesTruncated = this.result.details?.linesTruncated;
852
+ if (matchLimit || truncation?.truncated || linesTruncated) {
853
+ const warnings = [];
854
+ if (matchLimit) {
855
+ warnings.push(`${matchLimit} matches limit`);
856
+ }
857
+ if (truncation?.truncated) {
858
+ warnings.push(`${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit`);
859
+ }
860
+ if (linesTruncated) {
861
+ warnings.push("some lines truncated");
862
+ }
863
+ text += `\n${theme.fg("warning", `[Truncated: ${warnings.join(", ")}]`)}`;
864
+ }
865
+ }
866
+ }
867
+ else {
868
+ // Generic tool (shouldn't reach here for custom tools)
869
+ text = theme.fg("toolTitle", theme.bold(this.toolName));
870
+ const content = JSON.stringify(this.args, null, 2);
871
+ text += `\n\n${content}`;
872
+ const output = this.getTextOutput();
873
+ if (output) {
874
+ text += `\n${output}`;
875
+ }
876
+ }
877
+ return text;
878
+ }
879
+ }
880
+ //# sourceMappingURL=tool-execution.js.map