@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
@@ -0,0 +1,91 @@
1
+ import { readFile, readdir, stat } from 'node:fs/promises'
2
+ import { homedir } from 'node:os'
3
+ import { join } from 'node:path'
4
+ import {
5
+ PLUGIN_MANIFEST_FILENAME,
6
+ PLUGIN_NAME_PATTERN,
7
+ PROJECT_PLUGIN_DIR,
8
+ USER_PLUGIN_DIR,
9
+ } from '../constants/plugin/index.js'
10
+ import { type PluginManifest, PluginManifestSchema } from '../types/plugin/index.js'
11
+ import { getRootLogger } from '../utils/logger.js'
12
+
13
+ const logger = getRootLogger().child({ component: 'PluginLoader' })
14
+
15
+ /**
16
+ * Scans a directory for subdirectories containing a plugin manifest.
17
+ * Returns an array of absolute paths to plugin directories.
18
+ */
19
+ export async function discoverPlugins(parentDir: string): Promise<string[]> {
20
+ const dirs: string[] = []
21
+
22
+ try {
23
+ const entries = await readdir(parentDir)
24
+ for (const entry of entries) {
25
+ if (entry.startsWith('.') || entry.startsWith('_')) continue
26
+ const fullPath = join(parentDir, entry)
27
+ const s = await stat(fullPath)
28
+ if (!s.isDirectory()) continue
29
+
30
+ const manifestPath = join(fullPath, PLUGIN_MANIFEST_FILENAME)
31
+ try {
32
+ await stat(manifestPath)
33
+ dirs.push(fullPath)
34
+ } catch {
35
+ // No manifest in this directory — skip
36
+ }
37
+ }
38
+ } catch {
39
+ logger.debug('Plugins directory not found', { parentDir })
40
+ }
41
+
42
+ return dirs
43
+ }
44
+
45
+ /**
46
+ * Reads and validates a plugin manifest from a plugin directory.
47
+ * Throws on invalid manifest (fail fast).
48
+ */
49
+ export async function loadPluginManifest(pluginDir: string): Promise<PluginManifest> {
50
+ const manifestPath = join(pluginDir, PLUGIN_MANIFEST_FILENAME)
51
+ const raw = await readFile(manifestPath, 'utf-8')
52
+ const parsed: unknown = JSON.parse(raw)
53
+ return PluginManifestSchema.parse(parsed)
54
+ }
55
+
56
+ /**
57
+ * Validates that the plugin name matches the directory name
58
+ * and conforms to the plugin name pattern.
59
+ */
60
+ export function validatePluginName(name: string, dirName: string): void {
61
+ if (!PLUGIN_NAME_PATTERN.test(name)) {
62
+ throw new Error(
63
+ `Plugin name "${name}" is invalid. Must be lowercase alphanumeric with hyphens (pattern: ${PLUGIN_NAME_PATTERN.source})`,
64
+ )
65
+ }
66
+ if (name !== dirName) {
67
+ throw new Error(`Plugin name "${name}" must match directory name "${dirName}"`)
68
+ }
69
+ }
70
+
71
+ /**
72
+ * Discovers plugin directories from both project-level and user-level locations.
73
+ * Returns categorized arrays of absolute paths.
74
+ */
75
+ export async function discoverAllPluginDirs(
76
+ workingDirectory?: string,
77
+ ): Promise<{ project: string[]; user: string[] }> {
78
+ const projectDir = workingDirectory
79
+ ? join(workingDirectory, PROJECT_PLUGIN_DIR)
80
+ : join(process.cwd(), PROJECT_PLUGIN_DIR)
81
+ const userDir = join(homedir(), USER_PLUGIN_DIR)
82
+
83
+ const [project, user] = await Promise.all([discoverPlugins(projectDir), discoverPlugins(userDir)])
84
+
85
+ logger.debug('Plugin discovery complete', {
86
+ projectCount: project.length,
87
+ userCount: user.length,
88
+ })
89
+
90
+ return { project, user }
91
+ }
@@ -0,0 +1,95 @@
1
+ import { PLUGIN_NAMESPACE_SEPARATOR } from '../constants/plugin/index.js'
2
+ import type { PluginRegistry } from '../registry/plugin/index.js'
3
+ import type { ToolRegistry } from '../registry/tool/execute.js'
4
+ import type { PluginId } from '../types/ids/index.js'
5
+ import type { PluginContributionType } from '../types/plugin/index.js'
6
+
7
+ export class PluginResolver {
8
+ private pluginRegistry: PluginRegistry
9
+ private toolRegistry: ToolRegistry
10
+
11
+ constructor(pluginRegistry: PluginRegistry, toolRegistry: ToolRegistry) {
12
+ this.pluginRegistry = pluginRegistry
13
+ this.toolRegistry = toolRegistry
14
+ }
15
+
16
+ /**
17
+ * Parses a qualified tool name in `pluginName:toolName` format.
18
+ * Returns null if the name is not namespaced.
19
+ */
20
+ resolveToolName(qualifiedName: string): { pluginName: string; toolName: string } | null {
21
+ const sepIndex = qualifiedName.indexOf(PLUGIN_NAMESPACE_SEPARATOR)
22
+ if (sepIndex === -1) return null
23
+
24
+ return {
25
+ pluginName: qualifiedName.slice(0, sepIndex),
26
+ toolName: qualifiedName.slice(sepIndex + PLUGIN_NAMESPACE_SEPARATOR.length),
27
+ }
28
+ }
29
+
30
+ /**
31
+ * Lists all tool names contributed by a specific plugin.
32
+ * Matches tools whose name starts with `manifest.name:`.
33
+ */
34
+ getPluginTools(pluginId: PluginId): string[] {
35
+ const definition = this.pluginRegistry.getOrThrow(pluginId)
36
+ const prefix = definition.manifest.name + PLUGIN_NAMESPACE_SEPARATOR
37
+ return this.toolRegistry.listNames().filter((name) => name.startsWith(prefix))
38
+ }
39
+
40
+ /**
41
+ * Resolves a fully qualified component name to its plugin, contribution type, and local name.
42
+ */
43
+ resolveComponent(
44
+ qualifiedName: string,
45
+ ):
46
+ | { pluginId: PluginId; contributionType: PluginContributionType; componentName: string }
47
+ | undefined {
48
+ const sepIndex = qualifiedName.indexOf(PLUGIN_NAMESPACE_SEPARATOR)
49
+ if (sepIndex === -1) return undefined
50
+
51
+ const pluginName = qualifiedName.slice(0, sepIndex)
52
+ const componentName = qualifiedName.slice(sepIndex + PLUGIN_NAMESPACE_SEPARATOR.length)
53
+
54
+ const definition = this.pluginRegistry.findByName(pluginName)
55
+ if (!definition) return undefined
56
+
57
+ const contributionType = this.inferContributionType(definition.id, pluginName, componentName)
58
+ if (!contributionType) return undefined
59
+
60
+ return {
61
+ pluginId: definition.id,
62
+ contributionType,
63
+ componentName,
64
+ }
65
+ }
66
+
67
+ /**
68
+ * Returns a namespaced name in `pluginName:componentName` format.
69
+ */
70
+ namespaceName(pluginName: string, componentName: string): string {
71
+ return pluginName + PLUGIN_NAMESPACE_SEPARATOR + componentName
72
+ }
73
+
74
+ private inferContributionType(
75
+ pluginId: PluginId,
76
+ pluginName: string,
77
+ componentName: string,
78
+ ): PluginContributionType | undefined {
79
+ const definition = this.pluginRegistry.getOrThrow(pluginId)
80
+ const manifest = definition.manifest
81
+
82
+ if (manifest.tools?.includes(componentName)) return 'tool'
83
+ if (manifest.skills?.includes(componentName)) return 'skill'
84
+ if (manifest.hooks?.includes(componentName)) return 'hook'
85
+ if (manifest.connectors?.includes(componentName)) return 'connector'
86
+ if (manifest.personas?.includes(componentName)) return 'persona'
87
+ if (manifest.mcpServers?.some((s) => s.name === componentName)) return 'mcp_server'
88
+
89
+ // Check if it exists as a registered tool (runtime registration)
90
+ const namespacedToolName = pluginName + PLUGIN_NAMESPACE_SEPARATOR + componentName
91
+ if (this.toolRegistry.has(namespacedToolName)) return 'tool'
92
+
93
+ return undefined
94
+ }
95
+ }
@@ -0,0 +1,20 @@
1
+ import type { PluginDefinition, PluginScope, PluginStatus } from '../../types/plugin/index.js'
2
+ import { ManagedRegistry } from '../ManagedRegistry.js'
3
+
4
+ export class PluginRegistry extends ManagedRegistry<PluginDefinition> {
5
+ constructor() {
6
+ super({ componentName: 'PluginRegistry', idField: 'id' })
7
+ }
8
+
9
+ listByScope(scope: PluginScope): PluginDefinition[] {
10
+ return this.getAll().filter((def) => def.scope === scope)
11
+ }
12
+
13
+ listByStatus(status: PluginStatus): PluginDefinition[] {
14
+ return this.getAll().filter((def) => def.status === status)
15
+ }
16
+
17
+ findByName(name: string): PluginDefinition | undefined {
18
+ return this.getAll().find((def) => def.manifest.name === name)
19
+ }
20
+ }
@@ -9,6 +9,7 @@ import type {
9
9
  ToolDefinition,
10
10
  ToolRegistryConfig,
11
11
  ToolResult,
12
+ ToolTierConfig,
12
13
  } from '../../types/tool/index.js'
