wicked-crew 0.16.12 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (728) hide show
  1. package/README.md +3 -2
  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-history.d.ts +6 -0
  19. package/dist/api/chat-history.d.ts.map +1 -1
  20. package/dist/api/chat-history.js +21 -0
  21. package/dist/api/chat-history.js.map +1 -1
  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 +82 -155
  27. package/dist/api/chat-proposals.d.ts.map +1 -1
  28. package/dist/api/chat-proposals.js +254 -28
  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 +17 -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 +3 -22
  63. package/dist/api/product.d.ts.map +1 -1
  64. package/dist/api/product.js +4 -6
  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 +10 -37
  71. package/dist/api/recording.d.ts.map +1 -1
  72. package/dist/api/recording.js +9 -11
  73. package/dist/api/recording.js.map +1 -1
  74. package/dist/api/routes.d.ts +173 -1507
  75. package/dist/api/routes.d.ts.map +1 -1
  76. package/dist/api/routes.js +660 -139
  77. package/dist/api/routes.js.map +1 -1
  78. package/dist/api/run-timing-index.d.ts +18 -0
  79. package/dist/api/run-timing-index.d.ts.map +1 -1
  80. package/dist/api/run-timing-index.js +34 -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 +276 -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 +691 -0
  206. package/dist/apps/spec.d.ts.map +1 -0
  207. package/dist/apps/spec.js +839 -0
  208. package/dist/apps/spec.js.map +1 -0
  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 +9 -4
  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 +23 -0
  235. package/dist/core/adapter.d.ts.map +1 -1
  236. package/dist/core/adapter.js +49 -1
  237. package/dist/core/adapter.js.map +1 -1
  238. package/dist/core/deliver-text.d.ts +25 -0
  239. package/dist/core/deliver-text.d.ts.map +1 -1
  240. package/dist/core/deliver-text.js +50 -5
  241. package/dist/core/deliver-text.js.map +1 -1
  242. package/dist/core/deliver.d.ts.map +1 -1
  243. package/dist/core/deliver.js +6 -0
  244. package/dist/core/deliver.js.map +1 -1
  245. package/dist/core/estate-mcp-client.d.ts +9 -0
  246. package/dist/core/estate-mcp-client.d.ts.map +1 -1
  247. package/dist/core/estate-mcp-client.js +31 -3
  248. package/dist/core/estate-mcp-client.js.map +1 -1
  249. package/dist/core/linked-issues.d.ts +51 -3
  250. package/dist/core/linked-issues.d.ts.map +1 -1
  251. package/dist/core/linked-issues.js +59 -14
  252. package/dist/core/linked-issues.js.map +1 -1
  253. package/dist/core/run-boot-resume.d.ts +4 -1
  254. package/dist/core/run-boot-resume.d.ts.map +1 -1
  255. package/dist/core/run-boot-resume.js +6 -1
  256. package/dist/core/run-boot-resume.js.map +1 -1
  257. package/dist/decisions/chat-recorder.js +1 -1
  258. package/dist/decisions/chat-recorder.js.map +1 -1
  259. package/dist/decisions/routes.d.ts.map +1 -1
  260. package/dist/decisions/routes.js +5 -9
  261. package/dist/decisions/routes.js.map +1 -1
  262. package/dist/decisions/rules-brief.d.ts +76 -0
  263. package/dist/decisions/rules-brief.d.ts.map +1 -0
  264. package/dist/decisions/rules-brief.js +179 -0
  265. package/dist/decisions/rules-brief.js.map +1 -0
  266. package/dist/editors/csp.d.ts +24 -4
  267. package/dist/editors/csp.d.ts.map +1 -1
  268. package/dist/editors/csp.js +35 -8
  269. package/dist/editors/csp.js.map +1 -1
  270. package/dist/editors/registry.d.ts +97 -258
  271. package/dist/editors/registry.d.ts.map +1 -1
  272. package/dist/editors/registry.js +11 -11
  273. package/dist/editors/registry.js.map +1 -1
  274. package/dist/editors/routes.d.ts +4 -1
  275. package/dist/editors/routes.d.ts.map +1 -1
  276. package/dist/editors/routes.js +33 -6
  277. package/dist/editors/routes.js.map +1 -1
  278. package/dist/editors/webrtc-guard.d.ts +94 -0
  279. package/dist/editors/webrtc-guard.d.ts.map +1 -0
  280. package/dist/editors/webrtc-guard.js +506 -0
  281. package/dist/editors/webrtc-guard.js.map +1 -0
  282. package/dist/evals/routes.d.ts.map +1 -1
  283. package/dist/evals/routes.js +3 -5
  284. package/dist/evals/routes.js.map +1 -1
  285. package/dist/insights/routes.js +2 -2
  286. package/dist/insights/routes.js.map +1 -1
  287. package/dist/interactive/bridge-pool.d.ts +11 -2
  288. package/dist/interactive/bridge-pool.d.ts.map +1 -1
  289. package/dist/interactive/bridge-pool.js +10 -1
  290. package/dist/interactive/bridge-pool.js.map +1 -1
  291. package/dist/interactive/doc-binding.d.ts +156 -0
  292. package/dist/interactive/doc-binding.d.ts.map +1 -0
  293. package/dist/interactive/doc-binding.js +277 -0
  294. package/dist/interactive/doc-binding.js.map +1 -0
  295. package/dist/interactive/doc-delete-routes.d.ts +3 -0
  296. package/dist/interactive/doc-delete-routes.d.ts.map +1 -1
  297. package/dist/interactive/doc-delete-routes.js +4 -0
  298. package/dist/interactive/doc-delete-routes.js.map +1 -1
  299. package/dist/interactive/draft-events.d.ts +89 -3
  300. package/dist/interactive/draft-events.d.ts.map +1 -1
  301. package/dist/interactive/draft-events.js +438 -27
  302. package/dist/interactive/draft-events.js.map +1 -1
  303. package/dist/interactive/edit-events.d.ts +2 -0
  304. package/dist/interactive/edit-events.d.ts.map +1 -1
  305. package/dist/interactive/edit-events.js +11 -0
  306. package/dist/interactive/edit-events.js.map +1 -1
  307. package/dist/interactive/proposal-create.d.ts +143 -0
  308. package/dist/interactive/proposal-create.d.ts.map +1 -0
  309. package/dist/interactive/proposal-create.js +318 -0
  310. package/dist/interactive/proposal-create.js.map +1 -0
  311. package/dist/interactive/proxy-routes.d.ts +60 -3
  312. package/dist/interactive/proxy-routes.d.ts.map +1 -1
  313. package/dist/interactive/proxy-routes.js +285 -10
  314. package/dist/interactive/proxy-routes.js.map +1 -1
  315. package/dist/interactive/source-packet.d.ts +126 -0
  316. package/dist/interactive/source-packet.d.ts.map +1 -0
  317. package/dist/interactive/source-packet.js +482 -0
  318. package/dist/interactive/source-packet.js.map +1 -0
  319. package/dist/interactive/ws-relay.d.ts +3 -9
  320. package/dist/interactive/ws-relay.d.ts.map +1 -1
  321. package/dist/interactive/ws-relay.js +4 -6
  322. package/dist/interactive/ws-relay.js.map +1 -1
  323. package/dist/knowledge/adapters/native.d.ts +44 -0
  324. package/dist/knowledge/adapters/native.d.ts.map +1 -0
  325. package/dist/knowledge/adapters/native.js +60 -0
  326. package/dist/knowledge/adapters/native.js.map +1 -0
  327. package/dist/knowledge/adapters/toolbox/binary.d.ts +48 -0
  328. package/dist/knowledge/adapters/toolbox/binary.d.ts.map +1 -0
  329. package/dist/knowledge/adapters/toolbox/binary.js +145 -0
  330. package/dist/knowledge/adapters/toolbox/binary.js.map +1 -0
  331. package/dist/knowledge/adapters/toolbox/catalog.d.ts +22 -0
  332. package/dist/knowledge/adapters/toolbox/catalog.d.ts.map +1 -0
  333. package/dist/knowledge/adapters/toolbox/catalog.js +87 -0
  334. package/dist/knowledge/adapters/toolbox/catalog.js.map +1 -0
  335. package/dist/knowledge/adapters/toolbox/document.d.ts +71 -0
  336. package/dist/knowledge/adapters/toolbox/document.d.ts.map +1 -0
  337. package/dist/knowledge/adapters/toolbox/document.js +165 -0
  338. package/dist/knowledge/adapters/toolbox/document.js.map +1 -0
  339. package/dist/knowledge/adapters/toolbox/supervisor.d.ts +142 -0
  340. package/dist/knowledge/adapters/toolbox/supervisor.d.ts.map +1 -0
  341. package/dist/knowledge/adapters/toolbox/supervisor.js +438 -0
  342. package/dist/knowledge/adapters/toolbox/supervisor.js.map +1 -0
  343. package/dist/knowledge/gate/access.d.ts +36 -0
  344. package/dist/knowledge/gate/access.d.ts.map +1 -0
  345. package/dist/knowledge/gate/access.js +46 -0
  346. package/dist/knowledge/gate/access.js.map +1 -0
  347. package/dist/knowledge/gate/envelope.d.ts +67 -0
  348. package/dist/knowledge/gate/envelope.d.ts.map +1 -0
  349. package/dist/knowledge/gate/envelope.js +96 -0
  350. package/dist/knowledge/gate/envelope.js.map +1 -0
  351. package/dist/knowledge/gate/gate.d.ts +238 -0
  352. package/dist/knowledge/gate/gate.d.ts.map +1 -0
  353. package/dist/knowledge/gate/gate.js +782 -0
  354. package/dist/knowledge/gate/gate.js.map +1 -0
  355. package/dist/knowledge/gate/pg.d.ts +57 -0
  356. package/dist/knowledge/gate/pg.d.ts.map +1 -0
  357. package/dist/knowledge/gate/pg.js +94 -0
  358. package/dist/knowledge/gate/pg.js.map +1 -0
  359. package/dist/knowledge/gate/record.d.ts +77 -0
  360. package/dist/knowledge/gate/record.d.ts.map +1 -0
  361. package/dist/knowledge/gate/record.js +205 -0
  362. package/dist/knowledge/gate/record.js.map +1 -0
  363. package/dist/knowledge/gate/routes.d.ts +38 -0
  364. package/dist/knowledge/gate/routes.d.ts.map +1 -0
  365. package/dist/knowledge/gate/routes.js +102 -0
  366. package/dist/knowledge/gate/routes.js.map +1 -0
  367. package/dist/knowledge/gate/scheduler.d.ts +90 -0
  368. package/dist/knowledge/gate/scheduler.d.ts.map +1 -0
  369. package/dist/knowledge/gate/scheduler.js +224 -0
  370. package/dist/knowledge/gate/scheduler.js.map +1 -0
  371. package/dist/knowledge/gate/sources.d.ts +69 -0
  372. package/dist/knowledge/gate/sources.d.ts.map +1 -0
  373. package/dist/knowledge/gate/sources.js +135 -0
  374. package/dist/knowledge/gate/sources.js.map +1 -0
  375. package/dist/knowledge/package.d.ts +136 -0
  376. package/dist/knowledge/package.d.ts.map +1 -0
  377. package/dist/knowledge/package.js +148 -0
  378. package/dist/knowledge/package.js.map +1 -0
  379. package/dist/knowledge/projector.d.ts +144 -0
  380. package/dist/knowledge/projector.d.ts.map +1 -0
  381. package/dist/knowledge/projector.js +287 -0
  382. package/dist/knowledge/projector.js.map +1 -0
  383. package/dist/knowledge/registry/entry.d.ts +177 -0
  384. package/dist/knowledge/registry/entry.d.ts.map +1 -0
  385. package/dist/knowledge/registry/entry.js +126 -0
  386. package/dist/knowledge/registry/entry.js.map +1 -0
  387. package/dist/knowledge/registry/policy.d.ts +79 -0
  388. package/dist/knowledge/registry/policy.d.ts.map +1 -0
  389. package/dist/knowledge/registry/policy.js +139 -0
  390. package/dist/knowledge/registry/policy.js.map +1 -0
  391. package/dist/knowledge/shapes/code-search.d.ts +55 -0
  392. package/dist/knowledge/shapes/code-search.d.ts.map +1 -0
  393. package/dist/knowledge/shapes/code-search.js +88 -0
  394. package/dist/knowledge/shapes/code-search.js.map +1 -0
  395. package/dist/knowledge/shapes/map.d.ts +25 -0
  396. package/dist/knowledge/shapes/map.d.ts.map +1 -0
  397. package/dist/knowledge/shapes/map.js +187 -0
  398. package/dist/knowledge/shapes/map.js.map +1 -0
  399. package/dist/knowledge/shapes/profile.d.ts +117 -0
  400. package/dist/knowledge/shapes/profile.d.ts.map +1 -0
  401. package/dist/knowledge/shapes/profile.js +264 -0
  402. package/dist/knowledge/shapes/profile.js.map +1 -0
  403. package/dist/knowledge/shapes/routes.d.ts +69 -0
  404. package/dist/knowledge/shapes/routes.d.ts.map +1 -0
  405. package/dist/knowledge/shapes/routes.js +270 -0
  406. package/dist/knowledge/shapes/routes.js.map +1 -0
  407. package/dist/knowledge/shapes/shapes.d.ts +144 -0
  408. package/dist/knowledge/shapes/shapes.d.ts.map +1 -0
  409. package/dist/knowledge/shapes/shapes.js +280 -0
  410. package/dist/knowledge/shapes/shapes.js.map +1 -0
  411. package/dist/knowledge/shapes/verified.d.ts +36 -0
  412. package/dist/knowledge/shapes/verified.d.ts.map +1 -0
  413. package/dist/knowledge/shapes/verified.js +73 -0
  414. package/dist/knowledge/shapes/verified.js.map +1 -0
  415. package/dist/knowledge/summary.d.ts +45 -0
  416. package/dist/knowledge/summary.d.ts.map +1 -0
  417. package/dist/knowledge/summary.js +119 -0
  418. package/dist/knowledge/summary.js.map +1 -0
  419. package/dist/knowledge/trackers/actions.d.ts +55 -0
  420. package/dist/knowledge/trackers/actions.d.ts.map +1 -0
  421. package/dist/knowledge/trackers/actions.js +327 -0
  422. package/dist/knowledge/trackers/actions.js.map +1 -0
  423. package/dist/knowledge/trackers/addresses.d.ts +45 -0
  424. package/dist/knowledge/trackers/addresses.d.ts.map +1 -0
  425. package/dist/knowledge/trackers/addresses.js +59 -0
  426. package/dist/knowledge/trackers/addresses.js.map +1 -0
  427. package/dist/knowledge/trackers/bindings.d.ts +190 -0
  428. package/dist/knowledge/trackers/bindings.d.ts.map +1 -0
  429. package/dist/knowledge/trackers/bindings.js +970 -0
  430. package/dist/knowledge/trackers/bindings.js.map +1 -0
  431. package/dist/knowledge/trackers/gate-pm.d.ts +160 -0
  432. package/dist/knowledge/trackers/gate-pm.d.ts.map +1 -0
  433. package/dist/knowledge/trackers/gate-pm.js +427 -0
  434. package/dist/knowledge/trackers/gate-pm.js.map +1 -0
  435. package/dist/knowledge/trackers/issues.d.ts +69 -0
  436. package/dist/knowledge/trackers/issues.d.ts.map +1 -0
  437. package/dist/knowledge/trackers/issues.js +193 -0
  438. package/dist/knowledge/trackers/issues.js.map +1 -0
  439. package/dist/knowledge/trackers/map.d.ts +23 -0
  440. package/dist/knowledge/trackers/map.d.ts.map +1 -0
  441. package/dist/knowledge/trackers/map.js +130 -0
  442. package/dist/knowledge/trackers/map.js.map +1 -0
  443. package/dist/knowledge/trackers/projector.d.ts +113 -0
  444. package/dist/knowledge/trackers/projector.d.ts.map +1 -0
  445. package/dist/knowledge/trackers/projector.js +274 -0
  446. package/dist/knowledge/trackers/projector.js.map +1 -0
  447. package/dist/knowledge/trackers/routes.d.ts +107 -0
  448. package/dist/knowledge/trackers/routes.d.ts.map +1 -0
  449. package/dist/knowledge/trackers/routes.js +563 -0
  450. package/dist/knowledge/trackers/routes.js.map +1 -0
  451. package/dist/knowledge/trackers/set.d.ts +61 -0
  452. package/dist/knowledge/trackers/set.d.ts.map +1 -0
  453. package/dist/knowledge/trackers/set.js +77 -0
  454. package/dist/knowledge/trackers/set.js.map +1 -0
  455. package/dist/knowledge/trackers/view.d.ts +22 -0
  456. package/dist/knowledge/trackers/view.d.ts.map +1 -0
  457. package/dist/knowledge/trackers/view.js +31 -0
  458. package/dist/knowledge/trackers/view.js.map +1 -0
  459. package/dist/knowledge/trackers/visible.d.ts +9 -0
  460. package/dist/knowledge/trackers/visible.d.ts.map +1 -0
  461. package/dist/knowledge/trackers/visible.js +10 -0
  462. package/dist/knowledge/trackers/visible.js.map +1 -0
  463. package/dist/learn/routes.d.ts +3 -17
  464. package/dist/learn/routes.d.ts.map +1 -1
  465. package/dist/learn/routes.js +4 -6
  466. package/dist/learn/routes.js.map +1 -1
  467. package/dist/mcp/ask-server.d.ts +6 -0
  468. package/dist/mcp/ask-server.d.ts.map +1 -1
  469. package/dist/mcp/ask-server.js +15 -9
  470. package/dist/mcp/ask-server.js.map +1 -1
  471. package/dist/mcp/broker.d.ts +16 -0
  472. package/dist/mcp/broker.d.ts.map +1 -1
  473. package/dist/mcp/broker.js +137 -3
  474. package/dist/mcp/broker.js.map +1 -1
  475. package/dist/mcp/estate-relay.d.ts +50 -2
  476. package/dist/mcp/estate-relay.d.ts.map +1 -1
  477. package/dist/mcp/estate-relay.js +126 -4
  478. package/dist/mcp/estate-relay.js.map +1 -1
  479. package/dist/mcp/invoke.d.ts +12 -1
  480. package/dist/mcp/invoke.d.ts.map +1 -1
  481. package/dist/mcp/invoke.js +5 -2
  482. package/dist/mcp/invoke.js.map +1 -1
  483. package/dist/mcp/probe.d.ts +34 -2
  484. package/dist/mcp/probe.d.ts.map +1 -1
  485. package/dist/mcp/probe.js +51 -9
  486. package/dist/mcp/probe.js.map +1 -1
  487. package/dist/mcp/registry-store.d.ts +91 -0
  488. package/dist/mcp/registry-store.d.ts.map +1 -1
  489. package/dist/mcp/registry-store.js +116 -9
  490. package/dist/mcp/registry-store.js.map +1 -1
  491. package/dist/mcp/registry.d.ts +249 -6
  492. package/dist/mcp/registry.d.ts.map +1 -1
  493. package/dist/mcp/registry.js +735 -35
  494. package/dist/mcp/registry.js.map +1 -1
  495. package/dist/mcp/rest.d.ts +36 -10
  496. package/dist/mcp/rest.d.ts.map +1 -1
  497. package/dist/mcp/rest.js +71 -73
  498. package/dist/mcp/rest.js.map +1 -1
  499. package/dist/mcp/tool-list.d.ts +7 -0
  500. package/dist/mcp/tool-list.d.ts.map +1 -1
  501. package/dist/mcp/tool-list.js +32 -4
  502. package/dist/mcp/tool-list.js.map +1 -1
  503. package/dist/mcp-inspect/routes.d.ts +3 -0
  504. package/dist/mcp-inspect/routes.d.ts.map +1 -1
  505. package/dist/mcp-inspect/routes.js +31 -18
  506. package/dist/mcp-inspect/routes.js.map +1 -1
  507. package/dist/persona/routes.d.ts +14 -69
  508. package/dist/persona/routes.d.ts.map +1 -1
  509. package/dist/persona/routes.js +2 -2
  510. package/dist/persona/routes.js.map +1 -1
  511. package/dist/persona/store.d.ts +13 -40
  512. package/dist/persona/store.d.ts.map +1 -1
  513. package/dist/persona/store.js +9 -11
  514. package/dist/persona/store.js.map +1 -1
  515. package/dist/presets/routes.d.ts +3 -21
  516. package/dist/presets/routes.d.ts.map +1 -1
  517. package/dist/presets/routes.js +5 -7
  518. package/dist/presets/routes.js.map +1 -1
  519. package/dist/projects/repo-guard.d.ts +32 -0
  520. package/dist/projects/repo-guard.d.ts.map +1 -0
  521. package/dist/projects/repo-guard.js +46 -0
  522. package/dist/projects/repo-guard.js.map +1 -0
  523. package/dist/projects/routes.d.ts +16 -44
  524. package/dist/projects/routes.d.ts.map +1 -1
  525. package/dist/projects/routes.js +15 -18
  526. package/dist/projects/routes.js.map +1 -1
  527. package/dist/schedules/routes.d.ts +4 -18
  528. package/dist/schedules/routes.d.ts.map +1 -1
  529. package/dist/schedules/routes.js +4 -6
  530. package/dist/schedules/routes.js.map +1 -1
  531. package/dist/skills/plugin-source.d.ts +6 -5
  532. package/dist/skills/plugin-source.d.ts.map +1 -1
  533. package/dist/skills/plugin-source.js +6 -5
  534. package/dist/skills/plugin-source.js.map +1 -1
  535. package/dist/sources/ask.d.ts +108 -0
  536. package/dist/sources/ask.d.ts.map +1 -0
  537. package/dist/sources/ask.js +251 -0
  538. package/dist/sources/ask.js.map +1 -0
  539. package/dist/sources/catalog/mysql.d.ts +9 -0
  540. package/dist/sources/catalog/mysql.d.ts.map +1 -0
  541. package/dist/sources/catalog/mysql.js +77 -0
  542. package/dist/sources/catalog/mysql.js.map +1 -0
  543. package/dist/sources/catalog/postgres.d.ts +68 -0
  544. package/dist/sources/catalog/postgres.d.ts.map +1 -0
  545. package/dist/sources/catalog/postgres.js +164 -0
  546. package/dist/sources/catalog/postgres.js.map +1 -0
  547. package/dist/sources/catalog/types.d.ts +53 -0
  548. package/dist/sources/catalog/types.d.ts.map +1 -0
  549. package/dist/sources/catalog/types.js +30 -0
  550. package/dist/sources/catalog/types.js.map +1 -0
  551. package/dist/sources/connection-test.d.ts +37 -0
  552. package/dist/sources/connection-test.d.ts.map +1 -0
  553. package/dist/sources/connection-test.js +101 -0
  554. package/dist/sources/connection-test.js.map +1 -0
  555. package/dist/sources/crew-source.d.ts +31 -0
  556. package/dist/sources/crew-source.d.ts.map +1 -0
  557. package/dist/sources/crew-source.js +48 -0
  558. package/dist/sources/crew-source.js.map +1 -0
  559. package/dist/sources/dialer.d.ts +169 -0
  560. package/dist/sources/dialer.d.ts.map +1 -0
  561. package/dist/sources/dialer.js +761 -0
  562. package/dist/sources/dialer.js.map +1 -0
  563. package/dist/sources/drivers/mysql.d.ts +52 -0
  564. package/dist/sources/drivers/mysql.d.ts.map +1 -0
  565. package/dist/sources/drivers/mysql.js +348 -0
  566. package/dist/sources/drivers/mysql.js.map +1 -0
  567. package/dist/sources/drivers/postgres.d.ts +84 -0
  568. package/dist/sources/drivers/postgres.d.ts.map +1 -0
  569. package/dist/sources/drivers/postgres.js +381 -0
  570. package/dist/sources/drivers/postgres.js.map +1 -0
  571. package/dist/sources/drivers/sqlite.d.ts +47 -0
  572. package/dist/sources/drivers/sqlite.d.ts.map +1 -0
  573. package/dist/sources/drivers/sqlite.js +156 -0
  574. package/dist/sources/drivers/sqlite.js.map +1 -0
  575. package/dist/sources/drivers/types.d.ts +79 -0
  576. package/dist/sources/drivers/types.d.ts.map +1 -0
  577. package/dist/sources/drivers/types.js +31 -0
  578. package/dist/sources/drivers/types.js.map +1 -0
  579. package/dist/sources/graphql.d.ts +85 -0
  580. package/dist/sources/graphql.d.ts.map +1 -0
  581. package/dist/sources/graphql.js +155 -0
  582. package/dist/sources/graphql.js.map +1 -0
  583. package/dist/sources/kinds.d.ts +79 -0
  584. package/dist/sources/kinds.d.ts.map +1 -0
  585. package/dist/sources/kinds.js +145 -0
  586. package/dist/sources/kinds.js.map +1 -0
  587. package/dist/sources/policy/allowlists.d.ts +30 -0
  588. package/dist/sources/policy/allowlists.d.ts.map +1 -0
  589. package/dist/sources/policy/allowlists.js +104 -0
  590. package/dist/sources/policy/allowlists.js.map +1 -0
  591. package/dist/sources/policy/index.d.ts +20 -0
  592. package/dist/sources/policy/index.d.ts.map +1 -0
  593. package/dist/sources/policy/index.js +34 -0
  594. package/dist/sources/policy/index.js.map +1 -0
  595. package/dist/sources/policy/mysql.d.ts +21 -0
  596. package/dist/sources/policy/mysql.d.ts.map +1 -0
  597. package/dist/sources/policy/mysql.js +834 -0
  598. package/dist/sources/policy/mysql.js.map +1 -0
  599. package/dist/sources/policy/pg.d.ts +37 -0
  600. package/dist/sources/policy/pg.d.ts.map +1 -0
  601. package/dist/sources/policy/pg.js +572 -0
  602. package/dist/sources/policy/pg.js.map +1 -0
  603. package/dist/sources/policy/sqlite.d.ts +37 -0
  604. package/dist/sources/policy/sqlite.d.ts.map +1 -0
  605. package/dist/sources/policy/sqlite.js +94 -0
  606. package/dist/sources/policy/sqlite.js.map +1 -0
  607. package/dist/sources/policy/types.d.ts +46 -0
  608. package/dist/sources/policy/types.d.ts.map +1 -0
  609. package/dist/sources/policy/types.js +13 -0
  610. package/dist/sources/policy/types.js.map +1 -0
  611. package/dist/sources/routes.d.ts +154 -0
  612. package/dist/sources/routes.d.ts.map +1 -0
  613. package/dist/sources/routes.js +745 -0
  614. package/dist/sources/routes.js.map +1 -0
  615. package/dist/sources/safety/postgres.d.ts +87 -0
  616. package/dist/sources/safety/postgres.d.ts.map +1 -0
  617. package/dist/sources/safety/postgres.js +349 -0
  618. package/dist/sources/safety/postgres.js.map +1 -0
  619. package/dist/sources/sql.d.ts +51 -0
  620. package/dist/sources/sql.d.ts.map +1 -0
  621. package/dist/sources/sql.js +89 -0
  622. package/dist/sources/sql.js.map +1 -0
  623. package/dist/sources/store.d.ts +25 -0
  624. package/dist/sources/store.d.ts.map +1 -0
  625. package/dist/sources/store.js +59 -0
  626. package/dist/sources/store.js.map +1 -0
  627. package/dist/sources/uploads.d.ts +70 -0
  628. package/dist/sources/uploads.d.ts.map +1 -0
  629. package/dist/sources/uploads.js +636 -0
  630. package/dist/sources/uploads.js.map +1 -0
  631. package/dist/standing-orders/parse.d.ts +38 -0
  632. package/dist/standing-orders/parse.d.ts.map +1 -1
  633. package/dist/standing-orders/parse.js +104 -43
  634. package/dist/standing-orders/parse.js.map +1 -1
  635. package/dist/standing-orders/routes.d.ts +25 -126
  636. package/dist/standing-orders/routes.d.ts.map +1 -1
  637. package/dist/standing-orders/routes.js +4 -6
  638. package/dist/standing-orders/routes.js.map +1 -1
  639. package/dist/standing-orders/store.d.ts +22 -73
  640. package/dist/standing-orders/store.d.ts.map +1 -1
  641. package/dist/standing-orders/store.js +8 -12
  642. package/dist/standing-orders/store.js.map +1 -1
  643. package/dist/studio/assets/KnowledgeGraph-Cpm46tEp.js +1 -0
  644. package/dist/studio/assets/WickedSansA-Regular-CGPJLyb8.woff2 +0 -0
  645. package/dist/studio/assets/WickedSansA-SemiBold-Bk9KXUaV.woff2 +0 -0
  646. package/dist/studio/assets/favicon-BJA6hF2f.svg +1 -0
  647. package/dist/studio/assets/index-BRBwWQMH.css +32 -0
  648. package/dist/studio/assets/index-CVrWDGRP.js +1097 -0
  649. package/dist/studio/assets/wicked-studio-lettering-small-CBwSGqop.svg +2 -0
  650. package/dist/studio/assets/wicked-studio-wordmark-small-gF5xn6IC.svg +2 -0
  651. package/dist/studio/editors/wicked-apps/editor.json +45 -0
  652. package/dist/studio/editors/wicked-apps/icon.svg +1 -0
  653. package/dist/studio/editors/wicked-apps/index.html +151 -0
  654. package/dist/studio/editors/wicked-deck/editor.json +1 -1
  655. package/dist/studio/editors/wicked-deck/index.html +12 -8
  656. package/dist/studio/editors/wicked-doc/editor.json +1 -1
  657. package/dist/studio/editors/wicked-doc/index.html +12 -8
  658. package/dist/studio/editors/wicked-insights/editor.json +1 -1
  659. package/dist/studio/editors/wicked-insights/index.html +1 -1
  660. package/dist/studio/editors/wicked-page/editor.json +1 -1
  661. package/dist/studio/editors/wicked-page/index.html +12 -8
  662. package/dist/studio/editors/wicked-video/editor.json +1 -1
  663. package/dist/studio/editors/wicked-video/index.html +1 -1
  664. package/dist/studio/fonts/LICENSE-WickedSans.txt +97 -0
  665. package/dist/studio/index.html +3 -2
  666. package/dist/studio/testid-inventory.json +10850 -6700
  667. package/dist/team/routes.d.ts +21 -172
  668. package/dist/team/routes.d.ts.map +1 -1
  669. package/dist/team/routes.js +4 -8
  670. package/dist/team/routes.js.map +1 -1
  671. package/dist/voice/dashboard.d.ts +35 -313
  672. package/dist/voice/dashboard.d.ts.map +1 -1
  673. package/dist/voice/dashboard.js +10 -10
  674. package/dist/voice/dashboard.js.map +1 -1
  675. package/dist/voice/routes.d.ts +2 -6
  676. package/dist/voice/routes.d.ts.map +1 -1
  677. package/dist/voice/routes.js +2 -2
  678. package/dist/voice/routes.js.map +1 -1
  679. package/dist/watch/checks/check-failed.d.ts +4 -10
  680. package/dist/watch/checks/check-failed.d.ts.map +1 -1
  681. package/dist/watch/checks/check-failed.js +6 -8
  682. package/dist/watch/checks/check-failed.js.map +1 -1
  683. package/dist/watch/checks/claim-vs-evidence.js +3 -3
  684. package/dist/watch/checks/claim-vs-evidence.js.map +1 -1
  685. package/dist/watch/checks/deliver-audit.js +3 -3
  686. package/dist/watch/checks/deliver-audit.js.map +1 -1
  687. package/dist/watch/checks/discovery.d.ts.map +1 -1
  688. package/dist/watch/checks/discovery.js +5 -7
  689. package/dist/watch/checks/discovery.js.map +1 -1
  690. package/dist/watch/checks/lag.d.ts +4 -10
  691. package/dist/watch/checks/lag.d.ts.map +1 -1
  692. package/dist/watch/checks/lag.js +6 -8
  693. package/dist/watch/checks/lag.js.map +1 -1
  694. package/dist/watch/checks/quiet-after-claim.js +3 -3
  695. package/dist/watch/checks/quiet-after-claim.js.map +1 -1
  696. package/dist/watch/checks/scope-drift.js +3 -3
  697. package/dist/watch/checks/scope-drift.js.map +1 -1
  698. package/dist/watch/checks/team-path.js +2 -2
  699. package/dist/watch/checks/team-path.js.map +1 -1
  700. package/dist/watch/checks/ungated.js +3 -3
  701. package/dist/watch/checks/ungated.js.map +1 -1
  702. package/dist/watch/checks/warned-rule.js +3 -3
  703. package/dist/watch/checks/warned-rule.js.map +1 -1
  704. package/dist/watch/loader.d.ts.map +1 -1
  705. package/dist/watch/loader.js +12 -16
  706. package/dist/watch/loader.js.map +1 -1
  707. package/dist/workflow-catalog/build.d.ts +2 -0
  708. package/dist/workflow-catalog/build.d.ts.map +1 -1
  709. package/dist/workflow-catalog/build.js +8 -4
  710. package/dist/workflow-catalog/build.js.map +1 -1
  711. package/dist/workflow-catalog/catalog-data.d.ts +7 -1
  712. package/dist/workflow-catalog/catalog-data.d.ts.map +1 -1
  713. package/dist/workflow-catalog/catalog-data.js +36 -7
  714. package/dist/workflow-catalog/catalog-data.js.map +1 -1
  715. package/dist/working-doc/service.d.ts.map +1 -1
  716. package/dist/working-doc/service.js +2 -1
  717. package/dist/working-doc/service.js.map +1 -1
  718. package/dist/zod.d.ts +39 -0
  719. package/dist/zod.d.ts.map +1 -0
  720. package/dist/zod.js +197 -0
  721. package/dist/zod.js.map +1 -0
  722. package/endpoint-manifest.json +617 -7
  723. package/package.json +11 -5
  724. package/runners/sqlite-runner.mjs +110 -0
  725. package/dist/studio/assets/WickedSans-Regular-fb698rcD.woff2 +0 -0
  726. package/dist/studio/assets/WickedSans-SemiBold-CD53n1AC.woff2 +0 -0
  727. package/dist/studio/assets/index-BUZ_-Syk.css +0 -32
  728. package/dist/studio/assets/index-C_UIgTiy.js +0 -986
