clinkx 1.2.0 → 1.4.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 (371) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/README.md +17 -8
  3. package/clinkx-workflows/dist/architecture-arena/admission.d.ts +16 -0
  4. package/clinkx-workflows/dist/architecture-arena/admission.js +107 -0
  5. package/clinkx-workflows/dist/architecture-arena/admission.js.map +1 -0
  6. package/clinkx-workflows/dist/architecture-arena/contract.d.ts +1368 -0
  7. package/clinkx-workflows/dist/architecture-arena/contract.js +254 -0
  8. package/clinkx-workflows/dist/architecture-arena/contract.js.map +1 -0
  9. package/clinkx-workflows/dist/architecture-arena/runtime.d.ts +53 -0
  10. package/clinkx-workflows/dist/architecture-arena/runtime.js +511 -0
  11. package/clinkx-workflows/dist/architecture-arena/runtime.js.map +1 -0
  12. package/clinkx-workflows/dist/architecture-comparison/admission.d.ts +17 -1
  13. package/clinkx-workflows/dist/architecture-comparison/admission.js +27 -4
  14. package/clinkx-workflows/dist/architecture-comparison/admission.js.map +1 -1
  15. package/clinkx-workflows/dist/architecture-comparison/contract.d.ts +59 -62
  16. package/clinkx-workflows/dist/architecture-comparison/contract.js +4 -21
  17. package/clinkx-workflows/dist/architecture-comparison/contract.js.map +1 -1
  18. package/clinkx-workflows/dist/architecture-comparison/runtime.d.ts +4 -3
  19. package/clinkx-workflows/dist/architecture-comparison/runtime.js +22 -67
  20. package/clinkx-workflows/dist/architecture-comparison/runtime.js.map +1 -1
  21. package/clinkx-workflows/dist/artifacts.d.ts +19 -4
  22. package/clinkx-workflows/dist/artifacts.js +16 -7
  23. package/clinkx-workflows/dist/artifacts.js.map +1 -1
  24. package/clinkx-workflows/dist/backend.d.ts +30 -0
  25. package/clinkx-workflows/dist/child-env.d.ts +3 -0
  26. package/clinkx-workflows/dist/child-env.js +11 -0
  27. package/clinkx-workflows/dist/child-env.js.map +1 -1
  28. package/clinkx-workflows/dist/clink-client.d.ts +8 -2
  29. package/clinkx-workflows/dist/clink-client.js +4 -2
  30. package/clinkx-workflows/dist/clink-client.js.map +1 -1
  31. package/clinkx-workflows/dist/context-preflight.d.ts +6 -0
  32. package/clinkx-workflows/dist/context-preflight.js.map +1 -1
  33. package/clinkx-workflows/dist/council-execution-policy.d.ts +3 -1
  34. package/clinkx-workflows/dist/council-execution-policy.js +4 -0
  35. package/clinkx-workflows/dist/council-execution-policy.js.map +1 -1
  36. package/clinkx-workflows/dist/dashboard/api-routes.d.ts +21 -0
  37. package/clinkx-workflows/dist/dashboard/api-routes.js +27 -0
  38. package/clinkx-workflows/dist/dashboard/api-routes.js.map +1 -1
  39. package/clinkx-workflows/dist/dashboard/auth/challenge-store.d.ts +13 -0
  40. package/clinkx-workflows/dist/dashboard/auth/challenge-store.js.map +1 -1
  41. package/clinkx-workflows/dist/dashboard/auth/controller.d.ts +27 -0
  42. package/clinkx-workflows/dist/dashboard/auth/controller.js +262 -23
  43. package/clinkx-workflows/dist/dashboard/auth/controller.js.map +1 -1
  44. package/clinkx-workflows/dist/dashboard/auth/settings-step-up.d.ts +62 -0
  45. package/clinkx-workflows/dist/dashboard/auth/settings-step-up.js +70 -0
  46. package/clinkx-workflows/dist/dashboard/auth/settings-step-up.js.map +1 -0
  47. package/clinkx-workflows/dist/dashboard/contracts.d.ts +586 -586
  48. package/clinkx-workflows/dist/dashboard/progress-report-contract.d.ts +28 -28
  49. package/clinkx-workflows/dist/dashboard/request-admission.d.ts +6 -0
  50. package/clinkx-workflows/dist/dashboard/request-admission.js +9 -0
  51. package/clinkx-workflows/dist/dashboard/request-admission.js.map +1 -1
  52. package/clinkx-workflows/dist/dashboard/server-factory.js +15 -1
  53. package/clinkx-workflows/dist/dashboard/server-factory.js.map +1 -1
  54. package/clinkx-workflows/dist/dashboard/session-log-contract.d.ts +32 -32
  55. package/clinkx-workflows/dist/dashboard/settings-contract.d.ts +1806 -0
  56. package/clinkx-workflows/dist/dashboard/settings-contract.js +630 -0
  57. package/clinkx-workflows/dist/dashboard/settings-contract.js.map +1 -0
  58. package/clinkx-workflows/dist/dashboard/settings-process-reader.d.ts +48 -0
  59. package/clinkx-workflows/dist/dashboard/settings-process-reader.js +195 -0
  60. package/clinkx-workflows/dist/dashboard/settings-process-reader.js.map +1 -0
  61. package/clinkx-workflows/dist/dashboard/settings-routes.d.ts +87 -0
  62. package/clinkx-workflows/dist/dashboard/settings-routes.js +690 -0
  63. package/clinkx-workflows/dist/dashboard/settings-routes.js.map +1 -0
  64. package/clinkx-workflows/dist/dashboard-ui/assets/index-DSOtuS0p.js +122 -0
  65. package/clinkx-workflows/dist/dashboard-ui/assets/style-C5guUjwN.css +1 -0
  66. package/clinkx-workflows/dist/dashboard-ui/index.html +2 -2
  67. package/clinkx-workflows/dist/delegate-signature.d.ts +4 -3
  68. package/clinkx-workflows/dist/delegate-signature.js +4 -3
  69. package/clinkx-workflows/dist/delegate-signature.js.map +1 -1
  70. package/clinkx-workflows/dist/durable-file-core.d.ts +76 -0
  71. package/clinkx-workflows/dist/durable-file-core.js +146 -0
  72. package/clinkx-workflows/dist/durable-file-core.js.map +1 -0
  73. package/clinkx-workflows/dist/durable-file.d.ts +13 -0
  74. package/clinkx-workflows/dist/durable-file.js +22 -0
  75. package/clinkx-workflows/dist/durable-file.js.map +1 -0
  76. package/clinkx-workflows/dist/engine.d.ts +42 -7
  77. package/clinkx-workflows/dist/engine.js +196 -24
  78. package/clinkx-workflows/dist/engine.js.map +1 -1
  79. package/clinkx-workflows/dist/index.js +68 -2
  80. package/clinkx-workflows/dist/index.js.map +1 -1
  81. package/clinkx-workflows/dist/ping-pong/admission.d.ts +127 -0
  82. package/clinkx-workflows/dist/ping-pong/admission.js +522 -0
  83. package/clinkx-workflows/dist/ping-pong/admission.js.map +1 -0
  84. package/clinkx-workflows/dist/ping-pong/contract.d.ts +2539 -0
  85. package/clinkx-workflows/dist/ping-pong/contract.js +819 -0
  86. package/clinkx-workflows/dist/ping-pong/contract.js.map +1 -0
  87. package/clinkx-workflows/dist/ping-pong/control.d.ts +67 -0
  88. package/clinkx-workflows/dist/ping-pong/control.js +12 -0
  89. package/clinkx-workflows/dist/ping-pong/control.js.map +1 -0
  90. package/clinkx-workflows/dist/ping-pong/runtime-handle.d.ts +24 -0
  91. package/clinkx-workflows/dist/ping-pong/runtime-handle.js +55 -0
  92. package/clinkx-workflows/dist/ping-pong/runtime-handle.js.map +1 -0
  93. package/clinkx-workflows/dist/ping-pong/runtime.d.ts +235 -0
  94. package/clinkx-workflows/dist/ping-pong/runtime.js +1183 -0
  95. package/clinkx-workflows/dist/ping-pong/runtime.js.map +1 -0
  96. package/clinkx-workflows/dist/ping-pong/settle.d.ts +57 -0
  97. package/clinkx-workflows/dist/ping-pong/settle.js +58 -0
  98. package/clinkx-workflows/dist/ping-pong/settle.js.map +1 -0
  99. package/clinkx-workflows/dist/ping-pong/sidecar.d.ts +65 -0
  100. package/clinkx-workflows/dist/ping-pong/sidecar.js +138 -0
  101. package/clinkx-workflows/dist/ping-pong/sidecar.js.map +1 -0
  102. package/clinkx-workflows/dist/plan-review/publication.d.ts +2 -1
  103. package/clinkx-workflows/dist/plan-review/publication.js +5 -6
  104. package/clinkx-workflows/dist/plan-review/publication.js.map +1 -1
  105. package/clinkx-workflows/dist/plan-review/snapshot.d.ts +3 -2
  106. package/clinkx-workflows/dist/plan-review/snapshot.js +8 -8
  107. package/clinkx-workflows/dist/plan-review/snapshot.js.map +1 -1
  108. package/clinkx-workflows/dist/recipe-host.d.ts +315 -0
  109. package/clinkx-workflows/dist/recipe-host.js +183 -0
  110. package/clinkx-workflows/dist/recipe-host.js.map +1 -0
  111. package/clinkx-workflows/dist/recipe-seats.d.ts +96 -0
  112. package/clinkx-workflows/dist/recipe-seats.js +163 -0
  113. package/clinkx-workflows/dist/recipe-seats.js.map +1 -0
  114. package/clinkx-workflows/dist/recipe-shared/evidence.d.ts +67 -0
  115. package/clinkx-workflows/dist/recipe-shared/evidence.js +111 -0
  116. package/clinkx-workflows/dist/recipe-shared/evidence.js.map +1 -0
  117. package/clinkx-workflows/dist/reducers/index.d.ts +9 -1
  118. package/clinkx-workflows/dist/reducers/index.js +30 -0
  119. package/clinkx-workflows/dist/reducers/index.js.map +1 -1
  120. package/clinkx-workflows/dist/run-lock-reclaim.d.ts +44 -0
  121. package/clinkx-workflows/dist/run-lock-reclaim.js +86 -0
  122. package/clinkx-workflows/dist/run-lock-reclaim.js.map +1 -0
  123. package/clinkx-workflows/dist/settings/audit.d.ts +101 -0
  124. package/clinkx-workflows/dist/settings/audit.js +318 -0
  125. package/clinkx-workflows/dist/settings/audit.js.map +1 -0
  126. package/clinkx-workflows/dist/settings/bootstrap.d.ts +35 -0
  127. package/clinkx-workflows/dist/settings/bootstrap.js +52 -0
  128. package/clinkx-workflows/dist/settings/bootstrap.js.map +1 -0
  129. package/clinkx-workflows/dist/settings/codec.d.ts +51 -0
  130. package/clinkx-workflows/dist/settings/codec.js +410 -0
  131. package/clinkx-workflows/dist/settings/codec.js.map +1 -0
  132. package/clinkx-workflows/dist/settings/durable-write.d.ts +48 -0
  133. package/clinkx-workflows/dist/settings/durable-write.js +31 -0
  134. package/clinkx-workflows/dist/settings/durable-write.js.map +1 -0
  135. package/clinkx-workflows/dist/settings/index.d.ts +20 -0
  136. package/clinkx-workflows/dist/settings/index.js +23 -0
  137. package/clinkx-workflows/dist/settings/index.js.map +1 -0
  138. package/clinkx-workflows/dist/settings/loader.d.ts +80 -0
  139. package/clinkx-workflows/dist/settings/loader.js +577 -0
  140. package/clinkx-workflows/dist/settings/loader.js.map +1 -0
  141. package/clinkx-workflows/dist/settings/lock.d.ts +108 -0
  142. package/clinkx-workflows/dist/settings/lock.js +344 -0
  143. package/clinkx-workflows/dist/settings/lock.js.map +1 -0
  144. package/clinkx-workflows/dist/settings/paths.d.ts +65 -0
  145. package/clinkx-workflows/dist/settings/paths.js +173 -0
  146. package/clinkx-workflows/dist/settings/paths.js.map +1 -0
  147. package/clinkx-workflows/dist/settings/process-heartbeat.d.ts +47 -0
  148. package/clinkx-workflows/dist/settings/process-heartbeat.js +305 -0
  149. package/clinkx-workflows/dist/settings/process-heartbeat.js.map +1 -0
  150. package/clinkx-workflows/dist/settings/registry.d.ts +178 -0
  151. package/clinkx-workflows/dist/settings/registry.js +1285 -0
  152. package/clinkx-workflows/dist/settings/registry.js.map +1 -0
  153. package/clinkx-workflows/dist/settings/schema.d.ts +404 -0
  154. package/clinkx-workflows/dist/settings/schema.js +415 -0
  155. package/clinkx-workflows/dist/settings/schema.js.map +1 -0
  156. package/clinkx-workflows/dist/settings/store.d.ts +157 -0
  157. package/clinkx-workflows/dist/settings/store.js +842 -0
  158. package/clinkx-workflows/dist/settings/store.js.map +1 -0
  159. package/clinkx-workflows/dist/state-schema.d.ts +11 -0
  160. package/clinkx-workflows/dist/state-schema.js +4 -1
  161. package/clinkx-workflows/dist/state-schema.js.map +1 -1
  162. package/clinkx-workflows/dist/state.d.ts +178 -3
  163. package/clinkx-workflows/dist/state.js +618 -83
  164. package/clinkx-workflows/dist/state.js.map +1 -1
  165. package/clinkx-workflows/dist/stdio-entry.d.ts +2 -0
  166. package/clinkx-workflows/dist/stdio-entry.js +52 -0
  167. package/clinkx-workflows/dist/stdio-entry.js.map +1 -0
  168. package/clinkx-workflows/dist/transport.d.ts +2 -1
  169. package/clinkx-workflows/dist/transport.js +5 -0
  170. package/clinkx-workflows/dist/transport.js.map +1 -1
  171. package/clinkx-workflows/dist/validators/architecture-arena.d.ts +6 -0
  172. package/clinkx-workflows/dist/validators/architecture-arena.js +16 -0
  173. package/clinkx-workflows/dist/validators/architecture-arena.js.map +1 -0
  174. package/clinkx-workflows/dist/validators/index.js +4 -0
  175. package/clinkx-workflows/dist/validators/index.js.map +1 -1
  176. package/clinkx-workflows/dist/validators/ping-pong.d.ts +6 -0
  177. package/clinkx-workflows/dist/validators/ping-pong.js +10 -0
  178. package/clinkx-workflows/dist/validators/ping-pong.js.map +1 -0
  179. package/clinkx-workflows/dist/workflow-tools.d.ts +51 -5
  180. package/clinkx-workflows/dist/workflow-tools.js +785 -34
  181. package/clinkx-workflows/dist/workflow-tools.js.map +1 -1
  182. package/clinkx-workflows/dist/workflow-verification-contract.d.ts +4 -4
  183. package/clinkx-workflows/templates/architecture-arena/candidate.txt +39 -0
  184. package/clinkx-workflows/templates/architecture-arena/judge.txt +34 -0
  185. package/clinkx-workflows/templates/ping-pong/implement.txt +14 -0
  186. package/clinkx-workflows/templates/ping-pong/remediate.txt +14 -0
  187. package/clinkx-workflows/templates/ping-pong/review.txt +27 -0
  188. package/clinkx-workflows/workflows/architecture-arena.yaml +127 -0
  189. package/clinkx-workflows/workflows/ping-pong.yaml +158 -0
  190. package/dist/context-builder/bundle.js +4 -3
  191. package/dist/context-builder/bundle.js.map +1 -1
  192. package/dist/context-builder/delegate-packet.d.ts +1 -0
  193. package/dist/context-builder/delegate-packet.js +66 -7
  194. package/dist/context-builder/delegate-packet.js.map +1 -1
  195. package/dist/context-builder/delegate-validation.d.ts +12 -3
  196. package/dist/context-builder/delegate-validation.js +23 -13
  197. package/dist/context-builder/delegate-validation.js.map +1 -1
  198. package/dist/context-builder/external-gaps.d.ts +14 -3
  199. package/dist/context-builder/external-gaps.js +124 -18
  200. package/dist/context-builder/external-gaps.js.map +1 -1
  201. package/dist/context-builder/handler.js +108 -191
  202. package/dist/context-builder/handler.js.map +1 -1
  203. package/dist/context-builder/review-coverage.js +27 -1
  204. package/dist/context-builder/review-coverage.js.map +1 -1
  205. package/dist/context-builder/secrets.js +1 -1
  206. package/dist/context-builder/secrets.js.map +1 -1
  207. package/dist/context-builder/versions.d.ts +10 -4
  208. package/dist/context-builder/versions.js +10 -4
  209. package/dist/context-builder/versions.js.map +1 -1
  210. package/dist/context-builder/workflow-runner.js +33 -24
  211. package/dist/context-builder/workflow-runner.js.map +1 -1
  212. package/dist/dashboard-cli.d.ts +2 -0
  213. package/dist/dashboard-cli.js +197 -58
  214. package/dist/dashboard-cli.js.map +1 -1
  215. package/dist/dashboard-companion/client.d.ts +10 -0
  216. package/dist/dashboard-companion/client.js +43 -1
  217. package/dist/dashboard-companion/client.js.map +1 -1
  218. package/dist/dashboard-companion/config.d.ts +19 -1
  219. package/dist/dashboard-companion/config.js +104 -3
  220. package/dist/dashboard-companion/config.js.map +1 -1
  221. package/dist/dashboard-companion/protocol.d.ts +16 -0
  222. package/dist/dashboard-companion/protocol.js +55 -1
  223. package/dist/dashboard-companion/protocol.js.map +1 -1
  224. package/dist/dashboard-companion/workstation-binding.d.ts +69 -0
  225. package/dist/dashboard-companion/workstation-binding.js +192 -0
  226. package/dist/dashboard-companion/workstation-binding.js.map +1 -0
  227. package/dist/dashboard-gateway/admin-cli.d.ts +10 -0
  228. package/dist/dashboard-gateway/admin-cli.js +266 -0
  229. package/dist/dashboard-gateway/admin-cli.js.map +1 -0
  230. package/dist/dashboard-gateway/config.d.ts +50 -0
  231. package/dist/dashboard-gateway/config.js +235 -1
  232. package/dist/dashboard-gateway/config.js.map +1 -1
  233. package/dist/dashboard-gateway/connection-registry.d.ts +100 -0
  234. package/dist/dashboard-gateway/connection-registry.js +228 -0
  235. package/dist/dashboard-gateway/connection-registry.js.map +1 -0
  236. package/dist/dashboard-gateway/control-plane/account-auth.d.ts +78 -0
  237. package/dist/dashboard-gateway/control-plane/account-auth.js +198 -0
  238. package/dist/dashboard-gateway/control-plane/account-auth.js.map +1 -0
  239. package/dist/dashboard-gateway/control-plane/billing.d.ts +264 -0
  240. package/dist/dashboard-gateway/control-plane/billing.js +787 -0
  241. package/dist/dashboard-gateway/control-plane/billing.js.map +1 -0
  242. package/dist/dashboard-gateway/control-plane/contracts.d.ts +1293 -0
  243. package/dist/dashboard-gateway/control-plane/contracts.js +280 -0
  244. package/dist/dashboard-gateway/control-plane/contracts.js.map +1 -0
  245. package/dist/dashboard-gateway/control-plane/cookies.d.ts +13 -0
  246. package/dist/dashboard-gateway/control-plane/cookies.js +46 -0
  247. package/dist/dashboard-gateway/control-plane/cookies.js.map +1 -0
  248. package/dist/dashboard-gateway/control-plane/credentials.d.ts +63 -0
  249. package/dist/dashboard-gateway/control-plane/credentials.js +66 -0
  250. package/dist/dashboard-gateway/control-plane/credentials.js.map +1 -0
  251. package/dist/dashboard-gateway/control-plane/entitlements.d.ts +118 -0
  252. package/dist/dashboard-gateway/control-plane/entitlements.js +329 -0
  253. package/dist/dashboard-gateway/control-plane/entitlements.js.map +1 -0
  254. package/dist/dashboard-gateway/control-plane/errors.d.ts +17 -0
  255. package/dist/dashboard-gateway/control-plane/errors.js +23 -0
  256. package/dist/dashboard-gateway/control-plane/errors.js.map +1 -0
  257. package/dist/dashboard-gateway/control-plane/hosts.d.ts +6 -0
  258. package/dist/dashboard-gateway/control-plane/hosts.js +16 -0
  259. package/dist/dashboard-gateway/control-plane/hosts.js.map +1 -0
  260. package/dist/dashboard-gateway/control-plane/http.d.ts +34 -0
  261. package/dist/dashboard-gateway/control-plane/http.js +331 -0
  262. package/dist/dashboard-gateway/control-plane/http.js.map +1 -0
  263. package/dist/dashboard-gateway/control-plane/schema.d.ts +9 -0
  264. package/dist/dashboard-gateway/control-plane/schema.js +247 -0
  265. package/dist/dashboard-gateway/control-plane/schema.js.map +1 -0
  266. package/dist/dashboard-gateway/control-plane/secrets.d.ts +20 -0
  267. package/dist/dashboard-gateway/control-plane/secrets.js +39 -0
  268. package/dist/dashboard-gateway/control-plane/secrets.js.map +1 -0
  269. package/dist/dashboard-gateway/control-plane/store.d.ts +579 -0
  270. package/dist/dashboard-gateway/control-plane/store.js +1115 -0
  271. package/dist/dashboard-gateway/control-plane/store.js.map +1 -0
  272. package/dist/dashboard-gateway/cookie-boundary.d.ts +60 -0
  273. package/dist/dashboard-gateway/cookie-boundary.js +205 -0
  274. package/dist/dashboard-gateway/cookie-boundary.js.map +1 -0
  275. package/dist/dashboard-gateway/index.js +271 -494
  276. package/dist/dashboard-gateway/index.js.map +1 -1
  277. package/dist/dashboard-gateway/main.js +7 -2
  278. package/dist/dashboard-gateway/main.js.map +1 -1
  279. package/dist/dashboard-gateway/routing.d.ts +43 -0
  280. package/dist/dashboard-gateway/routing.js +65 -0
  281. package/dist/dashboard-gateway/routing.js.map +1 -0
  282. package/dist/dashboard-gateway/tenant-gateway.d.ts +56 -0
  283. package/dist/dashboard-gateway/tenant-gateway.js +989 -0
  284. package/dist/dashboard-gateway/tenant-gateway.js.map +1 -0
  285. package/dist/dashboard-gateway/tenant-main.d.ts +41 -0
  286. package/dist/dashboard-gateway/tenant-main.js +303 -0
  287. package/dist/dashboard-gateway/tenant-main.js.map +1 -0
  288. package/dist/dashboard-gateway/tunnel-errors.d.ts +16 -0
  289. package/dist/dashboard-gateway/tunnel-errors.js +22 -0
  290. package/dist/dashboard-gateway/tunnel-errors.js.map +1 -0
  291. package/dist/dashboard-gateway/tunnel-http.d.ts +21 -0
  292. package/dist/dashboard-gateway/tunnel-http.js +195 -0
  293. package/dist/dashboard-gateway/tunnel-http.js.map +1 -0
  294. package/dist/elaris/config.d.ts +10 -0
  295. package/dist/elaris/config.js +27 -1
  296. package/dist/elaris/config.js.map +1 -1
  297. package/dist/elaris/tools.js +4 -1
  298. package/dist/elaris/tools.js.map +1 -1
  299. package/dist/handler.d.ts +6 -0
  300. package/dist/handler.js +17 -1
  301. package/dist/handler.js.map +1 -1
  302. package/dist/index.d.ts +0 -31
  303. package/dist/index.js +41 -404
  304. package/dist/index.js.map +1 -1
  305. package/dist/lib.d.ts +17 -0
  306. package/dist/lib.js +17 -0
  307. package/dist/lib.js.map +1 -0
  308. package/dist/local-clink-backend.d.ts +2 -1
  309. package/dist/local-clink-backend.js +28 -4
  310. package/dist/local-clink-backend.js.map +1 -1
  311. package/dist/parsers/extract.d.ts +19 -1
  312. package/dist/parsers/extract.js +68 -3
  313. package/dist/parsers/extract.js.map +1 -1
  314. package/dist/pipeline.d.ts +17 -1
  315. package/dist/pipeline.js +34 -6
  316. package/dist/pipeline.js.map +1 -1
  317. package/dist/process-group.d.ts +65 -0
  318. package/dist/process-group.js +153 -0
  319. package/dist/process-group.js.map +1 -0
  320. package/dist/progress-report/lock.d.ts +17 -59
  321. package/dist/progress-report/lock.js +25 -329
  322. package/dist/progress-report/lock.js.map +1 -1
  323. package/dist/progress-report/schema.d.ts +23 -23
  324. package/dist/project-verification/files.js +1 -1
  325. package/dist/project-verification/files.js.map +1 -1
  326. package/dist/project-verification/process.js +23 -44
  327. package/dist/project-verification/process.js.map +1 -1
  328. package/dist/project-verification/service.js +9 -1
  329. package/dist/project-verification/service.js.map +1 -1
  330. package/dist/prompt.d.ts +7 -0
  331. package/dist/prompt.js +18 -1
  332. package/dist/prompt.js.map +1 -1
  333. package/dist/recipe-host/git-trust.d.ts +43 -0
  334. package/dist/recipe-host/git-trust.js +360 -0
  335. package/dist/recipe-host/git-trust.js.map +1 -0
  336. package/dist/recipe-host/git.d.ts +42 -0
  337. package/dist/recipe-host/git.js +207 -0
  338. package/dist/recipe-host/git.js.map +1 -0
  339. package/dist/recipe-host/native-recipe-host.d.ts +127 -0
  340. package/dist/recipe-host/native-recipe-host.js +880 -0
  341. package/dist/recipe-host/native-recipe-host.js.map +1 -0
  342. package/dist/recipe-host/seat-cwd.d.ts +16 -0
  343. package/dist/recipe-host/seat-cwd.js +170 -0
  344. package/dist/recipe-host/seat-cwd.js.map +1 -0
  345. package/dist/runner.d.ts +43 -1
  346. package/dist/runner.js +234 -35
  347. package/dist/runner.js.map +1 -1
  348. package/dist/server.js +84 -5
  349. package/dist/server.js.map +1 -1
  350. package/dist/settings-cli/clients.d.ts +137 -0
  351. package/dist/settings-cli/clients.js +1124 -0
  352. package/dist/settings-cli/clients.js.map +1 -0
  353. package/dist/settings-cli/commands.d.ts +67 -0
  354. package/dist/settings-cli/commands.js +726 -0
  355. package/dist/settings-cli/commands.js.map +1 -0
  356. package/dist/settings-cli/format.d.ts +34 -0
  357. package/dist/settings-cli/format.js +40 -0
  358. package/dist/settings-cli/format.js.map +1 -0
  359. package/dist/settings-cli/main.d.ts +18 -0
  360. package/dist/settings-cli/main.js +256 -0
  361. package/dist/settings-cli/main.js.map +1 -0
  362. package/dist/stdio-main.d.ts +73 -0
  363. package/dist/stdio-main.js +455 -0
  364. package/dist/stdio-main.js.map +1 -0
  365. package/docs/configuration.md +362 -40
  366. package/docs/engineering-recipes.md +291 -0
  367. package/docs/security.md +234 -6
  368. package/docs/verification/project-checks.md +24 -2
  369. package/package.json +6 -2
  370. package/clinkx-workflows/dist/dashboard-ui/assets/index-BdpmbPps.js +0 -115
  371. package/clinkx-workflows/dist/dashboard-ui/assets/style-Im5i1iAs.css +0 -1
