clinkx 0.3.0 → 1.0.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 (555) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/LICENSE +10 -0
  3. package/README.md +82 -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/citation-check.d.ts +40 -0
  12. package/clinkx-workflows/dist/citation-check.js +348 -0
  13. package/clinkx-workflows/dist/citation-check.js.map +1 -0
  14. package/clinkx-workflows/dist/clink-client.d.ts +2 -1
  15. package/clinkx-workflows/dist/clink-client.js +17 -4
  16. package/clinkx-workflows/dist/clink-client.js.map +1 -1
  17. package/clinkx-workflows/dist/config.d.ts +145 -16
  18. package/clinkx-workflows/dist/config.js +384 -26
  19. package/clinkx-workflows/dist/config.js.map +1 -1
  20. package/clinkx-workflows/dist/contained-file.d.ts +172 -0
  21. package/clinkx-workflows/dist/contained-file.js +483 -0
  22. package/clinkx-workflows/dist/contained-file.js.map +1 -0
  23. package/clinkx-workflows/dist/context-builder-lifecycle-contract.d.ts +416 -0
  24. package/clinkx-workflows/dist/context-builder-lifecycle-contract.js +328 -0
  25. package/clinkx-workflows/dist/context-builder-lifecycle-contract.js.map +1 -0
  26. package/clinkx-workflows/dist/context-builder-lifecycle-router.d.ts +24 -0
  27. package/clinkx-workflows/dist/context-builder-lifecycle-router.js +39 -0
  28. package/clinkx-workflows/dist/context-builder-lifecycle-router.js.map +1 -0
  29. package/clinkx-workflows/dist/context-cache-key.d.ts +53 -0
  30. package/clinkx-workflows/dist/context-cache-key.js +91 -0
  31. package/clinkx-workflows/dist/context-cache-key.js.map +1 -0
  32. package/clinkx-workflows/dist/context-mode-resolver.d.ts +27 -0
  33. package/clinkx-workflows/dist/context-mode-resolver.js +126 -0
  34. package/clinkx-workflows/dist/context-mode-resolver.js.map +1 -0
  35. package/clinkx-workflows/dist/context-preflight.d.ts +184 -0
  36. package/clinkx-workflows/dist/context-preflight.js +91 -0
  37. package/clinkx-workflows/dist/context-preflight.js.map +1 -0
  38. package/clinkx-workflows/dist/council-expander.d.ts +1 -1
  39. package/clinkx-workflows/dist/council-expander.js +2 -1
  40. package/clinkx-workflows/dist/council-expander.js.map +1 -1
  41. package/clinkx-workflows/dist/dashboard/activity-contract.d.ts +165 -0
  42. package/clinkx-workflows/dist/dashboard/activity-contract.js +105 -0
  43. package/clinkx-workflows/dist/dashboard/activity-contract.js.map +1 -0
  44. package/clinkx-workflows/dist/dashboard/activity-lease.d.ts +25 -0
  45. package/clinkx-workflows/dist/dashboard/activity-lease.js +34 -0
  46. package/clinkx-workflows/dist/dashboard/activity-lease.js.map +1 -0
  47. package/clinkx-workflows/dist/dashboard/activity-reader.d.ts +86 -0
  48. package/clinkx-workflows/dist/dashboard/activity-reader.js +480 -0
  49. package/clinkx-workflows/dist/dashboard/activity-reader.js.map +1 -0
  50. package/clinkx-workflows/dist/dashboard/api-routes.d.ts +36 -0
  51. package/clinkx-workflows/dist/dashboard/api-routes.js +1047 -0
  52. package/clinkx-workflows/dist/dashboard/api-routes.js.map +1 -0
  53. package/clinkx-workflows/dist/dashboard/artifact-index.d.ts +37 -0
  54. package/clinkx-workflows/dist/dashboard/artifact-index.js +145 -0
  55. package/clinkx-workflows/dist/dashboard/artifact-index.js.map +1 -0
  56. package/clinkx-workflows/dist/dashboard/auth/challenge-store.d.ts +31 -0
  57. package/clinkx-workflows/dist/dashboard/auth/challenge-store.js +65 -0
  58. package/clinkx-workflows/dist/dashboard/auth/challenge-store.js.map +1 -0
  59. package/clinkx-workflows/dist/dashboard/auth/controller.d.ts +26 -0
  60. package/clinkx-workflows/dist/dashboard/auth/controller.js +596 -0
  61. package/clinkx-workflows/dist/dashboard/auth/controller.js.map +1 -0
  62. package/clinkx-workflows/dist/dashboard/auth/credential-store.d.ts +60 -0
  63. package/clinkx-workflows/dist/dashboard/auth/credential-store.js +776 -0
  64. package/clinkx-workflows/dist/dashboard/auth/credential-store.js.map +1 -0
  65. package/clinkx-workflows/dist/dashboard/auth/enrollment-gate.d.ts +9 -0
  66. package/clinkx-workflows/dist/dashboard/auth/enrollment-gate.js +44 -0
  67. package/clinkx-workflows/dist/dashboard/auth/enrollment-gate.js.map +1 -0
  68. package/clinkx-workflows/dist/dashboard/auth/session-store.d.ts +17 -0
  69. package/clinkx-workflows/dist/dashboard/auth/session-store.js +77 -0
  70. package/clinkx-workflows/dist/dashboard/auth/session-store.js.map +1 -0
  71. package/clinkx-workflows/dist/dashboard/auth/webauthn-service.d.ts +25 -0
  72. package/clinkx-workflows/dist/dashboard/auth/webauthn-service.js +71 -0
  73. package/clinkx-workflows/dist/dashboard/auth/webauthn-service.js.map +1 -0
  74. package/clinkx-workflows/dist/dashboard/context-run-liveness.d.ts +37 -0
  75. package/clinkx-workflows/dist/dashboard/context-run-liveness.js +49 -0
  76. package/clinkx-workflows/dist/dashboard/context-run-liveness.js.map +1 -0
  77. package/clinkx-workflows/dist/dashboard/context-run-reader.d.ts +222 -0
  78. package/clinkx-workflows/dist/dashboard/context-run-reader.js +1178 -0
  79. package/clinkx-workflows/dist/dashboard/context-run-reader.js.map +1 -0
  80. package/clinkx-workflows/dist/dashboard/contracts.d.ts +8936 -0
  81. package/clinkx-workflows/dist/dashboard/contracts.js +1157 -0
  82. package/clinkx-workflows/dist/dashboard/contracts.js.map +1 -0
  83. package/clinkx-workflows/dist/dashboard/generation.d.ts +14 -0
  84. package/clinkx-workflows/dist/dashboard/generation.js +41 -0
  85. package/clinkx-workflows/dist/dashboard/generation.js.map +1 -0
  86. package/clinkx-workflows/dist/dashboard/index.d.ts +28 -0
  87. package/clinkx-workflows/dist/dashboard/index.js +16 -0
  88. package/clinkx-workflows/dist/dashboard/index.js.map +1 -0
  89. package/clinkx-workflows/dist/dashboard/lazy-content.d.ts +101 -0
  90. package/clinkx-workflows/dist/dashboard/lazy-content.js +748 -0
  91. package/clinkx-workflows/dist/dashboard/lazy-content.js.map +1 -0
  92. package/clinkx-workflows/dist/dashboard/progress-report-contract.d.ts +303 -0
  93. package/clinkx-workflows/dist/dashboard/progress-report-contract.js +221 -0
  94. package/clinkx-workflows/dist/dashboard/progress-report-contract.js.map +1 -0
  95. package/clinkx-workflows/dist/dashboard/progress-report-reader.d.ts +50 -0
  96. package/clinkx-workflows/dist/dashboard/progress-report-reader.js +581 -0
  97. package/clinkx-workflows/dist/dashboard/progress-report-reader.js.map +1 -0
  98. package/clinkx-workflows/dist/dashboard/progress-report-status-overlay.d.ts +89 -0
  99. package/clinkx-workflows/dist/dashboard/progress-report-status-overlay.js +71 -0
  100. package/clinkx-workflows/dist/dashboard/progress-report-status-overlay.js.map +1 -0
  101. package/clinkx-workflows/dist/dashboard/progress-report-status-store.d.ts +28 -0
  102. package/clinkx-workflows/dist/dashboard/progress-report-status-store.js +110 -0
  103. package/clinkx-workflows/dist/dashboard/progress-report-status-store.js.map +1 -0
  104. package/clinkx-workflows/dist/dashboard/read-model.d.ts +86 -0
  105. package/clinkx-workflows/dist/dashboard/read-model.js +440 -0
  106. package/clinkx-workflows/dist/dashboard/read-model.js.map +1 -0
  107. package/clinkx-workflows/dist/dashboard/request-admission.d.ts +31 -0
  108. package/clinkx-workflows/dist/dashboard/request-admission.js +126 -0
  109. package/clinkx-workflows/dist/dashboard/request-admission.js.map +1 -0
  110. package/clinkx-workflows/dist/dashboard/scanner.d.ts +75 -0
  111. package/clinkx-workflows/dist/dashboard/scanner.js +1110 -0
  112. package/clinkx-workflows/dist/dashboard/scanner.js.map +1 -0
  113. package/clinkx-workflows/dist/dashboard/server-factory.d.ts +50 -0
  114. package/clinkx-workflows/dist/dashboard/server-factory.js +431 -0
  115. package/clinkx-workflows/dist/dashboard/server-factory.js.map +1 -0
  116. package/clinkx-workflows/dist/dashboard/session-log-contract.d.ts +2611 -0
  117. package/clinkx-workflows/dist/dashboard/session-log-contract.js +480 -0
  118. package/clinkx-workflows/dist/dashboard/session-log-contract.js.map +1 -0
  119. package/clinkx-workflows/dist/dashboard/session-log-identity.d.ts +21 -0
  120. package/clinkx-workflows/dist/dashboard/session-log-identity.js +101 -0
  121. package/clinkx-workflows/dist/dashboard/session-log-identity.js.map +1 -0
  122. package/clinkx-workflows/dist/dashboard/session-log-journal.d.ts +43 -0
  123. package/clinkx-workflows/dist/dashboard/session-log-journal.js +522 -0
  124. package/clinkx-workflows/dist/dashboard/session-log-journal.js.map +1 -0
  125. package/clinkx-workflows/dist/dashboard/session-log-reader.d.ts +61 -0
  126. package/clinkx-workflows/dist/dashboard/session-log-reader.js +378 -0
  127. package/clinkx-workflows/dist/dashboard/session-log-reader.js.map +1 -0
  128. package/clinkx-workflows/dist/dashboard/session-log-redaction.d.ts +6 -0
  129. package/clinkx-workflows/dist/dashboard/session-log-redaction.js +367 -0
  130. package/clinkx-workflows/dist/dashboard/session-log-redaction.js.map +1 -0
  131. package/clinkx-workflows/dist/dashboard/session-log-retention.d.ts +23 -0
  132. package/clinkx-workflows/dist/dashboard/session-log-retention.js +212 -0
  133. package/clinkx-workflows/dist/dashboard/session-log-retention.js.map +1 -0
  134. package/clinkx-workflows/dist/dashboard/static-responses.d.ts +10 -0
  135. package/clinkx-workflows/dist/dashboard/static-responses.js +94 -0
  136. package/clinkx-workflows/dist/dashboard/static-responses.js.map +1 -0
  137. package/clinkx-workflows/dist/dashboard/worker-lock-observer.d.ts +28 -0
  138. package/clinkx-workflows/dist/dashboard/worker-lock-observer.js +241 -0
  139. package/clinkx-workflows/dist/dashboard/worker-lock-observer.js.map +1 -0
  140. package/clinkx-workflows/dist/dashboard-ui/assets/ibm-plex-mono-latin-400-normal-CvHOgSBP.woff +0 -0
  141. package/clinkx-workflows/dist/dashboard-ui/assets/ibm-plex-mono-latin-400-normal-DMJ8VG8y.woff2 +0 -0
  142. package/clinkx-workflows/dist/dashboard-ui/assets/ibm-plex-mono-latin-500-normal-CB9ihrfo.woff +0 -0
  143. package/clinkx-workflows/dist/dashboard-ui/assets/ibm-plex-mono-latin-500-normal-DSY6xOcd.woff2 +0 -0
  144. package/clinkx-workflows/dist/dashboard-ui/assets/ibm-plex-sans-latin-400-normal-CDDApCn2.woff2 +0 -0
  145. package/clinkx-workflows/dist/dashboard-ui/assets/ibm-plex-sans-latin-400-normal-CYLoc0-x.woff +0 -0
  146. package/clinkx-workflows/dist/dashboard-ui/assets/ibm-plex-sans-latin-500-normal-6ng42L7E.woff2 +0 -0
  147. package/clinkx-workflows/dist/dashboard-ui/assets/ibm-plex-sans-latin-500-normal-BgVn5rGT.woff +0 -0
  148. package/clinkx-workflows/dist/dashboard-ui/assets/ibm-plex-sans-latin-600-normal-Cu4Hd6ag.woff +0 -0
  149. package/clinkx-workflows/dist/dashboard-ui/assets/ibm-plex-sans-latin-600-normal-CuJfVYMP.woff2 +0 -0
  150. package/clinkx-workflows/dist/dashboard-ui/assets/index-DOkMXTfB.js +25 -0
  151. package/clinkx-workflows/dist/dashboard-ui/assets/jetbrains-mono-latin-400-normal-6-qcROiO.woff +0 -0
  152. package/clinkx-workflows/dist/dashboard-ui/assets/jetbrains-mono-latin-400-normal-V6pRDFza.woff2 +0 -0
  153. package/clinkx-workflows/dist/dashboard-ui/assets/jetbrains-mono-latin-500-normal-BWZEU5yA.woff2 +0 -0
  154. package/clinkx-workflows/dist/dashboard-ui/assets/jetbrains-mono-latin-500-normal-CJOVTJB7.woff +0 -0
  155. package/clinkx-workflows/dist/dashboard-ui/assets/style-ChJsn0KD.css +1 -0
  156. package/clinkx-workflows/dist/dashboard-ui/contracts/council-plan-review-input-v1.json +158 -0
  157. package/clinkx-workflows/dist/dashboard-ui/index.html +15 -0
  158. package/clinkx-workflows/dist/dashboard-ui/licenses/IBM-Plex-Mono-OFL.txt +93 -0
  159. package/clinkx-workflows/dist/dashboard-ui/licenses/IBM-Plex-Sans-OFL.txt +93 -0
  160. package/clinkx-workflows/dist/dashboard-ui/licenses/JetBrains-Mono-OFL.txt +93 -0
  161. package/clinkx-workflows/dist/dashboard-ui/licenses/NOTICE.md +32 -0
  162. package/clinkx-workflows/dist/dashboard-ui/theme-init.js +8 -0
  163. package/clinkx-workflows/dist/definition-normalizer.d.ts +19 -0
  164. package/clinkx-workflows/dist/definition-normalizer.js.map +1 -1
  165. package/clinkx-workflows/dist/delegate-validate.d.ts +78 -0
  166. package/clinkx-workflows/dist/delegate-validate.js +97 -0
  167. package/clinkx-workflows/dist/delegate-validate.js.map +1 -0
  168. package/clinkx-workflows/dist/engine.d.ts +141 -0
  169. package/clinkx-workflows/dist/engine.js +882 -28
  170. package/clinkx-workflows/dist/engine.js.map +1 -1
  171. package/clinkx-workflows/dist/errors.d.ts +2 -0
  172. package/clinkx-workflows/dist/errors.js.map +1 -1
  173. package/clinkx-workflows/dist/fingerprint.d.ts +1 -1
  174. package/clinkx-workflows/dist/fingerprint.js +1 -1
  175. package/clinkx-workflows/dist/index.d.ts +19 -0
  176. package/clinkx-workflows/dist/index.js +15 -0
  177. package/clinkx-workflows/dist/index.js.map +1 -1
  178. package/clinkx-workflows/dist/loader.d.ts +9 -3
  179. package/clinkx-workflows/dist/loader.js +92 -21
  180. package/clinkx-workflows/dist/loader.js.map +1 -1
  181. package/clinkx-workflows/dist/plan-review/admission.d.ts +160 -0
  182. package/clinkx-workflows/dist/plan-review/admission.js +290 -0
  183. package/clinkx-workflows/dist/plan-review/admission.js.map +1 -0
  184. package/clinkx-workflows/dist/plan-review/context-policy.d.ts +55 -0
  185. package/clinkx-workflows/dist/plan-review/context-policy.js +146 -0
  186. package/clinkx-workflows/dist/plan-review/context-policy.js.map +1 -0
  187. package/clinkx-workflows/dist/plan-review/contract.d.ts +763 -0
  188. package/clinkx-workflows/dist/plan-review/contract.js +289 -0
  189. package/clinkx-workflows/dist/plan-review/contract.js.map +1 -0
  190. package/clinkx-workflows/dist/plan-review/digest.d.ts +68 -0
  191. package/clinkx-workflows/dist/plan-review/digest.js +241 -0
  192. package/clinkx-workflows/dist/plan-review/digest.js.map +1 -0
  193. package/clinkx-workflows/dist/plan-review/discovery.d.ts +45 -0
  194. package/clinkx-workflows/dist/plan-review/discovery.js +36 -0
  195. package/clinkx-workflows/dist/plan-review/discovery.js.map +1 -0
  196. package/clinkx-workflows/dist/plan-review/execution-contract.d.ts +298 -0
  197. package/clinkx-workflows/dist/plan-review/execution-contract.js +194 -0
  198. package/clinkx-workflows/dist/plan-review/execution-contract.js.map +1 -0
  199. package/clinkx-workflows/dist/plan-review/expander.d.ts +48 -0
  200. package/clinkx-workflows/dist/plan-review/expander.js +243 -0
  201. package/clinkx-workflows/dist/plan-review/expander.js.map +1 -0
  202. package/clinkx-workflows/dist/plan-review/projector.d.ts +126 -0
  203. package/clinkx-workflows/dist/plan-review/projector.js +437 -0
  204. package/clinkx-workflows/dist/plan-review/projector.js.map +1 -0
  205. package/clinkx-workflows/dist/plan-review/publication.d.ts +95 -0
  206. package/clinkx-workflows/dist/plan-review/publication.js +182 -0
  207. package/clinkx-workflows/dist/plan-review/publication.js.map +1 -0
  208. package/clinkx-workflows/dist/plan-review/ranking-reducer.d.ts +34 -0
  209. package/clinkx-workflows/dist/plan-review/ranking-reducer.js +139 -0
  210. package/clinkx-workflows/dist/plan-review/ranking-reducer.js.map +1 -0
  211. package/clinkx-workflows/dist/plan-review/resume.d.ts +38 -0
  212. package/clinkx-workflows/dist/plan-review/resume.js +122 -0
  213. package/clinkx-workflows/dist/plan-review/resume.js.map +1 -0
  214. package/clinkx-workflows/dist/plan-review/rubric.d.ts +7 -0
  215. package/clinkx-workflows/dist/plan-review/rubric.js +24 -0
  216. package/clinkx-workflows/dist/plan-review/rubric.js.map +1 -0
  217. package/clinkx-workflows/dist/plan-review/run-state.d.ts +398 -0
  218. package/clinkx-workflows/dist/plan-review/run-state.js +183 -0
  219. package/clinkx-workflows/dist/plan-review/run-state.js.map +1 -0
  220. package/clinkx-workflows/dist/plan-review/runtime-policy.d.ts +74 -0
  221. package/clinkx-workflows/dist/plan-review/runtime-policy.js +186 -0
  222. package/clinkx-workflows/dist/plan-review/runtime-policy.js.map +1 -0
  223. package/clinkx-workflows/dist/plan-review/snapshot.d.ts +81 -0
  224. package/clinkx-workflows/dist/plan-review/snapshot.js +170 -0
  225. package/clinkx-workflows/dist/plan-review/snapshot.js.map +1 -0
  226. package/clinkx-workflows/dist/plan-review/stage-error.d.ts +19 -0
  227. package/clinkx-workflows/dist/plan-review/stage-error.js +20 -0
  228. package/clinkx-workflows/dist/plan-review/stage-error.js.map +1 -0
  229. package/clinkx-workflows/dist/post-processors/index.d.ts +20 -0
  230. package/clinkx-workflows/dist/post-processors/index.js +21 -0
  231. package/clinkx-workflows/dist/post-processors/index.js.map +1 -0
  232. package/clinkx-workflows/dist/prompt-budget.d.ts +7 -0
  233. package/clinkx-workflows/dist/prompt-budget.js +7 -1
  234. package/clinkx-workflows/dist/prompt-budget.js.map +1 -1
  235. package/clinkx-workflows/dist/reducers/index.js +2 -0
  236. package/clinkx-workflows/dist/reducers/index.js.map +1 -1
  237. package/clinkx-workflows/dist/run-lock-heartbeat.d.ts +2 -0
  238. package/clinkx-workflows/dist/run-lock-heartbeat.js +3 -0
  239. package/clinkx-workflows/dist/run-lock-heartbeat.js.map +1 -0
  240. package/clinkx-workflows/dist/run-summary/cards/council-plan-review.d.ts +34 -0
  241. package/clinkx-workflows/dist/run-summary/cards/council-plan-review.js +74 -0
  242. package/clinkx-workflows/dist/run-summary/cards/council-plan-review.js.map +1 -0
  243. package/clinkx-workflows/dist/run-summary/cards/index.js +5 -0
  244. package/clinkx-workflows/dist/run-summary/cards/index.js.map +1 -1
  245. package/clinkx-workflows/dist/run-summary.d.ts +13 -0
  246. package/clinkx-workflows/dist/run-summary.js +29 -1
  247. package/clinkx-workflows/dist/run-summary.js.map +1 -1
  248. package/clinkx-workflows/dist/schema.d.ts +76 -21
  249. package/clinkx-workflows/dist/schema.js +10 -1
  250. package/clinkx-workflows/dist/schema.js.map +1 -1
  251. package/clinkx-workflows/dist/seed-terms.d.ts +30 -0
  252. package/clinkx-workflows/dist/seed-terms.js +176 -0
  253. package/clinkx-workflows/dist/seed-terms.js.map +1 -0
  254. package/clinkx-workflows/dist/server.d.ts +5 -2
  255. package/clinkx-workflows/dist/server.js +82 -52
  256. package/clinkx-workflows/dist/server.js.map +1 -1
  257. package/clinkx-workflows/dist/shutdown.d.ts +18 -20
  258. package/clinkx-workflows/dist/shutdown.js +43 -61
  259. package/clinkx-workflows/dist/shutdown.js.map +1 -1
  260. package/clinkx-workflows/dist/state-schema.d.ts +38 -0
  261. package/clinkx-workflows/dist/state.d.ts +170 -3
  262. package/clinkx-workflows/dist/state.js +1275 -28
  263. package/clinkx-workflows/dist/state.js.map +1 -1
  264. package/clinkx-workflows/dist/transport.d.ts +15 -0
  265. package/clinkx-workflows/dist/transport.js +19 -10
  266. package/clinkx-workflows/dist/transport.js.map +1 -1
  267. package/clinkx-workflows/dist/types.d.ts +14 -2
  268. package/clinkx-workflows/dist/validators/council.d.ts +318 -85
  269. package/clinkx-workflows/dist/validators/council.js +52 -13
  270. package/clinkx-workflows/dist/validators/council.js.map +1 -1
  271. package/clinkx-workflows/dist/validators/index.d.ts +1 -0
  272. package/clinkx-workflows/dist/validators/index.js +3 -0
  273. package/clinkx-workflows/dist/validators/index.js.map +1 -1
  274. package/clinkx-workflows/dist/validators/plan-review.d.ts +398 -0
  275. package/clinkx-workflows/dist/validators/plan-review.js +316 -0
  276. package/clinkx-workflows/dist/validators/plan-review.js.map +1 -0
  277. package/clinkx-workflows/dist/workflow-receipt.js +188 -4
  278. package/clinkx-workflows/dist/workflow-receipt.js.map +1 -1
  279. package/clinkx-workflows/dist/workflow-tools.d.ts +48 -3
  280. package/clinkx-workflows/dist/workflow-tools.js +1402 -59
  281. package/clinkx-workflows/dist/workflow-tools.js.map +1 -1
  282. package/clinkx-workflows/dist/workspace-signature.d.ts +16 -0
  283. package/clinkx-workflows/dist/workspace-signature.js +388 -0
  284. package/clinkx-workflows/dist/workspace-signature.js.map +1 -0
  285. package/clinkx-workflows/templates/council/answer-specialist.txt +2 -1
  286. package/clinkx-workflows/templates/council/code-review-chairman.txt +13 -0
  287. package/clinkx-workflows/templates/council/code-review-cross-reviewer.txt +4 -1
  288. package/clinkx-workflows/templates/council/code-review-reviewer.txt +19 -3
  289. package/clinkx-workflows/templates/council/debug-debugger.txt +2 -1
  290. package/clinkx-workflows/templates/council/discover-analyst.txt +2 -1
  291. package/clinkx-workflows/templates/council/member.txt +2 -1
  292. package/clinkx-workflows/templates/council/plan-review-chairman.txt +68 -0
  293. package/clinkx-workflows/templates/council/plan-review-cross-reviewer.txt +51 -0
  294. package/clinkx-workflows/templates/council/plan-review-reviewer.txt +60 -0
  295. package/clinkx-workflows/templates/plan-review/chairman.txt +48 -0
  296. package/clinkx-workflows/templates/plan-review/cross-review.txt +52 -0
  297. package/clinkx-workflows/templates/plan-review/ranking.txt +16 -0
  298. package/clinkx-workflows/templates/plan-review/reviewer.txt +57 -0
  299. package/clinkx-workflows/workflows/council-answer.yaml +97 -8
  300. package/clinkx-workflows/workflows/council-code-review.yaml +103 -8
  301. package/clinkx-workflows/workflows/council-debug.yaml +97 -8
  302. package/clinkx-workflows/workflows/council-default.yaml +97 -8
  303. package/clinkx-workflows/workflows/council-discover.yaml +97 -8
  304. package/clinkx-workflows/workflows/council-plan-review.yaml +250 -0
  305. package/clinkx-workflows/workflows/plan-review-receipts.yaml +230 -0
  306. package/conf/adapters/agy.json +49 -0
  307. package/conf/adapters/claude.json +5 -0
  308. package/conf/adapters/codex-app-server.json +44 -0
  309. package/conf/adapters/codex.json +7 -2
  310. package/conf/adapters/glm.json +5 -0
  311. package/conf/adapters/grok.json +60 -0
  312. package/conf/adapters/hapi/agy.json +52 -0
  313. package/conf/adapters/hapi/claude.json +5 -0
  314. package/conf/adapters/hapi/codex.json +7 -2
  315. package/conf/adapters/hapi/glm.json +5 -0
  316. package/dist/activity-journal.d.ts +42 -0
  317. package/dist/activity-journal.js +381 -0
  318. package/dist/activity-journal.js.map +1 -0
  319. package/dist/allowed-roots.d.ts +41 -0
  320. package/dist/allowed-roots.js +125 -3
  321. package/dist/allowed-roots.js.map +1 -1
  322. package/dist/codex/activity-session-log.d.ts +14 -0
  323. package/dist/codex/activity-session-log.js +206 -0
  324. package/dist/codex/activity-session-log.js.map +1 -0
  325. package/dist/codex/agent-tools.d.ts +23 -0
  326. package/dist/codex/agent-tools.js +1270 -0
  327. package/dist/codex/agent-tools.js.map +1 -0
  328. package/dist/codex/app-server-client.d.ts +76 -0
  329. package/dist/codex/app-server-client.js +582 -0
  330. package/dist/codex/app-server-client.js.map +1 -0
  331. package/dist/codex/app-server-registry.d.ts +389 -0
  332. package/dist/codex/app-server-registry.js +1407 -0
  333. package/dist/codex/app-server-registry.js.map +1 -0
  334. package/dist/codex/client-types.d.ts +109 -0
  335. package/dist/codex/client-types.js +2 -0
  336. package/dist/codex/client-types.js.map +1 -0
  337. package/dist/codex/protocol.d.ts +5375 -0
  338. package/dist/codex/protocol.js +614 -0
  339. package/dist/codex/protocol.js.map +1 -0
  340. package/dist/codex/session.d.ts +263 -0
  341. package/dist/codex/session.js +466 -0
  342. package/dist/codex/session.js.map +1 -0
  343. package/dist/config.d.ts +185 -19
  344. package/dist/config.js +82 -16
  345. package/dist/config.js.map +1 -1
  346. package/dist/context-builder/anchors.d.ts +1 -0
  347. package/dist/context-builder/anchors.js +3 -0
  348. package/dist/context-builder/anchors.js.map +1 -1
  349. package/dist/context-builder/bundle.d.ts +35 -2
  350. package/dist/context-builder/bundle.js +342 -2417
  351. package/dist/context-builder/bundle.js.map +1 -1
  352. package/dist/context-builder/codemap.d.ts +5 -0
  353. package/dist/context-builder/codemap.js +387 -13
  354. package/dist/context-builder/codemap.js.map +1 -1
  355. package/dist/context-builder/config.d.ts +1 -0
  356. package/dist/context-builder/config.js +12 -0
  357. package/dist/context-builder/config.js.map +1 -1
  358. package/dist/context-builder/context-run-catalog.d.ts +17 -0
  359. package/dist/context-builder/context-run-catalog.js +99 -0
  360. package/dist/context-builder/context-run-catalog.js.map +1 -0
  361. package/dist/context-builder/delegate-packet.d.ts +37 -0
  362. package/dist/context-builder/delegate-packet.js +359 -67
  363. package/dist/context-builder/delegate-packet.js.map +1 -1
  364. package/dist/context-builder/delegate-validation.d.ts +10 -1
  365. package/dist/context-builder/delegate-validation.js +153 -41
  366. package/dist/context-builder/delegate-validation.js.map +1 -1
  367. package/dist/context-builder/delegate.d.ts +2 -0
  368. package/dist/context-builder/delegate.js +1 -0
  369. package/dist/context-builder/delegate.js.map +1 -1
  370. package/dist/context-builder/diagnostics.d.ts +11 -2
  371. package/dist/context-builder/diagnostics.js +39 -6
  372. package/dist/context-builder/diagnostics.js.map +1 -1
  373. package/dist/context-builder/discovery.d.ts +29 -1
  374. package/dist/context-builder/discovery.js +475 -175
  375. package/dist/context-builder/discovery.js.map +1 -1
  376. package/dist/context-builder/globs.js +10 -10
  377. package/dist/context-builder/globs.js.map +1 -1
  378. package/dist/context-builder/handler.d.ts +26 -2
  379. package/dist/context-builder/handler.js +1158 -2416
  380. package/dist/context-builder/handler.js.map +1 -1
  381. package/dist/context-builder/lifecycle-contract.d.ts +424 -0
  382. package/dist/context-builder/lifecycle-contract.js +523 -0
  383. package/dist/context-builder/lifecycle-contract.js.map +1 -0
  384. package/dist/context-builder/lifecycle-journal.d.ts +62 -0
  385. package/dist/context-builder/lifecycle-journal.js +88 -0
  386. package/dist/context-builder/lifecycle-journal.js.map +1 -0
  387. package/dist/context-builder/lifecycle-observer.d.ts +102 -0
  388. package/dist/context-builder/lifecycle-observer.js +258 -0
  389. package/dist/context-builder/lifecycle-observer.js.map +1 -0
  390. package/dist/context-builder/lifecycle-reconcile.d.ts +32 -0
  391. package/dist/context-builder/lifecycle-reconcile.js +191 -0
  392. package/dist/context-builder/lifecycle-reconcile.js.map +1 -0
  393. package/dist/context-builder/lifecycle-recovery.d.ts +2 -0
  394. package/dist/context-builder/lifecycle-recovery.js +14 -0
  395. package/dist/context-builder/lifecycle-recovery.js.map +1 -0
  396. package/dist/context-builder/path-signals.js +9 -5
  397. package/dist/context-builder/path-signals.js.map +1 -1
  398. package/dist/context-builder/progress.d.ts +3 -1
  399. package/dist/context-builder/progress.js +23 -0
  400. package/dist/context-builder/progress.js.map +1 -1
  401. package/dist/context-builder/receipt.d.ts +6 -4
  402. package/dist/context-builder/receipt.js +12 -1
  403. package/dist/context-builder/receipt.js.map +1 -1
  404. package/dist/context-builder/refine-handler.d.ts +14 -0
  405. package/dist/context-builder/refine-handler.js +790 -0
  406. package/dist/context-builder/refine-handler.js.map +1 -0
  407. package/dist/context-builder/review-coverage.d.ts +84 -0
  408. package/dist/context-builder/review-coverage.js +437 -0
  409. package/dist/context-builder/review-coverage.js.map +1 -0
  410. package/dist/context-builder/schema.d.ts +239 -1
  411. package/dist/context-builder/schema.js +112 -6
  412. package/dist/context-builder/schema.js.map +1 -1
  413. package/dist/context-builder/secrets.d.ts +28 -0
  414. package/dist/context-builder/secrets.js +1473 -44
  415. package/dist/context-builder/secrets.js.map +1 -1
  416. package/dist/context-builder/selection.d.ts +7 -3
  417. package/dist/context-builder/selection.js +200 -738
  418. package/dist/context-builder/selection.js.map +1 -1
  419. package/dist/context-builder/session-log-identity.d.ts +1 -0
  420. package/dist/context-builder/session-log-identity.js +66 -0
  421. package/dist/context-builder/session-log-identity.js.map +1 -0
  422. package/dist/context-builder/slice-range-math.d.ts +16 -0
  423. package/dist/context-builder/slice-range-math.js +137 -0
  424. package/dist/context-builder/slice-range-math.js.map +1 -0
  425. package/dist/context-builder/status.d.ts +22 -1
  426. package/dist/context-builder/status.js +59 -4
  427. package/dist/context-builder/status.js.map +1 -1
  428. package/dist/context-builder/storage.d.ts +35 -2
  429. package/dist/context-builder/storage.js +271 -14
  430. package/dist/context-builder/storage.js.map +1 -1
  431. package/dist/context-builder/token-estimate.d.ts +13 -2
  432. package/dist/context-builder/token-estimate.js +77 -4
  433. package/dist/context-builder/token-estimate.js.map +1 -1
  434. package/dist/context-builder/versions.d.ts +29 -0
  435. package/dist/context-builder/versions.js +30 -0
  436. package/dist/context-builder/versions.js.map +1 -0
  437. package/dist/context-builder/workflow-runner.d.ts +69 -0
  438. package/dist/context-builder/workflow-runner.js +1051 -0
  439. package/dist/context-builder/workflow-runner.js.map +1 -0
  440. package/dist/context-builder/write-watchdog.d.ts +14 -0
  441. package/dist/context-builder/write-watchdog.js +38 -0
  442. package/dist/context-builder/write-watchdog.js.map +1 -0
  443. package/dist/dashboard-adapter-catalog.d.ts +9 -0
  444. package/dist/dashboard-adapter-catalog.js +46 -0
  445. package/dist/dashboard-adapter-catalog.js.map +1 -0
  446. package/dist/dashboard-cli.d.ts +79 -0
  447. package/dist/dashboard-cli.js +585 -0
  448. package/dist/dashboard-cli.js.map +1 -0
  449. package/dist/dashboard-companion/client.d.ts +36 -0
  450. package/dist/dashboard-companion/client.js +210 -0
  451. package/dist/dashboard-companion/client.js.map +1 -0
  452. package/dist/dashboard-companion/config.d.ts +8 -0
  453. package/dist/dashboard-companion/config.js +52 -0
  454. package/dist/dashboard-companion/config.js.map +1 -0
  455. package/dist/dashboard-companion/http-proxy.d.ts +10 -0
  456. package/dist/dashboard-companion/http-proxy.js +234 -0
  457. package/dist/dashboard-companion/http-proxy.js.map +1 -0
  458. package/dist/dashboard-companion/protocol.d.ts +80 -0
  459. package/dist/dashboard-companion/protocol.js +455 -0
  460. package/dist/dashboard-companion/protocol.js.map +1 -0
  461. package/dist/dashboard-companion/standalone-assets.d.ts +12 -0
  462. package/dist/dashboard-companion/standalone-assets.js +72 -0
  463. package/dist/dashboard-companion/standalone-assets.js.map +1 -0
  464. package/dist/dashboard-companion/standalone-entry.d.ts +1 -0
  465. package/dist/dashboard-companion/standalone-entry.js +17 -0
  466. package/dist/dashboard-companion/standalone-entry.js.map +1 -0
  467. package/dist/dashboard-gateway/config.d.ts +9 -0
  468. package/dist/dashboard-gateway/config.js +44 -0
  469. package/dist/dashboard-gateway/config.js.map +1 -0
  470. package/dist/dashboard-gateway/index.d.ts +11 -0
  471. package/dist/dashboard-gateway/index.js +755 -0
  472. package/dist/dashboard-gateway/index.js.map +1 -0
  473. package/dist/dashboard-gateway/main.d.ts +1 -0
  474. package/dist/dashboard-gateway/main.js +25 -0
  475. package/dist/dashboard-gateway/main.js.map +1 -0
  476. package/dist/dashboard-pairing-token.d.ts +1 -0
  477. package/dist/dashboard-pairing-token.js +5 -0
  478. package/dist/dashboard-pairing-token.js.map +1 -0
  479. package/dist/elaris/client.d.ts +73 -0
  480. package/dist/elaris/client.js +825 -0
  481. package/dist/elaris/client.js.map +1 -0
  482. package/dist/elaris/config.d.ts +18 -0
  483. package/dist/elaris/config.js +75 -0
  484. package/dist/elaris/config.js.map +1 -0
  485. package/dist/elaris/errors.d.ts +41 -0
  486. package/dist/elaris/errors.js +205 -0
  487. package/dist/elaris/errors.js.map +1 -0
  488. package/dist/elaris/github-repo.d.ts +18 -0
  489. package/dist/elaris/github-repo.js +89 -0
  490. package/dist/elaris/github-repo.js.map +1 -0
  491. package/dist/elaris/index.d.ts +10 -0
  492. package/dist/elaris/index.js +11 -0
  493. package/dist/elaris/index.js.map +1 -0
  494. package/dist/elaris/redact.d.ts +89 -0
  495. package/dist/elaris/redact.js +423 -0
  496. package/dist/elaris/redact.js.map +1 -0
  497. package/dist/elaris/run-id.d.ts +5 -0
  498. package/dist/elaris/run-id.js +20 -0
  499. package/dist/elaris/run-id.js.map +1 -0
  500. package/dist/elaris/status.d.ts +45 -0
  501. package/dist/elaris/status.js +122 -0
  502. package/dist/elaris/status.js.map +1 -0
  503. package/dist/elaris/tool-schemas.d.ts +314 -0
  504. package/dist/elaris/tool-schemas.js +208 -0
  505. package/dist/elaris/tool-schemas.js.map +1 -0
  506. package/dist/elaris/tools.d.ts +73 -0
  507. package/dist/elaris/tools.js +1065 -0
  508. package/dist/elaris/tools.js.map +1 -0
  509. package/dist/elaris/types.d.ts +1541 -0
  510. package/dist/elaris/types.js +252 -0
  511. package/dist/elaris/types.js.map +1 -0
  512. package/dist/errors.d.ts +16 -0
  513. package/dist/errors.js +19 -0
  514. package/dist/errors.js.map +1 -1
  515. package/dist/handler.d.ts +4 -0
  516. package/dist/handler.js +10 -1
  517. package/dist/handler.js.map +1 -1
  518. package/dist/index.d.ts +2 -1
  519. package/dist/index.js +13 -3
  520. package/dist/index.js.map +1 -1
  521. package/dist/local-clink-backend.d.ts +3 -0
  522. package/dist/local-clink-backend.js +4 -0
  523. package/dist/local-clink-backend.js.map +1 -1
  524. package/dist/package-info.d.ts +2 -0
  525. package/dist/package-info.js +18 -0
  526. package/dist/package-info.js.map +1 -0
  527. package/dist/parsers/codex-jsonl.js +48 -3
  528. package/dist/parsers/codex-jsonl.js.map +1 -1
  529. package/dist/parsers/extract.d.ts +10 -1
  530. package/dist/parsers/extract.js +11 -3
  531. package/dist/parsers/extract.js.map +1 -1
  532. package/dist/pipeline.d.ts +4 -0
  533. package/dist/pipeline.js +129 -8
  534. package/dist/pipeline.js.map +1 -1
  535. package/dist/run-dir.d.ts +24 -0
  536. package/dist/run-dir.js +201 -2
  537. package/dist/run-dir.js.map +1 -1
  538. package/dist/runner.d.ts +13 -0
  539. package/dist/runner.js +184 -15
  540. package/dist/runner.js.map +1 -1
  541. package/dist/safety.d.ts +4 -4
  542. package/dist/safety.js +4 -4
  543. package/dist/schema.d.ts +7 -7
  544. package/dist/server.d.ts +1 -0
  545. package/dist/server.js +359 -17
  546. package/dist/server.js.map +1 -1
  547. package/dist/session-log-stream.d.ts +18 -0
  548. package/dist/session-log-stream.js +319 -0
  549. package/dist/session-log-stream.js.map +1 -0
  550. package/package.json +46 -5
  551. package/conf/adapters/gemini.json +0 -44
  552. package/conf/adapters/hapi/gemini.json +0 -47
  553. package/dist/parsers/gemini-json.d.ts +0 -2
  554. package/dist/parsers/gemini-json.js +0 -72
  555. package/dist/parsers/gemini-json.js.map +0 -1
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Deterministic seed-term synthesis (Plan Phase 5, tasks 5-1/5-2/5-3).
3
+ *
4
+ * Pure function: no clock, no RNG, no LLM, no I/O. Identical input always
5
+ * yields a byte-identical array (verified by tests/seed-terms.test.ts).
6
+ *
7
+ * Used to seed context_builder discovery when a workflow runs preflight in
8
+ * `full`/`deterministic` mode but the caller supplied neither focus paths nor
9
+ * search terms (wiring lives in Phase 3 — not here).
10
+ *
11
+ * Algorithm (pinned in plan task 5-3, authoritative):
12
+ * 1. Preserve quoted phrases, then camelCase/snake_case/dotted identifiers as
13
+ * WHOLE terms before any prose splitting (5-2).
14
+ * 2. Lowercase and split the remaining prose; drop the fixed 21-word stop set
15
+ * and tokens shorter than 3 chars (5-3).
16
+ * 3. Dedupe case-insensitively; rank by `score = frequency + lengthBonus`
17
+ * with a first-seen tie-break; cap at 12 terms (5-3).
18
+ */
19
+ export declare const MAX_SEED_SOURCE_CHARACTERS = 4000;
20
+ export declare const MAX_CONTEXT_SEARCH_TERMS = 20;
21
+ export declare const MAX_CONTEXT_SEARCH_TERM_CODE_POINTS = 256;
22
+ export declare const MAX_CONTEXT_SEARCH_TERMS_UTF8_BYTES = 4096;
23
+ /** Resolve the workflow context task using the runner's nonblank cb_task rule. */
24
+ export declare function resolveSeedSource(cbTask: string | undefined, userRequest: string | undefined): string;
25
+ /** Match the root task schema's trim-before-max character bound. */
26
+ export declare function seedSourceExceedsLimit(seedSource: string): boolean;
27
+ /** Match the root NonBlankStringSchema + post-parse task bound. */
28
+ export declare function contextSeedSourceValidationError(seedSource: string): string | undefined;
29
+ export declare function contextSearchTermsValidationError(searchTerms: readonly string[]): string | undefined;
30
+ export declare function synthesizeSeedTerms(text: string): string[];
@@ -0,0 +1,176 @@
1
+ /**
2
+ * Deterministic seed-term synthesis (Plan Phase 5, tasks 5-1/5-2/5-3).
3
+ *
4
+ * Pure function: no clock, no RNG, no LLM, no I/O. Identical input always
5
+ * yields a byte-identical array (verified by tests/seed-terms.test.ts).
6
+ *
7
+ * Used to seed context_builder discovery when a workflow runs preflight in
8
+ * `full`/`deterministic` mode but the caller supplied neither focus paths nor
9
+ * search terms (wiring lives in Phase 3 — not here).
10
+ *
11
+ * Algorithm (pinned in plan task 5-3, authoritative):
12
+ * 1. Preserve quoted phrases, then camelCase/snake_case/dotted identifiers as
13
+ * WHOLE terms before any prose splitting (5-2).
14
+ * 2. Lowercase and split the remaining prose; drop the fixed 21-word stop set
15
+ * and tokens shorter than 3 chars (5-3).
16
+ * 3. Dedupe case-insensitively; rank by `score = frequency + lengthBonus`
17
+ * with a first-seen tie-break; cap at 12 terms (5-3).
18
+ */
19
+ /** Fixed stop-word set — exactly the 21 words pinned in plan task 5-3. */
20
+ const STOP_WORDS = new Set([
21
+ "the", "a", "an", "of", "to", "and", "or", "is", "are", "for", "with",
22
+ "on", "in", "this", "that", "please", "add", "fix", "make", "use", "run",
23
+ ]);
24
+ const MIN_TERM_LENGTH = 3;
25
+ const MAX_TERMS = 12;
26
+ export const MAX_SEED_SOURCE_CHARACTERS = 4000;
27
+ export const MAX_CONTEXT_SEARCH_TERMS = 20;
28
+ export const MAX_CONTEXT_SEARCH_TERM_CODE_POINTS = 256;
29
+ export const MAX_CONTEXT_SEARCH_TERMS_UTF8_BYTES = 4_096;
30
+ /** Resolve the workflow context task using the runner's nonblank cb_task rule. */
31
+ export function resolveSeedSource(cbTask, userRequest) {
32
+ return cbTask != null && cbTask.trim() !== "" ? cbTask : userRequest ?? "";
33
+ }
34
+ /** Match the root task schema's trim-before-max character bound. */
35
+ export function seedSourceExceedsLimit(seedSource) {
36
+ return seedSource.trim().length > MAX_SEED_SOURCE_CHARACTERS;
37
+ }
38
+ /** Match the root NonBlankStringSchema + post-parse task bound. */
39
+ export function contextSeedSourceValidationError(seedSource) {
40
+ const normalized = seedSource.trim();
41
+ if (normalized.length === 0) {
42
+ return "Context seed source must be nonblank after trimming";
43
+ }
44
+ if (normalized.length > MAX_SEED_SOURCE_CHARACTERS) {
45
+ return `Context seed source must be at most ${String(MAX_SEED_SOURCE_CHARACTERS)} characters`;
46
+ }
47
+ return undefined;
48
+ }
49
+ export function contextSearchTermsValidationError(searchTerms) {
50
+ if (searchTerms.length > MAX_CONTEXT_SEARCH_TERMS) {
51
+ return `context_builder search_terms must contain at most ${String(MAX_CONTEXT_SEARCH_TERMS)} terms`;
52
+ }
53
+ let aggregateBytes = 0;
54
+ for (const [index, rawTerm] of searchTerms.entries()) {
55
+ const term = rawTerm.trim();
56
+ if (term.length === 0) {
57
+ return `context_builder search_terms[${String(index)}] must be nonblank after trimming`;
58
+ }
59
+ if (countCodePoints(term) > MAX_CONTEXT_SEARCH_TERM_CODE_POINTS) {
60
+ return `context_builder search_terms[${String(index)}] must be <= ${String(MAX_CONTEXT_SEARCH_TERM_CODE_POINTS)} characters`;
61
+ }
62
+ aggregateBytes += Buffer.byteLength(term, "utf8");
63
+ }
64
+ if (aggregateBytes > MAX_CONTEXT_SEARCH_TERMS_UTF8_BYTES) {
65
+ return `context_builder search_terms must total <= ${String(MAX_CONTEXT_SEARCH_TERMS_UTF8_BYTES)} UTF-8 bytes after trimming`;
66
+ }
67
+ return undefined;
68
+ }
69
+ function countCodePoints(value) {
70
+ let count = 0;
71
+ for (const _character of value) {
72
+ count += 1;
73
+ }
74
+ return count;
75
+ }
76
+ function termFitsPublicChannel(term) {
77
+ return countCodePoints(term.trim()) <= MAX_CONTEXT_SEARCH_TERM_CODE_POINTS;
78
+ }
79
+ /**
80
+ * Pinned, pure length bonus in [0, 1]: monotonic non-decreasing in length,
81
+ * saturating at 12 chars. Fixed rational of the term length — no clock/RNG —
82
+ * which keeps scoring (and therefore ordering) byte-deterministic.
83
+ */
84
+ function lengthBonus(term) {
85
+ return Math.min(term.length, 12) / 12;
86
+ }
87
+ /**
88
+ * A token qualifies as a preservable identifier when it contains an internal
89
+ * underscore (snake_case), an internal dot (dotted identifier), or a
90
+ * lower→upper transition (camelCase / PascalCase). "Internal" means an
91
+ * alphanumeric on both sides, so a trailing sentence dot does not qualify.
92
+ */
93
+ function isPreservableIdentifier(token) {
94
+ if (/[A-Za-z0-9]_[A-Za-z0-9]/.test(token))
95
+ return true;
96
+ if (/[A-Za-z0-9]\.[A-Za-z0-9]/.test(token))
97
+ return true;
98
+ if (/[a-z][A-Z]/.test(token))
99
+ return true;
100
+ return false;
101
+ }
102
+ export function synthesizeSeedTerms(text) {
103
+ if (typeof text !== "string" || text.trim() === "") {
104
+ return [];
105
+ }
106
+ // First-seen-ordered accumulation. `order` holds dedup keys in the order they
107
+ // first appear; `firstForm` records the surface form to emit; `freq` counts
108
+ // case-insensitive occurrences for scoring.
109
+ const order = [];
110
+ const firstForm = new Map();
111
+ const freq = new Map();
112
+ const consider = (term) => {
113
+ const key = term.toLowerCase();
114
+ const current = freq.get(key);
115
+ if (current === undefined) {
116
+ freq.set(key, 1);
117
+ firstForm.set(key, term);
118
+ order.push(key);
119
+ }
120
+ else {
121
+ freq.set(key, current + 1);
122
+ }
123
+ };
124
+ // 5-2: preserve quoted phrases as whole terms, then blank them out so the
125
+ // identifier/prose passes never re-split their contents.
126
+ let working = text.replace(/"([^"]+)"|'([^']+)'/g, (_match, dq, sq) => {
127
+ const phrase = (dq ?? sq ?? "").trim();
128
+ if (phrase === "")
129
+ return " ";
130
+ consider(phrase);
131
+ return termFitsPublicChannel(phrase) ? " " : ` ${phrase} `;
132
+ });
133
+ // 5-2: preserve camelCase/snake_case/dotted identifiers as whole terms,
134
+ // blanking only the ones we preserve so plain words flow to the prose pass.
135
+ working = working.replace(/[A-Za-z0-9_.]+/g, (token) => {
136
+ if (isPreservableIdentifier(token)) {
137
+ consider(token);
138
+ return termFitsPublicChannel(token) ? " " : token;
139
+ }
140
+ return token;
141
+ });
142
+ // 5-3: lowercase the remaining prose, split into alphanumeric tokens, drop
143
+ // stop words and sub-3-char tokens.
144
+ const proseTokens = working.toLowerCase().match(/[a-z0-9]+/g) ?? [];
145
+ for (const token of proseTokens) {
146
+ if (token.length < MIN_TERM_LENGTH)
147
+ continue;
148
+ if (STOP_WORDS.has(token))
149
+ continue;
150
+ consider(token);
151
+ }
152
+ // 5-3: rank by score = frequency + lengthBonus, first-seen tie-break, cap 12.
153
+ const ranked = order.map((key, idx) => {
154
+ const term = firstForm.get(key);
155
+ return { term, idx, score: freq.get(key) + lengthBonus(term) };
156
+ });
157
+ ranked.sort((a, b) => (b.score !== a.score ? b.score - a.score : a.idx - b.idx));
158
+ const selected = [];
159
+ let aggregateBytes = 0;
160
+ for (const { term } of ranked) {
161
+ if (selected.length >= MAX_TERMS) {
162
+ break;
163
+ }
164
+ if (!termFitsPublicChannel(term)) {
165
+ continue;
166
+ }
167
+ const termBytes = Buffer.byteLength(term.trim(), "utf8");
168
+ if (aggregateBytes + termBytes > MAX_CONTEXT_SEARCH_TERMS_UTF8_BYTES) {
169
+ continue;
170
+ }
171
+ selected.push(term);
172
+ aggregateBytes += termBytes;
173
+ }
174
+ return selected;
175
+ }
176
+ //# sourceMappingURL=seed-terms.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"seed-terms.js","sourceRoot":"","sources":["../src/seed-terms.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,0EAA0E;AAC1E,MAAM,UAAU,GAAwB,IAAI,GAAG,CAAC;IAC9C,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM;IACrE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK;CACzE,CAAC,CAAC;AAEH,MAAM,eAAe,GAAG,CAAC,CAAC;AAC1B,MAAM,SAAS,GAAG,EAAE,CAAC;AACrB,MAAM,CAAC,MAA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,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IAEjF,MAAM,QAAQ,GAAa,EAAE,CAAC;IAC9B,IAAI,cAAc,GAAG,CAAC,CAAC;IACvB,KAAK,MAAM,EAAE,IAAI,EAAE,IAAI,MAAM,EAAE,CAAC;QAC9B,IAAI,QAAQ,CAAC,MAAM,IAAI,SAAS,EAAE,CAAC;YACjC,MAAM;QACR,CAAC;QACD,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,EAAE,CAAC;YACjC,SAAS;QACX,CAAC;QACD,MAAM,SAAS,GAAG,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,MAAM,CAAC,CAAC;QACzD,IAAI,cAAc,GAAG,SAAS,GAAG,mCAAmC,EAAE,CAAC;YACrE,SAAS;QACX,CAAC;QACD,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACpB,cAAc,IAAI,SAAS,CAAC;IAC9B,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
@@ -9,7 +9,8 @@ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
9
9
  /**
10
10
  * Create the clinkx-workflows MCP server.
11
11
  *
12
- * Registers three tools: run_workflow, resume_workflow, list_workflows.
12
+ * Registers five tools: run_workflow, resume_workflow, list_workflows,
13
+ * workflow_run_status, cancel_workflow.
13
14
  * Uses ClinkSession (child process) as the backend.
14
15
  * Does NOT connect transport — caller is responsible.
15
16
  *
@@ -18,6 +19,8 @@ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
18
19
  * standalone server schema enum injection and parse-time validation
19
20
  * without requiring the caller to wire discovery manually.
20
21
  */
