@dealdesk/server 2026.527.0-canary.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (1311) hide show
  1. package/LICENSE +21 -0
  2. package/dist/__tests__/helpers/embedded-postgres.d.ts +2 -0
  3. package/dist/__tests__/helpers/embedded-postgres.d.ts.map +1 -0
  4. package/dist/__tests__/helpers/embedded-postgres.js +2 -0
  5. package/dist/__tests__/helpers/embedded-postgres.js.map +1 -0
  6. package/dist/adapters/builtin-adapter-types.d.ts +5 -0
  7. package/dist/adapters/builtin-adapter-types.d.ts.map +1 -0
  8. package/dist/adapters/builtin-adapter-types.js +18 -0
  9. package/dist/adapters/builtin-adapter-types.js.map +1 -0
  10. package/dist/adapters/codex-models.d.ts +5 -0
  11. package/dist/adapters/codex-models.d.ts.map +1 -0
  12. package/dist/adapters/codex-models.js +105 -0
  13. package/dist/adapters/codex-models.js.map +1 -0
  14. package/dist/adapters/cursor-models.d.ts +13 -0
  15. package/dist/adapters/cursor-models.d.ts.map +1 -0
  16. package/dist/adapters/cursor-models.js +148 -0
  17. package/dist/adapters/cursor-models.js.map +1 -0
  18. package/dist/adapters/http/execute.d.ts +3 -0
  19. package/dist/adapters/http/execute.d.ts.map +1 -0
  20. package/dist/adapters/http/execute.js +51 -0
  21. package/dist/adapters/http/execute.js.map +1 -0
  22. package/dist/adapters/http/execute.test.d.ts +2 -0
  23. package/dist/adapters/http/execute.test.d.ts.map +1 -0
  24. package/dist/adapters/http/execute.test.js +40 -0
  25. package/dist/adapters/http/execute.test.js.map +1 -0
  26. package/dist/adapters/http/index.d.ts +3 -0
  27. package/dist/adapters/http/index.d.ts.map +1 -0
  28. package/dist/adapters/http/index.js +20 -0
  29. package/dist/adapters/http/index.js.map +1 -0
  30. package/dist/adapters/http/test.d.ts +3 -0
  31. package/dist/adapters/http/test.d.ts.map +1 -0
  32. package/dist/adapters/http/test.js +106 -0
  33. package/dist/adapters/http/test.js.map +1 -0
  34. package/dist/adapters/index.d.ts +4 -0
  35. package/dist/adapters/index.d.ts.map +1 -0
  36. package/dist/adapters/index.js +3 -0
  37. package/dist/adapters/index.js.map +1 -0
  38. package/dist/adapters/plugin-loader.d.ts +28 -0
  39. package/dist/adapters/plugin-loader.d.ts.map +1 -0
  40. package/dist/adapters/plugin-loader.js +196 -0
  41. package/dist/adapters/plugin-loader.js.map +1 -0
  42. package/dist/adapters/process/execute.d.ts +3 -0
  43. package/dist/adapters/process/execute.d.ts.map +1 -0
  44. package/dist/adapters/process/execute.js +70 -0
  45. package/dist/adapters/process/execute.js.map +1 -0
  46. package/dist/adapters/process/index.d.ts +3 -0
  47. package/dist/adapters/process/index.d.ts.map +1 -0
  48. package/dist/adapters/process/index.js +23 -0
  49. package/dist/adapters/process/index.js.map +1 -0
  50. package/dist/adapters/process/test.d.ts +3 -0
  51. package/dist/adapters/process/test.d.ts.map +1 -0
  52. package/dist/adapters/process/test.js +77 -0
  53. package/dist/adapters/process/test.js.map +1 -0
  54. package/dist/adapters/registry.d.ts +69 -0
  55. package/dist/adapters/registry.d.ts.map +1 -0
  56. package/dist/adapters/registry.js +589 -0
  57. package/dist/adapters/registry.js.map +1 -0
  58. package/dist/adapters/types.d.ts +2 -0
  59. package/dist/adapters/types.d.ts.map +1 -0
  60. package/dist/adapters/types.js +2 -0
  61. package/dist/adapters/types.js.map +1 -0
  62. package/dist/adapters/utils.d.ts +43 -0
  63. package/dist/adapters/utils.d.ts.map +1 -0
  64. package/dist/adapters/utils.js +52 -0
  65. package/dist/adapters/utils.js.map +1 -0
  66. package/dist/agent-auth-jwt.d.ts +14 -0
  67. package/dist/agent-auth-jwt.d.ts.map +1 -0
  68. package/dist/agent-auth-jwt.js +117 -0
  69. package/dist/agent-auth-jwt.js.map +1 -0
  70. package/dist/app.d.ts +43 -0
  71. package/dist/app.d.ts.map +1 -0
  72. package/dist/app.js +426 -0
  73. package/dist/app.js.map +1 -0
  74. package/dist/attachment-types.d.ts +23 -0
  75. package/dist/attachment-types.d.ts.map +1 -0
  76. package/dist/attachment-types.js +91 -0
  77. package/dist/attachment-types.js.map +1 -0
  78. package/dist/auth/better-auth.d.ts +33 -0
  79. package/dist/auth/better-auth.d.ts.map +1 -0
  80. package/dist/auth/better-auth.js +133 -0
  81. package/dist/auth/better-auth.js.map +1 -0
  82. package/dist/board-claim.d.ts +23 -0
  83. package/dist/board-claim.d.ts.map +1 -0
  84. package/dist/board-claim.js +115 -0
  85. package/dist/board-claim.js.map +1 -0
  86. package/dist/config-file.d.ts +3 -0
  87. package/dist/config-file.d.ts.map +1 -0
  88. package/dist/config-file.js +16 -0
  89. package/dist/config-file.js.map +1 -0
  90. package/dist/config.d.ts +50 -0
  91. package/dist/config.d.ts.map +1 -0
  92. package/dist/config.js +233 -0
  93. package/dist/config.js.map +1 -0
  94. package/dist/deal-desk/enrichment/__tests__/apollo-client.test.d.ts +2 -0
  95. package/dist/deal-desk/enrichment/__tests__/apollo-client.test.d.ts.map +1 -0
  96. package/dist/deal-desk/enrichment/__tests__/apollo-client.test.js +168 -0
  97. package/dist/deal-desk/enrichment/__tests__/apollo-client.test.js.map +1 -0
  98. package/dist/deal-desk/enrichment/__tests__/apollo-config.test.d.ts +2 -0
  99. package/dist/deal-desk/enrichment/__tests__/apollo-config.test.d.ts.map +1 -0
  100. package/dist/deal-desk/enrichment/__tests__/apollo-config.test.js +63 -0
  101. package/dist/deal-desk/enrichment/__tests__/apollo-config.test.js.map +1 -0
  102. package/dist/deal-desk/enrichment/__tests__/resolve-contact-email.test.d.ts +2 -0
  103. package/dist/deal-desk/enrichment/__tests__/resolve-contact-email.test.d.ts.map +1 -0
  104. package/dist/deal-desk/enrichment/__tests__/resolve-contact-email.test.js +127 -0
  105. package/dist/deal-desk/enrichment/__tests__/resolve-contact-email.test.js.map +1 -0
  106. package/dist/deal-desk/enrichment/apollo-client.d.ts +57 -0
  107. package/dist/deal-desk/enrichment/apollo-client.d.ts.map +1 -0
  108. package/dist/deal-desk/enrichment/apollo-client.js +263 -0
  109. package/dist/deal-desk/enrichment/apollo-client.js.map +1 -0
  110. package/dist/deal-desk/enrichment/apollo-config.d.ts +56 -0
  111. package/dist/deal-desk/enrichment/apollo-config.d.ts.map +1 -0
  112. package/dist/deal-desk/enrichment/apollo-config.js +58 -0
  113. package/dist/deal-desk/enrichment/apollo-config.js.map +1 -0
  114. package/dist/deal-desk/enrichment/resolve-contact-email.d.ts +62 -0
  115. package/dist/deal-desk/enrichment/resolve-contact-email.d.ts.map +1 -0
  116. package/dist/deal-desk/enrichment/resolve-contact-email.js +199 -0
  117. package/dist/deal-desk/enrichment/resolve-contact-email.js.map +1 -0
  118. package/dist/deal-desk/gmail/__tests__/client-config.test.d.ts +2 -0
  119. package/dist/deal-desk/gmail/__tests__/client-config.test.d.ts.map +1 -0
  120. package/dist/deal-desk/gmail/__tests__/client-config.test.js +73 -0
  121. package/dist/deal-desk/gmail/__tests__/client-config.test.js.map +1 -0
  122. package/dist/deal-desk/gmail/__tests__/oauth.test.d.ts +2 -0
  123. package/dist/deal-desk/gmail/__tests__/oauth.test.d.ts.map +1 -0
  124. package/dist/deal-desk/gmail/__tests__/oauth.test.js +38 -0
  125. package/dist/deal-desk/gmail/__tests__/oauth.test.js.map +1 -0
  126. package/dist/deal-desk/gmail/__tests__/redirect-uri.test.d.ts +2 -0
  127. package/dist/deal-desk/gmail/__tests__/redirect-uri.test.d.ts.map +1 -0
  128. package/dist/deal-desk/gmail/__tests__/redirect-uri.test.js +74 -0
  129. package/dist/deal-desk/gmail/__tests__/redirect-uri.test.js.map +1 -0
  130. package/dist/deal-desk/gmail/__tests__/send.test.d.ts +2 -0
  131. package/dist/deal-desk/gmail/__tests__/send.test.d.ts.map +1 -0
  132. package/dist/deal-desk/gmail/__tests__/send.test.js +44 -0
  133. package/dist/deal-desk/gmail/__tests__/send.test.js.map +1 -0
  134. package/dist/deal-desk/gmail/__tests__/tokens.test.d.ts +2 -0
  135. package/dist/deal-desk/gmail/__tests__/tokens.test.d.ts.map +1 -0
  136. package/dist/deal-desk/gmail/__tests__/tokens.test.js +69 -0
  137. package/dist/deal-desk/gmail/__tests__/tokens.test.js.map +1 -0
  138. package/dist/deal-desk/gmail/client-config.d.ts +51 -0
  139. package/dist/deal-desk/gmail/client-config.d.ts.map +1 -0
  140. package/dist/deal-desk/gmail/client-config.js +38 -0
  141. package/dist/deal-desk/gmail/client-config.js.map +1 -0
  142. package/dist/deal-desk/gmail/oauth.d.ts +26 -0
  143. package/dist/deal-desk/gmail/oauth.d.ts.map +1 -0
  144. package/dist/deal-desk/gmail/oauth.js +50 -0
  145. package/dist/deal-desk/gmail/oauth.js.map +1 -0
  146. package/dist/deal-desk/gmail/redirect-uri.d.ts +8 -0
  147. package/dist/deal-desk/gmail/redirect-uri.d.ts.map +1 -0
  148. package/dist/deal-desk/gmail/redirect-uri.js +83 -0
  149. package/dist/deal-desk/gmail/redirect-uri.js.map +1 -0
  150. package/dist/deal-desk/gmail/send.d.ts +19 -0
  151. package/dist/deal-desk/gmail/send.d.ts.map +1 -0
  152. package/dist/deal-desk/gmail/send.js +39 -0
  153. package/dist/deal-desk/gmail/send.js.map +1 -0
  154. package/dist/deal-desk/gmail/tokens.d.ts +50 -0
  155. package/dist/deal-desk/gmail/tokens.d.ts.map +1 -0
  156. package/dist/deal-desk/gmail/tokens.js +50 -0
  157. package/dist/deal-desk/gmail/tokens.js.map +1 -0
  158. package/dist/deal-desk/intermediary-campaign.d.ts +4 -0
  159. package/dist/deal-desk/intermediary-campaign.d.ts.map +1 -0
  160. package/dist/deal-desk/intermediary-campaign.js +26 -0
  161. package/dist/deal-desk/intermediary-campaign.js.map +1 -0
  162. package/dist/deal-desk/seeds/role-templates.d.ts +10 -0
  163. package/dist/deal-desk/seeds/role-templates.d.ts.map +1 -0
  164. package/dist/deal-desk/seeds/role-templates.js +110 -0
  165. package/dist/deal-desk/seeds/role-templates.js.map +1 -0
  166. package/dist/deal-desk/seeds/seed-role-templates.d.ts +3 -0
  167. package/dist/deal-desk/seeds/seed-role-templates.d.ts.map +1 -0
  168. package/dist/deal-desk/seeds/seed-role-templates.js +39 -0
  169. package/dist/deal-desk/seeds/seed-role-templates.js.map +1 -0
  170. package/dist/deal-desk/target-service.d.ts +131 -0
  171. package/dist/deal-desk/target-service.d.ts.map +1 -0
  172. package/dist/deal-desk/target-service.js +169 -0
  173. package/dist/deal-desk/target-service.js.map +1 -0
  174. package/dist/deal-desk/tools/__tests__/apollo-api-key.test.d.ts +2 -0
  175. package/dist/deal-desk/tools/__tests__/apollo-api-key.test.d.ts.map +1 -0
  176. package/dist/deal-desk/tools/__tests__/apollo-api-key.test.js +122 -0
  177. package/dist/deal-desk/tools/__tests__/apollo-api-key.test.js.map +1 -0
  178. package/dist/deal-desk/tools/__tests__/create-contact.test.d.ts +2 -0
  179. package/dist/deal-desk/tools/__tests__/create-contact.test.d.ts.map +1 -0
  180. package/dist/deal-desk/tools/__tests__/create-contact.test.js +73 -0
  181. package/dist/deal-desk/tools/__tests__/create-contact.test.js.map +1 -0
  182. package/dist/deal-desk/tools/__tests__/deal-desk-tools.test.d.ts +2 -0
  183. package/dist/deal-desk/tools/__tests__/deal-desk-tools.test.d.ts.map +1 -0
  184. package/dist/deal-desk/tools/__tests__/deal-desk-tools.test.js +193 -0
  185. package/dist/deal-desk/tools/__tests__/deal-desk-tools.test.js.map +1 -0
  186. package/dist/deal-desk/tools/__tests__/email-accounts.test.d.ts +2 -0
  187. package/dist/deal-desk/tools/__tests__/email-accounts.test.d.ts.map +1 -0
  188. package/dist/deal-desk/tools/__tests__/email-accounts.test.js +71 -0
  189. package/dist/deal-desk/tools/__tests__/email-accounts.test.js.map +1 -0
  190. package/dist/deal-desk/tools/__tests__/enrich-contact.test.d.ts +2 -0
  191. package/dist/deal-desk/tools/__tests__/enrich-contact.test.d.ts.map +1 -0
  192. package/dist/deal-desk/tools/__tests__/enrich-contact.test.js +183 -0
  193. package/dist/deal-desk/tools/__tests__/enrich-contact.test.js.map +1 -0
  194. package/dist/deal-desk/tools/__tests__/gmail-client-config.test.d.ts +2 -0
  195. package/dist/deal-desk/tools/__tests__/gmail-client-config.test.d.ts.map +1 -0
  196. package/dist/deal-desk/tools/__tests__/gmail-client-config.test.js +67 -0
  197. package/dist/deal-desk/tools/__tests__/gmail-client-config.test.js.map +1 -0
  198. package/dist/deal-desk/tools/__tests__/helpers/where-introspection.d.ts +2 -0
  199. package/dist/deal-desk/tools/__tests__/helpers/where-introspection.d.ts.map +1 -0
  200. package/dist/deal-desk/tools/__tests__/helpers/where-introspection.js +29 -0
  201. package/dist/deal-desk/tools/__tests__/helpers/where-introspection.js.map +1 -0
  202. package/dist/deal-desk/tools/__tests__/outreach-approve.test.d.ts +2 -0
  203. package/dist/deal-desk/tools/__tests__/outreach-approve.test.d.ts.map +1 -0
  204. package/dist/deal-desk/tools/__tests__/outreach-approve.test.js +258 -0
  205. package/dist/deal-desk/tools/__tests__/outreach-approve.test.js.map +1 -0
  206. package/dist/deal-desk/tools/__tests__/outreach-draft.test.d.ts +2 -0
  207. package/dist/deal-desk/tools/__tests__/outreach-draft.test.d.ts.map +1 -0
  208. package/dist/deal-desk/tools/__tests__/outreach-draft.test.js +115 -0
  209. package/dist/deal-desk/tools/__tests__/outreach-draft.test.js.map +1 -0
  210. package/dist/deal-desk/tools/__tests__/outreach-edit.test.d.ts +2 -0
  211. package/dist/deal-desk/tools/__tests__/outreach-edit.test.d.ts.map +1 -0
  212. package/dist/deal-desk/tools/__tests__/outreach-edit.test.js +169 -0
  213. package/dist/deal-desk/tools/__tests__/outreach-edit.test.js.map +1 -0
  214. package/dist/deal-desk/tools/__tests__/outreach-list-pending.test.d.ts +2 -0
  215. package/dist/deal-desk/tools/__tests__/outreach-list-pending.test.d.ts.map +1 -0
  216. package/dist/deal-desk/tools/__tests__/outreach-list-pending.test.js +59 -0
  217. package/dist/deal-desk/tools/__tests__/outreach-list-pending.test.js.map +1 -0
  218. package/dist/deal-desk/tools/__tests__/test-gmail-send.test.d.ts +2 -0
  219. package/dist/deal-desk/tools/__tests__/test-gmail-send.test.d.ts.map +1 -0
  220. package/dist/deal-desk/tools/__tests__/test-gmail-send.test.js +98 -0
  221. package/dist/deal-desk/tools/__tests__/test-gmail-send.test.js.map +1 -0
  222. package/dist/deal-desk/tools/apollo-api-key.d.ts +11 -0
  223. package/dist/deal-desk/tools/apollo-api-key.d.ts.map +1 -0
  224. package/dist/deal-desk/tools/apollo-api-key.js +70 -0
  225. package/dist/deal-desk/tools/apollo-api-key.js.map +1 -0
  226. package/dist/deal-desk/tools/create-contact.d.ts +28 -0
  227. package/dist/deal-desk/tools/create-contact.d.ts.map +1 -0
  228. package/dist/deal-desk/tools/create-contact.js +52 -0
  229. package/dist/deal-desk/tools/create-contact.js.map +1 -0
  230. package/dist/deal-desk/tools/create-intermediary.d.ts +62 -0
  231. package/dist/deal-desk/tools/create-intermediary.d.ts.map +1 -0
  232. package/dist/deal-desk/tools/create-intermediary.js +105 -0
  233. package/dist/deal-desk/tools/create-intermediary.js.map +1 -0
  234. package/dist/deal-desk/tools/create-target.d.ts +8 -0
  235. package/dist/deal-desk/tools/create-target.d.ts.map +1 -0
  236. package/dist/deal-desk/tools/create-target.js +56 -0
  237. package/dist/deal-desk/tools/create-target.js.map +1 -0
  238. package/dist/deal-desk/tools/enrich-contact.d.ts +22 -0
  239. package/dist/deal-desk/tools/enrich-contact.d.ts.map +1 -0
  240. package/dist/deal-desk/tools/enrich-contact.js +85 -0
  241. package/dist/deal-desk/tools/enrich-contact.js.map +1 -0
  242. package/dist/deal-desk/tools/get-target.d.ts +5 -0
  243. package/dist/deal-desk/tools/get-target.d.ts.map +1 -0
  244. package/dist/deal-desk/tools/get-target.js +33 -0
  245. package/dist/deal-desk/tools/get-target.js.map +1 -0
  246. package/dist/deal-desk/tools/gmail-client-config.d.ts +20 -0
  247. package/dist/deal-desk/tools/gmail-client-config.d.ts.map +1 -0
  248. package/dist/deal-desk/tools/gmail-client-config.js +43 -0
  249. package/dist/deal-desk/tools/gmail-client-config.js.map +1 -0
  250. package/dist/deal-desk/tools/index.d.ts +39 -0
  251. package/dist/deal-desk/tools/index.d.ts.map +1 -0
  252. package/dist/deal-desk/tools/index.js +208 -0
  253. package/dist/deal-desk/tools/index.js.map +1 -0
  254. package/dist/deal-desk/tools/intermediary-outreach-draft.d.ts +21 -0
  255. package/dist/deal-desk/tools/intermediary-outreach-draft.d.ts.map +1 -0
  256. package/dist/deal-desk/tools/intermediary-outreach-draft.js +59 -0
  257. package/dist/deal-desk/tools/intermediary-outreach-draft.js.map +1 -0
  258. package/dist/deal-desk/tools/list-intermediaries.d.ts +20 -0
  259. package/dist/deal-desk/tools/list-intermediaries.d.ts.map +1 -0
  260. package/dist/deal-desk/tools/list-intermediaries.js +74 -0
  261. package/dist/deal-desk/tools/list-intermediaries.js.map +1 -0
  262. package/dist/deal-desk/tools/list-targets.d.ts +20 -0
  263. package/dist/deal-desk/tools/list-targets.d.ts.map +1 -0
  264. package/dist/deal-desk/tools/list-targets.js +73 -0
  265. package/dist/deal-desk/tools/list-targets.js.map +1 -0
  266. package/dist/deal-desk/tools/outreach-approve.d.ts +18 -0
  267. package/dist/deal-desk/tools/outreach-approve.d.ts.map +1 -0
  268. package/dist/deal-desk/tools/outreach-approve.js +229 -0
  269. package/dist/deal-desk/tools/outreach-approve.js.map +1 -0
  270. package/dist/deal-desk/tools/outreach-draft.d.ts +32 -0
  271. package/dist/deal-desk/tools/outreach-draft.d.ts.map +1 -0
  272. package/dist/deal-desk/tools/outreach-draft.js +101 -0
  273. package/dist/deal-desk/tools/outreach-draft.js.map +1 -0
  274. package/dist/deal-desk/tools/outreach-edit.d.ts +6 -0
  275. package/dist/deal-desk/tools/outreach-edit.d.ts.map +1 -0
  276. package/dist/deal-desk/tools/outreach-edit.js +94 -0
  277. package/dist/deal-desk/tools/outreach-edit.js.map +1 -0
  278. package/dist/deal-desk/tools/outreach-list-pending.d.ts +4 -0
  279. package/dist/deal-desk/tools/outreach-list-pending.d.ts.map +1 -0
  280. package/dist/deal-desk/tools/outreach-list-pending.js +55 -0
  281. package/dist/deal-desk/tools/outreach-list-pending.js.map +1 -0
  282. package/dist/deal-desk/tools/record-intermediary-touch.d.ts +20 -0
  283. package/dist/deal-desk/tools/record-intermediary-touch.d.ts.map +1 -0
  284. package/dist/deal-desk/tools/record-intermediary-touch.js +80 -0
  285. package/dist/deal-desk/tools/record-intermediary-touch.js.map +1 -0
  286. package/dist/deal-desk/tools/test-gmail-send.d.ts +21 -0
  287. package/dist/deal-desk/tools/test-gmail-send.d.ts.map +1 -0
  288. package/dist/deal-desk/tools/test-gmail-send.js +65 -0
  289. package/dist/deal-desk/tools/test-gmail-send.js.map +1 -0
  290. package/dist/deal-desk/tools/update-target.d.ts +6 -0
  291. package/dist/deal-desk/tools/update-target.d.ts.map +1 -0
  292. package/dist/deal-desk/tools/update-target.js +43 -0
  293. package/dist/deal-desk/tools/update-target.js.map +1 -0
  294. package/dist/dev-runner-worktree.d.ts +15 -0
  295. package/dist/dev-runner-worktree.d.ts.map +1 -0
  296. package/dist/dev-runner-worktree.js +68 -0
  297. package/dist/dev-runner-worktree.js.map +1 -0
  298. package/dist/dev-server-status.d.ts +27 -0
  299. package/dist/dev-server-status.d.ts.map +1 -0
  300. package/dist/dev-server-status.js +74 -0
  301. package/dist/dev-server-status.js.map +1 -0
  302. package/dist/dev-watch-ignore.d.ts +2 -0
  303. package/dist/dev-watch-ignore.d.ts.map +1 -0
  304. package/dist/dev-watch-ignore.js +36 -0
  305. package/dist/dev-watch-ignore.js.map +1 -0
  306. package/dist/embedded-postgres-watchdog.d.ts +12 -0
  307. package/dist/embedded-postgres-watchdog.d.ts.map +1 -0
  308. package/dist/embedded-postgres-watchdog.js +21 -0
  309. package/dist/embedded-postgres-watchdog.js.map +1 -0
  310. package/dist/errors.d.ts +12 -0
  311. package/dist/errors.d.ts.map +1 -0
  312. package/dist/errors.js +28 -0
  313. package/dist/errors.js.map +1 -0
  314. package/dist/home-paths.d.ts +15 -0
  315. package/dist/home-paths.d.ts.map +1 -0
  316. package/dist/home-paths.js +48 -0
  317. package/dist/home-paths.js.map +1 -0
  318. package/dist/index.d.ts +10 -0
  319. package/dist/index.d.ts.map +1 -0
  320. package/dist/index.js +787 -0
  321. package/dist/index.js.map +1 -0
  322. package/dist/lib/join-request-dedupe.d.ts +11 -0
  323. package/dist/lib/join-request-dedupe.d.ts.map +1 -0
  324. package/dist/lib/join-request-dedupe.js +49 -0
  325. package/dist/lib/join-request-dedupe.js.map +1 -0
  326. package/dist/log-redaction.d.ts +11 -0
  327. package/dist/log-redaction.d.ts.map +1 -0
  328. package/dist/log-redaction.js +122 -0
  329. package/dist/log-redaction.js.map +1 -0
  330. package/dist/middleware/auth.d.ts +12 -0
  331. package/dist/middleware/auth.d.ts.map +1 -0
  332. package/dist/middleware/auth.js +302 -0
  333. package/dist/middleware/auth.js.map +1 -0
  334. package/dist/middleware/board-mutation-guard.d.ts +3 -0
  335. package/dist/middleware/board-mutation-guard.d.ts.map +1 -0
  336. package/dist/middleware/board-mutation-guard.js +67 -0
  337. package/dist/middleware/board-mutation-guard.js.map +1 -0
  338. package/dist/middleware/error-handler.d.ts +17 -0
  339. package/dist/middleware/error-handler.d.ts.map +1 -0
  340. package/dist/middleware/error-handler.js +45 -0
  341. package/dist/middleware/error-handler.js.map +1 -0
  342. package/dist/middleware/http-log-policy.d.ts +2 -0
  343. package/dist/middleware/http-log-policy.d.ts.map +1 -0
  344. package/dist/middleware/http-log-policy.js +52 -0
  345. package/dist/middleware/http-log-policy.js.map +1 -0
  346. package/dist/middleware/index.d.ts +4 -0
  347. package/dist/middleware/index.d.ts.map +1 -0
  348. package/dist/middleware/index.js +4 -0
  349. package/dist/middleware/index.js.map +1 -0
  350. package/dist/middleware/logger.d.ts +4 -0
  351. package/dist/middleware/logger.d.ts.map +1 -0
  352. package/dist/middleware/logger.js +92 -0
  353. package/dist/middleware/logger.js.map +1 -0
  354. package/dist/middleware/private-hostname-guard.d.ts +11 -0
  355. package/dist/middleware/private-hostname-guard.d.ts.map +1 -0
  356. package/dist/middleware/private-hostname-guard.js +78 -0
  357. package/dist/middleware/private-hostname-guard.js.map +1 -0
  358. package/dist/middleware/validate.d.ts +4 -0
  359. package/dist/middleware/validate.d.ts.map +1 -0
  360. package/dist/middleware/validate.js +7 -0
  361. package/dist/middleware/validate.js.map +1 -0
  362. package/dist/onboarding-assets/ceo/AGENTS.md +59 -0
  363. package/dist/onboarding-assets/ceo/HEARTBEAT.md +85 -0
  364. package/dist/onboarding-assets/ceo/SOUL.md +33 -0
  365. package/dist/onboarding-assets/ceo/TOOLS.md +3 -0
  366. package/dist/onboarding-assets/default/AGENTS.md +17 -0
  367. package/dist/paths.d.ts +3 -0
  368. package/dist/paths.d.ts.map +1 -0
  369. package/dist/paths.js +31 -0
  370. package/dist/paths.js.map +1 -0
  371. package/dist/realtime/live-events-ws.d.ts +28 -0
  372. package/dist/realtime/live-events-ws.d.ts.map +1 -0
  373. package/dist/realtime/live-events-ws.js +187 -0
  374. package/dist/realtime/live-events-ws.js.map +1 -0
  375. package/dist/redaction.d.ts +5 -0
  376. package/dist/redaction.d.ts.map +1 -0
  377. package/dist/redaction.js +98 -0
  378. package/dist/redaction.js.map +1 -0
  379. package/dist/routes/__tests__/deal-desk-thesis.test.d.ts +2 -0
  380. package/dist/routes/__tests__/deal-desk-thesis.test.d.ts.map +1 -0
  381. package/dist/routes/__tests__/deal-desk-thesis.test.js +53 -0
  382. package/dist/routes/__tests__/deal-desk-thesis.test.js.map +1 -0
  383. package/dist/routes/__tests__/gmail-oauth.test.d.ts +2 -0
  384. package/dist/routes/__tests__/gmail-oauth.test.d.ts.map +1 -0
  385. package/dist/routes/__tests__/gmail-oauth.test.js +99 -0
  386. package/dist/routes/__tests__/gmail-oauth.test.js.map +1 -0
  387. package/dist/routes/access.d.ts +82 -0
  388. package/dist/routes/access.d.ts.map +1 -0
  389. package/dist/routes/access.js +3411 -0
  390. package/dist/routes/access.js.map +1 -0
  391. package/dist/routes/activity.d.ts +3 -0
  392. package/dist/routes/activity.d.ts.map +1 -0
  393. package/dist/routes/activity.js +90 -0
  394. package/dist/routes/activity.js.map +1 -0
  395. package/dist/routes/adapters.d.ts +16 -0
  396. package/dist/routes/adapters.d.ts.map +1 -0
  397. package/dist/routes/adapters.js +527 -0
  398. package/dist/routes/adapters.js.map +1 -0
  399. package/dist/routes/agents.d.ts +6 -0
  400. package/dist/routes/agents.d.ts.map +1 -0
  401. package/dist/routes/agents.js +2765 -0
  402. package/dist/routes/agents.js.map +1 -0
  403. package/dist/routes/approvals.d.ts +6 -0
  404. package/dist/routes/approvals.d.ts.map +1 -0
  405. package/dist/routes/approvals.js +300 -0
  406. package/dist/routes/approvals.js.map +1 -0
  407. package/dist/routes/assets.d.ts +4 -0
  408. package/dist/routes/assets.d.ts.map +1 -0
  409. package/dist/routes/assets.js +309 -0
  410. package/dist/routes/assets.js.map +1 -0
  411. package/dist/routes/auth.d.ts +3 -0
  412. package/dist/routes/auth.d.ts.map +1 -0
  413. package/dist/routes/auth.js +82 -0
  414. package/dist/routes/auth.js.map +1 -0
  415. package/dist/routes/authz.d.ts +19 -0
  416. package/dist/routes/authz.d.ts.map +1 -0
  417. package/dist/routes/authz.js +75 -0
  418. package/dist/routes/authz.js.map +1 -0
  419. package/dist/routes/companies.d.ts +4 -0
  420. package/dist/routes/companies.d.ts.map +1 -0
  421. package/dist/routes/companies.js +359 -0
  422. package/dist/routes/companies.js.map +1 -0
  423. package/dist/routes/company-skills.d.ts +3 -0
  424. package/dist/routes/company-skills.d.ts.map +1 -0
  425. package/dist/routes/company-skills.js +258 -0
  426. package/dist/routes/company-skills.js.map +1 -0
  427. package/dist/routes/costs.d.ts +11 -0
  428. package/dist/routes/costs.d.ts.map +1 -0
  429. package/dist/routes/costs.js +307 -0
  430. package/dist/routes/costs.js.map +1 -0
  431. package/dist/routes/dashboard.d.ts +3 -0
  432. package/dist/routes/dashboard.d.ts.map +1 -0
  433. package/dist/routes/dashboard.js +15 -0
  434. package/dist/routes/dashboard.js.map +1 -0
  435. package/dist/routes/deal-desk.d.ts +83 -0
  436. package/dist/routes/deal-desk.d.ts.map +1 -0
  437. package/dist/routes/deal-desk.js +288 -0
  438. package/dist/routes/deal-desk.js.map +1 -0
  439. package/dist/routes/deal-desk.test.d.ts +2 -0
  440. package/dist/routes/deal-desk.test.d.ts.map +1 -0
  441. package/dist/routes/deal-desk.test.js +291 -0
  442. package/dist/routes/deal-desk.test.js.map +1 -0
  443. package/dist/routes/environment-selection.d.ts +13 -0
  444. package/dist/routes/environment-selection.d.ts.map +1 -0
  445. package/dist/routes/environment-selection.js +30 -0
  446. package/dist/routes/environment-selection.js.map +1 -0
  447. package/dist/routes/environments.d.ts +6 -0
  448. package/dist/routes/environments.d.ts.map +1 -0
  449. package/dist/routes/environments.js +408 -0
  450. package/dist/routes/environments.js.map +1 -0
  451. package/dist/routes/execution-workspaces.d.ts +3 -0
  452. package/dist/routes/execution-workspaces.d.ts.map +1 -0
  453. package/dist/routes/execution-workspaces.js +536 -0
  454. package/dist/routes/execution-workspaces.js.map +1 -0
  455. package/dist/routes/gmail-oauth.d.ts +14 -0
  456. package/dist/routes/gmail-oauth.d.ts.map +1 -0
  457. package/dist/routes/gmail-oauth.js +124 -0
  458. package/dist/routes/gmail-oauth.js.map +1 -0
  459. package/dist/routes/goals.d.ts +3 -0
  460. package/dist/routes/goals.d.ts.map +1 -0
  461. package/dist/routes/goals.js +101 -0
  462. package/dist/routes/goals.js.map +1 -0
  463. package/dist/routes/health.d.ts +9 -0
  464. package/dist/routes/health.d.ts.map +1 -0
  465. package/dist/routes/health.js +114 -0
  466. package/dist/routes/health.js.map +1 -0
  467. package/dist/routes/inbox-dismissals.d.ts +3 -0
  468. package/dist/routes/inbox-dismissals.d.ts.map +1 -0
  469. package/dist/routes/inbox-dismissals.js +58 -0
  470. package/dist/routes/inbox-dismissals.js.map +1 -0
  471. package/dist/routes/index.d.ts +21 -0
  472. package/dist/routes/index.d.ts.map +1 -0
  473. package/dist/routes/index.js +21 -0
  474. package/dist/routes/index.js.map +1 -0
  475. package/dist/routes/instance-database-backups.d.ts +15 -0
  476. package/dist/routes/instance-database-backups.d.ts.map +1 -0
  477. package/dist/routes/instance-database-backups.js +12 -0
  478. package/dist/routes/instance-database-backups.js.map +1 -0
  479. package/dist/routes/instance-settings.d.ts +3 -0
  480. package/dist/routes/instance-settings.d.ts.map +1 -0
  481. package/dist/routes/instance-settings.js +110 -0
  482. package/dist/routes/instance-settings.js.map +1 -0
  483. package/dist/routes/issue-tree-control.d.ts +3 -0
  484. package/dist/routes/issue-tree-control.d.ts.map +1 -0
  485. package/dist/routes/issue-tree-control.js +363 -0
  486. package/dist/routes/issue-tree-control.js.map +1 -0
  487. package/dist/routes/issues-checkout-wakeup.d.ts +9 -0
  488. package/dist/routes/issues-checkout-wakeup.d.ts.map +1 -0
  489. package/dist/routes/issues-checkout-wakeup.js +12 -0
  490. package/dist/routes/issues-checkout-wakeup.js.map +1 -0
  491. package/dist/routes/issues.d.ts +23 -0
  492. package/dist/routes/issues.d.ts.map +1 -0
  493. package/dist/routes/issues.js +4094 -0
  494. package/dist/routes/issues.js.map +1 -0
  495. package/dist/routes/llms.d.ts +3 -0
  496. package/dist/routes/llms.d.ts.map +1 -0
  497. package/dist/routes/llms.js +80 -0
  498. package/dist/routes/llms.js.map +1 -0
  499. package/dist/routes/org-chart-svg.d.ts +25 -0
  500. package/dist/routes/org-chart-svg.d.ts.map +1 -0
  501. package/dist/routes/org-chart-svg.js +656 -0
  502. package/dist/routes/org-chart-svg.js.map +1 -0
  503. package/dist/routes/plugin-ui-static.d.ts +69 -0
  504. package/dist/routes/plugin-ui-static.d.ts.map +1 -0
  505. package/dist/routes/plugin-ui-static.js +411 -0
  506. package/dist/routes/plugin-ui-static.js.map +1 -0
  507. package/dist/routes/plugins.d.ts +121 -0
  508. package/dist/routes/plugins.d.ts.map +1 -0
  509. package/dist/routes/plugins.js +2184 -0
  510. package/dist/routes/plugins.js.map +1 -0
  511. package/dist/routes/projects.d.ts +3 -0
  512. package/dist/routes/projects.d.ts.map +1 -0
  513. package/dist/routes/projects.js +572 -0
  514. package/dist/routes/projects.js.map +1 -0
  515. package/dist/routes/routines.d.ts +6 -0
  516. package/dist/routes/routines.d.ts.map +1 -0
  517. package/dist/routes/routines.js +417 -0
  518. package/dist/routes/routines.js.map +1 -0
  519. package/dist/routes/secrets.d.ts +3 -0
  520. package/dist/routes/secrets.d.ts.map +1 -0
  521. package/dist/routes/secrets.js +392 -0
  522. package/dist/routes/secrets.js.map +1 -0
  523. package/dist/routes/sidebar-badges.d.ts +3 -0
  524. package/dist/routes/sidebar-badges.d.ts.map +1 -0
  525. package/dist/routes/sidebar-badges.js +68 -0
  526. package/dist/routes/sidebar-badges.js.map +1 -0
  527. package/dist/routes/sidebar-preferences.d.ts +3 -0
  528. package/dist/routes/sidebar-preferences.d.ts.map +1 -0
  529. package/dist/routes/sidebar-preferences.js +63 -0
  530. package/dist/routes/sidebar-preferences.js.map +1 -0
  531. package/dist/routes/user-profiles.d.ts +3 -0
  532. package/dist/routes/user-profiles.d.ts.map +1 -0
  533. package/dist/routes/user-profiles.js +337 -0
  534. package/dist/routes/user-profiles.js.map +1 -0
  535. package/dist/routes/workspace-command-authz.d.ts +14 -0
  536. package/dist/routes/workspace-command-authz.d.ts.map +1 -0
  537. package/dist/routes/workspace-command-authz.js +83 -0
  538. package/dist/routes/workspace-command-authz.js.map +1 -0
  539. package/dist/routes/workspace-runtime-service-authz.d.ts +12 -0
  540. package/dist/routes/workspace-runtime-service-authz.d.ts.map +1 -0
  541. package/dist/routes/workspace-runtime-service-authz.js +96 -0
  542. package/dist/routes/workspace-runtime-service-authz.js.map +1 -0
  543. package/dist/runtime-api.d.ts +19 -0
  544. package/dist/runtime-api.d.ts.map +1 -0
  545. package/dist/runtime-api.js +137 -0
  546. package/dist/runtime-api.js.map +1 -0
  547. package/dist/secrets/aws-secrets-manager-provider.d.ts +87 -0
  548. package/dist/secrets/aws-secrets-manager-provider.d.ts.map +1 -0
  549. package/dist/secrets/aws-secrets-manager-provider.js +748 -0
  550. package/dist/secrets/aws-secrets-manager-provider.js.map +1 -0
  551. package/dist/secrets/configured-provider.d.ts +3 -0
  552. package/dist/secrets/configured-provider.d.ts.map +1 -0
  553. package/dist/secrets/configured-provider.js +8 -0
  554. package/dist/secrets/configured-provider.js.map +1 -0
  555. package/dist/secrets/external-stub-providers.d.ts +5 -0
  556. package/dist/secrets/external-stub-providers.d.ts.map +1 -0
  557. package/dist/secrets/external-stub-providers.js +71 -0
  558. package/dist/secrets/external-stub-providers.js.map +1 -0
  559. package/dist/secrets/local-encrypted-provider.d.ts +3 -0
  560. package/dist/secrets/local-encrypted-provider.d.ts.map +1 -0
  561. package/dist/secrets/local-encrypted-provider.js +244 -0
  562. package/dist/secrets/local-encrypted-provider.js.map +1 -0
  563. package/dist/secrets/provider-registry.d.ts +6 -0
  564. package/dist/secrets/provider-registry.d.ts.map +1 -0
  565. package/dist/secrets/provider-registry.js +24 -0
  566. package/dist/secrets/provider-registry.js.map +1 -0
  567. package/dist/secrets/types.d.ts +131 -0
  568. package/dist/secrets/types.d.ts.map +1 -0
  569. package/dist/secrets/types.js +36 -0
  570. package/dist/secrets/types.js.map +1 -0
  571. package/dist/services/access.d.ts +171 -0
  572. package/dist/services/access.d.ts.map +1 -0
  573. package/dist/services/access.js +522 -0
  574. package/dist/services/access.js.map +1 -0
  575. package/dist/services/activity-log.d.ts +19 -0
  576. package/dist/services/activity-log.d.ts.map +1 -0
  577. package/dist/services/activity-log.js +99 -0
  578. package/dist/services/activity-log.js.map +1 -0
  579. package/dist/services/activity.d.ts +462 -0
  580. package/dist/services/activity.d.ts.map +1 -0
  581. package/dist/services/activity.js +443 -0
  582. package/dist/services/activity.js.map +1 -0
  583. package/dist/services/adapter-plugin-store.d.ts +36 -0
  584. package/dist/services/adapter-plugin-store.d.ts.map +1 -0
  585. package/dist/services/adapter-plugin-store.js +154 -0
  586. package/dist/services/adapter-plugin-store.js.map +1 -0
  587. package/dist/services/agent-instructions.d.ts +91 -0
  588. package/dist/services/agent-instructions.d.ts.map +1 -0
  589. package/dist/services/agent-instructions.js +580 -0
  590. package/dist/services/agent-instructions.js.map +1 -0
  591. package/dist/services/agent-permissions.d.ts +6 -0
  592. package/dist/services/agent-permissions.d.ts.map +1 -0
  593. package/dist/services/agent-permissions.js +18 -0
  594. package/dist/services/agent-permissions.js.map +1 -0
  595. package/dist/services/agent-start-lock.d.ts +2 -0
  596. package/dist/services/agent-start-lock.d.ts.map +1 -0
  597. package/dist/services/agent-start-lock.js +43 -0
  598. package/dist/services/agent-start-lock.js.map +1 -0
  599. package/dist/services/agents.d.ts +2253 -0
  600. package/dist/services/agents.d.ts.map +1 -0
  601. package/dist/services/agents.js +609 -0
  602. package/dist/services/agents.js.map +1 -0
  603. package/dist/services/approvals.d.ts +546 -0
  604. package/dist/services/approvals.d.ts.map +1 -0
  605. package/dist/services/approvals.js +212 -0
  606. package/dist/services/approvals.js.map +1 -0
  607. package/dist/services/assets.d.ts +33 -0
  608. package/dist/services/assets.d.ts.map +1 -0
  609. package/dist/services/assets.js +17 -0
  610. package/dist/services/assets.js.map +1 -0
  611. package/dist/services/board-auth.d.ts +239 -0
  612. package/dist/services/board-auth.d.ts.map +1 -0
  613. package/dist/services/board-auth.js +300 -0
  614. package/dist/services/board-auth.js.map +1 -0
  615. package/dist/services/budgets.d.ts +38 -0
  616. package/dist/services/budgets.d.ts.map +1 -0
  617. package/dist/services/budgets.js +784 -0
  618. package/dist/services/budgets.js.map +1 -0
  619. package/dist/services/companies.d.ts +154 -0
  620. package/dist/services/companies.d.ts.map +1 -0
  621. package/dist/services/companies.js +286 -0
  622. package/dist/services/companies.js.map +1 -0
  623. package/dist/services/company-export-readme.d.ts +17 -0
  624. package/dist/services/company-export-readme.d.ts.map +1 -0
  625. package/dist/services/company-export-readme.js +148 -0
  626. package/dist/services/company-export-readme.js.map +1 -0
  627. package/dist/services/company-member-roles.d.ts +9 -0
  628. package/dist/services/company-member-roles.d.ts.map +1 -0
  629. package/dist/services/company-member-roles.js +46 -0
  630. package/dist/services/company-member-roles.js.map +1 -0
  631. package/dist/services/company-portability.d.ts +24 -0
  632. package/dist/services/company-portability.d.ts.map +1 -0
  633. package/dist/services/company-portability.js +4077 -0
  634. package/dist/services/company-portability.js.map +1 -0
  635. package/dist/services/company-search-rate-limit.d.ts +22 -0
  636. package/dist/services/company-search-rate-limit.d.ts.map +1 -0
  637. package/dist/services/company-search-rate-limit.js +38 -0
  638. package/dist/services/company-search-rate-limit.js.map +1 -0
  639. package/dist/services/company-search.d.ts +8 -0
  640. package/dist/services/company-search.d.ts.map +1 -0
  641. package/dist/services/company-search.js +626 -0
  642. package/dist/services/company-search.js.map +1 -0
  643. package/dist/services/company-skills.d.ts +77 -0
  644. package/dist/services/company-skills.d.ts.map +1 -0
  645. package/dist/services/company-skills.js +2131 -0
  646. package/dist/services/company-skills.js.map +1 -0
  647. package/dist/services/cost-backfill.d.ts +16 -0
  648. package/dist/services/cost-backfill.d.ts.map +1 -0
  649. package/dist/services/cost-backfill.js +115 -0
  650. package/dist/services/cost-backfill.js.map +1 -0
  651. package/dist/services/cost-ledger.d.ts +28 -0
  652. package/dist/services/cost-ledger.d.ts.map +1 -0
  653. package/dist/services/cost-ledger.js +140 -0
  654. package/dist/services/cost-ledger.js.map +1 -0
  655. package/dist/services/cost-ledger.test.d.ts +2 -0
  656. package/dist/services/cost-ledger.test.d.ts.map +1 -0
  657. package/dist/services/cost-ledger.test.js +50 -0
  658. package/dist/services/cost-ledger.test.js.map +1 -0
  659. package/dist/services/cost-pipeline-health.d.ts +4 -0
  660. package/dist/services/cost-pipeline-health.d.ts.map +1 -0
  661. package/dist/services/cost-pipeline-health.js +42 -0
  662. package/dist/services/cost-pipeline-health.js.map +1 -0
  663. package/dist/services/costs.d.ts +128 -0
  664. package/dist/services/costs.d.ts.map +1 -0
  665. package/dist/services/costs.js +412 -0
  666. package/dist/services/costs.js.map +1 -0
  667. package/dist/services/cron.d.ts +80 -0
  668. package/dist/services/cron.d.ts.map +1 -0
  669. package/dist/services/cron.js +300 -0
  670. package/dist/services/cron.js.map +1 -0
  671. package/dist/services/dashboard.d.ts +34 -0
  672. package/dist/services/dashboard.d.ts.map +1 -0
  673. package/dist/services/dashboard.js +142 -0
  674. package/dist/services/dashboard.js.map +1 -0
  675. package/dist/services/default-agent-instructions.d.ts +9 -0
  676. package/dist/services/default-agent-instructions.d.ts.map +1 -0
  677. package/dist/services/default-agent-instructions.js +20 -0
  678. package/dist/services/default-agent-instructions.js.map +1 -0
  679. package/dist/services/documents.d.ts +199 -0
  680. package/dist/services/documents.d.ts.map +1 -0
  681. package/dist/services/documents.js +411 -0
  682. package/dist/services/documents.js.map +1 -0
  683. package/dist/services/environment-config.d.ts +55 -0
  684. package/dist/services/environment-config.d.ts.map +1 -0
  685. package/dist/services/environment-config.js +441 -0
  686. package/dist/services/environment-config.js.map +1 -0
  687. package/dist/services/environment-execution-target.d.ts +21 -0
  688. package/dist/services/environment-execution-target.d.ts.map +1 -0
  689. package/dist/services/environment-execution-target.js +121 -0
  690. package/dist/services/environment-execution-target.js.map +1 -0
  691. package/dist/services/environment-probe.d.ts +9 -0
  692. package/dist/services/environment-probe.d.ts.map +1 -0
  693. package/dist/services/environment-probe.js +106 -0
  694. package/dist/services/environment-probe.js.map +1 -0
  695. package/dist/services/environment-run-orchestrator.d.ts +124 -0
  696. package/dist/services/environment-run-orchestrator.d.ts.map +1 -0
  697. package/dist/services/environment-run-orchestrator.js +392 -0
  698. package/dist/services/environment-run-orchestrator.js.map +1 -0
  699. package/dist/services/environment-runtime.d.ts +90 -0
  700. package/dist/services/environment-runtime.d.ts.map +1 -0
  701. package/dist/services/environment-runtime.js +968 -0
  702. package/dist/services/environment-runtime.js.map +1 -0
  703. package/dist/services/environments.d.ts +36 -0
  704. package/dist/services/environments.d.ts.map +1 -0
  705. package/dist/services/environments.js +260 -0
  706. package/dist/services/environments.js.map +1 -0
  707. package/dist/services/execution-workspace-policy.d.ts +30 -0
  708. package/dist/services/execution-workspace-policy.d.ts.map +1 -0
  709. package/dist/services/execution-workspace-policy.js +195 -0
  710. package/dist/services/execution-workspace-policy.js.map +1 -0
  711. package/dist/services/execution-workspaces.d.ts +30 -0
  712. package/dist/services/execution-workspaces.d.ts.map +1 -0
  713. package/dist/services/execution-workspaces.js +635 -0
  714. package/dist/services/execution-workspaces.js.map +1 -0
  715. package/dist/services/feedback-redaction.d.ts +23 -0
  716. package/dist/services/feedback-redaction.d.ts.map +1 -0
  717. package/dist/services/feedback-redaction.js +150 -0
  718. package/dist/services/feedback-redaction.js.map +1 -0
  719. package/dist/services/feedback-share-client.d.ts +9 -0
  720. package/dist/services/feedback-share-client.d.ts.map +1 -0
  721. package/dist/services/feedback-share-client.js +46 -0
  722. package/dist/services/feedback-share-client.js.map +1 -0
  723. package/dist/services/feedback.d.ts +93 -0
  724. package/dist/services/feedback.d.ts.map +1 -0
  725. package/dist/services/feedback.js +1717 -0
  726. package/dist/services/feedback.js.map +1 -0
  727. package/dist/services/finance.d.ts +93 -0
  728. package/dist/services/finance.d.ts.map +1 -0
  729. package/dist/services/finance.js +120 -0
  730. package/dist/services/finance.js.map +1 -0
  731. package/dist/services/github-fetch.d.ts +4 -0
  732. package/dist/services/github-fetch.d.ts.map +1 -0
  733. package/dist/services/github-fetch.js +23 -0
  734. package/dist/services/github-fetch.js.map +1 -0
  735. package/dist/services/goals.d.ts +433 -0
  736. package/dist/services/goals.d.ts.map +1 -0
  737. package/dist/services/goals.js +54 -0
  738. package/dist/services/goals.js.map +1 -0
  739. package/dist/services/heartbeat-run-summary.d.ts +7 -0
  740. package/dist/services/heartbeat-run-summary.d.ts.map +1 -0
  741. package/dist/services/heartbeat-run-summary.js +84 -0
  742. package/dist/services/heartbeat-run-summary.js.map +1 -0
  743. package/dist/services/heartbeat-stop-metadata.d.ts +28 -0
  744. package/dist/services/heartbeat-stop-metadata.d.ts.map +1 -0
  745. package/dist/services/heartbeat-stop-metadata.js +86 -0
  746. package/dist/services/heartbeat-stop-metadata.js.map +1 -0
  747. package/dist/services/heartbeat-stop-metadata.test.d.ts +2 -0
  748. package/dist/services/heartbeat-stop-metadata.test.d.ts.map +1 -0
  749. package/dist/services/heartbeat-stop-metadata.test.js +93 -0
  750. package/dist/services/heartbeat-stop-metadata.test.js.map +1 -0
  751. package/dist/services/heartbeat.d.ts +1546 -0
  752. package/dist/services/heartbeat.d.ts.map +1 -0
  753. package/dist/services/heartbeat.js +7854 -0
  754. package/dist/services/heartbeat.js.map +1 -0
  755. package/dist/services/hire-hook.d.ts +14 -0
  756. package/dist/services/hire-hook.d.ts.map +1 -0
  757. package/dist/services/hire-hook.js +85 -0
  758. package/dist/services/hire-hook.js.map +1 -0
  759. package/dist/services/inbox-dismissals.d.ts +22 -0
  760. package/dist/services/inbox-dismissals.d.ts.map +1 -0
  761. package/dist/services/inbox-dismissals.js +33 -0
  762. package/dist/services/inbox-dismissals.js.map +1 -0
  763. package/dist/services/index.d.ts +45 -0
  764. package/dist/services/index.d.ts.map +1 -0
  765. package/dist/services/index.js +45 -0
  766. package/dist/services/index.js.map +1 -0
  767. package/dist/services/instance-settings.d.ts +11 -0
  768. package/dist/services/instance-settings.d.ts.map +1 -0
  769. package/dist/services/instance-settings.js +138 -0
  770. package/dist/services/instance-settings.js.map +1 -0
  771. package/dist/services/invite-grants.d.ts +15 -0
  772. package/dist/services/invite-grants.d.ts.map +1 -0
  773. package/dist/services/invite-grants.js +50 -0
  774. package/dist/services/invite-grants.js.map +1 -0
  775. package/dist/services/issue-approvals.d.ts +56 -0
  776. package/dist/services/issue-approvals.d.ts.map +1 -0
  777. package/dist/services/issue-approvals.js +153 -0
  778. package/dist/services/issue-approvals.js.map +1 -0
  779. package/dist/services/issue-assignment-wakeup.d.ts +29 -0
  780. package/dist/services/issue-assignment-wakeup.d.ts.map +1 -0
  781. package/dist/services/issue-assignment-wakeup.js +22 -0
  782. package/dist/services/issue-assignment-wakeup.js.map +1 -0
  783. package/dist/services/issue-continuation-summary.d.ts +68 -0
  784. package/dist/services/issue-continuation-summary.d.ts.map +1 -0
  785. package/dist/services/issue-continuation-summary.js +222 -0
  786. package/dist/services/issue-continuation-summary.js.map +1 -0
  787. package/dist/services/issue-execution-policy.d.ts +93 -0
  788. package/dist/services/issue-execution-policy.d.ts.map +1 -0
  789. package/dist/services/issue-execution-policy.js +838 -0
  790. package/dist/services/issue-execution-policy.js.map +1 -0
  791. package/dist/services/issue-goal-fallback.d.ts +18 -0
  792. package/dist/services/issue-goal-fallback.d.ts.map +1 -0
  793. package/dist/services/issue-goal-fallback.js +33 -0
  794. package/dist/services/issue-goal-fallback.js.map +1 -0
  795. package/dist/services/issue-liveness.d.ts +3 -0
  796. package/dist/services/issue-liveness.d.ts.map +1 -0
  797. package/dist/services/issue-liveness.js +2 -0
  798. package/dist/services/issue-liveness.js.map +1 -0
  799. package/dist/services/issue-recovery-actions.d.ts +40 -0
  800. package/dist/services/issue-recovery-actions.d.ts.map +1 -0
  801. package/dist/services/issue-recovery-actions.js +204 -0
  802. package/dist/services/issue-recovery-actions.js.map +1 -0
  803. package/dist/services/issue-references.d.ts +21 -0
  804. package/dist/services/issue-references.d.ts.map +1 -0
  805. package/dist/services/issue-references.js +318 -0
  806. package/dist/services/issue-references.js.map +1 -0
  807. package/dist/services/issue-thread-interactions.d.ts +76 -0
  808. package/dist/services/issue-thread-interactions.d.ts.map +1 -0
  809. package/dist/services/issue-thread-interactions.js +923 -0
  810. package/dist/services/issue-thread-interactions.js.map +1 -0
  811. package/dist/services/issue-thread-interactions.test.d.ts +2 -0
  812. package/dist/services/issue-thread-interactions.test.d.ts.map +1 -0
  813. package/dist/services/issue-thread-interactions.test.js +195 -0
  814. package/dist/services/issue-thread-interactions.test.js.map +1 -0
  815. package/dist/services/issue-tree-control.d.ts +89 -0
  816. package/dist/services/issue-tree-control.d.ts.map +1 -0
  817. package/dist/services/issue-tree-control.js +933 -0
  818. package/dist/services/issue-tree-control.js.map +1 -0
  819. package/dist/services/issues.d.ts +744 -0
  820. package/dist/services/issues.d.ts.map +1 -0
  821. package/dist/services/issues.js +3374 -0
  822. package/dist/services/issues.js.map +1 -0
  823. package/dist/services/json-schema-secret-refs.d.ts +5 -0
  824. package/dist/services/json-schema-secret-refs.d.ts.map +1 -0
  825. package/dist/services/json-schema-secret-refs.js +67 -0
  826. package/dist/services/json-schema-secret-refs.js.map +1 -0
  827. package/dist/services/live-events.d.ts +17 -0
  828. package/dist/services/live-events.d.ts.map +1 -0
  829. package/dist/services/live-events.js +33 -0
  830. package/dist/services/live-events.js.map +1 -0
  831. package/dist/services/local-service-supervisor.d.ts +56 -0
  832. package/dist/services/local-service-supervisor.d.ts.map +1 -0
  833. package/dist/services/local-service-supervisor.js +284 -0
  834. package/dist/services/local-service-supervisor.js.map +1 -0
  835. package/dist/services/plugin-capability-validator.d.ts +108 -0
  836. package/dist/services/plugin-capability-validator.d.ts.map +1 -0
  837. package/dist/services/plugin-capability-validator.js +313 -0
  838. package/dist/services/plugin-capability-validator.js.map +1 -0
  839. package/dist/services/plugin-config-validator.d.ts +26 -0
  840. package/dist/services/plugin-config-validator.d.ts.map +1 -0
  841. package/dist/services/plugin-config-validator.js +41 -0
  842. package/dist/services/plugin-config-validator.js.map +1 -0
  843. package/dist/services/plugin-database.d.ts +49 -0
  844. package/dist/services/plugin-database.d.ts.map +1 -0
  845. package/dist/services/plugin-database.js +440 -0
  846. package/dist/services/plugin-database.js.map +1 -0
  847. package/dist/services/plugin-dev-watcher.d.ts +30 -0
  848. package/dist/services/plugin-dev-watcher.d.ts.map +1 -0
  849. package/dist/services/plugin-dev-watcher.js +246 -0
  850. package/dist/services/plugin-dev-watcher.js.map +1 -0
  851. package/dist/services/plugin-environment-driver.d.ts +126 -0
  852. package/dist/services/plugin-environment-driver.d.ts.map +1 -0
  853. package/dist/services/plugin-environment-driver.js +226 -0
  854. package/dist/services/plugin-environment-driver.js.map +1 -0
  855. package/dist/services/plugin-event-bus.d.ts +149 -0
  856. package/dist/services/plugin-event-bus.d.ts.map +1 -0
  857. package/dist/services/plugin-event-bus.js +258 -0
  858. package/dist/services/plugin-event-bus.js.map +1 -0
  859. package/dist/services/plugin-host-service-cleanup.d.ts +14 -0
  860. package/dist/services/plugin-host-service-cleanup.d.ts.map +1 -0
  861. package/dist/services/plugin-host-service-cleanup.js +37 -0
  862. package/dist/services/plugin-host-service-cleanup.js.map +1 -0
  863. package/dist/services/plugin-host-services.d.ts +17 -0
  864. package/dist/services/plugin-host-services.d.ts.map +1 -0
  865. package/dist/services/plugin-host-services.js +1867 -0
  866. package/dist/services/plugin-host-services.js.map +1 -0
  867. package/dist/services/plugin-job-coordinator.d.ts +81 -0
  868. package/dist/services/plugin-job-coordinator.d.ts.map +1 -0
  869. package/dist/services/plugin-job-coordinator.js +172 -0
  870. package/dist/services/plugin-job-coordinator.js.map +1 -0
  871. package/dist/services/plugin-job-scheduler.d.ts +163 -0
  872. package/dist/services/plugin-job-scheduler.d.ts.map +1 -0
  873. package/dist/services/plugin-job-scheduler.js +459 -0
  874. package/dist/services/plugin-job-scheduler.js.map +1 -0
  875. package/dist/services/plugin-job-store.d.ts +208 -0
  876. package/dist/services/plugin-job-store.d.ts.map +1 -0
  877. package/dist/services/plugin-job-store.js +350 -0
  878. package/dist/services/plugin-job-store.js.map +1 -0
  879. package/dist/services/plugin-lifecycle.d.ts +203 -0
  880. package/dist/services/plugin-lifecycle.d.ts.map +1 -0
  881. package/dist/services/plugin-lifecycle.js +476 -0
  882. package/dist/services/plugin-lifecycle.js.map +1 -0
  883. package/dist/services/plugin-loader.d.ts +445 -0
  884. package/dist/services/plugin-loader.d.ts.map +1 -0
  885. package/dist/services/plugin-loader.js +1273 -0
  886. package/dist/services/plugin-loader.js.map +1 -0
  887. package/dist/services/plugin-local-folders.d.ts +49 -0
  888. package/dist/services/plugin-local-folders.d.ts.map +1 -0
  889. package/dist/services/plugin-local-folders.js +506 -0
  890. package/dist/services/plugin-local-folders.js.map +1 -0
  891. package/dist/services/plugin-log-retention.d.ts +20 -0
  892. package/dist/services/plugin-log-retention.d.ts.map +1 -0
  893. package/dist/services/plugin-log-retention.js +63 -0
  894. package/dist/services/plugin-log-retention.js.map +1 -0
  895. package/dist/services/plugin-managed-agents.d.ts +15 -0
  896. package/dist/services/plugin-managed-agents.d.ts.map +1 -0
  897. package/dist/services/plugin-managed-agents.js +458 -0
  898. package/dist/services/plugin-managed-agents.js.map +1 -0
  899. package/dist/services/plugin-managed-routines.d.ts +41 -0
  900. package/dist/services/plugin-managed-routines.d.ts.map +1 -0
  901. package/dist/services/plugin-managed-routines.js +416 -0
  902. package/dist/services/plugin-managed-routines.js.map +1 -0
  903. package/dist/services/plugin-managed-skills.d.ts +14 -0
  904. package/dist/services/plugin-managed-skills.d.ts.map +1 -0
  905. package/dist/services/plugin-managed-skills.js +264 -0
  906. package/dist/services/plugin-managed-skills.js.map +1 -0
  907. package/dist/services/plugin-manifest-validator.d.ts +79 -0
  908. package/dist/services/plugin-manifest-validator.d.ts.map +1 -0
  909. package/dist/services/plugin-manifest-validator.js +84 -0
  910. package/dist/services/plugin-manifest-validator.js.map +1 -0
  911. package/dist/services/plugin-registry.d.ts +2550 -0
  912. package/dist/services/plugin-registry.d.ts.map +1 -0
  913. package/dist/services/plugin-registry.js +581 -0
  914. package/dist/services/plugin-registry.js.map +1 -0
  915. package/dist/services/plugin-runtime-sandbox.d.ts +40 -0
  916. package/dist/services/plugin-runtime-sandbox.d.ts.map +1 -0
  917. package/dist/services/plugin-runtime-sandbox.js +154 -0
  918. package/dist/services/plugin-runtime-sandbox.js.map +1 -0
  919. package/dist/services/plugin-secrets-handler.d.ts +83 -0
  920. package/dist/services/plugin-secrets-handler.d.ts.map +1 -0
  921. package/dist/services/plugin-secrets-handler.js +168 -0
  922. package/dist/services/plugin-secrets-handler.js.map +1 -0
  923. package/dist/services/plugin-state-store.d.ts +92 -0
  924. package/dist/services/plugin-state-store.d.ts.map +1 -0
  925. package/dist/services/plugin-state-store.js +190 -0
  926. package/dist/services/plugin-state-store.js.map +1 -0
  927. package/dist/services/plugin-stream-bus.d.ts +29 -0
  928. package/dist/services/plugin-stream-bus.d.ts.map +1 -0
  929. package/dist/services/plugin-stream-bus.js +48 -0
  930. package/dist/services/plugin-stream-bus.js.map +1 -0
  931. package/dist/services/plugin-tool-dispatcher.d.ts +180 -0
  932. package/dist/services/plugin-tool-dispatcher.d.ts.map +1 -0
  933. package/dist/services/plugin-tool-dispatcher.js +224 -0
  934. package/dist/services/plugin-tool-dispatcher.js.map +1 -0
  935. package/dist/services/plugin-tool-registry.d.ts +192 -0
  936. package/dist/services/plugin-tool-registry.d.ts.map +1 -0
  937. package/dist/services/plugin-tool-registry.js +224 -0
  938. package/dist/services/plugin-tool-registry.js.map +1 -0
  939. package/dist/services/plugin-worker-manager.d.ts +262 -0
  940. package/dist/services/plugin-worker-manager.d.ts.map +1 -0
  941. package/dist/services/plugin-worker-manager.js +842 -0
  942. package/dist/services/plugin-worker-manager.js.map +1 -0
  943. package/dist/services/productivity-review.d.ts +83 -0
  944. package/dist/services/productivity-review.d.ts.map +1 -0
  945. package/dist/services/productivity-review.js +652 -0
  946. package/dist/services/productivity-review.js.map +1 -0
  947. package/dist/services/project-workspace-runtime-config.d.ts +4 -0
  948. package/dist/services/project-workspace-runtime-config.d.ts.map +1 -0
  949. package/dist/services/project-workspace-runtime-config.js +54 -0
  950. package/dist/services/project-workspace-runtime-config.js.map +1 -0
  951. package/dist/services/projects.d.ts +99 -0
  952. package/dist/services/projects.d.ts.map +1 -0
  953. package/dist/services/projects.js +822 -0
  954. package/dist/services/projects.js.map +1 -0
  955. package/dist/services/quota-windows.d.ts +9 -0
  956. package/dist/services/quota-windows.d.ts.map +1 -0
  957. package/dist/services/quota-windows.js +56 -0
  958. package/dist/services/quota-windows.js.map +1 -0
  959. package/dist/services/recovery/index.d.ts +10 -0
  960. package/dist/services/recovery/index.d.ts.map +1 -0
  961. package/dist/services/recovery/index.js +6 -0
  962. package/dist/services/recovery/index.js.map +1 -0
  963. package/dist/services/recovery/issue-graph-liveness.d.ts +85 -0
  964. package/dist/services/recovery/issue-graph-liveness.d.ts.map +1 -0
  965. package/dist/services/recovery/issue-graph-liveness.js +356 -0
  966. package/dist/services/recovery/issue-graph-liveness.js.map +1 -0
  967. package/dist/services/recovery/model-profile-hint.d.ts +8 -0
  968. package/dist/services/recovery/model-profile-hint.d.ts.map +1 -0
  969. package/dist/services/recovery/model-profile-hint.js +11 -0
  970. package/dist/services/recovery/model-profile-hint.js.map +1 -0
  971. package/dist/services/recovery/origins.d.ts +36 -0
  972. package/dist/services/recovery/origins.d.ts.map +1 -0
  973. package/dist/services/recovery/origins.js +45 -0
  974. package/dist/services/recovery/origins.js.map +1 -0
  975. package/dist/services/recovery/pause-hold-guard.d.ts +6 -0
  976. package/dist/services/recovery/pause-hold-guard.d.ts.map +1 -0
  977. package/dist/services/recovery/pause-hold-guard.js +6 -0
  978. package/dist/services/recovery/pause-hold-guard.js.map +1 -0
  979. package/dist/services/recovery/run-liveness-continuations.d.ts +50 -0
  980. package/dist/services/recovery/run-liveness-continuations.d.ts.map +1 -0
  981. package/dist/services/recovery/run-liveness-continuations.js +117 -0
  982. package/dist/services/recovery/run-liveness-continuations.js.map +1 -0
  983. package/dist/services/recovery/service.d.ts +256 -0
  984. package/dist/services/recovery/service.d.ts.map +1 -0
  985. package/dist/services/recovery/service.js +2441 -0
  986. package/dist/services/recovery/service.js.map +1 -0
  987. package/dist/services/recovery/successful-run-handoff.d.ts +89 -0
  988. package/dist/services/recovery/successful-run-handoff.d.ts.map +1 -0
  989. package/dist/services/recovery/successful-run-handoff.js +304 -0
  990. package/dist/services/recovery/successful-run-handoff.js.map +1 -0
  991. package/dist/services/recovery/successful-run-handoff.test.d.ts +2 -0
  992. package/dist/services/recovery/successful-run-handoff.test.d.ts.map +1 -0
  993. package/dist/services/recovery/successful-run-handoff.test.js +270 -0
  994. package/dist/services/recovery/successful-run-handoff.test.js.map +1 -0
  995. package/dist/services/routines.d.ts +166 -0
  996. package/dist/services/routines.d.ts.map +1 -0
  997. package/dist/services/routines.js +1969 -0
  998. package/dist/services/routines.js.map +1 -0
  999. package/dist/services/run-continuations.d.ts +3 -0
  1000. package/dist/services/run-continuations.d.ts.map +1 -0
  1001. package/dist/services/run-continuations.js +2 -0
  1002. package/dist/services/run-continuations.js.map +1 -0
  1003. package/dist/services/run-liveness.d.ts +46 -0
  1004. package/dist/services/run-liveness.d.ts.map +1 -0
  1005. package/dist/services/run-liveness.js +275 -0
  1006. package/dist/services/run-liveness.js.map +1 -0
  1007. package/dist/services/run-log-store.d.ts +34 -0
  1008. package/dist/services/run-log-store.d.ts.map +1 -0
  1009. package/dist/services/run-log-store.js +111 -0
  1010. package/dist/services/run-log-store.js.map +1 -0
  1011. package/dist/services/sandbox-provider-runtime.d.ts +132 -0
  1012. package/dist/services/sandbox-provider-runtime.d.ts.map +1 -0
  1013. package/dist/services/sandbox-provider-runtime.js +216 -0
  1014. package/dist/services/sandbox-provider-runtime.js.map +1 -0
  1015. package/dist/services/secrets.d.ts +1962 -0
  1016. package/dist/services/secrets.d.ts.map +1 -0
  1017. package/dist/services/secrets.js +1686 -0
  1018. package/dist/services/secrets.js.map +1 -0
  1019. package/dist/services/sidebar-badges.d.ts +14 -0
  1020. package/dist/services/sidebar-badges.d.ts.map +1 -0
  1021. package/dist/services/sidebar-badges.js +48 -0
  1022. package/dist/services/sidebar-badges.js.map +1 -0
  1023. package/dist/services/sidebar-preferences.d.ts +9 -0
  1024. package/dist/services/sidebar-preferences.d.ts.map +1 -0
  1025. package/dist/services/sidebar-preferences.js +82 -0
  1026. package/dist/services/sidebar-preferences.js.map +1 -0
  1027. package/dist/services/work-products.d.ts +14 -0
  1028. package/dist/services/work-products.d.ts.map +1 -0
  1029. package/dist/services/work-products.js +100 -0
  1030. package/dist/services/work-products.js.map +1 -0
  1031. package/dist/services/workspace-operation-log-store.d.ts +33 -0
  1032. package/dist/services/workspace-operation-log-store.d.ts.map +1 -0
  1033. package/dist/services/workspace-operation-log-store.js +110 -0
  1034. package/dist/services/workspace-operation-log-store.js.map +1 -0
  1035. package/dist/services/workspace-operations.d.ts +44 -0
  1036. package/dist/services/workspace-operations.d.ts.map +1 -0
  1037. package/dist/services/workspace-operations.js +211 -0
  1038. package/dist/services/workspace-operations.js.map +1 -0
  1039. package/dist/services/workspace-realization.d.ts +33 -0
  1040. package/dist/services/workspace-realization.d.ts.map +1 -0
  1041. package/dist/services/workspace-realization.js +221 -0
  1042. package/dist/services/workspace-realization.js.map +1 -0
  1043. package/dist/services/workspace-runtime-read-model.d.ts +92 -0
  1044. package/dist/services/workspace-runtime-read-model.d.ts.map +1 -0
  1045. package/dist/services/workspace-runtime-read-model.js +67 -0
  1046. package/dist/services/workspace-runtime-read-model.js.map +1 -0
  1047. package/dist/services/workspace-runtime.d.ts +238 -0
  1048. package/dist/services/workspace-runtime.d.ts.map +1 -0
  1049. package/dist/services/workspace-runtime.js +2388 -0
  1050. package/dist/services/workspace-runtime.js.map +1 -0
  1051. package/dist/startup-banner.d.ts +32 -0
  1052. package/dist/startup-banner.d.ts.map +1 -0
  1053. package/dist/startup-banner.js +89 -0
  1054. package/dist/startup-banner.js.map +1 -0
  1055. package/dist/storage/index.d.ts +6 -0
  1056. package/dist/storage/index.d.ts.map +1 -0
  1057. package/dist/storage/index.js +29 -0
  1058. package/dist/storage/index.js.map +1 -0
  1059. package/dist/storage/local-disk-provider.d.ts +3 -0
  1060. package/dist/storage/local-disk-provider.d.ts.map +1 -0
  1061. package/dist/storage/local-disk-provider.js +79 -0
  1062. package/dist/storage/local-disk-provider.js.map +1 -0
  1063. package/dist/storage/provider-registry.d.ts +4 -0
  1064. package/dist/storage/provider-registry.d.ts.map +1 -0
  1065. package/dist/storage/provider-registry.js +15 -0
  1066. package/dist/storage/provider-registry.js.map +1 -0
  1067. package/dist/storage/s3-provider.d.ts +11 -0
  1068. package/dist/storage/s3-provider.d.ts.map +1 -0
  1069. package/dist/storage/s3-provider.js +123 -0
  1070. package/dist/storage/s3-provider.js.map +1 -0
  1071. package/dist/storage/service.d.ts +3 -0
  1072. package/dist/storage/service.d.ts.map +1 -0
  1073. package/dist/storage/service.js +120 -0
  1074. package/dist/storage/service.js.map +1 -0
  1075. package/dist/storage/types.d.ts +55 -0
  1076. package/dist/storage/types.d.ts.map +1 -0
  1077. package/dist/storage/types.js +2 -0
  1078. package/dist/storage/types.js.map +1 -0
  1079. package/dist/telemetry.d.ts +6 -0
  1080. package/dist/telemetry.d.ts.map +1 -0
  1081. package/dist/telemetry.js +20 -0
  1082. package/dist/telemetry.js.map +1 -0
  1083. package/dist/ui-branding.d.ts +13 -0
  1084. package/dist/ui-branding.d.ts.map +1 -0
  1085. package/dist/ui-branding.js +188 -0
  1086. package/dist/ui-branding.js.map +1 -0
  1087. package/dist/utils/coalesced-error-logger.d.ts +11 -0
  1088. package/dist/utils/coalesced-error-logger.d.ts.map +1 -0
  1089. package/dist/utils/coalesced-error-logger.js +21 -0
  1090. package/dist/utils/coalesced-error-logger.js.map +1 -0
  1091. package/dist/version.d.ts +2 -0
  1092. package/dist/version.d.ts.map +1 -0
  1093. package/dist/version.js +5 -0
  1094. package/dist/version.js.map +1 -0
  1095. package/dist/vite-html-renderer.d.ts +18 -0
  1096. package/dist/vite-html-renderer.d.ts.map +1 -0
  1097. package/dist/vite-html-renderer.js +61 -0
  1098. package/dist/vite-html-renderer.js.map +1 -0
  1099. package/dist/worktree-config.d.ts +19 -0
  1100. package/dist/worktree-config.d.ts.map +1 -0
  1101. package/dist/worktree-config.js +368 -0
  1102. package/dist/worktree-config.js.map +1 -0
  1103. package/package.json +95 -0
  1104. package/skills/deal-desk-outreach/SKILL.md +77 -0
  1105. package/skills/dealdesk/SKILL.md +109 -0
  1106. package/skills/dealdesk/references/api-reference.md +899 -0
  1107. package/skills/dealdesk/references/company-skills.md +193 -0
  1108. package/skills/dealdesk/references/issue-workspaces.md +80 -0
  1109. package/skills/dealdesk/references/routines.md +187 -0
  1110. package/skills/dealdesk/references/workflows.md +141 -0
  1111. package/skills/dealdesk-converting-plans-to-tasks/SKILL.md +110 -0
  1112. package/skills/dealdesk-create-agent/SKILL.md +124 -0
  1113. package/skills/dealdesk-create-agent/references/agent-instruction-templates.md +123 -0
  1114. package/skills/dealdesk-create-agent/references/agents/coder.md +64 -0
  1115. package/skills/dealdesk-create-agent/references/agents/qa.md +88 -0
  1116. package/skills/dealdesk-create-agent/references/agents/securityengineer.md +135 -0
  1117. package/skills/dealdesk-create-agent/references/agents/uxdesigner.md +115 -0
  1118. package/skills/dealdesk-create-agent/references/api-reference.md +110 -0
  1119. package/skills/dealdesk-create-agent/references/baseline-role-guide.md +168 -0
  1120. package/skills/dealdesk-create-agent/references/draft-review-checklist.md +95 -0
  1121. package/skills/dealdesk-create-plugin/SKILL.md +92 -0
  1122. package/skills/dealdesk-dev/SKILL.md +103 -0
  1123. package/skills/diagnose-why-work-stopped/SKILL.md +161 -0
  1124. package/skills/para-memory-files/SKILL.md +104 -0
  1125. package/skills/para-memory-files/references/schemas.md +35 -0
  1126. package/skills/terminal-bench-loop/SKILL.md +236 -0
  1127. package/ui-dist/android-chrome-192x192.png +0 -0
  1128. package/ui-dist/android-chrome-512x512.png +0 -0
  1129. package/ui-dist/apple-touch-icon.png +0 -0
  1130. package/ui-dist/assets/_basePickBy-CaQZTZgE.js +1 -0
  1131. package/ui-dist/assets/_baseUniq-DvA-iyvx.js +1 -0
  1132. package/ui-dist/assets/apl-B4CMkyY2.js +1 -0
  1133. package/ui-dist/assets/arc-_uwl-PL9.js +1 -0
  1134. package/ui-dist/assets/architectureDiagram-VXUJARFQ-hoEr3qym.js +36 -0
  1135. package/ui-dist/assets/asciiarmor-Df11BRmG.js +1 -0
  1136. package/ui-dist/assets/asn1-EdZsLKOL.js +1 -0
  1137. package/ui-dist/assets/asterisk-B-8jnY81.js +1 -0
  1138. package/ui-dist/assets/blockDiagram-VD42YOAC-BpNmbQ9P.js +122 -0
  1139. package/ui-dist/assets/brainfuck-C4LP7Hcl.js +1 -0
  1140. package/ui-dist/assets/c4Diagram-YG6GDRKO-BG14x8dM.js +10 -0
  1141. package/ui-dist/assets/channel-NmuAvKfd.js +1 -0
  1142. package/ui-dist/assets/chunk-4BX2VUAB-Cb1YcG81.js +1 -0
  1143. package/ui-dist/assets/chunk-55IACEB6-DkMTjrQj.js +1 -0
  1144. package/ui-dist/assets/chunk-B4BG7PRW-BD6QmYfE.js +165 -0
  1145. package/ui-dist/assets/chunk-DI55MBZ5-B_xkiL3H.js +220 -0
  1146. package/ui-dist/assets/chunk-FMBD7UC4-DC95tjc1.js +15 -0
  1147. package/ui-dist/assets/chunk-QN33PNHL-BkIJ2KXA.js +1 -0
  1148. package/ui-dist/assets/chunk-QZHKN3VN-BWUNV7If.js +1 -0
  1149. package/ui-dist/assets/chunk-TZMSLE5B-NQYnSIs1.js +1 -0
  1150. package/ui-dist/assets/classDiagram-2ON5EDUG-eS4kRH8R.js +1 -0
  1151. package/ui-dist/assets/classDiagram-v2-WZHVMYZB-eS4kRH8R.js +1 -0
  1152. package/ui-dist/assets/clike-B9uivgTg.js +1 -0
  1153. package/ui-dist/assets/clojure-BMjYHr_A.js +1 -0
  1154. package/ui-dist/assets/clone-CbA0swX6.js +1 -0
  1155. package/ui-dist/assets/cmake-BQqOBYOt.js +1 -0
  1156. package/ui-dist/assets/cobol-CWcv1MsR.js +1 -0
  1157. package/ui-dist/assets/coffeescript-S37ZYGWr.js +1 -0
  1158. package/ui-dist/assets/commonlisp-DBKNyK5s.js +1 -0
  1159. package/ui-dist/assets/cose-bilkent-S5V4N54A-BHo6DkZj.js +1 -0
  1160. package/ui-dist/assets/crystal-SjHAIU92.js +1 -0
  1161. package/ui-dist/assets/css-BnMrqG3P.js +1 -0
  1162. package/ui-dist/assets/cypher-C_CwsFkJ.js +1 -0
  1163. package/ui-dist/assets/cytoscape.esm-jbPEKk2Y.js +321 -0
  1164. package/ui-dist/assets/d-pRatUO7H.js +1 -0
  1165. package/ui-dist/assets/dagre-6UL2VRFP-CfzNlqfr.js +4 -0
  1166. package/ui-dist/assets/defaultLocale-DX6XiGOO.js +1 -0
  1167. package/ui-dist/assets/diagram-PSM6KHXK-DjPk4Vl5.js +24 -0
  1168. package/ui-dist/assets/diagram-QEK2KX5R-ClmlUcpT.js +43 -0
  1169. package/ui-dist/assets/diagram-S2PKOQOG-B68LEXtz.js +24 -0
  1170. package/ui-dist/assets/diff-DbItnlRl.js +1 -0
  1171. package/ui-dist/assets/dockerfile-BKs6k2Af.js +1 -0
  1172. package/ui-dist/assets/dtd-DF_7sFjM.js +1 -0
  1173. package/ui-dist/assets/dylan-DwRh75JA.js +1 -0
  1174. package/ui-dist/assets/ebnf-CDyGwa7X.js +1 -0
  1175. package/ui-dist/assets/ecl-Cabwm37j.js +1 -0
  1176. package/ui-dist/assets/eiffel-CnydiIhH.js +1 -0
  1177. package/ui-dist/assets/elm-vLlmbW-K.js +1 -0
  1178. package/ui-dist/assets/erDiagram-Q2GNP2WA-CJSnga5T.js +60 -0
  1179. package/ui-dist/assets/erlang-BNw1qcRV.js +1 -0
  1180. package/ui-dist/assets/factor-kuTfRLto.js +1 -0
  1181. package/ui-dist/assets/fcl-Kvtd6kyn.js +1 -0
  1182. package/ui-dist/assets/flowDiagram-NV44I4VS-Drmp4DHd.js +162 -0
  1183. package/ui-dist/assets/forth-Ffai-XNe.js +1 -0
  1184. package/ui-dist/assets/fortran-DYz_wnZ1.js +1 -0
  1185. package/ui-dist/assets/ganttDiagram-JELNMOA3-C8ffQ-2u.js +267 -0
  1186. package/ui-dist/assets/gas-Bneqetm1.js +1 -0
  1187. package/ui-dist/assets/gherkin-heZmZLOM.js +1 -0
  1188. package/ui-dist/assets/gitGraphDiagram-V2S2FVAM-CPjF6oPQ.js +65 -0
  1189. package/ui-dist/assets/graph-B2qUgzgo.js +1 -0
  1190. package/ui-dist/assets/groovy-D9Dt4D0W.js +1 -0
  1191. package/ui-dist/assets/haskell-Cw1EW3IL.js +1 -0
  1192. package/ui-dist/assets/haxe-H-WmDvRZ.js +1 -0
  1193. package/ui-dist/assets/http-DBlCnlav.js +1 -0
  1194. package/ui-dist/assets/idl-BEugSyMb.js +1 -0
  1195. package/ui-dist/assets/index-6t3ZNnLR.js +1 -0
  1196. package/ui-dist/assets/index-ARl1W2jj.js +1 -0
  1197. package/ui-dist/assets/index-B9T1xuwJ.js +13 -0
  1198. package/ui-dist/assets/index-BAhZurej.js +2 -0
  1199. package/ui-dist/assets/index-BJ9IksfS.js +1 -0
  1200. package/ui-dist/assets/index-BKv2WUK1.js +1 -0
  1201. package/ui-dist/assets/index-BT7YS1Ir.js +3 -0
  1202. package/ui-dist/assets/index-Bkj-OIiI.js +1 -0
  1203. package/ui-dist/assets/index-CNEquZvK.js +1 -0
  1204. package/ui-dist/assets/index-CPGHpqpR.js +1 -0
  1205. package/ui-dist/assets/index-CW2NmfmI.js +1 -0
  1206. package/ui-dist/assets/index-Cf8smU9e.js +1 -0
  1207. package/ui-dist/assets/index-CrrVEpWP.js +537 -0
  1208. package/ui-dist/assets/index-CtebvrC7.js +1 -0
  1209. package/ui-dist/assets/index-CuwS3-lF.js +1 -0
  1210. package/ui-dist/assets/index-D1D5GrGc.js +1 -0
  1211. package/ui-dist/assets/index-DLN9KwFF.css +1 -0
  1212. package/ui-dist/assets/index-DWfkKcGS.js +1 -0
  1213. package/ui-dist/assets/index-DXzbokce.js +6 -0
  1214. package/ui-dist/assets/index-DY03uqeZ.js +1 -0
  1215. package/ui-dist/assets/index-DnDdXZYl.js +1 -0
  1216. package/ui-dist/assets/index-DvRp33UU.js +1 -0
  1217. package/ui-dist/assets/index-FnWH4Q9P.js +7 -0
  1218. package/ui-dist/assets/index-O_WP0QsK.js +1 -0
  1219. package/ui-dist/assets/infoDiagram-HS3SLOUP-DLOW6p4c.js +2 -0
  1220. package/ui-dist/assets/init-Gi6I4Gst.js +1 -0
  1221. package/ui-dist/assets/javascript-iXu5QeM3.js +1 -0
  1222. package/ui-dist/assets/journeyDiagram-XKPGCS4Q-oYaaSMQP.js +139 -0
  1223. package/ui-dist/assets/julia-DuME0IfC.js +1 -0
  1224. package/ui-dist/assets/kanban-definition-3W4ZIXB7-BE7mgk6q.js +89 -0
  1225. package/ui-dist/assets/katex-B95LWT_Q.js +261 -0
  1226. package/ui-dist/assets/layout-Cq5BDWzM.js +1 -0
  1227. package/ui-dist/assets/linear-HnEHTC6F.js +1 -0
  1228. package/ui-dist/assets/livescript-BwQOo05w.js +1 -0
  1229. package/ui-dist/assets/lua-BgMRiT3U.js +1 -0
  1230. package/ui-dist/assets/mathematica-DTrFuWx2.js +1 -0
  1231. package/ui-dist/assets/mbox-CNhZ1qSd.js +1 -0
  1232. package/ui-dist/assets/mermaid.core-JMROPF3S.js +250 -0
  1233. package/ui-dist/assets/mindmap-definition-VGOIOE7T-DoeZEBQU.js +68 -0
  1234. package/ui-dist/assets/mirc-CjQqDB4T.js +1 -0
  1235. package/ui-dist/assets/mllike-CXdrOF99.js +1 -0
  1236. package/ui-dist/assets/modelica-Dc1JOy9r.js +1 -0
  1237. package/ui-dist/assets/mscgen-BA5vi2Kp.js +1 -0
  1238. package/ui-dist/assets/mumps-BT43cFF4.js +1 -0
  1239. package/ui-dist/assets/nginx-DdIZxoE0.js +1 -0
  1240. package/ui-dist/assets/nsis-LdVXkNf5.js +1 -0
  1241. package/ui-dist/assets/ntriples-BfvgReVJ.js +1 -0
  1242. package/ui-dist/assets/octave-Ck1zUtKM.js +1 -0
  1243. package/ui-dist/assets/ordinal-Cboi1Yqb.js +1 -0
  1244. package/ui-dist/assets/oz-BzwKVEFT.js +1 -0
  1245. package/ui-dist/assets/pascal--L3eBynH.js +1 -0
  1246. package/ui-dist/assets/perl-CdXCOZ3F.js +1 -0
  1247. package/ui-dist/assets/pieDiagram-ADFJNKIX-BtfKQ-xw.js +30 -0
  1248. package/ui-dist/assets/pig-CevX1Tat.js +1 -0
  1249. package/ui-dist/assets/powershell-CFHJl5sT.js +1 -0
  1250. package/ui-dist/assets/properties-C78fOPTZ.js +1 -0
  1251. package/ui-dist/assets/protobuf-ChK-085T.js +1 -0
  1252. package/ui-dist/assets/pug-DeIclll2.js +1 -0
  1253. package/ui-dist/assets/puppet-DMA9R1ak.js +1 -0
  1254. package/ui-dist/assets/python-BuPzkPfP.js +1 -0
  1255. package/ui-dist/assets/q-pXgVlZs6.js +1 -0
  1256. package/ui-dist/assets/quadrantDiagram-AYHSOK5B-CIrjVDBB.js +7 -0
  1257. package/ui-dist/assets/r-B6wPVr8A.js +1 -0
  1258. package/ui-dist/assets/requirementDiagram-UZGBJVZJ-CNQ5h-EW.js +64 -0
  1259. package/ui-dist/assets/rpm-CTu-6PCP.js +1 -0
  1260. package/ui-dist/assets/ruby-B2Rjki9n.js +1 -0
  1261. package/ui-dist/assets/sankeyDiagram-TZEHDZUN-CrOSPDz5.js +10 -0
  1262. package/ui-dist/assets/sas-B4kiWyti.js +1 -0
  1263. package/ui-dist/assets/scheme-C41bIUwD.js +1 -0
  1264. package/ui-dist/assets/sequenceDiagram-WL72ISMW-D96XuK7n.js +145 -0
  1265. package/ui-dist/assets/shell-CjFT_Tl9.js +1 -0
  1266. package/ui-dist/assets/sieve-C3Gn_uJK.js +1 -0
  1267. package/ui-dist/assets/simple-mode-GW_nhZxv.js +1 -0
  1268. package/ui-dist/assets/smalltalk-CnHTOXQT.js +1 -0
  1269. package/ui-dist/assets/solr-DehyRSwq.js +1 -0
  1270. package/ui-dist/assets/sparql-DkYu6x3z.js +1 -0
  1271. package/ui-dist/assets/spreadsheet-BCZA_wO0.js +1 -0
  1272. package/ui-dist/assets/sql-D0XecflT.js +1 -0
  1273. package/ui-dist/assets/stateDiagram-FKZM4ZOC-BOf9izkD.js +1 -0
  1274. package/ui-dist/assets/stateDiagram-v2-4FDKWEC3-DEhq019K.js +1 -0
  1275. package/ui-dist/assets/stex-C3f8Ysf7.js +1 -0
  1276. package/ui-dist/assets/stylus-B533Al4x.js +1 -0
  1277. package/ui-dist/assets/swift-BzpIVaGY.js +1 -0
  1278. package/ui-dist/assets/tcl-DVfN8rqt.js +1 -0
  1279. package/ui-dist/assets/textile-CnDTJFAw.js +1 -0
  1280. package/ui-dist/assets/tiddlywiki-DO-Gjzrf.js +1 -0
  1281. package/ui-dist/assets/tiki-DGYXhP31.js +1 -0
  1282. package/ui-dist/assets/timeline-definition-IT6M3QCI-_lAaYcUI.js +61 -0
  1283. package/ui-dist/assets/toml-Bm5Em-hy.js +1 -0
  1284. package/ui-dist/assets/treemap-GDKQZRPO-BS18z8ox.js +154 -0
  1285. package/ui-dist/assets/troff-wAsdV37c.js +1 -0
  1286. package/ui-dist/assets/ttcn-CfJYG6tj.js +1 -0
  1287. package/ui-dist/assets/ttcn-cfg-B9xdYoR4.js +1 -0
  1288. package/ui-dist/assets/turtle-B1tBg_DP.js +1 -0
  1289. package/ui-dist/assets/vb-CmGdzxic.js +1 -0
  1290. package/ui-dist/assets/vbscript-BuJXcnF6.js +1 -0
  1291. package/ui-dist/assets/velocity-D8B20fx6.js +1 -0
  1292. package/ui-dist/assets/verilog-C6RDOZhf.js +1 -0
  1293. package/ui-dist/assets/vhdl-lSbBsy5d.js +1 -0
  1294. package/ui-dist/assets/webidl-ZXfAyPTL.js +1 -0
  1295. package/ui-dist/assets/xquery-DzFWVndE.js +1 -0
  1296. package/ui-dist/assets/xychartDiagram-PRI3JC2R-X82nn6D0.js +7 -0
  1297. package/ui-dist/assets/yacas-BJ4BC0dw.js +1 -0
  1298. package/ui-dist/assets/z80-Hz9HOZM7.js +1 -0
  1299. package/ui-dist/brands/opencode-logo-dark-square.svg +18 -0
  1300. package/ui-dist/brands/opencode-logo-light-square.svg +18 -0
  1301. package/ui-dist/favicon-16x16.png +0 -0
  1302. package/ui-dist/favicon-32x32.png +0 -0
  1303. package/ui-dist/favicon.ico +0 -0
  1304. package/ui-dist/favicon.svg +10 -0
  1305. package/ui-dist/index.html +49 -0
  1306. package/ui-dist/site.webmanifest +30 -0
  1307. package/ui-dist/sw.js +42 -0
  1308. package/ui-dist/worktree-favicon-16x16.png +0 -0
  1309. package/ui-dist/worktree-favicon-32x32.png +0 -0
  1310. package/ui-dist/worktree-favicon.ico +0 -0
  1311. package/ui-dist/worktree-favicon.svg +10 -0
