@namzu/sdk 0.1.3 → 0.1.4-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (412) hide show
  1. package/CHANGELOG.md +45 -29
  2. package/README.md +14 -2
  3. package/dist/advisory/context.d.ts +23 -0
  4. package/dist/advisory/context.d.ts.map +1 -0
  5. package/dist/advisory/context.js +33 -0
  6. package/dist/advisory/context.js.map +1 -0
  7. package/dist/advisory/evaluator.d.ts +14 -0
  8. package/dist/advisory/evaluator.d.ts.map +1 -0
  9. package/dist/advisory/evaluator.js +87 -0
  10. package/dist/advisory/evaluator.js.map +1 -0
  11. package/dist/advisory/executor.d.ts +40 -0
  12. package/dist/advisory/executor.d.ts.map +1 -0
  13. package/dist/advisory/executor.js +132 -0
  14. package/dist/advisory/executor.js.map +1 -0
  15. package/dist/advisory/index.d.ts +6 -0
  16. package/dist/advisory/index.d.ts.map +1 -0
  17. package/dist/advisory/index.js +5 -0
  18. package/dist/advisory/index.js.map +1 -0
  19. package/dist/advisory/registry.d.ts +14 -0
  20. package/dist/advisory/registry.d.ts.map +1 -0
  21. package/dist/advisory/registry.js +36 -0
  22. package/dist/advisory/registry.js.map +1 -0
  23. package/dist/agents/ReactiveAgent.d.ts.map +1 -1
  24. package/dist/agents/ReactiveAgent.js +1 -0
  25. package/dist/agents/ReactiveAgent.js.map +1 -1
  26. package/dist/agents/SupervisorAgent.d.ts.map +1 -1
  27. package/dist/agents/SupervisorAgent.js +12 -1
  28. package/dist/agents/SupervisorAgent.js.map +1 -1
  29. package/dist/bridge/a2a/mapper.d.ts.map +1 -1
  30. package/dist/bridge/a2a/mapper.js +2 -0
  31. package/dist/bridge/a2a/mapper.js.map +1 -1
  32. package/dist/bridge/sse/mapper.d.ts.map +1 -1
  33. package/dist/bridge/sse/mapper.js +17 -0
  34. package/dist/bridge/sse/mapper.js.map +1 -1
  35. package/dist/bus/breaker.d.ts +18 -0
  36. package/dist/bus/breaker.d.ts.map +1 -0
  37. package/dist/bus/breaker.js +158 -0
  38. package/dist/bus/breaker.js.map +1 -0
  39. package/dist/bus/index.d.ts +33 -0
  40. package/dist/bus/index.d.ts.map +1 -0
  41. package/dist/bus/index.js +72 -0
  42. package/dist/bus/index.js.map +1 -0
  43. package/dist/bus/lock.d.ts +27 -0
  44. package/dist/bus/lock.d.ts.map +1 -0
  45. package/dist/bus/lock.js +194 -0
  46. package/dist/bus/lock.js.map +1 -0
  47. package/dist/bus/ownership.d.ts +18 -0
  48. package/dist/bus/ownership.d.ts.map +1 -0
  49. package/dist/bus/ownership.js +111 -0
  50. package/dist/bus/ownership.js.map +1 -0
  51. package/dist/compaction/extractor.d.ts +7 -0
  52. package/dist/compaction/extractor.d.ts.map +1 -0
  53. package/dist/compaction/extractor.js +131 -0
  54. package/dist/compaction/extractor.js.map +1 -0
  55. package/dist/compaction/index.d.ts +6 -0
  56. package/dist/compaction/index.d.ts.map +1 -0
  57. package/dist/compaction/index.js +5 -0
  58. package/dist/compaction/index.js.map +1 -0
  59. package/dist/compaction/manager.d.ts +22 -0
  60. package/dist/compaction/manager.d.ts.map +1 -0
  61. package/dist/compaction/manager.js +91 -0
  62. package/dist/compaction/manager.js.map +1 -0
  63. package/dist/compaction/serializer.d.ts +3 -0
  64. package/dist/compaction/serializer.d.ts.map +1 -0
  65. package/dist/compaction/serializer.js +67 -0
  66. package/dist/compaction/serializer.js.map +1 -0
  67. package/dist/compaction/types.d.ts +40 -0
  68. package/dist/compaction/types.d.ts.map +1 -0
  69. package/dist/compaction/types.js +2 -0
  70. package/dist/compaction/types.js.map +1 -0
  71. package/dist/compaction/verifier.d.ts +6 -0
  72. package/dist/compaction/verifier.d.ts.map +1 -0
  73. package/dist/compaction/verifier.js +68 -0
  74. package/dist/compaction/verifier.js.map +1 -0
  75. package/dist/config/runtime.d.ts +328 -0
  76. package/dist/config/runtime.d.ts.map +1 -1
  77. package/dist/config/runtime.js +51 -0
  78. package/dist/config/runtime.js.map +1 -1
  79. package/dist/constants/advisory/index.d.ts +8 -0
  80. package/dist/constants/advisory/index.d.ts.map +1 -0
  81. package/dist/constants/advisory/index.js +8 -0
  82. package/dist/constants/advisory/index.js.map +1 -0
  83. package/dist/constants/bus/index.d.ts +7 -0
  84. package/dist/constants/bus/index.d.ts.map +1 -0
  85. package/dist/constants/bus/index.js +7 -0
  86. package/dist/constants/bus/index.js.map +1 -0
  87. package/dist/constants/compaction/index.d.ts +17 -0
  88. package/dist/constants/compaction/index.d.ts.map +1 -0
  89. package/dist/constants/compaction/index.js +17 -0
  90. package/dist/constants/compaction/index.js.map +1 -0
  91. package/dist/constants/emergency.d.ts +4 -0
  92. package/dist/constants/emergency.d.ts.map +1 -0
  93. package/dist/constants/emergency.js +4 -0
  94. package/dist/constants/emergency.js.map +1 -0
  95. package/dist/constants/index.d.ts +6 -0
  96. package/dist/constants/index.d.ts.map +1 -1
  97. package/dist/constants/index.js +6 -0
  98. package/dist/constants/index.js.map +1 -1
  99. package/dist/constants/limits.d.ts +1 -0
  100. package/dist/constants/limits.d.ts.map +1 -1
  101. package/dist/constants/limits.js +1 -0
  102. package/dist/constants/limits.js.map +1 -1
  103. package/dist/constants/plugin/index.d.ts +21 -0
  104. package/dist/constants/plugin/index.d.ts.map +1 -0
  105. package/dist/constants/plugin/index.js +21 -0
  106. package/dist/constants/plugin/index.js.map +1 -0
  107. package/dist/constants/verification/index.d.ts +2 -0
  108. package/dist/constants/verification/index.d.ts.map +1 -0
  109. package/dist/constants/verification/index.js +2 -0
  110. package/dist/constants/verification/index.js.map +1 -0
  111. package/dist/contracts/api.d.ts +1 -1
  112. package/dist/contracts/api.d.ts.map +1 -1
  113. package/dist/contracts/schemas.d.ts +20 -20
  114. package/dist/index.d.ts +24 -2
  115. package/dist/index.d.ts.map +1 -1
  116. package/dist/index.js +17 -1
  117. package/dist/index.js.map +1 -1
  118. package/dist/manager/run/emergency.d.ts +19 -0
  119. package/dist/manager/run/emergency.d.ts.map +1 -0
  120. package/dist/manager/run/emergency.js +88 -0
  121. package/dist/manager/run/emergency.js.map +1 -0
  122. package/dist/manager/run/persistence.d.ts +2 -0
  123. package/dist/manager/run/persistence.d.ts.map +1 -1
  124. package/dist/manager/run/persistence.js +14 -0
  125. package/dist/manager/run/persistence.js.map +1 -1
  126. package/dist/persona/assembler.d.ts +2 -1
  127. package/dist/persona/assembler.d.ts.map +1 -1
  128. package/dist/persona/assembler.js +23 -0
  129. package/dist/persona/assembler.js.map +1 -1
  130. package/dist/plugin/index.d.ts +4 -0
  131. package/dist/plugin/index.d.ts.map +1 -0
  132. package/dist/plugin/index.js +4 -0
  133. package/dist/plugin/index.js.map +1 -0
  134. package/dist/plugin/lifecycle.d.ts +30 -0
  135. package/dist/plugin/lifecycle.d.ts.map +1 -0
  136. package/dist/plugin/lifecycle.js +227 -0
  137. package/dist/plugin/lifecycle.js.map +1 -0
  138. package/dist/plugin/loader.d.ts +25 -0
  139. package/dist/plugin/loader.d.ts.map +1 -0
  140. package/dist/plugin/loader.js +76 -0
  141. package/dist/plugin/loader.js.map +1 -0
  142. package/dist/plugin/resolver.d.ts +36 -0
  143. package/dist/plugin/resolver.d.ts.map +1 -0
  144. package/dist/plugin/resolver.js +80 -0
  145. package/dist/plugin/resolver.js.map +1 -0
  146. package/dist/registry/plugin/index.d.ts +9 -0
  147. package/dist/registry/plugin/index.d.ts.map +1 -0
  148. package/dist/registry/plugin/index.js +16 -0
  149. package/dist/registry/plugin/index.js.map +1 -0
  150. package/dist/registry/tool/execute.d.ts +3 -0
  151. package/dist/registry/tool/execute.d.ts.map +1 -1
  152. package/dist/registry/tool/execute.js +45 -11
  153. package/dist/registry/tool/execute.js.map +1 -1
  154. package/dist/router/index.d.ts +2 -0
  155. package/dist/router/index.d.ts.map +1 -0
  156. package/dist/router/index.js +2 -0
  157. package/dist/router/index.js.map +1 -0
  158. package/dist/router/task-router.d.ts +8 -0
  159. package/dist/router/task-router.d.ts.map +1 -0
  160. package/dist/router/task-router.js +19 -0
  161. package/dist/router/task-router.js.map +1 -0
  162. package/dist/run/reporter.d.ts.map +1 -1
  163. package/dist/run/reporter.js +15 -0
  164. package/dist/run/reporter.js.map +1 -1
  165. package/dist/runtime/query/context-cache.d.ts +6 -0
  166. package/dist/runtime/query/context-cache.d.ts.map +1 -1
  167. package/dist/runtime/query/context-cache.js +36 -0
  168. package/dist/runtime/query/context-cache.js.map +1 -1
  169. package/dist/runtime/query/executor.d.ts +4 -0
  170. package/dist/runtime/query/executor.d.ts.map +1 -1
  171. package/dist/runtime/query/executor.js +30 -1
  172. package/dist/runtime/query/executor.js.map +1 -1
  173. package/dist/runtime/query/index.d.ts +10 -0
  174. package/dist/runtime/query/index.d.ts.map +1 -1
  175. package/dist/runtime/query/index.js +77 -12
  176. package/dist/runtime/query/index.js.map +1 -1
  177. package/dist/runtime/query/iteration/index.d.ts +9 -0
  178. package/dist/runtime/query/iteration/index.d.ts.map +1 -1
  179. package/dist/runtime/query/iteration/index.js +40 -0
  180. package/dist/runtime/query/iteration/index.js.map +1 -1
  181. package/dist/runtime/query/iteration/phases/advisory.d.ts +4 -0
  182. package/dist/runtime/query/iteration/phases/advisory.d.ts.map +1 -0
  183. package/dist/runtime/query/iteration/phases/advisory.js +150 -0
  184. package/dist/runtime/query/iteration/phases/advisory.js.map +1 -0
  185. package/dist/runtime/query/iteration/phases/compaction.d.ts +3 -0
  186. package/dist/runtime/query/iteration/phases/compaction.d.ts.map +1 -0
  187. package/dist/runtime/query/iteration/phases/compaction.js +87 -0
  188. package/dist/runtime/query/iteration/phases/compaction.js.map +1 -0
  189. package/dist/runtime/query/iteration/phases/context.d.ts +10 -0
  190. package/dist/runtime/query/iteration/phases/context.d.ts.map +1 -1
  191. package/dist/runtime/query/iteration/phases/context.js.map +1 -1
  192. package/dist/runtime/query/iteration/phases/index.d.ts +2 -0
  193. package/dist/runtime/query/iteration/phases/index.d.ts.map +1 -1
  194. package/dist/runtime/query/iteration/phases/index.js +2 -0
  195. package/dist/runtime/query/iteration/phases/index.js.map +1 -1
  196. package/dist/runtime/query/iteration/phases/tool-review.d.ts +6 -1
  197. package/dist/runtime/query/iteration/phases/tool-review.d.ts.map +1 -1
  198. package/dist/runtime/query/iteration/phases/tool-review.js +39 -0
  199. package/dist/runtime/query/iteration/phases/tool-review.js.map +1 -1
  200. package/dist/runtime/query/prompt.d.ts +7 -0
  201. package/dist/runtime/query/prompt.d.ts.map +1 -1
  202. package/dist/runtime/query/prompt.js +44 -0
  203. package/dist/runtime/query/prompt.js.map +1 -1
  204. package/dist/store/memory/disk.d.ts +30 -0
  205. package/dist/store/memory/disk.d.ts.map +1 -0
  206. package/dist/store/memory/disk.js +154 -0
  207. package/dist/store/memory/disk.js.map +1 -0
  208. package/dist/store/memory/index.d.ts +13 -0
  209. package/dist/store/memory/index.d.ts.map +1 -0
  210. package/dist/store/memory/index.js +46 -0
  211. package/dist/store/memory/index.js.map +1 -0
  212. package/dist/store/memory/memory.d.ts +17 -0
  213. package/dist/store/memory/memory.d.ts.map +1 -0
  214. package/dist/store/memory/memory.js +72 -0
  215. package/dist/store/memory/memory.js.map +1 -0
  216. package/dist/tools/advisory/index.d.ts +7 -0
  217. package/dist/tools/advisory/index.d.ts.map +1 -0
  218. package/dist/tools/advisory/index.js +125 -0
  219. package/dist/tools/advisory/index.js.map +1 -0
  220. package/dist/tools/defineTool.d.ts +1 -0
  221. package/dist/tools/defineTool.d.ts.map +1 -1
  222. package/dist/tools/defineTool.js +1 -0
  223. package/dist/tools/defineTool.js.map +1 -1
  224. package/dist/tools/memory/index.d.ts +7 -0
  225. package/dist/tools/memory/index.d.ts.map +1 -0
  226. package/dist/tools/memory/index.js +10 -0
  227. package/dist/tools/memory/index.js.map +1 -0
  228. package/dist/tools/memory/read.d.ts +4 -0
  229. package/dist/tools/memory/read.d.ts.map +1 -0
  230. package/dist/tools/memory/read.js +37 -0
  231. package/dist/tools/memory/read.js.map +1 -0
  232. package/dist/tools/memory/save.d.ts +4 -0
  233. package/dist/tools/memory/save.d.ts.map +1 -0
  234. package/dist/tools/memory/save.js +37 -0
  235. package/dist/tools/memory/save.js.map +1 -0
  236. package/dist/tools/memory/search.d.ts +4 -0
  237. package/dist/tools/memory/search.d.ts.map +1 -0
  238. package/dist/tools/memory/search.js +41 -0
  239. package/dist/tools/memory/search.js.map +1 -0
  240. package/dist/types/advisory/config.d.ts +33 -0
  241. package/dist/types/advisory/config.d.ts.map +1 -0
  242. package/dist/types/advisory/config.js +2 -0
  243. package/dist/types/advisory/config.js.map +1 -0
  244. package/dist/types/advisory/index.d.ts +4 -0
  245. package/dist/types/advisory/index.d.ts.map +1 -0
  246. package/dist/types/advisory/index.js +2 -0
  247. package/dist/types/advisory/index.js.map +1 -0
  248. package/dist/types/advisory/result.d.ts +35 -0
  249. package/dist/types/advisory/result.d.ts.map +1 -0
  250. package/dist/types/advisory/result.js +2 -0
  251. package/dist/types/advisory/result.js.map +1 -0
  252. package/dist/types/advisory/trigger.d.ts +44 -0
  253. package/dist/types/advisory/trigger.d.ts.map +1 -0
  254. package/dist/types/advisory/trigger.js +2 -0
  255. package/dist/types/advisory/trigger.js.map +1 -0
  256. package/dist/types/agent/factory.d.ts +2 -0
  257. package/dist/types/agent/factory.d.ts.map +1 -1
  258. package/dist/types/agent/reactive.d.ts +2 -0
  259. package/dist/types/agent/reactive.d.ts.map +1 -1
  260. package/dist/types/agent/supervisor.d.ts +4 -0
  261. package/dist/types/agent/supervisor.d.ts.map +1 -1
  262. package/dist/types/bus/index.d.ts +96 -0
  263. package/dist/types/bus/index.d.ts.map +1 -0
  264. package/dist/types/bus/index.js +2 -0
  265. package/dist/types/bus/index.js.map +1 -0
  266. package/dist/types/ids/index.d.ts +6 -0
  267. package/dist/types/ids/index.d.ts.map +1 -1
  268. package/dist/types/memory/index.d.ts +54 -0
  269. package/dist/types/memory/index.d.ts.map +1 -0
  270. package/dist/types/memory/index.js +12 -0
  271. package/dist/types/memory/index.js.map +1 -0
  272. package/dist/types/message/index.d.ts +3 -1
  273. package/dist/types/message/index.d.ts.map +1 -1
  274. package/dist/types/message/index.js +7 -2
  275. package/dist/types/message/index.js.map +1 -1
  276. package/dist/types/persona/index.d.ts +9 -0
  277. package/dist/types/persona/index.d.ts.map +1 -1
  278. package/dist/types/plugin/index.d.ts +186 -0
  279. package/dist/types/plugin/index.d.ts.map +1 -0
  280. package/dist/types/plugin/index.js +90 -0
  281. package/dist/types/plugin/index.js.map +1 -0
  282. package/dist/types/router/index.d.ts +2 -0
  283. package/dist/types/router/index.d.ts.map +1 -0
  284. package/dist/types/router/index.js +2 -0
  285. package/dist/types/router/index.js.map +1 -0
  286. package/dist/types/router/task-router.d.ts +12 -0
  287. package/dist/types/router/task-router.d.ts.map +1 -0
  288. package/dist/types/router/task-router.js +2 -0
  289. package/dist/types/router/task-router.js.map +1 -0
  290. package/dist/types/run/emergency.d.ts +27 -0
  291. package/dist/types/run/emergency.d.ts.map +1 -0
  292. package/dist/types/run/emergency.js +6 -0
  293. package/dist/types/run/emergency.js.map +1 -0
  294. package/dist/types/run/events.d.ts +13 -1
  295. package/dist/types/run/events.d.ts.map +1 -1
  296. package/dist/types/run/index.d.ts +1 -0
  297. package/dist/types/run/index.d.ts.map +1 -1
  298. package/dist/types/run/index.js +1 -0
  299. package/dist/types/run/index.js.map +1 -1
  300. package/dist/types/tool/index.d.ts +13 -0
  301. package/dist/types/tool/index.d.ts.map +1 -1
  302. package/dist/types/verification/index.d.ts +219 -0
  303. package/dist/types/verification/index.d.ts.map +1 -0
  304. package/dist/types/verification/index.js +43 -0
  305. package/dist/types/verification/index.js.map +1 -0
  306. package/dist/utils/id.d.ts +7 -1
  307. package/dist/utils/id.d.ts.map +1 -1
  308. package/dist/utils/id.js +18 -0
  309. package/dist/utils/id.js.map +1 -1
  310. package/dist/utils/shell-compress.d.ts +13 -0
  311. package/dist/utils/shell-compress.d.ts.map +1 -0
  312. package/dist/utils/shell-compress.js +97 -0
  313. package/dist/utils/shell-compress.js.map +1 -0
  314. package/dist/verification/gate.d.ts +19 -0
  315. package/dist/verification/gate.d.ts.map +1 -0
  316. package/dist/verification/gate.js +103 -0
  317. package/dist/verification/gate.js.map +1 -0
  318. package/dist/verification/index.d.ts +3 -0
  319. package/dist/verification/index.d.ts.map +1 -0
  320. package/dist/verification/index.js +3 -0
  321. package/dist/verification/index.js.map +1 -0
  322. package/dist/verification/rules.d.ts +4 -0
  323. package/dist/verification/rules.d.ts.map +1 -0
  324. package/dist/verification/rules.js +61 -0
  325. package/dist/verification/rules.js.map +1 -0
  326. package/package.json +5 -1
  327. package/src/advisory/context.ts +47 -0
  328. package/src/advisory/evaluator.ts +98 -0
  329. package/src/advisory/executor.ts +187 -0
  330. package/src/advisory/index.ts +5 -0
  331. package/src/advisory/registry.ts +42 -0
  332. package/src/agents/ReactiveAgent.ts +1 -0
  333. package/src/agents/SupervisorAgent.ts +13 -1
  334. package/src/bridge/a2a/mapper.ts +3 -0
  335. package/src/bridge/sse/mapper.ts +19 -0
  336. package/src/bus/breaker.ts +192 -0
  337. package/src/bus/index.ts +120 -0
  338. package/src/bus/lock.ts +233 -0
  339. package/src/bus/ownership.ts +133 -0
  340. package/src/compaction/extractor.ts +149 -0
  341. package/src/compaction/index.ts +21 -0
  342. package/src/compaction/manager.ts +107 -0
  343. package/src/compaction/serializer.ts +88 -0
  344. package/src/compaction/types.ts +37 -0
  345. package/src/compaction/verifier.ts +91 -0
  346. package/src/config/runtime.ts +64 -0
  347. package/src/constants/advisory/index.ts +7 -0
  348. package/src/constants/bus/index.ts +6 -0
  349. package/src/constants/compaction/index.ts +20 -0
  350. package/src/constants/emergency.ts +3 -0
  351. package/src/constants/index.ts +6 -0
  352. package/src/constants/limits.ts +2 -0
  353. package/src/constants/plugin/index.ts +25 -0
  354. package/src/constants/verification/index.ts +1 -0
  355. package/src/contracts/api.ts +2 -0
  356. package/src/index.ts +69 -2
  357. package/src/manager/run/emergency.ts +117 -0
  358. package/src/manager/run/persistence.ts +16 -0
  359. package/src/persona/assembler.ts +36 -1
  360. package/src/plugin/index.ts +3 -0
  361. package/src/plugin/lifecycle.ts +308 -0
  362. package/src/plugin/loader.ts +91 -0
  363. package/src/plugin/resolver.ts +95 -0
  364. package/src/registry/plugin/index.ts +20 -0
  365. package/src/registry/tool/execute.ts +51 -11
  366. package/src/router/index.ts +1 -0
  367. package/src/router/task-router.ts +24 -0
  368. package/src/run/reporter.ts +17 -0
  369. package/src/runtime/query/context-cache.ts +50 -0
  370. package/src/runtime/query/executor.ts +37 -1
  371. package/src/runtime/query/index.ts +125 -12
  372. package/src/runtime/query/iteration/index.ts +60 -0
  373. package/src/runtime/query/iteration/phases/advisory.ts +185 -0
  374. package/src/runtime/query/iteration/phases/compaction.ts +98 -0
  375. package/src/runtime/query/iteration/phases/context.ts +16 -0
  376. package/src/runtime/query/iteration/phases/index.ts +2 -0
  377. package/src/runtime/query/iteration/phases/tool-review.ts +52 -1
  378. package/src/runtime/query/prompt.ts +64 -0
  379. package/src/store/memory/disk.ts +205 -0
  380. package/src/store/memory/index.ts +68 -0
  381. package/src/store/memory/memory.ts +103 -0
  382. package/src/tools/advisory/index.ts +157 -0
  383. package/src/tools/defineTool.ts +2 -0
  384. package/src/tools/memory/index.ts +13 -0
  385. package/src/tools/memory/read.ts +42 -0
  386. package/src/tools/memory/save.ts +40 -0
  387. package/src/tools/memory/search.ts +52 -0
  388. package/src/types/advisory/config.ts +35 -0
  389. package/src/types/advisory/index.ts +18 -0
  390. package/src/types/advisory/result.ts +34 -0
  391. package/src/types/advisory/trigger.ts +39 -0
  392. package/src/types/agent/factory.ts +3 -0
  393. package/src/types/agent/reactive.ts +3 -0
  394. package/src/types/agent/supervisor.ts +6 -0
  395. package/src/types/bus/index.ts +53 -0
  396. package/src/types/ids/index.ts +6 -0
  397. package/src/types/memory/index.ts +69 -0
  398. package/src/types/message/index.ts +10 -2
  399. package/src/types/persona/index.ts +11 -0
  400. package/src/types/plugin/index.ts +231 -0
  401. package/src/types/router/index.ts +1 -0
  402. package/src/types/router/task-router.ts +20 -0
  403. package/src/types/run/emergency.ts +23 -0
  404. package/src/types/run/events.ts +15 -1
  405. package/src/types/run/index.ts +1 -0
  406. package/src/types/tool/index.ts +15 -0
  407. package/src/types/verification/index.ts +69 -0
  408. package/src/utils/id.ts +28 -0
  409. package/src/utils/shell-compress.ts +137 -0
  410. package/src/verification/gate.ts +136 -0
  411. package/src/verification/index.ts +2 -0
  412. package/src/verification/rules.ts +78 -0
