@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
@@ -1,4806 +0,0 @@
1
- export type ResolveIOAIManagerAction =
2
- | 'continue'
3
- | 'retry_infra'
4
- | 'reset_loop_budget'
5
- | 'park_repeated_failure'
6
- | 'park_ping_pong'
7
- | 'manual_handoff';
8
-
9
- export interface ResolveIOAIManagerFailureRecord {
10
- outcome?: string;
11
- lane?: string;
12
- stepType?: string;
13
- failureClass?: string;
14
- blocker?: string;
15
- blockerFingerprint?: string;
16
- evidenceHash?: string;
17
- changedFiles?: string[];
18
- artifactPaths?: string[];
19
- summary?: string;
20
- recordedAt?: Date | string;
21
- }
22
-
23
- export type ResolveIOAIManagerEvidenceStrength = 'none' | 'weak' | 'material' | 'proof';
24
-
25
- export interface ResolveIOAIManagerEvidenceAssessment {
26
- changed: boolean;
27
- material: boolean;
28
- strength: ResolveIOAIManagerEvidenceStrength;
29
- signals: string[];
30
- evidenceHash: string;
31
- blockerFingerprint: string;
32
- }
33
-
34
- export type ResolveIOAIManagerRecoveryClass =
35
- | 'advance_after_proof'
36
- | 'diagnosis_only'
37
- | 'diagnosis_revision'
38
- | 'infra_repair'
39
- | 'compile_repair'
40
- | 'journey_contract_repair'
41
- | 'business_proof_repair'
42
- | 'release_repair'
43
- | 'product_code_repair'
44
- | 'blocked_until_new_evidence'
45
- | 'manual_handoff'
46
- | 'continue';
47
-
48
- export interface ResolveIOAIManagerRecoveryPlan {
49
- recoveryClass: ResolveIOAIManagerRecoveryClass;
50
- lane: string;
51
- stepType: string;
52
- nextActionLabel: string;
53
- objective: string;
54
- allowedAction: string;
55
- productRepairAllowed: boolean;
56
- expensiveModelAllowed: boolean;
57
- maxAttemptsBeforePark: number;
58
- finiteSteps: string[];
59
- requiredEvidence: string[];
60
- loopResetEvidence: string[];
61
- forbiddenActions: string[];
62
- notes: string[];
63
- }
64
-
65
- export type ResolveIOAIManagerRecoveryCheckpointStatus =
66
- | 'active'
67
- | 'parked'
68
- | 'manual_handoff'
69
- | 'complete';
70
-
71
- export interface ResolveIOAIManagerRecoveryCheckpoint {
72
- checkpointId: string;
73
- recoveryClass: ResolveIOAIManagerRecoveryClass;
74
- status: ResolveIOAIManagerRecoveryCheckpointStatus;
75
- lane: string;
76
- stepType: string;
77
- allowedAction: string;
78
- productRepairAllowed: boolean;
79
- expensiveModelAllowed: boolean;
80
- attempts: number;
81
- maxAttemptsBeforePark: number;
82
- blockerFingerprint: string;
83
- evidenceHash: string;
84
- changedFiles: string[];
85
- artifactPaths: string[];
86
- requiredEvidence: string[];
87
- loopResetEvidence: string[];
88
- forbiddenActions: string[];
89
- objective: string;
90
- nextActionLabel: string;
91
- createdAt: string;
92
- updatedAt: string;
93
- }
94
-
95
- export type ResolveIOAIManagerRecoveryEvidenceProbeStepKind =
96
- | 'read_only_diagnosis'
97
- | 'rerun_same_gate'
98
- | 'infra_preflight'
99
- | 'compile_check'
100
- | 'route_probe'
101
- | 'business_assertion'
102
- | 'journey_validation'
103
- | 'release_status'
104
- | 'diff_scope_check'
105
- | 'operator_review';
106
-
107
- export interface ResolveIOAIManagerRecoveryEvidenceProbeStep {
108
- id: string;
109
- kind: ResolveIOAIManagerRecoveryEvidenceProbeStepKind;
110
- label: string;
111
- objective: string;
112
- required: boolean;
113
- commandHint?: string;
114
- artifactExpectation: string;
115
- successSignal: string;
116
- }
117
-
118
- export interface ResolveIOAIManagerRecoveryEvidenceProbe {
119
- probeId: string;
120
- checkpointId: string;
121
- recoveryClass: ResolveIOAIManagerRecoveryClass;
122
- lane: string;
123
- stepType: string;
124
- objective: string;
125
- evidenceOnly: boolean;
126
- productRepairAllowed: boolean;
127
- expensiveModelAllowed: boolean;
128
- evidenceHashBefore: string;
129
- blockerFingerprint: string;
130
- steps: ResolveIOAIManagerRecoveryEvidenceProbeStep[];
131
- requiredArtifacts: string[];
132
- acceptanceEvidence: string[];
133
- stopConditions: string[];
134
- loopResetEvidence: string[];
135
- createdAt: string;
136
- }
137
-
138
- export type ResolveIOAIManagerRecoveryAutomationMode =
139
- | 'advance'
140
- | 'collect_evidence'
141
- | 'read_only_diagnosis'
142
- | 'repair_infra'
143
- | 'repair_compile'
144
- | 'repair_journey_contract'
145
- | 'repair_business_assertion'
146
- | 'repair_release'
147
- | 'targeted_product_repair'
148
- | 'manual_review'
149
- | 'continue_gate';
150
-
151
- export interface ResolveIOAIManagerRecoveryActionRetryPolicy {
152
- allowImmediateRetry: boolean;
153
- requireNewEvidence: boolean;
154
- resetLoopWhen: string[];
155
- stopWhen: string[];
156
- }
157
-
158
- export type ResolveIOAIManagerHotfixFirstReleaseAction =
159
- | 'wait_for_active_deploy'
160
- | 'block_duplicate_deploy'
161
- | 'block_duplicate_publish'
162
- | 'review_force_deploy'
163
- | 'hotfix_release_artifact'
164
- | 'deploy_new_artifact_after_release_gate'
165
- | 'build_artifact_first';
166
-
167
- export type ResolveIOAIManagerHotfixChannel =
168
- | 'static_ui'
169
- | 'backend_js'
170
- | 'config'
171
- | 'seed_data'
172
- | 'cache_invalidation'
173
- | 'service_restart'
174
- | 'release_artifact'
175
- | 'force_deploy_review'
176
- | 'new_artifact_deploy'
177
- | 'artifact_build';
178
-
179
- export interface ResolveIOAIManagerHotfixPlanStep {
180
- id: string;
181
- label: string;
182
- channel: ResolveIOAIManagerHotfixChannel;
183
- safeToAutoRun: boolean;
184
- requiresFullDeploy: boolean;
185
- requiredEvidence: string[];
186
- successEvidence: string[];
187
- blockedBy: string[];
188
- }
189
-
190
- export interface ResolveIOAIManagerHotfixPlan {
191
- planId: string;
192
- label: string;
193
- recommendedChannel: ResolveIOAIManagerHotfixChannel;
194
- reason: string;
195
- fullDeployAvoided: boolean;
196
- steps: ResolveIOAIManagerHotfixPlanStep[];
197
- acceptanceEvidence: string[];
198
- escalationTriggers: string[];
199
- }
200
-
201
- export interface ResolveIOAIManagerHotfixFirstReleasePolicyInput {
202
- surface?: string;
203
- activeDeploy?: boolean;
204
- deployFingerprint?: string;
205
- lastDeployFingerprint?: string;
206
- publishFingerprint?: string;
207
- lastPublishFingerprint?: string;
208
- deployStatus?: string;
209
- publishStatus?: string;
210
- sampleDataStatus?: string;
211
- forceDeploy?: boolean;
212
- forcePublish?: boolean;
213
- hasNewArtifact?: boolean;
214
- }
215
-
216
- export interface ResolveIOAIManagerHotfixFirstReleasePolicy {
217
- policy: 'hotfix_first';
218
- surface: string;
219
- recommendedAction: ResolveIOAIManagerHotfixFirstReleaseAction;
220
- label: string;
221
- reason: string;
222
- hotfixPreferred: boolean;
223
- fullDeployAllowed: boolean;
224
- duplicateDeployBlocked: boolean;
225
- duplicatePublishBlocked: boolean;
226
- forceDeployRequiredToRepeat: boolean;
227
- forcePublishRequiredToRepeat: boolean;
228
- statuses: {
229
- deploy: string;
230
- publish: string;
231
- sampleData: string;
232
- };
233
- fingerprints: {
234
- current: string;
235
- last: string;
236
- matchesLast: boolean;
237
- publishCurrent: string;
238
- publishLast: string;
239
- publishMatchesLast: boolean;
240
- };
241
- hotfixPlan: ResolveIOAIManagerHotfixPlan;
242
- allowedActions: string[];
243
- forbiddenActions: string[];
244
- requiredEvidence: string[];
245
- }
246
-
247
- export type ResolveIOAIManagerHotfixEvidenceStatus =
248
- | 'missing'
249
- | 'incomplete'
250
- | 'passed'
251
- | 'blocked';
252
-
253
- export interface ResolveIOAIManagerHotfixEvidenceTarget {
254
- surface?: string;
255
- host?: string;
256
- path?: string;
257
- artifactPath?: string;
258
- bucket?: string;
259
- distributionId?: string;
260
- processName?: string;
261
- configKey?: string;
262
- cacheKey?: string;
263
- seedKey?: string;
264
- }
265
-
266
- export interface ResolveIOAIManagerHotfixEvidence {
267
- channel: ResolveIOAIManagerHotfixChannel;
268
- status?: ResolveIOAIManagerHotfixEvidenceStatus | string;
269
- target: ResolveIOAIManagerHotfixEvidenceTarget;
270
- compiledArtifactPath?: string;
271
- builtDistPath?: string;
272
- remoteChecksumBefore?: string;
273
- remoteChecksumAfter?: string;
274
- remoteChecksum?: string;
275
- restartEvidence?: string;
276
- healthCheckStatus?: string;
277
- selfTestStatus?: string;
278
- releaseGateStatus?: string;
279
- s3UploadResult?: string;
280
- cloudfrontInvalidationId?: string;
281
- publicProof?: string;
282
- configChangeEvidence?: string;
283
- seedDataEvidence?: string;
284
- cacheInvalidationEvidence?: string;
285
- serviceRestartEvidence?: string;
286
- releaseArtifactFingerprint?: string;
287
- lastReleaseArtifactFingerprint?: string;
288
- sourceCommitSha?: string;
289
- githubCommitUrl?: string;
290
- gitCommitStatus?: string;
291
- gitPushStatus?: string;
292
- committedAt?: Date | string;
293
- forceDeployReason?: string;
294
- hotfixCannotResolveReason?: string;
295
- fullDeployRequested?: boolean;
296
- recordedAt?: Date | string;
297
- }
298
-
299
- export interface ResolveIOAIManagerHotfixEvidenceValidation {
300
- valid: boolean;
301
- status: ResolveIOAIManagerHotfixEvidenceStatus;
302
- channel: ResolveIOAIManagerHotfixChannel | '';
303
- blockers: string[];
304
- warnings: string[];
305
- fullDeployAllowed: boolean;
306
- fullDeployBlocked: boolean;
307
- hotfixSatisfied: boolean;
308
- requiredEvidence: string[];
309
- successEvidence: string[];
310
- normalized?: ResolveIOAIManagerHotfixEvidence;
311
- githubCommitGuard: ResolveIOAIManagerHotfixGitProof;
312
- policy?: ResolveIOAIManagerHotfixFirstReleasePolicy;
313
- nextAction: 'record_hotfix_evidence' | 'rerun_release_gate' | 'request_force_deploy_reason' | 'allow_one_full_deploy' | 'park_manual';
314
- }
315
-
316
- export type ResolveIOAIManagerHotfixGitProofStatus =
317
- | 'not_required'
318
- | 'missing'
319
- | 'invalid'
320
- | 'passed';
321
-
322
- export interface ResolveIOAIManagerHotfixGitProof {
323
- required: boolean;
324
- status: ResolveIOAIManagerHotfixGitProofStatus;
325
- passed: boolean;
326
- managerMustCommitBeforeHotfix: boolean;
327
- channel: ResolveIOAIManagerHotfixChannel | '';
328
- sourceCommitSha: string;
329
- githubCommitUrl: string;
330
- githubCommitSha: string;
331
- gitCommitStatus: string;
332
- gitPushStatus: string;
333
- blockers: string[];
334
- nextCommands: string[];
335
- requiredEvidence: string[];
336
- }
337
-
338
- export type ResolveIOAIManagerHotfixContinuationAction =
339
- | 'record_hotfix_evidence'
340
- | 'rerun_release_gate'
341
- | 'continue_runner'
342
- | 'request_force_deploy_reason'
343
- | 'allow_one_full_deploy'
344
- | 'park_manual';
345
-
346
- export interface ResolveIOAIManagerHotfixContinuationInput {
347
- evidence?: any;
348
- policy?: ResolveIOAIManagerHotfixFirstReleasePolicy;
349
- releaseGatePassed?: boolean;
350
- repeatedFailure?: boolean;
351
- failureClass?: string;
352
- blocker?: string;
353
- now?: Date | string;
354
- }
355
-
356
- export interface ResolveIOAIManagerHotfixContinuationDecision {
357
- action: ResolveIOAIManagerHotfixContinuationAction;
358
- canContinueRun: boolean;
359
- canRunFullDeploy: boolean;
360
- shouldRerunReleaseGate: boolean;
361
- shouldPark: boolean;
362
- reason: string;
363
- blockers: string[];
364
- warnings: string[];
365
- requiredEvidence: string[];
366
- successEvidence: string[];
367
- nextCommands: string[];
368
- failureClass: string;
369
- blockerFingerprint: string;
370
- githubCommitGuard: ResolveIOAIManagerHotfixGitProof;
371
- validation: ResolveIOAIManagerHotfixEvidenceValidation;
372
- recordedAt: string;
373
- }
374
-
375
- export interface ResolveIOAIManagerHotfixCommitGuardDecision {
376
- active: boolean;
377
- blocked: boolean;
378
- reason: string;
379
- nextAction: 'record_hotfix_evidence' | 'continue';
380
- channel: ResolveIOAIManagerHotfixChannel | '';
381
- blockers: string[];
382
- nextCommands: string[];
383
- requiredEvidence: string[];
384
- githubCommitGuard: ResolveIOAIManagerHotfixGitProof;
385
- validation: ResolveIOAIManagerHotfixEvidenceValidation;
386
- }
387
-
388
- export type ResolveIOAIManagerHotfixEvidenceRecordSource =
389
- | 'manual'
390
- | 'manager'
391
- | 'runner_console'
392
- | 'hotfix_script'
393
- | 'deploy_script'
394
- | 'unknown';
395
-
396
- export interface ResolveIOAIManagerHotfixEvidenceRecordInput extends Partial<ResolveIOAIManagerHotfixEvidence> {
397
- evidence?: any;
398
- policy?: ResolveIOAIManagerHotfixFirstReleasePolicy;
399
- recordId?: string;
400
- reason?: string;
401
- recordedBy?: string;
402
- source?: ResolveIOAIManagerHotfixEvidenceRecordSource | string;
403
- now?: Date | string;
404
- }
405
-
406
- export interface ResolveIOAIManagerHotfixEvidenceRecord {
407
- recordId: string;
408
- recordedAt: string;
409
- recordedBy: string;
410
- source: ResolveIOAIManagerHotfixEvidenceRecordSource | string;
411
- reason: string;
412
- channel: ResolveIOAIManagerHotfixChannel | '';
413
- status: ResolveIOAIManagerHotfixEvidenceStatus;
414
- nextAction: ResolveIOAIManagerHotfixEvidenceValidation['nextAction'];
415
- valid: boolean;
416
- hotfixSatisfied: boolean;
417
- fullDeployAllowed: boolean;
418
- fullDeployBlocked: boolean;
419
- requiredFields: string[];
420
- missingFields: string[];
421
- evidence: ResolveIOAIManagerHotfixEvidence | undefined;
422
- validation: ResolveIOAIManagerHotfixEvidenceValidation;
423
- sourceCommitSha: string;
424
- githubCommitUrl: string;
425
- gitCommitStatus: string;
426
- gitPushStatus: string;
427
- githubCommitRequired: boolean;
428
- githubCommitProofPassed: boolean;
429
- commitProofStatus: 'not_required' | 'missing' | 'invalid' | 'passed';
430
- commitFirstProtocol: 'not_required' | 'commit_first_hotfix';
431
- commit_first_protocol: 'not_required' | 'commit_first_hotfix';
432
- commitFirstProtocolSatisfied: boolean;
433
- commit_first_protocol_satisfied: boolean;
434
- liveHotfixBlockedUntilCommit: boolean;
435
- live_hotfix_blocked_until_commit: boolean;
436
- liveHotfixAllowed: boolean;
437
- live_hotfix_allowed: boolean;
438
- managerMustCommitBeforeHotfix: boolean;
439
- githubCommitGuard: ResolveIOAIManagerHotfixGitProof;
440
- readyForReleaseGate: boolean;
441
- readyForContinuation: boolean;
442
- managerContinuationAllowed: boolean;
443
- manager_continuation_allowed: boolean;
444
- }
445
-
446
- export type ResolveIOAIManagerHotfixDurabilityStatus =
447
- | 'not_required'
448
- | 'waiting_for_commit_proof'
449
- | 'ready_for_live_hotfix'
450
- | 'ready_for_release_gate'
451
- | 'ready_for_continuation';
452
-
453
- export interface ResolveIOAIManagerHotfixDurabilityContractInput {
454
- action?: string;
455
- reason?: string;
456
- evidence?: any;
457
- policy?: ResolveIOAIManagerHotfixFirstReleasePolicy;
458
- continuation?: Partial<ResolveIOAIManagerHotfixContinuationDecision> | null;
459
- existing?: any;
460
- source?: string;
461
- releaseGatePassed?: boolean;
462
- now?: Date | string;
463
- }
464
-
465
- export interface ResolveIOAIManagerHotfixDurabilityContract {
466
- contractId: string;
467
- contract_id: string;
468
- createdAt: string;
469
- created_at: string;
470
- updatedAt: string;
471
- updated_at: string;
472
- source: string;
473
- required: boolean;
474
- action: string;
475
- status: ResolveIOAIManagerHotfixDurabilityStatus;
476
- reason: string;
477
- canPrepareHotfixPatch: boolean;
478
- can_prepare_hotfix_patch: boolean;
479
- canHotfixBackend: boolean;
480
- can_hotfix_backend: boolean;
481
- liveHotfixBlockedUntilCommit: boolean;
482
- live_hotfix_blocked_until_commit: boolean;
483
- durabilityProtocol: 'not_required' | 'commit_first_hotfix';
484
- durability_protocol: 'not_required' | 'commit_first_hotfix';
485
- commitFirstProtocolRequired: boolean;
486
- commit_first_protocol_required: boolean;
487
- commitFirstProtocolSatisfied: boolean;
488
- commit_first_protocol_satisfied: boolean;
489
- liveHotfixAllowed: boolean;
490
- live_hotfix_allowed: boolean;
491
- managerContinuationAllowed: boolean;
492
- manager_continuation_allowed: boolean;
493
- commitProofPassed: boolean;
494
- commit_proof_passed: boolean;
495
- commitProofStatus: ResolveIOAIManagerHotfixGitProofStatus | 'missing';
496
- commit_proof_status: ResolveIOAIManagerHotfixGitProofStatus | 'missing';
497
- sourceCommitSha: string;
498
- source_commit_sha: string;
499
- githubCommitUrl: string;
500
- github_commit_url: string;
501
- gitCommitStatus: string;
502
- git_commit_status: string;
503
- gitPushStatus: string;
504
- git_push_status: string;
505
- missingCommitProofFields: string[];
506
- missing_commit_proof_fields: string[];
507
- nextSafeAction: string;
508
- next_safe_action: string;
509
- phaseOrder: string[];
510
- phase_order: string[];
511
- requiredFields: string[];
512
- required_fields: string[];
513
- requiredEvidence: string[];
514
- required_evidence: string[];
515
- successCriteria: string[];
516
- success_criteria: string[];
517
- forbiddenActions: string[];
518
- forbidden_actions: string[];
519
- hotfixCommitGuard: Record<string, any>;
520
- hotfix_commit_guard: Record<string, any>;
521
- githubCommitGuard: ResolveIOAIManagerHotfixGitProof;
522
- github_commit_guard: ResolveIOAIManagerHotfixGitProof;
523
- validation: ResolveIOAIManagerHotfixEvidenceValidation;
524
- continuation?: Partial<ResolveIOAIManagerHotfixContinuationDecision> | null;
525
- extraRequest: string;
526
- extra_request: string;
527
- }
528
-
529
- export interface ResolveIOAIManagerRecoveryActionPacket {
530
- actionId: string;
531
- checkpointId: string;
532
- probeId: string;
533
- recoveryClass: ResolveIOAIManagerRecoveryClass;
534
- mode: ResolveIOAIManagerRecoveryAutomationMode;
535
- singleActionOnly: boolean;
536
- allowedDispatchAction: ResolveIOAIManagerRecoveryActionDispatchAction;
537
- label: string;
538
- lane: string;
539
- stepType: string;
540
- primaryStepKind: ResolveIOAIManagerRecoveryEvidenceProbeStepKind | 'none';
541
- objective: string;
542
- evidenceOnly: boolean;
543
- autoRunnable: boolean;
544
- productRepairAllowed: boolean;
545
- expensiveModelAllowed: boolean;
546
- costCeilingUsd: number;
547
- requiredStateTransition: string;
548
- proofRequiredBeforeContinuation: boolean;
549
- canResetLoopAfterEvidence: boolean;
550
- maxAttemptsBeforePark: number;
551
- requiredArtifacts: string[];
552
- nextCommands: string[];
553
- successCriteria: string[];
554
- exitCriteria: string[];
555
- retryPolicy: ResolveIOAIManagerRecoveryActionRetryPolicy;
556
- releasePolicy?: ResolveIOAIManagerHotfixFirstReleasePolicy;
557
- blockedReason?: string;
558
- createdAt: string;
559
- }
560
-
561
- export type ResolveIOAIManagerRecoveryActionDispatchAction =
562
- | 'run_evidence_probe'
563
- | 'run_read_only_diagnosis'
564
- | 'run_infra_repair'
565
- | 'run_compile_repair'
566
- | 'run_journey_contract_repair'
567
- | 'run_business_assertion_repair'
568
- | 'run_release_repair'
569
- | 'run_targeted_product_repair'
570
- | 'advance'
571
- | 'continue_gate'
572
- | 'park_manual';
573
-
574
- export interface ResolveIOAIManagerAutoDispatchPolicyInput {
575
- dispatchAction?: ResolveIOAIManagerRecoveryActionDispatchAction | string;
576
- directive?: Partial<ResolveIOAIManagerRecoveryExecutionDirective>;
577
- action?: Partial<ResolveIOAIManagerRecoveryActionPacket>;
578
- includeJourneyContractRepair?: boolean;
579
- includeReleaseRepair?: boolean;
580
- includeBusinessProofRepair?: boolean;
581
- includeProductRepair?: boolean;
582
- }
583
-
584
- export type ResolveIOAIManagerRecoveryActionDispatchStatus =
585
- | 'queued'
586
- | 'started'
587
- | 'completed'
588
- | 'failed'
589
- | 'parked';
590
-
591
- export interface ResolveIOAIManagerRecoveryActionDispatchRecord {
592
- dispatchId: string;
593
- actionId: string;
594
- checkpointId: string;
595
- probeId: string;
596
- mode: ResolveIOAIManagerRecoveryAutomationMode;
597
- dispatchAction: ResolveIOAIManagerRecoveryActionDispatchAction;
598
- status: ResolveIOAIManagerRecoveryActionDispatchStatus;
599
- evidenceHash: string;
600
- blockerFingerprint: string;
601
- productRepairAllowed: boolean;
602
- expensiveModelAllowed: boolean;
603
- reason: string;
604
- artifactPaths: string[];
605
- startedAt?: string;
606
- completedAt?: string;
607
- createdAt: string;
608
- }
609
-
610
- export interface ResolveIOAIManagerRecoveryActionDispatchInput {
611
- action?: ResolveIOAIManagerRecoveryActionPacket;
612
- history?: ResolveIOAIManagerRecoveryActionDispatchRecord[];
613
- current?: ResolveIOAIManagerFailureRecord;
614
- autonomyPolicy?: ResolveIOAIManagerAutonomyPolicyInput;
615
- operatorApproved?: boolean;
616
- now?: Date | string;
617
- }
618
-
619
- export interface ResolveIOAIManagerRecoveryActionDispatchDecision {
620
- dispatchAction: ResolveIOAIManagerRecoveryActionDispatchAction;
621
- allowed: boolean;
622
- reason: string;
623
- status: ResolveIOAIManagerRecoveryActionDispatchStatus;
624
- canRunProductRepair: boolean;
625
- canRunExpensiveModel: boolean;
626
- shouldRecordDispatch: boolean;
627
- requiresNewEvidence: boolean;
628
- newEvidence: boolean;
629
- autonomyPolicy?: ResolveIOAIManagerAutonomyPolicyDecision;
630
- dispatchRecord?: ResolveIOAIManagerRecoveryActionDispatchRecord;
631
- }
632
-
633
- export type ResolveIOAIManagerAutonomyMode =
634
- | 'manual_only'
635
- | 'monitor_only'
636
- | 'auto_retry_within_budget';
637
-
638
- export interface ResolveIOAIManagerAutonomyPolicyInput {
639
- mode?: ResolveIOAIManagerAutonomyMode | string;
640
- currentSpendUsd?: number;
641
- budgetSoftUsd?: number;
642
- budgetHardUsd?: number;
643
- projectedActionCostUsd?: number;
644
- dispatchAction?: ResolveIOAIManagerRecoveryActionDispatchAction | string;
645
- expectedValueScore?: number;
646
- minExpectedValueScore?: number;
647
- evidenceStrength?: ResolveIOAIManagerEvidenceStrength | string;
648
- materialEvidence?: boolean;
649
- newEvidence?: boolean;
650
- evidenceSignals?: string[];
651
- sameEvidenceAlreadyAttempted?: boolean;
652
- allowEvidenceProbeWithoutExpectedValue?: boolean;
653
- operatorApproved?: boolean;
654
- }
655
-
656
- export interface ResolveIOAIManagerRetryExpectedValueInput {
657
- dispatchAction?: ResolveIOAIManagerRecoveryActionDispatchAction | string;
658
- projectedActionCostUsd?: number;
659
- currentSpendUsd?: number;
660
- budgetHardUsd?: number;
661
- failureClass?: string;
662
- recoveryClass?: ResolveIOAIManagerRecoveryClass | string;
663
- evidenceStrength?: ResolveIOAIManagerEvidenceStrength | string;
664
- materialEvidence?: boolean;
665
- newEvidence?: boolean;
666
- evidenceSignals?: string[];
667
- sameEvidenceAlreadyAttempted?: boolean;
668
- }
669
-
670
- export interface ResolveIOAIManagerRetryExpectedValueEstimate {
671
- score: number;
672
- minScore: number;
673
- positive: boolean;
674
- source: 'estimated';
675
- confidence: 'low' | 'medium' | 'high';
676
- reason: string;
677
- signals: string[];
678
- }
679
-
680
- export interface ResolveIOAIManagerAutonomyPolicyDecision {
681
- mode: ResolveIOAIManagerAutonomyMode;
682
- canAutoDispatch: boolean;
683
- canManualDispatch: boolean;
684
- blocked: boolean;
685
- requiresHumanApproval: boolean;
686
- reason: string;
687
- currentSpendUsd: number;
688
- projectedActionCostUsd: number;
689
- projectedSpendUsd: number;
690
- budgetSoftUsd: number;
691
- budgetHardUsd: number;
692
- softBudgetExceeded: boolean;
693
- hardBudgetExceeded: boolean;
694
- dispatchAction: string;
695
- expectedValueScore: number;
696
- minExpectedValueScore: number;
697
- expectedValueKnown: boolean;
698
- expectedValueSource: 'provided' | 'estimated';
699
- expectedValuePositive: boolean;
700
- evidenceStrength: ResolveIOAIManagerEvidenceStrength;
701
- materialEvidence: boolean;
702
- newEvidence: boolean;
703
- evidenceBacked: boolean;
704
- evidenceSignals: string[];
705
- recommendedControl: 'manual_only' | 'monitor_only' | 'auto_retry_within_budget' | 'increase_budget_or_manual';
706
- forbiddenActions: string[];
707
- requiredEvidence: string[];
708
- }
709
-
710
- export type ResolveIOAIManagerRecoveryExecutionPhase =
711
- | 'evidence'
712
- | 'diagnosis'
713
- | 'infra'
714
- | 'compile'
715
- | 'journey'
716
- | 'business_proof'
717
- | 'release'
718
- | 'product_repair'
719
- | 'advance'
720
- | 'manual';
721
-
722
- export interface ResolveIOAIManagerRecoveryExecutionDirectiveInput {
723
- action?: ResolveIOAIManagerRecoveryActionPacket;
724
- dispatchDecision?: ResolveIOAIManagerRecoveryActionDispatchDecision;
725
- current?: ResolveIOAIManagerFailureRecord;
726
- autonomyPolicy?: ResolveIOAIManagerAutonomyPolicyInput;
727
- surface?: string;
728
- now?: Date | string;
729
- }
730
-
731
- export interface ResolveIOAIManagerRecoveryExecutionDirective {
732
- directiveId: string;
733
- surface: string;
734
- dispatchAction: ResolveIOAIManagerRecoveryActionDispatchAction;
735
- phase: ResolveIOAIManagerRecoveryExecutionPhase;
736
- allowed: boolean;
737
- status: ResolveIOAIManagerRecoveryActionDispatchStatus;
738
- reason: string;
739
- singleActionOnly: boolean;
740
- allowedDispatchAction: ResolveIOAIManagerRecoveryActionDispatchAction;
741
- lane: string;
742
- stepType: string;
743
- nextActionLabel: string;
744
- rerunReason: string;
745
- evidenceOnly: boolean;
746
- autoRunnable: boolean;
747
- productRepairAllowed: boolean;
748
- expensiveModelAllowed: boolean;
749
- costCeilingUsd: number;
750
- requiredStateTransition: string;
751
- proofRequiredBeforeContinuation: boolean;
752
- canRunProductRepair: boolean;
753
- canRunExpensiveModel: boolean;
754
- canResetLoopAfterEvidence: boolean;
755
- requiresNewEvidence: boolean;
756
- newEvidence: boolean;
757
- autonomyPolicy?: ResolveIOAIManagerAutonomyPolicyDecision;
758
- maxAttemptsBeforePark: number;
759
- requiredArtifacts: string[];
760
- nextCommands: string[];
761
- successCriteria: string[];
762
- exitCriteria: string[];
763
- forbiddenActions: string[];
764
- dispatchRecord?: ResolveIOAIManagerRecoveryActionDispatchRecord;
765
- releasePolicy?: ResolveIOAIManagerHotfixFirstReleasePolicy;
766
- createdAt: string;
767
- }
768
-
769
- export type ResolveIOAIManagerRecoveryExecutionProofStatus =
770
- | 'proof_ready'
771
- | 'waiting_for_execution'
772
- | 'waiting_for_new_evidence'
773
- | 'blocked_same_evidence'
774
- | 'manual_handoff';
775
-
776
- export interface ResolveIOAIManagerRecoveryExecutionProofContractInput {
777
- directive?: ResolveIOAIManagerRecoveryExecutionDirective;
778
- previous?: ResolveIOAIManagerFailureRecord;
779
- current?: ResolveIOAIManagerFailureRecord;
780
- requiredEvidence?: any;
781
- now?: Date | string;
782
- }
783
-
784
- export interface ResolveIOAIManagerRecoveryExecutionProofContract {
785
- contractId: string;
786
- directiveId: string;
787
- surface: string;
788
- dispatchAction: ResolveIOAIManagerRecoveryActionDispatchAction;
789
- phase: ResolveIOAIManagerRecoveryExecutionPhase;
790
- status: ResolveIOAIManagerRecoveryExecutionProofStatus;
791
- canContinueRun: boolean;
792
- canRunProductRepair: boolean;
793
- canRunExpensiveModel: boolean;
794
- canResetLoopBudget: boolean;
795
- proofRequiredBeforeContinuation: boolean;
796
- requiresNewEvidence: boolean;
797
- newEvidence: boolean;
798
- materialEvidence: boolean;
799
- evidenceStrength: ResolveIOAIManagerEvidenceStrength;
800
- evidenceSignals: string[];
801
- startingFailureClass: string;
802
- startingBlockerFingerprint: string;
803
- startingEvidenceHash: string;
804
- latestFailureClass: string;
805
- latestBlockerFingerprint: string;
806
- latestEvidenceHash: string;
807
- requiredEvidence: string[];
808
- missingEvidence: string[];
809
- artifactPaths: string[];
810
- changedFiles: string[];
811
- blockers: string[];
812
- nextAllowedAction: string;
813
- forbiddenActions: string[];
814
- createdAt: string;
815
- }
816
-
817
- export interface ResolveIOAIManagerRecoveryCheckpointInput {
818
- plan: ResolveIOAIManagerRecoveryPlan;
819
- current?: ResolveIOAIManagerFailureRecord;
820
- previousCheckpoint?: ResolveIOAIManagerRecoveryCheckpoint;
821
- now?: Date | string;
822
- }
823
-
824
- export type ResolveIOAIManagerRecoveryGateAction =
825
- | 'allow'
826
- | 'collect_new_evidence'
827
- | 'reject_action'
828
- | 'manual_handoff'
829
- | 'complete';
830
-
831
- export interface ResolveIOAIManagerRecoveryGateInput {
832
- checkpoint: ResolveIOAIManagerRecoveryCheckpoint;
833
- current?: ResolveIOAIManagerFailureRecord;
834
- proposedAction?: string;
835
- operatorApproved?: boolean;
836
- now?: Date | string;
837
- }
838
-
839
- export interface ResolveIOAIManagerRecoveryGateDecision {
840
- action: ResolveIOAIManagerRecoveryGateAction;
841
- reason: string;
842
- canRunProductRepair: boolean;
843
- canRunExpensiveModel: boolean;
844
- shouldResetLoopBudget: boolean;
845
- shouldIncrementAttempt: boolean;
846
- newEvidence: boolean;
847
- materialEvidence: boolean;
848
- evidenceStrength: ResolveIOAIManagerEvidenceStrength;
849
- evidenceSignals: string[];
850
- blockerFingerprint: string;
851
- evidenceHash: string;
852
- missingEvidence: string[];
853
- checkpoint: ResolveIOAIManagerRecoveryCheckpoint;
854
- }
855
-
856
- export interface ResolveIOAIManagerRecoveryEvidenceProbeInput {
857
- checkpoint: ResolveIOAIManagerRecoveryCheckpoint;
858
- current?: ResolveIOAIManagerFailureRecord;
859
- now?: Date | string;
860
- }
861
-
862
- export interface ResolveIOAIManagerRecoveryActionPacketInput {
863
- plan?: ResolveIOAIManagerRecoveryPlan;
864
- checkpoint: ResolveIOAIManagerRecoveryCheckpoint;
865
- probe?: ResolveIOAIManagerRecoveryEvidenceProbe;
866
- current?: ResolveIOAIManagerFailureRecord;
867
- now?: Date | string;
868
- }
869
-
870
- export interface ResolveIOAIManagerRecoveryPlanInput {
871
- action?: ResolveIOAIManagerAction | string;
872
- reason?: string;
873
- failureClass?: string;
874
- lane?: string;
875
- stepType?: string;
876
- blocker?: string;
877
- sameFailureCount?: number;
878
- pingPongCount?: number;
879
- newEvidence?: boolean;
880
- productRepairFailure?: boolean;
881
- changedFiles?: string[];
882
- artifactPaths?: string[];
883
- maxSameFailureRepeats?: number;
884
- }
885
-
886
- export interface ResolveIOAIManagerPolicyInput {
887
- history?: ResolveIOAIManagerFailureRecord[];
888
- current?: ResolveIOAIManagerFailureRecord;
889
- maxSameFailureRepeats?: number;
890
- maxPingPongTransitions?: number;
891
- infraFailureClasses?: string[];
892
- ignoredFailureClasses?: string[];
893
- }
894
-
895
- export interface ResolveIOAIManagerPolicyDecision {
896
- action: ResolveIOAIManagerAction;
897
- reason: string;
898
- failureClass: string;
899
- blockerFingerprint: string;
900
- evidenceHash: string;
901
- sameFailureCount: number;
902
- pingPongCount: number;
903
- newEvidence: boolean;
904
- materialEvidence: boolean;
905
- evidenceStrength: ResolveIOAIManagerEvidenceStrength;
906
- evidenceSignals: string[];
907
- loopBudgetShouldReset: boolean;
908
- productRepairFailure: boolean;
909
- recoveryPlan: ResolveIOAIManagerRecoveryPlan;
910
- recoveryCheckpoint: ResolveIOAIManagerRecoveryCheckpoint;
911
- recoveryEvidenceProbe: ResolveIOAIManagerRecoveryEvidenceProbe;
912
- recoveryAction: ResolveIOAIManagerRecoveryActionPacket;
913
- }
914
-
915
- export interface ResolveIOAIManagerRecoveryReplayMatrixInput {
916
- surface?: string;
917
- includeJourneyContractRepair?: boolean;
918
- includeReleaseRepair?: boolean;
919
- includeProductRepair?: boolean;
920
- maxSameFailureRepeats?: number;
921
- }
922
-
923
- export interface ResolveIOAIManagerRecoveryReplayCase {
924
- caseId: string;
925
- surface: string;
926
- pass: boolean;
927
- action: string;
928
- reason: string;
929
- recoveryClass: string;
930
- dispatchAction: string;
931
- safeAutoDispatch: boolean;
932
- expectedSafeAutoDispatch: boolean;
933
- productRepairAllowed: boolean;
934
- loopBudgetShouldReset: boolean;
935
- materialEvidence: boolean;
936
- evidenceStrength: ResolveIOAIManagerEvidenceStrength;
937
- hotfixFirst?: boolean;
938
- fullDeployAllowed?: boolean;
939
- details?: Record<string, any>;
940
- }
941
-
942
- function cleanText(value: any, max = 2000): string {
943
- return String(value || '').replace(/\s+/g, ' ').trim().slice(0, max);
944
- }
945
-
946
- function cleanList(values: any, limit = 40, max = 500): string[] {
947
- if (!Array.isArray(values)) {
948
- return [];
949
- }
950
- const result: string[] = [];
951
- for (const value of values) {
952
- const normalized = cleanText(value, max);
953
- if (normalized && !result.includes(normalized)) {
954
- result.push(normalized);
955
- }
956
- if (result.length >= limit) {
957
- break;
958
- }
959
- }
960
- return result;
961
- }
962
-
963
- const HOTFIX_CHANNELS = new Set<ResolveIOAIManagerHotfixChannel>([
964
- 'static_ui',
965
- 'backend_js',
966
- 'config',
967
- 'seed_data',
968
- 'cache_invalidation',
969
- 'service_restart',
970
- 'release_artifact',
971
- 'force_deploy_review',
972
- 'new_artifact_deploy',
973
- 'artifact_build'
974
- ]);
975
-
976
- function cleanObject(value: any): Record<string, any> {
977
- return value && typeof value === 'object' && !Array.isArray(value) ? value : {};
978
- }
979
-
980
- function normalizeAutonomyMode(value: any): ResolveIOAIManagerAutonomyMode {
981
- const normalized = cleanText(value, 120).toLowerCase().replace(/[\s-]+/g, '_');
982
- if (/^(monitor|monitor_only|watch|watch_only)$/.test(normalized)) {
983
- return 'monitor_only';
984
- }
985
- if (/^(auto|auto_retry|auto_retry_within_budget|autonomous|within_budget)$/.test(normalized)) {
986
- return 'auto_retry_within_budget';
987
- }
988
- return 'manual_only';
989
- }
990
-
991
- function normalizeManagerEvidenceStrength(value: any): ResolveIOAIManagerEvidenceStrength {
992
- const normalized = cleanText(value, 40).toLowerCase().replace(/[\s-]+/g, '_');
993
- if (normalized === 'proof') {
994
- return 'proof';
995
- }
996
- if (normalized === 'material' || normalized === 'strong') {
997
- return 'material';
998
- }
999
- if (normalized === 'weak') {
1000
- return 'weak';
1001
- }
1002
- return 'none';
1003
- }
1004
-
1005
- function nonNegativeMoney(value: any): number {
1006
- const parsed = Number(value);
1007
- return Number.isFinite(parsed) && parsed > 0 ? parsed : 0;
1008
- }
1009
-
1010
- function finiteNumber(value: any): number | undefined {
1011
- const parsed = Number(value);
1012
- return Number.isFinite(parsed) ? parsed : undefined;
1013
- }
1014
-
1015
- function clampNumber(value: number, min: number, max: number): number {
1016
- return Math.min(max, Math.max(min, value));
1017
- }
1018
-
1019
- function isCheapEvidenceAutonomyAction(value: any): boolean {
1020
- const action = cleanText(value, 120);
1021
- return !action || /^(run_evidence_probe|run_read_only_diagnosis|advance|continue_gate|park_manual)$/.test(action);
1022
- }
1023
-
1024
- export function estimateResolveIOAIManagerRetryExpectedValue(
1025
- input: ResolveIOAIManagerRetryExpectedValueInput = {}
1026
- ): ResolveIOAIManagerRetryExpectedValueEstimate {
1027
- const dispatchAction = cleanText(input.dispatchAction, 120);
1028
- const failureClass = normalizeResolveIOAIManagerFailureClass(input.failureClass);
1029
- const recoveryClass = cleanText(input.recoveryClass, 120);
1030
- const evidenceStrength = normalizeManagerEvidenceStrength(input.evidenceStrength);
1031
- const evidenceSignals = cleanList(input.evidenceSignals, 12, 120);
1032
- const projectedActionCostUsd = nonNegativeMoney(input.projectedActionCostUsd);
1033
- const budgetHardUsd = nonNegativeMoney(input.budgetHardUsd);
1034
- const materialEvidence = input.materialEvidence === true || evidenceStrength === 'material' || evidenceStrength === 'proof';
1035
- const newEvidence = input.newEvidence === true;
1036
- const signals: string[] = [];
1037
- let score = 0.1;
1038
- if (dispatchAction === 'run_evidence_probe') {
1039
- score = 0.75;
1040
- signals.push('cheap_evidence_probe');
1041
- }
1042
- else if (dispatchAction === 'run_read_only_diagnosis') {
1043
- score = 0.65;
1044
- signals.push('read_only_diagnosis');
1045
- }
1046
- else if (dispatchAction === 'advance' || dispatchAction === 'continue_gate') {
1047
- score = 0.55;
1048
- signals.push('gate_continuation');
1049
- }
1050
- else if (dispatchAction === 'run_infra_repair') {
1051
- score = 0.4;
1052
- signals.push('bounded_infra_repair');
1053
- }
1054
- else if (dispatchAction === 'run_compile_repair') {
1055
- score = 0.4;
1056
- signals.push('bounded_compile_repair');
1057
- }
1058
- else if (dispatchAction === 'run_release_repair') {
1059
- score = 0.3;
1060
- signals.push('bounded_release_repair');
1061
- }
1062
- else if (dispatchAction === 'run_journey_contract_repair' || dispatchAction === 'run_business_assertion_repair') {
1063
- score = 0.25;
1064
- signals.push('bounded_workflow_or_proof_repair');
1065
- }
1066
- else if (dispatchAction === 'run_targeted_product_repair') {
1067
- score = 0.15;
1068
- signals.push('targeted_product_repair');
1069
- }
1070
- if (evidenceStrength === 'proof') {
1071
- score += 0.3;
1072
- signals.push('proof_evidence');
1073
- }
1074
- else if (materialEvidence) {
1075
- score += 0.2;
1076
- signals.push('material_evidence');
1077
- }
1078
- else if (newEvidence) {
1079
- score += 0.1;
1080
- signals.push('new_evidence');
1081
- }
1082
- else if (evidenceStrength === 'weak') {
1083
- score -= 0.15;
1084
- signals.push('weak_evidence');
1085
- }
1086
- else if (!isCheapEvidenceAutonomyAction(dispatchAction)) {
1087
- score -= 0.25;
1088
- signals.push('no_material_evidence');
1089
- }
1090
- if ((failureClass === 'infra' || /infra/i.test(recoveryClass)) && dispatchAction === 'run_infra_repair') {
1091
- score += 0.15;
1092
- signals.push('failure_matches_infra_repair');
1093
- }
1094
- if ((failureClass === 'compile' || /compile/i.test(recoveryClass)) && dispatchAction === 'run_compile_repair') {
1095
- score += 0.15;
1096
- signals.push('failure_matches_compile_repair');
1097
- }
1098
- if (/release|publish|deploy/i.test(`${failureClass} ${recoveryClass}`) && dispatchAction === 'run_release_repair') {
1099
- score += 0.1;
1100
- signals.push('failure_matches_release_repair');
1101
- }
1102
- if (projectedActionCostUsd >= 5) {
1103
- score -= 0.3;
1104
- signals.push('high_projected_cost');
1105
- }
1106
- else if (projectedActionCostUsd >= 2) {
1107
- score -= 0.18;
1108
- signals.push('medium_projected_cost');
1109
- }
1110
- else if (projectedActionCostUsd >= 1) {
1111
- score -= 0.08;
1112
- signals.push('low_projected_cost');
1113
- }
1114
- if (budgetHardUsd > 0 && projectedActionCostUsd > budgetHardUsd * 0.5) {
1115
- score -= 0.2;
1116
- signals.push('large_fraction_of_remaining_budget');
1117
- }
1118
- if (input.sameEvidenceAlreadyAttempted === true) {
1119
- score -= 0.35;
1120
- signals.push('same_evidence_already_attempted');
1121
- }
1122
- for (const signal of evidenceSignals) {
1123
- if (/passing_outcome|business|proof|diagnosis|compile|infra|release|artifact|fingerprint_changed|evidence_hash_changed/i.test(signal)) {
1124
- score += 0.03;
1125
- signals.push(`evidence_signal:${signal}`);
1126
- }
1127
- }
1128
- const rounded = Number(clampNumber(score, -1, 1).toFixed(2));
1129
- const minScore = 0;
1130
- return {
1131
- score: rounded,
1132
- minScore,
1133
- positive: rounded >= minScore,
1134
- source: 'estimated',
1135
- confidence: evidenceStrength === 'proof' || materialEvidence ? 'medium' : 'low',
1136
- reason: rounded >= minScore
1137
- ? 'estimated_retry_value_is_non_negative'
1138
- : 'estimated_retry_value_is_negative',
1139
- signals: Array.from(new Set(signals)).slice(0, 16)
1140
- };
1141
- }
1142
-
1143
- export function decideResolveIOAIManagerAutonomyPolicy(
1144
- input: ResolveIOAIManagerAutonomyPolicyInput = {}
1145
- ): ResolveIOAIManagerAutonomyPolicyDecision {
1146
- const mode = normalizeAutonomyMode(input.mode);
1147
- const currentSpendUsd = nonNegativeMoney(input.currentSpendUsd);
1148
- const projectedActionCostUsd = nonNegativeMoney(input.projectedActionCostUsd);
1149
- const projectedSpendUsd = currentSpendUsd + projectedActionCostUsd;
1150
- const budgetSoftUsd = nonNegativeMoney(input.budgetSoftUsd);
1151
- const budgetHardUsd = nonNegativeMoney(input.budgetHardUsd);
1152
- const softBudgetExceeded = budgetSoftUsd > 0 && projectedSpendUsd >= budgetSoftUsd;
1153
- const hardBudgetExceeded = budgetHardUsd > 0 && projectedSpendUsd > budgetHardUsd;
1154
- const dispatchAction = cleanText(input.dispatchAction, 120);
1155
- const evidenceStrength = normalizeManagerEvidenceStrength(input.evidenceStrength);
1156
- const evidenceSignals = cleanList(input.evidenceSignals, 12, 120);
1157
- const materialEvidence = input.materialEvidence === true || evidenceStrength === 'material' || evidenceStrength === 'proof';
1158
- const newEvidence = input.newEvidence === true;
1159
- const evidenceBacked = materialEvidence || newEvidence || evidenceSignals.some((signal) => /material|proof|business|compile|infra|release|diagnosis|journey|workflow|artifact|hash_changed|fingerprint_changed/i.test(signal));
1160
- const cheapEvidenceAction = isCheapEvidenceAutonomyAction(dispatchAction);
1161
- const expectedValueEstimate = estimateResolveIOAIManagerRetryExpectedValue({
1162
- dispatchAction,
1163
- projectedActionCostUsd,
1164
- currentSpendUsd,
1165
- budgetHardUsd,
1166
- evidenceStrength,
1167
- materialEvidence,
1168
- newEvidence,
1169
- evidenceSignals,
1170
- sameEvidenceAlreadyAttempted: input.sameEvidenceAlreadyAttempted === true
1171
- });
1172
- const providedExpectedValue = finiteNumber(input.expectedValueScore);
1173
- const expectedValueKnown = providedExpectedValue !== undefined;
1174
- const expectedValueScore = expectedValueKnown ? providedExpectedValue as number : expectedValueEstimate.score;
1175
- const minExpectedValue = finiteNumber(input.minExpectedValueScore) ?? expectedValueEstimate.minScore;
1176
- const expectedValuePositive = expectedValueScore >= minExpectedValue;
1177
- const expectedValueSource: ResolveIOAIManagerAutonomyPolicyDecision['expectedValueSource'] = expectedValueKnown ? 'provided' : 'estimated';
1178
- const requiredEvidence = [
1179
- 'mode',
1180
- 'projectedActionCostUsd',
1181
- ...(budgetHardUsd > 0 ? ['budgetHardUsd'] : []),
1182
- ...(budgetSoftUsd > 0 ? ['budgetSoftUsd'] : []),
1183
- ...(dispatchAction ? ['dispatchAction'] : []),
1184
- ...(cheapEvidenceAction ? [] : ['materialEvidence or newEvidence', 'expectedValueScore when available'])
1185
- ];
1186
- const forbiddenActions: string[] = [];
1187
- let canAutoDispatch = false;
1188
- let canManualDispatch = true;
1189
- let blocked = false;
1190
- let requiresHumanApproval = true;
1191
- let reason = '';
1192
- let recommendedControl: ResolveIOAIManagerAutonomyPolicyDecision['recommendedControl'] = mode;
1193
- if (mode === 'monitor_only') {
1194
- canManualDispatch = false;
1195
- reason = 'monitor_only_blocks_runner_dispatch';
1196
- forbiddenActions.push('Do not run recovery, repair, QA, publish, deploy, or customer reply actions while in Monitor Only mode.');
1197
- }
1198
- else if (mode === 'manual_only') {
1199
- reason = 'manual_only_requires_operator_dispatch';
1200
- forbiddenActions.push('Do not auto-dispatch manager recovery actions in Manual Only mode.');
1201
- }
1202
- else if (hardBudgetExceeded) {
1203
- blocked = true;
1204
- canAutoDispatch = false;
1205
- canManualDispatch = input.operatorApproved === true;
1206
- reason = 'auto_retry_budget_hard_cap_would_be_exceeded';
1207
- recommendedControl = 'increase_budget_or_manual';
1208
- forbiddenActions.push('Do not auto-dispatch because projected spend exceeds the hard budget.');
1209
- }
1210
- else if (!cheapEvidenceAction && !evidenceBacked) {
1211
- canAutoDispatch = false;
1212
- requiresHumanApproval = true;
1213
- reason = 'auto_retry_requires_material_evidence';
1214
- forbiddenActions.push('Do not auto-dispatch repair work until a deterministic artifact, changed blocker fingerprint, or material proof is recorded.');
1215
- }
1216
- else if (!cheapEvidenceAction && !expectedValuePositive) {
1217
- canAutoDispatch = false;
1218
- requiresHumanApproval = true;
1219
- reason = 'auto_retry_expected_value_not_positive';
1220
- forbiddenActions.push('Do not auto-dispatch repair work when the expected value score is below the configured minimum.');
1221
- }
1222
- else {
1223
- canAutoDispatch = true;
1224
- requiresHumanApproval = softBudgetExceeded;
1225
- reason = softBudgetExceeded
1226
- ? 'auto_retry_soft_budget_warning_requires_review'
1227
- : 'auto_retry_within_budget_allows_auto_dispatch';
1228
- if (softBudgetExceeded) {
1229
- forbiddenActions.push('Do not escalate to a more expensive model or broader repair without operator review after soft budget warning.');
1230
- }
1231
- }
1232
- return {
1233
- mode,
1234
- canAutoDispatch,
1235
- canManualDispatch,
1236
- blocked,
1237
- requiresHumanApproval,
1238
- reason,
1239
- currentSpendUsd,
1240
- projectedActionCostUsd,
1241
- projectedSpendUsd,
1242
- budgetSoftUsd,
1243
- budgetHardUsd,
1244
- softBudgetExceeded,
1245
- hardBudgetExceeded,
1246
- dispatchAction,
1247
- expectedValueScore,
1248
- minExpectedValueScore: minExpectedValue,
1249
- expectedValueKnown,
1250
- expectedValueSource,
1251
- expectedValuePositive,
1252
- evidenceStrength,
1253
- materialEvidence,
1254
- newEvidence,
1255
- evidenceBacked,
1256
- evidenceSignals,
1257
- recommendedControl,
1258
- forbiddenActions,
1259
- requiredEvidence
1260
- };
1261
- }
1262
-
1263
- function cleanDateString(value: any): string {
1264
- const date = value instanceof Date ? value : new Date(value || Date.now());
1265
- return Number.isNaN(date.getTime()) ? new Date().toISOString() : date.toISOString();
1266
- }
1267
-
1268
- function normalizeHotfixChannel(value: any): ResolveIOAIManagerHotfixChannel | '' {
1269
- const normalized = cleanText(value, 120).toLowerCase().replace(/[\s-]+/g, '_') as ResolveIOAIManagerHotfixChannel;
1270
- return HOTFIX_CHANNELS.has(normalized) ? normalized : '';
1271
- }
1272
-
1273
- function normalizeHotfixStatus(value: any): ResolveIOAIManagerHotfixEvidenceStatus {
1274
- const normalized = cleanText(value, 120).toLowerCase().replace(/[\s-]+/g, '_');
1275
- if (/^(pass|passed|success|succeeded|complete|completed|accepted)$/.test(normalized)) {
1276
- return 'passed';
1277
- }
1278
- if (/^(block|blocked|failed|fail|error|denied)$/.test(normalized)) {
1279
- return 'blocked';
1280
- }
1281
- if (/^(missing|none)$/.test(normalized)) {
1282
- return 'missing';
1283
- }
1284
- return 'incomplete';
1285
- }
1286
-
1287
- function hotfixStatusPassed(value: any): boolean {
1288
- return normalizeHotfixStatus(value) === 'passed';
1289
- }
1290
-
1291
- function normalizeHotfixEvidenceTarget(value: any): ResolveIOAIManagerHotfixEvidenceTarget {
1292
- const source = cleanObject(value);
1293
- return {
1294
- surface: cleanText(source.surface, 160),
1295
- host: cleanText(source.host || source.hostname || source.domain, 240),
1296
- path: cleanText(source.path || source.remotePath || source.remote_path, 500),
1297
- artifactPath: cleanText(source.artifactPath || source.artifact_path || source.localPath || source.local_path, 500),
1298
- bucket: cleanText(source.bucket || source.s3Bucket || source.s3_bucket, 240),
1299
- distributionId: cleanText(source.distributionId || source.distribution_id || source.cloudfrontDistributionId || source.cloudfront_distribution_id, 240),
1300
- processName: cleanText(source.processName || source.process_name || source.service || source.serviceName, 160),
1301
- configKey: cleanText(source.configKey || source.config_key || source.key, 240),
1302
- cacheKey: cleanText(source.cacheKey || source.cache_key, 240),
1303
- seedKey: cleanText(source.seedKey || source.seed_key || source.fixture, 240)
1304
- };
1305
- }
1306
-
1307
- export function normalizeResolveIOAIManagerHotfixEvidence(
1308
- value: any,
1309
- policy?: ResolveIOAIManagerHotfixFirstReleasePolicy
1310
- ): ResolveIOAIManagerHotfixEvidence | undefined {
1311
- const source = cleanObject(value);
1312
- if (!Object.keys(source).length) {
1313
- return undefined;
1314
- }
1315
- const channel = normalizeHotfixChannel(source.channel || source.hotfixChannel || source.hotfix_channel || policy?.hotfixPlan?.recommendedChannel);
1316
- if (!channel) {
1317
- return undefined;
1318
- }
1319
- const target = normalizeHotfixEvidenceTarget(source.target || source);
1320
- return {
1321
- channel,
1322
- status: normalizeHotfixStatus(source.status),
1323
- target,
1324
- compiledArtifactPath: cleanText(source.compiledArtifactPath || source.compiled_artifact_path || target.artifactPath, 500),
1325
- builtDistPath: cleanText(source.builtDistPath || source.built_dist_path || target.artifactPath, 500),
1326
- remoteChecksumBefore: cleanText(source.remoteChecksumBefore || source.remote_checksum_before || source.checksumBefore || source.checksum_before, 160),
1327
- remoteChecksumAfter: cleanText(source.remoteChecksumAfter || source.remote_checksum_after || source.checksumAfter || source.checksum_after, 160),
1328
- remoteChecksum: cleanText(source.remoteChecksum || source.remote_checksum || source.checksum, 160),
1329
- restartEvidence: cleanText(source.restartEvidence || source.restart_evidence, 1000),
1330
- healthCheckStatus: cleanText(source.healthCheckStatus || source.health_check_status || source.health, 160),
1331
- selfTestStatus: cleanText(source.selfTestStatus || source.self_test_status || source.selfTest || source.self_test, 160),
1332
- releaseGateStatus: cleanText(source.releaseGateStatus || source.release_gate_status || source.releaseGate || source.release_gate, 160),
1333
- s3UploadResult: cleanText(source.s3UploadResult || source.s3_upload_result || source.uploadResult || source.upload_result, 1000),
1334
- cloudfrontInvalidationId: cleanText(source.cloudfrontInvalidationId || source.cloudfront_invalidation_id || source.invalidationId || source.invalidation_id, 240),
1335
- publicProof: cleanText(source.publicProof || source.public_proof || source.publicUrl || source.public_url, 1000),
1336
- configChangeEvidence: cleanText(source.configChangeEvidence || source.config_change_evidence, 1000),
1337
- seedDataEvidence: cleanText(source.seedDataEvidence || source.seed_data_evidence, 1000),
1338
- cacheInvalidationEvidence: cleanText(source.cacheInvalidationEvidence || source.cache_invalidation_evidence, 1000),
1339
- serviceRestartEvidence: cleanText(source.serviceRestartEvidence || source.service_restart_evidence, 1000),
1340
- releaseArtifactFingerprint: cleanText(source.releaseArtifactFingerprint || source.release_artifact_fingerprint || source.artifactFingerprint || source.artifact_fingerprint, 240),
1341
- lastReleaseArtifactFingerprint: cleanText(source.lastReleaseArtifactFingerprint || source.last_release_artifact_fingerprint || source.lastArtifactFingerprint || source.last_artifact_fingerprint, 240),
1342
- sourceCommitSha: cleanText(source.sourceCommitSha || source.source_commit_sha || source.gitCommitSha || source.git_commit_sha || source.commitSha || source.commit_sha, 120),
1343
- githubCommitUrl: cleanText(source.githubCommitUrl || source.github_commit_url || source.gitCommitUrl || source.git_commit_url || source.commitUrl || source.commit_url, 500),
1344
- gitCommitStatus: cleanText(source.gitCommitStatus || source.git_commit_status || source.githubCommitStatus || source.github_commit_status, 160),
1345
- gitPushStatus: cleanText(source.gitPushStatus || source.git_push_status || source.githubPushStatus || source.github_push_status || source.githubCommitReachableStatus || source.github_commit_reachable_status, 160),
1346
- committedAt: source.committedAt || source.committed_at,
1347
- forceDeployReason: cleanText(source.forceDeployReason || source.force_deploy_reason, 1000),
1348
- hotfixCannotResolveReason: cleanText(source.hotfixCannotResolveReason || source.hotfix_cannot_resolve_reason, 1000),
1349
- fullDeployRequested: source.fullDeployRequested === true || source.full_deploy_requested === true,
1350
- recordedAt: source.recordedAt || source.recorded_at
1351
- };
1352
- }
1353
-
1354
- function matchingHotfixPlanStep(
1355
- policy: ResolveIOAIManagerHotfixFirstReleasePolicy | undefined,
1356
- channel: ResolveIOAIManagerHotfixChannel | ''
1357
- ): ResolveIOAIManagerHotfixPlanStep | undefined {
1358
- return (policy?.hotfixPlan?.steps || []).find((step) => step.channel === channel);
1359
- }
1360
-
1361
- function pushMissing(blockers: string[], condition: boolean, message: string): void {
1362
- if (!condition) {
1363
- blockers.push(message);
1364
- }
1365
- }
1366
-
1367
- function hotfixRequiresGithubCommit(channel: ResolveIOAIManagerHotfixChannel | ''): boolean {
1368
- return /^(backend_js|static_ui|config|seed_data|release_artifact|new_artifact_deploy|artifact_build)$/.test(channel);
1369
- }
1370
-
1371
- function extractGithubCommitSha(value: string): string {
1372
- const match = cleanText(value, 500).match(/^https:\/\/github\.com\/[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+\/commit\/([a-f0-9]{40})(?:$|[?#/])/i);
1373
- return match?.[1]?.toLowerCase() || '';
1374
- }
1375
-
1376
- function isFullGitCommitSha(value: string): boolean {
1377
- return /^[a-f0-9]{40}$/i.test(cleanText(value, 120));
1378
- }
1379
-
1380
- function isStrongRemoteChecksum(value: string): boolean {
1381
- return /^[a-f0-9]{12,128}$/i.test(cleanText(value, 160));
1382
- }
1383
-
1384
- function githubCommitProofBlockers(value: ResolveIOAIManagerHotfixEvidence, channel: ResolveIOAIManagerHotfixChannel | ''): string[] {
1385
- const blockers: string[] = [];
1386
- const sourceCommitSha = cleanText(value.sourceCommitSha, 120);
1387
- const githubCommitUrl = cleanText(value.githubCommitUrl, 500);
1388
- const gitCommitStatus = cleanText(value.gitCommitStatus, 160);
1389
- const gitPushStatus = cleanText(value.gitPushStatus, 160);
1390
- const urlCommitSha = extractGithubCommitSha(githubCommitUrl);
1391
- if (!sourceCommitSha || !githubCommitUrl) {
1392
- blockers.push(`${channel} hotfix requires sourceCommitSha, githubCommitUrl, passed gitCommitStatus, and passed gitPushStatus so live hotfixes are backed by a committed and pushed GitHub change before continuation.`);
1393
- return blockers;
1394
- }
1395
- if (!isFullGitCommitSha(sourceCommitSha)) {
1396
- blockers.push(`${channel} hotfix sourceCommitSha must be a full 40-character git SHA.`);
1397
- }
1398
- if (!urlCommitSha) {
1399
- blockers.push(`${channel} hotfix githubCommitUrl must be a GitHub commit URL ending in a full 40-character git SHA.`);
1400
- }
1401
- else if (isFullGitCommitSha(sourceCommitSha) && urlCommitSha !== sourceCommitSha.toLowerCase()) {
1402
- blockers.push(`${channel} hotfix githubCommitUrl commit SHA must match sourceCommitSha.`);
1403
- }
1404
- if (!gitCommitStatus) {
1405
- blockers.push(`${channel} hotfix requires passed gitCommitStatus so the manager records that the hotfix diff was committed before continuation.`);
1406
- }
1407
- else if (!hotfixStatusPassed(gitCommitStatus)) {
1408
- blockers.push(`${channel} hotfix gitCommitStatus must be passed before continuation.`);
1409
- }
1410
- if (!gitPushStatus) {
1411
- blockers.push(`${channel} hotfix requires passed gitPushStatus so the manager knows the hotfix commit is present on GitHub before continuation.`);
1412
- }
1413
- else if (!hotfixStatusPassed(gitPushStatus)) {
1414
- blockers.push(`${channel} hotfix gitPushStatus must be passed before continuation.`);
1415
- }
1416
- return blockers;
1417
- }
1418
-
1419
- export function evaluateResolveIOAIManagerHotfixGitProof(
1420
- value: any,
1421
- channelHint: ResolveIOAIManagerHotfixChannel | '' = ''
1422
- ): ResolveIOAIManagerHotfixGitProof {
1423
- const normalized = normalizeResolveIOAIManagerHotfixEvidence(value);
1424
- const source = (normalized || cleanObject(value)) as Record<string, any>;
1425
- const channel = (channelHint || normalized?.channel || source.channel || '') as ResolveIOAIManagerHotfixChannel | '';
1426
- const required = hotfixRequiresGithubCommit(channel);
1427
- const sourceCommitSha = cleanText(source.sourceCommitSha || source.source_commit_sha || source.gitCommitSha || source.git_commit_sha || source.commitSha || source.commit_sha, 120);
1428
- const githubCommitUrl = cleanText(source.githubCommitUrl || source.github_commit_url || source.gitCommitUrl || source.git_commit_url || source.commitUrl || source.commit_url, 500);
1429
- const githubCommitSha = extractGithubCommitSha(githubCommitUrl);
1430
- const gitCommitStatus = cleanText(source.gitCommitStatus || source.git_commit_status || source.githubCommitStatus || source.github_commit_status, 160);
1431
- const gitPushStatus = cleanText(source.gitPushStatus || source.git_push_status || source.githubPushStatus || source.github_push_status || source.githubCommitReachableStatus || source.github_commit_reachable_status, 160);
1432
- const blockers = required
1433
- ? githubCommitProofBlockers({
1434
- channel: channel as ResolveIOAIManagerHotfixChannel,
1435
- target: normalized?.target || {},
1436
- sourceCommitSha,
1437
- githubCommitUrl,
1438
- gitCommitStatus,
1439
- gitPushStatus
1440
- }, channel)
1441
- : [];
1442
- const status: ResolveIOAIManagerHotfixGitProofStatus = !required
1443
- ? 'not_required'
1444
- : (!sourceCommitSha || !githubCommitUrl || !gitCommitStatus || !gitPushStatus)
1445
- ? 'missing'
1446
- : blockers.length
1447
- ? 'invalid'
1448
- : 'passed';
1449
- const passed = !required || status === 'passed';
1450
- return {
1451
- required,
1452
- status,
1453
- passed,
1454
- managerMustCommitBeforeHotfix: required && !passed,
1455
- channel,
1456
- sourceCommitSha,
1457
- githubCommitUrl,
1458
- githubCommitSha,
1459
- gitCommitStatus,
1460
- gitPushStatus,
1461
- blockers,
1462
- nextCommands: required && !passed
1463
- ? ['commit_and_push_hotfix_to_github', 'verify_github_commit_url_and_push_status', 'record_hotfix_evidence']
1464
- : [],
1465
- requiredEvidence: required
1466
- ? ['full 40-character sourceCommitSha', 'matching GitHub commit URL', 'passed gitCommitStatus', 'passed gitPushStatus']
1467
- : []
1468
- };
1469
- }
1470
-
1471
- export function validateResolveIOAIManagerHotfixEvidence(
1472
- value: any,
1473
- options: { policy?: ResolveIOAIManagerHotfixFirstReleasePolicy } = {}
1474
- ): ResolveIOAIManagerHotfixEvidenceValidation {
1475
- const normalized = normalizeResolveIOAIManagerHotfixEvidence(value, options.policy);
1476
- const policy = options.policy;
1477
- if (!normalized) {
1478
- return {
1479
- valid: false,
1480
- status: 'missing',
1481
- channel: '',
1482
- blockers: ['Hotfix evidence is missing or channel is unsupported.'],
1483
- warnings: [],
1484
- fullDeployAllowed: false,
1485
- fullDeployBlocked: true,
1486
- hotfixSatisfied: false,
1487
- requiredEvidence: policy?.hotfixPlan?.steps?.flatMap((step) => step.requiredEvidence) || [],
1488
- successEvidence: policy?.hotfixPlan?.steps?.flatMap((step) => step.successEvidence) || [],
1489
- githubCommitGuard: evaluateResolveIOAIManagerHotfixGitProof(value),
1490
- policy,
1491
- nextAction: 'record_hotfix_evidence'
1492
- };
1493
- }
1494
- const blockers: string[] = [];
1495
- const warnings: string[] = [];
1496
- const target = normalized.target || {};
1497
- const channel = normalized.channel;
1498
- const step = matchingHotfixPlanStep(policy, channel);
1499
- const requiredEvidence = step?.requiredEvidence || [];
1500
- const successEvidence = step?.successEvidence || [];
1501
- const policyAllowsFullDeploy = policy?.fullDeployAllowed === true;
1502
- const policyBlocksDuplicate = policy?.duplicateDeployBlocked === true || policy?.duplicatePublishBlocked === true;
1503
- const githubCommitGuard = evaluateResolveIOAIManagerHotfixGitProof(normalized, channel);
1504
- if (normalized.fullDeployRequested && !policyAllowsFullDeploy && channel !== 'force_deploy_review' && channel !== 'new_artifact_deploy') {
1505
- blockers.push('Full deploy requested but hotfix-first policy does not allow a full deploy for this release state.');
1506
- }
1507
- if (normalized.fullDeployRequested && policyBlocksDuplicate && !normalized.forceDeployReason && channel !== 'force_deploy_review') {
1508
- blockers.push('Duplicate deploy/publish fingerprint requires force deploy/publish evidence before any full deploy.');
1509
- }
1510
- if (githubCommitGuard.required) {
1511
- blockers.push(...githubCommitGuard.blockers);
1512
- }
1513
- if (channel === 'backend_js') {
1514
- pushMissing(blockers, !!normalized.compiledArtifactPath, 'Backend JS hotfix requires compiledArtifactPath.');
1515
- pushMissing(blockers, !!target.host, 'Backend JS hotfix requires target.host.');
1516
- pushMissing(blockers, !!target.path, 'Backend JS hotfix requires target.path.');
1517
- pushMissing(blockers, !!(normalized.remoteChecksumAfter || normalized.remoteChecksum), 'Backend JS hotfix requires remote checksum after replacement.');
1518
- if ((normalized.remoteChecksumAfter || normalized.remoteChecksum) && !isStrongRemoteChecksum(normalized.remoteChecksumAfter || normalized.remoteChecksum || '')) {
1519
- blockers.push('Backend JS hotfix remote checksum after replacement must be a strong hex checksum, not a label or placeholder.');
1520
- }
1521
- pushMissing(blockers, !!(normalized.restartEvidence || normalized.serviceRestartEvidence), 'Backend JS hotfix requires restart evidence.');
1522
- pushMissing(blockers, hotfixStatusPassed(normalized.healthCheckStatus), 'Backend JS hotfix requires passed healthCheckStatus.');
1523
- pushMissing(blockers, hotfixStatusPassed(normalized.selfTestStatus), 'Backend JS hotfix requires passed selfTestStatus.');
1524
- if (normalized.remoteChecksumBefore && normalized.remoteChecksumAfter && normalized.remoteChecksumBefore === normalized.remoteChecksumAfter) {
1525
- blockers.push('Backend JS hotfix checksum did not change; record force/no-op evidence or do not claim a hotfix.');
1526
- }
1527
- }
1528
- else if (channel === 'static_ui') {
1529
- pushMissing(blockers, !!normalized.builtDistPath, 'Static UI hotfix requires builtDistPath.');
1530
- pushMissing(blockers, !!target.bucket, 'Static UI hotfix requires target.bucket.');
1531
- pushMissing(blockers, !!target.distributionId, 'Static UI hotfix requires target.distributionId.');
1532
- pushMissing(blockers, !!normalized.s3UploadResult, 'Static UI hotfix requires s3UploadResult.');
1533
- pushMissing(blockers, !!normalized.cloudfrontInvalidationId, 'Static UI hotfix requires cloudfrontInvalidationId.');
1534
- pushMissing(blockers, !!normalized.publicProof, 'Static UI hotfix requires publicProof.');
1535
- }
1536
- else if (channel === 'config') {
1537
- pushMissing(blockers, !!target.configKey, 'Config hotfix requires target.configKey.');
1538
- pushMissing(blockers, !!normalized.configChangeEvidence, 'Config hotfix requires configChangeEvidence.');
1539
- pushMissing(blockers, hotfixStatusPassed(normalized.releaseGateStatus), 'Config hotfix requires passed releaseGateStatus.');
1540
- }
1541
- else if (channel === 'seed_data') {
1542
- pushMissing(blockers, !!target.seedKey, 'Seed-data hotfix requires target.seedKey.');
1543
- pushMissing(blockers, !!normalized.seedDataEvidence, 'Seed-data hotfix requires seedDataEvidence.');
1544
- pushMissing(blockers, hotfixStatusPassed(normalized.releaseGateStatus), 'Seed-data hotfix requires passed releaseGateStatus.');
1545
- }
1546
- else if (channel === 'cache_invalidation') {
1547
- pushMissing(blockers, !!target.cacheKey, 'Cache invalidation hotfix requires target.cacheKey.');
1548
- pushMissing(blockers, !!normalized.cacheInvalidationEvidence, 'Cache invalidation hotfix requires cacheInvalidationEvidence.');
1549
- pushMissing(blockers, hotfixStatusPassed(normalized.releaseGateStatus) || hotfixStatusPassed(normalized.healthCheckStatus), 'Cache invalidation hotfix requires passed releaseGateStatus or healthCheckStatus.');
1550
- }
1551
- else if (channel === 'service_restart') {
1552
- pushMissing(blockers, !!target.processName, 'Service restart hotfix requires target.processName.');
1553
- pushMissing(blockers, !!(normalized.serviceRestartEvidence || normalized.restartEvidence), 'Service restart hotfix requires restart evidence.');
1554
- pushMissing(blockers, hotfixStatusPassed(normalized.healthCheckStatus), 'Service restart hotfix requires passed healthCheckStatus.');
1555
- pushMissing(blockers, hotfixStatusPassed(normalized.selfTestStatus), 'Service restart hotfix requires passed selfTestStatus.');
1556
- }
1557
- else if (channel === 'release_artifact') {
1558
- pushMissing(blockers, !!normalized.releaseArtifactFingerprint, 'Release artifact hotfix requires releaseArtifactFingerprint.');
1559
- pushMissing(blockers, hotfixStatusPassed(normalized.releaseGateStatus), 'Release artifact hotfix requires passed releaseGateStatus.');
1560
- }
1561
- else if (channel === 'force_deploy_review') {
1562
- pushMissing(blockers, !!normalized.forceDeployReason, 'Force deploy review requires forceDeployReason.');
1563
- pushMissing(blockers, !!normalized.hotfixCannotResolveReason, 'Force deploy review requires hotfixCannotResolveReason.');
1564
- }
1565
- else if (channel === 'new_artifact_deploy') {
1566
- pushMissing(blockers, !!normalized.releaseArtifactFingerprint, 'New artifact deploy requires releaseArtifactFingerprint.');
1567
- pushMissing(blockers, !!normalized.lastReleaseArtifactFingerprint, 'New artifact deploy requires lastReleaseArtifactFingerprint.');
1568
- if (normalized.releaseArtifactFingerprint && normalized.lastReleaseArtifactFingerprint && normalized.releaseArtifactFingerprint === normalized.lastReleaseArtifactFingerprint) {
1569
- blockers.push('New artifact deploy requires a fingerprint different from the last deployed artifact.');
1570
- }
1571
- pushMissing(blockers, hotfixStatusPassed(normalized.releaseGateStatus), 'New artifact deploy requires passed releaseGateStatus.');
1572
- }
1573
- else if (channel === 'artifact_build') {
1574
- pushMissing(blockers, !!normalized.releaseArtifactFingerprint, 'Artifact build requires releaseArtifactFingerprint.');
1575
- if (normalized.fullDeployRequested) {
1576
- blockers.push('Artifact build evidence cannot request a full deploy in the same step.');
1577
- }
1578
- }
1579
- if (!step && policy) {
1580
- warnings.push(`Hotfix channel ${channel} is not the recommended channel in the current release policy.`);
1581
- }
1582
- const forceDeployReviewValid = channel === 'force_deploy_review' && blockers.length === 0;
1583
- const newArtifactDeployValid = channel === 'new_artifact_deploy' && blockers.length === 0;
1584
- const fullDeployAllowed = forceDeployReviewValid || newArtifactDeployValid || (policyAllowsFullDeploy && blockers.length === 0 && normalized.fullDeployRequested === true);
1585
- const hotfixSatisfied = blockers.length === 0 && !fullDeployAllowed;
1586
- const status: ResolveIOAIManagerHotfixEvidenceStatus = blockers.length
1587
- ? (normalizeHotfixStatus(normalized.status) === 'blocked' ? 'blocked' : 'incomplete')
1588
- : 'passed';
1589
- const fullDeployBlocked = !fullDeployAllowed && (normalized.fullDeployRequested === true || policy?.fullDeployAllowed !== true);
1590
- const nextAction: ResolveIOAIManagerHotfixEvidenceValidation['nextAction'] = blockers.some((blocker) => /force deploy/i.test(blocker))
1591
- ? 'request_force_deploy_reason'
1592
- : fullDeployAllowed
1593
- ? 'allow_one_full_deploy'
1594
- : hotfixSatisfied
1595
- ? 'rerun_release_gate'
1596
- : blockers.length
1597
- ? 'record_hotfix_evidence'
1598
- : 'park_manual';
1599
- normalized.status = status;
1600
- return {
1601
- valid: blockers.length === 0,
1602
- status,
1603
- channel,
1604
- blockers,
1605
- warnings,
1606
- fullDeployAllowed,
1607
- fullDeployBlocked,
1608
- hotfixSatisfied,
1609
- requiredEvidence,
1610
- successEvidence,
1611
- normalized,
1612
- githubCommitGuard,
1613
- policy,
1614
- nextAction
1615
- };
1616
- }
1617
-
1618
- function mergeHotfixEvidenceRecordInput(input: ResolveIOAIManagerHotfixEvidenceRecordInput): Record<string, any> {
1619
- const merged = {
1620
- ...cleanObject(input.evidence)
1621
- };
1622
- const directFields = [
1623
- 'channel',
1624
- 'status',
1625
- 'target',
1626
- 'compiledArtifactPath',
1627
- 'builtDistPath',
1628
- 'remoteChecksumBefore',
1629
- 'remoteChecksumAfter',
1630
- 'remoteChecksum',
1631
- 'restartEvidence',
1632
- 'healthCheckStatus',
1633
- 'selfTestStatus',
1634
- 'releaseGateStatus',
1635
- 's3UploadResult',
1636
- 'cloudfrontInvalidationId',
1637
- 'publicProof',
1638
- 'configChangeEvidence',
1639
- 'seedDataEvidence',
1640
- 'cacheInvalidationEvidence',
1641
- 'serviceRestartEvidence',
1642
- 'releaseArtifactFingerprint',
1643
- 'lastReleaseArtifactFingerprint',
1644
- 'sourceCommitSha',
1645
- 'githubCommitUrl',
1646
- 'gitCommitStatus',
1647
- 'gitPushStatus',
1648
- 'committedAt',
1649
- 'forceDeployReason',
1650
- 'hotfixCannotResolveReason',
1651
- 'fullDeployRequested',
1652
- 'recordedAt'
1653
- ];
1654
- for (const field of directFields) {
1655
- const value = (input as any)[field];
1656
- if (value !== undefined && value !== null && value !== '') {
1657
- (merged as any)[field] = value;
1658
- }
1659
- }
1660
- return merged;
1661
- }
1662
-
1663
- function resolveHotfixEvidenceRequiredFields(
1664
- channel: ResolveIOAIManagerHotfixChannel | ''
1665
- ): string[] {
1666
- const fields = ['channel'];
1667
- if (hotfixRequiresGithubCommit(channel)) {
1668
- fields.push('sourceCommitSha', 'githubCommitUrl', 'gitCommitStatus', 'gitPushStatus');
1669
- }
1670
- if (channel === 'backend_js') {
1671
- fields.push('compiledArtifactPath', 'target.host', 'target.path', 'remoteChecksumAfter', 'restartEvidence', 'healthCheckStatus', 'selfTestStatus');
1672
- }
1673
- else if (channel === 'static_ui') {
1674
- fields.push('builtDistPath', 'target.bucket', 'target.distributionId', 's3UploadResult', 'cloudfrontInvalidationId', 'publicProof');
1675
- }
1676
- else if (channel === 'config') {
1677
- fields.push('target.configKey', 'configChangeEvidence', 'releaseGateStatus');
1678
- }
1679
- else if (channel === 'seed_data') {
1680
- fields.push('target.seedKey', 'seedDataEvidence', 'releaseGateStatus');
1681
- }
1682
- else if (channel === 'cache_invalidation') {
1683
- fields.push('target.cacheKey', 'cacheInvalidationEvidence', 'releaseGateStatus_or_healthCheckStatus');
1684
- }
1685
- else if (channel === 'service_restart') {
1686
- fields.push('target.processName', 'serviceRestartEvidence', 'healthCheckStatus', 'selfTestStatus');
1687
- }
1688
- else if (channel === 'release_artifact') {
1689
- fields.push('releaseArtifactFingerprint', 'releaseGateStatus');
1690
- }
1691
- else if (channel === 'new_artifact_deploy') {
1692
- fields.push('releaseArtifactFingerprint', 'lastReleaseArtifactFingerprint', 'releaseGateStatus');
1693
- }
1694
- else if (channel === 'artifact_build') {
1695
- fields.push('releaseArtifactFingerprint');
1696
- }
1697
- else if (channel === 'force_deploy_review') {
1698
- fields.push('forceDeployReason', 'hotfixCannotResolveReason');
1699
- }
1700
- return Array.from(new Set(fields));
1701
- }
1702
-
1703
- function hotfixEvidenceFieldPresent(
1704
- evidence: ResolveIOAIManagerHotfixEvidence | undefined,
1705
- field: string
1706
- ): boolean {
1707
- if (!evidence) {
1708
- return false;
1709
- }
1710
- const target = evidence.target || {};
1711
- switch (field) {
1712
- case 'channel':
1713
- return !!evidence.channel;
1714
- case 'sourceCommitSha':
1715
- return isFullGitCommitSha(evidence.sourceCommitSha || '');
1716
- case 'githubCommitUrl':
1717
- return !!extractGithubCommitSha(evidence.githubCommitUrl || '');
1718
- case 'gitCommitStatus':
1719
- return hotfixStatusPassed(evidence.gitCommitStatus);
1720
- case 'gitPushStatus':
1721
- return hotfixStatusPassed(evidence.gitPushStatus);
1722
- case 'compiledArtifactPath':
1723
- return !!cleanText(evidence.compiledArtifactPath, 500);
1724
- case 'builtDistPath':
1725
- return !!cleanText(evidence.builtDistPath, 500);
1726
- case 'remoteChecksumAfter':
1727
- return !!cleanText(evidence.remoteChecksumAfter || evidence.remoteChecksum, 160);
1728
- case 'restartEvidence':
1729
- return !!cleanText(evidence.restartEvidence || evidence.serviceRestartEvidence, 1000);
1730
- case 'serviceRestartEvidence':
1731
- return !!cleanText(evidence.serviceRestartEvidence || evidence.restartEvidence, 1000);
1732
- case 'healthCheckStatus':
1733
- return hotfixStatusPassed(evidence.healthCheckStatus);
1734
- case 'selfTestStatus':
1735
- return hotfixStatusPassed(evidence.selfTestStatus);
1736
- case 'releaseGateStatus':
1737
- return hotfixStatusPassed(evidence.releaseGateStatus);
1738
- case 'releaseGateStatus_or_healthCheckStatus':
1739
- return hotfixStatusPassed(evidence.releaseGateStatus) || hotfixStatusPassed(evidence.healthCheckStatus);
1740
- case 's3UploadResult':
1741
- return !!cleanText(evidence.s3UploadResult, 1000);
1742
- case 'cloudfrontInvalidationId':
1743
- return !!cleanText(evidence.cloudfrontInvalidationId, 240);
1744
- case 'publicProof':
1745
- return !!cleanText(evidence.publicProof, 1000);
1746
- case 'configChangeEvidence':
1747
- return !!cleanText(evidence.configChangeEvidence, 1000);
1748
- case 'seedDataEvidence':
1749
- return !!cleanText(evidence.seedDataEvidence, 1000);
1750
- case 'cacheInvalidationEvidence':
1751
- return !!cleanText(evidence.cacheInvalidationEvidence, 1000);
1752
- case 'releaseArtifactFingerprint':
1753
- return !!cleanText(evidence.releaseArtifactFingerprint, 240);
1754
- case 'lastReleaseArtifactFingerprint':
1755
- return !!cleanText(evidence.lastReleaseArtifactFingerprint, 240);
1756
- case 'forceDeployReason':
1757
- return !!cleanText(evidence.forceDeployReason, 1000);
1758
- case 'hotfixCannotResolveReason':
1759
- return !!cleanText(evidence.hotfixCannotResolveReason, 1000);
1760
- case 'target.host':
1761
- return !!cleanText(target.host, 200);
1762
- case 'target.path':
1763
- return !!cleanText(target.path, 500);
1764
- case 'target.bucket':
1765
- return !!cleanText(target.bucket, 200);
1766
- case 'target.distributionId':
1767
- return !!cleanText(target.distributionId, 200);
1768
- case 'target.configKey':
1769
- return !!cleanText(target.configKey, 200);
1770
- case 'target.seedKey':
1771
- return !!cleanText(target.seedKey, 200);
1772
- case 'target.cacheKey':
1773
- return !!cleanText(target.cacheKey, 200);
1774
- case 'target.processName':
1775
- return !!cleanText(target.processName, 200);
1776
- default:
1777
- return false;
1778
- }
1779
- }
1780
-
1781
- export function buildResolveIOAIManagerHotfixEvidenceRecord(
1782
- input: ResolveIOAIManagerHotfixEvidenceRecordInput = {}
1783
- ): ResolveIOAIManagerHotfixEvidenceRecord {
1784
- const merged = mergeHotfixEvidenceRecordInput(input);
1785
- const normalized = normalizeResolveIOAIManagerHotfixEvidence(merged, input.policy);
1786
- const validation = validateResolveIOAIManagerHotfixEvidence(merged, { policy: input.policy });
1787
- const channel = validation.channel || normalized?.channel || input.policy?.hotfixPlan?.recommendedChannel || '';
1788
- const requiredFields = resolveHotfixEvidenceRequiredFields(channel);
1789
- const missingFields = requiredFields.filter((field) => !hotfixEvidenceFieldPresent(normalized, field));
1790
- const recordedAt = cleanDateString(input.now || normalized?.recordedAt || new Date());
1791
- const githubCommitGuard = validation.githubCommitGuard || evaluateResolveIOAIManagerHotfixGitProof(normalized || merged, channel);
1792
- const commitFirstProtocol = githubCommitGuard.required ? 'commit_first_hotfix' as const : 'not_required' as const;
1793
- const commitFirstProtocolSatisfied = githubCommitGuard.required ? githubCommitGuard.passed === true : true;
1794
- const liveHotfixBlockedUntilCommit = githubCommitGuard.required === true && commitFirstProtocolSatisfied !== true;
1795
- const liveHotfixAllowed = validation.valid === true && validation.hotfixSatisfied === true && commitFirstProtocolSatisfied === true;
1796
- const readyForContinuation = validation.valid === true && validation.hotfixSatisfied === true && hotfixStatusPassed(normalized?.releaseGateStatus);
1797
- return {
1798
- recordId: cleanText(input.recordId, 160) || `hotfix-${fingerprintResolveIOAIManagerBlocker(`${channel}:${githubCommitGuard.sourceCommitSha}:${recordedAt}`)}`,
1799
- recordedAt,
1800
- recordedBy: cleanText(input.recordedBy || 'manager', 160),
1801
- source: cleanText(input.source || 'unknown', 80),
1802
- reason: cleanText(input.reason, 1000),
1803
- channel,
1804
- status: validation.status,
1805
- nextAction: validation.nextAction,
1806
- valid: validation.valid,
1807
- hotfixSatisfied: validation.hotfixSatisfied,
1808
- fullDeployAllowed: validation.fullDeployAllowed,
1809
- fullDeployBlocked: validation.fullDeployBlocked,
1810
- requiredFields,
1811
- missingFields,
1812
- evidence: normalized,
1813
- validation,
1814
- sourceCommitSha: githubCommitGuard.sourceCommitSha,
1815
- githubCommitUrl: githubCommitGuard.githubCommitUrl,
1816
- gitCommitStatus: githubCommitGuard.gitCommitStatus,
1817
- gitPushStatus: githubCommitGuard.gitPushStatus,
1818
- githubCommitRequired: githubCommitGuard.required,
1819
- githubCommitProofPassed: githubCommitGuard.passed,
1820
- commitProofStatus: githubCommitGuard.status,
1821
- commitFirstProtocol,
1822
- commit_first_protocol: commitFirstProtocol,
1823
- commitFirstProtocolSatisfied,
1824
- commit_first_protocol_satisfied: commitFirstProtocolSatisfied,
1825
- liveHotfixBlockedUntilCommit,
1826
- live_hotfix_blocked_until_commit: liveHotfixBlockedUntilCommit,
1827
- liveHotfixAllowed,
1828
- live_hotfix_allowed: liveHotfixAllowed,
1829
- managerMustCommitBeforeHotfix: githubCommitGuard.managerMustCommitBeforeHotfix,
1830
- githubCommitGuard,
1831
- readyForReleaseGate: validation.valid === true && validation.nextAction === 'rerun_release_gate',
1832
- readyForContinuation,
1833
- managerContinuationAllowed: readyForContinuation,
1834
- manager_continuation_allowed: readyForContinuation
1835
- };
1836
- }
1837
-
1838
- function pickFirstHotfixText(sources: any[], keys: string[], max = 500, seen = new WeakSet<object>()): string {
1839
- for (const source of sources) {
1840
- const record = cleanObject(source);
1841
- if (!Object.keys(record).length || seen.has(record)) {
1842
- continue;
1843
- }
1844
- seen.add(record);
1845
- for (const key of keys) {
1846
- const value = cleanText(record[key], max);
1847
- if (value) {
1848
- return value;
1849
- }
1850
- }
1851
- for (const nestedKey of ['evidence', 'hotfixEvidence', 'hotfix_evidence', 'hotfixCommitProof', 'hotfix_commit_proof', 'hotfixCommitGuard', 'hotfix_commit_guard', 'githubCommitGuard', 'github_commit_guard']) {
1852
- const nestedValue = pickFirstHotfixText([record[nestedKey]], keys, max, seen);
1853
- if (nestedValue) {
1854
- return nestedValue;
1855
- }
1856
- }
1857
- }
1858
- return '';
1859
- }
1860
-
1861
- function hotfixDurabilityExtraRequest(contract: ResolveIOAIManagerHotfixDurabilityContract): string {
1862
- if (!contract.required) {
1863
- return '';
1864
- }
1865
- return [
1866
- 'Manager hotfix durability contract:',
1867
- `- Contract id: ${contract.contractId}`,
1868
- `- Live backend hotfix blocked until commit proof: ${contract.liveHotfixBlockedUntilCommit ? 'yes' : 'no'}`,
1869
- `- GitHub commit proof passed: ${contract.commitProofPassed ? 'yes' : 'no'}`,
1870
- contract.missingCommitProofFields.length ? `- Missing commit proof fields: ${contract.missingCommitProofFields.join(', ')}` : '',
1871
- contract.phaseOrder.length ? `- Required phase order: ${contract.phaseOrder.join(' -> ')}` : '',
1872
- contract.requiredFields.length ? `- Required evidence fields: ${contract.requiredFields.join(', ')}` : '',
1873
- contract.successCriteria.length ? `- Success criteria: ${contract.successCriteria.join(' | ')}` : '',
1874
- contract.forbiddenActions.length ? `- Forbidden actions: ${contract.forbiddenActions.join(' | ')}` : '',
1875
- '- Prepare the hotfix patch and GitHub commit proof before any live backend apply/restart.',
1876
- '- After commit proof exists, apply the backend hotfix only through the existing hotfix path, record restart/checksum evidence, run the runner-manager self-test, and rerun the smallest release gate.'
1877
- ].filter(Boolean).join('\n').slice(0, 3600);
1878
- }
1879
-
1880
- export function buildResolveIOAIManagerHotfixDurabilityContract(
1881
- input: ResolveIOAIManagerHotfixDurabilityContractInput = {}
1882
- ): ResolveIOAIManagerHotfixDurabilityContract {
1883
- const existing = cleanObject(input.existing);
1884
- const evidence = Object.keys(cleanObject(input.evidence)).length ? input.evidence : existing.evidence || existing.hotfixEvidence || existing.hotfix_evidence || existing;
1885
- const validation = validateResolveIOAIManagerHotfixEvidence(evidence, { policy: input.policy });
1886
- const continuation = input.continuation || undefined;
1887
- const githubCommitGuard = validation.githubCommitGuard || evaluateResolveIOAIManagerHotfixGitProof(evidence, validation.channel);
1888
- const sources = [evidence, existing, continuation, (continuation as any)?.githubCommitGuard, (continuation as any)?.github_commit_guard, githubCommitGuard];
1889
- const action = cleanText(input.action || existing.action || existing.dispatchAction || existing.dispatch_action || 'run_release_repair', 160);
1890
- const actionRequiresHotfix = /release_repair|hotfix|apply.*backend|deploy|publish/i.test(action);
1891
- const required = existing.required === true
1892
- || actionRequiresHotfix
1893
- || githubCommitGuard.required === true
1894
- || validation.githubCommitGuard?.required === true
1895
- || (continuation as any)?.githubCommitGuard?.required === true
1896
- || (continuation as any)?.github_commit_guard?.required === true
1897
- || input.policy?.hotfixPreferred === true;
1898
- const sourceCommitSha = githubCommitGuard.sourceCommitSha || pickFirstHotfixText(sources, ['sourceCommitSha', 'source_commit_sha', 'commitSha', 'commit_sha'], 120);
1899
- const githubCommitUrl = githubCommitGuard.githubCommitUrl || pickFirstHotfixText(sources, ['githubCommitUrl', 'github_commit_url', 'commitUrl', 'commit_url'], 500);
1900
- const gitCommitStatus = githubCommitGuard.gitCommitStatus || pickFirstHotfixText(sources, ['gitCommitStatus', 'git_commit_status', 'commitStatus', 'commit_status'], 160);
1901
- const gitPushStatus = githubCommitGuard.gitPushStatus || pickFirstHotfixText(sources, ['gitPushStatus', 'git_push_status', 'pushStatus', 'push_status'], 160);
1902
- const commitPassed = hotfixStatusPassed(gitCommitStatus);
1903
- const pushPassed = hotfixStatusPassed(gitPushStatus);
1904
- const sourceShaPassed = isFullGitCommitSha(sourceCommitSha);
1905
- const githubUrlSha = extractGithubCommitSha(githubCommitUrl);
1906
- const githubUrlPassed = !!githubUrlSha && (!sourceShaPassed || githubUrlSha === sourceCommitSha.toLowerCase());
1907
- const existingMissingCommitFields = cleanList(existing.missingCommitProofFields || existing.missing_commit_proof_fields, 20, 160);
1908
- const commitFirstProtocolRequired = githubCommitGuard.required === true
1909
- || existing.durabilityProtocol === 'commit_first_hotfix'
1910
- || existing.durability_protocol === 'commit_first_hotfix'
1911
- || existing.commitFirstProtocolRequired === true
1912
- || existing.commit_first_protocol_required === true
1913
- || existingMissingCommitFields.some((field) => /sourceCommitSha|githubCommitUrl|gitCommitStatus|gitPushStatus/i.test(field));
1914
- const durabilityProtocol = commitFirstProtocolRequired ? 'commit_first_hotfix' as const : 'not_required' as const;
1915
- const missingCommitProofFields = [
1916
- sourceShaPassed ? '' : 'sourceCommitSha',
1917
- githubUrlPassed ? '' : 'githubCommitUrl',
1918
- commitPassed ? '' : 'gitCommitStatus=passed',
1919
- pushPassed ? '' : 'gitPushStatus=passed'
1920
- ].filter(Boolean);
1921
- const commitProofPassed = required ? missingCommitProofFields.length === 0 : githubCommitGuard.passed === true;
1922
- const commitFirstProtocolSatisfied = commitFirstProtocolRequired ? commitProofPassed === true : true;
1923
- const liveHotfixBlockedUntilCommit = required && commitProofPassed !== true;
1924
- const releaseGatePassed = input.releaseGatePassed === true
1925
- || hotfixStatusPassed(validation.normalized?.releaseGateStatus)
1926
- || (continuation as any)?.canContinueRun === true;
1927
- const canPrepareHotfixPatch = required && (existing.canPrepareHotfixPatch === true || existing.can_prepare_hotfix_patch === true || actionRequiresHotfix || (continuation as any)?.action === 'record_hotfix_evidence');
1928
- const canHotfixBackend = required && commitProofPassed === true && canPrepareHotfixPatch === true;
1929
- const liveHotfixAllowed = required && commitFirstProtocolSatisfied === true && canPrepareHotfixPatch === true;
1930
- const managerContinuationAllowed = required
1931
- ? commitFirstProtocolSatisfied === true && validation.valid === true && releaseGatePassed === true
1932
- : true;
1933
- let status: ResolveIOAIManagerHotfixDurabilityStatus = 'not_required';
1934
- if (required && liveHotfixBlockedUntilCommit) {
1935
- status = 'waiting_for_commit_proof';
1936
- }
1937
- else if (required && validation.valid && releaseGatePassed) {
1938
- status = 'ready_for_continuation';
1939
- }
1940
- else if (required && validation.valid) {
1941
- status = 'ready_for_release_gate';
1942
- }
1943
- else if (required) {
1944
- status = 'ready_for_live_hotfix';
1945
- }
1946
- const phaseOrder = Array.from(new Set(cleanList(existing.phaseOrder || existing.phase_order, 12, 200).concat([
1947
- 'prepare_hotfix_patch_without_live_apply',
1948
- 'commit_and_push_hotfix_to_github',
1949
- 'record_hotfix_evidence',
1950
- 'apply_backend_hotfix_only_after_commit_proof',
1951
- 'run_runner_manager_self_test',
1952
- 'rerun_smallest_release_gate'
1953
- ]))).slice(0, 12);
1954
- const requiredFields = Array.from(new Set(cleanList(existing.requiredFields || existing.required_fields, 20, 200).concat([
1955
- 'sourceCommitSha',
1956
- 'githubCommitUrl',
1957
- 'gitCommitStatus=passed',
1958
- 'gitPushStatus=passed',
1959
- 'hotfixPatchDiff',
1960
- 'restartOrChecksumEvidence',
1961
- 'releaseGateResult'
1962
- ]))).slice(0, 20);
1963
- const requiredEvidence = Array.from(new Set(cleanList(existing.requiredEvidence || existing.required_evidence, 24, 300).concat(requiredFields, validation.requiredEvidence || []))).slice(0, 24);
1964
- const successCriteria = Array.from(new Set(cleanList(existing.successCriteria || existing.success_criteria, 14, 300).concat([
1965
- 'Hotfix patch exists without live apply side effects.',
1966
- 'GitHub commit and push proof are recorded before live hotfix.',
1967
- 'Backend restart/checksum evidence and runner-manager self-test pass.',
1968
- 'Only the smallest relevant release gate is rerun after hotfix evidence.'
1969
- ]))).slice(0, 14);
1970
- const forbiddenActions = Array.from(new Set(cleanList(existing.forbiddenActions || existing.forbidden_actions, 14, 500).concat([
1971
- 'Do not apply or restart a live backend before sourceCommitSha, githubCommitUrl, passed gitCommitStatus, and passed gitPushStatus are recorded.',
1972
- 'Do not run a full server deploy as a substitute for a targeted backend hotfix.',
1973
- 'Do not continue the ticket from route-only or release-status-only evidence.'
1974
- ]))).slice(0, 14);
1975
- const now = cleanDateString(input.now || new Date());
1976
- const createdAt = cleanDateString(existing.createdAt || existing.created_at || now);
1977
- const reason = cleanText(input.reason || existing.reason || (continuation as any)?.reason || validation.blockers.join('; '), 1000);
1978
- const contractId = cleanText(existing.contractId || existing.contract_id, 160)
1979
- || `hotfix-durability-${fingerprintResolveIOAIManagerBlocker([
1980
- action,
1981
- reason,
1982
- phaseOrder.join('|'),
1983
- createdAt.slice(0, 16)
1984
- ].join('\n')).slice(0, 16)}`;
1985
- const nextSafeAction = !required
1986
- ? 'continue'
1987
- : liveHotfixBlockedUntilCommit
1988
- ? 'commit_and_push_hotfix_to_github'
1989
- : validation.valid
1990
- ? (releaseGatePassed ? 'continue_current_runner' : 'rerun_smallest_release_gate')
1991
- : 'apply_backend_hotfix_only_after_commit_proof';
1992
- const hotfixCommitGuard = {
1993
- required,
1994
- blocks_live_hotfix: liveHotfixBlockedUntilCommit,
1995
- passed: commitProofPassed,
1996
- status: commitProofPassed ? 'passed' : 'missing',
1997
- sourceCommitSha,
1998
- githubCommitUrl,
1999
- gitCommitStatus,
2000
- gitPushStatus,
2001
- missingFields: missingCommitProofFields,
2002
- required_fields: ['sourceCommitSha', 'githubCommitUrl', 'gitCommitStatus=passed', 'gitPushStatus=passed'],
2003
- next_action: liveHotfixBlockedUntilCommit ? 'commit_and_push_hotfix_to_github' : 'record_hotfix_evidence'
2004
- };
2005
- const contract = {
2006
- contractId,
2007
- contract_id: contractId,
2008
- createdAt,
2009
- created_at: createdAt,
2010
- updatedAt: now,
2011
- updated_at: now,
2012
- source: cleanText(input.source || existing.source || 'ai_manager_hotfix_durability', 160),
2013
- required,
2014
- action,
2015
- status,
2016
- reason,
2017
- canPrepareHotfixPatch,
2018
- can_prepare_hotfix_patch: canPrepareHotfixPatch,
2019
- canHotfixBackend,
2020
- can_hotfix_backend: canHotfixBackend,
2021
- liveHotfixBlockedUntilCommit,
2022
- live_hotfix_blocked_until_commit: liveHotfixBlockedUntilCommit,
2023
- durabilityProtocol,
2024
- durability_protocol: durabilityProtocol,
2025
- commitFirstProtocolRequired,
2026
- commit_first_protocol_required: commitFirstProtocolRequired,
2027
- commitFirstProtocolSatisfied,
2028
- commit_first_protocol_satisfied: commitFirstProtocolSatisfied,
2029
- liveHotfixAllowed,
2030
- live_hotfix_allowed: liveHotfixAllowed,
2031
- managerContinuationAllowed,
2032
- manager_continuation_allowed: managerContinuationAllowed,
2033
- commitProofPassed,
2034
- commit_proof_passed: commitProofPassed,
2035
- commitProofStatus: commitProofPassed ? 'passed' as const : 'missing' as const,
2036
- commit_proof_status: commitProofPassed ? 'passed' as const : 'missing' as const,
2037
- sourceCommitSha,
2038
- source_commit_sha: sourceCommitSha,
2039
- githubCommitUrl,
2040
- github_commit_url: githubCommitUrl,
2041
- gitCommitStatus,
2042
- git_commit_status: gitCommitStatus,
2043
- gitPushStatus,
2044
- git_push_status: gitPushStatus,
2045
- missingCommitProofFields,
2046
- missing_commit_proof_fields: missingCommitProofFields,
2047
- nextSafeAction,
2048
- next_safe_action: nextSafeAction,
2049
- phaseOrder,
2050
- phase_order: phaseOrder,
2051
- requiredFields,
2052
- required_fields: requiredFields,
2053
- requiredEvidence,
2054
- required_evidence: requiredEvidence,
2055
- successCriteria,
2056
- success_criteria: successCriteria,
2057
- forbiddenActions,
2058
- forbidden_actions: forbiddenActions,
2059
- hotfixCommitGuard,
2060
- hotfix_commit_guard: hotfixCommitGuard,
2061
- githubCommitGuard: {
2062
- ...githubCommitGuard,
2063
- required,
2064
- passed: commitProofPassed,
2065
- status: commitProofPassed ? 'passed' as const : (required ? 'missing' as const : githubCommitGuard.status),
2066
- managerMustCommitBeforeHotfix: liveHotfixBlockedUntilCommit,
2067
- sourceCommitSha,
2068
- githubCommitUrl,
2069
- gitCommitStatus,
2070
- gitPushStatus
2071
- },
2072
- github_commit_guard: {
2073
- ...githubCommitGuard,
2074
- required,
2075
- passed: commitProofPassed,
2076
- status: commitProofPassed ? 'passed' as const : (required ? 'missing' as const : githubCommitGuard.status),
2077
- managerMustCommitBeforeHotfix: liveHotfixBlockedUntilCommit,
2078
- sourceCommitSha,
2079
- githubCommitUrl,
2080
- gitCommitStatus,
2081
- gitPushStatus
2082
- },
2083
- validation,
2084
- continuation,
2085
- extraRequest: '',
2086
- extra_request: ''
2087
- };
2088
- contract.extraRequest = hotfixDurabilityExtraRequest(contract);
2089
- contract.extra_request = contract.extraRequest;
2090
- return contract;
2091
- }
2092
-
2093
- export function decideResolveIOAIManagerHotfixContinuation(
2094
- input: ResolveIOAIManagerHotfixContinuationInput = {}
2095
- ): ResolveIOAIManagerHotfixContinuationDecision {
2096
- const validation = validateResolveIOAIManagerHotfixEvidence(input.evidence, { policy: input.policy });
2097
- const failureClass = cleanText(input.failureClass, 120) || 'release';
2098
- const blockerText = cleanText(input.blocker || validation.blockers.join('; ') || validation.normalized?.hotfixCannotResolveReason, 1000);
2099
- const blockerFingerprint = fingerprintResolveIOAIManagerBlocker(blockerText || `${validation.channel}:${validation.status}:${validation.nextAction}`);
2100
- const baseBlockers = [...validation.blockers];
2101
- const githubCommitGuard = validation.githubCommitGuard || evaluateResolveIOAIManagerHotfixGitProof(input.evidence, validation.channel);
2102
- const needsGithubCommitProof = githubCommitGuard.managerMustCommitBeforeHotfix
2103
- || validation.blockers.some((blocker) => /sourceCommitSha|githubCommitUrl|gitPushStatus|gitCommitStatus|GitHub commit|pushed/i.test(blocker));
2104
- const repeatedFailure = input.repeatedFailure === true;
2105
- const releaseGatePassed = input.releaseGatePassed === true
2106
- || hotfixStatusPassed(validation.normalized?.releaseGateStatus);
2107
- let action: ResolveIOAIManagerHotfixContinuationAction = validation.nextAction;
2108
- let canContinueRun = false;
2109
- let canRunFullDeploy = validation.fullDeployAllowed;
2110
- let shouldRerunReleaseGate = false;
2111
- let shouldPark = false;
2112
- let reason = '';
2113
- const nextCommands: string[] = [];
2114
-
2115
- if (githubCommitGuard.managerMustCommitBeforeHotfix) {
2116
- action = 'record_hotfix_evidence';
2117
- reason = githubCommitGuard.blockers.length
2118
- ? `Manager hotfix cannot continue until the hotfix is committed and pushed: ${githubCommitGuard.blockers.join('; ')}`
2119
- : 'Manager hotfix cannot continue until sourceCommitSha, githubCommitUrl, passed gitCommitStatus, and passed gitPushStatus prove the hotfix is committed and pushed to GitHub.';
2120
- nextCommands.push(...githubCommitGuard.nextCommands, 'rerun_hotfix_evidence_validator');
2121
- for (const blocker of githubCommitGuard.blockers) {
2122
- if (!baseBlockers.includes(blocker)) {
2123
- baseBlockers.push(blocker);
2124
- }
2125
- }
2126
- }
2127
- else if (!validation.valid || validation.status === 'missing' || validation.status === 'incomplete') {
2128
- action = validation.nextAction === 'request_force_deploy_reason'
2129
- ? 'request_force_deploy_reason'
2130
- : 'record_hotfix_evidence';
2131
- reason = validation.blockers.length
2132
- ? `Hotfix evidence is not complete: ${validation.blockers.join('; ')}`
2133
- : 'Hotfix evidence is missing; record the hotfix target, checksum, restart, health, and self-test proof before continuing.';
2134
- if (needsGithubCommitProof) {
2135
- nextCommands.push('commit_and_push_hotfix_to_github', 'verify_github_commit_url_and_push_status');
2136
- }
2137
- nextCommands.push('record_hotfix_evidence', 'rerun_hotfix_evidence_validator');
2138
- }
2139
- else if (validation.fullDeployAllowed) {
2140
- action = 'allow_one_full_deploy';
2141
- canRunFullDeploy = true;
2142
- reason = 'Hotfix evidence proves the duplicate release cannot be resolved by a hotfix, or a new artifact was verified, so exactly one full deploy can proceed.';
2143
- nextCommands.push('run_release_gate_once', 'execute_one_full_deploy_with_force_evidence', 'record_deploy_result');
2144
- }
2145
- else if (repeatedFailure) {
2146
- action = 'park_manual';
2147
- shouldPark = true;
2148
- reason = 'The same release failure repeated after valid hotfix evidence; park for manual review instead of looping or redeploying blindly.';
2149
- nextCommands.push('park_manual_with_hotfix_evidence', 'attach_release_gate_logs');
2150
- }
2151
- else if (validation.hotfixSatisfied && releaseGatePassed) {
2152
- action = 'continue_runner';
2153
- canContinueRun = true;
2154
- reason = 'Hotfix evidence and the release gate both passed; continue the current runner without a full deploy.';
2155
- nextCommands.push('continue_current_runner', 'record_hotfix_continuation');
2156
- }
2157
- else if (validation.hotfixSatisfied) {
2158
- action = 'rerun_release_gate';
2159
- shouldRerunReleaseGate = true;
2160
- reason = 'Hotfix evidence passed; rerun the smallest release gate before continuing the runner.';
2161
- nextCommands.push('rerun_release_gate_once', 'record_release_gate_status');
2162
- }
2163
- else {
2164
- action = 'park_manual';
2165
- shouldPark = true;
2166
- reason = 'Hotfix evidence reached an unsupported state; park instead of starting another broad deploy or model loop.';
2167
- baseBlockers.push('Unsupported hotfix continuation state.');
2168
- nextCommands.push('park_manual_with_hotfix_evidence');
2169
- }
2170
-
2171
- return {
2172
- action,
2173
- canContinueRun,
2174
- canRunFullDeploy,
2175
- shouldRerunReleaseGate,
2176
- shouldPark,
2177
- reason,
2178
- blockers: baseBlockers,
2179
- warnings: validation.warnings,
2180
- requiredEvidence: validation.requiredEvidence,
2181
- successEvidence: validation.successEvidence,
2182
- nextCommands: Array.from(new Set(nextCommands)),
2183
- failureClass,
2184
- blockerFingerprint,
2185
- githubCommitGuard,
2186
- validation,
2187
- recordedAt: isoNow(input.now)
2188
- };
2189
- }
2190
-
2191
- export function decideResolveIOAIManagerHotfixCommitGuard(
2192
- input: ResolveIOAIManagerHotfixContinuationInput = {}
2193
- ): ResolveIOAIManagerHotfixCommitGuardDecision {
2194
- const normalized = normalizeResolveIOAIManagerHotfixEvidence(input.evidence, input.policy);
2195
- const validation = validateResolveIOAIManagerHotfixEvidence(input.evidence, { policy: input.policy });
2196
- const githubCommitGuard = validation.githubCommitGuard || evaluateResolveIOAIManagerHotfixGitProof(input.evidence, validation.channel);
2197
- const active = !!normalized || githubCommitGuard.required === true;
2198
- const hotfixCommitBlockers = validation.blockers.filter((blocker) => /sourceCommitSha|githubCommitUrl|gitPushStatus|gitCommitStatus|GitHub commit|pushed/i.test(blocker));
2199
- const blockers = Array.from(new Set([
2200
- ...(githubCommitGuard.blockers || []),
2201
- ...hotfixCommitBlockers
2202
- ]));
2203
- const blocked = active && (
2204
- githubCommitGuard.managerMustCommitBeforeHotfix === true
2205
- || (githubCommitGuard.required === true && githubCommitGuard.passed !== true)
2206
- || hotfixCommitBlockers.length > 0
2207
- );
2208
- const nextCommands = blocked
2209
- ? Array.from(new Set([
2210
- ...(githubCommitGuard.nextCommands || []),
2211
- 'commit_and_push_hotfix_to_github',
2212
- 'verify_github_commit_url_and_push_status',
2213
- 'record_hotfix_evidence'
2214
- ]))
2215
- : [];
2216
- return {
2217
- active,
2218
- blocked,
2219
- reason: blocked
2220
- ? (blockers.length
2221
- ? `Hotfix continuation is blocked until GitHub commit proof is recorded: ${blockers.join('; ')}`
2222
- : 'Hotfix continuation is blocked until sourceCommitSha, githubCommitUrl, passed gitCommitStatus, and passed gitPushStatus prove the hotfix is committed and pushed to GitHub.')
2223
- : (active ? 'Hotfix GitHub commit proof is recorded.' : 'No hotfix commit guard is active.'),
2224
- nextAction: blocked ? 'record_hotfix_evidence' : 'continue',
2225
- channel: validation.channel || githubCommitGuard.channel || '',
2226
- blockers,
2227
- nextCommands,
2228
- requiredEvidence: githubCommitGuard.requiredEvidence,
2229
- githubCommitGuard,
2230
- validation
2231
- };
2232
- }
2233
-
2234
- function releaseStatusIsBlocked(value: string): boolean {
2235
- return /fail|error|blocked|missing|empty|not ready|not_ready|denied|invalid|timeout|stale/i.test(value);
2236
- }
2237
-
2238
- function releaseStatusIsTerminalDeploy(value: string): boolean {
2239
- return /requested|queued|in.?progress|completed|complete|success|succeeded|pass|passed|published|deployed|failed|error|blocked/i.test(value);
2240
- }
2241
-
2242
- function buildReleaseAllowedActions(action: ResolveIOAIManagerHotfixFirstReleaseAction): string[] {
2243
- if (action === 'wait_for_active_deploy') {
2244
- return ['wait_for_current_deploy_result', 'collect_current_deploy_log', 'refresh_release_snapshot'];
2245
- }
2246
- if (action === 'block_duplicate_deploy') {
2247
- return ['collect_existing_deploy_evidence', 'hotfix_release_artifact', 'request_force_deploy_with_reason'];
2248
- }
2249
- if (action === 'block_duplicate_publish') {
2250
- return ['collect_existing_publish_evidence', 'hotfix_release_artifact', 'request_force_publish_with_reason'];
2251
- }
2252
- if (action === 'review_force_deploy') {
2253
- return ['verify_force_deploy_reason', 'rerun_failed_release_gate_once', 'record_force_deploy_evidence'];
2254
- }
2255
- if (action === 'deploy_new_artifact_after_release_gate') {
2256
- return ['verify_new_artifact_fingerprint', 'run_release_gate_once', 'record_publish_deploy_evidence'];
2257
- }
2258
- if (action === 'build_artifact_first') {
2259
- return ['build_missing_release_artifact', 'record_artifact_fingerprint', 'run_release_gate_once'];
2260
- }
2261
- return ['hotfix_live_runner_or_release_artifact', 'rerun_failed_release_gate_only', 'record_release_evidence'];
2262
- }
2263
-
2264
- function hotfixStep(
2265
- id: string,
2266
- label: string,
2267
- channel: ResolveIOAIManagerHotfixChannel,
2268
- options: {
2269
- safeToAutoRun?: boolean;
2270
- requiresFullDeploy?: boolean;
2271
- requiredEvidence?: string[];
2272
- successEvidence?: string[];
2273
- blockedBy?: string[];
2274
- } = {}
2275
- ): ResolveIOAIManagerHotfixPlanStep {
2276
- return {
2277
- id,
2278
- label,
2279
- channel,
2280
- safeToAutoRun: options.safeToAutoRun === true,
2281
- requiresFullDeploy: options.requiresFullDeploy === true,
2282
- requiredEvidence: options.requiredEvidence || [],
2283
- successEvidence: options.successEvidence || [],
2284
- blockedBy: options.blockedBy || []
2285
- };
2286
- }
2287
-
2288
- function buildHotfixFirstReleasePlan(input: {
2289
- action: ResolveIOAIManagerHotfixFirstReleaseAction;
2290
- surface: string;
2291
- reason: string;
2292
- releaseBlocked: boolean;
2293
- }): ResolveIOAIManagerHotfixPlan {
2294
- const surface = cleanText(input.surface || 'runner', 80)
2295
- .toLowerCase()
2296
- .replace(/[^a-z0-9]+/g, '_')
2297
- .replace(/^_+|_+$/g, '') || 'runner';
2298
- const commonAcceptance = [
2299
- 'failed release gate is rerun once and passes',
2300
- 'artifact fingerprint or hotfix evidence is recorded',
2301
- 'operator console shows no active duplicate deploy blocker'
2302
- ];
2303
- if (input.action === 'wait_for_active_deploy') {
2304
- return {
2305
- planId: `${surface}:wait_for_active_deploy`,
2306
- label: 'Wait For Active Deploy',
2307
- recommendedChannel: 'release_artifact',
2308
- reason: input.reason,
2309
- fullDeployAvoided: true,
2310
- steps: [
2311
- hotfixStep('collect_active_deploy_log', 'Collect active deploy log', 'release_artifact', {
2312
- safeToAutoRun: true,
2313
- requiredEvidence: ['active deploy id or release operation id'],
2314
- successEvidence: ['terminal deploy status and release log captured']
2315
- })
2316
- ],
2317
- acceptanceEvidence: commonAcceptance,
2318
- escalationTriggers: ['active deploy exceeds timeout', 'active deploy fails without a release log']
2319
- };
2320
- }
2321
- if (input.action === 'deploy_new_artifact_after_release_gate') {
2322
- return {
2323
- planId: `${surface}:deploy_new_artifact_after_release_gate`,
2324
- label: 'Deploy New Artifact After Release Gate',
2325
- recommendedChannel: 'new_artifact_deploy',
2326
- reason: input.reason,
2327
- fullDeployAvoided: false,
2328
- steps: [
2329
- hotfixStep('verify_new_artifact_fingerprint', 'Verify new artifact fingerprint', 'new_artifact_deploy', {
2330
- safeToAutoRun: true,
2331
- requiresFullDeploy: true,
2332
- requiredEvidence: ['current artifact fingerprint differs from last deployed fingerprint'],
2333
- successEvidence: ['release gate permits one full deploy']
2334
- })
2335
- ],
2336
- acceptanceEvidence: [
2337
- 'new artifact fingerprint recorded',
2338
- 'release gate passed before full deploy',
2339
- 'deploy/publish result recorded'
2340
- ],
2341
- escalationTriggers: ['artifact fingerprint matches last deploy', 'release gate fails']
2342
- };
2343
- }
2344
- if (input.action === 'build_artifact_first') {
2345
- return {
2346
- planId: `${surface}:build_artifact_first`,
2347
- label: 'Build Artifact First',
2348
- recommendedChannel: 'artifact_build',
2349
- reason: input.reason,
2350
- fullDeployAvoided: true,
2351
- steps: [
2352
- hotfixStep('build_once_record_fingerprint', 'Build once and record fingerprint', 'artifact_build', {
2353
- safeToAutoRun: false,
2354
- requiredEvidence: ['missing artifact fingerprint', 'release gate reason for building'],
2355
- successEvidence: ['artifact fingerprint recorded before any deploy']
2356
- })
2357
- ],
2358
- acceptanceEvidence: ['artifact fingerprint exists', 'no deploy queued before release gate'],
2359
- escalationTriggers: ['build repeats without a new fingerprint', 'build failure lacks compile log']
2360
- };
2361
- }
2362
- if (input.action === 'review_force_deploy') {
2363
- return {
2364
- planId: `${surface}:review_force_deploy`,
2365
- label: 'Review Force Deploy',
2366
- recommendedChannel: 'force_deploy_review',
2367
- reason: input.reason,
2368
- fullDeployAvoided: false,
2369
- steps: [
2370
- hotfixStep('verify_force_deploy_reason', 'Verify force deploy reason', 'force_deploy_review', {
2371
- requiredEvidence: ['explicit force_deploy reason', 'why hotfix cannot resolve the release blocker'],
2372
- successEvidence: ['one allowed deploy attempt is recorded with reason']
2373
- })
2374
- ],
2375
- acceptanceEvidence: ['force deploy evidence recorded', 'duplicate fingerprint exception is auditable'],
2376
- escalationTriggers: ['force deploy reason is empty', 'same force deploy fails twice']
2377
- };
2378
- }
2379
- return {
2380
- planId: `${surface}:${input.action}`,
2381
- label: input.action === 'block_duplicate_deploy'
2382
- ? 'Hotfix Or Force Deploy'
2383
- : input.action === 'block_duplicate_publish'
2384
- ? 'Hotfix Or Force Publish'
2385
- : 'Hotfix Release Artifact',
2386
- recommendedChannel: input.action === 'block_duplicate_publish'
2387
- ? 'release_artifact'
2388
- : input.releaseBlocked ? 'release_artifact' : 'static_ui',
2389
- reason: input.reason,
2390
- fullDeployAvoided: true,
2391
- steps: [
2392
- hotfixStep('static_ui_hotfix', 'Static UI hotfix', 'static_ui', {
2393
- safeToAutoRun: true,
2394
- requiredEvidence: ['sourceCommitSha, githubCommitUrl, passed gitCommitStatus, and passed gitPushStatus', 'built dist path', 'target S3 bucket and CloudFront distribution', 'changed frontend bundle or asset list'],
2395
- successEvidence: ['GitHub commit and push proof', 'S3 upload result', 'CloudFront invalidation id', 'public bundle contains expected hotfix marker']
2396
- }),
2397
- hotfixStep('backend_js_hotfix', 'Backend JS hotfix', 'backend_js', {
2398
- requiredEvidence: ['sourceCommitSha, githubCommitUrl, passed gitCommitStatus, and passed gitPushStatus', 'compiled JS artifact path', 'target backend host', 'diff limited to runner/operator code'],
2399
- successEvidence: ['GitHub commit and push proof', 'remote file checksum', 'service restart or process reload evidence', 'self-test passes']
2400
- }),
2401
- hotfixStep('config_seed_cache_restart', 'Config, seed, cache, or restart repair', 'config', {
2402
- safeToAutoRun: true,
2403
- requiredEvidence: ['sourceCommitSha, githubCommitUrl, passed gitCommitStatus, and passed gitPushStatus', 'exact config/seed/cache key or process name', 'why no product artifact changed'],
2404
- successEvidence: ['GitHub commit and push proof', 'release gate rerun result', 'operator console release snapshot refreshed']
2405
- })
2406
- ],
2407
- acceptanceEvidence: commonAcceptance,
2408
- escalationTriggers: [
2409
- 'hotfix changes customer-facing product code outside the release artifact',
2410
- 'same release gate fails twice after hotfix evidence',
2411
- 'same publish fingerprint is retried without force_publish evidence',
2412
- 'force deploy is requested without a reason'
2413
- ]
2414
- };
2415
- }
2416
-
2417
- export function buildResolveIOAIManagerHotfixFirstReleasePolicy(
2418
- input: ResolveIOAIManagerHotfixFirstReleasePolicyInput = {}
2419
- ): ResolveIOAIManagerHotfixFirstReleasePolicy {
2420
- const surface = cleanText(input.surface || 'runner', 120);
2421
- const deployStatus = cleanText(input.deployStatus, 160);
2422
- const publishStatus = cleanText(input.publishStatus, 160);
2423
- const sampleDataStatus = cleanText(input.sampleDataStatus, 160);
2424
- const deployFingerprint = cleanText(input.deployFingerprint, 240);
2425
- const lastDeployFingerprint = cleanText(input.lastDeployFingerprint, 240);
2426
- const publishFingerprint = cleanText(input.publishFingerprint, 240);
2427
- const lastPublishFingerprint = cleanText(input.lastPublishFingerprint, 240);
2428
- const fingerprintMatchesLast = !!deployFingerprint && !!lastDeployFingerprint && deployFingerprint === lastDeployFingerprint;
2429
- const publishFingerprintMatchesLast = !!publishFingerprint && !!lastPublishFingerprint && publishFingerprint === lastPublishFingerprint;
2430
- const releaseBlocked = [deployStatus, publishStatus, sampleDataStatus].some(releaseStatusIsBlocked);
2431
- const duplicateDeployBlocked = fingerprintMatchesLast
2432
- && input.forceDeploy !== true
2433
- && releaseStatusIsTerminalDeploy([deployStatus, publishStatus].filter(Boolean).join(' '));
2434
- const duplicatePublishBlocked = publishFingerprintMatchesLast
2435
- && input.forcePublish !== true
2436
- && releaseStatusIsBlocked(publishStatus)
2437
- && releaseStatusIsTerminalDeploy(publishStatus);
2438
- let recommendedAction: ResolveIOAIManagerHotfixFirstReleaseAction = 'hotfix_release_artifact';
2439
- let label = 'Hotfix Release Artifact';
2440
- let reason = 'Repair the live runner/operator code, release config, domain, seed-data, or release artifact and rerun only the failed release gate.';
2441
- let fullDeployAllowed = false;
2442
- if (input.activeDeploy === true) {
2443
- recommendedAction = 'wait_for_active_deploy';
2444
- label = 'Wait For Active Deploy';
2445
- reason = 'A deploy is already queued or running; collect that result before spending another deploy cycle.';
2446
- }
2447
- else if (duplicateDeployBlocked) {
2448
- recommendedAction = 'block_duplicate_deploy';
2449
- label = 'Block Duplicate Deploy';
2450
- reason = 'The same artifact fingerprint already has release status; hotfix or provide explicit force_deploy evidence before rerunning it.';
2451
- }
2452
- else if (duplicatePublishBlocked) {
2453
- recommendedAction = 'block_duplicate_publish';
2454
- label = 'Block Duplicate Publish';
2455
- reason = 'The same publish fingerprint already has release status; hotfix the release artifact or provide explicit force_publish evidence before rerunning publish.';
2456
- }
2457
- else if ((fingerprintMatchesLast && input.forceDeploy === true) || (publishFingerprintMatchesLast && input.forcePublish === true)) {
2458
- recommendedAction = 'review_force_deploy';
2459
- label = 'Review Force Deploy';
2460
- reason = input.forcePublish === true
2461
- ? 'force_publish was explicitly requested for a repeated publish artifact; require a reason and rerun only the failed release gate.'
2462
- : 'force_deploy was explicitly requested for a repeated artifact; require a reason and rerun only the failed release gate.';
2463
- fullDeployAllowed = true;
2464
- }
2465
- else if (input.hasNewArtifact === false && !releaseBlocked) {
2466
- recommendedAction = 'build_artifact_first';
2467
- label = 'Build Artifact First';
2468
- reason = 'No release artifact fingerprint is available yet; build once, record the fingerprint, and avoid repeated deploys.';
2469
- }
2470
- else if (input.hasNewArtifact === true && !releaseBlocked) {
2471
- recommendedAction = 'deploy_new_artifact_after_release_gate';
2472
- label = 'Deploy New Artifact After Release Gate';
2473
- reason = 'A new artifact can be deployed after the release gate proves the artifact is new and ready.';
2474
- fullDeployAllowed = true;
2475
- }
2476
- const allowedActions = buildReleaseAllowedActions(recommendedAction);
2477
- const hotfixPlan = buildHotfixFirstReleasePlan({
2478
- action: recommendedAction,
2479
- surface,
2480
- reason,
2481
- releaseBlocked
2482
- });
2483
- return {
2484
- policy: 'hotfix_first',
2485
- surface,
2486
- recommendedAction,
2487
- label,
2488
- reason,
2489
- hotfixPreferred: recommendedAction !== 'deploy_new_artifact_after_release_gate' && recommendedAction !== 'review_force_deploy',
2490
- fullDeployAllowed,
2491
- duplicateDeployBlocked,
2492
- duplicatePublishBlocked,
2493
- forceDeployRequiredToRepeat: true,
2494
- forcePublishRequiredToRepeat: true,
2495
- statuses: {
2496
- deploy: deployStatus,
2497
- publish: publishStatus,
2498
- sampleData: sampleDataStatus
2499
- },
2500
- fingerprints: {
2501
- current: deployFingerprint,
2502
- last: lastDeployFingerprint,
2503
- matchesLast: fingerprintMatchesLast,
2504
- publishCurrent: publishFingerprint,
2505
- publishLast: lastPublishFingerprint,
2506
- publishMatchesLast: publishFingerprintMatchesLast
2507
- },
2508
- hotfixPlan,
2509
- allowedActions,
2510
- forbiddenActions: [
2511
- 'rerun full builder loop for a release-only blocker',
2512
- 'queue duplicate deploy without force_deploy evidence',
2513
- 'queue duplicate publish without force_publish evidence',
2514
- 'publish/deploy again before reading the failed release log',
2515
- 'change core workflow after business proof passed unless release evidence proves it is required'
2516
- ],
2517
- requiredEvidence: [
2518
- 'failed release gate log or active deploy result',
2519
- 'deploy artifact fingerprint comparison',
2520
- 'publish artifact fingerprint comparison when publish is the failed gate',
2521
- 'hotfix/config/seed/domain change evidence when no new product artifact is needed',
2522
- 'force_deploy or force_publish reason when repeating the same fingerprint'
2523
- ]
2524
- };
2525
- }
2526
-
2527
- export function isResolveIOAIManagerSafeAutoDispatch(
2528
- input: ResolveIOAIManagerAutoDispatchPolicyInput | ResolveIOAIManagerRecoveryActionDispatchAction | string | undefined
2529
- ): boolean {
2530
- const normalizedInput = typeof input === 'string'
2531
- ? { dispatchAction: input }
2532
- : (input || {});
2533
- const dispatchAction = cleanText(normalizedInput.dispatchAction || normalizedInput.directive?.dispatchAction, 120);
2534
- const directiveAllowed = normalizedInput.directive?.allowed;
2535
- const actionAutoRunnable = normalizedInput.action?.autoRunnable;
2536
- const productRepairAllowed = normalizedInput.directive?.canRunProductRepair === true
2537
- || normalizedInput.directive?.productRepairAllowed === true
2538
- || normalizedInput.action?.productRepairAllowed === true;
2539
- const expensiveModelAllowed = normalizedInput.directive?.canRunExpensiveModel === true
2540
- || normalizedInput.directive?.expensiveModelAllowed === true
2541
- || normalizedInput.action?.expensiveModelAllowed === true;
2542
- if (!dispatchAction || dispatchAction === 'park_manual') {
2543
- return false;
2544
- }
2545
- if (directiveAllowed === false || actionAutoRunnable === false) {
2546
- return false;
2547
- }
2548
- if ([
2549
- 'run_evidence_probe',
2550
- 'run_read_only_diagnosis',
2551
- 'run_infra_repair',
2552
- 'run_compile_repair'
2553
- ].includes(dispatchAction)) {
2554
- return true;
2555
- }
2556
- if (dispatchAction === 'run_release_repair') {
2557
- return normalizedInput.includeReleaseRepair !== false;
2558
- }
2559
- if (dispatchAction === 'run_journey_contract_repair') {
2560
- return normalizedInput.includeJourneyContractRepair !== false && productRepairAllowed !== true;
2561
- }
2562
- if (dispatchAction === 'run_business_assertion_repair') {
2563
- return normalizedInput.includeBusinessProofRepair === true
2564
- && productRepairAllowed !== true
2565
- && expensiveModelAllowed !== true;
2566
- }
2567
- if (dispatchAction === 'run_targeted_product_repair') {
2568
- return normalizedInput.includeProductRepair === true
2569
- && productRepairAllowed === true
2570
- && expensiveModelAllowed !== true;
2571
- }
2572
- return dispatchAction === 'advance' || dispatchAction === 'continue_gate';
2573
- }
2574
-
2575
- function isoNow(value?: Date | string): string {
2576
- if (value instanceof Date) {
2577
- return value.toISOString();
2578
- }
2579
- const parsed = value ? new Date(value) : new Date();
2580
- if (Number.isFinite(parsed.getTime())) {
2581
- return parsed.toISOString();
2582
- }
2583
- return new Date().toISOString();
2584
- }
2585
-
2586
- function stableHash(prefix: string, value: any): string {
2587
- const normalized = typeof value === 'string'
2588
- ? cleanText(value, 12000)
2589
- : JSON.stringify(value || {});
2590
- let hash = 0;
2591
- for (let index = 0; index < normalized.length; index += 1) {
2592
- hash = ((hash << 5) - hash + normalized.charCodeAt(index)) | 0;
2593
- }
2594
- return `${prefix}-${Math.abs(hash).toString(36) || '0'}`;
2595
- }
2596
-
2597
- export function normalizeResolveIOAIManagerFailureClass(value: any): string {
2598
- const normalized = cleanText(value, 80)
2599
- .toLowerCase()
2600
- .replace(/[\s-]+/g, '_');
2601
- if (!normalized) {
2602
- return 'unknown';
2603
- }
2604
- if (/^(qa_infra|infrastructure|harness|puppeteer|chrome|mongo|port|startup)$/.test(normalized)) {
2605
- return 'infra';
2606
- }
2607
- if (/^(build|compile|typescript|tsc|angular_build|ng_build)$/.test(normalized)) {
2608
- return 'compile';
2609
- }
2610
- if (/^(false_pass|route_only|missing_business_proof)$/.test(normalized)) {
2611
- return 'business';
2612
- }
2613
- return normalized.slice(0, 80);
2614
- }
2615
-
2616
- export function fingerprintResolveIOAIManagerBlocker(value: any): string {
2617
- const normalized = cleanText(value, 4000)
2618
- .toLowerCase()
2619
- .replace(/[a-f0-9]{16,}/g, '<id>')
2620
- .replace(/\b\d{2,}\b/g, '<n>')
2621
- .replace(/\bline\s+<n>\b/g, 'line <n>')
2622
- .replace(/https?:\/\/\S+/g, '<url>')
2623
- .replace(/\s+/g, ' ')
2624
- .trim();
2625
- return stableHash('mgr-blocker', normalized);
2626
- }
2627
-
2628
- function resolveResolveIOAIManagerBlockerFingerprint(
2629
- record: ResolveIOAIManagerFailureRecord | undefined,
2630
- fallback?: any
2631
- ): string {
2632
- const blockerText = cleanText(record?.blocker || record?.summary, 4000);
2633
- if (blockerText) {
2634
- return fingerprintResolveIOAIManagerBlocker(blockerText);
2635
- }
2636
- const explicit = cleanText(record?.blockerFingerprint, 120);
2637
- if (explicit) {
2638
- return explicit;
2639
- }
2640
- return fingerprintResolveIOAIManagerBlocker(fallback || '');
2641
- }
2642
-
2643
- export function hashResolveIOAIManagerEvidence(record: ResolveIOAIManagerFailureRecord | undefined): string {
2644
- if (!record) {
2645
- return stableHash('mgr-evidence', '');
2646
- }
2647
- const explicit = cleanText(record.evidenceHash, 120);
2648
- if (explicit) {
2649
- return explicit;
2650
- }
2651
- return stableHash('mgr-evidence', {
2652
- failureClass: normalizeResolveIOAIManagerFailureClass(record.failureClass),
2653
- blocker: cleanText(record.blocker || record.summary, 2000),
2654
- changedFiles: cleanList(record.changedFiles, 80, 500).sort(),
2655
- artifactPaths: cleanList(record.artifactPaths, 80, 500).sort()
2656
- });
2657
- }
2658
-
2659
- export function buildResolveIOAIManagerRecoveryCheckpoint(
2660
- input: ResolveIOAIManagerRecoveryCheckpointInput
2661
- ): ResolveIOAIManagerRecoveryCheckpoint {
2662
- const plan = input.plan;
2663
- const current = input.current || {};
2664
- const blockerFingerprint = resolveResolveIOAIManagerBlockerFingerprint(current, plan.objective);
2665
- const evidenceHash = hashResolveIOAIManagerEvidence(current);
2666
- const changedFiles = cleanList(current.changedFiles, 80, 500);
2667
- const artifactPaths = cleanList(current.artifactPaths, 80, 500);
2668
- const previous = input.previousCheckpoint;
2669
- const sameCheckpointBase = previous
2670
- && previous.recoveryClass === plan.recoveryClass
2671
- && previous.lane === plan.lane
2672
- && previous.stepType === plan.stepType
2673
- && previous.blockerFingerprint === blockerFingerprint
2674
- && previous.evidenceHash === evidenceHash;
2675
- const attempts = sameCheckpointBase ? Math.max(0, Number(previous.attempts || 0)) + 1 : 1;
2676
- const status: ResolveIOAIManagerRecoveryCheckpointStatus = plan.recoveryClass === 'manual_handoff'
2677
- ? 'manual_handoff'
2678
- : plan.recoveryClass === 'blocked_until_new_evidence'
2679
- ? 'parked'
2680
- : plan.recoveryClass === 'advance_after_proof'
2681
- ? 'complete'
2682
- : 'active';
2683
- const now = isoNow(input.now);
2684
- const checkpointId = stableHash('mgr-recovery', {
2685
- recoveryClass: plan.recoveryClass,
2686
- lane: plan.lane,
2687
- stepType: plan.stepType,
2688
- allowedAction: plan.allowedAction,
2689
- blockerFingerprint,
2690
- evidenceHash
2691
- });
2692
- return {
2693
- checkpointId,
2694
- recoveryClass: plan.recoveryClass,
2695
- status,
2696
- lane: plan.lane,
2697
- stepType: plan.stepType,
2698
- allowedAction: plan.allowedAction,
2699
- productRepairAllowed: plan.productRepairAllowed,
2700
- expensiveModelAllowed: plan.expensiveModelAllowed,
2701
- attempts,
2702
- maxAttemptsBeforePark: plan.maxAttemptsBeforePark,
2703
- blockerFingerprint,
2704
- evidenceHash,
2705
- changedFiles,
2706
- artifactPaths,
2707
- requiredEvidence: cleanList(plan.requiredEvidence, 40, 500),
2708
- loopResetEvidence: cleanList(plan.loopResetEvidence, 40, 500),
2709
- forbiddenActions: cleanList(plan.forbiddenActions, 40, 500),
2710
- objective: cleanText(plan.objective, 1000),
2711
- nextActionLabel: cleanText(plan.nextActionLabel, 160),
2712
- createdAt: sameCheckpointBase && previous?.createdAt ? previous.createdAt : now,
2713
- updatedAt: now
2714
- };
2715
- }
2716
-
2717
- function makeRecoveryEvidenceProbeStep(
2718
- id: string,
2719
- kind: ResolveIOAIManagerRecoveryEvidenceProbeStepKind,
2720
- label: string,
2721
- objective: string,
2722
- artifactExpectation: string,
2723
- successSignal: string,
2724
- options: Partial<Pick<ResolveIOAIManagerRecoveryEvidenceProbeStep, 'required' | 'commandHint'>> = {}
2725
- ): ResolveIOAIManagerRecoveryEvidenceProbeStep {
2726
- return {
2727
- id,
2728
- kind,
2729
- label,
2730
- objective: cleanText(objective, 1000),
2731
- required: options.required !== false,
2732
- ...(options.commandHint ? { commandHint: cleanText(options.commandHint, 500) } : {}),
2733
- artifactExpectation: cleanText(artifactExpectation, 500),
2734
- successSignal: cleanText(successSignal, 500)
2735
- };
2736
- }
2737
-
2738
- function recoveryEvidenceProbeStepsFor(
2739
- checkpoint: ResolveIOAIManagerRecoveryCheckpoint
2740
- ): ResolveIOAIManagerRecoveryEvidenceProbeStep[] {
2741
- const base = [
2742
- makeRecoveryEvidenceProbeStep(
2743
- 'snapshot_current_blocker',
2744
- 'rerun_same_gate',
2745
- 'Snapshot Current Blocker',
2746
- 'Capture the current blocker, failure class, evidence hash, changed files, and artifact paths before any new repair.',
2747
- 'runner-evidence/current-blocker.json',
2748
- 'Snapshot includes the same checkpointId, blockerFingerprint, and evidenceHashBefore.'
2749
- )
2750
- ];
2751
- if (checkpoint.recoveryClass === 'diagnosis_only' || checkpoint.recoveryClass === 'diagnosis_revision') {
2752
- return [
2753
- ...base,
2754
- makeRecoveryEvidenceProbeStep(
2755
- 'collect_read_only_root_cause_evidence',
2756
- 'read_only_diagnosis',
2757
- 'Collect Read-Only Root-Cause Evidence',
2758
- checkpoint.recoveryClass === 'diagnosis_revision'
2759
- ? 'Collect new evidence that proves the current owner_files or failing_path is wrong before broadening scope.'
2760
- : 'Reproduce or classify the issue and record the exact customer complaint, expected result, observed result, route/module, and account context.',
2761
- 'runner-evidence/diagnosis-readonly.md',
2762
- 'Evidence supports one falsifiable accepted hypothesis and at least one rejected alternative.'
2763
- ),
2764
- makeRecoveryEvidenceProbeStep(
2765
- 'validate_diagnosis_gate',
2766
- 'read_only_diagnosis',
2767
- 'Validate Diagnosis Gate',
2768
- 'Validate issue_case, accepted_hypothesis, rejected_alternatives, failing_path, owner_files, and before/action/after proof_plan.',
2769
- 'runner-evidence/diagnosis-gate.json',
2770
- 'Diagnosis gate validates before product-code repair is allowed.'
2771
- )
2772
- ];
2773
- }
2774
- if (checkpoint.recoveryClass === 'infra_repair') {
2775
- return [
2776
- ...base,
2777
- makeRecoveryEvidenceProbeStep(
2778
- 'run_infra_preflight',
2779
- 'infra_preflight',
2780
- 'Run Infra Preflight',
2781
- 'Check Puppeteer/Chrome, ports, Mongo/settings, cache state, startup commands, and server/client process health.',
2782
- 'runner-evidence/infra-preflight.log',
2783
- 'The same infra gate either passes or returns a new infra blocker hash.',
2784
- { commandHint: 'runner preflight: puppeteer/chrome/mongo/ports/startup' }
2785
- )
2786
- ];
2787
- }
2788
- if (checkpoint.recoveryClass === 'compile_repair') {
2789
- return [
2790
- ...base,
2791
- makeRecoveryEvidenceProbeStep(
2792
- 'rerun_compile_gate',
2793
- 'compile_check',
2794
- 'Rerun Compile Gate',
2795
- 'Rerun the same deterministic compile/build command and capture the first actionable error.',
2796
- 'runner-evidence/compile.log',
2797
- 'Compile passes or the first failing error changes.',
2798
- { commandHint: 'same finite build/compile command from the failed gate' }
2799
- )
2800
- ];
2801
- }
2802
- if (checkpoint.recoveryClass === 'journey_contract_repair') {
2803
- return [
2804
- ...base,
2805
- makeRecoveryEvidenceProbeStep(
2806
- 'validate_journey_contract',
2807
- 'journey_validation',
2808
- 'Validate Journey Contract',
2809
- 'Validate docs/APP_JOURNEY_CONTRACT.md has first/next/last workflow, route/action/method mapping, seeded data story, completion states, and QA assertions.',
2810
- 'runner-evidence/journey-contract-validation.json',
2811
- 'Journey contract validates before build tasks continue.'
2812
- ),
2813
- makeRecoveryEvidenceProbeStep(
2814
- 'verify_hub_workflow_mapping',
2815
- 'journey_validation',
2816
- 'Verify Hub Workflow Mapping',
2817
- 'Confirm the hub CTA and screen sequence implement the journey contract instead of link-only navigation.',
2818
- 'runner-evidence/hub-workflow-map.json',
2819
- 'Primary hub action maps to a real route/action/method/calculation and next state.'
2820
- )
2821
- ];
2822
- }
2823
- if (checkpoint.recoveryClass === 'business_proof_repair' || checkpoint.recoveryClass === 'product_code_repair') {
2824
- return [
2825
- ...base,
2826
- makeRecoveryEvidenceProbeStep(
2827
- 'rerun_business_assertion',
2828
- 'business_assertion',
2829
- 'Rerun Business Assertion',
2830
- 'Run the exact issue/app promise proof and capture before/action/after DOM/data evidence.',
2831
- 'runner-evidence/business-assertion.json',
2832
- 'Business assertion passes, or the observed failure changes with a new artifact path.'
2833
- ),
2834
- makeRecoveryEvidenceProbeStep(
2835
- 'check_diff_scope',
2836
- 'diff_scope_check',
2837
- 'Check Diff Scope',
2838
- 'Compare changed files against the current diagnosis/journey owner scope before another code repair.',
2839
- 'runner-evidence/diff-scope.json',
2840
- 'Changed files are in scope, or diagnosis/journey scope is revised with evidence.'
2841
- )
2842
- ];
2843
- }
2844
- if (checkpoint.recoveryClass === 'release_repair') {
2845
- return [
2846
- ...base,
2847
- makeRecoveryEvidenceProbeStep(
2848
- 'collect_release_status',
2849
- 'release_status',
2850
- 'Collect Release Status',
2851
- 'Collect publish/deploy/build-instance/domain/CloudFront status and the last actionable deploy error.',
2852
- 'runner-evidence/release-status.json',
2853
- 'Release gate passes or returns a new release blocker hash without product-code repair.'
2854
- )
2855
- ];
2856
- }
2857
- if (checkpoint.recoveryClass === 'manual_handoff') {
2858
- return [
2859
- ...base,
2860
- makeRecoveryEvidenceProbeStep(
2861
- 'operator_review_checkpoint',
2862
- 'operator_review',
2863
- 'Operator Review Checkpoint',
2864
- 'Expose budget, blocker, evidence hash, and the minimum policy/scope change needed before another expensive loop.',
2865
- 'runner-evidence/operator-review.json',
2866
- 'Operator approves a new scope/policy or provides new external evidence.'
2867
- )
2868
- ];
2869
- }
2870
- return [
2871
- ...base,
2872
- makeRecoveryEvidenceProbeStep(
2873
- 'rerun_same_deterministic_gate',
2874
- 'rerun_same_gate',
2875
- 'Rerun Same Deterministic Gate',
2876
- 'Rerun the exact failed check and capture new logs/artifacts without changing product code first.',
2877
- 'runner-evidence/retry-gate.log',
2878
- 'Gate passes, or evidenceHash/blockerFingerprint/artifactPaths change.'
2879
- )
2880
- ];
2881
- }
2882
-
2883
- export function buildResolveIOAIManagerRecoveryEvidenceProbe(
2884
- input: ResolveIOAIManagerRecoveryEvidenceProbeInput
2885
- ): ResolveIOAIManagerRecoveryEvidenceProbe {
2886
- const checkpoint = input.checkpoint;
2887
- const now = isoNow(input.now);
2888
- const steps = recoveryEvidenceProbeStepsFor(checkpoint);
2889
- const requiredArtifacts = Array.from(new Set(steps
2890
- .filter((step) => step.required)
2891
- .map((step) => step.artifactExpectation)
2892
- .filter(Boolean)));
2893
- return {
2894
- probeId: stableHash('mgr-probe', {
2895
- checkpointId: checkpoint.checkpointId,
2896
- recoveryClass: checkpoint.recoveryClass,
2897
- evidenceHash: checkpoint.evidenceHash,
2898
- blockerFingerprint: checkpoint.blockerFingerprint
2899
- }),
2900
- checkpointId: checkpoint.checkpointId,
2901
- recoveryClass: checkpoint.recoveryClass,
2902
- lane: checkpoint.lane,
2903
- stepType: checkpoint.stepType,
2904
- objective: checkpoint.status === 'parked'
2905
- ? 'Collect new evidence before any additional expensive model/code repair.'
2906
- : cleanText(checkpoint.objective, 1000),
2907
- evidenceOnly: checkpoint.status === 'parked'
2908
- || checkpoint.recoveryClass === 'diagnosis_only'
2909
- || checkpoint.recoveryClass === 'diagnosis_revision'
2910
- || checkpoint.recoveryClass === 'infra_repair'
2911
- || checkpoint.recoveryClass === 'compile_repair'
2912
- || checkpoint.recoveryClass === 'release_repair',
2913
- productRepairAllowed: checkpoint.productRepairAllowed && checkpoint.status !== 'parked',
2914
- expensiveModelAllowed: checkpoint.expensiveModelAllowed && checkpoint.status !== 'parked',
2915
- evidenceHashBefore: checkpoint.evidenceHash,
2916
- blockerFingerprint: checkpoint.blockerFingerprint,
2917
- steps,
2918
- requiredArtifacts,
2919
- acceptanceEvidence: Array.from(new Set([
2920
- ...checkpoint.requiredEvidence,
2921
- ...checkpoint.loopResetEvidence,
2922
- ...steps.map((step) => step.successSignal)
2923
- ].map((entry) => cleanText(entry, 500)).filter(Boolean))).slice(0, 30),
2924
- stopConditions: Array.from(new Set([
2925
- ...checkpoint.forbiddenActions,
2926
- 'no new evidence hash',
2927
- 'no new artifact path',
2928
- 'product-code repair requested while evidenceOnly is true'
2929
- ].map((entry) => cleanText(entry, 500)).filter(Boolean))).slice(0, 30),
2930
- loopResetEvidence: checkpoint.loopResetEvidence,
2931
- createdAt: now
2932
- };
2933
- }
2934
-
2935
- function recoveryAutomationModeFor(
2936
- checkpoint: ResolveIOAIManagerRecoveryCheckpoint
2937
- ): ResolveIOAIManagerRecoveryAutomationMode {
2938
- if (checkpoint.status === 'manual_handoff' || checkpoint.recoveryClass === 'manual_handoff') {
2939
- return 'manual_review';
2940
- }
2941
- if (checkpoint.status === 'complete' || checkpoint.recoveryClass === 'advance_after_proof') {
2942
- return 'advance';
2943
- }
2944
- if (checkpoint.status === 'parked' || checkpoint.recoveryClass === 'blocked_until_new_evidence') {
2945
- return 'collect_evidence';
2946
- }
2947
- if (checkpoint.recoveryClass === 'diagnosis_only' || checkpoint.recoveryClass === 'diagnosis_revision') {
2948
- return 'read_only_diagnosis';
2949
- }
2950
- if (checkpoint.recoveryClass === 'infra_repair') {
2951
- return 'repair_infra';
2952
- }
2953
- if (checkpoint.recoveryClass === 'compile_repair') {
2954
- return 'repair_compile';
2955
- }
2956
- if (checkpoint.recoveryClass === 'journey_contract_repair') {
2957
- return 'repair_journey_contract';
2958
- }
2959
- if (checkpoint.recoveryClass === 'business_proof_repair') {
2960
- return 'repair_business_assertion';
2961
- }
2962
- if (checkpoint.recoveryClass === 'release_repair') {
2963
- return 'repair_release';
2964
- }
2965
- if (checkpoint.recoveryClass === 'product_code_repair') {
2966
- return 'targeted_product_repair';
2967
- }
2968
- return 'continue_gate';
2969
- }
2970
-
2971
- function recoveryActionLabelFor(mode: ResolveIOAIManagerRecoveryAutomationMode, checkpoint: ResolveIOAIManagerRecoveryCheckpoint): string {
2972
- const explicit = cleanText(checkpoint.nextActionLabel, 120);
2973
- if (explicit && mode !== 'collect_evidence') {
2974
- return explicit;
2975
- }
2976
- const labels: Record<ResolveIOAIManagerRecoveryAutomationMode, string> = {
2977
- advance: 'Advance To Next Gate',
2978
- collect_evidence: 'Collect New Evidence',
2979
- read_only_diagnosis: 'Run Diagnosis Evidence Pass',
2980
- repair_infra: 'Repair Infra Gate',
2981
- repair_compile: 'Repair Compile Gate',
2982
- repair_journey_contract: 'Repair Journey Contract',
2983
- repair_business_assertion: 'Repair Business Proof',
2984
- repair_release: 'Repair Release Gate',
2985
- targeted_product_repair: 'Run Targeted Repair',
2986
- manual_review: 'Manual Review',
2987
- continue_gate: 'Continue Current Gate'
2988
- };
2989
- return labels[mode];
2990
- }
2991
-
2992
- function recoveryActionAutoRunnable(
2993
- mode: ResolveIOAIManagerRecoveryAutomationMode,
2994
- probe: ResolveIOAIManagerRecoveryEvidenceProbe
2995
- ): boolean {
2996
- if (mode === 'manual_review') {
2997
- return false;
2998
- }
2999
- if (mode === 'advance' || mode === 'continue_gate') {
3000
- return true;
3001
- }
3002
- if (mode === 'targeted_product_repair' || mode === 'read_only_diagnosis' || mode === 'repair_journey_contract' || mode === 'repair_business_assertion') {
3003
- return true;
3004
- }
3005
- return probe.steps.some((step) => step.commandHint || step.kind === 'rerun_same_gate' || step.kind === 'release_status' || step.kind === 'diff_scope_check');
3006
- }
3007
-
3008
- function recoveryActionCostCeilingUsd(mode: ResolveIOAIManagerRecoveryAutomationMode): number {
3009
- const map: Record<ResolveIOAIManagerRecoveryAutomationMode, number> = {
3010
- advance: 0,
3011
- collect_evidence: 0.25,
3012
- read_only_diagnosis: 1,
3013
- repair_infra: 0.5,
3014
- repair_compile: 1.5,
3015
- repair_journey_contract: 2,
3016
- repair_business_assertion: 1.5,
3017
- repair_release: 0.75,
3018
- targeted_product_repair: 5,
3019
- manual_review: 0,
3020
- continue_gate: 0
3021
- };
3022
- return map[mode] ?? 1;
3023
- }
3024
-
3025
- function recoveryActionRequiredStateTransition(mode: ResolveIOAIManagerRecoveryAutomationMode): string {
3026
- const map: Record<ResolveIOAIManagerRecoveryAutomationMode, string> = {
3027
- advance: 'current gate advances without repair after existing proof is accepted',
3028
- collect_evidence: 'blockerFingerprint or evidenceHash changes with material proof, or run remains parked',
3029
- read_only_diagnosis: 'diagnosis gate becomes valid or records a blocked-reproduction reason',
3030
- repair_infra: 'infra preflight changes from failed/blocked to passed, or records a new infra blocker',
3031
- repair_compile: 'compile/startup status changes from failed to passed, or records a new compile blocker',
3032
- repair_journey_contract: 'journey contract validates with first/next/last workflow proof',
3033
- repair_business_assertion: 'business assertion changes from missing/failed to passed with artifact proof',
3034
- repair_release: 'hotfix/release gate changes from blocked to passed, rerun_release_gate, or parked manual',
3035
- targeted_product_repair: 'owner-scoped diff is produced and deterministic proof advances to QA',
3036
- manual_review: 'operator records one explicit decision',
3037
- continue_gate: 'current gate records accepted proof and advances'
3038
- };
3039
- return map[mode] || 'runner records a validated state transition before continuing';
3040
- }
3041
-
3042
- function recoveryActionProofRequiredBeforeContinuation(mode: ResolveIOAIManagerRecoveryAutomationMode): boolean {
3043
- return mode !== 'advance' && mode !== 'continue_gate' && mode !== 'manual_review';
3044
- }
3045
-
3046
- function recoveryActionExitCriteria(input: {
3047
- mode: ResolveIOAIManagerRecoveryAutomationMode;
3048
- dispatchAction: ResolveIOAIManagerRecoveryActionDispatchAction;
3049
- requiredStateTransition: string;
3050
- stopWhen: string[];
3051
- }): string[] {
3052
- return Array.from(new Set([
3053
- `exact dispatch action ${input.dispatchAction} completed or was parked`,
3054
- input.requiredStateTransition,
3055
- ...(recoveryActionProofRequiredBeforeContinuation(input.mode) ? ['do not continue runner until required proof artifact is attached'] : []),
3056
- ...input.stopWhen
3057
- ].map((entry) => cleanText(entry, 500)).filter(Boolean))).slice(0, 30);
3058
- }
3059
-
3060
- function recoveryReleaseHotfixCommands(policy: ResolveIOAIManagerHotfixFirstReleasePolicy | undefined): string[] {
3061
- if (!policy) {
3062
- return [];
3063
- }
3064
- return Array.from(new Set([
3065
- ...policy.allowedActions,
3066
- ...(policy.hotfixPreferred ? [
3067
- 'prepare_hotfix_patch_without_live_apply',
3068
- 'commit_and_push_hotfix_to_github',
3069
- 'record_github_commit_for_hotfix',
3070
- 'apply_live_hotfix_only_after_github_commit_proof'
3071
- ] : []),
3072
- 'run_failed_release_gate_once',
3073
- 'record_release_evidence'
3074
- ].map((entry) => cleanText(entry, 500)).filter(Boolean))).slice(0, 20);
3075
- }
3076
-
3077
- function recoveryReleaseRequiredEvidence(policy: ResolveIOAIManagerHotfixFirstReleasePolicy | undefined): string[] {
3078
- if (!policy) {
3079
- return [];
3080
- }
3081
- const stepEvidence = (policy.hotfixPlan?.steps || []).flatMap((step) => step.requiredEvidence || []);
3082
- return Array.from(new Set([
3083
- ...policy.requiredEvidence,
3084
- ...stepEvidence,
3085
- ...(policy.hotfixPreferred ? [
3086
- 'full 40-character sourceCommitSha',
3087
- 'matching githubCommitUrl',
3088
- 'passed gitCommitStatus before any live hotfix is treated as durable',
3089
- 'passed gitPushStatus before any live hotfix is treated as durable'
3090
- ] : [])
3091
- ].map((entry) => cleanText(entry, 500)).filter(Boolean))).slice(0, 30);
3092
- }
3093
-
3094
- function recoveryReleaseSuccessEvidence(policy: ResolveIOAIManagerHotfixFirstReleasePolicy | undefined): string[] {
3095
- if (!policy) {
3096
- return [];
3097
- }
3098
- const stepEvidence = (policy.hotfixPlan?.steps || []).flatMap((step) => step.successEvidence || []);
3099
- return Array.from(new Set([
3100
- ...(policy.hotfixPlan?.acceptanceEvidence || []),
3101
- ...stepEvidence,
3102
- ...(policy.hotfixPreferred ? ['GitHub commit and push proof validates before continuation'] : [])
3103
- ].map((entry) => cleanText(entry, 500)).filter(Boolean))).slice(0, 30);
3104
- }
3105
-
3106
- export function buildResolveIOAIManagerRecoveryActionPacket(
3107
- input: ResolveIOAIManagerRecoveryActionPacketInput
3108
- ): ResolveIOAIManagerRecoveryActionPacket {
3109
- const checkpoint = input.checkpoint;
3110
- const probe = input.probe || buildResolveIOAIManagerRecoveryEvidenceProbe({
3111
- checkpoint,
3112
- current: input.current,
3113
- now: input.now
3114
- });
3115
- const mode = recoveryAutomationModeFor(checkpoint);
3116
- const primaryStep = probe.steps.find((step) => step.required && step.id !== 'snapshot_current_blocker')
3117
- || probe.steps.find((step) => step.required)
3118
- || probe.steps[0];
3119
- const evidenceOnly = probe.evidenceOnly || mode === 'collect_evidence' || mode === 'repair_infra' || mode === 'repair_compile' || mode === 'repair_release';
3120
- const requireNewEvidence = mode === 'collect_evidence'
3121
- || checkpoint.status === 'parked'
3122
- || checkpoint.attempts >= checkpoint.maxAttemptsBeforePark;
3123
- const stopWhen = Array.from(new Set([
3124
- ...probe.stopConditions,
3125
- ...(requireNewEvidence ? ['same blocker fingerprint and same evidence hash after probe'] : [])
3126
- ].map((entry) => cleanText(entry, 500)).filter(Boolean))).slice(0, 30);
3127
- const resetLoopWhen = Array.from(new Set([
3128
- ...checkpoint.loopResetEvidence,
3129
- ...probe.loopResetEvidence,
3130
- ...(requireNewEvidence ? [
3131
- 'new material evidence: changed blocker, validated diagnosis/journey, business proof, compile/infra/release proof, or new actionable trace',
3132
- 'weak hash-only evidence does not reset the loop'
3133
- ] : [])
3134
- ].map((entry) => cleanText(entry, 500)).filter(Boolean))).slice(0, 30);
3135
- const nextCommands = probe.steps
3136
- .map((step) => cleanText(step.commandHint || `${step.kind}:${step.id}`, 500))
3137
- .filter(Boolean)
3138
- .slice(0, 12);
3139
- const releasePolicy = mode === 'repair_release'
3140
- ? buildResolveIOAIManagerHotfixFirstReleasePolicy({
3141
- surface: 'manager_recovery',
3142
- deployStatus: checkpoint.stepType,
3143
- publishStatus: checkpoint.lane
3144
- })
3145
- : undefined;
3146
- const releaseNextCommands = recoveryReleaseHotfixCommands(releasePolicy);
3147
- const releaseRequiredEvidence = recoveryReleaseRequiredEvidence(releasePolicy);
3148
- const releaseSuccessEvidence = recoveryReleaseSuccessEvidence(releasePolicy);
3149
- const allowedDispatchAction = dispatchActionForMode(mode);
3150
- const requiredStateTransition = recoveryActionRequiredStateTransition(mode);
3151
- const proofRequiredBeforeContinuation = recoveryActionProofRequiredBeforeContinuation(mode);
3152
- const exitCriteria = recoveryActionExitCriteria({
3153
- mode,
3154
- dispatchAction: allowedDispatchAction,
3155
- requiredStateTransition,
3156
- stopWhen
3157
- });
3158
- const now = isoNow(input.now);
3159
- return {
3160
- actionId: stableHash('mgr-action', {
3161
- checkpointId: checkpoint.checkpointId,
3162
- probeId: probe.probeId,
3163
- mode,
3164
- evidenceHash: checkpoint.evidenceHash,
3165
- blockerFingerprint: checkpoint.blockerFingerprint
3166
- }),
3167
- checkpointId: checkpoint.checkpointId,
3168
- probeId: probe.probeId,
3169
- recoveryClass: checkpoint.recoveryClass,
3170
- mode,
3171
- singleActionOnly: true,
3172
- allowedDispatchAction,
3173
- label: recoveryActionLabelFor(mode, checkpoint),
3174
- lane: checkpoint.lane,
3175
- stepType: checkpoint.stepType,
3176
- primaryStepKind: primaryStep?.kind || 'none',
3177
- objective: mode === 'collect_evidence'
3178
- ? probe.objective
3179
- : cleanText(checkpoint.objective || probe.objective, 1000),
3180
- evidenceOnly,
3181
- autoRunnable: recoveryActionAutoRunnable(mode, probe),
3182
- productRepairAllowed: checkpoint.productRepairAllowed && !evidenceOnly && checkpoint.status !== 'parked',
3183
- expensiveModelAllowed: checkpoint.expensiveModelAllowed && checkpoint.status !== 'parked',
3184
- costCeilingUsd: recoveryActionCostCeilingUsd(mode),
3185
- requiredStateTransition,
3186
- proofRequiredBeforeContinuation,
3187
- canResetLoopAfterEvidence: resetLoopWhen.length > 0,
3188
- maxAttemptsBeforePark: checkpoint.maxAttemptsBeforePark,
3189
- requiredArtifacts: releasePolicy
3190
- ? Array.from(new Set([...probe.requiredArtifacts, ...releaseRequiredEvidence])).slice(0, 20)
3191
- : probe.requiredArtifacts.slice(0, 20),
3192
- nextCommands: releasePolicy
3193
- ? Array.from(new Set([...nextCommands, ...releaseNextCommands])).slice(0, 20)
3194
- : nextCommands,
3195
- successCriteria: releasePolicy
3196
- ? Array.from(new Set([...probe.acceptanceEvidence, ...releaseSuccessEvidence])).slice(0, 20)
3197
- : probe.acceptanceEvidence.slice(0, 20),
3198
- exitCriteria,
3199
- retryPolicy: {
3200
- allowImmediateRetry: checkpoint.status !== 'parked' && mode !== 'manual_review',
3201
- requireNewEvidence,
3202
- resetLoopWhen,
3203
- stopWhen
3204
- },
3205
- ...(releasePolicy ? { releasePolicy } : {}),
3206
- ...(mode === 'collect_evidence' ? { blockedReason: 'Manager parked this loop until the recovery action records new evidence.' } : {}),
3207
- createdAt: now
3208
- };
3209
- }
3210
-
3211
- function dispatchActionForMode(mode: ResolveIOAIManagerRecoveryAutomationMode): ResolveIOAIManagerRecoveryActionDispatchAction {
3212
- const map: Record<ResolveIOAIManagerRecoveryAutomationMode, ResolveIOAIManagerRecoveryActionDispatchAction> = {
3213
- advance: 'advance',
3214
- collect_evidence: 'run_evidence_probe',
3215
- read_only_diagnosis: 'run_read_only_diagnosis',
3216
- repair_infra: 'run_infra_repair',
3217
- repair_compile: 'run_compile_repair',
3218
- repair_journey_contract: 'run_journey_contract_repair',
3219
- repair_business_assertion: 'run_business_assertion_repair',
3220
- repair_release: 'run_release_repair',
3221
- targeted_product_repair: 'run_targeted_product_repair',
3222
- manual_review: 'park_manual',
3223
- continue_gate: 'continue_gate'
3224
- };
3225
- return map[mode] || 'park_manual';
3226
- }
3227
-
3228
- function buildRecoveryDispatchRecord(
3229
- action: ResolveIOAIManagerRecoveryActionPacket,
3230
- dispatchAction: ResolveIOAIManagerRecoveryActionDispatchAction,
3231
- status: ResolveIOAIManagerRecoveryActionDispatchStatus,
3232
- reason: string,
3233
- current?: ResolveIOAIManagerFailureRecord,
3234
- now?: Date | string
3235
- ): ResolveIOAIManagerRecoveryActionDispatchRecord {
3236
- const evidenceHash = current?.evidenceHash || action.checkpointId || action.actionId;
3237
- const blockerFingerprint = resolveResolveIOAIManagerBlockerFingerprint(current, action.objective);
3238
- const artifactPaths = cleanList(current?.artifactPaths, 20, 500);
3239
- const createdAt = isoNow(now);
3240
- return {
3241
- dispatchId: stableHash('mgr-dispatch', {
3242
- actionId: action.actionId,
3243
- dispatchAction,
3244
- evidenceHash,
3245
- blockerFingerprint,
3246
- status
3247
- }),
3248
- actionId: action.actionId,
3249
- checkpointId: action.checkpointId,
3250
- probeId: action.probeId,
3251
- mode: action.mode,
3252
- dispatchAction,
3253
- status,
3254
- evidenceHash,
3255
- blockerFingerprint,
3256
- productRepairAllowed: action.productRepairAllowed && dispatchAction === 'run_targeted_product_repair',
3257
- expensiveModelAllowed: action.expensiveModelAllowed && dispatchAction !== 'run_evidence_probe',
3258
- reason,
3259
- artifactPaths,
3260
- ...(status === 'started' ? { startedAt: createdAt } : {}),
3261
- ...(status === 'completed' ? { completedAt: createdAt } : {}),
3262
- createdAt
3263
- };
3264
- }
3265
-
3266
- export function decideResolveIOAIManagerRecoveryActionDispatch(
3267
- input: ResolveIOAIManagerRecoveryActionDispatchInput
3268
- ): ResolveIOAIManagerRecoveryActionDispatchDecision {
3269
- const action = input.action;
3270
- const history = Array.isArray(input.history) ? input.history.filter(Boolean).slice(-50) : [];
3271
- const current = input.current || {};
3272
- if (!action) {
3273
- return {
3274
- dispatchAction: 'park_manual',
3275
- allowed: false,
3276
- reason: 'recovery_dispatch_missing_action',
3277
- status: 'parked',
3278
- canRunProductRepair: false,
3279
- canRunExpensiveModel: false,
3280
- shouldRecordDispatch: false,
3281
- requiresNewEvidence: true,
3282
- newEvidence: false
3283
- };
3284
- }
3285
- const dispatchAction = dispatchActionForMode(action.mode);
3286
- const allowedDispatchAction = action.allowedDispatchAction || dispatchAction;
3287
- const evidenceHash = current.evidenceHash || action.checkpointId || action.actionId;
3288
- const blockerFingerprint = resolveResolveIOAIManagerBlockerFingerprint(current, action.objective);
3289
- const sameActionHistory = history.filter((entry) => entry.actionId === action.actionId);
3290
- const sameEvidenceHistory = sameActionHistory.filter((entry) => entry.evidenceHash === evidenceHash
3291
- && entry.blockerFingerprint === blockerFingerprint);
3292
- const activeDispatch = sameEvidenceHistory.find((entry) => entry.status === 'queued' || entry.status === 'started');
3293
- const completedDispatch = sameEvidenceHistory.find((entry) => entry.status === 'completed' || entry.status === 'failed');
3294
- const newEvidence = sameActionHistory.length > 0 && sameEvidenceHistory.length === 0;
3295
- const requiresNewEvidence = action.retryPolicy.requireNewEvidence === true;
3296
- const sameEvidenceAlreadyAttempted = !!completedDispatch && requiresNewEvidence && !newEvidence;
3297
- const manualOnly = action.mode === 'manual_review' || !action.autoRunnable;
3298
- const productDispatch = dispatchAction === 'run_targeted_product_repair';
3299
- const expensiveDispatch = !['run_evidence_probe', 'advance', 'continue_gate', 'park_manual'].includes(dispatchAction);
3300
- const evidenceAssessment = assessResolveIOAIManagerEvidenceChange(undefined, current, action.objective);
3301
- const autonomyPolicy = input.autonomyPolicy
3302
- ? decideResolveIOAIManagerAutonomyPolicy({
3303
- ...(input.autonomyPolicy || {}),
3304
- dispatchAction,
3305
- projectedActionCostUsd: input.autonomyPolicy?.projectedActionCostUsd ?? action.costCeilingUsd,
3306
- newEvidence: input.autonomyPolicy?.newEvidence ?? newEvidence,
3307
- materialEvidence: input.autonomyPolicy?.materialEvidence ?? evidenceAssessment.material,
3308
- evidenceStrength: input.autonomyPolicy?.evidenceStrength ?? evidenceAssessment.strength,
3309
- evidenceSignals: input.autonomyPolicy?.evidenceSignals ?? evidenceAssessment.signals,
3310
- sameEvidenceAlreadyAttempted: input.autonomyPolicy?.sameEvidenceAlreadyAttempted ?? sameEvidenceAlreadyAttempted,
3311
- operatorApproved: input.operatorApproved
3312
- })
3313
- : undefined;
3314
- const autonomyBlocksDispatch = !!autonomyPolicy && (
3315
- autonomyPolicy.mode === 'monitor_only'
3316
- || (autonomyPolicy.requiresHumanApproval === true && input.operatorApproved !== true)
3317
- || (autonomyPolicy.canAutoDispatch !== true && input.operatorApproved !== true)
3318
- || (autonomyPolicy.blocked === true && autonomyPolicy.canManualDispatch !== true)
3319
- );
3320
- if (autonomyBlocksDispatch) {
3321
- const record = buildRecoveryDispatchRecord(action, 'park_manual', 'parked', `recovery_dispatch_blocked_by_autonomy_policy:${autonomyPolicy?.reason || 'unknown'}`, current, input.now);
3322
- return {
3323
- dispatchAction: 'park_manual',
3324
- allowed: false,
3325
- reason: record.reason,
3326
- status: 'parked',
3327
- canRunProductRepair: false,
3328
- canRunExpensiveModel: false,
3329
- shouldRecordDispatch: true,
3330
- requiresNewEvidence,
3331
- newEvidence,
3332
- autonomyPolicy,
3333
- dispatchRecord: record
3334
- };
3335
- }
3336
- if (action.singleActionOnly === true && allowedDispatchAction !== dispatchAction) {
3337
- const record = buildRecoveryDispatchRecord(action, 'park_manual', 'parked', 'recovery_dispatch_action_not_in_packet_contract', current, input.now);
3338
- return {
3339
- dispatchAction: 'park_manual',
3340
- allowed: false,
3341
- reason: record.reason,
3342
- status: 'parked',
3343
- canRunProductRepair: false,
3344
- canRunExpensiveModel: false,
3345
- shouldRecordDispatch: true,
3346
- requiresNewEvidence: true,
3347
- newEvidence,
3348
- autonomyPolicy,
3349
- dispatchRecord: record
3350
- };
3351
- }
3352
- if (manualOnly && input.operatorApproved !== true) {
3353
- const record = buildRecoveryDispatchRecord(action, 'park_manual', 'parked', 'recovery_dispatch_requires_manual_review', current, input.now);
3354
- return {
3355
- dispatchAction: 'park_manual',
3356
- allowed: false,
3357
- reason: record.reason,
3358
- status: 'parked',
3359
- canRunProductRepair: false,
3360
- canRunExpensiveModel: false,
3361
- shouldRecordDispatch: true,
3362
- requiresNewEvidence,
3363
- newEvidence,
3364
- autonomyPolicy,
3365
- dispatchRecord: record
3366
- };
3367
- }
3368
- if (productDispatch && action.productRepairAllowed !== true) {
3369
- const record = buildRecoveryDispatchRecord(action, 'park_manual', 'parked', 'recovery_dispatch_product_repair_not_allowed', current, input.now);
3370
- return {
3371
- dispatchAction: 'park_manual',
3372
- allowed: false,
3373
- reason: record.reason,
3374
- status: 'parked',
3375
- canRunProductRepair: false,
3376
- canRunExpensiveModel: false,
3377
- shouldRecordDispatch: true,
3378
- requiresNewEvidence: true,
3379
- newEvidence,
3380
- autonomyPolicy,
3381
- dispatchRecord: record
3382
- };
3383
- }
3384
- if (activeDispatch) {
3385
- return {
3386
- dispatchAction: 'park_manual',
3387
- allowed: false,
3388
- reason: 'recovery_dispatch_already_running_for_same_evidence',
3389
- status: 'parked',
3390
- canRunProductRepair: false,
3391
- canRunExpensiveModel: false,
3392
- shouldRecordDispatch: false,
3393
- requiresNewEvidence: true,
3394
- newEvidence: false,
3395
- autonomyPolicy
3396
- };
3397
- }
3398
- if (sameEvidenceAlreadyAttempted) {
3399
- const record = buildRecoveryDispatchRecord(action, 'park_manual', 'parked', 'recovery_dispatch_same_evidence_already_attempted', current, input.now);
3400
- return {
3401
- dispatchAction: 'park_manual',
3402
- allowed: false,
3403
- reason: record.reason,
3404
- status: 'parked',
3405
- canRunProductRepair: false,
3406
- canRunExpensiveModel: false,
3407
- shouldRecordDispatch: true,
3408
- requiresNewEvidence: true,
3409
- newEvidence: false,
3410
- autonomyPolicy,
3411
- dispatchRecord: record
3412
- };
3413
- }
3414
- const status: ResolveIOAIManagerRecoveryActionDispatchStatus = dispatchAction === 'advance' || dispatchAction === 'continue_gate'
3415
- ? 'completed'
3416
- : 'started';
3417
- const record = buildRecoveryDispatchRecord(action, dispatchAction, status, 'recovery_dispatch_allowed', current, input.now);
3418
- return {
3419
- dispatchAction,
3420
- allowed: true,
3421
- reason: 'recovery_dispatch_allowed',
3422
- status,
3423
- canRunProductRepair: productDispatch && action.productRepairAllowed === true,
3424
- canRunExpensiveModel: expensiveDispatch && action.expensiveModelAllowed === true,
3425
- shouldRecordDispatch: true,
3426
- requiresNewEvidence,
3427
- newEvidence,
3428
- autonomyPolicy,
3429
- dispatchRecord: record
3430
- };
3431
- }
3432
-
3433
- export function appendResolveIOAIManagerRecoveryActionDispatch(
3434
- history: ResolveIOAIManagerRecoveryActionDispatchRecord[] | undefined,
3435
- record: ResolveIOAIManagerRecoveryActionDispatchRecord | undefined,
3436
- limit = 50
3437
- ): ResolveIOAIManagerRecoveryActionDispatchRecord[] {
3438
- const existing = Array.isArray(history) ? history.filter(Boolean) : [];
3439
- if (!record) {
3440
- return existing.slice(-limit);
3441
- }
3442
- const deduped = existing.filter((entry) => entry.dispatchId !== record.dispatchId);
3443
- return [...deduped, record].slice(-limit);
3444
- }
3445
-
3446
- function recoveryExecutionPhaseForDispatch(
3447
- dispatchAction: ResolveIOAIManagerRecoveryActionDispatchAction
3448
- ): ResolveIOAIManagerRecoveryExecutionPhase {
3449
- const map: Record<ResolveIOAIManagerRecoveryActionDispatchAction, ResolveIOAIManagerRecoveryExecutionPhase> = {
3450
- run_evidence_probe: 'evidence',
3451
- run_read_only_diagnosis: 'diagnosis',
3452
- run_infra_repair: 'infra',
3453
- run_compile_repair: 'compile',
3454
- run_journey_contract_repair: 'journey',
3455
- run_business_assertion_repair: 'business_proof',
3456
- run_release_repair: 'release',
3457
- run_targeted_product_repair: 'product_repair',
3458
- advance: 'advance',
3459
- continue_gate: 'advance',
3460
- park_manual: 'manual'
3461
- };
3462
- return map[dispatchAction] || 'manual';
3463
- }
3464
-
3465
- function recoveryDirectiveReason(
3466
- action: ResolveIOAIManagerRecoveryActionPacket | undefined,
3467
- decision: ResolveIOAIManagerRecoveryActionDispatchDecision,
3468
- current?: ResolveIOAIManagerFailureRecord
3469
- ): string {
3470
- const blocker = cleanText(current?.blocker || current?.summary || '', 260);
3471
- const label = cleanText(action?.label, 120) || decision.dispatchAction;
3472
- const objective = cleanText(action?.objective, 260);
3473
- return [
3474
- `MANAGER_RECOVERY:${decision.dispatchAction}`,
3475
- `label=${label}`,
3476
- decision.reason ? `reason=${decision.reason}` : '',
3477
- blocker ? `blocker=${blocker}` : '',
3478
- objective ? `objective=${objective}` : ''
3479
- ].filter(Boolean).join(' | ');
3480
- }
3481
-
3482
- export function buildResolveIOAIManagerRecoveryExecutionDirective(
3483
- input: ResolveIOAIManagerRecoveryExecutionDirectiveInput
3484
- ): ResolveIOAIManagerRecoveryExecutionDirective {
3485
- const action = input.action;
3486
- const dispatchDecision = input.dispatchDecision || decideResolveIOAIManagerRecoveryActionDispatch({
3487
- action,
3488
- current: input.current,
3489
- autonomyPolicy: input.autonomyPolicy,
3490
- now: input.now
3491
- });
3492
- const dispatchAction = dispatchDecision.dispatchAction;
3493
- const now = isoNow(input.now);
3494
- const phase = recoveryExecutionPhaseForDispatch(dispatchAction);
3495
- const lane = cleanText(action?.lane || input.current?.lane || '', 120);
3496
- const stepType = cleanText(action?.stepType || input.current?.stepType || '', 120);
3497
- const rerunReason = recoveryDirectiveReason(action, dispatchDecision, input.current);
3498
- const surface = cleanText(input.surface || 'runner', 120);
3499
- return {
3500
- directiveId: stableHash('mgr-directive', {
3501
- surface,
3502
- actionId: action?.actionId || '',
3503
- dispatchAction,
3504
- reason: dispatchDecision.reason,
3505
- evidenceHash: dispatchDecision.dispatchRecord?.evidenceHash || input.current?.evidenceHash || ''
3506
- }),
3507
- surface,
3508
- dispatchAction,
3509
- phase,
3510
- allowed: dispatchDecision.allowed,
3511
- status: dispatchDecision.status,
3512
- reason: dispatchDecision.reason,
3513
- singleActionOnly: action?.singleActionOnly !== false,
3514
- allowedDispatchAction: action?.allowedDispatchAction || dispatchAction,
3515
- lane,
3516
- stepType,
3517
- nextActionLabel: cleanText(action?.label, 160) || dispatchAction,
3518
- rerunReason,
3519
- evidenceOnly: action?.evidenceOnly !== false || dispatchAction === 'run_evidence_probe',
3520
- autoRunnable: action?.autoRunnable === true,
3521
- productRepairAllowed: action?.productRepairAllowed === true,
3522
- expensiveModelAllowed: action?.expensiveModelAllowed === true,
3523
- costCeilingUsd: Math.max(0, Number(action?.costCeilingUsd || 0) || 0),
3524
- requiredStateTransition: cleanText(action?.requiredStateTransition, 500),
3525
- proofRequiredBeforeContinuation: action?.proofRequiredBeforeContinuation === true,
3526
- canRunProductRepair: dispatchDecision.canRunProductRepair,
3527
- canRunExpensiveModel: dispatchDecision.canRunExpensiveModel,
3528
- canResetLoopAfterEvidence: action?.canResetLoopAfterEvidence === true,
3529
- requiresNewEvidence: dispatchDecision.requiresNewEvidence,
3530
- newEvidence: dispatchDecision.newEvidence,
3531
- ...(dispatchDecision.autonomyPolicy ? { autonomyPolicy: dispatchDecision.autonomyPolicy } : {}),
3532
- maxAttemptsBeforePark: Math.max(1, Number(action?.maxAttemptsBeforePark || 1) || 1),
3533
- requiredArtifacts: cleanList(action?.requiredArtifacts, 20, 500),
3534
- nextCommands: cleanList(action?.nextCommands, 20, 500),
3535
- successCriteria: cleanList(action?.successCriteria, 20, 500),
3536
- exitCriteria: cleanList(action?.exitCriteria, 30, 500),
3537
- forbiddenActions: action?.productRepairAllowed === true
3538
- ? []
3539
- : Array.from(new Set([
3540
- 'Do not run product-code repair from this directive unless canRunProductRepair is true.',
3541
- ...(action?.releasePolicy?.forbiddenActions || [])
3542
- ])).slice(0, 20),
3543
- ...(dispatchDecision.dispatchRecord ? { dispatchRecord: dispatchDecision.dispatchRecord } : {}),
3544
- ...(action?.releasePolicy ? { releasePolicy: action.releasePolicy } : {}),
3545
- createdAt: now
3546
- };
3547
- }
3548
-
3549
- function failureRecordFromDirectiveStart(
3550
- directive: ResolveIOAIManagerRecoveryExecutionDirective | undefined,
3551
- previous?: ResolveIOAIManagerFailureRecord
3552
- ): ResolveIOAIManagerFailureRecord {
3553
- if (previous) {
3554
- return previous;
3555
- }
3556
- const dispatchRecord = directive?.dispatchRecord;
3557
- return {
3558
- lane: directive?.lane,
3559
- stepType: directive?.stepType,
3560
- failureClass: '',
3561
- blockerFingerprint: dispatchRecord?.blockerFingerprint,
3562
- evidenceHash: dispatchRecord?.evidenceHash,
3563
- artifactPaths: dispatchRecord?.artifactPaths || [],
3564
- recordedAt: dispatchRecord?.createdAt || directive?.createdAt
3565
- };
3566
- }
3567
-
3568
- function recoveryExecutionProofStatus(input: {
3569
- directive?: ResolveIOAIManagerRecoveryExecutionDirective;
3570
- hasCurrent: boolean;
3571
- assessment: ResolveIOAIManagerEvidenceAssessment;
3572
- }): ResolveIOAIManagerRecoveryExecutionProofStatus {
3573
- const directive = input.directive;
3574
- if (!directive || directive.allowed !== true || directive.dispatchAction === 'park_manual') {
3575
- return 'manual_handoff';
3576
- }
3577
- if (!input.hasCurrent) {
3578
- return 'waiting_for_execution';
3579
- }
3580
- if (directive.requiresNewEvidence === true && input.assessment.changed !== true) {
3581
- return 'blocked_same_evidence';
3582
- }
3583
- if (directive.proofRequiredBeforeContinuation === true && input.assessment.material !== true) {
3584
- return 'waiting_for_new_evidence';
3585
- }
3586
- return 'proof_ready';
3587
- }
3588
-
3589
- export function buildResolveIOAIManagerRecoveryExecutionProofContract(
3590
- input: ResolveIOAIManagerRecoveryExecutionProofContractInput = {}
3591
- ): ResolveIOAIManagerRecoveryExecutionProofContract {
3592
- const directive = input.directive;
3593
- const previous = failureRecordFromDirectiveStart(directive, input.previous);
3594
- const current = input.current || {};
3595
- const hasCurrent = !!input.current;
3596
- const assessment = hasCurrent
3597
- ? assessResolveIOAIManagerEvidenceChange(previous, current, directive?.requiredStateTransition)
3598
- : {
3599
- changed: false,
3600
- material: false,
3601
- strength: 'none' as ResolveIOAIManagerEvidenceStrength,
3602
- signals: [],
3603
- evidenceHash: hashResolveIOAIManagerEvidence(previous),
3604
- blockerFingerprint: resolveResolveIOAIManagerBlockerFingerprint(previous, directive?.requiredStateTransition)
3605
- };
3606
- const status = recoveryExecutionProofStatus({ directive, hasCurrent, assessment });
3607
- const canContinueRun = status === 'proof_ready';
3608
- const requiredEvidence = Array.from(new Set([
3609
- ...cleanList(input.requiredEvidence, 30, 500),
3610
- ...cleanList(directive?.requiredArtifacts, 30, 500),
3611
- ...cleanList(directive?.successCriteria, 30, 500)
3612
- ].filter(Boolean)));
3613
- const missingEvidence = directive?.proofRequiredBeforeContinuation === true && status !== 'proof_ready'
3614
- ? (requiredEvidence.length ? requiredEvidence : ['new material evidence or passed proof artifact'])
3615
- : [];
3616
- const artifactPaths = cleanList(current.artifactPaths || previous.artifactPaths, 80, 500);
3617
- const changedFiles = cleanList(current.changedFiles, 80, 500);
3618
- const startingFailureClass = normalizeResolveIOAIManagerFailureClass(previous.failureClass);
3619
- const latestFailureClass = normalizeResolveIOAIManagerFailureClass(current.failureClass || previous.failureClass);
3620
- const startingBlockerFingerprint = cleanText(previous.blockerFingerprint, 160)
3621
- || resolveResolveIOAIManagerBlockerFingerprint(previous, directive?.requiredStateTransition);
3622
- const startingEvidenceHash = cleanText(previous.evidenceHash, 160)
3623
- || hashResolveIOAIManagerEvidence(previous);
3624
- const blockers = [
3625
- status === 'manual_handoff' ? (directive?.reason || 'recovery_execution_requires_manual_handoff') : '',
3626
- status === 'waiting_for_execution' ? 'recovery_execution_waiting_for_current_evidence' : '',
3627
- status === 'blocked_same_evidence' ? 'recovery_execution_same_evidence_after_dispatch' : '',
3628
- status === 'waiting_for_new_evidence' ? 'recovery_execution_missing_material_evidence' : ''
3629
- ].filter(Boolean);
3630
- const createdAt = isoNow(input.now);
3631
- return {
3632
- contractId: stableHash('mgr-execution-proof', {
3633
- directiveId: directive?.directiveId || '',
3634
- dispatchAction: directive?.dispatchAction || 'park_manual',
3635
- status,
3636
- startingEvidenceHash,
3637
- latestEvidenceHash: assessment.evidenceHash,
3638
- createdAt: createdAt.slice(0, 16)
3639
- }),
3640
- directiveId: cleanText(directive?.directiveId, 180),
3641
- surface: cleanText(directive?.surface, 120) || 'runner',
3642
- dispatchAction: directive?.dispatchAction || 'park_manual',
3643
- phase: directive?.phase || 'manual',
3644
- status,
3645
- canContinueRun,
3646
- canRunProductRepair: canContinueRun && directive?.canRunProductRepair === true,
3647
- canRunExpensiveModel: canContinueRun && directive?.canRunExpensiveModel === true,
3648
- canResetLoopBudget: canContinueRun && assessment.material === true,
3649
- proofRequiredBeforeContinuation: directive?.proofRequiredBeforeContinuation === true,
3650
- requiresNewEvidence: directive?.requiresNewEvidence === true,
3651
- newEvidence: assessment.changed,
3652
- materialEvidence: assessment.material,
3653
- evidenceStrength: assessment.strength,
3654
- evidenceSignals: assessment.signals,
3655
- startingFailureClass,
3656
- startingBlockerFingerprint,
3657
- startingEvidenceHash,
3658
- latestFailureClass,
3659
- latestBlockerFingerprint: assessment.blockerFingerprint,
3660
- latestEvidenceHash: assessment.evidenceHash,
3661
- requiredEvidence,
3662
- missingEvidence,
3663
- artifactPaths,
3664
- changedFiles,
3665
- blockers,
3666
- nextAllowedAction: canContinueRun ? (directive?.nextCommands[0] || 'continue_gate') : 'collect_required_recovery_proof',
3667
- forbiddenActions: Array.from(new Set([
3668
- 'Do not continue product-code repair until recovery execution proof is proof_ready.',
3669
- ...cleanList(directive?.forbiddenActions, 30, 500)
3670
- ])),
3671
- createdAt
3672
- };
3673
- }
3674
-
3675
- export function validateResolveIOAIManagerRecoveryExecutionProofContract(value: any): {
3676
- valid: boolean;
3677
- status: ResolveIOAIManagerRecoveryExecutionProofStatus | 'blocked';
3678
- blockers: string[];
3679
- normalized: ResolveIOAIManagerRecoveryExecutionProofContract;
3680
- } {
3681
- const source = value || {};
3682
- const validStatuses: ResolveIOAIManagerRecoveryExecutionProofStatus[] = [
3683
- 'proof_ready',
3684
- 'waiting_for_execution',
3685
- 'waiting_for_new_evidence',
3686
- 'blocked_same_evidence',
3687
- 'manual_handoff'
3688
- ];
3689
- const status = cleanText(source.status, 120) as ResolveIOAIManagerRecoveryExecutionProofStatus;
3690
- const normalized: ResolveIOAIManagerRecoveryExecutionProofContract = {
3691
- contractId: cleanText(source.contractId || source.contract_id, 180),
3692
- directiveId: cleanText(source.directiveId || source.directive_id, 180),
3693
- surface: cleanText(source.surface, 120),
3694
- dispatchAction: cleanText(source.dispatchAction || source.dispatch_action, 120) as ResolveIOAIManagerRecoveryActionDispatchAction,
3695
- phase: cleanText(source.phase, 120) as ResolveIOAIManagerRecoveryExecutionPhase,
3696
- status: validStatuses.includes(status) ? status : 'manual_handoff',
3697
- canContinueRun: source.canContinueRun === true || source.can_continue_run === true,
3698
- canRunProductRepair: source.canRunProductRepair === true || source.can_run_product_repair === true,
3699
- canRunExpensiveModel: source.canRunExpensiveModel === true || source.can_run_expensive_model === true,
3700
- canResetLoopBudget: source.canResetLoopBudget === true || source.can_reset_loop_budget === true,
3701
- proofRequiredBeforeContinuation: source.proofRequiredBeforeContinuation === true || source.proof_required_before_continuation === true,
3702
- requiresNewEvidence: source.requiresNewEvidence === true || source.requires_new_evidence === true,
3703
- newEvidence: source.newEvidence === true || source.new_evidence === true,
3704
- materialEvidence: source.materialEvidence === true || source.material_evidence === true,
3705
- evidenceStrength: cleanText(source.evidenceStrength || source.evidence_strength, 120) as ResolveIOAIManagerEvidenceStrength,
3706
- evidenceSignals: cleanList(source.evidenceSignals || source.evidence_signals, 30, 200),
3707
- startingFailureClass: cleanText(source.startingFailureClass || source.starting_failure_class, 120),
3708
- startingBlockerFingerprint: cleanText(source.startingBlockerFingerprint || source.starting_blocker_fingerprint, 180),
3709
- startingEvidenceHash: cleanText(source.startingEvidenceHash || source.starting_evidence_hash, 180),
3710
- latestFailureClass: cleanText(source.latestFailureClass || source.latest_failure_class, 120),
3711
- latestBlockerFingerprint: cleanText(source.latestBlockerFingerprint || source.latest_blocker_fingerprint, 180),
3712
- latestEvidenceHash: cleanText(source.latestEvidenceHash || source.latest_evidence_hash, 180),
3713
- requiredEvidence: cleanList(source.requiredEvidence || source.required_evidence, 30, 500),
3714
- missingEvidence: cleanList(source.missingEvidence || source.missing_evidence, 30, 500),
3715
- artifactPaths: cleanList(source.artifactPaths || source.artifact_paths, 80, 500),
3716
- changedFiles: cleanList(source.changedFiles || source.changed_files, 80, 500),
3717
- blockers: cleanList(source.blockers, 30, 500),
3718
- nextAllowedAction: cleanText(source.nextAllowedAction || source.next_allowed_action, 180),
3719
- forbiddenActions: cleanList(source.forbiddenActions || source.forbidden_actions, 30, 500),
3720
- createdAt: cleanText(source.createdAt || source.created_at, 120)
3721
- };
3722
- const blockers = [
3723
- normalized.contractId ? '' : 'Recovery execution proof is missing contractId.',
3724
- normalized.directiveId || normalized.status === 'manual_handoff' ? '' : 'Recovery execution proof is missing directiveId.',
3725
- normalized.dispatchAction ? '' : 'Recovery execution proof is missing dispatchAction.',
3726
- validStatuses.includes(status) ? '' : 'Recovery execution proof has an invalid status.',
3727
- normalized.canContinueRun && normalized.status !== 'proof_ready' ? 'Recovery execution cannot continue unless status=proof_ready.' : '',
3728
- normalized.status === 'proof_ready' && normalized.proofRequiredBeforeContinuation && !normalized.materialEvidence ? 'Proof-ready recovery requires materialEvidence=true when proof is required.' : '',
3729
- normalized.status === 'proof_ready' && normalized.requiresNewEvidence && !normalized.newEvidence ? 'Proof-ready recovery requires newEvidence=true when new evidence is required.' : '',
3730
- normalized.canRunProductRepair && !normalized.canContinueRun ? 'Product repair cannot run before recovery proof can continue.' : '',
3731
- normalized.canRunExpensiveModel && !normalized.canContinueRun ? 'Expensive model cannot run before recovery proof can continue.' : '',
3732
- normalized.status !== 'proof_ready' && normalized.missingEvidence.length === 0 && normalized.proofRequiredBeforeContinuation ? 'Blocked recovery proof must list missingEvidence.' : '',
3733
- normalized.forbiddenActions.length ? '' : 'Recovery execution proof must include forbiddenActions.'
3734
- ].filter(Boolean);
3735
- return {
3736
- valid: blockers.length === 0,
3737
- status: blockers.length ? 'blocked' : normalized.status,
3738
- blockers,
3739
- normalized
3740
- };
3741
- }
3742
-
3743
- function newListEntries(current: string[], previous: string[]): string[] {
3744
- const existing = new Set(previous.map((entry) => cleanText(entry, 500)).filter(Boolean));
3745
- return current
3746
- .map((entry) => cleanText(entry, 500))
3747
- .filter((entry) => entry && !existing.has(entry));
3748
- }
3749
-
3750
- function recordLane(value: any): string {
3751
- return cleanText(value?.lane, 80);
3752
- }
3753
-
3754
- function recordStepType(value: any): string {
3755
- return cleanText(value?.stepType, 80);
3756
- }
3757
-
3758
- function recordFailureClass(value: any): string {
3759
- const valueText = cleanText(value?.failureClass, 80);
3760
- return valueText ? normalizeResolveIOAIManagerFailureClass(valueText) : '';
3761
- }
3762
-
3763
- function materialEvidenceText(record: ResolveIOAIManagerFailureRecord | undefined, paths: string[] = []): string {
3764
- return [
3765
- cleanText(record?.blocker, 1200),
3766
- cleanText(record?.summary, 1200),
3767
- ...paths.map((path) => cleanText(path, 500))
3768
- ].filter(Boolean).join(' ').toLowerCase();
3769
- }
3770
-
3771
- function hasMaterialEvidenceLanguage(text: string): boolean {
3772
- return /(business|assertion|proof|before|after|dom|trace|stack|network|mongo|query|diff|scope|diagnosis|journey|contract|workflow|compile|build|preflight|infra|chrome|puppeteer|release|publish|deploy|sample|seed|route|auth|hydration|performance|slow|owner|root.?cause|repro|pdf|export|upload|import|filter|invoice|saved|calculated|comparison|report)/i.test(text);
3773
- }
3774
-
3775
- export function assessResolveIOAIManagerEvidenceChange(
3776
- previous: (ResolveIOAIManagerFailureRecord | ResolveIOAIManagerRecoveryCheckpoint | undefined),
3777
- current: ResolveIOAIManagerFailureRecord | undefined,
3778
- fallbackObjective?: string
3779
- ): ResolveIOAIManagerEvidenceAssessment {
3780
- const currentRecord = current || {};
3781
- const previousRecord = previous as any;
3782
- const previousEvidenceHash = previousRecord ? cleanText(previousRecord.evidenceHash, 160) || hashResolveIOAIManagerEvidence(previousRecord) : '';
3783
- const currentEvidenceHash = hashResolveIOAIManagerEvidence(currentRecord);
3784
- const previousBlockerFingerprint = previousRecord
3785
- ? cleanText(previousRecord.blockerFingerprint, 160) || resolveResolveIOAIManagerBlockerFingerprint(previousRecord, fallbackObjective)
3786
- : '';
3787
- const currentBlockerFingerprint = resolveResolveIOAIManagerBlockerFingerprint(currentRecord, fallbackObjective);
3788
- const previousChangedFiles = cleanList(previousRecord?.changedFiles, 80, 500);
3789
- const currentChangedFiles = cleanList(currentRecord.changedFiles, 80, 500);
3790
- const previousArtifactPaths = cleanList(previousRecord?.artifactPaths, 80, 500);
3791
- const currentArtifactPaths = cleanList(currentRecord.artifactPaths, 80, 500);
3792
- const addedChangedFiles = newListEntries(currentChangedFiles, previousChangedFiles);
3793
- const addedArtifactPaths = newListEntries(currentArtifactPaths, previousArtifactPaths);
3794
- const signals: string[] = [];
3795
- if (previousEvidenceHash && currentEvidenceHash !== previousEvidenceHash) {
3796
- signals.push('evidence_hash_changed');
3797
- }
3798
- if (previousBlockerFingerprint && currentBlockerFingerprint !== previousBlockerFingerprint) {
3799
- signals.push('blocker_fingerprint_changed');
3800
- }
3801
- if (recordLane(previousRecord) && recordLane(previousRecord) !== recordLane(currentRecord)) {
3802
- signals.push('lane_changed');
3803
- }
3804
- if (recordStepType(previousRecord) && recordStepType(previousRecord) !== recordStepType(currentRecord)) {
3805
- signals.push('step_type_changed');
3806
- }
3807
- if (recordFailureClass(previousRecord) && recordFailureClass(previousRecord) !== recordFailureClass(currentRecord)) {
3808
- signals.push('failure_class_changed');
3809
- }
3810
- if (addedChangedFiles.length) {
3811
- signals.push('changed_files_added');
3812
- }
3813
- if (addedArtifactPaths.length) {
3814
- signals.push('artifact_paths_added');
3815
- }
3816
- if (isPassingOutcome(currentRecord)) {
3817
- signals.push('passing_outcome');
3818
- }
3819
- const changed = signals.length > 0;
3820
- const evidenceText = materialEvidenceText(currentRecord, addedArtifactPaths);
3821
- const pathOrSummaryHasMaterialSignal = hasMaterialEvidenceLanguage(evidenceText);
3822
- const proof = signals.includes('passing_outcome');
3823
- const structuralChange = signals.some((signal) => /blocker_fingerprint_changed|lane_changed|step_type_changed|failure_class_changed/.test(signal));
3824
- const materialArtifact = addedArtifactPaths.length > 0 && pathOrSummaryHasMaterialSignal;
3825
- const materialChangedFiles = addedChangedFiles.length > 0
3826
- && /diagnosis|owner|scope|diff|root.?cause|failing path|stack|trace|business|proof|compile|release|deploy|workflow|journey/i.test(evidenceText);
3827
- const material = proof || structuralChange || materialArtifact || materialChangedFiles;
3828
- const strength: ResolveIOAIManagerEvidenceStrength = proof
3829
- ? 'proof'
3830
- : material
3831
- ? 'material'
3832
- : changed
3833
- ? 'weak'
3834
- : 'none';
3835
- return {
3836
- changed,
3837
- material,
3838
- strength,
3839
- signals,
3840
- evidenceHash: currentEvidenceHash,
3841
- blockerFingerprint: currentBlockerFingerprint
3842
- };
3843
- }
3844
-
3845
- function proposedActionIsProductRepair(value: any): boolean {
3846
- const normalized = cleanText(value, 120);
3847
- return /product|code|repair|build|business|journey|workflow/i.test(normalized)
3848
- && !/infra|compile|diagnosis|manual|evidence|release|publish/i.test(normalized);
3849
- }
3850
-
3851
- export function decideResolveIOAIManagerRecoveryGate(
3852
- input: ResolveIOAIManagerRecoveryGateInput
3853
- ): ResolveIOAIManagerRecoveryGateDecision {
3854
- const checkpoint = input.checkpoint;
3855
- const hasCurrent = !!input.current;
3856
- const current = input.current || {};
3857
- const assessment = hasCurrent
3858
- ? assessResolveIOAIManagerEvidenceChange(checkpoint, current, checkpoint.objective)
3859
- : {
3860
- changed: false,
3861
- material: false,
3862
- strength: 'none' as ResolveIOAIManagerEvidenceStrength,
3863
- signals: [],
3864
- evidenceHash: checkpoint.evidenceHash,
3865
- blockerFingerprint: checkpoint.blockerFingerprint
3866
- };
3867
- const blockerFingerprint = assessment.blockerFingerprint;
3868
- const evidenceHash = assessment.evidenceHash;
3869
- const changedFiles = hasCurrent ? cleanList(current.changedFiles, 80, 500) : checkpoint.changedFiles;
3870
- const artifactPaths = hasCurrent ? cleanList(current.artifactPaths, 80, 500) : checkpoint.artifactPaths;
3871
- const evidenceChanged = assessment.changed;
3872
- const proposedAction = cleanText(input.proposedAction || checkpoint.allowedAction, 120);
3873
- const productRepairRequested = proposedActionIsProductRepair(proposedAction);
3874
- const missingEvidence = checkpoint.requiredEvidence.filter((required) => {
3875
- const normalized = cleanText(required, 120).toLowerCase();
3876
- if (!normalized) {
3877
- return false;
3878
- }
3879
- if (/artifact|log|proof|gate|evidence/.test(normalized)) {
3880
- return !artifactPaths.length && !current.evidenceHash;
3881
- }
3882
- if (/diff|changed files|owner|scope|file/.test(normalized)) {
3883
- return !changedFiles.length;
3884
- }
3885
- return false;
3886
- });
3887
- const makeDecision = (
3888
- action: ResolveIOAIManagerRecoveryGateAction,
3889
- reason: string,
3890
- overrides: Partial<ResolveIOAIManagerRecoveryGateDecision> = {}
3891
- ): ResolveIOAIManagerRecoveryGateDecision => ({
3892
- action,
3893
- reason,
3894
- canRunProductRepair: checkpoint.productRepairAllowed,
3895
- canRunExpensiveModel: checkpoint.expensiveModelAllowed,
3896
- shouldResetLoopBudget: false,
3897
- shouldIncrementAttempt: action === 'allow',
3898
- newEvidence: evidenceChanged,
3899
- materialEvidence: assessment.material,
3900
- evidenceStrength: assessment.strength,
3901
- evidenceSignals: assessment.signals,
3902
- blockerFingerprint,
3903
- evidenceHash,
3904
- missingEvidence,
3905
- checkpoint: {
3906
- ...checkpoint,
3907
- updatedAt: isoNow(input.now)
3908
- },
3909
- ...overrides
3910
- });
3911
-
3912
- if (checkpoint.status === 'complete') {
3913
- return makeDecision('complete', 'recovery_gate_checkpoint_already_complete', {
3914
- canRunProductRepair: false,
3915
- canRunExpensiveModel: false,
3916
- shouldIncrementAttempt: false
3917
- });
3918
- }
3919
- if (checkpoint.status === 'manual_handoff' && input.operatorApproved !== true) {
3920
- return makeDecision('manual_handoff', 'recovery_gate_manual_handoff_requires_operator_approval', {
3921
- canRunProductRepair: false,
3922
- canRunExpensiveModel: false,
3923
- shouldIncrementAttempt: false
3924
- });
3925
- }
3926
- if (productRepairRequested && !checkpoint.productRepairAllowed) {
3927
- return makeDecision('reject_action', 'recovery_gate_product_repair_not_allowed_for_checkpoint', {
3928
- canRunProductRepair: false,
3929
- canRunExpensiveModel: false,
3930
- shouldIncrementAttempt: false
3931
- });
3932
- }
3933
- if (checkpoint.status === 'parked' && !evidenceChanged) {
3934
- return makeDecision('collect_new_evidence', 'recovery_gate_parked_until_new_evidence', {
3935
- canRunProductRepair: false,
3936
- canRunExpensiveModel: false,
3937
- shouldIncrementAttempt: false
3938
- });
3939
- }
3940
- if (checkpoint.status === 'parked' && evidenceChanged && !assessment.material) {
3941
- return makeDecision('collect_new_evidence', 'recovery_gate_weak_evidence_requires_material_signal', {
3942
- canRunProductRepair: false,
3943
- canRunExpensiveModel: false,
3944
- shouldIncrementAttempt: false
3945
- });
3946
- }
3947
- if (checkpoint.attempts >= checkpoint.maxAttemptsBeforePark && !evidenceChanged) {
3948
- return makeDecision('collect_new_evidence', 'recovery_gate_attempt_limit_requires_new_evidence', {
3949
- canRunProductRepair: false,
3950
- canRunExpensiveModel: false,
3951
- shouldIncrementAttempt: false
3952
- });
3953
- }
3954
- if (checkpoint.attempts >= checkpoint.maxAttemptsBeforePark && evidenceChanged && !assessment.material) {
3955
- return makeDecision('collect_new_evidence', 'recovery_gate_attempt_limit_requires_material_evidence', {
3956
- canRunProductRepair: false,
3957
- canRunExpensiveModel: false,
3958
- shouldIncrementAttempt: false
3959
- });
3960
- }
3961
- if (evidenceChanged) {
3962
- const currentFailureClass = normalizeResolveIOAIManagerFailureClass(current.failureClass);
3963
- const currentCanRunProductRepair = checkpoint.productRepairAllowed
3964
- || !/^(infra|compile|diagnosis|release)$/i.test(currentFailureClass);
3965
- return makeDecision('allow', 'recovery_gate_new_material_evidence_unblocks_retry', {
3966
- canRunProductRepair: currentCanRunProductRepair,
3967
- canRunExpensiveModel: checkpoint.expensiveModelAllowed || currentCanRunProductRepair,
3968
- shouldResetLoopBudget: true
3969
- });
3970
- }
3971
- return makeDecision('allow', 'recovery_gate_action_allowed');
3972
- }
3973
-
3974
- function failureKey(record: ResolveIOAIManagerFailureRecord | undefined): string {
3975
- if (!record) {
3976
- return '';
3977
- }
3978
- const failureClass = normalizeResolveIOAIManagerFailureClass(record.failureClass);
3979
- const blockerFingerprint = resolveResolveIOAIManagerBlockerFingerprint(record);
3980
- return `${cleanText(record.lane, 80)}:${cleanText(record.stepType, 80)}:${failureClass}:${blockerFingerprint}`;
3981
- }
3982
-
3983
- function failureEvidenceKey(record: ResolveIOAIManagerFailureRecord | undefined): string {
3984
- return `${failureKey(record)}:${hashResolveIOAIManagerEvidence(record)}`;
3985
- }
3986
-
3987
- function isPassingOutcome(record: ResolveIOAIManagerFailureRecord | undefined): boolean {
3988
- return /^(pass|accepted|ready_to_publish|published|ready_for_merge|complete|completed)$/i.test(cleanText(record?.outcome, 80));
3989
- }
3990
-
3991
- function isManualOutcome(record: ResolveIOAIManagerFailureRecord | undefined): boolean {
3992
- return /^(manual_handoff|park_manual|stopped)$/i.test(cleanText(record?.outcome, 80));
3993
- }
3994
-
3995
- export function buildResolveIOAIManagerRecoveryPlan(input: ResolveIOAIManagerRecoveryPlanInput = {}): ResolveIOAIManagerRecoveryPlan {
3996
- const action = cleanText(input.action, 80) || 'continue';
3997
- const reason = cleanText(input.reason, 240);
3998
- const failureClass = normalizeResolveIOAIManagerFailureClass(input.failureClass);
3999
- const lane = cleanText(input.lane, 80) || 'supervisor';
4000
- const stepType = cleanText(input.stepType, 80) || 'unknown';
4001
- const blocker = cleanText(input.blocker, 700);
4002
- const changedFiles = cleanList(input.changedFiles, 12, 240);
4003
- const artifactPaths = cleanList(input.artifactPaths, 12, 240);
4004
- const maxAttemptsBeforePark = Math.max(1, Number(input.maxSameFailureRepeats || 3) || 3);
4005
- const commonNotes = [
4006
- reason ? `policy_reason=${reason}` : '',
4007
- blocker ? `blocker=${blocker}` : '',
4008
- changedFiles.length ? `changed_files=${changedFiles.join(', ')}` : '',
4009
- artifactPaths.length ? `artifacts=${artifactPaths.join(', ')}` : ''
4010
- ].filter(Boolean);
4011
- const base: Omit<ResolveIOAIManagerRecoveryPlan, 'recoveryClass' | 'nextActionLabel' | 'objective' | 'allowedAction' | 'productRepairAllowed' | 'expensiveModelAllowed' | 'finiteSteps' | 'requiredEvidence' | 'loopResetEvidence' | 'forbiddenActions'> = {
4012
- lane,
4013
- stepType,
4014
- maxAttemptsBeforePark,
4015
- notes: commonNotes
4016
- };
4017
- const makePlan = (
4018
- recoveryClass: ResolveIOAIManagerRecoveryClass,
4019
- nextActionLabel: string,
4020
- objective: string,
4021
- allowedAction: string,
4022
- productRepairAllowed: boolean,
4023
- expensiveModelAllowed: boolean,
4024
- finiteSteps: string[],
4025
- requiredEvidence: string[],
4026
- loopResetEvidence: string[],
4027
- forbiddenActions: string[]
4028
- ): ResolveIOAIManagerRecoveryPlan => ({
4029
- ...base,
4030
- recoveryClass,
4031
- nextActionLabel,
4032
- objective,
4033
- allowedAction,
4034
- productRepairAllowed,
4035
- expensiveModelAllowed,
4036
- finiteSteps,
4037
- requiredEvidence,
4038
- loopResetEvidence,
4039
- forbiddenActions
4040
- });
4041
- if (action === 'reset_loop_budget') {
4042
- return makePlan(
4043
- 'advance_after_proof',
4044
- 'Advance After Proof',
4045
- 'Checkpoint the passing evidence and move to the next required gate.',
4046
- 'advance_to_next_gate',
4047
- false,
4048
- false,
4049
- [
4050
- 'Record the passing artifact, changed files, and gate result.',
4051
- 'Reset the loop counter because a real gate passed.',
4052
- 'Select the next unmet deterministic gate instead of repeating the previous repair.'
4053
- ],
4054
- ['passing gate record', 'artifact or log proving the passed check'],
4055
- ['new passing gate result', 'new business proof artifact'],
4056
- ['rerun the same repair after a pass', 'mark accepted without the required downstream gate']
4057
- );
4058
- }
4059
- if (action === 'manual_handoff') {
4060
- return makePlan(
4061
- 'manual_handoff',
4062
- 'Manual Review',
4063
- 'Stop autonomous repair and expose the blocker, evidence, and last safe state.',
4064
- 'manual_review_only',
4065
- false,
4066
- false,
4067
- [
4068
- 'Freeze further product-code edits.',
4069
- 'Show the blocker fingerprint, evidence hash, and prior attempts.',
4070
- 'Require a human edit to classification, scope, or retry policy before another model/code loop.'
4071
- ],
4072
- ['blocker fingerprint', 'evidence hash', 'attempt history'],
4073
- ['manual policy change', 'new external evidence'],
4074
- ['start another automatic model repair', 'hide the failed evidence']
4075
- );
4076
- }
4077
- if (action === 'budget_stop') {
4078
- return makePlan(
4079
- 'manual_handoff',
4080
- 'Budget Stop Review',
4081
- 'Stop autonomous model/code loops until a cheaper scoped next action is selected.',
4082
- 'budget_review_only',
4083
- false,
4084
- false,
4085
- [
4086
- 'Freeze further model repair loops.',
4087
- 'Show the prompt/token/runtime budget that tripped the guard.',
4088
- 'Select a cheaper deterministic gate, infra repair, diagnosis revision, or manual scope edit before resuming.'
4089
- ],
4090
- ['budget guard reason', 'latest prompt estimate', 'last blocker/evidence hash'],
4091
- ['manual scope reduction', 'new deterministic evidence', 'approved budget policy change'],
4092
- ['start another broad model prompt', 'reset budget without new evidence', 'hide cost context']
4093
- );
4094
- }
4095
- if (failureClass === 'diagnosis' || stepType === 'diagnosis_gate') {
4096
- return makePlan(
4097
- 'diagnosis_only',
4098
- 'Run Diagnosis Gate',
4099
- 'Produce a falsifiable root-cause diagnosis before any repair.',
4100
- 'read_only_diagnosis',
4101
- false,
4102
- true,
4103
- [
4104
- 'Reproduce or explicitly classify the customer issue.',
4105
- 'Accept one falsifiable hypothesis and record rejected alternatives.',
4106
- 'Identify the frontend/backend/shared failing path.',
4107
- 'Select a small owner_files set.',
4108
- 'Define exact before/action/after business proof.'
4109
- ],
4110
- ['issue_case', 'accepted_hypothesis', 'rejected_alternatives', 'failing_path', 'owner_files', 'proof_plan'],
4111
- ['new reproduction artifact', 'new query/log/code evidence', 'validated diagnosis gate'],
4112
- ['edit product code', 'run broad repo repair', 'accept route-load evidence as success']
4113
- );
4114
- }
4115
- if (failureClass === 'owner_scope' || failureClass === 'out_of_scope' || /out.?of.?scope|owner_files/i.test(reason)) {
4116
- return makePlan(
4117
- 'diagnosis_revision',
4118
- 'Revise Diagnosis Scope',
4119
- 'Revise owner_files only when new evidence proves the current scope is wrong.',
4120
- 'diagnosis_revision_only',
4121
- false,
4122
- true,
4123
- [
4124
- 'Compare changed files against the diagnosis owner_files.',
4125
- 'Collect evidence proving why the new file is in the failing path.',
4126
- 'Update accepted_hypothesis, failing_path, owner_files, and proof_plan together.',
4127
- 'Resume repair only after the revised gate validates.'
4128
- ],
4129
- ['out-of-scope file list', 'new failing-path evidence', 'revalidated diagnosis gate'],
4130
- ['revised owner_files with evidence', 'new business proof requirement'],
4131
- ['keep broad edits without diagnosis', 'add convenience refactors', 'continue repair outside owner_files']
4132
- );
4133
- }
4134
- if (action === 'retry_infra') {
4135
- const isCompile = failureClass === 'compile';
4136
- return makePlan(
4137
- isCompile ? 'compile_repair' : 'infra_repair',
4138
- isCompile ? 'Repair Compile Gate' : 'Repair Infra Gate',
4139
- isCompile
4140
- ? 'Fix the deterministic compile/build blocker before spending another product repair loop.'
4141
- : 'Fix the deterministic harness/browser/server/Mongo blocker before product repair.',
4142
- isCompile ? 'compile_repair_only' : 'infra_repair_only',
4143
- false,
4144
- false,
4145
- isCompile
4146
- ? [
4147
- 'Read the exact compile/build log and identify the first actionable error.',
4148
- 'Fix missing dependency, stale artifact, command, cache, or type wiring required by the compile gate.',
4149
- 'Rerun the same finite compile command.',
4150
- 'Return the compile log artifact and status.'
4151
- ]
4152
- : [
4153
- 'Run preflight for Puppeteer, Chrome executable, ports, Mongo/settings, and startup command.',
4154
- 'Repair only the failing harness/environment item.',
4155
- 'Rerun the same infra check.',
4156
- 'Return the infra log and pass/fail status.'
4157
- ],
4158
- isCompile
4159
- ? ['compile command', 'compile log artifact', 'first failing error fixed or still failing']
4160
- : ['preflight command', 'infra log artifact', 'specific repaired environment item'],
4161
- ['same check now passes', 'new infra/compile blocker hash'],
4162
- ['run product-code model repair', 'count this as product failure', 'accept route/business success without the compile/infra gate']
4163
- );
4164
- }
4165
- if (action === 'park_repeated_failure' || action === 'park_ping_pong') {
4166
- return makePlan(
4167
- 'blocked_until_new_evidence',
4168
- action === 'park_ping_pong' ? 'Park Ping-Pong Loop' : 'Park Repeated Failure',
4169
- 'Stop the current loop until new evidence changes the diagnosis, route, or repair target.',
4170
- 'collect_new_evidence_only',
4171
- false,
4172
- false,
4173
- [
4174
- 'Do not rerun the same prompt or same repair.',
4175
- 'Show the repeated blocker and evidence hash.',
4176
- 'Collect a new artifact: failing DOM state, stack trace, network response, Mongo delta, compile log, or revised diagnosis.',
4177
- 'Reset the loop only after material evidence changes the blocker, proof, diagnosis, journey, or actionable trace.'
4178
- ],
4179
- ['same failure count', 'blocker fingerprint', 'evidence hash'],
4180
- ['changed blocker fingerprint', 'changed evidence hash', 'new artifact path', 'business/compile/infra/release proof artifact', 'revised diagnosis or journey contract', 'new actionable trace or data delta'],
4181
- ['alternate between two failed patches', 'increase loop budget without evidence', 'hide the park reason']
4182
- );
4183
- }
4184
- if (failureClass === 'journey') {
4185
- return makePlan(
4186
- 'journey_contract_repair',
4187
- 'Repair Journey Contract',
4188
- 'Fix the first/next/last workflow contract before app code work continues.',
4189
- 'journey_contract_repair',
4190
- false,
4191
- true,
4192
- [
4193
- 'Open docs/APP_JOURNEY_CONTRACT.md.',
4194
- 'Define first_screen, north_star_workflow, screen_sequence, data_story, completion_states, and qa_assertions.',
4195
- 'Ensure each CTA maps to an action, route, method, calculation, or state transition.',
4196
- 'Validate that sample data can drive the promised workflow.'
4197
- ],
4198
- ['validated journey_contract JSON', 'CTA-to-action mapping', 'workflow QA assertions'],
4199
- ['journey validation passes', 'new workflow QA rows generated'],
4200
- ['build empty routes', 'add link-only dashboard actions', 'defer workflow design to wow pass']
4201
- );
4202
- }
4203
- if (failureClass === 'release') {
4204
- return makePlan(
4205
- 'release_repair',
4206
- 'Repair Release Gate',
4207
- 'Repair deploy/publish/sample-data release evidence with a hotfix-first path before any repeated full deploy.',
4208
- 'release_repair_only',
4209
- false,
4210
- false,
4211
- [
4212
- 'Read the deploy/publish/sample-data log.',
4213
- 'Identify whether the blocker is domain, asset, seed data, route, permission, or CDN.',
4214
- 'Prefer backend hotfix, release config, domain, cache, or seed-data repair when the product artifact already has business proof.',
4215
- 'Rerun only the failed release gate.'
4216
- ],
4217
- ['deploy or publish log', 'sample-data status', 'failed release gate rerun'],
4218
- ['release gate passes', 'new release blocker hash'],
4219
- ['change core workflow after business QA passed', 'mark accepted from scorecard only', 'rerun full builder loop', 'repeat deploy of same artifact without force_deploy evidence']
4220
- );
4221
- }
4222
- if (failureClass === 'business' || failureClass === 'qa_evidence' || failureClass === 'route') {
4223
- return makePlan(
4224
- 'business_proof_repair',
4225
- 'Repair Business Proof',
4226
- 'Fix the exact failing workflow assertion and prove before/action/after behavior.',
4227
- 'business_repair',
4228
- true,
4229
- true,
4230
- [
4231
- 'Open the failing QA row or proof_plan.',
4232
- 'Trace the UI action to method/publication/query/calculation.',
4233
- 'Patch the smallest owner or workflow files.',
4234
- 'Rerun only the failed business assertion.',
4235
- 'Record DOM/data/Mongo/artifact proof.'
4236
- ],
4237
- ['failing assertion', 'action trace', 'business proof artifact'],
4238
- ['business assertion passes', 'new failed assertion with new evidence'],
4239
- ['treat route load as success', 'rerun unrelated QA rows first', 'accept scorecard-only evidence']
4240
- );
4241
- }
4242
- if (input.productRepairFailure !== false || failureClass === 'product_code') {
4243
- return makePlan(
4244
- 'product_code_repair',
4245
- 'Run Targeted Product Repair',
4246
- 'Repair the current product-code blocker with the smallest scoped edit and immediate proof.',
4247
- 'targeted_product_repair',
4248
- true,
4249
- true,
4250
- [
4251
- 'Inspect the current blocker, artifacts, changed files, and owner/workflow scope.',
4252
- 'Form one small repair hypothesis.',
4253
- 'Patch only files justified by the active diagnosis or journey contract.',
4254
- 'Rerun the smallest failed gate.',
4255
- 'Record new evidence before any additional loop.'
4256
- ],
4257
- ['owner/workflow scope', 'repair diff', 'failed gate rerun artifact'],
4258
- ['new evidence hash', 'same gate passes'],
4259
- ['broad repo search-and-edit', 'rerun the same prompt without inspecting artifacts', 'change unrelated UI polish']
4260
- );
4261
- }
4262
- return makePlan(
4263
- 'continue',
4264
- 'Continue Current Gate',
4265
- 'Continue the current lane because no blocking loop or infra condition was detected.',
4266
- 'continue',
4267
- false,
4268
- false,
4269
- [
4270
- 'Use the active lane memory.',
4271
- 'Run the next finite gate.',
4272
- 'Record artifacts and evidence hash.'
4273
- ],
4274
- ['active lane memory', 'finite gate artifact'],
4275
- ['new gate result', 'new artifact path'],
4276
- ['spawn duplicate runners', 'advance without evidence']
4277
- );
4278
- }
4279
-
4280
- function collectOpenTail(records: ResolveIOAIManagerFailureRecord[]): ResolveIOAIManagerFailureRecord[] {
4281
- const tail: ResolveIOAIManagerFailureRecord[] = [];
4282
- for (let index = records.length - 1; index >= 0; index -= 1) {
4283
- const record = records[index];
4284
- if (isPassingOutcome(record)) {
4285
- break;
4286
- }
4287
- tail.unshift(record);
4288
- }
4289
- return tail;
4290
- }
4291
-
4292
- function countSameFailure(records: ResolveIOAIManagerFailureRecord[], current: ResolveIOAIManagerFailureRecord): number {
4293
- const currentKey = failureKey(current);
4294
- let count = 0;
4295
- for (let index = records.length - 1; index >= 0; index -= 1) {
4296
- const record = records[index];
4297
- if (isPassingOutcome(record)) {
4298
- break;
4299
- }
4300
- if (failureKey(record) !== currentKey) {
4301
- break;
4302
- }
4303
- count += 1;
4304
- }
4305
- return count;
4306
- }
4307
-
4308
- function previousRecordForPolicy(
4309
- history: ResolveIOAIManagerFailureRecord[],
4310
- current: ResolveIOAIManagerFailureRecord,
4311
- currentWasExplicit: boolean
4312
- ): ResolveIOAIManagerFailureRecord | undefined {
4313
- if (!history.length) {
4314
- return undefined;
4315
- }
4316
- if (!currentWasExplicit) {
4317
- return history.length > 1 ? history[history.length - 2] : undefined;
4318
- }
4319
- const last = history[history.length - 1];
4320
- if (failureEvidenceKey(last) === failureEvidenceKey(current)) {
4321
- return history.length > 1 ? history[history.length - 2] : undefined;
4322
- }
4323
- return last;
4324
- }
4325
-
4326
- function countPingPong(records: ResolveIOAIManagerFailureRecord[], current: ResolveIOAIManagerFailureRecord): number {
4327
- const tail = collectOpenTail(records).filter((record) => {
4328
- return cleanText(record.lane, 80) === cleanText(current.lane, 80)
4329
- && cleanText(record.stepType, 80) === cleanText(current.stepType, 80);
4330
- });
4331
- if (tail.length < 4) {
4332
- return 0;
4333
- }
4334
- const keys = tail.map(failureKey).filter(Boolean);
4335
- const last = keys.slice(-6);
4336
- if (last.length < 4) {
4337
- return 0;
4338
- }
4339
- const distinct = Array.from(new Set(last));
4340
- if (distinct.length !== 2) {
4341
- return 0;
4342
- }
4343
- for (let index = 2; index < last.length; index += 1) {
4344
- if (last[index] !== last[index - 2]) {
4345
- return 0;
4346
- }
4347
- }
4348
- return last.length - 1;
4349
- }
4350
-
4351
- export function decideResolveIOAIManagerPolicy(input: ResolveIOAIManagerPolicyInput): ResolveIOAIManagerPolicyDecision {
4352
- const history = Array.isArray(input.history) ? input.history : [];
4353
- const currentWasExplicit = !!input.current;
4354
- const current = input.current || history[history.length - 1] || {};
4355
- const failureClass = normalizeResolveIOAIManagerFailureClass(current.failureClass);
4356
- const blockerFingerprint = resolveResolveIOAIManagerBlockerFingerprint(current);
4357
- const evidenceHash = hashResolveIOAIManagerEvidence(current);
4358
- const previous = previousRecordForPolicy(history, current, currentWasExplicit);
4359
- const previousSameFailure = previous && failureKey(previous) === failureKey(current);
4360
- const evidenceAssessment = previousSameFailure
4361
- ? assessResolveIOAIManagerEvidenceChange(previous, current)
4362
- : {
4363
- changed: false,
4364
- material: false,
4365
- strength: 'none' as ResolveIOAIManagerEvidenceStrength,
4366
- signals: [],
4367
- evidenceHash,
4368
- blockerFingerprint
4369
- };
4370
- const newEvidence = !!previousSameFailure && evidenceAssessment.changed;
4371
- const sameFailureCount = countSameFailure(history, current);
4372
- const pingPongCount = countPingPong(history, current);
4373
- const maxSameFailureRepeats = Math.max(1, Number(input.maxSameFailureRepeats || 3) || 3);
4374
- const maxPingPongTransitions = Math.max(3, Number(input.maxPingPongTransitions || 3) || 3);
4375
- const infraClasses = new Set((input.infraFailureClasses || ['infra', 'compile']).map(normalizeResolveIOAIManagerFailureClass));
4376
- const ignoredClasses = new Set((input.ignoredFailureClasses || []).map(normalizeResolveIOAIManagerFailureClass));
4377
- const base = {
4378
- failureClass,
4379
- blockerFingerprint,
4380
- evidenceHash,
4381
- sameFailureCount,
4382
- pingPongCount,
4383
- newEvidence,
4384
- materialEvidence: evidenceAssessment.material,
4385
- evidenceStrength: evidenceAssessment.strength,
4386
- evidenceSignals: evidenceAssessment.signals,
4387
- loopBudgetShouldReset: false,
4388
- productRepairFailure: !infraClasses.has(failureClass) && !ignoredClasses.has(failureClass)
4389
- };
4390
- const withPlan = (
4391
- action: ResolveIOAIManagerAction,
4392
- reason: string,
4393
- overrides: Partial<Omit<ResolveIOAIManagerPolicyDecision, 'action' | 'reason' | 'recoveryPlan' | 'recoveryCheckpoint'>> = {}
4394
- ): ResolveIOAIManagerPolicyDecision => {
4395
- const merged = {
4396
- ...base,
4397
- ...overrides
4398
- };
4399
- const recoveryPlan = buildResolveIOAIManagerRecoveryPlan({
4400
- action,
4401
- reason,
4402
- failureClass: merged.failureClass,
4403
- lane: current.lane,
4404
- stepType: current.stepType,
4405
- blocker: current.blocker || current.summary,
4406
- sameFailureCount: merged.sameFailureCount,
4407
- pingPongCount: merged.pingPongCount,
4408
- newEvidence: merged.newEvidence,
4409
- productRepairFailure: merged.productRepairFailure,
4410
- changedFiles: current.changedFiles,
4411
- artifactPaths: current.artifactPaths,
4412
- maxSameFailureRepeats
4413
- });
4414
- const recoveryCheckpoint = buildResolveIOAIManagerRecoveryCheckpoint({
4415
- plan: recoveryPlan,
4416
- current
4417
- });
4418
- const recoveryEvidenceProbe = buildResolveIOAIManagerRecoveryEvidenceProbe({
4419
- checkpoint: recoveryCheckpoint,
4420
- current
4421
- });
4422
- return {
4423
- ...merged,
4424
- action,
4425
- reason,
4426
- recoveryPlan,
4427
- recoveryCheckpoint,
4428
- recoveryEvidenceProbe,
4429
- recoveryAction: buildResolveIOAIManagerRecoveryActionPacket({
4430
- plan: recoveryPlan,
4431
- checkpoint: recoveryCheckpoint,
4432
- probe: recoveryEvidenceProbe,
4433
- current
4434
- })
4435
- };
4436
- };
4437
- if (isPassingOutcome(current)) {
4438
- return withPlan('reset_loop_budget', 'manager_policy_progress_passed', {
4439
- loopBudgetShouldReset: true,
4440
- productRepairFailure: false
4441
- });
4442
- }
4443
- if (isManualOutcome(current)) {
4444
- return withPlan('manual_handoff', 'manager_policy_manual_or_stopped');
4445
- }
4446
- if (pingPongCount >= maxPingPongTransitions) {
4447
- return withPlan('park_ping_pong', 'manager_policy_ping_pong_failure_loop');
4448
- }
4449
- if (sameFailureCount >= maxSameFailureRepeats && !evidenceAssessment.material) {
4450
- return withPlan('park_repeated_failure', newEvidence
4451
- ? 'manager_policy_same_failure_with_weak_evidence'
4452
- : 'manager_policy_same_failure_without_new_evidence');
4453
- }
4454
- if (infraClasses.has(failureClass)) {
4455
- return withPlan('retry_infra', 'manager_policy_infra_failure_routes_to_infra_repair', {
4456
- productRepairFailure: false
4457
- });
4458
- }
4459
- if (newEvidence || !previousSameFailure) {
4460
- if (newEvidence && !evidenceAssessment.material) {
4461
- return withPlan('continue', 'manager_policy_weak_evidence_does_not_reset_loop_budget');
4462
- }
4463
- return withPlan('continue', newEvidence
4464
- ? 'manager_policy_new_material_evidence_resets_loop_budget'
4465
- : 'manager_policy_new_failure_or_lane', {
4466
- loopBudgetShouldReset: true,
4467
- materialEvidence: newEvidence ? true : base.materialEvidence,
4468
- evidenceStrength: newEvidence ? evidenceAssessment.strength : base.evidenceStrength
4469
- });
4470
- }
4471
- return withPlan('continue', 'manager_policy_retry_below_repeat_limit');
4472
- }
4473
-
4474
- function buildReplayDirectiveFromPlan(input: {
4475
- surface: string;
4476
- plan: ResolveIOAIManagerRecoveryPlan;
4477
- current: ResolveIOAIManagerFailureRecord;
4478
- now?: Date | string;
4479
- }): ResolveIOAIManagerRecoveryExecutionDirective {
4480
- const checkpoint = buildResolveIOAIManagerRecoveryCheckpoint({
4481
- plan: input.plan,
4482
- current: input.current,
4483
- now: input.now
4484
- });
4485
- const probe = buildResolveIOAIManagerRecoveryEvidenceProbe({
4486
- checkpoint,
4487
- current: input.current,
4488
- now: input.now
4489
- });
4490
- const action = buildResolveIOAIManagerRecoveryActionPacket({
4491
- plan: input.plan,
4492
- checkpoint,
4493
- probe,
4494
- current: input.current,
4495
- now: input.now
4496
- });
4497
- const dispatch = decideResolveIOAIManagerRecoveryActionDispatch({
4498
- action,
4499
- current: input.current,
4500
- now: input.now
4501
- });
4502
- return buildResolveIOAIManagerRecoveryExecutionDirective({
4503
- action,
4504
- dispatchDecision: dispatch,
4505
- current: input.current,
4506
- surface: input.surface,
4507
- now: input.now
4508
- });
4509
- }
4510
-
4511
- function replayCaseFromDirective(input: {
4512
- caseId: string;
4513
- surface: string;
4514
- action: string;
4515
- reason: string;
4516
- directive: ResolveIOAIManagerRecoveryExecutionDirective;
4517
- expectedSafeAutoDispatch: boolean;
4518
- pass: boolean;
4519
- loopBudgetShouldReset?: boolean;
4520
- materialEvidence?: boolean;
4521
- evidenceStrength?: ResolveIOAIManagerEvidenceStrength;
4522
- details?: Record<string, any>;
4523
- }): ResolveIOAIManagerRecoveryReplayCase {
4524
- const directive = input.directive;
4525
- const safeAutoDispatch = isResolveIOAIManagerSafeAutoDispatch({
4526
- dispatchAction: directive.dispatchAction,
4527
- directive,
4528
- includeJourneyContractRepair: input.expectedSafeAutoDispatch && directive.dispatchAction === 'run_journey_contract_repair',
4529
- includeReleaseRepair: input.expectedSafeAutoDispatch && directive.dispatchAction === 'run_release_repair',
4530
- includeProductRepair: false
4531
- });
4532
- return {
4533
- caseId: input.caseId,
4534
- surface: input.surface,
4535
- pass: input.pass && safeAutoDispatch === input.expectedSafeAutoDispatch,
4536
- action: input.action,
4537
- reason: input.reason,
4538
- recoveryClass: cleanText(directive.dispatchRecord?.mode || directive.phase, 120),
4539
- dispatchAction: directive.dispatchAction,
4540
- safeAutoDispatch,
4541
- expectedSafeAutoDispatch: input.expectedSafeAutoDispatch,
4542
- productRepairAllowed: directive.canRunProductRepair === true,
4543
- loopBudgetShouldReset: input.loopBudgetShouldReset === true,
4544
- materialEvidence: input.materialEvidence === true,
4545
- evidenceStrength: input.evidenceStrength || 'none',
4546
- ...(directive.releasePolicy ? {
4547
- hotfixFirst: directive.releasePolicy.policy === 'hotfix_first',
4548
- fullDeployAllowed: directive.releasePolicy.fullDeployAllowed
4549
- } : {}),
4550
- details: {
4551
- phase: directive.phase,
4552
- allowed: directive.allowed,
4553
- reason: directive.reason,
4554
- releasePolicy: directive.releasePolicy,
4555
- ...(input.details || {})
4556
- }
4557
- };
4558
- }
4559
-
4560
- export function buildResolveIOAIManagerRecoveryReplayMatrix(
4561
- input: ResolveIOAIManagerRecoveryReplayMatrixInput = {}
4562
- ): ResolveIOAIManagerRecoveryReplayCase[] {
4563
- const surface = cleanText(input.surface || 'runner', 120);
4564
- const maxSameFailureRepeats = Math.max(1, Number(input.maxSameFailureRepeats || 2) || 2);
4565
- const includeReleaseRepair = input.includeReleaseRepair !== false;
4566
- const includeJourneyContractRepair = input.includeJourneyContractRepair !== false;
4567
- const cases: ResolveIOAIManagerRecoveryReplayCase[] = [];
4568
- const infraPolicy = decideResolveIOAIManagerPolicy({
4569
- history: [
4570
- { lane: 'qa', stepType: 'workflow_qa', outcome: 'needs_repair', failureClass: 'infra', blocker: 'Chrome executable missing.', evidenceHash: 'chrome-missing' }
4571
- ],
4572
- current: { lane: 'qa', stepType: 'workflow_qa', outcome: 'needs_repair', failureClass: 'infra', blocker: 'Chrome executable missing.', evidenceHash: 'chrome-missing' },
4573
- maxSameFailureRepeats
4574
- });
4575
- const infraDirective = buildResolveIOAIManagerRecoveryExecutionDirective({
4576
- action: infraPolicy.recoveryAction,
4577
- current: { lane: 'qa', stepType: 'workflow_qa', outcome: 'needs_repair', failureClass: 'infra', blocker: 'Chrome executable missing.', evidenceHash: 'chrome-missing' },
4578
- surface
4579
- });
4580
- cases.push(replayCaseFromDirective({
4581
- caseId: 'infra_routes_to_infra_repair',
4582
- surface,
4583
- action: infraPolicy.action,
4584
- reason: infraPolicy.reason,
4585
- directive: infraDirective,
4586
- expectedSafeAutoDispatch: true,
4587
- pass: infraPolicy.action === 'retry_infra'
4588
- && infraPolicy.recoveryPlan.recoveryClass === 'infra_repair'
4589
- && infraDirective.dispatchAction === 'run_infra_repair'
4590
- && infraDirective.canRunProductRepair === false,
4591
- details: { recoveryClass: infraPolicy.recoveryPlan.recoveryClass }
4592
- }));
4593
- const releasePlan = buildResolveIOAIManagerRecoveryPlan({
4594
- action: 'continue',
4595
- reason: 'publish failed after business proof',
4596
- failureClass: 'release',
4597
- lane: 'publish',
4598
- stepType: 'test_deploy',
4599
- blocker: 'Domain publish failed for the current artifact.'
4600
- });
4601
- const releaseCurrent = {
4602
- lane: 'publish',
4603
- stepType: 'test_deploy',
4604
- outcome: 'needs_repair',
4605
- failureClass: 'release',
4606
- blocker: 'Domain publish failed for the current artifact.',
4607
- evidenceHash: 'release-domain-publish-failed',
4608
- artifactPaths: ['runner-evidence/release-status.json']
4609
- };
4610
- const releaseDirective = buildReplayDirectiveFromPlan({
4611
- surface,
4612
- plan: releasePlan,
4613
- current: releaseCurrent
4614
- });
4615
- cases.push(replayCaseFromDirective({
4616
- caseId: 'release_uses_hotfix_first_repair',
4617
- surface,
4618
- action: 'continue',
4619
- reason: 'publish failed after business proof',
4620
- directive: releaseDirective,
4621
- expectedSafeAutoDispatch: includeReleaseRepair,
4622
- pass: releasePlan.recoveryClass === 'release_repair'
4623
- && releaseDirective.dispatchAction === 'run_release_repair'
4624
- && releaseDirective.releasePolicy?.policy === 'hotfix_first'
4625
- && releaseDirective.releasePolicy?.fullDeployAllowed === false
4626
- && releaseDirective.canRunProductRepair === false,
4627
- details: { recoveryClass: releasePlan.recoveryClass }
4628
- }));
4629
- const journeyPlan = buildResolveIOAIManagerRecoveryPlan({
4630
- action: 'continue',
4631
- reason: 'journey contract missing first next last',
4632
- failureClass: 'journey',
4633
- lane: 'plan',
4634
- stepType: 'journey_contract',
4635
- blocker: 'Journey contract does not map the hub CTA to an action.'
4636
- });
4637
- const journeyDirective = buildReplayDirectiveFromPlan({
4638
- surface,
4639
- plan: journeyPlan,
4640
- current: {
4641
- lane: 'plan',
4642
- stepType: 'journey_contract',
4643
- outcome: 'needs_repair',
4644
- failureClass: 'journey',
4645
- blocker: 'Journey contract does not map the hub CTA to an action.',
4646
- evidenceHash: 'journey-contract-invalid'
4647
- }
4648
- });
4649
- cases.push(replayCaseFromDirective({
4650
- caseId: 'journey_repair_is_safe_only_for_aicoder_surfaces',
4651
- surface,
4652
- action: 'continue',
4653
- reason: 'journey contract missing first next last',
4654
- directive: journeyDirective,
4655
- expectedSafeAutoDispatch: includeJourneyContractRepair,
4656
- pass: journeyPlan.recoveryClass === 'journey_contract_repair'
4657
- && journeyDirective.dispatchAction === 'run_journey_contract_repair'
4658
- && journeyDirective.canRunProductRepair === false,
4659
- details: { recoveryClass: journeyPlan.recoveryClass }
4660
- }));
4661
- const weakPolicy = decideResolveIOAIManagerPolicy({
4662
- history: [
4663
- { lane: 'repair', stepType: 'repair', outcome: 'needs_repair', failureClass: 'product_code', blocker: 'Save action still throws TypeError.', evidenceHash: 'save-before' },
4664
- { lane: 'repair', stepType: 'repair', outcome: 'needs_repair', failureClass: 'product_code', blocker: 'Save action still throws TypeError.', evidenceHash: 'renamed-hash-only' }
4665
- ],
4666
- current: { lane: 'repair', stepType: 'repair', outcome: 'needs_repair', failureClass: 'product_code', blocker: 'Save action still throws TypeError.', evidenceHash: 'renamed-hash-only' },
4667
- maxSameFailureRepeats
4668
- });
4669
- const weakDirective = buildResolveIOAIManagerRecoveryExecutionDirective({
4670
- action: weakPolicy.recoveryAction,
4671
- current: { lane: 'repair', stepType: 'repair', outcome: 'needs_repair', failureClass: 'product_code', blocker: 'Save action still throws TypeError.', evidenceHash: 'renamed-hash-only' },
4672
- surface
4673
- });
4674
- cases.push(replayCaseFromDirective({
4675
- caseId: 'weak_hash_only_evidence_stays_parked',
4676
- surface,
4677
- action: weakPolicy.action,
4678
- reason: weakPolicy.reason,
4679
- directive: weakDirective,
4680
- expectedSafeAutoDispatch: true,
4681
- pass: weakPolicy.action === 'park_repeated_failure'
4682
- && weakPolicy.materialEvidence === false
4683
- && weakPolicy.loopBudgetShouldReset === false
4684
- && weakDirective.dispatchAction === 'run_evidence_probe',
4685
- loopBudgetShouldReset: weakPolicy.loopBudgetShouldReset,
4686
- materialEvidence: weakPolicy.materialEvidence,
4687
- evidenceStrength: weakPolicy.evidenceStrength,
4688
- details: { evidenceSignals: weakPolicy.evidenceSignals }
4689
- }));
4690
- const materialPolicy = decideResolveIOAIManagerPolicy({
4691
- history: [
4692
- { lane: 'repair', stepType: 'repair', outcome: 'needs_repair', failureClass: 'product_code', blocker: 'Save action still throws TypeError.', evidenceHash: 'save-before', artifactPaths: ['qa/save-before.log'] },
4693
- {
4694
- lane: 'repair',
4695
- stepType: 'repair',
4696
- outcome: 'needs_repair',
4697
- failureClass: 'product_code',
4698
- blocker: 'Save action still throws TypeError.',
4699
- summary: 'New DOM trace proves the click reaches the method with an undefined id.',
4700
- evidenceHash: 'save-dom-trace',
4701
- artifactPaths: ['qa/save-before.log', 'qa/save-dom-trace.json']
4702
- }
4703
- ],
4704
- current: {
4705
- lane: 'repair',
4706
- stepType: 'repair',
4707
- outcome: 'needs_repair',
4708
- failureClass: 'product_code',
4709
- blocker: 'Save action still throws TypeError.',
4710
- summary: 'New DOM trace proves the click reaches the method with an undefined id.',
4711
- evidenceHash: 'save-dom-trace',
4712
- artifactPaths: ['qa/save-before.log', 'qa/save-dom-trace.json']
4713
- },
4714
- maxSameFailureRepeats
4715
- });
4716
- cases.push({
4717
- caseId: 'material_evidence_resets_loop_budget',
4718
- surface,
4719
- pass: materialPolicy.action === 'continue'
4720
- && materialPolicy.materialEvidence === true
4721
- && materialPolicy.loopBudgetShouldReset === true,
4722
- action: materialPolicy.action,
4723
- reason: materialPolicy.reason,
4724
- recoveryClass: materialPolicy.recoveryPlan.recoveryClass,
4725
- dispatchAction: materialPolicy.recoveryAction.mode,
4726
- safeAutoDispatch: false,
4727
- expectedSafeAutoDispatch: false,
4728
- productRepairAllowed: materialPolicy.recoveryAction.productRepairAllowed,
4729
- loopBudgetShouldReset: materialPolicy.loopBudgetShouldReset,
4730
- materialEvidence: materialPolicy.materialEvidence,
4731
- evidenceStrength: materialPolicy.evidenceStrength,
4732
- details: { evidenceSignals: materialPolicy.evidenceSignals }
4733
- });
4734
- const productPlan = buildResolveIOAIManagerRecoveryPlan({
4735
- action: 'continue',
4736
- reason: 'business proof still failing',
4737
- failureClass: 'product_code',
4738
- lane: 'repair',
4739
- stepType: 'repair',
4740
- blocker: 'Save action still throws TypeError.',
4741
- productRepairFailure: true
4742
- });
4743
- const productDirective = buildReplayDirectiveFromPlan({
4744
- surface,
4745
- plan: productPlan,
4746
- current: {
4747
- lane: 'repair',
4748
- stepType: 'repair',
4749
- outcome: 'needs_repair',
4750
- failureClass: 'product_code',
4751
- blocker: 'Save action still throws TypeError.',
4752
- evidenceHash: 'save-product-repair'
4753
- }
4754
- });
4755
- const productSafe = isResolveIOAIManagerSafeAutoDispatch({
4756
- dispatchAction: productDirective.dispatchAction,
4757
- directive: productDirective,
4758
- includeProductRepair: input.includeProductRepair === true
4759
- });
4760
- cases.push({
4761
- caseId: 'product_repair_requires_explicit_operator_policy',
4762
- surface,
4763
- pass: productPlan.recoveryClass === 'product_code_repair'
4764
- && productDirective.dispatchAction === 'run_targeted_product_repair'
4765
- && productSafe === false,
4766
- action: 'continue',
4767
- reason: 'business proof still failing',
4768
- recoveryClass: productPlan.recoveryClass,
4769
- dispatchAction: productDirective.dispatchAction,
4770
- safeAutoDispatch: productSafe,
4771
- expectedSafeAutoDispatch: false,
4772
- productRepairAllowed: productDirective.canRunProductRepair,
4773
- loopBudgetShouldReset: false,
4774
- materialEvidence: false,
4775
- evidenceStrength: 'none',
4776
- details: { phase: productDirective.phase, allowed: productDirective.allowed }
4777
- });
4778
- const duplicateReleasePolicy = buildResolveIOAIManagerHotfixFirstReleasePolicy({
4779
- surface,
4780
- deployFingerprint: `${surface}-artifact-sha`,
4781
- lastDeployFingerprint: `${surface}-artifact-sha`,
4782
- deployStatus: 'completed',
4783
- publishStatus: 'published'
4784
- });
4785
- cases.push({
4786
- caseId: 'duplicate_release_fingerprint_blocks_full_deploy',
4787
- surface,
4788
- pass: duplicateReleasePolicy.recommendedAction === 'block_duplicate_deploy'
4789
- && duplicateReleasePolicy.duplicateDeployBlocked === true
4790
- && duplicateReleasePolicy.fullDeployAllowed === false,
4791
- action: duplicateReleasePolicy.recommendedAction,
4792
- reason: duplicateReleasePolicy.reason,
4793
- recoveryClass: 'release_repair',
4794
- dispatchAction: 'run_release_repair',
4795
- safeAutoDispatch: includeReleaseRepair,
4796
- expectedSafeAutoDispatch: includeReleaseRepair,
4797
- productRepairAllowed: false,
4798
- loopBudgetShouldReset: false,
4799
- materialEvidence: false,
4800
- evidenceStrength: 'none',
4801
- hotfixFirst: true,
4802
- fullDeployAllowed: duplicateReleasePolicy.fullDeployAllowed,
4803
- details: { releasePolicy: duplicateReleasePolicy }
4804
- });
4805
- return cases;
4806
- }