clinkx 1.2.0 → 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 (270) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/README.md +4 -2
  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/clink-client.d.ts +8 -2
  26. package/clinkx-workflows/dist/clink-client.js +4 -2
  27. package/clinkx-workflows/dist/clink-client.js.map +1 -1
  28. package/clinkx-workflows/dist/context-preflight.d.ts +6 -0
  29. package/clinkx-workflows/dist/context-preflight.js.map +1 -1
  30. package/clinkx-workflows/dist/council-execution-policy.d.ts +3 -1
  31. package/clinkx-workflows/dist/council-execution-policy.js +4 -0
  32. package/clinkx-workflows/dist/council-execution-policy.js.map +1 -1
  33. package/clinkx-workflows/dist/dashboard/contracts.d.ts +586 -586
  34. package/clinkx-workflows/dist/dashboard/progress-report-contract.d.ts +28 -28
  35. package/clinkx-workflows/dist/dashboard/session-log-contract.d.ts +32 -32
  36. package/clinkx-workflows/dist/dashboard-ui/assets/index-DRId2DVA.js +119 -0
  37. package/clinkx-workflows/dist/dashboard-ui/assets/style-CHAw57y5.css +1 -0
  38. package/clinkx-workflows/dist/dashboard-ui/index.html +2 -2
  39. package/clinkx-workflows/dist/delegate-signature.d.ts +4 -3
  40. package/clinkx-workflows/dist/delegate-signature.js +4 -3
  41. package/clinkx-workflows/dist/delegate-signature.js.map +1 -1
  42. package/clinkx-workflows/dist/durable-file.d.ts +69 -0
  43. package/clinkx-workflows/dist/durable-file.js +145 -0
  44. package/clinkx-workflows/dist/durable-file.js.map +1 -0
  45. package/clinkx-workflows/dist/engine.d.ts +42 -7
  46. package/clinkx-workflows/dist/engine.js +196 -24
  47. package/clinkx-workflows/dist/engine.js.map +1 -1
  48. package/clinkx-workflows/dist/ping-pong/admission.d.ts +127 -0
  49. package/clinkx-workflows/dist/ping-pong/admission.js +522 -0
  50. package/clinkx-workflows/dist/ping-pong/admission.js.map +1 -0
  51. package/clinkx-workflows/dist/ping-pong/contract.d.ts +2539 -0
  52. package/clinkx-workflows/dist/ping-pong/contract.js +819 -0
  53. package/clinkx-workflows/dist/ping-pong/contract.js.map +1 -0
  54. package/clinkx-workflows/dist/ping-pong/control.d.ts +67 -0
  55. package/clinkx-workflows/dist/ping-pong/control.js +12 -0
  56. package/clinkx-workflows/dist/ping-pong/control.js.map +1 -0
  57. package/clinkx-workflows/dist/ping-pong/runtime-handle.d.ts +24 -0
  58. package/clinkx-workflows/dist/ping-pong/runtime-handle.js +55 -0
  59. package/clinkx-workflows/dist/ping-pong/runtime-handle.js.map +1 -0
  60. package/clinkx-workflows/dist/ping-pong/runtime.d.ts +235 -0
  61. package/clinkx-workflows/dist/ping-pong/runtime.js +1183 -0
  62. package/clinkx-workflows/dist/ping-pong/runtime.js.map +1 -0
  63. package/clinkx-workflows/dist/ping-pong/settle.d.ts +57 -0
  64. package/clinkx-workflows/dist/ping-pong/settle.js +58 -0
  65. package/clinkx-workflows/dist/ping-pong/settle.js.map +1 -0
  66. package/clinkx-workflows/dist/ping-pong/sidecar.d.ts +65 -0
  67. package/clinkx-workflows/dist/ping-pong/sidecar.js +138 -0
  68. package/clinkx-workflows/dist/ping-pong/sidecar.js.map +1 -0
  69. package/clinkx-workflows/dist/plan-review/publication.d.ts +2 -1
  70. package/clinkx-workflows/dist/plan-review/publication.js +5 -6
  71. package/clinkx-workflows/dist/plan-review/publication.js.map +1 -1
  72. package/clinkx-workflows/dist/plan-review/snapshot.d.ts +3 -2
  73. package/clinkx-workflows/dist/plan-review/snapshot.js +8 -8
  74. package/clinkx-workflows/dist/plan-review/snapshot.js.map +1 -1
  75. package/clinkx-workflows/dist/recipe-host.d.ts +315 -0
  76. package/clinkx-workflows/dist/recipe-host.js +183 -0
  77. package/clinkx-workflows/dist/recipe-host.js.map +1 -0
  78. package/clinkx-workflows/dist/recipe-seats.d.ts +96 -0
  79. package/clinkx-workflows/dist/recipe-seats.js +163 -0
  80. package/clinkx-workflows/dist/recipe-seats.js.map +1 -0
  81. package/clinkx-workflows/dist/recipe-shared/evidence.d.ts +67 -0
  82. package/clinkx-workflows/dist/recipe-shared/evidence.js +111 -0
  83. package/clinkx-workflows/dist/recipe-shared/evidence.js.map +1 -0
  84. package/clinkx-workflows/dist/reducers/index.d.ts +9 -1
  85. package/clinkx-workflows/dist/reducers/index.js +30 -0
  86. package/clinkx-workflows/dist/reducers/index.js.map +1 -1
  87. package/clinkx-workflows/dist/run-lock-reclaim.d.ts +44 -0
  88. package/clinkx-workflows/dist/run-lock-reclaim.js +86 -0
  89. package/clinkx-workflows/dist/run-lock-reclaim.js.map +1 -0
  90. package/clinkx-workflows/dist/state-schema.d.ts +11 -0
  91. package/clinkx-workflows/dist/state-schema.js +4 -1
  92. package/clinkx-workflows/dist/state-schema.js.map +1 -1
  93. package/clinkx-workflows/dist/state.d.ts +178 -3
  94. package/clinkx-workflows/dist/state.js +618 -83
  95. package/clinkx-workflows/dist/state.js.map +1 -1
  96. package/clinkx-workflows/dist/transport.d.ts +2 -1
  97. package/clinkx-workflows/dist/transport.js +5 -0
  98. package/clinkx-workflows/dist/transport.js.map +1 -1
  99. package/clinkx-workflows/dist/validators/architecture-arena.d.ts +6 -0
  100. package/clinkx-workflows/dist/validators/architecture-arena.js +16 -0
  101. package/clinkx-workflows/dist/validators/architecture-arena.js.map +1 -0
  102. package/clinkx-workflows/dist/validators/index.js +4 -0
  103. package/clinkx-workflows/dist/validators/index.js.map +1 -1
  104. package/clinkx-workflows/dist/validators/ping-pong.d.ts +6 -0
  105. package/clinkx-workflows/dist/validators/ping-pong.js +10 -0
  106. package/clinkx-workflows/dist/validators/ping-pong.js.map +1 -0
  107. package/clinkx-workflows/dist/workflow-tools.d.ts +51 -5
  108. package/clinkx-workflows/dist/workflow-tools.js +785 -34
  109. package/clinkx-workflows/dist/workflow-tools.js.map +1 -1
  110. package/clinkx-workflows/dist/workflow-verification-contract.d.ts +4 -4
  111. package/clinkx-workflows/templates/architecture-arena/candidate.txt +39 -0
  112. package/clinkx-workflows/templates/architecture-arena/judge.txt +34 -0
  113. package/clinkx-workflows/templates/ping-pong/implement.txt +14 -0
  114. package/clinkx-workflows/templates/ping-pong/remediate.txt +14 -0
  115. package/clinkx-workflows/templates/ping-pong/review.txt +27 -0
  116. package/clinkx-workflows/workflows/architecture-arena.yaml +127 -0
  117. package/clinkx-workflows/workflows/ping-pong.yaml +158 -0
  118. package/dist/context-builder/bundle.js +4 -3
  119. package/dist/context-builder/bundle.js.map +1 -1
  120. package/dist/context-builder/delegate-packet.d.ts +1 -0
  121. package/dist/context-builder/delegate-packet.js +66 -7
  122. package/dist/context-builder/delegate-packet.js.map +1 -1
  123. package/dist/context-builder/delegate-validation.d.ts +12 -3
  124. package/dist/context-builder/delegate-validation.js +23 -13
  125. package/dist/context-builder/delegate-validation.js.map +1 -1
  126. package/dist/context-builder/external-gaps.d.ts +14 -3
  127. package/dist/context-builder/external-gaps.js +124 -18
  128. package/dist/context-builder/external-gaps.js.map +1 -1
  129. package/dist/context-builder/handler.js +108 -191
  130. package/dist/context-builder/handler.js.map +1 -1
  131. package/dist/context-builder/review-coverage.js +27 -1
  132. package/dist/context-builder/review-coverage.js.map +1 -1
  133. package/dist/context-builder/secrets.js +1 -1
  134. package/dist/context-builder/secrets.js.map +1 -1
  135. package/dist/context-builder/versions.d.ts +10 -4
  136. package/dist/context-builder/versions.js +10 -4
  137. package/dist/context-builder/versions.js.map +1 -1
  138. package/dist/context-builder/workflow-runner.js +33 -24
  139. package/dist/context-builder/workflow-runner.js.map +1 -1
  140. package/dist/dashboard-cli.d.ts +2 -0
  141. package/dist/dashboard-cli.js +147 -57
  142. package/dist/dashboard-cli.js.map +1 -1
  143. package/dist/dashboard-companion/client.d.ts +10 -0
  144. package/dist/dashboard-companion/client.js +43 -1
  145. package/dist/dashboard-companion/client.js.map +1 -1
  146. package/dist/dashboard-companion/config.d.ts +19 -1
  147. package/dist/dashboard-companion/config.js +104 -3
  148. package/dist/dashboard-companion/config.js.map +1 -1
  149. package/dist/dashboard-companion/protocol.d.ts +16 -0
  150. package/dist/dashboard-companion/protocol.js +38 -1
  151. package/dist/dashboard-companion/protocol.js.map +1 -1
  152. package/dist/dashboard-companion/workstation-binding.d.ts +69 -0
  153. package/dist/dashboard-companion/workstation-binding.js +192 -0
  154. package/dist/dashboard-companion/workstation-binding.js.map +1 -0
  155. package/dist/dashboard-gateway/admin-cli.d.ts +10 -0
  156. package/dist/dashboard-gateway/admin-cli.js +266 -0
  157. package/dist/dashboard-gateway/admin-cli.js.map +1 -0
  158. package/dist/dashboard-gateway/config.d.ts +50 -0
  159. package/dist/dashboard-gateway/config.js +235 -1
  160. package/dist/dashboard-gateway/config.js.map +1 -1
  161. package/dist/dashboard-gateway/connection-registry.d.ts +100 -0
  162. package/dist/dashboard-gateway/connection-registry.js +228 -0
  163. package/dist/dashboard-gateway/connection-registry.js.map +1 -0
  164. package/dist/dashboard-gateway/control-plane/account-auth.d.ts +78 -0
  165. package/dist/dashboard-gateway/control-plane/account-auth.js +198 -0
  166. package/dist/dashboard-gateway/control-plane/account-auth.js.map +1 -0
  167. package/dist/dashboard-gateway/control-plane/billing.d.ts +264 -0
  168. package/dist/dashboard-gateway/control-plane/billing.js +787 -0
  169. package/dist/dashboard-gateway/control-plane/billing.js.map +1 -0
  170. package/dist/dashboard-gateway/control-plane/contracts.d.ts +1293 -0
  171. package/dist/dashboard-gateway/control-plane/contracts.js +280 -0
  172. package/dist/dashboard-gateway/control-plane/contracts.js.map +1 -0
  173. package/dist/dashboard-gateway/control-plane/cookies.d.ts +13 -0
  174. package/dist/dashboard-gateway/control-plane/cookies.js +46 -0
  175. package/dist/dashboard-gateway/control-plane/cookies.js.map +1 -0
  176. package/dist/dashboard-gateway/control-plane/credentials.d.ts +63 -0
  177. package/dist/dashboard-gateway/control-plane/credentials.js +66 -0
  178. package/dist/dashboard-gateway/control-plane/credentials.js.map +1 -0
  179. package/dist/dashboard-gateway/control-plane/entitlements.d.ts +118 -0
  180. package/dist/dashboard-gateway/control-plane/entitlements.js +329 -0
  181. package/dist/dashboard-gateway/control-plane/entitlements.js.map +1 -0
  182. package/dist/dashboard-gateway/control-plane/errors.d.ts +17 -0
  183. package/dist/dashboard-gateway/control-plane/errors.js +23 -0
  184. package/dist/dashboard-gateway/control-plane/errors.js.map +1 -0
  185. package/dist/dashboard-gateway/control-plane/hosts.d.ts +6 -0
  186. package/dist/dashboard-gateway/control-plane/hosts.js +16 -0
  187. package/dist/dashboard-gateway/control-plane/hosts.js.map +1 -0
  188. package/dist/dashboard-gateway/control-plane/http.d.ts +34 -0
  189. package/dist/dashboard-gateway/control-plane/http.js +331 -0
  190. package/dist/dashboard-gateway/control-plane/http.js.map +1 -0
  191. package/dist/dashboard-gateway/control-plane/schema.d.ts +9 -0
  192. package/dist/dashboard-gateway/control-plane/schema.js +247 -0
  193. package/dist/dashboard-gateway/control-plane/schema.js.map +1 -0
  194. package/dist/dashboard-gateway/control-plane/secrets.d.ts +20 -0
  195. package/dist/dashboard-gateway/control-plane/secrets.js +39 -0
  196. package/dist/dashboard-gateway/control-plane/secrets.js.map +1 -0
  197. package/dist/dashboard-gateway/control-plane/store.d.ts +579 -0
  198. package/dist/dashboard-gateway/control-plane/store.js +1115 -0
  199. package/dist/dashboard-gateway/control-plane/store.js.map +1 -0
  200. package/dist/dashboard-gateway/cookie-boundary.d.ts +60 -0
  201. package/dist/dashboard-gateway/cookie-boundary.js +205 -0
  202. package/dist/dashboard-gateway/cookie-boundary.js.map +1 -0
  203. package/dist/dashboard-gateway/index.js +271 -494
  204. package/dist/dashboard-gateway/index.js.map +1 -1
  205. package/dist/dashboard-gateway/main.js +7 -2
  206. package/dist/dashboard-gateway/main.js.map +1 -1
  207. package/dist/dashboard-gateway/routing.d.ts +43 -0
  208. package/dist/dashboard-gateway/routing.js +65 -0
  209. package/dist/dashboard-gateway/routing.js.map +1 -0
  210. package/dist/dashboard-gateway/tenant-gateway.d.ts +56 -0
  211. package/dist/dashboard-gateway/tenant-gateway.js +989 -0
  212. package/dist/dashboard-gateway/tenant-gateway.js.map +1 -0
  213. package/dist/dashboard-gateway/tenant-main.d.ts +41 -0
  214. package/dist/dashboard-gateway/tenant-main.js +303 -0
  215. package/dist/dashboard-gateway/tenant-main.js.map +1 -0
  216. package/dist/dashboard-gateway/tunnel-errors.d.ts +16 -0
  217. package/dist/dashboard-gateway/tunnel-errors.js +22 -0
  218. package/dist/dashboard-gateway/tunnel-errors.js.map +1 -0
  219. package/dist/dashboard-gateway/tunnel-http.d.ts +21 -0
  220. package/dist/dashboard-gateway/tunnel-http.js +175 -0
  221. package/dist/dashboard-gateway/tunnel-http.js.map +1 -0
  222. package/dist/handler.d.ts +6 -0
  223. package/dist/handler.js +17 -1
  224. package/dist/handler.js.map +1 -1
  225. package/dist/local-clink-backend.d.ts +2 -1
  226. package/dist/local-clink-backend.js +28 -4
  227. package/dist/local-clink-backend.js.map +1 -1
  228. package/dist/parsers/extract.d.ts +19 -1
  229. package/dist/parsers/extract.js +68 -3
  230. package/dist/parsers/extract.js.map +1 -1
  231. package/dist/pipeline.d.ts +17 -1
  232. package/dist/pipeline.js +34 -6
  233. package/dist/pipeline.js.map +1 -1
  234. package/dist/process-group.d.ts +65 -0
  235. package/dist/process-group.js +153 -0
  236. package/dist/process-group.js.map +1 -0
  237. package/dist/progress-report/schema.d.ts +23 -23
  238. package/dist/project-verification/files.js +1 -1
  239. package/dist/project-verification/files.js.map +1 -1
  240. package/dist/project-verification/process.js +23 -44
  241. package/dist/project-verification/process.js.map +1 -1
  242. package/dist/project-verification/service.js +9 -1
  243. package/dist/project-verification/service.js.map +1 -1
  244. package/dist/prompt.d.ts +7 -0
  245. package/dist/prompt.js +18 -1
  246. package/dist/prompt.js.map +1 -1
  247. package/dist/recipe-host/git-trust.d.ts +43 -0
  248. package/dist/recipe-host/git-trust.js +360 -0
  249. package/dist/recipe-host/git-trust.js.map +1 -0
  250. package/dist/recipe-host/git.d.ts +42 -0
  251. package/dist/recipe-host/git.js +207 -0
  252. package/dist/recipe-host/git.js.map +1 -0
  253. package/dist/recipe-host/native-recipe-host.d.ts +127 -0
  254. package/dist/recipe-host/native-recipe-host.js +880 -0
  255. package/dist/recipe-host/native-recipe-host.js.map +1 -0
  256. package/dist/recipe-host/seat-cwd.d.ts +16 -0
  257. package/dist/recipe-host/seat-cwd.js +170 -0
  258. package/dist/recipe-host/seat-cwd.js.map +1 -0
  259. package/dist/runner.d.ts +43 -1
  260. package/dist/runner.js +234 -35
  261. package/dist/runner.js.map +1 -1
  262. package/dist/server.js +9 -1
  263. package/dist/server.js.map +1 -1
  264. package/docs/configuration.md +24 -3
  265. package/docs/engineering-recipes.md +291 -0
  266. package/docs/security.md +84 -0
  267. package/docs/verification/project-checks.md +24 -2
  268. package/package.json +5 -1
  269. package/clinkx-workflows/dist/dashboard-ui/assets/index-BdpmbPps.js +0 -115
  270. package/clinkx-workflows/dist/dashboard-ui/assets/style-Im5i1iAs.css +0 -1
