clinkx 1.1.2 → 1.3.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 (309) hide show
  1. package/CHANGELOG.md +63 -0
  2. package/README.md +67 -14
  3. package/clinkx-workflows/dist/allowed-roots.js +2 -0
  4. package/clinkx-workflows/dist/allowed-roots.js.map +1 -1
  5. package/clinkx-workflows/dist/architecture-arena/admission.d.ts +16 -0
  6. package/clinkx-workflows/dist/architecture-arena/admission.js +107 -0
  7. package/clinkx-workflows/dist/architecture-arena/admission.js.map +1 -0
  8. package/clinkx-workflows/dist/architecture-arena/contract.d.ts +1368 -0
  9. package/clinkx-workflows/dist/architecture-arena/contract.js +254 -0
  10. package/clinkx-workflows/dist/architecture-arena/contract.js.map +1 -0
  11. package/clinkx-workflows/dist/architecture-arena/runtime.d.ts +53 -0
  12. package/clinkx-workflows/dist/architecture-arena/runtime.js +511 -0
  13. package/clinkx-workflows/dist/architecture-arena/runtime.js.map +1 -0
  14. package/clinkx-workflows/dist/architecture-comparison/admission.d.ts +17 -1
  15. package/clinkx-workflows/dist/architecture-comparison/admission.js +27 -4
  16. package/clinkx-workflows/dist/architecture-comparison/admission.js.map +1 -1
  17. package/clinkx-workflows/dist/architecture-comparison/contract.d.ts +59 -62
  18. package/clinkx-workflows/dist/architecture-comparison/contract.js +4 -21
  19. package/clinkx-workflows/dist/architecture-comparison/contract.js.map +1 -1
  20. package/clinkx-workflows/dist/architecture-comparison/runtime.d.ts +4 -3
  21. package/clinkx-workflows/dist/architecture-comparison/runtime.js +22 -67
  22. package/clinkx-workflows/dist/architecture-comparison/runtime.js.map +1 -1
  23. package/clinkx-workflows/dist/artifacts.d.ts +19 -4
  24. package/clinkx-workflows/dist/artifacts.js +16 -7
  25. package/clinkx-workflows/dist/artifacts.js.map +1 -1
  26. package/clinkx-workflows/dist/backend.d.ts +30 -0
  27. package/clinkx-workflows/dist/child-env.d.ts +3 -1
  28. package/clinkx-workflows/dist/child-env.js +6 -2
  29. package/clinkx-workflows/dist/child-env.js.map +1 -1
  30. package/clinkx-workflows/dist/clink-client.d.ts +8 -2
  31. package/clinkx-workflows/dist/clink-client.js +4 -2
  32. package/clinkx-workflows/dist/clink-client.js.map +1 -1
  33. package/clinkx-workflows/dist/config.d.ts +28 -5
  34. package/clinkx-workflows/dist/config.js +137 -20
  35. package/clinkx-workflows/dist/config.js.map +1 -1
  36. package/clinkx-workflows/dist/contained-file.js +9 -0
  37. package/clinkx-workflows/dist/contained-file.js.map +1 -1
  38. package/clinkx-workflows/dist/context-preflight.d.ts +6 -0
  39. package/clinkx-workflows/dist/context-preflight.js.map +1 -1
  40. package/clinkx-workflows/dist/council-execution-policy.d.ts +3 -1
  41. package/clinkx-workflows/dist/council-execution-policy.js +4 -0
  42. package/clinkx-workflows/dist/council-execution-policy.js.map +1 -1
  43. package/clinkx-workflows/dist/dashboard/contracts.d.ts +586 -586
  44. package/clinkx-workflows/dist/dashboard/progress-report-contract.d.ts +28 -28
  45. package/clinkx-workflows/dist/dashboard/session-log-contract.d.ts +32 -32
  46. package/clinkx-workflows/dist/dashboard/session-log-identity.js +2 -1
  47. package/clinkx-workflows/dist/dashboard/session-log-identity.js.map +1 -1
  48. package/clinkx-workflows/dist/dashboard-ui/assets/index-DRId2DVA.js +119 -0
  49. package/clinkx-workflows/dist/dashboard-ui/assets/style-CHAw57y5.css +1 -0
  50. package/clinkx-workflows/dist/dashboard-ui/index.html +2 -2
  51. package/clinkx-workflows/dist/delegate-signature.d.ts +4 -3
  52. package/clinkx-workflows/dist/delegate-signature.js +4 -3
  53. package/clinkx-workflows/dist/delegate-signature.js.map +1 -1
  54. package/clinkx-workflows/dist/durable-file.d.ts +69 -0
  55. package/clinkx-workflows/dist/durable-file.js +145 -0
  56. package/clinkx-workflows/dist/durable-file.js.map +1 -0
  57. package/clinkx-workflows/dist/engine.d.ts +42 -7
  58. package/clinkx-workflows/dist/engine.js +196 -24
  59. package/clinkx-workflows/dist/engine.js.map +1 -1
  60. package/clinkx-workflows/dist/ping-pong/admission.d.ts +127 -0
  61. package/clinkx-workflows/dist/ping-pong/admission.js +522 -0
  62. package/clinkx-workflows/dist/ping-pong/admission.js.map +1 -0
  63. package/clinkx-workflows/dist/ping-pong/contract.d.ts +2539 -0
  64. package/clinkx-workflows/dist/ping-pong/contract.js +819 -0
  65. package/clinkx-workflows/dist/ping-pong/contract.js.map +1 -0
  66. package/clinkx-workflows/dist/ping-pong/control.d.ts +67 -0
  67. package/clinkx-workflows/dist/ping-pong/control.js +12 -0
  68. package/clinkx-workflows/dist/ping-pong/control.js.map +1 -0
  69. package/clinkx-workflows/dist/ping-pong/runtime-handle.d.ts +24 -0
  70. package/clinkx-workflows/dist/ping-pong/runtime-handle.js +55 -0
  71. package/clinkx-workflows/dist/ping-pong/runtime-handle.js.map +1 -0
  72. package/clinkx-workflows/dist/ping-pong/runtime.d.ts +235 -0
  73. package/clinkx-workflows/dist/ping-pong/runtime.js +1183 -0
  74. package/clinkx-workflows/dist/ping-pong/runtime.js.map +1 -0
  75. package/clinkx-workflows/dist/ping-pong/settle.d.ts +57 -0
  76. package/clinkx-workflows/dist/ping-pong/settle.js +58 -0
  77. package/clinkx-workflows/dist/ping-pong/settle.js.map +1 -0
  78. package/clinkx-workflows/dist/ping-pong/sidecar.d.ts +65 -0
  79. package/clinkx-workflows/dist/ping-pong/sidecar.js +138 -0
  80. package/clinkx-workflows/dist/ping-pong/sidecar.js.map +1 -0
  81. package/clinkx-workflows/dist/plan-review/publication.d.ts +2 -1
  82. package/clinkx-workflows/dist/plan-review/publication.js +5 -6
  83. package/clinkx-workflows/dist/plan-review/publication.js.map +1 -1
  84. package/clinkx-workflows/dist/plan-review/snapshot.d.ts +3 -2
  85. package/clinkx-workflows/dist/plan-review/snapshot.js +8 -8
  86. package/clinkx-workflows/dist/plan-review/snapshot.js.map +1 -1
  87. package/clinkx-workflows/dist/recipe-host.d.ts +315 -0
  88. package/clinkx-workflows/dist/recipe-host.js +183 -0
  89. package/clinkx-workflows/dist/recipe-host.js.map +1 -0
  90. package/clinkx-workflows/dist/recipe-seats.d.ts +96 -0
  91. package/clinkx-workflows/dist/recipe-seats.js +163 -0
  92. package/clinkx-workflows/dist/recipe-seats.js.map +1 -0
  93. package/clinkx-workflows/dist/recipe-shared/evidence.d.ts +67 -0
  94. package/clinkx-workflows/dist/recipe-shared/evidence.js +111 -0
  95. package/clinkx-workflows/dist/recipe-shared/evidence.js.map +1 -0
  96. package/clinkx-workflows/dist/reducers/index.d.ts +9 -1
  97. package/clinkx-workflows/dist/reducers/index.js +30 -0
  98. package/clinkx-workflows/dist/reducers/index.js.map +1 -1
  99. package/clinkx-workflows/dist/root-path-validation.d.ts +12 -0
  100. package/clinkx-workflows/dist/root-path-validation.js +63 -0
  101. package/clinkx-workflows/dist/root-path-validation.js.map +1 -0
  102. package/clinkx-workflows/dist/rosters.d.ts +1 -0
  103. package/clinkx-workflows/dist/rosters.js +16 -6
  104. package/clinkx-workflows/dist/rosters.js.map +1 -1
  105. package/clinkx-workflows/dist/run-lock-reclaim.d.ts +44 -0
  106. package/clinkx-workflows/dist/run-lock-reclaim.js +86 -0
  107. package/clinkx-workflows/dist/run-lock-reclaim.js.map +1 -0
  108. package/clinkx-workflows/dist/server.js +5 -2
  109. package/clinkx-workflows/dist/server.js.map +1 -1
  110. package/clinkx-workflows/dist/state-schema.d.ts +24 -0
  111. package/clinkx-workflows/dist/state-schema.js +4 -1
  112. package/clinkx-workflows/dist/state-schema.js.map +1 -1
  113. package/clinkx-workflows/dist/state.d.ts +185 -4
  114. package/clinkx-workflows/dist/state.js +684 -88
  115. package/clinkx-workflows/dist/state.js.map +1 -1
  116. package/clinkx-workflows/dist/transport.d.ts +2 -1
  117. package/clinkx-workflows/dist/transport.js +5 -0
  118. package/clinkx-workflows/dist/transport.js.map +1 -1
  119. package/clinkx-workflows/dist/validators/architecture-arena.d.ts +6 -0
  120. package/clinkx-workflows/dist/validators/architecture-arena.js +16 -0
  121. package/clinkx-workflows/dist/validators/architecture-arena.js.map +1 -0
  122. package/clinkx-workflows/dist/validators/index.js +4 -0
  123. package/clinkx-workflows/dist/validators/index.js.map +1 -1
  124. package/clinkx-workflows/dist/validators/ping-pong.d.ts +6 -0
  125. package/clinkx-workflows/dist/validators/ping-pong.js +10 -0
  126. package/clinkx-workflows/dist/validators/ping-pong.js.map +1 -0
  127. package/clinkx-workflows/dist/workflow-completion.d.ts +83 -0
  128. package/clinkx-workflows/dist/workflow-completion.js +250 -0
  129. package/clinkx-workflows/dist/workflow-completion.js.map +1 -0
  130. package/clinkx-workflows/dist/workflow-tools.d.ts +53 -6
  131. package/clinkx-workflows/dist/workflow-tools.js +1123 -65
  132. package/clinkx-workflows/dist/workflow-tools.js.map +1 -1
  133. package/clinkx-workflows/dist/workflow-verification-contract.d.ts +4 -4
  134. package/clinkx-workflows/templates/architecture-arena/candidate.txt +39 -0
  135. package/clinkx-workflows/templates/architecture-arena/judge.txt +34 -0
  136. package/clinkx-workflows/templates/ping-pong/implement.txt +14 -0
  137. package/clinkx-workflows/templates/ping-pong/remediate.txt +14 -0
  138. package/clinkx-workflows/templates/ping-pong/review.txt +27 -0
  139. package/clinkx-workflows/workflows/architecture-arena.yaml +127 -0
  140. package/clinkx-workflows/workflows/ping-pong.yaml +158 -0
  141. package/dist/allowed-roots.d.ts +1 -1
  142. package/dist/allowed-roots.js +124 -14
  143. package/dist/allowed-roots.js.map +1 -1
  144. package/dist/context-builder/bundle.js +4 -3
  145. package/dist/context-builder/bundle.js.map +1 -1
  146. package/dist/context-builder/config.d.ts +1 -0
  147. package/dist/context-builder/config.js +21 -9
  148. package/dist/context-builder/config.js.map +1 -1
  149. package/dist/context-builder/delegate-packet.d.ts +1 -0
  150. package/dist/context-builder/delegate-packet.js +66 -7
  151. package/dist/context-builder/delegate-packet.js.map +1 -1
  152. package/dist/context-builder/delegate-validation.d.ts +12 -3
  153. package/dist/context-builder/delegate-validation.js +23 -13
  154. package/dist/context-builder/delegate-validation.js.map +1 -1
  155. package/dist/context-builder/external-gaps.d.ts +14 -3
  156. package/dist/context-builder/external-gaps.js +124 -18
  157. package/dist/context-builder/external-gaps.js.map +1 -1
  158. package/dist/context-builder/handler.js +108 -191
  159. package/dist/context-builder/handler.js.map +1 -1
  160. package/dist/context-builder/mutation-lock.d.ts +4 -0
  161. package/dist/context-builder/mutation-lock.js +7 -1
  162. package/dist/context-builder/mutation-lock.js.map +1 -1
  163. package/dist/context-builder/review-coverage.js +27 -1
  164. package/dist/context-builder/review-coverage.js.map +1 -1
  165. package/dist/context-builder/secrets.js +1 -1
  166. package/dist/context-builder/secrets.js.map +1 -1
  167. package/dist/context-builder/storage.d.ts +10 -2
  168. package/dist/context-builder/storage.js +213 -16
  169. package/dist/context-builder/storage.js.map +1 -1
  170. package/dist/context-builder/versions.d.ts +10 -4
  171. package/dist/context-builder/versions.js +10 -4
  172. package/dist/context-builder/versions.js.map +1 -1
  173. package/dist/context-builder/workflow-runner.js +33 -24
  174. package/dist/context-builder/workflow-runner.js.map +1 -1
  175. package/dist/dashboard-cli.d.ts +8 -0
  176. package/dist/dashboard-cli.js +155 -86
  177. package/dist/dashboard-cli.js.map +1 -1
  178. package/dist/dashboard-companion/client.d.ts +10 -0
  179. package/dist/dashboard-companion/client.js +43 -1
  180. package/dist/dashboard-companion/client.js.map +1 -1
  181. package/dist/dashboard-companion/config.d.ts +19 -1
  182. package/dist/dashboard-companion/config.js +104 -3
  183. package/dist/dashboard-companion/config.js.map +1 -1
  184. package/dist/dashboard-companion/protocol.d.ts +16 -0
  185. package/dist/dashboard-companion/protocol.js +38 -1
  186. package/dist/dashboard-companion/protocol.js.map +1 -1
  187. package/dist/dashboard-companion/workstation-binding.d.ts +69 -0
  188. package/dist/dashboard-companion/workstation-binding.js +192 -0
  189. package/dist/dashboard-companion/workstation-binding.js.map +1 -0
  190. package/dist/dashboard-gateway/admin-cli.d.ts +10 -0
  191. package/dist/dashboard-gateway/admin-cli.js +266 -0
  192. package/dist/dashboard-gateway/admin-cli.js.map +1 -0
  193. package/dist/dashboard-gateway/config.d.ts +50 -0
  194. package/dist/dashboard-gateway/config.js +235 -1
  195. package/dist/dashboard-gateway/config.js.map +1 -1
  196. package/dist/dashboard-gateway/connection-registry.d.ts +100 -0
  197. package/dist/dashboard-gateway/connection-registry.js +228 -0
  198. package/dist/dashboard-gateway/connection-registry.js.map +1 -0
  199. package/dist/dashboard-gateway/control-plane/account-auth.d.ts +78 -0
  200. package/dist/dashboard-gateway/control-plane/account-auth.js +198 -0
  201. package/dist/dashboard-gateway/control-plane/account-auth.js.map +1 -0
  202. package/dist/dashboard-gateway/control-plane/billing.d.ts +264 -0
  203. package/dist/dashboard-gateway/control-plane/billing.js +787 -0
  204. package/dist/dashboard-gateway/control-plane/billing.js.map +1 -0
  205. package/dist/dashboard-gateway/control-plane/contracts.d.ts +1293 -0
  206. package/dist/dashboard-gateway/control-plane/contracts.js +280 -0
  207. package/dist/dashboard-gateway/control-plane/contracts.js.map +1 -0
  208. package/dist/dashboard-gateway/control-plane/cookies.d.ts +13 -0
  209. package/dist/dashboard-gateway/control-plane/cookies.js +46 -0
  210. package/dist/dashboard-gateway/control-plane/cookies.js.map +1 -0
  211. package/dist/dashboard-gateway/control-plane/credentials.d.ts +63 -0
  212. package/dist/dashboard-gateway/control-plane/credentials.js +66 -0
  213. package/dist/dashboard-gateway/control-plane/credentials.js.map +1 -0
  214. package/dist/dashboard-gateway/control-plane/entitlements.d.ts +118 -0
  215. package/dist/dashboard-gateway/control-plane/entitlements.js +329 -0
  216. package/dist/dashboard-gateway/control-plane/entitlements.js.map +1 -0
  217. package/dist/dashboard-gateway/control-plane/errors.d.ts +17 -0
  218. package/dist/dashboard-gateway/control-plane/errors.js +23 -0
  219. package/dist/dashboard-gateway/control-plane/errors.js.map +1 -0
  220. package/dist/dashboard-gateway/control-plane/hosts.d.ts +6 -0
  221. package/dist/dashboard-gateway/control-plane/hosts.js +16 -0
  222. package/dist/dashboard-gateway/control-plane/hosts.js.map +1 -0
  223. package/dist/dashboard-gateway/control-plane/http.d.ts +34 -0
  224. package/dist/dashboard-gateway/control-plane/http.js +331 -0
  225. package/dist/dashboard-gateway/control-plane/http.js.map +1 -0
  226. package/dist/dashboard-gateway/control-plane/schema.d.ts +9 -0
  227. package/dist/dashboard-gateway/control-plane/schema.js +247 -0
  228. package/dist/dashboard-gateway/control-plane/schema.js.map +1 -0
  229. package/dist/dashboard-gateway/control-plane/secrets.d.ts +20 -0
  230. package/dist/dashboard-gateway/control-plane/secrets.js +39 -0
  231. package/dist/dashboard-gateway/control-plane/secrets.js.map +1 -0
  232. package/dist/dashboard-gateway/control-plane/store.d.ts +579 -0
  233. package/dist/dashboard-gateway/control-plane/store.js +1115 -0
  234. package/dist/dashboard-gateway/control-plane/store.js.map +1 -0
  235. package/dist/dashboard-gateway/cookie-boundary.d.ts +60 -0
  236. package/dist/dashboard-gateway/cookie-boundary.js +205 -0
  237. package/dist/dashboard-gateway/cookie-boundary.js.map +1 -0
  238. package/dist/dashboard-gateway/index.js +271 -494
  239. package/dist/dashboard-gateway/index.js.map +1 -1
  240. package/dist/dashboard-gateway/main.js +7 -2
  241. package/dist/dashboard-gateway/main.js.map +1 -1
  242. package/dist/dashboard-gateway/routing.d.ts +43 -0
  243. package/dist/dashboard-gateway/routing.js +65 -0
  244. package/dist/dashboard-gateway/routing.js.map +1 -0
  245. package/dist/dashboard-gateway/tenant-gateway.d.ts +56 -0
  246. package/dist/dashboard-gateway/tenant-gateway.js +989 -0
  247. package/dist/dashboard-gateway/tenant-gateway.js.map +1 -0
  248. package/dist/dashboard-gateway/tenant-main.d.ts +41 -0
  249. package/dist/dashboard-gateway/tenant-main.js +303 -0
  250. package/dist/dashboard-gateway/tenant-main.js.map +1 -0
  251. package/dist/dashboard-gateway/tunnel-errors.d.ts +16 -0
  252. package/dist/dashboard-gateway/tunnel-errors.js +22 -0
  253. package/dist/dashboard-gateway/tunnel-errors.js.map +1 -0
  254. package/dist/dashboard-gateway/tunnel-http.d.ts +21 -0
  255. package/dist/dashboard-gateway/tunnel-http.js +175 -0
  256. package/dist/dashboard-gateway/tunnel-http.js.map +1 -0
  257. package/dist/handler.d.ts +6 -0
  258. package/dist/handler.js +17 -1
  259. package/dist/handler.js.map +1 -1
  260. package/dist/local-clink-backend.d.ts +2 -1
  261. package/dist/local-clink-backend.js +28 -4
  262. package/dist/local-clink-backend.js.map +1 -1
  263. package/dist/parsers/extract.d.ts +19 -1
  264. package/dist/parsers/extract.js +68 -3
  265. package/dist/parsers/extract.js.map +1 -1
  266. package/dist/pipeline.d.ts +17 -1
  267. package/dist/pipeline.js +34 -6
  268. package/dist/pipeline.js.map +1 -1
  269. package/dist/process-group.d.ts +65 -0
  270. package/dist/process-group.js +153 -0
  271. package/dist/process-group.js.map +1 -0
  272. package/dist/progress-report/schema.d.ts +23 -23
  273. package/dist/project-verification/files.js +1 -1
  274. package/dist/project-verification/files.js.map +1 -1
  275. package/dist/project-verification/process.js +23 -44
  276. package/dist/project-verification/process.js.map +1 -1
  277. package/dist/project-verification/service.js +9 -1
  278. package/dist/project-verification/service.js.map +1 -1
  279. package/dist/prompt.d.ts +7 -0
  280. package/dist/prompt.js +18 -1
  281. package/dist/prompt.js.map +1 -1
  282. package/dist/recipe-host/git-trust.d.ts +43 -0
  283. package/dist/recipe-host/git-trust.js +360 -0
  284. package/dist/recipe-host/git-trust.js.map +1 -0
  285. package/dist/recipe-host/git.d.ts +42 -0
  286. package/dist/recipe-host/git.js +207 -0
  287. package/dist/recipe-host/git.js.map +1 -0
  288. package/dist/recipe-host/native-recipe-host.d.ts +127 -0
  289. package/dist/recipe-host/native-recipe-host.js +880 -0
  290. package/dist/recipe-host/native-recipe-host.js.map +1 -0
  291. package/dist/recipe-host/seat-cwd.d.ts +16 -0
  292. package/dist/recipe-host/seat-cwd.js +170 -0
  293. package/dist/recipe-host/seat-cwd.js.map +1 -0
  294. package/dist/registry.d.ts +1 -1
  295. package/dist/registry.js +5 -1
  296. package/dist/registry.js.map +1 -1
  297. package/dist/runner.d.ts +43 -1
  298. package/dist/runner.js +234 -35
  299. package/dist/runner.js.map +1 -1
  300. package/dist/server.js +21 -6
  301. package/dist/server.js.map +1 -1
  302. package/docs/configuration.md +181 -15
  303. package/docs/engineering-recipes.md +291 -0
  304. package/docs/security.md +87 -0
  305. package/docs/verification/project-checks.md +24 -2
  306. package/package.json +5 -1
  307. package/scripts/provider-doctor-core.mjs +21 -5
  308. package/clinkx-workflows/dist/dashboard-ui/assets/index-BdpmbPps.js +0 -115
  309. package/clinkx-workflows/dist/dashboard-ui/assets/style-Im5i1iAs.css +0 -1
