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
@@ -67,6 +67,7 @@ import { stat as fsStat } from "node:fs/promises";
67
67
  import { ErrorCode, McpError } from "@modelcontextprotocol/sdk/types.js";
68
68
  import { basename, isAbsolute, join, resolve, sep } from "node:path";
69
69
  import { callClink, extractObservedInvocation } from "./clink-client.js";
70
+ import { resolveFileWriter } from "./durable-file.js";
70
71
  import { getArtifactsDir, getChildMaxConcurrent, getWorkflowsContextDefault, getWorkflowsContextDefaultCurator, getMaxParallel, getMaxPromptBytes, getStateDir, resolveWorkspaceRoot, } from "./config.js";
71
72
  import { validatePlanReviewCallBindings, validatePlanReviewPreparedInputPolicy, } from "./plan-review/runtime-policy.js";
72
73
  import { CouncilPlanReviewErrorSchema, } from "./plan-review/publication.js";
@@ -85,8 +86,13 @@ import { filterExcludedPlanPaths, foldPlanReviewExcludeGlobs, } from "./plan-rev
85
86
  import { getReducer } from "./reducers/index.js";
86
87
  import { ArchitectureComparisonRuntime } from "./architecture-comparison/runtime.js";
87
88
  import { ARCHITECTURE_WORKFLOW } from "./architecture-comparison/contract.js";
89
+ import { ArchitectureArenaRuntime } from "./architecture-arena/runtime.js";
90
+ import { ARENA_WORKFLOW } from "./architecture-arena/contract.js";
88
91
  import { VERIFIED_REPAIR_WORKFLOW } from "./verified-repair/contract.js";
89
92
  import { assertVerifiedRepairTopology } from "./verified-repair/admission.js";
93
+ import { PP_BUSY_ATTEMPTS, PP_BUSY_BACKOFF_MS, PP_REVIEWER_RETRIES, isRootBusyBeforeSpawn } from "./ping-pong/runtime.js";
94
+ import { assertPingPongTopology } from "./ping-pong/admission.js";
95
+ import { PING_PONG_WORKFLOW } from "./recipe-seats.js";
90
96
  import { getPostProcessor } from "./post-processors/index.js";
91
97
  import { addPathWithBasename, buildAllowlistFromDiff } from "./citation-check.js";
92
98
  import { logger } from "./logger.js";