@@ -0,0 +1,163 @@
1
+ /**
2
+ * Recipe seat admission (Phase 1, tasks 1-1 and 1-3; seat mapping D-R4).
3
+ *
4
+ * Recipe workflows reuse the council seat parameters (`members`, `chairman`,
5
+ * `chairman_model`, `chairman_effort`) but NOT the council expansion: a recipe
6
+ * runtime drives its own round loop and dispatches each seat itself, so the
7
+ * normalized definition is never rewritten here. Instead each recipe has one
8
+ * pure expander that maps the parsed seat inputs onto a typed seat plan.
9
+ *
10
+ * The recipe set is deliberately separate from `COUNCIL_RUNTIME_MEMBER_WORKFLOWS`:
11
+ * that set also selects council stage expansion, council execution policy,
12
+ * the ranking reducer, and the council chairman stage index, none of which
13
+ * apply to recipes.
14
+ *
15
+ * Expanders throw `McpError(InvalidParams)` so admission rejects with `-32602`
16
+ * before any run state exists.
17
+ */
18
+ import { McpError, ErrorCode } from "@modelcontextprotocol/sdk/types.js";
19
+ import { resolveEffectiveChairmanCall } from "./chairman-knobs.js";
20
+ import { COUNCIL_RUNTIME_MEMBER_WORKFLOWS } from "./council-expander.js";
21
+ import { WorkflowError } from "./errors.js";
22
+ export const ARCHITECTURE_ARENA_WORKFLOW = "architecture-arena";
23
+ export const PING_PONG_WORKFLOW = "ping-pong";
24
+ export const RECIPE_SEAT_RULES = {
25
+ [ARCHITECTURE_ARENA_WORKFLOW]: { membersMin: 2, membersMax: 4, chairman: "required", asyncOnly: false },
26
+ // CONTRACTS 0-4: one implementer plus k = 1..4 reviewers. Async-only because
27
+ // it pauses for workflow_recipe_decide after every review round.
28
+ [PING_PONG_WORKFLOW]: { membersMin: 2, membersMax: 5, chairman: "rejected", asyncOnly: true },
29
+ };
30
+ export const RECIPE_SEAT_WORKFLOWS = new Set(Object.keys(RECIPE_SEAT_RULES));
31
+ export function isRecipeSeatWorkflow(workflowName) {
32
+ return RECIPE_SEAT_WORKFLOWS.has(workflowName);
33
+ }
34
+ export function isAsyncOnlyWorkflow(workflowName) {
35
+ return isRecipeSeatWorkflow(workflowName) && RECIPE_SEAT_RULES[workflowName].asyncOnly;
36
+ }
37
+ /** `members` is accepted: council runtime members or a recipe seat workflow. */
38
+ export function supportsSeatMembers(workflowName) {
39
+ return COUNCIL_RUNTIME_MEMBER_WORKFLOWS.has(workflowName) || isRecipeSeatWorkflow(workflowName);
40
+ }
41
+ /** `chairman`, `chairman_model`, and `chairman_effort` are accepted. */
42
+ export function supportsSeatChairman(workflowName) {
43
+ if (COUNCIL_RUNTIME_MEMBER_WORKFLOWS.has(workflowName))
44
+ return true;
45
+ return isRecipeSeatWorkflow(workflowName) &&
46
+ RECIPE_SEAT_RULES[workflowName].chairman === "required";
47
+ }
48
+ /**
49
+ * Call id that marks a recipe workflow's default chairman. A recipe YAML that
50
+ * wants a default judge declares exactly one call with
51
+ * this id; its cli_name/model/effort are the static pins that
52
+ * `resolveEffectiveChairmanCall` overlays, as for councils.
53
+ */
54
+ export const RECIPE_DEFAULT_CHAIRMAN_CALL_ID = "chairman";
55
+ export function findRecipeDefaultChairmanCall(definition) {
56
+ const matches = definition.stages.flatMap((stage) => stage.calls.filter((call) => call.id === RECIPE_DEFAULT_CHAIRMAN_CALL_ID));
57
+ if (matches.length > 1) {
58
+ throw new WorkflowError(`Recipe workflow "${definition.name}" declares ${matches.length} "${RECIPE_DEFAULT_CHAIRMAN_CALL_ID}" calls; at most one is allowed`);
59
+ }
60
+ return matches[0];
61
+ }
62
+ function invalid(message) {
63
+ return new McpError(ErrorCode.InvalidParams, message);
64
+ }
65
+ function toSeats(members) {
66
+ return members.map((member, index) => ({
67
+ index,
68
+ cli_name: member.cli_name,
69
+ ...(member.model !== undefined ? { model: member.model } : {}),
70
+ ...(member.effort !== undefined ? { effort: member.effort } : {}),
71
+ ...(member.stance !== undefined ? { stance: member.stance } : {}),
72
+ }));
73
+ }
74
+ function requireMembers(workflow, input, roleText) {
75
+ const { membersMin, membersMax } = RECIPE_SEAT_RULES[workflow];
76
+ const members = input.members;
77
+ if (members === undefined) {
78
+ throw invalid(`members is required for workflow "${workflow}" (${roleText})`);
79
+ }
80
+ if (members.length < membersMin || members.length > membersMax) {
81
+ throw invalid(`members for workflow "${workflow}" must have ${membersMin}-${membersMax} entries (${roleText}), got ${members.length}`);
82
+ }
83
+ return toSeats(members);
84
+ }
85
+ function rejectChairman(workflow, input, reason) {
86
+ const supplied = [
87
+ input.chairman !== undefined ? "chairman" : undefined,
88
+ input.chairmanModel !== undefined ? "chairman_model" : undefined,
89
+ input.chairmanEffort !== undefined ? "chairman_effort" : undefined,
90
+ ].filter((name) => name !== undefined);
91
+ if (supplied.length > 0) {
92
+ throw invalid(`${supplied.join(", ")} ${supplied.length === 1 ? "is" : "are"} not supported for workflow "${workflow}": ${reason}`);
93
+ }
94
+ }
95
+ /**
96
+ * Resolve the chairman seat for a recipe that needs one.
97
+ *
98
+ * Omitted `chairman`: the workflow's default chairman call is used when the
99
+ * YAML declares one (knobs overlay it as for councils). Without a default the
100
+ * request is rejected — a recipe with a judge seat cannot run without
101
+ * that seat, and silently picking a provider would hide the choice from the
102
+ * caller. `chairman_model`/`chairman_effort` alone never name a provider.
103
+ */
104
+ function requireChairman(workflow, input, seatName) {
105
+ if (input.chairman === undefined && input.defaultChairman === undefined) {
106
+ throw invalid(`chairman is required for workflow "${workflow}" (${seatName} seat); the workflow declares no default chairman`);
107
+ }
108
+ const staticCall = input.defaultChairman ?? { cli_name: input.chairman };
109
+ const effective = resolveEffectiveChairmanCall({
110
+ staticCall,
111
+ chairmanCliName: input.chairman,
112
+ chairmanModel: input.chairmanModel,
113
+ chairmanEffort: input.chairmanEffort,
114
+ });
115
+ return {
116
+ cli_name: effective.cli_name,
117
+ ...(effective.model !== undefined ? { model: effective.model } : {}),
118
+ ...(effective.effort !== undefined ? { effort: effective.effort } : {}),
119
+ source: input.chairman !== undefined ? "caller" : "workflow_default",
120
+ };
121
+ }
122
+ export function expandArchitectureArenaSeats(input) {
123
+ const authors = requireMembers(ARCHITECTURE_ARENA_WORKFLOW, input, "author seats; stance is the exploration direction");
124
+ return {
125
+ workflow: ARCHITECTURE_ARENA_WORKFLOW,
126
+ authors,
127
+ judge: requireChairman(ARCHITECTURE_ARENA_WORKFLOW, input, "judge"),
128
+ };
129
+ }
130
+ export function expandPingPongSeats(input) {
131
+ rejectChairman(PING_PONG_WORKFLOW, input, "members[0] is the implementer and members[1..] are the reviewers");
132
+ const seats = requireMembers(PING_PONG_WORKFLOW, input, "members[0] is the implementer, members[1..] are 1 or more reviewers");
133
+ // The recipe owns every seat prompt, so a stance would be silently dropped.
134
+ const withStance = seats.filter((seat) => seat.stance !== undefined).map((seat) => `members[${seat.index}].stance`);
135
+ if (withStance.length > 0) {
136
+ throw invalid(`${withStance.join(", ")} ${withStance.length === 1 ? "is" : "are"} not supported for workflow "${PING_PONG_WORKFLOW}": ` +
137
+ "the recipe owns the implementer and reviewer prompts; remove stance from every member");
138
+ }
139
+ const [implementer, ...reviewers] = seats;
140
+ return { workflow: PING_PONG_WORKFLOW, implementer: implementer, reviewers };
141
+ }
142
+ export function expandRecipeSeats(workflow, input) {
143
+ switch (workflow) {
144
+ case ARCHITECTURE_ARENA_WORKFLOW:
145
+ return expandArchitectureArenaSeats(input);
146
+ case PING_PONG_WORKFLOW:
147
+ return expandPingPongSeats(input);
148
+ }
149
+ }
150
+ /**
151
+ * Flatten a plan back to caller order: member seats by `members` index, then
152
+ * the chairman seat when the recipe has one. Used for admission validation
153
+ * and the `resolved_roster` projection.
154
+ */
155
+ export function recipeSeatPlanSeats(plan) {
156
+ switch (plan.workflow) {
157
+ case ARCHITECTURE_ARENA_WORKFLOW:
158
+ return { members: plan.authors, chairman: plan.judge };
159
+ case PING_PONG_WORKFLOW:
160
+ return { members: [plan.implementer, ...plan.reviewers] };
161
+ }
162
+ }
163
+ //# sourceMappingURL=recipe-seats.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recipe-seats.js","sourceRoot":"","sources":["../src/recipe-seats.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,EAAE,4BAA4B,EAAyB,MAAM,qBAAqB,CAAC;AAC1F,OAAO,EAAE,gCAAgC,EAA2B,MAAM,uBAAuB,CAAC;AAElG,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,MAAM,CAAC,MAAM,2BAA2B,GAAG,oBAAoB,CAAC;AAChE,MAAM,CAAC,MAAM,kBAAkB,GAAG,WAAW,CAAC;AAgB9C,MAAM,CAAC,MAAM,iBAAiB,GAA0D;IACtF,CAAC,2BAA2B,CAAC,EAAE,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,KAAK,EAAE;IACvG,6EAA6E;IAC7E,iEAAiE;IACjE,CAAC,kBAAkB,CAAC,EAAE,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,IAAI,EAAE;CAC9F,CAAC;AAEF,MAAM,CAAC,MAAM,qBAAqB,GAAoC,IAAI,GAAG,CAC3E,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAyB,CACvD,CAAC;AAEF,MAAM,UAAU,oBAAoB,CAAC,YAAoB;IACvD,OAAQ,qBAA6C,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;AAC1E,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,YAAoB;IACtD,OAAO,oBAAoB,C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ACvH,uFAAuF,CAC1F,CAAC;IACJ,CAAC;IACD,MAAM,CAAC,WAAW,EAAE,GAAG,SAAS,CAAC,GAAG,KAAK,CAAC;IAC1C,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,WAAW,EAAE,WAAY,EAAE,SAAS,EAAE,CAAC;AAChF,CAAC;AAED,MAAM,UAAU,iBAAiB,CAC/B,QAA4B,EAC5B,KAAsB;IAEtB,QAAQ,QAAQ,EAAE,CAAC;QACjB,KAAK,2BAA2B;YAC9B,OAAO,4BAA4B,CAAC,KAAK,CAAC,CAAC;QAC7C,KAAK,kBAAkB;YACrB,OAAO,mBAAmB,CAAC,KAAK,CAAC,CAAC;IACtC,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,IAAoB;IAItD,QAAQ,IAAI,CAAC,QAAQ,EAAE,CAAC;QACtB,KAAK,2BAA2B;YAC9B,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,QAAQ,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC;QACzD,KAAK,kBAAkB;YACrB,OAAO,EAAE,OAAO,EAAE,CAAC,IAAI,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;IAC9D,CAAC;AACH,CAAC"}
@@ -0,0 +1,67 @@
1
+ import { type FileWriter } from "../durable-file.js";
2
+ /** Key-sorted JSON; `undefined` encodes as `null` everywhere, including object values. */
3
+ export declare function canonicalJson(value: unknown): string;
4
+ /** sha256 hex of the canonical JSON encoding. */
5
+ export declare function digest(value: unknown): string;
6
+ /** sha256 hex of raw bytes (a string is hashed as UTF-8). */
7
+ export declare function bytesDigest(value: string | Buffer): string;
8
+ /** The exact on-disk encoding of a retained JSON artifact. */
9
+ export declare function serialized(value: unknown): string;
10
+ /** Throws `message` when the retained encoding of `value` exceeds `maximum` UTF-8 bytes. */
11
+ export declare function assertSerializedWithin(value: unknown, maximum: number, message: string): void;
12
+ /** Seals a body with the digest of everything except the seal. */
13
+ export declare function sealFrozen<T extends Record<string, unknown>>(body: T): T & {
14
+ frozen_digest: string;
15
+ };
16
+ /** True when `frozen_digest` is the digest of every other field. */
17
+ export declare function hasValidFrozenSeal(sealed: {
18
+ frozen_digest: string;
19
+ }): boolean;
20
+ export interface FrozenSource {
21
+ source_ref: string;
22
+ sha256: string;
23
+ size_bytes: number;
24
+ content: string;
25
+ }
26
+ export interface FrozenSourceFile {
27
+ path: string;
28
+ sha256: string;
29
+ }
30
+ /** `source_001`, `source_002`, ... in delivery order. */
31
+ export declare function sourceRef(index: number): string;
32
+ /** True when every frozen source body still matches its recorded digest and size. */
33
+ export declare function frozenSourcesIntact(sources: readonly FrozenSource[]): boolean;
34
+ /**
35
+ * Reads caller files once, inside the allowed roots, into an in-run packet.
36
+ * Later stages receive this copy, never the live files; `files` records the
37
+ * canonical path and digest so a resume can detect changed originals.
38
+ */
39
+ export declare function freezeSourceFiles(allowedRoots: readonly string[], paths: readonly string[], options: {
40
+ readonly maxFiles: number;
41
+ readonly maxBytesPerFile: number;
42
+ readonly label: string;
43
+ }): Promise<{
44
+ sources: FrozenSource[];
45
+ files: FrozenSourceFile[];
46
+ }>;
47
+ /** Throws `message` when a frozen original no longer has its recorded digest. */
48
+ export declare function assertFrozenSourceFilesUnchanged(allowedRoots: readonly string[], files: readonly FrozenSourceFile[], maxBytesPerFile: number, message: string): Promise<void>;
49
+ /** Regular file at exactly `relativePath` under `runDir`, no symlinks or escapes. */
50
+ export declare function readRunFileText(runDir: string, relativePath: string, maxBytes: number): Promise<string>;
51
+ /** Reads a retained JSON artifact and parses it only after its bytes match `fact.sha256`. */
52
+ export declare function readDigestBoundJson(runDir: string, fact: {
53
+ readonly path: string;
54
+ readonly sha256: string;
55
+ }, maxBytes: number, mismatchMessage: string): Promise<unknown>;
56
+ /**
57
+ * Durable, owner-only (0600) replace of files under one directory. Writes run
58
+ * in call order: a runtime may update its state file from overlapping calls,
59
+ * and the last call's bytes must be the ones left on disk.
60
+ */
61
+ export declare class EvidenceFileWriter {
62
+ private readonly directory;
63
+ private readonly fileWriter;
64
+ private chain;
65
+ constructor(directory: string, fileWriter?: FileWriter);
66
+ write(fileName: string, content: string): Promise<void>;
67
+ }
@@ -0,0 +1,111 @@
1
+ import { createHash } from "node:crypto";
2
+ import { join } from "node:path";
3
+ import { readContainedAbsoluteFile, readContainedRelativeFile } from "../contained-file.js";
4
+ import { durableFileWriter } from "../durable-file.js";
5
+ // Evidence primitives shared by recipe workflows that freeze an input packet,
6
+ // retain digest-bound artifacts in the run directory, and resume against them.
7
+ // `architecture-comparison` v1 persisted digests depend on these exact
8
+ // encodings (pinned by tests/architecture-comparison-golden.test.ts).
9
+ /** Key-sorted JSON; `undefined` encodes as `null` everywhere, including object values. */
10
+ export function canonicalJson(value) {
11
+ if (Array.isArray(value))
12
+ return `[${value.map(canonicalJson).join(",")}]`;
13
+ if (value !== null && typeof value === "object") {
14
+ const object = value;
15
+ return `{${Object.keys(object).sort().map((key) => `${JSON.stringify(key)}:${canonicalJson(object[key])}`).join(",")}}`;
16
+ }
17
+ return JSON.stringify(value) ?? "null";
18
+ }
19
+ /** sha256 hex of the canonical JSON encoding. */
20
+ export function digest(value) {
21
+ return createHash("sha256").update(canonicalJson(value)).digest("hex");
22
+ }
23
+ /** sha256 hex of raw bytes (a string is hashed as UTF-8). */
24
+ export function bytesDigest(value) {
25
+ return createHash("sha256").update(value).digest("hex");
26
+ }
27
+ /** The exact on-disk encoding of a retained JSON artifact. */
28
+ export function serialized(value) { return `${JSON.stringify(value, null, 2)}\n`; }
29
+ /** Throws `message` when the retained encoding of `value` exceeds `maximum` UTF-8 bytes. */
30
+ export function assertSerializedWithin(value, maximum, message) {
31
+ if (Buffer.byteLength(serialized(value), "utf8") > maximum)
32
+ throw new Error(message);
33
+ }
34
+ /** Seals a body with the digest of everything except the seal. */
35
+ export function sealFrozen(body) {
36
+ return { ...body, frozen_digest: digest(body) };
37
+ }
38
+ /** True when `frozen_digest` is the digest of every other field. */
39
+ export function hasValidFrozenSeal(sealed) {
40
+ const { frozen_digest, ...body } = sealed;
41
+ return digest(body) === frozen_digest;
42
+ }
43
+ /** `source_001`, `source_002`, ... in delivery order. */
44
+ export function sourceRef(index) {
45
+ return `source_${String(index + 1).padStart(3, "0")}`;
46
+ }
47
+ /** True when every frozen source body still matches its recorded digest and size. */
48
+ export function frozenSourcesIntact(sources) {
49
+ return sources.every((source) => bytesDigest(source.content) === source.sha256 && Buffer.byteLength(source.content, "utf8") === source.size_bytes);
50
+ }
51
+ /**
52
+ * Reads caller files once, inside the allowed roots, into an in-run packet.
53
+ * Later stages receive this copy, never the live files; `files` records the
54
+ * canonical path and digest so a resume can detect changed originals.
55
+ */
56
+ export async function freezeSourceFiles(allowedRoots, paths, options) {
57
+ if (paths.length > options.maxFiles)
58
+ throw new Error(`${options.label} shared input exceeds ${options.maxFiles} files`);
59
+ const sources = [];
60
+ const files = [];
61
+ for (const [index, path] of paths.entries()) {
62
+ const read = await readContainedAbsoluteFile(allowedRoots, path, { wantContent: true, wantBytes: true, requireRegular: true, maxBytes: options.maxBytesPerFile });
63
+ if (!Buffer.from(read.content, "utf8").equals(read.bytes))
64
+ throw new Error(`${options.label} source files must contain valid UTF-8`);
65
+ const sha256 = bytesDigest(read.bytes);
66
+ sources.push({ source_ref: sourceRef(index), sha256, size_bytes: read.size, content: read.content });
67
+ files.push({ path: read.realPath, sha256 });
68
+ }
69
+ return { sources, files };
70
+ }
71
+ /** Throws `message` when a frozen original no longer has its recorded digest. */
72
+ export async function assertFrozenSourceFilesUnchanged(allowedRoots, files, maxBytesPerFile, message) {
73
+ for (const source of files) {
74
+ const current = await readContainedAbsoluteFile(allowedRoots, source.path, { wantBytes: true, requireRegular: true, maxBytes: maxBytesPerFile });
75
+ if (bytesDigest(current.bytes) !== source.sha256)
76
+ throw new Error(message);
77
+ }
78
+ }
79
+ /** Regular file at exactly `relativePath` under `runDir`, no symlinks or escapes. */
80
+ export async function readRunFileText(runDir, relativePath, maxBytes) {
81
+ const read = await readContainedRelativeFile(runDir, relativePath, { wantContent: true, requireRegular: true, requireExactRequestedPath: true, maxBytes });
82
+ return read.content;
83
+ }
84
+ /** Reads a retained JSON artifact and parses it only after its bytes match `fact.sha256`. */
85
+ export async function readDigestBoundJson(runDir, fact, maxBytes, mismatchMessage) {
86
+ const content = await readRunFileText(runDir, fact.path, maxBytes);
87
+ if (bytesDigest(content) !== fact.sha256)
88
+ throw new Error(mismatchMessage);
89
+ return JSON.parse(content);
90
+ }
91
+ /**
92
+ * Durable, owner-only (0600) replace of files under one directory. Writes run
93
+ * in call order: a runtime may update its state file from overlapping calls,
94
+ * and the last call's bytes must be the ones left on disk.
95
+ */
96
+ export class EvidenceFileWriter {
97
+ directory;
98
+ fileWriter;
99
+ chain = Promise.resolve();
100
+ constructor(directory, fileWriter = durableFileWriter) {
101
+ this.directory = directory;
102
+ this.fileWriter = fileWriter;
103
+ }
104
+ write(fileName, content) {
105
+ const task = () => this.fileWriter.writeFile(join(this.directory, fileName), content, { mode: 0o600 });
106
+ const next = this.chain.then(task, task);
107
+ this.chain = next.catch(() => { });
108
+ return next;
109
+ }
110
+ }
111
+ //# sourceMappingURL=evidence.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"evidence.js","sourceRoot":"","sources":["../../src/recipe-shared/evidence.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,yBAAyB,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AAC5F,OAAO,EAAE,iBAAiB,EAAmB,MAAM,oBAAoB,CAAC;AAExE,8EAA8E;AAC9E,+EAA+E;AAC/E,uEAAuE;AACvE,sEAAsE;AAEtE,0FAA0F;AAC1F,MAAM,UAAU,aAAa,CAAC,KAAc;IAC1C,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE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MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACzC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;QAClC,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
@@ -3,13 +3,21 @@
3
3
  *
