@openeryc/pi-coding-agent 0.75.11 → 0.75.13

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 (591) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  3. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  4. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  5. package/examples/extensions/sandbox/package-lock.json +2 -2
  6. package/examples/extensions/sandbox/package.json +1 -1
  7. package/examples/extensions/with-deps/package-lock.json +2 -2
  8. package/examples/extensions/with-deps/package.json +1 -1
  9. package/npm-shrinkwrap.json +12 -12
  10. package/package.json +4 -4
  11. package/dist/bun/cli.d.ts +0 -3
  12. package/dist/bun/cli.d.ts.map +0 -1
  13. package/dist/bun/cli.js +0 -9
  14. package/dist/bun/cli.js.map +0 -1
  15. package/dist/bun/register-bedrock.d.ts +0 -2
  16. package/dist/bun/register-bedrock.d.ts.map +0 -1
  17. package/dist/bun/register-bedrock.js +0 -4
  18. package/dist/bun/register-bedrock.js.map +0 -1
  19. package/dist/bun/restore-sandbox-env.d.ts +0 -13
  20. package/dist/bun/restore-sandbox-env.d.ts.map +0 -1
  21. package/dist/bun/restore-sandbox-env.js +0 -32
  22. package/dist/bun/restore-sandbox-env.js.map +0 -1
  23. package/dist/cli/args.d.ts +0 -53
  24. package/dist/cli/args.d.ts.map +0 -1
  25. package/dist/cli/args.js +0 -341
  26. package/dist/cli/args.js.map +0 -1
  27. package/dist/cli/config-selector.d.ts +0 -14
  28. package/dist/cli/config-selector.d.ts.map +0 -1
  29. package/dist/cli/config-selector.js +0 -31
  30. package/dist/cli/config-selector.js.map +0 -1
  31. package/dist/cli/file-processor.d.ts +0 -15
  32. package/dist/cli/file-processor.d.ts.map +0 -1
  33. package/dist/cli/file-processor.js +0 -83
  34. package/dist/cli/file-processor.js.map +0 -1
  35. package/dist/cli/initial-message.d.ts +0 -18
  36. package/dist/cli/initial-message.d.ts.map +0 -1
  37. package/dist/cli/initial-message.js +0 -22
  38. package/dist/cli/initial-message.js.map +0 -1
  39. package/dist/cli/list-models.d.ts +0 -9
  40. package/dist/cli/list-models.d.ts.map +0 -1
  41. package/dist/cli/list-models.js +0 -98
  42. package/dist/cli/list-models.js.map +0 -1
  43. package/dist/cli/session-picker.d.ts +0 -9
  44. package/dist/cli/session-picker.d.ts.map +0 -1
  45. package/dist/cli/session-picker.js +0 -35
  46. package/dist/cli/session-picker.js.map +0 -1
  47. package/dist/cli.d.ts +0 -3
  48. package/dist/cli.d.ts.map +0 -1
  49. package/dist/cli.js +0 -18
  50. package/dist/cli.js.map +0 -1
  51. package/dist/config.d.ts +0 -92
  52. package/dist/config.d.ts.map +0 -1
  53. package/dist/config.js +0 -422
  54. package/dist/config.js.map +0 -1
  55. package/dist/core/agent-session-runtime.d.ts +0 -117
  56. package/dist/core/agent-session-runtime.d.ts.map +0 -1
  57. package/dist/core/agent-session-runtime.js +0 -299
  58. package/dist/core/agent-session-runtime.js.map +0 -1
  59. package/dist/core/agent-session-services.d.ts +0 -86
  60. package/dist/core/agent-session-services.d.ts.map +0 -1
  61. package/dist/core/agent-session-services.js +0 -117
  62. package/dist/core/agent-session-services.js.map +0 -1
  63. package/dist/core/agent-session.d.ts +0 -605
  64. package/dist/core/agent-session.d.ts.map +0 -1
  65. package/dist/core/agent-session.js +0 -2519
  66. package/dist/core/agent-session.js.map +0 -1
  67. package/dist/core/auth-guidance.d.ts +0 -5
  68. package/dist/core/auth-guidance.d.ts.map +0 -1
  69. package/dist/core/auth-guidance.js +0 -21
  70. package/dist/core/auth-guidance.js.map +0 -1
  71. package/dist/core/auth-storage.d.ts +0 -141
  72. package/dist/core/auth-storage.d.ts.map +0 -1
  73. package/dist/core/auth-storage.js +0 -441
  74. package/dist/core/auth-storage.js.map +0 -1
  75. package/dist/core/bash-executor.d.ts +0 -32
  76. package/dist/core/bash-executor.d.ts.map +0 -1
  77. package/dist/core/bash-executor.js +0 -111
  78. package/dist/core/bash-executor.js.map +0 -1
  79. package/dist/core/compaction/branch-summarization.d.ts +0 -88
  80. package/dist/core/compaction/branch-summarization.d.ts.map +0 -1
  81. package/dist/core/compaction/branch-summarization.js +0 -243
  82. package/dist/core/compaction/branch-summarization.js.map +0 -1
  83. package/dist/core/compaction/compaction.d.ts +0 -121
  84. package/dist/core/compaction/compaction.d.ts.map +0 -1
  85. package/dist/core/compaction/compaction.js +0 -638
  86. package/dist/core/compaction/compaction.js.map +0 -1
  87. package/dist/core/compaction/index.d.ts +0 -7
  88. package/dist/core/compaction/index.d.ts.map +0 -1
  89. package/dist/core/compaction/index.js +0 -7
  90. package/dist/core/compaction/index.js.map +0 -1
  91. package/dist/core/compaction/utils.d.ts +0 -38
  92. package/dist/core/compaction/utils.d.ts.map +0 -1
  93. package/dist/core/compaction/utils.js +0 -153
  94. package/dist/core/compaction/utils.js.map +0 -1
  95. package/dist/core/defaults.d.ts +0 -3
  96. package/dist/core/defaults.d.ts.map +0 -1
  97. package/dist/core/defaults.js +0 -2
  98. package/dist/core/defaults.js.map +0 -1
  99. package/dist/core/diagnostics.d.ts +0 -15
  100. package/dist/core/diagnostics.d.ts.map +0 -1
  101. package/dist/core/diagnostics.js +0 -2
  102. package/dist/core/diagnostics.js.map +0 -1
  103. package/dist/core/event-bus.d.ts +0 -9
  104. package/dist/core/event-bus.d.ts.map +0 -1
  105. package/dist/core/event-bus.js +0 -25
  106. package/dist/core/event-bus.js.map +0 -1
  107. package/dist/core/exec.d.ts +0 -29
  108. package/dist/core/exec.d.ts.map +0 -1
  109. package/dist/core/exec.js +0 -75
  110. package/dist/core/exec.js.map +0 -1
  111. package/dist/core/export-html/ansi-to-html.d.ts +0 -22
  112. package/dist/core/export-html/ansi-to-html.d.ts.map +0 -1
  113. package/dist/core/export-html/ansi-to-html.js +0 -249
  114. package/dist/core/export-html/ansi-to-html.js.map +0 -1
  115. package/dist/core/export-html/index.d.ts +0 -37
  116. package/dist/core/export-html/index.d.ts.map +0 -1
  117. package/dist/core/export-html/index.js +0 -224
  118. package/dist/core/export-html/index.js.map +0 -1
  119. package/dist/core/export-html/template.css +0 -1066
  120. package/dist/core/export-html/template.html +0 -55
  121. package/dist/core/export-html/template.js +0 -1848
  122. package/dist/core/export-html/tool-renderer.d.ts +0 -34
  123. package/dist/core/export-html/tool-renderer.d.ts.map +0 -1
  124. package/dist/core/export-html/tool-renderer.js +0 -108
  125. package/dist/core/export-html/tool-renderer.js.map +0 -1
  126. package/dist/core/export-html/vendor/highlight.min.js +0 -1213
  127. package/dist/core/export-html/vendor/marked.min.js +0 -6
  128. package/dist/core/extensions/index.d.ts +0 -12
  129. package/dist/core/extensions/index.d.ts.map +0 -1
  130. package/dist/core/extensions/index.js +0 -9
  131. package/dist/core/extensions/index.js.map +0 -1
  132. package/dist/core/extensions/loader.d.ts +0 -24
  133. package/dist/core/extensions/loader.d.ts.map +0 -1
  134. package/dist/core/extensions/loader.js +0 -508
  135. package/dist/core/extensions/loader.js.map +0 -1
  136. package/dist/core/extensions/runner.d.ts +0 -159
  137. package/dist/core/extensions/runner.d.ts.map +0 -1
  138. package/dist/core/extensions/runner.js +0 -826
  139. package/dist/core/extensions/runner.js.map +0 -1
  140. package/dist/core/extensions/types.d.ts +0 -1181
  141. package/dist/core/extensions/types.d.ts.map +0 -1
  142. package/dist/core/extensions/types.js +0 -45
  143. package/dist/core/extensions/types.js.map +0 -1
  144. package/dist/core/extensions/wrapper.d.ts +0 -20
  145. package/dist/core/extensions/wrapper.d.ts.map +0 -1
  146. package/dist/core/extensions/wrapper.js +0 -22
  147. package/dist/core/extensions/wrapper.js.map +0 -1
  148. package/dist/core/footer-data-provider.d.ts +0 -52
  149. package/dist/core/footer-data-provider.d.ts.map +0 -1
  150. package/dist/core/footer-data-provider.js +0 -310
  151. package/dist/core/footer-data-provider.js.map +0 -1
  152. package/dist/core/http-dispatcher.d.ts +0 -21
  153. package/dist/core/http-dispatcher.d.ts.map +0 -1
  154. package/dist/core/http-dispatcher.js +0 -48
  155. package/dist/core/http-dispatcher.js.map +0 -1
  156. package/dist/core/index.d.ts +0 -12
  157. package/dist/core/index.d.ts.map +0 -1
  158. package/dist/core/index.js +0 -12
  159. package/dist/core/index.js.map +0 -1
  160. package/dist/core/keybindings.d.ts +0 -353
  161. package/dist/core/keybindings.d.ts.map +0 -1
  162. package/dist/core/keybindings.js +0 -295
  163. package/dist/core/keybindings.js.map +0 -1
  164. package/dist/core/messages.d.ts +0 -77
  165. package/dist/core/messages.d.ts.map +0 -1
  166. package/dist/core/messages.js +0 -123
  167. package/dist/core/messages.js.map +0 -1
  168. package/dist/core/model-registry.d.ts +0 -150
  169. package/dist/core/model-registry.d.ts.map +0 -1
  170. package/dist/core/model-registry.js +0 -728
  171. package/dist/core/model-registry.js.map +0 -1
  172. package/dist/core/model-resolver.d.ts +0 -110
  173. package/dist/core/model-resolver.d.ts.map +0 -1
  174. package/dist/core/model-resolver.js +0 -495
  175. package/dist/core/model-resolver.js.map +0 -1
  176. package/dist/core/output-guard.d.ts +0 -6
  177. package/dist/core/output-guard.d.ts.map +0 -1
  178. package/dist/core/output-guard.js +0 -59
  179. package/dist/core/output-guard.js.map +0 -1
  180. package/dist/core/package-manager.d.ts +0 -203
  181. package/dist/core/package-manager.d.ts.map +0 -1
  182. package/dist/core/package-manager.js +0 -2013
  183. package/dist/core/package-manager.js.map +0 -1
  184. package/dist/core/prompt-templates.d.ts +0 -52
  185. package/dist/core/prompt-templates.d.ts.map +0 -1
  186. package/dist/core/prompt-templates.js +0 -252
  187. package/dist/core/prompt-templates.js.map +0 -1
  188. package/dist/core/provider-display-names.d.ts +0 -2
  189. package/dist/core/provider-display-names.d.ts.map +0 -1
  190. package/dist/core/provider-display-names.js +0 -33
  191. package/dist/core/provider-display-names.js.map +0 -1
  192. package/dist/core/resolve-config-value.d.ts +0 -23
  193. package/dist/core/resolve-config-value.d.ts.map +0 -1
  194. package/dist/core/resolve-config-value.js +0 -126
  195. package/dist/core/resolve-config-value.js.map +0 -1
  196. package/dist/core/resource-loader.d.ts +0 -197
  197. package/dist/core/resource-loader.d.ts.map +0 -1
  198. package/dist/core/resource-loader.js +0 -757
  199. package/dist/core/resource-loader.js.map +0 -1
  200. package/dist/core/sdk.d.ts +0 -107
  201. package/dist/core/sdk.d.ts.map +0 -1
  202. package/dist/core/sdk.js +0 -282
  203. package/dist/core/sdk.js.map +0 -1
  204. package/dist/core/session-cwd.d.ts +0 -19
  205. package/dist/core/session-cwd.d.ts.map +0 -1
  206. package/dist/core/session-cwd.js +0 -38
  207. package/dist/core/session-cwd.js.map +0 -1
  208. package/dist/core/session-manager.d.ts +0 -363
  209. package/dist/core/session-manager.d.ts.map +0 -1
  210. package/dist/core/session-manager.js +0 -1318
  211. package/dist/core/session-manager.js.map +0 -1
  212. package/dist/core/settings-manager.d.ts +0 -264
  213. package/dist/core/settings-manager.d.ts.map +0 -1
  214. package/dist/core/settings-manager.js +0 -802
  215. package/dist/core/settings-manager.js.map +0 -1
  216. package/dist/core/skills.d.ts +0 -60
  217. package/dist/core/skills.d.ts.map +0 -1
  218. package/dist/core/skills.js +0 -401
  219. package/dist/core/skills.js.map +0 -1
  220. package/dist/core/slash-commands.d.ts +0 -14
  221. package/dist/core/slash-commands.d.ts.map +0 -1
  222. package/dist/core/slash-commands.js +0 -28
  223. package/dist/core/slash-commands.js.map +0 -1
  224. package/dist/core/source-info.d.ts +0 -18
  225. package/dist/core/source-info.d.ts.map +0 -1
  226. package/dist/core/source-info.js +0 -19
  227. package/dist/core/source-info.js.map +0 -1
  228. package/dist/core/system-prompt.d.ts +0 -30
  229. package/dist/core/system-prompt.d.ts.map +0 -1
  230. package/dist/core/system-prompt.js +0 -132
  231. package/dist/core/system-prompt.js.map +0 -1
  232. package/dist/core/telemetry.d.ts +0 -3
  233. package/dist/core/telemetry.d.ts.map +0 -1
  234. package/dist/core/telemetry.js +0 -9
  235. package/dist/core/telemetry.js.map +0 -1
  236. package/dist/core/timings.d.ts +0 -8
  237. package/dist/core/timings.d.ts.map +0 -1
  238. package/dist/core/timings.js +0 -31
  239. package/dist/core/timings.js.map +0 -1
  240. package/dist/core/tools/bash.d.ts +0 -68
  241. package/dist/core/tools/bash.d.ts.map +0 -1
  242. package/dist/core/tools/bash.js +0 -336
  243. package/dist/core/tools/bash.js.map +0 -1
  244. package/dist/core/tools/edit-diff.d.ts +0 -85
  245. package/dist/core/tools/edit-diff.d.ts.map +0 -1
  246. package/dist/core/tools/edit-diff.js +0 -338
  247. package/dist/core/tools/edit-diff.js.map +0 -1
  248. package/dist/core/tools/edit.d.ts +0 -49
  249. package/dist/core/tools/edit.d.ts.map +0 -1
  250. package/dist/core/tools/edit.js +0 -324
  251. package/dist/core/tools/edit.js.map +0 -1
  252. package/dist/core/tools/file-mutation-queue.d.ts +0 -6
  253. package/dist/core/tools/file-mutation-queue.d.ts.map +0 -1
  254. package/dist/core/tools/file-mutation-queue.js +0 -37
  255. package/dist/core/tools/file-mutation-queue.js.map +0 -1
  256. package/dist/core/tools/find.d.ts +0 -35
  257. package/dist/core/tools/find.d.ts.map +0 -1
  258. package/dist/core/tools/find.js +0 -298
  259. package/dist/core/tools/find.js.map +0 -1
  260. package/dist/core/tools/grep.d.ts +0 -37
  261. package/dist/core/tools/grep.d.ts.map +0 -1
  262. package/dist/core/tools/grep.js +0 -304
  263. package/dist/core/tools/grep.js.map +0 -1
  264. package/dist/core/tools/index.d.ts +0 -40
  265. package/dist/core/tools/index.d.ts.map +0 -1
  266. package/dist/core/tools/index.js +0 -112
  267. package/dist/core/tools/index.js.map +0 -1
  268. package/dist/core/tools/ls.d.ts +0 -37
  269. package/dist/core/tools/ls.d.ts.map +0 -1
  270. package/dist/core/tools/ls.js +0 -169
  271. package/dist/core/tools/ls.js.map +0 -1
  272. package/dist/core/tools/output-accumulator.d.ts +0 -50
  273. package/dist/core/tools/output-accumulator.d.ts.map +0 -1
  274. package/dist/core/tools/output-accumulator.js +0 -178
  275. package/dist/core/tools/output-accumulator.js.map +0 -1
  276. package/dist/core/tools/path-utils.d.ts +0 -8
  277. package/dist/core/tools/path-utils.d.ts.map +0 -1
  278. package/dist/core/tools/path-utils.js +0 -81
  279. package/dist/core/tools/path-utils.js.map +0 -1
  280. package/dist/core/tools/read.d.ts +0 -35
  281. package/dist/core/tools/read.d.ts.map +0 -1
  282. package/dist/core/tools/read.js +0 -291
  283. package/dist/core/tools/read.js.map +0 -1
  284. package/dist/core/tools/render-utils.d.ts +0 -21
  285. package/dist/core/tools/render-utils.d.ts.map +0 -1
  286. package/dist/core/tools/render-utils.js +0 -49
  287. package/dist/core/tools/render-utils.js.map +0 -1
  288. package/dist/core/tools/tool-definition-wrapper.d.ts +0 -14
  289. package/dist/core/tools/tool-definition-wrapper.d.ts.map +0 -1
  290. package/dist/core/tools/tool-definition-wrapper.js +0 -34
  291. package/dist/core/tools/tool-definition-wrapper.js.map +0 -1
  292. package/dist/core/tools/truncate.d.ts +0 -70
  293. package/dist/core/tools/truncate.d.ts.map +0 -1
  294. package/dist/core/tools/truncate.js +0 -205
  295. package/dist/core/tools/truncate.js.map +0 -1
  296. package/dist/core/tools/write.d.ts +0 -26
  297. package/dist/core/tools/write.d.ts.map +0 -1
  298. package/dist/core/tools/write.js +0 -213
  299. package/dist/core/tools/write.js.map +0 -1
  300. package/dist/index.d.ts +0 -29
  301. package/dist/index.d.ts.map +0 -1
  302. package/dist/index.js +0 -42
  303. package/dist/index.js.map +0 -1
  304. package/dist/main.d.ts +0 -12
  305. package/dist/main.d.ts.map +0 -1
  306. package/dist/main.js +0 -587
  307. package/dist/main.js.map +0 -1
  308. package/dist/migrations.d.ts +0 -33
  309. package/dist/migrations.d.ts.map +0 -1
  310. package/dist/migrations.js +0 -281
  311. package/dist/migrations.js.map +0 -1
  312. package/dist/modes/index.d.ts +0 -10
  313. package/dist/modes/index.d.ts.map +0 -1
  314. package/dist/modes/index.js +0 -9
  315. package/dist/modes/index.js.map +0 -1
  316. package/dist/modes/interactive/assets/clankolas.png +0 -0
  317. package/dist/modes/interactive/components/armin.d.ts +0 -34
  318. package/dist/modes/interactive/components/armin.d.ts.map +0 -1
  319. package/dist/modes/interactive/components/armin.js +0 -333
  320. package/dist/modes/interactive/components/armin.js.map +0 -1
  321. package/dist/modes/interactive/components/assistant-message.d.ts +0 -20
  322. package/dist/modes/interactive/components/assistant-message.d.ts.map +0 -1
  323. package/dist/modes/interactive/components/assistant-message.js +0 -121
  324. package/dist/modes/interactive/components/assistant-message.js.map +0 -1
  325. package/dist/modes/interactive/components/bash-execution.d.ts +0 -34
  326. package/dist/modes/interactive/components/bash-execution.d.ts.map +0 -1
  327. package/dist/modes/interactive/components/bash-execution.js +0 -175
  328. package/dist/modes/interactive/components/bash-execution.js.map +0 -1
  329. package/dist/modes/interactive/components/bordered-loader.d.ts +0 -16
  330. package/dist/modes/interactive/components/bordered-loader.d.ts.map +0 -1
  331. package/dist/modes/interactive/components/bordered-loader.js +0 -54
  332. package/dist/modes/interactive/components/bordered-loader.js.map +0 -1
  333. package/dist/modes/interactive/components/branch-summary-message.d.ts +0 -16
  334. package/dist/modes/interactive/components/branch-summary-message.d.ts.map +0 -1
  335. package/dist/modes/interactive/components/branch-summary-message.js +0 -44
  336. package/dist/modes/interactive/components/branch-summary-message.js.map +0 -1
  337. package/dist/modes/interactive/components/compaction-summary-message.d.ts +0 -16
  338. package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +0 -1
  339. package/dist/modes/interactive/components/compaction-summary-message.js +0 -45
  340. package/dist/modes/interactive/components/compaction-summary-message.js.map +0 -1
  341. package/dist/modes/interactive/components/config-selector.d.ts +0 -71
  342. package/dist/modes/interactive/components/config-selector.d.ts.map +0 -1
  343. package/dist/modes/interactive/components/config-selector.js +0 -506
  344. package/dist/modes/interactive/components/config-selector.js.map +0 -1
  345. package/dist/modes/interactive/components/countdown-timer.d.ts +0 -14
  346. package/dist/modes/interactive/components/countdown-timer.d.ts.map +0 -1
  347. package/dist/modes/interactive/components/countdown-timer.js +0 -33
  348. package/dist/modes/interactive/components/countdown-timer.js.map +0 -1
  349. package/dist/modes/interactive/components/custom-editor.d.ts +0 -21
  350. package/dist/modes/interactive/components/custom-editor.d.ts.map +0 -1
  351. package/dist/modes/interactive/components/custom-editor.js +0 -70
  352. package/dist/modes/interactive/components/custom-editor.js.map +0 -1
  353. package/dist/modes/interactive/components/custom-message.d.ts +0 -20
  354. package/dist/modes/interactive/components/custom-message.d.ts.map +0 -1
  355. package/dist/modes/interactive/components/custom-message.js +0 -79
  356. package/dist/modes/interactive/components/custom-message.js.map +0 -1
  357. package/dist/modes/interactive/components/daxnuts.d.ts +0 -23
  358. package/dist/modes/interactive/components/daxnuts.d.ts.map +0 -1
  359. package/dist/modes/interactive/components/daxnuts.js +0 -140
  360. package/dist/modes/interactive/components/daxnuts.js.map +0 -1
  361. package/dist/modes/interactive/components/diff.d.ts +0 -12
  362. package/dist/modes/interactive/components/diff.d.ts.map +0 -1
  363. package/dist/modes/interactive/components/diff.js +0 -133
  364. package/dist/modes/interactive/components/diff.js.map +0 -1
  365. package/dist/modes/interactive/components/dynamic-border.d.ts +0 -15
  366. package/dist/modes/interactive/components/dynamic-border.d.ts.map +0 -1
  367. package/dist/modes/interactive/components/dynamic-border.js +0 -21
  368. package/dist/modes/interactive/components/dynamic-border.js.map +0 -1
  369. package/dist/modes/interactive/components/earendil-announcement.d.ts +0 -5
  370. package/dist/modes/interactive/components/earendil-announcement.d.ts.map +0 -1
  371. package/dist/modes/interactive/components/earendil-announcement.js +0 -40
  372. package/dist/modes/interactive/components/earendil-announcement.js.map +0 -1
  373. package/dist/modes/interactive/components/extension-editor.d.ts +0 -20
  374. package/dist/modes/interactive/components/extension-editor.d.ts.map +0 -1
  375. package/dist/modes/interactive/components/extension-editor.js +0 -119
  376. package/dist/modes/interactive/components/extension-editor.js.map +0 -1
  377. package/dist/modes/interactive/components/extension-input.d.ts +0 -23
  378. package/dist/modes/interactive/components/extension-input.d.ts.map +0 -1
  379. package/dist/modes/interactive/components/extension-input.js +0 -61
  380. package/dist/modes/interactive/components/extension-input.js.map +0 -1
  381. package/dist/modes/interactive/components/extension-selector.d.ts +0 -26
  382. package/dist/modes/interactive/components/extension-selector.d.ts.map +0 -1
  383. package/dist/modes/interactive/components/extension-selector.js +0 -83
  384. package/dist/modes/interactive/components/extension-selector.js.map +0 -1
  385. package/dist/modes/interactive/components/footer.d.ts +0 -27
  386. package/dist/modes/interactive/components/footer.d.ts.map +0 -1
  387. package/dist/modes/interactive/components/footer.js +0 -201
  388. package/dist/modes/interactive/components/footer.js.map +0 -1
  389. package/dist/modes/interactive/components/index.d.ts +0 -32
  390. package/dist/modes/interactive/components/index.d.ts.map +0 -1
  391. package/dist/modes/interactive/components/index.js +0 -33
  392. package/dist/modes/interactive/components/index.js.map +0 -1
  393. package/dist/modes/interactive/components/keybinding-hints.d.ts +0 -13
  394. package/dist/modes/interactive/components/keybinding-hints.d.ts.map +0 -1
  395. package/dist/modes/interactive/components/keybinding-hints.js +0 -36
  396. package/dist/modes/interactive/components/keybinding-hints.js.map +0 -1
  397. package/dist/modes/interactive/components/login-dialog.d.ts +0 -46
  398. package/dist/modes/interactive/components/login-dialog.d.ts.map +0 -1
  399. package/dist/modes/interactive/components/login-dialog.js +0 -160
  400. package/dist/modes/interactive/components/login-dialog.js.map +0 -1
  401. package/dist/modes/interactive/components/model-selector.d.ts +0 -47
  402. package/dist/modes/interactive/components/model-selector.d.ts.map +0 -1
  403. package/dist/modes/interactive/components/model-selector.js +0 -278
  404. package/dist/modes/interactive/components/model-selector.js.map +0 -1
  405. package/dist/modes/interactive/components/oauth-selector.d.ts +0 -31
  406. package/dist/modes/interactive/components/oauth-selector.d.ts.map +0 -1
  407. package/dist/modes/interactive/components/oauth-selector.js +0 -165
  408. package/dist/modes/interactive/components/oauth-selector.js.map +0 -1
  409. package/dist/modes/interactive/components/scoped-models-selector.d.ts +0 -42
  410. package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +0 -1
  411. package/dist/modes/interactive/components/scoped-models-selector.js +0 -290
  412. package/dist/modes/interactive/components/scoped-models-selector.js.map +0 -1
  413. package/dist/modes/interactive/components/session-selector-search.d.ts +0 -23
  414. package/dist/modes/interactive/components/session-selector-search.d.ts.map +0 -1
  415. package/dist/modes/interactive/components/session-selector-search.js +0 -155
  416. package/dist/modes/interactive/components/session-selector-search.js.map +0 -1
  417. package/dist/modes/interactive/components/session-selector.d.ts +0 -96
  418. package/dist/modes/interactive/components/session-selector.d.ts.map +0 -1
  419. package/dist/modes/interactive/components/session-selector.js +0 -861
  420. package/dist/modes/interactive/components/session-selector.js.map +0 -1
  421. package/dist/modes/interactive/components/settings-selector.d.ts +0 -69
  422. package/dist/modes/interactive/components/settings-selector.d.ts.map +0 -1
  423. package/dist/modes/interactive/components/settings-selector.js +0 -390
  424. package/dist/modes/interactive/components/settings-selector.js.map +0 -1
  425. package/dist/modes/interactive/components/show-images-selector.d.ts +0 -10
  426. package/dist/modes/interactive/components/show-images-selector.d.ts.map +0 -1
  427. package/dist/modes/interactive/components/show-images-selector.js +0 -39
  428. package/dist/modes/interactive/components/show-images-selector.js.map +0 -1
  429. package/dist/modes/interactive/components/skill-invocation-message.d.ts +0 -17
  430. package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +0 -1
  431. package/dist/modes/interactive/components/skill-invocation-message.js +0 -47
  432. package/dist/modes/interactive/components/skill-invocation-message.js.map +0 -1
  433. package/dist/modes/interactive/components/theme-selector.d.ts +0 -11
  434. package/dist/modes/interactive/components/theme-selector.d.ts.map +0 -1
  435. package/dist/modes/interactive/components/theme-selector.js +0 -50
  436. package/dist/modes/interactive/components/theme-selector.js.map +0 -1
  437. package/dist/modes/interactive/components/thinking-selector.d.ts +0 -11
  438. package/dist/modes/interactive/components/thinking-selector.d.ts.map +0 -1
  439. package/dist/modes/interactive/components/thinking-selector.js +0 -51
  440. package/dist/modes/interactive/components/thinking-selector.js.map +0 -1
  441. package/dist/modes/interactive/components/tool-execution.d.ts +0 -63
  442. package/dist/modes/interactive/components/tool-execution.d.ts.map +0 -1
  443. package/dist/modes/interactive/components/tool-execution.js +0 -295
  444. package/dist/modes/interactive/components/tool-execution.js.map +0 -1
  445. package/dist/modes/interactive/components/tree-selector.d.ts +0 -89
  446. package/dist/modes/interactive/components/tree-selector.d.ts.map +0 -1
  447. package/dist/modes/interactive/components/tree-selector.js +0 -1093
  448. package/dist/modes/interactive/components/tree-selector.js.map +0 -1
  449. package/dist/modes/interactive/components/user-message-selector.d.ts +0 -30
  450. package/dist/modes/interactive/components/user-message-selector.d.ts.map +0 -1
  451. package/dist/modes/interactive/components/user-message-selector.js +0 -114
  452. package/dist/modes/interactive/components/user-message-selector.js.map +0 -1
  453. package/dist/modes/interactive/components/user-message.d.ts +0 -10
  454. package/dist/modes/interactive/components/user-message.d.ts.map +0 -1
  455. package/dist/modes/interactive/components/user-message.js +0 -29
  456. package/dist/modes/interactive/components/user-message.js.map +0 -1
  457. package/dist/modes/interactive/components/visual-truncate.d.ts +0 -24
  458. package/dist/modes/interactive/components/visual-truncate.d.ts.map +0 -1
  459. package/dist/modes/interactive/components/visual-truncate.js +0 -33
  460. package/dist/modes/interactive/components/visual-truncate.js.map +0 -1
  461. package/dist/modes/interactive/interactive-mode.d.ts +0 -373
  462. package/dist/modes/interactive/interactive-mode.d.ts.map +0 -1
  463. package/dist/modes/interactive/interactive-mode.js +0 -4750
  464. package/dist/modes/interactive/interactive-mode.js.map +0 -1
  465. package/dist/modes/interactive/theme/dark.json +0 -86
  466. package/dist/modes/interactive/theme/light.json +0 -85
  467. package/dist/modes/interactive/theme/theme-schema.json +0 -335
  468. package/dist/modes/interactive/theme/theme.d.ts +0 -100
  469. package/dist/modes/interactive/theme/theme.d.ts.map +0 -1
  470. package/dist/modes/interactive/theme/theme.js +0 -1015
  471. package/dist/modes/interactive/theme/theme.js.map +0 -1
  472. package/dist/modes/print-mode.d.ts +0 -28
  473. package/dist/modes/print-mode.d.ts.map +0 -1
  474. package/dist/modes/print-mode.js +0 -131
  475. package/dist/modes/print-mode.js.map +0 -1
  476. package/dist/modes/rpc/jsonl.d.ts +0 -17
  477. package/dist/modes/rpc/jsonl.d.ts.map +0 -1
  478. package/dist/modes/rpc/jsonl.js +0 -49
  479. package/dist/modes/rpc/jsonl.js.map +0 -1
  480. package/dist/modes/rpc/rpc-client.d.ts +0 -228
  481. package/dist/modes/rpc/rpc-client.d.ts.map +0 -1
  482. package/dist/modes/rpc/rpc-client.js +0 -416
  483. package/dist/modes/rpc/rpc-client.js.map +0 -1
  484. package/dist/modes/rpc/rpc-mode.d.ts +0 -20
  485. package/dist/modes/rpc/rpc-mode.d.ts.map +0 -1
  486. package/dist/modes/rpc/rpc-mode.js +0 -609
  487. package/dist/modes/rpc/rpc-mode.js.map +0 -1
  488. package/dist/modes/rpc/rpc-types.d.ts +0 -428
  489. package/dist/modes/rpc/rpc-types.d.ts.map +0 -1
  490. package/dist/modes/rpc/rpc-types.js +0 -8
  491. package/dist/modes/rpc/rpc-types.js.map +0 -1
  492. package/dist/modes/web/web-mode.d.ts +0 -3
  493. package/dist/modes/web/web-mode.d.ts.map +0 -1
  494. package/dist/modes/web/web-mode.js +0 -243
  495. package/dist/modes/web/web-mode.js.map +0 -1
  496. package/dist/package-manager-cli.d.ts +0 -4
  497. package/dist/package-manager-cli.d.ts.map +0 -1
  498. package/dist/package-manager-cli.js +0 -515
  499. package/dist/package-manager-cli.js.map +0 -1
  500. package/dist/utils/ansi.d.ts +0 -2
  501. package/dist/utils/ansi.d.ts.map +0 -1
  502. package/dist/utils/ansi.js +0 -52
  503. package/dist/utils/ansi.js.map +0 -1
  504. package/dist/utils/changelog.d.ts +0 -21
  505. package/dist/utils/changelog.d.ts.map +0 -1
  506. package/dist/utils/changelog.js +0 -87
  507. package/dist/utils/changelog.js.map +0 -1
  508. package/dist/utils/child-process.d.ts +0 -15
  509. package/dist/utils/child-process.d.ts.map +0 -1
  510. package/dist/utils/child-process.js +0 -88
  511. package/dist/utils/child-process.js.map +0 -1
  512. package/dist/utils/clipboard-image.d.ts +0 -11
  513. package/dist/utils/clipboard-image.d.ts.map +0 -1
  514. package/dist/utils/clipboard-image.js +0 -245
  515. package/dist/utils/clipboard-image.js.map +0 -1
  516. package/dist/utils/clipboard-native.d.ts +0 -8
  517. package/dist/utils/clipboard-native.d.ts.map +0 -1
  518. package/dist/utils/clipboard-native.js +0 -14
  519. package/dist/utils/clipboard-native.js.map +0 -1
  520. package/dist/utils/clipboard.d.ts +0 -2
  521. package/dist/utils/clipboard.d.ts.map +0 -1
  522. package/dist/utils/clipboard.js +0 -117
  523. package/dist/utils/clipboard.js.map +0 -1
  524. package/dist/utils/exif-orientation.d.ts +0 -5
  525. package/dist/utils/exif-orientation.d.ts.map +0 -1
  526. package/dist/utils/exif-orientation.js +0 -158
  527. package/dist/utils/exif-orientation.js.map +0 -1
  528. package/dist/utils/frontmatter.d.ts +0 -8
  529. package/dist/utils/frontmatter.d.ts.map +0 -1
  530. package/dist/utils/frontmatter.js +0 -26
  531. package/dist/utils/frontmatter.js.map +0 -1
  532. package/dist/utils/fs-watch.d.ts +0 -5
  533. package/dist/utils/fs-watch.d.ts.map +0 -1
  534. package/dist/utils/fs-watch.js +0 -25
  535. package/dist/utils/fs-watch.js.map +0 -1
  536. package/dist/utils/git.d.ts +0 -26
  537. package/dist/utils/git.d.ts.map +0 -1
  538. package/dist/utils/git.js +0 -163
  539. package/dist/utils/git.js.map +0 -1
  540. package/dist/utils/html.d.ts +0 -7
  541. package/dist/utils/html.d.ts.map +0 -1
  542. package/dist/utils/html.js +0 -40
  543. package/dist/utils/html.js.map +0 -1
  544. package/dist/utils/image-convert.d.ts +0 -9
  545. package/dist/utils/image-convert.d.ts.map +0 -1
  546. package/dist/utils/image-convert.js +0 -39
  547. package/dist/utils/image-convert.js.map +0 -1
  548. package/dist/utils/image-resize.d.ts +0 -36
  549. package/dist/utils/image-resize.d.ts.map +0 -1
  550. package/dist/utils/image-resize.js +0 -137
  551. package/dist/utils/image-resize.js.map +0 -1
  552. package/dist/utils/mime.d.ts +0 -3
  553. package/dist/utils/mime.d.ts.map +0 -1
  554. package/dist/utils/mime.js +0 -69
  555. package/dist/utils/mime.js.map +0 -1
  556. package/dist/utils/paths.d.ts +0 -17
  557. package/dist/utils/paths.d.ts.map +0 -1
  558. package/dist/utils/paths.js +0 -66
  559. package/dist/utils/paths.js.map +0 -1
  560. package/dist/utils/photon.d.ts +0 -21
  561. package/dist/utils/photon.d.ts.map +0 -1
  562. package/dist/utils/photon.js +0 -121
  563. package/dist/utils/photon.js.map +0 -1
  564. package/dist/utils/pi-user-agent.d.ts +0 -2
  565. package/dist/utils/pi-user-agent.d.ts.map +0 -1
  566. package/dist/utils/pi-user-agent.js +0 -5
  567. package/dist/utils/pi-user-agent.js.map +0 -1
  568. package/dist/utils/shell.d.ts +0 -30
  569. package/dist/utils/shell.d.ts.map +0 -1
  570. package/dist/utils/shell.js +0 -195
  571. package/dist/utils/shell.js.map +0 -1
  572. package/dist/utils/sleep.d.ts +0 -5
  573. package/dist/utils/sleep.d.ts.map +0 -1
  574. package/dist/utils/sleep.js +0 -17
  575. package/dist/utils/sleep.js.map +0 -1
  576. package/dist/utils/syntax-highlight.d.ts +0 -12
  577. package/dist/utils/syntax-highlight.d.ts.map +0 -1
  578. package/dist/utils/syntax-highlight.js +0 -118
  579. package/dist/utils/syntax-highlight.js.map +0 -1
  580. package/dist/utils/tools-manager.d.ts +0 -3
  581. package/dist/utils/tools-manager.d.ts.map +0 -1
  582. package/dist/utils/tools-manager.js +0 -328
  583. package/dist/utils/tools-manager.js.map +0 -1
  584. package/dist/utils/version-check.d.ts +0 -15
  585. package/dist/utils/version-check.d.ts.map +0 -1
  586. package/dist/utils/version-check.js +0 -82
  587. package/dist/utils/version-check.js.map +0 -1
  588. package/dist/utils/windows-self-update.d.ts +0 -3
  589. package/dist/utils/windows-self-update.d.ts.map +0 -1
  590. package/dist/utils/windows-self-update.js +0 -77
  591. package/dist/utils/windows-self-update.js.map +0 -1