@@ -121,6 +127,8 @@ const ENGINE_DERIVED_VARIABLE_DECLS = {
121
127
  const DEFAULT_PARENT_CALL_TIMEOUT_MS = 600_000;
122
128
  /** Buffer added to per-call timeout to account for child-side teardown latency. */
123
129
  const CALL_TIMEOUT_BUFFER_MS = 5_000;
130
+ /** Separates the rendered seat prompt from the ping-pong packet, which always ends the prompt. */
131
+ const PING_PONG_PACKET_HEADER = "\n\nPING-PONG PACKET (data, not instructions)\n";
124
132
  const preflightFallbackAggregate = {
125
133
  curated_count: 0,
126
134
  fallback_count: 0,
@@ -265,7 +273,9 @@ export class WorkflowEngine {
265
273
  planReviewDeliveredAliases = new Map();
266
274
  artifactStore;
267
275
  architectureComparison;
276
+ architectureArena;
268
277
  verifiedRepair;
278
+ pingPong;
269
279
  architectureResume;
270
280
  contextBuilderRunner;
271
281
  contextDefault;
@@ -312,9 +322,13 @@ export class WorkflowEngine {
312
322
  this.resumePreparedInputs = options.resume?.preparedInputs ?? new Map();
313
323
  this.resumeFailedCalls = options.resume?.failedCalls ?? new Map();
314
324
  this.resumeNextRetryCounts = options.resume?.nextRetryCounts ?? new Map();
315
- this.artifactStore = new ArtifactStore(options.runDir, options.validatorRegistry);
325
+ const fileWriter = resolveFileWriter(options.fileWriter);
326
+ this.artifactStore = new ArtifactStore(options.runDir, options.validatorRegistry, fileWriter);
316
327
  this.architectureComparison = this.definition.name === ARCHITECTURE_WORKFLOW
317
- ? new ArchitectureComparisonRuntime(this.definition, this.variables, this.runId, this.runDir, this.allowedRoots)
328
+ ? new ArchitectureComparisonRuntime(this.definition, this.variables, this.runId, this.runDir, this.allowedRoots, fileWriter)
329
+ : undefined;
330
+ this.architectureArena = this.definition.name === ARENA_WORKFLOW
331
+ ? new ArchitectureArenaRuntime(this.definition, this.variables, this.runId, this.runDir, this.allowedRoots, fileWriter)
318
332
  : undefined;
319
333
  this.architectureResume = options.resume;
320
334
  this.verifiedRepair = options.verifiedRepair;
@@ -325,6 +339,12 @@ export class WorkflowEngine {
325
339
  if (options.resume !== undefined)
326
340
  throw new WorkflowError("verified-repair mutation cannot be resumed; submit a fresh explicit contract");
327
341
  }
342
+ this.pingPong = options.pingPong;
343
+ if (this.definition.name === PING_PONG_WORKFLOW || this.pingPong !== undefined) {
344
+ assertPingPongTopology(this.definition, this.variables);
345
+ if (this.pingPong === undefined)
346
+ throw new WorkflowError("ping-pong requires the root recipe runtime");
347
+ }
328
348
  this.contextBuilderRunner = this.verifiedRepair === undefined ? options.contextBuilderRunner : undefined;
329
349
  this.contextDefault = options.contextDefault ?? getWorkflowsContextDefault();
330
350
  this.defaultCurator = options.defaultCurator ?? getWorkflowsContextDefaultCurator();
@@ -349,9 +369,12 @@ export class WorkflowEngine {
349
369
  this.seedResumedArtifacts();
350
370
  }
351
371
  async execute() {
372
+ // Ping-pong: min(remaining active budget, remaining wall deadline) + grace
373
+ // per execution, a backstop behind the runtime's own budget checks (D3).
374
+ const timeoutSeconds = this.pingPong?.executionTimeoutSeconds() ?? this.definition.settings.timeout_seconds;
352
375
  this.workflowDeadlineAtMonoMs =
353
- monotonicNowMs() + this.definition.settings.timeout_seconds * 1000;
354
- const deadlineController = this.createDeadlineController(this.definition.settings.timeout_seconds * 1000);
376
+ monotonicNowMs() + timeoutSeconds * 1000;
377
+ const deadlineController = this.createDeadlineController(timeoutSeconds * 1000);
355
378
  const stages = [];
356
379
  const startedAt = new Date().toISOString();
357
380
  try {
@@ -369,11 +392,17 @@ export class WorkflowEngine {
369
392
  message: `Workflow ${this.definition.name} is running`,
370
393
  });
371
394
  await this.architectureComparison?.restore(this.architectureResume);
395
+ await this.architectureArena?.restore(this.architectureResume);
372
396
  this.throwIfAborted(deadlineController.signal);
373
397
  await this.prepareContextPreflight(deadlineController.signal);
398
+ let paused = false;
374
399
  for (let stageIndex = 0; stageIndex < this.definition.stages.length; stageIndex += 1) {
375
400
  this.throwIfAborted(deadlineController.signal);
376
401
  const stage = this.definition.stages[stageIndex];
402
+ // Ping-pong: the runtime names the one stage that runs next; every
403
+ // other stage stays pending (D1 fixed topology).
404
+ if (this.pingPong?.stageDisposition(stage.id) === "skip")
405
+ continue;
377
406
  logger.info({ run_id: this.runId, stage_id: stage.id }, "executing workflow stage");
378
407
  await this.emitProgress({
379
408
  runId: this.runId,
@@ -401,6 +430,13 @@ export class WorkflowEngine {
401
430
  state: executedStage.ok ? "succeeded" : "failed",
402
431
  message: `Stage ${stage.id} ${executedStage.ok ? "succeeded" : "failed"}`,
403
432
  });
433
+ if (this.pingPong !== undefined) {
434
+ const directive = this.pingPong.afterStage(stage.id, executedStage.ok);
435
+ if (directive === "pause") {
436
+ paused = true;
437
+ break;
438
+ }
439
+ }
404
440
  if (!executedStage.ok && stage.on_failure === "abort") {
405
441
  // Generic boundary for ALL stage aborts, so it must stay permanent by
406
442
  // default — a stage that aborts on an ordinary permanent call failure
@@ -412,7 +448,11 @@ export class WorkflowEngine {
412
448
  throw new WorkflowError(`Stage ${stage.id} failed and on_failure=abort`, this.isWorkflowDeadlineExhausted() ? "transient" : undefined);
413
449
  }
414
450
  }
415
- const outputText = await this.resolveTerminalResult(stages);
451
+ // A pause publishes a terminal succeeded envelope for this execution;
452
+ // the recipe phase lives in the sidecar (D2).
453
+ const outputText = paused && this.pingPong !== undefined
454
+ ? this.pingPong.pauseOutput()
455
+ : await this.resolveTerminalResult(stages);
416
456
  const completedAt = new Date().toISOString();
417
457
  await this.emitRunStateChange({
418
458
  runId: this.runId,
@@ -568,6 +608,9 @@ export class WorkflowEngine {
568
608
  this.throwIfAborted(signal);
569
609
  const executedCall = await this.executeSingleCall(stage, stage.calls[callIndex], stageIndex, callIndex, signal);
570
610
  calls.push(executedCall);
611
+ if (stage.calls[callIndex].reducer == null) {
612
+ this.pingPong?.afterCall(`${stage.id}.${stage.calls[callIndex].id}`, executedCall.ok, executedCall.error);
613
+ }
571
614
  if (!executedCall.ok && stage.on_failure === "abort") {
572
615
  return { stageId: stage.id, ok: false, calls };
573
616
  }
@@ -620,9 +663,9 @@ export class WorkflowEngine {
620
663
  }
621
664
  try {
622
665
  const contextArtifacts = this.artifactStore.buildContext(this.definition, call.context_from);
623
- const outputText = await reducer(contextArtifacts.artifacts, { variables: this.effectiveVariables, architectureComparison: this.architectureComparison, verifiedRepair: this.verifiedRepair, signal });
666
+ const outputText = await reducer(contextArtifacts.artifacts, { variables: this.effectiveVariables, architectureComparison: this.architectureComparison, architectureArena: this.architectureArena, omissions: contextArtifacts.omissions, verifiedRepair: this.verifiedRepair, pingPong: this.pingPong, stageId: stage.id, signal });
624
667
  this.throwIfAborted(signal);
625
- const artifact = this.maybeWriteArtifact(stage, call, stageIndex, callIndex, outputText);
668
+ const artifact = await this.maybeWriteArtifact(stage, call, stageIndex, callIndex, outputText);
626
669
  const completedAt = new Date().toISOString();
627
670
  const durationMs = Date.now() - startedAtMs;
628
671
  await this.emitCallStateChange({
@@ -681,8 +724,10 @@ export class WorkflowEngine {
681
724
  let input;
682
725
  try {
683
726
  await this.verifiedRepair?.prepareProvider(callKey, signal);
727
+ await this.pingPong?.prepareProvider(callKey, signal);
684
728
  input = this.buildCallInput(stage, call, callKey, callIndex);
685
729
  await this.architectureComparison?.beforeDispatch(callKey, input);
730
+ await this.architectureArena?.beforeDispatch(callKey, input);
686
731
  this.throwIfAborted(signal);
687
732
  }
688
733
  catch (error) {
@@ -818,7 +863,7 @@ export class WorkflowEngine {
818
863
  callId: call.id,
819
864
  contextProducing,
820
865
  });
821
- const artifact = this.maybeWriteArtifact(stage, call, stageIndex, callIndex, result.outputText);
866
+ const artifact = await this.maybeWriteArtifact(stage, call, stageIndex, callIndex, result.outputText);
822
867
  const completedAt = new Date().toISOString();
823
868
  const durationMs = Date.now() - startedAtMs;
824
869
  const observedInvocation = extractObservedInvocation(result.debugMetadata);
@@ -937,7 +982,9 @@ export class WorkflowEngine {
937
982
  // parse problem on a transport failure still means delivery is incomplete.
938
983
  this.verifiedRepair.noteInvalidArtifact(callKey, new SchemaValidationError("native provider output failed strict JSON validation"));
939
984
  }
940
- this.artifactStore.noteFailedCall(stage.id, call.id, message);
985
+ // Read from the in-process marker only; the message can be provider text.
986
+ const failureKind = isRootBusyBeforeSpawn(lastError) ? "busy_before_spawn" : undefined;
987
+ this.artifactStore.noteFailedCall(stage.id, call.id, message, { failureClass: lastFailureClass, failureKind });
941
988
  logger.warn({ run_id: this.runId, stage_id: stage.id, call_id: call.id, err: message, retries: finalRetryCount }, "workflow call failed");
942
989
  const completedAt = new Date().toISOString();
943
990
  const durationMs = Date.now() - startedAtMs;
@@ -954,6 +1001,7 @@ export class WorkflowEngine {
954
1001
  durationMs,
955
1002
  error: message,
956
1003
  failureClass: lastFailureClass,
1004
+ ...(failureKind !== undefined ? { failureKind } : {}),
957
1005
  childDebugMetadata: lastChildDebug,
958
1006
  });
959
1007
  await this.emitProgress({
@@ -1078,7 +1126,9 @@ export class WorkflowEngine {
1078
1126
  if (detail == null) {
1079
1127
  return undefined;
1080
1128
  }
1081
- const suffix = buildCorrectiveSuffixText(detail, error instanceof OutputSizeError ? CORRECTIVE_SIZE_SUFFIX_HEADER : CORRECTIVE_SUFFIX_HEADER);
1129
+ const suffix = buildCorrectiveSuffixText(detail, error instanceof OutputSizeError ? CORRECTIVE_SIZE_SUFFIX_HEADER : CORRECTIVE_SUFFIX_HEADER, failedViaResultContract(error)
1130
+ ? `${CORRECTIVE_SUFFIX_FOOTER}${CORRECTIVE_RESULT_FILE_FOOTER}`
1131
+ : CORRECTIVE_SUFFIX_FOOTER);
1082
1132
  try {
1083
1133
  const basePrompt = typeof input["prompt"] === "string" ? input["prompt"] : "";
1084
1134
  const files = Array.isArray(input["absolute_file_paths"])
@@ -1133,8 +1183,96 @@ export class WorkflowEngine {
1133
1183
  await this.verifiedRepair?.beforeDispatch(`${stage.id}.${call.id}`, dispatchInput, signal);
1134
1184
  this.throwIfAborted(signal);
1135
1185
  const finalDispatchDeadline = this.computeDispatchDeadline(call);
1186
+ if (this.pingPong !== undefined) {
1187
+ return await this.invokePingPongCall(stage, call, dispatchInput, signal, finalDispatchDeadline.timeoutMs, sessionLogOwner);
1188
+ }
1136
1189
  return await callClink(this.session, dispatchInput, signal, { stageId: stage.id, callId: call.id }, finalDispatchDeadline.timeoutMs, sessionLogOwner);
1137
1190
  }
1191
+ /**
1192
+ * Ping-pong seat dispatch: recipe call options (worktree cwd, confirmed
1193
+ * exit), operation intent before and result after every attempt, and two
1194
+ * in-place retry arms with independent counters: busy-before-spawn,
1195
+ * bounded by PP_BUSY_ATTEMPTS, and the runtime-decided reviewer retry
1196
+ * (D-C), bounded by PP_REVIEWER_RETRIES and dispatched with the rebuilt
1197
+ * packet.
1198
+ */
1199
+ async invokePingPongCall(stage, call, dispatchInput, signal, timeoutMs, sessionLogOwner) {
1200
+ const pingPong = this.pingPong;
1201
+ const callKey = `${stage.id}.${call.id}`;
1202
+ let input = dispatchInput;
1203
+ let busyAttempts = 0;
1204
+ let reviewerRetries = 0;
1205
+ // Only the runtime's "retry" after a dispatch that ran is a reviewer retry.
1206
+ const reviewerRetry = (decision, dispatchedPacket) => {
1207
+ if (decision !== "retry" || reviewerRetries >= PP_REVIEWER_RETRIES)
1208
+ return false;
1209
+ reviewerRetries += 1;
1210
+ input = this.rebuildPingPongInput(input, dispatchedPacket, pingPong.providerPacket(callKey));
1211
+ return true;
1212
+ };
1213
+ for (;;) {
1214
+ const dispatchedPacket = pingPong.providerPacket(callKey);
1215
+ await pingPong.beforeDispatch(callKey, signal);
1216
+ let observed = false;
1217
+ let exit;
1218
+ let result;
1219
+ // Only the dispatch is guarded: a throw from settling a successful
1220
+ // result must not be settled a second time as a failed dispatch.
1221
+ try {
1222
+ result = await callClink(this.session, input, signal, { stageId: stage.id, callId: call.id }, timeoutMs,
1223
+ // A retried reviewer dispatch is its own session-log lane.
1224
+ sessionLogOwner?.family === "workflow" && reviewerRetries > 0
1225
+ ? { ...sessionLogOwner, attempt: (sessionLogOwner.attempt ?? 1) + reviewerRetries }
1226
+ : sessionLogOwner, {
1227
+ options: pingPong.recipeCallOptions(callKey),
1228
+ onResult: (processGroupExit) => { observed = true; exit = processGroupExit; },
1229
+ });
1230
+ }
1231
+ catch (error) {
1232
+ // A recipe call that is cancelled throws carrying the same
1233
+ // processGroupExit evidence a result would; absent means unconfirmed.
1234
+ const thrownExit = error?.processGroupExit;
1235
+ if (!observed && thrownExit !== null && typeof thrownExit === "object" &&
1236
+ typeof thrownExit.exited === "boolean") {
1237
+ observed = true;
1238
+ exit = { exited: thrownExit.exited };
1239
+ }
1240
+ if (!observed && isRootBusyBeforeSpawn(error)) {
1241
+ busyAttempts += 1;
1242
+ const final = busyAttempts >= PP_BUSY_ATTEMPTS;
1243
+ await pingPong.afterDispatch(callKey, { kind: "busy", final }, signal);
1244
+ if (!final) {
1245
+ await abortableDelay(PP_BUSY_BACKOFF_MS[busyAttempts - 1] ?? PP_BUSY_BACKOFF_MS.at(-1), signal);
1246
+ continue;
1247
+ }
1248
+ throw error;
1249
+ }
1250
+ const decision = await pingPong.afterDispatch(callKey, observed ? { kind: "result", outputText: "", isError: true, exit, error } : { kind: "thrown", error }, signal);
1251
+ if (reviewerRetry(decision, dispatchedPacket))
1252
+ continue;
1253
+ throw error;
1254
+ }
1255
+ const decision = await pingPong.afterDispatch(callKey, { kind: "result", outputText: result.outputText, isError: false, exit }, signal);
1256
+ if (reviewerRetry(decision, dispatchedPacket))
1257
+ continue;
1258
+ return result;
1259
+ }
1260
+ }
1261
+ /**
1262
+ * The dispatched prompt with its trailing ping-pong packet replaced by the
1263
+ * rebuilt one, re-checked against the prompt budget. Fails closed when the
1264
+ * prompt does not end with the packet it was dispatched with.
1265
+ */
1266
+ rebuildPingPongInput(input, dispatchedPacket, nextPacket) {
1267
+ const prompt = input["prompt"];
1268
+ const dispatchedTail = `${PING_PONG_PACKET_HEADER}${dispatchedPacket ?? ""}`;
1269
+ if (dispatchedPacket === undefined || nextPacket === undefined || typeof prompt !== "string" || !prompt.endsWith(dispatchedTail)) {
1270
+ throw new WorkflowError("ping-pong reviewer retry cannot rebuild the dispatched prompt");
1271
+ }
1272
+ const rebuilt = { ...input, prompt: `${prompt.slice(0, prompt.length - dispatchedTail.length)}${PING_PONG_PACKET_HEADER}${nextPacket}` };
1273
+ enforcePromptBudget(this.estimateInputPromptBudget(rebuilt));
1274
+ return rebuilt;
1275
+ }
1138
1276
  computeDispatchDeadline(call) {
1139
1277
  const configuredCallTimeoutMs = call.timeout_seconds != null
1140
1278
  ? Math.max((call.timeout_seconds * 1000) + CALL_TIMEOUT_BUFFER_MS, DEFAULT_PARENT_CALL_TIMEOUT_MS)
@@ -1175,24 +1313,31 @@ export class WorkflowEngine {
1175
1313
  callRemainingMs,
1176
1314
  })}`,
1177
1315
  };
1316
+ enforcePromptBudget(this.estimateInputPromptBudget(guidedInput));
1317
+ return guidedInput;
1318
+ }
1319
+ /** Prompt-budget estimate of a fully built call input (prompt, context, files, images). */
1320
+ estimateInputPromptBudget(input) {
1178
1321
  const filePaths = Array.isArray(input["absolute_file_paths"])
1179
1322
  ? input["absolute_file_paths"].filter((path) => typeof path === "string")
1180
1323
  : [];
1181
1324
  const imagePaths = Array.isArray(input["images"])
1182
1325
  ? input["images"].filter((path) => typeof path === "string")
1183
1326
  : [];
1184
- const estimate = estimatePromptBudget({
1185
- promptText: guidedInput["prompt"],
1327
+ return estimatePromptBudget({
1328
+ promptText: typeof input["prompt"] === "string" ? input["prompt"] : "",
1186
1329
  contextText: typeof input["context"] === "string" ? input["context"] : undefined,
1187
1330
  fileContributors: filePaths.map((path) => createPathContributor(`absolute_file_paths:${path}`, path, "file")),
1188
1331
  imageContributors: imagePaths.map((path) => createPathContributor(`image:${path}`, path, "image")),
1189
1332
  maxBytes: this.maxPromptBytes,
1190
1333
  reserveBytes: this.promptReserveBytes,
1191
1334
  });
1192
- enforcePromptBudget(estimate);
1193
- return guidedInput;
1194
1335
  }
1195
- maybeWriteArtifact(stage, call, stageIndex, callIndex, outputText) {
1336
+ /**
1337
+ * The artifact (and any recipe evidence it updates) is durable before it
1338
+ * returns, so the succeeded call state that names it is published second.
1339
+ */
1340
+ async maybeWriteArtifact(stage, call, stageIndex, callIndex, outputText) {
1196
1341
  const requiresValidation = call.validator_schema_id != null;
1197
1342
  if (!requiresValidation) {
1198
1343
  return undefined;
@@ -1205,6 +1350,7 @@ export class WorkflowEngine {
1205
1350
  try {
1206
1351
  validated = this.artifactStore.validateJsonOutput(stage.id, call.id, validatorSchemaId, outputText);
1207
1352
  this.architectureComparison?.validateOutput(`${stage.id}.${call.id}`, validated.parsed);
1353
+ this.architectureArena?.validateOutput(`${stage.id}.${call.id}`, validated.parsed);
1208
1354
  this.verifiedRepair?.validateOutput(`${stage.id}.${call.id}`, validated.parsed);
1209
1355
  }
1210
1356
  catch (error) {
@@ -1259,14 +1405,15 @@ export class WorkflowEngine {
1259
1405
  sizeBytes: Buffer.byteLength(serialized, "utf-8"),
1260
1406
  };
1261
1407
  }
1262
- const artifact = this.artifactStore.writeCallArtifact({
1408
+ const artifact = await this.artifactStore.writeCallArtifact({
1263
1409
  stage,
1264
1410
  call,
1265
1411
  stageIndex,
1266
1412
  callIndex,
1267
1413
  validated: persisted,
1268
1414
  });
1269
- this.architectureComparison?.recordWritten(artifact);
1415
+ await this.architectureComparison?.recordWritten(artifact);
1416
+ await this.architectureArena?.recordWritten(artifact);
1270
1417
  this.verifiedRepair?.recordWritten(artifact);
1271
1418
  return artifact;
1272
1419
  }
@@ -1530,6 +1677,9 @@ export class WorkflowEngine {
1530
1677
  ...(this.definition.settings.include_selected_context_artifact === true
1531
1678
  ? { includeSelectedContext: true }
1532
1679
  : {}),
1680
+ // D-B: ping-pong roots are its own baseline worktree; a cached bundle
1681
+ // keyed by a shared-checkout signature must never stand in for it.
1682
+ ...(this.pingPong !== undefined ? { bypassCache: true } : {}),
1533
1683
  ...(contextBudgetAdapter == null || contextBudgetAdapter.trim() === ""
1534
1684
  ? {}
1535
1685
  : { context_budget_adapter: contextBudgetAdapter }),
@@ -1916,9 +2066,12 @@ export class WorkflowEngine {
1916
2066
  // Frozen source text is data, never template input; count every delivered
1917
2067
  // byte in the same authoritative prompt budget as the rendered template.
1918
2068
  const repairPacket = this.verifiedRepair?.providerPacket(callKey);
1919
- const prompt = repairPacket === undefined
1920
- ? basePrompt
1921
- : `${basePrompt}\n\nFROZEN REPAIR PACKET\n${repairPacket}`;
2069
+ const pingPongPacket = this.pingPong?.providerPacket(callKey);
2070
+ const prompt = repairPacket !== undefined
2071
+ ? `${basePrompt}\n\nFROZEN REPAIR PACKET\n${repairPacket}`
2072
+ : pingPongPacket !== undefined
2073
+ ? `${basePrompt}${PING_PONG_PACKET_HEADER}${pingPongPacket}`
2074
+ : basePrompt;
1922
2075
  const contextArtifacts = call.anonymize_context === true
1923
2076
  ? this.artifactStore.buildAnonymizedContext(this.definition, call.context_from, callIndex, call.plan_review_semantic_context === true
1924
2077
  ? projectPlanReviewSemanticBody
@@ -2078,7 +2231,10 @@ export class WorkflowEngine {
2078
2231
  }
2079
2232
  for (const failedCall of this.resumeFailedCalls.values()) {
2080
2233
  if (failedCall.terminal) {
2081
- this.artifactStore.seedFailedCall(failedCall.stageId, failedCall.callId, failedCall.error);
2234
+ this.artifactStore.seedFailedCall(failedCall.stageId, failedCall.callId, failedCall.error, {
2235
+ failureClass: failedCall.failureClass,
2236
+ failureKind: failedCall.failureKind,
2237
+ });
2082
2238
  }
2083
2239
  }
2084
2240
  }
@@ -2268,6 +2424,22 @@ const CORRECTIVE_SUFFIX_HEADER = "\n\n---\nCORRECTION: Your previous response wa
2268
2424
  const CORRECTIVE_SIZE_SUFFIX_HEADER = "\n\n---\nCORRECTION: Your previous response was rejected because the pretty-printed JSON exceeded the validator byte cap. Shrink the deliverable first. Failure: ";
2269
2425
  const CORRECTIVE_SUFFIX_FOOTER = "\nReturn ONLY a single JSON object conforming to the declared contract — no prose, no markdown, " +
2270
2426
  "no code fences, and nothing before or after the JSON object.";
2427
+ // The footer alone let a provider fix stdout while rewriting the result file
2428
+ // as Markdown. The filename never reaches the engine (ChildFailureMetadata
2429
+ // carries only parse_source), so the instruction refers to it generically.
2430
+ const CORRECTIVE_RESULT_FILE_FOOTER = "\nThe result file named in your instructions must contain only that single JSON value — " +
2431
+ "no Markdown, no prose, and no code fences.";
2432
+ /**
2433
+ * Whether the rejected output was read from the result file. A
2434
+ * TypedResultFidelityError is only ever raised for result-contract output.
2435
+ */
2436
+ function failedViaResultContract(error) {
2437
+ if (error instanceof TypedResultFidelityError) {
2438
+ return true;
2439
+ }
2440
+ return error instanceof CallExecutionError &&
2441
+ error.childDebugMetadata?.parse_source === "result_contract";
2442
+ }
2271
2443
  /**
2272
2444
  * Detail text for a JSON/schema-shaped failure, or undefined when the failure
2273
2445
  * is not one a corrective re-prompt could fix (transport death, timeout, …).
@@ -2308,14 +2480,14 @@ function foldExternalGapPolicy(delegate, policy) {
2308
2480
  }
2309
2481
  return { ...delegate, external_gap_policy: policy };
2310
2482
  }
2311
- function buildCorrectiveSuffixText(detail, header = CORRECTIVE_SUFFIX_HEADER) {
2483
+ function buildCorrectiveSuffixText(detail, header = CORRECTIVE_SUFFIX_HEADER, footer = CORRECTIVE_SUFFIX_FOOTER) {
2312
2484
  const budget = CORRECTIVE_SUFFIX_MAX_CHARS -
2313
2485
  header.length -
2314
- CORRECTIVE_SUFFIX_FOOTER.length;
2486
+ footer.length;
2315
2487
  const bounded = detail.length > budget
2316
2488
  ? `${detail.slice(0, Math.max(0, budget - 1))}…`
2317
2489
  : detail;
2318
- return `${header}${bounded}${CORRECTIVE_SUFFIX_FOOTER}`;
2490
+ return `${header}${bounded}${footer}`;
2319
2491
  }
2320
2492
  /**
2321
2493
  * Determine whether an error is retryable based on the retry mode (5-1, 5-2).