4
4
  * Reducers run in place of LLM calls when a call specifies a `reducer` ID.
5
5
  */
6
- import type { ArtifactRecord } from "../artifacts.js";
6
+ import type { ArtifactRecord, OmittedArtifactRecord } from "../artifacts.js";
7
7
  import type { ArchitectureComparisonRuntime } from "../architecture-comparison/runtime.js";
8
+ import type { ArchitectureArenaRuntime } from "../architecture-arena/runtime.js";
8
9
  import type { VerifiedRepairRuntime } from "../verified-repair/runtime.js";
10
+ import type { PingPongRuntime } from "../ping-pong/runtime.js";
9
11
  export interface ReducerContext {
10
12
  readonly variables: Readonly<Record<string, unknown>>;
11
13
  readonly architectureComparison?: ArchitectureComparisonRuntime | undefined;
14
+ readonly architectureArena?: ArchitectureArenaRuntime | undefined;
15
+ /** Failed context_from references with their persisted failure reasons. */
16
+ readonly omissions?: readonly OmittedArtifactRecord[] | undefined;
12
17
  readonly verifiedRepair?: VerifiedRepairRuntime | undefined;
18
+ readonly pingPong?: PingPongRuntime | undefined;
19
+ /** Stage id of the reducer call (ping-pong reducers derive their round from it). */
20
+ readonly stageId?: string | undefined;
13
21
  readonly signal?: AbortSignal | undefined;
14
22
  }
