@namzu/sdk 72.0.0 → 74.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (394) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/README.md +34 -34
  3. package/dist/agents/examples/SupervisorAgent.d.ts.map +1 -1
  4. package/dist/agents/examples/SupervisorAgent.js +5 -0
  5. package/dist/agents/examples/SupervisorAgent.js.map +1 -1
  6. package/dist/authorization/protected-paths.d.ts +7 -0
  7. package/dist/authorization/protected-paths.d.ts.map +1 -1
  8. package/dist/authorization/protected-paths.js +11 -0
  9. package/dist/authorization/protected-paths.js.map +1 -1
  10. package/dist/authorization/readonly-commands.d.ts +23 -0
  11. package/dist/authorization/readonly-commands.d.ts.map +1 -1
  12. package/dist/authorization/readonly-commands.js +89 -3
  13. package/dist/authorization/readonly-commands.js.map +1 -1
  14. package/dist/authorization/shell-paths.d.ts +8 -0
  15. package/dist/authorization/shell-paths.d.ts.map +1 -1
  16. package/dist/authorization/shell-paths.js +125 -2
  17. package/dist/authorization/shell-paths.js.map +1 -1
  18. package/dist/bridge/acp/permission.d.ts +6 -0
  19. package/dist/bridge/acp/permission.d.ts.map +1 -1
  20. package/dist/bridge/acp/permission.js.map +1 -1
  21. package/dist/bridge/acp/server.d.ts.map +1 -1
  22. package/dist/bridge/acp/server.js +21 -3
  23. package/dist/bridge/acp/server.js.map +1 -1
  24. package/dist/compaction/context-window.d.ts.map +1 -1
  25. package/dist/compaction/context-window.js +11 -0
  26. package/dist/compaction/context-window.js.map +1 -1
  27. package/dist/compaction/manual.d.ts +16 -1
  28. package/dist/compaction/manual.d.ts.map +1 -1
  29. package/dist/compaction/manual.js +75 -13
  30. package/dist/compaction/manual.js.map +1 -1
  31. package/dist/compaction/plan.d.ts +2 -1
  32. package/dist/compaction/plan.d.ts.map +1 -1
  33. package/dist/compaction/plan.js +6 -5
  34. package/dist/compaction/plan.js.map +1 -1
  35. package/dist/compaction/precompute.d.ts +179 -0
  36. package/dist/compaction/precompute.d.ts.map +1 -0
  37. package/dist/compaction/precompute.js +274 -0
  38. package/dist/compaction/precompute.js.map +1 -0
  39. package/dist/compaction/retained-images.d.ts +16 -0
  40. package/dist/compaction/retained-images.d.ts.map +1 -0
  41. package/dist/compaction/retained-images.js +113 -0
  42. package/dist/compaction/retained-images.js.map +1 -0
  43. package/dist/compaction/token-estimate.d.ts +8 -3
  44. package/dist/compaction/token-estimate.d.ts.map +1 -1
  45. package/dist/compaction/token-estimate.js +76 -8
  46. package/dist/compaction/token-estimate.js.map +1 -1
  47. package/dist/compaction/tool-result-editing.d.ts.map +1 -1
  48. package/dist/compaction/tool-result-editing.js +15 -8
  49. package/dist/compaction/tool-result-editing.js.map +1 -1
  50. package/dist/config/runtime.d.ts +4 -0
  51. package/dist/config/runtime.d.ts.map +1 -1
  52. package/dist/config/runtime.js +17 -0
  53. package/dist/config/runtime.js.map +1 -1
  54. package/dist/constants/acp/index.d.ts +2 -0
  55. package/dist/constants/acp/index.d.ts.map +1 -1
  56. package/dist/constants/acp/index.js +2 -0
  57. package/dist/constants/acp/index.js.map +1 -1
  58. package/dist/manager/agent/lifecycle.d.ts.map +1 -1
  59. package/dist/manager/agent/lifecycle.js +8 -0
  60. package/dist/manager/agent/lifecycle.js.map +1 -1
  61. package/dist/manager/session/turn-recorder.d.ts +26 -0
  62. package/dist/manager/session/turn-recorder.d.ts.map +1 -1
  63. package/dist/manager/session/turn-recorder.js +72 -5
  64. package/dist/manager/session/turn-recorder.js.map +1 -1
  65. package/dist/peers/protocol.d.ts +9 -0
  66. package/dist/peers/protocol.d.ts.map +1 -1
  67. package/dist/peers/protocol.js +4 -0
  68. package/dist/peers/protocol.js.map +1 -1
  69. package/dist/peers/record.d.ts +6 -0
  70. package/dist/peers/record.d.ts.map +1 -1
  71. package/dist/peers/record.js +4 -0
  72. package/dist/peers/record.js.map +1 -1
  73. package/dist/plugin/index.d.ts +2 -2
  74. package/dist/plugin/index.d.ts.map +1 -1
  75. package/dist/plugin/index.js +1 -1
  76. package/dist/plugin/index.js.map +1 -1
  77. package/dist/plugin/shell-hook.d.ts +30 -0
  78. package/dist/plugin/shell-hook.d.ts.map +1 -1
  79. package/dist/plugin/shell-hook.js +35 -0
  80. package/dist/plugin/shell-hook.js.map +1 -1
  81. package/dist/pricing/catalogue.generated.d.ts.map +1 -1
  82. package/dist/pricing/catalogue.generated.js +178 -1
  83. package/dist/pricing/catalogue.generated.js.map +1 -1
  84. package/dist/provider/attribution.js +1 -1
  85. package/dist/provider/attribution.js.map +1 -1
  86. package/dist/public-runtime.d.ts +9 -5
  87. package/dist/public-runtime.d.ts.map +1 -1
  88. package/dist/public-runtime.js +12 -4
  89. package/dist/public-runtime.js.map +1 -1
  90. package/dist/public-tools.d.ts +1 -1
  91. package/dist/public-tools.d.ts.map +1 -1
  92. package/dist/public-tools.js +1 -1
  93. package/dist/public-tools.js.map +1 -1
  94. package/dist/public-types.d.ts +3 -2
  95. package/dist/public-types.d.ts.map +1 -1
  96. package/dist/rag/embedding.d.ts +5 -1
  97. package/dist/rag/embedding.d.ts.map +1 -1
  98. package/dist/rag/embedding.js +22 -7
  99. package/dist/rag/embedding.js.map +1 -1
  100. package/dist/registry/command/kernel-commands.d.ts +7 -1
  101. package/dist/registry/command/kernel-commands.d.ts.map +1 -1
  102. package/dist/registry/command/kernel-commands.js +40 -2
  103. package/dist/registry/command/kernel-commands.js.map +1 -1
  104. package/dist/registry/tool/execute.d.ts +8 -0
  105. package/dist/registry/tool/execute.d.ts.map +1 -1
  106. package/dist/registry/tool/execute.js +12 -0
  107. package/dist/registry/tool/execute.js.map +1 -1
  108. package/dist/runtime/query/abandon-turn.d.ts.map +1 -1
  109. package/dist/runtime/query/abandon-turn.js +9 -0
  110. package/dist/runtime/query/abandon-turn.js.map +1 -1
  111. package/dist/runtime/query/budget-nudge.d.ts +27 -0
  112. package/dist/runtime/query/budget-nudge.d.ts.map +1 -0
  113. package/dist/runtime/query/budget-nudge.js +66 -0
  114. package/dist/runtime/query/budget-nudge.js.map +1 -0
  115. package/dist/runtime/query/compact-session.d.ts +19 -3
  116. package/dist/runtime/query/compact-session.d.ts.map +1 -1
  117. package/dist/runtime/query/compact-session.js +180 -93
  118. package/dist/runtime/query/compact-session.js.map +1 -1
  119. package/dist/runtime/query/guard.d.ts +8 -0
  120. package/dist/runtime/query/guard.d.ts.map +1 -1
  121. package/dist/runtime/query/guard.js +20 -0
  122. package/dist/runtime/query/guard.js.map +1 -1
  123. package/dist/runtime/query/index.d.ts.map +1 -1
  124. package/dist/runtime/query/index.js +1 -0
  125. package/dist/runtime/query/index.js.map +1 -1
  126. package/dist/runtime/query/iteration/index.d.ts +2 -0
  127. package/dist/runtime/query/iteration/index.d.ts.map +1 -1
  128. package/dist/runtime/query/iteration/index.js +41 -1
  129. package/dist/runtime/query/iteration/index.js.map +1 -1
  130. package/dist/runtime/query/iteration/phases/compaction.d.ts +1 -0
  131. package/dist/runtime/query/iteration/phases/compaction.d.ts.map +1 -1
  132. package/dist/runtime/query/iteration/phases/compaction.js +203 -45
  133. package/dist/runtime/query/iteration/phases/compaction.js.map +1 -1
  134. package/dist/runtime/query/iteration/phases/context.d.ts +2 -0
  135. package/dist/runtime/query/iteration/phases/context.d.ts.map +1 -1
  136. package/dist/runtime/query/iteration/phases/context.js +1 -0
  137. package/dist/runtime/query/iteration/phases/context.js.map +1 -1
  138. package/dist/runtime/query/iteration/phases/precompute.d.ts +60 -0
  139. package/dist/runtime/query/iteration/phases/precompute.d.ts.map +1 -0
  140. package/dist/runtime/query/iteration/phases/precompute.js +240 -0
  141. package/dist/runtime/query/iteration/phases/precompute.js.map +1 -0
  142. package/dist/runtime/query/iteration/request-prefix.d.ts +21 -0
  143. package/dist/runtime/query/iteration/request-prefix.d.ts.map +1 -0
  144. package/dist/runtime/query/iteration/request-prefix.js +111 -0
  145. package/dist/runtime/query/iteration/request-prefix.js.map +1 -0
  146. package/dist/runtime/query/review-policy.d.ts +11 -3
  147. package/dist/runtime/query/review-policy.d.ts.map +1 -1
  148. package/dist/runtime/query/review-policy.js +54 -3
  149. package/dist/runtime/query/review-policy.js.map +1 -1
  150. package/dist/runtime/query/turn/outcome-ledger.d.ts +14 -0
  151. package/dist/runtime/query/turn/outcome-ledger.d.ts.map +1 -1
  152. package/dist/runtime/query/turn/outcome-ledger.js +28 -0
  153. package/dist/runtime/query/turn/outcome-ledger.js.map +1 -1
  154. package/dist/sandbox/exec-stdin.d.ts +21 -0
  155. package/dist/sandbox/exec-stdin.d.ts.map +1 -0
  156. package/dist/sandbox/exec-stdin.js +40 -0
  157. package/dist/sandbox/exec-stdin.js.map +1 -0
  158. package/dist/sandbox/file-walk.d.ts +12 -7
  159. package/dist/sandbox/file-walk.d.ts.map +1 -1
  160. package/dist/sandbox/file-walk.js +13 -4
  161. package/dist/sandbox/file-walk.js.map +1 -1
  162. package/dist/sandbox/ignore-matcher.d.ts +1 -0
  163. package/dist/sandbox/ignore-matcher.d.ts.map +1 -1
  164. package/dist/sandbox/ignore-matcher.js.map +1 -1
  165. package/dist/sandbox/ignore-source.js +1 -1
  166. package/dist/sandbox/index.d.ts +3 -2
  167. package/dist/sandbox/index.d.ts.map +1 -1
  168. package/dist/sandbox/index.js +2 -1
  169. package/dist/sandbox/index.js.map +1 -1
  170. package/dist/sandbox/provider/local.d.ts.map +1 -1
  171. package/dist/sandbox/provider/local.js +2 -0
  172. package/dist/sandbox/provider/local.js.map +1 -1
  173. package/dist/session/paths.d.ts +6 -0
  174. package/dist/session/paths.d.ts.map +1 -1
  175. package/dist/session/paths.js +7 -0
  176. package/dist/session/paths.js.map +1 -1
  177. package/dist/session-query/index.d.ts +1 -0
  178. package/dist/session-query/index.d.ts.map +1 -1
  179. package/dist/session-query/index.js +26 -15
  180. package/dist/session-query/index.js.map +1 -1
  181. package/dist/store/evidence/disk.js +3 -1
  182. package/dist/store/evidence/disk.js.map +1 -1
  183. package/dist/store/evidence/index-page.d.ts +1 -0
  184. package/dist/store/evidence/index-page.d.ts.map +1 -1
  185. package/dist/store/evidence/index-page.js +8 -0
  186. package/dist/store/evidence/index-page.js.map +1 -1
  187. package/dist/store/goal/gates.d.ts +53 -0
  188. package/dist/store/goal/gates.d.ts.map +1 -0
  189. package/dist/store/goal/gates.js +664 -0
  190. package/dist/store/goal/gates.js.map +1 -0
  191. package/dist/store/goal/index.d.ts +16 -1
  192. package/dist/store/goal/index.d.ts.map +1 -1
  193. package/dist/store/goal/index.js +74 -0
  194. package/dist/store/goal/index.js.map +1 -1
  195. package/dist/store/memory/operation-lock.d.ts.map +1 -1
  196. package/dist/store/memory/operation-lock.js +15 -1
  197. package/dist/store/memory/operation-lock.js.map +1 -1
  198. package/dist/store/session-log/core.d.ts.map +1 -1
  199. package/dist/store/session-log/core.js +23 -0
  200. package/dist/store/session-log/core.js.map +1 -1
  201. package/dist/tools/builtins/bash.js +1 -1
  202. package/dist/tools/builtins/bash.js.map +1 -1
  203. package/dist/tools/builtins/browser.d.ts.map +1 -1
  204. package/dist/tools/builtins/browser.js +2 -0
  205. package/dist/tools/builtins/browser.js.map +1 -1
  206. package/dist/tools/builtins/computer-use-image.d.ts +9 -0
  207. package/dist/tools/builtins/computer-use-image.d.ts.map +1 -1
  208. package/dist/tools/builtins/computer-use-image.js +21 -0
  209. package/dist/tools/builtins/computer-use-image.js.map +1 -1
  210. package/dist/tools/builtins/computer-use.d.ts +1 -9
  211. package/dist/tools/builtins/computer-use.d.ts.map +1 -1
  212. package/dist/tools/builtins/computer-use.js +2 -22
  213. package/dist/tools/builtins/computer-use.js.map +1 -1
  214. package/dist/tools/builtins/monitor.d.ts.map +1 -1
  215. package/dist/tools/builtins/monitor.js +1 -0
  216. package/dist/tools/builtins/monitor.js.map +1 -1
  217. package/dist/tools/builtins/search-tools.js +2 -2
  218. package/dist/tools/builtins/search-tools.js.map +1 -1
  219. package/dist/tools/builtins/sleep-guard.js +1 -1
  220. package/dist/tools/builtins/sleep-guard.js.map +1 -1
  221. package/dist/tools/builtins/wait-for-job.js +1 -1
  222. package/dist/tools/builtins/wait-for-job.js.map +1 -1
  223. package/dist/tools/coordinator/ask-user-question.d.ts.map +1 -1
  224. package/dist/tools/coordinator/ask-user-question.js +25 -0
  225. package/dist/tools/coordinator/ask-user-question.js.map +1 -1
  226. package/dist/tools/coordinator/index.d.ts.map +1 -1
  227. package/dist/tools/coordinator/index.js +3 -0
  228. package/dist/tools/coordinator/index.js.map +1 -1
  229. package/dist/tools/defineTool.d.ts +2 -0
  230. package/dist/tools/defineTool.d.ts.map +1 -1
  231. package/dist/tools/defineTool.js +3 -0
  232. package/dist/tools/defineTool.js.map +1 -1
  233. package/dist/tools/goal/confirmation.d.ts +40 -2
  234. package/dist/tools/goal/confirmation.d.ts.map +1 -1
  235. package/dist/tools/goal/confirmation.js +117 -0
  236. package/dist/tools/goal/confirmation.js.map +1 -1
  237. package/dist/tools/goal/index.d.ts.map +1 -1
  238. package/dist/tools/goal/index.js +14 -2
  239. package/dist/tools/goal/index.js.map +1 -1
  240. package/dist/tools/memory/save.d.ts.map +1 -1
  241. package/dist/tools/memory/save.js +1 -0
  242. package/dist/tools/memory/save.js.map +1 -1
  243. package/dist/tools/schedules/index.d.ts +1 -0
  244. package/dist/tools/schedules/index.d.ts.map +1 -1
  245. package/dist/tools/schedules/index.js +1 -0
  246. package/dist/tools/schedules/index.js.map +1 -1
  247. package/dist/tools/schedules/loop-tool.d.ts.map +1 -1
  248. package/dist/tools/schedules/loop-tool.js +1 -0
  249. package/dist/tools/schedules/loop-tool.js.map +1 -1
  250. package/dist/tools/schedules/present.d.ts.map +1 -1
  251. package/dist/tools/schedules/present.js +2 -0
  252. package/dist/tools/schedules/present.js.map +1 -1
  253. package/dist/tools/schedules/schedule-tool.d.ts.map +1 -1
  254. package/dist/tools/schedules/schedule-tool.js +79 -9
  255. package/dist/tools/schedules/schedule-tool.js.map +1 -1
  256. package/dist/tools/schedules/self-tool.d.ts +16 -0
  257. package/dist/tools/schedules/self-tool.d.ts.map +1 -0
  258. package/dist/tools/schedules/self-tool.js +140 -0
  259. package/dist/tools/schedules/self-tool.js.map +1 -0
  260. package/dist/tools/schedules/timer-tools.d.ts.map +1 -1
  261. package/dist/tools/schedules/timer-tools.js +1 -0
  262. package/dist/tools/schedules/timer-tools.js.map +1 -1
  263. package/dist/tools/schedules/types.d.ts +63 -0
  264. package/dist/tools/schedules/types.d.ts.map +1 -1
  265. package/dist/toolsets/manager.d.ts +14 -0
  266. package/dist/toolsets/manager.d.ts.map +1 -1
  267. package/dist/toolsets/manager.js +60 -7
  268. package/dist/toolsets/manager.js.map +1 -1
  269. package/dist/types/agent/supervisor.d.ts +10 -0
  270. package/dist/types/agent/supervisor.d.ts.map +1 -1
  271. package/dist/types/agent/task.d.ts +6 -0
  272. package/dist/types/agent/task.d.ts.map +1 -1
  273. package/dist/types/common/index.d.ts +20 -0
  274. package/dist/types/common/index.d.ts.map +1 -1
  275. package/dist/types/common/index.js +4 -1
  276. package/dist/types/common/index.js.map +1 -1
  277. package/dist/types/goal/index.d.ts +66 -0
  278. package/dist/types/goal/index.d.ts.map +1 -1
  279. package/dist/types/hitl/index.d.ts +11 -0
  280. package/dist/types/hitl/index.d.ts.map +1 -1
  281. package/dist/types/hitl/index.js.map +1 -1
  282. package/dist/types/rag/embedding.d.ts +4 -0
  283. package/dist/types/rag/embedding.d.ts.map +1 -1
  284. package/dist/types/sandbox/index.d.ts +19 -0
  285. package/dist/types/sandbox/index.d.ts.map +1 -1
  286. package/dist/types/sandbox/index.js.map +1 -1
  287. package/dist/types/session/events.d.ts +55 -0
  288. package/dist/types/session/events.d.ts.map +1 -1
  289. package/dist/types/session/events.js.map +1 -1
  290. package/dist/types/session/outcome.d.ts +12 -0
  291. package/dist/types/session/outcome.d.ts.map +1 -1
  292. package/dist/types/session/outcome.js.map +1 -1
  293. package/dist/types/session/records.d.ts +81 -1
  294. package/dist/types/session/records.d.ts.map +1 -1
  295. package/dist/types/session/records.js +33 -0
  296. package/dist/types/session/records.js.map +1 -1
  297. package/dist/types/tool/index.d.ts +7 -0
  298. package/dist/types/tool/index.d.ts.map +1 -1
  299. package/dist/types/tool/index.js.map +1 -1
  300. package/dist/utils/cost.d.ts +15 -0
  301. package/dist/utils/cost.d.ts.map +1 -1
  302. package/dist/utils/cost.js +24 -1
  303. package/dist/utils/cost.js.map +1 -1
  304. package/package.json +2 -2
  305. package/src/agents/examples/SupervisorAgent.ts +5 -0
  306. package/src/authorization/protected-paths.ts +11 -0
  307. package/src/authorization/readonly-commands.ts +85 -3
  308. package/src/authorization/shell-paths.ts +141 -3
  309. package/src/bridge/acp/permission.ts +6 -0
  310. package/src/bridge/acp/server.ts +20 -1
  311. package/src/compaction/context-window.ts +11 -0
  312. package/src/compaction/manual.ts +103 -17
  313. package/src/compaction/plan.ts +11 -5
  314. package/src/compaction/precompute.ts +390 -0
  315. package/src/compaction/retained-images.ts +130 -0
  316. package/src/compaction/token-estimate.ts +86 -8
  317. package/src/compaction/tool-result-editing.ts +20 -8
  318. package/src/config/runtime.ts +17 -0
  319. package/src/constants/acp/index.ts +2 -0
  320. package/src/manager/agent/lifecycle.ts +9 -0
  321. package/src/manager/session/turn-recorder.ts +92 -5
  322. package/src/peers/protocol.ts +4 -0
  323. package/src/peers/record.ts +4 -0
  324. package/src/plugin/index.ts +2 -0
  325. package/src/plugin/shell-hook.ts +60 -0
  326. package/src/pricing/catalogue.generated.ts +178 -1
  327. package/src/pricing/rates.source.json +155 -2
  328. package/src/provider/attribution.ts +1 -1
  329. package/src/public-runtime.ts +48 -0
  330. package/src/public-tools.ts +2 -0
  331. package/src/public-types.ts +8 -0
  332. package/src/rag/embedding.ts +23 -7
  333. package/src/registry/command/kernel-commands.ts +62 -3
  334. package/src/registry/tool/execute.ts +14 -0
  335. package/src/runtime/query/abandon-turn.ts +9 -0
  336. package/src/runtime/query/budget-nudge.ts +92 -0
  337. package/src/runtime/query/compact-session.ts +242 -87
  338. package/src/runtime/query/guard.ts +22 -0
  339. package/src/runtime/query/index.ts +1 -0
  340. package/src/runtime/query/iteration/index.ts +40 -1
  341. package/src/runtime/query/iteration/phases/compaction.ts +224 -46
  342. package/src/runtime/query/iteration/phases/context.ts +3 -0
  343. package/src/runtime/query/iteration/phases/precompute.ts +277 -0
  344. package/src/runtime/query/iteration/request-prefix.ts +161 -0
  345. package/src/runtime/query/review-policy.ts +79 -11
  346. package/src/runtime/query/turn/outcome-ledger.ts +34 -0
  347. package/src/sandbox/exec-stdin.ts +54 -0
  348. package/src/sandbox/file-walk.ts +25 -18
  349. package/src/sandbox/ignore-matcher.ts +1 -0
  350. package/src/sandbox/ignore-source.ts +1 -1
  351. package/src/sandbox/index.ts +8 -2
  352. package/src/sandbox/provider/local.ts +2 -0
  353. package/src/session/paths.ts +9 -0
  354. package/src/session-query/index.ts +23 -14
  355. package/src/store/evidence/disk.ts +3 -1
  356. package/src/store/evidence/index-page.ts +11 -0
  357. package/src/store/goal/gates.ts +738 -0
  358. package/src/store/goal/index.ts +109 -0
  359. package/src/store/memory/operation-lock.ts +19 -1
  360. package/src/store/session-log/core.ts +26 -0
  361. package/src/tools/builtins/bash.ts +1 -1
  362. package/src/tools/builtins/browser.ts +4 -0
  363. package/src/tools/builtins/computer-use-image.ts +20 -0
  364. package/src/tools/builtins/computer-use.ts +1 -20
  365. package/src/tools/builtins/monitor.ts +2 -0
  366. package/src/tools/builtins/search-tools.ts +2 -2
  367. package/src/tools/builtins/sleep-guard.ts +1 -1
  368. package/src/tools/builtins/wait-for-job.ts +1 -1
  369. package/src/tools/coordinator/ask-user-question.ts +37 -10
  370. package/src/tools/coordinator/index.ts +3 -0
  371. package/src/tools/defineTool.ts +5 -0
  372. package/src/tools/goal/confirmation.ts +171 -3
  373. package/src/tools/goal/index.ts +15 -3
  374. package/src/tools/memory/save.ts +2 -0
  375. package/src/tools/schedules/index.ts +1 -0
  376. package/src/tools/schedules/loop-tool.ts +2 -0
  377. package/src/tools/schedules/present.ts +2 -0
  378. package/src/tools/schedules/schedule-tool.ts +84 -9
  379. package/src/tools/schedules/self-tool.ts +152 -0
  380. package/src/tools/schedules/timer-tools.ts +2 -0
  381. package/src/tools/schedules/types.ts +62 -0
  382. package/src/toolsets/manager.ts +59 -8
  383. package/src/types/agent/supervisor.ts +11 -0
  384. package/src/types/agent/task.ts +7 -0
  385. package/src/types/common/index.ts +26 -1
  386. package/src/types/goal/index.ts +72 -0
  387. package/src/types/hitl/index.ts +11 -0
  388. package/src/types/rag/embedding.ts +7 -0
  389. package/src/types/sandbox/index.ts +19 -0
  390. package/src/types/session/events.ts +56 -0
  391. package/src/types/session/outcome.ts +16 -1
  392. package/src/types/session/records.ts +41 -0
  393. package/src/types/tool/index.ts +7 -0
  394. package/src/utils/cost.ts +44 -1
