clinkx 0.3.0 → 1.1.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 (669) hide show
  1. package/CHANGELOG.md +119 -0
  2. package/LICENSE +10 -0
  3. package/README.md +154 -26
  4. package/clinkx-workflows/dist/allowed-roots.d.ts +1 -0
  5. package/clinkx-workflows/dist/allowed-roots.js +5 -0
  6. package/clinkx-workflows/dist/allowed-roots.js.map +1 -0
  7. package/clinkx-workflows/dist/artifacts.d.ts +20 -1
  8. package/clinkx-workflows/dist/artifacts.js +38 -9
  9. package/clinkx-workflows/dist/artifacts.js.map +1 -1
  10. package/clinkx-workflows/dist/backend.d.ts +4 -0
  11. package/clinkx-workflows/dist/chairman-knobs.d.ts +24 -0
  12. package/clinkx-workflows/dist/chairman-knobs.js +27 -0
  13. package/clinkx-workflows/dist/chairman-knobs.js.map +1 -0
  14. package/clinkx-workflows/dist/citation-check.d.ts +40 -0
  15. package/clinkx-workflows/dist/citation-check.js +348 -0
  16. package/clinkx-workflows/dist/citation-check.js.map +1 -0
  17. package/clinkx-workflows/dist/clink-client.d.ts +12 -1
  18. package/clinkx-workflows/dist/clink-client.js +56 -5
  19. package/clinkx-workflows/dist/clink-client.js.map +1 -1
  20. package/clinkx-workflows/dist/config.d.ts +173 -16
  21. package/clinkx-workflows/dist/config.js +417 -26
  22. package/clinkx-workflows/dist/config.js.map +1 -1
  23. package/clinkx-workflows/dist/contained-file.d.ts +172 -0
  24. package/clinkx-workflows/dist/contained-file.js +483 -0
  25. package/clinkx-workflows/dist/contained-file.js.map +1 -0
  26. package/clinkx-workflows/dist/context-builder-lifecycle-contract.d.ts +416 -0
  27. package/clinkx-workflows/dist/context-builder-lifecycle-contract.js +328 -0
  28. package/clinkx-workflows/dist/context-builder-lifecycle-contract.js.map +1 -0
  29. package/clinkx-workflows/dist/context-builder-lifecycle-router.d.ts +24 -0
  30. package/clinkx-workflows/dist/context-builder-lifecycle-router.js +39 -0
  31. package/clinkx-workflows/dist/context-builder-lifecycle-router.js.map +1 -0
  32. package/clinkx-workflows/dist/context-cache-key.d.ts +53 -0
  33. package/clinkx-workflows/dist/context-cache-key.js +91 -0
  34. package/clinkx-workflows/dist/context-cache-key.js.map +1 -0
  35. package/clinkx-workflows/dist/context-mode-resolver.d.ts +27 -0
  36. package/clinkx-workflows/dist/context-mode-resolver.js +126 -0
  37. package/clinkx-workflows/dist/context-mode-resolver.js.map +1 -0
  38. package/clinkx-workflows/dist/context-preflight.d.ts +189 -0
  39. package/clinkx-workflows/dist/context-preflight.js +91 -0
  40. package/clinkx-workflows/dist/context-preflight.js.map +1 -0
  41. package/clinkx-workflows/dist/council-execution-policy.d.ts +68 -0
  42. package/clinkx-workflows/dist/council-execution-policy.js +110 -0
  43. package/clinkx-workflows/dist/council-execution-policy.js.map +1 -0
  44. package/clinkx-workflows/dist/council-expander.d.ts +10 -9
  45. package/clinkx-workflows/dist/council-expander.js +20 -10
  46. package/clinkx-workflows/dist/council-expander.js.map +1 -1
  47. package/clinkx-workflows/dist/dashboard/activity-contract.d.ts +5718 -0
  48. package/clinkx-workflows/dist/dashboard/activity-contract.js +157 -0
  49. package/clinkx-workflows/dist/dashboard/activity-contract.js.map +1 -0
  50. package/clinkx-workflows/dist/dashboard/activity-lease.d.ts +25 -0
  51. package/clinkx-workflows/dist/dashboard/activity-lease.js +34 -0
  52. package/clinkx-workflows/dist/dashboard/activity-lease.js.map +1 -0
  53. package/clinkx-workflows/dist/dashboard/activity-reader.d.ts +90 -0
  54. package/clinkx-workflows/dist/dashboard/activity-reader.js +493 -0
  55. package/clinkx-workflows/dist/dashboard/activity-reader.js.map +1 -0
  56. package/clinkx-workflows/dist/dashboard/api-routes.d.ts +40 -0
  57. package/clinkx-workflows/dist/dashboard/api-routes.js +1155 -0
  58. package/clinkx-workflows/dist/dashboard/api-routes.js.map +1 -0
  59. package/clinkx-workflows/dist/dashboard/artifact-index.d.ts +37 -0
  60. package/clinkx-workflows/dist/dashboard/artifact-index.js +145 -0
  61. package/clinkx-workflows/dist/dashboard/artifact-index.js.map +1 -0
  62. package/clinkx-workflows/dist/dashboard/auth/challenge-store.d.ts +31 -0
  63. package/clinkx-workflows/dist/dashboard/auth/challenge-store.js +65 -0
  64. package/clinkx-workflows/dist/dashboard/auth/challenge-store.js.map +1 -0
  65. package/clinkx-workflows/dist/dashboard/auth/controller.d.ts +26 -0
  66. package/clinkx-workflows/dist/dashboard/auth/controller.js +596 -0
  67. package/clinkx-workflows/dist/dashboard/auth/controller.js.map +1 -0
  68. package/clinkx-workflows/dist/dashboard/auth/credential-store.d.ts +60 -0
  69. package/clinkx-workflows/dist/dashboard/auth/credential-store.js +776 -0
  70. package/clinkx-workflows/dist/dashboard/auth/credential-store.js.map +1 -0
  71. package/clinkx-workflows/dist/dashboard/auth/enrollment-gate.d.ts +9 -0
  72. package/clinkx-workflows/dist/dashboard/auth/enrollment-gate.js +44 -0
  73. package/clinkx-workflows/dist/dashboard/auth/enrollment-gate.js.map +1 -0
  74. package/clinkx-workflows/dist/dashboard/auth/session-store.d.ts +17 -0
  75. package/clinkx-workflows/dist/dashboard/auth/session-store.js +77 -0
  76. package/clinkx-workflows/dist/dashboard/auth/session-store.js.map +1 -0
  77. package/clinkx-workflows/dist/dashboard/auth/webauthn-service.d.ts +25 -0
  78. package/clinkx-workflows/dist/dashboard/auth/webauthn-service.js +71 -0
  79. package/clinkx-workflows/dist/dashboard/auth/webauthn-service.js.map +1 -0
  80. package/clinkx-workflows/dist/dashboard/context-builder-invocation-contract.d.ts +3865 -0
  81. package/clinkx-workflows/dist/dashboard/context-builder-invocation-contract.js +69 -0
  82. package/clinkx-workflows/dist/dashboard/context-builder-invocation-contract.js.map +1 -0
  83. package/clinkx-workflows/dist/dashboard/context-run-liveness.d.ts +37 -0
  84. package/clinkx-workflows/dist/dashboard/context-run-liveness.js +49 -0
  85. package/clinkx-workflows/dist/dashboard/context-run-liveness.js.map +1 -0
  86. package/clinkx-workflows/dist/dashboard/context-run-reader.d.ts +256 -0
  87. package/clinkx-workflows/dist/dashboard/context-run-reader.js +1301 -0
  88. package/clinkx-workflows/dist/dashboard/context-run-reader.js.map +1 -0
  89. package/clinkx-workflows/dist/dashboard/contracts.d.ts +28483 -0
  90. package/clinkx-workflows/dist/dashboard/contracts.js +1284 -0
  91. package/clinkx-workflows/dist/dashboard/contracts.js.map +1 -0
  92. package/clinkx-workflows/dist/dashboard/generation.d.ts +14 -0
  93. package/clinkx-workflows/dist/dashboard/generation.js +41 -0
  94. package/clinkx-workflows/dist/dashboard/generation.js.map +1 -0
  95. package/clinkx-workflows/dist/dashboard/index.d.ts +32 -0
  96. package/clinkx-workflows/dist/dashboard/index.js +20 -0
  97. package/clinkx-workflows/dist/dashboard/index.js.map +1 -0
  98. package/clinkx-workflows/dist/dashboard/invocation-contract.d.ts +786 -0
  99. package/clinkx-workflows/dist/dashboard/invocation-contract.js +201 -0
  100. package/clinkx-workflows/dist/dashboard/invocation-contract.js.map +1 -0
  101. package/clinkx-workflows/dist/dashboard/lazy-content.d.ts +114 -0
  102. package/clinkx-workflows/dist/dashboard/lazy-content.js +799 -0
  103. package/clinkx-workflows/dist/dashboard/lazy-content.js.map +1 -0
  104. package/clinkx-workflows/dist/dashboard/native-transcript/contract.d.ts +90 -0
  105. package/clinkx-workflows/dist/dashboard/native-transcript/contract.js +31 -0
  106. package/clinkx-workflows/dist/dashboard/native-transcript/contract.js.map +1 -0
  107. package/clinkx-workflows/dist/dashboard/native-transcript/projection.d.ts +12 -0
  108. package/clinkx-workflows/dist/dashboard/native-transcript/projection.js +286 -0
  109. package/clinkx-workflows/dist/dashboard/native-transcript/projection.js.map +1 -0
  110. package/clinkx-workflows/dist/dashboard/progress-report-contract.d.ts +446 -0
  111. package/clinkx-workflows/dist/dashboard/progress-report-contract.js +221 -0
  112. package/clinkx-workflows/dist/dashboard/progress-report-contract.js.map +1 -0
  113. package/clinkx-workflows/dist/dashboard/progress-report-reader.d.ts +50 -0
  114. package/clinkx-workflows/dist/dashboard/progress-report-reader.js +529 -0
  115. package/clinkx-workflows/dist/dashboard/progress-report-reader.js.map +1 -0
  116. package/clinkx-workflows/dist/dashboard/progress-report-status-overlay.d.ts +89 -0
  117. package/clinkx-workflows/dist/dashboard/progress-report-status-overlay.js +71 -0
  118. package/clinkx-workflows/dist/dashboard/progress-report-status-overlay.js.map +1 -0
  119. package/clinkx-workflows/dist/dashboard/progress-report-status-store.d.ts +29 -0
  120. package/clinkx-workflows/dist/dashboard/progress-report-status-store.js +111 -0
  121. package/clinkx-workflows/dist/dashboard/progress-report-status-store.js.map +1 -0
  122. package/clinkx-workflows/dist/dashboard/prompt-builder-library-contract.d.ts +194 -0
  123. package/clinkx-workflows/dist/dashboard/prompt-builder-library-contract.js +89 -0
  124. package/clinkx-workflows/dist/dashboard/prompt-builder-library-contract.js.map +1 -0
  125. package/clinkx-workflows/dist/dashboard/prompt-builder-library-store.d.ts +26 -0
  126. package/clinkx-workflows/dist/dashboard/prompt-builder-library-store.js +102 -0
  127. package/clinkx-workflows/dist/dashboard/prompt-builder-library-store.js.map +1 -0
  128. package/clinkx-workflows/dist/dashboard/read-model.d.ts +86 -0
  129. package/clinkx-workflows/dist/dashboard/read-model.js +440 -0
  130. package/clinkx-workflows/dist/dashboard/read-model.js.map +1 -0
  131. package/clinkx-workflows/dist/dashboard/request-admission.d.ts +31 -0
  132. package/clinkx-workflows/dist/dashboard/request-admission.js +130 -0
  133. package/clinkx-workflows/dist/dashboard/request-admission.js.map +1 -0
  134. package/clinkx-workflows/dist/dashboard/scanner.d.ts +78 -0
  135. package/clinkx-workflows/dist/dashboard/scanner.js +1154 -0
  136. package/clinkx-workflows/dist/dashboard/scanner.js.map +1 -0
  137. package/clinkx-workflows/dist/dashboard/server-factory.d.ts +63 -0
  138. package/clinkx-workflows/dist/dashboard/server-factory.js +483 -0
  139. package/clinkx-workflows/dist/dashboard/server-factory.js.map +1 -0
  140. package/clinkx-workflows/dist/dashboard/session-log-contract.d.ts +2778 -0
  141. package/clinkx-workflows/dist/dashboard/session-log-contract.js +506 -0
  142. package/clinkx-workflows/dist/dashboard/session-log-contract.js.map +1 -0
  143. package/clinkx-workflows/dist/dashboard/session-log-identity.d.ts +21 -0
  144. package/clinkx-workflows/dist/dashboard/session-log-identity.js +101 -0
  145. package/clinkx-workflows/dist/dashboard/session-log-identity.js.map +1 -0
  146. package/clinkx-workflows/dist/dashboard/session-log-journal.d.ts +43 -0
  147. package/clinkx-workflows/dist/dashboard/session-log-journal.js +529 -0
  148. package/clinkx-workflows/dist/dashboard/session-log-journal.js.map +1 -0
  149. package/clinkx-workflows/dist/dashboard/session-log-reader.d.ts +61 -0
  150. package/clinkx-workflows/dist/dashboard/session-log-reader.js +378 -0
  151. package/clinkx-workflows/dist/dashboard/session-log-reader.js.map +1 -0
  152. package/clinkx-workflows/dist/dashboard/session-log-redaction.d.ts +14 -0
  153. package/clinkx-workflows/dist/dashboard/session-log-redaction.js +1101 -0
  154. package/clinkx-workflows/dist/dashboard/session-log-redaction.js.map +1 -0
  155. package/clinkx-workflows/dist/dashboard/session-log-retention.d.ts +23 -0
  156. package/clinkx-workflows/dist/dashboard/session-log-retention.js +212 -0
  157. package/clinkx-workflows/dist/dashboard/session-log-retention.js.map +1 -0
  158. package/clinkx-workflows/dist/dashboard/static-responses.d.ts +10 -0
  159. package/clinkx-workflows/dist/dashboard/static-responses.js +94 -0
  160. package/clinkx-workflows/dist/dashboard/static-responses.js.map +1 -0
  161. package/clinkx-workflows/dist/dashboard/worker-lock-observer.d.ts +28 -0
  162. package/clinkx-workflows/dist/dashboard/worker-lock-observer.js +241 -0
  163. package/clinkx-workflows/dist/dashboard/worker-lock-observer.js.map +1 -0
  164. package/clinkx-workflows/dist/dashboard-ui/assets/ibm-plex-mono-latin-400-normal-CvHOgSBP.woff +0 -0
  165. package/clinkx-workflows/dist/dashboard-ui/assets/ibm-plex-mono-latin-400-normal-DMJ8VG8y.woff2 +0 -0
  166. package/clinkx-workflows/dist/dashboard-ui/assets/ibm-plex-mono-latin-500-normal-CB9ihrfo.woff +0 -0
  167. package/clinkx-workflows/dist/dashboard-ui/assets/ibm-plex-mono-latin-500-normal-DSY6xOcd.woff2 +0 -0
  168. package/clinkx-workflows/dist/dashboard-ui/assets/ibm-plex-sans-latin-400-normal-CDDApCn2.woff2 +0 -0
  169. package/clinkx-workflows/dist/dashboard-ui/assets/ibm-plex-sans-latin-400-normal-CYLoc0-x.woff +0 -0
  170. package/clinkx-workflows/dist/dashboard-ui/assets/ibm-plex-sans-latin-500-normal-6ng42L7E.woff2 +0 -0
  171. package/clinkx-workflows/dist/dashboard-ui/assets/ibm-plex-sans-latin-500-normal-BgVn5rGT.woff +0 -0
  172. package/clinkx-workflows/dist/dashboard-ui/assets/ibm-plex-sans-latin-600-normal-Cu4Hd6ag.woff +0 -0
  173. package/clinkx-workflows/dist/dashboard-ui/assets/ibm-plex-sans-latin-600-normal-CuJfVYMP.woff2 +0 -0
  174. package/clinkx-workflows/dist/dashboard-ui/assets/index-JPHQVtn9.js +106 -0
  175. package/clinkx-workflows/dist/dashboard-ui/assets/jetbrains-mono-latin-400-normal-6-qcROiO.woff +0 -0
  176. package/clinkx-workflows/dist/dashboard-ui/assets/jetbrains-mono-latin-400-normal-V6pRDFza.woff2 +0 -0
  177. package/clinkx-workflows/dist/dashboard-ui/assets/jetbrains-mono-latin-500-normal-BWZEU5yA.woff2 +0 -0
  178. package/clinkx-workflows/dist/dashboard-ui/assets/jetbrains-mono-latin-500-normal-CJOVTJB7.woff +0 -0
  179. package/clinkx-workflows/dist/dashboard-ui/assets/style-DOMHk-j6.css +1 -0
  180. package/clinkx-workflows/dist/dashboard-ui/contracts/council-plan-review-input-v1.json +158 -0
  181. package/clinkx-workflows/dist/dashboard-ui/index.html +15 -0
  182. package/clinkx-workflows/dist/dashboard-ui/licenses/IBM-Plex-Mono-OFL.txt +93 -0
  183. package/clinkx-workflows/dist/dashboard-ui/licenses/IBM-Plex-Sans-OFL.txt +93 -0
  184. package/clinkx-workflows/dist/dashboard-ui/licenses/JetBrains-Mono-OFL.txt +93 -0
  185. package/clinkx-workflows/dist/dashboard-ui/licenses/NOTICE.md +32 -0
  186. package/clinkx-workflows/dist/dashboard-ui/theme-init.js +8 -0
  187. package/clinkx-workflows/dist/definition-normalizer.d.ts +19 -0
  188. package/clinkx-workflows/dist/definition-normalizer.js.map +1 -1
  189. package/clinkx-workflows/dist/delegate-finalizer-policy.d.ts +26 -0
  190. package/clinkx-workflows/dist/delegate-finalizer-policy.js +72 -0
  191. package/clinkx-workflows/dist/delegate-finalizer-policy.js.map +1 -0
  192. package/clinkx-workflows/dist/delegate-signature.d.ts +14 -0
  193. package/clinkx-workflows/dist/delegate-signature.js +14 -0
  194. package/clinkx-workflows/dist/delegate-signature.js.map +1 -0
  195. package/clinkx-workflows/dist/delegate-validate.d.ts +108 -0
  196. package/clinkx-workflows/dist/delegate-validate.js +148 -0
  197. package/clinkx-workflows/dist/delegate-validate.js.map +1 -0
  198. package/clinkx-workflows/dist/engine.d.ts +251 -0
  199. package/clinkx-workflows/dist/engine.js +1342 -92
  200. package/clinkx-workflows/dist/engine.js.map +1 -1
  201. package/clinkx-workflows/dist/errors.d.ts +24 -2
  202. package/clinkx-workflows/dist/errors.js +30 -2
  203. package/clinkx-workflows/dist/errors.js.map +1 -1
  204. package/clinkx-workflows/dist/fidelity.d.ts +47 -1
  205. package/clinkx-workflows/dist/fidelity.js +54 -1
  206. package/clinkx-workflows/dist/fidelity.js.map +1 -1
  207. package/clinkx-workflows/dist/fingerprint.d.ts +25 -7
  208. package/clinkx-workflows/dist/fingerprint.js +33 -10
  209. package/clinkx-workflows/dist/fingerprint.js.map +1 -1
  210. package/clinkx-workflows/dist/index.d.ts +19 -0
  211. package/clinkx-workflows/dist/index.js +68 -1
  212. package/clinkx-workflows/dist/index.js.map +1 -1
  213. package/clinkx-workflows/dist/loader.d.ts +9 -3
  214. package/clinkx-workflows/dist/loader.js +92 -21
  215. package/clinkx-workflows/dist/loader.js.map +1 -1
  216. package/clinkx-workflows/dist/logger.d.ts +1 -1
  217. package/clinkx-workflows/dist/logger.js +17 -3
  218. package/clinkx-workflows/dist/logger.js.map +1 -1
  219. package/clinkx-workflows/dist/monotonic-clock.d.ts +19 -0
  220. package/clinkx-workflows/dist/monotonic-clock.js +22 -0
  221. package/clinkx-workflows/dist/monotonic-clock.js.map +1 -0
  222. package/clinkx-workflows/dist/plan-review/admission.d.ts +160 -0
  223. package/clinkx-workflows/dist/plan-review/admission.js +290 -0
  224. package/clinkx-workflows/dist/plan-review/admission.js.map +1 -0
  225. package/clinkx-workflows/dist/plan-review/context-policy.d.ts +55 -0
  226. package/clinkx-workflows/dist/plan-review/context-policy.js +146 -0
  227. package/clinkx-workflows/dist/plan-review/context-policy.js.map +1 -0
  228. package/clinkx-workflows/dist/plan-review/contract.d.ts +763 -0
  229. package/clinkx-workflows/dist/plan-review/contract.js +289 -0
  230. package/clinkx-workflows/dist/plan-review/contract.js.map +1 -0
  231. package/clinkx-workflows/dist/plan-review/digest.d.ts +68 -0
  232. package/clinkx-workflows/dist/plan-review/digest.js +241 -0
  233. package/clinkx-workflows/dist/plan-review/digest.js.map +1 -0
  234. package/clinkx-workflows/dist/plan-review/discovery.d.ts +45 -0
  235. package/clinkx-workflows/dist/plan-review/discovery.js +36 -0
  236. package/clinkx-workflows/dist/plan-review/discovery.js.map +1 -0
  237. package/clinkx-workflows/dist/plan-review/execution-contract.d.ts +298 -0
  238. package/clinkx-workflows/dist/plan-review/execution-contract.js +194 -0
  239. package/clinkx-workflows/dist/plan-review/execution-contract.js.map +1 -0
  240. package/clinkx-workflows/dist/plan-review/expander.d.ts +48 -0
  241. package/clinkx-workflows/dist/plan-review/expander.js +243 -0
  242. package/clinkx-workflows/dist/plan-review/expander.js.map +1 -0
  243. package/clinkx-workflows/dist/plan-review/projector.d.ts +126 -0
  244. package/clinkx-workflows/dist/plan-review/projector.js +437 -0
  245. package/clinkx-workflows/dist/plan-review/projector.js.map +1 -0
  246. package/clinkx-workflows/dist/plan-review/publication.d.ts +95 -0
  247. package/clinkx-workflows/dist/plan-review/publication.js +182 -0
  248. package/clinkx-workflows/dist/plan-review/publication.js.map +1 -0
  249. package/clinkx-workflows/dist/plan-review/ranking-reducer.d.ts +34 -0
  250. package/clinkx-workflows/dist/plan-review/ranking-reducer.js +139 -0
  251. package/clinkx-workflows/dist/plan-review/ranking-reducer.js.map +1 -0
  252. package/clinkx-workflows/dist/plan-review/resume.d.ts +38 -0
  253. package/clinkx-workflows/dist/plan-review/resume.js +122 -0
  254. package/clinkx-workflows/dist/plan-review/resume.js.map +1 -0
  255. package/clinkx-workflows/dist/plan-review/rubric.d.ts +7 -0
  256. package/clinkx-workflows/dist/plan-review/rubric.js +24 -0
  257. package/clinkx-workflows/dist/plan-review/rubric.js.map +1 -0
  258. package/clinkx-workflows/dist/plan-review/run-state.d.ts +398 -0
  259. package/clinkx-workflows/dist/plan-review/run-state.js +183 -0
  260. package/clinkx-workflows/dist/plan-review/run-state.js.map +1 -0
  261. package/clinkx-workflows/dist/plan-review/runtime-policy.d.ts +74 -0
  262. package/clinkx-workflows/dist/plan-review/runtime-policy.js +186 -0
  263. package/clinkx-workflows/dist/plan-review/runtime-policy.js.map +1 -0
  264. package/clinkx-workflows/dist/plan-review/snapshot.d.ts +81 -0
  265. package/clinkx-workflows/dist/plan-review/snapshot.js +170 -0
  266. package/clinkx-workflows/dist/plan-review/snapshot.js.map +1 -0
  267. package/clinkx-workflows/dist/plan-review/stage-error.d.ts +19 -0
  268. package/clinkx-workflows/dist/plan-review/stage-error.js +20 -0
  269. package/clinkx-workflows/dist/plan-review/stage-error.js.map +1 -0
  270. package/clinkx-workflows/dist/post-processors/index.d.ts +20 -0
  271. package/clinkx-workflows/dist/post-processors/index.js +21 -0
  272. package/clinkx-workflows/dist/post-processors/index.js.map +1 -0
  273. package/clinkx-workflows/dist/prompt-budget.d.ts +7 -0
  274. package/clinkx-workflows/dist/prompt-budget.js +7 -1
  275. package/clinkx-workflows/dist/prompt-budget.js.map +1 -1
  276. package/clinkx-workflows/dist/reducers/index.js +2 -0
  277. package/clinkx-workflows/dist/reducers/index.js.map +1 -1
  278. package/clinkx-workflows/dist/roster-contract.d.ts +889 -0
  279. package/clinkx-workflows/dist/roster-contract.js +180 -0
  280. package/clinkx-workflows/dist/roster-contract.js.map +1 -0
  281. package/clinkx-workflows/dist/rosters.d.ts +14 -0
  282. package/clinkx-workflows/dist/rosters.js +169 -0
  283. package/clinkx-workflows/dist/rosters.js.map +1 -0
  284. package/clinkx-workflows/dist/run-health.d.ts +7 -0
  285. package/clinkx-workflows/dist/run-health.js +25 -0
  286. package/clinkx-workflows/dist/run-health.js.map +1 -0
  287. package/clinkx-workflows/dist/run-lock-heartbeat.d.ts +2 -0
  288. package/clinkx-workflows/dist/run-lock-heartbeat.js +3 -0
  289. package/clinkx-workflows/dist/run-lock-heartbeat.js.map +1 -0
  290. package/clinkx-workflows/dist/run-summary/cards/council-plan-review.d.ts +34 -0
  291. package/clinkx-workflows/dist/run-summary/cards/council-plan-review.js +74 -0
  292. package/clinkx-workflows/dist/run-summary/cards/council-plan-review.js.map +1 -0
  293. package/clinkx-workflows/dist/run-summary/cards/index.js +5 -0
  294. package/clinkx-workflows/dist/run-summary/cards/index.js.map +1 -1
  295. package/clinkx-workflows/dist/run-summary.d.ts +13 -0
  296. package/clinkx-workflows/dist/run-summary.js +29 -1
  297. package/clinkx-workflows/dist/run-summary.js.map +1 -1
  298. package/clinkx-workflows/dist/schema.d.ts +140 -21
  299. package/clinkx-workflows/dist/schema.js +34 -1
  300. package/clinkx-workflows/dist/schema.js.map +1 -1
  301. package/clinkx-workflows/dist/seed-terms.d.ts +30 -0
  302. package/clinkx-workflows/dist/seed-terms.js +176 -0
  303. package/clinkx-workflows/dist/seed-terms.js.map +1 -0
  304. package/clinkx-workflows/dist/server.d.ts +5 -2
  305. package/clinkx-workflows/dist/server.js +84 -52
  306. package/clinkx-workflows/dist/server.js.map +1 -1
  307. package/clinkx-workflows/dist/shutdown.d.ts +29 -18
  308. package/clinkx-workflows/dist/shutdown.js +90 -64
  309. package/clinkx-workflows/dist/shutdown.js.map +1 -1
  310. package/clinkx-workflows/dist/state-schema.d.ts +61 -0
  311. package/clinkx-workflows/dist/state.d.ts +175 -3
  312. package/clinkx-workflows/dist/state.js +1398 -44
  313. package/clinkx-workflows/dist/state.js.map +1 -1
  314. package/clinkx-workflows/dist/stdio-watchdog.d.ts +52 -0
  315. package/clinkx-workflows/dist/stdio-watchdog.js +212 -0
  316. package/clinkx-workflows/dist/stdio-watchdog.js.map +1 -0
  317. package/clinkx-workflows/dist/transport.d.ts +15 -0
  318. package/clinkx-workflows/dist/transport.js +19 -10
  319. package/clinkx-workflows/dist/transport.js.map +1 -1
  320. package/clinkx-workflows/dist/types.d.ts +20 -2
  321. package/clinkx-workflows/dist/validators/council.d.ts +334 -101
  322. package/clinkx-workflows/dist/validators/council.js +52 -13
  323. package/clinkx-workflows/dist/validators/council.js.map +1 -1
  324. package/clinkx-workflows/dist/validators/index.d.ts +1 -0
  325. package/clinkx-workflows/dist/validators/index.js +3 -0
  326. package/clinkx-workflows/dist/validators/index.js.map +1 -1
  327. package/clinkx-workflows/dist/validators/plan-review.d.ts +398 -0
  328. package/clinkx-workflows/dist/validators/plan-review.js +316 -0
  329. package/clinkx-workflows/dist/validators/plan-review.js.map +1 -0
  330. package/clinkx-workflows/dist/workflow-receipt.js +188 -4
  331. package/clinkx-workflows/dist/workflow-receipt.js.map +1 -1
  332. package/clinkx-workflows/dist/workflow-tools.d.ts +118 -3
  333. package/clinkx-workflows/dist/workflow-tools.js +2110 -175
  334. package/clinkx-workflows/dist/workflow-tools.js.map +1 -1
  335. package/clinkx-workflows/dist/workspace-signature.d.ts +16 -0
  336. package/clinkx-workflows/dist/workspace-signature.js +388 -0
  337. package/clinkx-workflows/dist/workspace-signature.js.map +1 -0
  338. package/clinkx-workflows/templates/council/answer-chairman.txt +3 -0
  339. package/clinkx-workflows/templates/council/answer-cross-reviewer.txt +3 -0
  340. package/clinkx-workflows/templates/council/answer-specialist.txt +5 -1
  341. package/clinkx-workflows/templates/council/chairman.txt +3 -0
  342. package/clinkx-workflows/templates/council/code-review-chairman.txt +16 -0
  343. package/clinkx-workflows/templates/council/code-review-cross-reviewer.txt +7 -1
  344. package/clinkx-workflows/templates/council/code-review-reviewer.txt +22 -3
  345. package/clinkx-workflows/templates/council/debug-chairman.txt +3 -0
  346. package/clinkx-workflows/templates/council/debug-cross-reviewer.txt +3 -0
  347. package/clinkx-workflows/templates/council/debug-debugger.txt +5 -1
  348. package/clinkx-workflows/templates/council/discover-analyst.txt +5 -1
  349. package/clinkx-workflows/templates/council/discover-chairman.txt +3 -0
  350. package/clinkx-workflows/templates/council/discover-cross-reviewer.txt +3 -0
  351. package/clinkx-workflows/templates/council/member.txt +5 -1
  352. package/clinkx-workflows/templates/council/plan-review-chairman.txt +71 -0
  353. package/clinkx-workflows/templates/council/plan-review-cross-reviewer.txt +54 -0
  354. package/clinkx-workflows/templates/council/plan-review-reviewer.txt +63 -0
  355. package/clinkx-workflows/templates/council/reviewer.txt +3 -0
  356. package/clinkx-workflows/templates/plan-review/chairman.txt +48 -0
  357. package/clinkx-workflows/templates/plan-review/cross-review.txt +52 -0
  358. package/clinkx-workflows/templates/plan-review/ranking.txt +16 -0
  359. package/clinkx-workflows/templates/plan-review/reviewer.txt +57 -0
  360. package/clinkx-workflows/workflows/council-answer.yaml +100 -8
  361. package/clinkx-workflows/workflows/council-code-review.yaml +106 -8
  362. package/clinkx-workflows/workflows/council-debug.yaml +100 -8
  363. package/clinkx-workflows/workflows/council-default.yaml +104 -8
  364. package/clinkx-workflows/workflows/council-discover.yaml +100 -8
  365. package/clinkx-workflows/workflows/council-plan-review.yaml +253 -0
  366. package/clinkx-workflows/workflows/plan-review-receipts.yaml +230 -0
  367. package/conf/adapters/agy.json +56 -0
  368. package/conf/adapters/claude.json +12 -0
  369. package/conf/adapters/codex-app-server.json +44 -0
  370. package/conf/adapters/codex.json +14 -2
  371. package/conf/adapters/glm.json +24 -3
  372. package/conf/adapters/grok.json +67 -0
  373. package/conf/adapters/hapi/agy.json +59 -0
  374. package/conf/adapters/hapi/claude.json +12 -0
  375. package/conf/adapters/hapi/codex.json +14 -2
  376. package/conf/adapters/hapi/glm.json +25 -4
  377. package/conf/rosters/default-council.json +21 -0
  378. package/dist/activity-journal.d.ts +56 -0
  379. package/dist/activity-journal.js +706 -0
  380. package/dist/activity-journal.js.map +1 -0
  381. package/dist/allowed-roots.d.ts +41 -0
  382. package/dist/allowed-roots.js +125 -3
  383. package/dist/allowed-roots.js.map +1 -1
  384. package/dist/codex/activity-session-log.d.ts +14 -0
  385. package/dist/codex/activity-session-log.js +206 -0
  386. package/dist/codex/activity-session-log.js.map +1 -0
  387. package/dist/codex/agent-tools.d.ts +23 -0
  388. package/dist/codex/agent-tools.js +1306 -0
  389. package/dist/codex/agent-tools.js.map +1 -0
  390. package/dist/codex/app-server-client.d.ts +79 -0
  391. package/dist/codex/app-server-client.js +593 -0
  392. package/dist/codex/app-server-client.js.map +1 -0
  393. package/dist/codex/app-server-registry.d.ts +407 -0
  394. package/dist/codex/app-server-registry.js +1493 -0
  395. package/dist/codex/app-server-registry.js.map +1 -0
  396. package/dist/codex/client-types.d.ts +115 -0
  397. package/dist/codex/client-types.js +2 -0
  398. package/dist/codex/client-types.js.map +1 -0
  399. package/dist/codex/protocol.d.ts +5375 -0
  400. package/dist/codex/protocol.js +614 -0
  401. package/dist/codex/protocol.js.map +1 -0
  402. package/dist/codex/session.d.ts +263 -0
  403. package/dist/codex/session.js +466 -0
  404. package/dist/codex/session.js.map +1 -0
  405. package/dist/config.d.ts +386 -23
  406. package/dist/config.js +184 -15
  407. package/dist/config.js.map +1 -1
  408. package/dist/context-builder/anchors.d.ts +1 -0
  409. package/dist/context-builder/anchors.js +3 -0
  410. package/dist/context-builder/anchors.js.map +1 -1
  411. package/dist/context-builder/bundle.d.ts +48 -2
  412. package/dist/context-builder/bundle.js +388 -2417
  413. package/dist/context-builder/bundle.js.map +1 -1
  414. package/dist/context-builder/codemap.d.ts +5 -0
  415. package/dist/context-builder/codemap.js +387 -13
  416. package/dist/context-builder/codemap.js.map +1 -1
  417. package/dist/context-builder/config.d.ts +1 -0
  418. package/dist/context-builder/config.js +12 -0
  419. package/dist/context-builder/config.js.map +1 -1
  420. package/dist/context-builder/context-run-catalog.d.ts +17 -0
  421. package/dist/context-builder/context-run-catalog.js +99 -0
  422. package/dist/context-builder/context-run-catalog.js.map +1 -0
  423. package/dist/context-builder/delegate-finalizer-effective.d.ts +33 -0
  424. package/dist/context-builder/delegate-finalizer-effective.js +82 -0
  425. package/dist/context-builder/delegate-finalizer-effective.js.map +1 -0
  426. package/dist/context-builder/delegate-packet.d.ts +55 -0
  427. package/dist/context-builder/delegate-packet.js +430 -74
  428. package/dist/context-builder/delegate-packet.js.map +1 -1
  429. package/dist/context-builder/delegate-reconstruction.d.ts +29 -0
  430. package/dist/context-builder/delegate-reconstruction.js +110 -41
  431. package/dist/context-builder/delegate-reconstruction.js.map +1 -1
  432. package/dist/context-builder/delegate-validation.d.ts +41 -1
  433. package/dist/context-builder/delegate-validation.js +237 -48
  434. package/dist/context-builder/delegate-validation.js.map +1 -1
  435. package/dist/context-builder/delegate.d.ts +11 -0
  436. package/dist/context-builder/delegate.js +210 -58
  437. package/dist/context-builder/delegate.js.map +1 -1
  438. package/dist/context-builder/diagnostics.d.ts +11 -2
  439. package/dist/context-builder/diagnostics.js +39 -6
  440. package/dist/context-builder/diagnostics.js.map +1 -1
  441. package/dist/context-builder/discovery-progress.d.ts +25 -0
  442. package/dist/context-builder/discovery-progress.js +64 -0
  443. package/dist/context-builder/discovery-progress.js.map +1 -0
  444. package/dist/context-builder/discovery-watchdog.d.ts +15 -0
  445. package/dist/context-builder/discovery-watchdog.js +39 -0
  446. package/dist/context-builder/discovery-watchdog.js.map +1 -0
  447. package/dist/context-builder/discovery.d.ts +36 -1
  448. package/dist/context-builder/discovery.js +584 -172
  449. package/dist/context-builder/discovery.js.map +1 -1
  450. package/dist/context-builder/external-gaps.d.ts +73 -0
  451. package/dist/context-builder/external-gaps.js +248 -0
  452. package/dist/context-builder/external-gaps.js.map +1 -0
  453. package/dist/context-builder/globs.d.ts +1 -0
  454. package/dist/context-builder/globs.js +25 -10
  455. package/dist/context-builder/globs.js.map +1 -1
  456. package/dist/context-builder/handler.d.ts +67 -2
  457. package/dist/context-builder/handler.js +1810 -2440
  458. package/dist/context-builder/handler.js.map +1 -1
  459. package/dist/context-builder/invocation-sidecar.d.ts +41 -0
  460. package/dist/context-builder/invocation-sidecar.js +189 -0
  461. package/dist/context-builder/invocation-sidecar.js.map +1 -0
  462. package/dist/context-builder/lifecycle-contract.d.ts +424 -0
  463. package/dist/context-builder/lifecycle-contract.js +523 -0
  464. package/dist/context-builder/lifecycle-contract.js.map +1 -0
  465. package/dist/context-builder/lifecycle-journal.d.ts +62 -0
  466. package/dist/context-builder/lifecycle-journal.js +88 -0
  467. package/dist/context-builder/lifecycle-journal.js.map +1 -0
  468. package/dist/context-builder/lifecycle-observer.d.ts +102 -0
  469. package/dist/context-builder/lifecycle-observer.js +258 -0
  470. package/dist/context-builder/lifecycle-observer.js.map +1 -0
  471. package/dist/context-builder/lifecycle-reconcile.d.ts +32 -0
  472. package/dist/context-builder/lifecycle-reconcile.js +191 -0
  473. package/dist/context-builder/lifecycle-reconcile.js.map +1 -0
  474. package/dist/context-builder/lifecycle-recovery.d.ts +2 -0
  475. package/dist/context-builder/lifecycle-recovery.js +14 -0
  476. package/dist/context-builder/lifecycle-recovery.js.map +1 -0
  477. package/dist/context-builder/mutation-lock.d.ts +32 -0
  478. package/dist/context-builder/mutation-lock.js +321 -0
  479. package/dist/context-builder/mutation-lock.js.map +1 -0
  480. package/dist/context-builder/path-signals.js +9 -5
  481. package/dist/context-builder/path-signals.js.map +1 -1
  482. package/dist/context-builder/progress.d.ts +3 -1
  483. package/dist/context-builder/progress.js +23 -0
  484. package/dist/context-builder/progress.js.map +1 -1
  485. package/dist/context-builder/receipt.d.ts +6 -4
  486. package/dist/context-builder/receipt.js +12 -1
  487. package/dist/context-builder/receipt.js.map +1 -1
  488. package/dist/context-builder/refine-handler.d.ts +14 -0
  489. package/dist/context-builder/refine-handler.js +790 -0
  490. package/dist/context-builder/refine-handler.js.map +1 -0
  491. package/dist/context-builder/review-coverage.d.ts +116 -0
  492. package/dist/context-builder/review-coverage.js +544 -0
  493. package/dist/context-builder/review-coverage.js.map +1 -0
  494. package/dist/context-builder/schema.d.ts +315 -2
  495. package/dist/context-builder/schema.js +133 -7
  496. package/dist/context-builder/schema.js.map +1 -1
  497. package/dist/context-builder/secrets.d.ts +59 -0
  498. package/dist/context-builder/secrets.js +2255 -44
  499. package/dist/context-builder/secrets.js.map +1 -1
  500. package/dist/context-builder/selection.d.ts +7 -3
  501. package/dist/context-builder/selection.js +200 -738
  502. package/dist/context-builder/selection.js.map +1 -1
  503. package/dist/context-builder/session-log-identity.d.ts +1 -0
  504. package/dist/context-builder/session-log-identity.js +66 -0
  505. package/dist/context-builder/session-log-identity.js.map +1 -0
  506. package/dist/context-builder/slice-range-math.d.ts +16 -0
  507. package/dist/context-builder/slice-range-math.js +137 -0
  508. package/dist/context-builder/slice-range-math.js.map +1 -0
  509. package/dist/context-builder/status.d.ts +23 -2
  510. package/dist/context-builder/status.js +60 -4
  511. package/dist/context-builder/status.js.map +1 -1
  512. package/dist/context-builder/storage.d.ts +59 -2
  513. package/dist/context-builder/storage.js +500 -168
  514. package/dist/context-builder/storage.js.map +1 -1
  515. package/dist/context-builder/token-estimate.d.ts +13 -2
  516. package/dist/context-builder/token-estimate.js +77 -4
  517. package/dist/context-builder/token-estimate.js.map +1 -1
  518. package/dist/context-builder/versions.d.ts +44 -0
  519. package/dist/context-builder/versions.js +45 -0
  520. package/dist/context-builder/versions.js.map +1 -0
  521. package/dist/context-builder/workflow-runner.d.ts +75 -0
  522. package/dist/context-builder/workflow-runner.js +1241 -0
  523. package/dist/context-builder/workflow-runner.js.map +1 -0
  524. package/dist/context-builder/write-watchdog.d.ts +14 -0
  525. package/dist/context-builder/write-watchdog.js +38 -0
  526. package/dist/context-builder/write-watchdog.js.map +1 -0
  527. package/dist/dashboard-adapter-catalog.d.ts +9 -0
  528. package/dist/dashboard-adapter-catalog.js +53 -0
  529. package/dist/dashboard-adapter-catalog.js.map +1 -0
  530. package/dist/dashboard-cli.d.ts +81 -0
  531. package/dist/dashboard-cli.js +623 -0
  532. package/dist/dashboard-cli.js.map +1 -0
  533. package/dist/dashboard-companion/client.d.ts +37 -0
  534. package/dist/dashboard-companion/client.js +229 -0
  535. package/dist/dashboard-companion/client.js.map +1 -0
  536. package/dist/dashboard-companion/config.d.ts +8 -0
  537. package/dist/dashboard-companion/config.js +52 -0
  538. package/dist/dashboard-companion/config.js.map +1 -0
  539. package/dist/dashboard-companion/http-proxy.d.ts +10 -0
  540. package/dist/dashboard-companion/http-proxy.js +234 -0
  541. package/dist/dashboard-companion/http-proxy.js.map +1 -0
  542. package/dist/dashboard-companion/protocol.d.ts +80 -0
  543. package/dist/dashboard-companion/protocol.js +458 -0
  544. package/dist/dashboard-companion/protocol.js.map +1 -0
  545. package/dist/dashboard-companion/standalone-assets.d.ts +12 -0
  546. package/dist/dashboard-companion/standalone-assets.js +72 -0
  547. package/dist/dashboard-companion/standalone-assets.js.map +1 -0
  548. package/dist/dashboard-companion/standalone-entry.d.ts +1 -0
  549. package/dist/dashboard-companion/standalone-entry.js +17 -0
  550. package/dist/dashboard-companion/standalone-entry.js.map +1 -0
  551. package/dist/dashboard-gateway/config.d.ts +9 -0
  552. package/dist/dashboard-gateway/config.js +44 -0
  553. package/dist/dashboard-gateway/config.js.map +1 -0
  554. package/dist/dashboard-gateway/index.d.ts +12 -0
  555. package/dist/dashboard-gateway/index.js +786 -0
  556. package/dist/dashboard-gateway/index.js.map +1 -0
  557. package/dist/dashboard-gateway/main.d.ts +1 -0
  558. package/dist/dashboard-gateway/main.js +25 -0
  559. package/dist/dashboard-gateway/main.js.map +1 -0
  560. package/dist/dashboard-pairing-token.d.ts +1 -0
  561. package/dist/dashboard-pairing-token.js +5 -0
  562. package/dist/dashboard-pairing-token.js.map +1 -0
  563. package/dist/elaris/client.d.ts +73 -0
  564. package/dist/elaris/client.js +825 -0
  565. package/dist/elaris/client.js.map +1 -0
  566. package/dist/elaris/config.d.ts +18 -0
  567. package/dist/elaris/config.js +75 -0
  568. package/dist/elaris/config.js.map +1 -0
  569. package/dist/elaris/errors.d.ts +41 -0
  570. package/dist/elaris/errors.js +205 -0
  571. package/dist/elaris/errors.js.map +1 -0
  572. package/dist/elaris/github-repo.d.ts +18 -0
  573. package/dist/elaris/github-repo.js +89 -0
  574. package/dist/elaris/github-repo.js.map +1 -0
  575. package/dist/elaris/index.d.ts +10 -0
  576. package/dist/elaris/index.js +11 -0
  577. package/dist/elaris/index.js.map +1 -0
  578. package/dist/elaris/redact.d.ts +89 -0
  579. package/dist/elaris/redact.js +423 -0
  580. package/dist/elaris/redact.js.map +1 -0
  581. package/dist/elaris/run-id.d.ts +5 -0
  582. package/dist/elaris/run-id.js +20 -0
  583. package/dist/elaris/run-id.js.map +1 -0
  584. package/dist/elaris/status.d.ts +45 -0
  585. package/dist/elaris/status.js +122 -0
  586. package/dist/elaris/status.js.map +1 -0
  587. package/dist/elaris/tool-schemas.d.ts +314 -0
  588. package/dist/elaris/tool-schemas.js +208 -0
  589. package/dist/elaris/tool-schemas.js.map +1 -0
  590. package/dist/elaris/tools.d.ts +73 -0
  591. package/dist/elaris/tools.js +1065 -0
  592. package/dist/elaris/tools.js.map +1 -0
  593. package/dist/elaris/types.d.ts +1541 -0
  594. package/dist/elaris/types.js +252 -0
  595. package/dist/elaris/types.js.map +1 -0
  596. package/dist/errors.d.ts +16 -0
  597. package/dist/errors.js +19 -0
  598. package/dist/errors.js.map +1 -1
  599. package/dist/handler.d.ts +4 -0
  600. package/dist/handler.js +15 -2
  601. package/dist/handler.js.map +1 -1
  602. package/dist/index.d.ts +20 -2
  603. package/dist/index.js +154 -6
  604. package/dist/index.js.map +1 -1
  605. package/dist/local-clink-backend.d.ts +3 -0
  606. package/dist/local-clink-backend.js +4 -0
  607. package/dist/local-clink-backend.js.map +1 -1
  608. package/dist/logger.d.ts +1 -1
  609. package/dist/logger.js +18 -3
  610. package/dist/logger.js.map +1 -1
  611. package/dist/package-info.d.ts +2 -0
  612. package/dist/package-info.js +18 -0
  613. package/dist/package-info.js.map +1 -0
  614. package/dist/parsers/agy-stream-json.d.ts +14 -0
  615. package/dist/parsers/agy-stream-json.js +172 -0
  616. package/dist/parsers/agy-stream-json.js.map +1 -0
  617. package/dist/parsers/codex-jsonl.js +48 -3
  618. package/dist/parsers/codex-jsonl.js.map +1 -1
  619. package/dist/parsers/extract.d.ts +10 -1
  620. package/dist/parsers/extract.js +16 -4
  621. package/dist/parsers/extract.js.map +1 -1
  622. package/dist/parsers/observed-invocation.d.ts +20 -0
  623. package/dist/parsers/observed-invocation.js +42 -0
  624. package/dist/parsers/observed-invocation.js.map +1 -0
  625. package/dist/pipeline.d.ts +17 -0
  626. package/dist/pipeline.js +181 -10
  627. package/dist/pipeline.js.map +1 -1
  628. package/dist/progress-report/lock.d.ts +74 -0
  629. package/dist/progress-report/lock.js +343 -0
  630. package/dist/progress-report/lock.js.map +1 -0
  631. package/dist/progress-report/schema.d.ts +808 -0
  632. package/dist/progress-report/schema.js +119 -0
  633. package/dist/progress-report/schema.js.map +1 -0
  634. package/dist/progress-report/store.d.ts +66 -0
  635. package/dist/progress-report/store.js +766 -0
  636. package/dist/progress-report/store.js.map +1 -0
  637. package/dist/progress-report/tools.d.ts +20 -0
  638. package/dist/progress-report/tools.js +141 -0
  639. package/dist/progress-report/tools.js.map +1 -0
  640. package/dist/prompt-mode.d.ts +1 -1
  641. package/dist/prompt-mode.js +7 -2
  642. package/dist/prompt-mode.js.map +1 -1
  643. package/dist/run-dir.d.ts +24 -0
  644. package/dist/run-dir.js +201 -2
  645. package/dist/run-dir.js.map +1 -1
  646. package/dist/runner.d.ts +20 -0
  647. package/dist/runner.js +192 -16
  648. package/dist/runner.js.map +1 -1
  649. package/dist/safety.d.ts +54 -4
  650. package/dist/safety.js +186 -5
  651. package/dist/safety.js.map +1 -1
  652. package/dist/schema.d.ts +15 -7
  653. package/dist/schema.js +20 -0
  654. package/dist/schema.js.map +1 -1
  655. package/dist/server.d.ts +7 -1
  656. package/dist/server.js +451 -23
  657. package/dist/server.js.map +1 -1
  658. package/dist/session-log-stream.d.ts +18 -0
  659. package/dist/session-log-stream.js +566 -0
  660. package/dist/session-log-stream.js.map +1 -0
  661. package/dist/stdio-activity.d.ts +28 -0
  662. package/dist/stdio-activity.js +72 -0
  663. package/dist/stdio-activity.js.map +1 -0
  664. package/package.json +47 -5
  665. package/conf/adapters/gemini.json +0 -44
  666. package/conf/adapters/hapi/gemini.json +0 -47
  667. package/dist/parsers/gemini-json.d.ts +0 -2
  668. package/dist/parsers/gemini-json.js +0 -72
  669. package/dist/parsers/gemini-json.js.map +0 -1
