@cursor/bdk 0.2.3 → 0.2.5
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.
- package/README.md +76 -1154
- package/dist/bin/agent-serve.js +9 -1
- package/dist/channels/slack/attachments.d.ts +2 -1
- package/dist/channels/slack/attachments.d.ts.map +1 -1
- package/dist/channels/slack/attachments.js +19 -9
- package/dist/channels/slack/dispatch.d.ts.map +1 -1
- package/dist/channels/slack/dispatch.js +26 -24
- package/dist/channels/slack/thread-context.d.ts +21 -11
- package/dist/channels/slack/thread-context.d.ts.map +1 -1
- package/dist/channels/slack/thread-context.js +75 -27
- package/dist/docs/404.html +2 -2
- package/dist/docs/assets/{app.BOIHhrKi.js → app.94Iu5dyD.js} +4 -4
- package/dist/docs/assets/{building-with-agents.md.-fcjCmJU.js → building-with-agents.md.BPjPFxFg.js} +2 -2
- package/dist/docs/assets/{building-with-agents.md.-fcjCmJU.lean.js → building-with-agents.md.BPjPFxFg.lean.js} +1 -1
- package/dist/docs/assets/chunks/@localSearchIndexroot.BITLoOQa.js +1 -0
- package/dist/docs/assets/chunks/{VPLocalSearchBox.D49zVZqM.js → VPLocalSearchBox.DTKFDlBr.js} +1 -1
- package/dist/docs/assets/chunks/{arc.hmjb-sc4.js → arc.DuzwHEeg.js} +1 -1
- package/dist/docs/assets/chunks/{architectureDiagram-Q4EWVU46.CxEI1KqM.js → architectureDiagram-Q4EWVU46.C6lyhLs0.js} +1 -1
- package/dist/docs/assets/chunks/{baseUniq.DHHvBWoV.js → baseUniq.DUNEWlY8.js} +1 -1
- package/dist/docs/assets/chunks/{blockDiagram-DXYQGD6D.DnXW-3bu.js → blockDiagram-DXYQGD6D.CXOQGI0O.js} +1 -1
- package/dist/docs/assets/chunks/{c4Diagram-AHTNJAMY.e-47O2jM.js → c4Diagram-AHTNJAMY.BYdPE-Oe.js} +1 -1
- package/dist/docs/assets/chunks/channel.B46uXH41.js +1 -0
- package/dist/docs/assets/chunks/{chunk-4BX2VUAB.3ry4pYXB.js → chunk-4BX2VUAB.YIV9HeX0.js} +1 -1
- package/dist/docs/assets/chunks/{chunk-4TB4RGXK.DGIZFRx6.js → chunk-4TB4RGXK.BG80DEOc.js} +1 -1
- package/dist/docs/assets/chunks/{chunk-55IACEB6.DKBnqg9U.js → chunk-55IACEB6.BDKJSZQc.js} +1 -1
- package/dist/docs/assets/chunks/{chunk-EDXVE4YY.BIU8Ue5k.js → chunk-EDXVE4YY.CtYnQqts.js} +1 -1
- package/dist/docs/assets/chunks/{chunk-FMBD7UC4.DP-TFhjI.js → chunk-FMBD7UC4.CityOth-.js} +1 -1
- package/dist/docs/assets/chunks/{chunk-OYMX7WX6.Ux0OYj5v.js → chunk-OYMX7WX6.CMD22CQX.js} +1 -1
- package/dist/docs/assets/chunks/{chunk-QZHKN3VN.BzHMwYox.js → chunk-QZHKN3VN.WWpc3ND0.js} +1 -1
- package/dist/docs/assets/chunks/{chunk-YZCP3GAM.D4OGAsSP.js → chunk-YZCP3GAM.BMg-yhj3.js} +1 -1
- package/dist/docs/assets/chunks/classDiagram-6PBFFD2Q.0cmCFsSf.js +1 -0
- package/dist/docs/assets/chunks/classDiagram-v2-HSJHXN6E.0cmCFsSf.js +1 -0
- package/dist/docs/assets/chunks/clone.1vTOFZT1.js +1 -0
- package/dist/docs/assets/chunks/{cose-bilkent-S5V4N54A.Jq_7BUNx.js → cose-bilkent-S5V4N54A.Buu_LC5q.js} +1 -1
- package/dist/docs/assets/chunks/{dagre-KV5264BT.Di-skR2x.js → dagre-KV5264BT.DW7onj6E.js} +1 -1
- package/dist/docs/assets/chunks/{diagram-5BDNPKRD.DeREHIdH.js → diagram-5BDNPKRD.B3NxIbEV.js} +1 -1
- package/dist/docs/assets/chunks/{diagram-G4DWMVQ6.C7Kcqxro.js → diagram-G4DWMVQ6.BJvN6Vkv.js} +1 -1
- package/dist/docs/assets/chunks/{diagram-MMDJMWI5.BK3eohyo.js → diagram-MMDJMWI5.wfRWrexs.js} +1 -1
- package/dist/docs/assets/chunks/{diagram-TYMM5635.C6TyymXT.js → diagram-TYMM5635.7QtjSYio.js} +1 -1
- package/dist/docs/assets/chunks/{erDiagram-SMLLAGMA.DYGG-gGx.js → erDiagram-SMLLAGMA.jxPgDH1t.js} +1 -1
- package/dist/docs/assets/chunks/{flowDiagram-DWJPFMVM.C9nBcSV4.js → flowDiagram-DWJPFMVM.BhDWA-TO.js} +1 -1
- package/dist/docs/assets/chunks/{ganttDiagram-T4ZO3ILL.wAg_ymsp.js → ganttDiagram-T4ZO3ILL.Ijq8iYKv.js} +1 -1
- package/dist/docs/assets/chunks/{gitGraphDiagram-UUTBAWPF.B87j9Oeg.js → gitGraphDiagram-UUTBAWPF.DXpfW4YG.js} +1 -1
- package/dist/docs/assets/chunks/{graph.CuFMj31w.js → graph.CoPlssRl.js} +1 -1
- package/dist/docs/assets/chunks/{infoDiagram-42DDH7IO.P_mLGumP.js → infoDiagram-42DDH7IO.eJuv_EOz.js} +1 -1
- package/dist/docs/assets/chunks/{ishikawaDiagram-UXIWVN3A.DyuL_MsT.js → ishikawaDiagram-UXIWVN3A._OEzenCR.js} +1 -1
- package/dist/docs/assets/chunks/{journeyDiagram-VCZTEJTY.CtP09IoJ.js → journeyDiagram-VCZTEJTY.CwlTjirB.js} +1 -1
- package/dist/docs/assets/chunks/{kanban-definition-6JOO6SKY.BoeSYPZo.js → kanban-definition-6JOO6SKY.DSp_C8cZ.js} +1 -1
- package/dist/docs/assets/chunks/{layout.B0lMMtNo.js → layout.Bms9s7uB.js} +1 -1
- package/dist/docs/assets/chunks/{linear.HxRBiAFX.js → linear.BjnmB4je.js} +1 -1
- package/dist/docs/assets/chunks/{min.BGlFFHwS.js → min.CKkYlMsn.js} +1 -1
- package/dist/docs/assets/chunks/{mindmap-definition-QFDTVHPH.JyLBD9M8.js → mindmap-definition-QFDTVHPH.T2d0vJ7X.js} +1 -1
- package/dist/docs/assets/chunks/{pieDiagram-DEJITSTG.DnSmNZF8.js → pieDiagram-DEJITSTG.DU0RoCvx.js} +1 -1
- package/dist/docs/assets/chunks/{quadrantDiagram-34T5L4WZ.CUCnbfCa.js → quadrantDiagram-34T5L4WZ.9QZjM-x0.js} +1 -1
- package/dist/docs/assets/chunks/{requirementDiagram-MS252O5E.py0IVUn5.js → requirementDiagram-MS252O5E.CZpylJMd.js} +1 -1
- package/dist/docs/assets/chunks/{sankeyDiagram-XADWPNL6.Bkc-HWYp.js → sankeyDiagram-XADWPNL6.CnFdfW95.js} +1 -1
- package/dist/docs/assets/chunks/{sequenceDiagram-FGHM5R23.Dqn8Mlv2.js → sequenceDiagram-FGHM5R23.-jC0PP1t.js} +1 -1
- package/dist/docs/assets/chunks/{stateDiagram-FHFEXIEX.JikkoQUU.js → stateDiagram-FHFEXIEX.DG7yBRUU.js} +1 -1
- package/dist/docs/assets/chunks/stateDiagram-v2-QKLJ7IA2.CbsZcOOu.js +1 -0
- package/dist/docs/assets/chunks/{theme.b6HQ6zG_.js → theme.B3O9koXV.js} +2 -2
- package/dist/docs/assets/chunks/{timeline-definition-GMOUNBTQ.BvpSXiBj.js → timeline-definition-GMOUNBTQ.Bf9u4Ebb.js} +1 -1
- package/dist/docs/assets/chunks/{vennDiagram-DHZGUBPP.CU7MVnZx.js → vennDiagram-DHZGUBPP.BjhbbYE6.js} +1 -1
- package/dist/docs/assets/chunks/{wardley-RL74JXVD.BKwC4ctG.js → wardley-RL74JXVD.DEA21akR.js} +1 -1
- package/dist/docs/assets/chunks/{wardleyDiagram-NUSXRM2D.BfaF6Uhe.js → wardleyDiagram-NUSXRM2D.8fRb4Nb5.js} +1 -1
- package/dist/docs/assets/chunks/{xychartDiagram-5P7HB3ND.Bg5dcpj4.js → xychartDiagram-5P7HB3ND.DoOP3zZM.js} +1 -1
- package/dist/docs/assets/{deployment.md.BJ8i7Q6p.js → deployment.md.BdqTiGdc.js} +5 -5
- package/dist/docs/assets/{deployment.md.BJ8i7Q6p.lean.js → deployment.md.BdqTiGdc.lean.js} +1 -1
- package/dist/docs/assets/{evals.md.CCAtNcuL.js → evals.md.LRCSn6Ik.js} +2 -2
- package/dist/docs/assets/{evals.md.CCAtNcuL.lean.js → evals.md.LRCSn6Ik.lean.js} +1 -1
- package/dist/docs/assets/{guides_agent-to-agent.md.CGkicXeB.js → guides_agent-to-agent.md.Cps5NiCV.js} +2 -2
- package/dist/docs/assets/{guides_agent-to-agent.md.CGkicXeB.lean.js → guides_agent-to-agent.md.Cps5NiCV.lean.js} +1 -1
- package/dist/docs/assets/{guides_bitbucket.md.Cb3LPKt3.js → guides_bitbucket.md.BB6fqD-M.js} +2 -2
- package/dist/docs/assets/{guides_bitbucket.md.Cb3LPKt3.lean.js → guides_bitbucket.md.BB6fqD-M.lean.js} +1 -1
- package/dist/docs/assets/{guides_cloud-agents.md.BuEkDCwo.js → guides_cloud-agents.md.CWJjS9No.js} +2 -2
- package/dist/docs/assets/{guides_cloud-agents.md.BuEkDCwo.lean.js → guides_cloud-agents.md.CWJjS9No.lean.js} +1 -1
- package/dist/docs/assets/{guides_convert-automation.md.Ci-Y2iD5.js → guides_convert-automation.md.DMEX9nF-.js} +3 -3
- package/dist/docs/assets/{guides_convert-automation.md.Ci-Y2iD5.lean.js → guides_convert-automation.md.DMEX9nF-.lean.js} +1 -1
- package/dist/docs/assets/{guides_github.md.Bq9kQU9B.js → guides_github.md.Cr1Xlf-m.js} +3 -3
- package/dist/docs/assets/{guides_github.md.Bq9kQU9B.lean.js → guides_github.md.Cr1Xlf-m.lean.js} +1 -1
- package/dist/docs/assets/{guides_gitlab.md.BM27P43u.js → guides_gitlab.md.CMpmFi4M.js} +2 -2
- package/dist/docs/assets/{guides_gitlab.md.BM27P43u.lean.js → guides_gitlab.md.CMpmFi4M.lean.js} +1 -1
- package/dist/docs/assets/{guides_grokbot-agents.md.yxVbSlKA.js → guides_grokbot-agents.md.tD1smFhU.js} +2 -2
- package/dist/docs/assets/{guides_grokbot-agents.md.yxVbSlKA.lean.js → guides_grokbot-agents.md.tD1smFhU.lean.js} +1 -1
- package/dist/docs/assets/{guides_hooks.md.BWoiNaMq.js → guides_hooks.md.5Ce3NXxZ.js} +2 -2
- package/dist/docs/assets/{guides_hooks.md.BWoiNaMq.lean.js → guides_hooks.md.5Ce3NXxZ.lean.js} +1 -1
- package/dist/docs/assets/{guides_improve.md.COtL-6ft.js → guides_improve.md.CRrYq22s.js} +2 -2
- package/dist/docs/assets/{guides_improve.md.COtL-6ft.lean.js → guides_improve.md.CRrYq22s.lean.js} +1 -1
- package/dist/docs/assets/{guides_jev.md.BNDm14Gy.js → guides_jev.md.D7XH4JH3.js} +2 -2
- package/dist/docs/assets/{guides_mcp-oauth.md.Cu6mhZ_3.js → guides_mcp-oauth.md.DR3zhC9r.js} +2 -2
- package/dist/docs/assets/{guides_mcp-oauth.md.Cu6mhZ_3.lean.js → guides_mcp-oauth.md.DR3zhC9r.lean.js} +1 -1
- package/dist/docs/assets/{guides_opentelemetry.md.DLlIB5rv.js → guides_opentelemetry.md.jcPNrQbH.js} +8 -6
- package/dist/docs/assets/{guides_opentelemetry.md.DLlIB5rv.lean.js → guides_opentelemetry.md.jcPNrQbH.lean.js} +1 -1
- package/dist/docs/assets/{guides_slack.md.diqqXTTm.js → guides_slack.md.Bn-WupSE.js} +8 -8
- package/dist/docs/assets/{guides_slack.md.diqqXTTm.lean.js → guides_slack.md.Bn-WupSE.lean.js} +1 -1
- package/dist/docs/assets/{guides_webhooks.md.D0furjw0.js → guides_webhooks.md.BBvAm_VF.js} +2 -2
- package/dist/docs/assets/{guides_webhooks.md.D0furjw0.lean.js → guides_webhooks.md.BBvAm_VF.lean.js} +1 -1
- package/dist/docs/assets/{hillclimbing.md.Biy0m-Qb.js → hillclimbing.md.Dxvd-0gT.js} +2 -2
- package/dist/docs/assets/{hillclimbing.md.Biy0m-Qb.lean.js → hillclimbing.md.Dxvd-0gT.lean.js} +1 -1
- package/dist/docs/assets/index.md.Dxxr7pFa.js +27 -0
- package/dist/docs/assets/{index.md.CVc_oOA3.lean.js → index.md.Dxxr7pFa.lean.js} +1 -1
- package/dist/docs/assets/{quickstart.md.CHpHPBUN.js → quickstart.md.BK5gjHM2.js} +2 -2
- package/dist/docs/assets/{quickstart.md.CHpHPBUN.lean.js → quickstart.md.BK5gjHM2.lean.js} +1 -1
- package/dist/docs/assets/{reference_agent-config.md.DzGI777n.js → reference_agent-config.md.DrtLxWgR.js} +4 -4
- package/dist/docs/assets/{reference_agent-config.md.DzGI777n.lean.js → reference_agent-config.md.DrtLxWgR.lean.js} +1 -1
- package/dist/docs/assets/{reference_artifacts.md.CQfKq8F2.js → reference_artifacts.md.DLV9MZES.js} +2 -2
- package/dist/docs/assets/{reference_artifacts.md.CQfKq8F2.lean.js → reference_artifacts.md.DLV9MZES.lean.js} +1 -1
- package/dist/docs/assets/{reference_channels.md.mbNtKCiR.js → reference_channels.md.LbNIJBwd.js} +2 -2
- package/dist/docs/assets/{reference_channels.md.mbNtKCiR.lean.js → reference_channels.md.LbNIJBwd.lean.js} +1 -1
- package/dist/docs/assets/{reference_cli.md.DgeLTO18.js → reference_cli.md.BsgDqYPh.js} +4 -4
- package/dist/docs/assets/{reference_cli.md.DgeLTO18.lean.js → reference_cli.md.BsgDqYPh.lean.js} +1 -1
- package/dist/docs/assets/{reference_connections.md.COq--gAm.js → reference_connections.md.Bljpve-y.js} +4 -4
- package/dist/docs/assets/{reference_connections.md.COq--gAm.lean.js → reference_connections.md.Bljpve-y.lean.js} +1 -1
- package/dist/docs/assets/{reference_evals.md.CJm3uCUm.js → reference_evals.md.D5i8PuXJ.js} +2 -2
- package/dist/docs/assets/{reference_evals.md.CJm3uCUm.lean.js → reference_evals.md.D5i8PuXJ.lean.js} +1 -1
- package/dist/docs/assets/{reference_extensions.md.CPPrkWlJ.js → reference_extensions.md.OUacPetl.js} +5 -4
- package/dist/docs/assets/{reference_extensions.md.CPPrkWlJ.lean.js → reference_extensions.md.OUacPetl.lean.js} +1 -1
- package/dist/docs/assets/{reference_hooks.md.DbthhtIR.js → reference_hooks.md.C5LCJ1R3.js} +2 -2
- package/dist/docs/assets/{reference_hooks.md.DbthhtIR.lean.js → reference_hooks.md.C5LCJ1R3.lean.js} +1 -1
- package/dist/docs/assets/{reference_http-api.md.BZOvhCqY.js → reference_http-api.md.DbFNOubV.js} +1 -1
- package/dist/docs/assets/{reference_instructions.md.Bdwscs4G.js → reference_instructions.md.DrcHZXig.js} +2 -2
- package/dist/docs/assets/{reference_instructions.md.Bdwscs4G.lean.js → reference_instructions.md.DrcHZXig.lean.js} +1 -1
- package/dist/docs/assets/reference_playground.md.1hx0gcIu.js +1 -0
- package/dist/docs/assets/{reference_playground.md.BdQzRJc2.lean.js → reference_playground.md.1hx0gcIu.lean.js} +1 -1
- package/dist/docs/assets/{reference_project-layout.md.CpLQ9j4K.js → reference_project-layout.md.C2JMRh7p.js} +2 -2
- package/dist/docs/assets/{reference_prompt.md.BQZB4eaV.js → reference_prompt.md.DqPh71XN.js} +3 -3
- package/dist/docs/assets/{reference_prompt.md.BQZB4eaV.lean.js → reference_prompt.md.DqPh71XN.lean.js} +1 -1
- package/dist/docs/assets/{reference_schedules.md.BVU5EFbz.js → reference_schedules.md.BuJ8fgMa.js} +2 -2
- package/dist/docs/assets/{reference_schedules.md.BVU5EFbz.lean.js → reference_schedules.md.BuJ8fgMa.lean.js} +1 -1
- package/dist/docs/assets/reference_sessions.md.CM5zo3w4.js +1 -0
- package/dist/docs/assets/{reference_sessions.md.DeRUItHD.lean.js → reference_sessions.md.CM5zo3w4.lean.js} +1 -1
- package/dist/docs/assets/{reference_skills.md.Cy00QMKS.js → reference_skills.md.C0guGcH0.js} +4 -4
- package/dist/docs/assets/{reference_skills.md.Cy00QMKS.lean.js → reference_skills.md.C0guGcH0.lean.js} +1 -1
- package/dist/docs/assets/{reference_subagents.md.B8oyeXOI.js → reference_subagents.md.gmPt5J-M.js} +2 -2
- package/dist/docs/assets/{reference_subagents.md.B8oyeXOI.lean.js → reference_subagents.md.gmPt5J-M.lean.js} +1 -1
- package/dist/docs/assets/{reference_tools.md.hg2Wi5Bq.js → reference_tools.md.v3SXVSs_.js} +2 -2
- package/dist/docs/assets/{reference_tools.md.hg2Wi5Bq.lean.js → reference_tools.md.v3SXVSs_.lean.js} +1 -1
- package/dist/docs/assets/{templates_agentic-owners.md.BykUiZ8j.js → templates_agentic-owners.md.vtjfwxbf.js} +2 -2
- package/dist/docs/assets/{templates_agentic-owners.md.BykUiZ8j.lean.js → templates_agentic-owners.md.vtjfwxbf.lean.js} +1 -1
- package/dist/docs/assets/templates_grokbot-agents.md.2sydjFiO.js +5 -0
- package/dist/docs/assets/templates_grokbot-agents.md.2sydjFiO.lean.js +1 -0
- package/dist/docs/assets/{templates_security-reviewer.md.DXMmKl_o.js → templates_security-reviewer.md.CX9l9bcg.js} +2 -2
- package/dist/docs/assets/{templates_security-reviewer.md.DXMmKl_o.lean.js → templates_security-reviewer.md.CX9l9bcg.lean.js} +1 -1
- package/dist/docs/assets/{templates_thermo-quality-review.md.Dg1p1MsG.js → templates_thermo-quality-review.md.95qmTmr1.js} +2 -2
- package/dist/docs/assets/{templates_thermo-quality-review.md.Dg1p1MsG.lean.js → templates_thermo-quality-review.md.95qmTmr1.lean.js} +1 -1
- package/dist/docs/assets/{templates_thermo-review.md.Dlylkowj.js → templates_thermo-review.md.DQh6Q0C-.js} +2 -2
- package/dist/docs/assets/{templates_thermo-review.md.Dlylkowj.lean.js → templates_thermo-review.md.DQh6Q0C-.lean.js} +1 -1
- package/dist/docs/assets/{templates_triage.md.CvJyx81N.js → templates_triage.md.BFlQhWXf.js} +3 -3
- package/dist/docs/assets/{templates_triage.md.CvJyx81N.lean.js → templates_triage.md.BFlQhWXf.lean.js} +1 -1
- package/dist/docs/assets/troubleshooting.md.Bscj6ODe.js +1 -0
- package/dist/docs/assets/{troubleshooting.md.Cw5PKa3t.lean.js → troubleshooting.md.Bscj6ODe.lean.js} +1 -1
- package/dist/docs/building-with-agents.html +36 -36
- package/dist/docs/building-with-agents.md +0 -3
- package/dist/docs/deployment.html +39 -39
- package/dist/docs/deployment.md +6 -10
- package/dist/docs/evals.html +36 -36
- package/dist/docs/evals.md +0 -3
- package/dist/docs/guides/agent-to-agent.html +36 -36
- package/dist/docs/guides/agent-to-agent.md +0 -3
- package/dist/docs/guides/bitbucket.html +36 -36
- package/dist/docs/guides/bitbucket.md +0 -3
- package/dist/docs/guides/cloud-agents.html +36 -36
- package/dist/docs/guides/cloud-agents.md +0 -4
- package/dist/docs/guides/convert-automation.html +37 -37
- package/dist/docs/guides/convert-automation.md +2 -5
- package/dist/docs/guides/github.html +37 -37
- package/dist/docs/guides/github.md +1 -4
- package/dist/docs/guides/gitlab.html +36 -36
- package/dist/docs/guides/gitlab.md +0 -3
- package/dist/docs/guides/grokbot-agents.html +37 -37
- package/dist/docs/guides/grokbot-agents.md +1 -4
- package/dist/docs/guides/hooks.html +36 -36
- package/dist/docs/guides/hooks.md +0 -3
- package/dist/docs/guides/improve.html +36 -36
- package/dist/docs/guides/improve.md +0 -3
- package/dist/docs/guides/jev.html +37 -37
- package/dist/docs/guides/jev.md +7 -3
- package/dist/docs/guides/mcp-oauth.html +37 -37
- package/dist/docs/guides/mcp-oauth.md +1 -4
- package/dist/docs/guides/opentelemetry.html +42 -40
- package/dist/docs/guides/opentelemetry.md +4 -5
- package/dist/docs/guides/slack.html +43 -43
- package/dist/docs/guides/slack.md +14 -24
- package/dist/docs/guides/webhooks.html +36 -36
- package/dist/docs/guides/webhooks.md +0 -3
- package/dist/docs/hashmap.json +1 -1
- package/dist/docs/hillclimbing.html +36 -36
- package/dist/docs/hillclimbing.md +0 -3
- package/dist/docs/index.html +38 -38
- package/dist/docs/index.md +9 -16
- package/dist/docs/llms-full.txt +156 -220
- package/dist/docs/llms.txt +1 -0
- package/dist/docs/quickstart.html +36 -36
- package/dist/docs/quickstart.md +2 -7
- package/dist/docs/reference/agent-config.html +38 -38
- package/dist/docs/reference/agent-config.md +4 -7
- package/dist/docs/reference/artifacts.html +36 -36
- package/dist/docs/reference/artifacts.md +0 -3
- package/dist/docs/reference/channels.html +37 -37
- package/dist/docs/reference/channels.md +1 -6
- package/dist/docs/reference/cli.html +38 -38
- package/dist/docs/reference/cli.md +7 -14
- package/dist/docs/reference/connections.html +38 -38
- package/dist/docs/reference/connections.md +7 -10
- package/dist/docs/reference/evals.html +36 -36
- package/dist/docs/reference/evals.md +0 -3
- package/dist/docs/reference/extensions.html +40 -39
- package/dist/docs/reference/extensions.md +15 -5
- package/dist/docs/reference/hooks.html +36 -36
- package/dist/docs/reference/hooks.md +0 -3
- package/dist/docs/reference/http-api.html +37 -37
- package/dist/docs/reference/http-api.md +1 -1
- package/dist/docs/reference/instructions.html +36 -36
- package/dist/docs/reference/instructions.md +0 -3
- package/dist/docs/reference/playground.html +36 -36
- package/dist/docs/reference/playground.md +0 -3
- package/dist/docs/reference/project-layout.html +37 -37
- package/dist/docs/reference/project-layout.md +2 -2
- package/dist/docs/reference/prompt.html +37 -37
- package/dist/docs/reference/prompt.md +0 -3
- package/dist/docs/reference/schedules.html +36 -36
- package/dist/docs/reference/schedules.md +0 -3
- package/dist/docs/reference/sessions.html +36 -36
- package/dist/docs/reference/sessions.md +0 -3
- package/dist/docs/reference/skills.html +38 -38
- package/dist/docs/reference/skills.md +0 -3
- package/dist/docs/reference/subagents.html +36 -36
- package/dist/docs/reference/subagents.md +0 -3
- package/dist/docs/reference/tools.html +36 -36
- package/dist/docs/reference/tools.md +1 -5
- package/dist/docs/templates/agentic-owners.html +36 -36
- package/dist/docs/templates/agentic-owners.md +0 -3
- package/dist/docs/templates/grokbot-agents.html +64 -0
- package/dist/docs/templates/grokbot-agents.md +55 -0
- package/dist/docs/templates/security-reviewer.html +37 -37
- package/dist/docs/templates/security-reviewer.md +0 -3
- package/dist/docs/templates/thermo-quality-review.html +36 -36
- package/dist/docs/templates/thermo-quality-review.md +3 -6
- package/dist/docs/templates/thermo-review.html +36 -36
- package/dist/docs/templates/thermo-review.md +3 -5
- package/dist/docs/templates/triage.html +37 -37
- package/dist/docs/templates/triage.md +2 -3
- package/dist/docs/troubleshooting.html +36 -36
- package/dist/docs/troubleshooting.md +3 -7
- package/dist/extensions/jev/extension.d.ts +3 -0
- package/dist/extensions/jev/extension.d.ts.map +1 -1
- package/dist/extensions/jev/extension.js +10 -1
- package/dist/extensions/jev/lib/evaluate.d.ts +4 -0
- package/dist/extensions/jev/lib/evaluate.d.ts.map +1 -1
- package/dist/extensions/jev/lib/evaluate.js +6 -2
- package/dist/extensions.d.ts +4 -2
- package/dist/extensions.d.ts.map +1 -1
- package/dist/extensions.js +5 -2
- package/dist/internal/cli-deploy.d.ts.map +1 -1
- package/dist/internal/cli-deploy.js +19 -5
- package/dist/internal/discovery/agent-config.d.ts +6 -5
- package/dist/internal/discovery/agent-config.d.ts.map +1 -1
- package/dist/internal/discovery/agent-config.js +29 -28
- package/dist/internal/discovery/agent.js +1 -1
- package/dist/internal/discovery/extensions.d.ts.map +1 -1
- package/dist/internal/discovery/extensions.js +12 -0
- package/dist/internal/hosting.d.ts +8 -0
- package/dist/internal/hosting.d.ts.map +1 -1
- package/dist/internal/hosting.js +24 -0
- package/dist/types.d.ts +18 -2
- package/dist/types.d.ts.map +1 -1
- package/docs/README.md +9 -16
- package/docs/building-with-agents.md +0 -3
- package/docs/deployment.md +6 -10
- package/docs/evals.md +0 -3
- package/docs/guides/agent-to-agent.md +0 -3
- package/docs/guides/bitbucket.md +0 -3
- package/docs/guides/cloud-agents.md +0 -4
- package/docs/guides/convert-automation.md +2 -5
- package/docs/guides/github.md +1 -4
- package/docs/guides/gitlab.md +0 -3
- package/docs/guides/grokbot-agents.md +1 -4
- package/docs/guides/hooks.md +0 -3
- package/docs/guides/improve.md +0 -3
- package/docs/guides/jev.md +7 -3
- package/docs/guides/mcp-oauth.md +1 -4
- package/docs/guides/opentelemetry.md +4 -5
- package/docs/guides/slack.md +14 -24
- package/docs/guides/webhooks.md +0 -3
- package/docs/hillclimbing.md +0 -3
- package/docs/quickstart.md +2 -7
- package/docs/reference/agent-config.md +4 -7
- package/docs/reference/artifacts.md +0 -3
- package/docs/reference/channels.md +1 -6
- package/docs/reference/cli.md +7 -14
- package/docs/reference/connections.md +7 -10
- package/docs/reference/evals.md +0 -3
- package/docs/reference/extensions.md +15 -5
- package/docs/reference/hooks.md +0 -3
- package/docs/reference/http-api.md +1 -1
- package/docs/reference/instructions.md +0 -3
- package/docs/reference/playground.md +0 -3
- package/docs/reference/project-layout.md +2 -2
- package/docs/reference/prompt.md +0 -3
- package/docs/reference/schedules.md +0 -3
- package/docs/reference/sessions.md +0 -3
- package/docs/reference/skills.md +0 -3
- package/docs/reference/subagents.md +0 -3
- package/docs/reference/tools.md +1 -5
- package/docs/templates/agentic-owners.md +0 -3
- package/docs/templates/grokbot-agents.md +60 -0
- package/docs/templates/security-reviewer.md +0 -3
- package/docs/templates/thermo-quality-review.md +3 -6
- package/docs/templates/thermo-review.md +3 -5
- package/docs/templates/triage.md +2 -3
- package/docs/troubleshooting.md +3 -7
- package/package.json +2 -10
- package/templates/agentic-owners/README.md +0 -3
- package/templates/agents-md/README.md +4 -3
- package/templates/code-wiki/README.md +0 -3
- package/templates/demo/README.md +0 -3
- package/templates/grokbot-agents/README.md +4 -6
- package/templates/security-help/README.md +12 -6
- package/templates/security-reviewer/README.md +0 -3
- package/templates/thermo-quality-review/README.md +0 -3
- package/templates/thermo-review/README.md +0 -3
- package/templates/triage/README.md +0 -3
- package/templates/triage/overlays/jira/README.md +0 -3
- package/templates/triage/overlays/linear/README.md +0 -3
- package/dist/docs/assets/chunks/@localSearchIndexroot.D5L-b34G.js +0 -1
- package/dist/docs/assets/chunks/channel.BbOGaJQP.js +0 -1
- package/dist/docs/assets/chunks/classDiagram-6PBFFD2Q.Db58HCb1.js +0 -1
- package/dist/docs/assets/chunks/classDiagram-v2-HSJHXN6E.Db58HCb1.js +0 -1
- package/dist/docs/assets/chunks/clone.Co4MBflG.js +0 -1
- package/dist/docs/assets/chunks/stateDiagram-v2-QKLJ7IA2.CMsKhrW0.js +0 -1
- package/dist/docs/assets/index.md.CVc_oOA3.js +0 -27
- package/dist/docs/assets/reference_playground.md.BdQzRJc2.js +0 -1
- package/dist/docs/assets/reference_sessions.md.DeRUItHD.js +0 -1
- package/dist/docs/assets/troubleshooting.md.Cw5PKa3t.js +0 -1
- package/src/artifacts.ts +0 -68
- package/src/bin/agent-serve.ts +0 -1854
- package/src/channels/bitbucket/api.ts +0 -891
- package/src/channels/bitbucket/binding.ts +0 -417
- package/src/channels/bitbucket/bitbucket-channel.ts +0 -162
- package/src/channels/bitbucket/bitbucket-webhook.ts +0 -519
- package/src/channels/bitbucket/checks.ts +0 -146
- package/src/channels/bitbucket/cursor-account.ts +0 -106
- package/src/channels/bitbucket/defaults.ts +0 -100
- package/src/channels/bitbucket/events.ts +0 -74
- package/src/channels/bitbucket/index.ts +0 -51
- package/src/channels/bitbucket/replay.ts +0 -421
- package/src/channels/bitbucket/state.ts +0 -59
- package/src/channels/bitbucket/types.ts +0 -261
- package/src/channels/change-monitors/change-monitors-channel.ts +0 -63
- package/src/channels/change-monitors/index.ts +0 -8
- package/src/channels/change-monitors/types.ts +0 -42
- package/src/channels/checks.ts +0 -185
- package/src/channels/deployments/deployments-channel.ts +0 -224
- package/src/channels/deployments/index.ts +0 -25
- package/src/channels/deployments/types.ts +0 -92
- package/src/channels/github/api.ts +0 -526
- package/src/channels/github/auth.ts +0 -293
- package/src/channels/github/binding.ts +0 -233
- package/src/channels/github/checks.ts +0 -145
- package/src/channels/github/cursor-account.ts +0 -303
- package/src/channels/github/defaults.ts +0 -168
- package/src/channels/github/events.ts +0 -67
- package/src/channels/github/forward.ts +0 -359
- package/src/channels/github/github-channel.ts +0 -2334
- package/src/channels/github/index.ts +0 -54
- package/src/channels/github/progress.ts +0 -365
- package/src/channels/github/replay.ts +0 -372
- package/src/channels/github/state.ts +0 -124
- package/src/channels/github/types.ts +0 -590
- package/src/channels/gitlab/api.ts +0 -329
- package/src/channels/gitlab/binding.ts +0 -231
- package/src/channels/gitlab/checks.ts +0 -228
- package/src/channels/gitlab/cursor-account.ts +0 -105
- package/src/channels/gitlab/defaults.ts +0 -80
- package/src/channels/gitlab/events.ts +0 -37
- package/src/channels/gitlab/gitlab-channel.ts +0 -160
- package/src/channels/gitlab/gitlab-webhook.ts +0 -509
- package/src/channels/gitlab/index.ts +0 -44
- package/src/channels/gitlab/replay.ts +0 -328
- package/src/channels/gitlab/state.ts +0 -55
- package/src/channels/gitlab/types.ts +0 -247
- package/src/channels/issues/index.ts +0 -9
- package/src/channels/issues/issues-channel.ts +0 -45
- package/src/channels/issues/types.ts +0 -38
- package/src/channels/origin/api.ts +0 -507
- package/src/channels/origin/binding.ts +0 -114
- package/src/channels/origin/checks.ts +0 -250
- package/src/channels/origin/cursor-account.ts +0 -58
- package/src/channels/origin/defaults.ts +0 -140
- package/src/channels/origin/events.ts +0 -35
- package/src/channels/origin/index.ts +0 -35
- package/src/channels/origin/origin-channel.ts +0 -815
- package/src/channels/origin/origin-webhook.ts +0 -296
- package/src/channels/origin/reactions.ts +0 -72
- package/src/channels/origin/state.ts +0 -54
- package/src/channels/origin/types.ts +0 -295
- package/src/channels/slack/agentic-delivery.ts +0 -634
- package/src/channels/slack/agentic-posted.ts +0 -135
- package/src/channels/slack/agentic-signals.ts +0 -231
- package/src/channels/slack/api.ts +0 -761
- package/src/channels/slack/approvals.ts +0 -279
- package/src/channels/slack/assistant.ts +0 -76
- package/src/channels/slack/attachments.ts +0 -596
- package/src/channels/slack/auth.ts +0 -127
- package/src/channels/slack/blocks.ts +0 -131
- package/src/channels/slack/bot-mentions.ts +0 -318
- package/src/channels/slack/channel-watch.ts +0 -314
- package/src/channels/slack/cli-project.ts +0 -249
- package/src/channels/slack/code-fences.ts +0 -171
- package/src/channels/slack/constants.ts +0 -38
- package/src/channels/slack/credentials.ts +0 -88
- package/src/channels/slack/defaults.ts +0 -714
- package/src/channels/slack/dispatch.ts +0 -1060
- package/src/channels/slack/doctor.ts +0 -338
- package/src/channels/slack/eval-directive.ts +0 -306
- package/src/channels/slack/event-id-dedupe.ts +0 -30
- package/src/channels/slack/external-policy.ts +0 -75
- package/src/channels/slack/footer.ts +0 -106
- package/src/channels/slack/inbound.ts +0 -416
- package/src/channels/slack/index.ts +0 -53
- package/src/channels/slack/init.ts +0 -169
- package/src/channels/slack/interactive.ts +0 -406
- package/src/channels/slack/links.ts +0 -23
- package/src/channels/slack/live-delivery.ts +0 -489
- package/src/channels/slack/log.ts +0 -70
- package/src/channels/slack/manifest.ts +0 -240
- package/src/channels/slack/message-body.ts +0 -82
- package/src/channels/slack/nudge-carrier.ts +0 -224
- package/src/channels/slack/nudge-store.ts +0 -334
- package/src/channels/slack/paint-start.ts +0 -93
- package/src/channels/slack/placeholder.ts +0 -358
- package/src/channels/slack/pr-ref.ts +0 -74
- package/src/channels/slack/progress-delivery.ts +0 -138
- package/src/channels/slack/reasoning-card.ts +0 -125
- package/src/channels/slack/reasoning-chip.ts +0 -41
- package/src/channels/slack/recording-sink.ts +0 -167
- package/src/channels/slack/redact.ts +0 -6
- package/src/channels/slack/reply-options.ts +0 -279
- package/src/channels/slack/setup.ts +0 -125
- package/src/channels/slack/slack-channel.ts +0 -744
- package/src/channels/slack/socket-mode.ts +0 -140
- package/src/channels/slack/stop.ts +0 -25
- package/src/channels/slack/stream.ts +0 -66
- package/src/channels/slack/thread-context.ts +0 -485
- package/src/channels/slack/tool-approval-events.ts +0 -233
- package/src/channels/slack/tool-cards.ts +0 -198
- package/src/channels/slack/tool-chip.ts +0 -34
- package/src/channels/slack/types.ts +0 -787
- package/src/channels/slack/upload.ts +0 -137
- package/src/channels.ts +0 -543
- package/src/connections.ts +0 -153
- package/src/dashboard-session-url.ts +0 -30
- package/src/evals/assertions.ts +0 -688
- package/src/evals/expect.ts +0 -250
- package/src/evals/judge.ts +0 -329
- package/src/evals/loaders.ts +0 -111
- package/src/evals/matchers.ts +0 -223
- package/src/evals/reporters.ts +0 -257
- package/src/evals/results.ts +0 -130
- package/src/evals/run-facts.ts +0 -306
- package/src/evals.ts +0 -709
- package/src/extensions/cursor-cloud-agents/extension.ts +0 -131
- package/src/extensions/cursor-cloud-agents/lib/backend.ts +0 -386
- package/src/extensions/cursor-cloud-agents/lib/channels.ts +0 -11
- package/src/extensions/cursor-cloud-agents/lib/fleet.ts +0 -98
- package/src/extensions/cursor-cloud-agents/lib/inputs.ts +0 -5
- package/src/extensions/cursor-cloud-agents/lib/repos.ts +0 -80
- package/src/extensions/cursor-cloud-agents/lib/transcript.ts +0 -19
- package/src/extensions/cursor-cloud-agents/skills/handoff.md +0 -37
- package/src/extensions/cursor-cloud-agents/tools/cancel.ts +0 -21
- package/src/extensions/cursor-cloud-agents/tools/dump.ts +0 -47
- package/src/extensions/cursor-cloud-agents/tools/get.ts +0 -18
- package/src/extensions/cursor-cloud-agents/tools/launch.ts +0 -62
- package/src/extensions/cursor-cloud-agents/tools/list.ts +0 -31
- package/src/extensions/cursor-cloud-agents/tools/reply.ts +0 -36
- package/src/extensions/cursor-grokbot-agents/extension.ts +0 -132
- package/src/extensions/cursor-grokbot-agents/lib/agents.ts +0 -42
- package/src/extensions/cursor-grokbot-agents/lib/backend.ts +0 -208
- package/src/extensions/cursor-grokbot-agents/lib/contacts.ts +0 -74
- package/src/extensions/cursor-grokbot-agents/lib/conversation.ts +0 -260
- package/src/extensions/cursor-grokbot-agents/lib/inputs.ts +0 -21
- package/src/extensions/cursor-grokbot-agents/lib/lock.ts +0 -26
- package/src/extensions/cursor-grokbot-agents/skills/consult.md +0 -40
- package/src/extensions/cursor-grokbot-agents/tools/ask.ts +0 -32
- package/src/extensions/cursor-grokbot-agents/tools/check.ts +0 -25
- package/src/extensions/cursor-grokbot-agents/tools/interrupt.ts +0 -17
- package/src/extensions/cursor-grokbot-agents/tools/list.ts +0 -26
- package/src/extensions/improve/extension.ts +0 -69
- package/src/extensions/improve/skills/yourself.ts +0 -50
- package/src/extensions/jev/extension.ts +0 -95
- package/src/extensions/jev/lib/evaluate.ts +0 -266
- package/src/extensions/jev/skills/gated-write.md +0 -25
- package/src/extensions/jev/skills/questions.md +0 -33
- package/src/extensions/jev/tools/evaluate.ts +0 -82
- package/src/extensions/slack-communication/evals/harness.ts +0 -705
- package/src/extensions/slack-communication/evals/slack-communication.eval.ts +0 -830
- package/src/extensions/slack-communication/evals/slack-placeholder.eval.ts +0 -172
- package/src/extensions/slack-communication/extension.ts +0 -44
- package/src/extensions/slack-communication/skills/slack-voice.ts +0 -56
- package/src/extensions/slack-communication/tools/delete-message.ts +0 -33
- package/src/extensions/slack-communication/tools/edit-message.ts +0 -42
- package/src/extensions/slack-communication/tools/post-card.ts +0 -28
- package/src/extensions/slack-communication/tools/post-file.ts +0 -82
- package/src/extensions/slack-communication/tools/post-update.ts +0 -40
- package/src/extensions/slack-communication/tools/react.ts +0 -30
- package/src/extensions/slack-communication/tools/set-status.ts +0 -21
- package/src/extensions.ts +0 -179
- package/src/files-backends/agent-store-presigned-url.ts +0 -11
- package/src/files-backends/cursor-hosted.ts +0 -1212
- package/src/files-backends/local-fs.ts +0 -163
- package/src/files.ts +0 -293
- package/src/filesystem.ts +0 -2005
- package/src/hooks.ts +0 -30
- package/src/index.ts +0 -259
- package/src/internal/advertise-tools.ts +0 -370
- package/src/internal/approval-gate.ts +0 -103
- package/src/internal/artifacts-store.ts +0 -836
- package/src/internal/as-of.ts +0 -257
- package/src/internal/auth.ts +0 -46
- package/src/internal/authored-alias-hooks.ts +0 -138
- package/src/internal/authored-loaders.ts +0 -188
- package/src/internal/bounded-int.ts +0 -24
- package/src/internal/bounded.ts +0 -25
- package/src/internal/brand.ts +0 -28
- package/src/internal/browser-origin-guard.ts +0 -67
- package/src/internal/builtin-tools/artifacts.ts +0 -62
- package/src/internal/builtin-tools/index.ts +0 -53
- package/src/internal/builtin-tools/reminders.ts +0 -145
- package/src/internal/channel-dispatch.ts +0 -129
- package/src/internal/channel-route-dispatch.ts +0 -58
- package/src/internal/channel-state.ts +0 -83
- package/src/internal/chat-client.ts +0 -594
- package/src/internal/cli-ax.ts +0 -2318
- package/src/internal/cli-bitbucket.ts +0 -438
- package/src/internal/cli-convert-automation.ts +0 -335
- package/src/internal/cli-cursor.ts +0 -282
- package/src/internal/cli-deploy.ts +0 -2519
- package/src/internal/cli-docs.ts +0 -192
- package/src/internal/cli-github.ts +0 -806
- package/src/internal/cli-gitlab.ts +0 -452
- package/src/internal/cli-images.ts +0 -672
- package/src/internal/cli-manifest.ts +0 -56
- package/src/internal/cli-mcp-oauth.ts +0 -396
- package/src/internal/cli-mcp.ts +0 -808
- package/src/internal/cli-skills.ts +0 -98
- package/src/internal/cli-slack-manual.ts +0 -418
- package/src/internal/cli-slack.ts +0 -874
- package/src/internal/cloud-merge.ts +0 -51
- package/src/internal/cloud-turn-cost.ts +0 -159
- package/src/internal/connection-env.ts +0 -106
- package/src/internal/continuation-channel.ts +0 -233
- package/src/internal/continuation-identity.ts +0 -935
- package/src/internal/conversation-mirror.ts +0 -423
- package/src/internal/convert-automation/convert-workflow.ts +0 -1377
- package/src/internal/convert-automation/slug.ts +0 -29
- package/src/internal/convert-automation/types.ts +0 -212
- package/src/internal/cron.ts +0 -76
- package/src/internal/cursor/account-mcp.ts +0 -692
- package/src/internal/cursor/backend-client.ts +0 -984
- package/src/internal/cursor/bound-secret-file.ts +0 -101
- package/src/internal/cursor/credentials.ts +0 -560
- package/src/internal/cursor/cursor-api-transport.ts +0 -65
- package/src/internal/cursor/github-credentials.ts +0 -228
- package/src/internal/cursor/hosted-bound-secrets.ts +0 -71
- package/src/internal/cursor/hosted-deployment-secrets.ts +0 -100
- package/src/internal/cursor/hosted-store-secrets.ts +0 -152
- package/src/internal/cursor/session-token.ts +0 -111
- package/src/internal/cursor/store-api-client.ts +0 -323
- package/src/internal/cursor-account-mcp-auth.ts +0 -303
- package/src/internal/cursor-agent-template.ts +0 -50
- package/src/internal/cursor-deployment-relay.ts +0 -315
- package/src/internal/cursor-event-relay.ts +0 -675
- package/src/internal/cursor-relay-core.ts +0 -563
- package/src/internal/deferred-channel-session.ts +0 -61
- package/src/internal/deploy-client.ts +0 -1574
- package/src/internal/deploy-manifest.ts +0 -361
- package/src/internal/deploy-source.ts +0 -144
- package/src/internal/describe-error.ts +0 -32
- package/src/internal/dev-mode.ts +0 -20
- package/src/internal/discovery/agent-config.ts +0 -288
- package/src/internal/discovery/agent.ts +0 -381
- package/src/internal/discovery/channels.ts +0 -100
- package/src/internal/discovery/connections.ts +0 -516
- package/src/internal/discovery/context.ts +0 -38
- package/src/internal/discovery/cursor-plugin.ts +0 -628
- package/src/internal/discovery/extension-overlay.ts +0 -247
- package/src/internal/discovery/extensions.ts +0 -490
- package/src/internal/discovery/fs.ts +0 -103
- package/src/internal/discovery/hooks.ts +0 -63
- package/src/internal/discovery/info.ts +0 -174
- package/src/internal/discovery/instructions.ts +0 -98
- package/src/internal/discovery/modules.ts +0 -107
- package/src/internal/discovery/names.ts +0 -45
- package/src/internal/discovery/project.ts +0 -319
- package/src/internal/discovery/reminders.ts +0 -65
- package/src/internal/discovery/runtime.ts +0 -158
- package/src/internal/discovery/schedules.ts +0 -120
- package/src/internal/discovery/seed-files.ts +0 -34
- package/src/internal/discovery/services.ts +0 -151
- package/src/internal/discovery/skills.ts +0 -174
- package/src/internal/discovery/subagent.ts +0 -138
- package/src/internal/discovery/tools.ts +0 -170
- package/src/internal/discovery.ts +0 -27
- package/src/internal/distribution.ts +0 -126
- package/src/internal/docs-site.ts +0 -248
- package/src/internal/duration.ts +0 -37
- package/src/internal/env-file.ts +0 -83
- package/src/internal/eval-judge-model.ts +0 -142
- package/src/internal/eval-run-store.ts +0 -585
- package/src/internal/eval-runner.ts +0 -823
- package/src/internal/evals-client.ts +0 -475
- package/src/internal/event-log.ts +0 -342
- package/src/internal/event-mapper.ts +0 -811
- package/src/internal/expected-delivery-failure.ts +0 -34
- package/src/internal/factory-resource-channel.ts +0 -103
- package/src/internal/filesystem/errors.ts +0 -207
- package/src/internal/filesystem/format.ts +0 -253
- package/src/internal/filesystem/merge.ts +0 -192
- package/src/internal/filesystem/nearest.ts +0 -112
- package/src/internal/filesystem/scratch.ts +0 -239
- package/src/internal/filesystem/sdk-schemas.ts +0 -204
- package/src/internal/filesystem/tools.ts +0 -804
- package/src/internal/filesystem/walk.ts +0 -366
- package/src/internal/fixtures/units-server.ts +0 -52
- package/src/internal/framework-file-storage.ts +0 -357
- package/src/internal/framework-storage-selection.ts +0 -156
- package/src/internal/frontmatter.ts +0 -108
- package/src/internal/github-fanout.ts +0 -144
- package/src/internal/guest-network.ts +0 -391
- package/src/internal/handleAgentServeTrigger.ts +0 -286
- package/src/internal/host-files.ts +0 -341
- package/src/internal/host-kv.ts +0 -81
- package/src/internal/host-otel.ts +0 -231
- package/src/internal/host-platforms.ts +0 -170
- package/src/internal/hosted-admission-adapter.ts +0 -47
- package/src/internal/hosted-admission-context.ts +0 -37
- package/src/internal/hosted-catch-protocol.ts +0 -112
- package/src/internal/hosted-catch.ts +0 -179
- package/src/internal/hosted-delivery-protocol.ts +0 -824
- package/src/internal/hosted-delivery.ts +0 -1410
- package/src/internal/hosted-execution-diag.ts +0 -291
- package/src/internal/hosted-execution-flush.ts +0 -136
- package/src/internal/hosted-execution-latency.ts +0 -301
- package/src/internal/hosted-managed-automation.ts +0 -116
- package/src/internal/hosting.ts +0 -114
- package/src/internal/http-channel-define.ts +0 -25
- package/src/internal/http-channel.ts +0 -669
- package/src/internal/http-control-plane-session.ts +0 -110
- package/src/internal/ids.ts +0 -39
- package/src/internal/incoming-headers-to-fetch.ts +0 -45
- package/src/internal/init-interview.ts +0 -360
- package/src/internal/init-project.ts +0 -711
- package/src/internal/init-scaffold.ts +0 -182
- package/src/internal/inline-stdio-define-stub.ts +0 -4
- package/src/internal/inline-stdio-mcp.ts +0 -230
- package/src/internal/install-cursor-skills.ts +0 -604
- package/src/internal/is-record.ts +0 -3
- package/src/internal/json-schema.ts +0 -95
- package/src/internal/legacy-command-guard.ts +0 -66
- package/src/internal/listen-port.ts +0 -85
- package/src/internal/local-control-plane.ts +0 -442
- package/src/internal/local-env.ts +0 -59
- package/src/internal/local-ingress.ts +0 -90
- package/src/internal/log-ring.ts +0 -59
- package/src/internal/logs-client.ts +0 -477
- package/src/internal/map-pool.ts +0 -39
- package/src/internal/mcp-endpoint.ts +0 -747
- package/src/internal/mcp-host.ts +0 -509
- package/src/internal/mcp-oauth-on-demand.ts +0 -337
- package/src/internal/mcp-oauth-persist.ts +0 -118
- package/src/internal/mcp-oauth.ts +0 -549
- package/src/internal/net.ts +0 -29
- package/src/internal/open-browser.ts +0 -41
- package/src/internal/otel/attrs.ts +0 -16
- package/src/internal/otel/collector.ts +0 -937
- package/src/internal/otel/config.ts +0 -287
- package/src/internal/otel/http.ts +0 -122
- package/src/internal/otel/mcp.ts +0 -56
- package/src/internal/otel/propagation.ts +0 -17
- package/src/internal/otel/runtime.ts +0 -441
- package/src/internal/package-inline-stdio.ts +0 -114
- package/src/internal/peer-connections.ts +0 -96
- package/src/internal/platform-schedule-sync.ts +0 -75
- package/src/internal/platform-timers.ts +0 -365
- package/src/internal/playground/static.ts +0 -278
- package/src/internal/playground/toolchain.ts +0 -270
- package/src/internal/playground-proxy.ts +0 -564
- package/src/internal/process-memory-telemetry.ts +0 -334
- package/src/internal/project-layout.ts +0 -31
- package/src/internal/prompt-context.ts +0 -116
- package/src/internal/reminder-control-plane-protocol.ts +0 -482
- package/src/internal/reminder-runner.ts +0 -1559
- package/src/internal/reminder-schedule.ts +0 -104
- package/src/internal/reminder-store.ts +0 -176
- package/src/internal/request-error-status.ts +0 -95
- package/src/internal/request-headers.ts +0 -21
- package/src/internal/resolve-prod-target.ts +0 -334
- package/src/internal/resolved-connections.ts +0 -190
- package/src/internal/router.ts +0 -143
- package/src/internal/run-client.ts +0 -354
- package/src/internal/runtime-dispatch-runner.ts +0 -50
- package/src/internal/sanitize-mcp-tool-name.ts +0 -31
- package/src/internal/schedule-runner.ts +0 -154
- package/src/internal/scm/pr-url.ts +0 -245
- package/src/internal/sdk-runner.ts +0 -959
- package/src/internal/serve-restart.ts +0 -113
- package/src/internal/server.ts +0 -3147
- package/src/internal/session-cost.ts +0 -208
- package/src/internal/session-engine.ts +0 -5622
- package/src/internal/session-links.ts +0 -84
- package/src/internal/session-run-log.ts +0 -535
- package/src/internal/session-store.ts +0 -307
- package/src/internal/session-urls.ts +0 -32
- package/src/internal/sessions-client.ts +0 -239
- package/src/internal/skill-catalog.ts +0 -66
- package/src/internal/skills-sync.ts +0 -55
- package/src/internal/slack-provision-client.ts +0 -544
- package/src/internal/slack-thread-key.ts +0 -11
- package/src/internal/sleep.ts +0 -3
- package/src/internal/start-log-store.ts +0 -164
- package/src/internal/steering.ts +0 -17
- package/src/internal/storage-coordinator.ts +0 -800
- package/src/internal/storage-roles.ts +0 -86
- package/src/internal/storage.ts +0 -1
- package/src/internal/store-api-protocol.ts +0 -205
- package/src/internal/store-mirror.ts +0 -73
- package/src/internal/stream-progress.ts +0 -294
- package/src/internal/terminal-style.ts +0 -133
- package/src/internal/testing/factory-resource-fixtures.ts +0 -84
- package/src/internal/testing/scm-continuation-fixtures.ts +0 -285
- package/src/internal/tool-catalog.ts +0 -104
- package/src/internal/tool-policy.ts +0 -222
- package/src/internal/tool-result.ts +0 -50
- package/src/internal/trajectory.ts +0 -418
- package/src/internal/turn-cost.ts +0 -136
- package/src/internal/turn-governor.ts +0 -145
- package/src/internal/turn-lease-store.ts +0 -144
- package/src/internal/turn-outbox.ts +0 -77
- package/src/internal/update-check.ts +0 -517
- package/src/internal/v2-hosting.ts +0 -52
- package/src/internal/workspace-sync.ts +0 -114
- package/src/internal/workspace.ts +0 -505
- package/src/kv/memory-kv.ts +0 -94
- package/src/kv.ts +0 -18
- package/src/memory.ts +0 -487
- package/src/otel-public.ts +0 -24
- package/src/otel.ts +0 -320
- package/src/prompt.ts +0 -80
- package/src/reminders.ts +0 -65
- package/src/schedules.ts +0 -31
- package/src/skills.ts +0 -27
- package/src/storage-backends/cursor-hosted-v2.ts +0 -204
- package/src/storage-backends/cursor-hosted.ts +0 -388
- package/src/storage-backends/file-kv.ts +0 -276
- package/src/storage-protocol.ts +0 -261
- package/src/storage.ts +0 -408
- package/src/tools.ts +0 -166
- package/src/types.ts +0 -3776
- /package/dist/docs/assets/{guides_jev.md.BNDm14Gy.lean.js → guides_jev.md.D7XH4JH3.lean.js} +0 -0
- /package/dist/docs/assets/{reference_http-api.md.BZOvhCqY.lean.js → reference_http-api.md.DbFNOubV.lean.js} +0 -0
- /package/dist/docs/assets/{reference_project-layout.md.CpLQ9j4K.lean.js → reference_project-layout.md.C2JMRh7p.lean.js} +0 -0
|
@@ -1,1559 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Per-session reminder runner: durable wake subscriptions with
|
|
3
|
-
* prompt XOR named handler XOR run, every/cron/delay/at schedules, and
|
|
4
|
-
* until as function XOR prompt.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { randomBytes } from "node:crypto";
|
|
8
|
-
import type {
|
|
9
|
-
AuthContext,
|
|
10
|
-
ChannelSession,
|
|
11
|
-
DiscoveredReminder,
|
|
12
|
-
HostOtelApi,
|
|
13
|
-
JsonObject,
|
|
14
|
-
JsonValue,
|
|
15
|
-
ReminderCreateInput,
|
|
16
|
-
ReminderDefinition,
|
|
17
|
-
ReminderFireContext,
|
|
18
|
-
ReminderFireResult,
|
|
19
|
-
ReminderFollowupOptions,
|
|
20
|
-
ReminderInfo,
|
|
21
|
-
ReminderStatus,
|
|
22
|
-
ReminderUntilContext,
|
|
23
|
-
TurnOutcome,
|
|
24
|
-
} from "../types.js";
|
|
25
|
-
import { channelContinuationIdentity, httpContinuationIdentity } from "./continuation-channel.js";
|
|
26
|
-
import { continuationSource } from "./continuation-identity.js";
|
|
27
|
-
import { NAME_PATTERN } from "./discovery/names.js";
|
|
28
|
-
import { parseDuration } from "./duration.js";
|
|
29
|
-
import type { PlatformTimers } from "./platform-timers.js";
|
|
30
|
-
import {
|
|
31
|
-
REMINDER_CP_PROTOCOL_VERSION,
|
|
32
|
-
type ReminderControlPlane,
|
|
33
|
-
type ReminderCreateIntent,
|
|
34
|
-
type ReminderExecutionOutcome,
|
|
35
|
-
type ReminderFireDescriptor,
|
|
36
|
-
scheduleSpecFromCreateInput,
|
|
37
|
-
toWireReschedule,
|
|
38
|
-
} from "./reminder-control-plane-protocol.js";
|
|
39
|
-
import {
|
|
40
|
-
defaultBusyPolicy,
|
|
41
|
-
MAX_TIMER_MS,
|
|
42
|
-
nextCronFireMs,
|
|
43
|
-
ReminderValidationError,
|
|
44
|
-
resolveSchedule,
|
|
45
|
-
} from "./reminder-schedule.js";
|
|
46
|
-
import type { ReminderBusyPolicy, ReminderRecord } from "./reminder-store.js";
|
|
47
|
-
import { APP_AUTH } from "./schedule-runner.js";
|
|
48
|
-
import {
|
|
49
|
-
type EngineSendOptions,
|
|
50
|
-
HTTP_CHANNEL_ID,
|
|
51
|
-
SessionAuthError,
|
|
52
|
-
SessionBusyError,
|
|
53
|
-
type SessionEngine,
|
|
54
|
-
} from "./session-engine.js";
|
|
55
|
-
|
|
56
|
-
export { ReminderValidationError } from "./reminder-schedule.js";
|
|
57
|
-
|
|
58
|
-
/** Max UTF-8 byte length of `JSON.stringify(args)` on named-handler create. */
|
|
59
|
-
export const REMINDER_ARGS_MAX_BYTES: number = 32 * 1024;
|
|
60
|
-
|
|
61
|
-
export class UnknownReminderError extends Error {
|
|
62
|
-
constructor(
|
|
63
|
-
reminderId: string,
|
|
64
|
-
readonly availableReminderIds: string[],
|
|
65
|
-
) {
|
|
66
|
-
super(`Unknown reminder "${reminderId}"`);
|
|
67
|
-
this.name = "UnknownReminderError";
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
interface LiveHandlers {
|
|
72
|
-
run?: (ctx: ReminderFireContext) => Promise<ReminderFireResult>;
|
|
73
|
-
untilFn?: (ctx: ReminderUntilContext) => Promise<boolean>;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export interface ReminderRunnerOptions {
|
|
77
|
-
/** Discovered `agent/reminders/*` handlers, keyed by module stem. */
|
|
78
|
-
namedHandlers?: readonly DiscoveredReminder[];
|
|
79
|
-
/**
|
|
80
|
-
* Architecture v2: reject anonymous `run` and function `until` at create
|
|
81
|
-
* (named `handler` + prompt remain), whether local or hosted.
|
|
82
|
-
*/
|
|
83
|
-
rejectAnonymousHandlers?: boolean;
|
|
84
|
-
/**
|
|
85
|
-
* When set (local self-hosted architecture v2), create/cancel/rekey go
|
|
86
|
-
* through the control-plane protocol and fires are guest executions of
|
|
87
|
-
* immutable descriptors.
|
|
88
|
-
*/
|
|
89
|
-
controlPlane?: ReminderControlPlane;
|
|
90
|
-
/** Agent architecture; used with {@link controlPlane} for v2 protocol path. */
|
|
91
|
-
architecture?: "v1" | "v2";
|
|
92
|
-
/**
|
|
93
|
-
* Hosted v2 guest (`--no-control-plane`, architecture v2). A pod starts
|
|
94
|
-
* for one delivery and stops when it settles, so a fire usually lands on
|
|
95
|
-
* a pod that holds no session for the reminder's continuation, and the
|
|
96
|
-
* pod may stop as soon as the fire's outcome is applied. The runner then
|
|
97
|
-
* opens a session on the stored continuation key and waits for the turn.
|
|
98
|
-
*/
|
|
99
|
-
hostedGuest?: ReminderHostedGuestOptions;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export interface ReminderHostedGuestOptions {
|
|
103
|
-
/**
|
|
104
|
-
* Principal for the session a prompt fire opens when the pod holds none.
|
|
105
|
-
* Hosted admissions open sessions with the same value, so a session the
|
|
106
|
-
* engine restores from durable storage keeps its principal. Return
|
|
107
|
-
* `undefined` when no principal applies; the fire then skips with a
|
|
108
|
-
* reschedule so the control plane keeps the reminder armed.
|
|
109
|
-
*/
|
|
110
|
-
fireAuth: () => AuthContext | null | undefined;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Reschedule applied when a hosted fire cannot open a session (no
|
|
115
|
-
* principal). A one-shot `skipped` outcome without a reschedule completes
|
|
116
|
-
* the reminder, which would lose the check-in for good.
|
|
117
|
-
*/
|
|
118
|
-
export const REMINDER_SESSION_OPEN_RETRY_DELAY = "5m";
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* `reason` tag on `agent_sdk.reminder.fire_outcome`. Prompt fires report
|
|
122
|
-
* how the session was reached: `session_joined` (held by this pod),
|
|
123
|
-
* `session_restored` (read back from durable storage), `session_opened`
|
|
124
|
-
* (fresh session on the stored key), `session_gone` (no session and none
|
|
125
|
-
* could be opened). `fire_threw` pairs with kind `error`: the fire raised
|
|
126
|
-
* and the hosted admission retries it.
|
|
127
|
-
*/
|
|
128
|
-
export type ReminderFireOutcomeReason =
|
|
129
|
-
| "session_gone"
|
|
130
|
-
| "session_opened"
|
|
131
|
-
| "session_restored"
|
|
132
|
-
| "session_joined"
|
|
133
|
-
| "handler_missing"
|
|
134
|
-
| "handler_lost_on_restart"
|
|
135
|
-
| "missing_handler"
|
|
136
|
-
| "run_stop"
|
|
137
|
-
| "run_skip"
|
|
138
|
-
| "run_delivered"
|
|
139
|
-
| "until_fn"
|
|
140
|
-
| "busy"
|
|
141
|
-
| "followup_failed"
|
|
142
|
-
| "fire_threw";
|
|
143
|
-
|
|
144
|
-
export const REMINDER_FIRE_OUTCOME_METRIC = "agent_sdk.reminder.fire_outcome";
|
|
145
|
-
|
|
146
|
-
/** What one `executeFire` reports: the CP outcome plus the telemetry tags. */
|
|
147
|
-
interface FireExecution {
|
|
148
|
-
outcome: ReminderExecutionOutcome;
|
|
149
|
-
reason: ReminderFireOutcomeReason;
|
|
150
|
-
/** Set when the hosted guest awaited the turn before reporting. */
|
|
151
|
-
turnStatus?: TurnOutcome["status"];
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
interface PromptDelivery {
|
|
155
|
-
result: ReminderFireResult;
|
|
156
|
-
reason: ReminderFireOutcomeReason;
|
|
157
|
-
turnStatus?: TurnOutcome["status"];
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/** Out-params `sendFollowup` fills in for the fire's telemetry. */
|
|
161
|
-
interface FollowupSettle {
|
|
162
|
-
turnStatus?: TurnOutcome["status"];
|
|
163
|
-
skipReason?: Extract<ReminderFireOutcomeReason, "busy" | "followup_failed">;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/** How a prompt fire reached (or failed to reach) its session. */
|
|
167
|
-
type FollowupTarget =
|
|
168
|
-
| {
|
|
169
|
-
auth: AuthContext | null;
|
|
170
|
-
reached: Extract<ReminderFireOutcomeReason, "session_joined" | "session_restored">;
|
|
171
|
-
}
|
|
172
|
-
| {
|
|
173
|
-
auth: undefined;
|
|
174
|
-
/**
|
|
175
|
-
* `session_gone`: no session anywhere. `session_unreadable`: the durable
|
|
176
|
-
* index has one but the local re-read missed; never open a fresh
|
|
177
|
-
* session over it.
|
|
178
|
-
*/
|
|
179
|
-
reached: "session_gone" | "session_unreadable";
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
/** Guest-side read surface shared by v1 timed-work and the v2 CP client. */
|
|
183
|
-
interface ReminderReader {
|
|
184
|
-
getReminder(id: string): Promise<ReminderRecord | undefined>;
|
|
185
|
-
listReminders(): Promise<ReminderRecord[]>;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* Server wiring for {@link ReminderRunnerOptions.rejectAnonymousHandlers}:
|
|
190
|
-
* architecture v2 always rejects anonymous run/until (local or hosted).
|
|
191
|
-
*/
|
|
192
|
-
export function rejectAnonymousReminderHandlers(options: {
|
|
193
|
-
noControlPlane?: boolean;
|
|
194
|
-
architecture?: string;
|
|
195
|
-
}): boolean {
|
|
196
|
-
return options.architecture === "v2";
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
function newReminderId(): string {
|
|
200
|
-
return `rem_${randomBytes(8).toString("hex")}`;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
function isJsonObject(value: unknown): value is JsonObject {
|
|
204
|
-
return (
|
|
205
|
-
typeof value === "object" &&
|
|
206
|
-
value !== null &&
|
|
207
|
-
!Array.isArray(value) &&
|
|
208
|
-
Object.values(value as Record<string, unknown>).every(isJsonValue)
|
|
209
|
-
);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
function isJsonValue(value: unknown): value is JsonValue {
|
|
213
|
-
if (value === null || typeof value === "string" || typeof value === "boolean") {
|
|
214
|
-
return true;
|
|
215
|
-
}
|
|
216
|
-
if (typeof value === "number") {
|
|
217
|
-
return Number.isFinite(value);
|
|
218
|
-
}
|
|
219
|
-
if (Array.isArray(value)) {
|
|
220
|
-
return value.every(isJsonValue);
|
|
221
|
-
}
|
|
222
|
-
return isJsonObject(value);
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
/** Same stem rules as `agent/reminders/<name>.ts` discovery. */
|
|
226
|
-
function isValidReminderHandlerName(name: string): boolean {
|
|
227
|
-
return NAME_PATTERN.test(name) && !name.includes("__");
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
function assertReminderArgsSize(args: JsonObject): void {
|
|
231
|
-
const bytes = Buffer.byteLength(JSON.stringify(args), "utf8");
|
|
232
|
-
if (bytes > REMINDER_ARGS_MAX_BYTES) {
|
|
233
|
-
throw new ReminderValidationError(
|
|
234
|
-
`reminders.create args exceed ${REMINDER_ARGS_MAX_BYTES} bytes (got ${bytes})`,
|
|
235
|
-
);
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
function toInfo(record: ReminderRecord): ReminderInfo {
|
|
240
|
-
return {
|
|
241
|
-
id: record.id,
|
|
242
|
-
purpose: record.purpose,
|
|
243
|
-
channelId: record.channelId,
|
|
244
|
-
continuationToken: record.continuationToken,
|
|
245
|
-
target: record.target,
|
|
246
|
-
scheduleKind: record.scheduleKind,
|
|
247
|
-
scheduleValue: record.scheduleValue,
|
|
248
|
-
prompt: record.prompt,
|
|
249
|
-
handler: record.handler,
|
|
250
|
-
args: record.args,
|
|
251
|
-
untilPrompt: record.untilPrompt,
|
|
252
|
-
busyPolicy: record.busyPolicy,
|
|
253
|
-
status: record.status === "firing" ? "armed" : record.status,
|
|
254
|
-
disarmReason: record.disarmReason,
|
|
255
|
-
fireCount: record.fireCount,
|
|
256
|
-
nextFireAt: new Date(record.nextFireAtMs).toISOString(),
|
|
257
|
-
createdAt: record.createdAt,
|
|
258
|
-
updatedAt: record.updatedAt,
|
|
259
|
-
hasRunHandler: record.hasRunHandler === true,
|
|
260
|
-
hasUntilFn: record.hasUntilFn === true,
|
|
261
|
-
};
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
function stopFire(
|
|
265
|
-
reason: Extract<
|
|
266
|
-
ReminderFireOutcomeReason,
|
|
267
|
-
"handler_missing" | "handler_lost_on_restart" | "missing_handler" | "until_fn"
|
|
268
|
-
>,
|
|
269
|
-
): FireExecution {
|
|
270
|
-
return { outcome: { kind: "stop", reason }, reason };
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
function runReason(result: ReminderFireResult): ReminderFireOutcomeReason {
|
|
274
|
-
switch (result.action) {
|
|
275
|
-
case "stop":
|
|
276
|
-
return "run_stop";
|
|
277
|
-
case "skip":
|
|
278
|
-
return "run_skip";
|
|
279
|
-
case "delivered":
|
|
280
|
-
return "run_delivered";
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
function buildFirePrompt(record: ReminderRecord): string {
|
|
285
|
-
const recurring = record.scheduleKind === "every" || record.scheduleKind === "cron";
|
|
286
|
-
const lines = [
|
|
287
|
-
`[reminder] id=${record.id} purpose=${record.purpose}`,
|
|
288
|
-
record.prompt ?? "Reminder fired. Check current state and only act if needed.",
|
|
289
|
-
];
|
|
290
|
-
if (record.untilPrompt !== undefined && record.untilPrompt.trim() !== "") {
|
|
291
|
-
lines.push("", `Stop condition: ${record.untilPrompt}`);
|
|
292
|
-
if (recurring) {
|
|
293
|
-
lines.push(`When the stop condition is met, call reminders_cancel with id=${record.id}.`);
|
|
294
|
-
} else {
|
|
295
|
-
lines.push(
|
|
296
|
-
"This is a one-shot reminder (auto-completes after this fire); no cancel needed unless you armed a separate recurring reminder.",
|
|
297
|
-
);
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
return lines.join("\n");
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
export class ReminderRunner {
|
|
304
|
-
private readonly records = new Map<string, ReminderRecord>();
|
|
305
|
-
private readonly handlers = new Map<string, LiveHandlers>();
|
|
306
|
-
private readonly namedHandlers = new Map<string, ReminderDefinition>();
|
|
307
|
-
private readonly namedHandlerNames = new Map<ReminderDefinition, string>();
|
|
308
|
-
private readonly timers = new Map<string, NodeJS.Timeout>();
|
|
309
|
-
private readonly firing = new Set<string>();
|
|
310
|
-
/** Single-flight idle gates keyed by `channelId:continuationToken`. */
|
|
311
|
-
private readonly idleGates = new Map<string, Promise<void>>();
|
|
312
|
-
private started = false;
|
|
313
|
-
private readonly rejectAnonymousHandlers: boolean;
|
|
314
|
-
private readonly controlPlane: ReminderControlPlane | undefined;
|
|
315
|
-
private readonly architecture: "v1" | "v2" | undefined;
|
|
316
|
-
private readonly hostedGuest: ReminderHostedGuestOptions | undefined;
|
|
317
|
-
/**
|
|
318
|
-
* A control-plane read failure is logged once per outage, not per call.
|
|
319
|
-
* The next successful read re-arms the log.
|
|
320
|
-
*/
|
|
321
|
-
private controlPlaneReadFailureLogged = false;
|
|
322
|
-
|
|
323
|
-
constructor(
|
|
324
|
-
private readonly engine: SessionEngine,
|
|
325
|
-
private readonly logger: (line: string) => void = () => {},
|
|
326
|
-
private readonly platformTimers?: PlatformTimers,
|
|
327
|
-
options: ReminderRunnerOptions = {},
|
|
328
|
-
) {
|
|
329
|
-
this.rejectAnonymousHandlers = options.rejectAnonymousHandlers === true;
|
|
330
|
-
this.controlPlane = options.controlPlane;
|
|
331
|
-
this.architecture = options.architecture;
|
|
332
|
-
this.hostedGuest = options.hostedGuest;
|
|
333
|
-
for (const reminder of options.namedHandlers ?? []) {
|
|
334
|
-
this.namedHandlers.set(reminder.name, reminder.definition);
|
|
335
|
-
this.namedHandlerNames.set(reminder.definition, reminder.name);
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
/** True when create/cancel/rekey/fire go through the CP protocol. */
|
|
340
|
-
private get usesControlPlaneProtocol(): boolean {
|
|
341
|
-
return this.controlPlane !== undefined && this.architecture === "v2";
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
/**
|
|
345
|
-
* Where reminder documents are read from. Under the CP protocol that is
|
|
346
|
-
* the v2 control-plane client; the v1 timed-work route answers 405 for a
|
|
347
|
-
* v2 deployment, which used to leave `list()` with only this process's
|
|
348
|
-
* in-memory map (breaking arm idempotence and `cancelForContinuation`).
|
|
349
|
-
*/
|
|
350
|
-
private get reminderReader(): ReminderReader | undefined {
|
|
351
|
-
if (this.usesControlPlaneProtocol) {
|
|
352
|
-
return this.controlPlane;
|
|
353
|
-
}
|
|
354
|
-
return this.platformTimers;
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
private logControlPlaneReadFailure(what: string, error: unknown): void {
|
|
358
|
-
if (this.usesControlPlaneProtocol && this.controlPlaneReadFailureLogged) {
|
|
359
|
-
return;
|
|
360
|
-
}
|
|
361
|
-
this.controlPlaneReadFailureLogged = true;
|
|
362
|
-
this.logger(
|
|
363
|
-
`[agent-sdk] reminders: control-plane ${what} failed: ${
|
|
364
|
-
error instanceof Error ? error.message : String(error)
|
|
365
|
-
}`,
|
|
366
|
-
);
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
/**
|
|
370
|
-
* Load reminder documents from the control plane into memory. Does not
|
|
371
|
-
* arm in-process timers — the CP owns clocks.
|
|
372
|
-
*/
|
|
373
|
-
async hydrate(): Promise<void> {
|
|
374
|
-
const reader = this.reminderReader;
|
|
375
|
-
if (reader === undefined) {
|
|
376
|
-
return;
|
|
377
|
-
}
|
|
378
|
-
let remote: ReminderRecord[] = [];
|
|
379
|
-
try {
|
|
380
|
-
remote = await reader.listReminders();
|
|
381
|
-
} catch (error) {
|
|
382
|
-
this.logControlPlaneReadFailure("list", error);
|
|
383
|
-
return;
|
|
384
|
-
}
|
|
385
|
-
this.controlPlaneReadFailureLogged = false;
|
|
386
|
-
this.records.clear();
|
|
387
|
-
for (const record of remote) {
|
|
388
|
-
this.records.set(record.id, record);
|
|
389
|
-
}
|
|
390
|
-
if (this.usesControlPlaneProtocol) {
|
|
391
|
-
// The CP owns status; a fire whose handler is missing reports `stop`
|
|
392
|
-
// from executeFire instead of the guest writing a disarm.
|
|
393
|
-
if (remote.length > 0) {
|
|
394
|
-
this.logger(
|
|
395
|
-
`[agent-sdk] reminders: hydrated ${remote.length} reminder(s) from control plane`,
|
|
396
|
-
);
|
|
397
|
-
}
|
|
398
|
-
return;
|
|
399
|
-
}
|
|
400
|
-
let disarmedOrphan = 0;
|
|
401
|
-
for (const record of [...this.records.values()]) {
|
|
402
|
-
if (record.status !== "armed") {
|
|
403
|
-
continue;
|
|
404
|
-
}
|
|
405
|
-
if (record.handler !== undefined) {
|
|
406
|
-
if (this.namedHandlers.get(record.handler) === undefined) {
|
|
407
|
-
await this.disarm(record, "handler_missing");
|
|
408
|
-
disarmedOrphan += 1;
|
|
409
|
-
}
|
|
410
|
-
continue;
|
|
411
|
-
}
|
|
412
|
-
if (
|
|
413
|
-
(record.hasRunHandler === true || record.hasUntilFn === true) &&
|
|
414
|
-
this.handlers.get(record.id) === undefined
|
|
415
|
-
) {
|
|
416
|
-
await this.disarm(record, "handler_lost_on_restart");
|
|
417
|
-
disarmedOrphan += 1;
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
if (remote.length > 0 || disarmedOrphan > 0) {
|
|
421
|
-
this.logger(
|
|
422
|
-
`[agent-sdk] reminders: hydrated ${remote.length} reminder(s) from control plane` +
|
|
423
|
-
(disarmedOrphan > 0 ? `; disarmed ${disarmedOrphan} without live handlers` : ""),
|
|
424
|
-
);
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
/** Start deadline timers for armed reminders (tests / no control plane). */
|
|
429
|
-
async start(): Promise<void> {
|
|
430
|
-
if (this.started) return;
|
|
431
|
-
this.started = true;
|
|
432
|
-
await this.hydrate();
|
|
433
|
-
if (this.platformTimers !== undefined) {
|
|
434
|
-
return;
|
|
435
|
-
}
|
|
436
|
-
const armed = [...this.records.values()].filter(r => r.status === "armed");
|
|
437
|
-
let restored = 0;
|
|
438
|
-
let disarmedOrphan = 0;
|
|
439
|
-
for (const record of armed) {
|
|
440
|
-
if (record.handler !== undefined) {
|
|
441
|
-
if (this.namedHandlers.get(record.handler) === undefined) {
|
|
442
|
-
await this.disarm(record, "handler_missing");
|
|
443
|
-
disarmedOrphan += 1;
|
|
444
|
-
continue;
|
|
445
|
-
}
|
|
446
|
-
this.armTimer(record);
|
|
447
|
-
restored += 1;
|
|
448
|
-
continue;
|
|
449
|
-
}
|
|
450
|
-
if (
|
|
451
|
-
(record.hasRunHandler === true || record.hasUntilFn === true) &&
|
|
452
|
-
this.handlers.get(record.id) === undefined
|
|
453
|
-
) {
|
|
454
|
-
await this.disarm(record, "handler_lost_on_restart");
|
|
455
|
-
disarmedOrphan += 1;
|
|
456
|
-
continue;
|
|
457
|
-
}
|
|
458
|
-
this.armTimer(record);
|
|
459
|
-
restored += 1;
|
|
460
|
-
}
|
|
461
|
-
if (restored > 0 || disarmedOrphan > 0) {
|
|
462
|
-
this.logger(
|
|
463
|
-
`[agent-sdk] reminders: restored ${restored} armed reminder(s)` +
|
|
464
|
-
(disarmedOrphan > 0 ? `; disarmed ${disarmedOrphan} without live handlers` : ""),
|
|
465
|
-
);
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
private async persist(record: ReminderRecord): Promise<void> {
|
|
470
|
-
if (this.platformTimers !== undefined) {
|
|
471
|
-
await this.platformTimers.putReminder(record);
|
|
472
|
-
}
|
|
473
|
-
this.records.set(record.id, record);
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
private async getRecord(id: string): Promise<ReminderRecord | undefined> {
|
|
477
|
-
const reader = this.reminderReader;
|
|
478
|
-
if (reader !== undefined) {
|
|
479
|
-
try {
|
|
480
|
-
const remote = await reader.getReminder(id);
|
|
481
|
-
this.controlPlaneReadFailureLogged = false;
|
|
482
|
-
if (remote === undefined) {
|
|
483
|
-
this.records.delete(id);
|
|
484
|
-
return undefined;
|
|
485
|
-
}
|
|
486
|
-
this.records.set(id, remote);
|
|
487
|
-
return remote;
|
|
488
|
-
} catch (error) {
|
|
489
|
-
this.logControlPlaneReadFailure(`get for ${id}`, error);
|
|
490
|
-
return this.records.get(id);
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
return this.records.get(id);
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
/**
|
|
497
|
-
* Under the CP protocol a list failure propagates: the in-memory map is
|
|
498
|
-
* only what this process created, and returning it would let a caller
|
|
499
|
-
* arm duplicates or miss rows to cancel. v1 keeps the best-effort form.
|
|
500
|
-
*/
|
|
501
|
-
private async allRecords(): Promise<ReminderRecord[]> {
|
|
502
|
-
const reader = this.reminderReader;
|
|
503
|
-
if (reader !== undefined) {
|
|
504
|
-
try {
|
|
505
|
-
const remote = await reader.listReminders();
|
|
506
|
-
this.controlPlaneReadFailureLogged = false;
|
|
507
|
-
this.records.clear();
|
|
508
|
-
for (const record of remote) {
|
|
509
|
-
this.records.set(record.id, record);
|
|
510
|
-
}
|
|
511
|
-
} catch (error) {
|
|
512
|
-
this.logControlPlaneReadFailure("list", error);
|
|
513
|
-
if (this.usesControlPlaneProtocol) {
|
|
514
|
-
throw error;
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
return [...this.records.values()];
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
stop(): void {
|
|
522
|
-
this.started = false;
|
|
523
|
-
for (const timer of this.timers.values()) {
|
|
524
|
-
clearTimeout(timer);
|
|
525
|
-
}
|
|
526
|
-
this.timers.clear();
|
|
527
|
-
this.idleGates.clear();
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
async create(input: ReminderCreateInput): Promise<ReminderInfo> {
|
|
531
|
-
const hasPrompt = input.prompt !== undefined;
|
|
532
|
-
const hasRun = input.run !== undefined;
|
|
533
|
-
const hasHandler = input.handler !== undefined;
|
|
534
|
-
const formCount = [hasPrompt, hasRun, hasHandler].filter(Boolean).length;
|
|
535
|
-
if (formCount !== 1) {
|
|
536
|
-
throw new ReminderValidationError(
|
|
537
|
-
"reminders.create requires exactly one of prompt, handler, or run",
|
|
538
|
-
);
|
|
539
|
-
}
|
|
540
|
-
if (input.continuationToken.trim() === "") {
|
|
541
|
-
throw new ReminderValidationError("continuationToken is required");
|
|
542
|
-
}
|
|
543
|
-
if (input.channelId.trim() === "") {
|
|
544
|
-
throw new ReminderValidationError("channelId is required");
|
|
545
|
-
}
|
|
546
|
-
if (input.purpose.trim() === "") {
|
|
547
|
-
throw new ReminderValidationError("purpose is required");
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
const untilPrompt = typeof input.until === "string" ? input.until : undefined;
|
|
551
|
-
const untilFn = typeof input.until === "function" ? input.until : undefined;
|
|
552
|
-
|
|
553
|
-
if (hasHandler && input.until !== undefined) {
|
|
554
|
-
throw new ReminderValidationError(
|
|
555
|
-
"reminders.create: until is not valid with handler; encode the stop condition in args and the handler body",
|
|
556
|
-
);
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
if (this.rejectAnonymousHandlers) {
|
|
560
|
-
if (hasRun) {
|
|
561
|
-
throw new ReminderValidationError(
|
|
562
|
-
"reminders.create: anonymous run handlers are not durable on architecture v2; author reminders/<name>.ts under the project root and pass handler + args",
|
|
563
|
-
);
|
|
564
|
-
}
|
|
565
|
-
if (untilFn !== undefined) {
|
|
566
|
-
throw new ReminderValidationError(
|
|
567
|
-
"reminders.create: function until is not durable on architecture v2; use a string until prompt",
|
|
568
|
-
);
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
let handlerName: string | undefined;
|
|
573
|
-
let handlerArgs: JsonObject | undefined;
|
|
574
|
-
if (hasHandler) {
|
|
575
|
-
const handler = input.handler!;
|
|
576
|
-
const name =
|
|
577
|
-
typeof handler === "string" ? handler.trim() : this.namedHandlerNames.get(handler);
|
|
578
|
-
if (name === undefined) {
|
|
579
|
-
throw new ReminderValidationError(
|
|
580
|
-
"Unknown reminder handler definition (expected a default export discovered under reminders/)",
|
|
581
|
-
);
|
|
582
|
-
}
|
|
583
|
-
if (name === "") {
|
|
584
|
-
throw new ReminderValidationError("handler name is required");
|
|
585
|
-
}
|
|
586
|
-
if (!isValidReminderHandlerName(name)) {
|
|
587
|
-
throw new ReminderValidationError(
|
|
588
|
-
name.includes("__")
|
|
589
|
-
? `Invalid reminder handler name "${name}": may not contain "__"`
|
|
590
|
-
: `Invalid reminder handler name "${name}": must match ${NAME_PATTERN}`,
|
|
591
|
-
);
|
|
592
|
-
}
|
|
593
|
-
if (this.namedHandlers.get(name) === undefined) {
|
|
594
|
-
throw new ReminderValidationError(
|
|
595
|
-
`Unknown reminder handler "${name}" (expected reminders/${name}.ts under the project root)`,
|
|
596
|
-
);
|
|
597
|
-
}
|
|
598
|
-
if (input.args !== undefined && !isJsonObject(input.args)) {
|
|
599
|
-
throw new ReminderValidationError("reminders.create args must be a JSON object");
|
|
600
|
-
}
|
|
601
|
-
handlerName = name;
|
|
602
|
-
handlerArgs = input.args ?? {};
|
|
603
|
-
assertReminderArgsSize(handlerArgs);
|
|
604
|
-
} else if (input.args !== undefined) {
|
|
605
|
-
throw new ReminderValidationError("reminders.create args is only valid with handler");
|
|
606
|
-
}
|
|
607
|
-
|
|
608
|
-
const schedule = resolveSchedule(input);
|
|
609
|
-
const busyPolicy: ReminderBusyPolicy = input.busyPolicy ?? defaultBusyPolicy(schedule.kind);
|
|
610
|
-
const hasRunHandler = input.run !== undefined;
|
|
611
|
-
const hasUntilFn = untilFn !== undefined;
|
|
612
|
-
|
|
613
|
-
let record: ReminderRecord;
|
|
614
|
-
if (this.usesControlPlaneProtocol) {
|
|
615
|
-
const intent: ReminderCreateIntent = {
|
|
616
|
-
protocolVersion: REMINDER_CP_PROTOCOL_VERSION,
|
|
617
|
-
purpose: input.purpose,
|
|
618
|
-
channelId: input.channelId,
|
|
619
|
-
continuationToken: input.continuationToken,
|
|
620
|
-
target: input.target,
|
|
621
|
-
// CP recalculates nextFireAtMs / intervalMs from the raw schedule.
|
|
622
|
-
schedule: scheduleSpecFromCreateInput(input),
|
|
623
|
-
prompt: input.prompt,
|
|
624
|
-
handler: handlerName,
|
|
625
|
-
args: handlerArgs,
|
|
626
|
-
hasRunHandler,
|
|
627
|
-
hasUntilFn,
|
|
628
|
-
untilPrompt,
|
|
629
|
-
busyPolicy,
|
|
630
|
-
};
|
|
631
|
-
record = await this.controlPlane!.createReminder(intent);
|
|
632
|
-
this.records.set(record.id, record);
|
|
633
|
-
} else {
|
|
634
|
-
const now = new Date().toISOString();
|
|
635
|
-
const id = newReminderId();
|
|
636
|
-
record = {
|
|
637
|
-
version: 1,
|
|
638
|
-
id,
|
|
639
|
-
purpose: input.purpose,
|
|
640
|
-
channelId: input.channelId,
|
|
641
|
-
continuationToken: input.continuationToken,
|
|
642
|
-
target: input.target,
|
|
643
|
-
scheduleKind: schedule.kind,
|
|
644
|
-
scheduleValue: schedule.value,
|
|
645
|
-
intervalMs: schedule.intervalMs,
|
|
646
|
-
prompt: input.prompt,
|
|
647
|
-
handler: handlerName,
|
|
648
|
-
args: handlerArgs,
|
|
649
|
-
hasRunHandler,
|
|
650
|
-
hasUntilFn,
|
|
651
|
-
untilPrompt,
|
|
652
|
-
busyPolicy,
|
|
653
|
-
status: "armed",
|
|
654
|
-
fireCount: 0,
|
|
655
|
-
nextFireAtMs: schedule.nextFireAtMs,
|
|
656
|
-
generation: 0,
|
|
657
|
-
createdAt: now,
|
|
658
|
-
updatedAt: now,
|
|
659
|
-
};
|
|
660
|
-
await this.persist(record);
|
|
661
|
-
}
|
|
662
|
-
|
|
663
|
-
this.handlers.set(record.id, {
|
|
664
|
-
run: input.run,
|
|
665
|
-
untilFn,
|
|
666
|
-
});
|
|
667
|
-
if (this.started && this.platformTimers === undefined && !this.usesControlPlaneProtocol) {
|
|
668
|
-
this.armTimer(record);
|
|
669
|
-
}
|
|
670
|
-
|
|
671
|
-
return toInfo(record);
|
|
672
|
-
}
|
|
673
|
-
|
|
674
|
-
async list(filter?: {
|
|
675
|
-
status?: ReminderStatus;
|
|
676
|
-
purpose?: string;
|
|
677
|
-
continuationToken?: string;
|
|
678
|
-
}): Promise<ReminderInfo[]> {
|
|
679
|
-
const all = await this.allRecords();
|
|
680
|
-
return all
|
|
681
|
-
.filter(r => {
|
|
682
|
-
if (filter?.status !== undefined) {
|
|
683
|
-
const publicStatus = r.status === "firing" ? "armed" : r.status;
|
|
684
|
-
if (publicStatus !== filter.status) {
|
|
685
|
-
return false;
|
|
686
|
-
}
|
|
687
|
-
}
|
|
688
|
-
if (filter?.purpose !== undefined && r.purpose !== filter.purpose) {
|
|
689
|
-
return false;
|
|
690
|
-
}
|
|
691
|
-
if (
|
|
692
|
-
filter?.continuationToken !== undefined &&
|
|
693
|
-
r.continuationToken !== filter.continuationToken
|
|
694
|
-
) {
|
|
695
|
-
return false;
|
|
696
|
-
}
|
|
697
|
-
return true;
|
|
698
|
-
})
|
|
699
|
-
.map(r => {
|
|
700
|
-
const live = this.handlers.get(r.id);
|
|
701
|
-
const info = toInfo(r);
|
|
702
|
-
if (live === undefined) return info;
|
|
703
|
-
return {
|
|
704
|
-
...info,
|
|
705
|
-
hasRunHandler: live.run !== undefined || info.hasRunHandler,
|
|
706
|
-
hasUntilFn: live.untilFn !== undefined || info.hasUntilFn,
|
|
707
|
-
};
|
|
708
|
-
});
|
|
709
|
-
}
|
|
710
|
-
|
|
711
|
-
async cancel(id: string, reason = "explicit_cancel"): Promise<ReminderInfo | undefined> {
|
|
712
|
-
if (this.usesControlPlaneProtocol) {
|
|
713
|
-
const updated = await this.controlPlane!.cancelReminder(id, reason);
|
|
714
|
-
if (updated === undefined) {
|
|
715
|
-
this.records.delete(id);
|
|
716
|
-
this.handlers.delete(id);
|
|
717
|
-
return undefined;
|
|
718
|
-
}
|
|
719
|
-
this.records.set(id, updated);
|
|
720
|
-
this.handlers.delete(id);
|
|
721
|
-
return toInfo(updated);
|
|
722
|
-
}
|
|
723
|
-
const record = await this.getRecord(id);
|
|
724
|
-
if (record === undefined) {
|
|
725
|
-
return undefined;
|
|
726
|
-
}
|
|
727
|
-
if (record.status !== "armed" && record.status !== "firing") {
|
|
728
|
-
return toInfo(record);
|
|
729
|
-
}
|
|
730
|
-
this.clearTimer(id);
|
|
731
|
-
const updated: ReminderRecord = {
|
|
732
|
-
...record,
|
|
733
|
-
status: "cancelled",
|
|
734
|
-
disarmReason: reason,
|
|
735
|
-
generation: (record.generation ?? 0) + 1,
|
|
736
|
-
updatedAt: new Date().toISOString(),
|
|
737
|
-
};
|
|
738
|
-
await this.persist(updated);
|
|
739
|
-
this.handlers.delete(id);
|
|
740
|
-
return toInfo(updated);
|
|
741
|
-
}
|
|
742
|
-
|
|
743
|
-
/** Cancel all armed reminders matching a continuation token (e.g. PR closed). */
|
|
744
|
-
async cancelForContinuation(continuationToken: string, reason: string): Promise<number> {
|
|
745
|
-
const armed = (await this.allRecords()).filter(r => r.status === "armed");
|
|
746
|
-
let n = 0;
|
|
747
|
-
for (const record of armed) {
|
|
748
|
-
if (record.continuationToken === continuationToken) {
|
|
749
|
-
await this.cancel(record.id, reason);
|
|
750
|
-
n += 1;
|
|
751
|
-
}
|
|
752
|
-
}
|
|
753
|
-
return n;
|
|
754
|
-
}
|
|
755
|
-
|
|
756
|
-
/**
|
|
757
|
-
* Re-key armed reminders when a channel rotates a session's continuation
|
|
758
|
-
* token (the built-in HTTP channel rotates after every follow-up). Without
|
|
759
|
-
* this, a reminder armed before the rotation misses its session at fire
|
|
760
|
-
* time and disarms as `session_gone`.
|
|
761
|
-
*/
|
|
762
|
-
async rekeyContinuation(channelId: string, oldToken: string, newToken: string): Promise<number> {
|
|
763
|
-
if (this.usesControlPlaneProtocol) {
|
|
764
|
-
return this.controlPlane!.rekeyReminders(channelId, oldToken, newToken);
|
|
765
|
-
}
|
|
766
|
-
const armed = (await this.allRecords()).filter(
|
|
767
|
-
r => r.status === "armed" || r.status === "firing",
|
|
768
|
-
);
|
|
769
|
-
let n = 0;
|
|
770
|
-
for (const record of armed) {
|
|
771
|
-
if (record.channelId !== channelId || record.continuationToken !== oldToken) {
|
|
772
|
-
continue;
|
|
773
|
-
}
|
|
774
|
-
await this.persist({
|
|
775
|
-
...record,
|
|
776
|
-
continuationToken: newToken,
|
|
777
|
-
generation: (record.generation ?? 0) + 1,
|
|
778
|
-
updatedAt: new Date().toISOString(),
|
|
779
|
-
});
|
|
780
|
-
n += 1;
|
|
781
|
-
}
|
|
782
|
-
return n;
|
|
783
|
-
}
|
|
784
|
-
|
|
785
|
-
/** Fire one reminder immediately (dev / hillclimb / control plane). */
|
|
786
|
-
async dispatch(
|
|
787
|
-
reminderId: string,
|
|
788
|
-
opts: { expectedFireCount?: number } = {},
|
|
789
|
-
): Promise<{
|
|
790
|
-
reminderId: string;
|
|
791
|
-
outcome: "fired" | "noop";
|
|
792
|
-
reason?: string;
|
|
793
|
-
}> {
|
|
794
|
-
const record = await this.getRecord(reminderId);
|
|
795
|
-
if (record === undefined) {
|
|
796
|
-
const ids = (await this.allRecords()).map(r => r.id);
|
|
797
|
-
throw new UnknownReminderError(reminderId, ids);
|
|
798
|
-
}
|
|
799
|
-
if (opts.expectedFireCount !== undefined && record.fireCount !== opts.expectedFireCount) {
|
|
800
|
-
return {
|
|
801
|
-
reminderId,
|
|
802
|
-
outcome: "noop",
|
|
803
|
-
reason: "stale_fire_count",
|
|
804
|
-
};
|
|
805
|
-
}
|
|
806
|
-
const result = await this.fire(record.id, { force: true });
|
|
807
|
-
return { reminderId, ...result };
|
|
808
|
-
}
|
|
809
|
-
|
|
810
|
-
/**
|
|
811
|
-
* Architecture v2 / CP protocol guest entrypoint: execute an immutable fire
|
|
812
|
-
* descriptor and return an outcome. Does not mint ids or mutate
|
|
813
|
-
* authoritative status/fireCount — the control plane applies the outcome.
|
|
814
|
-
*/
|
|
815
|
-
async executeFire(descriptor: ReminderFireDescriptor): Promise<ReminderExecutionOutcome> {
|
|
816
|
-
const record = this.recordFromDescriptor(descriptor);
|
|
817
|
-
this.records.set(record.id, record);
|
|
818
|
-
let fire: FireExecution;
|
|
819
|
-
try {
|
|
820
|
-
fire = await this.runFire(record);
|
|
821
|
-
} catch (error) {
|
|
822
|
-
// The hosted admission maps the throw to a retryable failure; count
|
|
823
|
-
// it so the retry loop is visible beside the settled outcomes.
|
|
824
|
-
this.recordFireOutcome(record, {
|
|
825
|
-
kind: "error",
|
|
826
|
-
reason: "fire_threw",
|
|
827
|
-
detail: error instanceof Error ? error.message : String(error),
|
|
828
|
-
});
|
|
829
|
-
throw error;
|
|
830
|
-
}
|
|
831
|
-
this.recordFireOutcome(record, {
|
|
832
|
-
kind: fire.outcome.kind,
|
|
833
|
-
reason: fire.reason,
|
|
834
|
-
turnStatus: fire.turnStatus,
|
|
835
|
-
});
|
|
836
|
-
return fire.outcome;
|
|
837
|
-
}
|
|
838
|
-
|
|
839
|
-
private async runFire(record: ReminderRecord): Promise<FireExecution> {
|
|
840
|
-
const live = this.handlers.get(record.id) ?? {};
|
|
841
|
-
if (record.handler !== undefined) {
|
|
842
|
-
if (this.resolveNamedHandler(record.handler) === undefined) {
|
|
843
|
-
return stopFire("handler_missing");
|
|
844
|
-
}
|
|
845
|
-
} else if (
|
|
846
|
-
(record.hasRunHandler === true || record.hasUntilFn === true) &&
|
|
847
|
-
live.run === undefined &&
|
|
848
|
-
live.untilFn === undefined
|
|
849
|
-
) {
|
|
850
|
-
return stopFire("handler_lost_on_restart");
|
|
851
|
-
}
|
|
852
|
-
|
|
853
|
-
if (live.untilFn !== undefined) {
|
|
854
|
-
try {
|
|
855
|
-
const done = await live.untilFn(this.buildUntilContext(record));
|
|
856
|
-
if (done) {
|
|
857
|
-
return stopFire("until_fn");
|
|
858
|
-
}
|
|
859
|
-
} catch (error) {
|
|
860
|
-
this.logger(
|
|
861
|
-
`[agent-sdk] reminder "${record.id}" until() failed: ${
|
|
862
|
-
error instanceof Error ? error.message : String(error)
|
|
863
|
-
}`,
|
|
864
|
-
);
|
|
865
|
-
}
|
|
866
|
-
}
|
|
867
|
-
|
|
868
|
-
if (await this.isSessionBusy(record.channelId, record.continuationToken)) {
|
|
869
|
-
if (record.busyPolicy === "skipIfBusy") {
|
|
870
|
-
return { outcome: { kind: "skipped" }, reason: "busy" };
|
|
871
|
-
}
|
|
872
|
-
await this.whenSessionIdle(record.channelId, record.continuationToken);
|
|
873
|
-
}
|
|
874
|
-
|
|
875
|
-
let result: ReminderFireResult;
|
|
876
|
-
let reason: ReminderFireOutcomeReason;
|
|
877
|
-
let turnStatus: TurnOutcome["status"] | undefined;
|
|
878
|
-
if (record.handler !== undefined) {
|
|
879
|
-
const named = this.resolveNamedHandler(record.handler);
|
|
880
|
-
if (named === undefined) {
|
|
881
|
-
return stopFire("handler_missing");
|
|
882
|
-
}
|
|
883
|
-
result = await named.run(this.buildFireContext(record));
|
|
884
|
-
reason = runReason(result);
|
|
885
|
-
} else if (live.run !== undefined) {
|
|
886
|
-
result = await live.run(this.buildFireContext(record));
|
|
887
|
-
reason = runReason(result);
|
|
888
|
-
} else if (record.prompt !== undefined) {
|
|
889
|
-
const delivery = await this.deliverPromptFire(record);
|
|
890
|
-
result = delivery.result;
|
|
891
|
-
reason = delivery.reason;
|
|
892
|
-
turnStatus = delivery.turnStatus;
|
|
893
|
-
} else {
|
|
894
|
-
return stopFire("missing_handler");
|
|
895
|
-
}
|
|
896
|
-
|
|
897
|
-
if (result.action === "stop") {
|
|
898
|
-
return { outcome: { kind: "stop", reason }, reason };
|
|
899
|
-
}
|
|
900
|
-
const reschedule =
|
|
901
|
-
result.reschedule !== undefined ? toWireReschedule(result.reschedule) : undefined;
|
|
902
|
-
return {
|
|
903
|
-
outcome: {
|
|
904
|
-
kind: result.action === "skip" ? "skipped" : "delivered",
|
|
905
|
-
reschedule,
|
|
906
|
-
},
|
|
907
|
-
reason,
|
|
908
|
-
turnStatus,
|
|
909
|
-
};
|
|
910
|
-
}
|
|
911
|
-
|
|
912
|
-
/**
|
|
913
|
-
* One structured line and one `agent_sdk.reminder.fire_outcome` count per
|
|
914
|
-
* fire. Emitted through the host OTel meter, the same path hosted v2
|
|
915
|
-
* exports turn/tool metrics on, so a fire that ends in `stop` is visible
|
|
916
|
-
* beside the control plane's `timed_work.fire` count.
|
|
917
|
-
*/
|
|
918
|
-
private recordFireOutcome(
|
|
919
|
-
record: ReminderRecord,
|
|
920
|
-
fire: {
|
|
921
|
-
kind: ReminderExecutionOutcome["kind"] | "error";
|
|
922
|
-
reason: ReminderFireOutcomeReason;
|
|
923
|
-
turnStatus?: TurnOutcome["status"];
|
|
924
|
-
detail?: string;
|
|
925
|
-
},
|
|
926
|
-
): void {
|
|
927
|
-
this.logger(
|
|
928
|
-
`[agent-sdk] reminder fire_outcome kind=${fire.kind} reason=${fire.reason}` +
|
|
929
|
-
` reminderId=${record.id} purpose=${record.purpose}` +
|
|
930
|
-
` channelId=${record.channelId} fireCount=${record.fireCount}` +
|
|
931
|
-
(fire.turnStatus === undefined ? "" : ` turn=${fire.turnStatus}`) +
|
|
932
|
-
(fire.detail === undefined ? "" : ` detail=${JSON.stringify(fire.detail)}`),
|
|
933
|
-
);
|
|
934
|
-
// Test doubles may omit `host.otel`; the metric is best-effort.
|
|
935
|
-
const otel: HostOtelApi | undefined = this.engine.host.otel;
|
|
936
|
-
if (otel === undefined) {
|
|
937
|
-
return;
|
|
938
|
-
}
|
|
939
|
-
try {
|
|
940
|
-
otel.increment(REMINDER_FIRE_OUTCOME_METRIC, {
|
|
941
|
-
kind: fire.kind,
|
|
942
|
-
reason: fire.reason,
|
|
943
|
-
purpose: record.purpose,
|
|
944
|
-
});
|
|
945
|
-
} catch (error) {
|
|
946
|
-
this.logger(
|
|
947
|
-
`[agent-sdk] reminder fire_outcome metric failed: ${
|
|
948
|
-
error instanceof Error ? error.message : String(error)
|
|
949
|
-
}`,
|
|
950
|
-
);
|
|
951
|
-
}
|
|
952
|
-
}
|
|
953
|
-
|
|
954
|
-
private recordFromDescriptor(descriptor: ReminderFireDescriptor): ReminderRecord {
|
|
955
|
-
const now = new Date().toISOString();
|
|
956
|
-
return {
|
|
957
|
-
version: 1,
|
|
958
|
-
id: descriptor.id,
|
|
959
|
-
purpose: descriptor.purpose,
|
|
960
|
-
channelId: descriptor.channelId,
|
|
961
|
-
continuationToken: descriptor.continuationToken,
|
|
962
|
-
target: descriptor.target,
|
|
963
|
-
scheduleKind: descriptor.scheduleKind,
|
|
964
|
-
scheduleValue: descriptor.scheduleValue,
|
|
965
|
-
intervalMs: descriptor.intervalMs,
|
|
966
|
-
prompt: descriptor.prompt,
|
|
967
|
-
handler: descriptor.handler,
|
|
968
|
-
args: descriptor.args,
|
|
969
|
-
hasRunHandler: descriptor.hasRunHandler,
|
|
970
|
-
hasUntilFn: descriptor.hasUntilFn,
|
|
971
|
-
untilPrompt: descriptor.untilPrompt,
|
|
972
|
-
busyPolicy: descriptor.busyPolicy,
|
|
973
|
-
status: "firing",
|
|
974
|
-
fireCount: descriptor.fireCount,
|
|
975
|
-
nextFireAtMs: descriptor.nextFireAtMs,
|
|
976
|
-
generation: descriptor.generation,
|
|
977
|
-
createdAt: now,
|
|
978
|
-
updatedAt: now,
|
|
979
|
-
};
|
|
980
|
-
}
|
|
981
|
-
|
|
982
|
-
private armTimer(record: ReminderRecord): void {
|
|
983
|
-
this.clearTimer(record.id);
|
|
984
|
-
if (!this.started || record.status !== "armed") return;
|
|
985
|
-
const nextFireAtMs = Number.isFinite(record.nextFireAtMs) ? record.nextFireAtMs : Date.now();
|
|
986
|
-
const delay = Math.min(MAX_TIMER_MS, Math.max(0, nextFireAtMs - Date.now()));
|
|
987
|
-
const timer = setTimeout(() => {
|
|
988
|
-
void this.fire(record.id).catch(async error => {
|
|
989
|
-
this.logger(
|
|
990
|
-
`[agent-sdk] reminder "${record.id}" fire failed: ${
|
|
991
|
-
error instanceof Error ? error.message : String(error)
|
|
992
|
-
}`,
|
|
993
|
-
);
|
|
994
|
-
// Keep recurring reminders alive after unexpected throws.
|
|
995
|
-
// One-shots stay armed so a failed wake can be retried / dispatched.
|
|
996
|
-
try {
|
|
997
|
-
const current = await this.getRecord(record.id);
|
|
998
|
-
if (current === undefined || current.status !== "armed") return;
|
|
999
|
-
const oneShot = current.scheduleKind === "delay" || current.scheduleKind === "at";
|
|
1000
|
-
if (oneShot) {
|
|
1001
|
-
this.armTimer(current);
|
|
1002
|
-
return;
|
|
1003
|
-
}
|
|
1004
|
-
await this.afterFire(current, "skip");
|
|
1005
|
-
} catch (rescheduleError) {
|
|
1006
|
-
this.logger(
|
|
1007
|
-
`[agent-sdk] reminder "${record.id}" reschedule after failure failed: ${
|
|
1008
|
-
rescheduleError instanceof Error ? rescheduleError.message : String(rescheduleError)
|
|
1009
|
-
}`,
|
|
1010
|
-
);
|
|
1011
|
-
}
|
|
1012
|
-
});
|
|
1013
|
-
}, delay);
|
|
1014
|
-
timer.unref?.();
|
|
1015
|
-
this.timers.set(record.id, timer);
|
|
1016
|
-
}
|
|
1017
|
-
|
|
1018
|
-
private clearTimer(id: string): void {
|
|
1019
|
-
const timer = this.timers.get(id);
|
|
1020
|
-
if (timer !== undefined) {
|
|
1021
|
-
clearTimeout(timer);
|
|
1022
|
-
this.timers.delete(id);
|
|
1023
|
-
}
|
|
1024
|
-
}
|
|
1025
|
-
|
|
1026
|
-
private resolveNamedHandler(name: string): ReminderDefinition | undefined {
|
|
1027
|
-
return this.namedHandlers.get(name);
|
|
1028
|
-
}
|
|
1029
|
-
|
|
1030
|
-
private async fire(
|
|
1031
|
-
id: string,
|
|
1032
|
-
opts: { force?: boolean } = {},
|
|
1033
|
-
): Promise<{ outcome: "fired" | "noop"; reason?: string }> {
|
|
1034
|
-
if (this.firing.has(id)) {
|
|
1035
|
-
return { outcome: "noop", reason: "already_firing" };
|
|
1036
|
-
}
|
|
1037
|
-
this.firing.add(id);
|
|
1038
|
-
try {
|
|
1039
|
-
const record = await this.getRecord(id);
|
|
1040
|
-
if (record === undefined || record.status !== "armed") {
|
|
1041
|
-
this.clearTimer(id);
|
|
1042
|
-
return { outcome: "noop", reason: "not_armed" };
|
|
1043
|
-
}
|
|
1044
|
-
|
|
1045
|
-
if (!opts.force && record.nextFireAtMs > Date.now() + 50) {
|
|
1046
|
-
// Spurious early wake — re-arm.
|
|
1047
|
-
this.armTimer(record);
|
|
1048
|
-
return { outcome: "noop", reason: "not_due" };
|
|
1049
|
-
}
|
|
1050
|
-
|
|
1051
|
-
const live = this.handlers.get(id) ?? {};
|
|
1052
|
-
if (record.handler !== undefined) {
|
|
1053
|
-
if (this.resolveNamedHandler(record.handler) === undefined) {
|
|
1054
|
-
await this.disarm(record, "handler_missing");
|
|
1055
|
-
return { outcome: "noop", reason: "handler_missing" };
|
|
1056
|
-
}
|
|
1057
|
-
} else if (
|
|
1058
|
-
(record.hasRunHandler === true || record.hasUntilFn === true) &&
|
|
1059
|
-
live.run === undefined &&
|
|
1060
|
-
live.untilFn === undefined
|
|
1061
|
-
) {
|
|
1062
|
-
await this.disarm(record, "handler_lost_on_restart");
|
|
1063
|
-
return { outcome: "noop", reason: "handler_lost_on_restart" };
|
|
1064
|
-
}
|
|
1065
|
-
|
|
1066
|
-
const untilCtx = this.buildUntilContext(record);
|
|
1067
|
-
|
|
1068
|
-
if (live.untilFn !== undefined) {
|
|
1069
|
-
try {
|
|
1070
|
-
const done = await live.untilFn(untilCtx);
|
|
1071
|
-
if (done) {
|
|
1072
|
-
await this.disarm(record, "until_fn");
|
|
1073
|
-
return { outcome: "fired", reason: "until_fn" };
|
|
1074
|
-
}
|
|
1075
|
-
} catch (error) {
|
|
1076
|
-
this.logger(
|
|
1077
|
-
`[agent-sdk] reminder "${id}" until() failed: ${
|
|
1078
|
-
error instanceof Error ? error.message : String(error)
|
|
1079
|
-
}`,
|
|
1080
|
-
);
|
|
1081
|
-
}
|
|
1082
|
-
}
|
|
1083
|
-
|
|
1084
|
-
if (await this.isSessionBusy(record.channelId, record.continuationToken)) {
|
|
1085
|
-
if (record.busyPolicy === "skipIfBusy") {
|
|
1086
|
-
await this.afterFire(record, "skip");
|
|
1087
|
-
this.logger(`[agent-sdk] reminder "${id}" (${record.purpose}) skipped: session busy`);
|
|
1088
|
-
return { outcome: "fired", reason: "skipped_busy" };
|
|
1089
|
-
}
|
|
1090
|
-
await this.whenSessionIdle(record.channelId, record.continuationToken);
|
|
1091
|
-
const still = await this.getRecord(id);
|
|
1092
|
-
if (still === undefined || still.status !== "armed") {
|
|
1093
|
-
return { outcome: "noop", reason: "disarmed_while_waiting" };
|
|
1094
|
-
}
|
|
1095
|
-
}
|
|
1096
|
-
|
|
1097
|
-
let result: ReminderFireResult;
|
|
1098
|
-
if (record.handler !== undefined) {
|
|
1099
|
-
const named = this.resolveNamedHandler(record.handler);
|
|
1100
|
-
if (named === undefined) {
|
|
1101
|
-
await this.disarm(record, "handler_missing");
|
|
1102
|
-
return { outcome: "noop", reason: "handler_missing" };
|
|
1103
|
-
}
|
|
1104
|
-
result = await named.run(this.buildFireContext(record));
|
|
1105
|
-
} else if (live.run !== undefined) {
|
|
1106
|
-
result = await live.run(this.buildFireContext(record));
|
|
1107
|
-
} else if (record.prompt !== undefined) {
|
|
1108
|
-
result = await this.deliverPrompt(record);
|
|
1109
|
-
} else {
|
|
1110
|
-
await this.disarm(record, "missing_handler");
|
|
1111
|
-
return { outcome: "noop", reason: "missing_handler" };
|
|
1112
|
-
}
|
|
1113
|
-
|
|
1114
|
-
// Cancel / disarm during the handler must win over reschedule.
|
|
1115
|
-
const latest = await this.getRecord(id);
|
|
1116
|
-
if (result.action === "stop") {
|
|
1117
|
-
if (latest !== undefined && latest.status === "armed") {
|
|
1118
|
-
await this.disarm(latest, "run_stop");
|
|
1119
|
-
this.logger(`[agent-sdk] reminder "${id}" (${record.purpose}) disarmed: run_stop`);
|
|
1120
|
-
return { outcome: "fired", reason: "run_stop" };
|
|
1121
|
-
}
|
|
1122
|
-
return {
|
|
1123
|
-
outcome: "fired",
|
|
1124
|
-
reason: latest?.disarmReason ?? "run_stop",
|
|
1125
|
-
};
|
|
1126
|
-
}
|
|
1127
|
-
if (latest === undefined || latest.status !== "armed") {
|
|
1128
|
-
return { outcome: "noop", reason: "disarmed_during_fire" };
|
|
1129
|
-
}
|
|
1130
|
-
|
|
1131
|
-
if (result.action === "skip") {
|
|
1132
|
-
await this.afterFire(latest, "skip", result.reschedule);
|
|
1133
|
-
this.logger(`[agent-sdk] reminder "${id}" (${record.purpose}) skipped`);
|
|
1134
|
-
return { outcome: "fired", reason: "skipped" };
|
|
1135
|
-
}
|
|
1136
|
-
await this.afterFire(latest, "delivered", result.reschedule);
|
|
1137
|
-
this.logger(`[agent-sdk] reminder "${id}" (${record.purpose}) fired`);
|
|
1138
|
-
return { outcome: "fired", reason: "delivered" };
|
|
1139
|
-
} finally {
|
|
1140
|
-
this.firing.delete(id);
|
|
1141
|
-
}
|
|
1142
|
-
}
|
|
1143
|
-
|
|
1144
|
-
private async isSessionBusy(channelId: string, continuationToken: string): Promise<boolean> {
|
|
1145
|
-
const existing = await this.engine.sessions.findByContinuation(channelId, continuationToken);
|
|
1146
|
-
if (existing === undefined) return false;
|
|
1147
|
-
return this.engine.isTurnRunning(existing.sessionId);
|
|
1148
|
-
}
|
|
1149
|
-
|
|
1150
|
-
private whenSessionIdle(channelId: string, continuationToken: string): Promise<void> {
|
|
1151
|
-
const sessionKey = `${channelId}:${continuationToken}`;
|
|
1152
|
-
const existing = this.idleGates.get(sessionKey);
|
|
1153
|
-
if (existing !== undefined) return existing;
|
|
1154
|
-
|
|
1155
|
-
const gate = (async () => {
|
|
1156
|
-
const session = await this.engine.sessions.findByContinuation(channelId, continuationToken);
|
|
1157
|
-
if (session === undefined) return;
|
|
1158
|
-
await this.engine.waitForCompletion(session.sessionId);
|
|
1159
|
-
})().finally(() => {
|
|
1160
|
-
this.idleGates.delete(sessionKey);
|
|
1161
|
-
});
|
|
1162
|
-
this.idleGates.set(sessionKey, gate);
|
|
1163
|
-
return gate;
|
|
1164
|
-
}
|
|
1165
|
-
|
|
1166
|
-
/**
|
|
1167
|
-
* Follow-ups must use the bound session's principal. If the session is gone,
|
|
1168
|
-
* disarm rather than creating a fresh APP_AUTH conversation.
|
|
1169
|
-
*/
|
|
1170
|
-
private async resolveFollowupAuth(
|
|
1171
|
-
channelId: string,
|
|
1172
|
-
continuationToken: string,
|
|
1173
|
-
): Promise<AuthContext | null | undefined> {
|
|
1174
|
-
const existing = await this.engine.sessions.findByContinuation(channelId, continuationToken);
|
|
1175
|
-
if (existing !== undefined) {
|
|
1176
|
-
return existing.auth;
|
|
1177
|
-
}
|
|
1178
|
-
return undefined;
|
|
1179
|
-
}
|
|
1180
|
-
|
|
1181
|
-
private async deliverPrompt(record: ReminderRecord): Promise<ReminderFireResult> {
|
|
1182
|
-
return (await this.deliverPromptFire(record)).result;
|
|
1183
|
-
}
|
|
1184
|
-
|
|
1185
|
-
/**
|
|
1186
|
-
* Where a prompt fire joins. The pod's own store first; on a hosted guest
|
|
1187
|
-
* the durable mirror next, because the pod that armed the reminder is
|
|
1188
|
-
* usually gone and the session lives only in storage. A restored session
|
|
1189
|
-
* keeps its own principal (channel admissions may carry a sender), so the
|
|
1190
|
-
* fire joins under that, never under {@link ReminderHostedGuestOptions.fireAuth}.
|
|
1191
|
-
*/
|
|
1192
|
-
private async resolveFollowupTarget(record: ReminderRecord): Promise<FollowupTarget> {
|
|
1193
|
-
const local = await this.resolveFollowupAuth(record.channelId, record.continuationToken);
|
|
1194
|
-
if (local !== undefined) {
|
|
1195
|
-
return { auth: local, reached: "session_joined" };
|
|
1196
|
-
}
|
|
1197
|
-
if (this.hostedGuest === undefined) {
|
|
1198
|
-
return { auth: undefined, reached: "session_gone" };
|
|
1199
|
-
}
|
|
1200
|
-
// Materializes the durable record locally; a storage error propagates
|
|
1201
|
-
// and the hosted admission retries the fire.
|
|
1202
|
-
const restored = await this.engine.hasContinuationSession(
|
|
1203
|
-
record.channelId,
|
|
1204
|
-
record.continuationToken,
|
|
1205
|
-
);
|
|
1206
|
-
if (!restored) {
|
|
1207
|
-
return { auth: undefined, reached: "session_gone" };
|
|
1208
|
-
}
|
|
1209
|
-
const auth = await this.resolveFollowupAuth(record.channelId, record.continuationToken);
|
|
1210
|
-
return auth === undefined
|
|
1211
|
-
? { auth: undefined, reached: "session_unreadable" }
|
|
1212
|
-
: { auth, reached: "session_restored" };
|
|
1213
|
-
}
|
|
1214
|
-
|
|
1215
|
-
private async deliverPromptFire(record: ReminderRecord): Promise<PromptDelivery> {
|
|
1216
|
-
const target = await this.resolveFollowupTarget(record);
|
|
1217
|
-
if (target.auth !== undefined) {
|
|
1218
|
-
return this.promptDelivery(record, target.auth, target.reached);
|
|
1219
|
-
}
|
|
1220
|
-
if (target.reached === "session_unreadable") {
|
|
1221
|
-
this.logger(
|
|
1222
|
-
`[agent-sdk] reminder "${record.id}" (${record.purpose}) durable session did not materialize locally; not opening a new one`,
|
|
1223
|
-
);
|
|
1224
|
-
return { result: { action: "stop" }, reason: "session_gone" };
|
|
1225
|
-
}
|
|
1226
|
-
if (
|
|
1227
|
-
this.hostedGuest !== undefined &&
|
|
1228
|
-
this.channelUsesControlPlaneContinuation(record.channelId)
|
|
1229
|
-
) {
|
|
1230
|
-
// No session on this pod and none in durable storage. Open one on the
|
|
1231
|
-
// stored key the way an inbound event on a fresh key does, instead of
|
|
1232
|
-
// consuming the fire with no turn.
|
|
1233
|
-
const fireAuth = this.hostedGuest.fireAuth();
|
|
1234
|
-
if (fireAuth === undefined) {
|
|
1235
|
-
return {
|
|
1236
|
-
result: {
|
|
1237
|
-
action: "skip",
|
|
1238
|
-
reschedule: { delay: REMINDER_SESSION_OPEN_RETRY_DELAY },
|
|
1239
|
-
},
|
|
1240
|
-
reason: "session_gone",
|
|
1241
|
-
};
|
|
1242
|
-
}
|
|
1243
|
-
try {
|
|
1244
|
-
return await this.promptDelivery(record, fireAuth, "session_opened");
|
|
1245
|
-
} catch (error) {
|
|
1246
|
-
if (!(error instanceof SessionAuthError)) {
|
|
1247
|
-
throw error;
|
|
1248
|
-
}
|
|
1249
|
-
// A session landed on this key under another principal between the
|
|
1250
|
-
// lookup and the send. That does not change on retry, so stop
|
|
1251
|
-
// rather than let the control plane re-admit until its attempt cap.
|
|
1252
|
-
this.logger(
|
|
1253
|
-
`[agent-sdk] reminder "${record.id}" (${record.purpose}) cannot join session on its continuation: ${error.message}`,
|
|
1254
|
-
);
|
|
1255
|
-
return { result: { action: "stop" }, reason: "session_gone" };
|
|
1256
|
-
}
|
|
1257
|
-
}
|
|
1258
|
-
// Under CP protocol, return stop and let the CP apply/CAS; do not
|
|
1259
|
-
// mutate authoritative status from the guest mid-fire.
|
|
1260
|
-
if (!this.usesControlPlaneProtocol) {
|
|
1261
|
-
await this.disarm(record, "session_gone");
|
|
1262
|
-
}
|
|
1263
|
-
return { result: { action: "stop" }, reason: "session_gone" };
|
|
1264
|
-
}
|
|
1265
|
-
|
|
1266
|
-
private async promptDelivery(
|
|
1267
|
-
record: ReminderRecord,
|
|
1268
|
-
auth: AuthContext | null,
|
|
1269
|
-
delivered: Extract<
|
|
1270
|
-
ReminderFireOutcomeReason,
|
|
1271
|
-
"session_joined" | "session_restored" | "session_opened"
|
|
1272
|
-
>,
|
|
1273
|
-
): Promise<PromptDelivery> {
|
|
1274
|
-
const settle: FollowupSettle = {};
|
|
1275
|
-
const result = await this.sendFollowup(record, buildFirePrompt(record), auth, settle);
|
|
1276
|
-
return {
|
|
1277
|
-
result,
|
|
1278
|
-
reason: result.action === "skip" ? (settle.skipReason ?? "busy") : delivered,
|
|
1279
|
-
turnStatus: settle.turnStatus,
|
|
1280
|
-
};
|
|
1281
|
-
}
|
|
1282
|
-
|
|
1283
|
-
/**
|
|
1284
|
-
* Join the reminder's existing session. Control-plane (`/v2`) channels
|
|
1285
|
-
* refuse authored `continuationToken`; pass the stored key as
|
|
1286
|
-
* {@link EngineSendOptions.mailboxContinuation} so the engine reuses the
|
|
1287
|
-
* CP-selected identity without channel admission.
|
|
1288
|
-
*/
|
|
1289
|
-
private followupSendOptions(record: ReminderRecord, auth: AuthContext | null): EngineSendOptions {
|
|
1290
|
-
if (this.channelUsesControlPlaneContinuation(record.channelId)) {
|
|
1291
|
-
return {
|
|
1292
|
-
auth,
|
|
1293
|
-
mailboxContinuation: { key: record.continuationToken },
|
|
1294
|
-
};
|
|
1295
|
-
}
|
|
1296
|
-
return {
|
|
1297
|
-
auth,
|
|
1298
|
-
continuationToken: record.continuationToken,
|
|
1299
|
-
};
|
|
1300
|
-
}
|
|
1301
|
-
|
|
1302
|
-
private channelUsesControlPlaneContinuation(channelId: string): boolean {
|
|
1303
|
-
const project = this.engine.project;
|
|
1304
|
-
// Test doubles may omit `project`; keep the legacy continuationToken path.
|
|
1305
|
-
if (project === undefined) {
|
|
1306
|
-
return false;
|
|
1307
|
-
}
|
|
1308
|
-
const identity =
|
|
1309
|
-
channelId === HTTP_CHANNEL_ID
|
|
1310
|
-
? httpContinuationIdentity(project.httpChannel)
|
|
1311
|
-
: channelContinuationIdentity(
|
|
1312
|
-
project.channels.find(channel => channel.id === channelId)?.definition,
|
|
1313
|
-
);
|
|
1314
|
-
return continuationSource(identity) === "control-plane";
|
|
1315
|
-
}
|
|
1316
|
-
|
|
1317
|
-
/**
|
|
1318
|
-
* Local and v1 track the turn in the background: the process outlives the
|
|
1319
|
-
* fire. A hosted v2 guest waits for the turn and its durable writes first,
|
|
1320
|
-
* because the control plane may stop the pod as soon as the fire's
|
|
1321
|
-
* outcome is applied, and `delivered` must mean the turn ran.
|
|
1322
|
-
*/
|
|
1323
|
-
private async settleFollowup(
|
|
1324
|
-
session: ChannelSession,
|
|
1325
|
-
settle: FollowupSettle | undefined,
|
|
1326
|
-
): Promise<void> {
|
|
1327
|
-
const completion = this.engine.waitForCompletion(session.id);
|
|
1328
|
-
if (this.hostedGuest === undefined) {
|
|
1329
|
-
this.engine.trackBackground(completion);
|
|
1330
|
-
return;
|
|
1331
|
-
}
|
|
1332
|
-
const outcome = await completion;
|
|
1333
|
-
await this.engine.drainSessionDurability(session.id);
|
|
1334
|
-
if (settle !== undefined) {
|
|
1335
|
-
settle.turnStatus = outcome.status;
|
|
1336
|
-
}
|
|
1337
|
-
}
|
|
1338
|
-
|
|
1339
|
-
private async sendFollowup(
|
|
1340
|
-
record: ReminderRecord,
|
|
1341
|
-
message: string,
|
|
1342
|
-
auth: AuthContext | null,
|
|
1343
|
-
settle?: FollowupSettle,
|
|
1344
|
-
extra?: ReminderFollowupOptions,
|
|
1345
|
-
): Promise<ReminderFireResult> {
|
|
1346
|
-
const sendOptions: EngineSendOptions = {
|
|
1347
|
-
...this.followupSendOptions(record, auth),
|
|
1348
|
-
state: extra?.state,
|
|
1349
|
-
refreshState: extra?.refreshState,
|
|
1350
|
-
title: extra?.title,
|
|
1351
|
-
clearCloudOverride: extra?.clearCloudOverride,
|
|
1352
|
-
};
|
|
1353
|
-
try {
|
|
1354
|
-
const session = await this.engine.send(record.channelId, message, sendOptions);
|
|
1355
|
-
await this.settleFollowup(session, settle);
|
|
1356
|
-
return { action: "delivered" };
|
|
1357
|
-
} catch (error) {
|
|
1358
|
-
if (error instanceof SessionBusyError) {
|
|
1359
|
-
if (record.busyPolicy === "skipIfBusy") {
|
|
1360
|
-
if (settle !== undefined) {
|
|
1361
|
-
settle.skipReason = "busy";
|
|
1362
|
-
}
|
|
1363
|
-
return { action: "skip" };
|
|
1364
|
-
}
|
|
1365
|
-
await this.whenSessionIdle(record.channelId, record.continuationToken);
|
|
1366
|
-
try {
|
|
1367
|
-
const session = await this.engine.send(record.channelId, message, sendOptions);
|
|
1368
|
-
await this.settleFollowup(session, settle);
|
|
1369
|
-
return { action: "delivered" };
|
|
1370
|
-
} catch (retryError) {
|
|
1371
|
-
this.logger(
|
|
1372
|
-
`[agent-sdk] reminder "${record.id}" followup failed after wait: ${
|
|
1373
|
-
retryError instanceof Error ? retryError.message : String(retryError)
|
|
1374
|
-
}`,
|
|
1375
|
-
);
|
|
1376
|
-
if (settle !== undefined) {
|
|
1377
|
-
settle.skipReason = "followup_failed";
|
|
1378
|
-
}
|
|
1379
|
-
return { action: "skip" };
|
|
1380
|
-
}
|
|
1381
|
-
}
|
|
1382
|
-
throw error;
|
|
1383
|
-
}
|
|
1384
|
-
}
|
|
1385
|
-
|
|
1386
|
-
private buildFireContext(record: ReminderRecord): ReminderFireContext {
|
|
1387
|
-
const self = this;
|
|
1388
|
-
return {
|
|
1389
|
-
id: record.id,
|
|
1390
|
-
purpose: record.purpose,
|
|
1391
|
-
fireCount: record.fireCount,
|
|
1392
|
-
target: {
|
|
1393
|
-
channelId: record.channelId,
|
|
1394
|
-
continuationToken: record.continuationToken,
|
|
1395
|
-
...(record.target ?? {}),
|
|
1396
|
-
},
|
|
1397
|
-
args: record.args ?? {},
|
|
1398
|
-
host: this.engine.host,
|
|
1399
|
-
mcp: this.engine.host.mcp,
|
|
1400
|
-
appAuth: APP_AUTH,
|
|
1401
|
-
artifacts: this.engine.artifacts,
|
|
1402
|
-
async followup(args: { message: string } & ReminderFollowupOptions) {
|
|
1403
|
-
const target = await self.resolveFollowupTarget(record);
|
|
1404
|
-
let auth = target.auth;
|
|
1405
|
-
// `openAuth` opens only when nothing exists anywhere: an unreadable
|
|
1406
|
-
// durable session must not be shadowed by a second one on the same
|
|
1407
|
-
// key (prompt-fire parity).
|
|
1408
|
-
if (
|
|
1409
|
-
auth === undefined &&
|
|
1410
|
-
target.reached === "session_gone" &&
|
|
1411
|
-
args.openAuth !== undefined
|
|
1412
|
-
) {
|
|
1413
|
-
auth = args.openAuth;
|
|
1414
|
-
}
|
|
1415
|
-
if (auth === undefined) {
|
|
1416
|
-
// Under the CP protocol the guest never writes reminder status;
|
|
1417
|
-
// the fire's `stop` outcome carries the reason instead.
|
|
1418
|
-
if (!self.usesControlPlaneProtocol) {
|
|
1419
|
-
await self.disarm(record, "session_gone");
|
|
1420
|
-
}
|
|
1421
|
-
throw new Error(`Reminder "${record.id}" followup: session gone for continuation`);
|
|
1422
|
-
}
|
|
1423
|
-
const result = await self.sendFollowup(record, args.message, auth, undefined, args);
|
|
1424
|
-
if (result.action === "skip") {
|
|
1425
|
-
throw new Error(`Reminder "${record.id}" followup skipped: session busy`);
|
|
1426
|
-
}
|
|
1427
|
-
const existing = await self.engine.sessions.findByContinuation(
|
|
1428
|
-
record.channelId,
|
|
1429
|
-
record.continuationToken,
|
|
1430
|
-
);
|
|
1431
|
-
if (existing === undefined) {
|
|
1432
|
-
throw new Error(`Reminder "${record.id}" followup: session not found for continuation`);
|
|
1433
|
-
}
|
|
1434
|
-
const session = await self.engine.getChannelSession(record.channelId, existing.sessionId);
|
|
1435
|
-
if (session === null) {
|
|
1436
|
-
throw new Error(`Reminder "${record.id}" followup: channel session missing`);
|
|
1437
|
-
}
|
|
1438
|
-
return session;
|
|
1439
|
-
},
|
|
1440
|
-
async cancel(reason = "handler_cancel") {
|
|
1441
|
-
await self.cancel(record.id, reason);
|
|
1442
|
-
},
|
|
1443
|
-
};
|
|
1444
|
-
}
|
|
1445
|
-
|
|
1446
|
-
private buildUntilContext(record: ReminderRecord): ReminderUntilContext {
|
|
1447
|
-
return {
|
|
1448
|
-
id: record.id,
|
|
1449
|
-
purpose: record.purpose,
|
|
1450
|
-
fireCount: record.fireCount,
|
|
1451
|
-
target: {
|
|
1452
|
-
channelId: record.channelId,
|
|
1453
|
-
continuationToken: record.continuationToken,
|
|
1454
|
-
...(record.target ?? {}),
|
|
1455
|
-
},
|
|
1456
|
-
host: this.engine.host,
|
|
1457
|
-
mcp: this.engine.host.mcp,
|
|
1458
|
-
};
|
|
1459
|
-
}
|
|
1460
|
-
|
|
1461
|
-
private async disarm(record: ReminderRecord, reason: string): Promise<void> {
|
|
1462
|
-
this.clearTimer(record.id);
|
|
1463
|
-
const updated: ReminderRecord = {
|
|
1464
|
-
...record,
|
|
1465
|
-
status: "disarmed",
|
|
1466
|
-
disarmReason: reason,
|
|
1467
|
-
updatedAt: new Date().toISOString(),
|
|
1468
|
-
};
|
|
1469
|
-
await this.persist(updated);
|
|
1470
|
-
this.handlers.delete(record.id);
|
|
1471
|
-
}
|
|
1472
|
-
|
|
1473
|
-
private async afterFire(
|
|
1474
|
-
record: ReminderRecord,
|
|
1475
|
-
_outcome: "skip" | "delivered",
|
|
1476
|
-
reschedule?: { delay?: string | number; at?: Date | string },
|
|
1477
|
-
): Promise<void> {
|
|
1478
|
-
const current = await this.getRecord(record.id);
|
|
1479
|
-
if (current === undefined || current.status !== "armed") {
|
|
1480
|
-
return;
|
|
1481
|
-
}
|
|
1482
|
-
|
|
1483
|
-
const now = Date.now();
|
|
1484
|
-
const oneShot = current.scheduleKind === "delay" || current.scheduleKind === "at";
|
|
1485
|
-
|
|
1486
|
-
if (reschedule !== undefined) {
|
|
1487
|
-
let nextFireAtMs: number;
|
|
1488
|
-
if (reschedule.delay !== undefined) {
|
|
1489
|
-
nextFireAtMs = now + parseDuration(reschedule.delay);
|
|
1490
|
-
} else if (reschedule.at !== undefined) {
|
|
1491
|
-
nextFireAtMs =
|
|
1492
|
-
reschedule.at instanceof Date
|
|
1493
|
-
? reschedule.at.getTime()
|
|
1494
|
-
: Date.parse(String(reschedule.at));
|
|
1495
|
-
if (!Number.isFinite(nextFireAtMs)) {
|
|
1496
|
-
throw new ReminderValidationError(`Invalid reschedule.at for reminder "${current.id}"`);
|
|
1497
|
-
}
|
|
1498
|
-
} else {
|
|
1499
|
-
throw new ReminderValidationError(
|
|
1500
|
-
`reschedule requires delay or at for reminder "${current.id}"`,
|
|
1501
|
-
);
|
|
1502
|
-
}
|
|
1503
|
-
const updated: ReminderRecord = {
|
|
1504
|
-
...current,
|
|
1505
|
-
fireCount: current.fireCount + 1,
|
|
1506
|
-
nextFireAtMs,
|
|
1507
|
-
// Promote to one-shot-from-now semantics if they rescheduled
|
|
1508
|
-
scheduleKind: reschedule.delay !== undefined ? "delay" : "at",
|
|
1509
|
-
scheduleValue:
|
|
1510
|
-
reschedule.delay !== undefined ? String(reschedule.delay) : String(reschedule.at),
|
|
1511
|
-
updatedAt: new Date().toISOString(),
|
|
1512
|
-
};
|
|
1513
|
-
await this.persist(updated);
|
|
1514
|
-
if (this.platformTimers === undefined) {
|
|
1515
|
-
this.armTimer(updated);
|
|
1516
|
-
}
|
|
1517
|
-
return;
|
|
1518
|
-
}
|
|
1519
|
-
|
|
1520
|
-
if (oneShot) {
|
|
1521
|
-
this.clearTimer(current.id);
|
|
1522
|
-
const updated: ReminderRecord = {
|
|
1523
|
-
...current,
|
|
1524
|
-
fireCount: current.fireCount + 1,
|
|
1525
|
-
status: "completed",
|
|
1526
|
-
disarmReason: "one_shot_complete",
|
|
1527
|
-
updatedAt: new Date().toISOString(),
|
|
1528
|
-
};
|
|
1529
|
-
await this.persist(updated);
|
|
1530
|
-
this.handlers.delete(current.id);
|
|
1531
|
-
return;
|
|
1532
|
-
}
|
|
1533
|
-
|
|
1534
|
-
// Recurring
|
|
1535
|
-
let nextFireAtMs: number;
|
|
1536
|
-
if (current.scheduleKind === "every" && current.intervalMs !== undefined) {
|
|
1537
|
-
nextFireAtMs = now + current.intervalMs;
|
|
1538
|
-
} else if (current.scheduleKind === "cron") {
|
|
1539
|
-
nextFireAtMs = nextCronFireMs(current.scheduleValue, now);
|
|
1540
|
-
} else {
|
|
1541
|
-
throw new Error(
|
|
1542
|
-
`Reminder "${current.id}" has recurring status with scheduleKind=${current.scheduleKind}`,
|
|
1543
|
-
);
|
|
1544
|
-
}
|
|
1545
|
-
const updated: ReminderRecord = {
|
|
1546
|
-
...current,
|
|
1547
|
-
fireCount: current.fireCount + 1,
|
|
1548
|
-
nextFireAtMs,
|
|
1549
|
-
updatedAt: new Date().toISOString(),
|
|
1550
|
-
};
|
|
1551
|
-
await this.persist(updated);
|
|
1552
|
-
if (this.platformTimers === undefined) {
|
|
1553
|
-
this.armTimer(updated);
|
|
1554
|
-
}
|
|
1555
|
-
}
|
|
1556
|
-
}
|
|
1557
|
-
|
|
1558
|
-
// Re-export store record type for tests
|
|
1559
|
-
export type { ReminderRecord } from "./reminder-store.js";
|