@@ -2,7 +2,7 @@ import { SpanStatusCode, context as otelContext, trace } from '@opentelemetry/ap
2
2
  import { isCompactionMessage } from '../compaction/summary.js'
3
3
  import { assertStrictSchema } from '../provider/strict-schema.js'
4
4
  import { callableToolNames, formatToolNames } from '../registry/tool/callable.js'
5
- import { assertToolName, describeWithOutput, toolDiscoveryHint } from '../registry/tool/execute.js'
5
+ import { assertToolName, describeWithOutput, toolCatalogueHint } from '../registry/tool/execute.js'
6
6
  import { renderToolSchema, toolWireSchema } from '../registry/tool/schema.js'
7
7
  import { ToolResultHalted, screenToolResult } from '../registry/tool/screen.js'
8
8
  import { GENAI, NAMZU, toolSpanName } from '../telemetry/attributes.js'
@@ -416,9 +416,7 @@ export class ToolManager {
416
416
  const entries = deferredNow.map((name) => {
417
417
  const tool = this.toolsByName.get(name)
418
418
  const hint =
419
- !tool || this.sourceKindOf(name) === 'mcp_server'
420
- ? ''
421
- : toolDiscoveryHint(tool.description)
419
+ !tool || this.sourceKindOf(name) === 'mcp_server' ? '' : toolCatalogueHint(tool)
422
420
  return hint.length > 0 ? `- ${name}: ${hint}` : `- ${name}`
423
421
  })
424
422
  const { shown, more } = capEntries(entries)
@@ -535,7 +533,61 @@ export class ToolManager {
535
533
  const candidates = filter
536
534
  ? filter.map((name) => this.getOrThrow(name))
537
535
  : [...this.toolsByName.values()]
538
- return candidates.filter((tool) => states.includes(this.availability(tool.name)))
536
+ const picked = candidates.filter((tool) => states.includes(this.availability(tool.name)))
537
+ return states.includes('active') ? this.loadedLast(picked) : picked
538
+ }
539
+
540
+ /**
541
+ * Put the tools that were loaded on request after the ones that are loaded
542
+ * from the start, in the order they were loaded. A load then extends the
543
+ * tools array of the previous request instead of reshaping it, so the tools
544
+ * the request already had keep their place. It is still a change to the
545
+ * tools block, which a provider reads before the system prompt and the
546
+ * messages: the request that carries a new tool re-reads those once, and
547
+ * only the unchanged start of the tools block is kept. The order comes
548
+ * from the receipts in the history, so a compaction or a resume gives the
549
+ * same one.
550
+ */
551
+ private loadedLast(tools: ToolDefinition[]): ToolDefinition[] {
552
+ const order = this.revealOrder()
553
+ if (order.size === 0) return tools
554
+ const fixed: ToolDefinition[] = []
555
+ const loaded: { tool: ToolDefinition; at: number }[] = []
556
+ for (const tool of tools) {
557
+ const at =
558
+ (this.defaultAvailabilityByName.get(tool.name) ?? 'active') === 'active'
559
+ ? undefined
560
+ : order.get(tool.name)
561
+ if (at === undefined) fixed.push(tool)
562
+ else loaded.push({ tool, at })
563
+ }
564
+ if (loaded.length === 0) return tools
565
+ loaded.sort((a, b) => a.at - b.at)
566
+ return [...fixed, ...loaded.map((entry) => entry.tool)]
567
+ }
568
+
569
+ /** The position at which each loaded-on-request tool first appears in the history. */
570
+ private revealOrder(): Map<string, number> {
571
+ const order = new Map<string, number>()
572
+ const note = (receipts: readonly ToolRevealReceipt[] | undefined) => {
573
+ for (const receipt of receipts ?? []) {
574
+ if (order.has(receipt.name)) continue
575
+ const owner = this.ownerToolsetByName.get(receipt.name)
576
+ if (
577
+ !owner ||
578
+ receipt.sourceId !== owner.source.id ||
579
+ receipt.sourceKind !== owner.source.kind
580
+ )
581
+ continue
582
+ order.set(receipt.name, order.size)
583
+ }
584
+ }
585
+ const { summary, window } = postCompactionWindow(this.messagesAccessor())
586
+ note(summary?.revealedTools)
587
+ for (const message of window) {
588
+ if (message.role === 'tool' && !message.isError) note(message.revealedTools)
589
+ }
590
+ return order
539
591
  }
540
592
 
541
593
  // ---- Discovery ----------------------------------------------------------
@@ -737,8 +789,7 @@ Executable tool names, descriptions, and JSON input schemas are attached through
737
789
  // SYSTEM would promote that remote text to host instruction.
738
790
  // Keep the name discoverable here; put its hint in the
739
791
  // request-only, provenance-labelled context below.
740
- const hint =
741
- this.sourceOf(t.name)?.kind === 'mcp_server' ? '' : toolDiscoveryHint(t.description)
792
+ const hint = this.sourceOf(t.name)?.kind === 'mcp_server' ? '' : toolCatalogueHint(t)
742
793
  const base = hint.length > 0 ? `- ${t.name}: ${hint}` : `- ${t.name}`
743
794
  return t.loadsWith && t.loadsWith.length > 0
744
795
  ? `${base} (loads with ${t.loadsWith.join(', ')})`
@@ -772,7 +823,7 @@ Executable tool names, descriptions, and JSON input schemas are attached through
772
823
  const candidates = this.getByAvailability(['deferred'])
773
824
  .filter((tool) => this.sourceOf(tool.name)?.kind === 'mcp_server')
774
825
  .map((tool) => {
775
- const hint = toolDiscoveryHint(tool.description)
826
+ const hint = toolCatalogueHint(tool)
776
827
  return {
777
828
  name: tool.name,
778
829
  text: hint ? `- ${tool.name}: ${hint}` : `- ${tool.name}`,
@@ -1,4 +1,5 @@
1
1
  import type { CompactionConfig } from '../../config/runtime.js'
2
+ import type { QueryParams } from '../../runtime/query/index.js'
2
3
  import type { SteeringChannel } from '../../runtime/query/steering.js'
3
4
  import type { Toolset } from '../../toolsets/types.js'
4
5
  import type { AdvisoryConfig } from '../advisory/index.js'
@@ -49,6 +50,16 @@ export interface SupervisorAgentConfig extends BaseAgentConfig {
49
50
  */
50
51
  allowDelegation?: boolean
51
52
 
53
+ /**
54
+ * Host lifecycle hooks for this run. Forwarded to the query the supervisor
55
+ * drains, so its own tool calls and turns fire `pre_tool_use`,
56
+ * `post_tool_use`, `user_prompt_submit`, `turn_end` and the rest, and
57
+ * handed to every agent it spawns, so a child's turn and its `subagent_*`
58
+ * events fire them too. A child's own `configOverrides.pluginManager`
59
+ * wins. Absent, no hook runs, as before.
60
+ */
61
+ pluginManager?: QueryParams['pluginManager']
62
+
52
63
  scheduler?: TaskScheduler
53
64
 
54
65
  /**
@@ -137,6 +137,13 @@ export interface AgentTaskContext {
137
137
  */
138
138
  toolResultGuardrails?: readonly import('../guardrail/index.js').ToolResultGuardrailSpec[]
139
139
 
140
+ /**
141
+ * The parent's lifecycle hook manager, stamped onto the child config so a
142
+ * delegated turn fires the same registered hooks. A child's own
143
+ * `configOverrides.pluginManager` wins. Absent, the child runs no hooks.
144
+ */
145
+ pluginManager?: import('../../plugin/lifecycle.js').PluginLifecycleManager
146
+
140
147
  /**
141
148
  * The tool denies in force for the actor that owns this context — the
142
149
  * union of every `toolScope.deny` recorded along its actor chain.
@@ -107,6 +107,28 @@ export interface TokenUsage {
107
107
  * provider reported nothing, a pending answer, or a hit.
108
108
  */
109
109
  cacheMiss?: CacheMiss
110
+
111
+ /**
112
+ * The request shape the driver actually put on the wire for this call, when
113
+ * it can say: a driver that drops a field after the backend refused it
114
+ * reports what remained. Per call, never summed. Absent means the driver
115
+ * does not report it, not that nothing was sent.
116
+ */
117
+ requestShape?: RequestWireShape
118
+ }
119
+
120
+ /** What a driver sent for one call, as far as the prompt cache is concerned. See {@link TokenUsage.requestShape}. */
121
+ export interface RequestWireShape {
122
+ /** A cache key naming the conversation was sent. */
123
+ cacheKey: boolean
124
+ /** A session header naming the conversation was sent. */
125
+ sessionHeader: boolean
126
+ /**
127
+ * True while the backend's refusal of the `developer` role is in force for the driver
128
+ * (it is process-wide), so it is true on every request made under it, whether or not
129
+ * that request had guidance to send. Absent or false otherwise.
130
+ */
131
+ developerRefused?: boolean
110
132
  }
111
133
 
112
134
  /** A prompt-cache miss as the provider explains it. See {@link TokenUsage.cacheMiss}. */
@@ -147,7 +169,7 @@ export function accumulateTokenUsage(current: TokenUsage, addition: TokenUsage):
147
169
  ? { reportedCostUsd: (current.reportedCostUsd ?? 0) + (addition.reportedCostUsd ?? 0) }
148
170
  : {}),
149
171
  // `fullPromptTokens`, `cacheTtlMs`, `cacheWriteTtlTokens`, `speed`, `serviceTier`,
150
- // `inferenceGeo` and `cacheMiss` are per-call facts and are deliberately
172
+ // `inferenceGeo`, `cacheMiss` and `requestShape` are per-call facts and are deliberately
151
173
  // not carried into a sum.
152
174
  }
153
175
  }
@@ -212,6 +234,9 @@ export function mergeTokenUsage(current: TokenUsage, next: TokenUsage): TokenUsa
212
234
  ...(next.cacheMiss !== undefined || current.cacheMiss !== undefined
213
235
  ? { cacheMiss: next.cacheMiss ?? current.cacheMiss }
214
236
  : {}),
237
+ ...(next.requestShape !== undefined || current.requestShape !== undefined
238
+ ? { requestShape: next.requestShape ?? current.requestShape }
239
+ : {}),
215
240
  }
