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,28 +1,163 @@
1
1
  /**
2
- * THE WORKING DOCUMENT AND STEERING FROM IT (program DES-POWER-MODE §8.3, §9; spike 3).
2
+ * THE CONTEXT DOCUMENT AND STEERING FROM IT (program DES-POWER-MODE §8.3, §9; spike 3). Called the working document
3
+ * before the engine kept a context block; the wire and code names (`/working-doc`, `WorkingDoc*`) are unchanged.
3
4
  *
4
- * - Each run may have ONE working document: a wicked-interactive document (kind `phase-report`) in the run's
5
+ * - Each run may have ONE context document: a wicked-interactive document (kind `phase-report`) in the run's
5
6
  * project, bound by crew (`store.ts`). Versions are interactive's: write-once, parent-linked, each batch with
6
7
  * its `author`. A section is rewritten with one deterministic `content-edit`: no model, never a governed run.
7
8
  * - Attribution is crew's to decide. A person's edit (`author: 'operator'`) is accepted only from a HUMAN actor and
8
9
  * is recorded as theirs, with the plugin that hosted it named as the surface. A plugin's own generated lines
9
10
  * (`author: 'plugin'`) are recorded as `plugin:<id>@<version>` and may touch only the plugin's own section.
10
11
  * Nothing a plugin writes is ever recorded as a person's, and a plugin's lines never steer.
11
- * - STEERING. A person's version becomes ONE note for the run, sent through the operator's existing back-channel
12
+ * - THE CONTEXT BLOCK (context-doc-switch, core#1325). When the engine keeps one (`supportsRunContext` +
13
+ * `setRunContext`), the person's CURRENT Goal, Approach and Constraints (each section whose latest write is a
14
+ * person's, capped visibly) are set as the run's block after every version that touches them and once per live
15
+ * document at daemon start; the engine hands it to every seat the run spawns (workers, judges, rule judges, QE,
16
+ * councils). Never clipped silently: a cut section says so in its text and on the view (`context.cut`); a refused
17
+ * block's reason is on the view (`context.error`, which studio shows with the document) and the engine's block is
18
+ * cleared; an unanswered set is retried.
19
+ * Next still goes to the next step once, as a note.
20
+ * - STEERING NOTES. A person's version becomes ONE note for the run, sent through the operator's existing back-channel
12
21
  * (`injectWorkerMessage`, the `POST /runs/:id/inject` path): queued by the engine, it rides the next step's
13
22
  * prompt as an operator context block, and `workerMessageInjected` says which step picked it up.
14
- * Goal, Approach and Next go to the next step once; Constraints and steering is a STANDING steer, re-sent before
15
- * every later step until a later edit replaces it. Decisions and Open questions are recorded, not sent.
16
- * - DOCUMENT TEXT HAS NO POWER OVER GATES. This module calls `injectWorkerMessage` and nothing else on the engine:
17
- * no gate answer, no plan edit, no intent amendment, no rigor change. A note says in its first line that it
18
- * adds to the step's brief and changes no gate, check or review. (Tested: `tests/working-doc.test.ts`.)
23
+ * Without the engine's block (the bridge, operator ruling 2026-11-06), the person's CURRENT Goal, Approach and
24
+ * Constraints are ONE STANDING steer, re-sent before every later worker step until a later edit replaces it. Next
25
+ * goes to the next step once. Decisions and Open questions are recorded, not sent.
26
+ * - DOCUMENT TEXT HAS NO POWER OVER GATES. Its only engine writes are `injectWorkerMessage` and `setRunContext`
27
+ * (it also reads `supportsRunContext`): no gate answer, no plan edit, no intent amendment, no rigor change. A note says in its first
28
+ * line that it adds to the step's brief and changes no gate, check or review; the block's framing is the engine's
29
+ * and says the same. (Tested: `tests/working-doc.test.ts`.)
19
30
  */
20
31
  import { randomUUID } from 'node:crypto';
21
32
  import { stripRulesBrief } from '../decisions/rules-brief.js';
22
33
  import { PLUGIN_SECTIONS, SECTION_LABELS, SECTION_MAX_CHARS, SECTION_STEER, anchorOf, changedSections, encodeSectionText, initialHtml, isSectionId, sectionsOf, } from './sections.js';
23
- import { LINE_EVENTS, PHASE_REPORT_AUTHOR, docLines, foldLines, reconcileSection } from './event-lines.js';
34
+ import { CONTEXT_SEEN_MAX } from './store.js';
35
+ import { LEGACY_GENERATED_DECISION, LINE_EVENTS, PHASE_REPORT_AUTHOR, docLines, foldLines, isGenerated, planApproach, planSettled, reconcileSection, } from './event-lines.js';
36
+ /** The sections a person's context is made of (what every agent of the run hears). */
37
+ export const CONTEXT_SECTIONS = ['goal', 'approach', 'constraints'];
38
+ /** Most characters of one section, and of all of them, the context carries (DESIGN §8 caps; the engine refuses more). */
39
+ export const CONTEXT_SECTION_MAX = 1_500;
40
+ export const CONTEXT_MAX = 4_000;
41
+ /** How long crew waits for the engine to answer a set before it records the set as unanswered. */
42
+ export const CONTEXT_SET_TIMEOUT_MS = 10_000;
43
+ /** A person's text in the shape the engine takes it: line breaks as LF, and the invisible characters it refuses (a
44
+ * control character from a paste, a Unicode line separator) as LF or dropped. Nothing visible is changed. */
45
+ export function contextText(text) {
46
+ return text
47
+ .replace(/\r\n?|[\u2028\u2029\v\f]/gu, '\n')
48
+ .replace(/[\u0000-\u0008\u000e-\u001f\u007f-\u009f]/gu, '')
49
+ .trim();
50
+ }
51
+ /** The person's sections under the caps: each at most {@link CONTEXT_SECTION_MAX}, all of them at most
52
+ * {@link CONTEXT_MAX} (short sections keep all of theirs, the long ones share the rest). A cut section ends saying where
53
+ * it was cut, and is named in `cut` so the document's thread says so too: never a silent clip. */
54
+ export function capBlock(sections) {
55
+ const len = sections.map((s) => Math.min(s.text.length, CONTEXT_SECTION_MAX));
56
+ let cap = CONTEXT_SECTION_MAX;
57
+ while (cap > 1 && len.reduce((a, l) => a + Math.min(l, cap), 0) > CONTEXT_MAX)
58
+ cap -= 1;
59
+ const cut = [];
60
+ const out = sections.map((s) => {
61
+ const text = capContext(s.text, cap);
62
+ if (text !== s.text.trim())
63
+ cut.push(s.id);
64
+ return { ...s, text };
65
+ });
66
+ return { sections: out, cut };
67
+ }
68
+ /** The seats the engine names in `runContextDelivered` (core `run_context`). */
69
+ export const CONTEXT_RECIPIENTS = new Set(['unit', 'judge', 'triage', 'council', 'team_member', 'qe', 'team_review', 'send_back']);
70
+ const EMPTY_SIG = '[]';
71
+ /**
72
+ * Whether a document owes the engine a context set, from crew's own record alone (no engine call, no document read):
73
+ * a set owed or never answered, or a person's Goal, Approach or Constraints newer than the last block the engine took.
74
+ * A document with none of the person's context and nothing owed needs nothing at start-up (F35).
75
+ */
76
+ export function contextOwed(rec) {
77
+ const c = rec.context;
78
+ if (c?.retry === true)
79
+ return true;
80
+ // A write of unknown outcome touching the person's context: settling it may set the block (xreview F35 r1).
81
+ if (rec.pending != null && Object.keys(rec.pending.values).some((k) => CONTEXT_SECTIONS.includes(k)))
82
+ return true;
83
+ if (c != null && c.attempted !== null && (c.sentVersion ?? -1) < c.attempted)
84
+ return true;
85
+ let newest = -1;
86
+ for (const sid of CONTEXT_SECTIONS) {
87
+ const last = [...rec.trail].reverse().find((t) => t.sections.includes(sid));
88
+ if (last?.author.kind === 'human')
89
+ newest = Math.max(newest, last.version);
90
+ }
91
+ return newest > (c?.sentVersion ?? -1);
92
+ }
93
+ /** What a block says (sections, their versions, authors and texts): an unchanged block is not sent again. */
94
+ function contextSig(b) {
95
+ return JSON.stringify(b.sections.map((x) => [x.id, x.version, x.author.id, x.text]));
96
+ }
97
+ /** An author id as the seats read it (`local` is the operator); an id the engine would refuse reads "a person". */
98
+ export function contextAuthorId(id) {
99
+ if (id === 'local')
100
+ return 'the operator';
101
+ return id.trim() === '' || id.length > 200 || /[\u0000-\u001f\u007f-\u009f\u2028\u2029]/u.test(id) ? 'a person' : id;
102
+ }
103
+ /** A person's section cut to `max` characters at a word boundary, saying so. */
104
+ export function capContext(text, max) {
105
+ const t = text.trim();
106
+ if (t.length <= max)
107
+ return t;
108
+ const tail = ` … (cut at ${max.toLocaleString('en-US')} characters)`;
109
+ const room = Math.max(1, max - tail.length);
110
+ let end = room;
111
+ // The last whitespace of any kind (a line break, a tab) at or before the cut; an unbroken run is cut where it is.
112
+ let space = room;
113
+ while (space > 0 && !/\s/u.test(t[space] ?? ''))
114
+ space -= 1;
115
+ if (space > room / 2)
116
+ end = space;
117
+ const last = t.charCodeAt(end - 1);
118
+ if (last >= 0xd800 && last <= 0xdbff)
119
+ end -= 1;
120
+ return `${t.slice(0, end).trimEnd()}${tail}`;
121
+ }
122
+ /** The person's current context as note lines: each section capped so that all of them fit {@link CONTEXT_MAX}. */
123
+ export function contextLines(context) {
124
+ const per = Math.min(CONTEXT_SECTION_MAX, Math.floor(CONTEXT_MAX / Math.max(1, context.length)));
125
+ return context.map((c) => `- ${SECTION_LABELS[c.id]}: ${capContext(c.text, per)}`);
126
+ }
127
+ /** (bridge) The one note a person's version becomes when it touches their context: the context, standing, and any
128
+ * one-step section (Next) or cleared section with it. */
129
+ export function contextSteerNote(version, by, context, once, marker) {
130
+ const head = context.length > 0
131
+ ? `Operator steering from the job's context document (version ${version}, by ${by}). The person's ${context.map((c) => SECTION_LABELS[c.id]).join(', ')} below are standing: follow them in this step and every later one until they are replaced. They replace any standing context or constraint from an earlier version.`
132
+ : `Operator steering from the job's context document (version ${version}, by ${by}).`;
133
+ const rest = once.map((t) => `- ${SECTION_LABELS[t.id]}${t.id === 'next' && context.length > 0 ? ' (this step)' : ''}: ${t.text.trim() === '' ? '(cleared)' : t.text.trim()}`);
134
+ return [head, NO_GATE_LINE, ...contextLines(context), ...rest, marker].join('\n');
135
+ }
136
+ /** (bridge) The person's context alone, re-sent before every later step. */
137
+ export function contextStandingNote(version, by, context, marker) {
138
+ return [
139
+ `Standing operator context from the job's context document (version ${version}, by ${by}): the person's current ${context.map((c) => SECTION_LABELS[c.id]).join(', ')}. Follow it in this step and every later one until it is replaced. If you also see standing context from a later version, that one applies instead.`,
140
+ NO_GATE_LINE,
141
+ ...contextLines(context),
142
+ marker,
143
+ ].join('\n');
144
+ }
145
+ /** How many live runs with no document a daemon start brings up to date (newest first, one at a time). The rest get
146
+ * theirs on their next event. Rig 2026-11-06: 98 parked runs, 26 of them from the last day. */
147
+ export const CATCH_UP_LIVE_MAX = 40;
24
148
  const PLUGIN_ID = /^[a-z0-9]+(?:-[a-z0-9]+)*$/u;