@@ -1,12 +1,17 @@
1
1
  import { createUserMessage } from '../../../../types/message/index.js'
2
2
  import type { ChatCompletionResponse } from '../../../../types/provider/index.js'
3
3
  import type { RunEvent } from '../../../../types/run/index.js'
4
+ import type { VerificationGate } from '../../../../verification/index.js'
4
5
  import type { IterationContext } from './context.js'
5
6
 
7
+ interface VerificationAwareContext extends IterationContext {
8
+ readonly verificationGate?: VerificationGate
9
+ }
10
+
6
11
  export type ToolReviewOutcome = 'executed' | 'rejected' | 'stop'
7
12
 
8
13
  export async function* runToolReview(
9
- ctx: IterationContext,
14
+ ctx: VerificationAwareContext,
10
15
  response: ChatCompletionResponse,
11
16
  iterationNum: number,
12
17
  ): AsyncGenerator<RunEvent, ToolReviewOutcome> {
@@ -33,6 +38,52 @@ export async function* runToolReview(
33
38
  }
34
39
  })
35
40
 
41
+ if (ctx.verificationGate) {
42
+ const gate = ctx.verificationGate
43
+ const gateResults = toolCallSummaries.map((tc) => ({
44
+ toolCall: tc,
45
+ gateResult: gate.evaluate({
46
+ toolName: tc.name,
47
+ toolInput: tc.input,
48
+ toolDef: ctx.tools.get(tc.name),
49
+ }),
50
+ }))
51
+
52
+ const allAllowed = gateResults.every((gr) => gr.gateResult.decision === 'allow')
53
+ const allDenied = gateResults.every((gr) => gr.gateResult.decision === 'deny')
54
+
55
+ if (allAllowed) {
56
+ ctx.log.debug('Verification gate: all tool calls pre-approved', {
57
+ tools: gateResults.map((gr) => gr.toolCall.name),
58
+ })
59
+ const batch = await ctx.toolExecutor.executeBatch(response)
60
+ for (const msg of batch.messages) {
61
+ ctx.sessionMgr.pushMessage(msg)
62
+ }
63
+ return 'executed'
64
+ }
65
+
66
+ if (allDenied) {
67
+ const reasons = gateResults
68
+ .map((gr) => `${gr.toolCall.name}: ${gr.gateResult.reason}`)
69
+ .join('; ')
70
+ ctx.log.debug('Verification gate: all tool calls denied', {
71
+ tools: gateResults.map((gr) => gr.toolCall.name),
72
+ })
73
+ ctx.sessionMgr.pushMessage(
74
+ createUserMessage(`[SYSTEM] Tool calls blocked by verification gate: ${reasons}`),
75
+ )
76
+ return 'rejected'
77
+ }
78
+
79
+ ctx.log.debug('Verification gate: mixed decisions, proceeding to review', {
80
+ decisions: gateResults.map((gr) => ({
81
+ tool: gr.toolCall.name,
82
+ decision: gr.gateResult.decision,
83
+ })),
84
+ })
85
+ }
86
+
36
87
  const reviewCheckpoint = await ctx.checkpointMgr.create(ctx.sessionMgr, iterationNum)
