@code-yeongyu/senpi 2026.7.17-5 → 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 (605) hide show
  1. package/CHANGELOG.md +41 -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/extensions/builtin/compaction/index.d.ts.map +1 -1
  18. package/dist/core/extensions/builtin/compaction/index.js +68 -10
  19. package/dist/core/extensions/builtin/compaction/index.js.map +1 -1
  20. package/dist/core/extensions/builtin/compaction/speculative.d.ts +7 -1
  21. package/dist/core/extensions/builtin/compaction/speculative.d.ts.map +1 -1
  22. package/dist/core/extensions/builtin/compaction/speculative.js +29 -11
  23. package/dist/core/extensions/builtin/compaction/speculative.js.map +1 -1
  24. package/dist/core/extensions/builtin/compaction/todo-bridge.d.ts +9 -7
  25. package/dist/core/extensions/builtin/compaction/todo-bridge.d.ts.map +1 -1
  26. package/dist/core/extensions/builtin/compaction/todo-bridge.js +34 -9
  27. package/dist/core/extensions/builtin/compaction/todo-bridge.js.map +1 -1
  28. package/dist/core/extensions/builtin/goal/command-registration.d.ts +2 -2
  29. package/dist/core/extensions/builtin/goal/command-registration.d.ts.map +1 -1
  30. package/dist/core/extensions/builtin/goal/command-registration.js +3 -4
  31. package/dist/core/extensions/builtin/goal/command-registration.js.map +1 -1
  32. package/dist/core/extensions/builtin/goal/index.d.ts.map +1 -1
  33. package/dist/core/extensions/builtin/goal/index.js +11 -27
  34. package/dist/core/extensions/builtin/goal/index.js.map +1 -1
  35. package/dist/core/extensions/builtin/goal/tool-registration.d.ts +2 -2
  36. package/dist/core/extensions/builtin/goal/tool-registration.d.ts.map +1 -1
  37. package/dist/core/extensions/builtin/goal/tool-registration.js +2 -3
  38. package/dist/core/extensions/builtin/goal/tool-registration.js.map +1 -1
  39. package/dist/core/extensions/builtin/goal/turn-usage.d.ts +20 -0
  40. package/dist/core/extensions/builtin/goal/turn-usage.d.ts.map +1 -0
  41. package/dist/core/extensions/builtin/goal/turn-usage.js +61 -0
  42. package/dist/core/extensions/builtin/goal/turn-usage.js.map +1 -0
  43. package/dist/core/extensions/builtin/gpt-apply-patch/constants.d.ts +1 -0
  44. package/dist/core/extensions/builtin/gpt-apply-patch/constants.d.ts.map +1 -1
  45. package/dist/core/extensions/builtin/gpt-apply-patch/constants.js +5 -1
  46. package/dist/core/extensions/builtin/gpt-apply-patch/constants.js.map +1 -1
  47. package/dist/core/extensions/builtin/gpt-apply-patch/extension.d.ts +2 -1
  48. package/dist/core/extensions/builtin/gpt-apply-patch/extension.d.ts.map +1 -1
  49. package/dist/core/extensions/builtin/gpt-apply-patch/extension.js +48 -29
  50. package/dist/core/extensions/builtin/gpt-apply-patch/extension.js.map +1 -1
  51. package/dist/core/extensions/builtin/gpt-apply-patch/index.d.ts +2 -2
  52. package/dist/core/extensions/builtin/gpt-apply-patch/index.d.ts.map +1 -1
  53. package/dist/core/extensions/builtin/gpt-apply-patch/index.js +2 -2
  54. package/dist/core/extensions/builtin/gpt-apply-patch/index.js.map +1 -1
  55. package/dist/core/extensions/builtin/gpt-apply-patch/tool.d.ts +1 -1
  56. package/dist/core/extensions/builtin/gpt-apply-patch/tool.d.ts.map +1 -1
  57. package/dist/core/extensions/builtin/gpt-apply-patch/tool.js +5 -3
  58. package/dist/core/extensions/builtin/gpt-apply-patch/tool.js.map +1 -1
  59. package/dist/core/extensions/builtin/gpt-apply-patch/types.d.ts +7 -6
  60. package/dist/core/extensions/builtin/gpt-apply-patch/types.d.ts.map +1 -1
  61. package/dist/core/extensions/builtin/gpt-apply-patch/types.js.map +1 -1
  62. package/dist/core/extensions/builtin/hooks/matcher.d.ts.map +1 -1
  63. package/dist/core/extensions/builtin/hooks/matcher.js +1 -0
  64. package/dist/core/extensions/builtin/hooks/matcher.js.map +1 -1
  65. package/dist/core/extensions/builtin/index.d.ts.map +1 -1
  66. package/dist/core/extensions/builtin/index.js +4 -0
  67. package/dist/core/extensions/builtin/index.js.map +1 -1
  68. package/dist/core/extensions/builtin/model-fallback/index.d.ts +4 -0
  69. package/dist/core/extensions/builtin/model-fallback/index.d.ts.map +1 -0
  70. package/dist/core/extensions/builtin/model-fallback/index.js +55 -0
  71. package/dist/core/extensions/builtin/model-fallback/index.js.map +1 -0
  72. package/dist/core/extensions/builtin/model-fallback/settings.d.ts +6 -0
  73. package/dist/core/extensions/builtin/model-fallback/settings.d.ts.map +1 -0
  74. package/dist/core/extensions/builtin/model-fallback/settings.js +11 -0
  75. package/dist/core/extensions/builtin/model-fallback/settings.js.map +1 -0
  76. package/dist/core/extensions/builtin/model-fallback/ui.d.ts +12 -0
  77. package/dist/core/extensions/builtin/model-fallback/ui.d.ts.map +1 -0
  78. package/dist/core/extensions/builtin/model-fallback/ui.js +72 -0
  79. package/dist/core/extensions/builtin/model-fallback/ui.js.map +1 -0
  80. package/dist/core/extensions/builtin/nested-agents-md/index.d.ts.map +1 -1
  81. package/dist/core/extensions/builtin/nested-agents-md/index.js +4 -1
  82. package/dist/core/extensions/builtin/nested-agents-md/index.js.map +1 -1
  83. package/dist/core/extensions/builtin/prompt-preset/glm-5-2.js +1 -1
  84. package/dist/core/extensions/builtin/prompt-preset/glm-5-2.js.map +1 -1
  85. package/dist/core/extensions/builtin/prompt-preset/gpt-5.5.js +2 -2
  86. package/dist/core/extensions/builtin/prompt-preset/gpt-5.5.js.map +1 -1
  87. package/dist/core/extensions/builtin/prompt-preset/gpt-5.6.js +2 -2
  88. package/dist/core/extensions/builtin/prompt-preset/gpt-5.6.js.map +1 -1
  89. package/dist/core/extensions/builtin/prompt-preset/grok-4.5.d.ts +3 -0
  90. package/dist/core/extensions/builtin/prompt-preset/grok-4.5.d.ts.map +1 -0
  91. package/dist/core/extensions/builtin/prompt-preset/grok-4.5.js +80 -0
  92. package/dist/core/extensions/builtin/prompt-preset/grok-4.5.js.map +1 -0
  93. package/dist/core/extensions/builtin/prompt-preset/presets.d.ts.map +1 -1
  94. package/dist/core/extensions/builtin/prompt-preset/presets.js +14 -0
  95. package/dist/core/extensions/builtin/prompt-preset/presets.js.map +1 -1
  96. package/dist/core/extensions/builtin/prompt-preset/settings.d.ts +1 -1
  97. package/dist/core/extensions/builtin/prompt-preset/settings.d.ts.map +1 -1
  98. package/dist/core/extensions/builtin/prompt-preset/settings.js +1 -0
  99. package/dist/core/extensions/builtin/prompt-preset/settings.js.map +1 -1
  100. package/dist/core/extensions/builtin/rules/index.d.ts.map +1 -1
  101. package/dist/core/extensions/builtin/rules/index.js +4 -1
  102. package/dist/core/extensions/builtin/rules/index.js.map +1 -1
  103. package/dist/core/extensions/builtin/terminal/shared.d.ts +7 -0
  104. package/dist/core/extensions/builtin/terminal/shared.d.ts.map +1 -1
  105. package/dist/core/extensions/builtin/terminal/shared.js +7 -0
  106. package/dist/core/extensions/builtin/terminal/shared.js.map +1 -1
  107. package/dist/core/extensions/builtin/terminal/tools/bash.d.ts.map +1 -1
  108. package/dist/core/extensions/builtin/terminal/tools/bash.js +68 -6
  109. package/dist/core/extensions/builtin/terminal/tools/bash.js.map +1 -1
  110. package/dist/core/extensions/builtin/todotools/commands.d.ts +18 -0
  111. package/dist/core/extensions/builtin/todotools/commands.d.ts.map +1 -0
  112. package/dist/core/extensions/builtin/todotools/commands.js +395 -0
  113. package/dist/core/extensions/builtin/todotools/commands.js.map +1 -0
  114. package/dist/core/extensions/builtin/todotools/index.d.ts +4 -1
  115. package/dist/core/extensions/builtin/todotools/index.d.ts.map +1 -1
  116. package/dist/core/extensions/builtin/todotools/index.js +17 -14
  117. package/dist/core/extensions/builtin/todotools/index.js.map +1 -1
  118. package/dist/core/extensions/builtin/todotools/markdown.d.ts +13 -0
  119. package/dist/core/extensions/builtin/todotools/markdown.d.ts.map +1 -0
  120. package/dist/core/extensions/builtin/todotools/markdown.js +82 -0
  121. package/dist/core/extensions/builtin/todotools/markdown.js.map +1 -0
  122. package/dist/core/extensions/builtin/todotools/prompt.d.ts +2 -1
  123. package/dist/core/extensions/builtin/todotools/prompt.d.ts.map +1 -1
  124. package/dist/core/extensions/builtin/todotools/prompt.js +50 -153
  125. package/dist/core/extensions/builtin/todotools/prompt.js.map +1 -1
  126. package/dist/core/extensions/builtin/todotools/state.d.ts +67 -14
  127. package/dist/core/extensions/builtin/todotools/state.d.ts.map +1 -1
  128. package/dist/core/extensions/builtin/todotools/state.js +400 -35
  129. package/dist/core/extensions/builtin/todotools/state.js.map +1 -1
  130. package/dist/core/extensions/builtin/todotools/tools/todo.d.ts +22 -0
  131. package/dist/core/extensions/builtin/todotools/tools/todo.d.ts.map +1 -0
  132. package/dist/core/extensions/builtin/todotools/tools/todo.js +229 -0
  133. package/dist/core/extensions/builtin/todotools/tools/todo.js.map +1 -0
  134. package/dist/core/extensions/builtin/video-in/index.d.ts +3 -0
  135. package/dist/core/extensions/builtin/video-in/index.d.ts.map +1 -0
  136. package/dist/core/extensions/builtin/video-in/index.js +111 -0
  137. package/dist/core/extensions/builtin/video-in/index.js.map +1 -0
  138. package/dist/core/extensions/builtin/websearch/websearch/renderers.d.ts.map +1 -1
  139. package/dist/core/extensions/builtin/websearch/websearch/renderers.js +13 -4
  140. package/dist/core/extensions/builtin/websearch/websearch/renderers.js.map +1 -1
  141. package/dist/core/extensions/builtin/websearch/websearch/search.d.ts +3 -2
  142. package/dist/core/extensions/builtin/websearch/websearch/search.d.ts.map +1 -1
  143. package/dist/core/extensions/builtin/websearch/websearch/search.js +2 -1
  144. package/dist/core/extensions/builtin/websearch/websearch/search.js.map +1 -1
  145. package/dist/core/extensions/builtin/websearch/websearch/tool.d.ts.map +1 -1
  146. package/dist/core/extensions/builtin/websearch/websearch/tool.js +17 -1
  147. package/dist/core/extensions/builtin/websearch/websearch/tool.js.map +1 -1
  148. package/dist/core/extensions/builtin/websearch/websearch/types.d.ts +2 -0
  149. package/dist/core/extensions/builtin/websearch/websearch/types.d.ts.map +1 -1
  150. package/dist/core/extensions/builtin/websearch/websearch/types.js.map +1 -1
  151. package/dist/core/extensions/loader.d.ts +10 -1
  152. package/dist/core/extensions/loader.d.ts.map +1 -1
  153. package/dist/core/extensions/loader.js +44 -3
  154. package/dist/core/extensions/loader.js.map +1 -1
  155. package/dist/core/extensions/runner.d.ts +3 -1
  156. package/dist/core/extensions/runner.d.ts.map +1 -1
  157. package/dist/core/extensions/runner.js +60 -8
  158. package/dist/core/extensions/runner.js.map +1 -1
  159. package/dist/core/extensions/types.d.ts +103 -18
  160. package/dist/core/extensions/types.d.ts.map +1 -1
  161. package/dist/core/extensions/types.js.map +1 -1
  162. package/dist/core/model-registry.d.ts +5 -1
  163. package/dist/core/model-registry.d.ts.map +1 -1
  164. package/dist/core/model-registry.js +17 -2
  165. package/dist/core/model-registry.js.map +1 -1
  166. package/dist/core/model-runtime.d.ts +12 -1
  167. package/dist/core/model-runtime.d.ts.map +1 -1
  168. package/dist/core/model-runtime.js +51 -9
  169. package/dist/core/model-runtime.js.map +1 -1
  170. package/dist/core/prompt-templates.d.ts +1 -0
  171. package/dist/core/prompt-templates.d.ts.map +1 -1
  172. package/dist/core/prompt-templates.js +4 -4
  173. package/dist/core/prompt-templates.js.map +1 -1
  174. package/dist/core/provider-composer.d.ts +1 -1
  175. package/dist/core/provider-composer.d.ts.map +1 -1
  176. package/dist/core/provider-composer.js.map +1 -1
  177. package/dist/core/remote-catalog-provider.d.ts.map +1 -1
  178. package/dist/core/remote-catalog-provider.js +16 -3
  179. package/dist/core/remote-catalog-provider.js.map +1 -1
  180. package/dist/core/resource-loader.d.ts +6 -0
  181. package/dist/core/resource-loader.d.ts.map +1 -1
  182. package/dist/core/resource-loader.js +27 -2
  183. package/dist/core/resource-loader.js.map +1 -1
  184. package/dist/core/retry-fallback/chains.d.ts +29 -0
  185. package/dist/core/retry-fallback/chains.d.ts.map +1 -0
  186. package/dist/core/retry-fallback/chains.js +109 -0
  187. package/dist/core/retry-fallback/chains.js.map +1 -0
  188. package/dist/core/retry-fallback/controller.d.ts +77 -0
  189. package/dist/core/retry-fallback/controller.d.ts.map +1 -0
  190. package/dist/core/retry-fallback/controller.js +157 -0
  191. package/dist/core/retry-fallback/controller.js.map +1 -0
  192. package/dist/core/retry-fallback/cooldown.d.ts +21 -0
  193. package/dist/core/retry-fallback/cooldown.d.ts.map +1 -0
  194. package/dist/core/retry-fallback/cooldown.js +49 -0
  195. package/dist/core/retry-fallback/cooldown.js.map +1 -0
  196. package/dist/core/retry-fallback/log.d.ts +10 -0
  197. package/dist/core/retry-fallback/log.d.ts.map +1 -0
  198. package/dist/core/retry-fallback/log.js +128 -0
  199. package/dist/core/retry-fallback/log.js.map +1 -0
  200. package/dist/core/retry-fallback/validate.d.ts +8 -0
  201. package/dist/core/retry-fallback/validate.d.ts.map +1 -0
  202. package/dist/core/retry-fallback/validate.js +63 -0
  203. package/dist/core/retry-fallback/validate.js.map +1 -0
  204. package/dist/core/sdk.d.ts.map +1 -1
  205. package/dist/core/sdk.js +1 -0
  206. package/dist/core/sdk.js.map +1 -1
  207. package/dist/core/session-manager.d.ts +6 -1
  208. package/dist/core/session-manager.d.ts.map +1 -1
  209. package/dist/core/session-manager.js +19 -3
  210. package/dist/core/session-manager.js.map +1 -1
  211. package/dist/core/settings-manager.d.ts +21 -0
  212. package/dist/core/settings-manager.d.ts.map +1 -1
  213. package/dist/core/settings-manager.js +100 -1
  214. package/dist/core/settings-manager.js.map +1 -1
  215. package/dist/core/tools/bash.d.ts.map +1 -1
  216. package/dist/core/tools/bash.js +20 -5
  217. package/dist/core/tools/bash.js.map +1 -1
  218. package/dist/core/tools/read.js +1 -1
  219. package/dist/core/tools/read.js.map +1 -1
  220. package/dist/extensions/index.d.ts +3 -0
  221. package/dist/extensions/index.d.ts.map +1 -0
  222. package/dist/extensions/index.js +3 -0
  223. package/dist/extensions/index.js.map +1 -0
  224. package/dist/extensions/llama/client.d.ts +61 -0
  225. package/dist/extensions/llama/client.d.ts.map +1 -0
  226. package/dist/extensions/llama/client.js +298 -0
  227. package/dist/extensions/llama/client.js.map +1 -0
  228. package/dist/extensions/llama/huggingface.d.ts +23 -0
  229. package/dist/extensions/llama/huggingface.d.ts.map +1 -0
  230. package/dist/extensions/llama/huggingface.js +139 -0
  231. package/dist/extensions/llama/huggingface.js.map +1 -0
  232. package/dist/extensions/llama/index.d.ts +3 -0
  233. package/dist/extensions/llama/index.d.ts.map +1 -0
  234. package/dist/extensions/llama/index.js +208 -0
  235. package/dist/extensions/llama/index.js.map +1 -0
  236. package/dist/extensions/llama/provider.d.ts +10 -0
  237. package/dist/extensions/llama/provider.d.ts.map +1 -0
  238. package/dist/extensions/llama/provider.js +106 -0
  239. package/dist/extensions/llama/provider.js.map +1 -0
  240. package/dist/extensions/llama/ui.d.ts +42 -0
  241. package/dist/extensions/llama/ui.d.ts.map +1 -0
  242. package/dist/extensions/llama/ui.js +400 -0
  243. package/dist/extensions/llama/ui.js.map +1 -0
  244. package/dist/index.d.ts +1 -1
  245. package/dist/index.d.ts.map +1 -1
  246. package/dist/index.js.map +1 -1
  247. package/dist/main.d.ts.map +1 -1
  248. package/dist/main.js +6 -4
  249. package/dist/main.js.map +1 -1
  250. package/dist/modes/interactive/components/assistant-message.d.ts +6 -7
  251. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  252. package/dist/modes/interactive/components/assistant-message.js +154 -114
  253. package/dist/modes/interactive/components/assistant-message.js.map +1 -1
  254. package/dist/modes/interactive/components/footer.d.ts +2 -1
  255. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  256. package/dist/modes/interactive/components/footer.js +25 -4
  257. package/dist/modes/interactive/components/footer.js.map +1 -1
  258. package/dist/modes/interactive/components/settings-selector.d.ts +4 -0
  259. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  260. package/dist/modes/interactive/components/settings-selector.js +20 -0
  261. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  262. package/dist/modes/interactive/interactive-mode.d.ts +7 -0
  263. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  264. package/dist/modes/interactive/interactive-mode.js +165 -13
  265. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  266. package/dist/modes/interactive/streaming-reveal.d.ts +35 -0
  267. package/dist/modes/interactive/streaming-reveal.d.ts.map +1 -0
  268. package/dist/modes/interactive/streaming-reveal.js +268 -0
  269. package/dist/modes/interactive/streaming-reveal.js.map +1 -0
  270. package/dist/modes/interactive/tool-args-reveal.d.ts +20 -0
  271. package/dist/modes/interactive/tool-args-reveal.d.ts.map +1 -0
  272. package/dist/modes/interactive/tool-args-reveal.js +153 -0
  273. package/dist/modes/interactive/tool-args-reveal.js.map +1 -0
  274. package/dist/utils/child-process.d.ts +17 -1
  275. package/dist/utils/child-process.d.ts.map +1 -1
  276. package/dist/utils/child-process.js +41 -1
  277. package/dist/utils/child-process.js.map +1 -1
  278. package/docs/custom-provider.md +28 -0
  279. package/docs/extensions.md +65 -5
  280. package/docs/index.md +1 -0
  281. package/docs/llama-cpp.md +99 -0
  282. package/docs/neo.md +2 -1
  283. package/docs/prompt-templates.md +1 -0
  284. package/docs/providers.md +7 -0
  285. package/docs/settings.md +35 -0
  286. package/docs/tui.md +41 -26
  287. package/docs/usage.md +1 -0
  288. package/examples/extensions/README.md +1 -1
  289. package/node_modules/@code-yeongyu/senpi-codemode/CHANGELOG.md +26 -0
  290. package/node_modules/@code-yeongyu/senpi-codemode/package.json +3 -3
  291. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/py/prelude.py +0 -1
  292. package/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.d.ts.map +1 -1
  293. package/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.js +76 -8
  294. package/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.js.map +1 -1
  295. package/node_modules/@earendil-works/pi-agent-core/dist/agent.d.ts.map +1 -1
  296. package/node_modules/@earendil-works/pi-agent-core/dist/agent.js +26 -1
  297. package/node_modules/@earendil-works/pi-agent-core/dist/agent.js.map +1 -1
  298. package/node_modules/@earendil-works/pi-agent-core/dist/harness/agent-harness.d.ts.map +1 -1
  299. package/node_modules/@earendil-works/pi-agent-core/dist/harness/agent-harness.js +24 -2
  300. package/node_modules/@earendil-works/pi-agent-core/dist/harness/agent-harness.js.map +1 -1
  301. package/node_modules/@earendil-works/pi-agent-core/dist/types.d.ts +5 -0
  302. package/node_modules/@earendil-works/pi-agent-core/dist/types.d.ts.map +1 -1
  303. package/node_modules/@earendil-works/pi-agent-core/dist/types.js.map +1 -1
  304. package/node_modules/@earendil-works/pi-agent-core/package.json +2 -2
  305. package/node_modules/@earendil-works/pi-ai/README.md +1 -1
  306. package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.d.ts.map +1 -1
  307. package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.js +92 -29
  308. package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.js.map +1 -1
  309. package/node_modules/@earendil-works/pi-ai/dist/api/transform-messages.d.ts.map +1 -1
  310. package/node_modules/@earendil-works/pi-ai/dist/api/transform-messages.js +105 -61
  311. package/node_modules/@earendil-works/pi-ai/dist/api/transform-messages.js.map +1 -1
  312. package/node_modules/@earendil-works/pi-ai/dist/image-models.generated.d.ts +15 -0
  313. package/node_modules/@earendil-works/pi-ai/dist/image-models.generated.d.ts.map +1 -1
  314. package/node_modules/@earendil-works/pi-ai/dist/image-models.generated.js +15 -0
  315. package/node_modules/@earendil-works/pi-ai/dist/image-models.generated.js.map +1 -1
  316. package/node_modules/@earendil-works/pi-ai/dist/index.d.ts +1 -0
  317. package/node_modules/@earendil-works/pi-ai/dist/index.d.ts.map +1 -1
  318. package/node_modules/@earendil-works/pi-ai/dist/index.js +1 -0
  319. package/node_modules/@earendil-works/pi-ai/dist/index.js.map +1 -1
  320. package/node_modules/@earendil-works/pi-ai/dist/models.generated.d.ts +4263 -22324
  321. package/node_modules/@earendil-works/pi-ai/dist/models.generated.d.ts.map +1 -1
  322. package/node_modules/@earendil-works/pi-ai/dist/providers/amazon-bedrock.models.d.ts +436 -1988
  323. package/node_modules/@earendil-works/pi-ai/dist/providers/amazon-bedrock.models.d.ts.map +1 -1
  324. package/node_modules/@earendil-works/pi-ai/dist/providers/amazon-bedrock.models.js +2 -1892
  325. package/node_modules/@earendil-works/pi-ai/dist/providers/amazon-bedrock.models.js.map +1 -1
  326. package/node_modules/@earendil-works/pi-ai/dist/providers/ant-ling.models.d.ts +10 -80
  327. package/node_modules/@earendil-works/pi-ai/dist/providers/ant-ling.models.d.ts.map +1 -1
  328. package/node_modules/@earendil-works/pi-ai/dist/providers/ant-ling.models.js +2 -57
  329. package/node_modules/@earendil-works/pi-ai/dist/providers/ant-ling.models.js.map +1 -1
  330. package/node_modules/@earendil-works/pi-ai/dist/providers/anthropic.models.d.ts +43 -267
  331. package/node_modules/@earendil-works/pi-ai/dist/providers/anthropic.models.d.ts.map +1 -1
  332. package/node_modules/@earendil-works/pi-ai/dist/providers/anthropic.models.js +2 -252
  333. package/node_modules/@earendil-works/pi-ai/dist/providers/anthropic.models.js.map +1 -1
  334. package/node_modules/@earendil-works/pi-ai/dist/providers/azure-openai-responses.models.d.ts +184 -883
  335. package/node_modules/@earendil-works/pi-ai/dist/providers/azure-openai-responses.models.d.ts.map +1 -1
  336. package/node_modules/@earendil-works/pi-ai/dist/providers/azure-openai-responses.models.js +2 -811
  337. package/node_modules/@earendil-works/pi-ai/dist/providers/azure-openai-responses.models.js.map +1 -1
  338. package/node_modules/@earendil-works/pi-ai/dist/providers/cerebras.models.d.ts +10 -60
  339. package/node_modules/@earendil-works/pi-ai/dist/providers/cerebras.models.d.ts.map +1 -1
  340. package/node_modules/@earendil-works/pi-ai/dist/providers/cerebras.models.js +2 -56
  341. package/node_modules/@earendil-works/pi-ai/dist/providers/cerebras.models.js.map +1 -1
  342. package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-ai-gateway.models.d.ts +168 -884
  343. package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-ai-gateway.models.d.ts.map +1 -1
  344. package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-ai-gateway.models.js +2 -755
  345. package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-ai-gateway.models.js.map +1 -1
  346. package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-workers-ai.models.d.ts +40 -286
  347. package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-workers-ai.models.d.ts.map +1 -1
  348. package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-workers-ai.models.js +2 -236
  349. package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-workers-ai.models.js.map +1 -1
  350. package/node_modules/@earendil-works/pi-ai/dist/providers/data/amazon-bedrock.json +1 -0
  351. package/node_modules/@earendil-works/pi-ai/dist/providers/data/ant-ling.json +1 -0
  352. package/node_modules/@earendil-works/pi-ai/dist/providers/data/anthropic.json +1 -0
  353. package/node_modules/@earendil-works/pi-ai/dist/providers/data/azure-openai-responses.json +1 -0
  354. package/node_modules/@earendil-works/pi-ai/dist/providers/data/cerebras.json +1 -0
  355. package/node_modules/@earendil-works/pi-ai/dist/providers/data/cloudflare-ai-gateway.json +1 -0
  356. package/node_modules/@earendil-works/pi-ai/dist/providers/data/cloudflare-workers-ai.json +1 -0
  357. package/node_modules/@earendil-works/pi-ai/dist/providers/data/deepseek.json +1 -0
  358. package/node_modules/@earendil-works/pi-ai/dist/providers/data/fireworks.json +1 -0
  359. package/node_modules/@earendil-works/pi-ai/dist/providers/data/github-copilot.json +1 -0
  360. package/node_modules/@earendil-works/pi-ai/dist/providers/data/google-vertex.json +1 -0
  361. package/node_modules/@earendil-works/pi-ai/dist/providers/data/google.json +1 -0
  362. package/node_modules/@earendil-works/pi-ai/dist/providers/data/groq.json +1 -0
  363. package/node_modules/@earendil-works/pi-ai/dist/providers/data/huggingface.json +1 -0
  364. package/node_modules/@earendil-works/pi-ai/dist/providers/data/kimi-coding.json +1 -0
  365. package/node_modules/@earendil-works/pi-ai/dist/providers/data/minimax-cn.json +1 -0
  366. package/node_modules/@earendil-works/pi-ai/dist/providers/data/minimax.json +1 -0
  367. package/node_modules/@earendil-works/pi-ai/dist/providers/data/mistral.json +1 -0
  368. package/node_modules/@earendil-works/pi-ai/dist/providers/data/moonshotai-cn.json +1 -0
  369. package/node_modules/@earendil-works/pi-ai/dist/providers/data/moonshotai.json +1 -0
  370. package/node_modules/@earendil-works/pi-ai/dist/providers/data/nvidia.json +1 -0
  371. package/node_modules/@earendil-works/pi-ai/dist/providers/data/openai-codex.json +1 -0
  372. package/node_modules/@earendil-works/pi-ai/dist/providers/data/openai.json +1 -0
  373. package/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode-go.json +1 -0
  374. package/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode.json +1 -0
  375. package/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -0
  376. package/node_modules/@earendil-works/pi-ai/dist/providers/data/together.json +1 -0
  377. package/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.json +1 -0
  378. package/node_modules/@earendil-works/pi-ai/dist/providers/data/xai.json +1 -0
  379. package/node_modules/@earendil-works/pi-ai/dist/providers/data/xiaomi-token-plan-ams.json +1 -0
  380. package/node_modules/@earendil-works/pi-ai/dist/providers/data/xiaomi-token-plan-cn.json +1 -0
  381. package/node_modules/@earendil-works/pi-ai/dist/providers/data/xiaomi-token-plan-sgp.json +1 -0
  382. package/node_modules/@earendil-works/pi-ai/dist/providers/data/xiaomi.json +1 -0
  383. package/node_modules/@earendil-works/pi-ai/dist/providers/data/zai-coding-cn.json +1 -0
  384. package/node_modules/@earendil-works/pi-ai/dist/providers/data/zai.json +1 -0
  385. package/node_modules/@earendil-works/pi-ai/dist/providers/deepseek.models.d.ts +7 -58
  386. package/node_modules/@earendil-works/pi-ai/dist/providers/deepseek.models.d.ts.map +1 -1
  387. package/node_modules/@earendil-works/pi-ai/dist/providers/deepseek.models.js +2 -40
  388. package/node_modules/@earendil-works/pi-ai/dist/providers/deepseek.models.js.map +1 -1
  389. package/node_modules/@earendil-works/pi-ai/dist/providers/faux.d.ts +1 -0
  390. package/node_modules/@earendil-works/pi-ai/dist/providers/faux.d.ts.map +1 -1
  391. package/node_modules/@earendil-works/pi-ai/dist/providers/faux.js +1 -0
  392. package/node_modules/@earendil-works/pi-ai/dist/providers/faux.js.map +1 -1
  393. package/node_modules/@earendil-works/pi-ai/dist/providers/fireworks.models.d.ts +49 -362
  394. package/node_modules/@earendil-works/pi-ai/dist/providers/fireworks.models.d.ts.map +1 -1
  395. package/node_modules/@earendil-works/pi-ai/dist/providers/fireworks.models.js +2 -292
  396. package/node_modules/@earendil-works/pi-ai/dist/providers/fireworks.models.js.map +1 -1
  397. package/node_modules/@earendil-works/pi-ai/dist/providers/github-copilot.models.d.ts +85 -760
  398. package/node_modules/@earendil-works/pi-ai/dist/providers/github-copilot.models.d.ts.map +1 -1
  399. package/node_modules/@earendil-works/pi-ai/dist/providers/github-copilot.models.js +2 -538
  400. package/node_modules/@earendil-works/pi-ai/dist/providers/github-copilot.models.js.map +1 -1
  401. package/node_modules/@earendil-works/pi-ai/dist/providers/google-vertex.models.d.ts +31 -189
  402. package/node_modules/@earendil-works/pi-ai/dist/providers/google-vertex.models.d.ts.map +1 -1
  403. package/node_modules/@earendil-works/pi-ai/dist/providers/google-vertex.models.js +2 -179
  404. package/node_modules/@earendil-works/pi-ai/dist/providers/google-vertex.models.js.map +1 -1
  405. package/node_modules/@earendil-works/pi-ai/dist/providers/google.models.d.ts +49 -309
  406. package/node_modules/@earendil-works/pi-ai/dist/providers/google.models.d.ts.map +1 -1
  407. package/node_modules/@earendil-works/pi-ai/dist/providers/google.models.js +2 -285
  408. package/node_modules/@earendil-works/pi-ai/dist/providers/google.models.js.map +1 -1
  409. package/node_modules/@earendil-works/pi-ai/dist/providers/groq.models.d.ts +22 -118
  410. package/node_modules/@earendil-works/pi-ai/dist/providers/groq.models.d.ts.map +1 -1
  411. package/node_modules/@earendil-works/pi-ai/dist/providers/groq.models.js +2 -122
  412. package/node_modules/@earendil-works/pi-ai/dist/providers/groq.models.js.map +1 -1
  413. package/node_modules/@earendil-works/pi-ai/dist/providers/huggingface.models.d.ts +196 -979
  414. package/node_modules/@earendil-works/pi-ai/dist/providers/huggingface.models.d.ts.map +1 -1
  415. package/node_modules/@earendil-works/pi-ai/dist/providers/huggingface.models.js +2 -884
  416. package/node_modules/@earendil-works/pi-ai/dist/providers/huggingface.models.js.map +1 -1
  417. package/node_modules/@earendil-works/pi-ai/dist/providers/kimi-coding.models.d.ts +13 -122
  418. package/node_modules/@earendil-works/pi-ai/dist/providers/kimi-coding.models.d.ts.map +1 -1
  419. package/node_modules/@earendil-works/pi-ai/dist/providers/kimi-coding.models.js +2 -98
  420. package/node_modules/@earendil-works/pi-ai/dist/providers/kimi-coding.models.js.map +1 -1
  421. package/node_modules/@earendil-works/pi-ai/dist/providers/minimax-cn.models.d.ts +10 -48
  422. package/node_modules/@earendil-works/pi-ai/dist/providers/minimax-cn.models.d.ts.map +1 -1
  423. package/node_modules/@earendil-works/pi-ai/dist/providers/minimax-cn.models.js +2 -53
  424. package/node_modules/@earendil-works/pi-ai/dist/providers/minimax-cn.models.js.map +1 -1
  425. package/node_modules/@earendil-works/pi-ai/dist/providers/minimax.models.d.ts +10 -48
  426. package/node_modules/@earendil-works/pi-ai/dist/providers/minimax.models.d.ts.map +1 -1
  427. package/node_modules/@earendil-works/pi-ai/dist/providers/minimax.models.js +2 -53
  428. package/node_modules/@earendil-works/pi-ai/dist/providers/minimax.models.js.map +1 -1
  429. package/node_modules/@earendil-works/pi-ai/dist/providers/mistral.models.d.ts +91 -480
  430. package/node_modules/@earendil-works/pi-ai/dist/providers/mistral.models.d.ts.map +1 -1
  431. package/node_modules/@earendil-works/pi-ai/dist/providers/mistral.models.js +2 -512
  432. package/node_modules/@earendil-works/pi-ai/dist/providers/mistral.models.js.map +1 -1
  433. package/node_modules/@earendil-works/pi-ai/dist/providers/moonshotai-cn.models.d.ts +31 -257
  434. package/node_modules/@earendil-works/pi-ai/dist/providers/moonshotai-cn.models.d.ts.map +1 -1
  435. package/node_modules/@earendil-works/pi-ai/dist/providers/moonshotai-cn.models.js +2 -185
  436. package/node_modules/@earendil-works/pi-ai/dist/providers/moonshotai-cn.models.js.map +1 -1
  437. package/node_modules/@earendil-works/pi-ai/dist/providers/moonshotai.models.d.ts +31 -257
  438. package/node_modules/@earendil-works/pi-ai/dist/providers/moonshotai.models.d.ts.map +1 -1
  439. package/node_modules/@earendil-works/pi-ai/dist/providers/moonshotai.models.js +2 -185
  440. package/node_modules/@earendil-works/pi-ai/dist/providers/moonshotai.models.js.map +1 -1
  441. package/node_modules/@earendil-works/pi-ai/dist/providers/nvidia.models.d.ts +58 -541
  442. package/node_modules/@earendil-works/pi-ai/dist/providers/nvidia.models.d.ts.map +1 -1
  443. package/node_modules/@earendil-works/pi-ai/dist/providers/nvidia.models.js +2 -382
  444. package/node_modules/@earendil-works/pi-ai/dist/providers/nvidia.models.js.map +1 -1
  445. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-codex.models.d.ts +22 -196
  446. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-codex.models.d.ts.map +1 -1
  447. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-codex.models.js +2 -139
  448. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-codex.models.js.map +1 -1
  449. package/node_modules/@earendil-works/pi-ai/dist/providers/openai.models.d.ts +184 -954
  450. package/node_modules/@earendil-works/pi-ai/dist/providers/openai.models.d.ts.map +1 -1
  451. package/node_modules/@earendil-works/pi-ai/dist/providers/openai.models.js +2 -825
  452. package/node_modules/@earendil-works/pi-ai/dist/providers/openai.models.js.map +1 -1
  453. package/node_modules/@earendil-works/pi-ai/dist/providers/opencode-go.d.ts +1 -1
  454. package/node_modules/@earendil-works/pi-ai/dist/providers/opencode-go.d.ts.map +1 -1
  455. package/node_modules/@earendil-works/pi-ai/dist/providers/opencode-go.js +2 -0
  456. package/node_modules/@earendil-works/pi-ai/dist/providers/opencode-go.js.map +1 -1
  457. package/node_modules/@earendil-works/pi-ai/dist/providers/opencode-go.models.d.ts +46 -335
  458. package/node_modules/@earendil-works/pi-ai/dist/providers/opencode-go.models.d.ts.map +1 -1
  459. package/node_modules/@earendil-works/pi-ai/dist/providers/opencode-go.models.js +2 -273
  460. package/node_modules/@earendil-works/pi-ai/dist/providers/opencode-go.models.js.map +1 -1
  461. package/node_modules/@earendil-works/pi-ai/dist/providers/opencode.models.d.ts +163 -1185
  462. package/node_modules/@earendil-works/pi-ai/dist/providers/opencode.models.d.ts.map +1 -1
  463. package/node_modules/@earendil-works/pi-ai/dist/providers/opencode.models.js +2 -996
  464. package/node_modules/@earendil-works/pi-ai/dist/providers/opencode.models.js.map +1 -1
  465. package/node_modules/@earendil-works/pi-ai/dist/providers/openrouter.models.d.ts +1076 -5729
  466. package/node_modules/@earendil-works/pi-ai/dist/providers/openrouter.models.d.ts.map +1 -1
  467. package/node_modules/@earendil-works/pi-ai/dist/providers/openrouter.models.js +2 -4892
  468. package/node_modules/@earendil-works/pi-ai/dist/providers/openrouter.models.js.map +1 -1
  469. package/node_modules/@earendil-works/pi-ai/dist/providers/together.models.d.ts +49 -610
  470. package/node_modules/@earendil-works/pi-ai/dist/providers/together.models.d.ts.map +1 -1
  471. package/node_modules/@earendil-works/pi-ai/dist/providers/together.models.js +2 -396
  472. package/node_modules/@earendil-works/pi-ai/dist/providers/together.models.js.map +1 -1
  473. package/node_modules/@earendil-works/pi-ai/dist/providers/vercel-ai-gateway.models.d.ts +752 -3336
  474. package/node_modules/@earendil-works/pi-ai/dist/providers/vercel-ai-gateway.models.d.ts.map +1 -1
  475. package/node_modules/@earendil-works/pi-ai/dist/providers/vercel-ai-gateway.models.js +2 -3263
  476. package/node_modules/@earendil-works/pi-ai/dist/providers/vercel-ai-gateway.models.js.map +1 -1
  477. package/node_modules/@earendil-works/pi-ai/dist/providers/xai.models.d.ts +10 -65
  478. package/node_modules/@earendil-works/pi-ai/dist/providers/xai.models.d.ts.map +1 -1
  479. package/node_modules/@earendil-works/pi-ai/dist/providers/xai.models.js +2 -57
  480. package/node_modules/@earendil-works/pi-ai/dist/providers/xai.models.js.map +1 -1
  481. package/node_modules/@earendil-works/pi-ai/dist/providers/xiaomi-token-plan-ams.models.d.ts +10 -63
  482. package/node_modules/@earendil-works/pi-ai/dist/providers/xiaomi-token-plan-ams.models.d.ts.map +1 -1
  483. package/node_modules/@earendil-works/pi-ai/dist/providers/xiaomi-token-plan-ams.models.js +2 -56
  484. package/node_modules/@earendil-works/pi-ai/dist/providers/xiaomi-token-plan-ams.models.js.map +1 -1
  485. package/node_modules/@earendil-works/pi-ai/dist/providers/xiaomi-token-plan-cn.models.d.ts +10 -63
  486. package/node_modules/@earendil-works/pi-ai/dist/providers/xiaomi-token-plan-cn.models.d.ts.map +1 -1
  487. package/node_modules/@earendil-works/pi-ai/dist/providers/xiaomi-token-plan-cn.models.js +2 -56
  488. package/node_modules/@earendil-works/pi-ai/dist/providers/xiaomi-token-plan-cn.models.js.map +1 -1
  489. package/node_modules/@earendil-works/pi-ai/dist/providers/xiaomi-token-plan-sgp.models.d.ts +10 -63
  490. package/node_modules/@earendil-works/pi-ai/dist/providers/xiaomi-token-plan-sgp.models.d.ts.map +1 -1
  491. package/node_modules/@earendil-works/pi-ai/dist/providers/xiaomi-token-plan-sgp.models.js +2 -56
  492. package/node_modules/@earendil-works/pi-ai/dist/providers/xiaomi-token-plan-sgp.models.js.map +1 -1
  493. package/node_modules/@earendil-works/pi-ai/dist/providers/xiaomi.models.d.ts +19 -126
  494. package/node_modules/@earendil-works/pi-ai/dist/providers/xiaomi.models.d.ts.map +1 -1
  495. package/node_modules/@earendil-works/pi-ai/dist/providers/xiaomi.models.js +2 -110
  496. package/node_modules/@earendil-works/pi-ai/dist/providers/xiaomi.models.js.map +1 -1
  497. package/node_modules/@earendil-works/pi-ai/dist/providers/zai-coding-cn.models.d.ts +19 -144
  498. package/node_modules/@earendil-works/pi-ai/dist/providers/zai-coding-cn.models.d.ts.map +1 -1
  499. package/node_modules/@earendil-works/pi-ai/dist/providers/zai-coding-cn.models.js +2 -111
  500. package/node_modules/@earendil-works/pi-ai/dist/providers/zai-coding-cn.models.js.map +1 -1
  501. package/node_modules/@earendil-works/pi-ai/dist/providers/zai.models.d.ts +19 -144
  502. package/node_modules/@earendil-works/pi-ai/dist/providers/zai.models.d.ts.map +1 -1
  503. package/node_modules/@earendil-works/pi-ai/dist/providers/zai.models.js +2 -111
  504. package/node_modules/@earendil-works/pi-ai/dist/providers/zai.models.js.map +1 -1
  505. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/context-transformer.d.ts.map +1 -1
  506. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/context-transformer.js +9 -0
  507. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/context-transformer.js.map +1 -1
  508. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/index.d.ts.map +1 -1
  509. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/index.js +2 -1
  510. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/index.js.map +1 -1
  511. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/coerce-parameters.d.ts +1 -0
  512. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/coerce-parameters.d.ts.map +1 -1
  513. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/coerce-parameters.js +1 -1
  514. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/coerce-parameters.js.map +1 -1
  515. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/format.d.ts +1 -0
  516. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/format.d.ts.map +1 -1
  517. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/format.js +1 -1
  518. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/format.js.map +1 -1
  519. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/invoke-protocol.d.ts +19 -0
  520. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/invoke-protocol.d.ts.map +1 -0
  521. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/invoke-protocol.js +8 -0
  522. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/invoke-protocol.js.map +1 -0
  523. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/parse.d.ts +2 -0
  524. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/parse.d.ts.map +1 -1
  525. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/parse.js +7 -4
  526. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/parse.js.map +1 -1
  527. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/stream.d.ts +2 -0
  528. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/stream.d.ts.map +1 -1
  529. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/stream.js +22 -18
  530. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/stream.js.map +1 -1
  531. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/antml/coerce-parameters.d.ts +15 -0
  532. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/antml/coerce-parameters.d.ts.map +1 -0
  533. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/antml/coerce-parameters.js +198 -0
  534. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/antml/coerce-parameters.js.map +1 -0
  535. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/antml/config.d.ts +3 -0
  536. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/antml/config.d.ts.map +1 -0
  537. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/antml/config.js +8 -0
  538. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/antml/config.js.map +1 -0
  539. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/antml/format.d.ts +6 -0
  540. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/antml/format.d.ts.map +1 -0
  541. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/antml/format.js +33 -0
  542. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/antml/format.js.map +1 -0
  543. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/antml/index.d.ts +6 -0
  544. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/antml/index.d.ts.map +1 -0
  545. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/antml/index.js +6 -0
  546. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/antml/index.js.map +1 -0
  547. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/antml/parse.d.ts +4 -0
  548. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/antml/parse.d.ts.map +1 -0
  549. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/antml/parse.js +6 -0
  550. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/antml/parse.js.map +1 -0
  551. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/antml/repair.d.ts +12 -0
  552. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/antml/repair.d.ts.map +1 -0
  553. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/antml/repair.js +46 -0
  554. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/antml/repair.js.map +1 -0
  555. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/antml/stream.d.ts +4 -0
  556. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/antml/stream.d.ts.map +1 -0
  557. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/antml/stream.js +6 -0
  558. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/antml/stream.js.map +1 -0
  559. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/types.d.ts +2 -1
  560. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/types.d.ts.map +1 -1
  561. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/types.js.map +1 -1
  562. package/node_modules/@earendil-works/pi-ai/dist/types.d.ts +19 -2
  563. package/node_modules/@earendil-works/pi-ai/dist/types.d.ts.map +1 -1
  564. package/node_modules/@earendil-works/pi-ai/dist/types.js +4 -1
  565. package/node_modules/@earendil-works/pi-ai/dist/types.js.map +1 -1
  566. package/node_modules/@earendil-works/pi-ai/dist/utils/retry.d.ts.map +1 -1
  567. package/node_modules/@earendil-works/pi-ai/dist/utils/retry.js +6 -1
  568. package/node_modules/@earendil-works/pi-ai/dist/utils/retry.js.map +1 -1
  569. package/node_modules/@earendil-works/pi-ai/dist/utils/stop-details.d.ts +4 -0
  570. package/node_modules/@earendil-works/pi-ai/dist/utils/stop-details.d.ts.map +1 -0
  571. package/node_modules/@earendil-works/pi-ai/dist/utils/stop-details.js +6 -0
  572. package/node_modules/@earendil-works/pi-ai/dist/utils/stop-details.js.map +1 -0
  573. package/node_modules/@earendil-works/pi-ai/package.json +2 -2
  574. package/node_modules/@earendil-works/pi-pty/dist/registry-session.d.ts +1 -1
  575. package/node_modules/@earendil-works/pi-pty/dist/registry-session.d.ts.map +1 -1
  576. package/node_modules/@earendil-works/pi-pty/dist/registry-session.js +25 -6
  577. package/node_modules/@earendil-works/pi-pty/dist/registry-session.js.map +1 -1
  578. package/node_modules/@earendil-works/pi-pty/dist/registry-types.d.ts +6 -0
  579. package/node_modules/@earendil-works/pi-pty/dist/registry-types.d.ts.map +1 -1
  580. package/node_modules/@earendil-works/pi-pty/dist/registry-types.js.map +1 -1
  581. package/node_modules/@earendil-works/pi-pty/dist/registry.d.ts +1 -0
  582. package/node_modules/@earendil-works/pi-pty/dist/registry.d.ts.map +1 -1
  583. package/node_modules/@earendil-works/pi-pty/dist/registry.js +9 -1
  584. package/node_modules/@earendil-works/pi-pty/dist/registry.js.map +1 -1
  585. package/node_modules/@earendil-works/pi-pty/package.json +1 -1
  586. package/node_modules/@earendil-works/pi-tui/dist/index.d.ts +1 -1
  587. package/node_modules/@earendil-works/pi-tui/dist/index.d.ts.map +1 -1
  588. package/node_modules/@earendil-works/pi-tui/dist/index.js +1 -1
  589. package/node_modules/@earendil-works/pi-tui/dist/index.js.map +1 -1
  590. package/node_modules/@earendil-works/pi-tui/dist/tui.d.ts +6 -1
  591. package/node_modules/@earendil-works/pi-tui/dist/tui.d.ts.map +1 -1
  592. package/node_modules/@earendil-works/pi-tui/dist/tui.js +14 -2
  593. package/node_modules/@earendil-works/pi-tui/dist/tui.js.map +1 -1
  594. package/node_modules/@earendil-works/pi-tui/dist/utils.js +1 -1
  595. package/node_modules/@earendil-works/pi-tui/dist/utils.js.map +1 -1
  596. package/node_modules/@earendil-works/pi-tui/package.json +1 -1
  597. package/package.json +6 -6
  598. package/dist/core/extensions/builtin/todotools/tools/todoread.d.ts +0 -4
  599. package/dist/core/extensions/builtin/todotools/tools/todoread.d.ts.map +0 -1
  600. package/dist/core/extensions/builtin/todotools/tools/todoread.js +0 -37
  601. package/dist/core/extensions/builtin/todotools/tools/todoread.js.map +0 -1
  602. package/dist/core/extensions/builtin/todotools/tools/todowrite.d.ts +0 -10
  603. package/dist/core/extensions/builtin/todotools/tools/todowrite.d.ts.map +0 -1
  604. package/dist/core/extensions/builtin/todotools/tools/todowrite.js +0 -95
  605. package/dist/core/extensions/builtin/todotools/tools/todowrite.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"todo-bridge.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/compaction/todo-bridge.ts"],"names":[],"mappings":"AAGA,MAAM,yBAAyB,GAAG,0BAA0B,CAAC;AAC7D,MAAM,oBAAoB,GAAG,mCAAmC,CAAC;AA+BjE,SAAS,iBAAiB,CAAC,KAAmB;IAC7C,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,UAAU,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;AAC5E,CAAC;AAED,SAAS,qBAAqB,CAAC,KAAmB;IACjD,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,UAAU,KAAK,WAAW,CAAC;AACpE,CAAC;AAED,SAAS,kBAAkB,CAAC,KAAkB;IAC7C,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC;IACxB,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI,IAAI,CAAC,CAAC,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QACnG,OAAO,EAAE,CAAC;IACX,CAAC;IACD,OAAO,IAAI,CAAC,KAAK,CAAC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AG,YAAiC,CAAC;IAC7C,MAAM,GAAG,GAAG,iBAAqC,CAAC;IAClD,IAAI,eAAe,CAAC,GAAG,CAAC,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO;IAE5C,MAAM,QAAQ,GAAG,sBAAsB,CAAC,GAAG,CAAC,CAAC;IAC7C,IAAI,CAAC,QAAQ,IAAI,QAAQ,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO;IAErD,EAAE,CAAC,WAAW,CACb;QACC,UAAU,EAAE,iCAAiC;QAC7C,OAAO,EAAE,kDAAkD,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;QAC3F,OAAO,EAAE,KAAK;QACd,OAAO,EAAE,QAAQ;KACjB,EACD,EAAE,WAAW,EAAE,IAAI,EAAE,SAAS,EAAE,UAAU,EAAE,CAC5C,CAAC;AACH,CAAC","sourcesContent":["import type { CustomEntry, SessionEntry } from \"../../../session-manager.ts\";\nimport type { ExtensionAPI, ExtensionContext } from \"../../types.ts\";\n\nconst TODO_SNAPSHOT_CUSTOM_TYPE = \"compaction.todo-snapshot\";\nconst TODO_SNAPSHOT_SCHEMA = \"senpi.compaction.todo-snapshot.v1\";\n\nexport interface TodoEntry {\n\tid: string;\n\tcontent?: string;\n\ttext?: string;\n\tstatus?: \"pending\" | \"in_progress\" | \"completed\" | \"cancelled\";\n}\n\nexport interface TodoSnapshotPayload {\n\tschema: typeof TODO_SNAPSHOT_SCHEMA;\n\ttodos: TodoEntry[] | SessionEntry[];\n\tcapturedAt: number;\n}\n\ninterface AppendEntryTarget {\n\tappendEntry<T = unknown>(customType: string, data?: T): void;\n}\n\ninterface SendMessageTarget extends AppendEntryTarget {\n\tsendMessage<T = unknown>(\n\t\tmessage: { customType: string; content: string; display: boolean; details?: T },\n\t\toptions?: { triggerTurn?: boolean; deliverAs?: \"steer\" | \"followUp\" | \"nextTurn\" },\n\t): void;\n}\n\ninterface RestoreResult {\n\tapplied: boolean;\n\trestoredTodos: TodoEntry[];\n}\n\nfunction isCustomTodoEntry(entry: SessionEntry): entry is CustomEntry {\n\treturn entry.type === \"custom\" && entry.customType.startsWith(\"todowrite\");\n}\n\nfunction isLegacyTodoListEntry(entry: SessionEntry): entry is CustomEntry {\n\treturn entry.type === \"custom\" && entry.customType === \"todo-list\";\n}\n\nfunction readTodosFromEntry(entry: CustomEntry): TodoEntry[] {\n\tconst data = entry.data;\n\tif (typeof data !== \"object\" || data === null || !(\"todos\" in data) || !Array.isArray(data.todos)) {\n\t\treturn [];\n\t}\n\treturn data.todos.filter((todo): todo is TodoEntry => {\n\t\treturn typeof todo === \"object\" && todo !== null && \"id\" in todo && typeof todo.id === \"string\";\n\t});\n}\n\nfunction findLatestTodoSnapshot(ctx: ExtensionContext): TodoSnapshotPayload | null {\n\tconst entries = ctx.sessionManager.getEntries();\n\tfor (let index = entries.length - 1; index >= 0; index--) {\n\t\tconst entry = entries[index];\n\t\tif (entry.type !== \"custom\" || entry.customType !== TODO_SNAPSHOT_CUSTOM_TYPE) continue;\n\t\tconst data = entry.data;\n\t\tif (typeof data === \"object\" && data !== null && \"schema\" in data && data.schema === TODO_SNAPSHOT_SCHEMA) {\n\t\t\treturn data as TodoSnapshotPayload;\n\t\t}\n\t}\n\treturn null;\n}\n\nexport function findTodoEntries(ctx: ExtensionContext): SessionEntry[];\nexport function findTodoEntries(entries: SessionEntry[], options?: { branchId?: string }): TodoEntry[];\nexport function findTodoEntries(\n\tctxOrEntries: ExtensionContext | SessionEntry[],\n\toptions?: { branchId?: string },\n): SessionEntry[] | TodoEntry[] {\n\tif (Array.isArray(ctxOrEntries)) {\n\t\treturn ctxOrEntries\n\t\t\t.filter(isLegacyTodoListEntry)\n\t\t\t.filter((entry) => options?.branchId === undefined || entry.parentId === options.branchId)\n\t\t\t.flatMap(readTodosFromEntry);\n\t}\n\n\treturn ctxOrEntries.sessionManager.getEntries().filter(isCustomTodoEntry);\n}\n\nexport function createTodoSnapshot(ctx: ExtensionContext): TodoSnapshotPayload {\n\treturn {\n\t\tschema: TODO_SNAPSHOT_SCHEMA,\n\t\ttodos: findTodoEntries(ctx),\n\t\tcapturedAt: Date.now(),\n\t};\n}\n\nexport function persistTodoSnapshot(pi: AppendEntryTarget, snapshot: TodoSnapshotPayload): void {\n\tpi.appendEntry(TODO_SNAPSHOT_CUSTOM_TYPE, snapshot);\n}\n\nexport function captureTodoSnapshot(pi: ExtensionAPI, ctx: ExtensionContext): void;\nexport function captureTodoSnapshot(currentTodos: TodoEntry[], pi: AppendEntryTarget, branchId?: string): void;\nexport function captureTodoSnapshot(\n\tpiOrTodos: ExtensionAPI | TodoEntry[],\n\tctxOrPi: ExtensionContext | AppendEntryTarget,\n\t_branchId?: string,\n): void {\n\tif (Array.isArray(piOrTodos)) {\n\t\tconst pi = ctxOrPi as AppendEntryTarget;\n\t\tpersistTodoSnapshot(pi, {\n\t\t\tschema: TODO_SNAPSHOT_SCHEMA,\n\t\t\ttodos: piOrTodos,\n\t\t\tcapturedAt: Date.now(),\n\t\t});\n\t\treturn;\n\t}\n\n\tpersistTodoSnapshot(piOrTodos, createTodoSnapshot(ctxOrPi as ExtensionContext));\n}\n\nexport function restoreTodosIfMissing(pi: ExtensionAPI, ctx: ExtensionContext): void;\nexport function restoreTodosIfMissing(\n\tsnapshot: TodoEntry[],\n\tcurrentTodos: TodoEntry[],\n\tpi: AppendEntryTarget,\n): RestoreResult;\nexport function restoreTodosIfMissing(\n\tpiOrSnapshot: ExtensionAPI | TodoEntry[],\n\tctxOrCurrentTodos: ExtensionContext | TodoEntry[],\n\t_pi?: AppendEntryTarget,\n): undefined | RestoreResult {\n\tif (Array.isArray(piOrSnapshot) && Array.isArray(ctxOrCurrentTodos)) {\n\t\tif (ctxOrCurrentTodos.length > 0) {\n\t\t\treturn { applied: false, restoredTodos: ctxOrCurrentTodos };\n\t\t}\n\t\treturn { applied: piOrSnapshot.length > 0, restoredTodos: piOrSnapshot };\n\t}\n\n\tconst pi = piOrSnapshot as SendMessageTarget;\n\tconst ctx = ctxOrCurrentTodos as ExtensionContext;\n\tif (findTodoEntries(ctx).length > 0) return;\n\n\tconst snapshot = findLatestTodoSnapshot(ctx);\n\tif (!snapshot || snapshot.todos.length === 0) return;\n\n\tpi.sendMessage(\n\t\t{\n\t\t\tcustomType: \"compaction.todo-restore-request\",\n\t\t\tcontent: `Restore missing todowrite todos from snapshot: ${JSON.stringify(snapshot.todos)}`,\n\t\t\tdisplay: false,\n\t\t\tdetails: snapshot,\n\t\t},\n\t\t{ triggerTurn: true, deliverAs: \"nextTurn\" },\n\t);\n}\n"]}