216
241
  }
217
242
 
@@ -73,6 +73,13 @@ export interface SessionGoal extends GoalRef {
73
73
  readonly wrapUpRound?: number
74
74
  /** What a check of the completion report found missing; leads the next round. */
75
75
  readonly missing?: readonly string[]
76
+ /**
77
+ * Commands the host runs at the end of each round; the goal completes only
78
+ * when every one of them passed on the files as they are. Fixed when the
79
+ * goal is created, so a settings file that changes later does not change a
80
+ * goal that is running. Absent: the goal has no gates.
81
+ */
82
+ readonly gates?: GoalGates
76
83
  readonly createdAt: number
77
84
  readonly updatedAt: number
78
85
  }
@@ -106,6 +113,69 @@ export interface GoalRoundOutcome {
106
113
  readonly missing?: readonly string[]
107
114
  }
108
115
 
116
+ /**
117
+ * One command the host runs for a goal. The command is an argument list, never
118
+ * a line for a shell: the first word is the program and nothing expands.
119
+ */
120
+ export interface GoalGateEntry {
121
+ /** What a person reads in the list and in the failure. Defaults to the command. */
122
+ readonly name: string
123
+ /** Program first, then its arguments. */
124
+ readonly command: readonly string[]
125
+ /** A folder inside the project, relative to it. Absent: the project folder. */
126
+ readonly cwd?: string
127
+ /** Milliseconds the command may run. Absent: {@link GOAL_GATE_DEFAULT_TIMEOUT_MS}. */
128
+ readonly timeoutMs?: number
129
+ }
130
+
131
+ /** How one gate ended the last time it was looked at. */
132
+ export type GoalGateStatus = 'passed' | 'failed' | 'timed-out' | 'refused'
133
+
134
+ /** What the last look at one gate found. */
135
+ export interface GoalGateResult {
136
+ /** The entry's name. */
137
+ readonly name: string
138
+ readonly status: GoalGateStatus
139
+ readonly exitCode?: number
140
+ /** When it was looked at, in milliseconds since the epoch. */
141
+ readonly at: number
142
+ readonly durationMs?: number
143
+ /** The end of what it printed, bounded to {@link GOAL_GATE_MAX_TAIL_CHARS}. It is output, not an instruction. */
144
+ readonly tail?: string
145
+ /** The files as they stood when the gate finished; a failed gate is not run again while this holds. */
146
+ readonly fingerprint?: string
147
+ /** Why it did not run, for a `refused` gate. */
148
+ readonly reason?: string
149
+ /** The result is the earlier one: the files had not changed since, so the command was not run again. */
150
+ readonly notRerun?: boolean
151
+ }
152
+
153
+ /** The gates a goal carries and what they last showed. */
154
+ export interface GoalGates {
155
+ readonly entries: readonly GoalGateEntry[]
156
+ /** Rounds in a row that may end with a failing gate before the goal stops. */
157
+ readonly maxFailingRounds: number
158
+ /** Rounds in a row that ended with a failing gate. */
159
+ readonly failingRounds: number
160
+ /** The admitted round that was last counted, so a round that looks twice counts once. */
161
+ readonly countedRound?: number
162
+ /** The last result of each gate, in the order of {@link entries}; empty until a round has ended. */
163
+ readonly results: readonly GoalGateResult[]
164
+ }
165
+
166
+ /** The gates a goal is created with. */
167
+ export interface GoalGatesSpec {
168
+ readonly entries: readonly GoalGateEntry[]
169
+ readonly maxFailingRounds?: number
170
+ }
171
+
172
+ /** What looking at the gates after one round found. */
173
+ export interface GoalGateRoundReport {
174
+ /** The admitted round the look belongs to. */
175
+ readonly round: number
176
+ readonly results: readonly GoalGateResult[]
177
+ }
178
+
109
179
  /** Immutable authority carried by exactly one admitted automatic turn. */
