@punch-bot/cli 0.85.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (1103) hide show
  1. package/CHANGELOG.md +572 -3
  2. package/README.md +82 -174
  3. package/dist/bun/cli.d.ts.map +1 -1
  4. package/dist/bun/restore-sandbox-env.d.ts.map +1 -1
  5. package/dist/bun/restore-sandbox-env.js.map +1 -1
  6. package/dist/bun/runtime-setup.d.ts.map +1 -1
  7. package/dist/bun/runtime-setup.js +4 -1
  8. package/dist/bun/runtime-setup.js.map +1 -1
  9. package/dist/bun/sandbox-env-setup.d.ts.map +1 -1
  10. package/dist/bundle/chunks/anthropic-messages-DA6M7CRN.js +6 -0
  11. package/dist/bundle/chunks/anthropic.js +2 -2
  12. package/dist/bundle/chunks/azure-openai-responses-IJO5RNR3.js +2 -0
  13. package/dist/bundle/chunks/bedrock-converse-stream.js +10 -2
  14. package/dist/bundle/chunks/chunk-22CYIUS4.js +2 -0
  15. package/dist/bundle/chunks/chunk-2M76JOVH.js +8 -0
  16. package/dist/bundle/chunks/chunk-5HTGPCR7.js +2 -0
  17. package/dist/bundle/chunks/chunk-5OD3Y36V.js +11 -0
  18. package/dist/bundle/chunks/chunk-6C5VKHGV.js +50 -0
  19. package/dist/bundle/chunks/chunk-F5ZABL6Z.js +20 -0
  20. package/dist/bundle/chunks/{chunk-3DNTDXPG.js → chunk-FJPXW4TE.js} +3 -3
  21. package/dist/bundle/chunks/chunk-FLX3SJDL.js +1156 -0
  22. package/dist/bundle/chunks/chunk-HACVPRBJ.js +11 -0
  23. package/dist/bundle/chunks/chunk-ITZNWD4K.js +2 -0
  24. package/dist/bundle/chunks/chunk-J7I2NFJ7.js +82 -0
  25. package/dist/bundle/chunks/chunk-JHYQSLCR.js +2 -0
  26. package/dist/bundle/chunks/chunk-LPXNMA2W.js +2 -0
  27. package/dist/bundle/chunks/chunk-OO6DJ3CL.js +31 -0
  28. package/dist/bundle/chunks/chunk-PMRZO46Y.js +2 -0
  29. package/dist/bundle/chunks/{chunk-TRDNDS6A.js → chunk-PYGXRV27.js} +5 -2
  30. package/dist/bundle/chunks/chunk-RDZVAGPR.js +2 -0
  31. package/dist/bundle/chunks/{chunk-XDUWOHPL.js → chunk-S3GGRYIO.js} +2 -2
  32. package/dist/bundle/chunks/chunk-UTB4DTYQ.js +2 -0
  33. package/dist/bundle/chunks/chunk-WUIPA42N.js +14 -0
  34. package/dist/bundle/chunks/chunk-XIX7LUWI.js +2 -0
  35. package/dist/bundle/chunks/chunk-YWHGLBPB.js +2 -0
  36. package/dist/bundle/chunks/chunk-ZBURYEWF.js +2 -0
  37. package/dist/bundle/chunks/cli-QAQLORRY.js +51 -0
  38. package/dist/bundle/chunks/cloudflare-workers-ai-system-one-UTBL2KOF.js +2 -0
  39. package/dist/bundle/chunks/codemode-worker.js +478 -0
  40. package/dist/bundle/chunks/execute-2Z6BN5R3.js +499 -0
  41. package/dist/bundle/chunks/github-copilot.js +1 -1
  42. package/dist/bundle/chunks/google-generative-ai-JSIIVUNP.js +2 -0
  43. package/dist/bundle/chunks/google-vertex-BZ3ID54S.js +2 -0
  44. package/dist/bundle/chunks/image-resize-worker.js +1 -1
  45. package/dist/bundle/chunks/jiti-loader-C3NU2SDH.js +21 -0
  46. package/dist/bundle/chunks/jiti-static-loader-E6ANQD5T.js +2 -0
  47. package/dist/bundle/chunks/{lib-HGQMNYVT.js → lib-TEDK3E5I.js} +2 -2
  48. package/dist/bundle/chunks/llama-cpp-classify-FYN623RH.js +22 -0
  49. package/dist/bundle/chunks/meta.js +2 -0
  50. package/dist/bundle/chunks/mistral-conversations-RMNTDYQK.js +5 -0
  51. package/dist/bundle/chunks/node-N5BSDOA5.js +16 -0
  52. package/dist/bundle/chunks/{node-4PXJTSWH.js → node-TWVVAGPO.js} +1 -1
  53. package/dist/bundle/chunks/openai-chatgpt.js +75 -0
  54. package/dist/bundle/chunks/openai-codex-responses-O3P3UWDP.js +10 -0
  55. package/dist/bundle/chunks/openai-codex.js +2 -2
  56. package/dist/bundle/chunks/openai-completions-G4BKSHGH.js +7 -0
  57. package/dist/bundle/chunks/openai-decisions-WVPMQ4JD.js +5 -0
  58. package/dist/bundle/chunks/openai-responses-377V6EDU.js +3 -0
  59. package/dist/bundle/chunks/{openrouter-images-N4XVVFSD.js → openrouter-images-YU24TD7D.js} +1 -1
  60. package/dist/bundle/chunks/openrouter.js +2 -2
  61. package/dist/bundle/chunks/{pi-messages-ZRYGTSON.js → pi-messages-V27DSLVC.js} +2 -2
  62. package/dist/bundle/chunks/radius.js +2 -2
  63. package/dist/bundle/chunks/runtime-R6O72Q4R.js +2 -0
  64. package/dist/bundle/chunks/typesafe-system-one-ZSK3RN4B.js +2 -0
  65. package/dist/bundle/chunks/virtual-modules-FOSN3OT2.js +2 -0
  66. package/dist/bundle/cli-runtime.js +3 -0
  67. package/dist/bundle/cli.js +4 -2
  68. package/dist/bundle/index.js +1 -1
  69. package/dist/bundle/rpc-entry.js +1 -1
  70. package/dist/cli/args.d.ts +1 -2
  71. package/dist/cli/args.d.ts.map +1 -1
  72. package/dist/cli/args.js +73 -53
  73. package/dist/cli/args.js.map +1 -1
  74. package/dist/cli/auth-check.d.ts.map +1 -1
  75. package/dist/cli/auth-check.js.map +1 -1
  76. package/dist/cli/auth-command.d.ts.map +1 -1
  77. package/dist/cli/auth-command.js.map +1 -1
  78. package/dist/cli/credential-print.d.ts.map +1 -1
  79. package/dist/cli/credential-print.js.map +1 -1
  80. package/dist/cli/experimental/transport-address.d.ts +21 -0
  81. package/dist/cli/experimental/transport-address.d.ts.map +1 -0
  82. package/dist/cli/experimental/transport-address.js +89 -0
  83. package/dist/cli/experimental/transport-address.js.map +1 -0
  84. package/dist/cli/file-processor.d.ts +1 -1
  85. package/dist/cli/file-processor.d.ts.map +1 -1
  86. package/dist/cli/file-processor.js.map +1 -1
  87. package/dist/cli/initial-message.d.ts +1 -1
  88. package/dist/cli/initial-message.d.ts.map +1 -1
  89. package/dist/cli/initial-message.js.map +1 -1
  90. package/dist/cli/list-models.d.ts.map +1 -1
  91. package/dist/cli/list-models.js +1 -1
  92. package/dist/cli/list-models.js.map +1 -1
  93. package/dist/cli/project-trust.d.ts.map +1 -1
  94. package/dist/cli/project-trust.js +5 -35
  95. package/dist/cli/project-trust.js.map +1 -1
  96. package/dist/cli/setup.d.ts.map +1 -1
  97. package/dist/cli/setup.js.map +1 -1
  98. package/dist/cli.d.ts.map +1 -1
  99. package/dist/config.d.ts +30 -11
  100. package/dist/config.d.ts.map +1 -1
  101. package/dist/config.js +72 -21
  102. package/dist/config.js.map +1 -1
  103. package/dist/core/agent-session-runtime.d.ts +4 -3
  104. package/dist/core/agent-session-runtime.d.ts.map +1 -1
  105. package/dist/core/agent-session-runtime.js +37 -27
  106. package/dist/core/agent-session-runtime.js.map +1 -1
  107. package/dist/core/agent-session-services.d.ts +1 -0
  108. package/dist/core/agent-session-services.d.ts.map +1 -1
  109. package/dist/core/agent-session-services.js +14 -0
  110. package/dist/core/agent-session-services.js.map +1 -1
  111. package/dist/core/agent-session.d.ts +270 -22
  112. package/dist/core/agent-session.d.ts.map +1 -1
  113. package/dist/core/agent-session.js +1174 -410
  114. package/dist/core/agent-session.js.map +1 -1
  115. package/dist/core/auth-guidance.d.ts.map +1 -1
  116. package/dist/core/auth-guidance.js.map +1 -1
  117. package/dist/core/auth-storage.d.ts.map +1 -1
  118. package/dist/core/auth-storage.js +20 -13
  119. package/dist/core/auth-storage.js.map +1 -1
  120. package/dist/core/bash-executor.d.ts.map +1 -1
  121. package/dist/core/bash-executor.js +42 -52
  122. package/dist/core/bash-executor.js.map +1 -1
  123. package/dist/core/bug-report-upload.d.ts +12 -0
  124. package/dist/core/bug-report-upload.d.ts.map +1 -0
  125. package/dist/core/bug-report-upload.js +22 -0
  126. package/dist/core/bug-report-upload.js.map +1 -0
  127. package/dist/core/bug-report.d.ts +184 -0
  128. package/dist/core/bug-report.d.ts.map +1 -0
  129. package/dist/core/bug-report.js +292 -0
  130. package/dist/core/bug-report.js.map +1 -0
  131. package/dist/core/cache-stats.d.ts.map +1 -1
  132. package/dist/core/cache-stats.js +12 -1
  133. package/dist/core/cache-stats.js.map +1 -1
  134. package/dist/core/cache-warmer.d.ts +103 -0
  135. package/dist/core/cache-warmer.d.ts.map +1 -0
  136. package/dist/core/cache-warmer.js +356 -0
  137. package/dist/core/cache-warmer.js.map +1 -0
  138. package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
  139. package/dist/core/compaction/branch-summarization.js +2 -2
  140. package/dist/core/compaction/branch-summarization.js.map +1 -1
  141. package/dist/core/compaction/compaction.d.ts +5 -3
  142. package/dist/core/compaction/compaction.d.ts.map +1 -1
  143. package/dist/core/compaction/compaction.js +164 -88
  144. package/dist/core/compaction/compaction.js.map +1 -1
  145. package/dist/core/compaction/index.d.ts.map +1 -1
  146. package/dist/core/compaction/utils.d.ts +8 -1
  147. package/dist/core/compaction/utils.d.ts.map +1 -1
  148. package/dist/core/compaction/utils.js +32 -26
  149. package/dist/core/compaction/utils.js.map +1 -1
  150. package/dist/core/crash-log.d.ts +27 -0
  151. package/dist/core/crash-log.d.ts.map +1 -0
  152. package/dist/core/crash-log.js +140 -0
  153. package/dist/core/crash-log.js.map +1 -0
  154. package/dist/core/defaults.d.ts.map +1 -1
  155. package/dist/core/delivery.d.ts.map +1 -1
  156. package/dist/core/delivery.js.map +1 -1
  157. package/dist/core/diagnostics.d.ts.map +1 -1
  158. package/dist/core/event-bus.d.ts.map +1 -1
  159. package/dist/core/event-bus.js.map +1 -1
  160. package/dist/core/exec.d.ts.map +1 -1
  161. package/dist/core/exec.js.map +1 -1
  162. package/dist/core/experimental.d.ts.map +1 -1
  163. package/dist/core/experimental.js.map +1 -1
  164. package/dist/core/export-html/ansi-to-html.d.ts.map +1 -1
  165. package/dist/core/export-html/ansi-to-html.js.map +1 -1
  166. package/dist/core/export-html/index.d.ts.map +1 -1
  167. package/dist/core/export-html/index.js +1 -1
  168. package/dist/core/export-html/index.js.map +1 -1
  169. package/dist/core/export-html/template.css +10 -0
  170. package/dist/core/export-html/template.js +93 -34
  171. package/dist/core/export-html/tool-renderer.d.ts +5 -11
  172. package/dist/core/export-html/tool-renderer.d.ts.map +1 -1
  173. package/dist/core/export-html/tool-renderer.js +8 -99
  174. package/dist/core/export-html/tool-renderer.js.map +1 -1
  175. package/dist/core/extensions/index.d.ts +1 -1
  176. package/dist/core/extensions/index.d.ts.map +1 -1
  177. package/dist/core/extensions/index.js.map +1 -1
  178. package/dist/core/extensions/jiti-loader.d.ts +2 -0
  179. package/dist/core/extensions/jiti-loader.d.ts.map +1 -0
  180. package/dist/core/extensions/jiti-loader.js +4 -0
  181. package/dist/core/extensions/jiti-loader.js.map +1 -0
  182. package/dist/core/extensions/jiti-static-loader.d.ts +2 -0
  183. package/dist/core/extensions/jiti-static-loader.d.ts.map +1 -0
  184. package/dist/core/extensions/jiti-static-loader.js +4 -0
  185. package/dist/core/extensions/jiti-static-loader.js.map +1 -0
  186. package/dist/core/extensions/loader.d.ts.map +1 -1
  187. package/dist/core/extensions/loader.js +102 -74
  188. package/dist/core/extensions/loader.js.map +1 -1
  189. package/dist/core/extensions/runner.d.ts +44 -14
  190. package/dist/core/extensions/runner.d.ts.map +1 -1
  191. package/dist/core/extensions/runner.js +297 -169
  192. package/dist/core/extensions/runner.js.map +1 -1
  193. package/dist/core/extensions/types.d.ts +482 -238
  194. package/dist/core/extensions/types.d.ts.map +1 -1
  195. package/dist/core/extensions/types.js.map +1 -1
  196. package/dist/core/extensions/virtual-modules.d.ts +3 -0
  197. package/dist/core/extensions/virtual-modules.d.ts.map +1 -0
  198. package/dist/core/extensions/virtual-modules.js +35 -0
  199. package/dist/core/extensions/virtual-modules.js.map +1 -0
  200. package/dist/core/extensions/wrapper.d.ts +2 -2
  201. package/dist/core/extensions/wrapper.d.ts.map +1 -1
  202. package/dist/core/extensions/wrapper.js +3 -22
  203. package/dist/core/extensions/wrapper.js.map +1 -1
  204. package/dist/core/footer-data-provider.d.ts.map +1 -1
  205. package/dist/core/footer-data-provider.js.map +1 -1
  206. package/dist/core/http-dispatcher.d.ts +13 -0
  207. package/dist/core/http-dispatcher.d.ts.map +1 -1
  208. package/dist/core/http-dispatcher.js +13 -4
  209. package/dist/core/http-dispatcher.js.map +1 -1
  210. package/dist/core/index.d.ts +2 -1
  211. package/dist/core/index.d.ts.map +1 -1
  212. package/dist/core/index.js.map +1 -1
  213. package/dist/core/mcp-servers.d.ts +139 -0
  214. package/dist/core/mcp-servers.d.ts.map +1 -0
  215. package/dist/core/mcp-servers.js +232 -0
  216. package/dist/core/mcp-servers.js.map +1 -0
  217. package/dist/core/messages.d.ts.map +1 -1
  218. package/dist/core/messages.js +1 -0
  219. package/dist/core/messages.js.map +1 -1
  220. package/dist/{modes/interactive → core}/model-catalog-refresh.d.ts +2 -2
  221. package/dist/core/model-catalog-refresh.d.ts.map +1 -0
  222. package/dist/{modes/interactive → core}/model-catalog-refresh.js +2 -2
  223. package/dist/core/model-catalog-refresh.js.map +1 -0
  224. package/dist/core/model-config.d.ts +886 -80
  225. package/dist/core/model-config.d.ts.map +1 -1
  226. package/dist/core/model-config.js +33 -148
  227. package/dist/core/model-config.js.map +1 -1
  228. package/dist/core/model-registry.d.ts +15 -1
  229. package/dist/core/model-registry.d.ts.map +1 -1
  230. package/dist/core/model-registry.js +29 -0
  231. package/dist/core/model-registry.js.map +1 -1
  232. package/dist/core/model-resolver.d.ts +19 -46
  233. package/dist/core/model-resolver.d.ts.map +1 -1
  234. package/dist/core/model-resolver.js +149 -359
  235. package/dist/core/model-resolver.js.map +1 -1
  236. package/dist/core/model-runtime.d.ts +47 -3
  237. package/dist/core/model-runtime.d.ts.map +1 -1
  238. package/dist/core/model-runtime.js +205 -43
  239. package/dist/core/model-runtime.js.map +1 -1
  240. package/dist/core/models-store.d.ts.map +1 -1
  241. package/dist/core/models-store.js.map +1 -1
  242. package/dist/core/nested-tool-calls.d.ts +103 -0
  243. package/dist/core/nested-tool-calls.d.ts.map +1 -0
  244. package/dist/core/nested-tool-calls.js +179 -0
  245. package/dist/core/nested-tool-calls.js.map +1 -0
  246. package/dist/core/output-guard.d.ts.map +1 -1
  247. package/dist/core/output-guard.js.map +1 -1
  248. package/dist/core/package-manager.d.ts +4 -0
  249. package/dist/core/package-manager.d.ts.map +1 -1
  250. package/dist/core/package-manager.js +62 -15
  251. package/dist/core/package-manager.js.map +1 -1
  252. package/dist/core/pi-manifest.d.ts.map +1 -1
  253. package/dist/core/pi-manifest.js.map +1 -1
  254. package/dist/core/project-trust.d.ts.map +1 -1
  255. package/dist/core/project-trust.js +2 -1
  256. package/dist/core/project-trust.js.map +1 -1
  257. package/dist/core/prompt-templates.d.ts +6 -1
  258. package/dist/core/prompt-templates.d.ts.map +1 -1
  259. package/dist/core/prompt-templates.js +68 -37
  260. package/dist/core/prompt-templates.js.map +1 -1
  261. package/dist/core/provider-attribution.d.ts.map +1 -1
  262. package/dist/core/provider-attribution.js.map +1 -1
  263. package/dist/core/provider-composer.d.ts +42 -20
  264. package/dist/core/provider-composer.d.ts.map +1 -1
  265. package/dist/core/provider-composer.js +126 -40
  266. package/dist/core/provider-composer.js.map +1 -1
  267. package/dist/core/radius.d.ts +5 -0
  268. package/dist/core/radius.d.ts.map +1 -1
  269. package/dist/core/radius.js +8 -0
  270. package/dist/core/radius.js.map +1 -1
  271. package/dist/core/remote-catalog-provider.d.ts +19 -1
  272. package/dist/core/remote-catalog-provider.d.ts.map +1 -1
  273. package/dist/core/remote-catalog-provider.js +102 -34
  274. package/dist/core/remote-catalog-provider.js.map +1 -1
  275. package/dist/core/resolve-config-value.d.ts.map +1 -1
  276. package/dist/core/resolve-config-value.js.map +1 -1
  277. package/dist/core/resource-loader.d.ts +11 -2
  278. package/dist/core/resource-loader.d.ts.map +1 -1
  279. package/dist/core/resource-loader.js +170 -42
  280. package/dist/core/resource-loader.js.map +1 -1
  281. package/dist/core/runtime-credentials.d.ts.map +1 -1
  282. package/dist/core/runtime-credentials.js.map +1 -1
  283. package/dist/core/sdk.d.ts +16 -5
  284. package/dist/core/sdk.d.ts.map +1 -1
  285. package/dist/core/sdk.js +124 -52
  286. package/dist/core/sdk.js.map +1 -1
  287. package/dist/core/session-cwd.d.ts.map +1 -1
  288. package/dist/core/session-cwd.js.map +1 -1
  289. package/dist/core/session-export.d.ts +6 -2
  290. package/dist/core/session-export.d.ts.map +1 -1
  291. package/dist/core/session-export.js +14 -13
  292. package/dist/core/session-export.js.map +1 -1
  293. package/dist/core/session-manager.d.ts +72 -13
  294. package/dist/core/session-manager.d.ts.map +1 -1
  295. package/dist/core/session-manager.js +277 -124
  296. package/dist/core/session-manager.js.map +1 -1
  297. package/dist/core/settings-defaults.d.ts +65 -0
  298. package/dist/core/settings-defaults.d.ts.map +1 -0
  299. package/dist/core/settings-defaults.js +66 -0
  300. package/dist/core/settings-defaults.js.map +1 -0
  301. package/dist/core/settings-diagnostics.d.ts.map +1 -1
  302. package/dist/core/settings-diagnostics.js.map +1 -1
  303. package/dist/core/settings-manager.d.ts +41 -126
  304. package/dist/core/settings-manager.d.ts.map +1 -1
  305. package/dist/core/settings-manager.js +165 -52
  306. package/dist/core/settings-manager.js.map +1 -1
  307. package/dist/core/settings-schema.d.ts +224 -0
  308. package/dist/core/settings-schema.d.ts.map +1 -0
  309. package/dist/core/settings-schema.js +285 -0
  310. package/dist/core/settings-schema.js.map +1 -0
  311. package/dist/core/skills.d.ts +4 -1
  312. package/dist/core/skills.d.ts.map +1 -1
  313. package/dist/core/skills.js +6 -1
  314. package/dist/core/skills.js.map +1 -1
  315. package/dist/core/slash-commands.d.ts.map +1 -1
  316. package/dist/core/slash-commands.js +3 -2
  317. package/dist/core/slash-commands.js.map +1 -1
  318. package/dist/core/source-info.d.ts +8 -0
  319. package/dist/core/source-info.d.ts.map +1 -1
  320. package/dist/core/source-info.js +16 -0
  321. package/dist/core/source-info.js.map +1 -1
  322. package/dist/core/system-prompt.d.ts +55 -6
  323. package/dist/core/system-prompt.d.ts.map +1 -1
  324. package/dist/core/system-prompt.js +128 -93
  325. package/dist/core/system-prompt.js.map +1 -1
  326. package/dist/core/telemetry.d.ts +2 -0
  327. package/dist/core/telemetry.d.ts.map +1 -1
  328. package/dist/core/telemetry.js +45 -0
  329. package/dist/core/telemetry.js.map +1 -1
  330. package/dist/core/theme/dark.json +78 -0
  331. package/dist/core/theme/light.json +78 -0
  332. package/dist/core/theme/system-theme.d.ts +54 -0
  333. package/dist/core/theme/system-theme.d.ts.map +1 -0
  334. package/dist/core/theme/system-theme.js +547 -0
  335. package/dist/core/theme/system-theme.js.map +1 -0
  336. package/dist/core/theme/theme-schema.d.ts +28 -0
  337. package/dist/core/theme/theme-schema.d.ts.map +1 -0
  338. package/dist/core/theme/theme-schema.js +105 -0
  339. package/dist/core/theme/theme-schema.js.map +1 -0
  340. package/dist/core/theme/theme-tokens.d.ts +257 -0
  341. package/dist/core/theme/theme-tokens.d.ts.map +1 -0
  342. package/dist/core/theme/theme-tokens.js +94 -0
  343. package/dist/core/theme/theme-tokens.js.map +1 -0
  344. package/dist/core/theme/theme.d.ts +162 -0
  345. package/dist/core/theme/theme.d.ts.map +1 -0
  346. package/dist/{modes/interactive → core}/theme/theme.js +265 -402
  347. package/dist/core/theme/theme.js.map +1 -0
  348. package/dist/core/timings.d.ts.map +1 -1
  349. package/dist/core/timings.js.map +1 -1
  350. package/dist/core/tools/bash.d.ts +14 -1
  351. package/dist/core/tools/bash.d.ts.map +1 -1
  352. package/dist/core/tools/bash.js +43 -6
  353. package/dist/core/tools/bash.js.map +1 -1
  354. package/dist/core/tools/edit-diff.d.ts.map +1 -1
  355. package/dist/core/tools/edit-diff.js.map +1 -1
  356. package/dist/core/tools/edit.d.ts +1 -2
  357. package/dist/core/tools/edit.d.ts.map +1 -1
  358. package/dist/core/tools/edit.js +0 -3
  359. package/dist/core/tools/edit.js.map +1 -1
  360. package/dist/core/tools/file-mutation-queue.d.ts.map +1 -1
  361. package/dist/core/tools/file-mutation-queue.js.map +1 -1
  362. package/dist/core/tools/find.d.ts.map +1 -1
  363. package/dist/core/tools/find.js +0 -2
  364. package/dist/core/tools/find.js.map +1 -1
  365. package/dist/core/tools/grep.d.ts.map +1 -1
  366. package/dist/core/tools/grep.js +0 -2
  367. package/dist/core/tools/grep.js.map +1 -1
  368. package/dist/core/tools/index.d.ts.map +1 -1
  369. package/dist/core/tools/index.js.map +1 -1
  370. package/dist/core/tools/ls.d.ts.map +1 -1
  371. package/dist/core/tools/ls.js +0 -2
  372. package/dist/core/tools/ls.js.map +1 -1
  373. package/dist/core/tools/output-accumulator.d.ts +11 -0
  374. package/dist/core/tools/output-accumulator.d.ts.map +1 -1
  375. package/dist/core/tools/output-accumulator.js +40 -10
  376. package/dist/core/tools/output-accumulator.js.map +1 -1
  377. package/dist/core/tools/path-utils.d.ts.map +1 -1
  378. package/dist/core/tools/path-utils.js.map +1 -1
  379. package/dist/core/tools/powershell.d.ts.map +1 -1
  380. package/dist/core/tools/powershell.js.map +1 -1
  381. package/dist/core/tools/read.d.ts +17 -1
  382. package/dist/core/tools/read.d.ts.map +1 -1
  383. package/dist/core/tools/read.js +23 -4
  384. package/dist/core/tools/read.js.map +1 -1
  385. package/dist/core/tools/tool-definition-wrapper.d.ts +5 -3
  386. package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -1
  387. package/dist/core/tools/tool-definition-wrapper.js +3 -1
  388. package/dist/core/tools/tool-definition-wrapper.js.map +1 -1
  389. package/dist/core/tools/truncate.d.ts +14 -0
  390. package/dist/core/tools/truncate.d.ts.map +1 -1
  391. package/dist/core/tools/truncate.js +29 -0
  392. package/dist/core/tools/truncate.js.map +1 -1
  393. package/dist/core/tools/write.d.ts.map +1 -1
  394. package/dist/core/tools/write.js +0 -2
  395. package/dist/core/tools/write.js.map +1 -1
  396. package/dist/core/trust-manager.d.ts.map +1 -1
  397. package/dist/core/trust-manager.js +1 -0
  398. package/dist/core/trust-manager.js.map +1 -1
  399. package/dist/core/usage-totals.d.ts +3 -1
  400. package/dist/core/usage-totals.d.ts.map +1 -1
  401. package/dist/core/usage-totals.js +28 -1
  402. package/dist/core/usage-totals.js.map +1 -1
  403. package/dist/core/virtual-models.d.ts +117 -0
  404. package/dist/core/virtual-models.d.ts.map +1 -0
  405. package/dist/core/virtual-models.js +124 -0
  406. package/dist/core/virtual-models.js.map +1 -0
  407. package/dist/extensions/browser/index.d.ts.map +1 -1
  408. package/dist/extensions/browser/index.js.map +1 -1
  409. package/dist/extensions/codemode/execute.d.ts +16 -0
  410. package/dist/extensions/codemode/execute.d.ts.map +1 -0
  411. package/dist/extensions/codemode/execute.js +665 -0
  412. package/dist/extensions/codemode/execute.js.map +1 -0
  413. package/dist/extensions/codemode/execute.lazy.d.ts +3 -0
  414. package/dist/extensions/codemode/execute.lazy.d.ts.map +1 -0
  415. package/dist/extensions/codemode/execute.lazy.js +3 -0
  416. package/dist/extensions/codemode/execute.lazy.js.map +1 -0
  417. package/dist/extensions/codemode/index.d.ts +21 -0
  418. package/dist/extensions/codemode/index.d.ts.map +1 -0
  419. package/dist/extensions/codemode/index.js +33 -0
  420. package/dist/extensions/codemode/index.js.map +1 -0
  421. package/dist/extensions/codemode/tool.d.ts +124 -0
  422. package/dist/extensions/codemode/tool.d.ts.map +1 -0
  423. package/dist/extensions/codemode/tool.js +286 -0
  424. package/dist/extensions/codemode/tool.js.map +1 -0
  425. package/dist/extensions/codemode/worker.d.ts +7 -0
  426. package/dist/extensions/codemode/worker.d.ts.map +1 -0
  427. package/dist/extensions/codemode/worker.js +7 -0
  428. package/dist/extensions/codemode/worker.js.map +1 -0
  429. package/dist/extensions/context-pruning/compress_context.d.ts.map +1 -1
  430. package/dist/extensions/context-pruning/compress_context.js +1 -3
  431. package/dist/extensions/context-pruning/compress_context.js.map +1 -1
  432. package/dist/extensions/context-pruning/context-pruning-state.d.ts.map +1 -1
  433. package/dist/extensions/context-pruning/context-pruning-state.js.map +1 -1
  434. package/dist/extensions/index.d.ts.map +1 -1
  435. package/dist/extensions/index.js +6 -2
  436. package/dist/extensions/index.js.map +1 -1
  437. package/dist/extensions/llama/client.d.ts +2 -0
  438. package/dist/extensions/llama/client.d.ts.map +1 -1
  439. package/dist/extensions/llama/client.js +7 -3
  440. package/dist/extensions/llama/client.js.map +1 -1
  441. package/dist/extensions/llama/huggingface.d.ts.map +1 -1
  442. package/dist/extensions/llama/huggingface.js.map +1 -1
  443. package/dist/extensions/llama/index.d.ts.map +1 -1
  444. package/dist/extensions/llama/index.js +0 -4
  445. package/dist/extensions/llama/index.js.map +1 -1
  446. package/dist/extensions/llama/provider.d.ts +1 -1
  447. package/dist/extensions/llama/provider.d.ts.map +1 -1
  448. package/dist/extensions/llama/provider.js +103 -13
  449. package/dist/extensions/llama/provider.js.map +1 -1
  450. package/dist/extensions/llama/ui.d.ts +3 -2
  451. package/dist/extensions/llama/ui.d.ts.map +1 -1
  452. package/dist/extensions/llama/ui.js +106 -364
  453. package/dist/extensions/llama/ui.js.map +1 -1
  454. package/dist/extensions/mcp/cli.d.ts +21 -0
  455. package/dist/extensions/mcp/cli.d.ts.map +1 -0
  456. package/dist/extensions/mcp/cli.js +494 -0
  457. package/dist/extensions/mcp/cli.js.map +1 -0
  458. package/dist/extensions/mcp/cli.lazy.d.ts +3 -0
  459. package/dist/extensions/mcp/cli.lazy.d.ts.map +1 -0
  460. package/dist/extensions/mcp/cli.lazy.js +3 -0
  461. package/dist/extensions/mcp/cli.lazy.js.map +1 -0
  462. package/dist/extensions/mcp/config.d.ts +84 -0
  463. package/dist/extensions/mcp/config.d.ts.map +1 -0
  464. package/dist/extensions/mcp/config.js +196 -0
  465. package/dist/extensions/mcp/config.js.map +1 -0
  466. package/dist/extensions/mcp/index.d.ts +71 -2
  467. package/dist/extensions/mcp/index.d.ts.map +1 -1
  468. package/dist/extensions/mcp/index.js +839 -131
  469. package/dist/extensions/mcp/index.js.map +1 -1
  470. package/dist/extensions/mcp/log.d.ts +16 -0
  471. package/dist/extensions/mcp/log.d.ts.map +1 -0
  472. package/dist/extensions/mcp/log.js +66 -0
  473. package/dist/extensions/mcp/log.js.map +1 -0
  474. package/dist/extensions/mcp/oauth.d.ts +102 -0
  475. package/dist/extensions/mcp/oauth.d.ts.map +1 -0
  476. package/dist/extensions/mcp/oauth.js +428 -0
  477. package/dist/extensions/mcp/oauth.js.map +1 -0
  478. package/dist/extensions/mcp/resources.d.ts +36 -0
  479. package/dist/extensions/mcp/resources.d.ts.map +1 -0
  480. package/dist/extensions/mcp/resources.js +261 -0
  481. package/dist/extensions/mcp/resources.js.map +1 -0
  482. package/dist/extensions/mcp/runtime.d.ts +98 -0
  483. package/dist/extensions/mcp/runtime.d.ts.map +1 -0
  484. package/dist/extensions/mcp/runtime.js +378 -0
  485. package/dist/extensions/mcp/runtime.js.map +1 -0
  486. package/dist/extensions/mcp/runtime.lazy.d.ts +3 -0
  487. package/dist/extensions/mcp/runtime.lazy.d.ts.map +1 -0
  488. package/dist/extensions/mcp/runtime.lazy.js +3 -0
  489. package/dist/extensions/mcp/runtime.lazy.js.map +1 -0
  490. package/dist/extensions/mcp/tools.d.ts +84 -0
  491. package/dist/extensions/mcp/tools.d.ts.map +1 -0
  492. package/dist/extensions/mcp/tools.js +263 -0
  493. package/dist/extensions/mcp/tools.js.map +1 -0
  494. package/dist/extensions/punch/a2a-listen.d.ts +9 -0
  495. package/dist/extensions/punch/a2a-listen.d.ts.map +1 -0
  496. package/dist/extensions/punch/a2a-listen.js +88 -0
  497. package/dist/extensions/punch/a2a-listen.js.map +1 -0
  498. package/dist/extensions/punch/a2a.d.ts +12 -0
  499. package/dist/extensions/punch/a2a.d.ts.map +1 -0
  500. package/dist/extensions/punch/a2a.js +106 -0
  501. package/dist/extensions/punch/a2a.js.map +1 -0
  502. package/dist/extensions/punch/auth.d.ts.map +1 -1
  503. package/dist/extensions/punch/auth.js.map +1 -1
  504. package/dist/extensions/punch/collabs.d.ts.map +1 -1
  505. package/dist/extensions/punch/collabs.js.map +1 -1
  506. package/dist/extensions/punch/index.d.ts.map +1 -1
  507. package/dist/extensions/punch/index.js +9 -14
  508. package/dist/extensions/punch/index.js.map +1 -1
  509. package/dist/extensions/punch/routines.d.ts +1 -3
  510. package/dist/extensions/punch/routines.d.ts.map +1 -1
  511. package/dist/extensions/punch/routines.js +1 -121
  512. package/dist/extensions/punch/routines.js.map +1 -1
  513. package/dist/extensions/punch/server.d.ts.map +1 -1
  514. package/dist/extensions/punch/server.js.map +1 -1
  515. package/dist/extensions/punch/timezone.d.ts.map +1 -1
  516. package/dist/extensions/punch/timezone.js.map +1 -1
  517. package/dist/extensions/punch/todos.d.ts.map +1 -1
  518. package/dist/extensions/punch/todos.js.map +1 -1
  519. package/dist/extensions/report-progress/index.d.ts.map +1 -1
  520. package/dist/extensions/report-progress/index.js.map +1 -1
  521. package/dist/extensions/subagent/agents.d.ts.map +1 -1
  522. package/dist/extensions/subagent/agents.js.map +1 -1
  523. package/dist/extensions/subagent/index.d.ts.map +1 -1
  524. package/dist/extensions/subagent/index.js +0 -372
  525. package/dist/extensions/subagent/index.js.map +1 -1
  526. package/dist/extensions/tool-search/index.d.ts +12 -0
  527. package/dist/extensions/tool-search/index.d.ts.map +1 -0
  528. package/dist/extensions/tool-search/index.js +15 -0
  529. package/dist/extensions/tool-search/index.js.map +1 -0
  530. package/dist/extensions/tool-search/tool.d.ts +71 -0
  531. package/dist/extensions/tool-search/tool.d.ts.map +1 -0
  532. package/dist/extensions/tool-search/tool.js +187 -0
  533. package/dist/extensions/tool-search/tool.js.map +1 -0
  534. package/dist/extensions/webfetch/index.d.ts.map +1 -1
  535. package/dist/extensions/webfetch/index.js.map +1 -1
  536. package/dist/extensions/websearch/index.d.ts.map +1 -1
  537. package/dist/extensions/websearch/index.js.map +1 -1
  538. package/dist/index.d.ts +13 -6
  539. package/dist/index.d.ts.map +1 -1
  540. package/dist/index.js +9 -6
  541. package/dist/index.js.map +1 -1
  542. package/dist/main.d.ts +1 -1
  543. package/dist/main.d.ts.map +1 -1
  544. package/dist/main.js +139 -173
  545. package/dist/main.js.map +1 -1
  546. package/dist/migrations.d.ts.map +1 -1
  547. package/dist/migrations.js +0 -20
  548. package/dist/migrations.js.map +1 -1
  549. package/dist/modes/index.d.ts +0 -1
  550. package/dist/modes/index.d.ts.map +1 -1
  551. package/dist/modes/index.js +0 -1
  552. package/dist/modes/index.js.map +1 -1
  553. package/dist/modes/json-event.d.ts.map +1 -1
  554. package/dist/modes/json-event.js.map +1 -1
  555. package/dist/modes/print-mode.d.ts.map +1 -1
  556. package/dist/modes/print-mode.js +4 -0
  557. package/dist/modes/print-mode.js.map +1 -1
  558. package/dist/modes/rpc/jsonl.d.ts.map +1 -1
  559. package/dist/modes/rpc/jsonl.js.map +1 -1
  560. package/dist/modes/rpc/rpc-client.d.ts +6 -6
  561. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  562. package/dist/modes/rpc/rpc-client.js +12 -8
  563. package/dist/modes/rpc/rpc-client.js.map +1 -1
  564. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  565. package/dist/modes/rpc/rpc-mode.js +16 -46
  566. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  567. package/dist/modes/rpc/rpc-types.d.ts +10 -1
  568. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  569. package/dist/modes/rpc/rpc-types.js.map +1 -1
  570. package/dist/package-manager-cli.d.ts.map +1 -1
  571. package/dist/package-manager-cli.js +43 -43
  572. package/dist/package-manager-cli.js.map +1 -1
  573. package/dist/rpc-entry.d.ts.map +1 -1
  574. package/dist/rpc-entry.js.map +1 -1
  575. package/dist/server/a2a/harness-runner.d.ts.map +1 -1
  576. package/dist/server/a2a/harness-runner.js.map +1 -1
  577. package/dist/server/a2a/run-server.d.ts.map +1 -1
  578. package/dist/server/a2a/run-server.js.map +1 -1
  579. package/dist/utils/abort.d.ts.map +1 -1
  580. package/dist/utils/abort.js.map +1 -1
  581. package/dist/utils/ansi.d.ts +8 -0
  582. package/dist/utils/ansi.d.ts.map +1 -1
  583. package/dist/utils/ansi.js +30 -11
  584. package/dist/utils/ansi.js.map +1 -1
  585. package/dist/utils/changelog.d.ts.map +1 -1
  586. package/dist/utils/changelog.js +5 -2
  587. package/dist/utils/changelog.js.map +1 -1
  588. package/dist/utils/child-process.d.ts.map +1 -1
  589. package/dist/utils/child-process.js.map +1 -1
  590. package/dist/utils/clipboard-command.d.ts.map +1 -1
  591. package/dist/utils/clipboard-command.js.map +1 -1
  592. package/dist/utils/clipboard-image.d.ts.map +1 -1
  593. package/dist/utils/clipboard-image.js +15 -41
  594. package/dist/utils/clipboard-image.js.map +1 -1
  595. package/dist/utils/clipboard.d.ts.map +1 -1
  596. package/dist/utils/clipboard.js +96 -38
  597. package/dist/utils/clipboard.js.map +1 -1
  598. package/dist/utils/colors.d.ts +73 -0
  599. package/dist/utils/colors.d.ts.map +1 -0
  600. package/dist/utils/colors.js +273 -0
  601. package/dist/utils/colors.js.map +1 -0
  602. package/dist/utils/deprecation.d.ts.map +1 -1
  603. package/dist/utils/deprecation.js.map +1 -1
  604. package/dist/utils/exif-orientation.d.ts.map +1 -1
  605. package/dist/utils/exif-orientation.js.map +1 -1
  606. package/dist/utils/frontmatter.d.ts.map +1 -1
  607. package/dist/utils/frontmatter.js.map +1 -1
  608. package/dist/utils/fs-watch.d.ts.map +1 -1
  609. package/dist/utils/fs-watch.js.map +1 -1
  610. package/dist/utils/fuzzy.d.ts +16 -0
  611. package/dist/utils/fuzzy.d.ts.map +1 -0
  612. package/dist/utils/fuzzy.js +111 -0
  613. package/dist/utils/fuzzy.js.map +1 -0
  614. package/dist/utils/git.d.ts.map +1 -1
  615. package/dist/utils/git.js.map +1 -1
  616. package/dist/utils/html.d.ts.map +1 -1
  617. package/dist/utils/html.js.map +1 -1
  618. package/dist/utils/image-convert.d.ts.map +1 -1
  619. package/dist/utils/image-convert.js.map +1 -1
  620. package/dist/utils/image-process.d.ts.map +1 -1
  621. package/dist/utils/image-process.js.map +1 -1
  622. package/dist/utils/image-resize-core.d.ts +12 -0
  623. package/dist/utils/image-resize-core.d.ts.map +1 -1
  624. package/dist/utils/image-resize-core.js +5 -0
  625. package/dist/utils/image-resize-core.js.map +1 -1
  626. package/dist/utils/image-resize-worker.d.ts.map +1 -1
  627. package/dist/utils/image-resize-worker.js +3 -2
  628. package/dist/utils/image-resize-worker.js.map +1 -1
  629. package/dist/utils/image-resize.d.ts.map +1 -1
  630. package/dist/utils/image-resize.js +9 -10
  631. package/dist/utils/image-resize.js.map +1 -1
  632. package/dist/utils/json.d.ts.map +1 -1
  633. package/dist/utils/json.js.map +1 -1
  634. package/dist/utils/management-http.d.ts.map +1 -1
  635. package/dist/utils/management-http.js.map +1 -1
  636. package/dist/utils/mime.d.ts.map +1 -1
  637. package/dist/utils/mime.js +1 -1
  638. package/dist/utils/mime.js.map +1 -1
  639. package/dist/utils/oklab.d.ts +43 -0
  640. package/dist/utils/oklab.d.ts.map +1 -0
  641. package/dist/utils/oklab.js +210 -0
  642. package/dist/utils/oklab.js.map +1 -0
  643. package/dist/utils/open-browser.d.ts.map +1 -1
  644. package/dist/utils/open-browser.js.map +1 -1
  645. package/dist/utils/output-files.d.ts +15 -0
  646. package/dist/utils/output-files.d.ts.map +1 -0
  647. package/dist/utils/output-files.js +30 -0
  648. package/dist/utils/output-files.js.map +1 -0
  649. package/dist/utils/paths.d.ts +3 -3
  650. package/dist/utils/paths.d.ts.map +1 -1
  651. package/dist/utils/paths.js +5 -4
  652. package/dist/utils/paths.js.map +1 -1
  653. package/dist/utils/photon.d.ts.map +1 -1
  654. package/dist/utils/photon.js.map +1 -1
  655. package/dist/utils/pi-user-agent.d.ts.map +1 -1
  656. package/dist/utils/pi-user-agent.js.map +1 -1
  657. package/dist/utils/shell.d.ts +1 -3
  658. package/dist/utils/shell.d.ts.map +1 -1
  659. package/dist/utils/shell.js +3 -30
  660. package/dist/utils/shell.js.map +1 -1
  661. package/dist/utils/sleep.d.ts.map +1 -1
  662. package/dist/utils/sleep.js.map +1 -1
  663. package/dist/utils/syntax-highlight.d.ts.map +1 -1
  664. package/dist/utils/syntax-highlight.js +8 -1
  665. package/dist/utils/syntax-highlight.js.map +1 -1
  666. package/dist/utils/text.d.ts.map +1 -1
  667. package/dist/utils/text.js.map +1 -1
  668. package/dist/utils/tool-result-images.d.ts +3 -1
  669. package/dist/utils/tool-result-images.d.ts.map +1 -1
  670. package/dist/utils/tool-result-images.js +4 -1
  671. package/dist/utils/tool-result-images.js.map +1 -1
  672. package/dist/utils/tools-manager.d.ts.map +1 -1
  673. package/dist/utils/tools-manager.js.map +1 -1
  674. package/dist/utils/version-check.d.ts.map +1 -1
  675. package/dist/utils/version-check.js.map +1 -1
  676. package/dist/utils/windows-self-update.d.ts.map +1 -1
  677. package/dist/utils/windows-self-update.js.map +1 -1
  678. package/dist/utils/wsl.d.ts +3 -0
  679. package/dist/utils/wsl.d.ts.map +1 -0
  680. package/dist/utils/wsl.js +15 -0
  681. package/dist/utils/wsl.js.map +1 -0
  682. package/dist/utils/zip.d.ts +7 -0
  683. package/dist/utils/zip.d.ts.map +1 -0
  684. package/dist/utils/zip.js +60 -0
  685. package/dist/utils/zip.js.map +1 -0
  686. package/docs/cli-integration.md +106 -0
  687. package/docs/cli.md +333 -0
  688. package/docs/codemode.md +230 -0
  689. package/docs/compaction.md +47 -28
  690. package/docs/configuration.md +47 -0
  691. package/docs/containerization.md +109 -82
  692. package/docs/custom-provider.md +109 -713
  693. package/docs/docs.json +148 -96
  694. package/docs/environment-variables.md +18 -3
  695. package/docs/extensions.md +284 -604
  696. package/docs/how-pi-works.md +49 -0
  697. package/docs/images/interactive-mode.png +0 -0
  698. package/docs/index.md +24 -69
  699. package/docs/json.md +193 -65
  700. package/docs/keybindings.md +58 -103
  701. package/docs/llama-cpp.md +24 -4
  702. package/docs/mcp.md +272 -0
  703. package/docs/message-types.md +279 -0
  704. package/docs/models.md +124 -489
  705. package/docs/nvidia-rtx-llama-cpp.md +96 -0
  706. package/docs/packages.md +67 -166
  707. package/docs/prompt-templates.md +31 -68
  708. package/docs/providers.md +158 -228
  709. package/docs/quickstart.md +61 -106
  710. package/docs/rpc-commands.md +860 -0
  711. package/docs/rpc-extension-ui.md +200 -0
  712. package/docs/rpc.md +131 -1554
  713. package/docs/sdk.md +79 -1158
  714. package/docs/security.md +72 -32
  715. package/docs/session-format.md +58 -215
  716. package/docs/sessions.md +35 -114
  717. package/docs/settings.md +98 -326
  718. package/docs/shell-aliases.md +85 -5
  719. package/docs/skills.md +51 -190
  720. package/docs/slash-commands.md +60 -0
  721. package/docs/subagents.md +2 -0
  722. package/docs/terminal-setup.md +7 -182
  723. package/docs/termux.md +74 -83
  724. package/docs/themes.md +89 -273
  725. package/docs/tmux.md +31 -39
  726. package/docs/tui.md +74 -910
  727. package/docs/usage.md +52 -129
  728. package/docs/virtual-models.md +114 -0
  729. package/docs/windows.md +45 -17
  730. package/examples/README.md +13 -5
  731. package/examples/extensions/README.md +4 -30
  732. package/examples/extensions/custom-provider-anthropic/index.ts +18 -12
  733. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  734. package/examples/extensions/custom-provider-anthropic/package.json +17 -17
  735. package/examples/extensions/custom-provider-gitlab-duo/index.ts +2 -2
  736. package/examples/extensions/custom-provider-gitlab-duo/package.json +14 -14
  737. package/examples/extensions/custom-provider-gitlab-duo/test.ts +5 -5
  738. package/examples/extensions/debug-provider.ts +69 -0
  739. package/examples/extensions/dynamic-resources/dynamic.json +1 -1
  740. package/examples/extensions/gondolin/package-lock.json +5 -5
  741. package/examples/extensions/gondolin/package.json +1 -1
  742. package/examples/extensions/jev-router.ts +113 -0
  743. package/examples/extensions/prompt-customizer.ts +19 -67
  744. package/examples/extensions/sandbox/package-lock.json +2 -2
  745. package/examples/extensions/sandbox/package.json +1 -1
  746. package/examples/extensions/with-deps/package-lock.json +2 -2
  747. package/examples/extensions/with-deps/package.json +20 -20
  748. package/examples/rpc-client.ts +35 -0
  749. package/examples/sdk/14-codemode-mcp.ts +61 -0
  750. package/examples/sdk/README.md +3 -2
  751. package/npm-shrinkwrap.json +2425 -0
  752. package/package.json +20 -29
  753. package/schemas/models.schema.json +1157 -0
  754. package/schemas/settings.schema.json +734 -0
  755. package/schemas/theme.schema.json +365 -0
  756. package/dist/bundle/chunks/anthropic-messages-ASRU76PT.js +0 -6
  757. package/dist/bundle/chunks/azure-openai-responses-UGF6LMEX.js +0 -2
  758. package/dist/bundle/chunks/chunk-5PRUVL6W.js +0 -1770
  759. package/dist/bundle/chunks/chunk-6R7UI4IY.js +0 -2
  760. package/dist/bundle/chunks/chunk-A3JYRWB6.js +0 -2
  761. package/dist/bundle/chunks/chunk-CHB3CEFP.js +0 -2
  762. package/dist/bundle/chunks/chunk-ELBMWBDG.js +0 -11
  763. package/dist/bundle/chunks/chunk-GMWCTUPB.js +0 -2
  764. package/dist/bundle/chunks/chunk-GTBU4EAF.js +0 -2
  765. package/dist/bundle/chunks/chunk-NUHFSC37.js +0 -25
  766. package/dist/bundle/chunks/chunk-UIWY7TU5.js +0 -42
  767. package/dist/bundle/chunks/chunk-XNGRGP62.js +0 -2
  768. package/dist/bundle/chunks/google-generative-ai-VCD2PGIY.js +0 -2
  769. package/dist/bundle/chunks/google-vertex-L6U34ZRC.js +0 -2
  770. package/dist/bundle/chunks/mistral-conversations-IXWQ2YKN.js +0 -5
  771. package/dist/bundle/chunks/node-5YXRXMVN.js +0 -16
  772. package/dist/bundle/chunks/openai-codex-responses-P7HKQLIT.js +0 -10
  773. package/dist/bundle/chunks/openai-completions-O7BFLP3U.js +0 -7
  774. package/dist/bundle/chunks/openai-responses-QAKWAYVG.js +0 -2
  775. package/dist/cli/config-selector.d.ts +0 -16
  776. package/dist/cli/config-selector.d.ts.map +0 -1
  777. package/dist/cli/config-selector.js +0 -32
  778. package/dist/cli/config-selector.js.map +0 -1
  779. package/dist/cli/session-picker.d.ts +0 -10
  780. package/dist/cli/session-picker.d.ts.map +0 -1
  781. package/dist/cli/session-picker.js +0 -36
  782. package/dist/cli/session-picker.js.map +0 -1
  783. package/dist/cli/startup-ui.d.ts +0 -20
  784. package/dist/cli/startup-ui.d.ts.map +0 -1
  785. package/dist/cli/startup-ui.js +0 -185
  786. package/dist/cli/startup-ui.js.map +0 -1
  787. package/dist/core/keybindings.d.ts +0 -428
  788. package/dist/core/keybindings.d.ts.map +0 -1
  789. package/dist/core/keybindings.js +0 -321
  790. package/dist/core/keybindings.js.map +0 -1
  791. package/dist/core/tools/render-utils.d.ts +0 -24
  792. package/dist/core/tools/render-utils.d.ts.map +0 -1
  793. package/dist/core/tools/render-utils.js +0 -65
  794. package/dist/core/tools/render-utils.js.map +0 -1
  795. package/dist/core/tools/renderers/bash.d.ts +0 -12
  796. package/dist/core/tools/renderers/bash.d.ts.map +0 -1
  797. package/dist/core/tools/renderers/bash.js +0 -130
  798. package/dist/core/tools/renderers/bash.js.map +0 -1
  799. package/dist/core/tools/renderers/edit.d.ts +0 -23
  800. package/dist/core/tools/renderers/edit.d.ts.map +0 -1
  801. package/dist/core/tools/renderers/edit.js +0 -167
  802. package/dist/core/tools/renderers/edit.js.map +0 -1
  803. package/dist/core/tools/renderers/find.d.ts +0 -10
  804. package/dist/core/tools/renderers/find.d.ts.map +0 -1
  805. package/dist/core/tools/renderers/find.js +0 -64
  806. package/dist/core/tools/renderers/find.js.map +0 -1
  807. package/dist/core/tools/renderers/grep.d.ts +0 -10
  808. package/dist/core/tools/renderers/grep.d.ts.map +0 -1
  809. package/dist/core/tools/renderers/grep.js +0 -69
  810. package/dist/core/tools/renderers/grep.js.map +0 -1
  811. package/dist/core/tools/renderers/index.d.ts +0 -28
  812. package/dist/core/tools/renderers/index.d.ts.map +0 -1
  813. package/dist/core/tools/renderers/index.js +0 -47
  814. package/dist/core/tools/renderers/index.js.map +0 -1
  815. package/dist/core/tools/renderers/ls.d.ts +0 -10
  816. package/dist/core/tools/renderers/ls.d.ts.map +0 -1
  817. package/dist/core/tools/renderers/ls.js +0 -58
  818. package/dist/core/tools/renderers/ls.js.map +0 -1
  819. package/dist/core/tools/renderers/read.d.ts +0 -11
  820. package/dist/core/tools/renderers/read.d.ts.map +0 -1
  821. package/dist/core/tools/renderers/read.js +0 -129
  822. package/dist/core/tools/renderers/read.js.map +0 -1
  823. package/dist/core/tools/renderers/write.d.ts +0 -10
  824. package/dist/core/tools/renderers/write.d.ts.map +0 -1
  825. package/dist/core/tools/renderers/write.js +0 -153
  826. package/dist/core/tools/renderers/write.js.map +0 -1
  827. package/dist/extensions/mcp/mcp-client.d.ts +0 -31
  828. package/dist/extensions/mcp/mcp-client.d.ts.map +0 -1
  829. package/dist/extensions/mcp/mcp-client.js +0 -149
  830. package/dist/extensions/mcp/mcp-client.js.map +0 -1
  831. package/dist/extensions/mcp/mcp-config.d.ts +0 -47
  832. package/dist/extensions/mcp/mcp-config.d.ts.map +0 -1
  833. package/dist/extensions/mcp/mcp-config.js +0 -281
  834. package/dist/extensions/mcp/mcp-config.js.map +0 -1
  835. package/dist/extensions/mcp/mcp-transport.d.ts +0 -65
  836. package/dist/extensions/mcp/mcp-transport.d.ts.map +0 -1
  837. package/dist/extensions/mcp/mcp-transport.js +0 -278
  838. package/dist/extensions/mcp/mcp-transport.js.map +0 -1
  839. package/dist/modes/interactive/assets/clankolas.png +0 -0
  840. package/dist/modes/interactive/chat-viewport.d.ts +0 -20
  841. package/dist/modes/interactive/chat-viewport.d.ts.map +0 -1
  842. package/dist/modes/interactive/chat-viewport.js +0 -28
  843. package/dist/modes/interactive/chat-viewport.js.map +0 -1
  844. package/dist/modes/interactive/components/armin.d.ts +0 -34
  845. package/dist/modes/interactive/components/armin.d.ts.map +0 -1
  846. package/dist/modes/interactive/components/armin.js +0 -333
  847. package/dist/modes/interactive/components/armin.js.map +0 -1
  848. package/dist/modes/interactive/components/assistant-message.d.ts +0 -26
  849. package/dist/modes/interactive/components/assistant-message.d.ts.map +0 -1
  850. package/dist/modes/interactive/components/assistant-message.js +0 -158
  851. package/dist/modes/interactive/components/assistant-message.js.map +0 -1
  852. package/dist/modes/interactive/components/bash-execution.d.ts +0 -34
  853. package/dist/modes/interactive/components/bash-execution.d.ts.map +0 -1
  854. package/dist/modes/interactive/components/bash-execution.js +0 -175
  855. package/dist/modes/interactive/components/bash-execution.js.map +0 -1
  856. package/dist/modes/interactive/components/bordered-loader.d.ts +0 -16
  857. package/dist/modes/interactive/components/bordered-loader.d.ts.map +0 -1
  858. package/dist/modes/interactive/components/bordered-loader.js +0 -54
  859. package/dist/modes/interactive/components/bordered-loader.js.map +0 -1
  860. package/dist/modes/interactive/components/branch-summary-message.d.ts +0 -16
  861. package/dist/modes/interactive/components/branch-summary-message.d.ts.map +0 -1
  862. package/dist/modes/interactive/components/branch-summary-message.js +0 -44
  863. package/dist/modes/interactive/components/branch-summary-message.js.map +0 -1
  864. package/dist/modes/interactive/components/compaction-summary-message.d.ts +0 -16
  865. package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +0 -1
  866. package/dist/modes/interactive/components/compaction-summary-message.js +0 -45
  867. package/dist/modes/interactive/components/compaction-summary-message.js.map +0 -1
  868. package/dist/modes/interactive/components/config-selector.d.ts +0 -102
  869. package/dist/modes/interactive/components/config-selector.d.ts.map +0 -1
  870. package/dist/modes/interactive/components/config-selector.js +0 -761
  871. package/dist/modes/interactive/components/config-selector.js.map +0 -1
  872. package/dist/modes/interactive/components/countdown-timer.d.ts +0 -14
  873. package/dist/modes/interactive/components/countdown-timer.d.ts.map +0 -1
  874. package/dist/modes/interactive/components/countdown-timer.js +0 -33
  875. package/dist/modes/interactive/components/countdown-timer.js.map +0 -1
  876. package/dist/modes/interactive/components/custom-editor.d.ts +0 -30
  877. package/dist/modes/interactive/components/custom-editor.d.ts.map +0 -1
  878. package/dist/modes/interactive/components/custom-editor.js +0 -115
  879. package/dist/modes/interactive/components/custom-editor.js.map +0 -1
  880. package/dist/modes/interactive/components/custom-entry.d.ts +0 -19
  881. package/dist/modes/interactive/components/custom-entry.d.ts.map +0 -1
  882. package/dist/modes/interactive/components/custom-entry.js +0 -52
  883. package/dist/modes/interactive/components/custom-entry.js.map +0 -1
  884. package/dist/modes/interactive/components/custom-message.d.ts +0 -22
  885. package/dist/modes/interactive/components/custom-message.d.ts.map +0 -1
  886. package/dist/modes/interactive/components/custom-message.js +0 -87
  887. package/dist/modes/interactive/components/custom-message.js.map +0 -1
  888. package/dist/modes/interactive/components/daxnuts.d.ts +0 -23
  889. package/dist/modes/interactive/components/daxnuts.d.ts.map +0 -1
  890. package/dist/modes/interactive/components/daxnuts.js +0 -140
  891. package/dist/modes/interactive/components/daxnuts.js.map +0 -1
  892. package/dist/modes/interactive/components/diff.d.ts +0 -12
  893. package/dist/modes/interactive/components/diff.d.ts.map +0 -1
  894. package/dist/modes/interactive/components/diff.js +0 -133
  895. package/dist/modes/interactive/components/diff.js.map +0 -1
  896. package/dist/modes/interactive/components/dynamic-border.d.ts +0 -15
  897. package/dist/modes/interactive/components/dynamic-border.d.ts.map +0 -1
  898. package/dist/modes/interactive/components/dynamic-border.js +0 -21
  899. package/dist/modes/interactive/components/dynamic-border.js.map +0 -1
  900. package/dist/modes/interactive/components/earendil-announcement.d.ts +0 -5
  901. package/dist/modes/interactive/components/earendil-announcement.d.ts.map +0 -1
  902. package/dist/modes/interactive/components/earendil-announcement.js +0 -40
  903. package/dist/modes/interactive/components/earendil-announcement.js.map +0 -1
  904. package/dist/modes/interactive/components/extension-editor.d.ts +0 -21
  905. package/dist/modes/interactive/components/extension-editor.d.ts.map +0 -1
  906. package/dist/modes/interactive/components/extension-editor.js +0 -98
  907. package/dist/modes/interactive/components/extension-editor.js.map +0 -1
  908. package/dist/modes/interactive/components/extension-input.d.ts +0 -23
  909. package/dist/modes/interactive/components/extension-input.d.ts.map +0 -1
  910. package/dist/modes/interactive/components/extension-input.js +0 -61
  911. package/dist/modes/interactive/components/extension-input.js.map +0 -1
  912. package/dist/modes/interactive/components/extension-selector.d.ts +0 -26
  913. package/dist/modes/interactive/components/extension-selector.d.ts.map +0 -1
  914. package/dist/modes/interactive/components/extension-selector.js +0 -83
  915. package/dist/modes/interactive/components/extension-selector.js.map +0 -1
  916. package/dist/modes/interactive/components/first-time-setup.d.ts +0 -25
  917. package/dist/modes/interactive/components/first-time-setup.d.ts.map +0 -1
  918. package/dist/modes/interactive/components/first-time-setup.js +0 -103
  919. package/dist/modes/interactive/components/first-time-setup.js.map +0 -1
  920. package/dist/modes/interactive/components/footer.d.ts +0 -32
  921. package/dist/modes/interactive/components/footer.d.ts.map +0 -1
  922. package/dist/modes/interactive/components/footer.js +0 -222
  923. package/dist/modes/interactive/components/footer.js.map +0 -1
  924. package/dist/modes/interactive/components/index.d.ts +0 -34
  925. package/dist/modes/interactive/components/index.d.ts.map +0 -1
  926. package/dist/modes/interactive/components/index.js +0 -35
  927. package/dist/modes/interactive/components/index.js.map +0 -1
  928. package/dist/modes/interactive/components/keybinding-hints.d.ts +0 -13
  929. package/dist/modes/interactive/components/keybinding-hints.d.ts.map +0 -1
  930. package/dist/modes/interactive/components/keybinding-hints.js +0 -36
  931. package/dist/modes/interactive/components/keybinding-hints.js.map +0 -1
  932. package/dist/modes/interactive/components/login-dialog.d.ts +0 -52
  933. package/dist/modes/interactive/components/login-dialog.d.ts.map +0 -1
  934. package/dist/modes/interactive/components/login-dialog.js +0 -188
  935. package/dist/modes/interactive/components/login-dialog.js.map +0 -1
  936. package/dist/modes/interactive/components/markdown-transform.d.ts +0 -3
  937. package/dist/modes/interactive/components/markdown-transform.d.ts.map +0 -1
  938. package/dist/modes/interactive/components/markdown-transform.js +0 -19
  939. package/dist/modes/interactive/components/markdown-transform.js.map +0 -1
  940. package/dist/modes/interactive/components/mermaid.d.ts +0 -11
  941. package/dist/modes/interactive/components/mermaid.d.ts.map +0 -1
  942. package/dist/modes/interactive/components/mermaid.js +0 -75
  943. package/dist/modes/interactive/components/mermaid.js.map +0 -1
  944. package/dist/modes/interactive/components/model-selector.d.ts +0 -60
  945. package/dist/modes/interactive/components/model-selector.d.ts.map +0 -1
  946. package/dist/modes/interactive/components/model-selector.js +0 -361
  947. package/dist/modes/interactive/components/model-selector.js.map +0 -1
  948. package/dist/modes/interactive/components/oauth-selector.d.ts +0 -33
  949. package/dist/modes/interactive/components/oauth-selector.d.ts.map +0 -1
  950. package/dist/modes/interactive/components/oauth-selector.js +0 -163
  951. package/dist/modes/interactive/components/oauth-selector.js.map +0 -1
  952. package/dist/modes/interactive/components/question-selector.d.ts +0 -24
  953. package/dist/modes/interactive/components/question-selector.d.ts.map +0 -1
  954. package/dist/modes/interactive/components/question-selector.js +0 -158
  955. package/dist/modes/interactive/components/question-selector.js.map +0 -1
  956. package/dist/modes/interactive/components/scoped-models-selector.d.ts +0 -46
  957. package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +0 -1
  958. package/dist/modes/interactive/components/scoped-models-selector.js +0 -326
  959. package/dist/modes/interactive/components/scoped-models-selector.js.map +0 -1
  960. package/dist/modes/interactive/components/session-selector-search.d.ts +0 -23
  961. package/dist/modes/interactive/components/session-selector-search.d.ts.map +0 -1
  962. package/dist/modes/interactive/components/session-selector-search.js +0 -155
  963. package/dist/modes/interactive/components/session-selector-search.js.map +0 -1
  964. package/dist/modes/interactive/components/session-selector.d.ts +0 -95
  965. package/dist/modes/interactive/components/session-selector.d.ts.map +0 -1
  966. package/dist/modes/interactive/components/session-selector.js +0 -867
  967. package/dist/modes/interactive/components/session-selector.js.map +0 -1
  968. package/dist/modes/interactive/components/settings-selector.d.ts +0 -92
  969. package/dist/modes/interactive/components/settings-selector.d.ts.map +0 -1
  970. package/dist/modes/interactive/components/settings-selector.js +0 -709
  971. package/dist/modes/interactive/components/settings-selector.js.map +0 -1
  972. package/dist/modes/interactive/components/settings-submenu.d.ts +0 -72
  973. package/dist/modes/interactive/components/settings-submenu.d.ts.map +0 -1
  974. package/dist/modes/interactive/components/settings-submenu.js +0 -165
  975. package/dist/modes/interactive/components/settings-submenu.js.map +0 -1
  976. package/dist/modes/interactive/components/show-images-selector.d.ts +0 -10
  977. package/dist/modes/interactive/components/show-images-selector.d.ts.map +0 -1
  978. package/dist/modes/interactive/components/show-images-selector.js +0 -39
  979. package/dist/modes/interactive/components/show-images-selector.js.map +0 -1
  980. package/dist/modes/interactive/components/skill-invocation-message.d.ts +0 -17
  981. package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +0 -1
  982. package/dist/modes/interactive/components/skill-invocation-message.js +0 -47
  983. package/dist/modes/interactive/components/skill-invocation-message.js.map +0 -1
  984. package/dist/modes/interactive/components/status-indicator.d.ts +0 -30
  985. package/dist/modes/interactive/components/status-indicator.d.ts.map +0 -1
  986. package/dist/modes/interactive/components/status-indicator.js +0 -67
  987. package/dist/modes/interactive/components/status-indicator.js.map +0 -1
  988. package/dist/modes/interactive/components/theme-selector.d.ts +0 -11
  989. package/dist/modes/interactive/components/theme-selector.d.ts.map +0 -1
  990. package/dist/modes/interactive/components/theme-selector.js +0 -50
  991. package/dist/modes/interactive/components/theme-selector.js.map +0 -1
  992. package/dist/modes/interactive/components/thinking-selector.d.ts +0 -23
  993. package/dist/modes/interactive/components/thinking-selector.d.ts.map +0 -1
  994. package/dist/modes/interactive/components/thinking-selector.js +0 -109
  995. package/dist/modes/interactive/components/thinking-selector.js.map +0 -1
  996. package/dist/modes/interactive/components/tool-execution.d.ts +0 -80
  997. package/dist/modes/interactive/components/tool-execution.d.ts.map +0 -1
  998. package/dist/modes/interactive/components/tool-execution.js +0 -328
  999. package/dist/modes/interactive/components/tool-execution.js.map +0 -1
  1000. package/dist/modes/interactive/components/tree-selector.d.ts +0 -94
  1001. package/dist/modes/interactive/components/tree-selector.d.ts.map +0 -1
  1002. package/dist/modes/interactive/components/tree-selector.js +0 -1245
  1003. package/dist/modes/interactive/components/tree-selector.js.map +0 -1
  1004. package/dist/modes/interactive/components/trust-selector.d.ts +0 -23
  1005. package/dist/modes/interactive/components/trust-selector.d.ts.map +0 -1
  1006. package/dist/modes/interactive/components/trust-selector.js +0 -91
  1007. package/dist/modes/interactive/components/trust-selector.js.map +0 -1
  1008. package/dist/modes/interactive/components/user-message-selector.d.ts +0 -30
  1009. package/dist/modes/interactive/components/user-message-selector.d.ts.map +0 -1
  1010. package/dist/modes/interactive/components/user-message-selector.js +0 -114
  1011. package/dist/modes/interactive/components/user-message-selector.js.map +0 -1
  1012. package/dist/modes/interactive/components/user-message.d.ts +0 -16
  1013. package/dist/modes/interactive/components/user-message.d.ts.map +0 -1
  1014. package/dist/modes/interactive/components/user-message.js +0 -49
  1015. package/dist/modes/interactive/components/user-message.js.map +0 -1
  1016. package/dist/modes/interactive/components/visual-truncate.d.ts +0 -24
  1017. package/dist/modes/interactive/components/visual-truncate.d.ts.map +0 -1
  1018. package/dist/modes/interactive/components/visual-truncate.js +0 -33
  1019. package/dist/modes/interactive/components/visual-truncate.js.map +0 -1
  1020. package/dist/modes/interactive/external-editor.d.ts +0 -12
  1021. package/dist/modes/interactive/external-editor.d.ts.map +0 -1
  1022. package/dist/modes/interactive/external-editor.js +0 -38
  1023. package/dist/modes/interactive/external-editor.js.map +0 -1
  1024. package/dist/modes/interactive/interactive-mode.d.ts +0 -443
  1025. package/dist/modes/interactive/interactive-mode.d.ts.map +0 -1
  1026. package/dist/modes/interactive/interactive-mode.js +0 -5604
  1027. package/dist/modes/interactive/interactive-mode.js.map +0 -1
  1028. package/dist/modes/interactive/model-catalog-refresh.d.ts.map +0 -1
  1029. package/dist/modes/interactive/model-catalog-refresh.js.map +0 -1
  1030. package/dist/modes/interactive/model-search.d.ts +0 -12
  1031. package/dist/modes/interactive/model-search.d.ts.map +0 -1
  1032. package/dist/modes/interactive/model-search.js +0 -15
  1033. package/dist/modes/interactive/model-search.js.map +0 -1
  1034. package/dist/modes/interactive/session-share.d.ts +0 -16
  1035. package/dist/modes/interactive/session-share.d.ts.map +0 -1
  1036. package/dist/modes/interactive/session-share.js +0 -184
  1037. package/dist/modes/interactive/session-share.js.map +0 -1
  1038. package/dist/modes/interactive/theme/dark.json +0 -91
  1039. package/dist/modes/interactive/theme/light.json +0 -90
  1040. package/dist/modes/interactive/theme/theme-controller.d.ts +0 -41
  1041. package/dist/modes/interactive/theme/theme-controller.d.ts.map +0 -1
  1042. package/dist/modes/interactive/theme/theme-controller.js +0 -130
  1043. package/dist/modes/interactive/theme/theme-controller.js.map +0 -1
  1044. package/dist/modes/interactive/theme/theme-json.d.ts +0 -84
  1045. package/dist/modes/interactive/theme/theme-json.d.ts.map +0 -1
  1046. package/dist/modes/interactive/theme/theme-json.js +0 -130
  1047. package/dist/modes/interactive/theme/theme-json.js.map +0 -1
  1048. package/dist/modes/interactive/theme/theme-schema.json +0 -356
  1049. package/dist/modes/interactive/theme/theme.d.ts +0 -131
  1050. package/dist/modes/interactive/theme/theme.d.ts.map +0 -1
  1051. package/dist/modes/interactive/theme/theme.js.map +0 -1
  1052. package/dist/modes/interactive/tui-renderer.d.ts +0 -21
  1053. package/dist/modes/interactive/tui-renderer.d.ts.map +0 -1
  1054. package/dist/modes/interactive/tui-renderer.js +0 -66
  1055. package/dist/modes/interactive/tui-renderer.js.map +0 -1
  1056. package/docs/development.md +0 -90
  1057. package/examples/extensions/border-status-editor.ts +0 -145
  1058. package/examples/extensions/built-in-tool-renderer.ts +0 -249
  1059. package/examples/extensions/custom-footer.ts +0 -64
  1060. package/examples/extensions/custom-header.ts +0 -73
  1061. package/examples/extensions/doom-overlay/README.md +0 -46
  1062. package/examples/extensions/doom-overlay/doom/build/doom.js +0 -21
  1063. package/examples/extensions/doom-overlay/doom/build/doom.wasm +0 -0
  1064. package/examples/extensions/doom-overlay/doom/build.sh +0 -152
  1065. package/examples/extensions/doom-overlay/doom/doomgeneric_pi.c +0 -72
  1066. package/examples/extensions/doom-overlay/doom-component.ts +0 -132
  1067. package/examples/extensions/doom-overlay/doom-engine.ts +0 -173
  1068. package/examples/extensions/doom-overlay/doom-keys.ts +0 -104
  1069. package/examples/extensions/doom-overlay/index.ts +0 -74
  1070. package/examples/extensions/doom-overlay/wad-finder.ts +0 -55
  1071. package/examples/extensions/entry-renderer.ts +0 -41
  1072. package/examples/extensions/github-issue-autocomplete.ts +0 -185
  1073. package/examples/extensions/handoff.ts +0 -190
  1074. package/examples/extensions/interactive-shell.ts +0 -196
  1075. package/examples/extensions/kimi-deferred-tools.ts +0 -61
  1076. package/examples/extensions/message-renderer.ts +0 -59
  1077. package/examples/extensions/minimal-mode.ts +0 -426
  1078. package/examples/extensions/modal-editor.ts +0 -85
  1079. package/examples/extensions/overlay-qa-tests.ts +0 -1450
  1080. package/examples/extensions/overlay-test.ts +0 -153
  1081. package/examples/extensions/plan-mode/README.md +0 -66
  1082. package/examples/extensions/plan-mode/index.ts +0 -390
  1083. package/examples/extensions/plan-mode/utils.ts +0 -168
  1084. package/examples/extensions/preset.ts +0 -436
  1085. package/examples/extensions/qna.ts +0 -118
  1086. package/examples/extensions/question.ts +0 -278
  1087. package/examples/extensions/questionnaire.ts +0 -440
  1088. package/examples/extensions/rainbow-editor.ts +0 -88
  1089. package/examples/extensions/snake.ts +0 -343
  1090. package/examples/extensions/space-invaders.ts +0 -560
  1091. package/examples/extensions/structured-output.ts +0 -65
  1092. package/examples/extensions/summarize.ts +0 -199
  1093. package/examples/extensions/tic-tac-toe.ts +0 -1008
  1094. package/examples/extensions/todo.ts +0 -297
  1095. package/examples/extensions/tools.ts +0 -146
  1096. package/examples/extensions/truncated-tool.ts +0 -195
  1097. package/examples/plugins/pi-example-plugin/README.md +0 -38
  1098. package/examples/plugins/pi-example-plugin/package.json +0 -10
  1099. package/examples/plugins/pi-example-plugin/src/contract.ts +0 -13
  1100. package/examples/plugins/pi-example-plugin/src/session.ts +0 -23
  1101. package/examples/plugins/pi-example-plugin/src/tui.ts +0 -31
  1102. package/examples/rpc-extension-ui.ts +0 -641
  1103. /package/dist/bundle/chunks/{chunk-PATAL4PO.js → chunk-7ZC4UXSL.js} +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"powershell.js","sourceRoot":"","sources":["../../../src/core/tools/powershell.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAQN,0BAA0B,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ACnB,aAAa,EAAE,UAAU,CAAC,aAAa;QACvC,gBAAgB,EAAE,UAAU,CAAC,gBAAgB;KAC7C,CAAC,CAAC;IACH,OAAO,IAAI,CAAC;AAAA,CACZ","sourcesContent":["import { getPowerShellConfig } from \"../../utils/shell.ts\";\nimport {\n\ttype BashOperations,\n\ttype BashSpawnContext,\n\ttype BashSpawnHook,\n\ttype BashToolDetails,\n\ttype BashToolInput,\n\ttype BashToolOptions,\n\ttype createBashTool,\n\tcreateLocalShellOperations,\n\tcreateShellToolDefinition,\n\ttype ShellToolConfig,\n} from \"./bash.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\n\nconst UTF8_OUTPUT_PREFIX = \"try { [Console]::OutputEncoding=[System.Text.Encoding]::UTF8 } catch {}\\n\";\n\nexport const powershellToolSystemPromptContribution = {\n\tsnippet: \"Execute PowerShell commands\",\n\tguidelines: [\"You can inspect PI_* environment variables for current model and session details.\"],\n} as const;\n\nexport type PowerShellOperations = BashOperations;\nexport type PowerShellSpawnContext = BashSpawnContext;\nexport type PowerShellSpawnHook = BashSpawnHook;\nexport type PowerShellToolDetails = BashToolDetails;\nexport type PowerShellToolInput = BashToolInput;\n\nexport interface PowerShellToolOptions\n\textends Pick<BashToolOptions, \"operations\" | \"exposeSessionEnvironment\" | \"spawnHook\"> {}\n\nexport function createLocalPowerShellOperations(): PowerShellOperations {\n\tconst operations = createLocalShellOperations(\"PowerShell\", getPowerShellConfig);\n\treturn {\n\t\texec: (command, cwd, options) => operations.exec(`${UTF8_OUTPUT_PREFIX}${command}`, cwd, options),\n\t};\n}\n\nconst powershellToolConfig: ShellToolConfig = {\n\tname: \"powershell\",\n\tlabel: \"powershell\",\n\tshellName: \"PowerShell\",\n\tprompt: \"PS>\",\n\tpromptSnippet: powershellToolSystemPromptContribution.snippet,\n\tpromptGuidelines: powershellToolSystemPromptContribution.guidelines,\n\ttempFilePrefix: \"pi-powershell\",\n};\n\nexport function createPowerShellToolDefinition(\n\tcwd: string,\n\toptions?: PowerShellToolOptions,\n): ReturnType<typeof createShellToolDefinition> {\n\treturn createShellToolDefinition(cwd, powershellToolConfig, {\n\t\t...options,\n\t\toperations: options?.operations ?? createLocalPowerShellOperations(),\n\t});\n}\n\nexport function createPowerShellTool(cwd: string, options?: PowerShellToolOptions): ReturnType<typeof createBashTool> {\n\tconst definition = createPowerShellToolDefinition(cwd, options);\n\tconst tool = wrapToolDefinition(definition);\n\tObject.assign(tool, {\n\t\tpromptSnippet: definition.promptSnippet,\n\t\tpromptGuidelines: definition.promptGuidelines,\n\t});\n\treturn tool;\n}\n"]}
