@cursor/july 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (298) hide show
  1. package/AGENTS.md +40 -7
  2. package/README.md +33 -24
  3. package/dist/bin/agent-serve.d.ts +3 -1
  4. package/dist/bin/agent-serve.d.ts.map +1 -1
  5. package/dist/bin/agent-serve.js +466 -140
  6. package/dist/channels/github/api.d.ts.map +1 -1
  7. package/dist/channels/github/api.js +31 -14
  8. package/dist/channels/github/cursor-account.d.ts +43 -0
  9. package/dist/channels/github/cursor-account.d.ts.map +1 -0
  10. package/dist/channels/github/cursor-account.js +95 -0
  11. package/dist/channels/github/github-channel.d.ts.map +1 -1
  12. package/dist/channels/github/github-channel.js +46 -9
  13. package/dist/channels/github/index.d.ts +2 -2
  14. package/dist/channels/github/index.js +2 -2
  15. package/dist/channels/github/types.d.ts +17 -0
  16. package/dist/channels/github/types.d.ts.map +1 -1
  17. package/dist/channels/slack/slack-channel.d.ts +8 -2
  18. package/dist/channels/slack/slack-channel.d.ts.map +1 -1
  19. package/dist/channels/slack/slack-channel.js +8 -0
  20. package/dist/channels/slack/types.d.ts +24 -3
  21. package/dist/channels/slack/types.d.ts.map +1 -1
  22. package/dist/channels/slack/types.js +15 -1
  23. package/dist/docs/404.html +2 -2
  24. package/dist/docs/ab.html +8 -8
  25. package/dist/docs/assets/{ab.md.COdXkces.js → ab.md.BMCZ6Hd7.js} +3 -3
  26. package/dist/docs/assets/{ab.md.COdXkces.lean.js → ab.md.BMCZ6Hd7.lean.js} +1 -1
  27. package/dist/docs/assets/{app.DqfFEmJd.js → app.BR0RbIdx.js} +1 -1
  28. package/dist/docs/assets/chunks/@localSearchIndexroot.DtIOQzGj.js +1 -0
  29. package/dist/docs/assets/chunks/{VPLocalSearchBox.BaLEdS15.js → VPLocalSearchBox.qjsVTneI.js} +1 -1
  30. package/dist/docs/assets/chunks/{theme.CZRvu_0q.js → theme.2Kg8jIp_.js} +2 -2
  31. package/dist/docs/assets/{deployment.md.Dx1TYNk5.js → deployment.md.DTKwE15Z.js} +3 -3
  32. package/dist/docs/assets/{deployment.md.Dx1TYNk5.lean.js → deployment.md.DTKwE15Z.lean.js} +1 -1
  33. package/dist/docs/assets/{evals.md.DPZ_MAnI.js → evals.md.DAgEc_hL.js} +3 -3
  34. package/dist/docs/assets/{guides_agent-to-agent.md.CrtrsySy.js → guides_agent-to-agent.md.Bpzgq2Pq.js} +1 -1
  35. package/dist/docs/assets/{guides_cloud-runtime.md.CYlNMTNp.js → guides_cloud-runtime.md.gVzabdQL.js} +1 -1
  36. package/dist/docs/assets/{guides_github.md.DwbKhCeS.js → guides_github.md.DOOCpqsW.js} +11 -4
  37. package/dist/docs/assets/{guides_github.md.DwbKhCeS.lean.js → guides_github.md.DOOCpqsW.lean.js} +1 -1
  38. package/dist/docs/assets/{guides_human-in-the-loop.md.Dvuctx7s.js → guides_human-in-the-loop.md.DlUqsp1S.js} +2 -2
  39. package/dist/docs/assets/{guides_slack.md.bv41fHfW.js → guides_slack.md.CCwqHvSV.js} +4 -4
  40. package/dist/docs/assets/{guides_slack.md.bv41fHfW.lean.js → guides_slack.md.CCwqHvSV.lean.js} +1 -1
  41. package/dist/docs/assets/{guides_webhooks.md.hFTik3lf.js → guides_webhooks.md.B1EswtUu.js} +2 -2
  42. package/dist/docs/assets/index.md.m81y7TY7.js +20 -0
  43. package/dist/docs/assets/{index.md.BPKcj5AI.lean.js → index.md.m81y7TY7.lean.js} +1 -1
  44. package/dist/docs/assets/quickstart.md.BU6Iwi_9.js +204 -0
  45. package/dist/docs/assets/quickstart.md.BU6Iwi_9.lean.js +1 -0
  46. package/dist/docs/assets/{reference_agent-config.md.Bpd7HQwf.js → reference_agent-config.md.DrW2JUM8.js} +4 -4
  47. package/dist/docs/assets/{reference_agent-config.md.Bpd7HQwf.lean.js → reference_agent-config.md.DrW2JUM8.lean.js} +1 -1
  48. package/dist/docs/assets/{reference_channels.md.D7JTR03W.js → reference_channels.md.DdmiKgqf.js} +4 -4
  49. package/dist/docs/assets/{reference_channels.md.D7JTR03W.lean.js → reference_channels.md.DdmiKgqf.lean.js} +1 -1
  50. package/dist/docs/assets/{reference_cli.md.DA730zCu.js → reference_cli.md.Bv6pOxcF.js} +11 -6
  51. package/dist/docs/assets/{reference_cli.md.DA730zCu.lean.js → reference_cli.md.Bv6pOxcF.lean.js} +1 -1
  52. package/dist/docs/assets/{reference_connections.md.C3vNH_DE.js → reference_connections.md.zaEYCLHT.js} +1 -1
  53. package/dist/docs/assets/{reference_hooks.md.BCEc3MyM.js → reference_hooks.md.DyLVfE1O.js} +1 -1
  54. package/dist/docs/assets/{reference_hooks.md.BCEc3MyM.lean.js → reference_hooks.md.DyLVfE1O.lean.js} +1 -1
  55. package/dist/docs/assets/{reference_http-api.md.DBAahtdz.js → reference_http-api.md.Dx_nmDG6.js} +1 -1
  56. package/dist/docs/assets/{reference_instructions.md.BC05LEQ8.js → reference_instructions.md.CgoV-YEb.js} +9 -7
  57. package/dist/docs/assets/{reference_instructions.md.BC05LEQ8.lean.js → reference_instructions.md.CgoV-YEb.lean.js} +1 -1
  58. package/dist/docs/assets/{reference_schedules.md.D7qijxLk.js → reference_schedules.md.w_F2mXB6.js} +2 -2
  59. package/dist/docs/assets/{reference_skills.md.VQnlBT3Q.js → reference_skills.md.B_jHN7JL.js} +3 -3
  60. package/dist/docs/assets/{reference_skills.md.VQnlBT3Q.lean.js → reference_skills.md.B_jHN7JL.lean.js} +1 -1
  61. package/dist/docs/assets/{reference_subagents.md.CIRAVcPK.js → reference_subagents.md.zWAMNfi1.js} +1 -1
  62. package/dist/docs/assets/{reference_tools.md.DF5kwlt0.js → reference_tools.md.CqgJroI0.js} +2 -2
  63. package/dist/docs/assets/scaffolding-agents.md.C3pTrmoE.js +1 -0
  64. package/dist/docs/assets/scaffolding-agents.md.C3pTrmoE.lean.js +1 -0
  65. package/dist/docs/assets/storage.md.CVnInNiN.js +17 -0
  66. package/dist/docs/assets/storage.md.CVnInNiN.lean.js +1 -0
  67. package/dist/docs/building-with-agents.html +4 -4
  68. package/dist/docs/concepts.html +4 -4
  69. package/dist/docs/deployment.html +7 -7
  70. package/dist/docs/evals.html +7 -7
  71. package/dist/docs/guides/agent-to-agent.html +6 -6
  72. package/dist/docs/guides/cloud-runtime.html +5 -5
  73. package/dist/docs/guides/github.html +14 -7
  74. package/dist/docs/guides/human-in-the-loop.html +6 -6
  75. package/dist/docs/guides/slack.html +8 -8
  76. package/dist/docs/guides/webhooks.html +6 -6
  77. package/dist/docs/hashmap.json +1 -1
  78. package/dist/docs/hillclimbing.html +5 -5
  79. package/dist/docs/index.html +7 -7
  80. package/dist/docs/quickstart.html +195 -26
  81. package/dist/docs/reference/agent-config.html +7 -7
  82. package/dist/docs/reference/channels.html +8 -8
  83. package/dist/docs/reference/cli.html +14 -9
  84. package/dist/docs/reference/connections.html +5 -5
  85. package/dist/docs/reference/hooks.html +5 -5
  86. package/dist/docs/reference/http-api.html +6 -6
  87. package/dist/docs/reference/instructions.html +13 -11
  88. package/dist/docs/reference/playground.html +4 -4
  89. package/dist/docs/reference/project-layout.html +4 -4
  90. package/dist/docs/reference/schedules.html +7 -7
  91. package/dist/docs/reference/sessions.html +4 -4
  92. package/dist/docs/reference/skills.html +6 -6
  93. package/dist/docs/reference/subagents.html +6 -6
  94. package/dist/docs/reference/tools.html +7 -7
  95. package/dist/docs/scaffolding-agents.html +5 -5
  96. package/dist/docs/storage.html +41 -0
  97. package/dist/docs/troubleshooting.html +4 -4
  98. package/dist/index.d.ts +2 -0
  99. package/dist/index.d.ts.map +1 -1
  100. package/dist/index.js +1 -0
  101. package/dist/internal/chat-client.d.ts +29 -3
  102. package/dist/internal/chat-client.d.ts.map +1 -1
  103. package/dist/internal/chat-client.js +180 -27
  104. package/dist/internal/cli-ax.d.ts +75 -2
  105. package/dist/internal/cli-ax.d.ts.map +1 -1
  106. package/dist/internal/cli-ax.js +600 -52
  107. package/dist/internal/cli-cursor.d.ts.map +1 -1
  108. package/dist/internal/cli-cursor.js +8 -36
  109. package/dist/internal/cli-deploy.d.ts +108 -0
  110. package/dist/internal/cli-deploy.d.ts.map +1 -0
  111. package/dist/internal/cli-deploy.js +1009 -0
  112. package/dist/internal/cursor/backend-client.d.ts +10 -1
  113. package/dist/internal/cursor/backend-client.d.ts.map +1 -1
  114. package/dist/internal/cursor/backend-client.js +79 -1
  115. package/dist/internal/cursor/credentials.d.ts +9 -0
  116. package/dist/internal/cursor/credentials.d.ts.map +1 -1
  117. package/dist/internal/cursor/credentials.js +12 -0
  118. package/dist/internal/cursor/github-credentials.d.ts +44 -0
  119. package/dist/internal/cursor/github-credentials.d.ts.map +1 -0
  120. package/dist/internal/cursor/github-credentials.js +195 -0
  121. package/dist/internal/deploy-client.d.ts +184 -0
  122. package/dist/internal/deploy-client.d.ts.map +1 -0
  123. package/dist/internal/deploy-client.js +395 -0
  124. package/dist/internal/deploy-source.d.ts +35 -0
  125. package/dist/internal/deploy-source.d.ts.map +1 -0
  126. package/dist/internal/deploy-source.js +118 -0
  127. package/dist/internal/discovery.d.ts +11 -0
  128. package/dist/internal/discovery.d.ts.map +1 -1
  129. package/dist/internal/discovery.js +116 -19
  130. package/dist/internal/distribution.d.ts.map +1 -1
  131. package/dist/internal/distribution.js +1 -0
  132. package/dist/internal/eval-run-store.d.ts +22 -3
  133. package/dist/internal/eval-run-store.d.ts.map +1 -1
  134. package/dist/internal/eval-run-store.js +39 -20
  135. package/dist/internal/eval-runner.d.ts +2 -0
  136. package/dist/internal/eval-runner.d.ts.map +1 -1
  137. package/dist/internal/eval-runner.js +2 -0
  138. package/dist/internal/event-mapper.d.ts +54 -1
  139. package/dist/internal/event-mapper.d.ts.map +1 -1
  140. package/dist/internal/event-mapper.js +151 -41
  141. package/dist/internal/handleAgentServeTrigger.d.ts.map +1 -1
  142. package/dist/internal/handleAgentServeTrigger.js +10 -12
  143. package/dist/internal/host-platforms.d.ts +7 -2
  144. package/dist/internal/host-platforms.d.ts.map +1 -1
  145. package/dist/internal/host-platforms.js +15 -10
  146. package/dist/internal/hosting.d.ts +37 -0
  147. package/dist/internal/hosting.d.ts.map +1 -0
  148. package/dist/internal/hosting.js +67 -0
  149. package/dist/internal/init-project.d.ts +88 -1
  150. package/dist/internal/init-project.d.ts.map +1 -1
  151. package/dist/internal/init-project.js +221 -31
  152. package/dist/internal/install-cursor-skills.d.ts +64 -0
  153. package/dist/internal/install-cursor-skills.d.ts.map +1 -0
  154. package/dist/internal/install-cursor-skills.js +274 -0
  155. package/dist/internal/logs-client.d.ts +60 -0
  156. package/dist/internal/logs-client.d.ts.map +1 -0
  157. package/dist/internal/logs-client.js +311 -0
  158. package/dist/internal/open-browser.d.ts +5 -0
  159. package/dist/internal/open-browser.d.ts.map +1 -0
  160. package/dist/internal/open-browser.js +34 -0
  161. package/dist/internal/playground/toolchain.d.ts.map +1 -1
  162. package/dist/internal/playground/toolchain.js +16 -11
  163. package/dist/internal/playground-proxy.d.ts +69 -0
  164. package/dist/internal/playground-proxy.d.ts.map +1 -0
  165. package/dist/internal/playground-proxy.js +468 -0
  166. package/dist/internal/prompt-context.d.ts +35 -0
  167. package/dist/internal/prompt-context.d.ts.map +1 -0
  168. package/dist/internal/prompt-context.js +71 -0
  169. package/dist/internal/reminder-runner.d.ts +7 -0
  170. package/dist/internal/reminder-runner.d.ts.map +1 -1
  171. package/dist/internal/reminder-runner.js +50 -6
  172. package/dist/internal/reminder-store.d.ts +2 -0
  173. package/dist/internal/reminder-store.d.ts.map +1 -1
  174. package/dist/internal/reminder-store.js +18 -0
  175. package/dist/internal/request-headers.d.ts +11 -0
  176. package/dist/internal/request-headers.d.ts.map +1 -0
  177. package/dist/internal/request-headers.js +14 -0
  178. package/dist/internal/resolve-prod-target.d.ts +42 -0
  179. package/dist/internal/resolve-prod-target.d.ts.map +1 -0
  180. package/dist/internal/resolve-prod-target.js +111 -0
  181. package/dist/internal/run-client.d.ts +2 -2
  182. package/dist/internal/run-client.d.ts.map +1 -1
  183. package/dist/internal/run-client.js +38 -23
  184. package/dist/internal/server.d.ts.map +1 -1
  185. package/dist/internal/server.js +182 -45
  186. package/dist/internal/session-engine.d.ts +50 -1
  187. package/dist/internal/session-engine.d.ts.map +1 -1
  188. package/dist/internal/session-engine.js +267 -23
  189. package/dist/internal/sessions-client.d.ts +21 -0
  190. package/dist/internal/sessions-client.d.ts.map +1 -0
  191. package/dist/internal/sessions-client.js +168 -0
  192. package/dist/internal/storage-coordinator.d.ts +139 -0
  193. package/dist/internal/storage-coordinator.d.ts.map +1 -0
  194. package/dist/internal/storage-coordinator.js +499 -0
  195. package/dist/internal/stream-progress.d.ts.map +1 -1
  196. package/dist/internal/stream-progress.js +31 -3
  197. package/dist/internal/terminal-style.d.ts +22 -0
  198. package/dist/internal/terminal-style.d.ts.map +1 -0
  199. package/dist/internal/terminal-style.js +49 -0
  200. package/dist/internal/trajectory.d.ts +10 -5
  201. package/dist/internal/trajectory.d.ts.map +1 -1
  202. package/dist/internal/trajectory.js +82 -10
  203. package/dist/internal/workspace.d.ts +11 -0
  204. package/dist/internal/workspace.d.ts.map +1 -1
  205. package/dist/internal/workspace.js +38 -4
  206. package/dist/playground/assets/cursor-icons-outline-BxTT_FVJ.woff2 +0 -0
  207. package/dist/playground/assets/index-D-vo2lV_.css +1 -0
  208. package/dist/playground/assets/index-x60b9q2j.js +312 -0
  209. package/dist/playground/index.html +2 -2
  210. package/dist/storage.d.ts +204 -0
  211. package/dist/storage.d.ts.map +1 -0
  212. package/dist/storage.js +153 -0
  213. package/dist/types.d.ts +70 -4
  214. package/dist/types.d.ts.map +1 -1
  215. package/docs/README.md +3 -2
  216. package/docs/guides/github.md +43 -8
  217. package/docs/guides/slack.md +1 -1
  218. package/docs/quickstart.md +350 -57
  219. package/docs/reference/cli.md +51 -3
  220. package/docs/reference/instructions.md +8 -6
  221. package/docs/scaffolding-agents.md +1 -1
  222. package/docs/storage.md +98 -0
  223. package/package.json +10 -1
  224. package/skills/ab/SKILL.md +8 -8
  225. package/skills/create-agent/SKILL.md +28 -22
  226. package/skills/debug/SKILL.md +11 -11
  227. package/skills/evals/SKILL.md +16 -16
  228. package/skills/framework-map/SKILL.md +6 -6
  229. package/skills/github/SKILL.md +22 -14
  230. package/skills/hillclimb/SKILL.md +10 -10
  231. package/skills/setup-slack/SKILL.md +13 -13
  232. package/src/bin/agent-serve.ts +552 -179
  233. package/src/channels/github/api.ts +42 -23
  234. package/src/channels/github/cursor-account.ts +165 -0
  235. package/src/channels/github/github-channel.ts +66 -6
  236. package/src/channels/github/index.ts +2 -2
  237. package/src/channels/github/types.ts +19 -0
  238. package/src/channels/slack/slack-channel.ts +17 -3
  239. package/src/channels/slack/types.ts +44 -3
  240. package/src/index.ts +13 -0
  241. package/src/internal/chat-client.ts +252 -37
  242. package/src/internal/cli-ax.ts +722 -72
  243. package/src/internal/cli-cursor.ts +14 -42
  244. package/src/internal/cli-deploy.ts +1319 -0
  245. package/src/internal/cursor/backend-client.ts +103 -1
  246. package/src/internal/cursor/credentials.ts +14 -0
  247. package/src/internal/cursor/github-credentials.ts +248 -0
  248. package/src/internal/deploy-client.ts +632 -0
  249. package/src/internal/deploy-source.ts +133 -0
  250. package/src/internal/discovery.ts +141 -17
  251. package/src/internal/distribution.ts +1 -0
  252. package/src/internal/eval-run-store.ts +50 -20
  253. package/src/internal/eval-runner.ts +5 -0
  254. package/src/internal/event-mapper.ts +222 -42
  255. package/src/internal/handleAgentServeTrigger.ts +10 -12
  256. package/src/internal/host-platforms.ts +28 -11
  257. package/src/internal/hosting.ts +77 -0
  258. package/src/internal/init-project.ts +333 -51
  259. package/src/internal/install-cursor-skills.ts +327 -0
  260. package/src/internal/logs-client.ts +442 -0
  261. package/src/internal/open-browser.ts +41 -0
  262. package/src/internal/playground/toolchain.ts +15 -13
  263. package/src/internal/playground-proxy.ts +576 -0
  264. package/src/internal/prompt-context.ts +95 -0
  265. package/src/internal/reminder-runner.ts +50 -6
  266. package/src/internal/reminder-store.ts +21 -0
  267. package/src/internal/request-headers.ts +23 -0
  268. package/src/internal/resolve-prod-target.ts +150 -0
  269. package/src/internal/run-client.ts +39 -36
  270. package/src/internal/server.ts +223 -28
  271. package/src/internal/session-engine.ts +307 -10
  272. package/src/internal/sessions-client.ts +182 -0
  273. package/src/internal/storage-coordinator.ts +615 -0
  274. package/src/internal/stream-progress.ts +36 -2
  275. package/src/internal/terminal-style.ts +74 -0
  276. package/src/internal/trajectory.ts +91 -13
  277. package/src/internal/workspace.ts +42 -4
  278. package/src/storage.ts +325 -0
  279. package/src/types.ts +82 -8
  280. package/dist/docs/assets/chunks/@localSearchIndexroot.CcVk1uKq.js +0 -1
  281. package/dist/docs/assets/index.md.BPKcj5AI.js +0 -20
  282. package/dist/docs/assets/quickstart.md.tVPiGK_L.js +0 -35
  283. package/dist/docs/assets/quickstart.md.tVPiGK_L.lean.js +0 -1
  284. package/dist/docs/assets/scaffolding-agents.md.CyYfWGdc.js +0 -1
  285. package/dist/docs/assets/scaffolding-agents.md.CyYfWGdc.lean.js +0 -1
  286. package/dist/playground/assets/cursor-icons-outline-oY2V_mvK.woff2 +0 -0
  287. package/dist/playground/assets/index-1K-hG-7p.css +0 -1
  288. package/dist/playground/assets/index-FlWjhg3x.js +0 -79
  289. /package/dist/docs/assets/{evals.md.DPZ_MAnI.lean.js → evals.md.DAgEc_hL.lean.js} +0 -0
  290. /package/dist/docs/assets/{guides_agent-to-agent.md.CrtrsySy.lean.js → guides_agent-to-agent.md.Bpzgq2Pq.lean.js} +0 -0
  291. /package/dist/docs/assets/{guides_cloud-runtime.md.CYlNMTNp.lean.js → guides_cloud-runtime.md.gVzabdQL.lean.js} +0 -0
  292. /package/dist/docs/assets/{guides_human-in-the-loop.md.Dvuctx7s.lean.js → guides_human-in-the-loop.md.DlUqsp1S.lean.js} +0 -0
  293. /package/dist/docs/assets/{guides_webhooks.md.hFTik3lf.lean.js → guides_webhooks.md.B1EswtUu.lean.js} +0 -0
  294. /package/dist/docs/assets/{reference_connections.md.C3vNH_DE.lean.js → reference_connections.md.zaEYCLHT.lean.js} +0 -0
  295. /package/dist/docs/assets/{reference_http-api.md.DBAahtdz.lean.js → reference_http-api.md.Dx_nmDG6.lean.js} +0 -0
  296. /package/dist/docs/assets/{reference_schedules.md.D7qijxLk.lean.js → reference_schedules.md.w_F2mXB6.lean.js} +0 -0
  297. /package/dist/docs/assets/{reference_subagents.md.CIRAVcPK.lean.js → reference_subagents.md.zWAMNfi1.lean.js} +0 -0
  298. /package/dist/docs/assets/{reference_tools.md.DF5kwlt0.lean.js → reference_tools.md.CqgJroI0.lean.js} +0 -0
