wicked-crew 0.16.13 → 0.17.1

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 (707) hide show
  1. package/README.md +27 -9
  2. package/dist/api/audit-view.d.ts +24 -0
  3. package/dist/api/audit-view.d.ts.map +1 -0
  4. package/dist/api/audit-view.js +70 -0
  5. package/dist/api/audit-view.js.map +1 -0
  6. package/dist/api/auth.d.ts +42 -2
  7. package/dist/api/auth.d.ts.map +1 -1
  8. package/dist/api/auth.js +157 -18
  9. package/dist/api/auth.js.map +1 -1
  10. package/dist/api/capture.d.ts +12 -59
  11. package/dist/api/capture.d.ts.map +1 -1
  12. package/dist/api/capture.js +9 -17
  13. package/dist/api/capture.js.map +1 -1
  14. package/dist/api/chat-context.d.ts +6 -62
  15. package/dist/api/chat-context.d.ts.map +1 -1
  16. package/dist/api/chat-context.js +6 -12
  17. package/dist/api/chat-context.js.map +1 -1
  18. package/dist/api/chat-jobs.d.ts +163 -0
  19. package/dist/api/chat-jobs.d.ts.map +1 -0
  20. package/dist/api/chat-jobs.js +767 -0
  21. package/dist/api/chat-jobs.js.map +1 -0
  22. package/dist/api/chat-mcp.d.ts +37 -0
  23. package/dist/api/chat-mcp.d.ts.map +1 -1
  24. package/dist/api/chat-mcp.js +118 -2
  25. package/dist/api/chat-mcp.js.map +1 -1
  26. package/dist/api/chat-proposals.d.ts +170 -152
  27. package/dist/api/chat-proposals.d.ts.map +1 -1
  28. package/dist/api/chat-proposals.js +833 -15
  29. package/dist/api/chat-proposals.js.map +1 -1
  30. package/dist/api/delivery-assurance.d.ts +3 -1
  31. package/dist/api/delivery-assurance.d.ts.map +1 -1
  32. package/dist/api/delivery-assurance.js +20 -0
  33. package/dist/api/delivery-assurance.js.map +1 -1
  34. package/dist/api/delivery-freeze.d.ts +2 -8
  35. package/dist/api/delivery-freeze.d.ts.map +1 -1
  36. package/dist/api/delivery-freeze.js +2 -4
  37. package/dist/api/delivery-freeze.js.map +1 -1
  38. package/dist/api/eval-sample.d.ts +18 -114
  39. package/dist/api/eval-sample.d.ts.map +1 -1
  40. package/dist/api/eval-sample.js +7 -13
  41. package/dist/api/eval-sample.js.map +1 -1
  42. package/dist/api/governance-steering.d.ts +27 -71
  43. package/dist/api/governance-steering.d.ts.map +1 -1
  44. package/dist/api/governance-steering.js +11 -19
  45. package/dist/api/governance-steering.js.map +1 -1
  46. package/dist/api/mcp.d.ts +159 -199
  47. package/dist/api/mcp.d.ts.map +1 -1
  48. package/dist/api/mcp.js +433 -68
  49. package/dist/api/mcp.js.map +1 -1
  50. package/dist/api/needs.d.ts +10 -0
  51. package/dist/api/needs.d.ts.map +1 -1
  52. package/dist/api/needs.js +77 -0
  53. package/dist/api/needs.js.map +1 -1
  54. package/dist/api/open-path.d.ts +10 -0
  55. package/dist/api/open-path.d.ts.map +1 -1
  56. package/dist/api/open-path.js +58 -1
  57. package/dist/api/open-path.js.map +1 -1
  58. package/dist/api/plan-schema.d.ts +8 -51
  59. package/dist/api/plan-schema.d.ts.map +1 -1
  60. package/dist/api/plan-schema.js +6 -6
  61. package/dist/api/plan-schema.js.map +1 -1
  62. package/dist/api/product.d.ts +81 -23
  63. package/dist/api/product.d.ts.map +1 -1
  64. package/dist/api/product.js +149 -72
  65. package/dist/api/product.js.map +1 -1
  66. package/dist/api/project-aggregates.d.ts +12 -20
  67. package/dist/api/project-aggregates.d.ts.map +1 -1
  68. package/dist/api/project-aggregates.js +3 -3
  69. package/dist/api/project-aggregates.js.map +1 -1
  70. package/dist/api/recording.d.ts +69 -39
  71. package/dist/api/recording.d.ts.map +1 -1
  72. package/dist/api/recording.js +60 -49
  73. package/dist/api/recording.js.map +1 -1
  74. package/dist/api/routes.d.ts +229 -1506
  75. package/dist/api/routes.d.ts.map +1 -1
  76. package/dist/api/routes.js +1226 -169
  77. package/dist/api/routes.js.map +1 -1
  78. package/dist/api/run-timing-index.d.ts +12 -1
  79. package/dist/api/run-timing-index.d.ts.map +1 -1
  80. package/dist/api/run-timing-index.js +35 -0
  81. package/dist/api/run-timing-index.js.map +1 -1
  82. package/dist/api/seat-images.d.ts +10 -0
  83. package/dist/api/seat-images.d.ts.map +1 -1
  84. package/dist/api/seat-images.js +16 -3
  85. package/dist/api/seat-images.js.map +1 -1
  86. package/dist/api/server-error-body.d.ts +44 -0
  87. package/dist/api/server-error-body.d.ts.map +1 -0
  88. package/dist/api/server-error-body.js +206 -0
  89. package/dist/api/server-error-body.js.map +1 -0
  90. package/dist/api/server.d.ts.map +1 -1
  91. package/dist/api/server.js +179 -4
  92. package/dist/api/server.js.map +1 -1
  93. package/dist/api/skills.d.ts +12 -36
  94. package/dist/api/skills.d.ts.map +1 -1
  95. package/dist/api/skills.js +12 -15
  96. package/dist/api/skills.js.map +1 -1
  97. package/dist/api/system-snapshot.d.ts +1 -5
  98. package/dist/api/system-snapshot.d.ts.map +1 -1
  99. package/dist/api/system-snapshot.js +7 -15
  100. package/dist/api/system-snapshot.js.map +1 -1
  101. package/dist/api/testing.d.ts +29 -50
  102. package/dist/api/testing.d.ts.map +1 -1
  103. package/dist/api/testing.js +7 -13
  104. package/dist/api/testing.js.map +1 -1
  105. package/dist/apps/actions/api-action.d.ts +47 -0
  106. package/dist/apps/actions/api-action.d.ts.map +1 -0
  107. package/dist/apps/actions/api-action.js +135 -0
  108. package/dist/apps/actions/api-action.js.map +1 -0
  109. package/dist/apps/actions/pg-fit.d.ts +27 -0
  110. package/dist/apps/actions/pg-fit.d.ts.map +1 -0
  111. package/dist/apps/actions/pg-fit.js +35 -0
  112. package/dist/apps/actions/pg-fit.js.map +1 -0
  113. package/dist/apps/actions/pg-write.d.ts +84 -0
  114. package/dist/apps/actions/pg-write.d.ts.map +1 -0
  115. package/dist/apps/actions/pg-write.js +161 -0
  116. package/dist/apps/actions/pg-write.js.map +1 -0
  117. package/dist/apps/actions/store.d.ts +109 -0
  118. package/dist/apps/actions/store.d.ts.map +1 -0
  119. package/dist/apps/actions/store.js +182 -0
  120. package/dist/apps/actions/store.js.map +1 -0
  121. package/dist/apps/actions/values.d.ts +59 -0
  122. package/dist/apps/actions/values.d.ts.map +1 -0
  123. package/dist/apps/actions/values.js +315 -0
  124. package/dist/apps/actions/values.js.map +1 -0
  125. package/dist/apps/actions/write-path.d.ts +103 -0
  126. package/dist/apps/actions/write-path.d.ts.map +1 -0
  127. package/dist/apps/actions/write-path.js +576 -0
  128. package/dist/apps/actions/write-path.js.map +1 -0
  129. package/dist/apps/check.d.ts +112 -0
  130. package/dist/apps/check.d.ts.map +1 -0
  131. package/dist/apps/check.js +358 -0
  132. package/dist/apps/check.js.map +1 -0
  133. package/dist/apps/exec/arg-types.d.ts +56 -0
  134. package/dist/apps/exec/arg-types.d.ts.map +1 -0
  135. package/dist/apps/exec/arg-types.js +234 -0
  136. package/dist/apps/exec/arg-types.js.map +1 -0
  137. package/dist/apps/exec/cache.d.ts +46 -0
  138. package/dist/apps/exec/cache.d.ts.map +1 -0
  139. package/dist/apps/exec/cache.js +93 -0
  140. package/dist/apps/exec/cache.js.map +1 -0
  141. package/dist/apps/exec/contract.d.ts +83 -0
  142. package/dist/apps/exec/contract.d.ts.map +1 -0
  143. package/dist/apps/exec/contract.js +220 -0
  144. package/dist/apps/exec/contract.js.map +1 -0
  145. package/dist/apps/exec/executor.d.ts +122 -0
  146. package/dist/apps/exec/executor.d.ts.map +1 -0
  147. package/dist/apps/exec/executor.js +455 -0
  148. package/dist/apps/exec/executor.js.map +1 -0
  149. package/dist/apps/exec/limits.d.ts +25 -0
  150. package/dist/apps/exec/limits.d.ts.map +1 -0
  151. package/dist/apps/exec/limits.js +71 -0
  152. package/dist/apps/exec/limits.js.map +1 -0
  153. package/dist/apps/exec/params.d.ts +34 -0
  154. package/dist/apps/exec/params.d.ts.map +1 -0
  155. package/dist/apps/exec/params.js +97 -0
  156. package/dist/apps/exec/params.js.map +1 -0
  157. package/dist/apps/exec/project.d.ts +67 -0
  158. package/dist/apps/exec/project.d.ts.map +1 -0
  159. package/dist/apps/exec/project.js +299 -0
  160. package/dist/apps/exec/project.js.map +1 -0
  161. package/dist/apps/exec/recall.d.ts +88 -0
  162. package/dist/apps/exec/recall.d.ts.map +1 -0
  163. package/dist/apps/exec/recall.js +301 -0
  164. package/dist/apps/exec/recall.js.map +1 -0
  165. package/dist/apps/exec/source-stage.d.ts +61 -0
  166. package/dist/apps/exec/source-stage.d.ts.map +1 -0
  167. package/dist/apps/exec/source-stage.js +540 -0
  168. package/dist/apps/exec/source-stage.js.map +1 -0
  169. package/dist/apps/exec/sources.d.ts +65 -0
  170. package/dist/apps/exec/sources.d.ts.map +1 -0
  171. package/dist/apps/exec/sources.js +77 -0
  172. package/dist/apps/exec/sources.js.map +1 -0
  173. package/dist/apps/exec/texts.d.ts +140 -0
  174. package/dist/apps/exec/texts.d.ts.map +1 -0
  175. package/dist/apps/exec/texts.js +76 -0
  176. package/dist/apps/exec/texts.js.map +1 -0
  177. package/dist/apps/exec/viewer.d.ts +11 -0
  178. package/dist/apps/exec/viewer.d.ts.map +1 -0
  179. package/dist/apps/exec/viewer.js +26 -0
  180. package/dist/apps/exec/viewer.js.map +1 -0
  181. package/dist/apps/git.d.ts +109 -0
  182. package/dist/apps/git.d.ts.map +1 -0
  183. package/dist/apps/git.js +361 -0
  184. package/dist/apps/git.js.map +1 -0
  185. package/dist/apps/publish/image.d.ts +25 -0
  186. package/dist/apps/publish/image.d.ts.map +1 -0
  187. package/dist/apps/publish/image.js +86 -0
  188. package/dist/apps/publish/image.js.map +1 -0
  189. package/dist/apps/publish/layout.d.ts +41 -0
  190. package/dist/apps/publish/layout.d.ts.map +1 -0
  191. package/dist/apps/publish/layout.js +31 -0
  192. package/dist/apps/publish/layout.js.map +1 -0
  193. package/dist/apps/publish/manifest.d.ts +64 -0
  194. package/dist/apps/publish/manifest.d.ts.map +1 -0
  195. package/dist/apps/publish/manifest.js +282 -0
  196. package/dist/apps/publish/manifest.js.map +1 -0
  197. package/dist/apps/publish/pack.d.ts +40 -0
  198. package/dist/apps/publish/pack.d.ts.map +1 -0
  199. package/dist/apps/publish/pack.js +78 -0
  200. package/dist/apps/publish/pack.js.map +1 -0
  201. package/dist/apps/routes.d.ts +103 -0
  202. package/dist/apps/routes.d.ts.map +1 -0
  203. package/dist/apps/routes.js +440 -0
  204. package/dist/apps/routes.js.map +1 -0
  205. package/dist/apps/spec.d.ts +322 -2640
  206. package/dist/apps/spec.d.ts.map +1 -1
  207. package/dist/apps/spec.js +89 -120
  208. package/dist/apps/spec.js.map +1 -1
  209. package/dist/apps/store.d.ts +341 -0
  210. package/dist/apps/store.d.ts.map +1 -0
  211. package/dist/apps/store.js +905 -0
  212. package/dist/apps/store.js.map +1 -0
  213. package/dist/apps/turns.d.ts +169 -0
  214. package/dist/apps/turns.d.ts.map +1 -0
  215. package/dist/apps/turns.js +556 -0
  216. package/dist/apps/turns.js.map +1 -0
  217. package/dist/apps/views.d.ts +44 -0
  218. package/dist/apps/views.d.ts.map +1 -0
  219. package/dist/apps/views.js +53 -0
  220. package/dist/apps/views.js.map +1 -0
  221. package/dist/campaigns/routes.d.ts +22 -94
  222. package/dist/campaigns/routes.d.ts.map +1 -1
  223. package/dist/campaigns/routes.js +8 -14
  224. package/dist/campaigns/routes.js.map +1 -1
  225. package/dist/cli/apps-check.d.ts +43 -0
  226. package/dist/cli/apps-check.d.ts.map +1 -0
  227. package/dist/cli/apps-check.js +166 -0
  228. package/dist/cli/apps-check.js.map +1 -0
  229. package/dist/cli/index.d.ts.map +1 -1
  230. package/dist/cli/index.js +6 -1
  231. package/dist/cli/index.js.map +1 -1
  232. package/dist/cli/mcp.js +2 -2
  233. package/dist/cli/mcp.js.map +1 -1
  234. package/dist/core/adapter.d.ts +34 -1
  235. package/dist/core/adapter.d.ts.map +1 -1
  236. package/dist/core/adapter.js +78 -2
  237. package/dist/core/adapter.js.map +1 -1
  238. package/dist/core/builtin-catalog.d.ts.map +1 -1
  239. package/dist/core/builtin-catalog.js +2 -0
  240. package/dist/core/builtin-catalog.js.map +1 -1
  241. package/dist/core/deliver-text.d.ts +62 -1
  242. package/dist/core/deliver-text.d.ts.map +1 -1
  243. package/dist/core/deliver-text.js +244 -22
  244. package/dist/core/deliver-text.js.map +1 -1
  245. package/dist/core/deliver.d.ts.map +1 -1
  246. package/dist/core/deliver.js +30 -3
  247. package/dist/core/deliver.js.map +1 -1
  248. package/dist/core/estate-mcp-client.d.ts +9 -0
  249. package/dist/core/estate-mcp-client.d.ts.map +1 -1
  250. package/dist/core/estate-mcp-client.js +31 -3
  251. package/dist/core/estate-mcp-client.js.map +1 -1
  252. package/dist/core/linked-issues.d.ts +51 -3
  253. package/dist/core/linked-issues.d.ts.map +1 -1
  254. package/dist/core/linked-issues.js +59 -14
  255. package/dist/core/linked-issues.js.map +1 -1
  256. package/dist/core/qe-acceptance-setting.d.ts.map +1 -1
  257. package/dist/core/qe-acceptance-setting.js +6 -0
  258. package/dist/core/qe-acceptance-setting.js.map +1 -1
  259. package/dist/decisions/chat-recorder.js +1 -1
  260. package/dist/decisions/chat-recorder.js.map +1 -1
  261. package/dist/decisions/routes.d.ts.map +1 -1
  262. package/dist/decisions/routes.js +5 -9
  263. package/dist/decisions/routes.js.map +1 -1
  264. package/dist/decisions/rules-brief.d.ts +76 -0
  265. package/dist/decisions/rules-brief.d.ts.map +1 -0
  266. package/dist/decisions/rules-brief.js +179 -0
  267. package/dist/decisions/rules-brief.js.map +1 -0
  268. package/dist/editors/registry.d.ts +97 -258
  269. package/dist/editors/registry.d.ts.map +1 -1
  270. package/dist/editors/registry.js +11 -11
  271. package/dist/editors/registry.js.map +1 -1
  272. package/dist/editors/routes.js +3 -3
  273. package/dist/editors/routes.js.map +1 -1
  274. package/dist/evals/routes.d.ts.map +1 -1
  275. package/dist/evals/routes.js +3 -5
  276. package/dist/evals/routes.js.map +1 -1
  277. package/dist/insights/routes.js +2 -2
  278. package/dist/insights/routes.js.map +1 -1
  279. package/dist/interactive/proxy-routes.d.ts.map +1 -1
  280. package/dist/interactive/proxy-routes.js +76 -7
  281. package/dist/interactive/proxy-routes.js.map +1 -1
  282. package/dist/interactive/ws-relay.d.ts +3 -9
  283. package/dist/interactive/ws-relay.d.ts.map +1 -1
  284. package/dist/interactive/ws-relay.js +4 -6
  285. package/dist/interactive/ws-relay.js.map +1 -1
  286. package/dist/knowledge/adapters/native.d.ts +44 -0
  287. package/dist/knowledge/adapters/native.d.ts.map +1 -0
  288. package/dist/knowledge/adapters/native.js +60 -0
  289. package/dist/knowledge/adapters/native.js.map +1 -0
  290. package/dist/knowledge/adapters/toolbox/binary.d.ts +48 -0
  291. package/dist/knowledge/adapters/toolbox/binary.d.ts.map +1 -0
  292. package/dist/knowledge/adapters/toolbox/binary.js +145 -0
  293. package/dist/knowledge/adapters/toolbox/binary.js.map +1 -0
  294. package/dist/knowledge/adapters/toolbox/catalog.d.ts +22 -0
  295. package/dist/knowledge/adapters/toolbox/catalog.d.ts.map +1 -0
  296. package/dist/knowledge/adapters/toolbox/catalog.js +87 -0
  297. package/dist/knowledge/adapters/toolbox/catalog.js.map +1 -0
  298. package/dist/knowledge/adapters/toolbox/document.d.ts +71 -0
  299. package/dist/knowledge/adapters/toolbox/document.d.ts.map +1 -0
  300. package/dist/knowledge/adapters/toolbox/document.js +165 -0
  301. package/dist/knowledge/adapters/toolbox/document.js.map +1 -0
  302. package/dist/knowledge/adapters/toolbox/supervisor.d.ts +142 -0
  303. package/dist/knowledge/adapters/toolbox/supervisor.d.ts.map +1 -0
  304. package/dist/knowledge/adapters/toolbox/supervisor.js +438 -0
  305. package/dist/knowledge/adapters/toolbox/supervisor.js.map +1 -0
  306. package/dist/knowledge/gate/access.d.ts +36 -0
  307. package/dist/knowledge/gate/access.d.ts.map +1 -0
  308. package/dist/knowledge/gate/access.js +46 -0
  309. package/dist/knowledge/gate/access.js.map +1 -0
  310. package/dist/knowledge/gate/envelope.d.ts +67 -0
  311. package/dist/knowledge/gate/envelope.d.ts.map +1 -0
  312. package/dist/knowledge/gate/envelope.js +96 -0
  313. package/dist/knowledge/gate/envelope.js.map +1 -0
  314. package/dist/knowledge/gate/gate.d.ts +238 -0
  315. package/dist/knowledge/gate/gate.d.ts.map +1 -0
  316. package/dist/knowledge/gate/gate.js +782 -0
  317. package/dist/knowledge/gate/gate.js.map +1 -0
  318. package/dist/knowledge/gate/pg.d.ts +57 -0
  319. package/dist/knowledge/gate/pg.d.ts.map +1 -0
  320. package/dist/knowledge/gate/pg.js +94 -0
  321. package/dist/knowledge/gate/pg.js.map +1 -0
  322. package/dist/knowledge/gate/record.d.ts +77 -0
  323. package/dist/knowledge/gate/record.d.ts.map +1 -0
  324. package/dist/knowledge/gate/record.js +205 -0
  325. package/dist/knowledge/gate/record.js.map +1 -0
  326. package/dist/knowledge/gate/routes.d.ts +38 -0
  327. package/dist/knowledge/gate/routes.d.ts.map +1 -0
  328. package/dist/knowledge/gate/routes.js +102 -0
  329. package/dist/knowledge/gate/routes.js.map +1 -0
  330. package/dist/knowledge/gate/scheduler.d.ts +90 -0
  331. package/dist/knowledge/gate/scheduler.d.ts.map +1 -0
  332. package/dist/knowledge/gate/scheduler.js +224 -0
  333. package/dist/knowledge/gate/scheduler.js.map +1 -0
  334. package/dist/knowledge/gate/sources.d.ts +69 -0
  335. package/dist/knowledge/gate/sources.d.ts.map +1 -0
  336. package/dist/knowledge/gate/sources.js +135 -0
  337. package/dist/knowledge/gate/sources.js.map +1 -0
  338. package/dist/knowledge/package.d.ts +136 -0
  339. package/dist/knowledge/package.d.ts.map +1 -0
  340. package/dist/knowledge/package.js +148 -0
  341. package/dist/knowledge/package.js.map +1 -0
  342. package/dist/knowledge/projector.d.ts +144 -0
  343. package/dist/knowledge/projector.d.ts.map +1 -0
  344. package/dist/knowledge/projector.js +287 -0
  345. package/dist/knowledge/projector.js.map +1 -0
  346. package/dist/knowledge/registry/entry.d.ts +177 -0
  347. package/dist/knowledge/registry/entry.d.ts.map +1 -0
  348. package/dist/knowledge/registry/entry.js +126 -0
  349. package/dist/knowledge/registry/entry.js.map +1 -0
  350. package/dist/knowledge/registry/policy.d.ts +79 -0
  351. package/dist/knowledge/registry/policy.d.ts.map +1 -0
  352. package/dist/knowledge/registry/policy.js +139 -0
  353. package/dist/knowledge/registry/policy.js.map +1 -0
  354. package/dist/knowledge/shapes/code-search.d.ts +55 -0
  355. package/dist/knowledge/shapes/code-search.d.ts.map +1 -0
  356. package/dist/knowledge/shapes/code-search.js +88 -0
  357. package/dist/knowledge/shapes/code-search.js.map +1 -0
  358. package/dist/knowledge/shapes/map.d.ts +25 -0
  359. package/dist/knowledge/shapes/map.d.ts.map +1 -0
  360. package/dist/knowledge/shapes/map.js +187 -0
  361. package/dist/knowledge/shapes/map.js.map +1 -0
  362. package/dist/knowledge/shapes/profile.d.ts +117 -0
  363. package/dist/knowledge/shapes/profile.d.ts.map +1 -0
  364. package/dist/knowledge/shapes/profile.js +264 -0
  365. package/dist/knowledge/shapes/profile.js.map +1 -0
  366. package/dist/knowledge/shapes/routes.d.ts +69 -0
  367. package/dist/knowledge/shapes/routes.d.ts.map +1 -0
  368. package/dist/knowledge/shapes/routes.js +270 -0
  369. package/dist/knowledge/shapes/routes.js.map +1 -0
  370. package/dist/knowledge/shapes/shapes.d.ts +144 -0
  371. package/dist/knowledge/shapes/shapes.d.ts.map +1 -0
  372. package/dist/knowledge/shapes/shapes.js +280 -0
  373. package/dist/knowledge/shapes/shapes.js.map +1 -0
  374. package/dist/knowledge/shapes/verified.d.ts +36 -0
  375. package/dist/knowledge/shapes/verified.d.ts.map +1 -0
  376. package/dist/knowledge/shapes/verified.js +73 -0
  377. package/dist/knowledge/shapes/verified.js.map +1 -0
  378. package/dist/knowledge/summary.d.ts +45 -0
  379. package/dist/knowledge/summary.d.ts.map +1 -0
  380. package/dist/knowledge/summary.js +119 -0
  381. package/dist/knowledge/summary.js.map +1 -0
  382. package/dist/knowledge/trackers/actions.d.ts +55 -0
  383. package/dist/knowledge/trackers/actions.d.ts.map +1 -0
  384. package/dist/knowledge/trackers/actions.js +327 -0
  385. package/dist/knowledge/trackers/actions.js.map +1 -0
  386. package/dist/knowledge/trackers/addresses.d.ts +45 -0
  387. package/dist/knowledge/trackers/addresses.d.ts.map +1 -0
  388. package/dist/knowledge/trackers/addresses.js +59 -0
  389. package/dist/knowledge/trackers/addresses.js.map +1 -0
  390. package/dist/knowledge/trackers/bindings.d.ts +190 -0
  391. package/dist/knowledge/trackers/bindings.d.ts.map +1 -0
  392. package/dist/knowledge/trackers/bindings.js +970 -0
  393. package/dist/knowledge/trackers/bindings.js.map +1 -0
  394. package/dist/knowledge/trackers/gate-pm.d.ts +160 -0
  395. package/dist/knowledge/trackers/gate-pm.d.ts.map +1 -0
  396. package/dist/knowledge/trackers/gate-pm.js +427 -0
  397. package/dist/knowledge/trackers/gate-pm.js.map +1 -0
  398. package/dist/knowledge/trackers/issues.d.ts +69 -0
  399. package/dist/knowledge/trackers/issues.d.ts.map +1 -0
  400. package/dist/knowledge/trackers/issues.js +193 -0
  401. package/dist/knowledge/trackers/issues.js.map +1 -0
  402. package/dist/knowledge/trackers/map.d.ts +23 -0
  403. package/dist/knowledge/trackers/map.d.ts.map +1 -0
  404. package/dist/knowledge/trackers/map.js +130 -0
  405. package/dist/knowledge/trackers/map.js.map +1 -0
  406. package/dist/knowledge/trackers/projector.d.ts +113 -0
  407. package/dist/knowledge/trackers/projector.d.ts.map +1 -0
  408. package/dist/knowledge/trackers/projector.js +274 -0
  409. package/dist/knowledge/trackers/projector.js.map +1 -0
  410. package/dist/knowledge/trackers/routes.d.ts +107 -0
  411. package/dist/knowledge/trackers/routes.d.ts.map +1 -0
  412. package/dist/knowledge/trackers/routes.js +563 -0
  413. package/dist/knowledge/trackers/routes.js.map +1 -0
  414. package/dist/knowledge/trackers/set.d.ts +61 -0
  415. package/dist/knowledge/trackers/set.d.ts.map +1 -0
  416. package/dist/knowledge/trackers/set.js +77 -0
  417. package/dist/knowledge/trackers/set.js.map +1 -0
  418. package/dist/knowledge/trackers/view.d.ts +22 -0
  419. package/dist/knowledge/trackers/view.d.ts.map +1 -0
  420. package/dist/knowledge/trackers/view.js +31 -0
  421. package/dist/knowledge/trackers/view.js.map +1 -0
  422. package/dist/knowledge/trackers/visible.d.ts +9 -0
  423. package/dist/knowledge/trackers/visible.d.ts.map +1 -0
  424. package/dist/knowledge/trackers/visible.js +10 -0
  425. package/dist/knowledge/trackers/visible.js.map +1 -0
  426. package/dist/learn/routes.d.ts +3 -17
  427. package/dist/learn/routes.d.ts.map +1 -1
  428. package/dist/learn/routes.js +4 -6
  429. package/dist/learn/routes.js.map +1 -1
  430. package/dist/mcp/ask-server.d.ts +6 -0
  431. package/dist/mcp/ask-server.d.ts.map +1 -1
  432. package/dist/mcp/ask-server.js +15 -9
  433. package/dist/mcp/ask-server.js.map +1 -1
  434. package/dist/mcp/broker.d.ts +16 -0
  435. package/dist/mcp/broker.d.ts.map +1 -1
  436. package/dist/mcp/broker.js +137 -3
  437. package/dist/mcp/broker.js.map +1 -1
  438. package/dist/mcp/estate-relay.d.ts +50 -2
  439. package/dist/mcp/estate-relay.d.ts.map +1 -1
  440. package/dist/mcp/estate-relay.js +126 -4
  441. package/dist/mcp/estate-relay.js.map +1 -1
  442. package/dist/mcp/invoke.d.ts +12 -1
  443. package/dist/mcp/invoke.d.ts.map +1 -1
  444. package/dist/mcp/invoke.js +5 -2
  445. package/dist/mcp/invoke.js.map +1 -1
  446. package/dist/mcp/probe.d.ts +34 -2
  447. package/dist/mcp/probe.d.ts.map +1 -1
  448. package/dist/mcp/probe.js +51 -9
  449. package/dist/mcp/probe.js.map +1 -1
  450. package/dist/mcp/registry-store.d.ts +91 -0
  451. package/dist/mcp/registry-store.d.ts.map +1 -1
  452. package/dist/mcp/registry-store.js +116 -9
  453. package/dist/mcp/registry-store.js.map +1 -1
  454. package/dist/mcp/registry.d.ts +249 -6
  455. package/dist/mcp/registry.d.ts.map +1 -1
  456. package/dist/mcp/registry.js +735 -35
  457. package/dist/mcp/registry.js.map +1 -1
  458. package/dist/mcp/rest.d.ts +36 -10
  459. package/dist/mcp/rest.d.ts.map +1 -1
  460. package/dist/mcp/rest.js +71 -73
  461. package/dist/mcp/rest.js.map +1 -1
  462. package/dist/mcp/tool-list.d.ts +7 -0
  463. package/dist/mcp/tool-list.d.ts.map +1 -1
  464. package/dist/mcp/tool-list.js +32 -4
  465. package/dist/mcp/tool-list.js.map +1 -1
  466. package/dist/mcp-inspect/routes.d.ts +3 -0
  467. package/dist/mcp-inspect/routes.d.ts.map +1 -1
  468. package/dist/mcp-inspect/routes.js +31 -18
  469. package/dist/mcp-inspect/routes.js.map +1 -1
  470. package/dist/persona/routes.d.ts +14 -69
  471. package/dist/persona/routes.d.ts.map +1 -1
  472. package/dist/persona/routes.js +2 -2
  473. package/dist/persona/routes.js.map +1 -1
  474. package/dist/persona/store.d.ts +13 -40
  475. package/dist/persona/store.d.ts.map +1 -1
  476. package/dist/persona/store.js +9 -11
  477. package/dist/persona/store.js.map +1 -1
  478. package/dist/presets/routes.d.ts +3 -21
  479. package/dist/presets/routes.d.ts.map +1 -1
  480. package/dist/presets/routes.js +5 -7
  481. package/dist/presets/routes.js.map +1 -1
  482. package/dist/projects/repo-guard.d.ts +32 -0
  483. package/dist/projects/repo-guard.d.ts.map +1 -0
  484. package/dist/projects/repo-guard.js +46 -0
  485. package/dist/projects/repo-guard.js.map +1 -0
  486. package/dist/projects/routes.d.ts +16 -44
  487. package/dist/projects/routes.d.ts.map +1 -1
  488. package/dist/projects/routes.js +15 -18
  489. package/dist/projects/routes.js.map +1 -1
  490. package/dist/schedules/routes.d.ts +4 -18
  491. package/dist/schedules/routes.d.ts.map +1 -1
  492. package/dist/schedules/routes.js +4 -6
  493. package/dist/schedules/routes.js.map +1 -1
  494. package/dist/skills/plugin-source.d.ts +6 -5
  495. package/dist/skills/plugin-source.d.ts.map +1 -1
  496. package/dist/skills/plugin-source.js +6 -5
  497. package/dist/skills/plugin-source.js.map +1 -1
  498. package/dist/sources/ask.d.ts +108 -0
  499. package/dist/sources/ask.d.ts.map +1 -0
  500. package/dist/sources/ask.js +251 -0
  501. package/dist/sources/ask.js.map +1 -0
  502. package/dist/sources/catalog/mysql.d.ts +9 -0
  503. package/dist/sources/catalog/mysql.d.ts.map +1 -0
  504. package/dist/sources/catalog/mysql.js +77 -0
  505. package/dist/sources/catalog/mysql.js.map +1 -0
  506. package/dist/sources/catalog/postgres.d.ts +68 -0
  507. package/dist/sources/catalog/postgres.d.ts.map +1 -0
  508. package/dist/sources/catalog/postgres.js +164 -0
  509. package/dist/sources/catalog/postgres.js.map +1 -0
  510. package/dist/sources/catalog/types.d.ts +53 -0
  511. package/dist/sources/catalog/types.d.ts.map +1 -0
  512. package/dist/sources/catalog/types.js +30 -0
  513. package/dist/sources/catalog/types.js.map +1 -0
  514. package/dist/sources/connection-test.d.ts +37 -0
  515. package/dist/sources/connection-test.d.ts.map +1 -0
  516. package/dist/sources/connection-test.js +101 -0
  517. package/dist/sources/connection-test.js.map +1 -0
  518. package/dist/sources/crew-source.d.ts +31 -0
  519. package/dist/sources/crew-source.d.ts.map +1 -0
  520. package/dist/sources/crew-source.js +48 -0
  521. package/dist/sources/crew-source.js.map +1 -0
  522. package/dist/sources/dialer.d.ts +169 -0
  523. package/dist/sources/dialer.d.ts.map +1 -0
  524. package/dist/sources/dialer.js +761 -0
  525. package/dist/sources/dialer.js.map +1 -0
  526. package/dist/sources/drivers/mysql.d.ts +52 -0
  527. package/dist/sources/drivers/mysql.d.ts.map +1 -0
  528. package/dist/sources/drivers/mysql.js +348 -0
  529. package/dist/sources/drivers/mysql.js.map +1 -0
  530. package/dist/sources/drivers/postgres.d.ts +84 -0
  531. package/dist/sources/drivers/postgres.d.ts.map +1 -0
  532. package/dist/sources/drivers/postgres.js +381 -0
  533. package/dist/sources/drivers/postgres.js.map +1 -0
  534. package/dist/sources/drivers/sqlite.d.ts +47 -0
  535. package/dist/sources/drivers/sqlite.d.ts.map +1 -0
  536. package/dist/sources/drivers/sqlite.js +156 -0
  537. package/dist/sources/drivers/sqlite.js.map +1 -0
  538. package/dist/sources/drivers/types.d.ts +79 -0
  539. package/dist/sources/drivers/types.d.ts.map +1 -0
  540. package/dist/sources/drivers/types.js +31 -0
  541. package/dist/sources/drivers/types.js.map +1 -0
  542. package/dist/sources/graphql.d.ts +85 -0
  543. package/dist/sources/graphql.d.ts.map +1 -0
  544. package/dist/sources/graphql.js +155 -0
  545. package/dist/sources/graphql.js.map +1 -0
  546. package/dist/sources/kinds.d.ts +79 -0
  547. package/dist/sources/kinds.d.ts.map +1 -0
  548. package/dist/sources/kinds.js +145 -0
  549. package/dist/sources/kinds.js.map +1 -0
  550. package/dist/sources/policy/allowlists.d.ts +30 -0
  551. package/dist/sources/policy/allowlists.d.ts.map +1 -0
  552. package/dist/sources/policy/allowlists.js +104 -0
  553. package/dist/sources/policy/allowlists.js.map +1 -0
  554. package/dist/sources/policy/index.d.ts +20 -0
  555. package/dist/sources/policy/index.d.ts.map +1 -0
  556. package/dist/sources/policy/index.js +34 -0
  557. package/dist/sources/policy/index.js.map +1 -0
  558. package/dist/sources/policy/mysql.d.ts +21 -0
  559. package/dist/sources/policy/mysql.d.ts.map +1 -0
  560. package/dist/sources/policy/mysql.js +834 -0
  561. package/dist/sources/policy/mysql.js.map +1 -0
  562. package/dist/sources/policy/pg.d.ts +37 -0
  563. package/dist/sources/policy/pg.d.ts.map +1 -0
  564. package/dist/sources/policy/pg.js +572 -0
  565. package/dist/sources/policy/pg.js.map +1 -0
  566. package/dist/sources/policy/sqlite.d.ts +37 -0
  567. package/dist/sources/policy/sqlite.d.ts.map +1 -0
  568. package/dist/sources/policy/sqlite.js +94 -0
  569. package/dist/sources/policy/sqlite.js.map +1 -0
  570. package/dist/sources/policy/types.d.ts +46 -0
  571. package/dist/sources/policy/types.d.ts.map +1 -0
  572. package/dist/sources/policy/types.js +13 -0
  573. package/dist/sources/policy/types.js.map +1 -0
  574. package/dist/sources/routes.d.ts +154 -0
  575. package/dist/sources/routes.d.ts.map +1 -0
  576. package/dist/sources/routes.js +745 -0
  577. package/dist/sources/routes.js.map +1 -0
  578. package/dist/sources/safety/postgres.d.ts +87 -0
  579. package/dist/sources/safety/postgres.d.ts.map +1 -0
  580. package/dist/sources/safety/postgres.js +349 -0
  581. package/dist/sources/safety/postgres.js.map +1 -0
  582. package/dist/sources/sql.d.ts +51 -0
  583. package/dist/sources/sql.d.ts.map +1 -0
  584. package/dist/sources/sql.js +89 -0
  585. package/dist/sources/sql.js.map +1 -0
  586. package/dist/sources/store.d.ts +25 -0
  587. package/dist/sources/store.d.ts.map +1 -0
  588. package/dist/sources/store.js +59 -0
  589. package/dist/sources/store.js.map +1 -0
  590. package/dist/sources/uploads.d.ts +70 -0
  591. package/dist/sources/uploads.d.ts.map +1 -0
  592. package/dist/sources/uploads.js +636 -0
  593. package/dist/sources/uploads.js.map +1 -0
  594. package/dist/standing-orders/parse.d.ts +38 -0
  595. package/dist/standing-orders/parse.d.ts.map +1 -1
  596. package/dist/standing-orders/parse.js +104 -43
  597. package/dist/standing-orders/parse.js.map +1 -1
  598. package/dist/standing-orders/routes.d.ts +25 -126
  599. package/dist/standing-orders/routes.d.ts.map +1 -1
  600. package/dist/standing-orders/routes.js +4 -6
  601. package/dist/standing-orders/routes.js.map +1 -1
  602. package/dist/standing-orders/store.d.ts +22 -73
  603. package/dist/standing-orders/store.d.ts.map +1 -1
  604. package/dist/standing-orders/store.js +8 -12
  605. package/dist/standing-orders/store.js.map +1 -1
  606. package/dist/studio/assets/KnowledgeGraph-Cpm46tEp.js +1 -0
  607. package/dist/studio/assets/WickedSansA-Regular-CGPJLyb8.woff2 +0 -0
  608. package/dist/studio/assets/WickedSansA-SemiBold-Bk9KXUaV.woff2 +0 -0
  609. package/dist/studio/assets/favicon-BJA6hF2f.svg +1 -0
  610. package/dist/studio/assets/index-BRBwWQMH.css +32 -0
  611. package/dist/studio/assets/index-CVrWDGRP.js +1097 -0
  612. package/dist/studio/assets/wicked-studio-lettering-small-CBwSGqop.svg +2 -0
  613. package/dist/studio/assets/wicked-studio-wordmark-small-gF5xn6IC.svg +2 -0
  614. package/dist/studio/editors/wicked-apps/editor.json +45 -0
  615. package/dist/studio/editors/wicked-apps/icon.svg +1 -0
  616. package/dist/studio/editors/wicked-apps/index.html +151 -0
  617. package/dist/studio/editors/wicked-deck/editor.json +1 -1
  618. package/dist/studio/editors/wicked-deck/index.html +12 -8
  619. package/dist/studio/editors/wicked-doc/editor.json +1 -1
  620. package/dist/studio/editors/wicked-doc/index.html +12 -8
  621. package/dist/studio/editors/wicked-insights/editor.json +1 -1
  622. package/dist/studio/editors/wicked-insights/index.html +1 -1
  623. package/dist/studio/editors/wicked-page/editor.json +1 -1
  624. package/dist/studio/editors/wicked-page/index.html +12 -8
  625. package/dist/studio/editors/wicked-video/editor.json +1 -1
  626. package/dist/studio/editors/wicked-video/index.html +1 -1
  627. package/dist/studio/fonts/LICENSE-WickedSans.txt +97 -0
  628. package/dist/studio/index.html +3 -2
  629. package/dist/studio/testid-inventory.json +10850 -6700
  630. package/dist/team/routes.d.ts +31 -172
  631. package/dist/team/routes.d.ts.map +1 -1
  632. package/dist/team/routes.js +31 -8
  633. package/dist/team/routes.js.map +1 -1
  634. package/dist/voice/dashboard.d.ts +35 -313
  635. package/dist/voice/dashboard.d.ts.map +1 -1
  636. package/dist/voice/dashboard.js +10 -10
  637. package/dist/voice/dashboard.js.map +1 -1
  638. package/dist/voice/routes.d.ts +2 -6
  639. package/dist/voice/routes.d.ts.map +1 -1
  640. package/dist/voice/routes.js +2 -2
  641. package/dist/voice/routes.js.map +1 -1
  642. package/dist/watch/checks/check-failed.d.ts +4 -10
  643. package/dist/watch/checks/check-failed.d.ts.map +1 -1
  644. package/dist/watch/checks/check-failed.js +6 -8
  645. package/dist/watch/checks/check-failed.js.map +1 -1
  646. package/dist/watch/checks/claim-vs-evidence.js +3 -3
  647. package/dist/watch/checks/claim-vs-evidence.js.map +1 -1
  648. package/dist/watch/checks/deliver-audit.js +3 -3
  649. package/dist/watch/checks/deliver-audit.js.map +1 -1
  650. package/dist/watch/checks/discovery.d.ts.map +1 -1
  651. package/dist/watch/checks/discovery.js +5 -7
  652. package/dist/watch/checks/discovery.js.map +1 -1
  653. package/dist/watch/checks/lag.d.ts +4 -10
  654. package/dist/watch/checks/lag.d.ts.map +1 -1
  655. package/dist/watch/checks/lag.js +6 -8
  656. package/dist/watch/checks/lag.js.map +1 -1
  657. package/dist/watch/checks/quiet-after-claim.js +3 -3
  658. package/dist/watch/checks/quiet-after-claim.js.map +1 -1
  659. package/dist/watch/checks/scope-drift.js +3 -3
  660. package/dist/watch/checks/scope-drift.js.map +1 -1
  661. package/dist/watch/checks/team-path.js +2 -2
  662. package/dist/watch/checks/team-path.js.map +1 -1
  663. package/dist/watch/checks/ungated.js +3 -3
  664. package/dist/watch/checks/ungated.js.map +1 -1
  665. package/dist/watch/checks/warned-rule.js +3 -3
  666. package/dist/watch/checks/warned-rule.js.map +1 -1
  667. package/dist/watch/loader.d.ts.map +1 -1
  668. package/dist/watch/loader.js +12 -16
  669. package/dist/watch/loader.js.map +1 -1
  670. package/dist/workflow-catalog/build-v2.d.ts +90 -0
  671. package/dist/workflow-catalog/build-v2.d.ts.map +1 -0
  672. package/dist/workflow-catalog/build-v2.js +527 -0
  673. package/dist/workflow-catalog/build-v2.js.map +1 -0
  674. package/dist/workflow-catalog/build.d.ts +2 -0
  675. package/dist/workflow-catalog/build.d.ts.map +1 -1
  676. package/dist/workflow-catalog/build.js +8 -4
  677. package/dist/workflow-catalog/build.js.map +1 -1
  678. package/dist/workflow-catalog/catalog-data-v2.d.ts +12 -0
  679. package/dist/workflow-catalog/catalog-data-v2.d.ts.map +1 -0
  680. package/dist/workflow-catalog/catalog-data-v2.js +2582 -0
  681. package/dist/workflow-catalog/catalog-data-v2.js.map +1 -0
  682. package/dist/workflow-catalog/catalog-data.d.ts +7 -1
  683. package/dist/workflow-catalog/catalog-data.d.ts.map +1 -1
  684. package/dist/workflow-catalog/catalog-data.js +36 -7
  685. package/dist/workflow-catalog/catalog-data.js.map +1 -1
  686. package/dist/workflow-catalog/seeds-v2.d.ts +91 -0
  687. package/dist/workflow-catalog/seeds-v2.d.ts.map +1 -0
  688. package/dist/workflow-catalog/seeds-v2.js +2 -0
  689. package/dist/workflow-catalog/seeds-v2.js.map +1 -0
  690. package/dist/workflow-catalog/shape.d.ts +97 -0
  691. package/dist/workflow-catalog/shape.d.ts.map +1 -0
  692. package/dist/workflow-catalog/shape.js +97 -0
  693. package/dist/workflow-catalog/shape.js.map +1 -0
  694. package/dist/working-doc/service.d.ts.map +1 -1
  695. package/dist/working-doc/service.js +2 -1
  696. package/dist/working-doc/service.js.map +1 -1
  697. package/dist/zod.d.ts +39 -0
  698. package/dist/zod.d.ts.map +1 -0
  699. package/dist/zod.js +197 -0
  700. package/dist/zod.js.map +1 -0
  701. package/endpoint-manifest.json +651 -11
  702. package/package.json +31 -7
  703. package/runners/sqlite-runner.mjs +110 -0
  704. package/dist/studio/assets/WickedSans-Regular-fb698rcD.woff2 +0 -0
  705. package/dist/studio/assets/WickedSans-SemiBold-CD53n1AC.woff2 +0 -0
  706. package/dist/studio/assets/index-BUZ_-Syk.css +0 -32
  707. package/dist/studio/assets/index-u4O_7N-b.js +0 -986