15
23
  export type ReducerFn = (artifacts: readonly ArtifactRecord[], context?: ReducerContext) => string | Promise<string>;
@@ -23,6 +23,21 @@ registry.set("architecture_record_v1", (artifacts, context) => {
23
23
  throw new Error("architecture record reducer requires its workflow contract");
24
24
  return context.architectureComparison.comparison(artifacts);
25
25
  });
26
+ registry.set("architecture_arena_freeze_v2", (_artifacts, context) => {
27
+ if (context?.architectureArena === undefined)
28
+ throw new Error("architecture arena freeze reducer requires its workflow contract");
29
+ return context.architectureArena.freeze(context.variables);
30
+ });
31
+ registry.set("architecture_arena_view_v2", (artifacts, context) => {
32
+ if (context?.architectureArena === undefined)
33
+ throw new Error("architecture arena judge view reducer requires its workflow contract");
34
+ return context.architectureArena.makeJudgeView(artifacts);
35
+ });
36
+ registry.set("architecture_arena_record_v2", (artifacts, context) => {
37
+ if (context?.architectureArena === undefined)
38
+ throw new Error("architecture arena record reducer requires its workflow contract");
39
+ return context.architectureArena.comparison(artifacts, context.omissions ?? []);
40
+ });
26
41
  for (const operation of ["capture", "reproduce", "fixed", "independent", "record"]) {
27
42
  registry.set(`repair_${operation}_v1`, (artifacts, context) => {
28
43
  if (context?.verifiedRepair === undefined)
@@ -30,6 +45,21 @@ for (const operation of ["capture", "reproduce", "fixed", "independent", "record
30
45
  return context.verifiedRepair.reduce(operation, artifacts, context.signal);
31
46
  });
32
47
  }
48
+ function pingPongRound(context, prefix) {
49
+ const match = new RegExp(`^${prefix}(\\d+)$`).exec(context?.stageId ?? "");
50
+ if (match === null)
51
+ throw new Error(`ping-pong reducer bound to unexpected stage ${context?.stageId ?? "(none)"}`);
52
+ return Number(match[1]);
53
+ }
54
+ function requirePingPong(context) {
55
+ if (context?.pingPong === undefined)
56
+ throw new Error("ping-pong reducer requires the root recipe runtime");
57
+ return context.pingPong;
58
+ }
59
+ registry.set("pp_verify_v1", (_artifacts, context) => requirePingPong(context).verify(pingPongRound(context, "v"), context?.signal));
60
+ registry.set("pp_gate_v1", (_artifacts, context) => requirePingPong(context).gate(pingPongRound(context, "g")));
61
+ registry.set("pp_final_verify_v1", (_artifacts, context) => requirePingPong(context).finalVerify(context?.signal));
62
+ registry.set("pp_record_v1", (_artifacts, context) => requirePingPong(context).record());
33
63
  export function getReducer(id) {
34
64
  return registry.get(id);
35
65
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/reducers/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,wBAAwB,EAAE,M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,EAAE,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;AAChH,QAAQ,CAAC,GAAG,CAAC,oBAAoB,EAAE,CAAC,UAAU,EAAE,OAAO,EAAE,EAAE,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,WAAW,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC;AACnH,QAAQ,CAAC,GAAG,CAAC,cAAc,EAAE,CAAC,UAAU,EAAE,OAAO,EAAE,EAAE,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;AAEzF,MAAM,UAAU,UAAU,CAAC,EAAU;IACnC,OAAO,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;AAC1B,CAAC"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Serializes the one destructive step of `run.lock` acquisition: deleting a
3
+ * same-host dead-PID lock. Ported from `src/progress-report/lock.ts`, which the
4
+ * workflows package cannot import.
5
+ */
6
+ export declare const RUN_LOCK_STEAL_SUFFIX = ".steal";
7
+ export declare function runLockStealPath(lockPath: string): string;
8
+ /** The fields of a `run.lock` record that identify one acquisition. */
9
+ export interface RunLockIdentity {
10
+ readonly pid: number;
11
+ readonly hostname: string;
12
+ readonly startedAt: string;
13
+ readonly token?: string;
14
+ }
15
+ export type DeadRunLockReclaimOutcome =
16
+ /** The observed lock is gone: we unlinked it, or someone already had. */
17
+ {
18
+ readonly kind: "reclaimed";
19
+ }
20
+ /** `run.lock` no longer holds the observed acquisition; nothing was deleted. */
21
+ | {
22
+ readonly kind: "superseded";
23
+ }
24
+ /** `run.lock.steal` already exists: another reclaimer is active, or it is stranded. */
25
+ | {
26
+ readonly kind: "steal_lock_busy";
27
+ readonly stealPath: string;
28
+ };
29
+ /**
30
+ * Delete a dead-PID `run.lock`, but only one reclaimer at a time, and only if
31
+ * the lock on disk is still the acquisition the caller judged dead.
32
+ *
33
+ * `O_EXCL` on `run.lock` arbitrates creation only. Without this, two
34
+ * contenders can both judge the SAME dead lock, the first unlinks, recreates
35
+ * and owns it, and the second's already-justified unlink then deletes the
36
+ * first's LIVE lock and lets the second own the run too. Holding
37
+ * `run.lock.steal` across the identity re-read and the unlink makes the
38
+ * check-and-delete indivisible with respect to other reclaimers.
39
+ *
40
+ * Residual, accepted: a process that dies while holding `run.lock.steal`
41
+ * strands it, which disables automatic dead-PID reclaim for that run until an
42
+ * operator removes the file. Normal acquisition of an absent lock is unaffected.
43
+ */
44
+ export declare function reclaimDeadRunLock(lockPath: string, observed: RunLockIdentity): Promise<DeadRunLockReclaimOutcome>;
@@ -0,0 +1,86 @@
1
+ import { open, readFile, unlink } from "node:fs/promises";
2
+ import { logger } from "./logger.js";
3
+ /**
4
+ * Serializes the one destructive step of `run.lock` acquisition: deleting a
5
+ * same-host dead-PID lock. Ported from `src/progress-report/lock.ts`, which the
6
+ * workflows package cannot import.
7
+ */
8
+ export const RUN_LOCK_STEAL_SUFFIX = ".steal";
9
+ export function runLockStealPath(lockPath) {
10
+ return `${lockPath}${RUN_LOCK_STEAL_SUFFIX}`;
11
+ }
12
+ /**
13
+ * Legacy locks predate `token`, so their identity falls back to the tuple a
14
+ * fresh acquisition can never reproduce: a new owner always writes a token.
15
+ */
16
+ function identityKey(record) {
17
+ const token = record["token"];
18
+ if (typeof token === "string" && token !== "") {
19
+ return JSON.stringify(["token", token]);
20
+ }
21
+ return JSON.stringify(["legacy", record["pid"], record["hostname"], record["startedAt"]]);
22
+ }
23
+ /**
24
+ * Delete a dead-PID `run.lock`, but only one reclaimer at a time, and only if
25
+ * the lock on disk is still the acquisition the caller judged dead.
26
+ *
27
+ * `O_EXCL` on `run.lock` arbitrates creation only. Without this, two
28
+ * contenders can both judge the SAME dead lock, the first unlinks, recreates
29
+ * and owns it, and the second's already-justified unlink then deletes the
30
+ * first's LIVE lock and lets the second own the run too. Holding
31
+ * `run.lock.steal` across the identity re-read and the unlink makes the
32
+ * check-and-delete indivisible with respect to other reclaimers.
33
+ *
34
+ * Residual, accepted: a process that dies while holding `run.lock.steal`
35
+ * strands it, which disables automatic dead-PID reclaim for that run until an
36
+ * operator removes the file. Normal acquisition of an absent lock is unaffected.
37
+ */
38
+ export async function reclaimDeadRunLock(lockPath, observed) {
39
+ const stealPath = runLockStealPath(lockPath);
40
+ let handle;
41
+ try {
42
+ handle = await open(stealPath, "wx", 0o600);
43
+ }
44
+ catch (error) {
45
+ if (error.code === "EEXIST") {
46
+ return { kind: "steal_lock_busy", stealPath };
47
+ }
48
+ throw new Error(`Could not create run lock reclaim file ${stealPath}: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
49
+ }
50
+ try {
51
+ let current;
52
+ try {
53
+ current = JSON.parse(await readFile(lockPath, "utf-8"));
54
+ }
55
+ catch (error) {
56
+ if (error.code === "ENOENT") {
57
+ return { kind: "reclaimed" };
58
+ }
59
+ // Unreadable or replaced mid-write: not provably the dead acquisition.
60
+ return { kind: "superseded" };
61
+ }
62
+ if (typeof current !== "object" ||
63
+ current === null ||
64
+ identityKey(current) !== identityKey({ ...observed })) {
65
+ return { kind: "superseded" };
66
+ }
67
+ try {
68
+ await unlink(lockPath);
69
+ }
70
+ catch (error) {
71
+ if (error.code !== "ENOENT") {
72
+ throw error;
73
+ }
74
+ }
75
+ return { kind: "reclaimed" };
76
+ }
77
+ finally {
78
+ // A rejected close() must not skip the unlink: stranding our own steal file
79
+ // would disable reclaim for this run by accident.
80
+ await handle.close().catch(() => undefined);
81
+ await unlink(stealPath).catch((error) => {
82
+ logger.warn({ stealPath, err: error instanceof Error ? error.message : String(error) }, "could not remove run lock reclaim file; dead-PID reclaim for this run is disabled until it is deleted");
83
+ });
84
+ }
85
+ }
86
+ //# sourceMappingURL=run-lock-reclaim.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-lock-reclaim.js","sourceRoot":"","sources":["../src/run-lock-reclaim.ts"],"names":[],"mappings":"AAAA,OAAO,EA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CAAC,IAAI,CACT,EAAE,SAAS,EAAE,GAAG,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EAC1E,uGAAuG,CACxG,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;AACH,CAAC"}
@@ -32,6 +32,15 @@ export type CallState = "pending" | "running" | "succeeded" | "failed" | "cancel
32
32
  export type RunStatus = "pending" | "running" | "succeeded" | "failed" | "cancelled";
33
33
  /** Failure classification for diagnostics and retry decisions. */
34
34
  export type FailureClass = "transient" | "permanent";
35
+ /**
36
+ * Structured failure provenance recorded by the engine from in-process
37
+ * evidence, never from message text. `busy_before_spawn` is the root
38
+ * pipeline's fail-fast semaphore rejection (nothing was spawned). Absent means
39
+ * unknown: legacy runs and the stdio transport, which serializes errors to text.
40
+ */
41
+ export type CallFailureKind = "busy_before_spawn";
42
+ /** Persisted state is untrusted on read: only the exact known literal counts. */
43
+ export declare function parseCallFailureKind(value: unknown): CallFailureKind | undefined;
35
44
  /** The canonical run-level terminal fields overwritten by a generic resume. */
36
45
  export interface PreviousTerminalEnvelope {
37
46
  readonly status: "succeeded" | "failed" | "cancelled";
@@ -51,6 +60,8 @@ export interface CallStateEntry {
51
60
  readonly completedAt?: string | undefined;
52
61
  readonly durationMs?: number | undefined;
53
62
  readonly failureClass?: FailureClass | undefined;
63
+ /** Set only on a failed call with structured provenance; cleared by later emits. */
64
+ readonly failureKind?: CallFailureKind | undefined;
54
65
  readonly errorMessage?: string | undefined;
55
66
  /**
56
67
  * Pointer to output file for large outputs (>10KB).
@@ -17,5 +17,8 @@
17
17
  * Persistent resume requires CLINKX_WORKFLOWS_CHILD_CONFIG_PATH;
18
18
  * ambient-config runs are non-resumable.
19
19
  */
20
- export {};
20
+ /** Persisted state is untrusted on read: only the exact known literal counts. */
21
+ export function parseCallFailureKind(value) {
22
+ return value === "busy_before_spawn" ? value : undefined;
23
+ }
21
24
  //# sourceMappingURL=state-schema.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"state-schema.js","sourceRoot":"","sources":["../src/state-schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG"}
1
+ {"version":3,"file":"state-schema.js","sourceRoot":"","sources":["../src/state-schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AA0CH,iFAAiF;AACjF,MAAM,UAAU,oBAAoB,CAAC,KAAc;IACjD,OAAO,KAAK,KAAK,mBAAmB,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AAC3D,CAAC"}