@hyperspaceng/neural-coding-agent 0.62.1 → 0.63.2

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 (374) hide show
  1. package/CHANGELOG.md +143 -0
  2. package/README.md +10 -0
  3. package/dist/bun/register-bedrock.d.ts.map +1 -1
  4. package/dist/bun/register-bedrock.js +2 -2
  5. package/dist/bun/register-bedrock.js.map +1 -1
  6. package/dist/cli/args.d.ts +1 -1
  7. package/dist/cli/args.d.ts.map +1 -1
  8. package/dist/cli/args.js.map +1 -1
  9. package/dist/cli/config-selector.d.ts.map +1 -1
  10. package/dist/cli/config-selector.js +1 -1
  11. package/dist/cli/config-selector.js.map +1 -1
  12. package/dist/cli/file-processor.d.ts +1 -1
  13. package/dist/cli/file-processor.d.ts.map +1 -1
  14. package/dist/cli/file-processor.js +4 -0
  15. package/dist/cli/file-processor.js.map +1 -1
  16. package/dist/cli/initial-message.d.ts +1 -1
  17. package/dist/cli/initial-message.d.ts.map +1 -1
  18. package/dist/cli/initial-message.js.map +1 -1
  19. package/dist/cli/list-models.d.ts.map +1 -1
  20. package/dist/cli/list-models.js +1 -1
  21. package/dist/cli/list-models.js.map +1 -1
  22. package/dist/cli/session-picker.d.ts.map +1 -1
  23. package/dist/cli/session-picker.js +1 -1
  24. package/dist/cli/session-picker.js.map +1 -1
  25. package/dist/core/agent-session.d.ts +21 -11
  26. package/dist/core/agent-session.d.ts.map +1 -1
  27. package/dist/core/agent-session.js +159 -101
  28. package/dist/core/agent-session.js.map +1 -1
  29. package/dist/core/auth-storage.d.ts +5 -3
  30. package/dist/core/auth-storage.d.ts.map +1 -1
  31. package/dist/core/auth-storage.js +7 -4
  32. package/dist/core/auth-storage.js.map +1 -1
  33. package/dist/core/compaction/branch-summarization.d.ts +4 -2
  34. package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
  35. package/dist/core/compaction/branch-summarization.js +3 -3
  36. package/dist/core/compaction/branch-summarization.js.map +1 -1
  37. package/dist/core/compaction/compaction.d.ts +5 -5
  38. package/dist/core/compaction/compaction.d.ts.map +1 -1
  39. package/dist/core/compaction/compaction.js +28 -27
  40. package/dist/core/compaction/compaction.js.map +1 -1
  41. package/dist/core/compaction/utils.d.ts +2 -2
  42. package/dist/core/compaction/utils.d.ts.map +1 -1
  43. package/dist/core/compaction/utils.js.map +1 -1
  44. package/dist/core/defaults.d.ts +1 -1
  45. package/dist/core/defaults.d.ts.map +1 -1
  46. package/dist/core/defaults.js.map +1 -1
  47. package/dist/core/export-html/index.d.ts +3 -3
  48. package/dist/core/export-html/index.d.ts.map +1 -1
  49. package/dist/core/export-html/index.js +7 -6
  50. package/dist/core/export-html/index.js.map +1 -1
  51. package/dist/core/export-html/tool-renderer.d.ts +2 -2
  52. package/dist/core/export-html/tool-renderer.d.ts.map +1 -1
  53. package/dist/core/export-html/tool-renderer.js +41 -16
  54. package/dist/core/export-html/tool-renderer.js.map +1 -1
  55. package/dist/core/extensions/index.d.ts +3 -2
  56. package/dist/core/extensions/index.d.ts.map +1 -1
  57. package/dist/core/extensions/index.js.map +1 -1
  58. package/dist/core/extensions/loader.d.ts.map +1 -1
  59. package/dist/core/extensions/loader.js +27 -17
  60. package/dist/core/extensions/loader.js.map +1 -1
  61. package/dist/core/extensions/runner.d.ts +7 -10
  62. package/dist/core/extensions/runner.d.ts.map +1 -1
  63. package/dist/core/extensions/runner.js +27 -38
  64. package/dist/core/extensions/runner.js.map +1 -1
  65. package/dist/core/extensions/types.d.ts +56 -15
  66. package/dist/core/extensions/types.d.ts.map +1 -1
  67. package/dist/core/extensions/types.js.map +1 -1
  68. package/dist/core/extensions/wrapper.d.ts +1 -1
  69. package/dist/core/extensions/wrapper.d.ts.map +1 -1
  70. package/dist/core/extensions/wrapper.js +2 -8
  71. package/dist/core/extensions/wrapper.js.map +1 -1
  72. package/dist/core/index.d.ts +2 -1
  73. package/dist/core/index.d.ts.map +1 -1
  74. package/dist/core/index.js +1 -0
  75. package/dist/core/index.js.map +1 -1
  76. package/dist/core/keybindings.d.ts +2 -2
  77. package/dist/core/keybindings.d.ts.map +1 -1
  78. package/dist/core/keybindings.js +1 -1
  79. package/dist/core/keybindings.js.map +1 -1
  80. package/dist/core/messages.d.ts +3 -3
  81. package/dist/core/messages.d.ts.map +1 -1
  82. package/dist/core/messages.js.map +1 -1
  83. package/dist/core/model-registry.d.ts +19 -3
  84. package/dist/core/model-registry.d.ts.map +1 -1
  85. package/dist/core/model-registry.js +85 -71
  86. package/dist/core/model-registry.js.map +1 -1
  87. package/dist/core/model-resolver.d.ts +2 -2
  88. package/dist/core/model-resolver.d.ts.map +1 -1
  89. package/dist/core/model-resolver.js +5 -5
  90. package/dist/core/model-resolver.js.map +1 -1
  91. package/dist/core/output-guard.d.ts +6 -0
  92. package/dist/core/output-guard.d.ts.map +1 -0
  93. package/dist/core/output-guard.js +59 -0
  94. package/dist/core/output-guard.js.map +1 -0
  95. package/dist/core/package-manager.d.ts +3 -0
  96. package/dist/core/package-manager.d.ts.map +1 -1
  97. package/dist/core/package-manager.js +153 -29
  98. package/dist/core/package-manager.js.map +1 -1
  99. package/dist/core/prompt-templates.d.ts +2 -1
  100. package/dist/core/prompt-templates.d.ts.map +1 -1
  101. package/dist/core/prompt-templates.js +30 -32
  102. package/dist/core/prompt-templates.js.map +1 -1
  103. package/dist/core/resolve-config-value.d.ts +6 -0
  104. package/dist/core/resolve-config-value.d.ts.map +1 -1
  105. package/dist/core/resolve-config-value.js +37 -5
  106. package/dist/core/resolve-config-value.js.map +1 -1
  107. package/dist/core/resource-loader.d.ts +6 -5
  108. package/dist/core/resource-loader.d.ts.map +1 -1
  109. package/dist/core/resource-loader.js +136 -108
  110. package/dist/core/resource-loader.js.map +1 -1
  111. package/dist/core/sdk.d.ts +4 -4
  112. package/dist/core/sdk.d.ts.map +1 -1
  113. package/dist/core/sdk.js +15 -24
  114. package/dist/core/sdk.js.map +1 -1
  115. package/dist/core/session-manager.d.ts +2 -2
  116. package/dist/core/session-manager.d.ts.map +1 -1
  117. package/dist/core/session-manager.js.map +1 -1
  118. package/dist/core/settings-manager.d.ts +3 -1
  119. package/dist/core/settings-manager.d.ts.map +1 -1
  120. package/dist/core/settings-manager.js +3 -0
  121. package/dist/core/settings-manager.js.map +1 -1
  122. package/dist/core/skills.d.ts +2 -1
  123. package/dist/core/skills.d.ts.map +1 -1
  124. package/dist/core/skills.js +25 -1
  125. package/dist/core/skills.js.map +1 -1
  126. package/dist/core/slash-commands.d.ts +2 -3
  127. package/dist/core/slash-commands.d.ts.map +1 -1
  128. package/dist/core/slash-commands.js.map +1 -1
  129. package/dist/core/source-info.d.ts +18 -0
  130. package/dist/core/source-info.d.ts.map +1 -0
  131. package/dist/core/source-info.js +19 -0
  132. package/dist/core/source-info.js.map +1 -0
  133. package/dist/core/system-prompt.d.ts.map +1 -1
  134. package/dist/core/system-prompt.js +3 -38
  135. package/dist/core/system-prompt.js.map +1 -1
  136. package/dist/core/timings.d.ts +1 -0
  137. package/dist/core/timings.d.ts.map +1 -1
  138. package/dist/core/timings.js +6 -0
  139. package/dist/core/timings.js.map +1 -1
  140. package/dist/core/tools/bash.d.ts +20 -10
  141. package/dist/core/tools/bash.d.ts.map +1 -1
  142. package/dist/core/tools/bash.js +151 -59
  143. package/dist/core/tools/bash.js.map +1 -1
  144. package/dist/core/tools/edit-diff.d.ts +23 -1
  145. package/dist/core/tools/edit-diff.d.ts.map +1 -1
  146. package/dist/core/tools/edit-diff.js +150 -57
  147. package/dist/core/tools/edit-diff.js.map +1 -1
  148. package/dist/core/tools/edit.d.ts +31 -7
  149. package/dist/core/tools/edit.d.ts.map +1 -1
  150. package/dist/core/tools/edit.js +179 -59
  151. package/dist/core/tools/edit.js.map +1 -1
  152. package/dist/core/tools/file-mutation-queue.d.ts.map +1 -1
  153. package/dist/core/tools/file-mutation-queue.js +4 -4
  154. package/dist/core/tools/file-mutation-queue.js.map +1 -1
  155. package/dist/core/tools/find.d.ts +12 -5
  156. package/dist/core/tools/find.d.ts.map +1 -1
  157. package/dist/core/tools/find.js +76 -27
  158. package/dist/core/tools/find.js.map +1 -1
  159. package/dist/core/tools/grep.d.ts +16 -5
  160. package/dist/core/tools/grep.d.ts.map +1 -1
  161. package/dist/core/tools/grep.js +83 -29
  162. package/dist/core/tools/grep.js.map +1 -1
  163. package/dist/core/tools/index.d.ts +68 -22
  164. package/dist/core/tools/index.d.ts.map +1 -1
  165. package/dist/core/tools/index.js +50 -26
  166. package/dist/core/tools/index.js.map +1 -1
  167. package/dist/core/tools/ls.d.ts +10 -4
  168. package/dist/core/tools/ls.d.ts.map +1 -1
  169. package/dist/core/tools/ls.js +67 -13
  170. package/dist/core/tools/ls.js.map +1 -1
  171. package/dist/core/tools/read.d.ts +11 -4
  172. package/dist/core/tools/read.d.ts.map +1 -1
  173. package/dist/core/tools/read.js +110 -51
  174. package/dist/core/tools/read.js.map +1 -1
  175. package/dist/core/tools/render-utils.d.ts +21 -0
  176. package/dist/core/tools/render-utils.d.ts.map +1 -0
  177. package/dist/core/tools/render-utils.js +49 -0
  178. package/dist/core/tools/render-utils.js.map +1 -0
  179. package/dist/core/tools/tool-definition-wrapper.d.ts +14 -0
  180. package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -0
  181. package/dist/core/tools/tool-definition-wrapper.js +30 -0
  182. package/dist/core/tools/tool-definition-wrapper.js.map +1 -0
  183. package/dist/core/tools/write.d.ts +10 -4
  184. package/dist/core/tools/write.d.ts.map +1 -1
  185. package/dist/core/tools/write.js +162 -27
  186. package/dist/core/tools/write.js.map +1 -1
  187. package/dist/index.d.ts +3 -2
  188. package/dist/index.d.ts.map +1 -1
  189. package/dist/index.js +2 -1
  190. package/dist/index.js.map +1 -1
  191. package/dist/main.d.ts.map +1 -1
  192. package/dist/main.js +57 -19
  193. package/dist/main.js.map +1 -1
  194. package/dist/modes/interactive/components/armin.d.ts +1 -1
  195. package/dist/modes/interactive/components/armin.d.ts.map +1 -1
  196. package/dist/modes/interactive/components/armin.js.map +1 -1
  197. package/dist/modes/interactive/components/assistant-message.d.ts +2 -2
  198. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  199. package/dist/modes/interactive/components/assistant-message.js +1 -1
  200. package/dist/modes/interactive/components/assistant-message.js.map +1 -1
  201. package/dist/modes/interactive/components/bash-execution.d.ts +1 -2
  202. package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
  203. package/dist/modes/interactive/components/bash-execution.js +19 -6
  204. package/dist/modes/interactive/components/bash-execution.js.map +1 -1
  205. package/dist/modes/interactive/components/bordered-loader.d.ts +1 -1
  206. package/dist/modes/interactive/components/bordered-loader.d.ts.map +1 -1
  207. package/dist/modes/interactive/components/bordered-loader.js +1 -1
  208. package/dist/modes/interactive/components/bordered-loader.js.map +1 -1
  209. package/dist/modes/interactive/components/branch-summary-message.d.ts +1 -1
  210. package/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -1
  211. package/dist/modes/interactive/components/branch-summary-message.js +1 -1
  212. package/dist/modes/interactive/components/branch-summary-message.js.map +1 -1
  213. package/dist/modes/interactive/components/compaction-summary-message.d.ts +1 -1
  214. package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +1 -1
  215. package/dist/modes/interactive/components/compaction-summary-message.js +1 -1
  216. package/dist/modes/interactive/components/compaction-summary-message.js.map +1 -1
  217. package/dist/modes/interactive/components/config-selector.d.ts +1 -1
  218. package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
  219. package/dist/modes/interactive/components/config-selector.js +1 -1
  220. package/dist/modes/interactive/components/config-selector.js.map +1 -1
  221. package/dist/modes/interactive/components/countdown-timer.d.ts +1 -1
  222. package/dist/modes/interactive/components/countdown-timer.d.ts.map +1 -1
  223. package/dist/modes/interactive/components/countdown-timer.js.map +1 -1
  224. package/dist/modes/interactive/components/custom-editor.d.ts +1 -1
  225. package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
  226. package/dist/modes/interactive/components/custom-editor.js +1 -1
  227. package/dist/modes/interactive/components/custom-editor.js.map +1 -1
  228. package/dist/modes/interactive/components/custom-message.d.ts +1 -1
  229. package/dist/modes/interactive/components/custom-message.d.ts.map +1 -1
  230. package/dist/modes/interactive/components/custom-message.js +1 -1
  231. package/dist/modes/interactive/components/custom-message.js.map +1 -1
  232. package/dist/modes/interactive/components/daxnuts.d.ts +1 -1
  233. package/dist/modes/interactive/components/daxnuts.d.ts.map +1 -1
  234. package/dist/modes/interactive/components/daxnuts.js.map +1 -1
  235. package/dist/modes/interactive/components/dynamic-border.d.ts +1 -1
  236. package/dist/modes/interactive/components/dynamic-border.d.ts.map +1 -1
  237. package/dist/modes/interactive/components/dynamic-border.js.map +1 -1
  238. package/dist/modes/interactive/components/extension-editor.d.ts +1 -1
  239. package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -1
  240. package/dist/modes/interactive/components/extension-editor.js +1 -1
  241. package/dist/modes/interactive/components/extension-editor.js.map +1 -1
  242. package/dist/modes/interactive/components/extension-input.d.ts +1 -1
  243. package/dist/modes/interactive/components/extension-input.d.ts.map +1 -1
  244. package/dist/modes/interactive/components/extension-input.js +1 -1
  245. package/dist/modes/interactive/components/extension-input.js.map +1 -1
  246. package/dist/modes/interactive/components/extension-selector.d.ts +1 -1
  247. package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -1
  248. package/dist/modes/interactive/components/extension-selector.js +1 -1
  249. package/dist/modes/interactive/components/extension-selector.js.map +1 -1
  250. package/dist/modes/interactive/components/footer.d.ts +1 -1
  251. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  252. package/dist/modes/interactive/components/footer.js +1 -1
  253. package/dist/modes/interactive/components/footer.js.map +1 -1
  254. package/dist/modes/interactive/components/keybinding-hints.d.ts +1 -1
  255. package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -1
  256. package/dist/modes/interactive/components/keybinding-hints.js +1 -1
  257. package/dist/modes/interactive/components/keybinding-hints.js.map +1 -1
  258. package/dist/modes/interactive/components/login-dialog.d.ts +1 -1
  259. package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
  260. package/dist/modes/interactive/components/login-dialog.js +2 -2
  261. package/dist/modes/interactive/components/login-dialog.js.map +1 -1
  262. package/dist/modes/interactive/components/model-selector.d.ts +2 -2
  263. package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
  264. package/dist/modes/interactive/components/model-selector.js +2 -2
  265. package/dist/modes/interactive/components/model-selector.js.map +1 -1
  266. package/dist/modes/interactive/components/oauth-selector.d.ts +1 -1
  267. package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
  268. package/dist/modes/interactive/components/oauth-selector.js +2 -2
  269. package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
  270. package/dist/modes/interactive/components/scoped-models-selector.d.ts +2 -2
  271. package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
  272. package/dist/modes/interactive/components/scoped-models-selector.js +1 -1
  273. package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
  274. package/dist/modes/interactive/components/session-selector-search.d.ts.map +1 -1
  275. package/dist/modes/interactive/components/session-selector-search.js +1 -1
  276. package/dist/modes/interactive/components/session-selector-search.js.map +1 -1
  277. package/dist/modes/interactive/components/session-selector.d.ts +1 -1
  278. package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
  279. package/dist/modes/interactive/components/session-selector.js +1 -1
  280. package/dist/modes/interactive/components/session-selector.js.map +1 -1
  281. package/dist/modes/interactive/components/settings-selector.d.ts +3 -3
  282. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  283. package/dist/modes/interactive/components/settings-selector.js +1 -1
  284. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  285. package/dist/modes/interactive/components/show-images-selector.d.ts +1 -1
  286. package/dist/modes/interactive/components/show-images-selector.d.ts.map +1 -1
  287. package/dist/modes/interactive/components/show-images-selector.js +1 -1
  288. package/dist/modes/interactive/components/show-images-selector.js.map +1 -1
  289. package/dist/modes/interactive/components/skill-invocation-message.d.ts +1 -1
  290. package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -1
  291. package/dist/modes/interactive/components/skill-invocation-message.js +1 -1
  292. package/dist/modes/interactive/components/skill-invocation-message.js.map +1 -1
  293. package/dist/modes/interactive/components/theme-selector.d.ts +1 -1
  294. package/dist/modes/interactive/components/theme-selector.d.ts.map +1 -1
  295. package/dist/modes/interactive/components/theme-selector.js +1 -1
  296. package/dist/modes/interactive/components/theme-selector.js.map +1 -1
  297. package/dist/modes/interactive/components/thinking-selector.d.ts +2 -2
  298. package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -1
  299. package/dist/modes/interactive/components/thinking-selector.js +1 -1
  300. package/dist/modes/interactive/components/thinking-selector.js.map +1 -1
  301. package/dist/modes/interactive/components/tool-execution.d.ts +15 -41
  302. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  303. package/dist/modes/interactive/components/tool-execution.js +121 -679
  304. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  305. package/dist/modes/interactive/components/tree-selector.d.ts +1 -1
  306. package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
  307. package/dist/modes/interactive/components/tree-selector.js +1 -1
  308. package/dist/modes/interactive/components/tree-selector.js.map +1 -1
  309. package/dist/modes/interactive/components/user-message-selector.d.ts +1 -1
  310. package/dist/modes/interactive/components/user-message-selector.d.ts.map +1 -1
  311. package/dist/modes/interactive/components/user-message-selector.js +1 -1
  312. package/dist/modes/interactive/components/user-message-selector.js.map +1 -1
  313. package/dist/modes/interactive/components/user-message.d.ts +1 -1
  314. package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
  315. package/dist/modes/interactive/components/user-message.js +1 -1
  316. package/dist/modes/interactive/components/user-message.js.map +1 -1
  317. package/dist/modes/interactive/components/visual-truncate.d.ts.map +1 -1
  318. package/dist/modes/interactive/components/visual-truncate.js +1 -1
  319. package/dist/modes/interactive/components/visual-truncate.js.map +1 -1
  320. package/dist/modes/interactive/interactive-mode.d.ts +5 -13
  321. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  322. package/dist/modes/interactive/interactive-mode.js +175 -160
  323. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  324. package/dist/modes/interactive/theme/theme.d.ts +5 -2
  325. package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  326. package/dist/modes/interactive/theme/theme.js +15 -1
  327. package/dist/modes/interactive/theme/theme.js.map +1 -1
  328. package/dist/modes/print-mode.d.ts +2 -2
  329. package/dist/modes/print-mode.d.ts.map +1 -1
  330. package/dist/modes/print-mode.js +84 -78
  331. package/dist/modes/print-mode.js.map +1 -1
  332. package/dist/modes/rpc/rpc-client.d.ts +2 -2
  333. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  334. package/dist/modes/rpc/rpc-client.js.map +1 -1
  335. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  336. package/dist/modes/rpc/rpc-mode.js +27 -20
  337. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  338. package/dist/modes/rpc/rpc-types.d.ts +5 -6
  339. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  340. package/dist/modes/rpc/rpc-types.js.map +1 -1
  341. package/dist/utils/image-resize.d.ts +6 -6
  342. package/dist/utils/image-resize.d.ts.map +1 -1
  343. package/dist/utils/image-resize.js +45 -94
  344. package/dist/utils/image-resize.js.map +1 -1
  345. package/docs/development.md +3 -1
  346. package/docs/extensions.md +85 -34
  347. package/docs/models.md +6 -0
  348. package/docs/rpc.md +11 -2
  349. package/docs/settings.md +12 -0
  350. package/docs/skills.md +3 -2
  351. package/docs/tui.md +2 -2
  352. package/examples/extensions/built-in-tool-renderer.ts +8 -8
  353. package/examples/extensions/commands.ts +3 -3
  354. package/examples/extensions/custom-compaction.ts +17 -4
  355. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  356. package/examples/extensions/custom-provider-anthropic/package.json +17 -17
  357. package/examples/extensions/custom-provider-gitlab-duo/package.json +14 -14
  358. package/examples/extensions/custom-provider-qwen-cli/package.json +14 -14
  359. package/examples/extensions/handoff.ts +5 -2
  360. package/examples/extensions/minimal-mode.ts +14 -14
  361. package/examples/extensions/qna.ts +5 -2
  362. package/examples/extensions/question.ts +2 -2
  363. package/examples/extensions/questionnaire.ts +2 -2
  364. package/examples/extensions/subagent/index.ts +23 -3
  365. package/examples/extensions/summarize.ts +15 -4
  366. package/examples/extensions/todo.ts +2 -2
  367. package/examples/extensions/trigger-compact.ts +11 -1
  368. package/examples/extensions/truncated-tool.ts +2 -2
  369. package/examples/extensions/with-deps/package-lock.json +2 -2
  370. package/examples/extensions/with-deps/package.json +20 -20
  371. package/examples/sdk/04-skills.ts +8 -2
  372. package/examples/sdk/08-prompt-templates.ts +2 -1
  373. package/examples/sdk/12-full-control.ts +0 -1
  374. package/package.json +5 -4
