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
@@ -0,0 +1,905 @@
1
+ /**
2
+ * The app store (DES-APPS-001 §4, §6.4, §9.1): apps as git repos under the apps root, and crew's own
3
+ * record of each app — its versions, the RECEIPT per (app, tree), the undo pointer and the turn lock.
4
+ *
5
+ * Where things live, and why:
6
+ * - Each app is a repo at `<apps root>/<slug>` (`~/.wicked/apps` by default), registered in crew's repo
7
+ * registry so a turn's run can work in a worktree of it. That repo is mounted into agent seats, so
8
+ * nothing that decides what may run lives in it.
9
+ * - The record is ONE file in the daemon's state home, `daemon-apps.json`: the state home is fenced from
10
+ * every worker, and the registered `daemon-` FILE prefix is the place a crew store may add a file
11
+ * without a core release (a new directory there would refuse every launch).
12
+ *
13
+ * Every change to an app runs under that app's lock (one daemon per state home), and every change a
14
+ * person makes carries the version it was made on: a stale `base` is refused (compare-and-swap), so two
15
+ * tabs cannot both step back. A turn in flight holds the app read-only. The record is the authority on
16
+ * which commit is the app's head; the repo's `main` mirrors it and is re-pointed when it has moved (an
17
+ * agent seat could move it; nothing crew serves reads `main`).
18
+ */
19
+ import { randomBytes } from 'node:crypto';
20
+ import { existsSync, lstatSync, mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
21
+ import { rm } from 'node:fs/promises';
22
+ import { dirname, join } from 'node:path';
23
+ import { EMPTY_LOCK, LOCK_PATH, QUERIES_DIR, QUERY_EXT, SPEC_PATH, lockBytes, ownText, readAppTree, specBytes, stagedCheck } from './check.js';
24
+ import { AppGit, gitProblem, SHA_RE } from './git.js';
25
+ /** The state-home file name (the registered `daemon-` file prefix). */
26
+ export const APPS_STATE_FILENAME = 'daemon-apps.json';
27
+ /**
28
+ * App slugs: a path component, a URL segment, and the app repo's id in crew's repo registry. The registry
29
+ * keys a repo by the first four kebab words of its name (core `repo.rs` `slug`), so a slug is at most four
30
+ * words: then the registry id IS the slug, and two apps can never share one. `check` and `uploads` are
31
+ * routes, not apps.
32
+ */
33
+ export const APP_SLUG_RE = /^(?=.{1,48}$)[a-z][a-z0-9]*(?:-[a-z0-9]+){0,3}$/;
34
+ export const RESERVED_APP_SLUGS = new Set(['check', 'uploads']);
35
+ /** The receipts that make a tree part of an app's accepted history (DES §6.4). */
36
+ const ACCEPTED = new Set(['you', 'reviewed', 'restored']);
37
+ export class AppStoreError extends Error {
38
+ status;
39
+ code;
40
+ extra;
41
+ constructor(status, code, message, extra = {}) {
42
+ super(message);
43
+ this.status = status;
44
+ this.code = code;
45
+ this.extra = extra;
46
+ }
47
+ }
48
+ /** How many turns an app's record keeps, and how many its detail answers. */
49
+ export const TURN_LOG_MAX = 50;
50
+ export const TURN_LOG_SHOWN = 20;
51
+ /** The person-or-crew author of a version from the actor that made it. */
52
+ const humanAuthor = (actor) => ({ kind: 'human', id: actor.id });
53
+ export class AppStore {
54
+ stateFile;
55
+ appsRoot;
56
+ now;
57
+ log;
58
+ state;
59
+ locks = new Map();
60
+ /**
61
+ * Runs whose launch THIS process has in flight: the engine may not know them yet, so no poll may release
62
+ * their turn. In memory on purpose (codex/pi r3): after a restart nothing is launching, and the engine is
63
+ * asked about every turn.
64
+ */
65
+ launching = new Set();
66
+ /** Parsed trees, by (repo root, tree): trees are immutable. */
67
+ treeCache = new Map();
68
+ sourceStage;
69
+ turns;
70
+ registry;
71
+ constructor(opts) {
72
+ this.stateFile = opts.stateFile;
73
+ this.appsRoot = opts.appsRoot;
74
+ this.registry = opts.registry;
75
+ this.now = opts.now ?? Date.now;
76
+ this.log = opts.log ?? (() => undefined);
77
+ this.sourceStage = opts.sourceStage ?? null;
78
+ this.turns = opts.turns ?? null;
79
+ this.state = this.read();
80
+ }
81
+ read() {
82
+ if (!existsSync(this.stateFile))
83
+ return { version: 1, apps: {} };
84
+ const parsed = JSON.parse(readFileSync(this.stateFile, 'utf8'));
85
+ if (parsed.version !== 1 || typeof parsed.apps !== 'object' || parsed.apps === null) {
86
+ throw new Error(`${this.stateFile} is not an apps store this daemon can read`);
87
+ }
88
+ return parsed;
89
+ }
90
+ /** Atomic: a temp file beside it (same `daemon-` prefix), then a rename. */
91
+ persist() {
92
+ mkdirSync(dirname(this.stateFile), { recursive: true });
93
+ const tmp = `${this.stateFile}.tmp-${process.pid}-${randomBytes(4).toString('hex')}`;
94
+ writeFileSync(tmp, `${JSON.stringify(this.state, null, 1)}\n`, 'utf8');
95
+ renameSync(tmp, this.stateFile);
96
+ }
97
+ /**
98
+ * Apply `mutate` to `slug`'s record and persist it, or put the record back as it was: memory never holds
99
+ * a change the file does not (codex r1 on the store: a failed write left a version accepted in memory).
100
+ */
101
+ transact(slug, mutate) {
102
+ const before = Object.hasOwn(this.state.apps, slug) ? structuredClone(this.state.apps[slug]) : undefined;
103
+ mutate();
104
+ try {
105
+ this.persist();
106
+ }
107
+ catch (err) {
108
+ if (before === undefined)
109
+ delete this.state.apps[slug];
110
+ else
111
+ this.state.apps[slug] = before;
112
+ throw err;
113
+ }
114
+ }
115
+ /** Run `fn` holding `slug`'s lock: one change to an app at a time. */
116
+ /** Apps runs git only where git honours its lazy-fetch switch (git.ts); else every operation says why. */
117
+ async requireGit() {
118
+ const problem = await gitProblem();
119
+ if (problem !== null)
120
+ throw new AppStoreError(503, 'apps_unavailable', problem);
121
+ }
122
+ async withApp(slug, fn) {
123
+ await this.requireGit();
124
+ const prev = this.locks.get(slug) ?? Promise.resolve();
125
+ const run = prev.then(fn, fn);
126
+ const tail = run.catch(() => undefined);
127
+ this.locks.set(slug, tail);
128
+ try {
129
+ return await run;
130
+ }
131
+ finally {
132
+ if (this.locks.get(slug) === tail)
133
+ this.locks.delete(slug);
134
+ }
135
+ }
136
+ app(slug) {
137
+ const a = Object.hasOwn(this.state.apps, slug) ? this.state.apps[slug] : undefined;
138
+ if (a === undefined)
139
+ throw new AppStoreError(404, 'unknown_app', `no app ${JSON.stringify(slug)}`);
140
+ return a;
141
+ }
142
+ head(a) {
143
+ return a.versions[a.versions.length - 1];
144
+ }
145
+ git(a) {
146
+ return new AppGit(a.root);
147
+ }
148
+ // ── Reads ───────────────────────────────────────────────────────────────────────────────────────
149
+ has(slug) {
150
+ return Object.hasOwn(this.state.apps, slug);
151
+ }
152
+ /**
153
+ * (crew#1324) Each app's repository: its registry id (`''` until registered) and its root, where its files and its
154
+ * turns' worktrees live (an app made under an earlier `WICKED_CREW_APPS_ROOT` keeps its root). A repo made by
155
+ * `POST /repos {create: true}` under the apps root is no app's: it has no record here.
156
+ */
157
+ appRepos() {
158
+ return Object.values(this.state.apps).map((a) => ({ repoId: a.repoId, root: a.root }));
159
+ }
160
+ summary(a) {
161
+ const h = this.head(a);
162
+ const turn = a.turn === null ? null : { runId: a.turn.runId, startedAt: a.turn.startedAt, base: a.turn.base, actor: a.turn.actor };
163
+ return { slug: a.slug, name: a.name, projectId: a.projectId, repoId: a.repoId, createdAt: a.createdAt, head: { version: h.version, tree: h.tree, receipt: h.receipt?.kind ?? null }, turn };
164
+ }
165
+ /** The project an app belongs to, or `null` when there is no such app (a knowledge query reads only its project's). */
166
+ projectOf(slug) {
167
+ const a = Object.hasOwn(this.state.apps, slug) ? this.state.apps[slug] : undefined;
168
+ return a === undefined || typeof a.projectId !== 'string' || a.projectId === '' ? null : a.projectId;
169
+ }
170
+ list(projectId) {
171
+ return Object.values(this.state.apps)
172
+ .filter((a) => projectId === undefined || a.projectId === projectId)
173
+ .sort((x, y) => x.createdAt - y.createdAt || x.slug.localeCompare(y.slug))
174
+ .map((a) => this.summary(a));
175
+ }
176
+ historyOf(a) {
177
+ const { states, pointer } = a.history;
178
+ return { states: [...states], pointer, canUndo: pointer > 0, canRedo: pointer >= 0 && pointer < states.length - 1 };
179
+ }
180
+ /** A tree crew landed, read from the repo's objects (cached: trees are immutable). */
181
+ async files(a, tree) {
182
+ const key = `${a.root}\0${tree}`;
183
+ const hit = this.treeCache.get(key);
184
+ if (hit !== undefined)
185
+ return hit;
186
+ const read = await readAppTree(this.git(a), tree, { requireLock: true });
187
+ if (!read.ok)
188
+ throw new AppStoreError(409, 'unreadable_tree', `app ${a.slug} tree ${tree} cannot be read from its repo (it may have been changed): ${read.findings.map((f) => f.message).join('; ')}`);
189
+ const files = { ...read.files, lock: read.files.lock ?? EMPTY_LOCK };
190
+ if (this.treeCache.size > 256)
191
+ this.treeCache.clear();
192
+ this.treeCache.set(key, files);
193
+ return files;
194
+ }
195
+ async detail(slug) {
196
+ await this.requireGit();
197
+ const a = this.app(slug);
198
+ await this.refreshTurn(a, { locked: false });
199
+ // The record may have been replaced meanwhile (a settlement's rollback swaps in a clone): read it again.
200
+ const now = this.app(slug);
201
+ // One snapshot: the summary, versions, pointer AND turn log are taken together with the head whose files are
202
+ // read, so a landing during the read cannot pair a new base with an old spec (codex r1 on the store), nor a
203
+ // turn log that says landed with the head before it (xreview r1 on K5).
204
+ const snap = structuredClone({ summary: this.summary(now), versions: now.versions, history: this.historyOf(now), root: now.root, turns: (now.turnLog ?? []).slice(-TURN_LOG_SHOWN) });
205
+ const files = await this.files({ ...now, root: snap.root }, snap.summary.head.tree);
206
+ return { ...snap.summary, spec: files.spec, lock: files.lock, queryText: { ...files.queryText }, versions: snap.versions, history: snap.history, turns: snap.turns };
207
+ }
208
+ /** (K5) The app whose turn in flight is `runId`, or `null`. */
209
+ turnApp(runId) {
210
+ for (const a of Object.values(this.state.apps))
211
+ if (a.turn?.runId === runId)
212
+ return a.slug;
213
+ return null;
214
+ }
215
+ /** (K5) The turns of `slug`, oldest first (at most {@link TURN_LOG_SHOWN}). */
216
+ turnLog(slug) {
217
+ return structuredClone((this.app(slug).turnLog ?? []).slice(-TURN_LOG_SHOWN));
218
+ }
219
+ /** (K5) Write `patch` onto `runId`'s turn record (inside a transaction). */
220
+ patchTurnRecord(a, runId, patch) {
221
+ const r = (a.turnLog ?? []).find((x) => x.runId === runId);
222
+ if (r !== undefined)
223
+ Object.assign(r, patch);
224
+ }
225
+ /**
226
+ * After a version is committed to the record, point `main` at it. A failure here never undoes or fails
227
+ * the landing (the record is the truth): it is logged, and the next change or the boot repairs `main`.
228
+ */
229
+ async mirror(a, commit) {
230
+ try {
231
+ await this.git(a).setMain(commit);
232
+ }
233
+ catch (err) {
234
+ this.log(`[apps] ${a.slug}: main could not be pointed at ${commit} (repaired on the next change): ${err instanceof Error ? err.message : String(err)}`);
235
+ }
236
+ }
237
+ /** The first accepted receipt `tree` holds in this app, or `null`. */
238
+ acceptedReceipt(slug, tree) {
239
+ const a = this.app(slug);
240
+ return (Object.hasOwn(a.receipts, tree) ? a.receipts[tree] : []).find((r) => ACCEPTED.has(r.kind)) ?? null;
241
+ }
242
+ /**
243
+ * A version number of this app, or a commit of its repo → its commit and tree; `null` when the app has
244
+ * no such version and its repo no such commit.
245
+ */
246
+ async resolve(slug, version) {
247
+ const a = this.app(slug);
248
+ if (typeof version === 'number') {
249
+ const v = Number.isInteger(version) && version >= 1 ? a.versions[version - 1] : undefined;
250
+ return v === undefined ? null : { commit: v.commit, tree: v.tree, version: v.version };
251
+ }
252
+ const sha = version.toLowerCase();
253
+ if (!SHA_RE.test(sha))
254
+ return null;
255
+ const known = a.versions.find((v) => v.commit === sha);
256
+ if (known !== undefined)
257
+ return { commit: known.commit, tree: known.tree, version: known.version };
258
+ const tree = await this.git(a).treeOf(sha);
259
+ return tree === null ? null : { commit: sha, tree, version: null };
260
+ }
261
+ /** The spec at an accepted tree of this app (the query route's step 1-2). */
262
+ async acceptedSpec(slug, version) {
263
+ await this.requireGit();
264
+ const a = this.app(slug);
265
+ const r = await this.resolve(slug, version);
266
+ if (r === null)
267
+ throw new AppStoreError(404, 'unknown_version', `app ${slug} has no version ${JSON.stringify(version)}`);
268
+ const receipt = this.acceptedReceipt(slug, r.tree);
269
+ if (receipt === null)
270
+ throw new AppStoreError(409, 'not_accepted', `tree ${r.tree} holds no accepted receipt for app ${slug}: it never runs against a source`);
271
+ return { spec: (await this.files(a, r.tree)).spec, tree: r.tree, receipt };
272
+ }
273
+ /**
274
+ * (K2b) The files at an accepted tree of this app: the spec, the query texts and the lock crew wrote, read
275
+ * from the repo's verified objects. The executor's and the write path's step 1 (DES §7.2, §7.3).
276
+ */
277
+ async acceptedFiles(slug, version) {
278
+ await this.requireGit();
279
+ const a = this.app(slug);
280
+ const r = await this.resolve(slug, version);
281
+ if (r === null)
282
+ throw new AppStoreError(404, 'unknown_version', `app ${slug} has no version ${JSON.stringify(version)}`);
283
+ const receipt = this.acceptedReceipt(slug, r.tree);
284
+ if (receipt === null)
285
+ throw new AppStoreError(409, 'not_accepted', `tree ${r.tree} holds no accepted receipt for app ${slug}: it never runs against a source`);
286
+ return { files: await this.files(a, r.tree), tree: r.tree, commit: r.commit, version: r.version, receipt };
287
+ }
288
+ // ── The turn lock ───────────────────────────────────────────────────────────────────────────────
289
+ /**
290
+ * A turn whose run has ended no longer holds the app (a lost end event, a restart). The engine is asked
291
+ * outside any lock; the turn is cleared only under the app's lock (`locked`: the caller holds it), only if
292
+ * it is still the turn that was asked about, and never while its launch is in flight (codex r2).
293
+ */
294
+ async refreshTurn(a, opts) {
295
+ if (a.turn === null || this.launching.has(a.turn.runId) || this.turns === null)
296
+ return;
297
+ const runId = a.turn.runId;
298
+ let active = true;
299
+ try {
300
+ active = await this.turns.isActive(runId);
301
+ }
302
+ catch (err) {
303
+ this.log(`[apps] cannot tell whether turn ${runId} of ${a.slug} still runs (it keeps the app read-only): ${err instanceof Error ? err.message : String(err)}`);
304
+ }
305
+ if (active)
306
+ return;
307
+ const settle = async () => {
308
+ const current = Object.hasOwn(this.state.apps, a.slug) ? this.state.apps[a.slug] : undefined;
309
+ if (current === undefined || current.turn?.runId !== runId || this.launching.has(runId))
310
+ return;
311
+ await this.settleLocked(current, runId);
312
+ };
313
+ if (opts.locked)
314
+ await settle();
315
+ else
316
+ await this.withApp(a.slug, settle);
317
+ }
318
+ /**
319
+ * (K5) A turn whose run ended, settled under the app's lock: it lands as a `reviewed` version only when the
320
+ * launcher's reading of the engine's record says its review by a distinct seat passed on the tree the check
321
+ * offered; otherwise it ends with the reason, and nothing lands. Either way the app is editable again.
322
+ */
323
+ async settleLocked(a, runId) {
324
+ const t = a.turn;
325
+ if (t === null || t.runId !== runId)
326
+ return;
327
+ let outcome;
328
+ if (this.turns?.settlement === undefined) {
329
+ outcome = { kind: 'end', state: 'failed', code: 'unknown', reason: 'this daemon cannot read how the turn ended, so nothing landed' };
330
+ }
331
+ else {
332
+ try {
333
+ // The head's files are read only when a landed turn's change line needs them (xreview r4: a cold read failing
334
+ // must never end a turn whose run is still parked).
335
+ outcome = await this.turns.settlement({ slug: a.slug, runId, checkedTree: t.checkedTree ?? null, base: () => this.files(a, this.head(a).tree), landedSpec: (tree) => this.files(a, tree) });
336
+ }
337
+ catch (err) {
338
+ // The launcher throws only for a run the engine says has ENDED (a parked or running one answers `pending`):
339
+ // a defect then ends the turn (failed), so the app is never wedged read-only (xreview r3, r4).
340
+ outcome = { kind: 'end', state: 'failed', code: 'unknown', reason: `crew could not read how the turn ended (${err instanceof Error ? err.message : String(err)}), so nothing landed` };
341
+ }
342
+ }
343
+ if (outcome.kind === 'pending') {
344
+ // Not known yet: the turn stays in flight and settles on a later read; nothing is recorded that the engine's
345
+ // record does not say, and no other turn starts meanwhile (xreview r2, r3).
346
+ this.log(`[apps] turn ${runId} of ${a.slug} is not settled yet (it stays read-only): ${outcome.why}`);
347
+ return;
348
+ }
349
+ if (outcome.kind === 'land') {
350
+ try {
351
+ await this.landTurnLocked(a, { runId, commit: t.checked ?? '', builder: outcome.builder, reviewer: outcome.reviewer, summary: outcome.summary, change: outcome.change });
352
+ return;
353
+ }
354
+ catch (err) {
355
+ // Only crew's own refusal ends the turn: a failure to write the record (a full disk) leaves the turn in
356
+ // flight, to settle on the next read, rather than recording an outcome the file does not hold (xreview r1).
357
+ if (!(err instanceof AppStoreError))
358
+ throw err;
359
+ outcome = { kind: 'end', state: 'refused', code: err.code, reason: err.message };
360
+ }
361
+ }
362
+ this.log(`[apps] turn ${runId} of ${a.slug} ended (${outcome.state}: ${outcome.code}); nothing landed, and the app is editable again`);
363
+ const ended = outcome;
364
+ // The record as it is now (a rolled-back transaction replaces it with a clone).
365
+ const cur = this.app(a.slug);
366
+ if (cur.turn?.runId !== runId)
367
+ return;
368
+ this.transact(a.slug, () => {
369
+ cur.turn = null;
370
+ this.patchTurnRecord(cur, runId, { state: ended.state, endedAt: this.now(), code: ended.code, reason: ended.reason.slice(0, 2000) });
371
+ });
372
+ await this.git(a).dropRef(['wicked', 'apps-checked', runId]).catch(() => undefined);
373
+ }
374
+ /** (K5) Settle `runId`'s turn now (its run ended): the event path's entry. A turn still running is left alone. */
375
+ async settleTurn(slug, runId) {
376
+ if (!this.has(slug))
377
+ return;
378
+ await this.withApp(slug, async () => {
379
+ const a = this.app(slug);
380
+ if (a.turn?.runId !== runId || this.launching.has(runId))
381
+ return;
382
+ let active = true;
383
+ try {
384
+ active = this.turns === null ? false : await this.turns.isActive(runId);
385
+ }
386
+ catch {
387
+ active = true;
388
+ }
389
+ if (!active)
390
+ await this.settleLocked(a, runId);
391
+ });
392
+ }
393
+ turnInFlight(a, what) {
394
+ const t = a.turn;
395
+ return new AppStoreError(409, 'turn_in_flight', `a turn (run ${t.runId}) is changing ${a.slug}; ${what} waits until it ends. Preview still works.`, {
396
+ turn: { runId: t.runId, startedAt: t.startedAt, base: t.base, actor: t.actor },
397
+ });
398
+ }
399
+ /** The guard every change runs first: no turn in flight, the base is the head, `main` mirrors the head. */
400
+ async guard(a, base, what, opts = {}) {
401
+ // Landing a turn is that turn settling: asking the engine about it again would settle it twice.
402
+ if (opts.turnRun === undefined)
403
+ await this.refreshTurn(a, { locked: true });
404
+ if (a.turn !== null && a.turn.runId !== opts.turnRun)
405
+ throw this.turnInFlight(a, what);
406
+ const h = this.head(a);
407
+ if (base !== h.version) {
408
+ throw new AppStoreError(409, 'stale_base', `${what} was made on v${base}, but ${a.slug} is at v${h.version}; reload and try again`, { head: h.version });
409
+ }
410
+ const main = await this.git(a).main();
411
+ if (main !== h.commit) {
412
+ this.log(`[apps] ${a.slug}: main was at ${main ?? '(none)'}, not crew's head ${h.commit}; re-pointing it`);
413
+ await this.mirror(a, h.commit);
414
+ }
415
+ }
416
+ async beginTurn(slug, input) {
417
+ const turns = this.turns;
418
+ if (turns === null)
419
+ throw new AppStoreError(501, 'not_implemented', 'this daemon cannot launch apps-turn runs yet');
420
+ return this.withApp(slug, async () => {
421
+ const a = this.app(slug);
422
+ await this.guard(a, input.base, 'a new turn');
423
+ if (a.repoId === '')
424
+ throw new AppStoreError(409, 'not_registered', `${slug}'s repository is not registered yet, so no turn can work in it; try again in a moment`);
425
+ // The turn is recorded under the run id crew chose BEFORE the run starts, so a crash between the two
426
+ // leaves a turn crew can ask about, never a run with no lock (codex r1 on the store).
427
+ const runId = `apps-${slug}-${randomBytes(6).toString('hex')}`;
428
+ const turn = { runId, startedAt: this.now(), base: input.base, actor: input.actor.id, launchedBy: input.actor, checked: null, checkedTree: null, checkedSummary: null };
429
+ this.launching.add(runId);
430
+ const record = {
431
+ runId, at: turn.startedAt, actor: input.actor.id, message: input.message, about: [...input.about], base: input.base,
432
+ state: 'running', endedAt: null, version: null, change: null, summary: null, builder: null, reviewer: null, code: null, reason: null,
433
+ };
434
+ try {
435
+ this.transact(slug, () => {
436
+ a.turn = turn;
437
+ a.turnLog = [...(a.turnLog ?? []), record].slice(-TURN_LOG_MAX);
438
+ });
439
+ const head = await this.files(a, this.head(a).tree);
440
+ const recent = structuredClone((a.turnLog ?? []).filter((r) => r.runId !== runId).slice(-5));
441
+ await turns.launch({ runId, app: slug, repoId: a.repoId, base: input.base, message: input.message, about: input.about, actor: input.actor, projectId: a.projectId, name: a.name, spec: head.spec, recent });
442
+ }
443
+ catch (err) {
444
+ if (a.turn?.runId === runId) {
445
+ // A launch the engine refused is a turn that never ran: its record says why, and nothing landed.
446
+ const reason = (err instanceof Error ? err.message : String(err)).slice(0, 2000);
447
+ this.transact(slug, () => {
448
+ a.turn = null;
449
+ this.patchTurnRecord(a, runId, { state: 'refused', endedAt: this.now(), code: err instanceof AppStoreError ? err.code : 'launch_refused', reason });
450
+ });
451
+ }
452
+ throw err;
453
+ }
454
+ finally {
455
+ this.launching.delete(runId);
456
+ }
457
+ return { runId, startedAt: turn.startedAt, base: turn.base, actor: turn.actor };
458
+ });
459
+ }
460
+ /** The turn's run ended (any outcome): the app is editable again. Idempotent; another run's end is ignored. */
461
+ async endTurn(slug, runId, outcome = { state: 'cancelled', code: 'ended', reason: 'the turn ended' }) {
462
+ await this.withApp(slug, async () => {
463
+ const a = this.app(slug);
464
+ if (a.turn?.runId !== runId)
465
+ return;
466
+ this.transact(slug, () => {
467
+ a.turn = null;
468
+ this.patchTurnRecord(a, runId, { state: outcome.state, endedAt: this.now(), code: outcome.code, reason: outcome.reason.slice(0, 2000) });
469
+ });
470
+ await this.git(a).dropRef(['wicked', 'apps-checked', runId]);
471
+ });
472
+ }
473
+ /**
474
+ * `apps_check` for the turn in flight (DES §9.2 `check`): the candidate commit the builder made, read
475
+ * from the repo's objects, through the staged check against the head; on a pass crew writes the lock
476
+ * and commits it on the candidate. That commit is the tree the turn offers, and the only one a review
477
+ * can land.
478
+ */
479
+ async checkTurn(slug, runId, given) {
480
+ return this.withApp(slug, async () => {
481
+ const a = this.app(slug);
482
+ if (a.turn?.runId !== runId)
483
+ throw new AppStoreError(409, 'not_this_turn', `run ${runId} is not ${slug}'s turn in flight`);
484
+ const git = this.git(a);
485
+ let candidate;
486
+ let tree;
487
+ if (typeof given === 'string' || 'commit' in given) {
488
+ candidate = (typeof given === 'string' ? given : given.commit).toLowerCase();
489
+ tree = await git.treeOf(candidate);
490
+ if (tree === null)
491
+ throw new AppStoreError(404, 'unknown_version', `${slug}'s repo has no commit ${candidate}`);
492
+ }
493
+ else {
494
+ // (K5) The engine's snapshot of the builder's worktree, a TREE in the app repo's objects (`WICKED_TREE`):
495
+ // crew makes the candidate commit itself, on the head, reading only verified objects.
496
+ tree = given.tree.toLowerCase();
497
+ if (!SHA_RE.test(tree))
498
+ throw new AppStoreError(400, 'bad_request', 'tree must be a 40-hex object id');
499
+ try {
500
+ await git.readTree(tree);
501
+ }
502
+ catch {
503
+ throw new AppStoreError(404, 'unknown_version', `${slug}'s repo has no tree ${tree}`);
504
+ }
505
+ candidate = await git.commitTree(tree, this.head(a).commit, `apps-turn ${runId}: the builder's tree`, this.now());
506
+ }
507
+ const read = await readAppTree(git, tree);
508
+ if (!read.ok)
509
+ return { ok: false, code: 'check_failed', findings: read.findings };
510
+ const base = await this.files(a, this.head(a).tree);
511
+ const outcome = await stagedCheck({ app: slug, spec: read.files.spec, queryText: read.files.queryText, base, level: 'auto', sourceStage: this.sourceStage });
512
+ if (!outcome.ok)
513
+ return { ok: false, code: outcome.code, findings: outcome.findings };
514
+ const checkedTree = await this.writeTree(git, read.files.spec, read.files.queryText, outcome.lock);
515
+ const commit = await git.commitTree(checkedTree, candidate, `apps-check: lock for turn ${runId}`, this.now());
516
+ const t = a.turn;
517
+ // Anchored under a crew ref so a gc in the builder's seat cannot prune it before it lands (pi r3).
518
+ await git.writeRef(['wicked', 'apps-checked', runId], commit);
519
+ this.transact(slug, () => {
520
+ t.checked = commit;
521
+ t.checkedTree = checkedTree;
522
+ t.checkedSummary = outcome.summary;
523
+ });
524
+ return { ok: true, commit, tree: checkedTree, summary: outcome.summary, files: this.treeFiles(read.files.spec, read.files.queryText, outcome.lock) };
525
+ });
526
+ }
527
+ /**
528
+ * (K5) The files of a tree {@link writeTree} makes, as text: what `wicked-crew apps-check` writes into the
529
+ * turn's worktree so the review is dispatched on exactly the checked tree.
530
+ */
531
+ treeFiles(spec, queryText, lock) {
532
+ return [
533
+ { path: SPEC_PATH, text: specBytes(spec) },
534
+ { path: LOCK_PATH, text: lockBytes(lock) },
535
+ ...spec.queries.map((q) => ({ path: `${QUERIES_DIR}/${q.id}.${QUERY_EXT[q.kind]}`, text: ownText(queryText, q.id) ?? '' })),
536
+ ];
537
+ }
538
+ /**
539
+ * A turn whose review by a seat distinct from its builder named `commit` lands it (DES §9.1 `reviewed`).
540
+ * Refused unless `commit` is exactly the tree this turn's check offered, the seats differ, and the app is
541
+ * still at the turn's base.
542
+ */
543
+ async landTurn(slug, input) {
544
+ return this.withApp(slug, async () => this.landTurnLocked(this.app(slug), input));
545
+ }
546
+ async landTurnLocked(a, input) {
547
+ const slug = a.slug;
548
+ {
549
+ const t = a.turn;
550
+ if (t === null || t.runId !== input.runId)
551
+ throw new AppStoreError(409, 'not_this_turn', `run ${input.runId} is not ${slug}'s turn in flight`);
552
+ if (t.checked === null || t.checked !== input.commit.toLowerCase()) {
553
+ throw new AppStoreError(409, 'not_checked', `commit ${input.commit} is not the tree this turn's check offered`);
554
+ }
555
+ if (input.builder.trim() === '' || input.reviewer.trim() === '' || input.builder === input.reviewer) {
556
+ throw new AppStoreError(409, 'reviewer_not_distinct', 'a turn lands only after a review by a seat distinct from its builder');
557
+ }
558
+ await this.guard(a, t.base, 'the turn', { turnRun: t.runId });
559
+ const git = this.git(a);
560
+ const tree = t.checkedTree ?? null;
561
+ if (tree === null)
562
+ throw new AppStoreError(409, 'not_checked', 'this turn has no checked tree');
563
+ const at = this.now();
564
+ const version = a.versions.length + 1;
565
+ const receipt = { kind: 'reviewed', tree, version, at, actor: t.launchedBy, review: { runId: t.runId, builder: input.builder, reviewer: input.reviewer } };
566
+ // The version is a commit on the head whose tree is the checked one (the builder's intermediate
567
+ // commits stay on the run's branch).
568
+ const commit = await git.commitTree(tree, this.head(a).commit, `v${version}: ${(input.change ?? input.summary).replace(/\s+/g, ' ').trim()}`, at);
569
+ const check = t.checkedSummary ?? { level: 'data', checked: [] };
570
+ const name = (await this.files(a, tree)).spec.name;
571
+ let landed = null;
572
+ this.transact(slug, () => {
573
+ // The version strip's summary is one line (the turn record keeps the builder's lines as written).
574
+ landed = this.record(a, { commit, tree, at, author: { kind: 'seat', id: input.builder }, receipt, summary: (input.change ?? input.summary).replace(/\s+/g, ' ').trim() || 'A turn', check, base: t.base });
575
+ a.turn = null;
576
+ this.pushHistory(a, landed.version);
577
+ // The app is called what its spec calls it (a turn or an edit may rename it).
578
+ if (typeof name === 'string' && name.trim() !== '')
579
+ a.name = name;
580
+ this.patchTurnRecord(a, t.runId, {
581
+ state: 'landed', endedAt: at, version: landed.version, change: (input.change ?? '').slice(0, 300) || null,
582
+ summary: input.summary.slice(0, 600) || null, builder: input.builder, reviewer: input.reviewer, code: null, reason: null,
583
+ });
584
+ });
585
+ await this.mirror(a, commit);
586
+ await git.dropRef(['wicked', 'apps-checked', t.runId]);
587
+ return landed;
588
+ }
589
+ }
590
+ // ── Creating an app ─────────────────────────────────────────────────────────────────────────────
591
+ /** Whether anything (a file, a directory, a dangling link) holds `name` under the apps root. */
592
+ pathTaken(name) {
593
+ try {
594
+ lstatSync(join(this.appsRoot, name));
595
+ return true;
596
+ }
597
+ catch {
598
+ return false;
599
+ }
600
+ }
601
+ async free(slug) {
602
+ return APP_SLUG_RE.test(slug) && !RESERVED_APP_SLUGS.has(slug) && !this.has(slug) && !this.pathTaken(slug) && !(await this.registry.idTaken(slug));
603
+ }
604
+ /**
605
+ * A free slug like `slug`: `<slug>-2`, `-3`, … while it has fewer than four words, else its last word
606
+ * numbered (`a-b-c-d2`), always a valid slug that is neither an app, a path under the root, nor a
607
+ * registered repo id.
608
+ */
609
+ async suggest(slug) {
610
+ const words = slug.split('-');
611
+ /** `slug` with `suffix` added, shortened (longest word first, each kept to one letter at least) to fit 48. */
612
+ const candidate = (suffix) => {
613
+ const w = words.length < 4 ? [...words, suffix] : [...words.slice(0, 3), `${words[3]}${suffix}`];
614
+ const last = w.length - 1;
615
+ const keep = (i) => (i === last ? suffix.length + 1 : 1);
616
+ while (w.join('-').length > 48) {
617
+ let longest = -1;
618
+ for (let i = 0; i < w.length; i++)
619
+ if (w[i].length > keep(i) && (longest < 0 || w[i].length > w[longest].length))
620
+ longest = i;
621
+ if (longest < 0)
622
+ break;
623
+ w[longest] = longest === last ? `${w[longest].slice(0, w[longest].length - suffix.length - 1)}${suffix}` : w[longest].slice(0, -1);
624
+ }
625
+ return w.join('-');
626
+ };
627
+ for (let i = 2; i < 100; i++) {
628
+ const c = candidate(String(i));
629
+ if (await this.free(c))
630
+ return c;
631
+ }
632
+ for (let i = 0; i < 20; i++) {
633
+ const c = candidate(randomBytes(3).toString('hex'));
634
+ if (await this.free(c))
635
+ return c;
636
+ }
637
+ throw new AppStoreError(409, 'slug_taken', `${slug} is taken and no free name like it was found`);
638
+ }
639
+ /** The slug rules a new app or a new empty repo meets; throws the refusal. */
640
+ async assertNewSlug(slug) {
641
+ if (!APP_SLUG_RE.test(slug))
642
+ throw new AppStoreError(400, 'bad_request', 'an app slug is 1-48 of a-z 0-9 in at most four words joined by -, starting with a letter');
643
+ if (RESERVED_APP_SLUGS.has(slug))
644
+ throw new AppStoreError(422, 'reserved_slug', `${slug} is reserved`, { suggestion: await this.suggest(`${slug}-app`) });
645
+ if (!(await this.free(slug)))
646
+ throw new AppStoreError(409, 'slug_taken', `${slug} is taken`, { suggestion: await this.suggest(slug) });
647
+ }
648
+ /** A new empty repo at `<apps root>/<slug>` (the `POST /repos {create: true}` path). */
649
+ async createEmptyRepo(slug) {
650
+ const root = join(this.appsRoot, slug);
651
+ try {
652
+ const { commit } = await AppGit.createEmpty(root);
653
+ return { root, commit };
654
+ }
655
+ catch (err) {
656
+ if (err.code === 'EEXIST')
657
+ throw new AppStoreError(409, 'slug_taken', `${slug} is taken`, { suggestion: await this.suggest(slug) });
658
+ throw err;
659
+ }
660
+ }
661
+ /** `POST /repos {create: true}`: a new empty repo, registered (its id is the slug); no app record. */
662
+ async createRepo(slug) {
663
+ return this.withApp(slug, async () => {
664
+ await this.assertNewSlug(slug);
665
+ const { root } = await this.createEmptyRepo(slug);
666
+ try {
667
+ if (await this.registry.idTaken(slug))
668
+ throw new AppStoreError(409, 'slug_taken', `${slug} was registered by something else meanwhile`, { suggestion: await this.suggest(slug) });
669
+ return { root, repo: await this.registry.register(slug, root) };
670
+ }
671
+ catch (err) {
672
+ await rm(root, { recursive: true, force: true }).catch(() => undefined);
673
+ throw err;
674
+ }
675
+ });
676
+ }
677
+ /**
678
+ * A new app: the empty repo and crew's first version (one empty page) are made first, then the record
679
+ * is written, then the repo is registered: a failure at any step leaves nothing behind that blocks a
680
+ * retry, and a crash after the record leaves an app whose registration {@link reconcile} finishes. The
681
+ * first version holds a `you` receipt only when a human made it (an agent-kind caller may add an app,
682
+ * never accept a tree).
683
+ */
684
+ async create(input) {
685
+ const { slug } = input;
686
+ return this.withApp(slug, async () => {
687
+ await this.assertNewSlug(slug);
688
+ const { root, commit: empty } = await this.createEmptyRepo(slug);
689
+ const at = this.now();
690
+ const a = { slug, name: input.name, projectId: input.projectId, repoId: '', root, createdAt: at, baseCommit: empty, versions: [], receipts: {}, history: { states: [], pointer: -1 }, turn: null };
691
+ const human = input.actor.kind === 'human';
692
+ try {
693
+ const spec = { schema: 'wicked.apps/v1', name: input.name, pages: [{ id: 'page-1', title: 'Page 1', components: [] }], queries: [], actions: [], linkHosts: [] };
694
+ const git = this.git(a);
695
+ const tree = await this.writeTree(git, spec, {}, EMPTY_LOCK);
696
+ const commit = await git.commitTree(tree, empty, 'v1: a new app', at);
697
+ await git.setMain(commit);
698
+ const receipt = human ? { kind: 'you', tree, version: 1, at, actor: input.actor } : null;
699
+ this.transact(slug, () => {
700
+ this.state.apps[slug] = a;
701
+ this.record(a, { commit, tree, at, author: { kind: 'crew', id: 'wicked-crew' }, receipt, summary: 'A new app', check: { level: 'spec', checked: [] }, base: null });
702
+ if (human)
703
+ this.pushHistory(a, 1);
704
+ });
705
+ }
706
+ catch (err) {
707
+ await rm(root, { recursive: true, force: true }).catch(() => undefined);
708
+ throw err;
709
+ }
710
+ await this.registerApp(slug, { compensate: true });
711
+ return this.detail(slug);
712
+ });
713
+ }
714
+ /**
715
+ * Register an app whose record has no repo id yet. At creation (`compensate`) a refusal removes the app
716
+ * and its repo, so the slug can be tried again; at recovery it never does (the app may already hold
717
+ * accepted versions): the app stays, and the next boot tries again (codex r2). Just before registering,
718
+ * the id is checked again, narrowing the window in which another registration could take it.
719
+ */
720
+ async registerApp(slug, opts) {
721
+ const a = this.app(slug);
722
+ let repoId;
723
+ try {
724
+ const existing = await this.registry.idTaken(slug);
725
+ if (existing && opts.compensate)
726
+ throw new AppStoreError(409, 'slug_taken', `${slug} was registered by something else meanwhile`, { suggestion: await this.suggest(slug) });
727
+ repoId = (await this.registry.register(slug, a.root)).id;
728
+ }
729
+ catch (err) {
730
+ if (opts.compensate) {
731
+ this.transact(slug, () => {
732
+ delete this.state.apps[slug];
733
+ });
734
+ await rm(a.root, { recursive: true, force: true }).catch(() => undefined);
735
+ }
736
+ throw err;
737
+ }
738
+ this.transact(slug, () => {
739
+ a.repoId = repoId;
740
+ });
741
+ }
742
+ /** At boot: finish any registration a crash interrupted, and point every app's `main` at its head. */
743
+ async reconcile() {
744
+ if ((await gitProblem()) !== null)
745
+ return;
746
+ for (const slug of Object.keys(this.state.apps)) {
747
+ await this.withApp(slug, async () => {
748
+ const a = this.app(slug);
749
+ if (a.repoId === '')
750
+ await this.registerApp(slug, { compensate: false });
751
+ const head = this.head(a).commit;
752
+ if ((await this.git(a).main()) !== head)
753
+ await this.mirror(a, head);
754
+ }).catch((err) => this.log(`[apps] ${slug} could not be reconciled: ${err instanceof Error ? err.message : String(err)}`));
755
+ }
756
+ }
757
+ // ── Changes a person makes (human-only routes) ──────────────────────────────────────────────────
758
+ async writeTree(git, spec, queryText, lock) {
759
+ const queryEntries = [];
760
+ for (const q of spec.queries) {
761
+ queryEntries.push({ mode: '100644', type: 'blob', sha: await git.writeBlob(ownText(queryText, q.id) ?? ''), name: `${q.id}.${QUERY_EXT[q.kind]}` });
762
+ }
763
+ const root = [
764
+ { mode: '100644', type: 'blob', sha: await git.writeBlob(specBytes(spec)), name: SPEC_PATH },
765
+ { mode: '100644', type: 'blob', sha: await git.writeBlob(lockBytes(lock)), name: LOCK_PATH },
766
+ ];
767
+ if (queryEntries.length > 0)
768
+ root.push({ mode: '040000', type: 'tree', sha: await git.mktree(queryEntries), name: QUERIES_DIR });
769
+ return git.mktree(root);
770
+ }
771
+ record(a, v) {
772
+ const version = { version: a.versions.length + 1, commit: v.commit, tree: v.tree, base: v.base, at: v.at, author: v.author, receipt: v.receipt, summary: v.summary.slice(0, 200), check: v.check };
773
+ a.versions.push(version);
774
+ if (v.receipt !== null)
775
+ (a.receipts[v.tree] ??= []).push(v.receipt);
776
+ return version;
777
+ }
778
+ /** A new accepted state: everything after the pointer is dropped (a new edit clears redo). */
779
+ pushHistory(a, version) {
780
+ a.history.states = [...a.history.states.slice(0, a.history.pointer + 1), version];
781
+ a.history.pointer = a.history.states.length - 1;
782
+ }
783
+ /** Check `candidate` against the head and land it as a new version with `receipt`. */
784
+ async land(a, candidate, opts) {
785
+ const h = this.head(a);
786
+ const base = await this.files(a, h.tree);
787
+ const outcome = await stagedCheck({ app: a.slug, spec: candidate.spec, queryText: candidate.queryText, base, level: opts.level, sourceStage: this.sourceStage });
788
+ if (!outcome.ok) {
789
+ const status = outcome.code === 'source_check_unavailable' ? 409 : 422;
790
+ throw new AppStoreError(status, outcome.code, outcome.findings.map((f) => f.message).slice(0, 5).join('; '), { findings: outcome.findings });
791
+ }
792
+ const git = this.git(a);
793
+ const tree = await this.writeTree(git, candidate.spec, candidate.queryText, outcome.lock);
794
+ const at = this.now();
795
+ const version = a.versions.length + 1;
796
+ const commit = await git.commitTree(tree, h.commit, `v${version}: ${opts.summary}`, at);
797
+ let landed = null;
798
+ this.transact(a.slug, () => {
799
+ landed = this.record(a, { commit, tree, at, author: humanAuthor(opts.actor), receipt: opts.receipt(version, tree, at), summary: opts.summary, check: outcome.summary, base: h.version });
800
+ opts.history(version);
801
+ if (candidate.spec.name.trim() !== '')
802
+ a.name = candidate.spec.name;
803
+ });
804
+ await this.mirror(a, commit);
805
+ return landed;
806
+ }
807
+ /** `POST /apps/:app/edits`: one `you` version from one edit burst. */
808
+ async edit(slug, input) {
809
+ return this.withApp(slug, async () => {
810
+ const a = this.app(slug);
811
+ await this.guard(a, input.base, 'this edit');
812
+ const head = await this.files(a, this.head(a).tree);
813
+ let spec = head.spec;
814
+ const queryText = { ...head.queryText };
815
+ for (const op of input.ops) {
816
+ if (op.op === 'spec')
817
+ spec = op.spec;
818
+ else
819
+ queryText[op.query] = op.text;
820
+ }
821
+ // The text of a query the spec no longer declares goes with it.
822
+ const declared = new Set(spec.queries.map((q) => q.id));
823
+ for (const id of Object.keys(queryText))
824
+ if (!declared.has(id))
825
+ delete queryText[id];
826
+ return this.land(a, { spec, queryText }, {
827
+ level: 'auto',
828
+ actor: input.actor,
829
+ summary: input.summary ?? 'Edited',
830
+ receipt: (version, tree, at) => ({ kind: 'you', tree, version, at, actor: input.actor }),
831
+ history: (version) => this.pushHistory(a, version),
832
+ });
833
+ });
834
+ }
835
+ /** The `restored` receipt for landing the tree of `from` (a version holding `held`), with its provenance. */
836
+ restoredReceipt(from, held, actor) {
837
+ const origin = held.kind === 'restored' && held.restoredFrom !== undefined
838
+ ? { originKind: held.restoredFrom.originKind, originVersion: held.restoredFrom.originVersion }
839
+ : { originKind: held.kind, originVersion: held.version };
840
+ return (version, tree, at) => ({ kind: 'restored', tree, version, at, actor, restoredFrom: { version: from, ...origin } });
841
+ }
842
+ /** `POST /apps/:app/undo` and `/redo`: move the pointer one accepted state, landing that state's tree after the full check. */
843
+ async move(slug, direction, input) {
844
+ return this.withApp(slug, async () => {
845
+ const a = this.app(slug);
846
+ await this.guard(a, input.base, direction === 'undo' ? 'this undo' : 'this redo');
847
+ const { states, pointer } = a.history;
848
+ const to = direction === 'undo' ? pointer - 1 : pointer + 1;
849
+ if (to < 0 || to >= states.length || pointer < 0) {
850
+ throw new AppStoreError(409, direction === 'undo' ? 'nothing_to_undo' : 'nothing_to_redo', direction === 'undo' ? 'there is no earlier accepted version to go back to' : 'there is nothing to redo');
851
+ }
852
+ const target = a.versions[states[to] - 1];
853
+ const held = target.receipt !== null && ACCEPTED.has(target.receipt.kind) ? target.receipt : this.acceptedReceipt(slug, target.tree);
854
+ if (held === null)
855
+ throw new AppStoreError(409, 'not_accepted', `v${target.version} holds no accepted receipt`);
856
+ const files = await this.files(a, target.tree);
857
+ return this.land(a, { spec: files.spec, queryText: files.queryText }, {
858
+ level: 'full',
859
+ actor: input.actor,
860
+ summary: `${direction === 'undo' ? 'Undo' : 'Redo'} to v${target.version}`,
861
+ receipt: this.restoredReceipt(target.version, held, input.actor),
862
+ history: () => {
863
+ a.history.pointer = to;
864
+ },
865
+ });
866
+ });
867
+ }
868
+ /** `POST /apps/:app/restore`: land an accepted version's tree as a new version (a new accepted state; redo is cleared). */
869
+ async restore(slug, input) {
870
+ return this.withApp(slug, async () => {
871
+ const a = this.app(slug);
872
+ await this.guard(a, input.base, 'this restore');
873
+ const r = await this.resolve(slug, input.version);
874
+ if (r === null)
875
+ throw new AppStoreError(404, 'unknown_version', `${slug} has no version ${JSON.stringify(input.version)}`);
876
+ // A known version's OWN accepted receipt carries its provenance; a tree-level one only for a commit
877
+ // that is no accepted version of this app (codex r2: two versions can share a tree).
878
+ const own = r.version !== null ? a.versions[r.version - 1].receipt : null;
879
+ const held = own !== null && ACCEPTED.has(own.kind) ? own : this.acceptedReceipt(slug, r.tree);
880
+ if (held === null) {
881
+ throw new AppStoreError(409, 'not_accepted', `${typeof input.version === 'number' ? `v${input.version}` : input.version} is not in ${slug}'s accepted history (no you, reviewed or restored receipt); it cannot be restored`);
882
+ }
883
+ const read = await readAppTree(this.git(a), r.tree);
884
+ if (!read.ok)
885
+ throw new AppStoreError(422, 'check_failed', read.findings.map((f) => f.message).join('; '), { findings: read.findings });
886
+ const from = r.version ?? held.version;
887
+ return this.land(a, { spec: read.files.spec, queryText: read.files.queryText }, {
888
+ level: 'full',
889
+ actor: input.actor,
890
+ summary: `Restored v${from}`,
891
+ receipt: this.restoredReceipt(from, held, input.actor),
892
+ history: (version) => this.pushHistory(a, version),
893
+ });
894
+ });
895
+ }
896
+ }
897
+ /** The apps root: `WICKED_CREW_APPS_ROOT`, else `~/.wicked/apps`. */
898
+ export function defaultAppsRoot(env = process.env) {
899
+ const explicit = env['WICKED_CREW_APPS_ROOT'];
900
+ if (explicit !== undefined && explicit.trim() !== '')
901
+ return explicit;
902
+ const home = env['HOME'] ?? env['USERPROFILE'] ?? '/tmp';
903
+ return join(home, '.wicked', 'apps');
904
+ }
905
+ //# sourceMappingURL=store.js.map