@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
@@ -71,7 +71,7 @@
71
71
  "promptIncludesCacheReads": false,
72
72
  "reportsCacheWrites": true,
73
73
  "webSearchPer1000": 10,
74
- "note": "The last two rows exist because the driver's own offline catalogue offers those models and this table did not price them — a lookup-key gap that reads as `cost unknown` and is invisible to the generator's own check, which only proves the module matches this file. `providers/anthropic` asserts the two lists agree. Vendor list prices, every row checked against its pricing page on the `verified` date. Cache read is the vendor's published 0.1x of the input rate, except on the six models it prices differently: 0.05x on claude-opus-5-5 and claude-sonnet-5-5 and 0.025x on claude-fable-5-1, claude-mythos-5-1, claude-fable-5-2 and claude-mythos-5-2, entered at the published rate rather than derived. claude-haiku-5-5 has no row on purpose: the vendor prices it by prompt length ($0.10 in / $0.50 out up to 100,000 prompt tokens, $0.50 / $2.50 above, cache counted in the length), this table holds one rate per model, and either single rate would be wrong for the other half of requests, so its cost reports unknown. Cache write is its published 1.25x for the five-minute entry, which is the default TTL and the one the driver's `cacheControl: { type: 'auto' }` asks for. claude-sonnet-5 launched at an introductory $2/$10 with $3/$15 scheduled from 2026-09-01, and this table recorded the scheduled rate; the vendor has since made $2/$10 the standard price and cancelled the increase. The table has no time dimension, so a future promotional window is still recorded at the list rate and over-reported rather than mis-modelled.",
74
+ "note": "The last two rows exist because the driver's own offline catalogue offers those models and this table did not price them — a lookup-key gap that reads as `cost unknown` and is invisible to the generator's own check, which only proves the module matches this file. `providers/anthropic` asserts the two lists agree. Vendor list prices, every row checked against its pricing page on the `verified` date. Cache read is the vendor's published 0.1x of the input rate, except on the six models it prices differently: 0.05x on claude-opus-5-5 and claude-sonnet-5-5 and 0.025x on claude-fable-5-1, claude-mythos-5-1, claude-fable-5-2 and claude-mythos-5-2, entered at the published rate rather than derived. The claude-haiku-5-5 tiers were checked on 2026-12-04 at https://platform.claude.com/docs/en/about-claude/pricing. The higher rates apply to the whole request above 100,000 prompt tokens, including cache reads and writes in the threshold count. Cache write is its published 1.25x for the five-minute entry, which is the default TTL and the one the driver's `cacheControl: { type: 'auto' }` asks for. claude-sonnet-5 launched at an introductory $2/$10 with $3/$15 scheduled from 2026-09-01, and this table recorded the scheduled rate; the vendor has since made $2/$10 the standard price and cancelled the increase. The table has no time dimension, so a future promotional window is still recorded at the list rate and over-reported rather than mis-modelled.",
75
75
  "models": [
76
76
  {
77
77
  "id": "claude-fable-5-2",
@@ -176,6 +176,20 @@
176
176
  "cacheReadPer1M": 0.3,
177
177
  "cacheWritePer1M": 3.75
178
178
  },
179
+ {
180
+ "id": "claude-haiku-5-5",
181
+ "inputPer1M": 0.1,
182
+ "outputPer1M": 0.5,
183
+ "cacheReadPer1M": 0.01,
184
+ "cacheWritePer1M": 0.125,
185
+ "longContext": {
186
+ "aboveInputTokens": 100000,
187
+ "inputPer1M": 0.5,
188
+ "outputPer1M": 2.5,
189
+ "cacheReadPer1M": 0.05,
190
+ "cacheWritePer1M": 0.625
191
+ }
192
+ },
179
193
  {
180
194
  "id": "claude-haiku-4-5",
181
195
  "inputPer1M": 1,
@@ -219,8 +233,147 @@
219
233
  "verified": "2026-08-10",
220
234
  "promptIncludesCacheReads": true,
221
235
  "reportsCacheWrites": false,
222
- "note": "Vendor list prices for text models, cached-input rate included. The driver hard-codes cacheWriteTokens to zero, so no write rate is carried. Embedding models are omitted (no output rate, and a chat turn never reaches one), as are models whose cached-input rate was not published alongside the others — an unestablished rate is left out rather than approximated, which is the rule this whole file follows. gpt-6-astra has no row on purpose: the vendor prices it by input length (read 2026-11-11 on its pricing page, $10 in / $1 cached / $50 out up to 272,000 input tokens, $20 / $2 / $75 above), this table holds one rate per model, and either single rate would be wrong for the other half of requests, so its cost reports unknown. The fastMultiplier on six rows is the vendor's fast-mode multiple read on its API pricing page on 2026-11-22: 2 for gpt-5.4, gpt-5.4-mini and the gpt-5.6 models, 2.5 for gpt-5.5 (fast is $12.50 in / $75 out, standard is $5 in / $30 out). The gpt-6 family has no row, so its fast usage reports unknown.",
236
+ "note": "Vendor list prices for text models, cached-input rate included. The driver hard-codes cacheWriteTokens to zero, so no write rate is carried. Embedding models are omitted (no output rate, and a chat turn never reaches one), as are models whose cached-input rate was not published alongside the others — an unestablished rate is left out rather than approximated, which is the rule this whole file follows. The gpt-6 rows (read 2026-12-04 on https://developers.openai.com/api/docs/pricing) carry the vendor's length tiers: the standard rate up to 272,000 input tokens and the `longContext` rate for the whole of a request whose prompt is longer. Fast mode is 2x for every one of them on that page. Ultrafast has no row (the page prices it 3x then 6x on a date), so ultrafast usage reports unknown. The healthcare rows are listed on that page at the same rates as their base model; they carry no fastMultiplier because the driver's fast table does not name them. The gpt-6-cyber, gpt-6-rosalind and gpt-6-*-law configurations are left out: the page lists them but the API's model list does not. The fastMultiplier on six rows is the vendor's fast-mode multiple read on its API pricing page on 2026-11-22: 2 for gpt-5.4, gpt-5.4-mini and the gpt-5.6 models, 2.5 for gpt-5.5 (fast is $12.50 in / $75 out, standard is $5 in / $30 out).",
223
237
  "models": [
238
+ {
239
+ "id": "gpt-6.2-astra",
240
+ "inputPer1M": 8,
241
+ "outputPer1M": 40,
242
+ "cacheReadPer1M": 0.4,
243
+ "fastMultiplier": 2,
244
+ "longContext": {
245
+ "aboveInputTokens": 272000,
246
+ "inputPer1M": 16,
247
+ "outputPer1M": 60,
248
+ "cacheReadPer1M": 0.8
249
+ }
250
+ },
251
+ {
252
+ "id": "gpt-6.2-astra-healthcare",
253
+ "inputPer1M": 8,
254
+ "outputPer1M": 40,
255
+ "cacheReadPer1M": 0.4,
256
+ "longContext": {
257
+ "aboveInputTokens": 272000,
258
+ "inputPer1M": 16,
259
+ "outputPer1M": 60,
260
+ "cacheReadPer1M": 0.8
261
+ }
262
+ },
263
+ {
264
+ "id": "gpt-6.2-sol",
265
+ "inputPer1M": 2,
266
+ "outputPer1M": 10,
267
+ "cacheReadPer1M": 0.1,
268
+ "fastMultiplier": 2,
269
+ "longContext": {
270
+ "aboveInputTokens": 272000,
271
+ "inputPer1M": 4,
272
+ "outputPer1M": 15,
273
+ "cacheReadPer1M": 0.2
274
+ }
275
+ },
276
+ {
277
+ "id": "gpt-6.2-sol-healthcare",
278
+ "inputPer1M": 2,
279
+ "outputPer1M": 10,
280
+ "cacheReadPer1M": 0.1,
281
+ "longContext": {
282
+ "aboveInputTokens": 272000,
283
+ "inputPer1M": 4,
284
+ "outputPer1M": 15,
285
+ "cacheReadPer1M": 0.2
286
+ }
287
+ },
288
+ {
289
+ "id": "gpt-6.1-sol",
290
+ "inputPer1M": 2,
291
+ "outputPer1M": 10,
292
+ "cacheReadPer1M": 0.1,
293
+ "fastMultiplier": 2,
294
+ "longContext": {
295
+ "aboveInputTokens": 272000,
296
+ "inputPer1M": 4,
297
+ "outputPer1M": 15,
298
+ "cacheReadPer1M": 0.2
299
+ }
300
+ },
301
+ {
302
+ "id": "gpt-6.1-sol-healthcare",
303
+ "inputPer1M": 2,
304
+ "outputPer1M": 10,
305
+ "cacheReadPer1M": 0.1,
306
+ "longContext": {
307
+ "aboveInputTokens": 272000,
308
+ "inputPer1M": 4,
309
+ "outputPer1M": 15,
310
+ "cacheReadPer1M": 0.2
311
+ }
312
+ },
313
+ {
314
+ "id": "gpt-6.1-terra",
315
+ "inputPer1M": 1,
316
+ "outputPer1M": 5,
317
+ "cacheReadPer1M": 0.05,
318
+ "fastMultiplier": 2,
319
+ "longContext": {
320
+ "aboveInputTokens": 272000,
321
+ "inputPer1M": 2,
322
+ "outputPer1M": 7.5,
323
+ "cacheReadPer1M": 0.1
324
+ }
325
+ },
326
+ {
327
+ "id": "gpt-6-astra",
328
+ "inputPer1M": 10,
329
+ "outputPer1M": 50,
330
+ "cacheReadPer1M": 1,
331
+ "fastMultiplier": 2,
332
+ "longContext": {
333
+ "aboveInputTokens": 272000,
334
+ "inputPer1M": 20,
335
+ "outputPer1M": 75,
336
+ "cacheReadPer1M": 2
337
+ }
338
+ },
339
+ {
340
+ "id": "gpt-6-astra-healthcare",
341
+ "inputPer1M": 10,
342
+ "outputPer1M": 50,
343
+ "cacheReadPer1M": 1,
344
+ "longContext": {
345
+ "aboveInputTokens": 272000,
346
+ "inputPer1M": 20,
347
+ "outputPer1M": 75,
348
+ "cacheReadPer1M": 2
349
+ }
350
+ },
351
+ {
352
+ "id": "gpt-6-luna",
353
+ "inputPer1M": 0.1,
354
+ "outputPer1M": 0.5,
355
+ "cacheReadPer1M": 0.01,
356
+ "fastMultiplier": 2,
357
+ "longContext": {
358
+ "aboveInputTokens": 272000,
359
+ "inputPer1M": 0.2,
360
+ "outputPer1M": 0.75,
361
+ "cacheReadPer1M": 0.02
362
+ }
363
+ },
364
+ {
365
+ "id": "gpt-6-sol",
366
+ "inputPer1M": 2,
367
+ "outputPer1M": 10,
368
+ "cacheReadPer1M": 0.2,
369
+ "fastMultiplier": 2,
370
+ "longContext": {
371
+ "aboveInputTokens": 272000,
372
+ "inputPer1M": 4,
373
+ "outputPer1M": 15,
374
+ "cacheReadPer1M": 0.4
375
+ }
376
+ },
224
377
  {
225
378
  "id": "gpt-5.6-sol",
226
379
  "inputPer1M": 5,
@@ -40,7 +40,7 @@ export interface AppIdentity {
40
40
  export const NAMZU_APP_IDENTITY: AppIdentity = {
41
41
  product: 'namzu',
42
42
  version: VERSION,
43
- url: 'https://github.com/cogitave/namzu',
43
+ url: 'https://github.com/bahadirarda/namzu',
44
44
  }
45
45
 
46
46
  /**
@@ -288,6 +288,26 @@ export { DEFAULT_MAX_REQUEST_RICH_CONTENT_BYTES } from './runtime/query/request-
288
288
  export { DEFAULT_SANDBOX_TEARDOWN_TIMEOUT_MS } from './runtime/query/sandbox-lifecycle.js'
289
289
 
290
290
  export { isTrustedReadOnly } from './tools/trusted-read-only.js'
291
+ export {
292
+ GOAL_GATES_BLOCK_CODE,
293
+ GOAL_GATE_DEFAULT_MAX_FAILING_ROUNDS,
294
+ GOAL_GATE_DEFAULT_TIMEOUT_MS,
295
+ GOAL_GATE_MAX_ARGS,
296
+ GOAL_GATE_MAX_ARG_CHARS,
297
+ GOAL_GATE_MAX_CWD_CHARS,
298
+ GOAL_GATE_MAX_ENTRIES,
299
+ GOAL_GATE_MAX_NAME_CHARS,
300
+ GOAL_GATE_MAX_TAIL_CHARS,
301
+ GOAL_GATE_MAX_TIMEOUT_MS,
302
+ GOAL_GATE_MIN_TIMEOUT_MS,
303
+ goalGateCommandText,
304
+ goalGateFailedNames,
305
+ goalGatePassed,
306
+ goalGateTail,
307
+ goalGatesBlockSentence,
308
+ goalGatesFrom,
309
+ parseGoalGateEntry,
310
+ } from './store/goal/gates.js'
291
311
  export {
292
312
  GoalRoundAuthorityError,
293
313
  MIN_GOAL_BLOCK_ROUND,
@@ -301,6 +321,7 @@ export {
301
321
  NO_CHECK_REASON_CODE,
302
322
  decideGoalConfirmation,
303
323
  describeGoalEnding,
324
+ gateFailureNote,
304
325
  parseGoalEvidence,
305
326
  recordSentence,
306
327
  } from './tools/goal/confirmation.js'
@@ -488,6 +509,10 @@ export type { AbandonTurnOptions, SessionLocatorOptions } from './runtime/query/
488
509
  export { CacheClock } from './runtime/cache-clock.js'
489
510
  export type { CacheClockState } from './runtime/cache-clock.js'
490
511
  export { compactSession, compactSessionRange } from './runtime/query/compact-session.js'
512
+ export {
513
+ type PreparedSpend,
514
+ releasePreparedSummary,
515
+ } from './compaction/precompute.js'
491
516
  export type {
492
517
  CompactSessionParams,
493
518
  CompactSessionRangeParams,
@@ -809,6 +834,7 @@ export {
809
834
  MAX_COMPACTION_SUMMARY_HOOK_CHARS,
810
835
  MAX_LAST_MESSAGE_HOOK_CHARS,
811
836
  createShellHook,
837
+ shellHookEntryLimitProblem,
812
838
  DEFAULT_SHELL_HOOK_TIMEOUT_MS,
813
839
  definePlugin,
814
840
  frameOperatorHookContext,
@@ -1033,11 +1059,17 @@ export {
1033
1059
  describeIsolation,
1034
1060
  isolationOf,
1035
1061
  LocalSandboxProvider,
1062
+ execStdinOf,
1036
1063
  missingIsolation,
1064
+ refuseExecStdin,
1065
+ SANDBOX_EXEC_STDIN_MAX_BYTES,
1066
+ SandboxExecStdinError,
1037
1067
  SandboxProviderFactory,
1068
+ walkFilesLocally,
1038
1069
  walkFilesViaExec,
1039
1070
  } from './sandbox/index.js'
1040
1071
  export type {
1072
+ LocalFileWalkOptions,
1041
1073
  LocalSandboxProviderOptions,
1042
1074
  SandboxFileWalkExec,
1043
1075
  } from './sandbox/index.js'
@@ -1320,6 +1352,21 @@ export {
1320
1352
  export { writesThroughRedirection } from './authorization/command-line.js'
1321
1353
  export { isReadOnlyCommandLine } from './authorization/readonly-commands.js'
1322
1354
 
1355
+ // The question the kernel asks before it lets a write through in any mode: is
1356
+ // this path one of the protected kinds (hooks, shell rc files, credential
1357
+ // homes, skill folders)? A host that runs a command in its own isolated
1358
+ // environment and copies the file changes back asks it here, with the same
1359
+ // name lists and the same path folding the kernel uses.
1360
+ export {
1361
+ isProtectedPath,
1362
+ PROJECT_DIRECTORY_AUTHORED_FOLDERS,
1363
+ PROTECTED_DIRECTORIES,
1364
+ PROTECTED_FILE_NAMES,
1365
+ PROTECTED_NESTED_DIRECTORIES,
1366
+ PROTECTED_ROOT_DIRECTORIES,
1367
+ } from './authorization/protected-paths.js'
1368
+ export type { ProtectedPathOptions } from './authorization/protected-paths.js'
1369
+
1323
1370
  // Where a command line actually execs a program — unwrapping `sudo`, `env`,
1324
1371
  // `nice`, `timeout` and the rest of a re-exec chain with their own real
1325
1372
  // option grammars, rather than assuming the program sits right after the
@@ -2123,6 +2170,7 @@ export {
2123
2170
  export {
2124
2171
  ChildOutcomeRecordedRecordSchema,
2125
2172
  ChildSessionMetaSchema,
2173
+ CompactionMeasuredRecordSchema,
2126
2174
  CompactionRecordSchema,
2127
2175
  ExternalRefSchema,
2128
2176
  IgnorableRecordSchema,
@@ -286,6 +286,7 @@ export { buildAgentTool, type AgentToolOptions } from './tools/coordinator/agent
286
286
  // jobs, draws the confirmation and computes every field it shows. Register
287
287
  // only where a person can confirm (never headless, scheduled or delegated).
288
288
  export {
289
+ buildScheduleSelfTool,
289
290
  buildScheduleTools,
290
291
  buildSessionLoopTools,
291
292
  buildSessionTimerTools,
@@ -293,6 +294,7 @@ export {
293
294
  clampWakeUpDelay,
294
295
  revealHiddenCharacters,
295
296
  scanSchedulePrompt,
297
+ SCHEDULE_SELF_TOOL_NAME,
296
298
  SCHEDULE_TOOL_NAME,
297
299
  SESSION_LOOP_TOOL_NAME,
298
300
  TIMER_CANCEL_TOOL_NAME,
@@ -254,6 +254,7 @@ export type {
254
254
  ShellHookOnFailure,
255
255
  ShellHookCall,
256
256
  ShellHookInput,
257
+ ShellHookHandlerType,
257
258
  ShellHookOptions,
258
259
  ShellHookPathFilter,
259
260
  ShellHookOutcome,
@@ -464,6 +465,10 @@ export type {
464
465
  SessionGoalStore,
465
466
  } from './store/goal/index.js'
466
467
  export type { ResolveGoalRoundAuthority } from './tools/goal/index.js'
468
+ export type {
469
+ GoalGateHost,
470
+ GoalGateRunInput,
471
+ } from './tools/goal/confirmation.js'
467
472
  export type {
468
473
  GoalConfirmationOptions,
469
474
  GoalDecision,
@@ -754,7 +759,10 @@ export type {
754
759
  ScheduleJobPreview,
755
760
  ScheduleJobSummary,
756
761
  ScheduleJobUpdateProposal,
762
+ ScheduleNoteSummary,
757
763
  ScheduleRuleEffect,
764
+ ScheduleSelfChanges,
765
+ ScheduleSelfHost,
758
766
  ScheduleToolHost,
759
767
  ScheduleUpdateRequest,
760
768
  SelfPacedHost,
@@ -63,16 +63,26 @@ function stripTrailingSlashes(value: string): string {
63
63
  export class HttpEmbeddingProvider implements EmbeddingProvider {
64
64
  readonly id = 'http-embedding'
65
65
  readonly model: string
66
- readonly dimensions: number
66
+ private observedDimensions: number | undefined
67
+
68
+ get dimensions(): number {
69
+ return this.observedDimensions ?? this.expectedDimensions
70
+ }
71
+
72
+ private readonly expectedDimensions: number
67
73
 
68
74
  private readonly apiKey: string
69
75
  private readonly baseUrl: string
70
76
  private readonly batchSize: number
77
+ private readonly useModelDimensions: boolean
78
+ private readonly fetch: NonNullable<HttpEmbeddingConfig['fetch']>
71
79
  private readonly requestTimeoutMs: number
72
80
 
73
81
  constructor(config: HttpEmbeddingConfig) {
74
82
  this.model = config.model
75
- this.dimensions = resolveDimensions(config.dimensions)
83
+ this.expectedDimensions = resolveDimensions(config.dimensions)
84
+ this.useModelDimensions = config.useModelDimensions === true
85
+ this.fetch = config.fetch ?? ((url, init) => fetch(url, init))
76
86
  this.apiKey = config.apiKey
77
87
  this.baseUrl = stripTrailingSlashes(config.baseUrl)
78
88
  this.batchSize = resolveBatchSize(config.batchSize)
@@ -156,16 +166,18 @@ export class HttpEmbeddingProvider implements EmbeddingProvider {
156
166
  }
157
167
 
158
168
  private async performEmbeddingRequest(texts: string[], signal: AbortSignal): Promise<number[][]> {
159
- const response = await fetch(`${this.baseUrl}/embeddings`, {
169
+ const response = await this.fetch(`${this.baseUrl}/embeddings`, {
160
170
  method: 'POST',
161
171
  headers: {
162
172
  'Content-Type': 'application/json',
163
- Authorization: `Bearer ${this.apiKey}`,
173
+ ...(!this.useModelDimensions || this.apiKey
174
+ ? { Authorization: `Bearer ${this.apiKey}` }
175
+ : {}),
164
176
  },
165
177
  body: JSON.stringify({
166
178
  model: this.model,
167
179
  input: texts,
168
- dimensions: this.dimensions,
180
+ ...(!this.useModelDimensions ? { dimensions: this.dimensions } : {}),
169
181
  }),
170
182
  signal,
171
183
  })
@@ -190,6 +202,7 @@ export class HttpEmbeddingProvider implements EmbeddingProvider {
190
202
 
191
203
  const embeddings = new Array<number[]>(expectedCount)
192
204
  const seen = new Set<number>()
205
+ let width = this.useModelDimensions ? this.observedDimensions : this.dimensions
193
206
  for (const item of value.data) {
194
207
  if (!isRecord(item) || !Number.isSafeInteger(item.index)) {
195
208
  throw new Error('Embedding API response contains a non-integer index')
@@ -203,20 +216,23 @@ export class HttpEmbeddingProvider implements EmbeddingProvider {
203
216
  }
204
217
  if (
205
218
  !Array.isArray(item.embedding) ||
206
- item.embedding.length !== this.dimensions ||
219
+ item.embedding.length === 0 ||
220
+ (width !== undefined && item.embedding.length !== width) ||
207
221
  !item.embedding.every(
208
222
  (coordinate) => typeof coordinate === 'number' && Number.isFinite(coordinate),
209
223
  )
210
224
  ) {
211
225
  throw new Error(
212
- `Embedding API response index ${index} must contain ${this.dimensions} finite numbers`,
226
+ `Embedding API response index ${index} must contain ${width ?? 'a nonempty array of'} finite numbers`,
213
227
  )
214
228
  }
215
229
 
230
+ width ??= item.embedding.length
216
231
  seen.add(index)
217
232
  embeddings[index] = item.embedding
218
233
  }
219
234
 
235
+ if (this.useModelDimensions) this.observedDimensions = width
220
236
  return embeddings
221
237
  }
222
238
  }
@@ -1,4 +1,5 @@
1
1
  import type { SessionGoalActivation } from '../../manager/goal/activation.js'
2
+ import { goalGateCommandText } from '../../store/goal/gates.js'
2
3
  import {
3
4
  GoalExistsError,
4
5
  GoalNotFoundError,
@@ -10,7 +11,15 @@ import {
10
11
  goalTokensText,
11
12
  } from '../../store/goal/index.js'
12
13
  import type { HostCommandDescriptor } from '../../types/command/index.js'
13
- import type { GoalConfirmedBy, GoalGuards, GoalRef, SessionGoal } from '../../types/goal/index.js'
14
+ import type {
15
+ GoalConfirmedBy,
16
+ GoalGateResult,
17
+ GoalGates,
18
+ GoalGatesSpec,
19
+ GoalGuards,
20
+ GoalRef,
21
+ SessionGoal,
22
+ } from '../../types/goal/index.js'
14
23
  import type { SessionId, TenantId } from '../../types/ids/index.js'
15
24
  import type { Skill } from '../../types/skills/index.js'
16
25
  import { isInvocableBy, skillInvocation } from '../../types/skills/index.js'
@@ -63,6 +72,10 @@ export interface GoalCommandScope {
63
72
  export interface GoalCommandDefaults {
64
73
  readonly maxGoalRounds?: number
65
74
  readonly guards?: GoalGuards
75
+ /** Completion gates a goal created here carries, shown when it starts. */
76
+ readonly gates?: GoalGatesSpec
77
+ /** A sentence added to a new goal's answer, for example why configured gates were left off. */
78
+ readonly gatesNotice?: string
66
79
  }
67
80
 
68
81
  const GOAL_ARGUMENTS =
@@ -189,6 +202,42 @@ function goalCommands(goal: SessionGoal, armed: boolean): string {
189
202
  return '/goal set <objective>, /goal clear'
190
203
  }
191
204
 
205
+ function gateResultText(result: GoalGateResult | undefined): string {
206
+ if (result === undefined) return 'not run yet'
207
+ const when = new Date(result.at).toISOString().replace('T', ' ').slice(0, 19)
208
+ switch (result.status) {
209
+ case 'passed':
210
+ return `passed (${when} UTC)${result.notRerun ? ', files unchanged since' : ''}`
211
+ case 'failed':
212
+ return `failed${result.exitCode !== undefined ? `, exit ${result.exitCode}` : ''} (${when} UTC)${result.notRerun ? ', not run again: files unchanged since' : ''}`
213
+ case 'timed-out':
214
+ return `timed out (${when} UTC)${result.notRerun ? ', not run again: files unchanged since' : ''}`
215
+ case 'refused':
216
+ return `not run: ${result.reason ?? 'refused'} (${when} UTC)`
217
+ }
218
+ }
219
+
220
+ /** The gates a goal carries and what they last showed, as lines of the status. */
221
+ export function renderGoalGates(gates: GoalGates | undefined): string[] {
222
+ if (gates === undefined || gates.entries.length === 0) return []
223
+ const lines = [
224
+ 'Completion gates (run by Namzu when each round ends; the goal is complete only when every one passes on the files as they are):',
225
+ ]
226
+ for (const [index, entry] of gates.entries.entries()) {
227
+ const result = gates.results.find((candidate) => candidate.name === entry.name)
228
+ const where = entry.cwd !== undefined ? ` in ${entry.cwd}` : ''
229
+ const limit =
230
+ entry.timeoutMs !== undefined ? `, limit ${Math.round(entry.timeoutMs / 1000)} s` : ''
231
+ lines.push(
232
+ ` ${index + 1}. ${entry.name}: ${goalGateCommandText(entry.command)}${where}${limit} - ${gateResultText(result)}`,
233
+ )
234
+ }
235
+ lines.push(
236
+ ` Failing rounds in a row: ${gates.failingRounds} of ${gates.maxFailingRounds}; the goal stops at ${gates.maxFailingRounds}.`,
237
+ )
238
+ return lines
239
+ }
240
+
192
241
  function renderGoal(
193
242
  title: string,
194
243
  goal: SessionGoal,
@@ -219,12 +268,17 @@ function renderGoal(
219
268
  ...(goal.missing && goal.missing.length > 0
220
269
  ? [`Still missing: ${goal.missing.join('; ')}`]
221
270
  : []),
271
+ ...renderGoalGates(goal.gates),
222
272
  `Objective: ${goal.objective}`,
223
273
  '',
224
274
  `Commands: ${goalCommands(goal, armed)}`,
225
275
  ].join('\n')
226
276
  }
227
277
 
278
+ function withGatesNotice(message: string, defaults: GoalCommandDefaults | undefined): string {
279
+ return defaults?.gatesNotice ? `${message}\n${defaults.gatesNotice}` : message
280
+ }
281
+
228
282
  function renderScopedGoal(title: string, goal: SessionGoal, scope: GoalCommandScope): string {
229
283
  return renderGoal(
230
284
  title,
@@ -306,13 +360,14 @@ async function runGoalCommand(scope: GoalCommandScope | undefined, args: readonl
306
360
  ...(maxGoalRounds !== undefined ? { maxGoalRounds } : {}),
307
361
  ...(Object.keys(guards).length > 0 ? { guards } : {}),
308
362
  ...(flag.confirmedBy !== undefined ? { confirmedBy: flag.confirmedBy } : {}),
363
+ ...(defaults?.gates ? { gates: defaults.gates } : {}),
309
364
  },
310
365
  scope.tenantId,
311
366
  )
312
367
  scope.activation?.arm(created)
313
368
  return {
314
369
  kind: 'ack' as const,
315
- message: renderScopedGoal('Goal created', created, scope),
370
+ message: withGatesNotice(renderScopedGoal('Goal created', created, scope), defaults),
316
371
  }
317
372
  }
318
373
  case 'edit': {
@@ -326,13 +381,17 @@ async function runGoalCommand(scope: GoalCommandScope | undefined, args: readonl
326
381
  ? { maxGoalRounds: scope.defaults.maxGoalRounds }
327
382
  : {}),
328
383
  ...(scope.defaults?.guards ? { guards: scope.defaults.guards } : {}),
384
+ ...(scope.defaults?.gates ? { gates: scope.defaults.gates } : {}),
329
385
  },
330
386
  scope.tenantId,
331
387
  )
332
388
  scope.activation?.arm(replacement)
333
389
  return {
334
390
  kind: 'ack' as const,
335
- message: renderScopedGoal('Goal created', replacement, scope),
391
+ message: withGatesNotice(
392
+ renderScopedGoal('Goal created', replacement, scope),
393
+ scope.defaults,
394
+ ),
336
395
  }
337
396
  }
338
397
  const wasArmed = scope.activation?.isArmed(scope.sessionId, current) ?? false
@@ -107,3 +107,17 @@ export function toolDiscoveryHint(description: string, maxLength = 100): string
107
107
  if (sentence.length <= maxLength) return sentence
108
108
  return `${sentence.slice(0, maxLength - 1).trimEnd()}…`
109
109
  }
110
+
111
+ /**
112
+ * The catalogue line of a deferred tool: its explicit `discoveryHint` when it
113
+ * has one, else the first-sentence rule of {@link toolDiscoveryHint}.
114
+ */
115
+ export function toolCatalogueHint(
116
+ tool: { readonly description: string; readonly discoveryHint?: string },
117
+ maxLength = 100,
118
+ ): string {
119
+ const explicit = tool.discoveryHint?.trim().replace(/\s+/g, ' ') ?? ''
120
+ if (explicit.length === 0) return toolDiscoveryHint(tool.description, maxLength)
121
+ if (explicit.length <= maxLength) return explicit
122
+ return `${explicit.slice(0, maxLength - 1).trimEnd()}…`
123
+ }
@@ -8,6 +8,7 @@ import {
8
8
  } from '../../store/session-log/index.js'
9
9
  import { NamzuError } from '../../types/errors/index.js'
10
10
  import type { SessionId, TurnId } from '../../types/ids/index.js'
11
+ import { TurnInProgressError } from '../../types/session/turn.js'
11
12
 
12
13
  /** How a session-level operation finds the session's log. */
13
14
  export interface SessionLocatorOptions {
@@ -91,6 +92,14 @@ export async function withSessionLease<T>(
91
92
  ttlMs: OPERATION_LEASE_TTL_MS,
92
93
  })
93
94
  if (!claimed) {
95
+ const active = await log.activeTurn()
96
+ if (active?.state === 'running') {
97
+ throw new TurnInProgressError({
98
+ sessionId: log.sessionId,
99
+ activeTurnId: active.turnId,
100
+ state: active.state,
101
+ })
102
+ }
94
103
  throw new NamzuError({
95
104
  code: 'invalid_config',
96
105
  message: `Session ${log.sessionId} is leased by a live writer; pass its lease, or wait for it to finish.`,