@@ -1,4 +1,4 @@
1
- import { link as fsLink, open as fsOpen, mkdir as fsMkdir, readFile as fsReadFile, rename as fsRename, rm as fsRm, stat as fsStat, writeFile as fsWriteFile, } from "node:fs/promises";
1
+ import { link as fsLink, lstat as fsLstat, open as fsOpen, mkdir as fsMkdir, readdir as fsReaddir, readFile as fsReadFile, rename as fsRename, rm as fsRm, stat as fsStat, writeFile as fsWriteFile, } from "node:fs/promises";
2
2
  import { randomBytes } from "node:crypto";
3
3
  import { hostname } from "node:os";
4
4
  import { basename, dirname, isAbsolute, join, relative, resolve } from "node:path";
@@ -6,12 +6,15 @@ import { CancellationError, ExecutionError, InvalidParamsError } from "../errors
6
6
  import { validateProspectiveChildPath } from "../paths.js";
7
7
  import { contextBuilderInternalCapsForManifest, CONTEXT_BUILDER_INTERNAL_CAP_DEFAULTS, resolveContextBuilderRunsDir, } from "./config.js";
8
8
  import { boundContextBuilderOmissions, boundContextBuilderWarnings, } from "./diagnostics.js";
9
- import { cloneContextBuilderDelegateReceiptMetadata, CONTEXT_BUILDER_DELEGATE_SCHEMA_VERSION, CONTEXT_BUILDER_NO_DELEGATE_ARTIFACT_KEYS, CONTEXT_BUILDER_NO_DELEGATE_SCHEMA_VERSION, CONTEXT_BUILDER_SCHEMA_VERSION, isContextBuilderDelegateReceiptMetadata, } from "./receipt.js";
9
+ import { cloneContextBuilderDelegateReceiptMetadata, CONTEXT_BUILDER_DELEGATE_SCHEMA_VERSION, CONTEXT_BUILDER_LEGACY_ARTIFACT_KEYS, CONTEXT_BUILDER_NO_DELEGATE_ARTIFACT_KEYS, CONTEXT_BUILDER_NO_DELEGATE_SCHEMA_VERSION, CONTEXT_BUILDER_SCHEMA_VERSION, isContextBuilderDelegateReceiptMetadata, } from "./receipt.js";
10
10
  import { validateCallerRunId } from "./run-id.js";