@@ -1,7 +1,11 @@
1
+ import { Text } from "@hyperspaceng/neural-tui";
1
2
  import { Type } from "@sinclair/typebox";
2
3
  import { existsSync, readdirSync, statSync } from "fs";
3
4
  import nodePath from "path";
5
+ import { keyHint } from "../../modes/interactive/components/keybinding-hints.js";
4
6
  import { resolveToCwd } from "./path-utils.js";
7
+ import { getTextOutput, invalidArgText, shortenPath, str } from "./render-utils.js";
8
+ import { wrapToolDefinition } from "./tool-definition-wrapper.js";
5
9
  import { DEFAULT_MAX_BYTES, formatSize, truncateHead } from "./truncate.js";
6
10
  const lsSchema = Type.Object({
7
11
  path: Type.Optional(Type.String({ description: "Directory to list (default: current directory)" })),
@@ -13,14 +17,51 @@ const defaultLsOperations = {
13
17
  stat: statSync,
14
18
  readdir: readdirSync,
15
19
  };
16
- export function createLsTool(cwd, options) {
20
+ function formatLsCall(args, theme) {
21
+ const rawPath = str(args?.path);
22
+ const path = rawPath !== null ? shortenPath(rawPath || ".") : null;
23
+ const limit = args?.limit;
24
+ const invalidArg = invalidArgText(theme);
25
+ let text = `${theme.fg("toolTitle", theme.bold("ls"))} ${path === null ? invalidArg : theme.fg("accent", path)}`;
26
+ if (limit !== undefined) {
27
+ text += theme.fg("toolOutput", ` (limit ${limit})`);
28
+ }
29
+ return text;
30
+ }
31
+ function formatLsResult(result, options, theme, showImages) {
32
+ const output = getTextOutput(result, showImages).trim();
33
+ let text = "";
34
+ if (output) {
35
+ const lines = output.split("\n");
36
+ const maxLines = options.expanded ? lines.length : 20;
37
+ const displayLines = lines.slice(0, maxLines);
38
+ const remaining = lines.length - maxLines;
39
+ text += `\n${displayLines.map((line) => theme.fg("toolOutput", line)).join("\n")}`;
40
+ if (remaining > 0) {
41
+ text += `${theme.fg("muted", `\n... (${remaining} more lines,`)} ${keyHint("app.tools.expand", "to expand")})`;
42
+ }
43
+ }
44
+ const entryLimit = result.details?.entryLimitReached;
45
+ const truncation = result.details?.truncation;
46
+ if (entryLimit || truncation?.truncated) {
47
+ const warnings = [];
48
+ if (entryLimit)
49
+ warnings.push(`${entryLimit} entries limit`);
50
+ if (truncation?.truncated)
51
+ warnings.push(`${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit`);
52
+ text += `\n${theme.fg("warning", `[Truncated: ${warnings.join(", ")}]`)}`;
53
+ }
54
+ return text;
55
+ }
56
+ export function createLsToolDefinition(cwd, options) {
17
57
  const ops = options?.operations ?? defaultLsOperations;
18
58
  return {
19
59
  name: "ls",
20
60
  label: "ls",
21
61
  description: `List directory contents. Returns entries sorted alphabetically, with '/' suffix for directories. Includes dotfiles. Output is truncated to ${DEFAULT_LIMIT} entries or ${DEFAULT_MAX_BYTES / 1024}KB (whichever is hit first).`,
62
+ promptSnippet: "List directory contents",
22
63
  parameters: lsSchema,
23
- execute: async (_toolCallId, { path, limit }, signal) => {
64
+ async execute(_toolCallId, { path, limit }, signal, _onUpdate, _ctx) {
24
65
  return new Promise((resolve, reject) => {
25
66
  if (signal?.aborted) {
26
67
  reject(new Error("Operation aborted"));
@@ -32,18 +73,18 @@ export function createLsTool(cwd, options) {
32
73
  try {
33
74
  const dirPath = resolveToCwd(path || ".", cwd);
34
75
  const effectiveLimit = limit ?? DEFAULT_LIMIT;
35
- // Check if path exists
76
+ // Check if path exists.
36
77
  if (!(await ops.exists(dirPath))) {
37
78
  reject(new Error(`Path not found: ${dirPath}`));
38
79
  return;
39
80
  }
40
- // Check if path is a directory
81
+ // Check if path is a directory.
41
82
  const stat = await ops.stat(dirPath);
42
83
  if (!stat.isDirectory()) {
43
84
  reject(new Error(`Not a directory: ${dirPath}`));
44
85
  return;
45
86
  }
46
- // Read directory entries
87
+ // Read directory entries.
47
88
  let entries;
48
89
  try {
49
90
  entries = await ops.readdir(dirPath);
@@ -52,9 +93,9 @@ export function createLsTool(cwd, options) {
52
93
  reject(new Error(`Cannot read directory: ${e.message}`));
53
94
  return;
54
95
  }
55
- // Sort alphabetically (case-insensitive)
96
+ // Sort alphabetically, case-insensitive.
56
97
  entries.sort((a, b) => a.toLowerCase().localeCompare(b.toLowerCase()));
57
- // Format entries with directory indicators
98
+ // Format entries with directory indicators.
58
99
  const results = [];
59
100
  let entryLimitReached = false;
60
101
  for (const entry of entries) {
@@ -66,12 +107,11 @@ export function createLsTool(cwd, options) {
66
107
  let suffix = "";
67
108
  try {
68
109
  const entryStat = await ops.stat(fullPath);
69
- if (entryStat.isDirectory()) {
110
+ if (entryStat.isDirectory())
70
111
  suffix = "/";
71
- }
72
112
  }
73
113
  catch {
74
- // Skip entries we can't stat
114
+ // Skip entries we cannot stat.
75
115
  continue;
76
116
  }
77
117
  results.push(entry + suffix);
@@ -81,12 +121,12 @@ export function createLsTool(cwd, options) {
81
121
  resolve({ content: [{ type: "text", text: "(empty directory)" }], details: undefined });
82
122
  return;
83
123
  }
84
- // Apply byte truncation (no line limit since we already have entry limit)
85
124
  const rawOutput = results.join("\n");
125
+ // Apply byte truncation. There is no separate line limit because entry count is already capped.
86
126
  const truncation = truncateHead(rawOutput, { maxLines: Number.MAX_SAFE_INTEGER });
87
127
  let output = truncation.content;
88
128
  const details = {};
89
- // Build notices
129
+ // Build actionable notices for truncation and entry limits.
90
130
  const notices = [];
91
131
  if (entryLimitReached) {
92
132
  notices.push(`${effectiveLimit} entries limit reached. Use limit=${effectiveLimit * 2} for more`);
@@ -111,8 +151,22 @@ export function createLsTool(cwd, options) {
111
151
  })();
112
152
  });
113
153
  },
154
+ renderCall(args, theme, context) {
155
+ const text = context.lastComponent ?? new Text("", 0, 0);
156
+ text.setText(formatLsCall(args, theme));
157
+ return text;
158
+ },
159
+ renderResult(result, options, theme, context) {
160
+ const text = context.lastComponent ?? new Text("", 0, 0);
161
+ text.setText(formatLsResult(result, options, theme, context.showImages));
162
+ return text;
163
+ },
114
164
  };
115
165
  }
116
- /** Default ls tool using process.cwd() - for backwards compatibility */
166
+ export function createLsTool(cwd, options) {
167
+ return wrapToolDefinition(createLsToolDefinition(cwd, options));
168
+ }
169
+ /** Default ls tool using process.cwd() for backwards compatibility. */
170
+ export const lsToolDefinition = createLsToolDefinition(process.cwd());
117
171
  export const lsTool = createLsTool(process.cwd());
118
172
  //# sourceMappingURL=ls.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ls.js","sourceRoot":"","sources":["../../../src/core/tools/ls.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AACvD,OAAO,QAAQ,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAyB,YAAY,EAAE,MAAM,eAAe,CAAC;AAEnG,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC;IAC5B,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,gDAAgD,EAAE,CAAC,CAAC;IACnG,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,oDAAoD,EAAE,CAA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C,CAAC;4BAC/D,OAAO,CAAC,UAAU,GAAG,UAAU,CAAC;wBACjC,CAAC;wBAED,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;4BACxB,MAAM,IAAI,QAAQ,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;wBACzC,CAAC;wBAED,OAAO,CAAC;4BACP,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;4BACzC,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS;yBAC9D,CAAC,CAAC;oBACJ,CAAC;oBAAC,OAAO,CAAM,EAAE,CAAC;wBACjB,MAAM,EAAE,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;wBAC9C,MAAM,CAAC,CAAC,CAAC,CAAC;oBACX,CAAC;gBAAA,CACD,CAAC,EAAE,CAAC;YAAA,CACL,CAAC,CAAC;QAAA,CACH;KACD,CAAC;AAAA,CACF;AAED,wEAAwE;AACxE,MAAM,CAAC,MAAM,MAAM,GAAG,YAAY,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC","sourcesContent":["import type { AgentTool } from \"@mariozechner/pi-agent-core\";\nimport { type Static, Type } from \"@sinclair/typebox\";\nimport { existsSync, readdirSync, statSync } from \"fs\";\nimport nodePath from \"path\";\nimport { resolveToCwd } from \"./path-utils.js\";\nimport { DEFAULT_MAX_BYTES, formatSize, type TruncationResult, truncateHead } from \"./truncate.js\";\n\nconst lsSchema = Type.Object({\n\tpath: Type.Optional(Type.String({ description: \"Directory to list (default: current directory)\" })),\n\tlimit: Type.Optional(Type.Number({ description: \"Maximum number of entries to return (default: 500)\" })),\n});\n\nexport type LsToolInput = Static<typeof lsSchema>;\n\nconst DEFAULT_LIMIT = 500;\n\nexport interface LsToolDetails {\n\ttruncation?: TruncationResult;\n\tentryLimitReached?: number;\n}\n\n/**\n * Pluggable operations for the ls tool.\n * Override these to delegate directory listing to remote systems (e.g., SSH).\n */\nexport interface LsOperations {\n\t/** Check if path exists */\n\texists: (absolutePath: string) => Promise<boolean> | boolean;\n\t/** Get file/directory stats. Throws if not found. */\n\tstat: (absolutePath: string) => Promise<{ isDirectory: () => boolean }> | { isDirectory: () => boolean };\n\t/** Read directory entries */\n\treaddir: (absolutePath: string) => Promise<string[]> | string[];\n}\n\nconst defaultLsOperations: LsOperations = {\n\texists: existsSync,\n\tstat: statSync,\n\treaddir: readdirSync,\n};\n\nexport interface LsToolOptions {\n\t/** Custom operations for directory listing. Default: local filesystem */\n\toperations?: LsOperations;\n}\n\nexport function createLsTool(cwd: string, options?: LsToolOptions): AgentTool<typeof lsSchema> {\n\tconst ops = options?.operations ?? defaultLsOperations;\n\n\treturn {\n\t\tname: \"ls\",\n\t\tlabel: \"ls\",\n\t\tdescription: `List directory contents. Returns entries sorted alphabetically, with '/' suffix for directories. Includes dotfiles. Output is truncated to ${DEFAULT_LIMIT} entries or ${DEFAULT_MAX_BYTES / 1024}KB (whichever is hit first).`,\n\t\tparameters: lsSchema,\n\t\texecute: async (\n\t\t\t_toolCallId: string,\n\t\t\t{ path, limit }: { path?: string; limit?: number },\n\t\t\tsignal?: AbortSignal,\n\t\t) => {\n\t\t\treturn new Promise((resolve, reject) => {\n\t\t\t\tif (signal?.aborted) {\n\t\t\t\t\treject(new Error(\"Operation aborted\"));\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst onAbort = () => reject(new Error(\"Operation aborted\"));\n\t\t\t\tsignal?.addEventListener(\"abort\", onAbort, { once: true });\n\n\t\t\t\t(async () => {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst dirPath = resolveToCwd(path || \".\", cwd);\n\t\t\t\t\t\tconst effectiveLimit = limit ?? DEFAULT_LIMIT;\n\n\t\t\t\t\t\t// Check if path exists\n\t\t\t\t\t\tif (!(await ops.exists(dirPath))) {\n\t\t\t\t\t\t\treject(new Error(`Path not found: ${dirPath}`));\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Check if path is a directory\n\t\t\t\t\t\tconst stat = await ops.stat(dirPath);\n\t\t\t\t\t\tif (!stat.isDirectory()) {\n\t\t\t\t\t\t\treject(new Error(`Not a directory: ${dirPath}`));\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Read directory entries\n\t\t\t\t\t\tlet entries: string[];\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tentries = await ops.readdir(dirPath);\n\t\t\t\t\t\t} catch (e: any) {\n\t\t\t\t\t\t\treject(new Error(`Cannot read directory: ${e.message}`));\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Sort alphabetically (case-insensitive)\n\t\t\t\t\t\tentries.sort((a, b) => a.toLowerCase().localeCompare(b.toLowerCase()));\n\n\t\t\t\t\t\t// Format entries with directory indicators\n\t\t\t\t\t\tconst results: string[] = [];\n\t\t\t\t\t\tlet entryLimitReached = false;\n\n\t\t\t\t\t\tfor (const entry of entries) {\n\t\t\t\t\t\t\tif (results.length >= effectiveLimit) {\n\t\t\t\t\t\t\t\tentryLimitReached = true;\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tconst fullPath = nodePath.join(dirPath, entry);\n\t\t\t\t\t\t\tlet suffix = \"\";\n\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tconst entryStat = await ops.stat(fullPath);\n\t\t\t\t\t\t\t\tif (entryStat.isDirectory()) {\n\t\t\t\t\t\t\t\t\tsuffix = \"/\";\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t\t// Skip entries we can't stat\n\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tresults.push(entry + suffix);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\n\t\t\t\t\t\tif (results.length === 0) {\n\t\t\t\t\t\t\tresolve({ content: [{ type: \"text\", text: \"(empty directory)\" }], details: undefined });\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Apply byte truncation (no line limit since we already have entry limit)\n\t\t\t\t\t\tconst rawOutput = results.join(\"\\n\");\n\t\t\t\t\t\tconst truncation = truncateHead(rawOutput, { maxLines: Number.MAX_SAFE_INTEGER });\n\n\t\t\t\t\t\tlet output = truncation.content;\n\t\t\t\t\t\tconst details: LsToolDetails = {};\n\n\t\t\t\t\t\t// Build notices\n\t\t\t\t\t\tconst notices: string[] = [];\n\n\t\t\t\t\t\tif (entryLimitReached) {\n\t\t\t\t\t\t\tnotices.push(`${effectiveLimit} entries limit reached. Use limit=${effectiveLimit * 2} for more`);\n\t\t\t\t\t\t\tdetails.entryLimitReached = effectiveLimit;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (truncation.truncated) {\n\t\t\t\t\t\t\tnotices.push(`${formatSize(DEFAULT_MAX_BYTES)} limit reached`);\n\t\t\t\t\t\t\tdetails.truncation = truncation;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (notices.length > 0) {\n\t\t\t\t\t\t\toutput += `\\n\\n[${notices.join(\". \")}]`;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tresolve({\n\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: output }],\n\t\t\t\t\t\t\tdetails: Object.keys(details).length > 0 ? details : undefined,\n\t\t\t\t\t\t});\n\t\t\t\t\t} catch (e: any) {\n\t\t\t\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\t\t\t\t\t\treject(e);\n\t\t\t\t\t}\n\t\t\t\t})();\n\t\t\t});\n\t\t},\n\t};\n}\n\n/** Default ls tool using process.cwd() - for backwards compatibility */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Static, Type } from \"@sinclair/typebox\";\nimport { existsSync, readdirSync, statSync } from \"fs\";\nimport nodePath from \"path\";\nimport { keyHint } from \"../../modes/interactive/components/keybinding-hints.js\";\nimport type { ToolDefinition, ToolRenderResultOptions } from \"../extensions/types.js\";\nimport { resolveToCwd } from \"./path-utils.js\";\nimport { getTextOutput, invalidArgText, shortenPath, str } from \"./render-utils.js\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.js\";\nimport { DEFAULT_MAX_BYTES, formatSize, type TruncationResult, truncateHead } from \"./truncate.js\";\n\nconst lsSchema = Type.Object({\n\tpath: Type.Optional(Type.String({ description: \"Directory to list (default: current directory)\" })),\n\tlimit: Type.Optional(Type.Number({ description: \"Maximum number of entries to return (default: 500)\" })),\n});\n\nexport type LsToolInput = Static<typeof lsSchema>;\n\nconst DEFAULT_LIMIT = 500;\n\nexport interface LsToolDetails {\n\ttruncation?: TruncationResult;\n\tentryLimitReached?: number;\n}\n\n/**\n * Pluggable operations for the ls tool.\n * Override these to delegate directory listing to remote systems (for example SSH).\n */\nexport interface LsOperations {\n\t/** Check if path exists */\n\texists: (absolutePath: string) => Promise<boolean> | boolean;\n\t/** Get file or directory stats. Throws if not found. */\n\tstat: (absolutePath: string) => Promise<{ isDirectory: () => boolean }> | { isDirectory: () => boolean };\n\t/** Read directory entries */\n\treaddir: (absolutePath: string) => Promise<string[]> | string[];\n}\n\nconst defaultLsOperations: LsOperations = {\n\texists: existsSync,\n\tstat: statSync,\n\treaddir: readdirSync,\n};\n\nexport interface LsToolOptions {\n\t/** Custom operations for directory listing. Default: local filesystem */\n\toperations?: LsOperations;\n}\n\nfunction formatLsCall(\n\targs: { path?: string; limit?: number } | undefined,\n\ttheme: typeof import(\"../../modes/interactive/theme/theme.js\").theme,\n): string {\n\tconst rawPath = str(args?.path);\n\tconst path = rawPath !== null ? shortenPath(rawPath || \".\") : null;\n\tconst limit = args?.limit;\n\tconst invalidArg = invalidArgText(theme);\n\tlet text = `${theme.fg(\"toolTitle\", theme.bold(\"ls\"))} ${path === null ? invalidArg : theme.fg(\"accent\", path)}`;\n\tif (limit !== undefined) {\n\t\ttext += theme.fg(\"toolOutput\", ` (limit ${limit})`);\n\t}\n\treturn text;\n}\n\nfunction formatLsResult(\n\tresult: {\n\t\tcontent: Array<{ type: string; text?: string; data?: string; mimeType?: string }>;\n\t\tdetails?: LsToolDetails;\n\t},\n\toptions: ToolRenderResultOptions,\n\ttheme: typeof import(\"../../modes/interactive/theme/theme.js\").theme,\n\tshowImages: boolean,\n): string {\n\tconst output = getTextOutput(result, showImages).trim();\n\tlet text = \"\";\n\tif (output) {\n\t\tconst lines = output.split(\"\\n\");\n\t\tconst maxLines = options.expanded ? lines.length : 20;\n\t\tconst displayLines = lines.slice(0, maxLines);\n\t\tconst remaining = lines.length - maxLines;\n\t\ttext += `\\n${displayLines.map((line) => theme.fg(\"toolOutput\", line)).join(\"\\n\")}`;\n\t\tif (remaining > 0) {\n\t\t\ttext += `${theme.fg(\"muted\", `\\n... (${remaining} more lines,`)} ${keyHint(\"app.tools.expand\", \"to expand\")})`;\n\t\t}\n\t}\n\n\tconst entryLimit = result.details?.entryLimitReached;\n\tconst truncation = result.details?.truncation;\n\tif (entryLimit || truncation?.truncated) {\n\t\tconst warnings: string[] = [];\n\t\tif (entryLimit) warnings.push(`${entryLimit} entries limit`);\n\t\tif (truncation?.truncated) warnings.push(`${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit`);\n\t\ttext += `\\n${theme.fg(\"warning\", `[Truncated: ${warnings.join(\", \")}]`)}`;\n\t}\n\treturn text;\n}\n\nexport function createLsToolDefinition(\n\tcwd: string,\n\toptions?: LsToolOptions,\n): ToolDefinition<typeof lsSchema, LsToolDetails | undefined> {\n\tconst ops = options?.operations ?? defaultLsOperations;\n\treturn {\n\t\tname: \"ls\",\n\t\tlabel: \"ls\",\n\t\tdescription: `List directory contents. Returns entries sorted alphabetically, with '/' suffix for directories. Includes dotfiles. Output is truncated to ${DEFAULT_LIMIT} entries or ${DEFAULT_MAX_BYTES / 1024}KB (whichever is hit first).`,\n\t\tpromptSnippet: \"List directory contents\",\n\t\tparameters: lsSchema,\n\t\tasync execute(\n\t\t\t_toolCallId,\n\t\t\t{ path, limit }: { path?: string; limit?: number },\n\t\t\tsignal?: AbortSignal,\n\t\t\t_onUpdate?,\n\t\t\t_ctx?,\n\t\t) {\n\t\t\treturn new Promise((resolve, reject) => {\n\t\t\t\tif (signal?.aborted) {\n\t\t\t\t\treject(new Error(\"Operation aborted\"));\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst onAbort = () => reject(new Error(\"Operation aborted\"));\n\t\t\t\tsignal?.addEventListener(\"abort\", onAbort, { once: true });\n\n\t\t\t\t(async () => {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst dirPath = resolveToCwd(path || \".\", cwd);\n\t\t\t\t\t\tconst effectiveLimit = limit ?? DEFAULT_LIMIT;\n\n\t\t\t\t\t\t// Check if path exists.\n\t\t\t\t\t\tif (!(await ops.exists(dirPath))) {\n\t\t\t\t\t\t\treject(new Error(`Path not found: ${dirPath}`));\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Check if path is a directory.\n\t\t\t\t\t\tconst stat = await ops.stat(dirPath);\n\t\t\t\t\t\tif (!stat.isDirectory()) {\n\t\t\t\t\t\t\treject(new Error(`Not a directory: ${dirPath}`));\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Read directory entries.\n\t\t\t\t\t\tlet entries: string[];\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tentries = await ops.readdir(dirPath);\n\t\t\t\t\t\t} catch (e: any) {\n\t\t\t\t\t\t\treject(new Error(`Cannot read directory: ${e.message}`));\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Sort alphabetically, case-insensitive.\n\t\t\t\t\t\tentries.sort((a, b) => a.toLowerCase().localeCompare(b.toLowerCase()));\n\n\t\t\t\t\t\t// Format entries with directory indicators.\n\t\t\t\t\t\tconst results: string[] = [];\n\t\t\t\t\t\tlet entryLimitReached = false;\n\t\t\t\t\t\tfor (const entry of entries) {\n\t\t\t\t\t\t\tif (results.length >= effectiveLimit) {\n\t\t\t\t\t\t\t\tentryLimitReached = true;\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tconst fullPath = nodePath.join(dirPath, entry);\n\t\t\t\t\t\t\tlet suffix = \"\";\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tconst entryStat = await ops.stat(fullPath);\n\t\t\t\t\t\t\t\tif (entryStat.isDirectory()) suffix = \"/\";\n\t\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t\t// Skip entries we cannot stat.\n\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tresults.push(entry + suffix);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\n\t\t\t\t\t\tif (results.length === 0) {\n\t\t\t\t\t\t\tresolve({ content: [{ type: \"text\", text: \"(empty directory)\" }], details: undefined });\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst rawOutput = results.join(\"\\n\");\n\t\t\t\t\t\t// Apply byte truncation. There is no separate line limit because entry count is already capped.\n\t\t\t\t\t\tconst truncation = truncateHead(rawOutput, { maxLines: Number.MAX_SAFE_INTEGER });\n\t\t\t\t\t\tlet output = truncation.content;\n\t\t\t\t\t\tconst details: LsToolDetails = {};\n\t\t\t\t\t\t// Build actionable notices for truncation and entry limits.\n\t\t\t\t\t\tconst notices: string[] = [];\n\t\t\t\t\t\tif (entryLimitReached) {\n\t\t\t\t\t\t\tnotices.push(`${effectiveLimit} entries limit reached. Use limit=${effectiveLimit * 2} for more`);\n\t\t\t\t\t\t\tdetails.entryLimitReached = effectiveLimit;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (truncation.truncated) {\n\t\t\t\t\t\t\tnotices.push(`${formatSize(DEFAULT_MAX_BYTES)} limit reached`);\n\t\t\t\t\t\t\tdetails.truncation = truncation;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (notices.length > 0) {\n\t\t\t\t\t\t\toutput += `\\n\\n[${notices.join(\". \")}]`;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tresolve({\n\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: output }],\n\t\t\t\t\t\t\tdetails: Object.keys(details).length > 0 ? details : undefined,\n\t\t\t\t\t\t});\n\t\t\t\t\t} catch (e: any) {\n\t\t\t\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\t\t\t\t\t\treject(e);\n\t\t\t\t\t}\n\t\t\t\t})();\n\t\t\t});\n\t\t},\n\t\trenderCall(args, theme, context) {\n\t\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\t\ttext.setText(formatLsCall(args, theme));\n\t\t\treturn text;\n\t\t},\n\t\trenderResult(result, options, theme, context) {\n\t\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\t\ttext.setText(formatLsResult(result as any, options, theme, context.showImages));\n\t\t\treturn text;\n\t\t},\n\t};\n}\n\nexport function createLsTool(cwd: string, options?: LsToolOptions): AgentTool<typeof lsSchema> {\n\treturn wrapToolDefinition(createLsToolDefinition(cwd, options));\n}\n\n/** Default ls tool using process.cwd() for backwards compatibility. */\nexport const lsToolDefinition = createLsToolDefinition(process.cwd());\nexport const lsTool = createLsTool(process.cwd());\n"]}
@@ -1,5 +1,6 @@
1
- import type { AgentTool } from "@mariozechner/pi-agent-core";
1
+ import type { AgentTool } from "@hyperspaceng/neural-agent-core";
2
2
  import { type Static } from "@sinclair/typebox";
3
+ import type { ToolDefinition } from "../extensions/types.js";
3
4
  import { type TruncationResult } from "./truncate.js";
4
5
  declare const readSchema: import("@sinclair/typebox").TObject<{
5
6
  path: import("@sinclair/typebox").TString;
@@ -12,14 +13,14 @@ export interface ReadToolDetails {
12
13
  }
13
14
  /**
14
15
  * Pluggable operations for the read tool.
15
- * Override these to delegate file reading to remote systems (e.g., SSH).
16
+ * Override these to delegate file reading to remote systems (for example SSH).
16
17
  */
17
18
  export interface ReadOperations {
18
19
  /** Read file contents as a Buffer */
19
20
  readFile: (absolutePath: string) => Promise<Buffer>;
20
21
  /** Check if file is readable (throw if not) */
21
22
  access: (absolutePath: string) => Promise<void>;
22
- /** Detect image MIME type, return null/undefined for non-images */
23
+ /** Detect image MIME type, return null or undefined for non-images */
23
24
  detectImageMimeType?: (absolutePath: string) => Promise<string | null | undefined>;
24
25
  }
25
26
  export interface ReadToolOptions {
@@ -28,8 +29,14 @@ export interface ReadToolOptions {
28
29
  /** Custom operations for file reading. Default: local filesystem */
29
30
  operations?: ReadOperations;
30
31
  }
32
+ export declare function createReadToolDefinition(cwd: string, options?: ReadToolOptions): ToolDefinition<typeof readSchema, ReadToolDetails | undefined>;
31
33
  export declare function createReadTool(cwd: string, options?: ReadToolOptions): AgentTool<typeof readSchema>;
32
- /** Default read tool using process.cwd() - for backwards compatibility */
34
+ /** Default read tool using process.cwd() for backwards compatibility. */
35
+ export declare const readToolDefinition: ToolDefinition<import("@sinclair/typebox").TObject<{
36
+ path: import("@sinclair/typebox").TString;
37
+ offset: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
38
+ limit: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
39
+ }>, ReadToolDetails | undefined, any>;
33
40
  export declare const readTool: AgentTool<import("@sinclair/typebox").TObject<{
34
41
  path: import("@sinclair/typebox").TString;
35
42
  offset: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
@@ -1 +1 @@
1
- {"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../../../src/core/tools/read.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAE7D,OAAO,EAAE,KAAK,MAAM,EAAQ,MAAM,mBAAmB,CAAC;AAMtD,OAAO,EAAoD,KAAK,gBAAgB,EAAgB,MAAM,eAAe,CAAC;AAEtH,QAAA,MAAM,UAAU;;;;EAId,CAAC;AAEH,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,UAAU,CAAC,CAAC;AAEtD,MAAM,WAAW,eAAe;IAC/B,UAAU,CAAC,EAAE,gBAAgB,CAAC;CAC9B;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC9B,qCAAqC;IACrC,QAAQ,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IACpD,+CAA+C;IAC/C,MAAM,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAChD,mEAAmE;IACnE,mBAAmB,CAAC,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;CACnF;AAQD,MAAM,WAAW,eAAe;IAC/B,oEAAoE;IACpE,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,oEAAoE;IACpE,UAAU,CAAC,EAAE,cAAc,CAAC;CAC5B;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,SAAS,CAAC,OAAO,UAAU,CAAC,CA0KnG;AAED,0EAA0E;AAC1E,eAAO,MAAM,QAAQ;;;;QAAgC,CAAC","sourcesContent":["import type { AgentTool } from \"@mariozechner/pi-agent-core\";\nimport type { ImageContent, TextContent } from \"@mariozechner/pi-ai\";\nimport { type Static, Type } from \"@sinclair/typebox\";\nimport { constants } from \"fs\";\nimport { access as fsAccess, readFile as fsReadFile } from \"fs/promises\";\nimport { formatDimensionNote, resizeImage } from \"../../utils/image-resize.js\";\nimport { detectSupportedImageMimeTypeFromFile } from \"../../utils/mime.js\";\nimport { resolveReadPath } from \"./path-utils.js\";\nimport { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize, type TruncationResult, truncateHead } from \"./truncate.js\";\n\nconst readSchema = Type.Object({\n\tpath: Type.String({ description: \"Path to the file to read (relative or absolute)\" }),\n\toffset: Type.Optional(Type.Number({ description: \"Line number to start reading from (1-indexed)\" })),\n\tlimit: Type.Optional(Type.Number({ description: \"Maximum number of lines to read\" })),\n});\n\nexport type ReadToolInput = Static<typeof readSchema>;\n\nexport interface ReadToolDetails {\n\ttruncation?: TruncationResult;\n}\n\n/**\n * Pluggable operations for the read tool.\n * Override these to delegate file reading to remote systems (e.g., SSH).\n */\nexport interface ReadOperations {\n\t/** Read file contents as a Buffer */\n\treadFile: (absolutePath: string) => Promise<Buffer>;\n\t/** Check if file is readable (throw if not) */\n\taccess: (absolutePath: string) => Promise<void>;\n\t/** Detect image MIME type, return null/undefined for non-images */\n\tdetectImageMimeType?: (absolutePath: string) => Promise<string | null | undefined>;\n}\n\nconst defaultReadOperations: ReadOperations = {\n\treadFile: (path) => fsReadFile(path),\n\taccess: (path) => fsAccess(path, constants.R_OK),\n\tdetectImageMimeType: detectSupportedImageMimeTypeFromFile,\n};\n\nexport interface ReadToolOptions {\n\t/** Whether to auto-resize images to 2000x2000 max. Default: true */\n\tautoResizeImages?: boolean;\n\t/** Custom operations for file reading. Default: local filesystem */\n\toperations?: ReadOperations;\n}\n\nexport function createReadTool(cwd: string, options?: ReadToolOptions): AgentTool<typeof readSchema> {\n\tconst autoResizeImages = options?.autoResizeImages ?? true;\n\tconst ops = options?.operations ?? defaultReadOperations;\n\n\treturn {\n\t\tname: \"read\",\n\t\tlabel: \"read\",\n\t\tdescription: `Read the contents of a file. Supports text files and images (jpg, png, gif, webp). Images are sent as attachments. For text files, output is truncated to ${DEFAULT_MAX_LINES} lines or ${DEFAULT_MAX_BYTES / 1024}KB (whichever is hit first). Use offset/limit for large files. When you need the full file, continue with offset until complete.`,\n\t\tparameters: readSchema,\n\t\texecute: async (\n\t\t\t_toolCallId: string,\n\t\t\t{ path, offset, limit }: { path: string; offset?: number; limit?: number },\n\t\t\tsignal?: AbortSignal,\n\t\t) => {\n\t\t\tconst absolutePath = resolveReadPath(path, cwd);\n\n\t\t\treturn new Promise<{ content: (TextContent | ImageContent)[]; details: ReadToolDetails | undefined }>(\n\t\t\t\t(resolve, reject) => {\n\t\t\t\t\t// Check if already aborted\n\t\t\t\t\tif (signal?.aborted) {\n\t\t\t\t\t\treject(new Error(\"Operation aborted\"));\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tlet aborted = false;\n\n\t\t\t\t\t// Set up abort handler\n\t\t\t\t\tconst onAbort = () => {\n\t\t\t\t\t\taborted = true;\n\t\t\t\t\t\treject(new Error(\"Operation aborted\"));\n\t\t\t\t\t};\n\n\t\t\t\t\tif (signal) {\n\t\t\t\t\t\tsignal.addEventListener(\"abort\", onAbort, { once: true });\n\t\t\t\t\t}\n\n\t\t\t\t\t// Perform the read operation\n\t\t\t\t\t(async () => {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t// Check if file exists\n\t\t\t\t\t\t\tawait ops.access(absolutePath);\n\n\t\t\t\t\t\t\t// Check if aborted before reading\n\t\t\t\t\t\t\tif (aborted) {\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tconst mimeType = ops.detectImageMimeType ? await ops.detectImageMimeType(absolutePath) : undefined;\n\n\t\t\t\t\t\t\t// Read the file based on type\n\t\t\t\t\t\t\tlet content: (TextContent | ImageContent)[];\n\t\t\t\t\t\t\tlet details: ReadToolDetails | undefined;\n\n\t\t\t\t\t\t\tif (mimeType) {\n\t\t\t\t\t\t\t\t// Read as image (binary)\n\t\t\t\t\t\t\t\tconst buffer = await ops.readFile(absolutePath);\n\t\t\t\t\t\t\t\tconst base64 = buffer.toString(\"base64\");\n\n\t\t\t\t\t\t\t\tif (autoResizeImages) {\n\t\t\t\t\t\t\t\t\t// Resize image if needed\n\t\t\t\t\t\t\t\t\tconst resized = await resizeImage({ type: \"image\", data: base64, mimeType });\n\t\t\t\t\t\t\t\t\tconst dimensionNote = formatDimensionNote(resized);\n\n\t\t\t\t\t\t\t\t\tlet textNote = `Read image file [${resized.mimeType}]`;\n\t\t\t\t\t\t\t\t\tif (dimensionNote) {\n\t\t\t\t\t\t\t\t\t\ttextNote += `\\n${dimensionNote}`;\n\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\tcontent = [\n\t\t\t\t\t\t\t\t\t\t{ type: \"text\", text: textNote },\n\t\t\t\t\t\t\t\t\t\t{ type: \"image\", data: resized.data, mimeType: resized.mimeType },\n\t\t\t\t\t\t\t\t\t];\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tconst textNote = `Read image file [${mimeType}]`;\n\t\t\t\t\t\t\t\t\tcontent = [\n\t\t\t\t\t\t\t\t\t\t{ type: \"text\", text: textNote },\n\t\t\t\t\t\t\t\t\t\t{ type: \"image\", data: base64, mimeType },\n\t\t\t\t\t\t\t\t\t];\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t// Read as text\n\t\t\t\t\t\t\t\tconst buffer = await ops.readFile(absolutePath);\n\t\t\t\t\t\t\t\tconst textContent = buffer.toString(\"utf-8\");\n\t\t\t\t\t\t\t\tconst allLines = textContent.split(\"\\n\");\n\t\t\t\t\t\t\t\tconst totalFileLines = allLines.length;\n\n\t\t\t\t\t\t\t\t// Apply offset if specified (1-indexed to 0-indexed)\n\t\t\t\t\t\t\t\tconst startLine = offset ? Math.max(0, offset - 1) : 0;\n\t\t\t\t\t\t\t\tconst startLineDisplay = startLine + 1; // For display (1-indexed)\n\n\t\t\t\t\t\t\t\t// Check if offset is out of bounds\n\t\t\t\t\t\t\t\tif (startLine >= allLines.length) {\n\t\t\t\t\t\t\t\t\tthrow new Error(`Offset ${offset} is beyond end of file (${allLines.length} lines total)`);\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t// If limit is specified by user, use it; otherwise we'll let truncateHead decide\n\t\t\t\t\t\t\t\tlet selectedContent: string;\n\t\t\t\t\t\t\t\tlet userLimitedLines: number | undefined;\n\t\t\t\t\t\t\t\tif (limit !== undefined) {\n\t\t\t\t\t\t\t\t\tconst endLine = Math.min(startLine + limit, allLines.length);\n\t\t\t\t\t\t\t\t\tselectedContent = allLines.slice(startLine, endLine).join(\"\\n\");\n\t\t\t\t\t\t\t\t\tuserLimitedLines = endLine - startLine;\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tselectedContent = allLines.slice(startLine).join(\"\\n\");\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t// Apply truncation (respects both line and byte limits)\n\t\t\t\t\t\t\t\tconst truncation = truncateHead(selectedContent);\n\n\t\t\t\t\t\t\t\tlet outputText: string;\n\n\t\t\t\t\t\t\t\tif (truncation.firstLineExceedsLimit) {\n\t\t\t\t\t\t\t\t\t// First line at offset exceeds 30KB - tell model to use bash\n\t\t\t\t\t\t\t\t\tconst firstLineSize = formatSize(Buffer.byteLength(allLines[startLine], \"utf-8\"));\n\t\t\t\t\t\t\t\t\toutputText = `[Line ${startLineDisplay} is ${firstLineSize}, exceeds ${formatSize(DEFAULT_MAX_BYTES)} limit. Use bash: sed -n '${startLineDisplay}p' ${path} | head -c ${DEFAULT_MAX_BYTES}]`;\n\t\t\t\t\t\t\t\t\tdetails = { truncation };\n\t\t\t\t\t\t\t\t} else if (truncation.truncated) {\n\t\t\t\t\t\t\t\t\t// Truncation occurred - build actionable notice\n\t\t\t\t\t\t\t\t\tconst endLineDisplay = startLineDisplay + truncation.outputLines - 1;\n\t\t\t\t\t\t\t\t\tconst nextOffset = endLineDisplay + 1;\n\n\t\t\t\t\t\t\t\t\toutputText = truncation.content;\n\n\t\t\t\t\t\t\t\t\tif (truncation.truncatedBy === \"lines\") {\n\t\t\t\t\t\t\t\t\t\toutputText += `\\n\\n[Showing lines ${startLineDisplay}-${endLineDisplay} of ${totalFileLines}. Use offset=${nextOffset} to continue.]`;\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\toutputText += `\\n\\n[Showing lines ${startLineDisplay}-${endLineDisplay} of ${totalFileLines} (${formatSize(DEFAULT_MAX_BYTES)} limit). Use offset=${nextOffset} to continue.]`;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tdetails = { truncation };\n\t\t\t\t\t\t\t\t} else if (userLimitedLines !== undefined && startLine + userLimitedLines < allLines.length) {\n\t\t\t\t\t\t\t\t\t// User specified limit, there's more content, but no truncation\n\t\t\t\t\t\t\t\t\tconst remaining = allLines.length - (startLine + userLimitedLines);\n\t\t\t\t\t\t\t\t\tconst nextOffset = startLine + userLimitedLines + 1;\n\n\t\t\t\t\t\t\t\t\toutputText = truncation.content;\n\t\t\t\t\t\t\t\t\toutputText += `\\n\\n[${remaining} more lines in file. Use offset=${nextOffset} to continue.]`;\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t// No truncation, no user limit exceeded\n\t\t\t\t\t\t\t\t\toutputText = truncation.content;\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tcontent = [{ type: \"text\", text: outputText }];\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// Check if aborted after reading\n\t\t\t\t\t\t\tif (aborted) {\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// Clean up abort handler\n\t\t\t\t\t\t\tif (signal) {\n\t\t\t\t\t\t\t\tsignal.removeEventListener(\"abort\", onAbort);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tresolve({ content, details });\n\t\t\t\t\t\t} catch (error: any) {\n\t\t\t\t\t\t\t// Clean up abort handler\n\t\t\t\t\t\t\tif (signal) {\n\t\t\t\t\t\t\t\tsignal.removeEventListener(\"abort\", onAbort);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif (!aborted) {\n\t\t\t\t\t\t\t\treject(error);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t})();\n\t\t\t\t},\n\t\t\t);\n\t\t},\n\t};\n}\n\n/** Default read tool using process.cwd() - for backwards compatibility */\nexport const readTool = createReadTool(process.cwd());\n"]}
1
+ {"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../../../src/core/tools/read.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAG7D,OAAO,EAAE,KAAK,MAAM,EAAQ,MAAM,mBAAmB,CAAC;AAOtD,OAAO,KAAK,EAAE,cAAc,EAA2B,MAAM,wBAAwB,CAAC;AAItF,OAAO,EAAoD,KAAK,gBAAgB,EAAgB,MAAM,eAAe,CAAC;AAEtH,QAAA,MAAM,UAAU;;;;EAId,CAAC;AAEH,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,UAAU,CAAC,CAAC;AAEtD,MAAM,WAAW,eAAe;IAC/B,UAAU,CAAC,EAAE,gBAAgB,CAAC;CAC9B;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC9B,qCAAqC;IACrC,QAAQ,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IACpD,+CAA+C;IAC/C,MAAM,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAChD,sEAAsE;IACtE,mBAAmB,CAAC,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;CACnF;AAQD,MAAM,WAAW,eAAe;IAC/B,oEAAoE;IACpE,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,oEAAoE;IACpE,UAAU,CAAC,EAAE,cAAc,CAAC;CAC5B;AA6DD,wBAAgB,wBAAwB,CACvC,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,eAAe,GACvB,cAAc,CAAC,OAAO,UAAU,EAAE,eAAe,GAAG,SAAS,CAAC,CAgJhE;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,SAAS,CAAC,OAAO,UAAU,CAAC,CAEnG;AAED,yEAAyE;AACzE,eAAO,MAAM,kBAAkB;;;;qCAA0C,CAAC;AAC1E,eAAO,MAAM,QAAQ;;;;QAAgC,CAAC","sourcesContent":["import type { AgentTool } from \"@hyperspaceng/neural-agent-core\";\nimport type { ImageContent, TextContent } from \"@hyperspaceng/neural-ai\";\nimport { Text } from \"@hyperspaceng/neural-tui\";\nimport { type Static, Type } from \"@sinclair/typebox\";\nimport { constants } from \"fs\";\nimport { access as fsAccess, readFile as fsReadFile } from \"fs/promises\";\nimport { keyHint } from \"../../modes/interactive/components/keybinding-hints.js\";\nimport { getLanguageFromPath, highlightCode } from \"../../modes/interactive/theme/theme.js\";\nimport { formatDimensionNote, resizeImage } from \"../../utils/image-resize.js\";\nimport { detectSupportedImageMimeTypeFromFile } from \"../../utils/mime.js\";\nimport type { ToolDefinition, ToolRenderResultOptions } from \"../extensions/types.js\";\nimport { resolveReadPath } from \"./path-utils.js\";\nimport { getTextOutput, invalidArgText, replaceTabs, shortenPath, str } from \"./render-utils.js\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.js\";\nimport { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize, type TruncationResult, truncateHead } from \"./truncate.js\";\n\nconst readSchema = Type.Object({\n\tpath: Type.String({ description: \"Path to the file to read (relative or absolute)\" }),\n\toffset: Type.Optional(Type.Number({ description: \"Line number to start reading from (1-indexed)\" })),\n\tlimit: Type.Optional(Type.Number({ description: \"Maximum number of lines to read\" })),\n});\n\nexport type ReadToolInput = Static<typeof readSchema>;\n\nexport interface ReadToolDetails {\n\ttruncation?: TruncationResult;\n}\n\n/**\n * Pluggable operations for the read tool.\n * Override these to delegate file reading to remote systems (for example SSH).\n */\nexport interface ReadOperations {\n\t/** Read file contents as a Buffer */\n\treadFile: (absolutePath: string) => Promise<Buffer>;\n\t/** Check if file is readable (throw if not) */\n\taccess: (absolutePath: string) => Promise<void>;\n\t/** Detect image MIME type, return null or undefined for non-images */\n\tdetectImageMimeType?: (absolutePath: string) => Promise<string | null | undefined>;\n}\n\nconst defaultReadOperations: ReadOperations = {\n\treadFile: (path) => fsReadFile(path),\n\taccess: (path) => fsAccess(path, constants.R_OK),\n\tdetectImageMimeType: detectSupportedImageMimeTypeFromFile,\n};\n\nexport interface ReadToolOptions {\n\t/** Whether to auto-resize images to 2000x2000 max. Default: true */\n\tautoResizeImages?: boolean;\n\t/** Custom operations for file reading. Default: local filesystem */\n\toperations?: ReadOperations;\n}\n\nfunction formatReadCall(\n\targs: { path?: string; file_path?: string; offset?: number; limit?: number } | undefined,\n\ttheme: typeof import(\"../../modes/interactive/theme/theme.js\").theme,\n): string {\n\tconst rawPath = str(args?.file_path ?? args?.path);\n\tconst path = rawPath !== null ? shortenPath(rawPath) : null;\n\tconst offset = args?.offset;\n\tconst limit = args?.limit;\n\tconst invalidArg = invalidArgText(theme);\n\tlet pathDisplay = path === null ? invalidArg : path ? theme.fg(\"accent\", path) : theme.fg(\"toolOutput\", \"...\");\n\tif (offset !== undefined || limit !== undefined) {\n\t\tconst startLine = offset ?? 1;\n\t\tconst endLine = limit !== undefined ? startLine + limit - 1 : \"\";\n\t\tpathDisplay += theme.fg(\"warning\", `:${startLine}${endLine ? `-${endLine}` : \"\"}`);\n\t}\n\treturn `${theme.fg(\"toolTitle\", theme.bold(\"read\"))} ${pathDisplay}`;\n}\n\nfunction trimTrailingEmptyLines(lines: string[]): string[] {\n\tlet end = lines.length;\n\twhile (end > 0 && lines[end - 1] === \"\") {\n\t\tend--;\n\t}\n\treturn lines.slice(0, end);\n}\n\nfunction formatReadResult(\n\targs: { path?: string; file_path?: string; offset?: number; limit?: number } | undefined,\n\tresult: { content: (TextContent | ImageContent)[]; details?: ReadToolDetails },\n\toptions: ToolRenderResultOptions,\n\ttheme: typeof import(\"../../modes/interactive/theme/theme.js\").theme,\n\tshowImages: boolean,\n): string {\n\tconst rawPath = str(args?.file_path ?? args?.path);\n\tconst output = getTextOutput(result as any, showImages);\n\tconst lang = rawPath ? getLanguageFromPath(rawPath) : undefined;\n\tconst renderedLines = lang ? highlightCode(replaceTabs(output), lang) : output.split(\"\\n\");\n\tconst lines = trimTrailingEmptyLines(renderedLines);\n\tconst maxLines = options.expanded ? lines.length : 10;\n\tconst displayLines = lines.slice(0, maxLines);\n\tconst remaining = lines.length - maxLines;\n\tlet text = `\\n${displayLines.map((line) => (lang ? replaceTabs(line) : theme.fg(\"toolOutput\", replaceTabs(line)))).join(\"\\n\")}`;\n\tif (remaining > 0) {\n\t\ttext += `${theme.fg(\"muted\", `\\n... (${remaining} more lines,`)} ${keyHint(\"app.tools.expand\", \"to expand\")})`;\n\t}\n\n\tconst truncation = result.details?.truncation;\n\tif (truncation?.truncated) {\n\t\tif (truncation.firstLineExceedsLimit) {\n\t\t\ttext += `\\n${theme.fg(\"warning\", `[First line exceeds ${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit]`)}`;\n\t\t} else if (truncation.truncatedBy === \"lines\") {\n\t\t\ttext += `\\n${theme.fg(\"warning\", `[Truncated: showing ${truncation.outputLines} of ${truncation.totalLines} lines (${truncation.maxLines ?? DEFAULT_MAX_LINES} line limit)]`)}`;\n\t\t} else {\n\t\t\ttext += `\\n${theme.fg(\"warning\", `[Truncated: ${truncation.outputLines} lines shown (${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit)]`)}`;\n\t\t}\n\t}\n\treturn text;\n}\n\nexport function createReadToolDefinition(\n\tcwd: string,\n\toptions?: ReadToolOptions,\n): ToolDefinition<typeof readSchema, ReadToolDetails | undefined> {\n\tconst autoResizeImages = options?.autoResizeImages ?? true;\n\tconst ops = options?.operations ?? defaultReadOperations;\n\treturn {\n\t\tname: \"read\",\n\t\tlabel: \"read\",\n\t\tdescription: `Read the contents of a file. Supports text files and images (jpg, png, gif, webp). Images are sent as attachments. For text files, output is truncated to ${DEFAULT_MAX_LINES} lines or ${DEFAULT_MAX_BYTES / 1024}KB (whichever is hit first). Use offset/limit for large files. When you need the full file, continue with offset until complete.`,\n\t\tpromptSnippet: \"Read file contents\",\n\t\tpromptGuidelines: [\"Use read to examine files instead of cat or sed.\"],\n\t\tparameters: readSchema,\n\t\tasync execute(\n\t\t\t_toolCallId,\n\t\t\t{ path, offset, limit }: { path: string; offset?: number; limit?: number },\n\t\t\tsignal?: AbortSignal,\n\t\t\t_onUpdate?,\n\t\t\t_ctx?,\n\t\t) {\n\t\t\tconst absolutePath = resolveReadPath(path, cwd);\n\t\t\treturn new Promise<{ content: (TextContent | ImageContent)[]; details: ReadToolDetails | undefined }>(\n\t\t\t\t(resolve, reject) => {\n\t\t\t\t\tif (signal?.aborted) {\n\t\t\t\t\t\treject(new Error(\"Operation aborted\"));\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tlet aborted = false;\n\t\t\t\t\tconst onAbort = () => {\n\t\t\t\t\t\taborted = true;\n\t\t\t\t\t\treject(new Error(\"Operation aborted\"));\n\t\t\t\t\t};\n\t\t\t\t\tsignal?.addEventListener(\"abort\", onAbort, { once: true });\n\n\t\t\t\t\t(async () => {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t// Check if file exists and is readable.\n\t\t\t\t\t\t\tawait ops.access(absolutePath);\n\t\t\t\t\t\t\tif (aborted) return;\n\t\t\t\t\t\t\tconst mimeType = ops.detectImageMimeType ? await ops.detectImageMimeType(absolutePath) : undefined;\n\t\t\t\t\t\t\tlet content: (TextContent | ImageContent)[];\n\t\t\t\t\t\t\tlet details: ReadToolDetails | undefined;\n\t\t\t\t\t\t\tif (mimeType) {\n\t\t\t\t\t\t\t\t// Read image as binary.\n\t\t\t\t\t\t\t\tconst buffer = await ops.readFile(absolutePath);\n\t\t\t\t\t\t\t\tconst base64 = buffer.toString(\"base64\");\n\t\t\t\t\t\t\t\tif (autoResizeImages) {\n\t\t\t\t\t\t\t\t\t// Resize image if needed before sending it back to the model.\n\t\t\t\t\t\t\t\t\tconst resized = await resizeImage({ type: \"image\", data: base64, mimeType });\n\t\t\t\t\t\t\t\t\tif (!resized) {\n\t\t\t\t\t\t\t\t\t\tcontent = [\n\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\t\t\t\t\t\t\ttext: `Read image file [${mimeType}]\\n[Image omitted: could not be resized below the inline image size limit.]`,\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t];\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\tconst dimensionNote = formatDimensionNote(resized);\n\t\t\t\t\t\t\t\t\t\tlet textNote = `Read image file [${resized.mimeType}]`;\n\t\t\t\t\t\t\t\t\t\tif (dimensionNote) textNote += `\\n${dimensionNote}`;\n\t\t\t\t\t\t\t\t\t\tcontent = [\n\t\t\t\t\t\t\t\t\t\t\t{ type: \"text\", text: textNote },\n\t\t\t\t\t\t\t\t\t\t\t{ type: \"image\", data: resized.data, mimeType: resized.mimeType },\n\t\t\t\t\t\t\t\t\t\t];\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tcontent = [\n\t\t\t\t\t\t\t\t\t\t{ type: \"text\", text: `Read image file [${mimeType}]` },\n\t\t\t\t\t\t\t\t\t\t{ type: \"image\", data: base64, mimeType },\n\t\t\t\t\t\t\t\t\t];\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t// Read text content.\n\t\t\t\t\t\t\t\tconst buffer = await ops.readFile(absolutePath);\n\t\t\t\t\t\t\t\tconst textContent = buffer.toString(\"utf-8\");\n\t\t\t\t\t\t\t\tconst allLines = textContent.split(\"\\n\");\n\t\t\t\t\t\t\t\tconst totalFileLines = allLines.length;\n\t\t\t\t\t\t\t\t// Apply offset if specified. Convert from 1-indexed input to 0-indexed array access.\n\t\t\t\t\t\t\t\tconst startLine = offset ? Math.max(0, offset - 1) : 0;\n\t\t\t\t\t\t\t\tconst startLineDisplay = startLine + 1;\n\t\t\t\t\t\t\t\t// Check if offset is out of bounds.\n\t\t\t\t\t\t\t\tif (startLine >= allLines.length) {\n\t\t\t\t\t\t\t\t\tthrow new Error(`Offset ${offset} is beyond end of file (${allLines.length} lines total)`);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tlet selectedContent: string;\n\t\t\t\t\t\t\t\tlet userLimitedLines: number | undefined;\n\t\t\t\t\t\t\t\t// If limit is specified by the user, honor it first. Otherwise truncateHead decides.\n\t\t\t\t\t\t\t\tif (limit !== undefined) {\n\t\t\t\t\t\t\t\t\tconst endLine = Math.min(startLine + limit, allLines.length);\n\t\t\t\t\t\t\t\t\tselectedContent = allLines.slice(startLine, endLine).join(\"\\n\");\n\t\t\t\t\t\t\t\t\tuserLimitedLines = endLine - startLine;\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tselectedContent = allLines.slice(startLine).join(\"\\n\");\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t// Apply truncation, respecting both line and byte limits.\n\t\t\t\t\t\t\t\tconst truncation = truncateHead(selectedContent);\n\t\t\t\t\t\t\t\tlet outputText: string;\n\t\t\t\t\t\t\t\tif (truncation.firstLineExceedsLimit) {\n\t\t\t\t\t\t\t\t\t// First line alone exceeds the byte limit. Point the model at a bash fallback.\n\t\t\t\t\t\t\t\t\tconst firstLineSize = formatSize(Buffer.byteLength(allLines[startLine], \"utf-8\"));\n\t\t\t\t\t\t\t\t\toutputText = `[Line ${startLineDisplay} is ${firstLineSize}, exceeds ${formatSize(DEFAULT_MAX_BYTES)} limit. Use bash: sed -n '${startLineDisplay}p' ${path} | head -c ${DEFAULT_MAX_BYTES}]`;\n\t\t\t\t\t\t\t\t\tdetails = { truncation };\n\t\t\t\t\t\t\t\t} else if (truncation.truncated) {\n\t\t\t\t\t\t\t\t\t// Truncation occurred. Build an actionable continuation notice.\n\t\t\t\t\t\t\t\t\tconst endLineDisplay = startLineDisplay + truncation.outputLines - 1;\n\t\t\t\t\t\t\t\t\tconst nextOffset = endLineDisplay + 1;\n\t\t\t\t\t\t\t\t\toutputText = truncation.content;\n\t\t\t\t\t\t\t\t\tif (truncation.truncatedBy === \"lines\") {\n\t\t\t\t\t\t\t\t\t\toutputText += `\\n\\n[Showing lines ${startLineDisplay}-${endLineDisplay} of ${totalFileLines}. Use offset=${nextOffset} to continue.]`;\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\toutputText += `\\n\\n[Showing lines ${startLineDisplay}-${endLineDisplay} of ${totalFileLines} (${formatSize(DEFAULT_MAX_BYTES)} limit). Use offset=${nextOffset} to continue.]`;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tdetails = { truncation };\n\t\t\t\t\t\t\t\t} else if (userLimitedLines !== undefined && startLine + userLimitedLines < allLines.length) {\n\t\t\t\t\t\t\t\t\t// User-specified limit stopped early, but the file still has more content.\n\t\t\t\t\t\t\t\t\tconst remaining = allLines.length - (startLine + userLimitedLines);\n\t\t\t\t\t\t\t\t\tconst nextOffset = startLine + userLimitedLines + 1;\n\t\t\t\t\t\t\t\t\toutputText = `${truncation.content}\\n\\n[${remaining} more lines in file. Use offset=${nextOffset} to continue.]`;\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t// No truncation and no remaining user-limited content.\n\t\t\t\t\t\t\t\t\toutputText = truncation.content;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tcontent = [{ type: \"text\", text: outputText }];\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif (aborted) return;\n\t\t\t\t\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\t\t\t\t\t\t\tresolve({ content, details });\n\t\t\t\t\t\t} catch (error: any) {\n\t\t\t\t\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\t\t\t\t\t\t\tif (!aborted) reject(error);\n\t\t\t\t\t\t}\n\t\t\t\t\t})();\n\t\t\t\t},\n\t\t\t);\n\t\t},\n\t\trenderCall(args, theme, context) {\n\t\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\t\ttext.setText(formatReadCall(args, theme));\n\t\t\treturn text;\n\t\t},\n\t\trenderResult(result, options, theme, context) {\n\t\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\t\ttext.setText(formatReadResult(context.args, result as any, options, theme, context.showImages));\n\t\t\treturn text;\n\t\t},\n\t};\n}\n\nexport function createReadTool(cwd: string, options?: ReadToolOptions): AgentTool<typeof readSchema> {\n\treturn wrapToolDefinition(createReadToolDefinition(cwd, options));\n}\n\n/** Default read tool using process.cwd() for backwards compatibility. */\nexport const readToolDefinition = createReadToolDefinition(process.cwd());\nexport const readTool = createReadTool(process.cwd());\n"]}
@@ -1,9 +1,14 @@
1
+ import { Text } from "@hyperspaceng/neural-tui";
1
2
  import { Type } from "@sinclair/typebox";
2
3
  import { constants } from "fs";
3
4
  import { access as fsAccess, readFile as fsReadFile } from "fs/promises";
5
+ import { keyHint } from "../../modes/interactive/components/keybinding-hints.js";
6
+ import { getLanguageFromPath, highlightCode } from "../../modes/interactive/theme/theme.js";
4
7
  import { formatDimensionNote, resizeImage } from "../../utils/image-resize.js";
5
8
  import { detectSupportedImageMimeTypeFromFile } from "../../utils/mime.js";
6
9
  import { resolveReadPath } from "./path-utils.js";
10
+ import { getTextOutput, invalidArgText, replaceTabs, shortenPath, str } from "./render-utils.js";
11
+ import { wrapToolDefinition } from "./tool-definition-wrapper.js";
7
12
  import { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize, truncateHead } from "./truncate.js";
8
13
  const readSchema = Type.Object({
9
14
  path: Type.String({ description: "Path to the file to read (relative or absolute)" }),
@@ -15,85 +20,135 @@ const defaultReadOperations = {
15
20
  access: (path) => fsAccess(path, constants.R_OK),
16
21
  detectImageMimeType: detectSupportedImageMimeTypeFromFile,
17
22
  };
18
- export function createReadTool(cwd, options) {
23
+ function formatReadCall(args, theme) {
24
+ const rawPath = str(args?.file_path ?? args?.path);
25
+ const path = rawPath !== null ? shortenPath(rawPath) : null;
26
+ const offset = args?.offset;
27
+ const limit = args?.limit;
28
+ const invalidArg = invalidArgText(theme);
29
+ let pathDisplay = path === null ? invalidArg : path ? theme.fg("accent", path) : theme.fg("toolOutput", "...");
30
+ if (offset !== undefined || limit !== undefined) {
31
+ const startLine = offset ?? 1;
32
+ const endLine = limit !== undefined ? startLine + limit - 1 : "";
33
+ pathDisplay += theme.fg("warning", `:${startLine}${endLine ? `-${endLine}` : ""}`);
34
+ }
35
+ return `${theme.fg("toolTitle", theme.bold("read"))} ${pathDisplay}`;
36
+ }
37
+ function trimTrailingEmptyLines(lines) {
38
+ let end = lines.length;
39
+ while (end > 0 && lines[end - 1] === "") {
40
+ end--;
41
+ }
42
+ return lines.slice(0, end);
43
+ }
44
+ function formatReadResult(args, result, options, theme, showImages) {
45
+ const rawPath = str(args?.file_path ?? args?.path);
46
+ const output = getTextOutput(result, showImages);
47
+ const lang = rawPath ? getLanguageFromPath(rawPath) : undefined;
48
+ const renderedLines = lang ? highlightCode(replaceTabs(output), lang) : output.split("\n");
49
+ const lines = trimTrailingEmptyLines(renderedLines);
50
+ const maxLines = options.expanded ? lines.length : 10;
51
+ const displayLines = lines.slice(0, maxLines);
52
+ const remaining = lines.length - maxLines;
53
+ let text = `\n${displayLines.map((line) => (lang ? replaceTabs(line) : theme.fg("toolOutput", replaceTabs(line)))).join("\n")}`;
54
+ if (remaining > 0) {
55
+ text += `${theme.fg("muted", `\n... (${remaining} more lines,`)} ${keyHint("app.tools.expand", "to expand")})`;
56
+ }
57
+ const truncation = result.details?.truncation;
58
+ if (truncation?.truncated) {
59
+ if (truncation.firstLineExceedsLimit) {
60
+ text += `\n${theme.fg("warning", `[First line exceeds ${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit]`)}`;
61
+ }
62
+ else if (truncation.truncatedBy === "lines") {
63
+ text += `\n${theme.fg("warning", `[Truncated: showing ${truncation.outputLines} of ${truncation.totalLines} lines (${truncation.maxLines ?? DEFAULT_MAX_LINES} line limit)]`)}`;
64
+ }
65
+ else {
66
+ text += `\n${theme.fg("warning", `[Truncated: ${truncation.outputLines} lines shown (${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit)]`)}`;
67
+ }
68
+ }
69
+ return text;
70
+ }
71
+ export function createReadToolDefinition(cwd, options) {
19
72
  const autoResizeImages = options?.autoResizeImages ?? true;
20
73
  const ops = options?.operations ?? defaultReadOperations;
21
74
  return {
22
75
  name: "read",
23
76
  label: "read",
24
77
  description: `Read the contents of a file. Supports text files and images (jpg, png, gif, webp). Images are sent as attachments. For text files, output is truncated to ${DEFAULT_MAX_LINES} lines or ${DEFAULT_MAX_BYTES / 1024}KB (whichever is hit first). Use offset/limit for large files. When you need the full file, continue with offset until complete.`,
78
+ promptSnippet: "Read file contents",
79
+ promptGuidelines: ["Use read to examine files instead of cat or sed."],
25
80
  parameters: readSchema,
26
- execute: async (_toolCallId, { path, offset, limit }, signal) => {
81
+ async execute(_toolCallId, { path, offset, limit }, signal, _onUpdate, _ctx) {
27
82
  const absolutePath = resolveReadPath(path, cwd);
28
83
  return new Promise((resolve, reject) => {
29
- // Check if already aborted
30
84
  if (signal?.aborted) {
31
85
  reject(new Error("Operation aborted"));
32
86
  return;
33
87
  }
34
88
  let aborted = false;
35
- // Set up abort handler
36
89
  const onAbort = () => {
37
90
  aborted = true;
38
91
  reject(new Error("Operation aborted"));
39
92
  };
40
- if (signal) {
41
- signal.addEventListener("abort", onAbort, { once: true });
42
- }
43
- // Perform the read operation
93
+ signal?.addEventListener("abort", onAbort, { once: true });
44
94
  (async () => {
45
95
  try {
46
- // Check if file exists
96
+ // Check if file exists and is readable.
47
97
  await ops.access(absolutePath);
48
- // Check if aborted before reading
49
- if (aborted) {
98
+ if (aborted)
50
99
  return;
51
- }
52
100
  const mimeType = ops.detectImageMimeType ? await ops.detectImageMimeType(absolutePath) : undefined;
53
- // Read the file based on type
54
101
  let content;
55
102
  let details;
56
103
  if (mimeType) {
57
- // Read as image (binary)
104
+ // Read image as binary.
58
105
  const buffer = await ops.readFile(absolutePath);
59
106
  const base64 = buffer.toString("base64");
60
107
  if (autoResizeImages) {
61
- // Resize image if needed
108
+ // Resize image if needed before sending it back to the model.
62
109
  const resized = await resizeImage({ type: "image", data: base64, mimeType });
63
- const dimensionNote = formatDimensionNote(resized);
64
- let textNote = `Read image file [${resized.mimeType}]`;
65
- if (dimensionNote) {
66
- textNote += `\n${dimensionNote}`;
110
+ if (!resized) {
111
+ content = [
112
+ {
113
+ type: "text",
114
+ text: `Read image file [${mimeType}]\n[Image omitted: could not be resized below the inline image size limit.]`,
115
+ },
116
+ ];
117
+ }
118
+ else {
119
+ const dimensionNote = formatDimensionNote(resized);
120
+ let textNote = `Read image file [${resized.mimeType}]`;
121
+ if (dimensionNote)
122
+ textNote += `\n${dimensionNote}`;
123
+ content = [
124
+ { type: "text", text: textNote },
125
+ { type: "image", data: resized.data, mimeType: resized.mimeType },
126
+ ];
67
127
  }
68
- content = [
69
- { type: "text", text: textNote },
70
- { type: "image", data: resized.data, mimeType: resized.mimeType },
71
- ];
72
128
  }
73
129
  else {
74
- const textNote = `Read image file [${mimeType}]`;
75
130
  content = [
76
- { type: "text", text: textNote },
131
+ { type: "text", text: `Read image file [${mimeType}]` },
77
132
  { type: "image", data: base64, mimeType },
78
133
  ];
79
134
  }
80
135
  }
81
136
  else {
82
- // Read as text
137
+ // Read text content.
83
138
  const buffer = await ops.readFile(absolutePath);
84
139
  const textContent = buffer.toString("utf-8");
85
140
  const allLines = textContent.split("\n");
86
141
  const totalFileLines = allLines.length;
87
- // Apply offset if specified (1-indexed to 0-indexed)
142
+ // Apply offset if specified. Convert from 1-indexed input to 0-indexed array access.
88
143
  const startLine = offset ? Math.max(0, offset - 1) : 0;
89
- const startLineDisplay = startLine + 1; // For display (1-indexed)
90
- // Check if offset is out of bounds
144
+ const startLineDisplay = startLine + 1;
145
+ // Check if offset is out of bounds.
91
146
  if (startLine >= allLines.length) {
92
147
  throw new Error(`Offset ${offset} is beyond end of file (${allLines.length} lines total)`);
93
148
  }
94
- // If limit is specified by user, use it; otherwise we'll let truncateHead decide
95
149
  let selectedContent;
96
150
  let userLimitedLines;
151
+ // If limit is specified by the user, honor it first. Otherwise truncateHead decides.
97
152
  if (limit !== undefined) {
98
153
  const endLine = Math.min(startLine + limit, allLines.length);
99
154
  selectedContent = allLines.slice(startLine, endLine).join("\n");
@@ -102,17 +157,17 @@ export function createReadTool(cwd, options) {
102
157
  else {
103
158
  selectedContent = allLines.slice(startLine).join("\n");
104
159
  }
105
- // Apply truncation (respects both line and byte limits)
160
+ // Apply truncation, respecting both line and byte limits.
106
161
  const truncation = truncateHead(selectedContent);
107
162
  let outputText;
108
163
  if (truncation.firstLineExceedsLimit) {
109
- // First line at offset exceeds 30KB - tell model to use bash
164
+ // First line alone exceeds the byte limit. Point the model at a bash fallback.
110
165
  const firstLineSize = formatSize(Buffer.byteLength(allLines[startLine], "utf-8"));
111
166
  outputText = `[Line ${startLineDisplay} is ${firstLineSize}, exceeds ${formatSize(DEFAULT_MAX_BYTES)} limit. Use bash: sed -n '${startLineDisplay}p' ${path} | head -c ${DEFAULT_MAX_BYTES}]`;
112
167
  details = { truncation };
113
168
  }
114
169
  else if (truncation.truncated) {
115
- // Truncation occurred - build actionable notice
170
+ // Truncation occurred. Build an actionable continuation notice.
116
171
  const endLineDisplay = startLineDisplay + truncation.outputLines - 1;
117
172
  const nextOffset = endLineDisplay + 1;
118
173
  outputText = truncation.content;
@@ -125,42 +180,46 @@ export function createReadTool(cwd, options) {
125
180
  details = { truncation };
126
181
  }
127
182
  else if (userLimitedLines !== undefined && startLine + userLimitedLines < allLines.length) {
128
- // User specified limit, there's more content, but no truncation
183
+ // User-specified limit stopped early, but the file still has more content.
129
184
  const remaining = allLines.length - (startLine + userLimitedLines);
130
185
  const nextOffset = startLine + userLimitedLines + 1;
131
- outputText = truncation.content;
132
- outputText += `\n\n[${remaining} more lines in file. Use offset=${nextOffset} to continue.]`;
186
+ outputText = `${truncation.content}\n\n[${remaining} more lines in file. Use offset=${nextOffset} to continue.]`;
133
187
  }
134
188
  else {
135
- // No truncation, no user limit exceeded
189
+ // No truncation and no remaining user-limited content.
136
190
  outputText = truncation.content;
137
191
  }
138
192
  content = [{ type: "text", text: outputText }];
139
193
  }
140
- // Check if aborted after reading
141
- if (aborted) {
194
+ if (aborted)
142
195
  return;
143
- }
144
- // Clean up abort handler
145
- if (signal) {
146
- signal.removeEventListener("abort", onAbort);
147
- }
196
+ signal?.removeEventListener("abort", onAbort);
148
197
  resolve({ content, details });
149
198
  }
150
199
  catch (error) {
151
- // Clean up abort handler
152
- if (signal) {
153
- signal.removeEventListener("abort", onAbort);
154
- }
155
- if (!aborted) {
200
+ signal?.removeEventListener("abort", onAbort);
201
+ if (!aborted)
156
202
  reject(error);
157
- }
158
203
  }
159
204
  })();
160
205
  });
161
206
  },
207
+ renderCall(args, theme, context) {
208
+ const text = context.lastComponent ?? new Text("", 0, 0);
209
+ text.setText(formatReadCall(args, theme));
210
+ return text;
211
+ },
212
+ renderResult(result, options, theme, context) {
213
+ const text = context.lastComponent ?? new Text("", 0, 0);
214
+ text.setText(formatReadResult(context.args, result, options, theme, context.showImages));
215
+ return text;
216
+ },
162
217
  };
163
218
  }
164
- /** Default read tool using process.cwd() - for backwards compatibility */
219
+ export function createReadTool(cwd, options) {
220
+ return wrapToolDefinition(createReadToolDefinition(cwd, options));
221
+ }
222
+ /** Default read tool using process.cwd() for backwards compatibility. */
223
+ export const readToolDefinition = createReadToolDefinition(process.cwd());
165
224
  export const readTool = createReadTool(process.cwd());
166
225
  //# sourceMappingURL=read.js.map