@cursor/bdk 0.2.24 → 0.2.26

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 (553) hide show
  1. package/AGENTS.md +4 -18
  2. package/CHANGELOG.md +3 -0
  3. package/dist/artifacts.d.ts +1 -1
  4. package/dist/artifacts.js +1 -1
  5. package/dist/bin/agent-serve.d.ts +1 -1
  6. package/dist/bin/agent-serve.js +71 -31
  7. package/dist/channels/bitbucket/api.d.ts +2 -2
  8. package/dist/channels/bitbucket/api.d.ts.map +1 -1
  9. package/dist/channels/bitbucket/bitbucket-channel.js +1 -1
  10. package/dist/channels/bitbucket/bitbucket-webhook.d.ts +5 -4
  11. package/dist/channels/bitbucket/bitbucket-webhook.d.ts.map +1 -1
  12. package/dist/channels/bitbucket/bitbucket-webhook.js +14 -9
  13. package/dist/channels/change-monitors/change-monitors-channel.js +1 -1
  14. package/dist/channels/deployments/deployments-channel.js +1 -1
  15. package/dist/channels/github/cursor-account.d.ts +7 -0
  16. package/dist/channels/github/cursor-account.d.ts.map +1 -1
  17. package/dist/channels/github/cursor-account.js +22 -5
  18. package/dist/channels/github/github-channel.d.ts.map +1 -1
  19. package/dist/channels/github/github-channel.js +10 -19
  20. package/dist/channels/github/replay.d.ts +1 -1
  21. package/dist/channels/github/replay.d.ts.map +1 -1
  22. package/dist/channels/gitlab/api.d.ts +2 -2
  23. package/dist/channels/gitlab/api.d.ts.map +1 -1
  24. package/dist/channels/gitlab/gitlab-channel.js +1 -1
  25. package/dist/channels/issues/issues-channel.js +1 -1
  26. package/dist/channels/origin/api.d.ts +4 -4
  27. package/dist/channels/origin/api.d.ts.map +1 -1
  28. package/dist/channels/origin/origin-channel.js +1 -1
  29. package/dist/channels/origin/origin-webhook.d.ts +3 -3
  30. package/dist/channels/origin/origin-webhook.d.ts.map +1 -1
  31. package/dist/channels/pagerduty/api.d.ts +74 -0
  32. package/dist/channels/pagerduty/api.d.ts.map +1 -0
  33. package/dist/channels/pagerduty/api.js +101 -0
  34. package/dist/channels/pagerduty/defaults.d.ts +42 -0
  35. package/dist/channels/pagerduty/defaults.d.ts.map +1 -0
  36. package/dist/channels/pagerduty/defaults.js +132 -0
  37. package/dist/channels/pagerduty/events.d.ts +24 -0
  38. package/dist/channels/pagerduty/events.d.ts.map +1 -0
  39. package/dist/channels/pagerduty/events.js +38 -0
  40. package/dist/channels/pagerduty/index.d.ts +31 -0
  41. package/dist/channels/pagerduty/index.d.ts.map +1 -0
  42. package/dist/channels/pagerduty/index.js +30 -0
  43. package/dist/channels/pagerduty/pagerduty-channel.d.ts +64 -0
  44. package/dist/channels/pagerduty/pagerduty-channel.d.ts.map +1 -0
  45. package/dist/channels/pagerduty/pagerduty-channel.js +195 -0
  46. package/dist/channels/pagerduty/pagerduty-webhook.d.ts +70 -0
  47. package/dist/channels/pagerduty/pagerduty-webhook.d.ts.map +1 -0
  48. package/dist/channels/pagerduty/pagerduty-webhook.js +280 -0
  49. package/dist/channels/pagerduty/payload.d.ts +33 -0
  50. package/dist/channels/pagerduty/payload.d.ts.map +1 -0
  51. package/dist/channels/pagerduty/payload.js +150 -0
  52. package/dist/channels/pagerduty/replay.d.ts +35 -0
  53. package/dist/channels/pagerduty/replay.d.ts.map +1 -0
  54. package/dist/channels/pagerduty/replay.js +115 -0
  55. package/dist/channels/pagerduty/secrets.d.ts +16 -0
  56. package/dist/channels/pagerduty/secrets.d.ts.map +1 -0
  57. package/dist/channels/pagerduty/secrets.js +23 -0
  58. package/dist/channels/pagerduty/self-user.d.ts +51 -0
  59. package/dist/channels/pagerduty/self-user.d.ts.map +1 -0
  60. package/dist/channels/pagerduty/self-user.js +157 -0
  61. package/dist/channels/pagerduty/state.d.ts +31 -0
  62. package/dist/channels/pagerduty/state.d.ts.map +1 -0
  63. package/dist/channels/pagerduty/state.js +30 -0
  64. package/dist/channels/pagerduty/types.d.ts +217 -0
  65. package/dist/channels/pagerduty/types.d.ts.map +1 -0
  66. package/dist/channels/pagerduty/types.js +1 -0
  67. package/dist/channels/runs/runs-channel.js +1 -1
  68. package/dist/channels/slack/agentic-delivery.d.ts +2 -1
  69. package/dist/channels/slack/agentic-delivery.d.ts.map +1 -1
  70. package/dist/channels/slack/agentic-delivery.js +6 -10
  71. package/dist/channels/slack/agentic-signals.d.ts +2 -7
  72. package/dist/channels/slack/agentic-signals.d.ts.map +1 -1
  73. package/dist/channels/slack/agentic-signals.js +4 -3
  74. package/dist/channels/slack/api.d.ts +1 -0
  75. package/dist/channels/slack/api.d.ts.map +1 -1
  76. package/dist/channels/slack/api.js +3 -0
  77. package/dist/channels/slack/constants.d.ts +2 -0
  78. package/dist/channels/slack/constants.d.ts.map +1 -1
  79. package/dist/channels/slack/constants.js +2 -0
  80. package/dist/channels/slack/defaults.d.ts.map +1 -1
  81. package/dist/channels/slack/defaults.js +3 -2
  82. package/dist/channels/slack/dispatch.d.ts +9 -0
  83. package/dist/channels/slack/dispatch.d.ts.map +1 -1
  84. package/dist/channels/slack/dispatch.js +3 -0
  85. package/dist/channels/slack/inbound.d.ts.map +1 -1
  86. package/dist/channels/slack/inbound.js +24 -20
  87. package/dist/channels/slack/interactive.d.ts +2 -0
  88. package/dist/channels/slack/interactive.d.ts.map +1 -1
  89. package/dist/channels/slack/interactive.js +1 -0
  90. package/dist/channels/slack/live-delivery.d.ts +3 -0
  91. package/dist/channels/slack/live-delivery.d.ts.map +1 -1
  92. package/dist/channels/slack/live-delivery.js +5 -0
  93. package/dist/channels/slack/reply-options.d.ts +9 -0
  94. package/dist/channels/slack/reply-options.d.ts.map +1 -1
  95. package/dist/channels/slack/reply-options.js +31 -1
  96. package/dist/channels/slack/slack-channel.d.ts.map +1 -1
  97. package/dist/channels/slack/slack-channel.js +7 -0
  98. package/dist/channels/slack/stream.d.ts +5 -1
  99. package/dist/channels/slack/stream.d.ts.map +1 -1
  100. package/dist/channels/slack/types.d.ts +29 -0
  101. package/dist/channels/slack/types.d.ts.map +1 -1
  102. package/dist/channels.d.ts +7 -1
  103. package/dist/channels.d.ts.map +1 -1
  104. package/dist/channels.js +12 -24
  105. package/dist/docs/404.html +3 -3
  106. package/dist/docs/assets/{app.DTIg0uKK.js → app.BITbgXMP.js} +4 -4
  107. package/dist/docs/assets/changelog.md.sdD6ctqK.js +1 -0
  108. package/dist/docs/assets/changelog.md.sdD6ctqK.lean.js +1 -0
  109. package/dist/docs/assets/chunks/@localSearchIndexroot.B45uCZp9.js +1 -0
  110. package/dist/docs/assets/chunks/{VPLocalSearchBox.BpJoSaxi.js → VPLocalSearchBox.3qo4-bX9.js} +2 -2
  111. package/dist/docs/assets/chunks/{arc.ylgNvRNq.js → arc.CTrZocKU.js} +1 -1
  112. package/dist/docs/assets/chunks/{architectureDiagram-Q4EWVU46.BMrNJqYk.js → architectureDiagram-Q4EWVU46.BkgIqxrv.js} +1 -1
  113. package/dist/docs/assets/chunks/{baseUniq.BBWUEqf9.js → baseUniq.5w0JfVgo.js} +1 -1
  114. package/dist/docs/assets/chunks/{blockDiagram-DXYQGD6D.DFMu-Vza.js → blockDiagram-DXYQGD6D.BVLtPjQc.js} +1 -1
  115. package/dist/docs/assets/chunks/{c4Diagram-AHTNJAMY.8nkAAxWv.js → c4Diagram-AHTNJAMY.CQ7neZTW.js} +1 -1
  116. package/dist/docs/assets/chunks/channel.Cv2w64wj.js +1 -0
  117. package/dist/docs/assets/chunks/{chunk-4BX2VUAB.sO-z2Bag.js → chunk-4BX2VUAB.D-hJ7uKM.js} +1 -1
  118. package/dist/docs/assets/chunks/{chunk-4TB4RGXK.BMROzTMq.js → chunk-4TB4RGXK.RBYX5ywX.js} +1 -1
  119. package/dist/docs/assets/chunks/{chunk-55IACEB6.X81urwg7.js → chunk-55IACEB6.Br05HoEb.js} +1 -1
  120. package/dist/docs/assets/chunks/{chunk-EDXVE4YY.eaZVFLZM.js → chunk-EDXVE4YY.BD_7QS60.js} +1 -1
  121. package/dist/docs/assets/chunks/{chunk-FMBD7UC4.CmZhzstR.js → chunk-FMBD7UC4.BOPnMabX.js} +1 -1
  122. package/dist/docs/assets/chunks/{chunk-OYMX7WX6.CTezt9Lc.js → chunk-OYMX7WX6.DmGIdP8i.js} +1 -1
  123. package/dist/docs/assets/chunks/{chunk-QZHKN3VN.s-T8zukB.js → chunk-QZHKN3VN.CGHmolCB.js} +1 -1
  124. package/dist/docs/assets/chunks/{chunk-YZCP3GAM.DN4Nhy-D.js → chunk-YZCP3GAM.C_Uhs25v.js} +1 -1
  125. package/dist/docs/assets/chunks/classDiagram-6PBFFD2Q.CtO2atCr.js +1 -0
  126. package/dist/docs/assets/chunks/classDiagram-v2-HSJHXN6E.CtO2atCr.js +1 -0
  127. package/dist/docs/assets/chunks/clone.hfsCtgP4.js +1 -0
  128. package/dist/docs/assets/chunks/{cose-bilkent-S5V4N54A.Cqyp4BUH.js → cose-bilkent-S5V4N54A.DsU6xpcZ.js} +1 -1
  129. package/dist/docs/assets/chunks/{dagre-KV5264BT.BIECOiqR.js → dagre-KV5264BT.BqQLDcoU.js} +1 -1
  130. package/dist/docs/assets/chunks/{diagram-5BDNPKRD.1tLyWoTg.js → diagram-5BDNPKRD.Cgv8uUNF.js} +1 -1
  131. package/dist/docs/assets/chunks/{diagram-G4DWMVQ6.BVY_6VMO.js → diagram-G4DWMVQ6.BXHPSXh_.js} +1 -1
  132. package/dist/docs/assets/chunks/{diagram-MMDJMWI5.BSZ7xiBB.js → diagram-MMDJMWI5.CgJzo8f_.js} +1 -1
  133. package/dist/docs/assets/chunks/{diagram-TYMM5635.Bho6GmLh.js → diagram-TYMM5635.CfiN6lgT.js} +1 -1
  134. package/dist/docs/assets/chunks/{erDiagram-SMLLAGMA.A0yVIANn.js → erDiagram-SMLLAGMA.8n_hHzAd.js} +1 -1
  135. package/dist/docs/assets/chunks/{flowDiagram-DWJPFMVM.ZMgbllH6.js → flowDiagram-DWJPFMVM.B2pb1Dv_.js} +1 -1
  136. package/dist/docs/assets/chunks/{ganttDiagram-T4ZO3ILL.BCCPBhXo.js → ganttDiagram-T4ZO3ILL.BFih4ucI.js} +1 -1
  137. package/dist/docs/assets/chunks/{gitGraphDiagram-UUTBAWPF.BOkL0BbA.js → gitGraphDiagram-UUTBAWPF.CqZ8PTl8.js} +1 -1
  138. package/dist/docs/assets/chunks/{graph.DMyZPu86.js → graph.0ufsI9gu.js} +1 -1
  139. package/dist/docs/assets/chunks/{infoDiagram-42DDH7IO.CjG1IiEw.js → infoDiagram-42DDH7IO.BkPRFww4.js} +1 -1
  140. package/dist/docs/assets/chunks/{ishikawaDiagram-UXIWVN3A.UCe-kq9g.js → ishikawaDiagram-UXIWVN3A.DCRK-cVX.js} +1 -1
  141. package/dist/docs/assets/chunks/{journeyDiagram-VCZTEJTY.3WyOK_eY.js → journeyDiagram-VCZTEJTY.BFyAJo33.js} +1 -1
  142. package/dist/docs/assets/chunks/{kanban-definition-6JOO6SKY.WoRG2qY1.js → kanban-definition-6JOO6SKY.CmA2SoGc.js} +1 -1
  143. package/dist/docs/assets/chunks/{layout.DV07xDd5.js → layout.CYY-CbMr.js} +1 -1
  144. package/dist/docs/assets/chunks/{linear.CTO8mN6o.js → linear.DeeDV4Oq.js} +1 -1
  145. package/dist/docs/assets/chunks/{min.SvTtcKuZ.js → min.BL3XTBN2.js} +1 -1
  146. package/dist/docs/assets/chunks/{mindmap-definition-QFDTVHPH.DMGgQ-HB.js → mindmap-definition-QFDTVHPH.BcbY-G6H.js} +1 -1
  147. package/dist/docs/assets/chunks/{pieDiagram-DEJITSTG.B7851apI.js → pieDiagram-DEJITSTG.dzDcQnPE.js} +1 -1
  148. package/dist/docs/assets/chunks/{quadrantDiagram-34T5L4WZ.CEqyypIX.js → quadrantDiagram-34T5L4WZ.RxR0m5iK.js} +1 -1
  149. package/dist/docs/assets/chunks/{requirementDiagram-MS252O5E.C3Mwsw-H.js → requirementDiagram-MS252O5E.DflaXb6Q.js} +1 -1
  150. package/dist/docs/assets/chunks/{sankeyDiagram-XADWPNL6.DyYK0XxY.js → sankeyDiagram-XADWPNL6.BteLKQAe.js} +1 -1
  151. package/dist/docs/assets/chunks/{sequenceDiagram-FGHM5R23.SiQPH-XM.js → sequenceDiagram-FGHM5R23.BD8jM8oz.js} +1 -1
  152. package/dist/docs/assets/chunks/{stateDiagram-FHFEXIEX.CTJMsP4p.js → stateDiagram-FHFEXIEX.C8SBkbPH.js} +1 -1
  153. package/dist/docs/assets/chunks/stateDiagram-v2-QKLJ7IA2.BLz7Qyo3.js +1 -0
  154. package/dist/docs/assets/chunks/{theme.DJo4my9R.js → theme.DiViIOLe.js} +2 -2
  155. package/dist/docs/assets/chunks/{timeline-definition-GMOUNBTQ.CxSNRlQ6.js → timeline-definition-GMOUNBTQ.D64XF5dV.js} +1 -1
  156. package/dist/docs/assets/chunks/{vennDiagram-DHZGUBPP.BdoJskyD.js → vennDiagram-DHZGUBPP.CwmeYan-.js} +1 -1
  157. package/dist/docs/assets/chunks/wardley-RL74JXVD.DmAlXlpu.js +162 -0
  158. package/dist/docs/assets/chunks/{wardleyDiagram-NUSXRM2D.IjIbFn_F.js → wardleyDiagram-NUSXRM2D.5VJ2-5K0.js} +1 -1
  159. package/dist/docs/assets/chunks/{xychartDiagram-5P7HB3ND.CPUxDZLH.js → xychartDiagram-5P7HB3ND.Cl6_fZVC.js} +1 -1
  160. package/dist/docs/assets/{guides_hooks.md.Bfj0pK91.js → guides_hooks.md.B2XfGX50.js} +7 -3
  161. package/dist/docs/assets/{guides_mcp-oauth.md.BM_eFC0L.js → guides_mcp-oauth.md.Cxq2TxBB.js} +3 -3
  162. package/dist/docs/assets/{guides_mcp-oauth.md.BM_eFC0L.lean.js → guides_mcp-oauth.md.Cxq2TxBB.lean.js} +1 -1
  163. package/dist/docs/assets/guides_opentelemetry.md.D4wO7_8v.js +37 -0
  164. package/dist/docs/assets/guides_opentelemetry.md.D4wO7_8v.lean.js +1 -0
  165. package/dist/docs/assets/guides_pagerduty.md.BHXMcMtx.js +60 -0
  166. package/dist/docs/assets/guides_pagerduty.md.BHXMcMtx.lean.js +1 -0
  167. package/dist/docs/assets/{guides_slack.md.Bn-WupSE.js → guides_slack.md.ClIyi7FI.js} +8 -3
  168. package/dist/docs/assets/{guides_slack.md.Bn-WupSE.lean.js → guides_slack.md.ClIyi7FI.lean.js} +1 -1
  169. package/dist/docs/assets/{reference_agent-config.md.IplwL25I.js → reference_agent-config.md.CGSx8COP.js} +6 -2
  170. package/dist/docs/assets/{reference_agent-config.md.IplwL25I.lean.js → reference_agent-config.md.CGSx8COP.lean.js} +1 -1
  171. package/dist/docs/assets/{reference_channels.md.DYg0CLud.js → reference_channels.md.CNNIS6K7.js} +1 -1
  172. package/dist/docs/assets/{reference_cli.md.DB7Llw3T.js → reference_cli.md.1o_TqKdt.js} +7 -2
  173. package/dist/docs/assets/{reference_cli.md.DB7Llw3T.lean.js → reference_cli.md.1o_TqKdt.lean.js} +1 -1
  174. package/dist/docs/assets/{reference_hooks.md.B1jq3oGl.js → reference_hooks.md.CROr0QgC.js} +13 -7
  175. package/dist/docs/assets/{reference_hooks.md.B1jq3oGl.lean.js → reference_hooks.md.CROr0QgC.lean.js} +1 -1
  176. package/dist/docs/assets/{reference_schedules.md.03Ryy9ca.js → reference_schedules.md.BqWnJES4.js} +3 -3
  177. package/dist/docs/assets/reference_sessions.md.Bi6lHttM.js +22 -0
  178. package/dist/docs/assets/reference_sessions.md.Bi6lHttM.lean.js +1 -0
  179. package/dist/docs/assets/{reference_skills.md.C2GWh7g8.js → reference_skills.md.Ckddg6KX.js} +3 -3
  180. package/dist/docs/assets/{reference_tools.md.08XR7lIl.js → reference_tools.md.Bo0UfT0a.js} +1 -1
  181. package/dist/docs/assets/{style.nMsabY-V.css → style.B9o0luvp.css} +1 -1
  182. package/dist/docs/building-with-agents.html +37 -37
  183. package/dist/docs/changelog.html +60 -0
  184. package/dist/docs/changelog.md +86 -0
  185. package/dist/docs/deployment.html +37 -37
  186. package/dist/docs/evals.html +37 -37
  187. package/dist/docs/guides/agent-to-agent.html +37 -37
  188. package/dist/docs/guides/bitbucket.html +37 -37
  189. package/dist/docs/guides/cloud-agents.html +37 -37
  190. package/dist/docs/guides/convert-automation.html +37 -37
  191. package/dist/docs/guides/export-grokbot.html +37 -37
  192. package/dist/docs/guides/github.html +37 -37
  193. package/dist/docs/guides/gitlab.html +37 -37
  194. package/dist/docs/guides/grokbot-agents.html +37 -37
  195. package/dist/docs/guides/hooks.html +45 -41
  196. package/dist/docs/guides/hooks.md +7 -3
  197. package/dist/docs/guides/improve.html +37 -37
  198. package/dist/docs/guides/jev.html +37 -37
  199. package/dist/docs/guides/mcp-oauth.html +39 -39
  200. package/dist/docs/guides/mcp-oauth.md +12 -0
  201. package/dist/docs/guides/migrate.html +37 -37
  202. package/dist/docs/guides/opentelemetry.html +62 -70
  203. package/dist/docs/guides/opentelemetry.md +150 -175
  204. package/dist/docs/guides/pagerduty.html +119 -0
  205. package/dist/docs/guides/pagerduty.md +336 -0
  206. package/dist/docs/guides/slack.html +44 -39
  207. package/dist/docs/guides/slack.md +41 -0
  208. package/dist/docs/guides/webhooks.html +37 -37
  209. package/dist/docs/hashmap.json +1 -1
  210. package/dist/docs/hillclimbing.html +37 -37
  211. package/dist/docs/index.html +37 -37
  212. package/dist/docs/llms-full.txt +730 -163
  213. package/dist/docs/llms.txt +3 -1
  214. package/dist/docs/quickstart.html +37 -37
  215. package/dist/docs/reference/agent-config.html +42 -38
  216. package/dist/docs/reference/agent-config.md +21 -1
  217. package/dist/docs/reference/artifacts.html +37 -37
  218. package/dist/docs/reference/channels.html +38 -38
  219. package/dist/docs/reference/channels.md +7 -2
  220. package/dist/docs/reference/cli.html +43 -38
  221. package/dist/docs/reference/cli.md +27 -0
  222. package/dist/docs/reference/connections.html +37 -37
  223. package/dist/docs/reference/evals.html +37 -37
  224. package/dist/docs/reference/extensions.html +37 -37
  225. package/dist/docs/reference/hooks.html +49 -43
  226. package/dist/docs/reference/hooks.md +10 -5
  227. package/dist/docs/reference/http-api.html +37 -37
  228. package/dist/docs/reference/instructions.html +37 -37
  229. package/dist/docs/reference/memory.html +37 -37
  230. package/dist/docs/reference/playground.html +36 -36
  231. package/dist/docs/reference/project-layout.html +37 -37
  232. package/dist/docs/reference/prompt.html +37 -37
  233. package/dist/docs/reference/schedules.html +40 -40
  234. package/dist/docs/reference/sessions.html +58 -37
  235. package/dist/docs/reference/sessions.md +46 -1
  236. package/dist/docs/reference/skills.html +40 -40
  237. package/dist/docs/reference/subagents.html +37 -37
  238. package/dist/docs/reference/tools.html +39 -39
  239. package/dist/docs/reference/tools.md +4 -3
  240. package/dist/docs/templates/agentic-owners.html +37 -37
  241. package/dist/docs/templates/grokbot-agents.html +37 -37
  242. package/dist/docs/templates/security-reviewer.html +37 -37
  243. package/dist/docs/templates/thermo-quality-review.html +37 -37
  244. package/dist/docs/templates/thermo-review.html +37 -37
  245. package/dist/docs/templates/triage.html +37 -37
  246. package/dist/docs/troubleshooting.html +36 -36
  247. package/dist/extensions/cursor-cloud-agents/extension.d.ts.map +1 -1
  248. package/dist/extensions/cursor-cloud-agents/extension.js +15 -15
  249. package/dist/extensions/cursor-cloud-agents/lib/backend.js +1 -1
  250. package/dist/extensions/cursor-cloud-agents/lib/fleet.js +1 -1
  251. package/dist/extensions/cursor-cloud-agents/lib/inputs.d.ts +1 -1
  252. package/dist/extensions/cursor-cloud-agents/lib/inputs.d.ts.map +1 -1
  253. package/dist/extensions/cursor-cloud-agents/lib/inputs.js +1 -1
  254. package/dist/extensions/cursor-cloud-agents/reminders/cloud-agent-stop-watch.js +1 -1
  255. package/dist/extensions/cursor-cloud-agents/tools/launch.js +1 -1
  256. package/dist/extensions/cursor-cloud-agents/tools/list.js +1 -1
  257. package/dist/extensions/cursor-cloud-agents/tools/reply.js +1 -1
  258. package/dist/extensions/cursor-grokbot-agents/extension.d.ts.map +1 -1
  259. package/dist/extensions/cursor-grokbot-agents/extension.js +7 -3
  260. package/dist/extensions/cursor-grokbot-agents/lib/backend.js +1 -1
  261. package/dist/extensions/cursor-grokbot-agents/lib/contacts.js +1 -1
  262. package/dist/extensions/cursor-grokbot-agents/lib/inputs.d.ts +1 -1
  263. package/dist/extensions/cursor-grokbot-agents/lib/inputs.d.ts.map +1 -1
  264. package/dist/extensions/cursor-grokbot-agents/lib/inputs.js +1 -1
  265. package/dist/extensions/cursor-grokbot-agents/tools/ask.js +1 -1
  266. package/dist/extensions/cursor-grokbot-agents/tools/check.js +1 -1
  267. package/dist/extensions/cursor-grokbot-agents/tools/interrupt.js +1 -1
  268. package/dist/extensions/cursor-grokbot-agents/tools/list.js +1 -1
  269. package/dist/extensions/improve/extension.js +1 -1
  270. package/dist/extensions/jev/extension.js +2 -2
  271. package/dist/extensions/jev/tools/evaluate.js +3 -3
  272. package/dist/extensions/slack-communication/extension.js +1 -1
  273. package/dist/extensions/slack-communication/tools/delete-message.js +1 -1
  274. package/dist/extensions/slack-communication/tools/edit-message.d.ts.map +1 -1
  275. package/dist/extensions/slack-communication/tools/edit-message.js +3 -6
  276. package/dist/extensions/slack-communication/tools/post-card.js +1 -1
  277. package/dist/extensions/slack-communication/tools/post-file.js +1 -1
  278. package/dist/extensions/slack-communication/tools/post-update.d.ts.map +1 -1
  279. package/dist/extensions/slack-communication/tools/post-update.js +3 -6
  280. package/dist/extensions/slack-communication/tools/react.js +1 -1
  281. package/dist/extensions/slack-communication/tools/set-status.js +1 -1
  282. package/dist/extensions.d.ts +1 -1
  283. package/dist/extensions.js +1 -1
  284. package/dist/index.d.ts +14 -11
  285. package/dist/index.d.ts.map +1 -1
  286. package/dist/index.js +8 -4
  287. package/dist/internal/approval-gate.d.ts +4 -2
  288. package/dist/internal/approval-gate.d.ts.map +1 -1
  289. package/dist/internal/approval-gate.js +2 -1
  290. package/dist/internal/as-of.d.ts +2 -0
  291. package/dist/internal/as-of.d.ts.map +1 -1
  292. package/dist/internal/as-of.js +2 -0
  293. package/dist/internal/builtin-tools/artifacts.d.ts.map +1 -1
  294. package/dist/internal/builtin-tools/artifacts.js +45 -12
  295. package/dist/internal/builtin-tools/reminders.js +1 -1
  296. package/dist/internal/channel-architecture.d.ts +1 -1
  297. package/dist/internal/channel-architecture.d.ts.map +1 -1
  298. package/dist/internal/channel-architecture.js +4 -2
  299. package/dist/internal/cli-deploy.d.ts.map +1 -1
  300. package/dist/internal/cli-deploy.js +39 -22
  301. package/dist/internal/cli-pagerduty.d.ts +32 -0
  302. package/dist/internal/cli-pagerduty.d.ts.map +1 -0
  303. package/dist/internal/cli-pagerduty.js +242 -0
  304. package/dist/internal/continuation-channel.d.ts.map +1 -1
  305. package/dist/internal/continuation-channel.js +7 -0
  306. package/dist/internal/continuation-identity.d.ts +11 -3
  307. package/dist/internal/continuation-identity.d.ts.map +1 -1
  308. package/dist/internal/continuation-identity.js +83 -0
  309. package/dist/internal/continuation.d.ts +3 -0
  310. package/dist/internal/continuation.d.ts.map +1 -0
  311. package/dist/internal/continuation.js +1 -0
  312. package/dist/internal/conversation-mirror.d.ts +5 -0
  313. package/dist/internal/conversation-mirror.d.ts.map +1 -1
  314. package/dist/internal/conversation-mirror.js +12 -1
  315. package/dist/internal/convert-automation/convert-workflow.js +1 -1
  316. package/dist/internal/convert-grokbot/answers.d.ts.map +1 -1
  317. package/dist/internal/convert-grokbot/answers.js +10 -8
  318. package/dist/internal/convert-grokbot/recipe.d.ts +1 -1
  319. package/dist/internal/convert-grokbot/recipe.d.ts.map +1 -1
  320. package/dist/internal/convert-grokbot/recipe.js +1 -1
  321. package/dist/internal/cursor/account-mcp.d.ts.map +1 -1
  322. package/dist/internal/cursor/account-mcp.js +2 -0
  323. package/dist/internal/cursor/backend-client.d.ts +8 -3
  324. package/dist/internal/cursor/backend-client.d.ts.map +1 -1
  325. package/dist/internal/cursor/backend-client.js +8 -3
  326. package/dist/internal/cursor/credentials.d.ts +2 -2
  327. package/dist/internal/cursor/credentials.d.ts.map +1 -1
  328. package/dist/internal/cursor/credentials.js +1 -1
  329. package/dist/internal/cursor-account-mcp-auth.d.ts +6 -2
  330. package/dist/internal/cursor-account-mcp-auth.d.ts.map +1 -1
  331. package/dist/internal/cursor-account-mcp-auth.js +15 -6
  332. package/dist/internal/deferred-channel-session.d.ts +5 -4
  333. package/dist/internal/deferred-channel-session.d.ts.map +1 -1
  334. package/dist/internal/deferred-channel-session.js +6 -4
  335. package/dist/internal/deploy-client.d.ts +5 -0
  336. package/dist/internal/deploy-client.d.ts.map +1 -1
  337. package/dist/internal/deploy-client.js +3 -3
  338. package/dist/internal/deploy-manifest.d.ts +11 -4
  339. package/dist/internal/deploy-manifest.d.ts.map +1 -1
  340. package/dist/internal/deploy-manifest.js +19 -7
  341. package/dist/internal/describe-error.d.ts +2 -0
  342. package/dist/internal/describe-error.d.ts.map +1 -1
  343. package/dist/internal/describe-error.js +2 -0
  344. package/dist/internal/discovery/agent-config.d.ts.map +1 -1
  345. package/dist/internal/discovery/agent-config.js +10 -10
  346. package/dist/internal/discovery/agent.d.ts.map +1 -1
  347. package/dist/internal/discovery/agent.js +10 -10
  348. package/dist/internal/discovery/channels.d.ts.map +1 -1
  349. package/dist/internal/discovery/channels.js +20 -16
  350. package/dist/internal/discovery/context.d.ts +16 -0
  351. package/dist/internal/discovery/context.d.ts.map +1 -1
  352. package/dist/internal/discovery/context.js +67 -2
  353. package/dist/internal/discovery/cursor-plugin.js +8 -8
  354. package/dist/internal/discovery/extension-overlay.d.ts.map +1 -1
  355. package/dist/internal/discovery/extension-overlay.js +2 -6
  356. package/dist/internal/discovery/extensions.js +15 -8
  357. package/dist/internal/discovery/info.d.ts +2 -2
  358. package/dist/internal/discovery/info.d.ts.map +1 -1
  359. package/dist/internal/discovery/info.js +9 -9
  360. package/dist/internal/discovery/instructions.d.ts.map +1 -1
  361. package/dist/internal/discovery/instructions.js +3 -6
  362. package/dist/internal/discovery/instrumentation.d.ts +10 -0
  363. package/dist/internal/discovery/instrumentation.d.ts.map +1 -0
  364. package/dist/internal/discovery/instrumentation.js +29 -0
  365. package/dist/internal/discovery/modules.d.ts.map +1 -1
  366. package/dist/internal/discovery/modules.js +7 -10
  367. package/dist/internal/discovery/project-public.d.ts +16 -0
  368. package/dist/internal/discovery/project-public.d.ts.map +1 -0
  369. package/dist/internal/discovery/project-public.js +54 -0
  370. package/dist/internal/discovery/project.d.ts +6 -0
  371. package/dist/internal/discovery/project.d.ts.map +1 -1
  372. package/dist/internal/discovery/project.js +40 -8
  373. package/dist/internal/discovery/runtime.d.ts.map +1 -1
  374. package/dist/internal/discovery/runtime.js +8 -8
  375. package/dist/internal/discovery/services.d.ts +5 -4
  376. package/dist/internal/discovery/services.d.ts.map +1 -1
  377. package/dist/internal/discovery/services.js +12 -6
  378. package/dist/internal/discovery.d.ts +1 -1
  379. package/dist/internal/discovery.d.ts.map +1 -1
  380. package/dist/internal/discovery.js +1 -1
  381. package/dist/internal/event-mapper.d.ts.map +1 -1
  382. package/dist/internal/event-mapper.js +1 -0
  383. package/dist/internal/expected-delivery-failure.d.ts.map +1 -1
  384. package/dist/internal/expected-delivery-failure.js +6 -0
  385. package/dist/internal/factory-resource-channel.d.ts +1 -1
  386. package/dist/internal/factory-resource-channel.d.ts.map +1 -1
  387. package/dist/internal/filesystem/nearest.d.ts +1 -0
  388. package/dist/internal/filesystem/nearest.d.ts.map +1 -1
  389. package/dist/internal/filesystem/nearest.js +1 -0
  390. package/dist/internal/filesystem/sdk-schemas.d.ts.map +1 -1
  391. package/dist/internal/filesystem/sdk-schemas.js +4 -3
  392. package/dist/internal/filesystem/tools.d.ts.map +1 -1
  393. package/dist/internal/filesystem/tools.js +1 -1
  394. package/dist/internal/handleAgentServeTrigger.d.ts +10 -0
  395. package/dist/internal/handleAgentServeTrigger.d.ts.map +1 -1
  396. package/dist/internal/handleAgentServeTrigger.js +3 -0
  397. package/dist/internal/hmac-secret-values.d.ts +48 -0
  398. package/dist/internal/hmac-secret-values.d.ts.map +1 -0
  399. package/dist/internal/hmac-secret-values.js +68 -0
  400. package/dist/internal/host-otel.d.ts +1 -1
  401. package/dist/internal/host-otel.d.ts.map +1 -1
  402. package/dist/internal/host-otel.js +5 -0
  403. package/dist/internal/host-platforms.d.ts.map +1 -1
  404. package/dist/internal/host-platforms.js +8 -2
  405. package/dist/internal/hosted-delivery.d.ts.map +1 -1
  406. package/dist/internal/hosted-delivery.js +6 -2
  407. package/dist/internal/http-channel.d.ts.map +1 -1
  408. package/dist/internal/http-channel.js +1 -0
  409. package/dist/internal/ids.d.ts +8 -0
  410. package/dist/internal/ids.d.ts.map +1 -1
  411. package/dist/internal/ids.js +20 -0
  412. package/dist/internal/init-scaffold.js +1 -1
  413. package/dist/internal/interview/agent-questions.d.ts +1 -1
  414. package/dist/internal/interview/agent-questions.d.ts.map +1 -1
  415. package/dist/internal/interview/agent-questions.js +1 -1
  416. package/dist/internal/interview/question.d.ts +2 -2
  417. package/dist/internal/interview/question.d.ts.map +1 -1
  418. package/dist/internal/interview/question.js +2 -2
  419. package/dist/internal/json-schema.d.ts +7 -7
  420. package/dist/internal/json-schema.d.ts.map +1 -1
  421. package/dist/internal/json-schema.js +16 -23
  422. package/dist/internal/mcp-endpoint.d.ts +16 -4
  423. package/dist/internal/mcp-endpoint.d.ts.map +1 -1
  424. package/dist/internal/mcp-endpoint.js +18 -6
  425. package/dist/internal/mcp-host.d.ts +9 -0
  426. package/dist/internal/mcp-host.d.ts.map +1 -1
  427. package/dist/internal/mcp-host.js +15 -0
  428. package/dist/internal/otel/collector.d.ts +5 -0
  429. package/dist/internal/otel/collector.d.ts.map +1 -1
  430. package/dist/internal/otel/collector.js +27 -6
  431. package/dist/internal/otel/config.d.ts +37 -22
  432. package/dist/internal/otel/config.d.ts.map +1 -1
  433. package/dist/internal/otel/config.js +132 -125
  434. package/dist/internal/otel/conversation-span-processor.d.ts +9 -0
  435. package/dist/internal/otel/conversation-span-processor.d.ts.map +1 -0
  436. package/dist/internal/otel/conversation-span-processor.js +34 -0
  437. package/dist/internal/otel/customer.d.ts +52 -0
  438. package/dist/internal/otel/customer.d.ts.map +1 -0
  439. package/dist/internal/otel/customer.js +727 -0
  440. package/dist/internal/otel/runtime.d.ts +12 -16
  441. package/dist/internal/otel/runtime.d.ts.map +1 -1
  442. package/dist/internal/otel/runtime.js +37 -218
  443. package/dist/internal/otel-env.d.ts +6 -0
  444. package/dist/internal/otel-env.d.ts.map +1 -0
  445. package/dist/internal/otel-env.js +5 -0
  446. package/dist/internal/package-inline-stdio.d.ts.map +1 -1
  447. package/dist/internal/package-inline-stdio.js +21 -6
  448. package/dist/internal/reminder-runner.d.ts +9 -4
  449. package/dist/internal/reminder-runner.d.ts.map +1 -1
  450. package/dist/internal/reminder-runner.js +12 -10
  451. package/dist/internal/reminder-schedule.d.ts +1 -0
  452. package/dist/internal/reminder-schedule.d.ts.map +1 -1
  453. package/dist/internal/reminder-schedule.js +1 -0
  454. package/dist/internal/sdk-runner.d.ts +4 -3
  455. package/dist/internal/sdk-runner.d.ts.map +1 -1
  456. package/dist/internal/sdk-runner.js +157 -17
  457. package/dist/internal/secret-alternatives.d.ts +11 -0
  458. package/dist/internal/secret-alternatives.d.ts.map +1 -0
  459. package/dist/internal/secret-alternatives.js +13 -0
  460. package/dist/internal/server.d.ts +4 -1
  461. package/dist/internal/server.d.ts.map +1 -1
  462. package/dist/internal/server.js +27 -26
  463. package/dist/internal/session-engine.d.ts +27 -0
  464. package/dist/internal/session-engine.d.ts.map +1 -1
  465. package/dist/internal/session-engine.js +154 -25
  466. package/dist/internal/slack-provision-client.js +1 -1
  467. package/dist/internal/sqlite-experimental-warning.d.ts +2 -0
  468. package/dist/internal/sqlite-experimental-warning.d.ts.map +1 -0
  469. package/dist/internal/sqlite-experimental-warning.js +22 -0
  470. package/dist/internal/store-api-protocol.d.ts +1 -1
  471. package/dist/internal/store-api-protocol.d.ts.map +1 -1
  472. package/dist/internal/store-api-protocol.js +1 -1
  473. package/dist/internal/testing/conversation-identity-vectors.d.ts +6 -1
  474. package/dist/internal/testing/conversation-identity-vectors.d.ts.map +1 -1
  475. package/dist/internal/testing/conversation-identity-vectors.js +34 -0
  476. package/dist/internal/testing/hmac-secret-vectors.d.ts +38 -0
  477. package/dist/internal/testing/hmac-secret-vectors.d.ts.map +1 -0
  478. package/dist/internal/testing/hmac-secret-vectors.js +89 -0
  479. package/dist/internal/testing/pagerduty-continuation-fixtures.d.ts +42 -0
  480. package/dist/internal/testing/pagerduty-continuation-fixtures.d.ts.map +1 -0
  481. package/dist/internal/testing/pagerduty-continuation-fixtures.js +175 -0
  482. package/dist/internal/update-check.d.ts +2 -2
  483. package/dist/internal/update-check.d.ts.map +1 -1
  484. package/dist/internal/update-check.js +3 -3
  485. package/dist/internal/zod-schema.d.ts +14 -0
  486. package/dist/internal/zod-schema.d.ts.map +1 -0
  487. package/dist/internal/zod-schema.js +22 -0
  488. package/dist/internal/zod3-datetime.d.ts +12 -0
  489. package/dist/internal/zod3-datetime.d.ts.map +1 -0
  490. package/dist/internal/zod3-datetime.js +17 -0
  491. package/dist/otel-public.d.ts +2 -3
  492. package/dist/otel-public.d.ts.map +1 -1
  493. package/dist/otel-public.js +2 -2
  494. package/dist/otel.d.ts +3 -102
  495. package/dist/otel.d.ts.map +1 -1
  496. package/dist/otel.js +61 -97
  497. package/dist/playground/assets/cursor-icons-16-DmHBTm1-.woff2 +0 -0
  498. package/dist/playground/assets/index-CyPkf2y7.css +1 -0
  499. package/dist/playground/assets/index-DpbzbqFY.js +62 -0
  500. package/dist/playground/index.html +2 -2
  501. package/dist/public-deprecated.d.ts +36 -0
  502. package/dist/public-deprecated.d.ts.map +1 -0
  503. package/dist/public-deprecated.js +39 -0
  504. package/dist/tools.d.ts +16 -13
  505. package/dist/tools.d.ts.map +1 -1
  506. package/dist/tools.js +4 -3
  507. package/dist/types.d.ts +286 -104
  508. package/dist/types.d.ts.map +1 -1
  509. package/docs/changelog.md +91 -0
  510. package/docs/guides/hooks.md +7 -3
  511. package/docs/guides/mcp-oauth.md +12 -0
  512. package/docs/guides/opentelemetry.md +150 -180
  513. package/docs/guides/pagerduty.md +341 -0
  514. package/docs/guides/slack.md +41 -0
  515. package/docs/reference/agent-config.md +21 -1
  516. package/docs/reference/channels.md +7 -2
  517. package/docs/reference/cli.md +27 -0
  518. package/docs/reference/hooks.md +10 -5
  519. package/docs/reference/sessions.md +46 -1
  520. package/docs/reference/tools.md +4 -3
  521. package/package.json +39 -8
  522. package/schemas/grokbot-answers.schema.json +11 -0
  523. package/skills/framework-map/SKILL.md +2 -1
  524. package/skills/migrate-v2/SKILL.md +1 -1
  525. package/skills/otel/SKILL.md +30 -46
  526. package/templates/agentic-owners/README.md +6 -1
  527. package/templates/agentic-owners/bot/lib/owners/decision.ts +31 -5
  528. package/templates/agentic-owners/bot/lib/owners/globalOverride.ts +60 -0
  529. package/templates/agentic-owners/bot/lib/owners/match.ts +85 -19
  530. package/templates/agentic-owners/bot/lib/owners/parse.ts +133 -2
  531. package/templates/agentic-owners/bot/lib/owners/types.ts +23 -0
  532. package/templates/code-wiki/evals/wiki.eval.ts +2 -2
  533. package/dist/docs/assets/chunks/@localSearchIndexroot.3ebvCWKy.js +0 -1
  534. package/dist/docs/assets/chunks/channel.BOebySCN.js +0 -1
  535. package/dist/docs/assets/chunks/classDiagram-6PBFFD2Q.C55IaN-T.js +0 -1
  536. package/dist/docs/assets/chunks/classDiagram-v2-HSJHXN6E.C55IaN-T.js +0 -1
  537. package/dist/docs/assets/chunks/clone.D06pA7ML.js +0 -1
  538. package/dist/docs/assets/chunks/stateDiagram-v2-QKLJ7IA2.DddRVjeq.js +0 -1
  539. package/dist/docs/assets/chunks/wardley-RL74JXVD.CVCRSuQK.js +0 -162
  540. package/dist/docs/assets/guides_opentelemetry.md.Ck1o2frw.js +0 -45
  541. package/dist/docs/assets/guides_opentelemetry.md.Ck1o2frw.lean.js +0 -1
  542. package/dist/docs/assets/reference_sessions.md.C8FXuGwk.js +0 -1
  543. package/dist/docs/assets/reference_sessions.md.C8FXuGwk.lean.js +0 -1
  544. package/dist/playground/assets/cursor-icons-16-gwXtdAvu.woff2 +0 -0
  545. package/dist/playground/assets/index-DKKdkF29.js +0 -62
  546. package/dist/playground/assets/index-DpKinTMs.css +0 -1
  547. package/templates/grokbot-agents/.gitignore +0 -4
  548. package/templates/security-help/.gitignore +0 -4
  549. /package/dist/docs/assets/{guides_hooks.md.Bfj0pK91.lean.js → guides_hooks.md.B2XfGX50.lean.js} +0 -0
  550. /package/dist/docs/assets/{reference_channels.md.DYg0CLud.lean.js → reference_channels.md.CNNIS6K7.lean.js} +0 -0
  551. /package/dist/docs/assets/{reference_schedules.md.03Ryy9ca.lean.js → reference_schedules.md.BqWnJES4.lean.js} +0 -0
  552. /package/dist/docs/assets/{reference_skills.md.C2GWh7g8.lean.js → reference_skills.md.Ckddg6KX.lean.js} +0 -0
  553. /package/dist/docs/assets/{reference_tools.md.08XR7lIl.lean.js → reference_tools.md.Bo0UfT0a.lean.js} +0 -0