37
88
 
38
89
  await ctx.emitEvent({
@@ -5,6 +5,13 @@ import type { AgentContextLevel } from '../../types/agent/factory.js'
5
5
  import type { AgentPersona } from '../../types/persona/index.js'
6
6
  import type { Skill } from '../../types/skills/index.js'
7
7
 
8
+ export interface PromptSegments {
9
+ /** Layers 1-6: basePrompt, persona identity/expertise/reflexes/skills/outputDiscipline. Stable within a session. */
10
+ readonly static: string
11
+ /** Layers 7-10: tools, tier guidance, env context, sessionContext. May change per run. */
12
+ readonly dynamic: string
13
+ }
14
+
8
15
  export interface PromptBuilderConfig {
9
16
  systemPrompt?: string
10
17
 
@@ -57,6 +64,11 @@ export class PromptBuilder {
57
64
  if (toolSection) {
58
65
  parts.push(toolSection)
59
66
  }
67
+
68
+ const tierGuidance = this.config.tools.toTierGuidance()
69
+ if (tierGuidance) {
70
+ parts.push(tierGuidance)
71
+ }
60
72
  }
61
73
 
62
74
  if (
@@ -69,4 +81,56 @@ export class PromptBuilder {
69
81
 
70
82
  return parts.join('\n\n---\n\n')
71
83
  }
84
+
85
+ buildSegmented(
86
+ contextLevel: AgentContextLevel = 'full',
87
+ workingDirectory?: string,
88
+ ): PromptSegments {
89
+ const separator = '\n\n---\n\n'
90
+ const staticParts: string[] = []
91
+ const dynamicParts: string[] = []
92
+
93
+ if (contextLevel === 'full' && this.config.basePrompt) {
94
+ staticParts.push(this.config.basePrompt)
95
+ }
96
+
97
+ if (this.config.systemPrompt) {
98
+ staticParts.push(this.config.systemPrompt)
99
+ } else if (this.config.persona) {
100
+ const personaWithoutSession: AgentPersona = {
101
+ ...this.config.persona,
102
+ sessionContext: undefined,
103
+ }
104
+ staticParts.push(assembleSystemPrompt(personaWithoutSession, this.config.skills))
105
+
106
+ if (this.config.persona.sessionContext) {
107
+ dynamicParts.push(`## Session Context\n${this.config.persona.sessionContext.trim()}`)
108
+ }
109
+ }
110
+
111
+ if (contextLevel !== 'minimal') {
112
+ const toolSection = this.config.tools.toPromptSection(this.config.allowedTools)
113
+ if (toolSection) {
114
+ dynamicParts.push(toolSection)
115
+ }
116
+
117
+ const tierGuidance = this.config.tools.toTierGuidance()
118
+ if (tierGuidance) {
119
+ dynamicParts.push(tierGuidance)
120
+ }
121
+ }
122
+
123
+ if (
124
+ contextLevel !== 'minimal' &&
125
+ workingDirectory &&
126
+ hasFilesystemTools(this.config.tools, this.config.allowedTools)
127
+ ) {
128
+ dynamicParts.push(buildEnvContext(workingDirectory))
129
+ }
130
+
131
+ return {
132
+ static: staticParts.join(separator),
133
+ dynamic: dynamicParts.join(separator),
134
+ }
135
+ }
72
136
  }
@@ -0,0 +1,205 @@
1
+ import { mkdir, readFile, rename, unlink, writeFile } from 'node:fs/promises'
2
+ import { join } from 'node:path'
3
+ import type { MemoryId } from '../../types/ids/index.js'
4
+ import type {
5
+ CreateMemoryParams,
6
+ MemoryContent,
7
+ MemoryIndexEntry,
8
+ MemorySearchParams,
9
+ MemorySearchResult,
10
+ MemoryStore,
11
+ } from '../../types/memory/index.js'
12
+ import { generateMemoryId } from '../../utils/id.js'
13
+ import { type Logger, getRootLogger } from '../../utils/logger.js'
14
+ import { InMemoryMemoryIndex } from './index.js'
15
+
16
+ export interface DiskMemoryStoreConfig {
17
+ baseDir: string
18
+ logger?: Logger
19
+ }
20
+
21
+ export class DiskMemoryStore implements MemoryStore {
22
+ private baseDir: string
23
+ private log: Logger
24
+ private index = new InMemoryMemoryIndex()
25
+ private initialized = false
26
+
27
+ constructor(config: DiskMemoryStoreConfig) {
28
+ this.baseDir = join(config.baseDir, 'memory')
29
+ this.log = (config.logger ?? getRootLogger()).child({ component: 'DiskMemoryStore' })
30
+ }
31
+
32
+ private get indexPath(): string {
33
+ return join(this.baseDir, 'index.json')
34
+ }
35
+
36
+ private get contentDir(): string {
37
+ return join(this.baseDir, 'content')
38
+ }
39
+
40
+ private contentPath(id: MemoryId): string {
41
+ return join(this.contentDir, `${id}.json`)
42
+ }
43
+
44
+ private async ensureInit(): Promise<void> {
45
+ if (this.initialized) return
46
+
47
+ await mkdir(this.contentDir, { recursive: true })
48
+
49
+ try {
50
+ const raw = await readFile(this.indexPath, 'utf-8')
51
+ const entries = JSON.parse(raw) as MemoryIndexEntry[]
52
+ this.index.rebuild(entries)
53
+ this.log.info('Memory index loaded', { count: entries.length })
54
+ } catch (err) {
55
+ const isNotFound =
56
+ typeof err === 'object' && err !== null && (err as NodeJS.ErrnoException).code === 'ENOENT'
57
+ if (!isNotFound) {
58
+ this.log.warn('Failed to read memory index — starting fresh', {
59
+ error: String(err),
60
+ })
61
+ }
62
+ }
63
+
64
+ this.initialized = true
65
+ }
66
+
67
+ async create(
68
+ params: CreateMemoryParams,
69
+ ): Promise<{ entry: MemoryIndexEntry; content: MemoryContent }> {
70
+ await this.ensureInit()
71
+
72
+ const id = generateMemoryId()
73
+ const now = Date.now()
74
+
75
+ const entry: MemoryIndexEntry = {
76
+ id,
77
+ title: params.title,
78
+ summary: params.summary,
79
+ tags: params.tags ? [...params.tags] : [],
80
+ status: 'active',
81
+ createdAt: now,
82
+ updatedAt: now,
83
+ }
84
+
85
+ const memoryContent: MemoryContent = {
86
+ id,
87
+ content: params.content,
88
+ format: params.format ?? 'text',
89
+ metadata: params.metadata ? { ...params.metadata } : undefined,
90
+ }
91
+
92
+ this.index.set(entry)
93
+ await this.persistIndex()
94
+ await atomicWriteJson(this.contentPath(id), memoryContent)
95
+
96
+ this.log.info('Memory created', { memoryId: id, title: params.title })
97
+
98
+ return { entry, content: memoryContent }
99
+ }
100
+
101
+ async get(id: MemoryId): Promise<MemoryContent | undefined> {
102
+ await this.ensureInit()
103
+
104
+ if (!this.index.getEntry(id)) return undefined
105
+
106
+ try {
107
+ const raw = await readFile(this.contentPath(id), 'utf-8')
108
+ return JSON.parse(raw) as MemoryContent
109
+ } catch {
110
+ this.log.warn('Failed to read memory content', { memoryId: id })
111
+ return undefined
112
+ }
113
+ }
114
+
115
+ async update(
116
+ id: MemoryId,
117
+ updates: Partial<CreateMemoryParams>,
118
+ ): Promise<MemoryIndexEntry | undefined> {
119
+ await this.ensureInit()
120
+
121
+ const existing = this.index.getEntry(id)
122
+ if (!existing) return undefined
123
+
124
+ const now = Date.now()
125
+
126
+ const updated: MemoryIndexEntry = {
127
+ ...existing,
128
+ title: updates.title ?? existing.title,
129
+ summary: updates.summary ?? existing.summary,
130
+ tags: updates.tags ? [...updates.tags] : existing.tags,
131
+ updatedAt: now,
132
+ }
133
+
134
+ this.index.set(updated)
135
+ await this.persistIndex()
136
+
137
+ if (
138
+ updates.content !== undefined ||
139
+ updates.format !== undefined ||
140
+ updates.metadata !== undefined
141
+ ) {
142
+ try {
143
+ const raw = await readFile(this.contentPath(id), 'utf-8')
144
+ const existingContent = JSON.parse(raw) as MemoryContent
145
+
146
+ const updatedContent: MemoryContent = {
147
+ ...existingContent,
148
+ content: updates.content ?? existingContent.content,
149
+ format: updates.format ?? existingContent.format,
150
+ metadata:
151
+ updates.metadata !== undefined ? { ...updates.metadata } : existingContent.metadata,
152
+ }
153
+
154
+ await atomicWriteJson(this.contentPath(id), updatedContent)
155
+ } catch {
156
+ this.log.warn('Failed to update memory content', { memoryId: id })
157
+ }
158
+ }
159
+
160
+ this.log.info('Memory updated', { memoryId: id })
161
+ return updated
162
+ }
163
+
164
+ async delete(id: MemoryId): Promise<boolean> {
165
+ await this.ensureInit()
166
+
167
+ const existed = this.index.remove(id)
168
+ if (!existed) return false
169
+
170
+ await this.persistIndex()
171
+ await unlink(this.contentPath(id)).catch(() => undefined)
172
+
173
+ this.log.info('Memory deleted', { memoryId: id })
174
+ return true
175
+ }
176
+
177
+ async list(params?: MemorySearchParams): Promise<MemorySearchResult> {
178
+ await this.ensureInit()
179
+ return this.index.search(params ?? {})
180
+ }
181
+
182
+ getIndex(): InMemoryMemoryIndex {
183
+ return this.index
184
+ }
185
+
186
+ private async persistIndex(): Promise<void> {
187
+ const entries = this.index.allEntries()
188
+ await atomicWriteJson(this.indexPath, entries)
189
+ }
190
+ }
191
+
192
+ async function atomicWriteFile(filePath: string, content: string): Promise<void> {
193
+ const tempPath = `${filePath}.tmp`
194
+ try {
195
+ await writeFile(tempPath, content, 'utf-8')
196
+ await rename(tempPath, filePath)
197
+ } catch (err) {
198
+ await unlink(tempPath).catch(() => undefined)
199
+ throw err
200
+ }
201
+ }
202
+
203
+ async function atomicWriteJson(filePath: string, value: unknown): Promise<void> {
204
+ await atomicWriteFile(filePath, JSON.stringify(value, null, 2))
205
+ }
@@ -0,0 +1,68 @@
1
+ import type { MemoryId } from '../../types/ids/index.js'
2
+ import type {
3
+ MemoryIndex,
4
+ MemoryIndexEntry,
5
+ MemorySearchParams,
6
+ MemorySearchResult,
7
+ } from '../../types/memory/index.js'
8
+
9
+ export class InMemoryMemoryIndex implements MemoryIndex {
10
+ private entries = new Map<string, MemoryIndexEntry>()
11
+
12
+ search(params: MemorySearchParams): MemorySearchResult {
13
+ let results = Array.from(this.entries.values())
14
+
15
+ if (params.query) {
16
+ const q = params.query.toLowerCase()
17
+ results = results.filter(
18
+ (e) => e.title.toLowerCase().includes(q) || e.summary.toLowerCase().includes(q),
19
+ )
20
+ }
21
+
22
+ if (params.tags && params.tags.length > 0) {
23
+ const requiredTags = params.tags
24
+ results = results.filter((e) => requiredTags.every((tag) => e.tags.includes(tag)))
25
+ }
26
+
27
+ if (params.status) {
28
+ results = results.filter((e) => e.status === params.status)
29
+ }
30
+
31
+ results.sort((a, b) => b.updatedAt - a.updatedAt)
32
+
33
+ const totalCount = results.length
34
+ const limit = params.limit ?? totalCount
35
+
36
+ return {
37
+ entries: results.slice(0, limit),
38
+ totalCount,
39
+ }
40
+ }
41
+
42
+ getEntry(id: MemoryId): MemoryIndexEntry | undefined {
43
+ return this.entries.get(id)
44
+ }
45
+
46
+ allEntries(): readonly MemoryIndexEntry[] {
47
+ return Array.from(this.entries.values())
48
+ }
49
+
50
+ count(): number {
51
+ return this.entries.size
52
+ }
53
+
54
+ rebuild(entries: MemoryIndexEntry[]): void {
55
+ this.entries.clear()
56
+ for (const entry of entries) {
57
+ this.entries.set(entry.id, entry)
58
+ }
59
+ }
60
+
61
+ set(entry: MemoryIndexEntry): void {
62
+ this.entries.set(entry.id, entry)
63
+ }
64
+
65
+ remove(id: MemoryId): boolean {
66
+ return this.entries.delete(id)
67
+ }
68
+ }
@@ -0,0 +1,103 @@
1
+ import type { MemoryId } from '../../types/ids/index.js'
2
+ import type {
3
+ CreateMemoryParams,
4
+ MemoryContent,
5
+ MemoryIndexEntry,
6
+ MemorySearchParams,
7
+ MemorySearchResult,
8
+ MemoryStore,
9
+ } from '../../types/memory/index.js'
10
+ import { generateMemoryId } from '../../utils/id.js'
11
+ import { InMemoryMemoryIndex } from './index.js'
12
+
13
+ export class InMemoryMemoryStore implements MemoryStore {
14
+ private content = new Map<string, MemoryContent>()
15
+ private index = new InMemoryMemoryIndex()
16
+
17
+ async create(
18
+ params: CreateMemoryParams,
19
+ ): Promise<{ entry: MemoryIndexEntry; content: MemoryContent }> {
20
+ const id = generateMemoryId()
21
+ const now = Date.now()
22
+
23
+ const entry: MemoryIndexEntry = {
24
+ id,
25
+ title: params.title,
26
+ summary: params.summary,
27
+ tags: params.tags ? [...params.tags] : [],
28
+ status: 'active',
29
+ createdAt: now,
30
+ updatedAt: now,
31
+ }
32
+
33
+ const memoryContent: MemoryContent = {
34
+ id,
35
+ content: params.content,
36
+ format: params.format ?? 'text',
37
+ metadata: params.metadata ? { ...params.metadata } : undefined,
38
+ }
39
+
40
+ this.index.set(entry)
41
+ this.content.set(id, memoryContent)
42
+
43
+ return { entry, content: memoryContent }
44
+ }
45
+
46
+ async get(id: MemoryId): Promise<MemoryContent | undefined> {
47
+ return this.content.get(id)
48
+ }
49
+
50
+ async update(
51
+ id: MemoryId,
52
+ updates: Partial<CreateMemoryParams>,
53
+ ): Promise<MemoryIndexEntry | undefined> {
54
+ const existing = this.index.getEntry(id)
55
+ if (!existing) return undefined
56
+
57
+ const now = Date.now()
58
+
59
+ const updated: MemoryIndexEntry = {
60
+ ...existing,
61
+ title: updates.title ?? existing.title,
62
+ summary: updates.summary ?? existing.summary,
63
+ tags: updates.tags ? [...updates.tags] : existing.tags,
64
+ updatedAt: now,
65
+ }
66
+
67
+ this.index.set(updated)
68
+
69
+ if (
70
+ updates.content !== undefined ||
71
+ updates.format !== undefined ||
72
+ updates.metadata !== undefined
73
+ ) {
74
+ const existingContent = this.content.get(id)
75
+ if (existingContent) {
76
+ const updatedContent: MemoryContent = {
77
+ ...existingContent,
78
+ content: updates.content ?? existingContent.content,
79
+ format: updates.format ?? existingContent.format,
80
+ metadata:
81
+ updates.metadata !== undefined ? { ...updates.metadata } : existingContent.metadata,
82
+ }
83
+ this.content.set(id, updatedContent)
84
+ }
85
+ }
86
+
87
+ return updated
88
+ }
89
+
90
+ async delete(id: MemoryId): Promise<boolean> {
91
+ const existed = this.index.remove(id)
92
+ this.content.delete(id)
93
+ return existed
94
+ }
95
+
96
+ async list(params?: MemorySearchParams): Promise<MemorySearchResult> {
97
+ return this.index.search(params ?? {})
98
+ }
99
+
100
+ getIndex(): InMemoryMemoryIndex {
101
+ return this.index
102
+ }
103
+ }
@@ -0,0 +1,157 @@
1
+ import { z } from 'zod'
2
+ import type { AdvisoryContext } from '../../advisory/context.js'
3
+ import type { ToolDefinition } from '../../types/tool/index.js'
4
+ import { defineTool } from '../defineTool.js'
5
+
6
+ export interface AdvisoryToolsOptions {
7
+ readonly advisoryCtx: AdvisoryContext
8
+ }
9
+
10
+ export function buildAdvisoryTools(opts: AdvisoryToolsOptions): ToolDefinition[] {
11
+ const { advisoryCtx } = opts
12
+
13
+ const listAdvisors = defineTool({
14
+ name: 'list_advisors',
15
+ description:
16
+ 'List all available advisory agents with their domains of expertise and current budget status. Use this to discover which advisors are available before consulting one.',
17
+ inputSchema: z.object({}),
18
+ category: 'analysis',
19
+ permissions: [],
20
+ readOnly: true,
21
+ destructive: false,
22
+ concurrencySafe: true,
23
+ async execute() {
24
+ const advisors = advisoryCtx.registry.listAll()
25
+ const budget = advisoryCtx.getBudgetStatus()
26
+
27
+ const lines = advisors.map((a) => {
28
+ const domains = a.domains && a.domains.length > 0 ? a.domains.join(', ') : 'general'
29
+ return `- ${a.id}: ${a.name} [domains: ${domains}]`
30
+ })
31
+
32
+ const budgetLine =
33
+ budget.total !== undefined
34
+ ? `Budget: ${budget.used}/${budget.total} calls used (${budget.remaining} remaining)`
35
+ : `Budget: ${budget.used} calls used (unlimited)`
36
+
37
+ return {
38
+ success: true,
39
+ output:
40
+ advisors.length === 0
41
+ ? 'No advisors configured.'
42
+ : `${advisors.length} advisor(s) available:\n${lines.join('\n')}\n\n${budgetLine}`,
43
+ data: {
44
+ advisors: advisors.map((a) => ({
45
+ id: a.id,
46
+ name: a.name,
47
+ domains: a.domains ?? [],
48
+ model: a.model,
49
+ })),
50
+ budget,
51
+ },
52
+ }
53
+ },
54
+ })
55
+
56
+ const consultAdvisor = defineTool({
57
+ name: 'consult_advisor',
58
+ description:
59
+ 'Consult an advisory agent for guidance. Resolves the advisor by explicit ID, domain match, or falls back to the default advisor. Checks budget before calling. Returns structured advice with optional warnings and decisions.',
60
+ inputSchema: z.object({
61
+ advisor_id: z.string().optional().describe('Explicit advisor ID to consult'),
62
+ question: z.string().describe('The question or situation to get advice on'),
63
+ domain: z
64
+ .string()
65
+ .optional()
66
+ .describe('Domain to match an advisor (e.g. "security", "architecture")'),
67
+ urgency: z
68
+ .enum(['low', 'normal', 'high'])
69
+ .optional()
70
+ .describe('How urgent the advisory need is'),
71
+ include_context: z
72
+ .boolean()
73
+ .optional()
74
+ .describe('Whether to include conversation context in the advisory call'),
75
+ }),
76
+ category: 'analysis',
77
+ permissions: [],
78
+ readOnly: true,
79
+ destructive: false,
80
+ concurrencySafe: true,
81
+ async execute({ advisor_id, question, domain, urgency, include_context }) {
82
+ const budgetCheck = advisoryCtx.checkBudget()
83
+ if (!budgetCheck.allowed) {
84
+ return {
85
+ success: false,
86
+ output: budgetCheck.reason ?? 'Advisory budget exhausted',
87
+ error: budgetCheck.reason,
88
+ }
89
+ }
90
+
91
+ const advisor = advisoryCtx.registry.resolve(advisor_id, domain)
92
+ if (!advisor) {
93
+ return {
94
+ success: false,
95
+ output: advisor_id
96
+ ? `Advisor not found: ${advisor_id}`
97
+ : domain
98
+ ? `No advisor found for domain: ${domain}`
99
+ : 'No advisors configured',
100
+ error: 'Advisor resolution failed',
101
+ }
102
+ }
103
+
104
+ const executionResult = await advisoryCtx.executor.consult(
105
+ advisor,
106
+ { advisorId: advisor.id, question, domain, urgency, includeContext: include_context },
107
+ { messages: [], iteration: 0 },
108
+ )
109
+
110
+ advisoryCtx.recordCall({
111
+ advisorId: advisor.id,
112
+ request: {
113
+ advisorId: advisor.id,
114
+ question,
115
+ domain,
116
+ urgency,
117
+ includeContext: include_context,
118
+ },
119
+ result: executionResult.result,
120
+ usage: executionResult.usage,
121
+ cost: executionResult.cost,
122
+ durationMs: executionResult.durationMs,
123
+ iteration: 0,
124
+ timestamp: Date.now(),
125
+ })
126
+
127
+ const sections: string[] = []
128
+
129
+ sections.push(`## Advice from ${advisor.name}\n\n${executionResult.result.advice}`)
130
+
131
+ if (executionResult.result.warnings && executionResult.result.warnings.length > 0) {
132
+ sections.push(
133
+ `## Warnings\n\n${executionResult.result.warnings.map((w) => `- ${w}`).join('\n')}`,
134
+ )
135
+ }
136
+
137
+ if (executionResult.result.decisions && executionResult.result.decisions.length > 0) {
138
+ sections.push(
139
+ `## Decisions\n\n${executionResult.result.decisions.map((d) => `- ${d}`).join('\n')}`,
140
+ )
141
+ }
142
+
143
+ return {
144
+ success: true,
145
+ output: sections.join('\n\n'),
146
+ data: {
147
+ advisorId: advisor.id,
148
+ result: executionResult.result,
149
+ usage: executionResult.usage,
150
+ durationMs: executionResult.durationMs,
151
+ },
152
+ }
153
+ },
154
+ })
155
+
156
+ return [listAdvisors, consultAdvisor]
157
+ }
@@ -16,6 +16,7 @@ export interface DefineToolOptions<S extends z.ZodType> {
16
16
  readOnly: boolean
17
17
  destructive: boolean | ((input: z.infer<S>) => boolean)
18
18
  concurrencySafe: boolean
19
+ tier?: string
19
20
  execute(input: z.infer<S>, context: ToolContext): Promise<ToolResult>
20
21
  }
21
22
 
@@ -28,6 +29,7 @@ export function defineTool<S extends z.ZodType>(
28
29
  name: options.name,
29
30
  description: options.description,
30
31
  inputSchema: options.inputSchema,
32
+ tier: options.tier,
31
33
  category: options.category,
32
34
  permissions: options.permissions,
33
35
  isReadOnly: () => options.readOnly,