@@ -0,0 +1,3374 @@
1
+ import { Buffer } from "node:buffer";
2
+ import { and, asc, desc, eq, gt, inArray, isNull, like, lt, ne, notInArray, or, sql } from "drizzle-orm";
3
+ import { activityLog, agentWakeupRequests, agents, approvals, assets, companies, companyMemberships, documents, goals, heartbeatRuns, executionWorkspaces, issueApprovals, issueAttachments, issueInboxArchives, issueLabels, issueRecoveryActions, issueRelations, issueComments, issueDocuments, issueReadStates, issueThreadInteractions, issues, labels, projectWorkspaces, projects, } from "@dealdesk/db";
4
+ import { clampIssueRequestDepth, extractAgentMentionIds, extractProjectMentionIds, issueCommentAuthorTypeSchema, issueCommentMetadataSchema, issueCommentPresentationSchema, isUuidLike, normalizeIssueIdentifier as normalizeIssueReferenceIdentifier, } from "@dealdesk/shared";
5
+ import { conflict, notFound, unprocessable } from "../errors.js";
6
+ import { parseObject } from "../adapters/utils.js";
7
+ import { defaultIssueExecutionWorkspaceSettingsForProject, gateProjectExecutionWorkspacePolicy, issueExecutionWorkspaceModeForPersistedWorkspace, parseIssueExecutionWorkspaceSettings, parseProjectExecutionWorkspacePolicy, } from "./execution-workspace-policy.js";
8
+ import { mergeExecutionWorkspaceConfig } from "./execution-workspaces.js";
9
+ import { buildInitialIssueMonitorFields, normalizeIssueExecutionPolicy } from "./issue-execution-policy.js";
10
+ import { instanceSettingsService } from "./instance-settings.js";
11
+ import { redactCurrentUserText } from "../log-redaction.js";
12
+ import { resolveIssueGoalId, resolveNextIssueGoalId } from "./issue-goal-fallback.js";
13
+ import { getRunLogStore } from "./run-log-store.js";
14
+ import { isVerifiedIssueTreeControlInteractionWake, issueTreeControlService, } from "./issue-tree-control.js";
15
+ import { parseIssueGraphLivenessIncidentKey } from "./recovery/origins.js";
16
+ const ALL_ISSUE_STATUSES = ["backlog", "todo", "in_progress", "in_review", "blocked", "done", "cancelled"];
17
+ const MAX_ISSUE_COMMENT_PAGE_LIMIT = 500;
18
+ export const ISSUE_LIST_DEFAULT_LIMIT = 500;
19
+ export const ISSUE_LIST_MAX_LIMIT = 1000;
20
+ const ISSUE_LIST_RELATED_QUERY_CHUNK_SIZE = 500;
21
+ export const MAX_CHILD_ISSUES_CREATED_BY_HELPER = 25;
22
+ const MAX_CHILD_COMPLETION_SUMMARIES = 20;
23
+ const CHILD_COMPLETION_SUMMARY_BODY_MAX_CHARS = 500;
24
+ const ISSUE_COMMENT_RUN_LOG_DERIVATION_MAX_LOG_BYTES = 2_000_000;
25
+ const ISSUE_COMMENT_RUN_LOG_DERIVATION_CHUNK_BYTES = 256_000;
26
+ const ISSUE_COMMENT_RUN_LOG_DERIVATION_END_SLACK_MS = 60_000;
27
+ const ISSUE_COMMENT_RUN_LOG_DERIVATION_MAX_PARALLEL_READS = 8;
28
+ function assertTransition(from, to) {
29
+ if (from === to)
30
+ return;
31
+ if (!ALL_ISSUE_STATUSES.includes(to)) {
32
+ throw conflict(`Unknown issue status: ${to}`);
33
+ }
34
+ }
35
+ function applyStatusSideEffects(status, patch) {
36
+ if (!status)
37
+ return patch;
38
+ if (status === "in_progress" && !patch.startedAt) {
39
+ patch.startedAt = new Date();
40
+ }
41
+ if (status === "done") {
42
+ patch.completedAt = new Date();
43
+ }
44
+ if (status === "cancelled") {
45
+ patch.cancelledAt = new Date();
46
+ }
47
+ return patch;
48
+ }
49
+ function readStringFromRecord(record, key) {
50
+ if (!record || typeof record !== "object")
51
+ return null;
52
+ const value = record[key];
53
+ return typeof value === "string" && value.trim().length > 0 ? value.trim() : null;
54
+ }
55
+ function buildReusedExecutionWorkspaceConfigPatchFromIssueSettings(settings) {
56
+ return {
57
+ environmentId: settings?.environmentId ?? null,
58
+ provisionCommand: settings?.workspaceStrategy?.provisionCommand ?? null,
59
+ teardownCommand: settings?.workspaceStrategy?.teardownCommand ?? null,
60
+ workspaceRuntime: settings?.workspaceRuntime ?? null,
61
+ };
62
+ }
63
+ function toTimestampMs(value) {
64
+ if (!value)
65
+ return null;
66
+ const date = value instanceof Date ? value : new Date(value);
67
+ const timestamp = date.getTime();
68
+ return Number.isFinite(timestamp) ? timestamp : null;
69
+ }
70
+ export function deriveIssueCommentRunLogAttribution(comments, runs) {
71
+ const derivedByCommentId = new Map();
72
+ for (const comment of comments) {
73
+ if (comment.authorAgentId || !comment.authorUserId || comment.createdByRunId)
74
+ continue;
75
+ const commentCreatedAtMs = toTimestampMs(comment.createdAt);
76
+ if (commentCreatedAtMs === null)
77
+ continue;
78
+ let bestMatch = null;
79
+ for (const run of runs) {
80
+ const runStartMs = toTimestampMs(run.startedAt ?? run.createdAt);
81
+ const runEndMs = toTimestampMs(run.finishedAt ?? run.createdAt);
82
+ if (runStartMs === null || runEndMs === null)
83
+ continue;
84
+ if (commentCreatedAtMs < runStartMs
85
+ || commentCreatedAtMs > runEndMs + ISSUE_COMMENT_RUN_LOG_DERIVATION_END_SLACK_MS) {
86
+ continue;
87
+ }
88
+ if (!run.logContent.includes(`comment id: ${comment.id}`))
89
+ continue;
90
+ const distanceMs = Math.abs(runEndMs - commentCreatedAtMs);
91
+ if (!bestMatch || distanceMs < bestMatch.distanceMs) {
92
+ bestMatch = {
93
+ runId: run.runId,
94
+ agentId: run.agentId,
95
+ distanceMs,
96
+ };
97
+ }
98
+ }
99
+ if (!bestMatch)
100
+ continue;
101
+ derivedByCommentId.set(comment.id, {
102
+ derivedAuthorAgentId: bestMatch.agentId,
103
+ derivedCreatedByRunId: bestMatch.runId,
104
+ derivedAuthorSource: "run_log_comment_post",
105
+ });
106
+ }
107
+ return derivedByCommentId;
108
+ }
109
+ function sameRunLock(checkoutRunId, actorRunId) {
110
+ if (actorRunId)
111
+ return checkoutRunId === actorRunId;
112
+ return checkoutRunId == null;
113
+ }
114
+ const TERMINAL_HEARTBEAT_RUN_STATUSES = new Set(["succeeded", "failed", "cancelled", "timed_out"]);
115
+ const ISSUE_LIST_DESCRIPTION_MAX_CHARS = 1200;
116
+ const ISSUE_LIST_DESCRIPTION_MAX_BYTES = ISSUE_LIST_DESCRIPTION_MAX_CHARS * 4;
117
+ function escapeLikePattern(value) {
118
+ return value.replace(/[\\%_]/g, "\\$&");
119
+ }
120
+ export function clampIssueListLimit(limit) {
121
+ return Math.min(ISSUE_LIST_MAX_LIMIT, Math.max(1, Math.floor(limit)));
122
+ }
123
+ function chunkList(values, size) {
124
+ const chunks = [];
125
+ for (let index = 0; index < values.length; index += size) {
126
+ chunks.push(values.slice(index, index + size));
127
+ }
128
+ return chunks;
129
+ }
130
+ function truncateInlineSummary(value, maxChars = CHILD_COMPLETION_SUMMARY_BODY_MAX_CHARS) {
131
+ const normalized = value?.trim();
132
+ if (!normalized)
133
+ return null;
134
+ return normalized.length > maxChars ? `${normalized.slice(0, Math.max(0, maxChars - 15)).trimEnd()} [truncated]` : normalized;
135
+ }
136
+ function truncateByCodePoint(value, maxChars) {
137
+ if (value.length <= maxChars)
138
+ return value;
139
+ return Array.from(value).slice(0, maxChars).join("");
140
+ }
141
+ function decodeDatabaseTextPreview(value, maxChars) {
142
+ if (value == null)
143
+ return null;
144
+ return truncateByCodePoint(Buffer.from(value, "base64").toString("utf8"), maxChars);
145
+ }
146
+ function appendAcceptanceCriteriaToDescription(description, acceptanceCriteria) {
147
+ const criteria = (acceptanceCriteria ?? []).map((item) => item.trim()).filter(Boolean);
148
+ if (criteria.length === 0)
149
+ return description ?? null;
150
+ const base = description?.trim() ?? "";
151
+ const criteriaMarkdown = ["## Acceptance Criteria", "", ...criteria.map((item) => `- ${item}`)].join("\n");
152
+ return base ? `${base}\n\n${criteriaMarkdown}` : criteriaMarkdown;
153
+ }
154
+ function createIssueDependencyReadiness(issueId) {
155
+ return {
156
+ issueId,
157
+ blockerIssueIds: [],
158
+ unresolvedBlockerIssueIds: [],
159
+ unresolvedBlockerCount: 0,
160
+ allBlockersDone: true,
161
+ isDependencyReady: true,
162
+ };
163
+ }
164
+ async function listIssueDependencyReadinessMap(dbOrTx, companyId, issueIds) {
165
+ const uniqueIssueIds = [...new Set(issueIds.filter(Boolean))];
166
+ const readinessMap = new Map();
167
+ for (const issueId of uniqueIssueIds) {
168
+ readinessMap.set(issueId, createIssueDependencyReadiness(issueId));
169
+ }
170
+ if (uniqueIssueIds.length === 0)
171
+ return readinessMap;
172
+ const blockerRows = await dbOrTx
173
+ .select({
174
+ issueId: issueRelations.relatedIssueId,
175
+ blockerIssueId: issueRelations.issueId,
176
+ blockerStatus: issues.status,
177
+ })
178
+ .from(issueRelations)
179
+ .innerJoin(issues, eq(issueRelations.issueId, issues.id))
180
+ .where(and(eq(issueRelations.companyId, companyId), eq(issueRelations.type, "blocks"), inArray(issueRelations.relatedIssueId, uniqueIssueIds)));
181
+ for (const row of blockerRows) {
182
+ const current = readinessMap.get(row.issueId) ?? createIssueDependencyReadiness(row.issueId);
183
+ current.blockerIssueIds.push(row.blockerIssueId);
184
+ // Only done blockers resolve dependents; cancelled blockers stay unresolved
185
+ // until an operator removes or replaces the blocker relationship explicitly.
186
+ if (row.blockerStatus !== "done") {
187
+ current.unresolvedBlockerIssueIds.push(row.blockerIssueId);
188
+ current.unresolvedBlockerCount += 1;
189
+ current.allBlockersDone = false;
190
+ current.isDependencyReady = false;
191
+ }
192
+ readinessMap.set(row.issueId, current);
193
+ }
194
+ return readinessMap;
195
+ }
196
+ async function listUnresolvedBlockerIssueIds(dbOrTx, companyId, blockerIssueIds) {
197
+ const uniqueBlockerIssueIds = [...new Set(blockerIssueIds.filter(Boolean))];
198
+ if (uniqueBlockerIssueIds.length === 0)
199
+ return [];
200
+ return dbOrTx
201
+ .select({ id: issues.id })
202
+ .from(issues)
203
+ .where(and(eq(issues.companyId, companyId), inArray(issues.id, uniqueBlockerIssueIds),
204
+ // Cancelled blockers intentionally remain unresolved until the relation changes.
205
+ ne(issues.status, "done")))
206
+ .then((rows) => rows.map((row) => row.id));
207
+ }
208
+ async function getWorkspaceInheritanceIssue(db, companyId, issueId) {
209
+ const issue = await db
210
+ .select({
211
+ id: issues.id,
212
+ projectId: issues.projectId,
213
+ projectWorkspaceId: issues.projectWorkspaceId,
214
+ executionWorkspaceId: issues.executionWorkspaceId,
215
+ executionWorkspaceSettings: issues.executionWorkspaceSettings,
216
+ })
217
+ .from(issues)
218
+ .where(and(eq(issues.id, issueId), eq(issues.companyId, companyId)))
219
+ .then((rows) => rows[0] ?? null);
220
+ if (!issue) {
221
+ throw notFound("Workspace inheritance issue not found");
222
+ }
223
+ return issue;
224
+ }
225
+ function touchedByUserCondition(companyId, userId) {
226
+ return sql `
227
+ (
228
+ ${issues.createdByUserId} = ${userId}
229
+ OR ${issues.assigneeUserId} = ${userId}
230
+ OR EXISTS (
231
+ SELECT 1
232
+ FROM ${issueReadStates}
233
+ WHERE ${issueReadStates.issueId} = ${issues.id}
234
+ AND ${issueReadStates.companyId} = ${companyId}
235
+ AND ${issueReadStates.userId} = ${userId}
236
+ )
237
+ OR EXISTS (
238
+ SELECT 1
239
+ FROM ${issueComments}
240
+ WHERE ${issueComments.issueId} = ${issues.id}
241
+ AND ${issueComments.companyId} = ${companyId}
242
+ AND ${issueComments.authorUserId} = ${userId}
243
+ )
244
+ )
245
+ `;
246
+ }
247
+ function participatedByAgentCondition(companyId, agentId) {
248
+ return sql `
249
+ (
250
+ ${issues.createdByAgentId} = ${agentId}
251
+ OR ${issues.assigneeAgentId} = ${agentId}
252
+ OR EXISTS (
253
+ SELECT 1
254
+ FROM ${issueComments}
255
+ WHERE ${issueComments.issueId} = ${issues.id}
256
+ AND ${issueComments.companyId} = ${companyId}
257
+ AND ${issueComments.authorAgentId} = ${agentId}
258
+ )
259
+ OR EXISTS (
260
+ SELECT 1
261
+ FROM ${activityLog}
262
+ WHERE ${activityLog.companyId} = ${companyId}
263
+ AND ${activityLog.entityType} = 'issue'
264
+ AND ${activityLog.entityId} = ${issues.id}::text
265
+ AND ${activityLog.agentId} = ${agentId}
266
+ )
267
+ )
268
+ `;
269
+ }
270
+ function myLastCommentAtExpr(companyId, userId) {
271
+ return sql `
272
+ (
273
+ SELECT MAX(${issueComments.createdAt})
274
+ FROM ${issueComments}
275
+ WHERE ${issueComments.issueId} = ${issues.id}
276
+ AND ${issueComments.companyId} = ${companyId}
277
+ AND ${issueComments.authorUserId} = ${userId}
278
+ )
279
+ `;
280
+ }
281
+ function myLastReadAtExpr(companyId, userId) {
282
+ return sql `
283
+ (
284
+ SELECT MAX(${issueReadStates.lastReadAt})
285
+ FROM ${issueReadStates}
286
+ WHERE ${issueReadStates.issueId} = ${issues.id}
287
+ AND ${issueReadStates.companyId} = ${companyId}
288
+ AND ${issueReadStates.userId} = ${userId}
289
+ )
290
+ `;
291
+ }
292
+ function myLastTouchAtExpr(companyId, userId) {
293
+ const myLastCommentAt = myLastCommentAtExpr(companyId, userId);
294
+ const myLastReadAt = myLastReadAtExpr(companyId, userId);
295
+ return sql `
296
+ GREATEST(
297
+ COALESCE(${myLastCommentAt}, to_timestamp(0)),
298
+ COALESCE(${myLastReadAt}, to_timestamp(0)),
299
+ COALESCE(CASE WHEN ${issues.createdByUserId} = ${userId} THEN ${issues.createdAt} ELSE NULL END, to_timestamp(0)),
300
+ COALESCE(CASE WHEN ${issues.assigneeUserId} = ${userId} THEN ${issues.updatedAt} ELSE NULL END, to_timestamp(0))
301
+ )
302
+ `;
303
+ }
304
+ function lastExternalCommentAtExpr(companyId, userId) {
305
+ return sql `
306
+ (
307
+ SELECT MAX(${issueComments.createdAt})
308
+ FROM ${issueComments}
309
+ WHERE ${issueComments.issueId} = ${issues.id}
310
+ AND ${issueComments.companyId} = ${companyId}
311
+ AND (
312
+ ${issueComments.authorUserId} IS NULL
313
+ OR ${issueComments.authorUserId} <> ${userId}
314
+ )
315
+ )
316
+ `;
317
+ }
318
+ function issueLastActivityAtExpr(companyId, userId) {
319
+ const lastExternalCommentAt = lastExternalCommentAtExpr(companyId, userId);
320
+ const myLastTouchAt = myLastTouchAtExpr(companyId, userId);
321
+ return sql `
322
+ GREATEST(
323
+ COALESCE(${lastExternalCommentAt}, to_timestamp(0)),
324
+ CASE
325
+ WHEN ${issues.updatedAt} > COALESCE(${myLastTouchAt}, to_timestamp(0))
326
+ THEN ${issues.updatedAt}
327
+ ELSE to_timestamp(0)
328
+ END
329
+ )
330
+ `;
331
+ }
332
+ const ISSUE_LOCAL_INBOX_ACTIVITY_ACTIONS = [
333
+ "issue.read_marked",
334
+ "issue.read_unmarked",
335
+ "issue.inbox_archived",
336
+ "issue.inbox_unarchived",
337
+ ];
338
+ function issueLatestCommentAtExpr(companyId) {
339
+ return sql `
340
+ (
341
+ SELECT MAX(${issueComments.createdAt})
342
+ FROM ${issueComments}
343
+ WHERE ${issueComments.issueId} = ${issues.id}
344
+ AND ${issueComments.companyId} = ${companyId}
345
+ )
346
+ `;
347
+ }
348
+ function issueLatestLogAtExpr(companyId) {
349
+ return sql `
350
+ (
351
+ SELECT MAX(${activityLog.createdAt})
352
+ FROM ${activityLog}
353
+ WHERE ${activityLog.companyId} = ${companyId}
354
+ AND ${activityLog.entityType} = 'issue'
355
+ AND ${activityLog.entityId} = ${issues.id}::text
356
+ AND ${activityLog.action} NOT IN (${sql.join(ISSUE_LOCAL_INBOX_ACTIVITY_ACTIONS.map((action) => sql `${action}`), sql `, `)})
357
+ )
358
+ `;
359
+ }
360
+ function issueCanonicalLastActivityAtExpr(companyId) {
361
+ const latestCommentAt = issueLatestCommentAtExpr(companyId);
362
+ const latestLogAt = issueLatestLogAtExpr(companyId);
363
+ return sql `
364
+ GREATEST(
365
+ ${issues.updatedAt},
366
+ COALESCE(${latestCommentAt}, to_timestamp(0)),
367
+ COALESCE(${latestLogAt}, to_timestamp(0))
368
+ )
369
+ `;
370
+ }
371
+ function unreadForUserCondition(companyId, userId) {
372
+ const touchedCondition = touchedByUserCondition(companyId, userId);
373
+ const myLastTouchAt = myLastTouchAtExpr(companyId, userId);
374
+ return sql `
375
+ (
376
+ ${touchedCondition}
377
+ AND EXISTS (
378
+ SELECT 1
379
+ FROM ${issueComments}
380
+ WHERE ${issueComments.issueId} = ${issues.id}
381
+ AND ${issueComments.companyId} = ${companyId}
382
+ AND (
383
+ ${issueComments.authorUserId} IS NULL
384
+ OR ${issueComments.authorUserId} <> ${userId}
385
+ )
386
+ AND ${issueComments.createdAt} > ${myLastTouchAt}
387
+ )
388
+ )
389
+ `;
390
+ }
391
+ function inboxVisibleForUserCondition(companyId, userId) {
392
+ const issueLastActivityAt = issueLastActivityAtExpr(companyId, userId);
393
+ return sql `
394
+ NOT EXISTS (
395
+ SELECT 1
396
+ FROM ${issueInboxArchives}
397
+ WHERE ${issueInboxArchives.issueId} = ${issues.id}
398
+ AND ${issueInboxArchives.companyId} = ${companyId}
399
+ AND ${issueInboxArchives.userId} = ${userId}
400
+ AND ${issueInboxArchives.archivedAt} >= ${issueLastActivityAt}
401
+ )
402
+ `;
403
+ }
404
+ function nonPluginOperationIssueCondition() {
405
+ return sql `NOT (${issues.originKind} LIKE 'plugin:%:operation' OR ${issues.originKind} LIKE 'plugin:%:operation:%')`;
406
+ }
407
+ function shouldIncludePluginOperationIssues(filters) {
408
+ return Boolean(filters?.includePluginOperations ||
409
+ filters?.originKind ||
410
+ filters?.originId ||
411
+ filters?.projectId);
412
+ }
413
+ /** Named entities commonly emitted in saved issue bodies; unknown `&name;` sequences are left unchanged. */
414
+ const WELL_KNOWN_NAMED_HTML_ENTITIES = {
415
+ amp: "&",
416
+ apos: "'",
417
+ copy: "\u00A9",
418
+ gt: ">",
419
+ lt: "<",
420
+ nbsp: "\u00A0",
421
+ quot: '"',
422
+ ensp: "\u2002",
423
+ emsp: "\u2003",
424
+ thinsp: "\u2009",
425
+ };
426
+ function decodeNumericHtmlEntity(digits, radix) {
427
+ const n = Number.parseInt(digits, radix);
428
+ if (Number.isNaN(n) || n < 0 || n > 0x10ffff)
429
+ return null;
430
+ try {
431
+ return String.fromCodePoint(n);
432
+ }
433
+ catch {
434
+ return null;
435
+ }
436
+ }
437
+ /** Decodes HTML character references in a raw @mention capture so UI-encoded bodies match agent names. */
438
+ export function normalizeAgentMentionToken(raw) {
439
+ let s = raw.replace(/&#x([0-9a-fA-F]+);/gi, (full, hex) => decodeNumericHtmlEntity(hex, 16) ?? full);
440
+ s = s.replace(/&#([0-9]+);/g, (full, dec) => decodeNumericHtmlEntity(dec, 10) ?? full);
441
+ s = s.replace(/&([a-z][a-z0-9]*);/gi, (full, name) => {
442
+ const decoded = WELL_KNOWN_NAMED_HTML_ENTITIES[name.toLowerCase()];
443
+ return decoded !== undefined ? decoded : full;
444
+ });
445
+ return s.trim();
446
+ }
447
+ export function deriveIssueUserContext(issue, userId, stats) {
448
+ const normalizeDate = (value) => {
449
+ if (!value)
450
+ return null;
451
+ if (value instanceof Date)
452
+ return Number.isNaN(value.getTime()) ? null : value;
453
+ const parsed = new Date(value);
454
+ return Number.isNaN(parsed.getTime()) ? null : parsed;
455
+ };
456
+ const myLastCommentAt = normalizeDate(stats?.myLastCommentAt);
457
+ const myLastReadAt = normalizeDate(stats?.myLastReadAt);
458
+ const createdTouchAt = issue.createdByUserId === userId ? normalizeDate(issue.createdAt) : null;
459
+ const assignedTouchAt = issue.assigneeUserId === userId ? normalizeDate(issue.updatedAt) : null;
460
+ const myLastTouchAt = [myLastCommentAt, myLastReadAt, createdTouchAt, assignedTouchAt]
461
+ .filter((value) => value instanceof Date)
462
+ .sort((a, b) => b.getTime() - a.getTime())[0] ?? null;
463
+ const lastExternalCommentAt = normalizeDate(stats?.lastExternalCommentAt);
464
+ const isUnreadForMe = Boolean(myLastTouchAt &&
465
+ lastExternalCommentAt &&
466
+ lastExternalCommentAt.getTime() > myLastTouchAt.getTime());
467
+ return {
468
+ myLastTouchAt,
469
+ lastExternalCommentAt,
470
+ isUnreadForMe,
471
+ };
472
+ }
473
+ function latestIssueActivityAt(...values) {
474
+ const normalized = values
475
+ .map((value) => {
476
+ if (!value)
477
+ return null;
478
+ if (value instanceof Date)
479
+ return Number.isNaN(value.getTime()) ? null : value;
480
+ const parsed = new Date(value);
481
+ return Number.isNaN(parsed.getTime()) ? null : parsed;
482
+ })
483
+ .filter((value) => value instanceof Date)
484
+ .sort((a, b) => b.getTime() - a.getTime());
485
+ return normalized[0] ?? null;
486
+ }
487
+ async function labelMapForIssues(dbOrTx, issueIds) {
488
+ const map = new Map();
489
+ if (issueIds.length === 0)
490
+ return map;
491
+ for (const issueIdChunk of chunkList(issueIds, ISSUE_LIST_RELATED_QUERY_CHUNK_SIZE)) {
492
+ const rows = await dbOrTx
493
+ .select({
494
+ issueId: issueLabels.issueId,
495
+ label: labels,
496
+ })
497
+ .from(issueLabels)
498
+ .innerJoin(labels, eq(issueLabels.labelId, labels.id))
499
+ .where(inArray(issueLabels.issueId, issueIdChunk))
500
+ .orderBy(asc(labels.name), asc(labels.id));
501
+ for (const row of rows) {
502
+ const existing = map.get(row.issueId);
503
+ if (existing)
504
+ existing.push(row.label);
505
+ else
506
+ map.set(row.issueId, [row.label]);
507
+ }
508
+ }
509
+ return map;
510
+ }
511
+ async function withIssueLabels(dbOrTx, rows) {
512
+ if (rows.length === 0)
513
+ return [];
514
+ const labelsByIssueId = await labelMapForIssues(dbOrTx, rows.map((row) => row.id));
515
+ return rows.map((row) => {
516
+ const issueLabels = labelsByIssueId.get(row.id) ?? [];
517
+ return {
518
+ ...row,
519
+ labels: issueLabels,
520
+ labelIds: issueLabels.map((label) => label.id),
521
+ };
522
+ });
523
+ }
524
+ const ACTIVE_RUN_STATUSES = ["queued", "running"];
525
+ const BLOCKER_ATTENTION_ACTIVE_RUN_STATUSES = ["queued", "running"];
526
+ const BLOCKER_ATTENTION_ACTIVE_WAKE_STATUSES = ["queued", "deferred_issue_execution"];
527
+ const BLOCKER_ATTENTION_PENDING_INTERACTION_STATUSES = ["pending"];
528
+ const BLOCKER_ATTENTION_PENDING_APPROVAL_STATUSES = ["pending", "revision_requested"];
529
+ const BLOCKER_ATTENTION_OPEN_RECOVERY_ORIGIN_KIND = "harness_liveness_escalation";
530
+ const PRODUCTIVITY_REVIEW_ORIGIN_KIND = "issue_productivity_review";
531
+ const PRODUCTIVITY_REVIEW_TERMINAL_STATUSES = ["done", "cancelled"];
532
+ const PRODUCTIVITY_REVIEW_ACTIVITY_ACTIONS = [
533
+ "issue.productivity_review_created",
534
+ "issue.productivity_review_updated",
535
+ ];
536
+ const PRODUCTIVITY_REVIEW_TRIGGERS = [
537
+ "no_comment_streak",
538
+ "long_active_duration",
539
+ "high_churn",
540
+ ];
541
+ const BLOCKER_ATTENTION_OPEN_RECOVERY_TERMINAL_STATUSES = ["done", "cancelled"];
542
+ const BLOCKER_ATTENTION_MAX_DEPTH = 8;
543
+ const BLOCKER_ATTENTION_MAX_NODES = 2000;
544
+ const BLOCKER_ATTENTION_INVOKABLE_AGENT_STATUSES = new Set(["active", "idle", "running", "error"]);
545
+ async function activeRunMapForIssues(dbOrTx, issueRows) {
546
+ const map = new Map();
547
+ const runIds = issueRows
548
+ .map((row) => row.executionRunId)
549
+ .filter((id) => id != null);
550
+ if (runIds.length === 0)
551
+ return map;
552
+ for (const runIdChunk of chunkList([...new Set(runIds)], ISSUE_LIST_RELATED_QUERY_CHUNK_SIZE)) {
553
+ const rows = await dbOrTx
554
+ .select({
555
+ id: heartbeatRuns.id,
556
+ status: heartbeatRuns.status,
557
+ agentId: heartbeatRuns.agentId,
558
+ invocationSource: heartbeatRuns.invocationSource,
559
+ triggerDetail: heartbeatRuns.triggerDetail,
560
+ startedAt: heartbeatRuns.startedAt,
561
+ finishedAt: heartbeatRuns.finishedAt,
562
+ createdAt: heartbeatRuns.createdAt,
563
+ })
564
+ .from(heartbeatRuns)
565
+ .where(and(inArray(heartbeatRuns.id, runIdChunk), inArray(heartbeatRuns.status, ACTIVE_RUN_STATUSES)));
566
+ for (const row of rows) {
567
+ map.set(row.id, row);
568
+ }
569
+ }
570
+ return map;
571
+ }
572
+ function createIssueBlockerAttention(input = {}) {
573
+ return {
574
+ state: input.state ?? "none",
575
+ reason: input.reason ?? null,
576
+ unresolvedBlockerCount: input.unresolvedBlockerCount ?? 0,
577
+ coveredBlockerCount: input.coveredBlockerCount ?? 0,
578
+ stalledBlockerCount: input.stalledBlockerCount ?? 0,
579
+ attentionBlockerCount: input.attentionBlockerCount ?? 0,
580
+ sampleBlockerIdentifier: input.sampleBlockerIdentifier ?? null,
581
+ sampleStalledBlockerIdentifier: input.sampleStalledBlockerIdentifier ?? null,
582
+ };
583
+ }
584
+ function blockerSampleIdentifier(node) {
585
+ return node?.identifier ?? node?.id ?? null;
586
+ }
587
+ function appendBlockerAttentionEdges(edgesByIssueId, rows) {
588
+ for (const row of rows) {
589
+ const existing = edgesByIssueId.get(row.issueId) ?? [];
590
+ if (!existing.some((edge) => edge.blockerIssueId === row.blockerIssueId)) {
591
+ existing.push(row);
592
+ edgesByIssueId.set(row.issueId, existing);
593
+ }
594
+ }
595
+ }
596
+ function summarizeIssueRelationRow(row) {
597
+ return {
598
+ id: row.relatedId,
599
+ identifier: row.identifier,
600
+ title: row.title,
601
+ status: row.status,
602
+ priority: row.priority,
603
+ assigneeAgentId: row.assigneeAgentId,
604
+ assigneeUserId: row.assigneeUserId,
605
+ };
606
+ }
607
+ async function terminalExplicitBlockersByRoot(companyId, roots, dbOrTx) {
608
+ const rootIds = [...new Set(roots.map((root) => root.id))];
609
+ const terminalByRoot = new Map();
610
+ if (rootIds.length === 0)
611
+ return terminalByRoot;
612
+ const nodesById = new Map();
613
+ const edgesByIssueId = new Map();
614
+ for (const root of roots)
615
+ nodesById.set(root.id, root);
616
+ let frontier = rootIds;
617
+ for (let depth = 0; frontier.length > 0 && depth < BLOCKER_ATTENTION_MAX_DEPTH; depth += 1) {
618
+ const nextFrontier = new Set();
619
+ for (const chunk of chunkList([...new Set(frontier)], ISSUE_LIST_RELATED_QUERY_CHUNK_SIZE)) {
620
+ const rows = await dbOrTx
621
+ .select({
622
+ currentIssueId: issueRelations.relatedIssueId,
623
+ relatedId: issues.id,
624
+ identifier: issues.identifier,
625
+ title: issues.title,
626
+ status: issues.status,
627
+ priority: issues.priority,
628
+ assigneeAgentId: issues.assigneeAgentId,
629
+ assigneeUserId: issues.assigneeUserId,
630
+ })
631
+ .from(issueRelations)
632
+ .innerJoin(issues, eq(issueRelations.issueId, issues.id))
633
+ .where(and(eq(issueRelations.companyId, companyId), eq(issueRelations.type, "blocks"), inArray(issueRelations.relatedIssueId, chunk), eq(issues.companyId, companyId), ne(issues.status, "done")));
634
+ for (const row of rows) {
635
+ const existingEdges = edgesByIssueId.get(row.currentIssueId) ?? [];
636
+ if (!existingEdges.includes(row.relatedId)) {
637
+ existingEdges.push(row.relatedId);
638
+ edgesByIssueId.set(row.currentIssueId, existingEdges);
639
+ }
640
+ if (!nodesById.has(row.relatedId)) {
641
+ nodesById.set(row.relatedId, summarizeIssueRelationRow(row));
642
+ nextFrontier.add(row.relatedId);
643
+ }
644
+ }
645
+ }
646
+ if (nodesById.size > BLOCKER_ATTENTION_MAX_NODES)
647
+ break;
648
+ frontier = [...nextFrontier];
649
+ }
650
+ const collectTerminal = (issueId, seen) => {
651
+ if (seen.has(issueId))
652
+ return [];
653
+ const node = nodesById.get(issueId);
654
+ if (!node || node.status === "done")
655
+ return [];
656
+ const nextSeen = new Set(seen);
657
+ nextSeen.add(issueId);
658
+ const downstreamIds = edgesByIssueId.get(issueId) ?? [];
659
+ if (downstreamIds.length === 0)
660
+ return [node];
661
+ return downstreamIds.flatMap((downstreamId) => collectTerminal(downstreamId, nextSeen));
662
+ };
663
+ for (const rootId of rootIds) {
664
+ const deduped = new Map();
665
+ for (const blocker of collectTerminal(rootId, new Set())) {
666
+ if (blocker.id !== rootId)
667
+ deduped.set(blocker.id, blocker);
668
+ }
669
+ if (deduped.size > 0) {
670
+ terminalByRoot.set(rootId, [...deduped.values()].sort((a, b) => a.title.localeCompare(b.title)));
671
+ }
672
+ }
673
+ return terminalByRoot;
674
+ }
675
+ function readProductivityReviewTrigger(value) {
676
+ if (typeof value !== "string")
677
+ return null;
678
+ return PRODUCTIVITY_REVIEW_TRIGGERS.includes(value)
679
+ ? value
680
+ : null;
681
+ }
682
+ function readProductivityReviewStreak(value) {
683
+ if (typeof value !== "number" || !Number.isFinite(value) || value < 0)
684
+ return null;
685
+ return Math.floor(value);
686
+ }
687
+ async function listIssueProductivityReviewMap(dbOrTx, companyId, sourceIssueIds) {
688
+ const map = new Map();
689
+ if (sourceIssueIds.length === 0)
690
+ return map;
691
+ const reviewRows = [];
692
+ for (const chunk of chunkList([...new Set(sourceIssueIds)], ISSUE_LIST_RELATED_QUERY_CHUNK_SIZE)) {
693
+ const rows = await dbOrTx
694
+ .select({
695
+ sourceIssueId: issues.originId,
696
+ reviewIssueId: issues.id,
697
+ reviewIdentifier: issues.identifier,
698
+ status: issues.status,
699
+ priority: issues.priority,
700
+ createdAt: issues.createdAt,
701
+ updatedAt: issues.updatedAt,
702
+ })
703
+ .from(issues)
704
+ .where(and(eq(issues.companyId, companyId), eq(issues.originKind, PRODUCTIVITY_REVIEW_ORIGIN_KIND), inArray(issues.originId, chunk), isNull(issues.hiddenAt), notInArray(issues.status, PRODUCTIVITY_REVIEW_TERMINAL_STATUSES)))
705
+ .orderBy(desc(issues.createdAt), desc(issues.id));
706
+ reviewRows.push(...rows);
707
+ }
708
+ if (reviewRows.length === 0)
709
+ return map;
710
+ const reviewIssueIds = reviewRows.map((row) => row.reviewIssueId);
711
+ const triggerByReviewIssueId = new Map();
712
+ for (const chunk of chunkList(reviewIssueIds, ISSUE_LIST_RELATED_QUERY_CHUNK_SIZE)) {
713
+ const detailRows = await dbOrTx
714
+ .select({
715
+ entityId: activityLog.entityId,
716
+ details: activityLog.details,
717
+ createdAt: activityLog.createdAt,
718
+ })
719
+ .from(activityLog)
720
+ .where(and(eq(activityLog.companyId, companyId), eq(activityLog.entityType, "issue"), inArray(activityLog.entityId, chunk), inArray(activityLog.action, PRODUCTIVITY_REVIEW_ACTIVITY_ACTIONS)))
721
+ .orderBy(desc(activityLog.createdAt));
722
+ for (const row of detailRows) {
723
+ if (triggerByReviewIssueId.has(row.entityId))
724
+ continue;
725
+ triggerByReviewIssueId.set(row.entityId, {
726
+ trigger: readProductivityReviewTrigger(row.details?.trigger),
727
+ noCommentStreak: readProductivityReviewStreak(row.details?.noCommentStreak),
728
+ });
729
+ }
730
+ }
731
+ for (const row of reviewRows) {
732
+ if (!row.sourceIssueId)
733
+ continue;
734
+ if (map.has(row.sourceIssueId))
735
+ continue;
736
+ const detail = triggerByReviewIssueId.get(row.reviewIssueId);
737
+ map.set(row.sourceIssueId, {
738
+ reviewIssueId: row.reviewIssueId,
739
+ reviewIdentifier: row.reviewIdentifier,
740
+ status: row.status,
741
+ priority: row.priority,
742
+ trigger: detail?.trigger ?? null,
743
+ noCommentStreak: detail?.noCommentStreak ?? null,
744
+ createdAt: row.createdAt,
745
+ updatedAt: row.updatedAt,
746
+ });
747
+ }
748
+ return map;
749
+ }
750
+ async function listIssueBlockerAttentionMap(dbOrTx, companyId, issueRows) {
751
+ const roots = issueRows.filter((row) => row.companyId === companyId && row.status === "blocked");
752
+ const attentionMap = new Map();
753
+ for (const row of issueRows) {
754
+ if (row.status !== "blocked") {
755
+ attentionMap.set(row.id, createIssueBlockerAttention());
756
+ }
757
+ }
758
+ if (roots.length === 0)
759
+ return attentionMap;
760
+ const nodesById = new Map();
761
+ const edgesByIssueId = new Map();
762
+ for (const root of roots)
763
+ nodesById.set(root.id, { ...root });
764
+ let frontier = roots.map((root) => root.id);
765
+ let truncated = false;
766
+ for (let depth = 0; frontier.length > 0 && depth < BLOCKER_ATTENTION_MAX_DEPTH; depth += 1) {
767
+ const nextFrontier = new Set();
768
+ for (const chunk of chunkList([...new Set(frontier)], ISSUE_LIST_RELATED_QUERY_CHUNK_SIZE)) {
769
+ const explicitBlockerRowsPromise = dbOrTx
770
+ .select({
771
+ issueId: issueRelations.relatedIssueId,
772
+ blockerIssueId: issues.id,
773
+ id: issues.id,
774
+ companyId: issues.companyId,
775
+ parentId: issues.parentId,
776
+ identifier: issues.identifier,
777
+ title: issues.title,
778
+ status: issues.status,
779
+ executionRunId: issues.executionRunId,
780
+ assigneeAgentId: issues.assigneeAgentId,
781
+ assigneeUserId: issues.assigneeUserId,
782
+ })
783
+ .from(issueRelations)
784
+ .innerJoin(issues, eq(issueRelations.issueId, issues.id))
785
+ .where(and(eq(issueRelations.companyId, companyId), eq(issueRelations.type, "blocks"), inArray(issueRelations.relatedIssueId, chunk), eq(issues.companyId, companyId), ne(issues.status, "done")));
786
+ const childRowsPromise = dbOrTx
787
+ .select({
788
+ issueId: issues.parentId,
789
+ blockerIssueId: issues.id,
790
+ id: issues.id,
791
+ companyId: issues.companyId,
792
+ parentId: issues.parentId,
793
+ identifier: issues.identifier,
794
+ title: issues.title,
795
+ status: issues.status,
796
+ executionRunId: issues.executionRunId,
797
+ assigneeAgentId: issues.assigneeAgentId,
798
+ assigneeUserId: issues.assigneeUserId,
799
+ })
800
+ .from(issues)
801
+ .where(and(eq(issues.companyId, companyId), inArray(issues.parentId, chunk), ne(issues.status, "done")));
802
+ const [explicitBlockerRows, childRows] = await Promise.all([
803
+ explicitBlockerRowsPromise,
804
+ childRowsPromise,
805
+ ]);
806
+ appendBlockerAttentionEdges(edgesByIssueId, [
807
+ ...explicitBlockerRows
808
+ .filter((row) => row.issueId !== null)
809
+ .map((row) => ({ issueId: row.issueId, blockerIssueId: row.blockerIssueId })),
810
+ ...childRows
811
+ .filter((row) => row.issueId !== null)
812
+ .map((row) => ({ issueId: row.issueId, blockerIssueId: row.blockerIssueId })),
813
+ ]);
814
+ for (const row of [...explicitBlockerRows, ...childRows]) {
815
+ if (!row.issueId || nodesById.has(row.blockerIssueId))
816
+ continue;
817
+ nodesById.set(row.blockerIssueId, {
818
+ id: row.blockerIssueId,
819
+ companyId: row.companyId,
820
+ parentId: row.parentId,
821
+ identifier: row.identifier,
822
+ title: row.title,
823
+ status: row.status,
824
+ executionRunId: row.executionRunId,
825
+ assigneeAgentId: row.assigneeAgentId,
826
+ assigneeUserId: row.assigneeUserId,
827
+ });
828
+ nextFrontier.add(row.blockerIssueId);
829
+ }
830
+ }
831
+ if (nodesById.size > BLOCKER_ATTENTION_MAX_NODES) {
832
+ truncated = true;
833
+ break;
834
+ }
835
+ frontier = [...nextFrontier];
836
+ }
837
+ if (frontier.length > 0)
838
+ truncated = true;
839
+ const nodeIds = [...nodesById.keys()];
840
+ const activeIssueIds = new Set();
841
+ const agentIds = new Set();
842
+ const issueIdByExecutionRunId = new Map();
843
+ for (const node of nodesById.values()) {
844
+ if (node.assigneeAgentId)
845
+ agentIds.add(node.assigneeAgentId);
846
+ if (node.executionRunId)
847
+ issueIdByExecutionRunId.set(node.executionRunId, node.id);
848
+ }
849
+ for (const chunk of chunkList([...issueIdByExecutionRunId.keys()], ISSUE_LIST_RELATED_QUERY_CHUNK_SIZE)) {
850
+ const runRows = await dbOrTx
851
+ .select({
852
+ id: heartbeatRuns.id,
853
+ })
854
+ .from(heartbeatRuns)
855
+ .where(and(eq(heartbeatRuns.companyId, companyId), inArray(heartbeatRuns.status, BLOCKER_ATTENTION_ACTIVE_RUN_STATUSES), inArray(heartbeatRuns.id, chunk)));
856
+ for (const row of runRows) {
857
+ const issueId = issueIdByExecutionRunId.get(row.id);
858
+ if (issueId)
859
+ activeIssueIds.add(issueId);
860
+ }
861
+ }
862
+ for (const chunk of chunkList(nodeIds, ISSUE_LIST_RELATED_QUERY_CHUNK_SIZE)) {
863
+ const wakeRowsPromise = dbOrTx
864
+ .select({
865
+ issueId: sql `${agentWakeupRequests.payload} ->> 'issueId'`,
866
+ })
867
+ .from(agentWakeupRequests)
868
+ .where(and(eq(agentWakeupRequests.companyId, companyId), inArray(agentWakeupRequests.status, BLOCKER_ATTENTION_ACTIVE_WAKE_STATUSES), sql `${agentWakeupRequests.runId} is null`, inArray(sql `${agentWakeupRequests.payload} ->> 'issueId'`, chunk)));
869
+ const wakeRows = await wakeRowsPromise;
870
+ for (const row of wakeRows) {
871
+ if (row.issueId)
872
+ activeIssueIds.add(row.issueId);
873
+ }
874
+ }
875
+ const explicitWaitCandidateIds = [...nodesById.values()]
876
+ .filter((node) => node.status !== "done")
877
+ .map((node) => node.id);
878
+ const explicitWaitingIssueIds = new Set();
879
+ if (explicitWaitCandidateIds.length > 0) {
880
+ for (const chunk of chunkList(explicitWaitCandidateIds, ISSUE_LIST_RELATED_QUERY_CHUNK_SIZE)) {
881
+ const interactionRows = await dbOrTx
882
+ .select({ issueId: issueThreadInteractions.issueId })
883
+ .from(issueThreadInteractions)
884
+ .where(and(eq(issueThreadInteractions.companyId, companyId), inArray(issueThreadInteractions.status, BLOCKER_ATTENTION_PENDING_INTERACTION_STATUSES), inArray(issueThreadInteractions.issueId, chunk)));
885
+ for (const row of interactionRows)
886
+ explicitWaitingIssueIds.add(row.issueId);
887
+ const approvalRows = await dbOrTx
888
+ .select({ issueId: issueApprovals.issueId })
889
+ .from(issueApprovals)
890
+ .innerJoin(approvals, eq(issueApprovals.approvalId, approvals.id))
891
+ .where(and(eq(issueApprovals.companyId, companyId), inArray(approvals.status, BLOCKER_ATTENTION_PENDING_APPROVAL_STATUSES), inArray(issueApprovals.issueId, chunk)));
892
+ for (const row of approvalRows)
893
+ explicitWaitingIssueIds.add(row.issueId);
894
+ }
895
+ // Recovery rows are intentionally company-wide: a liveness escalation for
896
+ // the same leaf blocker represents an active waiting path even when that
897
+ // blocker is reached through another blocked graph.
898
+ const recoveryRows = await dbOrTx
899
+ .select({ id: issues.id, originId: issues.originId })
900
+ .from(issues)
901
+ .where(and(eq(issues.companyId, companyId), eq(issues.originKind, BLOCKER_ATTENTION_OPEN_RECOVERY_ORIGIN_KIND), isNull(issues.hiddenAt), notInArray(issues.status, BLOCKER_ATTENTION_OPEN_RECOVERY_TERMINAL_STATUSES)));
902
+ for (const row of recoveryRows) {
903
+ const parsed = parseIssueGraphLivenessIncidentKey(row.originId);
904
+ if (!parsed || parsed.companyId !== companyId)
905
+ continue;
906
+ explicitWaitingIssueIds.add(row.id);
907
+ explicitWaitingIssueIds.add(parsed.issueId);
908
+ explicitWaitingIssueIds.add(parsed.leafIssueId);
909
+ }
910
+ const recoveryActionRows = await dbOrTx
911
+ .select({ sourceIssueId: issueRecoveryActions.sourceIssueId })
912
+ .from(issueRecoveryActions)
913
+ .where(and(eq(issueRecoveryActions.companyId, companyId), inArray(issueRecoveryActions.status, ["active", "escalated"]), inArray(issueRecoveryActions.sourceIssueId, explicitWaitCandidateIds)));
914
+ for (const row of recoveryActionRows)
915
+ explicitWaitingIssueIds.add(row.sourceIssueId);
916
+ }
917
+ const agentRows = agentIds.size > 0
918
+ ? await dbOrTx
919
+ .select({
920
+ id: agents.id,
921
+ companyId: agents.companyId,
922
+ status: agents.status,
923
+ })
924
+ .from(agents)
925
+ .where(and(eq(agents.companyId, companyId), inArray(agents.id, [...agentIds])))
926
+ : [];
927
+ const agentsById = new Map(agentRows.map((agent) => [agent.id, agent]));
928
+ const classifyPath = (nodeId, seen) => {
929
+ const sample = blockerSampleIdentifier(nodesById.get(nodeId));
930
+ if (truncated || seen.has(nodeId)) {
931
+ return { covered: false, stalled: false, sampleBlockerIdentifier: sample, sampleStalledBlockerIdentifier: null };
932
+ }
933
+ const node = nodesById.get(nodeId);
934
+ if (!node || node.companyId !== companyId) {
935
+ return { covered: false, stalled: false, sampleBlockerIdentifier: nodeId, sampleStalledBlockerIdentifier: null };
936
+ }
937
+ const nodeSample = blockerSampleIdentifier(node);
938
+ if (node.status === "done") {
939
+ return { covered: true, stalled: false, sampleBlockerIdentifier: nodeSample, sampleStalledBlockerIdentifier: null };
940
+ }
941
+ if (explicitWaitingIssueIds.has(node.id)) {
942
+ return { covered: true, stalled: false, sampleBlockerIdentifier: nodeSample, sampleStalledBlockerIdentifier: null };
943
+ }
944
+ if (node.assigneeUserId && node.status !== "cancelled") {
945
+ return { covered: true, stalled: false, sampleBlockerIdentifier: nodeSample, sampleStalledBlockerIdentifier: null };
946
+ }
947
+ if (node.status === "in_review") {
948
+ const hasWaitingPath = activeIssueIds.has(node.id) || Boolean(node.assigneeUserId);
949
+ if (hasWaitingPath) {
950
+ return { covered: true, stalled: false, sampleBlockerIdentifier: nodeSample, sampleStalledBlockerIdentifier: null };
951
+ }
952
+ return { covered: false, stalled: true, sampleBlockerIdentifier: nodeSample, sampleStalledBlockerIdentifier: nodeSample };
953
+ }
954
+ if (activeIssueIds.has(node.id)) {
955
+ return { covered: true, stalled: false, sampleBlockerIdentifier: nodeSample, sampleStalledBlockerIdentifier: null };
956
+ }
957
+ if (node.status === "cancelled") {
958
+ return { covered: false, stalled: false, sampleBlockerIdentifier: nodeSample, sampleStalledBlockerIdentifier: null };
959
+ }
960
+ if (node.status === "backlog" && node.assigneeAgentId) {
961
+ return { covered: false, stalled: false, sampleBlockerIdentifier: nodeSample, sampleStalledBlockerIdentifier: null };
962
+ }
963
+ const downstream = (edgesByIssueId.get(node.id) ?? []).filter((edge) => nodesById.get(edge.blockerIssueId)?.status !== "done");
964
+ if (downstream.length > 0) {
965
+ const nextSeen = new Set(seen);
966
+ nextSeen.add(nodeId);
967
+ const classified = downstream.map((edge) => classifyPath(edge.blockerIssueId, nextSeen));
968
+ const stalledChild = classified.find((result) => result.stalled || result.sampleStalledBlockerIdentifier);
969
+ const sampleStalled = stalledChild?.sampleStalledBlockerIdentifier ?? null;
970
+ const hardAttention = classified.find((result) => !result.covered && !result.stalled);
971
+ if (hardAttention) {
972
+ return {
973
+ covered: false,
974
+ stalled: false,
975
+ sampleBlockerIdentifier: hardAttention.sampleBlockerIdentifier,
976
+ sampleStalledBlockerIdentifier: sampleStalled,
977
+ };
978
+ }
979
+ const stalledEntry = classified.find((result) => result.stalled);
980
+ if (stalledEntry) {
981
+ return {
982
+ covered: false,
983
+ stalled: true,
984
+ sampleBlockerIdentifier: stalledEntry.sampleBlockerIdentifier,
985
+ sampleStalledBlockerIdentifier: sampleStalled,
986
+ };
987
+ }
988
+ return {
989
+ covered: true,
990
+ stalled: false,
991
+ sampleBlockerIdentifier: classified[0]?.sampleBlockerIdentifier ?? nodeSample,
992
+ sampleStalledBlockerIdentifier: null,
993
+ };
994
+ }
995
+ if (node.assigneeAgentId) {
996
+ const assignee = agentsById.get(node.assigneeAgentId);
997
+ if (!assignee || assignee.companyId !== companyId || !BLOCKER_ATTENTION_INVOKABLE_AGENT_STATUSES.has(assignee.status)) {
998
+ return { covered: false, stalled: false, sampleBlockerIdentifier: nodeSample, sampleStalledBlockerIdentifier: null };
999
+ }
1000
+ }
1001
+ return { covered: false, stalled: false, sampleBlockerIdentifier: nodeSample, sampleStalledBlockerIdentifier: null };
1002
+ };
1003
+ for (const root of roots) {
1004
+ const topLevelEdges = (edgesByIssueId.get(root.id) ?? []).filter((edge) => nodesById.get(edge.blockerIssueId)?.status !== "done");
1005
+ if (topLevelEdges.length === 0) {
1006
+ attentionMap.set(root.id, createIssueBlockerAttention({
1007
+ state: "needs_attention",
1008
+ reason: "attention_required",
1009
+ }));
1010
+ continue;
1011
+ }
1012
+ const classified = topLevelEdges.map((edge) => ({
1013
+ edge,
1014
+ result: classifyPath(edge.blockerIssueId, new Set([root.id])),
1015
+ }));
1016
+ const coveredBlockerCount = classified.filter((entry) => entry.result.covered).length;
1017
+ const stalledBlockerCount = classified.filter((entry) => entry.result.stalled).length;
1018
+ const attentionBlockerCount = classified.length - coveredBlockerCount - stalledBlockerCount;
1019
+ const hardAttentionEntry = classified.find((entry) => !entry.result.covered && !entry.result.stalled);
1020
+ const stalledEntry = classified.find((entry) => entry.result.stalled);
1021
+ const sampleEntry = hardAttentionEntry ?? stalledEntry ?? classified[0] ?? null;
1022
+ const sampleNode = sampleEntry ? nodesById.get(sampleEntry.edge.blockerIssueId) : null;
1023
+ const sampleStalledFromChain = classified
1024
+ .map((entry) => entry.result.sampleStalledBlockerIdentifier)
1025
+ .find((value) => value);
1026
+ let state;
1027
+ let reason;
1028
+ if (attentionBlockerCount > 0) {
1029
+ state = "needs_attention";
1030
+ reason = "attention_required";
1031
+ }
1032
+ else if (stalledBlockerCount > 0) {
1033
+ state = "stalled";
1034
+ reason = "stalled_review";
1035
+ }
1036
+ else {
1037
+ state = "covered";
1038
+ reason = topLevelEdges.every((edge) => nodesById.get(edge.blockerIssueId)?.parentId === root.id)
1039
+ ? "active_child"
1040
+ : "active_dependency";
1041
+ }
1042
+ attentionMap.set(root.id, createIssueBlockerAttention({
1043
+ state,
1044
+ reason,
1045
+ unresolvedBlockerCount: topLevelEdges.length,
1046
+ coveredBlockerCount,
1047
+ stalledBlockerCount,
1048
+ attentionBlockerCount,
1049
+ sampleBlockerIdentifier: sampleEntry?.result.sampleBlockerIdentifier ?? blockerSampleIdentifier(sampleNode),
1050
+ sampleStalledBlockerIdentifier: stalledEntry?.result.sampleStalledBlockerIdentifier ?? sampleStalledFromChain ?? null,
1051
+ }));
1052
+ }
1053
+ return attentionMap;
1054
+ }
1055
+ const issueListSelect = {
1056
+ id: issues.id,
1057
+ companyId: issues.companyId,
1058
+ projectId: issues.projectId,
1059
+ projectWorkspaceId: issues.projectWorkspaceId,
1060
+ goalId: issues.goalId,
1061
+ parentId: issues.parentId,
1062
+ title: issues.title,
1063
+ description: sql `
1064
+ CASE
1065
+ WHEN ${issues.description} IS NULL THEN NULL
1066
+ ELSE encode(
1067
+ substring(
1068
+ convert_to(${issues.description}, current_setting('server_encoding'))
1069
+ FROM 1 FOR ${ISSUE_LIST_DESCRIPTION_MAX_BYTES}
1070
+ ),
1071
+ 'base64'
1072
+ )
1073
+ END
1074
+ `,
1075
+ status: issues.status,
1076
+ workMode: issues.workMode,
1077
+ priority: issues.priority,
1078
+ assigneeAgentId: issues.assigneeAgentId,
1079
+ assigneeUserId: issues.assigneeUserId,
1080
+ checkoutRunId: issues.checkoutRunId,
1081
+ executionRunId: issues.executionRunId,
1082
+ executionAgentNameKey: issues.executionAgentNameKey,
1083
+ executionLockedAt: issues.executionLockedAt,
1084
+ createdByAgentId: issues.createdByAgentId,
1085
+ createdByUserId: issues.createdByUserId,
1086
+ issueNumber: issues.issueNumber,
1087
+ identifier: issues.identifier,
1088
+ originKind: issues.originKind,
1089
+ originId: issues.originId,
1090
+ originRunId: issues.originRunId,
1091
+ originFingerprint: issues.originFingerprint,
1092
+ requestDepth: issues.requestDepth,
1093
+ billingCode: issues.billingCode,
1094
+ assigneeAdapterOverrides: issues.assigneeAdapterOverrides,
1095
+ executionPolicy: sql `null`,
1096
+ executionState: sql `null`,
1097
+ monitorNextCheckAt: issues.monitorNextCheckAt,
1098
+ monitorWakeRequestedAt: issues.monitorWakeRequestedAt,
1099
+ monitorLastTriggeredAt: issues.monitorLastTriggeredAt,
1100
+ monitorAttemptCount: issues.monitorAttemptCount,
1101
+ monitorNotes: issues.monitorNotes,
1102
+ monitorScheduledBy: issues.monitorScheduledBy,
1103
+ executionWorkspaceId: issues.executionWorkspaceId,
1104
+ executionWorkspacePreference: issues.executionWorkspacePreference,
1105
+ executionWorkspaceSettings: sql `null`,
1106
+ startedAt: issues.startedAt,
1107
+ completedAt: issues.completedAt,
1108
+ cancelledAt: issues.cancelledAt,
1109
+ hiddenAt: issues.hiddenAt,
1110
+ createdAt: issues.createdAt,
1111
+ updatedAt: issues.updatedAt,
1112
+ };
1113
+ function withActiveRuns(issueRows, runMap) {
1114
+ return issueRows.map((row) => ({
1115
+ ...row,
1116
+ activeRun: row.executionRunId ? (runMap.get(row.executionRunId) ?? null) : null,
1117
+ }));
1118
+ }
1119
+ async function userCommentStatsForIssues(dbOrTx, companyId, userId, issueIds) {
1120
+ const stats = [];
1121
+ for (const issueIdChunk of chunkList(issueIds, ISSUE_LIST_RELATED_QUERY_CHUNK_SIZE)) {
1122
+ const rows = await dbOrTx
1123
+ .select({
1124
+ issueId: issueComments.issueId,
1125
+ myLastCommentAt: sql `
1126
+ MAX(CASE WHEN ${issueComments.authorUserId} = ${userId} THEN ${issueComments.createdAt} END)
1127
+ `,
1128
+ lastExternalCommentAt: sql `
1129
+ MAX(
1130
+ CASE
1131
+ WHEN ${issueComments.authorUserId} IS NULL OR ${issueComments.authorUserId} <> ${userId}
1132
+ THEN ${issueComments.createdAt}
1133
+ END
1134
+ )
1135
+ `,
1136
+ })
1137
+ .from(issueComments)
1138
+ .where(and(eq(issueComments.companyId, companyId), inArray(issueComments.issueId, issueIdChunk)))
1139
+ .groupBy(issueComments.issueId);
1140
+ stats.push(...rows);
1141
+ }
1142
+ return stats;
1143
+ }
1144
+ async function userReadStatsForIssues(dbOrTx, companyId, userId, issueIds) {
1145
+ const stats = [];
1146
+ for (const issueIdChunk of chunkList(issueIds, ISSUE_LIST_RELATED_QUERY_CHUNK_SIZE)) {
1147
+ const rows = await dbOrTx
1148
+ .select({
1149
+ issueId: issueReadStates.issueId,
1150
+ myLastReadAt: issueReadStates.lastReadAt,
1151
+ })
1152
+ .from(issueReadStates)
1153
+ .where(and(eq(issueReadStates.companyId, companyId), eq(issueReadStates.userId, userId), inArray(issueReadStates.issueId, issueIdChunk)));
1154
+ stats.push(...rows);
1155
+ }
1156
+ return stats;
1157
+ }
1158
+ async function lastActivityStatsForIssues(dbOrTx, companyId, issueIds) {
1159
+ const byIssueId = new Map();
1160
+ for (const issueIdChunk of chunkList(issueIds, ISSUE_LIST_RELATED_QUERY_CHUNK_SIZE)) {
1161
+ const [commentRows, logRows] = await Promise.all([
1162
+ dbOrTx
1163
+ .select({
1164
+ issueId: issueComments.issueId,
1165
+ latestCommentAt: sql `MAX(${issueComments.createdAt})`,
1166
+ })
1167
+ .from(issueComments)
1168
+ .where(and(eq(issueComments.companyId, companyId), inArray(issueComments.issueId, issueIdChunk)))
1169
+ .groupBy(issueComments.issueId),
1170
+ dbOrTx
1171
+ .select({
1172
+ issueId: activityLog.entityId,
1173
+ latestLogAt: sql `MAX(${activityLog.createdAt})`,
1174
+ })
1175
+ .from(activityLog)
1176
+ .where(and(eq(activityLog.companyId, companyId), eq(activityLog.entityType, "issue"), inArray(activityLog.entityId, issueIdChunk), sql `${activityLog.action} NOT IN (${sql.join(ISSUE_LOCAL_INBOX_ACTIVITY_ACTIONS.map((action) => sql `${action}`), sql `, `)})`))
1177
+ .groupBy(activityLog.entityId),
1178
+ ]);
1179
+ for (const row of commentRows) {
1180
+ byIssueId.set(row.issueId, {
1181
+ issueId: row.issueId,
1182
+ latestCommentAt: row.latestCommentAt,
1183
+ latestLogAt: null,
1184
+ });
1185
+ }
1186
+ for (const row of logRows) {
1187
+ const existing = byIssueId.get(row.issueId);
1188
+ if (existing)
1189
+ existing.latestLogAt = row.latestLogAt;
1190
+ else {
1191
+ byIssueId.set(row.issueId, {
1192
+ issueId: row.issueId,
1193
+ latestCommentAt: null,
1194
+ latestLogAt: row.latestLogAt,
1195
+ });
1196
+ }
1197
+ }
1198
+ }
1199
+ return [...byIssueId.values()];
1200
+ }
1201
+ async function blockedByMapForIssues(dbOrTx, companyId, issueIds) {
1202
+ const map = new Map();
1203
+ const uniqueIssueIds = [...new Set(issueIds)];
1204
+ if (uniqueIssueIds.length === 0)
1205
+ return map;
1206
+ for (const issueId of uniqueIssueIds) {
1207
+ map.set(issueId, []);
1208
+ }
1209
+ for (const issueIdChunk of chunkList(uniqueIssueIds, ISSUE_LIST_RELATED_QUERY_CHUNK_SIZE)) {
1210
+ const rows = await dbOrTx
1211
+ .select({
1212
+ currentIssueId: issueRelations.relatedIssueId,
1213
+ relatedId: issues.id,
1214
+ identifier: issues.identifier,
1215
+ title: issues.title,
1216
+ status: issues.status,
1217
+ priority: issues.priority,
1218
+ assigneeAgentId: issues.assigneeAgentId,
1219
+ assigneeUserId: issues.assigneeUserId,
1220
+ })
1221
+ .from(issueRelations)
1222
+ .innerJoin(issues, eq(issueRelations.issueId, issues.id))
1223
+ .where(and(eq(issueRelations.companyId, companyId), eq(issueRelations.type, "blocks"), inArray(issueRelations.relatedIssueId, issueIdChunk)));
1224
+ for (const row of rows) {
1225
+ const blockedBy = map.get(row.currentIssueId);
1226
+ if (!blockedBy)
1227
+ continue;
1228
+ blockedBy.push({
1229
+ id: row.relatedId,
1230
+ identifier: row.identifier,
1231
+ title: row.title,
1232
+ status: row.status,
1233
+ priority: row.priority,
1234
+ assigneeAgentId: row.assigneeAgentId,
1235
+ assigneeUserId: row.assigneeUserId,
1236
+ });
1237
+ }
1238
+ }
1239
+ for (const blockedBy of map.values()) {
1240
+ blockedBy.sort((a, b) => a.title.localeCompare(b.title));
1241
+ }
1242
+ return map;
1243
+ }
1244
+ export function issueService(db) {
1245
+ const instanceSettings = instanceSettingsService(db);
1246
+ const treeControlSvc = issueTreeControlService(db);
1247
+ async function getIssueByUuid(id) {
1248
+ const row = await db
1249
+ .select()
1250
+ .from(issues)
1251
+ .where(eq(issues.id, id))
1252
+ .then((rows) => rows[0] ?? null);
1253
+ if (!row)
1254
+ return null;
1255
+ const [enriched] = await withIssueLabels(db, [row]);
1256
+ return enriched;
1257
+ }
1258
+ async function getIssueByIdentifier(identifier) {
1259
+ const row = await db
1260
+ .select()
1261
+ .from(issues)
1262
+ .where(eq(issues.identifier, identifier.toUpperCase()))
1263
+ .then((rows) => rows[0] ?? null);
1264
+ if (!row)
1265
+ return null;
1266
+ const [enriched] = await withIssueLabels(db, [row]);
1267
+ return enriched;
1268
+ }
1269
+ async function getCurrentScheduledRetryForIssue(issueId, companyId) {
1270
+ const row = await db
1271
+ .select({
1272
+ runId: heartbeatRuns.id,
1273
+ status: heartbeatRuns.status,
1274
+ agentId: heartbeatRuns.agentId,
1275
+ agentName: agents.name,
1276
+ retryOfRunId: heartbeatRuns.retryOfRunId,
1277
+ scheduledRetryAt: heartbeatRuns.scheduledRetryAt,
1278
+ scheduledRetryAttempt: heartbeatRuns.scheduledRetryAttempt,
1279
+ scheduledRetryReason: heartbeatRuns.scheduledRetryReason,
1280
+ error: heartbeatRuns.error,
1281
+ errorCode: heartbeatRuns.errorCode,
1282
+ })
1283
+ .from(heartbeatRuns)
1284
+ .innerJoin(agents, eq(heartbeatRuns.agentId, agents.id))
1285
+ .where(and(eq(heartbeatRuns.companyId, companyId), eq(heartbeatRuns.status, "scheduled_retry"), sql `${heartbeatRuns.contextSnapshot} ->> 'issueId' = ${issueId}`))
1286
+ .orderBy(asc(heartbeatRuns.scheduledRetryAt), asc(heartbeatRuns.createdAt), asc(heartbeatRuns.id))
1287
+ .limit(1)
1288
+ .then((rows) => rows[0] ?? null);
1289
+ return row ? { ...row, status: "scheduled_retry" } : null;
1290
+ }
1291
+ function deriveIssueCommentAuthorType(comment) {
1292
+ const explicit = issueCommentAuthorTypeSchema.safeParse(comment.authorType);
1293
+ if (explicit.success)
1294
+ return explicit.data;
1295
+ if (comment.authorAgentId)
1296
+ return "agent";
1297
+ if (comment.authorUserId)
1298
+ return "user";
1299
+ return "system";
1300
+ }
1301
+ function assertIssueCommentAuthorTypeAllowed(actor, authorType) {
1302
+ if (actor.agentId && authorType !== "agent") {
1303
+ throw unprocessable("Comment authorType must match authenticated actor");
1304
+ }
1305
+ if (actor.userId && authorType !== "user") {
1306
+ throw unprocessable("Comment authorType must match authenticated actor");
1307
+ }
1308
+ if (!actor.agentId && !actor.userId && authorType !== "system") {
1309
+ throw unprocessable("System comments cannot use user or agent authorType without an author id");
1310
+ }
1311
+ }
1312
+ function redactIssueComment(comment, censorUsernameInLogs) {
1313
+ return {
1314
+ ...comment,
1315
+ authorType: deriveIssueCommentAuthorType(comment),
1316
+ body: redactCurrentUserText(comment.body, { enabled: censorUsernameInLogs }),
1317
+ presentation: issueCommentPresentationSchema.nullable().catch(null).parse(comment.presentation ?? null),
1318
+ metadata: issueCommentMetadataSchema.nullable().catch(null).parse(comment.metadata ?? null),
1319
+ };
1320
+ }
1321
+ async function readRunLogText(run) {
1322
+ if (run.logStore !== "local_file" || !run.logRef)
1323
+ return "";
1324
+ const logBytes = Number(run.logBytes ?? 0);
1325
+ if (!Number.isFinite(logBytes) || logBytes <= 0)
1326
+ return "";
1327
+ const store = getRunLogStore();
1328
+ let offset = 0;
1329
+ let content = "";
1330
+ let nextOffset = 0;
1331
+ while (nextOffset !== undefined) {
1332
+ const remainingBytes = ISSUE_COMMENT_RUN_LOG_DERIVATION_MAX_LOG_BYTES - Buffer.byteLength(content, "utf8");
1333
+ if (remainingBytes <= 0)
1334
+ break;
1335
+ const chunk = await store.read({ store: "local_file", logRef: run.logRef }, {
1336
+ offset,
1337
+ limitBytes: Math.min(ISSUE_COMMENT_RUN_LOG_DERIVATION_CHUNK_BYTES, remainingBytes),
1338
+ });
1339
+ content += chunk.content;
1340
+ nextOffset = chunk.nextOffset;
1341
+ offset = chunk.nextOffset ?? 0;
1342
+ }
1343
+ return content;
1344
+ }
1345
+ async function enrichCommentsWithDerivedAgentAttribution(comments) {
1346
+ const candidates = comments.filter((comment) => !comment.authorAgentId
1347
+ && !!comment.authorUserId
1348
+ && !comment.createdByRunId);
1349
+ if (candidates.length === 0)
1350
+ return comments;
1351
+ const companyId = comments[0]?.companyId ?? null;
1352
+ const issueId = comments[0]?.issueId ?? null;
1353
+ if (!companyId || !issueId)
1354
+ return comments;
1355
+ const minCommentCreatedAtMs = candidates.reduce((min, comment) => {
1356
+ const timestamp = toTimestampMs(comment.createdAt);
1357
+ if (timestamp === null)
1358
+ return min;
1359
+ return min === null ? timestamp : Math.min(min, timestamp);
1360
+ }, null);
1361
+ const maxCommentCreatedAtMs = candidates.reduce((max, comment) => {
1362
+ const timestamp = toTimestampMs(comment.createdAt);
1363
+ if (timestamp === null)
1364
+ return max;
1365
+ return max === null ? timestamp : Math.max(max, timestamp);
1366
+ }, null);
1367
+ if (minCommentCreatedAtMs === null || maxCommentCreatedAtMs === null)
1368
+ return comments;
1369
+ const minRunEndBound = new Date(minCommentCreatedAtMs).toISOString();
1370
+ const maxRunStartBound = new Date(maxCommentCreatedAtMs + ISSUE_COMMENT_RUN_LOG_DERIVATION_END_SLACK_MS).toISOString();
1371
+ const runs = await db
1372
+ .select({
1373
+ runId: heartbeatRuns.id,
1374
+ agentId: heartbeatRuns.agentId,
1375
+ createdAt: heartbeatRuns.createdAt,
1376
+ startedAt: heartbeatRuns.startedAt,
1377
+ finishedAt: heartbeatRuns.finishedAt,
1378
+ logStore: heartbeatRuns.logStore,
1379
+ logRef: heartbeatRuns.logRef,
1380
+ logBytes: heartbeatRuns.logBytes,
1381
+ })
1382
+ .from(heartbeatRuns)
1383
+ .where(and(eq(heartbeatRuns.companyId, companyId), or(sql `${heartbeatRuns.contextSnapshot} ->> 'issueId' = ${issueId}`, sql `exists (
1384
+ select 1
1385
+ from ${activityLog}
1386
+ where ${activityLog.companyId} = ${companyId}
1387
+ and ${activityLog.entityType} = 'issue'
1388
+ and ${activityLog.entityId} = ${issueId}
1389
+ and ${activityLog.runId} = ${heartbeatRuns.id}
1390
+ )`), sql `coalesce(${heartbeatRuns.finishedAt}, ${heartbeatRuns.createdAt}) >= ${minRunEndBound}::timestamptz`, sql `coalesce(${heartbeatRuns.startedAt}, ${heartbeatRuns.createdAt}) <= ${maxRunStartBound}::timestamptz`))
1391
+ .orderBy(desc(heartbeatRuns.createdAt));
1392
+ if (runs.length === 0)
1393
+ return comments;
1394
+ const runsWithLogs = [];
1395
+ for (let index = 0; index < runs.length; index += ISSUE_COMMENT_RUN_LOG_DERIVATION_MAX_PARALLEL_READS) {
1396
+ const batch = runs.slice(index, index + ISSUE_COMMENT_RUN_LOG_DERIVATION_MAX_PARALLEL_READS);
1397
+ const batchWithLogs = await Promise.all(batch.map(async (run) => ({
1398
+ ...run,
1399
+ logContent: await readRunLogText(run),
1400
+ })));
1401
+ runsWithLogs.push(...batchWithLogs);
1402
+ }
1403
+ const derivedByCommentId = deriveIssueCommentRunLogAttribution(candidates, runsWithLogs);
1404
+ if (derivedByCommentId.size === 0)
1405
+ return comments;
1406
+ return comments.map((comment) => {
1407
+ const derived = derivedByCommentId.get(comment.id);
1408
+ return derived ? { ...comment, ...derived } : comment;
1409
+ });
1410
+ }
1411
+ async function assertAssignableAgent(companyId, agentId) {
1412
+ const assignee = await db
1413
+ .select({
1414
+ id: agents.id,
1415
+ companyId: agents.companyId,
1416
+ status: agents.status,
1417
+ })
1418
+ .from(agents)
1419
+ .where(eq(agents.id, agentId))
1420
+ .then((rows) => rows[0] ?? null);
1421
+ if (!assignee)
1422
+ throw notFound("Assignee agent not found");
1423
+ if (assignee.companyId !== companyId) {
1424
+ throw unprocessable("Assignee must belong to same company");
1425
+ }
1426
+ if (assignee.status === "pending_approval") {
1427
+ throw conflict("Cannot assign work to pending approval agents");
1428
+ }
1429
+ if (assignee.status === "terminated") {
1430
+ throw conflict("Cannot assign work to terminated agents");
1431
+ }
1432
+ }
1433
+ async function isTreeHoldInteractionCheckoutAllowed(companyId, checkoutRunId, _gate) {
1434
+ if (!checkoutRunId)
1435
+ return false;
1436
+ const run = await db
1437
+ .select({
1438
+ id: heartbeatRuns.id,
1439
+ agentId: heartbeatRuns.agentId,
1440
+ wakeupRequestId: heartbeatRuns.wakeupRequestId,
1441
+ contextSnapshot: heartbeatRuns.contextSnapshot,
1442
+ })
1443
+ .from(heartbeatRuns)
1444
+ .where(and(eq(heartbeatRuns.id, checkoutRunId), eq(heartbeatRuns.companyId, companyId)))
1445
+ .then((rows) => rows[0] ?? null);
1446
+ const issueId = readStringFromRecord(run?.contextSnapshot, "issueId");
1447
+ if (!run || !issueId)
1448
+ return false;
1449
+ return isVerifiedIssueTreeControlInteractionWake(db, {
1450
+ companyId,
1451
+ issueId,
1452
+ agentId: run.agentId,
1453
+ runId: run.id,
1454
+ wakeupRequestId: run.wakeupRequestId,
1455
+ contextSnapshot: run.contextSnapshot,
1456
+ });
1457
+ }
1458
+ async function assertAssignableUser(companyId, userId) {
1459
+ const membership = await db
1460
+ .select({ id: companyMemberships.id })
1461
+ .from(companyMemberships)
1462
+ .where(and(eq(companyMemberships.companyId, companyId), eq(companyMemberships.principalType, "user"), eq(companyMemberships.principalId, userId), eq(companyMemberships.status, "active")))
1463
+ .then((rows) => rows[0] ?? null);
1464
+ if (!membership) {
1465
+ throw notFound("Assignee user not found");
1466
+ }
1467
+ }
1468
+ async function assertValidProjectWorkspace(companyId, projectId, projectWorkspaceId, dbOrTx = db) {
1469
+ const workspace = await dbOrTx
1470
+ .select({
1471
+ id: projectWorkspaces.id,
1472
+ companyId: projectWorkspaces.companyId,
1473
+ projectId: projectWorkspaces.projectId,
1474
+ })
1475
+ .from(projectWorkspaces)
1476
+ .where(eq(projectWorkspaces.id, projectWorkspaceId))
1477
+ .then((rows) => rows[0] ?? null);
1478
+ if (!workspace)
1479
+ throw notFound("Project workspace not found");
1480
+ if (workspace.companyId !== companyId)
1481
+ throw unprocessable("Project workspace must belong to same company");
1482
+ if (projectId && workspace.projectId !== projectId) {
1483
+ throw unprocessable("Project workspace must belong to the selected project");
1484
+ }
1485
+ }
1486
+ async function assertValidExecutionWorkspace(companyId, projectId, executionWorkspaceId, dbOrTx = db) {
1487
+ const workspace = await dbOrTx
1488
+ .select({
1489
+ id: executionWorkspaces.id,
1490
+ companyId: executionWorkspaces.companyId,
1491
+ projectId: executionWorkspaces.projectId,
1492
+ })
1493
+ .from(executionWorkspaces)
1494
+ .where(eq(executionWorkspaces.id, executionWorkspaceId))
1495
+ .then((rows) => rows[0] ?? null);
1496
+ if (!workspace)
1497
+ throw notFound("Execution workspace not found");
1498
+ if (workspace.companyId !== companyId)
1499
+ throw unprocessable("Execution workspace must belong to same company");
1500
+ if (projectId && workspace.projectId !== projectId) {
1501
+ throw unprocessable("Execution workspace must belong to the selected project");
1502
+ }
1503
+ }
1504
+ async function assertValidLabelIds(companyId, labelIds, dbOrTx = db) {
1505
+ if (labelIds.length === 0)
1506
+ return;
1507
+ const existing = await dbOrTx
1508
+ .select({ id: labels.id })
1509
+ .from(labels)
1510
+ .where(and(eq(labels.companyId, companyId), inArray(labels.id, labelIds)));
1511
+ if (existing.length !== new Set(labelIds).size) {
1512
+ throw unprocessable("One or more labels are invalid for this company");
1513
+ }
1514
+ }
1515
+ async function syncIssueLabels(issueId, companyId, labelIds, dbOrTx = db) {
1516
+ const deduped = [...new Set(labelIds)];
1517
+ await assertValidLabelIds(companyId, deduped, dbOrTx);
1518
+ await dbOrTx.delete(issueLabels).where(eq(issueLabels.issueId, issueId));
1519
+ if (deduped.length === 0)
1520
+ return;
1521
+ await dbOrTx.insert(issueLabels).values(deduped.map((labelId) => ({
1522
+ issueId,
1523
+ labelId,
1524
+ companyId,
1525
+ })));
1526
+ }
1527
+ async function getIssueRelationSummaryMap(companyId, issueIds, dbOrTx = db) {
1528
+ const uniqueIssueIds = [...new Set(issueIds)];
1529
+ const empty = new Map();
1530
+ for (const issueId of uniqueIssueIds) {
1531
+ empty.set(issueId, { blockedBy: [], blocks: [] });
1532
+ }
1533
+ if (uniqueIssueIds.length === 0)
1534
+ return empty;
1535
+ const [blockedByRows, blockingRows] = await Promise.all([
1536
+ dbOrTx
1537
+ .select({
1538
+ currentIssueId: issueRelations.relatedIssueId,
1539
+ relatedId: issues.id,
1540
+ identifier: issues.identifier,
1541
+ title: issues.title,
1542
+ status: issues.status,
1543
+ priority: issues.priority,
1544
+ assigneeAgentId: issues.assigneeAgentId,
1545
+ assigneeUserId: issues.assigneeUserId,
1546
+ })
1547
+ .from(issueRelations)
1548
+ .innerJoin(issues, eq(issueRelations.issueId, issues.id))
1549
+ .where(and(eq(issueRelations.companyId, companyId), eq(issueRelations.type, "blocks"), inArray(issueRelations.relatedIssueId, uniqueIssueIds))),
1550
+ dbOrTx
1551
+ .select({
1552
+ currentIssueId: issueRelations.issueId,
1553
+ relatedId: issues.id,
1554
+ identifier: issues.identifier,
1555
+ title: issues.title,
1556
+ status: issues.status,
1557
+ priority: issues.priority,
1558
+ assigneeAgentId: issues.assigneeAgentId,
1559
+ assigneeUserId: issues.assigneeUserId,
1560
+ })
1561
+ .from(issueRelations)
1562
+ .innerJoin(issues, eq(issueRelations.relatedIssueId, issues.id))
1563
+ .where(and(eq(issueRelations.companyId, companyId), eq(issueRelations.type, "blocks"), inArray(issueRelations.issueId, uniqueIssueIds))),
1564
+ ]);
1565
+ for (const row of blockedByRows) {
1566
+ empty.get(row.currentIssueId)?.blockedBy.push(summarizeIssueRelationRow(row));
1567
+ }
1568
+ for (const row of blockingRows) {
1569
+ empty.get(row.currentIssueId)?.blocks.push(summarizeIssueRelationRow(row));
1570
+ }
1571
+ const terminalByRoot = await terminalExplicitBlockersByRoot(companyId, [...empty.values()].flatMap((relations) => relations.blockedBy), dbOrTx);
1572
+ for (const relations of empty.values()) {
1573
+ relations.blockedBy.sort((a, b) => a.title.localeCompare(b.title));
1574
+ for (const blocker of relations.blockedBy) {
1575
+ const terminalBlockers = terminalByRoot.get(blocker.id);
1576
+ if (terminalBlockers && terminalBlockers.length > 0) {
1577
+ blocker.terminalBlockers = terminalBlockers;
1578
+ }
1579
+ }
1580
+ relations.blocks.sort((a, b) => a.title.localeCompare(b.title));
1581
+ }
1582
+ return empty;
1583
+ }
1584
+ async function assertNoBlockingCycles(companyId, issueId, blockerIssueIds, dbOrTx = db) {
1585
+ if (blockerIssueIds.length === 0)
1586
+ return;
1587
+ const rows = await dbOrTx
1588
+ .select({
1589
+ blockerIssueId: issueRelations.issueId,
1590
+ blockedIssueId: issueRelations.relatedIssueId,
1591
+ })
1592
+ .from(issueRelations)
1593
+ .where(and(eq(issueRelations.companyId, companyId), eq(issueRelations.type, "blocks")));
1594
+ const adjacency = new Map();
1595
+ for (const row of rows) {
1596
+ const list = adjacency.get(row.blockerIssueId) ?? [];
1597
+ list.push(row.blockedIssueId);
1598
+ adjacency.set(row.blockerIssueId, list);
1599
+ }
1600
+ for (const blockerIssueId of blockerIssueIds) {
1601
+ const queue = [...(adjacency.get(issueId) ?? [])];
1602
+ const visited = new Set([issueId]);
1603
+ while (queue.length > 0) {
1604
+ const current = queue.shift();
1605
+ if (current === blockerIssueId) {
1606
+ throw unprocessable("Blocking relations cannot contain cycles");
1607
+ }
1608
+ if (visited.has(current))
1609
+ continue;
1610
+ visited.add(current);
1611
+ queue.push(...(adjacency.get(current) ?? []));
1612
+ }
1613
+ }
1614
+ }
1615
+ async function syncBlockedByIssueIds(issueId, companyId, blockedByIssueIds, actor = {}, dbOrTx = db) {
1616
+ const deduped = [...new Set(blockedByIssueIds)];
1617
+ if (deduped.some((candidate) => candidate === issueId)) {
1618
+ throw unprocessable("Issue cannot be blocked by itself");
1619
+ }
1620
+ if (deduped.length > 0) {
1621
+ const lockedIssueIds = [issueId, ...deduped].sort();
1622
+ await dbOrTx.execute(sql `SELECT ${issues.id} FROM ${issues}
1623
+ WHERE ${and(eq(issues.companyId, companyId), inArray(issues.id, lockedIssueIds))}
1624
+ ORDER BY ${issues.id}
1625
+ FOR UPDATE`);
1626
+ const relatedIssues = await dbOrTx
1627
+ .select({ id: issues.id })
1628
+ .from(issues)
1629
+ .where(and(eq(issues.companyId, companyId), inArray(issues.id, deduped)));
1630
+ if (relatedIssues.length !== deduped.length) {
1631
+ throw unprocessable("Blocked-by issues must belong to the same company");
1632
+ }
1633
+ await assertNoBlockingCycles(companyId, issueId, deduped, dbOrTx);
1634
+ }
1635
+ await dbOrTx
1636
+ .delete(issueRelations)
1637
+ .where(and(eq(issueRelations.companyId, companyId), eq(issueRelations.relatedIssueId, issueId), eq(issueRelations.type, "blocks")));
1638
+ if (deduped.length === 0)
1639
+ return;
1640
+ await dbOrTx.insert(issueRelations).values(deduped.map((blockerIssueId) => ({
1641
+ companyId,
1642
+ issueId: blockerIssueId,
1643
+ relatedIssueId: issueId,
1644
+ type: "blocks",
1645
+ createdByAgentId: actor.agentId ?? null,
1646
+ createdByUserId: actor.userId ?? null,
1647
+ })));
1648
+ }
1649
+ async function isTerminalOrMissingHeartbeatRun(runId) {
1650
+ const run = await db
1651
+ .select({ status: heartbeatRuns.status })
1652
+ .from(heartbeatRuns)
1653
+ .where(eq(heartbeatRuns.id, runId))
1654
+ .then((rows) => rows[0] ?? null);
1655
+ if (!run)
1656
+ return true;
1657
+ return TERMINAL_HEARTBEAT_RUN_STATUSES.has(run.status);
1658
+ }
1659
+ async function adoptStaleCheckoutRun(input) {
1660
+ const stale = await isTerminalOrMissingHeartbeatRun(input.expectedCheckoutRunId);
1661
+ if (!stale)
1662
+ return null;
1663
+ const now = new Date();
1664
+ const adopted = await db
1665
+ .update(issues)
1666
+ .set({
1667
+ checkoutRunId: input.actorRunId,
1668
+ executionRunId: input.actorRunId,
1669
+ executionLockedAt: now,
1670
+ updatedAt: now,
1671
+ })
1672
+ .where(and(eq(issues.id, input.issueId), eq(issues.status, "in_progress"), eq(issues.assigneeAgentId, input.actorAgentId), eq(issues.checkoutRunId, input.expectedCheckoutRunId)))
1673
+ .returning({
1674
+ id: issues.id,
1675
+ status: issues.status,
1676
+ assigneeAgentId: issues.assigneeAgentId,
1677
+ checkoutRunId: issues.checkoutRunId,
1678
+ executionRunId: issues.executionRunId,
1679
+ })
1680
+ .then((rows) => rows[0] ?? null);
1681
+ return adopted;
1682
+ }
1683
+ async function adoptUnownedCheckoutRun(input) {
1684
+ const now = new Date();
1685
+ const adopted = await db
1686
+ .update(issues)
1687
+ .set({
1688
+ checkoutRunId: input.actorRunId,
1689
+ executionRunId: input.actorRunId,
1690
+ executionLockedAt: now,
1691
+ updatedAt: now,
1692
+ })
1693
+ .where(and(eq(issues.id, input.issueId), eq(issues.status, "in_progress"), eq(issues.assigneeAgentId, input.actorAgentId), isNull(issues.checkoutRunId), or(isNull(issues.executionRunId), eq(issues.executionRunId, input.actorRunId))))
1694
+ .returning({
1695
+ id: issues.id,
1696
+ status: issues.status,
1697
+ assigneeAgentId: issues.assigneeAgentId,
1698
+ checkoutRunId: issues.checkoutRunId,
1699
+ executionRunId: issues.executionRunId,
1700
+ })
1701
+ .then((rows) => rows[0] ?? null);
1702
+ return adopted;
1703
+ }
1704
+ async function clearExecutionRunIfTerminal(issueId) {
1705
+ return db.transaction(async (tx) => {
1706
+ await tx.execute(sql `select ${issues.id} from ${issues} where ${issues.id} = ${issueId} for update`);
1707
+ const issue = await tx
1708
+ .select({ executionRunId: issues.executionRunId })
1709
+ .from(issues)
1710
+ .where(eq(issues.id, issueId))
1711
+ .then((rows) => rows[0] ?? null);
1712
+ if (!issue?.executionRunId)
1713
+ return false;
1714
+ await tx.execute(sql `select ${heartbeatRuns.id} from ${heartbeatRuns} where ${heartbeatRuns.id} = ${issue.executionRunId} for update`);
1715
+ const run = await tx
1716
+ .select({ status: heartbeatRuns.status })
1717
+ .from(heartbeatRuns)
1718
+ .where(eq(heartbeatRuns.id, issue.executionRunId))
1719
+ .then((rows) => rows[0] ?? null);
1720
+ if (run && !TERMINAL_HEARTBEAT_RUN_STATUSES.has(run.status))
1721
+ return false;
1722
+ const updated = await tx
1723
+ .update(issues)
1724
+ .set({
1725
+ executionRunId: null,
1726
+ executionAgentNameKey: null,
1727
+ executionLockedAt: null,
1728
+ updatedAt: new Date(),
1729
+ })
1730
+ .where(and(eq(issues.id, issueId), eq(issues.executionRunId, issue.executionRunId)))
1731
+ .returning({ id: issues.id })
1732
+ .then((rows) => rows[0] ?? null);
1733
+ return Boolean(updated);
1734
+ });
1735
+ }
1736
+ return {
1737
+ clearExecutionRunIfTerminal,
1738
+ list: async (companyId, filters) => {
1739
+ const conditions = [eq(issues.companyId, companyId)];
1740
+ const limit = typeof filters?.limit === "number" && Number.isFinite(filters.limit)
1741
+ ? Math.max(1, Math.floor(filters.limit))
1742
+ : undefined;
1743
+ const offset = typeof filters?.offset === "number" && Number.isFinite(filters.offset)
1744
+ ? Math.max(0, Math.floor(filters.offset))
1745
+ : 0;
1746
+ const touchedByUserId = filters?.touchedByUserId?.trim() || undefined;
1747
+ const inboxArchivedByUserId = filters?.inboxArchivedByUserId?.trim() || undefined;
1748
+ const unreadForUserId = filters?.unreadForUserId?.trim() || undefined;
1749
+ const contextUserId = unreadForUserId ?? touchedByUserId ?? inboxArchivedByUserId;
1750
+ const includeBlockedBy = filters?.includeBlockedBy === true;
1751
+ const rawSearch = filters?.q?.trim() ?? "";
1752
+ const hasSearch = rawSearch.length > 0;
1753
+ const escapedSearch = hasSearch ? escapeLikePattern(rawSearch) : "";
1754
+ const startsWithPattern = `${escapedSearch}%`;
1755
+ const containsPattern = `%${escapedSearch}%`;
1756
+ const titleStartsWithMatch = sql `${issues.title} ILIKE ${startsWithPattern} ESCAPE '\\'`;
1757
+ const titleContainsMatch = sql `${issues.title} ILIKE ${containsPattern} ESCAPE '\\'`;
1758
+ const identifierStartsWithMatch = sql `${issues.identifier} ILIKE ${startsWithPattern} ESCAPE '\\'`;
1759
+ const identifierContainsMatch = sql `${issues.identifier} ILIKE ${containsPattern} ESCAPE '\\'`;
1760
+ const descriptionContainsMatch = sql `${issues.description} ILIKE ${containsPattern} ESCAPE '\\'`;
1761
+ const commentContainsMatch = sql `
1762
+ EXISTS (
1763
+ SELECT 1
1764
+ FROM ${issueComments}
1765
+ WHERE ${issueComments.issueId} = ${issues.id}
1766
+ AND ${issueComments.companyId} = ${companyId}
1767
+ AND ${issueComments.body} ILIKE ${containsPattern} ESCAPE '\\'
1768
+ )
1769
+ `;
1770
+ if (filters?.descendantOf) {
1771
+ conditions.push(sql `
1772
+ ${issues.id} IN (
1773
+ WITH RECURSIVE descendants(id) AS (
1774
+ SELECT ${issues.id}
1775
+ FROM ${issues}
1776
+ WHERE ${issues.companyId} = ${companyId}
1777
+ AND ${issues.parentId} = ${filters.descendantOf}
1778
+ UNION
1779
+ SELECT ${issues.id}
1780
+ FROM ${issues}
1781
+ JOIN descendants ON ${issues.parentId} = descendants.id
1782
+ WHERE ${issues.companyId} = ${companyId}
1783
+ )
1784
+ SELECT id FROM descendants
1785
+ )
1786
+ `);
1787
+ }
1788
+ if (filters?.status) {
1789
+ const statuses = filters.status.split(",").map((s) => s.trim());
1790
+ conditions.push(statuses.length === 1 ? eq(issues.status, statuses[0]) : inArray(issues.status, statuses));
1791
+ }
1792
+ if (filters?.assigneeAgentId) {
1793
+ conditions.push(eq(issues.assigneeAgentId, filters.assigneeAgentId));
1794
+ }
1795
+ if (filters?.participantAgentId) {
1796
+ conditions.push(participatedByAgentCondition(companyId, filters.participantAgentId));
1797
+ }
1798
+ if (filters?.assigneeUserId) {
1799
+ conditions.push(eq(issues.assigneeUserId, filters.assigneeUserId));
1800
+ }
1801
+ if (touchedByUserId) {
1802
+ conditions.push(touchedByUserCondition(companyId, touchedByUserId));
1803
+ }
1804
+ if (inboxArchivedByUserId) {
1805
+ conditions.push(inboxVisibleForUserCondition(companyId, inboxArchivedByUserId));
1806
+ }
1807
+ if (unreadForUserId) {
1808
+ conditions.push(unreadForUserCondition(companyId, unreadForUserId));
1809
+ }
1810
+ if (filters?.projectId)
1811
+ conditions.push(eq(issues.projectId, filters.projectId));
1812
+ if (filters?.workspaceId) {
1813
+ conditions.push(or(eq(issues.executionWorkspaceId, filters.workspaceId), eq(issues.projectWorkspaceId, filters.workspaceId)));
1814
+ }
1815
+ if (filters?.executionWorkspaceId) {
1816
+ conditions.push(eq(issues.executionWorkspaceId, filters.executionWorkspaceId));
1817
+ }
1818
+ if (filters?.parentId)
1819
+ conditions.push(eq(issues.parentId, filters.parentId));
1820
+ if (filters?.originKind)
1821
+ conditions.push(eq(issues.originKind, filters.originKind));
1822
+ if (filters?.originKindPrefix)
1823
+ conditions.push(like(issues.originKind, `${filters.originKindPrefix}%`));
1824
+ if (filters?.originId)
1825
+ conditions.push(eq(issues.originId, filters.originId));
1826
+ if (!shouldIncludePluginOperationIssues(filters)) {
1827
+ conditions.push(nonPluginOperationIssueCondition());
1828
+ }
1829
+ if (filters?.labelId) {
1830
+ const labeledIssueIds = await db
1831
+ .select({ issueId: issueLabels.issueId })
1832
+ .from(issueLabels)
1833
+ .where(and(eq(issueLabels.companyId, companyId), eq(issueLabels.labelId, filters.labelId)));
1834
+ if (labeledIssueIds.length === 0)
1835
+ return [];
1836
+ conditions.push(inArray(issues.id, labeledIssueIds.map((row) => row.issueId)));
1837
+ }
1838
+ if (hasSearch) {
1839
+ conditions.push(or(titleContainsMatch, identifierContainsMatch, descriptionContainsMatch, commentContainsMatch));
1840
+ }
1841
+ if (filters?.excludeRoutineExecutions && !filters?.originKind && !filters?.originId) {
1842
+ conditions.push(ne(issues.originKind, "routine_execution"));
1843
+ }
1844
+ conditions.push(isNull(issues.hiddenAt));
1845
+ const priorityOrder = sql `CASE ${issues.priority} WHEN 'critical' THEN 0 WHEN 'high' THEN 1 WHEN 'medium' THEN 2 WHEN 'low' THEN 3 ELSE 4 END`;
1846
+ const searchOrder = sql `
1847
+ CASE
1848
+ WHEN ${titleStartsWithMatch} THEN 0
1849
+ WHEN ${titleContainsMatch} THEN 1
1850
+ WHEN ${identifierStartsWithMatch} THEN 2
1851
+ WHEN ${identifierContainsMatch} THEN 3
1852
+ WHEN ${commentContainsMatch} THEN 4
1853
+ WHEN ${descriptionContainsMatch} THEN 5
1854
+ ELSE 6
1855
+ END
1856
+ `;
1857
+ const canonicalLastActivityAt = issueCanonicalLastActivityAtExpr(companyId);
1858
+ const baseQuery = db
1859
+ .select(issueListSelect)
1860
+ .from(issues)
1861
+ .where(and(...conditions))
1862
+ .orderBy(hasSearch ? asc(searchOrder) : asc(priorityOrder), asc(priorityOrder), desc(canonicalLastActivityAt), desc(issues.updatedAt), desc(issues.id));
1863
+ const pageQuery = offset > 0
1864
+ ? (limit === undefined ? baseQuery.offset(offset) : baseQuery.limit(limit).offset(offset))
1865
+ : (limit === undefined ? baseQuery : baseQuery.limit(limit));
1866
+ const rows = (await pageQuery).map((row) => ({
1867
+ ...row,
1868
+ description: decodeDatabaseTextPreview(row.description, ISSUE_LIST_DESCRIPTION_MAX_CHARS),
1869
+ }));
1870
+ const withLabels = await withIssueLabels(db, rows);
1871
+ const runMap = await activeRunMapForIssues(db, withLabels);
1872
+ const withRuns = withActiveRuns(withLabels, runMap);
1873
+ if (withRuns.length === 0) {
1874
+ return withRuns;
1875
+ }
1876
+ const issueIds = withRuns.map((row) => row.id);
1877
+ const [statsRows, readRows, lastActivityRows, blockedByMap] = await Promise.all([
1878
+ contextUserId
1879
+ ? userCommentStatsForIssues(db, companyId, contextUserId, issueIds)
1880
+ : Promise.resolve([]),
1881
+ contextUserId
1882
+ ? userReadStatsForIssues(db, companyId, contextUserId, issueIds)
1883
+ : Promise.resolve([]),
1884
+ lastActivityStatsForIssues(db, companyId, issueIds),
1885
+ includeBlockedBy
1886
+ ? blockedByMapForIssues(db, companyId, issueIds)
1887
+ : Promise.resolve(new Map()),
1888
+ ]);
1889
+ const statsByIssueId = new Map(statsRows.map((row) => [row.issueId, row]));
1890
+ const lastActivityByIssueId = new Map(lastActivityRows.map((row) => [row.issueId, row]));
1891
+ const [blockerAttentionByIssueId, productivityReviewByIssueId] = await Promise.all([
1892
+ listIssueBlockerAttentionMap(db, companyId, withRuns),
1893
+ listIssueProductivityReviewMap(db, companyId, issueIds),
1894
+ ]);
1895
+ if (!contextUserId) {
1896
+ return withRuns.map((row) => {
1897
+ const activity = lastActivityByIssueId.get(row.id);
1898
+ const lastActivityAt = latestIssueActivityAt(row.updatedAt, activity?.latestCommentAt ?? null, activity?.latestLogAt ?? null) ?? row.updatedAt;
1899
+ return {
1900
+ ...row,
1901
+ ...(includeBlockedBy ? { blockedBy: blockedByMap.get(row.id) ?? [] } : {}),
1902
+ lastActivityAt,
1903
+ ...(blockerAttentionByIssueId.has(row.id) ? { blockerAttention: blockerAttentionByIssueId.get(row.id) } : {}),
1904
+ ...(productivityReviewByIssueId.has(row.id)
1905
+ ? { productivityReview: productivityReviewByIssueId.get(row.id) }
1906
+ : {}),
1907
+ };
1908
+ });
1909
+ }
1910
+ const readByIssueId = new Map(readRows.map((row) => [row.issueId, row.myLastReadAt]));
1911
+ return withRuns.map((row) => {
1912
+ const activity = lastActivityByIssueId.get(row.id);
1913
+ const lastActivityAt = latestIssueActivityAt(row.updatedAt, activity?.latestCommentAt ?? null, activity?.latestLogAt ?? null) ?? row.updatedAt;
1914
+ return {
1915
+ ...row,
1916
+ ...(includeBlockedBy ? { blockedBy: blockedByMap.get(row.id) ?? [] } : {}),
1917
+ lastActivityAt,
1918
+ ...(blockerAttentionByIssueId.has(row.id) ? { blockerAttention: blockerAttentionByIssueId.get(row.id) } : {}),
1919
+ ...(productivityReviewByIssueId.has(row.id)
1920
+ ? { productivityReview: productivityReviewByIssueId.get(row.id) }
1921
+ : {}),
1922
+ ...deriveIssueUserContext(row, contextUserId, {
1923
+ myLastCommentAt: statsByIssueId.get(row.id)?.myLastCommentAt ?? null,
1924
+ myLastReadAt: readByIssueId.get(row.id) ?? null,
1925
+ lastExternalCommentAt: statsByIssueId.get(row.id)?.lastExternalCommentAt ?? null,
1926
+ }),
1927
+ };
1928
+ });
1929
+ },
1930
+ countUnreadTouchedByUser: async (companyId, userId, status) => {
1931
+ const conditions = [
1932
+ eq(issues.companyId, companyId),
1933
+ isNull(issues.hiddenAt),
1934
+ nonPluginOperationIssueCondition(),
1935
+ unreadForUserCondition(companyId, userId),
1936
+ ];
1937
+ if (status) {
1938
+ const statuses = status.split(",").map((s) => s.trim()).filter(Boolean);
1939
+ if (statuses.length === 1) {
1940
+ conditions.push(eq(issues.status, statuses[0]));
1941
+ }
1942
+ else if (statuses.length > 1) {
1943
+ conditions.push(inArray(issues.status, statuses));
1944
+ }
1945
+ }
1946
+ const [row] = await db
1947
+ .select({ count: sql `count(*)` })
1948
+ .from(issues)
1949
+ .where(and(...conditions));
1950
+ return Number(row?.count ?? 0);
1951
+ },
1952
+ markRead: async (companyId, issueId, userId, readAt = new Date()) => {
1953
+ const now = new Date();
1954
+ const [row] = await db
1955
+ .insert(issueReadStates)
1956
+ .values({
1957
+ companyId,
1958
+ issueId,
1959
+ userId,
1960
+ lastReadAt: readAt,
1961
+ updatedAt: now,
1962
+ })
1963
+ .onConflictDoUpdate({
1964
+ target: [issueReadStates.companyId, issueReadStates.issueId, issueReadStates.userId],
1965
+ set: {
1966
+ lastReadAt: readAt,
1967
+ updatedAt: now,
1968
+ },
1969
+ })
1970
+ .returning();
1971
+ return row;
1972
+ },
1973
+ markUnread: async (companyId, issueId, userId) => {
1974
+ const deleted = await db
1975
+ .delete(issueReadStates)
1976
+ .where(and(eq(issueReadStates.companyId, companyId), eq(issueReadStates.issueId, issueId), eq(issueReadStates.userId, userId)))
1977
+ .returning();
1978
+ return deleted.length > 0;
1979
+ },
1980
+ archiveInbox: async (companyId, issueId, userId, archivedAt = new Date()) => {
1981
+ const now = new Date();
1982
+ const [row] = await db
1983
+ .insert(issueInboxArchives)
1984
+ .values({
1985
+ companyId,
1986
+ issueId,
1987
+ userId,
1988
+ archivedAt,
1989
+ updatedAt: now,
1990
+ })
1991
+ .onConflictDoUpdate({
1992
+ target: [issueInboxArchives.companyId, issueInboxArchives.issueId, issueInboxArchives.userId],
1993
+ set: {
1994
+ archivedAt,
1995
+ updatedAt: now,
1996
+ },
1997
+ })
1998
+ .returning();
1999
+ return row;
2000
+ },
2001
+ unarchiveInbox: async (companyId, issueId, userId) => {
2002
+ const [row] = await db
2003
+ .delete(issueInboxArchives)
2004
+ .where(and(eq(issueInboxArchives.companyId, companyId), eq(issueInboxArchives.issueId, issueId), eq(issueInboxArchives.userId, userId)))
2005
+ .returning();
2006
+ return row ?? null;
2007
+ },
2008
+ getById: async (raw) => {
2009
+ const id = raw.trim();
2010
+ const identifier = normalizeIssueReferenceIdentifier(id);
2011
+ if (identifier) {
2012
+ return getIssueByIdentifier(identifier);
2013
+ }
2014
+ if (!isUuidLike(id)) {
2015
+ return null;
2016
+ }
2017
+ return getIssueByUuid(id);
2018
+ },
2019
+ getByIdentifier: async (identifier) => {
2020
+ return getIssueByIdentifier(identifier);
2021
+ },
2022
+ getCurrentScheduledRetry: async (issueId) => {
2023
+ const issue = await db
2024
+ .select({ id: issues.id, companyId: issues.companyId })
2025
+ .from(issues)
2026
+ .where(eq(issues.id, issueId))
2027
+ .then((rows) => rows[0] ?? null);
2028
+ if (!issue)
2029
+ throw notFound("Issue not found");
2030
+ return getCurrentScheduledRetryForIssue(issue.id, issue.companyId);
2031
+ },
2032
+ getRelationSummaries: async (issueId) => {
2033
+ const issue = await db
2034
+ .select({ id: issues.id, companyId: issues.companyId })
2035
+ .from(issues)
2036
+ .where(eq(issues.id, issueId))
2037
+ .then((rows) => rows[0] ?? null);
2038
+ if (!issue)
2039
+ throw notFound("Issue not found");
2040
+ const relations = await getIssueRelationSummaryMap(issue.companyId, [issueId], db);
2041
+ return relations.get(issueId) ?? { blockedBy: [], blocks: [] };
2042
+ },
2043
+ getDependencyReadiness: async (issueId, dbOrTx = db) => {
2044
+ const issue = await dbOrTx
2045
+ .select({ id: issues.id, companyId: issues.companyId })
2046
+ .from(issues)
2047
+ .where(eq(issues.id, issueId))
2048
+ .then((rows) => rows[0] ?? null);
2049
+ if (!issue)
2050
+ throw notFound("Issue not found");
2051
+ const readiness = await listIssueDependencyReadinessMap(dbOrTx, issue.companyId, [issueId]);
2052
+ return readiness.get(issueId) ?? createIssueDependencyReadiness(issueId);
2053
+ },
2054
+ listDependencyReadiness: async (companyId, issueIds, dbOrTx = db) => {
2055
+ return listIssueDependencyReadinessMap(dbOrTx, companyId, issueIds);
2056
+ },
2057
+ listBlockerAttention: async (companyId, issueRows, dbOrTx = db) => {
2058
+ return listIssueBlockerAttentionMap(dbOrTx, companyId, issueRows);
2059
+ },
2060
+ listProductivityReviews: async (companyId, sourceIssueIds, dbOrTx = db) => {
2061
+ return listIssueProductivityReviewMap(dbOrTx, companyId, sourceIssueIds);
2062
+ },
2063
+ listWakeableBlockedDependents: async (blockerIssueId) => {
2064
+ const blockerIssue = await db
2065
+ .select({ id: issues.id, companyId: issues.companyId })
2066
+ .from(issues)
2067
+ .where(eq(issues.id, blockerIssueId))
2068
+ .then((rows) => rows[0] ?? null);
2069
+ if (!blockerIssue)
2070
+ return [];
2071
+ const candidates = await db
2072
+ .select({
2073
+ id: issues.id,
2074
+ assigneeAgentId: issues.assigneeAgentId,
2075
+ status: issues.status,
2076
+ })
2077
+ .from(issueRelations)
2078
+ .innerJoin(issues, eq(issueRelations.relatedIssueId, issues.id))
2079
+ .where(and(eq(issueRelations.companyId, blockerIssue.companyId), eq(issueRelations.type, "blocks"), eq(issueRelations.issueId, blockerIssueId)));
2080
+ if (candidates.length === 0)
2081
+ return [];
2082
+ const candidateIds = candidates.map((candidate) => candidate.id);
2083
+ const blockerRows = await db
2084
+ .select({
2085
+ issueId: issueRelations.relatedIssueId,
2086
+ blockerIssueId: issueRelations.issueId,
2087
+ blockerStatus: issues.status,
2088
+ })
2089
+ .from(issueRelations)
2090
+ .innerJoin(issues, eq(issueRelations.issueId, issues.id))
2091
+ .where(and(eq(issueRelations.companyId, blockerIssue.companyId), eq(issueRelations.type, "blocks"), inArray(issueRelations.relatedIssueId, candidateIds)));
2092
+ const blockersByIssueId = new Map();
2093
+ for (const row of blockerRows) {
2094
+ const list = blockersByIssueId.get(row.issueId) ?? [];
2095
+ list.push({ blockerIssueId: row.blockerIssueId, blockerStatus: row.blockerStatus });
2096
+ blockersByIssueId.set(row.issueId, list);
2097
+ }
2098
+ return candidates
2099
+ .filter((candidate) => candidate.assigneeAgentId && !["backlog", "done", "cancelled"].includes(candidate.status))
2100
+ .map((candidate) => {
2101
+ const blockers = blockersByIssueId.get(candidate.id) ?? [];
2102
+ return {
2103
+ ...candidate,
2104
+ blockerIssueIds: blockers.map((blocker) => blocker.blockerIssueId),
2105
+ allBlockersDone: blockers.length > 0 && blockers.every((blocker) => blocker.blockerStatus === "done"),
2106
+ };
2107
+ })
2108
+ .filter((candidate) => candidate.allBlockersDone)
2109
+ .map((candidate) => ({
2110
+ id: candidate.id,
2111
+ assigneeAgentId: candidate.assigneeAgentId,
2112
+ blockerIssueIds: candidate.blockerIssueIds,
2113
+ }));
2114
+ },
2115
+ getWakeableParentAfterChildCompletion: async (parentIssueId) => {
2116
+ const parent = await db
2117
+ .select({
2118
+ id: issues.id,
2119
+ assigneeAgentId: issues.assigneeAgentId,
2120
+ status: issues.status,
2121
+ companyId: issues.companyId,
2122
+ })
2123
+ .from(issues)
2124
+ .where(eq(issues.id, parentIssueId))
2125
+ .then((rows) => rows[0] ?? null);
2126
+ if (!parent || !parent.assigneeAgentId || ["backlog", "done", "cancelled"].includes(parent.status)) {
2127
+ return null;
2128
+ }
2129
+ const children = await db
2130
+ .select({
2131
+ id: issues.id,
2132
+ identifier: issues.identifier,
2133
+ title: issues.title,
2134
+ status: issues.status,
2135
+ priority: issues.priority,
2136
+ assigneeAgentId: issues.assigneeAgentId,
2137
+ assigneeUserId: issues.assigneeUserId,
2138
+ updatedAt: issues.updatedAt,
2139
+ })
2140
+ .from(issues)
2141
+ .where(and(eq(issues.companyId, parent.companyId), eq(issues.parentId, parentIssueId)))
2142
+ .orderBy(asc(issues.issueNumber), asc(issues.createdAt));
2143
+ if (children.length === 0)
2144
+ return null;
2145
+ if (!children.every((child) => child.status === "done" || child.status === "cancelled")) {
2146
+ return null;
2147
+ }
2148
+ const childIdsForSummaries = children.slice(0, MAX_CHILD_COMPLETION_SUMMARIES).map((child) => child.id);
2149
+ const commentRows = childIdsForSummaries.length > 0
2150
+ ? await db
2151
+ .select({
2152
+ issueId: issueComments.issueId,
2153
+ body: issueComments.body,
2154
+ createdAt: issueComments.createdAt,
2155
+ })
2156
+ .from(issueComments)
2157
+ .where(and(eq(issueComments.companyId, parent.companyId), inArray(issueComments.issueId, childIdsForSummaries)))
2158
+ .orderBy(desc(issueComments.createdAt), desc(issueComments.id))
2159
+ : [];
2160
+ const latestCommentByIssueId = new Map();
2161
+ for (const comment of commentRows) {
2162
+ if (!latestCommentByIssueId.has(comment.issueId)) {
2163
+ latestCommentByIssueId.set(comment.issueId, comment.body);
2164
+ }
2165
+ }
2166
+ const childIssueSummaries = children
2167
+ .slice(0, MAX_CHILD_COMPLETION_SUMMARIES)
2168
+ .map((child) => ({
2169
+ ...child,
2170
+ summary: truncateInlineSummary(latestCommentByIssueId.get(child.id)),
2171
+ }));
2172
+ return {
2173
+ id: parent.id,
2174
+ assigneeAgentId: parent.assigneeAgentId,
2175
+ childIssueIds: children.map((child) => child.id),
2176
+ childIssueSummaries,
2177
+ childIssueSummaryTruncated: children.length > childIssueSummaries.length,
2178
+ };
2179
+ },
2180
+ createChild: async (parentIssueId, data) => {
2181
+ const parent = await db
2182
+ .select()
2183
+ .from(issues)
2184
+ .where(eq(issues.id, parentIssueId))
2185
+ .then((rows) => rows[0] ?? null);
2186
+ if (!parent)
2187
+ throw notFound("Parent issue not found");
2188
+ const [{ childCount }] = await db
2189
+ .select({ childCount: sql `count(*)::int` })
2190
+ .from(issues)
2191
+ .where(and(eq(issues.companyId, parent.companyId), eq(issues.parentId, parent.id)));
2192
+ if (childCount >= MAX_CHILD_ISSUES_CREATED_BY_HELPER) {
2193
+ throw unprocessable(`Parent issue already has the maximum ${MAX_CHILD_ISSUES_CREATED_BY_HELPER} child issues for this helper`);
2194
+ }
2195
+ const { acceptanceCriteria, blockParentUntilDone, actorAgentId, actorUserId, ...issueData } = data;
2196
+ const child = await issueService(db).create(parent.companyId, {
2197
+ ...issueData,
2198
+ parentId: parent.id,
2199
+ projectId: issueData.projectId ?? parent.projectId,
2200
+ goalId: issueData.goalId ?? parent.goalId,
2201
+ requestDepth: clampIssueRequestDepth(Math.max(clampIssueRequestDepth(parent.requestDepth) + 1, issueData.requestDepth ?? 0)),
2202
+ description: appendAcceptanceCriteriaToDescription(issueData.description, acceptanceCriteria),
2203
+ inheritExecutionWorkspaceFromIssueId: parent.id,
2204
+ });
2205
+ if (blockParentUntilDone) {
2206
+ const existingBlockers = await db
2207
+ .select({ blockerIssueId: issueRelations.issueId })
2208
+ .from(issueRelations)
2209
+ .where(and(eq(issueRelations.companyId, parent.companyId), eq(issueRelations.relatedIssueId, parent.id), eq(issueRelations.type, "blocks")));
2210
+ await syncBlockedByIssueIds(parent.id, parent.companyId, [...new Set([...existingBlockers.map((row) => row.blockerIssueId), child.id])], { agentId: actorAgentId ?? null, userId: actorUserId ?? null });
2211
+ }
2212
+ return {
2213
+ issue: child,
2214
+ parentBlockerAdded: Boolean(blockParentUntilDone),
2215
+ };
2216
+ },
2217
+ create: async (companyId, data) => {
2218
+ const { labelIds: inputLabelIds, blockedByIssueIds, inheritExecutionWorkspaceFromIssueId, ...issueData } = data;
2219
+ const isolatedWorkspacesEnabled = (await instanceSettings.getExperimental()).enableIsolatedWorkspaces;
2220
+ if (!isolatedWorkspacesEnabled) {
2221
+ delete issueData.executionWorkspaceId;
2222
+ delete issueData.executionWorkspacePreference;
2223
+ delete issueData.executionWorkspaceSettings;
2224
+ }
2225
+ if (data.assigneeAgentId && data.assigneeUserId) {
2226
+ throw unprocessable("Issue can only have one assignee");
2227
+ }
2228
+ if (data.assigneeAgentId) {
2229
+ await assertAssignableAgent(companyId, data.assigneeAgentId);
2230
+ }
2231
+ if (data.assigneeUserId) {
2232
+ await assertAssignableUser(companyId, data.assigneeUserId);
2233
+ }
2234
+ if (data.status === "in_progress" && !data.assigneeAgentId && !data.assigneeUserId) {
2235
+ throw unprocessable("in_progress issues require an assignee");
2236
+ }
2237
+ return db.transaction(async (tx) => {
2238
+ const projectGoalId = null;
2239
+ let projectWorkspaceId = issueData.projectWorkspaceId ?? null;
2240
+ let executionWorkspaceId = issueData.executionWorkspaceId ?? null;
2241
+ let executionWorkspacePreference = issueData.executionWorkspacePreference ?? null;
2242
+ let executionWorkspaceSettings = issueData.executionWorkspaceSettings ?? null;
2243
+ const workspaceInheritanceIssueId = inheritExecutionWorkspaceFromIssueId ?? issueData.parentId ?? null;
2244
+ const hasExplicitExecutionWorkspaceOverride = issueData.executionWorkspaceId !== undefined ||
2245
+ issueData.executionWorkspacePreference !== undefined ||
2246
+ issueData.executionWorkspaceSettings !== undefined;
2247
+ if (workspaceInheritanceIssueId) {
2248
+ const workspaceSource = await getWorkspaceInheritanceIssue(tx, companyId, workspaceInheritanceIssueId);
2249
+ if (projectWorkspaceId == null && workspaceSource.projectWorkspaceId) {
2250
+ projectWorkspaceId = workspaceSource.projectWorkspaceId;
2251
+ }
2252
+ if (isolatedWorkspacesEnabled &&
2253
+ !hasExplicitExecutionWorkspaceOverride &&
2254
+ workspaceSource.executionWorkspaceId) {
2255
+ const sourceWorkspace = await tx
2256
+ .select({
2257
+ id: executionWorkspaces.id,
2258
+ mode: executionWorkspaces.mode,
2259
+ })
2260
+ .from(executionWorkspaces)
2261
+ .where(eq(executionWorkspaces.id, workspaceSource.executionWorkspaceId))
2262
+ .then((rows) => rows[0] ?? null);
2263
+ if (sourceWorkspace) {
2264
+ executionWorkspaceId = sourceWorkspace.id;
2265
+ executionWorkspacePreference = "reuse_existing";
2266
+ executionWorkspaceSettings = {
2267
+ ...(workspaceSource.executionWorkspaceSettings ?? {}),
2268
+ mode: issueExecutionWorkspaceModeForPersistedWorkspace(sourceWorkspace.mode),
2269
+ };
2270
+ }
2271
+ }
2272
+ }
2273
+ // Cache the project policy lookup for this insert. Both the
2274
+ // default-settings block and the assignee-environment-promotion block
2275
+ // need the same row; without caching they'd issue two round-trips.
2276
+ let projectPolicyCached = null;
2277
+ let projectPolicyLoaded = false;
2278
+ const loadProjectPolicyOnce = async () => {
2279
+ if (projectPolicyLoaded)
2280
+ return projectPolicyCached;
2281
+ projectPolicyLoaded = true;
2282
+ if (!issueData.projectId)
2283
+ return null;
2284
+ const projectRow = await tx
2285
+ .select({ executionWorkspacePolicy: projects.executionWorkspacePolicy })
2286
+ .from(projects)
2287
+ .where(and(eq(projects.id, issueData.projectId), eq(projects.companyId, companyId)))
2288
+ .then((rows) => rows[0] ?? null);
2289
+ projectPolicyCached = parseProjectExecutionWorkspacePolicy(projectRow?.executionWorkspacePolicy);
2290
+ return projectPolicyCached;
2291
+ };
2292
+ if (executionWorkspaceSettings == null &&
2293
+ executionWorkspaceId == null &&
2294
+ issueData.projectId) {
2295
+ executionWorkspaceSettings =
2296
+ defaultIssueExecutionWorkspaceSettingsForProject(gateProjectExecutionWorkspacePolicy(await loadProjectPolicyOnce(), isolatedWorkspacesEnabled));
2297
+ }
2298
+ if (data.assigneeAgentId && isolatedWorkspacesEnabled) {
2299
+ const currentWorkspaceSettings = executionWorkspaceSettings == null
2300
+ ? {}
2301
+ : parseObject(executionWorkspaceSettings);
2302
+ const issueHasEnvironmentSelection = Object.prototype.hasOwnProperty.call(currentWorkspaceSettings, "environmentId");
2303
+ // Don't promote the assignee agent's defaultEnvironmentId if either
2304
+ // the issue or the project policy already specifies an environment.
2305
+ // resolveExecutionWorkspaceEnvironmentId treats issue settings as
2306
+ // higher priority than project policy, so promoting the agent's
2307
+ // default to issue settings would invert the documented priority
2308
+ // (project policy must win over agent default when explicitly set).
2309
+ let projectHasEnvironmentSelection = false;
2310
+ if (!issueHasEnvironmentSelection && issueData.projectId) {
2311
+ const projectPolicy = await loadProjectPolicyOnce();
2312
+ projectHasEnvironmentSelection = projectPolicy?.environmentId !== undefined;
2313
+ }
2314
+ if (!issueHasEnvironmentSelection && !projectHasEnvironmentSelection) {
2315
+ const assigneeAgent = await tx
2316
+ .select({ defaultEnvironmentId: agents.defaultEnvironmentId })
2317
+ .from(agents)
2318
+ .where(and(eq(agents.id, data.assigneeAgentId), eq(agents.companyId, companyId)))
2319
+ .then((rows) => rows[0] ?? null);
2320
+ if (typeof assigneeAgent?.defaultEnvironmentId === "string" && assigneeAgent.defaultEnvironmentId.length > 0) {
2321
+ executionWorkspaceSettings = {
2322
+ ...currentWorkspaceSettings,
2323
+ environmentId: assigneeAgent.defaultEnvironmentId,
2324
+ };
2325
+ }
2326
+ }
2327
+ }
2328
+ if (!projectWorkspaceId && issueData.projectId) {
2329
+ const project = await tx
2330
+ .select({
2331
+ executionWorkspacePolicy: projects.executionWorkspacePolicy,
2332
+ })
2333
+ .from(projects)
2334
+ .where(and(eq(projects.id, issueData.projectId), eq(projects.companyId, companyId)))
2335
+ .then((rows) => rows[0] ?? null);
2336
+ const projectPolicy = parseProjectExecutionWorkspacePolicy(project?.executionWorkspacePolicy);
2337
+ projectWorkspaceId = projectPolicy?.defaultProjectWorkspaceId ?? null;
2338
+ if (!projectWorkspaceId) {
2339
+ projectWorkspaceId = await tx
2340
+ .select({ id: projectWorkspaces.id })
2341
+ .from(projectWorkspaces)
2342
+ .where(and(eq(projectWorkspaces.projectId, issueData.projectId), eq(projectWorkspaces.companyId, companyId)))
2343
+ .orderBy(desc(projectWorkspaces.isPrimary), asc(projectWorkspaces.createdAt), asc(projectWorkspaces.id))
2344
+ .then((rows) => rows[0]?.id ?? null);
2345
+ }
2346
+ }
2347
+ if (projectWorkspaceId) {
2348
+ await assertValidProjectWorkspace(companyId, issueData.projectId, projectWorkspaceId, tx);
2349
+ }
2350
+ if (executionWorkspaceId) {
2351
+ await assertValidExecutionWorkspace(companyId, issueData.projectId, executionWorkspaceId, tx);
2352
+ }
2353
+ // Self-correcting counter: use MAX(issue_number) + 1 if the counter
2354
+ // has drifted below the actual max, preventing identifier collisions.
2355
+ const [maxRow] = await tx
2356
+ .select({ maxNum: sql `coalesce(max(${issues.issueNumber}), 0)` })
2357
+ .from(issues)
2358
+ .where(eq(issues.companyId, companyId));
2359
+ const currentMax = maxRow?.maxNum ?? 0;
2360
+ const [company] = await tx
2361
+ .update(companies)
2362
+ .set({
2363
+ issueCounter: sql `greatest(${companies.issueCounter}, ${currentMax}) + 1`,
2364
+ })
2365
+ .where(eq(companies.id, companyId))
2366
+ .returning({ issueCounter: companies.issueCounter, issuePrefix: companies.issuePrefix });
2367
+ const issueNumber = company.issueCounter;
2368
+ const identifier = `${company.issuePrefix}-${issueNumber}`;
2369
+ const values = {
2370
+ ...issueData,
2371
+ requestDepth: clampIssueRequestDepth(issueData.requestDepth),
2372
+ originKind: issueData.originKind ?? "manual",
2373
+ goalId: resolveIssueGoalId({
2374
+ projectId: issueData.projectId,
2375
+ goalId: issueData.goalId,
2376
+ projectGoalId,
2377
+ defaultGoalId: null,
2378
+ }),
2379
+ ...(projectWorkspaceId ? { projectWorkspaceId } : {}),
2380
+ ...(executionWorkspaceId ? { executionWorkspaceId } : {}),
2381
+ ...(executionWorkspacePreference ? { executionWorkspacePreference } : {}),
2382
+ ...(executionWorkspaceSettings ? { executionWorkspaceSettings } : {}),
2383
+ companyId,
2384
+ issueNumber,
2385
+ identifier,
2386
+ };
2387
+ if (values.status === "in_progress" && !values.startedAt) {
2388
+ values.startedAt = new Date();
2389
+ }
2390
+ if (values.status === "done") {
2391
+ values.completedAt = new Date();
2392
+ }
2393
+ if (values.status === "cancelled") {
2394
+ values.cancelledAt = new Date();
2395
+ }
2396
+ Object.assign(values, buildInitialIssueMonitorFields({
2397
+ policy: normalizeIssueExecutionPolicy(issueData.executionPolicy ?? null),
2398
+ status: values.status ?? "backlog",
2399
+ assigneeAgentId: values.assigneeAgentId ?? null,
2400
+ assigneeUserId: values.assigneeUserId ?? null,
2401
+ }));
2402
+ const [issue] = await tx.insert(issues).values(values).returning();
2403
+ if (inputLabelIds) {
2404
+ await syncIssueLabels(issue.id, companyId, inputLabelIds, tx);
2405
+ }
2406
+ if (blockedByIssueIds !== undefined) {
2407
+ await syncBlockedByIssueIds(issue.id, companyId, blockedByIssueIds, {
2408
+ agentId: issueData.createdByAgentId ?? null,
2409
+ userId: issueData.createdByUserId ?? null,
2410
+ }, tx);
2411
+ }
2412
+ const [enriched] = await withIssueLabels(tx, [issue]);
2413
+ return enriched;
2414
+ });
2415
+ },
2416
+ update: async (id, data, dbOrTx = db) => {
2417
+ const existing = await dbOrTx
2418
+ .select()
2419
+ .from(issues)
2420
+ .where(eq(issues.id, id))
2421
+ .then((rows) => rows[0] ?? null);
2422
+ if (!existing)
2423
+ return null;
2424
+ const { labelIds: nextLabelIds, blockedByIssueIds, actorAgentId, actorUserId, ...issueData } = data;
2425
+ const isolatedWorkspacesEnabled = (await instanceSettings.getExperimental()).enableIsolatedWorkspaces;
2426
+ if (!isolatedWorkspacesEnabled) {
2427
+ delete issueData.executionWorkspaceId;
2428
+ delete issueData.executionWorkspacePreference;
2429
+ delete issueData.executionWorkspaceSettings;
2430
+ }
2431
+ if (issueData.status) {
2432
+ assertTransition(existing.status, issueData.status);
2433
+ }
2434
+ const patch = {
2435
+ ...issueData,
2436
+ updatedAt: new Date(),
2437
+ };
2438
+ if (issueData.requestDepth !== undefined) {
2439
+ patch.requestDepth = clampIssueRequestDepth(issueData.requestDepth);
2440
+ }
2441
+ const nextAssigneeAgentId = issueData.assigneeAgentId !== undefined ? issueData.assigneeAgentId : existing.assigneeAgentId;
2442
+ const nextAssigneeUserId = issueData.assigneeUserId !== undefined ? issueData.assigneeUserId : existing.assigneeUserId;
2443
+ if (nextAssigneeAgentId && nextAssigneeUserId) {
2444
+ throw unprocessable("Issue can only have one assignee");
2445
+ }
2446
+ if (patch.status === "in_progress" && !nextAssigneeAgentId && !nextAssigneeUserId) {
2447
+ throw unprocessable("in_progress issues require an assignee");
2448
+ }
2449
+ if (patch.status === "in_progress") {
2450
+ const unresolvedBlockerIssueIds = blockedByIssueIds !== undefined
2451
+ ? await listUnresolvedBlockerIssueIds(dbOrTx, existing.companyId, blockedByIssueIds)
2452
+ : (await listIssueDependencyReadinessMap(dbOrTx, existing.companyId, [id])).get(id)?.unresolvedBlockerIssueIds ?? [];
2453
+ if (unresolvedBlockerIssueIds.length > 0) {
2454
+ throw unprocessable("Issue is blocked by unresolved blockers", { unresolvedBlockerIssueIds });
2455
+ }
2456
+ }
2457
+ if (issueData.assigneeAgentId) {
2458
+ await assertAssignableAgent(existing.companyId, issueData.assigneeAgentId);
2459
+ }
2460
+ if (issueData.assigneeUserId) {
2461
+ await assertAssignableUser(existing.companyId, issueData.assigneeUserId);
2462
+ }
2463
+ const nextProjectId = issueData.projectId !== undefined ? issueData.projectId : existing.projectId;
2464
+ const nextProjectWorkspaceId = issueData.projectWorkspaceId !== undefined ? issueData.projectWorkspaceId : existing.projectWorkspaceId;
2465
+ const nextExecutionWorkspaceId = issueData.executionWorkspaceId !== undefined ? issueData.executionWorkspaceId : existing.executionWorkspaceId;
2466
+ const nextExecutionWorkspacePreference = issueData.executionWorkspacePreference !== undefined
2467
+ ? issueData.executionWorkspacePreference
2468
+ : existing.executionWorkspacePreference;
2469
+ const nextExecutionWorkspaceSettings = issueData.executionWorkspaceSettings !== undefined
2470
+ ? parseIssueExecutionWorkspaceSettings(issueData.executionWorkspaceSettings)
2471
+ : parseIssueExecutionWorkspaceSettings(existing.executionWorkspaceSettings);
2472
+ if (nextProjectWorkspaceId) {
2473
+ await assertValidProjectWorkspace(existing.companyId, nextProjectId, nextProjectWorkspaceId);
2474
+ }
2475
+ if (nextExecutionWorkspaceId) {
2476
+ await assertValidExecutionWorkspace(existing.companyId, nextProjectId, nextExecutionWorkspaceId);
2477
+ }
2478
+ applyStatusSideEffects(issueData.status, patch);
2479
+ if (issueData.status && issueData.status !== "done") {
2480
+ patch.completedAt = null;
2481
+ }
2482
+ if (issueData.status && issueData.status !== "cancelled") {
2483
+ patch.cancelledAt = null;
2484
+ }
2485
+ if (issueData.status && issueData.status !== "in_progress") {
2486
+ patch.checkoutRunId = null;
2487
+ // Fix B: also clear the execution lock when leaving in_progress
2488
+ patch.executionRunId = null;
2489
+ patch.executionAgentNameKey = null;
2490
+ patch.executionLockedAt = null;
2491
+ }
2492
+ if ((issueData.assigneeAgentId !== undefined && issueData.assigneeAgentId !== existing.assigneeAgentId) ||
2493
+ (issueData.assigneeUserId !== undefined && issueData.assigneeUserId !== existing.assigneeUserId)) {
2494
+ patch.checkoutRunId = null;
2495
+ // Fix B: clear execution lock on reassignment, matching checkoutRunId clear
2496
+ patch.executionRunId = null;
2497
+ patch.executionAgentNameKey = null;
2498
+ patch.executionLockedAt = null;
2499
+ }
2500
+ const runUpdate = async (tx) => {
2501
+ const currentProjectGoalId = null;
2502
+ const nextProjectGoalId = null;
2503
+ // Mirror the create() path: when the assignee changes to a non-null
2504
+ // agent, default the issue's executionWorkspaceSettings.environmentId
2505
+ // to the new agent's defaultEnvironmentId. Skip when:
2506
+ // - this update explicitly sets executionWorkspaceSettings.environmentId
2507
+ // (caller is making a deliberate override; respect it), OR
2508
+ // - the project policy already specifies an environmentId (project
2509
+ // policy must win over agent default per the documented priority
2510
+ // order in resolveExecutionWorkspaceEnvironmentId), OR
2511
+ // - the issue already has an environmentId that was *not* the prior
2512
+ // assignee's default (i.e., the operator set it explicitly in an
2513
+ // earlier update; preserve their choice). When the existing
2514
+ // environmentId matches the prior assignee's default, treat it as
2515
+ // auto-promoted and refresh it to the new assignee's default.
2516
+ const assigneeChanged = issueData.assigneeAgentId !== undefined &&
2517
+ issueData.assigneeAgentId !== null &&
2518
+ issueData.assigneeAgentId !== existing.assigneeAgentId;
2519
+ const explicitEnvInThisUpdate = issueData.executionWorkspaceSettings !== undefined &&
2520
+ Object.prototype.hasOwnProperty.call(parseObject(issueData.executionWorkspaceSettings), "environmentId");
2521
+ if (assigneeChanged && isolatedWorkspacesEnabled && !explicitEnvInThisUpdate) {
2522
+ let projectHasEnvironmentSelection = false;
2523
+ if (nextProjectId) {
2524
+ const projectRow = await tx
2525
+ .select({ executionWorkspacePolicy: projects.executionWorkspacePolicy })
2526
+ .from(projects)
2527
+ .where(and(eq(projects.id, nextProjectId), eq(projects.companyId, existing.companyId)))
2528
+ .then((rows) => rows[0] ?? null);
2529
+ const projectPolicy = parseProjectExecutionWorkspacePolicy(projectRow?.executionWorkspacePolicy);
2530
+ projectHasEnvironmentSelection = projectPolicy?.environmentId !== undefined;
2531
+ }
2532
+ if (!projectHasEnvironmentSelection) {
2533
+ const baseSettings = nextExecutionWorkspaceSettings == null
2534
+ ? {}
2535
+ : parseObject(nextExecutionWorkspaceSettings);
2536
+ const existingEnvId = typeof baseSettings.environmentId === "string"
2537
+ ? baseSettings.environmentId
2538
+ : null;
2539
+ const agentRows = await tx
2540
+ .select({ id: agents.id, defaultEnvironmentId: agents.defaultEnvironmentId })
2541
+ .from(agents)
2542
+ .where(and(eq(agents.companyId, existing.companyId), inArray(agents.id, [issueData.assigneeAgentId, existing.assigneeAgentId].filter((value) => typeof value === "string"))));
2543
+ const newAssignee = agentRows.find((row) => row.id === issueData.assigneeAgentId);
2544
+ const previousAssignee = existing.assigneeAgentId
2545
+ ? agentRows.find((row) => row.id === existing.assigneeAgentId)
2546
+ : null;
2547
+ const newDefaultEnvId = typeof newAssignee?.defaultEnvironmentId === "string" && newAssignee.defaultEnvironmentId.length > 0
2548
+ ? newAssignee.defaultEnvironmentId
2549
+ : null;
2550
+ const previousDefaultEnvId = typeof previousAssignee?.defaultEnvironmentId === "string" && previousAssignee.defaultEnvironmentId.length > 0
2551
+ ? previousAssignee.defaultEnvironmentId
2552
+ : null;
2553
+ const existingEnvWasAutoPromoted = existingEnvId === null ||
2554
+ (previousDefaultEnvId !== null && existingEnvId === previousDefaultEnvId);
2555
+ if (newDefaultEnvId && existingEnvWasAutoPromoted) {
2556
+ patch.executionWorkspaceSettings = {
2557
+ ...baseSettings,
2558
+ environmentId: newDefaultEnvId,
2559
+ };
2560
+ }
2561
+ }
2562
+ }
2563
+ patch.goalId = resolveNextIssueGoalId({
2564
+ currentProjectId: existing.projectId,
2565
+ currentGoalId: existing.goalId,
2566
+ currentProjectGoalId,
2567
+ projectId: issueData.projectId,
2568
+ goalId: issueData.goalId,
2569
+ projectGoalId: nextProjectGoalId,
2570
+ defaultGoalId: null,
2571
+ });
2572
+ const updated = await tx
2573
+ .update(issues)
2574
+ .set(patch)
2575
+ .where(eq(issues.id, id))
2576
+ .returning()
2577
+ .then((rows) => rows[0] ?? null);
2578
+ if (!updated)
2579
+ return null;
2580
+ if (nextLabelIds !== undefined) {
2581
+ await syncIssueLabels(updated.id, existing.companyId, nextLabelIds, tx);
2582
+ }
2583
+ if (blockedByIssueIds !== undefined) {
2584
+ await syncBlockedByIssueIds(updated.id, existing.companyId, blockedByIssueIds, {
2585
+ agentId: actorAgentId ?? null,
2586
+ userId: actorUserId ?? null,
2587
+ }, tx);
2588
+ }
2589
+ if (issueData.executionWorkspaceSettings !== undefined &&
2590
+ nextExecutionWorkspaceId &&
2591
+ nextExecutionWorkspacePreference === "reuse_existing") {
2592
+ const workspace = await tx
2593
+ .select({
2594
+ id: executionWorkspaces.id,
2595
+ metadata: executionWorkspaces.metadata,
2596
+ })
2597
+ .from(executionWorkspaces)
2598
+ .where(and(eq(executionWorkspaces.id, nextExecutionWorkspaceId), eq(executionWorkspaces.companyId, existing.companyId)))
2599
+ .then((rows) => rows[0] ?? null);
2600
+ if (workspace) {
2601
+ await tx
2602
+ .update(executionWorkspaces)
2603
+ .set({
2604
+ metadata: mergeExecutionWorkspaceConfig(workspace.metadata ?? null, buildReusedExecutionWorkspaceConfigPatchFromIssueSettings(nextExecutionWorkspaceSettings)),
2605
+ updatedAt: new Date(),
2606
+ })
2607
+ .where(eq(executionWorkspaces.id, workspace.id));
2608
+ }
2609
+ }
2610
+ const [enriched] = await withIssueLabels(tx, [updated]);
2611
+ return enriched;
2612
+ };
2613
+ return dbOrTx === db ? db.transaction(runUpdate) : runUpdate(dbOrTx);
2614
+ },
2615
+ clearExecutionWorkspaceEnvironmentSelection: async (companyId, environmentId) => {
2616
+ const rows = await db
2617
+ .select({
2618
+ id: issues.id,
2619
+ executionWorkspaceSettings: issues.executionWorkspaceSettings,
2620
+ })
2621
+ .from(issues)
2622
+ .where(eq(issues.companyId, companyId));
2623
+ let cleared = 0;
2624
+ for (const row of rows) {
2625
+ const settings = parseIssueExecutionWorkspaceSettings(row.executionWorkspaceSettings);
2626
+ if (settings?.environmentId !== environmentId)
2627
+ continue;
2628
+ await db
2629
+ .update(issues)
2630
+ .set({
2631
+ executionWorkspaceSettings: {
2632
+ ...settings,
2633
+ environmentId: null,
2634
+ },
2635
+ updatedAt: new Date(),
2636
+ })
2637
+ .where(eq(issues.id, row.id));
2638
+ cleared += 1;
2639
+ }
2640
+ return cleared;
2641
+ },
2642
+ remove: (id) => db.transaction(async (tx) => {
2643
+ const attachmentAssetIds = await tx
2644
+ .select({ assetId: issueAttachments.assetId })
2645
+ .from(issueAttachments)
2646
+ .where(eq(issueAttachments.issueId, id));
2647
+ const issueDocumentIds = await tx
2648
+ .select({ documentId: issueDocuments.documentId })
2649
+ .from(issueDocuments)
2650
+ .where(eq(issueDocuments.issueId, id));
2651
+ const removedIssue = await tx
2652
+ .delete(issues)
2653
+ .where(eq(issues.id, id))
2654
+ .returning()
2655
+ .then((rows) => rows[0] ?? null);
2656
+ if (removedIssue && attachmentAssetIds.length > 0) {
2657
+ await tx
2658
+ .delete(assets)
2659
+ .where(inArray(assets.id, attachmentAssetIds.map((row) => row.assetId)));
2660
+ }
2661
+ if (removedIssue && issueDocumentIds.length > 0) {
2662
+ await tx
2663
+ .delete(documents)
2664
+ .where(inArray(documents.id, issueDocumentIds.map((row) => row.documentId)));
2665
+ }
2666
+ if (!removedIssue)
2667
+ return null;
2668
+ const [enriched] = await withIssueLabels(tx, [removedIssue]);
2669
+ return enriched;
2670
+ }),
2671
+ checkout: async (id, agentId, expectedStatuses, checkoutRunId) => {
2672
+ const issueCompany = await db
2673
+ .select({ companyId: issues.companyId })
2674
+ .from(issues)
2675
+ .where(eq(issues.id, id))
2676
+ .then((rows) => rows[0] ?? null);
2677
+ if (!issueCompany)
2678
+ throw notFound("Issue not found");
2679
+ await assertAssignableAgent(issueCompany.companyId, agentId);
2680
+ const now = new Date();
2681
+ const activePauseHold = await treeControlSvc.getActivePauseHoldGate(issueCompany.companyId, id);
2682
+ if (activePauseHold &&
2683
+ !(await isTreeHoldInteractionCheckoutAllowed(issueCompany.companyId, checkoutRunId, activePauseHold))) {
2684
+ throw conflict("Issue checkout blocked by active subtree pause hold", {
2685
+ issueId: id,
2686
+ holdId: activePauseHold.holdId,
2687
+ rootIssueId: activePauseHold.rootIssueId,
2688
+ mode: activePauseHold.mode,
2689
+ securityPrinciples: ["Complete Mediation", "Fail Securely", "Secure Defaults"],
2690
+ });
2691
+ }
2692
+ await clearExecutionRunIfTerminal(id);
2693
+ const dependencyReadiness = await listIssueDependencyReadinessMap(db, issueCompany.companyId, [id]);
2694
+ const unresolvedBlockerIssueIds = dependencyReadiness.get(id)?.unresolvedBlockerIssueIds ?? [];
2695
+ if (unresolvedBlockerIssueIds.length > 0) {
2696
+ throw unprocessable("Issue is blocked by unresolved blockers", { unresolvedBlockerIssueIds });
2697
+ }
2698
+ const sameRunAssigneeCondition = checkoutRunId
2699
+ ? and(eq(issues.assigneeAgentId, agentId), or(isNull(issues.checkoutRunId), eq(issues.checkoutRunId, checkoutRunId)))
2700
+ : and(eq(issues.assigneeAgentId, agentId), isNull(issues.checkoutRunId));
2701
+ const executionLockCondition = checkoutRunId
2702
+ ? or(isNull(issues.executionRunId), eq(issues.executionRunId, checkoutRunId))
2703
+ : isNull(issues.executionRunId);
2704
+ const updated = await db
2705
+ .update(issues)
2706
+ .set({
2707
+ assigneeAgentId: agentId,
2708
+ assigneeUserId: null,
2709
+ checkoutRunId,
2710
+ executionRunId: checkoutRunId,
2711
+ status: "in_progress",
2712
+ startedAt: now,
2713
+ updatedAt: now,
2714
+ })
2715
+ .where(and(eq(issues.id, id), inArray(issues.status, expectedStatuses), or(isNull(issues.assigneeAgentId), sameRunAssigneeCondition), executionLockCondition))
2716
+ .returning()
2717
+ .then((rows) => rows[0] ?? null);
2718
+ if (updated) {
2719
+ const [enriched] = await withIssueLabels(db, [updated]);
2720
+ return enriched;
2721
+ }
2722
+ const current = await db
2723
+ .select({
2724
+ id: issues.id,
2725
+ status: issues.status,
2726
+ assigneeAgentId: issues.assigneeAgentId,
2727
+ checkoutRunId: issues.checkoutRunId,
2728
+ executionRunId: issues.executionRunId,
2729
+ })
2730
+ .from(issues)
2731
+ .where(eq(issues.id, id))
2732
+ .then((rows) => rows[0] ?? null);
2733
+ if (!current)
2734
+ throw notFound("Issue not found");
2735
+ if (current.assigneeAgentId === agentId &&
2736
+ current.status === "in_progress" &&
2737
+ current.checkoutRunId == null &&
2738
+ (current.executionRunId == null || current.executionRunId === checkoutRunId) &&
2739
+ checkoutRunId) {
2740
+ const adopted = await db
2741
+ .update(issues)
2742
+ .set({
2743
+ checkoutRunId,
2744
+ executionRunId: checkoutRunId,
2745
+ updatedAt: new Date(),
2746
+ })
2747
+ .where(and(eq(issues.id, id), eq(issues.status, "in_progress"), eq(issues.assigneeAgentId, agentId), isNull(issues.checkoutRunId), or(isNull(issues.executionRunId), eq(issues.executionRunId, checkoutRunId))))
2748
+ .returning()
2749
+ .then((rows) => rows[0] ?? null);
2750
+ if (adopted)
2751
+ return adopted;
2752
+ }
2753
+ if (checkoutRunId &&
2754
+ current.assigneeAgentId === agentId &&
2755
+ current.status === "in_progress" &&
2756
+ current.checkoutRunId &&
2757
+ current.checkoutRunId !== checkoutRunId) {
2758
+ const adopted = await adoptStaleCheckoutRun({
2759
+ issueId: id,
2760
+ actorAgentId: agentId,
2761
+ actorRunId: checkoutRunId,
2762
+ expectedCheckoutRunId: current.checkoutRunId,
2763
+ });
2764
+ if (adopted) {
2765
+ const row = await db.select().from(issues).where(eq(issues.id, id)).then((rows) => rows[0] ?? null);
2766
+ if (!row)
2767
+ throw notFound("Issue not found");
2768
+ const [enriched] = await withIssueLabels(db, [row]);
2769
+ return enriched;
2770
+ }
2771
+ }
2772
+ // If this run already owns it and it's in_progress, return it (no self-409)
2773
+ if (current.assigneeAgentId === agentId &&
2774
+ current.status === "in_progress" &&
2775
+ sameRunLock(current.checkoutRunId, checkoutRunId)) {
2776
+ const row = await db.select().from(issues).where(eq(issues.id, id)).then((rows) => rows[0] ?? null);
2777
+ if (!row)
2778
+ throw notFound("Issue not found");
2779
+ const [enriched] = await withIssueLabels(db, [row]);
2780
+ return enriched;
2781
+ }
2782
+ throw conflict("Issue checkout conflict", {
2783
+ issueId: current.id,
2784
+ status: current.status,
2785
+ assigneeAgentId: current.assigneeAgentId,
2786
+ checkoutRunId: current.checkoutRunId,
2787
+ executionRunId: current.executionRunId,
2788
+ });
2789
+ },
2790
+ assertCheckoutOwner: async (id, actorAgentId, actorRunId) => {
2791
+ await clearExecutionRunIfTerminal(id);
2792
+ const current = await db
2793
+ .select({
2794
+ id: issues.id,
2795
+ status: issues.status,
2796
+ assigneeAgentId: issues.assigneeAgentId,
2797
+ checkoutRunId: issues.checkoutRunId,
2798
+ executionRunId: issues.executionRunId,
2799
+ })
2800
+ .from(issues)
2801
+ .where(eq(issues.id, id))
2802
+ .then((rows) => rows[0] ?? null);
2803
+ if (!current)
2804
+ throw notFound("Issue not found");
2805
+ if (current.status === "in_progress" &&
2806
+ current.assigneeAgentId === actorAgentId &&
2807
+ sameRunLock(current.checkoutRunId, actorRunId)) {
2808
+ return { ...current, adoptedFromRunId: null };
2809
+ }
2810
+ if (actorRunId &&
2811
+ current.status === "in_progress" &&
2812
+ current.assigneeAgentId === actorAgentId &&
2813
+ current.checkoutRunId == null &&
2814
+ (current.executionRunId == null || current.executionRunId === actorRunId)) {
2815
+ const adopted = await adoptUnownedCheckoutRun({
2816
+ issueId: id,
2817
+ actorAgentId,
2818
+ actorRunId,
2819
+ });
2820
+ if (adopted) {
2821
+ return {
2822
+ ...adopted,
2823
+ adoptedFromRunId: null,
2824
+ };
2825
+ }
2826
+ }
2827
+ if (actorRunId &&
2828
+ current.status === "in_progress" &&
2829
+ current.assigneeAgentId === actorAgentId &&
2830
+ current.checkoutRunId &&
2831
+ current.checkoutRunId !== actorRunId) {
2832
+ const adopted = await adoptStaleCheckoutRun({
2833
+ issueId: id,
2834
+ actorAgentId,
2835
+ actorRunId,
2836
+ expectedCheckoutRunId: current.checkoutRunId,
2837
+ });
2838
+ if (adopted) {
2839
+ return {
2840
+ ...adopted,
2841
+ adoptedFromRunId: current.checkoutRunId,
2842
+ };
2843
+ }
2844
+ }
2845
+ throw conflict("Issue run ownership conflict", {
2846
+ issueId: current.id,
2847
+ status: current.status,
2848
+ assigneeAgentId: current.assigneeAgentId,
2849
+ checkoutRunId: current.checkoutRunId,
2850
+ executionRunId: current.executionRunId,
2851
+ actorAgentId,
2852
+ actorRunId,
2853
+ });
2854
+ },
2855
+ release: async (id, actorAgentId, actorRunId) => {
2856
+ await clearExecutionRunIfTerminal(id);
2857
+ const existing = await db
2858
+ .select()
2859
+ .from(issues)
2860
+ .where(eq(issues.id, id))
2861
+ .then((rows) => rows[0] ?? null);
2862
+ if (!existing)
2863
+ return null;
2864
+ if (actorAgentId && existing.assigneeAgentId && existing.assigneeAgentId !== actorAgentId) {
2865
+ throw conflict("Only assignee can release issue");
2866
+ }
2867
+ if (actorAgentId &&
2868
+ existing.status === "in_progress" &&
2869
+ existing.assigneeAgentId === actorAgentId &&
2870
+ existing.checkoutRunId &&
2871
+ !sameRunLock(existing.checkoutRunId, actorRunId ?? null)) {
2872
+ const stale = await isTerminalOrMissingHeartbeatRun(existing.checkoutRunId);
2873
+ if (!stale) {
2874
+ throw conflict("Only checkout run can release issue", {
2875
+ issueId: existing.id,
2876
+ assigneeAgentId: existing.assigneeAgentId,
2877
+ checkoutRunId: existing.checkoutRunId,
2878
+ actorRunId: actorRunId ?? null,
2879
+ });
2880
+ }
2881
+ }
2882
+ const updated = await db
2883
+ .update(issues)
2884
+ .set({
2885
+ status: "todo",
2886
+ assigneeAgentId: null,
2887
+ checkoutRunId: null,
2888
+ executionRunId: null,
2889
+ executionAgentNameKey: null,
2890
+ executionLockedAt: null,
2891
+ updatedAt: new Date(),
2892
+ })
2893
+ .where(eq(issues.id, id))
2894
+ .returning()
2895
+ .then((rows) => rows[0] ?? null);
2896
+ if (!updated)
2897
+ return null;
2898
+ const [enriched] = await withIssueLabels(db, [updated]);
2899
+ return enriched;
2900
+ },
2901
+ adminForceRelease: async (id, options = {}) => db.transaction(async (tx) => {
2902
+ await tx.execute(sql `select ${issues.id} from ${issues} where ${issues.id} = ${id} for update`);
2903
+ const existing = await tx
2904
+ .select({
2905
+ id: issues.id,
2906
+ checkoutRunId: issues.checkoutRunId,
2907
+ executionRunId: issues.executionRunId,
2908
+ })
2909
+ .from(issues)
2910
+ .where(eq(issues.id, id))
2911
+ .then((rows) => rows[0] ?? null);
2912
+ if (!existing)
2913
+ return null;
2914
+ const patch = {
2915
+ checkoutRunId: null,
2916
+ executionRunId: null,
2917
+ executionAgentNameKey: null,
2918
+ executionLockedAt: null,
2919
+ updatedAt: new Date(),
2920
+ };
2921
+ if (options.clearAssignee) {
2922
+ patch.assigneeAgentId = null;
2923
+ }
2924
+ const updated = await tx
2925
+ .update(issues)
2926
+ .set(patch)
2927
+ .where(eq(issues.id, id))
2928
+ .returning()
2929
+ .then((rows) => rows[0] ?? null);
2930
+ if (!updated)
2931
+ return null;
2932
+ const [enriched] = await withIssueLabels(tx, [updated]);
2933
+ return {
2934
+ issue: enriched,
2935
+ previous: {
2936
+ checkoutRunId: existing.checkoutRunId,
2937
+ executionRunId: existing.executionRunId,
2938
+ },
2939
+ };
2940
+ }),
2941
+ listLabels: (companyId) => db.select().from(labels).where(eq(labels.companyId, companyId)).orderBy(asc(labels.name), asc(labels.id)),
2942
+ getLabelById: (id) => db
2943
+ .select()
2944
+ .from(labels)
2945
+ .where(eq(labels.id, id))
2946
+ .then((rows) => rows[0] ?? null),
2947
+ createLabel: async (companyId, data) => {
2948
+ const [created] = await db
2949
+ .insert(labels)
2950
+ .values({
2951
+ companyId,
2952
+ name: data.name.trim(),
2953
+ color: data.color,
2954
+ })
2955
+ .returning();
2956
+ return created;
2957
+ },
2958
+ deleteLabel: async (id) => db
2959
+ .delete(labels)
2960
+ .where(eq(labels.id, id))
2961
+ .returning()
2962
+ .then((rows) => rows[0] ?? null),
2963
+ listComments: async (issueId, opts) => {
2964
+ const order = opts?.order === "asc" ? "asc" : "desc";
2965
+ const afterCommentId = opts?.afterCommentId?.trim() || null;
2966
+ const limit = opts?.limit && opts.limit > 0
2967
+ ? Math.min(Math.floor(opts.limit), MAX_ISSUE_COMMENT_PAGE_LIMIT)
2968
+ : null;
2969
+ const conditions = [eq(issueComments.issueId, issueId)];
2970
+ if (afterCommentId) {
2971
+ const anchor = await db
2972
+ .select({
2973
+ id: issueComments.id,
2974
+ createdAt: issueComments.createdAt,
2975
+ })
2976
+ .from(issueComments)
2977
+ .where(and(eq(issueComments.issueId, issueId), eq(issueComments.id, afterCommentId)))
2978
+ .then((rows) => rows[0] ?? null);
2979
+ if (!anchor)
2980
+ return [];
2981
+ conditions.push(order === "asc"
2982
+ ? or(gt(issueComments.createdAt, anchor.createdAt), and(eq(issueComments.createdAt, anchor.createdAt), gt(issueComments.id, anchor.id)))
2983
+ : or(lt(issueComments.createdAt, anchor.createdAt), and(eq(issueComments.createdAt, anchor.createdAt), lt(issueComments.id, anchor.id))));
2984
+ }
2985
+ const query = db
2986
+ .select()
2987
+ .from(issueComments)
2988
+ .where(and(...conditions))
2989
+ .orderBy(order === "asc" ? asc(issueComments.createdAt) : desc(issueComments.createdAt), order === "asc" ? asc(issueComments.id) : desc(issueComments.id));
2990
+ const comments = limit ? await query.limit(limit) : await query;
2991
+ const { censorUsernameInLogs } = await instanceSettings.getGeneral();
2992
+ const enrichedComments = await enrichCommentsWithDerivedAgentAttribution(comments);
2993
+ return enrichedComments.map((comment) => redactIssueComment(comment, censorUsernameInLogs));
2994
+ },
2995
+ getCommentCursor: async (issueId) => {
2996
+ const [latest, countRow] = await Promise.all([
2997
+ db
2998
+ .select({
2999
+ latestCommentId: issueComments.id,
3000
+ latestCommentAt: issueComments.createdAt,
3001
+ })
3002
+ .from(issueComments)
3003
+ .where(eq(issueComments.issueId, issueId))
3004
+ .orderBy(desc(issueComments.createdAt), desc(issueComments.id))
3005
+ .limit(1)
3006
+ .then((rows) => rows[0] ?? null),
3007
+ db
3008
+ .select({
3009
+ totalComments: sql `count(*)::int`,
3010
+ })
3011
+ .from(issueComments)
3012
+ .where(eq(issueComments.issueId, issueId))
3013
+ .then((rows) => rows[0] ?? null),
3014
+ ]);
3015
+ return {
3016
+ totalComments: Number(countRow?.totalComments ?? 0),
3017
+ latestCommentId: latest?.latestCommentId ?? null,
3018
+ latestCommentAt: latest?.latestCommentAt ?? null,
3019
+ };
3020
+ },
3021
+ getComment: async (commentId) => {
3022
+ const { censorUsernameInLogs } = await instanceSettings.getGeneral();
3023
+ const comment = await db
3024
+ .select()
3025
+ .from(issueComments)
3026
+ .where(eq(issueComments.id, commentId))
3027
+ .then((rows) => rows[0] ?? null);
3028
+ if (!comment)
3029
+ return null;
3030
+ const [enrichedComment] = await enrichCommentsWithDerivedAgentAttribution([comment]);
3031
+ return redactIssueComment(enrichedComment ?? comment, censorUsernameInLogs);
3032
+ },
3033
+ removeComment: async (commentId) => {
3034
+ const currentUserRedactionOptions = {
3035
+ enabled: (await instanceSettings.getGeneral()).censorUsernameInLogs,
3036
+ };
3037
+ return db.transaction(async (tx) => {
3038
+ const [comment] = await tx
3039
+ .delete(issueComments)
3040
+ .where(eq(issueComments.id, commentId))
3041
+ .returning();
3042
+ if (!comment)
3043
+ return null;
3044
+ await tx
3045
+ .update(issues)
3046
+ .set({ updatedAt: new Date() })
3047
+ .where(eq(issues.id, comment.issueId));
3048
+ return redactIssueComment(comment, currentUserRedactionOptions.enabled);
3049
+ });
3050
+ },
3051
+ addComment: async (issueId, body, actor, options) => {
3052
+ const issue = await db
3053
+ .select({ companyId: issues.companyId })
3054
+ .from(issues)
3055
+ .where(eq(issues.id, issueId))
3056
+ .then((rows) => rows[0] ?? null);
3057
+ if (!issue)
3058
+ throw notFound("Issue not found");
3059
+ const currentUserRedactionOptions = {
3060
+ enabled: (await instanceSettings.getGeneral()).censorUsernameInLogs,
3061
+ };
3062
+ const redactedBody = redactCurrentUserText(body, currentUserRedactionOptions);
3063
+ const authorType = issueCommentAuthorTypeSchema.parse(options?.authorType ?? (actor.agentId ? "agent" : actor.userId ? "user" : "system"));
3064
+ assertIssueCommentAuthorTypeAllowed(actor, authorType);
3065
+ const presentation = issueCommentPresentationSchema.nullable().parse(options?.presentation ?? null);
3066
+ const metadata = issueCommentMetadataSchema.nullable().parse(options?.metadata ?? null);
3067
+ const createdAt = options?.createdAt ? new Date(options.createdAt) : null;
3068
+ const [comment] = await db
3069
+ .insert(issueComments)
3070
+ .values({
3071
+ companyId: issue.companyId,
3072
+ issueId,
3073
+ authorAgentId: actor.agentId ?? null,
3074
+ authorUserId: actor.userId ?? null,
3075
+ authorType,
3076
+ createdByRunId: actor.runId ?? null,
3077
+ body: redactedBody,
3078
+ presentation,
3079
+ metadata,
3080
+ ...(createdAt && !Number.isNaN(createdAt.getTime()) ? { createdAt } : {}),
3081
+ })
3082
+ .returning();
3083
+ // Update issue's updatedAt so comment activity is reflected in recency sorting
3084
+ await db
3085
+ .update(issues)
3086
+ .set({ updatedAt: new Date() })
3087
+ .where(eq(issues.id, issueId));
3088
+ return redactIssueComment(comment, currentUserRedactionOptions.enabled);
3089
+ },
3090
+ createAttachment: async (input) => {
3091
+ const issue = await db
3092
+ .select({ id: issues.id, companyId: issues.companyId })
3093
+ .from(issues)
3094
+ .where(eq(issues.id, input.issueId))
3095
+ .then((rows) => rows[0] ?? null);
3096
+ if (!issue)
3097
+ throw notFound("Issue not found");
3098
+ if (input.issueCommentId) {
3099
+ const comment = await db
3100
+ .select({ id: issueComments.id, companyId: issueComments.companyId, issueId: issueComments.issueId })
3101
+ .from(issueComments)
3102
+ .where(eq(issueComments.id, input.issueCommentId))
3103
+ .then((rows) => rows[0] ?? null);
3104
+ if (!comment)
3105
+ throw notFound("Issue comment not found");
3106
+ if (comment.companyId !== issue.companyId || comment.issueId !== issue.id) {
3107
+ throw unprocessable("Attachment comment must belong to same issue and company");
3108
+ }
3109
+ }
3110
+ return db.transaction(async (tx) => {
3111
+ const [asset] = await tx
3112
+ .insert(assets)
3113
+ .values({
3114
+ companyId: issue.companyId,
3115
+ provider: input.provider,
3116
+ objectKey: input.objectKey,
3117
+ contentType: input.contentType,
3118
+ byteSize: input.byteSize,
3119
+ sha256: input.sha256,
3120
+ originalFilename: input.originalFilename ?? null,
3121
+ createdByAgentId: input.createdByAgentId ?? null,
3122
+ createdByUserId: input.createdByUserId ?? null,
3123
+ })
3124
+ .returning();
3125
+ const [attachment] = await tx
3126
+ .insert(issueAttachments)
3127
+ .values({
3128
+ companyId: issue.companyId,
3129
+ issueId: issue.id,
3130
+ assetId: asset.id,
3131
+ issueCommentId: input.issueCommentId ?? null,
3132
+ })
3133
+ .returning();
3134
+ return {
3135
+ id: attachment.id,
3136
+ companyId: attachment.companyId,
3137
+ issueId: attachment.issueId,
3138
+ issueCommentId: attachment.issueCommentId,
3139
+ assetId: attachment.assetId,
3140
+ provider: asset.provider,
3141
+ objectKey: asset.objectKey,
3142
+ contentType: asset.contentType,
3143
+ byteSize: asset.byteSize,
3144
+ sha256: asset.sha256,
3145
+ originalFilename: asset.originalFilename,
3146
+ createdByAgentId: asset.createdByAgentId,
3147
+ createdByUserId: asset.createdByUserId,
3148
+ createdAt: attachment.createdAt,
3149
+ updatedAt: attachment.updatedAt,
3150
+ };
3151
+ });
3152
+ },
3153
+ listAttachments: async (issueId) => db
3154
+ .select({
3155
+ id: issueAttachments.id,
3156
+ companyId: issueAttachments.companyId,
3157
+ issueId: issueAttachments.issueId,
3158
+ issueCommentId: issueAttachments.issueCommentId,
3159
+ assetId: issueAttachments.assetId,
3160
+ provider: assets.provider,
3161
+ objectKey: assets.objectKey,
3162
+ contentType: assets.contentType,
3163
+ byteSize: assets.byteSize,
3164
+ sha256: assets.sha256,
3165
+ originalFilename: assets.originalFilename,
3166
+ createdByAgentId: assets.createdByAgentId,
3167
+ createdByUserId: assets.createdByUserId,
3168
+ createdAt: issueAttachments.createdAt,
3169
+ updatedAt: issueAttachments.updatedAt,
3170
+ })
3171
+ .from(issueAttachments)
3172
+ .innerJoin(assets, eq(issueAttachments.assetId, assets.id))
3173
+ .where(eq(issueAttachments.issueId, issueId))
3174
+ .orderBy(desc(issueAttachments.createdAt)),
3175
+ getAttachmentById: async (id) => db
3176
+ .select({
3177
+ id: issueAttachments.id,
3178
+ companyId: issueAttachments.companyId,
3179
+ issueId: issueAttachments.issueId,
3180
+ issueCommentId: issueAttachments.issueCommentId,
3181
+ assetId: issueAttachments.assetId,
3182
+ provider: assets.provider,
3183
+ objectKey: assets.objectKey,
3184
+ contentType: assets.contentType,
3185
+ byteSize: assets.byteSize,
3186
+ sha256: assets.sha256,
3187
+ originalFilename: assets.originalFilename,
3188
+ createdByAgentId: assets.createdByAgentId,
3189
+ createdByUserId: assets.createdByUserId,
3190
+ createdAt: issueAttachments.createdAt,
3191
+ updatedAt: issueAttachments.updatedAt,
3192
+ })
3193
+ .from(issueAttachments)
3194
+ .innerJoin(assets, eq(issueAttachments.assetId, assets.id))
3195
+ .where(eq(issueAttachments.id, id))
3196
+ .then((rows) => rows[0] ?? null),
3197
+ removeAttachment: async (id) => db.transaction(async (tx) => {
3198
+ const existing = await tx
3199
+ .select({
3200
+ id: issueAttachments.id,
3201
+ companyId: issueAttachments.companyId,
3202
+ issueId: issueAttachments.issueId,
3203
+ issueCommentId: issueAttachments.issueCommentId,
3204
+ assetId: issueAttachments.assetId,
3205
+ provider: assets.provider,
3206
+ objectKey: assets.objectKey,
3207
+ contentType: assets.contentType,
3208
+ byteSize: assets.byteSize,
3209
+ sha256: assets.sha256,
3210
+ originalFilename: assets.originalFilename,
3211
+ createdByAgentId: assets.createdByAgentId,
3212
+ createdByUserId: assets.createdByUserId,
3213
+ createdAt: issueAttachments.createdAt,
3214
+ updatedAt: issueAttachments.updatedAt,
3215
+ })
3216
+ .from(issueAttachments)
3217
+ .innerJoin(assets, eq(issueAttachments.assetId, assets.id))
3218
+ .where(eq(issueAttachments.id, id))
3219
+ .then((rows) => rows[0] ?? null);
3220
+ if (!existing)
3221
+ return null;
3222
+ await tx.delete(issueAttachments).where(eq(issueAttachments.id, id));
3223
+ await tx.delete(assets).where(eq(assets.id, existing.assetId));
3224
+ return existing;
3225
+ }),
3226
+ findMentionedAgents: async (companyId, body) => {
3227
+ const re = /\B@([^\s@,!?.]+)/g;
3228
+ const tokens = new Set();
3229
+ let m;
3230
+ while ((m = re.exec(body)) !== null) {
3231
+ const normalized = normalizeAgentMentionToken(m[1]);
3232
+ if (normalized)
3233
+ tokens.add(normalized.toLowerCase());
3234
+ }
3235
+ const explicitAgentMentionIds = extractAgentMentionIds(body);
3236
+ if (tokens.size === 0 && explicitAgentMentionIds.length === 0)
3237
+ return [];
3238
+ const rows = await db.select({ id: agents.id, name: agents.name })
3239
+ .from(agents).where(eq(agents.companyId, companyId));
3240
+ const resolved = new Set(explicitAgentMentionIds);
3241
+ for (const agent of rows) {
3242
+ if (tokens.has(agent.name.toLowerCase())) {
3243
+ resolved.add(agent.id);
3244
+ }
3245
+ }
3246
+ return [...resolved];
3247
+ },
3248
+ findMentionedProjectIds: async (issueId, opts) => {
3249
+ const issue = await db
3250
+ .select({
3251
+ companyId: issues.companyId,
3252
+ title: issues.title,
3253
+ description: issues.description,
3254
+ })
3255
+ .from(issues)
3256
+ .where(eq(issues.id, issueId))
3257
+ .then((rows) => rows[0] ?? null);
3258
+ if (!issue)
3259
+ return [];
3260
+ const mentionedIds = new Set();
3261
+ for (const source of [issue.title, issue.description ?? ""]) {
3262
+ for (const projectId of extractProjectMentionIds(source)) {
3263
+ mentionedIds.add(projectId);
3264
+ }
3265
+ }
3266
+ if (opts?.includeCommentBodies !== false) {
3267
+ const comments = await db
3268
+ .select({ body: issueComments.body })
3269
+ .from(issueComments)
3270
+ .where(eq(issueComments.issueId, issueId));
3271
+ for (const comment of comments) {
3272
+ for (const projectId of extractProjectMentionIds(comment.body)) {
3273
+ mentionedIds.add(projectId);
3274
+ }
3275
+ }
3276
+ }
3277
+ if (mentionedIds.size === 0)
3278
+ return [];
3279
+ const rows = await db
3280
+ .select({ id: projects.id })
3281
+ .from(projects)
3282
+ .where(and(eq(projects.companyId, issue.companyId), inArray(projects.id, [...mentionedIds])));
3283
+ const valid = new Set(rows.map((row) => row.id));
3284
+ return [...mentionedIds].filter((projectId) => valid.has(projectId));
3285
+ },
3286
+ getAncestors: async (issueId) => {
3287
+ const raw = [];
3288
+ const visited = new Set([issueId]);
3289
+ const start = await db.select().from(issues).where(eq(issues.id, issueId)).then(r => r[0] ?? null);
3290
+ let currentId = start?.parentId ?? null;
3291
+ while (currentId && !visited.has(currentId) && raw.length < 50) {
3292
+ visited.add(currentId);
3293
+ const parent = await db.select({
3294
+ id: issues.id, identifier: issues.identifier, title: issues.title, description: issues.description,
3295
+ status: issues.status, priority: issues.priority,
3296
+ assigneeAgentId: issues.assigneeAgentId, projectId: issues.projectId,
3297
+ goalId: issues.goalId, parentId: issues.parentId,
3298
+ }).from(issues).where(eq(issues.id, currentId)).then(r => r[0] ?? null);
3299
+ if (!parent)
3300
+ break;
3301
+ raw.push({
3302
+ id: parent.id, identifier: parent.identifier ?? null, title: parent.title, description: parent.description ?? null,
3303
+ status: parent.status, priority: parent.priority,
3304
+ assigneeAgentId: parent.assigneeAgentId ?? null,
3305
+ projectId: parent.projectId ?? null, goalId: parent.goalId ?? null,
3306
+ });
3307
+ currentId = parent.parentId ?? null;
3308
+ }
3309
+ // Batch-fetch referenced projects and goals
3310
+ const projectIds = [...new Set(raw.map(a => a.projectId).filter((id) => id != null))];
3311
+ const goalIds = [...new Set(raw.map(a => a.goalId).filter((id) => id != null))];
3312
+ const projectMap = new Map();
3313
+ const goalMap = new Map();
3314
+ if (projectIds.length > 0) {
3315
+ const workspaceRows = await db
3316
+ .select()
3317
+ .from(projectWorkspaces)
3318
+ .where(inArray(projectWorkspaces.projectId, projectIds))
3319
+ .orderBy(desc(projectWorkspaces.isPrimary), asc(projectWorkspaces.createdAt), asc(projectWorkspaces.id));
3320
+ const workspaceMap = new Map();
3321
+ for (const workspace of workspaceRows) {
3322
+ const existing = workspaceMap.get(workspace.projectId);
3323
+ if (existing)
3324
+ existing.push(workspace);
3325
+ else
3326
+ workspaceMap.set(workspace.projectId, [workspace]);
3327
+ }
3328
+ const rows = await db.select({
3329
+ id: projects.id, name: projects.name, description: projects.description,
3330
+ status: projects.status, goalId: projects.goalId,
3331
+ }).from(projects).where(inArray(projects.id, projectIds));
3332
+ for (const r of rows) {
3333
+ const projectWorkspaceRows = workspaceMap.get(r.id) ?? [];
3334
+ const workspaces = projectWorkspaceRows.map((workspace) => ({
3335
+ id: workspace.id,
3336
+ companyId: workspace.companyId,
3337
+ projectId: workspace.projectId,
3338
+ name: workspace.name,
3339
+ cwd: workspace.cwd,
3340
+ repoUrl: workspace.repoUrl ?? null,
3341
+ repoRef: workspace.repoRef ?? null,
3342
+ metadata: workspace.metadata ?? null,
3343
+ isPrimary: workspace.isPrimary,
3344
+ createdAt: workspace.createdAt,
3345
+ updatedAt: workspace.updatedAt,
3346
+ }));
3347
+ const primaryWorkspace = workspaces.find((workspace) => workspace.isPrimary) ?? workspaces[0] ?? null;
3348
+ projectMap.set(r.id, {
3349
+ ...r,
3350
+ workspaces,
3351
+ primaryWorkspace,
3352
+ });
3353
+ // Also collect goalIds from projects
3354
+ if (r.goalId && !goalIds.includes(r.goalId))
3355
+ goalIds.push(r.goalId);
3356
+ }
3357
+ }
3358
+ if (goalIds.length > 0) {
3359
+ const rows = await db.select({
3360
+ id: goals.id, title: goals.title, description: goals.description,
3361
+ level: goals.level, status: goals.status,
3362
+ }).from(goals).where(inArray(goals.id, goalIds));
3363
+ for (const r of rows)
3364
+ goalMap.set(r.id, r);
3365
+ }
3366
+ return raw.map(a => ({
3367
+ ...a,
3368
+ project: a.projectId ? projectMap.get(a.projectId) ?? null : null,
3369
+ goal: a.goalId ? goalMap.get(a.goalId) ?? null : null,
3370
+ }));
3371
+ },
3372
+ };
3373
+ }
3374
+ //# sourceMappingURL=issues.js.map