@@ -0,0 +1,83 @@
1
+ export declare const WORKFLOW_WAIT_BUDGET_MS = 30000;
2
+ export declare const SETTLED_LIMIT = 128;
3
+ export type IdentityFailure = "identity_changed" | "identity_unavailable";
4
+ export interface PublicationIdentity {
5
+ readonly generation: string;
6
+ readonly fingerprint: string;
7
+ readonly terminal: boolean;
8
+ }
9
+ /** Read-only view; every transition goes through WorkflowCompletionRegistry. */
10
+ export interface WorkflowCompletion {
11
+ readonly executionId: string;
12
+ readonly runId: string;
13
+ readonly runDir: string;
14
+ readonly settled: boolean;
15
+ /** state.json carries executionId; set once the owner's stamp write lands. */
16
+ readonly stamped: boolean;
17
+ readonly observers: number;
18
+ readonly listenerCount: number;
19
+ }
20
+ /** One run owner's lazy binding to the store it created or resumed. */
21
+ export interface CompletionOwner {
22
+ readonly entry: WorkflowCompletion | undefined;
23
+ /** Idempotent for the same store; a different store is a programming error. */
24
+ bind(store: {
25
+ readonly sessionLogGeneration: string | undefined;
26
+ }): WorkflowCompletion;
27
+ }
28
+ /**
29
+ * Provenance only: result bodies and unfinished promise callbacks are never cached.
30
+ * An execution exists here only once its owner has bound a created/resumed
31
+ * store, so a request rejected during admission can never displace one.
32
+ */
33
+ export declare class WorkflowCompletionRegistry {
34
+ private readonly latest;
35
+ private readonly byId;
36
+ private readonly minted;
37
+ private readonly settledIds;
38
+ bind(runId: string, runDir: string, generation: string | undefined): WorkflowCompletion;
39
+ owner(runId: string, runDir: string): CompletionOwner;
40
+ /**
41
+ * A pin yields `identity_unavailable` only when this registry retains no
42
+ * record for it (bound by another process, or evicted); callers may then
43
+ * consult the identity persisted in state.json.
44
+ */
45
+ select(runDir: string): WorkflowCompletion | undefined;
46
+ select(runDir: string, expected?: string): WorkflowCompletion | IdentityFailure | undefined;
47
+ /**
48
+ * Capture the terminal publication while ownership still prevents local
49
+ * re-admission. Only a terminal state of the bound directory incarnation counts.
50
+ */
51
+ recordPublication(entry: WorkflowCompletion): Promise<void>;
52
+ markStamped(entry: WorkflowCompletion): void;
53
+ settle(entry: WorkflowCompletion): void;
54
+ /** Protect provenance through the handler's final filesystem rereads. */
55
+ retain(entry: WorkflowCompletion): () => void;
56
+ /**
57
+ * Execution fence around a projection. `observedDigest` is the fingerprint of
58
+ * the state bytes the projection actually parsed (null: unreadable); pass it
59
+ * only when the entry was already settled before that projection began.
60
+ * Without it, only provenance and directory incarnation are checked, which
61
+ * is correct for an active execution that legitimately republishes state.
62
+ */
63
+ check(entry: WorkflowCompletion, observedDigest?: string | null): Promise<IdentityFailure | undefined>;
64
+ wait(entry: WorkflowCompletion, signal: AbortSignal): Promise<"settled" | "budget_elapsed">;
65
+ private selectionFailure;
66
+ private own;
67
+ private prune;
68
+ }
69
+ /**
70
+ * Persisted provenance for a pin this process retains no record for. Only a
71
+ * terminal state stamped with exactly that id, whose run.lock is released
72
+ * (`stale_or_absent`), counts as its settlement: a live or unknown lock means
73
+ * an owner may still be inside its cleanup fence, and a non-terminal match has
74
+ * no local owner whose fence could be witnessed.
75
+ */
76
+ export declare function persistedIdentityFailure(state: {
77
+ readonly runId?: unknown;
78
+ readonly status?: unknown;
79
+ readonly executionId?: unknown;
80
+ readonly completedAt?: unknown;
81
+ readonly executionCompletedAt?: unknown;
82
+ }, lock: "held" | "stale_or_absent" | "unknown", runId: string, expected: string): IdentityFailure | undefined;
83
+ export declare function inspectPublication(runDir: string): Promise<PublicationIdentity | undefined>;
@@ -0,0 +1,250 @@
1
+ import { createHash, randomUUID } from "node:crypto";
2
+ import { resolve } from "node:path";
3
+ import { readContainedRelativeFile } from "./contained-file.js";
4
+ import { DEFAULT_DASHBOARD_MAX_STATE_BYTES } from "./config.js";
5
+ import { readSessionLogGeneration } from "./dashboard/session-log-identity.js";
6
+ import { WorkflowCancellationError } from "./errors.js";
7
+ import { logger } from "./logger.js";
8
+ export const WORKFLOW_WAIT_BUDGET_MS = 30_000;
9
+ export const SETTLED_LIMIT = 128;
10
+ /** sha256 over the exact bytes read from state.json (never a decoded string). */
11
+ function fingerprintStateBytes(bytes) {
12
+ return createHash("sha256").update(bytes).digest("hex");
13
+ }
14
+ /**
15
+ * Provenance only: result bodies and unfinished promise callbacks are never cached.
16
+ * An execution exists here only once its owner has bound a created/resumed
17
+ * store, so a request rejected during admission can never displace one.
18
+ */
19
+ export class WorkflowCompletionRegistry {
20
+ latest = new Map();
21
+ byId = new Map();
22
+ minted = new WeakSet();
23
+ settledIds = [];
24
+ bind(runId, runDir, generation) {
25
+ const listeners = new Set();
26
+ const record = {
27
+ executionId: randomUUID(),
28
+ runId,
29
+ runDir: resolve(runDir),
30
+ generation,
31
+ publication: undefined,
32
+ settled: false,
33
+ stamped: false,
34
+ observers: 0,
35
+ listeners,
36
+ get listenerCount() { return listeners.size; },
37
+ };
38
+ this.minted.add(record);
39
+ this.byId.set(record.executionId, record);
40
+ this.latest.set(record.runDir, record);
41
+ return record;
42
+ }
43
+ owner(runId, runDir) {
44
+ let entry;
45
+ let boundStore;
46
+ return {
47
+ get entry() { return entry; },
48
+ bind: (store) => {
49
+ if (entry !== undefined) {
50
+ if (boundStore !== store)
51
+ throw new Error(`workflow run ${runId} is already bound to a different state store`);
52
+ return entry;
53
+ }
54
+ entry = this.bind(runId, runDir, store.sessionLogGeneration);
55
+ boundStore = store;
56
+ return entry;
57
+ },
58
+ };
59
+ }
60
+ select(runDir, expected) {
61
+ const latest = this.latest.get(resolve(runDir));
62
+ if (expected === undefined)
63
+ return latest;
64
+ const entry = this.byId.get(expected);
65
+ if (entry === undefined)
66
+ return "identity_unavailable";
67
+ if (entry.runDir !== resolve(runDir) || latest !== entry)
68
+ return "identity_changed";
69
+ return entry;
70
+ }
71
+ /**
72
+ * Capture the terminal publication while ownership still prevents local
73
+ * re-admission. Only a terminal state of the bound directory incarnation counts.
74
+ */
75
+ async recordPublication(entry) {
76
+ const record = this.own(entry);
77
+ if (record.settled || record.generation === undefined)
78
+ return;
79
+ const publication = await inspectPublication(record.runDir);
80
+ if (publication?.generation === record.generation && publication.terminal) {
81
+ record.publication = publication;
82
+ }
83
+ }
84
+ markStamped(entry) {
85
+ this.own(entry).stamped = true;
86
+ }
87
+ settle(entry) {
88
+ const record = this.own(entry);
89
+ if (record.settled)
90
+ return;
91
+ record.settled = true;
92
+ this.settledIds.push(record.executionId);
93
+ this.prune();
94
+ for (const listener of [...record.listeners])
95
+ listener();
96
+ }
97
+ /** Protect provenance through the handler's final filesystem rereads. */
98
+ retain(entry) {
99
+ const record = this.own(entry);
100
+ record.observers += 1;
101
+ return () => {
102
+ record.observers -= 1;
103
+ this.prune();
104
+ };
105
+ }
106
+ /**
107
+ * Execution fence around a projection. `observedDigest` is the fingerprint of
108
+ * the state bytes the projection actually parsed (null: unreadable); pass it
109
+ * only when the entry was already settled before that projection began.
110
+ * Without it, only provenance and directory incarnation are checked, which
111
+ * is correct for an active execution that legitimately republishes state.
112
+ */
113
+ async check(entry, observedDigest) {
114
+ const record = this.own(entry);
115
+ const before = this.selectionFailure(record);
116
+ if (before !== undefined)
117
+ return before;
118
+ if (record.generation === undefined)
119
+ return "identity_unavailable";
120
+ const generation = await readSessionLogGeneration(record.runDir);
121
+ // Recheck after the I/O: a replacement may bind while the read is pending.
122
+ const after = this.selectionFailure(record);
123
+ if (after !== undefined)
124
+ return after;
125
+ if (generation.kind !== "available")
126
+ return "identity_unavailable";
127
+ if (generation.sessionLogGeneration !== record.generation)
128
+ return "identity_changed";
129
+ if (record.settled && record.publication === undefined)
130
+ return "identity_unavailable";
131
+ if (observedDigest !== undefined) {
132
+ if (record.publication === undefined || observedDigest === null)
133
+ return "identity_unavailable";
134
+ if (observedDigest !== record.publication.fingerprint)
135
+ return "identity_changed";
136
+ }
137
+ return undefined;
138
+ }
139
+ wait(entry, signal) {
140
+ const record = this.own(entry);
141
+ if (signal.aborted)
142
+ return Promise.reject(new WorkflowCancellationError());
143
+ if (record.settled)
144
+ return Promise.resolve("settled");
145
+ return new Promise((resolveWait, reject) => {
146
+ let timer;
147
+ const cleanup = () => {
148
+ if (timer !== undefined)
149
+ clearTimeout(timer);
150
+ record.listeners.delete(onComplete);
151
+ signal.removeEventListener("abort", onAbort);
152
+ };
153
+ const onComplete = () => {
154
+ cleanup();
155
+ resolveWait("settled");
156
+ };
157
+ const onAbort = () => {
158
+ cleanup();
159
+ reject(new WorkflowCancellationError());
160
+ };
161
+ record.listeners.add(onComplete);
162
+ signal.addEventListener("abort", onAbort, { once: true });
163
+ timer = setTimeout(() => {
164
+ cleanup();
165
+ resolveWait("budget_elapsed");
166
+ }, WORKFLOW_WAIT_BUDGET_MS);
167
+ // A pending observation must not keep an otherwise idle process alive.
168
+ timer.unref?.();
169
+ // Inspect after registration, so a fast completion cannot strand a waiter.
170
+ if (record.settled)
171
+ onComplete();
172
+ else if (signal.aborted)
173
+ onAbort();
174
+ });
175
+ }
176
+ selectionFailure(record) {
177
+ const selected = this.select(record.runDir, record.executionId);
178
+ if (typeof selected === "string")
179
+ return selected;
180
+ return selected === record ? undefined : "identity_unavailable";
181
+ }
182
+ own(entry) {
183
+ if (!this.minted.has(entry))
184
+ throw new Error("workflow completion was not bound by this registry");
185
+ return entry;
186
+ }
187
+ prune() {
188
+ while (this.settledIds.length > SETTLED_LIMIT) {
189
+ const index = this.settledIds.findIndex((id) => this.byId.get(id)?.observers === 0);
190
+ if (index === -1)
191
+ return;
192
+ const id = this.settledIds.splice(index, 1)[0];
193
+ const retired = this.byId.get(id);
194
+ this.byId.delete(id);
195
+ if (retired !== undefined && this.latest.get(retired.runDir) === retired) {
196
+ this.latest.delete(retired.runDir);
197
+ }
198
+ }
199
+ }
200
+ }
201
+ function isTerminalStatus(status) {
202
+ return status === "succeeded" || status === "failed" || status === "cancelled";
203
+ }
204
+ /**
205
+ * Persisted provenance for a pin this process retains no record for. Only a
206
+ * terminal state stamped with exactly that id, whose run.lock is released
207
+ * (`stale_or_absent`), counts as its settlement: a live or unknown lock means
208
+ * an owner may still be inside its cleanup fence, and a non-terminal match has
209
+ * no local owner whose fence could be witnessed.
210
+ */
211
+ export function persistedIdentityFailure(state, lock, runId, expected) {
212
+ if (typeof state.executionId !== "string" || state.runId !== runId)
213
+ return "identity_unavailable";
214
+ if (state.executionId !== expected)
215
+ return "identity_changed";
216
+ if (!isTerminalStatus(state.status) || lock !== "stale_or_absent")
217
+ return "identity_unavailable";
218
+ return typeof state.completedAt === "string" && state.executionCompletedAt === state.completedAt
219
+ ? undefined
220
+ : "identity_unavailable";
221
+ }
222
+ export async function inspectPublication(runDir) {
223
+ try {
224
+ const before = await readSessionLogGeneration(runDir);
225
+ if (before.kind !== "available")
226
+ return undefined;
227
+ const file = await readContainedRelativeFile(runDir, "state.json", {
228
+ wantBytes: true,
229
+ requireRegular: true,
230
+ requireExactRequestedPath: true,
231
+ maxBytes: DEFAULT_DASHBOARD_MAX_STATE_BYTES,
232
+ });
233
+ const state = JSON.parse(file.bytes.toString("utf-8"));
234
+ const after = await readSessionLogGeneration(runDir);
235
+ if (after.kind !== "available" || after.sessionLogGeneration !== before.sessionLogGeneration) {
236
+ return undefined;
237
+ }
238
+ return {
239
+ generation: before.sessionLogGeneration,
240
+ fingerprint: fingerprintStateBytes(file.bytes),
241
+ terminal: isTerminalStatus(state.status),
242
+ };
243
+ }
244
+ catch (error) {
245
+ // Class only: messages can carry paths or state values.
246
+ logger.debug({ errClass: error instanceof Error ? error.constructor.name : typeof error, runDir }, "workflow publication identity unavailable");
247
+ return undefined;
248
+ }
249
+ }
250
+ //# sourceMappingURL=workflow-completion.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflow-completion.js","sourceRoot":"","sources":["../src/workflow-completion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EAAE,iCAAiC,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,EAAE,wBAAwB,EAAE,MAAM,qCAAqC,CAAC;AAC/E,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,MAAM,CAAC,MAAM,uBAAuB,GAAG,MAAM,CAAC;AAC9C,MAAM,CAAC,MAAM,aAAa,GAAG,GAAG,CAAC;AAsCjC,iFAAiF;AACjF,SAAS,qBAAqB,CAAC,KAAiB;IAC9C,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC1D,CAAC;AAED;;;;GAIG;AACH,MAAM,OAAO,0BAA0B;IACpB,MAAM,GAAG,IAAI,GAAG,EAA4B,CAAC;IAC7C,IAAI,GAAG,IAAI,GAAG,EAA4B,CAAC;IAC3C,MAAM,GAAG,IAAI,OAAO,EAAsB,CAAC;IAC3C,UAAU,GAAa,EAAE,CAAC;IAE3C,IAAI,CAAC,KAAa,EAAE,MAAc,EAAE,UAA8B;QAChE,MAAM,SAAS,GAAG,IAAI,GAAG,EAAc,CAAC;QACxC,MAAM,MAAM,GAAqB;YAC/B,WAAW,EAAE,UAAU,EAAE;YACzB,KAAK;YACL,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC;YACvB,UAAU;YACV,WAAW,EAAE,SAAS;YACtB,OAAO,EAAE,KAAK;YACd,OA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C;SAC5C,CAAC,CAAC;QACH,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAyB,CAAC;QAChF,MAAM,KAAK,GAAG,MAAM,wBAAwB,CAAC,MAAM,CAAC,CAAC;QACrD,IAAI,KAAK,CAAC,IAAI,KAAK,WAAW,IAAI,KAAK,CAAC,oBAAoB,KAAK,MAAM,CAAC,oBAAoB,EAAE,CAAC;YAC7F,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,OAAO;YACL,UAAU,EAAE,MAAM,CAAC,oBAAoB;YACvC,WAAW,EAAE,qBAAqB,CAAC,IAAI,CAAC,KAAM,CAAC;YAC/C,QAAQ,EAAE,gBAAgB,CAAC,KAAK,CAAC,MAAM,CAAC;SACzC,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,wDAAwD;QACxD,MAAM,CAAC,KAAK,CACV,EAAE,QAAQ,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,KAAK,EAAE,MAAM,EAAE,EACpF,2CAA2C,CAC5C,CAAC;QACF,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC"}
@@ -5,11 +5,12 @@
5
5
  * - Standalone STDIO server (ClinkSession child process backend)