@@ -0,0 +1,576 @@
1
+ /**
2
+ * The shared write path (DES-APPS-001 §7.3, §7.4, §9.4): grant, prepare, run, records, for both kinds of
3
+ * action. The library crew's routes serve and the app server (K6) reuses.
4
+ *
5
+ * - GRANT (a person, once per action version): the version's tree is accepted, the action is in it and
6
+ * its lock entry is crew's; the source's descriptor and the action's contract recomputed NOW equal the
7
+ * lock's; a row write needs its source's Allow writes on and passes the table safety check now. The grant
8
+ * binds the action hash, the contract hash (with the fingerprint) and the descriptor. Audited
9
+ * `apps.action.granted` / `revoked`.
10
+ * - PREPARE and RUN each recheck: not `APPS_READ_ONLY`; the tree still holds its receipt; the grant still
11
+ * matches the action and contract hashes; the source's descriptor still matches; a database source still
12
+ * has Allow writes on. A stale grant is withdrawn (any change withdraws it). Prepare also re-runs the
13
+ * safety check (the card says "checked just now"), validates the parameters (a viewer-bound one from the
14
+ * viewer only), fills crew's `now` / `new uuid`, asks the database whether each value fits (P28), and
15
+ * makes the CARD from the resolved operation; the record expires in 2 minutes.
16
+ * - RUN moves the record from `prepared` to `running` under the store's lock, persisted BEFORE the call:
17
+ * the linearization point (a revoke or an Allow-writes-off before it wins). Then the call; the outcome
18
+ * is persisted, audited `apps.action.ran` (no values), and the app's read cache is invalidated.
19
+ */
20
+ import { createHash, randomUUID } from 'node:crypto';
21
+ import { canonicalJson } from '../../mcp/classify.js';
22
+ import { pgPrivileges } from '../../sources/catalog/postgres.js';
23
+ import { pgReadOnly } from '../../sources/drivers/postgres.js';
24
+ import { sqlConnectArgs } from '../../sources/kinds.js';
25
+ import { pgTableSafety } from '../../sources/safety/postgres.js';
26
+ import { actionHash } from '../check.js';
27
+ import { graphqlMutationContract, graphqlRootSignatures, rowWriteContract, splitTable, toolActionContract } from '../exec/contract.js';
28
+ import { graphqlVariablesProblem } from '../exec/executor.js';
29
+ import { AppLimits, RateLimited } from '../exec/limits.js';
30
+ import { bindParams, ParamError } from '../exec/params.js';
31
+ import { checkRowValues } from '../exec/source-stage.js';
32
+ import { lookupSource, pinOf } from '../exec/sources.js';
33
+ import { callMutation, callTool, describeMutation, describeToolRequest, idempotencyArg, mutationField } from './api-action.js';
34
+ import { baseTypeSql, pgExactFitIn } from './pg-fit.js';
35
+ import { generateStatement, runRowWrite } from './pg-write.js';
36
+ import { crewNow, inputForm, writableKind } from './values.js';
37
+ export const RECORD_TTL_MS = 2 * 60 * 1000;
38
+ /** crew itself, for withdrawals no person asked for (a changed source, Allow writes off). */
39
+ const CREW = { id: 'wicked-crew', kind: 'system', trust: 'admin' };
40
+ export class AppWriteError extends Error {
41
+ status;
42
+ code;
43
+ extra;
44
+ constructor(status, code, message, extra = {}) {
45
+ super(message);
46
+ this.status = status;
47
+ this.code = code;
48
+ this.extra = extra;
49
+ }
50
+ }
51
+ const sha = (v) => createHash('sha256').update(canonicalJson(v)).digest('hex');
52
+ const LABEL = { param: 'you entered it', app: 'fixed by the app', viewer: 'your sign-in', crew: 'filled by studio' };
53
+ /** A grant or record check that failed, with the words for the person. */
54
+ const refuse = (status, code, message) => new AppWriteError(status, code, message);
55
+ export class AppWritePath {
56
+ deps;
57
+ limits;
58
+ now;
59
+ constructor(deps) {
60
+ this.deps = deps;
61
+ this.now = deps.now ?? Date.now;
62
+ this.limits = new AppLimits(this.now);
63
+ // A run a stopped daemon left `running` gets its audit line now, as `unknown` (codex r1).
64
+ for (const r of deps.actions.recoveredAtBoot) {
65
+ this.audited('apps.action.ran', CREW, { app: r.app, action: r.action, record: r.id, viewer: r.viewer, descriptorHash: r.descriptorHash, paramsDigest: r.paramHash, outcome: 'unknown', reason: 'crew stopped during the run', recovered: true });
66
+ }
67
+ }
68
+ readOnly() {
69
+ const v = (this.deps.env ?? process.env)['APPS_READ_ONLY'];
70
+ return v !== undefined && v !== '' && v !== '0' && v.toLowerCase() !== 'false';
71
+ }
72
+ refuseReadOnly() {
73
+ if (this.readOnly())
74
+ throw refuse(409, 'read_only', 'APPS_READ_ONLY is set: no action runs on this daemon');
75
+ }
76
+ /** The action at an accepted version, with its lock entry (crew's). */
77
+ async actionAt(app, version, id) {
78
+ const at = await this.deps.store.acceptedFiles(app, version);
79
+ const action = at.files.spec.actions.find((a) => a.id === id);
80
+ if (action === undefined)
81
+ throw refuse(404, 'unknown_action', `this version of ${app} has no action ${id}`);
82
+ const locked = Object.hasOwn(at.files.lock.actions, id) ? at.files.lock.actions[id] : undefined;
83
+ const pinned = Object.hasOwn(at.files.lock.sources, action.source) ? at.files.lock.sources[action.source] : undefined;
84
+ if (locked === undefined || pinned === undefined || locked.actionHash !== actionHash(action))
85
+ throw refuse(409, 'contract_changed', `action ${id} was never checked in this version: check it again`);
86
+ return { at, action, locked, pinned };
87
+ }
88
+ /** Recompute the action's contract against the source now (never executes it). */
89
+ async resolve(action, snapshot) {
90
+ // ONE snapshot of the source for the check and the call (codex r1: two lookups could see two saves).
91
+ const source = snapshot !== undefined ? snapshot : await lookupSource(this.deps.registry, action.source);
92
+ if (source === null)
93
+ throw refuse(409, 'contract_changed', `${action.source} is gone`);
94
+ if (action.kind === 'row-write') {
95
+ if (source.kind !== 'sql' || source.config.sql?.driver !== 'postgres')
96
+ throw refuse(409, 'contract_changed', `${action.source} is not a Postgres source`);
97
+ const { schema, name } = splitTable(action.table);
98
+ const set = Object.keys(action.set ?? {});
99
+ const key = Object.keys(action.key);
100
+ const secret = await this.secret(source);
101
+ const r = await pgTableSafety(sqlConnectArgs(source.config, secret, this.deps.dial ?? {}), schema, name, { op: action.op, set, key }).catch((err) => {
102
+ throw refuse(502, 'source_unavailable', `the safety check on ${action.table} could not run (${err.errorClass ?? 'connection'})`);
103
+ });
104
+ if (!r.safe)
105
+ throw refuse(409, 'table_changed', `${action.table} does not pass the table safety check now: ${r.reasons.map((x) => x.detail).join('; ')}`);
106
+ return { source, contractHash: rowWriteContract({ schema, table: name, op: action.op, set, key, fingerprint: r.fingerprint }), safety: { fingerprint: r.fingerprint, columns: r.columns } };
107
+ }
108
+ if (action.call.kind === 'tool') {
109
+ if (source.kind !== 'rest' && source.kind !== 'mcp-http' && source.kind !== 'mcp-stdio')
110
+ throw refuse(409, 'contract_changed', `${action.source} is not a REST or MCP server now`);
111
+ const t = await this.deps.registry.appTool(source.name, action.call.tool);
112
+ if (t === null || !t.bound || pinOf(t.config).descriptorHash !== source.pin.descriptorHash)
113
+ throw refuse(409, 'contract_changed', `${action.source}/${action.call.tool} changed since this version was checked`);
114
+ return { source, contractHash: toolActionContract(source.kind, t.tool), tool: t.tool };
115
+ }
116
+ if (source.kind !== 'graphql' || source.description?.introspection === undefined)
117
+ throw refuse(409, 'contract_changed', `${action.source} is not a described GraphQL source now`);
118
+ const sigs = graphqlRootSignatures(action.call.mutation, source.description.introspection, 'mutation');
119
+ if (sigs === null)
120
+ throw refuse(409, 'contract_changed', `the mutation no longer fits ${action.source}'s schema`);
121
+ return { source, contractHash: graphqlMutationContract(sigs), field: mutationField(action.call.mutation).name, responseKey: mutationField(action.call.mutation).key };
122
+ }
123
+ async secret(s) {
124
+ if (s.kind === 'crew' || s.kind === 'estate')
125
+ return null;
126
+ const r = await this.deps.registry.callSecret(s.config);
127
+ if (r.missing)
128
+ throw refuse(409, 'source_failed', `${s.name}'s secret resolves to nothing; set it first`);
129
+ return r.secret;
130
+ }
131
+ audited(what, actor, detail) {
132
+ this.deps.audit.record(what, actor, { detail });
133
+ }
134
+ /** Withdraw a grant that no longer holds (any change withdraws it), audited, then refuse. */
135
+ async withdraw(app, action, why, code, message, observed) {
136
+ // Only the grant that was judged stale goes: one granted again meanwhile stays (codex r1).
137
+ const gone = await this.deps.actions.locked((tx) => {
138
+ const g = tx.grant(app, action);
139
+ if (g === null || (observed !== undefined && (g.grantedAt !== observed.grantedAt || g.contractHash !== observed.contractHash || g.actionHash !== observed.actionHash || g.descriptorHash !== observed.descriptorHash)))
140
+ return false;
141
+ return tx.dropGrant(app, action);
142
+ });
143
+ if (gone)
144
+ this.audited('apps.action.revoked', CREW, { app, action, reason: why });
145
+ throw refuse(409, code, message);
146
+ }
147
+ // ── grant / revoke ───────────────────────────────────────────────────────────────────────────
148
+ async grant(app, id, input) {
149
+ const { action, locked, pinned } = await this.actionAt(app, input.version, id);
150
+ const source = await lookupSource(this.deps.registry, action.source);
151
+ if (source !== null && source.kind === 'sql' && !source.allowWrites)
152
+ throw refuse(409, 'writes_off', `${action.source}'s Allow writes switch is off: turn it on before granting a row write`);
153
+ const r = await this.resolve(action);
154
+ // The writer login must hold what the write needs (§7.4 "The writer login"): say exactly which GRANTs are missing.
155
+ if (action.kind === 'row-write' && r.source.kind === 'sql') {
156
+ const { schema, name } = splitTable(action.table);
157
+ const report = await pgPrivileges(sqlConnectArgs(r.source.config, await this.secret(r.source), this.deps.dial ?? {}), [{ schema, table: name, op: action.op, set: Object.keys(action.set ?? {}), key: Object.keys(action.key) }]).catch(() => null);
158
+ // No report is no evidence: the grant waits for one (codex r1).
159
+ if (report === null || report.writes[0] === undefined)
160
+ throw refuse(502, 'source_unavailable', `the privilege report for ${action.table} could not be read; nothing was granted`);
161
+ const missing = report.writes[0].missing;
162
+ if (missing.length > 0)
163
+ throw refuse(409, 'missing_grants', `${r.source.config.sql?.user ?? 'the login'} cannot make this write yet; run: ${missing.join(' ')}`);
164
+ }
165
+ if (r.source.pin.descriptorHash !== pinned.descriptorHash)
166
+ throw refuse(409, 'contract_changed', `${action.source}'s connection changed since this version was checked: check it again`);
167
+ if (r.contractHash !== locked.contractHash)
168
+ throw refuse(409, action.kind === 'row-write' ? 'table_changed' : 'contract_changed', `what action ${id} uses at ${action.source} changed since this version was checked: check it again`);
169
+ const grant = {
170
+ app,
171
+ action: id,
172
+ kind: action.kind === 'row-write' ? 'row-write' : 'api',
173
+ source: action.source,
174
+ actionHash: locked.actionHash,
175
+ contractHash: locked.contractHash,
176
+ descriptorHash: pinned.descriptorHash,
177
+ ...(r.safety !== undefined ? { fingerprint: r.safety.fingerprint } : {}),
178
+ grantedBy: input.actor,
179
+ grantedAt: this.now(),
180
+ };
181
+ // Allow writes is read again under the lock, so a switch turned off meanwhile (its withdrawal waits for this lock) wins.
182
+ await this.deps.actions.locked(async (tx) => {
183
+ if (action.kind === 'row-write') {
184
+ const now = await lookupSource(this.deps.registry, action.source);
185
+ if (now === null || now.kind !== 'sql' || !now.allowWrites || now.pin.descriptorHash !== pinned.descriptorHash)
186
+ throw refuse(409, 'writes_off', `${action.source}'s Allow writes switch is off`);
187
+ }
188
+ tx.setGrant(grant);
189
+ });
190
+ this.audited('apps.action.granted', input.actor, { app, action: id, kind: grant.kind, source: grant.source, actionHash: grant.actionHash, contractHash: grant.contractHash, descriptorHash: grant.descriptorHash, ...(grant.fingerprint !== undefined ? { fingerprint: grant.fingerprint } : {}) });
191
+ return grant;
192
+ }
193
+ async revoke(app, id, actor) {
194
+ const gone = await this.deps.actions.locked((tx) => tx.dropGrant(app, id));
195
+ if (gone)
196
+ this.audited('apps.action.revoked', actor, { app, action: id });
197
+ return gone;
198
+ }
199
+ getGrant(app, id) {
200
+ return this.deps.actions.grant(app, id);
201
+ }
202
+ /** K1's Allow writes switch: off withdraws every row-write grant on the source (under the store's lock). */
203
+ async withdrawForSource(source) {
204
+ const gone = await this.deps.actions.locked((tx) => tx.dropRowWriteGrants(source));
205
+ for (const g of gone)
206
+ this.audited('apps.action.revoked', CREW, { app: g.app, action: g.action, reason: 'allow_writes_off' });
207
+ return gone.length;
208
+ }
209
+ // ── prepare ──────────────────────────────────────────────────────────────────────────────────
210
+ /** Every recheck prepare and run share; answers the grant and what the action resolves to now. */
211
+ async recheck(app, action, tree, record) {
212
+ this.refuseReadOnly();
213
+ if (this.deps.store.acceptedReceipt(app, tree) === null)
214
+ throw refuse(409, 'not_accepted', `tree ${tree} no longer holds an accepted receipt for ${app}`);
215
+ const grant = this.deps.actions.grant(app, action.id);
216
+ const hash = actionHash(action);
217
+ if (grant === null)
218
+ throw refuse(409, 'not_granted', `action ${action.id} is not granted: a person grants it in the data panel first`);
219
+ // The grant is for another version of the action (an older tab, or a newer grant): refused, and that
220
+ // grant stays (codex r1).
221
+ if (grant.actionHash !== hash || (record !== undefined && (record.actionHash !== hash || record.actionHash !== grant.actionHash || record.contractHash !== grant.contractHash))) {
222
+ throw refuse(409, 'not_granted', `this version of action ${action.id} is not the one granted: grant it again to use it`);
223
+ }
224
+ const source = await lookupSource(this.deps.registry, action.source);
225
+ if (source === null || source.pin.descriptorHash !== grant.descriptorHash || (record !== undefined && record.descriptorHash !== source.pin.descriptorHash)) {
226
+ return this.withdraw(app, action.id, 'source_changed', 'contract_changed', `${action.source}'s connection changed since the grant: the grant is withdrawn`, grant);
227
+ }
228
+ // The system's knowledge (`estate`) is read by recall queries only: it takes no action.
229
+ if (source.kind === 'estate')
230
+ throw refuse(409, 'contract_changed', `${action.source} takes no action`);
231
+ if (source.kind !== 'crew' && !source.enabled)
232
+ throw refuse(409, 'contract_changed', `${action.source} is switched off`);
233
+ if (action.kind === 'row-write' && (source.kind !== 'sql' || !source.allowWrites))
234
+ throw refuse(409, 'writes_off', `${action.source}'s Allow writes switch is off`);
235
+ let resolved;
236
+ try {
237
+ resolved = await this.resolve(action, source);
238
+ }
239
+ catch (err) {
240
+ if (err instanceof AppWriteError && (err.code === 'table_changed' || err.code === 'contract_changed'))
241
+ return this.withdraw(app, action.id, err.code, err.code, `${err.message}: the grant is withdrawn`, grant);
242
+ throw err;
243
+ }
244
+ if (resolved.contractHash !== grant.contractHash) {
245
+ return this.withdraw(app, action.id, 'contract_changed', action.kind === 'row-write' ? 'table_changed' : 'contract_changed', `what action ${action.id} uses at ${action.source} changed since the grant (for a table: its safety fingerprint): the grant is withdrawn`, grant);
246
+ }
247
+ return { grant, resolved };
248
+ }
249
+ /**
250
+ * Every recheck a prepare runs, without preparing: the version is accepted, the action holds a grant
251
+ * for this version of it, its source's descriptor is the granted one, Allow writes is on for a row
252
+ * write, and its contract recomputed now (for a row write, the table safety check against the live
253
+ * catalog) equals the grant's. A grant that no longer holds is withdrawn, as at prepare. The app
254
+ * server runs it for every action at startup and after every re-describe.
255
+ */
256
+ async checkAction(app, id, version) {
257
+ const { at, action } = await this.actionAt(app, version, id);
258
+ await this.recheck(app, action, at.tree);
259
+ }
260
+ async prepareAction(app, id, input) {
261
+ this.refuseReadOnly();
262
+ this.rate(app, input.actor, 'prepare');
263
+ const { at, action } = await this.actionAt(app, input.version, id);
264
+ const { grant, resolved } = await this.recheck(app, action, at.tree);
265
+ const viewer = await this.deps.viewerOf(input.actor);
266
+ let bound;
267
+ try {
268
+ bound = bindParams(action.params, input.params, viewer);
269
+ }
270
+ catch (err) {
271
+ if (err instanceof ParamError)
272
+ throw refuse(err.code === 'bad_params' ? 400 : 409, err.code, err.message);
273
+ throw err;
274
+ }
275
+ const nowAt = new Date(this.now());
276
+ const value = (v) => {
277
+ if (v.kind === 'param') {
278
+ const decl = action.params?.properties[v.name];
279
+ if (decl?.from !== undefined)
280
+ return { value: bound.byName[v.name], from: 'viewer', label: LABEL.viewer };
281
+ return { value: bound.byName[v.name], from: 'param', label: LABEL.param };
282
+ }
283
+ if (v.kind === 'literal')
284
+ return { value: v.value, from: 'app', label: LABEL.app };
285
+ if (v.kind === 'viewer') {
286
+ const claim = v.claim === 'email' ? viewer.email : v.claim === 'name' ? viewer.name : viewer.id;
287
+ if (claim === null)
288
+ throw refuse(409, 'viewer_unavailable', `the action needs your ${v.claim}, and crew does not know it: set your git user.${v.claim}`);
289
+ return { value: claim, from: 'viewer', label: LABEL.viewer };
290
+ }
291
+ return { value: v.value === 'now' ? '' : randomUUID(), from: 'crew', label: `${LABEL.crew}: ${v.value === 'now' ? 'now' : 'new uuid'}` };
292
+ };
293
+ // The record's id is chosen first: an operation that sends it (an idempotency key) shows it on the card.
294
+ const recordId = randomUUID();
295
+ let card;
296
+ let operation;
297
+ if (action.kind === 'row-write')
298
+ ({ card, operation } = await this.prepareRow(app, action, resolved, value, nowAt));
299
+ else
300
+ ({ card, operation } = this.prepareApi(app, action, resolved, value, nowAt, bound.absent, recordId));
301
+ const t = this.now();
302
+ const rec = await this.deps.actions.locked((tx) => {
303
+ // The grant is read again under the lock: a revoke meanwhile wins.
304
+ const g = tx.grant(app, id);
305
+ if (g === null || g.contractHash !== grant.contractHash || g.actionHash !== grant.actionHash || g.descriptorHash !== grant.descriptorHash)
306
+ throw refuse(409, 'not_granted', `action ${id} was revoked or granted again while it was being prepared`);
307
+ return tx.addRecord({
308
+ id: recordId,
309
+ app,
310
+ tree: at.tree,
311
+ commit: at.commit,
312
+ version: at.version,
313
+ action: id,
314
+ actionHash: grant.actionHash,
315
+ contractHash: grant.contractHash,
316
+ descriptorHash: grant.descriptorHash,
317
+ source: action.source,
318
+ ...(grant.fingerprint !== undefined ? { fingerprint: grant.fingerprint } : {}),
319
+ paramHash: sha(operation),
320
+ viewer: input.actor.id,
321
+ state: 'prepared',
322
+ card,
323
+ operation,
324
+ createdAt: t,
325
+ expiresAt: t + RECORD_TTL_MS,
326
+ epoch: this.deps.actions.epoch,
327
+ });
328
+ });
329
+ return { record: rec.id, card: rec.card, expiresAt: rec.expiresAt };
330
+ }
331
+ async prepareRow(app, action, resolved, value, nowAt) {
332
+ const columns = resolved.safety.columns;
333
+ // The declaration against the columns as they are now (the source stage's rule, again).
334
+ try {
335
+ checkRowValues(action, columns);
336
+ }
337
+ catch (err) {
338
+ throw refuse(409, 'table_changed', err instanceof Error ? err.message : String(err));
339
+ }
340
+ const { schema, name } = splitTable(action.table);
341
+ const set = Object.keys(action.set ?? {});
342
+ const key = Object.keys(action.key);
343
+ const stmt = generateStatement({ schema, table: name, op: action.op, set, key, columns });
344
+ const texts = new Map();
345
+ const fit = [];
346
+ const resolveCol = (column, v) => {
347
+ const c = columns.find((x) => x.name === column);
348
+ const kind = writableKind(c);
349
+ const r = value(v);
350
+ const raw = v.kind === 'crew' && v.value === 'now' ? crewNow(kind, nowAt) : r.value;
351
+ const f = inputForm(kind, raw, { nullable: !c.notnull, ...(c.enumLabels !== undefined ? { enumLabels: c.enumLabels } : {}) });
352
+ if (!f.ok)
353
+ throw refuse(400, 'bad_params', `the value for ${action.table}.${column} ${f.why}`);
354
+ if (f.text !== null)
355
+ fit.push({ column, full: c.type, base: baseTypeSql(c), text: f.text });
356
+ const shown = typeof raw === 'number' || typeof raw === 'boolean' || raw === null ? raw : String(f.text);
357
+ return { text: f.text, card: { name: column, value: shown, from: r.from, label: r.label } };
358
+ };
359
+ for (const c of set)
360
+ texts.set(`set:${c}`, resolveCol(c, action.set[c]));
361
+ for (const k of key)
362
+ if (!texts.has(`key:${k}`))
363
+ texts.set(`key:${k}`, resolveCol(k, action.key[k]));
364
+ const source = resolved.source;
365
+ const args = sqlConnectArgs(source.config, await this.secret(source), this.deps.dial ?? {});
366
+ const misfits = await pgReadOnly(args, (tx) => pgExactFitIn(tx, fit)).catch((err) => {
367
+ throw refuse(502, 'source_unavailable', `the values could not be checked at ${action.source} (${err.errorClass ?? 'connection'})`);
368
+ });
369
+ if (misfits.length > 0)
370
+ throw refuse(409, 'value_does_not_fit', misfits.map((m) => `${JSON.stringify(fit.find((f) => f.column === m.column)?.text ?? '')} ${m.why}`).join('; '));
371
+ const values = stmt.slots.map((s) => texts.get(`${s.role}:${s.column}`).text);
372
+ const keyValues = Object.fromEntries(key.map((k) => [k, texts.get(`key:${k}`).card.value]));
373
+ const verb = action.op === 'insert' ? 'INSERT' : action.op === 'update' ? 'UPDATE' : 'DELETE';
374
+ const card = {
375
+ kind: 'row-write',
376
+ app,
377
+ action: action.id,
378
+ source: action.source,
379
+ login: source.config.sql?.user ?? '',
380
+ verb,
381
+ table: action.table,
382
+ columns: set.map((c) => texts.get(`set:${c}`).card),
383
+ key: key.map((k) => texts.get(`key:${k}`).card),
384
+ rows: 'exactly 1 row, verified',
385
+ checks: 'plain table: no triggers, rules, inheritance or row security; checked just now',
386
+ statement: stmt.text,
387
+ ...(action.description !== undefined ? { appSays: action.description } : {}),
388
+ };
389
+ return { card, operation: { kind: 'row-write', schema, table: name, op: action.op, statement: stmt.text, values, set, key, keyValues } };
390
+ }
391
+ prepareApi(app, action, resolved, value, nowAt, absent, recordId) {
392
+ const cards = [];
393
+ const args = {};
394
+ for (const [k, v] of Object.entries(action.args)) {
395
+ // An absent optional parameter's argument is left out of the call (and off the card), never sent as null.
396
+ if (v.kind === 'param' && absent.has(v.name))
397
+ continue;
398
+ const r = value(v);
399
+ const sent = v.kind === 'crew' && v.value === 'now' ? nowAt.toISOString() : r.value;
400
+ args[k] = sent;
401
+ cards.push({ name: k, value: sent === undefined ? null : sent, from: r.from, label: r.label });
402
+ }
403
+ const source = resolved.source;
404
+ let shown;
405
+ let operation;
406
+ if (action.call.kind === 'tool') {
407
+ const tool = resolved.tool;
408
+ // An operation that maps an Idempotency-Key header gets the record id, on the card like any value (codex/pi r1).
409
+ const idem = idempotencyArg(tool.rest);
410
+ if (idem !== null && !Object.hasOwn(args, idem)) {
411
+ args[idem] = recordId;
412
+ cards.push({ name: idem, value: recordId, from: 'crew', label: `${LABEL.crew}: the record id` });
413
+ }
414
+ shown = describeToolRequest(source.config, tool.name, tool.rest, args);
415
+ operation = { kind: 'tool', tool: tool.name, args };
416
+ }
417
+ else {
418
+ // graphql-js's own coercion of the variables, before any card (Int range, enums, nulls).
419
+ const introspection = source.description?.introspection;
420
+ const problem = introspection === undefined ? 'the source is not described' : graphqlVariablesProblem(action.call.mutation, introspection, args);
421
+ if (problem !== null)
422
+ throw refuse(400, 'bad_params', problem);
423
+ shown = describeMutation(source.config, action.call.mutation, args, resolved.field ?? 'mutation');
424
+ operation = { kind: 'mutation', document: action.call.mutation, variables: args };
425
+ }
426
+ const card = {
427
+ kind: 'api',
428
+ app,
429
+ action: action.id,
430
+ source: action.source,
431
+ sourceKind: source.kind,
432
+ operation: shown.operation,
433
+ args: cards,
434
+ request: shown.request,
435
+ ...(action.description !== undefined ? { appSays: action.description } : {}),
436
+ };
437
+ return { card, operation };
438
+ }
439
+ rate(app, actor, bucket) {
440
+ try {
441
+ this.limits.rate(bucket, app, actor.id);
442
+ }
443
+ catch (err) {
444
+ if (err instanceof RateLimited)
445
+ throw new AppWriteError(429, 'rate_limited', err.message, { retryAfterMs: err.retryAfterMs });
446
+ throw err;
447
+ }
448
+ }
449
+ // ── run ──────────────────────────────────────────────────────────────────────────────────────
450
+ async runAction(app, id, input) {
451
+ this.refuseReadOnly();
452
+ this.rate(app, input.actor, 'action');
453
+ const snap = this.deps.actions.record(input.record);
454
+ if (snap === null || snap.app !== app || snap.action !== id || snap.viewer !== input.actor.id)
455
+ throw refuse(404, 'unknown_record', `no record ${input.record} of ${app}/${id} for you`);
456
+ if (snap.state !== 'prepared')
457
+ throw refuse(409, 'record_used', `record ${snap.id} is ${snap.state}: an action record runs once`);
458
+ if (this.now() >= snap.expiresAt)
459
+ throw refuse(409, 'record_expired', `record ${snap.id} expired: prepare the action again`);
460
+ const files = await this.deps.store.acceptedFiles(app, snap.commit).catch((err) => {
461
+ throw refuse(409, 'not_accepted', `the version record ${snap.id} was prepared on is no longer accepted (${err.code ?? 'unreadable'})`);
462
+ });
463
+ const action = files.files.spec.actions.find((a) => a.id === id);
464
+ if (action === undefined || files.tree !== snap.tree)
465
+ throw refuse(409, 'not_accepted', `the version this record was prepared on no longer holds action ${id}`);
466
+ const { resolved } = await this.recheck(app, action, snap.tree, snap);
467
+ const secret = await this.secret(resolved.source);
468
+ await this.deps.hooks?.beforeRunning?.();
469
+ // The linearization point: prepared → running, persisted, under the lock a revoke and Allow-writes-off take
470
+ // too. The awaited read of the source comes FIRST; every check after it is synchronous, right before the
471
+ // step (codex r1: expiry or APPS_READ_ONLY could otherwise change during the await).
472
+ const rec = await this.deps.actions.locked(async (tx) => {
473
+ const now = await lookupSource(this.deps.registry, action.source);
474
+ const r = tx.record(snap.id);
475
+ if (r === null || r.state !== 'prepared')
476
+ throw refuse(409, 'record_used', `record ${snap.id} already ran`);
477
+ if (this.now() >= r.expiresAt)
478
+ throw refuse(409, 'record_expired', `record ${snap.id} expired: prepare the action again`);
479
+ if (this.readOnly())
480
+ throw refuse(409, 'read_only', 'APPS_READ_ONLY is set: no action runs on this daemon');
481
+ const g = tx.grant(app, id);
482
+ if (g === null || g.actionHash !== r.actionHash || g.contractHash !== r.contractHash || g.descriptorHash !== r.descriptorHash)
483
+ throw refuse(409, 'not_granted', `action ${id} was revoked or granted again`);
484
+ // The source the call goes to is the one checked: its descriptor is the record's, for every kind (codex r1).
485
+ if (now === null || now.pin.descriptorHash !== r.descriptorHash || resolved.source.pin.descriptorHash !== r.descriptorHash)
486
+ throw refuse(409, 'contract_changed', `${action.source} changed while the action was starting`);
487
+ if (now.kind === 'estate')
488
+ throw refuse(409, 'contract_changed', `${action.source} takes no action`);
489
+ if (now.kind !== 'crew' && !now.enabled)
490
+ throw refuse(409, 'contract_changed', `${action.source} is switched off`);
491
+ if (action.kind === 'row-write' && (now.kind !== 'sql' || !now.allowWrites))
492
+ throw refuse(409, 'writes_off', `${action.source}'s Allow writes switch is off`);
493
+ return structuredClone(tx.update(r, { state: 'running', startedAt: this.now(), epoch: this.deps.actions.epoch }));
494
+ });
495
+ let outcome;
496
+ const started = this.now();
497
+ try {
498
+ outcome = await this.execute(rec, resolved, secret);
499
+ }
500
+ catch (err) {
501
+ // Only reached by a bug: the call may have gone out, so the outcome is not known.
502
+ outcome = { state: 'unknown', reason: `the run ended unexpectedly (${err instanceof Error ? err.name : 'error'}): whether it happened is not known` };
503
+ }
504
+ // The outcome is known now: it is answered, audited and the cache invalidated even if saving it fails
505
+ // (codex r1); the record then stays `running` on disk and the next start makes it `unknown`.
506
+ const patch = { state: outcome.state, ...(outcome.reason !== undefined ? { reason: outcome.reason } : {}), ...(outcome.result !== undefined ? { result: outcome.result } : {}), endedAt: this.now() };
507
+ let done = { ...rec, ...patch };
508
+ let saved = false;
509
+ for (let attempt = 0; attempt < 2 && !saved; attempt++) {
510
+ try {
511
+ done = await this.deps.actions.locked((tx) => structuredClone(tx.update(tx.record(rec.id), patch)));
512
+ saved = true;
513
+ }
514
+ catch {
515
+ // retried once
516
+ }
517
+ }
518
+ this.deps.executor?.invalidate(app);
519
+ const op = rec.operation;
520
+ this.audited('apps.action.ran', input.actor, {
521
+ app,
522
+ action: id,
523
+ record: rec.id,
524
+ viewer: rec.viewer,
525
+ descriptorHash: rec.descriptorHash,
526
+ operation: op.kind === 'row-write' ? `${op.op.toUpperCase()} ${op.schema}.${op.table}` : rec.card.kind === 'api' ? rec.card.operation.replace(/\s.*$/, '') + (op.kind === 'tool' ? ` ${op.tool}` : '') : op.kind,
527
+ paramsDigest: rec.paramHash,
528
+ ...(rec.fingerprint !== undefined ? { fingerprint: rec.fingerprint } : {}),
529
+ outcome: done.state,
530
+ ...(done.reason !== undefined ? { reason: done.reason } : {}),
531
+ ...(saved ? {} : { recordNotSaved: true }),
532
+ ms: this.now() - started,
533
+ });
534
+ return { record: done.id, state: done.state, ...(done.reason !== undefined ? { reason: done.reason } : {}), ...(done.result !== undefined ? { result: done.result } : {}) };
535
+ }
536
+ async execute(rec, resolved, secret) {
537
+ const op = rec.operation;
538
+ if (op.kind === 'row-write') {
539
+ const source = resolved.source;
540
+ const out = await runRowWrite(sqlConnectArgs(source.config, secret, this.deps.dial ?? {}), { ...op, fingerprint: rec.fingerprint ?? '' }, this.deps.hooks ?? {});
541
+ if (out.state === 'succeeded')
542
+ return { state: 'succeeded', result: { table: `${op.schema}.${op.table}`, op: op.op, key: op.keyValues } };
543
+ return { state: out.state, reason: out.reason };
544
+ }
545
+ const source = resolved.source;
546
+ let out;
547
+ if (op.kind === 'tool') {
548
+ out = await callTool(source.config, secret, op.tool, resolved.tool?.rest, op.args);
549
+ }
550
+ else {
551
+ out = await callMutation(source.config, secret, op.document, op.variables, resolved.responseKey ?? mutationField(op.document).key, this.deps.dial ?? {});
552
+ }
553
+ return out.state === 'succeeded' ? { state: 'succeeded', result: out.result } : { state: out.state, reason: out.reason };
554
+ }
555
+ /** `GET …/records/:id`: the person who prepared it. */
556
+ recordView(app, id, actor) {
557
+ const r = this.deps.actions.record(id);
558
+ if (r === null || r.app !== app || r.viewer !== actor.id)
559
+ throw refuse(404, 'unknown_record', `no record ${id} of ${app} for you`);
560
+ return {
561
+ id: r.id,
562
+ app: r.app,
563
+ action: r.action,
564
+ version: r.version,
565
+ tree: r.tree,
566
+ state: r.state,
567
+ ...(r.reason !== undefined ? { reason: r.reason } : {}),
568
+ ...(r.result !== undefined ? { result: r.result } : {}),
569
+ card: r.card,
570
+ createdAt: r.createdAt,
571
+ expiresAt: r.expiresAt,
572
+ ...(r.endedAt !== undefined ? { endedAt: r.endedAt } : {}),
573
+ };
574
+ }
575
+ }
576
+ //# sourceMappingURL=write-path.js.map