@@ -2,19 +2,14 @@ import { createServer, validateHeaderValue, } from "node:http";
2
2
  import { timingSafeEqual } from "node:crypto";
3
3
  import { randomUUID } from "node:crypto";
4
4
  import { WebSocketServer } from "ws";
5
- import { DASHBOARD_GATEWAY_V2_SUBPROTOCOL, MAX_GATEWAY_V2_REQUEST_BODY_BYTES, isForwardableV2PostPath, parseGatewayRequest, parseGatewayV2Request, parseGatewayV2Response, } from "../dashboard-companion/protocol.js";
5
+ import { DASHBOARD_GATEWAY_V2_SUBPROTOCOL, isForwardableV2PostPath, parseGatewayRequest, parseGatewayV2Request, parseGatewayV2Response, } from "../dashboard-companion/protocol.js";
6
6
  import { isDashboardPairingToken } from "../dashboard-pairing-token.js";
7
- const MAX_AGENT_FRAME_BYTES = 24 * 1024 * 1024;
8
- const MAX_FORWARD_PATH_BYTES = 2_048;
9
- const MAX_FORWARD_HEADER_BYTES = 64 * 1024;
7
+ import { filterBrowserCookieHeader, filterCompanionSetCookies, } from "./cookie-boundary.js";
8
+ import { ConnectionRegistry, LEGACY_CONNECTION_SLOT, } from "./connection-registry.js";
9
+ import { COMPANION_UNAVAILABLE, DEFAULT_PING_INTERVAL_MS, DEFAULT_REQUEST_TIMEOUT_MS, MAX_AGENT_FRAME_BYTES, MAX_FORWARD_HEADER_BYTES, MAX_V2_IN_FLIGHT, OUTCOME_UNKNOWN, PASSKEY_COMPANION_UNAVAILABLE, isAllowedApiTarget, readV2RequestBody, rejectUpgrade, sendJson, sendText, v2PostBodyLimit, v2RequestHeaders, v2ResponseHeaders, } from "./tunnel-http.js";
10
10
  const MAX_REQUEST_MESSAGE_BYTES = 64 * 1024;