25
149
  const PLUGIN_VERSION = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/u;
150
+ /** A unit's step name: its `phase_ref`, unless that is the engine's execution id (`wf-<run>:unit-4:a1`, which a run's
151
+ * unit carries once it ran: xreview r2, rig run W12), else its description's head ("pa-scope — Fixes …" → "pa-scope"). */
152
+ export function workingDocStep(u) {
153
+ if (u === undefined)
154
+ return null;
155
+ const ref = u.phase_ref;
156
+ if (typeof ref === 'string' && ref !== '' && !/^wf-|:unit-\d/u.test(ref))
157
+ return ref;
158
+ const head = typeof u.description === 'string' ? (u.description.split(/\s+[—-]\s+/u)[0]?.trim() ?? '') : '';
159
+ return head === '' ? null : head;
160
+ }
26
161
  /** A doc name interactive accepts (lowercase, digits, hyphens; ≤ 64): one per run. */
27
162
  export function workingDocName(runId) {
28
163
  const slug = runId.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+/, '').slice(0, 40).replace(/-+$/, '');
@@ -35,15 +170,15 @@ export function steerMarker(runId, steerId) {
35
170
  /** The one note a person's version becomes: the sections that steer once, and the standing constraint, together. */
36
171
  export function steerNote(version, by, standing, texts, marker) {
37
172
  const head = standing
38
- ? `Operator steering from the job's working document (version ${version}, by ${by}). Its Constraints and steering is standing: follow it in this step and every later one until it is replaced. It replaces any standing constraint from an earlier version.`
39
- : `Operator steering from the job's working document (version ${version}, by ${by}).`;
173
+ ? `Operator steering from the job's context document (version ${version}, by ${by}). Its Constraints and steering is standing: follow it in this step and every later one until it is replaced. It replaces any standing constraint from an earlier version.`
174
+ : `Operator steering from the job's context document (version ${version}, by ${by}).`;
40
175
  const lines = texts.map((t) => `- ${SECTION_LABELS[t.id]}: ${t.text.trim() === '' ? '(cleared)' : t.text.trim()}`);
41
176
  return [head, NO_GATE_LINE, ...lines, marker].join('\n');
42
177
  }
43
178
  /** The standing constraint alone, re-sent before every later step. */
44
179
  export function standingNote(version, by, text, marker) {
45
180
  return [
46
- `Standing operator constraint from the job's working document (version ${version}, by ${by}). Follow it in this step and every later one until it is replaced. If you also see a standing constraint from a later version, that one applies instead.`,
181
+ `Standing operator constraint from the job's context document (version ${version}, by ${by}). Follow it in this step and every later one until it is replaced. If you also see a standing constraint from a later version, that one applies instead.`,
47
182
  NO_GATE_LINE,
48
183
  `- ${SECTION_LABELS.constraints}: ${text.trim()}`,
49
184
  marker,
@@ -106,6 +241,15 @@ export class WorkingDocService {
106
241
  eventLog = null;
107
242
  /** Runs whose orchestrator wrote its own APPROACH line: its turn summaries then never replace it. */
108
243
  approachNoted = new Set();
244
+ /** Runs whose pending line sync may MAKE the document (a live event came for it, or the start-up catch-up chose it). */
245
+ mayCreate = new Set();
246
+ /** Per run, the settled plan's event signature the Approach was last checked against (the run's view is read again
247
+ * only when it moves). */
248
+ planChecked = new Map();
249
+ /** (context-doc-switch) Per run, how many retries of an unanswered context set are scheduled so far. */
250
+ contextRetries = new Map();
251
+ /** The start-up context catch-up (once per daemon). */
252
+ contextCaughtUp = null;
109
253
  constructor(d) {
110
254
  this.d = d;
111
255
  this.now = d.now ?? Date.now;
@@ -121,7 +265,11 @@ export class WorkingDocService {
121
265
  if (this.d.store.get(runId)?.pending != null)
122
266
  await this.exclusive(runId, () => this.reconcile(runId));
123
267
  const rec = this.d.store.get(runId);
124
- const base = { runId, labels: { ...SECTION_LABELS }, trail: rec?.trail ?? [], steers: rec?.steers ?? [], eventLines: await this.eventLines(runId) };
268
+ const ctx = rec !== undefined ? this.contextView(rec) : null;
269
+ const base = {
270
+ runId, labels: { ...SECTION_LABELS }, trail: rec?.trail ?? [], steers: rec?.steers ?? [], eventLines: await this.eventLines(runId),
271
+ ...(ctx !== null ? { context: ctx } : {}),
272
+ };
125
273
  if (rec === undefined)
126
274
  return { ...base, doc: null, sections: null };
127
275
  const head = await this.d.backend.read(rec.projectId, rec.docId);
@@ -144,10 +292,42 @@ export class WorkingDocService {
144
292
  }
145
293
  return this.eventLog;
146
294
  }
147
- /** Catch up every document crew holds (after a daemon restart, no further event may come for a run). */
148
- catchUp() {
149
- for (const rec of this.d.store.all())
150
- this.linesSoon(rec.runId);
295
+ /**
296
+ * After a daemon restart no further event may come for a run (a parked run waits on a person): bring every document
297
+ * crew holds up to date, and make one for the {@link CATCH_UP_LIVE_MAX} newest live runs that have none (rig run W12
298
+ * 9dd4f6d1: parked, never viewed, no document). One run at a time, so a start is never a storm. A finished run with no
299
+ * document gets none here: hundreds of finished runs would each be a document nobody asked for. Resolves when done;
300
+ * never rejects.
301
+ */
302
+ async catchUp() {
303
+ await this.contextCatchUp();
304
+ if (this.d.events === undefined)
305
+ return;
306
+ const held = this.d.store.all().map((r) => r.runId);
307
+ let fresh = [];
308
+ if (this.d.liveRuns !== undefined) {
309
+ try {
310
+ const have = new Set(held);
311
+ fresh = [...await this.d.liveRuns()]
312
+ .filter((r) => !have.has(r.runId))
313
+ .sort((a, b) => b.createdAt - a.createdAt)
314
+ .slice(0, CATCH_UP_LIVE_MAX)
315
+ .map((r) => r.runId);
316
+ }
317
+ catch (err) {
318
+ this.d.log?.(`[working-doc] catch-up could not list live runs: ${String(err)}`);
319
+ }
320
+ }
321
+ const gap = this.d.catchUpGapMs ?? 250;
322
+ const pause = () => (gap > 0 ? new Promise((r) => { const t = setTimeout(r, gap); t.unref?.(); }) : Promise.resolve());
323
+ for (const runId of held) {
324
+ await this.syncLines(runId).catch((err) => this.d.log?.(`[working-doc] catch-up ${runId}: ${String(err)}`));
325
+ await pause();
326
+ }
327
+ for (const runId of fresh) {
328
+ await this.syncLines(runId, { create: true }).catch((err) => this.d.log?.(`[working-doc] catch-up ${runId}: ${String(err)}`));
329
+ await pause();
330
+ }
151
331
  }
152
332
  /** The run's working document, created on first ask (its Goal seeded from the run's intent, by crew). The view is
153
333
  * read after the lock is released: `view()` settles a pending write under the same lock (review on #1218: reading it
@@ -189,7 +369,7 @@ export class WorkingDocService {
189
369
  async proposeNow(runId, input, actor) {
190
370
  const rec = this.d.store.get(runId);
191
371
  if (rec === undefined)
192
- return { ok: false, code: 404, error: 'this job has no working document yet' };
372
+ return { ok: false, code: 404, error: 'this job has no context document yet' };
193
373
  if (!Number.isInteger(input.base))
194
374
  return { ok: false, code: 400, error: 'base must be the version the edit was made on' };
195
375
  const plugin = input.plugin;
@@ -203,7 +383,7 @@ export class WorkingDocService {
203
383
  if (input.author === 'operator') {
204
384
  // A person's words are a person's only: a worker, system or plugin caller never writes as the operator.
205
385
  if (actor.kind !== 'human')
206
- return { ok: false, code: 403, error: 'only a person can edit the working document as the operator' };
386
+ return { ok: false, code: 403, error: 'only a person can edit the context document as the operator' };
207
387
  author = { kind: 'human', id: actor.id };
208
388
  }
209
389
  else if (input.author === 'plugin') {
@@ -234,9 +414,9 @@ export class WorkingDocService {
234
414
  await this.reconcile(runId);
235
415
  const head = await this.d.backend.read(rec.projectId, rec.docId);
236
416
  if (head === null)
237
- return { ok: false, code: 404, error: 'the working document is gone' };
417
+ return { ok: false, code: 404, error: 'the context document is gone' };
238
418
  if (head.head !== input.base)
239
- return { ok: false, code: 409, error: 'the working document changed since', head: head.head };
419
+ return { ok: false, code: 409, error: 'the context document changed since', head: head.head };
240
420
  if (this.d.store.get(runId)?.pending != null)
241
421
  return { ok: false, code: 409, error: 'an earlier edit may still land; read the document again', head: head.head };
242
422
  const before = sectionsOf(head.html);
@@ -263,8 +443,9 @@ export class WorkingDocService {
263
443
  throw err;
264
444
  }
265
445
  if ('headMoved' in written)
266
- return { ok: false, code: 409, error: 'the working document changed since', head: written.head };
267
- const steer = await this.record(runId, written.version, written.parent, author, surface, changed, values, actor, input.input);
446
+ return { ok: false, code: 409, error: 'the context document changed since', head: written.head };
447
+ // The version's sections, from what it was made on and what it changed (never a second, fallible read: xreview b1).
448
+ const steer = await this.record(runId, written.version, written.parent, author, surface, changed, values, actor, input.input, { ...before, ...values });
268
449
  return { ok: true, version: written.version, unchanged: false, steer, view: await this.view(runId) };
269
450
  }
270
451
  /**
@@ -338,7 +519,7 @@ export class WorkingDocService {
338
519
  }
339
520
  if ('headMoved' in written)
340
521
  continue;
341
- await this.record(runId, written.version, written.parent, { kind: 'agent', id }, null, changed, values, { id, kind: 'agent' });
522
+ await this.record(runId, written.version, written.parent, { kind: 'agent', id }, null, changed, values, { id, kind: 'agent' }, undefined, { ...before, ...values });
342
523
  return written.version;
343
524
  }
344
525
  return null;
@@ -348,20 +529,23 @@ export class WorkingDocService {
348
529
  * The document's EVENT-DERIVED lines (Decisions answered, Open questions, Next), brought up to date from the run's
349
530
  * own recorded events and written by crew as the Phase report plugin's actor ({@link PHASE_REPORT_AUTHOR}), whether
350
531
  * or not anyone has the run open (rig run ea73afc0: only a viewing tab wrote them). Like every plugin line they
351
- * never steer, and a person's own lines in those sections stay as they are, in place. A power run gets its document
352
- * here if it has none; any other run only once it has one. A person's edit racing this write wins: crew re-reads and
353
- * writes again on top of it (3 tries at most). Resolves to the version written, or `null` (nothing to change, no
354
- * log, no document).
532
+ * never steer, and a person's own lines in those sections stay as they are, in place. With `create` (a live event
533
+ * came for the run, or the start-up catch-up chose it) a run of any kind gets its document here if it has none
534
+ * (workdoc-all-runs, rig run W12: only power runs did). A phased run's Approach is its settled plan
535
+ * ({@link planApproach}), written as the plan's author seat. A person's edit racing a write wins: crew re-reads and
536
+ * writes again on top of it (3 tries at most). Resolves to the last version written, or `null` (nothing to change,
537
+ * no log, no document).
355
538
  */
356
- async syncLines(runId) {
539
+ async syncLines(runId, opts = {}) {
357
540
  // One sync per run at a time, each reading the log afresh (xreview on #1224: two overlapping reads could let an
358
541
  // older snapshot restore an answered question after a newer one wrote).
542
+ const create = opts.create === true;
359
543
  const prev = this.linesChain.get(runId) ?? Promise.resolve();
360
- const next = prev.then(() => this.syncLinesNow(runId), () => this.syncLinesNow(runId));
544
+ const next = prev.then(() => this.syncLinesNow(runId, create), () => this.syncLinesNow(runId, create));
361
545
  this.linesChain.set(runId, next.catch(() => null));
362
546
  return next;
363
547
  }
364
- async syncLinesNow(runId) {
548
+ async syncLinesNow(runId, create) {
365
549
  if (this.d.events === undefined)
366
550
  return null;
367
551
  const events = await this.d.events(runId);
@@ -371,90 +555,224 @@ export class WorkingDocService {
371
555
  }
372
556
  this.eventLog = true;
373
557
  const model = foldLines(events);
374
- if (!model.power && this.d.store.get(runId) === undefined)
558
+ // A power run makes its document on any sync, as before; any other run when a live event or the catch-up asks.
559
+ if (this.d.store.get(runId) === undefined && !create && !model.power)
375
560
  return null;
376
561
  if (!(await this.ensureDoc(runId)))
377
562
  return null;
378
- const lines = docLines(model);
379
- const id = PHASE_REPORT_AUTHOR;
563
+ let notes = [];
564
+ if (this.d.notes !== undefined) {
565
+ // The person's words are an addition: a trail that cannot be read leaves the engine-derived lines to be written
566
+ // (xreview r1), and Decisions never takes a line back, so the ones already there stay.
567
+ try {
568
+ notes = await this.d.notes(runId);
569
+ }
570
+ catch (err) {
571
+ this.d.log?.(`[working-doc] the person's answers for ${runId} could not be read: ${String(err)}`);
572
+ }
573
+ }
574
+ const lines = docLines(model, notes);
575
+ const approach = await this.planText(runId, model);
380
576
  return this.exclusive(runId, async () => {
577
+ if (this.d.store.get(runId) === undefined)
578
+ return null;
579
+ await this.reconcile(runId);
580
+ // Read after `reconcile`: it may just have recorded a person's write (xreview r1).
381
581
  const rec = this.d.store.get(runId);
382
582
  if (rec === undefined)
383
583
  return null;
384
- await this.reconcile(runId);
385
- if (this.d.store.get(runId)?.pending != null) {
584
+ if (rec.pending != null) {
386
585
  // A person's write of unknown outcome is still settling: try again once it has (it settles within ~75 s).
586
+ this.planChecked.delete(runId);
387
587
  this.linesSoon(runId, this.d.linesRetryMs ?? 15_000);
388
588
  return null;
389
589
  }
390
- for (let attempt = 0; attempt < 3; attempt++) {
391
- const head = await this.d.backend.read(rec.projectId, rec.docId);
392
- if (head === null)
393
- return null;
394
- const before = { ...blankSections(), ...sectionsOf(head.html) };
395
- const wanted = {};
396
- for (const sid of ['decisions', 'questions', 'next']) {
397
- const text = reconcileSection(sid, before[sid], lines[sid], SECTION_MAX_CHARS);
398
- if (text !== null)
399
- wanted[sid] = text;
400
- }
401
- const changed = changedSections(before, wanted);
402
- if (changed.length === 0)
403
- return null;
404
- const values = {};
405
- for (const sid of changed)
406
- values[sid] = wanted[sid] ?? '';
407
- let written;
590
+ let wrote = null;
591
+ if (approach !== null) {
592
+ // A person's Approach stands: a plan (even a revised one) never replaces it. Asked again on every try, against
593
+ // the run's own trail as it is then.
594
+ const personsApproach = () => [...(this.d.store.get(runId)?.trail ?? [])].reverse().find((t) => t.sections.includes('approach'))?.author.kind === 'human';
595
+ let r;
408
596
  try {
409
- written = await this.d.backend.edit(rec.projectId, rec.docId, {
410
- expectHead: head.head,
411
- items: changed.map((sid) => ({ selector: anchorOf(sid), value: encodeSectionText(values[sid] ?? '') })),
412
- author: id,
413
- });
597
+ r = await this.writeAs(runId, rec, approach.author, () => (personsApproach() ? {} : { approach: approach.text.slice(0, SECTION_MAX_CHARS) }));
414
598
  }
415
599
  catch (err) {
600
+ // Not known whether it landed: the lines wait for it to settle, then come (xreview r2: they were stranded).
416
601
  if (err instanceof UndeterminedWriteError)
417
- this.rememberPending(runId, head.head, { kind: 'plugin', id }, null, values, { id, kind: 'plugin' });
602
+ this.linesSoon(runId, this.d.linesRetryMs ?? 15_000);
418
603
  throw err;
419
604
  }
420
- if ('headMoved' in written)
421
- continue;
422
- await this.record(runId, written.version, written.parent, { kind: 'plugin', id }, null, changed, values, { id, kind: 'plugin' });
423
- return written.version;
605
+ // Only a settled outcome is remembered: a write that gave up is tried again on the next sync (xreview r1).
606
+ if (r !== null)
607
+ this.planChecked.set(runId, approach.key);
608
+ if (typeof r === 'number')
609
+ wrote = r;
424
610
  }
425
- return null;
611
+ let owned = new Set();
612
+ let decisionsAfter = '';
613
+ // What crew's lines in Decisions are after the write (a person's edit of one makes it theirs: its text no longer
614
+ // matches).
615
+ const mineAfter = () => decisionsAfter.split('\n').map((l) => l.trim())
616
+ .filter((l) => l !== '' && isGenerated('decisions', l) && (lines.decisions.includes(l) || owned.has(l)));
617
+ const v = await this.writeAs(runId, rec, { kind: 'plugin', id: PHASE_REPORT_AUTHOR }, (before) => {
618
+ // A record from before crew kept its own lines: the lines main treated as crew's (the legacy generated shape),
619
+ // so nothing a person had is newly treated as crew's (xreview r7: renamed gate words, refined pauses).
620
+ const kept = this.d.store.get(runId)?.ownedDecisions;
621
+ owned = new Set(kept ?? before.decisions.split('\n').map((l) => l.trim()).filter((l) => LEGACY_GENERATED_DECISION.test(l)));
622
+ const wanted = {};
623
+ for (const sid of ['decisions', 'questions', 'next']) {
624
+ const text = reconcileSection(sid, before[sid], lines[sid], SECTION_MAX_CHARS, sid === 'decisions' ? owned : undefined);
625
+ if (text !== null)
626
+ wanted[sid] = text;
627
+ }
628
+ decisionsAfter = wanted.decisions ?? before.decisions;
629
+ return wanted;
630
+ }, mineAfter);
631
+ if (v !== null) {
632
+ const mineNow = mineAfter();
633
+ if (mineNow.join('\n') !== (this.d.store.get(runId)?.ownedDecisions ?? []).join('\n')) {
634
+ this.d.store.update(runId, (r) => { r.ownedDecisions = mineNow; });
635
+ }
636
+ }
637
+ return typeof v === 'number' ? v : wrote;
426
638
  });
427
639
  }
428
- /** Bring the event-derived lines up to date shortly (a burst of events becomes one write). */
429
- linesSoon(runId, delayMs) {
430
- if (this.d.events === undefined || this.linesDue.has(runId))
640
+ /** (workdoc-all-runs) Something the run's document shows changed outside the engine's log (a person's answer
641
+ * recorded in crew's trail): bring it up to date shortly, making it if the run has none. */
642
+ nudge(runId) {
643
+ this.linesSoon(runId, undefined, true);
644
+ }
645
+ /**
646
+ * (workdoc-all-runs) A phased run's Approach: its plan once settled ({@link planSettled}), read from the run's own
647
+ * unit list, by the seat that wrote the plan (the plan gate's reviewed step) when known, else by crew. `null` for a
648
+ * power run (its orchestrator writes Approach), before the plan is settled, or when nothing moved since the last look.
649
+ */
650
+ async planText(runId, model) {
651
+ if (model.power || this.approachNoted.has(runId))
652
+ return null;
653
+ const settled = planSettled(model);
654
+ if (settled === null)
655
+ return null;
656
+ const key = `${settled.approvedAt}|${settled.authorOrd}|${model.started.join(',')}|${model.gates.length}|${model.planned}`;
657
+ if (this.planChecked.get(runId) === key)
658
+ return null;
659
+ const run = await this.d.run(runId);
660
+ if (run === null || run.power === true || run.steps === undefined)
661
+ return null;
662
+ // The plan the unit list shows must be the one the events settled: a revision (and its new plan gate) landing
663
+ // between the two reads would be written as approved (xreview r3). The event that changed it brings its own sync.
664
+ const again = this.d.events !== undefined ? await this.d.events(runId) : null;
665
+ if (again === null)
666
+ return null;
667
+ const now = foldLines(again);
668
+ const settledNow = planSettled(now);
669
+ if (settledNow === null || `${settledNow.approvedAt}|${settledNow.authorOrd}|${now.started.join(',')}|${now.gates.length}|${now.planned}` !== key)
670
+ return null;
671
+ const steps = [...run.steps].sort((a, b) => a.ord - b.ord);
672
+ const text = planApproach(steps.map((x) => x.name), settled.approvedAt);
673
+ if (text === null)
674
+ return null;
675
+ const seat = settled.authorOrd !== null ? steps.find((x) => x.ord === settled.authorOrd)?.seat ?? null : null;
676
+ return { text, key, author: seat !== null && AGENT_SEAT.test(seat) ? { kind: 'agent', id: `agent:${seat}` } : { kind: 'system', id: 'crew' } };
677
+ }
678
+ /** Crew's own write of some sections, as `author` (never a person, so it never steers), on the newest head; a person's
679
+ * edit racing it wins and the sections are computed again on top of it (3 tries at most). Inside the run's turn.
680
+ * Resolves to the version written, `'same'` when nothing needed changing, or `null` (gave up, or the doc is gone). */
681
+ async writeAs(runId, rec, author, compute, ownedAfter) {
682
+ const batchAuthor = author.kind === 'system' ? 'crew' : author.id;
683
+ for (let attempt = 0; attempt < 3; attempt++) {
684
+ const head = await this.d.backend.read(rec.projectId, rec.docId);
685
+ if (head === null)
686
+ return null;
687
+ const before = { ...blankSections(), ...sectionsOf(head.html) };
688
+ const wanted = compute(before);
689
+ const changed = changedSections(before, wanted);
690
+ if (changed.length === 0)
691
+ return 'same';
692
+ const values = {};
693
+ for (const sid of changed)
694
+ values[sid] = wanted[sid] ?? '';
695
+ let written;
696
+ try {
697
+ written = await this.d.backend.edit(rec.projectId, rec.docId, {
698
+ expectHead: head.head,
699
+ items: changed.map((sid) => ({ selector: anchorOf(sid), value: encodeSectionText(values[sid] ?? '') })),
700
+ author: batchAuthor,
701
+ });
702
+ }
703
+ catch (err) {
704
+ // Crew's own Decisions lines if this write landed travel with it, installed when it is confirmed (xreview r6).
705
+ if (err instanceof UndeterminedWriteError)
706
+ this.rememberPending(runId, head.head, author, null, values, { id: batchAuthor, kind: author.kind }, undefined, ownedAfter?.());
707
+ throw err;
708
+ }
709
+ if ('headMoved' in written)
710
+ continue;
711
+ await this.record(runId, written.version, written.parent, author, null, changed, values, { id: batchAuthor, kind: author.kind }, undefined, { ...before, ...values });
712
+ return written.version;
713
+ }
714
+ return null;
715
+ }
716
+ /** Bring the event-derived lines up to date shortly (a burst of events becomes one write). `create`: the sync may
717
+ * make the run's document (a live event came for it). */
718
+ linesSoon(runId, delayMs, create = false) {
719
+ if (this.d.events === undefined)
720
+ return;
721
+ if (create)
722
+ this.mayCreate.add(runId);
723
+ if (this.linesDue.has(runId))
431
724
  return;
432
725
  const t = setTimeout(() => {
433
726
  this.linesDue.delete(runId);
434
- void this.syncLines(runId).catch((err) => this.d.log?.(`[working-doc] lines for ${runId}: ${String(err)}`));
727
+ const made = this.mayCreate.delete(runId);
728
+ void this.syncLines(runId, { create: made }).catch((err) => this.d.log?.(`[working-doc] lines for ${runId}: ${String(err)}`));
435
729
  }, delayMs ?? this.d.linesDelayMs ?? 1_500);
436
730
  t.unref?.();
437
731
  this.linesDue.set(runId, t);
438
732
  }
439
733
  /** A write whose outcome is not known: remembered, so a later read attributes it if it lands, never to the next
440
734
  * caller, and looked at again on its own shortly, so its steer (a person's) is not left waiting for a reader. */
441
- rememberPending(runId, expectHead, author, surface, values, actor, spoken) {
442
- this.d.store.update(runId, (r) => { r.pending = { expectHead, author, surface, values, at: this.now(), actor: { id: actor.id, kind: actor.kind }, ...(spoken !== undefined ? { input: spoken } : {}) }; });
735
+ rememberPending(runId, expectHead, author, surface, values, actor, spoken, ownedDecisions) {
736
+ // One save: the write and (crew's lines write only) the ownership it carries (xreview r7).
737
+ this.d.store.update(runId, (r) => {
738
+ r.pending = {
739
+ expectHead, author, surface, values, at: this.now(), actor: { id: actor.id, kind: actor.kind },
740
+ ...(spoken !== undefined ? { input: spoken } : {}), ...(ownedDecisions !== undefined ? { ownedDecisions } : {}),
741
+ };
742
+ });
443
743
  for (const ms of [30_000, 75_000]) {
444
- const t = setTimeout(() => { void this.exclusive(runId, () => this.reconcile(runId)).catch(() => undefined); }, ms);
744
+ // Once settled, the event lines come too: a write that stalled may have kept them from being written (xreview r2).
745
+ const t = setTimeout(() => { void this.exclusive(runId, () => this.reconcile(runId)).then(() => this.linesSoon(runId), () => undefined); }, ms);
445
746
  t.unref?.();
446
747
  }
447
748
  }
448
749
  /** A version that landed: its trail entry, its steer (a person's only), its audit line and the change frame. */
449
- async record(runId, version, parent, author, surface, changed, values, actor, spoken) {
450
- const steer = author.kind === 'human' ? await this.steer(runId, version, changed, values, author.id, spoken) : null;
451
- const entry = { version, parent, author, surface, sections: changed, at: this.now(), steerId: steer?.id ?? null };
750
+ async record(runId, version, parent, author, surface, changed, values, actor, spoken, after) {
751
+ // The version's trail entry first (its steer, if any, is named on it below): the block and the steer read the trail.
752
+ const entry = { version, parent, author, surface, sections: changed, at: this.now(), steerId: null };
452
753
  this.d.store.update(runId, (r) => { r.trail.push(entry); });
754
+ // (context-doc-switch) A version that touched the person's context: the engine's block is set from THIS version's
755
+ // own sections and the trail up to it, inside the run's turn (so no later version is sent ahead of it), and BEFORE
756
+ // the version's Next note is queued, so the next step never takes Next under the context it replaced.
757
+ const owed = this.d.store.get(runId)?.context?.retry === true;
758
+ const block = this.blockMode() && (owed || changed.some((x) => CONTEXT_SECTIONS.includes(x))) && after !== undefined
759
+ ? this.contextBlock(runId, version, after, author.kind === 'human' ? { kind: 'human', id: contextAuthorId(author.id) } : { kind: 'system', id: 'crew' })
760
+ : null;
761
+ if (block !== null) {
762
+ // A new version gets its own retries.
763
+ this.contextRetries.delete(runId);
764
+ await this.sendContext(runId, block);
765
+ }
766
+ const steer = author.kind === 'human' ? await this.steer(runId, version, changed, values, author.id, spoken, after ?? values) : null;
767
+ if (steer !== null)
768
+ this.d.store.update(runId, (r) => { const t = r.trail.find((x) => x.version === version && x.steerId === null); if (t !== undefined)
769
+ t.steerId = steer.id; });
453
770
  this.d.audit?.('run.steered.doc', actor, runId, {
454
771
  version, sections: changed, author: author.kind === 'human' ? 'operator' : author.id,
455
772
  ...(surface !== null ? { surface } : {}),
456
773
  ...(steer !== null ? { steer: steer.id, kind: steer.kind, steered: steer.sections, sent: steer.error === null } : {}),
457
774
  ...(spoken !== undefined && author.kind === 'human' ? { input: spoken } : {}),
775
+ ...(block !== null ? { context: block.block.sections.map((x) => x.id) } : {}),
458
776
  });
459
777
  this.d.changed?.(runId, version);
460
778
  return steer;
@@ -477,28 +795,79 @@ export class WorkingDocService {
477
795
  }
478
796
  const got = sectionsOf(html);
479
797
  const ids = Object.keys(p.values);
480
- this.d.store.update(runId, (r) => { r.pending = null; });
481
- if (ids.every((id) => got[id] === p.values[id]))
482
- await this.record(runId, v, p.expectHead, p.author, p.surface, ids, p.values, p.actor, p.input);
798
+ const landed = ids.every((id) => got[id] === p.values[id]);
799
+ // One save: the write settled and, if it was crew's lines and landed, the ownership it carries (xreview r7).
800
+ this.d.store.update(runId, (r) => { r.pending = null; if (landed && p.ownedDecisions !== undefined)
801
+ r.ownedDecisions = p.ownedDecisions; });
802
+ if (landed) {
803
+ await this.record(runId, v, p.expectHead, p.author, p.surface, ids, p.values, p.actor, p.input, got);
804
+ }
483
805
  }
484
806
  /**
485
- * A person's version → ONE steering note for the run (§9): Goal, Approach and Next for the next step, and Constraints
486
- * and steering as a standing constraint (an emptied Constraints is said once, as cleared). The record is stored
487
- * BEFORE the engine is asked, so a pickup reported at once is never lost.
807
+ * A person's version → ONE steering note for the run (§9). With the engine's context block (`blockMode`): Goal,
808
+ * Approach and Constraints are in the block (set in `record`), every standing note is replaced, and only Next makes a
809
+ * note, for the next step. Without it (the bridge): the person's CURRENT Goal, Approach and Constraints stand together,
810
+ * replaced by the next edit of any of them, with Next for the next step and a cleared section said once. An engine
811
+ * that reports the block but has no way to set it (none in production): Goal, Approach and Next once, Constraints
812
+ * standing. The record is stored BEFORE the engine is asked, so a pickup reported at
813
+ * once is never lost. `after` is the version's sections as written.
488
814
  */
489
- async steer(runId, version, changed, values, by, spoken) {
815
+ async steer(runId, version, changed, values, by, spoken, after) {
490
816
  const steered = changed.filter((id) => SECTION_STEER[id] !== 'record');
491
817
  if (steered.length === 0)
492
818
  return null;
493
- const constraints = values.constraints;
494
- const standing = steered.includes('constraints') && constraints !== undefined && constraints.trim() !== '';
495
819
  const who = by === 'local' ? 'the operator' : by;
496
820
  const id = randomUUID().slice(0, 8);
497
821
  const marker = steerMarker(runId, id);
822
+ let standing;
823
+ let note;
824
+ let standingText = null;
825
+ // Which earlier standing steer this one replaces: any edit of the sections that stand.
826
+ let replaces;
827
+ if (this.blockMode()) {
828
+ // (context-doc-switch) The engine keeps the person's Goal, Approach and Constraints as the run's context block and
829
+ // hands it to every seat it spawns (crew sets it in `record`): no note carries them, and every standing note is
830
+ // replaced by an edit of them. Only Next still goes to the next step, once.
831
+ const once = steered.filter((x) => !CONTEXT_SECTIONS.includes(x));
832
+ replaces = steered.some((x) => CONTEXT_SECTIONS.includes(x));
833
+ if (replaces) {
834
+ this.d.store.update(runId, (r) => { for (const old of r.steers)
835
+ if (old.kind === 'standing' && old.supersededBy == null)
836
+ old.supersededBy = `v${version}`; });
837
+ }
838
+ if (once.length === 0)
839
+ return null;
840
+ standing = false;
841
+ replaces = false;
842
+ note = steerNote(version, who, false, once.map((x) => ({ id: x, text: values[x] ?? '' })), marker);
843
+ }
844
+ else if (this.d.engine.supportsRunContext?.() !== true) {
845
+ // (bridge, operator ruling 2026-11-06) The person's CURRENT Goal, Approach and Constraints (each section whose
846
+ // latest version is a person's, never crew's or an agent's) stand together, re-sent before every later worker step
847
+ // until the engine keeps a context block of its own. Next is still for the next step only.
848
+ replaces = steered.some((x) => CONTEXT_SECTIONS.includes(x));
849
+ const context = replaces ? this.personContext(runId, changed, after) : [];
850
+ standing = context.length > 0;
851
+ const inContext = new Set(context.map((c) => c.id));
852
+ note = contextSteerNote(version, who, context, steered.filter((x) => !inContext.has(x)).map((x) => ({ id: x, text: after[x] ?? values[x] ?? '' })), marker);
853
+ if (standing)
854
+ standingText = contextStandingNote(version, who, context, marker);
855
+ }
856
+ else {
857
+ const constraints = values.constraints;
858
+ standing = steered.includes('constraints') && constraints !== undefined && constraints.trim() !== '';
859
+ // A bridge note from before the engine had its block is replaced by any edit of what it carried (xreview b1).
860
+ replaces = steered.includes('constraints') || (steered.some((x) => CONTEXT_SECTIONS.includes(x))
861
+ && (this.d.store.get(runId)?.steers ?? []).some((o) => o.kind === 'standing' && o.supersededBy == null && o.context === true));
862
+ note = steerNote(version, who, standing, steered.map((x) => ({ id: x, text: values[x] ?? '' })), marker);
863
+ if (standing)
864
+ standingText = standingNote(version, who, constraints ?? '', marker);
865
+ }
498
866
  const s = {
499
- id, version, sections: steered, kind: standing ? 'standing' : 'next',
500
- note: steerNote(version, who, standing, steered.map((x) => ({ id: x, text: values[x] ?? '' })), marker),
501
- ...(standing ? { standingNote: standingNote(version, who, constraints ?? '', marker), supersededBy: null, renewals: 0 } : {}),
867
+ id, version, sections: this.blockMode() ? steered.filter((x) => !CONTEXT_SECTIONS.includes(x)) : steered, kind: standing ? 'standing' : 'next',
868
+ ...(standing && this.d.engine.supportsRunContext?.() !== true ? { context: true } : {}),
869
+ note,
870
+ ...(standingText !== null ? { standingNote: standingText, supersededBy: null, renewals: 0 } : {}),
502
871
  at: this.now(), by, queuedAt: null, pickedUp: null, error: null,
503
872
  ...(spoken !== undefined ? { input: spoken } : {}),
504
873
  };
@@ -506,8 +875,8 @@ export class WorkingDocService {
506
875
  if (run === null || run.terminal)
507
876
  s.error = 'the job has ended, so there is no next step to steer';
508
877
  this.d.store.update(runId, (r) => {
509
- // Any edit of Constraints (a new one, or emptied) replaces the standing one before it.
510
- if (steered.includes('constraints'))
878
+ // An edit of what stands (a new text, or emptied) replaces the standing steer before it.
879
+ if (replaces)
511
880
  for (const old of r.steers)
512
881
  if (old.kind === 'standing' && old.supersededBy == null)
513
882
  old.supersededBy = id;
@@ -526,6 +895,321 @@ export class WorkingDocService {
526
895
  }
527
896
  return this.d.store.get(runId)?.steers.find((y) => y.id === id) ?? s;
528
897
  }
898
+ /**
899
+ * (bridge) The person's current context in a version (`after`, its sections as written): each of Goal, Approach and
900
+ * Constraints whose latest write is a person's (this version's sections are). Crew's seeded Goal, a plan's Approach and
901
+ * an agent's notes are never in it: only a person's words steer.
902
+ */
903
+ personContext(runId, changed, after) {
904
+ const rec = this.d.store.get(runId);
905
+ if (rec === undefined)
906
+ return [];
907
+ const out = [];
908
+ for (const sid of CONTEXT_SECTIONS) {
909
+ const persons = changed.includes(sid) || [...rec.trail].reverse().find((t) => t.sections.includes(sid))?.author.kind === 'human';
910
+ const text = after[sid] ?? '';
911
+ if (persons && text.trim() !== '')
912
+ out.push({ id: sid, text });
913
+ }
914
+ return out;
915
+ }
916
+ // ── the engine's context block (context-doc-switch; core#1325) ────────────────────────────────────────────────────
917
+ /** The linked engine keeps a context block crew can set: the person's context goes there, not in notes. */
918
+ blockMode() {
919
+ return this.d.engine.supportsRunContext?.() === true && typeof this.d.engine.setRunContext === 'function';
920
+ }
921
+ /** The engine holds the run's block at `version` or later (crew heard it say so). */
922
+ blockCovers(runId, version) {
923
+ const inForce = this.d.store.get(runId)?.context?.inForce;
924
+ return this.blockMode() && typeof inForce === 'number' && inForce >= version;
925
+ }
926
+ /**
927
+ * The block of one version: each of Goal, Approach and Constraints whose newest write at or before `version` is a
928
+ * person's (crew's trail), with that version's text. Crew's seeded Goal, a plan's Approach, an agent's or a plugin's
929
+ * lines are never in it. Capped visibly ({@link capBlock}). `sections` are the version's own sections as written.
930
+ */
931
+ contextBlock(runId, version, sections, setBy) {
932
+ const trail = (this.d.store.get(runId)?.trail ?? []).filter((t) => t.version <= version);
933
+ const mine = [];
934
+ for (const sid of CONTEXT_SECTIONS) {
935
+ const last = [...trail].reverse().find((t) => t.sections.includes(sid));
936
+ if (last === undefined || last.author.kind !== 'human')
937
+ continue;
938
+ const text = contextText(sections[sid] ?? '');
939
+ if (text === '')
940
+ continue;
941
+ mine.push({ id: sid, text, author: { kind: 'human', id: contextAuthorId(last.author.id) }, version: last.version });
942
+ }
943
+ const capped = capBlock(mine);
944
+ return { block: { version, sections: capped.sections, set_by: setBy }, cut: capped.cut };
945
+ }
946
+ /**
947
+ * Set the run's block (inside the run's turn), unless it is the block crew last set and the engine took (the engine
948
+ * keeps it durably). The engine keeps the higher version, so an older block sent late is a no-op.
949
+ *
950
+ * - The attempt is recorded BEFORE the engine is asked: an answer lost (a timeout, a restart) never lets a later
951
+ * empty block be skipped as "nothing was ever set".
952
+ * - A refusal (`bad_request`, e.g. too long once framed) is recorded with the engine's reason, and the engine's block
953
+ * is CLEARED at that version, so no words the person has since replaced stay in force.
954
+ * - Any other failure (no answer in time, the engine down) and a clear that fails are retried from the document's
955
+ * head ({@link resyncContext}) a few times, then at the next start or edit; the view says so meanwhile.
956
+ * - An ended run (`conflict`) or one the engine does not know (`not_found`) is recorded, not retried.
957
+ *
958
+ * Never throws: the version is written whatever the engine says. The state is on the view (`context`), which studio
959
+ * shows with the document.
960
+ */
961
+ async sendContext(runId, b) {
962
+ const set = this.d.engine.setRunContext;
963
+ if (set === undefined)
964
+ return;
965
+ const v = b.block.version;
966
+ const sig = contextSig(b.block);
967
+ const prior = this.d.store.get(runId)?.context;
968
+ // An attempt whose answer crew never recorded (a restart mid-call) is unresolved: the block is sent again whatever
969
+ // its signature says (xreview r2).
970
+ const unresolved = (prior?.attempted ?? null) !== null && (prior?.sentVersion ?? -1) < (prior?.attempted ?? -1);
971
+ if (!unresolved && prior?.retry !== true && (prior?.sig ?? EMPTY_SIG) === sig && prior?.error == null)
972
+ return;
973
+ // Nothing of the person's, and nothing ever tried: there is no block to clear.
974
+ if (b.block.sections.length === 0 && (prior?.attempted ?? null) === null)
975
+ return;
976
+ const timeoutMs = this.d.contextTimeoutMs ?? CONTEXT_SET_TIMEOUT_MS;
977
+ const call = async (ctx) => {
978
+ // The set is owed until the engine's answer is recorded (xreview r3): a restart mid-call leaves it owed, so every
979
+ // recovery path (the start-up sync, its re-arm, the next version) sends it again.
980
+ this.updateContext(runId, (c) => { c.attempted = Math.max(c.attempted ?? 0, ctx.version); c.retry = true; });
981
+ const answer = set.call(this.d.engine, runId, ctx);
982
+ // An answer after the timeout is not awaited by anyone: its rejection must not go unhandled.
983
+ answer.catch(() => undefined);
984
+ let timer;
985
+ const late = new Promise((_, reject) => {
986
+ timer = setTimeout(() => reject(new Error('the engine did not answer in time')), timeoutMs);
987
+ timer.unref?.();
988
+ });
989
+ try {
990
+ return await Promise.race([answer, late]);
991
+ }
992
+ finally {
993
+ if (timer !== undefined)
994
+ clearTimeout(timer);
995
+ }
996
+ };
997
+ /** The engine holds exactly version `v`: a block's content at a version is fixed by the trail up to it, so it is
998
+ * this block (or, after a refusal, the clear). */
999
+ const holds = (c, ack, sections, cut, s) => {
1000
+ c.inForce = Math.max(c.inForce ?? 0, ack.version);
1001
+ if (ack.version !== v)
1002
+ return; // a newer block is in force: its metadata came with it
1003
+ c.sig = s;
1004
+ c.sentVersion = v;
1005
+ c.sections = sections.map((x) => x.id);
1006
+ c.cut = cut;
1007
+ c.at = this.now();
1008
+ };
1009
+ let retry = false;
1010
+ try {
1011
+ const ack = await call(b.block);
1012
+ this.updateContext(runId, (c) => {
1013
+ holds(c, ack, b.block.sections, b.cut, sig);
1014
+ if (c.error !== null && c.error.version <= Math.max(v, ack.version))
1015
+ c.error = null;
1016
+ c.retry = false;
1017
+ });
1018
+ this.contextRetries.delete(runId);
1019
+ }
1020
+ catch (err) {
1021
+ const msg = err instanceof Error ? err.message : String(err);
1022
+ let reason = msg.replace(/^bad_request:\s*(run context refused:\s*)?/u, '');
1023
+ let cleared = false;
1024
+ if (/^conflict:/u.test(msg)) {
1025
+ reason = 'the job has ended';
1026
+ this.updateContext(runId, (c) => { c.retry = false; });
1027
+ }
1028
+ else if (/^not_found:/u.test(msg)) {
1029
+ reason = 'the engine does not know this job';
1030
+ this.updateContext(runId, (c) => { c.retry = false; });
1031
+ }
1032
+ else if (/^bad_request:/u.test(msg)) {
1033
+ // Refused whole: withdraw the block in force, so the agents never keep the words the person has just replaced.
1034
+ const hadBlock = (prior?.sections.length ?? 0) > 0;
1035
+ try {
1036
+ const ack = await call({ version: v, sections: [], set_by: b.block.set_by });
1037
+ this.updateContext(runId, (c) => { holds(c, ack, [], [], EMPTY_SIG); c.retry = false; });
1038
+ cleared = hadBlock && ack.version === v;
1039
+ this.contextRetries.delete(runId);
1040
+ }
1041
+ catch (e2) {
1042
+ retry = true;
1043
+ reason = `${reason}; the earlier context could not be taken out yet, trying again`;
1044
+ this.d.log?.(`[working-doc] clearing the context block of ${runId} after a refusal failed: ${String(e2)}`);
1045
+ }
1046
+ }
1047
+ else {
1048
+ retry = true;
1049
+ reason = `${reason}; trying again`;
1050
+ }
1051
+ this.updateContext(runId, (c) => { c.error = { version: v, reason: reason.slice(0, 400), at: this.now(), cleared }; });
1052
+ this.d.log?.(`[working-doc] the context block v${v} of ${runId} was not set: ${msg}`);
1053
+ }
1054
+ if (retry)
1055
+ this.updateContext(runId, (c) => { c.retry = true; });
1056
+ this.d.changed?.(runId, null);
1057
+ if (retry)
1058
+ this.scheduleContextRetry(runId);
1059
+ }
1060
+ updateContext(runId, f) {
1061
+ this.d.store.update(runId, (r) => {
1062
+ r.context ??= { inForce: null, attempted: null, sig: null, sentVersion: null, sections: [], cut: [], at: null, error: null, retry: false, seenVersion: null, seenBy: [] };
1063
+ f(r.context);
1064
+ });
1065
+ }
1066
+ /** Try the run's block again later (a set with no answer, a clear that failed, a retry that could not read the
1067
+ * document): a few times, then the next start or the run's next version of any section (`record`). */
1068
+ scheduleContextRetry(runId) {
1069
+ const delays = this.d.contextRetryMs ?? [15_000, 60_000, 300_000];
1070
+ const n = this.contextRetries.get(runId) ?? 0;
1071
+ if (n >= delays.length) {
1072
+ // Out of tries for now: the view stops promising one (pi r2). The next version of any section, or the next start,
1073
+ // sends it again (`retry` stays set).
1074
+ this.updateContext(runId, (c) => { if (c.error !== null)
1075
+ c.error.reason = c.error.reason.replace(/trying again$/u, 'tried again at your next edit or the next start'); });
1076
+ this.d.changed?.(runId, null);
1077
+ return;
1078
+ }
1079
+ this.contextRetries.set(runId, n + 1);
1080
+ const t = setTimeout(() => {
1081
+ void this.resyncContext(runId).catch((err) => this.d.log?.(`[working-doc] context retry ${runId}: ${String(err)}`));
1082
+ }, delays[n]);
1083
+ t.unref?.();
1084
+ }
1085
+ /**
1086
+ * Set the run's block from its document's head (one read: the version and its HTML), inside the run's turn, after an
1087
+ * unknown-outcome write has settled: at daemon start ({@link contextCatchUp}) and on a retry. A finished run is
1088
+ * skipped. Never rejects.
1089
+ */
1090
+ async resyncContext(runId, knownLive = false) {
1091
+ if (!this.blockMode())
1092
+ return;
1093
+ try {
1094
+ // `run()` reads every run's view (the engine's whole-store fold): the start-up sync passes `knownLive` from its one
1095
+ // read instead of a fold per document (F35).
1096
+ if (!knownLive) {
1097
+ const run = await this.d.run(runId);
1098
+ if (run === null || run.terminal)
1099
+ return;
1100
+ }
1101
+ await this.exclusive(runId, async () => {
1102
+ await this.reconcile(runId);
1103
+ const now = this.d.store.get(runId);
1104
+ if (now === undefined)
1105
+ return;
1106
+ // A write of unknown outcome: its settling (`record`) sets the block, or the retry comes back for it.
1107
+ if (now.pending != null) {
1108
+ if (now.context?.retry === true || contextOwed(now))
1109
+ this.scheduleContextRetry(runId);
1110
+ return;
1111
+ }
1112
+ const head = await this.d.backend.read(now.projectId, now.docId);
1113
+ if (head === null)
1114
+ return;
1115
+ await this.sendContext(runId, this.contextBlock(runId, head.head, sectionsOf(head.html), { kind: 'system', id: 'crew' }));
1116
+ });
1117
+ }
1118
+ catch (err) {
1119
+ this.d.log?.(`[working-doc] context sync ${runId}: ${String(err)}`);
1120
+ // The document or the run could not be read: a retry owed stays owed, and so does a person's context write still
1121
+ // of unknown outcome (xreview F35 r2).
1122
+ const rec = this.d.store.get(runId);
1123
+ if (rec !== undefined && (rec.context?.retry === true || (rec.pending != null && contextOwed(rec))))
1124
+ this.scheduleContextRetry(runId);
1125
+ }
1126
+ }
1127
+ /** Once per document at daemon start (as soon as the daemon is up, ahead of the slower line catch-up): set every live
1128
+ * run's block from its head, so a block the engine lacks (an upgrade, a lost answer) is in force before the run's
1129
+ * next step. Serial, once per daemon; never rejects. */
1130
+ contextCatchUp() {
1131
+ this.contextCaughtUp ??= (async () => {
1132
+ if (!this.blockMode())
1133
+ return;
1134
+ // F35 (rig :7721 heap OOM): this used to visit EVERY held document (139 on the rig), each visit reading every run's
1135
+ // view (`run()`, an engine whole-store fold of ~30 MB parsed per caller) and the document through interactive, at
1136
+ // boot while studio's tabs reload. Now only the documents crew's own record says owe the engine a set are visited,
1137
+ // and which runs are live is read ONCE.
1138
+ const todo = this.d.store.all().filter((r) => contextOwed(r)).map((r) => r.runId);
1139
+ if (todo.length === 0)
1140
+ return;
1141
+ let live = null;
1142
+ if (this.d.liveRuns !== undefined) {
1143
+ try {
1144
+ live = new Set((await this.d.liveRuns()).map((r) => r.runId));
1145
+ }
1146
+ catch (err) {
1147
+ this.d.log?.(`[working-doc] context catch-up could not list live runs: ${String(err)}`);
1148
+ }
1149
+ }
1150
+ const gap = this.d.catchUpGapMs ?? 250;
1151
+ for (const runId of todo) {
1152
+ // Not in the live list (archived, or the list could not be read): its own check, bounded by the owed set.
1153
+ await this.resyncContext(runId, live?.has(runId) === true);
1154
+ if (gap > 0)
1155
+ await new Promise((r) => { const t = setTimeout(r, gap); t.unref?.(); });
1156
+ }
1157
+ })();
1158
+ return this.contextCaughtUp;
1159
+ }
1160
+ /** What the document's view says about the block, or null when there is nothing to say (no block engine, never fed). */
1161
+ contextView(rec) {
1162
+ const engine = this.blockMode();
1163
+ const c = rec.context;
1164
+ if (!engine && c === undefined)
1165
+ return null;
1166
+ return {
1167
+ engine,
1168
+ version: c?.inForce ?? null,
1169
+ sections: [...(c?.sections ?? [])],
1170
+ cut: [...(c?.cut ?? [])],
1171
+ at: c?.at ?? null,
1172
+ error: c?.error ?? null,
1173
+ seenBy: c !== undefined && c.seenVersion !== null && c.seenVersion === c.inForce ? [...c.seenBy] : [],
1174
+ };
1175
+ }
1176
+ /**
1177
+ * `runContextDelivered`: one seat the engine built a prompt for with the block (no text in the frame). It only names
1178
+ * who saw a version crew itself set: a version crew never tried, a malformed value or an unknown recipient is dropped,
1179
+ * and it never moves the version in force (only the engine's answers to crew's own sets do).
1180
+ */
1181
+ delivered(runId, ev) {
1182
+ const version = ev['version'];
1183
+ const recipient = ev['recipient'];
1184
+ const cli = ev['recipientCli'];
1185
+ const ord = ev['ord'];
1186
+ if (typeof version !== 'number' || !Number.isSafeInteger(version) || version < 0)
1187
+ return;
1188
+ if (typeof recipient !== 'string' || !CONTEXT_RECIPIENTS.has(recipient))
1189
+ return;
1190
+ const attempted = this.d.store.get(runId)?.context?.attempted ?? null;
1191
+ if (attempted === null || version > attempted)
1192
+ return;
1193
+ const seat = typeof cli === 'string' && /^[a-z0-9][a-z0-9._-]{0,39}$/u.test(cli) ? cli : '';
1194
+ const at = typeof ord === 'number' && Number.isSafeInteger(ord) && ord >= 0 ? ord : 0;
1195
+ let changed = false;
1196
+ // One synchronous update (no await inside): atomic against the run's other context writes.
1197
+ this.updateContext(runId, (c) => {
1198
+ if (c.seenVersion !== null && version < c.seenVersion)
1199
+ return;
1200
+ if (c.seenVersion !== version) {
1201
+ c.seenVersion = version;
1202
+ c.seenBy = [];
1203
+ changed = true;
1204
+ }
1205
+ if (c.seenBy.some((x) => x.recipient === recipient && x.cli === seat) || c.seenBy.length >= CONTEXT_SEEN_MAX)
1206
+ return;
1207
+ c.seenBy.push({ recipient, cli: seat, ord: at });
1208
+ changed = true;
1209
+ });
1210
+ if (changed)
1211
+ this.d.changed?.(runId, null);
1212
+ }
529
1213
  /**
530
1214
  * The daemon's CoreEvent tap.
531
1215
  *
@@ -543,8 +1227,9 @@ export class WorkingDocService {
543
1227
  const runId = typeof ev['session'] === 'string' ? ev['session'] : null;
544
1228
  if (runId === null)
545
1229
  return;
1230
+ // Any run, power or not, viewed or not: a live line event makes the run's document if it has none (rig run W12).
546
1231
  if (LINE_EVENTS.has(ev['type']))
547
- this.linesSoon(runId);
1232
+ this.linesSoon(runId, undefined, true);
548
1233
  if (ev['type'] === 'powerTurnCompleted') {
549
1234
  // (rig run 1d372696) The orchestrator wrote no APPROACH line, so the document stayed empty. Its own turn
550
1235
  // summary is the Approach, as the agent, unless it stated one itself or a person wrote it (agentNotes).
@@ -583,6 +1268,10 @@ export class WorkingDocService {
583
1268
  const rec = this.d.store.get(runId);
584
1269
  if (rec === undefined)
585
1270
  return;
1271
+ if (ev['type'] === 'runContextDelivered') {
1272
+ this.delivered(runId, ev);
1273
+ return;
1274
+ }
586
1275
  if (e.type === 'unitDone' || e.type === 'unitDenied') {
587
1276
  for (const s of rec.steers) {
588
1277
  if (s.kind === 'standing' && s.supersededBy == null && s.error === null && s.pickedUp !== null && this.queued.get(s.id) !== true)
@@ -627,6 +1316,18 @@ export class WorkingDocService {
627
1316
  this.queued.set(steerId, false);
628
1317
  return;
629
1318
  }
1319
+ // A bridge note is not re-sent once the engine keeps a context block of its own (xreview b1): crew feeds that.
1320
+ if (current.context === true && this.d.engine.supportsRunContext?.() === true && !this.blockMode()) {
1321
+ this.queued.set(steerId, false);
1322
+ return;
1323
+ }
1324
+ // (context-doc-switch) No standing note is re-sent once the engine holds the run's block at this note's version or
1325
+ // later: the block carries the person's context to every seat. Until then (a daemon just started, the catch-up not
1326
+ // yet run) the note keeps the person's words in front of the next step.
1327
+ if (this.blockCovers(runId, current.version)) {
1328
+ this.queued.set(steerId, false);
1329
+ return;
1330
+ }
630
1331
  const run = await this.d.run(runId);
631
1332
  if (run === null || run.terminal || this.d.store.get(runId)?.steers.find((x) => x.id === steerId)?.supersededBy != null) {
632
1333
  this.queued.set(steerId, false);