wicked-crew 0.17.0 → 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 (547) hide show
  1. package/README.md +71 -18
  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 +192 -0
  16. package/dist/api/chat-jobs.d.ts.map +1 -0
  17. package/dist/api/chat-jobs.js +929 -0
  18. package/dist/api/chat-jobs.js.map +1 -0
  19. package/dist/api/chat-proposals.d.ts +323 -7
  20. package/dist/api/chat-proposals.d.ts.map +1 -1
  21. package/dist/api/chat-proposals.js +1581 -40
  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-assurance.d.ts.map +1 -1
  36. package/dist/api/delivery-assurance.js +5 -2
  37. package/dist/api/delivery-assurance.js.map +1 -1
  38. package/dist/api/delivery-index.d.ts +109 -5
  39. package/dist/api/delivery-index.d.ts.map +1 -1
  40. package/dist/api/delivery-index.js +199 -7
  41. package/dist/api/delivery-index.js.map +1 -1
  42. package/dist/api/mcp.d.ts +7 -2
  43. package/dist/api/mcp.d.ts.map +1 -1
  44. package/dist/api/mcp.js +1 -1
  45. package/dist/api/mcp.js.map +1 -1
  46. package/dist/api/needs.d.ts.map +1 -1
  47. package/dist/api/needs.js +19 -1
  48. package/dist/api/needs.js.map +1 -1
  49. package/dist/api/product.d.ts +87 -3
  50. package/dist/api/product.d.ts.map +1 -1
  51. package/dist/api/product.js +155 -68
  52. package/dist/api/product.js.map +1 -1
  53. package/dist/api/proposal-theme.d.ts +23 -0
  54. package/dist/api/proposal-theme.d.ts.map +1 -0
  55. package/dist/api/proposal-theme.js +30 -0
  56. package/dist/api/proposal-theme.js.map +1 -0
  57. package/dist/api/recording.d.ts +127 -10
  58. package/dist/api/recording.d.ts.map +1 -1
  59. package/dist/api/recording.js +320 -68
  60. package/dist/api/recording.js.map +1 -1
  61. package/dist/api/repo-input.d.ts +55 -0
  62. package/dist/api/repo-input.d.ts.map +1 -0
  63. package/dist/api/repo-input.js +113 -0
  64. package/dist/api/repo-input.js.map +1 -0
  65. package/dist/api/requirements.d.ts +75 -0
  66. package/dist/api/requirements.d.ts.map +1 -1
  67. package/dist/api/requirements.js +97 -9
  68. package/dist/api/requirements.js.map +1 -1
  69. package/dist/api/review-change.d.ts +64 -0
  70. package/dist/api/review-change.d.ts.map +1 -0
  71. package/dist/api/review-change.js +214 -0
  72. package/dist/api/review-change.js.map +1 -0
  73. package/dist/api/roster-standing.d.ts +4 -0
  74. package/dist/api/roster-standing.d.ts.map +1 -1
  75. package/dist/api/roster-standing.js +43 -10
  76. package/dist/api/roster-standing.js.map +1 -1
  77. package/dist/api/routes.d.ts +138 -12
  78. package/dist/api/routes.d.ts.map +1 -1
  79. package/dist/api/routes.js +1496 -301
  80. package/dist/api/routes.js.map +1 -1
  81. package/dist/api/run-documents.d.ts +97 -0
  82. package/dist/api/run-documents.d.ts.map +1 -0
  83. package/dist/api/run-documents.js +458 -0
  84. package/dist/api/run-documents.js.map +1 -0
  85. package/dist/api/run-sources.d.ts +51 -0
  86. package/dist/api/run-sources.d.ts.map +1 -0
  87. package/dist/api/run-sources.js +133 -0
  88. package/dist/api/run-sources.js.map +1 -0
  89. package/dist/api/run-timing-index.d.ts +12 -1
  90. package/dist/api/run-timing-index.d.ts.map +1 -1
  91. package/dist/api/run-timing-index.js +35 -0
  92. package/dist/api/run-timing-index.js.map +1 -1
  93. package/dist/api/runtime-state.d.ts +41 -0
  94. package/dist/api/runtime-state.d.ts.map +1 -0
  95. package/dist/api/runtime-state.js +75 -0
  96. package/dist/api/runtime-state.js.map +1 -0
  97. package/dist/api/seat-container-login.d.ts +51 -0
  98. package/dist/api/seat-container-login.d.ts.map +1 -1
  99. package/dist/api/seat-container-login.js +317 -1
  100. package/dist/api/seat-container-login.js.map +1 -1
  101. package/dist/api/seat-images.d.ts.map +1 -1
  102. package/dist/api/seat-images.js +7 -0
  103. package/dist/api/seat-images.js.map +1 -1
  104. package/dist/api/server.d.ts +7 -0
  105. package/dist/api/server.d.ts.map +1 -1
  106. package/dist/api/server.js +207 -26
  107. package/dist/api/server.js.map +1 -1
  108. package/dist/api/skills.d.ts +8 -0
  109. package/dist/api/skills.d.ts.map +1 -1
  110. package/dist/api/skills.js +21 -0
  111. package/dist/api/skills.js.map +1 -1
  112. package/dist/api/system-snapshot.d.ts +3 -2
  113. package/dist/api/system-snapshot.d.ts.map +1 -1
  114. package/dist/api/system-snapshot.js +19 -6
  115. package/dist/api/system-snapshot.js.map +1 -1
  116. package/dist/api/testing.d.ts +3 -3
  117. package/dist/api/ui-text.d.ts +45 -0
  118. package/dist/api/ui-text.d.ts.map +1 -0
  119. package/dist/api/ui-text.js +188 -0
  120. package/dist/api/ui-text.js.map +1 -0
  121. package/dist/apps/actions/card.d.ts +62 -0
  122. package/dist/apps/actions/card.d.ts.map +1 -0
  123. package/dist/apps/actions/card.js +111 -0
  124. package/dist/apps/actions/card.js.map +1 -0
  125. package/dist/apps/actions/write-path.d.ts.map +1 -1
  126. package/dist/apps/actions/write-path.js +26 -77
  127. package/dist/apps/actions/write-path.js.map +1 -1
  128. package/dist/apps/exec/sources.d.ts.map +1 -1
  129. package/dist/apps/exec/sources.js +3 -0
  130. package/dist/apps/exec/sources.js.map +1 -1
  131. package/dist/apps/exec/texts.d.ts +1 -1
  132. package/dist/apps/publish/artifacts.d.ts +18 -0
  133. package/dist/apps/publish/artifacts.d.ts.map +1 -0
  134. package/dist/apps/publish/artifacts.js +87 -0
  135. package/dist/apps/publish/artifacts.js.map +1 -0
  136. package/dist/apps/publish/check.d.ts +103 -0
  137. package/dist/apps/publish/check.d.ts.map +1 -0
  138. package/dist/apps/publish/check.js +235 -0
  139. package/dist/apps/publish/check.js.map +1 -0
  140. package/dist/apps/publish/image.d.ts +2 -0
  141. package/dist/apps/publish/image.d.ts.map +1 -1
  142. package/dist/apps/publish/image.js +2 -1
  143. package/dist/apps/publish/image.js.map +1 -1
  144. package/dist/apps/publish/render.d.ts +71 -0
  145. package/dist/apps/publish/render.d.ts.map +1 -0
  146. package/dist/apps/publish/render.js +122 -0
  147. package/dist/apps/publish/render.js.map +1 -0
  148. package/dist/apps/publish/run.d.ts +35 -0
  149. package/dist/apps/publish/run.d.ts.map +1 -0
  150. package/dist/apps/publish/run.js +127 -0
  151. package/dist/apps/publish/run.js.map +1 -0
  152. package/dist/apps/routes.d.ts +54 -2
  153. package/dist/apps/routes.d.ts.map +1 -1
  154. package/dist/apps/routes.js +124 -7
  155. package/dist/apps/routes.js.map +1 -1
  156. package/dist/apps/spec.d.ts +8 -8
  157. package/dist/apps/store.d.ts +84 -5
  158. package/dist/apps/store.d.ts.map +1 -1
  159. package/dist/apps/store.js +191 -4
  160. package/dist/apps/store.js.map +1 -1
  161. package/dist/apps/turns.d.ts +19 -1
  162. package/dist/apps/turns.d.ts.map +1 -1
  163. package/dist/apps/turns.js +60 -2
  164. package/dist/apps/turns.js.map +1 -1
  165. package/dist/apps/views.d.ts +5 -1
  166. package/dist/apps/views.d.ts.map +1 -1
  167. package/dist/apps/views.js +18 -7
  168. package/dist/apps/views.js.map +1 -1
  169. package/dist/apps-server/Dockerfile +25 -0
  170. package/dist/apps-server/runners/sqlite-runner.mjs +110 -0
  171. package/dist/apps-server/server/lib/bundle/server.mjs +92523 -0
  172. package/dist/apps-server/server/node_modules/@pgsql/types/LICENSE +22 -0
  173. package/dist/apps-server/server/node_modules/@pgsql/types/README.md +106 -0
  174. package/dist/apps-server/server/node_modules/@pgsql/types/enums.d.ts +76 -0
  175. package/dist/apps-server/server/node_modules/@pgsql/types/enums.js +2 -0
  176. package/dist/apps-server/server/node_modules/@pgsql/types/esm/enums.js +1 -0
  177. package/dist/apps-server/server/node_modules/@pgsql/types/esm/index.js +2 -0
  178. package/dist/apps-server/server/node_modules/@pgsql/types/esm/types.js +1 -0
  179. package/dist/apps-server/server/node_modules/@pgsql/types/index.d.ts +2 -0
  180. package/dist/apps-server/server/node_modules/@pgsql/types/index.js +18 -0
  181. package/dist/apps-server/server/node_modules/@pgsql/types/package.json +36 -0
  182. package/dist/apps-server/server/node_modules/@pgsql/types/types.d.ts +2488 -0
  183. package/dist/apps-server/server/node_modules/@pgsql/types/types.js +2 -0
  184. package/dist/apps-server/server/node_modules/libpg-query/LICENSE +22 -0
  185. package/dist/apps-server/server/node_modules/libpg-query/README.md +275 -0
  186. package/dist/apps-server/server/node_modules/libpg-query/package.json +58 -0
  187. package/dist/apps-server/server/node_modules/libpg-query/wasm/index.cjs +369 -0
  188. package/dist/apps-server/server/node_modules/libpg-query/wasm/index.d.ts +48 -0
  189. package/dist/apps-server/server/node_modules/libpg-query/wasm/index.js +344 -0
  190. package/dist/apps-server/server/node_modules/libpg-query/wasm/libpg-query.js +2 -0
  191. package/dist/apps-server/server/node_modules/libpg-query/wasm/libpg-query.wasm +0 -0
  192. package/dist/apps-server/server/shim/host.css +22 -0
  193. package/dist/apps-server/server/shim/host.js +1 -0
  194. package/dist/cli/apps-check.d.ts +18 -0
  195. package/dist/cli/apps-check.d.ts.map +1 -1
  196. package/dist/cli/apps-check.js +179 -5
  197. package/dist/cli/apps-check.js.map +1 -1
  198. package/dist/cli/apps-produce.d.ts +9 -0
  199. package/dist/cli/apps-produce.d.ts.map +1 -0
  200. package/dist/cli/apps-produce.js +27 -0
  201. package/dist/cli/apps-produce.js.map +1 -0
  202. package/dist/cli/index.d.ts.map +1 -1
  203. package/dist/cli/index.js +15 -3
  204. package/dist/cli/index.js.map +1 -1
  205. package/dist/cli/insights-facts.d.ts +17 -0
  206. package/dist/cli/insights-facts.d.ts.map +1 -0
  207. package/dist/cli/insights-facts.js +56 -0
  208. package/dist/cli/insights-facts.js.map +1 -0
  209. package/dist/core/adapter.d.ts +85 -16
  210. package/dist/core/adapter.d.ts.map +1 -1
  211. package/dist/core/adapter.js +274 -54
  212. package/dist/core/adapter.js.map +1 -1
  213. package/dist/core/builtin-catalog.d.ts.map +1 -1
  214. package/dist/core/builtin-catalog.js +2 -0
  215. package/dist/core/builtin-catalog.js.map +1 -1
  216. package/dist/core/deliver-text.d.ts +42 -6
  217. package/dist/core/deliver-text.d.ts.map +1 -1
  218. package/dist/core/deliver-text.js +204 -27
  219. package/dist/core/deliver-text.js.map +1 -1
  220. package/dist/core/deliver.d.ts.map +1 -1
  221. package/dist/core/deliver.js +28 -7
  222. package/dist/core/deliver.js.map +1 -1
  223. package/dist/core/engine-roster.d.ts.map +1 -1
  224. package/dist/core/engine-roster.js +1 -0
  225. package/dist/core/engine-roster.js.map +1 -1
  226. package/dist/core/estate-mcp-client.d.ts +3 -2
  227. package/dist/core/estate-mcp-client.d.ts.map +1 -1
  228. package/dist/core/estate-mcp-client.js +3 -2
  229. package/dist/core/estate-mcp-client.js.map +1 -1
  230. package/dist/core/qe-acceptance-setting.d.ts.map +1 -1
  231. package/dist/core/qe-acceptance-setting.js +6 -0
  232. package/dist/core/qe-acceptance-setting.js.map +1 -1
  233. package/dist/core/run-identity.d.ts.map +1 -1
  234. package/dist/core/run-identity.js +3 -0
  235. package/dist/core/run-identity.js.map +1 -1
  236. package/dist/core/types.d.ts +5 -0
  237. package/dist/core/types.d.ts.map +1 -1
  238. package/dist/core/types.js.map +1 -1
  239. package/dist/editors/conformance-runtime.d.ts +107 -0
  240. package/dist/editors/conformance-runtime.d.ts.map +1 -1
  241. package/dist/editors/conformance-runtime.js +268 -13
  242. package/dist/editors/conformance-runtime.js.map +1 -1
  243. package/dist/editors/csp.d.ts +2 -2
  244. package/dist/editors/csp.d.ts.map +1 -1
  245. package/dist/editors/csp.js +4 -2
  246. package/dist/editors/csp.js.map +1 -1
  247. package/dist/editors/pack-install.d.ts +28 -13
  248. package/dist/editors/pack-install.d.ts.map +1 -1
  249. package/dist/editors/pack-install.js +96 -48
  250. package/dist/editors/pack-install.js.map +1 -1
  251. package/dist/editors/registry.d.ts +111 -8
  252. package/dist/editors/registry.d.ts.map +1 -1
  253. package/dist/editors/registry.js +183 -7
  254. package/dist/editors/registry.js.map +1 -1
  255. package/dist/editors/routes.d.ts +66 -13
  256. package/dist/editors/routes.d.ts.map +1 -1
  257. package/dist/editors/routes.js +277 -44
  258. package/dist/editors/routes.js.map +1 -1
  259. package/dist/evals/replay.d.ts +6 -0
  260. package/dist/evals/replay.d.ts.map +1 -1
  261. package/dist/evals/replay.js +24 -1
  262. package/dist/evals/replay.js.map +1 -1
  263. package/dist/evals/routes.d.ts.map +1 -1
  264. package/dist/evals/routes.js +17 -2
  265. package/dist/evals/routes.js.map +1 -1
  266. package/dist/evals/runner.d.ts.map +1 -1
  267. package/dist/evals/runner.js +5 -0
  268. package/dist/evals/runner.js.map +1 -1
  269. package/dist/evals/shape-corrections.d.ts +146 -0
  270. package/dist/evals/shape-corrections.d.ts.map +1 -0
  271. package/dist/evals/shape-corrections.js +394 -0
  272. package/dist/evals/shape-corrections.js.map +1 -0
  273. package/dist/evals/shape.d.ts +145 -0
  274. package/dist/evals/shape.d.ts.map +1 -0
  275. package/dist/evals/shape.js +376 -0
  276. package/dist/evals/shape.js.map +1 -0
  277. package/dist/evals/types.d.ts +2 -2
  278. package/dist/evals/types.d.ts.map +1 -1
  279. package/dist/evals/types.js +2 -1
  280. package/dist/evals/types.js.map +1 -1
  281. package/dist/insights/analyze.d.ts +14 -1
  282. package/dist/insights/analyze.d.ts.map +1 -1
  283. package/dist/insights/analyze.js +35 -8
  284. package/dist/insights/analyze.js.map +1 -1
  285. package/dist/insights/cost.d.ts +123 -0
  286. package/dist/insights/cost.d.ts.map +1 -0
  287. package/dist/insights/cost.js +221 -0
  288. package/dist/insights/cost.js.map +1 -0
  289. package/dist/insights/review-service.d.ts +20 -1
  290. package/dist/insights/review-service.d.ts.map +1 -1
  291. package/dist/insights/review-service.js +50 -25
  292. package/dist/insights/review-service.js.map +1 -1
  293. package/dist/insights/routes.d.ts +29 -0
  294. package/dist/insights/routes.d.ts.map +1 -1
  295. package/dist/insights/routes.js +62 -0
  296. package/dist/insights/routes.js.map +1 -1
  297. package/dist/insights/run-facts.d.ts +16 -0
  298. package/dist/insights/run-facts.d.ts.map +1 -1
  299. package/dist/insights/run-facts.js +26 -3
  300. package/dist/insights/run-facts.js.map +1 -1
  301. package/dist/interactive/bridge-pool.d.ts +11 -2
  302. package/dist/interactive/bridge-pool.d.ts.map +1 -1
  303. package/dist/interactive/bridge-pool.js +10 -1
  304. package/dist/interactive/bridge-pool.js.map +1 -1
  305. package/dist/interactive/chat-events.d.ts +74 -1
  306. package/dist/interactive/chat-events.d.ts.map +1 -1
  307. package/dist/interactive/chat-events.js +338 -6
  308. package/dist/interactive/chat-events.js.map +1 -1
  309. package/dist/interactive/doc-binding.d.ts +15 -0
  310. package/dist/interactive/doc-binding.d.ts.map +1 -1
  311. package/dist/interactive/doc-binding.js +4 -0
  312. package/dist/interactive/doc-binding.js.map +1 -1
  313. package/dist/interactive/doc-checks-routes.d.ts +34 -1
  314. package/dist/interactive/doc-checks-routes.d.ts.map +1 -1
  315. package/dist/interactive/doc-checks-routes.js +84 -0
  316. package/dist/interactive/doc-checks-routes.js.map +1 -1
  317. package/dist/interactive/draft-events.d.ts +7 -0
  318. package/dist/interactive/draft-events.d.ts.map +1 -1
  319. package/dist/interactive/draft-events.js +38 -6
  320. package/dist/interactive/draft-events.js.map +1 -1
  321. package/dist/interactive/draft-skill.d.ts +76 -6
  322. package/dist/interactive/draft-skill.d.ts.map +1 -1
  323. package/dist/interactive/draft-skill.js +219 -17
  324. package/dist/interactive/draft-skill.js.map +1 -1
  325. package/dist/interactive/edit-events.d.ts.map +1 -1
  326. package/dist/interactive/edit-events.js +4 -2
  327. package/dist/interactive/edit-events.js.map +1 -1
  328. package/dist/interactive/landing-guard.d.ts +47 -0
  329. package/dist/interactive/landing-guard.d.ts.map +1 -0
  330. package/dist/interactive/landing-guard.js +43 -0
  331. package/dist/interactive/landing-guard.js.map +1 -0
  332. package/dist/interactive/landing-record.d.ts +68 -0
  333. package/dist/interactive/landing-record.d.ts.map +1 -0
  334. package/dist/interactive/landing-record.js +154 -0
  335. package/dist/interactive/landing-record.js.map +1 -0
  336. package/dist/interactive/proposal-create.d.ts +3 -1
  337. package/dist/interactive/proposal-create.d.ts.map +1 -1
  338. package/dist/interactive/proposal-create.js +14 -2
  339. package/dist/interactive/proposal-create.js.map +1 -1
  340. package/dist/interactive/proposal-refine.d.ts +48 -0
  341. package/dist/interactive/proposal-refine.d.ts.map +1 -0
  342. package/dist/interactive/proposal-refine.js +99 -0
  343. package/dist/interactive/proposal-refine.js.map +1 -0
  344. package/dist/interactive/protected-edits.d.ts +67 -0
  345. package/dist/interactive/protected-edits.d.ts.map +1 -0
  346. package/dist/interactive/protected-edits.js +160 -0
  347. package/dist/interactive/protected-edits.js.map +1 -0
  348. package/dist/interactive/proxy-routes.js +2 -2
  349. package/dist/interactive/review-events.js +1 -1
  350. package/dist/interactive/run-units.d.ts +1 -1
  351. package/dist/interactive/run-units.d.ts.map +1 -1
  352. package/dist/interactive/run-units.js +8 -2
  353. package/dist/interactive/run-units.js.map +1 -1
  354. package/dist/interactive/source-packet.d.ts +66 -1
  355. package/dist/interactive/source-packet.d.ts.map +1 -1
  356. package/dist/interactive/source-packet.js +309 -60
  357. package/dist/interactive/source-packet.js.map +1 -1
  358. package/dist/interactive/theme-events.js +1 -1
  359. package/dist/knowledge/adapters/web/egress.d.ts +99 -0
  360. package/dist/knowledge/adapters/web/egress.d.ts.map +1 -0
  361. package/dist/knowledge/adapters/web/egress.js +330 -0
  362. package/dist/knowledge/adapters/web/egress.js.map +1 -0
  363. package/dist/knowledge/adapters/web/engine.d.ts +54 -0
  364. package/dist/knowledge/adapters/web/engine.d.ts.map +1 -0
  365. package/dist/knowledge/adapters/web/engine.js +101 -0
  366. package/dist/knowledge/adapters/web/engine.js.map +1 -0
  367. package/dist/knowledge/adapters/web/fetch.d.ts +131 -0
  368. package/dist/knowledge/adapters/web/fetch.d.ts.map +1 -0
  369. package/dist/knowledge/adapters/web/fetch.js +325 -0
  370. package/dist/knowledge/adapters/web/fetch.js.map +1 -0
  371. package/dist/knowledge/adapters/web/gate-web.d.ts +182 -0
  372. package/dist/knowledge/adapters/web/gate-web.d.ts.map +1 -0
  373. package/dist/knowledge/adapters/web/gate-web.js +496 -0
  374. package/dist/knowledge/adapters/web/gate-web.js.map +1 -0
  375. package/dist/knowledge/adapters/web/routes.d.ts +36 -0
  376. package/dist/knowledge/adapters/web/routes.d.ts.map +1 -0
  377. package/dist/knowledge/adapters/web/routes.js +99 -0
  378. package/dist/knowledge/adapters/web/routes.js.map +1 -0
  379. package/dist/knowledge/adapters/web/searxng.d.ts +89 -0
  380. package/dist/knowledge/adapters/web/searxng.d.ts.map +1 -0
  381. package/dist/knowledge/adapters/web/searxng.js +274 -0
  382. package/dist/knowledge/adapters/web/searxng.js.map +1 -0
  383. package/dist/knowledge/adapters/web/source.d.ts +65 -0
  384. package/dist/knowledge/adapters/web/source.d.ts.map +1 -0
  385. package/dist/knowledge/adapters/web/source.js +192 -0
  386. package/dist/knowledge/adapters/web/source.js.map +1 -0
  387. package/dist/knowledge/gate/gate.d.ts +22 -0
  388. package/dist/knowledge/gate/gate.d.ts.map +1 -1
  389. package/dist/knowledge/gate/gate.js +62 -1
  390. package/dist/knowledge/gate/gate.js.map +1 -1
  391. package/dist/knowledge/gate/sources.d.ts +2 -0
  392. package/dist/knowledge/gate/sources.d.ts.map +1 -1
  393. package/dist/knowledge/gate/sources.js +5 -2
  394. package/dist/knowledge/gate/sources.js.map +1 -1
  395. package/dist/knowledge/package.d.ts +7 -0
  396. package/dist/knowledge/package.d.ts.map +1 -1
  397. package/dist/knowledge/package.js +15 -1
  398. package/dist/knowledge/package.js.map +1 -1
  399. package/dist/knowledge/trackers/actions.js +1 -1
  400. package/dist/knowledge/trackers/actions.js.map +1 -1
  401. package/dist/knowledge/trackers/bindings.d.ts +3 -3
  402. package/dist/knowledge/trackers/bindings.d.ts.map +1 -1
  403. package/dist/knowledge/trackers/bindings.js +36 -23
  404. package/dist/knowledge/trackers/bindings.js.map +1 -1
  405. package/dist/knowledge/trackers/routes.js +1 -1
  406. package/dist/knowledge/trackers/routes.js.map +1 -1
  407. package/dist/learnings/service.d.ts.map +1 -1
  408. package/dist/learnings/service.js +2 -0
  409. package/dist/learnings/service.js.map +1 -1
  410. package/dist/mcp/broker.d.ts +8 -0
  411. package/dist/mcp/broker.d.ts.map +1 -1
  412. package/dist/mcp/broker.js +48 -3
  413. package/dist/mcp/broker.js.map +1 -1
  414. package/dist/mcp/estate-relay.d.ts +43 -1
  415. package/dist/mcp/estate-relay.d.ts.map +1 -1
  416. package/dist/mcp/estate-relay.js +38 -2
  417. package/dist/mcp/estate-relay.js.map +1 -1
  418. package/dist/mcp/registry.d.ts +6 -0
  419. package/dist/mcp/registry.d.ts.map +1 -1
  420. package/dist/mcp/registry.js +42 -3
  421. package/dist/mcp/registry.js.map +1 -1
  422. package/dist/mcp/run-fence.d.ts +57 -0
  423. package/dist/mcp/run-fence.d.ts.map +1 -0
  424. package/dist/mcp/run-fence.js +86 -0
  425. package/dist/mcp/run-fence.js.map +1 -0
  426. package/dist/mcp/tool-list.d.ts +5 -0
  427. package/dist/mcp/tool-list.d.ts.map +1 -1
  428. package/dist/mcp/tool-list.js +7 -3
  429. package/dist/mcp/tool-list.js.map +1 -1
  430. package/dist/presets/routes.d.ts.map +1 -1
  431. package/dist/presets/routes.js +6 -0
  432. package/dist/presets/routes.js.map +1 -1
  433. package/dist/projects/routes.d.ts +1 -1
  434. package/dist/projects/state-home-preflight.d.ts.map +1 -1
  435. package/dist/projects/state-home-preflight.js +2 -0
  436. package/dist/projects/state-home-preflight.js.map +1 -1
  437. package/dist/setup/tool-path.d.ts +16 -0
  438. package/dist/setup/tool-path.d.ts.map +1 -0
  439. package/dist/setup/tool-path.js +66 -0
  440. package/dist/setup/tool-path.js.map +1 -0
  441. package/dist/skills/plugin-source.d.ts +42 -88
  442. package/dist/skills/plugin-source.d.ts.map +1 -1
  443. package/dist/skills/plugin-source.js +140 -100
  444. package/dist/skills/plugin-source.js.map +1 -1
  445. package/dist/skills/runtime.d.ts.map +1 -1
  446. package/dist/skills/runtime.js +15 -7
  447. package/dist/skills/runtime.js.map +1 -1
  448. package/dist/skills/store.d.ts.map +1 -1
  449. package/dist/skills/store.js +25 -14
  450. package/dist/skills/store.js.map +1 -1
  451. package/dist/skills/usage.d.ts +238 -0
  452. package/dist/skills/usage.d.ts.map +1 -0
  453. package/dist/skills/usage.js +789 -0
  454. package/dist/skills/usage.js.map +1 -0
  455. package/dist/skills/venv.d.ts +18 -2
  456. package/dist/skills/venv.d.ts.map +1 -1
  457. package/dist/skills/venv.js +2 -2
  458. package/dist/skills/venv.js.map +1 -1
  459. package/dist/sources/routes.d.ts +3 -1
  460. package/dist/sources/routes.d.ts.map +1 -1
  461. package/dist/sources/routes.js +11 -0
  462. package/dist/sources/routes.js.map +1 -1
  463. package/dist/standing-orders/parse.d.ts +19 -0
  464. package/dist/standing-orders/parse.d.ts.map +1 -1
  465. package/dist/standing-orders/parse.js +61 -18
  466. package/dist/standing-orders/parse.js.map +1 -1
  467. package/dist/studio/apps-standalone/fixture.html +12 -0
  468. package/dist/studio/apps-standalone/fixture.js +10 -0
  469. package/dist/studio/apps-standalone/runtime.css +139 -0
  470. package/dist/studio/apps-standalone/runtime.js +1 -0
  471. package/dist/studio/assets/{KnowledgeGraph-Cpm46tEp.js → KnowledgeGraph-AtkRlS3c.js} +1 -1
  472. package/dist/studio/assets/index-CdbCAs7s.css +32 -0
  473. package/dist/studio/assets/index-DU_8o4uq.js +1104 -0
  474. package/dist/studio/editors/wicked-apps/editor.json +1 -1
  475. package/dist/studio/editors/wicked-apps/index.html +2 -2
  476. package/dist/studio/editors/wicked-deck/editor.json +1 -1
  477. package/dist/studio/editors/wicked-deck/index.html +14 -1
  478. package/dist/studio/editors/wicked-doc/editor.json +1 -1
  479. package/dist/studio/editors/wicked-doc/index.html +1 -1
  480. package/dist/studio/editors/wicked-insights/editor.json +1 -1
  481. package/dist/studio/editors/wicked-insights/index.html +1 -1
  482. package/dist/studio/editors/wicked-page/editor.json +10 -1
  483. package/dist/studio/editors/wicked-page/index.html +2 -2
  484. package/dist/studio/editors/wicked-video/editor.json +7 -2
  485. package/dist/studio/editors/wicked-video/index.html +14 -11
  486. package/dist/studio/index.html +2 -2
  487. package/dist/studio/testid-inventory.json +2069 -242
  488. package/dist/team/routes.d.ts +11 -1
  489. package/dist/team/routes.d.ts.map +1 -1
  490. package/dist/team/routes.js +27 -0
  491. package/dist/team/routes.js.map +1 -1
  492. package/dist/workflow-catalog/build-v2.d.ts +94 -0
  493. package/dist/workflow-catalog/build-v2.d.ts.map +1 -0
  494. package/dist/workflow-catalog/build-v2.js +551 -0
  495. package/dist/workflow-catalog/build-v2.js.map +1 -0
  496. package/dist/workflow-catalog/catalog-data-v2.d.ts +12 -0
  497. package/dist/workflow-catalog/catalog-data-v2.d.ts.map +1 -0
  498. package/dist/workflow-catalog/catalog-data-v2.js +2787 -0
  499. package/dist/workflow-catalog/catalog-data-v2.js.map +1 -0
  500. package/dist/workflow-catalog/catalog-data.d.ts.map +1 -1
  501. package/dist/workflow-catalog/catalog-data.js +2 -20
  502. package/dist/workflow-catalog/catalog-data.js.map +1 -1
  503. package/dist/workflow-catalog/detect-service.d.ts +95 -0
  504. package/dist/workflow-catalog/detect-service.d.ts.map +1 -0
  505. package/dist/workflow-catalog/detect-service.js +239 -0
  506. package/dist/workflow-catalog/detect-service.js.map +1 -0
  507. package/dist/workflow-catalog/detect.d.ts +213 -0
  508. package/dist/workflow-catalog/detect.d.ts.map +1 -0
  509. package/dist/workflow-catalog/detect.js +653 -0
  510. package/dist/workflow-catalog/detect.js.map +1 -0
  511. package/dist/workflow-catalog/seeds-v2.d.ts +91 -0
  512. package/dist/workflow-catalog/seeds-v2.d.ts.map +1 -0
  513. package/dist/workflow-catalog/seeds-v2.js +2 -0
  514. package/dist/workflow-catalog/seeds-v2.js.map +1 -0
  515. package/dist/workflow-catalog/shape.d.ts +99 -0
  516. package/dist/workflow-catalog/shape.d.ts.map +1 -0
  517. package/dist/workflow-catalog/shape.js +103 -0
  518. package/dist/workflow-catalog/shape.js.map +1 -0
  519. package/dist/working-doc/bridge-backend.js +2 -2
  520. package/dist/working-doc/event-lines.d.ts +67 -2
  521. package/dist/working-doc/event-lines.d.ts.map +1 -1
  522. package/dist/working-doc/event-lines.js +155 -8
  523. package/dist/working-doc/event-lines.js.map +1 -1
  524. package/dist/working-doc/notes-index.d.ts +35 -0
  525. package/dist/working-doc/notes-index.d.ts.map +1 -0
  526. package/dist/working-doc/notes-index.js +82 -0
  527. package/dist/working-doc/notes-index.js.map +1 -0
  528. package/dist/working-doc/routes.js +4 -4
  529. package/dist/working-doc/sections.js +2 -2
  530. package/dist/working-doc/service.d.ts +260 -21
  531. package/dist/working-doc/service.d.ts.map +1 -1
  532. package/dist/working-doc/service.js +791 -90
  533. package/dist/working-doc/service.js.map +1 -1
  534. package/dist/working-doc/store.d.ts +50 -1
  535. package/dist/working-doc/store.d.ts.map +1 -1
  536. package/dist/working-doc/store.js +4 -1
  537. package/dist/working-doc/store.js.map +1 -1
  538. package/endpoint-manifest.json +219 -5
  539. package/evals/corpora/shape-corrections-v1.json +594 -0
  540. package/evals/corpora/shape-corrections-v1.seat-fixture.json +186 -0
  541. package/evals/corpora/shape-v1.json +2113 -0
  542. package/evals/corpora/shape-v1.seat-fixture.json +1800 -0
  543. package/package.json +31 -8
  544. package/scripts/apps-render.py +226 -0
  545. package/workflows/detect-shape.json +29 -0
  546. package/dist/studio/assets/index-BRBwWQMH.css +0 -32
  547. package/dist/studio/assets/index-CVrWDGRP.js +0 -1097
