@resolveio/server-lib 22.3.150 → 22.3.152

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 +337 -0
  200. package/methods/ai-terminal.js +23193 -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 +33 -0
  462. package/util/ai-run-evidence-adapters.js +838 -0
  463. package/util/ai-run-evidence-adapters.js.map +1 -0
  464. package/util/ai-run-evidence-dashboard.d.ts +84 -0
  465. package/util/ai-run-evidence-dashboard.js +336 -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 +854 -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 +731 -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 +112 -0
  477. package/util/ai-runner-manager-autopilot.js +313 -0
  478. package/util/ai-runner-manager-autopilot.js.map +1 -0
  479. package/util/ai-runner-manager-policy.d.ts +403 -0
  480. package/util/ai-runner-manager-policy.js +1763 -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 +214 -0
  489. package/util/aicoder-runner-v6.js +507 -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 +451 -0
  522. package/util/support-runner-v5.js +1680 -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 -23524
  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 -684
  690. package/src/util/ai-run-evidence-dashboard.ts +0 -313
  691. package/src/util/ai-run-evidence-eval.ts +0 -885
  692. package/src/util/ai-run-evidence.ts +0 -1058
  693. package/src/util/ai-runner-artifacts.ts +0 -586
  694. package/src/util/ai-runner-manager-autopilot.ts +0 -434
  695. package/src/util/ai-runner-manager-policy.ts +0 -2733
  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 -875
  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 -2167
  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 -2968
  723. package/tests/ai-manager-autopilot-snapshot.test.ts +0 -177
  724. package/tests/ai-manager-recovery-checkpoint.test.ts +0 -595
  725. package/tests/ai-run-eval.test.ts +0 -88
  726. package/tests/ai-run-evidence.test.ts +0 -348
  727. package/tests/ai-runner-contract.test.ts +0 -488
  728. package/tests/aicoder-runner-v6.test.ts +0 -298
  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 -488
  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,2167 +0,0 @@
