@code-yeongyu/senpi 2026.7.17 → 2026.7.20-2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (738) hide show
  1. package/CHANGELOG.md +100 -0
  2. package/README.md +5 -2
  3. package/dist/cli/neo/build-argv.d.ts.map +1 -1
  4. package/dist/cli/neo/build-argv.js +2 -0
  5. package/dist/cli/neo/build-argv.js.map +1 -1
  6. package/dist/core/agent-session-services.d.ts.map +1 -1
  7. package/dist/core/agent-session-services.js +11 -4
  8. package/dist/core/agent-session-services.js.map +1 -1
  9. package/dist/core/agent-session.d.ts +37 -0
  10. package/dist/core/agent-session.d.ts.map +1 -1
  11. package/dist/core/agent-session.js +395 -73
  12. package/dist/core/agent-session.js.map +1 -1
  13. package/dist/core/compaction/compaction.d.ts +2 -2
  14. package/dist/core/compaction/compaction.d.ts.map +1 -1
  15. package/dist/core/compaction/compaction.js +59 -15
  16. package/dist/core/compaction/compaction.js.map +1 -1
  17. package/dist/core/dynamic-prompt/build.d.ts +7 -0
  18. package/dist/core/dynamic-prompt/build.d.ts.map +1 -1
  19. package/dist/core/dynamic-prompt/build.js +5 -0
  20. package/dist/core/dynamic-prompt/build.js.map +1 -1
  21. package/dist/core/dynamic-prompt/workstation.d.ts +35 -0
  22. package/dist/core/dynamic-prompt/workstation.d.ts.map +1 -0
  23. package/dist/core/dynamic-prompt/workstation.js +81 -0
  24. package/dist/core/dynamic-prompt/workstation.js.map +1 -0
  25. package/dist/core/extensions/builtin/compaction/index.d.ts.map +1 -1
  26. package/dist/core/extensions/builtin/compaction/index.js +68 -10
  27. package/dist/core/extensions/builtin/compaction/index.js.map +1 -1
  28. package/dist/core/extensions/builtin/compaction/repair-tool-pairs.d.ts +1 -0
  29. package/dist/core/extensions/builtin/compaction/repair-tool-pairs.d.ts.map +1 -1
  30. package/dist/core/extensions/builtin/compaction/repair-tool-pairs.js +20 -2
  31. package/dist/core/extensions/builtin/compaction/repair-tool-pairs.js.map +1 -1
  32. package/dist/core/extensions/builtin/compaction/speculative.d.ts +7 -1
  33. package/dist/core/extensions/builtin/compaction/speculative.d.ts.map +1 -1
  34. package/dist/core/extensions/builtin/compaction/speculative.js +29 -11
  35. package/dist/core/extensions/builtin/compaction/speculative.js.map +1 -1
  36. package/dist/core/extensions/builtin/compaction/todo-bridge.d.ts +9 -7
  37. package/dist/core/extensions/builtin/compaction/todo-bridge.d.ts.map +1 -1
  38. package/dist/core/extensions/builtin/compaction/todo-bridge.js +34 -9
  39. package/dist/core/extensions/builtin/compaction/todo-bridge.js.map +1 -1
  40. package/dist/core/extensions/builtin/goal/command-registration.d.ts +2 -2
  41. package/dist/core/extensions/builtin/goal/command-registration.d.ts.map +1 -1
  42. package/dist/core/extensions/builtin/goal/command-registration.js +3 -4
  43. package/dist/core/extensions/builtin/goal/command-registration.js.map +1 -1
  44. package/dist/core/extensions/builtin/goal/index.d.ts.map +1 -1
  45. package/dist/core/extensions/builtin/goal/index.js +11 -27
  46. package/dist/core/extensions/builtin/goal/index.js.map +1 -1
  47. package/dist/core/extensions/builtin/goal/tool-registration.d.ts +2 -2
  48. package/dist/core/extensions/builtin/goal/tool-registration.d.ts.map +1 -1
  49. package/dist/core/extensions/builtin/goal/tool-registration.js +2 -3
  50. package/dist/core/extensions/builtin/goal/tool-registration.js.map +1 -1
  51. package/dist/core/extensions/builtin/goal/turn-usage.d.ts +20 -0
  52. package/dist/core/extensions/builtin/goal/turn-usage.d.ts.map +1 -0
  53. package/dist/core/extensions/builtin/goal/turn-usage.js +61 -0
  54. package/dist/core/extensions/builtin/goal/turn-usage.js.map +1 -0
  55. package/dist/core/extensions/builtin/gpt-apply-patch/constants.d.ts +1 -0
  56. package/dist/core/extensions/builtin/gpt-apply-patch/constants.d.ts.map +1 -1
  57. package/dist/core/extensions/builtin/gpt-apply-patch/constants.js +5 -1
  58. package/dist/core/extensions/builtin/gpt-apply-patch/constants.js.map +1 -1
  59. package/dist/core/extensions/builtin/gpt-apply-patch/extension.d.ts +2 -1
  60. package/dist/core/extensions/builtin/gpt-apply-patch/extension.d.ts.map +1 -1
  61. package/dist/core/extensions/builtin/gpt-apply-patch/extension.js +48 -29
  62. package/dist/core/extensions/builtin/gpt-apply-patch/extension.js.map +1 -1
  63. package/dist/core/extensions/builtin/gpt-apply-patch/index.d.ts +2 -2
  64. package/dist/core/extensions/builtin/gpt-apply-patch/index.d.ts.map +1 -1
  65. package/dist/core/extensions/builtin/gpt-apply-patch/index.js +2 -2
  66. package/dist/core/extensions/builtin/gpt-apply-patch/index.js.map +1 -1
  67. package/dist/core/extensions/builtin/gpt-apply-patch/tool.d.ts +1 -1
  68. package/dist/core/extensions/builtin/gpt-apply-patch/tool.d.ts.map +1 -1
  69. package/dist/core/extensions/builtin/gpt-apply-patch/tool.js +5 -3
  70. package/dist/core/extensions/builtin/gpt-apply-patch/tool.js.map +1 -1
  71. package/dist/core/extensions/builtin/gpt-apply-patch/types.d.ts +7 -6
  72. package/dist/core/extensions/builtin/gpt-apply-patch/types.d.ts.map +1 -1
  73. package/dist/core/extensions/builtin/gpt-apply-patch/types.js.map +1 -1
  74. package/dist/core/extensions/builtin/hooks/matcher.d.ts.map +1 -1
  75. package/dist/core/extensions/builtin/hooks/matcher.js +1 -0
  76. package/dist/core/extensions/builtin/hooks/matcher.js.map +1 -1
  77. package/dist/core/extensions/builtin/index.d.ts.map +1 -1
  78. package/dist/core/extensions/builtin/index.js +4 -0
  79. package/dist/core/extensions/builtin/index.js.map +1 -1
  80. package/dist/core/extensions/builtin/mcp/config-schema.d.ts +8 -1
  81. package/dist/core/extensions/builtin/mcp/config-schema.d.ts.map +1 -1
  82. package/dist/core/extensions/builtin/mcp/config-schema.js +23 -0
  83. package/dist/core/extensions/builtin/mcp/config-schema.js.map +1 -1
  84. package/dist/core/extensions/builtin/mcp/config.d.ts +13 -0
  85. package/dist/core/extensions/builtin/mcp/config.d.ts.map +1 -1
  86. package/dist/core/extensions/builtin/mcp/config.js +36 -0
  87. package/dist/core/extensions/builtin/mcp/config.js.map +1 -1
  88. package/dist/core/extensions/builtin/mcp/expose/native-search.d.ts +1 -1
  89. package/dist/core/extensions/builtin/mcp/expose/native-search.d.ts.map +1 -1
  90. package/dist/core/extensions/builtin/mcp/expose/native-search.js +1 -1
  91. package/dist/core/extensions/builtin/mcp/expose/native-search.js.map +1 -1
  92. package/dist/core/extensions/builtin/mcp/expose/policy.js +1 -1
  93. package/dist/core/extensions/builtin/mcp/expose/policy.js.map +1 -1
  94. package/dist/core/extensions/builtin/mcp/expose/status.js +1 -1
  95. package/dist/core/extensions/builtin/mcp/expose/status.js.map +1 -1
  96. package/dist/core/extensions/builtin/mcp/expose/tier-b.d.ts +3 -3
  97. package/dist/core/extensions/builtin/mcp/expose/tier-b.d.ts.map +1 -1
  98. package/dist/core/extensions/builtin/mcp/expose/tier-b.js +10 -10
  99. package/dist/core/extensions/builtin/mcp/expose/tier-b.js.map +1 -1
  100. package/dist/core/extensions/builtin/mcp/expose/tool-search.d.ts +3 -3
  101. package/dist/core/extensions/builtin/mcp/expose/tool-search.d.ts.map +1 -1
  102. package/dist/core/extensions/builtin/mcp/expose/tool-search.js +14 -14
  103. package/dist/core/extensions/builtin/mcp/expose/tool-search.js.map +1 -1
  104. package/dist/core/extensions/builtin/mcp/index.js +5 -5
  105. package/dist/core/extensions/builtin/mcp/index.js.map +1 -1
  106. package/dist/core/extensions/builtin/mcp/service-snapshot.d.ts.map +1 -1
  107. package/dist/core/extensions/builtin/mcp/service-snapshot.js +1 -0
  108. package/dist/core/extensions/builtin/mcp/service-snapshot.js.map +1 -1
  109. package/dist/core/extensions/builtin/mcp/service-types.d.ts +12 -0
  110. package/dist/core/extensions/builtin/mcp/service-types.d.ts.map +1 -1
  111. package/dist/core/extensions/builtin/mcp/service-types.js.map +1 -1
  112. package/dist/core/extensions/builtin/mcp/service.d.ts +2 -2
  113. package/dist/core/extensions/builtin/mcp/service.d.ts.map +1 -1
  114. package/dist/core/extensions/builtin/mcp/service.js +4 -3
  115. package/dist/core/extensions/builtin/mcp/service.js.map +1 -1
  116. package/dist/core/extensions/builtin/mcp/status.js +1 -0
  117. package/dist/core/extensions/builtin/mcp/status.js.map +1 -1
  118. package/dist/core/extensions/builtin/model-fallback/index.d.ts +4 -0
  119. package/dist/core/extensions/builtin/model-fallback/index.d.ts.map +1 -0
  120. package/dist/core/extensions/builtin/model-fallback/index.js +55 -0
  121. package/dist/core/extensions/builtin/model-fallback/index.js.map +1 -0
  122. package/dist/core/extensions/builtin/model-fallback/settings.d.ts +6 -0
  123. package/dist/core/extensions/builtin/model-fallback/settings.d.ts.map +1 -0
  124. package/dist/core/extensions/builtin/model-fallback/settings.js +11 -0
  125. package/dist/core/extensions/builtin/model-fallback/settings.js.map +1 -0
  126. package/dist/core/extensions/builtin/model-fallback/ui.d.ts +12 -0
  127. package/dist/core/extensions/builtin/model-fallback/ui.d.ts.map +1 -0
  128. package/dist/core/extensions/builtin/model-fallback/ui.js +72 -0
  129. package/dist/core/extensions/builtin/model-fallback/ui.js.map +1 -0
  130. package/dist/core/extensions/builtin/nested-agents-md/index.d.ts.map +1 -1
  131. package/dist/core/extensions/builtin/nested-agents-md/index.js +4 -1
  132. package/dist/core/extensions/builtin/nested-agents-md/index.js.map +1 -1
  133. package/dist/core/extensions/builtin/prompt-preset/claude-fable-5.d.ts.map +1 -1
  134. package/dist/core/extensions/builtin/prompt-preset/claude-fable-5.js +5 -1
  135. package/dist/core/extensions/builtin/prompt-preset/claude-fable-5.js.map +1 -1
  136. package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-5.d.ts.map +1 -1
  137. package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-5.js +5 -1
  138. package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-5.js.map +1 -1
  139. package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-6.d.ts.map +1 -1
  140. package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-6.js +5 -1
  141. package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-6.js.map +1 -1
  142. package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-7.d.ts.map +1 -1
  143. package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-7.js +5 -1
  144. package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-7.js.map +1 -1
  145. package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-8.d.ts.map +1 -1
  146. package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-8.js +5 -1
  147. package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-8.js.map +1 -1
  148. package/dist/core/extensions/builtin/prompt-preset/glm-5-2.js +2 -2
  149. package/dist/core/extensions/builtin/prompt-preset/glm-5-2.js.map +1 -1
  150. package/dist/core/extensions/builtin/prompt-preset/gpt-5.2.js +1 -1
  151. package/dist/core/extensions/builtin/prompt-preset/gpt-5.2.js.map +1 -1
  152. package/dist/core/extensions/builtin/prompt-preset/gpt-5.3-codex.js +1 -1
  153. package/dist/core/extensions/builtin/prompt-preset/gpt-5.3-codex.js.map +1 -1
  154. package/dist/core/extensions/builtin/prompt-preset/gpt-5.4.js +1 -1
  155. package/dist/core/extensions/builtin/prompt-preset/gpt-5.4.js.map +1 -1
  156. package/dist/core/extensions/builtin/prompt-preset/gpt-5.5.js +3 -3
  157. package/dist/core/extensions/builtin/prompt-preset/gpt-5.5.js.map +1 -1
  158. package/dist/core/extensions/builtin/prompt-preset/gpt-5.6.js +3 -3
  159. package/dist/core/extensions/builtin/prompt-preset/gpt-5.6.js.map +1 -1
  160. package/dist/core/extensions/builtin/prompt-preset/gpt-5.js +1 -1
  161. package/dist/core/extensions/builtin/prompt-preset/gpt-5.js.map +1 -1
  162. package/dist/core/extensions/builtin/prompt-preset/grok-4.5.d.ts +3 -0
  163. package/dist/core/extensions/builtin/prompt-preset/grok-4.5.d.ts.map +1 -0
  164. package/dist/core/extensions/builtin/prompt-preset/grok-4.5.js +80 -0
  165. package/dist/core/extensions/builtin/prompt-preset/grok-4.5.js.map +1 -0
  166. package/dist/core/extensions/builtin/prompt-preset/kimi-k2-6.js +1 -1
  167. package/dist/core/extensions/builtin/prompt-preset/kimi-k2-6.js.map +1 -1
  168. package/dist/core/extensions/builtin/prompt-preset/kimi-k2-7.js +1 -1
  169. package/dist/core/extensions/builtin/prompt-preset/kimi-k2-7.js.map +1 -1
  170. package/dist/core/extensions/builtin/prompt-preset/kimi-k3.d.ts.map +1 -1
  171. package/dist/core/extensions/builtin/prompt-preset/kimi-k3.js +5 -7
  172. package/dist/core/extensions/builtin/prompt-preset/kimi-k3.js.map +1 -1
  173. package/dist/core/extensions/builtin/prompt-preset/presets.d.ts.map +1 -1
  174. package/dist/core/extensions/builtin/prompt-preset/presets.js +14 -0
  175. package/dist/core/extensions/builtin/prompt-preset/presets.js.map +1 -1
  176. package/dist/core/extensions/builtin/prompt-preset/settings.d.ts +1 -1
  177. package/dist/core/extensions/builtin/prompt-preset/settings.d.ts.map +1 -1
  178. package/dist/core/extensions/builtin/prompt-preset/settings.js +1 -0
  179. package/dist/core/extensions/builtin/prompt-preset/settings.js.map +1 -1
  180. package/dist/core/extensions/builtin/rules/index.d.ts.map +1 -1
  181. package/dist/core/extensions/builtin/rules/index.js +4 -1
  182. package/dist/core/extensions/builtin/rules/index.js.map +1 -1
  183. package/dist/core/extensions/builtin/terminal/shared.d.ts +7 -0
  184. package/dist/core/extensions/builtin/terminal/shared.d.ts.map +1 -1
  185. package/dist/core/extensions/builtin/terminal/shared.js +7 -0
  186. package/dist/core/extensions/builtin/terminal/shared.js.map +1 -1
  187. package/dist/core/extensions/builtin/terminal/tools/bash.d.ts.map +1 -1
  188. package/dist/core/extensions/builtin/terminal/tools/bash.js +68 -6
  189. package/dist/core/extensions/builtin/terminal/tools/bash.js.map +1 -1
  190. package/dist/core/extensions/builtin/todotools/commands.d.ts +18 -0
  191. package/dist/core/extensions/builtin/todotools/commands.d.ts.map +1 -0
  192. package/dist/core/extensions/builtin/todotools/commands.js +395 -0
  193. package/dist/core/extensions/builtin/todotools/commands.js.map +1 -0
  194. package/dist/core/extensions/builtin/todotools/index.d.ts +4 -1
  195. package/dist/core/extensions/builtin/todotools/index.d.ts.map +1 -1
  196. package/dist/core/extensions/builtin/todotools/index.js +17 -14
  197. package/dist/core/extensions/builtin/todotools/index.js.map +1 -1
  198. package/dist/core/extensions/builtin/todotools/markdown.d.ts +13 -0
  199. package/dist/core/extensions/builtin/todotools/markdown.d.ts.map +1 -0
  200. package/dist/core/extensions/builtin/todotools/markdown.js +82 -0
  201. package/dist/core/extensions/builtin/todotools/markdown.js.map +1 -0
  202. package/dist/core/extensions/builtin/todotools/prompt.d.ts +2 -1
  203. package/dist/core/extensions/builtin/todotools/prompt.d.ts.map +1 -1
  204. package/dist/core/extensions/builtin/todotools/prompt.js +50 -153
  205. package/dist/core/extensions/builtin/todotools/prompt.js.map +1 -1
  206. package/dist/core/extensions/builtin/todotools/state.d.ts +67 -14
  207. package/dist/core/extensions/builtin/todotools/state.d.ts.map +1 -1
  208. package/dist/core/extensions/builtin/todotools/state.js +400 -35
  209. package/dist/core/extensions/builtin/todotools/state.js.map +1 -1
  210. package/dist/core/extensions/builtin/todotools/tools/todo.d.ts +22 -0
  211. package/dist/core/extensions/builtin/todotools/tools/todo.d.ts.map +1 -0
  212. package/dist/core/extensions/builtin/todotools/tools/todo.js +229 -0
  213. package/dist/core/extensions/builtin/todotools/tools/todo.js.map +1 -0
  214. package/dist/core/extensions/builtin/video-in/index.d.ts +3 -0
  215. package/dist/core/extensions/builtin/video-in/index.d.ts.map +1 -0
  216. package/dist/core/extensions/builtin/video-in/index.js +111 -0
  217. package/dist/core/extensions/builtin/video-in/index.js.map +1 -0
  218. package/dist/core/extensions/builtin/websearch/index.d.ts.map +1 -1
  219. package/dist/core/extensions/builtin/websearch/index.js +20 -3
  220. package/dist/core/extensions/builtin/websearch/index.js.map +1 -1
  221. package/dist/core/extensions/builtin/websearch/websearch/renderers.d.ts.map +1 -1
  222. package/dist/core/extensions/builtin/websearch/websearch/renderers.js +13 -4
  223. package/dist/core/extensions/builtin/websearch/websearch/renderers.js.map +1 -1
  224. package/dist/core/extensions/builtin/websearch/websearch/search.d.ts +3 -2
  225. package/dist/core/extensions/builtin/websearch/websearch/search.d.ts.map +1 -1
  226. package/dist/core/extensions/builtin/websearch/websearch/search.js +2 -1
  227. package/dist/core/extensions/builtin/websearch/websearch/search.js.map +1 -1
  228. package/dist/core/extensions/builtin/websearch/websearch/tool.d.ts.map +1 -1
  229. package/dist/core/extensions/builtin/websearch/websearch/tool.js +17 -1
  230. package/dist/core/extensions/builtin/websearch/websearch/tool.js.map +1 -1
  231. package/dist/core/extensions/builtin/websearch/websearch/types.d.ts +2 -0
  232. package/dist/core/extensions/builtin/websearch/websearch/types.d.ts.map +1 -1
  233. package/dist/core/extensions/builtin/websearch/websearch/types.js.map +1 -1
  234. package/dist/core/extensions/index.d.ts +1 -0
  235. package/dist/core/extensions/index.d.ts.map +1 -1
  236. package/dist/core/extensions/index.js.map +1 -1
  237. package/dist/core/extensions/loader.d.ts +10 -1
  238. package/dist/core/extensions/loader.d.ts.map +1 -1
  239. package/dist/core/extensions/loader.js +64 -7
  240. package/dist/core/extensions/loader.js.map +1 -1
  241. package/dist/core/extensions/runner.d.ts +6 -2
  242. package/dist/core/extensions/runner.d.ts.map +1 -1
  243. package/dist/core/extensions/runner.js +80 -8
  244. package/dist/core/extensions/runner.js.map +1 -1
  245. package/dist/core/extensions/types.d.ts +116 -18
  246. package/dist/core/extensions/types.d.ts.map +1 -1
  247. package/dist/core/extensions/types.js.map +1 -1
  248. package/dist/core/model-registry.d.ts +5 -1
  249. package/dist/core/model-registry.d.ts.map +1 -1
  250. package/dist/core/model-registry.js +17 -2
  251. package/dist/core/model-registry.js.map +1 -1
  252. package/dist/core/model-runtime.d.ts +12 -1
  253. package/dist/core/model-runtime.d.ts.map +1 -1
  254. package/dist/core/model-runtime.js +51 -9
  255. package/dist/core/model-runtime.js.map +1 -1
  256. package/dist/core/prompt-templates.d.ts +1 -0
  257. package/dist/core/prompt-templates.d.ts.map +1 -1
  258. package/dist/core/prompt-templates.js +4 -4
  259. package/dist/core/prompt-templates.js.map +1 -1
  260. package/dist/core/provider-composer.d.ts +1 -1
  261. package/dist/core/provider-composer.d.ts.map +1 -1
  262. package/dist/core/provider-composer.js +8 -1
  263. package/dist/core/provider-composer.js.map +1 -1
  264. package/dist/core/remote-catalog-provider.d.ts.map +1 -1
  265. package/dist/core/remote-catalog-provider.js +16 -3
  266. package/dist/core/remote-catalog-provider.js.map +1 -1
  267. package/dist/core/resource-loader.d.ts +6 -0
  268. package/dist/core/resource-loader.d.ts.map +1 -1
  269. package/dist/core/resource-loader.js +27 -2
  270. package/dist/core/resource-loader.js.map +1 -1
  271. package/dist/core/retry-fallback/chains.d.ts +29 -0
  272. package/dist/core/retry-fallback/chains.d.ts.map +1 -0
  273. package/dist/core/retry-fallback/chains.js +109 -0
  274. package/dist/core/retry-fallback/chains.js.map +1 -0
  275. package/dist/core/retry-fallback/controller.d.ts +77 -0
  276. package/dist/core/retry-fallback/controller.d.ts.map +1 -0
  277. package/dist/core/retry-fallback/controller.js +157 -0
  278. package/dist/core/retry-fallback/controller.js.map +1 -0
  279. package/dist/core/retry-fallback/cooldown.d.ts +21 -0
  280. package/dist/core/retry-fallback/cooldown.d.ts.map +1 -0
  281. package/dist/core/retry-fallback/cooldown.js +49 -0
  282. package/dist/core/retry-fallback/cooldown.js.map +1 -0
  283. package/dist/core/retry-fallback/log.d.ts +10 -0
  284. package/dist/core/retry-fallback/log.d.ts.map +1 -0
  285. package/dist/core/retry-fallback/log.js +128 -0
  286. package/dist/core/retry-fallback/log.js.map +1 -0
  287. package/dist/core/retry-fallback/validate.d.ts +8 -0
  288. package/dist/core/retry-fallback/validate.d.ts.map +1 -0
  289. package/dist/core/retry-fallback/validate.js +63 -0
  290. package/dist/core/retry-fallback/validate.js.map +1 -0
  291. package/dist/core/sdk.d.ts.map +1 -1
  292. package/dist/core/sdk.js +1 -0
  293. package/dist/core/sdk.js.map +1 -1
  294. package/dist/core/session-manager.d.ts +6 -1
  295. package/dist/core/session-manager.d.ts.map +1 -1
  296. package/dist/core/session-manager.js +19 -3
  297. package/dist/core/session-manager.js.map +1 -1
  298. package/dist/core/settings-manager.d.ts +21 -0
  299. package/dist/core/settings-manager.d.ts.map +1 -1
  300. package/dist/core/settings-manager.js +100 -1
  301. package/dist/core/settings-manager.js.map +1 -1
  302. package/dist/core/tools/bash.d.ts.map +1 -1
  303. package/dist/core/tools/bash.js +20 -5
  304. package/dist/core/tools/bash.js.map +1 -1
  305. package/dist/core/tools/read.js +1 -1
  306. package/dist/core/tools/read.js.map +1 -1
  307. package/dist/extensions/index.d.ts +3 -0
  308. package/dist/extensions/index.d.ts.map +1 -0
  309. package/dist/extensions/index.js +3 -0
  310. package/dist/extensions/index.js.map +1 -0
  311. package/dist/extensions/llama/client.d.ts +61 -0
  312. package/dist/extensions/llama/client.d.ts.map +1 -0
  313. package/dist/extensions/llama/client.js +298 -0
  314. package/dist/extensions/llama/client.js.map +1 -0
  315. package/dist/extensions/llama/huggingface.d.ts +23 -0
  316. package/dist/extensions/llama/huggingface.d.ts.map +1 -0
  317. package/dist/extensions/llama/huggingface.js +139 -0
  318. package/dist/extensions/llama/huggingface.js.map +1 -0
  319. package/dist/extensions/llama/index.d.ts +3 -0
  320. package/dist/extensions/llama/index.d.ts.map +1 -0
  321. package/dist/extensions/llama/index.js +208 -0
  322. package/dist/extensions/llama/index.js.map +1 -0
  323. package/dist/extensions/llama/provider.d.ts +10 -0
  324. package/dist/extensions/llama/provider.d.ts.map +1 -0
  325. package/dist/extensions/llama/provider.js +106 -0
  326. package/dist/extensions/llama/provider.js.map +1 -0
  327. package/dist/extensions/llama/ui.d.ts +42 -0
  328. package/dist/extensions/llama/ui.d.ts.map +1 -0
  329. package/dist/extensions/llama/ui.js +400 -0
  330. package/dist/extensions/llama/ui.js.map +1 -0
  331. package/dist/index.d.ts +2 -2
  332. package/dist/index.d.ts.map +1 -1
  333. package/dist/index.js.map +1 -1
  334. package/dist/main.d.ts.map +1 -1
  335. package/dist/main.js +6 -4
  336. package/dist/main.js.map +1 -1
  337. package/dist/modes/interactive/components/assistant-message.d.ts +6 -7
  338. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  339. package/dist/modes/interactive/components/assistant-message.js +154 -114
  340. package/dist/modes/interactive/components/assistant-message.js.map +1 -1
  341. package/dist/modes/interactive/components/footer.d.ts +2 -1
  342. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  343. package/dist/modes/interactive/components/footer.js +25 -4
  344. package/dist/modes/interactive/components/footer.js.map +1 -1
  345. package/dist/modes/interactive/components/settings-selector.d.ts +4 -0
  346. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  347. package/dist/modes/interactive/components/settings-selector.js +20 -0
  348. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  349. package/dist/modes/interactive/interactive-mode.d.ts +7 -0
  350. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  351. package/dist/modes/interactive/interactive-mode.js +165 -13
  352. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  353. package/dist/modes/interactive/streaming-reveal.d.ts +35 -0
  354. package/dist/modes/interactive/streaming-reveal.d.ts.map +1 -0
  355. package/dist/modes/interactive/streaming-reveal.js +268 -0
  356. package/dist/modes/interactive/streaming-reveal.js.map +1 -0
  357. package/dist/modes/interactive/tool-args-reveal.d.ts +20 -0
  358. package/dist/modes/interactive/tool-args-reveal.d.ts.map +1 -0
  359. package/dist/modes/interactive/tool-args-reveal.js +153 -0
  360. package/dist/modes/interactive/tool-args-reveal.js.map +1 -0
  361. package/dist/utils/child-process.d.ts +17 -1
  362. package/dist/utils/child-process.d.ts.map +1 -1
  363. package/dist/utils/child-process.js +41 -1
  364. package/dist/utils/child-process.js.map +1 -1
  365. package/docs/AGENTS.md +70 -0
  366. package/docs/custom-provider.md +28 -0
  367. package/docs/extensions.md +111 -5
  368. package/docs/index.md +1 -0
  369. package/docs/llama-cpp.md +99 -0
  370. package/docs/mcp.md +21 -5
  371. package/docs/neo.md +2 -1
  372. package/docs/prompt-templates.md +1 -0
  373. package/docs/providers.md +7 -0
  374. package/docs/settings.md +35 -0
  375. package/docs/tui.md +41 -26
  376. package/docs/usage.md +1 -0
  377. package/examples/AGENTS.md +3 -0
  378. package/examples/extensions/README.md +1 -1
  379. package/node_modules/@code-yeongyu/senpi-codemode/CHANGELOG.md +74 -0
  380. package/node_modules/@code-yeongyu/senpi-codemode/package.json +3 -3
  381. package/node_modules/@code-yeongyu/senpi-codemode/src/index.ts +59 -19
  382. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/py/prelude.py +0 -1
  383. package/node_modules/@code-yeongyu/senpi-codemode/src/prompt/eval-prompt.ts +69 -2
  384. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/eval-tool.ts +6 -0
  385. package/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.d.ts.map +1 -1
  386. package/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.js +95 -12
  387. package/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.js.map +1 -1
  388. package/node_modules/@earendil-works/pi-agent-core/dist/agent.d.ts.map +1 -1
  389. package/node_modules/@earendil-works/pi-agent-core/dist/agent.js +26 -1
  390. package/node_modules/@earendil-works/pi-agent-core/dist/agent.js.map +1 -1
  391. package/node_modules/@earendil-works/pi-agent-core/dist/harness/agent-harness.d.ts.map +1 -1
  392. package/node_modules/@earendil-works/pi-agent-core/dist/harness/agent-harness.js +24 -2
  393. package/node_modules/@earendil-works/pi-agent-core/dist/harness/agent-harness.js.map +1 -1
  394. package/node_modules/@earendil-works/pi-agent-core/dist/proxy.d.ts +3 -1
  395. package/node_modules/@earendil-works/pi-agent-core/dist/proxy.d.ts.map +1 -1
  396. package/node_modules/@earendil-works/pi-agent-core/dist/proxy.js +4 -2
  397. package/node_modules/@earendil-works/pi-agent-core/dist/proxy.js.map +1 -1
  398. package/node_modules/@earendil-works/pi-agent-core/dist/types.d.ts +5 -0
  399. package/node_modules/@earendil-works/pi-agent-core/dist/types.d.ts.map +1 -1
  400. package/node_modules/@earendil-works/pi-agent-core/dist/types.js.map +1 -1
  401. package/node_modules/@earendil-works/pi-agent-core/package.json +2 -2
  402. package/node_modules/@earendil-works/pi-ai/README.md +1 -1
  403. package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.d.ts.map +1 -1
  404. package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.js +92 -29
  405. package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.js.map +1 -1
  406. package/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.d.ts +2 -1
  407. package/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.d.ts.map +1 -1
  408. package/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.js +25 -1
  409. package/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.js.map +1 -1
  410. package/node_modules/@earendil-works/pi-ai/dist/api/transform-messages.d.ts.map +1 -1
  411. package/node_modules/@earendil-works/pi-ai/dist/api/transform-messages.js +105 -61
  412. package/node_modules/@earendil-works/pi-ai/dist/api/transform-messages.js.map +1 -1
  413. package/node_modules/@earendil-works/pi-ai/dist/compat.d.ts +1 -0
  414. package/node_modules/@earendil-works/pi-ai/dist/compat.d.ts.map +1 -1
  415. package/node_modules/@earendil-works/pi-ai/dist/compat.js +1 -0
  416. package/node_modules/@earendil-works/pi-ai/dist/compat.js.map +1 -1
  417. package/node_modules/@earendil-works/pi-ai/dist/image-models.generated.d.ts +15 -0
  418. package/node_modules/@earendil-works/pi-ai/dist/image-models.generated.d.ts.map +1 -1
  419. package/node_modules/@earendil-works/pi-ai/dist/image-models.generated.js +15 -0
  420. package/node_modules/@earendil-works/pi-ai/dist/image-models.generated.js.map +1 -1
  421. package/node_modules/@earendil-works/pi-ai/dist/index.d.ts +1 -0
  422. package/node_modules/@earendil-works/pi-ai/dist/index.d.ts.map +1 -1
  423. package/node_modules/@earendil-works/pi-ai/dist/index.js +1 -0
  424. package/node_modules/@earendil-works/pi-ai/dist/index.js.map +1 -1
  425. package/node_modules/@earendil-works/pi-ai/dist/models.generated.d.ts +4263 -22314
  426. package/node_modules/@earendil-works/pi-ai/dist/models.generated.d.ts.map +1 -1
  427. package/node_modules/@earendil-works/pi-ai/dist/providers/amazon-bedrock.models.d.ts +436 -1988
  428. package/node_modules/@earendil-works/pi-ai/dist/providers/amazon-bedrock.models.d.ts.map +1 -1
  429. package/node_modules/@earendil-works/pi-ai/dist/providers/amazon-bedrock.models.js +2 -1892
  430. package/node_modules/@earendil-works/pi-ai/dist/providers/amazon-bedrock.models.js.map +1 -1
  431. package/node_modules/@earendil-works/pi-ai/dist/providers/ant-ling.models.d.ts +10 -80
  432. package/node_modules/@earendil-works/pi-ai/dist/providers/ant-ling.models.d.ts.map +1 -1
  433. package/node_modules/@earendil-works/pi-ai/dist/providers/ant-ling.models.js +2 -57
  434. package/node_modules/@earendil-works/pi-ai/dist/providers/ant-ling.models.js.map +1 -1
  435. package/node_modules/@earendil-works/pi-ai/dist/providers/anthropic.models.d.ts +43 -267
  436. package/node_modules/@earendil-works/pi-ai/dist/providers/anthropic.models.d.ts.map +1 -1
  437. package/node_modules/@earendil-works/pi-ai/dist/providers/anthropic.models.js +2 -252
  438. package/node_modules/@earendil-works/pi-ai/dist/providers/anthropic.models.js.map +1 -1
  439. package/node_modules/@earendil-works/pi-ai/dist/providers/azure-openai-responses.models.d.ts +184 -883
  440. package/node_modules/@earendil-works/pi-ai/dist/providers/azure-openai-responses.models.d.ts.map +1 -1
  441. package/node_modules/@earendil-works/pi-ai/dist/providers/azure-openai-responses.models.js +2 -811
  442. package/node_modules/@earendil-works/pi-ai/dist/providers/azure-openai-responses.models.js.map +1 -1
  443. package/node_modules/@earendil-works/pi-ai/dist/providers/cerebras.models.d.ts +10 -60
  444. package/node_modules/@earendil-works/pi-ai/dist/providers/cerebras.models.d.ts.map +1 -1
  445. package/node_modules/@earendil-works/pi-ai/dist/providers/cerebras.models.js +2 -56
  446. package/node_modules/@earendil-works/pi-ai/dist/providers/cerebras.models.js.map +1 -1
  447. package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-ai-gateway.models.d.ts +168 -884
  448. package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-ai-gateway.models.d.ts.map +1 -1
  449. package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-ai-gateway.models.js +2 -755
  450. package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-ai-gateway.models.js.map +1 -1
  451. package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-workers-ai.models.d.ts +40 -286
  452. package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-workers-ai.models.d.ts.map +1 -1
  453. package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-workers-ai.models.js +2 -236
  454. package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-workers-ai.models.js.map +1 -1
  455. package/node_modules/@earendil-works/pi-ai/dist/providers/data/amazon-bedrock.json +1 -0
  456. package/node_modules/@earendil-works/pi-ai/dist/providers/data/ant-ling.json +1 -0
  457. package/node_modules/@earendil-works/pi-ai/dist/providers/data/anthropic.json +1 -0
  458. package/node_modules/@earendil-works/pi-ai/dist/providers/data/azure-openai-responses.json +1 -0
  459. package/node_modules/@earendil-works/pi-ai/dist/providers/data/cerebras.json +1 -0
  460. package/node_modules/@earendil-works/pi-ai/dist/providers/data/cloudflare-ai-gateway.json +1 -0
  461. package/node_modules/@earendil-works/pi-ai/dist/providers/data/cloudflare-workers-ai.json +1 -0
  462. package/node_modules/@earendil-works/pi-ai/dist/providers/data/deepseek.json +1 -0
  463. package/node_modules/@earendil-works/pi-ai/dist/providers/data/fireworks.json +1 -0
  464. package/node_modules/@earendil-works/pi-ai/dist/providers/data/github-copilot.json +1 -0
  465. package/node_modules/@earendil-works/pi-ai/dist/providers/data/google-vertex.json +1 -0
  466. package/node_modules/@earendil-works/pi-ai/dist/providers/data/google.json +1 -0
  467. package/node_modules/@earendil-works/pi-ai/dist/providers/data/groq.json +1 -0
  468. package/node_modules/@earendil-works/pi-ai/dist/providers/data/huggingface.json +1 -0
  469. package/node_modules/@earendil-works/pi-ai/dist/providers/data/kimi-coding.json +1 -0
  470. package/node_modules/@earendil-works/pi-ai/dist/providers/data/minimax-cn.json +1 -0
  471. package/node_modules/@earendil-works/pi-ai/dist/providers/data/minimax.json +1 -0
  472. package/node_modules/@earendil-works/pi-ai/dist/providers/data/mistral.json +1 -0
  473. package/node_modules/@earendil-works/pi-ai/dist/providers/data/moonshotai-cn.json +1 -0
  474. package/node_modules/@earendil-works/pi-ai/dist/providers/data/moonshotai.json +1 -0
  475. package/node_modules/@earendil-works/pi-ai/dist/providers/data/nvidia.json +1 -0
  476. package/node_modules/@earendil-works/pi-ai/dist/providers/data/openai-codex.json +1 -0
  477. package/node_modules/@earendil-works/pi-ai/dist/providers/data/openai.json +1 -0
  478. package/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode-go.json +1 -0
  479. package/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode.json +1 -0
  480. package/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -0
  481. package/node_modules/@earendil-works/pi-ai/dist/providers/data/together.json +1 -0
  482. package/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.json +1 -0
  483. package/node_modules/@earendil-works/pi-ai/dist/providers/data/xai.json +1 -0
  484. package/node_modules/@earendil-works/pi-ai/dist/providers/data/xiaomi-token-plan-ams.json +1 -0
  485. package/node_modules/@earendil-works/pi-ai/dist/providers/data/xiaomi-token-plan-cn.json +1 -0
  486. package/node_modules/@earendil-works/pi-ai/dist/providers/data/xiaomi-token-plan-sgp.json +1 -0
  487. package/node_modules/@earendil-works/pi-ai/dist/providers/data/xiaomi.json +1 -0
  488. package/node_modules/@earendil-works/pi-ai/dist/providers/data/zai-coding-cn.json +1 -0
  489. package/node_modules/@earendil-works/pi-ai/dist/providers/data/zai.json +1 -0
  490. package/node_modules/@earendil-works/pi-ai/dist/providers/deepseek.models.d.ts +7 -58
  491. package/node_modules/@earendil-works/pi-ai/dist/providers/deepseek.models.d.ts.map +1 -1
  492. package/node_modules/@earendil-works/pi-ai/dist/providers/deepseek.models.js +2 -40
  493. package/node_modules/@earendil-works/pi-ai/dist/providers/deepseek.models.js.map +1 -1
  494. package/node_modules/@earendil-works/pi-ai/dist/providers/faux.d.ts +1 -0
  495. package/node_modules/@earendil-works/pi-ai/dist/providers/faux.d.ts.map +1 -1
  496. package/node_modules/@earendil-works/pi-ai/dist/providers/faux.js +1 -0
  497. package/node_modules/@earendil-works/pi-ai/dist/providers/faux.js.map +1 -1
  498. package/node_modules/@earendil-works/pi-ai/dist/providers/fireworks.models.d.ts +49 -362
  499. package/node_modules/@earendil-works/pi-ai/dist/providers/fireworks.models.d.ts.map +1 -1
  500. package/node_modules/@earendil-works/pi-ai/dist/providers/fireworks.models.js +2 -292
  501. package/node_modules/@earendil-works/pi-ai/dist/providers/fireworks.models.js.map +1 -1
  502. package/node_modules/@earendil-works/pi-ai/dist/providers/github-copilot.models.d.ts +85 -760
  503. package/node_modules/@earendil-works/pi-ai/dist/providers/github-copilot.models.d.ts.map +1 -1
  504. package/node_modules/@earendil-works/pi-ai/dist/providers/github-copilot.models.js +2 -538
  505. package/node_modules/@earendil-works/pi-ai/dist/providers/github-copilot.models.js.map +1 -1
  506. package/node_modules/@earendil-works/pi-ai/dist/providers/google-vertex.models.d.ts +31 -189
  507. package/node_modules/@earendil-works/pi-ai/dist/providers/google-vertex.models.d.ts.map +1 -1
  508. package/node_modules/@earendil-works/pi-ai/dist/providers/google-vertex.models.js +2 -179
  509. package/node_modules/@earendil-works/pi-ai/dist/providers/google-vertex.models.js.map +1 -1
  510. package/node_modules/@earendil-works/pi-ai/dist/providers/google.models.d.ts +49 -309
  511. package/node_modules/@earendil-works/pi-ai/dist/providers/google.models.d.ts.map +1 -1
  512. package/node_modules/@earendil-works/pi-ai/dist/providers/google.models.js +2 -285
  513. package/node_modules/@earendil-works/pi-ai/dist/providers/google.models.js.map +1 -1
  514. package/node_modules/@earendil-works/pi-ai/dist/providers/groq.models.d.ts +22 -118
  515. package/node_modules/@earendil-works/pi-ai/dist/providers/groq.models.d.ts.map +1 -1
  516. package/node_modules/@earendil-works/pi-ai/dist/providers/groq.models.js +2 -122
  517. package/node_modules/@earendil-works/pi-ai/dist/providers/groq.models.js.map +1 -1
  518. package/node_modules/@earendil-works/pi-ai/dist/providers/huggingface.models.d.ts +196 -979
  519. package/node_modules/@earendil-works/pi-ai/dist/providers/huggingface.models.d.ts.map +1 -1
  520. package/node_modules/@earendil-works/pi-ai/dist/providers/huggingface.models.js +2 -884
  521. package/node_modules/@earendil-works/pi-ai/dist/providers/huggingface.models.js.map +1 -1
  522. package/node_modules/@earendil-works/pi-ai/dist/providers/kimi-coding.models.d.ts +13 -122
  523. package/node_modules/@earendil-works/pi-ai/dist/providers/kimi-coding.models.d.ts.map +1 -1
  524. package/node_modules/@earendil-works/pi-ai/dist/providers/kimi-coding.models.js +2 -98
  525. package/node_modules/@earendil-works/pi-ai/dist/providers/kimi-coding.models.js.map +1 -1
  526. package/node_modules/@earendil-works/pi-ai/dist/providers/minimax-cn.models.d.ts +10 -48
  527. package/node_modules/@earendil-works/pi-ai/dist/providers/minimax-cn.models.d.ts.map +1 -1
  528. package/node_modules/@earendil-works/pi-ai/dist/providers/minimax-cn.models.js +2 -53
  529. package/node_modules/@earendil-works/pi-ai/dist/providers/minimax-cn.models.js.map +1 -1
  530. package/node_modules/@earendil-works/pi-ai/dist/providers/minimax.models.d.ts +10 -48
  531. package/node_modules/@earendil-works/pi-ai/dist/providers/minimax.models.d.ts.map +1 -1
  532. package/node_modules/@earendil-works/pi-ai/dist/providers/minimax.models.js +2 -53
  533. package/node_modules/@earendil-works/pi-ai/dist/providers/minimax.models.js.map +1 -1
  534. package/node_modules/@earendil-works/pi-ai/dist/providers/mistral.models.d.ts +91 -480
  535. package/node_modules/@earendil-works/pi-ai/dist/providers/mistral.models.d.ts.map +1 -1
  536. package/node_modules/@earendil-works/pi-ai/dist/providers/mistral.models.js +2 -512
  537. package/node_modules/@earendil-works/pi-ai/dist/providers/mistral.models.js.map +1 -1
  538. package/node_modules/@earendil-works/pi-ai/dist/providers/moonshotai-cn.models.d.ts +31 -257
  539. package/node_modules/@earendil-works/pi-ai/dist/providers/moonshotai-cn.models.d.ts.map +1 -1
  540. package/node_modules/@earendil-works/pi-ai/dist/providers/moonshotai-cn.models.js +2 -185
  541. package/node_modules/@earendil-works/pi-ai/dist/providers/moonshotai-cn.models.js.map +1 -1
  542. package/node_modules/@earendil-works/pi-ai/dist/providers/moonshotai.models.d.ts +31 -257
  543. package/node_modules/@earendil-works/pi-ai/dist/providers/moonshotai.models.d.ts.map +1 -1
  544. package/node_modules/@earendil-works/pi-ai/dist/providers/moonshotai.models.js +2 -185
  545. package/node_modules/@earendil-works/pi-ai/dist/providers/moonshotai.models.js.map +1 -1
  546. package/node_modules/@earendil-works/pi-ai/dist/providers/nvidia.models.d.ts +58 -541
  547. package/node_modules/@earendil-works/pi-ai/dist/providers/nvidia.models.d.ts.map +1 -1
  548. package/node_modules/@earendil-works/pi-ai/dist/providers/nvidia.models.js +2 -382
  549. package/node_modules/@earendil-works/pi-ai/dist/providers/nvidia.models.js.map +1 -1
  550. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-codex.models.d.ts +22 -196
  551. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-codex.models.d.ts.map +1 -1
  552. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-codex.models.js +2 -139
  553. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-codex.models.js.map +1 -1
  554. package/node_modules/@earendil-works/pi-ai/dist/providers/openai.models.d.ts +184 -954
  555. package/node_modules/@earendil-works/pi-ai/dist/providers/openai.models.d.ts.map +1 -1
  556. package/node_modules/@earendil-works/pi-ai/dist/providers/openai.models.js +2 -825
  557. package/node_modules/@earendil-works/pi-ai/dist/providers/openai.models.js.map +1 -1
  558. package/node_modules/@earendil-works/pi-ai/dist/providers/opencode-go.d.ts +1 -1
  559. package/node_modules/@earendil-works/pi-ai/dist/providers/opencode-go.d.ts.map +1 -1
  560. package/node_modules/@earendil-works/pi-ai/dist/providers/opencode-go.js +2 -0
  561. package/node_modules/@earendil-works/pi-ai/dist/providers/opencode-go.js.map +1 -1
  562. package/node_modules/@earendil-works/pi-ai/dist/providers/opencode-go.models.d.ts +46 -335
  563. package/node_modules/@earendil-works/pi-ai/dist/providers/opencode-go.models.d.ts.map +1 -1
  564. package/node_modules/@earendil-works/pi-ai/dist/providers/opencode-go.models.js +2 -273
  565. package/node_modules/@earendil-works/pi-ai/dist/providers/opencode-go.models.js.map +1 -1
  566. package/node_modules/@earendil-works/pi-ai/dist/providers/opencode.models.d.ts +163 -1185
  567. package/node_modules/@earendil-works/pi-ai/dist/providers/opencode.models.d.ts.map +1 -1
  568. package/node_modules/@earendil-works/pi-ai/dist/providers/opencode.models.js +2 -996
  569. package/node_modules/@earendil-works/pi-ai/dist/providers/opencode.models.js.map +1 -1
  570. package/node_modules/@earendil-works/pi-ai/dist/providers/openrouter.models.d.ts +1076 -5750
  571. package/node_modules/@earendil-works/pi-ai/dist/providers/openrouter.models.d.ts.map +1 -1
  572. package/node_modules/@earendil-works/pi-ai/dist/providers/openrouter.models.js +2 -4910
  573. package/node_modules/@earendil-works/pi-ai/dist/providers/openrouter.models.js.map +1 -1
  574. package/node_modules/@earendil-works/pi-ai/dist/providers/together.models.d.ts +49 -579
  575. package/node_modules/@earendil-works/pi-ai/dist/providers/together.models.d.ts.map +1 -1
  576. package/node_modules/@earendil-works/pi-ai/dist/providers/together.models.js +2 -377
  577. package/node_modules/@earendil-works/pi-ai/dist/providers/together.models.js.map +1 -1
  578. package/node_modules/@earendil-works/pi-ai/dist/providers/vercel-ai-gateway.models.d.ts +752 -3336
  579. package/node_modules/@earendil-works/pi-ai/dist/providers/vercel-ai-gateway.models.d.ts.map +1 -1
  580. package/node_modules/@earendil-works/pi-ai/dist/providers/vercel-ai-gateway.models.js +2 -3263
  581. package/node_modules/@earendil-works/pi-ai/dist/providers/vercel-ai-gateway.models.js.map +1 -1
  582. package/node_modules/@earendil-works/pi-ai/dist/providers/xai.models.d.ts +10 -65
  583. package/node_modules/@earendil-works/pi-ai/dist/providers/xai.models.d.ts.map +1 -1
  584. package/node_modules/@earendil-works/pi-ai/dist/providers/xai.models.js +2 -57
  585. package/node_modules/@earendil-works/pi-ai/dist/providers/xai.models.js.map +1 -1
  586. package/node_modules/@earendil-works/pi-ai/dist/providers/xiaomi-token-plan-ams.models.d.ts +10 -63
  587. package/node_modules/@earendil-works/pi-ai/dist/providers/xiaomi-token-plan-ams.models.d.ts.map +1 -1
  588. package/node_modules/@earendil-works/pi-ai/dist/providers/xiaomi-token-plan-ams.models.js +2 -56
  589. package/node_modules/@earendil-works/pi-ai/dist/providers/xiaomi-token-plan-ams.models.js.map +1 -1
  590. package/node_modules/@earendil-works/pi-ai/dist/providers/xiaomi-token-plan-cn.models.d.ts +10 -63
  591. package/node_modules/@earendil-works/pi-ai/dist/providers/xiaomi-token-plan-cn.models.d.ts.map +1 -1
  592. package/node_modules/@earendil-works/pi-ai/dist/providers/xiaomi-token-plan-cn.models.js +2 -56
  593. package/node_modules/@earendil-works/pi-ai/dist/providers/xiaomi-token-plan-cn.models.js.map +1 -1
  594. package/node_modules/@earendil-works/pi-ai/dist/providers/xiaomi-token-plan-sgp.models.d.ts +10 -63
  595. package/node_modules/@earendil-works/pi-ai/dist/providers/xiaomi-token-plan-sgp.models.d.ts.map +1 -1
  596. package/node_modules/@earendil-works/pi-ai/dist/providers/xiaomi-token-plan-sgp.models.js +2 -56
  597. package/node_modules/@earendil-works/pi-ai/dist/providers/xiaomi-token-plan-sgp.models.js.map +1 -1
  598. package/node_modules/@earendil-works/pi-ai/dist/providers/xiaomi.models.d.ts +19 -126
  599. package/node_modules/@earendil-works/pi-ai/dist/providers/xiaomi.models.d.ts.map +1 -1
  600. package/node_modules/@earendil-works/pi-ai/dist/providers/xiaomi.models.js +2 -110
  601. package/node_modules/@earendil-works/pi-ai/dist/providers/xiaomi.models.js.map +1 -1
  602. package/node_modules/@earendil-works/pi-ai/dist/providers/zai-coding-cn.models.d.ts +19 -144
  603. package/node_modules/@earendil-works/pi-ai/dist/providers/zai-coding-cn.models.d.ts.map +1 -1
  604. package/node_modules/@earendil-works/pi-ai/dist/providers/zai-coding-cn.models.js +2 -111
  605. package/node_modules/@earendil-works/pi-ai/dist/providers/zai-coding-cn.models.js.map +1 -1
  606. package/node_modules/@earendil-works/pi-ai/dist/providers/zai.models.d.ts +19 -144
  607. package/node_modules/@earendil-works/pi-ai/dist/providers/zai.models.d.ts.map +1 -1
  608. package/node_modules/@earendil-works/pi-ai/dist/providers/zai.models.js +2 -111
  609. package/node_modules/@earendil-works/pi-ai/dist/providers/zai.models.js.map +1 -1
  610. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/context-transformer.d.ts.map +1 -1
  611. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/context-transformer.js +12 -0
  612. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/context-transformer.js.map +1 -1
  613. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/index.d.ts +1 -1
  614. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/index.d.ts.map +1 -1
  615. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/index.js +4 -2
  616. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/index.js.map +1 -1
  617. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/coerce-parameters.d.ts +1 -0
  618. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/coerce-parameters.d.ts.map +1 -1
  619. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/coerce-parameters.js +1 -1
  620. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/coerce-parameters.js.map +1 -1
  621. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/format.d.ts +1 -0
  622. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/format.d.ts.map +1 -1
  623. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/format.js +1 -1
  624. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/format.js.map +1 -1
  625. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/invoke-protocol.d.ts +19 -0
  626. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/invoke-protocol.d.ts.map +1 -0
  627. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/invoke-protocol.js +8 -0
  628. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/invoke-protocol.js.map +1 -0
  629. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/invoke-tag-scanner.d.ts +11 -0
  630. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/invoke-tag-scanner.d.ts.map +1 -1
  631. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/invoke-tag-scanner.js +40 -1
  632. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/invoke-tag-scanner.js.map +1 -1
  633. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/parse.d.ts +2 -0
  634. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/parse.d.ts.map +1 -1
  635. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/parse.js +7 -4
  636. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/parse.js.map +1 -1
  637. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/stream.d.ts +2 -0
  638. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/stream.d.ts.map +1 -1
  639. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/stream.js +104 -15
  640. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/stream.js.map +1 -1
  641. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/antml/coerce-parameters.d.ts +15 -0
  642. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/antml/coerce-parameters.d.ts.map +1 -0
  643. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/antml/coerce-parameters.js +198 -0
  644. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/antml/coerce-parameters.js.map +1 -0
  645. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/antml/config.d.ts +3 -0
  646. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/antml/config.d.ts.map +1 -0
  647. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/antml/config.js +8 -0
  648. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/antml/config.js.map +1 -0
  649. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/antml/format.d.ts +6 -0
  650. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/antml/format.d.ts.map +1 -0
  651. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/antml/format.js +33 -0
  652. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/antml/format.js.map +1 -0
  653. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/antml/index.d.ts +6 -0
  654. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/antml/index.d.ts.map +1 -0
  655. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/antml/index.js +6 -0
  656. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/antml/index.js.map +1 -0
  657. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/antml/parse.d.ts +4 -0
  658. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/antml/parse.d.ts.map +1 -0
  659. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/antml/parse.js +6 -0
  660. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/antml/parse.js.map +1 -0
  661. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/antml/repair.d.ts +12 -0
  662. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/antml/repair.d.ts.map +1 -0
  663. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/antml/repair.js +46 -0
  664. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/antml/repair.js.map +1 -0
  665. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/antml/stream.d.ts +4 -0
  666. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/antml/stream.d.ts.map +1 -0
  667. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/antml/stream.js +6 -0
  668. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/antml/stream.js.map +1 -0
  669. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/gemma4.d.ts +8 -1
  670. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/gemma4.d.ts.map +1 -1
  671. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/gemma4.js +129 -27
  672. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/gemma4.js.map +1 -1
  673. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/json-mix.d.ts.map +1 -1
  674. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/json-mix.js +140 -6
  675. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/json-mix.js.map +1 -1
  676. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/morph-xml.d.ts.map +1 -1
  677. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/morph-xml.js +28 -6
  678. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/morph-xml.js.map +1 -1
  679. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/yaml-xml.d.ts.map +1 -1
  680. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/yaml-xml.js +51 -18
  681. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/yaml-xml.js.map +1 -1
  682. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/stream-wrapper.d.ts.map +1 -1
  683. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/stream-wrapper.js +70 -9
  684. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/stream-wrapper.js.map +1 -1
  685. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/types.d.ts +6 -2
  686. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/types.d.ts.map +1 -1
  687. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/types.js.map +1 -1
  688. package/node_modules/@earendil-works/pi-ai/dist/types.d.ts +31 -3
  689. package/node_modules/@earendil-works/pi-ai/dist/types.d.ts.map +1 -1
  690. package/node_modules/@earendil-works/pi-ai/dist/types.js +4 -1
  691. package/node_modules/@earendil-works/pi-ai/dist/types.js.map +1 -1
  692. package/node_modules/@earendil-works/pi-ai/dist/utils/retry.d.ts.map +1 -1
  693. package/node_modules/@earendil-works/pi-ai/dist/utils/retry.js +6 -1
  694. package/node_modules/@earendil-works/pi-ai/dist/utils/retry.js.map +1 -1
  695. package/node_modules/@earendil-works/pi-ai/dist/utils/stop-details.d.ts +4 -0
  696. package/node_modules/@earendil-works/pi-ai/dist/utils/stop-details.d.ts.map +1 -0
  697. package/node_modules/@earendil-works/pi-ai/dist/utils/stop-details.js +6 -0
  698. package/node_modules/@earendil-works/pi-ai/dist/utils/stop-details.js.map +1 -0
  699. package/node_modules/@earendil-works/pi-ai/dist/utils/tool-pair-repair.d.ts.map +1 -1
  700. package/node_modules/@earendil-works/pi-ai/dist/utils/tool-pair-repair.js +19 -2
  701. package/node_modules/@earendil-works/pi-ai/dist/utils/tool-pair-repair.js.map +1 -1
  702. package/node_modules/@earendil-works/pi-ai/dist/utils/tool-schema-compat.d.ts +19 -0
  703. package/node_modules/@earendil-works/pi-ai/dist/utils/tool-schema-compat.d.ts.map +1 -0
  704. package/node_modules/@earendil-works/pi-ai/dist/utils/tool-schema-compat.js +215 -0
  705. package/node_modules/@earendil-works/pi-ai/dist/utils/tool-schema-compat.js.map +1 -0
  706. package/node_modules/@earendil-works/pi-ai/package.json +2 -2
  707. package/node_modules/@earendil-works/pi-pty/dist/registry-session.d.ts +1 -1
  708. package/node_modules/@earendil-works/pi-pty/dist/registry-session.d.ts.map +1 -1
  709. package/node_modules/@earendil-works/pi-pty/dist/registry-session.js +25 -6
  710. package/node_modules/@earendil-works/pi-pty/dist/registry-session.js.map +1 -1
  711. package/node_modules/@earendil-works/pi-pty/dist/registry-types.d.ts +6 -0
  712. package/node_modules/@earendil-works/pi-pty/dist/registry-types.d.ts.map +1 -1
  713. package/node_modules/@earendil-works/pi-pty/dist/registry-types.js.map +1 -1
  714. package/node_modules/@earendil-works/pi-pty/dist/registry.d.ts +1 -0
  715. package/node_modules/@earendil-works/pi-pty/dist/registry.d.ts.map +1 -1
  716. package/node_modules/@earendil-works/pi-pty/dist/registry.js +9 -1
  717. package/node_modules/@earendil-works/pi-pty/dist/registry.js.map +1 -1
  718. package/node_modules/@earendil-works/pi-pty/package.json +1 -1
  719. package/node_modules/@earendil-works/pi-tui/dist/index.d.ts +1 -1
  720. package/node_modules/@earendil-works/pi-tui/dist/index.d.ts.map +1 -1
  721. package/node_modules/@earendil-works/pi-tui/dist/index.js +1 -1
  722. package/node_modules/@earendil-works/pi-tui/dist/index.js.map +1 -1
  723. package/node_modules/@earendil-works/pi-tui/dist/tui.d.ts +6 -1
  724. package/node_modules/@earendil-works/pi-tui/dist/tui.d.ts.map +1 -1
  725. package/node_modules/@earendil-works/pi-tui/dist/tui.js +14 -2
  726. package/node_modules/@earendil-works/pi-tui/dist/tui.js.map +1 -1
  727. package/node_modules/@earendil-works/pi-tui/dist/utils.js +1 -1
  728. package/node_modules/@earendil-works/pi-tui/dist/utils.js.map +1 -1
  729. package/node_modules/@earendil-works/pi-tui/package.json +1 -1
  730. package/package.json +6 -6
  731. package/dist/core/extensions/builtin/todotools/tools/todoread.d.ts +0 -4
  732. package/dist/core/extensions/builtin/todotools/tools/todoread.d.ts.map +0 -1
  733. package/dist/core/extensions/builtin/todotools/tools/todoread.js +0 -37
  734. package/dist/core/extensions/builtin/todotools/tools/todoread.js.map +0 -1
  735. package/dist/core/extensions/builtin/todotools/tools/todowrite.d.ts +0 -10
  736. package/dist/core/extensions/builtin/todotools/tools/todowrite.d.ts.map +0 -1
  737. package/dist/core/extensions/builtin/todotools/tools/todowrite.js +0 -95
  738. package/dist/core/extensions/builtin/todotools/tools/todowrite.js.map +0 -1