22
+ export type WorkflowServer = Server;
21
23
  export declare function createWorkflowServer(options?: {
22
24
  availableCliNames?: readonly string[];
23
- }): Server;
25
+ asyncAdmissionCap?: number;
26
+ }): WorkflowServer;
@@ -8,52 +8,44 @@
8
8
  import { readdirSync, readFileSync, statSync } from "node:fs";
9
9
  import { join, extname } from "node:path";
10
10
  import { Server } from "@modelcontextprotocol/sdk/server/index.js";
11
- import { getChildConfigPath } from "./config.js";
11
+ import { getChildConfigPath, getRunsDir, hasExplicitWorkspaceRoot, resolveWorkspaceRoot, } from "./config.js";
12
12
  import { logger } from "./logger.js";
13
- import { ClinkSession } from "./transport.js";
13
+ import { reconcileStaleRunDirectories } from "./state.js";
14
+ import { ClinkSession, resolveClinkChildRuntime } from "./transport.js";
14
15
  import { registerWorkflowTools } from "./workflow-tools.js";
15
- // ---------------------------------------------------------------------------
16
- // Adapter name discovery
17
- // ---------------------------------------------------------------------------
18
- /**
19
- * Best-effort adapter name discovery from child config path.
20
- *
21
- * Reads CLINKX_WORKFLOWS_CHILD_CONFIG_PATH — supports both directory
22
- * (scan for .json files) and single-file paths, mirroring the path-
23
- * resolution behavior of AdapterRegistry.loadFromPath.
24
- *
25
- * This performs lightweight structural validation (requires `name` +
26
- * `command` fields) rather than full CliAdapterConfigSchema parsing,
27
- * which lives in the root package and cannot be imported without
28
- * creating a circular dependency. Runtime validation in the child
29
- * process remains the authoritative gate. Returns undefined when no
30
- * config path is set or no valid adapters are found.
31
- */
32
- function discoverChildAdapterNames() {
16
+ function discoverChildAdapters() {
33
17
  const configPath = getChildConfigPath();
34
18
  if (configPath == null)
35
19
  return undefined;
36
20
  try {
37
21
  const stat = statSync(configPath);
38
- const names = [];
22
+ const cliNames = [];
23
+ const planReviewCliNames = [];
24
+ const record = (entry) => {
25
+ if (entry == null)
26
+ return;
27
+ if (!cliNames.includes(entry.name))
28
+ cliNames.push(entry.name);
29
+ if (entry.hasJsonRole && !planReviewCliNames.includes(entry.name)) {
30
+ planReviewCliNames.push(entry.name);
31
+ }
32
+ };
39
33
  if (stat.isFile()) {
40
34
  // Single-file config path
41
- const name = extractAdapterName(configPath);
42
- if (name != null)
43
- names.push(name);
35
+ record(extractAdapter(configPath));
44
36
  }
45
37
  else if (stat.isDirectory()) {
46
38
  // Directory config path — scan for .json files
47
- const files = readdirSync(configPath).filter((f) => extname(f) === ".json");
39
+ const files = readdirSync(configPath)
40
+ .filter((f) => extname(f) === ".json")
41
+ .sort();
48
42
  for (const file of files) {
49
- const name = extractAdapterName(join(configPath, file));
50
- if (name != null)
51
- names.push(name);
43
+ record(extractAdapter(join(configPath, file)));
52
44
  }
53
45
  }
54
- if (names.length > 0) {
55
- logger.debug({ names, configPath }, "discovered child adapter names for standalone server");
56
- return names;
46
+ if (cliNames.length > 0) {
47
+ logger.debug({ names: cliNames, planReviewNames: planReviewCliNames, configPath }, "discovered child adapter names for standalone server");
48
+ return { cliNames, planReviewCliNames };
57
49
  }
58
50
  }
59
51
  catch (err) {
@@ -62,19 +54,35 @@ function discoverChildAdapterNames() {
62
54
  return undefined;
63
55
  }
64
56
  /**
65
- * Extract the adapter name from a config JSON file.
57
+ * Extract adapter name (+ plan-review role eligibility) from a config JSON file.
66
58
  *
67
59
  * Requires both `name` (string) and `command` (string) fields to be
68
60
  * present — the two mandatory fields in any valid adapter config.
69
61
  * Skips files that don't meet this minimum bar.
62
+ *
63
+ * `backend: "app_server"` adapters are EXCLUDED. They are driven exclusively by
64
+ * the async `clink_agent_run` / `clink_agent_manage` tools; the synchronous
65
+ * pipeline every workflow seat runs through rejects them with `-32602`. Naming
66
+ * one in a workflow enum would advertise a seat that can only fail at dispatch.
67
+ * The root server filters these already; this is the standalone path, which the
68
+ * removal of the `eligible:false` bit left unguarded.
69
+ *
70
+ * Plan-review eligibility is presence of a `roles` object with a `"json"` key
71
+ * (raw JSON field read only — no AdapterRegistry import, no dependency cycle).
70
72
  */
71
- function extractAdapterName(filePath) {
73
+ function extractAdapter(filePath) {
72
74
  try {
73
75
  const raw = readFileSync(filePath, "utf-8");
74
76
  const parsed = JSON.parse(raw);
75
77
  if (typeof parsed["name"] === "string" && parsed["name"] !== "" &&
76
- typeof parsed["command"] === "string" && parsed["command"] !== "") {
77
- return parsed["name"];
78
+ typeof parsed["command"] === "string" && parsed["command"] !== "" &&
79
+ parsed["backend"] !== "app_server") {
80
+ const roles = parsed["roles"];
81
+ const hasJsonRole = roles != null &&
82
+ typeof roles === "object" &&
83
+ !Array.isArray(roles) &&
84
+ Object.prototype.hasOwnProperty.call(roles, "json");
85
+ return { name: parsed["name"], hasJsonRole };
78
86
  }
79
87
  }
80
88
  catch {
@@ -82,21 +90,6 @@ function extractAdapterName(filePath) {
82
90
  }
83
91
  return undefined;
84
92
  }
85
- // ---------------------------------------------------------------------------
86
- // Server factory
87
- // ---------------------------------------------------------------------------
88
- /**
89
- * Create the clinkx-workflows MCP server.
90
- *
91
- * Registers three tools: run_workflow, resume_workflow, list_workflows.
92
- * Uses ClinkSession (child process) as the backend.
93
- * Does NOT connect transport — caller is responsible.
94
- *
95
- * When `availableCliNames` is not explicitly provided, attempts to
96
- * discover adapter names from the child config path. This gives the
97
- * standalone server schema enum injection and parse-time validation
98
- * without requiring the caller to wire discovery manually.
99
- */
100
93
  export function createWorkflowServer(options) {
101
94
  const server = new Server({ name: "clinkx-workflows", version: "0.1.0" }, {
102
95
  capabilities: { tools: {} },
@@ -104,15 +97,52 @@ export function createWorkflowServer(options) {
104
97
  "Use run_workflow to start a new workflow, resume_workflow to continue a failed run, " +
105
98
  "or list_workflows to see available workflows.",
106
99
  });
100
+ // `resolveWorkspaceRoot()` silently falls back to process.cwd(), and an MCP
101
+ // server's cwd is chosen by the client — so the same request can pass or fail
102
+ // purely on where the client happened to spawn us. Surface the implicit root
103
+ // instead of leaving it invisible (config.ts cannot log: logger imports it).
104
+ if (!hasExplicitWorkspaceRoot()) {
105
+ logger.warn({
106
+ env_var: "CLINKX_WORKFLOWS_WORKSPACE_ROOT",
107
+ workspace_root: resolveWorkspaceRoot(),
108
+ cwd: process.cwd(),
109
+ }, "CLINKX_WORKFLOWS_WORKSPACE_ROOT is not set; defaulting the workflows workspace root to process.cwd(). " +
110
+ "This root governs plan_file containment and the workflow child process cwd, so workflow behavior " +
111
+ "depends on the cwd the MCP client spawned this server with. Set CLINKX_WORKFLOWS_WORKSPACE_ROOT explicitly.");
112
+ }
113
+ // One-time startup reconcile of runs frozen as running/pending with no live
114
+ // worker (fire-and-forget: bounded, idempotent, never blocks startup).
115
+ try {
116
+ void reconcileStaleRunDirectories(getRunsDir()).catch((err) => {
117
+ logger.warn({ err: err instanceof Error ? err.message : String(err) }, "startup stale workflow run reconcile failed");
118
+ });
119
+ }
120
+ catch (err) {
121
+ logger.warn({ err: err instanceof Error ? err.message : String(err) }, "startup stale workflow run reconcile could not be scheduled");
122
+ }
123
+ const childRuntime = resolveClinkChildRuntime();
107
124
  // Normalize empty arrays to undefined — an empty list would suppress schema
108
125
  // hints while still enabling validation (rejecting all adapter names).
109
126
  const explicit = options?.availableCliNames;
127
+ const discovered = explicit != null && explicit.length > 0
128
+ ? undefined
129
+ : discoverChildAdapters();
110
130
  const cliNames = (explicit != null && explicit.length > 0)
111
131
  ? explicit
112
- : discoverChildAdapterNames();
132
+ : discovered?.cliNames;
133
+ // When the caller supplies availableCliNames explicitly, they own filtering
134
+ // (or accept the availableCliNames fallback in workflow-tools). Auto-discovery
135
+ // always supplies the roles.json-filtered plan-review set.
136
+ const planReviewCliNames = discovered?.planReviewCliNames;
113
137
  registerWorkflowTools(server, {
114
- createBackend: (runId) => new ClinkSession({ runId }),
138
+ createBackend: (runId) => new ClinkSession({ runId, runtime: childRuntime }),
115
139
  ...(cliNames != null ? { availableCliNames: cliNames } : {}),
140
+ ...(planReviewCliNames != null
141
+ ? { planReviewAvailableCliNames: planReviewCliNames }
142
+ : {}),
143
+ ...(options?.asyncAdmissionCap != null
144
+ ? { asyncAdmissionCap: options.asyncAdmissionCap }
145
+ : {}),
116
146
  });
117
147
  return server;
118
148
  }
@@ -1 +1 @@
1
- {"version":3,"file":"server.js","sourceRoot":"","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
+ /** Opaque handle returned by register(); identifies a single run's entry. */
15
+ export type ShutdownHandle = number;
14
16
  /**
15
17
  * Manages graceful shutdown across signal handlers and MCP cancellation.
18
+ *
19
+ * Keyed registry: each run registers its own entry so concurrent runs (cap > 1)
20
+ * never clobber each other. Shutdown/cancel iterate over ALL registered entries.
16
21
  */
17
22
  export declare class ShutdownCoordinator {
18
- private state;
23
+ private readonly entries;
24
+ private nextHandle;
19
25
  private shuttingDown;
20
26
  /**
21
- * Register the active session and abort controller for this run.
22
- * Call at the start of each workflow run.
23
- */
24
- register(session: ClinkBackend, controller: AbortController, persistState: StatePersister): void;
25
- /**
26
- * Unregister the current run (on normal completion).
27
- */
28
- unregister(): void;
29
- /**
30
- * Get the AbortSignal for the current run.
31
- * Use this to propagate cancellation to in-flight calls.
27
+ * Register a run's session and abort controller. Returns an opaque handle
28
+ * to be passed to unregister(). Each call adds a new entry; existing entries
29
+ * are never clobbered.
32
30
  */
33
- get signal(): AbortSignal | undefined;
31
+ register(session: ClinkBackend, controller: AbortController, persistState: StatePersister): ShutdownHandle;
34
32
  /**
35
- * Cancel the current run (e.g., from MCP notifications/cancelled).
36
- * Aborts in-flight calls, persists state, terminates child.
37
- * Does NOT call process.exit — caller decides response behavior.
33
+ * Unregister a single run (on normal completion). Deletes only this handle's
34
+ * entry; other registered runs remain.
38
35
  */
39
- cancelRun(): Promise<void>;
36
+ unregister(handle: ShutdownHandle): void;
40
37
  /**
41
38
  * Handle process shutdown.
42
- * Cancel, persist, and terminate. The entrypoint owns process.exit.
39
+ * Cancel, persist, and terminate all registered runs. The entrypoint owns
40
+ * process.exit.
43
41
  */
44
42
  shutdown(signal: string): Promise<void>;
45
- private safePersistState;
46
- private safeTerminateSession;
43
+ /** Abort, persist, and terminate every registered entry (best-effort). */
44
+ private handleAll;
47
45
  }
48
46
  /** Singleton shutdown coordinator. */
49
47
  export declare const shutdownCoordinator: ShutdownCoordinator;
@@ -12,55 +12,36 @@
12
12
  import { logger } from "./logger.js";
13
13
  /**
14
14
  * Manages graceful shutdown across signal handlers and MCP cancellation.
15
+ *
16
+ * Keyed registry: each run registers its own entry so concurrent runs (cap > 1)
17
+ * never clobber each other. Shutdown/cancel iterate over ALL registered entries.
15
18
  */
16
19
  export class ShutdownCoordinator {
17
- state = {
18
- session: null,
19
- controller: null,
20
- persistState: null,
21
- };
20
+ entries = new Map();
21
+ nextHandle = 1;
22
22
  shuttingDown = false;
23
23
  /**
24
- * Register the active session and abort controller for this run.
25
- * Call at the start of each workflow run.
24
+ * Register a run's session and abort controller. Returns an opaque handle
25
+ * to be passed to unregister(). Each call adds a new entry; existing entries
26
+ * are never clobbered.
26
27
  */
27
28
  register(session, controller, persistState) {
28
- this.state = { session, controller, persistState };
29
- this.shuttingDown = false;
30
- }
31
- /**
32
- * Unregister the current run (on normal completion).
33
- */
34
- unregister() {
35
- this.state = { session: null, controller: null, persistState: null };
29
+ const handle = this.nextHandle;
30
+ this.nextHandle += 1;
31
+ this.entries.set(handle, { session, controller, persistState });
32
+ return handle;
36
33
  }
37
34
  /**
38
- * Get the AbortSignal for the current run.
39
- * Use this to propagate cancellation to in-flight calls.
35
+ * Unregister a single run (on normal completion). Deletes only this handle's
36
+ * entry; other registered runs remain.
40
37
  */
41
- get signal() {
42
- return this.state.controller?.signal;
43
- }
44
- /**
45
- * Cancel the current run (e.g., from MCP notifications/cancelled).
46
- * Aborts in-flight calls, persists state, terminates child.
47
- * Does NOT call process.exit — caller decides response behavior.
48
- */
49
- async cancelRun() {
50
- if (this.shuttingDown)
51
- return;
52
- this.shuttingDown = true;
53
- logger.info("cancelling current workflow run");
54
- // 1. Abort in-flight calls
55
- this.state.controller?.abort(new Error("Workflow cancelled"));
56
- // 2. Best-effort state persistence
57
- await this.safePersistState();
58
- // 3. Terminate child session
59
- await this.safeTerminateSession();
38
+ unregister(handle) {
39
+ this.entries.delete(handle);
60
40
  }
61
41
  /**
62
42
  * Handle process shutdown.
63
- * Cancel, persist, and terminate. The entrypoint owns process.exit.
43
+ * Cancel, persist, and terminate all registered runs. The entrypoint owns
44
+ * process.exit.
64
45
  */
65
46
  async shutdown(signal) {
66
47
  if (this.shuttingDown) {
@@ -69,32 +50,33 @@ export class ShutdownCoordinator {
69
50
  }
70
51
  this.shuttingDown = true;
71
52
  logger.info({ signal }, "received shutdown signal");
72
- // 1. Abort in-flight calls
73
- this.state.controller?.abort(new Error(`Shutdown: ${signal}`));
74
- // 2. Best-effort state persistence
75
- await this.safePersistState();
76
- // 3. Terminate child session
77
- await this.safeTerminateSession();
53
+ await this.handleAll(new Error(`Shutdown: ${signal}`));
78
54
  logger.info({ signal }, "shutdown cleanup complete");
79
55
  }
80
- async safePersistState() {
81
- if (this.state.persistState == null)
82
- return;
83
- try {
84
- await this.state.persistState();
85
- }
86
- catch (err) {
87
- logger.error({ err: err instanceof Error ? err.message : String(err) }, "failed to persist state during shutdown");
88
- }
89
- }
90
- async safeTerminateSession() {
91
- if (this.state.session == null)
92
- return;
93
- try {
94
- await this.state.session.terminate();
95
- }
96
- catch (err) {
97
- logger.error({ err: err instanceof Error ? err.message : String(err) }, "failed to terminate child session during shutdown");
56
+ /** Abort, persist, and terminate every registered entry (best-effort). */
57
+ async handleAll(abortReason) {
58
+ // Snapshot before iterating: an entry registered after this point is left
59
+ // intact rather than silently wiped by a blanket clear().
60
+ const snapshot = Array.from(this.entries.entries());
61
+ for (const [handle, entry] of snapshot) {
62
+ // 1. Abort in-flight calls
63
+ entry.controller.abort(abortReason);
64
+ // 2. Best-effort state persistence
65
+ try {
66
+ await entry.persistState();
67
+ }
68
+ catch (err) {
69
+ logger.error({ err: err instanceof Error ? err.message : String(err) }, "failed to persist state during shutdown");
70
+ }
71
+ // 3. Terminate child session
72
+ try {
73
+ await entry.session.terminate();
74
+ }
75
+ catch (err) {
76
+ logger.error({ err: err instanceof Error ? err.message : String(err) }, "failed to terminate child session during shutdown");
77
+ }
78
+ // 4. Delete only the processed handle.
79
+ this.entries.delete(handle);
98
80
  }
99
81
  }
100
82
  }