@resolveio/server-lib 22.3.197 → 22.3.198

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 (745) hide show
  1. package/ai/assistant-core-heuristics.d.ts +11 -0
  2. package/ai/assistant-core-heuristics.js +356 -0
  3. package/ai/assistant-core-heuristics.js.map +1 -0
  4. package/ai/resolveio-platform-intelligence-memory-corpus.d.ts +3 -0
  5. package/ai/resolveio-platform-intelligence-memory-corpus.js +214 -0
  6. package/ai/resolveio-platform-intelligence-memory-corpus.js.map +1 -0
  7. package/ai/resolveio-platform-intelligence-memory.d.ts +20 -0
  8. package/ai/resolveio-platform-intelligence-memory.js +341 -0
  9. package/ai/resolveio-platform-intelligence-memory.js.map +1 -0
  10. package/{src/ai/resolveio-platform-intelligence-types.ts → ai/resolveio-platform-intelligence-types.d.ts} +15 -20
  11. package/ai/resolveio-platform-intelligence-types.js +4 -0
  12. package/ai/resolveio-platform-intelligence-types.js.map +1 -0
  13. package/ai/resolveio-platform-intelligence.d.ts +6 -0
  14. package/ai/resolveio-platform-intelligence.js +463 -0
  15. package/ai/resolveio-platform-intelligence.js.map +1 -0
  16. package/client-server-app.d.ts +1 -0
  17. package/client-server-app.js +68 -0
  18. package/client-server-app.js.map +1 -0
  19. package/collections/ai-run.collection.d.ts +3 -0
  20. package/collections/ai-run.collection.js +170 -0
  21. package/collections/ai-run.collection.js.map +1 -0
  22. package/collections/ai-terminal-conversation.collection.d.ts +2 -0
  23. package/collections/ai-terminal-conversation.collection.js +140 -0
  24. package/collections/ai-terminal-conversation.collection.js.map +1 -0
  25. package/collections/ai-terminal-issue-report.collection.d.ts +2 -0
  26. package/collections/ai-terminal-issue-report.collection.js +148 -0
  27. package/collections/ai-terminal-issue-report.collection.js.map +1 -0
  28. package/collections/ai-terminal-message.collection.d.ts +2 -0
  29. package/collections/ai-terminal-message.collection.js +121 -0
  30. package/collections/ai-terminal-message.collection.js.map +1 -0
  31. package/collections/app-setting.collection.d.ts +3 -0
  32. package/collections/app-setting.collection.js +103 -0
  33. package/collections/app-setting.collection.js.map +1 -0
  34. package/collections/app-status.collection.d.ts +3 -0
  35. package/collections/app-status.collection.js +57 -0
  36. package/collections/app-status.collection.js.map +1 -0
  37. package/collections/communication-metric.collection.d.ts +2 -0
  38. package/collections/communication-metric.collection.js +133 -0
  39. package/collections/communication-metric.collection.js.map +1 -0
  40. package/collections/counter.collection.d.ts +3 -0
  41. package/collections/counter.collection.js +56 -0
  42. package/collections/counter.collection.js.map +1 -0
  43. package/collections/cron-job-history.collection.d.ts +3 -0
  44. package/collections/cron-job-history.collection.js +137 -0
  45. package/collections/cron-job-history.collection.js.map +1 -0
  46. package/collections/cron-job.collection.d.ts +3 -0
  47. package/collections/cron-job.collection.js +92 -0
  48. package/collections/cron-job.collection.js.map +1 -0
  49. package/collections/customer-notification.collection.d.ts +3 -0
  50. package/collections/customer-notification.collection.js +130 -0
  51. package/collections/customer-notification.collection.js.map +1 -0
  52. package/collections/customer-portal-password.collection.d.ts +3 -0
  53. package/collections/customer-portal-password.collection.js +75 -0
  54. package/collections/customer-portal-password.collection.js.map +1 -0
  55. package/collections/email-history.collection.d.ts +3 -0
  56. package/collections/email-history.collection.js +134 -0
  57. package/collections/email-history.collection.js.map +1 -0
  58. package/collections/email-verified.collection.d.ts +3 -0
  59. package/collections/email-verified.collection.js +62 -0
  60. package/collections/email-verified.collection.js.map +1 -0
  61. package/collections/file.collection.d.ts +3 -0
  62. package/collections/file.collection.js +74 -0
  63. package/collections/file.collection.js.map +1 -0
  64. package/collections/flag-update.collection.d.ts +3 -0
  65. package/collections/flag-update.collection.js +57 -0
  66. package/collections/flag-update.collection.js.map +1 -0
  67. package/collections/flag.collection.d.ts +3 -0
  68. package/collections/flag.collection.js +57 -0
  69. package/collections/flag.collection.js.map +1 -0
  70. package/collections/log-method-latency.collection.d.ts +3 -0
  71. package/collections/log-method-latency.collection.js +77 -0
  72. package/collections/log-method-latency.collection.js.map +1 -0
  73. package/collections/log-subscription.collection.d.ts +3 -0
  74. package/collections/log-subscription.collection.js +80 -0
  75. package/collections/log-subscription.collection.js.map +1 -0
  76. package/collections/log.collection.d.ts +3 -0
  77. package/collections/log.collection.js +93 -0
  78. package/collections/log.collection.js.map +1 -0
  79. package/collections/logged-in-users.collection.d.ts +3 -0
  80. package/collections/logged-in-users.collection.js +67 -0
  81. package/collections/logged-in-users.collection.js.map +1 -0
  82. package/collections/monitor-cpu.collection.d.ts +3 -0
  83. package/collections/monitor-cpu.collection.js +65 -0
  84. package/collections/monitor-cpu.collection.js.map +1 -0
  85. package/collections/monitor-function.collection.d.ts +3 -0
  86. package/collections/monitor-function.collection.js +74 -0
  87. package/collections/monitor-function.collection.js.map +1 -0
  88. package/collections/monitor-memory.collection.d.ts +3 -0
  89. package/collections/monitor-memory.collection.js +77 -0
  90. package/collections/monitor-memory.collection.js.map +1 -0
  91. package/collections/monitor-mongo.collection.d.ts +3 -0
  92. package/collections/monitor-mongo.collection.js +71 -0
  93. package/collections/monitor-mongo.collection.js.map +1 -0
  94. package/collections/notification.collection.d.ts +3 -0
  95. package/collections/notification.collection.js +57 -0
  96. package/collections/notification.collection.js.map +1 -0
  97. package/collections/openai-usage-ledger.collection.d.ts +2 -0
  98. package/collections/openai-usage-ledger.collection.js +188 -0
  99. package/collections/openai-usage-ledger.collection.js.map +1 -0
  100. package/collections/report-builder-dashboard-builder.collection.d.ts +3 -0
  101. package/collections/report-builder-dashboard-builder.collection.js +109 -0
  102. package/collections/report-builder-dashboard-builder.collection.js.map +1 -0
  103. package/collections/report-builder-library.collection.d.ts +3 -0
  104. package/collections/report-builder-library.collection.js +87 -0
  105. package/collections/report-builder-library.collection.js.map +1 -0
  106. package/collections/report-builder-report.collection.d.ts +4 -0
  107. package/collections/report-builder-report.collection.js +184 -0
  108. package/collections/report-builder-report.collection.js.map +1 -0
  109. package/collections/user-group.collection.d.ts +4 -0
  110. package/collections/user-group.collection.js +89 -0
  111. package/collections/user-group.collection.js.map +1 -0
  112. package/collections/user-guide.collection.d.ts +3 -0
  113. package/collections/user-guide.collection.js +57 -0
  114. package/collections/user-guide.collection.js.map +1 -0
  115. package/collections/user.collection.d.ts +4 -0
  116. package/collections/user.collection.js +180 -0
  117. package/collections/user.collection.js.map +1 -0
  118. package/cron/cron.d.ts +14 -0
  119. package/cron/cron.js +216 -0
  120. package/cron/cron.js.map +1 -0
  121. package/fixtures/cron-jobs.d.ts +1 -0
  122. package/fixtures/cron-jobs.js +150 -0
  123. package/fixtures/cron-jobs.js.map +1 -0
  124. package/fixtures/init.d.ts +1 -0
  125. package/fixtures/init.js +91 -0
  126. package/fixtures/init.js.map +1 -0
  127. package/http/auth.d.ts +2 -0
  128. package/http/auth.js +951 -0
  129. package/http/auth.js.map +1 -0
  130. package/http/health.d.ts +1 -0
  131. package/http/health.js +11 -0
  132. package/http/health.js.map +1 -0
  133. package/http/home.d.ts +1 -0
  134. package/http/home.js +134 -0
  135. package/http/home.js.map +1 -0
  136. package/http/slow-query-publication.d.ts +2 -0
  137. package/http/slow-query-publication.js +99 -0
  138. package/http/slow-query-publication.js.map +1 -0
  139. package/index.d.ts +1 -0
  140. package/index.js +19 -0
  141. package/index.js.map +1 -0
  142. package/managers/ai-assistant-codex-manager.manager.d.ts +67 -0
  143. package/managers/ai-assistant-codex-manager.manager.js +1113 -0
  144. package/managers/ai-assistant-codex-manager.manager.js.map +1 -0
  145. package/managers/ai-run-evidence.manager.d.ts +36 -0
  146. package/managers/ai-run-evidence.manager.js +377 -0
  147. package/managers/ai-run-evidence.manager.js.map +1 -0
  148. package/managers/communication-metric.manager.d.ts +16 -0
  149. package/managers/communication-metric.manager.js +134 -0
  150. package/managers/communication-metric.manager.js.map +1 -0
  151. package/managers/cron.manager.d.ts +20 -0
  152. package/managers/cron.manager.js +534 -0
  153. package/managers/cron.manager.js.map +1 -0
  154. package/managers/customer-notification-content.manager.d.ts +55 -0
  155. package/managers/customer-notification-content.manager.js +158 -0
  156. package/managers/customer-notification-content.manager.js.map +1 -0
  157. package/managers/diagnostic-manager-bootstrap.d.ts +9 -0
  158. package/managers/diagnostic-manager-bootstrap.js +260 -0
  159. package/managers/diagnostic-manager-bootstrap.js.map +1 -0
  160. package/managers/error-auto-fix.manager.d.ts +149 -0
  161. package/managers/error-auto-fix.manager.js +3064 -0
  162. package/managers/error-auto-fix.manager.js.map +1 -0
  163. package/managers/local-log.manager.d.ts +18 -0
  164. package/managers/local-log.manager.js +88 -0
  165. package/managers/local-log.manager.js.map +1 -0
  166. package/managers/method.manager.d.ts +84 -0
  167. package/managers/method.manager.js +1964 -0
  168. package/managers/method.manager.js.map +1 -0
  169. package/managers/mongo.manager.d.ts +224 -0
  170. package/managers/mongo.manager.js +5000 -0
  171. package/managers/mongo.manager.js.map +1 -0
  172. package/managers/monitor.manager.d.ts +70 -0
  173. package/managers/monitor.manager.js +550 -0
  174. package/managers/monitor.manager.js.map +1 -0
  175. package/managers/openai-usage-ledger.manager.d.ts +30 -0
  176. package/managers/openai-usage-ledger.manager.js +142 -0
  177. package/managers/openai-usage-ledger.manager.js.map +1 -0
  178. package/managers/slow-query-verifier.manager.d.ts +144 -0
  179. package/managers/slow-query-verifier.manager.js +3857 -0
  180. package/managers/slow-query-verifier.manager.js.map +1 -0
  181. package/managers/slow-query.manager.d.ts +28 -0
  182. package/managers/slow-query.manager.js +468 -0
  183. package/managers/slow-query.manager.js.map +1 -0
  184. package/managers/subscription.manager.d.ts +169 -0
  185. package/managers/subscription.manager.js +3434 -0
  186. package/managers/subscription.manager.js.map +1 -0
  187. package/managers/websocket.manager.d.ts +73 -0
  188. package/managers/websocket.manager.js +673 -0
  189. package/managers/websocket.manager.js.map +1 -0
  190. package/managers/worker-dispatcher.manager.d.ts +120 -0
  191. package/managers/worker-dispatcher.manager.js +1266 -0
  192. package/managers/worker-dispatcher.manager.js.map +1 -0
  193. package/managers/worker-server.manager.d.ts +35 -0
  194. package/managers/worker-server.manager.js +582 -0
  195. package/managers/worker-server.manager.js.map +1 -0
  196. package/methods/accounts.d.ts +2 -0
  197. package/methods/accounts.js +624 -0
  198. package/methods/accounts.js.map +1 -0
  199. package/methods/ai-terminal.d.ts +338 -0
  200. package/methods/ai-terminal.js +23454 -0
  201. package/methods/ai-terminal.js.map +1 -0
  202. package/methods/app-settings.d.ts +2 -0
  203. package/methods/app-settings.js +169 -0
  204. package/methods/app-settings.js.map +1 -0
  205. package/methods/aws.d.ts +2 -0
  206. package/methods/aws.js +877 -0
  207. package/methods/aws.js.map +1 -0
  208. package/methods/collections.d.ts +2 -0
  209. package/methods/collections.js +719 -0
  210. package/methods/collections.js.map +1 -0
  211. package/methods/counters.d.ts +2 -0
  212. package/methods/counters.js +113 -0
  213. package/methods/counters.js.map +1 -0
  214. package/methods/cron-jobs.d.ts +2 -0
  215. package/methods/cron-jobs.js +2475 -0
  216. package/methods/cron-jobs.js.map +1 -0
  217. package/methods/customer-notifications.d.ts +2 -0
  218. package/methods/customer-notifications.js +528 -0
  219. package/methods/customer-notifications.js.map +1 -0
  220. package/methods/diagnostics.d.ts +2 -0
  221. package/methods/diagnostics.js +703 -0
  222. package/methods/diagnostics.js.map +1 -0
  223. package/methods/flag-updates.d.ts +2 -0
  224. package/methods/flag-updates.js +8 -0
  225. package/methods/flag-updates.js.map +1 -0
  226. package/methods/flags.d.ts +2 -0
  227. package/methods/flags.js +8 -0
  228. package/methods/flags.js.map +1 -0
  229. package/methods/logs.d.ts +2 -0
  230. package/methods/logs.js +751 -0
  231. package/methods/logs.js.map +1 -0
  232. package/methods/mongo-explorer.d.ts +2 -0
  233. package/methods/mongo-explorer.js +1808 -0
  234. package/methods/mongo-explorer.js.map +1 -0
  235. package/methods/monitor.d.ts +2 -0
  236. package/methods/monitor.js +543 -0
  237. package/methods/monitor.js.map +1 -0
  238. package/methods/pdf.d.ts +2 -0
  239. package/methods/pdf.js +1216 -0
  240. package/methods/pdf.js.map +1 -0
  241. package/methods/publications.d.ts +1 -0
  242. package/methods/publications.js +183 -0
  243. package/methods/publications.js.map +1 -0
  244. package/methods/report-builder.d.ts +2 -0
  245. package/methods/report-builder.js +3094 -0
  246. package/methods/report-builder.js.map +1 -0
  247. package/methods/support.d.ts +2 -0
  248. package/methods/support.js +430 -0
  249. package/methods/support.js.map +1 -0
  250. package/models/ai-run.model.d.ts +19 -0
  251. package/models/ai-run.model.js +4 -0
  252. package/models/ai-run.model.js.map +1 -0
  253. package/models/ai-terminal-conversation.model.d.ts +17 -0
  254. package/models/ai-terminal-conversation.model.js +4 -0
  255. package/models/ai-terminal-conversation.model.js.map +1 -0
  256. package/models/ai-terminal-issue-report.model.d.ts +19 -0
  257. package/models/ai-terminal-issue-report.model.js +4 -0
  258. package/models/ai-terminal-issue-report.model.js.map +1 -0
  259. package/models/ai-terminal-message.model.d.ts +22 -0
  260. package/models/ai-terminal-message.model.js +4 -0
  261. package/models/ai-terminal-message.model.js.map +1 -0
  262. package/models/app-setting.model.d.ts +16 -0
  263. package/models/app-setting.model.js +4 -0
  264. package/models/app-setting.model.js.map +1 -0
  265. package/{src/models/app-status.model.ts → models/app-status.model.d.ts} +2 -3
  266. package/models/app-status.model.js +4 -0
  267. package/models/app-status.model.js.map +1 -0
  268. package/{src/models/billing-logged-in-users.model.ts → models/billing-logged-in-users.model.d.ts} +4 -5
  269. package/models/billing-logged-in-users.model.js +4 -0
  270. package/models/billing-logged-in-users.model.js.map +1 -0
  271. package/models/collection-document.model.d.ts +21 -0
  272. package/models/collection-document.model.js +4 -0
  273. package/models/collection-document.model.js.map +1 -0
  274. package/models/communication-metric.model.d.ts +20 -0
  275. package/models/communication-metric.model.js +4 -0
  276. package/models/communication-metric.model.js.map +1 -0
  277. package/{src/models/counter.model.ts → models/counter.model.d.ts} +3 -4
  278. package/models/counter.model.js +4 -0
  279. package/models/counter.model.js.map +1 -0
  280. package/models/cron-job-history.model.d.ts +15 -0
  281. package/models/cron-job-history.model.js +4 -0
  282. package/models/cron-job-history.model.js.map +1 -0
  283. package/models/cron-job.model.d.ts +14 -0
  284. package/models/cron-job.model.js +4 -0
  285. package/models/cron-job.model.js.map +1 -0
  286. package/models/customer-notification.model.d.ts +26 -0
  287. package/models/customer-notification.model.js +4 -0
  288. package/models/customer-notification.model.js.map +1 -0
  289. package/models/customer-portal-password.model.d.ts +11 -0
  290. package/models/customer-portal-password.model.js +4 -0
  291. package/models/customer-portal-password.model.js.map +1 -0
  292. package/models/dialog.model.d.ts +23 -0
  293. package/models/dialog.model.js +4 -0
  294. package/models/dialog.model.js.map +1 -0
  295. package/models/email-history.model.d.ts +32 -0
  296. package/{src/models/email-history.model.ts → models/email-history.model.js} +4 -36
  297. package/models/email-history.model.js.map +1 -0
  298. package/{src/models/email-verified.model.ts → models/email-verified.model.d.ts} +5 -6
  299. package/models/email-verified.model.js +4 -0
  300. package/models/email-verified.model.js.map +1 -0
  301. package/{src/models/file.model.ts → models/file.model.d.ts} +7 -8
  302. package/models/file.model.js +4 -0
  303. package/models/file.model.js.map +1 -0
  304. package/{src/models/flag-update.model.ts → models/flag-update.model.d.ts} +3 -4
  305. package/models/flag-update.model.js +4 -0
  306. package/models/flag-update.model.js.map +1 -0
  307. package/{src/models/flag.model.ts → models/flag.model.d.ts} +3 -4
  308. package/models/flag.model.js +4 -0
  309. package/models/flag.model.js.map +1 -0
  310. package/models/log-method-latency.model.d.ts +10 -0
  311. package/models/log-method-latency.model.js +4 -0
  312. package/models/log-method-latency.model.js.map +1 -0
  313. package/{src/models/log-subscription.model.ts → models/log-subscription.model.d.ts} +9 -11
  314. package/models/log-subscription.model.js +4 -0
  315. package/models/log-subscription.model.js.map +1 -0
  316. package/models/log.model.d.ts +17 -0
  317. package/models/log.model.js +4 -0
  318. package/models/log.model.js.map +1 -0
  319. package/{src/models/logged-in-users.model.ts → models/logged-in-users.model.d.ts} +5 -6
  320. package/models/logged-in-users.model.js +4 -0
  321. package/models/logged-in-users.model.js.map +1 -0
  322. package/{src/models/method-response.model.ts → models/method-response.model.d.ts} +6 -7
  323. package/models/method-response.model.js +4 -0
  324. package/models/method-response.model.js.map +1 -0
  325. package/models/method.model.d.ts +26 -0
  326. package/models/method.model.js +4 -0
  327. package/models/method.model.js.map +1 -0
  328. package/{src/models/monitor-cpu.model.ts → models/monitor-cpu.model.d.ts} +7 -9
  329. package/models/monitor-cpu.model.js +4 -0
  330. package/models/monitor-cpu.model.js.map +1 -0
  331. package/models/monitor-function.model.d.ts +14 -0
  332. package/models/monitor-function.model.js +4 -0
  333. package/models/monitor-function.model.js.map +1 -0
  334. package/models/monitor-memory.model.d.ts +15 -0
  335. package/models/monitor-memory.model.js +4 -0
  336. package/models/monitor-memory.model.js.map +1 -0
  337. package/models/monitor-mongo.model.d.ts +13 -0
  338. package/models/monitor-mongo.model.js +4 -0
  339. package/models/monitor-mongo.model.js.map +1 -0
  340. package/{src/models/notification.model.ts → models/notification.model.d.ts} +4 -6
  341. package/models/notification.model.js +4 -0
  342. package/models/notification.model.js.map +1 -0
  343. package/models/openai-usage-ledger.model.d.ts +30 -0
  344. package/models/openai-usage-ledger.model.js +4 -0
  345. package/models/openai-usage-ledger.model.js.map +1 -0
  346. package/models/pagination.model.d.ts +11 -0
  347. package/models/pagination.model.js +28 -0
  348. package/models/pagination.model.js.map +1 -0
  349. package/models/permission.model.d.ts +12 -0
  350. package/models/permission.model.js +4 -0
  351. package/models/permission.model.js.map +1 -0
  352. package/models/report-builder-dashboard-builder.model.d.ts +25 -0
  353. package/models/report-builder-dashboard-builder.model.js +4 -0
  354. package/models/report-builder-dashboard-builder.model.js.map +1 -0
  355. package/models/report-builder-library.model.d.ts +17 -0
  356. package/models/report-builder-library.model.js +4 -0
  357. package/models/report-builder-library.model.js.map +1 -0
  358. package/models/report-builder-report.model.d.ts +121 -0
  359. package/models/report-builder-report.model.js +4 -0
  360. package/models/report-builder-report.model.js.map +1 -0
  361. package/models/report-builder.model.d.ts +61 -0
  362. package/models/report-builder.model.js +4 -0
  363. package/models/report-builder.model.js.map +1 -0
  364. package/models/select-data-label.model.d.ts +9 -0
  365. package/models/select-data-label.model.js +4 -0
  366. package/models/select-data-label.model.js.map +1 -0
  367. package/models/server-message.model.d.ts +32 -0
  368. package/models/server-message.model.js +4 -0
  369. package/models/server-message.model.js.map +1 -0
  370. package/models/slow-query-report.model.d.ts +23 -0
  371. package/models/slow-query-report.model.js +4 -0
  372. package/models/slow-query-report.model.js.map +1 -0
  373. package/models/subscription.model.d.ts +31 -0
  374. package/models/subscription.model.js +4 -0
  375. package/models/subscription.model.js.map +1 -0
  376. package/models/support-ticket.model.d.ts +87 -0
  377. package/models/support-ticket.model.js +4 -0
  378. package/models/support-ticket.model.js.map +1 -0
  379. package/models/user-group.model.d.ts +20 -0
  380. package/models/user-group.model.js +4 -0
  381. package/models/user-group.model.js.map +1 -0
  382. package/{src/models/user-guide.model.ts → models/user-guide.model.d.ts} +4 -5
  383. package/models/user-guide.model.js +4 -0
  384. package/models/user-guide.model.js.map +1 -0
  385. package/models/user.model.d.ts +84 -0
  386. package/models/user.model.js +4 -0
  387. package/models/user.model.js.map +1 -0
  388. package/package.json +1 -1
  389. package/private/images/ResolveIO.png +0 -0
  390. package/public_api.js +127 -0
  391. package/public_api.js.map +1 -0
  392. package/publications/ai-terminal.d.ts +1 -0
  393. package/publications/ai-terminal.js +122 -0
  394. package/publications/ai-terminal.js.map +1 -0
  395. package/publications/app-settings.d.ts +2 -0
  396. package/publications/app-settings.js +28 -0
  397. package/publications/app-settings.js.map +1 -0
  398. package/publications/app-status.d.ts +2 -0
  399. package/publications/app-status.js +16 -0
  400. package/publications/app-status.js.map +1 -0
  401. package/publications/cron-jobs.d.ts +2 -0
  402. package/publications/cron-jobs.js +88 -0
  403. package/publications/cron-jobs.js.map +1 -0
  404. package/publications/customer-notifications.d.ts +2 -0
  405. package/publications/customer-notifications.js +161 -0
  406. package/publications/customer-notifications.js.map +1 -0
  407. package/publications/files.d.ts +2 -0
  408. package/publications/files.js +36 -0
  409. package/publications/files.js.map +1 -0
  410. package/publications/flags-update.d.ts +2 -0
  411. package/publications/flags-update.js +22 -0
  412. package/publications/flags-update.js.map +1 -0
  413. package/publications/flags.d.ts +2 -0
  414. package/publications/flags.js +22 -0
  415. package/publications/flags.js.map +1 -0
  416. package/publications/logs.d.ts +2 -0
  417. package/publications/logs.js +164 -0
  418. package/publications/logs.js.map +1 -0
  419. package/publications/notifications.d.ts +2 -0
  420. package/publications/notifications.js +16 -0
  421. package/publications/notifications.js.map +1 -0
  422. package/publications/report-builder-dashboard-builders.d.ts +2 -0
  423. package/publications/report-builder-dashboard-builders.js +42 -0
  424. package/publications/report-builder-dashboard-builders.js.map +1 -0
  425. package/publications/report-builder-libraries.d.ts +2 -0
  426. package/publications/report-builder-libraries.js +90 -0
  427. package/publications/report-builder-libraries.js.map +1 -0
  428. package/publications/report-builder-reports.d.ts +2 -0
  429. package/publications/report-builder-reports.js +50 -0
  430. package/publications/report-builder-reports.js.map +1 -0
  431. package/publications/super-admin.d.ts +2 -0
  432. package/publications/super-admin.js +16 -0
  433. package/publications/super-admin.js.map +1 -0
  434. package/publications/user-groups.d.ts +1 -0
  435. package/publications/user-groups.js +16 -0
  436. package/publications/user-groups.js.map +1 -0
  437. package/publications/user-guides.d.ts +1 -0
  438. package/publications/user-guides.js +16 -0
  439. package/publications/user-guides.js.map +1 -0
  440. package/resolveio-server-app.d.ts +70 -0
  441. package/resolveio-server-app.js +801 -0
  442. package/resolveio-server-app.js.map +1 -0
  443. package/server-app.d.ts +228 -0
  444. package/server-app.js +3566 -0
  445. package/server-app.js.map +1 -0
  446. package/services/codex-client.d.ts +128 -0
  447. package/services/codex-client.js +1629 -0
  448. package/services/codex-client.js.map +1 -0
  449. package/services/openai-client.d.ts +46 -0
  450. package/services/openai-client.js +318 -0
  451. package/services/openai-client.js.map +1 -0
  452. package/types/error-report.d.ts +25 -0
  453. package/types/error-report.js +4 -0
  454. package/types/error-report.js.map +1 -0
  455. package/types/slow-query-report.d.ts +27 -0
  456. package/types/slow-query-report.js +6 -0
  457. package/types/slow-query-report.js.map +1 -0
  458. package/util/ai-qa-policy.d.ts +124 -0
  459. package/util/ai-qa-policy.js +736 -0
  460. package/util/ai-qa-policy.js.map +1 -0
  461. package/util/ai-run-evidence-adapters.d.ts +109 -0
  462. package/util/ai-run-evidence-adapters.js +4255 -0
  463. package/util/ai-run-evidence-adapters.js.map +1 -0
  464. package/util/ai-run-evidence-dashboard.d.ts +88 -0
  465. package/util/ai-run-evidence-dashboard.js +343 -0
  466. package/util/ai-run-evidence-dashboard.js.map +1 -0
  467. package/util/ai-run-evidence-eval.d.ts +86 -0
  468. package/util/ai-run-evidence-eval.js +1018 -0
  469. package/util/ai-run-evidence-eval.js.map +1 -0
  470. package/util/ai-run-evidence.d.ts +244 -0
  471. package/util/ai-run-evidence.js +852 -0
  472. package/util/ai-run-evidence.js.map +1 -0
  473. package/util/ai-runner-artifacts.d.ts +82 -0
  474. package/util/ai-runner-artifacts.js +713 -0
  475. package/util/ai-runner-artifacts.js.map +1 -0
  476. package/util/ai-runner-manager-autopilot.d.ts +210 -0
  477. package/util/ai-runner-manager-autopilot.js +642 -0
  478. package/util/ai-runner-manager-autopilot.js.map +1 -0
  479. package/util/ai-runner-manager-policy.d.ts +787 -0
  480. package/util/ai-runner-manager-policy.js +3342 -0
  481. package/util/ai-runner-manager-policy.js.map +1 -0
  482. package/util/ai-runner-qa-auth.d.ts +5 -0
  483. package/util/ai-runner-qa-auth.js +822 -0
  484. package/util/ai-runner-qa-auth.js.map +1 -0
  485. package/util/ai-runner-qa-tools.d.ts +26 -0
  486. package/util/ai-runner-qa-tools.js +3029 -0
  487. package/util/ai-runner-qa-tools.js.map +1 -0
  488. package/util/aicoder-runner-v6.d.ts +424 -0
  489. package/util/aicoder-runner-v6.js +2325 -0
  490. package/util/aicoder-runner-v6.js.map +1 -0
  491. package/util/common.d.ts +31 -0
  492. package/util/common.js +683 -0
  493. package/util/common.js.map +1 -0
  494. package/util/customer-portal-password.d.ts +13 -0
  495. package/util/customer-portal-password.js +209 -0
  496. package/util/customer-portal-password.js.map +1 -0
  497. package/util/error-reporter.d.ts +52 -0
  498. package/util/error-reporter.js +326 -0
  499. package/util/error-reporter.js.map +1 -0
  500. package/util/error-tracking.d.ts +13 -0
  501. package/util/error-tracking.js +120 -0
  502. package/util/error-tracking.js.map +1 -0
  503. package/util/openai-usage-cost.d.ts +6 -0
  504. package/util/openai-usage-cost.js +103 -0
  505. package/util/openai-usage-cost.js.map +1 -0
  506. package/util/report-builder-unwinds.d.ts +15 -0
  507. package/util/report-builder-unwinds.js +156 -0
  508. package/util/report-builder-unwinds.js.map +1 -0
  509. package/util/runner-process-janitor.d.ts +27 -0
  510. package/util/runner-process-janitor.js +208 -0
  511. package/util/runner-process-janitor.js.map +1 -0
  512. package/util/schema-report-builder.d.ts +6 -0
  513. package/util/schema-report-builder.js +481 -0
  514. package/util/schema-report-builder.js.map +1 -0
  515. package/util/slow-query-reporter.d.ts +28 -0
  516. package/util/slow-query-reporter.js +226 -0
  517. package/util/slow-query-reporter.js.map +1 -0
  518. package/util/subscription-dependency-context.d.ts +34 -0
  519. package/util/subscription-dependency-context.js +1283 -0
  520. package/util/subscription-dependency-context.js.map +1 -0
  521. package/util/support-runner-v5.d.ts +1055 -0
  522. package/util/support-runner-v5.js +4808 -0
  523. package/util/support-runner-v5.js.map +1 -0
  524. package/util/tokenizer.d.ts +5 -0
  525. package/util/tokenizer.js +41 -0
  526. package/util/tokenizer.js.map +1 -0
  527. package/workers/codex-runner.worker.d.ts +1 -0
  528. package/workers/codex-runner.worker.js +192 -0
  529. package/workers/codex-runner.worker.js.map +1 -0
  530. package/.nodemon.json +0 -5
  531. package/.vscode/settings.json +0 -21
  532. package/AGENTS.md +0 -195
  533. package/README.md +0 -22
  534. package/build_package.sh +0 -5
  535. package/compileDTS.pl +0 -64
  536. package/docs/ai-assistant-nightly-eval.md +0 -65
  537. package/docs/ai-assistant-preflight-checklist.md +0 -23
  538. package/docs/ai-assistant-report-builder-bridge-playbook.md +0 -115
  539. package/eslint-plugin-custom/index.js +0 -7
  540. package/eslint-plugin-custom/rules/no-filter-zero-index.js +0 -44
  541. package/eslint.config.js +0 -103
  542. package/gulpfile.js +0 -216
  543. package/methodAndPublicationListGenerator.py +0 -375
  544. package/mongodbensurers.js +0 -2
  545. package/mongostop.js +0 -3
  546. package/scripts/cleanup-bypassed-callmethod-logs.js +0 -616
  547. package/settings.development.json +0 -25
  548. package/settings.development.redacted.json +0 -25
  549. package/src/.env +0 -12
  550. package/src/ai/assistant-core-heuristics.ts +0 -379
  551. package/src/ai/resolveio-platform-intelligence-memory-corpus.ts +0 -185
  552. package/src/ai/resolveio-platform-intelligence-memory.ts +0 -325
  553. package/src/ai/resolveio-platform-intelligence.ts +0 -462
  554. package/src/client-server-app.ts +0 -12
  555. package/src/collections/ai-run.collection.ts +0 -117
  556. package/src/collections/ai-terminal-conversation.collection.ts +0 -91
  557. package/src/collections/ai-terminal-issue-report.collection.ts +0 -99
  558. package/src/collections/ai-terminal-message.collection.ts +0 -77
  559. package/src/collections/app-setting.collection.ts +0 -104
  560. package/src/collections/app-status.collection.ts +0 -58
  561. package/src/collections/communication-metric.collection.ts +0 -84
  562. package/src/collections/counter.collection.ts +0 -56
  563. package/src/collections/cron-job-history.collection.ts +0 -94
  564. package/src/collections/cron-job.collection.ts +0 -92
  565. package/src/collections/customer-notification.collection.ts +0 -131
  566. package/src/collections/customer-portal-password.collection.ts +0 -76
  567. package/src/collections/email-history.collection.ts +0 -134
  568. package/src/collections/email-verified.collection.ts +0 -62
  569. package/src/collections/file.collection.ts +0 -74
  570. package/src/collections/flag-update.collection.ts +0 -57
  571. package/src/collections/flag.collection.ts +0 -57
  572. package/src/collections/log-method-latency.collection.ts +0 -77
  573. package/src/collections/log-subscription.collection.ts +0 -80
  574. package/src/collections/log.collection.ts +0 -93
  575. package/src/collections/logged-in-users.collection.ts +0 -67
  576. package/src/collections/monitor-cpu.collection.ts +0 -65
  577. package/src/collections/monitor-function.collection.ts +0 -74
  578. package/src/collections/monitor-memory.collection.ts +0 -77
  579. package/src/collections/monitor-mongo.collection.ts +0 -71
  580. package/src/collections/notification.collection.ts +0 -57
  581. package/src/collections/openai-usage-ledger.collection.ts +0 -131
  582. package/src/collections/report-builder-dashboard-builder.collection.ts +0 -109
  583. package/src/collections/report-builder-library.collection.ts +0 -89
  584. package/src/collections/report-builder-report.collection.ts +0 -184
  585. package/src/collections/user-group.collection.ts +0 -89
  586. package/src/collections/user-guide.collection.ts +0 -57
  587. package/src/collections/user.collection.ts +0 -181
  588. package/src/cron/cron.ts +0 -117
  589. package/src/fixtures/cron-jobs.ts +0 -95
  590. package/src/fixtures/init.ts +0 -35
  591. package/src/http/auth.ts +0 -818
  592. package/src/http/health.ts +0 -7
  593. package/src/http/home.ts +0 -90
  594. package/src/http/slow-query-publication.ts +0 -49
  595. package/src/index.ts +0 -1
  596. package/src/managers/ai-assistant-codex-manager.manager.ts +0 -1131
  597. package/src/managers/ai-run-evidence.manager.ts +0 -264
  598. package/src/managers/communication-metric.manager.ts +0 -82
  599. package/src/managers/cron.manager.ts +0 -333
  600. package/src/managers/customer-notification-content.manager.ts +0 -236
  601. package/src/managers/diagnostic-manager-bootstrap.ts +0 -165
  602. package/src/managers/error-auto-fix.manager.ts +0 -2767
  603. package/src/managers/local-log.manager.ts +0 -113
  604. package/src/managers/method.manager.ts +0 -1857
  605. package/src/managers/mongo.manager.ts +0 -4575
  606. package/src/managers/monitor.manager.ts +0 -507
  607. package/src/managers/openai-usage-ledger.manager.ts +0 -112
  608. package/src/managers/slow-query-verifier.manager.ts +0 -3590
  609. package/src/managers/slow-query.manager.ts +0 -519
  610. package/src/managers/subscription.manager.ts +0 -3128
  611. package/src/managers/websocket.manager.ts +0 -746
  612. package/src/managers/worker-dispatcher.manager.ts +0 -1360
  613. package/src/managers/worker-server.manager.ts +0 -536
  614. package/src/methods/accounts.ts +0 -532
  615. package/src/methods/ai-terminal.ts +0 -23825
  616. package/src/methods/app-settings.ts +0 -114
  617. package/src/methods/aws.ts +0 -649
  618. package/src/methods/collections.ts +0 -641
  619. package/src/methods/counters.ts +0 -69
  620. package/src/methods/cron-jobs.ts +0 -2614
  621. package/src/methods/customer-notifications.ts +0 -458
  622. package/src/methods/diagnostics.ts +0 -616
  623. package/src/methods/flag-updates.ts +0 -7
  624. package/src/methods/flags.ts +0 -7
  625. package/src/methods/logs.ts +0 -657
  626. package/src/methods/mongo-explorer.ts +0 -1880
  627. package/src/methods/monitor.ts +0 -540
  628. package/src/methods/pdf.ts +0 -1236
  629. package/src/methods/publications.ts +0 -129
  630. package/src/methods/report-builder.ts +0 -3300
  631. package/src/methods/support.ts +0 -335
  632. package/src/models/ai-run.model.ts +0 -27
  633. package/src/models/ai-terminal-conversation.model.ts +0 -19
  634. package/src/models/ai-terminal-issue-report.model.ts +0 -21
  635. package/src/models/ai-terminal-message.model.ts +0 -24
  636. package/src/models/app-setting.model.ts +0 -17
  637. package/src/models/collection-document.model.ts +0 -24
  638. package/src/models/communication-metric.model.ts +0 -23
  639. package/src/models/cron-job-history.model.ts +0 -16
  640. package/src/models/cron-job.model.ts +0 -15
  641. package/src/models/customer-notification.model.ts +0 -28
  642. package/src/models/customer-portal-password.model.ts +0 -12
  643. package/src/models/dialog.model.ts +0 -25
  644. package/src/models/log-method-latency.model.ts +0 -11
  645. package/src/models/log.model.ts +0 -19
  646. package/src/models/method.model.ts +0 -25
  647. package/src/models/monitor-function.model.ts +0 -16
  648. package/src/models/monitor-memory.model.ts +0 -17
  649. package/src/models/monitor-mongo.model.ts +0 -15
  650. package/src/models/openai-usage-ledger.model.ts +0 -56
  651. package/src/models/pagination.model.ts +0 -35
  652. package/src/models/permission.model.ts +0 -14
  653. package/src/models/report-builder-dashboard-builder.model.ts +0 -29
  654. package/src/models/report-builder-library.model.ts +0 -20
  655. package/src/models/report-builder-report.model.ts +0 -136
  656. package/src/models/report-builder.model.ts +0 -68
  657. package/src/models/select-data-label.model.ts +0 -9
  658. package/src/models/server-message.model.ts +0 -31
  659. package/src/models/slow-query-report.model.ts +0 -23
  660. package/src/models/subscription.model.ts +0 -73
  661. package/src/models/support-ticket.model.ts +0 -104
  662. package/src/models/user-group.model.ts +0 -24
  663. package/src/models/user.model.ts +0 -96
  664. package/src/private/images/ResolveIO.png +0 -0
  665. package/src/publications/ai-terminal.ts +0 -73
  666. package/src/publications/app-settings.ts +0 -25
  667. package/src/publications/app-status.ts +0 -13
  668. package/src/publications/cron-jobs.ts +0 -40
  669. package/src/publications/customer-notifications.ts +0 -101
  670. package/src/publications/files.ts +0 -33
  671. package/src/publications/flags-update.ts +0 -19
  672. package/src/publications/flags.ts +0 -19
  673. package/src/publications/logs.ts +0 -163
  674. package/src/publications/notifications.ts +0 -13
  675. package/src/publications/report-builder-dashboard-builders.ts +0 -39
  676. package/src/publications/report-builder-libraries.ts +0 -41
  677. package/src/publications/report-builder-reports.ts +0 -47
  678. package/src/publications/super-admin.ts +0 -13
  679. package/src/publications/user-groups.ts +0 -12
  680. package/src/publications/user-guides.ts +0 -12
  681. package/src/resolveio-server-app.ts +0 -617
  682. package/src/server-app.ts +0 -3354
  683. package/src/services/codex-client.ts +0 -1231
  684. package/src/services/openai-client.ts +0 -265
  685. package/src/types/error-report.ts +0 -26
  686. package/src/types/js-tiktoken.d.ts +0 -11
  687. package/src/types/slow-query-report.ts +0 -28
  688. package/src/util/ai-qa-policy.ts +0 -925
  689. package/src/util/ai-run-evidence-adapters.ts +0 -4642
  690. package/src/util/ai-run-evidence-dashboard.ts +0 -323
  691. package/src/util/ai-run-evidence-eval.ts +0 -1057
  692. package/src/util/ai-run-evidence.ts +0 -1185
  693. package/src/util/ai-runner-artifacts.ts +0 -586
  694. package/src/util/ai-runner-manager-autopilot.ts +0 -961
  695. package/src/util/ai-runner-manager-policy.ts +0 -4806
  696. package/src/util/ai-runner-qa-auth.ts +0 -821
  697. package/src/util/ai-runner-qa-tools.ts +0 -3045
  698. package/src/util/aicoder-runner-v6.ts +0 -2979
  699. package/src/util/common.ts +0 -649
  700. package/src/util/customer-portal-password.ts +0 -183
  701. package/src/util/error-reporter.ts +0 -332
  702. package/src/util/error-tracking.ts +0 -79
  703. package/src/util/openai-usage-cost.ts +0 -114
  704. package/src/util/report-builder-unwinds.ts +0 -180
  705. package/src/util/runner-process-janitor.ts +0 -219
  706. package/src/util/schema-report-builder.ts +0 -448
  707. package/src/util/slow-query-reporter.ts +0 -216
  708. package/src/util/subscription-dependency-context.ts +0 -1096
  709. package/src/util/support-runner-v5.ts +0 -6573
  710. package/src/util/tokenizer.ts +0 -38
  711. package/src/workers/codex-runner.worker.ts +0 -142
  712. package/start_server.sh +0 -5
  713. package/tests/ai-assistant-corpus-build.ts +0 -484
  714. package/tests/ai-assistant-corpus-replay-e2e.ts +0 -774
  715. package/tests/ai-assistant-data-parity-e2e.ts +0 -1989
  716. package/tests/ai-assistant-eval-triage.ts +0 -831
  717. package/tests/ai-assistant-openai-e2e.ts +0 -1061
  718. package/tests/ai-assistant-openai-git-e2e.ts +0 -155
  719. package/tests/ai-assistant-preflight-matrix.ts +0 -215
  720. package/tests/ai-assistant-routing-eval.test.ts +0 -560
  721. package/tests/ai-assistant-snf-live-eval.ts +0 -975
  722. package/tests/ai-assistant-utils.test.ts +0 -3057
  723. package/tests/ai-manager-autopilot-snapshot.test.ts +0 -193
  724. package/tests/ai-manager-recovery-checkpoint.test.ts +0 -1287
  725. package/tests/ai-run-eval.test.ts +0 -132
  726. package/tests/ai-run-evidence.test.ts +0 -2129
  727. package/tests/ai-runner-contract.test.ts +0 -488
  728. package/tests/aicoder-runner-v6.test.ts +0 -751
  729. package/tests/error-reporter.test.ts +0 -145
  730. package/tests/method-publication-generator.test.ts +0 -46
  731. package/tests/report-builder-linking.test.ts +0 -79
  732. package/tests/resolveio-platform-intelligence.test.ts +0 -352
  733. package/tests/server-app-cron-owner.test.ts +0 -127
  734. package/tests/subscription-connect-race.test.ts +0 -158
  735. package/tests/subscription-dependency-context.test.ts +0 -324
  736. package/tests/subscription-manager-collection-tracking.test.ts +0 -86
  737. package/tests/subscription-manager-invalidation.test.ts +0 -86
  738. package/tests/support-runner-v5.test.ts +0 -1473
  739. package/tsconfig.json +0 -34
  740. /package/{src/private → private}/email-templates/enrollment.html +0 -0
  741. /package/{src/private → private}/email-templates/forgot-password.html +0 -0
  742. /package/{src/private → private}/email-templates/support-ticket-deleted.html +0 -0
  743. /package/{src/private → private}/email-templates/support-ticket-modified.html +0 -0
  744. /package/{src/private → private}/email-templates/support-ticket.html +0 -0
  745. /package/{src/public_api.ts → public_api.d.ts} +0 -0
@@ -0,0 +1,4255 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __values = (this && this.__values) || function(o) {
14
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
15
+ if (m) return m.call(o);
16
+ if (o && typeof o.length === "number") return {
17
+ next: function () {
18
+ if (o && i >= o.length) o = void 0;
19
+ return { value: o && o[i++], done: !o };
20
+ }
21
+ };
22
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
23
+ };
24
+ var __read = (this && this.__read) || function (o, n) {
25
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
26
+ if (!m) return o;
27
+ var i = m.call(o), r, ar = [], e;
28
+ try {
29
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
30
+ }
31
+ catch (error) { e = { error: error }; }
32
+ finally {
33
+ try {
34
+ if (r && !r.done && (m = i["return"])) m.call(i);
35
+ }
36
+ finally { if (e) throw e.error; }
37
+ }
38
+ return ar;
39
+ };
40
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
41
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
42
+ if (ar || !(i in from)) {
43
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
44
+ ar[i] = from[i];
45
+ }
46
+ }
47
+ return to.concat(ar || Array.prototype.slice.call(from));
48
+ };
49
+ Object.defineProperty(exports, "__esModule", { value: true });
50
+ exports.evaluateAssistantAnswerQuality = evaluateAssistantAnswerQuality;
51
+ exports.buildAssistantAnswerActionabilityContract = buildAssistantAnswerActionabilityContract;
52
+ exports.buildSupportAIRunFromEvidence = buildSupportAIRunFromEvidence;
53
+ exports.buildAICoderAIRunFromEvidence = buildAICoderAIRunFromEvidence;
54
+ exports.buildAssistantAIRunFromEvidence = buildAssistantAIRunFromEvidence;
55
+ var ai_run_evidence_1 = require("./ai-run-evidence");
56
+ var aicoder_runner_v6_1 = require("./aicoder-runner-v6");
57
+ var ai_runner_manager_policy_1 = require("./ai-runner-manager-policy");
58
+ var support_runner_v5_1 = require("./support-runner-v5");
59
+ function cleanText(value, max) {
60
+ if (max === void 0) { max = 1000; }
61
+ return String(value || '').replace(/\s+/g, ' ').trim().slice(0, max);
62
+ }
63
+ function idText(value, max) {
64
+ if (max === void 0) { max = 160; }
65
+ var normalized = cleanText(value, max);
66
+ return normalized || undefined;
67
+ }
68
+ function asArray(value) {
69
+ return Array.isArray(value) ? value : [];
70
+ }
71
+ function cleanStringList(value, limit, max) {
72
+ if (limit === void 0) { limit = 40; }
73
+ if (max === void 0) { max = 500; }
74
+ return asArray(value)
75
+ .map(function (entry) { return cleanText(entry, max); })
76
+ .filter(Boolean)
77
+ .slice(0, limit);
78
+ }
79
+ function plainObject(value) {
80
+ return value && typeof value === 'object' && !Array.isArray(value) ? value : {};
81
+ }
82
+ function firstText(source, fields, max) {
83
+ var e_1, _a;
84
+ if (max === void 0) { max = 1000; }
85
+ try {
86
+ for (var fields_1 = __values(fields), fields_1_1 = fields_1.next(); !fields_1_1.done; fields_1_1 = fields_1.next()) {
87
+ var field = fields_1_1.value;
88
+ var value = source === null || source === void 0 ? void 0 : source[field];
89
+ var normalized = idText(value, max);
90
+ if (normalized) {
91
+ return normalized;
92
+ }
93
+ }
94
+ }
95
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
96
+ finally {
97
+ try {
98
+ if (fields_1_1 && !fields_1_1.done && (_a = fields_1.return)) _a.call(fields_1);
99
+ }
100
+ finally { if (e_1) throw e_1.error; }
101
+ }
102
+ return undefined;
103
+ }
104
+ function dateValue(source, fields) {
105
+ var e_2, _a;
106
+ try {
107
+ for (var fields_2 = __values(fields), fields_2_1 = fields_2.next(); !fields_2_1.done; fields_2_1 = fields_2.next()) {
108
+ var field = fields_2_1.value;
109
+ var value = source === null || source === void 0 ? void 0 : source[field];
110
+ if (value) {
111
+ return value;
112
+ }
113
+ }
114
+ }
115
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
116
+ finally {
117
+ try {
118
+ if (fields_2_1 && !fields_2_1.done && (_a = fields_2.return)) _a.call(fields_2);
119
+ }
120
+ finally { if (e_2) throw e_2.error; }
121
+ }
122
+ return undefined;
123
+ }
124
+ function addSourceId(sourceIds, key, value) {
125
+ var normalized = idText(value);
126
+ if (normalized) {
127
+ sourceIds[key] = normalized;
128
+ }
129
+ }
130
+ function pushEvent(events, event) {
131
+ var _a;
132
+ var message = cleanText(event.message, 1800);
133
+ var metadata = event.metadata || {};
134
+ if (!message && !Object.keys(metadata).length && !((_a = event.artifactPaths) === null || _a === void 0 ? void 0 : _a.length)) {
135
+ return;
136
+ }
137
+ events.push(__assign(__assign({}, event), { message: message, artifactPaths: asArray(event.artifactPaths).filter(Boolean).slice(0, 20) }));
138
+ }
139
+ function eventDate(record) {
140
+ return dateValue(record, ['recordedAt', 'createdAt', 'updatedAt', 'timestamp', 'time', 'date']);
141
+ }
142
+ function normalizeManagerFailureRecord(value, fallback) {
143
+ if (fallback === void 0) { fallback = {}; }
144
+ var entry = plainObject(value);
145
+ if (!Object.keys(entry).length && !Object.keys(fallback).length) {
146
+ return undefined;
147
+ }
148
+ var blocker = cleanText(entry.blocker || entry.reason || entry.summary || entry.message || fallback.blocker || fallback.summary, 1200);
149
+ var failureClass = cleanText(entry.failureClass || entry.failure_class || entry.class || fallback.failureClass, 120);
150
+ var evidenceHash = cleanText(entry.evidenceHash || entry.evidence_hash || entry.hash || fallback.evidenceHash, 180);
151
+ var blockerFingerprint = cleanText(entry.blockerFingerprint || entry.blocker_fingerprint || fallback.blockerFingerprint, 180);
152
+ var lane = cleanText(entry.lane || fallback.lane || 'support', 80);
153
+ var stepType = cleanText(entry.stepType || entry.step_type || entry.type || fallback.stepType || 'support_step', 80);
154
+ var outcome = cleanText(entry.outcome || entry.status || entry.result || fallback.outcome || 'needs_repair', 80);
155
+ if (!blocker && !failureClass && !evidenceHash && !blockerFingerprint) {
156
+ return undefined;
157
+ }
158
+ return {
159
+ lane: lane,
160
+ stepType: stepType,
161
+ outcome: outcome,
162
+ failureClass: failureClass || undefined,
163
+ blocker: blocker || undefined,
164
+ summary: cleanText(entry.summary || entry.message || fallback.summary, 1200) || undefined,
165
+ blockerFingerprint: blockerFingerprint || undefined,
166
+ evidenceHash: evidenceHash || undefined,
167
+ changedFiles: cleanStringList(entry.changedFiles || entry.changed_files || fallback.changedFiles, 80, 500),
168
+ artifactPaths: cleanStringList(entry.artifactPaths || entry.artifact_paths || entry.artifacts || fallback.artifactPaths, 80, 500)
169
+ };
170
+ }
171
+ function supportManagerFailureRecords(job, evidence) {
172
+ var e_3, _a, e_4, _b;
173
+ var records = [];
174
+ var pushRecord = function (value, fallback) {
175
+ if (fallback === void 0) { fallback = {}; }
176
+ var record = normalizeManagerFailureRecord(value, fallback);
177
+ if (record) {
178
+ records.push(record);
179
+ }
180
+ };
181
+ try {
182
+ for (var _c = __values(asArray(job.supportV5StepHistory || job.support_v5_step_history || evidence.supportV5StepHistory || evidence.support_v5_step_history)), _d = _c.next(); !_d.done; _d = _c.next()) {
183
+ var entry = _d.value;
184
+ pushRecord(entry);
185
+ }
186
+ }
187
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
188
+ finally {
189
+ try {
190
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
191
+ }
192
+ finally { if (e_3) throw e_3.error; }
193
+ }
194
+ try {
195
+ for (var _e = __values(asArray(job.supportV5FailureFingerprints || job.support_v5_failure_fingerprints || evidence.supportV5FailureFingerprints || evidence.support_v5_failure_fingerprints)), _f = _e.next(); !_f.done; _f = _e.next()) {
196
+ var entry = _f.value;
197
+ var fingerprint = plainObject(entry);
198
+ var count = Math.max(1, Math.min(8, Number(fingerprint.count || fingerprint.repeatedCount || fingerprint.repeated_count || 1) || 1));
199
+ var fallback = {
200
+ lane: cleanText(fingerprint.lane || 'support', 80),
201
+ stepType: cleanText(fingerprint.stepType || fingerprint.step_type || 'support_step', 80),
202
+ outcome: cleanText(fingerprint.outcome || 'needs_repair', 80),
203
+ failureClass: cleanText(fingerprint.failureClass || fingerprint.failure_class || fingerprint.class, 120),
204
+ blocker: cleanText(fingerprint.blocker || fingerprint.reason || fingerprint.summary, 1200),
205
+ blockerFingerprint: cleanText(fingerprint.blockerFingerprint || fingerprint.blocker_fingerprint, 180),
206
+ evidenceHash: cleanText(fingerprint.evidenceHash || fingerprint.evidence_hash, 180)
207
+ };
208
+ for (var index = 0; index < count; index += 1) {
209
+ pushRecord(fingerprint, fallback);
210
+ }
211
+ }
212
+ }
213
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
214
+ finally {
215
+ try {
216
+ if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
217
+ }
218
+ finally { if (e_4) throw e_4.error; }
219
+ }
220
+ var currentFailure = evidenceObject(job.supportV5CurrentFailure, job.support_v5_current_failure, job.supportV5RecoveryCurrent, job.support_v5_recovery_current, evidence.currentFailure, evidence.current_failure);
221
+ pushRecord(currentFailure);
222
+ return records.slice(-80);
223
+ }
224
+ function managerNoBlindLoopGateFromHistory(history, budgetSource, now) {
225
+ var _a;
226
+ if (!history.length) {
227
+ return undefined;
228
+ }
229
+ var budget = plainObject(budgetSource);
230
+ var maxSameFailureRepeats = Math.max(1, Number(budget.maxRepeatedNoProgress || budget.max_repeated_no_progress || budget.maxSameFailureRepeats || budget.max_same_failure_repeats || 3) || 3);
231
+ var decision = (0, ai_runner_manager_policy_1.decideResolveIOAIManagerPolicy)({
232
+ history: history,
233
+ maxSameFailureRepeats: maxSameFailureRepeats
234
+ });
235
+ var parksRun = /^(park_repeated_failure|park_ping_pong|manual_handoff)$/.test(decision.action);
236
+ var status = parksRun
237
+ ? 'blocked'
238
+ : decision.action === 'retry_infra'
239
+ ? 'warn'
240
+ : 'pass';
241
+ return {
242
+ key: 'manager_no_blind_loop_policy',
243
+ label: 'No-blind-loop manager policy',
244
+ status: status,
245
+ reason: decision.reason,
246
+ evidenceRefs: cleanStringList(decision.recoveryAction.requiredArtifacts, 20, 500),
247
+ recordedAt: isoNow(now),
248
+ metadata: {
249
+ action: decision.action,
250
+ failureClass: decision.failureClass,
251
+ blockerFingerprint: decision.blockerFingerprint,
252
+ evidenceHash: decision.evidenceHash,
253
+ sameFailureCount: decision.sameFailureCount,
254
+ pingPongCount: decision.pingPongCount,
255
+ newEvidence: decision.newEvidence,
256
+ materialEvidence: decision.materialEvidence,
257
+ evidenceStrength: decision.evidenceStrength,
258
+ evidenceSignals: decision.evidenceSignals,
259
+ loopBudgetShouldReset: decision.loopBudgetShouldReset,
260
+ productRepairFailure: decision.productRepairFailure,
261
+ recoveryClass: decision.recoveryPlan.recoveryClass,
262
+ allowedAction: decision.recoveryPlan.allowedAction,
263
+ dispatchAction: decision.recoveryAction.allowedDispatchAction,
264
+ evidenceOnly: decision.recoveryAction.evidenceOnly,
265
+ productRepairAllowed: decision.recoveryAction.productRepairAllowed,
266
+ expensiveModelAllowed: decision.recoveryAction.expensiveModelAllowed,
267
+ costCeilingUsd: decision.recoveryAction.costCeilingUsd,
268
+ requiresNewEvidence: ((_a = decision.recoveryAction.retryPolicy) === null || _a === void 0 ? void 0 : _a.requireNewEvidence) === true,
269
+ nextCommands: decision.recoveryAction.nextCommands,
270
+ requiredEvidence: decision.recoveryAction.requiredArtifacts,
271
+ forbiddenActions: decision.recoveryPlan.forbiddenActions
272
+ }
273
+ };
274
+ }
275
+ function managerRecoveryExecutionProofGate(proof, now) {
276
+ if (!proof || !Object.keys(proof).length) {
277
+ return undefined;
278
+ }
279
+ var validation = (0, ai_runner_manager_policy_1.validateResolveIOAIManagerRecoveryExecutionProofContract)(proof);
280
+ var normalized = validation.normalized;
281
+ var statusText = cleanText(normalized.status, 120);
282
+ var gateStatus = validation.valid && normalized.canContinueRun === true && statusText === 'proof_ready'
283
+ ? 'pass'
284
+ : statusText === 'manual_handoff'
285
+ ? 'warn'
286
+ : 'blocked';
287
+ return {
288
+ key: 'manager_recovery_execution_proof',
289
+ label: 'Manager recovery execution proof',
290
+ status: gateStatus,
291
+ reason: normalized.blockers[0] || validation.blockers[0] || statusText || 'Manager recovery execution proof recorded.',
292
+ evidenceRefs: normalized.artifactPaths,
293
+ recordedAt: isoNow(now || normalized.createdAt),
294
+ metadata: {
295
+ contractId: normalized.contractId,
296
+ directiveId: normalized.directiveId,
297
+ surface: normalized.surface,
298
+ dispatchAction: normalized.dispatchAction,
299
+ phase: normalized.phase,
300
+ status: statusText,
301
+ canContinueRun: normalized.canContinueRun,
302
+ canRunProductRepair: normalized.canRunProductRepair,
303
+ canRunExpensiveModel: normalized.canRunExpensiveModel,
304
+ canResetLoopBudget: normalized.canResetLoopBudget,
305
+ proofRequiredBeforeContinuation: normalized.proofRequiredBeforeContinuation,
306
+ requiresNewEvidence: normalized.requiresNewEvidence,
307
+ newEvidence: normalized.newEvidence,
308
+ materialEvidence: normalized.materialEvidence,
309
+ evidenceStrength: normalized.evidenceStrength,
310
+ evidenceSignals: normalized.evidenceSignals,
311
+ startingFailureClass: normalized.startingFailureClass,
312
+ startingBlockerFingerprint: normalized.startingBlockerFingerprint,
313
+ startingEvidenceHash: normalized.startingEvidenceHash,
314
+ latestFailureClass: normalized.latestFailureClass,
315
+ latestBlockerFingerprint: normalized.latestBlockerFingerprint,
316
+ latestEvidenceHash: normalized.latestEvidenceHash,
317
+ requiredEvidence: normalized.requiredEvidence,
318
+ missingEvidence: normalized.missingEvidence,
319
+ changedFiles: normalized.changedFiles,
320
+ blockers: Array.from(new Set(__spreadArray(__spreadArray([], __read(normalized.blockers), false), __read(validation.blockers), false))),
321
+ nextAllowedAction: normalized.nextAllowedAction,
322
+ forbiddenActions: normalized.forbiddenActions
323
+ }
324
+ };
325
+ }
326
+ function supportManagerNoBlindLoopGate(job, evidence, now) {
327
+ return managerNoBlindLoopGateFromHistory(supportManagerFailureRecords(job, evidence), job.supportV5Budget || job.support_v5_budget || evidence.supportV5Budget || evidence.support_v5_budget, now);
328
+ }
329
+ function aicoderManagerFailureRecords(app, job, evidence) {
330
+ var e_5, _a, e_6, _b, e_7, _c, e_8, _d;
331
+ var records = [];
332
+ var pushRecord = function (value, fallback) {
333
+ if (fallback === void 0) { fallback = {}; }
334
+ var record = normalizeManagerFailureRecord(value, __assign({ lane: 'aicoder', stepType: 'workflow_step' }, fallback));
335
+ if (record) {
336
+ records.push(record);
337
+ }
338
+ };
339
+ var historySources = [
340
+ job.aicoderV6StepHistory,
341
+ job.aiCoderV6StepHistory,
342
+ job.aicoder_v6_step_history,
343
+ job.ai_coder_v6_step_history,
344
+ job.workflowStepHistory,
345
+ job.workflow_step_history,
346
+ job.stepHistory,
347
+ job.step_history,
348
+ job.managerFailureHistory,
349
+ job.manager_failure_history,
350
+ app.aicoderV6StepHistory,
351
+ app.aiCoderV6StepHistory,
352
+ app.aicoder_v6_step_history,
353
+ app.ai_coder_v6_step_history,
354
+ app.workflowStepHistory,
355
+ app.workflow_step_history,
356
+ evidence.aicoderV6StepHistory,
357
+ evidence.aiCoderV6StepHistory,
358
+ evidence.aicoder_v6_step_history,
359
+ evidence.ai_coder_v6_step_history,
360
+ evidence.workflowStepHistory,
361
+ evidence.workflow_step_history,
362
+ evidence.stepHistory,
363
+ evidence.step_history,
364
+ evidence.managerFailureHistory,
365
+ evidence.manager_failure_history
366
+ ];
367
+ try {
368
+ for (var historySources_1 = __values(historySources), historySources_1_1 = historySources_1.next(); !historySources_1_1.done; historySources_1_1 = historySources_1.next()) {
369
+ var source = historySources_1_1.value;
370
+ try {
371
+ for (var _e = (e_6 = void 0, __values(asArray(source))), _f = _e.next(); !_f.done; _f = _e.next()) {
372
+ var entry = _f.value;
373
+ pushRecord(entry);
374
+ }
375
+ }
376
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
377
+ finally {
378
+ try {
379
+ if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
380
+ }
381
+ finally { if (e_6) throw e_6.error; }
382
+ }
383
+ }
384
+ }
385
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
386
+ finally {
387
+ try {
388
+ if (historySources_1_1 && !historySources_1_1.done && (_a = historySources_1.return)) _a.call(historySources_1);
389
+ }
390
+ finally { if (e_5) throw e_5.error; }
391
+ }
392
+ var fingerprintSources = [
393
+ job.aicoderV6FailureFingerprints,
394
+ job.aiCoderV6FailureFingerprints,
395
+ job.aicoder_v6_failure_fingerprints,
396
+ job.ai_coder_v6_failure_fingerprints,
397
+ job.workflowFailureFingerprints,
398
+ job.workflow_failure_fingerprints,
399
+ job.failureFingerprints,
400
+ job.failure_fingerprints,
401
+ app.aicoderV6FailureFingerprints,
402
+ app.aiCoderV6FailureFingerprints,
403
+ app.aicoder_v6_failure_fingerprints,
404
+ app.ai_coder_v6_failure_fingerprints,
405
+ evidence.aicoderV6FailureFingerprints,
406
+ evidence.aiCoderV6FailureFingerprints,
407
+ evidence.aicoder_v6_failure_fingerprints,
408
+ evidence.ai_coder_v6_failure_fingerprints,
409
+ evidence.workflowFailureFingerprints,
410
+ evidence.workflow_failure_fingerprints,
411
+ evidence.failureFingerprints,
412
+ evidence.failure_fingerprints
413
+ ];
414
+ try {
415
+ for (var fingerprintSources_1 = __values(fingerprintSources), fingerprintSources_1_1 = fingerprintSources_1.next(); !fingerprintSources_1_1.done; fingerprintSources_1_1 = fingerprintSources_1.next()) {
416
+ var source = fingerprintSources_1_1.value;
417
+ try {
418
+ for (var _g = (e_8 = void 0, __values(asArray(source))), _h = _g.next(); !_h.done; _h = _g.next()) {
419
+ var entry = _h.value;
420
+ var fingerprint = plainObject(entry);
421
+ var count = Math.max(1, Math.min(8, Number(fingerprint.count || fingerprint.repeatedCount || fingerprint.repeated_count || 1) || 1));
422
+ var fallback = {
423
+ lane: cleanText(fingerprint.lane || 'aicoder', 80),
424
+ stepType: cleanText(fingerprint.stepType || fingerprint.step_type || 'workflow_step', 80),
425
+ outcome: cleanText(fingerprint.outcome || 'needs_repair', 80),
426
+ failureClass: cleanText(fingerprint.failureClass || fingerprint.failure_class || fingerprint.class, 120),
427
+ blocker: cleanText(fingerprint.blocker || fingerprint.reason || fingerprint.summary, 1200),
428
+ blockerFingerprint: cleanText(fingerprint.blockerFingerprint || fingerprint.blocker_fingerprint, 180),
429
+ evidenceHash: cleanText(fingerprint.evidenceHash || fingerprint.evidence_hash, 180)
430
+ };
431
+ for (var index = 0; index < count; index += 1) {
432
+ pushRecord(fingerprint, fallback);
433
+ }
434
+ }
435
+ }
436
+ catch (e_8_1) { e_8 = { error: e_8_1 }; }
437
+ finally {
438
+ try {
439
+ if (_h && !_h.done && (_d = _g.return)) _d.call(_g);
440
+ }
441
+ finally { if (e_8) throw e_8.error; }
442
+ }
443
+ }
444
+ }
445
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
446
+ finally {
447
+ try {
448
+ if (fingerprintSources_1_1 && !fingerprintSources_1_1.done && (_c = fingerprintSources_1.return)) _c.call(fingerprintSources_1);
449
+ }
450
+ finally { if (e_7) throw e_7.error; }
451
+ }
452
+ var currentFailure = evidenceObject(job.aicoderV6CurrentFailure, job.aiCoderV6CurrentFailure, job.aicoder_v6_current_failure, job.ai_coder_v6_current_failure, job.workflowCurrentFailure, job.workflow_current_failure, job.currentFailure, job.current_failure, evidence.aicoderV6CurrentFailure, evidence.aiCoderV6CurrentFailure, evidence.aicoder_v6_current_failure, evidence.ai_coder_v6_current_failure, evidence.workflowCurrentFailure, evidence.workflow_current_failure, evidence.currentFailure, evidence.current_failure);
453
+ pushRecord(currentFailure);
454
+ return records.slice(-80);
455
+ }
456
+ function aicoderManagerNoBlindLoopGate(app, job, evidence, now) {
457
+ return managerNoBlindLoopGateFromHistory(aicoderManagerFailureRecords(app, job, evidence), job.aicoderV6Budget
458
+ || job.aiCoderV6Budget
459
+ || job.aicoder_v6_budget
460
+ || job.ai_coder_v6_budget
461
+ || evidence.aicoderV6Budget
462
+ || evidence.aiCoderV6Budget
463
+ || evidence.aicoder_v6_budget
464
+ || evidence.ai_coder_v6_budget
465
+ || app.aicoderV6Budget
466
+ || app.aiCoderV6Budget
467
+ || app.aicoder_v6_budget
468
+ || app.ai_coder_v6_budget
469
+ || job.budget
470
+ || evidence.budget, now);
471
+ }
472
+ function managerNoBlindLoopMetadata(gate) {
473
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
474
+ if (!gate) {
475
+ return undefined;
476
+ }
477
+ return {
478
+ action: cleanText((_a = gate.metadata) === null || _a === void 0 ? void 0 : _a.action, 120),
479
+ status: gate.status,
480
+ failureClass: cleanText((_b = gate.metadata) === null || _b === void 0 ? void 0 : _b.failureClass, 120),
481
+ sameFailureCount: Number(((_c = gate.metadata) === null || _c === void 0 ? void 0 : _c.sameFailureCount) || 0),
482
+ pingPongCount: Number(((_d = gate.metadata) === null || _d === void 0 ? void 0 : _d.pingPongCount) || 0),
483
+ newEvidence: ((_e = gate.metadata) === null || _e === void 0 ? void 0 : _e.newEvidence) === true,
484
+ materialEvidence: ((_f = gate.metadata) === null || _f === void 0 ? void 0 : _f.materialEvidence) === true,
485
+ evidenceStrength: cleanText((_g = gate.metadata) === null || _g === void 0 ? void 0 : _g.evidenceStrength, 120),
486
+ loopBudgetShouldReset: ((_h = gate.metadata) === null || _h === void 0 ? void 0 : _h.loopBudgetShouldReset) === true,
487
+ dispatchAction: cleanText((_j = gate.metadata) === null || _j === void 0 ? void 0 : _j.dispatchAction, 160),
488
+ productRepairAllowed: ((_k = gate.metadata) === null || _k === void 0 ? void 0 : _k.productRepairAllowed) === true,
489
+ expensiveModelAllowed: ((_l = gate.metadata) === null || _l === void 0 ? void 0 : _l.expensiveModelAllowed) === true,
490
+ productRepairFailure: ((_m = gate.metadata) === null || _m === void 0 ? void 0 : _m.productRepairFailure) === true,
491
+ requiresNewEvidence: ((_o = gate.metadata) === null || _o === void 0 ? void 0 : _o.requiresNewEvidence) === true
492
+ };
493
+ }
494
+ function hotfixEvidenceCandidates() {
495
+ var e_9, _a;
496
+ var sources = [];
497
+ for (var _i = 0; _i < arguments.length; _i++) {
498
+ sources[_i] = arguments[_i];
499
+ }
500
+ var result = [];
501
+ var seen = new Set();
502
+ var pushCandidate = function (value) {
503
+ var e_10, _a, e_11, _b;
504
+ var _c, _d;
505
+ if (Array.isArray(value)) {
506
+ try {
507
+ for (var value_1 = __values(value), value_1_1 = value_1.next(); !value_1_1.done; value_1_1 = value_1.next()) {
508
+ var entry = value_1_1.value;
509
+ pushCandidate(entry);
510
+ }
511
+ }
512
+ catch (e_10_1) { e_10 = { error: e_10_1 }; }
513
+ finally {
514
+ try {
515
+ if (value_1_1 && !value_1_1.done && (_a = value_1.return)) _a.call(value_1);
516
+ }
517
+ finally { if (e_10) throw e_10.error; }
518
+ }
519
+ return;
520
+ }
521
+ if (!value || typeof value !== 'object') {
522
+ return;
523
+ }
524
+ var nestedValues = [
525
+ value.hotfixEvidence,
526
+ value.hotfix_evidence,
527
+ value.releaseHotfixEvidence,
528
+ value.release_hotfix_evidence,
529
+ value.managerHotfixEvidence,
530
+ value.manager_hotfix_evidence,
531
+ value.backendHotfixEvidence,
532
+ value.backend_hotfix_evidence
533
+ ].filter(Boolean);
534
+ if (nestedValues.length) {
535
+ try {
536
+ for (var nestedValues_1 = __values(nestedValues), nestedValues_1_1 = nestedValues_1.next(); !nestedValues_1_1.done; nestedValues_1_1 = nestedValues_1.next()) {
537
+ var nestedValue = nestedValues_1_1.value;
538
+ pushCandidate(nestedValue);
539
+ }
540
+ }
541
+ catch (e_11_1) { e_11 = { error: e_11_1 }; }
542
+ finally {
543
+ try {
544
+ if (nestedValues_1_1 && !nestedValues_1_1.done && (_b = nestedValues_1.return)) _b.call(nestedValues_1);
545
+ }
546
+ finally { if (e_11) throw e_11.error; }
547
+ }
548
+ return;
549
+ }
550
+ if (!(value.channel || value.hotfixChannel || value.hotfix_channel)) {
551
+ return;
552
+ }
553
+ var key = JSON.stringify({
554
+ channel: value.channel || value.hotfixChannel || value.hotfix_channel,
555
+ host: ((_c = value.target) === null || _c === void 0 ? void 0 : _c.host) || value.host,
556
+ path: ((_d = value.target) === null || _d === void 0 ? void 0 : _d.path) || value.path || value.remotePath || value.remote_path,
557
+ checksum: value.remoteChecksumAfter || value.remote_checksum_after || value.remoteChecksum || value.remote_checksum
558
+ });
559
+ if (seen.has(key)) {
560
+ return;
561
+ }
562
+ seen.add(key);
563
+ result.push(value);
564
+ };
565
+ try {
566
+ for (var sources_1 = __values(sources), sources_1_1 = sources_1.next(); !sources_1_1.done; sources_1_1 = sources_1.next()) {
567
+ var source = sources_1_1.value;
568
+ pushCandidate(source);
569
+ }
570
+ }
571
+ catch (e_9_1) { e_9 = { error: e_9_1 }; }
572
+ finally {
573
+ try {
574
+ if (sources_1_1 && !sources_1_1.done && (_a = sources_1.return)) _a.call(sources_1);
575
+ }
576
+ finally { if (e_9) throw e_9.error; }
577
+ }
578
+ return result;
579
+ }
580
+ function hotfixEvidenceArtifactPaths(evidence, normalized) {
581
+ var _a;
582
+ return [
583
+ normalized === null || normalized === void 0 ? void 0 : normalized.compiledArtifactPath,
584
+ normalized === null || normalized === void 0 ? void 0 : normalized.builtDistPath,
585
+ (_a = normalized === null || normalized === void 0 ? void 0 : normalized.target) === null || _a === void 0 ? void 0 : _a.artifactPath,
586
+ evidence.compiledArtifactPath,
587
+ evidence.compiled_artifact_path,
588
+ evidence.builtDistPath,
589
+ evidence.built_dist_path,
590
+ evidence.artifactPath,
591
+ evidence.artifact_path
592
+ ].map(function (entry) { return cleanText(entry, 500); }).filter(Boolean).slice(0, 8);
593
+ }
594
+ function hotfixEvidenceGate(evidence, now) {
595
+ var _a, _b;
596
+ var validation = (0, ai_runner_manager_policy_1.validateResolveIOAIManagerHotfixEvidence)(evidence);
597
+ if (!validation.normalized && validation.status === 'missing') {
598
+ return undefined;
599
+ }
600
+ var status = validation.valid
601
+ ? (validation.fullDeployAllowed ? 'warn' : 'pass')
602
+ : validation.status === 'blocked'
603
+ ? 'blocked'
604
+ : 'fail';
605
+ var reason = validation.valid
606
+ ? validation.fullDeployAllowed
607
+ ? 'Hotfix evidence allows exactly one full deploy after force/new-artifact proof.'
608
+ : 'Hotfix evidence is sufficient; rerun the smallest release gate before continuing.'
609
+ : validation.blockers.join('; ');
610
+ return {
611
+ key: 'hotfix_evidence',
612
+ label: 'Hotfix evidence',
613
+ status: status,
614
+ reason: reason,
615
+ evidenceRefs: hotfixEvidenceArtifactPaths(evidence, validation.normalized),
616
+ recordedAt: isoNow(now || ((_a = validation.normalized) === null || _a === void 0 ? void 0 : _a.recordedAt)),
617
+ metadata: {
618
+ channel: validation.channel,
619
+ nextAction: validation.nextAction,
620
+ fullDeployAllowed: validation.fullDeployAllowed,
621
+ fullDeployBlocked: validation.fullDeployBlocked,
622
+ hotfixSatisfied: validation.hotfixSatisfied,
623
+ blockers: validation.blockers,
624
+ githubCommitGuard: validation.githubCommitGuard,
625
+ target: (_b = validation.normalized) === null || _b === void 0 ? void 0 : _b.target
626
+ }
627
+ };
628
+ }
629
+ function hotfixCommitProofGate(evidence, now) {
630
+ var _a;
631
+ var validation = (0, ai_runner_manager_policy_1.validateResolveIOAIManagerHotfixEvidence)(evidence);
632
+ var guard = validation.githubCommitGuard;
633
+ if (!guard.required) {
634
+ return undefined;
635
+ }
636
+ var status = guard.passed
637
+ ? 'pass'
638
+ : guard.status === 'invalid'
639
+ ? 'fail'
640
+ : 'blocked';
641
+ return {
642
+ key: 'hotfix_commit_proof',
643
+ label: 'Hotfix GitHub commit proof',
644
+ status: status,
645
+ reason: guard.passed
646
+ ? 'Hotfix has matching sourceCommitSha, GitHub commit URL, passed gitCommitStatus, and passed gitPushStatus.'
647
+ : (guard.blockers.join('; ') || 'Manager hotfix is blocked until sourceCommitSha, githubCommitUrl, passed gitCommitStatus, and passed gitPushStatus prove the hotfix is committed and pushed to GitHub.'),
648
+ evidenceRefs: cleanStringList([guard.githubCommitUrl], 1, 500),
649
+ recordedAt: isoNow(now || ((_a = validation.normalized) === null || _a === void 0 ? void 0 : _a.recordedAt)),
650
+ metadata: {
651
+ channel: guard.channel || validation.channel,
652
+ status: guard.status,
653
+ passed: guard.passed,
654
+ commitFirstProtocol: guard.required ? 'commit_first_hotfix' : 'not_required',
655
+ commitFirstProtocolSatisfied: guard.required ? guard.passed === true : true,
656
+ liveHotfixBlockedUntilCommit: guard.required === true && guard.passed !== true,
657
+ managerMustCommitBeforeHotfix: guard.managerMustCommitBeforeHotfix,
658
+ sourceCommitSha: guard.sourceCommitSha,
659
+ githubCommitUrl: guard.githubCommitUrl,
660
+ githubCommitSha: guard.githubCommitSha,
661
+ gitCommitStatus: guard.gitCommitStatus,
662
+ gitPushStatus: guard.gitPushStatus,
663
+ blockers: guard.blockers,
664
+ nextCommands: guard.nextCommands,
665
+ requiredEvidence: guard.requiredEvidence
666
+ }
667
+ };
668
+ }
669
+ function hotfixDurabilityContractCandidates() {
670
+ var e_12, _a;
671
+ var sources = [];
672
+ for (var _i = 0; _i < arguments.length; _i++) {
673
+ sources[_i] = arguments[_i];
674
+ }
675
+ var result = [];
676
+ var seen = new Set();
677
+ var pushCandidate = function (value) {
678
+ var e_13, _a, e_14, _b;
679
+ var _c, _d;
680
+ if (Array.isArray(value)) {
681
+ try {
682
+ for (var value_2 = __values(value), value_2_1 = value_2.next(); !value_2_1.done; value_2_1 = value_2.next()) {
683
+ var entry = value_2_1.value;
684
+ pushCandidate(entry);
685
+ }
686
+ }
687
+ catch (e_13_1) { e_13 = { error: e_13_1 }; }
688
+ finally {
689
+ try {
690
+ if (value_2_1 && !value_2_1.done && (_a = value_2.return)) _a.call(value_2);
691
+ }
692
+ finally { if (e_13) throw e_13.error; }
693
+ }
694
+ return;
695
+ }
696
+ if (!value || typeof value !== 'object') {
697
+ return;
698
+ }
699
+ var nestedValues = [
700
+ value.hotfixDurabilityContract,
701
+ value.hotfix_durability_contract,
702
+ value.supportManagerHotfixDurabilityContract,
703
+ value.support_manager_hotfix_durability_contract,
704
+ value.managerRecoveryHotfixDurability,
705
+ value.manager_recovery_hotfix_durability,
706
+ (_c = value.supportV5RecoveryDirective) === null || _c === void 0 ? void 0 : _c.hotfixDurabilityContract,
707
+ (_d = value.supportV5RecoveryDirective) === null || _d === void 0 ? void 0 : _d.hotfix_durability_contract
708
+ ].filter(Boolean);
709
+ if (nestedValues.length) {
710
+ try {
711
+ for (var nestedValues_2 = __values(nestedValues), nestedValues_2_1 = nestedValues_2.next(); !nestedValues_2_1.done; nestedValues_2_1 = nestedValues_2.next()) {
712
+ var nestedValue = nestedValues_2_1.value;
713
+ pushCandidate(nestedValue);
714
+ }
715
+ }
716
+ catch (e_14_1) { e_14 = { error: e_14_1 }; }
717
+ finally {
718
+ try {
719
+ if (nestedValues_2_1 && !nestedValues_2_1.done && (_b = nestedValues_2.return)) _b.call(nestedValues_2);
720
+ }
721
+ finally { if (e_14) throw e_14.error; }
722
+ }
723
+ }
724
+ var required = value.required === true || value.liveHotfixBlockedUntilCommit === true || value.live_hotfix_blocked_until_commit === true || value.commitProofPassed === true || value.commit_proof_passed === true;
725
+ if (!required) {
726
+ return;
727
+ }
728
+ var key = cleanText(value.contractId || value.contract_id || JSON.stringify({
729
+ status: value.status,
730
+ sha: value.sourceCommitSha || value.source_commit_sha,
731
+ url: value.githubCommitUrl || value.github_commit_url
732
+ }), 500);
733
+ if (seen.has(key)) {
734
+ return;
735
+ }
736
+ seen.add(key);
737
+ result.push(value);
738
+ };
739
+ try {
740
+ for (var sources_2 = __values(sources), sources_2_1 = sources_2.next(); !sources_2_1.done; sources_2_1 = sources_2.next()) {
741
+ var source = sources_2_1.value;
742
+ pushCandidate(source);
743
+ }
744
+ }
745
+ catch (e_12_1) { e_12 = { error: e_12_1 }; }
746
+ finally {
747
+ try {
748
+ if (sources_2_1 && !sources_2_1.done && (_a = sources_2.return)) _a.call(sources_2);
749
+ }
750
+ finally { if (e_12) throw e_12.error; }
751
+ }
752
+ return result;
753
+ }
754
+ function hotfixDurabilityContractGate(contractValue, now) {
755
+ var contract = (0, ai_runner_manager_policy_1.buildResolveIOAIManagerHotfixDurabilityContract)({
756
+ existing: contractValue,
757
+ evidence: contractValue.evidence || contractValue.hotfixEvidence || contractValue.hotfix_evidence,
758
+ action: contractValue.action,
759
+ reason: contractValue.reason,
760
+ now: now
761
+ });
762
+ if (!contract.required) {
763
+ return undefined;
764
+ }
765
+ var status = contract.liveHotfixBlockedUntilCommit
766
+ ? 'blocked'
767
+ : contract.status === 'ready_for_continuation' || contract.status === 'ready_for_release_gate'
768
+ ? 'pass'
769
+ : 'warn';
770
+ return {
771
+ key: 'hotfix_durability_contract',
772
+ label: 'Hotfix durability contract',
773
+ status: status,
774
+ reason: contract.liveHotfixBlockedUntilCommit
775
+ ? "Manager hotfix is blocked until GitHub commit proof is recorded: ".concat(contract.missingCommitProofFields.join(', ') || 'sourceCommitSha, githubCommitUrl, gitCommitStatus=passed, gitPushStatus=passed')
776
+ : "Manager hotfix durability contract is ".concat(contract.status, "."),
777
+ evidenceRefs: cleanStringList([contract.githubCommitUrl], 1, 500),
778
+ recordedAt: isoNow(now || contract.updatedAt),
779
+ metadata: {
780
+ contractId: contract.contractId,
781
+ status: contract.status,
782
+ nextSafeAction: contract.nextSafeAction,
783
+ canPrepareHotfixPatch: contract.canPrepareHotfixPatch,
784
+ canHotfixBackend: contract.canHotfixBackend,
785
+ liveHotfixBlockedUntilCommit: contract.liveHotfixBlockedUntilCommit,
786
+ durabilityProtocol: contract.durabilityProtocol,
787
+ commitFirstProtocolRequired: contract.commitFirstProtocolRequired,
788
+ commitFirstProtocolSatisfied: contract.commitFirstProtocolSatisfied,
789
+ liveHotfixAllowed: contract.liveHotfixAllowed,
790
+ managerContinuationAllowed: contract.managerContinuationAllowed,
791
+ commitProofPassed: contract.commitProofPassed,
792
+ commitProofStatus: contract.commitProofStatus,
793
+ missingCommitProofFields: contract.missingCommitProofFields,
794
+ sourceCommitSha: contract.sourceCommitSha,
795
+ githubCommitUrl: contract.githubCommitUrl,
796
+ gitCommitStatus: contract.gitCommitStatus,
797
+ gitPushStatus: contract.gitPushStatus,
798
+ phaseOrder: contract.phaseOrder,
799
+ requiredFields: contract.requiredFields,
800
+ forbiddenActions: contract.forbiddenActions
801
+ }
802
+ };
803
+ }
804
+ function collectHotfixEvidenceEvents(sources, events, gates, now) {
805
+ var e_15, _a, e_16, _b;
806
+ var _c, _d;
807
+ try {
808
+ for (var _e = __values(hotfixDurabilityContractCandidates.apply(void 0, __spreadArray([], __read(sources), false))), _f = _e.next(); !_f.done; _f = _e.next()) {
809
+ var contract = _f.value;
810
+ var gate = hotfixDurabilityContractGate(contract, now);
811
+ if (gate) {
812
+ gates.push(gate);
813
+ pushEvent(events, {
814
+ type: 'log',
815
+ category: 'hotfix_durability_contract',
816
+ message: gate.reason,
817
+ artifactPaths: gate.evidenceRefs,
818
+ recordedAt: gate.recordedAt,
819
+ metadata: gate.metadata
820
+ });
821
+ }
822
+ }
823
+ }
824
+ catch (e_15_1) { e_15 = { error: e_15_1 }; }
825
+ finally {
826
+ try {
827
+ if (_f && !_f.done && (_a = _e.return)) _a.call(_e);
828
+ }
829
+ finally { if (e_15) throw e_15.error; }
830
+ }
831
+ try {
832
+ for (var _g = __values(hotfixEvidenceCandidates.apply(void 0, __spreadArray([], __read(sources), false))), _h = _g.next(); !_h.done; _h = _g.next()) {
833
+ var evidence = _h.value;
834
+ var validation = (0, ai_runner_manager_policy_1.validateResolveIOAIManagerHotfixEvidence)(evidence);
835
+ if (!validation.normalized && validation.status === 'missing') {
836
+ continue;
837
+ }
838
+ var artifactPaths = hotfixEvidenceArtifactPaths(evidence, validation.normalized);
839
+ pushEvent(events, {
840
+ type: 'hotfix',
841
+ category: validation.channel || 'hotfix',
842
+ message: validation.valid
843
+ ? "Hotfix evidence recorded for ".concat(validation.channel, ".")
844
+ : "Incomplete hotfix evidence for ".concat(validation.channel || 'unknown channel', "."),
845
+ artifactPaths: artifactPaths,
846
+ recordedAt: ((_c = validation.normalized) === null || _c === void 0 ? void 0 : _c.recordedAt) || eventDate(evidence),
847
+ metadata: {
848
+ status: validation.status,
849
+ nextAction: validation.nextAction,
850
+ fullDeployAllowed: validation.fullDeployAllowed,
851
+ fullDeployBlocked: validation.fullDeployBlocked,
852
+ hotfixSatisfied: validation.hotfixSatisfied,
853
+ blockers: validation.blockers,
854
+ githubCommitGuard: validation.githubCommitGuard,
855
+ target: (_d = validation.normalized) === null || _d === void 0 ? void 0 : _d.target
856
+ }
857
+ });
858
+ var gate = hotfixEvidenceGate(evidence, now);
859
+ if (gate) {
860
+ gates.push(gate);
861
+ }
862
+ var commitProofGate = hotfixCommitProofGate(evidence, now);
863
+ if (commitProofGate) {
864
+ gates.push(commitProofGate);
865
+ pushEvent(events, {
866
+ type: 'log',
867
+ category: 'hotfix_commit_proof',
868
+ message: commitProofGate.reason,
869
+ artifactPaths: commitProofGate.evidenceRefs,
870
+ recordedAt: commitProofGate.recordedAt,
871
+ metadata: commitProofGate.metadata
872
+ });
873
+ }
874
+ }
875
+ }
876
+ catch (e_16_1) { e_16 = { error: e_16_1 }; }
877
+ finally {
878
+ try {
879
+ if (_h && !_h.done && (_b = _g.return)) _b.call(_g);
880
+ }
881
+ finally { if (e_16) throw e_16.error; }
882
+ }
883
+ }
884
+ function hotfixDurabilityMetadata(gates) {
885
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12;
886
+ var hotfixGate = gates.find(function (gate) { return gate.key === 'hotfix_evidence'; });
887
+ var commitGate = gates.find(function (gate) { return gate.key === 'hotfix_commit_proof'; });
888
+ var durabilityGate = gates.find(function (gate) { return gate.key === 'hotfix_durability_contract'; });
889
+ if (!hotfixGate && !commitGate && !durabilityGate) {
890
+ return undefined;
891
+ }
892
+ var commitBlocked = (!!commitGate && (commitGate.status === 'blocked' || commitGate.status === 'fail'))
893
+ || ((_a = durabilityGate === null || durabilityGate === void 0 ? void 0 : durabilityGate.metadata) === null || _a === void 0 ? void 0 : _a.liveHotfixBlockedUntilCommit) === true;
894
+ return {
895
+ durabilityStatus: cleanText((_b = durabilityGate === null || durabilityGate === void 0 ? void 0 : durabilityGate.metadata) === null || _b === void 0 ? void 0 : _b.status, 80),
896
+ durabilityGateStatus: cleanText(durabilityGate === null || durabilityGate === void 0 ? void 0 : durabilityGate.status, 80),
897
+ canPrepareHotfixPatch: ((_c = durabilityGate === null || durabilityGate === void 0 ? void 0 : durabilityGate.metadata) === null || _c === void 0 ? void 0 : _c.canPrepareHotfixPatch) === true,
898
+ canHotfixBackend: ((_d = durabilityGate === null || durabilityGate === void 0 ? void 0 : durabilityGate.metadata) === null || _d === void 0 ? void 0 : _d.canHotfixBackend) === true,
899
+ liveHotfixBlockedUntilCommit: ((_e = durabilityGate === null || durabilityGate === void 0 ? void 0 : durabilityGate.metadata) === null || _e === void 0 ? void 0 : _e.liveHotfixBlockedUntilCommit) === true,
900
+ durabilityProtocol: cleanText((_f = durabilityGate === null || durabilityGate === void 0 ? void 0 : durabilityGate.metadata) === null || _f === void 0 ? void 0 : _f.durabilityProtocol, 120),
901
+ commitFirstProtocolRequired: ((_g = durabilityGate === null || durabilityGate === void 0 ? void 0 : durabilityGate.metadata) === null || _g === void 0 ? void 0 : _g.commitFirstProtocolRequired) === true,
902
+ commitFirstProtocolSatisfied: ((_h = durabilityGate === null || durabilityGate === void 0 ? void 0 : durabilityGate.metadata) === null || _h === void 0 ? void 0 : _h.commitFirstProtocolSatisfied) === true || ((_j = commitGate === null || commitGate === void 0 ? void 0 : commitGate.metadata) === null || _j === void 0 ? void 0 : _j.commitFirstProtocolSatisfied) === true,
903
+ liveHotfixAllowed: ((_k = durabilityGate === null || durabilityGate === void 0 ? void 0 : durabilityGate.metadata) === null || _k === void 0 ? void 0 : _k.liveHotfixAllowed) === true || (((_l = hotfixGate === null || hotfixGate === void 0 ? void 0 : hotfixGate.metadata) === null || _l === void 0 ? void 0 : _l.hotfixSatisfied) === true && ((_m = commitGate === null || commitGate === void 0 ? void 0 : commitGate.metadata) === null || _m === void 0 ? void 0 : _m.commitFirstProtocolSatisfied) === true),
904
+ managerContinuationAllowed: ((_o = durabilityGate === null || durabilityGate === void 0 ? void 0 : durabilityGate.metadata) === null || _o === void 0 ? void 0 : _o.managerContinuationAllowed) === true,
905
+ hotfixEvidenceStatus: cleanText(hotfixGate === null || hotfixGate === void 0 ? void 0 : hotfixGate.status, 80),
906
+ hotfixSatisfied: ((_p = hotfixGate === null || hotfixGate === void 0 ? void 0 : hotfixGate.metadata) === null || _p === void 0 ? void 0 : _p.hotfixSatisfied) === true,
907
+ fullDeployBlocked: ((_q = hotfixGate === null || hotfixGate === void 0 ? void 0 : hotfixGate.metadata) === null || _q === void 0 ? void 0 : _q.fullDeployBlocked) === true,
908
+ fullDeployAllowed: ((_r = hotfixGate === null || hotfixGate === void 0 ? void 0 : hotfixGate.metadata) === null || _r === void 0 ? void 0 : _r.fullDeployAllowed) === true,
909
+ commitProofRequired: !!commitGate || !!durabilityGate,
910
+ commitProofStatus: cleanText((commitGate === null || commitGate === void 0 ? void 0 : commitGate.status) || ((_s = durabilityGate === null || durabilityGate === void 0 ? void 0 : durabilityGate.metadata) === null || _s === void 0 ? void 0 : _s.commitProofStatus), 80),
911
+ commitProofPassed: ((_t = commitGate === null || commitGate === void 0 ? void 0 : commitGate.metadata) === null || _t === void 0 ? void 0 : _t.passed) === true || ((_u = durabilityGate === null || durabilityGate === void 0 ? void 0 : durabilityGate.metadata) === null || _u === void 0 ? void 0 : _u.commitProofPassed) === true,
912
+ commitBlocked: commitBlocked,
913
+ channel: cleanText(((_v = commitGate === null || commitGate === void 0 ? void 0 : commitGate.metadata) === null || _v === void 0 ? void 0 : _v.channel) || ((_w = hotfixGate === null || hotfixGate === void 0 ? void 0 : hotfixGate.metadata) === null || _w === void 0 ? void 0 : _w.channel), 120),
914
+ sourceCommitSha: cleanText(((_x = commitGate === null || commitGate === void 0 ? void 0 : commitGate.metadata) === null || _x === void 0 ? void 0 : _x.sourceCommitSha) || ((_y = durabilityGate === null || durabilityGate === void 0 ? void 0 : durabilityGate.metadata) === null || _y === void 0 ? void 0 : _y.sourceCommitSha), 200),
915
+ githubCommitUrl: cleanText(((_z = commitGate === null || commitGate === void 0 ? void 0 : commitGate.metadata) === null || _z === void 0 ? void 0 : _z.githubCommitUrl) || ((_0 = durabilityGate === null || durabilityGate === void 0 ? void 0 : durabilityGate.metadata) === null || _0 === void 0 ? void 0 : _0.githubCommitUrl), 500),
916
+ gitCommitStatus: cleanText(((_1 = commitGate === null || commitGate === void 0 ? void 0 : commitGate.metadata) === null || _1 === void 0 ? void 0 : _1.gitCommitStatus) || ((_2 = durabilityGate === null || durabilityGate === void 0 ? void 0 : durabilityGate.metadata) === null || _2 === void 0 ? void 0 : _2.gitCommitStatus), 120),
917
+ gitPushStatus: cleanText(((_3 = commitGate === null || commitGate === void 0 ? void 0 : commitGate.metadata) === null || _3 === void 0 ? void 0 : _3.gitPushStatus) || ((_4 = durabilityGate === null || durabilityGate === void 0 ? void 0 : durabilityGate.metadata) === null || _4 === void 0 ? void 0 : _4.gitPushStatus), 120),
918
+ blockers: cleanStringList(__spreadArray(__spreadArray(__spreadArray([], __read(asArray((_5 = durabilityGate === null || durabilityGate === void 0 ? void 0 : durabilityGate.metadata) === null || _5 === void 0 ? void 0 : _5.missingCommitProofFields)), false), __read(asArray((_6 = commitGate === null || commitGate === void 0 ? void 0 : commitGate.metadata) === null || _6 === void 0 ? void 0 : _6.blockers)), false), __read(asArray((_7 = hotfixGate === null || hotfixGate === void 0 ? void 0 : hotfixGate.metadata) === null || _7 === void 0 ? void 0 : _7.blockers)), false), 20, 500),
919
+ requiredEvidence: cleanStringList(((_8 = commitGate === null || commitGate === void 0 ? void 0 : commitGate.metadata) === null || _8 === void 0 ? void 0 : _8.requiredEvidence) || ((_9 = durabilityGate === null || durabilityGate === void 0 ? void 0 : durabilityGate.metadata) === null || _9 === void 0 ? void 0 : _9.requiredFields), 20, 500),
920
+ nextCommands: cleanStringList((_10 = commitGate === null || commitGate === void 0 ? void 0 : commitGate.metadata) === null || _10 === void 0 ? void 0 : _10.nextCommands, 20, 240),
921
+ nextAction: commitBlocked
922
+ ? cleanText((_11 = durabilityGate === null || durabilityGate === void 0 ? void 0 : durabilityGate.metadata) === null || _11 === void 0 ? void 0 : _11.nextSafeAction, 200) || 'Commit and push the hotfix to GitHub, record sourceCommitSha/githubCommitUrl/gitCommitStatus/gitPushStatus, then rerun the smallest verification gate.'
923
+ : cleanText((_12 = hotfixGate === null || hotfixGate === void 0 ? void 0 : hotfixGate.metadata) === null || _12 === void 0 ? void 0 : _12.nextAction, 1000)
924
+ };
925
+ }
926
+ function collectUsageEvents(entries, events) {
927
+ var e_17, _a;
928
+ var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
929
+ if (!entries.length) {
930
+ return undefined;
931
+ }
932
+ var normalizedEntries = (0, ai_run_evidence_1.normalizeOpenAIUsageRowsForCosting)(entries);
933
+ try {
934
+ for (var normalizedEntries_1 = __values(normalizedEntries), normalizedEntries_1_1 = normalizedEntries_1.next(); !normalizedEntries_1_1.done; normalizedEntries_1_1 = normalizedEntries_1.next()) {
935
+ var entry = normalizedEntries_1_1.value;
936
+ pushEvent(events, {
937
+ type: 'usage',
938
+ category: cleanText(entry.category || entry.kind || entry.phase, 160) || 'usage',
939
+ message: cleanText(entry.summary || entry.description || entry.model || 'Model usage recorded.', 800),
940
+ recordedAt: eventDate(entry),
941
+ metadata: {
942
+ model: entry.model,
943
+ inputTokens: (_b = entry.inputTokens) !== null && _b !== void 0 ? _b : entry.input_tokens,
944
+ outputTokens: (_c = entry.outputTokens) !== null && _c !== void 0 ? _c : entry.output_tokens,
945
+ totalTokens: (_d = entry.totalTokens) !== null && _d !== void 0 ? _d : entry.total_tokens,
946
+ estimatedUsd: (_e = entry.estimatedUsd) !== null && _e !== void 0 ? _e : entry.cost_estimate,
947
+ usageSource: (_f = entry.usage_source) !== null && _f !== void 0 ? _f : entry.usageSource,
948
+ usageSurface: (_g = entry.usage_surface) !== null && _g !== void 0 ? _g : entry.usageSurface,
949
+ usagePhase: (_h = entry.usage_phase) !== null && _h !== void 0 ? _h : entry.usagePhase,
950
+ costBasis: (_j = entry.cost_basis) !== null && _j !== void 0 ? _j : entry.costBasis,
951
+ isManual: (_k = entry.is_manual) !== null && _k !== void 0 ? _k : entry.isManual,
952
+ isUntracked: (_l = entry.is_untracked) !== null && _l !== void 0 ? _l : entry.isUntracked,
953
+ untrackedReason: (_m = entry.untracked_reason) !== null && _m !== void 0 ? _m : entry.untrackedReason
954
+ }
955
+ });
956
+ }
957
+ }
958
+ catch (e_17_1) { e_17 = { error: e_17_1 }; }
959
+ finally {
960
+ try {
961
+ if (normalizedEntries_1_1 && !normalizedEntries_1_1.done && (_a = normalizedEntries_1.return)) _a.call(normalizedEntries_1);
962
+ }
963
+ finally { if (e_17) throw e_17.error; }
964
+ }
965
+ return (0, ai_run_evidence_1.buildAIRunCost)(entries);
966
+ }
967
+ function costObservabilityGate(cost, source, now) {
968
+ var manualEstimatedUsd = Number((cost === null || cost === void 0 ? void 0 : cost.manualEstimatedUsd) || 0);
969
+ var untrackedEstimatedUsd = Number((cost === null || cost === void 0 ? void 0 : cost.untrackedEstimatedUsd) || 0);
970
+ var warnings = cleanStringList(cost === null || cost === void 0 ? void 0 : cost.untrackedWarnings, 20, 500);
971
+ var manualSources = Object.entries((cost === null || cost === void 0 ? void 0 : cost.sources) || {})
972
+ .filter(function (_a) {
973
+ var _b = __read(_a, 2), value = _b[1];
974
+ return Number(value.manualCount || 0) > 0;
975
+ })
976
+ .map(function (_a) {
977
+ var _b = __read(_a, 1), key = _b[0];
978
+ return key;
979
+ });
980
+ var untrackedSources = Object.entries((cost === null || cost === void 0 ? void 0 : cost.sources) || {})
981
+ .filter(function (_a) {
982
+ var _b = __read(_a, 2), value = _b[1];
983
+ return Number(value.untrackedCount || 0) > 0;
984
+ })
985
+ .map(function (_a) {
986
+ var _b = __read(_a, 1), key = _b[0];
987
+ return key;
988
+ });
989
+ var missingLedger = !cost;
990
+ var externalCodexMonitorUsed = manualEstimatedUsd > 0
991
+ || untrackedEstimatedUsd > 0
992
+ || manualSources.some(function (sourceKey) { return /codex|manual/i.test(sourceKey); })
993
+ || warnings.some(function (warning) { return /codex|sidecar|monitor/i.test(warning); });
994
+ var status = missingLedger
995
+ ? 'skipped'
996
+ : (manualEstimatedUsd > 0 || untrackedEstimatedUsd > 0 || warnings.length ? 'warn' : 'pass');
997
+ return {
998
+ key: 'cost_observability',
999
+ label: 'Cost observability',
1000
+ status: status,
1001
+ reason: missingLedger
1002
+ ? 'No usage ledger was supplied for this run, so cost per accepted run cannot be fully evaluated.'
1003
+ : status === 'warn'
1004
+ ? "Runner cost includes manual or untracked usage: manual=$".concat(manualEstimatedUsd.toFixed(2), ", untracked=$").concat(untrackedEstimatedUsd.toFixed(2), ".")
1005
+ : 'Runner usage is tracked in the unified cost ledger.',
1006
+ evidenceRefs: warnings,
1007
+ recordedAt: isoNow(now),
1008
+ metadata: {
1009
+ source: source,
1010
+ missingLedger: missingLedger,
1011
+ estimatedUsd: Number((cost === null || cost === void 0 ? void 0 : cost.estimatedUsd) || 0),
1012
+ manualEstimatedUsd: manualEstimatedUsd,
1013
+ untrackedEstimatedUsd: untrackedEstimatedUsd,
1014
+ externalCodexMonitorUsed: externalCodexMonitorUsed,
1015
+ manualSources: manualSources,
1016
+ untrackedSources: untrackedSources,
1017
+ models: cleanStringList(cost === null || cost === void 0 ? void 0 : cost.models, 40, 120),
1018
+ categories: Object.keys((cost === null || cost === void 0 ? void 0 : cost.categories) || {}).slice(0, 40),
1019
+ surfaces: Object.keys((cost === null || cost === void 0 ? void 0 : cost.surfaces) || {}).slice(0, 40),
1020
+ warnings: warnings
1021
+ }
1022
+ };
1023
+ }
1024
+ function costObservabilityMetadata(gate) {
1025
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
1026
+ if (!gate) {
1027
+ return undefined;
1028
+ }
1029
+ return {
1030
+ status: gate.status,
1031
+ missingLedger: ((_a = gate.metadata) === null || _a === void 0 ? void 0 : _a.missingLedger) === true,
1032
+ estimatedUsd: Number(((_b = gate.metadata) === null || _b === void 0 ? void 0 : _b.estimatedUsd) || 0),
1033
+ manualEstimatedUsd: Number(((_c = gate.metadata) === null || _c === void 0 ? void 0 : _c.manualEstimatedUsd) || 0),
1034
+ untrackedEstimatedUsd: Number(((_d = gate.metadata) === null || _d === void 0 ? void 0 : _d.untrackedEstimatedUsd) || 0),
1035
+ externalCodexMonitorUsed: ((_e = gate.metadata) === null || _e === void 0 ? void 0 : _e.externalCodexMonitorUsed) === true,
1036
+ manualSources: cleanStringList((_f = gate.metadata) === null || _f === void 0 ? void 0 : _f.manualSources, 20, 120),
1037
+ untrackedSources: cleanStringList((_g = gate.metadata) === null || _g === void 0 ? void 0 : _g.untrackedSources, 20, 120),
1038
+ models: cleanStringList((_h = gate.metadata) === null || _h === void 0 ? void 0 : _h.models, 40, 120),
1039
+ categories: cleanStringList((_j = gate.metadata) === null || _j === void 0 ? void 0 : _j.categories, 40, 120),
1040
+ surfaces: cleanStringList((_k = gate.metadata) === null || _k === void 0 ? void 0 : _k.surfaces, 40, 120),
1041
+ warnings: cleanStringList((_l = gate.metadata) === null || _l === void 0 ? void 0 : _l.warnings, 20, 500),
1042
+ nextAction: gate.status === 'warn'
1043
+ ? 'Record manual Codex sidecar usage in the unified ledger and replace external monitoring with a validated next-action contract.'
1044
+ : gate.status === 'skipped'
1045
+ ? 'Attach runner, assistant, manual Codex, retry, and deploy usage rows before comparing cost per accepted run.'
1046
+ : 'Continue tracking cost in the unified ledger.'
1047
+ };
1048
+ }
1049
+ function collectCommitEvents(commits, events) {
1050
+ var e_18, _a;
1051
+ try {
1052
+ for (var _b = __values(commits.slice(0, 80)), _c = _b.next(); !_c.done; _c = _b.next()) {
1053
+ var commit = _c.value;
1054
+ pushEvent(events, {
1055
+ type: 'git_commit',
1056
+ message: cleanText(commit.message || commit.subject || commit.title || commit.hash || commit.sha, 1200),
1057
+ recordedAt: eventDate(commit),
1058
+ metadata: {
1059
+ sha: commit.sha || commit.hash,
1060
+ branch: commit.branch,
1061
+ author: commit.author
1062
+ }
1063
+ });
1064
+ }
1065
+ }
1066
+ catch (e_18_1) { e_18 = { error: e_18_1 }; }
1067
+ finally {
1068
+ try {
1069
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1070
+ }
1071
+ finally { if (e_18) throw e_18.error; }
1072
+ }
1073
+ }
1074
+ function statusFromBoolean(value, fallback) {
1075
+ if (value === true) {
1076
+ return 'pass';
1077
+ }
1078
+ if (value === false) {
1079
+ return 'fail';
1080
+ }
1081
+ return fallback;
1082
+ }
1083
+ function collectArtifacts(evidence) {
1084
+ var e_19, _a, e_20, _b, e_21, _c;
1085
+ var artifacts = [];
1086
+ try {
1087
+ for (var _d = __values(asArray(evidence === null || evidence === void 0 ? void 0 : evidence.artifacts)), _e = _d.next(); !_e.done; _e = _d.next()) {
1088
+ var entry = _e.value;
1089
+ artifacts.push({
1090
+ type: entry.type || 'other',
1091
+ path: cleanText(entry.path || entry.file || entry.artifactPath, 500),
1092
+ url: cleanText(entry.url, 500),
1093
+ title: cleanText(entry.title || entry.name, 300),
1094
+ caption: cleanText(entry.caption || entry.message, 800),
1095
+ metadata: entry.metadata
1096
+ });
1097
+ }
1098
+ }
1099
+ catch (e_19_1) { e_19 = { error: e_19_1 }; }
1100
+ finally {
1101
+ try {
1102
+ if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
1103
+ }
1104
+ finally { if (e_19) throw e_19.error; }
1105
+ }
1106
+ var screenshots = asArray((evidence === null || evidence === void 0 ? void 0 : evidence.screenshots) || (evidence === null || evidence === void 0 ? void 0 : evidence.qaScreenshots) || (evidence === null || evidence === void 0 ? void 0 : evidence.browserScreenshots));
1107
+ try {
1108
+ for (var _f = __values(screenshots.slice(0, 40)), _g = _f.next(); !_g.done; _g = _f.next()) {
1109
+ var screenshot = _g.value;
1110
+ if (typeof screenshot === 'string') {
1111
+ artifacts.push({ type: 'screenshot', path: screenshot });
1112
+ }
1113
+ else {
1114
+ artifacts.push({
1115
+ type: 'screenshot',
1116
+ path: cleanText(screenshot.path || screenshot.file, 500),
1117
+ url: cleanText(screenshot.url, 500),
1118
+ title: cleanText(screenshot.title || screenshot.route, 300),
1119
+ caption: cleanText(screenshot.caption || screenshot.message, 800),
1120
+ metadata: screenshot.metadata
1121
+ });
1122
+ }
1123
+ }
1124
+ }
1125
+ catch (e_20_1) { e_20 = { error: e_20_1 }; }
1126
+ finally {
1127
+ try {
1128
+ if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
1129
+ }
1130
+ finally { if (e_20) throw e_20.error; }
1131
+ }
1132
+ var artifactRefs = __spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(asArray(evidence === null || evidence === void 0 ? void 0 : evidence.artifactPaths)), false), __read(asArray(evidence === null || evidence === void 0 ? void 0 : evidence.artifact_paths)), false), __read(asArray(evidence === null || evidence === void 0 ? void 0 : evidence.runnerEvidenceArtifacts)), false), __read(asArray(evidence === null || evidence === void 0 ? void 0 : evidence.runner_evidence_artifacts)), false), __read(asArray(evidence === null || evidence === void 0 ? void 0 : evidence.supportQaArtifacts)), false), __read(asArray(evidence === null || evidence === void 0 ? void 0 : evidence.support_qa_artifacts)), false), __read(asArray(evidence === null || evidence === void 0 ? void 0 : evidence.qa_artifacts)), false);
1133
+ try {
1134
+ for (var _h = __values(artifactRefs.slice(0, 60)), _j = _h.next(); !_j.done; _j = _h.next()) {
1135
+ var entry = _j.value;
1136
+ if (typeof entry === 'string') {
1137
+ artifacts.push({ type: 'other', path: cleanText(entry, 500) });
1138
+ }
1139
+ else if (entry && typeof entry === 'object') {
1140
+ artifacts.push({
1141
+ type: entry.type || 'other',
1142
+ path: cleanText(entry.path || entry.file || entry.artifactPath || entry.artifact_path, 500),
1143
+ url: cleanText(entry.url, 500),
1144
+ title: cleanText(entry.title || entry.name || entry.label, 300),
1145
+ caption: cleanText(entry.caption || entry.message || entry.summary, 800),
1146
+ metadata: entry.metadata
1147
+ });
1148
+ }
1149
+ }
1150
+ }
1151
+ catch (e_21_1) { e_21 = { error: e_21_1 }; }
1152
+ finally {
1153
+ try {
1154
+ if (_j && !_j.done && (_c = _h.return)) _c.call(_h);
1155
+ }
1156
+ finally { if (e_21) throw e_21.error; }
1157
+ }
1158
+ return artifacts;
1159
+ }
1160
+ function collectInfraChecks(evidence) {
1161
+ var e_22, _a;
1162
+ var _b;
1163
+ var checks = [];
1164
+ try {
1165
+ for (var _c = __values(asArray((evidence === null || evidence === void 0 ? void 0 : evidence.infraChecks) || (evidence === null || evidence === void 0 ? void 0 : evidence.preflightChecks))), _d = _c.next(); !_d.done; _d = _c.next()) {
1166
+ var entry = _d.value;
1167
+ checks.push({
1168
+ name: cleanText(entry.name || entry.check || entry.key, 160) || 'infra_check',
1169
+ status: entry.status || statusFromBoolean(entry.passed),
1170
+ message: cleanText(entry.message || entry.error || entry.reason, 1000),
1171
+ path: cleanText(entry.path, 500),
1172
+ durationMs: Number((_b = entry.durationMs) !== null && _b !== void 0 ? _b : entry.duration_ms) || undefined,
1173
+ metadata: entry.metadata,
1174
+ checkedAt: eventDate(entry)
1175
+ });
1176
+ }
1177
+ }
1178
+ catch (e_22_1) { e_22 = { error: e_22_1 }; }
1179
+ finally {
1180
+ try {
1181
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
1182
+ }
1183
+ finally { if (e_22) throw e_22.error; }
1184
+ }
1185
+ if (evidence === null || evidence === void 0 ? void 0 : evidence.preflightStatus) {
1186
+ checks.push({
1187
+ name: 'qa_preflight',
1188
+ status: evidence.preflightStatus,
1189
+ message: cleanText(evidence.preflightMessage || evidence.preflightReason, 1000),
1190
+ path: cleanText(evidence.preflightArtifactPath || evidence.preflightPath, 500)
1191
+ });
1192
+ }
1193
+ return checks;
1194
+ }
1195
+ function collectCompileResult(evidence) {
1196
+ var _a, _b, _c;
1197
+ var build = (evidence === null || evidence === void 0 ? void 0 : evidence.compile) || (evidence === null || evidence === void 0 ? void 0 : evidence.build) || (evidence === null || evidence === void 0 ? void 0 : evidence.buildEvidence) || (evidence === null || evidence === void 0 ? void 0 : evidence.buildResult);
1198
+ if (!build && (evidence === null || evidence === void 0 ? void 0 : evidence.compileStatus) === undefined && (evidence === null || evidence === void 0 ? void 0 : evidence.buildStatus) === undefined) {
1199
+ return undefined;
1200
+ }
1201
+ var status = (build === null || build === void 0 ? void 0 : build.status)
1202
+ || (evidence === null || evidence === void 0 ? void 0 : evidence.compileStatus)
1203
+ || (evidence === null || evidence === void 0 ? void 0 : evidence.buildStatus)
1204
+ || statusFromBoolean((_b = (_a = build === null || build === void 0 ? void 0 : build.passed) !== null && _a !== void 0 ? _a : build === null || build === void 0 ? void 0 : build.allExpectedPassed) !== null && _b !== void 0 ? _b : evidence === null || evidence === void 0 ? void 0 : evidence.buildPassed);
1205
+ return {
1206
+ status: status,
1207
+ command: cleanText((build === null || build === void 0 ? void 0 : build.command) || (evidence === null || evidence === void 0 ? void 0 : evidence.buildCommand), 500),
1208
+ artifactPath: cleanText((build === null || build === void 0 ? void 0 : build.artifactPath) || (build === null || build === void 0 ? void 0 : build.logPath) || (evidence === null || evidence === void 0 ? void 0 : evidence.buildLogPath), 500),
1209
+ message: cleanText((build === null || build === void 0 ? void 0 : build.message) || (build === null || build === void 0 ? void 0 : build.error) || (evidence === null || evidence === void 0 ? void 0 : evidence.buildMessage), 1000),
1210
+ durationMs: Number((_c = build === null || build === void 0 ? void 0 : build.durationMs) !== null && _c !== void 0 ? _c : build === null || build === void 0 ? void 0 : build.duration_ms) || undefined,
1211
+ staleEvidence: (build === null || build === void 0 ? void 0 : build.staleEvidence) === true || (evidence === null || evidence === void 0 ? void 0 : evidence.staleBuildEvidence) === true,
1212
+ recordedAt: eventDate(build || evidence || {})
1213
+ };
1214
+ }
1215
+ function collectRouteProbes(evidence) {
1216
+ var e_23, _a, e_24, _b;
1217
+ var probes = [];
1218
+ var rows = __spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(asArray(evidence === null || evidence === void 0 ? void 0 : evidence.routeProbes)), false), __read(asArray(evidence === null || evidence === void 0 ? void 0 : evidence.route_probes)), false), __read(asArray(evidence === null || evidence === void 0 ? void 0 : evidence.routes)), false), __read(asArray(evidence === null || evidence === void 0 ? void 0 : evidence.browserRoutes)), false), __read(asArray(evidence === null || evidence === void 0 ? void 0 : evidence.browser_routes)), false), __read(asArray(evidence === null || evidence === void 0 ? void 0 : evidence.workflowProbes)), false), __read(asArray(evidence === null || evidence === void 0 ? void 0 : evidence.workflow_probes)), false);
1219
+ var directProbe = plainObject((evidence === null || evidence === void 0 ? void 0 : evidence.routeProbe) || (evidence === null || evidence === void 0 ? void 0 : evidence.route_probe) || (evidence === null || evidence === void 0 ? void 0 : evidence.workflowProbe) || (evidence === null || evidence === void 0 ? void 0 : evidence.workflow_probe));
1220
+ if (Object.keys(directProbe).length) {
1221
+ rows.push(directProbe);
1222
+ }
1223
+ try {
1224
+ for (var rows_1 = __values(rows), rows_1_1 = rows_1.next(); !rows_1_1.done; rows_1_1 = rows_1.next()) {
1225
+ var entry = rows_1_1.value;
1226
+ probes.push({
1227
+ route: cleanText(entry.route || entry.path || entry.url, 500) || '/',
1228
+ status: entry.status || statusFromBoolean(entry.passed),
1229
+ screenshot: cleanText(entry.screenshot || entry.screenshotPath, 500),
1230
+ caption: cleanText(entry.caption || entry.message, 1000),
1231
+ shellOnly: entry.shellOnly === true,
1232
+ authenticated: entry.authenticated === true,
1233
+ consoleErrors: asArray(entry.consoleErrors),
1234
+ networkErrors: asArray(entry.networkErrors),
1235
+ message: cleanText(entry.message || entry.error, 1000),
1236
+ recordedAt: eventDate(entry)
1237
+ });
1238
+ }
1239
+ }
1240
+ catch (e_23_1) { e_23 = { error: e_23_1 }; }
1241
+ finally {
1242
+ try {
1243
+ if (rows_1_1 && !rows_1_1.done && (_a = rows_1.return)) _a.call(rows_1);
1244
+ }
1245
+ finally { if (e_23) throw e_23.error; }
1246
+ }
1247
+ var screenshots = asArray((evidence === null || evidence === void 0 ? void 0 : evidence.screenshots) || (evidence === null || evidence === void 0 ? void 0 : evidence.qaScreenshots) || (evidence === null || evidence === void 0 ? void 0 : evidence.browserScreenshots));
1248
+ try {
1249
+ for (var _c = __values(screenshots.slice(0, 20)), _d = _c.next(); !_d.done; _d = _c.next()) {
1250
+ var screenshot = _d.value;
1251
+ if (typeof screenshot === 'string') {
1252
+ probes.push({ route: '/', status: 'pass', screenshot: screenshot, caption: 'Historical browser screenshot recorded.' });
1253
+ }
1254
+ else if (screenshot.route || screenshot.path || screenshot.url || screenshot.screenshot || screenshot.file) {
1255
+ probes.push({
1256
+ route: cleanText(screenshot.route || screenshot.url || screenshot.path, 500) || '/',
1257
+ status: screenshot.status || statusFromBoolean(screenshot.passed, 'pass'),
1258
+ screenshot: cleanText(screenshot.screenshot || screenshot.screenshotPath || screenshot.file || screenshot.path, 500),
1259
+ caption: cleanText(screenshot.caption || screenshot.message, 1000),
1260
+ shellOnly: screenshot.shellOnly === true,
1261
+ authenticated: screenshot.authenticated === true,
1262
+ recordedAt: eventDate(screenshot)
1263
+ });
1264
+ }
1265
+ }
1266
+ }
1267
+ catch (e_24_1) { e_24 = { error: e_24_1 }; }
1268
+ finally {
1269
+ try {
1270
+ if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
1271
+ }
1272
+ finally { if (e_24) throw e_24.error; }
1273
+ }
1274
+ return probes;
1275
+ }
1276
+ function collectBusinessAssertions(evidence) {
1277
+ var e_25, _a;
1278
+ var assertions = [];
1279
+ var rows = __spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(asArray(evidence === null || evidence === void 0 ? void 0 : evidence.businessAssertions)), false), __read(asArray(evidence === null || evidence === void 0 ? void 0 : evidence.business_assertions)), false), __read(asArray(evidence === null || evidence === void 0 ? void 0 : evidence.workflowAssertions)), false), __read(asArray(evidence === null || evidence === void 0 ? void 0 : evidence.workflow_assertions)), false), __read(asArray(evidence === null || evidence === void 0 ? void 0 : evidence.assertions)), false), __read(asArray(evidence === null || evidence === void 0 ? void 0 : evidence.qaRows)), false), __read(asArray(evidence === null || evidence === void 0 ? void 0 : evidence.qa_rows)), false), __read(asArray(evidence === null || evidence === void 0 ? void 0 : evidence.rows)), false), __read(asArray(evidence === null || evidence === void 0 ? void 0 : evidence.supportQaAssertions)), false), __read(asArray(evidence === null || evidence === void 0 ? void 0 : evidence.support_qa_assertions)), false), __read(asArray(evidence === null || evidence === void 0 ? void 0 : evidence.aiQaBusinessAssertions)), false), __read(asArray(evidence === null || evidence === void 0 ? void 0 : evidence.ai_qa_business_assertions)), false);
1280
+ try {
1281
+ for (var rows_2 = __values(rows), rows_2_1 = rows_2.next(); !rows_2_1.done; rows_2_1 = rows_2.next()) {
1282
+ var entry = rows_2_1.value;
1283
+ assertions.push({
1284
+ assertion: cleanText(entry.assertion || entry.name || entry.label || entry.workflow || entry.expected, 1000) || 'business assertion',
1285
+ status: entry.status || entry.outcome || entry.result || statusFromBoolean(entry.passed),
1286
+ workflow: cleanText(entry.workflow || entry.workflowName || entry.workflow_name, 400),
1287
+ route: cleanText(entry.route || entry.url, 500),
1288
+ action: cleanText(entry.action || entry.action_under_test || entry.actionUnderTest, 500),
1289
+ expected: cleanText(entry.expected || entry.expected_business_state_change || entry.expectedBusinessStateChange, 1000),
1290
+ observed: cleanText(entry.observed || entry.actual || entry.after || entry.after_state || entry.afterState, 1000),
1291
+ dataProof: cleanText(entry.dataProof || entry.data_proof || entry.domProof || entry.dom_proof || entry.proof || entry.summary, 1400),
1292
+ mongoDelta: plainObject(entry.mongoDelta || entry.mongo_delta),
1293
+ artifactPaths: cleanStringList(entry.artifactPaths || entry.artifact_paths || entry.artifacts || entry.screenshots || (entry.screenshot ? [entry.screenshot] : []), 30, 500),
1294
+ message: cleanText(entry.message || entry.error || entry.reason, 1000),
1295
+ recordedAt: eventDate(entry),
1296
+ metadata: __assign(__assign(__assign({}, plainObject(entry.metadata)), (entry.acceptanceBlocked === true || entry.acceptance_blocked === true ? { acceptanceBlocked: true } : {})), (entry.routeOnly === true || entry.route_only === true ? { routeOnly: true } : {}))
1297
+ });
1298
+ }
1299
+ }
1300
+ catch (e_25_1) { e_25 = { error: e_25_1 }; }
1301
+ finally {
1302
+ try {
1303
+ if (rows_2_1 && !rows_2_1.done && (_a = rows_2.return)) _a.call(rows_2);
1304
+ }
1305
+ finally { if (e_25) throw e_25.error; }
1306
+ }
1307
+ if (!assertions.length && (evidence === null || evidence === void 0 ? void 0 : evidence.qaRunOutcome) === 'business_assertion_passed') {
1308
+ assertions.push({
1309
+ assertion: cleanText(evidence.aiRunOutcomeReason || evidence.reason || 'Historical business assertion passed.', 1000),
1310
+ status: 'pass',
1311
+ dataProof: cleanText(evidence.aiRunOutcomeReason || evidence.reason, 1400)
1312
+ });
1313
+ }
1314
+ if (!assertions.length && (evidence === null || evidence === void 0 ? void 0 : evidence.qaRunOutcome) === 'business_assertion_failed') {
1315
+ assertions.push({
1316
+ assertion: cleanText(evidence.aiRunOutcomeReason || evidence.reason || 'Historical business assertion failed.', 1000),
1317
+ status: 'fail',
1318
+ observed: cleanText(evidence.aiRunOutcomeReason || evidence.reason, 1000)
1319
+ });
1320
+ }
1321
+ return assertions;
1322
+ }
1323
+ function buildQaFromEvidence(evidence, now) {
1324
+ return (0, ai_run_evidence_1.buildAIQaRun)({
1325
+ infraChecks: collectInfraChecks(evidence),
1326
+ compile: collectCompileResult(evidence),
1327
+ routeProbes: collectRouteProbes(evidence),
1328
+ businessAssertions: collectBusinessAssertions(evidence),
1329
+ artifacts: collectArtifacts(evidence),
1330
+ now: now
1331
+ });
1332
+ }
1333
+ function isoNow(value) {
1334
+ if (value instanceof Date) {
1335
+ return value.toISOString();
1336
+ }
1337
+ if (value) {
1338
+ var parsed = new Date(value);
1339
+ if (!Number.isNaN(parsed.getTime())) {
1340
+ return parsed.toISOString();
1341
+ }
1342
+ }
1343
+ return new Date().toISOString();
1344
+ }
1345
+ function normalizeMatchText(value) {
1346
+ return cleanText(value, 3000)
1347
+ .toLowerCase()
1348
+ .replace(/[^a-z0-9]+/g, ' ')
1349
+ .replace(/\s+/g, ' ')
1350
+ .trim();
1351
+ }
1352
+ function importantTokens(value) {
1353
+ var stopWords = new Set([
1354
+ 'the', 'and', 'that', 'with', 'from', 'after', 'before', 'when', 'then', 'this', 'must',
1355
+ 'should', 'will', 'only', 'into', 'have', 'has', 'are', 'was', 'were', 'been'
1356
+ ]);
1357
+ return new Set(normalizeMatchText(value).split(' ')
1358
+ .filter(function (token) { return token.length >= 4 && !stopWords.has(token); }));
1359
+ }
1360
+ function businessAssertionPassed(assertion) {
1361
+ return /^(pass|passed|success|ok|done)$/i.test(cleanText(assertion.status, 40));
1362
+ }
1363
+ function supportAssertionMatchesDiagnosisProof(assertion, proofPlan) {
1364
+ var e_26, _a;
1365
+ var metadata = assertion.metadata || {};
1366
+ if (metadata.diagnosisProofPlanMatched === true || metadata.proofPlanMatched === true || metadata.supportDiagnosisProof === true) {
1367
+ return true;
1368
+ }
1369
+ var requiredBusinessAssertion = proofPlan.business_assertion || proofPlan.businessAssertion;
1370
+ var proofParts = [
1371
+ requiredBusinessAssertion,
1372
+ proofPlan.after,
1373
+ proofPlan.data_assertion || proofPlan.dataAssertion,
1374
+ proofPlan.artifact_expectation || proofPlan.artifactExpectation
1375
+ ].map(function (part) { return normalizeMatchText(part); }).filter(function (part) { return part.length >= 16; });
1376
+ if (!proofParts.length) {
1377
+ return true;
1378
+ }
1379
+ var assertionText = normalizeMatchText([
1380
+ assertion.assertion,
1381
+ assertion.workflow,
1382
+ assertion.action,
1383
+ assertion.expected,
1384
+ assertion.observed,
1385
+ assertion.dataProof,
1386
+ assertion.message
1387
+ ].filter(Boolean).join(' '));
1388
+ if (proofParts.some(function (part) { return assertionText.includes(part); })) {
1389
+ return true;
1390
+ }
1391
+ var proofTokens = importantTokens([
1392
+ requiredBusinessAssertion,
1393
+ proofPlan.after,
1394
+ proofPlan.data_assertion || proofPlan.dataAssertion
1395
+ ].filter(Boolean).join(' '));
1396
+ var assertionTokens = importantTokens(assertionText);
1397
+ if (!proofTokens.size) {
1398
+ return true;
1399
+ }
1400
+ var overlap = 0;
1401
+ try {
1402
+ for (var proofTokens_1 = __values(proofTokens), proofTokens_1_1 = proofTokens_1.next(); !proofTokens_1_1.done; proofTokens_1_1 = proofTokens_1.next()) {
1403
+ var token = proofTokens_1_1.value;
1404
+ if (assertionTokens.has(token)) {
1405
+ overlap += 1;
1406
+ }
1407
+ }
1408
+ }
1409
+ catch (e_26_1) { e_26 = { error: e_26_1 }; }
1410
+ finally {
1411
+ try {
1412
+ if (proofTokens_1_1 && !proofTokens_1_1.done && (_a = proofTokens_1.return)) _a.call(proofTokens_1);
1413
+ }
1414
+ finally { if (e_26) throw e_26.error; }
1415
+ }
1416
+ return overlap >= Math.min(4, Math.max(3, Math.ceil(proofTokens.size * 0.45)));
1417
+ }
1418
+ function supportDiagnosisProofGateResult(diagnosisGate, now) {
1419
+ var proofPlan = diagnosisGate.proof_plan || diagnosisGate.proofPlan || {};
1420
+ return {
1421
+ key: 'support_diagnosis_business_proof',
1422
+ label: 'Diagnosis proof plan',
1423
+ status: 'blocked',
1424
+ reason: 'Support business assertion did not map to the diagnosis proof_plan. Route proof or generic workflow proof cannot accept the ticket.',
1425
+ evidenceRefs: [],
1426
+ recordedAt: isoNow(now),
1427
+ metadata: {
1428
+ issueClass: cleanText(diagnosisGate.issue_class || diagnosisGate.issueClass, 120),
1429
+ requiredBusinessAssertion: cleanText(proofPlan.business_assertion || proofPlan.businessAssertion, 1000),
1430
+ requiredAfter: cleanText(proofPlan.after, 1000),
1431
+ requiredDataAssertion: cleanText(proofPlan.data_assertion || proofPlan.dataAssertion, 1000)
1432
+ }
1433
+ };
1434
+ }
1435
+ var SUPPORT_ROOT_CAUSE_ENTRY_REQUIRED_FIELDS = [
1436
+ 'issue_case',
1437
+ 'issue_class',
1438
+ 'accepted_hypothesis',
1439
+ 'rejected_alternatives',
1440
+ 'failing_path',
1441
+ 'owner_files',
1442
+ 'proof_plan',
1443
+ 'evidence'
1444
+ ];
1445
+ var SUPPORT_ROOT_CAUSE_ENTRY_ISSUE_CLASSES = [
1446
+ 'no_op_submit',
1447
+ 'missing_wrong_data',
1448
+ 'filter_query_mismatch',
1449
+ 'invoice_pdf_export',
1450
+ 'upload_import',
1451
+ 'route_auth_hydration',
1452
+ 'slow_query_performance'
1453
+ ];
1454
+ function supportRootCauseEntryContractGate(contract, now) {
1455
+ if (!contract || !Object.keys(contract).length) {
1456
+ return undefined;
1457
+ }
1458
+ var requiredOutput = plainObject(contract.required_output || contract.requiredOutput);
1459
+ var ownerPolicy = plainObject(contract.owner_file_policy || contract.ownerFilePolicy);
1460
+ var businessProofPolicy = plainObject(contract.business_proof_policy || contract.businessProofPolicy);
1461
+ var failurePolicy = plainObject(contract.failure_policy || contract.failurePolicy);
1462
+ var probes = asArray(contract.issue_class_probes || contract.issueClassProbes);
1463
+ var requiredFields = cleanStringList(requiredOutput.required_fields || requiredOutput.requiredFields, 30, 160);
1464
+ var issueClasses = probes.map(function (probe) { return cleanText(probe.issue_class || probe.issueClass, 120); }).filter(Boolean);
1465
+ var missingRequiredFields = SUPPORT_ROOT_CAUSE_ENTRY_REQUIRED_FIELDS.filter(function (field) { return !requiredFields.includes(field); });
1466
+ var missingIssueClasses = SUPPORT_ROOT_CAUSE_ENTRY_ISSUE_CLASSES.filter(function (issueClass) { return !issueClasses.includes(issueClass); });
1467
+ var blockers = [];
1468
+ if (!cleanText(contract.contract_id || contract.contractId, 160)) {
1469
+ blockers.push('Root-cause entry contract is missing contract_id.');
1470
+ }
1471
+ if (cleanText(requiredOutput.object_key || requiredOutput.objectKey, 120) !== 'support_diagnosis_gate') {
1472
+ blockers.push('Root-cause entry contract must require support_diagnosis_gate output.');
1473
+ }
1474
+ if (missingRequiredFields.length) {
1475
+ blockers.push("Root-cause entry contract missing required output fields: ".concat(missingRequiredFields.join(', '), "."));
1476
+ }
1477
+ var ownerFileMax = Number(ownerPolicy.max_files || ownerPolicy.maxFiles || 0);
1478
+ if (!Number.isFinite(ownerFileMax) || ownerFileMax <= 0 || ownerFileMax > 12) {
1479
+ blockers.push('Root-cause entry contract must cap owner_files to a small exact file set.');
1480
+ }
1481
+ if (ownerPolicy.edits_outside_owner_files_require_revised_diagnosis !== true && ownerPolicy.editsOutsideOwnerFilesRequireRevisedDiagnosis !== true) {
1482
+ blockers.push('Root-cause entry contract must require revised diagnosis before edits outside owner_files.');
1483
+ }
1484
+ if (businessProofPolicy.requires_aiqa_business_assertion !== true && businessProofPolicy.requiresAiqaBusinessAssertion !== true) {
1485
+ blockers.push('Root-cause entry contract must require AIQaBusinessAssertion business proof.');
1486
+ }
1487
+ if (businessProofPolicy.route_load_screenshot_scorecard_model_claim_not_acceptance !== true && businessProofPolicy.routeLoadScreenshotScorecardModelClaimNotAcceptance !== true) {
1488
+ blockers.push('Root-cause entry contract must reject route-load/screenshot/scorecard/model-claim acceptance.');
1489
+ }
1490
+ if (failurePolicy.repeated_failure_without_new_evidence_parks_run !== true && failurePolicy.repeatedFailureWithoutNewEvidenceParksRun !== true) {
1491
+ blockers.push('Root-cause entry contract must park repeated failures without new evidence.');
1492
+ }
1493
+ if (missingIssueClasses.length) {
1494
+ blockers.push("Root-cause entry contract missing issue-class probes: ".concat(missingIssueClasses.join(', '), "."));
1495
+ }
1496
+ var status = blockers.length ? 'fail' : 'pass';
1497
+ return {
1498
+ key: 'support_root_cause_entry_contract',
1499
+ label: 'Root-cause entry contract',
1500
+ status: status,
1501
+ reason: blockers.length
1502
+ ? blockers.join(' ')
1503
+ : 'Support run has a structured root-cause-first entry contract with issue-class probes, owner-file policy, and business-proof policy.',
1504
+ evidenceRefs: cleanStringList(businessProofPolicy.required_artifacts || businessProofPolicy.requiredArtifacts, 20, 500),
1505
+ recordedAt: isoNow(now),
1506
+ metadata: {
1507
+ contractId: cleanText(contract.contract_id || contract.contractId, 160),
1508
+ version: cleanText(contract.version, 120),
1509
+ status: cleanText(contract.status, 120),
1510
+ requiredOutputKey: cleanText(requiredOutput.object_key || requiredOutput.objectKey, 120),
1511
+ requiredFields: requiredFields,
1512
+ missingRequiredFields: missingRequiredFields,
1513
+ ownerFileMax: ownerFileMax,
1514
+ requiresRevisedDiagnosisForOutOfScopeEdits: ownerPolicy.edits_outside_owner_files_require_revised_diagnosis === true || ownerPolicy.editsOutsideOwnerFilesRequireRevisedDiagnosis === true,
1515
+ requiresBusinessAssertion: businessProofPolicy.requires_aiqa_business_assertion === true || businessProofPolicy.requiresAiqaBusinessAssertion === true,
1516
+ routeOnlyAcceptanceRejected: businessProofPolicy.route_load_screenshot_scorecard_model_claim_not_acceptance === true || businessProofPolicy.routeLoadScreenshotScorecardModelClaimNotAcceptance === true,
1517
+ issueClassProbeCount: issueClasses.length,
1518
+ issueClasses: issueClasses,
1519
+ missingIssueClasses: missingIssueClasses
1520
+ }
1521
+ };
1522
+ }
1523
+ function applySupportDiagnosisProofGate(qa, diagnosisGate, now) {
1524
+ var proofPlan = diagnosisGate.proof_plan || diagnosisGate.proofPlan || {};
1525
+ var requiredBusinessAssertion = cleanText(proofPlan.business_assertion || proofPlan.businessAssertion, 1000);
1526
+ var requiredAfter = cleanText(proofPlan.after, 1000);
1527
+ if (!Object.keys(proofPlan).length || (!requiredBusinessAssertion && !requiredAfter)) {
1528
+ return qa;
1529
+ }
1530
+ var passedAssertions = qa.businessAssertions.filter(businessAssertionPassed);
1531
+ if (!passedAssertions.length) {
1532
+ return qa;
1533
+ }
1534
+ if (passedAssertions.some(function (assertion) { return supportAssertionMatchesDiagnosisProof(assertion, proofPlan); })) {
1535
+ return qa;
1536
+ }
1537
+ var gate = supportDiagnosisProofGateResult(diagnosisGate, now);
1538
+ return __assign(__assign({}, qa), { outcome: qa.routeProbes.some(function (probe) { return /^(pass|passed|success|ok|done)$/i.test(cleanText(probe.status, 40)); })
1539
+ ? 'route_only_pass'
1540
+ : 'incomplete', gateResults: __spreadArray(__spreadArray([], __read(qa.gateResults.filter(function (existing) { return !(existing.key === 'qa_business_assertion' && existing.status === 'pass'); })), false), [
1541
+ gate
1542
+ ], false) });
1543
+ }
1544
+ var SUPPORT_PRODUCT_REPAIR_STEP_TYPES = new Set([
1545
+ 'build_repair',
1546
+ 'owner_scoped_repair',
1547
+ 'product_repair',
1548
+ 'code_repair'
1549
+ ]);
1550
+ var SUPPORT_PRODUCT_REPAIR_ACTIONS = new Set([
1551
+ 'run_owner_scoped_repair',
1552
+ 'run_targeted_product_repair',
1553
+ 'allow_product_repair'
1554
+ ]);
1555
+ function supportSourceEditFiles(value) {
1556
+ return cleanStringList(value, 80, 500)
1557
+ .filter(function (filePath) {
1558
+ var normalized = filePath.replace(/\\/g, '/').toLowerCase();
1559
+ if (!normalized || /(^|\/)(qa-artifacts|runner-evidence|logs?|tmp|dist|node_modules)(\/|$)/.test(normalized)) {
1560
+ return false;
1561
+ }
1562
+ return /\.(?:ts|tsx|js|jsx|html|scss|css|json|mjs|cjs|vue|svelte|md)$/i.test(normalized);
1563
+ });
1564
+ }
1565
+ function supportRepairActivityFromRecord(value, source, index) {
1566
+ var record = plainObject(value);
1567
+ if (!Object.keys(record).length) {
1568
+ return undefined;
1569
+ }
1570
+ var stepType = cleanText(record.stepType || record.step_type || record.type, 120);
1571
+ var action = cleanText(record.action || record.primaryAction || record.primary_action || record.allowedDispatchAction || record.allowed_dispatch_action, 120);
1572
+ var lane = cleanText(record.lane || record.phase || record.category, 120).toLowerCase();
1573
+ var changedFiles = supportSourceEditFiles(record.changedFiles
1574
+ || record.changed_files
1575
+ || record.modifiedFiles
1576
+ || record.modified_files
1577
+ || record.editedFiles
1578
+ || record.edited_files
1579
+ || record.files);
1580
+ var explicitProductRepair = SUPPORT_PRODUCT_REPAIR_STEP_TYPES.has(stepType)
1581
+ || SUPPORT_PRODUCT_REPAIR_ACTIONS.has(action)
1582
+ || (lane === 'build' && changedFiles.length > 0);
1583
+ if (!explicitProductRepair) {
1584
+ return undefined;
1585
+ }
1586
+ var activityRef = cleanText(record.microtaskId
1587
+ || record.microtask_id
1588
+ || record.taskId
1589
+ || record.task_id
1590
+ || record.jobId
1591
+ || record.job_id
1592
+ || record._id
1593
+ || record.id
1594
+ || "".concat(source, ":").concat(index), 240);
1595
+ return { changedFiles: changedFiles, activityRef: activityRef };
1596
+ }
1597
+ function supportProductRepairEvidence(input, evidence) {
1598
+ var job = input.job || {};
1599
+ var records = __spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(asArray(job.supportV5StepHistory)), false), __read(asArray(job.support_v5_step_history)), false), __read(asArray(job.stepHistory)), false), __read(asArray(job.step_history)), false), __read(asArray(evidence.supportV5StepHistory)), false), __read(asArray(evidence.support_v5_step_history)), false), __read(asArray(evidence.stepHistory)), false), __read(asArray(evidence.step_history)), false), __read(asArray(input.taskEvents)), false), __read(asArray(input.aiJobs)), false), __read(asArray(input.buildPlans)), false);
1600
+ var activityRefs = [];
1601
+ var changedFiles = [];
1602
+ var activityCount = 0;
1603
+ records.forEach(function (record, index) {
1604
+ var activity = supportRepairActivityFromRecord(record, 'support_repair_activity', index);
1605
+ if (!activity) {
1606
+ return;
1607
+ }
1608
+ activityCount += 1;
1609
+ if (activity.activityRef) {
1610
+ activityRefs.push(activity.activityRef);
1611
+ }
1612
+ changedFiles.push.apply(changedFiles, __spreadArray([], __read(activity.changedFiles), false));
1613
+ });
1614
+ var directChangedFiles = supportSourceEditFiles(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(asArray(job.changedFiles)), false), __read(asArray(job.changed_files)), false), __read(asArray(job.modifiedFiles)), false), __read(asArray(job.modified_files)), false), __read(asArray(job.editedFiles)), false), __read(asArray(job.edited_files)), false), __read(asArray(evidence.changedFiles)), false), __read(asArray(evidence.changed_files)), false), __read(asArray(evidence.modifiedFiles)), false), __read(asArray(evidence.modified_files)), false), __read(asArray(evidence.editedFiles)), false), __read(asArray(evidence.edited_files)), false), __read(asArray(input.commits).flatMap(function (commit) { return asArray(commit.changedFiles || commit.changed_files || commit.files); })), false));
1615
+ if (directChangedFiles.length) {
1616
+ activityCount += 1;
1617
+ activityRefs.push('changed_files');
1618
+ changedFiles.push.apply(changedFiles, __spreadArray([], __read(directChangedFiles), false));
1619
+ }
1620
+ var uniqueChangedFiles = Array.from(new Set(changedFiles.map(function (filePath) { return cleanText(filePath, 500); }).filter(Boolean))).slice(0, 80);
1621
+ return {
1622
+ attempted: activityCount > 0,
1623
+ changedFiles: uniqueChangedFiles,
1624
+ activityRefs: Array.from(new Set(activityRefs.map(function (ref) { return cleanText(ref, 240); }).filter(Boolean))).slice(0, 40),
1625
+ activityCount: activityCount
1626
+ };
1627
+ }
1628
+ function supportDiagnosisBeforeRepairGate(diagnosisGate, repairEvidence, now) {
1629
+ var _a, _b;
1630
+ if (!repairEvidence.attempted) {
1631
+ return undefined;
1632
+ }
1633
+ var validation = (0, support_runner_v5_1.validateResolveIOSupportDiagnosisGate)(diagnosisGate);
1634
+ var status = validation.valid ? 'pass' : 'blocked';
1635
+ return {
1636
+ key: 'support_diagnosis_before_repair',
1637
+ label: 'Support diagnosis before repair',
1638
+ status: status,
1639
+ reason: validation.valid
1640
+ ? 'Support product repair has a valid root-cause diagnosis gate and owner-file scope.'
1641
+ : 'Support product repair is blocked until a valid SupportDiagnosisGate records reproduction/classification, accepted hypothesis, rejected alternatives, owner_files, and before/action/after proof.',
1642
+ evidenceRefs: repairEvidence.changedFiles,
1643
+ recordedAt: isoNow(now),
1644
+ metadata: {
1645
+ repairAttempted: true,
1646
+ activityCount: repairEvidence.activityCount,
1647
+ activityRefs: repairEvidence.activityRefs,
1648
+ changedFiles: repairEvidence.changedFiles,
1649
+ diagnosisValid: validation.valid,
1650
+ diagnosisStatus: validation.status,
1651
+ blockers: validation.blockers,
1652
+ ownerFiles: ((_a = validation.normalized) === null || _a === void 0 ? void 0 : _a.owner_files) || [],
1653
+ issueClass: (_b = validation.normalized) === null || _b === void 0 ? void 0 : _b.issue_class,
1654
+ productRepairAllowed: validation.valid,
1655
+ allowedDispatchAction: validation.valid ? 'run_owner_scoped_repair' : 'run_read_only_diagnosis',
1656
+ requiredEvidence: validation.valid
1657
+ ? ['AIQaBusinessAssertion mapped to diagnosis proof_plan before acceptance']
1658
+ : ['support_diagnosis_gate JSON', 'reproduction or blocked-reproduction reason', 'accepted_hypothesis with evidence', 'owner_files', 'proof_plan before/action/after']
1659
+ }
1660
+ };
1661
+ }
1662
+ function supportOwnerFileScopeGate(diagnosisGate, repairEvidence, now) {
1663
+ if (!repairEvidence.attempted) {
1664
+ return undefined;
1665
+ }
1666
+ var validation = (0, support_runner_v5_1.validateResolveIOSupportDiagnosisGate)(diagnosisGate);
1667
+ if (!validation.valid || !validation.normalized) {
1668
+ return undefined;
1669
+ }
1670
+ var outsideOwnerFiles = (0, support_runner_v5_1.changedFilesOutsideResolveIOSupportDiagnosisOwnerFiles)(validation.normalized, repairEvidence.changedFiles, { allowTests: true });
1671
+ var status = outsideOwnerFiles.length ? 'blocked' : 'pass';
1672
+ return {
1673
+ key: 'support_owner_file_scope',
1674
+ label: 'Support owner-file scope',
1675
+ status: status,
1676
+ reason: outsideOwnerFiles.length
1677
+ ? "Support repair changed files outside diagnosis owner_files; revise diagnosis with new evidence before broadening edits: ".concat(outsideOwnerFiles.join(', '))
1678
+ : 'Support repair stayed within diagnosis owner_files; test-only changes are allowed as supporting evidence.',
1679
+ evidenceRefs: outsideOwnerFiles.length ? outsideOwnerFiles : repairEvidence.changedFiles,
1680
+ recordedAt: isoNow(now),
1681
+ metadata: {
1682
+ repairAttempted: true,
1683
+ diagnosisValid: true,
1684
+ issueClass: validation.normalized.issue_class,
1685
+ ownerFiles: validation.normalized.owner_files,
1686
+ changedFiles: repairEvidence.changedFiles,
1687
+ outsideOwnerFiles: outsideOwnerFiles,
1688
+ allowedTestFilesOutsideOwnerScope: true,
1689
+ productRepairAllowed: outsideOwnerFiles.length === 0,
1690
+ allowedDispatchAction: outsideOwnerFiles.length ? 'run_read_only_diagnosis' : 'run_business_proof_qa',
1691
+ requiredEvidence: outsideOwnerFiles.length
1692
+ ? ['revised SupportDiagnosisGate with evidence for each new owner file', 'updated failing_path and proof_plan matching broadened scope']
1693
+ : ['compile/unit proof', 'AIQaBusinessAssertion mapped to diagnosis proof_plan']
1694
+ }
1695
+ };
1696
+ }
1697
+ function evidenceObject() {
1698
+ var e_27, _a;
1699
+ var values = [];
1700
+ for (var _i = 0; _i < arguments.length; _i++) {
1701
+ values[_i] = arguments[_i];
1702
+ }
1703
+ try {
1704
+ for (var values_1 = __values(values), values_1_1 = values_1.next(); !values_1_1.done; values_1_1 = values_1.next()) {
1705
+ var value = values_1_1.value;
1706
+ if (value && typeof value === 'object' && !Array.isArray(value)) {
1707
+ return value;
1708
+ }
1709
+ }
1710
+ }
1711
+ catch (e_27_1) { e_27 = { error: e_27_1 }; }
1712
+ finally {
1713
+ try {
1714
+ if (values_1_1 && !values_1_1.done && (_a = values_1.return)) _a.call(values_1);
1715
+ }
1716
+ finally { if (e_27) throw e_27.error; }
1717
+ }
1718
+ return {};
1719
+ }
1720
+ function mergeEvidenceRecords() {
1721
+ var e_28, _a, e_29, _b;
1722
+ var values = [];
1723
+ for (var _i = 0; _i < arguments.length; _i++) {
1724
+ values[_i] = arguments[_i];
1725
+ }
1726
+ var merged = {};
1727
+ try {
1728
+ for (var values_2 = __values(values), values_2_1 = values_2.next(); !values_2_1.done; values_2_1 = values_2.next()) {
1729
+ var value = values_2_1.value;
1730
+ var source = plainObject(value);
1731
+ try {
1732
+ for (var _c = (e_29 = void 0, __values(Object.entries(source))), _d = _c.next(); !_d.done; _d = _c.next()) {
1733
+ var _e = __read(_d.value, 2), key = _e[0], entry = _e[1];
1734
+ if (entry === undefined || entry === null || entry === '') {
1735
+ continue;
1736
+ }
1737
+ if (Array.isArray(entry)) {
1738
+ merged[key] = __spreadArray(__spreadArray([], __read(asArray(merged[key])), false), __read(entry), false);
1739
+ continue;
1740
+ }
1741
+ if (plainObject(entry) === entry && plainObject(merged[key]) === merged[key]) {
1742
+ merged[key] = __assign(__assign({}, merged[key]), entry);
1743
+ continue;
1744
+ }
1745
+ merged[key] = entry;
1746
+ }
1747
+ }
1748
+ catch (e_29_1) { e_29 = { error: e_29_1 }; }
1749
+ finally {
1750
+ try {
1751
+ if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
1752
+ }
1753
+ finally { if (e_29) throw e_29.error; }
1754
+ }
1755
+ }
1756
+ }
1757
+ catch (e_28_1) { e_28 = { error: e_28_1 }; }
1758
+ finally {
1759
+ try {
1760
+ if (values_2_1 && !values_2_1.done && (_a = values_2.return)) _a.call(values_2);
1761
+ }
1762
+ finally { if (e_28) throw e_28.error; }
1763
+ }
1764
+ return merged;
1765
+ }
1766
+ function buildSupportQaEvidence(input) {
1767
+ var job = input.job || {};
1768
+ var ticket = input.ticket || {};
1769
+ var qaCursor = plainObject(job.supportQaValidationCursor || job.support_qa_validation_cursor);
1770
+ var autonomousDecision = plainObject(job.supportV5AutonomousDecision || job.support_v5_autonomous_decision);
1771
+ var ticketAutomation = plainObject(ticket.automation);
1772
+ var ticketManager = plainObject(ticketAutomation.manager || ticket.manager);
1773
+ var preflightGate = supportPreflightGateObject(ticket, job, __assign(__assign({}, plainObject(input.qaEvidence)), { supportV5AutonomousDecision: autonomousDecision }));
1774
+ var businessProofReadiness = plainObject(autonomousDecision.businessProofReadiness
1775
+ || autonomousDecision.business_proof_readiness
1776
+ || job.businessProofReadiness
1777
+ || job.business_proof_readiness);
1778
+ var customerReplyPolicy = plainObject(autonomousDecision.customerReplyPolicy
1779
+ || autonomousDecision.customer_reply_policy
1780
+ || job.customerReplyPolicy
1781
+ || job.customer_reply_policy);
1782
+ var customerReplyReadiness = plainObject(autonomousDecision.customerReplyReadiness
1783
+ || autonomousDecision.customer_reply_readiness
1784
+ || customerReplyPolicy.readinessContract
1785
+ || customerReplyPolicy.readiness_contract
1786
+ || job.customerReplyReadiness
1787
+ || job.customer_reply_readiness);
1788
+ var managerRecoveryExecutionProof = plainObject(job.managerRecoveryExecutionProof
1789
+ || job.manager_recovery_execution_proof
1790
+ || job.supportManagerRecoveryExecutionProof
1791
+ || job.support_manager_recovery_execution_proof
1792
+ || autonomousDecision.recoveryExecutionProof
1793
+ || autonomousDecision.recovery_execution_proof
1794
+ || ticketManager.last_recovery_execution_proof
1795
+ || ticketManager.recovery_execution_proof);
1796
+ var humanReviewPacket = plainObject(autonomousDecision.humanReviewPacket
1797
+ || autonomousDecision.human_review_packet
1798
+ || customerReplyPolicy.humanReviewPacket
1799
+ || customerReplyPolicy.human_review_packet
1800
+ || job.humanReviewPacket
1801
+ || job.human_review_packet);
1802
+ var evidence = mergeEvidenceRecords(qaCursor, job.qaEvidence, job.qa_evidence, ticket.qaEvidence, ticket.qa_evidence, input.qaEvidence);
1803
+ evidence.supportQaAssertions = __spreadArray(__spreadArray(__spreadArray([], __read(asArray(job.supportQaAssertions)), false), __read(asArray(job.support_qa_assertions)), false), __read(asArray(evidence.supportQaAssertions)), false);
1804
+ evidence.aiQaBusinessAssertions = __spreadArray(__spreadArray(__spreadArray([], __read(asArray(job.aiQaBusinessAssertions)), false), __read(asArray(job.ai_qa_business_assertions)), false), __read(asArray(evidence.aiQaBusinessAssertions)), false);
1805
+ evidence.runnerEvidenceArtifacts = __spreadArray(__spreadArray(__spreadArray([], __read(asArray(job.runnerEvidenceArtifacts)), false), __read(asArray(job.runner_evidence_artifacts)), false), __read(asArray(evidence.runnerEvidenceArtifacts)), false);
1806
+ evidence.supportQaArtifacts = __spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(asArray(job.supportQaArtifacts)), false), __read(asArray(job.support_qa_artifacts)), false), __read(asArray(job.qa_artifacts)), false), __read(asArray(evidence.supportQaArtifacts)), false);
1807
+ if (Object.keys(businessProofReadiness).length) {
1808
+ evidence.businessProofReadiness = businessProofReadiness;
1809
+ }
1810
+ if (Object.keys(customerReplyPolicy).length) {
1811
+ evidence.customerReplyPolicy = __assign(__assign({}, customerReplyPolicy), (Object.keys(humanReviewPacket).length ? { humanReviewPacket: humanReviewPacket } : {}));
1812
+ }
1813
+ else if (Object.keys(humanReviewPacket).length) {
1814
+ evidence.customerReplyPolicy = { humanReviewPacket: humanReviewPacket };
1815
+ }
1816
+ if (Object.keys(customerReplyReadiness).length) {
1817
+ evidence.customerReplyReadiness = customerReplyReadiness;
1818
+ }
1819
+ if (Object.keys(managerRecoveryExecutionProof).length) {
1820
+ evidence.managerRecoveryExecutionProof = managerRecoveryExecutionProof;
1821
+ }
1822
+ if (Object.keys(preflightGate).length) {
1823
+ evidence.supportV5PreflightGate = preflightGate;
1824
+ applySupportPreflightGateToQaEvidence(evidence, preflightGate);
1825
+ }
1826
+ return evidence;
1827
+ }
1828
+ function supportPreflightGateObject(ticket, job, evidence) {
1829
+ var _a, _b;
1830
+ var autonomousDecision = plainObject(job.supportV5AutonomousDecision
1831
+ || job.support_v5_autonomous_decision
1832
+ || evidence.supportV5AutonomousDecision
1833
+ || evidence.support_v5_autonomous_decision
1834
+ || ticket.supportV5AutonomousDecision
1835
+ || ticket.support_v5_autonomous_decision);
1836
+ var ticketAutomation = plainObject(ticket.automation);
1837
+ var ticketManager = plainObject(ticketAutomation.manager || ticket.manager);
1838
+ return evidenceObject(job.supportV5PreflightGate, job.support_v5_preflight_gate, job.preflightGate, job.preflight_gate, evidence.supportV5PreflightGate, evidence.support_v5_preflight_gate, evidence.preflightGate, evidence.preflight_gate, autonomousDecision.preflightGate, autonomousDecision.preflight_gate, (_a = autonomousDecision.rootCauseReadiness) === null || _a === void 0 ? void 0 : _a.preflightGate, (_b = autonomousDecision.root_cause_readiness) === null || _b === void 0 ? void 0 : _b.preflight_gate, ticket.supportV5PreflightGate, ticket.support_v5_preflight_gate, ticketManager.supportV5PreflightGate, ticketManager.support_v5_preflight_gate, ticketManager.preflightGate, ticketManager.preflight_gate);
1839
+ }
1840
+ function supportPreflightStatus(value) {
1841
+ return cleanText(value, 120).toLowerCase();
1842
+ }
1843
+ function supportPreflightFailedChecks(preflightGate) {
1844
+ var failed = __spreadArray(__spreadArray([], __read(asArray(preflightGate.failedChecks || preflightGate.failed_checks)), false), __read(asArray(preflightGate.checks).filter(function (check) {
1845
+ var status = supportPreflightStatus(check.status || check.state || check.outcome);
1846
+ return /fail|failed|blocked|missing|error/.test(status);
1847
+ })), false);
1848
+ var seen = new Set();
1849
+ return failed.filter(function (check) {
1850
+ var key = "".concat(cleanText(check.name || check.check || check.key, 160), ":").concat(cleanText(check.summary || check.message || check.error || check.reason, 500));
1851
+ if (seen.has(key)) {
1852
+ return false;
1853
+ }
1854
+ seen.add(key);
1855
+ return true;
1856
+ });
1857
+ }
1858
+ function supportPreflightArtifactPaths(preflightGate, checks) {
1859
+ return Array.from(new Set(__spreadArray(__spreadArray(__spreadArray([], __read(cleanStringList(preflightGate.artifactPaths || preflightGate.artifact_paths, 60, 500)), false), __read(checks.flatMap(function (check) { return cleanStringList(check.artifactPaths || check.artifact_paths || check.artifacts, 20, 500); })), false), __read(checks.map(function (check) { return cleanText(check.artifactPath || check.artifact_path || check.path || check.file, 500); }).filter(Boolean)), false))).slice(0, 80);
1860
+ }
1861
+ function supportPreflightCheckMessage(check) {
1862
+ return cleanText(check.summary || check.message || check.error || check.reason || check.status, 1000);
1863
+ }
1864
+ function applySupportPreflightGateToQaEvidence(evidence, preflightGate) {
1865
+ var _a;
1866
+ var status = supportPreflightStatus(preflightGate.status);
1867
+ var failureClass = supportPreflightStatus(preflightGate.failureClass || preflightGate.failure_class);
1868
+ var failedChecks = supportPreflightFailedChecks(preflightGate);
1869
+ var artifactPaths = supportPreflightArtifactPaths(preflightGate, failedChecks);
1870
+ var compileResult = plainObject(preflightGate.compileResult || preflightGate.compile_result);
1871
+ var compileFailed = status === 'compile_failed'
1872
+ || failureClass === 'compile'
1873
+ || cleanText(compileResult.failureClass || compileResult.failure_class, 120).toLowerCase() === 'compile'
1874
+ || failedChecks.some(function (check) {
1875
+ var name = supportPreflightStatus(check.name || check.check || check.key);
1876
+ var checkClass = supportPreflightStatus(check.failureClass || check.failure_class);
1877
+ return name === 'compile' || checkClass === 'compile';
1878
+ });
1879
+ if (compileFailed) {
1880
+ var compileCheck = Object.keys(compileResult).length ? compileResult : failedChecks[0] || {};
1881
+ evidence.compile = __assign(__assign({}, plainObject(evidence.compile || evidence.build || evidence.buildResult || evidence.build_result)), { status: cleanText(compileCheck.status || preflightGate.status || 'fail', 80) || 'fail', command: cleanText(compileCheck.command || preflightGate.command || preflightGate.nextCommand || preflightGate.next_command, 500), artifactPath: artifactPaths[0] || cleanText(compileCheck.artifactPath || compileCheck.artifact_path || compileCheck.path, 500), message: supportPreflightCheckMessage(compileCheck) || cleanText(preflightGate.reason || ((_a = preflightGate.blockers) === null || _a === void 0 ? void 0 : _a[0]) || 'Support compile preflight failed before browser QA.', 1000), metadata: {
1882
+ source: 'supportV5PreflightGate',
1883
+ preflightStatus: status,
1884
+ preflightEvidenceHash: cleanText(preflightGate.evidenceHash || preflightGate.evidence_hash, 200),
1885
+ nextCommand: cleanText(preflightGate.nextCommand || preflightGate.next_command, 180)
1886
+ } });
1887
+ return;
1888
+ }
1889
+ var blocksRepair = preflightGate.blocksProductRepair === true || preflightGate.blocks_product_repair === true || /infra_failed|blocked|missing/.test(status);
1890
+ var checks = failedChecks.length
1891
+ ? failedChecks
1892
+ : Object.keys(preflightGate).length && (blocksRepair || status === 'passed')
1893
+ ? [{
1894
+ name: 'support_preflight',
1895
+ status: status === 'passed' ? 'pass' : 'blocked',
1896
+ summary: cleanStringList(preflightGate.blockers, 4, 500).join('; ') || cleanText(preflightGate.reason || preflightGate.status, 1000),
1897
+ artifactPaths: artifactPaths
1898
+ }]
1899
+ : [];
1900
+ if (!checks.length) {
1901
+ return;
1902
+ }
1903
+ evidence.infraChecks = __spreadArray(__spreadArray([], __read(asArray(evidence.infraChecks)), false), __read(checks.map(function (check) { return ({
1904
+ name: cleanText(check.name || check.check || check.key, 160) || 'support_preflight',
1905
+ status: cleanText(check.status || check.state || check.outcome || (status === 'passed' ? 'pass' : 'blocked'), 80),
1906
+ message: supportPreflightCheckMessage(check) || cleanStringList(preflightGate.blockers, 3, 500).join('; '),
1907
+ path: cleanText(check.path || check.artifactPath || check.artifact_path, 500) || artifactPaths[0],
1908
+ metadata: {
1909
+ source: 'supportV5PreflightGate',
1910
+ preflightStatus: status,
1911
+ preflightFailureClass: failureClass,
1912
+ preflightEvidenceHash: cleanText(preflightGate.evidenceHash || preflightGate.evidence_hash, 200),
1913
+ nextCommand: cleanText(preflightGate.nextCommand || preflightGate.next_command, 180)
1914
+ }
1915
+ }); })), false);
1916
+ }
1917
+ function supportPreflightGateResult(preflightGate, now) {
1918
+ if (!preflightGate || !Object.keys(preflightGate).length) {
1919
+ return undefined;
1920
+ }
1921
+ var statusText = supportPreflightStatus(preflightGate.status);
1922
+ var ready = preflightGate.ready === true;
1923
+ var blocksProductRepair = preflightGate.blocksProductRepair === true || preflightGate.blocks_product_repair === true;
1924
+ var failedChecks = supportPreflightFailedChecks(preflightGate);
1925
+ var artifactPaths = supportPreflightArtifactPaths(preflightGate, failedChecks);
1926
+ var gateStatus = ready || statusText === 'passed'
1927
+ ? 'pass'
1928
+ : /compile_failed|infra_failed|fail|failed/.test(statusText)
1929
+ ? 'fail'
1930
+ : blocksProductRepair || /missing|blocked/.test(statusText)
1931
+ ? 'blocked'
1932
+ : 'warn';
1933
+ var blockers = cleanStringList(preflightGate.blockers, 20, 500);
1934
+ return {
1935
+ key: 'support_preflight_gate',
1936
+ label: 'Support preflight gate',
1937
+ status: gateStatus,
1938
+ reason: gateStatus === 'pass'
1939
+ ? 'Support deterministic preflight passed before product-code repair.'
1940
+ : cleanText(blockers.join('; ') || preflightGate.reason || "Support deterministic preflight is ".concat(statusText || 'not ready', " before product-code repair."), 1200),
1941
+ evidenceRefs: artifactPaths,
1942
+ recordedAt: isoNow(now || preflightGate.recordedAt || preflightGate.recorded_at),
1943
+ metadata: {
1944
+ ready: ready,
1945
+ required: preflightGate.required === true,
1946
+ status: statusText,
1947
+ failureClass: cleanText(preflightGate.failureClass || preflightGate.failure_class, 120),
1948
+ nextCommand: cleanText(preflightGate.nextCommand || preflightGate.next_command, 180),
1949
+ blocksProductRepair: blocksProductRepair,
1950
+ blocksModelRepair: preflightGate.blocksModelRepair === true || preflightGate.blocks_model_repair === true,
1951
+ failedChecks: failedChecks.map(function (check) { return cleanText(check.name || check.check || check.key, 160); }).filter(Boolean),
1952
+ requiredEvidence: cleanStringList(preflightGate.requiredEvidence || preflightGate.required_evidence, 20, 500),
1953
+ evidenceHash: cleanText(preflightGate.evidenceHash || preflightGate.evidence_hash, 200)
1954
+ }
1955
+ };
1956
+ }
1957
+ function supportBusinessProofReadinessGate(readiness, now) {
1958
+ if (!readiness || !Object.keys(readiness).length) {
1959
+ return undefined;
1960
+ }
1961
+ var ready = readiness.ready === true;
1962
+ var readinessStatus = cleanText(readiness.status, 120).toLowerCase();
1963
+ var blockers = cleanStringList(readiness.blockers, 20, 500);
1964
+ var artifactPaths = cleanStringList(readiness.artifactPaths || readiness.artifact_paths, 40, 500);
1965
+ var proofFingerprint = cleanText(readiness.proofFingerprint || readiness.proof_fingerprint, 160);
1966
+ var artifactFingerprint = cleanText(readiness.artifactFingerprint || readiness.artifact_fingerprint, 160);
1967
+ var proofFreshness = cleanText(readiness.proofFreshness || readiness.proof_freshness, 120);
1968
+ var status = ready
1969
+ ? 'pass'
1970
+ : /fail|failed/.test(readinessStatus)
1971
+ ? 'fail'
1972
+ : /missing|route_only|blocked|weak|stale|incomplete/.test(readinessStatus)
1973
+ ? 'blocked'
1974
+ : 'warn';
1975
+ return {
1976
+ key: 'support_business_proof_readiness',
1977
+ label: 'Support business proof readiness',
1978
+ status: status,
1979
+ reason: cleanText(readiness.reason || blockers.join('; ') || readinessStatus || 'Support business proof readiness recorded.', 1200),
1980
+ evidenceRefs: artifactPaths,
1981
+ recordedAt: isoNow(now || readiness.recordedAt || readiness.recorded_at),
1982
+ metadata: {
1983
+ ready: ready,
1984
+ status: readinessStatus,
1985
+ blockers: blockers,
1986
+ requiredEvidence: cleanStringList(readiness.requiredEvidence || readiness.required_evidence, 20, 500),
1987
+ proofFingerprint: proofFingerprint,
1988
+ artifactFingerprint: artifactFingerprint,
1989
+ proofFreshness: proofFreshness
1990
+ }
1991
+ };
1992
+ }
1993
+ function supportCustomerReplyPolicyGate(policy, now) {
1994
+ if (!policy || !Object.keys(policy).length) {
1995
+ return undefined;
1996
+ }
1997
+ var action = cleanText(policy.action, 120);
1998
+ var safety = cleanText(policy.safety, 120);
1999
+ var reason = cleanText(policy.reason, 1200);
2000
+ var canDraft = policy.canDraftCustomerReply === true || policy.can_draft_customer_reply === true;
2001
+ var canSend = policy.canSendCustomerReply === true || policy.can_send_customer_reply === true;
2002
+ var reviewPacket = plainObject(policy.humanReviewPacket || policy.human_review_packet);
2003
+ var draftBasis = plainObject(policy.draftBasis || policy.draft_basis);
2004
+ var clarificationValidation = (0, support_runner_v5_1.validateResolveIOSupportClarificationContract)(policy.clarificationContract || policy.clarification_contract || {});
2005
+ var clarificationContract = clarificationValidation.normalized;
2006
+ var reviewType = cleanText(reviewPacket.reviewType || reviewPacket.review_type, 160);
2007
+ var evidenceRefs = cleanStringList(reviewPacket.evidenceRefs || reviewPacket.evidence_refs, 40, 500);
2008
+ var blockers = cleanStringList(policy.blockers || reviewPacket.blockers, 20, 500);
2009
+ var gateStatus = canSend
2010
+ ? 'blocked'
2011
+ : action === 'draft_resolution_reply' && canDraft
2012
+ ? 'warn'
2013
+ : action === 'ask_clarification' && canDraft
2014
+ ? (clarificationValidation.valid ? 'warn' : 'blocked')
2015
+ : 'blocked';
2016
+ var mergedBlockers = Array.from(new Set(__spreadArray(__spreadArray([], __read(blockers), false), __read((action === 'ask_clarification' ? clarificationValidation.blockers : [])), false)));
2017
+ return {
2018
+ key: 'support_customer_reply_policy',
2019
+ label: 'Support customer reply policy',
2020
+ status: gateStatus,
2021
+ reason: reason || mergedBlockers.join('; ') || action || 'Support customer reply policy recorded.',
2022
+ evidenceRefs: evidenceRefs,
2023
+ recordedAt: isoNow(now || policy.recordedAt || policy.recorded_at || reviewPacket.createdAt || reviewPacket.created_at),
2024
+ metadata: {
2025
+ action: action,
2026
+ safety: safety,
2027
+ canDraftCustomerReply: canDraft,
2028
+ canSendCustomerReply: canSend,
2029
+ confidenceLevel: cleanText(policy.confidenceLevel || policy.confidence_level, 120),
2030
+ issueClass: cleanText(draftBasis.issueClass || draftBasis.issue_class, 120),
2031
+ issueClassProbePlanId: cleanText(draftBasis.issueClassProbePlanId || draftBasis.issue_class_probe_plan_id, 180),
2032
+ issueClassProbePlanStatus: cleanText(draftBasis.issueClassProbePlanStatus || draftBasis.issue_class_probe_plan_status, 120),
2033
+ reviewType: reviewType,
2034
+ primaryAction: cleanText(reviewPacket.primaryAction || reviewPacket.primary_action, 160),
2035
+ requiresHumanApproval: reviewPacket.requiresHumanApproval !== false && reviewPacket.requires_human_approval !== false,
2036
+ questionPresent: !!cleanText(policy.clarificationQuestion || policy.clarification_question || reviewPacket.question, 1000),
2037
+ clarificationContractStatus: cleanText(clarificationContract.status, 120),
2038
+ clarificationMissingField: cleanText(clarificationContract.missingField, 120),
2039
+ clarificationOneQuestionOnly: clarificationContract.oneQuestionOnly === true,
2040
+ clarificationParksTicket: clarificationContract.parksTicketUntilCustomerReply === true,
2041
+ blockers: mergedBlockers
2042
+ }
2043
+ };
2044
+ }
2045
+ function supportCustomerReplyReadinessGate(contract, now) {
2046
+ if (!contract || !Object.keys(contract).length) {
2047
+ return undefined;
2048
+ }
2049
+ var validation = (0, support_runner_v5_1.validateResolveIOSupportCustomerReplyReadinessContract)(contract);
2050
+ var normalized = validation.normalized;
2051
+ var status = cleanText(normalized.status, 120);
2052
+ var gateStatus = normalized.canSendCustomerReply
2053
+ ? 'blocked'
2054
+ : validation.valid && (status === 'draft_ready' || status === 'clarification_required')
2055
+ ? 'warn'
2056
+ : 'blocked';
2057
+ return {
2058
+ key: 'support_customer_reply_readiness',
2059
+ label: 'Support customer reply readiness',
2060
+ status: gateStatus,
2061
+ reason: normalized.reason || validation.blockers.join('; ') || status || 'Support customer reply readiness recorded.',
2062
+ evidenceRefs: normalized.evidenceRefs,
2063
+ recordedAt: isoNow(now || normalized.createdAt),
2064
+ metadata: {
2065
+ contractId: normalized.contractId,
2066
+ status: status,
2067
+ policyAction: normalized.policyAction,
2068
+ reviewType: normalized.reviewType,
2069
+ primaryCommand: normalized.primaryCommand,
2070
+ canDraftCustomerReply: normalized.canDraftCustomerReply,
2071
+ canSendCustomerReply: normalized.canSendCustomerReply,
2072
+ requiresHumanApproval: normalized.requiresHumanApproval,
2073
+ proofBacked: normalized.proofBacked,
2074
+ businessProofReady: normalized.businessProofReady,
2075
+ releaseReady: normalized.releaseReady,
2076
+ diagnosisReady: normalized.diagnosisReady,
2077
+ issueClassProbePlanReady: normalized.issueClassProbePlanReady,
2078
+ clarificationRequired: normalized.clarificationRequired,
2079
+ blockers: Array.from(new Set(__spreadArray(__spreadArray([], __read(normalized.blockers), false), __read(validation.blockers), false))),
2080
+ requiredEvidence: normalized.requiredEvidence,
2081
+ nextCommands: normalized.nextCommands,
2082
+ forbiddenActions: normalized.forbiddenActions
2083
+ }
2084
+ };
2085
+ }
2086
+ function supportNextActionContractObject(ticket, job, evidence) {
2087
+ var ticketAutomation = plainObject(ticket.automation);
2088
+ var ticketManager = plainObject(ticketAutomation.manager || ticket.manager);
2089
+ var autonomousDecision = plainObject(job.supportV5AutonomousDecision
2090
+ || job.support_v5_autonomous_decision
2091
+ || evidence.supportV5AutonomousDecision
2092
+ || evidence.support_v5_autonomous_decision
2093
+ || ticket.supportV5AutonomousDecision
2094
+ || ticket.support_v5_autonomous_decision);
2095
+ return evidenceObject(autonomousDecision.nextActionContract, autonomousDecision.next_action_contract, job.supportV5NextActionContract, job.support_v5_next_action_contract, job.nextActionContract, job.next_action_contract, evidence.supportV5NextActionContract, evidence.support_v5_next_action_contract, evidence.nextActionContract, evidence.next_action_contract, ticket.supportV5NextActionContract, ticket.support_v5_next_action_contract, ticket.nextActionContract, ticket.next_action_contract, ticketManager.nextActionContract, ticketManager.next_action_contract);
2096
+ }
2097
+ function supportNextActionContractRequired(ticket, job, evidence) {
2098
+ var ticketAutomation = plainObject(ticket.automation);
2099
+ var ticketManager = plainObject(ticketAutomation.manager || ticket.manager);
2100
+ var workflowMarkers = [
2101
+ job.supportWorkflowMode,
2102
+ job.workflowMode,
2103
+ job.workflow_mode,
2104
+ job.supportWorkflowVersion,
2105
+ job.support_workflow_version,
2106
+ ticket.supportWorkflowMode,
2107
+ ticket.workflowMode,
2108
+ ticket.workflow_mode
2109
+ ].map(function (value) { return cleanText(value, 80).toLowerCase(); });
2110
+ return workflowMarkers.some(function (value) { return value === 'support_v5' || value === 'v5'; })
2111
+ || !!job.supportV5SupervisorState
2112
+ || !!job.supportV5MicrotaskLedger
2113
+ || !!job.supportV5StepHistory
2114
+ || !!job.supportV5DiagnosisGate
2115
+ || !!job.supportV5DiagnosisEvidencePack
2116
+ || !!job.support_v5_supervisor_state
2117
+ || !!job.support_v5_microtask_ledger
2118
+ || !!job.support_v5_step_history
2119
+ || !!job.support_v5_diagnosis_gate
2120
+ || !!job.support_v5_diagnosis_evidence_pack
2121
+ || !!job.supportRootCauseEntryContract
2122
+ || !!job.support_root_cause_entry_contract
2123
+ || !!evidence.supportV5AutonomousDecision
2124
+ || !!evidence.support_v5_autonomous_decision
2125
+ || !!evidence.rootCauseReadiness
2126
+ || !!evidence.root_cause_readiness
2127
+ || !!ticketManager.root_cause_entry_contract
2128
+ || !!ticketManager.rootCauseEntryContract
2129
+ || !!ticketManager.last_watchdog_decision;
2130
+ }
2131
+ function supportNextActionContractMetadata(contract) {
2132
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
2133
+ var decisionBasis = plainObject(contract.decisionBasis || contract.decision_basis);
2134
+ var costRisk = plainObject(contract.costRisk || contract.cost_risk);
2135
+ var source = {
2136
+ contractId: cleanText(contract.contractId || contract.contract_id, 200),
2137
+ action: cleanText(contract.action, 160),
2138
+ label: cleanText(contract.label, 300),
2139
+ primaryCommand: cleanText(contract.primaryCommand || contract.primary_command, 240),
2140
+ lane: cleanText(contract.lane, 120),
2141
+ stepType: cleanText(contract.stepType || contract.step_type, 120),
2142
+ safeToAutoRun: booleanFlag((_a = contract.safeToAutoRun) !== null && _a !== void 0 ? _a : contract.safe_to_auto_run),
2143
+ requiresHumanApproval: booleanFlag((_b = contract.requiresHumanApproval) !== null && _b !== void 0 ? _b : contract.requires_human_approval),
2144
+ canRunWithoutCodexMonitor: booleanFlag((_c = contract.canRunWithoutCodexMonitor) !== null && _c !== void 0 ? _c : contract.can_run_without_codex_monitor),
2145
+ codexFallbackRequired: booleanFlag((_d = contract.codexFallbackRequired) !== null && _d !== void 0 ? _d : contract.codex_fallback_required),
2146
+ codexFallbackReason: cleanText(contract.codexFallbackReason || contract.codex_fallback_reason, 1000),
2147
+ rootCauseFirstSatisfied: booleanFlag((_e = contract.rootCauseFirstSatisfied) !== null && _e !== void 0 ? _e : contract.root_cause_first_satisfied),
2148
+ preconditions: cleanStringList(contract.preconditions, 40, 500),
2149
+ expectedStateTransition: cleanText(contract.expectedStateTransition || contract.expected_state_transition, 1000),
2150
+ successEvidence: cleanStringList(contract.successEvidence || contract.success_evidence, 40, 500),
2151
+ stopConditions: cleanStringList(contract.stopConditions || contract.stop_conditions, 40, 500),
2152
+ forbiddenActions: cleanStringList(contract.forbiddenActions || contract.forbidden_actions, 40, 500),
2153
+ ownerFiles: cleanStringList(contract.ownerFiles || contract.owner_files || decisionBasis.ownerFiles || decisionBasis.owner_files, 40, 500),
2154
+ blockers: cleanStringList(contract.blockers, 40, 500),
2155
+ nextCommands: cleanStringList(contract.nextCommands || contract.next_commands, 40, 500),
2156
+ costRisk: {
2157
+ level: cleanText(costRisk.level || contract.costRiskLevel || contract.cost_risk_level, 80),
2158
+ estimatedUsd: numberValue((_h = (_g = (_f = costRisk.estimatedUsd) !== null && _f !== void 0 ? _f : costRisk.estimated_usd) !== null && _g !== void 0 ? _g : contract.estimatedUsd) !== null && _h !== void 0 ? _h : contract.estimated_usd),
2159
+ reason: cleanText(costRisk.reason, 800)
2160
+ },
2161
+ diagnosisValid: booleanFlag((_j = decisionBasis.diagnosisValid) !== null && _j !== void 0 ? _j : decisionBasis.diagnosis_valid),
2162
+ ownerFilesReady: booleanFlag((_k = decisionBasis.ownerFilesReady) !== null && _k !== void 0 ? _k : decisionBasis.owner_files_ready),
2163
+ proofPlanReady: booleanFlag((_l = decisionBasis.proofPlanReady) !== null && _l !== void 0 ? _l : decisionBasis.proof_plan_ready),
2164
+ businessProofReady: booleanFlag((_m = decisionBasis.businessProofReady) !== null && _m !== void 0 ? _m : decisionBasis.business_proof_ready),
2165
+ evidenceFreshnessStatus: cleanText(decisionBasis.evidenceFreshnessStatus || decisionBasis.evidence_freshness_status, 120),
2166
+ evidenceStrength: cleanText(decisionBasis.evidenceStrength || decisionBasis.evidence_strength, 120),
2167
+ failureClass: cleanText(decisionBasis.failureClass || decisionBasis.failure_class, 120),
2168
+ blockerFingerprint: cleanText(decisionBasis.blockerFingerprint || decisionBasis.blocker_fingerprint, 200),
2169
+ evidenceHash: cleanText(decisionBasis.evidenceHash || decisionBasis.evidence_hash, 200),
2170
+ sameFailureCount: numberValue((_o = decisionBasis.sameFailureCount) !== null && _o !== void 0 ? _o : decisionBasis.same_failure_count),
2171
+ preflightReady: booleanFlag((_p = decisionBasis.preflightReady) !== null && _p !== void 0 ? _p : decisionBasis.preflight_ready),
2172
+ preflightStatus: cleanText(decisionBasis.preflightStatus || decisionBasis.preflight_status, 120),
2173
+ preflightFailureClass: cleanText(decisionBasis.preflightFailureClass || decisionBasis.preflight_failure_class, 120),
2174
+ preflightEvidenceHash: cleanText(decisionBasis.preflightEvidenceHash || decisionBasis.preflight_evidence_hash, 200),
2175
+ hotfixCommitRequired: booleanFlag((_s = (_r = (_q = decisionBasis.hotfixCommitRequired) !== null && _q !== void 0 ? _q : decisionBasis.hotfix_commit_required) !== null && _r !== void 0 ? _r : contract.hotfixCommitRequired) !== null && _s !== void 0 ? _s : contract.hotfix_commit_required),
2176
+ liveHotfixBlockedUntilCommit: booleanFlag((_v = (_u = (_t = decisionBasis.liveHotfixBlockedUntilCommit) !== null && _t !== void 0 ? _t : decisionBasis.live_hotfix_blocked_until_commit) !== null && _u !== void 0 ? _u : contract.liveHotfixBlockedUntilCommit) !== null && _v !== void 0 ? _v : contract.live_hotfix_blocked_until_commit)
2177
+ };
2178
+ return source;
2179
+ }
2180
+ function supportNextActionContractGate(contract, now, required) {
2181
+ if (required === void 0) { required = false; }
2182
+ if (!contract || !Object.keys(contract).length) {
2183
+ if (!required) {
2184
+ return undefined;
2185
+ }
2186
+ var blocker = 'Support V5 run is missing a validated next-action contract, so the manager cannot prove one safe primary action without external Codex monitoring.';
2187
+ return {
2188
+ key: 'support_next_action_contract',
2189
+ label: 'Support next-action contract',
2190
+ status: 'blocked',
2191
+ reason: blocker,
2192
+ evidenceRefs: [],
2193
+ recordedAt: isoNow(now),
2194
+ metadata: {
2195
+ required: true,
2196
+ missingContract: true,
2197
+ safeToAutoRun: false,
2198
+ canRunWithoutCodexMonitor: false,
2199
+ codexFallbackRequired: true,
2200
+ codexFallbackReason: 'missing_support_next_action_contract',
2201
+ blockers: [blocker],
2202
+ missingSafetyFlags: ['safeToAutoRun', 'canRunWithoutCodexMonitor', 'codexFallbackRequired']
2203
+ }
2204
+ };
2205
+ }
2206
+ var metadata = supportNextActionContractMetadata(contract);
2207
+ var blockers = cleanStringList(metadata.blockers, 40, 500);
2208
+ if (metadata.safeToAutoRun === false) {
2209
+ blockers.push('Next action contract marks the action unsafe for autonomous run.');
2210
+ }
2211
+ if (metadata.canRunWithoutCodexMonitor === false) {
2212
+ blockers.push('Next action requires Codex fallback/monitoring instead of manager-only execution.');
2213
+ }
2214
+ if (metadata.codexFallbackRequired === true) {
2215
+ blockers.push(metadata.codexFallbackReason || 'Next action contract requires Codex fallback.');
2216
+ }
2217
+ if (metadata.requiresHumanApproval === true) {
2218
+ blockers.push('Next action contract requires human approval.');
2219
+ }
2220
+ if (metadata.liveHotfixBlockedUntilCommit === true) {
2221
+ blockers.push('Live hotfix is blocked until the manager records and pushes the GitHub commit proof.');
2222
+ }
2223
+ var missingSafetyFlags = [
2224
+ metadata.safeToAutoRun === undefined ? 'safeToAutoRun' : '',
2225
+ metadata.canRunWithoutCodexMonitor === undefined ? 'canRunWithoutCodexMonitor' : '',
2226
+ metadata.codexFallbackRequired === undefined ? 'codexFallbackRequired' : ''
2227
+ ].filter(Boolean);
2228
+ var status = blockers.length
2229
+ ? 'blocked'
2230
+ : missingSafetyFlags.length
2231
+ ? 'warn'
2232
+ : 'pass';
2233
+ var actionLabel = metadata.label || metadata.action || metadata.primaryCommand || 'support next action';
2234
+ return {
2235
+ key: 'support_next_action_contract',
2236
+ label: 'Support next-action contract',
2237
+ status: status,
2238
+ reason: blockers.length
2239
+ ? blockers.join(' ')
2240
+ : missingSafetyFlags.length
2241
+ ? "Support next-action contract is present for ".concat(actionLabel, ", but missing explicit safety flags: ").concat(missingSafetyFlags.join(', '), ".")
2242
+ : "Support next-action contract allows ".concat(actionLabel, " without Codex monitoring."),
2243
+ evidenceRefs: cleanStringList(__spreadArray(__spreadArray(__spreadArray([], __read(metadata.successEvidence), false), __read(metadata.preconditions), false), __read(metadata.stopConditions), false), 40, 500),
2244
+ recordedAt: isoNow(now || contract.createdAt || contract.created_at || contract.recordedAt || contract.recorded_at),
2245
+ metadata: __assign(__assign({}, metadata), { blockers: blockers, missingSafetyFlags: missingSafetyFlags })
2246
+ };
2247
+ }
2248
+ function supportDiagnosisEvidencePackObject(ticket, job, evidence) {
2249
+ var ticketAutomation = plainObject(ticket.automation);
2250
+ var ticketManager = plainObject(ticketAutomation.manager || ticket.manager);
2251
+ return evidenceObject(job.supportV5DiagnosisEvidencePack, job.support_v5_diagnosis_evidence_pack, job.diagnosisEvidencePack, job.diagnosis_evidence_pack, evidence.supportV5DiagnosisEvidencePack, evidence.support_v5_diagnosis_evidence_pack, evidence.diagnosisEvidencePack, evidence.diagnosis_evidence_pack, ticket.supportV5DiagnosisEvidencePack, ticket.support_v5_diagnosis_evidence_pack, ticket.diagnosisEvidencePack, ticket.diagnosis_evidence_pack, ticketManager.diagnosisEvidencePack, ticketManager.diagnosis_evidence_pack);
2252
+ }
2253
+ function supportIssueClassProbePlanObject(ticket, job, evidence) {
2254
+ var ticketAutomation = plainObject(ticket.automation);
2255
+ var ticketManager = plainObject(ticketAutomation.manager || ticket.manager);
2256
+ var autonomousDecision = plainObject(job.supportV5AutonomousDecision
2257
+ || job.support_v5_autonomous_decision
2258
+ || evidence.supportV5AutonomousDecision
2259
+ || evidence.support_v5_autonomous_decision
2260
+ || ticket.supportV5AutonomousDecision
2261
+ || ticket.support_v5_autonomous_decision);
2262
+ return evidenceObject(autonomousDecision.issueClassProbePlan, autonomousDecision.issue_class_probe_plan, job.supportV5IssueClassProbePlan, job.support_v5_issue_class_probe_plan, job.issueClassProbePlan, job.issue_class_probe_plan, evidence.supportV5IssueClassProbePlan, evidence.support_v5_issue_class_probe_plan, evidence.issueClassProbePlan, evidence.issue_class_probe_plan, ticket.supportV5IssueClassProbePlan, ticket.support_v5_issue_class_probe_plan, ticket.issueClassProbePlan, ticket.issue_class_probe_plan, ticketManager.issueClassProbePlan, ticketManager.issue_class_probe_plan);
2263
+ }
2264
+ function supportSimilarFixHintsObject(ticket, job, evidence) {
2265
+ var ticketAutomation = plainObject(ticket.automation);
2266
+ var ticketManager = plainObject(ticketAutomation.manager || ticket.manager);
2267
+ return evidenceObject(job.supportRootCauseSimilarFixHints, job.support_root_cause_similar_fix_hints, job.similarFixHints, job.similar_fix_hints, evidence.supportRootCauseSimilarFixHints, evidence.support_root_cause_similar_fix_hints, evidence.similarFixHints, evidence.similar_fix_hints, ticket.supportRootCauseSimilarFixHints, ticket.support_root_cause_similar_fix_hints, ticketManager.rootCauseSimilarFixHints, ticketManager.root_cause_similar_fix_hints);
2268
+ }
2269
+ function supportDiagnosisEvidencePackGate(pack, now) {
2270
+ if (!pack || !Object.keys(pack).length) {
2271
+ return undefined;
2272
+ }
2273
+ var statusText = cleanText(pack.status, 120);
2274
+ var diagnosisValid = pack.diagnosisValid === true || pack.diagnosis_valid === true;
2275
+ var validationBlockers = cleanStringList(pack.validationBlockers || pack.validation_blockers, 40, 500);
2276
+ var similarSelection = plainObject(pack.similarCaseSelection || pack.similar_case_selection);
2277
+ var rankedHints = asArray(similarSelection.ranked);
2278
+ var gateStatus = diagnosisValid || statusText === 'diagnosis_ready'
2279
+ ? 'pass'
2280
+ : statusText === 'blocked'
2281
+ ? 'blocked'
2282
+ : 'warn';
2283
+ return {
2284
+ key: 'support_diagnosis_evidence_pack',
2285
+ label: 'Support diagnosis evidence pack',
2286
+ status: gateStatus,
2287
+ reason: gateStatus === 'pass'
2288
+ ? 'Support diagnosis evidence pack has a valid root-cause diagnosis and advisory similar-fix context.'
2289
+ : validationBlockers.join('; ') || 'Support diagnosis evidence pack requires read-only root-cause evidence before repair.',
2290
+ evidenceRefs: cleanStringList(pack.requiredEvidence || pack.required_evidence, 30, 500),
2291
+ recordedAt: isoNow(now || pack.generatedAt || pack.generated_at),
2292
+ metadata: {
2293
+ packId: cleanText(pack.packId || pack.pack_id, 180),
2294
+ status: statusText,
2295
+ readOnly: pack.readOnly !== false && pack.read_only !== false,
2296
+ sourceEditsAllowed: pack.sourceEditsAllowed === true || pack.source_edits_allowed === true,
2297
+ rootCauseFirstRequired: pack.rootCauseFirstRequired !== false && pack.root_cause_first_required !== false,
2298
+ requiredOutputKey: cleanText(pack.requiredOutputKey || pack.required_output_key, 120),
2299
+ requiredFields: cleanStringList(pack.requiredFields || pack.required_fields, 20, 160),
2300
+ forbiddenActions: cleanStringList(pack.forbiddenActions || pack.forbidden_actions, 20, 500),
2301
+ diagnosisValid: diagnosisValid,
2302
+ diagnosisStatus: cleanText(pack.diagnosisStatus || pack.diagnosis_status, 120),
2303
+ validationBlockers: validationBlockers,
2304
+ issueClassHint: cleanText(pack.issueClassHint || pack.issue_class_hint, 120),
2305
+ ownerFileHints: cleanStringList(pack.ownerFileHints || pack.owner_file_hints, 20, 500),
2306
+ similarHintCount: rankedHints.length,
2307
+ similarHintsAdvisoryOnly: true,
2308
+ issueClassProbeCount: asArray(pack.issueClassProbeCatalog || pack.issue_class_probe_catalog).length
2309
+ }
2310
+ };
2311
+ }
2312
+ function supportIssueClassProbePlanGate(plan, diagnosisGate, now, required) {
2313
+ if (required === void 0) { required = false; }
2314
+ if (!plan || !Object.keys(plan).length) {
2315
+ if (!required) {
2316
+ return undefined;
2317
+ }
2318
+ var blocker = 'Support V5 run is missing IssueClassProbePlan, so business proof cannot be accepted from route-only or generic QA.';
2319
+ return {
2320
+ key: 'support_issue_class_probe_plan',
2321
+ label: 'Support issue-class probe plan',
2322
+ status: 'blocked',
2323
+ reason: blocker,
2324
+ evidenceRefs: [],
2325
+ recordedAt: isoNow(now),
2326
+ metadata: {
2327
+ required: true,
2328
+ missingPlan: true,
2329
+ issueClassProbePlanReady: false,
2330
+ acceptanceGate: 'aiqa_business_assertion',
2331
+ blockers: [blocker],
2332
+ falsePassBlockers: ['route load only', 'generic clickthrough only', 'scorecard-only pass']
2333
+ }
2334
+ };
2335
+ }
2336
+ var validation = (0, support_runner_v5_1.validateResolveIOSupportIssueClassProbePlan)(plan, diagnosisGate, now);
2337
+ var normalized = plainObject(validation.normalized || plan);
2338
+ var activeProbe = plainObject(validation.activeProbe || normalized.activeProbe || normalized.active_probe);
2339
+ var blockers = cleanStringList(validation.blockers || normalized.blockers, 40, 500);
2340
+ var requiredArtifacts = cleanStringList(normalized.requiredArtifacts
2341
+ || normalized.required_artifacts
2342
+ || activeProbe.required_artifacts, 30, 500);
2343
+ var falsePassBlockers = cleanStringList(normalized.falsePassBlockers
2344
+ || normalized.false_pass_blockers
2345
+ || activeProbe.false_pass_blockers, 30, 500);
2346
+ var status = validation.valid ? 'pass' : 'blocked';
2347
+ var issueClass = cleanText(normalized.issue_class || normalized.issueClass || activeProbe.issue_class, 120);
2348
+ var route = cleanText(activeProbe.route, 500);
2349
+ var action = cleanText(activeProbe.action, 1000);
2350
+ return {
2351
+ key: 'support_issue_class_probe_plan',
2352
+ label: 'Support issue-class probe plan',
2353
+ status: status,
2354
+ reason: validation.valid
2355
+ ? "Support issue-class probe plan is ready for ".concat(issueClass || 'the diagnosed issue', " and requires AIQaBusinessAssertion proof.")
2356
+ : blockers.join('; ') || 'Support issue-class probe plan is incomplete.',
2357
+ evidenceRefs: requiredArtifacts,
2358
+ recordedAt: isoNow(now || normalized.generatedAt || normalized.generated_at),
2359
+ metadata: {
2360
+ planId: cleanText(normalized.planId || normalized.plan_id, 180),
2361
+ status: cleanText(validation.status || normalized.status, 120),
2362
+ issueClass: issueClass,
2363
+ diagnosisValid: normalized.diagnosisValid === true || normalized.diagnosis_valid === true,
2364
+ issueClassProbePlanReady: validation.valid === true && validation.status === 'ready',
2365
+ activeRoute: route,
2366
+ action: action,
2367
+ expectedEvidence: cleanText(activeProbe.expected_evidence || activeProbe.expectedEvidence, 1200),
2368
+ expectedBusinessProof: cleanText(activeProbe.expected_business_proof || activeProbe.expectedBusinessProof, 1200),
2369
+ acceptanceGate: cleanText(normalized.acceptanceGate || normalized.acceptance_gate || activeProbe.acceptance_gate, 120),
2370
+ requiredArtifacts: requiredArtifacts,
2371
+ falsePassBlockers: falsePassBlockers,
2372
+ blockers: blockers,
2373
+ activeProbe: {
2374
+ issueClass: issueClass,
2375
+ route: route,
2376
+ action: action,
2377
+ probeType: cleanText(activeProbe.probe_type || activeProbe.probeType, 120),
2378
+ failureClass: cleanText(activeProbe.failure_class || activeProbe.failureClass, 120),
2379
+ blocksAcceptanceWithoutBusinessAssertion: activeProbe.blocks_acceptance_without_business_assertion === true
2380
+ || activeProbe.blocksAcceptanceWithoutBusinessAssertion === true
2381
+ }
2382
+ }
2383
+ };
2384
+ }
2385
+ function firstNonEmptyText(values, max) {
2386
+ var e_30, _a;
2387
+ if (max === void 0) { max = 1000; }
2388
+ try {
2389
+ for (var values_3 = __values(values), values_3_1 = values_3.next(); !values_3_1.done; values_3_1 = values_3.next()) {
2390
+ var value = values_3_1.value;
2391
+ var normalized = idText(value, max);
2392
+ if (normalized) {
2393
+ return normalized;
2394
+ }
2395
+ }
2396
+ }
2397
+ catch (e_30_1) { e_30 = { error: e_30_1 }; }
2398
+ finally {
2399
+ try {
2400
+ if (values_3_1 && !values_3_1.done && (_a = values_3.return)) _a.call(values_3);
2401
+ }
2402
+ finally { if (e_30) throw e_30.error; }
2403
+ }
2404
+ return undefined;
2405
+ }
2406
+ function booleanFlag(value) {
2407
+ if (value === true || value === false) {
2408
+ return value;
2409
+ }
2410
+ if (typeof value === 'string') {
2411
+ var normalized = value.trim().toLowerCase();
2412
+ if (/^(true|yes|1|passed|pass|ready|safe)$/.test(normalized)) {
2413
+ return true;
2414
+ }
2415
+ if (/^(false|no|0|failed|fail|blocked|unsafe)$/.test(normalized)) {
2416
+ return false;
2417
+ }
2418
+ }
2419
+ return undefined;
2420
+ }
2421
+ function numberValue(value) {
2422
+ var parsed = Number(value);
2423
+ return Number.isFinite(parsed) ? parsed : undefined;
2424
+ }
2425
+ function buildAICoderQaEvidence(input) {
2426
+ var _a, _b, _c;
2427
+ var app = input.app || {};
2428
+ var job = input.job || {};
2429
+ var workflowMemory = plainObject(job.aiCoderV6WorkflowMemory
2430
+ || job.ai_coder_v6_workflow_memory
2431
+ || app.aiCoderV6WorkflowMemory
2432
+ || app.ai_coder_v6_workflow_memory);
2433
+ var evidence = mergeEvidenceRecords(job.qaEvidence, job.qa_evidence, app.qaEvidence, app.qa_evidence, input.qaEvidence);
2434
+ evidence.workflowQaRows = __spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(asArray(workflowMemory.workflowQaRows)), false), __read(asArray(workflowMemory.workflow_qa_rows)), false), __read(asArray(job.workflowQaRows)), false), __read(asArray(job.workflow_qa_rows)), false), __read(asArray(app.workflowQaRows)), false), __read(asArray(app.workflow_qa_rows)), false), __read(asArray(evidence.workflowQaRows)), false), __read(asArray(evidence.workflow_qa_rows)), false);
2435
+ evidence.businessAssertions = __spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(asArray(job.aiQaBusinessAssertions)), false), __read(asArray(job.ai_qa_business_assertions)), false), __read(asArray(job.businessAssertions)), false), __read(asArray(job.business_assertions)), false), __read(asArray(app.businessAssertions)), false), __read(asArray(app.business_assertions)), false), __read(asArray(evidence.businessAssertions)), false), __read(asArray(evidence.business_assertions)), false);
2436
+ evidence.routeProbes = __spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(asArray(job.workflowProbes)), false), __read(asArray(job.workflow_probes)), false), __read(asArray(evidence.routeProbes)), false), __read(asArray(evidence.route_probes)), false);
2437
+ evidence.artifactPaths = __spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(asArray(workflowMemory.businessProofArtifacts)), false), __read(asArray(workflowMemory.business_proof_artifacts)), false), __read(asArray(job.artifactPaths)), false), __read(asArray(job.artifact_paths)), false), __read(asArray(app.artifactPaths)), false), __read(asArray(app.artifact_paths)), false), __read(asArray(evidence.artifactPaths)), false), __read(asArray(evidence.artifact_paths)), false);
2438
+ evidence.journeyContract = evidence.journeyContract
2439
+ || evidence.journey_contract
2440
+ || job.journeyContract
2441
+ || job.journey_contract
2442
+ || app.journeyContract
2443
+ || app.journey_contract
2444
+ || workflowMemory.journeyContract
2445
+ || workflowMemory.journey_contract;
2446
+ evidence.journeyContractMarkdown = evidence.journeyContractMarkdown
2447
+ || evidence.journey_contract_markdown
2448
+ || job.journeyContractMarkdown
2449
+ || job.journey_contract_markdown
2450
+ || app.journeyContractMarkdown
2451
+ || app.journey_contract_markdown;
2452
+ evidence.journeyContractPath = firstNonEmptyText([
2453
+ evidence.journeyContractPath,
2454
+ evidence.journey_contract_path,
2455
+ workflowMemory.journeyContractPath,
2456
+ workflowMemory.journey_contract_path,
2457
+ job.journeyContractPath,
2458
+ job.journey_contract_path,
2459
+ app.journeyContractPath,
2460
+ app.journey_contract_path
2461
+ ], 500) || 'docs/APP_JOURNEY_CONTRACT.md';
2462
+ evidence.deployStatus = firstNonEmptyText([
2463
+ evidence.deployStatus,
2464
+ evidence.deploy_status,
2465
+ job.deployStatus,
2466
+ job.deploy_status,
2467
+ job.testDeployStatus,
2468
+ job.test_deploy_status,
2469
+ app.deployStatus,
2470
+ app.deploy_status
2471
+ ], 160);
2472
+ evidence.publishStatus = firstNonEmptyText([
2473
+ evidence.publishStatus,
2474
+ evidence.publish_status,
2475
+ evidence.pullRequestStatus,
2476
+ evidence.pull_request_status,
2477
+ job.publishStatus,
2478
+ job.publish_status,
2479
+ job.pullRequestStatus,
2480
+ job.pull_request_status,
2481
+ app.publishStatus,
2482
+ app.publish_status
2483
+ ], 160);
2484
+ evidence.sampleDataStatus = firstNonEmptyText([
2485
+ evidence.sampleDataStatus,
2486
+ evidence.sample_data_status,
2487
+ job.sampleDataStatus,
2488
+ job.sample_data_status,
2489
+ app.sampleDataStatus,
2490
+ app.sample_data_status
2491
+ ], 160) || statusFromBoolean((_c = (_b = (_a = evidence.sampleDataReady) !== null && _a !== void 0 ? _a : evidence.hasSampleData) !== null && _b !== void 0 ? _b : job.sampleDataReady) !== null && _c !== void 0 ? _c : app.sampleDataReady);
2492
+ return evidence;
2493
+ }
2494
+ function normalizeAICoderWorkflowProofReadiness(value, now) {
2495
+ if (!value || !Object.keys(value).length) {
2496
+ return undefined;
2497
+ }
2498
+ var ready = value.ready === true;
2499
+ var status = cleanText(value.status, 120) || (ready ? 'ready' : 'blocked');
2500
+ return {
2501
+ ready: ready,
2502
+ status: status,
2503
+ reason: cleanText(value.reason || value.summary || status, 1200),
2504
+ blockers: cleanStringList(value.blockers, 40, 500),
2505
+ journeyContractValid: value.journeyContractValid === true || value.journey_contract_valid === true,
2506
+ primaryWorkflowId: cleanText(value.primaryWorkflowId || value.primary_workflow_id, 200),
2507
+ passedWorkflowRows: cleanStringList(value.passedWorkflowRows || value.passed_workflow_rows, 80, 300),
2508
+ missingWorkflowRows: cleanStringList(value.missingWorkflowRows || value.missing_workflow_rows, 80, 300),
2509
+ failedWorkflowRows: cleanStringList(value.failedWorkflowRows || value.failed_workflow_rows, 80, 300),
2510
+ passedBusinessAssertions: cleanStringList(value.passedBusinessAssertions || value.passed_business_assertions, 80, 500),
2511
+ routeOnly: value.routeOnly === true || value.route_only === true,
2512
+ scorecardOnly: value.scorecardOnly === true || value.scorecard_only === true,
2513
+ sampleDataReady: value.sampleDataReady === true || value.sample_data_ready === true,
2514
+ releaseBlockers: cleanStringList(value.releaseBlockers || value.release_blockers, 40, 500),
2515
+ artifactPaths: cleanStringList(value.artifactPaths || value.artifact_paths, 80, 500),
2516
+ workflowProofFingerprint: cleanText(value.workflowProofFingerprint || value.workflow_proof_fingerprint, 200),
2517
+ artifactFingerprint: cleanText(value.artifactFingerprint || value.artifact_fingerprint, 200),
2518
+ proofFreshness: cleanText(value.proofFreshness || value.proof_freshness, 80),
2519
+ nextAction: cleanText(value.nextAction || value.next_action, 1000),
2520
+ evaluatedAt: isoNow(now || value.evaluatedAt || value.evaluated_at || value.recordedAt || value.recorded_at)
2521
+ };
2522
+ }
2523
+ function aicoderJourneyContractValidationFromEvidence(evidence) {
2524
+ var journeyInput = evidence.journeyContract !== undefined && evidence.journeyContract !== null
2525
+ ? evidence.journeyContract
2526
+ : evidence.journeyContractMarkdown;
2527
+ var hasJourneyInput = journeyInput !== undefined && journeyInput !== null && cleanText(journeyInput, 100).length > 0;
2528
+ if (!hasJourneyInput) {
2529
+ return {
2530
+ valid: false,
2531
+ contract: null,
2532
+ issues: [{
2533
+ code: 'missing_contract',
2534
+ path: cleanText(evidence.journeyContractPath, 500) || 'docs/APP_JOURNEY_CONTRACT.md',
2535
+ message: 'docs/APP_JOURNEY_CONTRACT.md with structured journey_contract JSON is required before AICoder build, workflow QA, wow UI, publish, or acceptance.',
2536
+ severity: 'error'
2537
+ }],
2538
+ workflowQaRows: [],
2539
+ primaryWorkflowId: ''
2540
+ };
2541
+ }
2542
+ return (0, aicoder_runner_v6_1.validateResolveIOAICoderJourneyContract)(journeyInput, {
2543
+ requireMarkdownEnvelope: typeof journeyInput === 'string'
2544
+ });
2545
+ }
2546
+ function aicoderJourneyContractGate(validation, evidence, now) {
2547
+ var errorIssues = validation.issues.filter(function (issue) { return issue.severity === 'error'; });
2548
+ var warningIssues = validation.issues.filter(function (issue) { return issue.severity === 'warning'; });
2549
+ var status = validation.valid
2550
+ ? (warningIssues.length ? 'warn' : 'pass')
2551
+ : 'blocked';
2552
+ var path = cleanText(evidence.journeyContractPath, 500) || 'docs/APP_JOURNEY_CONTRACT.md';
2553
+ return {
2554
+ key: 'aicoder_journey_contract',
2555
+ label: 'AICoder journey contract',
2556
+ status: status,
2557
+ reason: validation.valid
2558
+ ? (warningIssues.length
2559
+ ? "Journey contract is valid with warnings: ".concat(warningIssues.map(function (issue) { return issue.message; }).slice(0, 3).join(' | '))
2560
+ : 'Journey contract validates first/next/last workflow, data story, completion states, and QA assertions.')
2561
+ : (errorIssues.map(function (issue) { return issue.message; }).slice(0, 5).join(' | ') || 'AICoder Journey Contract is missing or invalid.'),
2562
+ evidenceRefs: [path],
2563
+ recordedAt: isoNow(now),
2564
+ metadata: {
2565
+ path: path,
2566
+ valid: validation.valid,
2567
+ primaryWorkflowId: cleanText(validation.primaryWorkflowId, 200),
2568
+ workflowQaRowCount: validation.workflowQaRows.length,
2569
+ workflowQaCoverageTags: cleanStringList(validation.workflowQaRows.flatMap(function (row) { return asArray(row.coverageTags || row.coverage_tags); }), 80, 120),
2570
+ workflowQaProofKinds: cleanStringList(validation.workflowQaRows.map(function (row) { return row.proofKind || row.proof_kind; }), 80, 120),
2571
+ errorCount: errorIssues.length,
2572
+ warningCount: warningIssues.length,
2573
+ issueCodes: cleanStringList(validation.issues.map(function (issue) { return issue.code; }), 40, 120),
2574
+ issues: validation.issues.slice(0, 20).map(function (issue) { return ({
2575
+ code: cleanText(issue.code, 120),
2576
+ path: cleanText(issue.path, 500),
2577
+ severity: issue.severity,
2578
+ message: cleanText(issue.message, 800)
2579
+ }); }),
2580
+ blocksBuildUntilValid: !validation.valid,
2581
+ blocksWorkflowQaUntilValid: !validation.valid,
2582
+ blocksWowUiUntilWorkflowProof: !validation.valid,
2583
+ blocksPublishUntilWorkflowProof: !validation.valid,
2584
+ nextAction: validation.valid
2585
+ ? 'Generate workflow QA rows from journey_contract.qa_assertions and execute the north-star workflow.'
2586
+ : 'Generate or repair docs/APP_JOURNEY_CONTRACT.md before app build, wow UI, publish, or acceptance.'
2587
+ }
2588
+ };
2589
+ }
2590
+ function aicoderWorkflowProofReadinessGate(readiness, now) {
2591
+ var status = readiness.ready
2592
+ ? 'pass'
2593
+ : readiness.status === 'release_blocked' || readiness.status === 'journey_invalid' || readiness.status === 'sample_data_missing'
2594
+ ? 'fail'
2595
+ : 'blocked';
2596
+ return {
2597
+ key: 'aicoder_workflow_proof_readiness',
2598
+ label: 'AICoder workflow proof readiness',
2599
+ status: status,
2600
+ reason: readiness.reason || readiness.blockers.join('; ') || readiness.status,
2601
+ evidenceRefs: readiness.artifactPaths,
2602
+ recordedAt: isoNow(now || readiness.evaluatedAt),
2603
+ metadata: {
2604
+ ready: readiness.ready,
2605
+ status: readiness.status,
2606
+ primaryWorkflowId: readiness.primaryWorkflowId,
2607
+ journeyContractValid: readiness.journeyContractValid,
2608
+ blockers: readiness.blockers,
2609
+ passedWorkflowRows: readiness.passedWorkflowRows,
2610
+ missingWorkflowRows: readiness.missingWorkflowRows,
2611
+ failedWorkflowRows: readiness.failedWorkflowRows,
2612
+ passedBusinessAssertions: readiness.passedBusinessAssertions,
2613
+ routeOnly: readiness.routeOnly,
2614
+ scorecardOnly: readiness.scorecardOnly,
2615
+ sampleDataReady: readiness.sampleDataReady,
2616
+ releaseBlockers: readiness.releaseBlockers,
2617
+ workflowProofFingerprint: readiness.workflowProofFingerprint,
2618
+ artifactFingerprint: readiness.artifactFingerprint,
2619
+ proofFreshness: readiness.proofFreshness,
2620
+ nextAction: readiness.nextAction
2621
+ }
2622
+ };
2623
+ }
2624
+ function aicoderWorkflowProofCheckpointObject(app, job, evidence) {
2625
+ var workflowMemory = plainObject(job.aiCoderV6WorkflowMemory
2626
+ || job.ai_coder_v6_workflow_memory
2627
+ || app.aiCoderV6WorkflowMemory
2628
+ || app.ai_coder_v6_workflow_memory
2629
+ || evidence.aiCoderV6WorkflowMemory
2630
+ || evidence.ai_coder_v6_workflow_memory);
2631
+ var continuationDecision = plainObject(job.aicoderV6ContinuationDecision
2632
+ || job.aiCoderV6ContinuationDecision
2633
+ || job.aicoder_v6_continuation_decision
2634
+ || job.ai_coder_v6_continuation_decision
2635
+ || app.aicoderV6ContinuationDecision
2636
+ || app.aiCoderV6ContinuationDecision
2637
+ || app.aicoder_v6_continuation_decision
2638
+ || evidence.aicoderV6ContinuationDecision
2639
+ || evidence.aiCoderV6ContinuationDecision
2640
+ || evidence.aicoder_v6_continuation_decision);
2641
+ return evidenceObject(continuationDecision.workflowProofCheckpoint, continuationDecision.workflow_proof_checkpoint, workflowMemory.workflowProofCheckpoint, workflowMemory.workflow_proof_checkpoint, job.workflowProofCheckpoint, job.workflow_proof_checkpoint, job.aicoderWorkflowProofCheckpoint, job.aicoder_workflow_proof_checkpoint, app.workflowProofCheckpoint, app.workflow_proof_checkpoint, evidence.workflowProofCheckpoint, evidence.workflow_proof_checkpoint, evidence.aicoderWorkflowProofCheckpoint, evidence.aicoder_workflow_proof_checkpoint);
2642
+ }
2643
+ function aicoderWorkflowProofCheckpointGate(checkpoint, now) {
2644
+ var _a, _b, _c, _d, _e;
2645
+ if (!checkpoint || !Object.keys(checkpoint).length) {
2646
+ return undefined;
2647
+ }
2648
+ var blocksProductRepairUntilJourneyContract = booleanFlag((_a = checkpoint.blocksProductRepairUntilJourneyContract) !== null && _a !== void 0 ? _a : checkpoint.blocks_product_repair_until_journey_contract) === true;
2649
+ var blocksPublishUntilWorkflowProof = booleanFlag((_b = checkpoint.blocksPublishUntilWorkflowProof) !== null && _b !== void 0 ? _b : checkpoint.blocks_publish_until_workflow_proof) === true;
2650
+ var blocksPublishUntilReleaseGate = booleanFlag((_c = checkpoint.blocksPublishUntilReleaseGate) !== null && _c !== void 0 ? _c : checkpoint.blocks_publish_until_release_gate) === true;
2651
+ var blocksWowUiUntilWorkflowProof = booleanFlag((_d = checkpoint.blocksWowUiUntilWorkflowProof) !== null && _d !== void 0 ? _d : checkpoint.blocks_wow_ui_until_workflow_proof) === true;
2652
+ var statusText = cleanText(checkpoint.status, 120);
2653
+ var required = booleanFlag(checkpoint.required) !== false;
2654
+ var blockers = cleanStringList(checkpoint.blockers, 40, 500);
2655
+ if (blocksProductRepairUntilJourneyContract) {
2656
+ blockers.push('Product repair is blocked until the journey contract is valid.');
2657
+ }
2658
+ if (blocksPublishUntilWorkflowProof) {
2659
+ blockers.push('Publish is blocked until workflow business proof passes.');
2660
+ }
2661
+ if (blocksPublishUntilReleaseGate) {
2662
+ blockers.push('Publish is blocked until release gate evidence passes.');
2663
+ }
2664
+ if (blocksWowUiUntilWorkflowProof) {
2665
+ blockers.push('Wow UI polish is blocked until workflow proof exists.');
2666
+ }
2667
+ var gateStatus = !required || statusText === 'ready_to_continue'
2668
+ ? 'pass'
2669
+ : blockers.length
2670
+ ? 'blocked'
2671
+ : 'warn';
2672
+ return {
2673
+ key: 'aicoder_workflow_proof_checkpoint',
2674
+ label: 'AICoder workflow proof checkpoint',
2675
+ status: gateStatus,
2676
+ reason: gateStatus === 'pass'
2677
+ ? 'AICoder workflow checkpoint allows the next action.'
2678
+ : (blockers.join(' ') || cleanText(checkpoint.nextAction || checkpoint.next_action || statusText, 1200) || 'AICoder workflow checkpoint requires more proof before continuing.'),
2679
+ evidenceRefs: cleanStringList(__spreadArray(__spreadArray([], __read(asArray(checkpoint.requiredEvidence || checkpoint.required_evidence)), false), __read(asArray(checkpoint.requiredResetEvidence || checkpoint.required_reset_evidence)), false), 40, 500),
2680
+ recordedAt: isoNow(now || checkpoint.recordedAt || checkpoint.recorded_at || checkpoint.createdAt || checkpoint.created_at),
2681
+ metadata: {
2682
+ required: required,
2683
+ status: statusText,
2684
+ readinessStatus: cleanText(checkpoint.readinessStatus || checkpoint.readiness_status, 120),
2685
+ nextGate: cleanText(checkpoint.nextGate || checkpoint.next_gate, 120),
2686
+ nextAction: cleanText(checkpoint.nextAction || checkpoint.next_action, 1000),
2687
+ startingFailureClass: cleanText(checkpoint.startingFailureClass || checkpoint.starting_failure_class, 120),
2688
+ startingBlockerFingerprint: cleanText(checkpoint.startingBlockerFingerprint || checkpoint.starting_blocker_fingerprint, 200),
2689
+ startingEvidenceHash: cleanText(checkpoint.startingEvidenceHash || checkpoint.starting_evidence_hash, 200),
2690
+ workflowProofFingerprint: cleanText(checkpoint.workflowProofFingerprint || checkpoint.workflow_proof_fingerprint, 200),
2691
+ artifactFingerprint: cleanText(checkpoint.artifactFingerprint || checkpoint.artifact_fingerprint, 200),
2692
+ requiredEvidence: cleanStringList(checkpoint.requiredEvidence || checkpoint.required_evidence, 40, 500),
2693
+ requiredResetEvidence: cleanStringList(checkpoint.requiredResetEvidence || checkpoint.required_reset_evidence, 40, 500),
2694
+ successRequiresWorkflowBusinessProof: booleanFlag((_e = checkpoint.successRequiresWorkflowBusinessProof) !== null && _e !== void 0 ? _e : checkpoint.success_requires_workflow_business_proof) === true,
2695
+ blocksProductRepairUntilJourneyContract: blocksProductRepairUntilJourneyContract,
2696
+ blocksPublishUntilWorkflowProof: blocksPublishUntilWorkflowProof,
2697
+ blocksPublishUntilReleaseGate: blocksPublishUntilReleaseGate,
2698
+ blocksWowUiUntilWorkflowProof: blocksWowUiUntilWorkflowProof,
2699
+ blockers: blockers
2700
+ }
2701
+ };
2702
+ }
2703
+ function aicoderNextActionContractObject(app, job, evidence) {
2704
+ var continuationDecision = plainObject(job.aicoderV6ContinuationDecision
2705
+ || job.aiCoderV6ContinuationDecision
2706
+ || job.aicoder_v6_continuation_decision
2707
+ || job.ai_coder_v6_continuation_decision
2708
+ || app.aicoderV6ContinuationDecision
2709
+ || app.aiCoderV6ContinuationDecision
2710
+ || app.aicoder_v6_continuation_decision
2711
+ || evidence.aicoderV6ContinuationDecision
2712
+ || evidence.aiCoderV6ContinuationDecision
2713
+ || evidence.aicoder_v6_continuation_decision);
2714
+ return evidenceObject(continuationDecision.nextActionContract, continuationDecision.next_action_contract, job.nextActionContract, job.next_action_contract, job.aicoderNextActionContract, job.aicoder_next_action_contract, job.aiCoderNextActionContract, job.ai_coder_next_action_contract, app.nextActionContract, app.next_action_contract, evidence.nextActionContract, evidence.next_action_contract, evidence.aicoderNextActionContract, evidence.aicoder_next_action_contract);
2715
+ }
2716
+ function aicoderNextActionContractGate(contract, now) {
2717
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
2718
+ if (!contract || !Object.keys(contract).length) {
2719
+ return undefined;
2720
+ }
2721
+ var safeToAutoRun = booleanFlag((_a = contract.safeToAutoRun) !== null && _a !== void 0 ? _a : contract.safe_to_auto_run) === true;
2722
+ var requiresHumanApproval = booleanFlag((_b = contract.requiresHumanApproval) !== null && _b !== void 0 ? _b : contract.requires_human_approval) === true;
2723
+ var canRunWithoutCodexMonitor = booleanFlag((_c = contract.canRunWithoutCodexMonitor) !== null && _c !== void 0 ? _c : contract.can_run_without_codex_monitor) === true;
2724
+ var codexFallbackRequired = booleanFlag((_d = contract.codexFallbackRequired) !== null && _d !== void 0 ? _d : contract.codex_fallback_required) === true;
2725
+ var sourceBlockers = cleanStringList(contract.blockers, 40, 500);
2726
+ var primaryCommand = cleanText(contract.primaryCommand || contract.primary_command, 200);
2727
+ var liveHotfixBlockedUntilCommit = booleanFlag((_g = (_f = (_e = contract.liveHotfixBlockedUntilCommit) !== null && _e !== void 0 ? _e : contract.live_hotfix_blocked_until_commit) !== null && _f !== void 0 ? _f : plainObject(contract.decisionBasis || contract.decision_basis).liveHotfixBlockedUntilCommit) !== null && _g !== void 0 ? _g : plainObject(contract.decisionBasis || contract.decision_basis).live_hotfix_blocked_until_commit) === true;
2728
+ var safetyBlockers = Array.from(new Set(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read((safeToAutoRun ? [] : ['AICoder next action is not marked safe to auto-run.'])), false), __read((canRunWithoutCodexMonitor ? [] : ['AICoder next action requires Codex fallback/monitoring instead of manager-only execution.'])), false), __read((codexFallbackRequired ? [cleanText(contract.codexFallbackReason || contract.codex_fallback_reason, 1000) || 'AICoder next action contract requires Codex fallback.'] : [])), false), __read((requiresHumanApproval ? ['AICoder next action requires human approval.'] : [])), false), __read((liveHotfixBlockedUntilCommit ? ['Live AICoder hotfix is blocked until GitHub commit and push proof is recorded.'] : [])), false))).filter(Boolean).slice(0, 40);
2729
+ var contractBlockers = safetyBlockers.length
2730
+ ? Array.from(new Set(__spreadArray(__spreadArray([], __read(sourceBlockers), false), __read(safetyBlockers), false))).slice(0, 40)
2731
+ : [];
2732
+ var missingSafetyFlags = [
2733
+ contract.safeToAutoRun === undefined && contract.safe_to_auto_run === undefined ? 'safeToAutoRun' : '',
2734
+ contract.canRunWithoutCodexMonitor === undefined && contract.can_run_without_codex_monitor === undefined ? 'canRunWithoutCodexMonitor' : '',
2735
+ contract.codexFallbackRequired === undefined && contract.codex_fallback_required === undefined ? 'codexFallbackRequired' : ''
2736
+ ].filter(Boolean);
2737
+ var gateStatus = contractBlockers.length
2738
+ ? 'blocked'
2739
+ : missingSafetyFlags.length
2740
+ ? 'warn'
2741
+ : 'pass';
2742
+ return {
2743
+ key: 'aicoder_next_action_contract',
2744
+ label: 'AICoder next action contract',
2745
+ status: gateStatus,
2746
+ reason: gateStatus === 'pass'
2747
+ ? "AICoder can run ".concat(primaryCommand || 'the next action', " without a Codex monitor.")
2748
+ : (contractBlockers.join(' ') || cleanText(contract.codexFallbackReason || contract.codex_fallback_reason || contract.expectedStateTransition || contract.expected_state_transition, 1200) || 'AICoder next action is not safe to run unattended.'),
2749
+ evidenceRefs: cleanStringList(__spreadArray(__spreadArray(__spreadArray([], __read(asArray(contract.preconditions)), false), __read(asArray(contract.successEvidence || contract.success_evidence)), false), __read(asArray(contract.stopConditions || contract.stop_conditions)), false), 40, 500),
2750
+ recordedAt: isoNow(now || contract.createdAt || contract.created_at || contract.recordedAt || contract.recorded_at),
2751
+ metadata: {
2752
+ contractId: cleanText(contract.contractId || contract.contract_id, 200),
2753
+ action: cleanText(contract.action, 120),
2754
+ label: cleanText(contract.label, 200),
2755
+ primaryCommand: primaryCommand,
2756
+ lane: cleanText(contract.lane, 120),
2757
+ stepType: cleanText(contract.stepType || contract.step_type, 120),
2758
+ safeToAutoRun: safeToAutoRun,
2759
+ requiresHumanApproval: requiresHumanApproval,
2760
+ canRunWithoutCodexMonitor: canRunWithoutCodexMonitor,
2761
+ codexFallbackRequired: codexFallbackRequired,
2762
+ codexFallbackReason: cleanText(contract.codexFallbackReason || contract.codex_fallback_reason, 1000),
2763
+ costRisk: cleanText(contract.costRisk || contract.cost_risk, 120),
2764
+ workflowFirstSatisfied: booleanFlag((_h = contract.workflowFirstSatisfied) !== null && _h !== void 0 ? _h : contract.workflow_first_satisfied) === true,
2765
+ hotfixCommitRequired: booleanFlag((_l = (_k = (_j = contract.hotfixCommitRequired) !== null && _j !== void 0 ? _j : contract.hotfix_commit_required) !== null && _k !== void 0 ? _k : plainObject(contract.decisionBasis || contract.decision_basis).hotfixCommitRequired) !== null && _l !== void 0 ? _l : plainObject(contract.decisionBasis || contract.decision_basis).hotfix_commit_required) === true,
2766
+ liveHotfixBlockedUntilCommit: liveHotfixBlockedUntilCommit,
2767
+ decisionBasis: plainObject(contract.decisionBasis || contract.decision_basis),
2768
+ preconditions: cleanStringList(contract.preconditions, 40, 500),
2769
+ expectedStateTransition: cleanText(contract.expectedStateTransition || contract.expected_state_transition, 1000),
2770
+ successEvidence: cleanStringList(contract.successEvidence || contract.success_evidence, 40, 500),
2771
+ requiredHotfixCommitProof: cleanStringList(contract.requiredHotfixCommitProof || contract.required_hotfix_commit_proof, 20, 240),
2772
+ stopConditions: cleanStringList(contract.stopConditions || contract.stop_conditions, 40, 500),
2773
+ forbiddenActions: cleanStringList(contract.forbiddenActions || contract.forbidden_actions, 40, 500),
2774
+ nextCommands: cleanStringList(contract.nextCommands || contract.next_commands, 40, 240),
2775
+ blockers: contractBlockers,
2776
+ contextBlockers: sourceBlockers,
2777
+ safetyBlockers: safetyBlockers,
2778
+ missingSafetyFlags: missingSafetyFlags,
2779
+ ownerFiles: cleanStringList(contract.ownerFiles || contract.owner_files, 40, 500)
2780
+ }
2781
+ };
2782
+ }
2783
+ function adapterStatusPassed(value) {
2784
+ var normalized = cleanText(value, 120).toLowerCase();
2785
+ return !!normalized && /(pass|passed|success|succeeded|ok|done|complete|completed|ready|saved|published|deployed)/i.test(normalized);
2786
+ }
2787
+ function applyAICoderWorkflowProofGate(qa, readiness, now) {
2788
+ if (readiness.ready
2789
+ || readiness.status === 'release_blocked'
2790
+ || qa.outcome === 'infra_failed'
2791
+ || qa.outcome === 'compile_failed'
2792
+ || qa.outcome === 'route_failed'
2793
+ || qa.outcome === 'business_assertion_failed') {
2794
+ return qa;
2795
+ }
2796
+ var gate = aicoderWorkflowProofReadinessGate(readiness, now);
2797
+ return __assign(__assign({}, qa), { outcome: qa.routeProbes.some(function (probe) { return adapterStatusPassed(probe.status); })
2798
+ ? 'route_only_pass'
2799
+ : 'incomplete', gateResults: __spreadArray(__spreadArray([], __read(qa.gateResults.filter(function (existing) { return !(existing.key === 'qa_business_assertion' && existing.status === 'pass'); })), false), [
2800
+ gate
2801
+ ], false) });
2802
+ }
2803
+ function assistantQualityObject(input) {
2804
+ var _a, _b;
2805
+ var conversation = input.conversation || {};
2806
+ var latestAssistantMessage = __spreadArray([], __read(asArray(input.messages)), false).reverse()
2807
+ .find(function (message) { return /assistant/i.test(cleanText(message.role || message.authorRole || message.type, 80)); });
2808
+ return plainObject(input.answerQuality
2809
+ || conversation.answerQuality
2810
+ || conversation.answer_quality
2811
+ || conversation.assistantAnswerQuality
2812
+ || conversation.assistant_answer_quality
2813
+ || (latestAssistantMessage === null || latestAssistantMessage === void 0 ? void 0 : latestAssistantMessage.answerQuality)
2814
+ || (latestAssistantMessage === null || latestAssistantMessage === void 0 ? void 0 : latestAssistantMessage.answer_quality)
2815
+ || ((_a = latestAssistantMessage === null || latestAssistantMessage === void 0 ? void 0 : latestAssistantMessage.metadata) === null || _a === void 0 ? void 0 : _a.answerQuality)
2816
+ || ((_b = latestAssistantMessage === null || latestAssistantMessage === void 0 ? void 0 : latestAssistantMessage.metadata) === null || _b === void 0 ? void 0 : _b.answer_quality));
2817
+ }
2818
+ function assistantConfidenceLevel(value) {
2819
+ var normalized = cleanText((value === null || value === void 0 ? void 0 : value.level) || (value === null || value === void 0 ? void 0 : value.confidenceLevel) || (value === null || value === void 0 ? void 0 : value.confidence_level) || value, 80).toLowerCase();
2820
+ if (/^high$/.test(normalized)) {
2821
+ return 'high';
2822
+ }
2823
+ if (/^medium$/.test(normalized)) {
2824
+ return 'medium';
2825
+ }
2826
+ if (/^low$/.test(normalized)) {
2827
+ return 'low';
2828
+ }
2829
+ return 'unknown';
2830
+ }
2831
+ function assistantQueryStatus(value) {
2832
+ var normalized = cleanText((value === null || value === void 0 ? void 0 : value.status) || (value === null || value === void 0 ? void 0 : value.queryStatus) || (value === null || value === void 0 ? void 0 : value.query_status) || value, 120).toLowerCase().replace(/[\s-]+/g, '_');
2833
+ if (/^(ok|success|answered|data_found|data)$/.test(normalized)) {
2834
+ return 'ok';
2835
+ }
2836
+ if (/^(no_data|no_results|empty|not_found)$/.test(normalized)) {
2837
+ return 'no_data';
2838
+ }
2839
+ if (/^(query_error|mongo_error|error|failed)$/.test(normalized)) {
2840
+ return 'query_error';
2841
+ }
2842
+ if (/^(permission_error|permission_denied|forbidden|unauthorized)$/.test(normalized)) {
2843
+ return 'permission_error';
2844
+ }
2845
+ return 'unknown';
2846
+ }
2847
+ function asObjectList(value) {
2848
+ return asArray(value).filter(function (entry) { return entry && typeof entry === 'object' && !Array.isArray(entry); });
2849
+ }
2850
+ function assistantEvidenceRefs(quality) {
2851
+ return cleanStringList(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(asArray(quality.evidenceRefs)), false), __read(asArray(quality.evidence_refs)), false), __read(asArray(quality.citationRefs)), false), __read(asArray(quality.citation_refs)), false), __read(asArray(quality.artifactPaths)), false), __read(asArray(quality.artifact_paths)), false), __read(asObjectList(quality.citations).map(function (citation) { return citation.path || citation.url || citation.id || citation.ref; })), false), __read(asObjectList(quality.evidence).map(function (entry) { return entry.path || entry.url || entry.id || entry.ref; })), false), 80, 500);
2852
+ }
2853
+ function assistantCitationRefs(quality) {
2854
+ return cleanStringList(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(asArray(quality.citationRefs)), false), __read(asArray(quality.citation_refs)), false), __read(asObjectList(quality.citations).map(function (citation) { return citation.path || citation.url || citation.id || citation.ref; })), false), __read(asObjectList(quality.evidence).map(function (entry) { return entry.citation || entry.ref || entry.path || entry.url; })), false), 80, 500);
2855
+ }
2856
+ function assistantQueryExecutions(quality) {
2857
+ var queryExecution = plainObject(quality.queryExecution || quality.query_execution);
2858
+ var toolResult = plainObject(quality.toolResult || quality.tool_result);
2859
+ return __spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(asObjectList(quality.queryExecutions)), false), __read(asObjectList(quality.query_executions)), false), __read(asObjectList(quality.dataQueries)), false), __read(asObjectList(quality.data_queries)), false), __read(asObjectList(quality.toolResults)), false), __read(asObjectList(quality.tool_results)), false), __read(asObjectList(quality.mongoReads)), false), __read(asObjectList(quality.mongo_reads)), false), __read(asObjectList(quality.mongoAggregations)), false), __read(asObjectList(quality.mongo_aggregations)), false), __read((Object.keys(queryExecution).length ? [queryExecution] : [])), false), __read((Object.keys(toolResult).length ? [toolResult] : [])), false).filter(function (entry) { return Object.keys(entry).length; });
2860
+ }
2861
+ function assistantQueryEvidenceRefs(quality, executions) {
2862
+ if (executions === void 0) { executions = assistantQueryExecutions(quality); }
2863
+ return cleanStringList(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(asArray(quality.queryEvidenceRefs)), false), __read(asArray(quality.query_evidence_refs)), false), __read(asArray(quality.toolResultRefs)), false), __read(asArray(quality.tool_result_refs)), false), __read(asArray(quality.queryResultRefs)), false), __read(asArray(quality.query_result_refs)), false), __read(executions.map(function (execution) {
2864
+ return execution.id
2865
+ || execution._id
2866
+ || execution.ref
2867
+ || execution.toolResultId
2868
+ || execution.tool_result_id
2869
+ || execution.toolCallId
2870
+ || execution.tool_call_id
2871
+ || execution.artifactPath
2872
+ || execution.artifact_path
2873
+ || execution.path
2874
+ || execution.url;
2875
+ })), false), 80, 500);
2876
+ }
2877
+ function assistantNextActions(quality) {
2878
+ return cleanStringList(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(asArray(quality.nextActions)), false), __read(asArray(quality.next_actions)), false), __read(asArray(quality.recommendedActions)), false), __read(asArray(quality.recommended_actions)), false), 20, 500);
2879
+ }
2880
+ function normalizedIsoDay(value) {
2881
+ if (!value) {
2882
+ return '';
2883
+ }
2884
+ var date = value instanceof Date ? value : new Date(value);
2885
+ if (!Number.isFinite(date.getTime())) {
2886
+ return cleanText(value, 40).slice(0, 10);
2887
+ }
2888
+ return date.toISOString().slice(0, 10);
2889
+ }
2890
+ function assistantDateWindowObject(quality) {
2891
+ var _a, _b, _c;
2892
+ var dateWindow = plainObject(quality.dateWindow || quality.date_window);
2893
+ var nestedWindow = plainObject(((_b = (_a = quality.verification) === null || _a === void 0 ? void 0 : _a.metrics) === null || _b === void 0 ? void 0 : _b.window) || ((_c = quality.metrics) === null || _c === void 0 ? void 0 : _c.window));
2894
+ return Object.keys(dateWindow).length ? dateWindow : nestedWindow;
2895
+ }
2896
+ function collectMongoProjectionObjects(value, result) {
2897
+ var e_31, _a;
2898
+ if (result === void 0) { result = []; }
2899
+ if (!value || typeof value !== 'object') {
2900
+ return result;
2901
+ }
2902
+ if (Array.isArray(value)) {
2903
+ try {
2904
+ for (var value_3 = __values(value), value_3_1 = value_3.next(); !value_3_1.done; value_3_1 = value_3.next()) {
2905
+ var entry = value_3_1.value;
2906
+ collectMongoProjectionObjects(entry, result);
2907
+ }
2908
+ }
2909
+ catch (e_31_1) { e_31 = { error: e_31_1 }; }
2910
+ finally {
2911
+ try {
2912
+ if (value_3_1 && !value_3_1.done && (_a = value_3.return)) _a.call(value_3);
2913
+ }
2914
+ finally { if (e_31) throw e_31.error; }
2915
+ }
2916
+ return result;
2917
+ }
2918
+ if (value.projection && typeof value.projection === 'object' && !Array.isArray(value.projection)) {
2919
+ result.push(value.projection);
2920
+ }
2921
+ if (value.options && typeof value.options === 'object' && !Array.isArray(value.options) && value.options.projection) {
2922
+ collectMongoProjectionObjects({ projection: value.options.projection }, result);
2923
+ }
2924
+ if (value.query && typeof value.query === 'object') {
2925
+ collectMongoProjectionObjects(value.query, result);
2926
+ }
2927
+ if (value.mongoQuery && typeof value.mongoQuery === 'object') {
2928
+ collectMongoProjectionObjects(value.mongoQuery, result);
2929
+ }
2930
+ if (value.mongo_query && typeof value.mongo_query === 'object') {
2931
+ collectMongoProjectionObjects(value.mongo_query, result);
2932
+ }
2933
+ return result;
2934
+ }
2935
+ function projectionHasPositionalOperator(projection) {
2936
+ return Object.keys(projection || {}).some(function (key) { return /\.(?:\$|\$\[)|\.\$$/.test(key); });
2937
+ }
2938
+ function assistantQueryShapeLegal(quality) {
2939
+ if (quality.legalQueryShape === true || quality.legal_query_shape === true) {
2940
+ return true;
2941
+ }
2942
+ if (quality.legalQueryShape === false || quality.legal_query_shape === false || quality.illegalQueryShape === true || quality.illegal_query_shape === true) {
2943
+ return false;
2944
+ }
2945
+ var queryShape = plainObject(quality.queryShape || quality.query_shape);
2946
+ if (queryShape.legal === true || queryShape.status === 'pass') {
2947
+ return true;
2948
+ }
2949
+ if (queryShape.legal === false || queryShape.status === 'fail') {
2950
+ return false;
2951
+ }
2952
+ var projections = collectMongoProjectionObjects(quality);
2953
+ if (projections.some(projectionHasPositionalOperator)) {
2954
+ return false;
2955
+ }
2956
+ return true;
2957
+ }
2958
+ function assistantCorrectnessFailed(checks) {
2959
+ return checks
2960
+ .filter(function (check) {
2961
+ var status = cleanText(check.status || (check.passed === true ? 'pass' : check.passed === false ? 'fail' : ''), 80).toLowerCase();
2962
+ return /^(fail|failed|blocked|incorrect|wrong|error)$/.test(status);
2963
+ })
2964
+ .map(function (check) { return cleanText(check.assertion || check.name || check.case || check.reason || 'assistant correctness check failed', 300); })
2965
+ .slice(0, 20);
2966
+ }
2967
+ function evaluateAssistantAnswerQuality(input) {
2968
+ var _a, _b;
2969
+ if (input === void 0) { input = {}; }
2970
+ var quality = plainObject(input.answerQuality);
2971
+ var now = isoNow(input.now);
2972
+ var correctnessChecks = asArray(input.correctnessChecks);
2973
+ var failedChecks = assistantCorrectnessFailed(correctnessChecks);
2974
+ var queryStatus = assistantQueryStatus(quality.queryStatus || quality.query_status || quality.queryResult || quality.query_result);
2975
+ var confidenceLevel = assistantConfidenceLevel(quality.confidence || quality.confidenceLevel || quality.confidence_level);
2976
+ var evidenceRefs = assistantEvidenceRefs(quality);
2977
+ var citationRefs = assistantCitationRefs(quality);
2978
+ var queryExecutions = assistantQueryExecutions(quality);
2979
+ var queryEvidenceRefs = assistantQueryEvidenceRefs(quality, queryExecutions);
2980
+ var nextActions = assistantNextActions(quality);
2981
+ var requiresCurrentDate = quality.requiresCurrentDate === true || quality.requires_current_date === true;
2982
+ var dateWindowRequired = quality.requiresDateWindow === true
2983
+ || quality.requires_date_window === true
2984
+ || quality.dateWindowRequired === true
2985
+ || quality.date_window_required === true;
2986
+ var requiresCitations = quality.requiresCitations !== false && quality.requires_citations !== false;
2987
+ var requiresNextAction = quality.requiresNextAction !== false && quality.requires_next_action !== false;
2988
+ var dateWindow = assistantDateWindowObject(quality);
2989
+ var dateWindowStart = cleanText(dateWindow.startDate || dateWindow.start_date || dateWindow.start, 80);
2990
+ var dateWindowEnd = cleanText(dateWindow.endDate || dateWindow.end_date || dateWindow.end, 80);
2991
+ var dateWindowPresent = !!dateWindowStart && !!dateWindowEnd;
2992
+ var dateBasis = cleanText(quality.currentDateUsed
2993
+ || quality.current_date_used
2994
+ || quality.dateBasis
2995
+ || quality.date_basis
2996
+ || ((_a = quality.dateWindow) === null || _a === void 0 ? void 0 : _a.basisDate)
2997
+ || ((_b = quality.date_window) === null || _b === void 0 ? void 0 : _b.basis_date), 80);
2998
+ var expectedCurrentDate = cleanText(quality.expectedCurrentDate || quality.expected_current_date, 80)
2999
+ || normalizedIsoDay(input.now);
3000
+ var noDataConfirmed = quality.noDataConfirmed === true
3001
+ || quality.no_data_confirmed === true
3002
+ || quality.confirmedNoData === true
3003
+ || quality.confirmed_no_data === true;
3004
+ var legalQueryShape = assistantQueryShapeLegal(quality);
3005
+ var queryEvidenceRequired = quality.requiresQueryEvidence !== false
3006
+ && quality.requires_query_evidence !== false
3007
+ && (queryStatus === 'ok' || queryStatus === 'no_data');
3008
+ var queryEvidencePresent = queryExecutions.length > 0 || queryEvidenceRefs.length > 0;
3009
+ var blockers = [];
3010
+ var status = 'ready';
3011
+ var reason = 'Assistant answer has structured data evidence, legal query shape, citations, confidence, and next action.';
3012
+ if (!Object.keys(quality).length) {
3013
+ status = 'missing_data_source';
3014
+ blockers.push('Assistant answerQuality evidence is missing.');
3015
+ reason = 'Assistant answer cannot be accepted without structured answerQuality evidence.';
3016
+ }
3017
+ else if (failedChecks.length) {
3018
+ status = 'incorrect';
3019
+ blockers.push.apply(blockers, __spreadArray([], __read(failedChecks), false));
3020
+ reason = 'Assistant correctness checks failed.';
3021
+ }
3022
+ else if (queryStatus === 'permission_error') {
3023
+ status = 'permission_error';
3024
+ blockers.push('Assistant data query was blocked by permission or authorization.');
3025
+ reason = 'Assistant must report permission-error state and avoid claiming no data or success.';
3026
+ }
3027
+ else if (queryStatus === 'query_error') {
3028
+ status = 'query_error';
3029
+ blockers.push('Assistant data query failed.');
3030
+ reason = 'Assistant must report query-error state and avoid claiming no data or success.';
3031
+ }
3032
+ else if (!legalQueryShape) {
3033
+ status = 'illegal_query_shape';
3034
+ blockers.push('Assistant query shape is illegal or uses an unsafe Mongo projection shape.');
3035
+ reason = 'Assistant must use legal Mongo query/projection shapes before answering.';
3036
+ }
3037
+ else if (requiresCurrentDate && (!dateBasis || normalizedIsoDay(dateBasis) !== normalizedIsoDay(expectedCurrentDate))) {
3038
+ status = 'date_incorrect';
3039
+ blockers.push("Expected current date ".concat(normalizedIsoDay(expectedCurrentDate) || expectedCurrentDate, ", got ").concat(dateBasis || 'missing date basis', "."));
3040
+ reason = 'Assistant answer did not prove it used the actual current date.';
3041
+ }
3042
+ else if (dateWindowRequired && !dateWindowPresent) {
3043
+ status = 'missing_date_window';
3044
+ blockers.push('Assistant dated answer did not record concrete date-window start and end evidence.');
3045
+ reason = 'Assistant dated answers must record the exact query date window used.';
3046
+ }
3047
+ else if (queryStatus === 'unknown') {
3048
+ status = 'missing_data_source';
3049
+ blockers.push('Assistant answer did not record queryStatus ok/no_data/query_error/permission_error.');
3050
+ reason = 'Assistant answer must classify data access result before acceptance.';
3051
+ }
3052
+ else if (queryStatus === 'no_data' && !noDataConfirmed) {
3053
+ status = 'no_data_unverified';
3054
+ blockers.push('No-data answer was not confirmed by a probe or query evidence.');
3055
+ reason = 'Assistant no-data answers require explicit noDataConfirmed evidence.';
3056
+ }
3057
+ else if (queryEvidenceRequired && !queryEvidencePresent) {
3058
+ status = 'missing_query_proof';
3059
+ blockers.push('Assistant data answer did not record a structured query execution, tool result, or query evidence reference.');
3060
+ reason = 'Assistant answers from system data require structured query/tool execution proof before acceptance.';
3061
+ }
3062
+ else if (requiresCitations && !citationRefs.length && !evidenceRefs.length) {
3063
+ status = 'missing_citations';
3064
+ blockers.push('Assistant answer has no cited evidence or artifact reference.');
3065
+ reason = 'Assistant answer must cite system data evidence.';
3066
+ }
3067
+ else if (confidenceLevel === 'low' || confidenceLevel === 'unknown') {
3068
+ status = 'low_confidence';
3069
+ blockers.push('Assistant answer confidence is low or unknown.');
3070
+ reason = 'Assistant answer requires recorded medium/high confidence.';
3071
+ }
3072
+ else if (requiresNextAction && !nextActions.length) {
3073
+ status = 'missing_next_action';
3074
+ blockers.push('Assistant answer did not record next actions.');
3075
+ reason = 'Assistant answer must provide a next action or explicit no-action state.';
3076
+ }
3077
+ return {
3078
+ ready: status === 'ready',
3079
+ status: status,
3080
+ reason: reason,
3081
+ blockers: blockers,
3082
+ queryStatus: queryStatus,
3083
+ confidenceLevel: confidenceLevel,
3084
+ dateBasis: dateBasis || undefined,
3085
+ expectedCurrentDate: expectedCurrentDate || undefined,
3086
+ dateWindowRequired: dateWindowRequired,
3087
+ dateWindowPresent: dateWindowPresent,
3088
+ dateWindow: dateWindowPresent ? {
3089
+ startDate: dateWindowStart,
3090
+ endDate: dateWindowEnd,
3091
+ mode: cleanText(dateWindow.mode || dateWindow.type, 80) || undefined,
3092
+ months: typeof dateWindow.months === 'number' ? dateWindow.months : undefined
3093
+ } : undefined,
3094
+ noDataConfirmed: noDataConfirmed,
3095
+ legalQueryShape: legalQueryShape,
3096
+ citationRefs: citationRefs,
3097
+ queryEvidenceRequired: queryEvidenceRequired,
3098
+ queryEvidencePresent: queryEvidencePresent,
3099
+ queryEvidenceRefs: queryEvidenceRefs,
3100
+ queryExecutionCount: queryExecutions.length,
3101
+ nextActions: nextActions,
3102
+ evidenceRefs: evidenceRefs,
3103
+ failedChecks: failedChecks,
3104
+ recordedAt: now
3105
+ };
3106
+ }
3107
+ function assistantAnswerQualityGate(decision, now) {
3108
+ var status = decision.ready
3109
+ ? 'pass'
3110
+ : /incorrect|date_incorrect|missing_date_window|illegal_query_shape/.test(decision.status)
3111
+ ? 'fail'
3112
+ : 'blocked';
3113
+ return {
3114
+ key: 'assistant_answer_quality',
3115
+ label: 'Assistant answer quality',
3116
+ status: status,
3117
+ reason: decision.reason,
3118
+ evidenceRefs: decision.evidenceRefs.length ? decision.evidenceRefs : decision.citationRefs,
3119
+ recordedAt: isoNow(now || decision.recordedAt),
3120
+ metadata: {
3121
+ ready: decision.ready,
3122
+ status: decision.status,
3123
+ queryStatus: decision.queryStatus,
3124
+ confidenceLevel: decision.confidenceLevel,
3125
+ dateBasis: decision.dateBasis,
3126
+ expectedCurrentDate: decision.expectedCurrentDate,
3127
+ dateWindowRequired: decision.dateWindowRequired,
3128
+ dateWindowPresent: decision.dateWindowPresent,
3129
+ dateWindow: decision.dateWindow,
3130
+ noDataConfirmed: decision.noDataConfirmed,
3131
+ legalQueryShape: decision.legalQueryShape,
3132
+ citationRefs: decision.citationRefs,
3133
+ queryEvidenceRequired: decision.queryEvidenceRequired,
3134
+ queryEvidencePresent: decision.queryEvidencePresent,
3135
+ queryEvidenceRefs: decision.queryEvidenceRefs,
3136
+ queryExecutionCount: decision.queryExecutionCount,
3137
+ nextActions: decision.nextActions,
3138
+ blockers: decision.blockers,
3139
+ failedChecks: decision.failedChecks
3140
+ }
3141
+ };
3142
+ }
3143
+ function assistantActionabilityStatus(decision) {
3144
+ switch (decision.status) {
3145
+ case 'ready':
3146
+ return 'ready_to_answer';
3147
+ case 'query_error':
3148
+ return 'needs_query_repair';
3149
+ case 'permission_error':
3150
+ return 'needs_permission';
3151
+ case 'no_data_unverified':
3152
+ return 'needs_no_data_verification';
3153
+ case 'date_incorrect':
3154
+ case 'missing_date_window':
3155
+ return 'needs_date_window_repair';
3156
+ case 'illegal_query_shape':
3157
+ return 'needs_query_shape_repair';
3158
+ case 'missing_data_source':
3159
+ case 'missing_query_proof':
3160
+ case 'missing_citations':
3161
+ return 'needs_evidence';
3162
+ case 'low_confidence':
3163
+ return 'needs_confidence_review';
3164
+ case 'missing_next_action':
3165
+ return 'needs_next_action';
3166
+ case 'incorrect':
3167
+ return 'incorrect';
3168
+ default:
3169
+ return 'blocked';
3170
+ }
3171
+ }
3172
+ function assistantActionabilityCommand(status) {
3173
+ switch (status) {
3174
+ case 'ready_to_answer':
3175
+ return 'answer_from_verified_system_data';
3176
+ case 'needs_query_repair':
3177
+ return 'repair_assistant_query_and_rerun';
3178
+ case 'needs_permission':
3179
+ return 'request_assistant_data_permission';
3180
+ case 'needs_no_data_verification':
3181
+ return 'verify_no_data_with_scoped_probe';
3182
+ case 'needs_date_window_repair':
3183
+ return 'repair_assistant_date_window_and_rerun';
3184
+ case 'needs_query_shape_repair':
3185
+ return 'repair_assistant_mongo_query_shape';
3186
+ case 'needs_confidence_review':
3187
+ return 'review_assistant_confidence_evidence';
3188
+ case 'needs_next_action':
3189
+ return 'add_assistant_next_action';
3190
+ case 'incorrect':
3191
+ return 'repair_assistant_answer_from_failed_check';
3192
+ case 'needs_evidence':
3193
+ case 'blocked':
3194
+ default:
3195
+ return 'collect_assistant_answer_evidence';
3196
+ }
3197
+ }
3198
+ function assistantActionabilityLabel(status) {
3199
+ switch (status) {
3200
+ case 'ready_to_answer':
3201
+ return 'Answer From Verified Data';
3202
+ case 'needs_query_repair':
3203
+ return 'Repair Query';
3204
+ case 'needs_permission':
3205
+ return 'Request Data Permission';
3206
+ case 'needs_no_data_verification':
3207
+ return 'Verify No Data';
3208
+ case 'needs_date_window_repair':
3209
+ return 'Repair Date Window';
3210
+ case 'needs_query_shape_repair':
3211
+ return 'Repair Query Shape';
3212
+ case 'needs_confidence_review':
3213
+ return 'Review Confidence';
3214
+ case 'needs_next_action':
3215
+ return 'Add Next Action';
3216
+ case 'incorrect':
3217
+ return 'Repair Incorrect Answer';
3218
+ default:
3219
+ return 'Collect Answer Evidence';
3220
+ }
3221
+ }
3222
+ function buildAssistantAnswerActionabilityContract(decision, now) {
3223
+ var status = assistantActionabilityStatus(decision);
3224
+ var primaryCommand = assistantActionabilityCommand(status);
3225
+ var ready = status === 'ready_to_answer';
3226
+ var noDataReady = ready && decision.queryStatus === 'no_data' && decision.noDataConfirmed;
3227
+ var canAnswerCustomer = ready && (decision.queryStatus === 'ok'
3228
+ || noDataReady
3229
+ || decision.queryEvidenceRequired === false);
3230
+ var canDraftSupportReply = canAnswerCustomer && decision.confidenceLevel === 'high';
3231
+ var requiresHumanReview = !canAnswerCustomer || canDraftSupportReply;
3232
+ var cheapRepair = /needs_(?:no_data|date_window|query_shape|next_action)|needs_evidence/.test(status);
3233
+ var blockers = decision.blockers.length
3234
+ ? decision.blockers
3235
+ : (ready ? [] : [decision.reason]);
3236
+ var requiredEvidence = Array.from(new Set(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read((decision.queryEvidenceRequired ? ['structured query/tool execution proof'] : [])), false), __read((decision.dateWindowRequired ? ['concrete date-window start and end'] : [])), false), __read((decision.queryStatus === 'no_data' ? ['noDataConfirmed=true from scoped probe or query evidence'] : [])), false), __read((decision.legalQueryShape ? [] : ['legal Mongo query/projection shape'])), false), __read((decision.citationRefs.length || decision.evidenceRefs.length ? [] : ['citationRefs or evidenceRefs'])), false), __read((decision.nextActions.length ? [] : ['one explicit next action or no-action state'])), false), __read((decision.confidenceLevel === 'low' || decision.confidenceLevel === 'unknown' ? ['medium/high confidence evidence'] : [])), false))).slice(0, 20);
3237
+ return {
3238
+ contractId: "assistant-actionability:".concat(decision.status, ":").concat(decision.queryStatus, ":").concat(decision.recordedAt),
3239
+ status: status,
3240
+ primaryCommand: primaryCommand,
3241
+ label: assistantActionabilityLabel(status),
3242
+ canAnswerCustomer: canAnswerCustomer,
3243
+ canDraftSupportReply: canDraftSupportReply,
3244
+ canSendCustomerReply: false,
3245
+ requiresHumanReview: requiresHumanReview,
3246
+ canRunWithoutCodexMonitor: ready || cheapRepair,
3247
+ codexFallbackRequired: !ready && !cheapRepair,
3248
+ costRisk: ready
3249
+ ? 'free_or_deterministic'
3250
+ : status === 'needs_permission'
3251
+ ? 'manual_blocked'
3252
+ : (status === 'needs_query_repair' || status === 'incorrect' ? 'small_model_or_qa' : 'free_or_deterministic'),
3253
+ queryResultClass: decision.queryStatus,
3254
+ confidenceLevel: decision.confidenceLevel,
3255
+ decisionBasis: {
3256
+ answerQualityStatus: decision.status,
3257
+ queryStatus: decision.queryStatus,
3258
+ queryEvidencePresent: decision.queryEvidencePresent,
3259
+ noDataConfirmed: decision.noDataConfirmed,
3260
+ legalQueryShape: decision.legalQueryShape,
3261
+ dateWindowRequired: decision.dateWindowRequired,
3262
+ dateWindowPresent: decision.dateWindowPresent,
3263
+ citationCount: decision.citationRefs.length + decision.evidenceRefs.length,
3264
+ nextActionCount: decision.nextActions.length
3265
+ },
3266
+ requiredEvidence: requiredEvidence,
3267
+ successEvidence: Array.from(new Set(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read((ready ? ['assistant answer quality gate passed'] : [])), false), __read((decision.queryEvidenceRefs.length ? decision.queryEvidenceRefs : [])), false), __read((decision.citationRefs.length ? decision.citationRefs : [])), false), __read((decision.evidenceRefs.length ? decision.evidenceRefs : [])), false))).slice(0, 20),
3268
+ blockers: blockers,
3269
+ nextActions: decision.nextActions,
3270
+ nextCommands: Array.from(new Set(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([
3271
+ primaryCommand
3272
+ ], __read((status === 'needs_query_repair' ? ['fix_query_error', 'rerun_assistant_query'] : [])), false), __read((status === 'needs_no_data_verification' ? ['run_tiny_shape_probe', 'record_no_data_confirmed'] : [])), false), __read((status === 'needs_date_window_repair' ? ['resolve_current_date', 'record_concrete_date_window', 'rerun_assistant_query'] : [])), false), __read((status === 'needs_query_shape_repair' ? ['rewrite_illegal_projection', 'rerun_query_shape_validator'] : [])), false), __read((status === 'needs_permission' ? ['request_permission_or_choose_allowed_route'] : [])), false), [
3273
+ 'record_assistant_actionability_result'
3274
+ ], false))).slice(0, 20),
3275
+ forbiddenActions: Array.from(new Set(__spreadArray(__spreadArray(__spreadArray(__spreadArray([
3276
+ 'Do not answer from keyword or route guesses without verified query evidence.',
3277
+ 'Do not claim no data when queryStatus is query_error or permission_error.'
3278
+ ], __read((decision.queryStatus === 'no_data' && !decision.noDataConfirmed ? ['Do not present no-data answer until noDataConfirmed=true.'] : [])), false), __read((decision.legalQueryShape ? [] : ['Do not answer from illegal Mongo projection/query shape.'])), false), __read((decision.dateWindowRequired && !decision.dateWindowPresent ? ['Do not answer dated questions without concrete start/end date evidence.'] : [])), false), __read((decision.confidenceLevel === 'low' || decision.confidenceLevel === 'unknown' ? ['Do not draft support/customer reply from low or unknown confidence.'] : [])), false))).slice(0, 20),
3279
+ evidenceRefs: Array.from(new Set(__spreadArray(__spreadArray(__spreadArray([], __read(decision.queryEvidenceRefs), false), __read(decision.citationRefs), false), __read(decision.evidenceRefs), false))).slice(0, 40),
3280
+ recordedAt: isoNow(now || decision.recordedAt)
3281
+ };
3282
+ }
3283
+ function assistantAnswerActionabilityGate(contract, now) {
3284
+ var status = contract.status === 'ready_to_answer'
3285
+ ? 'pass'
3286
+ : contract.status === 'incorrect' || contract.status === 'needs_query_shape_repair' || contract.status === 'needs_date_window_repair'
3287
+ ? 'fail'
3288
+ : 'blocked';
3289
+ return {
3290
+ key: 'assistant_answer_actionability',
3291
+ label: 'Assistant answer actionability',
3292
+ status: status,
3293
+ reason: status === 'pass'
3294
+ ? 'Assistant answer can proceed from verified structured evidence.'
3295
+ : (contract.blockers.join(' ') || 'Assistant answer is blocked until actionability evidence is complete.'),
3296
+ evidenceRefs: contract.evidenceRefs,
3297
+ recordedAt: isoNow(now || contract.recordedAt),
3298
+ metadata: {
3299
+ contractId: contract.contractId,
3300
+ status: contract.status,
3301
+ primaryCommand: contract.primaryCommand,
3302
+ label: contract.label,
3303
+ canAnswerCustomer: contract.canAnswerCustomer,
3304
+ canDraftSupportReply: contract.canDraftSupportReply,
3305
+ canSendCustomerReply: contract.canSendCustomerReply,
3306
+ requiresHumanReview: contract.requiresHumanReview,
3307
+ canRunWithoutCodexMonitor: contract.canRunWithoutCodexMonitor,
3308
+ codexFallbackRequired: contract.codexFallbackRequired,
3309
+ costRisk: contract.costRisk,
3310
+ queryResultClass: contract.queryResultClass,
3311
+ confidenceLevel: contract.confidenceLevel,
3312
+ decisionBasis: contract.decisionBasis,
3313
+ requiredEvidence: contract.requiredEvidence,
3314
+ successEvidence: contract.successEvidence,
3315
+ blockers: contract.blockers,
3316
+ nextActions: contract.nextActions,
3317
+ nextCommands: contract.nextCommands,
3318
+ forbiddenActions: contract.forbiddenActions
3319
+ }
3320
+ };
3321
+ }
3322
+ function applyAssistantAnswerQualityGate(qa, decision, now) {
3323
+ var gate = assistantAnswerQualityGate(decision, now);
3324
+ if (decision.ready) {
3325
+ return __assign(__assign({}, qa), { gateResults: __spreadArray(__spreadArray([], __read(qa.gateResults), false), [gate], false) });
3326
+ }
3327
+ return __assign(__assign({}, qa), { outcome: /incorrect|date_incorrect|missing_date_window|illegal_query_shape/.test(decision.status)
3328
+ ? 'business_assertion_failed'
3329
+ : 'incomplete', gateResults: __spreadArray(__spreadArray([], __read(qa.gateResults.filter(function (existing) { return !(existing.key === 'qa_business_assertion' && existing.status === 'pass'); })), false), [
3330
+ gate
3331
+ ], false) });
3332
+ }
3333
+ function buildSupportAIRunFromEvidence(input) {
3334
+ var e_32, _a, e_33, _b;
3335
+ var _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, _62, _63, _64, _65, _66, _67, _68, _69, _70, _71, _72;
3336
+ var ticket = input.ticket || {};
3337
+ var job = input.job || {};
3338
+ var evidence = buildSupportQaEvidence(input);
3339
+ var events = [];
3340
+ var gates = [];
3341
+ var sourceIds = {};
3342
+ addSourceId(sourceIds, 'ticketId', ticket._id || ticket.id || job.ticketId || job.supportTicketId);
3343
+ addSourceId(sourceIds, 'ticketNumber', ticket.ticketNumber || ticket.number || job.ticketNumber);
3344
+ addSourceId(sourceIds, 'jobId', job._id || job.id || job.jobId);
3345
+ addSourceId(sourceIds, 'buildPlanId', job.buildPlanId || ticket.buildPlanId);
3346
+ try {
3347
+ for (var _73 = __values(asArray(input.taskEvents)), _74 = _73.next(); !_74.done; _74 = _73.next()) {
3348
+ var event_1 = _74.value;
3349
+ pushEvent(events, {
3350
+ type: event_1.type === 'human_intervention' ? 'human_intervention' : 'log',
3351
+ category: cleanText(event_1.category || event_1.phase || event_1.type, 160),
3352
+ message: cleanText(event_1.message || event_1.summary || event_1.text || event_1.title, 1800),
3353
+ recordedAt: eventDate(event_1),
3354
+ metadata: {
3355
+ status: event_1.status,
3356
+ phase: event_1.phase,
3357
+ taskId: event_1.taskId || event_1._id || event_1.id
3358
+ }
3359
+ });
3360
+ }
3361
+ }
3362
+ catch (e_32_1) { e_32 = { error: e_32_1 }; }
3363
+ finally {
3364
+ try {
3365
+ if (_74 && !_74.done && (_a = _73.return)) _a.call(_73);
3366
+ }
3367
+ finally { if (e_32) throw e_32.error; }
3368
+ }
3369
+ try {
3370
+ for (var _75 = __values(asArray(input.aiJobs)), _76 = _75.next(); !_76.done; _76 = _75.next()) {
3371
+ var aiJob = _76.value;
3372
+ pushEvent(events, {
3373
+ type: aiJob.model ? 'model_call' : 'log',
3374
+ category: cleanText(aiJob.category || aiJob.phase || aiJob.runner, 160),
3375
+ message: cleanText(aiJob.summary || aiJob.promptSummary || aiJob.status || aiJob.phase, 1800),
3376
+ recordedAt: eventDate(aiJob),
3377
+ metadata: {
3378
+ id: aiJob._id || aiJob.id,
3379
+ model: aiJob.model,
3380
+ status: aiJob.status,
3381
+ phase: aiJob.phase
3382
+ }
3383
+ });
3384
+ }
3385
+ }
3386
+ catch (e_33_1) { e_33 = { error: e_33_1 }; }
3387
+ finally {
3388
+ try {
3389
+ if (_76 && !_76.done && (_b = _75.return)) _b.call(_75);
3390
+ }
3391
+ finally { if (e_33) throw e_33.error; }
3392
+ }
3393
+ collectCommitEvents(asArray(input.commits), events);
3394
+ collectHotfixEvidenceEvents([job, ticket, evidence, input.qaEvidence], events, gates, input.now);
3395
+ var noBlindLoopGate = supportManagerNoBlindLoopGate(job, evidence, input.now);
3396
+ if (noBlindLoopGate) {
3397
+ gates.push(noBlindLoopGate);
3398
+ pushEvent(events, {
3399
+ type: 'log',
3400
+ category: 'manager_no_blind_loop_policy',
3401
+ message: noBlindLoopGate.reason,
3402
+ artifactPaths: noBlindLoopGate.evidenceRefs,
3403
+ recordedAt: noBlindLoopGate.recordedAt,
3404
+ metadata: noBlindLoopGate.metadata
3405
+ });
3406
+ }
3407
+ var businessProofReadiness = plainObject(evidence.businessProofReadiness || evidence.business_proof_readiness);
3408
+ var businessProofReadinessGate = supportBusinessProofReadinessGate(businessProofReadiness, input.now);
3409
+ if (businessProofReadinessGate) {
3410
+ gates.push(businessProofReadinessGate);
3411
+ pushEvent(events, {
3412
+ type: 'qa_business_assertion',
3413
+ category: 'support_business_proof_readiness',
3414
+ message: businessProofReadinessGate.reason,
3415
+ artifactPaths: businessProofReadinessGate.evidenceRefs,
3416
+ recordedAt: businessProofReadinessGate.recordedAt,
3417
+ metadata: businessProofReadinessGate.metadata
3418
+ });
3419
+ }
3420
+ var customerReplyPolicy = plainObject(evidence.customerReplyPolicy || evidence.customer_reply_policy);
3421
+ var customerReplyPolicyGate = supportCustomerReplyPolicyGate(customerReplyPolicy, input.now);
3422
+ if (customerReplyPolicyGate) {
3423
+ gates.push(customerReplyPolicyGate);
3424
+ pushEvent(events, {
3425
+ type: 'human_intervention',
3426
+ category: 'support_customer_reply_policy',
3427
+ message: customerReplyPolicyGate.reason,
3428
+ artifactPaths: customerReplyPolicyGate.evidenceRefs,
3429
+ recordedAt: customerReplyPolicyGate.recordedAt,
3430
+ metadata: customerReplyPolicyGate.metadata
3431
+ });
3432
+ }
3433
+ var customerReplyReadiness = plainObject(evidence.customerReplyReadiness
3434
+ || evidence.customer_reply_readiness
3435
+ || customerReplyPolicy.readinessContract
3436
+ || customerReplyPolicy.readiness_contract);
3437
+ var customerReplyReadinessGate = supportCustomerReplyReadinessGate(customerReplyReadiness, input.now);
3438
+ if (customerReplyReadinessGate) {
3439
+ gates.push(customerReplyReadinessGate);
3440
+ pushEvent(events, {
3441
+ type: 'human_intervention',
3442
+ category: 'support_customer_reply_readiness',
3443
+ message: customerReplyReadinessGate.reason,
3444
+ artifactPaths: customerReplyReadinessGate.evidenceRefs,
3445
+ recordedAt: customerReplyReadinessGate.recordedAt,
3446
+ metadata: customerReplyReadinessGate.metadata
3447
+ });
3448
+ }
3449
+ var nextActionContract = supportNextActionContractObject(ticket, job, evidence);
3450
+ var nextActionContractRequired = supportNextActionContractRequired(ticket, job, evidence);
3451
+ var nextActionContractGate = supportNextActionContractGate(nextActionContract, input.now, nextActionContractRequired);
3452
+ if (nextActionContractGate) {
3453
+ gates.push(nextActionContractGate);
3454
+ pushEvent(events, {
3455
+ type: 'log',
3456
+ category: 'support_next_action_contract',
3457
+ message: nextActionContractGate.reason,
3458
+ artifactPaths: nextActionContractGate.evidenceRefs,
3459
+ recordedAt: nextActionContractGate.recordedAt,
3460
+ metadata: nextActionContractGate.metadata
3461
+ });
3462
+ }
3463
+ var managerRecoveryExecutionProof = plainObject(evidence.managerRecoveryExecutionProof || evidence.manager_recovery_execution_proof);
3464
+ var recoveryExecutionProofGate = managerRecoveryExecutionProofGate(managerRecoveryExecutionProof, input.now);
3465
+ if (recoveryExecutionProofGate) {
3466
+ gates.push(recoveryExecutionProofGate);
3467
+ pushEvent(events, {
3468
+ type: 'log',
3469
+ category: 'manager_recovery_execution_proof',
3470
+ message: recoveryExecutionProofGate.reason,
3471
+ artifactPaths: recoveryExecutionProofGate.evidenceRefs,
3472
+ recordedAt: recoveryExecutionProofGate.recordedAt,
3473
+ metadata: recoveryExecutionProofGate.metadata
3474
+ });
3475
+ }
3476
+ var ticketAutomation = plainObject(ticket.automation);
3477
+ var ticketManagerState = plainObject(ticketAutomation.manager || ticket.manager);
3478
+ var rootCauseEntryContract = evidenceObject(job.supportRootCauseEntryContract, job.support_root_cause_entry_contract, job.rootCauseEntryContract, ticket.supportRootCauseEntryContract, ticket.rootCauseEntryContract, ticketManagerState.root_cause_entry_contract, ticketManagerState.rootCauseEntryContract, evidence.rootCauseEntryContract, evidence.root_cause_entry_contract);
3479
+ var rootCauseEntryContractGate = supportRootCauseEntryContractGate(rootCauseEntryContract, input.now);
3480
+ if (rootCauseEntryContractGate) {
3481
+ gates.push(rootCauseEntryContractGate);
3482
+ pushEvent(events, {
3483
+ type: 'log',
3484
+ category: 'support_root_cause_entry_contract',
3485
+ message: rootCauseEntryContractGate.reason,
3486
+ artifactPaths: rootCauseEntryContractGate.evidenceRefs,
3487
+ recordedAt: rootCauseEntryContractGate.recordedAt,
3488
+ metadata: rootCauseEntryContractGate.metadata
3489
+ });
3490
+ }
3491
+ var cost = collectUsageEvents(asArray(input.usageLedger), events);
3492
+ var costGate = costObservabilityGate(cost, 'support_ticket', input.now);
3493
+ gates.push(costGate);
3494
+ pushEvent(events, {
3495
+ type: 'usage',
3496
+ category: 'cost_observability',
3497
+ message: costGate.reason,
3498
+ artifactPaths: costGate.evidenceRefs,
3499
+ recordedAt: costGate.recordedAt,
3500
+ metadata: costGate.metadata
3501
+ });
3502
+ var preflightGateSource = supportPreflightGateObject(ticket, job, evidence);
3503
+ var preflightGate = supportPreflightGateResult(preflightGateSource, input.now);
3504
+ if (preflightGate) {
3505
+ gates.push(preflightGate);
3506
+ pushEvent(events, {
3507
+ type: ((_c = preflightGate.metadata) === null || _c === void 0 ? void 0 : _c.failureClass) === 'compile' || preflightGateSource.status === 'compile_failed' ? 'qa_compile' : 'qa_infra',
3508
+ category: 'support_preflight_gate',
3509
+ message: preflightGate.reason,
3510
+ artifactPaths: preflightGate.evidenceRefs,
3511
+ recordedAt: preflightGate.recordedAt,
3512
+ metadata: preflightGate.metadata
3513
+ });
3514
+ }
3515
+ var diagnosisGate = evidenceObject(job.supportV5DiagnosisGate, job.support_v5_diagnosis_gate, job.diagnosisGate, ticket.supportV5DiagnosisGate, ticket.diagnosisGate, evidence.diagnosisGate, evidence.supportV5DiagnosisGate);
3516
+ var diagnosisEvidencePackSource = supportDiagnosisEvidencePackObject(ticket, job, evidence);
3517
+ var similarFixHints = supportSimilarFixHintsObject(ticket, job, evidence);
3518
+ var diagnosisEvidencePack = Object.keys(diagnosisEvidencePackSource).length
3519
+ ? diagnosisEvidencePackSource
3520
+ : (Object.keys(diagnosisGate).length || Object.keys(similarFixHints).length)
3521
+ ? (0, support_runner_v5_1.buildResolveIOSupportDiagnosisEvidencePack)({
3522
+ diagnosisGate: diagnosisGate,
3523
+ similarCaseHints: similarFixHints,
3524
+ issueClass: diagnosisGate.issue_class || diagnosisGate.issueClass,
3525
+ ownerFiles: diagnosisGate.owner_files || diagnosisGate.ownerFiles,
3526
+ text: [
3527
+ ticket.title,
3528
+ ticket.subject,
3529
+ ticket.summary,
3530
+ job.title,
3531
+ job.summary
3532
+ ].filter(Boolean).join(' '),
3533
+ now: input.now
3534
+ })
3535
+ : {};
3536
+ var diagnosisEvidencePackGate = supportDiagnosisEvidencePackGate(diagnosisEvidencePack, input.now);
3537
+ if (diagnosisEvidencePackGate) {
3538
+ gates.push(diagnosisEvidencePackGate);
3539
+ pushEvent(events, {
3540
+ type: 'log',
3541
+ category: 'support_diagnosis_evidence_pack',
3542
+ message: diagnosisEvidencePackGate.reason,
3543
+ artifactPaths: diagnosisEvidencePackGate.evidenceRefs,
3544
+ recordedAt: diagnosisEvidencePackGate.recordedAt,
3545
+ metadata: diagnosisEvidencePackGate.metadata
3546
+ });
3547
+ }
3548
+ var issueClassProbePlanSource = supportIssueClassProbePlanObject(ticket, job, evidence);
3549
+ var issueClassProbePlan = Object.keys(issueClassProbePlanSource).length
3550
+ ? issueClassProbePlanSource
3551
+ : Object.keys(diagnosisGate).length
3552
+ ? (0, support_runner_v5_1.buildResolveIOSupportIssueClassProbePlan)(diagnosisGate, input.now)
3553
+ : {};
3554
+ var issueClassProbePlanRequired = nextActionContractRequired || Object.keys(diagnosisGate).length > 0;
3555
+ var issueClassProbePlanGate = supportIssueClassProbePlanGate(issueClassProbePlan, diagnosisGate, input.now, issueClassProbePlanRequired);
3556
+ if (issueClassProbePlanGate) {
3557
+ gates.push(issueClassProbePlanGate);
3558
+ pushEvent(events, {
3559
+ type: 'log',
3560
+ category: 'support_issue_class_probe_plan',
3561
+ message: issueClassProbePlanGate.reason,
3562
+ artifactPaths: issueClassProbePlanGate.evidenceRefs,
3563
+ recordedAt: issueClassProbePlanGate.recordedAt,
3564
+ metadata: issueClassProbePlanGate.metadata
3565
+ });
3566
+ }
3567
+ var productRepairEvidence = supportProductRepairEvidence(input, evidence);
3568
+ var diagnosisBeforeRepairGate = supportDiagnosisBeforeRepairGate(diagnosisGate, productRepairEvidence, input.now);
3569
+ if (diagnosisBeforeRepairGate) {
3570
+ gates.push(diagnosisBeforeRepairGate);
3571
+ pushEvent(events, {
3572
+ type: 'log',
3573
+ category: 'support_diagnosis_before_repair',
3574
+ message: diagnosisBeforeRepairGate.reason,
3575
+ artifactPaths: diagnosisBeforeRepairGate.evidenceRefs,
3576
+ recordedAt: diagnosisBeforeRepairGate.recordedAt,
3577
+ metadata: diagnosisBeforeRepairGate.metadata
3578
+ });
3579
+ }
3580
+ var ownerFileScopeGate = supportOwnerFileScopeGate(diagnosisGate, productRepairEvidence, input.now);
3581
+ if (ownerFileScopeGate) {
3582
+ gates.push(ownerFileScopeGate);
3583
+ pushEvent(events, {
3584
+ type: 'log',
3585
+ category: 'support_owner_file_scope',
3586
+ message: ownerFileScopeGate.reason,
3587
+ artifactPaths: ownerFileScopeGate.evidenceRefs,
3588
+ recordedAt: ownerFileScopeGate.recordedAt,
3589
+ metadata: ownerFileScopeGate.metadata
3590
+ });
3591
+ }
3592
+ var qa = applySupportDiagnosisProofGate(buildQaFromEvidence(evidence, input.now), diagnosisGate, input.now);
3593
+ var diagnosisOwnerFiles = asArray(diagnosisGate.owner_files || diagnosisGate.ownerFiles);
3594
+ var diagnosisIssueClass = cleanText(diagnosisGate.issue_class || diagnosisGate.issueClass, 120);
3595
+ if (Object.keys(diagnosisGate).length) {
3596
+ pushEvent(events, {
3597
+ type: 'log',
3598
+ category: 'diagnosis_gate',
3599
+ message: cleanText(((_d = diagnosisGate.accepted_hypothesis) === null || _d === void 0 ? void 0 : _d.statement) || ((_e = diagnosisGate.acceptedHypothesis) === null || _e === void 0 ? void 0 : _e.statement) || diagnosisGate.summary || 'Support diagnosis gate recorded.', 1800),
3600
+ metadata: {
3601
+ status: diagnosisGate.status,
3602
+ issueClass: diagnosisIssueClass,
3603
+ ownerFiles: diagnosisOwnerFiles
3604
+ }
3605
+ });
3606
+ }
3607
+ return (0, ai_run_evidence_1.buildAIRun)({
3608
+ source: 'support_ticket',
3609
+ sourceIds: sourceIds,
3610
+ title: firstText(ticket, ['title', 'subject', 'summary']) || firstText(job, ['title', 'summary']),
3611
+ status: firstText(job, ['status', 'state']) || firstText(ticket, ['status', 'state']),
3612
+ phase: firstText(job, ['phase', 'runnerPhase']),
3613
+ startedAt: dateValue(job, ['startedAt', 'createdAt']) || dateValue(ticket, ['createdAt']),
3614
+ completedAt: dateValue(job, ['completedAt', 'finishedAt', 'updatedAt']),
3615
+ events: events,
3616
+ gates: gates,
3617
+ qa: qa,
3618
+ cost: cost,
3619
+ scorecardPassed: evidence.scorecardPassed === true || evidence.scorecardStatus === 'pass',
3620
+ deployStatus: evidence.deployStatus,
3621
+ publishStatus: evidence.publishStatus,
3622
+ sampleDataStatus: evidence.sampleDataStatus,
3623
+ manualHandoff: evidence.manualHandoff === true || job.manualHandoff === true,
3624
+ stopped: evidence.stopped === true || job.stopped === true,
3625
+ rejected: evidence.rejected === true,
3626
+ explicitAccepted: evidence.explicitAccepted === true || ticket.accepted === true,
3627
+ terminal: /complete|closed|resolved|done|failed|rejected/i.test("".concat(job.status || '', " ").concat(ticket.status || '')),
3628
+ now: input.now,
3629
+ metadata: {
3630
+ versionCount: asArray(input.versions).length,
3631
+ buildPlanCount: asArray(input.buildPlans).length,
3632
+ costObservability: costObservabilityMetadata(costGate),
3633
+ hotfixDurability: hotfixDurabilityMetadata(gates),
3634
+ managerNoBlindLoopPolicy: managerNoBlindLoopMetadata(noBlindLoopGate),
3635
+ diagnosisBeforeRepair: diagnosisBeforeRepairGate ? {
3636
+ status: diagnosisBeforeRepairGate.status,
3637
+ diagnosisValid: ((_f = diagnosisBeforeRepairGate.metadata) === null || _f === void 0 ? void 0 : _f.diagnosisValid) === true,
3638
+ diagnosisStatus: cleanText((_g = diagnosisBeforeRepairGate.metadata) === null || _g === void 0 ? void 0 : _g.diagnosisStatus, 120),
3639
+ activityCount: Number(((_h = diagnosisBeforeRepairGate.metadata) === null || _h === void 0 ? void 0 : _h.activityCount) || 0),
3640
+ changedFiles: cleanStringList((_j = diagnosisBeforeRepairGate.metadata) === null || _j === void 0 ? void 0 : _j.changedFiles, 40, 500),
3641
+ allowedDispatchAction: cleanText((_k = diagnosisBeforeRepairGate.metadata) === null || _k === void 0 ? void 0 : _k.allowedDispatchAction, 160),
3642
+ productRepairAllowed: ((_l = diagnosisBeforeRepairGate.metadata) === null || _l === void 0 ? void 0 : _l.productRepairAllowed) === true,
3643
+ blockers: cleanStringList((_m = diagnosisBeforeRepairGate.metadata) === null || _m === void 0 ? void 0 : _m.blockers, 20, 500)
3644
+ } : undefined,
3645
+ ownerFileScope: ownerFileScopeGate ? {
3646
+ status: ownerFileScopeGate.status,
3647
+ productRepairAllowed: ((_o = ownerFileScopeGate.metadata) === null || _o === void 0 ? void 0 : _o.productRepairAllowed) === true,
3648
+ allowedDispatchAction: cleanText((_p = ownerFileScopeGate.metadata) === null || _p === void 0 ? void 0 : _p.allowedDispatchAction, 160),
3649
+ ownerFiles: cleanStringList((_q = ownerFileScopeGate.metadata) === null || _q === void 0 ? void 0 : _q.ownerFiles, 40, 500),
3650
+ changedFiles: cleanStringList((_r = ownerFileScopeGate.metadata) === null || _r === void 0 ? void 0 : _r.changedFiles, 60, 500),
3651
+ outsideOwnerFiles: cleanStringList((_s = ownerFileScopeGate.metadata) === null || _s === void 0 ? void 0 : _s.outsideOwnerFiles, 40, 500),
3652
+ allowedTestFilesOutsideOwnerScope: ((_t = ownerFileScopeGate.metadata) === null || _t === void 0 ? void 0 : _t.allowedTestFilesOutsideOwnerScope) === true,
3653
+ requiredEvidence: cleanStringList((_u = ownerFileScopeGate.metadata) === null || _u === void 0 ? void 0 : _u.requiredEvidence, 20, 500)
3654
+ } : undefined,
3655
+ rootCauseEntryContract: Object.keys(rootCauseEntryContract).length ? {
3656
+ contractId: cleanText(rootCauseEntryContract.contract_id || rootCauseEntryContract.contractId, 160),
3657
+ version: cleanText(rootCauseEntryContract.version, 120),
3658
+ status: cleanText(rootCauseEntryContract.status, 120),
3659
+ issueClassProbeCount: asArray(rootCauseEntryContract.issue_class_probes || rootCauseEntryContract.issueClassProbes).length,
3660
+ ownerFileMax: Number(((_v = rootCauseEntryContract.owner_file_policy) === null || _v === void 0 ? void 0 : _v.max_files) || ((_w = rootCauseEntryContract.ownerFilePolicy) === null || _w === void 0 ? void 0 : _w.maxFiles) || 0) || 0,
3661
+ requiresBusinessAssertion: ((_x = rootCauseEntryContract.business_proof_policy) === null || _x === void 0 ? void 0 : _x.requires_aiqa_business_assertion) === true
3662
+ || ((_y = rootCauseEntryContract.businessProofPolicy) === null || _y === void 0 ? void 0 : _y.requiresAiqaBusinessAssertion) === true
3663
+ } : undefined,
3664
+ diagnosis: Object.keys(diagnosisGate).length ? {
3665
+ status: cleanText(diagnosisGate.status, 80),
3666
+ issueClass: diagnosisIssueClass,
3667
+ ownerFiles: diagnosisOwnerFiles,
3668
+ acceptedHypothesis: cleanText(((_z = diagnosisGate.accepted_hypothesis) === null || _z === void 0 ? void 0 : _z.statement) || ((_0 = diagnosisGate.acceptedHypothesis) === null || _0 === void 0 ? void 0 : _0.statement), 1000),
3669
+ proofPlan: diagnosisGate.proof_plan || diagnosisGate.proofPlan
3670
+ } : undefined,
3671
+ diagnosisEvidencePack: diagnosisEvidencePackGate ? {
3672
+ status: cleanText((_1 = diagnosisEvidencePackGate.metadata) === null || _1 === void 0 ? void 0 : _1.status, 120),
3673
+ gateStatus: diagnosisEvidencePackGate.status,
3674
+ packId: cleanText((_2 = diagnosisEvidencePackGate.metadata) === null || _2 === void 0 ? void 0 : _2.packId, 180),
3675
+ readOnly: ((_3 = diagnosisEvidencePackGate.metadata) === null || _3 === void 0 ? void 0 : _3.readOnly) !== false,
3676
+ sourceEditsAllowed: ((_4 = diagnosisEvidencePackGate.metadata) === null || _4 === void 0 ? void 0 : _4.sourceEditsAllowed) === true,
3677
+ requiredOutputKey: cleanText((_5 = diagnosisEvidencePackGate.metadata) === null || _5 === void 0 ? void 0 : _5.requiredOutputKey, 120),
3678
+ diagnosisValid: ((_6 = diagnosisEvidencePackGate.metadata) === null || _6 === void 0 ? void 0 : _6.diagnosisValid) === true,
3679
+ issueClassHint: cleanText((_7 = diagnosisEvidencePackGate.metadata) === null || _7 === void 0 ? void 0 : _7.issueClassHint, 120),
3680
+ ownerFileHints: cleanStringList((_8 = diagnosisEvidencePackGate.metadata) === null || _8 === void 0 ? void 0 : _8.ownerFileHints, 20, 500),
3681
+ similarHintCount: Number(((_9 = diagnosisEvidencePackGate.metadata) === null || _9 === void 0 ? void 0 : _9.similarHintCount) || 0),
3682
+ similarHintsAdvisoryOnly: ((_10 = diagnosisEvidencePackGate.metadata) === null || _10 === void 0 ? void 0 : _10.similarHintsAdvisoryOnly) === true,
3683
+ issueClassProbeCount: Number(((_11 = diagnosisEvidencePackGate.metadata) === null || _11 === void 0 ? void 0 : _11.issueClassProbeCount) || 0),
3684
+ validationBlockers: cleanStringList((_12 = diagnosisEvidencePackGate.metadata) === null || _12 === void 0 ? void 0 : _12.validationBlockers, 20, 500)
3685
+ } : undefined,
3686
+ issueClassProbePlan: issueClassProbePlanGate ? {
3687
+ status: cleanText((_13 = issueClassProbePlanGate.metadata) === null || _13 === void 0 ? void 0 : _13.status, 120),
3688
+ gateStatus: issueClassProbePlanGate.status,
3689
+ planId: cleanText((_14 = issueClassProbePlanGate.metadata) === null || _14 === void 0 ? void 0 : _14.planId, 180),
3690
+ issueClass: cleanText((_15 = issueClassProbePlanGate.metadata) === null || _15 === void 0 ? void 0 : _15.issueClass, 120),
3691
+ diagnosisValid: ((_16 = issueClassProbePlanGate.metadata) === null || _16 === void 0 ? void 0 : _16.diagnosisValid) === true,
3692
+ issueClassProbePlanReady: ((_17 = issueClassProbePlanGate.metadata) === null || _17 === void 0 ? void 0 : _17.issueClassProbePlanReady) === true,
3693
+ activeRoute: cleanText((_18 = issueClassProbePlanGate.metadata) === null || _18 === void 0 ? void 0 : _18.activeRoute, 500),
3694
+ action: cleanText((_19 = issueClassProbePlanGate.metadata) === null || _19 === void 0 ? void 0 : _19.action, 1000),
3695
+ expectedBusinessProof: cleanText((_20 = issueClassProbePlanGate.metadata) === null || _20 === void 0 ? void 0 : _20.expectedBusinessProof, 1200),
3696
+ acceptanceGate: cleanText((_21 = issueClassProbePlanGate.metadata) === null || _21 === void 0 ? void 0 : _21.acceptanceGate, 120),
3697
+ requiredArtifacts: cleanStringList((_22 = issueClassProbePlanGate.metadata) === null || _22 === void 0 ? void 0 : _22.requiredArtifacts, 20, 500),
3698
+ falsePassBlockers: cleanStringList((_23 = issueClassProbePlanGate.metadata) === null || _23 === void 0 ? void 0 : _23.falsePassBlockers, 20, 500),
3699
+ blockers: cleanStringList((_24 = issueClassProbePlanGate.metadata) === null || _24 === void 0 ? void 0 : _24.blockers, 20, 500)
3700
+ } : undefined,
3701
+ businessProofReadiness: Object.keys(businessProofReadiness).length ? {
3702
+ ready: businessProofReadiness.ready === true,
3703
+ status: cleanText(businessProofReadiness.status, 120),
3704
+ reason: cleanText(businessProofReadiness.reason, 1000),
3705
+ blockers: cleanStringList(businessProofReadiness.blockers, 20, 500)
3706
+ } : undefined,
3707
+ nextActionContract: nextActionContractGate ? {
3708
+ status: nextActionContractGate.status,
3709
+ action: cleanText((_25 = nextActionContractGate.metadata) === null || _25 === void 0 ? void 0 : _25.action, 160),
3710
+ primaryCommand: cleanText((_26 = nextActionContractGate.metadata) === null || _26 === void 0 ? void 0 : _26.primaryCommand, 240),
3711
+ safeToAutoRun: ((_27 = nextActionContractGate.metadata) === null || _27 === void 0 ? void 0 : _27.safeToAutoRun) === true,
3712
+ canRunWithoutCodexMonitor: ((_28 = nextActionContractGate.metadata) === null || _28 === void 0 ? void 0 : _28.canRunWithoutCodexMonitor) === true,
3713
+ codexFallbackRequired: ((_29 = nextActionContractGate.metadata) === null || _29 === void 0 ? void 0 : _29.codexFallbackRequired) === true,
3714
+ requiresHumanApproval: ((_30 = nextActionContractGate.metadata) === null || _30 === void 0 ? void 0 : _30.requiresHumanApproval) === true,
3715
+ rootCauseFirstSatisfied: ((_31 = nextActionContractGate.metadata) === null || _31 === void 0 ? void 0 : _31.rootCauseFirstSatisfied) === true,
3716
+ hotfixCommitRequired: ((_32 = nextActionContractGate.metadata) === null || _32 === void 0 ? void 0 : _32.hotfixCommitRequired) === true,
3717
+ liveHotfixBlockedUntilCommit: ((_33 = nextActionContractGate.metadata) === null || _33 === void 0 ? void 0 : _33.liveHotfixBlockedUntilCommit) === true,
3718
+ failureClass: cleanText((_34 = nextActionContractGate.metadata) === null || _34 === void 0 ? void 0 : _34.failureClass, 120),
3719
+ evidenceFreshnessStatus: cleanText((_35 = nextActionContractGate.metadata) === null || _35 === void 0 ? void 0 : _35.evidenceFreshnessStatus, 120),
3720
+ sameFailureCount: Number(((_36 = nextActionContractGate.metadata) === null || _36 === void 0 ? void 0 : _36.sameFailureCount) || 0),
3721
+ blockers: cleanStringList((_37 = nextActionContractGate.metadata) === null || _37 === void 0 ? void 0 : _37.blockers, 20, 500)
3722
+ } : undefined,
3723
+ managerRecoveryExecutionProof: recoveryExecutionProofGate ? {
3724
+ status: cleanText((_38 = recoveryExecutionProofGate.metadata) === null || _38 === void 0 ? void 0 : _38.status, 120),
3725
+ gateStatus: recoveryExecutionProofGate.status,
3726
+ canContinueRun: ((_39 = recoveryExecutionProofGate.metadata) === null || _39 === void 0 ? void 0 : _39.canContinueRun) === true,
3727
+ canRunProductRepair: ((_40 = recoveryExecutionProofGate.metadata) === null || _40 === void 0 ? void 0 : _40.canRunProductRepair) === true,
3728
+ canRunExpensiveModel: ((_41 = recoveryExecutionProofGate.metadata) === null || _41 === void 0 ? void 0 : _41.canRunExpensiveModel) === true,
3729
+ canResetLoopBudget: ((_42 = recoveryExecutionProofGate.metadata) === null || _42 === void 0 ? void 0 : _42.canResetLoopBudget) === true,
3730
+ newEvidence: ((_43 = recoveryExecutionProofGate.metadata) === null || _43 === void 0 ? void 0 : _43.newEvidence) === true,
3731
+ materialEvidence: ((_44 = recoveryExecutionProofGate.metadata) === null || _44 === void 0 ? void 0 : _44.materialEvidence) === true,
3732
+ evidenceStrength: cleanText((_45 = recoveryExecutionProofGate.metadata) === null || _45 === void 0 ? void 0 : _45.evidenceStrength, 120),
3733
+ nextAllowedAction: cleanText((_46 = recoveryExecutionProofGate.metadata) === null || _46 === void 0 ? void 0 : _46.nextAllowedAction, 180),
3734
+ missingEvidence: cleanStringList((_47 = recoveryExecutionProofGate.metadata) === null || _47 === void 0 ? void 0 : _47.missingEvidence, 20, 500),
3735
+ blockers: cleanStringList((_48 = recoveryExecutionProofGate.metadata) === null || _48 === void 0 ? void 0 : _48.blockers, 20, 500)
3736
+ } : undefined,
3737
+ customerReplyPolicy: Object.keys(customerReplyPolicy).length ? {
3738
+ action: cleanText(customerReplyPolicy.action, 120),
3739
+ safety: cleanText(customerReplyPolicy.safety, 120),
3740
+ canDraftCustomerReply: customerReplyPolicy.canDraftCustomerReply === true || customerReplyPolicy.can_draft_customer_reply === true,
3741
+ canSendCustomerReply: customerReplyPolicy.canSendCustomerReply === true || customerReplyPolicy.can_send_customer_reply === true,
3742
+ reason: cleanText(customerReplyPolicy.reason, 1000),
3743
+ reviewType: cleanText(((_49 = customerReplyPolicy.humanReviewPacket) === null || _49 === void 0 ? void 0 : _49.reviewType)
3744
+ || ((_50 = customerReplyPolicy.human_review_packet) === null || _50 === void 0 ? void 0 : _50.review_type)
3745
+ || ((_51 = customerReplyPolicy.human_review_packet) === null || _51 === void 0 ? void 0 : _51.reviewType), 160),
3746
+ primaryAction: cleanText(((_52 = customerReplyPolicy.humanReviewPacket) === null || _52 === void 0 ? void 0 : _52.primaryAction)
3747
+ || ((_53 = customerReplyPolicy.human_review_packet) === null || _53 === void 0 ? void 0 : _53.primary_action)
3748
+ || ((_54 = customerReplyPolicy.human_review_packet) === null || _54 === void 0 ? void 0 : _54.primaryAction), 160),
3749
+ clarificationContract: customerReplyPolicy.clarificationContract || customerReplyPolicy.clarification_contract ? {
3750
+ status: cleanText(((_55 = customerReplyPolicy.clarificationContract) === null || _55 === void 0 ? void 0 : _55.status) || ((_56 = customerReplyPolicy.clarification_contract) === null || _56 === void 0 ? void 0 : _56.status), 120),
3751
+ missingField: cleanText(((_57 = customerReplyPolicy.clarificationContract) === null || _57 === void 0 ? void 0 : _57.missingField) || ((_58 = customerReplyPolicy.clarification_contract) === null || _58 === void 0 ? void 0 : _58.missing_field), 120),
3752
+ oneQuestionOnly: ((_59 = customerReplyPolicy.clarificationContract) === null || _59 === void 0 ? void 0 : _59.oneQuestionOnly) === true || ((_60 = customerReplyPolicy.clarification_contract) === null || _60 === void 0 ? void 0 : _60.one_question_only) === true,
3753
+ parksTicketUntilCustomerReply: ((_61 = customerReplyPolicy.clarificationContract) === null || _61 === void 0 ? void 0 : _61.parksTicketUntilCustomerReply) === true || ((_62 = customerReplyPolicy.clarification_contract) === null || _62 === void 0 ? void 0 : _62.parks_ticket_until_customer_reply) === true
3754
+ } : undefined
3755
+ } : undefined,
3756
+ customerReplyReadiness: customerReplyReadinessGate ? {
3757
+ status: cleanText((_63 = customerReplyReadinessGate.metadata) === null || _63 === void 0 ? void 0 : _63.status, 120),
3758
+ gateStatus: customerReplyReadinessGate.status,
3759
+ primaryCommand: cleanText((_64 = customerReplyReadinessGate.metadata) === null || _64 === void 0 ? void 0 : _64.primaryCommand, 180),
3760
+ policyAction: cleanText((_65 = customerReplyReadinessGate.metadata) === null || _65 === void 0 ? void 0 : _65.policyAction, 120),
3761
+ canDraftCustomerReply: ((_66 = customerReplyReadinessGate.metadata) === null || _66 === void 0 ? void 0 : _66.canDraftCustomerReply) === true,
3762
+ canSendCustomerReply: ((_67 = customerReplyReadinessGate.metadata) === null || _67 === void 0 ? void 0 : _67.canSendCustomerReply) === true,
3763
+ requiresHumanApproval: ((_68 = customerReplyReadinessGate.metadata) === null || _68 === void 0 ? void 0 : _68.requiresHumanApproval) === true,
3764
+ proofBacked: ((_69 = customerReplyReadinessGate.metadata) === null || _69 === void 0 ? void 0 : _69.proofBacked) === true,
3765
+ businessProofReady: ((_70 = customerReplyReadinessGate.metadata) === null || _70 === void 0 ? void 0 : _70.businessProofReady) === true,
3766
+ releaseReady: ((_71 = customerReplyReadinessGate.metadata) === null || _71 === void 0 ? void 0 : _71.releaseReady) === true,
3767
+ blockers: cleanStringList((_72 = customerReplyReadinessGate.metadata) === null || _72 === void 0 ? void 0 : _72.blockers, 20, 500)
3768
+ } : undefined
3769
+ }
3770
+ });
3771
+ }
3772
+ function buildAICoderAIRunFromEvidence(input) {
3773
+ var e_34, _a;
3774
+ var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30;
3775
+ var app = input.app || {};
3776
+ var job = input.job || {};
3777
+ var evidence = buildAICoderQaEvidence(input);
3778
+ var events = [];
3779
+ var gates = [];
3780
+ var sourceIds = {};
3781
+ addSourceId(sourceIds, 'appId', app._id || app.id || job.appId || job.aicoderAppId);
3782
+ addSourceId(sourceIds, 'jobId', job._id || job.id || job.jobId);
3783
+ addSourceId(sourceIds, 'domain', app.domain || app.customDomain || job.domain);
3784
+ try {
3785
+ for (var _31 = __values(asArray(input.logs)), _32 = _31.next(); !_32.done; _32 = _31.next()) {
3786
+ var log = _32.value;
3787
+ pushEvent(events, {
3788
+ type: log.type === 'scorecard' ? 'scorecard' : 'log',
3789
+ category: cleanText(log.category || log.phase || log.level, 160),
3790
+ message: cleanText(log.message || log.summary || log.text || log.title, 1800),
3791
+ artifactPaths: asArray(log.artifactPaths || log.artifacts),
3792
+ recordedAt: eventDate(log),
3793
+ metadata: {
3794
+ status: log.status,
3795
+ level: log.level,
3796
+ score: log.score
3797
+ }
3798
+ });
3799
+ }
3800
+ }
3801
+ catch (e_34_1) { e_34 = { error: e_34_1 }; }
3802
+ finally {
3803
+ try {
3804
+ if (_32 && !_32.done && (_a = _31.return)) _a.call(_31);
3805
+ }
3806
+ finally { if (e_34) throw e_34.error; }
3807
+ }
3808
+ collectCommitEvents(asArray(input.commits), events);
3809
+ collectHotfixEvidenceEvents([job, app, evidence, input.qaEvidence], events, gates, input.now);
3810
+ var noBlindLoopGate = aicoderManagerNoBlindLoopGate(app, job, evidence, input.now);
3811
+ if (noBlindLoopGate) {
3812
+ gates.push(noBlindLoopGate);
3813
+ pushEvent(events, {
3814
+ type: 'log',
3815
+ category: 'manager_no_blind_loop_policy',
3816
+ message: noBlindLoopGate.reason,
3817
+ artifactPaths: noBlindLoopGate.evidenceRefs,
3818
+ recordedAt: noBlindLoopGate.recordedAt,
3819
+ metadata: noBlindLoopGate.metadata
3820
+ });
3821
+ }
3822
+ var cost = collectUsageEvents(asArray(input.usageLedger), events);
3823
+ var costGate = costObservabilityGate(cost, 'aicoder_app', input.now);
3824
+ gates.push(costGate);
3825
+ pushEvent(events, {
3826
+ type: 'usage',
3827
+ category: 'cost_observability',
3828
+ message: costGate.reason,
3829
+ artifactPaths: costGate.evidenceRefs,
3830
+ recordedAt: costGate.recordedAt,
3831
+ metadata: costGate.metadata
3832
+ });
3833
+ var journeyContractValidation = aicoderJourneyContractValidationFromEvidence(evidence);
3834
+ var journeyContractGate = aicoderJourneyContractGate(journeyContractValidation, evidence, input.now);
3835
+ gates.push(journeyContractGate);
3836
+ pushEvent(events, {
3837
+ type: 'log',
3838
+ category: 'aicoder_journey_contract',
3839
+ message: journeyContractGate.reason,
3840
+ artifactPaths: journeyContractGate.evidenceRefs,
3841
+ recordedAt: journeyContractGate.recordedAt,
3842
+ metadata: journeyContractGate.metadata
3843
+ });
3844
+ var scorecardPassed = evidence.scorecardPassed === true
3845
+ || evidence.scorecardStatus === 'pass'
3846
+ || (Number((_c = (_b = evidence.score) !== null && _b !== void 0 ? _b : evidence.qualityScore) !== null && _c !== void 0 ? _c : 0) >= Number((_e = (_d = evidence.scoreThreshold) !== null && _d !== void 0 ? _d : job.scoreThreshold) !== null && _e !== void 0 ? _e : 90));
3847
+ var explicitWorkflowReadiness = normalizeAICoderWorkflowProofReadiness(plainObject(evidence.workflowProofReadiness
3848
+ || evidence.workflow_proof_readiness
3849
+ || evidence.aicoderWorkflowProofReadiness
3850
+ || evidence.aicoder_workflow_proof_readiness
3851
+ || job.workflowProofReadiness
3852
+ || job.workflow_proof_readiness
3853
+ || job.aicoderWorkflowProofReadiness
3854
+ || job.aicoder_workflow_proof_readiness), input.now);
3855
+ var workflowReadiness = explicitWorkflowReadiness || (0, aicoder_runner_v6_1.evaluateResolveIOAICoderWorkflowProofReadiness)({
3856
+ journeyContract: evidence.journeyContract,
3857
+ journeyContractMarkdown: evidence.journeyContractMarkdown,
3858
+ workflowQaRows: asArray(evidence.workflowQaRows || evidence.workflow_qa_rows),
3859
+ businessAssertions: __spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(asArray(evidence.businessAssertions)), false), __read(asArray(evidence.business_assertions)), false), __read(asArray(evidence.workflowAssertions)), false), __read(asArray(evidence.workflow_assertions)), false),
3860
+ routeProbes: __spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(asArray(evidence.routeProbes)), false), __read(asArray(evidence.route_probes)), false), __read(asArray(evidence.workflowProbes)), false), __read(asArray(evidence.workflow_probes)), false),
3861
+ artifactPaths: __spreadArray(__spreadArray([], __read(asArray(evidence.artifactPaths)), false), __read(asArray(evidence.artifact_paths)), false),
3862
+ scorecardPassed: scorecardPassed,
3863
+ deployStatus: evidence.deployStatus,
3864
+ publishStatus: evidence.publishStatus,
3865
+ sampleDataStatus: evidence.sampleDataStatus,
3866
+ previousWorkflowProofFingerprint: firstNonEmptyText([
3867
+ evidence.previousWorkflowProofFingerprint,
3868
+ evidence.previous_workflow_proof_fingerprint,
3869
+ job.previousWorkflowProofFingerprint,
3870
+ job.previous_workflow_proof_fingerprint,
3871
+ app.previousWorkflowProofFingerprint,
3872
+ app.previous_workflow_proof_fingerprint
3873
+ ], 200),
3874
+ previousArtifactFingerprint: firstNonEmptyText([
3875
+ evidence.previousArtifactFingerprint,
3876
+ evidence.previous_artifact_fingerprint,
3877
+ job.previousArtifactFingerprint,
3878
+ job.previous_artifact_fingerprint,
3879
+ app.previousArtifactFingerprint,
3880
+ app.previous_artifact_fingerprint
3881
+ ], 200),
3882
+ previousWorkflowProofFingerprints: __spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(asArray(evidence.previousWorkflowProofFingerprints)), false), __read(asArray(evidence.previous_workflow_proof_fingerprints)), false), __read(asArray(job.previousWorkflowProofFingerprints)), false), __read(asArray(job.previous_workflow_proof_fingerprints)), false), __read(asArray(app.previousWorkflowProofFingerprints)), false), __read(asArray(app.previous_workflow_proof_fingerprints)), false),
3883
+ previousArtifactFingerprints: __spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(asArray(evidence.previousArtifactFingerprints)), false), __read(asArray(evidence.previous_artifact_fingerprints)), false), __read(asArray(job.previousArtifactFingerprints)), false), __read(asArray(job.previous_artifact_fingerprints)), false), __read(asArray(app.previousArtifactFingerprints)), false), __read(asArray(app.previous_artifact_fingerprints)), false),
3884
+ now: input.now
3885
+ });
3886
+ var workflowReadinessGate = aicoderWorkflowProofReadinessGate(workflowReadiness, input.now);
3887
+ gates.push(workflowReadinessGate);
3888
+ pushEvent(events, {
3889
+ type: 'qa_business_assertion',
3890
+ category: 'aicoder_workflow_proof_readiness',
3891
+ message: workflowReadinessGate.reason,
3892
+ artifactPaths: workflowReadinessGate.evidenceRefs,
3893
+ recordedAt: workflowReadinessGate.recordedAt,
3894
+ metadata: workflowReadinessGate.metadata
3895
+ });
3896
+ var workflowProofCheckpoint = aicoderWorkflowProofCheckpointObject(app, job, evidence);
3897
+ var workflowProofCheckpointGate = aicoderWorkflowProofCheckpointGate(workflowProofCheckpoint, input.now);
3898
+ if (workflowProofCheckpointGate) {
3899
+ gates.push(workflowProofCheckpointGate);
3900
+ pushEvent(events, {
3901
+ type: 'log',
3902
+ category: 'aicoder_workflow_proof_checkpoint',
3903
+ message: workflowProofCheckpointGate.reason,
3904
+ artifactPaths: workflowProofCheckpointGate.evidenceRefs,
3905
+ recordedAt: workflowProofCheckpointGate.recordedAt,
3906
+ metadata: workflowProofCheckpointGate.metadata
3907
+ });
3908
+ }
3909
+ var nextActionContract = aicoderNextActionContractObject(app, job, evidence);
3910
+ var nextActionContractGate = aicoderNextActionContractGate(nextActionContract, input.now);
3911
+ if (nextActionContractGate) {
3912
+ gates.push(nextActionContractGate);
3913
+ pushEvent(events, {
3914
+ type: 'log',
3915
+ category: 'aicoder_next_action_contract',
3916
+ message: nextActionContractGate.reason,
3917
+ artifactPaths: nextActionContractGate.evidenceRefs,
3918
+ recordedAt: nextActionContractGate.recordedAt,
3919
+ metadata: nextActionContractGate.metadata
3920
+ });
3921
+ }
3922
+ var qa = applyAICoderWorkflowProofGate(buildQaFromEvidence(evidence, input.now), workflowReadiness, input.now);
3923
+ return (0, ai_run_evidence_1.buildAIRun)({
3924
+ source: 'aicoder_app',
3925
+ sourceIds: sourceIds,
3926
+ title: firstText(app, ['name', 'title']) || firstText(job, ['appName', 'title', 'goal']),
3927
+ status: firstText(job, ['status', 'state']) || firstText(app, ['status', 'state']),
3928
+ phase: firstText(job, ['phase', 'runnerPhase']),
3929
+ startedAt: dateValue(job, ['startedAt', 'createdAt']) || dateValue(app, ['createdAt']),
3930
+ completedAt: dateValue(job, ['completedAt', 'finishedAt', 'updatedAt']),
3931
+ events: events,
3932
+ gates: gates,
3933
+ qa: qa,
3934
+ cost: cost,
3935
+ scorecardPassed: scorecardPassed,
3936
+ deployStatus: evidence.deployStatus || statusFromBoolean(evidence.deployReady),
3937
+ publishStatus: evidence.publishStatus || evidence.pullRequestStatus,
3938
+ sampleDataStatus: evidence.sampleDataStatus || statusFromBoolean((_f = evidence.sampleDataReady) !== null && _f !== void 0 ? _f : evidence.hasSampleData),
3939
+ manualHandoff: evidence.manualHandoff === true || job.manualHandoff === true,
3940
+ stopped: evidence.stopped === true || job.stopped === true,
3941
+ rejected: evidence.rejected === true,
3942
+ explicitAccepted: evidence.explicitAccepted === true || app.accepted === true,
3943
+ terminal: /complete|closed|resolved|done|failed|rejected/i.test("".concat(job.status || '', " ").concat(job.phase || '')),
3944
+ now: input.now,
3945
+ metadata: {
3946
+ domain: app.domain || app.customDomain || job.domain,
3947
+ wowScore: (_g = evidence.wowScore) !== null && _g !== void 0 ? _g : job.wowScore,
3948
+ score: (_h = evidence.score) !== null && _h !== void 0 ? _h : evidence.qualityScore,
3949
+ costObservability: costObservabilityMetadata(costGate),
3950
+ hotfixDurability: hotfixDurabilityMetadata(gates),
3951
+ managerNoBlindLoopPolicy: managerNoBlindLoopMetadata(noBlindLoopGate),
3952
+ journeyContract: {
3953
+ status: journeyContractGate.status,
3954
+ valid: ((_j = journeyContractGate.metadata) === null || _j === void 0 ? void 0 : _j.valid) === true,
3955
+ path: cleanText((_k = journeyContractGate.metadata) === null || _k === void 0 ? void 0 : _k.path, 500),
3956
+ primaryWorkflowId: cleanText((_l = journeyContractGate.metadata) === null || _l === void 0 ? void 0 : _l.primaryWorkflowId, 200),
3957
+ workflowQaRowCount: Number(((_m = journeyContractGate.metadata) === null || _m === void 0 ? void 0 : _m.workflowQaRowCount) || 0),
3958
+ workflowQaCoverageTags: cleanStringList((_o = journeyContractGate.metadata) === null || _o === void 0 ? void 0 : _o.workflowQaCoverageTags, 80, 120),
3959
+ workflowQaProofKinds: cleanStringList((_p = journeyContractGate.metadata) === null || _p === void 0 ? void 0 : _p.workflowQaProofKinds, 80, 120),
3960
+ errorCount: Number(((_q = journeyContractGate.metadata) === null || _q === void 0 ? void 0 : _q.errorCount) || 0),
3961
+ warningCount: Number(((_r = journeyContractGate.metadata) === null || _r === void 0 ? void 0 : _r.warningCount) || 0),
3962
+ issueCodes: cleanStringList((_s = journeyContractGate.metadata) === null || _s === void 0 ? void 0 : _s.issueCodes, 40, 120),
3963
+ blocksBuildUntilValid: ((_t = journeyContractGate.metadata) === null || _t === void 0 ? void 0 : _t.blocksBuildUntilValid) === true,
3964
+ blocksWorkflowQaUntilValid: ((_u = journeyContractGate.metadata) === null || _u === void 0 ? void 0 : _u.blocksWorkflowQaUntilValid) === true,
3965
+ blocksWowUiUntilWorkflowProof: ((_v = journeyContractGate.metadata) === null || _v === void 0 ? void 0 : _v.blocksWowUiUntilWorkflowProof) === true,
3966
+ blocksPublishUntilWorkflowProof: ((_w = journeyContractGate.metadata) === null || _w === void 0 ? void 0 : _w.blocksPublishUntilWorkflowProof) === true,
3967
+ nextAction: cleanText((_x = journeyContractGate.metadata) === null || _x === void 0 ? void 0 : _x.nextAction, 1000)
3968
+ },
3969
+ workflowProofReadiness: {
3970
+ ready: workflowReadiness.ready,
3971
+ status: workflowReadiness.status,
3972
+ reason: workflowReadiness.reason,
3973
+ blockers: workflowReadiness.blockers,
3974
+ primaryWorkflowId: workflowReadiness.primaryWorkflowId,
3975
+ passedWorkflowRows: workflowReadiness.passedWorkflowRows,
3976
+ missingWorkflowRows: workflowReadiness.missingWorkflowRows,
3977
+ failedWorkflowRows: workflowReadiness.failedWorkflowRows,
3978
+ sampleDataReady: workflowReadiness.sampleDataReady,
3979
+ releaseBlockers: workflowReadiness.releaseBlockers,
3980
+ workflowProofFingerprint: workflowReadiness.workflowProofFingerprint,
3981
+ artifactFingerprint: workflowReadiness.artifactFingerprint,
3982
+ proofFreshness: workflowReadiness.proofFreshness
3983
+ },
3984
+ workflowProofCheckpoint: workflowProofCheckpointGate ? {
3985
+ status: cleanText((_y = workflowProofCheckpointGate.metadata) === null || _y === void 0 ? void 0 : _y.status, 120),
3986
+ gateStatus: workflowProofCheckpointGate.status,
3987
+ readinessStatus: cleanText((_z = workflowProofCheckpointGate.metadata) === null || _z === void 0 ? void 0 : _z.readinessStatus, 120),
3988
+ nextGate: cleanText((_0 = workflowProofCheckpointGate.metadata) === null || _0 === void 0 ? void 0 : _0.nextGate, 120),
3989
+ nextAction: cleanText((_1 = workflowProofCheckpointGate.metadata) === null || _1 === void 0 ? void 0 : _1.nextAction, 1000),
3990
+ blocksProductRepairUntilJourneyContract: ((_2 = workflowProofCheckpointGate.metadata) === null || _2 === void 0 ? void 0 : _2.blocksProductRepairUntilJourneyContract) === true,
3991
+ blocksPublishUntilWorkflowProof: ((_3 = workflowProofCheckpointGate.metadata) === null || _3 === void 0 ? void 0 : _3.blocksPublishUntilWorkflowProof) === true,
3992
+ blocksPublishUntilReleaseGate: ((_4 = workflowProofCheckpointGate.metadata) === null || _4 === void 0 ? void 0 : _4.blocksPublishUntilReleaseGate) === true,
3993
+ blocksWowUiUntilWorkflowProof: ((_5 = workflowProofCheckpointGate.metadata) === null || _5 === void 0 ? void 0 : _5.blocksWowUiUntilWorkflowProof) === true,
3994
+ workflowProofFingerprint: cleanText((_6 = workflowProofCheckpointGate.metadata) === null || _6 === void 0 ? void 0 : _6.workflowProofFingerprint, 200),
3995
+ artifactFingerprint: cleanText((_7 = workflowProofCheckpointGate.metadata) === null || _7 === void 0 ? void 0 : _7.artifactFingerprint, 200),
3996
+ blockers: cleanStringList((_8 = workflowProofCheckpointGate.metadata) === null || _8 === void 0 ? void 0 : _8.blockers, 20, 500)
3997
+ } : undefined,
3998
+ nextActionContract: nextActionContractGate ? {
3999
+ gateStatus: nextActionContractGate.status,
4000
+ contractId: cleanText((_9 = nextActionContractGate.metadata) === null || _9 === void 0 ? void 0 : _9.contractId, 200),
4001
+ action: cleanText((_10 = nextActionContractGate.metadata) === null || _10 === void 0 ? void 0 : _10.action, 120),
4002
+ label: cleanText((_11 = nextActionContractGate.metadata) === null || _11 === void 0 ? void 0 : _11.label, 200),
4003
+ primaryCommand: cleanText((_12 = nextActionContractGate.metadata) === null || _12 === void 0 ? void 0 : _12.primaryCommand, 200),
4004
+ lane: cleanText((_13 = nextActionContractGate.metadata) === null || _13 === void 0 ? void 0 : _13.lane, 120),
4005
+ stepType: cleanText((_14 = nextActionContractGate.metadata) === null || _14 === void 0 ? void 0 : _14.stepType, 120),
4006
+ safeToAutoRun: ((_15 = nextActionContractGate.metadata) === null || _15 === void 0 ? void 0 : _15.safeToAutoRun) === true,
4007
+ requiresHumanApproval: ((_16 = nextActionContractGate.metadata) === null || _16 === void 0 ? void 0 : _16.requiresHumanApproval) === true,
4008
+ canRunWithoutCodexMonitor: ((_17 = nextActionContractGate.metadata) === null || _17 === void 0 ? void 0 : _17.canRunWithoutCodexMonitor) === true,
4009
+ codexFallbackRequired: ((_18 = nextActionContractGate.metadata) === null || _18 === void 0 ? void 0 : _18.codexFallbackRequired) === true,
4010
+ costRisk: cleanText((_19 = nextActionContractGate.metadata) === null || _19 === void 0 ? void 0 : _19.costRisk, 120),
4011
+ workflowFirstSatisfied: ((_20 = nextActionContractGate.metadata) === null || _20 === void 0 ? void 0 : _20.workflowFirstSatisfied) === true,
4012
+ hotfixCommitRequired: ((_21 = nextActionContractGate.metadata) === null || _21 === void 0 ? void 0 : _21.hotfixCommitRequired) === true,
4013
+ liveHotfixBlockedUntilCommit: ((_22 = nextActionContractGate.metadata) === null || _22 === void 0 ? void 0 : _22.liveHotfixBlockedUntilCommit) === true,
4014
+ decisionBasis: plainObject((_23 = nextActionContractGate.metadata) === null || _23 === void 0 ? void 0 : _23.decisionBasis),
4015
+ preconditions: cleanStringList((_24 = nextActionContractGate.metadata) === null || _24 === void 0 ? void 0 : _24.preconditions, 20, 500),
4016
+ successEvidence: cleanStringList((_25 = nextActionContractGate.metadata) === null || _25 === void 0 ? void 0 : _25.successEvidence, 20, 500),
4017
+ requiredHotfixCommitProof: cleanStringList((_26 = nextActionContractGate.metadata) === null || _26 === void 0 ? void 0 : _26.requiredHotfixCommitProof, 20, 240),
4018
+ stopConditions: cleanStringList((_27 = nextActionContractGate.metadata) === null || _27 === void 0 ? void 0 : _27.stopConditions, 20, 500),
4019
+ forbiddenActions: cleanStringList((_28 = nextActionContractGate.metadata) === null || _28 === void 0 ? void 0 : _28.forbiddenActions, 20, 500),
4020
+ nextCommands: cleanStringList((_29 = nextActionContractGate.metadata) === null || _29 === void 0 ? void 0 : _29.nextCommands, 20, 240),
4021
+ blockers: cleanStringList((_30 = nextActionContractGate.metadata) === null || _30 === void 0 ? void 0 : _30.blockers, 20, 500)
4022
+ } : undefined
4023
+ }
4024
+ });
4025
+ }
4026
+ function buildAssistantAIRunFromEvidence(input) {
4027
+ var e_35, _a, e_36, _b, e_37, _c;
4028
+ var _d, _e, _f, _g;
4029
+ var conversation = input.conversation || {};
4030
+ var events = [];
4031
+ var sourceIds = {};
4032
+ addSourceId(sourceIds, 'runId', input.runId);
4033
+ addSourceId(sourceIds, 'requestId', input.requestId);
4034
+ addSourceId(sourceIds, 'messageId', input.messageId);
4035
+ addSourceId(sourceIds, 'conversationId', conversation._id || conversation.id || conversation.conversationId);
4036
+ addSourceId(sourceIds, 'userId', conversation.userId || conversation.ownerId);
4037
+ try {
4038
+ for (var _h = __values(asArray(input.messages)), _j = _h.next(); !_j.done; _j = _h.next()) {
4039
+ var message = _j.value;
4040
+ pushEvent(events, {
4041
+ type: 'assistant_message',
4042
+ category: cleanText(message.role || message.authorRole || message.type, 160),
4043
+ message: cleanText(message.content || message.text || message.message || message.summary, 1800),
4044
+ recordedAt: eventDate(message),
4045
+ metadata: {
4046
+ id: message._id || message.id,
4047
+ role: message.role,
4048
+ model: message.model || ((_d = message === null || message === void 0 ? void 0 : message.usage) === null || _d === void 0 ? void 0 : _d.model)
4049
+ }
4050
+ });
4051
+ }
4052
+ }
4053
+ catch (e_35_1) { e_35 = { error: e_35_1 }; }
4054
+ finally {
4055
+ try {
4056
+ if (_j && !_j.done && (_a = _h.return)) _a.call(_h);
4057
+ }
4058
+ finally { if (e_35) throw e_35.error; }
4059
+ }
4060
+ try {
4061
+ for (var _k = __values(asArray(input.issueReports)), _l = _k.next(); !_l.done; _l = _k.next()) {
4062
+ var report = _l.value;
4063
+ pushEvent(events, {
4064
+ type: 'human_intervention',
4065
+ category: cleanText(report.category || report.status || 'issue_report', 160),
4066
+ message: cleanText(report.summary || report.description || report.message || report.title, 1800),
4067
+ recordedAt: eventDate(report),
4068
+ metadata: {
4069
+ id: report._id || report.id,
4070
+ status: report.status,
4071
+ severity: report.severity
4072
+ }
4073
+ });
4074
+ }
4075
+ }
4076
+ catch (e_36_1) { e_36 = { error: e_36_1 }; }
4077
+ finally {
4078
+ try {
4079
+ if (_l && !_l.done && (_b = _k.return)) _b.call(_k);
4080
+ }
4081
+ finally { if (e_36) throw e_36.error; }
4082
+ }
4083
+ var cost = collectUsageEvents(asArray(input.usageLedger), events);
4084
+ var costGate = costObservabilityGate(cost, 'ai_assistant', input.now);
4085
+ pushEvent(events, {
4086
+ type: 'usage',
4087
+ category: 'cost_observability',
4088
+ message: costGate.reason,
4089
+ artifactPaths: costGate.evidenceRefs,
4090
+ recordedAt: costGate.recordedAt,
4091
+ metadata: costGate.metadata
4092
+ });
4093
+ var answerQuality = assistantQualityObject(input);
4094
+ try {
4095
+ for (var _m = __values(assistantQueryExecutions(answerQuality).slice(0, 40)), _o = _m.next(); !_o.done; _o = _m.next()) {
4096
+ var execution = _o.value;
4097
+ var status_1 = cleanText(execution.status || execution.queryStatus || execution.query_status || execution.resultStatus || execution.result_status, 120);
4098
+ var toolName = cleanText(execution.tool || execution.toolName || execution.tool_name || execution.type || 'query', 160);
4099
+ var collection = cleanText(execution.collection || execution.collectionName || execution.collection_name, 240);
4100
+ pushEvent(events, {
4101
+ type: 'assistant_query',
4102
+ category: status_1 || toolName,
4103
+ message: cleanText(execution.summary || execution.message || "".concat(toolName).concat(collection ? " ".concat(collection) : ''), 1200),
4104
+ artifactPaths: cleanStringList(__spreadArray(__spreadArray([
4105
+ execution.artifactPath,
4106
+ execution.artifact_path,
4107
+ execution.path
4108
+ ], __read(asArray(execution.artifactPaths)), false), __read(asArray(execution.artifact_paths)), false), 20, 500),
4109
+ recordedAt: eventDate(execution),
4110
+ metadata: {
4111
+ id: execution.id || execution._id || execution.ref,
4112
+ tool: toolName,
4113
+ status: status_1,
4114
+ collection: collection,
4115
+ resultCount: (_f = (_e = execution.resultCount) !== null && _e !== void 0 ? _e : execution.result_count) !== null && _f !== void 0 ? _f : execution.count,
4116
+ queryStatus: execution.queryStatus || execution.query_status,
4117
+ legalQueryShape: (_g = execution.legalQueryShape) !== null && _g !== void 0 ? _g : execution.legal_query_shape
4118
+ }
4119
+ });
4120
+ }
4121
+ }
4122
+ catch (e_37_1) { e_37 = { error: e_37_1 }; }
4123
+ finally {
4124
+ try {
4125
+ if (_o && !_o.done && (_c = _m.return)) _c.call(_m);
4126
+ }
4127
+ finally { if (e_37) throw e_37.error; }
4128
+ }
4129
+ var answerQualityDecision = evaluateAssistantAnswerQuality({
4130
+ answerQuality: answerQuality,
4131
+ correctnessChecks: input.correctnessChecks,
4132
+ now: input.now
4133
+ });
4134
+ var answerQualityGate = assistantAnswerQualityGate(answerQualityDecision, input.now);
4135
+ pushEvent(events, {
4136
+ type: 'assistant_message',
4137
+ category: 'assistant_answer_quality',
4138
+ message: answerQualityGate.reason,
4139
+ artifactPaths: answerQualityGate.evidenceRefs,
4140
+ recordedAt: answerQualityGate.recordedAt,
4141
+ metadata: answerQualityGate.metadata
4142
+ });
4143
+ var answerActionabilityContract = buildAssistantAnswerActionabilityContract(answerQualityDecision, input.now);
4144
+ var answerActionabilityGate = assistantAnswerActionabilityGate(answerActionabilityContract, input.now);
4145
+ pushEvent(events, {
4146
+ type: 'assistant_message',
4147
+ category: 'assistant_answer_actionability',
4148
+ message: answerActionabilityGate.reason,
4149
+ artifactPaths: answerActionabilityGate.evidenceRefs,
4150
+ recordedAt: answerActionabilityGate.recordedAt,
4151
+ metadata: answerActionabilityGate.metadata
4152
+ });
4153
+ var correctnessChecks = asArray(input.correctnessChecks);
4154
+ var hasPassedCorrectnessCheck = correctnessChecks.some(function (check) { return /^(pass|passed|success|ok)$/i.test(cleanText(check.status || (check.passed === true ? 'pass' : ''), 80)); });
4155
+ var correctnessEvidence = {
4156
+ businessAssertions: __spreadArray(__spreadArray([], __read(correctnessChecks.map(function (check) { return ({
4157
+ assertion: check.assertion || check.name || check.case || 'assistant correctness check',
4158
+ status: check.status || statusFromBoolean(check.passed),
4159
+ expected: check.expected,
4160
+ observed: check.observed || check.actual,
4161
+ dataProof: check.dataProof || check.proof,
4162
+ artifactPaths: check.artifactPaths,
4163
+ message: check.message || check.reason,
4164
+ metadata: check.metadata,
4165
+ recordedAt: eventDate(check)
4166
+ }); })), false), __read((answerQualityDecision.ready && !hasPassedCorrectnessCheck ? [{
4167
+ assertion: 'Assistant answer quality gate passed.',
4168
+ status: 'pass',
4169
+ expected: 'Correct dates, legal query shape, query result classification, cited evidence, confidence, and next action.',
4170
+ observed: answerQualityDecision.reason,
4171
+ dataProof: answerQualityDecision.evidenceRefs.concat(answerQualityDecision.citationRefs).join(', '),
4172
+ artifactPaths: answerQualityDecision.evidenceRefs,
4173
+ message: answerQualityDecision.reason,
4174
+ metadata: {
4175
+ answerQualityStatus: answerQualityDecision.status,
4176
+ queryStatus: answerQualityDecision.queryStatus,
4177
+ dateWindowRequired: answerQualityDecision.dateWindowRequired,
4178
+ dateWindowPresent: answerQualityDecision.dateWindowPresent,
4179
+ dateWindow: answerQualityDecision.dateWindow
4180
+ }
4181
+ }] : [])), false)
4182
+ };
4183
+ var qa = applyAssistantAnswerQualityGate(buildQaFromEvidence(correctnessEvidence, input.now), answerQualityDecision, input.now);
4184
+ var failedReports = asArray(input.issueReports)
4185
+ .filter(function (report) { return /open|new|fail|bug|wrong|incorrect|error/i.test("".concat(report.status || '', " ").concat(report.category || '', " ").concat(report.summary || '')); });
4186
+ return (0, ai_run_evidence_1.buildAIRun)({
4187
+ id: cleanText(input.runId, 240) || undefined,
4188
+ source: 'ai_assistant',
4189
+ sourceIds: sourceIds,
4190
+ title: firstText(conversation, ['title', 'subject', 'summary']) || 'AI assistant conversation',
4191
+ status: firstText(conversation, ['status', 'state']),
4192
+ phase: firstText(conversation, ['phase']),
4193
+ startedAt: dateValue(conversation, ['startedAt', 'createdAt']),
4194
+ completedAt: dateValue(conversation, ['completedAt', 'closedAt', 'updatedAt']),
4195
+ events: events,
4196
+ gates: [answerActionabilityGate, costGate],
4197
+ qa: qa,
4198
+ cost: cost,
4199
+ rejected: failedReports.length > 0 || conversation.rejected === true,
4200
+ manualHandoff: conversation.manualHandoff === true,
4201
+ stopped: conversation.stopped === true,
4202
+ explicitAccepted: conversation.accepted === true,
4203
+ terminal: /complete|closed|resolved|done|failed|rejected/i.test("".concat(conversation.status || '')),
4204
+ now: input.now,
4205
+ metadata: {
4206
+ issueReportCount: asArray(input.issueReports).length,
4207
+ correctnessCheckCount: correctnessChecks.length,
4208
+ costObservability: costObservabilityMetadata(costGate),
4209
+ answerQuality: {
4210
+ ready: answerQualityDecision.ready,
4211
+ status: answerQualityDecision.status,
4212
+ queryStatus: answerQualityDecision.queryStatus,
4213
+ confidenceLevel: answerQualityDecision.confidenceLevel,
4214
+ dateBasis: answerQualityDecision.dateBasis,
4215
+ expectedCurrentDate: answerQualityDecision.expectedCurrentDate,
4216
+ dateWindowRequired: answerQualityDecision.dateWindowRequired,
4217
+ dateWindowPresent: answerQualityDecision.dateWindowPresent,
4218
+ dateWindow: answerQualityDecision.dateWindow,
4219
+ noDataConfirmed: answerQualityDecision.noDataConfirmed,
4220
+ legalQueryShape: answerQualityDecision.legalQueryShape,
4221
+ citationRefs: answerQualityDecision.citationRefs,
4222
+ queryEvidenceRequired: answerQualityDecision.queryEvidenceRequired,
4223
+ queryEvidencePresent: answerQualityDecision.queryEvidencePresent,
4224
+ queryEvidenceRefs: answerQualityDecision.queryEvidenceRefs,
4225
+ queryExecutionCount: answerQualityDecision.queryExecutionCount,
4226
+ nextActions: answerQualityDecision.nextActions,
4227
+ blockers: answerQualityDecision.blockers
4228
+ },
4229
+ answerActionability: {
4230
+ contractId: answerActionabilityContract.contractId,
4231
+ status: answerActionabilityContract.status,
4232
+ primaryCommand: answerActionabilityContract.primaryCommand,
4233
+ label: answerActionabilityContract.label,
4234
+ canAnswerCustomer: answerActionabilityContract.canAnswerCustomer,
4235
+ canDraftSupportReply: answerActionabilityContract.canDraftSupportReply,
4236
+ canSendCustomerReply: answerActionabilityContract.canSendCustomerReply,
4237
+ requiresHumanReview: answerActionabilityContract.requiresHumanReview,
4238
+ canRunWithoutCodexMonitor: answerActionabilityContract.canRunWithoutCodexMonitor,
4239
+ codexFallbackRequired: answerActionabilityContract.codexFallbackRequired,
4240
+ costRisk: answerActionabilityContract.costRisk,
4241
+ queryResultClass: answerActionabilityContract.queryResultClass,
4242
+ confidenceLevel: answerActionabilityContract.confidenceLevel,
4243
+ decisionBasis: answerActionabilityContract.decisionBasis,
4244
+ requiredEvidence: answerActionabilityContract.requiredEvidence,
4245
+ successEvidence: answerActionabilityContract.successEvidence,
4246
+ blockers: answerActionabilityContract.blockers,
4247
+ nextActions: answerActionabilityContract.nextActions,
4248
+ nextCommands: answerActionabilityContract.nextCommands,
4249
+ forbiddenActions: answerActionabilityContract.forbiddenActions
4250
+ }
4251
+ }
4252
+ });
4253
+ }
4254
+
4255
+ //# sourceMappingURL=ai-run-evidence-adapters.js.map