@@ -1,8 +1,8 @@
1
1
  import type { ExtensionAPI, ExtensionContext } from "../../types.ts";
2
- import type { Goal, GoalAccountingMode, GoalStoreRef, TokenUsageSnapshot } from "./types.ts";
2
+ import type { Goal, GoalAccountingMode, GoalStoreRef } from "./types.ts";
3
3
  export type GoalToolRegistrationDeps = {
4
4
  readonly goalStoreRef: (ctx: ExtensionContext) => GoalStoreRef;
5
- readonly accountCurrentAgentTurn: (ctx: ExtensionContext, usage: TokenUsageSnapshot, mode: GoalAccountingMode) => Promise<Goal | null>;
5
+ readonly accountCurrentAgentTurn: (ctx: ExtensionContext, mode: GoalAccountingMode) => Promise<Goal | null>;
6
6
  readonly beginAgentGoalAccounting: (goal: Goal) => void;
7
7
  readonly markGoalCompletedThisTurn: (goal: Goal) => void;
8
8
  readonly refreshGoalUi: (ctx: ExtensionContext, goal: Goal | null) => void;
@@ -1 +1 @@
1
- {"version":3,"file":"tool-registration.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/goal/tool-registration.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAmB,YAAY,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAGtF,OAAO,KAAK,EAAE,IAAI,EAAE,kBAAkB,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAO7F,MAAM,MAAM,wBAAwB,GAAG;IACtC,QAAQ,CAAC,YAAY,EAAE,CAAC,GAAG,EAAE,gBAAgB,KAAK,YAAY,CAAC;IAC/D,QAAQ,CAAC,uBAAuB,EAAE,CACjC,GAAG,EAAE,gBAAgB,EACrB,KAAK,EAAE,kBAAkB,EACzB,IAAI,EAAE,kBAAkB,KACpB,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC;IAC1B,QAAQ,CAAC,wBAAwB,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;IACxD,QAAQ,CAAC,yBAAyB,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;IACzD,QAAQ,CAAC,aAAa,EAAE,CAAC,GAAG,EAAE,gBAAgB,EAAE,IAAI,EAAE,IAAI,GAAG,IAAI,KAAK,IAAI,CAAC;CAC3E,CAAC;AAEF,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,wBAAwB,GAAG,IAAI,CAuExF"}
1
+ {"version":3,"file":"tool-registration.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/goal/tool-registration.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAmB,YAAY,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAGtF,OAAO,KAAK,EAAE,IAAI,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAKzE,MAAM,MAAM,wBAAwB,GAAG;IACtC,QAAQ,CAAC,YAAY,EAAE,CAAC,GAAG,EAAE,gBAAgB,KAAK,YAAY,CAAC;IAC/D,QAAQ,CAAC,uBAAuB,EAAE,CAAC,GAAG,EAAE,gBAAgB,EAAE,IAAI,EAAE,kBAAkB,KAAK,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC;IAC5G,QAAQ,CAAC,wBAAwB,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;IACxD,QAAQ,CAAC,yBAAyB,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;IACzD,QAAQ,CAAC,aAAa,EAAE,CAAC,GAAG,EAAE,gBAAgB,EAAE,IAAI,EAAE,IAAI,GAAG,IAAI,KAAK,IAAI,CAAC;CAC3E,CAAC;AAEF,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,wBAAwB,GAAG,IAAI,CAuExF"}
@@ -2,7 +2,6 @@ import { Type } from "typebox";
2
2
  import { formatGoalToolResponse } from "./format.js";
3
3
  import { createGoal, readGoal, updateGoal } from "./store.js";
4
4
  import { COMPLETABLE_GOAL_STATUS_VALUES } from "./types.js";
5
- const EMPTY_USAGE = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, totalTokens: 0 };
6
5
  export function registerGoalTools(pi, deps) {
7
6
  pi.registerTool({
8
7
  name: "create_goal",
@@ -37,7 +36,7 @@ export function registerGoalTools(pi, deps) {
37
36
  if (params.status !== "complete") {
38
37
  throw new Error("update_goal can only mark the existing goal complete; pause and resume are controlled by the user or system");
39
38
  }
40
- await deps.accountCurrentAgentTurn(ctx, EMPTY_USAGE, "active");
39
+ await deps.accountCurrentAgentTurn(ctx, "active");
41
40
  const goal = await updateGoal(deps.goalStoreRef(ctx), { status: "complete" });
42
41
  deps.markGoalCompletedThisTurn(goal);
43
42
  deps.refreshGoalUi(ctx, goal);
@@ -50,7 +49,7 @@ export function registerGoalTools(pi, deps) {
50
49
  description: "Get the current goal for this thread, including status, token and elapsed-time usage.",
51
50
  parameters: Type.Object({}, { additionalProperties: false }),
52
51
  async execute(_toolCallId, _params, _signal, _onUpdate, ctx) {
53
- const goal = await readGoal(deps.goalStoreRef(ctx));
52
+ const goal = await deps.accountCurrentAgentTurn(ctx, "active");
54
53
  deps.refreshGoalUi(ctx, goal);
55
54
  return toolText(formatGoalToolResponse(goal));
56
55
  },
@@ -1 +1 @@
1
- {"version":3,"file":"tool-registration.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/goal/tool-registration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE/B,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE9D,OAAO,EAAE,8BAA8B,EAAE,MAAM,YAAY,CAAC;AAE5D,MAAM,WAAW,GAAuB,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,WAAW,EAAE,CAAC,EAAE,CAAC;AAgB7G,MAAM,UAAU,iBAAiB,CAAC,EAAgB,EAAE,IAA8B;IACjF,EAAE,CAAC,YAAY,CAAC;QACf,IAAI,EAAE,aAAa;QACnB,KAAK,EAAE,aAAa;QACpB,WAAW,EACV,sMAAsM;QACvM,UAAU,EAAE,IAAI,CAAC,MAAM,CACtB;YACC,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC;gBACtB,WAAW,EACV,sKAAsK;aACvK,CAAC;SACF,EACD,EAAE,oBAAoB,EAAE,KAAK,EAAE,CAC/B;QACD,KAAK,CAAC,OAAO,CAAC,WAAW,E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UAAU,CAAC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC,CAAC;YAC9E,IAAI,CAAC,yBAAyB,CAAC,IAAI,CAAC,CAAC;YACrC,IAAI,CAAC,aAAa,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;YAC9B,OAAO,QAAQ,CAAC,sBAAsB,CAAC,IAAI,CAAC,CAAC,CAAC;QAC/C,CAAC;KACD,CAAC,CAAC;IAEH,EAAE,CAAC,YAAY,CAAC;QACf,IAAI,EAAE,UAAU;QAChB,KAAK,EAAE,UAAU;QACjB,WAAW,EAAE,uFAAuF;QACpG,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,oBAAoB,EAAE,KAAK,EAAE,CAAC;QAC5D,KAAK,CAAC,OAAO,CAAC,WAAW,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG;YAC1D,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC;YACpD,IAAI,CAAC,aAAa,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;YAC9B,OAAO,QAAQ,CAAC,sBAAsB,CAAC,IAAI,CAAC,CAAC,CAAC;QAC/C,CAAC;KACD,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,QAAQ,CAAC,IAAY;IAC7B,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;AACpE,CAAC","sourcesContent":["import { Type } from \"typebox\";\nimport type { AgentToolResult, ExtensionAPI, ExtensionContext } from \"../../types.ts\";\nimport { formatGoalToolResponse } from \"./format.ts\";\nimport { createGoal, readGoal, updateGoal } from \"./store.ts\";\nimport type { Goal, GoalAccountingMode, GoalStoreRef, TokenUsageSnapshot } from \"./types.ts\";\nimport { COMPLETABLE_GOAL_STATUS_VALUES } from \"./types.ts\";\n\nconst EMPTY_USAGE: TokenUsageSnapshot = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, totalTokens: 0 };\n\ntype GoalToolResult = AgentToolResult<Record<string, never>>;\n\nexport type GoalToolRegistrationDeps = {\n\treadonly goalStoreRef: (ctx: ExtensionContext) => GoalStoreRef;\n\treadonly accountCurrentAgentTurn: (\n\t\tctx: ExtensionContext,\n\t\tusage: TokenUsageSnapshot,\n\t\tmode: GoalAccountingMode,\n\t) => Promise<Goal | null>;\n\treadonly beginAgentGoalAccounting: (goal: Goal) => void;\n\treadonly markGoalCompletedThisTurn: (goal: Goal) => void;\n\treadonly refreshGoalUi: (ctx: ExtensionContext, goal: Goal | null) => void;\n};\n\nexport function registerGoalTools(pi: ExtensionAPI, deps: GoalToolRegistrationDeps): void {\n\tpi.registerTool({\n\t\tname: \"create_goal\",\n\t\tlabel: \"Create Goal\",\n\t\tdescription:\n\t\t\t\"Create a goal only when explicitly requested by the user or system/developer instructions; do not infer goals from ordinary tasks.\\nFails if a goal already exists; use update_goal only for status.\",\n\t\tparameters: Type.Object(\n\t\t\t{\n\t\t\t\tobjective: Type.String({\n\t\t\t\t\tdescription:\n\t\t\t\t\t\t\"Required. The concrete objective to start pursuing. This starts a new active goal only when no goal is currently defined; if a goal already exists, this tool fails.\",\n\t\t\t\t}),\n\t\t\t},\n\t\t\t{ additionalProperties: false },\n\t\t),\n\t\tasync execute(_toolCallId, params, _signal, _onUpdate, ctx) {\n\t\t\tconst ref = deps.goalStoreRef(ctx);\n\t\t\tif ((await readGoal(ref)) !== null) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"cannot create a new goal because this thread already has a goal; use update_goal only when the existing goal is complete\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst goal = await createGoal(ref, params.objective);\n\t\t\tdeps.beginAgentGoalAccounting(goal);\n\t\t\tdeps.refreshGoalUi(ctx, goal);\n\t\t\treturn toolText(formatGoalToolResponse(goal));\n\t\t},\n\t});\n\n\tpi.registerTool({\n\t\tname: \"update_goal\",\n\t\tlabel: \"Update Goal\",\n\t\tdescription:\n\t\t\t\"Update the existing goal.\\nUse this tool only to mark the goal achieved.\\nSet status to `complete` only when the objective has actually been achieved and no required work remains.\\nDo not mark a goal complete merely because you are stopping work.\\nYou cannot use this tool to pause or resume a goal; those status changes are controlled by the user or system.\\nWhen marking the goal achieved with status `complete`, report the final elapsed time and token usage from the tool result to the user.\",\n\t\tparameters: Type.Object(\n\t\t\t{\n\t\t\t\tstatus: Type.Union(\n\t\t\t\t\tCOMPLETABLE_GOAL_STATUS_VALUES.map((status) => Type.Literal(status)),\n\t\t\t\t\t{\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\"Required. Set to complete only when the objective is achieved and no required work remains.\",\n\t\t\t\t\t},\n\t\t\t\t),\n\t\t\t},\n\t\t\t{ additionalProperties: false },\n\t\t),\n\t\tasync execute(_toolCallId, params, _signal, _onUpdate, ctx) {\n\t\t\tif (params.status !== \"complete\") {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"update_goal can only mark the existing goal complete; pause and resume are controlled by the user or system\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tawait deps.accountCurrentAgentTurn(ctx, EMPTY_USAGE, \"active\");\n\t\t\tconst goal = await updateGoal(deps.goalStoreRef(ctx), { status: \"complete\" });\n\t\t\tdeps.markGoalCompletedThisTurn(goal);\n\t\t\tdeps.refreshGoalUi(ctx, goal);\n\t\t\treturn toolText(formatGoalToolResponse(goal));\n\t\t},\n\t});\n\n\tpi.registerTool({\n\t\tname: \"get_goal\",\n\t\tlabel: \"Get Goal\",\n\t\tdescription: \"Get the current goal for this thread, including status, token and elapsed-time usage.\",\n\t\tparameters: Type.Object({}, { additionalProperties: false }),\n\t\tasync execute(_toolCallId, _params, _signal, _onUpdate, ctx) {\n\t\t\tconst goal = await readGoal(deps.goalStoreRef(ctx));\n\t\t\tdeps.refreshGoalUi(ctx, goal);\n\t\t\treturn toolText(formatGoalToolResponse(goal));\n\t\t},\n\t});\n}\n\nfunction toolText(text: string): GoalToolResult {\n\treturn { content: [{ type: \"text\" as const, text }], details: {} };\n}\n"]}
1
+ {"version":3,"file":"tool-registration.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/goal/tool-registration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE/B,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE9D,OAAO,EAAE,8BAA8B,EAAE,MAAM,YAAY,CAAC;AAY5D,MAAM,UAAU,iBAAiB,CAAC,EAAgB,EAAE,IAA8B;IACjF,EAAE,CAAC,YAAY,CAAC;QACf,IAAI,EAAE,aAAa;QACnB,KAAK,EAAE,aAAa;QACpB,WAAW,EACV,sMAAsM;QACvM,UAAU,EAAE,IAAI,CAAC,MAAM,CACtB;YACC,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC;gBACtB,WAAW,EACV,sKAAsK;aACvK,CAAC;SACF,EACD,EAAE,oBAAoB,EAAE,KAAK,EAAE,CAC/B;QACD,KAAK,CAAC,OAAO,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG;YACzD,MAAM,GAAG,GAAG,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;YACnC,IAAI,CAAC,MAAM,QAAQ,CAAC,GAAG,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;gBACpC,MAAM,IAAI,KAAK,CACd,0HAA0H,CAC1H,CAAC;YACH,CAAC;YACD,MAAM,IAAI,GAAG,MAAM,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC;YACrD,IAAI,CAAC,wBAAwB,CAAC,IAAI,CAAC,CAAC;YACpC,IAAI,CAAC,aAAa,CAAC,GAAG,EAAE,IAA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,EAAE,EAAE,EAAE,oBAAoB,EAAE,KAAK,EAAE,CAAC;QAC5D,KAAK,CAAC,OAAO,CAAC,WAAW,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG;YAC1D,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,uBAAuB,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;YAC/D,IAAI,CAAC,aAAa,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;YAC9B,OAAO,QAAQ,CAAC,sBAAsB,CAAC,IAAI,CAAC,CAAC,CAAC;QAC/C,CAAC;KACD,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,QAAQ,CAAC,IAAY;IAC7B,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;AACpE,CAAC","sourcesContent":["import { Type } from \"typebox\";\nimport type { AgentToolResult, ExtensionAPI, ExtensionContext } from \"../../types.ts\";\nimport { formatGoalToolResponse } from \"./format.ts\";\nimport { createGoal, readGoal, updateGoal } from \"./store.ts\";\nimport type { Goal, GoalAccountingMode, GoalStoreRef } from \"./types.ts\";\nimport { COMPLETABLE_GOAL_STATUS_VALUES } from \"./types.ts\";\n\ntype GoalToolResult = AgentToolResult<Record<string, never>>;\n\nexport type GoalToolRegistrationDeps = {\n\treadonly goalStoreRef: (ctx: ExtensionContext) => GoalStoreRef;\n\treadonly accountCurrentAgentTurn: (ctx: ExtensionContext, mode: GoalAccountingMode) => Promise<Goal | null>;\n\treadonly beginAgentGoalAccounting: (goal: Goal) => void;\n\treadonly markGoalCompletedThisTurn: (goal: Goal) => void;\n\treadonly refreshGoalUi: (ctx: ExtensionContext, goal: Goal | null) => void;\n};\n\nexport function registerGoalTools(pi: ExtensionAPI, deps: GoalToolRegistrationDeps): void {\n\tpi.registerTool({\n\t\tname: \"create_goal\",\n\t\tlabel: \"Create Goal\",\n\t\tdescription:\n\t\t\t\"Create a goal only when explicitly requested by the user or system/developer instructions; do not infer goals from ordinary tasks.\\nFails if a goal already exists; use update_goal only for status.\",\n\t\tparameters: Type.Object(\n\t\t\t{\n\t\t\t\tobjective: Type.String({\n\t\t\t\t\tdescription:\n\t\t\t\t\t\t\"Required. The concrete objective to start pursuing. This starts a new active goal only when no goal is currently defined; if a goal already exists, this tool fails.\",\n\t\t\t\t}),\n\t\t\t},\n\t\t\t{ additionalProperties: false },\n\t\t),\n\t\tasync execute(_toolCallId, params, _signal, _onUpdate, ctx) {\n\t\t\tconst ref = deps.goalStoreRef(ctx);\n\t\t\tif ((await readGoal(ref)) !== null) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"cannot create a new goal because this thread already has a goal; use update_goal only when the existing goal is complete\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst goal = await createGoal(ref, params.objective);\n\t\t\tdeps.beginAgentGoalAccounting(goal);\n\t\t\tdeps.refreshGoalUi(ctx, goal);\n\t\t\treturn toolText(formatGoalToolResponse(goal));\n\t\t},\n\t});\n\n\tpi.registerTool({\n\t\tname: \"update_goal\",\n\t\tlabel: \"Update Goal\",\n\t\tdescription:\n\t\t\t\"Update the existing goal.\\nUse this tool only to mark the goal achieved.\\nSet status to `complete` only when the objective has actually been achieved and no required work remains.\\nDo not mark a goal complete merely because you are stopping work.\\nYou cannot use this tool to pause or resume a goal; those status changes are controlled by the user or system.\\nWhen marking the goal achieved with status `complete`, report the final elapsed time and token usage from the tool result to the user.\",\n\t\tparameters: Type.Object(\n\t\t\t{\n\t\t\t\tstatus: Type.Union(\n\t\t\t\t\tCOMPLETABLE_GOAL_STATUS_VALUES.map((status) => Type.Literal(status)),\n\t\t\t\t\t{\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\"Required. Set to complete only when the objective is achieved and no required work remains.\",\n\t\t\t\t\t},\n\t\t\t\t),\n\t\t\t},\n\t\t\t{ additionalProperties: false },\n\t\t),\n\t\tasync execute(_toolCallId, params, _signal, _onUpdate, ctx) {\n\t\t\tif (params.status !== \"complete\") {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"update_goal can only mark the existing goal complete; pause and resume are controlled by the user or system\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tawait deps.accountCurrentAgentTurn(ctx, \"active\");\n\t\t\tconst goal = await updateGoal(deps.goalStoreRef(ctx), { status: \"complete\" });\n\t\t\tdeps.markGoalCompletedThisTurn(goal);\n\t\t\tdeps.refreshGoalUi(ctx, goal);\n\t\t\treturn toolText(formatGoalToolResponse(goal));\n\t\t},\n\t});\n\n\tpi.registerTool({\n\t\tname: \"get_goal\",\n\t\tlabel: \"Get Goal\",\n\t\tdescription: \"Get the current goal for this thread, including status, token and elapsed-time usage.\",\n\t\tparameters: Type.Object({}, { additionalProperties: false }),\n\t\tasync execute(_toolCallId, _params, _signal, _onUpdate, ctx) {\n\t\t\tconst goal = await deps.accountCurrentAgentTurn(ctx, \"active\");\n\t\t\tdeps.refreshGoalUi(ctx, goal);\n\t\t\treturn toolText(formatGoalToolResponse(goal));\n\t\t},\n\t});\n}\n\nfunction toolText(text: string): GoalToolResult {\n\treturn { content: [{ type: \"text\" as const, text }], details: {} };\n}\n"]}
@@ -0,0 +1,20 @@
1
+ import type { TokenUsageSnapshot } from "./types.ts";
2
+ export declare function emptyUsage(): TokenUsageSnapshot;
3
+ export declare function collectAssistantUsage(messages: unknown[]): TokenUsageSnapshot;
4
+ /**
5
+ * Accumulates assistant token usage streamed during the current agent run so
6
+ * goal accounting can checkpoint mid-turn (tool calls, commands, shutdown)
7
+ * without waiting for `agent_end` and without double counting when it fires.
8
+ */
9
+ export declare class TurnUsageTracker {
10
+ private pending;
11
+ private flushed;
12
+ reset(): void;
13
+ noteMessageEnd(message: unknown): void;
14
+ takePending(): TokenUsageSnapshot;
15
+ /** Drop usage streamed before a new accounting window opened mid-turn. */
16
+ discardPending(): void;
17
+ /** Return the run's total usage minus what checkpoints already accounted. */
18
+ takeRemaining(agentRunMessages: unknown[]): TokenUsageSnapshot;
19
+ }
20
+ //# sourceMappingURL=turn-usage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"turn-usage.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/goal/turn-usage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAKrD,wBAAgB,UAAU,IAAI,kBAAkB,CAE/C;AAED,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,kBAAkB,CAI7E;AAED;;;;GAIG;AACH,qBAAa,gBAAgB;IAC5B,OAAO,CAAC,OAAO,CAAgB;IAC/B,OAAO,CAAC,OAAO,CAAgB;IAE/B,KAAK,IAAI,IAAI,CAGZ;IAED,cAAc,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAErC;IAED,WAAW,IAAI,kBAAkB,CAKhC;IAED,0EAA0E;IAC1E,cAAc,IAAI,IAAI,CAErB;IAED,6EAA6E;IAC7E,aAAa,CAAC,gBAAgB,EAAE,OAAO,EAAE,GAAG,kBAAkB,CAS7D;CACD"}
@@ -0,0 +1,61 @@
1
+ import { isRecord } from "./types.js";
2
+ const USAGE_FIELDS = ["input", "output", "cacheRead", "cacheWrite", "totalTokens"];
3
+ export function emptyUsage() {
4
+ return { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, totalTokens: 0 };
5
+ }
6
+ export function collectAssistantUsage(messages) {
7
+ const usage = emptyUsage();
8
+ for (const message of messages)
9
+ addAssistantMessageUsage(usage, message);
10
+ return usage;
11
+ }
12
+ /**
13
+ * Accumulates assistant token usage streamed during the current agent run so
14
+ * goal accounting can checkpoint mid-turn (tool calls, commands, shutdown)
15
+ * without waiting for `agent_end` and without double counting when it fires.
16
+ */
17
+ export class TurnUsageTracker {
18
+ constructor() {
19
+ this.pending = emptyUsage();
20
+ this.flushed = emptyUsage();
21
+ }
22
+ reset() {
23
+ this.pending = emptyUsage();
24
+ this.flushed = emptyUsage();
25
+ }
26
+ noteMessageEnd(message) {
27
+ addAssistantMessageUsage(this.pending, message);
28
+ }
29
+ takePending() {
30
+ const taken = this.pending;
31
+ this.pending = emptyUsage();
32
+ for (const field of USAGE_FIELDS)
33
+ this.flushed[field] += taken[field];
34
+ return taken;
35
+ }
36
+ /** Drop usage streamed before a new accounting window opened mid-turn. */
37
+ discardPending() {
38
+ this.takePending();
39
+ }
40
+ /** Return the run's total usage minus what checkpoints already accounted. */
41
+ takeRemaining(agentRunMessages) {
42
+ const collected = collectAssistantUsage(agentRunMessages);
43
+ const remaining = emptyUsage();
44
+ for (const field of USAGE_FIELDS) {
45
+ remaining[field] = Math.max(0, collected[field] - this.flushed[field]);
46
+ this.flushed[field] = Math.max(this.flushed[field], collected[field]);
47
+ }
48
+ this.pending = emptyUsage();
49
+ return remaining;
50
+ }
51
+ }
52
+ function addAssistantMessageUsage(target, message) {
53
+ if (!isRecord(message) || message.role !== "assistant" || !isRecord(message.usage))
54
+ return;
55
+ for (const field of USAGE_FIELDS) {
56
+ const value = message.usage[field];
57
+ if (typeof value === "number" && Number.isFinite(value))
58
+ target[field] += value;
59
+ }
60
+ }
61
+ //# sourceMappingURL=turn-usage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"turn-usage.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/goal/turn-usage.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,MAAM,YAAY,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,YAAY,EAAE,aAAa,CAAU,CAAC;AAE5F,MAAM,UAAU,UAAU;IACzB,OAAO,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,WAAW,EAAE,CAAC,EAAE,CAAC;AAC7E,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,QAAmB;IAC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C,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;QACvE,CAAC;QACD,IAAI,CAAC,OAAO,GAAG,UAAU,EAAE,CAAC;QAC5B,OAAO,SAAS,CAAC;IAClB,CAAC;CACD;AAED,SAAS,wBAAwB,CAAC,MAA0B,EAAE,OAAgB;IAC7E,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,IAAI,KAAK,WAAW,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO;IAC3F,KAAK,MAAM,KAAK,IAAI,YAAY,EAAE,CAAC;QAClC,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACnC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC;YAAE,MAAM,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC;IACjF,CAAC;AACF,CAAC","sourcesContent":["import type { TokenUsageSnapshot } from \"./types.ts\";\nimport { isRecord } from \"./types.ts\";\n\nconst USAGE_FIELDS = [\"input\", \"output\", \"cacheRead\", \"cacheWrite\", \"totalTokens\"] as const;\n\nexport function emptyUsage(): TokenUsageSnapshot {\n\treturn { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, totalTokens: 0 };\n}\n\nexport function collectAssistantUsage(messages: unknown[]): TokenUsageSnapshot {\n\tconst usage = emptyUsage();\n\tfor (const message of messages) addAssistantMessageUsage(usage, message);\n\treturn usage;\n}\n\n/**\n * Accumulates assistant token usage streamed during the current agent run so\n * goal accounting can checkpoint mid-turn (tool calls, commands, shutdown)\n * without waiting for `agent_end` and without double counting when it fires.\n */\nexport class TurnUsageTracker {\n\tprivate pending = emptyUsage();\n\tprivate flushed = emptyUsage();\n\n\treset(): void {\n\t\tthis.pending = emptyUsage();\n\t\tthis.flushed = emptyUsage();\n\t}\n\n\tnoteMessageEnd(message: unknown): void {\n\t\taddAssistantMessageUsage(this.pending, message);\n\t}\n\n\ttakePending(): TokenUsageSnapshot {\n\t\tconst taken = this.pending;\n\t\tthis.pending = emptyUsage();\n\t\tfor (const field of USAGE_FIELDS) this.flushed[field] += taken[field];\n\t\treturn taken;\n\t}\n\n\t/** Drop usage streamed before a new accounting window opened mid-turn. */\n\tdiscardPending(): void {\n\t\tthis.takePending();\n\t}\n\n\t/** Return the run's total usage minus what checkpoints already accounted. */\n\ttakeRemaining(agentRunMessages: unknown[]): TokenUsageSnapshot {\n\t\tconst collected = collectAssistantUsage(agentRunMessages);\n\t\tconst remaining = emptyUsage();\n\t\tfor (const field of USAGE_FIELDS) {\n\t\t\tremaining[field] = Math.max(0, collected[field] - this.flushed[field]);\n\t\t\tthis.flushed[field] = Math.max(this.flushed[field], collected[field]);\n\t\t}\n\t\tthis.pending = emptyUsage();\n\t\treturn remaining;\n\t}\n}\n\nfunction addAssistantMessageUsage(target: TokenUsageSnapshot, message: unknown): void {\n\tif (!isRecord(message) || message.role !== \"assistant\" || !isRecord(message.usage)) return;\n\tfor (const field of USAGE_FIELDS) {\n\t\tconst value = message.usage[field];\n\t\tif (typeof value === \"number\" && Number.isFinite(value)) target[field] += value;\n\t}\n}\n"]}
@@ -5,4 +5,5 @@ export declare const APPLY_PATCH_PARAMS: Type.TObject<{
5
5
  export declare const APPLY_PATCH_FREEFORM_DESCRIPTION = "Use the `apply_patch` tool to edit files. This is a FREEFORM tool, so do not wrap the patch in JSON.";
6
6
  export declare const APPLY_PATCH_LARK_GRAMMAR = "start: begin_patch hunk+ end_patch\nbegin_patch: \"*** Begin Patch\" LF\nend_patch: \"*** End Patch\" LF?\n\nhunk: add_hunk | delete_hunk | update_hunk\nadd_hunk: \"*** Add File: \" filename LF add_line+\ndelete_hunk: \"*** Delete File: \" filename LF\nupdate_hunk: \"*** Update File: \" filename LF change_move? change?\n\nfilename: /(.+)/\nadd_line: \"+\" /(.*)/ LF -> line\n\nchange_move: \"*** Move to: \" filename LF\nchange: (change_context | change_line)+ eof_line?\nchange_context: (\"@@\" | \"@@ \" /(.+)/) LF\nchange_line: (\"+\" | \"-\" | \" \") /(.*)/ LF\neof_line: \"*** End of File\" LF\n\n%import common.LF\n";
7
7
  export declare const CODEX_APPLY_PATCH_DESCRIPTION = "Use the `apply_patch` tool to edit files.\nYour patch language is a stripped\u2011down, file\u2011oriented diff format designed to be easy to parse and safe to apply. You can think of it as a high\u2011level envelope:\n\n*** Begin Patch\n[ one or more file sections ]\n*** End Patch\n\nWithin that envelope, you get a sequence of file operations.\nYou MUST include a header to specify the action you are taking.\nEach operation starts with one of three headers:\n\n*** Add File: <path> - create a new file. Every following line is a + line (the initial contents).\n*** Delete File: <path> - remove an existing file. Nothing follows.\n*** Update File: <path> - patch an existing file in place (optionally with a rename).\n\nMay be immediately followed by *** Move to: <new path> if you want to rename the file.\nThen one or more \u201Chunks\u201D, each introduced by @@ (optionally followed by a hunk header).\nWithin a hunk each line starts with:\n\nFor instructions on [context_before] and [context_after]:\n- By default, show 3 lines of code immediately above and 3 lines immediately below each change. If a change is within 3 lines of a previous change, do NOT duplicate the first change\u2019s [context_after] lines in the second change\u2019s [context_before] lines.\n- If 3 lines of context is insufficient to uniquely identify the snippet of code within the file, use the @@ operator to indicate the class or function to which the snippet belongs. For instance, we might have:\n@@ class BaseClass\n[3 lines of pre-context]\n- [old_code]\n+ [new_code]\n[3 lines of post-context]\n\n- If a code block is repeated so many times in a class or function such that even a single `@@` statement and 3 lines of context cannot uniquely identify the snippet of code, you can use multiple `@@` statements to jump to the right context. For instance:\n\n@@ class BaseClass\n@@ \t def method():\n[3 lines of pre-context]\n- [old_code]\n+ [new_code]\n[3 lines of post-context]\n\nThe full grammar definition is below:\nPatch := Begin { FileOp } End\nBegin := \"*** Begin Patch\" NEWLINE\nEnd := \"*** End Patch\" NEWLINE\nFileOp := AddFile | DeleteFile | UpdateFile\nAddFile := \"*** Add File: \" path NEWLINE { \"+\" line NEWLINE }\nDeleteFile := \"*** Delete File: \" path NEWLINE\nUpdateFile := \"*** Update File: \" path NEWLINE [ MoveTo ] { Hunk }\nMoveTo := \"*** Move to: \" newPath NEWLINE\nHunk := \"@@\" [ header ] NEWLINE { HunkLine } [ \"*** End of File\" NEWLINE ]\nHunkLine := (\" \" | \"-\" | \"+\") text NEWLINE\n\nA full patch can combine several operations:\n\n*** Begin Patch\n*** Add File: hello.txt\n+Hello world\n*** Update File: src/app.py\n*** Move to: src/main.py\n@@ def greet():\n-print(\"Hi\")\n+print(\"Hello, world!\")\n*** Delete File: obsolete.txt\n*** End Patch\n\nIt is important to remember:\n\n- You must include a header with your intended action (Add/Delete/Update)\n- You must prefix new lines with `+` even when creating a new file\n- File references can only be relative, NEVER ABSOLUTE.\n";
8
+ export declare const APPLY_PATCH_JSON_DESCRIPTION = "Use the `apply_patch` tool to edit files by passing the entire patch as the `input` string argument.\nUse the `apply_patch` tool to edit files.\nYour patch language is a stripped\u2011down, file\u2011oriented diff format designed to be easy to parse and safe to apply. You can think of it as a high\u2011level envelope:\n\n*** Begin Patch\n[ one or more file sections ]\n*** End Patch\n\nWithin that envelope, you get a sequence of file operations.\nYou MUST include a header to specify the action you are taking.\nEach operation starts with one of three headers:\n\n*** Add File: <path> - create a new file. Every following line is a + line (the initial contents).\n*** Delete File: <path> - remove an existing file. Nothing follows.\n*** Update File: <path> - patch an existing file in place (optionally with a rename).\n\nMay be immediately followed by *** Move to: <new path> if you want to rename the file.\nThen one or more \u201Chunks\u201D, each introduced by @@ (optionally followed by a hunk header).\nWithin a hunk each line starts with:\n\nFor instructions on [context_before] and [context_after]:\n- By default, show 3 lines of code immediately above and 3 lines immediately below each change. If a change is within 3 lines of a previous change, do NOT duplicate the first change\u2019s [context_after] lines in the second change\u2019s [context_before] lines.\n- If 3 lines of context is insufficient to uniquely identify the snippet of code within the file, use the @@ operator to indicate the class or function to which the snippet belongs. For instance, we might have:\n@@ class BaseClass\n[3 lines of pre-context]\n- [old_code]\n+ [new_code]\n[3 lines of post-context]\n\n- If a code block is repeated so many times in a class or function such that even a single `@@` statement and 3 lines of context cannot uniquely identify the snippet of code, you can use multiple `@@` statements to jump to the right context. For instance:\n\n@@ class BaseClass\n@@ \t def method():\n[3 lines of pre-context]\n- [old_code]\n+ [new_code]\n[3 lines of post-context]\n\nThe full grammar definition is below:\nPatch := Begin { FileOp } End\nBegin := \"*** Begin Patch\" NEWLINE\nEnd := \"*** End Patch\" NEWLINE\nFileOp := AddFile | DeleteFile | UpdateFile\nAddFile := \"*** Add File: \" path NEWLINE { \"+\" line NEWLINE }\nDeleteFile := \"*** Delete File: \" path NEWLINE\nUpdateFile := \"*** Update File: \" path NEWLINE [ MoveTo ] { Hunk }\nMoveTo := \"*** Move to: \" newPath NEWLINE\nHunk := \"@@\" [ header ] NEWLINE { HunkLine } [ \"*** End of File\" NEWLINE ]\nHunkLine := (\" \" | \"-\" | \"+\") text NEWLINE\n\nA full patch can combine several operations:\n\n*** Begin Patch\n*** Add File: hello.txt\n+Hello world\n*** Update File: src/app.py\n*** Move to: src/main.py\n@@ def greet():\n-print(\"Hi\")\n+print(\"Hello, world!\")\n*** Delete File: obsolete.txt\n*** End Patch\n\nIt is important to remember:\n\n- You must include a header with your intended action (Add/Delete/Update)\n- You must prefix new lines with `+` even when creating a new file\n- File references can only be relative, NEVER ABSOLUTE.\n";
8
9
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/gpt-apply-patch/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE/B,eAAO,MAAM,kBAAkB;;EAI7B,CAAC;AAEH,eAAO,MAAM,gCAAgC,yGAC0D,CAAC;AACxG,eAAO,MAAM,wBAAwB,onBAmBpC,CAAC;AACF,eAAO,MAAM,6BAA6B,k9FACu2F,CAAC"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/gpt-apply-patch/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE/B,eAAO,MAAM,kBAAkB;;EAI7B,CAAC;AAEH,eAAO,MAAM,gCAAgC,yGAC0D,CAAC;AACxG,eAAO,MAAM,wBAAwB,onBAmBpC,CAAC;AAIF,eAAO,MAAM,6BAA6B,k9FAAqC,CAAC;AAIhF,eAAO,MAAM,4BAA4B,wjGAAoJ,CAAC"}
@@ -25,5 +25,9 @@ eof_line: "*** End of File" LF
25
25
 
26
26
  %import common.LF
27
27
  `;
28
- export const CODEX_APPLY_PATCH_DESCRIPTION = 'Use the `apply_patch` tool to edit files.\nYour patch language is a stripped‑down, file‑oriented diff format designed to be easy to parse and safe to apply. You can think of it as a high‑level envelope:\n\n*** Begin Patch\n[ one or more file sections ]\n*** End Patch\n\nWithin that envelope, you get a sequence of file operations.\nYou MUST include a header to specify the action you are taking.\nEach operation starts with one of three headers:\n\n*** Add File: <path> - create a new file. Every following line is a + line (the initial contents).\n*** Delete File: <path> - remove an existing file. Nothing follows.\n*** Update File: <path> - patch an existing file in place (optionally with a rename).\n\nMay be immediately followed by *** Move to: <new path> if you want to rename the file.\nThen one or more “hunks”, each introduced by @@ (optionally followed by a hunk header).\nWithin a hunk each line starts with:\n\nFor instructions on [context_before] and [context_after]:\n- By default, show 3 lines of code immediately above and 3 lines immediately below each change. If a change is within 3 lines of a previous change, do NOT duplicate the first change’s [context_after] lines in the second change’s [context_before] lines.\n- If 3 lines of context is insufficient to uniquely identify the snippet of code within the file, use the @@ operator to indicate the class or function to which the snippet belongs. For instance, we might have:\n@@ class BaseClass\n[3 lines of pre-context]\n- [old_code]\n+ [new_code]\n[3 lines of post-context]\n\n- If a code block is repeated so many times in a class or function such that even a single `@@` statement and 3 lines of context cannot uniquely identify the snippet of code, you can use multiple `@@` statements to jump to the right context. For instance:\n\n@@ class BaseClass\n@@ \t def method():\n[3 lines of pre-context]\n- [old_code]\n+ [new_code]\n[3 lines of post-context]\n\nThe full grammar definition is below:\nPatch := Begin { FileOp } End\nBegin := "*** Begin Patch" NEWLINE\nEnd := "*** End Patch" NEWLINE\nFileOp := AddFile | DeleteFile | UpdateFile\nAddFile := "*** Add File: " path NEWLINE { "+" line NEWLINE }\nDeleteFile := "*** Delete File: " path NEWLINE\nUpdateFile := "*** Update File: " path NEWLINE [ MoveTo ] { Hunk }\nMoveTo := "*** Move to: " newPath NEWLINE\nHunk := "@@" [ header ] NEWLINE { HunkLine } [ "*** End of File" NEWLINE ]\nHunkLine := (" " | "-" | "+") text NEWLINE\n\nA full patch can combine several operations:\n\n*** Begin Patch\n*** Add File: hello.txt\n+Hello world\n*** Update File: src/app.py\n*** Move to: src/main.py\n@@ def greet():\n-print("Hi")\n+print("Hello, world!")\n*** Delete File: obsolete.txt\n*** End Patch\n\nIt is important to remember:\n\n- You must include a header with your intended action (Add/Delete/Update)\n- You must prefix new lines with `+` even when creating a new file\n- File references can only be relative, NEVER ABSOLUTE.\n';
28
+ const CODEX_APPLY_PATCH_DESCRIPTION_BODY = 'Use the `apply_patch` tool to edit files.\nYour patch language is a stripped‑down, file‑oriented diff format designed to be easy to parse and safe to apply. You can think of it as a high‑level envelope:\n\n*** Begin Patch\n[ one or more file sections ]\n*** End Patch\n\nWithin that envelope, you get a sequence of file operations.\nYou MUST include a header to specify the action you are taking.\nEach operation starts with one of three headers:\n\n*** Add File: <path> - create a new file. Every following line is a + line (the initial contents).\n*** Delete File: <path> - remove an existing file. Nothing follows.\n*** Update File: <path> - patch an existing file in place (optionally with a rename).\n\nMay be immediately followed by *** Move to: <new path> if you want to rename the file.\nThen one or more “hunks”, each introduced by @@ (optionally followed by a hunk header).\nWithin a hunk each line starts with:\n\nFor instructions on [context_before] and [context_after]:\n- By default, show 3 lines of code immediately above and 3 lines immediately below each change. If a change is within 3 lines of a previous change, do NOT duplicate the first change’s [context_after] lines in the second change’s [context_before] lines.\n- If 3 lines of context is insufficient to uniquely identify the snippet of code within the file, use the @@ operator to indicate the class or function to which the snippet belongs. For instance, we might have:\n@@ class BaseClass\n[3 lines of pre-context]\n- [old_code]\n+ [new_code]\n[3 lines of post-context]\n\n- If a code block is repeated so many times in a class or function such that even a single `@@` statement and 3 lines of context cannot uniquely identify the snippet of code, you can use multiple `@@` statements to jump to the right context. For instance:\n\n@@ class BaseClass\n@@ \t def method():\n[3 lines of pre-context]\n- [old_code]\n+ [new_code]\n[3 lines of post-context]\n\nThe full grammar definition is below:\nPatch := Begin { FileOp } End\nBegin := "*** Begin Patch" NEWLINE\nEnd := "*** End Patch" NEWLINE\nFileOp := AddFile | DeleteFile | UpdateFile\nAddFile := "*** Add File: " path NEWLINE { "+" line NEWLINE }\nDeleteFile := "*** Delete File: " path NEWLINE\nUpdateFile := "*** Update File: " path NEWLINE [ MoveTo ] { Hunk }\nMoveTo := "*** Move to: " newPath NEWLINE\nHunk := "@@" [ header ] NEWLINE { HunkLine } [ "*** End of File" NEWLINE ]\nHunkLine := (" " | "-" | "+") text NEWLINE\n\nA full patch can combine several operations:\n\n*** Begin Patch\n*** Add File: hello.txt\n+Hello world\n*** Update File: src/app.py\n*** Move to: src/main.py\n@@ def greet():\n-print("Hi")\n+print("Hello, world!")\n*** Delete File: obsolete.txt\n*** End Patch\n\nIt is important to remember:\n\n- You must include a header with your intended action (Add/Delete/Update)\n- You must prefix new lines with `+` even when creating a new file\n- File references can only be relative, NEVER ABSOLUTE.\n';
29
+ export const CODEX_APPLY_PATCH_DESCRIPTION = CODEX_APPLY_PATCH_DESCRIPTION_BODY;
30
+ // JSON-function variant of the tool description for Chat Completions targets, derived from
31
+ // CODEX_APPLY_PATCH_DESCRIPTION (which carries no freeform / "do not wrap in JSON" wording).
32
+ export const APPLY_PATCH_JSON_DESCRIPTION = `Use the \`apply_patch\` tool to edit files by passing the entire patch as the \`input\` string argument.\n${CODEX_APPLY_PATCH_DESCRIPTION_BODY}`;
29
33
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/gpt-apply-patch/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE/B,MAAM,CAAC,MAAM,kBAAkB,GAAG,IAAI,CAAC,MAAM,CAAC;IAC7C,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC;QAClB,WAAW,EAAE,gDAAgD;KAC7D,CAAC;CACF,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,gCAAgC,GAC5C,sGAAsG,CAAC;AACxG,MAAM,CAAC,MAAM,wBAAwB,GAAG;;;;;;;;;;;;;;;;;;;CAmBvC,CAAC;AACF,MAAM,CAAC,MAAM,6BAA6B,GACzC,g5FAAg5F,CAAC","sourcesContent":["import { Type } from \"typebox\";\n\nexport const APPLY_PATCH_PARAMS = Type.Object({\n\tinput: Type.String({\n\t\tdescription: \"The entire contents of the apply_patch command\",\n\t}),\n});\n\nexport const APPLY_PATCH_FREEFORM_DESCRIPTION =\n\t\"Use the `apply_patch` tool to edit files. This is a FREEFORM tool, so do not wrap the patch in JSON.\";\nexport const APPLY_PATCH_LARK_GRAMMAR = `start: begin_patch hunk+ end_patch\nbegin_patch: \"*** Begin Patch\" LF\nend_patch: \"*** End Patch\" LF?\n\nhunk: add_hunk | delete_hunk | update_hunk\nadd_hunk: \"*** Add File: \" filename LF add_line+\ndelete_hunk: \"*** Delete File: \" filename LF\nupdate_hunk: \"*** Update File: \" filename LF change_move? change?\n\nfilename: /(.+)/\nadd_line: \"+\" /(.*)/ LF -> line\n\nchange_move: \"*** Move to: \" filename LF\nchange: (change_context | change_line)+ eof_line?\nchange_context: (\"@@\" | \"@@ \" /(.+)/) LF\nchange_line: (\"+\" | \"-\" | \" \") /(.*)/ LF\neof_line: \"*** End of File\" LF\n\n%import common.LF\n`;\nexport const CODEX_APPLY_PATCH_DESCRIPTION =\n\t'Use the `apply_patch` tool to edit files.\\nYour patch language is a stripped‑down, file‑oriented diff format designed to be easy to parse and safe to apply. You can think of it as a high‑level envelope:\\n\\n*** Begin Patch\\n[ one or more file sections ]\\n*** End Patch\\n\\nWithin that envelope, you get a sequence of file operations.\\nYou MUST include a header to specify the action you are taking.\\nEach operation starts with one of three headers:\\n\\n*** Add File: <path> - create a new file. Every following line is a + line (the initial contents).\\n*** Delete File: <path> - remove an existing file. Nothing follows.\\n*** Update File: <path> - patch an existing file in place (optionally with a rename).\\n\\nMay be immediately followed by *** Move to: <new path> if you want to rename the file.\\nThen one or more “hunks”, each introduced by @@ (optionally followed by a hunk header).\\nWithin a hunk each line starts with:\\n\\nFor instructions on [context_before] and [context_after]:\\n- By default, show 3 lines of code immediately above and 3 lines immediately below each change. If a change is within 3 lines of a previous change, do NOT duplicate the first change’s [context_after] lines in the second change’s [context_before] lines.\\n- If 3 lines of context is insufficient to uniquely identify the snippet of code within the file, use the @@ operator to indicate the class or function to which the snippet belongs. For instance, we might have:\\n@@ class BaseClass\\n[3 lines of pre-context]\\n- [old_code]\\n+ [new_code]\\n[3 lines of post-context]\\n\\n- If a code block is repeated so many times in a class or function such that even a single `@@` statement and 3 lines of context cannot uniquely identify the snippet of code, you can use multiple `@@` statements to jump to the right context. For instance:\\n\\n@@ class BaseClass\\n@@ \\t def method():\\n[3 lines of pre-context]\\n- [old_code]\\n+ [new_code]\\n[3 lines of post-context]\\n\\nThe full grammar definition is below:\\nPatch := Begin { FileOp } End\\nBegin := \"*** Begin Patch\" NEWLINE\\nEnd := \"*** End Patch\" NEWLINE\\nFileOp := AddFile | DeleteFile | UpdateFile\\nAddFile := \"*** Add File: \" path NEWLINE { \"+\" line NEWLINE }\\nDeleteFile := \"*** Delete File: \" path NEWLINE\\nUpdateFile := \"*** Update File: \" path NEWLINE [ MoveTo ] { Hunk }\\nMoveTo := \"*** Move to: \" newPath NEWLINE\\nHunk := \"@@\" [ header ] NEWLINE { HunkLine } [ \"*** End of File\" NEWLINE ]\\nHunkLine := (\" \" | \"-\" | \"+\") text NEWLINE\\n\\nA full patch can combine several operations:\\n\\n*** Begin Patch\\n*** Add File: hello.txt\\n+Hello world\\n*** Update File: src/app.py\\n*** Move to: src/main.py\\n@@ def greet():\\n-print(\"Hi\")\\n+print(\"Hello, world!\")\\n*** Delete File: obsolete.txt\\n*** End Patch\\n\\nIt is important to remember:\\n\\n- You must include a header with your intended action (Add/Delete/Update)\\n- You must prefix new lines with `+` even when creating a new file\\n- File references can only be relative, NEVER ABSOLUTE.\\n';\n"]}
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/gpt-apply-patch/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE/B,MAAM,CAAC,MAAM,kBAAkB,GAAG,IAAI,CAAC,MAAM,CAAC;IAC7C,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC;QAClB,WAAW,EAAE,gDAAgD;KAC7D,CAAC;CACF,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,gCAAgC,GAC5C,sGAAsG,CAAC;AACxG,MAAM,CAAC,MAAM,wBAAwB,GAAG;;;;;;;;;;;;;;;;;;;CAmBvC,CAAC;AACF,MAAM,kCAAkC,GACvC,g5FAAg5F,CAAC;AAEl5F,MAAM,CAAC,MAAM,6BAA6B,GAAG,kCAAkC,CAAC;AAEhF,2FAA2F;AAC3F,6FAA6F;AAC7F,MAAM,CAAC,MAAM,4BAA4B,GAAG,6GAA6G,kCAAkC,EAAE,CAAC","sourcesContent":["import { Type } from \"typebox\";\n\nexport const APPLY_PATCH_PARAMS = Type.Object({\n\tinput: Type.String({\n\t\tdescription: \"The entire contents of the apply_patch command\",\n\t}),\n});\n\nexport const APPLY_PATCH_FREEFORM_DESCRIPTION =\n\t\"Use the `apply_patch` tool to edit files. This is a FREEFORM tool, so do not wrap the patch in JSON.\";\nexport const APPLY_PATCH_LARK_GRAMMAR = `start: begin_patch hunk+ end_patch\nbegin_patch: \"*** Begin Patch\" LF\nend_patch: \"*** End Patch\" LF?\n\nhunk: add_hunk | delete_hunk | update_hunk\nadd_hunk: \"*** Add File: \" filename LF add_line+\ndelete_hunk: \"*** Delete File: \" filename LF\nupdate_hunk: \"*** Update File: \" filename LF change_move? change?\n\nfilename: /(.+)/\nadd_line: \"+\" /(.*)/ LF -> line\n\nchange_move: \"*** Move to: \" filename LF\nchange: (change_context | change_line)+ eof_line?\nchange_context: (\"@@\" | \"@@ \" /(.+)/) LF\nchange_line: (\"+\" | \"-\" | \" \") /(.*)/ LF\neof_line: \"*** End of File\" LF\n\n%import common.LF\n`;\nconst CODEX_APPLY_PATCH_DESCRIPTION_BODY =\n\t'Use the `apply_patch` tool to edit files.\\nYour patch language is a stripped‑down, file‑oriented diff format designed to be easy to parse and safe to apply. You can think of it as a high‑level envelope:\\n\\n*** Begin Patch\\n[ one or more file sections ]\\n*** End Patch\\n\\nWithin that envelope, you get a sequence of file operations.\\nYou MUST include a header to specify the action you are taking.\\nEach operation starts with one of three headers:\\n\\n*** Add File: <path> - create a new file. Every following line is a + line (the initial contents).\\n*** Delete File: <path> - remove an existing file. Nothing follows.\\n*** Update File: <path> - patch an existing file in place (optionally with a rename).\\n\\nMay be immediately followed by *** Move to: <new path> if you want to rename the file.\\nThen one or more “hunks”, each introduced by @@ (optionally followed by a hunk header).\\nWithin a hunk each line starts with:\\n\\nFor instructions on [context_before] and [context_after]:\\n- By default, show 3 lines of code immediately above and 3 lines immediately below each change. If a change is within 3 lines of a previous change, do NOT duplicate the first change’s [context_after] lines in the second change’s [context_before] lines.\\n- If 3 lines of context is insufficient to uniquely identify the snippet of code within the file, use the @@ operator to indicate the class or function to which the snippet belongs. For instance, we might have:\\n@@ class BaseClass\\n[3 lines of pre-context]\\n- [old_code]\\n+ [new_code]\\n[3 lines of post-context]\\n\\n- If a code block is repeated so many times in a class or function such that even a single `@@` statement and 3 lines of context cannot uniquely identify the snippet of code, you can use multiple `@@` statements to jump to the right context. For instance:\\n\\n@@ class BaseClass\\n@@ \\t def method():\\n[3 lines of pre-context]\\n- [old_code]\\n+ [new_code]\\n[3 lines of post-context]\\n\\nThe full grammar definition is below:\\nPatch := Begin { FileOp } End\\nBegin := \"*** Begin Patch\" NEWLINE\\nEnd := \"*** End Patch\" NEWLINE\\nFileOp := AddFile | DeleteFile | UpdateFile\\nAddFile := \"*** Add File: \" path NEWLINE { \"+\" line NEWLINE }\\nDeleteFile := \"*** Delete File: \" path NEWLINE\\nUpdateFile := \"*** Update File: \" path NEWLINE [ MoveTo ] { Hunk }\\nMoveTo := \"*** Move to: \" newPath NEWLINE\\nHunk := \"@@\" [ header ] NEWLINE { HunkLine } [ \"*** End of File\" NEWLINE ]\\nHunkLine := (\" \" | \"-\" | \"+\") text NEWLINE\\n\\nA full patch can combine several operations:\\n\\n*** Begin Patch\\n*** Add File: hello.txt\\n+Hello world\\n*** Update File: src/app.py\\n*** Move to: src/main.py\\n@@ def greet():\\n-print(\"Hi\")\\n+print(\"Hello, world!\")\\n*** Delete File: obsolete.txt\\n*** End Patch\\n\\nIt is important to remember:\\n\\n- You must include a header with your intended action (Add/Delete/Update)\\n- You must prefix new lines with `+` even when creating a new file\\n- File references can only be relative, NEVER ABSOLUTE.\\n';\n\nexport const CODEX_APPLY_PATCH_DESCRIPTION = CODEX_APPLY_PATCH_DESCRIPTION_BODY;\n\n// JSON-function variant of the tool description for Chat Completions targets, derived from\n// CODEX_APPLY_PATCH_DESCRIPTION (which carries no freeform / \"do not wrap in JSON\" wording).\nexport const APPLY_PATCH_JSON_DESCRIPTION = `Use the \\`apply_patch\\` tool to edit files by passing the entire patch as the \\`input\\` string argument.\\n${CODEX_APPLY_PATCH_DESCRIPTION_BODY}`;\n"]}
@@ -1,5 +1,6 @@
1
1
  import type { Model } from "@earendil-works/pi-ai";
2
- import type { ApplyPatchExtensionAPI } from "./types.ts";
2
+ import type { ApplyPatchExtensionAPI, ApplyPatchWireMode } from "./types.ts";
3
+ export declare function getApplyPatchWireMode(model: Pick<Model<string>, "api" | "id"> | undefined): ApplyPatchWireMode;
3
4
  export declare function isOpenAIGptModel(model: Pick<Model<string>, "api" | "id"> | undefined): boolean;
4
5
  export declare function registerApplyPatchExtension(pi: ApplyPatchExtensionAPI): void;
5
6
  export default registerApplyPatchExtension;
@@ -1 +1 @@
1
- {"version":3,"file":"extension.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/gpt-apply-patch/extension.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAO,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAExD,OAAO,KAAK,EAAE,sBAAsB,EAAiB,MAAM,YAAY,CAAC;AAaxE,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC,GAAG,SAAS,GAAG,OAAO,CAE9F;AA+CD,wBAAgB,2BAA2B,CAAC,EAAE,EAAE,sBAAsB,GAAG,IAAI,CAS5E;eAEc,2BAA2B"}
1
+ {"version":3,"file":"extension.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/gpt-apply-patch/extension.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAO,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAExD,OAAO,KAAK,EACX,sBAAsB,EAGtB,kBAAkB,EAClB,MAAM,YAAY,CAAC;AAepB,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC,GAAG,SAAS,GAAG,kBAAkB,CAK9G;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC,GAAG,SAAS,GAAG,OAAO,CAE9F;AAkDD,wBAAgB,2BAA2B,CAAC,EAAE,EAAE,sBAAsB,GAAG,IAAI,CAc5E;eAEc,2BAA2B"}
@@ -1,61 +1,80 @@
1
1
  import { createApplyPatchTool } from "./tool.js";
2
- // apply_patch ships as a freeform custom tool, which only the OpenAI Responses-family
3
- // APIs can carry (openai-completions throws on freeform tools). Gate on the model's API
4
- // rather than a provider allowlist so OpenAI-compatible custom providers (e.g. a proxy
5
- // exposing gpt-5.5 via openai-responses) also swap edit/write for apply_patch.
6
2
  const APPLY_PATCH_FREEFORM_APIS = new Set([
7
3
  "openai-responses",
8
4
  "azure-openai-responses",
9
5
  "openai-codex-responses",
10
6
  ]);
7
+ const APPLY_PATCH_JSON_APIS = new Set(["openai-completions"]);
11
8
  const EDIT_TOOL_NAMES = new Set(["write", "edit"]);
9
+ const APPLY_PATCH_NAME = "apply_patch";
10
+ function isGptId(model) {
11
+ return model?.id.startsWith("gpt-") ?? false;
12
+ }
13
+ export function getApplyPatchWireMode(model) {
14
+ if (!isGptId(model))
15
+ return "none";
16
+ if (APPLY_PATCH_FREEFORM_APIS.has(model.api))
17
+ return "freeform";
18
+ if (APPLY_PATCH_JSON_APIS.has(model.api))
19
+ return "json";
20
+ return "none";
21
+ }
12
22
  export function isOpenAIGptModel(model) {
13
- return model !== undefined && APPLY_PATCH_FREEFORM_APIS.has(model.api) && model.id.startsWith("gpt-");
23
+ return getApplyPatchWireMode(model) === "freeform";
14
24
  }
15
25
  function hasEditTools(toolNames) {
16
26
  return toolNames.some((toolName) => EDIT_TOOL_NAMES.has(toolName));
17
27
  }
18
28
  function withoutApplyPatch(toolNames) {
19
- return toolNames.filter((toolName) => toolName !== "apply_patch");
29
+ return toolNames.filter((toolName) => toolName !== APPLY_PATCH_NAME);
20
30
  }
21
31
  function replaceEditToolsWithApplyPatch(toolNames) {
32
+ const hadApplyPatch = toolNames.includes(APPLY_PATCH_NAME);
33
+ const insertIndex = toolNames.findIndex((toolName) => EDIT_TOOL_NAMES.has(toolName) || toolName === APPLY_PATCH_NAME);
22
34
  const filteredToolNames = withoutApplyPatch(toolNames).filter((toolName) => !EDIT_TOOL_NAMES.has(toolName));
23
- if (!hasEditTools(toolNames))
35
+ if (!hasEditTools(toolNames) && !hadApplyPatch)
24
36
  return filteredToolNames;
25
- return [...filteredToolNames, "apply_patch"];
26
- }
27
- function restoreEditToolsFromBaseline(currentToolNames, baselineToolNames) {
28
- const restoredToolNames = [
29
- ...withoutApplyPatch(currentToolNames),
30
- ...baselineToolNames.filter((toolName) => EDIT_TOOL_NAMES.has(toolName)),
31
- ];
32
- return [...new Set(restoredToolNames)];
37
+ const at = insertIndex === -1 ? filteredToolNames.length : Math.min(insertIndex, filteredToolNames.length);
38
+ return [...filteredToolNames.slice(0, at), APPLY_PATCH_NAME, ...filteredToolNames.slice(at)];
33
39
  }
34
- function syncToolset(pi, model, state) {
40
+ function syncToolset(pi, model, state, variants) {
41
+ const mode = getApplyPatchWireMode(model);
35
42
  const currentToolNames = pi.getActiveTools();
36
- if (isOpenAIGptModel(model)) {
37
- if (hasEditTools(currentToolNames))
38
- state.nonGptToolNames = withoutApplyPatch(currentToolNames);
43
+ if (mode !== "none") {
44
+ if (state.activeVariant !== mode) {
45
+ pi.registerTool(variants[mode]);
46
+ state.activeVariant = mode;
47
+ }
48
+ const activeEdit = currentToolNames.filter((toolName) => EDIT_TOOL_NAMES.has(toolName));
49
+ if (activeEdit.length > 0)
50
+ state.removedEditToolNames = activeEdit;
39
51
  pi.setActiveTools(replaceEditToolsWithApplyPatch(currentToolNames));
40
52
  return;
41
53
  }
42
- if (state.nonGptToolNames.length > 0) {
43
- const restoredToolNames = restoreEditToolsFromBaseline(currentToolNames, state.nonGptToolNames);
44
- state.nonGptToolNames = restoredToolNames;
45
- pi.setActiveTools(restoredToolNames);
54
+ if (state.removedEditToolNames.length === 0) {
55
+ if (currentToolNames.includes(APPLY_PATCH_NAME))
56
+ pi.setActiveTools(withoutApplyPatch(currentToolNames));
46
57
  return;
47
58
  }
48
- state.nonGptToolNames = withoutApplyPatch(currentToolNames);
49
- pi.setActiveTools(state.nonGptToolNames);
59
+ const registeredNames = new Set(pi.getAllTools().map((tool) => tool.name));
60
+ const restorable = state.removedEditToolNames.filter((toolName) => registeredNames.has(toolName));
61
+ const restored = [...withoutApplyPatch(currentToolNames), ...restorable];
62
+ state.removedEditToolNames = [];
63
+ pi.setActiveTools([...new Set(restored)]);
50
64
  }
51
65
  export function registerApplyPatchExtension(pi) {
52
- const state = { nonGptToolNames: [] };
53
- pi.registerTool(createApplyPatchTool());
66
+ const state = { removedEditToolNames: [] };
67
+ const variants = {
68
+ freeform: createApplyPatchTool("freeform"),
69
+ json: createApplyPatchTool("json"),
70
+ };
71
+ state.activeVariant = "freeform";
72
+ pi.registerTool(variants.freeform);
54
73
  pi.on("session_start", async (_event, ctx) => {
55
- syncToolset(pi, ctx.model, state);
74
+ syncToolset(pi, ctx.model, state, variants);
56
75
  });
57
76
  pi.on("model_select", async (event) => {
58
- syncToolset(pi, event.model, state);
77
+ syncToolset(pi, event.model, state, variants);
59
78
  });
60
79
  }
61
80
  export default registerApplyPatchExtension;
@@ -1 +1 @@
1
- {"version":3,"file":"extension.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/gpt-apply-patch/extension.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAGjD,sFAAsF;AACtF,wFAAwF;AACxF,uFAAuF;AACvF,+EAA+E;AAC/E,MAAM,yBAAyB,GAAG,IAAI,GAAG,CAAM;IAC9C,kBAAkB;IAClB,wBAAwB;IACxB,wBAAwB;CACxB,CAAC,CAAC;AACH,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC;AAEnD,MAAM,UAAU,gBAAgB,CAAC,KAAoD;IACpF,OAAO,KAAK,KAAK,SAAS,IAAI,yBAAyB,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;AACvG,CAAC;AAED,S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CAAC,cAAc,CAAC,8BAA8B,CAAC,gBAAgB,CAAC,CAAC,CAAC;QACpE,OAAO;IACR,CAAC;IAED,IAAI,KAAK,CAAC,eAAe,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtC,MAAM,iBAAiB,GAAG,4BAA4B,CAAC,gBAAgB,EAAE,KAAK,CAAC,eAAe,CAAC,CAAC;QAChG,KAAK,CAAC,eAAe,GAAG,iBAAiB,CAAC;QAC1C,EAAE,CAAC,cAAc,CAAC,iBAAiB,CAAC,CAAC;QACrC,OAAO;IACR,CAAC;IAED,KAAK,CAAC,eAAe,GAAG,iBAAiB,CAAC,gBAAgB,CAAC,CAAC;IAC5D,EAAE,CAAC,cAAc,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;AAC1C,CAAC;AAED,MAAM,UAAU,2BAA2B,CAAC,EAA0B;IACrE,MAAM,KAAK,GAAkB,EAAE,eAAe,EAAE,EAAE,EAAE,CAAC;IACrD,EAAE,CAAC,YAAY,CAAC,oBAAoB,EAAE,CAAC,CAAC;IACxC,EAAE,CAAC,EAAE,CAAC,eAAe,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE;QAC5C,WAAW,CAAC,EAAE,EAAE,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACnC,CAAC,CAAC,CAAC;IACH,EAAE,CAAC,EAAE,CAAC,cAAc,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE;QACrC,WAAW,CAAC,EAAE,EAAE,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACrC,CAAC,CAAC,CAAC;AACJ,CAAC;AAED,eAAe,2BAA2B,CAAC","sourcesContent":["import type { Api, Model } from \"@earendil-works/pi-ai\";\nimport { createApplyPatchTool } from \"./tool.ts\";\nimport type { ApplyPatchExtensionAPI, BaselineState } from \"./types.ts\";\n\n// apply_patch ships as a freeform custom tool, which only the OpenAI Responses-family\n// APIs can carry (openai-completions throws on freeform tools). Gate on the model's API\n// rather than a provider allowlist so OpenAI-compatible custom providers (e.g. a proxy\n// exposing gpt-5.5 via openai-responses) also swap edit/write for apply_patch.\nconst APPLY_PATCH_FREEFORM_APIS = new Set<Api>([\n\t\"openai-responses\",\n\t\"azure-openai-responses\",\n\t\"openai-codex-responses\",\n]);\nconst EDIT_TOOL_NAMES = new Set([\"write\", \"edit\"]);\n\nexport function isOpenAIGptModel(model: Pick<Model<string>, \"api\" | \"id\"> | undefined): boolean {\n\treturn model !== undefined && APPLY_PATCH_FREEFORM_APIS.has(model.api) && model.id.startsWith(\"gpt-\");\n}\n\nfunction hasEditTools(toolNames: string[]): boolean {\n\treturn toolNames.some((toolName) => EDIT_TOOL_NAMES.has(toolName));\n}\n\nfunction withoutApplyPatch(toolNames: string[]): string[] {\n\treturn toolNames.filter((toolName) => toolName !== \"apply_patch\");\n}\n\nfunction replaceEditToolsWithApplyPatch(toolNames: string[]): string[] {\n\tconst filteredToolNames = withoutApplyPatch(toolNames).filter((toolName) => !EDIT_TOOL_NAMES.has(toolName));\n\tif (!hasEditTools(toolNames)) return filteredToolNames;\n\treturn [...filteredToolNames, \"apply_patch\"];\n}\n\nfunction restoreEditToolsFromBaseline(currentToolNames: string[], baselineToolNames: string[]): string[] {\n\tconst restoredToolNames = [\n\t\t...withoutApplyPatch(currentToolNames),\n\t\t...baselineToolNames.filter((toolName) => EDIT_TOOL_NAMES.has(toolName)),\n\t];\n\treturn [...new Set(restoredToolNames)];\n}\n\nfunction syncToolset(\n\tpi: Pick<ApplyPatchExtensionAPI, \"getActiveTools\" | \"setActiveTools\">,\n\tmodel: Model<string> | undefined,\n\tstate: BaselineState,\n): void {\n\tconst currentToolNames = pi.getActiveTools();\n\tif (isOpenAIGptModel(model)) {\n\t\tif (hasEditTools(currentToolNames)) state.nonGptToolNames = withoutApplyPatch(currentToolNames);\n\t\tpi.setActiveTools(replaceEditToolsWithApplyPatch(currentToolNames));\n\t\treturn;\n\t}\n\n\tif (state.nonGptToolNames.length > 0) {\n\t\tconst restoredToolNames = restoreEditToolsFromBaseline(currentToolNames, state.nonGptToolNames);\n\t\tstate.nonGptToolNames = restoredToolNames;\n\t\tpi.setActiveTools(restoredToolNames);\n\t\treturn;\n\t}\n\n\tstate.nonGptToolNames = withoutApplyPatch(currentToolNames);\n\tpi.setActiveTools(state.nonGptToolNames);\n}\n\nexport function registerApplyPatchExtension(pi: ApplyPatchExtensionAPI): void {\n\tconst state: BaselineState = { nonGptToolNames: [] };\n\tpi.registerTool(createApplyPatchTool());\n\tpi.on(\"session_start\", async (_event, ctx) => {\n\t\tsyncToolset(pi, ctx.model, state);\n\t});\n\tpi.on(\"model_select\", async (event) => {\n\t\tsyncToolset(pi, event.model, state);\n\t});\n}\n\nexport default registerApplyPatchExtension;\n"]}
1
+ {"version":3,"file":"extension.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/gpt-apply-patch/extension.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAQjD,MAAM,yBAAyB,GAAG,IAAI,GAAG,CAAM;IAC9C,kBAAkB;IAClB,wBAAwB;IACxB,wBAAwB;CACxB,CAAC,CAAC;AACH,MAAM,qBAAqB,GAAG,IAAI,GAAG,CAAM,CAAC,oBAAoB,CAAC,CAAC,CAAC;AACnE,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC;AACnD,MAAM,gBAAgB,GAAG,aAAa,CAAC;AAEvC,SAAS,OAAO,CAAC,KAAoD;IACpE,OAAO,KAAK,EAAE,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC;AAC9C,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,KAAoD;IACzF,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,MAAM,CAAC;IACnC,IAAI,yBAAyB,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC;QAAE,OAAO,UAAU,C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PatchExtensionAPI,\n\tApplyPatchToolsetState,\n\tApplyPatchToolVariant,\n\tApplyPatchWireMode,\n} from \"./types.ts\";\n\nconst APPLY_PATCH_FREEFORM_APIS = new Set<Api>([\n\t\"openai-responses\",\n\t\"azure-openai-responses\",\n\t\"openai-codex-responses\",\n]);\nconst APPLY_PATCH_JSON_APIS = new Set<Api>([\"openai-completions\"]);\nconst EDIT_TOOL_NAMES = new Set([\"write\", \"edit\"]);\nconst APPLY_PATCH_NAME = \"apply_patch\";\n\nfunction isGptId(model: Pick<Model<string>, \"api\" | \"id\"> | undefined): model is Pick<Model<string>, \"api\" | \"id\"> {\n\treturn model?.id.startsWith(\"gpt-\") ?? false;\n}\n\nexport function getApplyPatchWireMode(model: Pick<Model<string>, \"api\" | \"id\"> | undefined): ApplyPatchWireMode {\n\tif (!isGptId(model)) return \"none\";\n\tif (APPLY_PATCH_FREEFORM_APIS.has(model.api)) return \"freeform\";\n\tif (APPLY_PATCH_JSON_APIS.has(model.api)) return \"json\";\n\treturn \"none\";\n}\n\nexport function isOpenAIGptModel(model: Pick<Model<string>, \"api\" | \"id\"> | undefined): boolean {\n\treturn getApplyPatchWireMode(model) === \"freeform\";\n}\n\nfunction hasEditTools(toolNames: string[]): boolean {\n\treturn toolNames.some((toolName) => EDIT_TOOL_NAMES.has(toolName));\n}\n\nfunction withoutApplyPatch(toolNames: string[]): string[] {\n\treturn toolNames.filter((toolName) => toolName !== APPLY_PATCH_NAME);\n}\n\nfunction replaceEditToolsWithApplyPatch(toolNames: string[]): string[] {\n\tconst hadApplyPatch = toolNames.includes(APPLY_PATCH_NAME);\n\tconst insertIndex = toolNames.findIndex(\n\t\t(toolName) => EDIT_TOOL_NAMES.has(toolName) || toolName === APPLY_PATCH_NAME,\n\t);\n\tconst filteredToolNames = withoutApplyPatch(toolNames).filter((toolName) => !EDIT_TOOL_NAMES.has(toolName));\n\tif (!hasEditTools(toolNames) && !hadApplyPatch) return filteredToolNames;\n\tconst at = insertIndex === -1 ? filteredToolNames.length : Math.min(insertIndex, filteredToolNames.length);\n\treturn [...filteredToolNames.slice(0, at), APPLY_PATCH_NAME, ...filteredToolNames.slice(at)];\n}\n\nfunction syncToolset(\n\tpi: ApplyPatchExtensionAPI,\n\tmodel: Model<string> | undefined,\n\tstate: ApplyPatchToolsetState & { activeVariant?: ApplyPatchToolVariant },\n\tvariants: Readonly<Record<ApplyPatchToolVariant, ReturnType<typeof createApplyPatchTool>>>,\n): void {\n\tconst mode = getApplyPatchWireMode(model);\n\tconst currentToolNames = pi.getActiveTools();\n\tif (mode !== \"none\") {\n\t\tif (state.activeVariant !== mode) {\n\t\t\tpi.registerTool(variants[mode]);\n\t\t\tstate.activeVariant = mode;\n\t\t}\n\t\tconst activeEdit = currentToolNames.filter((toolName) => EDIT_TOOL_NAMES.has(toolName));\n\t\tif (activeEdit.length > 0) state.removedEditToolNames = activeEdit;\n\t\tpi.setActiveTools(replaceEditToolsWithApplyPatch(currentToolNames));\n\t\treturn;\n\t}\n\tif (state.removedEditToolNames.length === 0) {\n\t\tif (currentToolNames.includes(APPLY_PATCH_NAME)) pi.setActiveTools(withoutApplyPatch(currentToolNames));\n\t\treturn;\n\t}\n\tconst registeredNames = new Set(pi.getAllTools().map((tool) => tool.name));\n\tconst restorable = state.removedEditToolNames.filter((toolName) => registeredNames.has(toolName));\n\tconst restored = [...withoutApplyPatch(currentToolNames), ...restorable];\n\tstate.removedEditToolNames = [];\n\tpi.setActiveTools([...new Set(restored)]);\n}\n\nexport function registerApplyPatchExtension(pi: ApplyPatchExtensionAPI): void {\n\tconst state: ApplyPatchToolsetState & { activeVariant?: ApplyPatchToolVariant } = { removedEditToolNames: [] };\n\tconst variants = {\n\t\tfreeform: createApplyPatchTool(\"freeform\"),\n\t\tjson: createApplyPatchTool(\"json\"),\n\t} as const;\n\tstate.activeVariant = \"freeform\";\n\tpi.registerTool(variants.freeform);\n\tpi.on(\"session_start\", async (_event, ctx) => {\n\t\tsyncToolset(pi, ctx.model, state, variants);\n\t});\n\tpi.on(\"model_select\", async (event) => {\n\t\tsyncToolset(pi, event.model, state, variants);\n\t});\n}\n\nexport default registerApplyPatchExtension;\n"]}
@@ -1,7 +1,7 @@
1
1
  export { __testWriteFileAtomic, applyPatch, applyPatchDetailed, buildPartialFailureText } from "./apply.ts";
2
- export { APPLY_PATCH_FREEFORM_DESCRIPTION, APPLY_PATCH_LARK_GRAMMAR, APPLY_PATCH_PARAMS, CODEX_APPLY_PATCH_DESCRIPTION, } from "./constants.ts";
2
+ export { APPLY_PATCH_FREEFORM_DESCRIPTION, APPLY_PATCH_JSON_DESCRIPTION, APPLY_PATCH_LARK_GRAMMAR, APPLY_PATCH_PARAMS, CODEX_APPLY_PATCH_DESCRIPTION, } from "./constants.ts";
3
3
  export { ApplyPatchError } from "./errors.ts";
4
- export { default, isOpenAIGptModel, registerApplyPatchExtension } from "./extension.ts";
4
+ export { default, getApplyPatchWireMode, isOpenAIGptModel, registerApplyPatchExtension } from "./extension.ts";
5
5
  export { parsePatch } from "./parser.ts";
6
6
  export { clearApplyPatchRenderState, displayPath, formatInFlightCallText, formatPatchPreview, getApplyPatchRenderState, PATCH_PREVIEW_MAX_CHARS, PATCH_PREVIEW_MAX_LINES, renderPatchPreview, truncatePreview, } from "./preview-format.ts";
7
7
  export { seekSequence } from "./seek-sequence.ts";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/gpt-apply-patch/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,UAAU,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAC5G,OAAO,EACN,gCAAgC,EAChC,wBAAwB,EACxB,kBAAkB,EAClB,6BAA6B,GAC7B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,2BAA2B,EAAE,MAAM,gBAAgB,CAAC;AACxF,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EACN,0BAA0B,EAC1B,WAAW,EACX,sBAAsB,EACtB,kBAAkB,EAClB,wBAAwB,EACxB,uBAAuB,EACvB,uBAAuB,EACvB,kBAAkB,EAClB,eAAe,GACf,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAClF,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AACjD,YAAY,EACX,sBAAsB,EACtB,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,0BAA0B,EAC1B,8BAA8B,EAC9B,qBAAqB,EACrB,gBAAgB,EAChB,wBAAwB,EACxB,qBAAqB,EACrB,qBAAqB,EACrB,kBAAkB,EAClB,WAAW,EACX,UAAU,GACV,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/gpt-apply-patch/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,UAAU,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAC5G,OAAO,EACN,gCAAgC,EAChC,4BAA4B,EAC5B,wBAAwB,EACxB,kBAAkB,EAClB,6BAA6B,GAC7B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,2BAA2B,EAAE,MAAM,gBAAgB,CAAC;AAC/G,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EACN,0BAA0B,EAC1B,WAAW,EACX,sBAAsB,EACtB,kBAAkB,EAClB,wBAAwB,EACxB,uBAAuB,EACvB,uBAAuB,EACvB,kBAAkB,EAClB,eAAe,GACf,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAClF,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AACjD,YAAY,EACX,sBAAsB,EACtB,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,0BAA0B,EAC1B,8BAA8B,EAC9B,qBAAqB,EACrB,gBAAgB,EAChB,wBAAwB,EACxB,qBAAqB,EACrB,qBAAqB,EACrB,kBAAkB,EAClB,WAAW,EACX,UAAU,GACV,MAAM,YAAY,CAAC"}
@@ -1,7 +1,7 @@
1
1
  export { __testWriteFileAtomic, applyPatch, applyPatchDetailed, buildPartialFailureText } from "./apply.js";
2
- export { APPLY_PATCH_FREEFORM_DESCRIPTION, APPLY_PATCH_LARK_GRAMMAR, APPLY_PATCH_PARAMS, CODEX_APPLY_PATCH_DESCRIPTION, } from "./constants.js";
2
+ export { APPLY_PATCH_FREEFORM_DESCRIPTION, APPLY_PATCH_JSON_DESCRIPTION, APPLY_PATCH_LARK_GRAMMAR, APPLY_PATCH_PARAMS, CODEX_APPLY_PATCH_DESCRIPTION, } from "./constants.js";
3
3
  export { ApplyPatchError } from "./errors.js";
4
- export { default, isOpenAIGptModel, registerApplyPatchExtension } from "./extension.js";
4
+ export { default, getApplyPatchWireMode, isOpenAIGptModel, registerApplyPatchExtension } from "./extension.js";
5
5
  export { parsePatch } from "./parser.js";
6
6
  export { clearApplyPatchRenderState, displayPath, formatInFlightCallText, formatPatchPreview, getApplyPatchRenderState, PATCH_PREVIEW_MAX_CHARS, PATCH_PREVIEW_MAX_LINES, renderPatchPreview, truncatePreview, } from "./preview-format.js";
7
7
  export { seekSequence } from "./seek-sequence.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/gpt-apply-patch/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,UAAU,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAC5G,OAAO,EACN,gCAAgC,EAChC,wBAAwB,EACxB,kBAAkB,EAClB,6BAA6B,GAC7B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,2BAA2B,EAAE,MAAM,gBAAgB,CAAC;AACxF,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EACN,0BAA0B,EAC1B,WAAW,EACX,sBAAsB,EACtB,kBAAkB,EAClB,wBAAwB,EACxB,uBAAuB,EACvB,uBAAuB,EACvB,kBAAkB,EAClB,eAAe,GACf,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAClF,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC","sourcesContent":["export { __testWriteFileAtomic, applyPatch, applyPatchDetailed, buildPartialFailureText } from \"./apply.ts\";\nexport {\n\tAPPLY_PATCH_FREEFORM_DESCRIPTION,\n\tAPPLY_PATCH_LARK_GRAMMAR,\n\tAPPLY_PATCH_PARAMS,\n\tCODEX_APPLY_PATCH_DESCRIPTION,\n} from \"./constants.ts\";\nexport { ApplyPatchError } from \"./errors.ts\";\nexport { default, isOpenAIGptModel, registerApplyPatchExtension } from \"./extension.ts\";\nexport { parsePatch } from \"./parser.ts\";\nexport {\n\tclearApplyPatchRenderState,\n\tdisplayPath,\n\tformatInFlightCallText,\n\tformatPatchPreview,\n\tgetApplyPatchRenderState,\n\tPATCH_PREVIEW_MAX_CHARS,\n\tPATCH_PREVIEW_MAX_LINES,\n\trenderPatchPreview,\n\ttruncatePreview,\n} from \"./preview-format.ts\";\nexport { seekSequence } from \"./seek-sequence.ts\";\nexport { StreamingPatchParser } from \"./streaming-parser.ts\";\nexport { extractPatchedPaths, normalizePatchText, stripHeredoc } from \"./text.ts\";\nexport { createApplyPatchTool } from \"./tool.ts\";\nexport type {\n\tApplyPatchExtensionAPI,\n\tApplyPatchFailure,\n\tApplyPatchParams,\n\tApplyPatchPreview,\n\tApplyPatchProgress,\n\tApplyPatchProgressCallback,\n\tApplyPatchRecoveryInstructions,\n\tApplyPatchRenderState,\n\tApplyPatchResult,\n\tApplyPatchToolDefinition,\n\tApplyPatchToolDetails,\n\tAtomicWriteOperations,\n\tFreeformToolFormat,\n\tParsedPatch,\n\tPatchChunk,\n} from \"./types.ts\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/gpt-apply-patch/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,UAAU,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAC5G,OAAO,EACN,gCAAgC,EAChC,4BAA4B,EAC5B,wBAAwB,EACxB,kBAAkB,EAClB,6BAA6B,GAC7B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,2BAA2B,EAAE,MAAM,gBAAgB,CAAC;AAC/G,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EACN,0BAA0B,EAC1B,WAAW,EACX,sBAAsB,EACtB,kBAAkB,EAClB,wBAAwB,EACxB,uBAAuB,EACvB,uBAAuB,EACvB,kBAAkB,EAClB,eAAe,GACf,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAClF,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC","sourcesContent":["export { __testWriteFileAtomic, applyPatch, applyPatchDetailed, buildPartialFailureText } from \"./apply.ts\";\nexport {\n\tAPPLY_PATCH_FREEFORM_DESCRIPTION,\n\tAPPLY_PATCH_JSON_DESCRIPTION,\n\tAPPLY_PATCH_LARK_GRAMMAR,\n\tAPPLY_PATCH_PARAMS,\n\tCODEX_APPLY_PATCH_DESCRIPTION,\n} from \"./constants.ts\";\nexport { ApplyPatchError } from \"./errors.ts\";\nexport { default, getApplyPatchWireMode, isOpenAIGptModel, registerApplyPatchExtension } from \"./extension.ts\";\nexport { parsePatch } from \"./parser.ts\";\nexport {\n\tclearApplyPatchRenderState,\n\tdisplayPath,\n\tformatInFlightCallText,\n\tformatPatchPreview,\n\tgetApplyPatchRenderState,\n\tPATCH_PREVIEW_MAX_CHARS,\n\tPATCH_PREVIEW_MAX_LINES,\n\trenderPatchPreview,\n\ttruncatePreview,\n} from \"./preview-format.ts\";\nexport { seekSequence } from \"./seek-sequence.ts\";\nexport { StreamingPatchParser } from \"./streaming-parser.ts\";\nexport { extractPatchedPaths, normalizePatchText, stripHeredoc } from \"./text.ts\";\nexport { createApplyPatchTool } from \"./tool.ts\";\nexport type {\n\tApplyPatchExtensionAPI,\n\tApplyPatchFailure,\n\tApplyPatchParams,\n\tApplyPatchPreview,\n\tApplyPatchProgress,\n\tApplyPatchProgressCallback,\n\tApplyPatchRecoveryInstructions,\n\tApplyPatchRenderState,\n\tApplyPatchResult,\n\tApplyPatchToolDefinition,\n\tApplyPatchToolDetails,\n\tAtomicWriteOperations,\n\tFreeformToolFormat,\n\tParsedPatch,\n\tPatchChunk,\n} from \"./types.ts\";\n"]}
@@ -1,3 +1,3 @@
1
1
  import type { ApplyPatchToolDefinition } from "./types.ts";
2
- export declare function createApplyPatchTool(): ApplyPatchToolDefinition;
2
+ export declare function createApplyPatchTool(variant?: "freeform" | "json"): ApplyPatchToolDefinition;
3
3
  //# sourceMappingURL=tool.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tool.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/gpt-apply-patch/tool.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAGX,wBAAwB,EAGxB,MAAM,YAAY,CAAC;AAqCpB,wBAAgB,oBAAoB,IAAI,wBAAwB,CA2F/D"}
1
+ {"version":3,"file":"tool.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/gpt-apply-patch/tool.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAGX,wBAAwB,EAGxB,MAAM,YAAY,CAAC;AAqCpB,wBAAgB,oBAAoB,CAAC,OAAO,GAAE,UAAU,GAAG,MAAmB,GAAG,wBAAwB,CA4FxG"}
@@ -1,7 +1,7 @@
1
1
  import { Box, Container, Spacer, Text } from "@earendil-works/pi-tui";
2
2
  import { defineTool } from "../../types.js";
3
3
  import { applyPatchDetailed, buildPartialFailureText } from "./apply.js";
4
- import { APPLY_PATCH_FREEFORM_DESCRIPTION, APPLY_PATCH_LARK_GRAMMAR, APPLY_PATCH_PARAMS } from "./constants.js";
4
+ import { APPLY_PATCH_FREEFORM_DESCRIPTION, APPLY_PATCH_JSON_DESCRIPTION, APPLY_PATCH_LARK_GRAMMAR, APPLY_PATCH_PARAMS, } from "./constants.js";
5
5
  import { normalizeApplyPatchArguments } from "./params.js";
6
6
  import { parsePatch } from "./parser.js";
7
7
  import { createPendingPatchUpdate } from "./preview.js";
@@ -32,11 +32,11 @@ function renderTextResult(result, theme) {
32
32
  component.addChild(new Text(theme.fg("toolOutput", text), 0, 0));
33
33
  return component;
34
34
  }
35
- export function createApplyPatchTool() {
35
+ export function createApplyPatchTool(variant = "freeform") {
36
36
  const tool = defineTool({
37
37
  name: "apply_patch",
38
38
  label: "ApplyPatch",
39
- description: APPLY_PATCH_FREEFORM_DESCRIPTION,
39
+ description: variant === "json" ? APPLY_PATCH_JSON_DESCRIPTION : APPLY_PATCH_FREEFORM_DESCRIPTION,
40
40
  parameters: APPLY_PATCH_PARAMS,
41
41
  prepareArguments: normalizeApplyPatchArguments,
42
42
  promptSnippet: "Apply Codex-format file patches with apply_patch",
@@ -109,6 +109,8 @@ export function createApplyPatchTool() {
109
109
  return renderTextResult(result, theme);
110
110
  },
111
111
  });
112
+ if (variant === "json")
113
+ return tool;
112
114
  return Object.assign(tool, {
113
115
  freeform: { type: "grammar", syntax: "lark", definition: APPLY_PATCH_LARK_GRAMMAR },
114
116
  });
@@ -1 +1 @@
1
- {"version":3,"file":"tool.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/gpt-apply-patch/tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAEtE,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AACzE,OAAO,EAAE,gCAAgC,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAChH,OAAO,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACnF,OAAO,EAAE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,CAAC,CAAC;gBAC5B,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;oBAC5B,MAAM,QAAQ,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,IAAI,IAAI,CAAC,CAAC;oBACvE,GAAG,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,EAAE,KAAK,EAAE,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;gBACxG,CAAC;gBACD,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;gBACxB,OAAO,SAAS,CAAC;YAClB,CAAC;YACD,OAAO,gBAAgB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QACxC,CAAC;KACD,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE;QAC1B,QAAQ,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,wBAAwB,EAA+B;KAChH,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { Box, Container, Spacer, Text } from \"@earendil-works/pi-tui\";\nimport type { AgentToolResult, ToolRenderContext } from \"../../types.ts\";\nimport { defineTool } from \"../../types.ts\";\nimport { applyPatchDetailed, buildPartialFailureText } from \"./apply.ts\";\nimport { APPLY_PATCH_FREEFORM_DESCRIPTION, APPLY_PATCH_LARK_GRAMMAR, APPLY_PATCH_PARAMS } from \"./constants.ts\";\nimport { normalizeApplyPatchArguments } from \"./params.ts\";\nimport { parsePatch } from \"./parser.ts\";\nimport { createPendingPatchUpdate } from \"./preview.ts\";\nimport { getApplyPatchRenderState, renderPatchPreview } from \"./preview-format.ts\";\nimport { renderStreamingPatchCall } from \"./streaming-render.ts\";\nimport type {\n\tApplyPatchRenderState,\n\tApplyPatchTheme,\n\tApplyPatchToolDefinition,\n\tApplyPatchToolDetails,\n\tFreeformToolFormat,\n} from \"./types.ts\";\n\nfunction renderPreviewBox(\n\ttitle: string,\n\tdetails: ApplyPatchToolDetails,\n\tisPartial: boolean,\n\tcwd: string,\n\texpanded: boolean,\n\ttheme: ApplyPatchTheme,\n): Container {\n\tconst component = new Container();\n\tif (!details.preview) return component;\n\tconst bgName = isPartial ? \"toolPendingBg\" : \"toolSuccessBg\";\n\tconst progress = details.progress;\n\tconst renderedTitle = progress ? `Applying patch (${progress.applied + progress.failed}/${progress.total})` : title;\n\tconst box = new Box(1, 1, (text: string) => theme.bg(bgName, text));\n\tbox.addChild(new Text(theme.fg(\"toolTitle\", theme.bold(renderedTitle)), 0, 0));\n\tbox.addChild(new Spacer(1));\n\tbox.addChild(new Text(renderPatchPreview(details.preview, cwd, theme, expanded), 0, 0));\n\tcomponent.addChild(box);\n\treturn component;\n}\n\nfunction renderTextResult(\n\tresult: AgentToolResult<ApplyPatchToolDetails | undefined>,\n\ttheme: ApplyPatchTheme,\n): Container {\n\tconst component = new Container();\n\tconst text = result.content\n\t\t.filter((block) => block.type === \"text\")\n\t\t.map((block) => block.text)\n\t\t.filter((value) => typeof value === \"string\" && value.length > 0)\n\t\t.join(\"\\n\");\n\tif (text) component.addChild(new Text(theme.fg(\"toolOutput\", text), 0, 0));\n\treturn component;\n}\n\nexport function createApplyPatchTool(): ApplyPatchToolDefinition {\n\tconst tool = defineTool<typeof APPLY_PATCH_PARAMS, ApplyPatchToolDetails | undefined, ApplyPatchRenderState>({\n\t\tname: \"apply_patch\",\n\t\tlabel: \"ApplyPatch\",\n\t\tdescription: APPLY_PATCH_FREEFORM_DESCRIPTION,\n\t\tparameters: APPLY_PATCH_PARAMS,\n\t\tprepareArguments: normalizeApplyPatchArguments,\n\t\tpromptSnippet: \"Apply Codex-format file patches with apply_patch\",\n\t\tpromptGuidelines: [\n\t\t\t\"Use apply_patch for file edits instead of mutating files through bash, Python scripts, heredocs, or shell redirection.\",\n\t\t\t\"After apply_patch succeeds, do not re-read the edited files just to confirm the patch applied.\",\n\t\t],\n\t\tasync execute(\n\t\t\t_toolCallId,\n\t\t\tparams,\n\t\t\t_signal,\n\t\t\tonUpdate,\n\t\t\tctx,\n\t\t): Promise<AgentToolResult<ApplyPatchToolDetails | undefined>> {\n\t\t\tconst normalizedParams = normalizeApplyPatchArguments(params);\n\t\t\tif (!normalizedParams.input) throw new Error(\"input is required\");\n\t\t\tlet totalOperations = 0;\n\t\t\ttry {\n\t\t\t\ttotalOperations = parsePatch(normalizedParams.input).length;\n\t\t\t} catch {\n\t\t\t\t// createPendingPatchUpdate keeps incomplete or invalid patch text renderable.\n\t\t\t}\n\t\t\tconst initialProgress = totalOperations > 0 ? { applied: 0, failed: 0, total: totalOperations } : undefined;\n\t\t\tconst pendingUpdate = await createPendingPatchUpdate(ctx.cwd, normalizedParams.input, initialProgress);\n\t\t\tonUpdate?.({ content: [{ type: \"text\", text: pendingUpdate.text }], details: pendingUpdate.details });\n\t\t\tconst preview = pendingUpdate.details?.preview;\n\t\t\tconst result = await applyPatchDetailed(ctx.cwd, normalizedParams.input, async (progress) => {\n\t\t\t\tconst progressUpdate = await createPendingPatchUpdate(ctx.cwd, normalizedParams.input, progress, preview);\n\t\t\t\tonUpdate?.({ content: [{ type: \"text\", text: progressUpdate.text }], details: progressUpdate.details });\n\t\t\t});\n\t\t\tif (result.failures.length > 0) {\n\t\t\t\tif (result.appliedFiles.length === 0) {\n\t\t\t\t\tconst firstFailure = result.failures[0];\n\t\t\t\t\tif (firstFailure) throw new Error(firstFailure.message);\n\t\t\t\t}\n\t\t\t\treturn { content: [{ type: \"text\", text: buildPartialFailureText(result) }], details: { result } };\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tcontent: [{ type: \"text\", text: result.summaries.join(\"\\n\") }],\n\t\t\t\tdetails: pendingUpdate.details?.preview ? { preview: pendingUpdate.details.preview, result } : { result },\n\t\t\t};\n\t\t},\n\t\trenderCall(args, theme, context: ToolRenderContext<ApplyPatchRenderState, { input: string }>) {\n\t\t\tif (!context.executionStarted) {\n\t\t\t\tconst streaming = renderStreamingPatchCall(normalizeApplyPatchArguments(args), theme, context.state);\n\t\t\t\tif (streaming) return streaming;\n\t\t\t}\n\t\t\tif (!context.argsComplete) return new Text(theme.fg(\"toolTitle\", theme.bold(\"apply_patch: Patching\")), 0, 0);\n\t\t\tconst normalizedArgs = normalizeApplyPatchArguments(args);\n\t\t\tconst renderState = getApplyPatchRenderState(context.toolCallId, context.cwd, normalizedArgs.input);\n\t\t\tconst text = renderState.callText?.length ? `apply_patch: ${renderState.callText}` : \"apply_patch\";\n\t\t\treturn new Text(theme.fg(\"toolTitle\", theme.bold(text)), 0, 0);\n\t\t},\n\t\trenderResult(result, options, theme, context) {\n\t\t\tif (result.details?.preview) {\n\t\t\t\tconst expanded = true;\n\t\t\t\treturn renderPreviewBox(\n\t\t\t\t\toptions.isPartial ? \"Applying patch\" : \"Applied patch\",\n\t\t\t\t\tresult.details,\n\t\t\t\t\toptions.isPartial,\n\t\t\t\t\tcontext.cwd,\n\t\t\t\t\texpanded,\n\t\t\t\t\ttheme,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (result.details?.result) {\n\t\t\t\tconst component = new Container();\n\t\t\t\tconst box = new Box(1, 1, (text: string) =>\n\t\t\t\t\ttheme.bg(options.isPartial ? \"toolPendingBg\" : \"toolSuccessBg\", text),\n\t\t\t\t);\n\t\t\t\tbox.addChild(new Text(theme.fg(\"toolTitle\", theme.bold(\"Applying patch\")), 0, 0));\n\t\t\t\tbox.addChild(new Spacer(1));\n\t\t\t\tif (result.details.preview) {\n\t\t\t\t\tconst expanded = options.isPartial ? true : (options.expanded ?? true);\n\t\t\t\t\tbox.addChild(new Text(renderPatchPreview(result.details.preview, context.cwd, theme, expanded), 0, 0));\n\t\t\t\t}\n\t\t\t\tcomponent.addChild(box);\n\t\t\t\treturn component;\n\t\t\t}\n\t\t\treturn renderTextResult(result, theme);\n\t\t},\n\t});\n\n\treturn Object.assign(tool, {\n\t\tfreeform: { type: \"grammar\", syntax: \"lark\", definition: APPLY_PATCH_LARK_GRAMMAR } satisfies FreeformToolFormat,\n\t});\n}\n"]}
1
+ {"version":3,"file":"tool.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/gpt-apply-patch/tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAEtE,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AACzE,OAAO,EACN,gCAAgC,EAChC,4BAA4B,EAC5B,wBAAwB,EACxB,kBAAkB,GAClB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACnF,OAAO,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AASjE,SAAS,gBAAgB,CACxB,KAAa,EACb,OAA8B,EAC9B,SAAkB,EAClB,GAAW,EACX,QAAiB,EACjB,KAAsB;IAEtB,MAAM,SAAS,GAAG,IAAI,SAAS,EAAE,CAAC;IAClC,IAAI,CAAC,OAAO,CAAC,OAAO;QAAE,OAAO,SAAS,CAAC;IACvC,MAAM,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,eAAe,CAAC;IAC7D,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;IAClC,MAAM,aAAa,GAAG,QAAQ,CAAC,CAAC,CAAC,mBAAmB,QAAQ,CAAC,OAAO,GAAG,QAAQ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AC,CAAC,CAAC,CAAC;gBACxG,CAAC;gBACD,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;gBACxB,OAAO,SAAS,CAAC;YAClB,CAAC;YACD,OAAO,gBAAgB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QACxC,CAAC;KACD,CAAC,CAAC;IAEH,IAAI,OAAO,KAAK,MAAM;QAAE,OAAO,IAAI,CAAC;IACpC,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE;QAC1B,QAAQ,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,wBAAwB,EAA+B;KAChH,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { Box, Container, Spacer, Text } from \"@earendil-works/pi-tui\";\nimport type { AgentToolResult, ToolRenderContext } from \"../../types.ts\";\nimport { defineTool } from \"../../types.ts\";\nimport { applyPatchDetailed, buildPartialFailureText } from \"./apply.ts\";\nimport {\n\tAPPLY_PATCH_FREEFORM_DESCRIPTION,\n\tAPPLY_PATCH_JSON_DESCRIPTION,\n\tAPPLY_PATCH_LARK_GRAMMAR,\n\tAPPLY_PATCH_PARAMS,\n} from \"./constants.ts\";\nimport { normalizeApplyPatchArguments } from \"./params.ts\";\nimport { parsePatch } from \"./parser.ts\";\nimport { createPendingPatchUpdate } from \"./preview.ts\";\nimport { getApplyPatchRenderState, renderPatchPreview } from \"./preview-format.ts\";\nimport { renderStreamingPatchCall } from \"./streaming-render.ts\";\nimport type {\n\tApplyPatchRenderState,\n\tApplyPatchTheme,\n\tApplyPatchToolDefinition,\n\tApplyPatchToolDetails,\n\tFreeformToolFormat,\n} from \"./types.ts\";\n\nfunction renderPreviewBox(\n\ttitle: string,\n\tdetails: ApplyPatchToolDetails,\n\tisPartial: boolean,\n\tcwd: string,\n\texpanded: boolean,\n\ttheme: ApplyPatchTheme,\n): Container {\n\tconst component = new Container();\n\tif (!details.preview) return component;\n\tconst bgName = isPartial ? \"toolPendingBg\" : \"toolSuccessBg\";\n\tconst progress = details.progress;\n\tconst renderedTitle = progress ? `Applying patch (${progress.applied + progress.failed}/${progress.total})` : title;\n\tconst box = new Box(1, 1, (text: string) => theme.bg(bgName, text));\n\tbox.addChild(new Text(theme.fg(\"toolTitle\", theme.bold(renderedTitle)), 0, 0));\n\tbox.addChild(new Spacer(1));\n\tbox.addChild(new Text(renderPatchPreview(details.preview, cwd, theme, expanded), 0, 0));\n\tcomponent.addChild(box);\n\treturn component;\n}\n\nfunction renderTextResult(\n\tresult: AgentToolResult<ApplyPatchToolDetails | undefined>,\n\ttheme: ApplyPatchTheme,\n): Container {\n\tconst component = new Container();\n\tconst text = result.content\n\t\t.filter((block) => block.type === \"text\")\n\t\t.map((block) => block.text)\n\t\t.filter((value) => typeof value === \"string\" && value.length > 0)\n\t\t.join(\"\\n\");\n\tif (text) component.addChild(new Text(theme.fg(\"toolOutput\", text), 0, 0));\n\treturn component;\n}\n\nexport function createApplyPatchTool(variant: \"freeform\" | \"json\" = \"freeform\"): ApplyPatchToolDefinition {\n\tconst tool = defineTool<typeof APPLY_PATCH_PARAMS, ApplyPatchToolDetails | undefined, ApplyPatchRenderState>({\n\t\tname: \"apply_patch\",\n\t\tlabel: \"ApplyPatch\",\n\t\tdescription: variant === \"json\" ? APPLY_PATCH_JSON_DESCRIPTION : APPLY_PATCH_FREEFORM_DESCRIPTION,\n\t\tparameters: APPLY_PATCH_PARAMS,\n\t\tprepareArguments: normalizeApplyPatchArguments,\n\t\tpromptSnippet: \"Apply Codex-format file patches with apply_patch\",\n\t\tpromptGuidelines: [\n\t\t\t\"Use apply_patch for file edits instead of mutating files through bash, Python scripts, heredocs, or shell redirection.\",\n\t\t\t\"After apply_patch succeeds, do not re-read the edited files just to confirm the patch applied.\",\n\t\t],\n\t\tasync execute(\n\t\t\t_toolCallId,\n\t\t\tparams,\n\t\t\t_signal,\n\t\t\tonUpdate,\n\t\t\tctx,\n\t\t): Promise<AgentToolResult<ApplyPatchToolDetails | undefined>> {\n\t\t\tconst normalizedParams = normalizeApplyPatchArguments(params);\n\t\t\tif (!normalizedParams.input) throw new Error(\"input is required\");\n\t\t\tlet totalOperations = 0;\n\t\t\ttry {\n\t\t\t\ttotalOperations = parsePatch(normalizedParams.input).length;\n\t\t\t} catch {\n\t\t\t\t// createPendingPatchUpdate keeps incomplete or invalid patch text renderable.\n\t\t\t}\n\t\t\tconst initialProgress = totalOperations > 0 ? { applied: 0, failed: 0, total: totalOperations } : undefined;\n\t\t\tconst pendingUpdate = await createPendingPatchUpdate(ctx.cwd, normalizedParams.input, initialProgress);\n\t\t\tonUpdate?.({ content: [{ type: \"text\", text: pendingUpdate.text }], details: pendingUpdate.details });\n\t\t\tconst preview = pendingUpdate.details?.preview;\n\t\t\tconst result = await applyPatchDetailed(ctx.cwd, normalizedParams.input, async (progress) => {\n\t\t\t\tconst progressUpdate = await createPendingPatchUpdate(ctx.cwd, normalizedParams.input, progress, preview);\n\t\t\t\tonUpdate?.({ content: [{ type: \"text\", text: progressUpdate.text }], details: progressUpdate.details });\n\t\t\t});\n\t\t\tif (result.failures.length > 0) {\n\t\t\t\tif (result.appliedFiles.length === 0) {\n\t\t\t\t\tconst firstFailure = result.failures[0];\n\t\t\t\t\tif (firstFailure) throw new Error(firstFailure.message);\n\t\t\t\t}\n\t\t\t\treturn { content: [{ type: \"text\", text: buildPartialFailureText(result) }], details: { result } };\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tcontent: [{ type: \"text\", text: result.summaries.join(\"\\n\") }],\n\t\t\t\tdetails: pendingUpdate.details?.preview ? { preview: pendingUpdate.details.preview, result } : { result },\n\t\t\t};\n\t\t},\n\t\trenderCall(args, theme, context: ToolRenderContext<ApplyPatchRenderState, { input: string }>) {\n\t\t\tif (!context.executionStarted) {\n\t\t\t\tconst streaming = renderStreamingPatchCall(normalizeApplyPatchArguments(args), theme, context.state);\n\t\t\t\tif (streaming) return streaming;\n\t\t\t}\n\t\t\tif (!context.argsComplete) return new Text(theme.fg(\"toolTitle\", theme.bold(\"apply_patch: Patching\")), 0, 0);\n\t\t\tconst normalizedArgs = normalizeApplyPatchArguments(args);\n\t\t\tconst renderState = getApplyPatchRenderState(context.toolCallId, context.cwd, normalizedArgs.input);\n\t\t\tconst text = renderState.callText?.length ? `apply_patch: ${renderState.callText}` : \"apply_patch\";\n\t\t\treturn new Text(theme.fg(\"toolTitle\", theme.bold(text)), 0, 0);\n\t\t},\n\t\trenderResult(result, options, theme, context) {\n\t\t\tif (result.details?.preview) {\n\t\t\t\tconst expanded = true;\n\t\t\t\treturn renderPreviewBox(\n\t\t\t\t\toptions.isPartial ? \"Applying patch\" : \"Applied patch\",\n\t\t\t\t\tresult.details,\n\t\t\t\t\toptions.isPartial,\n\t\t\t\t\tcontext.cwd,\n\t\t\t\t\texpanded,\n\t\t\t\t\ttheme,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (result.details?.result) {\n\t\t\t\tconst component = new Container();\n\t\t\t\tconst box = new Box(1, 1, (text: string) =>\n\t\t\t\t\ttheme.bg(options.isPartial ? \"toolPendingBg\" : \"toolSuccessBg\", text),\n\t\t\t\t);\n\t\t\t\tbox.addChild(new Text(theme.fg(\"toolTitle\", theme.bold(\"Applying patch\")), 0, 0));\n\t\t\t\tbox.addChild(new Spacer(1));\n\t\t\t\tif (result.details.preview) {\n\t\t\t\t\tconst expanded = options.isPartial ? true : (options.expanded ?? true);\n\t\t\t\t\tbox.addChild(new Text(renderPatchPreview(result.details.preview, context.cwd, theme, expanded), 0, 0));\n\t\t\t\t}\n\t\t\t\tcomponent.addChild(box);\n\t\t\t\treturn component;\n\t\t\t}\n\t\t\treturn renderTextResult(result, theme);\n\t\t},\n\t});\n\n\tif (variant === \"json\") return tool;\n\treturn Object.assign(tool, {\n\t\tfreeform: { type: \"grammar\", syntax: \"lark\", definition: APPLY_PATCH_LARK_GRAMMAR } satisfies FreeformToolFormat,\n\t});\n}\n"]}