11
11
  import { scanSecretPath } from "./secrets.js";
12
+ import { CONTEXT_BUILDER_INVOCATION_AUDIT_FILENAME, readContextBuilderInvocationAuditSidecar, } from "./invocation-sidecar.js";
13
+ import { withContextBuilderMutationLock, } from "./mutation-lock.js";
12
14
  export const CONTEXT_BUILDER_ARTIFACT_FILE_NAMES = Object.freeze({
13
15
  manifest_json: "manifest.json",
14
16
  bundle_md: "bundle.md",
17
+ selected_context_jsonl: "selected-context.jsonl",
15
18
  tree_json: "tree.json",
16
19
  search_jsonl: "search.jsonl",
17
20
  slices_jsonl: "slices.jsonl",
@@ -25,8 +28,10 @@ const DEFAULT_STORAGE_OPS = {
25
28
  rename: fsRename,
26
29
  rm: fsRm,
27
30
  open: fsOpen,
31
+ lstat: fsLstat,
28
32
  link: fsLink,
29
33
  stat: fsStat,
34
+ readdir: fsReaddir,
30
35
  };
31
36
  const CONTEXT_BUILDER_METRIC_TYPES = Object.freeze({
32
37
  files_seen: "number",
@@ -44,10 +49,38 @@ const CONTEXT_BUILDER_METRIC_TYPES = Object.freeze({
44
49
  truncated: "boolean",
45
50
  });
46
51
  const CONTEXT_BUILDER_INTERNAL_CAP_KEYS = Object.keys(CONTEXT_BUILDER_INTERNAL_CAP_DEFAULTS);
47
- const CONTEXT_BUILDER_MUTATION_LOCK_SUFFIX = ".mutation.lock";
48
- const CONTEXT_BUILDER_MUTATION_LOCK_ATTEMPTS = 1_000;
49
- const CONTEXT_BUILDER_MUTATION_LOCK_RETRY_MS = 10;
50
- const CONTEXT_BUILDER_STALE_MUTATION_LOCK_MS = 10 * 60 * 1_000;
52
+ export const WORKFLOW_CONTEXT_CACHE_MAX_ENTRIES_ENV = "CLINKX_WORKFLOWS_CONTEXT_CACHE_MAX_ENTRIES";
53
+ export const WORKFLOW_CONTEXT_CACHE_TTL_SECONDS_ENV = "CLINKX_WORKFLOWS_CONTEXT_CACHE_TTL_SECONDS";
54
+ export const DEFAULT_WORKFLOW_CONTEXT_CACHE_MAX_ENTRIES = 50;
55
+ export const DEFAULT_WORKFLOW_CONTEXT_CACHE_TTL_SECONDS = 86_400;
56
+ const DEFAULT_WORKFLOW_CONTEXT_TEMP_TTL_SECONDS = 3_600;
57
+ export class ContextBuilderAncillaryPromotionError extends ExecutionError {
58
+ reasonCode;
59
+ constructor(reasonCode) {
60
+ super("context_builder invocation audit ancillary promotion failed");
61
+ this.name = "ContextBuilderAncillaryPromotionError";
62
+ this.reasonCode = reasonCode;
63
+ }
64
+ }
65
+ export class ContextBuilderRunClaimConflictError extends InvalidParamsError {
66
+ constructor(runId) {
67
+ super(`context_builder run_id already exists: ${runId}`);
68
+ this.name = "ContextBuilderRunClaimConflictError";
69
+ }
70
+ }
71
+ export class ContextBuilderActiveRunClaimConflictError extends ExecutionError {
72
+ constructor(runId) {
73
+ super(`context_builder run_id conflicts with an incomplete or active run: ${runId}`);
74
+ this.name = "ContextBuilderActiveRunClaimConflictError";
75
+ }
76
+ }
77
+ export class ContextBuilderCommittedRunChangedError extends ExecutionError {
78
+ constructor(runId) {
79
+ super(`context_builder committed run changed before lease admission: ${runId}`);
80
+ this.name = "ContextBuilderCommittedRunChangedError";
81
+ }
82
+ }
83
+ const HELD_CONTEXT_BUILDER_MUTATION_LOCKS = Symbol("heldContextBuilderMutationLocks");
51
84
  export function resolveContextBuilderRunPaths(runsDir, runId) {
52
85
  validateCallerRunId(runId);
53
86
  const resolvedRunsDir = resolve(runsDir);
@@ -112,7 +145,7 @@ export async function createContextBuilderRun(input, ops = DEFAULT_STORAGE_OPS)
112
145
  }
113
146
  export async function writeContextBuilderArtifact(storage, key, content, ops = DEFAULT_STORAGE_OPS) {
114
147
  const canonicalStorage = canonicalizeContextBuilderStorage(storage);
115
- await withContextBuilderMutationLock(canonicalStorage, ops, async () => {
148
+ await withContextBuilderStorageMutationLock(canonicalStorage, ops, async () => {
116
149
  await assertManifestAbsentForMutation(canonicalStorage, ops);
117
150
  await writeAtomicText(canonicalStorage.artifacts[key], content, ops, {
118
151
  mustNotExistPath: canonicalStorage.manifestJson,
@@ -123,7 +156,7 @@ export async function commitContextBuilderRun(storage, manifest, optionsOrOps =
123
156
  const { options, ops } = normalizeCommitArguments(optionsOrOps, maybeOps);
124
157
  const canonicalStorage = canonicalizeContextBuilderStorage(storage);
125
158
  const ownerNonce = options.ownerNonce ?? canonicalStorage.ownerNonce;
126
- await withContextBuilderMutationLock(canonicalStorage, ops, async () => {
159
+ await withContextBuilderStorageMutationLock(canonicalStorage, ops, async () => {
127
160
  await assertManifestAbsentForMutation(canonicalStorage, ops);
128
161
  await assertRequiredArtifactsReadable(canonicalStorage, ops);
129
162
  throwIfCancelledBeforeManifest(options);
@@ -147,7 +180,7 @@ export async function writeContextBuilderArtifactsAndCommit(storage, contents, m
147
180
  const ops = options.ops ?? DEFAULT_STORAGE_OPS;
148
181
  const canonicalStorage = canonicalizeContextBuilderStorage(storage);
149
182
  const ownerNonce = options.ownerNonce ?? canonicalStorage.ownerNonce;
150
- await withContextBuilderMutationLock(canonicalStorage, ops, async () => {
183
+ await withContextBuilderStorageMutationLock(canonicalStorage, ops, async () => {
151
184
  await assertManifestAbsentForMutation(canonicalStorage, ops);
152
185
  for (const [key, content] of Object.entries(contents)) {
153
186
  if (options.signal?.aborted === true) {
@@ -157,6 +190,7 @@ export async function writeContextBuilderArtifactsAndCommit(storage, contents, m
157
190
  }
158
191
  throwIfCancelledBeforeManifest(options.signal === undefined ? {} : { signal: options.signal });
159
192
  await assertRequiredArtifactsReadable(canonicalStorage, ops);
193
+ await options.beforeManifestCommit?.();
160
194
  const internalCaps = contextBuilderInternalCapsForManifest(manifest.internal_caps);
161
195
  const { delegate, ...manifestWithoutDelegate } = manifest;
162
196
  const boundedDelegate = normalizeManifestDelegateMetadata(delegate);
@@ -173,13 +207,358 @@ export async function writeContextBuilderArtifactsAndCommit(storage, contents, m
173
207
  await writeExclusiveText(canonicalStorage.manifestJson, `${JSON.stringify(completeManifest)}\n`, ops, options.signal === undefined ? {} : { signal: options.signal });
174
208
  }, { ownerNonce });
175
209
  }
210
+ export async function promoteContextBuilderRun(tempRunDir, targetRunId, ops = DEFAULT_STORAGE_OPS) {
211
+ return await withPromotedContextBuilderRun(tempRunDir, targetRunId, async (storage) => storage, ops);
212
+ }
213
+ /**
214
+ * Acquire source before target, then retain the target lease through its
215
+ * caller's manifest re-read and materialization callback.
216
+ */
217
+ export async function withPromotedContextBuilderRun(tempRunDir, targetRunId, callback, ops = DEFAULT_STORAGE_OPS) {
218
+ const resolvedTempRunDir = resolve(tempRunDir);
219
+ const tempStorage = resolveContextBuilderRunPaths(dirname(resolvedTempRunDir), basename(resolvedTempRunDir));
220
+ return await withCommittedContextBuilderRunMutationLease(tempStorage, async (sourceOps) => {
221
+ const tempManifest = await readContextBuilderManifest(tempStorage.manifestJson, sourceOps);
222
+ if (tempStorage.runDir !== resolvedTempRunDir
223
+ || tempManifest.run_id !== tempStorage.runId) {
224
+ throw new ExecutionError("context_builder cannot promote an uncommitted or mismatched temp run");
225
+ }
226
+ let invocationAudit;
227
+ try {
228
+ invocationAudit = await readContextBuilderInvocationAuditSidecar(tempStorage.runDir);
229
+ }
230
+ catch {
231
+ throw new ContextBuilderAncillaryPromotionError("invalid_source");
232
+ }
233
+ const targetStorage = resolveContextBuilderRunPaths(tempStorage.runsDir, targetRunId);
234
+ await claimContextBuilderRunDir(targetStorage, sourceOps);
235
+ let targetCommitted = false;
236
+ try {
237
+ await sourceOps.mkdir(targetStorage.artifactDir, { recursive: false, mode: 0o700 });
238
+ return await withContextBuilderStorageMutationLock(targetStorage, sourceOps, async (targetOps) => {
239
+ await assertManifestAbsentForMutation(targetStorage, targetOps);
240
+ const artifactEntries = Object.entries(tempManifest.artifacts);
241
+ for (const [key, sourcePath] of artifactEntries) {
242
+ if (key === "manifest_json") {
243
+ continue;
244
+ }
245
+ const targetPath = targetStorage.artifacts[key];
246
+ const sourceContent = await targetOps.readFile(sourcePath, "utf8");
247
+ const targetContent = key === "summary_json"
248
+ ? rewriteContextBuilderSummaryRunId(sourceContent, targetRunId)
249
+ : sourceContent;
250
+ await writeAtomicText(targetPath, targetContent, targetOps, {
251
+ mustNotExistPath: targetStorage.manifestJson,
252
+ });
253
+ }
254
+ if (invocationAudit !== undefined) {
255
+ try {
256
+ await writeAtomicText(join(targetStorage.runDir, CONTEXT_BUILDER_INVOCATION_AUDIT_FILENAME), invocationAudit.serialized, targetOps, { mustNotExistPath: targetStorage.manifestJson });
257
+ }
258
+ catch {
259
+ throw new ContextBuilderAncillaryPromotionError("copy_failed");
260
+ }
261
+ }
262
+ const targetArtifacts = Object.fromEntries(Object.keys(tempManifest.artifacts).map((key) => [
263
+ key,
264
+ targetStorage.artifacts[key],
265
+ ]));
266
+ const targetManifest = {
267
+ ...tempManifest,
268
+ run_id: targetRunId,
269
+ artifacts: targetArtifacts,
270
+ };
271
+ await writeExclusiveText(targetStorage.manifestJson, `${JSON.stringify(targetManifest)}\n`, targetOps);
272
+ if (!await isContextBuilderRunCommitted(targetStorage.runDir, targetOps)) {
273
+ throw new ExecutionError(`context_builder promoted run failed validation: ${targetRunId}`);
274
+ }
275
+ targetCommitted = true;
276
+ await (targetOps.rm ?? fsRm)(resolvedTempRunDir, { recursive: true, force: true }).catch(() => { });
277
+ await syncDirectoryBestEffort(tempStorage.runsDir, targetOps);
278
+ return await callback(targetStorage, targetOps);
279
+ });
280
+ }
281
+ catch (error) {
282
+ if (!targetCommitted) {
283
+ // This call claimed the uncommitted target, so it owns cleanup.
284
+ await (sourceOps.rm ?? fsRm)(targetStorage.runDir, {
285
+ recursive: true,
286
+ force: true,
287
+ }).catch(() => { });
288
+ await syncDirectoryBestEffort(targetStorage.runsDir, sourceOps);
289
+ }
290
+ throw error;
291
+ }
292
+ }, ops);
293
+ }
294
+ export async function evictWorkflowContextRuns(runsDir, options = {}) {
295
+ const ops = options.ops ?? DEFAULT_STORAGE_OPS;
296
+ const readdir = ops.readdir ?? fsReaddir;
297
+ const resolvedRunsDir = await resolveContextBuilderRunsDir(runsDir);
298
+ const bounds = resolveWorkflowContextEvictionBounds(options);
299
+ const nowMs = options.nowMs ?? Date.now();
300
+ const protectedRunIds = new Set(options.protectedRunIds ?? []);
301
+ const entries = await readdir(resolvedRunsDir, { withFileTypes: true });
302
+ const committedCacheEntries = [];
303
+ const removeSet = new Map();
304
+ let scanned = 0;
305
+ let skipped = 0;
306
+ let failed = 0;
307
+ for (const entry of entries) {
308
+ if (!entry.isDirectory() || !isWorkflowContextRunId(entry.name)) {
309
+ continue;
310
+ }
311
+ scanned += 1;
312
+ try {
313
+ const storage = resolveContextBuilderRunPaths(resolvedRunsDir, entry.name);
314
+ const directoryAdmission = await admitContextBuilderRunDirectory(storage, ops);
315
+ if (directoryAdmission === undefined) {
316
+ skipped += 1;
317
+ continue;
318
+ }
319
+ const admission = await admitCommittedContextBuilderRun(storage, ops);
320
+ if (admission === undefined) {
321
+ skipped += 1;
322
+ continue;
323
+ }
324
+ const currentDirectoryAdmission = await admitContextBuilderRunDirectory(storage, ops);
325
+ if (currentDirectoryAdmission === undefined
326
+ || !contextBuilderRunDirectoryAdmissionsEqual(directoryAdmission, currentDirectoryAdmission)) {
327
+ skipped += 1;
328
+ continue;
329
+ }
330
+ const mtimeMs = Number(directoryAdmission.mtimeNs) / 1_000_000;
331
+ const candidate = {
332
+ storage,
333
+ mtimeMs,
334
+ admission,
335
+ directoryAdmission,
336
+ };
337
+ const isProtected = protectedRunIds.has(storage.runId);
338
+ if (entry.name.startsWith("wfctx-")) {
339
+ // Protected cache entries are excluded from LRU survivor accounting so
340
+ // they can never be selected for the max-entries trim below either.
341
+ if (!isProtected) {
342
+ committedCacheEntries.push(candidate);
343
+ }
344
+ if (nowMs - mtimeMs > bounds.cacheTtlMs) {
345
+ if (isProtected) {
346
+ skipped += 1;
347
+ }
348
+ else {
349
+ removeSet.set(storage.runId, candidate);
350
+ }
351
+ }
352
+ continue;
353
+ }
354
+ if (nowMs - mtimeMs > bounds.tempTtlMs) {
355
+ if (isProtected) {
356
+ skipped += 1;
357
+ }
358
+ else {
359
+ removeSet.set(storage.runId, candidate);
360
+ }
361
+ }
362
+ }
363
+ catch {
364
+ failed += 1;
365
+ }
366
+ }
367
+ const cacheSurvivors = committedCacheEntries
368
+ .filter(({ storage }) => !removeSet.has(storage.runId))
369
+ .sort((a, b) => a.mtimeMs - b.mtimeMs);
370
+ cacheSurvivors
371
+ .slice(0, Math.max(0, cacheSurvivors.length - bounds.maxEntries))
372
+ .forEach((candidate) => {
373
+ removeSet.set(candidate.storage.runId, candidate);
374
+ });
375
+ let evicted = 0;
376
+ for (const { storage, admission, directoryAdmission } of removeSet.values()) {
377
+ try {
378
+ const didRemove = await removeCommittedWorkflowContextRun(storage, admission, directoryAdmission, ops);
379
+ if (didRemove) {
380
+ evicted += 1;
381
+ }
382
+ else {
383
+ skipped += 1;
384
+ }
385
+ }
386
+ catch (error) {
387
+ if (isNodeError(error) && error.code === "ENOENT") {
388
+ skipped += 1;
389
+ }
390
+ else {
391
+ failed += 1;
392
+ }
393
+ }
394
+ }
395
+ if (evicted > 0) {
396
+ await syncDirectoryBestEffort(resolvedRunsDir, ops);
397
+ }
398
+ return { scanned, evicted, skipped, failed };
399
+ }
176
400
  export async function cleanupContextBuilderIncompleteRun(storage, ownerNonce, ops = DEFAULT_STORAGE_OPS) {
177
401
  const canonicalStorage = canonicalizeContextBuilderStorage(storage);
178
- return withContextBuilderMutationLock(canonicalStorage, ops, async () => cleanupContextBuilderIncompleteRunLocked(canonicalStorage, ownerNonce, ops), {
402
+ return withContextBuilderStorageMutationLock(canonicalStorage, ops, async () => cleanupContextBuilderIncompleteRunLocked(canonicalStorage, ownerNonce, ops), {
179
403
  ownerNonce,
180
- recoverStaleForCleanup: true,
404
+ canRecoverStale: async () => (await canRemoveIncompleteRunDir(canonicalStorage, ownerNonce, ops)).removable,
181
405
  });
182
406
  }
407
+ /** Hold one run's mutation lock, reusing it for nested storage operations. */
408
+ export async function withContextBuilderRunMutationLease(storage, callback, ops = DEFAULT_STORAGE_OPS, options = {}) {
409
+ const canonicalStorage = canonicalizeContextBuilderStorage(storage);
410
+ const effectiveOps = ops ?? DEFAULT_STORAGE_OPS;
411
+ return await withContextBuilderStorageMutationLock(canonicalStorage, effectiveOps, callback, options);
412
+ }
413
+ /**
414
+ * Admit one exact committed-run incarnation, recover only a stale lock bound to
415
+ * that admission, and recheck the manifest after acquiring the lease.
416
+ */
417
+ export async function withCommittedContextBuilderRunMutationLease(storage, callback, ops = DEFAULT_STORAGE_OPS) {
418
+ const canonicalStorage = canonicalizeContextBuilderStorage(storage);
419
+ const admitted = await admitCommittedContextBuilderRun(canonicalStorage, ops);
420
+ if (admitted === undefined) {
421
+ throw new ContextBuilderCommittedRunChangedError(canonicalStorage.runId);
422
+ }
423
+ return await withAdmittedCommittedContextBuilderRunMutationLease(canonicalStorage, admitted, callback, ops);
424
+ }
425
+ async function withAdmittedCommittedContextBuilderRunMutationLease(storage, admitted, callback, ops) {
426
+ return await withContextBuilderStorageMutationLock(storage, ops, async (leasedOps) => {
427
+ const current = await admitCommittedContextBuilderRun(storage, leasedOps);
428
+ if (current === undefined
429
+ || !committedRunAdmissionsEqual(admitted, current)) {
430
+ throw new ContextBuilderCommittedRunChangedError(storage.runId);
431
+ }
432
+ return await callback(leasedOps);
433
+ }, {
434
+ canRecoverStale: async () => {
435
+ const current = await admitCommittedContextBuilderRun(storage, ops);
436
+ return current !== undefined
437
+ && committedRunAdmissionsEqual(admitted, current);
438
+ },
439
+ });
440
+ }
441
+ async function withContextBuilderStorageMutationLock(storage, ops, callback, options = {}) {
442
+ const heldLocks = ops[HELD_CONTEXT_BUILDER_MUTATION_LOCKS];
443
+ if (heldLocks?.has(storage.runDir) === true) {
444
+ return await callback(ops);
445
+ }
446
+ return await withContextBuilderMutationLock(storage, ops, async () => await callback(markContextBuilderMutationLockHeld(ops, storage.runDir)), options);
447
+ }
448
+ function markContextBuilderMutationLockHeld(ops, runDir) {
449
+ const inherited = ops[HELD_CONTEXT_BUILDER_MUTATION_LOCKS];
450
+ const heldLocks = new Set(inherited ?? []);
451
+ heldLocks.add(runDir);
452
+ const leasedOps = Object.create(ops);
453
+ Object.defineProperty(leasedOps, HELD_CONTEXT_BUILDER_MUTATION_LOCKS, {
454
+ value: heldLocks,
455
+ });
456
+ return leasedOps;
457
+ }
458
+ async function admitCommittedContextBuilderRun(storage, ops) {
459
+ const lstat = ops.lstat ?? fsLstat;
460
+ const open = ops.open ?? fsOpen;
461
+ let handle;
462
+ try {
463
+ const pathStats = await lstat(storage.manifestJson, { bigint: true });
464
+ if (!pathStats.isFile()) {
465
+ return undefined;
466
+ }
467
+ handle = await open(storage.manifestJson, "r");
468
+ const before = await handle.stat({ bigint: true });
469
+ if (!before.isFile()
470
+ || before.nlink === 0n
471
+ || !sameCommittedRunIncarnation(committedRunFingerprintFromStats(pathStats), committedRunFingerprintFromStats(before))) {
472
+ return undefined;
473
+ }
474
+ const serializedManifest = await handle.readFile({ encoding: "utf8" });
475
+ const afterRead = await handle.stat({ bigint: true });
476
+ const beforeFingerprint = committedRunFingerprintFromStats(before);
477
+ const afterReadFingerprint = committedRunFingerprintFromStats(afterRead);
478
+ if (afterRead.nlink === 0n
479
+ || !committedRunFingerprintsEqual(beforeFingerprint, afterReadFingerprint)) {
480
+ return undefined;
481
+ }
482
+ const parsed = JSON.parse(serializedManifest);
483
+ if (!isValidContextBuilderManifest(parsed, storage.runId)) {
484
+ return undefined;
485
+ }
486
+ const artifactKeys = supportedArtifactKeys(parsed.artifacts);
487
+ if (artifactKeys == null
488
+ || !artifactPathsExactlyMatch(parsed.artifacts, storage.artifacts, artifactKeys)) {
489
+ return undefined;
490
+ }
491
+ await assertRequiredArtifactsReadable(storage, ops, artifactKeys);
492
+ const afterArtifacts = await handle.stat({ bigint: true });
493
+ const finalFingerprint = committedRunFingerprintFromStats(afterArtifacts);
494
+ if (afterArtifacts.nlink === 0n
495
+ || !committedRunFingerprintsEqual(afterReadFingerprint, finalFingerprint)) {
496
+ return undefined;
497
+ }
498
+ return { serializedManifest, fingerprint: finalFingerprint };
499
+ }
500
+ catch {
501
+ return undefined;
502
+ }
503
+ finally {
504
+ await handle?.close().catch(() => { });
505
+ }
506
+ }
507
+ function committedRunFingerprintFromStats(stats) {
508
+ return {
509
+ dev: stats.dev,
510
+ ino: stats.ino,
511
+ mtimeNs: stats.mtimeNs,
512
+ ctimeNs: stats.ctimeNs,
513
+ size: stats.size,
514
+ nlink: stats.nlink,
515
+ };
516
+ }
517
+ function sameCommittedRunIncarnation(left, right) {
518
+ return left.dev === right.dev && left.ino === right.ino;
519
+ }
520
+ function committedRunFingerprintsEqual(left, right) {
521
+ return sameCommittedRunIncarnation(left, right)
522
+ && left.mtimeNs === right.mtimeNs
523
+ && left.ctimeNs === right.ctimeNs
524
+ && left.size === right.size
525
+ && left.nlink === right.nlink;
526
+ }
527
+ function committedRunAdmissionsEqual(left, right) {
528
+ return left.serializedManifest === right.serializedManifest
529
+ && committedRunFingerprintsEqual(left.fingerprint, right.fingerprint);
530
+ }
531
+ async function admitContextBuilderRunDirectory(storage, ops) {
532
+ const lstat = ops.lstat ?? fsLstat;
533
+ try {
534
+ const stats = await lstat(storage.runDir, { bigint: true });
535
+ if (!stats.isDirectory() || stats.nlink === 0n) {
536
+ return undefined;
537
+ }
538
+ return {
539
+ dev: stats.dev,
540
+ ino: stats.ino,
541
+ mtimeNs: stats.mtimeNs,
542
+ ctimeNs: stats.ctimeNs,
543
+ size: stats.size,
544
+ nlink: stats.nlink,
545
+ };
546
+ }
547
+ catch (error) {
548
+ if (isNodeError(error) && error.code === "ENOENT") {
549
+ return undefined;
550
+ }
551
+ throw error;
552
+ }
553
+ }
554
+ function contextBuilderRunDirectoryAdmissionsEqual(left, right) {
555
+ return left.dev === right.dev
556
+ && left.ino === right.ino
557
+ && left.mtimeNs === right.mtimeNs
558
+ && left.ctimeNs === right.ctimeNs
559
+ && left.size === right.size
560
+ && left.nlink === right.nlink;
561
+ }
183
562
  async function cleanupContextBuilderIncompleteRunLocked(storage, ownerNonce, ops) {
184
563
  if (!await mayRemoveIncompleteRunDir(storage, ownerNonce, ops)) {
185
564
  return false;
@@ -202,10 +581,12 @@ export async function isContextBuilderRunCommitted(runDir, ops = DEFAULT_STORAGE
202
581
  if (expectedStorage.runDir !== resolvedRunDir) {
203
582
  return false;
204
583
  }
205
- if (!artifactPathsExactlyMatch(parsed.artifacts, expectedStorage.artifacts)) {
584
+ const artifactKeys = supportedArtifactKeys(parsed.artifacts);
585
+ if (artifactKeys == null
586
+ || !artifactPathsExactlyMatch(parsed.artifacts, expectedStorage.artifacts, artifactKeys)) {
206
587
  return false;
207
588
  }
208
- await assertRequiredArtifactsReadable(expectedStorage, ops);
589
+ await assertRequiredArtifactsReadable(expectedStorage, ops, artifactKeys);
209
590
  return true;
210
591
  }
211
592
  catch {
@@ -218,13 +599,46 @@ function canonicalizeContextBuilderStorage(storage) {
218
599
  || storage.artifactDir !== expected.artifactDir
219
600
  || storage.buildingJson !== expected.buildingJson
220
601
  || storage.manifestJson !== expected.manifestJson
221
- || !artifactPathsExactlyMatch(storage.artifacts, expected.artifacts)) {
602
+ || !artifactPathsExactlyMatch(storage.artifacts, expected.artifacts, CONTEXT_BUILDER_NO_DELEGATE_ARTIFACT_KEYS)) {
222
603
  throw new ExecutionError("context_builder storage paths do not match run_id and runs_dir");
223
604
  }
224
605
  return storage.ownerNonce === undefined
225
606
  ? expected
226
607
  : { ...expected, ownerNonce: storage.ownerNonce };
227
608
  }
609
+ async function readContextBuilderManifest(manifestPath, ops) {
610
+ let parsed;
611
+ try {
612
+ parsed = JSON.parse(await ops.readFile(manifestPath, "utf8"));
613
+ }
614
+ catch (error) {
615
+ throw new ExecutionError(`context_builder cannot read manifest for promotion: ${nodeErrorCode(error)}`);
616
+ }
617
+ const parsedRunId = parsed !== null && typeof parsed === "object"
618
+ ? parsed.run_id
619
+ : undefined;
620
+ if (typeof parsedRunId !== "string"
621
+ || !isValidContextBuilderManifest(parsed, parsedRunId)) {
622
+ throw new ExecutionError("context_builder cannot promote run with an invalid manifest");
623
+ }
624
+ return parsed;
625
+ }
626
+ function rewriteContextBuilderSummaryRunId(summaryText, targetRunId) {
627
+ let parsed;
628
+ try {
629
+ parsed = JSON.parse(summaryText);
630
+ }
631
+ catch {
632
+ throw new ExecutionError("context_builder cannot promote run with an invalid summary artifact");
633
+ }
634
+ if (parsed === null || typeof parsed !== "object") {
635
+ throw new ExecutionError("context_builder cannot promote run with an invalid summary artifact");
636
+ }
637
+ return `${JSON.stringify({
638
+ ...parsed,
639
+ run_id: targetRunId,
640
+ })}\n`;
641
+ }
228
642
  async function mayRemoveIncompleteRunDir(storage, ownerNonce, ops) {
229
643
  return (await canRemoveIncompleteRunDir(storage, ownerNonce, ops)).removable;
230
644
  }
@@ -274,9 +688,9 @@ async function claimContextBuilderRunDir(paths, ops) {
274
688
  catch (error) {
275
689
  if (isNodeError(error) && error.code === "EEXIST") {
276
690
  if (await isContextBuilderRunCommitted(paths.runDir, ops)) {
277
- throw new InvalidParamsError(`context_builder run_id already exists: ${paths.runId}`);
691
+ throw new ContextBuilderRunClaimConflictError(paths.runId);
278
692
  }
279
- throw new ExecutionError(`context_builder run_id conflicts with an incomplete or active run: ${paths.runId}`);
693
+ throw new ContextBuilderActiveRunClaimConflictError(paths.runId);
280
694
  }
281
695
  throw error;
282
696
  }
@@ -302,149 +716,9 @@ function isStorageOps(value) {
302
716
  || "open" in value
303
717
  || "link" in value);
304
718
  }
305
- async function withContextBuilderMutationLock(storage, ops, callback, options = {}) {
306
- const lockPath = mutationLockPathForStorage(storage);
307
- const lockHandle = await acquireContextBuilderMutationLock(storage, lockPath, ops, options);
308
- try {
309
- return await callback();
310
- }
311
- finally {
312
- await lockHandle.close().catch(() => { });
313
- await (ops.rm ?? fsRm)(lockPath, { force: true }).catch(() => { });
314
- }
315
- }
316
- async function acquireContextBuilderMutationLock(storage, lockPath, ops, options) {
317
- const open = ops.open ?? fsOpen;
318
- for (let attempt = 0; attempt < CONTEXT_BUILDER_MUTATION_LOCK_ATTEMPTS; attempt += 1) {
319
- try {
320
- const handle = await open(lockPath, "wx", 0o600);
321
- try {
322
- await writeMutationLockMetadata(handle, options.ownerNonce);
323
- return handle;
324
- }
325
- catch (error) {
326
- await handle.close().catch(() => { });
327
- await (ops.rm ?? fsRm)(lockPath, { force: true }).catch(() => { });
328
- throw error;
329
- }
330
- }
331
- catch (error) {
332
- if (isNodeError(error) && error.code === "EEXIST") {
333
- if (options.recoverStaleForCleanup === true
334
- && await breakStaleCleanupMutationLock(storage, lockPath, options.ownerNonce, ops)) {
335
- continue;
336
- }
337
- await delay(CONTEXT_BUILDER_MUTATION_LOCK_RETRY_MS);
338
- continue;
339
- }
340
- throw error;
341
- }
342
- }
343
- throw new ExecutionError("context_builder timed out waiting for the run mutation lock");
344
- }
345
- function mutationLockPathForStorage(storage) {
346
- validateCallerRunId(storage.runId);
347
- const resolvedRunsDir = resolve(storage.runsDir);
348
- const resolvedRunDir = resolve(storage.runDir);
349
- if (!isPathInsideDirectory(resolvedRunDir, resolvedRunsDir)) {
350
- throw new ExecutionError("context_builder refused mutation lock outside runs directory");
351
- }
352
- return join(resolvedRunsDir, `.${storage.runId}${CONTEXT_BUILDER_MUTATION_LOCK_SUFFIX}`);
353
- }
354
- async function writeMutationLockMetadata(handle, ownerNonce) {
355
- const metadata = {
356
- pid: process.pid,
357
- hostname: hostname(),
358
- created_at: new Date().toISOString(),
359
- ...(ownerNonce == null ? {} : { owner_nonce: ownerNonce }),
360
- };
361
- await handle.writeFile(`${JSON.stringify(metadata)}\n`, { encoding: "utf8" });
362
- }
363
- async function breakStaleCleanupMutationLock(storage, lockPath, ownerNonce, ops) {
364
- if (ownerNonce == null) {
365
- return false;
366
- }
367
- const cleanupDecision = await canRemoveIncompleteRunDir(storage, ownerNonce, ops);
368
- if (!cleanupDecision.removable) {
369
- return false;
370
- }
371
- if (!await isMutationLockOldEnough(lockPath, ops)) {
372
- return false;
373
- }
374
- const metadata = await readMutationLockMetadata(lockPath, ops);
375
- if (metadata !== "invalid" && !isStaleMutationLockMetadata(metadata)) {
376
- return false;
377
- }
378
- await (ops.rm ?? fsRm)(lockPath, { force: true }).catch(() => { });
379
- return true;
380
- }
381
- async function isMutationLockOldEnough(lockPath, ops) {
382
- const stat = ops.stat ?? fsStat;
383
- try {
384
- const lockStat = await stat(lockPath);
385
- return Date.now() - lockStat.mtimeMs >= CONTEXT_BUILDER_STALE_MUTATION_LOCK_MS;
386
- }
387
- catch {
388
- return false;
389
- }
390
- }
391
- async function readMutationLockMetadata(lockPath, ops) {
392
- let parsed;
393
- try {
394
- parsed = JSON.parse(await ops.readFile(lockPath, "utf8"));
395
- }
396
- catch {
397
- return "invalid";
398
- }
399
- if (parsed === null || typeof parsed !== "object") {
400
- return "invalid";
401
- }
402
- const metadata = parsed;
403
- if (typeof metadata.pid !== "number"
404
- || !Number.isInteger(metadata.pid)
405
- || typeof metadata.hostname !== "string"
406
- || typeof metadata.created_at !== "string") {
407
- return "invalid";
408
- }
409
- if (metadata.owner_nonce !== undefined
410
- && typeof metadata.owner_nonce !== "string") {
411
- return "invalid";
412
- }
413
- return {
414
- pid: metadata.pid,
415
- hostname: metadata.hostname,
416
- created_at: metadata.created_at,
417
- ...(metadata.owner_nonce === undefined
418
- ? {}
419
- : { owner_nonce: metadata.owner_nonce }),
420
- };
421
- }
422
- function isStaleMutationLockMetadata(metadata) {
423
- const createdAtMs = Date.parse(metadata.created_at);
424
- if (!Number.isFinite(createdAtMs)
425
- || Date.now() - createdAtMs < CONTEXT_BUILDER_STALE_MUTATION_LOCK_MS) {
426
- return false;
427
- }
428
- if (metadata.hostname !== hostname()) {
429
- return false;
430
- }
431
- return !isProcessAlive(metadata.pid);
432
- }
433
- function isProcessAlive(pid) {
434
- if (pid <= 0) {
435
- return false;
436
- }
437
- try {
438
- process.kill(pid, 0);
439
- return true;
440
- }
441
- catch (error) {
442
- return !(isNodeError(error) && error.code === "ESRCH");
443
- }
444
- }
445
- async function assertRequiredArtifactsReadable(storage, ops) {
719
+ async function assertRequiredArtifactsReadable(storage, ops, artifactKeys = CONTEXT_BUILDER_NO_DELEGATE_ARTIFACT_KEYS) {
446
720
  const missing = [];
447
- for (const key of CONTEXT_BUILDER_NO_DELEGATE_ARTIFACT_KEYS) {
721
+ for (const key of artifactKeys) {
448
722
  if (key === "manifest_json") {
449
723
  continue;
450
724
  }
@@ -471,11 +745,11 @@ async function assertManifestAbsentForMutation(storage, ops) {
471
745
  }
472
746
  throw new ExecutionError("context_builder cannot mutate committed run: manifest already exists");
473
747
  }
474
- function artifactPathsExactlyMatch(actual, expected) {
475
- if (!hasExactArtifactKeys(actual)) {
748
+ function artifactPathsExactlyMatch(actual, expected, artifactKeys) {
749
+ if (!hasExactArtifactKeys(actual, artifactKeys)) {
476
750
  return false;
477
751
  }
478
- for (const key of CONTEXT_BUILDER_NO_DELEGATE_ARTIFACT_KEYS) {
752
+ for (const key of artifactKeys) {
479
753
  if (actual[key] !== expected[key]) {
480
754
  return false;
481
755
  }
@@ -533,12 +807,22 @@ function hasRequiredArtifactPaths(value) {
533
807
  return false;
534
808
  }
535
809
  const artifacts = value;
536
- return hasExactArtifactKeys(artifacts) && CONTEXT_BUILDER_NO_DELEGATE_ARTIFACT_KEYS.every((key) => (typeof artifacts[key] === "string"));
810
+ const artifactKeys = supportedArtifactKeys(artifacts);
811
+ return artifactKeys != null && artifactKeys.every((key) => (typeof artifacts[key] === "string"));
537
812
  }
538
- function hasExactArtifactKeys(value) {
539
- const expectedKeys = new Set(CONTEXT_BUILDER_NO_DELEGATE_ARTIFACT_KEYS);
813
+ function supportedArtifactKeys(value) {
814
+ if (hasExactArtifactKeys(value, CONTEXT_BUILDER_NO_DELEGATE_ARTIFACT_KEYS)) {
815
+ return CONTEXT_BUILDER_NO_DELEGATE_ARTIFACT_KEYS;
816
+ }
817
+ if (hasExactArtifactKeys(value, CONTEXT_BUILDER_LEGACY_ARTIFACT_KEYS)) {
818
+ return CONTEXT_BUILDER_LEGACY_ARTIFACT_KEYS;
819
+ }
820
+ return undefined;
821
+ }
822
+ function hasExactArtifactKeys(value, expectedArtifactKeys) {
823
+ const expectedKeys = new Set(expectedArtifactKeys);
540
824
  const actualKeys = Object.keys(value);
541
- return (actualKeys.length === CONTEXT_BUILDER_NO_DELEGATE_ARTIFACT_KEYS.length
825
+ return (actualKeys.length === expectedArtifactKeys.length
542
826
  && actualKeys.every((key) => expectedKeys.has(key)));
543
827
  }
544
828
  function hasRequiredMetrics(value) {
@@ -660,6 +944,57 @@ async function syncDirectoryBestEffort(path, ops) {
660
944
  }
661
945
  }
662
946
  }
947
+ async function removeCommittedWorkflowContextRun(storage, admission, directoryAdmission, ops) {
948
+ if (!isWorkflowContextRunId(storage.runId)) {
949
+ return false;
950
+ }
951
+ try {
952
+ return await withAdmittedCommittedContextBuilderRunMutationLease(storage, admission, async (leasedOps) => {
953
+ const currentDirectoryAdmission = await admitContextBuilderRunDirectory(storage, leasedOps);
954
+ if (currentDirectoryAdmission === undefined
955
+ || !contextBuilderRunDirectoryAdmissionsEqual(directoryAdmission, currentDirectoryAdmission)) {
956
+ return false;
957
+ }
958
+ await (leasedOps.rm ?? fsRm)(storage.runDir, { recursive: true, force: true });
959
+ return true;
960
+ }, ops);
961
+ }
962
+ catch (error) {
963
+ if (error instanceof ContextBuilderCommittedRunChangedError) {
964
+ return false;
965
+ }
966
+ throw error;
967
+ }
968
+ }
969
+ function isWorkflowContextRunId(runId) {
970
+ return runId.startsWith("wfctx-") || runId.startsWith("wfpre-");
971
+ }
972
+ function resolveWorkflowContextEvictionBounds(options) {
973
+ const env = options.env ?? process.env;
974
+ const maxEntries = normalizeNonNegativeInteger(options.maxEntries, parseNonNegativeInteger(env[WORKFLOW_CONTEXT_CACHE_MAX_ENTRIES_ENV], DEFAULT_WORKFLOW_CONTEXT_CACHE_MAX_ENTRIES));
975
+ const cacheTtlSeconds = normalizeNonNegativeInteger(options.cacheTtlSeconds, parseNonNegativeInteger(env[WORKFLOW_CONTEXT_CACHE_TTL_SECONDS_ENV], DEFAULT_WORKFLOW_CONTEXT_CACHE_TTL_SECONDS));
976
+ const tempTtlSeconds = normalizeNonNegativeInteger(options.tempTtlSeconds, Math.min(cacheTtlSeconds, DEFAULT_WORKFLOW_CONTEXT_TEMP_TTL_SECONDS));
977
+ return {
978
+ maxEntries,
979
+ cacheTtlMs: cacheTtlSeconds * 1_000,
980
+ // Provenance-only temp runs are useful for debugging recent misses, but they
981
+ // are not reusable cache entries, so they get a shorter bounded lifetime.
982
+ tempTtlMs: tempTtlSeconds * 1_000,
983
+ };
984
+ }
985
+ function parseNonNegativeInteger(value, fallback) {
986
+ if (value == null || value.trim() === "") {
987
+ return fallback;
988
+ }
989
+ const parsed = Number(value);
990
+ return normalizeNonNegativeInteger(parsed, fallback);
991
+ }
992
+ function normalizeNonNegativeInteger(value, fallback) {
993
+ if (value === undefined) {
994
+ return fallback;
995
+ }
996
+ return Number.isSafeInteger(value) && value >= 0 ? value : fallback;
997
+ }
663
998
  function isNodeError(error) {
664
999
  return error instanceof Error && "code" in error;
665
1000
  }
@@ -736,9 +1071,6 @@ function diagnosticText(value, fallback) {
736
1071
  function isRecord(value) {
737
1072
  return value !== null && typeof value === "object";
738
1073
  }
739
- async function delay(ms) {
740
- await new Promise((resolve) => setTimeout(resolve, ms));
741
- }
742
1074
  function isPathInsideDirectory(candidate, directory) {
743
1075
  const relation = relative(directory, candidate);
744
1076
  return relation !== "" && !relation.startsWith("..") && !isAbsolute(relation);