@@ -14,9 +14,28 @@
14
14
  * failed probes.
15
15
  * - **Secrets.** Only a reference is stored. A value is resolved just for the probe and scrubbed
16
16
  * from its result (`probe.ts`).
17
+ *
18
+ * (DES-KNOWLEDGE-DATA-001 §5, the ONE registry) Every entry has an immutable `id`. A Postgres source
19
+ * is stored as Toolbox's own source document (`kind: 'toolbox-source'`), and {@link configOf} is the
20
+ * read-path projection that gives every consumer the K1 `kind: 'sql'` config it always read. A K1
21
+ * record is mapped on read, as descriptor version 1, only when the mapping keeps its descriptor hash;
22
+ * a save writes version 2. Each tool carries a reviewed disclosure class. Answers have a full view
23
+ * (human operators) and an agent-safe projection ({@link agentServerView}). Every write keeps the
24
+ * generation it replaces; {@link McpRegistry.restore} brings one back and fails closed.
17
25
  */
18
- import { canonicalJson, deriveToolClass, effectiveToolClass, ESTATE_SERVER, mcpSubject, parseMcpSubject, sha256Hex, toolSchemaHash } from './classify.js';
26
+ import { randomUUID } from 'node:crypto';
27
+ import { isIP } from 'node:net';
28
+ import { join } from 'node:path';
29
+ import { agentAccessOf, effectiveDisclosure, hasPmMarker, legacyEntryId, pmOf, proposedDisclosure, trackersOf } from '../knowledge/registry/entry.js';
30
+ import { bindingFor, bindingInForce, bindingOnSave } from '../knowledge/trackers/bindings.js';
31
+ import { PROJECTION_UNKNOWN, trackerLinkViews } from '../knowledge/trackers/view.js';
32
+ import { checkSourceDocument, DeploymentPolicyError, policyVersionOf } from '../knowledge/registry/policy.js';
33
+ import { canonicalJson, deriveToolClass, effectiveToolClass, ESTATE_SERVER, MCP_SERVER_NAME_RE, mcpSubject, parseMcpSubject, sha256Hex, toolSchemaHash } from './classify.js';
34
+ import { GENERATIONS_KEPT } from './registry-store.js';
19
35
  import { restTarget } from './rest.js';