@@ -1,21 +1,27 @@
1
- import{_ as e,c as t,o as a,a3 as i}from"./chunks/framework.BNw1pucY.js";const k=JSON.parse('{"title":"Hooks","description":"Observe-only subscribers to the session event stream: audit logs, metrics, transcript mirrors, derived state.","frontmatter":{"title":"Hooks","description":"Observe-only subscribers to the session event stream: audit logs, metrics, transcript mirrors, derived state."},"headers":[],"relativePath":"reference/hooks.md","filePath":"reference/hooks.md"}'),n={name:"reference/hooks.md"};function o(d,s,h,l,r,c){return a(),t("div",null,[...s[0]||(s[0]=[i(`<h1 id="hooks" tabindex="-1">Hooks <a class="header-anchor" href="#hooks" aria-label="Permalink to &quot;Hooks&quot;">​</a></h1><p>A hook subscribes to selected session events and can run a side effect after each matching event is recorded: an audit line, a metric, a transcript copy, or derived state. Hooks run in the serving process for every session of the agent. They cannot change the turn, the prompt, or the reply; a handler that throws is logged and skipped.</p><p>Treat the event as read-only. Later subscribers see the same object. That makes hooks safe to add to a production agent, and the wrong surface for anything that must run before the model or must fail a turn; see <a href="#hook-boundaries">Hook boundaries</a>.</p><p><code>defineHook</code> is unrelated to <a href="https://cursor.com/docs/agent/hooks" target="_blank" rel="noreferrer">Cursor Agent hooks</a>, the <code>.cursor/hooks.json</code> scripts that can observe, block, or modify the agent loop. Those still run inside a local session workspace.</p><h2 id="author-a-hook" tabindex="-1">Author a hook <a class="header-anchor" href="#author-a-hook" aria-label="Permalink to &quot;Author a hook&quot;">​</a></h2><p>Author <code>bot/hooks/&lt;name&gt;.ts</code> with <code>defineHook</code> from <code>@cursor/bdk/hooks</code>. This one meters tokens:</p><div class="language-ts vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">ts</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// bot/hooks/usage.ts</span></span>
1
+ import{_ as e,c as t,o as a,a3 as i}from"./chunks/framework.BNw1pucY.js";const c=JSON.parse('{"title":"Hooks","description":"Observe-only subscribers to the session event stream: audit logs, metrics, transcript mirrors, derived state.","frontmatter":{"title":"Hooks","description":"Observe-only subscribers to the session event stream: audit logs, metrics, transcript mirrors, derived state."},"headers":[],"relativePath":"reference/hooks.md","filePath":"reference/hooks.md"}'),n={name:"reference/hooks.md"};function o(d,s,h,l,r,k){return a(),t("div",null,[...s[0]||(s[0]=[i(`<h1 id="hooks" tabindex="-1">Hooks <a class="header-anchor" href="#hooks" aria-label="Permalink to &quot;Hooks&quot;">​</a></h1><p>A hook subscribes to selected session events and can run a side effect after each matching event is recorded: an audit line, a metric, a transcript copy, or derived state. Hooks run in the serving process for every session of the agent. They cannot change the turn, the prompt, or the reply; a handler that throws is logged and skipped.</p><p>Treat the event as read-only. Later subscribers see the same object. That makes hooks safe to add to a production agent, and the wrong surface for anything that must run before the model or must fail a turn; see <a href="#hook-boundaries">Hook boundaries</a>.</p><p><code>defineHook</code> is unrelated to <a href="https://cursor.com/docs/agent/hooks" target="_blank" rel="noreferrer">Cursor Agent hooks</a>, the <code>.cursor/hooks.json</code> scripts that can observe, block, or modify the agent loop. Those still run inside a local session workspace.</p><h2 id="author-a-hook" tabindex="-1">Author a hook <a class="header-anchor" href="#author-a-hook" aria-label="Permalink to &quot;Author a hook&quot;">​</a></h2><p>Author <code>bot/hooks/&lt;name&gt;.ts</code> with <code>defineHook</code> from <code>@cursor/bdk/hooks</code>. This one meters tokens:</p><div class="language-ts vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">ts</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// bot/hooks/usage.ts</span></span>
2
+ <span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">import</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> { metrics } </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">from</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;@opentelemetry/api&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
2
3
  <span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">import</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> { defineHook } </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">from</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;@cursor/bdk/hooks&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
3
4
  <span class="line"></span>
5
+ <span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">const</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> meter</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> metrics.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">getMeter</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;acme&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
6
+ <span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">const</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> inputTokens</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> meter.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">createCounter</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;acme.tokens.input&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
7
+ <span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">const</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> outputTokens</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> meter.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">createCounter</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;acme.tokens.output&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
8
+ <span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">const</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> turnFailed</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> meter.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">createCounter</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;acme.turn.failed&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
9
+ <span class="line"></span>
4
10
  <span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">export</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> default</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> defineHook</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">({</span></span>
5
11
  <span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> events: {</span></span>
6
12
  <span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> async</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;turn.completed&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">event</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">ctx</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
7
13
  <span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (ctx.session.purpose </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">===</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;eval&quot;</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> ||</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> event.data.usage </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">===</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> undefined</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
8
14
  <span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
9
15
  <span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
10
- <span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> const</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> { </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">inputTokens</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">outputTokens</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> } </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> event.data.usage;</span></span>
11
- <span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> ctx.host.otel.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">increment</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;acme.tokens.input&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, inputTokens);</span></span>
12
- <span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> ctx.host.otel.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">increment</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;acme.tokens.output&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, outputTokens);</span></span>
16
+ <span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> const</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> usage</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> event.data.usage;</span></span>
17
+ <span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> inputTokens.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">add</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(usage.inputTokens);</span></span>
18
+ <span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> outputTokens.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">add</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(usage.outputTokens);</span></span>
13
19
  <span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> },</span></span>
14
20
  <span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> async</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;turn.failed&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">_event</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">ctx</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
15
- <span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> ctx.host.otel.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">increment</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;acme.turn.failed&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, { channel: ctx.channel.id });</span></span>
21
+ <span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> turnFailed.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">add</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, { channel: ctx.channel.id });</span></span>
16
22
  <span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> },</span></span>
17
23
  <span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> },</span></span>
18
- <span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">});</span></span></code></pre></div><p>Any module under <code>bot/hooks/</code>, subfolders included, is a hook named by its path without the extension: <code>bot/hooks/audit/usage.ts</code> is <code>audit/usage</code>. <code>*.test.ts</code> and <code>*.spec.ts</code> files are skipped. The default export must be <code>defineHook(...)</code>, names can&#39;t contain <code>__</code>, and an empty <code>events</code> map skips the hook with a warning; <code>bdk validate</code> reports all three. An extension mounts its hooks as <code>&lt;ns&gt;__&lt;name&gt;</code>, and <code>disableHook()</code> removes one (<a href="./extensions.html#adjust-a-mounted-extension">Adjust a mounted extension</a>).</p><p><code>bdk init</code> scaffolds <code>bot/hooks/memory.ts</code>, which exports <code>memoryHook()</code> from <code>@cursor/bdk/memory</code> and journals every turn for later sessions to read. Delete the file to opt out. See <a href="./memory.html">Memory</a>.</p><h2 id="events-and-payloads" tabindex="-1">Events and payloads <a class="header-anchor" href="#events-and-payloads" aria-label="Permalink to &quot;Events and payloads&quot;">​</a></h2><p>Keys are event types from the <a href="./sessions.html#stream-events">event vocabulary</a>, or <code>&quot;*&quot;</code> for every event. A typed key narrows <code>event.data</code>; a <code>&quot;*&quot;</code> handler receives the union, so switch on <code>event.type</code>. Every event carries the stream envelope <code>{ type, index, sessionId, turnId?, at, data }</code>, with <code>turnId</code> set on turn-scoped events. Skip <code>*.appended</code> deltas when you want the final text; <code>message.completed</code> already has it.</p><table tabindex="0"><thead><tr><th>Event</th><th><code>event.data</code></th></tr></thead><tbody><tr><td><code>message.received</code></td><td><code>{ text }</code></td></tr><tr><td><code>turn.completed</code></td><td><code>{ result?, usage?, cost? }</code>. <code>usage</code> has <code>inputTokens</code>, <code>outputTokens</code>, <code>cacheReadTokens</code>, <code>cacheWriteTokens</code>, and optional <code>reasoningTokens</code>. <code>cost</code> has <code>totalUsd</code> and the <code>model</code> it was priced against</td></tr><tr><td><code>turn.failed</code></td><td><code>{ message, status? }</code>. <code>status</code> is <code>&quot;error&quot;</code> or <code>&quot;cancelled&quot;</code> when present</td></tr><tr><td><code>actions.requested</code></td><td><code>{ calls: [{ callId, toolName, args?, parentCallId? }], parentCallId? }</code>. One envelope per model step once that step has listed its tools. A single tool is a batch of one. <code>parentCallId</code> marks subagent work</td></tr><tr><td><code>actions.completed</code></td><td><code>{ results: [{ callId, toolName, output?, isError, stubbed?, parentCallId? }], parentCallId? }</code>. Pair with <code>actions.requested</code>; emitted when every call in that batch has a result</td></tr><tr><td><code>action.result</code></td><td><code>{ callId, toolName, output?, isError, stubbed?, parentCallId? }</code>. Live per-call envelope for chips and spans. <code>stubbed</code> means a dry-run session answered a write without running it</td></tr><tr><td><code>action.tool_retry</code></td><td><code>{ callId, toolName, attempt, reason, connection? }</code>. A read is running again after a transient failure. <code>attempt</code> is the try about to run. <code>reason</code> is a class such as <code>transport</code> or <code>http_503</code></td></tr></tbody></table><p>The types are <code>SessionEvent</code>, <code>SessionEventType</code>, and <code>HookContext</code>, exported from <code>@cursor/bdk</code>.</p><h2 id="handler-context" tabindex="-1">Handler context <a class="header-anchor" href="#handler-context" aria-label="Permalink to &quot;Handler context&quot;">​</a></h2><table tabindex="0"><thead><tr><th>Member</th><th>What it is</th></tr></thead><tbody><tr><td><code>ctx.session</code></td><td>Read-only session info: <code>id</code>, <code>channelId</code>, <code>mode</code> (<code>chat</code> or <code>task</code>), <code>purpose</code> (<code>live</code> or <code>eval</code>), <code>auth</code>, plus <code>title</code> and <code>sdkAgentId</code> when set</td></tr><tr><td><code>ctx.agent</code></td><td><code>{ name }</code> of the agent the event belongs to</td></tr><tr><td><code>ctx.channel</code></td><td><code>{ id, continuationToken }</code>. The token is <code>null</code> when the session can&#39;t take follow-ups</td></tr><tr><td><code>ctx.host.kv</code></td><td>Durable JSON, shared by every session of the agent. Prefix keys with <code>ctx.session.id</code> for per-session state</td></tr><tr><td><code>ctx.host.files</code></td><td>Durable files, bound to this session. Pass <code>{ scope: &quot;deployment&quot; }</code> for agent-wide files</td></tr><tr><td><code>ctx.host.otel</code></td><td>Counters, histograms, and tags, attributed to this session</td></tr><tr><td><code>ctx.host.mcp</code>, <code>ctx.host.github</code>, <code>ctx.host.slack</code></td><td>The same shared clients tools get</td></tr><tr><td><code>ctx.host.reminders</code></td><td>Per-session <a href="./schedules.html#reminders">reminders</a>, the same API tools get</td></tr><tr><td><code>ctx.artifacts</code></td><td>Session-bound <a href="./artifacts.html">artifacts</a> facade: <code>tag</code> fills in <code>sessionId</code> and <code>turnId</code></td></tr><tr><td><code>ctx.stateRoot</code></td><td>Absolute path of the local state root. It resets when a hosted deployment is replaced; keep derived state in <code>kv</code> or <code>files</code></td></tr></tbody></table><h2 id="hook-dispatch" tabindex="-1">Hook dispatch <a class="header-anchor" href="#hook-dispatch" aria-label="Permalink to &quot;Hook dispatch&quot;">​</a></h2><p>A hook runs after the event is recorded. It never delays the model and never sees an event that wasn&#39;t recorded.</p><table tabindex="0"><thead><tr><th>Rule</th><th>What happens</th></tr></thead><tbody><tr><td>Same session</td><td>Events dispatch one at a time</td></tr><tr><td>Eval sessions</td><td>The same stream fires; skip metering or paging when <code>ctx.session.purpose === &quot;eval&quot;</code></td></tr><tr><td>Host restart</td><td>Recorded events are not replayed into hooks, so a mirror needs no dedupe</td></tr><tr><td>Slow handler</td><td>Holds the next event&#39;s handlers on that session, not the model. Keep handlers short and queue anything slow</td></tr></tbody></table><p>Read hosted secrets inside the handler, not at module scope. Give outbound calls a timeout; a stalled request holds later handlers on that session. Skip cancelled turns when paging; they record interrupted work.</p><div class="language-ts vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">ts</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// bot/hooks/page-on-failure.ts</span></span>
24
+ <span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">});</span></span></code></pre></div><p>Any module under <code>bot/hooks/</code>, subfolders included, is a hook named by its path without the extension: <code>bot/hooks/audit/usage.ts</code> is <code>audit/usage</code>. <code>*.test.ts</code> and <code>*.spec.ts</code> files are skipped. The default export must be <code>defineHook(...)</code>, names can&#39;t contain <code>__</code>, and an empty <code>events</code> map skips the hook with a warning; <code>bdk validate</code> reports all three. An extension mounts its hooks as <code>&lt;ns&gt;__&lt;name&gt;</code>, and <code>disableHook()</code> removes one (<a href="./extensions.html#adjust-a-mounted-extension">Adjust a mounted extension</a>).</p><p><code>bdk init</code> scaffolds <code>bot/hooks/memory.ts</code>, which exports <code>memoryHook()</code> from <code>@cursor/bdk/memory</code> and journals every turn for later sessions to read. Delete the file to opt out. See <a href="./memory.html">Memory</a>.</p><h2 id="events-and-payloads" tabindex="-1">Events and payloads <a class="header-anchor" href="#events-and-payloads" aria-label="Permalink to &quot;Events and payloads&quot;">​</a></h2><p>Keys are event types from the <a href="./sessions.html#stream-events">event vocabulary</a>, or <code>&quot;*&quot;</code> for every event. A typed key narrows <code>event.data</code>; a <code>&quot;*&quot;</code> handler receives the union, so switch on <code>event.type</code>. Every event carries the stream envelope <code>{ type, index, sessionId, turnId?, at, data }</code>, with <code>turnId</code> set on turn-scoped events. Skip <code>*.appended</code> deltas when you want the final text; <code>message.completed</code> already has it.</p><table tabindex="0"><thead><tr><th>Event</th><th><code>event.data</code></th></tr></thead><tbody><tr><td><code>message.received</code></td><td><code>{ text }</code></td></tr><tr><td><code>turn.completed</code></td><td><code>{ result?, usage?, cost? }</code>. <code>usage</code> has <code>inputTokens</code>, <code>outputTokens</code>, <code>cacheReadTokens</code>, <code>cacheWriteTokens</code>, and optional <code>reasoningTokens</code>. <code>cost</code> has <code>totalUsd</code> and the <code>model</code> it was priced against</td></tr><tr><td><code>turn.failed</code></td><td><code>{ message, status? }</code>. <code>status</code> is <code>&quot;error&quot;</code> or <code>&quot;cancelled&quot;</code> when present</td></tr><tr><td><code>actions.requested</code></td><td><code>{ calls: [{ callId, toolName, args?, parentCallId? }], parentCallId? }</code>. One envelope per model step once that step has listed its tools. A single tool is a batch of one. <code>parentCallId</code> marks subagent work</td></tr><tr><td><code>actions.completed</code></td><td><code>{ results: [{ callId, toolName, output?, isError, stubbed?, parentCallId? }], parentCallId? }</code>. Pair with <code>actions.requested</code>; emitted when every call in that batch has a result</td></tr><tr><td><code>action.result</code></td><td><code>{ callId, toolName, output?, isError, stubbed?, parentCallId? }</code>. Live per-call envelope for chips and spans. <code>stubbed</code> means a dry-run session answered a write without running it</td></tr><tr><td><code>action.tool_retry</code></td><td><code>{ callId, toolName, attempt, reason, connection? }</code>. A read is running again after a transient failure. <code>attempt</code> is the try about to run. <code>reason</code> is a class such as <code>transport</code> or <code>http_503</code></td></tr></tbody></table><p>The types are <code>SessionEvent</code>, <code>SessionEventType</code>, and <code>HookContext</code>, exported from <code>@cursor/bdk</code>.</p><h2 id="handler-context" tabindex="-1">Handler context <a class="header-anchor" href="#handler-context" aria-label="Permalink to &quot;Handler context&quot;">​</a></h2><table tabindex="0"><thead><tr><th>Member</th><th>What it is</th></tr></thead><tbody><tr><td><code>ctx.session</code></td><td>Read-only session info: <code>id</code>, <code>channelId</code>, <code>mode</code> (<code>chat</code> or <code>task</code>), <code>purpose</code> (<code>live</code> or <code>eval</code>), <code>auth</code>, plus <code>title</code> and <code>sdkAgentId</code> when set</td></tr><tr><td><code>ctx.agent</code></td><td><code>{ name }</code> of the agent the event belongs to</td></tr><tr><td><code>ctx.channel</code></td><td><code>{ id, continuationToken }</code>. The token is <code>null</code> when the session can&#39;t take follow-ups</td></tr><tr><td><code>ctx.host.kv</code></td><td>Durable JSON, shared by every session of the agent. Prefix keys with <code>ctx.session.id</code> for per-session state</td></tr><tr><td><code>ctx.host.files</code></td><td>Durable files, bound to this session. Pass <code>{ scope: &quot;deployment&quot; }</code> for agent-wide files</td></tr><tr><td><code>ctx.host.mcp</code>, <code>ctx.host.github</code>, <code>ctx.host.slack</code></td><td>The same shared clients tools get</td></tr><tr><td><code>ctx.host.reminders</code></td><td>Per-session <a href="./schedules.html#reminders">reminders</a>, the same API tools get</td></tr><tr><td><code>ctx.artifacts</code></td><td>Session-bound <a href="./artifacts.html">artifacts</a> facade: <code>tag</code> fills in <code>sessionId</code> and <code>turnId</code></td></tr><tr><td><code>ctx.stateRoot</code></td><td>Absolute path of the local state root. It resets when a hosted deployment is replaced; keep derived state in <code>kv</code> or <code>files</code></td></tr></tbody></table><h2 id="hook-dispatch" tabindex="-1">Hook dispatch <a class="header-anchor" href="#hook-dispatch" aria-label="Permalink to &quot;Hook dispatch&quot;">​</a></h2><p>A hook runs after the event is recorded. It never delays the model and never sees an event that wasn&#39;t recorded.</p><table tabindex="0"><thead><tr><th>Rule</th><th>What happens</th></tr></thead><tbody><tr><td>Same session</td><td>Events dispatch one at a time</td></tr><tr><td>Eval sessions</td><td>The same stream fires; skip metering or paging when <code>ctx.session.purpose === &quot;eval&quot;</code></td></tr><tr><td>Host restart</td><td>Recorded events are not replayed into hooks, so a mirror needs no dedupe</td></tr><tr><td>Slow handler</td><td>Holds the next event&#39;s handlers on that session, not the model. Keep handlers short and queue anything slow</td></tr></tbody></table><p>Read hosted secrets inside the handler, not at module scope. Give outbound calls a timeout; a stalled request holds later handlers on that session. Skip cancelled turns when paging; they record interrupted work.</p><div class="language-ts vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">ts</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// bot/hooks/page-on-failure.ts</span></span>
19
25
  <span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">import</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> { defineHook } </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">from</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;@cursor/bdk/hooks&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
20
26
  <span class="line"></span>
21
27
  <span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">export</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> default</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> defineHook</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">({</span></span>
@@ -42,4 +48,4 @@ import{_ as e,c as t,o as a,a3 as i}from"./chunks/framework.BNw1pucY.js";const k
42
48
  <span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> });</span></span>
43
49
  <span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> },</span></span>
44
50
  <span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> },</span></span>
45
- <span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">});</span></span></code></pre></div><h2 id="hooks-vs-channels-vs-evals" tabindex="-1">Hooks vs channels vs evals <a class="header-anchor" href="#hooks-vs-channels-vs-evals" aria-label="Permalink to &quot;Hooks vs channels vs evals&quot;">​</a></h2><p>All three consume the same stream, for different jobs:</p><table tabindex="0"><thead><tr><th></th><th>Hooks</th><th>Channel <code>events</code></th><th>Evals</th></tr></thead><tbody><tr><td>Scope</td><td>every session of the agent</td><td>sessions the channel owns</td><td>one test turn</td></tr><tr><td>Job</td><td>observe: audit, metrics, mirrors, derived state</td><td>deliver: replies back to the channel&#39;s surface</td><td>assert: gates over the trajectory</td></tr><tr><td>Context</td><td><code>ctx.host</code>, <code>ctx.artifacts</code>, session info</td><td><code>channel.state</code>, <code>setContinuationToken</code>, <code>ctx.host</code>, session info</td><td>the <code>t</code> assertion helpers</td></tr><tr><td>Can affect the run</td><td>no</td><td>yes, it owns the surface</td><td>n/a</td></tr><tr><td>Authored at</td><td><code>bot/hooks/*.ts</code></td><td>channel config</td><td><code>evals/**/*.eval.ts</code></td></tr></tbody></table><h2 id="hook-boundaries" tabindex="-1">Hook boundaries <a class="header-anchor" href="#hook-boundaries" aria-label="Permalink to &quot;Hook boundaries&quot;">​</a></h2><table tabindex="0"><thead><tr><th>You want to</th><th>Use instead</th></tr></thead><tbody><tr><td>Add context before the model runs</td><td>The channel&#39;s <code>send</code> message and <code>workspaceFiles</code>, <code>instructions.md</code>, skills, or <code>sandbox/workspace/</code> seed files</td></tr><tr><td>Reply on Slack, comment on a PR, or post any other delivery</td><td>The channel&#39;s <code>events</code> map, or the Slack and GitHub packs</td></tr><tr><td>Show PR progress (merge-box check, sticky banner)</td><td><code>githubChannel({ progress: { commitStatus, banner } })</code>; see <a href="./../guides/github.html">GitHub agents</a></td></tr><tr><td>Gate a change on behavior</td><td><a href="./../evals.html">Evals</a></td></tr></tbody></table><p>To act on a turn&#39;s decision, such as a label or a ticket, have the model record it with an authored <a href="./tools.html">tool</a>. A <code>turn.completed</code> hook then reads the recorded decision and acts on it through <code>ctx.host</code>.</p><h2 id="test-a-hook" tabindex="-1">Test a hook <a class="header-anchor" href="#test-a-hook" aria-label="Permalink to &quot;Test a hook&quot;">​</a></h2><p>A hook definition is a plain object, so a unit test calls <code>hook.events[&quot;turn.completed&quot;]</code> directly with an event and a stub <code>HookContext</code>. Discovery skips <code>*.test.ts</code>, so the test can live next to the hook.</p><table tabindex="0"><thead><tr><th>Command</th><th>What it reports</th></tr></thead><tbody><tr><td><code>bdk validate --dir .</code></td><td>Discovery errors and the empty-handlers warning</td></tr><tr><td><code>bdk info --dir . --json</code></td><td>Loaded hooks under <code>agents[].hooks</code></td></tr><tr><td><code>bdk run --dir . --message &quot;…&quot;</code></td><td>Serve log on stderr, including <code>hook &quot;&lt;name&gt;&quot; handler for &lt;event&gt; threw: …</code></td></tr></tbody></table><p>On hosting, read the same log with <a href="./cli.html#logs"><code>bdk logs</code></a>.</p><h2 id="related" tabindex="-1">Related <a class="header-anchor" href="#related" aria-label="Permalink to &quot;Related&quot;">​</a></h2><ul><li><a href="./../guides/hooks.html">Hooks guide</a>: meter usage and page on failure</li><li><a href="./sessions.html">Sessions and streaming</a>: the event vocabulary hooks observe</li><li><a href="./../guides/opentelemetry.html">OpenTelemetry</a>: OTLP traces and metrics from the same event stream</li><li><a href="./../deployment.html#observability">Deployment</a>: runtime logs and export paths</li><li><a href="./channels.html#events">Channels</a>: the delivery-side counterpart</li></ul>`,32)])])}const E=e(n,[["render",o]]);export{k as __pageData,E as default};
51
+ <span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">});</span></span></code></pre></div><h2 id="hooks-vs-channels-vs-evals" tabindex="-1">Hooks vs channels vs evals <a class="header-anchor" href="#hooks-vs-channels-vs-evals" aria-label="Permalink to &quot;Hooks vs channels vs evals&quot;">​</a></h2><p>All three consume the same stream, for different jobs:</p><table tabindex="0"><thead><tr><th></th><th>Hooks</th><th>Channel <code>events</code></th><th>Evals</th></tr></thead><tbody><tr><td>Scope</td><td>every session of the agent</td><td>sessions the channel owns</td><td>one test turn</td></tr><tr><td>Job</td><td>observe: audit, metrics, mirrors, derived state</td><td>deliver: replies back to the channel&#39;s surface</td><td>assert: gates over the trajectory</td></tr><tr><td>Context</td><td><code>ctx.host</code>, <code>ctx.artifacts</code>, session info</td><td><code>channel.state</code>, <code>setContinuationToken</code>, <code>ctx.host</code>, session info</td><td>the <code>t</code> assertion helpers</td></tr><tr><td>Can affect the run</td><td>no</td><td>yes, it owns the surface</td><td>n/a</td></tr><tr><td>Authored at</td><td><code>bot/hooks/*.ts</code></td><td>channel config</td><td><code>evals/**/*.eval.ts</code></td></tr></tbody></table><h2 id="hook-boundaries" tabindex="-1">Hook boundaries <a class="header-anchor" href="#hook-boundaries" aria-label="Permalink to &quot;Hook boundaries&quot;">​</a></h2><table tabindex="0"><thead><tr><th>You want to</th><th>Use instead</th></tr></thead><tbody><tr><td>Add context before the model runs</td><td>The channel&#39;s <code>send</code> message and <code>workspaceFiles</code>, <code>instructions.md</code>, skills, or <code>sandbox/workspace/</code> seed files</td></tr><tr><td>Reply on Slack, comment on a PR, or post any other delivery</td><td>The channel&#39;s <code>events</code> map, or the Slack and GitHub packs</td></tr><tr><td>Show PR progress (merge-box check, sticky banner)</td><td><code>githubChannel({ progress: { commitStatus, banner } })</code>; see <a href="./../guides/github.html">GitHub agents</a></td></tr><tr><td>Gate a change on behavior</td><td><a href="./../evals.html">Evals</a></td></tr></tbody></table><p>To act on a turn&#39;s decision, such as a label or a ticket, have the model record it with an authored <a href="./tools.html">tool</a>. A <code>turn.completed</code> hook then reads the recorded decision and acts on it through <code>ctx.host</code>.</p><h2 id="test-a-hook" tabindex="-1">Test a hook <a class="header-anchor" href="#test-a-hook" aria-label="Permalink to &quot;Test a hook&quot;">​</a></h2><p>A hook definition is a plain object, so a unit test calls <code>hook.events[&quot;turn.completed&quot;]</code> directly with an event and a stub <code>HookContext</code>. Discovery skips <code>*.test.ts</code>, so the test can live next to the hook.</p><table tabindex="0"><thead><tr><th>Command</th><th>What it reports</th></tr></thead><tbody><tr><td><code>bdk validate --dir .</code></td><td>Discovery errors and the empty-handlers warning</td></tr><tr><td><code>bdk info --dir . --json</code></td><td>Loaded hooks under <code>agents[].hooks</code></td></tr><tr><td><code>bdk run --dir . --message &quot;…&quot;</code></td><td>Serve log on stderr, including <code>hook &quot;&lt;name&gt;&quot; handler for &lt;event&gt; threw: …</code></td></tr></tbody></table><p>On hosting, read the same log with <a href="./cli.html#logs"><code>bdk logs</code></a>.</p><h2 id="related" tabindex="-1">Related <a class="header-anchor" href="#related" aria-label="Permalink to &quot;Related&quot;">​</a></h2><ul><li><a href="./../guides/hooks.html">Hooks guide</a>: meter usage and page on failure</li><li><a href="./sessions.html">Sessions and streaming</a>: the event vocabulary hooks observe</li><li><a href="./../guides/opentelemetry.html">OpenTelemetry</a>: OTLP traces and metrics from the same event stream</li><li><a href="./../deployment.html#observability">Deployment</a>: runtime logs and export paths</li><li><a href="./channels.html#events">Channels</a>: the delivery-side counterpart</li></ul>`,32)])])}const E=e(n,[["render",o]]);export{c as __pageData,E as default};
@@ -1 +1 @@
1
- import{_ as e,c as t,o as a,a3 as i}from"./chunks/framework.BNw1pucY.js";const k=JSON.parse('{"title":"Hooks","description":"Observe-only subscribers to the session event stream: audit logs, metrics, transcript mirrors, derived state.","frontmatter":{"title":"Hooks","description":"Observe-only subscribers to the session event stream: audit logs, metrics, transcript mirrors, derived state."},"headers":[],"relativePath":"reference/hooks.md","filePath":"reference/hooks.md"}'),n={name:"reference/hooks.md"};function o(d,s,h,l,r,c){return a(),t("div",null,[...s[0]||(s[0]=[i("",32)])])}const E=e(n,[["render",o]]);export{k as __pageData,E as default};
1
+ import{_ as e,c as t,o as a,a3 as i}from"./chunks/framework.BNw1pucY.js";const c=JSON.parse('{"title":"Hooks","description":"Observe-only subscribers to the session event stream: audit logs, metrics, transcript mirrors, derived state.","frontmatter":{"title":"Hooks","description":"Observe-only subscribers to the session event stream: audit logs, metrics, transcript mirrors, derived state."},"headers":[],"relativePath":"reference/hooks.md","filePath":"reference/hooks.md"}'),n={name:"reference/hooks.md"};function o(d,s,h,l,r,k){return a(),t("div",null,[...s[0]||(s[0]=[i("",32)])])}const E=e(n,[["render",o]]);export{c as __pageData,E as default};
@@ -1,6 +1,6 @@
1
- import{_ as i,c as e,o as a,a3 as t}from"./chunks/framework.BNw1pucY.js";const c=JSON.parse('{"title":"Schedules & reminders","description":"Cron-driven runs defined at deploy time, and per-session durable wakes created at runtime.","frontmatter":{"title":"Schedules & reminders","description":"Cron-driven runs defined at deploy time, and per-session durable wakes created at runtime."},"headers":[],"relativePath":"reference/schedules.md","filePath":"reference/schedules.md"}'),n={name:"reference/schedules.md"};function h(l,s,d,r,p,o){return a(),e("div",null,[...s[0]||(s[0]=[t(`<h1 id="schedules-and-reminders" tabindex="-1">Schedules and reminders <a class="header-anchor" href="#schedules-and-reminders" aria-label="Permalink to &quot;Schedules and reminders&quot;">​</a></h1><p>An agent can act without an inbound message in two ways. A schedule is deploy-time cron: &quot;every weekday at 09:00, summarize open incidents.&quot; A reminder is a runtime wake bound to one conversation: &quot;re-check this PR&#39;s CI in two hours.&quot; Schedules live in the filesystem; reminders are created by running code.</p><h2 id="schedules" tabindex="-1">Schedules <a class="header-anchor" href="#schedules" aria-label="Permalink to &quot;Schedules&quot;">​</a></h2><p>Cron expressions are standard 5-field, evaluated in UTC with minute granularity.</p><h3 id="markdown-schedules" tabindex="-1">Markdown schedules <a class="header-anchor" href="#markdown-schedules" aria-label="Permalink to &quot;Markdown schedules&quot;">​</a></h3><p>A markdown file with <code>cron:</code> frontmatter is a fire-and-forget task:</p><div class="language-md vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">md</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#005CC5;--shiki-light-font-weight:bold;--shiki-dark:#79B8FF;--shiki-dark-font-weight:bold;">---</span></span>
2
- <span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">cron: &quot;0 9 * * 1-5&quot;</span></span>
3
- <span class="line"><span style="--shiki-light:#005CC5;--shiki-light-font-weight:bold;--shiki-dark:#79B8FF;--shiki-dark-font-weight:bold;">---</span></span>
1
+ import{_ as i,c as e,o as a,a3 as t}from"./chunks/framework.BNw1pucY.js";const c=JSON.parse('{"title":"Schedules & reminders","description":"Cron-driven runs defined at deploy time, and per-session durable wakes created at runtime.","frontmatter":{"title":"Schedules & reminders","description":"Cron-driven runs defined at deploy time, and per-session durable wakes created at runtime."},"headers":[],"relativePath":"reference/schedules.md","filePath":"reference/schedules.md"}'),n={name:"reference/schedules.md"};function h(l,s,d,r,p,o){return a(),e("div",null,[...s[0]||(s[0]=[t(`<h1 id="schedules-and-reminders" tabindex="-1">Schedules and reminders <a class="header-anchor" href="#schedules-and-reminders" aria-label="Permalink to &quot;Schedules and reminders&quot;">​</a></h1><p>An agent can act without an inbound message in two ways. A schedule is deploy-time cron: &quot;every weekday at 09:00, summarize open incidents.&quot; A reminder is a runtime wake bound to one conversation: &quot;re-check this PR&#39;s CI in two hours.&quot; Schedules live in the filesystem; reminders are created by running code.</p><h2 id="schedules" tabindex="-1">Schedules <a class="header-anchor" href="#schedules" aria-label="Permalink to &quot;Schedules&quot;">​</a></h2><p>Cron expressions are standard 5-field, evaluated in UTC with minute granularity.</p><h3 id="markdown-schedules" tabindex="-1">Markdown schedules <a class="header-anchor" href="#markdown-schedules" aria-label="Permalink to &quot;Markdown schedules&quot;">​</a></h3><p>A markdown file with <code>cron:</code> frontmatter is a fire-and-forget task:</p><div class="language-md vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">md</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">---</span></span>
2
+ <span class="line"><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">cron</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;0 9 * * 1-5&quot;</span></span>
3
+ <span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">---</span></span>
4
4
  <span class="line"></span>
5
5
  <span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">Pull open incidents and post a summary to the metrics endpoint.</span></span></code></pre></div><p>Each firing starts a task-mode session: the body is the prompt, the session runs to <code>session.completed</code> or <code>session.failed</code>, and it isn&#39;t followable.</p><h3 id="schedule-handlers" tabindex="-1">Schedule handlers <a class="header-anchor" href="#schedule-handlers" aria-label="Permalink to &quot;Schedule handlers&quot;">​</a></h3><p>Use <code>defineSchedule</code> with a <code>run</code> handler to call tools or hand work into a channel so its delivery events fire:</p><div class="language-ts vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">ts</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">import</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> { defineSchedule } </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">from</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;@cursor/bdk/schedules&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
6
6
  <span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">import</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> webhook </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">from</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;../channels/webhook.js&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
@@ -0,0 +1,22 @@
1
+ import{_ as s,c as t,o as a,a3 as i}from"./chunks/framework.BNw1pucY.js";const k=JSON.parse('{"title":"Sessions, events, and streaming","description":"Understand how conversations continue, how events stream, and where session data lives.","frontmatter":{"title":"Sessions, events, and streaming","description":"Understand how conversations continue, how events stream, and where session data lives."},"headers":[],"relativePath":"reference/sessions.md","filePath":"reference/sessions.md"}'),n={name:"reference/sessions.md"};function o(d,e,r,l,h,c){return a(),t("div",null,[...e[0]||(e[0]=[i(`<h1 id="sessions-events-and-streaming" tabindex="-1">Sessions, events, and streaming <a class="header-anchor" href="#sessions-events-and-streaming" aria-label="Permalink to &quot;Sessions, events, and streaming&quot;">​</a></h1><p>A session keeps one conversation, its workspace, and an append-only record of every message and tool call. Continue it with a continuation token, inspect it with a session ID, and follow progress on the NDJSON stream. Chat sessions wait for follow-ups; task sessions run once and stop.</p><h2 id="session-contents" tabindex="-1">Session contents <a class="header-anchor" href="#session-contents" aria-label="Permalink to &quot;Session contents&quot;">​</a></h2><p>Each session combines:</p><ul><li>A channel and authenticated caller</li><li>A conversation the caller can continue</li><li>A workspace for local turns</li><li>An NDJSON event stream</li><li>State that lets the conversation resume after a restart</li></ul><p>Sessions belong to the principal that created them. Follow-up, stream, and list routes return <code>403</code> when another caller tries to access one.</p><h2 id="session-identifiers" tabindex="-1">Session identifiers <a class="header-anchor" href="#session-identifiers" aria-label="Permalink to &quot;Session identifiers&quot;">​</a></h2><p>Sessions have two identifiers because conversation routing and inspection are different jobs.</p><table tabindex="0"><thead><tr><th>Identifier</th><th>Use it for</th></tr></thead><tbody><tr><td><code>continuationToken</code></td><td>Continue a conversation through its channel</td></tr><tr><td><code>sessionId</code></td><td>Stream events, inspect state, or run a session-bound tool call</td></tr></tbody></table><p>Channels decide what a continuation token looks like. Slack uses its thread identity. A PR channel can use a key such as <code>pr:owner/repo#1</code>. The built-in HTTP API returns an opaque token and rotates it after each accepted follow-up. Reusing a stale HTTP token returns <code>409</code>.</p><p>Use the continuation token to keep talking. Use the session ID to observe or manage the stored session.</p><h2 id="session-modes" tabindex="-1">Session modes <a class="header-anchor" href="#session-modes" aria-label="Permalink to &quot;Session modes&quot;">​</a></h2><table tabindex="0"><thead><tr><th>Mode</th><th>Created by</th><th>What happens after a turn</th></tr></thead><tbody><tr><td><code>chat</code></td><td>HTTP sessions, channel <code>send</code>, Slack, or MCP <code>ask</code></td><td>Waits in <code>session.waiting</code> and accepts follow-ups</td></tr><tr><td><code>task</code></td><td>Markdown schedules and fire-and-forget dispatch</td><td>Ends in <code>session.completed</code> or <code>session.failed</code></td></tr></tbody></table><p>Task sessions don&#39;t accept follow-ups. Trying one returns <code>409</code>.</p><h2 id="follow-ups" tabindex="-1">Follow-ups <a class="header-anchor" href="#follow-ups" aria-label="Permalink to &quot;Follow-ups&quot;">​</a></h2><p>A follow-up to an idle chat session starts another turn. Admission when the session is already busy depends on the channel:</p><table tabindex="0"><thead><tr><th>Path</th><th>Busy-session policy</th></tr></thead><tbody><tr><td>HTTP playground / <code>POST /v1/session/:id</code> / MCP <code>ask</code></td><td><strong>Preempt</strong> (default): interrupt the in-flight turn, wait for it to settle, then run the new message</td></tr><tr><td>Slack mentions / DMs / alert-watch</td><td><strong>Coalesce</strong>: leave the active turn running and queue the follow-up. The running turn may receive it at a tool boundary; any asks that remain become one follow-up turn when it finishes</td></tr></tbody></table><p>Pass <code>admission: &quot;coalesce&quot;</code> on <code>send()</code> to opt into the Slack policy from other callers. Omit it (or pass <code>&quot;preempt&quot;</code>) to keep interrupt semantics.</p><h3 id="track-which-follow-up-reached-the-agent" tabindex="-1">Track which follow-up reached the agent <a class="header-anchor" href="#track-which-follow-up-reached-the-agent" aria-label="Permalink to &quot;Track which follow-up reached the agent&quot;">​</a></h3><p>Every <code>send()</code> returns a <code>deliveryId</code>. Pass your own as the <code>deliveryId</code> option, such as the webhook delivery ID you already hold, or omit it to get a fresh <code>dlv_…</code> ID. A coalesced follow-up reaches the agent in one of two ways, and the ID is on the event for that path:</p><table tabindex="0"><thead><tr><th>Path</th><th>Event</th><th>Field</th></tr></thead><tbody><tr><td>Steered into the running turn</td><td><code>nudge.delivered</code></td><td><code>data.deliveryId</code></td></tr><tr><td>Fell back to the next turn</td><td>That turn&#39;s <code>message.received</code></td><td><code>data.deliveryIds</code></td></tr></tbody></table><p><code>message.received</code> lists every send its prompt carries, in arrival order. Follow-ups queued behind a busy turn drain into one turn, so the list can hold several IDs. A direct send that starts a turn gets a one-item list.</p><div class="language-ts vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">ts</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// In a route or channel hook: name the steer after the webhook delivery.</span></span>
2
+ <span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">await</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> send</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">\`Incident \${</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">incident</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">.</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">id</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">} was acknowledged.\`</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, {</span></span>
3
+ <span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> continuationToken: incident.id,</span></span>
4
+ <span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> admission: </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;coalesce&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
5
+ <span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> deliveryId: webhookId,</span></span>
6
+ <span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">});</span></span>
7
+ <span class="line"></span>
8
+ <span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// In the channel&#39;s \`events\` map:</span></span>
9
+ <span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">const</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> steered</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> new</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> Set</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&lt;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">string</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&gt;();</span></span>
10
+ <span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">const</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> prompted</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> new</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> Set</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&lt;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">string</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&gt;();</span></span>
11
+ <span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">const</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> events</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">:</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> ChannelEventHandlers</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
12
+ <span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;nudge.delivered&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">async</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">event</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=&gt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
13
+ <span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (event.data.deliveryId </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">!==</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> undefined</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) {</span></span>
14
+ <span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> steered.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">add</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(event.data.deliveryId);</span></span>
15
+ <span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
16
+ <span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> },</span></span>
17
+ <span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;message.received&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">async</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">event</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=&gt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
18
+ <span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">const</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> id</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> of</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> event.data.deliveryIds </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">??</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> []) {</span></span>
19
+ <span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> prompted.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">add</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(id);</span></span>
20
+ <span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }</span></span>
21
+ <span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> },</span></span>
22
+ <span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span></span></code></pre></div><p>A local Slack session can also pick up follow-ups at a tool boundary from its own thread store. That <code>nudge.delivered</code> has no <code>deliveryId</code>, which tells it apart from a steered send.</p><p><code>POST /v1/session/:id/stop</code> interrupts a turn without sending a new message. The stream records <code>turn.failed</code> with <code>status: &quot;cancelled&quot;</code>; the session stays a chat session and can take another follow-up. A whole-message Slack <code>stop</code> / <code>@agent stop</code> does the same for that thread and clears pending coalesced follow-ups.</p><p>See <a href="./tools.html#call-a-tool-without-a-model-turn">Tools</a> for direct-call behavior while a session is busy.</p><h2 id="stream-events" tabindex="-1">Stream events <a class="header-anchor" href="#stream-events" aria-label="Permalink to &quot;Stream events&quot;">​</a></h2><p>Each NDJSON line uses this envelope: <code>{ type, index, sessionId, turnId?, at, data }</code>. The <code>index</code> increases within one session. The <code>at</code> field is an ISO-8601 timestamp.</p><table tabindex="0"><thead><tr><th>Phase</th><th>Events</th><th>What they tell you</th></tr></thead><tbody><tr><td>Session</td><td><code>session.started</code>, <code>session.waiting</code>, <code>session.completed</code>, <code>session.failed</code></td><td>Session creation, readiness, and task completion</td></tr><tr><td>Input</td><td><code>message.received</code>, <code>nudge.delivered</code></td><td>A user message was accepted as a turn&#39;s prompt, or reached a running turn mid-turn. Both name the <a href="#track-which-follow-up-reached-the-agent">sends they carry</a></td></tr><tr><td>Turn</td><td><code>turn.queued</code>, <code>turn.started</code>, <code>turn.completed</code>, <code>turn.failed</code></td><td>Queue position under a <a href="./agent-config.html#concurrency"><code>maxRunningTurns</code> cap</a>, then turn status, final result, and token usage</td></tr><tr><td>Steps</td><td><code>step.started</code>, <code>step.completed</code></td><td>Model step boundaries and duration</td></tr><tr><td>Reasoning</td><td><code>reasoning.appended</code>, <code>reasoning.completed</code></td><td>Streamed reasoning blocks</td></tr><tr><td>Reply</td><td><code>message.appended</code>, <code>message.completed</code></td><td>Text deltas and finalized assistant messages</td></tr><tr><td>Tools</td><td><code>actions.requested</code>, <code>actions.completed</code>, <code>action.result</code>, <code>action.tool_retry</code></td><td>Tool names, validated arguments, outputs, and errors. <code>action.tool_retry</code> means a read is running again after a transient failure</td></tr><tr><td>Subagents</td><td><code>subagent.called</code>, <code>subagent.completed</code></td><td>Delegated work</td></tr><tr><td>Artifacts</td><td><code>artifact.tagged</code></td><td>A durable <a href="./artifacts.html">artifact</a> was tagged for this session, by host code or <code>tag_artifact</code></td></tr></tbody></table><p>Pair <code>actions.requested</code> with <code>actions.completed</code> for each model-step batch. <code>action.result</code> is the live per-call envelope. Read <code>turn.completed.data.usage</code> for input, output, and cache token counts.</p><h2 id="stream-or-replay-events" tabindex="-1">Stream or replay events <a class="header-anchor" href="#stream-or-replay-events" aria-label="Permalink to &quot;Stream or replay events&quot;">​</a></h2><p>One endpoint handles both live streaming and replay:</p><div class="language-bash vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">curl</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -N</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;http://127.0.0.1:3000/&lt;slug&gt;/v1/session/ses_…/stream?startIndex=0&#39;</span></span></code></pre></div><p>Pass <code>startIndex</code> to continue after the last event you received, including after a server restart. Omit it or pass <code>0</code> to replay the full session before following new events. <code>GET /v1/session/:id/events</code> returns a one-time dump without staying connected.</p><h2 id="local-session-workspace" tabindex="-1">Local session workspace <a class="header-anchor" href="#local-session-workspace" aria-label="Permalink to &quot;Local session workspace&quot;">​</a></h2><p>BDK creates a workspace before the first local turn:</p><table tabindex="0"><thead><tr><th>Source path</th><th>Lands as</th></tr></thead><tbody><tr><td><code>skills/*</code></td><td><code>.cursor/skills/&lt;name&gt;/SKILL.md</code></td></tr><tr><td>agent tools (<code>execution: &quot;agent&quot;</code>)</td><td>scripts in the session workspace, with a catalog in <code>AGENTS.md</code></td></tr><tr><td><code>sandbox/workspace/**</code></td><td>copied in as seed files</td></tr><tr><td>per-send <code>workspaceFiles</code></td><td>written before the turn</td></tr></tbody></table><p>Instructions reach the model as its system prompt; they aren&#39;t written into the workspace. See <a href="./instructions.html#delivery">Instructions</a>.</p><p>Local turns use this workspace as their working directory. Parent directories can contribute <code>AGENTS.md</code> and <code>.cursor</code> settings. Set <code>local.cwd</code> when you need a clean parent directory. A channel can also provide a different working directory for one session, such as a PR worktree.</p><p>See <a href="./agent-config.html#local-cwd">Agent config: local cwd</a> for the inheritance rules.</p><h2 id="session-storage" tabindex="-1">Session storage <a class="header-anchor" href="#session-storage" aria-label="Permalink to &quot;Session storage&quot;">​</a></h2><p>Local session state lives under <code>--state-root</code>. A slugged mount stores it in a subdirectory named for the slug.</p><p>Deleting a session directory removes the session from the server: it disappears from listings and can no longer be streamed or continued.</p><h2 id="inspect-a-saved-event-stream" tabindex="-1">Inspect a saved event stream <a class="header-anchor" href="#inspect-a-saved-event-stream" aria-label="Permalink to &quot;Inspect a saved event stream&quot;">​</a></h2><p>Use <code>trajectory</code> with a saved trace:</p><div class="language-text vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">text</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>bdk trajectory --events &lt;state-root&gt;/traces/&lt;sessionId&gt;.ndjson</span></span></code></pre></div><p>The command prints tool calls, the reply, and token usage in the same JSON shape as <code>run</code>. Open the session&#39;s <strong>Trace</strong> view in the playground for a visual timeline.</p><h2 id="related" tabindex="-1">Related <a class="header-anchor" href="#related" aria-label="Permalink to &quot;Related&quot;">​</a></h2><ul><li><a href="./http-api.html">HTTP API</a></li><li><a href="./hooks.html">Hooks</a></li><li><a href="./tools.html">Tools</a></li></ul>`,49)])])}const u=s(n,[["render",o]]);export{k as __pageData,u as default};
@@ -0,0 +1 @@
1
+ import{_ as s,c as t,o as a,a3 as i}from"./chunks/framework.BNw1pucY.js";const k=JSON.parse('{"title":"Sessions, events, and streaming","description":"Understand how conversations continue, how events stream, and where session data lives.","frontmatter":{"title":"Sessions, events, and streaming","description":"Understand how conversations continue, how events stream, and where session data lives."},"headers":[],"relativePath":"reference/sessions.md","filePath":"reference/sessions.md"}'),n={name:"reference/sessions.md"};function o(d,e,r,l,h,c){return a(),t("div",null,[...e[0]||(e[0]=[i("",49)])])}const u=s(n,[["render",o]]);export{k as __pageData,u as default};
@@ -1,6 +1,6 @@
1
- import{_ as i,c as e,o as t,a3 as a}from"./chunks/framework.BNw1pucY.js";const c=JSON.parse('{"title":"Skills","description":"On-demand procedures the model loads only when relevant, in three authoring forms.","frontmatter":{"title":"Skills","description":"On-demand procedures the model loads only when relevant, in three authoring forms."},"headers":[],"relativePath":"reference/skills.md","filePath":"reference/skills.md"}'),l={name:"reference/skills.md"};function n(h,s,r,o,d,p){return t(),e("div",null,[...s[0]||(s[0]=[a(`<h1 id="skills" tabindex="-1">Skills <a class="header-anchor" href="#skills" aria-label="Permalink to &quot;Skills&quot;">​</a></h1><p>A skill is an on-demand procedure following the <code>SKILL.md</code> convention: the harness advertises each skill by its description, and the model loads the full content only when the task calls for it. Skills are how you give an agent a multi-step workflow without carrying it in the always-on <a href="./instructions.html">instructions</a>.</p><h2 id="authoring-forms" tabindex="-1">Authoring forms <a class="header-anchor" href="#authoring-forms" aria-label="Permalink to &quot;Authoring forms&quot;">​</a></h2><p>Skills support three authoring forms.</p><table tabindex="0"><thead><tr><th>Form</th><th>Reach for it when</th></tr></thead><tbody><tr><td><code>bot/skills/&lt;name&gt;.md</code></td><td>Static Markdown. Optional <code>description</code> frontmatter; the first body line is the fallback.</td></tr><tr><td><code>bot/skills/&lt;name&gt;/SKILL.md</code> plus siblings</td><td>A packaged directory with reference files (<code>references/…</code>). Requires <code>description</code> frontmatter.</td></tr><tr><td><code>bot/skills/&lt;name&gt;.ts</code></td><td>Generated content, with <code>defineSkill</code> from <code>@cursor/bdk/skills</code>.</td></tr></tbody></table><p>Use flat Markdown for static content:</p><div class="language-md vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">md</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">---</span></span>
2
- <span class="line"><span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">description</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">Use when a pull request needs a structured approval checklist.</span></span>
3
- <span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">---</span></span>
1
+ import{_ as i,c as e,o as t,a3 as a}from"./chunks/framework.BNw1pucY.js";const c=JSON.parse('{"title":"Skills","description":"On-demand procedures the model loads only when relevant, in three authoring forms.","frontmatter":{"title":"Skills","description":"On-demand procedures the model loads only when relevant, in three authoring forms."},"headers":[],"relativePath":"reference/skills.md","filePath":"reference/skills.md"}'),l={name:"reference/skills.md"};function n(h,s,r,o,d,p){return t(),e("div",null,[...s[0]||(s[0]=[a(`<h1 id="skills" tabindex="-1">Skills <a class="header-anchor" href="#skills" aria-label="Permalink to &quot;Skills&quot;">​</a></h1><p>A skill is an on-demand procedure following the <code>SKILL.md</code> convention: the harness advertises each skill by its description, and the model loads the full content only when the task calls for it. Skills are how you give an agent a multi-step workflow without carrying it in the always-on <a href="./instructions.html">instructions</a>.</p><h2 id="authoring-forms" tabindex="-1">Authoring forms <a class="header-anchor" href="#authoring-forms" aria-label="Permalink to &quot;Authoring forms&quot;">​</a></h2><p>Skills support three authoring forms.</p><table tabindex="0"><thead><tr><th>Form</th><th>Reach for it when</th></tr></thead><tbody><tr><td><code>bot/skills/&lt;name&gt;.md</code></td><td>Static Markdown. Optional <code>description</code> frontmatter; the first body line is the fallback.</td></tr><tr><td><code>bot/skills/&lt;name&gt;/SKILL.md</code> plus siblings</td><td>A packaged directory with reference files (<code>references/…</code>). Requires <code>description</code> frontmatter.</td></tr><tr><td><code>bot/skills/&lt;name&gt;.ts</code></td><td>Generated content, with <code>defineSkill</code> from <code>@cursor/bdk/skills</code>.</td></tr></tbody></table><p>Use flat Markdown for static content:</p><div class="language-md vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">md</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#005CC5;--shiki-light-font-weight:bold;--shiki-dark:#79B8FF;--shiki-dark-font-weight:bold;">---</span></span>
2
+ <span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">description: Use when a pull request needs a structured approval checklist.</span></span>
3
+ <span class="line"><span style="--shiki-light:#005CC5;--shiki-light-font-weight:bold;--shiki-dark:#79B8FF;--shiki-dark-font-weight:bold;">---</span></span>
4
4
  <span class="line"></span>
5
5
  <span class="line"><span style="--shiki-light:#005CC5;--shiki-light-font-weight:bold;--shiki-dark:#79B8FF;--shiki-dark-font-weight:bold;"># PR review checklist</span></span>
6
6
  <span class="line"></span>
@@ -22,7 +22,7 @@ import{_ as i,c as a,o as e,a3 as t}from"./chunks/framework.BNw1pucY.js";const c
22
22
  <span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> async</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> execute</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">({ </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">prUrl</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> }) {</span></span>
23
23
  <span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> { prUrl };</span></span>
24
24
  <span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> },</span></span>
25
- <span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">});</span></span></code></pre></div><h3 id="tool-context" tabindex="-1">Tool context <a class="header-anchor" href="#tool-context" aria-label="Permalink to &quot;Tool context&quot;">​</a></h3><p><code>execute</code> receives a <code>ctx</code> with the runtime accessors:</p><table tabindex="0"><thead><tr><th>Member</th><th>What it is</th></tr></thead><tbody><tr><td><code>ctx.toolCallId</code></td><td>The call id, matching the <code>actions.requested</code> / <code>action.result</code> stream events</td></tr><tr><td><code>ctx.session</code></td><td>Read-only session info: id, channel, mode, auth</td></tr><tr><td><code>ctx.workspaceDir</code></td><td>The session&#39;s workspace directory</td></tr><tr><td><code>ctx.stateRoot</code></td><td>The agent&#39;s durable state root, shared across every session</td></tr><tr><td><code>ctx.host</code></td><td>Shared host services (see below)</td></tr><tr><td><code>ctx.send(channelId, message, options?)</code></td><td>Start or resume a session on any channel. <code>auth</code> defaults to this call&#39;s session principal</td></tr><tr><td><code>ctx.getSession(channelId, sessionId)</code></td><td>Look up a session on a channel</td></tr><tr><td><code>ctx.artifacts</code></td><td>Session-bound <a href="./artifacts.html">artifacts</a> facade: <code>tag</code> auto-fills the session</td></tr></tbody></table><p><code>ctx.host</code> carries the shared host services: <code>host.mcp</code> (authored MCP connections: <code>names()</code>, <code>listTools(name)</code>, <code>callTool(name, tool, args)</code>), <code>host.github</code> and <code>host.slack</code> (shared platform clients), <code>host.kv</code> and <code>host.files</code> (durable storage), <code>host.otel</code> (custom metrics and session tags; see <a href="./../guides/opentelemetry.html">OpenTelemetry</a>), <code>host.reminders</code> (per-session wakes, when attached).</p><h3 id="return-values" tabindex="-1">Return values <a class="header-anchor" href="#return-values" aria-label="Permalink to &quot;Return values&quot;">​</a></h3><p><code>execute</code> may return a string (passed to the model verbatim), a JSON-shaped value (serialized), or the envelope <code>{ content: [...], isError? }</code> for rich results. Returns must be JSON-shaped: use object literals or <code>type</code> aliases. An <code>interface</code> type fails assignability (no index signature), and tsx won&#39;t catch it. Your typecheck will.</p><p>Throwing inside <code>execute</code> reports an error result to the model (<code>isError: true</code>). The turn and the server keep running.</p><h3 id="declare-structured-output" tabindex="-1">Declare structured output <a class="header-anchor" href="#declare-structured-output" aria-label="Permalink to &quot;Declare structured output&quot;">​</a></h3><p>Set <code>outputSchema</code> when MCP clients need a structured result contract. Use a Zod schema or plain JSON Schema:</p><div class="language-ts vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">ts</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">const</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> Weather</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> z.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">object</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">({</span></span>
25
+ <span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">});</span></span></code></pre></div><h3 id="tool-context" tabindex="-1">Tool context <a class="header-anchor" href="#tool-context" aria-label="Permalink to &quot;Tool context&quot;">​</a></h3><p><code>execute</code> receives a <code>ctx</code> with the runtime accessors:</p><table tabindex="0"><thead><tr><th>Member</th><th>What it is</th></tr></thead><tbody><tr><td><code>ctx.toolCallId</code></td><td>The call id, matching the <code>actions.requested</code> / <code>action.result</code> stream events</td></tr><tr><td><code>ctx.session</code></td><td>Read-only session info: id, channel, mode, auth</td></tr><tr><td><code>ctx.approvedBy</code></td><td>For a <code>needsApproval</code> tool, the auth of whoever approved this call, in the same shape as <code>ctx.session.auth</code>. On Slack, <code>attributes.user_id</code> is the person who clicked Approve, who can differ from the person who started the thread. Unset when the call needed no approval</td></tr><tr><td><code>ctx.workspaceDir</code></td><td>The session&#39;s workspace directory</td></tr><tr><td><code>ctx.stateRoot</code></td><td>The agent&#39;s durable state root, shared across every session</td></tr><tr><td><code>ctx.host</code></td><td>Shared host services (see below)</td></tr><tr><td><code>ctx.send(channelId, message, options?)</code></td><td>Start or resume a session on any channel. <code>auth</code> defaults to this call&#39;s session principal</td></tr><tr><td><code>ctx.getSession(channelId, sessionId)</code></td><td>Look up a session on a channel</td></tr><tr><td><code>ctx.artifacts</code></td><td>Session-bound <a href="./artifacts.html">artifacts</a> facade: <code>tag</code> auto-fills the session</td></tr></tbody></table><p><code>ctx.host</code> carries the shared host services: <code>host.mcp</code> (authored MCP connections: <code>names()</code>, <code>listTools(name)</code>, <code>callTool(name, tool, args)</code>), <code>host.github</code> and <code>host.slack</code> (shared platform clients), <code>host.kv</code> and <code>host.files</code> (durable storage), and <code>host.reminders</code> (per-session wakes, when attached). Custom metrics use the <a href="./../guides/opentelemetry.html">OpenTelemetry</a> API.</p><h3 id="return-values" tabindex="-1">Return values <a class="header-anchor" href="#return-values" aria-label="Permalink to &quot;Return values&quot;">​</a></h3><p><code>execute</code> may return a string (passed to the model verbatim), a JSON-shaped value (serialized), or the envelope <code>{ content: [...], isError? }</code> for rich results. Returns must be JSON-shaped: use object literals or <code>type</code> aliases. An <code>interface</code> type fails assignability (no index signature), and tsx won&#39;t catch it. Your typecheck will.</p><p>Throwing inside <code>execute</code> reports an error result to the model (<code>isError: true</code>). The turn and the server keep running.</p><h3 id="declare-structured-output" tabindex="-1">Declare structured output <a class="header-anchor" href="#declare-structured-output" aria-label="Permalink to &quot;Declare structured output&quot;">​</a></h3><p>Set <code>outputSchema</code> when MCP clients need a structured result contract. Use a Zod schema or plain JSON Schema:</p><div class="language-ts vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">ts</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">const</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> Weather</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> z.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">object</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">({</span></span>
26
26
  <span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> city: z.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">string</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(),</span></span>
27
27
  <span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> temperatureF: z.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">number</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(),</span></span>
28
28
  <span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">});</span></span>