@@ -1 +0,0 @@
1
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AC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC,OAAO,QAAQ,CAAC,CAE7F","sourcesContent":["import type { AgentTool } from \"@openeryc/pi-agent-core\";\nimport { Text } from \"@openeryc/pi-tui\";\nimport { existsSync, readdirSync, statSync } from \"fs\";\nimport nodePath from \"path\";\nimport { type Static, Type } from \"typebox\";\nimport { keyHint } from \"../../modes/interactive/components/keybinding-hints.ts\";\nimport type { ToolDefinition, ToolRenderResultOptions } from \"../extensions/types.ts\";\nimport { resolveToCwd } from \"./path-utils.ts\";\nimport { getTextOutput, invalidArgText, shortenPath, str } from \"./render-utils.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\nimport { DEFAULT_MAX_BYTES, formatSize, type TruncationResult, truncateHead } from \"./truncate.ts\";\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.ts\").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.ts\").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"]}
@@ -1,169 +0,0 @@
1
- import { Text } from "@openeryc/pi-tui";
2
- import { existsSync, readdirSync, statSync } from "fs";
3
- import nodePath from "path";
4
- import { Type } from "typebox";
5
- import { keyHint } from "../../modes/interactive/components/keybinding-hints.js";
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";
9
- import { DEFAULT_MAX_BYTES, formatSize, truncateHead } from "./truncate.js";
10
- const lsSchema = Type.Object({
11
- path: Type.Optional(Type.String({ description: "Directory to list (default: current directory)" })),
12
- limit: Type.Optional(Type.Number({ description: "Maximum number of entries to return (default: 500)" })),
13
- });
14
- const DEFAULT_LIMIT = 500;
15
- const defaultLsOperations = {
16
- exists: existsSync,
17
- stat: statSync,
18
- readdir: readdirSync,
19
- };
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) {
57
- const ops = options?.operations ?? defaultLsOperations;
58
- return {
59
- name: "ls",
60
- label: "ls",
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",
63
- parameters: lsSchema,
64
- async execute(_toolCallId, { path, limit }, signal, _onUpdate, _ctx) {
65
- return new Promise((resolve, reject) => {
66
- if (signal?.aborted) {
67
- reject(new Error("Operation aborted"));
68
- return;
69
- }
70
- const onAbort = () => reject(new Error("Operation aborted"));
71
- signal?.addEventListener("abort", onAbort, { once: true });
72
- (async () => {
73
- try {
74
- const dirPath = resolveToCwd(path || ".", cwd);
75
- const effectiveLimit = limit ?? DEFAULT_LIMIT;
76
- // Check if path exists.
77
- if (!(await ops.exists(dirPath))) {
78
- reject(new Error(`Path not found: ${dirPath}`));
79
- return;
80
- }
81
- // Check if path is a directory.
82
- const stat = await ops.stat(dirPath);
83
- if (!stat.isDirectory()) {
84
- reject(new Error(`Not a directory: ${dirPath}`));
85
- return;
86
- }
87
- // Read directory entries.
88
- let entries;
89
- try {
90
- entries = await ops.readdir(dirPath);
91
- }
92
- catch (e) {
93
- reject(new Error(`Cannot read directory: ${e.message}`));
94
- return;
95
- }
96
- // Sort alphabetically, case-insensitive.
97
- entries.sort((a, b) => a.toLowerCase().localeCompare(b.toLowerCase()));
98
- // Format entries with directory indicators.
99
- const results = [];
100
- let entryLimitReached = false;
101
- for (const entry of entries) {
102
- if (results.length >= effectiveLimit) {
103
- entryLimitReached = true;
104
- break;
105
- }
106
- const fullPath = nodePath.join(dirPath, entry);
107
- let suffix = "";
108
- try {
109
- const entryStat = await ops.stat(fullPath);
110
- if (entryStat.isDirectory())
111
- suffix = "/";
112
- }
113
- catch {
114
- // Skip entries we cannot stat.
115
- continue;
116
- }
117
- results.push(entry + suffix);
118
- }
119
- signal?.removeEventListener("abort", onAbort);
120
- if (results.length === 0) {
121
- resolve({ content: [{ type: "text", text: "(empty directory)" }], details: undefined });
122
- return;
123
- }
124
- const rawOutput = results.join("\n");
125
- // Apply byte truncation. There is no separate line limit because entry count is already capped.
126
- const truncation = truncateHead(rawOutput, { maxLines: Number.MAX_SAFE_INTEGER });
127
- let output = truncation.content;
128
- const details = {};
129
- // Build actionable notices for truncation and entry limits.
130
- const notices = [];
131
- if (entryLimitReached) {
132
- notices.push(`${effectiveLimit} entries limit reached. Use limit=${effectiveLimit * 2} for more`);
133
- details.entryLimitReached = effectiveLimit;
134
- }
135
- if (truncation.truncated) {
136
- notices.push(`${formatSize(DEFAULT_MAX_BYTES)} limit reached`);
137
- details.truncation = truncation;
138
- }
139
- if (notices.length > 0) {
140
- output += `\n\n[${notices.join(". ")}]`;
141
- }
142
- resolve({
143
- content: [{ type: "text", text: output }],
144
- details: Object.keys(details).length > 0 ? details : undefined,
145
- });
146
- }
147
- catch (e) {
148
- signal?.removeEventListener("abort", onAbort);
149
- reject(e);
150
- }
151
- })();
152
- });
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
- },
164
- };
165
- }
166
- export function createLsTool(cwd, options) {
167
- return wrapToolDefinition(createLsToolDefinition(cwd, options));
168
- }
169
- //# sourceMappingURL=ls.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ls.js","sourceRoot":"","sources":["../../../src/core/tools/ls.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,M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E,KAAK,EAAE,OAAO,EAAE;YAChC,MAAM,IAAI,GAAI,OAAO,CAAC,aAAkC,IAAI,IAAI,IAAI,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;YAC/E,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;YACxC,OAAO,IAAI,CAAC;QAAA,CACZ;QACD,YAAY,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE;YAC7C,MAAM,IAAI,GAAI,OAAO,CAAC,aAAkC,IAAI,IAAI,IAAI,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;YAC/E,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,MAAa,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC;YAChF,OAAO,IAAI,CAAC;QAAA,CACZ;KACD,CAAC;AAAA,CACF;AAED,MAAM,UAAU,YAAY,CAAC,GAAW,EAAE,OAAuB,EAA8B;IAC9F,OAAO,kBAAkB,CAAC,sBAAsB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;AAAA,CAChE","sourcesContent":["import type { AgentTool } from \"@openeryc/pi-agent-core\";\nimport { Text } from \"@openeryc/pi-tui\";\nimport { existsSync, readdirSync, statSync } from \"fs\";\nimport nodePath from \"path\";\nimport { type Static, Type } from \"typebox\";\nimport { keyHint } from \"../../modes/interactive/components/keybinding-hints.ts\";\nimport type { ToolDefinition, ToolRenderResultOptions } from \"../extensions/types.ts\";\nimport { resolveToCwd } from \"./path-utils.ts\";\nimport { getTextOutput, invalidArgText, shortenPath, str } from \"./render-utils.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\nimport { DEFAULT_MAX_BYTES, formatSize, type TruncationResult, truncateHead } from \"./truncate.ts\";\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.ts\").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.ts\").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"]}
@@ -1,50 +0,0 @@
1
- import { type TruncationResult } from "./truncate.ts";
2
- export interface OutputAccumulatorOptions {
3
- maxLines?: number;
4
- maxBytes?: number;
5
- tempFilePrefix?: string;
6
- }
7
- export interface OutputSnapshot {
8
- content: string;
9
- truncation: TruncationResult;
10
- fullOutputPath?: string;
11
- }
12
- /**
13
- * Incrementally tracks streaming output with bounded memory.
14
- *
15
- * Appends decode chunks with a streaming UTF-8 decoder, keeps only a decoded
16
- * tail for display snapshots, and opens a temp file when the full output needs
17
- * to be preserved.
18
- */
19
- export declare class OutputAccumulator {
20
- private readonly maxLines;
21
- private readonly maxBytes;
22
- private readonly maxRollingBytes;
23
- private readonly tempFilePrefix;
24
- private readonly decoder;
25
- private rawChunks;
26
- private tailText;
27
- private tailBytes;
28
- private tailStartsAtLineBoundary;
29
- private totalRawBytes;
30
- private totalDecodedBytes;
31
- private totalLines;
32
- private currentLineBytes;
33
- private finished;
34
- private tempFilePath;
35
- private tempFileStream;
36
- constructor(options?: OutputAccumulatorOptions);
37
- append(data: Buffer): void;
38
- finish(): void;
39
- snapshot(options?: {
40
- persistIfTruncated?: boolean;
41
- }): OutputSnapshot;
42
- closeTempFile(): Promise<void>;
43
- getLastLineBytes(): number;
44
- private appendDecodedText;
45
- private trimTail;
46
- private getSnapshotText;
47
- private shouldUseTempFile;
48
- private ensureTempFile;
49
- }
50
- //# sourceMappingURL=output-accumulator.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"output-accumulator.d.ts","sourceRoot":"","sources":["../../../src/core/tools/output-accumulator.ts"],"names":[],"mappings":"AAIA,OAAO,EAAwC,KAAK,gBAAgB,EAAgB,MAAM,eAAe,CAAC;AAE1G,MAAM,WAAW,wBAAwB;IACxC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,cAAc;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,gBAAgB,CAAC;IAC7B,cAAc,CAAC,EAAE,MAAM,CAAC;CACxB;AAWD;;;;;;GAMG;AACH,qBAAa,iBAAiB;IAC7B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;IACzC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;IACxC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAqB;IAE7C,OAAO,CAAC,SAAS,CAAgB;IACjC,OAAO,CAAC,QAAQ,CAAM;IACtB,OAAO,CAAC,SAAS,CAAK;IACtB,OAAO,CAAC,wBAAwB,CAAQ;IACxC,OAAO,CAAC,aAAa,CAAK;IAC1B,OAAO,CAAC,iBAAiB,CAAK;IAC9B,OAAO,CAAC,UAAU,CAAK;IACvB,OAAO,CAAC,gBAAgB,CAAK;IAC7B,OAAO,CAAC,QAAQ,CAAS;IAEzB,OAAO,CAAC,YAAY,CAAqB;IACzC,OAAO,CAAC,cAAc,CAA0B;IAEhD,YAAY,OAAO,GAAE,wBAA6B,EAKjD;IAED,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAczB;IAED,MAAM,IAAI,IAAI,CASb;IAED,QAAQ,CAAC,OAAO,GAAE;QAAE,kBAAkB,CAAC,EAAE,OAAO,CAAA;KAAO,GAAG,cAAc,CA4BvE;IAEK,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC,CAqBnC;IAED,gBAAgB,IAAI,MAAM,CAEzB;IAED,OAAO,CAAC,iBAAiB;IA2BzB,OAAO,CAAC,QAAQ;IAiBhB,OAAO,CAAC,eAAe;IASvB,OAAO,CAAC,iBAAiB;IAMzB,OAAO,CAAC,cAAc;CAWtB","sourcesContent":["import { randomBytes } from \"node:crypto\";\nimport { createWriteStream, type WriteStream } from \"node:fs\";\nimport { tmpdir } from \"node:os\";\nimport { join } from \"node:path\";\nimport { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, type TruncationResult, truncateTail } from \"./truncate.ts\";\n\nexport interface OutputAccumulatorOptions {\n\tmaxLines?: number;\n\tmaxBytes?: number;\n\ttempFilePrefix?: string;\n}\n\nexport interface OutputSnapshot {\n\tcontent: string;\n\ttruncation: TruncationResult;\n\tfullOutputPath?: string;\n}\n\nfunction defaultTempFilePath(prefix: string): string {\n\tconst id = randomBytes(8).toString(\"hex\");\n\treturn join(tmpdir(), `${prefix}-${id}.log`);\n}\n\nfunction byteLength(text: string): number {\n\treturn Buffer.byteLength(text, \"utf-8\");\n}\n\n/**\n * Incrementally tracks streaming output with bounded memory.\n *\n * Appends decode chunks with a streaming UTF-8 decoder, keeps only a decoded\n * tail for display snapshots, and opens a temp file when the full output needs\n * to be preserved.\n */\nexport class OutputAccumulator {\n\tprivate readonly maxLines: number;\n\tprivate readonly maxBytes: number;\n\tprivate readonly maxRollingBytes: number;\n\tprivate readonly tempFilePrefix: string;\n\tprivate readonly decoder = new TextDecoder();\n\n\tprivate rawChunks: Buffer[] = [];\n\tprivate tailText = \"\";\n\tprivate tailBytes = 0;\n\tprivate tailStartsAtLineBoundary = true;\n\tprivate totalRawBytes = 0;\n\tprivate totalDecodedBytes = 0;\n\tprivate totalLines = 1;\n\tprivate currentLineBytes = 0;\n\tprivate finished = false;\n\n\tprivate tempFilePath: string | undefined;\n\tprivate tempFileStream: WriteStream | undefined;\n\n\tconstructor(options: OutputAccumulatorOptions = {}) {\n\t\tthis.maxLines = options.maxLines ?? DEFAULT_MAX_LINES;\n\t\tthis.maxBytes = options.maxBytes ?? DEFAULT_MAX_BYTES;\n\t\tthis.maxRollingBytes = Math.max(this.maxBytes * 2, 1);\n\t\tthis.tempFilePrefix = options.tempFilePrefix ?? \"pi-output\";\n\t}\n\n\tappend(data: Buffer): void {\n\t\tif (this.finished) {\n\t\t\tthrow new Error(\"Cannot append to a finished output accumulator\");\n\t\t}\n\n\t\tthis.totalRawBytes += data.length;\n\t\tthis.appendDecodedText(this.decoder.decode(data, { stream: true }));\n\n\t\tif (this.tempFileStream || this.shouldUseTempFile()) {\n\t\t\tthis.ensureTempFile();\n\t\t\tthis.tempFileStream?.write(data);\n\t\t} else if (data.length > 0) {\n\t\t\tthis.rawChunks.push(data);\n\t\t}\n\t}\n\n\tfinish(): void {\n\t\tif (this.finished) {\n\t\t\treturn;\n\t\t}\n\t\tthis.finished = true;\n\t\tthis.appendDecodedText(this.decoder.decode());\n\t\tif (this.shouldUseTempFile()) {\n\t\t\tthis.ensureTempFile();\n\t\t}\n\t}\n\n\tsnapshot(options: { persistIfTruncated?: boolean } = {}): OutputSnapshot {\n\t\tconst tailTruncation = truncateTail(this.getSnapshotText(), {\n\t\t\tmaxLines: this.maxLines,\n\t\t\tmaxBytes: this.maxBytes,\n\t\t});\n\t\tconst truncated = this.totalLines > this.maxLines || this.totalDecodedBytes > this.maxBytes;\n\t\tconst truncatedBy = truncated\n\t\t\t? (tailTruncation.truncatedBy ?? (this.totalDecodedBytes > this.maxBytes ? \"bytes\" : \"lines\"))\n\t\t\t: null;\n\t\tconst truncation: TruncationResult = {\n\t\t\t...tailTruncation,\n\t\t\ttruncated,\n\t\t\ttruncatedBy,\n\t\t\ttotalLines: this.totalLines,\n\t\t\ttotalBytes: this.totalDecodedBytes,\n\t\t\tmaxLines: this.maxLines,\n\t\t\tmaxBytes: this.maxBytes,\n\t\t};\n\n\t\tif (options.persistIfTruncated && truncation.truncated) {\n\t\t\tthis.ensureTempFile();\n\t\t}\n\n\t\treturn {\n\t\t\tcontent: truncation.content,\n\t\t\ttruncation,\n\t\t\tfullOutputPath: this.tempFilePath,\n\t\t};\n\t}\n\n\tasync closeTempFile(): Promise<void> {\n\t\tif (!this.tempFileStream) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst stream = this.tempFileStream;\n\t\tthis.tempFileStream = undefined;\n\n\t\tawait new Promise<void>((resolve, reject) => {\n\t\t\tconst onError = (error: Error) => {\n\t\t\t\tstream.off(\"finish\", onFinish);\n\t\t\t\treject(error);\n\t\t\t};\n\t\t\tconst onFinish = () => {\n\t\t\t\tstream.off(\"error\", onError);\n\t\t\t\tresolve();\n\t\t\t};\n\t\t\tstream.once(\"error\", onError);\n\t\t\tstream.once(\"finish\", onFinish);\n\t\t\tstream.end();\n\t\t});\n\t}\n\n\tgetLastLineBytes(): number {\n\t\treturn this.currentLineBytes;\n\t}\n\n\tprivate appendDecodedText(text: string): void {\n\t\tif (text.length === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst bytes = byteLength(text);\n\t\tthis.totalDecodedBytes += bytes;\n\t\tthis.tailText += text;\n\t\tthis.tailBytes += bytes;\n\t\tif (this.tailBytes > this.maxRollingBytes * 2) {\n\t\t\tthis.trimTail();\n\t\t}\n\n\t\tlet newlines = 0;\n\t\tlet lastNewline = -1;\n\t\tfor (let i = text.indexOf(\"\\n\"); i !== -1; i = text.indexOf(\"\\n\", i + 1)) {\n\t\t\tnewlines++;\n\t\t\tlastNewline = i;\n\t\t}\n\t\tif (newlines === 0) {\n\t\t\tthis.currentLineBytes += bytes;\n\t\t} else {\n\t\t\tthis.totalLines += newlines;\n\t\t\tthis.currentLineBytes = byteLength(text.slice(lastNewline + 1));\n\t\t}\n\t}\n\n\tprivate trimTail(): void {\n\t\tconst buffer = Buffer.from(this.tailText, \"utf-8\");\n\t\tif (buffer.length <= this.maxRollingBytes) {\n\t\t\tthis.tailBytes = buffer.length;\n\t\t\treturn;\n\t\t}\n\n\t\tlet start = buffer.length - this.maxRollingBytes;\n\t\twhile (start < buffer.length && (buffer[start] & 0xc0) === 0x80) {\n\t\t\tstart++;\n\t\t}\n\n\t\tthis.tailStartsAtLineBoundary = start === 0 ? this.tailStartsAtLineBoundary : buffer[start - 1] === 0x0a;\n\t\tthis.tailText = buffer.subarray(start).toString(\"utf-8\");\n\t\tthis.tailBytes = byteLength(this.tailText);\n\t}\n\n\tprivate getSnapshotText(): string {\n\t\tif (this.tailStartsAtLineBoundary) {\n\t\t\treturn this.tailText;\n\t\t}\n\n\t\tconst firstNewline = this.tailText.indexOf(\"\\n\");\n\t\treturn firstNewline === -1 ? this.tailText : this.tailText.slice(firstNewline + 1);\n\t}\n\n\tprivate shouldUseTempFile(): boolean {\n\t\treturn (\n\t\t\tthis.totalRawBytes > this.maxBytes || this.totalDecodedBytes > this.maxBytes || this.totalLines > this.maxLines\n\t\t);\n\t}\n\n\tprivate ensureTempFile(): void {\n\t\tif (this.tempFilePath) {\n\t\t\treturn;\n\t\t}\n\t\tthis.tempFilePath = defaultTempFilePath(this.tempFilePrefix);\n\t\tthis.tempFileStream = createWriteStream(this.tempFilePath);\n\t\tfor (const chunk of this.rawChunks) {\n\t\t\tthis.tempFileStream.write(chunk);\n\t\t}\n\t\tthis.rawChunks = [];\n\t}\n}\n"]}
@@ -1,178 +0,0 @@
1
- import { randomBytes } from "node:crypto";
2
- import { createWriteStream } from "node:fs";
3
- import { tmpdir } from "node:os";
4
- import { join } from "node:path";
5
- import { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, truncateTail } from "./truncate.js";
6
- function defaultTempFilePath(prefix) {
7
- const id = randomBytes(8).toString("hex");
8
- return join(tmpdir(), `${prefix}-${id}.log`);
9
- }
10
- function byteLength(text) {
11
- return Buffer.byteLength(text, "utf-8");
12
- }
13
- /**
14
- * Incrementally tracks streaming output with bounded memory.
15
- *
16
- * Appends decode chunks with a streaming UTF-8 decoder, keeps only a decoded
17
- * tail for display snapshots, and opens a temp file when the full output needs
18
- * to be preserved.
19
- */
20
- export class OutputAccumulator {
21
- maxLines;
22
- maxBytes;
23
- maxRollingBytes;
24
- tempFilePrefix;
25
- decoder = new TextDecoder();
26
- rawChunks = [];
27
- tailText = "";
28
- tailBytes = 0;
29
- tailStartsAtLineBoundary = true;
30
- totalRawBytes = 0;
31
- totalDecodedBytes = 0;
32
- totalLines = 1;
33
- currentLineBytes = 0;
34
- finished = false;
35
- tempFilePath;
36
- tempFileStream;
37
- constructor(options = {}) {
38
- this.maxLines = options.maxLines ?? DEFAULT_MAX_LINES;
39
- this.maxBytes = options.maxBytes ?? DEFAULT_MAX_BYTES;
40
- this.maxRollingBytes = Math.max(this.maxBytes * 2, 1);
41
- this.tempFilePrefix = options.tempFilePrefix ?? "pi-output";
42
- }
43
- append(data) {
44
- if (this.finished) {
45
- throw new Error("Cannot append to a finished output accumulator");
46
- }
47
- this.totalRawBytes += data.length;
48
- this.appendDecodedText(this.decoder.decode(data, { stream: true }));
49
- if (this.tempFileStream || this.shouldUseTempFile()) {
50
- this.ensureTempFile();
51
- this.tempFileStream?.write(data);
52
- }
53
- else if (data.length > 0) {
54
- this.rawChunks.push(data);
55
- }
56
- }
57
- finish() {
58
- if (this.finished) {
59
- return;
60
- }
61
- this.finished = true;
62
- this.appendDecodedText(this.decoder.decode());
63
- if (this.shouldUseTempFile()) {
64
- this.ensureTempFile();
65
- }
66
- }
67
- snapshot(options = {}) {
68
- const tailTruncation = truncateTail(this.getSnapshotText(), {
69
- maxLines: this.maxLines,
70
- maxBytes: this.maxBytes,
71
- });
72
- const truncated = this.totalLines > this.maxLines || this.totalDecodedBytes > this.maxBytes;
73
- const truncatedBy = truncated
74
- ? (tailTruncation.truncatedBy ?? (this.totalDecodedBytes > this.maxBytes ? "bytes" : "lines"))
75
- : null;
76
- const truncation = {
77
- ...tailTruncation,
78
- truncated,
79
- truncatedBy,
80
- totalLines: this.totalLines,
81
- totalBytes: this.totalDecodedBytes,
82
- maxLines: this.maxLines,
83
- maxBytes: this.maxBytes,
84
- };
85
- if (options.persistIfTruncated && truncation.truncated) {
86
- this.ensureTempFile();
87
- }
88
- return {
89
- content: truncation.content,
90
- truncation,
91
- fullOutputPath: this.tempFilePath,
92
- };
93
- }
94
- async closeTempFile() {
95
- if (!this.tempFileStream) {
96
- return;
97
- }
98
- const stream = this.tempFileStream;
99
- this.tempFileStream = undefined;
100
- await new Promise((resolve, reject) => {
101
- const onError = (error) => {
102
- stream.off("finish", onFinish);
103
- reject(error);
104
- };
105
- const onFinish = () => {
106
- stream.off("error", onError);
107
- resolve();
108
- };
109
- stream.once("error", onError);
110
- stream.once("finish", onFinish);
111
- stream.end();
112
- });
113
- }
114
- getLastLineBytes() {
115
- return this.currentLineBytes;
116
- }
117
- appendDecodedText(text) {
118
- if (text.length === 0) {
119
- return;
120
- }
121
- const bytes = byteLength(text);
122
- this.totalDecodedBytes += bytes;
123
- this.tailText += text;
124
- this.tailBytes += bytes;
125
- if (this.tailBytes > this.maxRollingBytes * 2) {
126
- this.trimTail();
127
- }
128
- let newlines = 0;
129
- let lastNewline = -1;
130
- for (let i = text.indexOf("\n"); i !== -1; i = text.indexOf("\n", i + 1)) {
131
- newlines++;
132
- lastNewline = i;
133
- }
134
- if (newlines === 0) {
135
- this.currentLineBytes += bytes;
136
- }
137
- else {
138
- this.totalLines += newlines;
139
- this.currentLineBytes = byteLength(text.slice(lastNewline + 1));
140
- }
141
- }
142
- trimTail() {
143
- const buffer = Buffer.from(this.tailText, "utf-8");
144
- if (buffer.length <= this.maxRollingBytes) {
145
- this.tailBytes = buffer.length;
146
- return;
147
- }
148
- let start = buffer.length - this.maxRollingBytes;
149
- while (start < buffer.length && (buffer[start] & 0xc0) === 0x80) {
150
- start++;
151
- }
152
- this.tailStartsAtLineBoundary = start === 0 ? this.tailStartsAtLineBoundary : buffer[start - 1] === 0x0a;
153
- this.tailText = buffer.subarray(start).toString("utf-8");
154
- this.tailBytes = byteLength(this.tailText);
155
- }
156
- getSnapshotText() {
157
- if (this.tailStartsAtLineBoundary) {
158
- return this.tailText;
159
- }
160
- const firstNewline = this.tailText.indexOf("\n");
161
- return firstNewline === -1 ? this.tailText : this.tailText.slice(firstNewline + 1);
162
- }
163
- shouldUseTempFile() {
164
- return (this.totalRawBytes > this.maxBytes || this.totalDecodedBytes > this.maxBytes || this.totalLines > this.maxLines);
165
- }
166
- ensureTempFile() {
167
- if (this.tempFilePath) {
168
- return;
169
- }
170
- this.tempFilePath = defaultTempFilePath(this.tempFilePrefix);
171
- this.tempFileStream = createWriteStream(this.tempFilePath);
172
- for (const chunk of this.rawChunks) {
173
- this.tempFileStream.write(chunk);
174
- }
175
- this.rawChunks = [];
176
- }
177
- }
178
- //# sourceMappingURL=output-accumulator.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"output-accumulator.js","sourceRoot":"","sources":["../../../src/core/tools/output-accumulator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAoB,MAAM,SAAS,CAAC;AAC9D,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAyB,YAAY,EAAE,MAAM,eAAe,CAAC;AAc1G,SAAS,mBAAmB,CAAC,MAAc,EAAU;IACpD,MAAM,EAAE,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC1C,OAAO,IAAI,CAAC,MAAM,EAAE,EAAE,GAA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I,CAAC,iBAAiB,GAAG,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,QAAQ,CAC/G,CAAC;IAAA,CACF;IAEO,cAAc,GAAS;QAC9B,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;YACvB,OAAO;QACR,CAAC;QACD,IAAI,CAAC,YAAY,GAAG,mBAAmB,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QAC7D,IAAI,CAAC,cAAc,GAAG,iBAAiB,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAC3D,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACpC,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAClC,CAAC;QACD,IAAI,CAAC,SAAS,GAAG,EAAE,CAAC;IAAA,CACpB;CACD","sourcesContent":["import { randomBytes } from \"node:crypto\";\nimport { createWriteStream, type WriteStream } from \"node:fs\";\nimport { tmpdir } from \"node:os\";\nimport { join } from \"node:path\";\nimport { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, type TruncationResult, truncateTail } from \"./truncate.ts\";\n\nexport interface OutputAccumulatorOptions {\n\tmaxLines?: number;\n\tmaxBytes?: number;\n\ttempFilePrefix?: string;\n}\n\nexport interface OutputSnapshot {\n\tcontent: string;\n\ttruncation: TruncationResult;\n\tfullOutputPath?: string;\n}\n\nfunction defaultTempFilePath(prefix: string): string {\n\tconst id = randomBytes(8).toString(\"hex\");\n\treturn join(tmpdir(), `${prefix}-${id}.log`);\n}\n\nfunction byteLength(text: string): number {\n\treturn Buffer.byteLength(text, \"utf-8\");\n}\n\n/**\n * Incrementally tracks streaming output with bounded memory.\n *\n * Appends decode chunks with a streaming UTF-8 decoder, keeps only a decoded\n * tail for display snapshots, and opens a temp file when the full output needs\n * to be preserved.\n */\nexport class OutputAccumulator {\n\tprivate readonly maxLines: number;\n\tprivate readonly maxBytes: number;\n\tprivate readonly maxRollingBytes: number;\n\tprivate readonly tempFilePrefix: string;\n\tprivate readonly decoder = new TextDecoder();\n\n\tprivate rawChunks: Buffer[] = [];\n\tprivate tailText = \"\";\n\tprivate tailBytes = 0;\n\tprivate tailStartsAtLineBoundary = true;\n\tprivate totalRawBytes = 0;\n\tprivate totalDecodedBytes = 0;\n\tprivate totalLines = 1;\n\tprivate currentLineBytes = 0;\n\tprivate finished = false;\n\n\tprivate tempFilePath: string | undefined;\n\tprivate tempFileStream: WriteStream | undefined;\n\n\tconstructor(options: OutputAccumulatorOptions = {}) {\n\t\tthis.maxLines = options.maxLines ?? DEFAULT_MAX_LINES;\n\t\tthis.maxBytes = options.maxBytes ?? DEFAULT_MAX_BYTES;\n\t\tthis.maxRollingBytes = Math.max(this.maxBytes * 2, 1);\n\t\tthis.tempFilePrefix = options.tempFilePrefix ?? \"pi-output\";\n\t}\n\n\tappend(data: Buffer): void {\n\t\tif (this.finished) {\n\t\t\tthrow new Error(\"Cannot append to a finished output accumulator\");\n\t\t}\n\n\t\tthis.totalRawBytes += data.length;\n\t\tthis.appendDecodedText(this.decoder.decode(data, { stream: true }));\n\n\t\tif (this.tempFileStream || this.shouldUseTempFile()) {\n\t\t\tthis.ensureTempFile();\n\t\t\tthis.tempFileStream?.write(data);\n\t\t} else if (data.length > 0) {\n\t\t\tthis.rawChunks.push(data);\n\t\t}\n\t}\n\n\tfinish(): void {\n\t\tif (this.finished) {\n\t\t\treturn;\n\t\t}\n\t\tthis.finished = true;\n\t\tthis.appendDecodedText(this.decoder.decode());\n\t\tif (this.shouldUseTempFile()) {\n\t\t\tthis.ensureTempFile();\n\t\t}\n\t}\n\n\tsnapshot(options: { persistIfTruncated?: boolean } = {}): OutputSnapshot {\n\t\tconst tailTruncation = truncateTail(this.getSnapshotText(), {\n\t\t\tmaxLines: this.maxLines,\n\t\t\tmaxBytes: this.maxBytes,\n\t\t});\n\t\tconst truncated = this.totalLines > this.maxLines || this.totalDecodedBytes > this.maxBytes;\n\t\tconst truncatedBy = truncated\n\t\t\t? (tailTruncation.truncatedBy ?? (this.totalDecodedBytes > this.maxBytes ? \"bytes\" : \"lines\"))\n\t\t\t: null;\n\t\tconst truncation: TruncationResult = {\n\t\t\t...tailTruncation,\n\t\t\ttruncated,\n\t\t\ttruncatedBy,\n\t\t\ttotalLines: this.totalLines,\n\t\t\ttotalBytes: this.totalDecodedBytes,\n\t\t\tmaxLines: this.maxLines,\n\t\t\tmaxBytes: this.maxBytes,\n\t\t};\n\n\t\tif (options.persistIfTruncated && truncation.truncated) {\n\t\t\tthis.ensureTempFile();\n\t\t}\n\n\t\treturn {\n\t\t\tcontent: truncation.content,\n\t\t\ttruncation,\n\t\t\tfullOutputPath: this.tempFilePath,\n\t\t};\n\t}\n\n\tasync closeTempFile(): Promise<void> {\n\t\tif (!this.tempFileStream) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst stream = this.tempFileStream;\n\t\tthis.tempFileStream = undefined;\n\n\t\tawait new Promise<void>((resolve, reject) => {\n\t\t\tconst onError = (error: Error) => {\n\t\t\t\tstream.off(\"finish\", onFinish);\n\t\t\t\treject(error);\n\t\t\t};\n\t\t\tconst onFinish = () => {\n\t\t\t\tstream.off(\"error\", onError);\n\t\t\t\tresolve();\n\t\t\t};\n\t\t\tstream.once(\"error\", onError);\n\t\t\tstream.once(\"finish\", onFinish);\n\t\t\tstream.end();\n\t\t});\n\t}\n\n\tgetLastLineBytes(): number {\n\t\treturn this.currentLineBytes;\n\t}\n\n\tprivate appendDecodedText(text: string): void {\n\t\tif (text.length === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst bytes = byteLength(text);\n\t\tthis.totalDecodedBytes += bytes;\n\t\tthis.tailText += text;\n\t\tthis.tailBytes += bytes;\n\t\tif (this.tailBytes > this.maxRollingBytes * 2) {\n\t\t\tthis.trimTail();\n\t\t}\n\n\t\tlet newlines = 0;\n\t\tlet lastNewline = -1;\n\t\tfor (let i = text.indexOf(\"\\n\"); i !== -1; i = text.indexOf(\"\\n\", i + 1)) {\n\t\t\tnewlines++;\n\t\t\tlastNewline = i;\n\t\t}\n\t\tif (newlines === 0) {\n\t\t\tthis.currentLineBytes += bytes;\n\t\t} else {\n\t\t\tthis.totalLines += newlines;\n\t\t\tthis.currentLineBytes = byteLength(text.slice(lastNewline + 1));\n\t\t}\n\t}\n\n\tprivate trimTail(): void {\n\t\tconst buffer = Buffer.from(this.tailText, \"utf-8\");\n\t\tif (buffer.length <= this.maxRollingBytes) {\n\t\t\tthis.tailBytes = buffer.length;\n\t\t\treturn;\n\t\t}\n\n\t\tlet start = buffer.length - this.maxRollingBytes;\n\t\twhile (start < buffer.length && (buffer[start] & 0xc0) === 0x80) {\n\t\t\tstart++;\n\t\t}\n\n\t\tthis.tailStartsAtLineBoundary = start === 0 ? this.tailStartsAtLineBoundary : buffer[start - 1] === 0x0a;\n\t\tthis.tailText = buffer.subarray(start).toString(\"utf-8\");\n\t\tthis.tailBytes = byteLength(this.tailText);\n\t}\n\n\tprivate getSnapshotText(): string {\n\t\tif (this.tailStartsAtLineBoundary) {\n\t\t\treturn this.tailText;\n\t\t}\n\n\t\tconst firstNewline = this.tailText.indexOf(\"\\n\");\n\t\treturn firstNewline === -1 ? this.tailText : this.tailText.slice(firstNewline + 1);\n\t}\n\n\tprivate shouldUseTempFile(): boolean {\n\t\treturn (\n\t\t\tthis.totalRawBytes > this.maxBytes || this.totalDecodedBytes > this.maxBytes || this.totalLines > this.maxLines\n\t\t);\n\t}\n\n\tprivate ensureTempFile(): void {\n\t\tif (this.tempFilePath) {\n\t\t\treturn;\n\t\t}\n\t\tthis.tempFilePath = defaultTempFilePath(this.tempFilePrefix);\n\t\tthis.tempFileStream = createWriteStream(this.tempFilePath);\n\t\tfor (const chunk of this.rawChunks) {\n\t\t\tthis.tempFileStream.write(chunk);\n\t\t}\n\t\tthis.rawChunks = [];\n\t}\n}\n"]}
@@ -1,8 +0,0 @@
1
- export declare function expandPath(filePath: string): string;
2
- /**
3
- * Resolve a path relative to the given cwd.
4
- * Handles ~ expansion and absolute paths.
5
- */
6
- export declare function resolveToCwd(filePath: string, cwd: string): string;
7
- export declare function resolveReadPath(filePath: string, cwd: string): string;
8
- //# sourceMappingURL=path-utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"path-utils.d.ts","sourceRoot":"","sources":["../../../src/core/tools/path-utils.ts"],"names":[],"mappings":"AAsCA,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CASnD;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAMlE;AAED,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAgCrE","sourcesContent":["import { accessSync, constants } from \"node:fs\";\nimport * as os from \"node:os\";\nimport { isAbsolute, resolve as resolvePath } from \"node:path\";\n\nconst UNICODE_SPACES = /[\\u00A0\\u2000-\\u200A\\u202F\\u205F\\u3000]/g;\nconst NARROW_NO_BREAK_SPACE = \"\\u202F\";\nfunction normalizeUnicodeSpaces(str: string): string {\n\treturn str.replace(UNICODE_SPACES, \" \");\n}\n\nfunction tryMacOSScreenshotPath(filePath: string): string {\n\treturn filePath.replace(/ (AM|PM)\\./gi, `${NARROW_NO_BREAK_SPACE}$1.`);\n}\n\nfunction tryNFDVariant(filePath: string): string {\n\t// macOS stores filenames in NFD (decomposed) form, try converting user input to NFD\n\treturn filePath.normalize(\"NFD\");\n}\n\nfunction tryCurlyQuoteVariant(filePath: string): string {\n\t// macOS uses U+2019 (right single quotation mark) in screenshot names like \"Capture d'écran\"\n\t// Users typically type U+0027 (straight apostrophe)\n\treturn filePath.replace(/'/g, \"\\u2019\");\n}\n\nfunction fileExists(filePath: string): boolean {\n\ttry {\n\t\taccessSync(filePath, constants.F_OK);\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nfunction normalizeAtPrefix(filePath: string): string {\n\treturn filePath.startsWith(\"@\") ? filePath.slice(1) : filePath;\n}\n\nexport function expandPath(filePath: string): string {\n\tconst normalized = normalizeUnicodeSpaces(normalizeAtPrefix(filePath));\n\tif (normalized === \"~\") {\n\t\treturn os.homedir();\n\t}\n\tif (normalized.startsWith(\"~/\")) {\n\t\treturn os.homedir() + normalized.slice(1);\n\t}\n\treturn normalized;\n}\n\n/**\n * Resolve a path relative to the given cwd.\n * Handles ~ expansion and absolute paths.\n */\nexport function resolveToCwd(filePath: string, cwd: string): string {\n\tconst expanded = expandPath(filePath);\n\tif (isAbsolute(expanded)) {\n\t\treturn expanded;\n\t}\n\treturn resolvePath(cwd, expanded);\n}\n\nexport function resolveReadPath(filePath: string, cwd: string): string {\n\tconst resolved = resolveToCwd(filePath, cwd);\n\n\tif (fileExists(resolved)) {\n\t\treturn resolved;\n\t}\n\n\t// Try macOS AM/PM variant (narrow no-break space before AM/PM)\n\tconst amPmVariant = tryMacOSScreenshotPath(resolved);\n\tif (amPmVariant !== resolved && fileExists(amPmVariant)) {\n\t\treturn amPmVariant;\n\t}\n\n\t// Try NFD variant (macOS stores filenames in NFD form)\n\tconst nfdVariant = tryNFDVariant(resolved);\n\tif (nfdVariant !== resolved && fileExists(nfdVariant)) {\n\t\treturn nfdVariant;\n\t}\n\n\t// Try curly quote variant (macOS uses U+2019 in screenshot names)\n\tconst curlyVariant = tryCurlyQuoteVariant(resolved);\n\tif (curlyVariant !== resolved && fileExists(curlyVariant)) {\n\t\treturn curlyVariant;\n\t}\n\n\t// Try combined NFD + curly quote (for French macOS screenshots like \"Capture d'écran\")\n\tconst nfdCurlyVariant = tryCurlyQuoteVariant(nfdVariant);\n\tif (nfdCurlyVariant !== resolved && fileExists(nfdCurlyVariant)) {\n\t\treturn nfdCurlyVariant;\n\t}\n\n\treturn resolved;\n}\n"]}
@@ -1,81 +0,0 @@
1
- import { accessSync, constants } from "node:fs";
2
- import * as os from "node:os";
3
- import { isAbsolute, resolve as resolvePath } from "node:path";
4
- const UNICODE_SPACES = /[\u00A0\u2000-\u200A\u202F\u205F\u3000]/g;
5
- const NARROW_NO_BREAK_SPACE = "\u202F";
6
- function normalizeUnicodeSpaces(str) {
7
- return str.replace(UNICODE_SPACES, " ");
8
- }
9
- function tryMacOSScreenshotPath(filePath) {
10
- return filePath.replace(/ (AM|PM)\./gi, `${NARROW_NO_BREAK_SPACE}$1.`);
11
- }
12
- function tryNFDVariant(filePath) {
13
- // macOS stores filenames in NFD (decomposed) form, try converting user input to NFD
14
- return filePath.normalize("NFD");
15
- }
16
- function tryCurlyQuoteVariant(filePath) {
17
- // macOS uses U+2019 (right single quotation mark) in screenshot names like "Capture d'écran"
18
- // Users typically type U+0027 (straight apostrophe)
19
- return filePath.replace(/'/g, "\u2019");
20
- }
21
- function fileExists(filePath) {
22
- try {
23
- accessSync(filePath, constants.F_OK);
24
- return true;
25
- }
26
- catch {
27
- return false;
28
- }
29
- }
30
- function normalizeAtPrefix(filePath) {
31
- return filePath.startsWith("@") ? filePath.slice(1) : filePath;
32
- }
33
- export function expandPath(filePath) {
34
- const normalized = normalizeUnicodeSpaces(normalizeAtPrefix(filePath));
35
- if (normalized === "~") {
36
- return os.homedir();
37
- }
38
- if (normalized.startsWith("~/")) {
39
- return os.homedir() + normalized.slice(1);
40
- }
41
- return normalized;
42
- }
43
- /**
44
- * Resolve a path relative to the given cwd.
45
- * Handles ~ expansion and absolute paths.
46
- */
47
- export function resolveToCwd(filePath, cwd) {
48
- const expanded = expandPath(filePath);
49
- if (isAbsolute(expanded)) {
50
- return expanded;
51
- }
52
- return resolvePath(cwd, expanded);
53
- }
54
- export function resolveReadPath(filePath, cwd) {
55
- const resolved = resolveToCwd(filePath, cwd);
56
- if (fileExists(resolved)) {
57
- return resolved;
58
- }
59
- // Try macOS AM/PM variant (narrow no-break space before AM/PM)
60
- const amPmVariant = tryMacOSScreenshotPath(resolved);
61
- if (amPmVariant !== resolved && fileExists(amPmVariant)) {
62
- return amPmVariant;
63
- }
64
- // Try NFD variant (macOS stores filenames in NFD form)
65
- const nfdVariant = tryNFDVariant(resolved);
66
- if (nfdVariant !== resolved && fileExists(nfdVariant)) {
67
- return nfdVariant;
68
- }
69
- // Try curly quote variant (macOS uses U+2019 in screenshot names)
70
- const curlyVariant = tryCurlyQuoteVariant(resolved);
71
- if (curlyVariant !== resolved && fileExists(curlyVariant)) {
72
- return curlyVariant;
73
- }
74
- // Try combined NFD + curly quote (for French macOS screenshots like "Capture d'écran")
75
- const nfdCurlyVariant = tryCurlyQuoteVariant(nfdVariant);
76
- if (nfdCurlyVariant !== resolved && fileExists(nfdCurlyVariant)) {
77
- return nfdCurlyVariant;
78
- }
79
- return resolved;
80
- }
81
- //# sourceMappingURL=path-utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"path-utils.js","sourceRoot":"","sources":["../../../src/core/tools/path-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,UAAU,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,WAAW,CAAC;AAE/D,MAAM,cAAc,GAAG,0CAA0C,CAAC;AAClE,MAAM,qBAAqB,GAAG,QAAQ,CAAC;AACvC,SAAS,sBAAsB,CAAC,GAAW,EAAU;IACpD,OAAO,GAAG,CAAC,OAAO,CAAC,cAAc,EAAE,GAAG,CAAC,CAAC;AAAA,CACxC;AAED,SAAS,sBAAsB,CAAC,QAAgB,EAAU;IACzD,OAAO,QAAQ,CAAC,OAAO,CAAC,cAAc,EAAE,GAAG,qBAAqB,KAAK,CAAC,CAAC;AAAA,CACvE;AAED,SAAS,aAAa,CAAC,QAAgB,EAAU;IAChD,oFAAoF;IACpF,OAAO,QAAQ,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AAAA,CACjC;AAED,SAAS,oBAAoB,CAAC,QAAgB,EAAU;IACvD,8FAA6F;IAC7F,oDAAo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AAM,QAAQ,GAAG,YAAY,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;IAE7C,IAAI,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC1B,OAAO,QAAQ,CAAC;IACjB,CAAC;IAED,+DAA+D;IAC/D,MAAM,WAAW,GAAG,sBAAsB,CAAC,QAAQ,CAAC,CAAC;IACrD,IAAI,WAAW,KAAK,QAAQ,IAAI,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC;QACzD,OAAO,WAAW,CAAC;IACpB,CAAC;IAED,uDAAuD;IACvD,MAAM,UAAU,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC;IAC3C,IAAI,UAAU,KAAK,QAAQ,IAAI,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;QACvD,OAAO,UAAU,CAAC;IACnB,CAAC;IAED,kEAAkE;IAClE,MAAM,YAAY,GAAG,oBAAoB,CAAC,QAAQ,CAAC,CAAC;IACpD,IAAI,YAAY,KAAK,QAAQ,IAAI,UAAU,CAAC,YAAY,CAAC,EAAE,CAAC;QAC3D,OAAO,YAAY,CAAC;IACrB,CAAC;IAED,wFAAuF;IACvF,MAAM,eAAe,GAAG,oBAAoB,CAAC,UAAU,CAAC,CAAC;IACzD,IAAI,eAAe,KAAK,QAAQ,IAAI,UAAU,CAAC,eAAe,CAAC,EAAE,CAAC;QACjE,OAAO,eAAe,CAAC;IACxB,CAAC;IAED,OAAO,QAAQ,CAAC;AAAA,CAChB","sourcesContent":["import { accessSync, constants } from \"node:fs\";\nimport * as os from \"node:os\";\nimport { isAbsolute, resolve as resolvePath } from \"node:path\";\n\nconst UNICODE_SPACES = /[\\u00A0\\u2000-\\u200A\\u202F\\u205F\\u3000]/g;\nconst NARROW_NO_BREAK_SPACE = \"\\u202F\";\nfunction normalizeUnicodeSpaces(str: string): string {\n\treturn str.replace(UNICODE_SPACES, \" \");\n}\n\nfunction tryMacOSScreenshotPath(filePath: string): string {\n\treturn filePath.replace(/ (AM|PM)\\./gi, `${NARROW_NO_BREAK_SPACE}$1.`);\n}\n\nfunction tryNFDVariant(filePath: string): string {\n\t// macOS stores filenames in NFD (decomposed) form, try converting user input to NFD\n\treturn filePath.normalize(\"NFD\");\n}\n\nfunction tryCurlyQuoteVariant(filePath: string): string {\n\t// macOS uses U+2019 (right single quotation mark) in screenshot names like \"Capture d'écran\"\n\t// Users typically type U+0027 (straight apostrophe)\n\treturn filePath.replace(/'/g, \"\\u2019\");\n}\n\nfunction fileExists(filePath: string): boolean {\n\ttry {\n\t\taccessSync(filePath, constants.F_OK);\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nfunction normalizeAtPrefix(filePath: string): string {\n\treturn filePath.startsWith(\"@\") ? filePath.slice(1) : filePath;\n}\n\nexport function expandPath(filePath: string): string {\n\tconst normalized = normalizeUnicodeSpaces(normalizeAtPrefix(filePath));\n\tif (normalized === \"~\") {\n\t\treturn os.homedir();\n\t}\n\tif (normalized.startsWith(\"~/\")) {\n\t\treturn os.homedir() + normalized.slice(1);\n\t}\n\treturn normalized;\n}\n\n/**\n * Resolve a path relative to the given cwd.\n * Handles ~ expansion and absolute paths.\n */\nexport function resolveToCwd(filePath: string, cwd: string): string {\n\tconst expanded = expandPath(filePath);\n\tif (isAbsolute(expanded)) {\n\t\treturn expanded;\n\t}\n\treturn resolvePath(cwd, expanded);\n}\n\nexport function resolveReadPath(filePath: string, cwd: string): string {\n\tconst resolved = resolveToCwd(filePath, cwd);\n\n\tif (fileExists(resolved)) {\n\t\treturn resolved;\n\t}\n\n\t// Try macOS AM/PM variant (narrow no-break space before AM/PM)\n\tconst amPmVariant = tryMacOSScreenshotPath(resolved);\n\tif (amPmVariant !== resolved && fileExists(amPmVariant)) {\n\t\treturn amPmVariant;\n\t}\n\n\t// Try NFD variant (macOS stores filenames in NFD form)\n\tconst nfdVariant = tryNFDVariant(resolved);\n\tif (nfdVariant !== resolved && fileExists(nfdVariant)) {\n\t\treturn nfdVariant;\n\t}\n\n\t// Try curly quote variant (macOS uses U+2019 in screenshot names)\n\tconst curlyVariant = tryCurlyQuoteVariant(resolved);\n\tif (curlyVariant !== resolved && fileExists(curlyVariant)) {\n\t\treturn curlyVariant;\n\t}\n\n\t// Try combined NFD + curly quote (for French macOS screenshots like \"Capture d'écran\")\n\tconst nfdCurlyVariant = tryCurlyQuoteVariant(nfdVariant);\n\tif (nfdCurlyVariant !== resolved && fileExists(nfdCurlyVariant)) {\n\t\treturn nfdCurlyVariant;\n\t}\n\n\treturn resolved;\n}\n"]}