1
+ {"version":3,"file":"powershell.js","sourceRoot":"","sources":["../../../src/core/tools/powershell.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAQN,0BAA0B,EAC1B,yBAAyB,GAEzB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAElE,MAAM,kBAAkB,GAAG,2EAA2E,CAAC;AAEvG,MAAM,CAAC,MAAM,sCAAsC,GAAG;IACrD,OAAO,EAAE,6BAA6B;IACtC,UAAU,EAAE,CAAC,mFAAmF,CAAC;CACxF,CAAC;AAWX,MAAM,UAAU,+BAA+B;IAC9C,MAAM,UAAU,GAAG,0BAA0B,CAAC,YAAY,EAAE,mBAAmB,CAAC,CAAC;IACjF,OAAO;QACN,IAAI,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,kBAAkB,GAAG,OAAO,EAAE,EAAE,GAAG,EAAE,OAAO,CAAC;KACjG,CAAC;AACH,CAAC;AAED,MAAM,oBAAoB,GAAoB;IAC7C,IAAI,EAAE,YAAY;IAClB,KAAK,EAAE,YAAY;IACnB,SAAS,EAAE,YAAY;IACvB,MAAM,EAAE,KAAK;IACb,aAAa,EAAE,sCAAsC,CAAC,OAAO;IAC7D,gBAAgB,EAAE,sCAAsC,CAAC,UAAU;IACnE,cAAc,EAAE,eAAe;CAC/B,CAAC;AAEF,MAAM,UAAU,8BAA8B,CAC7C,GAAW,EACX,OAA+B;IAE/B,OAAO,yBAAyB,CAAC,GAAG,EAAE,oBAAoB,EAAE;QAC3D,GAAG,OAAO;QACV,UAAU,EAAE,OAAO,EAAE,UAAU,IAAI,+BAA+B,EAAE;KACpE,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,GAAW,EAAE,OAA+B;IAChF,MAAM,UAAU,GAAG,8BAA8B,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IAChE,MAAM,IAAI,GAAG,kBAAkB,CAAC,UAAU,CAAC,CAAC;IAC5C,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE;QACnB,aAAa,EAAE,UAAU,CAAC,aAAa;QACvC,gBAAgB,EAAE,UAAU,CAAC,gBAAgB;KAC7C,CAAC,CAAC;IACH,OAAO,IAAI,CAAC;AACb,CAAC","sourcesContent":["import { getPowerShellConfig } from \"../../utils/shell.ts\";\nimport {\n\ttype BashOperations,\n\ttype BashSpawnContext,\n\ttype BashSpawnHook,\n\ttype BashToolDetails,\n\ttype BashToolInput,\n\ttype BashToolOptions,\n\ttype createBashTool,\n\tcreateLocalShellOperations,\n\tcreateShellToolDefinition,\n\ttype ShellToolConfig,\n} from \"./bash.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\n\nconst UTF8_OUTPUT_PREFIX = \"try { [Console]::OutputEncoding=[System.Text.Encoding]::UTF8 } catch {}\\n\";\n\nexport const powershellToolSystemPromptContribution = {\n\tsnippet: \"Execute PowerShell commands\",\n\tguidelines: [\"You can inspect PI_* environment variables for current model and session details.\"],\n} as const;\n\nexport type PowerShellOperations = BashOperations;\nexport type PowerShellSpawnContext = BashSpawnContext;\nexport type PowerShellSpawnHook = BashSpawnHook;\nexport type PowerShellToolDetails = BashToolDetails;\nexport type PowerShellToolInput = BashToolInput;\n\nexport interface PowerShellToolOptions\n\textends Pick<BashToolOptions, \"operations\" | \"exposeSessionEnvironment\" | \"spawnHook\"> {}\n\nexport function createLocalPowerShellOperations(): PowerShellOperations {\n\tconst operations = createLocalShellOperations(\"PowerShell\", getPowerShellConfig);\n\treturn {\n\t\texec: (command, cwd, options) => operations.exec(`${UTF8_OUTPUT_PREFIX}${command}`, cwd, options),\n\t};\n}\n\nconst powershellToolConfig: ShellToolConfig = {\n\tname: \"powershell\",\n\tlabel: \"powershell\",\n\tshellName: \"PowerShell\",\n\tprompt: \"PS>\",\n\tpromptSnippet: powershellToolSystemPromptContribution.snippet,\n\tpromptGuidelines: powershellToolSystemPromptContribution.guidelines,\n\ttempFilePrefix: \"pi-powershell\",\n};\n\nexport function createPowerShellToolDefinition(\n\tcwd: string,\n\toptions?: PowerShellToolOptions,\n): ReturnType<typeof createShellToolDefinition> {\n\treturn createShellToolDefinition(cwd, powershellToolConfig, {\n\t\t...options,\n\t\toperations: options?.operations ?? createLocalPowerShellOperations(),\n\t});\n}\n\nexport function createPowerShellTool(cwd: string, options?: PowerShellToolOptions): ReturnType<typeof createBashTool> {\n\tconst definition = createPowerShellToolDefinition(cwd, options);\n\tconst tool = wrapToolDefinition(definition);\n\tObject.assign(tool, {\n\t\tpromptSnippet: definition.promptSnippet,\n\t\tpromptGuidelines: definition.promptGuidelines,\n\t});\n\treturn tool;\n}\n"]}
@@ -1,4 +1,5 @@
1
1
  import type { AgentTool } from "@punch-bot/agent";
2
+ import type { ModelImageResizeOptions } from "@punch-bot/ai";
2
3
  import { type Static, Type } from "typebox";
3
4
  import type { ToolDefinition } from "../extensions/types.ts";
4
5
  import { type TruncationResult } from "./truncate.ts";
@@ -12,6 +13,19 @@ export declare const readToolSystemPromptContribution: {
12
13
  readonly guidelines: readonly ["Use read to examine files instead of cat or sed."];
13
14
  };
14
15
  export type ReadToolInput = Static<typeof readSchema>;
16
+ /**
17
+ * Result for programmatic callers such as codemode scripts: the text for text files, and an image
18
+ * block for images that codemode's `image()` accepts. `note` is the text that goes with the image,
19
+ * such as resize hints. Property descriptions are left out so the type stays on one line in tool
20
+ * descriptions.
21
+ */
22
+ declare const readOutputSchema: Type.TUnion<[Type.TString, Type.TObject<{
23
+ type: Type.TLiteral<"image">;
24
+ data: Type.TString;
25
+ mimeType: Type.TString;
26
+ note: Type.TString;
27
+ }>]>;
28
+ export type ReadToolOutput = Static<typeof readOutputSchema>;
15
29
  export interface ReadToolDetails {
16
30
  truncation?: TruncationResult;
17
31
  }
@@ -28,8 +42,10 @@ export interface ReadOperations {
28
42
  detectImageMimeType?: (absolutePath: string) => Promise<string | null | undefined>;
29
43
  }
30
44
  export interface ReadToolOptions {
31
- /** Whether to auto-resize images to 2000x2000 max. Default: true */
45
+ /** Whether to auto-resize images. Default: true */
32
46
  autoResizeImages?: boolean;
47
+ /** Fallback resize profile when the execution context has no model metadata. */
48
+ resizeOptions?: ModelImageResizeOptions;
33
49
  /** Custom operations for file reading. Default: local filesystem */
34
50
  operations?: ReadOperations;
35
51
  }
@@ -1 +1 @@
1
- {"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../../../src/core/tools/read.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAIlD,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAG5C,OAAO,KAAK,EAAoB,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAI/E,OAAO,EAAoD,KAAK,gBAAgB,EAAgB,MAAM,eAAe,CAAC;AAEtH,QAAA,MAAM,UAAU;;;;EAId,CAAC;AAEH,eAAO,MAAM,gCAAgC;;;CAGnC,CAAC;AAEX,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,UAAU,CAAC,CAAC;AAEtD,MAAM,WAAW,eAAe;IAC/B,UAAU,CAAC,EAAE,gBAAgB,CAAC;CAC9B;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC9B,qCAAqC;IACrC,QAAQ,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IACpD,+CAA+C;IAC/C,MAAM,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAChD,sEAAsE;IACtE,mBAAmB,CAAC,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;CACnF;AAQD,MAAM,WAAW,eAAe;IAC/B,oEAAoE;IACpE,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,oEAAoE;IACpE,UAAU,CAAC,EAAE,cAAc,CAAC;CAC5B;AASD,wBAAgB,wBAAwB,CACvC,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,eAAe,GACvB,cAAc,CAAC,OAAO,UAAU,EAAE,eAAe,GAAG,SAAS,CAAC,CA8HhE;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,SAAS,CAAC,OAAO,UAAU,CAAC,CAEnG","sourcesContent":["import type { AgentTool } from \"@punch-bot/agent\";\nimport type { Api, ImageContent, Model, TextContent } from \"@punch-bot/ai\";\nimport { constants } from \"fs\";\nimport { access as fsAccess, readFile as fsReadFile } from \"fs/promises\";\nimport { type Static, Type } from \"typebox\";\nimport { processImage } from \"../../utils/image-process.ts\";\nimport { detectSupportedImageMimeTypeFromFile } from \"../../utils/mime.ts\";\nimport type { ExtensionContext, ToolDefinition } from \"../extensions/types.ts\";\nimport { resolveReadPathAsync } from \"./path-utils.ts\";\nimport { readRenderers } from \"./renderers/read.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\nimport { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize, type TruncationResult, truncateHead } from \"./truncate.ts\";\n\nconst readSchema = Type.Object({\n\tpath: Type.String({ description: \"Path to the file to read (relative or absolute)\" }),\n\toffset: Type.Optional(Type.Number({ description: \"Line number to start reading from (1-indexed)\" })),\n\tlimit: Type.Optional(Type.Number({ description: \"Maximum number of lines to read\" })),\n});\n\nexport const readToolSystemPromptContribution = {\n\tsnippet: \"Read file contents\",\n\tguidelines: [\"Use read to examine files instead of cat or sed.\"],\n} as const;\n\nexport type ReadToolInput = Static<typeof readSchema>;\n\nexport interface ReadToolDetails {\n\ttruncation?: TruncationResult;\n}\n\n/**\n * Pluggable operations for the read tool.\n * Override these to delegate file reading to remote systems (for example SSH).\n */\nexport interface ReadOperations {\n\t/** Read file contents as a Buffer */\n\treadFile: (absolutePath: string) => Promise<Buffer>;\n\t/** Check if file is readable (throw if not) */\n\taccess: (absolutePath: string) => Promise<void>;\n\t/** Detect image MIME type, return null or undefined for non-images */\n\tdetectImageMimeType?: (absolutePath: string) => Promise<string | null | undefined>;\n}\n\nconst defaultReadOperations: ReadOperations = {\n\treadFile: (path) => fsReadFile(path),\n\taccess: (path) => fsAccess(path, constants.R_OK),\n\tdetectImageMimeType: detectSupportedImageMimeTypeFromFile,\n};\n\nexport interface ReadToolOptions {\n\t/** Whether to auto-resize images to 2000x2000 max. Default: true */\n\tautoResizeImages?: boolean;\n\t/** Custom operations for file reading. Default: local filesystem */\n\toperations?: ReadOperations;\n}\n\nfunction getNonVisionImageNote(model: Model<Api> | undefined): string | undefined {\n\tif (!model || model.input.includes(\"image\")) {\n\t\treturn undefined;\n\t}\n\treturn \"[Current model does not support images. The image will be omitted from this request.]\";\n}\n\nexport function createReadToolDefinition(\n\tcwd: string,\n\toptions?: ReadToolOptions,\n): ToolDefinition<typeof readSchema, ReadToolDetails | undefined> {\n\tconst autoResizeImages = options?.autoResizeImages ?? true;\n\tconst ops = options?.operations ?? defaultReadOperations;\n\treturn {\n\t\tname: \"read\",\n\t\tlabel: \"read\",\n\t\tdescription: `Read the contents of a file. Supports text files and images (jpg, png, gif, webp, bmp). Images are sent as attachments. For text files, output is truncated to ${DEFAULT_MAX_LINES} lines or ${DEFAULT_MAX_BYTES / 1024}KB (whichever is hit first). Use offset/limit for large files. When you need the full file, continue with offset until complete.`,\n\t\tpromptSnippet: readToolSystemPromptContribution.snippet,\n\t\tpromptGuidelines: [...readToolSystemPromptContribution.guidelines],\n\t\tparameters: readSchema,\n\t\tconstrainedSampling: { type: \"json_schema\", strict: \"prefer\" },\n\t\tasync execute(\n\t\t\t_toolCallId,\n\t\t\t{ path, offset, limit }: { path: string; offset?: number; limit?: number },\n\t\t\tsignal?: AbortSignal,\n\t\t\t_onUpdate?,\n\t\t\tctx?: ExtensionContext,\n\t\t) {\n\t\t\treturn new Promise<{ content: (TextContent | ImageContent)[]; details: ReadToolDetails | undefined }>(\n\t\t\t\t(resolve, reject) => {\n\t\t\t\t\tif (signal?.aborted) {\n\t\t\t\t\t\treject(new Error(\"Operation aborted\"));\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tlet aborted = false;\n\t\t\t\t\tconst onAbort = () => {\n\t\t\t\t\t\taborted = true;\n\t\t\t\t\t\treject(new Error(\"Operation aborted\"));\n\t\t\t\t\t};\n\t\t\t\t\tsignal?.addEventListener(\"abort\", onAbort, { once: true });\n\n\t\t\t\t\t(async () => {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst absolutePath = await resolveReadPathAsync(path, ctx?.cwd || cwd);\n\t\t\t\t\t\t\tif (aborted) return;\n\t\t\t\t\t\t\t// Check if file exists and is readable.\n\t\t\t\t\t\t\tawait ops.access(absolutePath);\n\t\t\t\t\t\t\tif (aborted) return;\n\t\t\t\t\t\t\tconst mimeType = ops.detectImageMimeType ? await ops.detectImageMimeType(absolutePath) : undefined;\n\t\t\t\t\t\t\tlet content: (TextContent | ImageContent)[];\n\t\t\t\t\t\t\tlet details: ReadToolDetails | undefined;\n\t\t\t\t\t\t\tconst nonVisionImageNote = getNonVisionImageNote(ctx?.model);\n\t\t\t\t\t\t\tif (mimeType) {\n\t\t\t\t\t\t\t\t// Read image as binary.\n\t\t\t\t\t\t\t\tconst buffer = await ops.readFile(absolutePath);\n\t\t\t\t\t\t\t\tconst processed = await processImage(buffer, mimeType, { autoResizeImages });\n\t\t\t\t\t\t\t\tif (!processed.ok) {\n\t\t\t\t\t\t\t\t\tlet textNote = `Read image file [${mimeType}]\\n${processed.message}`;\n\t\t\t\t\t\t\t\t\tif (nonVisionImageNote) textNote += `\\n${nonVisionImageNote}`;\n\t\t\t\t\t\t\t\t\tcontent = [{ type: \"text\", text: textNote }];\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tlet textNote = `Read image file [${processed.mimeType}]`;\n\t\t\t\t\t\t\t\t\tif (processed.hints.length > 0) textNote += `\\n${processed.hints.join(\"\\n\")}`;\n\t\t\t\t\t\t\t\t\tif (nonVisionImageNote) textNote += `\\n${nonVisionImageNote}`;\n\t\t\t\t\t\t\t\t\tcontent = [\n\t\t\t\t\t\t\t\t\t\t{ type: \"text\", text: textNote },\n\t\t\t\t\t\t\t\t\t\t{ type: \"image\", data: processed.data, mimeType: processed.mimeType },\n\t\t\t\t\t\t\t\t\t];\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t// Read text content.\n\t\t\t\t\t\t\t\tconst buffer = await ops.readFile(absolutePath);\n\t\t\t\t\t\t\t\tconst textContent = buffer.toString(\"utf-8\");\n\t\t\t\t\t\t\t\tconst allLines = textContent.split(\"\\n\");\n\t\t\t\t\t\t\t\tconst totalFileLines = allLines.length;\n\t\t\t\t\t\t\t\t// Apply offset if specified. Convert from 1-indexed input to 0-indexed array access.\n\t\t\t\t\t\t\t\tconst startLine = offset ? Math.max(0, offset - 1) : 0;\n\t\t\t\t\t\t\t\tconst startLineDisplay = startLine + 1;\n\t\t\t\t\t\t\t\t// Check if offset is out of bounds.\n\t\t\t\t\t\t\t\tif (startLine >= allLines.length) {\n\t\t\t\t\t\t\t\t\tthrow new Error(`Offset ${offset} is beyond end of file (${allLines.length} lines total)`);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tlet selectedContent: string;\n\t\t\t\t\t\t\t\tlet userLimitedLines: number | undefined;\n\t\t\t\t\t\t\t\t// If limit is specified by the user, honor it first. Otherwise truncateHead decides.\n\t\t\t\t\t\t\t\tif (limit !== undefined) {\n\t\t\t\t\t\t\t\t\tconst endLine = Math.min(startLine + limit, allLines.length);\n\t\t\t\t\t\t\t\t\tselectedContent = allLines.slice(startLine, endLine).join(\"\\n\");\n\t\t\t\t\t\t\t\t\tuserLimitedLines = endLine - startLine;\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tselectedContent = allLines.slice(startLine).join(\"\\n\");\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t// Apply truncation, respecting both line and byte limits.\n\t\t\t\t\t\t\t\tconst truncation = truncateHead(selectedContent);\n\t\t\t\t\t\t\t\tlet outputText: string;\n\t\t\t\t\t\t\t\tif (truncation.firstLineExceedsLimit) {\n\t\t\t\t\t\t\t\t\t// First line alone exceeds the byte limit. Point the model at a bash fallback.\n\t\t\t\t\t\t\t\t\tconst firstLineSize = formatSize(Buffer.byteLength(allLines[startLine], \"utf-8\"));\n\t\t\t\t\t\t\t\t\toutputText = `[Line ${startLineDisplay} is ${firstLineSize}, exceeds ${formatSize(DEFAULT_MAX_BYTES)} limit. Use bash: sed -n '${startLineDisplay}p' ${path} | head -c ${DEFAULT_MAX_BYTES}]`;\n\t\t\t\t\t\t\t\t\tdetails = { truncation };\n\t\t\t\t\t\t\t\t} else if (truncation.truncated) {\n\t\t\t\t\t\t\t\t\t// Truncation occurred. Build an actionable continuation notice.\n\t\t\t\t\t\t\t\t\tconst endLineDisplay = startLineDisplay + truncation.outputLines - 1;\n\t\t\t\t\t\t\t\t\tconst nextOffset = endLineDisplay + 1;\n\t\t\t\t\t\t\t\t\toutputText = truncation.content;\n\t\t\t\t\t\t\t\t\tif (truncation.truncatedBy === \"lines\") {\n\t\t\t\t\t\t\t\t\t\toutputText += `\\n\\n[Showing lines ${startLineDisplay}-${endLineDisplay} of ${totalFileLines}. Use offset=${nextOffset} to continue.]`;\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\toutputText += `\\n\\n[Showing lines ${startLineDisplay}-${endLineDisplay} of ${totalFileLines} (${formatSize(DEFAULT_MAX_BYTES)} limit). Use offset=${nextOffset} to continue.]`;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tdetails = { truncation };\n\t\t\t\t\t\t\t\t} else if (userLimitedLines !== undefined && startLine + userLimitedLines < allLines.length) {\n\t\t\t\t\t\t\t\t\t// User-specified limit stopped early, but the file still has more content.\n\t\t\t\t\t\t\t\t\tconst remaining = allLines.length - (startLine + userLimitedLines);\n\t\t\t\t\t\t\t\t\tconst nextOffset = startLine + userLimitedLines + 1;\n\t\t\t\t\t\t\t\t\toutputText = `${truncation.content}\\n\\n[${remaining} more lines in file. Use offset=${nextOffset} to continue.]`;\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t// No truncation and no remaining user-limited content.\n\t\t\t\t\t\t\t\t\toutputText = truncation.content;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tcontent = [{ type: \"text\", text: outputText }];\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif (aborted) return;\n\t\t\t\t\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\t\t\t\t\t\t\tresolve({ content, details });\n\t\t\t\t\t\t} catch (error: any) {\n\t\t\t\t\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\t\t\t\t\t\t\tif (!aborted) reject(error);\n\t\t\t\t\t\t}\n\t\t\t\t\t})();\n\t\t\t\t},\n\t\t\t);\n\t\t},\n\t\t...readRenderers,\n\t};\n}\n\nexport function createReadTool(cwd: string, options?: ReadToolOptions): AgentTool<typeof readSchema> {\n\treturn wrapToolDefinition(createReadToolDef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IAC3B,gFAAgF;IAChF,aAAa,CAAC,EAAE,uBAAuB,CAAC;IACxC,oEAAoE;IACpE,UAAU,CAAC,EAAE,cAAc,CAAC;CAC5B;AAgBD,wBAAgB,wBAAwB,CACvC,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,eAAe,GACvB,cAAc,CAAC,OAAO,UAAU,EAAE,eAAe,GAAG,SAAS,CAAC,CAkIhE;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,SAAS,CAAC,OAAO,UAAU,CAAC,CAEnG"}
@@ -4,7 +4,6 @@ import { Type } from "typebox";
4
4
  import { processImage } from "../../utils/image-process.js";
5
5
  import { detectSupportedImageMimeTypeFromFile } from "../../utils/mime.js";
6
6
  import { resolveReadPathAsync } from "./path-utils.js";
7
- import { readRenderers } from "./renderers/read.js";
8
7
  import { wrapToolDefinition } from "./tool-definition-wrapper.js";
9
8
  import { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize, truncateHead } from "./truncate.js";
10
9
  const readSchema = Type.Object({
@@ -16,11 +15,27 @@ export const readToolSystemPromptContribution = {
16
15
  snippet: "Read file contents",
17
16
  guidelines: ["Use read to examine files instead of cat or sed."],
18
17
  };
18
+ /**
19
+ * Result for programmatic callers such as codemode scripts: the text for text files, and an image
20
+ * block for images that codemode's `image()` accepts. `note` is the text that goes with the image,
21
+ * such as resize hints. Property descriptions are left out so the type stays on one line in tool
22
+ * descriptions.
23
+ */
24
+ const readOutputSchema = Type.Union([
25
+ Type.String(),
26
+ Type.Object({ type: Type.Literal("image"), data: Type.String(), mimeType: Type.String(), note: Type.String() }),
27
+ ]);
19
28
  const defaultReadOperations = {
20
29
  readFile: (path) => fsReadFile(path),
21
30
  access: (path) => fsAccess(path, constants.R_OK),
22
31
  detectImageMimeType: detectSupportedImageMimeTypeFromFile,
23
32
  };
33
+ /** The image block and its note, or the text for text files and images that could not be processed. */
34
+ function toReadOutput(content) {
35
+ const text = content.find((block) => block.type === "text")?.text ?? "";
36
+ const image = content.find((block) => block.type === "image");
37
+ return image ? { type: "image", data: image.data, mimeType: image.mimeType, note: text } : text;
38
+ }
24
39
  function getNonVisionImageNote(model) {
25
40
  if (!model || model.input.includes("image")) {
26
41
  return undefined;
@@ -29,6 +44,7 @@ function getNonVisionImageNote(model) {
29
44
  }
30
45
  export function createReadToolDefinition(cwd, options) {
31
46
  const autoResizeImages = options?.autoResizeImages ?? true;
47
+ const fallbackResizeOptions = options?.resizeOptions;
32
48
  const ops = options?.operations ?? defaultReadOperations;
33
49
  return {
34
50
  name: "read",
@@ -37,6 +53,7 @@ export function createReadToolDefinition(cwd, options) {
37
53
  promptSnippet: readToolSystemPromptContribution.snippet,
38
54
  promptGuidelines: [...readToolSystemPromptContribution.guidelines],
39
55
  parameters: readSchema,
56
+ outputSchema: readOutputSchema,
40
57
  constrainedSampling: { type: "json_schema", strict: "prefer" },
41
58
  async execute(_toolCallId, { path, offset, limit }, signal, _onUpdate, ctx) {
42
59
  return new Promise((resolve, reject) => {
@@ -66,7 +83,10 @@ export function createReadToolDefinition(cwd, options) {
66
83
  if (mimeType) {
67
84
  // Read image as binary.
68
85
  const buffer = await ops.readFile(absolutePath);
69
- const processed = await processImage(buffer, mimeType, { autoResizeImages });
86
+ const processed = await processImage(buffer, mimeType, {
87
+ autoResizeImages,
88
+ resizeOptions: ctx?.model?.inputLimits?.images?.resize ?? fallbackResizeOptions,
89
+ });
70
90
  if (!processed.ok) {
71
91
  let textNote = `Read image file [${mimeType}]\n${processed.message}`;
72
92
  if (nonVisionImageNote)
@@ -154,9 +174,8 @@ export function createReadToolDefinition(cwd, options) {
154
174
  reject(error);
155
175
  }
156
176
  })();
157
- });
177
+ }).then((result) => ({ ...result, structuredContent: toReadOutput(result.content) }));
158
178
  },
159
- ...readRenderers,
160
179
  };
161
180
  }
162
181
  export function createReadTool(cwd, options) {
@@ -1 +1 @@
1
- {"version":3,"file":"read.js","sourceRoot":"","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BAAA,CACD,CAAC,EAAE,CAAC;YAAA,CACL,CACD,CAAC;QAAA,CACF;QACD,GAAG,aAAa;KAChB,CAAC;AAAA,CACF;AAED,MAAM,UAAU,cAAc,CAAC,GAAW,EAAE,OAAyB,EAAgC;IACpG,OAAO,kBAAkB,CAAC,wBAAwB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;AAAA,CAClE","sourcesContent":["import type { AgentTool } from \"@punch-bot/agent\";\nimport type { Api, ImageContent, Model, TextContent } from \"@punch-bot/ai\";\nimport { constants } from \"fs\";\nimport { access as fsAccess, readFile as fsReadFile } from \"fs/promises\";\nimport { type Static, Type } from \"typebox\";\nimport { processImage } from \"../../utils/image-process.ts\";\nimport { detectSupportedImageMimeTypeFromFile } from \"../../utils/mime.ts\";\nimport type { ExtensionContext, ToolDefinition } from \"../extensions/types.ts\";\nimport { resolveReadPathAsync } from \"./path-utils.ts\";\nimport { readRenderers } from \"./renderers/read.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\nimport { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize, type TruncationResult, truncateHead } from \"./truncate.ts\";\n\nconst readSchema = Type.Object({\n\tpath: Type.String({ description: \"Path to the file to read (relative or absolute)\" }),\n\toffset: Type.Optional(Type.Number({ description: \"Line number to start reading from (1-indexed)\" })),\n\tlimit: Type.Optional(Type.Number({ description: \"Maximum number of lines to read\" })),\n});\n\nexport const readToolSystemPromptContribution = {\n\tsnippet: \"Read file contents\",\n\tguidelines: [\"Use read to examine files instead of cat or sed.\"],\n} as const;\n\nexport type ReadToolInput = Static<typeof readSchema>;\n\nexport interface ReadToolDetails {\n\ttruncation?: TruncationResult;\n}\n\n/**\n * Pluggable operations for the read tool.\n * Override these to delegate file reading to remote systems (for example SSH).\n */\nexport interface ReadOperations {\n\t/** Read file contents as a Buffer */\n\treadFile: (absolutePath: string) => Promise<Buffer>;\n\t/** Check if file is readable (throw if not) */\n\taccess: (absolutePath: string) => Promise<void>;\n\t/** Detect image MIME type, return null or undefined for non-images */\n\tdetectImageMimeType?: (absolutePath: string) => Promise<string | null | undefined>;\n}\n\nconst defaultReadOperations: ReadOperations = {\n\treadFile: (path) => fsReadFile(path),\n\taccess: (path) => fsAccess(path, constants.R_OK),\n\tdetectImageMimeType: detectSupportedImageMimeTypeFromFile,\n};\n\nexport interface ReadToolOptions {\n\t/** Whether to auto-resize images to 2000x2000 max. Default: true */\n\tautoResizeImages?: boolean;\n\t/** Custom operations for file reading. Default: local filesystem */\n\toperations?: ReadOperations;\n}\n\nfunction getNonVisionImageNote(model: Model<Api> | undefined): string | undefined {\n\tif (!model || model.input.includes(\"image\")) {\n\t\treturn undefined;\n\t}\n\treturn \"[Current model does not support images. The image will be omitted from this request.]\";\n}\n\nexport function createReadToolDefinition(\n\tcwd: string,\n\toptions?: ReadToolOptions,\n): ToolDefinition<typeof readSchema, ReadToolDetails | undefined> {\n\tconst autoResizeImages = options?.autoResizeImages ?? true;\n\tconst ops = options?.operations ?? defaultReadOperations;\n\treturn {\n\t\tname: \"read\",\n\t\tlabel: \"read\",\n\t\tdescription: `Read the contents of a file. Supports text files and images (jpg, png, gif, webp, bmp). Images are sent as attachments. For text files, output is truncated to ${DEFAULT_MAX_LINES} lines or ${DEFAULT_MAX_BYTES / 1024}KB (whichever is hit first). Use offset/limit for large files. When you need the full file, continue with offset until complete.`,\n\t\tpromptSnippet: readToolSystemPromptContribution.snippet,\n\t\tpromptGuidelines: [...readToolSystemPromptContribution.guidelines],\n\t\tparameters: readSchema,\n\t\tconstrainedSampling: { type: \"json_schema\", strict: \"prefer\" },\n\t\tasync execute(\n\t\t\t_toolCallId,\n\t\t\t{ path, offset, limit }: { path: string; offset?: number; limit?: number },\n\t\t\tsignal?: AbortSignal,\n\t\t\t_onUpdate?,\n\t\t\tctx?: ExtensionContext,\n\t\t) {\n\t\t\treturn new Promise<{ content: (TextContent | ImageContent)[]; details: ReadToolDetails | undefined }>(\n\t\t\t\t(resolve, reject) => {\n\t\t\t\t\tif (signal?.aborted) {\n\t\t\t\t\t\treject(new Error(\"Operation aborted\"));\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tlet aborted = false;\n\t\t\t\t\tconst onAbort = () => {\n\t\t\t\t\t\taborted = true;\n\t\t\t\t\t\treject(new Error(\"Operation aborted\"));\n\t\t\t\t\t};\n\t\t\t\t\tsignal?.addEventListener(\"abort\", onAbort, { once: true });\n\n\t\t\t\t\t(async () => {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst absolutePath = await resolveReadPathAsync(path, ctx?.cwd || cwd);\n\t\t\t\t\t\t\tif (aborted) return;\n\t\t\t\t\t\t\t// Check if file exists and is readable.\n\t\t\t\t\t\t\tawait ops.access(absolutePath);\n\t\t\t\t\t\t\tif (aborted) return;\n\t\t\t\t\t\t\tconst mimeType = ops.detectImageMimeType ? await ops.detectImageMimeType(absolutePath) : undefined;\n\t\t\t\t\t\t\tlet content: (TextContent | ImageContent)[];\n\t\t\t\t\t\t\tlet details: ReadToolDetails | undefined;\n\t\t\t\t\t\t\tconst nonVisionImageNote = getNonVisionImageNote(ctx?.model);\n\t\t\t\t\t\t\tif (mimeType) {\n\t\t\t\t\t\t\t\t// Read image as binary.\n\t\t\t\t\t\t\t\tconst buffer = await ops.readFile(absolutePath);\n\t\t\t\t\t\t\t\tconst processed = await processImage(buffer, mimeType, { autoResizeImages });\n\t\t\t\t\t\t\t\tif (!processed.ok) {\n\t\t\t\t\t\t\t\t\tlet textNote = `Read image file [${mimeType}]\\n${processed.message}`;\n\t\t\t\t\t\t\t\t\tif (nonVisionImageNote) textNote += `\\n${nonVisionImageNote}`;\n\t\t\t\t\t\t\t\t\tcontent = [{ type: \"text\", text: textNote }];\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tlet textNote = `Read image file [${processed.mimeType}]`;\n\t\t\t\t\t\t\t\t\tif (processed.hints.length > 0) textNote += `\\n${processed.hints.join(\"\\n\")}`;\n\t\t\t\t\t\t\t\t\tif (nonVisionImageNote) textNote += `\\n${nonVisionImageNote}`;\n\t\t\t\t\t\t\t\t\tcontent = [\n\t\t\t\t\t\t\t\t\t\t{ type: \"text\", text: textNote },\n\t\t\t\t\t\t\t\t\t\t{ type: \"image\", data: processed.data, mimeType: processed.mimeType },\n\t\t\t\t\t\t\t\t\t];\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t// Read text content.\n\t\t\t\t\t\t\t\tconst buffer = await ops.readFile(absolutePath);\n\t\t\t\t\t\t\t\tconst textContent = buffer.toString(\"utf-8\");\n\t\t\t\t\t\t\t\tconst allLines = textContent.split(\"\\n\");\n\t\t\t\t\t\t\t\tconst totalFileLines = allLines.length;\n\t\t\t\t\t\t\t\t// Apply offset if specified. Convert from 1-indexed input to 0-indexed array access.\n\t\t\t\t\t\t\t\tconst startLine = offset ? Math.max(0, offset - 1) : 0;\n\t\t\t\t\t\t\t\tconst startLineDisplay = startLine + 1;\n\t\t\t\t\t\t\t\t// Check if offset is out of bounds.\n\t\t\t\t\t\t\t\tif (startLine >= allLines.length) {\n\t\t\t\t\t\t\t\t\tthrow new Error(`Offset ${offset} is beyond end of file (${allLines.length} lines total)`);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tlet selectedContent: string;\n\t\t\t\t\t\t\t\tlet userLimitedLines: number | undefined;\n\t\t\t\t\t\t\t\t// If limit is specified by the user, honor it first. Otherwise truncateHead decides.\n\t\t\t\t\t\t\t\tif (limit !== undefined) {\n\t\t\t\t\t\t\t\t\tconst endLine = Math.min(startLine + limit, allLines.length);\n\t\t\t\t\t\t\t\t\tselectedContent = allLines.slice(startLine, endLine).join(\"\\n\");\n\t\t\t\t\t\t\t\t\tuserLimitedLines = endLine - startLine;\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tselectedContent = allLines.slice(startLine).join(\"\\n\");\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t// Apply truncation, respecting both line and byte limits.\n\t\t\t\t\t\t\t\tconst truncation = truncateHead(selectedContent);\n\t\t\t\t\t\t\t\tlet outputText: string;\n\t\t\t\t\t\t\t\tif (truncation.firstLineExceedsLimit) {\n\t\t\t\t\t\t\t\t\t// First line alone exceeds the byte limit. Point the model at a bash fallback.\n\t\t\t\t\t\t\t\t\tconst firstLineSize = formatSize(Buffer.byteLength(allLines[startLine], \"utf-8\"));\n\t\t\t\t\t\t\t\t\toutputText = `[Line ${startLineDisplay} is ${firstLineSize}, exceeds ${formatSize(DEFAULT_MAX_BYTES)} limit. Use bash: sed -n '${startLineDisplay}p' ${path} | head -c ${DEFAULT_MAX_BYTES}]`;\n\t\t\t\t\t\t\t\t\tdetails = { truncation };\n\t\t\t\t\t\t\t\t} else if (truncation.truncated) {\n\t\t\t\t\t\t\t\t\t// Truncation occurred. Build an actionable continuation notice.\n\t\t\t\t\t\t\t\t\tconst endLineDisplay = startLineDisplay + truncation.outputLines - 1;\n\t\t\t\t\t\t\t\t\tconst nextOffset = endLineDisplay + 1;\n\t\t\t\t\t\t\t\t\toutputText = truncation.content;\n\t\t\t\t\t\t\t\t\tif (truncation.truncatedBy === \"lines\") {\n\t\t\t\t\t\t\t\t\t\toutputText += `\\n\\n[Showing lines ${startLineDisplay}-${endLineDisplay} of ${totalFileLines}. Use offset=${nextOffset} to continue.]`;\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\toutputText += `\\n\\n[Showing lines ${startLineDisplay}-${endLineDisplay} of ${totalFileLines} (${formatSize(DEFAULT_MAX_BYTES)} limit). Use offset=${nextOffset} to continue.]`;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tdetails = { truncation };\n\t\t\t\t\t\t\t\t} else if (userLimitedLines !== undefined && startLine + userLimitedLines < allLines.length) {\n\t\t\t\t\t\t\t\t\t// User-specified limit stopped early, but the file still has more content.\n\t\t\t\t\t\t\t\t\tconst remaining = allLines.length - (startLine + userLimitedLines);\n\t\t\t\t\t\t\t\t\tconst nextOffset = startLine + userLimitedLines + 1;\n\t\t\t\t\t\t\t\t\toutputText = `${truncation.content}\\n\\n[${remaining} more lines in file. Use offset=${nextOffset} to continue.]`;\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t// No truncation and no remaining user-limited content.\n\t\t\t\t\t\t\t\t\toutputText = truncation.content;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tcontent = [{ type: \"text\", text: outputText }];\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif (aborted) return;\n\t\t\t\t\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\t\t\t\t\t\t\tresolve({ content, details });\n\t\t\t\t\t\t} catch (error: any) {\n\t\t\t\t\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\t\t\t\t\t\t\tif (!aborted) reject(error);\n\t\t\t\t\t\t}\n\t\t\t\t\t})();\n\t\t\t\t},\n\t\t\t);\n\t\t},\n\t\t...readRenderers,\n\t};\n}\n\nexport function createReadTool(cwd: string, options?: ReadToolOptions): AgentTool<typeof readSchema> {\n\treturn wrapToolDefinition(createReadToolDefinition(cwd, options));\n}\n"]}
1
+ {"version":3,"file":"read.js","sourceRoot":"","sources":["../../../src/core/tools/read.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAC/B,OAAO,EAAE,MAAM,IAAI,QAAQ,EAAE,QAAQ,IAAI,UAAU,EAAE,MAAM,aAAa,CAAC;AACzE,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,oCAAoC,EAAE,MAAM,qBAAqB,CAAC;AAE3E,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,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AuD;gCACvD,UAAU,GAAG,UAAU,CAAC,OAAO,CAAC;4BACjC,CAAC;4BACD,OAAO,GAAG,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC;wBAChD,CAAC;wBAED,IAAI,OAAO;4BAAE,OAAO;wBACpB,MAAM,EAAE,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;wBAC9C,OAAO,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;oBAC/B,CAAC;oBAAC,OAAO,KAAU,EAAE,CAAC;wBACrB,MAAM,EAAE,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;wBAC9C,IAAI,CAAC,OAAO;4BAAE,MAAM,CAAC,KAAK,CAAC,CAAC;oBAC7B,CAAC;gBACF,CAAC,CAAC,EAAE,CAAC;YACN,CAAC,CACD,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,MAAM,EAAE,iBAAiB,EAAE,YAAY,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC;QACtF,CAAC;KACD,CAAC;AACH,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,GAAW,EAAE,OAAyB;IACpE,OAAO,kBAAkB,CAAC,wBAAwB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;AACnE,CAAC","sourcesContent":["import type { AgentTool } from \"@punch-bot/agent\";\nimport type { Api, ImageContent, Model, ModelImageResizeOptions, TextContent } from \"@punch-bot/ai\";\nimport { constants } from \"fs\";\nimport { access as fsAccess, readFile as fsReadFile } from \"fs/promises\";\nimport { type Static, Type } from \"typebox\";\nimport { processImage } from \"../../utils/image-process.ts\";\nimport { detectSupportedImageMimeTypeFromFile } from \"../../utils/mime.ts\";\nimport type { ExtensionContext, ToolDefinition } from \"../extensions/types.ts\";\nimport { resolveReadPathAsync } from \"./path-utils.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\nimport { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize, type TruncationResult, truncateHead } from \"./truncate.ts\";\n\nconst readSchema = Type.Object({\n\tpath: Type.String({ description: \"Path to the file to read (relative or absolute)\" }),\n\toffset: Type.Optional(Type.Number({ description: \"Line number to start reading from (1-indexed)\" })),\n\tlimit: Type.Optional(Type.Number({ description: \"Maximum number of lines to read\" })),\n});\n\nexport const readToolSystemPromptContribution = {\n\tsnippet: \"Read file contents\",\n\tguidelines: [\"Use read to examine files instead of cat or sed.\"],\n} as const;\n\nexport type ReadToolInput = Static<typeof readSchema>;\n\n/**\n * Result for programmatic callers such as codemode scripts: the text for text files, and an image\n * block for images that codemode's `image()` accepts. `note` is the text that goes with the image,\n * such as resize hints. Property descriptions are left out so the type stays on one line in tool\n * descriptions.\n */\nconst readOutputSchema = Type.Union([\n\tType.String(),\n\tType.Object({ type: Type.Literal(\"image\"), data: Type.String(), mimeType: Type.String(), note: Type.String() }),\n]);\n\nexport type ReadToolOutput = Static<typeof readOutputSchema>;\n\nexport interface ReadToolDetails {\n\ttruncation?: TruncationResult;\n}\n\n/**\n * Pluggable operations for the read tool.\n * Override these to delegate file reading to remote systems (for example SSH).\n */\nexport interface ReadOperations {\n\t/** Read file contents as a Buffer */\n\treadFile: (absolutePath: string) => Promise<Buffer>;\n\t/** Check if file is readable (throw if not) */\n\taccess: (absolutePath: string) => Promise<void>;\n\t/** Detect image MIME type, return null or undefined for non-images */\n\tdetectImageMimeType?: (absolutePath: string) => Promise<string | null | undefined>;\n}\n\nconst defaultReadOperations: ReadOperations = {\n\treadFile: (path) => fsReadFile(path),\n\taccess: (path) => fsAccess(path, constants.R_OK),\n\tdetectImageMimeType: detectSupportedImageMimeTypeFromFile,\n};\n\nexport interface ReadToolOptions {\n\t/** Whether to auto-resize images. Default: true */\n\tautoResizeImages?: boolean;\n\t/** Fallback resize profile when the execution context has no model metadata. */\n\tresizeOptions?: ModelImageResizeOptions;\n\t/** Custom operations for file reading. Default: local filesystem */\n\toperations?: ReadOperations;\n}\n\n/** The image block and its note, or the text for text files and images that could not be processed. */\nfunction toReadOutput(content: (TextContent | ImageContent)[]): ReadToolOutput {\n\tconst text = content.find((block) => block.type === \"text\")?.text ?? \"\";\n\tconst image = content.find((block) => block.type === \"image\");\n\treturn image ? { type: \"image\", data: image.data, mimeType: image.mimeType, note: text } : text;\n}\n\nfunction getNonVisionImageNote(model: Model<Api> | undefined): string | undefined {\n\tif (!model || model.input.includes(\"image\")) {\n\t\treturn undefined;\n\t}\n\treturn \"[Current model does not support images. The image will be omitted from this request.]\";\n}\n\nexport function createReadToolDefinition(\n\tcwd: string,\n\toptions?: ReadToolOptions,\n): ToolDefinition<typeof readSchema, ReadToolDetails | undefined> {\n\tconst autoResizeImages = options?.autoResizeImages ?? true;\n\tconst fallbackResizeOptions = options?.resizeOptions;\n\tconst ops = options?.operations ?? defaultReadOperations;\n\treturn {\n\t\tname: \"read\",\n\t\tlabel: \"read\",\n\t\tdescription: `Read the contents of a file. Supports text files and images (jpg, png, gif, webp, bmp). Images are sent as attachments. For text files, output is truncated to ${DEFAULT_MAX_LINES} lines or ${DEFAULT_MAX_BYTES / 1024}KB (whichever is hit first). Use offset/limit for large files. When you need the full file, continue with offset until complete.`,\n\t\tpromptSnippet: readToolSystemPromptContribution.snippet,\n\t\tpromptGuidelines: [...readToolSystemPromptContribution.guidelines],\n\t\tparameters: readSchema,\n\t\toutputSchema: readOutputSchema,\n\t\tconstrainedSampling: { type: \"json_schema\", strict: \"prefer\" },\n\t\tasync execute(\n\t\t\t_toolCallId,\n\t\t\t{ path, offset, limit }: { path: string; offset?: number; limit?: number },\n\t\t\tsignal?: AbortSignal,\n\t\t\t_onUpdate?,\n\t\t\tctx?: ExtensionContext,\n\t\t) {\n\t\t\treturn new Promise<{ content: (TextContent | ImageContent)[]; details: ReadToolDetails | undefined }>(\n\t\t\t\t(resolve, reject) => {\n\t\t\t\t\tif (signal?.aborted) {\n\t\t\t\t\t\treject(new Error(\"Operation aborted\"));\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tlet aborted = false;\n\t\t\t\t\tconst onAbort = () => {\n\t\t\t\t\t\taborted = true;\n\t\t\t\t\t\treject(new Error(\"Operation aborted\"));\n\t\t\t\t\t};\n\t\t\t\t\tsignal?.addEventListener(\"abort\", onAbort, { once: true });\n\n\t\t\t\t\t(async () => {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst absolutePath = await resolveReadPathAsync(path, ctx?.cwd || cwd);\n\t\t\t\t\t\t\tif (aborted) return;\n\t\t\t\t\t\t\t// Check if file exists and is readable.\n\t\t\t\t\t\t\tawait ops.access(absolutePath);\n\t\t\t\t\t\t\tif (aborted) return;\n\t\t\t\t\t\t\tconst mimeType = ops.detectImageMimeType ? await ops.detectImageMimeType(absolutePath) : undefined;\n\t\t\t\t\t\t\tlet content: (TextContent | ImageContent)[];\n\t\t\t\t\t\t\tlet details: ReadToolDetails | undefined;\n\t\t\t\t\t\t\tconst nonVisionImageNote = getNonVisionImageNote(ctx?.model);\n\t\t\t\t\t\t\tif (mimeType) {\n\t\t\t\t\t\t\t\t// Read image as binary.\n\t\t\t\t\t\t\t\tconst buffer = await ops.readFile(absolutePath);\n\t\t\t\t\t\t\t\tconst processed = await processImage(buffer, mimeType, {\n\t\t\t\t\t\t\t\t\tautoResizeImages,\n\t\t\t\t\t\t\t\t\tresizeOptions: ctx?.model?.inputLimits?.images?.resize ?? fallbackResizeOptions,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\tif (!processed.ok) {\n\t\t\t\t\t\t\t\t\tlet textNote = `Read image file [${mimeType}]\\n${processed.message}`;\n\t\t\t\t\t\t\t\t\tif (nonVisionImageNote) textNote += `\\n${nonVisionImageNote}`;\n\t\t\t\t\t\t\t\t\tcontent = [{ type: \"text\", text: textNote }];\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tlet textNote = `Read image file [${processed.mimeType}]`;\n\t\t\t\t\t\t\t\t\tif (processed.hints.length > 0) textNote += `\\n${processed.hints.join(\"\\n\")}`;\n\t\t\t\t\t\t\t\t\tif (nonVisionImageNote) textNote += `\\n${nonVisionImageNote}`;\n\t\t\t\t\t\t\t\t\tcontent = [\n\t\t\t\t\t\t\t\t\t\t{ type: \"text\", text: textNote },\n\t\t\t\t\t\t\t\t\t\t{ type: \"image\", data: processed.data, mimeType: processed.mimeType },\n\t\t\t\t\t\t\t\t\t];\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t// Read text content.\n\t\t\t\t\t\t\t\tconst buffer = await ops.readFile(absolutePath);\n\t\t\t\t\t\t\t\tconst textContent = buffer.toString(\"utf-8\");\n\t\t\t\t\t\t\t\tconst allLines = textContent.split(\"\\n\");\n\t\t\t\t\t\t\t\tconst totalFileLines = allLines.length;\n\t\t\t\t\t\t\t\t// Apply offset if specified. Convert from 1-indexed input to 0-indexed array access.\n\t\t\t\t\t\t\t\tconst startLine = offset ? Math.max(0, offset - 1) : 0;\n\t\t\t\t\t\t\t\tconst startLineDisplay = startLine + 1;\n\t\t\t\t\t\t\t\t// Check if offset is out of bounds.\n\t\t\t\t\t\t\t\tif (startLine >= allLines.length) {\n\t\t\t\t\t\t\t\t\tthrow new Error(`Offset ${offset} is beyond end of file (${allLines.length} lines total)`);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tlet selectedContent: string;\n\t\t\t\t\t\t\t\tlet userLimitedLines: number | undefined;\n\t\t\t\t\t\t\t\t// If limit is specified by the user, honor it first. Otherwise truncateHead decides.\n\t\t\t\t\t\t\t\tif (limit !== undefined) {\n\t\t\t\t\t\t\t\t\tconst endLine = Math.min(startLine + limit, allLines.length);\n\t\t\t\t\t\t\t\t\tselectedContent = allLines.slice(startLine, endLine).join(\"\\n\");\n\t\t\t\t\t\t\t\t\tuserLimitedLines = endLine - startLine;\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tselectedContent = allLines.slice(startLine).join(\"\\n\");\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t// Apply truncation, respecting both line and byte limits.\n\t\t\t\t\t\t\t\tconst truncation = truncateHead(selectedContent);\n\t\t\t\t\t\t\t\tlet outputText: string;\n\t\t\t\t\t\t\t\tif (truncation.firstLineExceedsLimit) {\n\t\t\t\t\t\t\t\t\t// First line alone exceeds the byte limit. Point the model at a bash fallback.\n\t\t\t\t\t\t\t\t\tconst firstLineSize = formatSize(Buffer.byteLength(allLines[startLine], \"utf-8\"));\n\t\t\t\t\t\t\t\t\toutputText = `[Line ${startLineDisplay} is ${firstLineSize}, exceeds ${formatSize(DEFAULT_MAX_BYTES)} limit. Use bash: sed -n '${startLineDisplay}p' ${path} | head -c ${DEFAULT_MAX_BYTES}]`;\n\t\t\t\t\t\t\t\t\tdetails = { truncation };\n\t\t\t\t\t\t\t\t} else if (truncation.truncated) {\n\t\t\t\t\t\t\t\t\t// Truncation occurred. Build an actionable continuation notice.\n\t\t\t\t\t\t\t\t\tconst endLineDisplay = startLineDisplay + truncation.outputLines - 1;\n\t\t\t\t\t\t\t\t\tconst nextOffset = endLineDisplay + 1;\n\t\t\t\t\t\t\t\t\toutputText = truncation.content;\n\t\t\t\t\t\t\t\t\tif (truncation.truncatedBy === \"lines\") {\n\t\t\t\t\t\t\t\t\t\toutputText += `\\n\\n[Showing lines ${startLineDisplay}-${endLineDisplay} of ${totalFileLines}. Use offset=${nextOffset} to continue.]`;\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\toutputText += `\\n\\n[Showing lines ${startLineDisplay}-${endLineDisplay} of ${totalFileLines} (${formatSize(DEFAULT_MAX_BYTES)} limit). Use offset=${nextOffset} to continue.]`;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tdetails = { truncation };\n\t\t\t\t\t\t\t\t} else if (userLimitedLines !== undefined && startLine + userLimitedLines < allLines.length) {\n\t\t\t\t\t\t\t\t\t// User-specified limit stopped early, but the file still has more content.\n\t\t\t\t\t\t\t\t\tconst remaining = allLines.length - (startLine + userLimitedLines);\n\t\t\t\t\t\t\t\t\tconst nextOffset = startLine + userLimitedLines + 1;\n\t\t\t\t\t\t\t\t\toutputText = `${truncation.content}\\n\\n[${remaining} more lines in file. Use offset=${nextOffset} to continue.]`;\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t// No truncation and no remaining user-limited content.\n\t\t\t\t\t\t\t\t\toutputText = truncation.content;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tcontent = [{ type: \"text\", text: outputText }];\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif (aborted) return;\n\t\t\t\t\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\t\t\t\t\t\t\tresolve({ content, details });\n\t\t\t\t\t\t} catch (error: any) {\n\t\t\t\t\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\t\t\t\t\t\t\tif (!aborted) reject(error);\n\t\t\t\t\t\t}\n\t\t\t\t\t})();\n\t\t\t\t},\n\t\t\t).then((result) => ({ ...result, structuredContent: toReadOutput(result.content) }));\n\t\t},\n\t};\n}\n\nexport function createReadTool(cwd: string, options?: ReadToolOptions): AgentTool<typeof readSchema> {\n\treturn wrapToolDefinition(createReadToolDefinition(cwd, options));\n}\n"]}
@@ -1,9 +1,11 @@
1
1
  import type { AgentTool } from "@punch-bot/agent";
2
- import type { ExtensionContext, ToolDefinition } from "../extensions/types.ts";
2
+ import type { ExtensionToolContext, ToolDefinition } from "../extensions/types.ts";
3
+ /** Creates the context for one tool call. */
4
+ export type ToolContextFactory = (toolCallId: string, signal: AbortSignal | undefined) => ExtensionToolContext;
3
5
  /** Wrap a ToolDefinition into an AgentTool for the core runtime. */
4
- export declare function wrapToolDefinition<TDetails = unknown>(definition: ToolDefinition<any, TDetails>, ctxFactory?: () => ExtensionContext): AgentTool<any, TDetails>;
6
+ export declare function wrapToolDefinition<TDetails = unknown>(definition: ToolDefinition<any, TDetails>, ctxFactory?: ToolContextFactory): AgentTool<any, TDetails>;
5
7
  /** Wrap multiple ToolDefinitions into AgentTools for the core runtime. */
6
- export declare function wrapToolDefinitions(definitions: ToolDefinition<any, any>[], ctxFactory?: () => ExtensionContext): AgentTool<any>[];
8
+ export declare function wrapToolDefinitions(definitions: ToolDefinition<any, any>[], ctxFactory?: ToolContextFactory): AgentTool<any>[];
7
9
  /**
8
10
  * Synthesize a minimal ToolDefinition from an AgentTool.
9
11
  *
@@ -1 +1 @@
1
- {"version":3,"file":"tool-definition-wrapper.d.ts","sourceRoot":"","sources":["../../../src/core/tools/tool-definition-wrapper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAE/E,oEAAoE;AACpE,wBAAgB,kBAAkB,CAAC,QAAQ,GAAG,OAAO,EACpD,UAAU,EAAE,cAAc,CAAC,GAAG,EAAE,QAAQ,CAAC,EACzC,UAAU,CAAC,EAAE,MAAM,gBAAgB,GACjC,SAAS,CAAC,GAAG,EAAE,QAAQ,CAAC,CAY1B;AAED,0EAA0E;AAC1E,wBAAgB,mBAAmB,CAClC,WAAW,EAAE,cAAc,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,EACvC,UAAU,CAAC,EAAE,MAAM,gBAAgB,GACjC,SAAS,CAAC,GAAG,CAAC,EAAE,CAElB;AAED;;;;;GAKG;AACH,wBAAgB,iCAAiC,CAAC,IAAI,EAAE,SAAS,CAAC,GAAG,CAAC,GAAG,cAAc,CAAC,GAAG,EAAE,OAAO,CAAC,CAWpG","sourcesContent":["import type { AgentTool } from \"@punch-bot/agent\";\nimport type { ExtensionContext, ToolDefinition } from \"../extensions/types.ts\";\n\n/** Wrap a ToolDefinition into an AgentTool for the core runtime. */\nexport function wrapToolDefinition<TDetails = unknown>(\n\tdefinition: ToolDefinition<any, TDetails>,\n\tctxFactory?: () => ExtensionContext,\n): AgentTool<any, TDetails> {\n\treturn {\n\t\tname: definition.name,\n\t\tlabel: definition.label,\n\t\tdescription: definition.description,\n\t\tparameters: definition.parameters,\n\t\tconstrainedSampling: definition.constrainedSampling,\n\t\tprepareArguments: definition.prepareArguments,\n\t\texecutionMode: definition.executionMode,\n\t\texecute: (toolCallId, params, signal, onUpdate, ctx?: ExtensionContext) =>\n\t\t\tdefinition.execute(toolCallId, params, signal, onUpdate, ctx ?? (ctxFactory?.() as ExtensionContext)),\n\t};\n}\n\n/** Wrap multiple ToolDefinitions into AgentTools for the core runtime. */\nexport function wrapToolDefinitions(\n\tdefinitions: ToolDefinition<any, any>[],\n\tctxFactory?: () => ExtensionContext,\n): AgentTool<any>[] {\n\treturn definitions.map((definition) => wrapToolDefinition(definition, ctxFactory));\n}\n\n/**\n * Synthesize a minimal ToolDefinition from an AgentTool.\n *\n * This keeps AgentSession's internal registry definition-first even when a caller\n * provides plain AgentTool overrides that do not include prompt metadata or renderers.\n */\nexport function createToolDefinitionFromAgentTool(tool: AgentTool<any>): ToolDefinition<any, unknown> {\n\treturn {\n\t\tname: tool.name,\n\t\tlabel: tool.label,\n\t\tdescription: tool.description,\n\t\tparameters: tool.parameters as any,\n\t\tconstrainedSampling: tool.constrainedSampling,\n\t\tprepareArguments: tool.prepareArguments,\n\t\texecutionMode: tool.executionMode,\n\t\texecute: async (toolCallId, params, signal, onUpdate) => tool.execute(toolCallId, params, signal, onUpdate),\n\t};\n}\n"]}
1
+ {"version":3,"file":"tool-definition-wrapper.d.ts","sourceRoot":"","sources":["../../../src/core/tools/tool-definition-wrapper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,KAAK,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAEnF,6CAA6C;AAC7C,MAAM,MAAM,kBAAkB,GAAG,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,SAAS,KAAK,oBAAoB,CAAC;AAE/G,oEAAoE;AACpE,wBAAgB,kBAAkB,CAAC,QAAQ,GAAG,OAAO,EACpD,UAAU,EAAE,cAAc,CAAC,GAAG,EAAE,QAAQ,CAAC,EACzC,UAAU,CAAC,EAAE,kBAAkB,GAC7B,SAAS,CAAC,GAAG,EAAE,QAAQ,CAAC,CAmB1B;AAED,0EAA0E;AAC1E,wBAAgB,mBAAmB,CAClC,WAAW,EAAE,cAAc,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,EACvC,UAAU,CAAC,EAAE,kBAAkB,GAC7B,SAAS,CAAC,GAAG,CAAC,EAAE,CAElB;AAED;;;;;GAKG;AACH,wBAAgB,iCAAiC,CAAC,IAAI,EAAE,SAAS,CAAC,GAAG,CAAC,GAAG,cAAc,CAAC,GAAG,EAAE,OAAO,CAAC,CAYpG"}
@@ -5,10 +5,11 @@ export function wrapToolDefinition(definition, ctxFactory) {
5
5
  label: definition.label,
6
6
  description: definition.description,
7
7
  parameters: definition.parameters,
8
+ outputSchema: definition.outputSchema,
8
9
  constrainedSampling: definition.constrainedSampling,
9
10
  prepareArguments: definition.prepareArguments,
10
11
  executionMode: definition.executionMode,
11
- execute: (toolCallId, params, signal, onUpdate, ctx) => definition.execute(toolCallId, params, signal, onUpdate, ctx ?? ctxFactory?.()),
12
+ execute: (toolCallId, params, signal, onUpdate, ctx) => definition.execute(toolCallId, params, signal, onUpdate, ctx ?? ctxFactory?.(toolCallId, signal)),
12
13
  };
13
14
  }
14
15
  /** Wrap multiple ToolDefinitions into AgentTools for the core runtime. */
@@ -27,6 +28,7 @@ export function createToolDefinitionFromAgentTool(tool) {
27
28
  label: tool.label,
28
29
  description: tool.description,
29
30
  parameters: tool.parameters,
31
+ outputSchema: tool.outputSchema,
30
32
  constrainedSampling: tool.constrainedSampling,
31
33
  prepareArguments: tool.prepareArguments,
32
34
  executionMode: tool.executionMode,
@@ -1 +1 @@
1
- {"version":3,"file":"tool-definition-wrapper.js","sourceRoot":"","sources":["../../../src/core/tools/tool-definition-wrapper.ts"],"names":[],"mappings":"AAGA,oEAAoE;AACpE,MAAM,UAAU,kBAAkB,CACjC,UAAyC,EACzC,UAAmC,EACR;IAC3B,OAAO;QACN,IAAI,EAAE,UAAU,CAAC,IAAI;QACrB,KAAK,EAAE,UAAU,CAAC,KAAK;QACvB,WAAW,EAAE,UAAU,CAAC,WAAW;QACnC,UAAU,EAAE,UAAU,CAAC,UAAU;QACjC,mBAAmB,EAAE,UAAU,CAAC,mBAAmB;QACnD,gBAAgB,EAAE,UAAU,CAAC,gBAAgB;QAC7C,aAAa,EAAE,UAAU,CAAC,aAAa;QACvC,OAAO,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAsB,EAAE,EAAE,CACzE,UAAU,CAAC,OAAO,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAK,UAAU,EAAE,EAAuB,CAAC;KACtG,CAAC;AAAA,CACF;AAED,0EAA0E;AAC1E,MAAM,UAAU,mBAAmB,CAClC,WAAuC,EACvC,UAAmC,EAChB;IACnB,OAAO,WAAW,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,kBAAkB,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC;AAAA,CACnF;AAED;;;;;GAKG;AACH,MAAM,UAAU,iCAAiC,CAAC,IAAoB,EAAgC;IACrG,OAAO;QACN,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,WAAW,EAAE,IAAI,CAAC,WAAW;QAC7B,UAAU,EAAE,IAAI,CAAC,UAAiB;QAClC,mBAAmB,EAAE,IAAI,CAAC,mBAAmB;QAC7C,gBAAgB,EAAE,IAAI,CAAC,gBAAgB;QACvC,aAAa,EAAE,IAAI,CAAC,aAAa;QACjC,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC;KAC3G,CAAC;AAAA,CACF","sourcesContent":["import type { AgentTool } from \"@punch-bot/agent\";\nimport type { ExtensionContext, ToolDefinition } from \"../extensions/types.ts\";\n\n/** Wrap a ToolDefinition into an AgentTool for the core runtime. */\nexport function wrapToolDefinition<TDetails = unknown>(\n\tdefinition: ToolDefinition<any, TDetails>,\n\tctxFactory?: () => ExtensionContext,\n): AgentTool<any, TDetails> {\n\treturn {\n\t\tname: definition.name,\n\t\tlabel: definition.label,\n\t\tdescription: definition.description,\n\t\tparameters: definition.parameters,\n\t\tconstrainedSampling: definition.constrainedSampling,\n\t\tprepareArguments: definition.prepareArguments,\n\t\texecutionMode: definition.executionMode,\n\t\texecute: (toolCallId, params, signal, onUpdate, ctx?: ExtensionContext) =>\n\t\t\tdefinition.execute(toolCallId, params, signal, onUpdate, ctx ?? (ctxFactory?.() as ExtensionContext)),\n\t};\n}\n\n/** Wrap multiple ToolDefinitions into AgentTools for the core runtime. */\nexport function wrapToolDefinitions(\n\tdefinitions: ToolDefinition<any, any>[],\n\tctxFactory?: () => ExtensionContext,\n): AgentTool<any>[] {\n\treturn definitions.map((definition) => wrapToolDefinition(definition, ctxFactory));\n}\n\n/**\n * Synthesize a minimal ToolDefinition from an AgentTool.\n *\n * This keeps AgentSession's internal registry definition-first even when a caller\n * provides plain AgentTool overrides that do not include prompt metadata or renderers.\n */\nexport function createToolDefinitionFromAgentTool(tool: AgentTool<any>): ToolDefinition<any, unknown> {\n\treturn {\n\t\tname: tool.name,\n\t\tlabel: tool.label,\n\t\tdescription: tool.description,\n\t\tparameters: tool.parameters as any,\n\t\tconstrainedSampling: tool.constrainedSampling,\n\t\tprepareArguments: tool.prepareArguments,\n\t\texecutionMode: tool.executionMode,\n\t\texecute: async (toolCallId, params, signal, onUpdate) => tool.execute(toolCallId, params, signal, onUpdate),\n\t};\n}\n"]}
1
+ {"version":3,"file":"tool-definition-wrapper.js","sourceRoot":"","sources":["../../../src/core/tools/tool-definition-wrapper.ts"],"names":[],"mappings":"AAMA,oEAAoE;AACpE,MAAM,UAAU,kBAAkB,CACjC,UAAyC,EACzC,UAA+B;IAE/B,OAAO;QACN,IAAI,EAAE,UAAU,CAAC,IAAI;QACrB,KAAK,EAAE,UAAU,CAAC,KAAK;QACvB,WAAW,EAAE,UAAU,CAAC,WAAW;QACnC,UAAU,EAAE,UAAU,CAAC,UAAU;QACjC,YAAY,EAAE,UAAU,CAAC,YAAY;QACrC,mBAAmB,EAAE,UAAU,CAAC,mBAAmB;QACnD,gBAAgB,EAAE,UAAU,CAAC,gBAAgB;QAC7C,aAAa,EAAE,UAAU,CAAC,aAAa;QACvC,OAAO,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAA0B,EAAE,EAAE,CAC7E,UAAU,CAAC,OAAO,CACjB,UAAU,EACV,MAAM,EACN,MAAM,EACN,QAAQ,EACR,GAAG,IAAK,UAAU,EAAE,CAAC,UAAU,EAAE,MAAM,CAA0B,CACjE;KACF,CAAC;AACH,CAAC;AAED,0EAA0E;AAC1E,MAAM,UAAU,mBAAmB,CAClC,WAAuC,EACvC,UAA+B;IAE/B,OAAO,WAAW,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,kBAAkB,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC;AACpF,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iCAAiC,CAAC,IAAoB;IACrE,OAAO;QACN,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,WAAW,EAAE,IAAI,CAAC,WAAW;QAC7B,UAAU,EAAE,IAAI,CAAC,UAAiB;QAClC,YAAY,EAAE,IAAI,CAAC,YAAY;QAC/B,mBAAmB,EAAE,IAAI,CAAC,mBAAmB;QAC7C,gBAAgB,EAAE,IAAI,CAAC,gBAAgB;QACvC,aAAa,EAAE,IAAI,CAAC,aAAa;QACjC,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC;KAC3G,CAAC;AACH,CAAC","sourcesContent":["import type { AgentTool } from \"@punch-bot/agent\";\nimport type { ExtensionToolContext, ToolDefinition } from \"../extensions/types.ts\";\n\n/** Creates the context for one tool call. */\nexport type ToolContextFactory = (toolCallId: string, signal: AbortSignal | undefined) => ExtensionToolContext;\n\n/** Wrap a ToolDefinition into an AgentTool for the core runtime. */\nexport function wrapToolDefinition<TDetails = unknown>(\n\tdefinition: ToolDefinition<any, TDetails>,\n\tctxFactory?: ToolContextFactory,\n): AgentTool<any, TDetails> {\n\treturn {\n\t\tname: definition.name,\n\t\tlabel: definition.label,\n\t\tdescription: definition.description,\n\t\tparameters: definition.parameters,\n\t\toutputSchema: definition.outputSchema,\n\t\tconstrainedSampling: definition.constrainedSampling,\n\t\tprepareArguments: definition.prepareArguments,\n\t\texecutionMode: definition.executionMode,\n\t\texecute: (toolCallId, params, signal, onUpdate, ctx?: ExtensionToolContext) =>\n\t\t\tdefinition.execute(\n\t\t\t\ttoolCallId,\n\t\t\t\tparams,\n\t\t\t\tsignal,\n\t\t\t\tonUpdate,\n\t\t\t\tctx ?? (ctxFactory?.(toolCallId, signal) as ExtensionToolContext),\n\t\t\t),\n\t};\n}\n\n/** Wrap multiple ToolDefinitions into AgentTools for the core runtime. */\nexport function wrapToolDefinitions(\n\tdefinitions: ToolDefinition<any, any>[],\n\tctxFactory?: ToolContextFactory,\n): AgentTool<any>[] {\n\treturn definitions.map((definition) => wrapToolDefinition(definition, ctxFactory));\n}\n\n/**\n * Synthesize a minimal ToolDefinition from an AgentTool.\n *\n * This keeps AgentSession's internal registry definition-first even when a caller\n * provides plain AgentTool overrides that do not include prompt metadata or renderers.\n */\nexport function createToolDefinitionFromAgentTool(tool: AgentTool<any>): ToolDefinition<any, unknown> {\n\treturn {\n\t\tname: tool.name,\n\t\tlabel: tool.label,\n\t\tdescription: tool.description,\n\t\tparameters: tool.parameters as any,\n\t\toutputSchema: tool.outputSchema,\n\t\tconstrainedSampling: tool.constrainedSampling,\n\t\tprepareArguments: tool.prepareArguments,\n\t\texecutionMode: tool.executionMode,\n\t\texecute: async (toolCallId, params, signal, onUpdate) => tool.execute(toolCallId, params, signal, onUpdate),\n\t};\n}\n"]}
@@ -67,4 +67,18 @@ export declare function truncateLine(line: string, maxChars?: number): {
67
67
  text: string;
68
68
  wasTruncated: boolean;
69
69
  };
70
+ export interface MiddleTruncationResult {
71
+ /** The start and end of the content with a `…N chars truncated…` marker between them. */
72
+ content: string;
73
+ truncated: boolean;
74
+ /** Characters left out. */
75
+ removedChars: number;
76
+ totalBytes: number;
77
+ totalLines: number;
78
+ }
79
+ /**
80
+ * Keep the start and the end of `content`, half of `maxBytes` each, and replace the middle with a
81
+ * `…N chars truncated…` marker, like Codex does for tool output. Cuts only at character boundaries.
82
+ */
83
+ export declare function truncateMiddle(content: string, maxBytes: number): MiddleTruncationResult;
70
84
  //# sourceMappingURL=truncate.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"truncate.d.ts","sourceRoot":"","sources":["../../../src/core/tools/truncate.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,eAAO,MAAM,iBAAiB,OAAO,CAAC;AACtC,eAAO,MAAM,iBAAiB,QAAY,CAAC;AAC3C,eAAO,MAAM,oBAAoB,MAAM,CAAC;AAExC,MAAM,WAAW,gBAAgB;IAChC,4BAA4B;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,kCAAkC;IAClC,SAAS,EAAE,OAAO,CAAC;IACnB,sEAAsE;IACtE,WAAW,EAAE,OAAO,GAAG,OAAO,GAAG,IAAI,CAAC;IACtC,oDAAoD;IACpD,UAAU,EAAE,MAAM,CAAC;IACnB,oDAAoD;IACpD,UAAU,EAAE,MAAM,CAAC;IACnB,uDAAuD;IACvD,WAAW,EAAE,MAAM,CAAC;IACpB,8CAA8C;IAC9C,WAAW,EAAE,MAAM,CAAC;IACpB,yFAAyF;IACzF,eAAe,EAAE,OAAO,CAAC;IACzB,2EAA2E;IAC3E,qBAAqB,EAAE,OAAO,CAAC;IAC/B,2CAA2C;IAC3C,QAAQ,EAAE,MAAM,CAAC;IACjB,2CAA2C;IAC3C,QAAQ,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,iBAAiB;IACjC,8CAA8C;IAC9C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,8CAA8C;IAC9C,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB;AAaD;;GAEG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAQhD;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,iBAAsB,GAAG,gBAAgB,CAkF/F;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,iBAAsB,GAAG,gBAAgB,CAyE/F;AAuBD;;;GAGG;AACH,wBAAgB,YAAY,CAC3B,IAAI,EAAE,MAAM,EACZ,QAAQ,GAAE,MAA6B,GACrC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,OAAO,CAAA;CAAE,CAKzC","sourcesContent":["/**\n * Shared truncation utilities for tool outputs.\n *\n * Truncation is based on two independent limits - whichever is hit first wins:\n * - Line limit (default: 2000 lines)\n * - Byte limit (default: 50KB)\n *\n * Never returns partial lines (except bash tail truncation edge case).\n */\n\nexport const DEFAULT_MAX_LINES = 2000;\nexport const DEFAULT_MAX_BYTES = 50 * 1024; // 50KB\nexport const GREP_MAX_LINE_LENGTH = 500; // Max chars per grep match line\n\nexport interface TruncationResult {\n\t/** The truncated content */\n\tcontent: string;\n\t/** Whether truncation occurred */\n\ttruncated: boolean;\n\t/** Which limit was hit: \"lines\", \"bytes\", or null if not truncated */\n\ttruncatedBy: \"lines\" | \"bytes\" | null;\n\t/** Total number of lines in the original content */\n\ttotalLines: number;\n\t/** Total number of bytes in the original content */\n\ttotalBytes: number;\n\t/** Number of complete lines in the truncated output */\n\toutputLines: number;\n\t/** Number of bytes in the truncated output */\n\toutputBytes: number;\n\t/** Whether the last line was partially truncated (only for tail truncation edge case) */\n\tlastLinePartial: boolean;\n\t/** Whether the first line exceeded the byte limit (for head truncation) */\n\tfirstLineExceedsLimit: boolean;\n\t/** The max lines limit that was applied */\n\tmaxLines: number;\n\t/** The max bytes limit that was applied */\n\tmaxBytes: number;\n}\n\nexport interface TruncationOptions {\n\t/** Maximum number of lines (default: 2000) */\n\tmaxLines?: number;\n\t/** Maximum number of bytes (default: 50KB) */\n\tmaxBytes?: number;\n}\n\nfunction splitLinesForCounting(content: string): string[] {\n\tif (content.length === 0) {\n\t\treturn [];\n\t}\n\tconst lines = content.split(\"\\n\");\n\tif (content.endsWith(\"\\n\")) {\n\t\tlines.pop();\n\t}\n\treturn lines;\n}\n\n/**\n * Format bytes as human-readable size.\n */\nexport function formatSize(bytes: number): string {\n\tif (bytes < 1024) {\n\t\treturn `${bytes}B`;\n\t} else if (bytes < 1024 * 1024) {\n\t\treturn `${(bytes / 1024).toFixed(1)}KB`;\n\t} else {\n\t\treturn `${(bytes / (1024 * 1024)).toFixed(1)}MB`;\n\t}\n}\n\n/**\n * Truncate content from the head (keep first N lines/bytes).\n * Suitable for file reads where you want to see the beginning.\n *\n * Never returns partial lines. If first line exceeds byte limit,\n * returns empty content with firstLineExceedsLimit=true.\n */\nexport function truncateHead(content: string, options: TruncationOptions = {}): TruncationResult {\n\tconst maxLines = options.maxLines ?? DEFAULT_MAX_LINES;\n\tconst maxBytes = options.maxBytes ?? DEFAULT_MAX_BYTES;\n\n\tconst totalBytes = Buffer.byteLength(content, \"utf-8\");\n\tconst lines = splitLinesForCounting(content);\n\tconst totalLines = lines.length;\n\n\t// Check if no truncation needed\n\tif (totalLines <= maxLines && totalBytes <= maxBytes) {\n\t\treturn {\n\t\t\tcontent,\n\t\t\ttruncated: false,\n\t\t\ttruncatedBy: null,\n\t\t\ttotalLines,\n\t\t\ttotalBytes,\n\t\t\toutputLines: totalLines,\n\t\t\toutputBytes: totalBytes,\n\t\t\tlastLinePartial: false,\n\t\t\tfirstLineExceedsLimit: false,\n\t\t\tmaxLines,\n\t\t\tmaxBytes,\n\t\t};\n\t}\n\n\t// Check if first line alone exceeds byte limit\n\tconst firstLineBytes = Buffer.byteLength(lines[0], \"utf-8\");\n\tif (firstLineBytes > maxBytes) {\n\t\treturn {\n\t\t\tcontent: \"\",\n\t\t\ttruncated: true,\n\t\t\ttruncatedBy: \"bytes\",\n\t\t\ttotalLines,\n\t\t\ttotalBytes,\n\t\t\toutputLines: 0,\n\t\t\toutputBytes: 0,\n\t\t\tlastLinePartial: false,\n\t\t\tfirstLineExceedsLimit: true,\n\t\t\tmaxLines,\n\t\t\tmaxBytes,\n\t\t};\n\t}\n\n\t// Collect complete lines that fit\n\tconst outputLinesArr: string[] = [];\n\tlet outputBytesCount = 0;\n\tlet truncatedBy: \"lines\" | \"bytes\" = \"lines\";\n\n\tfor (let i = 0; i < lines.length && i < maxLines; i++) {\n\t\tconst line = lines[i];\n\t\tconst lineBytes = Buffer.byteLength(line, \"utf-8\") + (i > 0 ? 1 : 0); // +1 for newline\n\n\t\tif (outputBytesCount + lineBytes > maxBytes) {\n\t\t\ttruncatedBy = \"bytes\";\n\t\t\tbreak;\n\t\t}\n\n\t\toutputLinesArr.push(line);\n\t\toutputBytesCount += lineBytes;\n\t}\n\n\t// If we exited due to line limit\n\tif (outputLinesArr.length >= maxLines && outputBytesCount <= maxBytes) {\n\t\ttruncatedBy = \"lines\";\n\t}\n\n\tconst outputContent = outputLinesArr.join(\"\\n\");\n\tconst finalOutputBytes = Buffer.byteLength(outputContent, \"utf-8\");\n\n\treturn {\n\t\tcontent: outputContent,\n\t\ttruncated: true,\n\t\ttruncatedBy,\n\t\ttotalLines,\n\t\ttotalBytes,\n\t\toutputLines: outputLinesArr.length,\n\t\toutputBytes: finalOutputBytes,\n\t\tlastLinePartial: false,\n\t\tfirstLineExceedsLimit: false,\n\t\tmaxLines,\n\t\tmaxBytes,\n\t};\n}\n\n/**\n * Truncate content from the tail (keep last N lines/bytes).\n * Suitable for bash output where you want to see the end (errors, final results).\n *\n * May return partial first line if the last line of original content exceeds byte limit.\n */\nexport function truncateTail(content: string, options: TruncationOptions = {}): TruncationResult {\n\tconst maxLines = options.maxLines ?? DEFAULT_MAX_LINES;\n\tconst maxBytes = options.maxBytes ?? DEFAULT_MAX_BYTES;\n\n\tconst totalBytes = Buffer.byteLength(content, \"utf-8\");\n\tconst lines = splitLinesForCounting(content);\n\tconst totalLines = lines.length;\n\n\t// Check if no truncation needed\n\tif (totalLines <= maxLines && totalBytes <= maxBytes) {\n\t\treturn {\n\t\t\tcontent,\n\t\t\ttruncated: false,\n\t\t\ttruncatedBy: null,\n\t\t\ttotalLines,\n\t\t\ttotalBytes,\n\t\t\toutputLines: totalLines,\n\t\t\toutputBytes: totalBytes,\n\t\t\tlastLinePartial: false,\n\t\t\tfirstLineExceedsLimit: false,\n\t\t\tmaxLines,\n\t\t\tmaxBytes,\n\t\t};\n\t}\n\n\t// Work backwards from the end\n\tconst outputLinesArr: string[] = [];\n\tlet outputBytesCount = 0;\n\tlet truncatedBy: \"lines\" | \"bytes\" = \"lines\";\n\tlet lastLinePartial = false;\n\n\tfor (let i = lines.length - 1; i >= 0 && outputLinesArr.length < maxLines; i--) {\n\t\tconst line = lines[i];\n\t\tconst lineBytes = Buffer.byteLength(line, \"utf-8\") + (outputLinesArr.length > 0 ? 1 : 0); // +1 for newline\n\n\t\tif (outputBytesCount + lineBytes > maxBytes) {\n\t\t\ttruncatedBy = \"bytes\";\n\t\t\t// Edge case: if we haven't added ANY lines yet and this line exceeds maxBytes,\n\t\t\t// take the end of the line (partial)\n\t\t\tif (outputLinesArr.length === 0) {\n\t\t\t\tconst truncatedLine = truncateStringToBytesFromEnd(line, maxBytes);\n\t\t\t\toutputLinesArr.unshift(truncatedLine);\n\t\t\t\toutputBytesCount = Buffer.byteLength(truncatedLine, \"utf-8\");\n\t\t\t\tlastLinePartial = true;\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\n\t\toutputLinesArr.unshift(line);\n\t\toutputBytesCount += lineBytes;\n\t}\n\n\t// If we exited due to line limit\n\tif (outputLinesArr.length >= maxLines && outputBytesCount <= maxBytes) {\n\t\ttruncatedBy = \"lines\";\n\t}\n\n\tconst outputContent = outputLinesArr.join(\"\\n\");\n\tconst finalOutputBytes = Buffer.byteLength(outputContent, \"utf-8\");\n\n\treturn {\n\t\tcontent: outputContent,\n\t\ttruncated: true,\n\t\ttruncatedBy,\n\t\ttotalLines,\n\t\ttotalBytes,\n\t\toutputLines: outputLinesArr.length,\n\t\toutputBytes: finalOutputBytes,\n\t\tlastLinePartial,\n\t\tfirstLineExceedsLimit: false,\n\t\tmaxLines,\n\t\tmaxBytes,\n\t};\n}\n\n/**\n * Truncate a string to fit within a byte limit (from the end).\n * Handles multi-byte UTF-8 characters correctly.\n */\nfunction truncateStringToBytesFromEnd(str: string, maxBytes: number): string {\n\tconst buf = Buffer.from(str, \"utf-8\");\n\tif (buf.length <= maxBytes) {\n\t\treturn str;\n\t}\n\n\t// Start from the end, skip maxBytes back\n\tlet start = buf.length - maxBytes;\n\n\t// Find a valid UTF-8 boundary (start of a character)\n\twhile (start < buf.length && (buf[start] & 0xc0) === 0x80) {\n\t\tstart++;\n\t}\n\n\treturn buf.slice(start).toString(\"utf-8\");\n}\n\n/**\n * Truncate a single line to max characters, adding [truncated] suffix.\n * Used for grep match lines.\n */\nexport function truncateLine(\n\tline: string,\n\tmaxChars: number = GREP_MAX_LINE_LENGTH,\n): { text: string; wasTruncated: boolean } {\n\tif (line.length <= maxChars) {\n\t\treturn { text: line, wasTruncated: false };\n\t}\n\treturn { text: `${line.slice(0, maxChars)}... [truncated]`, wasTruncated: true };\n}\n"]}
1
+ {"version":3,"file":"truncate.d.ts","sourceRoot":"","sources":["../../../src/core/tools/truncate.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,eAAO,MAAM,iBAAiB,OAAO,CAAC;AACtC,eAAO,MAAM,iBAAiB,QAAY,CAAC;AAC3C,eAAO,MAAM,oBAAoB,MAAM,CAAC;AAExC,MAAM,WAAW,gBAAgB;IAChC,4BAA4B;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,kCAAkC;IAClC,SAAS,EAAE,OAAO,CAAC;IACnB,sEAAsE;IACtE,WAAW,EAAE,OAAO,GAAG,OAAO,GAAG,IAAI,CAAC;IACtC,oDAAoD;IACpD,UAAU,EAAE,MAAM,CAAC;IACnB,oDAAoD;IACpD,UAAU,EAAE,MAAM,CAAC;IACnB,uDAAuD;IACvD,WAAW,EAAE,MAAM,CAAC;IACpB,8CAA8C;IAC9C,WAAW,EAAE,MAAM,CAAC;IACpB,yFAAyF;IACzF,eAAe,EAAE,OAAO,CAAC;IACzB,2EAA2E;IAC3E,qBAAqB,EAAE,OAAO,CAAC;IAC/B,2CAA2C;IAC3C,QAAQ,EAAE,MAAM,CAAC;IACjB,2CAA2C;IAC3C,QAAQ,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,iBAAiB;IACjC,8CAA8C;IAC9C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,8CAA8C;IAC9C,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB;AAaD;;GAEG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAQhD;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,iBAAsB,GAAG,gBAAgB,CAkF/F;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,iBAAsB,GAAG,gBAAgB,CAyE/F;AAuBD;;;GAGG;AACH,wBAAgB,YAAY,CAC3B,IAAI,EAAE,MAAM,EACZ,QAAQ,GAAE,MAA6B,GACrC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,OAAO,CAAA;CAAE,CAKzC;AAED,MAAM,WAAW,sBAAsB;IACtC,yFAAyF;IACzF,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,OAAO,CAAC;IACnB,2BAA2B;IAC3B,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACnB;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,sBAAsB,CAsBxF"}
@@ -212,4 +212,33 @@ export function truncateLine(line, maxChars = GREP_MAX_LINE_LENGTH) {
212
212
  }
213
213
  return { text: `${line.slice(0, maxChars)}... [truncated]`, wasTruncated: true };
214
214
  }
215
+ /**
216
+ * Keep the start and the end of `content`, half of `maxBytes` each, and replace the middle with a
217
+ * `…N chars truncated…` marker, like Codex does for tool output. Cuts only at character boundaries.
218
+ */
219
+ export function truncateMiddle(content, maxBytes) {
220
+ const buf = Buffer.from(content, "utf-8");
221
+ const totalLines = splitLinesForCounting(content).length;
222
+ if (buf.length <= maxBytes) {
223
+ return { content, truncated: false, removedChars: 0, totalBytes: buf.length, totalLines };
224
+ }
225
+ // Continuation bytes (10xxxxxx) are not character starts.
226
+ const isBoundary = (index) => index >= buf.length || (buf[index] & 0xc0) !== 0x80;
227
+ let headEnd = Math.floor(maxBytes / 2);
228
+ while (headEnd > 0 && !isBoundary(headEnd))
229
+ headEnd--;
230
+ let tailStart = buf.length - (maxBytes - Math.floor(maxBytes / 2));
231
+ while (tailStart < buf.length && !isBoundary(tailStart))
232
+ tailStart++;
233
+ const head = buf.subarray(0, headEnd).toString("utf-8");
234
+ const tail = buf.subarray(tailStart).toString("utf-8");
235
+ const removedChars = Array.from(buf.subarray(headEnd, tailStart).toString("utf-8")).length;
236
+ return {
237
+ content: `${head}…${removedChars} chars truncated…${tail}`,
238
+ truncated: true,
239
+ removedChars,
240
+ totalBytes: buf.length,
241
+ totalLines,
242
+ };
243
+ }
215
244
  //# sourceMappingURL=truncate.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"truncate.js","sourceRoot":"","sources":["../../../src/core/tools/truncate.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,CAAC;AACtC,MAAM,CAAC,MAAM,iBAAiB,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,OAAO;AACnD,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAG,CAAC,CAAC,gCAAgC;AAkCzE,SAAS,qBAAqB,CAAC,OAAe,EAAY;IACzD,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC1B,OAAO,EAAE,CAAC;IACX,CAAC;IACD,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAClC,IAAI,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QAC5B,KAAK,CAAC,GAAG,EAAE,CAAC;IACb,CAAC;IACD,OAAO,KAAK,CAAC;AAAA,CACb;AAED;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,KAAa,EAAU;IACjD,IAAI,KAAK,GAAG,IAAI,EAAE,CAAC;QAClB,OAAO,GAAG,KAAK,GAAG,CAAC;IACpB,CAAC;SAAM,IAAI,KAAK,GAAG,IAAI,GAAG,IAAI,EAAE,CAAC;QAChC,OAAO,GAAG,CAAC,KAAK,GAAG,IAAI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4B,CAAC,GAAW,EAAE,QAAgB,EAAU;IAC5E,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IACtC,IAAI,GAAG,CAAC,MAAM,IAAI,QAAQ,EAAE,CAAC;QAC5B,OAAO,GAAG,CAAC;IACZ,CAAC;IAED,yCAAyC;IACzC,IAAI,KAAK,GAAG,GAAG,CAAC,MAAM,GAAG,QAAQ,CAAC;IAElC,qDAAqD;IACrD,OAAO,KAAK,GAAG,GAAG,CAAC,MAAM,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC;QAC3D,KAAK,EAAE,CAAC;IACT,CAAC;IAED,OAAO,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;AAAA,CAC1C;AAED;;;GAGG;AACH,MAAM,UAAU,YAAY,CAC3B,IAAY,EACZ,QAAQ,GAAW,oBAAoB,EACG;IAC1C,IAAI,IAAI,CAAC,MAAM,IAAI,QAAQ,EAAE,CAAC;QAC7B,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC;IAC5C,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC,iBAAiB,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;AAAA,CACjF","sourcesContent":["/**\n * Shared truncation utilities for tool outputs.\n *\n * Truncation is based on two independent limits - whichever is hit first wins:\n * - Line limit (default: 2000 lines)\n * - Byte limit (default: 50KB)\n *\n * Never returns partial lines (except bash tail truncation edge case).\n */\n\nexport const DEFAULT_MAX_LINES = 2000;\nexport const DEFAULT_MAX_BYTES = 50 * 1024; // 50KB\nexport const GREP_MAX_LINE_LENGTH = 500; // Max chars per grep match line\n\nexport interface TruncationResult {\n\t/** The truncated content */\n\tcontent: string;\n\t/** Whether truncation occurred */\n\ttruncated: boolean;\n\t/** Which limit was hit: \"lines\", \"bytes\", or null if not truncated */\n\ttruncatedBy: \"lines\" | \"bytes\" | null;\n\t/** Total number of lines in the original content */\n\ttotalLines: number;\n\t/** Total number of bytes in the original content */\n\ttotalBytes: number;\n\t/** Number of complete lines in the truncated output */\n\toutputLines: number;\n\t/** Number of bytes in the truncated output */\n\toutputBytes: number;\n\t/** Whether the last line was partially truncated (only for tail truncation edge case) */\n\tlastLinePartial: boolean;\n\t/** Whether the first line exceeded the byte limit (for head truncation) */\n\tfirstLineExceedsLimit: boolean;\n\t/** The max lines limit that was applied */\n\tmaxLines: number;\n\t/** The max bytes limit that was applied */\n\tmaxBytes: number;\n}\n\nexport interface TruncationOptions {\n\t/** Maximum number of lines (default: 2000) */\n\tmaxLines?: number;\n\t/** Maximum number of bytes (default: 50KB) */\n\tmaxBytes?: number;\n}\n\nfunction splitLinesForCounting(content: string): string[] {\n\tif (content.length === 0) {\n\t\treturn [];\n\t}\n\tconst lines = content.split(\"\\n\");\n\tif (content.endsWith(\"\\n\")) {\n\t\tlines.pop();\n\t}\n\treturn lines;\n}\n\n/**\n * Format bytes as human-readable size.\n */\nexport function formatSize(bytes: number): string {\n\tif (bytes < 1024) {\n\t\treturn `${bytes}B`;\n\t} else if (bytes < 1024 * 1024) {\n\t\treturn `${(bytes / 1024).toFixed(1)}KB`;\n\t} else {\n\t\treturn `${(bytes / (1024 * 1024)).toFixed(1)}MB`;\n\t}\n}\n\n/**\n * Truncate content from the head (keep first N lines/bytes).\n * Suitable for file reads where you want to see the beginning.\n *\n * Never returns partial lines. If first line exceeds byte limit,\n * returns empty content with firstLineExceedsLimit=true.\n */\nexport function truncateHead(content: string, options: TruncationOptions = {}): TruncationResult {\n\tconst maxLines = options.maxLines ?? DEFAULT_MAX_LINES;\n\tconst maxBytes = options.maxBytes ?? DEFAULT_MAX_BYTES;\n\n\tconst totalBytes = Buffer.byteLength(content, \"utf-8\");\n\tconst lines = splitLinesForCounting(content);\n\tconst totalLines = lines.length;\n\n\t// Check if no truncation needed\n\tif (totalLines <= maxLines && totalBytes <= maxBytes) {\n\t\treturn {\n\t\t\tcontent,\n\t\t\ttruncated: false,\n\t\t\ttruncatedBy: null,\n\t\t\ttotalLines,\n\t\t\ttotalBytes,\n\t\t\toutputLines: totalLines,\n\t\t\toutputBytes: totalBytes,\n\t\t\tlastLinePartial: false,\n\t\t\tfirstLineExceedsLimit: false,\n\t\t\tmaxLines,\n\t\t\tmaxBytes,\n\t\t};\n\t}\n\n\t// Check if first line alone exceeds byte limit\n\tconst firstLineBytes = Buffer.byteLength(lines[0], \"utf-8\");\n\tif (firstLineBytes > maxBytes) {\n\t\treturn {\n\t\t\tcontent: \"\",\n\t\t\ttruncated: true,\n\t\t\ttruncatedBy: \"bytes\",\n\t\t\ttotalLines,\n\t\t\ttotalBytes,\n\t\t\toutputLines: 0,\n\t\t\toutputBytes: 0,\n\t\t\tlastLinePartial: false,\n\t\t\tfirstLineExceedsLimit: true,\n\t\t\tmaxLines,\n\t\t\tmaxBytes,\n\t\t};\n\t}\n\n\t// Collect complete lines that fit\n\tconst outputLinesArr: string[] = [];\n\tlet outputBytesCount = 0;\n\tlet truncatedBy: \"lines\" | \"bytes\" = \"lines\";\n\n\tfor (let i = 0; i < lines.length && i < maxLines; i++) {\n\t\tconst line = lines[i];\n\t\tconst lineBytes = Buffer.byteLength(line, \"utf-8\") + (i > 0 ? 1 : 0); // +1 for newline\n\n\t\tif (outputBytesCount + lineBytes > maxBytes) {\n\t\t\ttruncatedBy = \"bytes\";\n\t\t\tbreak;\n\t\t}\n\n\t\toutputLinesArr.push(line);\n\t\toutputBytesCount += lineBytes;\n\t}\n\n\t// If we exited due to line limit\n\tif (outputLinesArr.length >= maxLines && outputBytesCount <= maxBytes) {\n\t\ttruncatedBy = \"lines\";\n\t}\n\n\tconst outputContent = outputLinesArr.join(\"\\n\");\n\tconst finalOutputBytes = Buffer.byteLength(outputContent, \"utf-8\");\n\n\treturn {\n\t\tcontent: outputContent,\n\t\ttruncated: true,\n\t\ttruncatedBy,\n\t\ttotalLines,\n\t\ttotalBytes,\n\t\toutputLines: outputLinesArr.length,\n\t\toutputBytes: finalOutputBytes,\n\t\tlastLinePartial: false,\n\t\tfirstLineExceedsLimit: false,\n\t\tmaxLines,\n\t\tmaxBytes,\n\t};\n}\n\n/**\n * Truncate content from the tail (keep last N lines/bytes).\n * Suitable for bash output where you want to see the end (errors, final results).\n *\n * May return partial first line if the last line of original content exceeds byte limit.\n */\nexport function truncateTail(content: string, options: TruncationOptions = {}): TruncationResult {\n\tconst maxLines = options.maxLines ?? DEFAULT_MAX_LINES;\n\tconst maxBytes = options.maxBytes ?? DEFAULT_MAX_BYTES;\n\n\tconst totalBytes = Buffer.byteLength(content, \"utf-8\");\n\tconst lines = splitLinesForCounting(content);\n\tconst totalLines = lines.length;\n\n\t// Check if no truncation needed\n\tif (totalLines <= maxLines && totalBytes <= maxBytes) {\n\t\treturn {\n\t\t\tcontent,\n\t\t\ttruncated: false,\n\t\t\ttruncatedBy: null,\n\t\t\ttotalLines,\n\t\t\ttotalBytes,\n\t\t\toutputLines: totalLines,\n\t\t\toutputBytes: totalBytes,\n\t\t\tlastLinePartial: false,\n\t\t\tfirstLineExceedsLimit: false,\n\t\t\tmaxLines,\n\t\t\tmaxBytes,\n\t\t};\n\t}\n\n\t// Work backwards from the end\n\tconst outputLinesArr: string[] = [];\n\tlet outputBytesCount = 0;\n\tlet truncatedBy: \"lines\" | \"bytes\" = \"lines\";\n\tlet lastLinePartial = false;\n\n\tfor (let i = lines.length - 1; i >= 0 && outputLinesArr.length < maxLines; i--) {\n\t\tconst line = lines[i];\n\t\tconst lineBytes = Buffer.byteLength(line, \"utf-8\") + (outputLinesArr.length > 0 ? 1 : 0); // +1 for newline\n\n\t\tif (outputBytesCount + lineBytes > maxBytes) {\n\t\t\ttruncatedBy = \"bytes\";\n\t\t\t// Edge case: if we haven't added ANY lines yet and this line exceeds maxBytes,\n\t\t\t// take the end of the line (partial)\n\t\t\tif (outputLinesArr.length === 0) {\n\t\t\t\tconst truncatedLine = truncateStringToBytesFromEnd(line, maxBytes);\n\t\t\t\toutputLinesArr.unshift(truncatedLine);\n\t\t\t\toutputBytesCount = Buffer.byteLength(truncatedLine, \"utf-8\");\n\t\t\t\tlastLinePartial = true;\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\n\t\toutputLinesArr.unshift(line);\n\t\toutputBytesCount += lineBytes;\n\t}\n\n\t// If we exited due to line limit\n\tif (outputLinesArr.length >= maxLines && outputBytesCount <= maxBytes) {\n\t\ttruncatedBy = \"lines\";\n\t}\n\n\tconst outputContent = outputLinesArr.join(\"\\n\");\n\tconst finalOutputBytes = Buffer.byteLength(outputContent, \"utf-8\");\n\n\treturn {\n\t\tcontent: outputContent,\n\t\ttruncated: true,\n\t\ttruncatedBy,\n\t\ttotalLines,\n\t\ttotalBytes,\n\t\toutputLines: outputLinesArr.length,\n\t\toutputBytes: finalOutputBytes,\n\t\tlastLinePartial,\n\t\tfirstLineExceedsLimit: false,\n\t\tmaxLines,\n\t\tmaxBytes,\n\t};\n}\n\n/**\n * Truncate a string to fit within a byte limit (from the end).\n * Handles multi-byte UTF-8 characters correctly.\n */\nfunction truncateStringToBytesFromEnd(str: string, maxBytes: number): string {\n\tconst buf = Buffer.from(str, \"utf-8\");\n\tif (buf.length <= maxBytes) {\n\t\treturn str;\n\t}\n\n\t// Start from the end, skip maxBytes back\n\tlet start = buf.length - maxBytes;\n\n\t// Find a valid UTF-8 boundary (start of a character)\n\twhile (start < buf.length && (buf[start] & 0xc0) === 0x80) {\n\t\tstart++;\n\t}\n\n\treturn buf.slice(start).toString(\"utf-8\");\n}\n\n/**\n * Truncate a single line to max characters, adding [truncated] suffix.\n * Used for grep match lines.\n */\nexport function truncateLine(\n\tline: string,\n\tmaxChars: number = GREP_MAX_LINE_LENGTH,\n): { text: string; wasTruncated: boolean } {\n\tif (line.length <= maxChars) {\n\t\treturn { text: line, wasTruncated: false };\n\t}\n\treturn { text: `${line.slice(0, maxChars)}... [truncated]`, wasTruncated: true };\n}\n"]}
1
+ {"version":3,"file":"truncate.js","sourceRoot":"","sources":["../../../src/core/tools/truncate.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,CAAC;AACtC,MAAM,CAAC,MAAM,iBAAiB,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,OAAO;AACnD,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAG,CAAC,CAAC,gCAAgC;AAkCzE,SAAS,qBAAqB,CAAC,OAAe;IAC7C,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC1B,OAAO,EAAE,CAAC;IACX,CAAC;IACD,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAClC,IAAI,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QAC5B,KAAK,CAAC,GAAG,EAAE,CAAC;IACb,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,KAAa;IACvC,IAAI,KAAK,GAAG,IAAI,EAAE,CAAC;QAClB,OAAO,GAAG,KAAK,GAAG,CAAC;IACpB,CAAC;SAAM,IAAI,KAAK,GAAG,IAAI,GAAG,IAAI,EAAE,CAAC;QAChC,OAAO,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC;IACzC,CAAC;SAAM,CAAC;QACP,OAAO,GAAG,CAAC,KAAK,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC;IAClD,CAAC;AACF,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,OAAe,EAAE,OAAO,GAAsB,EAAE;IAC5E,MAAM,QAAQ,G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AAC,CAAC,CAAC;IACvC,OAAO,OAAO,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC;QAAE,OAAO,EAAE,CAAC;IACtD,IAAI,SAAS,GAAG,GAAG,CAAC,MAAM,GAAG,CAAC,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC,CAAC;IACnE,OAAO,SAAS,GAAG,GAAG,CAAC,MAAM,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC;QAAE,SAAS,EAAE,CAAC;IACrE,MAAM,IAAI,GAAG,GAAG,CAAC,QAAQ,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IACxD,MAAM,IAAI,GAAG,GAAG,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IACvD,MAAM,YAAY,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC;IAC3F,OAAO;QACN,OAAO,EAAE,GAAG,IAAI,IAAI,YAAY,oBAAoB,IAAI,EAAE;QAC1D,SAAS,EAAE,IAAI;QACf,YAAY;QACZ,UAAU,EAAE,GAAG,CAAC,MAAM;QACtB,UAAU;KACV,CAAC;AACH,CAAC","sourcesContent":["/**\n * Shared truncation utilities for tool outputs.\n *\n * Truncation is based on two independent limits - whichever is hit first wins:\n * - Line limit (default: 2000 lines)\n * - Byte limit (default: 50KB)\n *\n * Never returns partial lines (except bash tail truncation edge case).\n */\n\nexport const DEFAULT_MAX_LINES = 2000;\nexport const DEFAULT_MAX_BYTES = 50 * 1024; // 50KB\nexport const GREP_MAX_LINE_LENGTH = 500; // Max chars per grep match line\n\nexport interface TruncationResult {\n\t/** The truncated content */\n\tcontent: string;\n\t/** Whether truncation occurred */\n\ttruncated: boolean;\n\t/** Which limit was hit: \"lines\", \"bytes\", or null if not truncated */\n\ttruncatedBy: \"lines\" | \"bytes\" | null;\n\t/** Total number of lines in the original content */\n\ttotalLines: number;\n\t/** Total number of bytes in the original content */\n\ttotalBytes: number;\n\t/** Number of complete lines in the truncated output */\n\toutputLines: number;\n\t/** Number of bytes in the truncated output */\n\toutputBytes: number;\n\t/** Whether the last line was partially truncated (only for tail truncation edge case) */\n\tlastLinePartial: boolean;\n\t/** Whether the first line exceeded the byte limit (for head truncation) */\n\tfirstLineExceedsLimit: boolean;\n\t/** The max lines limit that was applied */\n\tmaxLines: number;\n\t/** The max bytes limit that was applied */\n\tmaxBytes: number;\n}\n\nexport interface TruncationOptions {\n\t/** Maximum number of lines (default: 2000) */\n\tmaxLines?: number;\n\t/** Maximum number of bytes (default: 50KB) */\n\tmaxBytes?: number;\n}\n\nfunction splitLinesForCounting(content: string): string[] {\n\tif (content.length === 0) {\n\t\treturn [];\n\t}\n\tconst lines = content.split(\"\\n\");\n\tif (content.endsWith(\"\\n\")) {\n\t\tlines.pop();\n\t}\n\treturn lines;\n}\n\n/**\n * Format bytes as human-readable size.\n */\nexport function formatSize(bytes: number): string {\n\tif (bytes < 1024) {\n\t\treturn `${bytes}B`;\n\t} else if (bytes < 1024 * 1024) {\n\t\treturn `${(bytes / 1024).toFixed(1)}KB`;\n\t} else {\n\t\treturn `${(bytes / (1024 * 1024)).toFixed(1)}MB`;\n\t}\n}\n\n/**\n * Truncate content from the head (keep first N lines/bytes).\n * Suitable for file reads where you want to see the beginning.\n *\n * Never returns partial lines. If first line exceeds byte limit,\n * returns empty content with firstLineExceedsLimit=true.\n */\nexport function truncateHead(content: string, options: TruncationOptions = {}): TruncationResult {\n\tconst maxLines = options.maxLines ?? DEFAULT_MAX_LINES;\n\tconst maxBytes = options.maxBytes ?? DEFAULT_MAX_BYTES;\n\n\tconst totalBytes = Buffer.byteLength(content, \"utf-8\");\n\tconst lines = splitLinesForCounting(content);\n\tconst totalLines = lines.length;\n\n\t// Check if no truncation needed\n\tif (totalLines <= maxLines && totalBytes <= maxBytes) {\n\t\treturn {\n\t\t\tcontent,\n\t\t\ttruncated: false,\n\t\t\ttruncatedBy: null,\n\t\t\ttotalLines,\n\t\t\ttotalBytes,\n\t\t\toutputLines: totalLines,\n\t\t\toutputBytes: totalBytes,\n\t\t\tlastLinePartial: false,\n\t\t\tfirstLineExceedsLimit: false,\n\t\t\tmaxLines,\n\t\t\tmaxBytes,\n\t\t};\n\t}\n\n\t// Check if first line alone exceeds byte limit\n\tconst firstLineBytes = Buffer.byteLength(lines[0], \"utf-8\");\n\tif (firstLineBytes > maxBytes) {\n\t\treturn {\n\t\t\tcontent: \"\",\n\t\t\ttruncated: true,\n\t\t\ttruncatedBy: \"bytes\",\n\t\t\ttotalLines,\n\t\t\ttotalBytes,\n\t\t\toutputLines: 0,\n\t\t\toutputBytes: 0,\n\t\t\tlastLinePartial: false,\n\t\t\tfirstLineExceedsLimit: true,\n\t\t\tmaxLines,\n\t\t\tmaxBytes,\n\t\t};\n\t}\n\n\t// Collect complete lines that fit\n\tconst outputLinesArr: string[] = [];\n\tlet outputBytesCount = 0;\n\tlet truncatedBy: \"lines\" | \"bytes\" = \"lines\";\n\n\tfor (let i = 0; i < lines.length && i < maxLines; i++) {\n\t\tconst line = lines[i];\n\t\tconst lineBytes = Buffer.byteLength(line, \"utf-8\") + (i > 0 ? 1 : 0); // +1 for newline\n\n\t\tif (outputBytesCount + lineBytes > maxBytes) {\n\t\t\ttruncatedBy = \"bytes\";\n\t\t\tbreak;\n\t\t}\n\n\t\toutputLinesArr.push(line);\n\t\toutputBytesCount += lineBytes;\n\t}\n\n\t// If we exited due to line limit\n\tif (outputLinesArr.length >= maxLines && outputBytesCount <= maxBytes) {\n\t\ttruncatedBy = \"lines\";\n\t}\n\n\tconst outputContent = outputLinesArr.join(\"\\n\");\n\tconst finalOutputBytes = Buffer.byteLength(outputContent, \"utf-8\");\n\n\treturn {\n\t\tcontent: outputContent,\n\t\ttruncated: true,\n\t\ttruncatedBy,\n\t\ttotalLines,\n\t\ttotalBytes,\n\t\toutputLines: outputLinesArr.length,\n\t\toutputBytes: finalOutputBytes,\n\t\tlastLinePartial: false,\n\t\tfirstLineExceedsLimit: false,\n\t\tmaxLines,\n\t\tmaxBytes,\n\t};\n}\n\n/**\n * Truncate content from the tail (keep last N lines/bytes).\n * Suitable for bash output where you want to see the end (errors, final results).\n *\n * May return partial first line if the last line of original content exceeds byte limit.\n */\nexport function truncateTail(content: string, options: TruncationOptions = {}): TruncationResult {\n\tconst maxLines = options.maxLines ?? DEFAULT_MAX_LINES;\n\tconst maxBytes = options.maxBytes ?? DEFAULT_MAX_BYTES;\n\n\tconst totalBytes = Buffer.byteLength(content, \"utf-8\");\n\tconst lines = splitLinesForCounting(content);\n\tconst totalLines = lines.length;\n\n\t// Check if no truncation needed\n\tif (totalLines <= maxLines && totalBytes <= maxBytes) {\n\t\treturn {\n\t\t\tcontent,\n\t\t\ttruncated: false,\n\t\t\ttruncatedBy: null,\n\t\t\ttotalLines,\n\t\t\ttotalBytes,\n\t\t\toutputLines: totalLines,\n\t\t\toutputBytes: totalBytes,\n\t\t\tlastLinePartial: false,\n\t\t\tfirstLineExceedsLimit: false,\n\t\t\tmaxLines,\n\t\t\tmaxBytes,\n\t\t};\n\t}\n\n\t// Work backwards from the end\n\tconst outputLinesArr: string[] = [];\n\tlet outputBytesCount = 0;\n\tlet truncatedBy: \"lines\" | \"bytes\" = \"lines\";\n\tlet lastLinePartial = false;\n\n\tfor (let i = lines.length - 1; i >= 0 && outputLinesArr.length < maxLines; i--) {\n\t\tconst line = lines[i];\n\t\tconst lineBytes = Buffer.byteLength(line, \"utf-8\") + (outputLinesArr.length > 0 ? 1 : 0); // +1 for newline\n\n\t\tif (outputBytesCount + lineBytes > maxBytes) {\n\t\t\ttruncatedBy = \"bytes\";\n\t\t\t// Edge case: if we haven't added ANY lines yet and this line exceeds maxBytes,\n\t\t\t// take the end of the line (partial)\n\t\t\tif (outputLinesArr.length === 0) {\n\t\t\t\tconst truncatedLine = truncateStringToBytesFromEnd(line, maxBytes);\n\t\t\t\toutputLinesArr.unshift(truncatedLine);\n\t\t\t\toutputBytesCount = Buffer.byteLength(truncatedLine, \"utf-8\");\n\t\t\t\tlastLinePartial = true;\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\n\t\toutputLinesArr.unshift(line);\n\t\toutputBytesCount += lineBytes;\n\t}\n\n\t// If we exited due to line limit\n\tif (outputLinesArr.length >= maxLines && outputBytesCount <= maxBytes) {\n\t\ttruncatedBy = \"lines\";\n\t}\n\n\tconst outputContent = outputLinesArr.join(\"\\n\");\n\tconst finalOutputBytes = Buffer.byteLength(outputContent, \"utf-8\");\n\n\treturn {\n\t\tcontent: outputContent,\n\t\ttruncated: true,\n\t\ttruncatedBy,\n\t\ttotalLines,\n\t\ttotalBytes,\n\t\toutputLines: outputLinesArr.length,\n\t\toutputBytes: finalOutputBytes,\n\t\tlastLinePartial,\n\t\tfirstLineExceedsLimit: false,\n\t\tmaxLines,\n\t\tmaxBytes,\n\t};\n}\n\n/**\n * Truncate a string to fit within a byte limit (from the end).\n * Handles multi-byte UTF-8 characters correctly.\n */\nfunction truncateStringToBytesFromEnd(str: string, maxBytes: number): string {\n\tconst buf = Buffer.from(str, \"utf-8\");\n\tif (buf.length <= maxBytes) {\n\t\treturn str;\n\t}\n\n\t// Start from the end, skip maxBytes back\n\tlet start = buf.length - maxBytes;\n\n\t// Find a valid UTF-8 boundary (start of a character)\n\twhile (start < buf.length && (buf[start] & 0xc0) === 0x80) {\n\t\tstart++;\n\t}\n\n\treturn buf.slice(start).toString(\"utf-8\");\n}\n\n/**\n * Truncate a single line to max characters, adding [truncated] suffix.\n * Used for grep match lines.\n */\nexport function truncateLine(\n\tline: string,\n\tmaxChars: number = GREP_MAX_LINE_LENGTH,\n): { text: string; wasTruncated: boolean } {\n\tif (line.length <= maxChars) {\n\t\treturn { text: line, wasTruncated: false };\n\t}\n\treturn { text: `${line.slice(0, maxChars)}... [truncated]`, wasTruncated: true };\n}\n\nexport interface MiddleTruncationResult {\n\t/** The start and end of the content with a `…N chars truncated…` marker between them. */\n\tcontent: string;\n\ttruncated: boolean;\n\t/** Characters left out. */\n\tremovedChars: number;\n\ttotalBytes: number;\n\ttotalLines: number;\n}\n\n/**\n * Keep the start and the end of `content`, half of `maxBytes` each, and replace the middle with a\n * `…N chars truncated…` marker, like Codex does for tool output. Cuts only at character boundaries.\n */\nexport function truncateMiddle(content: string, maxBytes: number): MiddleTruncationResult {\n\tconst buf = Buffer.from(content, \"utf-8\");\n\tconst totalLines = splitLinesForCounting(content).length;\n\tif (buf.length <= maxBytes) {\n\t\treturn { content, truncated: false, removedChars: 0, totalBytes: buf.length, totalLines };\n\t}\n\t// Continuation bytes (10xxxxxx) are not character starts.\n\tconst isBoundary = (index: number) => index >= buf.length || (buf[index] & 0xc0) !== 0x80;\n\tlet headEnd = Math.floor(maxBytes / 2);\n\twhile (headEnd > 0 && !isBoundary(headEnd)) headEnd--;\n\tlet tailStart = buf.length - (maxBytes - Math.floor(maxBytes / 2));\n\twhile (tailStart < buf.length && !isBoundary(tailStart)) tailStart++;\n\tconst head = buf.subarray(0, headEnd).toString(\"utf-8\");\n\tconst tail = buf.subarray(tailStart).toString(\"utf-8\");\n\tconst removedChars = Array.from(buf.subarray(headEnd, tailStart).toString(\"utf-8\")).length;\n\treturn {\n\t\tcontent: `${head}…${removedChars} chars truncated…${tail}`,\n\t\ttruncated: true,\n\t\tremovedChars,\n\t\ttotalBytes: buf.length,\n\t\ttotalLines,\n\t};\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"write.d.ts","sourceRoot":"","sources":["../../../src/core/tools/write.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAGlD,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAoB,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAM/E,QAAA,MAAM,WAAW;;;EAGf,CAAC;AAEH,eAAO,MAAM,iCAAiC;;;CAGpC,CAAC;AAEX,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,OAAO,WAAW,CAAC,CAAC;AAExD;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC/B,8BAA8B;IAC9B,SAAS,EAAE,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACpE,mCAAmC;IACnC,KAAK,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACtC;AAOD,MAAM,WAAW,gBAAgB;IAChC,oEAAoE;IACpE,UAAU,CAAC,EAAE,eAAe,CAAC;CAC7B;AAED,wBAAgB,yBAAyB,CACxC,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,gBAAgB,GACxB,cAAc,CAAC,OAAO,WAAW,EAAE,SAAS,CAAC,CA8C/C;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,SAAS,CAAC,OAAO,WAAW,CAAC,CAEtG","sourcesContent":["import type { AgentTool } from \"@punch-bot/agent\";\nimport { mkdir as fsMkdir, writeFile as fsWriteFile } from \"fs/promises\";\nimport { dirname } from \"path\";\nimport { type Static, Type } from \"typebox\";\nimport type { ExtensionContext, ToolDefinition } from \"../extensions/types.ts\";\nimport { withFileMutationQueue } from \"./file-mutation-queue.ts\";\nimport { resolveToCwd } from \"./path-utils.ts\";\nimport { writeRenderers } from \"./renderers/write.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\n\nconst writeSchema = Type.Object({\n\tpath: Type.String({ description: \"Path to the file to write (relative or absolute)\" }),\n\tcontent: Type.String({ description: \"Content to write to the file\" }),\n});\n\nexport const writeToolSystemPromptContribution = {\n\tsnippet: \"Create or overwrite files\",\n\tguidelines: [\"Use write only for new files or complete rewrites.\"],\n} as const;\n\nexport type WriteToolInput = Static<typeof writeSchema>;\n\n/**\n * Pluggable operations for the write tool.\n * Override these to delegate file writing to remote systems (for example SSH).\n */\nexport interface WriteOperations {\n\t/** Write content to a file */\n\twriteFile: (absolutePath: string, content: string) => Promise<void>;\n\t/** Create directory recursively */\n\tmkdir: (dir: string) => Promise<void>;\n}\n\nconst defaultWriteOperations: WriteOperations = {\n\twriteFile: (path, content) => fsWriteFile(path, content, \"utf-8\"),\n\tmkdir: (dir) => fsMkdir(dir, { recursive: true }).then(() => {}),\n};\n\nexport interface WriteToolOptions {\n\t/** Custom operations for file writing. Default: local filesystem */\n\toperations?: WriteOperations;\n}\n\nexport function createWriteToolDefinition(\n\tcwd: string,\n\toptions?: WriteToolOptions,\n): ToolDefinition<typeof writeSchema, undefined> {\n\tconst ops = options?.operations ?? defaultWriteOperations;\n\treturn {\n\t\tname: \"write\",\n\t\tlabel: \"write\",\n\t\tdescription:\n\t\t\t\"Write content to a file. Creates the file if it doesn't exist, overwrites if it does. Automatically creates parent directories.\",\n\t\tpromptSnippet: writeToolSystemPromptContribution.snippet,\n\t\tpromptGuidelines: [...writeToolSystemPromptContribution.guidelines],\n\t\tparameters: writeSchema,\n\t\tconstrainedSampling: { type: \"json_schema\", strict: \"prefer\" },\n\t\tasync execute(\n\t\t\t_toolCallId,\n\t\t\t{ path, content }: { path: string; content: string },\n\t\t\tsignal?: AbortSignal,\n\t\t\t_onUpdate?,\n\t\t\tctx?: ExtensionContext,\n\t\t) {\n\t\t\tconst absolutePath = resolveToCwd(path, ctx?.cwd || cwd);\n\t\t\tconst dir = dirname(absolutePath);\n\t\t\treturn withFileMutationQueue(absolutePath, async () => {\n\t\t\t\t// Do not reject from an abort event listener here: that would release the\n\t\t\t\t// mutation queue while an in-flight filesystem operation may still finish.\n\t\t\t\t// Checking signal.aborted after each await observes the same aborts while\n\t\t\t\t// keeping the queue locked until the current operation has settled.\n\t\t\t\tconst throwIfAborted = (): void => {\n\t\t\t\t\tif (signal?.aborted) throw new Error(\"Operation aborted\");\n\t\t\t\t};\n\n\t\t\t\tthrowIfAborted();\n\t\t\t\t// Create parent directories if needed.\n\t\t\t\tawait ops.mkdir(dir);\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\t// Write the file contents.\n\t\t\t\tawait ops.writeFile(absolutePath, content);\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text: `Successfully wrote to ${path}` }],\n\t\t\t\t\tdetails: undefined,\n\t\t\t\t};\n\t\t\t});\n\t\t},\n\t\t...writeRenderers,\n\t};\n}\n\nexport function createWriteTool(cwd: string, options?: WriteToolOptions): AgentTool<typeof writeSchema> {\n\treturn wrapToolDefinition(createWriteToolDefinition(cwd, options));\n}\n"]}
1
+ {"version":3,"file":"write.d.ts","sourceRoot":"","sources":["../../../src/core/tools/write.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAGlD,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAoB,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAK/E,QAAA,MAAM,WAAW;;;EAGf,CAAC;AAEH,eAAO,MAAM,iCAAiC;aAC7C,OAAO,EAAE,2BAA2B;aACpC,UAAU,YAAG,oDAAoD;CACxD,CAAC;AAEX,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,OAAO,WAAW,CAAC,CAAC;AAExD;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC/B,8BAA8B;IAC9B,SAAS,EAAE,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACpE,mCAAmC;IACnC,KAAK,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACtC;AAOD,MAAM,WAAW,gBAAgB;IAChC,oEAAoE;IACpE,UAAU,CAAC,EAAE,eAAe,CAAC;CAC7B;AAED,wBAAgB,yBAAyB,CACxC,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,gBAAgB,GACxB,cAAc,CAAC,OAAO,WAAW,EAAE,SAAS,CAAC,CA6C/C;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,SAAS,CAAC,OAAO,WAAW,CAAC,CAEtG"}
@@ -3,7 +3,6 @@ import { dirname } from "path";
3
3
  import { Type } from "typebox";
4
4
  import { withFileMutationQueue } from "./file-mutation-queue.js";
5
5
  import { resolveToCwd } from "./path-utils.js";
6
- import { writeRenderers } from "./renderers/write.js";
7
6
  import { wrapToolDefinition } from "./tool-definition-wrapper.js";
8
7
  const writeSchema = Type.Object({
9
8
  path: Type.String({ description: "Path to the file to write (relative or absolute)" }),
@@ -52,7 +51,6 @@ export function createWriteToolDefinition(cwd, options) {
52
51
  };
53
52
  });
54
53
  },
55
- ...writeRenderers,
56
54
  };
57
55
  }
58
56
  export function createWriteTool(cwd, options) {
@@ -1 +1 @@
1
- {"version":3,"file":"write.js","sourceRoot":"","sources":["../../../src/core/tools/write.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,IAAI,OAAO,EAAE,SAAS,IAAI,WAAW,EAAE,MAAM,aAAa,CAAC;AACzE,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAE5C,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAElE,MAAM,WAAW,GAAG,IAAI,CAAC,MAAM,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AAG,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;YAClC,OAAO,qBAAqB,CAAC,YAAY,EAAE,KAAK,IAAI,EAAE,CAAC;gBACtD,0EAA0E;gBAC1E,2EAA2E;gBAC3E,0EAA0E;gBAC1E,oEAAoE;gBACpE,MAAM,cAAc,GAAG,GAAS,EAAE,CAAC;oBAClC,IAAI,MAAM,EAAE,OAAO;wBAAE,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;gBAAA,CAC1D,CAAC;gBAEF,cAAc,EAAE,CAAC;gBACjB,uCAAuC;gBACvC,MAAM,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBACrB,cAAc,EAAE,CAAC;gBAEjB,2BAA2B;gBAC3B,MAAM,GAAG,CAAC,SAAS,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;gBAC3C,cAAc,EAAE,CAAC;gBAEjB,OAAO;oBACN,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,yBAAyB,IAAI,EAAE,EAAE,CAAC;oBAClE,OAAO,EAAE,SAAS;iBAClB,CAAC;YAAA,CACF,CAAC,CAAC;QAAA,CACH;QACD,GAAG,cAAc;KACjB,CAAC;AAAA,CACF;AAED,MAAM,UAAU,eAAe,CAAC,GAAW,EAAE,OAA0B,EAAiC;IACvG,OAAO,kBAAkB,CAAC,yBAAyB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;AAAA,CACnE","sourcesContent":["import type { AgentTool } from \"@punch-bot/agent\";\nimport { mkdir as fsMkdir, writeFile as fsWriteFile } from \"fs/promises\";\nimport { dirname } from \"path\";\nimport { type Static, Type } from \"typebox\";\nimport type { ExtensionContext, ToolDefinition } from \"../extensions/types.ts\";\nimport { withFileMutationQueue } from \"./file-mutation-queue.ts\";\nimport { resolveToCwd } from \"./path-utils.ts\";\nimport { writeRenderers } from \"./renderers/write.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\n\nconst writeSchema = Type.Object({\n\tpath: Type.String({ description: \"Path to the file to write (relative or absolute)\" }),\n\tcontent: Type.String({ description: \"Content to write to the file\" }),\n});\n\nexport const writeToolSystemPromptContribution = {\n\tsnippet: \"Create or overwrite files\",\n\tguidelines: [\"Use write only for new files or complete rewrites.\"],\n} as const;\n\nexport type WriteToolInput = Static<typeof writeSchema>;\n\n/**\n * Pluggable operations for the write tool.\n * Override these to delegate file writing to remote systems (for example SSH).\n */\nexport interface WriteOperations {\n\t/** Write content to a file */\n\twriteFile: (absolutePath: string, content: string) => Promise<void>;\n\t/** Create directory recursively */\n\tmkdir: (dir: string) => Promise<void>;\n}\n\nconst defaultWriteOperations: WriteOperations = {\n\twriteFile: (path, content) => fsWriteFile(path, content, \"utf-8\"),\n\tmkdir: (dir) => fsMkdir(dir, { recursive: true }).then(() => {}),\n};\n\nexport interface WriteToolOptions {\n\t/** Custom operations for file writing. Default: local filesystem */\n\toperations?: WriteOperations;\n}\n\nexport function createWriteToolDefinition(\n\tcwd: string,\n\toptions?: WriteToolOptions,\n): ToolDefinition<typeof writeSchema, undefined> {\n\tconst ops = options?.operations ?? defaultWriteOperations;\n\treturn {\n\t\tname: \"write\",\n\t\tlabel: \"write\",\n\t\tdescription:\n\t\t\t\"Write content to a file. Creates the file if it doesn't exist, overwrites if it does. Automatically creates parent directories.\",\n\t\tpromptSnippet: writeToolSystemPromptContribution.snippet,\n\t\tpromptGuidelines: [...writeToolSystemPromptContribution.guidelines],\n\t\tparameters: writeSchema,\n\t\tconstrainedSampling: { type: \"json_schema\", strict: \"prefer\" },\n\t\tasync execute(\n\t\t\t_toolCallId,\n\t\t\t{ path, content }: { path: string; content: string },\n\t\t\tsignal?: AbortSignal,\n\t\t\t_onUpdate?,\n\t\t\tctx?: ExtensionContext,\n\t\t) {\n\t\t\tconst absolutePath = resolveToCwd(path, ctx?.cwd || cwd);\n\t\t\tconst dir = dirname(absolutePath);\n\t\t\treturn withFileMutationQueue(absolutePath, async () => {\n\t\t\t\t// Do not reject from an abort event listener here: that would release the\n\t\t\t\t// mutation queue while an in-flight filesystem operation may still finish.\n\t\t\t\t// Checking signal.aborted after each await observes the same aborts while\n\t\t\t\t// keeping the queue locked until the current operation has settled.\n\t\t\t\tconst throwIfAborted = (): void => {\n\t\t\t\t\tif (signal?.aborted) throw new Error(\"Operation aborted\");\n\t\t\t\t};\n\n\t\t\t\tthrowIfAborted();\n\t\t\t\t// Create parent directories if needed.\n\t\t\t\tawait ops.mkdir(dir);\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\t// Write the file contents.\n\t\t\t\tawait ops.writeFile(absolutePath, content);\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text: `Successfully wrote to ${path}` }],\n\t\t\t\t\tdetails: undefined,\n\t\t\t\t};\n\t\t\t});\n\t\t},\n\t\t...writeRenderers,\n\t};\n}\n\nexport function createWriteTool(cwd: string, options?: WriteToolOptions): AgentTool<typeof writeSchema> {\n\treturn wrapToolDefinition(createWriteToolDefinition(cwd, options));\n}\n"]}
1
+ {"version":3,"file":"write.js","sourceRoot":"","sources":["../../../src/core/tools/write.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,IAAI,OAAO,EAAE,SAAS,IAAI,WAAW,EAAE,MAAM,aAAa,CAAC;AACzE,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAE5C,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAElE,MAAM,WAAW,GAAG,IAAI,CAAC,MAAM,CAAC;IAC/B,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,kDAAkD,EAAE,CAAC;IACtF,OAAO,EAAE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E,2EAA2E;gBAC3E,0EAA0E;gBAC1E,oEAAoE;gBACpE,MAAM,cAAc,GAAG,GAAS,EAAE;oBACjC,IAAI,MAAM,EAAE,OAAO;wBAAE,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;gBAC3D,CAAC,CAAC;gBAEF,cAAc,EAAE,CAAC;gBACjB,uCAAuC;gBACvC,MAAM,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBACrB,cAAc,EAAE,CAAC;gBAEjB,2BAA2B;gBAC3B,MAAM,GAAG,CAAC,SAAS,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;gBAC3C,cAAc,EAAE,CAAC;gBAEjB,OAAO;oBACN,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,yBAAyB,IAAI,EAAE,EAAE,CAAC;oBAClE,OAAO,EAAE,SAAS;iBAClB,CAAC;YACH,CAAC,CAAC,CAAC;QACJ,CAAC;KACD,CAAC;AACH,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,GAAW,EAAE,OAA0B;IACtE,OAAO,kBAAkB,CAAC,yBAAyB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;AACpE,CAAC","sourcesContent":["import type { AgentTool } from \"@punch-bot/agent\";\nimport { mkdir as fsMkdir, writeFile as fsWriteFile } from \"fs/promises\";\nimport { dirname } from \"path\";\nimport { type Static, Type } from \"typebox\";\nimport type { ExtensionContext, ToolDefinition } from \"../extensions/types.ts\";\nimport { withFileMutationQueue } from \"./file-mutation-queue.ts\";\nimport { resolveToCwd } from \"./path-utils.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\n\nconst writeSchema = Type.Object({\n\tpath: Type.String({ description: \"Path to the file to write (relative or absolute)\" }),\n\tcontent: Type.String({ description: \"Content to write to the file\" }),\n});\n\nexport const writeToolSystemPromptContribution = {\n\tsnippet: \"Create or overwrite files\",\n\tguidelines: [\"Use write only for new files or complete rewrites.\"],\n} as const;\n\nexport type WriteToolInput = Static<typeof writeSchema>;\n\n/**\n * Pluggable operations for the write tool.\n * Override these to delegate file writing to remote systems (for example SSH).\n */\nexport interface WriteOperations {\n\t/** Write content to a file */\n\twriteFile: (absolutePath: string, content: string) => Promise<void>;\n\t/** Create directory recursively */\n\tmkdir: (dir: string) => Promise<void>;\n}\n\nconst defaultWriteOperations: WriteOperations = {\n\twriteFile: (path, content) => fsWriteFile(path, content, \"utf-8\"),\n\tmkdir: (dir) => fsMkdir(dir, { recursive: true }).then(() => {}),\n};\n\nexport interface WriteToolOptions {\n\t/** Custom operations for file writing. Default: local filesystem */\n\toperations?: WriteOperations;\n}\n\nexport function createWriteToolDefinition(\n\tcwd: string,\n\toptions?: WriteToolOptions,\n): ToolDefinition<typeof writeSchema, undefined> {\n\tconst ops = options?.operations ?? defaultWriteOperations;\n\treturn {\n\t\tname: \"write\",\n\t\tlabel: \"write\",\n\t\tdescription:\n\t\t\t\"Write content to a file. Creates the file if it doesn't exist, overwrites if it does. Automatically creates parent directories.\",\n\t\tpromptSnippet: writeToolSystemPromptContribution.snippet,\n\t\tpromptGuidelines: [...writeToolSystemPromptContribution.guidelines],\n\t\tparameters: writeSchema,\n\t\tconstrainedSampling: { type: \"json_schema\", strict: \"prefer\" },\n\t\tasync execute(\n\t\t\t_toolCallId,\n\t\t\t{ path, content }: { path: string; content: string },\n\t\t\tsignal?: AbortSignal,\n\t\t\t_onUpdate?,\n\t\t\tctx?: ExtensionContext,\n\t\t) {\n\t\t\tconst absolutePath = resolveToCwd(path, ctx?.cwd || cwd);\n\t\t\tconst dir = dirname(absolutePath);\n\t\t\treturn withFileMutationQueue(absolutePath, async () => {\n\t\t\t\t// Do not reject from an abort event listener here: that would release the\n\t\t\t\t// mutation queue while an in-flight filesystem operation may still finish.\n\t\t\t\t// Checking signal.aborted after each await observes the same aborts while\n\t\t\t\t// keeping the queue locked until the current operation has settled.\n\t\t\t\tconst throwIfAborted = (): void => {\n\t\t\t\t\tif (signal?.aborted) throw new Error(\"Operation aborted\");\n\t\t\t\t};\n\n\t\t\t\tthrowIfAborted();\n\t\t\t\t// Create parent directories if needed.\n\t\t\t\tawait ops.mkdir(dir);\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\t// Write the file contents.\n\t\t\t\tawait ops.writeFile(absolutePath, content);\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text: `Successfully wrote to ${path}` }],\n\t\t\t\t\tdetails: undefined,\n\t\t\t\t};\n\t\t\t});\n\t\t},\n\t};\n}\n\nexport function createWriteTool(cwd: string, options?: WriteToolOptions): AgentTool<typeof writeSchema> {\n\treturn wrapToolDefinition(createWriteToolDefinition(cwd, options));\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"trust-manager.d.ts","sourceRoot":"","sources":["../../src/core/trust-manager.ts"],"names":[],"mappings":"AAQA,MAAM,MAAM,oBAAoB,GAAG,OAAO,GAAG,IAAI,CAAC;AAElD,MAAM,WAAW,sBAAsB;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,kBAAkB;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,oBAAoB,CAAC;CAC/B;AAED,MAAM,WAAW,kBAAkB;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,kBAAkB,EAAE,CAAC;IAC9B,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB;AAkCD,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAIzE;AAED,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;IAAE,kBAAkB,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,kBAAkB,EAAE,CA8BpH;AAkFD;;;;;;GAMG;AACH,wBAAgB,iCAAiC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAsBtE;AAED,qBAAa,iBAAiB;IAC7B,OAAO,CAAC,SAAS,CAAS;IAE1B,YAAY,QAAQ,EAAE,MAAM,EAE3B;IAED,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,oBAAoB,CAErC;IAED,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,sBAAsB,GAAG,IAAI,CAKnD;IAED,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,oBAAoB,GAAG,IAAI,CAErD;IAED,OAAO,CAAC,SAAS,EAAE,kBAAkB,EAAE,GAAG,IAAI,CAa7C;CACD","sourcesContent":["import { existsSync, mkdirSync, readFileSync, writeFileSync } from \"node:fs\";\nimport { homedir } from \"node:os\";\nimport { dirname, join } from \"node:path\";\nimport lockfile from \"proper-lockfile\";\nimport { CONFIG_DIR_NAME } from \"../config.ts\";\nimport { canonicalizePath, resolvePath } from \"../utils/paths.ts\";\nimport { stripBom } from \"../utils/text.ts\";\n\nexport type ProjectTrustDecision = boolean | null;\n\nexport interface ProjectTrustStoreEntry {\n\tpath: string;\n\tdecision: boolean;\n}\n\nexport interface ProjectTrustUpdate {\n\tpath: string;\n\tdecision: ProjectTrustDecision;\n}\n\nexport interface ProjectTrustOption {\n\tlabel: string;\n\ttrusted: boolean;\n\tupdates: ProjectTrustUpdate[];\n\tsavedPath?: string;\n}\n\ntype TrustFile = Record<string, boolean | null | undefined>;\n\nconst TRUST_REQUIRING_PROJECT_CONFIG_RESOURCES = [\n\t\"settings.json\",\n\t\"extensions\",\n\t\"skills\",\n\t\"prompts\",\n\t\"themes\",\n\t\"SYSTEM.md\",\n\t\"APPEND_SYSTEM.md\",\n] as const;\n\nfunction normalizeCwd(cwd: string): string {\n\treturn canonicalizePath(resolvePath(cwd));\n}\n\nfunction findNearestTrustEntry(data: TrustFile, cwd: string): ProjectTrustStoreEntry | null {\n\tlet currentDir = normalizeCwd(cwd);\n\twhile (true) {\n\t\tconst value = data[currentDir];\n\t\tif (value === true || value === false) {\n\t\t\treturn { path: currentDir, decision: value };\n\t\t}\n\n\t\tconst parentDir = dirname(currentDir);\n\t\tif (parentDir === currentDir) {\n\t\t\treturn null;\n\t\t}\n\t\tcurrentDir = parentDir;\n\t}\n}\n\nexport function getProjectTrustParentPath(cwd: string): string | undefined {\n\tconst trustPath = normalizeCwd(cwd);\n\tconst parentDir = dirname(trustPath);\n\treturn parentDir === trustPath ? undefined : parentDir;\n}\n\nexport function getProjectTrustOptions(cwd: string, options?: { includeSessionOnly?: boolean }): ProjectTrustOption[] {\n\tconst trustPath = normalizeCwd(cwd);\n\tconst trustOptions: ProjectTrustOption[] = [\n\t\t{ label: \"Trust\", trusted: true, updates: [{ path: trustPath, decision: true }], savedPath: trustPath },\n\t];\n\tconst parentPath = getProjectTrustParentPath(cwd);\n\tif (parentPath !== undefined) {\n\t\ttrustOptions.push({\n\t\t\tlabel: `Trust parent folder (${parentPath})`,\n\t\t\ttrusted: true,\n\t\t\tupdates: [\n\t\t\t\t{ path: parentPath, decision: true },\n\t\t\t\t{ path: trustPath, decision: null },\n\t\t\t],\n\t\t\tsavedPath: parentPath,\n\t\t});\n\t}\n\tif (options?.includeSessionOnly) {\n\t\ttrustOptions.push({ label: \"Trust (this session only)\", trusted: true, updates: [] });\n\t}\n\ttrustOptions.push({\n\t\tlabel: \"Do not trust\",\n\t\ttrusted: false,\n\t\tupdates: [{ path: trustPath, decision: false }],\n\t\tsavedPath: trustPath,\n\t});\n\tif (options?.includeSessionOnly) {\n\t\ttrustOptions.push({ label: \"Do not trust (this session only)\", trusted: false, updates: [] });\n\t}\n\treturn trustOptions;\n}\n\nfunction readTrustFile(path: string): TrustFile {\n\tif (!existsSync(path)) {\n\t\treturn {};\n\t}\n\n\tlet parsed: unknown;\n\ttry {\n\t\tparsed = JSON.parse(stripBom(readFileSync(path, \"utf-8\")));\n\t} catch (error) {\n\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\tthrow new Error(`Failed to read trust store ${path}: ${message}`);\n\t}\n\n\tif (typeof parsed !== \"object\" || parsed === null || Array.isArray(parsed)) {\n\t\tthrow new Error(`Invalid trust store ${path}: expected an object`);\n\t}\n\n\tconst data: TrustFile = {};\n\tfor (const [key, value] of Object.entries(parsed)) {\n\t\tif (value !== true && value !== false && value !== null) {\n\t\t\tthrow new Error(`Invalid trust store ${path}: value for ${JSON.stringify(key)} must be true, false, or null`);\n\t\t}\n\t\tdata[key] = value;\n\t}\n\treturn data;\n}\n\nfunction writeTrustFile(path: string, data: TrustFile): void {\n\tconst sorted: TrustFile = {};\n\tfor (const key of Object.keys(data).sort()) {\n\t\tconst value = data[key];\n\t\tif (value === true || value === false || value === null) {\n\t\t\tsorted[key] = value;\n\t\t}\n\t}\n\tmkdirSync(dirname(path), { recursive: true });\n\twriteFileSync(path, `${JSON.stringify(sorted, null, 2)}\\n`, \"utf-8\");\n}\n\nfunction acquireTrustLockSync(path: string): () => void {\n\tconst trustDir = dirname(path);\n\tmkdirSync(trustDir, { recursive: true });\n\tconst maxAttempts = 10;\n\tconst delayMs = 20;\n\tlet lastError: unknown;\n\n\tfor (let attempt = 1; attempt <= maxAttempts; attempt++) {\n\t\ttry {\n\t\t\treturn lockfile.lockSync(trustDir, { realpath: false, lockfilePath: `${path}.lock` });\n\t\t} catch (error) {\n\t\t\tconst code =\n\t\t\t\ttypeof error === \"object\" && error !== null && \"code\" in error\n\t\t\t\t\t? String((error as { code?: unknown }).code)\n\t\t\t\t\t: undefined;\n\t\t\tif (code !== \"ELOCKED\" || attempt === maxAttempts) {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tlastError = error;\n\t\t\tconst start = Date.now();\n\t\t\twhile (Date.now() - start < delayMs) {\n\t\t\t\t// Sleep synchronously to avoid changing trust store callers to async.\n\t\t\t}\n\t\t}\n\t}\n\n\tif (lastError instanceof Error) {\n\t\tthrow lastError;\n\t}\n\tthrow new Error(\"Failed to acquire trust store lock\");\n}\n\nfunction withTrustFileLock<T>(path: string, fn: () => T): T {\n\tconst release = acquireTrustLockSync(path);\n\ttry {\n\t\treturn fn();\n\t} finally {\n\t\trelease();\n\t}\n}\n\n/**\n * Returns true when cwd has project-local resources that must be gated by\n * project trust: trust-requiring entries under cwd/.pi, or .agents/skills in\n * cwd or one of its ancestors. Returns false when no such project resources\n * exist. The user/global ~/.agents/skills directory is always treated as a\n * trusted user resource and is ignored here, even when cwd is $HOME.\n */\nexport function hasTrustRequiringProjectResources(cwd: string): boolean {\n\tconst homeDir = canonicalizePath(resolvePath(process.env.HOME || homedir()));\n\tconst userAgentsSkillsDir = join(homeDir, \".agents\", \"skills\");\n\tlet currentDir = canonicalizePath(resolvePath(cwd));\n\n\tconst configDir = join(currentDir, CONFIG_DIR_NAME);\n\tif (TRUST_REQUIRING_PROJECT_CONFIG_RESOURCES.some((entry) => existsSync(join(configDir, entry)))) {\n\t\treturn true;\n\t}\n\n\twhile (true) {\n\t\tconst agentsSkillsDir = join(currentDir, \".agents\", \"skills\");\n\t\tif (agentsSkillsDir !== userAgentsSkillsDir && existsSync(agentsSkillsDir)) {\n\t\t\treturn true;\n\t\t}\n\n\t\tconst parentDir = dirname(currentDir);\n\t\tif (parentDir === currentDir) {\n\t\t\treturn false;\n\t\t}\n\t\tcurrentDir = parentDir;\n\t}\n}\n\nexport class ProjectTrustStore {\n\tprivate trustPath: string;\n\n\tconstructor(agentDir: string) {\n\t\tthis.trustPath = join(resolvePath(agentDir), \"trust.json\");\n\t}\n\n\tget(cwd: string): ProjectTrustDecision {\n\t\treturn this.getEntry(cwd)?.decision ?? null;\n\t}\n\n\tgetEntry(cwd: string): ProjectTrustStoreEntry | null {\n\t\treturn withTrustFileLock(this.trustPath, () => {\n\t\t\tconst data = readTrustFile(this.trustPath);\n\t\t\treturn findNearestTrustEntry(data, cwd);\n\t\t});\n\t}\n\n\tset(cwd: string, decision: ProjectTrustDecision): void {\n\t\tthis.setMany([{ path: cwd, decision }]);\n\t}\n\n\tsetMany(decisions: ProjectTrustUpdate[]): void {\n\t\twithTrustFileLock(this.trustPath, () => {\n\t\t\tconst data = readTrustFile(this.trustPath);\n\t\t\tfor (const { path, decision } of decisions) {\n\t\t\t\tconst key = normalizeCwd(path);\n\t\t\t\tif (decision === null) {\n\t\t\t\t\tdelete data[key];\n\t\t\t\t} else {\n\t\t\t\t\tdata[key] = decision;\n\t\t\t\t}\n\t\t\t}\n\t\t\twriteTrustFile(this.trustPath, data);\n\t\t});\n\t}\n}\n"]}
1
+ {"version":3,"file":"trust-manager.d.ts","sourceRoot":"","sources":["../../src/core/trust-manager.ts"],"names":[],"mappings":"AAQA,MAAM,MAAM,oBAAoB,GAAG,OAAO,GAAG,IAAI,CAAC;AAElD,MAAM,WAAW,sBAAsB;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,kBAAkB;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,oBAAoB,CAAC;CAC/B;AAED,MAAM,WAAW,kBAAkB;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,kBAAkB,EAAE,CAAC;IAC9B,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB;AAmCD,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAIzE;AAED,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;IAAE,kBAAkB,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,kBAAkB,EAAE,CA8BpH;AAkFD;;;;;;GAMG;AACH,wBAAgB,iCAAiC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAsBtE;AAED,qBAAa,iBAAiB;IAC7B,OAAO,CAAC,SAAS,CAAS;IAE1B,YAAY,QAAQ,EAAE,MAAM,EAE3B;IAED,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,oBAAoB,CAErC;IAED,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,sBAAsB,GAAG,IAAI,CAKnD;IAED,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,oBAAoB,GAAG,IAAI,CAErD;IAED,OAAO,CAAC,SAAS,EAAE,kBAAkB,EAAE,GAAG,IAAI,CAa7C;CACD"}
@@ -7,6 +7,7 @@ import { canonicalizePath, resolvePath } from "../utils/paths.js";
7
7
  import { stripBom } from "../utils/text.js";
8
8
  const TRUST_REQUIRING_PROJECT_CONFIG_RESOURCES = [
9
9
  "settings.json",
10
+ "mcp.json",
10
11
  "extensions",
11
12
  "skills",
12
13
  "prompts",