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
@@ -0,0 +1,1101 @@
1
+ import { createHash } from "node:crypto";
2
+ const REDACTION_MARKER = "[REDACTED]";
3
+ const MAX_EVENT_TEXT_CHARS = 32_768;
4
+ const MAX_EVENT_SUMMARY_CHARS = 4_096;
5
+ const MAX_REDACTIONS = 10_000;
6
+ const MAX_ARGUMENT_BYTES = 32_768;
7
+ const MAX_ARGUMENT_INPUT_BYTES = 1024 * 1024;
8
+ const MAX_ARGUMENT_DEPTH = 64;
9
+ const MAX_ARGUMENT_NODES = 10_000;
10
+ const SENSITIVE_KEY_SOURCE = "api[-_]?key|apikey|access[-_]?token|auth[-_]?token|token|secret|client[-_]?secret|password|authorization|proxy[-_]?authorization|cookie|set[-_]?cookie|private[-_]?key";
11
+ const SENSITIVE_KEY_PATTERN = new RegExp(`^(?:${SENSITIVE_KEY_SOURCE}|pgpassword)$`, "i");
12
+ const BEARER_PATTERN = /\bBearer\s+(?!\[REDACTED\])[^\s,;"']+/gi;
13
+ const PRIVATE_KEY_SIGNAL_PATTERN = /-----BEGIN (?:[A-Z0-9]+ )*PRIVATE KEY(?: BLOCK)?-----/i;
14
+ const SENSITIVE_QUERY_PATTERN = /([?&](?:api[-_]?key|access[-_]?token|auth[-_]?token|token|secret|password|client[-_]?secret|signature|sig|key)=)(?!\[REDACTED\])([^&#\s"']+)/gi;
15
+ const ASSIGNMENT_PATTERN = /(^|[^A-Za-z0-9_])([A-Za-z_][A-Za-z0-9_]{0,127})([ \t]*[=:][ \t]*)/g;
16
+ const VENDOR_TOKEN_PATTERN = /\b(?:sk-(?:ant-|proj-|svcacct-)?[A-Za-z0-9_-]{12,}|(?:sk|pk|github_pat|cxel|cxmsg|npm)_[A-Za-z0-9_:-]{12,}|gh[pousr]_[A-Za-z0-9]{12,}|xox[baprs]-[A-Za-z0-9-]{10,}|glpat-[A-Za-z0-9_-]{12,}|(?:AKIA|ASIA)[0-9A-Z]{16}|AIza[0-9A-Za-z_-]{35})\b/g;
17
+ const JWT_PATTERN = /\beyJ[A-Za-z0-9_-]{1,4096}\.[A-Za-z0-9_-]{1,4096}\.[A-Za-z0-9_-]{1,4096}(?![A-Za-z0-9_.-])/g;
18
+ const HEADER_PATTERN = /^(Proxy-Authorization|Authorization|Set-Cookie|Cookie)([ \t]*:[ \t]*)(.*)$/i;
19
+ const SHELL_DELIMITER_PATTERN = /[\s;|&]/;
20
+ const POSIX_USER_HOME_PATTERN = /\/(?:Users|home)\/[^/\s"'`<>]+/g;
21
+ const ROOT_USER_HOME_PATTERN = /\/root(?=\/|[\s"'`<>]|$)/g;
22
+ const WINDOWS_USER_HOME_PATTERN = /\b[A-Za-z]:\\Users\\[^\\/\s"'`<>]+/gi;
23
+ function isSensitiveKey(key) {
24
+ const normalized = key.toLowerCase().replace(/[-_ ]+/g, "_");
25
+ return SENSITIVE_KEY_PATTERN.test(normalized) || /(?:^|_)(?:token|secret|password|api_key|secret_access_key)$/.test(normalized);
26
+ }
27
+ const preparationHistory = new WeakMap();
28
+ export function prepareSessionLogEventV1(input, options) {
29
+ const prior = input !== null && typeof input === "object"
30
+ ? preparationHistory.get(input)
31
+ : undefined;
32
+ if (prior !== undefined) {
33
+ if (options?.coverage === undefined || options.coverage === prior.redaction.coverage)
34
+ return prior;
35
+ const result = Object.freeze({ ...prior, redaction: Object.freeze({ ...prior.redaction, coverage: options.coverage }) });
36
+ preparationHistory.set(prior.event, result);
37
+ return result;
38
+ }
39
+ const normalized = validateNormalizedEvent(input);
40
+ const prepared = redactEvent(normalized);
41
+ assertTextWithinContract(prepared.event);
42
+ if (prepared.event.kind === "tool_call" && prepared.event.arguments !== undefined) {
43
+ Object.freeze(prepared.event.arguments);
44
+ }
45
+ const event = Object.freeze(prepared.event);
46
+ const count = Math.min(MAX_REDACTIONS, prepared.count);
47
+ const redaction = Object.freeze({
48
+ ran: true,
49
+ status: count === 0 ? "no_matches" : "redacted",
50
+ count,
51
+ ...(options?.coverage === undefined ? {} : { coverage: options.coverage }),
52
+ });
53
+ const result = Object.freeze({
54
+ event,
55
+ redaction,
56
+ ...(prepared.truncated ? { truncated: true } : {}),
57
+ ...(event.kind === "tool_call" && event.arguments !== undefined && event.arguments.omission !== "none"
58
+ ? { omitted: true } : {}),
59
+ });
60
+ preparationHistory.set(event, result);
61
+ return result;
62
+ }
63
+ class ArgumentAdmissionError extends Error {
64
+ reason;
65
+ constructor(reason) {
66
+ super("argument admission failed");
67
+ this.reason = reason;
68
+ }
69
+ }
70
+ export function prepareSessionLogToolCallV1(event, value, options) {
71
+ const args = sanitizeArguments(value);
72
+ const candidate = { ...event, summary: args.summary ?? event.summary, arguments: args.detail };
73
+ const prepared = prepareSessionLogEventV1(candidate, options);
74
+ const count = Math.min(MAX_REDACTIONS, args.count + prepared.redaction.count);
75
+ const result = Object.freeze({
76
+ ...prepared,
77
+ redaction: Object.freeze({ ...prepared.redaction, status: count > 0 ? "redacted" : "no_matches", count }),
78
+ });
79
+ preparationHistory.set(result.event, result);
80
+ return result;
81
+ }
82
+ function sanitizeArgumentDetail(detail) {
83
+ if (detail.omission !== "none")
84
+ return { detail: { ...detail }, count: 0 };
85
+ if (detail.content.length > MAX_ARGUMENT_INPUT_BYTES || Buffer.byteLength(detail.content, "utf8") > MAX_ARGUMENT_INPUT_BYTES) {
86
+ return { detail: { content: "", omission: "size_limit" }, count: 0 };
87
+ }
88
+ try {
89
+ return sanitizeArguments(JSON.parse(detail.content));
90
+ }
91
+ catch {
92
+ return { detail: { content: "", omission: "invalid" }, count: 0 };
93
+ }
94
+ }
95
+ function sanitizeArguments(input, baseDepth = 0) {
96
+ let nodes = 0;
97
+ let bytes = 0;
98
+ let count = 0;
99
+ const active = new Set();
100
+ const charge = (text) => {
101
+ if (text.length > MAX_ARGUMENT_INPUT_BYTES)
102
+ throw new ArgumentAdmissionError("size_limit");
103
+ bytes += Buffer.byteLength(JSON.stringify(text), "utf8");
104
+ if (bytes > MAX_ARGUMENT_INPUT_BYTES)
105
+ throw new ArgumentAdmissionError("size_limit");
106
+ };
107
+ const visit = (value, depth) => {
108
+ if (++nodes > MAX_ARGUMENT_NODES || depth > MAX_ARGUMENT_DEPTH)
109
+ throw new ArgumentAdmissionError("structure_limit");
110
+ if (value === null || typeof value === "boolean")
111
+ return value;
112
+ if (typeof value === "number") {
113
+ if (!Number.isFinite(value))
114
+ throw new ArgumentAdmissionError("invalid");
115
+ return value;
116
+ }
117
+ if (typeof value === "string") {
118
+ charge(value);
119
+ const trimmed = value.trimStart();
120
+ if (/^[{["]/.test(trimmed)) {
121
+ let decoded;
122
+ let valid = false;
123
+ try {
124
+ decoded = JSON.parse(value);
125
+ valid = true;
126
+ }
127
+ catch {
128
+ valid = false;
129
+ }
130
+ if (valid)
131
+ return JSON.stringify(visit(decoded, depth + 1));
132
+ }
133
+ const redacted = redactText(value, Number.POSITIVE_INFINITY, depth + 1);
134
+ count += redacted.count;
135
+ return redacted.text;
136
+ }
137
+ if (typeof value !== "object" || value === undefined)
138
+ throw new ArgumentAdmissionError("invalid");
139
+ if (active.has(value))
140
+ throw new ArgumentAdmissionError("invalid");
141
+ active.add(value);
142
+ try {
143
+ if (Array.isArray(value)) {
144
+ if (value.length + nodes > MAX_ARGUMENT_NODES)
145
+ throw new ArgumentAdmissionError("structure_limit");
146
+ const result = [];
147
+ for (let index = 0; index < value.length; index += 1) {
148
+ const descriptor = Object.getOwnPropertyDescriptor(value, String(index));
149
+ if (descriptor === undefined || !("value" in descriptor))
150
+ throw new ArgumentAdmissionError("invalid");
151
+ result.push(visit(descriptor.value, depth + 1));
152
+ }
153
+ return result;
154
+ }
155
+ if (!isPlainRecord(value))
156
+ throw new ArgumentAdmissionError("invalid");
157
+ const keys = Object.keys(value);
158
+ if (keys.length + nodes > MAX_ARGUMENT_NODES)
159
+ throw new ArgumentAdmissionError("structure_limit");
160
+ const result = Object.create(null);
161
+ const sensitiveHeaderPair = typeof value["name"] === "string" && isSensitiveKey(value["name"]);
162
+ for (const key of keys) {
163
+ charge(key);
164
+ const child = visit(value[key], depth + 1);
165
+ const redactedKey = redactText(key);
166
+ count += redactedKey.count;
167
+ const retainedKey = redactedKey.count === 0 ? key
168
+ : `redacted_key_${createHash("sha256").update(key).digest("hex")}`;
169
+ if (isSensitiveKey(key) || (key === "value" && sensitiveHeaderPair)) {
170
+ if (value[key] !== REDACTION_MARKER)
171
+ count += 1;
172
+ result[retainedKey] = REDACTION_MARKER;
173
+ }
174
+ else {
175
+ if (Object.hasOwn(result, retainedKey))
176
+ throw new ArgumentAdmissionError("invalid");
177
+ result[retainedKey] = child;
178
+ }
179
+ }
180
+ return result;
181
+ }
182
+ finally {
183
+ active.delete(value);
184
+ }
185
+ };
186
+ try {
187
+ const value = visit(input, baseDepth);
188
+ const content = JSON.stringify(value);
189
+ let summary;
190
+ if (isPlainRecord(value)) {
191
+ for (const key of ["command", "cmd", "CommandLine", "file_path", "path", "pattern", "query"]) {
192
+ if (typeof value[key] === "string" && value[key].length > 0) {
193
+ summary = value[key];
194
+ break;
195
+ }
196
+ }
197
+ }
198
+ return {
199
+ detail: Buffer.byteLength(content, "utf8") > MAX_ARGUMENT_BYTES
200
+ ? { content: "", omission: "size_limit" } : { content, omission: "none" },
201
+ ...(summary === undefined ? {} : { summary }),
202
+ count,
203
+ };
204
+ }
205
+ catch (error) {
206
+ return { detail: { content: "", omission: error instanceof ArgumentAdmissionError ? error.reason : "invalid" }, count };
207
+ }
208
+ }
209
+ function assertTextWithinContract(event) {
210
+ let text;
211
+ let max = MAX_EVENT_SUMMARY_CHARS;
212
+ switch (event.kind) {
213
+ case "user":
214
+ case "assistant":
215
+ text = event.content;
216
+ max = MAX_EVENT_TEXT_CHARS;
217
+ break;
218
+ case "tool_call":
219
+ case "tool_result":
220
+ case "reasoning":
221
+ case "unknown":
222
+ text = event.summary;
223
+ break;
224
+ case "approval_request":
225
+ text = event.action;
226
+ break;
227
+ case "error":
228
+ text = event.message;
229
+ break;
230
+ case "approval_resolution":
231
+ case "lifecycle":
232
+ case "usage":
233
+ return;
234
+ }
235
+ if (text.length > max) {
236
+ throw new TypeError("session-log-v1 text exceeds contract bounds");
237
+ }
238
+ }
239
+ function redactEvent(event) {
240
+ switch (event.kind) {
241
+ case "user":
242
+ case "assistant": {
243
+ const redacted = redactText(event.content, MAX_EVENT_TEXT_CHARS, 0, "prose");
244
+ return { event: { ...event, content: redacted.text }, count: redacted.count,
245
+ ...(redacted.truncated ? { truncated: true } : {}) };
246
+ }
247
+ case "tool_call": {
248
+ const toolName = redactIdentifier(event.toolName);
249
+ const callId = redactIdentifier(event.callId);
250
+ const args = event.arguments === undefined ? undefined : sanitizeArgumentDetail(event.arguments);
251
+ const redacted = redactText(args?.summary ?? event.summary, MAX_EVENT_SUMMARY_CHARS);
252
+ return {
253
+ event: {
254
+ ...event,
255
+ toolName: toolName.value,
256
+ callId: callId.value,
257
+ summary: redacted.text,
258
+ ...(args === undefined ? {} : { arguments: args.detail }),
259
+ },
260
+ count: toolName.count + callId.count + redacted.count + (args?.count ?? 0),
261
+ ...(redacted.truncated ? { truncated: true } : {}),
262
+ };
263
+ }
264
+ case "tool_result": {
265
+ const toolName = redactIdentifier(event.toolName);
266
+ const callId = redactIdentifier(event.callId);
267
+ const redacted = redactText(event.summary, MAX_EVENT_SUMMARY_CHARS, 0, "prose");
268
+ return {
269
+ event: {
270
+ ...event,
271
+ toolName: toolName.value,
272
+ callId: callId.value,
273
+ summary: redacted.text,
274
+ },
275
+ count: toolName.count + callId.count + redacted.count,
276
+ ...(redacted.truncated ? { truncated: true } : {}),
277
+ };
278
+ }
279
+ case "approval_request": {
280
+ const approvalId = redactIdentifier(event.approvalId);
281
+ const redacted = redactText(event.action, MAX_EVENT_SUMMARY_CHARS);
282
+ return {
283
+ event: { ...event, approvalId: approvalId.value, action: redacted.text },
284
+ count: approvalId.count + redacted.count,
285
+ ...(redacted.truncated ? { truncated: true } : {}),
286
+ };
287
+ }
288
+ case "approval_resolution": {
289
+ const approvalId = redactIdentifier(event.approvalId);
290
+ return {
291
+ event: { ...event, approvalId: approvalId.value },
292
+ count: approvalId.count,
293
+ };
294
+ }
295
+ case "error": {
296
+ const code = redactIdentifier(event.code);
297
+ const redacted = redactText(event.message, MAX_EVENT_SUMMARY_CHARS, 0, "prose");
298
+ return {
299
+ event: { ...event, code: code.value, message: redacted.text },
300
+ count: code.count + redacted.count,
301
+ ...(redacted.truncated ? { truncated: true } : {}),
302
+ };
303
+ }
304
+ case "reasoning": {
305
+ const redacted = redactText(event.summary, MAX_EVENT_SUMMARY_CHARS, 0, "prose");
306
+ return { event: { ...event, summary: redacted.text }, count: redacted.count,
307
+ ...(redacted.truncated ? { truncated: true } : {}) };
308
+ }
309
+ case "unknown": {
310
+ const originalKind = redactIdentifier(event.originalKind);
311
+ const redacted = redactText(event.summary, MAX_EVENT_SUMMARY_CHARS, 0, "prose");
312
+ return {
313
+ event: { ...event, originalKind: originalKind.value, summary: redacted.text },
314
+ count: originalKind.count + redacted.count,
315
+ ...(redacted.truncated ? { truncated: true } : {}),
316
+ };
317
+ }
318
+ case "lifecycle":
319
+ case "usage":
320
+ return { event: { ...event }, count: 0 };
321
+ }
322
+ }
323
+ function redactIdentifier(value) {
324
+ if (redactText(value).count === 0)
325
+ return { value, count: 0 };
326
+ const digest = createHash("sha256")
327
+ .update("session-log-v1-identifier\0", "utf8")
328
+ .update(value, "utf8")
329
+ .digest("hex")
330
+ .slice(0, 16);
331
+ return { value: `redacted_${digest}`, count: 1 };
332
+ }
333
+ function applyTextEdits(text, edits) {
334
+ const parts = [];
335
+ let end = 0;
336
+ let count = 0;
337
+ for (const edit of edits) {
338
+ parts.push(text.slice(end, edit.start), edit.text);
339
+ end = edit.end;
340
+ count += edit.count;
341
+ }
342
+ parts.push(text.slice(end));
343
+ return { text: parts.join(""), count };
344
+ }
345
+ function redactEmbeddedJson(text, depth) {
346
+ const edits = [];
347
+ for (let start = 0; start < text.length; start += 1) {
348
+ if (text[start] !== "{" && text[start] !== "[")
349
+ continue;
350
+ let shellEscaped = false;
351
+ const stack = [];
352
+ const decoded = [];
353
+ let quoted = false;
354
+ let escaped = false;
355
+ let end = start;
356
+ for (; end < text.length; end += 1) {
357
+ let char = text[end];
358
+ if (!quoted && char === "\\" && text[end + 1] === '"')
359
+ shellEscaped = true;
360
+ if (shellEscaped && char === "\\" && (text[end + 1] === "\\" || text[end + 1] === '"'))
361
+ char = text[++end];
362
+ decoded.push(char);
363
+ if (quoted) {
364
+ if (escaped)
365
+ escaped = false;
366
+ else if (char === "\\")
367
+ escaped = true;
368
+ else if (char === '"')
369
+ quoted = false;
370
+ }
371
+ else if (char === '"')
372
+ quoted = true;
373
+ else if (char === "{" || char === "[")
374
+ stack.push(char);
375
+ else if (char === "}" || char === "]") {
376
+ const open = stack.pop();
377
+ if ((char === "}" && open !== "{") || (char === "]" && open !== "["))
378
+ break;
379
+ if (stack.length === 0) {
380
+ end += 1;
381
+ break;
382
+ }
383
+ }
384
+ }
385
+ const source = decoded.join("");
386
+ try {
387
+ const parsed = JSON.parse(source);
388
+ const sanitized = sanitizeArguments(parsed, depth + 1);
389
+ if (sanitized.detail.omission !== "none") {
390
+ edits.push({ start, end, text: REDACTION_MARKER, count: Math.max(1, sanitized.count) });
391
+ }
392
+ else if (sanitized.count > 0) {
393
+ const replacement = shellEscaped ? sanitized.detail.content.replace(/[\\"]/g, "\\$&") : sanitized.detail.content;
394
+ edits.push({ start, end, text: replacement, count: sanitized.count });
395
+ }
396
+ }
397
+ catch {
398
+ const keyPattern = /"((?:\\.|[^"\\]){1,512})"\s*:/g;
399
+ let match;
400
+ while ((match = keyPattern.exec(source)) !== null) {
401
+ let key;
402
+ try {
403
+ key = JSON.parse(`"${match[1]}"`);
404
+ }
405
+ catch {
406
+ continue;
407
+ }
408
+ if (typeof key === "string" && isSensitiveKey(key)) {
409
+ return { text: REDACTION_MARKER, count: 1 };
410
+ }
411
+ }
412
+ }
413
+ start = Math.max(start, end - 1);
414
+ }
415
+ return applyTextEdits(text, edits);
416
+ }
417
+ function isWordApostrophe(text, index) {
418
+ const attachedFlag = index >= 2 && /^-[uab]$/.test(text.slice(index - 2, index))
419
+ && (index === 2 || SHELL_DELIMITER_PATTERN.test(text[index - 3]));
420
+ return text[index] === "'"
421
+ && !attachedFlag
422
+ && /(?:\p{L}|\p{N})$/u.test(text.slice(Math.max(0, index - 2), index))
423
+ && /^\p{L}/u.test(text.slice(index + 1, index + 3));
424
+ }
425
+ function shellTokens(text, mode = "command") {
426
+ const tokens = [];
427
+ for (let index = 0; index < text.length;) {
428
+ const start = index;
429
+ if (SHELL_DELIMITER_PATTERN.test(text[index])) {
430
+ index += 1;
431
+ if (/[;|&\n]/.test(text[start]))
432
+ tokens.push({ start, end: index, value: text[start], quoted: false });
433
+ continue;
434
+ }
435
+ let quote;
436
+ let quoted = false;
437
+ const parts = [];
438
+ while (index < text.length) {
439
+ const char = text[index];
440
+ if (quote === undefined && SHELL_DELIMITER_PATTERN.test(char))
441
+ break;
442
+ const wordApostrophe = mode === "prose" && quote === undefined && isWordApostrophe(text, index);
443
+ index += 1;
444
+ if (wordApostrophe)
445
+ parts.push(char);
446
+ else if (quote === undefined && (char === "'" || char === '"')) {
447
+ quote = char;
448
+ quoted = true;
449
+ }
450
+ else if (char === quote)
451
+ quote = undefined;
452
+ else if (char === "\\" && quote !== "'" && index < text.length) {
453
+ if (text[index] === "\n")
454
+ index += 1;
455
+ else if (text[index] === "\r" && text[index + 1] === "\n")
456
+ index += 2;
457
+ else
458
+ parts.push(text[index++]);
459
+ }
460
+ else
461
+ parts.push(char);
462
+ }
463
+ if (index <= start) {
464
+ index = start + 1;
465
+ continue;
466
+ }
467
+ if (parts.length > 0 || quoted)
468
+ tokens.push({ start, end: index, value: parts.join(""), quoted });
469
+ }
470
+ return tokens;
471
+ }
472
+ function redactHeader(value) {
473
+ const match = HEADER_PATTERN.exec(value);
474
+ if (match === null)
475
+ return { text: value, count: 0 };
476
+ const body = match[3].trim();
477
+ const scheme = /authorization/i.test(match[1]) ? /^(?:Bearer|Basic)[ \t]+/i.exec(body)?.[0] ?? "" : "";
478
+ if (body === "" || body === REDACTION_MARKER || body === `${scheme}${REDACTION_MARKER}`)
479
+ return { text: value, count: 0 };
480
+ return { text: `${match[1]}${match[2]}${scheme}${REDACTION_MARKER}`, count: 1 };
481
+ }
482
+ function isMysqlCredential(value) {
483
+ return value.startsWith("-p") && value.length > 2
484
+ && !/^(?:(?:\d{1,3}\.){3}\d{1,3}:|\[[0-9A-Fa-f:]+\]:)?\d+(?::\d+)?(?:\/\w+)?$/.test(value.slice(2));
485
+ }
486
+ function credentialOption(tokens, index) {
487
+ const token = tokens[index];
488
+ const match = /^(--[\w-]+)(?:=([\s\S]*))?$|^(-[uab])=?([\s\S]*)$/.exec(token.value);
489
+ if (match === null)
490
+ return undefined;
491
+ const flag = match[1] ?? match[3];
492
+ const attached = match[2] !== undefined || (match[3] !== undefined && token.value.length > 2);
493
+ const operand = attached ? token : tokens[index + 1];
494
+ const value = attached ? match[2] ?? match[4] : operand?.value ?? "";
495
+ const colon = value.indexOf(":");
496
+ const sensitive = ["-u", "--user", "--proxy-user", "--http-user", "-a", "--auth"].includes(flag) ? colon >= 0 && colon < value.length - 1
497
+ : ["-b", "--cookie"].includes(flag) ? value.includes("=")
498
+ : ["--password", "--http-password", "--proxy-password", "--passwd"].includes(flag);
499
+ return sensitive && operand !== undefined && !(!operand.quoted && /^[;|&\n]$/.test(value))
500
+ ? { flag, attached, operand, value } : undefined;
501
+ }
502
+ function proseOperandWord(line, start, enclosingEnd) {
503
+ if (start >= line.length || SHELL_DELIMITER_PATTERN.test(line[start]))
504
+ return undefined;
505
+ let quote;
506
+ let quoted = false;
507
+ const parts = [];
508
+ let end = start;
509
+ while (end < line.length) {
510
+ if (quote === undefined && SHELL_DELIMITER_PATTERN.test(line[end]))
511
+ break;
512
+ const char = line[end++];
513
+ if (quote === undefined && (char === "'" || char === '"')) {
514
+ quote = char;
515
+ quoted = true;
516
+ }
517
+ else if (char === quote)
518
+ quote = undefined;
519
+ else if (char === "\\" && quote !== "'" && end < line.length)
520
+ parts.push(line[end++]);
521
+ else
522
+ parts.push(char);
523
+ }
524
+ if (quote !== undefined && enclosingEnd !== undefined && enclosingEnd > start && enclosingEnd < end) {
525
+ return proseOperandWord(line.slice(0, enclosingEnd), start);
526
+ }
527
+ return { start, end, value: parts.join(""), quoted };
528
+ }
529
+ function recoveredProseCredentialOption(line, tokens, index, enclosingEnd) {
530
+ const token = tokens[index];
531
+ const attached = /^(--[\w-]+=|-[uab]=?)(?=\S)/.exec(line.slice(token.start, token.end));
532
+ if (attached === null && !/^(?:--[\w-]+|-[uab])$/.test(token.value))
533
+ return undefined;
534
+ const start = attached === null ? tokens[index + 1]?.start : token.start + attached[0].length;
535
+ if (start === undefined)
536
+ return undefined;
537
+ const operand = proseOperandWord(line, start, enclosingEnd);
538
+ if (operand === undefined)
539
+ return undefined;
540
+ const flag = attached === null ? token : { ...token, end: operand.end, value: attached[0] + operand.value };
541
+ const credential = credentialOption([flag, operand], 0);
542
+ return credential?.value === REDACTION_MARKER ? undefined : credential;
543
+ }
544
+ function proseEvidenceTokens(text) {
545
+ return Array.from(text.matchAll(/[^\s;|&]+|[;|&\n]/g), (word) => ({
546
+ start: word.index, end: word.index + word[0].length, value: word[0].replace(/["']/g, ""), quoted: false,
547
+ }));
548
+ }
549
+ function redactMultilineProseTokens(text) {
550
+ if (!text.includes("\n"))
551
+ return { text, count: 0 };
552
+ // Recover only credential-owned words; preceding prose quotes cannot own later lines.
553
+ const tokens = proseEvidenceTokens(text);
554
+ const edits = [];
555
+ let mysql = false;
556
+ let enclosingEnd;
557
+ for (let index = 0; index < tokens.length; index += 1) {
558
+ const token = tokens[index];
559
+ if (enclosingEnd !== undefined && token.start >= enclosingEnd)
560
+ enclosingEnd = undefined;
561
+ if (/^[;|&\n]$/.test(token.value)) {
562
+ mysql = false;
563
+ continue;
564
+ }
565
+ if (["mysql", "mariadb"].includes(token.value.split(/[\\/]/).at(-1)))
566
+ mysql = true;
567
+ const assignment = /^["']?([A-Za-z_][A-Za-z0-9_]{0,127})([ \t]*[=:][ \t]*)/.exec(text.slice(token.start));
568
+ const sensitiveAssignment = assignment !== null && isSensitiveKey(assignment[1])
569
+ && !(assignment[2].includes(":") && /authorization|cookie/i.test(assignment[1]));
570
+ const spacedAssignment = sensitiveAssignment && /[ \t]/.test(assignment[2]);
571
+ const credential = recoveredProseCredentialOption(text, tokens, index, enclosingEnd);
572
+ const mysqlOperand = mysql && isMysqlCredential(token.value) && token.value !== `-p${REDACTION_MARKER}`;
573
+ const headerPrefix = token.value.startsWith("--header=") ? "--header=" : token.value.startsWith("-H") ? "-H" : "";
574
+ const headerOperand = headerPrefix !== "" || ["-H", "--header"].includes(tokens[index - 1]?.value ?? "");
575
+ const wrapper = tokens[index - 1]?.value.split(/[\\/]/).at(-1);
576
+ const commandFlag = (["sh", "bash", "zsh"].includes(wrapper ?? "") && /^-[A-Za-z]*c[A-Za-z]*$/.test(token.value))
577
+ || (wrapper === "env" && ["-S", "--split-string"].includes(token.value));
578
+ const operand = credential?.operand ?? (commandFlag ? proseOperandWord(text, tokens[index + 1]?.start ?? text.length, enclosingEnd)
579
+ : sensitiveAssignment || mysqlOperand || headerOperand ? proseOperandWord(text, spacedAssignment ? token.start + assignment[0].length : token.start + headerPrefix.length, enclosingEnd) : undefined);
580
+ if (operand === undefined) {
581
+ const quote = text[token.start];
582
+ if (quote === "'" || quote === '"') {
583
+ const enclosing = proseOperandWord(text, token.start);
584
+ if (text.slice(token.start, enclosing.end).includes("\n") && text[enclosing.end - 1] === quote)
585
+ enclosingEnd = enclosing.end - 1;
586
+ }
587
+ continue;
588
+ }
589
+ const source = text.slice(operand.start, operand.end);
590
+ if (source.includes("\n") || operand.end === enclosingEnd) {
591
+ let replacement;
592
+ if (spacedAssignment) {
593
+ const quote = source[0];
594
+ replacement = (quote === "'" || quote === '"') && source.endsWith(quote)
595
+ ? `${quote}${REDACTION_MARKER}${quote}` : REDACTION_MARKER;
596
+ }
597
+ else if (sensitiveAssignment) {
598
+ const prefix = `${assignment[1]}${assignment[2]}`;
599
+ if (operand.value.slice(prefix.length) !== REDACTION_MARKER) {
600
+ replacement = REDACTION_MARKER;
601
+ const quote = source[0];
602
+ if ((quote === "'" || quote === '"') && source === `${quote}${operand.value}${quote}`) {
603
+ replacement = `${quote}${prefix}${REDACTION_MARKER}${quote}`;
604
+ }
605
+ else if (source.startsWith(prefix)) {
606
+ const rawValue = source.slice(prefix.length);
607
+ const quote = rawValue[0];
608
+ if (quote !== "'" && quote !== '"')
609
+ replacement = prefix + REDACTION_MARKER;
610
+ else if (rawValue === `${quote}${operand.value.slice(prefix.length)}${quote}`) {
611
+ replacement = `${prefix}${quote}${REDACTION_MARKER}${quote}`;
612
+ }
613
+ }
614
+ }
615
+ }
616
+ else if (credential !== undefined) {
617
+ replacement = (credential.attached ? credential.flag + (token.value[credential.flag.length] === "=" ? "=" : "") : "") + REDACTION_MARKER;
618
+ }
619
+ else if (mysqlOperand)
620
+ replacement = `-p${REDACTION_MARKER}`;
621
+ else if (headerOperand && redactHeader(operand.value.replace(/\r?\n/g, " ")).count > 0)
622
+ replacement = REDACTION_MARKER;
623
+ else if (commandFlag && firstProseCredentialEvidence(operand.value.replace(/\r?\n/g, " ")) !== undefined)
624
+ replacement = REDACTION_MARKER;
625
+ if (replacement !== undefined)
626
+ edits.push({
627
+ start: operand.start, end: operand.end + (sensitiveAssignment && operand.end === enclosingEnd ? 1 : 0), text: replacement, count: 1,
628
+ });
629
+ }
630
+ // A locally decoded word owns its quote fragments, even when no edit is needed.
631
+ while (tokens[index + 1] !== undefined && tokens[index + 1].start < operand.end)
632
+ index += 1;
633
+ }
634
+ return applyTextEdits(text, edits);
635
+ }
636
+ function firstProseCredentialEvidence(line) {
637
+ let first = Number.POSITIVE_INFINITY;
638
+ ASSIGNMENT_PATTERN.lastIndex = 0;
639
+ let match;
640
+ while ((match = ASSIGNMENT_PATTERN.exec(line)) !== null) {
641
+ const valueStart = ASSIGNMENT_PATTERN.lastIndex;
642
+ // Leave trailing space available as the boundary of a following assignment.
643
+ ASSIGNMENT_PATTERN.lastIndex -= /[ \t]+$/.exec(match[3])?.[0].length ?? 0;
644
+ if (match[1] === "-" && line[match.index - 1] === "-" && match[3].startsWith("=")
645
+ && /^(?:user|proxy-user|http-user|auth|cookie|password|http-password|proxy-password|passwd)$/.test(match[2])
646
+ && (match.index === 1 || /[\s;|&"']/.test(line[match.index - 2])))
647
+ continue;
648
+ if (isSensitiveKey(match[2]) && !(match[3].includes(":") && /authorization|cookie/i.test(match[2]))) {
649
+ if (/^["']?\[REDACTED\]["']?(?=$|[\s;|&,])/.test(line.slice(valueStart)))
650
+ continue;
651
+ const operand = proseOperandWord(line, valueStart);
652
+ if (operand !== undefined && operand.value !== REDACTION_MARKER) {
653
+ first = match.index + match[1].length;
654
+ break;
655
+ }
656
+ }
657
+ }
658
+ // Ignore quote grouping only for locating evidence in an already ambiguous line.
659
+ const tokens = proseEvidenceTokens(line);
660
+ let mysql = false;
661
+ for (let index = 0; index < tokens.length; index += 1) {
662
+ const token = tokens[index];
663
+ if (token.start >= first)
664
+ break;
665
+ if (/^[;|&]$/.test(token.value)) {
666
+ mysql = false;
667
+ continue;
668
+ }
669
+ const credential = credentialOption(tokens, index);
670
+ if ((credential !== undefined && credential.value !== REDACTION_MARKER) || recoveredProseCredentialOption(line, tokens, index) !== undefined
671
+ || (mysql && isMysqlCredential(token.value) && token.value !== `-p${REDACTION_MARKER}`)) {
672
+ first = Math.min(first, token.start);
673
+ }
674
+ const headerPrefix = token.value.startsWith("--header=") ? "--header=" : token.value.startsWith("-H") ? "-H" : "";
675
+ if (HEADER_PATTERN.test(token.value.slice(headerPrefix.length))) {
676
+ const headerStart = token.start + headerPrefix.length;
677
+ const quoted = line[headerStart] === "'" || line[headerStart] === '"';
678
+ const value = (quoted ? proseOperandWord(line, headerStart)?.value : undefined) ?? line.slice(headerStart).replace(/["']/g, "");
679
+ const header = HEADER_PATTERN.exec(value);
680
+ if (header !== null && redactHeader(value).count > 0) {
681
+ const previous = tokens[index - 1];
682
+ const start = previous !== undefined && ["-H", "--header"].includes(previous.value) ? previous.start : token.start;
683
+ first = Math.min(first, start);
684
+ }
685
+ }
686
+ if (["mysql", "mariadb"].includes(token.value.split(/[\\/]/).at(-1)))
687
+ mysql = true;
688
+ }
689
+ const url = redactUrlUserinfo(line);
690
+ if (url.firstStart !== undefined)
691
+ first = Math.min(first, url.firstStart);
692
+ for (const pattern of [VENDOR_TOKEN_PATTERN, JWT_PATTERN, BEARER_PATTERN]) {
693
+ pattern.lastIndex = 0;
694
+ const evidence = pattern.exec(line);
695
+ if (evidence !== null)
696
+ first = Math.min(first, evidence.index);
697
+ }
698
+ return Number.isFinite(first) ? first : undefined;
699
+ }
700
+ function redactProseCommandsAndHeaders(text) {
701
+ const multiline = redactMultilineProseTokens(text);
702
+ let count = multiline.count;
703
+ const lines = multiline.text.split("\n").map((source) => {
704
+ const cr = source.endsWith("\r") ? "\r" : "";
705
+ const line = cr === "" ? source : source.slice(0, -1);
706
+ let single = 0;
707
+ let double = 0;
708
+ for (let index = 0; index < line.length; index += 1) {
709
+ if (line[index] === "\\") {
710
+ index += 1;
711
+ continue;
712
+ }
713
+ if (line[index] === "'" && !isWordApostrophe(line, index))
714
+ single += 1;
715
+ if (line[index] === '"')
716
+ double += 1;
717
+ }
718
+ const assignments = redactAssignments(line);
719
+ if (single % 2 !== 0 || double % 2 !== 0 || (assignments.text === REDACTION_MARKER && assignments.count > 0)) {
720
+ const first = firstProseCredentialEvidence(line);
721
+ if (first === undefined)
722
+ return source;
723
+ count += 1;
724
+ return line.slice(0, first) + REDACTION_MARKER + cr;
725
+ }
726
+ const redacted = redactCommandsAndHeaders(line, 0, false, "prose");
727
+ count += redacted.count;
728
+ return redacted.text + cr;
729
+ });
730
+ return { text: lines.join("\n"), count };
731
+ }
732
+ function redactCommandsAndHeaders(text, depth = 0, evidenceOnly = false, mode = "command") {
733
+ const lines = text.split("\n");
734
+ let lineCount = 0;
735
+ text = lines.map((line) => {
736
+ const indent = /^[ \t]*/.exec(line)[0];
737
+ const redacted = redactHeader(line.slice(indent.length));
738
+ lineCount += redacted.count;
739
+ return indent + redacted.text;
740
+ }).join("\n");
741
+ const tokens = shellTokens(text, mode);
742
+ const edits = [];
743
+ let mysql = false;
744
+ for (let index = 0; index < tokens.length; index += 1) {
745
+ const token = tokens[index];
746
+ if (/^[;|&\n]$/.test(token.value) && !token.quoted) {
747
+ mysql = false;
748
+ continue;
749
+ }
750
+ const source = text.slice(token.start, token.end);
751
+ const previous = tokens[index - 1];
752
+ const wrapper = tokens[index - 2]?.value.split(/[\\/]/).at(-1);
753
+ const quotedCommand = token.quoted && previous !== undefined && !previous.quoted && ((["sh", "bash", "zsh"].includes(wrapper ?? "") && /^-[A-Za-z]*c[A-Za-z]*$/.test(previous.value))
754
+ || (wrapper === "env" && ["-S", "--split-string"].includes(previous.value)));
755
+ const assignment = /^([A-Za-z_][A-Za-z0-9_]*)=/.exec(token.value);
756
+ if (assignment !== null && isSensitiveKey(assignment[1]) && !quotedCommand) {
757
+ // Spaced prose values are handled by redactAssignments, including existing markers.
758
+ if (mode === "prose" && token.value === assignment[0] && /[ \t]/.test(text[token.end] ?? ""))
759
+ continue;
760
+ if (!source.startsWith(assignment[0])) {
761
+ const quote = source[0];
762
+ const mapped = (quote === '"' || quote === "'") && source === `${quote}${token.value}${quote}`;
763
+ const replacement = mapped ? `${quote}${assignment[0]}${REDACTION_MARKER}${quote}` : REDACTION_MARKER;
764
+ if (source !== replacement)
765
+ edits.push({ start: token.start, end: token.end, text: replacement, count: 1 });
766
+ continue;
767
+ }
768
+ const start = token.start + assignment[0].length;
769
+ const quote = text[start] === '"' || text[start] === "'" ? text[start] : "";
770
+ if (quote !== "" && (text.slice(start, token.end).includes("\n") || text[token.end - 1] !== quote)) {
771
+ return { text: REDACTION_MARKER, count: 1 };
772
+ }
773
+ const replacement = `${quote}${REDACTION_MARKER}${quote}${quote === "" && source.endsWith(",") ? "," : ""}`;
774
+ if (text.slice(start, token.end) !== replacement)
775
+ edits.push({ start, end: token.end, text: replacement, count: 1 });
776
+ continue;
777
+ }
778
+ const headerPrefix = token.value.startsWith("--header=") ? "--header=" : token.value.startsWith("-H") ? "-H" : "";
779
+ const header = headerPrefix !== "" || token.quoted || tokens[index - 1]?.value === "-H" || tokens[index - 1]?.value === "--header"
780
+ ? redactHeader(token.value.slice(headerPrefix.length)) : { text: token.value, count: 0 };
781
+ if (header.count > 0) {
782
+ edits.push({ start: token.start, end: token.end, text: headerPrefix + JSON.stringify(header.text), count: 1 });
783
+ continue;
784
+ }
785
+ if (mysql && isMysqlCredential(token.value)) {
786
+ if (token.value.slice(2) !== REDACTION_MARKER)
787
+ edits.push({ start: token.start, end: token.end, text: `-p${REDACTION_MARKER}`, count: 1 });
788
+ continue;
789
+ }
790
+ if (!token.quoted && ["mysql", "mariadb"].includes(token.value.split(/[\\/]/).at(-1)))
791
+ mysql = true;
792
+ const credential = credentialOption(tokens, index);
793
+ if (credential !== undefined) {
794
+ const { flag, attached, operand, value } = credential;
795
+ const prefix = attached ? flag + (token.value[flag.length] === "=" ? "=" : "") : "";
796
+ if (value !== REDACTION_MARKER)
797
+ edits.push({ start: operand.start, end: operand.end, text: prefix + REDACTION_MARKER, count: 1 });
798
+ if (!attached)
799
+ index += 1;
800
+ continue;
801
+ }
802
+ if (token.quoted && (quotedCommand || /\s/.test(token.value)) && !evidenceOnly) {
803
+ const nested = redactCommandsAndHeaders(token.value, 1, depth > 0);
804
+ const count = nested.count + (depth === 0 ? 0 : redactAssignments(token.value).count + redactUrlUserinfo(token.value).count
805
+ + Number(Boolean(token.value.match(VENDOR_TOKEN_PATTERN) || token.value.match(JWT_PATTERN) || token.value.match(BEARER_PATTERN))));
806
+ if (count > 0) {
807
+ const quote = source[0];
808
+ const mapped = (quote === '"' || quote === "'") && source === `${quote}${token.value}${quote}`;
809
+ edits.push({ start: token.start, end: token.end, text: mapped && depth === 0 ? `${quote}${nested.text}${quote}` : REDACTION_MARKER, count: depth === 0 ? count : 1 });
810
+ }
811
+ }
812
+ }
813
+ const result = applyTextEdits(text, edits);
814
+ return { text: result.text, count: result.count + lineCount };
815
+ }
816
+ function redactAssignments(text) {
817
+ const edits = [];
818
+ ASSIGNMENT_PATTERN.lastIndex = 0;
819
+ let match;
820
+ while ((match = ASSIGNMENT_PATTERN.exec(text)) !== null) {
821
+ if (!isSensitiveKey(match[2]))
822
+ continue;
823
+ if (match[1] === "-" && text[match.index - 1] === "-" && match[3].startsWith("=")
824
+ && /^(?:user|proxy-user|http-user|auth|cookie|password|http-password|proxy-password|passwd)$/.test(match[2])
825
+ && (match.index === 1 || /[\s;|&"']/.test(text[match.index - 2])))
826
+ continue;
827
+ if (match[3].includes(":") && /authorization|cookie/i.test(match[2]))
828
+ continue;
829
+ const start = ASSIGNMENT_PATTERN.lastIndex;
830
+ const quote = text[start] === '"' || text[start] === "'" ? text[start] : undefined;
831
+ let end = start + (quote === undefined ? 0 : 1);
832
+ if (quote === undefined && text.startsWith(REDACTION_MARKER, start))
833
+ end += REDACTION_MARKER.length;
834
+ for (; end < text.length; end += 1) {
835
+ const char = text[end];
836
+ if (quote === undefined && (/[\s,;&#}\]]/.test(char) || ((match[1] === '"' || match[1] === "'") && char === match[1])))
837
+ break;
838
+ if (quote !== undefined && char === "\n")
839
+ return { text: REDACTION_MARKER, count: 1 };
840
+ if (quote !== undefined && char === "\\")
841
+ end += 1;
842
+ else if (quote !== undefined && char === quote) {
843
+ end += 1;
844
+ break;
845
+ }
846
+ }
847
+ const replacement = quote === undefined ? REDACTION_MARKER : `${quote}${REDACTION_MARKER}${quote}`;
848
+ if (text.slice(start, end) === replacement || end === start)
849
+ continue;
850
+ if (quote !== undefined && text[end - 1] !== quote)
851
+ return { text: REDACTION_MARKER, count: 1 };
852
+ if (quote !== undefined && end < text.length && !/[\s,;&#}\]]/.test(text[end]))
853
+ return { text: REDACTION_MARKER, count: 1 };
854
+ edits.push({ start, end, text: replacement, count: 1 });
855
+ ASSIGNMENT_PATTERN.lastIndex = end;
856
+ }
857
+ return applyTextEdits(text, edits);
858
+ }
859
+ function redactUrlUserinfo(text) {
860
+ const schemePattern = /\b[A-Za-z][A-Za-z0-9+.-]{0,63}:\/\//g;
861
+ const edits = [];
862
+ let firstStart;
863
+ let match;
864
+ while ((match = schemePattern.exec(text)) !== null) {
865
+ const start = schemePattern.lastIndex;
866
+ let end = start;
867
+ let colon = -1;
868
+ let at = -1;
869
+ for (; end < text.length && !/[\s/?#"'<>`]/.test(text[end]); end += 1) {
870
+ if (text[end] === ":" && colon < 0)
871
+ colon = end;
872
+ if (text[end] === "@")
873
+ at = end;
874
+ }
875
+ if (colon >= start && at > colon) {
876
+ firstStart ??= match.index;
877
+ edits.push({ start, end: at, text: REDACTION_MARKER, count: 1 });
878
+ }
879
+ schemePattern.lastIndex = end;
880
+ }
881
+ return { ...applyTextEdits(text, edits), firstStart };
882
+ }
883
+ function redactText(value, maxChars = Number.POSITIVE_INFINITY, depth = 0, mode = "command") {
884
+ if (PRIVATE_KEY_SIGNAL_PATTERN.test(value))
885
+ return { text: REDACTION_MARKER, count: 1 };
886
+ const embedded = redactEmbeddedJson(value, depth);
887
+ const commands = mode === "prose" ? redactProseCommandsAndHeaders(embedded.text) : redactCommandsAndHeaders(embedded.text);
888
+ let text = commands.text;
889
+ let count = embedded.count + commands.count;
890
+ const replace = (pattern, replacement) => {
891
+ text = text.replace(pattern, (...args) => {
892
+ count += 1;
893
+ return replacement(...args.slice(0, -2).map(String));
894
+ });
895
+ };
896
+ replace(BEARER_PATTERN, (match) => `${match.slice(0, match.search(/\s/))} ${REDACTION_MARKER}`);
897
+ replace(SENSITIVE_QUERY_PATTERN, (_match, prefix) => `${prefix}${REDACTION_MARKER}`);
898
+ const assignments = redactAssignments(text);
899
+ text = assignments.text;
900
+ count += assignments.count;
901
+ const urls = redactUrlUserinfo(text);
902
+ text = urls.text;
903
+ count += urls.count;
904
+ replace(VENDOR_TOKEN_PATTERN, () => REDACTION_MARKER);
905
+ replace(JWT_PATTERN, () => REDACTION_MARKER);
906
+ replace(POSIX_USER_HOME_PATTERN, () => REDACTION_MARKER);
907
+ replace(ROOT_USER_HOME_PATTERN, () => REDACTION_MARKER);
908
+ replace(WINDOWS_USER_HOME_PATTERN, () => REDACTION_MARKER);
909
+ if (count > MAX_REDACTIONS)
910
+ return { text: REDACTION_MARKER, count: 1 };
911
+ if (text.length <= maxChars)
912
+ return { text, count };
913
+ let end = maxChars;
914
+ const markerStart = text.lastIndexOf(REDACTION_MARKER, end - 1);
915
+ if (markerStart >= 0 && markerStart + REDACTION_MARKER.length > end)
916
+ end = markerStart;
917
+ const code = text.charCodeAt(end - 1);
918
+ if (code >= 0xd800 && code <= 0xdbff)
919
+ end -= 1;
920
+ return { text: text.slice(0, end), count, truncated: true };
921
+ }
922
+ function validateNormalizedEvent(value) {
923
+ if (!isPlainRecord(value) || typeof value["kind"] !== "string")
924
+ return invalidEvent();
925
+ switch (value["kind"]) {
926
+ case "user":
927
+ case "assistant":
928
+ if (!hasExactKeys(value, ["kind", "content"]) || typeof value["content"] !== "string") {
929
+ return invalidEvent();
930
+ }
931
+ return { kind: value["kind"], content: value["content"] };
932
+ case "tool_call":
933
+ if (!hasExactKeys(value, ["kind", "toolName", "callId", "summary", ...(Object.hasOwn(value, "arguments") ? ["arguments"] : [])]) ||
934
+ !isAdmissibleIdentifier(value["toolName"]) ||
935
+ !isAdmissibleIdentifier(value["callId"]) ||
936
+ typeof value["summary"] !== "string")
937
+ return invalidEvent();
938
+ return {
939
+ kind: "tool_call",
940
+ toolName: value["toolName"],
941
+ callId: value["callId"],
942
+ summary: value["summary"],
943
+ ...(Object.hasOwn(value, "arguments") ? { arguments: validateArgumentDetail(value["arguments"]) } : {}),
944
+ };
945
+ case "tool_result":
946
+ if (!hasExactKeys(value, ["kind", "toolName", "callId", "outcome", "summary"]) ||
947
+ !isAdmissibleIdentifier(value["toolName"]) ||
948
+ !isAdmissibleIdentifier(value["callId"]) ||
949
+ !isOneOf(value["outcome"], ["succeeded", "failed", "cancelled"]) ||
950
+ typeof value["summary"] !== "string")
951
+ return invalidEvent();
952
+ return {
953
+ kind: "tool_result",
954
+ toolName: value["toolName"],
955
+ callId: value["callId"],
956
+ outcome: value["outcome"],
957
+ summary: value["summary"],
958
+ };
959
+ case "approval_request":
960
+ if (!hasExactKeys(value, ["kind", "approvalId", "action", "risk"]) ||
961
+ !isAdmissibleIdentifier(value["approvalId"]) ||
962
+ typeof value["action"] !== "string" ||
963
+ !isOneOf(value["risk"], ["low", "medium", "high"]))
964
+ return invalidEvent();
965
+ return {
966
+ kind: "approval_request",
967
+ approvalId: value["approvalId"],
968
+ action: value["action"],
969
+ risk: value["risk"],
970
+ };
971
+ case "approval_resolution":
972
+ if (!hasExactKeys(value, ["kind", "approvalId", "decision"]) ||
973
+ !isAdmissibleIdentifier(value["approvalId"]) ||
974
+ !isOneOf(value["decision"], ["approved", "denied", "cancelled"]))
975
+ return invalidEvent();
976
+ return {
977
+ kind: "approval_resolution",
978
+ approvalId: value["approvalId"],
979
+ decision: value["decision"],
980
+ };
981
+ case "error":
982
+ if (!hasExactKeys(value, ["kind", "code", "message", "retryable"]) ||
983
+ !isAdmissibleIdentifier(value["code"]) ||
984
+ typeof value["message"] !== "string" ||
985
+ typeof value["retryable"] !== "boolean")
986
+ return invalidEvent();
987
+ return {
988
+ kind: "error",
989
+ code: value["code"],
990
+ message: value["message"],
991
+ retryable: value["retryable"],
992
+ };
993
+ case "lifecycle":
994
+ if (!hasExactKeys(value, ["kind", "state"]) ||
995
+ !isOneOf(value["state"], [
996
+ "pending", "queued", "resolving", "running", "parsing",
997
+ "awaiting_approval", "succeeded", "partial", "failed", "cancelled",
998
+ "interrupted", "timeout", "completed",
999
+ ]))
1000
+ return invalidEvent();
1001
+ return { kind: "lifecycle", state: value["state"] };
1002
+ case "usage": {
1003
+ if (!hasExactKeys(value, [
1004
+ "kind", "completeness", "inputTokens", "outputTokens",
1005
+ "cachedInputTokens", "reasoningTokens",
1006
+ ]) ||
1007
+ !isOneOf(value["completeness"], ["complete", "partial", "unknown"]) ||
1008
+ !isTokenCountOrNull(value["inputTokens"]) ||
1009
+ !isTokenCountOrNull(value["outputTokens"]) ||
1010
+ !isTokenCountOrNull(value["cachedInputTokens"]) ||
1011
+ !isTokenCountOrNull(value["reasoningTokens"]))
1012
+ return invalidEvent();
1013
+ const counters = [
1014
+ value["inputTokens"], value["outputTokens"],
1015
+ value["cachedInputTokens"], value["reasoningTokens"],
1016
+ ];
1017
+ const knownCount = counters.filter((counter) => counter !== null).length;
1018
+ if ((value["completeness"] === "unknown" && knownCount !== 0) ||
1019
+ (value["completeness"] === "complete" &&
1020
+ (value["inputTokens"] === null || value["outputTokens"] === null)) ||
1021
+ (value["completeness"] === "partial" &&
1022
+ (knownCount === 0 || knownCount === counters.length)))
1023
+ return invalidEvent();
1024
+ return {
1025
+ kind: "usage",
1026
+ completeness: value["completeness"],
1027
+ inputTokens: value["inputTokens"],
1028
+ outputTokens: value["outputTokens"],
1029
+ cachedInputTokens: value["cachedInputTokens"],
1030
+ reasoningTokens: value["reasoningTokens"],
1031
+ };
1032
+ }
1033
+ case "reasoning":
1034
+ if (!hasExactKeys(value, ["kind", "summary"]) || typeof value["summary"] !== "string") {
1035
+ return invalidEvent();
1036
+ }
1037
+ return { kind: "reasoning", summary: value["summary"] };
1038
+ case "unknown":
1039
+ if (!hasExactKeys(value, ["kind", "originalKind", "summary", "forwardCaptured"]) ||
1040
+ !isAdmissibleIdentifier(value["originalKind"]) ||
1041
+ typeof value["summary"] !== "string" ||
1042
+ value["forwardCaptured"] !== true)
1043
+ return invalidEvent();
1044
+ return {
1045
+ kind: "unknown",
1046
+ originalKind: value["originalKind"],
1047
+ summary: value["summary"],
1048
+ forwardCaptured: true,
1049
+ };
1050
+ default:
1051
+ return invalidEvent();
1052
+ }
1053
+ }
1054
+ function validateArgumentDetail(value) {
1055
+ if (!isPlainRecord(value) || !hasExactKeys(value, ["content", "omission"]) ||
1056
+ typeof value["content"] !== "string" ||
1057
+ !isOneOf(value["omission"], ["none", "size_limit", "structure_limit", "invalid"]) ||
1058
+ (value["omission"] !== "none" && value["content"] !== ""))
1059
+ return invalidEvent();
1060
+ return { content: value["content"], omission: value["omission"] };
1061
+ }
1062
+ function invalidEvent() {
1063
+ throw new TypeError("unsupported session-log-v1 normalized event");
1064
+ }
1065
+ function hasExactKeys(value, expected) {
1066
+ const actual = Object.keys(value);
1067
+ return actual.length === expected.length && expected.every((key) => actual.includes(key));
1068
+ }
1069
+ function isOwnerId(value) {
1070
+ return typeof value === "string" && /^[A-Za-z0-9_-]{1,128}$/.test(value);
1071
+ }
1072
+ function isAdmissibleIdentifier(value) {
1073
+ return typeof value === "string" && (isOwnerId(value) || redactText(value).count > 0);
1074
+ }
1075
+ function isOneOf(value, allowed) {
1076
+ return typeof value === "string" && allowed.some((candidate) => candidate === value);
1077
+ }
1078
+ function isTokenCountOrNull(value) {
1079
+ return value === null || (typeof value === "number" &&
1080
+ Number.isSafeInteger(value) &&
1081
+ value >= 0);
1082
+ }
1083
+ function isPlainRecord(value) {
1084
+ if (value === null || typeof value !== "object" || Array.isArray(value))
1085
+ return false;
1086
+ try {
1087
+ const prototype = Object.getPrototypeOf(value);
1088
+ if (prototype !== Object.prototype && prototype !== null)
1089
+ return false;
1090
+ return Reflect.ownKeys(value).every((key) => {
1091
+ if (typeof key !== "string")
1092
+ return false;
1093
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
1094
+ return descriptor?.enumerable === true && "value" in descriptor;
1095
+ });
1096
+ }
1097
+ catch {
1098
+ return false;
1099
+ }
1100
+ }
1101
+ //# sourceMappingURL=session-log-redaction.js.map