6
6
  * - In-process integration (LocalClinkBackend via root ClinkX)
7
7
  *
8
- * The `registerWorkflowTools()` function registers five tools on a Server:
8
+ * The `registerWorkflowTools()` function registers six tools on a Server:
9
9
  * - run_workflow: start a new workflow execution
10
10
  * - resume_workflow: resume a failed/cancelled run
11
11
  * - list_workflows: list available workflow definitions
12
12
  * - workflow_run_status: read workflow run progress/result
13
+ * - workflow_run_wait: observe local execution settlement
13
14
  * - cancel_workflow: cancel a live or orphaned workflow run
14
15
  *
15
16
  * The caller provides a `createBackend` factory that determines how clink
@@ -18,18 +19,39 @@
18
19
  import type { Server } from "@modelcontextprotocol/sdk/server/index.js";
19
20
  import type { ClinkBackend } from "./backend.js";
20
21
  import type { NormalizedWorkflowDefinition } from "./definition-normalizer.js";
22
+ import { WorkflowStateStore } from "./state.js";
21
23
  import type { RunState } from "./state-schema.js";
22
24
  import type { InvocationAuditWrite } from "./dashboard/invocation-contract.js";
23
25
  import type { ContextBuilderRunner, WorkflowContext } from "./context-preflight.js";