1
+ {"version":3,"file":"todo-bridge.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/compaction/todo-bridge.ts"],"names":[],"mappings":"AAIA,MAAM,yBAAyB,GAAG,0BAA0B,CAAC;AAC7D,MAAM,oBAAoB,GAAG,mCAAmC,CAAC;AACjE,MAAM,qBAAqB,GAAG,kBAAkB,CAAC;AAiCjD,SAAS,QAAQ,CAAC,KAAc;IAC/B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC;AACpD,CAAC;AAED,SAAS,YAAY,CAAC,KAAc;IACnC,8EAA8E;IAC9E,2EAA2E;IAC3E,0EAA0E;IAC1E,OAAO,KAAK,KAAK,SAAS,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAC;AACzD,CAAC;AAED,SAAS,WAAW,CAAC,KAAc;IAClC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACnC,MAAM,KAAK,GAAG,OAAO,KAAK,CAAC,EAAE,KAAK,QAAQ,CAAC;IAC3C,MAAM,UAAU,GAAG,OAAO,KAAK,CAAC,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,CAAC;IACvF,OAAO,CAAC,KAAK,IAAI,UAAU,CAAC,IAAI,YAAY,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;AAC5D,CAAC;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AI,CAAC,QAAQ,IAAI,QAAQ,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO;IAErD,EAAE,CAAC,WAAW,CACb;QACC,UAAU,EAAE,iCAAiC;QAC7C,OAAO,EAAE,6CAA6C,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;QACtF,OAAO,EAAE,KAAK;QACd,OAAO,EAAE,QAAQ;KACjB,EACD,EAAE,WAAW,EAAE,IAAI,EAAE,SAAS,EAAE,UAAU,EAAE,CAC5C,CAAC;AACH,CAAC","sourcesContent":["import type { CustomEntry, SessionEntry } from \"../../../session-manager.ts\";\nimport type { ExtensionAPI, ExtensionContext } from \"../../types.ts\";\nimport type { TodoPhase } from \"../todotools/state.ts\";\n\nconst TODO_SNAPSHOT_CUSTOM_TYPE = \"compaction.todo-snapshot\";\nconst TODO_SNAPSHOT_SCHEMA = \"senpi.compaction.todo-snapshot.v1\";\nconst TODO_STATE_ENTRY_TYPE = \"senpi.todo-state\";\n\nexport interface TodoEntry {\n\tid?: string;\n\tcontent?: string;\n\ttext?: string;\n\tstatus?: string;\n}\n\nexport type TodoSnapshotItems = TodoEntry[] | TodoPhase[];\n\nexport interface TodoSnapshotPayload {\n\tschema: typeof TODO_SNAPSHOT_SCHEMA;\n\ttodos: TodoSnapshotItems | SessionEntry[];\n\tcapturedAt: number;\n}\n\ninterface AppendEntryTarget {\n\tappendEntry<T = unknown>(customType: string, data?: T): void;\n}\n\ninterface SendMessageTarget extends AppendEntryTarget {\n\tsendMessage<T = unknown>(\n\t\tmessage: { customType: string; content: string; display: boolean; details?: T },\n\t\toptions?: { triggerTurn?: boolean; deliverAs?: \"steer\" | \"followUp\" | \"nextTurn\" },\n\t): void;\n}\n\nexport interface RestoreResult<T extends TodoSnapshotItems = TodoSnapshotItems> {\n\tapplied: boolean;\n\trestoredTodos: T;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null;\n}\n\nfunction isTodoStatus(value: unknown): value is TodoEntry[\"status\"] {\n\t// Legacy todowrite entries carried arbitrary status strings (e.g. \"blocked\").\n\t// The bridge is a pass-through snapshot carrier, not a validator: preserve\n\t// every string-status entry so restore never silently drops legacy todos.\n\treturn value === undefined || typeof value === \"string\";\n}\n\nfunction isTodoEntry(value: unknown): value is TodoEntry {\n\tif (!isRecord(value)) return false;\n\tconst hasId = typeof value.id === \"string\";\n\tconst hasContent = typeof value.content === \"string\" || typeof value.text === \"string\";\n\treturn (hasId || hasContent) && isTodoStatus(value.status);\n}\n\nfunction isTodoPhase(value: unknown): value is TodoPhase {\n\tif (!isRecord(value) || typeof value.name !== \"string\" || !Array.isArray(value.tasks)) return false;\n\treturn value.tasks.every(isTodoEntry);\n}\n\nfunction isCustomTodoEntry(entry: SessionEntry): entry is CustomEntry {\n\treturn (\n\t\tentry.type === \"custom\" &&\n\t\t(entry.customType.startsWith(\"todowrite\") || entry.customType === TODO_STATE_ENTRY_TYPE)\n\t);\n}\n\nfunction isLegacyTodoListEntry(entry: SessionEntry): entry is CustomEntry {\n\treturn entry.type === \"custom\" && entry.customType === \"todo-list\";\n}\n\nfunction readTodosFromEntry(entry: CustomEntry): TodoEntry[] {\n\tconst data = entry.data;\n\tif (!isRecord(data)) return [];\n\tif (Array.isArray(data.todos)) return data.todos.filter(isTodoEntry);\n\tif (Array.isArray(data.phases)) {\n\t\treturn data.phases.filter(isTodoPhase).flatMap((phase) => phase.tasks);\n\t}\n\treturn [];\n}\n\nfunction findLatestTodoSnapshot(ctx: ExtensionContext): TodoSnapshotPayload | null {\n\tconst entries = ctx.sessionManager.getEntries();\n\tfor (let index = entries.length - 1; index >= 0; index -= 1) {\n\t\tconst entry = entries[index];\n\t\tif (entry.type !== \"custom\" || entry.customType !== TODO_SNAPSHOT_CUSTOM_TYPE) continue;\n\t\tconst data = entry.data;\n\t\tif (isRecord(data) && data.schema === TODO_SNAPSHOT_SCHEMA && Array.isArray(data.todos)) {\n\t\t\treturn data as unknown as TodoSnapshotPayload;\n\t\t}\n\t}\n\treturn null;\n}\n\nexport function findTodoEntries(ctx: ExtensionContext): SessionEntry[];\nexport function findTodoEntries(entries: SessionEntry[], options?: { branchId?: string }): TodoEntry[];\nexport function findTodoEntries(\n\tctxOrEntries: ExtensionContext | SessionEntry[],\n\toptions?: { branchId?: string },\n): SessionEntry[] | TodoEntry[] {\n\tif (Array.isArray(ctxOrEntries)) {\n\t\treturn ctxOrEntries\n\t\t\t.filter((entry) => isLegacyTodoListEntry(entry) || isCustomTodoEntry(entry))\n\t\t\t.filter((entry) => options?.branchId === undefined || entry.parentId === options.branchId)\n\t\t\t.flatMap(readTodosFromEntry);\n\t}\n\n\treturn ctxOrEntries.sessionManager.getEntries().filter(isCustomTodoEntry);\n}\n\nexport function createTodoSnapshot(ctx: ExtensionContext): TodoSnapshotPayload {\n\treturn {\n\t\tschema: TODO_SNAPSHOT_SCHEMA,\n\t\ttodos: findTodoEntries(ctx),\n\t\tcapturedAt: Date.now(),\n\t};\n}\n\nexport function persistTodoSnapshot(pi: AppendEntryTarget, snapshot: TodoSnapshotPayload): void {\n\tpi.appendEntry(TODO_SNAPSHOT_CUSTOM_TYPE, snapshot);\n}\n\nexport function captureTodoSnapshot(pi: ExtensionAPI, ctx: ExtensionContext): void;\nexport function captureTodoSnapshot(currentTodos: TodoSnapshotItems, pi: AppendEntryTarget, branchId?: string): void;\nexport function captureTodoSnapshot(\n\tpiOrTodos: ExtensionAPI | TodoSnapshotItems,\n\tctxOrPi: ExtensionContext | AppendEntryTarget,\n\t_branchId?: string,\n): void {\n\tif (Array.isArray(piOrTodos)) {\n\t\tconst pi = ctxOrPi as AppendEntryTarget;\n\t\tpersistTodoSnapshot(pi, {\n\t\t\tschema: TODO_SNAPSHOT_SCHEMA,\n\t\t\ttodos: piOrTodos,\n\t\t\tcapturedAt: Date.now(),\n\t\t});\n\t\treturn;\n\t}\n\n\tpersistTodoSnapshot(piOrTodos, createTodoSnapshot(ctxOrPi as ExtensionContext));\n}\n\nexport function restoreTodosIfMissing(pi: ExtensionAPI, ctx: ExtensionContext): void;\nexport function restoreTodosIfMissing<T extends TodoSnapshotItems>(\n\tsnapshot: T,\n\tcurrentTodos: T,\n\tpi: AppendEntryTarget,\n): RestoreResult<T>;\nexport function restoreTodosIfMissing(\n\tpiOrSnapshot: ExtensionAPI | TodoSnapshotItems,\n\tctxOrCurrentTodos: ExtensionContext | TodoSnapshotItems,\n\t_pi?: AppendEntryTarget,\n): undefined | RestoreResult {\n\tif (Array.isArray(piOrSnapshot) && Array.isArray(ctxOrCurrentTodos)) {\n\t\tif (ctxOrCurrentTodos.length > 0) {\n\t\t\treturn { applied: false, restoredTodos: ctxOrCurrentTodos };\n\t\t}\n\t\treturn { applied: piOrSnapshot.length > 0, restoredTodos: piOrSnapshot };\n\t}\n\n\tconst pi = piOrSnapshot as SendMessageTarget;\n\tconst ctx = ctxOrCurrentTodos as ExtensionContext;\n\tif (findTodoEntries(ctx).length > 0) return;\n\n\tconst snapshot = findLatestTodoSnapshot(ctx);\n\tif (!snapshot || snapshot.todos.length === 0) return;\n\n\tpi.sendMessage(\n\t\t{\n\t\t\tcustomType: \"compaction.todo-restore-request\",\n\t\t\tcontent: `Restore missing todo tasks from snapshot: ${JSON.stringify(snapshot.todos)}`,\n\t\t\tdisplay: false,\n\t\t\tdetails: snapshot,\n\t\t},\n\t\t{ triggerTurn: true, deliverAs: \"nextTurn\" },\n\t);\n}\n"]}
@@ -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 GoalCommandRegistrationDeps = {
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 stopAgentGoalAccounting: (goalId: string) => void;
8
8
  readonly clearAgentGoalAccounting: () => void;
@@ -1 +1 @@
1
- {"version":3,"file":"command-registration.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/goal/command-registration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAIrE,OAAO,KAAK,EAAE,IAAI,EAAE,kBAAkB,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAQ7F,MAAM,MAAM,2BAA2B,GAAG;IACzC,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,uBAAuB,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3D,QAAQ,CAAC,wBAAwB,EAAE,MAAM,IAAI,CAAC;IAC9C,QAAQ,CAAC,qBAAqB,EAAE,CAAC,EAAE,EAAE,YAAY,EAAE,GAAG,EAAE,gBAAgB,EAAE,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;IAC9F,QAAQ,CAAC,aAAa,EAAE,CAAC,GAAG,EAAE,gBAAgB,EAAE,IAAI,EAAE,IAAI,GAAG,IAAI,KAAK,IAAI,CAAC;CAC3E,CAAC;AAEF,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,2BAA2B,GAAG,IAAI,CAoD7F"}
1
+ {"version":3,"file":"command-registration.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/goal/command-registration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAIrE,OAAO,KAAK,EAAE,IAAI,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAOzE,MAAM,MAAM,2BAA2B,GAAG;IACzC,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,uBAAuB,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3D,QAAQ,CAAC,wBAAwB,EAAE,MAAM,IAAI,CAAC;IAC9C,QAAQ,CAAC,qBAAqB,EAAE,CAAC,EAAE,EAAE,YAAY,EAAE,GAAG,EAAE,gBAAgB,EAAE,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;IAC9F,QAAQ,CAAC,aAAa,EAAE,CAAC,GAAG,EAAE,gBAAgB,EAAE,IAAI,EAAE,IAAI,GAAG,IAAI,KAAK,IAAI,CAAC;CAC3E,CAAC;AAEF,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,2BAA2B,GAAG,IAAI,CAoD7F"}
@@ -5,7 +5,6 @@ const GOAL_USAGE = "Usage: /goal <objective>";
5
5
  const GOAL_EMPTY_HINT = "No goal is currently set.";
6
6
  const REPLACE_GOAL_CHOICE = "Replace current goal";
7
7
  const CANCEL_REPLACE_GOAL_CHOICE = "Cancel";
8
- const EMPTY_USAGE = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, totalTokens: 0 };
9
8
  export function registerGoalCommand(pi, deps) {
10
9
  pi.registerCommand("goal", {
11
10
  description: "Set, inspect, pause, resume, or clear the persistent goal",
@@ -25,7 +24,7 @@ export function registerGoalCommand(pi, deps) {
25
24
  }
26
25
  case "setStatus": {
27
26
  if (command.status === "paused") {
28
- await deps.accountCurrentAgentTurn(ctx, EMPTY_USAGE, "active");
27
+ await deps.accountCurrentAgentTurn(ctx, "active");
29
28
  }
30
29
  const goal = await updateGoal(deps.goalStoreRef(ctx), { status: command.status });
31
30
  if (goal.status === "active") {
@@ -40,7 +39,7 @@ export function registerGoalCommand(pi, deps) {
40
39
  return;
41
40
  }
42
41
  case "clear": {
43
- await deps.accountCurrentAgentTurn(ctx, EMPTY_USAGE, "active");
42
+ await deps.accountCurrentAgentTurn(ctx, "active");
44
43
  const cleared = await clearGoal(deps.goalStoreRef(ctx));
45
44
  deps.clearAgentGoalAccounting();
46
45
  deps.refreshGoalUi(ctx, null);
@@ -64,7 +63,7 @@ async function setGoalObjective(pi, ctx, objective, deps) {
64
63
  return;
65
64
  }
66
65
  if (current?.status === "active") {
67
- await deps.accountCurrentAgentTurn(ctx, EMPTY_USAGE, "active");
66
+ await deps.accountCurrentAgentTurn(ctx, "active");
68
67
  }
69
68
  const goal = current === null ? await createGoal(ref, objective) : await updateGoal(ref, { objective });
70
69
  if (goal.status === "active")
@@ -1 +1 @@
1
- {"version":3,"file":"command-registration.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/goal/command-registration.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,YAA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;IAC9B,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,QAAQ,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,iBAAiB,CAAC,IAAI,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;IAC1F,IAAI,CAAC,qBAAqB,CAAC,EAAE,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;AAC3C,CAAC;AAED,KAAK,UAAU,kBAAkB,CAAC,GAAqB,EAAE,SAAiB;IACzE,IAAI,CAAC,GAAG,CAAC,KAAK;QAAE,OAAO,IAAI,CAAC;IAC5B,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,iCAAiC,SAAS,EAAE,EAAE;QAChF,mBAAmB;QACnB,0BAA0B;KAC1B,CAAC,CAAC;IACH,OAAO,MAAM,KAAK,mBAAmB,CAAC;AACvC,CAAC","sourcesContent":["import type { ExtensionAPI, ExtensionContext } from \"../../types.ts\";\nimport { parseGoalCommand } from \"./command.ts\";\nimport { formatGoalForTool, goalStatusLabel } from \"./format.ts\";\nimport { clearGoal, createGoal, readGoal, updateGoal } from \"./store.ts\";\nimport type { Goal, GoalAccountingMode, GoalStoreRef, TokenUsageSnapshot } from \"./types.ts\";\n\nconst GOAL_USAGE = \"Usage: /goal <objective>\";\nconst GOAL_EMPTY_HINT = \"No goal is currently set.\";\nconst REPLACE_GOAL_CHOICE = \"Replace current goal\";\nconst CANCEL_REPLACE_GOAL_CHOICE = \"Cancel\";\nconst EMPTY_USAGE: TokenUsageSnapshot = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, totalTokens: 0 };\n\nexport type GoalCommandRegistrationDeps = {\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 stopAgentGoalAccounting: (goalId: string) => void;\n\treadonly clearAgentGoalAccounting: () => void;\n\treadonly queueGoalContinuation: (pi: ExtensionAPI, ctx: ExtensionContext, goal: Goal) => void;\n\treadonly refreshGoalUi: (ctx: ExtensionContext, goal: Goal | null) => void;\n};\n\nexport function registerGoalCommand(pi: ExtensionAPI, deps: GoalCommandRegistrationDeps): void {\n\tpi.registerCommand(\"goal\", {\n\t\tdescription: \"Set, inspect, pause, resume, or clear the persistent goal\",\n\t\thandler: async (rawArgs, ctx) => {\n\t\t\tconst command = parseGoalCommand(rawArgs);\n\t\t\ttry {\n\t\t\t\tswitch (command.kind) {\n\t\t\t\t\tcase \"show\": {\n\t\t\t\t\t\tconst goal = await readGoal(deps.goalStoreRef(ctx));\n\t\t\t\t\t\tdeps.refreshGoalUi(ctx, goal);\n\t\t\t\t\t\tctx.ui.notify(\n\t\t\t\t\t\t\tgoal === null ? `${GOAL_USAGE}\\n${GOAL_EMPTY_HINT}` : formatGoalForTool(goal),\n\t\t\t\t\t\t\tgoal ? \"info\" : \"warning\",\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tcase \"setObjective\": {\n\t\t\t\t\t\tawait setGoalObjective(pi, ctx, command.objective, deps);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tcase \"setStatus\": {\n\t\t\t\t\t\tif (command.status === \"paused\") {\n\t\t\t\t\t\t\tawait deps.accountCurrentAgentTurn(ctx, EMPTY_USAGE, \"active\");\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst goal = await updateGoal(deps.goalStoreRef(ctx), { status: command.status });\n\t\t\t\t\t\tif (goal.status === \"active\") {\n\t\t\t\t\t\t\tdeps.beginAgentGoalAccounting(goal);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tdeps.stopAgentGoalAccounting(goal.id);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tdeps.refreshGoalUi(ctx, goal);\n\t\t\t\t\t\tctx.ui.notify(`Goal ${goalStatusLabel(goal.status)}\\n${formatGoalForTool(goal)}`, \"info\");\n\t\t\t\t\t\tdeps.queueGoalContinuation(pi, ctx, goal);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tcase \"clear\": {\n\t\t\t\t\t\tawait deps.accountCurrentAgentTurn(ctx, EMPTY_USAGE, \"active\");\n\t\t\t\t\t\tconst cleared = await clearGoal(deps.goalStoreRef(ctx));\n\t\t\t\t\t\tdeps.clearAgentGoalAccounting();\n\t\t\t\t\t\tdeps.refreshGoalUi(ctx, null);\n\t\t\t\t\t\tctx.ui.notify(\n\t\t\t\t\t\t\tcleared ? \"Goal cleared\" : \"No goal to clear\\nThis thread does not currently have a goal.\",\n\t\t\t\t\t\t\tcleared ? \"info\" : \"warning\",\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tctx.ui.notify(error instanceof Error ? error.message : String(error), \"error\");\n\t\t\t}\n\t\t},\n\t});\n}\n\nasync function setGoalObjective(\n\tpi: ExtensionAPI,\n\tctx: ExtensionContext,\n\tobjective: string,\n\tdeps: GoalCommandRegistrationDeps,\n): Promise<void> {\n\tconst ref = deps.goalStoreRef(ctx);\n\tconst current = await readGoal(ref);\n\tif (current !== null) {\n\t\tconst shouldReplace = await confirmReplaceGoal(ctx, objective);\n\t\tif (!shouldReplace) return;\n\t}\n\n\tif (current?.status === \"active\") {\n\t\tawait deps.accountCurrentAgentTurn(ctx, EMPTY_USAGE, \"active\");\n\t}\n\tconst goal = current === null ? await createGoal(ref, objective) : await updateGoal(ref, { objective });\n\tif (goal.status === \"active\") deps.beginAgentGoalAccounting(goal);\n\tdeps.refreshGoalUi(ctx, goal);\n\tctx.ui.notify(`Goal ${goalStatusLabel(goal.status)}\\n${formatGoalForTool(goal)}`, \"info\");\n\tdeps.queueGoalContinuation(pi, ctx, goal);\n}\n\nasync function confirmReplaceGoal(ctx: ExtensionContext, objective: string): Promise<boolean> {\n\tif (!ctx.hasUI) return true;\n\tconst choice = await ctx.ui.select(`Replace goal?\\nNew objective: ${objective}`, [\n\t\tREPLACE_GOAL_CHOICE,\n\t\tCANCEL_REPLACE_GOAL_CHOICE,\n\t]);\n\treturn choice === REPLACE_GOAL_CHOICE;\n}\n"]}
1
+ {"version":3,"file":"command-registration.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/goal/command-registration.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAGzE,MAAM,UAAU,GAAG,0BAA0B,CAAC;AAC9C,MAAM,eAAe,GAAG,2BAA2B,CAAC;AACpD,MAAM,mBAAmB,GAAG,sBAAsB,CAAC;AACnD,MAAM,0BAA0B,GAAG,QAAQ,CAAC;AAY5C,MAAM,UAAU,mBAAmB,CAAC,EAAgB,EAAE,IAAiC;IACtF,EAAE,CAAC,eAAe,CAAC,MAAM,EAAE;QAC1B,WAAW,EAAE,2DAA2D;QACxE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,EAAE;YAC/B,MAAM,OAAO,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;YAC1C,IAAI,CAAC;gBACJ,QAAQ,OAAO,CAAC,IAAI,EAAE,CAAC;oBACtB,KAAK,MAAM,EAAE,CAAC;wBACb,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC;wBACpD,IAAI,CAAC,aAAa,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;wBAC9B,GAAG,CAAC,EAAE,CAAC,MAAM,CACZ,IAAI,KAAK,IAAI,CAAC,C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AO,KAAK,IAAI,CAAC,CAAC,CAAC,MAAM,UAAU,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,MAAM,UAAU,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC;IACxG,IAAI,IAAI,CAAC,MAAM,KAAK,QAAQ;QAAE,IAAI,CAAC,wBAAwB,CAAC,IAAI,CAAC,CAAC;IAClE,IAAI,CAAC,aAAa,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IAC9B,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,QAAQ,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,iBAAiB,CAAC,IAAI,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;IAC1F,IAAI,CAAC,qBAAqB,CAAC,EAAE,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;AAC3C,CAAC;AAED,KAAK,UAAU,kBAAkB,CAAC,GAAqB,EAAE,SAAiB;IACzE,IAAI,CAAC,GAAG,CAAC,KAAK;QAAE,OAAO,IAAI,CAAC;IAC5B,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,iCAAiC,SAAS,EAAE,EAAE;QAChF,mBAAmB;QACnB,0BAA0B;KAC1B,CAAC,CAAC;IACH,OAAO,MAAM,KAAK,mBAAmB,CAAC;AACvC,CAAC","sourcesContent":["import type { ExtensionAPI, ExtensionContext } from \"../../types.ts\";\nimport { parseGoalCommand } from \"./command.ts\";\nimport { formatGoalForTool, goalStatusLabel } from \"./format.ts\";\nimport { clearGoal, createGoal, readGoal, updateGoal } from \"./store.ts\";\nimport type { Goal, GoalAccountingMode, GoalStoreRef } from \"./types.ts\";\n\nconst GOAL_USAGE = \"Usage: /goal <objective>\";\nconst GOAL_EMPTY_HINT = \"No goal is currently set.\";\nconst REPLACE_GOAL_CHOICE = \"Replace current goal\";\nconst CANCEL_REPLACE_GOAL_CHOICE = \"Cancel\";\n\nexport type GoalCommandRegistrationDeps = {\n\treadonly goalStoreRef: (ctx: ExtensionContext) => GoalStoreRef;\n\treadonly accountCurrentAgentTurn: (ctx: ExtensionContext, mode: GoalAccountingMode) => Promise<Goal | null>;\n\treadonly beginAgentGoalAccounting: (goal: Goal) => void;\n\treadonly stopAgentGoalAccounting: (goalId: string) => void;\n\treadonly clearAgentGoalAccounting: () => void;\n\treadonly queueGoalContinuation: (pi: ExtensionAPI, ctx: ExtensionContext, goal: Goal) => void;\n\treadonly refreshGoalUi: (ctx: ExtensionContext, goal: Goal | null) => void;\n};\n\nexport function registerGoalCommand(pi: ExtensionAPI, deps: GoalCommandRegistrationDeps): void {\n\tpi.registerCommand(\"goal\", {\n\t\tdescription: \"Set, inspect, pause, resume, or clear the persistent goal\",\n\t\thandler: async (rawArgs, ctx) => {\n\t\t\tconst command = parseGoalCommand(rawArgs);\n\t\t\ttry {\n\t\t\t\tswitch (command.kind) {\n\t\t\t\t\tcase \"show\": {\n\t\t\t\t\t\tconst goal = await readGoal(deps.goalStoreRef(ctx));\n\t\t\t\t\t\tdeps.refreshGoalUi(ctx, goal);\n\t\t\t\t\t\tctx.ui.notify(\n\t\t\t\t\t\t\tgoal === null ? `${GOAL_USAGE}\\n${GOAL_EMPTY_HINT}` : formatGoalForTool(goal),\n\t\t\t\t\t\t\tgoal ? \"info\" : \"warning\",\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tcase \"setObjective\": {\n\t\t\t\t\t\tawait setGoalObjective(pi, ctx, command.objective, deps);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tcase \"setStatus\": {\n\t\t\t\t\t\tif (command.status === \"paused\") {\n\t\t\t\t\t\t\tawait deps.accountCurrentAgentTurn(ctx, \"active\");\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst goal = await updateGoal(deps.goalStoreRef(ctx), { status: command.status });\n\t\t\t\t\t\tif (goal.status === \"active\") {\n\t\t\t\t\t\t\tdeps.beginAgentGoalAccounting(goal);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tdeps.stopAgentGoalAccounting(goal.id);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tdeps.refreshGoalUi(ctx, goal);\n\t\t\t\t\t\tctx.ui.notify(`Goal ${goalStatusLabel(goal.status)}\\n${formatGoalForTool(goal)}`, \"info\");\n\t\t\t\t\t\tdeps.queueGoalContinuation(pi, ctx, goal);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tcase \"clear\": {\n\t\t\t\t\t\tawait deps.accountCurrentAgentTurn(ctx, \"active\");\n\t\t\t\t\t\tconst cleared = await clearGoal(deps.goalStoreRef(ctx));\n\t\t\t\t\t\tdeps.clearAgentGoalAccounting();\n\t\t\t\t\t\tdeps.refreshGoalUi(ctx, null);\n\t\t\t\t\t\tctx.ui.notify(\n\t\t\t\t\t\t\tcleared ? \"Goal cleared\" : \"No goal to clear\\nThis thread does not currently have a goal.\",\n\t\t\t\t\t\t\tcleared ? \"info\" : \"warning\",\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tctx.ui.notify(error instanceof Error ? error.message : String(error), \"error\");\n\t\t\t}\n\t\t},\n\t});\n}\n\nasync function setGoalObjective(\n\tpi: ExtensionAPI,\n\tctx: ExtensionContext,\n\tobjective: string,\n\tdeps: GoalCommandRegistrationDeps,\n): Promise<void> {\n\tconst ref = deps.goalStoreRef(ctx);\n\tconst current = await readGoal(ref);\n\tif (current !== null) {\n\t\tconst shouldReplace = await confirmReplaceGoal(ctx, objective);\n\t\tif (!shouldReplace) return;\n\t}\n\n\tif (current?.status === \"active\") {\n\t\tawait deps.accountCurrentAgentTurn(ctx, \"active\");\n\t}\n\tconst goal = current === null ? await createGoal(ref, objective) : await updateGoal(ref, { objective });\n\tif (goal.status === \"active\") deps.beginAgentGoalAccounting(goal);\n\tdeps.refreshGoalUi(ctx, goal);\n\tctx.ui.notify(`Goal ${goalStatusLabel(goal.status)}\\n${formatGoalForTool(goal)}`, \"info\");\n\tdeps.queueGoalContinuation(pi, ctx, goal);\n}\n\nasync function confirmReplaceGoal(ctx: ExtensionContext, objective: string): Promise<boolean> {\n\tif (!ctx.hasUI) return true;\n\tconst choice = await ctx.ui.select(`Replace goal?\\nNew objective: ${objective}`, [\n\t\tREPLACE_GOAL_CHOICE,\n\t\tCANCEL_REPLACE_GOAL_CHOICE,\n\t]);\n\treturn choice === REPLACE_GOAL_CHOICE;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/goal/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAoB,MAAM,gBAAgB,CAAC;AA2BrE,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,EAAE,EAAE,YAAY,GAAG,IAAI,CAkL5D"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/goal/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAoB,MAAM,gBAAgB,CAAC;AAsBrE,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,EAAE,EAAE,YAAY,GAAG,IAAI,CA2L5D"}
@@ -8,17 +8,17 @@ import { formatGoalForTool, goalStatusLabel } from "./format.js";
8
8
  import { buildContinuationPrompt } from "./prompt.js";
9
9
  import { accountGoalUsage, readGoal, updateGoal } from "./store.js";
10
10
  import { registerGoalTools } from "./tool-registration.js";
11
- import { isRecord } from "./types.js";
11
+ import { TurnUsageTracker } from "./turn-usage.js";
12
12
  import { updateGoalUi } from "./ui.js";
13
13
  const GOAL_CONTINUATION_MESSAGE_TYPE = "goal-continuation";
14
14
  const RESUME_GOAL_CHOICE = "Resume goal";
15
15
  const LEAVE_GOAL_PAUSED_CHOICE = "Leave paused";
16
- const EMPTY_USAGE = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, totalTokens: 0 };
17
16
  const STALE_EXTENSION_CONTEXT_ERROR_PREFIX = "This extension ctx is stale after session replacement or reload.";
18
17
  export default function goalExtension(pi) {
19
18
  let agentTurnInProgress = false;
20
19
  let agentGoalAccounting = null;
21
20
  let completedThisTurnGoalId = null;
21
+ const turnUsage = new TurnUsageTracker();
22
22
  const goalTicker = new GoalElapsedTicker({
23
23
  render: (renderCtx, renderGoal, live) => {
24
24
  try {
@@ -66,6 +66,7 @@ export default function goalExtension(pi) {
66
66
  pi.on("agent_start", async (_event, ctx) => {
67
67
  agentTurnInProgress = true;
68
68
  completedThisTurnGoalId = null;
69
+ turnUsage.reset();
69
70
  const goal = await readGoal(goalStoreRef(ctx));
70
71
  if (goal?.status === "active") {
71
72
  beginAgentGoalAccounting(goal);
@@ -74,9 +75,12 @@ export default function goalExtension(pi) {
74
75
  agentGoalAccounting = null;
75
76
  }
76
77
  });
78
+ pi.on("message_end", async (event) => {
79
+ turnUsage.noteMessageEnd(event.message);
80
+ });
77
81
  pi.on("agent_end", async (event, ctx) => {
78
82
  const mode = completedThisTurnGoalId === null ? "active" : "activeOrComplete";
79
- const goal = await accountCurrentAgentTurn(ctx, collectAssistantUsage(event.messages), mode);
83
+ const goal = await accountCurrentAgentTurn(ctx, mode, event.messages);
80
84
  agentTurnInProgress = false;
81
85
  completedThisTurnGoalId = null;
82
86
  if (goal?.status === "active") {
@@ -94,7 +98,7 @@ export default function goalExtension(pi) {
94
98
  });
95
99
  pi.on("session_shutdown", async (_event, ctx) => {
96
100
  if (agentGoalAccounting !== null) {
97
- await accountCurrentAgentTurn(ctx, EMPTY_USAGE, "active");
101
+ await accountCurrentAgentTurn(ctx, "active");
98
102
  }
99
103
  clearAgentGoalAccounting();
100
104
  goalTicker.stop();
@@ -121,6 +125,7 @@ export default function goalExtension(pi) {
121
125
  return;
122
126
  if (agentGoalAccounting?.goalId === goal.id)
123
127
  return;
128
+ turnUsage.discardPending();
124
129
  agentGoalAccounting = { goalId: goal.id, measuredFromMilliseconds: Date.now() };
125
130
  }
126
131
  function markGoalCompletedThisTurn(goal) {
@@ -161,11 +166,12 @@ export default function goalExtension(pi) {
161
166
  throw error;
162
167
  }
163
168
  }
164
- async function accountCurrentAgentTurn(ctx, usage, mode) {
169
+ async function accountCurrentAgentTurn(ctx, mode, agentRunMessages) {
165
170
  const accounting = agentGoalAccounting;
166
171
  const ref = goalStoreRef(ctx);
167
172
  if (accounting === null)
168
173
  return readGoal(ref);
174
+ const usage = agentRunMessages === undefined ? turnUsage.takePending() : turnUsage.takeRemaining(agentRunMessages);
169
175
  const now = Date.now();
170
176
  const elapsedSeconds = Math.max(0, Math.round((now - accounting.measuredFromMilliseconds) / 1000));
171
177
  const goal = await accountGoalUsage(ref, usage, elapsedSeconds, mode, accounting.goalId);
@@ -206,26 +212,4 @@ function goalStoreRef(ctx) {
206
212
  function cwdStoreKey(cwd) {
207
213
  return createHash("sha256").update(cwd).digest("hex").slice(0, 24);
208
214
  }
209
- function collectAssistantUsage(messages) {
210
- const usage = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, totalTokens: 0 };
211
- for (const message of messages) {
212
- if (!isAssistantUsageMessage(message))
213
- continue;
214
- usage.input += numericUsageField(message.usage, "input");
215
- usage.output += numericUsageField(message.usage, "output");
216
- usage.cacheRead += numericUsageField(message.usage, "cacheRead");
217
- usage.cacheWrite += numericUsageField(message.usage, "cacheWrite");
218
- usage.totalTokens += numericUsageField(message.usage, "totalTokens");
219
- }
220
- return usage;
221
- }
222
- function isAssistantUsageMessage(message) {
223
- if (!isRecord(message))
224
- return false;
225
- return message.role === "assistant" && isRecord(message.usage);
226
- }
227
- function numericUsageField(usage, key) {
228
- const value = usage[key];
229
- return typeof value === "number" && Number.isFinite(value) ? value : 0;
230
- }
231
215
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/goal/index.ts"],"names":[],"mappings":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M,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;IACzB,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AACxE,CAAC","sourcesContent":["import { createHash } from \"node:crypto\";\nimport { join } from \"node:path\";\nimport { getAgentDir } from \"../../../../config.ts\";\nimport type { ExtensionAPI, ExtensionContext } from \"../../types.ts\";\nimport { registerGoalCommand } from \"./command-registration.ts\";\nimport { shouldQueueGoalContinuationAfterAgentEnd, shouldQueueGoalContinuationWhenIdle } from \"./continuation.ts\";\nimport { GoalElapsedTicker } from \"./elapsed-ticker.ts\";\nimport { formatGoalForTool, goalStatusLabel } from \"./format.ts\";\nimport { buildContinuationPrompt } from \"./prompt.ts\";\nimport { accountGoalUsage, readGoal, updateGoal } from \"./store.ts\";\nimport { registerGoalTools } from \"./tool-registration.ts\";\nimport type { Goal, GoalAccountingMode, GoalStoreRef, TokenUsageSnapshot } from \"./types.ts\";\nimport { isRecord } from \"./types.ts\";\nimport { updateGoalUi } from \"./ui.ts\";\n\nconst GOAL_CONTINUATION_MESSAGE_TYPE = \"goal-continuation\";\nconst RESUME_GOAL_CHOICE = \"Resume goal\";\nconst LEAVE_GOAL_PAUSED_CHOICE = \"Leave paused\";\nconst EMPTY_USAGE: TokenUsageSnapshot = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, totalTokens: 0 };\nconst STALE_EXTENSION_CONTEXT_ERROR_PREFIX = \"This extension ctx is stale after session replacement or reload.\";\n\ntype AssistantUsageMessage = {\n\trole: \"assistant\";\n\tusage: Record<string, unknown>;\n};\ntype AgentGoalAccounting = {\n\tgoalId: string;\n\tmeasuredFromMilliseconds: number;\n};\n\nexport default function goalExtension(pi: ExtensionAPI): void {\n\tlet agentTurnInProgress = false;\n\tlet agentGoalAccounting: AgentGoalAccounting | null = null;\n\tlet completedThisTurnGoalId: string | null = null;\n\n\tconst goalTicker = new GoalElapsedTicker({\n\t\trender: (renderCtx, renderGoal, live) => {\n\t\t\ttry {\n\t\t\t\tupdateGoalUi(renderCtx, renderGoal, live);\n\t\t\t} catch (error) {\n\t\t\t\tif (error instanceof Error && error.message.startsWith(STALE_EXTENSION_CONTEXT_ERROR_PREFIX)) return;\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t},\n\t});\n\n\tregisterGoalTools(pi, {\n\t\tgoalStoreRef,\n\t\taccountCurrentAgentTurn,\n\t\tbeginAgentGoalAccounting,\n\t\tmarkGoalCompletedThisTurn,\n\t\trefreshGoalUi,\n\t});\n\tregisterGoalCommand(pi, {\n\t\tgoalStoreRef,\n\t\taccountCurrentAgentTurn,\n\t\tbeginAgentGoalAccounting,\n\t\tstopAgentGoalAccounting,\n\t\tclearAgentGoalAccounting,\n\t\tqueueGoalContinuation,\n\t\trefreshGoalUi,\n\t});\n\n\tpi.on(\"session_start\", async (event, ctx) => {\n\t\tconst goal = await readGoal(goalStoreRef(ctx));\n\t\tif (goal?.status === \"active\") {\n\t\t\tbeginAgentGoalAccounting(goal);\n\t\t} else {\n\t\t\tclearAgentGoalAccounting();\n\t\t}\n\t\trefreshGoalUi(ctx, goal);\n\t\tif (await maybePromptResumePausedGoal(pi, ctx, event.reason, goal)) {\n\t\t\treturn;\n\t\t}\n\t\tif (shouldQueueGoalContinuationWhenIdle(goal, ctx.isIdle(), ctx.hasPendingMessages())) {\n\t\t\tqueueHiddenGoalPrompt(pi, buildContinuationPrompt(goal));\n\t\t}\n\t});\n\n\tpi.on(\"agent_start\", async (_event, ctx) => {\n\t\tagentTurnInProgress = true;\n\t\tcompletedThisTurnGoalId = null;\n\t\tconst goal = await readGoal(goalStoreRef(ctx));\n\t\tif (goal?.status === \"active\") {\n\t\t\tbeginAgentGoalAccounting(goal);\n\t\t} else {\n\t\t\tagentGoalAccounting = null;\n\t\t}\n\t});\n\n\tpi.on(\"agent_end\", async (event, ctx) => {\n\t\tconst mode: GoalAccountingMode = completedThisTurnGoalId === null ? \"active\" : \"activeOrComplete\";\n\t\tconst goal = await accountCurrentAgentTurn(ctx, collectAssistantUsage(event.messages), mode);\n\t\tagentTurnInProgress = false;\n\t\tcompletedThisTurnGoalId = null;\n\t\tif (goal?.status === \"active\") {\n\t\t\tbeginAgentGoalAccounting(goal);\n\t\t} else {\n\t\t\tclearAgentGoalAccounting();\n\t\t}\n\t\trefreshGoalUiBestEffort(ctx, goal);\n\t\tif (\n\t\t\tgoal?.status === \"active\" &&\n\t\t\t!ctx.signal?.aborted &&\n\t\t\tshouldQueueGoalContinuationAfterAgentEnd(goal, ctx.hasPendingMessages(), event.messages)\n\t\t) {\n\t\t\tqueueHiddenGoalPrompt(pi, buildContinuationPrompt(goal));\n\t\t}\n\t});\n\n\tpi.on(\"session_shutdown\", async (_event, ctx) => {\n\t\tif (agentGoalAccounting !== null) {\n\t\t\tawait accountCurrentAgentTurn(ctx, EMPTY_USAGE, \"active\");\n\t\t}\n\t\tclearAgentGoalAccounting();\n\t\tgoalTicker.stop();\n\t});\n\n\tasync function maybePromptResumePausedGoal(\n\t\tpi: ExtensionAPI,\n\t\tctx: ExtensionContext,\n\t\tsessionStartReason: string,\n\t\tgoal: Goal | null,\n\t): Promise<boolean> {\n\t\tif (!isResumeOfPausedGoal(ctx, sessionStartReason, goal)) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst choice = await ctx.ui.select(`Resume paused goal?\\nGoal: ${goal.objective}`, [\n\t\t\tRESUME_GOAL_CHOICE,\n\t\t\tLEAVE_GOAL_PAUSED_CHOICE,\n\t\t]);\n\t\tif (choice !== RESUME_GOAL_CHOICE) return true;\n\n\t\tconst resumed = await updateGoal(goalStoreRef(ctx), { status: \"active\" });\n\t\tbeginAgentGoalAccounting(resumed);\n\t\trefreshGoalUi(ctx, resumed);\n\t\tctx.ui.notify(`Goal ${goalStatusLabel(resumed.status)}\\n${formatGoalForTool(resumed)}`, \"info\");\n\t\tqueueGoalContinuation(pi, ctx, resumed);\n\t\treturn true;\n\t}\n\n\tfunction beginAgentGoalAccounting(goal: Goal): void {\n\t\tif (goal.status !== \"active\") return;\n\t\tif (agentGoalAccounting?.goalId === goal.id) return;\n\t\tagentGoalAccounting = { goalId: goal.id, measuredFromMilliseconds: Date.now() };\n\t}\n\n\tfunction markGoalCompletedThisTurn(goal: Goal): void {\n\t\tif (!agentTurnInProgress) return;\n\t\tcompletedThisTurnGoalId = goal.id;\n\t\tagentGoalAccounting = { goalId: goal.id, measuredFromMilliseconds: Date.now() };\n\t}\n\n\tfunction stopAgentGoalAccounting(goalId: string): void {\n\t\tif (agentGoalAccounting?.goalId === goalId) {\n\t\t\tagentGoalAccounting = null;\n\t\t}\n\t\tif (completedThisTurnGoalId === goalId) {\n\t\t\tcompletedThisTurnGoalId = null;\n\t\t}\n\t}\n\n\tfunction clearAgentGoalAccounting(): void {\n\t\tagentGoalAccounting = null;\n\t\tcompletedThisTurnGoalId = null;\n\t}\n\n\tfunction refreshGoalUi(ctx: ExtensionContext, goal: Goal | null): void {\n\t\tconst accounting = agentGoalAccounting;\n\t\tif (ctx.hasUI && goal?.status === \"active\" && accounting?.goalId === goal.id) {\n\t\t\tgoalTicker.sync(ctx, goal, accounting.measuredFromMilliseconds);\n\t\t\treturn;\n\t\t}\n\t\tgoalTicker.stop();\n\t\tupdateGoalUi(ctx, goal);\n\t}\n\n\tfunction refreshGoalUiBestEffort(ctx: ExtensionContext, goal: Goal | null): void {\n\t\ttry {\n\t\t\trefreshGoalUi(ctx, goal);\n\t\t} catch (error) {\n\t\t\tif (error instanceof Error && error.message.startsWith(STALE_EXTENSION_CONTEXT_ERROR_PREFIX)) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\tasync function accountCurrentAgentTurn(\n\t\tctx: ExtensionContext,\n\t\tusage: TokenUsageSnapshot,\n\t\tmode: GoalAccountingMode,\n\t): Promise<Goal | null> {\n\t\tconst accounting = agentGoalAccounting;\n\t\tconst ref = goalStoreRef(ctx);\n\t\tif (accounting === null) return readGoal(ref);\n\n\t\tconst now = Date.now();\n\t\tconst elapsedSeconds = Math.max(0, Math.round((now - accounting.measuredFromMilliseconds) / 1000));\n\t\tconst goal = await accountGoalUsage(ref, usage, elapsedSeconds, mode, accounting.goalId);\n\t\tif (goal?.id === accounting.goalId) {\n\t\t\tagentGoalAccounting = { goalId: accounting.goalId, measuredFromMilliseconds: now };\n\t\t} else {\n\t\t\tclearAgentGoalAccounting();\n\t\t}\n\t\treturn goal;\n\t}\n}\n\nfunction isResumeOfPausedGoal(ctx: ExtensionContext, sessionStartReason: string, goal: Goal | null): goal is Goal {\n\treturn (\n\t\tsessionStartReason === \"resume\" &&\n\t\tgoal?.status === \"paused\" &&\n\t\tctx.hasUI &&\n\t\tctx.isIdle() &&\n\t\t!ctx.hasPendingMessages()\n\t);\n}\n\nfunction queueGoalContinuation(pi: ExtensionAPI, ctx: ExtensionContext, goal: Goal): void {\n\tif (shouldQueueGoalContinuationWhenIdle(goal, ctx.isIdle(), ctx.hasPendingMessages())) {\n\t\tqueueHiddenGoalPrompt(pi, buildContinuationPrompt(goal));\n\t}\n}\n\nfunction queueHiddenGoalPrompt(pi: ExtensionAPI, content: string): void {\n\tpi.sendMessage(\n\t\t{ customType: GOAL_CONTINUATION_MESSAGE_TYPE, content, display: false },\n\t\t{ triggerTurn: true, deliverAs: \"followUp\" },\n\t);\n}\n\nfunction goalStoreRef(ctx: ExtensionContext): GoalStoreRef {\n\tconst sessionFile = ctx.sessionManager.getSessionFile();\n\tconst baseDir =\n\t\tsessionFile === undefined\n\t\t\t? join(getAgentDir(), \"extensions\", \"goal\", \"no-session\", cwdStoreKey(ctx.cwd))\n\t\t\t: join(ctx.sessionManager.getSessionDir(), \"extensions\", \"goal\");\n\n\treturn {\n\t\tbaseDir,\n\t\tthreadId: ctx.sessionManager.getSessionId(),\n\t};\n}\n\nfunction cwdStoreKey(cwd: string): string {\n\treturn createHash(\"sha256\").update(cwd).digest(\"hex\").slice(0, 24);\n}\n\nfunction collectAssistantUsage(messages: unknown[]): TokenUsageSnapshot {\n\tconst usage: TokenUsageSnapshot = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, totalTokens: 0 };\n\tfor (const message of messages) {\n\t\tif (!isAssistantUsageMessage(message)) continue;\n\t\tusage.input += numericUsageField(message.usage, \"input\");\n\t\tusage.output += numericUsageField(message.usage, \"output\");\n\t\tusage.cacheRead += numericUsageField(message.usage, \"cacheRead\");\n\t\tusage.cacheWrite += numericUsageField(message.usage, \"cacheWrite\");\n\t\tusage.totalTokens += numericUsageField(message.usage, \"totalTokens\");\n\t}\n\treturn usage;\n}\n\nfunction isAssistantUsageMessage(message: unknown): message is AssistantUsageMessage {\n\tif (!isRecord(message)) return false;\n\treturn message.role === \"assistant\" && isRecord(message.usage);\n}\n\nfunction numericUsageField(usage: Record<string, unknown>, key: string): number {\n\tconst value = usage[key];\n\treturn typeof value === \"number\" && Number.isFinite(value) ? value : 0;\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/goal/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAE,wCAAwC,EAAE,mCAAmC,EAAE,MAAM,mBAAmB,CAAC;AAClH,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACjE,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACpE,OAAO,EAAE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AS,qBAAqB,CAAC,EAAgB,EAAE,GAAqB,EAAE,IAAU;IACjF,IAAI,mCAAmC,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,EAAE,GAAG,CAAC,kBAAkB,EAAE,CAAC,EAAE,CAAC;QACvF,qBAAqB,CAAC,EAAE,EAAE,uBAAuB,CAAC,IAAI,CAAC,CAAC,CAAC;IAC1D,CAAC;AACF,CAAC;AAED,SAAS,qBAAqB,CAAC,EAAgB,EAAE,OAAe;IAC/D,EAAE,CAAC,WAAW,CACb,EAAE,UAAU,EAAE,8BAA8B,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,EACvE,EAAE,WAAW,EAAE,IAAI,EAAE,SAAS,EAAE,UAAU,EAAE,CAC5C,CAAC;AACH,CAAC;AAED,SAAS,YAAY,CAAC,GAAqB;IAC1C,MAAM,WAAW,GAAG,GAAG,CAAC,cAAc,CAAC,cAAc,EAAE,CAAC;IACxD,MAAM,OAAO,GACZ,WAAW,KAAK,SAAS;QACxB,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,YAAY,EAAE,MAAM,EAAE,YAAY,EAAE,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC/E,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC,aAAa,EAAE,EAAE,YAAY,EAAE,MAAM,CAAC,CAAC;IAEnE,OAAO;QACN,OAAO;QACP,QAAQ,EAAE,GAAG,CAAC,cAAc,CAAC,YAAY,EAAE;KAC3C,CAAC;AACH,CAAC;AAED,SAAS,WAAW,CAAC,GAAW;IAC/B,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AACpE,CAAC","sourcesContent":["import { createHash } from \"node:crypto\";\nimport { join } from \"node:path\";\nimport { getAgentDir } from \"../../../../config.ts\";\nimport type { ExtensionAPI, ExtensionContext } from \"../../types.ts\";\nimport { registerGoalCommand } from \"./command-registration.ts\";\nimport { shouldQueueGoalContinuationAfterAgentEnd, shouldQueueGoalContinuationWhenIdle } from \"./continuation.ts\";\nimport { GoalElapsedTicker } from \"./elapsed-ticker.ts\";\nimport { formatGoalForTool, goalStatusLabel } from \"./format.ts\";\nimport { buildContinuationPrompt } from \"./prompt.ts\";\nimport { accountGoalUsage, readGoal, updateGoal } from \"./store.ts\";\nimport { registerGoalTools } from \"./tool-registration.ts\";\nimport { TurnUsageTracker } from \"./turn-usage.ts\";\nimport type { Goal, GoalAccountingMode, GoalStoreRef } from \"./types.ts\";\nimport { updateGoalUi } from \"./ui.ts\";\n\nconst GOAL_CONTINUATION_MESSAGE_TYPE = \"goal-continuation\";\nconst RESUME_GOAL_CHOICE = \"Resume goal\";\nconst LEAVE_GOAL_PAUSED_CHOICE = \"Leave paused\";\nconst STALE_EXTENSION_CONTEXT_ERROR_PREFIX = \"This extension ctx is stale after session replacement or reload.\";\n\ntype AgentGoalAccounting = {\n\tgoalId: string;\n\tmeasuredFromMilliseconds: number;\n};\n\nexport default function goalExtension(pi: ExtensionAPI): void {\n\tlet agentTurnInProgress = false;\n\tlet agentGoalAccounting: AgentGoalAccounting | null = null;\n\tlet completedThisTurnGoalId: string | null = null;\n\tconst turnUsage = new TurnUsageTracker();\n\n\tconst goalTicker = new GoalElapsedTicker({\n\t\trender: (renderCtx, renderGoal, live) => {\n\t\t\ttry {\n\t\t\t\tupdateGoalUi(renderCtx, renderGoal, live);\n\t\t\t} catch (error) {\n\t\t\t\tif (error instanceof Error && error.message.startsWith(STALE_EXTENSION_CONTEXT_ERROR_PREFIX)) return;\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t},\n\t});\n\n\tregisterGoalTools(pi, {\n\t\tgoalStoreRef,\n\t\taccountCurrentAgentTurn,\n\t\tbeginAgentGoalAccounting,\n\t\tmarkGoalCompletedThisTurn,\n\t\trefreshGoalUi,\n\t});\n\tregisterGoalCommand(pi, {\n\t\tgoalStoreRef,\n\t\taccountCurrentAgentTurn,\n\t\tbeginAgentGoalAccounting,\n\t\tstopAgentGoalAccounting,\n\t\tclearAgentGoalAccounting,\n\t\tqueueGoalContinuation,\n\t\trefreshGoalUi,\n\t});\n\n\tpi.on(\"session_start\", async (event, ctx) => {\n\t\tconst goal = await readGoal(goalStoreRef(ctx));\n\t\tif (goal?.status === \"active\") {\n\t\t\tbeginAgentGoalAccounting(goal);\n\t\t} else {\n\t\t\tclearAgentGoalAccounting();\n\t\t}\n\t\trefreshGoalUi(ctx, goal);\n\t\tif (await maybePromptResumePausedGoal(pi, ctx, event.reason, goal)) {\n\t\t\treturn;\n\t\t}\n\t\tif (shouldQueueGoalContinuationWhenIdle(goal, ctx.isIdle(), ctx.hasPendingMessages())) {\n\t\t\tqueueHiddenGoalPrompt(pi, buildContinuationPrompt(goal));\n\t\t}\n\t});\n\n\tpi.on(\"agent_start\", async (_event, ctx) => {\n\t\tagentTurnInProgress = true;\n\t\tcompletedThisTurnGoalId = null;\n\t\tturnUsage.reset();\n\t\tconst goal = await readGoal(goalStoreRef(ctx));\n\t\tif (goal?.status === \"active\") {\n\t\t\tbeginAgentGoalAccounting(goal);\n\t\t} else {\n\t\t\tagentGoalAccounting = null;\n\t\t}\n\t});\n\n\tpi.on(\"message_end\", async (event) => {\n\t\tturnUsage.noteMessageEnd(event.message);\n\t});\n\n\tpi.on(\"agent_end\", async (event, ctx) => {\n\t\tconst mode: GoalAccountingMode = completedThisTurnGoalId === null ? \"active\" : \"activeOrComplete\";\n\t\tconst goal = await accountCurrentAgentTurn(ctx, mode, event.messages);\n\t\tagentTurnInProgress = false;\n\t\tcompletedThisTurnGoalId = null;\n\t\tif (goal?.status === \"active\") {\n\t\t\tbeginAgentGoalAccounting(goal);\n\t\t} else {\n\t\t\tclearAgentGoalAccounting();\n\t\t}\n\t\trefreshGoalUiBestEffort(ctx, goal);\n\t\tif (\n\t\t\tgoal?.status === \"active\" &&\n\t\t\t!ctx.signal?.aborted &&\n\t\t\tshouldQueueGoalContinuationAfterAgentEnd(goal, ctx.hasPendingMessages(), event.messages)\n\t\t) {\n\t\t\tqueueHiddenGoalPrompt(pi, buildContinuationPrompt(goal));\n\t\t}\n\t});\n\n\tpi.on(\"session_shutdown\", async (_event, ctx) => {\n\t\tif (agentGoalAccounting !== null) {\n\t\t\tawait accountCurrentAgentTurn(ctx, \"active\");\n\t\t}\n\t\tclearAgentGoalAccounting();\n\t\tgoalTicker.stop();\n\t});\n\n\tasync function maybePromptResumePausedGoal(\n\t\tpi: ExtensionAPI,\n\t\tctx: ExtensionContext,\n\t\tsessionStartReason: string,\n\t\tgoal: Goal | null,\n\t): Promise<boolean> {\n\t\tif (!isResumeOfPausedGoal(ctx, sessionStartReason, goal)) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst choice = await ctx.ui.select(`Resume paused goal?\\nGoal: ${goal.objective}`, [\n\t\t\tRESUME_GOAL_CHOICE,\n\t\t\tLEAVE_GOAL_PAUSED_CHOICE,\n\t\t]);\n\t\tif (choice !== RESUME_GOAL_CHOICE) return true;\n\n\t\tconst resumed = await updateGoal(goalStoreRef(ctx), { status: \"active\" });\n\t\tbeginAgentGoalAccounting(resumed);\n\t\trefreshGoalUi(ctx, resumed);\n\t\tctx.ui.notify(`Goal ${goalStatusLabel(resumed.status)}\\n${formatGoalForTool(resumed)}`, \"info\");\n\t\tqueueGoalContinuation(pi, ctx, resumed);\n\t\treturn true;\n\t}\n\n\tfunction beginAgentGoalAccounting(goal: Goal): void {\n\t\tif (goal.status !== \"active\") return;\n\t\tif (agentGoalAccounting?.goalId === goal.id) return;\n\t\tturnUsage.discardPending();\n\t\tagentGoalAccounting = { goalId: goal.id, measuredFromMilliseconds: Date.now() };\n\t}\n\n\tfunction markGoalCompletedThisTurn(goal: Goal): void {\n\t\tif (!agentTurnInProgress) return;\n\t\tcompletedThisTurnGoalId = goal.id;\n\t\tagentGoalAccounting = { goalId: goal.id, measuredFromMilliseconds: Date.now() };\n\t}\n\n\tfunction stopAgentGoalAccounting(goalId: string): void {\n\t\tif (agentGoalAccounting?.goalId === goalId) {\n\t\t\tagentGoalAccounting = null;\n\t\t}\n\t\tif (completedThisTurnGoalId === goalId) {\n\t\t\tcompletedThisTurnGoalId = null;\n\t\t}\n\t}\n\n\tfunction clearAgentGoalAccounting(): void {\n\t\tagentGoalAccounting = null;\n\t\tcompletedThisTurnGoalId = null;\n\t}\n\n\tfunction refreshGoalUi(ctx: ExtensionContext, goal: Goal | null): void {\n\t\tconst accounting = agentGoalAccounting;\n\t\tif (ctx.hasUI && goal?.status === \"active\" && accounting?.goalId === goal.id) {\n\t\t\tgoalTicker.sync(ctx, goal, accounting.measuredFromMilliseconds);\n\t\t\treturn;\n\t\t}\n\t\tgoalTicker.stop();\n\t\tupdateGoalUi(ctx, goal);\n\t}\n\n\tfunction refreshGoalUiBestEffort(ctx: ExtensionContext, goal: Goal | null): void {\n\t\ttry {\n\t\t\trefreshGoalUi(ctx, goal);\n\t\t} catch (error) {\n\t\t\tif (error instanceof Error && error.message.startsWith(STALE_EXTENSION_CONTEXT_ERROR_PREFIX)) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\tasync function accountCurrentAgentTurn(\n\t\tctx: ExtensionContext,\n\t\tmode: GoalAccountingMode,\n\t\tagentRunMessages?: unknown[],\n\t): Promise<Goal | null> {\n\t\tconst accounting = agentGoalAccounting;\n\t\tconst ref = goalStoreRef(ctx);\n\t\tif (accounting === null) return readGoal(ref);\n\n\t\tconst usage =\n\t\t\tagentRunMessages === undefined ? turnUsage.takePending() : turnUsage.takeRemaining(agentRunMessages);\n\t\tconst now = Date.now();\n\t\tconst elapsedSeconds = Math.max(0, Math.round((now - accounting.measuredFromMilliseconds) / 1000));\n\t\tconst goal = await accountGoalUsage(ref, usage, elapsedSeconds, mode, accounting.goalId);\n\t\tif (goal?.id === accounting.goalId) {\n\t\t\tagentGoalAccounting = { goalId: accounting.goalId, measuredFromMilliseconds: now };\n\t\t} else {\n\t\t\tclearAgentGoalAccounting();\n\t\t}\n\t\treturn goal;\n\t}\n}\n\nfunction isResumeOfPausedGoal(ctx: ExtensionContext, sessionStartReason: string, goal: Goal | null): goal is Goal {\n\treturn (\n\t\tsessionStartReason === \"resume\" &&\n\t\tgoal?.status === \"paused\" &&\n\t\tctx.hasUI &&\n\t\tctx.isIdle() &&\n\t\t!ctx.hasPendingMessages()\n\t);\n}\n\nfunction queueGoalContinuation(pi: ExtensionAPI, ctx: ExtensionContext, goal: Goal): void {\n\tif (shouldQueueGoalContinuationWhenIdle(goal, ctx.isIdle(), ctx.hasPendingMessages())) {\n\t\tqueueHiddenGoalPrompt(pi, buildContinuationPrompt(goal));\n\t}\n}\n\nfunction queueHiddenGoalPrompt(pi: ExtensionAPI, content: string): void {\n\tpi.sendMessage(\n\t\t{ customType: GOAL_CONTINUATION_MESSAGE_TYPE, content, display: false },\n\t\t{ triggerTurn: true, deliverAs: \"followUp\" },\n\t);\n}\n\nfunction goalStoreRef(ctx: ExtensionContext): GoalStoreRef {\n\tconst sessionFile = ctx.sessionManager.getSessionFile();\n\tconst baseDir =\n\t\tsessionFile === undefined\n\t\t\t? join(getAgentDir(), \"extensions\", \"goal\", \"no-session\", cwdStoreKey(ctx.cwd))\n\t\t\t: join(ctx.sessionManager.getSessionDir(), \"extensions\", \"goal\");\n\n\treturn {\n\t\tbaseDir,\n\t\tthreadId: ctx.sessionManager.getSessionId(),\n\t};\n}\n\nfunction cwdStoreKey(cwd: string): string {\n\treturn createHash(\"sha256\").update(cwd).digest(\"hex\").slice(0, 24);\n}\n"]}
@@ -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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ionContext } 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,IA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AAC;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,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,CA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CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,SAAS,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;YACvE,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,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