@@ -0,0 +1,632 @@
1
+ /**
2
+ * Thin client for the Agent Serve deployment management API
3
+ * (`/internal/agent-serve/deployments` on the Cursor backend). Pure
4
+ * request/response + error mapping — no console I/O, no polling loops;
5
+ * rendering lives in `cli-deploy.ts`.
6
+ *
7
+ * Auth is the user API key sent directly as the bearer (the routes are
8
+ * `wrapUserApiRoute` on the backend); there is no token exchange here.
9
+ * The endpoints are gated on the `agent_serve_mvp` Statsig gate and 404
10
+ * when it is off — the error mapping says so instead of "not found".
11
+ */
12
+
13
+ import { z } from "zod";
14
+ import {
15
+ MAX_SECRET_VALUE_BYTES,
16
+ MAX_SECRETS,
17
+ validateEgressDomain,
18
+ validateSettableSecretName,
19
+ } from "./hosting.js";
20
+
21
+ export type DeploymentStatus =
22
+ | "pending"
23
+ | "deploying"
24
+ | "running"
25
+ | "degraded"
26
+ | "failed"
27
+ | "stopping"
28
+ | "stopped";
29
+
30
+ /** Customer-safe deploy progress (no hosting phase / infra names). */
31
+ export type DeploymentProgress =
32
+ | "queued"
33
+ | "preparing"
34
+ | "building"
35
+ | "finalizing"
36
+ | "running"
37
+ | "failed"
38
+ | "stopping"
39
+ | "stopped"
40
+ | "degraded";
41
+
42
+ export const TERMINAL_DEPLOY_STATUSES: ReadonlySet<DeploymentStatus> = new Set([
43
+ "running",
44
+ "degraded",
45
+ "failed",
46
+ "stopped",
47
+ ]);
48
+
49
+ /**
50
+ * What gets deployed. Today the control plane builds the engine itself from
51
+ * a git ref (or serves the static placeholder when no repo is given), so the
52
+ * only member is the slug/git-ref shape. When artifact-based deploys ship
53
+ * ("build locally + upload"), add an `{ kind: "artifact", ... }` member here
54
+ * and a branch in {@link AgentServeDeployClient.deploy} — the command
55
+ * surface and everything downstream stays unchanged.
56
+ */
57
+ export type DeploySource = {
58
+ kind: "git-ref";
59
+ /** Omit for the control-plane static engine (`static-http-200`). */
60
+ gitRepoUrl?: string;
61
+ gitRef?: string;
62
+ agentPath?: string;
63
+ /** Repos whose SCM events the deployed engine pulls (`owner/name`). */
64
+ cursorEventRepos?: string[];
65
+ /**
66
+ * Egress allowlist for the engine pod. Only valid on repo-backed
67
+ * deploys — the backend 400s when set on a static deploy.
68
+ */
69
+ egressAllowedDomains?: string[];
70
+ };
71
+
72
+ const SLUG_PATTERN = /^[a-z0-9_-]{1,64}$/;
73
+
74
+ /** Returns a human error message, or undefined when the slug is valid. */
75
+ export function validateDeploymentSlug(slug: string): string | undefined {
76
+ if (SLUG_PATTERN.test(slug)) {
77
+ return undefined;
78
+ }
79
+ return `Invalid slug ${JSON.stringify(slug)}: use lowercase letters, digits, '-' or '_' (max 64 chars)`;
80
+ }
81
+
82
+ /** Derive a valid slug from a directory name, or undefined if impossible. */
83
+ export function slugFromDirectoryName(name: string): string | undefined {
84
+ const slug = name
85
+ .toLowerCase()
86
+ .replace(/[^a-z0-9_-]+/g, "-")
87
+ .replace(/^-+|-+$/g, "")
88
+ .slice(0, 64);
89
+ return SLUG_PATTERN.test(slug) ? slug : undefined;
90
+ }
91
+
92
+ export class DeployApiError extends Error {
93
+ constructor(
94
+ message: string,
95
+ readonly status: number,
96
+ /** Seconds to wait before retrying (from `Retry-After` on 429s). */
97
+ readonly retryAfterSeconds?: number
98
+ ) {
99
+ super(message);
100
+ this.name = "DeployApiError";
101
+ }
102
+ }
103
+
104
+ // ============================================================================
105
+ // Response shapes (backend `serializeDeployment` + route-specific bodies).
106
+ // Interfaces are hand-written (the package compiles with
107
+ // --isolatedDeclarations, so exported types cannot be z.infer of an
108
+ // unannotated schema); the zod schemas below stay module-internal.
109
+ // ============================================================================
110
+
111
+ export interface DeployAccepted {
112
+ id: number;
113
+ slug: string;
114
+ teamId: number;
115
+ status: string;
116
+ generation: number;
117
+ deploymentKind: string;
118
+ engineAlias: string;
119
+ /** Present exactly once, on the deploy that minted the record. */
120
+ aliasToken?: string;
121
+ }
122
+
123
+ export interface Deployment {
124
+ id: number;
125
+ slug: string;
126
+ teamId: number;
127
+ deploymentKind: string;
128
+ gitRepoUrl?: string | null;
129
+ gitRef?: string;
130
+ agentPath?: string;
131
+ desiredState?: string;
132
+ status: DeploymentStatus;
133
+ /**
134
+ * Customer-safe deploy progress (no hosting internals). Present on newer
135
+ * backends; older responses omit it.
136
+ */
137
+ progress?: DeploymentProgress;
138
+ generation: number;
139
+ observedGeneration?: number | null;
140
+ engineGeneration?: number | null;
141
+ publicId?: string;
142
+ engineUrl?: string | null;
143
+ lastError?: string | null;
144
+ engineAlias: string;
145
+ desiredUpdatedAt?: string;
146
+ lastReconciledAt?: string | null;
147
+ /** SCM-event repos configured on the deployment (`owner/name`). */
148
+ cursorEventRepos?: string[];
149
+ /** Normalized egress allowlist for the engine pod. */
150
+ egressAllowedDomains?: string[];
151
+ /** Service-account id (`sa_…`); null on legacy rows. */
152
+ serviceAccountId?: string | number | null;
153
+ /** Masked pod credential; the raw key is never returned. */
154
+ podCredentialMaskedKey?: string | null;
155
+ /** Names of the secrets set on the deployment (values never returned). */
156
+ secretNames?: string[];
157
+ }
158
+
159
+ /** Short-lived direct pod access minted by the status route. */
160
+ export interface EngineAccess {
161
+ url: string;
162
+ headers: Record<string, string>;
163
+ expiresAt: string;
164
+ }
165
+
166
+ export interface DeploymentDetail extends Deployment {
167
+ engineAccess?: EngineAccess | null;
168
+ }
169
+
170
+ export interface StopAccepted {
171
+ id: number;
172
+ status: string;
173
+ }
174
+
175
+ /** One secret's metadata from the list endpoint — names only, never values. */
176
+ export interface SecretInfo {
177
+ name: string;
178
+ createdAt: string;
179
+ }
180
+
181
+ // All response schemas are `.passthrough()`: the backend keeps growing the
182
+ // deployment payload (serviceAccountId, egressAllowedDomains, secret
183
+ // metadata, ...) and unknown fields must flow through untouched — both so
184
+ // parsing never breaks on a newer backend and so `--json` output stays
185
+ // faithful to the API instead of silently dropping fields.
186
+ const deployAcceptedSchema = z
187
+ .object({
188
+ id: z.number(),
189
+ slug: z.string(),
190
+ teamId: z.number(),
191
+ status: z.string(),
192
+ generation: z.number(),
193
+ deploymentKind: z.string(),
194
+ engineAlias: z.string(),
195
+ aliasToken: z.string().optional(),
196
+ })
197
+ .passthrough();
198
+
199
+ const deploymentSchema = z.object({
200
+ id: z.number(),
201
+ slug: z.string(),
202
+ teamId: z.number(),
203
+ deploymentKind: z.string(),
204
+ gitRepoUrl: z.string().nullable().optional(),
205
+ gitRef: z.string().optional(),
206
+ agentPath: z.string().optional(),
207
+ desiredState: z.string().optional(),
208
+ status: z.enum([
209
+ "pending",
210
+ "deploying",
211
+ "running",
212
+ "degraded",
213
+ "failed",
214
+ "stopping",
215
+ "stopped",
216
+ ]),
217
+ progress: z
218
+ .enum([
219
+ "queued",
220
+ "preparing",
221
+ "building",
222
+ "finalizing",
223
+ "running",
224
+ "failed",
225
+ "stopping",
226
+ "stopped",
227
+ "degraded",
228
+ ])
229
+ .optional(),
230
+ generation: z.number(),
231
+ observedGeneration: z.number().nullable().optional(),
232
+ engineGeneration: z.number().nullable().optional(),
233
+ publicId: z.string().optional(),
234
+ engineUrl: z.string().nullable().optional(),
235
+ lastError: z.string().nullable().optional(),
236
+ engineAlias: z.string(),
237
+ desiredUpdatedAt: z.string().optional(),
238
+ lastReconciledAt: z.string().nullable().optional(),
239
+ cursorEventRepos: z.array(z.string()).optional(),
240
+ egressAllowedDomains: z.array(z.string()).optional(),
241
+ // String ids (`sa_…`) in prod; older mocks/fixtures used numbers. Null on
242
+ // legacy rows that predate service-account-backed deploys.
243
+ serviceAccountId: z.union([z.string(), z.number()]).nullable().optional(),
244
+ podCredentialMaskedKey: z.string().nullable().optional(),
245
+ secretNames: z.array(z.string()).optional(),
246
+ });
247
+
248
+ const deploymentListItemSchema = deploymentSchema.passthrough();
249
+
250
+ const deploymentDetailSchema = deploymentSchema
251
+ .extend({
252
+ engineAccess: z
253
+ .object({
254
+ url: z.string(),
255
+ headers: z.record(z.string()),
256
+ expiresAt: z.string(),
257
+ })
258
+ .nullable()
259
+ .optional(),
260
+ })
261
+ .passthrough();
262
+
263
+ const listResponseSchema = z.object({
264
+ deployments: z.array(deploymentListItemSchema),
265
+ });
266
+
267
+ const stopAcceptedSchema = z
268
+ .object({
269
+ id: z.number(),
270
+ status: z.string(),
271
+ })
272
+ .passthrough();
273
+
274
+ const rotateResponseSchema = z
275
+ .object({
276
+ aliasToken: z.string().min(1),
277
+ })
278
+ .passthrough();
279
+
280
+ const rotatePodCredentialResponseSchema = z
281
+ .object({
282
+ podCredentialMaskedKey: z.string().min(1),
283
+ })
284
+ .passthrough();
285
+
286
+ const setSecretsResponseSchema = z
287
+ .object({
288
+ secretNames: z.array(z.string()),
289
+ })
290
+ .passthrough();
291
+
292
+ const listSecretsResponseSchema = z
293
+ .object({
294
+ secrets: z.array(
295
+ z.object({ name: z.string(), createdAt: z.string() }).passthrough()
296
+ ),
297
+ })
298
+ .passthrough();
299
+
300
+ // ============================================================================
301
+ // Client
302
+ // ============================================================================
303
+
304
+ export interface AgentServeDeployClientOptions {
305
+ backendUrl: string;
306
+ apiKey: string;
307
+ /** Test seam; defaults to global fetch. */
308
+ fetchImpl?: typeof fetch;
309
+ }
310
+
311
+ export class AgentServeDeployClient {
312
+ private readonly backendUrl: string;
313
+ private readonly apiKey: string;
314
+ private readonly fetchImpl: typeof fetch;
315
+
316
+ constructor(options: AgentServeDeployClientOptions) {
317
+ this.backendUrl = options.backendUrl.endsWith("/")
318
+ ? options.backendUrl.slice(0, -1)
319
+ : options.backendUrl;
320
+ this.apiKey = options.apiKey;
321
+ this.fetchImpl = options.fetchImpl ?? fetch;
322
+ }
323
+
324
+ /** Create or redeploy; 202 means accepted, not running (poll status). */
325
+ async deploy(args: {
326
+ teamId: number;
327
+ slug: string;
328
+ source: DeploySource;
329
+ }): Promise<DeployAccepted> {
330
+ const slugError = validateDeploymentSlug(args.slug);
331
+ if (slugError !== undefined) {
332
+ throw new DeployApiError(slugError, 400);
333
+ }
334
+ for (const domain of args.source.egressAllowedDomains ?? []) {
335
+ const domainError = validateEgressDomain(domain);
336
+ if (domainError !== undefined) {
337
+ throw new DeployApiError(domainError, 400);
338
+ }
339
+ }
340
+ // Only the git-ref member exists today; a future artifact member would
341
+ // upload the build first and post a different body from this branch.
342
+ const body: Record<string, unknown> = {
343
+ teamId: args.teamId,
344
+ slug: args.slug,
345
+ ...(args.source.gitRepoUrl === undefined
346
+ ? {}
347
+ : { gitRepoUrl: args.source.gitRepoUrl }),
348
+ ...(args.source.gitRef === undefined
349
+ ? {}
350
+ : { gitRef: args.source.gitRef }),
351
+ ...(args.source.agentPath === undefined
352
+ ? {}
353
+ : { agentPath: args.source.agentPath }),
354
+ ...(args.source.cursorEventRepos === undefined
355
+ ? {}
356
+ : { cursorEventRepos: args.source.cursorEventRepos }),
357
+ ...(args.source.egressAllowedDomains === undefined
358
+ ? {}
359
+ : { egressAllowedDomains: args.source.egressAllowedDomains }),
360
+ };
361
+ const raw = await this.request({
362
+ method: "POST",
363
+ path: "/internal/agent-serve/deployments",
364
+ body,
365
+ context: { verb: "deploy", slug: args.slug },
366
+ });
367
+ return deployAcceptedSchema.parse(raw);
368
+ }
369
+
370
+ async listDeployments(args: { teamId: number }): Promise<Deployment[]> {
371
+ const raw = await this.request({
372
+ method: "GET",
373
+ path: `/internal/agent-serve/deployments?teamId=${args.teamId}`,
374
+ context: { verb: "list deployments" },
375
+ });
376
+ return listResponseSchema.parse(raw).deployments;
377
+ }
378
+
379
+ async getDeployment(args: {
380
+ teamId: number;
381
+ slug: string;
382
+ }): Promise<DeploymentDetail> {
383
+ const raw = await this.request({
384
+ method: "GET",
385
+ path: `/internal/agent-serve/deployments/${encodeURIComponent(args.slug)}?teamId=${args.teamId}`,
386
+ context: { verb: "get deployment", slug: args.slug },
387
+ });
388
+ return deploymentDetailSchema.parse(raw);
389
+ }
390
+
391
+ async stopDeployment(args: {
392
+ teamId: number;
393
+ slug: string;
394
+ }): Promise<StopAccepted> {
395
+ const raw = await this.request({
396
+ method: "POST",
397
+ path: `/internal/agent-serve/deployments/${encodeURIComponent(args.slug)}/stop?teamId=${args.teamId}`,
398
+ context: { verb: "stop", slug: args.slug },
399
+ });
400
+ return stopAcceptedSchema.parse(raw);
401
+ }
402
+
403
+ /** Returns the new alias token exactly once; the old one dies now. */
404
+ async rotateAliasToken(args: {
405
+ teamId: number;
406
+ slug: string;
407
+ }): Promise<string> {
408
+ const raw = await this.request({
409
+ method: "POST",
410
+ path: `/internal/agent-serve/deployments/${encodeURIComponent(args.slug)}/rotate-alias-token?teamId=${args.teamId}`,
411
+ context: { verb: "rotate alias token", slug: args.slug },
412
+ });
413
+ return rotateResponseSchema.parse(raw).aliasToken;
414
+ }
415
+
416
+ /**
417
+ * Upsert secrets by name (unlisted names stay untouched). Returns the
418
+ * post-write union of secret names, sorted. Validates names and value
419
+ * sizes client-side with the backend's grammar before any network call.
420
+ */
421
+ async setSecrets(args: {
422
+ teamId: number;
423
+ slug: string;
424
+ secrets: Array<{ name: string; value: string }>;
425
+ }): Promise<string[]> {
426
+ for (const { name, value } of args.secrets) {
427
+ const nameError = validateSettableSecretName(name);
428
+ if (nameError !== undefined) {
429
+ throw new DeployApiError(nameError, 400);
430
+ }
431
+ if (Buffer.byteLength(value, "utf8") > MAX_SECRET_VALUE_BYTES) {
432
+ throw new DeployApiError(
433
+ `The value for ${name} is too large (max ${MAX_SECRET_VALUE_BYTES} bytes).`,
434
+ 400
435
+ );
436
+ }
437
+ }
438
+ if (args.secrets.length > MAX_SECRETS) {
439
+ throw new DeployApiError(
440
+ `Too many secrets in one request (${args.secrets.length}); deployments hold at most ${MAX_SECRETS}.`,
441
+ 400
442
+ );
443
+ }
444
+ const raw = await this.request({
445
+ method: "PUT",
446
+ path: `/internal/agent-serve/deployments/${encodeURIComponent(args.slug)}/secrets`,
447
+ body: { teamId: args.teamId, secrets: args.secrets },
448
+ context: { verb: "set secrets", slug: args.slug },
449
+ });
450
+ return setSecretsResponseSchema.parse(raw).secretNames;
451
+ }
452
+
453
+ /** Secret names + creation times; values are never returned. */
454
+ async listSecrets(args: {
455
+ teamId: number;
456
+ slug: string;
457
+ }): Promise<SecretInfo[]> {
458
+ const raw = await this.request({
459
+ method: "GET",
460
+ path: `/internal/agent-serve/deployments/${encodeURIComponent(args.slug)}/secrets?teamId=${args.teamId}`,
461
+ context: { verb: "list secrets", slug: args.slug },
462
+ });
463
+ return listSecretsResponseSchema.parse(raw).secrets;
464
+ }
465
+
466
+ /** Remove one secret by name; 404 when it is not set. */
467
+ async deleteSecret(args: {
468
+ teamId: number;
469
+ slug: string;
470
+ name: string;
471
+ }): Promise<void> {
472
+ const nameError = validateSettableSecretName(args.name);
473
+ if (nameError !== undefined) {
474
+ throw new DeployApiError(nameError, 400);
475
+ }
476
+ await this.request({
477
+ method: "DELETE",
478
+ path: `/internal/agent-serve/deployments/${encodeURIComponent(args.slug)}/secrets/${encodeURIComponent(args.name)}?teamId=${args.teamId}`,
479
+ context: { verb: "unset secret", slug: args.slug },
480
+ });
481
+ }
482
+
483
+ /**
484
+ * Rotate the deployment's pod credential. Returns the masked new key —
485
+ * the raw key is injected into the pod on the next deploy, never
486
+ * returned to clients.
487
+ */
488
+ async rotatePodCredential(args: {
489
+ teamId: number;
490
+ slug: string;
491
+ }): Promise<string> {
492
+ const raw = await this.request({
493
+ method: "POST",
494
+ path: `/internal/agent-serve/deployments/${encodeURIComponent(args.slug)}/rotate-pod-credential?teamId=${args.teamId}`,
495
+ context: { verb: "rotate pod credential", slug: args.slug },
496
+ });
497
+ return rotatePodCredentialResponseSchema.parse(raw).podCredentialMaskedKey;
498
+ }
499
+
500
+ /** Full URL of the stable engine alias for a deployment. */
501
+ aliasUrl(engineAlias: string): string {
502
+ return `${this.backendUrl}${engineAlias}`;
503
+ }
504
+
505
+ private async request(args: {
506
+ method: "GET" | "POST" | "PUT" | "DELETE";
507
+ path: string;
508
+ body?: unknown;
509
+ context: { verb: string; slug?: string };
510
+ }): Promise<unknown> {
511
+ let response: Response;
512
+ try {
513
+ response = await this.fetchImpl(`${this.backendUrl}${args.path}`, {
514
+ method: args.method,
515
+ headers: {
516
+ accept: "application/json",
517
+ authorization: `Bearer ${this.apiKey}`,
518
+ ...(args.body === undefined
519
+ ? {}
520
+ : { "content-type": "application/json" }),
521
+ },
522
+ ...(args.body === undefined ? {} : { body: JSON.stringify(args.body) }),
523
+ signal: AbortSignal.timeout(60_000),
524
+ });
525
+ } catch (error) {
526
+ throw new DeployApiError(
527
+ `Could not reach the Cursor backend at ${this.backendUrl}: ${
528
+ error instanceof Error ? error.message : String(error)
529
+ }`,
530
+ 0
531
+ );
532
+ }
533
+ const text = await response.text();
534
+ if (!response.ok) {
535
+ throw mapErrorResponse(response, text, args.context);
536
+ }
537
+ try {
538
+ return JSON.parse(text) as unknown;
539
+ } catch {
540
+ throw new DeployApiError(
541
+ `The Cursor backend returned a non-JSON response to ${args.context.verb}.`,
542
+ response.status
543
+ );
544
+ }
545
+ }
546
+ }
547
+
548
+ // ============================================================================
549
+ // Error mapping (HTTP → actionable human messages)
550
+ // ============================================================================
551
+
552
+ function serverErrorText(bodyText: string): string | undefined {
553
+ try {
554
+ const parsed = JSON.parse(bodyText) as { error?: unknown };
555
+ if (typeof parsed.error === "string" && parsed.error !== "") {
556
+ return parsed.error;
557
+ }
558
+ } catch {
559
+ // Non-JSON body — fall through.
560
+ }
561
+ return undefined;
562
+ }
563
+
564
+ function mapErrorResponse(
565
+ response: Response,
566
+ bodyText: string,
567
+ context: { verb: string; slug?: string }
568
+ ): DeployApiError {
569
+ const serverError = serverErrorText(bodyText);
570
+ const slugPart = context.slug === undefined ? "" : ` "${context.slug}"`;
571
+ switch (response.status) {
572
+ case 400:
573
+ return new DeployApiError(
574
+ serverError ?? `The ${context.verb} request was rejected as invalid.`,
575
+ 400
576
+ );
577
+ case 401:
578
+ return new DeployApiError(
579
+ "The Cursor API key was rejected. Run `agentkit login` again or update CURSOR_API_KEY.",
580
+ 401
581
+ );
582
+ case 403:
583
+ return new DeployApiError(
584
+ `${serverError ?? "Not authorized"} — deploying needs team-admin permission and the cloud-agent entitlement on that team.`,
585
+ 403
586
+ );
587
+ case 404: {
588
+ // Fastify's route-not-found envelope means we hit the wrong host
589
+ // (api2 vs api.cursor.com), not a missing deployment / closed gate.
590
+ if (/Route \S+ not found/i.test(bodyText)) {
591
+ return new DeployApiError(
592
+ `Agent Serve deploy API not found on this host — use the default api.cursor.com (unset CURSOR_API_BASE_URL), or point CURSOR_API_BASE_URL at a backend that mounts /internal/agent-serve/*.`,
593
+ 404
594
+ );
595
+ }
596
+ return new DeployApiError(
597
+ context.slug === undefined
598
+ ? `Not found — the agent_serve_mvp feature gate may not be enabled for your team.`
599
+ : `Deployment${slugPart} was not found — check the slug and --team, or the agent_serve_mvp feature gate may not be enabled for your team.`,
600
+ 404
601
+ );
602
+ }
603
+ case 409:
604
+ return new DeployApiError(
605
+ `A concurrent deploy or stop is changing deployment${slugPart}; retry in a moment.`,
606
+ 409
607
+ );
608
+ case 429: {
609
+ const retryAfterHeader = response.headers.get("retry-after");
610
+ const retryAfterSeconds =
611
+ retryAfterHeader !== null && /^\d+$/.test(retryAfterHeader)
612
+ ? Number(retryAfterHeader)
613
+ : undefined;
614
+ return new DeployApiError(
615
+ `${serverError ?? "Rate limited"}${
616
+ retryAfterSeconds === undefined
617
+ ? ""
618
+ : ` — retry in ${retryAfterSeconds}s`
619
+ }`,
620
+ 429,
621
+ retryAfterSeconds
622
+ );
623
+ }
624
+ default:
625
+ return new DeployApiError(
626
+ `The ${context.verb} request failed (${response.status}): ${
627
+ serverError ?? bodyText.slice(0, 300) ?? "(empty body)"
628
+ }`,
629
+ response.status
630
+ );
631
+ }
632
+ }