24
26
  import type { WorkflowContextBuilderLifecycleRouter } from "./context-builder-lifecycle-router.js";
27
+ import type { FileWriter } from "./durable-file.js";
25
28
  import type { Variable } from "./schema.js";
29
+ import { type RecipeSeatPlan } from "./recipe-seats.js";
26
30
  import { type WorkflowContextRequestedMode, type WorkflowContextPolicy } from "./context-mode-resolver.js";
27
31
  import { type AvailableCliCapability, type ResolvedRoster } from "./roster-contract.js";
28
32
  import type { RosterLoader } from "./rosters.js";
29
33
  import type { VerifiedRepairHost } from "./verified-repair/host.js";
34
+ import type { RecipeHost } from "./recipe-host.js";
35
+ import type { PingPongRuntimeHandle } from "./ping-pong/control.js";
30
36
  export interface WorkflowToolsOptions {
37
+ /**
38
+ * Test seam for run-state, snapshot, artifact and sidecar writes. Production
39
+ * composition never sets it, so every write is fsync-durable; there is
40
+ * deliberately no environment switch.
41
+ */
42
+ readonly fileWriter?: FileWriter | undefined;
31
43
  /** Root-owned contract capture, scoped edits, and native verification. */
32
44
  readonly verifiedRepairHost?: VerifiedRepairHost | undefined;
45
+ /**
46
+ * Root-owned recipe worktrees (1-8..1-10). Standalone servers omit it, and
47
+ * worktree recipes are rejected via `assertRecipeHostAvailable`.
48
+ */
49
+ readonly recipeHost?: RecipeHost | undefined;
50
+ /**
51
+ * Ping-pong data plane (Phase 3b). Absent: `workflow_recipe_decide` fails
52
+ * closed (-32602) before admission or any write.
53
+ */
54
+ readonly pingPongRuntime?: PingPongRuntimeHandle | undefined;
33
55
  /**
34
56
  * Factory that creates a ClinkBackend for a given run.
35
57
  * For standalone server: `(runId) => new ClinkSession({ runId })`
@@ -114,13 +136,32 @@ export declare function getActiveWorkflowRunCount(): number;
114
136
  */
115
137
  export declare function setWorkflowActivityObserver(observer: (() => void) | undefined): void;
116
138
  export declare function resolveWorkflowAsyncAdmissionCap(options?: Pick<WorkflowToolsOptions, "asyncAdmissionCap">): number;
139
+ /**
140
+ * Owner-side settlement of a recipe execution whose runtime returned or threw
141
+ * with `state.json` still active: an aborted execution ends `cancelled`
142
+ * whether the runtime threw or returned normally; anything else ends
143
+ * `failed`. `mark*` applies D1 in one critical section: a terminal sidecar
144
+ * this execution already committed decides the status (so a cancel that lost
145
+ * the race to `qualified` settles `succeeded`), and a non-terminal one is
146
+ * terminalized before the state. If that sidecar record fails, state stays
147
+ * active and the orphaned run is recovered later.
148
+ */
149
+ export declare function settleRecipeExecution(store: WorkflowStateStore, signal: AbortSignal, failure: unknown): Promise<void>;
117
150
  interface ParsedMember {
118
151
  cli_name: string;
119
152
  stance?: string;
120
153
  model?: string;
121
154
  effort?: string;
122
155
  }
123
- export declare function parseMembersOverride(raw: unknown, knownCliNames?: ReadonlySet<string>): ParsedMember[] | undefined;
156
+ export declare function parseMembersOverride(raw: unknown, knownCliNames?: ReadonlySet<string>, options?: {
157
+ /**
158
+ * Council templates carry stance bullets only for seats _a/_b/_c, so
159
+ * councils require an explicit stance from index 3 (the default). Recipe
160
+ * workflows pass `null`: their runtimes own seat prompts and stance stays
161
+ * optional at every index.
162
+ */
163
+ readonly stanceRequiredFromIndex?: number | null;
164
+ }): ParsedMember[] | undefined;
124
165
  export declare function parseChairmanOverride(raw: unknown, knownCliNames?: ReadonlySet<string>): string | undefined;
125
166
  /** @internal Shared with the compiled producer-fixture admission check. */
126
167
  export declare function validateVariables(supplied: Record<string, unknown> | undefined, schema: Record<string, Variable>): Record<string, unknown>;
@@ -147,12 +188,17 @@ export interface BuildResolvedRosterInput {
147
188
  readonly rosterName?: string | undefined;
148
189
  }
149
190
  /**
150
- * Requested-value roster projection for council workflows. Call AFTER
191
+ * D-R4 seat plan for a recipe workflow from the parsed seat parameters and
192
+ * the workflow's optional default chairman call. Pure; throws `-32602`.
193
+ */
194
+ export declare function recipeSeatPlanForAdmission(workflow: string, definition: NormalizedWorkflowDefinition, parsedMembers: BuildResolvedRosterInput["parsedMembers"], parsedChairman: string | undefined, parsedChairmanModel: string | undefined, parsedChairmanEffort: string | undefined): RecipeSeatPlan;
195
+ /**
196
+ * Requested-value roster projection for council and recipe workflows. Call AFTER
151
197
  * `expandCouncilComposition` / `expandRunWorkflowDefinition`, AFTER
152
198
  * `resolveEffectiveChairmanCall` values are on the definition (or passed as
153
199
  * parsed chairman knobs), and AFTER `effectiveFinalizerEnabled` can be
154
200
  * evaluated from `initialContextPolicy` — and BEFORE `WorkflowStateStore.create()`.
155
- * `plan-review-receipts` and any non-council workflow return undefined.
201
+ * `plan-review-receipts` and any other workflow return undefined.
156
202
  */
157
203
  export declare function buildResolvedRoster(input: BuildResolvedRosterInput): ResolvedRoster | undefined;
158
204
  /**
@@ -194,8 +240,9 @@ export declare function handleWorkflowToolCall(server: Server, options: Workflow
194
240
  * Register workflow tools on an MCP Server instance.
195
241
  *
196
242
  * This is the reusable core extracted from createWorkflowServer().
197
- * It registers five tools: run_workflow, resume_workflow, list_workflows,
198
- * workflow_run_status, cancel_workflow.
243
+ * It registers seven tools: run_workflow, resume_workflow, list_workflows,
244
+ * workflow_run_status, workflow_run_wait, cancel_workflow,
245
+ * workflow_recipe_decide.
199
246
  *
200
247
  * The `options.createBackend` factory determines how clink calls are
201
248
  * dispatched — callers provide either a child-process or in-process backend.