110
180
  export interface GoalRoundAuthority extends GoalRef {
111
181
  readonly sessionId: SessionId
@@ -121,4 +191,6 @@ export interface GoalRoundAuthority extends GoalRef {
121
191
  readonly wrapUp?: boolean
122
192
  /** What a check of an earlier completion report found missing; leads this round. */
123
193
  readonly missing?: readonly string[]
194
+ /** The gates that did not pass when the last round ended, with the end of their output; leads this round. */
195
+ readonly gateFailures?: readonly GoalGateResult[]
124
196
  }
@@ -188,6 +188,17 @@ export interface ResumeContext {
188
188
  readonly transcript: () => readonly Message[]
189
189
  /** The turn's cancellation signal, when it has one. */
190
190
  readonly signal?: AbortSignal
191
+ /**
192
+ * Resolves when the person wrote a message to this turn, and for no other
193
+ * reason; the supplied signal ends the wait and releases its listener. Present
194
+ * only when the host has a live message box for the turn.
195
+ *
196
+ * A handler that puts a question to a person reads it: a message that arrives
197
+ * while the question is open (or was already waiting when it would be asked)
198
+ * closes the question, so the turn never carries on beside a request nobody
199
+ * will answer. The message itself is delivered in the turn's usual way.
200
+ */
201
+ readonly waitForOperator?: (signal: AbortSignal) => Promise<void>
191
202
  /**
192
203
  * The script files a shell line launches that the agent wrote, or that came
193
204
  * into being during the session, read now. Absent when the host keeps no
@@ -31,6 +31,13 @@ export interface EmbeddingConfig {
31
31
  * loud.
32
32
  */
33
33
  export interface HttpEmbeddingConfig extends EmbeddingConfig {
34
+ /** Let the server choose the vector width and omit dimensions from the request. */
35
+ useModelDimensions?: boolean
36
+ /** Override the HTTP transport, for example to connect directly to a local server. */
37
+ fetch?: (
38
+ url: string,
39
+ init: RequestInit,
40
+ ) => Promise<Pick<Response, 'ok' | 'status' | 'text' | 'json'>>
34
41
  apiKey: string
35
42
  /** Root of an embeddings API; `/embeddings` is appended. */
36
43
  baseUrl: string
@@ -178,6 +178,25 @@ export interface SandboxExecOptions {
178
178
  * returns an explicit unsupported error before running the command.
179
179
  */
180
180
  readonly signal?: AbortSignal
181
+ /**
182
+ * Text to give the command on its standard input; stdin is closed once it
183
+ * has been written, so a program that reads to the end sees end-of-file.
184
+ *
185
+ * **Who honours it.** The agent-backed backends in `@namzu/sandbox`
186
+ * (Firecracker microVMs and Kubernetes pods) carry it on the wire request
187
+ * the guest agent already accepts, under the same abort, timeout and
188
+ * output rules as the rest of `exec`. A backend without a guest agent (the
189
+ * in-process local sandbox, the Docker and ACI HTTP workers, the local
190
+ * virtual computer) **refuses** a call that carries it, before anything
191
+ * runs, with a {@link SandboxExecStdinError}; it never drops the input and
192
+ * runs the command on an empty stdin. A detached Kubernetes exec refuses
193
+ * it too.
194
+ *
195
+ * Bounded: the UTF-8 encoding may be at most
196
+ * {@link SANDBOX_EXEC_STDIN_MAX_BYTES} bytes. Larger input is refused
197
+ * before it is sent; stage a big document with `writeFile` instead.
198
+ */
199
+ readonly stdin?: string
181
200
  }
182
201
 
183
202
  // ---------------------------------------------------------------------------
@@ -26,6 +26,49 @@ import type { MessageStopReason, StopReason } from './stop-reason.js'
26
26
  import type { SubSessionKind } from './sub-session.js'
27
27
  import type { LiveTurnSettlement, Origin, TurnBudgetBinding, TurnConfigSnapshot } from './turn.js'
28
28
 
29
+ /**
30
+ * Where a request's start differs from the previous request of its
31
+ * conversation, without any of its content. A provider cache reads a request
32
+ * from its start (model, tools, system text, then each message), so the first
33
+ * thing that moved is where the cache can no longer be read.
34
+ *
35
+ * Every field is a hash; none can be turned back into text.
36
+ */
37
+ export interface RequestPrefixDigest {
38
+ /** Hash of the model name. */
39
+ model: string
40
+ /** Hash of the tools as sent, in order. */
41
+ tools: string
42
+ /** Hash of the leading system messages. */
43
+ system: string
44
+ /** Hash of the settings that are not part of the start but can still move a cache (effort, speed, tool choice). */
45
+ params: string
46
+ /** One 6-character hash per message after the leading system run, in order, concatenated. */
47
+ items: string
48
+ /**
49
+ * What the driver reports it sent after the backend's refusals, when it reports it:
50
+ * whether a cache key and a session header named the conversation, and whether the
51
+ * backend's refusal of the `developer` role is in force (true on every request made
52
+ * under it, whether or not that request had guidance). Absent for a driver that does
53
+ * not say; never assumed from what was asked for.
54
+ */
55
+ cacheKey?: boolean
56
+ sessionHeader?: boolean
57
+ developerRefused?: boolean
58
+ /**
59
+ * Which of the above moved since the previous request of this conversation in this
60
+ * process (`wire` is the three reported fields together). Absent for the first request
61
+ * of the process, including the first after a restart or resume: there is nothing to compare with.
62
+ */
63
+ changed?: ('model' | 'tools' | 'system' | 'params' | 'wire')[]
64
+ /**
65
+ * The index of the first earlier message that this request does not repeat in place
66
+ * (the previous request's own request-only notes, which no request repeats, do not count).
67
+ * Absent when every earlier message is still where it was.
68
+ */
69
+ firstChangedItem?: number
70
+ }
71
+
29
72
  /**
30
73
  * Live events of a session: the stream a host listens to while a turn runs.
31
74
  *
@@ -267,6 +310,13 @@ type CoreSessionEvent =
267
310
  * want to surface that the turn is running tight.
268
311
  */
269
312
  reachedResetThreshold?: boolean
313
+ /** What started the pass, and how long it took from the decision to the swap. */
314
+ trigger?: 'auto' | 'manual' | 'idle' | 'prepared'
315
+ durationMs?: number
316
+ /** True when a summary written ahead of time was installed at once. */
317
+ precomputed?: boolean
318
+ /** `cache_expired`: a turn that started after the provider's prompt cache lapsed installed a summary written earlier. */
319
+ cause?: 'cache_expired'
270
320
  }
271
321
  /**
272
322
  * Oversized tool results were emptied instead of the history being
@@ -956,6 +1006,12 @@ type CoreSessionEvent =
956
1006
  * shows it should do so quietly; a miss after an edit is ordinary.
957
1007
  */
958
1008
  cacheMiss?: { reason: string; missedTokens?: number }
1009
+ /**
1010
+ * What this request's start was, as hashes, and what moved since the
1011
+ * request before it: the record that says where a fall in the cached
1012
+ * share began. Optional; an older reader ignores it.
1013
+ */
1014
+ requestPrefix?: RequestPrefixDigest
959
1015
  /**
960
1016
  * How large the CONTEXT is right now, and how large it may get.
961
1017
  *
@@ -103,6 +103,14 @@ export interface AnswerClaimMismatch {
103
103
  readonly recordSays: string
104
104
  }
105
105
 
106
+ /** A check the host itself ran for the turn, handed to the record as it stands. */
107
+ export interface HostCheck {
108
+ /** The command as a person reads it. */
109
+ readonly command: string
110
+ readonly result: 'passed' | 'failed'
111
+ readonly exitCode?: number
112
+ }
113
+
106
114
  /** Host hooks for the turn's outcome record. */
107
115
  export interface TurnOutcomeConfig {
108
116
  /**
@@ -130,7 +138,14 @@ export interface TurnOutcomeConfig {
130
138
  */
131
139
  readonly beforeEnd?: (
132
140
  read: () => Promise<TurnOutcome | undefined>,
133
- context?: { readonly finalMessage?: string },
141
+ context?: {
142
+ readonly finalMessage?: string
143
+ /**
144
+ * Adds a check the host ran to the turn's record: it reads like a recognised
145
+ * check of the files as they are now, whether or not the turn ran one.
146
+ */
147
+ readonly recordCheck?: (check: HostCheck) => Promise<void>
148
+ },
134
149
  ) => string | undefined | Promise<string | undefined>
135
150
  }
136
151
 
@@ -541,6 +541,30 @@ export const CompactionRecordSchema = recordSchema('compaction', {
541
541
  tokensAfter: count,
542
542
  })
543
543
 
544
+ /**
545
+ * What a compaction pass measured beyond the sizes its `compaction` record
546
+ * holds: what really started it, how long it took, the running total of tokens
547
+ * every pass of the session has dropped, and whether a summary written ahead
548
+ * of time was installed. Written just after the `compaction` record it names,
549
+ * flagged `ignorable`, and never a field of that record: a release that does
550
+ * not know this type keeps it in the hash chain and skips it, where a new
551
+ * field or a new `trigger` value on the strict `compaction` record would make
552
+ * it refuse the whole log. `trigger` here may be `prepared`; the record it
553
+ * names says `auto` then, which an earlier release also reads.
554
+ */
555
+ export const CompactionMeasuredRecordSchema = recordSchema('compaction_measured', {
556
+ ignorable: z.literal(true),
557
+ /** The `compactionId` of the `compaction` record this describes. */
558
+ compactionId: text.min(1),
559
+ trigger: z.enum(['auto', 'manual', 'idle', 'prepared']),
560
+ /** Wall-clock milliseconds the pass took, from the decision to the swap. */
561
+ durationMs: count.optional(),
562
+ /** Tokens every compaction in this session has dropped so far, this one included. */
563
+ cumulativeDroppedTokens: count.optional(),
564
+ /** True when the summary was written ahead of time and installed at once. */
565
+ precomputed: z.boolean().optional(),
566
+ })
567
+
544
568
  // Children (the live child_session_* events, plus one record-only type)
545
569
  //
546
570
  // A child can outlive the parent turn that spawned it (`Turn.abandonedTaskIds`
@@ -729,6 +753,7 @@ const RECORD_ONLY_SCHEMAS = {
729
753
  decision_resolved: DecisionResolvedRecordSchema,
730
754
  decision_expired: DecisionExpiredRecordSchema,
731
755
  compaction: CompactionRecordSchema,
756
+ compaction_measured: CompactionMeasuredRecordSchema,
732
757
  child_session_ended: ChildSessionEndedRecordSchema,
733
758
  audit: AuditRecordSchema,
734
759
  budget_bound: BudgetBoundRecordSchema,
@@ -974,6 +999,17 @@ export const SessionRecordSchema = z
974
999
  message: `${r.type} happens only inside a turn and must carry turnId`,
975
1000
  })
976
1001
  }
