wicked-crew 0.17.1 → 0.18.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 (518) hide show
  1. package/README.md +49 -14
  2. package/adapters/web-source.lock +1314 -0
  3. package/dist/api/audit.d.ts +5 -0
  4. package/dist/api/audit.d.ts.map +1 -1
  5. package/dist/api/audit.js +20 -0
  6. package/dist/api/audit.js.map +1 -1
  7. package/dist/api/auth.d.ts.map +1 -1
  8. package/dist/api/auth.js +3 -0
  9. package/dist/api/auth.js.map +1 -1
  10. package/dist/api/chat-context.js +1 -1
  11. package/dist/api/chat-history.d.ts +3 -0
  12. package/dist/api/chat-history.d.ts.map +1 -1
  13. package/dist/api/chat-history.js +6 -1
  14. package/dist/api/chat-history.js.map +1 -1
  15. package/dist/api/chat-jobs.d.ts +30 -1
  16. package/dist/api/chat-jobs.d.ts.map +1 -1
  17. package/dist/api/chat-jobs.js +172 -10
  18. package/dist/api/chat-jobs.js.map +1 -1
  19. package/dist/api/chat-proposals.d.ts +178 -8
  20. package/dist/api/chat-proposals.d.ts.map +1 -1
  21. package/dist/api/chat-proposals.js +775 -54
  22. package/dist/api/chat-proposals.js.map +1 -1
  23. package/dist/api/chat-requirements.d.ts +54 -0
  24. package/dist/api/chat-requirements.d.ts.map +1 -0
  25. package/dist/api/chat-requirements.js +282 -0
  26. package/dist/api/chat-requirements.js.map +1 -0
  27. package/dist/api/chat-scope.d.ts +56 -0
  28. package/dist/api/chat-scope.d.ts.map +1 -1
  29. package/dist/api/chat-scope.js +175 -5
  30. package/dist/api/chat-scope.js.map +1 -1
  31. package/dist/api/chat-transcripts.d.ts +7 -0
  32. package/dist/api/chat-transcripts.d.ts.map +1 -1
  33. package/dist/api/chat-transcripts.js +17 -1
  34. package/dist/api/chat-transcripts.js.map +1 -1
  35. package/dist/api/delivery-index.d.ts +109 -5
  36. package/dist/api/delivery-index.d.ts.map +1 -1
  37. package/dist/api/delivery-index.js +199 -7
  38. package/dist/api/delivery-index.js.map +1 -1
  39. package/dist/api/mcp.d.ts +7 -2
  40. package/dist/api/mcp.d.ts.map +1 -1
  41. package/dist/api/mcp.js +1 -1
  42. package/dist/api/mcp.js.map +1 -1
  43. package/dist/api/needs.d.ts.map +1 -1
  44. package/dist/api/needs.js +19 -1
  45. package/dist/api/needs.js.map +1 -1
  46. package/dist/api/product.d.ts +9 -2
  47. package/dist/api/product.d.ts.map +1 -1
  48. package/dist/api/product.js +10 -2
  49. package/dist/api/product.js.map +1 -1
  50. package/dist/api/proposal-theme.d.ts +23 -0
  51. package/dist/api/proposal-theme.d.ts.map +1 -0
  52. package/dist/api/proposal-theme.js +30 -0
  53. package/dist/api/proposal-theme.js.map +1 -0
  54. package/dist/api/recording.d.ts +70 -10
  55. package/dist/api/recording.d.ts.map +1 -1
  56. package/dist/api/recording.js +278 -39
  57. package/dist/api/recording.js.map +1 -1
  58. package/dist/api/repo-input.d.ts +55 -0
  59. package/dist/api/repo-input.d.ts.map +1 -0
  60. package/dist/api/repo-input.js +113 -0
  61. package/dist/api/repo-input.js.map +1 -0
  62. package/dist/api/requirements.d.ts +75 -0
  63. package/dist/api/requirements.d.ts.map +1 -1
  64. package/dist/api/requirements.js +97 -9
  65. package/dist/api/requirements.js.map +1 -1
  66. package/dist/api/review-change.d.ts +64 -0
  67. package/dist/api/review-change.d.ts.map +1 -0
  68. package/dist/api/review-change.js +214 -0
  69. package/dist/api/review-change.js.map +1 -0
  70. package/dist/api/roster-standing.d.ts +4 -0
  71. package/dist/api/roster-standing.d.ts.map +1 -1
  72. package/dist/api/roster-standing.js +43 -10
  73. package/dist/api/roster-standing.js.map +1 -1
  74. package/dist/api/routes.d.ts +63 -6
  75. package/dist/api/routes.d.ts.map +1 -1
  76. package/dist/api/routes.js +818 -269
  77. package/dist/api/routes.js.map +1 -1
  78. package/dist/api/run-documents.d.ts +97 -0
  79. package/dist/api/run-documents.d.ts.map +1 -0
  80. package/dist/api/run-documents.js +458 -0
  81. package/dist/api/run-documents.js.map +1 -0
  82. package/dist/api/run-sources.d.ts +51 -0
  83. package/dist/api/run-sources.d.ts.map +1 -0
  84. package/dist/api/run-sources.js +133 -0
  85. package/dist/api/run-sources.js.map +1 -0
  86. package/dist/api/runtime-state.d.ts +41 -0
  87. package/dist/api/runtime-state.d.ts.map +1 -0
  88. package/dist/api/runtime-state.js +75 -0
  89. package/dist/api/runtime-state.js.map +1 -0
  90. package/dist/api/seat-container-login.d.ts +51 -0
  91. package/dist/api/seat-container-login.d.ts.map +1 -1
  92. package/dist/api/seat-container-login.js +317 -1
  93. package/dist/api/seat-container-login.js.map +1 -1
  94. package/dist/api/seat-images.d.ts.map +1 -1
  95. package/dist/api/seat-images.js +7 -0
  96. package/dist/api/seat-images.js.map +1 -1
  97. package/dist/api/server.d.ts +7 -0
  98. package/dist/api/server.d.ts.map +1 -1
  99. package/dist/api/server.js +204 -25
  100. package/dist/api/server.js.map +1 -1
  101. package/dist/api/skills.d.ts +8 -0
  102. package/dist/api/skills.d.ts.map +1 -1
  103. package/dist/api/skills.js +21 -0
  104. package/dist/api/skills.js.map +1 -1
  105. package/dist/api/system-snapshot.d.ts +3 -2
  106. package/dist/api/system-snapshot.d.ts.map +1 -1
  107. package/dist/api/system-snapshot.js +19 -6
  108. package/dist/api/system-snapshot.js.map +1 -1
  109. package/dist/api/testing.d.ts +3 -3
  110. package/dist/api/ui-text.d.ts +45 -0
  111. package/dist/api/ui-text.d.ts.map +1 -0
  112. package/dist/api/ui-text.js +188 -0
  113. package/dist/api/ui-text.js.map +1 -0
  114. package/dist/apps/actions/card.d.ts +62 -0
  115. package/dist/apps/actions/card.d.ts.map +1 -0
  116. package/dist/apps/actions/card.js +111 -0
  117. package/dist/apps/actions/card.js.map +1 -0
  118. package/dist/apps/actions/write-path.d.ts.map +1 -1
  119. package/dist/apps/actions/write-path.js +26 -77
  120. package/dist/apps/actions/write-path.js.map +1 -1
  121. package/dist/apps/exec/sources.d.ts.map +1 -1
  122. package/dist/apps/exec/sources.js +3 -0
  123. package/dist/apps/exec/sources.js.map +1 -1
  124. package/dist/apps/publish/artifacts.d.ts +18 -0
  125. package/dist/apps/publish/artifacts.d.ts.map +1 -0
  126. package/dist/apps/publish/artifacts.js +87 -0
  127. package/dist/apps/publish/artifacts.js.map +1 -0
  128. package/dist/apps/publish/check.d.ts +103 -0
  129. package/dist/apps/publish/check.d.ts.map +1 -0
  130. package/dist/apps/publish/check.js +235 -0
  131. package/dist/apps/publish/check.js.map +1 -0
  132. package/dist/apps/publish/image.d.ts +2 -0
  133. package/dist/apps/publish/image.d.ts.map +1 -1
  134. package/dist/apps/publish/image.js +2 -1
  135. package/dist/apps/publish/image.js.map +1 -1
  136. package/dist/apps/publish/render.d.ts +71 -0
  137. package/dist/apps/publish/render.d.ts.map +1 -0
  138. package/dist/apps/publish/render.js +122 -0
  139. package/dist/apps/publish/render.js.map +1 -0
  140. package/dist/apps/publish/run.d.ts +35 -0
  141. package/dist/apps/publish/run.d.ts.map +1 -0
  142. package/dist/apps/publish/run.js +127 -0
  143. package/dist/apps/publish/run.js.map +1 -0
  144. package/dist/apps/routes.d.ts +54 -2
  145. package/dist/apps/routes.d.ts.map +1 -1
  146. package/dist/apps/routes.js +124 -7
  147. package/dist/apps/routes.js.map +1 -1
  148. package/dist/apps/spec.d.ts +8 -8
  149. package/dist/apps/store.d.ts +84 -5
  150. package/dist/apps/store.d.ts.map +1 -1
  151. package/dist/apps/store.js +191 -4
  152. package/dist/apps/store.js.map +1 -1
  153. package/dist/apps/turns.d.ts +19 -1
  154. package/dist/apps/turns.d.ts.map +1 -1
  155. package/dist/apps/turns.js +60 -2
  156. package/dist/apps/turns.js.map +1 -1
  157. package/dist/apps/views.d.ts +5 -1
  158. package/dist/apps/views.d.ts.map +1 -1
  159. package/dist/apps/views.js +18 -7
  160. package/dist/apps/views.js.map +1 -1
  161. package/dist/apps-server/Dockerfile +25 -0
  162. package/dist/apps-server/runners/sqlite-runner.mjs +110 -0
  163. package/dist/apps-server/server/lib/bundle/server.mjs +92523 -0
  164. package/dist/apps-server/server/node_modules/@pgsql/types/LICENSE +22 -0
  165. package/dist/apps-server/server/node_modules/@pgsql/types/README.md +106 -0
  166. package/dist/apps-server/server/node_modules/@pgsql/types/enums.d.ts +76 -0
  167. package/dist/apps-server/server/node_modules/@pgsql/types/enums.js +2 -0
  168. package/dist/apps-server/server/node_modules/@pgsql/types/esm/enums.js +1 -0
  169. package/dist/apps-server/server/node_modules/@pgsql/types/esm/index.js +2 -0
  170. package/dist/apps-server/server/node_modules/@pgsql/types/esm/types.js +1 -0
  171. package/dist/apps-server/server/node_modules/@pgsql/types/index.d.ts +2 -0
  172. package/dist/apps-server/server/node_modules/@pgsql/types/index.js +18 -0
  173. package/dist/apps-server/server/node_modules/@pgsql/types/package.json +36 -0
  174. package/dist/apps-server/server/node_modules/@pgsql/types/types.d.ts +2488 -0
  175. package/dist/apps-server/server/node_modules/@pgsql/types/types.js +2 -0
  176. package/dist/apps-server/server/node_modules/libpg-query/LICENSE +22 -0
  177. package/dist/apps-server/server/node_modules/libpg-query/README.md +275 -0
  178. package/dist/apps-server/server/node_modules/libpg-query/package.json +58 -0
  179. package/dist/apps-server/server/node_modules/libpg-query/wasm/index.cjs +369 -0
  180. package/dist/apps-server/server/node_modules/libpg-query/wasm/index.d.ts +48 -0
  181. package/dist/apps-server/server/node_modules/libpg-query/wasm/index.js +344 -0
  182. package/dist/apps-server/server/node_modules/libpg-query/wasm/libpg-query.js +2 -0
  183. package/dist/apps-server/server/node_modules/libpg-query/wasm/libpg-query.wasm +0 -0
  184. package/dist/apps-server/server/shim/host.css +22 -0
  185. package/dist/apps-server/server/shim/host.js +1 -0
  186. package/dist/cli/apps-check.d.ts +18 -0
  187. package/dist/cli/apps-check.d.ts.map +1 -1
  188. package/dist/cli/apps-check.js +179 -5
  189. package/dist/cli/apps-check.js.map +1 -1
  190. package/dist/cli/apps-produce.d.ts +9 -0
  191. package/dist/cli/apps-produce.d.ts.map +1 -0
  192. package/dist/cli/apps-produce.js +27 -0
  193. package/dist/cli/apps-produce.js.map +1 -0
  194. package/dist/cli/index.d.ts.map +1 -1
  195. package/dist/cli/index.js +15 -3
  196. package/dist/cli/index.js.map +1 -1
  197. package/dist/cli/insights-facts.d.ts +17 -0
  198. package/dist/cli/insights-facts.d.ts.map +1 -0
  199. package/dist/cli/insights-facts.js +56 -0
  200. package/dist/cli/insights-facts.js.map +1 -0
  201. package/dist/core/adapter.d.ts +74 -15
  202. package/dist/core/adapter.d.ts.map +1 -1
  203. package/dist/core/adapter.js +245 -53
  204. package/dist/core/adapter.js.map +1 -1
  205. package/dist/core/engine-roster.d.ts.map +1 -1
  206. package/dist/core/engine-roster.js +1 -0
  207. package/dist/core/engine-roster.js.map +1 -1
  208. package/dist/core/estate-mcp-client.d.ts +3 -2
  209. package/dist/core/estate-mcp-client.d.ts.map +1 -1
  210. package/dist/core/estate-mcp-client.js +3 -2
  211. package/dist/core/estate-mcp-client.js.map +1 -1
  212. package/dist/core/run-identity.d.ts.map +1 -1
  213. package/dist/core/run-identity.js +3 -0
  214. package/dist/core/run-identity.js.map +1 -1
  215. package/dist/core/types.d.ts +5 -0
  216. package/dist/core/types.d.ts.map +1 -1
  217. package/dist/core/types.js.map +1 -1
  218. package/dist/editors/conformance-runtime.d.ts +107 -0
  219. package/dist/editors/conformance-runtime.d.ts.map +1 -1
  220. package/dist/editors/conformance-runtime.js +268 -13
  221. package/dist/editors/conformance-runtime.js.map +1 -1
  222. package/dist/editors/csp.d.ts +2 -2
  223. package/dist/editors/csp.d.ts.map +1 -1
  224. package/dist/editors/csp.js +4 -2
  225. package/dist/editors/csp.js.map +1 -1
  226. package/dist/editors/pack-install.d.ts +28 -13
  227. package/dist/editors/pack-install.d.ts.map +1 -1
  228. package/dist/editors/pack-install.js +96 -48
  229. package/dist/editors/pack-install.js.map +1 -1
  230. package/dist/editors/registry.d.ts +111 -8
  231. package/dist/editors/registry.d.ts.map +1 -1
  232. package/dist/editors/registry.js +183 -7
  233. package/dist/editors/registry.js.map +1 -1
  234. package/dist/editors/routes.d.ts +66 -13
  235. package/dist/editors/routes.d.ts.map +1 -1
  236. package/dist/editors/routes.js +277 -44
  237. package/dist/editors/routes.js.map +1 -1
  238. package/dist/evals/replay.d.ts +6 -0
  239. package/dist/evals/replay.d.ts.map +1 -1
  240. package/dist/evals/replay.js +24 -1
  241. package/dist/evals/replay.js.map +1 -1
  242. package/dist/evals/routes.d.ts.map +1 -1
  243. package/dist/evals/routes.js +17 -2
  244. package/dist/evals/routes.js.map +1 -1
  245. package/dist/evals/runner.d.ts.map +1 -1
  246. package/dist/evals/runner.js +5 -0
  247. package/dist/evals/runner.js.map +1 -1
  248. package/dist/evals/shape-corrections.d.ts +146 -0
  249. package/dist/evals/shape-corrections.d.ts.map +1 -0
  250. package/dist/evals/shape-corrections.js +394 -0
  251. package/dist/evals/shape-corrections.js.map +1 -0
  252. package/dist/evals/shape.d.ts +145 -0
  253. package/dist/evals/shape.d.ts.map +1 -0
  254. package/dist/evals/shape.js +376 -0
  255. package/dist/evals/shape.js.map +1 -0
  256. package/dist/evals/types.d.ts +2 -2
  257. package/dist/evals/types.d.ts.map +1 -1
  258. package/dist/evals/types.js +2 -1
  259. package/dist/evals/types.js.map +1 -1
  260. package/dist/insights/analyze.d.ts +14 -1
  261. package/dist/insights/analyze.d.ts.map +1 -1
  262. package/dist/insights/analyze.js +35 -8
  263. package/dist/insights/analyze.js.map +1 -1
  264. package/dist/insights/cost.d.ts +123 -0
  265. package/dist/insights/cost.d.ts.map +1 -0
  266. package/dist/insights/cost.js +221 -0
  267. package/dist/insights/cost.js.map +1 -0
  268. package/dist/insights/review-service.d.ts +20 -1
  269. package/dist/insights/review-service.d.ts.map +1 -1
  270. package/dist/insights/review-service.js +50 -25
  271. package/dist/insights/review-service.js.map +1 -1
  272. package/dist/insights/routes.d.ts +29 -0
  273. package/dist/insights/routes.d.ts.map +1 -1
  274. package/dist/insights/routes.js +62 -0
  275. package/dist/insights/routes.js.map +1 -1
  276. package/dist/insights/run-facts.d.ts +16 -0
  277. package/dist/insights/run-facts.d.ts.map +1 -1
  278. package/dist/insights/run-facts.js +26 -3
  279. package/dist/insights/run-facts.js.map +1 -1
  280. package/dist/interactive/bridge-pool.d.ts +11 -2
  281. package/dist/interactive/bridge-pool.d.ts.map +1 -1
  282. package/dist/interactive/bridge-pool.js +10 -1
  283. package/dist/interactive/bridge-pool.js.map +1 -1
  284. package/dist/interactive/chat-events.d.ts +74 -1
  285. package/dist/interactive/chat-events.d.ts.map +1 -1
  286. package/dist/interactive/chat-events.js +338 -6
  287. package/dist/interactive/chat-events.js.map +1 -1
  288. package/dist/interactive/doc-binding.d.ts +15 -0
  289. package/dist/interactive/doc-binding.d.ts.map +1 -1
  290. package/dist/interactive/doc-binding.js +4 -0
  291. package/dist/interactive/doc-binding.js.map +1 -1
  292. package/dist/interactive/doc-checks-routes.d.ts +34 -1
  293. package/dist/interactive/doc-checks-routes.d.ts.map +1 -1
  294. package/dist/interactive/doc-checks-routes.js +84 -0
  295. package/dist/interactive/doc-checks-routes.js.map +1 -1
  296. package/dist/interactive/draft-events.d.ts +7 -0
  297. package/dist/interactive/draft-events.d.ts.map +1 -1
  298. package/dist/interactive/draft-events.js +38 -6
  299. package/dist/interactive/draft-events.js.map +1 -1
  300. package/dist/interactive/draft-skill.d.ts +76 -6
  301. package/dist/interactive/draft-skill.d.ts.map +1 -1
  302. package/dist/interactive/draft-skill.js +219 -17
  303. package/dist/interactive/draft-skill.js.map +1 -1
  304. package/dist/interactive/edit-events.d.ts.map +1 -1
  305. package/dist/interactive/edit-events.js +4 -2
  306. package/dist/interactive/edit-events.js.map +1 -1
  307. package/dist/interactive/landing-guard.d.ts +47 -0
  308. package/dist/interactive/landing-guard.d.ts.map +1 -0
  309. package/dist/interactive/landing-guard.js +43 -0
  310. package/dist/interactive/landing-guard.js.map +1 -0
  311. package/dist/interactive/landing-record.d.ts +68 -0
  312. package/dist/interactive/landing-record.d.ts.map +1 -0
  313. package/dist/interactive/landing-record.js +154 -0
  314. package/dist/interactive/landing-record.js.map +1 -0
  315. package/dist/interactive/proposal-create.d.ts +3 -1
  316. package/dist/interactive/proposal-create.d.ts.map +1 -1
  317. package/dist/interactive/proposal-create.js +14 -2
  318. package/dist/interactive/proposal-create.js.map +1 -1
  319. package/dist/interactive/proposal-refine.d.ts +48 -0
  320. package/dist/interactive/proposal-refine.d.ts.map +1 -0
  321. package/dist/interactive/proposal-refine.js +99 -0
  322. package/dist/interactive/proposal-refine.js.map +1 -0
  323. package/dist/interactive/protected-edits.d.ts +67 -0
  324. package/dist/interactive/protected-edits.d.ts.map +1 -0
  325. package/dist/interactive/protected-edits.js +160 -0
  326. package/dist/interactive/protected-edits.js.map +1 -0
  327. package/dist/interactive/proxy-routes.js +2 -2
  328. package/dist/interactive/review-events.js +1 -1
  329. package/dist/interactive/run-units.d.ts +1 -1
  330. package/dist/interactive/run-units.d.ts.map +1 -1
  331. package/dist/interactive/run-units.js +8 -2
  332. package/dist/interactive/run-units.js.map +1 -1
  333. package/dist/interactive/source-packet.d.ts +66 -1
  334. package/dist/interactive/source-packet.d.ts.map +1 -1
  335. package/dist/interactive/source-packet.js +309 -60
  336. package/dist/interactive/source-packet.js.map +1 -1
  337. package/dist/interactive/theme-events.js +1 -1
  338. package/dist/knowledge/adapters/web/egress.d.ts +99 -0
  339. package/dist/knowledge/adapters/web/egress.d.ts.map +1 -0
  340. package/dist/knowledge/adapters/web/egress.js +330 -0
  341. package/dist/knowledge/adapters/web/egress.js.map +1 -0
  342. package/dist/knowledge/adapters/web/engine.d.ts +54 -0
  343. package/dist/knowledge/adapters/web/engine.d.ts.map +1 -0
  344. package/dist/knowledge/adapters/web/engine.js +101 -0
  345. package/dist/knowledge/adapters/web/engine.js.map +1 -0
  346. package/dist/knowledge/adapters/web/fetch.d.ts +131 -0
  347. package/dist/knowledge/adapters/web/fetch.d.ts.map +1 -0
  348. package/dist/knowledge/adapters/web/fetch.js +325 -0
  349. package/dist/knowledge/adapters/web/fetch.js.map +1 -0
  350. package/dist/knowledge/adapters/web/gate-web.d.ts +182 -0
  351. package/dist/knowledge/adapters/web/gate-web.d.ts.map +1 -0
  352. package/dist/knowledge/adapters/web/gate-web.js +496 -0
  353. package/dist/knowledge/adapters/web/gate-web.js.map +1 -0
  354. package/dist/knowledge/adapters/web/routes.d.ts +36 -0
  355. package/dist/knowledge/adapters/web/routes.d.ts.map +1 -0
  356. package/dist/knowledge/adapters/web/routes.js +99 -0
  357. package/dist/knowledge/adapters/web/routes.js.map +1 -0
  358. package/dist/knowledge/adapters/web/searxng.d.ts +89 -0
  359. package/dist/knowledge/adapters/web/searxng.d.ts.map +1 -0
  360. package/dist/knowledge/adapters/web/searxng.js +274 -0
  361. package/dist/knowledge/adapters/web/searxng.js.map +1 -0
  362. package/dist/knowledge/adapters/web/source.d.ts +65 -0
  363. package/dist/knowledge/adapters/web/source.d.ts.map +1 -0
  364. package/dist/knowledge/adapters/web/source.js +192 -0
  365. package/dist/knowledge/adapters/web/source.js.map +1 -0
  366. package/dist/knowledge/gate/gate.d.ts +22 -0
  367. package/dist/knowledge/gate/gate.d.ts.map +1 -1
  368. package/dist/knowledge/gate/gate.js +62 -1
  369. package/dist/knowledge/gate/gate.js.map +1 -1
  370. package/dist/knowledge/gate/sources.d.ts +2 -0
  371. package/dist/knowledge/gate/sources.d.ts.map +1 -1
  372. package/dist/knowledge/gate/sources.js +5 -2
  373. package/dist/knowledge/gate/sources.js.map +1 -1
  374. package/dist/knowledge/package.d.ts +7 -0
  375. package/dist/knowledge/package.d.ts.map +1 -1
  376. package/dist/knowledge/package.js +15 -1
  377. package/dist/knowledge/package.js.map +1 -1
  378. package/dist/knowledge/trackers/actions.js +1 -1
  379. package/dist/knowledge/trackers/actions.js.map +1 -1
  380. package/dist/knowledge/trackers/bindings.d.ts +3 -3
  381. package/dist/knowledge/trackers/bindings.d.ts.map +1 -1
  382. package/dist/knowledge/trackers/bindings.js +36 -23
  383. package/dist/knowledge/trackers/bindings.js.map +1 -1
  384. package/dist/knowledge/trackers/routes.js +1 -1
  385. package/dist/knowledge/trackers/routes.js.map +1 -1
  386. package/dist/learnings/service.d.ts.map +1 -1
  387. package/dist/learnings/service.js +2 -0
  388. package/dist/learnings/service.js.map +1 -1
  389. package/dist/mcp/broker.d.ts +8 -0
  390. package/dist/mcp/broker.d.ts.map +1 -1
  391. package/dist/mcp/broker.js +48 -3
  392. package/dist/mcp/broker.js.map +1 -1
  393. package/dist/mcp/estate-relay.d.ts +43 -1
  394. package/dist/mcp/estate-relay.d.ts.map +1 -1
  395. package/dist/mcp/estate-relay.js +38 -2
  396. package/dist/mcp/estate-relay.js.map +1 -1
  397. package/dist/mcp/registry.d.ts +6 -0
  398. package/dist/mcp/registry.d.ts.map +1 -1
  399. package/dist/mcp/registry.js +42 -3
  400. package/dist/mcp/registry.js.map +1 -1
  401. package/dist/mcp/run-fence.d.ts +57 -0
  402. package/dist/mcp/run-fence.d.ts.map +1 -0
  403. package/dist/mcp/run-fence.js +86 -0
  404. package/dist/mcp/run-fence.js.map +1 -0
  405. package/dist/mcp/tool-list.d.ts +5 -0
  406. package/dist/mcp/tool-list.d.ts.map +1 -1
  407. package/dist/mcp/tool-list.js +7 -3
  408. package/dist/mcp/tool-list.js.map +1 -1
  409. package/dist/presets/routes.d.ts.map +1 -1
  410. package/dist/presets/routes.js +6 -0
  411. package/dist/presets/routes.js.map +1 -1
  412. package/dist/projects/routes.d.ts +1 -1
  413. package/dist/projects/state-home-preflight.d.ts.map +1 -1
  414. package/dist/projects/state-home-preflight.js +2 -0
  415. package/dist/projects/state-home-preflight.js.map +1 -1
  416. package/dist/setup/tool-path.d.ts +16 -0
  417. package/dist/setup/tool-path.d.ts.map +1 -0
  418. package/dist/setup/tool-path.js +66 -0
  419. package/dist/setup/tool-path.js.map +1 -0
  420. package/dist/skills/plugin-source.d.ts +42 -88
  421. package/dist/skills/plugin-source.d.ts.map +1 -1
  422. package/dist/skills/plugin-source.js +140 -100
  423. package/dist/skills/plugin-source.js.map +1 -1
  424. package/dist/skills/runtime.d.ts.map +1 -1
  425. package/dist/skills/runtime.js +15 -7
  426. package/dist/skills/runtime.js.map +1 -1
  427. package/dist/skills/store.d.ts.map +1 -1
  428. package/dist/skills/store.js +25 -14
  429. package/dist/skills/store.js.map +1 -1
  430. package/dist/skills/usage.d.ts +238 -0
  431. package/dist/skills/usage.d.ts.map +1 -0
  432. package/dist/skills/usage.js +789 -0
  433. package/dist/skills/usage.js.map +1 -0
  434. package/dist/skills/venv.d.ts +18 -2
  435. package/dist/skills/venv.d.ts.map +1 -1
  436. package/dist/skills/venv.js +2 -2
  437. package/dist/skills/venv.js.map +1 -1
  438. package/dist/sources/routes.d.ts +3 -1
  439. package/dist/sources/routes.d.ts.map +1 -1
  440. package/dist/sources/routes.js +11 -0
  441. package/dist/sources/routes.js.map +1 -1
  442. package/dist/standing-orders/parse.d.ts +19 -0
  443. package/dist/standing-orders/parse.d.ts.map +1 -1
  444. package/dist/standing-orders/parse.js +61 -18
  445. package/dist/standing-orders/parse.js.map +1 -1
  446. package/dist/studio/apps-standalone/fixture.html +12 -0
  447. package/dist/studio/apps-standalone/fixture.js +10 -0
  448. package/dist/studio/apps-standalone/runtime.css +139 -0
  449. package/dist/studio/apps-standalone/runtime.js +1 -0
  450. package/dist/studio/assets/{KnowledgeGraph-Cpm46tEp.js → KnowledgeGraph-AtkRlS3c.js} +1 -1
  451. package/dist/studio/assets/index-CdbCAs7s.css +32 -0
  452. package/dist/studio/assets/index-DU_8o4uq.js +1104 -0
  453. package/dist/studio/editors/wicked-apps/editor.json +1 -1
  454. package/dist/studio/editors/wicked-apps/index.html +2 -2
  455. package/dist/studio/editors/wicked-deck/editor.json +1 -1
  456. package/dist/studio/editors/wicked-deck/index.html +14 -1
  457. package/dist/studio/editors/wicked-doc/editor.json +1 -1
  458. package/dist/studio/editors/wicked-doc/index.html +1 -1
  459. package/dist/studio/editors/wicked-insights/editor.json +1 -1
  460. package/dist/studio/editors/wicked-insights/index.html +1 -1
  461. package/dist/studio/editors/wicked-page/editor.json +10 -1
  462. package/dist/studio/editors/wicked-page/index.html +2 -2
  463. package/dist/studio/editors/wicked-video/editor.json +7 -2
  464. package/dist/studio/editors/wicked-video/index.html +14 -11
  465. package/dist/studio/index.html +2 -2
  466. package/dist/studio/testid-inventory.json +2069 -242
  467. package/dist/team/routes.d.ts +1 -1
  468. package/dist/workflow-catalog/build-v2.d.ts +6 -2
  469. package/dist/workflow-catalog/build-v2.d.ts.map +1 -1
  470. package/dist/workflow-catalog/build-v2.js +37 -13
  471. package/dist/workflow-catalog/build-v2.js.map +1 -1
  472. package/dist/workflow-catalog/catalog-data-v2.d.ts.map +1 -1
  473. package/dist/workflow-catalog/catalog-data-v2.js +310 -105
  474. package/dist/workflow-catalog/catalog-data-v2.js.map +1 -1
  475. package/dist/workflow-catalog/catalog-data.d.ts.map +1 -1
  476. package/dist/workflow-catalog/catalog-data.js +2 -20
  477. package/dist/workflow-catalog/catalog-data.js.map +1 -1
  478. package/dist/workflow-catalog/detect-service.d.ts +95 -0
  479. package/dist/workflow-catalog/detect-service.d.ts.map +1 -0
  480. package/dist/workflow-catalog/detect-service.js +239 -0
  481. package/dist/workflow-catalog/detect-service.js.map +1 -0
  482. package/dist/workflow-catalog/detect.d.ts +213 -0
  483. package/dist/workflow-catalog/detect.d.ts.map +1 -0
  484. package/dist/workflow-catalog/detect.js +653 -0
  485. package/dist/workflow-catalog/detect.js.map +1 -0
  486. package/dist/workflow-catalog/shape.d.ts +3 -1
  487. package/dist/workflow-catalog/shape.d.ts.map +1 -1
  488. package/dist/workflow-catalog/shape.js +7 -1
  489. package/dist/workflow-catalog/shape.js.map +1 -1
  490. package/dist/working-doc/bridge-backend.js +2 -2
  491. package/dist/working-doc/event-lines.d.ts +67 -2
  492. package/dist/working-doc/event-lines.d.ts.map +1 -1
  493. package/dist/working-doc/event-lines.js +155 -8
  494. package/dist/working-doc/event-lines.js.map +1 -1
  495. package/dist/working-doc/notes-index.d.ts +35 -0
  496. package/dist/working-doc/notes-index.d.ts.map +1 -0
  497. package/dist/working-doc/notes-index.js +82 -0
  498. package/dist/working-doc/notes-index.js.map +1 -0
  499. package/dist/working-doc/routes.js +4 -4
  500. package/dist/working-doc/sections.js +2 -2
  501. package/dist/working-doc/service.d.ts +260 -21
  502. package/dist/working-doc/service.d.ts.map +1 -1
  503. package/dist/working-doc/service.js +791 -90
  504. package/dist/working-doc/service.js.map +1 -1
  505. package/dist/working-doc/store.d.ts +50 -1
  506. package/dist/working-doc/store.d.ts.map +1 -1
  507. package/dist/working-doc/store.js +4 -1
  508. package/dist/working-doc/store.js.map +1 -1
  509. package/endpoint-manifest.json +187 -3
  510. package/evals/corpora/shape-corrections-v1.json +594 -0
  511. package/evals/corpora/shape-corrections-v1.seat-fixture.json +186 -0
  512. package/evals/corpora/shape-v1.json +2113 -0
  513. package/evals/corpora/shape-v1.seat-fixture.json +1800 -0
  514. package/package.json +11 -7
  515. package/scripts/apps-render.py +226 -0
  516. package/workflows/detect-shape.json +29 -0
  517. package/dist/studio/assets/index-BRBwWQMH.css +0 -32
  518. package/dist/studio/assets/index-CVrWDGRP.js +0 -1097