@@ -0,0 +1,929 @@
1
+ /**
2
+ * JOB PROPOSALS: the conversation's facts (DES-CATALOG-002 §2.4, §4.6).
3
+ *
4
+ * A job proposal is work in a chat: a v2 card (and option) whose resolved launch is a run, a compose or a demo. Every
5
+ * fact on it is crew's, computed here from crew's own resolution (`workflow-catalog/build-v2.ts`), never from a seat's
6
+ * words: the card and option, the repository and project from the chat's scope, the seats from the roster, the checks
7
+ * from the composed plan, the time, the sentence wicked says ("what Start runs"), its tokens and their swaps, at most two
8
+ * suggestions, the one question when something is missing, and the starting shape.
9
+ *
10
+ * A correction is a {@link ProposalRevision} merged by fixed rules ({@link mergeRevision}). The one rule that guards
11
+ * assurance is step 7: a result with fewer checks than its parent is never written from a seat's block — it becomes a
12
+ * question naming what is lost, whose lossy choice only a person's press applies (`confirmLoss`, person route only).
13
+ * A QE skip from a seat counts only when its reason appears, unquoted and not reported, in the person's own message
14
+ * that turn answers.
15
+ */
16
+ import { createHash } from 'node:crypto';
17
+ import { CATALOG_V2_CARDS } from '../workflow-catalog/catalog-data-v2.js';
18
+ import { resolveOption } from '../workflow-catalog/build-v2.js';
19
+ import { DEPTH_LINES } from '../workflow-catalog/shape.js';
20
+ // ── words ──────────────────────────────────────────────────────────────────────────────────────────────────────────
21
+ /** How the sentence names each card and option ("I'll run this as **an upgrade** of …"): one entry per card. */
22
+ const NOUNS = {
23
+ 'plan-it': { _: 'a plan' },
24
+ feature: { _: 'a feature' },
25
+ bug: { _: 'a bug fix' },
26
+ migrate: { move: 'a move', 'in-place': 'an in-place migration', upgrade: 'an upgrade' },
27
+ refactor: { refactor: 'a refactor', polish: 'a polish' },
28
+ release: { _: 'a release' },
29
+ 'start-new': { cli: 'a new CLI', service: 'a new service', library: 'a new library', 'mcp-server': 'a new MCP server' },
30
+ 'studio-plugin': { editor: 'an editor plugin', phase: 'a phase plugin' },
31
+ 'plan-tests': { _: 'a test plan' },
32
+ 'test-analysis': { _: 'a test analysis' },
33
+ 'write-tests': { _: 'new tests' },
34
+ 'suite-health': { flaky: 'a flaky-test cleanup', weak: 'a weak-test cleanup', snapshots: 'a snapshot cleanup', slow: 'a slow-test cleanup' },
35
+ incident: { _: 'an incident investigation' },
36
+ competitive: { _: 'a competitive analysis' },
37
+ 'due-diligence': { _: 'a due diligence review' },
38
+ research: { _: 'a cited answer' },
39
+ reconstruct: { _: 'a reconstruction of what happened' },
40
+ 'analyze-codebase': { overview: 'an overview of how it works', domain: 'a domain map', docs: 'a docs-versus-code check' },
41
+ 'map-requirements': { _: 'a requirements map' },
42
+ 'analyze-documents': { _: 'an analysis of your documents' },
43
+ 'review-change': { _: 'a review of the change' },
44
+ critique: { _: 'a critique' },
45
+ risk: { _: 'a risk analysis' },
46
+ security: { security: 'a security review', privacy: 'a privacy review', compliance: 'a compliance review' },
47
+ decide: { _: 'a decision record' },
48
+ document: { document: 'a document', presentation: 'a presentation', 'repo-docs': 'docs in the repo' },
49
+ 'interactive-page': { _: 'an interactive page' },
50
+ 'demo-video': { _: 'a demo video' },
51
+ respond: { rfp: 'an RFP response', rfi: 'an RFI response', questionnaire: 'a filled-in questionnaire' },
52
+ rework: { condense: 'a condensed version', 're-audience': 'a version for another audience', generalize: 'a general version', convert: 'a converted version', refresh: 'a refreshed version' },
53
+ communicate: { narrative: 'a narrative', 'meeting-prep': 'meeting prep', 'demo-script': 'a demo script', 'status-update': 'a status update', message: 'a message' },
54
+ 'estimate-price': { _: 'an estimate and price' },
55
+ 'run-cost': { _: 'a run cost model' },
56
+ backlog: { epics: 'epics', stories: 'stories', tasks: 'tasks' },
57
+ 'operating-model': { _: 'roles and an operating model' },
58
+ 'analyze-runs': { _: 'an analysis of your runs' },
59
+ 'review-recent-work': { _: 'a review of recent work' },
60
+ propose: { rules: 'proposed rules', memories: 'proposed memories', knowledge: 'proposed knowledge' },
61
+ 'evaluate-rules': { _: 'a rules evaluation' },
62
+ retro: { _: 'a retro' },
63
+ };
64
+ /** "an upgrade", or the card's title in lower case for a card the table does not name. */
65
+ export function nounOf(card, option) {
66
+ const n = NOUNS[card.id];
67
+ const hit = n?.[option ?? '_'] ?? n?.['_'];
68
+ if (hit !== undefined)
69
+ return hit;
70
+ const opt = card.variant?.options.find((o) => o.id === option);
71
+ return `${card.title.toLowerCase()}${opt !== undefined ? ` (${opt.title.toLowerCase()})` : ''}`;
72
+ }
73
+ const GATE_WORDS = {
74
+ 'qe-acceptance': 'QE acceptance',
75
+ parity: 'a parity check',
76
+ 'cited-findings': 'cited findings, each re-checked',
77
+ 'fidelity-to-source': 'a check against its sources',
78
+ 'proposal-only': 'your approval of everything it proposes',
79
+ 'evidence-floor': 'the evidence floor',
80
+ 'install-consent': 'your consent before it installs',
81
+ walkthrough: 'a walkthrough review',
82
+ pick: 'your pick',
83
+ 'draft-floor': 'the draft floor',
84
+ 'traces-to-requirements': 'a trace to each requirement',
85
+ review: 'a review on another seat',
86
+ };
87
+ const list = (xs) => xs.length <= 1 ? (xs[0] ?? '') : xs.length === 2 ? `${xs[0]} and ${xs[1]}` : `${xs.slice(0, -1).join(', ')} and ${xs[xs.length - 1]}`;
88
+ export const checksLabel = (gate) => (gate.length === 0 ? 'its own steps' : list(gate.map((g) => GATE_WORDS[g])));
89
+ const humanStep = (id) => {
90
+ const words = id.replace(/[-_]+/g, ' ').trim();
91
+ return words === '' ? id : `${words[0].toUpperCase()}${words.slice(1)}`;
92
+ };
93
+ /** Workflows whose launch picks its own seat (the run review's preparer, the default evals' Tool step): the proposal's
94
+ * seats are not what runs there, so they are neither shown as choosable nor sent (codex r2). */
95
+ export const SELF_SEATED = new Set(['review-recent-work', 'run-evals']);
96
+ export class JobRefusal extends Error {
97
+ code;
98
+ status;
99
+ constructor(code, message, status = 400) {
100
+ super(message);
101
+ this.code = code;
102
+ this.status = status;
103
+ }
104
+ }
105
+ /** The kind a resolved option proposes as: a run, a compose or a demo is a job; a document is an artifact create. */
106
+ export function proposalKindOf(r) {
107
+ const k = r.resolved.launch.kind;
108
+ if (k === 'run' || k === 'compose' || k === 'demo')
109
+ return 'job';
110
+ if (k === 'document')
111
+ return 'create';
112
+ return r.resolved.status === 'coming_soon' ? 'job' : 'none';
113
+ }
114
+ /** The seats a card needs to check its own work (Q31: words name who builds; the reviewer and judge stay). */
115
+ export function seatsNeeded(r) {
116
+ return 1 + (r.resolved.seats.distinctEvaluator ? 1 : 0) + (r.resolved.seats.distinctJudge ? 1 : 0);
117
+ }
118
+ function seatsOf(facts, ctx, r) {
119
+ const can = new Set(ctx.roster.map((s) => s.key));
120
+ const name = (k) => ctx.roster.find((s) => s.key === k)?.name ?? k;
121
+ const ordered = [...new Set([facts.lead, ctx.chat.lead, ...ctx.chat.seats, ...ctx.roster.map((s) => s.key)].filter((k) => k !== null && can.has(k)))];
122
+ const keys = facts.seats !== null ? facts.seats.filter((k) => can.has(k)) : ordered;
123
+ const lead = facts.lead !== null && keys.includes(facts.lead) ? facts.lead : (keys[0] ?? null);
124
+ const rest = keys.filter((k) => k !== lead);
125
+ const others = rest.map(name);
126
+ const label = lead === null
127
+ ? 'no seat that can work now'
128
+ : others.length === 0
129
+ ? name(lead)
130
+ : facts.lead !== null && facts.seats === null
131
+ ? `${name(lead)}, with ${list(others)} checking it`
132
+ : list([name(lead), ...others]);
133
+ return { seats: { lead, keys: lead === null ? [] : [lead, ...rest], label }, short: (lead === null ? 0 : 1 + rest.length) < seatsNeeded(r) };
134
+ }
135
+ function inputValueLabel(v) {
136
+ if (v.kind === 'requirements')
137
+ return `${v.refs.length} requirement${v.refs.length === 1 ? '' : 's'}`;
138
+ if (v.kind === 'documents')
139
+ return `${v.tokens.length} document${v.tokens.length === 1 ? '' : 's'}`;
140
+ if (v.kind === 'sources')
141
+ return list(v.ids.map((id) => id === 'web' ? 'the web' : id)) || 'no sources';
142
+ return v.value;
143
+ }
144
+ function sourcesLabel(ids, sources) {
145
+ if (sources === undefined)
146
+ return 'no sources on this daemon';
147
+ return list(ids.map((id) => sources.find((s) => s.id === id)?.label ?? (id === 'web' ? 'the web' : id))) || 'no sources';
148
+ }
149
+ function needsOf(facts, ctx, r) {
150
+ const out = [];
151
+ for (const i of r.resolved.inputs) {
152
+ if (i.id === 'seats')
153
+ continue;
154
+ if (i.id === 'intent') {
155
+ out.push({ id: i.id, label: i.label, kind: i.kind, required: i.required, status: facts.words.trim() !== '' ? 'met' : 'missing', ...(facts.words.trim() !== '' ? { value: facts.words.trim().slice(0, 200) } : {}) });
156
+ continue;
157
+ }
158
+ if (i.id === 'repo') {
159
+ const hit = ctx.chat.repos.find((x) => x.id === facts.repoRef);
160
+ const choices = ctx.chat.repos.slice(0, 8).map((x) => ({ label: x.name, value: x.id }));
161
+ out.push({ id: i.id, label: i.label, kind: i.kind, required: i.required, status: hit !== undefined ? 'met' : 'missing', ...(hit !== undefined ? { value: hit.id } : {}), ...(choices.length > 0 ? { choices } : {}) });
162
+ continue;
163
+ }
164
+ if (i.id === 'project') {
165
+ out.push({ id: i.id, label: i.label, kind: i.kind, required: i.required, status: facts.projectId !== null ? 'met' : 'missing', ...(facts.projectId !== null ? { value: facts.projectId } : {}) });
166
+ continue;
167
+ }
168
+ const v = facts.inputs[i.id];
169
+ if (i.kind === 'documents') {
170
+ const ok = ctx.documents?.filter((s) => s.status === 'ok').length ?? 0;
171
+ out.push({ id: i.id, label: i.label, kind: i.kind, required: i.required, status: ok > 0 ? 'met' : 'missing', value: `${ok} document${ok === 1 ? '' : 's'}` });
172
+ continue;
173
+ }
174
+ if (i.kind === 'sources') {
175
+ out.push({ id: i.id, label: i.label, kind: i.kind, required: i.required, status: 'met', value: sourcesLabel(v?.kind === 'sources' ? v.ids : [], ctx.jobSources).slice(0, 200) });
176
+ continue;
177
+ }
178
+ out.push({ id: i.id, label: i.label, kind: i.kind, required: i.required, status: v !== undefined ? 'met' : 'missing', ...(v !== undefined ? { value: inputValueLabel(v).slice(0, 200) } : {}) });
179
+ }
180
+ return out;
181
+ }
182
+ /** The repository a job runs on: the one named, else the chat's only one. */
183
+ export function repoOf(facts, chat) {
184
+ if (facts.repoRef !== null)
185
+ return chat.repos.find((r) => r.id === facts.repoRef) ?? null;
186
+ return chat.repos.length === 1 ? chat.repos[0] : null;
187
+ }
188
+ /** The checks a resolution carries, the QE skip taken off. */
189
+ export function checksOf(r, skipQe) {
190
+ return r.resolved.gate.filter((g) => !(g === 'qe-acceptance' && skipQe !== null));
191
+ }
192
+ function sketchOf(r) {
193
+ const launch = r.resolved.launch.kind;
194
+ if (launch === 'compose')
195
+ return { steps: [{ label: 'Draft', asks: false }, { label: 'Review', asks: true }] };
196
+ const steps = r.steps.map((s) => {
197
+ const gate = s['gate'];
198
+ const asks = gate === 'consent_before' || (gate !== null && typeof gate === 'object' && (gate['human_confirm'] !== undefined || gate['human_confirm_if'] !== undefined));
199
+ return { label: humanStep(s.id), asks };
200
+ });
201
+ return { steps };
202
+ }
203
+ const minutesLabel = (m) => {
204
+ if (m === null)
205
+ return null;
206
+ const fmt = (x) => (x >= 60 ? `${Math.round((x / 60) * 10) / 10} h` : `${x} min`);
207
+ return `About ${fmt(m[0])}–${fmt(m[1])}`;
208
+ };
209
+ const STOPS = {
210
+ run: 'Asks you to approve the plan first.',
211
+ compose: 'Stops for you at the review.',
212
+ demo: 'Stops for you after the script and after the review.',
213
+ };
214
+ // ── the resolution ─────────────────────────────────────────────────────────────────────────────────────────────────
215
+ /** The option a card proposes when none is named (Q23 asks for the most used; the default stands in until usage is read). */
216
+ export function optionFor(card, option) {
217
+ if (option !== undefined)
218
+ return option;
219
+ return card.variant?.default ?? null;
220
+ }
221
+ /**
222
+ * Resolve a job proposal from its facts. Refuses (a {@link JobRefusal}) an unknown card or option and a hidden card
223
+ * reached by anything but its alias; everything else resolves, with what cannot run yet as `blocked` or the question.
224
+ */
225
+ export function resolveJob(facts, ctx, opts = {}) {
226
+ const card = CATALOG_V2_CARDS.find((c) => c.id === facts.card);
227
+ if (card === undefined)
228
+ throw new JobRefusal('card_unknown', `there is no job called “${facts.card.slice(0, 80)}”`);
229
+ if (card.hidden === true && opts.allowHidden !== true)
230
+ throw new JobRefusal('card_hidden', `${card.title} is reached only by its own command`);
231
+ const optionId = optionFor(card, facts.option);
232
+ const r = resolveOption(card.id, optionId, ctx.served);
233
+ if (r === null)
234
+ throw new JobRefusal('card_unknown', `${card.title} has no option “${String(optionId).slice(0, 80)}”`);
235
+ if (facts.depth !== null && card.depth !== true)
236
+ throw new JobRefusal('edits_invalid', `${card.title} takes no depth`);
237
+ // An Investigate card's depth is always one of three: the default is standard, shown and launched alike.
238
+ if (card.depth === true && facts.depth === null)
239
+ facts = { ...facts, depth: 'standard' };
240
+ const kind = proposalKindOf(r);
241
+ if (kind !== 'job')
242
+ throw new JobRefusal('not_a_job', `${card.title} makes a document: it is proposed as one`);
243
+ const notes = [...ctx.notes];
244
+ const takesDocuments = r.resolved.inputs.some((i) => i.id === 'documents');
245
+ const takesSources = r.resolved.inputs.some((i) => i.id === 'sources');
246
+ if (takesSources) {
247
+ const current = facts.inputs['sources'];
248
+ const defaultWeb = current === undefined && (card.id === 'research' || card.id === 'competitive');
249
+ // A revision replaces the pick only through the merge's checks. Keep an existing pick for the launch's fresh
250
+ // check, even if a switch changed since: a refresh must not silently choose different sources for the person.
251
+ let ids = current?.kind === 'sources' && ctx.jobSources !== undefined ? [...new Set(current.ids)] : [];
252
+ if (defaultWeb) {
253
+ const web = ctx.jobSources?.find((s) => s.web === true);
254
+ if (web !== undefined && web.reason === undefined)
255
+ ids = [web.id];
256
+ else
257
+ notes.push(`the web can't be read: ${web?.reason ?? ctx.webReason ?? 'not available on this daemon'}`);
258
+ }
259
+ facts = { ...facts, inputs: { ...facts.inputs, sources: { kind: 'sources', ids } } };
260
+ }
261
+ const repo = repoOf(facts, ctx.chat);
262
+ const { seats, short } = seatsOf(facts, ctx, r);
263
+ const needs = needsOf({ ...facts, repoRef: repo?.id ?? null }, ctx, r);
264
+ const qeOffHere = ctx.qeOff === true && facts.skipQe === null && r.resolved.gate.includes('qe-acceptance');
265
+ const gate = checksOf(r, facts.skipQe).filter((g) => !(qeOffHere && g === 'qe-acceptance'));
266
+ if (qeOffHere)
267
+ notes.push('QE acceptance is off on this daemon (Settings), so this job runs without it, labelled.');
268
+ const launch = r.resolved.launch.kind;
269
+ const shape = {
270
+ card: card.id,
271
+ option: r.option?.id ?? null,
272
+ depth: facts.depth,
273
+ by: facts.by,
274
+ source: facts.source,
275
+ ...(facts.guess !== undefined ? { guess: facts.guess } : {}),
276
+ };
277
+ const optTitle = r.option?.title ?? null;
278
+ const label = `${card.title}${optTitle !== null ? ` · ${optTitle}` : ''}`;
279
+ const command = r.option?.command ?? card.command;
280
+ const blockedBy = [];
281
+ let coming;
282
+ if (r.resolved.status === 'coming_soon') {
283
+ coming = { release: card.release, note: r.resolved.statusNote ?? card.statusNote ?? null, nearest: card.nearest ?? null };
284
+ blockedBy.push(`${label} comes in ${card.release}`);
285
+ }
286
+ else if (r.resolved.status === 'unavailable') {
287
+ blockedBy.push(r.resolved.statusNote ?? `${label} can't start on this daemon`);
288
+ }
289
+ if (launch === 'compose' && briefOf(facts).length > 500)
290
+ blockedBy.push('A backlog takes a steer of at most 500 characters: say it shorter');
291
+ if (launch === 'demo' && demoShowOf({ words: facts.words, inputs: facts.inputs, details: facts.details }).length > 4000) {
292
+ blockedBy.push('What to show is over 4000 characters with your corrections: say it shorter');
293
+ }
294
+ // A self-seated workflow picks its own seat at launch: the roster's count is not its requirement (codex r3).
295
+ if (short && coming === undefined && !(r.workflow !== null && SELF_SEATED.has(r.workflow)))
296
+ blockedBy.push(`Needs ${seatsNeeded(r)} seats that can work now (one builds, the others check it); sign another seat in`);
297
+ // The one question: the first required need that is missing.
298
+ let question = null;
299
+ const missing = needs.find((n) => n.required && n.status === 'missing');
300
+ if (coming === undefined && missing !== undefined) {
301
+ if (missing.id === 'repo') {
302
+ question = {
303
+ kind: 'missing',
304
+ text: ctx.chat.repos.length === 0 ? 'Which repository? This chat has none in its scope: start a thread on one.' : 'Which repository?',
305
+ choices: ctx.chat.repos.slice(0, 4).map((x) => ({ label: x.name, edit: { repoRef: x.id } })),
306
+ };
307
+ }
308
+ else if (missing.kind === 'documents') {
309
+ const why = ctx.documents?.find((s) => s.status === 'struck')?.reason;
310
+ question = { kind: 'missing', text: `Which documents?${why !== undefined ? ` ${why}` : ''}`, choices: [] };
311
+ }
312
+ else if (missing.kind === 'text' || missing.kind === 'url') {
313
+ question = { kind: 'missing', text: `${missing.label}?`, choices: [], input: { kind: 'text', label: missing.label, edit: `inputs.${missing.id}` } };
314
+ if (missing.id === 'intent')
315
+ question.input = { kind: 'text', label: missing.label, edit: 'inputs.intent' };
316
+ }
317
+ else {
318
+ question = { kind: 'missing', text: `${missing.label}?`, choices: [] };
319
+ }
320
+ }
321
+ // The sentence: one template per card (its noun), the facts as tokens.
322
+ const tokens = [];
323
+ const t = (tok) => {
324
+ tokens.push(tok);
325
+ return `{${tok.id}}`;
326
+ };
327
+ const visibleCards = CATALOG_V2_CARDS.filter((c) => c.hidden !== true && c.category === card.category && c.id !== card.id && c.release === '1.0');
328
+ const kindSwap = (card.variant?.options ?? [])
329
+ .filter((o) => o.id !== r.option?.id && o.status !== 'coming_soon')
330
+ .slice(0, 4)
331
+ .map((o) => swapChoice(nounOf(card, o.id), { option: o.id }, gate, card.id, o.id, ctx.served, facts.skipQe, seatProtections(r)));
332
+ const cardTok = t({
333
+ id: 'kind',
334
+ kind: card.variant !== undefined ? 'option' : 'card',
335
+ label: nounOf(card, r.option?.id ?? null),
336
+ swap: kindSwap.length > 0 ? { choices: kindSwap } : visibleCards.length > 0 ? { choices: visibleCards.slice(0, 4).map((c) => swapChoice(nounOf(c, optionFor(c, undefined)), { card: c.id }, gate, c.id, optionFor(c, undefined), ctx.served, facts.skipQe, seatProtections(r))) } : null,
337
+ });
338
+ const parts = [];
339
+ const delivers = r.resolved.delivers;
340
+ const repoTok = repo === null ? null : t({
341
+ id: 'repo',
342
+ kind: 'repo',
343
+ label: repo.name,
344
+ swap: ctx.chat.repos.length > 1 ? { choices: ctx.chat.repos.filter((x) => x.id !== repo.id).slice(0, 4).map((x) => ({ label: x.name, edit: { repoRef: x.id } })) } : null,
345
+ });
346
+ const selfSeated = r.workflow !== null && SELF_SEATED.has(r.workflow);
347
+ const seatsTok = t({
348
+ id: 'seats',
349
+ kind: 'seats',
350
+ label: selfSeated ? (r.workflow === 'run-evals' ? 'no seat (the evals compute every number)' : 'a seat the review picks itself') : seats.label,
351
+ swap: !selfSeated && ctx.roster.length > 1 ? { choices: ctx.roster.filter((s) => s.key !== seats.lead).slice(0, 4).map((s) => ({ label: `${s.name} leads`, edit: { lead: s.key } })) } : null,
352
+ });
353
+ const checksTok = t({ id: 'checks', kind: 'checks', label: checksLabel(gate), swap: null });
354
+ const reading = [];
355
+ if (takesDocuments) {
356
+ const documents = ctx.documents ?? [];
357
+ const ok = documents.filter((s) => s.status === 'ok').length;
358
+ reading.push(t({ id: 'documents', kind: 'documents', label: `${ok} document${ok === 1 ? '' : 's'}`, swap: null, documents }));
359
+ }
360
+ if (takesSources) {
361
+ const value = facts.inputs['sources'];
362
+ const picked = value.kind === 'sources' ? value.ids : [];
363
+ const sources = (ctx.jobSources ?? []).map((s) => ({ ...s, picked: picked.includes(s.id) }));
364
+ const label = sourcesLabel(picked, ctx.jobSources);
365
+ reading.push(t({ id: 'sources', kind: 'sources', label, swap: null, sources }));
366
+ }
367
+ const readingClause = reading.length > 0 ? `, reading ${list(reading)}` : '';
368
+ if (launch === 'compose') {
369
+ const projectTok = t({ id: 'project', kind: 'project', label: ctx.projectLabel, swap: null });
370
+ parts.push(`I'll draft ${cardTok} from the requirements you pick in ${projectTok}${readingClause}, checked by ${checksTok}.`);
371
+ }
372
+ else if (launch === 'demo') {
373
+ const url = facts.inputs['url'];
374
+ parts.push(`I'll record ${cardTok}${url !== undefined ? ` of ${inputValueLabel(url)}` : ''}${readingClause} with ${seatsTok}, checked by ${checksTok}.`);
375
+ }
376
+ else if (delivers === 'report' || delivers === 'answer' || delivers === 'proposals') {
377
+ parts.push(`I'll do this as ${cardTok}${repoTok !== null ? ` of ${repoTok}` : ''}${readingClause}, read-only, with ${seatsTok}, checked by ${checksTok}.`);
378
+ }
379
+ else {
380
+ parts.push(`I'll run this as ${cardTok}${repoTok !== null ? ` of ${repoTok}` : ''}${readingClause}, with ${seatsTok}, checked by ${checksTok}.`);
381
+ }
382
+ if (card.depth === true) {
383
+ const d = facts.depth ?? 'standard';
384
+ const depthTok = t({ id: 'depth', kind: 'depth', label: d, swap: { choices: ['quick', 'standard', 'deep'].filter((x) => x !== d).map((x) => ({ label: x, edit: { depth: x } })) } });
385
+ parts.push(`Depth: ${depthTok}.`);
386
+ }
387
+ if (facts.details.length > 0) {
388
+ const ds = facts.details.map((d, i) => t({ id: `detail-${i}`, kind: 'detail', label: d, swap: { choices: [{ label: 'Remove', edit: { detail: { remove: [d] } } }] } }));
389
+ parts.push(`Carrying: ${ds.join(', ')}.`);
390
+ }
391
+ if (facts.skipQe !== null)
392
+ parts.push(`Without QE acceptance (you said: “${facts.skipQe.reason}”), labelled on the job.`);
393
+ const time = minutesLabel(r.resolved.typicalMinutes);
394
+ // The plan promise holds only where the Start can't choose a power run (crew 0.196.0): there, how it runs is the
395
+ // Start's own choice, shown beside it (studio's Review plan), never promised here first (nor in `stops`).
396
+ const startChooses = launch === 'run' && repo !== null && r.workflow !== null && ctx.powerPresets?.has(r.workflow) === true;
397
+ const stops = launch === 'none' || startChooses ? null : STOPS[launch];
398
+ const promise = launch === 'run' ? (startChooses ? '' : "I'll show you the plan before anything changes.") : (stops ?? '');
399
+ if (coming === undefined)
400
+ parts.push(time !== null ? (promise !== '' ? `${time}, and ${promise}` : `${time}.`) : promise);
401
+ const ask = coming !== undefined ? null : question !== null ? question.text : blockedBy.length > 0 ? null : 'Start?';
402
+ const comingText = coming !== undefined
403
+ ? `${label} comes in ${card.release}.${coming.nearest !== null ? ` Today, the closest is ${nounOf(CATALOG_V2_CARDS.find((c) => c.id === coming.nearest.card) ?? card, coming.nearest.option)}.` : ''}`
404
+ : null;
405
+ const sentence = { text: comingText ?? parts.filter((p) => p !== '').join(' '), tokens: comingText !== null ? [] : tokens, notes, ask };
406
+ // At most two suggestions: another option that runs a different plan, and another repository in scope.
407
+ const suggestions = [];
408
+ if (coming !== undefined && coming.nearest !== null) {
409
+ const near = CATALOG_V2_CARDS.find((c) => c.id === coming.nearest.card);
410
+ if (near !== undefined)
411
+ suggestions.push({ label: `Do ${nounOf(near, coming.nearest.option)} instead`, edit: { card: near.id, ...(coming.nearest.option !== null ? { option: coming.nearest.option } : {}) } });
412
+ }
413
+ else if (question === null) {
414
+ const alt = (card.variant?.options ?? []).find((o) => o.id !== r.option?.id && o.status !== 'coming_soon' && JSON.stringify(o.launch) !== JSON.stringify(r.resolved.launch));
415
+ if (alt !== undefined) {
416
+ const c = swapChoice(nounOf(card, alt.id), { option: alt.id }, gate, card.id, alt.id, ctx.served, facts.skipQe, seatProtections(r));
417
+ suggestions.push({ label: `Make it ${c.label}`, edit: c.edit });
418
+ }
419
+ const other = ctx.chat.repos.find((x) => x.id !== repo?.id);
420
+ if (other !== undefined && r.resolved.inputs.some((i) => i.id === 'repo'))
421
+ suggestions.push({ label: `Use ${other.name}`, edit: { repoRef: other.id } });
422
+ }
423
+ const brief = briefOf(facts);
424
+ return {
425
+ pid: ctx.pid,
426
+ chatId: ctx.chatId,
427
+ turnId: ctx.turnId,
428
+ kind: 'job',
429
+ seat: ctx.seat,
430
+ what: { entry: card.id, title: card.title, label, outcome: card.outcome ?? null },
431
+ brief,
432
+ reason: facts.guess?.reason ?? null,
433
+ sources: [],
434
+ repos: repo !== null ? [repo.name] : [],
435
+ ...(repo !== null ? { repoRefs: [repo.id] } : {}),
436
+ helpers: null,
437
+ time: { minutes: r.resolved.typicalMinutes, cost: r.resolved.cost, steps: r.steps.length > 0 ? r.steps.length : null, median: null, label: time ?? '' },
438
+ stops,
439
+ ...(startChooses ? { powerChoice: true } : {}),
440
+ filedIn: { projectId: facts.projectId, label: ctx.projectLabel },
441
+ blocked: blockedBy[0] ?? (question !== null ? question.text : null),
442
+ shape,
443
+ catalogRev: ctx.served.rev,
444
+ resolution: r.resolved.resolution,
445
+ launch: launch === 'none' ? 'run' : launch,
446
+ command: command ?? null,
447
+ needs,
448
+ gate,
449
+ // A self-seated workflow has no membership of the proposal's choosing (codex r3).
450
+ seats: selfSeated ? { lead: null, keys: [], label: tokens.find((x) => x.id === 'seats')?.label ?? seats.label } : seats,
451
+ seatRules: seatProtections(r),
452
+ words: facts.words,
453
+ details: [...facts.details],
454
+ inputs: { ...facts.inputs },
455
+ skipQe: facts.skipQe,
456
+ ...(coming !== undefined ? { coming } : {}),
457
+ sentence,
458
+ suggestions: suggestions.slice(0, 2),
459
+ question,
460
+ sketch: sketchOf(r),
461
+ revises: ctx.revises,
462
+ lineage: ctx.lineage ?? ctx.pid,
463
+ ...(ctx.answers !== undefined ? { answers: ctx.answers } : {}),
464
+ ...(ctx.request !== undefined ? { request: ctx.request } : {}),
465
+ };
466
+ }
467
+ /** A swap choice; one that drops a check names it in its own label and carries `confirmLoss` (pressing it is the
468
+ * person's act, §4.6 step 7). */
469
+ function swapChoice(label, edit, gate, card, option, served, skipQe, protections = []) {
470
+ const r = resolveOption(card, option, served);
471
+ if (r === null)
472
+ return { label, edit };
473
+ const lost = gate.filter((g) => !checksOf(r, skipQe).includes(g));
474
+ const lostSeats = protections.filter((k) => !seatProtections(r).includes(k));
475
+ if (lost.length === 0 && lostSeats.length === 0)
476
+ return { label, edit };
477
+ // Every loss the press confirms is named in its own label (codex r2).
478
+ return { label: `${label}, without ${list([...lost.map((g) => GATE_WORDS[g]), ...lostSeats.map((k) => SEAT_WORDS[k])])}`, edit: { ...edit, confirmLoss: [...lost, ...lostSeats] } };
479
+ }
480
+ /**
481
+ * The brief a launch runs on (§4.6 rule 6): the person's first words plus the current details, so removing a detail
482
+ * removes it from the brief. Crew's framing line and depth line are put first by the launch itself (shape.ts).
483
+ */
484
+ export function briefOf(facts) {
485
+ const words = facts.words.trim();
486
+ if (facts.details.length === 0)
487
+ return words;
488
+ return `${words}\n\nAlso: ${facts.details.join('; ')}.`;
489
+ }
490
+ /** The facts a job proposal was resolved from (a revision starts from them: rule 1). */
491
+ export function factsOf(p) {
492
+ const shape = p.shape;
493
+ return {
494
+ card: shape.card,
495
+ option: shape.option,
496
+ depth: shape.depth,
497
+ words: p.words ?? p.brief ?? '',
498
+ details: [...(p.details ?? [])],
499
+ repoRef: p.repoRefs?.[0] ?? null,
500
+ projectId: p.filedIn.projectId,
501
+ lead: p.seats?.lead ?? null,
502
+ seats: p.seats !== undefined ? [...p.seats.keys] : null,
503
+ inputs: inputsOfProposal(p),
504
+ skipQe: p.skipQe ?? null,
505
+ by: shape.by,
506
+ source: shape.source,
507
+ ...(shape.guess !== undefined ? { guess: shape.guess } : {}),
508
+ };
509
+ }
510
+ /** The input values a proposal holds (a revision carries them; Go launches with them). */
511
+ export function inputsOfProposal(p) {
512
+ return { ...(p.inputs ?? {}) };
513
+ }
514
+ /** The controls a job's words must never lower: its checks and its seat protections, by any of their names. */
515
+ const CONTROL = String.raw `(?:the\s+|any\s+|a\s+|all\s+)?(?:distinct\s+|independent\s+|separate\s+|second\s+|other\s+)?(?:reviews?|reviewers?|review\s+step|judges?|judging|parity|qe(?:\s+acceptance)?|acceptance|tests?|testing|checks?|cited\s+findings|citations|evidence\s+floor|floor|plan\s+(?:gate|approval)|gates?)(?:\s+checks?)?`;
516
+ // A lowering verb, then the control, with at most two words between ("without running the reviewer's checks").
517
+ const LOWER_VERB = new RegExp(String.raw `\b(skip(?:ping)?|drop(?:ping)?|remov(?:e|ing)|disabl(?:e|ing)|bypass(?:ing)?|omit(?:ting)?|cut(?:ting)?|ditch(?:ing)?|waiv(?:e|ing)|forget|lighten|reduc(?:e|ing)|fewer|less|turn(?:ing)?\s+off|get\s+rid\s+of|ignor(?:e|ing)|without|no\s+need\s+for|(?:don'?t|do\s+not)\s+need)(?:\s+[\w'’-]+){0,2}?\s+${CONTROL}\b`, 'giu');
518
+ const NO_CONTROL = /\bno\s+(?:qe|parity|review|reviewer|judge)\b/giu;
519
+ /** A prohibition of a check itself ("do not run the independent review", "never run the tests", "do not review it"),
520
+ * apart from a negation that keeps one ("do not drop parity": no performing verb) or scopes the work ("don't review the
521
+ * generated files": the object is not a check; pi r3). */
522
+ const PROHIBIT = new RegExp(String.raw `\b(?:don'?t|do\s+not|never|no\s+need\s+to)\s+(?:(?:run|do|perform|use|have|bother\s+(?:with|to)|need)\s+${CONTROL}|(?:review|test|check|judge)\s+(?:it|this|that|the\s+(?:change|work|pr|fix|code|job))\b|(?:review|test|check|judge)(?=\s*(?:$|[.,;:!?)]))|(?:review|test|check|judge)\s+(?:or|and|nor)\s+(?:review|test|check|judge)\b)`, 'giu');
523
+ /** A control turned off with the control between ("turn QE off"). */
524
+ const TURN_OFF = new RegExp(String.raw `\bturn(?:ing)?\s+${CONTROL}\s+off\b`, 'giu');
525
+ const SHIP = /\b(?:tag(?:ging)?\s+(?:it|the\s+release|a\s+release|v?\d[\w.]*)|publish(?:ing)?\s+(?:it|the\s+package|to\s+npm)|merg(?:e|ing)\s+(?:it|the\s+pr)|push(?:ing)?\s+(?:it\s+)?to\s+main)\b/giu;
526
+ /** A negation just before a match makes it a request to KEEP the check ("do not drop parity", "without skipping QE"). */
527
+ const NEGATED_BEFORE = /\b(?:don'?t|do\s+not|never|not|without|no)\s+(?:\w+\s+){0,2}$/iu;
528
+ /**
529
+ * Whether words, carried into a job's brief, would ask the lead to lower a check, drop a protected seat, or tag,
530
+ * publish or merge (§9.1 "carried words must never carry a skip"). Descriptive facts ("there are no tests for this
531
+ * module", "no tests failed") and requests to keep a check ("do not drop parity", "without skipping QE") do not.
532
+ */
533
+ export function lowersCheck(raw) {
534
+ const text = raw.replace(/[\u2018\u2019]/gu, "'");
535
+ for (const re of [PROHIBIT, TURN_OFF, LOWER_VERB, NO_CONTROL, SHIP]) {
536
+ re.lastIndex = 0;
537
+ for (let m = re.exec(text); m !== null; m = re.exec(text)) {
538
+ const verb = (m[1] ?? m[0]).toLowerCase();
539
+ // Another lowering verb between this one and the control ("without SKIPPING QE"): the inner one is the request,
540
+ // read with its own negation; scan on from just after this verb.
541
+ if (re === LOWER_VERB && /\b(?:skip|drop|remov|disabl|bypass|omit|cut|ditch|waiv|ignor)/iu.test(m[0].slice(verb.length))) {
542
+ re.lastIndex = m.index + verb.length;
543
+ continue;
544
+ }
545
+ if (re !== PROHIBIT && !verb.startsWith('without') && NEGATED_BEFORE.test(text.slice(0, m.index)))
546
+ continue;
547
+ return true;
548
+ }
549
+ }
550
+ return false;
551
+ }
552
+ const KNOWN_EDITS = new Set(['card', 'option', 'depth', 'repoRef', 'project', 'lead', 'addSeats', 'removeSeats', 'inputs', 'detail', 'skipQe', 'restoreQe', 'confirmLoss']);
553
+ export const SEAT_WORDS = {
554
+ distinctEvaluator: 'a reviewer who did not build it',
555
+ distinctJudge: 'a separate judge',
556
+ excludeChangeAuthors: "a reviewer who wrote none of the change",
557
+ notRunSeat: 'a reviewer who ran none of the work',
558
+ proposalOnly: 'your approval of everything it proposes',
559
+ };
560
+ export function seatProtections(r) {
561
+ if (r === null)
562
+ return [];
563
+ const s = r.resolved.seats;
564
+ return ['distinctEvaluator', 'distinctJudge', 'excludeChangeAuthors', 'notRunSeat', 'proposalOnly'].filter((k) => s[k]);
565
+ }
566
+ /**
567
+ * Merge a revision into its parent by the rules of §4.6, in order. Pure over its inputs: the caller decides what a
568
+ * lost check does (a question, or, with the person's `confirmLoss`, the write).
569
+ */
570
+ export function mergeRevision(parent, edits, ctx) {
571
+ const notes = [];
572
+ const refusedInputs = [];
573
+ // 1. The parent whole; a field the revision does not name keeps its value.
574
+ const facts = factsOf(parent);
575
+ const before = JSON.stringify(facts);
576
+ for (const k of Object.keys(edits))
577
+ if (!KNOWN_EDITS.has(k))
578
+ notes.push(`Not changed: “${k.slice(0, 40)}” isn't something a job can change`);
579
+ // 2. A card change: the new card's default option and depth; what the new card takes is kept, the rest dropped.
580
+ if (edits.card !== undefined && edits.card !== facts.card) {
581
+ const target = CATALOG_V2_CARDS.find((c) => c.id === edits.card);
582
+ if (target === undefined || target.hidden === true) {
583
+ notes.push(`Not changed: there is no job called “${String(edits.card).slice(0, 60)}” to switch to`);
584
+ }
585
+ else {
586
+ facts.card = target.id;
587
+ facts.option = target.variant?.default ?? null;
588
+ facts.depth = target.depth === true ? 'standard' : null;
589
+ // A QE skip was given for the old card: the new card's checks are its own, so it asks again (pi r1).
590
+ facts.skipQe = null;
591
+ const r = resolveOption(target.id, facts.option, ctx.served);
592
+ const takes = new Set((r?.resolved.inputs ?? []).map((i) => i.id));
593
+ if (!takes.has('repo') && facts.repoRef !== null) {
594
+ facts.repoRef = null;
595
+ notes.push(`${target.title} takes no repository: left out`);
596
+ }
597
+ for (const id of Object.keys(facts.inputs)) {
598
+ if (!takes.has(id)) {
599
+ delete facts.inputs[id];
600
+ notes.push(`${target.title} takes no ${id}: left out`);
601
+ }
602
+ }
603
+ }
604
+ }
605
+ // 3. An option or depth change keeps everything else.
606
+ if (edits.option !== undefined) {
607
+ const card = CATALOG_V2_CARDS.find((c) => c.id === facts.card);
608
+ // `null` on a card with variants is its default option, as the resolver reads it (codex r5).
609
+ if (edits.option !== null && card.variant?.options.some((o) => o.id === edits.option) !== true) {
610
+ notes.push(`Not changed: ${card.title} has no option “${String(edits.option).slice(0, 60)}”`);
611
+ }
612
+ else {
613
+ facts.option = edits.option === null ? (card.variant?.default ?? null) : edits.option;
614
+ }
615
+ }
616
+ if (edits.depth !== undefined) {
617
+ const card = CATALOG_V2_CARDS.find((c) => c.id === facts.card);
618
+ if (edits.depth !== null && card.depth !== true)
619
+ notes.push(`Not changed: ${card.title} takes no depth`);
620
+ else
621
+ facts.depth = edits.depth;
622
+ }
623
+ if (edits.repoRef !== undefined) {
624
+ const hit = ctx.chat.repos.find((r) => r.id === edits.repoRef || r.name === edits.repoRef);
625
+ if (hit === undefined)
626
+ notes.push(`Not changed: ${String(edits.repoRef).slice(0, 80)} isn't in this chat's scope (start a thread on it)`);
627
+ else
628
+ facts.repoRef = hit.id;
629
+ }
630
+ if (edits.project !== undefined && edits.project !== facts.projectId)
631
+ notes.push("Not changed: the project is the chat's own");
632
+ // 4. Seats: the lead, added seats; removing the card's only distinct reviewer or judge is refused. A self-seated
633
+ // workflow picks its own seat: a seat edit there changes nothing (codex r2).
634
+ const card4 = CATALOG_V2_CARDS.find((c) => c.id === facts.card);
635
+ const r4 = resolveOption(card4.id, optionFor(card4, facts.option), ctx.served);
636
+ if (r4?.workflow !== null && r4?.workflow !== undefined && SELF_SEATED.has(r4.workflow) && (edits.lead !== undefined || edits.addSeats !== undefined || edits.removeSeats !== undefined)) {
637
+ notes.push(`Not changed: ${card4.title} picks its own seat`);
638
+ edits = { ...edits };
639
+ delete edits.lead;
640
+ delete edits.addSeats;
641
+ delete edits.removeSeats;
642
+ }
643
+ const can = new Set(ctx.roster.map((s) => s.key));
644
+ const nameOf = (k) => ctx.roster.find((s) => s.key === k)?.name ?? k;
645
+ if (edits.lead !== undefined) {
646
+ if (!can.has(edits.lead))
647
+ notes.push(`Not changed: ${nameOf(edits.lead)} can't work now`);
648
+ else {
649
+ facts.lead = edits.lead;
650
+ if (facts.seats !== null && !facts.seats.includes(edits.lead))
651
+ facts.seats = [edits.lead, ...facts.seats];
652
+ }
653
+ }
654
+ if (edits.addSeats !== undefined) {
655
+ const add = edits.addSeats.filter((k) => can.has(k));
656
+ for (const k of edits.addSeats)
657
+ if (!can.has(k))
658
+ notes.push(`Not changed: ${nameOf(k)} can't work now`);
659
+ if (add.length > 0)
660
+ facts.seats = [...new Set([...(facts.seats ?? []), ...add])];
661
+ }
662
+ if (edits.removeSeats !== undefined && edits.removeSeats.length > 0) {
663
+ const r = resolveOption(facts.card, optionFor(CATALOG_V2_CARDS.find((c) => c.id === facts.card), facts.option), ctx.served);
664
+ const need = r === null ? 1 : seatsNeeded(r);
665
+ const current = facts.seats ?? [...new Set([facts.lead, ...ctx.chat.seats, ...ctx.roster.map((s) => s.key)].filter((k) => k !== null && can.has(k)))];
666
+ const kept = current.filter((k) => !edits.removeSeats.includes(k));
667
+ if (kept.length < need) {
668
+ notes.push(`Not changed: ${list(edits.removeSeats.map(nameOf))} ${edits.removeSeats.length === 1 ? 'stays' : 'stay'}; this job needs ${need} seats, so another seat checks the one that builds`);
669
+ }
670
+ else {
671
+ facts.seats = kept;
672
+ if (facts.lead !== null && !kept.includes(facts.lead))
673
+ facts.lead = kept[0] ?? null;
674
+ }
675
+ }
676
+ // 5. Inputs fill or replace the needs they name, each validated against the card's own input (its kind, non-blank).
677
+ if (edits.inputs !== undefined) {
678
+ const card5 = CATALOG_V2_CARDS.find((c) => c.id === facts.card);
679
+ const defs5 = resolveOption(facts.card, optionFor(card5, facts.option), ctx.served)?.resolved.inputs ?? [];
680
+ for (const [id, v] of Object.entries(edits.inputs)) {
681
+ const def = defs5.find((d) => d.id === id);
682
+ const kindOk = def !== undefined && (def.kind === v.kind || (def.kind === 'text' && v.kind === 'text'));
683
+ if (!kindOk) {
684
+ refusedInputs.push(id);
685
+ notes.push(`Not changed: ${card5.title} takes no ${def === undefined ? '' : `${v.kind} `}${id.slice(0, 40)}`);
686
+ continue;
687
+ }
688
+ if ((v.kind === 'text' || v.kind === 'url') && v.value.trim() === '') {
689
+ refusedInputs.push(id);
690
+ notes.push(`Not changed: ${def.label} can't be blank`);
691
+ continue;
692
+ }
693
+ // The launch's own limits, checked here so Start never shows for a launch that would refuse (codex r3).
694
+ const LIMIT = { audience: 2000, show: 4000, url: 2048 };
695
+ if ((v.kind === 'text' || v.kind === 'url') && LIMIT[id] !== undefined && v.value.length > LIMIT[id]) {
696
+ refusedInputs.push(id);
697
+ notes.push(`Not changed: ${def.label} is over ${LIMIT[id]} characters`);
698
+ continue;
699
+ }
700
+ if (v.kind === 'requirements' && v.refs.length > 40) {
701
+ refusedInputs.push(id);
702
+ notes.push('Not changed: pick at most 40 requirements');
703
+ continue;
704
+ }
705
+ if (v.kind === 'sources') {
706
+ const refused = v.ids.filter((id) => {
707
+ const source = ctx.jobSources?.find((s) => s.id === id);
708
+ return source === undefined || source.reason !== undefined;
709
+ });
710
+ if (refused.length > 0) {
711
+ refusedInputs.push(id);
712
+ const current = facts.inputs[id];
713
+ const label = sourcesLabel(current?.kind === 'sources' ? current.ids : [], ctx.jobSources);
714
+ for (const id of refused)
715
+ notes.push(`Not changed: the sources stay ${label}; ${id} can't be picked: ${ctx.jobSources?.find((s) => s.id === id)?.reason ?? 'not available on this daemon'}`);
716
+ continue;
717
+ }
718
+ }
719
+ // Words that would lower a check never reach the brief through an input either (codex r1).
720
+ if (v.kind === 'text' && lowersCheck(v.value)) {
721
+ refusedInputs.push(id);
722
+ notes.push(`Not changed: ${def.label} would ask the job to drop a check, and its checks are its own`);
723
+ continue;
724
+ }
725
+ if (id === 'intent' && v.kind === 'text') {
726
+ facts.words = v.value.slice(0, 8000);
727
+ continue;
728
+ }
729
+ if ((v.kind === 'text' || v.kind === 'url') && (typeof v.value !== 'string' || v.value.length > 4000)) {
730
+ refusedInputs.push(id);
731
+ notes.push(`Not changed: ${id} is too long`);
732
+ continue;
733
+ }
734
+ if (v.kind === 'url') {
735
+ try {
736
+ const u = new URL(v.value);
737
+ if (u.protocol !== 'http:' && u.protocol !== 'https:')
738
+ throw new Error('scheme');
739
+ }
740
+ catch {
741
+ refusedInputs.push(id);
742
+ notes.push(`Not changed: ${v.value.slice(0, 80)} isn't an http(s) address`);
743
+ continue;
744
+ }
745
+ }
746
+ facts.inputs[id] = v;
747
+ }
748
+ }
749
+ // 6. Details: facts carried from corrections; the brief is rebuilt from the first words plus these.
750
+ if (edits.detail !== undefined) {
751
+ for (const d of edits.detail.remove ?? [])
752
+ facts.details = facts.details.filter((x) => x !== d);
753
+ for (const d of edits.detail.add ?? []) {
754
+ const t = d.trim().slice(0, 200);
755
+ // DES-CATALOG-002 §9.1: carried words never carry a lowered check ("skip parity" as a detail would reach the
756
+ // lead's brief): refused with a note, the rest of the revision standing.
757
+ if (lowersCheck(t)) {
758
+ notes.push(`Not changed: “${t.slice(0, 60)}” would ask the job to drop a check, and its checks are its own`);
759
+ continue;
760
+ }
761
+ if (t !== '' && !facts.details.includes(t) && !facts.words.includes(t))
762
+ facts.details.push(t);
763
+ }
764
+ facts.details = facts.details.slice(0, 12);
765
+ }
766
+ if (edits.skipQe !== undefined)
767
+ facts.skipQe = { reason: edits.skipQe.reason.trim().slice(0, 600) };
768
+ if (edits.restoreQe === true)
769
+ facts.skipQe = null;
770
+ // 7. The checks compared with the parent's: what the result lacks is lost (the caller asks before writing it).
771
+ const card = CATALOG_V2_CARDS.find((c) => c.id === facts.card);
772
+ const r = resolveOption(facts.card, optionFor(card, facts.option), ctx.served);
773
+ // A skip on a shape with no QE acceptance to skip is dropped (the engine refuses one there).
774
+ if (facts.skipQe !== null && r !== null && !r.resolved.gate.includes('qe-acceptance'))
775
+ facts.skipQe = null;
776
+ const after = r === null ? [] : checksOf(r, facts.skipQe);
777
+ // A loss the parent's own question is still asking about stays a loss until the person's press (codex r2).
778
+ const pending = parent.question?.kind === 'lost_check' ? (parent.question.lost ?? []) : [];
779
+ const lost = [...new Set([...(parent.gate ?? []), ...pending])].filter((g) => !after.includes(g));
780
+ const parentCard = parent.shape === undefined ? null : CATALOG_V2_CARDS.find((c) => c.id === parent.shape.card) ?? null;
781
+ // The parent's frozen seat rules (a catalog change since never erases one), else read from its card.
782
+ const before7 = parent.seatRules ?? (parentCard === null ? [] : seatProtections(resolveOption(parentCard.id, optionFor(parentCard, parent.shape.option), ctx.served)));
783
+ const after7 = seatProtections(r);
784
+ const pendingSeats = parent.question?.kind === 'lost_check' ? (parent.question.lostSeats ?? []) : [];
785
+ const lostSeats = [...new Set([...before7, ...pendingSeats])].filter((k) => !after7.includes(k));
786
+ return { facts, notes, refusedInputs, lost, lostSeats, unchanged: JSON.stringify(facts) === before };
787
+ }
788
+ // ── the QE skip, bound to the person's own words (§2.4, §9.2 (ac)) ─────────────────────────────────────────────────
789
+ /** The text outside quotes and reported speech ("the PM said: …"): only that is the person's own ask. */
790
+ export function ownWords(message) {
791
+ // Quoted material in the chat's own formats: block quotes, code spans and fences; curly apostrophes read as straight.
792
+ let t = message
793
+ .replace(/(^|[\s(])\u2018[^\u2019]*\u2019(?![a-z])/giu, '$1 ')
794
+ .replace(/(?<=[a-z])\u2019(?=[a-z])/giu, "'")
795
+ // Fenced blocks of any supported length, backtick or tilde (codex r4).
796
+ .replace(/(`{3,}|~{3,})[\s\S]*?(?:\1|$)/gu, ' ')
797
+ .replace(/`[^`]*`/gu, ' ')
798
+ .split('\n')
799
+ .filter((line) => !/^\s*>/u.test(line))
800
+ .join('\n');
801
+ t = t.replace(/“[^”]*”|"[^"]*"|«[^»]*»|(^|[\s(])'[^']*'(?=$|[\s).,;:!?])/gu, (_m, lead) => `${lead ?? ''} `);
802
+ // Reported speech: whatever follows "X said:" / "they asked" / "told me to" is someone else's.
803
+ // A speaker's words, said as such ("the PM said:", "per the PM", "requested by legal"): an ordinary noun or preposition
804
+ // ("requests that time out", "100 per minute") is not reported speech (codex r4).
805
+ t = t.replace(/\b(said|says|asked|asks|told (me|us)( to)?|wrote|writes|wants (me|us) to|requested|mentioned|suggested|according to|per (?:the|my|our|their|his|her|\w+'s)\s+(?:pm|manager|lead|boss|team|client|customer|ticket|email|message|thread))\b[\s\S]*$/iu, ' ');
806
+ // A named speaker ("per Alice, …"), case-sensitive so a rate ("per second, …") is not one (codex r6).
807
+ t = t.replace(/\b(?:[Pp]er|PER)\s+\p{Lu}\p{L}*\s*,[\s\S]*$/u, ' ');
808
+ return t;
809
+ }
810
+ const SKIP_ASK = /\b(skip(ping)?|drop(ping)?|without|no)\s+(the\s+)?qe(\s+acceptance)?\b/iu;
811
+ /** "No skipping QE…", "no need to skip…": a refusal phrased as a skip. */
812
+ const NO_SKIP = /\bno\s+(skipping|dropping|need\s+to)\b/iu;
813
+ /** A negation anywhere earlier in the same sentence makes the ask not one (conservative: ask the person instead). */
814
+ const NEGATED = /\b(don'?t|do not|never|not|no need to|shouldn'?t|mustn'?t|won'?t|can'?t|cannot)\b[^.!?\n]*$/iu;
815
+ /** Whether the person's own words (not quoted, not reported, not negated) ask to skip QE acceptance. */
816
+ export function personAskedSkip(message) {
817
+ if (message === null)
818
+ return false;
819
+ const own = ownWords(message);
820
+ const m = SKIP_ASK.exec(own);
821
+ return m !== null && !NEGATED.test(own.slice(0, m.index)) && !NO_SKIP.test(own);
822
+ }
823
+ /**
824
+ * Whether a seat's QE skip is the person's own: their message that this turn answers asks for it in their own words
825
+ * (not quoted, not reported, not negated), and the reason appears there too, unquoted. A reason that is only "QE" is
826
+ * none.
827
+ */
828
+ export function qeSkipBound(reason, message) {
829
+ if (message === null)
830
+ return false;
831
+ const own = ownWords(message);
832
+ const m = SKIP_ASK.exec(own);
833
+ if (m === null)
834
+ return false;
835
+ if (NEGATED.test(own.slice(0, m.index)) || NO_SKIP.test(own))
836
+ return false;
837
+ const r = reason.trim().toLowerCase().replace(/[.!?,;:]+$/u, '');
838
+ const bare = r.replace(/\b(qe|acceptance|skip|the|it|because|since)\b/gu, '').replace(/[^\p{L}\p{N}]+/gu, '');
839
+ if (r.length < 3 || bare.length < 3)
840
+ return false;
841
+ return own.toLowerCase().includes(r);
842
+ }
843
+ // ── ids ────────────────────────────────────────────────────────────────────────────────────────────────────────────
844
+ /** A digest of a request body (a repeated `requestId` with another body is refused). */
845
+ export function requestDigest(body) {
846
+ return createHash('sha256').update(JSON.stringify(body)).digest('hex').slice(0, 24);
847
+ }
848
+ /** A person-made proposal's pid, derived from the person and their request id (a retry names the same one). */
849
+ export function personPid(chatId, actorId, requestId) {
850
+ const tag = createHash('sha256').update(`${actorId}\u0000${requestId}`, 'utf8').digest('hex').slice(0, 20);
851
+ return `${chatId}:p:${tag}`;
852
+ }
853
+ export const depthLine = (d) => DEPTH_LINES[d];
854
+ // ── what Go launches (DES-CATALOG-002 §4.6) ────────────────────────────────────────────────────────────────────────
855
+ /** A demo's brief: the person's first words, their show field and the corrections, together (one rendering for the
856
+ * check before Start and the launch). */
857
+ export function demoShowOf(p) {
858
+ const show = p.inputs?.['show'];
859
+ return [...new Set([p.words ?? '', show !== undefined && show.kind === 'text' ? show.value : '', ...(p.details ?? [])])].filter((x) => x.trim() !== '').join('\n');
860
+ }
861
+ /** The inputs a run launch carries in its brief (beside the intent, the repository and the project), as plain lines. */
862
+ export function inputLines(p) {
863
+ const out = [];
864
+ for (const [id, v] of Object.entries(p.inputs ?? {})) {
865
+ if (id === 'intent' || v.kind === 'documents' || v.kind === 'sources')
866
+ continue;
867
+ const label = p.needs?.find((n) => n.id === id)?.label ?? id;
868
+ if (v.kind === 'requirements')
869
+ out.push(`${label}: ${v.refs.map((r) => `${r.repoId} ${r.key}`).join(', ')}`);
870
+ else
871
+ out.push(`${label}: ${v.value}`);
872
+ }
873
+ return out;
874
+ }
875
+ /** Go always declares the card's documents, including none, so a retry cannot inherit files the card never showed. */
876
+ export function jobInputsOfProposal(p, heldPick) {
877
+ const out = { documents: [] };
878
+ if (p.needs?.some((n) => n.id === 'documents' && n.kind === 'documents')) {
879
+ out.documents = p.sentence?.tokens.find((t) => t.kind === 'documents')?.documents?.filter((s) => s.status === 'ok').map((s) => s.token) ?? [];
880
+ }
881
+ const sources = p.inputs?.['sources'];
882
+ if (p.needs?.some((n) => n.id === 'sources' && n.kind === 'sources'))
883
+ out.sources = sources?.kind === 'sources' ? [...sources.ids] : [];
884
+ // (CS10) A reshape keeps the held run's pick when its new shape takes no sources: changing the card never widens what
885
+ // the job reads. (A reshape whose shape takes sources carries the held proposal's pick in its inputs.) The launch
886
+ // checks it again against the switches, like any sent pick.
887
+ if (out.sources === undefined && p.reshapes !== undefined && heldPick !== undefined) {
888
+ const held = heldPick(p.reshapes);
889
+ if (held !== null)
890
+ out.sources = [...held];
891
+ }
892
+ return out;
893
+ }
894
+ /** The launch's `LaunchShape` from a proposal's frozen shape. */
895
+ export function launchShapeOfProposal(p) {
896
+ const shape = p.shape;
897
+ return {
898
+ card: shape.card,
899
+ option: shape.option,
900
+ depth: shape.depth,
901
+ by: shape.by === 'detected' ? 'detected' : 'person',
902
+ catalogRev: p.catalogRev,
903
+ ...(shape.guess !== undefined ? { guess: { confidence: shape.guess.confidence, band: shape.guess.band, source: shape.guess.source, reason: shape.guess.reason, detectionRunId: null } } : {}),
904
+ };
905
+ }
906
+ /**
907
+ * The common launch fields of a job's Go, for every launch kind: the derived identity, the chat, the shape, the seats
908
+ * the person saw, the plan held, QE as shown (forced when the daemon's setting is off but the proposal promised it),
909
+ * and a reshape's lineage and envelope.
910
+ */
911
+ export function jobLaunchCommon(p, d, o) {
912
+ const lead = p.seats?.lead ?? undefined;
913
+ const qeShown = (p.gate ?? []).includes('qe-acceptance');
914
+ const skip = p.skipQe ?? null;
915
+ return {
916
+ sessionId: d.runId,
917
+ chatId: d.chatId,
918
+ ...(!o.selfSeated && lead !== undefined ? { primary: lead } : {}),
919
+ ...(!o.selfSeated && o.clisJson !== undefined ? { clisJson: o.clisJson } : {}),
920
+ shape: launchShapeOfProposal(p),
921
+ // QE as the person saw it (codex r2): promised, it is forced (no setting or score drops it unseen); skipped, the
922
+ // person's own skip with their reason.
923
+ ...(skip !== null ? { skipQeAcceptance: { reason: skip.reason } } : qeShown ? { forceQeAcceptance: true } : {}),
924
+ ...(p.relaunch?.campaignId !== undefined ? { campaignId: p.relaunch.campaignId } : p.relaunch?.groupLabel !== undefined ? { groupLabel: p.relaunch.groupLabel } : {}),
925
+ ...(p.reshapes !== undefined ? { retryOf: p.reshapes } : {}),
926
+ ...(p.reducedAssurance === true ? { reducedAssurance: true } : {}),
927
+ };
928
+ }
929
+ //# sourceMappingURL=chat-jobs.js.map