1002
+ if (
1003
+ r.type === 'compaction_shed' &&
1004
+ r.messagesSpill !== undefined &&
1005
+ (!Array.isArray(r.messages) || !spill.safeParse(r.messagesSpill).success)
1006
+ ) {
1007
+ context.addIssue({
1008
+ code: z.ZodIssueCode.custom,
1009
+ path: ['messagesSpill'],
1010
+ message: 'Invalid shed message spill or inline projection.',
1011
+ })
1012
+ }
977
1013
  if (
978
1014
  r.type === 'tool_completed' &&
979
1015
  r.inputFailure !== undefined &&
@@ -1138,6 +1174,9 @@ export type SessionEventRecord<T extends PersistedSessionEventType = PersistedSe
1138
1174
  readonly structuredOutputSpill?: z.infer<typeof structuredResultSpill>
1139
1175
  }
1140
1176
  : unknown) &
1177
+ (T extends 'compaction_shed'
1178
+ ? { readonly messagesSpill?: z.infer<typeof spill> }
1179
+ : unknown) &
1141
1180
  (T extends TurnBoundSessionEventType ? { readonly turnId: TurnId } : unknown)
1142
1181
  : never
1143
1182
 
@@ -1152,6 +1191,7 @@ export type DecisionRequestedRecord = z.infer<typeof DecisionRequestedRecordSche
1152
1191
  export type DecisionResolvedRecord = z.infer<typeof DecisionResolvedRecordSchema>