11
11
  const MAX_RESPONSE_BODY_BYTES = 16 * 1024 * 1024;
12
12
  const MAX_IN_FLIGHT = 128;
13
- const MAX_V2_IN_FLIGHT = 8;
14
- const MAX_V2_SMALL_POST_BYTES = 4 * 1024;
15
- const MAX_RETIRED_REQUEST_IDS = 1_024;
16
- const DEFAULT_REQUEST_TIMEOUT_MS = 30_000;
17
- const DEFAULT_PING_INTERVAL_MS = 10_000;
18
13
  const RESPONSE_HEADER_ALLOWLIST = new Set([
19
14
  "access-control-allow-headers",
20
15
  "access-control-allow-methods",
@@ -27,22 +22,6 @@ const RESPONSE_HEADER_ALLOWLIST = new Set([
27
22
  "vary",
28
23
  "x-clinkx-agent-instance-id",
29
24
  ]);
30
- function sendText(response, status, body) {
31
- response.writeHead(status, {
32
- "cache-control": "no-store",
33
- "content-type": "text/plain; charset=utf-8",
34
- });
35
- response.end(body);
36
- }
37
- function sendJson(response, status, error) {
38
- const body = `${JSON.stringify({ error })}\n`;
39
- response.writeHead(status, {
40
- "cache-control": "no-store",
41
- "content-type": "application/json; charset=utf-8",
42
- "content-length": Buffer.byteLength(body),
43
- });
44
- response.end(body);
45
- }
46
25
  function requestHeaders(request) {
47
26
  const result = { host: request.headers.host ?? "" };
48
27
  const copy = (source, target) => {
@@ -57,123 +36,9 @@ function requestHeaders(request) {
57
36
  copy("x-clinkx-agent-instance-id", "agentInstanceId");
58
37
  return result;
59
38
  }
60
- function oneHeader(request, name) {
61
- const values = request.headersDistinct[name];
62
- if (values === undefined)
63
- return undefined;
64
- return values.length === 1 && values[0] !== undefined && values[0] !== ""
65
- ? values[0]
66
- : null;
67
- }
68
- const V2_PROGRESS_REPORT_STATUS_OVERRIDE_PATH = /^\/api\/progress-reports\/[A-Za-z0-9][A-Za-z0-9_-]{0,63}\/status-override$/;
69
- function v2PostBodyLimit(path) {
70
- return path === "/api/auth/register/options"
71
- || path === "/api/auth/login/options"
72
- || path === "/api/auth/logout"
73
- || V2_PROGRESS_REPORT_STATUS_OVERRIDE_PATH.test(path)
74
- ? MAX_V2_SMALL_POST_BYTES
75
- : MAX_GATEWAY_V2_REQUEST_BODY_BYTES;
76
- }
77
- function v2RequestHeaders(request, method, path) {
78
- const host = oneHeader(request, "host");
79
- const origin = oneHeader(request, "origin");
80
- const cookie = oneHeader(request, "cookie");
81
- const contentType = oneHeader(request, "content-type");
82
- const enrollmentCode = oneHeader(request, "x-enrollment-code");
83
- if (host == null || origin === null || cookie === null || contentType === null || enrollmentCode === null) {
84
- return undefined;
85
- }
86
- if (method === "POST") {
87
- if (contentType === undefined || contentType.toLowerCase() !== "application/json")
88
- return undefined;
89
- if (enrollmentCode !== undefined
90
- && path !== "/api/auth/register/options"
91
- && path !== "/api/auth/register/verify")
92
- return undefined;
93
- }
94
- else if (contentType !== undefined || enrollmentCode !== undefined) {
95
- return undefined;
96
- }
97
- return {
98
- host,
99
- ...(origin === undefined ? {} : { origin }),
100
- ...(cookie === undefined ? {} : { cookie }),
101
- ...(contentType === undefined ? {} : { contentType }),
102
- ...(enrollmentCode === undefined ? {} : { enrollmentCode }),
103
- };
104
- }
105
- async function readV2RequestBody(request, maximumBytes, signal) {
106
- return new Promise((resolve, reject) => {
107
- const chunks = [];
108
- let total = 0;
109
- let settled = false;
110
- const cleanup = () => {
111
- request.off("data", onData);
112
- request.off("end", onEnd);
113
- request.off("error", onError);
114
- request.off("aborted", onAborted);
115
- signal.removeEventListener("abort", onAbort);
116
- };
117
- const finish = (body) => {
118
- if (settled)
119
- return;
120
- settled = true;
121
- cleanup();
122
- resolve(body);
123
- };
124
- const onData = (chunk) => {
125
- const bytes = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
126
- total += bytes.byteLength;
127
- if (total > maximumBytes) {
128
- request.resume();
129
- finish(undefined);
130
- return;
131
- }
132
- chunks.push(bytes);
133
- };
134
- const onEnd = () => finish(Buffer.concat(chunks));
135
- const onError = (error) => {
136
- if (settled)
137
- return;
138
- settled = true;
139
- cleanup();
140
- reject(error);
141
- };
142
- const onAborted = () => finish(undefined);
143
- const onAbort = () => {
144
- request.resume();
145
- finish(undefined);
146
- };
147
- if (signal.aborted) {
148
- onAbort();
149
- return;
150
- }
151
- request.on("data", onData);
152
- request.once("end", onEnd);
153
- request.once("error", onError);
154
- request.once("aborted", onAborted);
155
- signal.addEventListener("abort", onAbort, { once: true });
156
- });
157
- }
158
39
  function byteSize(value) {
159
40
  return Buffer.byteLength(JSON.stringify(value));
160
41
  }
161
- function isAllowedApiTarget(path) {
162
- if (Buffer.byteLength(path) > MAX_FORWARD_PATH_BYTES)
163
- return false;
164
- const rawPathname = path.split("?", 1)[0] ?? "";
165
- if (/%(?:00|2e|2f|5c)/i.test(rawPathname) || rawPathname.includes("\\"))
166
- return false;
167
- try {
168
- const parsed = new URL(path, "http://dashboard-gateway.invalid");
169
- return parsed.origin === "http://dashboard-gateway.invalid"
170
- && `${parsed.pathname}${parsed.search}` === path
171
- && (parsed.pathname === "/api" || parsed.pathname.startsWith("/api/"));
172
- }
173
- catch {
174
- return false;
175
- }
176
- }
177
42
  function decodeBase64(value) {
178
43
  if (typeof value !== "string" || value.length % 4 !== 0)
179
44
  return undefined;
@@ -216,14 +81,6 @@ function tokenMatches(header, expectedToken) {
216
81
  const expected = Buffer.from(expectedToken);
217
82
  return actual.length === expected.length && timingSafeEqual(actual, expected);
218
83
  }
219
- function rejectUpgrade(socket, status, reason) {
220
- const body = `${reason}\n`;
221
- socket.end(`HTTP/1.1 ${status} ${reason}\r\n` +
222
- "Connection: close\r\n" +
223
- "Cache-Control: no-store\r\n" +
224
- "Content-Type: text/plain; charset=utf-8\r\n" +
225
- `Content-Length: ${Buffer.byteLength(body)}\r\n\r\n${body}`);
226
- }
227
84
  export function createDashboardGateway(options) {
228
85
  if (!isDashboardPairingToken(options.token)) {
229
86
  throw new Error("Dashboard gateway token is invalid");
@@ -239,44 +96,60 @@ export function createDashboardGateway(options) {
239
96
  // Production default 10s → 20s miss window, which is max(15s, 2×interval).
240
97
  // Tests inject a short interval; a literal 15s floor would make those tests wait 15s.
241
98
  const pongDeadlineMs = pingIntervalMs * 2;
242
- const pending = new Map();
243
- const retiredRequestIds = new Set();
244
- let agent;
245
- let v2Reservations = 0;
246
- const reserveV2Request = () => {
247
- if (v2Reservations >= MAX_V2_IN_FLIGHT)
248
- return false;
249
- v2Reservations += 1;
250
- return true;
99
+ const registry = new ConnectionRegistry((websocket) => websocket.readyState === 1);
100
+ const slot = LEGACY_CONNECTION_SLOT;
101
+ const finish = (connection, id, outcome) => {
102
+ const settled = registry.settle(connection, id, outcome);
103
+ if (settled === undefined)
104
+ return undefined;
105
+ clearTimeout(settled.value.timeout);
106
+ settled.value.bodyRead?.abort();
107
+ return settled.value;
251
108
  };
252
- const releaseV2Request = () => {
253
- if (v2Reservations > 0)
254
- v2Reservations -= 1;
109
+ const respondCompanionLost = (lost) => {
110
+ const item = lost.value;
111
+ if (item.response.writableEnded || item.response.destroyed)
112
+ return;
113
+ // A forwarded mutation may already have run on the workstation, so it is never replayed.
114
+ const uncertainMutation = lost.phase === "forwarded" && item.method !== "GET" && item.method !== "HEAD";
115
+ if (uncertainMutation)
116
+ sendJson(item.response, 502, OUTCOME_UNKNOWN);
117
+ else
118
+ sendJson(item.response, 503, item.unavailableError);
255
119
  };
256
- const dropPending = (id) => {
257
- const item = pending.get(id);
258
- if (item === undefined)
259
- return undefined;
260
- pending.delete(id);
261
- if (item.version === 2)
262
- releaseV2Request();
263
- return item;
120
+ const failOwnerLost = (lost) => {
121
+ clearTimeout(lost.value.timeout);
122
+ lost.value.bodyRead?.abort();
123
+ respondCompanionLost(lost);
264
124
  };
265
- const retireRequestId = (id) => {
266
- retiredRequestIds.add(id);
267
- while (retiredRequestIds.size > MAX_RETIRED_REQUEST_IDS) {
268
- const oldest = retiredRequestIds.values().next().value;
269
- if (oldest === undefined)
270
- break;
271
- retiredRequestIds.delete(oldest);
272
- }
125
+ const startDeadline = (connection, id, delayMs) => {
126
+ const timeout = setTimeout(() => {
127
+ const item = finish(connection, id, "abandoned");
128
+ if (item !== undefined && !item.response.destroyed && !item.response.writableEnded) {
129
+ sendJson(item.response, 504, "dashboard_companion_timeout");
130
+ }
131
+ }, Math.max(1, delayMs));
132
+ timeout.unref();
133
+ return timeout;
273
134
  };
274
- const failPending = (status, error) => {
275
- for (const [id, item] of pending) {
276
- clearTimeout(item.timeout);
277
- dropPending(id);
278
- if (!item.response.writableEnded)
279
- sendJson(item.response, status, error);
135
+ const forward = (connection, id, wireRequest) => {
136
+ const failSend = () => {
137
+ const lost = registry.settle(connection, id, "abandoned");
138
+ if (lost !== undefined)
139
+ failOwnerLost(lost);
140
+ };
141
+ if (!registry.markForwarded(connection, id)) {
142
+ failSend();
143
+ return;
144
+ }
145
+ try {
146
+ connection.socket.send(wireRequest, (error) => {
147
+ if (error)
148
+ failSend();
149
+ });
150
+ }
151
+ catch {
152
+ failSend();
280
153
  }
281
154
  };
282
155
  const server = createServer({ maxHeaderSize: MAX_FORWARD_HEADER_BYTES }, (request, response) => {
@@ -292,87 +165,67 @@ export function createDashboardGateway(options) {
292
165
  }
293
166
  const v2Post = method === "POST" && isForwardableV2PostPath(path);
294
167
  if (v2Post) {
295
- if (agent === undefined || agent.websocket.readyState !== 1 || agent.version !== 2) {
168
+ const connection = registry.current(slot);
169
+ if (connection === undefined || connection.version !== 2) {
296
170
  request.resume();
297
- sendJson(response, 503, "dashboard_passkey_companion_unavailable");
171
+ sendJson(response, 503, PASSKEY_COMPANION_UNAVAILABLE);
298
172
  return;
299
173
  }
300
- if (!reserveV2Request()) {
174
+ const cookies = filterBrowserCookieHeader(request.headersDistinct.cookie);
175
+ if (!cookies.ok) {
301
176
  request.resume();
302
- sendJson(response, 503, "dashboard_gateway_capacity_exceeded");
177
+ sendJson(response, cookies.status, cookies.code);
303
178
  return;
304
179
  }
305
- const bodyReadAbort = new AbortController();
180
+ const id = randomUUID();
306
181
  const requestDeadlineAt = Date.now() + requestTimeoutMs;
307
- let pendingId;
308
- let reservationHeld = true;
309
- let bodyTimedOut = false;
310
- let bodyDeadline;
311
- const clearBodyDeadline = () => {
312
- if (bodyDeadline !== undefined) {
313
- clearTimeout(bodyDeadline);
314
- bodyDeadline = undefined;
315
- }
316
- };
317
- const releaseReservation = () => {
318
- if (!reservationHeld)
319
- return;
320
- reservationHeld = false;
321
- releaseV2Request();
322
- };
182
+ const bodyRead = new AbortController();
183
+ const timeout = startDeadline(connection, id, requestTimeoutMs);
184
+ const admitted = registry.admit(connection, id, {
185
+ response,
186
+ method,
187
+ timeout,
188
+ bodyRead,
189
+ unavailableError: PASSKEY_COMPANION_UNAVAILABLE,
190
+ }, MAX_V2_IN_FLIGHT);
191
+ if (admitted !== "admitted") {
192
+ clearTimeout(timeout);
193
+ request.resume();
194
+ sendJson(response, 503, "dashboard_gateway_capacity_exceeded");
195
+ return;
196
+ }
323
197
  response.once("close", () => {
324
- if (pendingId !== undefined) {
325
- const item = dropPending(pendingId);
326
- if (item !== undefined) {
327
- clearTimeout(item.timeout);
328
- retireRequestId(pendingId);
329
- }
330
- return;
331
- }
332
- clearBodyDeadline();
333
- bodyReadAbort.abort();
334
- releaseReservation();
198
+ finish(connection, id, "abandoned");
335
199
  });
336
- bodyDeadline = setTimeout(() => {
337
- if (!reservationHeld)
338
- return;
339
- bodyTimedOut = true;
340
- bodyReadAbort.abort();
341
- releaseReservation();
342
- if (!response.destroyed && !response.writableEnded) {
343
- sendJson(response, 504, "dashboard_companion_timeout");
344
- }
345
- }, Math.max(1, requestDeadlineAt - Date.now()));
346
- bodyDeadline.unref();
347
- const headers = v2RequestHeaders(request, "POST", path);
200
+ const headers = v2RequestHeaders(request, "POST", path, cookies.cookie);
348
201
  if (headers === undefined) {
349
202
  request.resume();
350
- clearBodyDeadline();
351
- bodyReadAbort.abort();
352
- releaseReservation();
203
+ finish(connection, id, "failed");
353
204
  sendJson(response, 400, "invalid_request");
354
205
  return;
355
206
  }
356
- void readV2RequestBody(request, v2PostBodyLimit(path), bodyReadAbort.signal).then((body) => {
357
- clearBodyDeadline();
358
- if (bodyTimedOut || response.destroyed || response.writableEnded || !reservationHeld)
207
+ void readV2RequestBody(request, v2PostBodyLimit(path), bodyRead.signal).then((body) => {
208
+ if (registry.owned(connection, id)?.phase !== "admitted")
359
209
  return;
210
+ if (response.destroyed || response.writableEnded) {
211
+ finish(connection, id, "failed");
212
+ return;
213
+ }
360
214
  if (Date.now() >= requestDeadlineAt) {
361
- releaseReservation();
215
+ finish(connection, id, "failed");
362
216
  sendJson(response, 504, "dashboard_companion_timeout");
363
217
  return;
364
218
  }
365
219
  if (body === undefined) {
366
- releaseReservation();
220
+ finish(connection, id, "failed");
367
221
  sendJson(response, 413, "payload_too_large");
368
222
  return;
369
223
  }
370
- if (agent === undefined || agent.websocket.readyState !== 1 || agent.version !== 2) {
371
- releaseReservation();
372
- sendJson(response, 503, "dashboard_passkey_companion_unavailable");
224
+ if (!registry.isCurrent(connection)) {
225
+ finish(connection, id, "failed");
226
+ sendJson(response, 503, PASSKEY_COMPANION_UNAVAILABLE);
373
227
  return;
374
228
  }
375
- const id = randomUUID();
376
229
  let wireRequest;
377
230
  try {
378
231
  wireRequest = JSON.stringify(parseGatewayV2Request(JSON.stringify({
@@ -386,46 +239,16 @@ export function createDashboardGateway(options) {
386
239
  })));
387
240
  }
388
241
  catch {
389
- releaseReservation();
242
+ finish(connection, id, "failed");
390
243
  sendJson(response, 400, "invalid_request");
391
244
  return;
392
245
  }
393
- const timeout = setTimeout(() => {
394
- const item = dropPending(id);
395
- if (item === undefined)
396
- return;
397
- retireRequestId(id);
398
- sendJson(item.response, 504, "dashboard_companion_timeout");
399
- }, requestDeadlineAt - Date.now());
400
- timeout.unref();
401
- pending.set(id, { response, method, timeout, version: 2 });
402
- pendingId = id;
403
- reservationHeld = false;
404
- try {
405
- agent.websocket.send(wireRequest, (error) => {
406
- if (!error)
407
- return;
408
- const item = dropPending(id);
409
- if (item === undefined)
410
- return;
411
- clearTimeout(item.timeout);
412
- retireRequestId(id);
413
- sendJson(item.response, 503, "dashboard_passkey_companion_unavailable");
414
- });
415
- }
416
- catch {
417
- const item = dropPending(id);
418
- if (item !== undefined) {
419
- clearTimeout(item.timeout);
420
- retireRequestId(id);
421
- sendJson(item.response, 503, "dashboard_passkey_companion_unavailable");
422
- }
423
- }
246
+ forward(connection, id, wireRequest);
424
247
  }).catch(() => {
425
- clearBodyDeadline();
426
- if (bodyTimedOut || response.destroyed || response.writableEnded)
248
+ if (finish(connection, id, "failed") === undefined)
249
+ return;
250
+ if (response.destroyed || response.writableEnded)
427
251
  return;
428
- releaseReservation();
429
252
  sendJson(response, 400, "invalid_request");
430
253
  });
431
254
  return;
@@ -443,28 +266,49 @@ export function createDashboardGateway(options) {
443
266
  sendJson(response, 413, "request_body_not_allowed");
444
267
  return;
445
268
  }
446
- if (agent === undefined || agent.websocket.readyState !== 1) {
447
- sendJson(response, 503, "dashboard_companion_unavailable");
269
+ const connection = registry.current(slot);
270
+ if (connection === undefined) {
271
+ sendJson(response, 503, COMPANION_UNAVAILABLE);
448
272
  return;
449
273
  }
450
- if (agent.version === 2 && method === "OPTIONS") {
274
+ if (connection.version === 2 && method === "OPTIONS") {
451
275
  response.setHeader("allow", "GET, HEAD");
452
276
  sendJson(response, 405, "method_not_allowed");
453
277
  return;
454
278
  }
455
- if (agent.version === 2 && method !== "OPTIONS") {
456
- if (!reserveV2Request()) {
457
- sendJson(response, 503, "dashboard_gateway_capacity_exceeded");
279
+ let v2Cookie;
280
+ if (connection.version === 2) {
281
+ const cookies = filterBrowserCookieHeader(request.headersDistinct.cookie);
282
+ if (!cookies.ok) {
283
+ sendJson(response, cookies.status, cookies.code);
458
284
  return;
459
285
  }
460
- const headers = v2RequestHeaders(request, method, path);
286
+ v2Cookie = cookies.cookie;
287
+ }
288
+ const id = randomUUID();
289
+ const timeout = startDeadline(connection, id, requestTimeoutMs);
290
+ const admitted = registry.admit(connection, id, {
291
+ response,
292
+ method,
293
+ timeout,
294
+ unavailableError: COMPANION_UNAVAILABLE,
295
+ }, connection.version === 2 ? MAX_V2_IN_FLIGHT : MAX_IN_FLIGHT);
296
+ if (admitted !== "admitted") {
297
+ clearTimeout(timeout);
298
+ sendJson(response, 503, "dashboard_gateway_capacity_exceeded");
299
+ return;
300
+ }
301
+ response.once("close", () => {
302
+ finish(connection, id, "abandoned");
303
+ });
304
+ let wireRequest;
305
+ if (connection.version === 2) {
306
+ const headers = v2RequestHeaders(request, method, path, v2Cookie);
461
307
  if (headers === undefined) {
462
- releaseV2Request();
308
+ finish(connection, id, "failed");
463
309
  sendJson(response, 400, "invalid_request");
464
310
  return;
465
311
  }
466
- const id = randomUUID();
467
- let wireRequest;
468
312
  try {
469
313
  wireRequest = JSON.stringify(parseGatewayV2Request(JSON.stringify({
470
314
  v: 2,
@@ -477,104 +321,33 @@ export function createDashboardGateway(options) {
477
321
  })));
478
322
  }
479
323
  catch {
480
- releaseV2Request();
324
+ finish(connection, id, "failed");
481
325
  sendJson(response, 400, "invalid_request");
482
326
  return;
483
327
  }
484
- const timeout = setTimeout(() => {
485
- const item = dropPending(id);
486
- if (item === undefined)
487
- return;
488
- retireRequestId(id);
489
- sendJson(item.response, 504, "dashboard_companion_timeout");
490
- }, requestTimeoutMs);
491
- timeout.unref();
492
- pending.set(id, { response, method, timeout, version: 2 });
328
+ }
329
+ else {
330
+ const headers = requestHeaders(request);
331
+ if (byteSize(headers) > MAX_FORWARD_HEADER_BYTES) {
332
+ finish(connection, id, "failed");
333
+ sendJson(response, 431, "request_headers_too_large");
334
+ return;
335
+ }
493
336
  try {
494
- agent.websocket.send(wireRequest, (error) => {
495
- if (!error)
496
- return;
497
- const item = dropPending(id);
498
- if (item === undefined)
499
- return;
500
- clearTimeout(item.timeout);
501
- retireRequestId(id);
502
- sendJson(item.response, 503, "dashboard_companion_unavailable");
503
- });
337
+ wireRequest = JSON.stringify(parseGatewayRequest(JSON.stringify({ v: 1, type: "request", id, method, path, headers })));
504
338
  }
505
339
  catch {
506
- const item = dropPending(id);
507
- if (item !== undefined) {
508
- clearTimeout(item.timeout);
509
- retireRequestId(id);
510
- sendJson(item.response, 503, "dashboard_companion_unavailable");
511
- }
512
- }
513
- response.once("close", () => {
514
- if (response.writableEnded)
515
- return;
516
- const item = dropPending(id);
517
- if (item !== undefined) {
518
- clearTimeout(item.timeout);
519
- retireRequestId(id);
520
- }
521
- });
522
- return;
523
- }
524
- if (pending.size >= MAX_IN_FLIGHT) {
525
- sendJson(response, 503, "dashboard_gateway_capacity_exceeded");
526
- return;
527
- }
528
- const headers = requestHeaders(request);
529
- if (byteSize(headers) > MAX_FORWARD_HEADER_BYTES) {
530
- sendJson(response, 431, "request_headers_too_large");
531
- return;
532
- }
533
- const id = randomUUID();
534
- let wireRequest;
535
- try {
536
- const admitted = parseGatewayRequest(JSON.stringify({ v: 1, type: "request", id, method, path, headers }));
537
- wireRequest = JSON.stringify(admitted);
538
- }
539
- catch {
540
- sendJson(response, 431, "request_headers_too_large");
541
- return;
542
- }
543
- if (Buffer.byteLength(wireRequest) > MAX_REQUEST_MESSAGE_BYTES) {
544
- sendJson(response, 431, "request_headers_too_large");
545
- return;
546
- }
547
- const timeout = setTimeout(() => {
548
- const item = pending.get(id);
549
- if (item === undefined)
550
- return;
551
- dropPending(id);
552
- retireRequestId(id);
553
- sendJson(item.response, 504, "dashboard_companion_timeout");
554
- }, requestTimeoutMs);
555
- timeout.unref();
556
- pending.set(id, { response, method, timeout, version: 1 });
557
- agent.websocket.send(wireRequest, (error) => {
558
- if (!error)
340
+ finish(connection, id, "failed");
341
+ sendJson(response, 431, "request_headers_too_large");
559
342
  return;
560
- const item = pending.get(id);
561
- if (item === undefined)
562
- return;
563
- clearTimeout(item.timeout);
564
- dropPending(id);
565
- retireRequestId(id);
566
- sendJson(item.response, 503, "dashboard_companion_unavailable");
567
- });
568
- response.once("close", () => {
569
- if (response.writableEnded)
343
+ }
344
+ if (Buffer.byteLength(wireRequest) > MAX_REQUEST_MESSAGE_BYTES) {
345
+ finish(connection, id, "failed");
346
+ sendJson(response, 431, "request_headers_too_large");
570
347
  return;
571
- const item = pending.get(id);
572
- if (item !== undefined)
573
- clearTimeout(item.timeout);
574
- dropPending(id);
575
- if (item !== undefined)
576
- retireRequestId(id);
577
- });
348
+ }
349
+ }
350
+ forward(connection, id, wireRequest);
578
351
  });
579
352
  const websocketServer = new WebSocketServer({
580
353
  noServer: true,
@@ -586,118 +359,136 @@ export function createDashboardGateway(options) {
586
359
  : false;
587
360
  },
588
361
  });
589
- websocketServer.on("connection", (websocket) => {
590
- websocket.on("error", () => undefined);
591
- const version = websocket.protocol === DASHBOARD_GATEWAY_V2_SUBPROTOCOL ? 2 : 1;
592
- websocket.on("message", (data, isBinary) => {
593
- if (isBinary) {
594
- websocket.close(1003, "text messages required");
595
- return;
596
- }
597
- let message;
362
+ const handleAgentMessage = (connection, data, isBinary) => {
363
+ // Replies from a displaced generation are dropped; their requests were already failed.
364
+ if (!registry.isAttached(connection))
365
+ return;
366
+ const websocket = connection.socket;
367
+ if (isBinary) {
368
+ websocket.close(1003, "text messages required");
369
+ return;
370
+ }
371
+ let message;
372
+ try {
373
+ const parsed = JSON.parse(data.toString());
374
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed))
375
+ throw new Error();
376
+ message = parsed;
377
+ }
378
+ catch {
379
+ websocket.close(1007, "invalid response");
380
+ return;
381
+ }
382
+ if (typeof message.id !== "string") {
383
+ websocket.close(1008, "invalid response");
384
+ return;
385
+ }
386
+ const id = message.id;
387
+ const lookup = registry.lookupResponse(connection, id);
388
+ if (lookup.kind === "late" || lookup.kind === "stale_connection")
389
+ return;
390
+ if (lookup.kind === "unknown") {
391
+ websocket.close(1008, "unknown response id");
392
+ return;
393
+ }
394
+ const item = lookup.request.value;
395
+ if (connection.version === 2) {
396
+ let parsed;
598
397
  try {
599
- const parsed = JSON.parse(data.toString());
600
- if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed))
601
- throw new Error();
602
- message = parsed;
398
+ parsed = parseGatewayV2Response(data.toString());
603
399
  }
604
400
  catch {
605
- websocket.close(1007, "invalid response");
606
- return;
607
- }
608
- if (typeof message.id !== "string") {
401
+ finish(connection, id, "failed");
402
+ sendJson(item.response, 502, "invalid_companion_response");
609
403
  websocket.close(1008, "invalid response");
610
404
  return;
611
405
  }
612
- const item = pending.get(message.id);
613
- if (item === undefined) {
614
- if (retiredRequestIds.delete(message.id))
615
- return;
616
- websocket.close(1008, "unknown response id");
406
+ const cookies = filterCompanionSetCookies(parsed.headers.setCookies);
407
+ if (!cookies.ok) {
408
+ finish(connection, id, "failed");
409
+ process.stderr.write(`Dashboard gateway rejected companion Set-Cookie: code=${cookies.code} index=${String(cookies.index)}\n`);
410
+ sendJson(item.response, 502, "companion_cookie_rejected");
617
411
  return;
618
412
  }
619
- if (item.version !== version) {
413
+ const body = Buffer.from(parsed.bodyBase64, "base64");
414
+ const headers = v2ResponseHeaders(parsed.headers, cookies.setCookies);
415
+ if (parsed.headers.contentLength !== undefined
416
+ && item.method !== "HEAD"
417
+ && Number(parsed.headers.contentLength) !== body.byteLength) {
418
+ finish(connection, id, "failed");
419
+ sendJson(item.response, 502, "invalid_companion_response");
620
420
  websocket.close(1008, "invalid response");
621
421
  return;
622
422
  }
623
- if (version === 2) {
624
- let parsed;
625
- try {
626
- parsed = parseGatewayV2Response(data.toString());
627
- }
628
- catch {
629
- clearTimeout(item.timeout);
630
- dropPending(message.id);
631
- sendJson(item.response, 502, "invalid_companion_response");
632
- websocket.close(1008, "invalid response");
633
- return;
634
- }
635
- const body = Buffer.from(parsed.bodyBase64, "base64");
636
- const headers = {
637
- ...(parsed.headers.allow === undefined ? {} : { allow: parsed.headers.allow }),
638
- ...(parsed.headers.cacheControl === undefined ? {} : { "cache-control": parsed.headers.cacheControl }),
639
- ...(parsed.headers.contentLength === undefined ? {} : { "content-length": parsed.headers.contentLength }),
640
- ...(parsed.headers.contentType === undefined ? {} : { "content-type": parsed.headers.contentType }),
641
- ...(parsed.headers.etag === undefined ? {} : { etag: parsed.headers.etag }),
642
- ...(parsed.headers.retryAfter === undefined ? {} : { "retry-after": parsed.headers.retryAfter }),
643
- ...(parsed.headers.setCookies === undefined ? {} : { "set-cookie": [...parsed.headers.setCookies] }),
644
- ...(parsed.headers.validatorSchemaId === undefined ? {} : { "x-clinkx-validator-schema-id": parsed.headers.validatorSchemaId }),
645
- ...(parsed.headers.vary === undefined ? {} : { vary: parsed.headers.vary }),
646
- };
647
- if (parsed.headers.contentLength !== undefined
648
- && item.method !== "HEAD"
649
- && Number(parsed.headers.contentLength) !== body.byteLength) {
650
- clearTimeout(item.timeout);
651
- dropPending(parsed.id);
652
- sendJson(item.response, 502, "invalid_companion_response");
653
- websocket.close(1008, "invalid response");
654
- return;
655
- }
423
+ try {
424
+ item.response.writeHead(parsed.status, headers);
425
+ }
426
+ catch {
427
+ finish(connection, id, "failed");
656
428
  try {
657
- item.response.writeHead(parsed.status, headers);
658
- }
659
- catch {
660
- clearTimeout(item.timeout);
661
- dropPending(parsed.id);
662
- try {
663
- if (!item.response.headersSent && !item.response.writableEnded) {
664
- sendJson(item.response, 502, "invalid_companion_response");
665
- }
666
- else {
667
- item.response.destroy();
668
- }
429
+ if (!item.response.headersSent && !item.response.writableEnded) {
430
+ sendJson(item.response, 502, "invalid_companion_response");
669
431
  }
670
- catch {
432
+ else {
671
433
  item.response.destroy();
672
434
  }
673
- websocket.close(1008, "invalid response");
674
- return;
675
435
  }
676
- clearTimeout(item.timeout);
677
- dropPending(parsed.id);
678
- item.response.end(item.method === "HEAD" ? undefined : body);
679
- return;
680
- }
681
- if (message.v !== 1 || message.type !== "response") {
436
+ catch {
437
+ item.response.destroy();
438
+ }
682
439
  websocket.close(1008, "invalid response");
683
440
  return;
684
441
  }
685
- const status = message.status;
686
- const headers = allowedResponseHeaders(message.headers);
687
- const body = decodeBase64(message.bodyBase64);
688
- if (!Number.isInteger(status) || status < 100 || status > 599 || headers === undefined || body === undefined) {
689
- clearTimeout(item.timeout);
690
- dropPending(message.id);
691
- sendJson(item.response, 502, "invalid_companion_response");
692
- websocket.close(1008, "invalid response");
442
+ finish(connection, id, "completed");
443
+ item.response.end(item.method === "HEAD" ? undefined : body);
444
+ return;
445
+ }
446
+ if (message.v !== 1 || message.type !== "response") {
447
+ websocket.close(1008, "invalid response");
448
+ return;
449
+ }
450
+ const status = message.status;
451
+ const headers = allowedResponseHeaders(message.headers);
452
+ const body = decodeBase64(message.bodyBase64);
453
+ if (!Number.isInteger(status) || status < 100 || status > 599 || headers === undefined || body === undefined) {
454
+ finish(connection, id, "failed");
455
+ sendJson(item.response, 502, "invalid_companion_response");
456
+ websocket.close(1008, "invalid response");
457
+ return;
458
+ }
459
+ finish(connection, id, "completed");
460
+ item.response.writeHead(status, headers);
461
+ item.response.end(item.method === "HEAD" ? undefined : body);
462
+ };
463
+ const installConnection = (connection) => {
464
+ const websocket = connection.socket;
465
+ websocket.on("error", () => undefined);
466
+ let lastPongAt = Date.now();
467
+ const heartbeat = setInterval(() => {
468
+ if (websocket.readyState !== 1)
469
+ return;
470
+ if (Date.now() - lastPongAt > pongDeadlineMs) {
471
+ websocket.terminate();
693
472
  return;
694
473
  }
695
- clearTimeout(item.timeout);
696
- dropPending(message.id);
697
- item.response.writeHead(status, headers);
698
- item.response.end(item.method === "HEAD" ? undefined : body);
474
+ try {
475
+ websocket.ping();
476
+ }
477
+ catch {
478
+ websocket.terminate();
479
+ }
480
+ }, pingIntervalMs);
481
+ heartbeat.unref();
482
+ websocket.on("pong", () => {
483
+ lastPongAt = Date.now();
699
484
  });
700
- });
485
+ websocket.once("close", () => {
486
+ clearInterval(heartbeat);
487
+ for (const lost of registry.detach(connection))
488
+ failOwnerLost(lost);
489
+ });
490
+ websocket.on("message", (data, isBinary) => handleAgentMessage(connection, data, isBinary));
491
+ };
701
492
  server.on("upgrade", (request, socket, head) => {
702
493
  if (request.url !== "/agent") {
703
494
  rejectUpgrade(socket, 404, "Not Found");
@@ -713,44 +504,29 @@ export function createDashboardGateway(options) {
713
504
  rejectUpgrade(socket, 426, "Upgrade Required");
714
505
  return;
715
506
  }
716
- if (agent !== undefined && agent.websocket.readyState === 1) {
507
+ const claim = registry.claim(slot);
508
+ if (claim === undefined) {
717
509
  rejectUpgrade(socket, 409, "Conflict");
718
510
  return;
719
511
  }
720
- websocketServer.handleUpgrade(request, socket, head, (websocket) => {
721
- if (agent !== undefined) {
722
- failPending(503, "dashboard_companion_unavailable");
723
- }
724
- let lastPongAt = Date.now();
725
- const heartbeat = setInterval(() => {
726
- if (websocket.readyState !== 1)
727
- return;
728
- if (Date.now() - lastPongAt > pongDeadlineMs) {
512
+ try {
513
+ websocketServer.handleUpgrade(request, socket, head, (websocket) => {
514
+ const version = websocket.protocol === DASHBOARD_GATEWAY_V2_SUBPROTOCOL ? 2 : 1;
515
+ const attached = registry.attach(claim, websocket, version);
516
+ if (attached === undefined) {
729
517
  websocket.terminate();
730
518
  return;
731
519
  }
732
- try {
733
- websocket.ping();
734
- }
735
- catch {
736
- websocket.terminate();
737
- }
738
- }, pingIntervalMs);
739
- heartbeat.unref();
740
- websocket.on("pong", () => {
741
- lastPongAt = Date.now();
742
- });
743
- websocket.once("close", () => {
744
- clearInterval(heartbeat);
745
- if (agent?.websocket === websocket) {
746
- agent = undefined;
747
- failPending(503, "dashboard_companion_unavailable");
748
- }
520
+ for (const lost of attached.displacedRequests)
521
+ failOwnerLost(lost);
522
+ installConnection(attached.connection);
749
523
  });
750
- agent = { websocket, version: websocket.protocol === DASHBOARD_GATEWAY_V2_SUBPROTOCOL ? 2 : 1 };
751
- retiredRequestIds.clear();
752
- websocketServer.emit("connection", websocket, request);
753
- });
524
+ }
525
+ finally {
526
+ // Without verifyClient, ws completes or aborts the handshake synchronously, so an
527
+ // unconsumed claim here belongs to an aborted handshake and must not block the slot.
528
+ registry.release(claim);
529
+ }
754
530
  });
755
531
  return {
756
532
  listen(port, host) {
@@ -768,7 +544,8 @@ export function createDashboardGateway(options) {
768
544
  },
769
545
  close() {
770
546
  return new Promise((resolve, reject) => {
771
- agent?.websocket.terminate();
547
+ for (const connection of registry.shutdown())
548
+ connection.socket.terminate();
772
549
  if (!server.listening) {
773
550
  resolve();
774
551
  return;