@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
@@ -24,6 +24,7 @@ import {
24
24
  planCompaction,
25
25
  planSalienceWorkingSet,
26
26
  } from '../../../../compaction/plan.js'
27
+ import { precomputeStoreFor } from '../../../../compaction/precompute.js'
27
28
  import type { ContextReducer, ContextReduction } from '../../../../compaction/reducer.js'
28
29
  import { createSlidingWindowReducer } from '../../../../compaction/reducer.js'
29
30
  import {
@@ -32,6 +33,7 @@ import {
32
33
  keptInstructionFiles,
33
34
  renderRestoredContext,
34
35
  } from '../../../../compaction/restore.js'
36
+ import { fitRetainedImages } from '../../../../compaction/retained-images.js'
35
37
  import { findRetainedIndices } from '../../../../compaction/retention.js'
36
38
  import { serializeState } from '../../../../compaction/serializer.js'
37
39
  import {
@@ -40,7 +42,10 @@ import {
40
42
  collectRevealedTools,
41
43
  isCompactionMessage,
42
44
  } from '../../../../compaction/summary.js'
43
- import { estimateMessagesTokens } from '../../../../compaction/token-estimate.js'
45
+ import {
46
+ estimateMessagesTokens,
47
+ estimateMessagesTokensForModel,
48
+ } from '../../../../compaction/token-estimate.js'
44
49
  import { clearStaleToolResults } from '../../../../compaction/tool-result-editing.js'
45
50
  import { buildVerifiedSummaryWithBoundedProvider } from '../../../../compaction/verifier.js'
46
51
  import type { CompactionConfig } from '../../../../config/runtime.js'
@@ -60,6 +65,7 @@ import {
60
65
  estimateRefillTokens,
61
66
  } from './compaction-breaker.js'
62
67
  import type { IterationContext } from './context.js'
68
+ import { armPrecompute, bookPreparedSpend, takePrepared } from './precompute.js'
63
69
  import { isWorkingMemoryMessage } from './working-memory.js'
64
70
 
65
71
  // `isCompactionMessage` and the header moved to `compaction/summary.ts` —
@@ -129,7 +135,12 @@ function estimateToolCatalogTokens(ctx: IterationContext): number {
129
135
  }
130
136
 
131
137
  function estimateTokens(ctx: IterationContext): number {
132
- return estimateMessagesTokens(ctx.recorder.messages) + estimateToolCatalogTokens(ctx)
138
+ return (
139
+ estimateMessagesTokensForModel(
140
+ ctx.recorder.messages,
141
+ ctx.contextModel ?? ctx.turnConfig.model,
142
+ ) + estimateToolCatalogTokens(ctx)
143
+ )
133
144
  }
134
145
 
135
146
  type ToolResultClearPlan = Extract<CompactionPlan, { kind: 'cleared' }>
@@ -364,7 +375,12 @@ export function measureContext(ctx: IterationContext): {
364
375
  if (reported !== undefined && reported > 0) {
365
376
  const measuredThrough = ctx.recorder.lastPromptMessageCount ?? ctx.recorder.messages.length
366
377
  const appended = ctx.recorder.messages.slice(measuredThrough)
367
- return { tokens: reported + estimateMessagesTokens(appended), source: 'provider' }
378
+ return {
379
+ tokens:
380
+ reported +
381
+ estimateMessagesTokensForModel(appended, ctx.contextModel ?? ctx.turnConfig.model),
382
+ source: 'provider',
383
+ }
368
384
  }
369
385
  return { tokens: estimateTokens(ctx), source: 'estimate' }
370
386
  }
@@ -652,6 +668,7 @@ async function applyReducer(
652
668
  windowSource: 'config' | 'provider' | 'model-table' | 'default'
653
669
  },
654
670
  ): Promise<void> {
671
+ const startedAt = performance.now()
655
672
  const messages = ctx.recorder.messages
656
673
  const before = messages.length
657
674
  const beforeChars = totalChars(messages)
@@ -724,6 +741,13 @@ async function applyReducer(
724
741
  // Found by a test written for the decline paths asserting that success does
725
742
  // NOT report a failure, which is the only reason anybody looked here.
726
743
  const tokensAfter = estimateTokens(ctx)
744
+ const durationMs = Math.max(0, Math.round(performance.now() - startedAt))
745
+ ctx.recorder.noteCompaction?.({
746
+ trigger: 'auto',
747
+ tokensBefore: reduction.estimatedTokens,
748
+ tokensAfter,
749
+ durationMs,
750
+ })
727
751
  await ctx.emitEvent?.({
728
752
  type: 'compaction_completed',
729
753
  turnId: ctx.recorder.turnId,
@@ -735,6 +759,8 @@ async function applyReducer(
735
759
  measuredBy: measurement.measuredBy,
736
760
  contextWindowTokens: reduction.contextWindowTokens,
737
761
  windowSource: measurement.windowSource,
762
+ trigger: 'auto',
763
+ durationMs,
738
764
  })
739
765
  await emitContextUsageSnapshot(
740
766
  ctx,
@@ -801,17 +827,22 @@ interface CompactionPass {
801
827
  hookInstructions?: string
802
828
  /** The summary the pass installed, for `post_compact`. */
803
829
  summary?: string
830
+ /** The summary was written ahead of time and installed at once. */
831
+ precomputed?: boolean
832
+ /** A turn that started after the prompt cache lapsed asked for it. */
833
+ cause?: 'cache_expired'
804
834
  tokensBefore: number
805
835
  contextWindowTokens: number
806
836
  }
807
837
 
808
838
  export async function runCompactionCheck(
809
839
  ctx: IterationContext,
810
- options?: { force?: boolean; deeper?: boolean },
840
+ options?: { force?: boolean; deeper?: boolean; preparedOnly?: boolean },
811
841
  ): Promise<void> {
812
842
  const pass: CompactionPass = {
813
843
  attempted: false,
814
844
  reason: options?.force ? 'overflow' : 'threshold',
845
+ ...(options?.preparedOnly ? { cause: 'cache_expired' as const } : {}),
815
846
  tokensBefore: 0,
816
847
  contextWindowTokens: 0,
817
848
  }
@@ -852,13 +883,23 @@ export async function runCompactionCheck(
852
883
  async function runCompactionCheckInner(
853
884
  ctx: IterationContext,
854
885
  pass: CompactionPass,
855
- options?: { force?: boolean; deeper?: boolean },
886
+ options?: { force?: boolean; deeper?: boolean; preparedOnly?: boolean },
856
887
  ): Promise<void> {
888
+ const startedAt = performance.now()
889
+ // What summaries prepared earlier cost, before any early return below.
890
+ bookPreparedSpend(ctx)
857
891
  const configured = ctx.compactionConfig
858
892
  if (!configured) return
859
893
  if (configured.strategy === 'disabled') return
860
894
  // Automatic compaction off: only a pass the provider forced (an overflow) runs.
861
895
  if (configured.autoCompact === false && !options?.force) return
896
+ if (options?.preparedOnly) {
897
+ // Only a summary already written, and only where one could be used: a
898
+ // reducer owns reduction, and nothing prepared means nothing to install.
899
+ if (configured.precompute === false || !ctx.compactionSummaryRoute) return
900
+ if (ctx.contextReducer || configured.strategy === 'sliding-window') return
901
+ if (precomputeStoreFor(ctx.recorder.sessionId).entry?.status !== 'ready') return
902
+ }
862
903
  const deepened = options?.deeper ? deepenConfig(configured, ctx.recorder.messages) : configured
863
904
 
864
905
  const measured = measureContext(ctx)
@@ -907,7 +948,20 @@ async function runCompactionCheckInner(
907
948
  config.autoCompactWindowTokens,
908
949
  )
909
950
  const startAt = salience ? Math.min(config.softTarget ?? DEFAULT_SOFT_TARGET, trigger) : trigger
910
- if (!options?.force && usage < startAt) return
951
+ if (!options?.force && !options?.preparedOnly && usage < startAt) {
952
+ // Short of the trigger. Near it, a summary starts in the background so it
953
+ // is ready by the time the trigger is reached; far from it, nothing runs.
954
+ armPrecompute(ctx, {
955
+ config,
956
+ usage,
957
+ trigger,
958
+ budget,
959
+ estimatedTokens,
960
+ ...(maxOutputTokens !== undefined ? { maxOutputTokens } : {}),
961
+ source: 'estimate',
962
+ })
963
+ return
964
+ }
911
965
 
912
966
  // A pass that can shed nothing and has not reached the summary trigger
913
967
  // does nothing but announce itself: two hooks, a started event and a log
@@ -919,10 +973,21 @@ async function runCompactionCheckInner(
919
973
  if (
920
974
  salience &&
921
975
  !options?.force &&
976
+ !options?.preparedOnly &&
922
977
  !ctx.contextReducer &&
923
978
  usage < trigger &&
924
979
  !canShedSalienceWorkingSet(ctx.recorder.messages, config)
925
980
  ) {
981
+ // Nothing to shed yet, but the summary can still start near the trigger.
982
+ armPrecompute(ctx, {
983
+ config,
984
+ usage,
985
+ trigger,
986
+ budget,
987
+ estimatedTokens,
988
+ ...(maxOutputTokens !== undefined ? { maxOutputTokens } : {}),
989
+ source: 'estimate',
990
+ })
926
991
  return
927
992
  }
928
993
 
@@ -1056,7 +1121,7 @@ async function runCompactionCheckInner(
1056
1121
  // The decision is `planCompaction`'s; installing it is this file's. The
1057
1122
  // planner touches no `ctx` at all, which is what lets the boundary
1058
1123
  // arithmetic be tested without a turn.
1059
- if (salience) {
1124
+ if (salience && !options?.preparedOnly) {
1060
1125
  let openTasks: string[] | undefined
1061
1126
  if (ctx.taskStore) {
1062
1127
  try {
@@ -1084,16 +1149,69 @@ async function runCompactionCheckInner(
1084
1149
  // Under the trigger, the working set was the whole pass: the summary
1085
1150
  // path is for the trigger, not for the soft target.
1086
1151
  if (!options?.force && (estimatedTokens - working.reclaimedTokens) / budget < trigger) {
1152
+ armPrecompute(ctx, {
1153
+ config,
1154
+ usage: (estimatedTokens - working.reclaimedTokens) / budget,
1155
+ trigger,
1156
+ budget,
1157
+ estimatedTokens: estimatedTokens - working.reclaimedTokens,
1158
+ ...(maxOutputTokens !== undefined ? { maxOutputTokens } : {}),
1159
+ source: 'estimate',
1160
+ })
1087
1161
  return
1088
1162
  }
1089
1163
  }
1164
+ const fitWithoutSummary = async (candidate: readonly Message[]): Promise<boolean> => {
1165
+ if (options?.preparedOnly) return false
1166
+ const copy = [...candidate]
1167
+ const fitted = fitRetainedImages(
1168
+ copy,
1169
+ Math.floor(budget * config.resetThreshold) - estimateToolCatalogTokens(ctx),
1170
+ model,
1171
+ )
1172
+ if (fitted === copy) return false
1173
+
1174
+ const live = ctx.recorder.messages
1175
+ await recordShed(ctx, live, fitted, pass.reason)
1176
+ installMessages(live, fitted)
1177
+ ctx.recorder.clearLastPromptTokens?.()
1178
+ const tokensAfter = estimateTokens(ctx)
1179
+ const durationMs = Math.max(0, Math.round(performance.now() - startedAt))
1180
+ ctx.recorder.noteCompaction?.({
1181
+ trigger: 'auto',
1182
+ tokensBefore: estimatedTokens,
1183
+ tokensAfter,
1184
+ durationMs,
1185
+ })
1186
+ await ctx.emitEvent?.({
1187
+ type: 'compaction_completed',
1188
+ turnId: ctx.recorder.turnId,
1189
+ iteration: ctx.recorder.currentIteration,
1190
+ messagesBefore: live.length,
1191
+ messagesAfter: live.length,
1192
+ tokensBefore: estimatedTokens,
1193
+ tokensAfter,
1194
+ measuredBy: measured.source,
1195
+ contextWindowTokens: budget,
1196
+ windowSource: window.source,
1197
+ reachedResetThreshold: tokensAfter / budget <= config.resetThreshold,
1198
+ trigger: 'auto',
1199
+ durationMs,
1200
+ })
1201
+ await emitContextUsageSnapshot(ctx, tokensAfter, budget, window.source)
1202
+ breaker?.recordRelief()
1203
+ return true
1204
+ }
1090
1205
  const clearPlan = planCompaction({
1206
+ model,
1091
1207
  messages: ctx.recorder.messages,
1092
1208
  config,
1093
1209
  contextWindowTokens: budget,
1094
1210
  ...(maxOutputTokens !== undefined ? { maxOutputTokens } : {}),
1095
1211
  estimatedTokens,
1096
1212
  ...(options?.force ? { force: true } : {}),
1213
+ // Installing a prepared summary leaves the tool results to the stale clear.
1214
+ ...(options?.preparedOnly ? { skipToolResultClear: true } : {}),
1097
1215
  })
1098
1216
 
1099
1217
  if (clearPlan.kind === 'cleared') {
@@ -1114,6 +1232,7 @@ async function runCompactionCheckInner(
1114
1232
  const stagedClear = clearPlan.kind === 'cleared' ? clearPlan : undefined
1115
1233
  const messages = stagedClear?.messages ?? ctx.recorder.messages
1116
1234
  const plan = planCompaction({
1235
+ model,
1117
1236
  messages,
1118
1237
  config,
1119
1238
  contextWindowTokens: budget,
@@ -1124,6 +1243,7 @@ async function runCompactionCheckInner(
1124
1243
  })
1125
1244
 
1126
1245
  if (plan.kind !== 'plan') {
1246
+ if (await fitWithoutSummary(messages)) return
1127
1247
  // One log line per reason, with the fields each one was already
1128
1248
  // reporting. The planner names the reason; what it means to an
1129
1249
  // operator reading a turn is this file's to say.
@@ -1168,52 +1288,82 @@ async function runCompactionCheckInner(
1168
1288
  return
1169
1289
  }
1170
1290
 
1171
- const { systemMessages, olderMessages, recentMessages, keepStart } = plan
1291
+ let { olderMessages, recentMessages, keepStart } = plan
1292
+ const { systemMessages } = plan
1172
1293
 
1173
1294
  let compactedContent: string
1174
1295
 
1296
+ // A summary written ahead of time stands in for the one this pass would
1297
+ // write, when it still describes the start of the conversation. What was
1298
+ // said after it was armed stays verbatim after the summary.
1299
+ const prepared =
1300
+ ctx.compactionSummaryRoute && config.precompute !== false && !ctx.contextReducer
1301
+ ? await takePrepared(ctx, {
1302
+ messages,
1303
+ floorLength: systemMessages.length,
1304
+ hookInstructions: pass.hookInstructions,
1305
+ overheadTokens: estimateToolCatalogTokens(ctx),
1306
+ budget,
1307
+ triggerTokens: trigger * budget,
1308
+ ...(options?.preparedOnly ? { readyOnly: true } : {}),
1309
+ })
1310
+ : undefined
1311
+ // A turn that starts after the cache lapsed installs a summary that is
1312
+ // ready, and writes none: a refusal is a skip.
1313
+ if (options?.preparedOnly && !prepared) return
1314
+ if (prepared) {
1315
+ keepStart = prepared.keepStart
1316
+ olderMessages = messages.slice(systemMessages.length, keepStart)
1317
+ recentMessages = messages.slice(keepStart)
1318
+ pass.precomputed = true
1319
+ }
1320
+
1175
1321
  // A model the host set aside writes the summary when it can. Its own cost
1176
1322
  // goes on the turn's ledger at the price of the model that answered. When
1177
1323
  // there is no such model, or its call does not give a summary, the
1178
1324
  // extracted state below is used, with its verifier step where that applies.
1179
1325
  let modelRoute: { providerId: string; model: string } | undefined
1180
- const modelWritten = !ctx.compactionSummaryRoute
1181
- ? undefined
1182
- : await summarizeWithModel({
1183
- manager,
1184
- olderMessages,
1185
- previousSummaries: replaceableSummaries(systemMessages),
1186
- config,
1187
- ...(pass.hookInstructions !== undefined ? { hookInstructions: pass.hookInstructions } : {}),
1188
- resolveRoute: async (signal) => {
1189
- const route = await ctx.compactionSummaryRoute?.(signal)
1190
- if (route) {
1191
- modelRoute = {
1192
- providerId: route.providerId ?? ctx.recorder.servingProviderId,
1193
- model: route.model,
1326
+ const modelWritten = prepared
1327
+ ? prepared.summary
1328
+ : !ctx.compactionSummaryRoute
1329
+ ? undefined
1330
+ : await summarizeWithModel({
1331
+ manager,
1332
+ olderMessages,
1333
+ previousSummaries: replaceableSummaries(systemMessages),
1334
+ config,
1335
+ ...(pass.hookInstructions !== undefined
1336
+ ? { hookInstructions: pass.hookInstructions }
1337
+ : {}),
1338
+ resolveRoute: async (signal) => {
1339
+ const route = await ctx.compactionSummaryRoute?.(signal)
1340
+ if (route) {
1341
+ modelRoute = {
1342
+ providerId: route.providerId ?? ctx.recorder.servingProviderId,
1343
+ model: route.model,
1344
+ }
1194
1345
  }
1195
- }
1196
- return route
1197
- },
1198
- onUsage: (usage) => {
1199
- if (modelRoute) ctx.recorder.accumulateUsage(usage, modelRoute)
1200
- },
1201
- signal: ctx.abortController.signal,
1202
- onFallback: (reason, error) => {
1203
- if (reason === 'no_route') return
1204
- if (error !== undefined) noteCompactionError(ctx, error)
1205
- ctx.log.warn(
1206
- 'The model-written compaction summary was not used — using the extracted state',
1207
- {
1208
- [NAMZU.TURN_ID]: ctx.recorder.turnId,
1209
- 'namzu.runtime.reason': reason,
1210
- ...(error !== undefined
1211
- ? { 'exception.message': error instanceof Error ? error.message : String(error) }
1212
- : {}),
1213
- },
1214
- )
1215
- },
1216
- })
1346
+ return route
1347
+ },
1348
+ onUsage: (usage) => {
1349
+ if (modelRoute) ctx.recorder.accumulateUsage(usage, modelRoute)
1350
+ },
1351
+ signal: ctx.abortController.signal,
1352
+ onFallback: (reason, error) => {
1353
+ if (reason === 'no_route') return
1354
+ if (error !== undefined) noteCompactionError(ctx, error)
1355
+ ctx.log.warn(
1356
+ 'The model-written compaction summary was not used — using the extracted state',
1357
+ {
1358
+ [NAMZU.TURN_ID]: ctx.recorder.turnId,
1359
+ 'namzu.runtime.reason': reason,
1360
+ ...(error !== undefined
1361
+ ? { 'exception.message': error instanceof Error ? error.message : String(error) }
1362
+ : {}),
1363
+ },
1364
+ )
1365
+ },
1366
+ })
1217
1367
 
1218
1368
  if (modelWritten !== undefined) {
1219
1369
  compactedContent = modelWritten
@@ -1348,7 +1498,17 @@ async function runCompactionCheckInner(
1348
1498
  },
1349
1499
  )
1350
1500
 
1351
- const newMessages = [...preservedSystem, compactionMessage, ...retainedOlder, ...recentMessages]
1501
+ const newMessages = fitRetainedImages(
1502
+ [...preservedSystem, compactionMessage, ...retainedOlder, ...recentMessages],
1503
+ Math.floor(budget * config.resetThreshold) - estimateToolCatalogTokens(ctx),
1504
+ model,
1505
+ config.keepRecentTokens === undefined
1506
+ ? undefined
1507
+ : {
1508
+ start: preservedSystem.length + 1 + retainedOlder.length,
1509
+ tokens: config.keepRecentTokens,
1510
+ },
1511
+ )
1352
1512
 
1353
1513
  // OPAQUE survival guard: the pinned working-memory slot is a
1354
1514
  // leading system message, so it is kept in `preservedSystem` (the compaction
@@ -1379,7 +1539,11 @@ async function runCompactionCheckInner(
1379
1539
  // comparing provider usage against an estimate or trusting message count.
1380
1540
  // When a clear was staged, require the summary itself to improve on it;
1381
1541
  // otherwise publish the useful clear without consuming its savings.
1382
- if (estimateMessagesTokens(newMessages) >= estimateMessagesTokens(messages)) {
1542
+ if (
1543
+ estimateMessagesTokensForModel(newMessages, model) >=
1544
+ estimateMessagesTokensForModel(messages, model)
1545
+ ) {
1546
+ if (await fitWithoutSummary(messages)) return
1383
1547
  if (stagedClear && stagedClear.reclaimedTokens > 0) {
1384
1548
  await commitToolResultClear(ctx, stagedClear, budget, window.source, pass.reason)
1385
1549
  } else {
@@ -1393,6 +1557,16 @@ async function runCompactionCheckInner(
1393
1557
  pass.summary = compactedContent
1394
1558
 
1395
1559
  const newEstimate = estimateTokens(ctx)
1560
+ // Said before anything below emits: an emit reconciles the log with the new
1561
+ // context, and the `compaction` record it writes carries what was said here.
1562
+ const durationMs = Math.max(0, Math.round(performance.now() - startedAt))
1563
+ ctx.recorder.noteCompaction?.({
1564
+ trigger: pass.precomputed ? 'prepared' : 'auto',
1565
+ tokensBefore: estimatedTokens,
1566
+ tokensAfter: newEstimate,
1567
+ durationMs,
1568
+ ...(pass.precomputed ? { precomputed: true } : {}),
1569
+ })
1396
1570
 
1397
1571
  // The provider's count described the PRE-compaction prompt; the window
1398
1572
  // it just shrank to has not been sent yet, so the post number is
@@ -1446,6 +1620,10 @@ async function runCompactionCheckInner(
1446
1620
  contextWindowTokens: budget,
1447
1621
  windowSource: window.source,
1448
1622
  reachedResetThreshold: reachedReset,
1623
+ trigger: pass.precomputed ? 'prepared' : 'auto',
1624
+ durationMs,
1625
+ ...(pass.precomputed ? { precomputed: true } : {}),
1626
+ ...(pass.cause ? { cause: pass.cause } : {}),
1449
1627
  })
1450
1628
  await emitContextUsageSnapshot(ctx, newEstimate, budget, window.source)
1451
1629
  if (putBack.rendered && putBack.rendered.carried.length > 0) {
@@ -269,6 +269,8 @@ export interface IterationContext {
269
269
  readonly resumedInput?: readonly import('../../../../types/message/index.js').Message[]
270
270
  /** Observes pending input without draining it; abort releases the waiter. */
271
271
  readonly waitForInbound?: (signal: AbortSignal) => Promise<void>
272
+ /** Resolves when the person wrote to this turn; handed to resume handlers, see `ResumeContext`. */
273
+ readonly waitForOperator?: (signal: AbortSignal) => Promise<void>
272
274
  readonly durableInbound?: DurableInboundSource
273
275
 
274
276
  /** Live project policy; separate from human inbound continuation. */
@@ -481,6 +483,7 @@ function resumeContextOf(ctx: IterationContext, scope?: AskScope): ResumeContext
481
483
  return {
482
484
  transcript: () => ctx.recorder.messages,
483
485
  ...(signal ? { signal } : {}),
486
+ ...(ctx.waitForOperator ? { waitForOperator: ctx.waitForOperator } : {}),
484
487
  ...(typeof ctx.toolExecutor?.launchedScripts === 'function'
485
488
  ? {
486
489
  launchedScripts: (callId, line, dialect) =>