1153
1192
  export type DecisionExpiredRecord = z.infer<typeof DecisionExpiredRecordSchema>
1154
1193
  export type CompactionRecord = z.infer<typeof CompactionRecordSchema>
1194
+ export type CompactionMeasuredRecord = z.infer<typeof CompactionMeasuredRecordSchema>
1155
1195
  export type ChildSessionEndedRecord = z.infer<typeof ChildSessionEndedRecordSchema>
1156
1196
  export type AuditRecord = z.infer<typeof AuditRecordSchema>
1157
1197
  export type BudgetBoundRecord = z.infer<typeof BudgetBoundRecordSchema>
@@ -1174,6 +1214,7 @@ export type SessionRecordOnly =
1174
1214
  | DecisionResolvedRecord
1175
1215
  | DecisionExpiredRecord
1176
1216
  | CompactionRecord
1217
+ | CompactionMeasuredRecord
1177
1218
  | ChildSessionEndedRecord
1178
1219
  | AuditRecord
1179
1220
  | BudgetBoundRecord
@@ -1357,6 +1357,13 @@ export interface ToolDefinition<TInput = unknown> extends ToolPresentation<TInpu
1357
1357
  * otherwise have to search for: a loaded schema rides every later request.
1358
1358
  */
1359
1359
  loadsWith?: readonly string[]
