@cursor/bdk 0.2.3 → 0.2.4

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 (577) hide show
  1. package/dist/bin/agent-serve.js +9 -1
  2. package/dist/channels/slack/attachments.d.ts +2 -1
  3. package/dist/channels/slack/attachments.d.ts.map +1 -1
  4. package/dist/channels/slack/attachments.js +19 -9
  5. package/dist/channels/slack/dispatch.d.ts.map +1 -1
  6. package/dist/channels/slack/dispatch.js +26 -24
  7. package/dist/channels/slack/thread-context.d.ts +21 -11
  8. package/dist/channels/slack/thread-context.d.ts.map +1 -1
  9. package/dist/channels/slack/thread-context.js +75 -27
  10. package/dist/docs/404.html +2 -2
  11. package/dist/docs/assets/{app.BOIHhrKi.js → app.4kQ8Db_q.js} +4 -4
  12. package/dist/docs/assets/chunks/@localSearchIndexroot.CvuAJ0My.js +1 -0
  13. package/dist/docs/assets/chunks/{VPLocalSearchBox.D49zVZqM.js → VPLocalSearchBox.DY1RwB8Q.js} +1 -1
  14. package/dist/docs/assets/chunks/{arc.hmjb-sc4.js → arc.CxE_fSPK.js} +1 -1
  15. package/dist/docs/assets/chunks/{architectureDiagram-Q4EWVU46.CxEI1KqM.js → architectureDiagram-Q4EWVU46.CPX426ui.js} +1 -1
  16. package/dist/docs/assets/chunks/{baseUniq.DHHvBWoV.js → baseUniq.CB52JrKG.js} +1 -1
  17. package/dist/docs/assets/chunks/{blockDiagram-DXYQGD6D.DnXW-3bu.js → blockDiagram-DXYQGD6D.J0cNaQCL.js} +1 -1
  18. package/dist/docs/assets/chunks/{c4Diagram-AHTNJAMY.e-47O2jM.js → c4Diagram-AHTNJAMY.DJn3vEGT.js} +1 -1
  19. package/dist/docs/assets/chunks/channel.BoNycAoN.js +1 -0
  20. package/dist/docs/assets/chunks/{chunk-4BX2VUAB.3ry4pYXB.js → chunk-4BX2VUAB.Dao618F6.js} +1 -1
  21. package/dist/docs/assets/chunks/{chunk-4TB4RGXK.DGIZFRx6.js → chunk-4TB4RGXK.QW8Rhjai.js} +1 -1
  22. package/dist/docs/assets/chunks/{chunk-55IACEB6.DKBnqg9U.js → chunk-55IACEB6.DfRLLKF_.js} +1 -1
  23. package/dist/docs/assets/chunks/{chunk-EDXVE4YY.BIU8Ue5k.js → chunk-EDXVE4YY.CIV2ApKQ.js} +1 -1
  24. package/dist/docs/assets/chunks/{chunk-FMBD7UC4.DP-TFhjI.js → chunk-FMBD7UC4.BEheSuxp.js} +1 -1
  25. package/dist/docs/assets/chunks/{chunk-OYMX7WX6.Ux0OYj5v.js → chunk-OYMX7WX6.CUN88ENB.js} +1 -1
  26. package/dist/docs/assets/chunks/{chunk-QZHKN3VN.BzHMwYox.js → chunk-QZHKN3VN.CgqCs8b_.js} +1 -1
  27. package/dist/docs/assets/chunks/{chunk-YZCP3GAM.D4OGAsSP.js → chunk-YZCP3GAM.iCH0nnTJ.js} +1 -1
  28. package/dist/docs/assets/chunks/classDiagram-6PBFFD2Q.C4x07Gkj.js +1 -0
  29. package/dist/docs/assets/chunks/classDiagram-v2-HSJHXN6E.C4x07Gkj.js +1 -0
  30. package/dist/docs/assets/chunks/clone.Db22cH_-.js +1 -0
  31. package/dist/docs/assets/chunks/{cose-bilkent-S5V4N54A.Jq_7BUNx.js → cose-bilkent-S5V4N54A.BLcUxhWE.js} +1 -1
  32. package/dist/docs/assets/chunks/{dagre-KV5264BT.Di-skR2x.js → dagre-KV5264BT.Ep7LofOm.js} +1 -1
  33. package/dist/docs/assets/chunks/{diagram-5BDNPKRD.DeREHIdH.js → diagram-5BDNPKRD.Bzf4GSQ4.js} +1 -1
  34. package/dist/docs/assets/chunks/{diagram-G4DWMVQ6.C7Kcqxro.js → diagram-G4DWMVQ6.DD6Jh-eM.js} +1 -1
  35. package/dist/docs/assets/chunks/{diagram-MMDJMWI5.BK3eohyo.js → diagram-MMDJMWI5.oOIl8bWd.js} +1 -1
  36. package/dist/docs/assets/chunks/{diagram-TYMM5635.C6TyymXT.js → diagram-TYMM5635.DHs85Ade.js} +1 -1
  37. package/dist/docs/assets/chunks/{erDiagram-SMLLAGMA.DYGG-gGx.js → erDiagram-SMLLAGMA.BIb5ghCk.js} +1 -1
  38. package/dist/docs/assets/chunks/{flowDiagram-DWJPFMVM.C9nBcSV4.js → flowDiagram-DWJPFMVM.DV4paY9k.js} +1 -1
  39. package/dist/docs/assets/chunks/{ganttDiagram-T4ZO3ILL.wAg_ymsp.js → ganttDiagram-T4ZO3ILL.AyEKA6_v.js} +1 -1
  40. package/dist/docs/assets/chunks/{gitGraphDiagram-UUTBAWPF.B87j9Oeg.js → gitGraphDiagram-UUTBAWPF.BltiCDFo.js} +1 -1
  41. package/dist/docs/assets/chunks/{graph.CuFMj31w.js → graph.DzuEYGdC.js} +1 -1
  42. package/dist/docs/assets/chunks/{infoDiagram-42DDH7IO.P_mLGumP.js → infoDiagram-42DDH7IO.BV2l981J.js} +1 -1
  43. package/dist/docs/assets/chunks/{ishikawaDiagram-UXIWVN3A.DyuL_MsT.js → ishikawaDiagram-UXIWVN3A.BA4Izf-m.js} +1 -1
  44. package/dist/docs/assets/chunks/{journeyDiagram-VCZTEJTY.CtP09IoJ.js → journeyDiagram-VCZTEJTY.DjaFbFS3.js} +1 -1
  45. package/dist/docs/assets/chunks/{kanban-definition-6JOO6SKY.BoeSYPZo.js → kanban-definition-6JOO6SKY.CfTFieDs.js} +1 -1
  46. package/dist/docs/assets/chunks/{layout.B0lMMtNo.js → layout.DzfWqTBV.js} +1 -1
  47. package/dist/docs/assets/chunks/{linear.HxRBiAFX.js → linear.BO6mpulV.js} +1 -1
  48. package/dist/docs/assets/chunks/{min.BGlFFHwS.js → min.BGgTadgT.js} +1 -1
  49. package/dist/docs/assets/chunks/{mindmap-definition-QFDTVHPH.JyLBD9M8.js → mindmap-definition-QFDTVHPH.DPuIXVWY.js} +1 -1
  50. package/dist/docs/assets/chunks/{pieDiagram-DEJITSTG.DnSmNZF8.js → pieDiagram-DEJITSTG.BOnl3bBg.js} +1 -1
  51. package/dist/docs/assets/chunks/{quadrantDiagram-34T5L4WZ.CUCnbfCa.js → quadrantDiagram-34T5L4WZ.DNB6Ckdc.js} +1 -1
  52. package/dist/docs/assets/chunks/{requirementDiagram-MS252O5E.py0IVUn5.js → requirementDiagram-MS252O5E.D5-Qo7vb.js} +1 -1
  53. package/dist/docs/assets/chunks/{sankeyDiagram-XADWPNL6.Bkc-HWYp.js → sankeyDiagram-XADWPNL6.8t65cesf.js} +1 -1
  54. package/dist/docs/assets/chunks/{sequenceDiagram-FGHM5R23.Dqn8Mlv2.js → sequenceDiagram-FGHM5R23.CaG07BdS.js} +1 -1
  55. package/dist/docs/assets/chunks/{stateDiagram-FHFEXIEX.JikkoQUU.js → stateDiagram-FHFEXIEX.TKOweTB6.js} +1 -1
  56. package/dist/docs/assets/chunks/stateDiagram-v2-QKLJ7IA2.CuqmyQc4.js +1 -0
  57. package/dist/docs/assets/chunks/{theme.b6HQ6zG_.js → theme.Dx-JhpTB.js} +2 -2
  58. package/dist/docs/assets/chunks/{timeline-definition-GMOUNBTQ.BvpSXiBj.js → timeline-definition-GMOUNBTQ.fE53zQ2s.js} +1 -1
  59. package/dist/docs/assets/chunks/{vennDiagram-DHZGUBPP.CU7MVnZx.js → vennDiagram-DHZGUBPP.DJsZZaJg.js} +1 -1
  60. package/dist/docs/assets/chunks/{wardley-RL74JXVD.BKwC4ctG.js → wardley-RL74JXVD.844kyrjl.js} +1 -1
  61. package/dist/docs/assets/chunks/{wardleyDiagram-NUSXRM2D.BfaF6Uhe.js → wardleyDiagram-NUSXRM2D.CMZ-Ru_t.js} +1 -1
  62. package/dist/docs/assets/chunks/{xychartDiagram-5P7HB3ND.Bg5dcpj4.js → xychartDiagram-5P7HB3ND.XXrhBc7a.js} +1 -1
  63. package/dist/docs/assets/{deployment.md.BJ8i7Q6p.js → deployment.md.UhnJIMr-.js} +2 -2
  64. package/dist/docs/assets/{deployment.md.BJ8i7Q6p.lean.js → deployment.md.UhnJIMr-.lean.js} +1 -1
  65. package/dist/docs/assets/{guides_jev.md.BNDm14Gy.js → guides_jev.md.CRcgmjDb.js} +2 -2
  66. package/dist/docs/assets/{guides_jev.md.BNDm14Gy.lean.js → guides_jev.md.CRcgmjDb.lean.js} +1 -1
  67. package/dist/docs/assets/{reference_agent-config.md.DzGI777n.js → reference_agent-config.md.Cj5uBKp4.js} +1 -1
  68. package/dist/docs/assets/{reference_extensions.md.CPPrkWlJ.js → reference_extensions.md.pa2tN-e4.js} +4 -3
  69. package/dist/docs/assets/{reference_extensions.md.CPPrkWlJ.lean.js → reference_extensions.md.pa2tN-e4.lean.js} +1 -1
  70. package/dist/docs/building-with-agents.html +35 -35
  71. package/dist/docs/deployment.html +37 -37
  72. package/dist/docs/deployment.md +4 -1
  73. package/dist/docs/evals.html +35 -35
  74. package/dist/docs/guides/agent-to-agent.html +35 -35
  75. package/dist/docs/guides/bitbucket.html +35 -35
  76. package/dist/docs/guides/cloud-agents.html +35 -35
  77. package/dist/docs/guides/convert-automation.html +35 -35
  78. package/dist/docs/guides/github.html +35 -35
  79. package/dist/docs/guides/gitlab.html +35 -35
  80. package/dist/docs/guides/grokbot-agents.html +35 -35
  81. package/dist/docs/guides/hooks.html +35 -35
  82. package/dist/docs/guides/improve.html +35 -35
  83. package/dist/docs/guides/jev.html +37 -37
  84. package/dist/docs/guides/jev.md +7 -0
  85. package/dist/docs/guides/mcp-oauth.html +35 -35
  86. package/dist/docs/guides/opentelemetry.html +35 -35
  87. package/dist/docs/guides/slack.html +35 -35
  88. package/dist/docs/guides/webhooks.html +35 -35
  89. package/dist/docs/hashmap.json +1 -1
  90. package/dist/docs/hillclimbing.html +35 -35
  91. package/dist/docs/index.html +35 -35
  92. package/dist/docs/llms-full.txt +25 -2
  93. package/dist/docs/quickstart.html +35 -35
  94. package/dist/docs/reference/agent-config.html +37 -37
  95. package/dist/docs/reference/agent-config.md +1 -1
  96. package/dist/docs/reference/artifacts.html +35 -35
  97. package/dist/docs/reference/channels.html +35 -35
  98. package/dist/docs/reference/cli.html +35 -35
  99. package/dist/docs/reference/connections.html +35 -35
  100. package/dist/docs/reference/evals.html +35 -35
  101. package/dist/docs/reference/extensions.html +39 -38
  102. package/dist/docs/reference/extensions.md +13 -0
  103. package/dist/docs/reference/hooks.html +35 -35
  104. package/dist/docs/reference/http-api.html +35 -35
  105. package/dist/docs/reference/instructions.html +35 -35
  106. package/dist/docs/reference/playground.html +35 -35
  107. package/dist/docs/reference/project-layout.html +35 -35
  108. package/dist/docs/reference/prompt.html +35 -35
  109. package/dist/docs/reference/schedules.html +35 -35
  110. package/dist/docs/reference/sessions.html +35 -35
  111. package/dist/docs/reference/skills.html +35 -35
  112. package/dist/docs/reference/subagents.html +35 -35
  113. package/dist/docs/reference/tools.html +35 -35
  114. package/dist/docs/templates/agentic-owners.html +35 -35
  115. package/dist/docs/templates/security-reviewer.html +35 -35
  116. package/dist/docs/templates/thermo-quality-review.html +35 -35
  117. package/dist/docs/templates/thermo-review.html +35 -35
  118. package/dist/docs/templates/triage.html +35 -35
  119. package/dist/docs/troubleshooting.html +35 -35
  120. package/dist/extensions/jev/extension.d.ts +3 -0
  121. package/dist/extensions/jev/extension.d.ts.map +1 -1
  122. package/dist/extensions/jev/extension.js +10 -1
  123. package/dist/extensions/jev/lib/evaluate.d.ts +4 -0
  124. package/dist/extensions/jev/lib/evaluate.d.ts.map +1 -1
  125. package/dist/extensions/jev/lib/evaluate.js +6 -2
  126. package/dist/extensions.d.ts +4 -2
  127. package/dist/extensions.d.ts.map +1 -1
  128. package/dist/extensions.js +5 -2
  129. package/dist/internal/cli-deploy.d.ts.map +1 -1
  130. package/dist/internal/cli-deploy.js +19 -5
  131. package/dist/internal/discovery/agent-config.d.ts +6 -5
  132. package/dist/internal/discovery/agent-config.d.ts.map +1 -1
  133. package/dist/internal/discovery/agent-config.js +29 -28
  134. package/dist/internal/discovery/agent.js +1 -1
  135. package/dist/internal/discovery/extensions.d.ts.map +1 -1
  136. package/dist/internal/discovery/extensions.js +12 -0
  137. package/dist/internal/hosting.d.ts +8 -0
  138. package/dist/internal/hosting.d.ts.map +1 -1
  139. package/dist/internal/hosting.js +24 -0
  140. package/dist/types.d.ts +18 -2
  141. package/dist/types.d.ts.map +1 -1
  142. package/docs/deployment.md +4 -1
  143. package/docs/guides/jev.md +7 -0
  144. package/docs/reference/agent-config.md +1 -1
  145. package/docs/reference/extensions.md +13 -0
  146. package/package.json +1 -9
  147. package/dist/docs/assets/chunks/@localSearchIndexroot.D5L-b34G.js +0 -1
  148. package/dist/docs/assets/chunks/channel.BbOGaJQP.js +0 -1
  149. package/dist/docs/assets/chunks/classDiagram-6PBFFD2Q.Db58HCb1.js +0 -1
  150. package/dist/docs/assets/chunks/classDiagram-v2-HSJHXN6E.Db58HCb1.js +0 -1
  151. package/dist/docs/assets/chunks/clone.Co4MBflG.js +0 -1
  152. package/dist/docs/assets/chunks/stateDiagram-v2-QKLJ7IA2.CMsKhrW0.js +0 -1
  153. package/src/artifacts.ts +0 -68
  154. package/src/bin/agent-serve.ts +0 -1854
  155. package/src/channels/bitbucket/api.ts +0 -891
  156. package/src/channels/bitbucket/binding.ts +0 -417
  157. package/src/channels/bitbucket/bitbucket-channel.ts +0 -162
  158. package/src/channels/bitbucket/bitbucket-webhook.ts +0 -519
  159. package/src/channels/bitbucket/checks.ts +0 -146
  160. package/src/channels/bitbucket/cursor-account.ts +0 -106
  161. package/src/channels/bitbucket/defaults.ts +0 -100
  162. package/src/channels/bitbucket/events.ts +0 -74
  163. package/src/channels/bitbucket/index.ts +0 -51
  164. package/src/channels/bitbucket/replay.ts +0 -421
  165. package/src/channels/bitbucket/state.ts +0 -59
  166. package/src/channels/bitbucket/types.ts +0 -261
  167. package/src/channels/change-monitors/change-monitors-channel.ts +0 -63
  168. package/src/channels/change-monitors/index.ts +0 -8
  169. package/src/channels/change-monitors/types.ts +0 -42
  170. package/src/channels/checks.ts +0 -185
  171. package/src/channels/deployments/deployments-channel.ts +0 -224
  172. package/src/channels/deployments/index.ts +0 -25
  173. package/src/channels/deployments/types.ts +0 -92
  174. package/src/channels/github/api.ts +0 -526
  175. package/src/channels/github/auth.ts +0 -293
  176. package/src/channels/github/binding.ts +0 -233
  177. package/src/channels/github/checks.ts +0 -145
  178. package/src/channels/github/cursor-account.ts +0 -303
  179. package/src/channels/github/defaults.ts +0 -168
  180. package/src/channels/github/events.ts +0 -67
  181. package/src/channels/github/forward.ts +0 -359
  182. package/src/channels/github/github-channel.ts +0 -2334
  183. package/src/channels/github/index.ts +0 -54
  184. package/src/channels/github/progress.ts +0 -365
  185. package/src/channels/github/replay.ts +0 -372
  186. package/src/channels/github/state.ts +0 -124
  187. package/src/channels/github/types.ts +0 -590
  188. package/src/channels/gitlab/api.ts +0 -329
  189. package/src/channels/gitlab/binding.ts +0 -231
  190. package/src/channels/gitlab/checks.ts +0 -228
  191. package/src/channels/gitlab/cursor-account.ts +0 -105
  192. package/src/channels/gitlab/defaults.ts +0 -80
  193. package/src/channels/gitlab/events.ts +0 -37
  194. package/src/channels/gitlab/gitlab-channel.ts +0 -160
  195. package/src/channels/gitlab/gitlab-webhook.ts +0 -509
  196. package/src/channels/gitlab/index.ts +0 -44
  197. package/src/channels/gitlab/replay.ts +0 -328
  198. package/src/channels/gitlab/state.ts +0 -55
  199. package/src/channels/gitlab/types.ts +0 -247
  200. package/src/channels/issues/index.ts +0 -9
  201. package/src/channels/issues/issues-channel.ts +0 -45
  202. package/src/channels/issues/types.ts +0 -38
  203. package/src/channels/origin/api.ts +0 -507
  204. package/src/channels/origin/binding.ts +0 -114
  205. package/src/channels/origin/checks.ts +0 -250
  206. package/src/channels/origin/cursor-account.ts +0 -58
  207. package/src/channels/origin/defaults.ts +0 -140
  208. package/src/channels/origin/events.ts +0 -35
  209. package/src/channels/origin/index.ts +0 -35
  210. package/src/channels/origin/origin-channel.ts +0 -815
  211. package/src/channels/origin/origin-webhook.ts +0 -296
  212. package/src/channels/origin/reactions.ts +0 -72
  213. package/src/channels/origin/state.ts +0 -54
  214. package/src/channels/origin/types.ts +0 -295
  215. package/src/channels/slack/agentic-delivery.ts +0 -634
  216. package/src/channels/slack/agentic-posted.ts +0 -135
  217. package/src/channels/slack/agentic-signals.ts +0 -231
  218. package/src/channels/slack/api.ts +0 -761
  219. package/src/channels/slack/approvals.ts +0 -279
  220. package/src/channels/slack/assistant.ts +0 -76
  221. package/src/channels/slack/attachments.ts +0 -596
  222. package/src/channels/slack/auth.ts +0 -127
  223. package/src/channels/slack/blocks.ts +0 -131
  224. package/src/channels/slack/bot-mentions.ts +0 -318
  225. package/src/channels/slack/channel-watch.ts +0 -314
  226. package/src/channels/slack/cli-project.ts +0 -249
  227. package/src/channels/slack/code-fences.ts +0 -171
  228. package/src/channels/slack/constants.ts +0 -38
  229. package/src/channels/slack/credentials.ts +0 -88
  230. package/src/channels/slack/defaults.ts +0 -714
  231. package/src/channels/slack/dispatch.ts +0 -1060
  232. package/src/channels/slack/doctor.ts +0 -338
  233. package/src/channels/slack/eval-directive.ts +0 -306
  234. package/src/channels/slack/event-id-dedupe.ts +0 -30
  235. package/src/channels/slack/external-policy.ts +0 -75
  236. package/src/channels/slack/footer.ts +0 -106
  237. package/src/channels/slack/inbound.ts +0 -416
  238. package/src/channels/slack/index.ts +0 -53
  239. package/src/channels/slack/init.ts +0 -169
  240. package/src/channels/slack/interactive.ts +0 -406
  241. package/src/channels/slack/links.ts +0 -23
  242. package/src/channels/slack/live-delivery.ts +0 -489
  243. package/src/channels/slack/log.ts +0 -70
  244. package/src/channels/slack/manifest.ts +0 -240
  245. package/src/channels/slack/message-body.ts +0 -82
  246. package/src/channels/slack/nudge-carrier.ts +0 -224
  247. package/src/channels/slack/nudge-store.ts +0 -334
  248. package/src/channels/slack/paint-start.ts +0 -93
  249. package/src/channels/slack/placeholder.ts +0 -358
  250. package/src/channels/slack/pr-ref.ts +0 -74
  251. package/src/channels/slack/progress-delivery.ts +0 -138
  252. package/src/channels/slack/reasoning-card.ts +0 -125
  253. package/src/channels/slack/reasoning-chip.ts +0 -41
  254. package/src/channels/slack/recording-sink.ts +0 -167
  255. package/src/channels/slack/redact.ts +0 -6
  256. package/src/channels/slack/reply-options.ts +0 -279
  257. package/src/channels/slack/setup.ts +0 -125
  258. package/src/channels/slack/slack-channel.ts +0 -744
  259. package/src/channels/slack/socket-mode.ts +0 -140
  260. package/src/channels/slack/stop.ts +0 -25
  261. package/src/channels/slack/stream.ts +0 -66
  262. package/src/channels/slack/thread-context.ts +0 -485
  263. package/src/channels/slack/tool-approval-events.ts +0 -233
  264. package/src/channels/slack/tool-cards.ts +0 -198
  265. package/src/channels/slack/tool-chip.ts +0 -34
  266. package/src/channels/slack/types.ts +0 -787
  267. package/src/channels/slack/upload.ts +0 -137
  268. package/src/channels.ts +0 -543
  269. package/src/connections.ts +0 -153
  270. package/src/dashboard-session-url.ts +0 -30
  271. package/src/evals/assertions.ts +0 -688
  272. package/src/evals/expect.ts +0 -250
  273. package/src/evals/judge.ts +0 -329
  274. package/src/evals/loaders.ts +0 -111
  275. package/src/evals/matchers.ts +0 -223
  276. package/src/evals/reporters.ts +0 -257
  277. package/src/evals/results.ts +0 -130
  278. package/src/evals/run-facts.ts +0 -306
  279. package/src/evals.ts +0 -709
  280. package/src/extensions/cursor-cloud-agents/extension.ts +0 -131
  281. package/src/extensions/cursor-cloud-agents/lib/backend.ts +0 -386
  282. package/src/extensions/cursor-cloud-agents/lib/channels.ts +0 -11
  283. package/src/extensions/cursor-cloud-agents/lib/fleet.ts +0 -98
  284. package/src/extensions/cursor-cloud-agents/lib/inputs.ts +0 -5
  285. package/src/extensions/cursor-cloud-agents/lib/repos.ts +0 -80
  286. package/src/extensions/cursor-cloud-agents/lib/transcript.ts +0 -19
  287. package/src/extensions/cursor-cloud-agents/skills/handoff.md +0 -37
  288. package/src/extensions/cursor-cloud-agents/tools/cancel.ts +0 -21
  289. package/src/extensions/cursor-cloud-agents/tools/dump.ts +0 -47
  290. package/src/extensions/cursor-cloud-agents/tools/get.ts +0 -18
  291. package/src/extensions/cursor-cloud-agents/tools/launch.ts +0 -62
  292. package/src/extensions/cursor-cloud-agents/tools/list.ts +0 -31
  293. package/src/extensions/cursor-cloud-agents/tools/reply.ts +0 -36
  294. package/src/extensions/cursor-grokbot-agents/extension.ts +0 -132
  295. package/src/extensions/cursor-grokbot-agents/lib/agents.ts +0 -42
  296. package/src/extensions/cursor-grokbot-agents/lib/backend.ts +0 -208
  297. package/src/extensions/cursor-grokbot-agents/lib/contacts.ts +0 -74
  298. package/src/extensions/cursor-grokbot-agents/lib/conversation.ts +0 -260
  299. package/src/extensions/cursor-grokbot-agents/lib/inputs.ts +0 -21
  300. package/src/extensions/cursor-grokbot-agents/lib/lock.ts +0 -26
  301. package/src/extensions/cursor-grokbot-agents/skills/consult.md +0 -40
  302. package/src/extensions/cursor-grokbot-agents/tools/ask.ts +0 -32
  303. package/src/extensions/cursor-grokbot-agents/tools/check.ts +0 -25
  304. package/src/extensions/cursor-grokbot-agents/tools/interrupt.ts +0 -17
  305. package/src/extensions/cursor-grokbot-agents/tools/list.ts +0 -26
  306. package/src/extensions/improve/extension.ts +0 -69
  307. package/src/extensions/improve/skills/yourself.ts +0 -50
  308. package/src/extensions/jev/extension.ts +0 -95
  309. package/src/extensions/jev/lib/evaluate.ts +0 -266
  310. package/src/extensions/jev/skills/gated-write.md +0 -25
  311. package/src/extensions/jev/skills/questions.md +0 -33
  312. package/src/extensions/jev/tools/evaluate.ts +0 -82
  313. package/src/extensions/slack-communication/evals/harness.ts +0 -705
  314. package/src/extensions/slack-communication/evals/slack-communication.eval.ts +0 -830
  315. package/src/extensions/slack-communication/evals/slack-placeholder.eval.ts +0 -172
  316. package/src/extensions/slack-communication/extension.ts +0 -44
  317. package/src/extensions/slack-communication/skills/slack-voice.ts +0 -56
  318. package/src/extensions/slack-communication/tools/delete-message.ts +0 -33
  319. package/src/extensions/slack-communication/tools/edit-message.ts +0 -42
  320. package/src/extensions/slack-communication/tools/post-card.ts +0 -28
  321. package/src/extensions/slack-communication/tools/post-file.ts +0 -82
  322. package/src/extensions/slack-communication/tools/post-update.ts +0 -40
  323. package/src/extensions/slack-communication/tools/react.ts +0 -30
  324. package/src/extensions/slack-communication/tools/set-status.ts +0 -21
  325. package/src/extensions.ts +0 -179
  326. package/src/files-backends/agent-store-presigned-url.ts +0 -11
  327. package/src/files-backends/cursor-hosted.ts +0 -1212
  328. package/src/files-backends/local-fs.ts +0 -163
  329. package/src/files.ts +0 -293
  330. package/src/filesystem.ts +0 -2005
  331. package/src/hooks.ts +0 -30
  332. package/src/index.ts +0 -259
  333. package/src/internal/advertise-tools.ts +0 -370
  334. package/src/internal/approval-gate.ts +0 -103
  335. package/src/internal/artifacts-store.ts +0 -836
  336. package/src/internal/as-of.ts +0 -257
  337. package/src/internal/auth.ts +0 -46
  338. package/src/internal/authored-alias-hooks.ts +0 -138
  339. package/src/internal/authored-loaders.ts +0 -188
  340. package/src/internal/bounded-int.ts +0 -24
  341. package/src/internal/bounded.ts +0 -25
  342. package/src/internal/brand.ts +0 -28
  343. package/src/internal/browser-origin-guard.ts +0 -67
  344. package/src/internal/builtin-tools/artifacts.ts +0 -62
  345. package/src/internal/builtin-tools/index.ts +0 -53
  346. package/src/internal/builtin-tools/reminders.ts +0 -145
  347. package/src/internal/channel-dispatch.ts +0 -129
  348. package/src/internal/channel-route-dispatch.ts +0 -58
  349. package/src/internal/channel-state.ts +0 -83
  350. package/src/internal/chat-client.ts +0 -594
  351. package/src/internal/cli-ax.ts +0 -2318
  352. package/src/internal/cli-bitbucket.ts +0 -438
  353. package/src/internal/cli-convert-automation.ts +0 -335
  354. package/src/internal/cli-cursor.ts +0 -282
  355. package/src/internal/cli-deploy.ts +0 -2519
  356. package/src/internal/cli-docs.ts +0 -192
  357. package/src/internal/cli-github.ts +0 -806
  358. package/src/internal/cli-gitlab.ts +0 -452
  359. package/src/internal/cli-images.ts +0 -672
  360. package/src/internal/cli-manifest.ts +0 -56
  361. package/src/internal/cli-mcp-oauth.ts +0 -396
  362. package/src/internal/cli-mcp.ts +0 -808
  363. package/src/internal/cli-skills.ts +0 -98
  364. package/src/internal/cli-slack-manual.ts +0 -418
  365. package/src/internal/cli-slack.ts +0 -874
  366. package/src/internal/cloud-merge.ts +0 -51
  367. package/src/internal/cloud-turn-cost.ts +0 -159
  368. package/src/internal/connection-env.ts +0 -106
  369. package/src/internal/continuation-channel.ts +0 -233
  370. package/src/internal/continuation-identity.ts +0 -935
  371. package/src/internal/conversation-mirror.ts +0 -423
  372. package/src/internal/convert-automation/convert-workflow.ts +0 -1377
  373. package/src/internal/convert-automation/slug.ts +0 -29
  374. package/src/internal/convert-automation/types.ts +0 -212
  375. package/src/internal/cron.ts +0 -76
  376. package/src/internal/cursor/account-mcp.ts +0 -692
  377. package/src/internal/cursor/backend-client.ts +0 -984
  378. package/src/internal/cursor/bound-secret-file.ts +0 -101
  379. package/src/internal/cursor/credentials.ts +0 -560
  380. package/src/internal/cursor/cursor-api-transport.ts +0 -65
  381. package/src/internal/cursor/github-credentials.ts +0 -228
  382. package/src/internal/cursor/hosted-bound-secrets.ts +0 -71
  383. package/src/internal/cursor/hosted-deployment-secrets.ts +0 -100
  384. package/src/internal/cursor/hosted-store-secrets.ts +0 -152
  385. package/src/internal/cursor/session-token.ts +0 -111
  386. package/src/internal/cursor/store-api-client.ts +0 -323
  387. package/src/internal/cursor-account-mcp-auth.ts +0 -303
  388. package/src/internal/cursor-agent-template.ts +0 -50
  389. package/src/internal/cursor-deployment-relay.ts +0 -315
  390. package/src/internal/cursor-event-relay.ts +0 -675
  391. package/src/internal/cursor-relay-core.ts +0 -563
  392. package/src/internal/deferred-channel-session.ts +0 -61
  393. package/src/internal/deploy-client.ts +0 -1574
  394. package/src/internal/deploy-manifest.ts +0 -361
  395. package/src/internal/deploy-source.ts +0 -144
  396. package/src/internal/describe-error.ts +0 -32
  397. package/src/internal/dev-mode.ts +0 -20
  398. package/src/internal/discovery/agent-config.ts +0 -288
  399. package/src/internal/discovery/agent.ts +0 -381
  400. package/src/internal/discovery/channels.ts +0 -100
  401. package/src/internal/discovery/connections.ts +0 -516
  402. package/src/internal/discovery/context.ts +0 -38
  403. package/src/internal/discovery/cursor-plugin.ts +0 -628
  404. package/src/internal/discovery/extension-overlay.ts +0 -247
  405. package/src/internal/discovery/extensions.ts +0 -490
  406. package/src/internal/discovery/fs.ts +0 -103
  407. package/src/internal/discovery/hooks.ts +0 -63
  408. package/src/internal/discovery/info.ts +0 -174
  409. package/src/internal/discovery/instructions.ts +0 -98
  410. package/src/internal/discovery/modules.ts +0 -107
  411. package/src/internal/discovery/names.ts +0 -45
  412. package/src/internal/discovery/project.ts +0 -319
  413. package/src/internal/discovery/reminders.ts +0 -65
  414. package/src/internal/discovery/runtime.ts +0 -158
  415. package/src/internal/discovery/schedules.ts +0 -120
  416. package/src/internal/discovery/seed-files.ts +0 -34
  417. package/src/internal/discovery/services.ts +0 -151
  418. package/src/internal/discovery/skills.ts +0 -174
  419. package/src/internal/discovery/subagent.ts +0 -138
  420. package/src/internal/discovery/tools.ts +0 -170
  421. package/src/internal/discovery.ts +0 -27
  422. package/src/internal/distribution.ts +0 -126
  423. package/src/internal/docs-site.ts +0 -248
  424. package/src/internal/duration.ts +0 -37
  425. package/src/internal/env-file.ts +0 -83
  426. package/src/internal/eval-judge-model.ts +0 -142
  427. package/src/internal/eval-run-store.ts +0 -585
  428. package/src/internal/eval-runner.ts +0 -823
  429. package/src/internal/evals-client.ts +0 -475
  430. package/src/internal/event-log.ts +0 -342
  431. package/src/internal/event-mapper.ts +0 -811
  432. package/src/internal/expected-delivery-failure.ts +0 -34
  433. package/src/internal/factory-resource-channel.ts +0 -103
  434. package/src/internal/filesystem/errors.ts +0 -207
  435. package/src/internal/filesystem/format.ts +0 -253
  436. package/src/internal/filesystem/merge.ts +0 -192
  437. package/src/internal/filesystem/nearest.ts +0 -112
  438. package/src/internal/filesystem/scratch.ts +0 -239
  439. package/src/internal/filesystem/sdk-schemas.ts +0 -204
  440. package/src/internal/filesystem/tools.ts +0 -804
  441. package/src/internal/filesystem/walk.ts +0 -366
  442. package/src/internal/fixtures/units-server.ts +0 -52
  443. package/src/internal/framework-file-storage.ts +0 -357
  444. package/src/internal/framework-storage-selection.ts +0 -156
  445. package/src/internal/frontmatter.ts +0 -108
  446. package/src/internal/github-fanout.ts +0 -144
  447. package/src/internal/guest-network.ts +0 -391
  448. package/src/internal/handleAgentServeTrigger.ts +0 -286
  449. package/src/internal/host-files.ts +0 -341
  450. package/src/internal/host-kv.ts +0 -81
  451. package/src/internal/host-otel.ts +0 -231
  452. package/src/internal/host-platforms.ts +0 -170
  453. package/src/internal/hosted-admission-adapter.ts +0 -47
  454. package/src/internal/hosted-admission-context.ts +0 -37
  455. package/src/internal/hosted-catch-protocol.ts +0 -112
  456. package/src/internal/hosted-catch.ts +0 -179
  457. package/src/internal/hosted-delivery-protocol.ts +0 -824
  458. package/src/internal/hosted-delivery.ts +0 -1410
  459. package/src/internal/hosted-execution-diag.ts +0 -291
  460. package/src/internal/hosted-execution-flush.ts +0 -136
  461. package/src/internal/hosted-execution-latency.ts +0 -301
  462. package/src/internal/hosted-managed-automation.ts +0 -116
  463. package/src/internal/hosting.ts +0 -114
  464. package/src/internal/http-channel-define.ts +0 -25
  465. package/src/internal/http-channel.ts +0 -669
  466. package/src/internal/http-control-plane-session.ts +0 -110
  467. package/src/internal/ids.ts +0 -39
  468. package/src/internal/incoming-headers-to-fetch.ts +0 -45
  469. package/src/internal/init-interview.ts +0 -360
  470. package/src/internal/init-project.ts +0 -711
  471. package/src/internal/init-scaffold.ts +0 -182
  472. package/src/internal/inline-stdio-define-stub.ts +0 -4
  473. package/src/internal/inline-stdio-mcp.ts +0 -230
  474. package/src/internal/install-cursor-skills.ts +0 -604
  475. package/src/internal/is-record.ts +0 -3
  476. package/src/internal/json-schema.ts +0 -95
  477. package/src/internal/legacy-command-guard.ts +0 -66
  478. package/src/internal/listen-port.ts +0 -85
  479. package/src/internal/local-control-plane.ts +0 -442
  480. package/src/internal/local-env.ts +0 -59
  481. package/src/internal/local-ingress.ts +0 -90
  482. package/src/internal/log-ring.ts +0 -59
  483. package/src/internal/logs-client.ts +0 -477
  484. package/src/internal/map-pool.ts +0 -39
  485. package/src/internal/mcp-endpoint.ts +0 -747
  486. package/src/internal/mcp-host.ts +0 -509
  487. package/src/internal/mcp-oauth-on-demand.ts +0 -337
  488. package/src/internal/mcp-oauth-persist.ts +0 -118
  489. package/src/internal/mcp-oauth.ts +0 -549
  490. package/src/internal/net.ts +0 -29
  491. package/src/internal/open-browser.ts +0 -41
  492. package/src/internal/otel/attrs.ts +0 -16
  493. package/src/internal/otel/collector.ts +0 -937
  494. package/src/internal/otel/config.ts +0 -287
  495. package/src/internal/otel/http.ts +0 -122
  496. package/src/internal/otel/mcp.ts +0 -56
  497. package/src/internal/otel/propagation.ts +0 -17
  498. package/src/internal/otel/runtime.ts +0 -441
  499. package/src/internal/package-inline-stdio.ts +0 -114
  500. package/src/internal/peer-connections.ts +0 -96
  501. package/src/internal/platform-schedule-sync.ts +0 -75
  502. package/src/internal/platform-timers.ts +0 -365
  503. package/src/internal/playground/static.ts +0 -278
  504. package/src/internal/playground/toolchain.ts +0 -270
  505. package/src/internal/playground-proxy.ts +0 -564
  506. package/src/internal/process-memory-telemetry.ts +0 -334
  507. package/src/internal/project-layout.ts +0 -31
  508. package/src/internal/prompt-context.ts +0 -116
  509. package/src/internal/reminder-control-plane-protocol.ts +0 -482
  510. package/src/internal/reminder-runner.ts +0 -1559
  511. package/src/internal/reminder-schedule.ts +0 -104
  512. package/src/internal/reminder-store.ts +0 -176
  513. package/src/internal/request-error-status.ts +0 -95
  514. package/src/internal/request-headers.ts +0 -21
  515. package/src/internal/resolve-prod-target.ts +0 -334
  516. package/src/internal/resolved-connections.ts +0 -190
  517. package/src/internal/router.ts +0 -143
  518. package/src/internal/run-client.ts +0 -354
  519. package/src/internal/runtime-dispatch-runner.ts +0 -50
  520. package/src/internal/sanitize-mcp-tool-name.ts +0 -31
  521. package/src/internal/schedule-runner.ts +0 -154
  522. package/src/internal/scm/pr-url.ts +0 -245
  523. package/src/internal/sdk-runner.ts +0 -959
  524. package/src/internal/serve-restart.ts +0 -113
  525. package/src/internal/server.ts +0 -3147
  526. package/src/internal/session-cost.ts +0 -208
  527. package/src/internal/session-engine.ts +0 -5622
  528. package/src/internal/session-links.ts +0 -84
  529. package/src/internal/session-run-log.ts +0 -535
  530. package/src/internal/session-store.ts +0 -307
  531. package/src/internal/session-urls.ts +0 -32
  532. package/src/internal/sessions-client.ts +0 -239
  533. package/src/internal/skill-catalog.ts +0 -66
  534. package/src/internal/skills-sync.ts +0 -55
  535. package/src/internal/slack-provision-client.ts +0 -544
  536. package/src/internal/slack-thread-key.ts +0 -11
  537. package/src/internal/sleep.ts +0 -3
  538. package/src/internal/start-log-store.ts +0 -164
  539. package/src/internal/steering.ts +0 -17
  540. package/src/internal/storage-coordinator.ts +0 -800
  541. package/src/internal/storage-roles.ts +0 -86
  542. package/src/internal/storage.ts +0 -1
  543. package/src/internal/store-api-protocol.ts +0 -205
  544. package/src/internal/store-mirror.ts +0 -73
  545. package/src/internal/stream-progress.ts +0 -294
  546. package/src/internal/terminal-style.ts +0 -133
  547. package/src/internal/testing/factory-resource-fixtures.ts +0 -84
  548. package/src/internal/testing/scm-continuation-fixtures.ts +0 -285
  549. package/src/internal/tool-catalog.ts +0 -104
  550. package/src/internal/tool-policy.ts +0 -222
  551. package/src/internal/tool-result.ts +0 -50
  552. package/src/internal/trajectory.ts +0 -418
  553. package/src/internal/turn-cost.ts +0 -136
  554. package/src/internal/turn-governor.ts +0 -145
  555. package/src/internal/turn-lease-store.ts +0 -144
  556. package/src/internal/turn-outbox.ts +0 -77
  557. package/src/internal/update-check.ts +0 -517
  558. package/src/internal/v2-hosting.ts +0 -52
  559. package/src/internal/workspace-sync.ts +0 -114
  560. package/src/internal/workspace.ts +0 -505
  561. package/src/kv/memory-kv.ts +0 -94
  562. package/src/kv.ts +0 -18
  563. package/src/memory.ts +0 -487
  564. package/src/otel-public.ts +0 -24
  565. package/src/otel.ts +0 -320
  566. package/src/prompt.ts +0 -80
  567. package/src/reminders.ts +0 -65
  568. package/src/schedules.ts +0 -31
  569. package/src/skills.ts +0 -27
  570. package/src/storage-backends/cursor-hosted-v2.ts +0 -204
  571. package/src/storage-backends/cursor-hosted.ts +0 -388
  572. package/src/storage-backends/file-kv.ts +0 -276
  573. package/src/storage-protocol.ts +0 -261
  574. package/src/storage.ts +0 -408
  575. package/src/tools.ts +0 -166
  576. package/src/types.ts +0 -3776
  577. /package/dist/docs/assets/{reference_agent-config.md.DzGI777n.lean.js → reference_agent-config.md.Cj5uBKp4.lean.js} +0 -0