36
+ import { classifyAddress, exactRangesFor, NO_CONFIRMATION } from '../sources/dialer.js';
37
+ import { CREW_SOURCE, sourceDescriptorHash, sqlFromToolboxEntry, toolboxEntryFromSql } from '../sources/kinds.js';
38
+ import { SourceCatalogStore } from '../sources/store.js';
20
39
  import { KEYCHAIN_SERVICE, keychainRef, parseSecretRef, resolveSecret, secretIsSet } from './secrets.js';
21
40
  /** How long a preview can be saved. */
22
41
  export const PREVIEW_TTL_MS = 15 * 60 * 1000;
@@ -28,13 +47,17 @@ export const HEALTH_FAILING_AFTER = 3;
28
47
  export class McpRegistryError extends Error {
29
48
  status;
30
49
  code;
50
+ humanMessage;
31
51
  constructor(
32
52
  // 500: the registry and the OS secret store disagree and crew could not reconcile them
33
53
  // (crew#719, `secret_orphaned`) — the message names what was left behind.
34
- status, code, message) {
54
+ status, code, message,
55
+ /** (DES-APPS-001 §5.2) Fuller words that hold a source's own text: answered to a HUMAN only. */
56
+ humanMessage) {
35
57
  super(message);
36
58
  this.status = status;
37
59
  this.code = code;
60
+ this.humanMessage = humanMessage;
38
61
  }
39
62
  }