1360
+ /**
1361
+ * One line, at most 100 characters, that says what a deferred tool is for
1362
+ * and when to use it. The catalogue of deferred tools shows it in place of
1363
+ * the first sentence of `description`, which can be cut before the part
1364
+ * that says when to use the tool. Longer text is cut at 100 characters.
1365
+ */
1366
+ discoveryHint?: string
1360
1367
  /**
1361
1368
  * A refusal that needs no person's answer: the call cannot run as it stands,
1362
1369
  * and the tool can already tell.
package/src/utils/cost.ts CHANGED
@@ -30,6 +30,16 @@ export interface CacheRates {
30
30
  readonly writeCostPer1M?: number
31
31
  }
32
32
 
33
+ export interface LongContextRates {
34
+ /** A prompt of more than this many tokens is priced at the rates below. */
35
+ readonly aboveInputTokens: number
36
+ readonly inputCostPer1M: number
37
+ readonly outputCostPer1M: number
38
+ readonly cacheReadCostPer1M: number
39
+ /** Falls back to the base cache-write rate when omitted. */
40
+ readonly cacheWriteCostPer1M?: number
41
+ }
42
+
33
43
  export interface ModelPricing {
34
44
  inputCostPer1M: number
35
45
  outputCostPer1M: number
@@ -48,6 +58,12 @@ export interface ModelPricing {
48
58
  * charged at the standard rate, which would under-report it.
49
59
  */
50
60
  fastMultiplier?: number
61
+ /**
62
+ * A higher rate card the vendor applies to the whole of any request whose
63
+ * prompt is longer than `aboveInputTokens`, including cache reads and
64
+ * writes. Absent means one rate card at every length.
65
+ */
66
+ longContext?: LongContextRates
51
67
  /**
52
68
  * What the vendor charges per 1,000 hosted web searches
53
69
  * (`TokenUsage.webSearchRequests`). Absent means no published search price:
@@ -111,7 +127,34 @@ function priceTokens(usage: TokenUsage, pricing: ModelPricing): Priced {
111
127
  return priceStandard(usage, pricing)
112
128
  }
113
129
 
114
- function priceStandard(usage: TokenUsage, pricing: ModelPricing): Priced {
130
+ function countPromptTokens(usage: TokenUsage, cache: CacheRates | undefined): number {
131
+ return (
132
+ usage.fullPromptTokens ??
133
+ usage.promptTokens +
134
+ (cache?.promptIncludesCacheReads === false ? usage.cachedTokens : 0) +
135
+ usage.cacheWriteTokens
136
+ )
137
+ }
138
+
139
+ function priceStandard(usage: TokenUsage, basePricing: ModelPricing): Priced {
140
+ const tier = basePricing.longContext
141
+ const pricing: ModelPricing =
142
+ tier && countPromptTokens(usage, basePricing.cache) > tier.aboveInputTokens
143
+ ? {
144
+ ...basePricing,
145
+ inputCostPer1M: tier.inputCostPer1M,
146
+ outputCostPer1M: tier.outputCostPer1M,
147
+ ...(basePricing.cache
148
+ ? {
149
+ cache: {
150
+ ...basePricing.cache,
151
+ readCostPer1M: tier.cacheReadCostPer1M,
152
+ writeCostPer1M: tier.cacheWriteCostPer1M ?? basePricing.cache.writeCostPer1M,
153
+ },
154
+ }
155
+ : {}),
156
+ }
157
+ : basePricing
115
158
  const perMillion = (tokens: number, rate: number) => (tokens / 1_000_000) * rate
116
159
 
117
160
  const cache = pricing.cache