@@ -1,9 +1,10 @@
1
1
  import { REVIEW_WORKFLOW } from '../insights/workflow.js';
2
+ import { appsRuntimeDir, appsServerArtifact, containerEngineKnown } from '../apps/publish/artifacts.js';
2
3
  import { busSeamsOffWarning, busUnavailableWarning } from '../core/bus-notice.js';
3
4
  import { vaultBinWarning, vaultDiagnostics } from '../core/vault-bin.js';
4
5
  import { PlanSchema, toLaunchPlan } from './plan-schema.js';
5
6
  import { record, z } from '../zod.js';
6
- import { listRequirementsRead, getRequirement, patchRequirement, readRequirementsGraph, REQUIREMENTS_NOT_GENERATED, } from './requirements.js';
7
+ import { listRequirementsRead, setRepoMinimum, getRequirement, patchRequirement, readRequirementsGraph, REQUIREMENTS_NOT_GENERATED, } from './requirements.js';
7
8
  import { randomUUID } from 'node:crypto';
8
9
  import { homedir } from 'node:os';
9
10
  import { readFileSync, existsSync, mkdirSync, realpathSync } from 'node:fs';
@@ -24,15 +25,26 @@ function ensureDir(dir) {
24
25
  function turnReadRoots(scratchRoot) {
25
26
  if (!beneathSupported())
26
27
  return [];
28
+ const real = seatPathOf(scratchRoot);
29
+ const roots = [];
27
30
  try {
28
31
  ensureRealDir(contextReadRoots(scratchRoot).open);
29
32
  ensureRealDir(contextReadRoots(scratchRoot).context);
33
+ roots.push(join(real, 'open'), join(real, 'context'));
30
34
  }
31
35
  catch {
32
- return [];
36
+ // no artifact copies or run briefs this run; the requirements maps are tried on their own
33
37
  }
34
- const real = seatPathOf(scratchRoot);
35
- return [join(real, 'open'), join(real, 'context')];
38
+ // crew#1412: the requirements maps each message hands the seats (`chat-requirements.ts`). Each folder on its own
39
+ // (codex r1/r2): one that cannot be made costs only what it holds, never the other roots.
40
+ try {
41
+ ensureRealDir(join(scratchRoot, REQUIREMENTS_MAP_DIR));
42
+ roots.push(join(real, REQUIREMENTS_MAP_DIR));
43
+ }
44
+ catch {
45
+ // the maps' own publication reports it
46
+ }
47
+ return roots;
36
48
  }
37
49
  import { detectRefusal, isOpenGate, offeredChoices, replayOpenGate } from './gate-cache.js';
38
50
  import { acceptanceRequirementOf, buildAcceptanceView } from '../qe/acceptance.js';
@@ -53,9 +65,10 @@ import { chatSeatAdmission, homeless } from './seat-standing.js';
53
65
  import { seatGovernanceDiagnostics, seatGovernanceWarnings, } from './seat-governance.js';
54
66
  import { seatWorkDefaultNow } from './seat-work-default.js';
55
67
  import { ROSTER_REFRESH_WAIT_MS, rosterWithStandingFactory } from './roster-standing.js';
56
- import { SeatContainerStatus, gatewayDirOf, isContainerLoginCli, isContainerSeatFloor, isHostSeatFloor, loginDetail, runSeatLogin, seatLoginDepsFor, } from './seat-container-login.js';
68
+ import { SeatContainerStatus, gatewayDirOf, isContainerLoginCli, isContainerSeatFloor, isHostSeatFloor, loginDetail, registerSeatContainerLoginRoutes, seatLoginDepsFor, } from './seat-container-login.js';
57
69
  import { ChatTurnIndex } from './chat-turns.js';
58
- import { CHAT_ID, chatMakeDigest, ChatScopeIndex, chatScopeDeps, chatScopeStatement, prepareChatScratch, removeChatScratch, namedKindRefusal, resolveChatScope, } from './chat-scope.js';
70
+ import { CHAT_ID, chatJobTurnLines, chatMakeDigest, ChatScopeIndex, chatScopeDeps, chatScopeStatement, prepareChatScratch, removeChatScratch, namedKindRefusal, resolveChatScope, } from './chat-scope.js';
71
+ import { buildRequirementsMaps, publishRequirementsMaps, REQUIREMENTS_MAP_DIR } from './chat-requirements.js';
59
72
  import { ASK_TURN_BUDGET_SECS, AskPathIndex, isAskTurn } from './ask-paths.js';
60
73
  import { chatTurnStep, resolveChatWorkflow, servedChatWorkflows, writeCapableStep } from './chat-workflow.js';
61
74
  import { reassignRefusedSeats } from '../core/reassign-refusal.js';
@@ -71,6 +84,7 @@ import { registerProjectAggregateRoutes } from './project-aggregates.js';
71
84
  import { composeLaunch, composePreflight, registerProductRoutes } from './product.js';
72
85
  import { buildWorkflowCatalogV2, parseCommand, resolveOption } from '../workflow-catalog/build-v2.js';
73
86
  import { DEFAULT_PROJECT_ID } from '../projects/default-project.js';
87
+ import { DETECT_MAX_CHARS, DETECT_TIMEOUT_MS, DetectService, shadowCheck } from '../workflow-catalog/detect-service.js';
74
88
  import { checkLaunchShape, LaunchShapeSchema, launchShapeOf, servedFor, withBriefLines } from '../workflow-catalog/shape.js';
75
89
  import { registerPresetRoutes } from '../presets/routes.js';
76
90
  import { busRows, openPlanGateRev, registerTeamRoutes, workPlanAccepted } from '../team/routes.js';
@@ -85,7 +99,8 @@ import { registerDefaultEvalRoutes, runAndRecord } from '../evals/routes.js';
85
99
  import { prepareRunEvalsLaunch, RUN_EVALS_WORKFLOW } from '../evals/workflow.js';
86
100
  import { defaultReplaySet } from '../evals/replay.js';
87
101
  import { gardenRootFor } from '../learn/scheduler.js';
88
- import { DEMO_PRESET, demoLaunch, demoLaunchRoots, registerDemoDocumentRoute, registerDemoRoutes, registerWalkthroughRoutes, walkthroughAcceptance } from './recording.js';
102
+ import { agentMay } from '../knowledge/gate/access.js';
103
+ import { DEMO_PRESETS, demoLaunch, demoLaunchRoots, registerDemoDocumentRoute, registerDemoRoutes, registerWalkthroughRoutes, walkthroughAcceptance } from './recording.js';
89
104
  import { projectDocsRoot } from '../interactive/project-root.js';
90
105
  import { registerSkillsRoutes } from './skills.js';
91
106
  import { registerSourceRoutes } from '../sources/routes.js';
@@ -110,13 +125,16 @@ import { isHumanOperator } from './watch-routes.js';
110
125
  import { boundOrigin, InteractiveBridgePool } from '../interactive/bridge-pool.js';
111
126
  import { defaultInteractiveRoot } from '../interactive/bridge-root.js';
112
127
  import { composeDeliverText, configuredPublicOrigin, extractFollowUps, factsFromRun, reportsFromOutputs, FOLLOW_UPS_MAX, framedDeliverText, runUrlFor, } from '../core/deliver-text.js';
113
- import { deliverIdentityFor, deliverRepoFor, deliverTargetView, isGitHubLogin, pushIdentityOf, readDeliverOriginUrl, resolvePullRequest as resolvePullRequestViaGh, unverifiedTreesFrom, } from '../core/deliver.js';
128
+ import { deliverIdentityFor, defaultGhExec, deliverRepoFor, deliverTargetView, isGitHubLogin, pushIdentityOf, readDeliverOriginUrl, resolvePullRequest as resolvePullRequestViaGh, unverifiedTreesFrom, } from '../core/deliver.js';
114
129
  import { credentialsMissingIn, deliverCredentialsProbe, missingCredentials } from '../core/deliver-credentials.js';
115
130
  import { codebaseArchiveUrl } from './codebase-archive.js';
116
131
  import { projectRepoCandidates } from '../interactive/doc-grounding.js';
117
132
  import { artifactStatus, beneathSupported, buildTurnContext, chatMount, ChatMessageContextSchema, contextReadRoots, ensureRealDir, sha256Hex, parseArtifactRef, readGroundingBeneath, seatPathOf, UNFILED_MOUNT, } from './chat-context.js';
118
133
  import { createDocInProcess, registerInteractiveProxy } from '../interactive/proxy-routes.js';
119
134
  import { CreateLauncher } from '../interactive/proposal-create.js';
135
+ import { ThemeLauncher } from './proposal-theme.js';
136
+ import { RefineLauncher } from '../interactive/proposal-refine.js';
137
+ import { lineageSteps, protectedEdits } from '../interactive/protected-edits.js';
120
138
  import { buildRunBrief } from './run-brief.js';
121
139
  import { readBeneath } from './beneath.js';
122
140
  /** A context brief copied into a document's packet, at most (the packet's per-file cap). */
@@ -124,7 +142,9 @@ const BRIEF_COPY_MAX = 512 * 1024;
124
142
  import { registerInteractiveDocDelete } from '../interactive/doc-delete-routes.js';
125
143
  import { registerInteractiveDocChecks } from '../interactive/doc-checks-routes.js';
126
144
  import { crewStateHome, stateHomeOfDb } from '../projects/state-home.js';
127
- import { demoShowOf, factsOf, inputLines, jobLaunchCommon, personPid, requestDigest, SELF_SEATED } from './chat-jobs.js';
145
+ import { demoShowOf, factsOf, inputLines, jobInputsOfProposal, jobLaunchCommon, personPid, requestDigest, SELF_SEATED } from './chat-jobs.js';
146
+ import { DocumentsRefused, documentsClause, RUN_DOCS_TOKENS_MAX, stagedDocumentsOf, stageRunDocuments } from './run-documents.js';
147
+ import { checkSourcePick, projectSources, RUN_SOURCES_MAX, runSourcesDeps, webScopeReason } from './run-sources.js';
128
148
  import { CATALOG_V2_CARDS } from '../workflow-catalog/catalog-data-v2.js';
129
149
  import { ChatProposals, LaunchOnceRegistry, proposalRunId, RecordingStubDispatcher, RevisionEditsSchema, runCostFromEvents } from './chat-proposals.js';
130
150
  import { CATALOG_SEEDS } from '../workflow-catalog/catalog-data.js';
@@ -160,7 +180,9 @@ import { VoiceInjectInputs } from '../voice/inject-input.js';
160
180
  import { GroupIndex } from './group-index.js';
161
181
  import { RunTimingIndex, recordRunLaunched } from './run-timing-index.js';
162
182
  import { GuidanceIndex } from './guidance-index.js';
163
- import { DELIVER_REQUESTED_ACTION, DeliveryIndex, gitRunBranchIsEmpty, gitWorktreeIsClean, isDeliverConflictStranded, deliveryRecordFrom, deliverUnitOf, pushedState, canDeliverResolver, FREE_TEXT_NOTICE, freeTextOutcome, } from './delivery-index.js';
183
+ import { DELIVER_REQUESTED_ACTION, DeliveryIndex, gitRunBranchIsEmpty, gitWorktreeIsClean, isDeliverConflictStranded, deliveryRecordFrom, readDeliveredCommit, deliverUnitOf, pushedState, canDeliverResolver, FREE_TEXT_NOTICE, freeTextOutcome, } from './delivery-index.js';
184
+ import { REVIEW_CHANGE_WORKFLOW, reviewChangeExclusion } from './review-change.js';
185
+ import { rosterWithout } from '../interactive/review-events.js';
164
186
  import { DeliveryDerivationCache } from './delivery-cache.js';
165
187
  import { gitReprovisionWorktree, runDeliverScript, } from './post-hoc-deliver.js';
166
188
  import { LOCAL_ACTOR, trustAtLeast, viewOf } from './auth.js';
@@ -175,16 +197,18 @@ import { registerDecisionRoutes } from '../decisions/routes.js';
175
197
  import { ChatDecisionRecorder } from '../decisions/chat-recorder.js';
176
198
  import { ConsiderationService } from '../decisions/consider.js';
177
199
  import { gardenConformance, gardenPackCheck } from '../editors/pack-install.js';
178
- import { conformanceProvisioner, conformanceRuntimeRoot } from '../editors/conformance-runtime.js';
200
+ import { conformanceProvisioner, conformanceRuntimeReady, conformanceRuntimeRoot, conformanceVenvDir, editorPluginLaunchListener, venvPython } from '../editors/conformance-runtime.js';
179
201
  import { EditorRegistry } from '../editors/registry.js';
180
- import { registerEditorRoutes } from '../editors/routes.js';
202
+ import { registerEditorRoutes, unitTokenProbe } from '../editors/routes.js';
181
203
  import { AppWritePath } from '../apps/actions/write-path.js';
182
204
  import { AppExecutor } from '../apps/exec/executor.js';
183
205
  import { localViewerOf } from '../apps/exec/viewer.js';
184
206
  import { registerAppRoutes } from '../apps/routes.js';
185
207
  import { AppStoreError } from '../apps/store.js';
186
208
  import { registerMcpInspectRoutes } from '../mcp-inspect/routes.js';
209
+ import { daemonRunFence, fencedRunId } from '../mcp/run-fence.js';
187
210
  import { discoverLivePlugin } from '../skills/plugin-source.js';
211
+ import { onboardFailure, readRepoPath, registerFailure } from './repo-input.js';
188
212
  import { resolveDecisionsMode } from '../decisions/types.js';
189
213
  const V = API_PREFIX;
190
214
  /** How long `GET /health` waits on the engine's actor before answering `ping: "busy"` (crew#471). */
@@ -384,6 +408,8 @@ const RULE_STATUSES = new Set(['active', 'retired', 'all']);
384
408
  // Repo names become directory components under ~/.wicked/repos/ — reject anything
385
409
  // that would allow path traversal (slashes, dots-only segments, control chars).
386
410
  const SAFE_REPO_NAME = /^[a-zA-Z0-9][a-zA-Z0-9._-]*$/;
411
+ /** `PUT /repos/:id/requirements/minimum` (api-types 0.197.0 `RequirementsMinimumBody`): `null` clears. */
412
+ export const ReqMinimumSchema = z.strictObject({ minPct: z.number().int().min(1).max(100).nullable() });
387
413
  export const RegisterRepoSchema = z.strictObject({
388
414
  name: z
389
415
  .string()
@@ -443,6 +469,17 @@ const ExcludeLinkedIssuesSchema = z
443
469
  .array(z.string().regex(/^\s*(?:\d+|(?:(?:[\w.-]+\/)?[\w.-]+)?#\d+)\s*$/, 'an issue ref: 541, #541, repo#541 or owner/repo#541'))
444
470
  .max(50)
445
471
  .optional();
472
+ /**
473
+ * F43: the seats a chat job (or a chat document's helpers) may name, and the ones its Start re-checks, in roster order:
474
+ * the seats that can work now (enabled for council, work-eligible, not signed out) under the default launch rule
475
+ * ({@link defaultLaunchRoster}: no opt-in seat unless it is the only one left). Filtered first, so a seat the predicate
476
+ * drops never hides the fallback. The standing rows carry no `optIn` (only `GET /roster` marks it, `markOptIn`), so the
477
+ * opt-in rule reads the key.
478
+ */
479
+ export function proposalRoster(standing) {
480
+ const canWork = standing.filter((s) => s.enabled_for_council && s.seat_eligible_for_work !== false && s.auth !== 'signed_out');
481
+ return defaultLaunchRoster(canWork).map((s) => ({ key: String(s.key), name: s.display_name || String(s.key) }));
482
+ }
446
483
  /**
447
484
  * The default launch roster ({@link defaultLaunchRoster}: no opt-in seats) — plus the opt-in seat a
448
485
  * launch NAMES as its lead (`primary`): naming it is the opt-in.
@@ -578,6 +615,14 @@ export const LaunchSchema = z.strictObject({
578
615
  forceQeAcceptance: z.boolean().optional(),
579
616
  /** (api-types 0.192.0, DES-CATALOG-002 §4.4) What this launch is the shape of; judged against the current catalog. */
580
617
  shape: LaunchShapeSchema.optional(),
618
+ /** (DES-CATALOG-002 §2.d piece 2, CS4) The documents the run reads: chat source tokens, authorised again against
619
+ * `chatId` and staged read-only before the engine is called. `[]` = none (a retry inherits nothing). */
620
+ documents: z.array(z.string().trim().min(1).max(300)).max(RUN_DOCS_TOKENS_MAX).optional(),
621
+ /** (DES-CATALOG-002 §2.d piece 4, CS4) The run's source pick (registered source names); `[]` = none. */
622
+ sources: z.array(z.string().trim().min(1).max(100)).max(RUN_SOURCES_MAX).optional(),
623
+ }).refine((b) => b.documents === undefined || b.documents.length === 0 || b.chatId !== undefined, {
624
+ path: ['documents'],
625
+ error: 'documents are chat tokens: send the chatId they were named in',
581
626
  }).refine((b) => b.skipQeAcceptance === undefined || b.forceQeAcceptance !== true, {
582
627
  path: ['forceQeAcceptance'],
583
628
  error: 'skipQeAcceptance and forceQeAcceptance are mutually exclusive — skip it with a reason, or force it',
@@ -611,7 +656,13 @@ export const LaunchSchema = z.strictObject({
611
656
  * re-runs the judge of a `judge_unavailable` gate on the same work, the step's seat not run again.
612
657
  * The ENGINE refuses each at any other gate (a 409 naming the gate it answers) — and `rejudge`
613
658
  * while no judge seat is eligible ({@link GateInfo.rejudge} says beforehand). */
614
- export const ESCALATION_ACTIONS = ['extend', 'targeted', 'accept_partial', 'accept_suggestion', 'rejudge', 'retry_rules'];
659
+ export const ESCALATION_ACTIONS = ['extend', 'targeted', 'accept_partial', 'accept_suggestion', 'rejudge', 'retry_rules', 'retry_qe'];
660
+ /** (e2e-1105 F23, api-types 0.195.0) `retry_qe` (an escalation arm above): REDO THE QE CHECK at the gate of the run's QE
661
+ * step whose isolated reviewer gave no verdict on the work (INCONCLUSIVE, no reviewer seat, or no bound verdict). The
662
+ * engine (wicked-core `HumanDecision::RetryQe`, core#1312) runs the QE step again from fresh evidence with a new
663
+ * isolated reviewer session, never on an author of the work outside reduced assurance; it is never a verdict (QE stays required, only that
664
+ * reviewer's PASS counts) and is capped at 2 per QE step and tree. The engine refuses it (409) at any other gate,
665
+ * at the cap, and when no reviewer seat can run now. */
615
666
  /** (DES-RULE-CHECK-001 S2, api-types 0.190.0) At a gate the steering-rule check holds or denies:
616
667
  * `retry_rules` (an escalation arm above) re-runs the rule check on the same work, the step's seat
617
668
  * not run again; `skip_rules` skips held rules (unchecked, a waiver to confirm, or, rev 2 / api-types
@@ -698,7 +749,7 @@ export const GateSchema = z.strictObject({
698
749
  .max(500)
699
750
  .optional(),
700
751
  }).refine((b) => (b.action === SKIP_RULES_ACTION) === (b.skipRules !== undefined), { path: ['skipRules'], error: 'skip_rules needs `skipRules`: [{id, reason}] for each rule you skip (unchecked, waived or disputed), each with your written reason; skipRules goes with skip_rules only' }).refine((b) => b.action !== SKIP_RULES_ACTION || (b.approve && b.amend === undefined && b.amendScope === undefined && b.plan === undefined), { path: ['action'], error: 'skip_rules takes approve: true and no amend, amendScope or plan — the reasons ride skipRules' }).refine((b) => b.skipRules === undefined || new Set(b.skipRules.map((r) => r.id)).size === b.skipRules.length, { path: ['skipRules'], error: 'skipRules names a rule twice' }).refine((b) => b.keepRules === undefined || (b.approve && (b.action === undefined || b.action === 'approve') && b.plan === undefined), { path: ['keepRules'], error: 'keepRules goes with a plain approve (no action other than approve, no plan) of a steering-author propose gate' }).refine((b) => b.action === undefined
701
- || (b.action === 'approve' || b.action === 'edit_plan' || b.action === 'amend_intent' || b.action === OPERATOR_JUDGMENT_ACTION || b.action === SKIP_QE_ACTION || b.action === SKIP_RULES_ACTION || isEscalationAction(b.action)) === b.approve, { path: ['action'], error: '`action` disagrees with `approve`: request_changes and reject require approve: false; approve, edit_plan, amend_intent, operator_judgment, skip_qe, skip_rules, extend, targeted, accept_partial, accept_suggestion, rejudge, retry_rules and consent:<id> require approve: true' }).refine(
752
+ || (b.action === 'approve' || b.action === 'edit_plan' || b.action === 'amend_intent' || b.action === OPERATOR_JUDGMENT_ACTION || b.action === SKIP_QE_ACTION || b.action === SKIP_RULES_ACTION || isEscalationAction(b.action)) === b.approve, { path: ['action'], error: '`action` disagrees with `approve`: request_changes and reject require approve: false; approve, edit_plan, amend_intent, operator_judgment, skip_qe, skip_rules, extend, targeted, accept_partial, accept_suggestion, rejudge, retry_rules, retry_qe and consent:<id> require approve: true' }).refine(
702
753
  // (operator ruling 2026-10-21) The override's rationale IS its record: a blank one is a 400 here,
703
754
  // before the engine is asked.
704
755
  (b) => b.action !== OPERATOR_JUDGMENT_ACTION || (b.amend !== undefined && b.amend.trim() !== ''), { path: ['amend'], error: 'operator_judgment needs `amend`: your written rationale — why the failed floor is not the work\'s (an empty one is refused)' }).refine((b) => b.action !== OPERATOR_JUDGMENT_ACTION || (b.amendScope === undefined && b.plan === undefined), { path: ['amendScope'], error: 'operator_judgment takes no amendScope or plan — it answers the failed floor of the gated unit' }).refine(
@@ -707,7 +758,7 @@ export const GateSchema = z.strictObject({
707
758
  // (wicked-core#555) An intent amendment IS its text: an empty one amends nothing, and the arm's
708
759
  // scope is every unit at or after the cursor — which is what makes it reach the evaluator — so
709
760
  // `amendScope` cannot narrow it. Both are 400s here rather than a 409 from the engine.
710
- (b) => b.action !== 'amend_intent' || (b.amend !== undefined && b.amend.trim() !== ''), { path: ['amend'], error: 'amend_intent needs `amend`: what the run\'s acceptance list now says (approve without an action to proceed unamended)' }).refine((b) => b.action !== 'amend_intent' || (b.amendScope === undefined && b.plan === undefined), { path: ['amendScope'], error: 'amend_intent takes no amendScope or plan — an intent amendment reaches every unit at or after the cursor, which is what makes it reach the evaluator' }).refine((b) => !isEscalationAction(b.action) || (b.amend === undefined && b.amendScope === undefined && b.plan === undefined), { path: ['action'], error: 'extend, targeted, accept_partial, accept_suggestion, rejudge, retry_rules and consent:<id> take no amend, amendScope or plan — the engine re-runs the floor, adopts the pinned edit, re-runs the judge or the rule check, or runs the chosen install as it stands' }).refine((b) => (b.action === 'edit_plan') === (b.plan !== undefined) || (b.action === undefined && b.plan !== undefined), { path: ['plan'], error: 'an edited plan answers a plan_approval gate: `plan` needs approve: true with `action` omitted or edit_plan, and edit_plan needs `plan`' }).refine(
761
+ (b) => b.action !== 'amend_intent' || (b.amend !== undefined && b.amend.trim() !== ''), { path: ['amend'], error: 'amend_intent needs `amend`: what the run\'s acceptance list now says (approve without an action to proceed unamended)' }).refine((b) => b.action !== 'amend_intent' || (b.amendScope === undefined && b.plan === undefined), { path: ['amendScope'], error: 'amend_intent takes no amendScope or plan — an intent amendment reaches every unit at or after the cursor, which is what makes it reach the evaluator' }).refine((b) => !isEscalationAction(b.action) || (b.amend === undefined && b.amendScope === undefined && b.plan === undefined), { path: ['action'], error: 'extend, targeted, accept_partial, accept_suggestion, rejudge, retry_rules, retry_qe and consent:<id> take no amend, amendScope or plan — the engine re-runs the floor, adopts the pinned edit, re-runs the judge, the rule check or the QE check, or runs the chosen install as it stands' }).refine((b) => (b.action === 'edit_plan') === (b.plan !== undefined) || (b.action === undefined && b.plan !== undefined), { path: ['plan'], error: 'an edited plan answers a plan_approval gate: `plan` needs approve: true with `action` omitted or edit_plan, and edit_plan needs `plan`' }).refine(
711
762
  // (crew#1139) `amend` beside a plan is the operator's note to the steps it releases (the engine lands
712
763
  // it on the plan's first creator step); a plan gate's note has no scope to choose.
713
764
  (b) => b.plan === undefined || (b.approve && b.amendScope === undefined), { path: ['plan'], error: '`plan` is an approve WITH an edited plan: approve: true, and no amendScope (a note in `amend` lands on the plan\'s first creator step)' }).refine((b) => b.amendScope === undefined || b.approve, { path: ['amendScope'], error: '`amendScope` applies to an approve only (approve: true)' });
@@ -972,6 +1023,52 @@ security = { audit: AuditLog.noop(), authMode: 'off' },
972
1023
  // Defaulted likewise: a directly-driven route set gets a fresh (all-active) health map and the
973
1024
  // real OS opener — tests inject both through this seam.
974
1025
  runtime = {}) {
1026
+ // (DES-DEMO-RECORD-001 §3.7) The seams a demo launch reads to decide what the app may show a model, and whether
1027
+ // the engine records demos on the host at all. One object for the route and a chat's Demo video job.
1028
+ const demoDeps = {
1029
+ engineRecordsDemos: async () => (typeof adapter.catalog === 'function' ? (await adapter.catalog()).some((e) => e.id === 'demo_record') : true),
1030
+ // (DES-DEMO-RECORD-001 §3.7) The sources a crew app reads, and whether agents may query each: a demo of an app
1031
+ // whose rows may not reach a model records with no model review.
1032
+ ...(runtime.apps !== undefined
1033
+ ? {
1034
+ // Every source any version of the app reads (the head, and every accepted version the page may serve):
1035
+ // the person's page picks its version, so the decision covers them all. `null` when the head spec
1036
+ // cannot be read (the decision then keeps the rows private).
1037
+ appSources: async (slug) => {
1038
+ const store = runtime.apps;
1039
+ const detail = await store.detail(slug);
1040
+ if (detail.spec === null || detail.spec === undefined)
1041
+ return null;
1042
+ const sourcesOf = (spec) => (spec?.queries ?? [])
1043
+ .map((q) => q.source)
1044
+ .filter((x) => typeof x === 'string');
1045
+ const all = new Set(sourcesOf(detail.spec));
1046
+ for (const v of detail.versions) {
1047
+ try {
1048
+ for (const s of sourcesOf((await store.acceptedSpec(slug, v.version)).spec))
1049
+ all.add(s);
1050
+ }
1051
+ catch (err) {
1052
+ // A version that was never accepted never runs against a source; anything else is unreadable.
1053
+ if (err.code !== 'not_accepted')
1054
+ return null;
1055
+ }
1056
+ }
1057
+ return [...all];
1058
+ },
1059
+ }
1060
+ : {}),
1061
+ ...(runtime.dataGate !== undefined
1062
+ ? {
1063
+ // The data gate's own predicate (DES-APPS-001 S5): the source on, query on, and the run's project in its
1064
+ // scope. A source the gate does not know keeps the rows private.
1065
+ agentQueryAllowed: async (source, projectId) => {
1066
+ const s = (await runtime.dataGate.sources()).find((x) => x.name === source);
1067
+ return s !== undefined && agentMay(s.access, s, projectId, 'query');
1068
+ },
1069
+ }
1070
+ : {}),
1071
+ };
975
1072
  const { audit } = security;
976
1073
  const seatHealth = runtime.seatHealth ?? new SeatHealthTracker();
977
1074
  const deliveryFreeze = runtime.deliveryFreeze ?? new DeliveryFreeze();
@@ -1004,19 +1101,28 @@ runtime = {}) {
1004
1101
  const chatTranscripts = runtime.chatTranscripts;
1005
1102
  const chatAttachments = runtime.chatAttachments ?? new ChatAttachmentStore();
1006
1103
  const chatHistory = runtime.chatHistory ?? (chatTranscripts !== undefined ? new ChatHistoryStore(chatTranscripts, chatAttachments) : null);
1007
- // DES-CHAT-ARTIFACTS-001 §14 (A2): what a chat can do with artifacts. Production: `proposals` on and every operation
1008
- // off — each later slice turns its own on and registers its launcher. The TEST configuration (§13 A2) turns every
1104
+ // DES-CHAT-ARTIFACTS-001 §14 (A2): what a chat can do with artifacts. Production: `proposals` on, and each operation
1105
+ // on once its slice registers its launcher (A3 create, A7 theme). The TEST configuration (§13 A2) turns every
1009
1106
  // operation's resolution on and registers a recording stub that starts nothing.
1010
1107
  const chatArtifactsStub = runtime.chatArtifactsStub === true;
1011
1108
  // A3: a real `create` exists whenever the draft seam can launch a proposal-bound draft (the launcher is registered
1012
1109
  // below, once the bridge pool exists). Production advertises it; the test configuration keeps the recording stub only
1013
1110
  // for the operations whose slices have not landed.
1014
1111
  const realCreate = runtime.docBindings !== undefined && runtime.launchBoundDraft !== undefined;
1015
- const stubOps = realCreate ? ['refine', 'theme', 'demo'] : ['create', 'refine', 'theme', 'demo'];
1112
+ // A7: a theme starts no run (§15.2), so its launcher is always real: studio applies the patch, Go records it.
1113
+ // A5: a real `refine` exists whenever the chat seam can launch a proposal-bound refine (its launcher is registered
1114
+ // below, beside `create`).
1115
+ const realRefine = runtime.docBindings !== undefined && runtime.launchBoundRefine !== undefined;
1116
+ const stubOps = [
1117
+ ...(realCreate ? [] : ['create']),
1118
+ ...(realRefine ? [] : ['refine']),
1119
+ 'demo',
1120
+ ];
1016
1121
  const chatArtifactFlags = chatArtifactsStub
1017
1122
  ? { context: true, proposals: true, create: true, refine: true, theme: true, demo: true, stub: true, stubOps }
1018
- : { context: true, proposals: true, create: realCreate, refine: false, theme: false, demo: false };
1123
+ : { context: true, proposals: true, create: realCreate, refine: realRefine, theme: true, demo: false };
1019
1124
  const proposalLaunchers = new LaunchOnceRegistry();
1125
+ proposalLaunchers.register('theme', new ThemeLauncher());
1020
1126
  /** (DES-CATALOG-002 §4.6) Job proposals in a chat: on wherever chat proposals are. */
1021
1127
  const chatJobProposalsOn = chatArtifactFlags.proposals;
1022
1128
  if (chatArtifactsStub) {
@@ -1126,11 +1232,35 @@ runtime = {}) {
1126
1232
  ...(runtime.studioRoot !== undefined ? { studioRoot: runtime.studioRoot } : {}),
1127
1233
  log: (m) => app.log.warn(m),
1128
1234
  });
1235
+ // (DES-EDITOR-CONFORMANCE-HOST) An editor-plugin run's conformance step runs on this host under crew's runtime:
1236
+ // start making it when such a run starts, so it is ready when the build is done.
1237
+ if (runtime.editorConformance === undefined && typeof adapter.onLaunch === 'function') {
1238
+ const root = conformanceRuntimeRoot();
1239
+ const off = adapter.onLaunch(editorPluginLaunchListener({
1240
+ provision: editorConformanceRuntime,
1241
+ log: (m) => app.log.warn(m),
1242
+ managed: venvPython(conformanceVenvDir(root)),
1243
+ ready: () => conformanceRuntimeReady(root),
1244
+ workflowOf: async (runId) => {
1245
+ const events = await adapter.runEvents(runId);
1246
+ const started = events?.find((e) => e.type === 'sessionStarted');
1247
+ return typeof started?.workflowId === 'string' ? started.workflowId : undefined;
1248
+ },
1249
+ }));
1250
+ app.addHook('onClose', async () => {
1251
+ off();
1252
+ });
1253
+ }
1129
1254
  registerEditorRoutes(app, {
1130
1255
  registry: editorRegistry,
1131
1256
  adapter,
1132
1257
  packCheck: runtime.packCheck ?? gardenPackCheck(discoverLivePlugin()?.path ?? null),
1133
1258
  conformance: runtime.editorConformance ?? gardenConformance(discoverLivePlugin()?.path ?? null, () => process.env['WICKED_CREW_URL'] ?? null, { provision: editorConformanceRuntime }),
1259
+ // F37: the grant write's §6.4 tripwire asks the engine whether a bearer is a governed unit's token.
1260
+ ...(() => {
1261
+ const probe = runtime.editorUnitTokenProbe !== undefined ? runtime.editorUnitTokenProbe : unitTokenProbe(CoreAdapter.estateScopeResolver());
1262
+ return probe !== undefined ? { isUnitToken: probe } : {};
1263
+ })(),
1134
1264
  log: (m) => app.log.warn(m),
1135
1265
  });
1136
1266
  // DES-APPS-001 §7.6 (K2a): the app store's routes, when this daemon has a store.
@@ -1174,6 +1304,15 @@ runtime = {}) {
1174
1304
  registerAppRoutes(app, {
1175
1305
  store: runtime.apps,
1176
1306
  audit,
1307
+ publish: {
1308
+ engine: adapter,
1309
+ roster: async () => {
1310
+ await rosterWithStanding.ready?.();
1311
+ return JSON.stringify(launchRosterNaming(rosterWithStanding(), undefined));
1312
+ },
1313
+ registry: runtime.mcp ?? null,
1314
+ grantOf: (slug, action) => appsWritePath?.getGrant(slug, action) ?? null,
1315
+ },
1177
1316
  ...(appsExecutor !== undefined ? { executor: appsExecutor } : {}),
1178
1317
  ...(appsWritePath !== undefined ? { writePath: appsWritePath } : {}),
1179
1318
  ...(runtime.appsVerifyUnitToken !== undefined ? { verifyUnitToken: runtime.appsVerifyUnitToken } : {}),
@@ -1194,6 +1333,27 @@ runtime = {}) {
1194
1333
  : null;
1195
1334
  /** Repo root for a repo ref, from the registry — shared by the reprovision path below. */
1196
1335
  const repoRootOf = async (repoRef) => (await adapter.listRepos()).find((r) => r.id === repoRef)?.root_path;
1336
+ /** The lookups a review-change exclusion reads (the launch and the job proposal read the same ones, CJ13). */
1337
+ const reviewChangeDeps = (repoRef, repoRoot) => ({
1338
+ repoRef,
1339
+ repoRoot,
1340
+ views: () => adapter.sessionsDetail(),
1341
+ deliveredUrl: (id) => deliveryIndex.urlFor(id),
1342
+ pushed: (id) => deliveryIndex.pushedFor(id),
1343
+ deliveredCommit: (id) => deliveryIndex.commitFor(id),
1344
+ revisesPr: (id) => retryIndex.revisesPrFor(id),
1345
+ gh: runtime.reviewChange?.gh ?? defaultGhExec,
1346
+ git: runtime.reviewChange?.git ?? (async (args, cwd) => {
1347
+ try {
1348
+ return { ...(await execCapped('git', args, { cwd, timeout: 5_000 })), code: 0 };
1349
+ }
1350
+ catch (err) {
1351
+ // Only exit 1 proves non-membership; preserve it separately from lookup failures.
1352
+ const code = err.code;
1353
+ return { code: typeof code === 'number' ? code : null, stdout: '', stderr: message(err) };
1354
+ }
1355
+ }),
1356
+ });
1197
1357
  /** DES-L9: PR number → head branch, through `gh pr view` unless the runtime injected an answerer. */
1198
1358
  const resolvePullRequest = runtime.resolvePullRequest ?? resolvePullRequestViaGh;
1199
1359
  /** crew#627: the intent's linked issues, read under the daemon's identity at launch. */
@@ -1593,8 +1753,11 @@ runtime = {}) {
1593
1753
  // DES-CATALOG-002 §4.1: `?v=2` on the same route, and `shape` on every launch route.
1594
1754
  workflowCatalogV2: app.hasRoute({ method: 'GET', url: `${V}/workflows/catalog` }),
1595
1755
  launchShape: true,
1756
+ // DES-CATALOG-002 §2.3: `POST /workflows/catalog/detect` (the words layer, then the hidden detect-shape turn).
1757
+ detectShape: app.hasRoute({ method: 'POST', url: `${V}/workflows/catalog/detect` }),
1596
1758
  // DES-CATALOG-002 §4.6: person-made and revised job proposals, the revising hold, plan answers bound to planRev.
1597
1759
  chatJobProposals: chatJobProposalsOn,
1760
+ chatJobPower: chatJobProposalsOn,
1598
1761
  reshapeRun: chatJobProposalsOn,
1599
1762
  // (api-types 0.169.0, DES-CHAT-ARTIFACTS-001 §14) Per operation: A1 serves `context` (the chat sees the open
1600
1763
  // artifact and the runs the person names; `seedFromArtifact`); A2 (0.170.0) `proposals`. The operations are later
@@ -1608,7 +1771,7 @@ runtime = {}) {
1608
1771
  query: appsExecutor !== undefined,
1609
1772
  actions: appsWritePath !== undefined,
1610
1773
  turns: runtime.apps.turns !== null,
1611
- publish: false,
1774
+ publish: appsServerArtifact() !== null && appsRuntimeDir() !== null && containerEngineKnown(),
1612
1775
  uploads: app.hasRoute({ method: 'POST', url: `${V}/apps/uploads` }),
1613
1776
  sourceCheck: runtime.apps.sourceStage !== null,
1614
1777
  },
@@ -1810,6 +1973,43 @@ runtime = {}) {
1810
1973
  return { diagnostics: [], workEligible: new Set() };
1811
1974
  }
1812
1975
  };
1976
+ /**
1977
+ * The seat record per query (`<days> <project>`), F35: one read at a time per query, which every
1978
+ * caller asking meanwhile shares, kept while the views snapshot it was read from is current (held
1979
+ * weakly: a kept answer never keeps an old snapshot alive). At most {@link SEAT_RECORDS_KEPT}
1980
+ * answered queries are kept (trimmed as each read settles); a read in flight is never dropped, so it
1981
+ * stays shared.
1982
+ */
1983
+ const seatRecords = new Map();
1984
+ const SEAT_RECORDS_KEPT = 16;
1985
+ /** Drop the oldest answered queries past {@link SEAT_RECORDS_KEPT}; a read in flight is never dropped. */
1986
+ const trimSeatRecords = () => {
1987
+ let answered = 0;
1988
+ for (const kept of seatRecords.values())
1989
+ if (kept.settled)
1990
+ answered++;
1991
+ for (const [k, kept] of seatRecords) {
1992
+ if (answered <= SEAT_RECORDS_KEPT)
1993
+ break;
1994
+ if (kept.settled) {
1995
+ seatRecords.delete(k);
1996
+ answered--;
1997
+ }
1998
+ }
1999
+ };
2000
+ const readSeatRecord = async (snapshot, days, project) => {
2001
+ const detail = structuredClone(snapshot.views);
2002
+ await backfillEndedAt(detail);
2003
+ const all = detail.map(decorateRun);
2004
+ const views = project === undefined ? all : all.filter((v) => v.session.project_id === project);
2005
+ return seatRecord(views, async (id) => {
2006
+ const engine = await adapter.runEvents(id);
2007
+ if (engine === null)
2008
+ return null;
2009
+ const daemon = runtime.stallFrames?.(id) ?? [];
2010
+ return daemon.length === 0 ? engine : [...engine, ...daemon];
2011
+ }, { days, now: Date.now() });
2012
+ };
1813
2013
  // Each seat's week (studio's weekly 1:1 per agent; api-types 0.52.0): units, first pass, rework,
1814
2014
  // stalls, bench and cost, folded from the runs' durable event logs by `seatRecord` — nothing new
1815
2015
  // is stored. The daemon's remembered stall frames join the engine's, as on `/runs/:id/events`.
@@ -1831,17 +2031,25 @@ runtime = {}) {
1831
2031
  return reply.code(400).send({ error: 'Invalid ?project — expected one project id' });
1832
2032
  }
1833
2033
  const project = rawProject?.trim();
1834
- const detail = await adapter.sessionsDetail();
1835
- await backfillEndedAt(detail);
1836
- const all = detail.map(decorateRun);
1837
- const views = project === undefined ? all : all.filter((v) => v.session.project_id === project);
1838
- const out = await seatRecord(views, async (id) => {
1839
- const engine = await adapter.runEvents(id);
1840
- if (engine === null)
1841
- return null;
1842
- const daemon = runtime.stallFrames?.(id) ?? [];
1843
- return daemon.length === 0 ? engine : [...engine, ...daemon];
1844
- }, { days, now: Date.now() });
2034
+ // F35: it reads up to SEAT_RECORD_RUN_CAP run logs and studio asks from every tab, so one read
2035
+ // per query runs at a time, shared, and is kept while its views snapshot is current.
2036
+ const snapshot = await adapter.runViewsSnapshot();
2037
+ const key = `${days} ${project ?? ''}`;
2038
+ let entry = seatRecords.get(key);
2039
+ if (entry === undefined || (entry.settled && entry.of.deref() !== snapshot)) {
2040
+ const started = { of: new WeakRef(snapshot), read: readSeatRecord(snapshot, days, project), settled: false };
2041
+ seatRecords.delete(key);
2042
+ seatRecords.set(key, started);
2043
+ started.read.then(() => {
2044
+ started.settled = true;
2045
+ trimSeatRecords();
2046
+ }, () => {
2047
+ if (seatRecords.get(key) === started)
2048
+ seatRecords.delete(key);
2049
+ });
2050
+ entry = started;
2051
+ }
2052
+ const out = await entry.read;
1845
2053
  if (out === null) {
1846
2054
  return reply.code(503).send({ error: 'Seat records are unavailable: this wicked-core build has no event-log read binding' });
1847
2055
  }
@@ -1867,8 +2075,7 @@ runtime = {}) {
1867
2075
  try {
1868
2076
  let session;
1869
2077
  if (runId !== undefined) {
1870
- const views = await adapter.sessionsDetail();
1871
- const view = views.find((v) => v.session.id === runId);
2078
+ const view = await adapter.runView(runId);
1872
2079
  if (view === undefined) {
1873
2080
  return reply.code(404).send({ error: `unknown run: ${runId}` });
1874
2081
  }
@@ -1905,8 +2112,7 @@ runtime = {}) {
1905
2112
  let session;
1906
2113
  let roots;
1907
2114
  try {
1908
- const views = await adapter.sessionsDetail();
1909
- const view = views.find((v) => v.session.id === id);
2115
+ const view = await adapter.runView(id);
1910
2116
  if (view === undefined) {
1911
2117
  await reply.code(404).send({ error: `unknown run: ${id}` });
1912
2118
  return null;
@@ -2255,7 +2461,15 @@ runtime = {}) {
2255
2461
  const refused = await onboardRefusal();
2256
2462
  if (refused !== null)
2257
2463
  return reply.code(refused.status).send(refused.body);
2258
- const { name, rootPath, gitUrl, projectId, channel, actor, autoCapture } = parsed.data;
2464
+ const { name, gitUrl, projectId, channel, actor, autoCapture } = parsed.data;
2465
+ // First-run C1: `~/code/my-app` (the field's own example) is expanded; a relative or missing folder is refused in plain words.
2466
+ let rootPath = parsed.data.rootPath;
2467
+ if (rootPath !== undefined && rootPath !== '') {
2468
+ const read = readRepoPath(rootPath);
2469
+ if (!read.ok)
2470
+ return reply.code(400).send({ code: read.code, error: read.error });
2471
+ rootPath = read.path;
2472
+ }
2259
2473
  // (DES-PM-001 Q-PM2) Re-pointing an existing repo id at another checkout keeps its projects and tracker links.
2260
2474
  const repointed = await reRegisterRefusal(actorOf(req), name, rootPath, Boolean(gitUrl), () => adapter.listRepos());
2261
2475
  if (repointed !== null)
@@ -2277,10 +2491,11 @@ runtime = {}) {
2277
2491
  }
2278
2492
  catch (err) {
2279
2493
  if (repo === undefined)
2280
- return reply.code(400).send({ error: message(err) });
2494
+ return reply.code(400).send(registerFailure(message(err), gitUrl ? undefined : rootPath));
2281
2495
  req.log.warn({ repoId: repo.id }, `repo registered but onboarding launch failed: ${message(err)}`);
2282
2496
  // No run exists to record or file, even when projectId was supplied (crew#1019).
2283
- return reply.code(201).send({ repo, onboardRunId: null, onboardError: message(err) });
2497
+ const failure = onboardFailure(message(err));
2498
+ return reply.code(201).send({ repo, onboardRunId: null, onboardError: failure.error, ...(failure.code !== undefined ? { onboardErrorCode: failure.code, missingTool: failure.tool } : {}) });
2284
2499
  }
2285
2500
  const projectAttachError = await recordOnboardingLaunch(req, runId, repo.id, { projectId, channel, actor, autoCapture });
2286
2501
  return reply.code(201).send({ repo, onboardRunId: runId, ...(projectAttachError !== undefined ? { projectAttachError } : {}) });
@@ -2311,7 +2526,8 @@ runtime = {}) {
2311
2526
  runId = await adapter.launchOnboardingRun(repo.id, repo.name);
2312
2527
  }
2313
2528
  catch (err) {
2314
- return reply.code(400).send({ error: message(err) });
2529
+ const failure = onboardFailure(message(err));
2530
+ return reply.code(400).send({ error: failure.error, ...(failure.code !== undefined ? { code: failure.code, missingTool: failure.tool } : {}) });
2315
2531
  }
2316
2532
  const projectAttachError = await recordOnboardingLaunch(req, runId, repo.id, body.data);
2317
2533
  return reply.code(201).send({ runId, ...(projectAttachError !== undefined ? { projectAttachError } : {}) });
@@ -2355,6 +2571,35 @@ runtime = {}) {
2355
2571
  presets: (projectId) => adapter.listPresets(projectId),
2356
2572
  entries: () => adapter.catalog(),
2357
2573
  };
2574
+ /** (CS4) A chat's project, as its proposals read it (`null`: Unfiled, or the chat is unknown). */
2575
+ const chatProposalsProjectOf = (chatId) => {
2576
+ const p = chatScopes.get(chatId)?.projectId ?? chatHistory?.stateOf(chatId)?.projectId ?? null;
2577
+ return p === null || p === DEFAULT_PROJECT_ID ? null : p;
2578
+ };
2579
+ /**
2580
+ * (CS4) The documents an earlier run was given, to be authorised and staged again for its retry: its tokens and chat
2581
+ * from its staged manifest, hash-checked. `null` = it had none; `'unreadable'` = it had some that can't be read back.
2582
+ */
2583
+ const stagedTokensOf = (runId, root) => {
2584
+ const staged = stagedDocumentsOf(runId, root);
2585
+ if (staged === null) {
2586
+ try {
2587
+ readFileSync(join(root, runId, 'records', 'MANIFEST.json'));
2588
+ }
2589
+ catch {
2590
+ return null;
2591
+ }
2592
+ return 'unreadable';
2593
+ }
2594
+ try {
2595
+ const m = JSON.parse(readFileSync(join(staged.records, 'MANIFEST.json'), 'utf8'));
2596
+ const tokens = [...new Set(staged.files.filter((f) => f.derived === undefined).map((f) => f.token))];
2597
+ return typeof m.chat === 'string' && tokens.length > 0 ? { chatId: m.chat, tokens } : 'unreadable';
2598
+ }
2599
+ catch {
2600
+ return 'unreadable';
2601
+ }
2602
+ };
2358
2603
  const launchRun = async (raw, ctx) => {
2359
2604
  const reply = new LaunchReply();
2360
2605
  const req = { body: raw, log: ctx.log, actor: ctx.actor };
@@ -2373,7 +2618,7 @@ runtime = {}) {
2373
2618
  if (b.shape !== undefined) {
2374
2619
  const target = ctx.target === 'compose'
2375
2620
  ? { kind: 'compose' }
2376
- : b.workflow === DEMO_PRESET
2621
+ : b.workflow !== undefined && DEMO_PRESETS.includes(b.workflow)
2377
2622
  ? { kind: 'demo' }
2378
2623
  : { kind: 'run', workflow: b.workflow };
2379
2624
  if (ctx.target !== 'compose' && b.plan !== undefined) {
@@ -2394,7 +2639,7 @@ runtime = {}) {
2394
2639
  }
2395
2640
  // The demo preset launches only from POST /projects/:id/demo (api/recording.ts), which mints the run's
2396
2641
  // demo root and brief first: launched here directly it would have neither.
2397
- if (b.workflow === DEMO_PRESET && (b.sessionId === undefined || !demoLaunchRoots.has(b.sessionId))) {
2642
+ if (b.workflow !== undefined && DEMO_PRESETS.includes(b.workflow) && (b.sessionId === undefined || !demoLaunchRoots.has(b.sessionId))) {
2398
2643
  return reply.code(400).send({
2399
2644
  error: 'the demo preset launches from POST /projects/:id/demo, which makes its demo root and brief; POST /runs does not take it directly',
2400
2645
  });
@@ -2461,10 +2706,15 @@ runtime = {}) {
2461
2706
  const captureRoot = captureLaunchRoots.get(input.sessionId);
2462
2707
  if (captureRoot !== undefined)
2463
2708
  input.extraWriteRoots = [captureRoot];
2464
- // A demo launch (api/recording.ts) writes every file into the demo root the demo route minted for it.
2465
- const demoRoot = demoLaunchRoots.get(input.sessionId);
2466
- if (demoRoot !== undefined)
2467
- input.extraWriteRoots = [demoRoot];
2709
+ // A demo launch (api/recording.ts, DES-DEMO-RECORD-001 §3.2): the demo root is the run's evidence root (the
2710
+ // engine's Tools record under it); the plan directory is its ONLY write root; the probe (and the review
2711
+ // sheets, when the rows may reach a model) are read-only mounts.
2712
+ const demo = demoLaunchRoots.get(input.sessionId);
2713
+ if (demo !== undefined) {
2714
+ input.extraWriteRoots = [demo.write];
2715
+ input.extraReadRoots = demo.read;
2716
+ input.demoRoot = demo.root;
2717
+ }
2468
2718
  if (b.entityMode !== undefined)
2469
2719
  input.entityMode = b.entityMode;
2470
2720
  if (b.humanConfirm !== undefined)
@@ -2589,7 +2839,15 @@ runtime = {}) {
2589
2839
  else if (!powerSupported()) {
2590
2840
  powerNotice = 'this engine has no power mode; the launch runs phased';
2591
2841
  }
2592
- else {
2842
+ else if (ctx.powerRequired === true && ((await adapter.getSettings()).powerModeDefault ?? true) === false) {
2843
+ // A chat job's power Start follows the setting up to the engine call (it may have been turned off meanwhile).
2844
+ powerNotice = 'Power mode for new jobs is off on this daemon; the launch runs phased';
2845
+ }
2846
+ // A chat job's power Start is never run phased in its place (the person chose no plan review for a power run).
2847
+ if (powerNotice !== null && ctx.powerRequired === true) {
2848
+ return reply.code(409).send({ code: 'power_unavailable', error: `${powerNotice.replace(/; this launch runs phased|; the launch runs phased/u, '')}; press Start with Review plan on` });
2849
+ }
2850
+ if (powerNotice === null) {
2593
2851
  input.power = true;
2594
2852
  input.humanConfirm = 'none';
2595
2853
  // DES-LEARN §3.3 / wicked-core#1216: the orchestrator talks to the person in their personality
@@ -2608,6 +2866,66 @@ runtime = {}) {
2608
2866
  input.skipQeAcceptanceReason = settingSkip;
2609
2867
  if (b.forceQeAcceptance === true)
2610
2868
  input.forceQeAcceptance = true;
2869
+ let reviewChange;
2870
+ if (b.workflow === REVIEW_CHANGE_WORKFLOW) {
2871
+ if (b.deliver === 'pr' || b.revisesPr !== undefined) {
2872
+ return reply.code(400).send({ error: 'a review posts nothing and never delivers' });
2873
+ }
2874
+ if (b.repoRef === undefined)
2875
+ return reply.code(400).send({ error: 'review-change needs repoRef' });
2876
+ deliver = 'none';
2877
+ delete input.deliver;
2878
+ const root = await repoRootOf(b.repoRef);
2879
+ if (root === undefined)
2880
+ return reply.code(404).send({ error: `repoRef names an unknown repo: ${b.repoRef}` });
2881
+ const ex = await reviewChangeExclusion(envelopeWords, reviewChangeDeps(b.repoRef, root));
2882
+ if (!ex.ok)
2883
+ return reply.code(409).send({ code: ex.code, error: ex.error });
2884
+ const excluded = b.reducedAssurance === true ? [] : ex.excludeSeats;
2885
+ if (b.reducedAssurance !== true) {
2886
+ let parsed;
2887
+ try {
2888
+ parsed = JSON.parse(input.clisJson);
2889
+ }
2890
+ catch {
2891
+ parsed = null;
2892
+ }
2893
+ if (!Array.isArray(parsed))
2894
+ return reply.code(400).send({ error: 'review-change needs clisJson to be a roster array' });
2895
+ const roster = rosterWithout(parsed, excluded);
2896
+ const canWork = roster.some((seat) => {
2897
+ if (typeof seat !== 'object' || seat === null)
2898
+ return false;
2899
+ const s = seat;
2900
+ const health = toEngineSeat(s).health;
2901
+ return typeof s['key'] === 'string' && s['key'].trim() !== '' && s['work_eligible'] !== false &&
2902
+ s['seat_eligible_for_work'] !== false && s['signed_in'] !== false && s['auth'] !== 'signed_out' && health?.usable !== false;
2903
+ });
2904
+ if (!canWork) {
2905
+ return reply.code(409).send({
2906
+ code: 'no_independent_reviewer',
2907
+ error: `Every available seat (${ex.excludeSeats.join(', ')}) wrote part of this change, so none can review it independently. Sign in another seat, or start it again in reduced assurance (the authors review their own change, labelled on the run and every gate).`,
2908
+ excluded: ex.excludeSeats,
2909
+ retryWith: { reducedAssurance: true },
2910
+ });
2911
+ }
2912
+ input.clisJson = JSON.stringify(roster);
2913
+ input.excludeSeats = [...new Set([...(input.excludeSeats ?? []), ...excluded])];
2914
+ if (input.primary !== undefined) {
2915
+ const refusal = primaryRefusal(input.primary, input.clisJson);
2916
+ if (refusal !== null)
2917
+ return reply.code(400).send({ error: refusal });
2918
+ }
2919
+ }
2920
+ const lines = ex.briefLines.map((line) => b.reducedAssurance === true && line === ex.label
2921
+ ? "reduced assurance: the change's authors may review it" : line);
2922
+ // The workflow decoration below rebuilds input.problem from b.problem: retain these lines in both.
2923
+ b.problem = withBriefLines(stripLinkedIssues(b.problem), lines);
2924
+ input.problem = withBriefLines(input.problem, lines);
2925
+ if (ex.baseRef !== undefined)
2926
+ input.baseRef = ex.baseRef;
2927
+ reviewChange = { target: ex.target, provenance: ex.provenance, runs: ex.runs, excluded, headSha: ex.headSha };
2928
+ }
2611
2929
  // DES-L9 / crew#550 — REVISION: `revisesPr` names an OPEN same-repository pull request whose
2612
2930
  // head branch becomes the run's base (`baseRef`, crew-internal → the engine's
2613
2931
  // `LaunchSpec.base_ref`) and the push target of the composed deliver phase — the PR gains
@@ -2649,6 +2967,30 @@ runtime = {}) {
2649
2967
  });
2650
2968
  }
2651
2969
  }
2970
+ // (DES-CATALOG-002 §2.d piece 4, CS4) The source pick, checked at launch against the project's sources and their
2971
+ // "Agents can query" switches (the pick narrows the switches, never widens them), before anything is committed. A
2972
+ // retry or reshape that sends none keeps the earlier run's pick; a run without a pick reads what the switches allow.
2973
+ let sourcePick = null;
2974
+ // An inherited pick is checked like a sent one (the switches may have changed since the earlier run).
2975
+ const wantedPick = b.sources ?? (b.retryOf !== undefined ? (runtime.runSourcePicks?.get(b.retryOf) ?? undefined) : undefined);
2976
+ if (wantedPick !== undefined) {
2977
+ if (runtime.runSourcePicks === undefined || runtime.dataGate === undefined) {
2978
+ return reply.code(400).send({ code: 'sources_refused', error: 'this daemon cannot limit a run to picked sources' });
2979
+ }
2980
+ const checked = await checkSourcePick(b.projectId ?? null, wantedPick, runSourcesDeps(runtime.dataGate));
2981
+ if (!checked.ok) {
2982
+ return reply.code(400).send({
2983
+ code: 'sources_refused',
2984
+ error: `can't read ${checked.refused.map((r) => `${r.id} (${r.reason})`).join(', ')}`,
2985
+ refused: checked.refused,
2986
+ });
2987
+ }
2988
+ sourcePick = checked.ids;
2989
+ }
2990
+ // (DES-CATALOG-002 §2.d piece 2, CS4) The documents can be staged only where this daemon keeps them.
2991
+ if (b.documents !== undefined && b.documents.length > 0 && runtime.runDocumentsRoot === undefined) {
2992
+ return reply.code(400).send({ code: 'documents_refused', error: 'this daemon cannot stage documents for a run' });
2993
+ }
2652
2994
  // Ad-hoc campaign attach (wicked-studio#27): `campaignId` must name an EXISTING campaign,
2653
2995
  // checked BEFORE anything launches — an unknown id is a 404 with nothing committed, never a
2654
2996
  // run silently filed onto a surface that does not exist. An engine addon without the
@@ -2790,6 +3132,81 @@ runtime = {}) {
2790
3132
  return reply.code(409).send({ code: 'catalog_unavailable', error: message(err) });
2791
3133
  }
2792
3134
  }
3135
+ // (CS4) The pick is recorded before anything is staged and before the engine is called, so no unit of the run ever
3136
+ // runs without it (CS10's fence reads it) and a failed record leaves nothing behind. Fail closed: nothing launches.
3137
+ if (sourcePick !== null) {
3138
+ try {
3139
+ runtime.runSourcePicks.set(input.sessionId, sourcePick);
3140
+ }
3141
+ catch (err) {
3142
+ return reply.code(409).send({ code: 'sources_unavailable', error: `the source pick could not be recorded: ${message(err)}` });
3143
+ }
3144
+ }
3145
+ // (DES-CATALOG-002 §2.d piece 2, CS4) The documents: every token authorised again with the chat's own rules (this
3146
+ // chat, its project, the document's version now) and staged whole, read-only, in the run's own folder outside the
3147
+ // state home; a retry or reshape that sends none reuses the earlier run's staged folder (hash-checked). The folder
3148
+ // is a READ root only: the run can read its documents and never write there. The brief says where they are.
3149
+ let staged = null;
3150
+ // What to stage: the documents sent, or (a retry that sends none) the earlier run's tokens under the earlier run's
3151
+ // chat, authorised again now; never the earlier folder mounted as it is. `[]` = none, inherit nothing.
3152
+ let docTokens = null;
3153
+ if (b.documents !== undefined) {
3154
+ if (b.documents.length > 0 && b.chatId !== undefined)
3155
+ docTokens = { chatId: b.chatId, tokens: b.documents };
3156
+ }
3157
+ else if (b.retryOf !== undefined && runtime.runDocumentsRoot !== undefined) {
3158
+ const earlier = stagedTokensOf(b.retryOf, runtime.runDocumentsRoot);
3159
+ if (earlier === 'unreadable') {
3160
+ return reply.code(409).send({ code: 'documents_unavailable', error: `the documents of run ${b.retryOf} can't be read again; start the job again from its chat` });
3161
+ }
3162
+ if (earlier !== null)
3163
+ docTokens = earlier;
3164
+ }
3165
+ if (docTokens !== null && runtime.runDocumentsRoot !== undefined) {
3166
+ // The documents are the chat's: a run filed in another project never reads them.
3167
+ const chatProject = chatProposalsProjectOf(docTokens.chatId);
3168
+ const runProject = b.projectId !== undefined && b.projectId !== DEFAULT_PROJECT_ID ? b.projectId : null;
3169
+ if ((chatProject ?? null) !== runProject) {
3170
+ // A bare retry sends no projectId: it is filed Unfiled, so it is told where its documents belong (fail closed).
3171
+ return reply.code(400).send({
3172
+ code: 'documents_refused',
3173
+ error: chatProject !== null && runProject === null
3174
+ ? `the documents belong to project ${chatProject}: file this run there (send projectId)`
3175
+ : "the documents belong to the chat's project, and this run is filed in another",
3176
+ });
3177
+ }
3178
+ try {
3179
+ staged = await stageRunDocuments(input.sessionId, docTokens.chatId, docTokens.tokens, {
3180
+ authorize: (chatId, tokens) => chatProposals.authorizeDocuments(chatId, tokens),
3181
+ attachment: (chatId, id) => {
3182
+ // An attachment the store no longer has is "no longer attached", not a 500 (resolve throws for an unknown id).
3183
+ try {
3184
+ const hit = chatAttachments.resolve(chatId, [id])[0];
3185
+ return hit === undefined ? null : { name: hit.name, path: hit.path };
3186
+ }
3187
+ catch {
3188
+ return null;
3189
+ }
3190
+ },
3191
+ docsRoot: (projectId) => projectDocsRoot(adapter, projectSettings, projectId),
3192
+ stateRoot: runtime.runDocumentsRoot,
3193
+ });
3194
+ }
3195
+ catch (err) {
3196
+ if (err instanceof DocumentsRefused) {
3197
+ return reply.code(400).send({
3198
+ code: 'documents_refused',
3199
+ error: `can't read ${err.refused.map((r) => `${r.token} (${r.reason})`).join(', ')}`,
3200
+ refused: err.refused,
3201
+ });
3202
+ }
3203
+ return reply.code(409).send({ code: 'documents_unavailable', error: `the documents could not be staged: ${message(err)}` });
3204
+ }
3205
+ }
3206
+ if (staged !== null) {
3207
+ input.extraReadRoots = [...(input.extraReadRoots ?? []), staged.root];
3208
+ input.problem = `${input.problem.trimEnd()}\n\n${documentsClause(staged)}`;
3209
+ }
2793
3210
  try {
2794
3211
  const runId = await adapter.launchRun(input);
2795
3212
  // crew#641/#642 (item 5): when a run is promoted from a chat, record how many seats
@@ -2843,6 +3260,7 @@ runtime = {}) {
2843
3260
  // DES-L9: the revised PR (number, head branch, URL) — the retry index (and a restarted
2844
3261
  // daemon's hydrate) reads it back from here so a stranded revision re-pushes to THAT PR.
2845
3262
  ...(revisesPr !== undefined ? { revisesPr, baseRef: revisesPr.headRef } : {}),
3263
+ ...(reviewChange !== undefined ? { reviewChange } : {}),
2846
3264
  // wicked-studio#27: the trail is likewise the durable record of the group attach —
2847
3265
  // the group index (and a restarted daemon's hydrate) reads it back from here.
2848
3266
  ...(b.campaignId !== undefined ? { campaignId: b.campaignId } : {}),
@@ -3027,17 +3445,56 @@ runtime = {}) {
3027
3445
  /**
3028
3446
  * (DES-CATALOG-002 §4.6) The `job` launcher: a chat job proposal's Go, one launcher per launch kind, each with the
3029
3447
  * identity derived from the proposal (`sessionId` = its run id, so a retry finds and adopts it), the chat filing, the
3030
- * shape, and the plan held (a repository job launched from a chat always stops at its first plan, whatever the
3031
- * person's posture, so power mode is off for it).
3448
+ * shape, and the plan held: a job launched from a chat stops at its first plan unless the person's Start chose a
3449
+ * power run (`power: true`, api-types 0.196.0), which is refused unless this daemon can run that job as one.
3032
3450
  */
3033
3451
  const jobRefusalText = (payload) => {
3034
3452
  const b = payload;
3035
3453
  return `${typeof b?.error === 'string' ? b.error : 'the launch was refused'}${typeof b?.code === 'string' ? ` (${b.code})` : ''}`;
3036
3454
  };
3455
+ /**
3456
+ * (operator ruling 2026-11-06) Why a chat job can't run as a power run on this daemon now, else `null`: only a
3457
+ * workflow run on a repository whose workflow is a preset, on an engine with power mode (launchRun's own rule, which
3458
+ * would otherwise run it phased and only say so), with Power mode for new jobs on (chat starts follow the setting).
3459
+ */
3460
+ const chatJobPowerRefusal = async (p) => {
3461
+ const askPlan = 'press Start with Review plan on';
3462
+ if (p.launch !== 'run' && p.launch !== undefined)
3463
+ return `${p.what.label} can't run as a power run; ${askPlan}`;
3464
+ if (p.repoRefs?.[0] === undefined)
3465
+ return `a power run works on a repository, and this job names none; ${askPlan}`;
3466
+ if (!powerSupported())
3467
+ return `this daemon's engine has no power mode; ${askPlan}`;
3468
+ // The operator ruling: chat starts follow the Power-mode default; with it off, a chat job reviews its plan.
3469
+ try {
3470
+ if (((await adapter.getSettings()).powerModeDefault ?? true) === false)
3471
+ return `Power mode for new jobs is off on this daemon; ${askPlan}`;
3472
+ }
3473
+ catch (err) {
3474
+ return `the Power-mode setting could not be read (${err instanceof Error ? err.message : String(err)}); press Start again`;
3475
+ }
3476
+ if (p.shape === undefined)
3477
+ return `this proposal has no shape to launch; ${askPlan}`;
3478
+ const projectId = p.filedIn.projectId;
3479
+ let served;
3480
+ try {
3481
+ served = await servedFor(shapeReads, projectId ?? undefined);
3482
+ }
3483
+ catch (err) {
3484
+ return `${err instanceof Error ? err.message : String(err)}; press Start again`;
3485
+ }
3486
+ const resolved = resolveOption(p.shape.card, p.shape.option, served);
3487
+ if (resolved === null || resolved.workflow === null)
3488
+ return `${p.what.label} has no workflow to run; ${askPlan}`;
3489
+ const scoped = projectId !== null && projectId !== DEFAULT_PROJECT_ID ? projectId : undefined;
3490
+ if (!(await namesPreset(resolved.workflow, scoped)))
3491
+ return `${p.what.label} can't run as a power run (its workflow is not a preset); ${askPlan}`;
3492
+ return null;
3493
+ };
3037
3494
  proposalLaunchers.register('job', {
3038
3495
  find: async (identity) => (await adapter.sessions()).includes(identity.runId),
3039
3496
  live: async (runId) => {
3040
- const v = (await adapter.sessionsDetail()).find((x) => x.session.id === runId);
3497
+ const v = await adapter.runView(runId);
3041
3498
  return v !== undefined && !['completed', 'cancelled', 'failed'].includes(String(v.session.status));
3042
3499
  },
3043
3500
  launch: async (d) => {
@@ -3078,6 +3535,12 @@ runtime = {}) {
3078
3535
  ...((inherited !== null || narrowed.length !== roster.length) && narrowed.length > 0 ? { clisJson: JSON.stringify(narrowed) } : {}),
3079
3536
  selfSeated,
3080
3537
  });
3538
+ // A power Start was checked before accepting; checked again here, so it never runs phased behind the person's back.
3539
+ if (d.power === true) {
3540
+ const why = await chatJobPowerRefusal(p);
3541
+ if (why !== null)
3542
+ throw new Error(why);
3543
+ }
3081
3544
  if (p.launch === 'run' || p.launch === undefined) {
3082
3545
  if (resolved.workflow === null)
3083
3546
  throw new Error(`${p.what.label} has no workflow to run`);
@@ -3088,14 +3551,19 @@ runtime = {}) {
3088
3551
  ...(p.repoRefs?.[0] !== undefined ? { repoRef: p.repoRefs[0] } : {}),
3089
3552
  ...(projectId !== null && projectId !== DEFAULT_PROJECT_ID ? { projectId } : {}),
3090
3553
  ...common,
3554
+ // (CS4) The documents and the source pick, as tokens and names (never flattened into the brief's prose).
3555
+ ...jobInputsOfProposal(p, runtime.runSourcePicks !== undefined ? (runId) => runtime.runSourcePicks.get(runId) : undefined),
3556
+ // A power run when the person's Start chose one (checked against this daemon just now); otherwise it
3557
+ // stops at its first plan, as every chat job did before (operator ruling 2026-11-06).
3558
+ // (A power launch overrides the plan hold; launchRun refuses rather than run it phased, `powerRequired`.)
3091
3559
  humanConfirm: 'before:1',
3092
- power: false,
3560
+ power: d.power === true,
3093
3561
  channel: 'studio',
3094
3562
  // §2.5: a reshape's replacement keeps the held run's delivery and grouping.
3095
3563
  ...(p.relaunch?.deliver !== undefined ? { deliver: p.relaunch.deliver } : {}),
3096
3564
  ...(p.relaunch?.deliverGate !== undefined && p.relaunch.deliver !== 'none' ? { deliverGate: p.relaunch.deliverGate } : {}),
3097
3565
  ...(p.relaunch?.revisesPr !== undefined && p.relaunch.deliver === 'pr' && p.repoRefs?.[0] !== undefined ? { revisesPr: p.relaunch.revisesPr } : {}),
3098
- }, { ...ctx, fromProposal: d.pid });
3566
+ }, { ...ctx, fromProposal: d.pid, ...(d.power === true ? { powerRequired: true } : {}) });
3099
3567
  if (out.statusCode !== 201)
3100
3568
  throw new Error(jobRefusalText(out.payload));
3101
3569
  return;
@@ -3125,7 +3593,7 @@ runtime = {}) {
3125
3593
  const out = await demoLaunch(launchRun, projectId ?? DEFAULT_PROJECT_ID, { url: v('url') ?? '', audience: v('audience') ?? '', show, shape: common['shape'] }, ctx, {
3126
3594
  fromProposal: d.pid,
3127
3595
  common,
3128
- });
3596
+ }, demoDeps);
3129
3597
  if (out.code !== 201)
3130
3598
  throw new Error(jobRefusalText(out.body));
3131
3599
  return;
@@ -3235,14 +3703,15 @@ runtime = {}) {
3235
3703
  // are one step, so a gate answered at the same moment can never be stopped by a resolve. The
3236
3704
  // status is read again inside the lock, right before the stop.
3237
3705
  const outcome = await decideExclusively(id, async () => {
3238
- const views = await adapter.sessionsDetail();
3239
- const run = views.find((v) => v.session.id === id);
3706
+ // The replacement is looked up first, so the run's own status is the last read before the stop.
3707
+ const byKnown = b.action === 'superseded' && b.by !== id ? (await adapter.runView(b.by)) !== undefined : true;
3708
+ const run = await adapter.runView(id);
3240
3709
  if (run === undefined)
3241
3710
  return { code: 404, body: { error: 'Run not found' } };
3242
3711
  if (b.action === 'superseded') {
3243
3712
  if (b.by === id)
3244
3713
  return { code: 400, body: { error: '`by` must name another run' } };
3245
- if (!views.some((v) => v.session.id === b.by))
3714
+ if (!byKnown)
3246
3715
  return { code: 400, body: { error: `\`by\` names an unknown run: ${b.by}` } };
3247
3716
  }
3248
3717
  const status = run.session.status;
@@ -3296,8 +3765,7 @@ runtime = {}) {
3296
3765
  // One run's detail.
3297
3766
  app.get(`${V}/runs/:id`, { config: { manifest: { responseType: '{ run: SessionView }', statusCodes: [200, 404] } } }, async (req, reply) => {
3298
3767
  const { id } = req.params;
3299
- const views = await adapter.sessionsDetail();
3300
- const run = views.find((v) => v.session.id === id);
3768
+ const run = await adapter.runView(id);
3301
3769
  if (!run)
3302
3770
  return reply.code(404).send({ error: 'Run not found' });
3303
3771
  await settleDeliveries([run]);
@@ -3326,8 +3794,7 @@ runtime = {}) {
3326
3794
  // is the run's open gate. Read-only.
3327
3795
  app.get(`${V}/governance/steering/author/:runId/draft`, { config: { manifest: { responseType: 'SteeringDraftResponse', statusCodes: [200, 404, 500] } } }, async (req, reply) => {
3328
3796
  const { runId } = req.params;
3329
- const views = await adapter.sessionsDetail();
3330
- const run = views.find((v) => v.session.id === runId);
3797
+ const run = await adapter.runView(runId);
3331
3798
  if (!run)
3332
3799
  return reply.code(404).send({ error: 'Run not found' });
3333
3800
  if (!isSteeringAuthorRun(run))
@@ -3360,8 +3827,7 @@ runtime = {}) {
3360
3827
  },
3361
3828
  }, async (req, reply) => {
3362
3829
  const { id } = req.params;
3363
- const views = await adapter.sessionsDetail();
3364
- const run = views.find((v) => v.session.id === id);
3830
+ const run = await adapter.runView(id);
3365
3831
  if (!run)
3366
3832
  return reply.code(404).send({ error: 'Run not found' });
3367
3833
  if (typeof adapter.workOutput !== 'function') {
@@ -3410,8 +3876,7 @@ runtime = {}) {
3410
3876
  // asks, and is listed as `this PR`.
3411
3877
  app.get(`${V}/runs/:id/deliver-text`, { config: { manifest: { statusCodes: [200, 404] } } }, async (req, reply) => {
3412
3878
  const { id } = req.params;
3413
- const views = await adapter.sessionsDetail();
3414
- const run = views.find((v) => v.session.id === id);
3879
+ const run = await adapter.runView(id);
3415
3880
  if (!run)
3416
3881
  return reply.code(404).send({ error: 'Run not found' });
3417
3882
  const followUps = await evaluatorFollowUps(run);
@@ -3498,8 +3963,7 @@ runtime = {}) {
3498
3963
  if (pushedAlready !== undefined) {
3499
3964
  return reply.code(409).send({ error: pushedOnlyRefusal(id, pushedAlready) });
3500
3965
  }
3501
- const views = await adapter.sessionsDetail();
3502
- const run = views.find((v) => v.session.id === id);
3966
+ const run = await adapter.runView(id);
3503
3967
  if (!run)
3504
3968
  return reply.code(404).send({ error: 'Run not found' });
3505
3969
  // Freeze deliveries (idea 15): nothing pushes while the switch is on.
@@ -3553,6 +4017,11 @@ runtime = {}) {
3553
4017
  let result;
3554
4018
  let codebase;
3555
4019
  let worktreeGone = false;
4020
+ // CS11 (cs11-b review P1): the delivered HEAD of the run branch, captured INSIDE the per-repo
4021
+ // deliver lock below — before the lock is released and `deliverInFlight` cleared — so no
4022
+ // concurrent delivery can move `wicked/<id>` between the push and the read. `undefined` records
4023
+ // the delivery without a commit (the review-change join then keeps the run, fail-closed).
4024
+ let deliveredCommit;
3556
4025
  // DES-L9: a stranded REVISION re-pushes onto its PR's branch (re-checked OPEN via the same
3557
4026
  // resolver), never a new PR; a PR that closed meanwhile is a named 409.
3558
4027
  let revisionRefused;
@@ -3625,6 +4094,17 @@ runtime = {}) {
3625
4094
  // Best-effort: the archive store logs its own failures; a lookup that threw leaves none.
3626
4095
  }
3627
4096
  }
4097
+ // CS11 (cs11-b review P1): read the delivered HEAD of the run branch HERE — still under the
4098
+ // per-repo deliver lock, right after the script's verdict, before the lock releases and
4099
+ // `deliverInFlight` is cleared. The branch lives in the repo root (not this possibly-
4100
+ // throwaway worktree), so a `repoRootOf` read is correct even after `cw` is torn down; the
4101
+ // point is the LOCK, which keeps `wicked/<id>` from moving between the push and this read.
4102
+ if (result !== undefined && result.status === 0) {
4103
+ const deliveredRoot = await repoRootOf(repoRef).catch(() => undefined);
4104
+ if (deliveredRoot !== undefined) {
4105
+ deliveredCommit = (await readDeliveredCommit(deliveredRoot, s.run_branch ?? `wicked/${id}`)) ?? undefined;
4106
+ }
4107
+ }
3628
4108
  }
3629
4109
  finally {
3630
4110
  if (cw !== null)
@@ -3672,6 +4152,11 @@ runtime = {}) {
3672
4152
  const record = deliveryRecordFrom(result.output);
3673
4153
  const url = record !== null && 'url' in record ? record.url : null;
3674
4154
  const pushedOnly = record !== null && 'pushed' in record ? record.pushed : null;
4155
+ // A post-hoc push also needs its delivered head for later reviews' ancestry checks. CS11
4156
+ // (cs11-b review P1): use the SHA captured inside the delivery lock above — not a fresh read
4157
+ // here, after the lock released and `deliverInFlight` was cleared, where a concurrent delivery
4158
+ // could have moved the branch. No delivery to record (`record === null`) attaches no commit.
4159
+ const commit = record === null ? undefined : deliveredCommit;
3675
4160
  // wicked-core#850 EX-04: no engine lift re-verified what this pushed — the run record says so,
3676
4161
  // with the trees the script named (the PR body carries the same label). Built before the
3677
4162
  // outcome branches, so a push-only delivery records it too (codex r1).
@@ -3680,8 +4165,8 @@ runtime = {}) {
3680
4165
  // N1: the script pushed the branch and gh could resolve no GitHub repository for the
3681
4166
  // origin. That IS a delivery — record it, so the run reads `delivery: 'pushed'` — but there
3682
4167
  // is no PR URL to answer with, so the reply says what happened instead of a 200 `prUrl`.
3683
- audit.record('run.delivered', actorOf(req), { runId: id, detail: { pushed: pushedOnly, via: 'post-hoc', assurance } });
3684
- deliveryIndex.setPushed(id, pushedOnly, assurance);
4168
+ audit.record('run.delivered', actorOf(req), { runId: id, detail: { pushed: pushedOnly, via: 'post-hoc', assurance, ...(commit !== undefined ? { commit } : {}) } });
4169
+ deliveryIndex.setPushed(id, pushedOnly, assurance, commit);
3685
4170
  return reply.code(409).send({ error: pushedOnlyRefusal(id, pushedOnly) });
3686
4171
  }
3687
4172
  if (url === null) {
@@ -3693,8 +4178,8 @@ runtime = {}) {
3693
4178
  }
3694
4179
  // The durable record first, then the read-side index — the same write order as the
3695
4180
  // deliver-phase resolution in server.ts, so the index can only LAG a crash, never lead it.
3696
- audit.record('run.delivered', actorOf(req), { runId: id, detail: { url, via: 'post-hoc', assurance, ...(codebase !== undefined ? { codebase } : {}) } });
3697
- deliveryIndex.set(id, url, assurance);
4181
+ audit.record('run.delivered', actorOf(req), { runId: id, detail: { url, via: 'post-hoc', assurance, ...(commit !== undefined ? { commit } : {}), ...(codebase !== undefined ? { codebase } : {}) } });
4182
+ deliveryIndex.set(id, url, assurance, commit);
3698
4183
  return { prUrl: url, assurance, ...(codebase !== undefined ? { codebase } : {}) };
3699
4184
  });
3700
4185
  // Durable pre-gate guidance (DES-UX-002 §7.2 — spec'd there as CREW-UX-4, implemented as
@@ -3768,6 +4253,8 @@ runtime = {}) {
3768
4253
  /** The seeded chat's person-made proposal (`POST /chats {seed}`), made or found by its request id. */
3769
4254
  const seedProposal = async (chatId, seed, requestId, actor) => {
3770
4255
  const instance = chatHistory?.stateOf(chatId)?.instance ?? null;
4256
+ // The chat is live and may have no turn yet (a new chat's seed always has none): its proposal starts the transcript.
4257
+ chatTranscripts?.start(chatId);
3771
4258
  const out = await chatProposals.propose(chatId, seedBody(seed, requestId), actor, instance);
3772
4259
  if (out.code >= 300) {
3773
4260
  const b = out.body;
@@ -3819,7 +4306,7 @@ runtime = {}) {
3819
4306
  // A retry: this request's chat exists (open, or kept in history after a close or a restart). Answer it and its
3820
4307
  // proposal, completing the proposal while the chat is open; never open the id again (codex r1).
3821
4308
  const open = askPaths.get(seedChatId) !== undefined || chatScopes.get(seedChatId) !== undefined;
3822
- if (open || chatHistory?.stateOf(seedChatId) !== undefined) {
4309
+ if (open || chatHistory?.has(seedChatId) === true) {
3823
4310
  let view = chatProposals.viewOfPid(seedChatId, personPid(seedChatId, seedActor.id, b.requestId));
3824
4311
  // The same request id with another seed is not a retry (codex r2).
3825
4312
  if (view !== null && view.proposal.request?.digest !== requestDigest(seedBody(b.seed, b.requestId))) {
@@ -3835,8 +4322,9 @@ runtime = {}) {
3835
4322
  }
3836
4323
  }
3837
4324
  const chatId = seedChatId ?? b.chatId ?? randomUUID();
3838
- if (b.accepts !== undefined)
3839
- chatAccepts.set(chatId, b.accepts.includes('job'));
4325
+ // A new chat's declaration is its own (an omitted one is "no job cards"): an id reused after a close never inherits
4326
+ // the previous chat's (codex r2 on Lane D).
4327
+ const openAccepts = b.accepts?.includes('job') === true;
3840
4328
  const requestedRefs = [...(b.repoRef !== undefined ? [b.repoRef] : []), ...(b.repoRefs ?? [])];
3841
4329
  // The scope kind as the open resolves it: the request's, unless an Ask-about-this seed names the repositories.
3842
4330
  let scopeKind = b.scopeKind;
@@ -3955,7 +4443,7 @@ runtime = {}) {
3955
4443
  return reply.code(resolved.status).send({ error: resolved.error });
3956
4444
  workflow = resolved.workflow;
3957
4445
  }
3958
- const statementOpts = { analysis: workflow !== undefined, make: chatProposals.digest() };
4446
+ const statementOpts = { analysis: workflow !== undefined, make: chatProposals.digest(chatId, openAccepts, { appearance: false }) };
3959
4447
  // A chat id this daemon already holds a scope for is LIVE: re-preparing its scratch root and
3960
4448
  // re-opening it would overwrite the statement its seats are reading and (on a changed scope)
3961
4449
  // evict them mid-conversation (Copilot, #518). Close it first, or let the daemon mint the id.
@@ -3970,6 +4458,9 @@ runtime = {}) {
3970
4458
  : `chat ${chatId} is already open on this daemon; DELETE /chats/${chatId} first, or omit chatId to mint a fresh one`,
3971
4459
  });
3972
4460
  }
4461
+ // DES-CATALOG-002 §4.6: this open owns the id now: its declaration is the chat's (an omitted one is "no job cards").
4462
+ // A refused open (409 above) never touched the live chat's (codex r3).
4463
+ chatAccepts.set(chatId, openAccepts);
3973
4464
  // DC-S7: the in-force rules the statement lists; recorded as "told" only once the open succeeds.
3974
4465
  let inForceAtOpen = [];
3975
4466
  // Everything below either ends in `chatScopes.set(chatId, …, token)` or releases the reservation.
@@ -4263,7 +4754,7 @@ runtime = {}) {
4263
4754
  */
4264
4755
  const reshapeEligibility = async (runId) => {
4265
4756
  const after = (why) => ({ refusal: { code: 409, body: { code: 'reshape_after_work', error: `run ${runId} ${why}: change it with the plan's own edit, or start a new job` } } });
4266
- const run = (await adapter.sessionsDetail()).find((v) => v.session.id === runId);
4757
+ const run = await adapter.runView(runId);
4267
4758
  if (run === undefined)
4268
4759
  return { refusal: { code: 404, body: { error: 'Run not found' } } };
4269
4760
  if (run.session.status !== 'awaiting_human')
@@ -4280,15 +4771,43 @@ runtime = {}) {
4280
4771
  return { ord: held.gated.ord, planRev };
4281
4772
  };
4282
4773
  /** The held plan answered Reject (`reshaped`) for a reshape, bound to the ord and revision just read. */
4283
- const reshapeReject = async (runId, actor, pid) => {
4774
+ const reshapeReject = async (runId, actor, pid, expect) => {
4284
4775
  const elig = await reshapeEligibility(runId);
4285
4776
  if ('refusal' in elig)
4286
4777
  return elig.refusal;
4778
+ // A reshape offered on one plan version answers only that version (Lane D, codex r1): a plan revised since is
4779
+ // gate_changed, and the engine checks the same expectation inside its decision.
4780
+ if (expect !== undefined && (expect.ord !== elig.ord || expect.planRev !== elig.planRev)) {
4781
+ return { code: 409, body: { code: 'gate_changed', error: `run ${runId}'s plan changed since this was offered (now version ${elig.planRev}); look at it again`, openOrd: elig.ord, planRev: elig.planRev } };
4782
+ }
4287
4783
  const out = await decideGate(runId, { approve: false, action: 'reject', amend: 'reshaped', ord: elig.ord, planRev: elig.planRev }, actor, { reshape: pid });
4288
4784
  return out.code === 200 ? null : { code: out.code, body: (out.body ?? {}) };
4289
4785
  };
4290
4786
  const chatProposals = new ChatProposals({
4291
4787
  flags: () => chatArtifactFlags,
4788
+ // (DES-CATALOG-002 §2.d piece 4, CS4) The sources a job's pick lists: the project's sources with their switches.
4789
+ ...(runtime.dataGate !== undefined && runtime.runSourcePicks !== undefined
4790
+ ? {
4791
+ jobSources: (projectId) => projectSources(projectId, runSourcesDeps(runtime.dataGate)),
4792
+ webReason: (projectId) => webScopeReason(projectId, {
4793
+ scopedElsewhere: (p) => runtime.dataGate.webScopedElsewhere(p),
4794
+ projectName: async (id) => (await adapter.projectGet(id).catch(() => null))?.name ?? null,
4795
+ }),
4796
+ }
4797
+ : {}),
4798
+ // A5 (DES §6.1-6.2): the person's own edits a refine keeps, from the document's lineage (fail closed: an error
4799
+ // blocks the card, since the landing guard could never pass). Only where a real refine can run.
4800
+ ...(runtime.docBindings !== undefined && runtime.launchBoundRefine !== undefined ? { protectedEdits: async (artifactRef, version, touch) => {
4801
+ const ref = parseArtifactRef(artifactRef);
4802
+ const root = ref === null ? null : await projectDocsRoot(adapter, projectSettings, ref.projectId);
4803
+ if (ref === null || root === null)
4804
+ return { ok: false, error: 'the document is not on this daemon' };
4805
+ const steps = lineageSteps(root, ref.doc, version, (runId) => runtime.docBindings?.allowOf(runId) ?? []);
4806
+ if (steps === null)
4807
+ return { ok: false, error: `its versions up to v${version} could not be read` };
4808
+ const mapped = await protectedEdits(steps, touch);
4809
+ return mapped.ok ? { ok: true, entries: mapped.entries } : mapped;
4810
+ } } : {}),
4292
4811
  catalog: CATALOG_SEEDS,
4293
4812
  records: (chatId) => chatHistory?.messages(chatId) ?? chatTranscripts?.read(chatId) ?? [],
4294
4813
  append: (chatId, record) => {
@@ -4311,9 +4830,7 @@ runtime = {}) {
4311
4830
  analysis: path?.workflow !== undefined,
4312
4831
  };
4313
4832
  },
4314
- rosterEligible: () => rosterWithStanding()
4315
- .filter((s) => s.enabled_for_council && s.seat_eligible_for_work !== false && s.auth !== 'signed_out' && s.optIn !== true)
4316
- .map((s) => ({ key: String(s.key), name: s.display_name || String(s.key) })),
4833
+ rosterEligible: () => proposalRoster(rosterWithStanding()),
4317
4834
  runs: async () => (await adapter.sessionsDetail()).map((v) => decorateRun(v)),
4318
4835
  chatOfRun: (runId) => runTimingIndex.chatIdFor(runId),
4319
4836
  isAskPath: (runId) => runTimingIndex.isAskPath(runId),
@@ -4336,6 +4853,25 @@ runtime = {}) {
4336
4853
  // DES-CATALOG-002 §4.6: job proposals, resolved against the catalog a launch in the chat's project reads.
4337
4854
  jobs: () => chatJobProposalsOn,
4338
4855
  reshapeReject,
4856
+ // DES-CATALOG-002 §2.4: a chat job's run as typed plan edits read it (held at a plan gate, its ord and revision).
4857
+ heldPlan: async (runId) => {
4858
+ const run = await adapter.runView(runId);
4859
+ if (run === undefined)
4860
+ return null;
4861
+ if (['completed', 'failed', 'cancelled'].includes(String(run.session.status)))
4862
+ return { state: 'ended' };
4863
+ if (run.session.status !== 'awaiting_human')
4864
+ return { state: 'running' };
4865
+ const held = await gateOfRecord(run, undefined);
4866
+ if ('refusal' in held || held.gateKind !== 'plan_approval' || held.gated === undefined)
4867
+ return { state: 'running' };
4868
+ const rows = await busRows(adapter.busDbPath, runId);
4869
+ const planRev = openPlanGateRev(rows);
4870
+ if (planRev === undefined)
4871
+ return { state: 'running' };
4872
+ const lead = run.session.primary;
4873
+ return { state: 'held', ord: held.gated.ord, planRev, reshapeable: !workPlanAccepted(rows), lead: typeof lead === 'string' ? lead : null };
4874
+ },
4339
4875
  preflight: async (p) => {
4340
4876
  // The project it files into still takes runs: an archived one refuses every new attachment (codex r6).
4341
4877
  if (p.filedIn.projectId !== null && p.filedIn.projectId !== DEFAULT_PROJECT_ID) {
@@ -4370,6 +4906,20 @@ runtime = {}) {
4370
4906
  return composePreflight(adapter, p.filedIn.projectId, req.refs, steer === '' ? undefined : steer);
4371
4907
  },
4372
4908
  qeOff: async () => addonSupportsQeOverride() && (await qeAcceptanceNow()) === 'off',
4909
+ powerRefusal: chatJobPowerRefusal,
4910
+ reviewAuthors: async (repoRef, words) => {
4911
+ const root = await repoRootOf(repoRef);
4912
+ if (root === undefined)
4913
+ return null;
4914
+ const ex = await reviewChangeExclusion(words, reviewChangeDeps(repoRef, root));
4915
+ return ex.ok ? ex.excludeSeats : null;
4916
+ },
4917
+ powerPresets: async (projectId) => {
4918
+ if (!powerSupported() || ((await adapter.getSettings()).powerModeDefault ?? true) === false || typeof adapter.listPresets !== 'function')
4919
+ return null;
4920
+ // The launch's own source (namesPreset): this project's presets, else the global ones.
4921
+ return new Set((await adapter.listPresets(projectId !== null && projectId !== DEFAULT_PROJECT_ID ? projectId : undefined)).map((p) => p.name));
4922
+ },
4373
4923
  acceptsJobs: (chatId) => chatAccepts.get(chatId) === true,
4374
4924
  served: (projectId) => servedFor(shapeReads, projectId ?? undefined),
4375
4925
  turnLive: (chatId, turnId) => chatTurns.turnsOf(chatId).some((t) => t.turnId === turnId),
@@ -4392,8 +4942,6 @@ runtime = {}) {
4392
4942
  if (!parsed.success) {
4393
4943
  return reply.code(400).send(invalidBody(parsed.error, 'Invalid request body'));
4394
4944
  }
4395
- if (parsed.data.accepts !== undefined)
4396
- chatAccepts.set(id, parsed.data.accepts.includes('job'));
4397
4945
  // DES-ASK-TEAM-CHAT-001 §3, §5.1 (ASK-C1): the first message of a chat LAUNCHES one team path
4398
4946
  // — a user-composed plan of one `understand` step with its gate raised to the turn gate, one
4399
4947
  // reviewer asked for, the eligible roster as `clis`, the operator's choice as `primary`; every
@@ -4478,6 +5026,10 @@ runtime = {}) {
4478
5026
  // logged, never a retraction of a turn that is already being answered (codex on #808 r2, 9).
4479
5027
  const persistAccepted = (preface, after) => {
4480
5028
  try {
5029
+ // DES-CATALOG-002 §4.6: the client's declaration takes effect with an ACCEPTED message only (a refused one, a
5030
+ // second tab's 409, never changes how a turn in flight is read; codex r2 on Lane D).
5031
+ if (parsed.data.accepts !== undefined)
5032
+ chatAccepts.set(id, parsed.data.accepts.includes('job'));
4481
5033
  after();
4482
5034
  if (preface !== null)
4483
5035
  chatTranscripts?.appendSystem(id, turnId, preface);
@@ -4543,7 +5095,7 @@ runtime = {}) {
4543
5095
  return reply.code(409).send({ error: `chat '${id}' was closed while the message was in flight; nothing was sent` });
4544
5096
  }
4545
5097
  if (path.runId !== undefined) {
4546
- const view = (await adapter.sessionsDetail()).find((v) => v.session.id === path.runId);
5098
+ const view = await adapter.runView(path.runId);
4547
5099
  if (view === undefined) {
4548
5100
  askPaths.release(id, lease);
4549
5101
  return reply.code(409).send({ error: `chat '${id}': its path ${path.runId} is gone — open a new chat` });
@@ -4587,6 +5139,15 @@ runtime = {}) {
4587
5139
  });
4588
5140
  }
4589
5141
  const pending = await considerations.pendingPreface(id, { inForce: rules });
5142
+ // A7: a seat is told it can propose a studio theme only when this message carried the tab's appearance (a client
5143
+ // that can preview and apply one sends it).
5144
+ const themeClient = { appearance: msgContext?.appearance !== undefined };
5145
+ // DES-CATALOG-002 §2.3, §4.6: the per-message job lines (the chat catalog digest, the open proposal, the held plan),
5146
+ // read here, before the last check (no await after it). Never in an analysis.
5147
+ // The declaration this message's instructions are written for: its own, else the chat's (applied to the chat only
5148
+ // once the message is accepted; the reply to this turn is read the same way, codex r3).
5149
+ const turnAccepts = parsed.data.accepts !== undefined ? parsed.data.accepts.includes('job') : chatAccepts.get(id) === true;
5150
+ const jobTurn = path.workflow === undefined ? await chatProposals.jobTurn(id, turnAccepts).catch(() => null) : null;
4590
5151
  // DES-CHAT-ARTIFACTS-001 §5.1 (A1): the turn's block — scope checked before anything is read or copied; the
4591
5152
  // copies and briefs land in the scratch root's `open/` and `context/`, read roots of the chat's run.
4592
5153
  // Built in memory here (it awaits); its files are written only after the last check below, with no await between.
@@ -4612,6 +5173,10 @@ runtime = {}) {
4612
5173
  return reply.code(500).send({ error: `could not prepare what this message is about: ${message(err)}. Nothing was sent.` });
4613
5174
  }
4614
5175
  }
5176
+ // crew#1412: each repository's requirements map, read for this message (never fails the turn; published below).
5177
+ const requirementsBuilt = scope !== undefined
5178
+ ? await buildRequirementsMaps(scope, { listRepos: () => adapter.listRepos(), reader: adapter }).catch(() => [])
5179
+ : [];
4615
5180
  // The last await before delivery may also have closed/reopened the chat. From this check
4616
5181
  // through publication and the send there is no await, so no executing turn's files change.
4617
5182
  if (askPaths.get(id)?.generation !== lease || chatScopes.get(id) !== storedScope) {
@@ -4619,7 +5184,7 @@ runtime = {}) {
4619
5184
  }
4620
5185
  if (storedScope !== undefined && scope !== undefined && engine !== undefined &&
4621
5186
  (JSON.stringify(scope) !== JSON.stringify(storedScope) || JSON.stringify(engine) !== JSON.stringify(chatScopes.engineOf(id)))) {
4622
- prepareChatScratch(id, scope, rules, { analysis: path.workflow !== undefined, make: chatProposals.digest(), ...voiceFor(scope.projectId) });
5187
+ prepareChatScratch(id, scope, rules, { analysis: path.workflow !== undefined, make: chatProposals.digest(id, turnAccepts, themeClient), ...voiceFor(scope.projectId) });
4623
5188
  if (chatScopes.refresh(id, storedScope, scope, engine)) {
4624
5189
  chatTranscripts?.registerRoots(id, scope.repos.map((r) => ({ absRoot: resolve(r.rootPath), name: r.name })));
4625
5190
  }
@@ -4653,20 +5218,29 @@ runtime = {}) {
4653
5218
  seatText = `${seatText}\n\n${contextBlock}`;
4654
5219
  }
4655
5220
  // A2: the per-message digest of what the chat can make now (advertised operations only; never in an analysis).
4656
- const makeDigest = path.workflow === undefined ? chatMakeDigest(chatProposals.digest()) : '';
4657
- if (makeDigest !== '')
5221
+ const makeDigest = path.workflow === undefined ? chatMakeDigest(chatProposals.digest(id, turnAccepts, themeClient)) : '';
5222
+ // DES-CATALOG-002 §2.3: with job cards, the make digest rides INSIDE the job block, under its one 2 KB budget.
5223
+ if (jobTurn !== null && jobTurn.mode === 'cards') {
5224
+ seatText = `${seatText}\n\n${chatJobTurnLines(jobTurn.mode, { ...jobTurn.context, preface: makeDigest })}`;
5225
+ }
5226
+ else if (makeDigest !== '') {
5227
+ // An older client's message is today's (its statement lists the job commands).
4658
5228
  seatText = `${seatText}\n\n${makeDigest}`;
5229
+ }
4659
5230
  voice = path.pa !== null ? [path.pa] : [];
4660
5231
  // A random pick reserves every eligible seat until the relay names the PA.
4661
5232
  audience = voice.length > 0 ? voice : path.eligible;
4662
5233
  turn = chatTurns.begin(id, audience, text, ASK_TURN_BUDGET_SECS);
4663
5234
  turnId = turn?.turnId ?? turnId;
5235
+ chatProposals.noteTurnAccepts(id, turnId, turnAccepts);
4664
5236
  // A repo-bound path can deliver; project and multi-repo scopes remain read-only asks. A workflow
4665
5237
  // chat (crew#1157) never delivers: it is bound to its repository read-only, with no deliver.
4666
5238
  const repoRef = scope?.kind === 'repos' && scope.repos.length === 1 ? scope.repos[0].id : undefined;
4667
5239
  const delivers = repoRef !== undefined && path.workflow === undefined;
4668
5240
  // A2: the per-message digest of what the chat can make now (advertised operations only).
4669
- const statementOpts = { analysis: path.workflow !== undefined, make: chatProposals.digest(), ...voiceFor(scope?.projectId) };
5241
+ // crew#1412: written after the last await and the generation check; a map that cannot be written says so.
5242
+ const requirementsMaps = scope !== undefined ? publishRequirementsMaps(scope.cwd, requirementsBuilt) : [];
5243
+ const statementOpts = { analysis: path.workflow !== undefined, make: chatProposals.digest(id, turnAccepts, themeClient), requirementsMaps, ...voiceFor(scope?.projectId) };
4670
5244
  const projectId = scope?.projectId;
4671
5245
  if (path.runId === undefined) {
4672
5246
  const stepId = 'answer-1';
@@ -4751,7 +5325,7 @@ runtime = {}) {
4751
5325
  // The status read above is a pre-check that changes nothing; this read is the one that counts.
4752
5326
  const pathRunId = path.runId;
4753
5327
  const refused = await decideExclusively(pathRunId, async () => {
4754
- const view = (await adapter.sessionsDetail()).find((v) => v.session.id === pathRunId);
5328
+ const view = await adapter.runView(pathRunId);
4755
5329
  if (view === undefined || view.session.status !== 'awaiting_human') {
4756
5330
  return { code: 409, body: {
4757
5331
  code: 'turn_in_flight',
@@ -4816,6 +5390,9 @@ runtime = {}) {
4816
5390
  seats: z.array(z.string().min(1).max(64)).min(1).max(8).optional(),
4817
5391
  inputs: RevisionEditsSchema.shape.inputs,
4818
5392
  }).optional(),
5393
+ // (api-types 0.196.0, operator ruling 2026-11-06) a job's Start chooses how it runs: `true` = a power run (no plan
5394
+ // gate), `false` = it stops at its plan. Absent = it stops at its plan, as before.
5395
+ power: z.boolean().optional(),
4819
5396
  });
4820
5397
  /** (api-types 0.192.0) `POST /chats/:id/proposals`: a person-made proposal, or a revision of the open one. */
4821
5398
  const PersonProposalSchema = z.union([
@@ -4890,7 +5467,11 @@ runtime = {}) {
4890
5467
  const edits = parsed.data.edits === undefined
4891
5468
  ? undefined
4892
5469
  : Object.fromEntries(Object.entries(parsed.data.edits).filter(([, v]) => v !== undefined));
4893
- const out = await chatProposals.decide(id, pid, { decision: parsed.data.decision, ...(edits !== undefined ? { edits } : {}) }, actor, instance);
5470
+ const out = await chatProposals.decide(id, pid, {
5471
+ decision: parsed.data.decision,
5472
+ ...(edits !== undefined ? { edits } : {}),
5473
+ ...(parsed.data.power !== undefined ? { power: parsed.data.power } : {}),
5474
+ }, actor, instance);
4894
5475
  return reply.code(out.code).send(out.body);
4895
5476
  });
4896
5477
  const ChatSeatsSchema = z.strictObject({
@@ -5281,8 +5862,7 @@ runtime = {}) {
5281
5862
  });
5282
5863
  app.get(`${V}/runs/:id/units/:unitKey/output`, async (req, reply) => {
5283
5864
  const { id, unitKey } = req.params;
5284
- const views = await adapter.sessionsDetail();
5285
- const run = views.find((v) => v.session.id === id);
5865
+ const run = await adapter.runView(id);
5286
5866
  if (!run)
5287
5867
  return reply.code(404).send({ error: 'Run not found' });
5288
5868
  const unit = resolveUnit(run, unitKey);
@@ -5374,8 +5954,7 @@ runtime = {}) {
5374
5954
  // per-run event log — what actually happened, not a re-derivation of it.
5375
5955
  app.get(`${V}/runs/:id/evidence`, async (req, reply) => {
5376
5956
  const { id } = req.params;
5377
- const views = await adapter.sessionsDetail();
5378
- const run = views.find((v) => v.session.id === id);
5957
+ const run = await adapter.runView(id);
5379
5958
  if (!run)
5380
5959
  return reply.code(404).send({ error: 'Run not found' });
5381
5960
  const bundle = await buildEvidenceBundle(run, (unitId) => adapter.workOutput(unitId), (runId) => adapter.runEvents(runId));
@@ -5399,8 +5978,7 @@ runtime = {}) {
5399
5978
  const q = req.query;
5400
5979
  const qeRunRaw = Array.isArray(q.qeRun) ? q.qeRun[0] : q.qeRun;
5401
5980
  const qeRunId = qeRunRaw?.trim();
5402
- const views = await adapter.sessionsDetail();
5403
- const run = views.find((v) => v.session.id === id);
5981
+ const run = await adapter.runView(id);
5404
5982
  if (!run)
5405
5983
  return reply.code(404).send({ error: 'Run not found' });
5406
5984
  return acceptanceViewOf(run, { ...(qeRunId !== undefined && qeRunId !== '' ? { qeRunId } : {}) });
@@ -5788,8 +6366,7 @@ runtime = {}) {
5788
6366
  };
5789
6367
  }
5790
6368
  return decideExclusively(id, async () => {
5791
- const views = await adapter.sessionsDetail();
5792
- const run = views.find((v) => v.session.id === id);
6369
+ const run = await adapter.runView(id);
5793
6370
  if (!run)
5794
6371
  return { code: 404, body: { error: 'Run not found' } };
5795
6372
  if (run.session.status !== 'awaiting_human') {
@@ -6019,7 +6596,10 @@ runtime = {}) {
6019
6596
  requestId: z.string().trim().min(1).max(128).regex(/^[A-Za-z0-9._-]+$/),
6020
6597
  /** The person's press on the reshape question: the loss ids it was shown. */
6021
6598
  confirmLoss: z.array(z.string().min(1).max(40)).min(1).max(12).optional(),
6022
- });
6599
+ /** (api-types 0.194.0) The plan version a `plan_offer` was made on: both or neither. */
6600
+ ord: z.number().int().min(0).optional(),
6601
+ planRev: z.number().int().min(0).optional(),
6602
+ }).refine((b) => (b.ord === undefined) === (b.planRev === undefined), { message: 'send `ord` and `planRev` together (the plan version the offer was made on)' });
6023
6603
  app.post(`${V}/runs/:id/reshape`, { config: { manifest: { requestType: 'ReshapeRunBody', responseType: 'ReshapeRunResponse', statusCodes: [200, 400, 403, 404, 409, 502] } } }, async (req, reply) => {
6024
6604
  const { id } = req.params;
6025
6605
  if (!chatJobProposalsOn)
@@ -6036,7 +6616,7 @@ runtime = {}) {
6036
6616
  const gate = personChatGate(req, chatId, 'starts a run again');
6037
6617
  if ('refusal' in gate)
6038
6618
  return reply.code(gate.refusal.code).send(gate.refusal.body);
6039
- const run = (await adapter.sessionsDetail()).find((v) => v.session.id === id);
6619
+ const run = await adapter.runView(id);
6040
6620
  if (run === undefined)
6041
6621
  return reply.code(404).send({ error: 'Run not found' });
6042
6622
  const pid = `${chatId}:reshape:${id}:${parsed.data.requestId}`;
@@ -6046,6 +6626,9 @@ runtime = {}) {
6046
6626
  const elig = await reshapeEligibility(id);
6047
6627
  if ('refusal' in elig)
6048
6628
  return reply.code(elig.refusal.code).send(elig.refusal.body);
6629
+ if (parsed.data.planRev !== undefined && (parsed.data.planRev !== elig.planRev || parsed.data.ord !== elig.ord)) {
6630
+ return reply.code(409).send({ code: 'gate_changed', error: `run ${id}'s plan changed since this was offered (now version ${elig.planRev}); look at it again`, openOrd: elig.ord, planRev: elig.planRev });
6631
+ }
6049
6632
  }
6050
6633
  const old = chatProposals.proposalOfPid(chatId, fromProposal);
6051
6634
  const base = old !== null && old.shape !== undefined ? factsOf(old) : null;
@@ -6088,6 +6671,7 @@ runtime = {}) {
6088
6671
  },
6089
6672
  request: { id: parsed.data.requestId, digest: requestDigest({ card: parsed.data.card, option: parsed.data.option ?? null, depth: parsed.data.depth ?? null, inputs: parsed.data.inputs ?? null }) },
6090
6673
  confirmLoss: parsed.data.confirmLoss ?? [],
6674
+ ...(parsed.data.ord !== undefined && parsed.data.planRev !== undefined ? { heldPlan: { ord: parsed.data.ord, planRev: parsed.data.planRev } } : {}),
6091
6675
  }, gate.actor, gate.instance);
6092
6676
  return reply.code(out.code).send(out.body);
6093
6677
  });
@@ -6104,8 +6688,7 @@ runtime = {}) {
6104
6688
  const spoken = parsed.data.input === 'voice';
6105
6689
  if (spoken && !isHumanOperator(actorOf(req)))
6106
6690
  return reply.code(403).send({ error: 'Only a person speaks: input "voice" is a person\'s stop' });
6107
- const views = await adapter.sessionsDetail();
6108
- const run = views.find((v) => v.session.id === id);
6691
+ const run = await adapter.runView(id);
6109
6692
  if (!run)
6110
6693
  return reply.code(404).send({ error: 'Run not found' });
6111
6694
  try {
@@ -6123,8 +6706,7 @@ runtime = {}) {
6123
6706
  const { id } = req.params;
6124
6707
  // A gated resume confirms the gate: one decision at a time per run (crew#1083 round 5).
6125
6708
  return decideExclusively(id, async () => {
6126
- const views = await adapter.sessionsDetail();
6127
- const run = views.find((v) => v.session.id === id);
6709
+ const run = await adapter.runView(id);
6128
6710
  if (!run)
6129
6711
  return reply.code(404).send({ error: 'Run not found' });
6130
6712
  // crew#418 A: a run stranded by a deliver-phase lift collision reads `failed` from the engine
@@ -6293,7 +6875,7 @@ runtime = {}) {
6293
6875
  return reply.code(409).send({ error: 'Refused', reason });
6294
6876
  };
6295
6877
  const powerView = async (id) => {
6296
- const view = (await adapter.sessionsDetail()).find((v) => v.session.id === id);
6878
+ const view = await adapter.runView(id);
6297
6879
  if (view === undefined)
6298
6880
  return null;
6299
6881
  const power = view.session.power ?? null;
@@ -6477,8 +7059,7 @@ runtime = {}) {
6477
7059
  reassignsInFlight.add(id);
6478
7060
  try {
6479
7061
  return await decideExclusively(id, async () => {
6480
- const views = await adapter.sessionsDetail();
6481
- const run = views.find((v) => v.session.id === id);
7062
+ const run = await adapter.runView(id);
6482
7063
  if (!run)
6483
7064
  return reply.code(404).send({ error: 'Run not found' });
6484
7065
  // Wave 6 (F-7R2-007 root fix): a run PARKED at a gate on a dead seat — the stall watchdog's
@@ -6623,8 +7204,13 @@ runtime = {}) {
6623
7204
  // read it. A restart is routine: deploy, crash, laptop sleep.
6624
7205
  app.get(`${V}/runs/:id/gate`, async (req, reply) => {
6625
7206
  const { id } = req.params;
7207
+ // F35: this run's view only, never every run's (studio polls this route for every parked run, from
7208
+ // every open tab). Each read is a copy of one run from the shared snapshot, so a read after an
7209
+ // await sees a change the adapter learned of during it (a frame, or a write it made); any other
7210
+ // change is at most the snapshot's age bound old.
7211
+ const runOf = () => adapter.runView(id);
6626
7212
  // wicked-core#850: the gate answer carries the gated unit's receipt — what assured the work it asks about.
6627
- const unitAt = async (ord) => (await adapter.sessionsDetail()).find((v) => v.session.id === id)?.units?.find((u) => u.ord === ord);
7213
+ const unitAt = async (ord) => (await runOf())?.units?.find((u) => u.ord === ord);
6628
7214
  // (rejudge, api-types 0.134.0) A gate whose unit no judge could rule on says whether its judge
6629
7215
  // can be re-run now, and from which seats — the engine's own selection, read each time (a seat
6630
7216
  // signed in since the pause counts). Absent on every other gate and on an addon without the read.
@@ -6652,7 +7238,7 @@ runtime = {}) {
6652
7238
  const skipQeAt = async (gated) => {
6653
7239
  if (gated === undefined || !isDeliverUnit(gated))
6654
7240
  return {};
6655
- const run = (await adapter.sessionsDetail()).find((v) => v.session.id === id);
7241
+ const run = await runOf();
6656
7242
  if (run === undefined)
6657
7243
  return {};
6658
7244
  const decision = qeDecisionOf(run);
@@ -6690,8 +7276,7 @@ runtime = {}) {
6690
7276
  if (cached) {
6691
7277
  const servable = recorded === null
6692
7278
  || (recorded.state === 'open' && cached.ord === recorded.ord)
6693
- || (recorded.state === 'none'
6694
- && (await adapter.sessionsDetail()).find((v) => v.session.id === id)?.session.status === 'awaiting_human');
7279
+ || (recorded.state === 'none' && (await runOf())?.session.status === 'awaiting_human');
6695
7280
  if (servable) {
6696
7281
  // One read of the gated unit serves both its receipt and its re-judge offer.
6697
7282
  const gated = await unitAt(cached.ord);
@@ -6705,11 +7290,16 @@ runtime = {}) {
6705
7290
  // common case here, since studio polls this route for runs that are merely finished.
6706
7291
  //
6707
7292
  // Reading status first is therefore CHEAPER than not reading it, the opposite of what the first
6708
- // cut of this assumed: it trades one `sessionsDetail()` for replaying an entire event history,
7293
+ // cut of this assumed: it trades one read of the run's view for replaying an entire event history,
6709
7294
  // and it was that skipped check which made a completed run answer 503 on any build without the
6710
7295
  // binding (CI caught it) — an error where the honest, knowable answer was "no gate".
6711
- const views = await adapter.sessionsDetail();
6712
- const run = views.find((v) => v.session.id === id);
7296
+ let run = await runOf();
7297
+ // F35: the engine's gate record was read before the view and outranks it. A record showing a gate
7298
+ // open beside no view of the run, or a view of it still moving, means the shared snapshot predates
7299
+ // the pause (its frame has not landed yet): read the run from a fold that starts now.
7300
+ if (recorded?.state === 'open' && run?.session.status !== 'awaiting_human') {
7301
+ run = await adapter.runView(id, { fresh: true });
7302
+ }
6713
7303
  if (!run)
6714
7304
  return reply.code(404).send({ error: 'Run not found' });
6715
7305
  if (run.session.status !== 'awaiting_human') {
@@ -7471,6 +8061,58 @@ runtime = {}) {
7471
8061
  });
7472
8062
  return body;
7473
8063
  });
8064
+ /**
8065
+ * (DES-CATALOG-002 §2.3, api-types 0.192.0 `DetectShapeRequest` → `ShapeGuess`) Free words typed into the `/` list
8066
+ * that match no command: the words layer, then (unless `seat: false`) the hidden `detect-shape` turn on one seat,
8067
+ * validated, cross-checked and banded. A person's route: it spends a seat's turn, and it proposes and starts nothing.
8068
+ */
8069
+ const detectService = new DetectService({
8070
+ turn: seatTurn({
8071
+ adapter,
8072
+ roster: rosterWithStanding,
8073
+ timeoutMs: DETECT_TIMEOUT_MS,
8074
+ outputOf: async (runId) => {
8075
+ const view = await adapter.runView(runId);
8076
+ const unit = view?.units.find((u) => u.ord === 1) ?? view?.units[0];
8077
+ return view !== undefined && unit !== undefined ? adapter.workOutput(coreUnitId(runId, unit)) : null;
8078
+ },
8079
+ }),
8080
+ cancelRun: async (runId) => {
8081
+ await adapter.cancelRun(runId);
8082
+ },
8083
+ catalog: async (projectId) => {
8084
+ const served = await servedFor(shapeReads, projectId ?? undefined);
8085
+ const status = (card, option) => resolveOption(card, option, served)?.resolved.status ?? 'unavailable';
8086
+ // The detect turn launches repo-less and project-less: the global rows (and the project's) are what could shadow it.
8087
+ // A read that fails is a shadow: the seat is not asked (codex r7).
8088
+ const detectShadowed = await shadowCheck(async () => [...(await adapter.listPresets()), ...(projectId !== null ? await adapter.listPresets(projectId) : [])]);
8089
+ return { rev: served.rev, status, available: (card, option) => status(card, option) === 'available', detectShadowed };
8090
+ },
8091
+ costOf: async (runId) => {
8092
+ const view = await adapter.runView(runId);
8093
+ return view === undefined ? null : runCostFromEvents(view, (await adapter.runEvents(runId)));
8094
+ },
8095
+ audit: (row) => audit.record('workflow.detect', { id: row.actor, kind: 'human', trust: 'operator' }, { ...(row.runId !== null ? { runId: row.runId } : {}), detail: { ...row } }),
8096
+ // A detect-shape run's id carries its fence (mcp/run-fence.ts), across a restart.
8097
+ newId: () => fencedRunId(),
8098
+ log: (m) => app.log.warn(m),
8099
+ });
8100
+ const DetectSchema = z.strictObject({
8101
+ text: z.string().max(DETECT_MAX_CHARS),
8102
+ seat: z.boolean().optional(),
8103
+ projectId: z.string().trim().min(1).max(200).optional(),
8104
+ });
8105
+ app.post(`${V}/workflows/catalog/detect`, { config: { manifest: { requestType: 'DetectShapeRequest', responseType: 'ShapeGuess', statusCodes: [200, 400, 403, 409, 503] } } }, async (req, reply) => {
8106
+ const actor = actorOf(req);
8107
+ if (!isHumanOperator(actor)) {
8108
+ return reply.code(403).send({ code: 'detect_refused', error: `only a person asks what job their words are (you are ${actor.kind}/${actor.trust})` });
8109
+ }
8110
+ const parsed = DetectSchema.safeParse(req.body);
8111
+ if (!parsed.success)
8112
+ return reply.code(400).send(invalidBody(parsed.error, 'Invalid request body'));
8113
+ const out = await detectService.detect({ text: parsed.data.text, ...(parsed.data.seat !== undefined ? { seat: parsed.data.seat } : {}), projectId: parsed.data.projectId ?? null }, actor);
8114
+ return reply.code(out.code).send(out.body);
8115
+ });
7474
8116
  app.get(`${V}/workflows/:id`, async (req, reply) => {
7475
8117
  const { id } = req.params;
7476
8118
  const workflow = adapter.getWorkflow(id);
@@ -7578,6 +8220,7 @@ runtime = {}) {
7578
8220
  q: z.string().optional(),
7579
8221
  risk: z.enum(['risk', 'no-risk']).optional(),
7580
8222
  category: z.enum(['functional', 'config-data']).optional(),
8223
+ mismatch: z.enum(['yes', 'no']).optional(),
7581
8224
  domain: z.string().optional(),
7582
8225
  offset: z.coerce.number().int().min(0).prefault(0),
7583
8226
  limit: z.coerce.number().int().min(1).max(200).prefault(50),
@@ -7594,8 +8237,9 @@ runtime = {}) {
7594
8237
  }
7595
8238
  let page;
7596
8239
  let coverage = null;
8240
+ let minimum = null;
7597
8241
  try {
7598
- ({ page, coverage } = await listRequirementsRead(repo, parsed.data, adapter));
8242
+ ({ page, coverage, minimum } = await listRequirementsRead(repo, parsed.data, adapter));
7599
8243
  }
7600
8244
  catch (err) {
7601
8245
  // wicked-core#406: a CURRENT engine with no repo-graph root is a 503, not a 500.
@@ -7608,9 +8252,11 @@ runtime = {}) {
7608
8252
  // Not generated yet is a state, typed by `code`, not a refusal (lane repo-page). It says how
7609
8253
  // far the repository is ("23% real requirements · 4397 placeholders · target 80%";
7610
8254
  // wicked-core#1233), from the very engine read the page used, when it has a store to count.
7611
- return reply
7612
- .code(404)
7613
- .send(coverage === null ? REQUIREMENTS_NOT_GENERATED : { ...REQUIREMENTS_NOT_GENERATED, coverage });
8255
+ return reply.code(404).send({
8256
+ ...REQUIREMENTS_NOT_GENERATED,
8257
+ ...(coverage === null ? {} : { coverage }),
8258
+ ...(minimum === null ? {} : { minimum }),
8259
+ });
7614
8260
  }
7615
8261
  // Overrides keyed by ids the corpus no longer mints (an estate id-scheme migration re-keys
7616
8262
  // method/field SymbolIds) would otherwise vanish without a trace — the count is on the page
@@ -7620,6 +8266,33 @@ runtime = {}) {
7620
8266
  }
7621
8267
  return page;
7622
8268
  });
8269
+ // P3 (operator ruling 2026-11-06): raise, lower or clear a repository's OWN minimum from the requirements page.
8270
+ // `minPct: null` clears it (the Settings minimum applies again).
8271
+ app.put(`${V}/repos/:id/requirements/minimum`, { config: { manifest: { requestType: 'RequirementsMinimumBody', responseType: 'RequirementsMinimumResponse', statusCodes: [200, 400, 404, 409, 500, 503] } } }, async (req, reply) => {
8272
+ const { id } = req.params;
8273
+ const repos = await adapter.listRepos();
8274
+ const repo = repos.find((r) => r.id === id);
8275
+ if (!repo)
8276
+ return reply.code(404).send({ error: `Repo ${id} not found` });
8277
+ const parsed = ReqMinimumSchema.safeParse(req.body);
8278
+ if (!parsed.success)
8279
+ return reply.code(400).send(invalidBody(parsed.error, 'Invalid minimum'));
8280
+ let set;
8281
+ try {
8282
+ set = await setRepoMinimum(repo, parsed.data.minPct);
8283
+ }
8284
+ catch (err) {
8285
+ const status = codeGraphErrorStatus(err);
8286
+ if (status !== null)
8287
+ return reply.code(status).send({ error: message(err) });
8288
+ return reply.code(500).send({ error: `the minimum could not be saved: ${message(err)}` });
8289
+ }
8290
+ if (!set) {
8291
+ return reply.code(409).send({ error: `${repo.name} has no code graph yet, so it has no minimum of its own to set` });
8292
+ }
8293
+ const { minimum } = await listRequirementsRead(repo, { offset: 0, limit: 0 }, adapter);
8294
+ return { minimum };
8295
+ });
7623
8296
  app.get(`${V}/repos/:id/requirements/:key`, async (req, reply) => {
7624
8297
  const { id, key } = req.params;
7625
8298
  const repos = await adapter.listRepos();
@@ -7964,158 +8637,8 @@ runtime = {}) {
7964
8637
  return reply.code(201).send({ terminalId: termId, cli, action });
7965
8638
  });
7966
8639
  }
7967
- const containerLoginOutcomes = new Map();
7968
- const containerSeat = (cli) => isContainerSeatFloor() && isContainerLoginCli(cli) && rosterWithStanding().some((seat) => seat.key === cli);
7969
- const loginError = (stderr) => loginDetail(stderr) || 'seat-login failed';
7970
- // One sign-in/sign-out at a time per seat, and a generation every new sign-in and every sign-out
7971
- // bumps (agy crew-r1): an abandoned login terminal that exits later never ingests over a newer
7972
- // sign-in or a sign-out, and an ingest in flight finishes before a sign-out runs.
7973
- const loginGeneration = new Map();
7974
- const seatOps = new Map();
7975
- const serial = (cli, op) => {
7976
- const next = (seatOps.get(cli) ?? Promise.resolve()).then(op, op);
7977
- seatOps.set(cli, next.catch(() => undefined));
7978
- return next;
7979
- };
7980
- const bump = (cli) => {
7981
- const g = (loginGeneration.get(cli) ?? 0) + 1;
7982
- loginGeneration.set(cli, g);
7983
- return g;
7984
- };
7985
- // The one sign-in per seat, reserved synchronously from the request's first await until its
7986
- // ingest settles (codex crew-r1/r2: two sessions would share the engine's login session), and
7987
- // released only by its owner (the generation that reserved it).
7988
- const openLogins = new Map();
7989
- const release = (cli, generation) => {
7990
- if (openLogins.get(cli) === generation)
7991
- openLogins.delete(cli);
7992
- };
7993
- app.post(`${V}/seats/:cli/container-login`, { config: { manifest: { requestType: 'SeatSessionBody', responseType: 'SeatContainerLoginResponse', statusCodes: [201, 400, 404, 502] } } }, async (req, reply) => {
7994
- const { cli } = req.params;
7995
- if (!containerSeat(cli))
7996
- return reply.code(404).send({ error: `container login unavailable for seat: ${cli}` });
7997
- const parsed = SeatSessionSchema.safeParse(req.body ?? {});
7998
- if (!parsed.success)
7999
- return reply.code(400).send(invalidBody(parsed.error, 'Invalid request body'));
8000
- if (openLogins.has(cli)) {
8001
- return reply.code(409).send({ error: `a sign-in is already open for ${cli}; finish or close it first` });
8002
- }
8003
- // Reserved BEFORE the first await (codex crew-r1): a sign-out that lands meanwhile wins.
8004
- const generation = bump(cli);
8005
- openLogins.set(cli, generation);
8006
- containerLoginOutcomes.delete(cli);
8007
- const out = await serial(cli, () => runSeatLogin('argv', cli, seatLoginDeps));
8008
- if (out.rc !== 0) {
8009
- release(cli, generation);
8010
- return reply.code(502).send({ error: loginError(out.stderr) });
8011
- }
8012
- if (loginGeneration.get(cli) !== generation) {
8013
- release(cli, generation);
8014
- return reply.code(409).send({ error: `the ${cli} sign-in was superseded (a sign-out or another sign-in)` });
8015
- }
8016
- let argv;
8017
- try {
8018
- const value = JSON.parse(out.stdout);
8019
- if (!Array.isArray(value) || value.length === 0 || !value.every((arg) => typeof arg === 'string' && arg.length > 0)) {
8020
- throw new Error('seat-login argv must be a non-empty array of non-empty strings');
8021
- }
8022
- argv = value;
8023
- }
8024
- catch (err) {
8025
- release(cli, generation);
8026
- return reply.code(502).send({ error: message(err) });
8027
- }
8028
- let termId = null;
8029
- let completed = false;
8030
- const exitedEarly = new Set();
8031
- const ingest = () => serial(cli, async () => {
8032
- // A newer sign-in or a sign-out superseded this terminal: nothing to ingest or record.
8033
- if (loginGeneration.get(cli) !== generation)
8034
- return;
8035
- // Refusals the OLD credential earned up to now are superseded by this sign-in (codex
8036
- // crew-r2: a 401 during the interactive login must not outlive it).
8037
- const cutoff = Date.now();
8038
- const result = await runSeatLogin('ingest', cli, seatLoginDeps);
8039
- // The broker may have changed whatever happens next: the next reading is its own.
8040
- containerStatus.invalidate(cli);
8041
- rosterWithStanding.reprobe?.(cli);
8042
- const outcome = { cli, ok: result.rc === 0, at: new Date().toISOString() };
8043
- if (result.rc !== 0)
8044
- outcome.error = loginError(result.stderr);
8045
- else {
8046
- try {
8047
- const value = JSON.parse(result.stdout);
8048
- if (value === null || !Array.isArray(value.files) || !value.files.every((file) => typeof file === 'string') ||
8049
- !(value.expires_at === null || (typeof value.expires_at === 'number' && Number.isFinite(value.expires_at)))) {
8050
- throw new Error('invalid seat-login ingest response');
8051
- }
8052
- // Only the public ingest fields cross the wire; raw stdout may contain credentials.
8053
- outcome.files = value.files;
8054
- outcome.expires_at = value.expires_at;
8055
- }
8056
- catch {
8057
- outcome.ok = false;
8058
- outcome.error = 'invalid seat-login ingest response';
8059
- }
8060
- }
8061
- if (outcome.ok) {
8062
- seatHealth.clearAuthFailureBefore(cli, cutoff);
8063
- seatHealth.clearRecentBench(cli);
8064
- }
8065
- // A sign-out (or a newer sign-in) while this ingest ran owns the outcome now.
8066
- if (loginGeneration.get(cli) === generation)
8067
- containerLoginOutcomes.set(cli, outcome);
8068
- }).finally(() => release(cli, generation));
8069
- const done = () => {
8070
- if (completed)
8071
- return;
8072
- completed = true;
8073
- stop();
8074
- void ingest();
8075
- };
8076
- // Subscribe before spawn: an immediate exit still needs exactly one ingest.
8077
- const stop = adapter.onEvent((event) => {
8078
- if (event.type !== 'terminalExited' || typeof event.id !== 'string')
8079
- return;
8080
- if (termId === null)
8081
- exitedEarly.add(event.id);
8082
- else if (event.id === termId)
8083
- done();
8084
- });
8085
- try {
8086
- termId = await adapter.openTerminal(homedir(), argv, parsed.data.cols ?? 100, parsed.data.rows ?? 30, true);
8087
- }
8088
- catch (err) {
8089
- stop();
8090
- release(cli, generation);
8091
- return reply.code(400).send({ error: message(err) });
8092
- }
8093
- if (exitedEarly.has(termId))
8094
- done();
8095
- return reply.code(201).send({ terminalId: termId, cli, action: 'sign_in' });
8096
- });
8097
- app.get(`${V}/seats/:cli/container-login`, { config: { manifest: { responseType: 'SeatContainerLoginOutcome', statusCodes: [200, 404] } } }, async (req, reply) => {
8098
- const { cli } = req.params;
8099
- const outcome = containerSeat(cli) ? containerLoginOutcomes.get(cli) : undefined;
8100
- if (outcome === undefined)
8101
- return reply.code(404).send({ error: `no container login outcome for seat: ${cli}` });
8102
- return reply.send(outcome);
8103
- });
8104
- app.post(`${V}/seats/:cli/container-logout`, { config: { manifest: { responseType: 'SeatContainerLogoutResponse', statusCodes: [200, 404, 502] } } }, async (req, reply) => {
8105
- const { cli } = req.params;
8106
- if (!containerSeat(cli))
8107
- return reply.code(404).send({ error: `container logout unavailable for seat: ${cli}` });
8108
- bump(cli);
8109
- const out = await serial(cli, async () => {
8110
- containerLoginOutcomes.delete(cli);
8111
- return runSeatLogin('sign-out', cli, seatLoginDeps);
8112
- });
8113
- // Whatever the engine managed before failing, the next reading is the broker's (codex crew-r1).
8114
- containerStatus.invalidate(cli);
8115
- rosterWithStanding.reprobe?.(cli);
8116
- if (out.rc !== 0)
8117
- return reply.code(502).send({ error: loginError(out.stderr) });
8118
- return reply.send({ cli, action: 'sign_out' });
8640
+ registerSeatContainerLoginRoutes(app, {
8641
+ adapter, rosterWithStanding, containerStatus, seatHealth, seatLoginDeps, parseSession: (body) => SeatSessionSchema.safeParse(body),
8119
8642
  });
8120
8643
  // Resize a live terminal's PTY.
8121
8644
  app.post(`${V}/terminals/:id/resize`, async (req, reply) => {
@@ -9189,7 +9712,7 @@ runtime = {}) {
9189
9712
  // proposals in the queue above; the launch is POST /runs itself (api/capture.ts).
9190
9713
  registerCaptureRoutes(app);
9191
9714
  // The Demo experience (studio#373): the demo preset's launch, view, files and script edit.
9192
- registerDemoRoutes(app, adapter, launchRun);
9715
+ registerDemoRoutes(app, adapter, launchRun, demoDeps);
9193
9716
  // WT-W3: the storyline PUT checks the open gate through the same resolution the gate routes use.
9194
9717
  registerWalkthroughRoutes(app, adapter, { resolveOpenGate, audit });
9195
9718
  // ── Presets (DES-TEAMING-002 §8.4, seam C2) — saved phase selections in the engine's store;
@@ -9284,6 +9807,7 @@ runtime = {}) {
9284
9807
  // directly-driven route set answers 503 unless a test injects one over a fixture root.
9285
9808
  registerSkillsRoutes(app, {
9286
9809
  ...(runtime.skills !== undefined ? { runtime: runtime.skills } : {}),
9810
+ ...(runtime.skillUsage !== undefined ? { usage: runtime.skillUsage } : {}),
9287
9811
  audit,
9288
9812
  actorOf,
9289
9813
  });
@@ -9306,6 +9830,10 @@ runtime = {}) {
9306
9830
  registerMcpRoutes(app, {
9307
9831
  ...(runtime.askServer !== undefined ? { askServer: runtime.askServer } : {}),
9308
9832
  ...(runtime.mcp !== undefined ? { registry: runtime.mcp, toolLister: () => CoreAdapter.mcpToolLister() } : {}),
9833
+ // DES-CATALOG-002 §2.3: a `detect-shape` run is listed no tool (its fence is its identity).
9834
+ fence: daemonRunFence((runId) => adapter.launchedWorkflowOfRun(runId)),
9835
+ // (DES-CATALOG-002 CS10) A unit is listed no tool of a source its job did not pick (the broker refuses the call too).
9836
+ ...(runtime.runSourcePicks !== undefined ? { picks: runtime.runSourcePicks } : {}),
9309
9837
  ...(runtime.mcpBroker !== undefined ? { broker: runtime.mcpBroker } : {}),
9310
9838
  ...(runtime.dataGate !== undefined ? { gate: runtime.dataGate } : {}),
9311
9839
  ...(mcpPolicies !== undefined ? { policies: mcpPolicies } : {}),
@@ -9352,7 +9880,7 @@ runtime = {}) {
9352
9880
  ...(runtime.dataGate !== undefined ? { pm: runtime.dataGate.pm } : {}),
9353
9881
  ...(runtime.trackerAddresses !== undefined ? { addresses: runtime.trackerAddresses } : {}),
9354
9882
  runScope: async (runId) => {
9355
- const run = (await adapter.sessionsDetail()).find((v) => v.session.id === runId);
9883
+ const run = await adapter.runView(runId);
9356
9884
  if (run === undefined)
9357
9885
  return null;
9358
9886
  const projectId = projects.index.projectOf(runId) ?? (await adapter.memberProjects('crew.run', runId).catch(() => []))[0] ?? null;
@@ -9783,6 +10311,25 @@ runtime = {}) {
9783
10311
  log: (m) => app.log.warn(m),
9784
10312
  });
9785
10313
  // A3: the real `create` launcher (§4.3 steps 2-3): one document and one run per proposal identity.
10314
+ if (realRefine) {
10315
+ // A5 (DES §6): the refine launcher — the attempt on the document's binding, then the chat seam's bound refine with the
10316
+ // derived run id and the card's two helpers; crew's landing guard and the head's CAS decide what lands.
10317
+ proposalLaunchers.register('refine', new RefineLauncher({
10318
+ bindings: runtime.docBindings,
10319
+ runExists: async (runId) => (await adapter.sessions()).includes(runId),
10320
+ docsRoot: (projectId) => projectDocsRoot(adapter, projectSettings, projectId),
10321
+ launchBound: runtime.launchBoundRefine,
10322
+ ...(runtime.fenceBoundDraft !== undefined ? { fence: runtime.fenceBoundDraft } : {}),
10323
+ records: (chatId) => chatHistory?.messages(chatId) ?? chatTranscripts?.read(chatId) ?? [],
10324
+ instanceOf: (chatId) => chatHistory?.stateOf(chatId)?.instance ?? null,
10325
+ clisJsonFor: (seats) => {
10326
+ const roster = rosterWithStanding();
10327
+ const picked = seats.map((k) => roster.find((s) => s.key === k));
10328
+ return picked.some((s) => s === undefined) ? null : JSON.stringify(picked);
10329
+ },
10330
+ log: (m) => app.log.warn(m),
10331
+ }));
10332
+ }
9786
10333
  if (realCreate) {
9787
10334
  const bindings = runtime.docBindings;
9788
10335
  proposalLaunchers.register('create', new CreateLauncher({
@@ -9910,6 +10457,8 @@ runtime = {}) {
9910
10457
  // EP-C2: the ONE checks read of a document — the reviewers' recorded verdicts, read-only.
9911
10458
  registerInteractiveDocChecks(app, adapter, {
9912
10459
  reviewsDir: runtime.docReviewsDir ?? (() => join(crewStateHome(), 'interactive-edits', REVIEWS_DIRNAME)),
10460
+ ...(runtime.docLandings !== undefined ? { landings: runtime.docLandings } : {}),
10461
+ docsRoot: (projectId) => projectDocsRoot(adapter, projectSettings, projectId),
9913
10462
  log: (m) => app.log.warn(m),
9914
10463
  });
9915
10464
  // `GET /search` (api-types 0.127.0): one query over every major entity. The index is read lazily,