1
- import {
2
- buildResolveIOAIManagerRecoveryCheckpoint,
3
- buildResolveIOAIManagerRecoveryActionPacket,
4
- buildResolveIOAIManagerRecoveryEvidenceProbe,
5
- buildResolveIOAIManagerRecoveryPlan,
6
- decideResolveIOAIManagerPolicy,
7
- hashResolveIOAIManagerEvidence,
8
- ResolveIOAIManagerRecoveryCheckpoint,
9
- ResolveIOAIManagerRecoveryActionPacket,
10
- ResolveIOAIManagerRecoveryActionDispatchRecord,
11
- ResolveIOAIManagerRecoveryExecutionDirective,
12
- ResolveIOAIManagerRecoveryEvidenceProbe,
13
- ResolveIOAIManagerRecoveryPlan,
14
- ResolveIOAIManagerRecoveryPlanInput
15
- } from './ai-runner-manager-policy';
16
-
17
- export type ResolveIOSupportV5StepType =
18
- | 'diagnosis_gate'
19
- | 'reproduction_probe'
20
- | 'issue_class_probe'
21
- | 'business_proof'
22
- | 'compile_check'
23
- | 'startup_check'
24
- | 'live_seed'
25
- | 'auth_bootstrap'
26
- | 'route_probe'
27
- | 'qa_row'
28
- | 'build_repair'
29
- | 'qa_retest'
30
- | 'pr_review'
31
- | 'artifact_package'
32
- | 'cleanup';
33
-
34
- export type ResolveIOSupportV5Outcome =
35
- | 'pass'
36
- | 'needs_repair'
37
- | 'retry_same_step'
38
- | 'park_manual'
39
- | 'budget_stop'
40
- | 'infra_retry'
41
- | 'ready_for_merge';
42
-
43
- export type ResolveIOSupportV5Lane = 'build' | 'qa' | 'review' | 'supervisor';
44
-
45
- export type ResolveIOSupportIssueClass =
46
- | 'no_op_submit'
47
- | 'missing_wrong_data'
48
- | 'filter_query_mismatch'
49
- | 'invoice_pdf_export'
50
- | 'upload_import'
51
- | 'route_auth_hydration'
52
- | 'slow_query_performance';
53
-
54
- export type ResolveIOSupportDiagnosisGateStatus = 'missing' | 'incomplete' | 'blocked' | 'passed';
55
-
56
- export type ResolveIOSupportV5FailureClass =
57
- | 'diagnosis'
58
- | 'infra'
59
- | 'compile'
60
- | 'route'
61
- | 'business'
62
- | 'product_code'
63
- | 'qa_evidence'
64
- | 'release'
65
- | 'unknown';
66
-
67
- export interface ResolveIOSupportDiagnosisIssueCase {
68
- customer_complaint: string;
69
- expected_result: string;
70
- observed_result: string;
71
- route_module: string;
72
- account_customer_context: string;
73
- reproduction_status: 'reproduced' | 'blocked' | 'classified';
74
- reproduction_blocker?: string;
75
- }
76
-
77
- export interface ResolveIOSupportDiagnosisHypothesis {
78
- statement: string;
79
- falsifiable_test: string;
80
- evidence: string[];
81
- }
82
-
83
- export interface ResolveIOSupportDiagnosisFailingPath {
84
- frontend?: string;
85
- backend?: string;
86
- shared_library?: string;
87
- data_query?: string;
88
- description: string;
89
- }
90
-
91
- export interface ResolveIOSupportDiagnosisBusinessProofContract {
92
- issue_class: ResolveIOSupportIssueClass;
93
- setup_state: string;
94
- action_under_test: string;
95
- expected_business_state_change: string;
96
- prohibited_false_pass: string;
97
- proof_artifacts: string[];
98
- data_or_dom_assertion: string;
99
- }
100
-
101
- export interface ResolveIOSupportDiagnosisProofPlan {
102
- before: string;
103
- before_state_unavailable_reason?: string;
104
- action: string;
105
- after: string;
106
- business_assertion: string;
107
- route?: string;
108
- data_assertion?: string;
109
- artifact_expectation?: string;
110
- business_proof_contract?: ResolveIOSupportDiagnosisBusinessProofContract;
111
- }
112
-
113
- export interface ResolveIOSupportDiagnosisHint {
114
- id?: string;
115
- ticketNumber?: string;
116
- title?: string;
117
- outcome?: string;
118
- issueClass?: string;
119
- ownerFiles?: string[];
120
- commitSha?: string;
121
- commitMessage?: string;
122
- reason?: string;
123
- }
124
-
125
- export interface ResolveIOSupportDiagnosisEvidence {
126
- type: 'ticket' | 'browser' | 'mongo' | 'log' | 'code' | 'commit' | 'qa' | 'other';
127
- summary: string;
128
- artifactPath?: string;
129
- }
130
-
131
- export interface ResolveIOSupportDiagnosisGate {
132
- issue_case: ResolveIOSupportDiagnosisIssueCase;
133
- issue_class: ResolveIOSupportIssueClass;
134
- accepted_hypothesis: ResolveIOSupportDiagnosisHypothesis;
135
- rejected_alternatives: string[];
136
- failing_path: ResolveIOSupportDiagnosisFailingPath;
137
- owner_files: string[];
138
- proof_plan: ResolveIOSupportDiagnosisProofPlan;
139
- similar_tickets?: ResolveIOSupportDiagnosisHint[];
140
- similar_commits?: ResolveIOSupportDiagnosisHint[];
141
- evidence: ResolveIOSupportDiagnosisEvidence[];
142
- status: ResolveIOSupportDiagnosisGateStatus;
143
- updatedAt?: string;
144
- }
145
-
146
- export interface ResolveIOSupportDiagnosisGateValidation {
147
- valid: boolean;
148
- status: ResolveIOSupportDiagnosisGateStatus;
149
- blockers: string[];
150
- normalized?: ResolveIOSupportDiagnosisGate;
151
- }
152
-
153
- export interface ResolveIOSupportIssueClassProbe {
154
- issue_class: ResolveIOSupportIssueClass;
155
- probe_type: ResolveIOSupportV5StepType;
156
- objective: string;
157
- route?: string;
158
- action: string;
159
- expected_evidence: string;
160
- blocks_acceptance_without_business_assertion: boolean;
161
- }
162
-
163
- export interface ResolveIOSupportV5RepeatStopInput {
164
- history: ResolveIOSupportV5StepRecord[];
165
- failureClass?: ResolveIOSupportV5FailureClass | string;
166
- blocker?: string;
167
- evidence?: any;
168
- evidenceHash?: string;
169
- limit?: number;
170
- ignoreInfra?: boolean;
171
- }
172
-
173
- export interface ResolveIOSupportV5RepeatStopDecision {
174
- shouldStop: boolean;
175
- repeatedCount: number;
176
- failureClass: string;
177
- blockerFingerprint: string;
178
- evidenceHash: string;
179
- reason: string;
180
- }
181
-
182
- export type ResolveIOSupportV5RepairGateAction =
183
- | 'diagnose_only'
184
- | 'infra_repair_only'
185
- | 'allow_product_repair'
186
- | 'reject_out_of_scope'
187
- | 'park_repeated_failure';
188
-
189
- export interface ResolveIOSupportV5RepairGateInput {
190
- diagnosisGate?: any;
191
- activeStepType?: ResolveIOSupportV5StepType | string;
192
- changedFiles?: any;
193
- failureClass?: ResolveIOSupportV5FailureClass | string;
194
- blocker?: string;
195
- evidence?: any;
196
- evidenceHash?: string;
197
- history?: ResolveIOSupportV5StepRecord[];
198
- maxOwnerFiles?: number;
199
- maxRepeatedNoProgress?: number;
200
- allowTestsOutsideOwnerFiles?: boolean;
201
- }
202
-
203
- export interface ResolveIOSupportV5RepairGateDecision {
204
- action: ResolveIOSupportV5RepairGateAction;
205
- canEditProductCode: boolean;
206
- blockers: string[];
207
- ownerFiles: string[];
208
- issueClass?: ResolveIOSupportIssueClass;
209
- proofPlan?: ResolveIOSupportDiagnosisProofPlan;
210
- outsideOwnerFiles: string[];
211
- repeatedFailure?: ResolveIOSupportV5RepeatStopDecision;
212
- diagnosisValidation: ResolveIOSupportDiagnosisGateValidation;
213
- recoveryPlan: ResolveIOAIManagerRecoveryPlan;
214
- recoveryCheckpoint: ResolveIOAIManagerRecoveryCheckpoint;
215
- recoveryEvidenceProbe: ResolveIOAIManagerRecoveryEvidenceProbe;
216
- recoveryAction: ResolveIOAIManagerRecoveryActionPacket;
217
- }
218
-
219
- export type ResolveIOSupportV5MicrotaskStatus =
220
- | 'pending'
221
- | 'in_progress'
222
- | 'pass'
223
- | 'needs_repair'
224
- | 'blocked'
225
- | 'parked';
226
-
227
- export type ResolveIOSupportV5MicrotaskType =
228
- | ResolveIOSupportV5StepType
229
- | 'planning'
230
- | 'scope_slice'
231
- | 'product_repair'
232
- | 'runner_repair';
233
-
234
- export interface ResolveIOSupportV5PromptBudget {
235
- initialPlannerCap: number;
236
- buildMicrotaskCap: number;
237
- buildMicrotaskHardCap: number;
238
- qaMicrotaskCap: number;
239
- qaMicrotaskHardCap: number;
240
- repairMicrotaskCap: number;
241
- repairMicrotaskHardCap: number;
242
- }
243
-
244
- export interface ResolveIOSupportV5Microtask {
245
- microtaskId: string;
246
- lane: ResolveIOSupportV5Lane;
247
- type: ResolveIOSupportV5MicrotaskType;
248
- status: ResolveIOSupportV5MicrotaskStatus;
249
- objective: string;
250
- targetFiles: string[];
251
- contextRefs: string[];
252
- selfGate: string;
253
- acceptanceProof: string;
254
- threadKey: string;
255
- promptTokenEstimate?: number;
256
- attempts: number;
257
- dependsOn: string[];
258
- parentScopeId?: string;
259
- blocker?: string;
260
- createdAt: string;
261
- updatedAt: string;
262
- }
263
-
264
- export interface ResolveIOSupportV5UsageSection {
265
- name: string;
266
- tokenEstimate: number;
267
- }
268
-
269
- export interface ResolveIOSupportV5MicrotaskUsage {
270
- microtaskId: string;
271
- lane: ResolveIOSupportV5Lane;
272
- model?: string;
273
- threadKey?: string;
274
- reuseThread: boolean;
275
- freshReason?: string;
276
- promptTokenEstimate: number;
277
- promptSections: ResolveIOSupportV5UsageSection[];
278
- actualInputTokens?: number;
279
- actualCachedInputTokens?: number;
280
- actualOutputTokens?: number;
281
- durationMs?: number;
282
- outcome?: ResolveIOSupportV5Outcome | ResolveIOSupportV5MicrotaskStatus;
283
- recordedAt: string;
284
- }
285
-
286
- export interface ResolveIOSupportV5Budget {
287
- maxPromptTokensPerNonInitialStep: number;
288
- maxLoopsPerTicket: number;
289
- maxRepeatedNoProgress: number;
290
- maxRuntimeMinutesPerLoop: number;
291
- totalPromptTokenEstimate: number;
292
- totalRuntimeMs: number;
293
- loopCount: number;
294
- }
295
-
296
- export interface ResolveIOSupportV5LaneMemory {
297
- lane: ResolveIOSupportV5Lane;
298
- model: string;
299
- threadKey: string;
300
- scopeSummary: string;
301
- activeBlocker: string;
302
- activeQaRow?: {
303
- index?: number;
304
- workflow?: string;
305
- route?: string;
306
- assertion?: string;
307
- status?: string;
308
- };
309
- changedFiles: string[];
310
- artifactPaths: string[];
311
- latestPromptTokenEstimate?: number;
312
- updatedAt: string;
313
- }
314
-
315
- export interface ResolveIOSupportV5FailureFingerprint {
316
- stepType: ResolveIOSupportV5StepType;
317
- failureClass: string;
318
- blockerFingerprint: string;
319
- evidenceHash: string;
320
- recordedAt: string;
321
- }
322
-
323
- export interface ResolveIOSupportV5SupervisorState {
324
- version: 'v5';
325
- status: 'active' | 'parked' | 'complete';
326
- currentGoal: string;
327
- approvedScope: string;
328
- prBranch: string;
329
- activeStep: ResolveIOSupportV5StepType;
330
- activeBlocker: string;
331
- lastGoodCheckpoint: string;
332
- currentQaRow?: ResolveIOSupportV5LaneMemory['activeQaRow'];
333
- processLease?: {
334
- runId?: string;
335
- token?: string;
336
- generation?: number;
337
- workspace?: string;
338
- lane?: string;
339
- };
340
- artifactLinks: string[];
341
- noEmailUnlessApproved: boolean;
342
- updatedAt: string;
343
- }
344
-
345
- export interface ResolveIOSupportV5StepRecord {
346
- microtaskId?: string;
347
- stepType: ResolveIOSupportV5StepType;
348
- outcome: ResolveIOSupportV5Outcome;
349
- lane: ResolveIOSupportV5Lane;
350
- model?: string;
351
- threadKey?: string;
352
- promptTokenEstimate?: number;
353
- runtimeMs?: number;
354
- summary: string;
355
- blocker?: string;
356
- changedFiles?: string[];
357
- artifactPaths?: string[];
358
- diagnosisGate?: ResolveIOSupportDiagnosisGate;
359
- failureClass?: ResolveIOSupportV5FailureClass | string;
360
- blockerFingerprint?: string;
361
- evidenceHash?: string;
362
- recordedAt: string;
363
- }
364
-
365
- export interface ResolveIOSupportV5RunnerIncident {
366
- incidentClass: string;
367
- summary: string;
368
- stepType?: ResolveIOSupportV5StepType;
369
- blockerFingerprint?: string;
370
- artifactPaths?: string[];
371
- recordedAt: string;
372
- }
373
-
374
- export interface ResolveIOSupportV5StateBundle {
375
- supportWorkflowVersion: 'v5';
376
- supportV5SupervisorState: ResolveIOSupportV5SupervisorState;
377
- supportV5DiagnosisGate?: ResolveIOSupportDiagnosisGate;
378
- supportV5LaneMemory: {
379
- build: ResolveIOSupportV5LaneMemory;
380
- qa: ResolveIOSupportV5LaneMemory;
381
- };
382
- supportV5StepHistory: ResolveIOSupportV5StepRecord[];
383
- supportV5Budget: ResolveIOSupportV5Budget;
384
- supportV5RunnerIncidents: ResolveIOSupportV5RunnerIncident[];
385
- supportV5MicrotaskLedger: ResolveIOSupportV5Microtask[];
386
- supportV5ActiveMicrotaskId?: string;
387
- supportV5ScopeDigest?: string;
388
- supportV5MicrotaskUsageHistory: ResolveIOSupportV5MicrotaskUsage[];
389
- supportV5FailureFingerprints?: ResolveIOSupportV5FailureFingerprint[];
390
- supportV5RecoveryPlan?: ResolveIOAIManagerRecoveryPlan;
391
- supportV5RecoveryCheckpoint?: ResolveIOAIManagerRecoveryCheckpoint;
392
- supportV5RecoveryEvidenceProbe?: ResolveIOAIManagerRecoveryEvidenceProbe;
393
- supportV5RecoveryAction?: ResolveIOAIManagerRecoveryActionPacket;
394
- supportV5RecoveryDispatchHistory?: ResolveIOAIManagerRecoveryActionDispatchRecord[];
395
- supportV5RecoveryDirective?: ResolveIOAIManagerRecoveryExecutionDirective;
396
- }
397
-
398
- export interface ResolveIOSupportV5InitializeInput {
399
- jobId: string;
400
- ticketId?: string;
401
- ticketNumber?: string;
402
- title?: string;
403
- description?: string;
404
- approvedScopeRequirements?: string[];
405
- approvedScopeHours?: number | null;
406
- prBranch?: string;
407
- buildThreadKey?: string;
408
- qaThreadKey?: string;
409
- processLease?: ResolveIOSupportV5SupervisorState['processLease'];
410
- now?: Date | string;
411
- existing?: Partial<ResolveIOSupportV5StateBundle>;
412
- }
413
-
414
- export interface ResolveIOSupportV5StepInput {
415
- microtaskId?: string;
416
- stepType: ResolveIOSupportV5StepType;
417
- outcome: ResolveIOSupportV5Outcome;
418
- lane: ResolveIOSupportV5Lane;
419
- model?: string;
420
- threadKey?: string;
421
- promptTokenEstimate?: number;
422
- runtimeMs?: number;
423
- summary?: string;
424
- blocker?: string;
425
- changedFiles?: string[];
426
- artifactPaths?: string[];
427
- diagnosisGate?: ResolveIOSupportDiagnosisGate;
428
- failureClass?: ResolveIOSupportV5FailureClass | string;
429
- evidenceHash?: string;
430
- activeQaRow?: ResolveIOSupportV5LaneMemory['activeQaRow'];
431
- now?: Date | string;
432
- }
433
-
434
- export interface ResolveIOSupportV5ContinuationDecision {
435
- action: 'continue' | 'park';
436
- reason: string;
437
- nextStep: ResolveIOSupportV5StepType;
438
- repeatedNoProgressCount: number;
439
- budgetExceeded: boolean;
440
- recoveryPlan: ResolveIOAIManagerRecoveryPlan;
441
- recoveryCheckpoint: ResolveIOAIManagerRecoveryCheckpoint;
442
- recoveryEvidenceProbe: ResolveIOAIManagerRecoveryEvidenceProbe;
443
- recoveryAction: ResolveIOAIManagerRecoveryActionPacket;
444
- }
445
-
446
- function isoNow(value?: Date | string): string {
447
- if (value instanceof Date) {
448
- return value.toISOString();
449
- }
450
- const parsed = value ? new Date(value) : new Date();
451
- if (Number.isFinite(parsed.getTime())) {
452
- return parsed.toISOString();
453
- }
454
- return new Date().toISOString();
455
- }
456
-
457
- function cleanText(value: any, max = 2000): string {
458
- return String(value || '').replace(/\s+/g, ' ').trim().slice(0, max);
459
- }
460
-
461
- function cleanList(values: any, limit = 20, max = 500): string[] {
462
- if (!Array.isArray(values)) {
463
- return [];
464
- }
465
- const result: string[] = [];
466
- for (const value of values) {
467
- const normalized = cleanText(value, max);
468
- if (normalized && !result.includes(normalized)) {
469
- result.push(normalized);
470
- }
471
- if (result.length >= limit) {
472
- break;
473
- }
474
- }
475
- return result;
476
- }
477
-
478
- function cleanObject(value: any): Record<string, any> {
479
- return value && typeof value === 'object' && !Array.isArray(value) ? value : {};
480
- }
481
-
482
- function pickText(source: Record<string, any>, fields: string[], max = 1000): string {
483
- for (const field of fields) {
484
- const normalized = cleanText(source?.[field], max);
485
- if (normalized) {
486
- return normalized;
487
- }
488
- }
489
- return '';
490
- }
491
-
492
- function normalizeIssueClass(value: any): ResolveIOSupportIssueClass | '' {
493
- const normalized = cleanText(value, 80)
494
- .toLowerCase()
495
- .replace(/[\s-]+/g, '_');
496
- const aliases: Record<string, ResolveIOSupportIssueClass> = {
497
- no_op: 'no_op_submit',
498
- no_op_submit: 'no_op_submit',
499
- submit_noop: 'no_op_submit',
500
- missing_data: 'missing_wrong_data',
501
- wrong_data: 'missing_wrong_data',
502
- missing_wrong_data: 'missing_wrong_data',
503
- filter_mismatch: 'filter_query_mismatch',
504
- query_mismatch: 'filter_query_mismatch',
505
- filter_query_mismatch: 'filter_query_mismatch',
506
- invoice_pdf_export: 'invoice_pdf_export',
507
- pdf_export: 'invoice_pdf_export',
508
- export: 'invoice_pdf_export',
509
- upload: 'upload_import',
510
- import: 'upload_import',
511
- upload_import: 'upload_import',
512
- route_auth: 'route_auth_hydration',
513
- auth_hydration: 'route_auth_hydration',
514
- route_auth_hydration: 'route_auth_hydration',
515
- slow_query: 'slow_query_performance',
516
- performance: 'slow_query_performance',
517
- slow_query_performance: 'slow_query_performance'
518
- };
519
- return aliases[normalized] || '';
520
- }
521
-
522
- function normalizeReproductionStatus(value: any): ResolveIOSupportDiagnosisIssueCase['reproduction_status'] {
523
- const normalized = cleanText(value, 80).toLowerCase();
524
- if (/blocked|unable|cannot/.test(normalized)) {
525
- return 'blocked';
526
- }
527
- if (/classif|triag|inferred/.test(normalized)) {
528
- return 'classified';
529
- }
530
- return 'reproduced';
531
- }
532
-
533
- function normalizeSupportDiagnosisEvidence(values: any): ResolveIOSupportDiagnosisEvidence[] {
534
- const allowed = new Set(['ticket', 'browser', 'mongo', 'log', 'code', 'commit', 'qa', 'other']);
535
- if (!Array.isArray(values)) {
536
- const summary = cleanText(values, 1200);
537
- return summary ? [{ type: 'other', summary }] : [];
538
- }
539
- const stringEvidence: ResolveIOSupportDiagnosisEvidence[] = values
540
- .filter((entry) => typeof entry === 'string')
541
- .map((entry) => ({
542
- type: 'other' as const,
543
- summary: cleanText(entry, 1200)
544
- }));
545
- const objectEvidence: ResolveIOSupportDiagnosisEvidence[] = values
546
- .filter((entry) => entry && typeof entry === 'object' && !Array.isArray(entry))
547
- .map((entry) => {
548
- const type = cleanText(entry.type, 80).toLowerCase();
549
- return {
550
- type: (allowed.has(type) ? type : 'other') as ResolveIOSupportDiagnosisEvidence['type'],
551
- summary: cleanText(entry.summary || entry.message || entry.evidence || entry.reason, 1200),
552
- artifactPath: cleanText(entry.artifactPath || entry.path || entry.file, 500)
553
- };
554
- });
555
- return stringEvidence.concat(objectEvidence)
556
- .filter((entry) => entry.summary)
557
- .slice(0, 20);
558
- }
559
-
560
- function normalizeSupportDiagnosisHints(values: any): ResolveIOSupportDiagnosisHint[] {
561
- return (Array.isArray(values) ? values : [])
562
- .map((entry) => {
563
- if (typeof entry === 'string') {
564
- return { reason: cleanText(entry, 500) };
565
- }
566
- const value = cleanObject(entry);
567
- return {
568
- id: cleanText(value.id || value._id, 160),
569
- ticketNumber: cleanText(value.ticketNumber || value.ticket_number || value.sourceTicketNumber, 80),
570
- title: cleanText(value.title || value.summary, 300),
571
- outcome: cleanText(value.outcome || value.status, 80),
572
- issueClass: cleanText(value.issueClass || value.issue_class, 80),
573
- ownerFiles: cleanList(value.ownerFiles || value.owner_files || value.files, 8, 240),
574
- commitSha: cleanText(value.commitSha || value.commit_sha, 80),
575
- commitMessage: cleanText(value.commitMessage || value.commit_message, 300),
576
- reason: cleanText(value.reason || value.matchReason || value.match_reason, 500)
577
- };
578
- })
579
- .filter((entry) => entry.id || entry.ticketNumber || entry.title || entry.reason || entry.commitSha)
580
- .slice(0, 8);
581
- }
582
-
583
- function normalizeSupportDiagnosisBusinessProofContract(value: any, issueClassHint: any): ResolveIOSupportDiagnosisBusinessProofContract | undefined {
584
- const source = cleanObject(value);
585
- if (!Object.keys(source).length) {
586
- return undefined;
587
- }
588
- const issueClass = normalizeIssueClass(source.issue_class || source.issueClass || issueClassHint)
589
- || normalizeIssueClass(issueClassHint)
590
- || 'missing_wrong_data';
591
- return {
592
- issue_class: issueClass,
593
- setup_state: pickText(source, ['setup_state', 'setupState', 'before', 'precondition'], 1000),
594
- action_under_test: pickText(source, ['action_under_test', 'actionUnderTest', 'action', 'steps'], 1000),
595
- expected_business_state_change: pickText(source, ['expected_business_state_change', 'expectedBusinessStateChange', 'expected_change', 'expectedChange', 'after'], 1000),
596
- prohibited_false_pass: pickText(source, ['prohibited_false_pass', 'prohibitedFalsePass', 'false_pass', 'falsePass'], 1000),
597
- proof_artifacts: cleanList(source.proof_artifacts || source.proofArtifacts || source.artifacts || source.artifact_paths || source.artifactPaths, 10, 500),
598
- data_or_dom_assertion: pickText(source, ['data_or_dom_assertion', 'dataOrDomAssertion', 'data_assertion', 'dataAssertion', 'dom_assertion', 'domAssertion', 'assertion'], 1000)
599
- };
600
- }
601
-
602
- function normalizeOwnerFilePath(value: any): string {
603
- return cleanText(value, 500)
604
- .replace(/\\/g, '/')
605
- .replace(/^\.\/+/, '')
606
- .replace(/^\/+/, '')
607
- .replace(/\s+$/g, '');
608
- }
609
-
610
- function ownerFileLooksBroad(value: string): boolean {
611
- const normalized = normalizeOwnerFilePath(value);
612
- return !normalized
613
- || normalized.includes('*')
614
- || normalized.endsWith('/')
615
- || !/\.[a-z0-9]+$/i.test(normalized)
616
- || /^(\.|src|server|angular|client|app|lib|packages?)$/i.test(normalized)
617
- || /(^|\/)(node_modules|dist|build|coverage|\.git)(\/|$)/i.test(normalized);
618
- }
619
-
620
- function proofPlanLooksRouteOnly(proofPlan: ResolveIOSupportDiagnosisProofPlan): boolean {
621
- const assertionText = cleanText([
622
- proofPlan.business_assertion,
623
- proofPlan.action,
624
- proofPlan.after,
625
- proofPlan.data_assertion,
626
- proofPlan.artifact_expectation
627
- ].filter(Boolean).join(' '), 3000).toLowerCase();
628
- if (!assertionText) {
629
- return false;
630
- }
631
- const routeOnlySignal = /\b(route|page|screen|dashboard|url|component|shell)\b/.test(assertionText)
632
- && /\b(loads?|loaded|renders?|rendered|opens?|opened|visible|visibility|hydrates?|hydrated|screenshot)\b/.test(assertionText);
633
- const businessSignal = /\b(save|saved|persist|persisted|create|created|update|updated|delete|deleted|filter|filtered|exclude|excluded|include|included|row|rows|record|records|count|counts|total|totals|value|values|data|mongo|query|result|results|invoice|pdf|export|download|upload|import|dropdown|selection|selected|form|submit|submitted|validation|error message|customer|account|user|permission|auth|control|button|status|calculation|performance|duration|latency)\b/.test(assertionText);
634
- return routeOnlySignal && !businessSignal;
635
- }
636
-
637
- export function normalizeResolveIOSupportDiagnosisGate(value: any, now?: Date | string): ResolveIOSupportDiagnosisGate | undefined {
638
- const source = cleanObject(value);
639
- if (!Object.keys(source).length) {
640
- return undefined;
641
- }
642
- const issueCaseSource = cleanObject(source.issue_case || source.issueCase);
643
- const hypothesisSource = cleanObject(source.accepted_hypothesis || source.acceptedHypothesis);
644
- const failingPathSource = cleanObject(source.failing_path || source.failingPath);
645
- const proofPlanSource = cleanObject(source.proof_plan || source.proofPlan);
646
- const issueClass = normalizeIssueClass(source.issue_class || source.issueClass);
647
- const businessProofContract = normalizeSupportDiagnosisBusinessProofContract(
648
- proofPlanSource.business_proof_contract || proofPlanSource.businessProofContract || source.business_proof_contract || source.businessProofContract,
649
- issueClass || source.issue_class || source.issueClass
650
- );
651
- const ownerFiles = cleanList(source.owner_files || source.ownerFiles, 20, 500)
652
- .map(normalizeOwnerFilePath)
653
- .filter(Boolean);
654
- const gate: ResolveIOSupportDiagnosisGate = {
655
- issue_case: {
656
- customer_complaint: pickText(issueCaseSource, ['customer_complaint', 'customerComplaint', 'complaint', 'request', 'summary'], 1200),
657
- expected_result: pickText(issueCaseSource, ['expected_result', 'expectedResult', 'expected'], 1000),
658
- observed_result: pickText(issueCaseSource, ['observed_result', 'observedResult', 'observed', 'actual'], 1000),
659
- route_module: pickText(issueCaseSource, ['route_module', 'routeModule', 'route', 'module', 'screen'], 500),
660
- account_customer_context: pickText(issueCaseSource, ['account_customer_context', 'accountCustomerContext', 'account', 'customer', 'user', 'context'], 800),
661
- reproduction_status: normalizeReproductionStatus(issueCaseSource.reproduction_status || issueCaseSource.reproductionStatus || source.reproduction_status),
662
- reproduction_blocker: pickText(issueCaseSource, ['reproduction_blocker', 'reproductionBlocker', 'blocked_reason', 'blockedReason'], 1000)
663
- },
664
- issue_class: issueClass || 'missing_wrong_data',
665
- accepted_hypothesis: {
666
- statement: pickText(hypothesisSource, ['statement', 'hypothesis', 'root_cause', 'rootCause', 'summary'], 1200)
667
- || (typeof source.accepted_hypothesis === 'string' ? cleanText(source.accepted_hypothesis, 1200) : ''),
668
- falsifiable_test: pickText(hypothesisSource, ['falsifiable_test', 'falsifiableTest', 'test', 'proof', 'falsifier'], 1000),
669
- evidence: cleanList(hypothesisSource.evidence || source.hypothesis_evidence || source.hypothesisEvidence, 10, 800)
670
- },
671
- rejected_alternatives: cleanList(source.rejected_alternatives || source.rejectedAlternatives, 10, 700),
672
- failing_path: {
673
- frontend: pickText(failingPathSource, ['frontend', 'frontend_path', 'frontendPath', 'eventPath'], 700),
674
- backend: pickText(failingPathSource, ['backend', 'backend_path', 'backendPath', 'methodPublicationPath'], 700),
675
- shared_library: pickText(failingPathSource, ['shared_library', 'sharedLibrary', 'library', 'lib'], 700),
676
- data_query: pickText(failingPathSource, ['data_query', 'dataQuery', 'query'], 700),
677
- description: pickText(failingPathSource, ['description', 'path', 'summary'], 1200) || cleanText(source.failing_path, 1200)
678
- },
679
- owner_files: ownerFiles,
680
- proof_plan: {
681
- before: pickText(proofPlanSource, ['before', 'before_state', 'beforeState', 'precondition'], 1000),
682
- before_state_unavailable_reason: pickText(proofPlanSource, ['before_state_unavailable_reason', 'beforeStateUnavailableReason', 'before_unavailable_reason'], 1000),
683
- action: pickText(proofPlanSource, ['action', 'browser_action', 'browserAction', 'steps'], 1000),
684
- after: pickText(proofPlanSource, ['after', 'after_state', 'afterState', 'expected_after'], 1000),
685
- business_assertion: pickText(proofPlanSource, ['business_assertion', 'businessAssertion', 'assertion'], 1000),
686
- route: pickText(proofPlanSource, ['route', 'url'], 500),
687
- data_assertion: pickText(proofPlanSource, ['data_assertion', 'dataAssertion', 'mongo_delta', 'mongoDelta'], 1000),
688
- artifact_expectation: pickText(proofPlanSource, ['artifact_expectation', 'artifactExpectation', 'artifact', 'screenshot'], 1000),
689
- business_proof_contract: businessProofContract
690
- },
691
- similar_tickets: normalizeSupportDiagnosisHints(source.similar_tickets || source.similarTickets),
692
- similar_commits: normalizeSupportDiagnosisHints(source.similar_commits || source.similarCommits),
693
- evidence: normalizeSupportDiagnosisEvidence(source.evidence),
694
- status: (cleanText(source.status, 80).toLowerCase() as ResolveIOSupportDiagnosisGateStatus) || 'incomplete',
695
- updatedAt: isoNow(now || source.updatedAt || source.updated_at)
696
- };
697
- if (!['missing', 'incomplete', 'blocked', 'passed'].includes(gate.status)) {
698
- gate.status = 'incomplete';
699
- }
700
- return gate;
701
- }
702
-
703
- export function extractResolveIOSupportDiagnosisGateFromText(value: string, now?: Date | string): ResolveIOSupportDiagnosisGate | undefined {
704
- const text = String(value || '').trim();
705
- if (!text) {
706
- return undefined;
707
- }
708
- const candidates: string[] = [];
709
- const fenced = Array.from(text.matchAll(/```(?:json)?\s*([\s\S]*?)```/gi)).map((match) => match[1]);
710
- candidates.push(...fenced);
711
- const jsonBlock = text.match(/\{[\s\S]*\}/);
712
- if (jsonBlock) {
713
- candidates.push(jsonBlock[0]);
714
- }
715
- for (const candidate of candidates) {
716
- try {
717
- const parsed = JSON.parse(candidate);
718
- const wrapped = parsed?.support_diagnosis_gate || parsed?.supportDiagnosisGate || parsed?.diagnosis_gate || parsed?.diagnosisGate || parsed;
719
- const normalized = normalizeResolveIOSupportDiagnosisGate(wrapped, now);
720
- if (normalized) {
721
- return normalized;
722
- }
723
- }
724
- catch {
725
- // Continue trying less exact JSON candidates.
726
- }
727
- }
728
- return undefined;
729
- }
730
-
731
- export function validateResolveIOSupportDiagnosisGate(
732
- value: any,
733
- options: { maxOwnerFiles?: number } = {}
734
- ): ResolveIOSupportDiagnosisGateValidation {
735
- const normalized = normalizeResolveIOSupportDiagnosisGate(value);
736
- if (!normalized) {
737
- return { valid: false, status: 'missing', blockers: ['SupportDiagnosisGate is missing.'] };
738
- }
739
- const blockers: string[] = [];
740
- const maxOwnerFiles = Math.max(1, Number(options.maxOwnerFiles || 8) || 8);
741
- if (!normalized.issue_case.customer_complaint) {
742
- blockers.push('Diagnosis issue_case.customer_complaint is required.');
743
- }
744
- if (!normalized.issue_case.expected_result) {
745
- blockers.push('Diagnosis issue_case.expected_result is required.');
746
- }
747
- if (!normalized.issue_case.observed_result) {
748
- blockers.push('Diagnosis issue_case.observed_result is required.');
749
- }
750
- if (!normalized.issue_case.route_module) {
751
- blockers.push('Diagnosis issue_case.route_module is required.');
752
- }
753
- if (!normalized.issue_case.account_customer_context) {
754
- blockers.push('Diagnosis issue_case.account_customer_context is required.');
755
- }
756
- if (normalized.issue_case.reproduction_status === 'blocked' && !normalized.issue_case.reproduction_blocker) {
757
- blockers.push('Diagnosis blocked reproduction requires issue_case.reproduction_blocker.');
758
- }
759
- if (!normalizeIssueClass(normalized.issue_class)) {
760
- blockers.push('Diagnosis issue_class must be one of the supported issue-class probes.');
761
- }
762
- if (!normalized.accepted_hypothesis.statement) {
763
- blockers.push('Diagnosis accepted_hypothesis.statement is required.');
764
- }
765
- if (!normalized.accepted_hypothesis.falsifiable_test) {
766
- blockers.push('Diagnosis accepted_hypothesis.falsifiable_test is required.');
767
- }
768
- if (!normalized.accepted_hypothesis.evidence.length) {
769
- blockers.push('Diagnosis accepted_hypothesis.evidence must cite proof.');
770
- }
771
- if (!normalized.rejected_alternatives.length) {
772
- blockers.push('Diagnosis rejected_alternatives must include at least one rejected theory.');
773
- }
774
- if (!normalized.failing_path.description
775
- && !normalized.failing_path.frontend
776
- && !normalized.failing_path.backend
777
- && !normalized.failing_path.shared_library
778
- && !normalized.failing_path.data_query) {
779
- blockers.push('Diagnosis failing_path must identify frontend, backend, query, shared library, or path description.');
780
- }
781
- if (!normalized.owner_files.length) {
782
- blockers.push('Diagnosis owner_files must contain the small editable file set.');
783
- }
784
- if (normalized.owner_files.length > maxOwnerFiles) {
785
- blockers.push(`Diagnosis owner_files has ${normalized.owner_files.length} entries; maximum is ${maxOwnerFiles}.`);
786
- }
787
- const broadFiles = normalized.owner_files.filter(ownerFileLooksBroad);
788
- if (broadFiles.length) {
789
- blockers.push(`Diagnosis owner_files contains broad or unsafe path(s): ${broadFiles.join(', ')}.`);
790
- }
791
- if (!normalized.proof_plan.before && !normalized.proof_plan.before_state_unavailable_reason) {
792
- blockers.push('Diagnosis proof_plan.before is required unless proof_plan.before_state_unavailable_reason explains why before-state proof is impossible.');
793
- }
794
- if (!normalized.proof_plan.action) {
795
- blockers.push('Diagnosis proof_plan.action is required.');
796
- }
797
- if (!normalized.proof_plan.after) {
798
- blockers.push('Diagnosis proof_plan.after is required.');
799
- }
800
- if (!normalized.proof_plan.business_assertion) {
801
- blockers.push('Diagnosis proof_plan.business_assertion is required.');
802
- }
803
- if (proofPlanLooksRouteOnly(normalized.proof_plan)) {
804
- blockers.push('Diagnosis proof_plan cannot be route-load, screen-visible, or screenshot-only; it must name the business state/data/control change that proves the issue is fixed.');
805
- }
806
- const proofContract = normalized.proof_plan.business_proof_contract;
807
- if (!proofContract) {
808
- blockers.push('Diagnosis proof_plan.business_proof_contract is required.');
809
- }
810
- else {
811
- if (proofContract.issue_class !== normalized.issue_class) {
812
- blockers.push(`Diagnosis proof_plan.business_proof_contract.issue_class (${proofContract.issue_class}) must match diagnosis issue_class (${normalized.issue_class}).`);
813
- }
814
- if (!proofContract.setup_state) {
815
- blockers.push('Diagnosis proof_plan.business_proof_contract.setup_state is required.');
816
- }
817
- if (!proofContract.action_under_test) {
818
- blockers.push('Diagnosis proof_plan.business_proof_contract.action_under_test is required.');
819
- }
820
- if (!proofContract.expected_business_state_change) {
821
- blockers.push('Diagnosis proof_plan.business_proof_contract.expected_business_state_change is required.');
822
- }
823
- if (!proofContract.prohibited_false_pass) {
824
- blockers.push('Diagnosis proof_plan.business_proof_contract.prohibited_false_pass is required.');
825
- }
826
- if (!proofContract.proof_artifacts.length) {
827
- blockers.push('Diagnosis proof_plan.business_proof_contract.proof_artifacts must include at least one required artifact.');
828
- }
829
- if (!proofContract.data_or_dom_assertion) {
830
- blockers.push('Diagnosis proof_plan.business_proof_contract.data_or_dom_assertion is required.');
831
- }
832
- }
833
- if (!normalized.evidence.length) {
834
- blockers.push('Diagnosis evidence must include ticket/code/browser/log/Mongo proof.');
835
- }
836
- normalized.status = blockers.length ? 'incomplete' : 'passed';
837
- return {
838
- valid: blockers.length === 0,
839
- status: normalized.status,
840
- blockers,
841
- normalized
842
- };
843
- }
844
-
845
- export function buildResolveIOSupportIssueClassProbes(value: any): ResolveIOSupportIssueClassProbe[] {
846
- const validation = validateResolveIOSupportDiagnosisGate(value);
847
- const gate = validation.normalized || normalizeResolveIOSupportDiagnosisGate(value);
848
- if (!gate) {
849
- return [];
850
- }
851
- const route = gate.proof_plan.route || gate.issue_case.route_module;
852
- const proofContract = gate.proof_plan.business_proof_contract;
853
- const proof = proofContract?.expected_business_state_change || gate.proof_plan.business_assertion;
854
- const assertion = proofContract?.data_or_dom_assertion || gate.proof_plan.data_assertion || gate.proof_plan.after;
855
- const artifacts = proofContract?.proof_artifacts?.length
856
- ? ` Required artifacts: ${proofContract.proof_artifacts.join(', ')}.`
857
- : '';
858
- const common = {
859
- issue_class: gate.issue_class,
860
- probe_type: 'issue_class_probe' as ResolveIOSupportV5StepType,
861
- route,
862
- blocks_acceptance_without_business_assertion: true
863
- };
864
- const map: Record<ResolveIOSupportIssueClass, { action: string; expected: string }> = {
865
- no_op_submit: {
866
- action: `Submit the customer action on ${route || 'the affected screen'} and assert a persisted state change or explicit validation message.`,
867
- expected: proof || 'Before/action/after proof shows the submit is no longer a no-op.'
868
- },
869
- missing_wrong_data: {
870
- action: `Load the named record/list on ${route || 'the affected route'} and compare visible data to the expected persisted source.`,
871
- expected: proof || 'Visible data and persisted data match the customer expectation.'
872
- },
873
- filter_query_mismatch: {
874
- action: 'Apply the reported filter/query inputs and assert the returned rows/counts match the expected dataset.',
875
- expected: proof || 'Filter/query output contains the correct included rows and excludes the wrong rows.'
876
- },
877
- invoice_pdf_export: {
878
- action: 'Generate the invoice/PDF/export from the affected route and inspect the downloaded/generated artifact.',
879
- expected: proof || 'Generated artifact contains the expected customer-visible rows, totals, or fields.'
880
- },
881
- upload_import: {
882
- action: 'Run the upload/import workflow with a representative file and assert parsed plus persisted results.',
883
- expected: proof || 'Import shows a success result and persisted rows/counts changed as expected.'
884
- },
885
- route_auth_hydration: {
886
- action: 'Open the route as the affected user and assert authenticated hydration reaches the functional screen, not a shell.',
887
- expected: proof || 'Route hydrates with the required controls/data for the affected account.'
888
- },
889
- slow_query_performance: {
890
- action: 'Run the reported query/workflow with timing/log evidence before and after the fix.',
891
- expected: proof || 'Performance evidence shows the slow path improved without changing results.'
892
- }
893
- };
894
- const selected = map[gate.issue_class];
895
- return [{
896
- ...common,
897
- objective: `Issue-class probe for ${gate.issue_class}: ${gate.issue_case.customer_complaint}`,
898
- action: proofContract
899
- ? `${proofContract.action_under_test} ${selected.action}`
900
- : selected.action,
901
- expected_evidence: `${selected.expected}${assertion ? ` Assertion: ${assertion}.` : ''}${artifacts}`.trim()
902
- }];
903
- }
904
-
905
- export function hashResolveIOSupportV5Evidence(value: any): string {
906
- const raw = typeof value === 'string' ? value : JSON.stringify(value || {});
907
- const normalized = cleanText(raw, 8000)
908
- .toLowerCase()
909
- .replace(/[a-f0-9]{16,}/g, '<id>')
910
- .replace(/\b\d{2,}\b/g, '<n>');
911
- let hash = 0;
912
- for (let index = 0; index < normalized.length; index += 1) {
913
- hash = ((hash << 5) - hash + normalized.charCodeAt(index)) | 0;
914
- }
915
- return `ev-${Math.abs(hash).toString(36) || '0'}`;
916
- }
917
-
918
- export function decideResolveIOSupportV5RepeatedFailureStop(input: ResolveIOSupportV5RepeatStopInput): ResolveIOSupportV5RepeatStopDecision {
919
- const failureClass = cleanText(input.failureClass || 'unknown', 80).toLowerCase();
920
- const blockerFingerprint = fingerprintResolveIOSupportV5Blocker(input.blocker || '');
921
- const evidenceHash = cleanText(input.evidenceHash, 80) || hashResolveIOSupportV5Evidence(input.evidence || input.blocker || '');
922
- const limit = Math.max(1, Number(input.limit || 2) || 2);
923
- if (input.ignoreInfra !== false && /^(infra|compile)$/.test(failureClass)) {
924
- return {
925
- shouldStop: false,
926
- repeatedCount: 0,
927
- failureClass,
928
- blockerFingerprint,
929
- evidenceHash,
930
- reason: 'support_v5_infra_failures_do_not_count_as_product_repair_loops'
931
- };
932
- }
933
- const latestRecord = (input.history || [])[(input.history || []).length - 1];
934
- const managerDecision = decideResolveIOAIManagerPolicy({
935
- history: (input.history || []).map((entry) => ({
936
- outcome: entry.outcome,
937
- lane: entry.lane,
938
- stepType: entry.stepType,
939
- failureClass: entry.failureClass,
940
- blocker: entry.blocker || entry.summary,
941
- blockerFingerprint: entry.blockerFingerprint,
942
- evidenceHash: entry.evidenceHash,
943
- changedFiles: entry.changedFiles,
944
- artifactPaths: entry.artifactPaths,
945
- summary: entry.summary,
946
- recordedAt: entry.recordedAt
947
- })),
948
- current: {
949
- outcome: 'needs_repair',
950
- lane: latestRecord?.lane,
951
- stepType: latestRecord?.stepType,
952
- failureClass,
953
- blocker: input.blocker,
954
- blockerFingerprint,
955
- evidenceHash
956
- },
957
- maxSameFailureRepeats: limit,
958
- maxPingPongTransitions: 3,
959
- infraFailureClasses: input.ignoreInfra !== false ? ['infra', 'compile'] : []
960
- });
961
- if (managerDecision.action === 'retry_infra') {
962
- return {
963
- shouldStop: false,
964
- repeatedCount: 0,
965
- failureClass,
966
- blockerFingerprint,
967
- evidenceHash,
968
- reason: 'support_v5_infra_failures_do_not_count_as_product_repair_loops'
969
- };
970
- }
971
- if (managerDecision.action === 'park_ping_pong') {
972
- return {
973
- shouldStop: true,
974
- repeatedCount: managerDecision.pingPongCount,
975
- failureClass,
976
- blockerFingerprint,
977
- evidenceHash,
978
- reason: 'support_v5_ping_pong_failure_loop'
979
- };
980
- }
981
- if (managerDecision.action === 'park_repeated_failure' && managerDecision.newEvidence) {
982
- return {
983
- shouldStop: false,
984
- repeatedCount: managerDecision.sameFailureCount,
985
- failureClass,
986
- blockerFingerprint,
987
- evidenceHash,
988
- reason: 'support_v5_retry_allowed_changed_evidence_hash'
989
- };
990
- }
991
- if (managerDecision.action === 'park_repeated_failure') {
992
- return {
993
- shouldStop: true,
994
- repeatedCount: managerDecision.sameFailureCount,
995
- failureClass,
996
- blockerFingerprint,
997
- evidenceHash,
998
- reason: 'support_v5_same_failure_class_without_new_evidence'
999
- };
1000
- }
1001
- let repeatedCount = 0;
1002
- for (let index = (input.history || []).length - 1; index >= 0; index -= 1) {
1003
- const item = input.history[index];
1004
- if (item.outcome === 'pass' || item.outcome === 'ready_for_merge') {
1005
- break;
1006
- }
1007
- const itemFailureClass = cleanText(item.failureClass || 'unknown', 80).toLowerCase();
1008
- const itemBlockerFingerprint = cleanText(item.blockerFingerprint, 80)
1009
- || fingerprintResolveIOSupportV5Blocker(item.blocker || item.summary || '');
1010
- const itemEvidenceHash = cleanText(item.evidenceHash, 80)
1011
- || hashResolveIOSupportV5Evidence(item.artifactPaths || item.blocker || item.summary || '');
1012
- if (itemFailureClass !== failureClass || itemBlockerFingerprint !== blockerFingerprint || itemEvidenceHash !== evidenceHash) {
1013
- break;
1014
- }
1015
- repeatedCount += 1;
1016
- }
1017
- return {
1018
- shouldStop: repeatedCount >= limit,
1019
- repeatedCount,
1020
- failureClass,
1021
- blockerFingerprint,
1022
- evidenceHash,
1023
- reason: repeatedCount >= limit
1024
- ? 'support_v5_same_failure_class_without_new_evidence'
1025
- : 'support_v5_retry_allowed_new_or_below_repeat_limit'
1026
- };
1027
- }
1028
-
1029
- export function changedFilesOutsideResolveIOSupportDiagnosisOwnerFiles(
1030
- diagnosisGate: any,
1031
- changedFiles: any,
1032
- options: { allowTests?: boolean } = {}
1033
- ): string[] {
1034
- const validation = validateResolveIOSupportDiagnosisGate(diagnosisGate);
1035
- if (!validation.valid || !validation.normalized) {
1036
- return cleanList(changedFiles, 80, 500);
1037
- }
1038
- const owners = new Set(validation.normalized.owner_files.map(normalizeOwnerFilePath));
1039
- return cleanList(changedFiles, 120, 500)
1040
- .map(normalizeOwnerFilePath)
1041
- .filter((filePath) => {
1042
- if (!filePath) {
1043
- return false;
1044
- }
1045
- if (owners.has(filePath)) {
1046
- return false;
1047
- }
1048
- if (options.allowTests && /(^|\/)(tests?|spec|__tests__)(\/|$)|\.(?:spec|test)\.[jt]sx?$/i.test(filePath)) {
1049
- return false;
1050
- }
1051
- return true;
1052
- });
1053
- }
1054
-
1055
- export function decideResolveIOSupportV5RepairGate(input: ResolveIOSupportV5RepairGateInput): ResolveIOSupportV5RepairGateDecision {
1056
- const activeStepType = cleanText(input.activeStepType, 80);
1057
- const failureClass = cleanText(input.failureClass, 80).toLowerCase();
1058
- const diagnosisValidation = validateResolveIOSupportDiagnosisGate(input.diagnosisGate, {
1059
- maxOwnerFiles: input.maxOwnerFiles
1060
- });
1061
- const ownerFiles = diagnosisValidation.normalized?.owner_files || [];
1062
- const outsideOwnerFiles = changedFilesOutsideResolveIOSupportDiagnosisOwnerFiles(
1063
- diagnosisValidation.normalized || input.diagnosisGate,
1064
- input.changedFiles,
1065
- { allowTests: input.allowTestsOutsideOwnerFiles === true }
1066
- );
1067
- const repeatedFailure = input.history?.length ? decideResolveIOSupportV5RepeatedFailureStop({
1068
- history: input.history,
1069
- failureClass,
1070
- blocker: input.blocker,
1071
- evidence: input.evidence,
1072
- evidenceHash: input.evidenceHash,
1073
- limit: Math.max(1, Number(input.maxRepeatedNoProgress || 2) || 2),
1074
- ignoreInfra: true
1075
- }) : undefined;
1076
- const recoveryPlanFor = (
1077
- action: string,
1078
- reason: string,
1079
- recoveryFailureClass = failureClass || 'unknown',
1080
- productRepairFailure = false
1081
- ): ResolveIOAIManagerRecoveryPlan => buildResolveIOAIManagerRecoveryPlan({
1082
- action,
1083
- reason,
1084
- failureClass: recoveryFailureClass,
1085
- lane: 'build',
1086
- stepType: activeStepType || 'build_repair',
1087
- blocker: input.blocker || (diagnosisValidation.blockers || []).join(' | '),
1088
- changedFiles: cleanList(input.changedFiles, 40, 500),
1089
- maxSameFailureRepeats: Math.max(1, Number(input.maxRepeatedNoProgress || 2) || 2),
1090
- productRepairFailure
1091
- });
1092
- const recoveryCheckpointFor = (
1093
- recoveryPlan: ResolveIOAIManagerRecoveryPlan
1094
- ): ResolveIOAIManagerRecoveryCheckpoint => buildResolveIOAIManagerRecoveryCheckpoint({
1095
- plan: recoveryPlan,
1096
- current: {
1097
- lane: 'build',
1098
- stepType: activeStepType || 'build_repair',
1099
- failureClass: failureClass || 'unknown',
1100
- blocker: input.blocker || (diagnosisValidation.blockers || []).join(' | '),
1101
- evidenceHash: input.evidenceHash,
1102
- changedFiles: cleanList(input.changedFiles, 40, 500),
1103
- summary: input.blocker
1104
- }
1105
- });
1106
- const recoveryFieldsFor = (
1107
- recoveryPlan: ResolveIOAIManagerRecoveryPlan
1108
- ): Pick<ResolveIOSupportV5RepairGateDecision, 'recoveryPlan' | 'recoveryCheckpoint' | 'recoveryEvidenceProbe' | 'recoveryAction'> => {
1109
- const recoveryCheckpoint = recoveryCheckpointFor(recoveryPlan);
1110
- const recoveryEvidenceProbe = buildResolveIOAIManagerRecoveryEvidenceProbe({
1111
- checkpoint: recoveryCheckpoint,
1112
- current: {
1113
- lane: 'build',
1114
- stepType: activeStepType || 'build_repair',
1115
- failureClass: failureClass || 'unknown',
1116
- blocker: input.blocker || (diagnosisValidation.blockers || []).join(' | '),
1117
- evidenceHash: input.evidenceHash,
1118
- changedFiles: cleanList(input.changedFiles, 40, 500),
1119
- summary: input.blocker
1120
- }
1121
- });
1122
- const current = {
1123
- lane: 'build',
1124
- stepType: activeStepType || 'build_repair',
1125
- failureClass: failureClass || 'unknown',
1126
- blocker: input.blocker || (diagnosisValidation.blockers || []).join(' | '),
1127
- evidenceHash: input.evidenceHash,
1128
- changedFiles: cleanList(input.changedFiles, 40, 500),
1129
- summary: input.blocker
1130
- };
1131
- return {
1132
- recoveryPlan,
1133
- recoveryCheckpoint,
1134
- recoveryEvidenceProbe,
1135
- recoveryAction: buildResolveIOAIManagerRecoveryActionPacket({
1136
- plan: recoveryPlan,
1137
- checkpoint: recoveryCheckpoint,
1138
- probe: recoveryEvidenceProbe,
1139
- current
1140
- })
1141
- };
1142
- };
1143
- if (repeatedFailure?.shouldStop) {
1144
- const recoveryPlan = recoveryPlanFor('park_repeated_failure', repeatedFailure.reason, repeatedFailure.failureClass, true);
1145
- return {
1146
- action: 'park_repeated_failure',
1147
- canEditProductCode: false,
1148
- blockers: [repeatedFailure.reason],
1149
- ownerFiles,
1150
- issueClass: diagnosisValidation.normalized?.issue_class,
1151
- proofPlan: diagnosisValidation.normalized?.proof_plan,
1152
- outsideOwnerFiles,
1153
- repeatedFailure,
1154
- diagnosisValidation,
1155
- ...recoveryFieldsFor(recoveryPlan)
1156
- };
1157
- }
1158
- if (failureClass === 'infra' || failureClass === 'compile') {
1159
- const recoveryPlan = recoveryPlanFor('retry_infra', 'support_v5_infra_or_compile_repair_required', failureClass, false);
1160
- return {
1161
- action: 'infra_repair_only',
1162
- canEditProductCode: false,
1163
- blockers: ['Infra/compile/Puppeteer/startup failures must be repaired in the harness lane before product-code repair.'],
1164
- ownerFiles,
1165
- issueClass: diagnosisValidation.normalized?.issue_class,
1166
- proofPlan: diagnosisValidation.normalized?.proof_plan,
1167
- outsideOwnerFiles,
1168
- repeatedFailure,
1169
- diagnosisValidation,
1170
- ...recoveryFieldsFor(recoveryPlan)
1171
- };
1172
- }
1173
- if (activeStepType === 'diagnosis_gate' || !diagnosisValidation.valid) {
1174
- const recoveryPlan = recoveryPlanFor('continue', 'support_v5_diagnosis_gate_required', 'diagnosis', false);
1175
- return {
1176
- action: 'diagnose_only',
1177
- canEditProductCode: false,
1178
- blockers: diagnosisValidation.blockers.length
1179
- ? diagnosisValidation.blockers
1180
- : ['SupportDiagnosisGate is required before product-code repair.'],
1181
- ownerFiles,
1182
- issueClass: diagnosisValidation.normalized?.issue_class,
1183
- proofPlan: diagnosisValidation.normalized?.proof_plan,
1184
- outsideOwnerFiles,
1185
- repeatedFailure,
1186
- diagnosisValidation,
1187
- ...recoveryFieldsFor(recoveryPlan)
1188
- };
1189
- }
1190
- if (outsideOwnerFiles.length) {
1191
- const recoveryPlan = recoveryPlanFor('continue', 'support_v5_out_of_scope_requires_diagnosis_revision', 'owner_scope', false);
1192
- return {
1193
- action: 'reject_out_of_scope',
1194
- canEditProductCode: false,
1195
- blockers: [`Changed files outside diagnosis owner_files; revise diagnosis with new evidence before broadening edits: ${outsideOwnerFiles.join(', ')}`],
1196
- ownerFiles,
1197
- issueClass: diagnosisValidation.normalized?.issue_class,
1198
- proofPlan: diagnosisValidation.normalized?.proof_plan,
1199
- outsideOwnerFiles,
1200
- repeatedFailure,
1201
- diagnosisValidation,
1202
- ...recoveryFieldsFor(recoveryPlan)
1203
- };
1204
- }
1205
- const recoveryPlan = recoveryPlanFor('continue', 'support_v5_product_repair_allowed_after_diagnosis', failureClass || 'product_code', true);
1206
- return {
1207
- action: 'allow_product_repair',
1208
- canEditProductCode: true,
1209
- blockers: [],
1210
- ownerFiles,
1211
- issueClass: diagnosisValidation.normalized?.issue_class,
1212
- proofPlan: diagnosisValidation.normalized?.proof_plan,
1213
- outsideOwnerFiles,
1214
- repeatedFailure,
1215
- diagnosisValidation,
1216
- ...recoveryFieldsFor(recoveryPlan)
1217
- };
1218
- }
1219
-
1220
- export function applyResolveIOSupportDiagnosisGateToMicrotasks(
1221
- bundle: ResolveIOSupportV5StateBundle,
1222
- diagnosisGate: any
1223
- ): ResolveIOSupportV5StateBundle {
1224
- const validation = validateResolveIOSupportDiagnosisGate(diagnosisGate);
1225
- const gate = validation.normalized;
1226
- if (!gate) {
1227
- return bundle;
1228
- }
1229
- const ownerFiles = gate.owner_files;
1230
- const probes = buildResolveIOSupportIssueClassProbes(gate);
1231
- const proofContract = gate.proof_plan.business_proof_contract;
1232
- const businessProof = proofContract?.expected_business_state_change || gate.proof_plan.business_assertion;
1233
- const businessAssertion = proofContract?.data_or_dom_assertion || gate.proof_plan.data_assertion || gate.proof_plan.after;
1234
- const now = isoNow();
1235
- const diagnosisMicrotaskId = (bundle.supportV5MicrotaskLedger || [])
1236
- .find((task) => task.type === 'diagnosis_gate')?.microtaskId
1237
- || stableIdFromText('diagnosis', `Root-cause-first diagnosis gate for: ${cleanText(bundle.supportV5ScopeDigest || gate.issue_case.customer_complaint, 360) || 'support ticket'}`);
1238
- const ledger = (bundle.supportV5MicrotaskLedger || []).map((task) => {
1239
- if (task.type === 'diagnosis_gate') {
1240
- return {
1241
- ...task,
1242
- status: validation.valid ? 'pass' as ResolveIOSupportV5MicrotaskStatus : 'needs_repair' as ResolveIOSupportV5MicrotaskStatus,
1243
- blocker: validation.valid ? '' : validation.blockers.join(' | '),
1244
- updatedAt: now
1245
- };
1246
- }
1247
- if (task.lane === 'build' && /repair|product_repair|build_repair/i.test(String(task.type || ''))) {
1248
- return {
1249
- ...task,
1250
- targetFiles: ownerFiles,
1251
- contextRefs: Array.from(new Set([...(task.contextRefs || []), 'supportV5DiagnosisGate', 'owner_files'])),
1252
- selfGate: `Repair only the diagnosed owner files unless you revise the diagnosis with new evidence. Owner files: ${ownerFiles.join(', ')}.`,
1253
- acceptanceProof: businessProof,
1254
- dependsOn: Array.from(new Set([...(task.dependsOn || []), diagnosisMicrotaskId])),
1255
- updatedAt: now
1256
- };
1257
- }
1258
- if (task.lane === 'qa' && task.type === 'qa_row') {
1259
- return {
1260
- ...task,
1261
- contextRefs: Array.from(new Set([...(task.contextRefs || []), 'supportV5DiagnosisGate', 'proof_plan'])),
1262
- selfGate: probes[0]?.action || task.selfGate,
1263
- acceptanceProof: businessProof || task.acceptanceProof,
1264
- targetFiles: ownerFiles,
1265
- updatedAt: now
1266
- };
1267
- }
1268
- return task;
1269
- });
1270
- const nextActive = selectResolveIOSupportV5ActiveMicrotask(ledger, bundle.supportV5ActiveMicrotaskId);
1271
- return {
1272
- ...bundle,
1273
- supportV5DiagnosisGate: gate,
1274
- supportV5MicrotaskLedger: ledger,
1275
- supportV5ActiveMicrotaskId: nextActive?.microtaskId,
1276
- supportV5LaneMemory: {
1277
- ...bundle.supportV5LaneMemory,
1278
- build: {
1279
- ...bundle.supportV5LaneMemory.build,
1280
- changedFiles: ownerFiles,
1281
- scopeSummary: [
1282
- bundle.supportV5LaneMemory.build.scopeSummary,
1283
- `Diagnosis issue class: ${gate.issue_class}`,
1284
- `Accepted hypothesis: ${gate.accepted_hypothesis.statement}`,
1285
- `Owner files: ${ownerFiles.join(', ')}`
1286
- ].filter(Boolean).join(' | '),
1287
- updatedAt: now
1288
- },
1289
- qa: {
1290
- ...bundle.supportV5LaneMemory.qa,
1291
- activeQaRow: {
1292
- workflow: proofContract?.action_under_test || gate.proof_plan.action,
1293
- route: gate.proof_plan.route || gate.issue_case.route_module,
1294
- assertion: businessAssertion,
1295
- status: 'pending'
1296
- },
1297
- updatedAt: now
1298
- }
1299
- }
1300
- };
1301
- }
1302
-
1303
- function stableIdFromText(prefix: string, value: string): string {
1304
- const text = cleanText(value, 2000).toLowerCase();
1305
- let hash = 0;
1306
- for (let index = 0; index < text.length; index += 1) {
1307
- hash = ((hash << 5) - hash + text.charCodeAt(index)) | 0;
1308
- }
1309
- return `${prefix}-${Math.abs(hash).toString(36) || '0'}`;
1310
- }
1311
-
1312
- function estimateTextTokens(value: string): number {
1313
- const text = String(value || '');
1314
- if (!text) {
1315
- return 0;
1316
- }
1317
- return Math.max(1, Math.ceil(text.length / 4));
1318
- }
1319
-
1320
- export function fingerprintResolveIOSupportV5Blocker(value: any): string {
1321
- const text = cleanText(value, 4000)
1322
- .toLowerCase()
1323
- .replace(/[a-f0-9]{16,}/g, '<id>')
1324
- .replace(/\b\d{2,}\b/g, '<n>')
1325
- .replace(/\bline\s+<n>\b/g, 'line <n>');
1326
- let hash = 0;
1327
- for (let index = 0; index < text.length; index += 1) {
1328
- hash = ((hash << 5) - hash + text.charCodeAt(index)) | 0;
1329
- }
1330
- return `v5-${Math.abs(hash).toString(36)}`;
1331
- }
1332
-
1333
- export function buildResolveIOSupportV5Budget(existing?: Partial<ResolveIOSupportV5Budget>): ResolveIOSupportV5Budget {
1334
- return {
1335
- maxPromptTokensPerNonInitialStep: Number(existing?.maxPromptTokensPerNonInitialStep || 1800),
1336
- maxLoopsPerTicket: Number(existing?.maxLoopsPerTicket || 24),
1337
- maxRepeatedNoProgress: Number(existing?.maxRepeatedNoProgress || 2),
1338
- maxRuntimeMinutesPerLoop: Number(existing?.maxRuntimeMinutesPerLoop || 15),
1339
- totalPromptTokenEstimate: Number(existing?.totalPromptTokenEstimate || 0),
1340
- totalRuntimeMs: Number(existing?.totalRuntimeMs || 0),
1341
- loopCount: Number(existing?.loopCount || 0)
1342
- };
1343
- }
1344
-
1345
- export function buildResolveIOSupportV5PromptBudget(existing?: Partial<ResolveIOSupportV5PromptBudget>): ResolveIOSupportV5PromptBudget {
1346
- return {
1347
- initialPlannerCap: Number(existing?.initialPlannerCap || 6000),
1348
- buildMicrotaskCap: Number(existing?.buildMicrotaskCap || 1800),
1349
- buildMicrotaskHardCap: Number(existing?.buildMicrotaskHardCap || 2500),
1350
- qaMicrotaskCap: Number(existing?.qaMicrotaskCap || 1500),
1351
- qaMicrotaskHardCap: Number(existing?.qaMicrotaskHardCap || 2200),
1352
- repairMicrotaskCap: Number(existing?.repairMicrotaskCap || 1200),
1353
- repairMicrotaskHardCap: Number(existing?.repairMicrotaskHardCap || 1800)
1354
- };
1355
- }
1356
-
1357
- export function buildResolveIOSupportV5ScopeDigest(input: {
1358
- goal?: string;
1359
- approvedScope?: string | string[];
1360
- prBranch?: string;
1361
- maxTokens?: number;
1362
- }): string {
1363
- const scope = Array.isArray(input.approvedScope)
1364
- ? cleanList(input.approvedScope, 30, 220).join(' | ')
1365
- : cleanText(input.approvedScope, 4000);
1366
- const raw = [
1367
- input.goal ? `Goal: ${cleanText(input.goal, 300)}` : '',
1368
- scope ? `Approved scope: ${scope}` : '',
1369
- input.prBranch ? `PR branch: ${cleanText(input.prBranch, 160)}` : ''
1370
- ].filter(Boolean).join('\n');
1371
- const maxChars = Math.max(400, Math.floor(Number(input.maxTokens || 1000) * 4));
1372
- return raw.slice(0, maxChars);
1373
- }
1374
-
1375
- export function buildResolveIOSupportV5MicrotaskLedger(input: {
1376
- scopeDigest: string;
1377
- requirements?: string[];
1378
- buildThreadKey: string;
1379
- qaThreadKey: string;
1380
- now?: Date | string;
1381
- existing?: ResolveIOSupportV5Microtask[];
1382
- }): ResolveIOSupportV5Microtask[] {
1383
- const existing = Array.isArray(input.existing) ? input.existing : [];
1384
- const completedByObjective = new Map<string, ResolveIOSupportV5Microtask>();
1385
- for (const task of existing) {
1386
- if (task && (task.status === 'pass' || task.status === 'parked')) {
1387
- completedByObjective.set(cleanText(task.objective, 500).toLowerCase(), task);
1388
- }
1389
- }
1390
- const now = isoNow(input.now);
1391
- const requirements = cleanList(input.requirements, 30, 240);
1392
- const sourceRequirements = requirements.length
1393
- ? requirements
1394
- : cleanText(input.scopeDigest, 1000).split(/\s+\|\s+|\r?\n/g).map((line) => line.trim()).filter(Boolean).slice(0, 12);
1395
- const ledger: ResolveIOSupportV5Microtask[] = [];
1396
- const diagnosisObjective = `Root-cause-first diagnosis gate for: ${cleanText(input.scopeDigest, 360) || 'support ticket'}`;
1397
- const diagnosisId = stableIdFromText('diagnosis', diagnosisObjective);
1398
- const existingDiagnosis = existing.find((task) => task?.type === 'diagnosis_gate' || task?.microtaskId === diagnosisId);
1399
- ledger.push(existingDiagnosis && (existingDiagnosis.status === 'pass' || existingDiagnosis.status === 'parked') ? existingDiagnosis : {
1400
- microtaskId: diagnosisId,
1401
- lane: 'build',
1402
- type: 'diagnosis_gate',
1403
- status: existingDiagnosis?.status || 'pending',
1404
- objective: diagnosisObjective,
1405
- targetFiles: [],
1406
- contextRefs: ['scope_digest', 'support_context', 'similar_tickets', 'similar_commits'],
1407
- selfGate: 'Read-only diagnosis only: reproduce or explicitly classify the issue, accept one falsifiable root-cause hypothesis, reject alternatives, identify the failing path, cap owner_files, and define before/action/after business proof.',
1408
- acceptanceProof: 'Valid ResolveIOSupportDiagnosisGate JSON with issue_case, issue_class, accepted_hypothesis, rejected_alternatives, failing_path, owner_files, proof_plan, evidence, and status=passed.',
1409
- threadKey: input.buildThreadKey,
1410
- promptTokenEstimate: existingDiagnosis?.promptTokenEstimate,
1411
- attempts: existingDiagnosis?.attempts || 0,
1412
- dependsOn: [],
1413
- parentScopeId: stableIdFromText('scope', diagnosisObjective),
1414
- blocker: existingDiagnosis?.blocker,
1415
- createdAt: existingDiagnosis?.createdAt || now,
1416
- updatedAt: existingDiagnosis?.updatedAt || now
1417
- });
1418
- sourceRequirements.forEach((requirement, index) => {
1419
- const objective = cleanText(requirement, 240);
1420
- if (!objective) {
1421
- return;
1422
- }
1423
- const existingCompleted = completedByObjective.get(objective.toLowerCase());
1424
- const buildId = stableIdFromText(`build-${index + 1}`, objective);
1425
- const qaId = stableIdFromText(`qa-${index + 1}`, objective);
1426
- ledger.push(existingCompleted && existingCompleted.lane === 'build' ? existingCompleted : {
1427
- microtaskId: buildId,
1428
- lane: 'build',
1429
- type: 'build_repair',
1430
- status: 'pending',
1431
- objective,
1432
- targetFiles: [],
1433
- contextRefs: ['scope_digest'],
1434
- selfGate: 'Run the smallest compile/type/unit check that proves this one behavior.',
1435
- acceptanceProof: 'Concrete code/data proof for this behavior, with changed files listed.',
1436
- threadKey: input.buildThreadKey,
1437
- attempts: 0,
1438
- dependsOn: [diagnosisId],
1439
- parentScopeId: stableIdFromText('scope', objective),
1440
- createdAt: now,
1441
- updatedAt: now
1442
- });
1443
- ledger.push({
1444
- microtaskId: qaId,
1445
- lane: 'qa',
1446
- type: 'qa_row',
1447
- status: 'pending',
1448
- objective: `QA proof for: ${objective}`,
1449
- targetFiles: [],
1450
- contextRefs: ['scope_digest', buildId],
1451
- selfGate: 'Drive this one customer-facing workflow row in browser/localhost and capture one captioned proof artifact.',
1452
- acceptanceProof: 'QA matrix row pass with route/data assertion, screenshot/caption artifact, and persisted before/after row/count/value proof for data-changing workflows.',
1453
- threadKey: input.qaThreadKey,
1454
- attempts: 0,
1455
- dependsOn: [diagnosisId, buildId],
1456
- parentScopeId: stableIdFromText('scope', objective),
1457
- createdAt: now,
1458
- updatedAt: now
1459
- });
1460
- });
1461
- return ledger.length ? ledger : existing.slice(-80);
1462
- }
1463
-
1464
- export function selectResolveIOSupportV5ActiveMicrotask(
1465
- ledger: ResolveIOSupportV5Microtask[] = [],
1466
- preferredId?: string
1467
- ): ResolveIOSupportV5Microtask | undefined {
1468
- const byPreferred = preferredId ? ledger.find((task) => task.microtaskId === preferredId && !['pass', 'parked'].includes(task.status)) : undefined;
1469
- if (byPreferred) {
1470
- return byPreferred;
1471
- }
1472
- return ledger.find((task) => task.status === 'needs_repair')
1473
- || ledger.find((task) => task.status === 'in_progress')
1474
- || ledger.find((task) => task.type === 'diagnosis_gate' && task.status === 'pending')
1475
- || ledger.find((task) => task.lane === 'build' && /repair/i.test(String(task.type || '')) && task.status === 'pending')
1476
- || ledger.find((task) => task.status === 'pending')
1477
- || ledger.find((task) => task.status === 'blocked');
1478
- }
1479
-
1480
- export function initializeResolveIOSupportV5State(input: ResolveIOSupportV5InitializeInput): ResolveIOSupportV5StateBundle {
1481
- const now = isoNow(input.now);
1482
- const existing = input.existing || {};
1483
- const existingSupervisor = existing.supportV5SupervisorState;
1484
- const existingLaneMemory = existing.supportV5LaneMemory || {} as ResolveIOSupportV5StateBundle['supportV5LaneMemory'];
1485
- const scope = cleanList(input.approvedScopeRequirements, 24, 240).join(' | ')
1486
- || cleanText(input.description, 1000)
1487
- || cleanText(input.title, 300);
1488
- const ticketLabel = cleanText(input.ticketNumber || input.ticketId || input.jobId, 120);
1489
- const buildThreadKey = cleanText(input.buildThreadKey || existingLaneMemory.build?.threadKey || `support:${input.ticketId || input.jobId}:job:${input.jobId}:build`, 240);
1490
- const qaThreadKey = cleanText(input.qaThreadKey || existingLaneMemory.qa?.threadKey || `support:${input.ticketId || input.jobId}:job:${input.jobId}:qa`, 240);
1491
- const budget = buildResolveIOSupportV5Budget(existing.supportV5Budget);
1492
- const existingDiagnosisGate = normalizeResolveIOSupportDiagnosisGate((existing as any).supportV5DiagnosisGate);
1493
- const diagnosisValidation = validateResolveIOSupportDiagnosisGate(existingDiagnosisGate);
1494
- const scopeDigest = cleanText((existing as any).supportV5ScopeDigest, 4000) || buildResolveIOSupportV5ScopeDigest({
1495
- goal: existingSupervisor?.currentGoal || `Resolve support ticket ${ticketLabel}`,
1496
- approvedScope: scope,
1497
- prBranch: input.prBranch || existingSupervisor?.prBranch || ''
1498
- });
1499
- const ledger = buildResolveIOSupportV5MicrotaskLedger({
1500
- scopeDigest,
1501
- requirements: cleanList(input.approvedScopeRequirements, 30, 240),
1502
- buildThreadKey,
1503
- qaThreadKey,
1504
- now,
1505
- existing: (existing as any).supportV5MicrotaskLedger
1506
- });
1507
- const activeMicrotask = selectResolveIOSupportV5ActiveMicrotask(ledger, (existing as any).supportV5ActiveMicrotaskId);
1508
- const initialized: ResolveIOSupportV5StateBundle = {
1509
- supportWorkflowVersion: 'v5',
1510
- supportV5SupervisorState: {
1511
- version: 'v5',
1512
- status: existingSupervisor?.status || 'active',
1513
- currentGoal: existingSupervisor?.currentGoal || `Resolve support ticket ${ticketLabel}`,
1514
- approvedScope: existingSupervisor?.approvedScope || scope,
1515
- prBranch: cleanText(input.prBranch || existingSupervisor?.prBranch || '', 240),
1516
- activeStep: existingSupervisor?.activeStep || (diagnosisValidation.valid ? 'compile_check' : 'diagnosis_gate'),
1517
- activeBlocker: existingSupervisor?.activeBlocker || (diagnosisValidation.valid ? '' : 'SupportDiagnosisGate required before product-code repair.'),
1518
- lastGoodCheckpoint: existingSupervisor?.lastGoodCheckpoint || 'v5_initialized',
1519
- currentQaRow: existingSupervisor?.currentQaRow,
1520
- processLease: input.processLease || existingSupervisor?.processLease,
1521
- artifactLinks: cleanList(existingSupervisor?.artifactLinks, 40, 500),
1522
- noEmailUnlessApproved: true,
1523
- updatedAt: now
1524
- },
1525
- supportV5DiagnosisGate: diagnosisValidation.valid ? diagnosisValidation.normalized : existingDiagnosisGate,
1526
- supportV5LaneMemory: {
1527
- build: {
1528
- lane: 'build',
1529
- model: existingLaneMemory.build?.model || 'gpt-5.3-codex',
1530
- threadKey: buildThreadKey,
1531
- scopeSummary: existingLaneMemory.build?.scopeSummary || scope,
1532
- activeBlocker: existingLaneMemory.build?.activeBlocker || '',
1533
- activeQaRow: existingLaneMemory.build?.activeQaRow,
1534
- changedFiles: cleanList(existingLaneMemory.build?.changedFiles, 80, 500),
1535
- artifactPaths: cleanList(existingLaneMemory.build?.artifactPaths, 80, 500),
1536
- latestPromptTokenEstimate: Number(existingLaneMemory.build?.latestPromptTokenEstimate || 0) || undefined,
1537
- updatedAt: existingLaneMemory.build?.updatedAt || now
1538
- },
1539
- qa: {
1540
- lane: 'qa',
1541
- model: existingLaneMemory.qa?.model || 'gpt-5.4-mini',
1542
- threadKey: qaThreadKey,
1543
- scopeSummary: existingLaneMemory.qa?.scopeSummary || scope,
1544
- activeBlocker: existingLaneMemory.qa?.activeBlocker || '',
1545
- activeQaRow: existingLaneMemory.qa?.activeQaRow,
1546
- changedFiles: cleanList(existingLaneMemory.qa?.changedFiles, 80, 500),
1547
- artifactPaths: cleanList(existingLaneMemory.qa?.artifactPaths, 80, 500),
1548
- latestPromptTokenEstimate: Number(existingLaneMemory.qa?.latestPromptTokenEstimate || 0) || undefined,
1549
- updatedAt: existingLaneMemory.qa?.updatedAt || now
1550
- }
1551
- },
1552
- supportV5StepHistory: Array.isArray(existing.supportV5StepHistory)
1553
- ? existing.supportV5StepHistory.slice(-80)
1554
- : [],
1555
- supportV5Budget: budget,
1556
- supportV5RunnerIncidents: Array.isArray(existing.supportV5RunnerIncidents)
1557
- ? existing.supportV5RunnerIncidents.slice(-80)
1558
- : [],
1559
- supportV5MicrotaskLedger: ledger,
1560
- supportV5ActiveMicrotaskId: diagnosisValidation.valid
1561
- ? activeMicrotask?.microtaskId
1562
- : ledger.find((task) => task.type === 'diagnosis_gate' && !['pass', 'parked'].includes(task.status))?.microtaskId || activeMicrotask?.microtaskId,
1563
- supportV5ScopeDigest: scopeDigest,
1564
- supportV5MicrotaskUsageHistory: Array.isArray((existing as any).supportV5MicrotaskUsageHistory)
1565
- ? (existing as any).supportV5MicrotaskUsageHistory.slice(-200)
1566
- : [],
1567
- supportV5FailureFingerprints: Array.isArray((existing as any).supportV5FailureFingerprints)
1568
- ? (existing as any).supportV5FailureFingerprints.slice(-200)
1569
- : [],
1570
- supportV5RecoveryPlan: (existing as any).supportV5RecoveryPlan,
1571
- supportV5RecoveryCheckpoint: (existing as any).supportV5RecoveryCheckpoint,
1572
- supportV5RecoveryEvidenceProbe: (existing as any).supportV5RecoveryEvidenceProbe,
1573
- supportV5RecoveryAction: (existing as any).supportV5RecoveryAction,
1574
- supportV5RecoveryDispatchHistory: Array.isArray((existing as any).supportV5RecoveryDispatchHistory)
1575
- ? (existing as any).supportV5RecoveryDispatchHistory.slice(-50)
1576
- : [],
1577
- supportV5RecoveryDirective: (existing as any).supportV5RecoveryDirective
1578
- };
1579
- return diagnosisValidation.valid && diagnosisValidation.normalized
1580
- ? applyResolveIOSupportDiagnosisGateToMicrotasks(initialized, diagnosisValidation.normalized)
1581
- : initialized;
1582
- }
1583
-
1584
- export function recordResolveIOSupportV5Step(
1585
- bundle: ResolveIOSupportV5StateBundle,
1586
- step: ResolveIOSupportV5StepInput
1587
- ): ResolveIOSupportV5StateBundle {
1588
- const now = isoNow(step.now);
1589
- const promptTokens = Math.max(0, Number(step.promptTokenEstimate || 0) || 0);
1590
- const runtimeMs = Math.max(0, Number(step.runtimeMs || 0) || 0);
1591
- const microtaskId = cleanText(step.microtaskId || bundle.supportV5ActiveMicrotaskId, 160);
1592
- const normalizedDiagnosisGate = step.diagnosisGate
1593
- ? normalizeResolveIOSupportDiagnosisGate(step.diagnosisGate, now)
1594
- : undefined;
1595
- const blockerFingerprint = step.blocker || step.summary
1596
- ? fingerprintResolveIOSupportV5Blocker(step.blocker || step.summary || '')
1597
- : undefined;
1598
- const evidenceHash = cleanText(step.evidenceHash, 80)
1599
- || (step.artifactPaths?.length || step.blocker || step.summary
1600
- ? hashResolveIOSupportV5Evidence(step.artifactPaths?.length ? step.artifactPaths : `${step.blocker || ''}\n${step.summary || ''}`)
1601
- : hashResolveIOAIManagerEvidence({
1602
- failureClass: step.failureClass,
1603
- blocker: step.blocker,
1604
- summary: step.summary,
1605
- changedFiles: step.changedFiles,
1606
- artifactPaths: step.artifactPaths
1607
- }));
1608
- const record: ResolveIOSupportV5StepRecord = {
1609
- ...(microtaskId ? { microtaskId } : {}),
1610
- stepType: step.stepType,
1611
- outcome: step.outcome,
1612
- lane: step.lane,
1613
- model: cleanText(step.model, 80),
1614
- threadKey: cleanText(step.threadKey, 240),
1615
- promptTokenEstimate: promptTokens || undefined,
1616
- runtimeMs: runtimeMs || undefined,
1617
- summary: cleanText(step.summary || step.blocker || step.outcome, 1200),
1618
- blocker: cleanText(step.blocker, 1200),
1619
- changedFiles: cleanList(step.changedFiles, 80, 500),
1620
- artifactPaths: cleanList(step.artifactPaths, 80, 500),
1621
- diagnosisGate: normalizedDiagnosisGate,
1622
- failureClass: cleanText(step.failureClass, 80) || undefined,
1623
- blockerFingerprint,
1624
- evidenceHash,
1625
- recordedAt: now
1626
- };
1627
- const diagnosisGate = normalizedDiagnosisGate || bundle.supportV5DiagnosisGate;
1628
- const laneMemory = { ...bundle.supportV5LaneMemory };
1629
- if (step.lane === 'build' || step.lane === 'qa') {
1630
- const previous = laneMemory[step.lane];
1631
- laneMemory[step.lane] = {
1632
- ...previous,
1633
- activeBlocker: record.blocker || previous.activeBlocker || '',
1634
- activeQaRow: step.activeQaRow || previous.activeQaRow,
1635
- changedFiles: record.changedFiles?.length ? record.changedFiles : previous.changedFiles,
1636
- artifactPaths: record.artifactPaths?.length ? record.artifactPaths : previous.artifactPaths,
1637
- latestPromptTokenEstimate: promptTokens || previous.latestPromptTokenEstimate,
1638
- updatedAt: now
1639
- };
1640
- }
1641
- const supervisor = {
1642
- ...bundle.supportV5SupervisorState,
1643
- status: step.outcome === 'ready_for_merge' ? 'complete' as const : (step.outcome === 'park_manual' || step.outcome === 'budget_stop' ? 'parked' as const : 'active' as const),
1644
- activeStep: step.stepType,
1645
- activeBlocker: record.blocker || '',
1646
- currentQaRow: step.activeQaRow || bundle.supportV5SupervisorState.currentQaRow,
1647
- lastGoodCheckpoint: step.outcome === 'pass' || step.outcome === 'ready_for_merge'
1648
- ? step.stepType
1649
- : bundle.supportV5SupervisorState.lastGoodCheckpoint,
1650
- artifactLinks: Array.from(new Set([
1651
- ...bundle.supportV5SupervisorState.artifactLinks,
1652
- ...(record.artifactPaths || [])
1653
- ])).slice(-80),
1654
- updatedAt: now
1655
- };
1656
- const ledger = (bundle.supportV5MicrotaskLedger || []).map((task) => {
1657
- if (task.microtaskId !== bundle.supportV5ActiveMicrotaskId) {
1658
- return task;
1659
- }
1660
- const status: ResolveIOSupportV5MicrotaskStatus = step.outcome === 'pass' || step.outcome === 'ready_for_merge'
1661
- ? 'pass'
1662
- : step.outcome === 'park_manual' || step.outcome === 'budget_stop'
1663
- ? 'parked'
1664
- : step.outcome === 'needs_repair' || step.outcome === 'retry_same_step'
1665
- ? 'needs_repair'
1666
- : 'in_progress';
1667
- return {
1668
- ...task,
1669
- status,
1670
- blocker: record.blocker || task.blocker,
1671
- promptTokenEstimate: promptTokens || task.promptTokenEstimate,
1672
- attempts: task.attempts + (step.outcome === 'pass' || step.outcome === 'ready_for_merge' ? 0 : 1),
1673
- updatedAt: now
1674
- };
1675
- });
1676
- const failureFingerprint = record.failureClass && record.blockerFingerprint && record.evidenceHash
1677
- ? {
1678
- stepType: record.stepType,
1679
- failureClass: cleanText(record.failureClass, 80),
1680
- blockerFingerprint: record.blockerFingerprint,
1681
- evidenceHash: record.evidenceHash,
1682
- recordedAt: now
1683
- }
1684
- : undefined;
1685
- const managerDecision = decideResolveIOAIManagerPolicy({
1686
- history: [...bundle.supportV5StepHistory, record],
1687
- current: record,
1688
- maxSameFailureRepeats: buildResolveIOSupportV5Budget(bundle.supportV5Budget).maxRepeatedNoProgress,
1689
- maxPingPongTransitions: 3,
1690
- infraFailureClasses: ['infra', 'compile']
1691
- });
1692
- const previousRecord = bundle.supportV5StepHistory[bundle.supportV5StepHistory.length - 1];
1693
- const nextLoopCount = managerDecision.loopBudgetShouldReset
1694
- || previousRecord?.failureClass !== record.failureClass
1695
- || previousRecord?.blockerFingerprint !== record.blockerFingerprint
1696
- || previousRecord?.evidenceHash !== record.evidenceHash
1697
- ? 1
1698
- : bundle.supportV5Budget.loopCount + 1;
1699
- const nextMicrotask = selectResolveIOSupportV5ActiveMicrotask(ledger, bundle.supportV5ActiveMicrotaskId);
1700
- const nextBundle: ResolveIOSupportV5StateBundle = {
1701
- ...bundle,
1702
- supportV5SupervisorState: supervisor,
1703
- supportV5DiagnosisGate: diagnosisGate,
1704
- supportV5LaneMemory: laneMemory,
1705
- supportV5StepHistory: [...bundle.supportV5StepHistory, record].slice(-100),
1706
- supportV5Budget: {
1707
- ...bundle.supportV5Budget,
1708
- totalPromptTokenEstimate: bundle.supportV5Budget.totalPromptTokenEstimate + promptTokens,
1709
- totalRuntimeMs: bundle.supportV5Budget.totalRuntimeMs + runtimeMs,
1710
- loopCount: nextLoopCount
1711
- },
1712
- supportV5MicrotaskLedger: ledger,
1713
- supportV5ActiveMicrotaskId: nextMicrotask?.microtaskId,
1714
- supportV5MicrotaskUsageHistory: bundle.supportV5MicrotaskUsageHistory || [],
1715
- supportV5FailureFingerprints: failureFingerprint
1716
- ? [...(bundle.supportV5FailureFingerprints || []), failureFingerprint].slice(-200)
1717
- : (bundle.supportV5FailureFingerprints || []),
1718
- supportV5RecoveryPlan: managerDecision.recoveryPlan,
1719
- supportV5RecoveryCheckpoint: managerDecision.recoveryCheckpoint,
1720
- supportV5RecoveryEvidenceProbe: managerDecision.recoveryEvidenceProbe,
1721
- supportV5RecoveryAction: managerDecision.recoveryAction
1722
- };
1723
- if (normalizedDiagnosisGate && validateResolveIOSupportDiagnosisGate(normalizedDiagnosisGate).valid) {
1724
- return applyResolveIOSupportDiagnosisGateToMicrotasks(nextBundle, normalizedDiagnosisGate);
1725
- }
1726
- return nextBundle;
1727
- }
1728
-
1729
- export function recordResolveIOSupportV5MicrotaskUsage(
1730
- bundle: ResolveIOSupportV5StateBundle,
1731
- usage: Omit<ResolveIOSupportV5MicrotaskUsage, 'recordedAt'>
1732
- ): ResolveIOSupportV5StateBundle {
1733
- const record: ResolveIOSupportV5MicrotaskUsage = {
1734
- ...usage,
1735
- microtaskId: cleanText(usage.microtaskId, 160),
1736
- threadKey: cleanText(usage.threadKey, 240),
1737
- model: cleanText(usage.model, 80),
1738
- promptTokenEstimate: Math.max(0, Number(usage.promptTokenEstimate || 0) || 0),
1739
- promptSections: Array.isArray(usage.promptSections)
1740
- ? usage.promptSections.map((section) => ({
1741
- name: cleanText(section.name, 120),
1742
- tokenEstimate: Math.max(0, Number(section.tokenEstimate || 0) || 0)
1743
- })).filter((section) => section.name)
1744
- : [],
1745
- recordedAt: isoNow()
1746
- };
1747
- const ledger = (bundle.supportV5MicrotaskLedger || []).map((task) => task.microtaskId === record.microtaskId
1748
- ? {
1749
- ...task,
1750
- promptTokenEstimate: record.promptTokenEstimate,
1751
- updatedAt: record.recordedAt
1752
- }
1753
- : task);
1754
- return {
1755
- ...bundle,
1756
- supportV5MicrotaskLedger: ledger,
1757
- supportV5MicrotaskUsageHistory: [
1758
- ...(bundle.supportV5MicrotaskUsageHistory || []),
1759
- record
1760
- ].slice(-200)
1761
- };
1762
- }
1763
-
1764
- export function decideResolveIOSupportV5Continuation(bundle: ResolveIOSupportV5StateBundle): ResolveIOSupportV5ContinuationDecision {
1765
- const history = bundle.supportV5StepHistory || [];
1766
- const budget = buildResolveIOSupportV5Budget(bundle.supportV5Budget);
1767
- const last = history[history.length - 1];
1768
- const activeMicrotaskId = cleanText(bundle.supportV5ActiveMicrotaskId, 160);
1769
- const blockerFingerprint = fingerprintResolveIOSupportV5Blocker(last?.blocker || last?.summary || '');
1770
- let repeatedNoProgressCount = 0;
1771
- for (let index = history.length - 1; index >= 0; index -= 1) {
1772
- const item = history[index];
1773
- if (activeMicrotaskId && cleanText((item as any).microtaskId, 160) !== activeMicrotaskId) {
1774
- continue;
1775
- }
1776
- if (item.outcome === 'pass' || item.outcome === 'ready_for_merge') {
1777
- break;
1778
- }
1779
- if (item.stepType !== last?.stepType) {
1780
- break;
1781
- }
1782
- if (fingerprintResolveIOSupportV5Blocker(item.blocker || item.summary || '') === blockerFingerprint) {
1783
- repeatedNoProgressCount += 1;
1784
- }
1785
- }
1786
- const budgetExceeded = budget.loopCount >= budget.maxLoopsPerTicket
1787
- || (last?.promptTokenEstimate || 0) > budget.maxPromptTokensPerNonInitialStep;
1788
- const repeatedFailure = last ? decideResolveIOSupportV5RepeatedFailureStop({
1789
- history,
1790
- failureClass: last.failureClass,
1791
- blocker: last.blocker || last.summary,
1792
- evidenceHash: last.evidenceHash,
1793
- limit: budget.maxRepeatedNoProgress,
1794
- ignoreInfra: true
1795
- }) : null;
1796
- const recoveryPlanFor = (
1797
- action: string,
1798
- reason: string,
1799
- extra: Partial<ResolveIOAIManagerRecoveryPlanInput> = {}
1800
- ): ResolveIOAIManagerRecoveryPlan => buildResolveIOAIManagerRecoveryPlan({
1801
- action,
1802
- reason,
1803
- failureClass: last?.failureClass,
1804
- lane: last?.lane || 'supervisor',
1805
- stepType: last?.stepType || bundle.supportV5SupervisorState.activeStep,
1806
- blocker: last?.blocker || last?.summary,
1807
- changedFiles: last?.changedFiles,
1808
- artifactPaths: last?.artifactPaths,
1809
- maxSameFailureRepeats: budget.maxRepeatedNoProgress,
1810
- ...extra
1811
- });
1812
- const recoveryCheckpointFor = (
1813
- recoveryPlan: ResolveIOAIManagerRecoveryPlan
1814
- ): ResolveIOAIManagerRecoveryCheckpoint => buildResolveIOAIManagerRecoveryCheckpoint({
1815
- plan: recoveryPlan,
1816
- current: last
1817
- });
1818
- const recoveryFieldsFor = (
1819
- recoveryPlan: ResolveIOAIManagerRecoveryPlan
1820
- ): Pick<ResolveIOSupportV5ContinuationDecision, 'recoveryPlan' | 'recoveryCheckpoint' | 'recoveryEvidenceProbe' | 'recoveryAction'> => {
1821
- const recoveryCheckpoint = recoveryCheckpointFor(recoveryPlan);
1822
- const recoveryEvidenceProbe = buildResolveIOAIManagerRecoveryEvidenceProbe({
1823
- checkpoint: recoveryCheckpoint,
1824
- current: last
1825
- });
1826
- return {
1827
- recoveryPlan,
1828
- recoveryCheckpoint,
1829
- recoveryEvidenceProbe,
1830
- recoveryAction: buildResolveIOAIManagerRecoveryActionPacket({
1831
- plan: recoveryPlan,
1832
- checkpoint: recoveryCheckpoint,
1833
- probe: recoveryEvidenceProbe,
1834
- current: last
1835
- })
1836
- };
1837
- };
1838
- if (budgetExceeded) {
1839
- const recoveryPlan = recoveryPlanFor('manual_handoff', 'support_v5_budget_guard', {
1840
- productRepairFailure: false
1841
- });
1842
- return {
1843
- action: 'park',
1844
- reason: 'support_v5_budget_guard',
1845
- nextStep: last?.stepType || 'cleanup',
1846
- repeatedNoProgressCount,
1847
- budgetExceeded,
1848
- ...recoveryFieldsFor(recoveryPlan)
1849
- };
1850
- }
1851
- const lastFailureClass = cleanText(last?.failureClass, 80).toLowerCase();
1852
- if (repeatedNoProgressCount > budget.maxRepeatedNoProgress && /^(infra|compile)$/.test(lastFailureClass)) {
1853
- const recoveryPlan = recoveryPlanFor('retry_infra', 'support_v5_infra_or_compile_repair_required', {
1854
- failureClass: lastFailureClass,
1855
- productRepairFailure: false
1856
- });
1857
- return {
1858
- action: 'continue',
1859
- reason: 'support_v5_infra_or_compile_repair_required',
1860
- nextStep: last?.stepType || 'compile_check',
1861
- repeatedNoProgressCount,
1862
- budgetExceeded,
1863
- ...recoveryFieldsFor(recoveryPlan)
1864
- };
1865
- }
1866
- if (repeatedNoProgressCount > budget.maxRepeatedNoProgress) {
1867
- const recoveryPlan = recoveryPlanFor('park_repeated_failure', 'support_v5_repeated_no_progress', {
1868
- productRepairFailure: true
1869
- });
1870
- return {
1871
- action: 'park',
1872
- reason: 'support_v5_repeated_no_progress',
1873
- nextStep: last?.stepType || 'cleanup',
1874
- repeatedNoProgressCount,
1875
- budgetExceeded,
1876
- ...recoveryFieldsFor(recoveryPlan)
1877
- };
1878
- }
1879
- if (repeatedFailure?.shouldStop) {
1880
- const recoveryPlan = recoveryPlanFor(
1881
- repeatedFailure.reason === 'support_v5_ping_pong_failure_loop' ? 'park_ping_pong' : 'park_repeated_failure',
1882
- repeatedFailure.reason,
1883
- {
1884
- failureClass: repeatedFailure.failureClass,
1885
- productRepairFailure: true
1886
- }
1887
- );
1888
- return {
1889
- action: 'park',
1890
- reason: repeatedFailure.reason,
1891
- nextStep: last?.stepType || 'cleanup',
1892
- repeatedNoProgressCount: repeatedFailure.repeatedCount,
1893
- budgetExceeded,
1894
- ...recoveryFieldsFor(recoveryPlan)
1895
- };
1896
- }
1897
- const recoveryPlan = recoveryPlanFor('continue', 'support_v5_continue');
1898
- return {
1899
- action: 'continue',
1900
- reason: 'support_v5_continue',
1901
- nextStep: last?.stepType || bundle.supportV5SupervisorState.activeStep,
1902
- repeatedNoProgressCount,
1903
- budgetExceeded: false,
1904
- ...recoveryFieldsFor(recoveryPlan)
1905
- };
1906
- }
1907
-
1908
- export function buildResolveIOSupportV5DiagnoseFirstPrompt(lines: {
1909
- goal?: string;
1910
- approvedScope?: string[];
1911
- activeStep?: ResolveIOSupportV5StepType;
1912
- activeBlocker?: string;
1913
- lane?: ResolveIOSupportV5Lane;
1914
- laneSummary?: string;
1915
- currentQaRow?: ResolveIOSupportV5LaneMemory['activeQaRow'];
1916
- artifactPaths?: string[];
1917
- changedFiles?: string[];
1918
- }): string[] {
1919
- return [
1920
- 'Support Runner V5 contract: act like a guarded autonomous engineer, not a gate checklist.',
1921
- 'Start with Diagnose First: observed evidence, likely cause, smallest next action, and expected proof.',
1922
- 'Use compact lane memory and current artifacts before asking for broad ticket context.',
1923
- 'Do not send customer email. Do not write production data. Do not spawn duplicate build, QA, server, client, Mongo, browser, or Codex processes.',
1924
- 'If repairing, inspect logs/artifacts/source/diff first; make the smallest code or localhost-data change, then run the smallest finite self-gate.',
1925
- 'For build repairs, prefer `npm run build-prod -- --watch=false`, a targeted `tsc --noEmit`, or a focused unit test. `npm run build-dev` is forbidden for support microtasks because it is slow/watch-oriented and can leave heavy esbuild work. If no finite gate exists, return a blocked self-gate with the exact reason instead of running build-dev.',
1926
- 'If QA fails, retest the failed row before advancing; if the same blocker repeats without new proof, park with the exact blocker.',
1927
- lines.goal ? `Goal: ${cleanText(lines.goal, 500)}` : '',
1928
- cleanList(lines.approvedScope, 12, 240).length ? `Approved scope: ${cleanList(lines.approvedScope, 12, 240).join(' | ')}` : '',
1929
- lines.activeStep ? `Active step: ${lines.activeStep}` : '',
1930
- lines.lane ? `Lane: ${lines.lane}` : '',
1931
- lines.laneSummary ? `Lane memory: ${cleanText(lines.laneSummary, 700)}` : '',
1932
- lines.activeBlocker ? `Active blocker: ${cleanText(lines.activeBlocker, 800)}` : '',
1933
- lines.currentQaRow?.workflow ? `Current QA row: ${cleanText(lines.currentQaRow.workflow, 300)}` : '',
1934
- lines.currentQaRow?.route ? `Current QA route: ${cleanText(lines.currentQaRow.route, 300)}` : '',
1935
- cleanList(lines.changedFiles, 12, 200).length ? `Changed files: ${cleanList(lines.changedFiles, 12, 200).join(', ')}` : '',
1936
- cleanList(lines.artifactPaths, 12, 240).length ? `Artifacts: ${cleanList(lines.artifactPaths, 12, 240).join(', ')}` : ''
1937
- ].filter(Boolean);
1938
- }
1939
-
1940
- export function buildResolveIOSupportV5MicrotaskPrompt(input: {
1941
- bundle: ResolveIOSupportV5StateBundle;
1942
- lane: 'build' | 'qa';
1943
- model?: string;
1944
- stage?: string;
1945
- failureText?: string;
1946
- changedFiles?: string[];
1947
- artifactPaths?: string[];
1948
- targetFiles?: string[];
1949
- contextSnippets?: string[];
1950
- activeQaRow?: ResolveIOSupportV5LaneMemory['activeQaRow'];
1951
- }): {
1952
- prompt: string;
1953
- promptTokenEstimate: number;
1954
- promptSections: ResolveIOSupportV5UsageSection[];
1955
- activeMicrotask?: ResolveIOSupportV5Microtask;
1956
- withinCap: boolean;
1957
- withinHardCap: boolean;
1958
- cap: number;
1959
- hardCap: number;
1960
- reason?: string;
1961
- } {
1962
- const activeMicrotask = selectResolveIOSupportV5ActiveMicrotask(
1963
- input.bundle.supportV5MicrotaskLedger || [],
1964
- input.bundle.supportV5ActiveMicrotaskId
1965
- );
1966
- const diagnosisValidation = validateResolveIOSupportDiagnosisGate(input.bundle.supportV5DiagnosisGate);
1967
- const diagnosisGate = diagnosisValidation.normalized || input.bundle.supportV5DiagnosisGate;
1968
- const diagnosisActive = activeMicrotask?.type === 'diagnosis_gate';
1969
- const budget = buildResolveIOSupportV5PromptBudget();
1970
- const repairLike = Boolean(input.failureText || activeMicrotask?.status === 'needs_repair' || /repair/i.test(String(input.stage || activeMicrotask?.type || '')));
1971
- const cap = repairLike
1972
- ? budget.repairMicrotaskCap
1973
- : input.lane === 'qa'
1974
- ? budget.qaMicrotaskCap
1975
- : budget.buildMicrotaskCap;
1976
- const hardCap = repairLike
1977
- ? budget.repairMicrotaskHardCap
1978
- : input.lane === 'qa'
1979
- ? budget.qaMicrotaskHardCap
1980
- : budget.buildMicrotaskHardCap;
1981
- const laneMemory = input.bundle.supportV5LaneMemory[input.lane];
1982
- const taskThreadKey = activeMicrotask?.threadKey || laneMemory.threadKey;
1983
- const changedFiles = cleanList(input.changedFiles?.length ? input.changedFiles : laneMemory.changedFiles, 8, 160);
1984
- const artifactPaths = cleanList(input.artifactPaths?.length ? input.artifactPaths : laneMemory.artifactPaths, 8, 200);
1985
- const targetFiles = cleanList(input.targetFiles?.length ? input.targetFiles : activeMicrotask?.targetFiles, 5, 160);
1986
- const contextSnippets = cleanList(input.contextSnippets, 5, 360);
1987
- const qaRow = input.activeQaRow || activeMicrotask?.lane === 'qa'
1988
- ? input.activeQaRow || laneMemory.activeQaRow || input.bundle.supportV5SupervisorState.currentQaRow
1989
- : undefined;
1990
- const sections = [
1991
- {
1992
- name: 'microtask_contract',
1993
- text: [
1994
- 'Support Runner V5 Microtask Contract.',
1995
- 'Use the existing persistent lane thread. Do not start a fresh thread.',
1996
- 'Do exactly one microtask and one proof gate. Do not replay ticket triage, prior plans, attachments, broad QA checklist, or unrelated scope.',
1997
- 'If context is insufficient, request the smallest missing file/log/artifact by path and park this microtask; do not broaden the prompt.',
1998
- 'Do not send customer email. Do not deploy. Do not spawn duplicate server/client/Mongo/browser/Codex processes.',
1999
- diagnosisActive
2000
- ? 'Diagnosis gate hard boundary: read-only investigation only. Do not edit source, generated files, package files, tests, fixtures, QA artifacts, or local data. Return the diagnosis JSON contract only.'
2001
- : input.lane === 'qa'
2002
- ? 'QA lane hard boundary: the platform preflight owns compile, dependency install, Mongo/server/client startup, and Angular startup. This lane owns only browser/data proof and QA artifacts unless the prompt explicitly says preflight was skipped.'
2003
- : 'Build lane hard boundary: do not run `npm run build-dev`, `ng build`, `npm run server`, `npm run client`, `ng serve`, `run-local-qa.sh`, browser automation, or any watch/long-lived command. If a broad compile gate is needed, run only `npm run build-prod -- --watch=false`; otherwise use a targeted finite check or return the precise blocker.'
2004
- ].join('\n')
2005
- },
2006
- diagnosisActive ? {
2007
- name: 'root_cause_first_diagnosis_contract',
2008
- text: [
2009
- 'Before any product-code repair, produce strict JSON only:',
2010
- '{"support_diagnosis_gate":{"issue_case":{"customer_complaint":"","expected_result":"","observed_result":"","route_module":"","account_customer_context":"","reproduction_status":"reproduced|blocked|classified","reproduction_blocker":""},"issue_class":"no_op_submit|missing_wrong_data|filter_query_mismatch|invoice_pdf_export|upload_import|route_auth_hydration|slow_query_performance","accepted_hypothesis":{"statement":"","falsifiable_test":"","evidence":[""]},"rejected_alternatives":[""],"failing_path":{"frontend":"","backend":"","shared_library":"","data_query":"","description":""},"owner_files":["small/exact/file.ts"],"proof_plan":{"before":"","before_state_unavailable_reason":"","action":"","after":"","business_assertion":"","route":"","data_assertion":"","artifact_expectation":"","business_proof_contract":{"issue_class":"same as diagnosis issue_class","setup_state":"","action_under_test":"","expected_business_state_change":"","prohibited_false_pass":"Route load, screenshot, scorecard, or model claim alone is not acceptance.","proof_artifacts":["browser trace/screenshot/json/mongo delta"],"data_or_dom_assertion":""}},"similar_tickets":[],"similar_commits":[],"evidence":[{"type":"ticket|browser|mongo|log|code|commit|qa|other","summary":"","artifactPath":""}],"status":"passed"}}',
2011
- 'Owner files must be a small exact editable set, not directories, globs, generated wrappers, or broad repo areas.',
2012
- 'The accepted hypothesis must be falsifiable and backed by evidence; prior similar tickets or commits are hints only and cannot bypass fresh diagnosis.',
2013
- 'The proof plan must be before/action/after business proof plus business_proof_contract. If before-state proof is impossible, explain exactly why in before_state_unavailable_reason.',
2014
- 'The business_proof_contract must name the setup state, action under test, expected business state change, prohibited false pass, required artifacts, and DOM/data assertion.'
2015
- ].join('\n')
2016
- } : {
2017
- name: 'diagnosis_gate_context',
2018
- text: diagnosisValidation.valid && diagnosisGate ? [
2019
- `Diagnosis issue class: ${(diagnosisGate as ResolveIOSupportDiagnosisGate).issue_class}`,
2020
- `Accepted hypothesis: ${(diagnosisGate as ResolveIOSupportDiagnosisGate).accepted_hypothesis.statement}`,
2021
- `Failing path: ${(diagnosisGate as ResolveIOSupportDiagnosisGate).failing_path.description || (diagnosisGate as ResolveIOSupportDiagnosisGate).failing_path.frontend || (diagnosisGate as ResolveIOSupportDiagnosisGate).failing_path.backend || ''}`,
2022
- `Owner files: ${(diagnosisGate as ResolveIOSupportDiagnosisGate).owner_files.join(', ')}`,
2023
- `Business proof required: ${(diagnosisGate as ResolveIOSupportDiagnosisGate).proof_plan.business_assertion}`,
2024
- (diagnosisGate as ResolveIOSupportDiagnosisGate).proof_plan.business_proof_contract
2025
- ? `Business proof contract: ${(diagnosisGate as ResolveIOSupportDiagnosisGate).proof_plan.business_proof_contract?.action_under_test} -> ${(diagnosisGate as ResolveIOSupportDiagnosisGate).proof_plan.business_proof_contract?.expected_business_state_change}; assertion ${(diagnosisGate as ResolveIOSupportDiagnosisGate).proof_plan.business_proof_contract?.data_or_dom_assertion}`
2026
- : '',
2027
- `Before/action/after: ${(diagnosisGate as ResolveIOSupportDiagnosisGate).proof_plan.before || (diagnosisGate as ResolveIOSupportDiagnosisGate).proof_plan.before_state_unavailable_reason} -> ${(diagnosisGate as ResolveIOSupportDiagnosisGate).proof_plan.action} -> ${(diagnosisGate as ResolveIOSupportDiagnosisGate).proof_plan.after}`
2028
- ].filter(Boolean).join('\n') : 'SupportDiagnosisGate is not valid. Park instead of editing product code.'
2029
- },
2030
- {
2031
- name: 'scope_digest',
2032
- text: cleanText(input.bundle.supportV5ScopeDigest || input.bundle.supportV5SupervisorState.approvedScope, 900)
2033
- },
2034
- {
2035
- name: 'active_microtask',
2036
- text: activeMicrotask ? [
2037
- `Microtask id: ${activeMicrotask.microtaskId}`,
2038
- `Lane: ${input.lane}`,
2039
- `Type: ${activeMicrotask.type}`,
2040
- `Status: ${activeMicrotask.status}`,
2041
- `Objective: ${cleanText(activeMicrotask.objective, 360)}`,
2042
- `Self-gate: ${cleanText(activeMicrotask.selfGate, 260)}`,
2043
- `Acceptance proof: ${cleanText(activeMicrotask.acceptanceProof, 260)}`,
2044
- `Attempts on this microtask: ${activeMicrotask.attempts}`,
2045
- `Thread key: ${taskThreadKey}`
2046
- ].join('\n') : 'No active microtask found. Park and report support_v5_microtask_missing.'
2047
- },
2048
- {
2049
- name: 'failure_delta',
2050
- text: input.failureText ? `Latest blocker/failure delta: ${cleanText(input.failureText, 700)}` : ''
2051
- },
2052
- {
2053
- name: 'target_context',
2054
- text: [
2055
- targetFiles.length ? `Target files: ${targetFiles.join(', ')}` : '',
2056
- changedFiles.length ? `Changed files: ${changedFiles.join(', ')}` : '',
2057
- artifactPaths.length ? `Artifacts: ${artifactPaths.join(', ')}` : '',
2058
- qaRow?.workflow ? `QA row workflow: ${cleanText(qaRow.workflow, 220)}` : '',
2059
- qaRow?.route ? `QA row route: ${cleanText(qaRow.route, 220)}` : '',
2060
- qaRow?.assertion ? `QA row assertion: ${cleanText(qaRow.assertion, 260)}` : '',
2061
- contextSnippets.length ? `Relevant snippets:\n${contextSnippets.join('\n---\n')}` : ''
2062
- ].filter(Boolean).join('\n')
2063
- },
2064
- input.lane === 'qa' ? {
2065
- name: 'qa_browser_evidence_contract',
2066
- text: [
2067
- 'QA lane first action after preflight: collect fresh browser evidence for the active row, not a proof review of existing route/auth artifacts.',
2068
- 'Use the already-running localhost harness and staged env. Before any shell command, run `source .resolveio-support-tools/env.sh 2>/dev/null || source ../.resolveio-support-tools/env.sh 2>/dev/null || true`; then use `$RESOLVEIO_SUPPORT_QA_CLIENT_URL`, `$RESOLVEIO_SUPPORT_QA_SERVER_URL`, `$PUPPETEER_EXECUTABLE_PATH`, and `$CHROME_BIN`.',
2069
- 'Required auth replay helper inside every Puppeteer row script: `const storage=JSON.parse(fs.readFileSync("qa-artifacts/auth-bootstrap-storage-state.json","utf8")); const entries=[...(Array.isArray(storage.localStorageEntries)?storage.localStorageEntries:[]), ...(Array.isArray(storage.localStorage)?storage.localStorage:Object.entries(storage.localStorage||{}).map(([key,value])=>({key,value}))), ...((storage.origins||[]).flatMap(o=>o.localStorage||[]))].map(e=>({key:e.key||e.name,value:e.value})).filter(e=>e.key); const clientUrl=process.env.RESOLVEIO_SUPPORT_QA_CLIENT_URL||process.env.RESOLVEIO_RUNNER_QA_CLIENT_URL; const rowRoute="<ACTIVE_QA_ROUTE>"; await page.goto(clientUrl,{waitUntil:"domcontentloaded"}); await page.evaluate(items=>{localStorage.clear(); for(const item of items)localStorage.setItem(item.key,item.value);}, entries); await page.goto(new URL(rowRoute, clientUrl).href,{waitUntil:"domcontentloaded"});` Replace `<ACTIVE_QA_ROUTE>` with the active row route before running. A screenshot of `/home`, the login screen, or a shell route after this helper means the QA script navigated to the wrong route or storage is stale; rerun the same row with the active route before returning an app blocker.',
2070
- 'Allowed first command shape: one bounded `node`/Puppeteer row script that reads `qa-artifacts/auth-bootstrap-storage-state.json`, opens `$RESOLVEIO_SUPPORT_QA_CLIENT_URL`, seeds localStorage, navigates to the active QA route with `new URL(activeRoute, clientUrl).href`, drives the visible workflow, captures screenshot/caption, and updates the active matrix row. A `/home` proof is invalid for a locked non-home route.',
2071
- 'Forbidden in QA lane after preflight: `npm run build`, `npm run build-dev`, `npm run build-prod`, `ng build`, `npm install`, `npm ci`, `npm run server`, `npm run client`, `ng serve`, `gulp`, `mongod`, `run-local-qa.sh`, and broad source discovery. If a build/startup/dependency problem is suspected, return `blocked` or `needs-fix` with the existing qa-artifacts log paths instead of launching those commands.',
2072
- 'Launch Puppeteer from `PUPPETEER_EXECUTABLE_PATH || CHROME_BIN`, seed localStorage from `qa-artifacts/auth-bootstrap-storage-state.json`, then navigate to the active QA route.',
2073
- 'Before passing, confirm `qa-artifacts/auth-bootstrap-result.json` used the ticket reporter or named affected user when available. If it used generic admin/dev while `qa-live-data-seed-result.json.selected.qa_user_context` names a reporter/affected user, rerun auth as that user or return needs-fix.',
2074
- 'Drive the visible customer workflow for this one row. Capture a new customer-facing screenshot/caption and update `qa-artifacts/qa-coverage-matrix.json` with workflow, route, data id/name, assertion, screenshot path, caption, and pass/failed/blocked status.',
2075
- 'After selecting any From/To, source/target, dropdown, combobox, rio-select, filter, item, customer, yard, chemical, or treatment-plan value, read the visible control text back from the DOM. If it still contains placeholder text such as Select Chemical, Select Yard, Select Customer, Select Treatment Plan Type, Loading..., empty, null, or undefined, do not click the action button and do not mark pass. Capture the selected-state blocker screenshot/DOM text and return needs-fix.',
2076
- 'If the row needs persisted data proof, create that proof yourself in the same bounded QA command by querying localhost QA Mongo through process.env.MONGO_URL after the visible UI action. Write the result under qa-artifacts/ as JSON and reference that path in the matrix. Do not ask for a missing post-action DB artifact while the local QA stack is running; either write it or return needs-fix with the exact query/script error. For update-interchangeables rows, the JSON must include concrete non-placeholder fromText and toText, before/after counts or sample documents for treatment plans and tank/interchangeable records, and must fail if either selected value is only an arrow/placeholder or if the persisted collections are empty.',
2077
- 'If the row names multiple concrete entities such as assets, units, BOLs, invoices, chemicals, customers, yards, or numbered records, prove every named entity. Do not pass by proving only one representative record.',
2078
- 'For customer-reported data bugs, use production-seeded localhost records from `qa-live-data-seed-result.json`. If the exact named record is missing from the seed, fail the row as a seed/query blocker instead of testing a substitute record.',
2079
- 'Route-ready, auth-bootstrap, shell, header-only, and empty-list screenshots do not satisfy this microtask. If the row cannot be proven, capture the blocker screenshot/DOM state and return needs-fix with that exact blocker.',
2080
- 'Do not run compile/startup/npm install, do not spawn another server/client/Mongo, and do not inspect broad source trees before the first browser evidence command.'
2081
- ].join('\n')
2082
- } : {
2083
- name: 'non_qa_noop',
2084
- text: ''
2085
- },
2086
- {
2087
- name: 'return_contract',
2088
- text: diagnosisActive
2089
- ? 'Return strict JSON only with support_diagnosis_gate. Do not include Markdown and do not edit files.'
2090
- : input.lane === 'qa'
2091
- ? 'Return strict JSON only: {"status":"pass"|"needs-fix"|"blocked","microtaskId":"","summary":"","evidence":[""],"artifacts":[""],"next_actions":[""]}.'
2092
- : 'Return concise Markdown with: Microtask Result, Root Cause, Changes, Self-Gate, Acceptance Proof, Residual Risk.'
2093
- }
2094
- ].filter((section) => cleanText(section.text, 20));
2095
- const promptSections = sections.map((section) => ({
2096
- name: section.name,
2097
- tokenEstimate: estimateTextTokens(section.text)
2098
- }));
2099
- const prompt = sections.map((section) => section.text).join('\n\n');
2100
- const promptTokenEstimate = estimateTextTokens(prompt);
2101
- return {
2102
- prompt,
2103
- promptTokenEstimate,
2104
- promptSections,
2105
- activeMicrotask,
2106
- withinCap: promptTokenEstimate <= cap,
2107
- withinHardCap: promptTokenEstimate <= hardCap,
2108
- cap,
2109
- hardCap,
2110
- reason: promptTokenEstimate > hardCap
2111
- ? 'support_v5_microtask_prompt_hard_cap'
2112
- : promptTokenEstimate > cap
2113
- ? 'support_v5_microtask_prompt_soft_cap'
2114
- : undefined
2115
- };
2116
- }
2117
-
2118
- export function summarizeResolveIOSupportV5MicrotaskUsage(bundle: ResolveIOSupportV5StateBundle): {
2119
- totalPromptTokenEstimate: number;
2120
- byMicrotask: Array<{ microtaskId: string; promptTokenEstimate: number; calls: number }>;
2121
- bySection: ResolveIOSupportV5UsageSection[];
2122
- broadPromptViolations: ResolveIOSupportV5MicrotaskUsage[];
2123
- } {
2124
- const byMicrotask = new Map<string, { microtaskId: string; promptTokenEstimate: number; calls: number }>();
2125
- const bySection = new Map<string, number>();
2126
- let totalPromptTokenEstimate = 0;
2127
- const broadPromptViolations: ResolveIOSupportV5MicrotaskUsage[] = [];
2128
- const promptBudget = buildResolveIOSupportV5PromptBudget();
2129
- for (const usage of bundle.supportV5MicrotaskUsageHistory || []) {
2130
- totalPromptTokenEstimate += usage.promptTokenEstimate || 0;
2131
- const existing = byMicrotask.get(usage.microtaskId) || { microtaskId: usage.microtaskId, promptTokenEstimate: 0, calls: 0 };
2132
- existing.promptTokenEstimate += usage.promptTokenEstimate || 0;
2133
- existing.calls += 1;
2134
- byMicrotask.set(usage.microtaskId, existing);
2135
- for (const section of usage.promptSections || []) {
2136
- bySection.set(section.name, (bySection.get(section.name) || 0) + section.tokenEstimate);
2137
- }
2138
- const hardCap = usage.lane === 'qa' ? promptBudget.qaMicrotaskHardCap : promptBudget.buildMicrotaskHardCap;
2139
- if ((usage.promptTokenEstimate || 0) > hardCap) {
2140
- broadPromptViolations.push(usage);
2141
- }
2142
- }
2143
- return {
2144
- totalPromptTokenEstimate,
2145
- byMicrotask: Array.from(byMicrotask.values()),
2146
- bySection: Array.from(bySection.entries()).map(([name, tokenEstimate]) => ({ name, tokenEstimate })),
2147
- broadPromptViolations
2148
- };
2149
- }
2150
-
2151
- export function buildResolveIOSupportV5Incident(input: {
2152
- incidentClass: string;
2153
- summary: string;
2154
- stepType?: ResolveIOSupportV5StepType;
2155
- blocker?: string;
2156
- artifactPaths?: string[];
2157
- now?: Date | string;
2158
- }): ResolveIOSupportV5RunnerIncident {
2159
- return {
2160
- incidentClass: cleanText(input.incidentClass, 120) || 'support_v5_runner_incident',
2161
- summary: cleanText(input.summary, 1200),
2162
- stepType: input.stepType,
2163
- blockerFingerprint: input.blocker ? fingerprintResolveIOSupportV5Blocker(input.blocker) : undefined,
2164
- artifactPaths: cleanList(input.artifactPaths, 40, 500),
2165
- recordedAt: isoNow(input.now)
2166
- };
2167
- }