@@ -1,2334 +0,0 @@
1
- import { createHmac, timingSafeEqual } from "node:crypto";
2
- import { z } from "zod";
3
- import {
4
- allowAll,
5
- defineChannel,
6
- localDevStrict,
7
- loopbackGitHubDev,
8
- POST,
9
- } from "../../channels.js";
10
- import {
11
- acknowledgeTask,
12
- acknowledgeTurn,
13
- isTaskDispatch,
14
- scheduleAfterAck,
15
- skipped,
16
- turnStarted,
17
- withPropagatingBackgroundErrors,
18
- } from "../../internal/channel-dispatch.js";
19
- import { continuationSource, normalizeIdentity } from "../../internal/continuation-identity.js";
20
- import { isDevMode } from "../../internal/dev-mode.js";
21
- import { attachHostedAdmissionAdapter } from "../../internal/hosted-admission-adapter.js";
22
- import { bindLocalIngressSend } from "../../internal/local-ingress.js";
23
- import type {
24
- AgentCloudOptions,
25
- ArtifactsApi,
26
- AuthContext,
27
- ChannelDefinition,
28
- ChannelEventHandlers,
29
- ChannelHandlerArgs,
30
- HostContext,
31
- JsonValue,
32
- SendMessageFn,
33
- } from "../../types.js";
34
- import { resolveCredentialValue } from "./auth.js";
35
- import {
36
- buildGitHubBinding,
37
- type GitHubBindingConfig,
38
- type GitHubBindingState,
39
- } from "./binding.js";
40
- import {
41
- createCursorAccountGithubTokenResolver,
42
- createPendingCursorGithubCredentials,
43
- cursorGithubPermissionsForChannel,
44
- type PendingCursorGithubCredentials,
45
- parseCursorGithubRepoScope,
46
- registerGithubCursorAccountRuntime,
47
- } from "./cursor-account.js";
48
- import { buildDefaultGitHubEvents } from "./defaults.js";
49
- import { deriveGitHubWebhookEvents, GITHUB_CHANNEL_KIND } from "./events.js";
50
- import {
51
- emptyGitHubChannelState,
52
- type GitHubChannelState,
53
- githubBindingStateForEvent,
54
- } from "./state.js";
55
- import type {
56
- GitHubChannelOptions,
57
- GitHubCheckRunEvent,
58
- GitHubCheckSuiteEvent,
59
- GitHubCiAppRef,
60
- GitHubCiPullRequestRef,
61
- GitHubComment,
62
- GitHubConversationKind,
63
- GitHubCredentialValue,
64
- GitHubEventContext,
65
- GitHubIssueEvent,
66
- GitHubPullRequestAction,
67
- GitHubPullRequestEvent,
68
- GitHubPullRequestPayload,
69
- GitHubRawEvent,
70
- GitHubRepositoryRef,
71
- GitHubStatusEvent,
72
- GitHubTurnDispatch,
73
- GitHubUser,
74
- GitHubWorkflowRunEvent,
75
- } from "./types.js";
76
-
77
- /**
78
- * Inbound context as produced by the payload parsers, before the GitHub API +
79
- * thread handles are attached. {@link enrichEventContext} adds `github`,
80
- * `thread`, and `host` to make a full {@link GitHubEventContext} for hooks.
81
- */
82
- type GitHubParsedContext = Omit<
83
- GitHubEventContext,
84
- "github" | "thread" | "host" | "artifacts" | "payload"
85
- >;
86
-
87
- const DEFAULT_PULL_REQUEST_ACTIONS: ReadonlySet<string> = new Set([
88
- "opened",
89
- "reopened",
90
- "synchronize",
91
- "ready_for_review",
92
- ]);
93
-
94
- const repositorySchema = z.object({
95
- id: z.number().optional(),
96
- full_name: z.string().min(1),
97
- html_url: z.string().url(),
98
- name: z.string().optional(),
99
- owner: z
100
- .object({
101
- login: z.string().optional(),
102
- })
103
- .optional(),
104
- });
105
-
106
- const senderSchema = z
107
- .object({
108
- login: z.string().min(1).optional(),
109
- id: z.number().optional(),
110
- type: z.string().optional(),
111
- })
112
- .nullable()
113
- .optional();
114
-
115
- const installationSchema = z
116
- .object({
117
- id: z.number().optional(),
118
- })
119
- .nullable()
120
- .optional();
121
-
122
- const githubPullRequestPayloadSchema: z.ZodType<GitHubPullRequestPayload> = z.object({
123
- action: z.string().min(1),
124
- repository: repositorySchema,
125
- pull_request: z.object({
126
- number: z.number().int().positive(),
127
- html_url: z.string().url(),
128
- title: z.string(),
129
- body: z.string().nullable().optional(),
130
- draft: z.boolean().optional(),
131
- merged: z.boolean().optional(),
132
- user: z
133
- .object({
134
- login: z.string().min(1).optional(),
135
- id: z.number().optional(),
136
- type: z.string().optional(),
137
- })
138
- .nullable()
139
- .optional(),
140
- head: z.object({
141
- ref: z.string().min(1),
142
- sha: z.string().min(1),
143
- }),
144
- base: z.object({
145
- ref: z.string().min(1),
146
- sha: z.string().optional(),
147
- }),
148
- }),
149
- changes: z
150
- .object({
151
- base: z
152
- .object({
153
- ref: z.object({ from: z.string().min(1).optional() }).optional(),
154
- })
155
- .optional(),
156
- })
157
- .nullable()
158
- .optional(),
159
- sender: senderSchema,
160
- installation: installationSchema,
161
- label: z
162
- .object({
163
- name: z.string().min(1),
164
- })
165
- .nullable()
166
- .optional(),
167
- });
168
-
169
- /**
170
- * Derive the turn's auth from the actor that triggered the delivery — the
171
- * standard `{ auth: defaultGitHubAuth(ctx) }` dispatch from an inbound hook.
172
- */
173
- export function defaultGitHubAuth(ctx: GitHubParsedContext): AuthContext {
174
- const senderId = ctx.sender?.id;
175
- return {
176
- authenticator: "github-webhook",
177
- principalId: senderId !== undefined ? `github:${senderId}` : (ctx.senderLogin ?? "github"),
178
- principalType: ctx.sender?.type === "Bot" ? "service" : "user",
179
- attributes: {
180
- conversation_kind: ctx.conversation.kind,
181
- ...(ctx.deliveryId === undefined ? {} : { delivery_id: ctx.deliveryId }),
182
- ...(ctx.installationId === undefined ? {} : { installation_id: String(ctx.installationId) }),
183
- repository: ctx.repository.fullName,
184
- ...(ctx.repository.id === undefined ? {} : { repository_id: String(ctx.repository.id) }),
185
- ...(ctx.senderLogin === undefined ? {} : { user_login: ctx.senderLogin }),
186
- ...(ctx.sender?.type === undefined ? {} : { user_type: ctx.sender.type }),
187
- ...(ctx.repository.owner === "" ? {} : { issuer: `github:${ctx.repository.owner}` }),
188
- ...(ctx.senderLogin === undefined ? {} : { subject: ctx.senderLogin }),
189
- },
190
- };
191
- }
192
-
193
- export function githubContinuationKey(ctx: GitHubParsedContext): string {
194
- const kind = ctx.conversation.kind === "issue" ? "github-issue" : "github-pr";
195
- return `${kind}:${ctx.repository.fullName}#${ctx.conversation.number}`;
196
- }
197
-
198
- export interface GitHubPullRequestRef {
199
- owner: string;
200
- repo: string;
201
- number: number;
202
- }
203
-
204
- /**
205
- * Parse a pull-request continuation key minted by
206
- * {@link githubContinuationKey} back into its repo + number. Undefined for
207
- * issue keys and non-GitHub sessions — lets a server tool recover which PR
208
- * its session is pinned to without trusting model-provided identifiers.
209
- */
210
- export function parseGitHubPrContinuationKey(key: string): GitHubPullRequestRef | undefined {
211
- const match = /^github-pr:([^/#\s]+)\/([^#\s]+)#(\d+)$/.exec(key);
212
- if (match === null) {
213
- return undefined;
214
- }
215
- return {
216
- owner: match[1]!,
217
- repo: match[2]!,
218
- number: Number(match[3]!),
219
- };
220
- }
221
-
222
- export function defaultGitHubTitle(ctx: GitHubParsedContext): string {
223
- return `GitHub ${ctx.repository.fullName}#${ctx.conversation.number}`;
224
- }
225
-
226
- export function defaultGitHubPullRequestMessage(
227
- ctx: GitHubParsedContext,
228
- pullRequest: GitHubPullRequestEvent,
229
- ): string {
230
- return [
231
- `GitHub pull request trigger: ${ctx.repository.fullName}#${pullRequest.number}`,
232
- `Action: ${pullRequest.action}`,
233
- `PR: ${pullRequest.url}`,
234
- `Title: ${pullRequest.title}`,
235
- `Head: ${pullRequest.headRef} (${pullRequest.headSha})`,
236
- `Base: ${pullRequest.baseRef}`,
237
- ...(pullRequest.authorLogin === undefined ? [] : [`Author: ${pullRequest.authorLogin}`]),
238
- ...(ctx.senderLogin === undefined ? [] : [`Sender: ${ctx.senderLogin}`]),
239
- "",
240
- "Handle this pull request event.",
241
- ].join("\n");
242
- }
243
-
244
- /**
245
- * Default dispatch gate when no `onPullRequest` hook is declared: the common
246
- * review triggers start a turn as the delivery's actor.
247
- *
248
- * Eve has no default for `onPullRequest` (opt-in only). Agent-serve keeps this
249
- * gate for backward compatibility with existing demos.
250
- */
251
- export function defaultGitHubPullRequestDispatch(
252
- ctx: GitHubParsedContext,
253
- pullRequest: GitHubPullRequestEvent,
254
- ): GitHubTurnDispatch | null {
255
- if (!DEFAULT_PULL_REQUEST_ACTIONS.has(pullRequest.action)) {
256
- return null;
257
- }
258
- return { auth: defaultGitHubAuth(ctx) };
259
- }
260
-
261
- /**
262
- * Default comment hook (Eve-compatible): dispatch only when the comment
263
- * `@mention`s {@link botName}.
264
- */
265
- export function defaultOnComment(
266
- ctx: GitHubParsedContext,
267
- comment: GitHubComment,
268
- options: { botName?: string },
269
- ): GitHubTurnDispatch | null {
270
- if (
271
- !shouldDispatchGitHubComment({
272
- body: comment.body,
273
- author: comment.author,
274
- botName: options.botName,
275
- })
276
- ) {
277
- return null;
278
- }
279
- return { auth: defaultGitHubAuth(ctx) };
280
- }
281
-
282
- export function shouldDispatchGitHubComment(args: {
283
- body: string;
284
- author?: GitHubUser;
285
- botName?: string;
286
- }): boolean {
287
- const botName = args.botName?.trim();
288
- if (botName === undefined || botName === "") {
289
- return false;
290
- }
291
- if (isGitHubAppBotAuthor(args.author, botName)) {
292
- return false;
293
- }
294
- const mention = new RegExp(`(^|\\W)@${escapeRegExp(botName)}\\b`, "i");
295
- return mention.test(args.body);
296
- }
297
-
298
- export function extractGitHubCommentTrigger(args: {
299
- body: string;
300
- botName?: string;
301
- }): { message: string } | undefined {
302
- const botName = args.botName?.trim();
303
- if (botName === undefined || botName === "") {
304
- const trimmed = args.body.trim();
305
- return trimmed === "" ? undefined : { message: trimmed };
306
- }
307
- const mention = new RegExp(`@${escapeRegExp(botName)}\\b[,:]?\\s*`, "i");
308
- const stripped = args.body.replace(mention, "").trim();
309
- if (stripped === "") {
310
- return { message: args.body.trim() };
311
- }
312
- return { message: stripped };
313
- }
314
-
315
- export function parseGitHubPullRequestEvent(args: {
316
- payload: unknown;
317
- deliveryId?: string;
318
- }): { ctx: GitHubParsedContext; pullRequest: GitHubPullRequestEvent } | null {
319
- const parsed = githubPullRequestPayloadSchema.safeParse(args.payload);
320
- if (!parsed.success) {
321
- return null;
322
- }
323
- const payload = parsed.data;
324
- const repository = toRepositoryRef(payload.repository);
325
- const sender = toUser(payload.sender);
326
- const installationId = payload.installation?.id;
327
- const ctx: GitHubParsedContext = {
328
- ...(args.deliveryId === undefined ? {} : { deliveryId: args.deliveryId }),
329
- eventName: "pull_request",
330
- repository,
331
- conversation: {
332
- kind: "pull_request",
333
- number: payload.pull_request.number,
334
- url: payload.pull_request.html_url,
335
- },
336
- ...(sender === undefined ? {} : { sender, senderLogin: sender.login }),
337
- ...(installationId === undefined ? {} : { installationId }),
338
- };
339
- const pullRequest: GitHubPullRequestEvent = {
340
- action: payload.action as GitHubPullRequestAction,
341
- number: payload.pull_request.number,
342
- url: payload.pull_request.html_url,
343
- title: payload.pull_request.title,
344
- ...(payload.pull_request.body === undefined || payload.pull_request.body === null
345
- ? {}
346
- : { body: payload.pull_request.body }),
347
- headRef: payload.pull_request.head.ref,
348
- headSha: payload.pull_request.head.sha,
349
- baseRef: payload.pull_request.base.ref,
350
- ...(payload.pull_request.base.sha === undefined
351
- ? {}
352
- : { baseSha: payload.pull_request.base.sha }),
353
- ...(payload.changes?.base?.ref?.from === undefined
354
- ? {}
355
- : { baseRefChangedFrom: payload.changes.base.ref.from }),
356
- draft: payload.pull_request.draft ?? false,
357
- merged: payload.pull_request.merged === true,
358
- ...(payload.pull_request.user?.login === undefined
359
- ? {}
360
- : { authorLogin: payload.pull_request.user.login }),
361
- ...(payload.label?.name === undefined ? {} : { label: { name: payload.label.name } }),
362
- };
363
- return { ctx, pullRequest };
364
- }
365
-
366
- export async function verifyGitHubWebhookSignature(args: {
367
- body: string;
368
- signatureHeader: string | null;
369
- secret: GitHubCredentialValue | undefined;
370
- }): Promise<"verified" | "missing_secret" | "missing_signature" | "mismatch"> {
371
- const secret = await resolveCredentialValue(args.secret);
372
- if (secret === undefined || secret === "") {
373
- return "missing_secret";
374
- }
375
- if (args.signatureHeader === null) {
376
- return "missing_signature";
377
- }
378
- const isVerified = verifyWebhookSha256Signature({
379
- secret,
380
- body: args.body,
381
- signatureHeader: args.signatureHeader,
382
- });
383
- return isVerified ? "verified" : "mismatch";
384
- }
385
-
386
- function verifyWebhookSha256Signature(args: {
387
- secret: string;
388
- body: string;
389
- signatureHeader: string;
390
- }): boolean {
391
- const prefix = "sha256=";
392
- if (!args.signatureHeader.startsWith(prefix)) {
393
- return false;
394
- }
395
-
396
- const receivedHex = args.signatureHeader.slice(prefix.length);
397
- if (!/^[0-9a-f]+$/i.test(receivedHex) || receivedHex.length % 2 !== 0) {
398
- return false;
399
- }
400
-
401
- const expected = createHmac("sha256", args.secret).update(args.body).digest();
402
- const received = Buffer.from(receivedHex, "hex");
403
- return received.length === expected.length && timingSafeEqual(received, expected);
404
- }
405
-
406
- /**
407
- * Run the authored hooks for one GitHub delivery and `send()` the turn.
408
- * Callers own delivery auth: the HTTP route verifies the HMAC; trigger
409
- * fan-out and hosted admission arrive verified. The v2 mailbox is stamped
410
- * upstream (local CP or hosted ingress), never here.
411
- */
412
- export async function dispatchGitHubWebhook(input: {
413
- options: GitHubChannelOptions;
414
- eventName: string | null;
415
- payload: unknown;
416
- deliveryId?: string;
417
- args: ChannelHandlerArgs;
418
- }): Promise<Response> {
419
- const { options, eventName, payload, deliveryId, args } = input;
420
- const botName = options.botName ?? process.env.GITHUB_APP_SLUG;
421
- const bindingConfig: GitHubBindingConfig = {
422
- api: options.api,
423
- credentials: options.credentials,
424
- };
425
-
426
- if (eventName === "ping") {
427
- return Response.json({ ok: true, event: "ping" });
428
- }
429
-
430
- switch (eventName) {
431
- case "pull_request":
432
- return handlePullRequest({
433
- options,
434
- bindingConfig,
435
- payload,
436
- deliveryId,
437
- args,
438
- });
439
- case "issue_comment":
440
- return handleIssueComment({
441
- options,
442
- bindingConfig,
443
- botName,
444
- payload,
445
- deliveryId,
446
- args,
447
- });
448
- case "pull_request_review_comment":
449
- return handleReviewComment({
450
- options,
451
- bindingConfig,
452
- botName,
453
- payload,
454
- deliveryId,
455
- args,
456
- });
457
- case "issues":
458
- return handleIssue({
459
- options,
460
- bindingConfig,
461
- payload,
462
- deliveryId,
463
- args,
464
- });
465
- case "check_suite":
466
- return handleCheckSuite({
467
- options,
468
- bindingConfig,
469
- payload,
470
- deliveryId,
471
- args,
472
- });
473
- case "check_run":
474
- return handleCheckRun({
475
- options,
476
- bindingConfig,
477
- payload,
478
- deliveryId,
479
- args,
480
- });
481
- case "workflow_run":
482
- return handleWorkflowRun({
483
- options,
484
- bindingConfig,
485
- payload,
486
- deliveryId,
487
- args,
488
- });
489
- case "status":
490
- return handleStatus({
491
- options,
492
- bindingConfig,
493
- payload,
494
- deliveryId,
495
- args,
496
- });
497
- default:
498
- if (options.onEvent !== undefined && eventName !== null) {
499
- return handleGenericEvent({
500
- options,
501
- bindingConfig,
502
- eventName,
503
- payload,
504
- deliveryId,
505
- args,
506
- });
507
- }
508
- return skipped("unsupported_event", { event: eventName });
509
- }
510
- }
511
-
512
- /**
513
- * HTTP entry for a single agent's GitHub channel: optional HMAC verify, then
514
- * {@link dispatchGitHubWebhook}.
515
- */
516
- export async function handleGitHubWebhookRequest(input: {
517
- options: GitHubChannelOptions;
518
- request: Request;
519
- args: ChannelHandlerArgs;
520
- /** When true, skip HMAC even if a webhook secret is configured. */
521
- skipSignatureVerification?: boolean;
522
- }): Promise<Response> {
523
- const bodyText = await input.request.text();
524
- const webhookSecret = input.options.credentials?.webhookSecret ?? envWebhookSecret();
525
-
526
- if (webhookSecret !== undefined && input.skipSignatureVerification !== true) {
527
- const signatureResult = await verifyGitHubWebhookSignature({
528
- body: bodyText,
529
- signatureHeader: input.request.headers.get("x-hub-signature-256"),
530
- secret: webhookSecret,
531
- });
532
- if (signatureResult !== "verified") {
533
- return Response.json({ ok: false, error: signatureResult }, { status: 401 });
534
- }
535
- }
536
-
537
- let payload: unknown;
538
- try {
539
- payload = JSON.parse(bodyText) as unknown;
540
- } catch {
541
- return Response.json({ ok: false, error: "invalid_json" }, { status: 400 });
542
- }
543
-
544
- const eventName = input.request.headers.get("x-github-event");
545
- const args =
546
- eventName === null
547
- ? input.args
548
- : bindLocalIngressSend(input.args, {
549
- identity: input.options.continuation,
550
- kind: "github",
551
- eventType: eventName,
552
- payload,
553
- });
554
- return dispatchGitHubWebhook({
555
- options: input.options,
556
- eventName,
557
- payload,
558
- deliveryId: input.request.headers.get("x-github-delivery") ?? undefined,
559
- args,
560
- });
561
- }
562
-
563
- /** Options used to construct a github channel — for host-level fan-out. */
564
- const githubChannelOptionsByDefinition = new WeakMap<object, GitHubChannelOptions>();
565
-
566
- /**
567
- * Recover the {@link GitHubChannelOptions} used to build a channel definition,
568
- * if it was created via {@link githubChannel}.
569
- */
570
- export function getGitHubChannelOptions(definition: object): GitHubChannelOptions | undefined {
571
- return githubChannelOptionsByDefinition.get(definition);
572
- }
573
-
574
- /**
575
- * GitHub webhook channel (Eve-compatible dispatch surface). Point a GitHub App
576
- * or repository webhook at `/<agent>/v1/channels/github` and declare inbound
577
- * hooks:
578
- *
579
- * ```ts
580
- * import { defaultGitHubAuth, githubChannel } from "@cursor/bdk/channels/github";
581
- *
582
- * export default githubChannel({
583
- * botName: "my-agent",
584
- * credentials: { webhookSecret: () => process.env.GITHUB_WEBHOOK_SECRET },
585
- * // Replaces the @mention gate. Prefer typed Octokit via getOctokit().
586
- * onComment: (ctx, comment) => ({ auth: defaultGitHubAuth(ctx) }),
587
- * onPullRequest: (ctx, pr) => {
588
- * if (pr.action !== "opened") {
589
- * return null;
590
- * }
591
- * return { auth: defaultGitHubAuth(ctx) };
592
- * },
593
- * onStatus: (ctx, status) => {
594
- * if (status.state !== "failure") {
595
- * return null;
596
- * }
597
- * return {
598
- * task: async () => {
599
- * const octokit = await ctx.github.getOctokit();
600
- * await octokit.rest.repos.createCommitStatus({
601
- * owner: ctx.repository.owner,
602
- * repo: ctx.repository.name,
603
- * sha: status.sha,
604
- * state: "pending",
605
- * context: "agent/triage",
606
- * });
607
- * },
608
- * };
609
- * },
610
- * onEvent: (ctx, event) => {
611
- * if (event.eventName !== "label") {
612
- * return null;
613
- * }
614
- * return { auth: defaultGitHubAuth(ctx) };
615
- * },
616
- * });
617
- * ```
618
- */
619
- export function githubChannel(
620
- options: GitHubChannelOptions = {},
621
- ): ChannelDefinition<GitHubChannelState> {
622
- const usesCursorAccount =
623
- options.cursorAccount === true || typeof options.cursorAccount === "object";
624
- // Normalized scope lives on the private runtime — never rewrite authored
625
- // `cursorAccount` on the options object the author passed in.
626
- const cursorScope =
627
- typeof options.cursorAccount === "object"
628
- ? parseCursorGithubRepoScope(
629
- options.cursorAccount.repos,
630
- cursorGithubPermissionsForChannel(options, options.cursorAccount.permissions),
631
- )
632
- : undefined;
633
-
634
- let cursorCredentials: PendingCursorGithubCredentials | undefined;
635
- let credentials = options.credentials;
636
- if (usesCursorAccount) {
637
- if (hasDedicatedGitHubApiCredentials(options)) {
638
- throw new Error(
639
- "githubChannel({ cursorAccount: true }) cannot be combined with token or GitHub App credentials.",
640
- );
641
- }
642
- const pending = createPendingCursorGithubCredentials();
643
- cursorCredentials = pending;
644
- credentials = {
645
- ...options.credentials,
646
- token: createCursorAccountGithubTokenResolver(() => pending.getToken(), pending),
647
- };
648
- }
649
-
650
- const routePath = options.path ?? "/";
651
- const webhookSecret = credentials?.webhookSecret ?? envWebhookSecret();
652
- // With a secret the HMAC is the request auth (allowAll). Without one, prod
653
- // stays loopback-strict; dev admits unsigned deliveries from a loopback peer
654
- // only (loopbackGitHubDev) — not the LAN. Admits `gh webhook forward`
655
- // deliveries (loopback peer + GitHub forwarding/delivery headers) while
656
- // rejecting loopback tunnels that relay unsigned traffic without
657
- // `X-GitHub-Event`.
658
- //
659
- // Evaluate `isDevMode()` per request (not at channel construction): channel
660
- // modules call `githubChannel()` at import, and discovery may cache the
661
- // definition across serve() calls. `serve()` sets the flag before discovery,
662
- // but request-time lookup stays correct if that ordering ever drifts.
663
- const auth =
664
- options.auth ??
665
- (webhookSecret !== undefined
666
- ? [allowAll()]
667
- : [(request, info) => (isDevMode() ? loopbackGitHubDev() : localDevStrict())(request, info)]);
668
-
669
- const channelOptions: GitHubChannelOptions = {
670
- ...options,
671
- credentials,
672
- };
673
- if (channelOptions.continuation !== undefined) {
674
- channelOptions.continuation = normalizeIdentity(channelOptions.continuation, "github");
675
- }
676
- const events: ChannelEventHandlers<GitHubChannelState> = {
677
- ...buildDefaultGitHubEvents({ ...channelOptions }),
678
- ...options.events,
679
- };
680
-
681
- const definition = defineChannel({
682
- auth,
683
- state: emptyGitHubChannelState(),
684
- events,
685
- meta: {
686
- kind: GITHUB_CHANNEL_KIND,
687
- githubWebhookEvents: deriveGitHubWebhookEvents(channelOptions),
688
- },
689
- onStart: options.onStart,
690
- onStop: options.onStop,
691
- routes: [
692
- POST(routePath, {
693
- // Webhook payloads vary by `X-GitHub-Event`; event-specific Zod
694
- // parsing happens inside the dispatcher. Require a schema at the
695
- // route boundary so /v1/info + Try always have something to show.
696
- bodySchema: z.unknown(),
697
- description: "GitHub webhook ingress",
698
- handler: async (request, args) =>
699
- handleGitHubWebhookRequest({
700
- options: channelOptions,
701
- request,
702
- args,
703
- }),
704
- }),
705
- ],
706
- });
707
- githubChannelOptionsByDefinition.set(definition, channelOptions);
708
- attachHostedAdmissionAdapter(definition, {
709
- kind: GITHUB_CHANNEL_KIND,
710
- prepareArgs: withPropagatingBackgroundErrors,
711
- dispatch: ({ eventType, payload, deliveryId, args }) =>
712
- dispatchGitHubWebhook({
713
- options: channelOptions,
714
- eventName: eventType,
715
- payload,
716
- deliveryId,
717
- args,
718
- }),
719
- });
720
- if (cursorCredentials !== undefined) {
721
- registerGithubCursorAccountRuntime(definition, {
722
- options,
723
- credentials: cursorCredentials,
724
- scope: cursorScope,
725
- });
726
- }
727
- return definition;
728
- }
729
-
730
- function hasDedicatedGitHubApiCredentials(options: GitHubChannelOptions): boolean {
731
- return (
732
- options.credentials?.token !== undefined ||
733
- options.credentials?.installationToken !== undefined ||
734
- options.credentials?.appId !== undefined ||
735
- options.credentials?.privateKey !== undefined
736
- );
737
- }
738
-
739
- async function handlePullRequest(input: {
740
- options: GitHubChannelOptions;
741
- bindingConfig: GitHubBindingConfig;
742
- payload: unknown;
743
- deliveryId?: string;
744
- args: ChannelHandlerArgs;
745
- }): Promise<Response> {
746
- const parsed = parseGitHubPullRequestEvent({
747
- payload: input.payload,
748
- deliveryId: input.deliveryId,
749
- });
750
- if (parsed === null) {
751
- return Response.json({ ok: false, error: "invalid_pull_request_payload" }, { status: 400 });
752
- }
753
- const { pullRequest } = parsed;
754
- const installationId = readInstallationId(input.payload) ?? parsed.ctx.installationId;
755
- const binding = githubBindingStateForEvent({
756
- kind: parsed.ctx.conversation.kind,
757
- owner: parsed.ctx.repository.owner,
758
- repo: parsed.ctx.repository.name,
759
- number: parsed.ctx.conversation.number,
760
- repositoryId: parsed.ctx.repository.id,
761
- repositoryUrl: parsed.ctx.repository.url,
762
- installationId,
763
- });
764
- const ctx = enrichEventContext({
765
- bindingConfig: input.bindingConfig,
766
- ctx: parsed.ctx,
767
- payload: input.payload,
768
- bindingState: binding,
769
- installationId,
770
- host: input.args.host,
771
- artifacts: input.args.artifacts,
772
- send: input.args.send,
773
- });
774
- const dispatch =
775
- input.options.onPullRequest === undefined
776
- ? defaultGitHubPullRequestDispatch(ctx, pullRequest)
777
- : await input.options.onPullRequest(ctx, pullRequest);
778
- if (dispatch === null) {
779
- return skipped("not_dispatched", { action: pullRequest.action });
780
- }
781
-
782
- if (isTaskDispatch(dispatch)) {
783
- return acknowledgeTask(input.args, GITHUB_CHANNEL_KIND, dispatch, {
784
- action: pullRequest.action,
785
- prUrl: pullRequest.url,
786
- headSha: pullRequest.headSha,
787
- });
788
- }
789
-
790
- const message = [
791
- dispatch.message ?? defaultGitHubPullRequestMessage(ctx, pullRequest),
792
- ...(dispatch.context ?? []),
793
- ].join("\n");
794
- const cloud =
795
- dispatch.cloud ?? (await resolveCloudOptions(input.options.cloud, ctx, pullRequest));
796
- return startTurn({
797
- options: input.options,
798
- args: input.args,
799
- ctx,
800
- message,
801
- dispatch,
802
- cloud,
803
- state: sessionStateFromBinding({
804
- binding,
805
- deliveryId: ctx.deliveryId,
806
- eventName: ctx.eventName,
807
- headSha: pullRequest.headSha,
808
- baseRef: pullRequest.baseRef,
809
- headRef: pullRequest.headRef,
810
- }),
811
- });
812
- }
813
-
814
- async function handleIssueComment(input: {
815
- options: GitHubChannelOptions;
816
- bindingConfig: GitHubBindingConfig;
817
- botName?: string;
818
- payload: unknown;
819
- deliveryId?: string;
820
- args: ChannelHandlerArgs;
821
- }): Promise<Response> {
822
- const parsed = parseIssueCommentEvent({
823
- payload: input.payload,
824
- deliveryId: input.deliveryId,
825
- });
826
- if (parsed === null) {
827
- return Response.json({ ok: false, error: "invalid_issue_comment_payload" }, { status: 400 });
828
- }
829
- if (parsed.action !== "created") {
830
- return skipped("not_dispatched", { action: parsed.action });
831
- }
832
- if (isIgnoredInboundComment(parsed.comment.body, parsed.comment.author, input.botName)) {
833
- return skipped("ignored_comment");
834
- }
835
-
836
- const installationId = readInstallationId(input.payload) ?? parsed.ctx.installationId;
837
- const binding = githubBindingStateForEvent({
838
- kind: parsed.ctx.conversation.kind,
839
- owner: parsed.ctx.repository.owner,
840
- repo: parsed.ctx.repository.name,
841
- number: parsed.ctx.conversation.number,
842
- repositoryId: parsed.ctx.repository.id,
843
- repositoryUrl: parsed.ctx.repository.url,
844
- installationId,
845
- triggeringCommentId: parsed.comment.id,
846
- });
847
- const ctx = enrichEventContext({
848
- bindingConfig: input.bindingConfig,
849
- ctx: parsed.ctx,
850
- payload: input.payload,
851
- bindingState: binding,
852
- installationId,
853
- host: input.args.host,
854
- artifacts: input.args.artifacts,
855
- send: input.args.send,
856
- });
857
-
858
- const dispatch =
859
- input.options.onComment === undefined
860
- ? defaultOnComment(ctx, parsed.comment, {
861
- botName: input.botName,
862
- })
863
- : await input.options.onComment(ctx, parsed.comment);
864
- if (dispatch === null) {
865
- return skipped("not_dispatched");
866
- }
867
- if (isTaskDispatch(dispatch)) {
868
- return acknowledgeTask(input.args, GITHUB_CHANNEL_KIND, dispatch, {
869
- event: "issue_comment",
870
- action: parsed.action,
871
- });
872
- }
873
-
874
- const trigger = extractGitHubCommentTrigger({
875
- body: parsed.comment.body,
876
- botName: input.botName,
877
- });
878
- const message = [
879
- dispatch.message ?? trigger?.message ?? parsed.comment.body.trim(),
880
- ...(dispatch.context ?? []),
881
- ].join("\n");
882
-
883
- return startTurn({
884
- options: input.options,
885
- args: input.args,
886
- ctx,
887
- message,
888
- dispatch,
889
- state: sessionStateFromBinding({
890
- binding,
891
- deliveryId: ctx.deliveryId,
892
- eventName: ctx.eventName,
893
- }),
894
- });
895
- }
896
-
897
- async function handleReviewComment(input: {
898
- options: GitHubChannelOptions;
899
- bindingConfig: GitHubBindingConfig;
900
- botName?: string;
901
- payload: unknown;
902
- deliveryId?: string;
903
- args: ChannelHandlerArgs;
904
- }): Promise<Response> {
905
- const parsed = parseReviewCommentEvent({
906
- payload: input.payload,
907
- deliveryId: input.deliveryId,
908
- });
909
- if (parsed === null) {
910
- return Response.json({ ok: false, error: "invalid_review_comment_payload" }, { status: 400 });
911
- }
912
- if (parsed.action !== "created") {
913
- return skipped("not_dispatched", { action: parsed.action });
914
- }
915
- if (isIgnoredInboundComment(parsed.comment.body, parsed.comment.author, input.botName)) {
916
- return skipped("ignored_comment");
917
- }
918
-
919
- const installationId = readInstallationId(input.payload) ?? parsed.ctx.installationId;
920
- const binding = githubBindingStateForEvent({
921
- kind: parsed.ctx.conversation.kind,
922
- owner: parsed.ctx.repository.owner,
923
- repo: parsed.ctx.repository.name,
924
- number: parsed.ctx.conversation.number,
925
- repositoryId: parsed.ctx.repository.id,
926
- repositoryUrl: parsed.ctx.repository.url,
927
- installationId,
928
- triggeringCommentId: parsed.comment.id,
929
- reviewCommentId: parsed.comment.id,
930
- reviewThreadRootCommentId: parsed.comment.inReplyToId ?? parsed.comment.id,
931
- });
932
- const ctx = enrichEventContext({
933
- bindingConfig: input.bindingConfig,
934
- ctx: parsed.ctx,
935
- payload: input.payload,
936
- bindingState: binding,
937
- installationId,
938
- host: input.args.host,
939
- artifacts: input.args.artifacts,
940
- send: input.args.send,
941
- });
942
-
943
- const dispatch =
944
- input.options.onComment === undefined
945
- ? defaultOnComment(ctx, parsed.comment, {
946
- botName: input.botName,
947
- })
948
- : await input.options.onComment(ctx, parsed.comment);
949
- if (dispatch === null) {
950
- return skipped("not_dispatched");
951
- }
952
- if (isTaskDispatch(dispatch)) {
953
- return acknowledgeTask(input.args, GITHUB_CHANNEL_KIND, dispatch, {
954
- event: "pull_request_review_comment",
955
- action: parsed.action,
956
- });
957
- }
958
-
959
- const trigger = extractGitHubCommentTrigger({
960
- body: parsed.comment.body,
961
- botName: input.botName,
962
- });
963
- const message = [
964
- dispatch.message ?? trigger?.message ?? parsed.comment.body.trim(),
965
- ...(dispatch.context ?? []),
966
- ].join("\n");
967
-
968
- return startTurn({
969
- options: input.options,
970
- args: input.args,
971
- ctx,
972
- message,
973
- dispatch,
974
- state: sessionStateFromBinding({
975
- binding,
976
- deliveryId: ctx.deliveryId,
977
- eventName: ctx.eventName,
978
- headSha: parsed.headSha,
979
- headRef: parsed.headRef,
980
- baseRef: parsed.baseRef,
981
- }),
982
- });
983
- }
984
-
985
- async function handleIssue(input: {
986
- options: GitHubChannelOptions;
987
- bindingConfig: GitHubBindingConfig;
988
- payload: unknown;
989
- deliveryId?: string;
990
- args: ChannelHandlerArgs;
991
- }): Promise<Response> {
992
- if (input.options.onIssue === undefined) {
993
- return skipped("no_handler", { event: "issues" });
994
- }
995
- const parsed = parseIssueEvent({
996
- payload: input.payload,
997
- deliveryId: input.deliveryId,
998
- });
999
- if (parsed === null) {
1000
- return Response.json({ ok: false, error: "invalid_issues_payload" }, { status: 400 });
1001
- }
1002
- const installationId = readInstallationId(input.payload) ?? parsed.ctx.installationId;
1003
- const binding = githubBindingStateForEvent({
1004
- kind: parsed.ctx.conversation.kind,
1005
- owner: parsed.ctx.repository.owner,
1006
- repo: parsed.ctx.repository.name,
1007
- number: parsed.ctx.conversation.number,
1008
- repositoryId: parsed.ctx.repository.id,
1009
- repositoryUrl: parsed.ctx.repository.url,
1010
- installationId,
1011
- });
1012
- const ctx = enrichEventContext({
1013
- bindingConfig: input.bindingConfig,
1014
- ctx: parsed.ctx,
1015
- payload: input.payload,
1016
- bindingState: binding,
1017
- installationId,
1018
- host: input.args.host,
1019
- artifacts: input.args.artifacts,
1020
- send: input.args.send,
1021
- });
1022
- const dispatch = await input.options.onIssue(ctx, parsed.issue);
1023
- if (dispatch === null) {
1024
- return skipped("not_dispatched", { action: parsed.issue.action });
1025
- }
1026
- if (isTaskDispatch(dispatch)) {
1027
- return acknowledgeTask(input.args, GITHUB_CHANNEL_KIND, dispatch, {
1028
- event: "issues",
1029
- action: parsed.issue.action,
1030
- issueNumber: parsed.issue.number,
1031
- });
1032
- }
1033
- const message = [
1034
- dispatch.message ??
1035
- `Issue ${parsed.issue.action}: #${parsed.issue.number} ${parsed.issue.title}`,
1036
- ...(dispatch.context ?? []),
1037
- ].join("\n");
1038
- return startTurn({
1039
- options: input.options,
1040
- args: input.args,
1041
- ctx,
1042
- message,
1043
- dispatch,
1044
- state: sessionStateFromBinding({
1045
- binding,
1046
- deliveryId: ctx.deliveryId,
1047
- eventName: ctx.eventName,
1048
- }),
1049
- });
1050
- }
1051
-
1052
- async function handleCheckSuite(input: {
1053
- options: GitHubChannelOptions;
1054
- bindingConfig: GitHubBindingConfig;
1055
- payload: unknown;
1056
- deliveryId?: string;
1057
- args: ChannelHandlerArgs;
1058
- }): Promise<Response> {
1059
- if (input.options.onCheckSuite === undefined) {
1060
- return skipped("no_handler", { event: "check_suite" });
1061
- }
1062
- const parsed = parseCheckSuiteEvent({
1063
- payload: input.payload,
1064
- deliveryId: input.deliveryId,
1065
- });
1066
- if (parsed === null) {
1067
- return Response.json({ ok: false, error: "invalid_check_suite_payload" }, { status: 400 });
1068
- }
1069
- const installationId = readInstallationId(input.payload) ?? parsed.unanchoredCtx.installationId;
1070
- if (parsed.ctx === null) {
1071
- const dispatch = await input.options.onCheckSuite(
1072
- enrichCiContext({
1073
- bindingConfig: input.bindingConfig,
1074
- ctx: parsed.unanchoredCtx,
1075
- payload: input.payload,
1076
- installationId,
1077
- host: input.args.host,
1078
- artifacts: input.args.artifacts,
1079
- send: input.args.send,
1080
- }),
1081
- parsed.checkSuite,
1082
- );
1083
- if (dispatch !== null && isTaskDispatch(dispatch)) {
1084
- return acknowledgeTask(input.args, GITHUB_CHANNEL_KIND, dispatch, {
1085
- event: "check_suite",
1086
- action: parsed.checkSuite.action,
1087
- checkSuiteId: parsed.checkSuite.checkSuiteId,
1088
- });
1089
- }
1090
- return skipped("no_pull_request", { event: "check_suite" });
1091
- }
1092
- const binding = githubBindingStateForEvent({
1093
- kind: parsed.ctx.conversation.kind,
1094
- owner: parsed.ctx.repository.owner,
1095
- repo: parsed.ctx.repository.name,
1096
- number: parsed.ctx.conversation.number,
1097
- repositoryId: parsed.ctx.repository.id,
1098
- repositoryUrl: parsed.ctx.repository.url,
1099
- installationId,
1100
- });
1101
- const ctx = enrichEventContext({
1102
- bindingConfig: input.bindingConfig,
1103
- ctx: parsed.ctx,
1104
- payload: input.payload,
1105
- bindingState: binding,
1106
- installationId,
1107
- host: input.args.host,
1108
- artifacts: input.args.artifacts,
1109
- send: input.args.send,
1110
- });
1111
- const dispatch = await input.options.onCheckSuite(ctx, parsed.checkSuite);
1112
- if (dispatch === null) {
1113
- return skipped("not_dispatched", { action: parsed.checkSuite.action });
1114
- }
1115
- if (isTaskDispatch(dispatch)) {
1116
- return acknowledgeTask(input.args, GITHUB_CHANNEL_KIND, dispatch, {
1117
- event: "check_suite",
1118
- action: parsed.checkSuite.action,
1119
- checkSuiteId: parsed.checkSuite.checkSuiteId,
1120
- });
1121
- }
1122
- const message = [
1123
- dispatch.message ??
1124
- formatCiMessage("Check suite", parsed.checkSuite.checkSuiteId, parsed.checkSuite),
1125
- ...(dispatch.context ?? []),
1126
- ].join("\n");
1127
- return startTurn({
1128
- options: input.options,
1129
- args: input.args,
1130
- ctx,
1131
- message,
1132
- dispatch,
1133
- state: sessionStateFromBinding({
1134
- binding,
1135
- deliveryId: ctx.deliveryId,
1136
- eventName: ctx.eventName,
1137
- headSha: parsed.checkSuite.headSha,
1138
- }),
1139
- });
1140
- }
1141
-
1142
- async function handleCheckRun(input: {
1143
- options: GitHubChannelOptions;
1144
- bindingConfig: GitHubBindingConfig;
1145
- payload: unknown;
1146
- deliveryId?: string;
1147
- args: ChannelHandlerArgs;
1148
- }): Promise<Response> {
1149
- if (input.options.onCheckRun === undefined) {
1150
- return skipped("no_handler", { event: "check_run" });
1151
- }
1152
- const parsed = parseCheckRunEvent({
1153
- payload: input.payload,
1154
- deliveryId: input.deliveryId,
1155
- });
1156
- if (parsed === null) {
1157
- return Response.json({ ok: false, error: "invalid_check_run_payload" }, { status: 400 });
1158
- }
1159
- const installationId = readInstallationId(input.payload) ?? parsed.unanchoredCtx.installationId;
1160
- if (parsed.ctx === null) {
1161
- const dispatch = await input.options.onCheckRun(
1162
- enrichCiContext({
1163
- bindingConfig: input.bindingConfig,
1164
- ctx: parsed.unanchoredCtx,
1165
- payload: input.payload,
1166
- installationId,
1167
- host: input.args.host,
1168
- artifacts: input.args.artifacts,
1169
- send: input.args.send,
1170
- }),
1171
- parsed.checkRun,
1172
- );
1173
- if (dispatch !== null && isTaskDispatch(dispatch)) {
1174
- return acknowledgeTask(input.args, GITHUB_CHANNEL_KIND, dispatch, {
1175
- event: "check_run",
1176
- action: parsed.checkRun.action,
1177
- checkRunId: parsed.checkRun.checkRunId,
1178
- });
1179
- }
1180
- return skipped("no_pull_request", { event: "check_run" });
1181
- }
1182
- const binding = githubBindingStateForEvent({
1183
- kind: parsed.ctx.conversation.kind,
1184
- owner: parsed.ctx.repository.owner,
1185
- repo: parsed.ctx.repository.name,
1186
- number: parsed.ctx.conversation.number,
1187
- repositoryId: parsed.ctx.repository.id,
1188
- repositoryUrl: parsed.ctx.repository.url,
1189
- installationId,
1190
- });
1191
- const ctx = enrichEventContext({
1192
- bindingConfig: input.bindingConfig,
1193
- ctx: parsed.ctx,
1194
- payload: input.payload,
1195
- bindingState: binding,
1196
- installationId,
1197
- host: input.args.host,
1198
- artifacts: input.args.artifacts,
1199
- send: input.args.send,
1200
- });
1201
- const dispatch = await input.options.onCheckRun(ctx, parsed.checkRun);
1202
- if (dispatch === null) {
1203
- return skipped("not_dispatched", { action: parsed.checkRun.action });
1204
- }
1205
- if (isTaskDispatch(dispatch)) {
1206
- return acknowledgeTask(input.args, GITHUB_CHANNEL_KIND, dispatch, {
1207
- event: "check_run",
1208
- action: parsed.checkRun.action,
1209
- checkRunId: parsed.checkRun.checkRunId,
1210
- });
1211
- }
1212
- const message = [
1213
- dispatch.message ?? formatCiMessage("Check run", parsed.checkRun.checkRunId, parsed.checkRun),
1214
- ...(dispatch.context ?? []),
1215
- ].join("\n");
1216
- return startTurn({
1217
- options: input.options,
1218
- args: input.args,
1219
- ctx,
1220
- message,
1221
- dispatch,
1222
- state: sessionStateFromBinding({
1223
- binding,
1224
- deliveryId: ctx.deliveryId,
1225
- eventName: ctx.eventName,
1226
- headSha: parsed.checkRun.headSha,
1227
- }),
1228
- });
1229
- }
1230
-
1231
- async function handleWorkflowRun(input: {
1232
- options: GitHubChannelOptions;
1233
- bindingConfig: GitHubBindingConfig;
1234
- payload: unknown;
1235
- deliveryId?: string;
1236
- args: ChannelHandlerArgs;
1237
- }): Promise<Response> {
1238
- if (input.options.onWorkflowRun === undefined) {
1239
- return skipped("no_handler", { event: "workflow_run" });
1240
- }
1241
- const parsed = parseWorkflowRunEvent({
1242
- payload: input.payload,
1243
- deliveryId: input.deliveryId,
1244
- });
1245
- if (parsed === null) {
1246
- return Response.json({ ok: false, error: "invalid_workflow_run_payload" }, { status: 400 });
1247
- }
1248
- const installationId = readInstallationId(input.payload) ?? parsed.unanchoredCtx.installationId;
1249
- if (parsed.ctx === null) {
1250
- const dispatch = await input.options.onWorkflowRun(
1251
- enrichCiContext({
1252
- bindingConfig: input.bindingConfig,
1253
- ctx: parsed.unanchoredCtx,
1254
- payload: input.payload,
1255
- installationId,
1256
- host: input.args.host,
1257
- artifacts: input.args.artifacts,
1258
- send: input.args.send,
1259
- }),
1260
- parsed.workflowRun,
1261
- );
1262
- if (dispatch !== null && isTaskDispatch(dispatch)) {
1263
- return acknowledgeTask(input.args, GITHUB_CHANNEL_KIND, dispatch, {
1264
- event: "workflow_run",
1265
- action: parsed.workflowRun.action,
1266
- workflowRunId: parsed.workflowRun.workflowRunId,
1267
- });
1268
- }
1269
- return skipped("no_pull_request", { event: "workflow_run" });
1270
- }
1271
- const binding = githubBindingStateForEvent({
1272
- kind: parsed.ctx.conversation.kind,
1273
- owner: parsed.ctx.repository.owner,
1274
- repo: parsed.ctx.repository.name,
1275
- number: parsed.ctx.conversation.number,
1276
- repositoryId: parsed.ctx.repository.id,
1277
- repositoryUrl: parsed.ctx.repository.url,
1278
- installationId,
1279
- });
1280
- const ctx = enrichEventContext({
1281
- bindingConfig: input.bindingConfig,
1282
- ctx: parsed.ctx,
1283
- payload: input.payload,
1284
- bindingState: binding,
1285
- installationId,
1286
- host: input.args.host,
1287
- artifacts: input.args.artifacts,
1288
- send: input.args.send,
1289
- });
1290
- const dispatch = await input.options.onWorkflowRun(ctx, parsed.workflowRun);
1291
- if (dispatch === null) {
1292
- return skipped("not_dispatched", { action: parsed.workflowRun.action });
1293
- }
1294
- if (isTaskDispatch(dispatch)) {
1295
- return acknowledgeTask(input.args, GITHUB_CHANNEL_KIND, dispatch, {
1296
- event: "workflow_run",
1297
- action: parsed.workflowRun.action,
1298
- workflowRunId: parsed.workflowRun.workflowRunId,
1299
- });
1300
- }
1301
- const message = [
1302
- dispatch.message ??
1303
- formatCiMessage("Workflow run", parsed.workflowRun.workflowRunId, parsed.workflowRun),
1304
- ...(dispatch.context ?? []),
1305
- ].join("\n");
1306
- return startTurn({
1307
- options: input.options,
1308
- args: input.args,
1309
- ctx,
1310
- message,
1311
- dispatch,
1312
- state: sessionStateFromBinding({
1313
- binding,
1314
- deliveryId: ctx.deliveryId,
1315
- eventName: ctx.eventName,
1316
- headSha: parsed.workflowRun.headSha,
1317
- }),
1318
- });
1319
- }
1320
-
1321
- async function handleStatus(input: {
1322
- options: GitHubChannelOptions;
1323
- bindingConfig: GitHubBindingConfig;
1324
- payload: unknown;
1325
- deliveryId?: string;
1326
- args: ChannelHandlerArgs;
1327
- }): Promise<Response> {
1328
- if (input.options.onStatus === undefined) {
1329
- return skipped("no_handler", { event: "status" });
1330
- }
1331
- const parsed = parseStatusEvent({
1332
- payload: input.payload,
1333
- deliveryId: input.deliveryId,
1334
- });
1335
- if (parsed === null) {
1336
- return Response.json({ ok: false, error: "invalid_status_payload" }, { status: 400 });
1337
- }
1338
- const installationId = readInstallationId(input.payload) ?? parsed.ctx.installationId;
1339
- const binding = githubBindingStateForEvent({
1340
- kind: parsed.ctx.conversation.kind,
1341
- owner: parsed.ctx.repository.owner,
1342
- repo: parsed.ctx.repository.name,
1343
- number: parsed.ctx.conversation.number,
1344
- repositoryId: parsed.ctx.repository.id,
1345
- repositoryUrl: parsed.ctx.repository.url,
1346
- installationId,
1347
- });
1348
- const ctx = enrichEventContext({
1349
- bindingConfig: input.bindingConfig,
1350
- ctx: parsed.ctx,
1351
- payload: input.payload,
1352
- bindingState: binding,
1353
- installationId,
1354
- host: input.args.host,
1355
- artifacts: input.args.artifacts,
1356
- send: input.args.send,
1357
- });
1358
- const dispatch = await input.options.onStatus(ctx, parsed.status);
1359
- if (dispatch === null) {
1360
- return skipped("not_dispatched", {
1361
- event: "status",
1362
- state: parsed.status.state,
1363
- });
1364
- }
1365
- if (isTaskDispatch(dispatch)) {
1366
- return acknowledgeTask(input.args, GITHUB_CHANNEL_KIND, dispatch, {
1367
- event: "status",
1368
- state: parsed.status.state,
1369
- sha: parsed.status.sha,
1370
- });
1371
- }
1372
- // A turn needs a thread to anchor to; commit statuses often have no PR.
1373
- if (ctx.conversation.number === 0) {
1374
- return skipped("no_pull_request", { event: "status" });
1375
- }
1376
- const message = [
1377
- dispatch.message ??
1378
- `Commit status ${parsed.status.state} for ${parsed.status.context} at ${parsed.status.sha}`,
1379
- ...(dispatch.context ?? []),
1380
- ].join("\n");
1381
- return startTurn({
1382
- options: input.options,
1383
- args: input.args,
1384
- ctx,
1385
- message,
1386
- dispatch,
1387
- state: sessionStateFromBinding({
1388
- binding,
1389
- deliveryId: ctx.deliveryId,
1390
- eventName: ctx.eventName,
1391
- headSha: parsed.status.sha,
1392
- }),
1393
- });
1394
- }
1395
-
1396
- async function handleGenericEvent(input: {
1397
- options: GitHubChannelOptions;
1398
- bindingConfig: GitHubBindingConfig;
1399
- eventName: string;
1400
- payload: unknown;
1401
- deliveryId?: string;
1402
- args: ChannelHandlerArgs;
1403
- }): Promise<Response> {
1404
- if (input.options.onEvent === undefined) {
1405
- return skipped("no_handler", { event: input.eventName });
1406
- }
1407
- const parsed = parseGenericEvent({
1408
- eventName: input.eventName,
1409
- payload: input.payload,
1410
- deliveryId: input.deliveryId,
1411
- });
1412
- if (parsed === null) {
1413
- return skipped("unsupported_event", { event: input.eventName });
1414
- }
1415
- const installationId = readInstallationId(input.payload) ?? parsed.ctx.installationId;
1416
- const binding = githubBindingStateForEvent({
1417
- kind: parsed.ctx.conversation.kind,
1418
- owner: parsed.ctx.repository.owner,
1419
- repo: parsed.ctx.repository.name,
1420
- number: parsed.ctx.conversation.number,
1421
- repositoryId: parsed.ctx.repository.id,
1422
- repositoryUrl: parsed.ctx.repository.url,
1423
- installationId,
1424
- });
1425
- const ctx = enrichEventContext({
1426
- bindingConfig: input.bindingConfig,
1427
- ctx: parsed.ctx,
1428
- payload: input.payload,
1429
- bindingState: binding,
1430
- installationId,
1431
- host: input.args.host,
1432
- artifacts: input.args.artifacts,
1433
- send: input.args.send,
1434
- });
1435
- const dispatch = await input.options.onEvent(ctx, parsed.event);
1436
- if (dispatch === null) {
1437
- return skipped("not_dispatched", { event: input.eventName });
1438
- }
1439
- if (isTaskDispatch(dispatch)) {
1440
- return acknowledgeTask(input.args, GITHUB_CHANNEL_KIND, dispatch, {
1441
- event: input.eventName,
1442
- ...(parsed.event.action === undefined ? {} : { action: parsed.event.action }),
1443
- });
1444
- }
1445
- if (ctx.conversation.number === 0) {
1446
- return skipped("no_conversation", { event: input.eventName });
1447
- }
1448
- const message = [
1449
- dispatch.message ?? `GitHub ${input.eventName} event`,
1450
- ...(dispatch.context ?? []),
1451
- ].join("\n");
1452
- return startTurn({
1453
- options: input.options,
1454
- args: input.args,
1455
- ctx,
1456
- message,
1457
- dispatch,
1458
- state: sessionStateFromBinding({
1459
- binding,
1460
- deliveryId: ctx.deliveryId,
1461
- eventName: ctx.eventName,
1462
- }),
1463
- });
1464
- }
1465
-
1466
- async function startTurn(input: {
1467
- options: GitHubChannelOptions;
1468
- args: ChannelHandlerArgs;
1469
- ctx: GitHubEventContext;
1470
- message: string;
1471
- dispatch: GitHubTurnDispatch;
1472
- cloud?: AgentCloudOptions;
1473
- state: GitHubChannelState;
1474
- }): Promise<Response> {
1475
- const files = input.dispatch.workspaceFiles;
1476
- const lazy = typeof files === "function";
1477
- const cloud = input.dispatch.cloud ?? input.cloud;
1478
- const state = { ...input.dispatch.state, ...input.state };
1479
-
1480
- const sendTurn = async () => {
1481
- const workspaceFiles = lazy ? await files() : files;
1482
- const source = continuationSource(input.options.continuation, "github");
1483
- return input.args.send(input.message, {
1484
- auth: input.dispatch.auth,
1485
- ...(source === "engine" ? { continuationToken: githubContinuationKey(input.ctx) } : {}),
1486
- title: input.dispatch.title ?? defaultGitHubTitle(input.ctx),
1487
- cloud,
1488
- ...(workspaceFiles === undefined ? {} : { workspaceFiles }),
1489
- state: state as unknown as JsonValue,
1490
- // Resume must refresh headSha / refs without wiping sticky banner id.
1491
- refreshState: state as unknown as JsonValue,
1492
- });
1493
- };
1494
-
1495
- if (lazy) {
1496
- scheduleAfterAck(input.args, GITHUB_CHANNEL_KIND, async () => {
1497
- await sendTurn();
1498
- });
1499
- return acknowledgeTurn();
1500
- }
1501
-
1502
- return turnStarted(await sendTurn());
1503
- }
1504
-
1505
- function formatCiMessage(
1506
- label: string,
1507
- id: number,
1508
- event: { action: string; status?: string; conclusion?: string | null },
1509
- ): string {
1510
- const outcome = event.conclusion ?? event.status;
1511
- return `${label} ${event.action}: ${id}${outcome ? ` (${outcome})` : ""}`;
1512
- }
1513
-
1514
- function isIgnoredInboundComment(
1515
- body: string,
1516
- author: GitHubUser | undefined,
1517
- botName: string | undefined,
1518
- ): boolean {
1519
- if (body.includes("<!-- agent-serve-github -->")) {
1520
- return true;
1521
- }
1522
- if (isGitHubAppBotAuthor(author, botName)) {
1523
- return true;
1524
- }
1525
- return false;
1526
- }
1527
-
1528
- /** Match GitHub App bot actors (`slug` config vs `slug[bot]` login). */
1529
- export function isGitHubAppBotAuthor(
1530
- author: GitHubUser | undefined,
1531
- botName: string | undefined,
1532
- ): boolean {
1533
- const normalizedBot = botName?.trim();
1534
- if (normalizedBot === undefined || normalizedBot === "") {
1535
- return false;
1536
- }
1537
- if (author?.type !== "Bot") {
1538
- return false;
1539
- }
1540
- const login = author.login;
1541
- const stripBotSuffix = (value: string): string => value.replace(/\[bot\]$/i, "").toLowerCase();
1542
- return (
1543
- login.toLowerCase() === normalizedBot.toLowerCase() ||
1544
- stripBotSuffix(login) === stripBotSuffix(normalizedBot)
1545
- );
1546
- }
1547
-
1548
- function parseIssueCommentEvent(args: { payload: unknown; deliveryId?: string }): {
1549
- action: string;
1550
- ctx: GitHubParsedContext;
1551
- comment: GitHubComment;
1552
- } | null {
1553
- const schema = z.object({
1554
- action: z.string().min(1),
1555
- repository: repositorySchema,
1556
- issue: z.object({
1557
- number: z.number().int().positive(),
1558
- html_url: z.string().url(),
1559
- pull_request: z.unknown().optional(),
1560
- }),
1561
- comment: z.object({
1562
- id: z.number(),
1563
- body: z.string(),
1564
- html_url: z.string().url(),
1565
- url: z.string().url().optional(),
1566
- user: z
1567
- .object({
1568
- login: z.string().optional(),
1569
- id: z.number().optional(),
1570
- type: z.string().optional(),
1571
- })
1572
- .nullable()
1573
- .optional(),
1574
- }),
1575
- sender: senderSchema,
1576
- installation: installationSchema,
1577
- });
1578
- const parsed = schema.safeParse(args.payload);
1579
- if (!parsed.success) return null;
1580
- const payload = parsed.data;
1581
- const kind: GitHubConversationKind =
1582
- payload.issue.pull_request === undefined ? "issue" : "pull_request";
1583
- const repository = toRepositoryRef(payload.repository);
1584
- const sender = toUser(payload.sender);
1585
- const author = toUser(payload.comment.user);
1586
- const installationId = payload.installation?.id;
1587
- const ctx: GitHubParsedContext = {
1588
- ...(args.deliveryId === undefined ? {} : { deliveryId: args.deliveryId }),
1589
- eventName: "issue_comment",
1590
- repository,
1591
- conversation: {
1592
- kind,
1593
- number: payload.issue.number,
1594
- url: payload.issue.html_url,
1595
- },
1596
- ...(sender === undefined ? {} : { sender, senderLogin: sender.login }),
1597
- ...(installationId === undefined ? {} : { installationId }),
1598
- };
1599
- const comment: GitHubComment = {
1600
- id: payload.comment.id,
1601
- body: payload.comment.body,
1602
- htmlUrl: payload.comment.html_url,
1603
- url: payload.comment.url ?? payload.comment.html_url,
1604
- ...(author === undefined ? {} : { author }),
1605
- };
1606
- return { action: payload.action, ctx, comment };
1607
- }
1608
-
1609
- function parseReviewCommentEvent(args: { payload: unknown; deliveryId?: string }): {
1610
- action: string;
1611
- ctx: GitHubParsedContext;
1612
- comment: GitHubComment;
1613
- headSha?: string;
1614
- headRef?: string;
1615
- baseRef?: string;
1616
- } | null {
1617
- const schema = z.object({
1618
- action: z.string().min(1),
1619
- repository: repositorySchema,
1620
- pull_request: z.object({
1621
- number: z.number().int().positive(),
1622
- html_url: z.string().url(),
1623
- head: z
1624
- .object({
1625
- sha: z.string().min(1).optional(),
1626
- ref: z.string().min(1).optional(),
1627
- })
1628
- .optional(),
1629
- base: z
1630
- .object({
1631
- ref: z.string().min(1).optional(),
1632
- })
1633
- .optional(),
1634
- }),
1635
- comment: z.object({
1636
- id: z.number(),
1637
- body: z.string(),
1638
- html_url: z.string().url(),
1639
- url: z.string().url().optional(),
1640
- path: z.string().optional(),
1641
- line: z.number().nullable().optional(),
1642
- pull_request_review_id: z.number().nullable().optional(),
1643
- in_reply_to_id: z.number().optional(),
1644
- user: z
1645
- .object({
1646
- login: z.string().optional(),
1647
- id: z.number().optional(),
1648
- type: z.string().optional(),
1649
- })
1650
- .nullable()
1651
- .optional(),
1652
- }),
1653
- sender: senderSchema,
1654
- installation: installationSchema,
1655
- });
1656
- const parsed = schema.safeParse(args.payload);
1657
- if (!parsed.success) return null;
1658
- const payload = parsed.data;
1659
- const repository = toRepositoryRef(payload.repository);
1660
- const sender = toUser(payload.sender);
1661
- const author = toUser(payload.comment.user);
1662
- const installationId = payload.installation?.id;
1663
- const ctx: GitHubParsedContext = {
1664
- ...(args.deliveryId === undefined ? {} : { deliveryId: args.deliveryId }),
1665
- eventName: "pull_request_review_comment",
1666
- repository,
1667
- conversation: {
1668
- kind: "review_thread",
1669
- number: payload.pull_request.number,
1670
- url: payload.pull_request.html_url,
1671
- },
1672
- ...(sender === undefined ? {} : { sender, senderLogin: sender.login }),
1673
- ...(installationId === undefined ? {} : { installationId }),
1674
- };
1675
- const comment: GitHubComment = {
1676
- id: payload.comment.id,
1677
- body: payload.comment.body,
1678
- htmlUrl: payload.comment.html_url,
1679
- url: payload.comment.url ?? payload.comment.html_url,
1680
- ...(author === undefined ? {} : { author }),
1681
- ...(payload.comment.path === undefined ? {} : { path: payload.comment.path }),
1682
- ...(payload.comment.line === undefined ? {} : { line: payload.comment.line }),
1683
- ...(payload.comment.pull_request_review_id === undefined
1684
- ? {}
1685
- : { pullRequestReviewId: payload.comment.pull_request_review_id }),
1686
- ...(payload.comment.in_reply_to_id === undefined
1687
- ? {}
1688
- : { inReplyToId: payload.comment.in_reply_to_id }),
1689
- };
1690
- return {
1691
- action: payload.action,
1692
- ctx,
1693
- comment,
1694
- headSha: payload.pull_request.head?.sha,
1695
- headRef: payload.pull_request.head?.ref,
1696
- baseRef: payload.pull_request.base?.ref,
1697
- };
1698
- }
1699
-
1700
- function parseIssueEvent(args: {
1701
- payload: unknown;
1702
- deliveryId?: string;
1703
- }): { ctx: GitHubParsedContext; issue: GitHubIssueEvent } | null {
1704
- const schema = z.object({
1705
- action: z.string().min(1),
1706
- repository: repositorySchema,
1707
- issue: z.object({
1708
- number: z.number().int().positive(),
1709
- html_url: z.string().url(),
1710
- title: z.string(),
1711
- body: z.string().nullable().optional(),
1712
- user: z
1713
- .object({
1714
- login: z.string().optional(),
1715
- })
1716
- .nullable()
1717
- .optional(),
1718
- }),
1719
- sender: senderSchema,
1720
- installation: installationSchema,
1721
- });
1722
- const parsed = schema.safeParse(args.payload);
1723
- if (!parsed.success) return null;
1724
- const payload = parsed.data;
1725
- const repository = toRepositoryRef(payload.repository);
1726
- const sender = toUser(payload.sender);
1727
- const installationId = payload.installation?.id;
1728
- const ctx: GitHubParsedContext = {
1729
- ...(args.deliveryId === undefined ? {} : { deliveryId: args.deliveryId }),
1730
- eventName: "issues",
1731
- repository,
1732
- conversation: {
1733
- kind: "issue",
1734
- number: payload.issue.number,
1735
- url: payload.issue.html_url,
1736
- },
1737
- ...(sender === undefined ? {} : { sender, senderLogin: sender.login }),
1738
- ...(installationId === undefined ? {} : { installationId }),
1739
- };
1740
- const issue: GitHubIssueEvent = {
1741
- action: payload.action,
1742
- number: payload.issue.number,
1743
- url: payload.issue.html_url,
1744
- title: payload.issue.title,
1745
- ...(payload.issue.body === undefined || payload.issue.body === null
1746
- ? {}
1747
- : { body: payload.issue.body }),
1748
- ...(payload.issue.user?.login === undefined ? {} : { authorLogin: payload.issue.user.login }),
1749
- };
1750
- return { ctx, issue };
1751
- }
1752
-
1753
- function parseCheckSuiteEvent(args: { payload: unknown; deliveryId?: string }): {
1754
- ctx: GitHubParsedContext | null;
1755
- unanchoredCtx: GitHubParsedContext;
1756
- checkSuite: GitHubCheckSuiteEvent;
1757
- } | null {
1758
- const schema = z.object({
1759
- action: z.string().min(1),
1760
- repository: repositorySchema,
1761
- check_suite: z.object({
1762
- id: z.number(),
1763
- head_sha: z.string().min(1),
1764
- status: z.string().optional(),
1765
- conclusion: z.string().nullable().optional(),
1766
- app: z
1767
- .object({
1768
- slug: z.string().optional(),
1769
- name: z.string().optional(),
1770
- })
1771
- .nullable()
1772
- .optional(),
1773
- pull_requests: z
1774
- .array(
1775
- z.object({
1776
- number: z.number(),
1777
- url: z.string().optional(),
1778
- html_url: z.string().optional(),
1779
- }),
1780
- )
1781
- .optional(),
1782
- }),
1783
- sender: senderSchema,
1784
- installation: installationSchema,
1785
- });
1786
- const parsed = schema.safeParse(args.payload);
1787
- if (!parsed.success) return null;
1788
- const payload = parsed.data;
1789
- const repository = toRepositoryRef(payload.repository);
1790
- const sender = toUser(payload.sender);
1791
- const installationId = payload.installation?.id;
1792
- const pullRequests = toCiPullRequests(payload.check_suite.pull_requests);
1793
- const checkSuite: GitHubCheckSuiteEvent = {
1794
- action: payload.action,
1795
- checkSuiteId: payload.check_suite.id,
1796
- headSha: payload.check_suite.head_sha,
1797
- ...(payload.check_suite.status === undefined ? {} : { status: payload.check_suite.status }),
1798
- conclusion: (payload.check_suite.conclusion ?? null) as GitHubCheckSuiteEvent["conclusion"],
1799
- app: toCiApp(payload.check_suite.app),
1800
- pullRequests,
1801
- };
1802
- const unanchoredCtx = unanchoredEventContext({
1803
- deliveryId: args.deliveryId,
1804
- eventName: "check_suite",
1805
- repository,
1806
- sender,
1807
- installationId,
1808
- });
1809
- const first = pullRequests[0];
1810
- if (first === undefined) {
1811
- return { ctx: null, unanchoredCtx, checkSuite };
1812
- }
1813
- return {
1814
- ctx: {
1815
- ...unanchoredCtx,
1816
- conversation: {
1817
- kind: "pull_request",
1818
- number: first.number,
1819
- url: first.url ?? `${repository.url}/pull/${first.number}`,
1820
- },
1821
- },
1822
- unanchoredCtx,
1823
- checkSuite,
1824
- };
1825
- }
1826
-
1827
- function parseCheckRunEvent(args: { payload: unknown; deliveryId?: string }): {
1828
- ctx: GitHubParsedContext | null;
1829
- unanchoredCtx: GitHubParsedContext;
1830
- checkRun: GitHubCheckRunEvent;
1831
- } | null {
1832
- const schema = z.object({
1833
- action: z.string().min(1),
1834
- repository: repositorySchema,
1835
- check_run: z.object({
1836
- id: z.number(),
1837
- name: z.string().optional(),
1838
- head_sha: z.string().min(1),
1839
- status: z.string().optional(),
1840
- conclusion: z.string().nullable().optional(),
1841
- html_url: z.string().optional(),
1842
- check_suite: z
1843
- .object({
1844
- id: z.number().optional(),
1845
- })
1846
- .optional(),
1847
- app: z
1848
- .object({
1849
- slug: z.string().optional(),
1850
- name: z.string().optional(),
1851
- })
1852
- .nullable()
1853
- .optional(),
1854
- pull_requests: z
1855
- .array(
1856
- z.object({
1857
- number: z.number(),
1858
- url: z.string().optional(),
1859
- html_url: z.string().optional(),
1860
- }),
1861
- )
1862
- .optional(),
1863
- }),
1864
- sender: senderSchema,
1865
- installation: installationSchema,
1866
- });
1867
- const parsed = schema.safeParse(args.payload);
1868
- if (!parsed.success) return null;
1869
- const payload = parsed.data;
1870
- const repository = toRepositoryRef(payload.repository);
1871
- const sender = toUser(payload.sender);
1872
- const installationId = payload.installation?.id;
1873
- const pullRequests = toCiPullRequests(payload.check_run.pull_requests);
1874
- const checkRun: GitHubCheckRunEvent = {
1875
- action: payload.action,
1876
- checkRunId: payload.check_run.id,
1877
- headSha: payload.check_run.head_sha,
1878
- ...(payload.check_run.name === undefined ? {} : { name: payload.check_run.name }),
1879
- ...(payload.check_run.check_suite?.id === undefined
1880
- ? {}
1881
- : { checkSuiteId: payload.check_run.check_suite.id }),
1882
- ...(payload.check_run.status === undefined ? {} : { status: payload.check_run.status }),
1883
- conclusion: (payload.check_run.conclusion ?? null) as GitHubCheckRunEvent["conclusion"],
1884
- app: toCiApp(payload.check_run.app),
1885
- pullRequests,
1886
- };
1887
- const unanchoredCtx = unanchoredEventContext({
1888
- deliveryId: args.deliveryId,
1889
- eventName: "check_run",
1890
- repository,
1891
- sender,
1892
- installationId,
1893
- });
1894
- const first = pullRequests[0];
1895
- if (first === undefined) {
1896
- return { ctx: null, unanchoredCtx, checkRun };
1897
- }
1898
- return {
1899
- ctx: {
1900
- ...unanchoredCtx,
1901
- conversation: {
1902
- kind: "pull_request",
1903
- number: first.number,
1904
- url: first.url ?? `${repository.url}/pull/${first.number}`,
1905
- },
1906
- },
1907
- unanchoredCtx,
1908
- checkRun,
1909
- };
1910
- }
1911
-
1912
- function parseWorkflowRunEvent(args: { payload: unknown; deliveryId?: string }): {
1913
- ctx: GitHubParsedContext | null;
1914
- unanchoredCtx: GitHubParsedContext;
1915
- workflowRun: GitHubWorkflowRunEvent;
1916
- } | null {
1917
- const schema = z.object({
1918
- action: z.string().min(1),
1919
- repository: repositorySchema,
1920
- workflow_run: z.object({
1921
- id: z.number(),
1922
- name: z.string().nullable().optional(),
1923
- workflow_id: z.number().optional(),
1924
- head_sha: z.string().min(1),
1925
- status: z.string().optional(),
1926
- conclusion: z.string().nullable().optional(),
1927
- html_url: z.string().optional(),
1928
- pull_requests: z
1929
- .array(
1930
- z.object({
1931
- number: z.number(),
1932
- url: z.string().optional(),
1933
- html_url: z.string().optional(),
1934
- }),
1935
- )
1936
- .optional(),
1937
- }),
1938
- sender: senderSchema,
1939
- installation: installationSchema,
1940
- });
1941
- const parsed = schema.safeParse(args.payload);
1942
- if (!parsed.success) return null;
1943
- const payload = parsed.data;
1944
- const repository = toRepositoryRef(payload.repository);
1945
- const sender = toUser(payload.sender);
1946
- const installationId = payload.installation?.id;
1947
- const pullRequests = toCiPullRequests(payload.workflow_run.pull_requests);
1948
- const workflowRun: GitHubWorkflowRunEvent = {
1949
- action: payload.action,
1950
- workflowRunId: payload.workflow_run.id,
1951
- headSha: payload.workflow_run.head_sha,
1952
- ...(payload.workflow_run.name === undefined || payload.workflow_run.name === null
1953
- ? {}
1954
- : { name: payload.workflow_run.name }),
1955
- ...(payload.workflow_run.workflow_id === undefined
1956
- ? {}
1957
- : { workflowId: payload.workflow_run.workflow_id }),
1958
- ...(payload.workflow_run.html_url === undefined
1959
- ? {}
1960
- : { htmlUrl: payload.workflow_run.html_url }),
1961
- ...(payload.workflow_run.status === undefined ? {} : { status: payload.workflow_run.status }),
1962
- conclusion: (payload.workflow_run.conclusion ?? null) as GitHubWorkflowRunEvent["conclusion"],
1963
- // workflow_run is GitHub Actions-only (Eve semantics).
1964
- app: { slug: "github-actions", name: "GitHub Actions" },
1965
- pullRequests,
1966
- };
1967
- const unanchoredCtx = unanchoredEventContext({
1968
- deliveryId: args.deliveryId,
1969
- eventName: "workflow_run",
1970
- repository,
1971
- sender,
1972
- installationId,
1973
- });
1974
- const first = pullRequests[0];
1975
- if (first === undefined) {
1976
- return { ctx: null, unanchoredCtx, workflowRun };
1977
- }
1978
- return {
1979
- ctx: {
1980
- ...unanchoredCtx,
1981
- conversation: {
1982
- kind: "pull_request",
1983
- number: first.number,
1984
- url: first.url ?? `${repository.url}/pull/${first.number}`,
1985
- },
1986
- },
1987
- unanchoredCtx,
1988
- workflowRun,
1989
- };
1990
- }
1991
-
1992
- function parseStatusEvent(args: {
1993
- payload: unknown;
1994
- deliveryId?: string;
1995
- }): { ctx: GitHubParsedContext; status: GitHubStatusEvent } | null {
1996
- const schema = z.object({
1997
- state: z.string().min(1),
1998
- sha: z.string().min(1),
1999
- context: z.string().optional(),
2000
- description: z.string().nullable().optional(),
2001
- target_url: z.string().nullable().optional(),
2002
- name: z.string().optional(),
2003
- branches: z
2004
- .array(
2005
- z.object({
2006
- name: z.string(),
2007
- commit: z.object({ sha: z.string().optional() }).optional(),
2008
- }),
2009
- )
2010
- .optional(),
2011
- commit: z
2012
- .object({
2013
- sha: z.string().optional(),
2014
- html_url: z.string().optional(),
2015
- })
2016
- .optional(),
2017
- repository: repositorySchema,
2018
- sender: senderSchema,
2019
- installation: installationSchema,
2020
- pull_requests: z
2021
- .array(
2022
- z.object({
2023
- number: z.number(),
2024
- url: z.string().optional(),
2025
- html_url: z.string().optional(),
2026
- }),
2027
- )
2028
- .optional(),
2029
- });
2030
- const parsed = schema.safeParse(args.payload);
2031
- if (!parsed.success) return null;
2032
- const payload = parsed.data;
2033
- const repository = toRepositoryRef(payload.repository);
2034
- const sender = toUser(payload.sender);
2035
- const installationId = payload.installation?.id;
2036
- const pullRequests = toCiPullRequests(payload.pull_requests);
2037
- const first = pullRequests[0];
2038
- const status: GitHubStatusEvent = {
2039
- state: payload.state,
2040
- context: payload.context ?? "",
2041
- ...(payload.description === undefined ? {} : { description: payload.description }),
2042
- ...(payload.target_url === undefined ? {} : { targetUrl: payload.target_url }),
2043
- sha: payload.sha,
2044
- ...(payload.name === undefined ? {} : { name: payload.name }),
2045
- branches: (payload.branches ?? []).map(branch => ({
2046
- name: branch.name,
2047
- ...(branch.commit === undefined ? {} : { commit: branch.commit }),
2048
- })),
2049
- ...(payload.commit === undefined
2050
- ? {}
2051
- : {
2052
- commit: {
2053
- ...(payload.commit.sha === undefined ? {} : { sha: payload.commit.sha }),
2054
- ...(payload.commit.html_url === undefined ? {} : { htmlUrl: payload.commit.html_url }),
2055
- },
2056
- }),
2057
- raw: args.payload,
2058
- };
2059
- const ctx: GitHubParsedContext = {
2060
- ...(args.deliveryId === undefined ? {} : { deliveryId: args.deliveryId }),
2061
- eventName: "status",
2062
- repository,
2063
- conversation: {
2064
- kind: "pull_request",
2065
- number: first?.number ?? 0,
2066
- url: first?.url ?? repository.url,
2067
- },
2068
- ...(sender === undefined ? {} : { sender, senderLogin: sender.login }),
2069
- ...(installationId === undefined ? {} : { installationId }),
2070
- };
2071
- return { ctx, status };
2072
- }
2073
-
2074
- function parseGenericEvent(args: {
2075
- eventName: string;
2076
- payload: unknown;
2077
- deliveryId?: string;
2078
- }): { ctx: GitHubParsedContext; event: GitHubRawEvent } | null {
2079
- const schema = z.object({
2080
- action: z.string().optional(),
2081
- repository: repositorySchema.optional(),
2082
- sender: senderSchema,
2083
- installation: installationSchema,
2084
- issue: z
2085
- .object({
2086
- number: z.number().int().positive(),
2087
- html_url: z.string().url().optional(),
2088
- pull_request: z.unknown().optional(),
2089
- })
2090
- .optional(),
2091
- pull_request: z
2092
- .object({
2093
- number: z.number().int().positive(),
2094
- html_url: z.string().url().optional(),
2095
- })
2096
- .optional(),
2097
- });
2098
- const parsed = schema.safeParse(args.payload);
2099
- if (!parsed.success) {
2100
- return null;
2101
- }
2102
- const payload = parsed.data;
2103
- if (payload.repository === undefined) {
2104
- return null;
2105
- }
2106
- const repository = toRepositoryRef(payload.repository);
2107
- const sender = toUser(payload.sender);
2108
- const installationId = payload.installation?.id;
2109
- const kind: GitHubConversationKind =
2110
- payload.issue?.pull_request !== undefined
2111
- ? "pull_request"
2112
- : payload.issue !== undefined
2113
- ? "issue"
2114
- : "pull_request";
2115
- const number = payload.issue?.number ?? payload.pull_request?.number ?? 0;
2116
- const url = payload.issue?.html_url ?? payload.pull_request?.html_url ?? repository.url;
2117
- const event: GitHubRawEvent = {
2118
- eventName: args.eventName,
2119
- ...(args.deliveryId === undefined ? {} : { deliveryId: args.deliveryId }),
2120
- ...(payload.action === undefined ? {} : { action: payload.action }),
2121
- payload: args.payload,
2122
- };
2123
- const ctx: GitHubParsedContext = {
2124
- ...(args.deliveryId === undefined ? {} : { deliveryId: args.deliveryId }),
2125
- eventName: args.eventName,
2126
- repository,
2127
- conversation: { kind, number, url },
2128
- ...(sender === undefined ? {} : { sender, senderLogin: sender.login }),
2129
- ...(installationId === undefined ? {} : { installationId }),
2130
- };
2131
- return { ctx, event };
2132
- }
2133
-
2134
- function unanchoredEventContext(args: {
2135
- deliveryId?: string;
2136
- eventName: string;
2137
- repository: GitHubRepositoryRef;
2138
- sender?: GitHubUser;
2139
- installationId?: number;
2140
- }): GitHubParsedContext {
2141
- return {
2142
- ...(args.deliveryId === undefined ? {} : { deliveryId: args.deliveryId }),
2143
- eventName: args.eventName,
2144
- repository: args.repository,
2145
- conversation: {
2146
- kind: "pull_request",
2147
- number: 0,
2148
- url: args.repository.url,
2149
- },
2150
- ...(args.sender === undefined ? {} : { sender: args.sender, senderLogin: args.sender.login }),
2151
- ...(args.installationId === undefined ? {} : { installationId: args.installationId }),
2152
- };
2153
- }
2154
-
2155
- function toRepositoryRef(repo: {
2156
- id?: number;
2157
- full_name: string;
2158
- html_url: string;
2159
- name?: string;
2160
- owner?: { login?: string };
2161
- }): GitHubRepositoryRef {
2162
- const [ownerFromName, nameFromFull] = repo.full_name.split("/");
2163
- return {
2164
- fullName: repo.full_name,
2165
- url: repo.html_url,
2166
- owner: repo.owner?.login ?? ownerFromName ?? "",
2167
- name: repo.name ?? nameFromFull ?? repo.full_name,
2168
- ...(repo.id === undefined ? {} : { id: repo.id }),
2169
- };
2170
- }
2171
-
2172
- function toUser(
2173
- raw:
2174
- | {
2175
- login?: string;
2176
- id?: number;
2177
- type?: string;
2178
- }
2179
- | null
2180
- | undefined,
2181
- ): GitHubUser | undefined {
2182
- if (raw?.login === undefined || raw.login === "") return undefined;
2183
- return {
2184
- login: raw.login,
2185
- ...(raw.id === undefined ? {} : { id: raw.id }),
2186
- ...(raw.type === undefined ? {} : { type: raw.type }),
2187
- };
2188
- }
2189
-
2190
- function toCiPullRequests(
2191
- raw: Array<{ number: number; url?: string; html_url?: string }> | undefined,
2192
- ): GitHubCiPullRequestRef[] {
2193
- return (raw ?? []).map(pr => ({
2194
- number: pr.number,
2195
- ...(pr.html_url !== undefined
2196
- ? { url: pr.html_url }
2197
- : pr.url !== undefined
2198
- ? { url: pr.url }
2199
- : {}),
2200
- }));
2201
- }
2202
-
2203
- function toCiApp(raw: { slug?: string; name?: string } | null | undefined): GitHubCiAppRef {
2204
- return {
2205
- ...(raw?.slug === undefined ? {} : { slug: raw.slug }),
2206
- ...(raw?.name === undefined ? {} : { name: raw.name }),
2207
- };
2208
- }
2209
-
2210
- function escapeRegExp(value: string): string {
2211
- return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
2212
- }
2213
-
2214
- /**
2215
- * Attach the GitHub API + thread handles to a parsed context, producing the
2216
- * full {@link GitHubEventContext} handed to inbound hooks.
2217
- */
2218
- function enrichEventContext(input: {
2219
- bindingConfig: GitHubBindingConfig;
2220
- ctx: GitHubParsedContext & Partial<Pick<GitHubEventContext, "github" | "thread">>;
2221
- bindingState: GitHubBindingState;
2222
- installationId?: number;
2223
- payload: unknown;
2224
- host: HostContext;
2225
- artifacts: ArtifactsApi;
2226
- send?: SendMessageFn;
2227
- }): GitHubEventContext {
2228
- const { github, thread } = buildGitHubBinding({
2229
- config: input.bindingConfig,
2230
- state: input.bindingState,
2231
- });
2232
- return {
2233
- ...input.ctx,
2234
- payload: input.payload,
2235
- ...(input.installationId === undefined ? {} : { installationId: input.installationId }),
2236
- github,
2237
- thread,
2238
- host: input.host,
2239
- artifacts: input.artifacts,
2240
- ...(input.send === undefined ? {} : { send: input.send }),
2241
- };
2242
- }
2243
-
2244
- /**
2245
- * Enrich an unanchored CI context (`conversation.number === 0`). The binding
2246
- * still resolves `github`, but `thread.post` throws until a PR is attached.
2247
- */
2248
- function enrichCiContext(input: {
2249
- bindingConfig: GitHubBindingConfig;
2250
- ctx: GitHubParsedContext;
2251
- installationId?: number;
2252
- payload: unknown;
2253
- host: HostContext;
2254
- artifacts: ArtifactsApi;
2255
- send?: SendMessageFn;
2256
- }): GitHubEventContext {
2257
- const binding = githubBindingStateForEvent({
2258
- kind: input.ctx.conversation.kind,
2259
- owner: input.ctx.repository.owner,
2260
- repo: input.ctx.repository.name,
2261
- number: input.ctx.conversation.number,
2262
- repositoryId: input.ctx.repository.id,
2263
- repositoryUrl: input.ctx.repository.url,
2264
- installationId: input.installationId,
2265
- });
2266
- return enrichEventContext({
2267
- bindingConfig: input.bindingConfig,
2268
- ctx: input.ctx,
2269
- bindingState: binding,
2270
- installationId: input.installationId,
2271
- payload: input.payload,
2272
- host: input.host,
2273
- artifacts: input.artifacts,
2274
- ...(input.send === undefined ? {} : { send: input.send }),
2275
- });
2276
- }
2277
-
2278
- /** Build the durable per-session channel state stored with the turn. */
2279
- function sessionStateFromBinding(input: {
2280
- binding: GitHubBindingState;
2281
- deliveryId?: string;
2282
- eventName: string;
2283
- headSha?: string;
2284
- baseRef?: string;
2285
- headRef?: string;
2286
- }): GitHubChannelState {
2287
- return emptyGitHubChannelState({
2288
- ...input.binding,
2289
- deliveryId: input.deliveryId ?? null,
2290
- eventName: input.eventName,
2291
- headSha: input.headSha ?? null,
2292
- baseRef: input.baseRef ?? null,
2293
- headRef: input.headRef ?? null,
2294
- });
2295
- }
2296
-
2297
- /** Read `installation.id` from a raw webhook payload when present. */
2298
- function readInstallationId(payload: unknown): number | undefined {
2299
- if (typeof payload !== "object" || payload === null) return undefined;
2300
- const installation = (payload as { installation?: { id?: number } }).installation;
2301
- return typeof installation?.id === "number" ? installation.id : undefined;
2302
- }
2303
-
2304
- function envWebhookSecret(): GitHubCredentialValue | undefined {
2305
- if (process.env.GITHUB_WEBHOOK_SECRET === undefined || process.env.GITHUB_WEBHOOK_SECRET === "") {
2306
- return undefined;
2307
- }
2308
- return () => process.env.GITHUB_WEBHOOK_SECRET;
2309
- }
2310
-
2311
- async function resolveCloudOptions(
2312
- cloud: GitHubChannelOptions["cloud"],
2313
- ctx: GitHubEventContext,
2314
- pullRequest: GitHubPullRequestEvent,
2315
- ): Promise<AgentCloudOptions | undefined> {
2316
- if (cloud === undefined || cloud === false) {
2317
- return undefined;
2318
- }
2319
- if (cloud === true) {
2320
- return {
2321
- repos: [
2322
- {
2323
- url: ctx.repository.url,
2324
- prUrl: pullRequest.url,
2325
- startingRef: pullRequest.headSha,
2326
- },
2327
- ],
2328
- };
2329
- }
2330
- if (typeof cloud === "function") {
2331
- return await cloud(ctx, pullRequest);
2332
- }
2333
- return cloud;
2334
- }