40
63
  export class McpRegistry {
@@ -42,22 +65,52 @@ export class McpRegistry {
42
65
  previews = new Map();
43
66
  now;
44
67
  env;
68
+ catalogs;
69
+ /**
70
+ * (crew#1328 item 3) A restored registry generation changes a source's projection key (its descriptor and allowed
71
+ * views) with no catalog written, so `catalogs.onWritten` does not fire. Every source a restore commits is named
72
+ * here once it has landed, and the daemon queues a re-projection of its structure into estate, so a source whose
73
+ * stored catalog matches the restored descriptor does not wait for the next describe or boot (one whose catalog
74
+ * belongs to a later descriptor still needs a describe). A listener's failure never fails the restore.
75
+ */
76
+ onSourceChanged = null;
77
+ /** (DES-PM-001 §3.4) Whether estate holds each tracker's links yet; the daemon points it at the tracker projector. */
78
+ trackerProjection = PROJECTION_UNKNOWN;
79
+ /** (DES-PM-001 §3.4) Called once a restore has landed (the daemon points it at the tracker projector). */
80
+ onRestored;
45
81
  constructor(deps) {
46
82
  this.deps = deps;
47
83
  this.now = deps.now ?? Date.now;
48
84
  this.env = deps.env ?? process.env;
85
+ // Beside the registry file; a store without a directory (a test double) gets the default place.
86
+ const dir = deps.store.directory;
87
+ this.catalogs = deps.catalogs ?? new SourceCatalogStore(typeof dir === 'string' ? join(dir, 'catalogs') : undefined);
49
88
  }
50
89
  get secretStoreAvailable() {
51
90
  return this.deps.secrets.available;
52
91
  }
53
92
  async list() {
54
- const file = await this.deps.store.read();
93
+ const file = await this.readFile();
55
94
  const servers = await Promise.all(file.servers.map((s) => this.view(s)));
56
95
  const discovered = this.deps.discover(new Set(file.servers.map((s) => s.name)));
57
96
  return { servers, discovered };
58
97
  }
98
+ /**
99
+ * (DES-KNOWLEDGE-DATA-001 §5.2, crew#1310) The agent-safe view: name, kind, switch, health state, the tools with
100
+ * their classes, and a source's see/query switches. No host, port, database, login, url, command, path, address,
101
+ * secret reference or descriptor.
102
+ */
103
+ async listForAgents() {
104
+ const file = await this.readFile();
105
+ return { servers: (await Promise.all(file.servers.map((s) => this.view(s)))).map(agentServerView) };
106
+ }
107
+ /** The kept generations of the registry, newest first (DES-KNOWLEDGE-DATA-001 §5.5). */
108
+ async generations() {
109
+ const file = await this.readFile();
110
+ return { current: file.generation ?? 0, generations: await this.deps.store.generations() };
111
+ }
59
112
  async get(name) {
60
- const file = await this.deps.store.read();
113
+ const file = await this.readFile();
61
114
  return this.view(this.find(file.servers, name));
62
115
  }
63
116
  /**
@@ -69,6 +122,12 @@ export class McpRegistry {
69
122
  if (config.name === ESTATE_SERVER) {
70
123
  throw new McpRegistryError(400, 'reserved_name', `"${ESTATE_SERVER}" is reserved: mcp:${ESTATE_SERVER}/<tool> is the broker's estate relay (the seat's own estate), never a registered server; choose another name`);
71
124
  }
125
+ if ((config.kind === 'sql' || config.kind === 'graphql' || config.kind === 'toolbox-source') && config.name === CREW_SOURCE) {
126
+ throw new McpRegistryError(400, 'reserved_name', `"${CREW_SOURCE}" is the built-in crew source; choose another name`);
127
+ }
128
+ // (DES-KNOWLEDGE-DATA-001 §5.1) A database source is saved as its Toolbox document, checked against the
129
+ // deployment policy here (the preview) and again when the write lands.
130
+ config = this.forSave(config);
72
131
  if (stagedSecret !== null) {
73
132
  if (!this.deps.secrets.available) {
74
133
  throw new McpRegistryError(501, 'secret_store_unavailable', 'this platform has no OS secret store; reference a daemon env variable instead (auth.ref "env:<NAME>")');
@@ -86,24 +145,34 @@ export class McpRegistry {
86
145
  throw new McpRegistryError(409, 'secret_missing', result.error);
87
146
  if (!result.ok) {
88
147
  const what = config.kind === 'rest' ? 'the OpenAPI document could not be imported' : 'the server did not answer tools/list';
89
- throw new McpRegistryError(502, 'probe_failed', `${what}: ${result.error}`);
148
+ // (DES-APPS-001 §5.2) The dialer refused the connection: a 409 naming why (an unconfirmed range
149
+ // to confirm, an always-refused address, plaintext), not an upstream failure.
150
+ const human = result.sourceDetail !== undefined ? `${what}: ${result.sourceDetail}` : undefined;
151
+ if (result.refusal !== undefined)
152
+ throw new McpRegistryError(409, result.refusal, `${what}: ${result.error}`, human);
153
+ throw new McpRegistryError(502, 'probe_failed', `${what}: ${result.error}`, human);
90
154
  }
91
155
  const tools = result.tools.map((t) => ({ ...t, schemaHash: hashOf(config, t) }));
92
156
  const previewHash = sha256Hex(canonicalJson({ config, tools: tools.map((t) => [t.name, t.schemaHash]) }));
93
157
  const expiresAt = this.now() + PREVIEW_TTL_MS;
94
- const existing = (await this.deps.store.read()).servers.find((s) => s.name === config.name);
158
+ const existing = (await this.readFile()).servers.find((s) => s.name === config.name);
95
159
  // (G2) A mismatch with the spec's `servers`, or a private address, needs the operator to name
96
160
  // the origin at save, unless an earlier save of this server already confirmed that origin.
97
161
  const egress = config.kind !== 'rest' || result.egress === undefined ? null : { ...result.egress, confirmRequired: egressRefusal(result.egress, null, existing) !== null };
98
162
  if (config.kind === 'rest' && egress === null)
99
163
  throw new McpRegistryError(502, 'probe_failed', 'the rest probe did not report where its calls go');
100
- this.hold(previewHash, { config, tools, expiresAt, secret: stagedSecret, egress });
164
+ const source = result.source ?? null;
165
+ if ((config.kind === 'sql' || config.kind === 'graphql') && source === null)
166
+ throw new McpRegistryError(502, 'probe_failed', 'the source probe did not describe the source');
167
+ this.hold(previewHash, { config, tools, expiresAt, secret: stagedSecret, egress, source });
101
168
  const was = (name) => existing?.tools.find((p) => p.name === name);
102
169
  // The override a save keeps: only while the tool's schema is unchanged (as `save` decides).
103
170
  const survivingOverride = (t) => {
104
171
  const w = was(t.name);
105
172
  return w !== undefined && w.schemaHash === t.schemaHash ? w.classOverride : null;
106
173
  };
174
+ // (DES-KNOWLEDGE-DATA-001 §5.1) The disclosure class a save gives each tool when the body names none.
175
+ const reviewed = (t) => disclosureOnSave(t, was(t.name), undefined, config.kind, config.pm?.system ?? null)?.class ?? null;
107
176
  return {
108
177
  previewHash,
109
178
  expiresAt: new Date(expiresAt).toISOString(),
@@ -119,11 +188,14 @@ export class McpRegistry {
119
188
  classOverride: survivingOverride(t),
120
189
  schemaHash: t.schemaHash,
121
190
  enabledOnSave: enabledOnSave(was(t.name), t),
191
+ disclosure: reviewed(t),
192
+ ...(config.pm != null ? { binding: bindingOnSave(config.pm.system, t) === null ? null : { policy: bindingOnSave(config.pm.system, t).policy } } : {}),
122
193
  ...(config.kind === 'rest' ? { rest: t.rest ?? null } : {}),
123
194
  })),
124
195
  diff: existing === undefined ? null : diffTools(existing.tools, tools),
125
196
  ...(result.skipped !== undefined && result.skipped.length > 0 ? { skipped: result.skipped } : {}),
126
197
  ...(egress !== null ? { egress } : {}),
198
+ ...(source !== null ? { source: { catalog: source.catalog, ...(source.privileges !== undefined ? { privileges: source.privileges } : {}) } } : {}),
127
199
  };
128
200
  }
129
201
  /**
@@ -141,8 +213,12 @@ export class McpRegistry {
141
213
  * (G2) `allowOrigin` is the operator naming the exact origin a `rest` server's calls go to. It is
142
214
  * required when the preview's `egress.confirmRequired` (see {@link checkEgress}) and remembered
143
215
  * on the record, so a re-save over the same origin does not ask again.
216
+ *
217
+ * (DES-KNOWLEDGE-DATA-001 §5.1) `disclosures` is the operator's review of each tool's disclosure class (human
218
+ * operator only, like a write grant). A tool it does not name keeps its class while its schema is unchanged;
219
+ * a tool of crew's own Toolbox configuration gets crew's class; any other tool has none until reviewed.
144
220
  */
145
- async save(previewHash, enabledWrites = [], allowOrigin = null) {
221
+ async save(previewHash, enabledWrites = [], allowOrigin = null, disclosures = {}) {
146
222
  if (previewHash === undefined) {
147
223
  throw new McpRegistryError(409, 'preview_required', 'saving a server needs the previewHash of a preview of it: POST /mcp/servers/preview first');
148
224
  }
@@ -154,6 +230,7 @@ export class McpRegistry {
154
230
  // A wrong grant is refused before the preview is spent, so the operator can correct it and save again.
155
231
  await this.checkWriteGrants(previewHash, enabledWrites);
156
232
  await this.checkEgress(previewHash, allowOrigin);
233
+ this.checkDisclosures(previewHash, disclosures);
157
234
  const granted = new Set(enabledWrites);
158
235
  this.previews.delete(previewHash);
159
236
  const stamp = new Date(this.now()).toISOString();
@@ -168,11 +245,24 @@ export class McpRegistry {
168
245
  // whose registry write then failed used to leave the NEW secret behind under an unchanged row:
169
246
  // the credential its running calls use had silently changed, which is a worse outcome than the
170
247
  // orphan this was written to prevent. `null` = no prior value, and then the rollback deletes.
248
+ // (DES-PM-001 §3) A save that would drop or change a PM source's marker is refused BEFORE any credential is
249
+ // written (the mutation refuses it again, under the store's chain, for a marker set meanwhile).
250
+ const existing = (await this.readFile()).servers.find((s) => s.name === held.config.name);
251
+ const existingPm = existing === undefined ? null : pmOf(existing);
252
+ if (existingPm !== null && (held.config.pm == null || held.config.pm.system !== existingPm.system)) {
253
+ throw new McpRegistryError(409, 'pm_marker_fixed', `${held.config.name} is registered as a ${existingPm.system} project-management source; save it with pm.system "${existingPm.system}", or remove it and register it again`);
254
+ }
171
255
  const prior = held.secret === null ? null : await this.deps.secrets.get(held.config.name);
172
256
  if (held.secret !== null)
173
257
  await this.deps.secrets.set(held.config.name, held.secret);
174
- const saved = await this.restoreSecretOnFailure(held.config.name, held.secret !== null, prior, () => this.deps.store.mutate((file) => {
258
+ const saved = await this.restoreSecretOnFailure(held.config.name, held.secret !== null, prior, () => this.mutate(async (file) => {
175
259
  const prior = file.servers.find((s) => s.name === held.config.name);
260
+ // (DES-PM-001 §3) A PM entry stays the PM system it was registered as: a re-save that drops the marker, or
261
+ // names another system, would hand its tools to the plain path (or its links to another vendor).
262
+ const priorPm = prior === undefined ? null : pmOf(prior);
263
+ if (priorPm !== null && (held.config.pm == null || held.config.pm.system !== priorPm.system)) {
264
+ throw new McpRegistryError(409, 'pm_marker_fixed', `${held.config.name} is registered as a ${priorPm.system} project-management source; save it with pm.system "${priorPm.system}", or remove it and register it again`);
265
+ }
176
266
  // (G2) Re-judged against the record as it is NOW, inside the write: a confirmation the
177
267
  // preview inherited from a server since removed or re-pointed does not carry over.
178
268
  if (held.egress !== null) {
@@ -194,6 +284,9 @@ export class McpRegistry {
194
284
  observedSchemaHash: t.schemaHash,
195
285
  present: true,
196
286
  ...(t.rest != null ? { rest: t.rest } : {}),
287
+ disclosure: disclosureOnSave(t, was, disclosures[t.name], held.config.kind, held.config.pm?.system ?? null),
288
+ // (DES-PM-001 §3) A PM tool's binding: crew's current policy, bound to the schema this save registers.
289
+ ...(held.config.pm != null ? { binding: bindingOnSave(held.config.pm.system, t) } : {}),
197
290
  };
198
291
  });
199
292
  for (const old of prior?.tools ?? []) {
@@ -203,8 +296,22 @@ export class McpRegistry {
203
296
  const origin = held.egress?.origin ?? null;
204
297
  // The confirmed origin is kept while the server still goes there: named now, or by an earlier save.
205
298
  const allowedOrigin = origin !== null && (allowOrigin === origin || prior?.allowedOrigin === origin) ? origin : null;
299
+ const { address, sql, viewsAllowed, entry, id: _unsavedId, pm: heldPm, ...config } = held.config;
300
+ void _unsavedId;
301
+ // (DES-KNOWLEDGE-DATA-001 §5.1) A database source is stored as its Toolbox document (no `sql`): the read
302
+ // path projects it. A re-save keeps the entry's id; a new name gets a new one.
303
+ const stored = entry != null
304
+ ? { kind: 'toolbox-source', toolbox: entry.toolbox, runtime: entry.runtime, tls: entry.tls, descriptorVersion: entry.descriptorVersion, policyVersion: entry.policyVersion }
305
+ : sql != null
306
+ ? { sql }
307
+ : {};
206
308
  const record = {
207
- ...held.config,
309
+ id: prior?.id ?? randomUUID(),
310
+ ...config,
311
+ ...stored,
312
+ ...(address != null ? { address } : {}),
313
+ ...(heldPm != null ? { pm: { system: heldPm.system } } : {}),
314
+ ...(viewsAllowed != null ? { viewsAllowed } : {}),
208
315
  ...(allowedOrigin !== null ? { allowedOrigin } : {}),
209
316
  enabled: prior?.enabled ?? true,
210
317
  health: { state: 'ok', consecutiveFailures: 0, checkedAt: stamp, lastError: null },
@@ -212,11 +319,46 @@ export class McpRegistry {
212
319
  updatedAt: stamp,
213
320
  tools,
214
321
  };
322
+ // (DES-APPS-001 §7.4, DES-KNOWLEDGE-DATA-001 §5.4) Allow writes is off on every new Postgres source, and
323
+ // "query" on every new source. A re-save keeps each only while the descriptor is unchanged, and a K1
324
+ // entry's first save writes descriptor version 2, which is a change (grants bind to the descriptor anyway).
325
+ const sameDescriptor = prior !== undefined && isSourceRecord(prior) && isSourceRecord(record) && sourceDescriptorHash(configOf(prior)) === sourceDescriptorHash(configOf(record));
326
+ if (isPostgresRecord(record))
327
+ record.allowWrites = prior !== undefined && prior.allowWrites === true && isPostgresRecord(prior) && sameDescriptor;
328
+ if (prior !== undefined && prior.agents !== undefined && isSourceRecord(prior) && isSourceRecord(record)) {
329
+ const was = agentAccessOf(prior);
330
+ record.agents = { ...was, query: was.query && sameDescriptor };
331
+ }
332
+ // (DES-PM-001 §3) A PM entry under the source safeguards: a re-save keeps its switches and its links, and turns
333
+ // "query" off when its execution descriptor changed (no issue is read until a person turns it on again).
334
+ if (prior !== undefined && priorPm !== null) {
335
+ const samePm = pmDescriptorHash(configOf(prior)) === pmDescriptorHash(configOf(record));
336
+ if (prior.agents !== undefined) {
337
+ const was = agentAccessOf(prior);
338
+ record.agents = { ...was, query: was.query && samePm };
339
+ }
340
+ if (prior.trackers !== undefined)
341
+ record.trackers = structuredClone(prior.trackers);
342
+ if (prior.retired !== undefined)
343
+ record.retired = structuredClone(prior.retired);
344
+ }
215
345
  file.servers = [...file.servers.filter((s) => s.name !== record.name), record];
346
+ // The description lands INSIDE the record's own write (the store serializes mutations), so a
347
+ // record and its description can never be paired with another save's.
348
+ if (held.source !== null)
349
+ await this.catalogs.write(record.name, { ...held.source, descriptorHash: sourceDescriptorHash(configOf(record)) });
216
350
  return record;
217
351
  }));
218
352
  return this.view(saved);
219
353
  }
354
+ sourceChanged(name) {
355
+ try {
356
+ this.onSourceChanged?.(name);
357
+ }
358
+ catch {
359
+ // a listener's failure is its own (the projector logs); the registry write has landed
360
+ }
361
+ }
220
362
  /**
221
363
  * Run `commit`; if it throws and this save had written the OS secret store, put the entry back
222
364
  * exactly as it was — deleted when there was no `prior` value, restored to `prior` when there
@@ -263,7 +405,7 @@ export class McpRegistry {
263
405
  const held = this.previews.get(previewHash);
264
406
  if (held === undefined || held.expiresAt <= this.now())
265
407
  return;
266
- const prior = (await this.deps.store.read()).servers.find((s) => s.name === held.config.name);
408
+ const prior = (await this.readFile()).servers.find((s) => s.name === held.config.name);
267
409
  for (const name of enabledWrites) {
268
410
  const t = held.tools.find((x) => x.name === name);
269
411
  if (t === undefined)
@@ -277,8 +419,8 @@ export class McpRegistry {
277
419
  }
278
420
  /**
279
421
  * (G2, DES-data-connectors §3) Refuse a save whose egress the operator has not confirmed: when
280
- * the held preview's `egress.confirmRequired` (the base URL matches none of the spec's `servers`,
281
- * or its host is a loopback/private address), `allowOrigin` must be exactly `egress.origin`
422
+ * the held preview's `egress.confirmRequired` (the base URL matches none of the spec's `servers`;
423
+ * a loopback/private host is the dialer's, confirmed as `address.allow`), `allowOrigin` must be exactly `egress.origin`
282
424
  * (409 `egress_unconfirmed`). An `allowOrigin` that names another origin is refused the same way
283
425
  * even when no confirmation is needed, and one for a server that is not `rest` is a 400
284
426
  * `egress_not_rest`. Like {@link checkWriteGrants} it changes nothing, so the route calls it
@@ -294,11 +436,24 @@ export class McpRegistry {
294
436
  throw new McpRegistryError(400, 'egress_not_rest', 'allowOrigin is for a rest server');
295
437
  return;
296
438
  }
297
- const prior = (await this.deps.store.read()).servers.find((s) => s.name === held.config.name);
439
+ const prior = (await this.readFile()).servers.find((s) => s.name === held.config.name);
298
440
  const refusal = egressRefusal(held.egress, allowOrigin, prior);
299
441
  if (refusal !== null)
300
442
  throw refusal;
301
443
  }
444
+ /**
445
+ * (DES-KNOWLEDGE-DATA-001 §5.1) Refuse a `disclosures` review that does not fit the held preview: a tool it
446
+ * does not list (400 `unknown_tool`). Changes nothing. An unknown or expired preview is left for `save`.
447
+ */
448
+ checkDisclosures(previewHash, disclosures) {
449
+ const held = this.previews.get(previewHash);
450
+ if (held === undefined || held.expiresAt <= this.now())
451
+ return;
452
+ for (const name of Object.keys(disclosures)) {
453
+ if (!held.tools.some((t) => t.name === name))
454
+ throw new McpRegistryError(400, 'unknown_tool', `disclosures names ${name}, which this preview does not list`);
455
+ }
456
+ }
302
457
  /**
303
458
  * (G2) Whether every saved tool of the `rest` server `name` has a hash that covers the server's
304
459
  * target. `false` for a registration saved before G2 (or whose url or auth header changed outside
@@ -306,7 +461,7 @@ export class McpRegistry {
306
461
  * unknown server and for an MCP server.
307
462
  */
308
463
  async targetBound(name) {
309
- const s = (await this.deps.store.read()).servers.find((x) => x.name === name);
464
+ const s = (await this.readFile()).servers.find((x) => x.name === name);
310
465
  return s === undefined || s.tools.every((t) => targetBound(s, t));
311
466
  }
312
467
  /** What a held preview would register: its server name and each tool's schema hash (S6). */
@@ -315,6 +470,8 @@ export class McpRegistry {
315
470
  if (held === undefined || held.expiresAt <= this.now())
316
471
  return null;
317
472
  return {
473
+ pm: held.config.pm ?? null,
474
+ address: held.config.address ?? null,
318
475
  name: held.config.name,
319
476
  tools: held.tools.map((t) => ({ name: t.name, schemaHash: t.schemaHash })),
320
477
  egress: held.egress,
@@ -322,7 +479,7 @@ export class McpRegistry {
322
479
  };
323
480
  }
324
481
  async setServerEnabled(name, enabled) {
325
- const rec = await this.deps.store.mutate((file) => {
482
+ const rec = await this.mutate((file) => {
326
483
  const s = this.find(file.servers, name);
327
484
  s.enabled = enabled;
328
485
  s.updatedAt = new Date(this.now()).toISOString();
@@ -332,9 +489,13 @@ export class McpRegistry {
332
489
  }
333
490
  /** Remove a server, and the keychain secret it owns (`keychain:wicked-mcp/<name>`). */
334
491
  async remove(name) {
335
- const removed = await this.deps.store.mutate((file) => {
492
+ const removed = await this.mutate(async (file) => {
336
493
  const s = this.find(file.servers, name);
337
494
  file.servers = file.servers.filter((x) => x.name !== name);
495
+ // Inside the mutation, serialized with every save and upload: a source saved under this name
496
+ // next writes its catalog after this deletion, never before it.
497
+ if (isSourceRecord(s))
498
+ await this.catalogs.remove(name);
338
499
  return s;
339
500
  });
340
501
  if (removed.auth?.ref === keychainRef(name) && this.deps.secrets.available) {
@@ -362,11 +523,19 @@ export class McpRegistry {
362
523
  if (parts === null)
363
524
  throw new McpRegistryError(404, 'unknown_tool', `no tool ${subject}`);
364
525
  const stamp = new Date(this.now()).toISOString();
365
- const { server, tool, grant } = await this.deps.store.mutate((file) => {
526
+ const { server, tool, grant } = await this.mutate((file) => {
366
527
  const s = this.find(file.servers, parts.server);
367
528
  const t = s.tools.find((x) => x.name === parts.tool);
368
529
  if (t === undefined)
369
530
  throw new McpRegistryError(404, 'unknown_tool', `no tool ${subject}`);
531
+ // (DES-KNOWLEDGE-DATA-001 §5.1) A disclosure class is reviewed by a human operator, against the schema the
532
+ // operator saved; clearing one (the tool is offered to no agent) needs no review.
533
+ if (patch.disclosure != null) {
534
+ if (opts.mayReviewDisclosure !== true)
535
+ throw new McpRegistryError(403, 'disclosure_review_human_only', `only a human operator reviews what ${subject} discloses`);
536
+ if (t.schemaHash === null || t.schemaHash !== t.observedSchemaHash)
537
+ throw new McpRegistryError(409, 'not_registered', `${subject}'s schema is not the saved one: preview and save the server again, then review it`);
538
+ }
370
539
  const before = t.enabled && isWriteGrant(t.annotations, t.classOverride);
371
540
  const enabled = patch.enabled ?? t.enabled;
372
541
  const override = patch.classOverride !== undefined ? patch.classOverride : t.classOverride;
@@ -376,6 +545,8 @@ export class McpRegistry {
376
545
  }
377
546
  t.enabled = enabled;
378
547
  t.classOverride = override;
548
+ if (patch.disclosure !== undefined)
549
+ t.disclosure = patch.disclosure === null || t.schemaHash === null ? null : { class: patch.disclosure, schemaHash: t.schemaHash };
379
550
  s.updatedAt = stamp;
380
551
  return { server: s, tool: t, grant };
381
552
  });
@@ -383,12 +554,12 @@ export class McpRegistry {
383
554
  }
384
555
  /** Probe a registered server again: record its health and its tool diff. */
385
556
  async test(name) {
386
- const current = this.find((await this.deps.store.read()).servers, name);
557
+ const current = this.find((await this.readFile()).servers, name);
387
558
  const config = configOf(current);
388
559
  const result = await this.probe(config);
389
560
  const stamp = new Date(this.now()).toISOString();
390
561
  let diff = null;
391
- const rec = await this.deps.store.mutate((file) => {
562
+ const rec = await this.mutate((file) => {
392
563
  const s = this.find(file.servers, name);
393
564
  // A save with a different config landed while the probe ran: the result describes a server
394
565
  // that is no longer registered, so it is not applied to the new one.
@@ -447,9 +618,10 @@ export class McpRegistry {
447
618
  // orphan nothing can find again — a keychain service's entries cannot be enumerated — and it
448
619
  // was the first half of the non-atomic add: secret, then save, with a window between them.
449
620
  // A NEW server's secret is staged with its preview and committed by `save`.
450
- const server = this.find((await this.deps.store.read()).servers, name);
621
+ const server = this.find((await this.readFile()).servers, name);
451
622
  if (server.auth?.ref !== ref) {
452
- throw new McpRegistryError(400, 'secret_not_referenced', `${name} does not reference ${ref} (auth.ref is ${server.auth?.ref ?? 'unset'}), so a secret stored there would be unreachable; stage it with the preview instead`);
623
+ // The stored reference is a connection field: it is not echoed (an agent-kind caller reads errors too).
624
+ throw new McpRegistryError(400, 'secret_not_referenced', `${name} does not reference ${ref}, so a secret stored there would be unreachable; stage it with the preview instead`);
453
625
  }
454
626
  await this.deps.secrets.set(name, value);
455
627
  return ref;
@@ -460,7 +632,7 @@ export class McpRegistry {
460
632
  * was saved reads `registered: false`, which the engine denies (D-5).
461
633
  */
462
634
  async resolveCall(server, tool) {
463
- const s = (await this.deps.store.read()).servers.find((x) => x.name === server);
635
+ const s = (await this.readFile()).servers.find((x) => x.name === server);
464
636
  if (s === undefined)
465
637
  return null;
466
638
  const t = s.tools.find((x) => x.name === tool);
@@ -469,8 +641,12 @@ export class McpRegistry {
469
641
  rest: t?.rest ?? null,
470
642
  annotations: t?.annotations ?? null,
471
643
  classOverride: t?.classOverride ?? null,
644
+ schemaHash: t?.schemaHash ?? null,
645
+ disclosure: t === undefined ? null : effectiveDisclosure(t),
646
+ id: entryId(s),
472
647
  registered: s.enabled && t !== undefined && t.enabled && statusOf(s, t) === 'registered',
473
648
  resaveRequired: t !== undefined && !targetBound(s, t),
649
+ ...(hasPmMarker(s) ? { pm: true } : {}),
474
650
  };
475
651
  }
476
652
  /**
@@ -480,16 +656,19 @@ export class McpRegistry {
480
656
  */
481
657
  async callableTools() {
482
658
  const out = [];
483
- for (const s of (await this.deps.store.read()).servers) {
484
- if (!s.enabled)
659
+ for (const s of (await this.readFile()).servers) {
660
+ // (DES-PM-001 §3.1) A PM entry's tools are the gate's to list, bound to the unit's tracker set; never raw.
661
+ if (!s.enabled || hasPmMarker(s))
485
662
  continue;
486
663
  for (const t of s.tools) {
487
664
  if (!t.enabled || statusOf(s, t) !== 'registered')
488
665
  continue;
489
666
  out.push({
490
667
  server: s.name,
668
+ id: entryId(s),
491
669
  tool: t.name,
492
- kind: s.kind,
670
+ kind: configOf(s).kind,
671
+ disclosure: effectiveDisclosure(t),
493
672
  annotations: t.annotations,
494
673
  classOverride: t.classOverride,
495
674
  description: t.description,
@@ -504,7 +683,7 @@ export class McpRegistry {
504
683
  * enabled or not (an operator debugs a server it switched off), or `null` for no such name.
505
684
  */
506
685
  async inspectTarget(name) {
507
- const s = (await this.deps.store.read()).servers.find((x) => x.name === name);
686
+ const s = (await this.readFile()).servers.find((x) => x.name === name);
508
687
  return s === undefined ? null : configOf(s);
509
688
  }
510
689
  /**
@@ -518,7 +697,287 @@ export class McpRegistry {
518
697
  const secret = await resolveSecret(config.auth.ref, this.deps.secrets, this.env);
519
698
  return { secret, missing: secret === null };
520
699
  }
700
+ // ── Apps data sources (DES-APPS-001 §5, §7.4) ─────────────────────────────────────────────
701
+ /**
702
+ * A `sql` or `graphql` source as the sources routes need it: its config, its Allow writes switch
703
+ * and its stored description (`null` until described). 404 for no such source, 400 for a server
704
+ * that is not one.
705
+ */
706
+ async source(name) {
707
+ const s = this.find((await this.readFile()).servers, name);
708
+ const config = configOf(s);
709
+ if (config.kind !== 'sql' && config.kind !== 'graphql')
710
+ throw new McpRegistryError(400, 'not_a_source', `${name} is an ${config.kind} server, not a data source`);
711
+ const descriptorHash = sourceDescriptorHash(config);
712
+ const stored = await this.catalogs.read(name);
713
+ // A description taken under another descriptor (a re-save since) is not this source's: not described.
714
+ return { config, allowWrites: s.allowWrites === true, description: stored !== null && stored.descriptorHash === descriptorHash ? stored : null, descriptorHash, enabled: s.enabled };
715
+ }
716
+ /**
717
+ * (DES-APPS-001 §9.4) A REST or MCP server's tool as an Apps query or API action uses it: the server's
718
+ * config and descriptor hash, and the tool's record, with whether the person's saved schema still is the
719
+ * one the server shows (`bound`). The per-tool switch (G1) governs agent runs only, so a tool's `enabled`
720
+ * is not consulted here; a server switched off is. `null` = no such server or tool.
721
+ */
722
+ async appTool(server, tool) {
723
+ const s = (await this.readFile()).servers.find((x) => x.name === server);
724
+ if (s === undefined || (s.kind !== 'rest' && s.kind !== 'mcp-http' && s.kind !== 'mcp-stdio'))
725
+ return null;
726
+ // (DES-PM-001) PM-1 gives Apps no PM entry: its tools are read only through the gate's bindings.
727
+ if (hasPmMarker(s))
728
+ return null;
729
+ const t = s.tools.find((x) => x.name === tool);
730
+ if (t === undefined)
731
+ return null;
732
+ return { config: configOf(s), tool: structuredClone(t), bound: s.enabled && statusOf(s, t) === 'registered' };
733
+ }
734
+ /** (K2b) A server's config and whether it is switched on, from ONE read of the store (no presentation work). */
735
+ async snapshot(name) {
736
+ const s = (await this.readFile()).servers.find((x) => x.name === name);
737
+ return s === undefined ? null : { config: configOf(s), enabled: s.enabled };
738
+ }
739
+ /** Store a fresh description of a source (a re-describe), bound to the descriptor it was taken under. */
740
+ async saveDescription(name, description, descriptorHash) {
741
+ // Checked and written inside one registry mutation (serialized with every save), so a save that
742
+ // lands while the source was being described always wins.
743
+ await this.mutate(async (file) => {
744
+ const s = this.find(file.servers, name);
745
+ if (sourceDescriptorHash(configOf(s)) !== descriptorHash)
746
+ throw new McpRegistryError(409, 'server_changed', `${name} was saved again while it was being described; describe it again`);
747
+ await this.catalogs.write(name, { ...description, descriptorHash });
748
+ });
749
+ }
750
+ /**
751
+ * (DES-APPS-001 §7.4) Turn a Postgres source's Allow writes switch on or off. The route allows a
752
+ * human operator only and audits it; turning it off withdraws the source's row-write grants (the
753
+ * caller's hook). Answers whether it changed.
754
+ */
755
+ async setAllowWrites(name, allowed) {
756
+ const { before, rec } = await this.mutate((file) => {
757
+ const s = this.find(file.servers, name);
758
+ if (!isPostgresRecord(s))
759
+ throw new McpRegistryError(400, 'writes_not_supported', `${name} is not a Postgres source: v1 row writes are Postgres only`);
760
+ const was = s.allowWrites === true;
761
+ s.allowWrites = allowed;
762
+ s.updatedAt = new Date(this.now()).toISOString();
763
+ return { before: was, rec: s };
764
+ });
765
+ return { before, after: allowed, server: await this.view(rec) };
766
+ }
767
+ /**
768
+ * Register (or replace) an uploaded snapshot as a `sql`/`sqlite` source (DES-APPS-001 §5.1). The
769
+ * upload IS the person's act, so there is no preview; a name held by any other kind is refused.
770
+ */
771
+ async registerSnapshotSource(name, digest, description) {
772
+ if (name === CREW_SOURCE || name === ESTATE_SERVER)
773
+ throw new McpRegistryError(400, 'reserved_name', `"${name}" is reserved; choose another name`);
774
+ const stamp = new Date(this.now()).toISOString();
775
+ const rec = await this.mutate(async (file) => {
776
+ const prior = file.servers.find((s) => s.name === name);
777
+ if (prior !== undefined && !(prior.kind === 'sql' && prior.sql?.driver === 'sqlite')) {
778
+ throw new McpRegistryError(409, 'name_taken', `${name} is already a registered ${prior.kind} server; choose another name`);
779
+ }
780
+ const record = {
781
+ id: prior?.id ?? randomUUID(),
782
+ name,
783
+ kind: 'sql',
784
+ command: null,
785
+ args: [],
786
+ url: null,
787
+ auth: null,
788
+ sql: { driver: 'sqlite', snapshot: digest },
789
+ viewsAllowed: [],
790
+ enabled: true,
791
+ health: { state: 'ok', consecutiveFailures: 0, checkedAt: stamp, lastError: null },
792
+ registeredAt: prior?.registeredAt ?? stamp,
793
+ updatedAt: stamp,
794
+ tools: [],
795
+ // (DES-KNOWLEDGE-DATA-001 §7.1) A new upload of the same name keeps the person's agent switches; "query"
796
+ // only when it is the same snapshot (a new digest is a new descriptor).
797
+ ...(prior?.agents !== undefined ? { agents: { ...agentAccessOf(prior), query: agentAccessOf(prior).query && prior.sql?.snapshot === digest } } : {}),
798
+ };
799
+ file.servers = [...file.servers.filter((s) => s.name !== name), record];
800
+ await this.catalogs.write(name, { ...description, descriptorHash: sourceDescriptorHash(configOf(record)) });
801
+ return record;
802
+ });
803
+ return this.view(rec);
804
+ }
805
+ // ── Generations (DES-KNOWLEDGE-DATA-001 §5.5) ──────────────────────────────────────────────
806
+ /**
807
+ * Read, normalize, VALIDATE and RECONCILE a kept generation, with no side effect on the registry (§5.5): the one
808
+ * snapshot a restore plans its approval withdrawals against and then commits as it is, so a restore refused for
809
+ * any reason withdraws nothing, and a generation pruned meanwhile cannot fail it half-way. 404
810
+ * `unknown_generation` when it is not kept; 409 `generation_unreadable` when it cannot be read, does not parse, or
811
+ * holds a record crew could not have written; 400 with the policy's code when a database source fails the
812
+ * deployment policy (a hand edit).
813
+ *
814
+ * The reconciliation fails closed: "query" and Allow writes come back OFF on every source (a person turns them on
815
+ * again); a missing secret disables its server at the commit ({@link restore}); grants stay bound to their
816
+ * descriptors and are judged where they are used. The secret check reads the value only to compare it with
817
+ * nothing, and drops it at once.
818
+ */
819
+ async planRestore(generation) {
820
+ let kept;
821
+ try {
822
+ kept = await this.deps.store.readGeneration(generation);
823
+ }
824
+ catch (err) {
825
+ const why = err instanceof Error ? err.message : String(err);
826
+ throw new McpRegistryError(409, 'generation_unreadable', `generation ${generation} cannot be read, so it cannot be restored: ${why}`);
827
+ }
828
+ if (kept === null)
829
+ throw new McpRegistryError(404, 'unknown_generation', `generation ${generation} is not kept (the registry keeps the last ${GENERATIONS_KEPT})`);
830
+ let servers;
831
+ try {
832
+ for (const raw of kept.servers) {
833
+ const problem = recordShapeProblem(raw);
834
+ if (problem !== null)
835
+ throw new Error(`${String(raw.name)}: ${problem}`);
836
+ }
837
+ servers = structuredClone(normalizeRegistryFile(kept).servers);
838
+ }
839
+ catch (err) {
840
+ const why = err instanceof Error ? err.message : String(err);
841
+ throw new McpRegistryError(409, 'generation_unreadable', `generation ${generation} is not a registry crew can read: ${why}`);
842
+ }
843
+ for (const s of servers) {
844
+ if (s.kind !== 'toolbox-source')
845
+ continue;
846
+ try {
847
+ checkSourceDocument(s.toolbox, { runtime: s.runtime ?? 'native' });
848
+ }
849
+ catch (err) {
850
+ throw policyRefusal(err);
851
+ }
852
+ }
853
+ const queryReset = [];
854
+ const writesReset = [];
855
+ for (const s of servers) {
856
+ if (!isGovernedRecord(s))
857
+ continue;
858
+ const a = agentAccessOf(s);
859
+ if (a.query)
860
+ queryReset.push(s.name);
861
+ if (s.agents !== undefined || a.query)
862
+ s.agents = { ...a, query: false };
863
+ if (s.allowWrites === true)
864
+ writesReset.push(s.name);
865
+ if (isPostgresRecord(s))
866
+ s.allowWrites = false;
867
+ }
868
+ return Object.freeze({ generation, servers: Object.freeze(servers), queryReset: Object.freeze(queryReset), writesReset: Object.freeze(writesReset) });
869
+ }
870
+ /**
871
+ * Commit a planned restore (§5.5). The route calls it under every affected server's lock, after its approval
872
+ * withdrawals, so the secrets are judged HERE, after any removal of those servers has finished (codex r3): a server
873
+ * whose secret reference does not RESOLVE to a value now comes back DISABLED, `secret_missing`. Nothing here can
874
+ * throw on a planned record, so after the withdrawals only a failing write refuses a restore (the registry is then
875
+ * unchanged and the approvals withdrawn: the safe direction).
876
+ *
877
+ * `expected` is the set of servers the route locked and judged. A server registered after that (it holds no lock of
878
+ * the restore's) is not overwritten: the restore is refused, 409 `registry_busy`, and nothing is written.
879
+ */
880
+ async restore(plan, expected) {
881
+ const servers = structuredClone(plan.servers);
882
+ const disabled = [];
883
+ const stamp = new Date(this.now()).toISOString();
884
+ for (const s of servers) {
885
+ if (s.auth === null || (await this.secretResolves(s.auth)))
886
+ continue;
887
+ if (s.enabled)
888
+ disabled.push({ name: s.name, code: 'secret_missing' });
889
+ s.enabled = false;
890
+ s.health = { ...s.health, checkedAt: stamp, lastError: `secret_missing: ${s.auth.ref} resolves to no secret; set it, then switch ${s.name} on` };
891
+ s.updatedAt = stamp;
892
+ }
893
+ const current = await this.mutate((file) => {
894
+ if (expected !== undefined) {
895
+ const late = file.servers.map((s) => s.name).filter((n) => !expected.includes(n));
896
+ if (late.length > 0)
897
+ throw new McpRegistryError(409, 'registry_busy', `${late.join(', ')} was registered while the restore ran; nothing was restored: try again`);
898
+ }
899
+ file.servers = servers;
900
+ return file.generation ?? 0;
901
+ });
902
+ for (const s of servers)
903
+ if (isSourceRecord(s))
904
+ this.sourceChanged(s.name);
905
+ // (DES-PM-001 §3.4) A restored generation brings its tracker links back: the projection reconciles to them.
906
+ this.onRestored?.();
907
+ return { restored: plan.generation, generation: current + 1, servers: servers.length, disabled, queryReset: [...plan.queryReset], writesReset: [...plan.writesReset] };
908
+ }
909
+ /** Whether a secret reference resolves to a non-empty value now; any error reading it counts as no (fail closed). */
910
+ async secretResolves(auth) {
911
+ try {
912
+ const value = await resolveSecret(auth.ref, this.deps.secrets, this.env);
913
+ return value !== null && value !== '';
914
+ }
915
+ catch {
916
+ return false;
917
+ }
918
+ }
919
+ /**
920
+ * A config as a save will store it (DES-KNOWLEDGE-DATA-001 §5.1): a network Postgres source, sent in K1's form
921
+ * or as a Toolbox document, becomes a Toolbox-form entry (descriptor version 2), checked against the deployment
922
+ * policy; a native-runtime entry carries its K1 projection, which is what the probe describes.
923
+ */
924
+ forSave(config) {
925
+ try {
926
+ if (config.kind === 'sql' && config.sql?.driver === 'postgres') {
927
+ const entry = toolboxEntryFromSql(config, 2);
928
+ return entry === null ? config : { ...config, entry };
929
+ }
930
+ if (config.kind !== 'toolbox-source')
931
+ return config;
932
+ const raw = config.entry ?? null;
933
+ if (raw === null)
934
+ throw new McpRegistryError(400, 'bad_toolbox', 'a toolbox-source carries its Toolbox source document');
935
+ const toolbox = checkSourceDocument(raw.toolbox, { runtime: raw.runtime });
936
+ const entry = { toolbox, runtime: raw.runtime, tls: { mode: raw.tls.mode, ca: raw.tls.ca ?? null }, descriptorVersion: 2, policyVersion: policyVersionOf(toolbox.type) };
937
+ if (raw.runtime === 'native') {
938
+ return { ...config, kind: 'sql', sql: sqlFromToolboxEntry(entry), viewsAllowed: config.viewsAllowed ?? [], address: config.address ?? { ...NO_CONFIRMATION, allow: [] }, entry };
939
+ }
940
+ if (this.deps.toolboxProbe === undefined) {
941
+ throw new McpRegistryError(501, 'runtime_unavailable', 'this daemon has no Toolbox runtime yet: save the source with runtime "native" (Postgres)');
942
+ }
943
+ return { ...config, entry };
944
+ }
945
+ catch (err) {
946
+ throw policyRefusal(err);
947
+ }
948
+ }
521
949
  // ── internals ──────────────────────────────────────────────────────────────────────────────
950
+ /** The registry as every reader sees it: ids present, K1 Postgres records mapped (DES-KNOWLEDGE-DATA-001 §5.4). */
951
+ async readFile() {
952
+ return normalizeRegistryFile(await this.deps.store.read());
953
+ }
954
+ /**
955
+ * One mutation of the normalized registry. The write persists the normalized form (ids, mapped entries). Every
956
+ * Toolbox document that is new or changed by the mutation is checked against its deployment policy before the
957
+ * write lands, so no path saves one the policy refuses.
958
+ */
959
+ mutate(fn) {
960
+ return this.deps.store.mutate(async (file) => {
961
+ normalizeRegistryFile(file);
962
+ // What the policy judges: the document AND the runtime it is judged for.
963
+ const judged = (s) => canonicalJson({ toolbox: s.toolbox ?? null, runtime: s.runtime ?? null, kind: s.kind });
964
+ const before = new Map(file.servers.map((s) => [s.name, judged(s)]));
965
+ const result = await fn(file);
966
+ for (const s of file.servers) {
967
+ if (s.kind !== 'toolbox-source')
968
+ continue;
969
+ if (before.get(s.name) === judged(s))
970
+ continue;
971
+ try {
972
+ checkSourceDocument(s.toolbox, { runtime: s.runtime ?? 'native' });
973
+ }
974
+ catch (err) {
975
+ throw policyRefusal(err);
976
+ }
977
+ }
978
+ return result;
979
+ });
980
+ }
522
981
  find(servers, name) {
523
982
  const s = servers.find((x) => x.name === name);
524
983
  if (s === undefined)
@@ -541,15 +1000,19 @@ export class McpRegistry {
541
1000
  * without connecting.
542
1001
  */
543
1002
  async probe(config, staged = null) {
1003
+ // (DES-KNOWLEDGE-DATA-001 §6.3) A Toolbox-runtime source is probed by the Toolbox runtime, never as a server.
1004
+ const prober = config.kind === 'toolbox-source' ? this.deps.toolboxProbe : this.deps.probe;
1005
+ if (prober === undefined)
1006
+ return { ok: false, error: 'this daemon has no Toolbox runtime' };
544
1007
  if (config.auth === null)
545
- return this.deps.probe(config, null);
1008
+ return prober(config, null);
546
1009
  // (crew#719) A staged secret is probed with instead of being written first. The caller has
547
1010
  // already checked it belongs to THIS server's keychain reference.
548
1011
  const secret = staged ?? (await resolveSecret(config.auth.ref, this.deps.secrets, this.env));
549
1012
  if (secret === null) {
550
1013
  return { ok: false, error: `auth.ref ${config.auth.ref} resolves to no secret: set it, then try again`, missingSecret: true };
551
1014
  }
552
- return this.deps.probe(config, secret);
1015
+ return prober(config, secret);
553
1016
  }
554
1017
  async authState(auth) {
555
1018
  if (auth === null)
@@ -558,11 +1021,22 @@ export class McpRegistry {
558
1021
  return 'missing';
559
1022
  return (await secretIsSet(auth.ref, this.deps.secrets, this.env)) ? 'set' : 'missing';
560
1023
  }
1024
+ /** A PM entry's links as the sheet shows them (read-only there; written only through the tracker-links routes). */
1025
+ trackerLinksOf(s) {
1026
+ const pm = pmOf(s);
1027
+ return pm === null ? [] : trackerLinkViews({ id: entryId(s), name: s.name, system: pm.system }, trackersOf(s), this.trackerProjection);
1028
+ }
561
1029
  async view(s) {
562
1030
  const tools = s.tools.map((t) => toolView(s, t));
563
1031
  const live = tools.filter((t) => t.status !== 'gone');
1032
+ const isSource = isSourceRecord(s);
1033
+ const pm = pmOf(s);
564
1034
  return {
1035
+ id: entryId(s),
565
1036
  ...configView(configOf(s)),
1037
+ ...(isPostgresRecord(s) ? { allowWrites: s.allowWrites === true } : {}),
1038
+ ...(isSource ? { descriptorHash: sourceDescriptorHash(configOf(s)), agents: agentAccessOf(s) } : {}),
1039
+ ...(pm !== null ? { agents: agentAccessOf(s), trackers: this.trackerLinksOf(s) } : {}),
566
1040
  authState: await this.authState(s.auth),
567
1041
  enabled: s.enabled,
568
1042
  health: s.health,
@@ -580,19 +1054,81 @@ export class McpRegistry {
580
1054
  };
581
1055
  }
582
1056
  }
583
- function configOf(s) {
584
- const base = { name: s.name, kind: s.kind, command: s.command, args: s.args, url: s.url, auth: s.auth };
585
- if (s.kind !== 'rest')
1057
+ /**
1058
+ * A record as every consumer reads it: the READ-PATH PROJECTION (DES-KNOWLEDGE-DATA-001 §5.4). A native-runtime
1059
+ * `toolbox-source` entry answers K1's `kind: 'sql'` config, with `config.sql` synthesised from its Toolbox document,
1060
+ * so no consumer sees the new form until it moves onto the gate (M3b); `config.entry` carries the stored form. A
1061
+ * `runtime: 'toolbox'` entry keeps `kind: 'toolbox-source'` and has no `sql`: Apps cannot read it in v1 (§6.3).
1062
+ */
1063
+ export function configOf(s) {
1064
+ const pm = pmOf(s);
1065
+ const base = { name: s.name, kind: s.kind, command: s.command, args: s.args, url: s.url, auth: s.auth, ...(s.id !== undefined ? { id: s.id } : {}), ...(pm !== null ? { pm } : {}) };
1066
+ if (s.kind === 'toolbox-source') {
1067
+ const entry = entryOf(s);
1068
+ const address = s.address ?? { ...NO_CONFIRMATION, allow: [] };
1069
+ if (entry === null)
1070
+ return { ...base, address };
1071
+ if (entry.runtime === 'native')
1072
+ return { ...base, kind: 'sql', sql: sqlFromToolboxEntry(entry), viewsAllowed: s.viewsAllowed ?? [], address, entry };
1073
+ return { ...base, address, viewsAllowed: s.viewsAllowed ?? [], entry };
1074
+ }
1075
+ if (s.kind === 'mcp-stdio')
586
1076
  return base;
587
- return { ...base, openapiUrl: s.openapiUrl ?? null, openapi: s.openapi ?? null, operations: s.operations ?? null };
1077
+ if (s.kind === 'sql') {
1078
+ const sqlite = s.sql?.driver === 'sqlite';
1079
+ return { ...base, sql: s.sql ?? null, viewsAllowed: s.viewsAllowed ?? [], ...(sqlite ? {} : { address: s.address ?? { ...NO_CONFIRMATION, allow: [] } }) };
1080
+ }
1081
+ if (s.kind === 'graphql')
1082
+ return { ...base, address: s.address ?? { ...NO_CONFIRMATION, allow: [] } };
1083
+ const address = s.address ?? legacyAddress(s);
1084
+ if (s.kind !== 'rest')
1085
+ return { ...base, address };
1086
+ return { ...base, openapiUrl: s.openapiUrl ?? null, openapi: s.openapi ?? null, operations: s.operations ?? null, address };
1087
+ }
1088
+ /**
1089
+ * (DES-APPS-001 §5.2) The confirmation of a record saved before the dialer, which has none. Only
1090
+ * what is safe to re-derive: the IP literal, or `localhost`, it was explicitly registered at — an
1091
+ * `mcp-http` server's url, or the origin a `rest` server's operator confirmed with G2's
1092
+ * `allowOrigin` (before the dialer, the only way a rest server reached a loopback or private host).
1093
+ * An IP literal is the exact address (no name to re-resolve); `localhost` is loopback by definition
1094
+ * (RFC 6761). A private NAME is not re-derived: its calls are refused, naming the range to confirm,
1095
+ * until the server is saved again with one.
1096
+ */
1097
+ export function legacyAddress(s) {
1098
+ const raw = s.kind === 'mcp-http' ? s.url : s.kind === 'rest' ? (s.allowedOrigin ?? null) : null;
1099
+ const allow = exactRangesFor(raw);
1100
+ if (allow.length === 0)
1101
+ return { ...NO_CONFIRMATION, allow: [] };
1102
+ // A private IP literal registered over http was registered as plaintext; loopback never needs it.
1103
+ const host = new URL(raw).hostname.replace(/^\[|\]$/g, '');
1104
+ const plaintext = new URL(raw).protocol === 'http:' && isIP(host) !== 0 && classifyAddress(host).cls === 'private';
1105
+ return { allow, plaintext };
588
1106
  }
589
1107
  /** What a response shows of a config. A pasted OpenAPI document is not echoed back. */
590
1108
  function configView(c) {
591
1109
  const view = { name: c.name, kind: c.kind, command: c.command, args: c.args, url: c.url, auth: c.auth };
1110
+ if (c.pm != null)
1111
+ view.pm = { system: c.pm.system };
592
1112
  if (c.kind === 'rest') {
593
1113
  view.openapiUrl = c.openapiUrl ?? null;
594
1114
  view.operations = c.operations ?? null;
595
1115
  }
1116
+ if (c.kind !== 'mcp-stdio' && !(c.kind === 'sql' && c.sql?.driver === 'sqlite'))
1117
+ view.address = c.address ?? { ...NO_CONFIRMATION, allow: [] };
1118
+ if (c.kind === 'sql' && c.sql != null) {
1119
+ view.sql = { driver: c.sql.driver, host: c.sql.host ?? null, port: c.sql.port ?? null, database: c.sql.database ?? null, user: c.sql.user ?? null, tls: c.sql.tls ?? 'verify-full', ca: c.sql.ca != null, snapshot: c.sql.snapshot ?? null };
1120
+ view.viewsAllowed = c.viewsAllowed ?? [];
1121
+ }
1122
+ // (DES-KNOWLEDGE-DATA-001 §5.1) The stored form of a database source: its Toolbox document (the password is a
1123
+ // placeholder, never a value), runtime and versions. A human operator's view only.
1124
+ if (c.entry != null) {
1125
+ view.runtime = c.entry.runtime;
1126
+ view.toolbox = c.entry.toolbox;
1127
+ view.descriptorVersion = c.entry.descriptorVersion;
1128
+ view.policyVersion = c.entry.policyVersion;
1129
+ if (c.kind === 'toolbox-source')
1130
+ view.viewsAllowed = c.viewsAllowed ?? [];
1131
+ }
596
1132
  return view;
597
1133
  }
598
1134
  /**
@@ -631,10 +1167,11 @@ function egressRefusal(egress, allowOrigin, prior) {
631
1167
  }
632
1168
  if (allowOrigin !== null || prior?.allowedOrigin === egress.origin)
633
1169
  return null;
1170
+ // (DES-APPS-001 §5.2) A loopback, private or unresolvable host is the dialer's to judge, at every
1171
+ // connection under the server's confirmed ranges; a preview could not have reached here with an
1172
+ // unconfirmed one. `allowOrigin` is only the operator accepting a base URL the spec does not list.
634
1173
  const why = [
635
1174
  ...(egress.matches ? [] : [egress.servers.length === 0 ? 'the OpenAPI document names no server crew can check it against' : `it matches none of the OpenAPI document's servers (${egress.servers.join(', ')})`]),
636
- ...(egress.privateAddress ? ['it is a loopback or private address'] : []),
637
- ...(egress.resolved ? [] : ['its host did not resolve, so crew could not check that it is not a private address']),
638
1175
  ];
639
1176
  if (why.length === 0)
640
1177
  return null;
@@ -663,6 +1200,7 @@ function statusOf(s, t) {
663
1200
  }
664
1201
  function toolView(s, t) {
665
1202
  const derivedClass = deriveToolClass(t.annotations);
1203
+ const pm = pmOf(s);
666
1204
  return {
667
1205
  name: t.name,
668
1206
  ...(t.rest != null ? { rest: t.rest } : {}),
@@ -677,6 +1215,8 @@ function toolView(s, t) {
677
1215
  status: statusOf(s, t),
678
1216
  schemaHash: t.schemaHash,
679
1217
  observedSchemaHash: t.observedSchemaHash,
1218
+ disclosure: effectiveDisclosure(t),
1219
+ ...(pm !== null ? { binding: t.binding == null ? null : { policy: t.binding.policy, schemaHash: t.binding.schemaHash, inForce: bindingInForce(pm.system, t) !== null } } : {}),
680
1220
  };
681
1221
  }
682
1222
  /** The difference between the registered tools and a probe's (by name, then schema hash). */
@@ -698,4 +1238,164 @@ export function diffTools(registered, probed) {
698
1238
  diff.removed.push(t.name);
699
1239
  return diff;
700
1240
  }
1241
+ // ── The one registry's entry (DES-KNOWLEDGE-DATA-001 §5) ─────────────────────────────────────────
1242
+ /** A data source of any form: K1 `sql`/`graphql`, or a Toolbox-form database source. */
1243
+ export function isSourceRecord(s) {
1244
+ return s.kind === 'sql' || s.kind === 'graphql' || s.kind === 'toolbox-source';
1245
+ }
1246
+ /** (DES-PM-001 §3) A record under the source safeguards: a data source, or a PM entry (Agents switches, restore resets). */
1247
+ export function isGovernedRecord(s) {
1248
+ return isSourceRecord(s) || pmOf(s) !== null;
1249
+ }
1250
+ /**
1251
+ * (DES-PM-001 §3) A PM entry's execution descriptor: the MCP descriptor Apps already uses (command, arguments, URL),
1252
+ * the secret reference's identity and where it is injected, the confirmed ranges and the PM system. A change turns
1253
+ * "query" off, as a source's descriptor change does. Never a secret value.
1254
+ */
1255
+ export function pmDescriptorHash(c) {
1256
+ return sha256Hex(canonicalJson({ v: 1, kind: c.kind, command: c.command, args: c.args, url: c.url, auth: c.auth, address: c.address ?? null, pm: c.pm?.system ?? null }));
1257
+ }
1258
+ /** A network Postgres source, in either form (the one kind with row writes in v1). */
1259
+ export function isPostgresRecord(s) {
1260
+ if (s.kind === 'toolbox-source')
1261
+ return s.toolbox?.type === 'postgres';
1262
+ return s.kind === 'sql' && s.sql?.driver === 'postgres';
1263
+ }
1264
+ /** A record's id; one read through {@link normalizeRegistryFile} always has it. */
1265
+ export function entryId(s) {
1266
+ return s.id ?? legacyEntryId(s.name, s.registeredAt);
1267
+ }
1268
+ /** The stored database-source part of a `toolbox-source` record; `null` when it is incomplete (a hand edit). */
1269
+ function entryOf(s) {
1270
+ if (s.toolbox === undefined || (s.runtime !== 'native' && s.runtime !== 'toolbox') || s.tls === undefined)
1271
+ return null;
1272
+ return { toolbox: s.toolbox, runtime: s.runtime, tls: { mode: s.tls.mode, ca: s.tls.ca ?? null }, descriptorVersion: s.descriptorVersion === 2 ? 2 : 1, policyVersion: s.policyVersion ?? policyVersionOf(s.toolbox.type) };
1273
+ }
1274
+ /**
1275
+ * The registry as every reader sees it, normalized IN PLACE (and answered):
1276
+ *
1277
+ * - every record has an `id` (a record from before ids gets {@link legacyEntryId}, the same on every read);
1278
+ * - a K1 network Postgres `sql` record is mapped to the Toolbox form as descriptor version 1, ONLY when the
1279
+ * projection of the mapped record hashes exactly as the K1 record did (so every lock, grant, Allow writes switch
1280
+ * and stored description bound to it stays valid) and its document passes the deployment policy. Anything
1281
+ * else (a host the policy refuses, a field the projection would not give back) stays in K1's form.
1282
+ *
1283
+ * Pure and idempotent: the first write after an upgrade persists the mapped form.
1284
+ */
1285
+ export function normalizeRegistryFile(file) {
1286
+ for (const [i, s] of file.servers.entries()) {
1287
+ if (s.id === undefined)
1288
+ s.id = legacyEntryId(s.name, s.registeredAt);
1289
+ if (s.kind !== 'sql' || s.sql?.driver !== 'postgres')
1290
+ continue;
1291
+ const legacy = configOf(s);
1292
+ let entry;
1293
+ try {
1294
+ entry = toolboxEntryFromSql(legacy, 1);
1295
+ }
1296
+ catch {
1297
+ continue; // the policy refuses the mapped document: the record stays as K1 saved it
1298
+ }
1299
+ if (entry === null)
1300
+ continue;
1301
+ const { sql: _sql, ...rest } = s;
1302
+ void _sql;
1303
+ const mapped = { ...rest, kind: 'toolbox-source', toolbox: entry.toolbox, runtime: 'native', tls: entry.tls, descriptorVersion: 1, policyVersion: entry.policyVersion };
1304
+ if (sourceDescriptorHash(configOf(mapped)) !== sourceDescriptorHash(legacy))
1305
+ continue;
1306
+ file.servers[i] = mapped;
1307
+ }
1308
+ return file;
1309
+ }
1310
+ /** A deployment-policy refusal as the routes answer it (400 with the policy's code). */
1311
+ function policyRefusal(err) {
1312
+ if (err instanceof DeploymentPolicyError)
1313
+ return new McpRegistryError(400, err.code, `the Toolbox source document is refused: ${err.message}`);
1314
+ return err;
1315
+ }
1316
+ /**
1317
+ * The disclosure class a save gives a tool (DES-KNOWLEDGE-DATA-001 §5.1): the operator's review when the body
1318
+ * gives one; else the class the tool kept while its schema is the one it was reviewed against; else crew's own
1319
+ * class for a tool of crew's Toolbox configuration; else none.
1320
+ */
1321
+ export function disclosureOnSave(t, was, reviewed, kind, pm = null) {
1322
+ if (reviewed !== undefined)
1323
+ return { class: reviewed, schemaHash: t.schemaHash };
1324
+ const prior = was?.disclosure ?? null;
1325
+ if (prior !== null && prior.schemaHash === t.schemaHash)
1326
+ return prior;
1327
+ // (DES-PM-001 §3.1) A PM entry's bound read tools are `rows` (issue content); its other tools get no class.
1328
+ const bound = pm === null ? null : bindingFor(pm, t.name);
1329
+ const proposed = bound !== null ? bound.disclosure : proposedDisclosure(kind, t.name);
1330
+ return proposed === null ? null : { class: proposed, schemaHash: t.schemaHash };
1331
+ }
1332
+ /**
1333
+ * The agent-safe projection of a server (DES-KNOWLEDGE-DATA-001 §5.2, crew#1310): what an agent-kind bearer and
1334
+ * the relay may know. Built from the full view, field by field (an allowlist), so a field added to the full view
1335
+ * never reaches an agent by default.
1336
+ */
1337
+ export function agentServerView(s) {
1338
+ return {
1339
+ id: s.id,
1340
+ name: s.name,
1341
+ kind: s.kind,
1342
+ enabled: s.enabled,
1343
+ health: { state: s.health.state },
1344
+ // (DES-PM-001 §3.1) A PM source's tools reach an agent only through the gate's scope-aware list: none here.
1345
+ tools: s.pm !== undefined ? [] : s.tools.filter((t) => t.status !== 'gone').map((t) => ({ name: t.name, subject: t.subject, class: t.class, disclosure: t.disclosure, enabled: t.enabled, status: t.status })),
1346
+ ...(s.agents !== undefined ? { agents: { see: s.agents.see, query: s.agents.query } } : {}),
1347
+ ...(s.pm !== undefined ? { pm: { system: s.pm.system } } : {}),
1348
+ };
1349
+ }
1350
+ const RECORD_KINDS = new Set(['mcp-stdio', 'mcp-http', 'rest', 'sql', 'graphql', 'toolbox-source']);
1351
+ /**
1352
+ * Why a stored record is not one crew could have written (`null`: it is): the fields every reader and a restore
1353
+ * use. A restore refuses a generation holding one (409) before anything changes (codex r2).
1354
+ */
1355
+ export function recordShapeProblem(raw) {
1356
+ if (typeof raw !== 'object' || raw === null || Array.isArray(raw))
1357
+ return 'not an object';
1358
+ const s = raw;
1359
+ const str = (v) => typeof v === 'string';
1360
+ const strOrNull = (v) => v === null || typeof v === 'string';
1361
+ if (!str(s['name']) || !MCP_SERVER_NAME_RE.test(s['name']))
1362
+ return 'no valid name';
1363
+ if (!str(s['kind']) || !RECORD_KINDS.has(s['kind']))
1364
+ return 'an unknown kind';
1365
+ if (!strOrNull(s['command']) || !Array.isArray(s['args']) || !strOrNull(s['url']))
1366
+ return 'no command, args or url';
1367
+ const auth = s['auth'];
1368
+ if (auth !== null && (typeof auth !== 'object' || !str(auth['ref'])))
1369
+ return 'auth is neither null nor a reference';
1370
+ if (typeof s['enabled'] !== 'boolean' || typeof s['health'] !== 'object' || s['health'] === null)
1371
+ return 'no enabled switch or health';
1372
+ if (!str(s['registeredAt']) || !str(s['updatedAt']))
1373
+ return 'no registeredAt or updatedAt';
1374
+ if (s['id'] !== undefined && !str(s['id']))
1375
+ return 'an id that is not a string';
1376
+ if (!Array.isArray(s['tools']))
1377
+ return 'no tools';
1378
+ for (const t of s['tools']) {
1379
+ if (typeof t !== 'object' || t === null)
1380
+ return 'a tool that is not an object';
1381
+ const r = t;
1382
+ if (!str(r['name']) || !strOrNull(r['schemaHash']) || !str(r['observedSchemaHash']) || typeof r['present'] !== 'boolean' || typeof r['enabled'] !== 'boolean')
1383
+ return `tool ${String(r['name'])} is malformed`;
1384
+ }
1385
+ if (s['kind'] === 'toolbox-source') {
1386
+ const tls = s['tls'];
1387
+ if (typeof s['toolbox'] !== 'object' || s['toolbox'] === null || (s['runtime'] !== 'native' && s['runtime'] !== 'toolbox') || typeof tls !== 'object' || tls === null || (tls['mode'] !== 'verify-full' && tls['mode'] !== 'disable'))
1388
+ return 'a database source without its document, runtime or TLS choice';
1389
+ }
1390
+ if (s['agents'] !== undefined && (typeof s['agents'] !== 'object' || s['agents'] === null))
1391
+ return 'agents is not an object';
1392
+ if (s['pm'] !== undefined && (typeof s['pm'] !== 'object' || s['pm'] === null || (s['kind'] !== 'mcp-http' && s['kind'] !== 'mcp-stdio')))
1393
+ return 'a pm marker on a server that is not an MCP server';
1394
+ // A marker this release cannot read would leave the entry ungoverned: refused as a record crew could not have written.
1395
+ if (s['pm'] !== undefined && !['github', 'jira'].includes(String(s['pm']['system'])))
1396
+ return 'a pm marker naming a system this release does not govern';
1397
+ if (s['trackers'] !== undefined && !Array.isArray(s['trackers']))
1398
+ return 'trackers is not a list';
1399
+ return null;
1400
+ }
701
1401
  //# sourceMappingURL=registry.js.map