13
14
  import { toErrorMessage } from '../../utils/error.js'
14
15
  import { type Logger, getRootLogger } from '../../utils/logger.js'
@@ -22,12 +23,14 @@ export interface ToolExecutionResult extends ToolResult {
22
23
  export class ToolRegistry extends Registry<ToolDefinition> {
23
24
  private log: Logger
24
25
  private availability: Map<string, ToolAvailability> = new Map()
26
+ private tierConfig?: ToolTierConfig
25
27
 
26
28
  constructor(config?: ToolRegistryConfig) {
27
29
  super()
28
30
  this.log = (config?.logger ?? getRootLogger()).child({
29
31
  component: 'ToolRegistry',
30
32
  })
33
+ this.tierConfig = config?.tierConfig
31
34
  }
32
35
 
33
36
  override register(id: string, tool: ToolDefinition): void
@@ -61,6 +64,14 @@ export class ToolRegistry extends Registry<ToolDefinition> {
61
64
  }
62
65
 
63
66
  private registerOne(id: string, tool: ToolDefinition, state: ToolAvailability): void {
67
+ if (tool.tier && this.tierConfig) {
68
+ const validIds = this.tierConfig.tiers.map((t) => t.id)
69
+ if (!validIds.includes(tool.tier)) {
70
+ throw new Error(
71
+ `Tool "${id}" has tier "${tool.tier}" which is not defined. Valid tiers: ${validIds.join(', ')}`,
72
+ )
73
+ }
74
+ }
64
75
  if (this.has(id)) {
65
76
  this.log.warn(`Tool "${id}" is already registered, overwriting.`)
66
77
  }
@@ -122,6 +133,26 @@ export class ToolRegistry extends Registry<ToolDefinition> {
122
133
  )
123
134
  }
124
135
 
136
+ assignTiers(mapping: Record<string, string>): void {
137
+ for (const [toolName, tierId] of Object.entries(mapping)) {
138
+ const tool = this.getOrThrow(toolName)
139
+ if (this.tierConfig) {
140
+ const validIds = this.tierConfig.tiers.map((t) => t.id)
141
+ if (!validIds.includes(tierId)) {
142
+ throw new Error(
143
+ `Tier "${tierId}" for tool "${toolName}" is not defined. Valid tiers: ${validIds.join(', ')}`,
144
+ )
145
+ }
146
+ }
147
+ tool.tier = tierId
148
+ }
149
+ }
150
+
151
+ toTierGuidance(): string | null {
152
+ if (!this.tierConfig?.guidanceTemplate) return null
153
+ return this.tierConfig.guidanceTemplate(this.tierConfig.tiers)
154
+ }
155
+
125
156
  getOrThrow(name: string): ToolDefinition {
126
157
  const tool = this.get(name)
127
158
  if (!tool) {
@@ -159,17 +190,26 @@ export class ToolRegistry extends Registry<ToolDefinition> {
159
190
  toLLMTools(toolNames?: string[]): LLMToolSchema[] {
160
191
  const toolsToConvert = this.getByAvailability(['active', 'suspended'], toolNames)
161
192
 
162
- return toolsToConvert.map((tool) => ({
163
- type: 'function' as const,
164
- function: {
165
- name: tool.name,
166
- description: tool.description,
167
- parameters: zodToJsonSchema(tool.inputSchema, {
168
- target: 'jsonSchema7',
169
- $refStrategy: 'none',
170
- }) as Record<string, unknown>,
171
- },
172
- }))
193
+ return toolsToConvert.map((tool) => {
194
+ let description = tool.description
195
+ if (this.tierConfig?.labelInDescription && tool.tier) {
196
+ const tierDef = this.tierConfig.tiers.find((t) => t.id === tool.tier)
197
+ if (tierDef) {
198
+ description = `[${tierDef.label}] ${description}`
199
+ }
200
+ }
201
+ return {
202
+ type: 'function' as const,
203
+ function: {
204
+ name: tool.name,
205
+ description,
206
+ parameters: zodToJsonSchema(tool.inputSchema, {
207
+ target: 'jsonSchema7',
208
+ $refStrategy: 'none',
209
+ }) as Record<string, unknown>,
210
+ },
211
+ }
212
+ })
173
213
  }
174
214
 
175
215
  getCallableTools(toolNames?: string[]): ToolDefinition[] {
@@ -0,0 +1 @@
1
+ export { resolveTaskModel } from './task-router.js'
@@ -0,0 +1,24 @@
1
+ import type { TaskRouterConfig, TaskType } from '../types/router/index.js'
2
+
3
+ /**
4
+ * Resolves the model ID for a given task type using the router config.
5
+ *
6
+ * Fallback chain: `router[taskType]` -> `router.default` -> `primaryModel`
7
+ */
8
+ export function resolveTaskModel(
9
+ taskType: TaskType,
10
+ router: TaskRouterConfig | undefined,
11
+ primaryModel: string,
12
+ ): string {
13
+ if (!router) return primaryModel
14
+
15
+ const specific = router[taskType]
16
+ if (specific) return specific
17
+
18
+ if (taskType !== 'default') {
19
+ const fallback = router.default
20
+ if (fallback) return fallback
21
+ }
22
+
23
+ return primaryModel
24
+ }
@@ -154,6 +154,23 @@ export function createRunReporter(parentLogger?: Logger): RunReporter {
154
154
  })
155
155
  break
156
156
 
157
+ case 'plugin_hook_executing':
158
+ log.debug('Plugin hook executing', {
159
+ runId: event.runId,
160
+ pluginId: event.pluginId,
161
+ hookEvent: event.hookEvent,
162
+ })
163
+ break
164
+
165
+ case 'plugin_hook_completed':
166
+ log.debug('Plugin hook completed', {
167
+ runId: event.runId,
168
+ pluginId: event.pluginId,
169
+ hookEvent: event.hookEvent,
170
+ action: event.result.action,
171
+ })
172
+ break
173
+
157
174
  default: {
158
175
  const _exhaustive: never = event
159
176
  throw new Error(`Unhandled run event type: ${(_exhaustive as RunEvent).type}`)
@@ -1,9 +1,11 @@
1
1
  import { createHash } from 'node:crypto'
2
2
  import type { ToolRegistry } from '../../registry/tool/execute.js'
3
+ import type { AgentContextLevel } from '../../types/agent/factory.js'
3
4
  import type { ThreadId } from '../../types/ids/index.js'
4
5
  import type { AgentPersona } from '../../types/persona/index.js'
5
6
  import type { Skill } from '../../types/skills/index.js'
6
7
  import { PromptBuilder } from './prompt.js'
8
+ import type { PromptSegments } from './prompt.js'
7
9
 
8
10
  export interface ContextCacheConfig {
9
11
  agentId: string
@@ -25,6 +27,8 @@ export class ContextCache {
25
27
 
26
28
  private cachedPrompt: string | undefined
27
29
  private cachedConfigHash: string | undefined
30
+ private cachedStaticSegment: string | undefined
31
+ private cachedStaticHash: string | undefined
28
32
 
29
33
  constructor(config: ContextCacheConfig) {
30
34
  this.threadId = config.threadId
@@ -61,9 +65,55 @@ export class ContextCache {
61
65
  return this.computeConfigHash(input) !== this.cachedConfigHash
62
66
  }
63
67
 
68
+ getSystemPromptSegmented(
69
+ input: PromptCacheInput,
70
+ contextLevel: AgentContextLevel = 'full',
71
+ workingDirectory?: string,
72
+ ): PromptSegments {
73
+ const staticHash = this.computeStaticHash(input)
74
+
75
+ const builder = new PromptBuilder({
76
+ systemPrompt: input.systemPrompt,
77
+ persona: input.persona,
78
+ skills: input.skills,
79
+ basePrompt: input.basePrompt,
80
+ tools: input.tools,
81
+ allowedTools: input.allowedTools,
82
+ })
83
+
84
+ const segments = builder.buildSegmented(contextLevel, workingDirectory)
85
+
86
+ if (this.cachedStaticHash === staticHash && this.cachedStaticSegment !== undefined) {
87
+ return {
88
+ static: this.cachedStaticSegment,
89
+ dynamic: segments.dynamic,
90
+ }
91
+ }
92
+
93
+ this.cachedStaticSegment = segments.static
94
+ this.cachedStaticHash = staticHash
95
+
96
+ return segments
97
+ }
98
+
64
99
  invalidate(): void {
65
100
  this.cachedPrompt = undefined
66
101
  this.cachedConfigHash = undefined
102
+ this.cachedStaticSegment = undefined
103
+ this.cachedStaticHash = undefined
104
+ }
105
+
106
+ private computeStaticHash(input: PromptCacheInput): string {
107
+ const parts: string[] = [
108
+ this.agentId,
109
+ input.systemPrompt ?? '',
110
+ input.persona?.identity?.role ?? '',
111
+ input.persona?.identity?.description ?? '',
112
+ input.basePrompt ?? '',
113
+ ...(input.skills?.map((s) => s.metadata.name) ?? []),
114
+ ]
115
+
116
+ return createHash('sha256').update(parts.join('\0')).digest('hex').slice(0, 16)
67
117
  }
68
118
 
69
119
  private computeConfigHash(input: PromptCacheInput): string {
@@ -1,3 +1,5 @@
1
+ import { extractFromToolCall, extractFromToolResult } from '../../compaction/extractor.js'
2
+ import type { WorkingStateManager } from '../../compaction/manager.js'
1
3
  import type { ToolRegistry } from '../../registry/tool/execute.js'
2
4
  import type { ActivityStore } from '../../store/activity/memory.js'
3
5
  import type { RunId } from '../../types/ids/index.js'
@@ -7,6 +9,7 @@ import type { ChatCompletionResponse } from '../../types/provider/index.js'
7
9
  import type { RunEvent } from '../../types/run/index.js'
8
10
  import type { ToolContext } from '../../types/tool/index.js'
9
11
  import type { Logger } from '../../utils/logger.js'
12
+ import { compressShellOutput } from '../../utils/shell-compress.js'
10
13
 
11
14
  export type EmitEvent = (event: RunEvent) => Promise<void>
12
15
 
@@ -29,6 +32,7 @@ export class ToolExecutor {
29
32
  private activityStore: ActivityStore
30
33
  private emitEvent: EmitEvent
31
34
  private log: Logger
35
+ private workingStateManager?: WorkingStateManager
32
36
 
33
37
  constructor(
34
38
  config: ToolExecutorConfig,
@@ -42,6 +46,10 @@ export class ToolExecutor {
42
46
  this.log = log
43
47
  }
44
48
 
49
+ setWorkingStateManager(manager: WorkingStateManager): void {
50
+ this.workingStateManager = manager
51
+ }
52
+
45
53
  async executeBatch(response: ChatCompletionResponse): Promise<ToolExecutionBatch> {
46
54
  const toolCalls = response.message.toolCalls
47
55
  if (!toolCalls) {
@@ -119,14 +127,24 @@ export class ToolExecutor {
119
127
  input,
120
128
  })
121
129
 
130
+ if (this.workingStateManager) {
131
+ extractFromToolCall(this.workingStateManager, toolName, toolCall.function.arguments)
132
+ }
133
+
122
134
  const startMs = Date.now()
123
135
  const result = await this.config.tools.execute(toolName, input, toolContext)
124
136
  const durationMs = Date.now() - startMs
125
137
 
126
- const output = result.success
138
+ const rawOutput = result.success
127
139
  ? result.output
128
140
  : `Error: ${result.error ?? 'Tool execution failed'}`
129
141
 
142
+ const output = result.success ? this.maybeCompress(toolName, rawOutput) : rawOutput
143
+
144
+ if (this.workingStateManager) {
145
+ extractFromToolResult(this.workingStateManager, toolName, output, !result.success)
146
+ }
147
+
130
148
  if (result.success) {
131
149
  this.log.debug('Tool executed successfully', {
132
150
  runId: this.config.runId,
@@ -160,4 +178,22 @@ export class ToolExecutor {
160
178
 
161
179
  return { toolCallId: toolCall.id, output }
162
180
  }
181
+
182
+ private maybeCompress(toolName: string, output: string): string {
183
+ const tool = this.config.tools.get(toolName)
184
+ if (!tool || tool.category !== 'shell') {
185
+ return output
186
+ }
187
+
188
+ const compressed = compressShellOutput(output)
189
+ if (compressed.length < output.length) {
190
+ this.log.debug('Shell output compressed', {
191
+ tool: toolName,
192
+ originalLength: output.length,
193
+ compressedLength: compressed.length,
194
+ reductionPercent: Math.round((1 - compressed.length / output.length) * 100),
195
+ })
196
+ }
197
+ return compressed
198
+ }
163
199
  }