@cursor/july 0.1.26 → 0.1.28

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 (324) hide show
  1. package/dist/ab.d.ts +6 -0
  2. package/dist/ab.d.ts.map +1 -1
  3. package/dist/ab.js +1 -0
  4. package/dist/artifacts.d.ts +34 -0
  5. package/dist/artifacts.d.ts.map +1 -0
  6. package/dist/artifacts.js +57 -0
  7. package/dist/bin/agent-serve.js +43 -12
  8. package/dist/channels/github/github-channel.d.ts +1 -1
  9. package/dist/channels/github/github-channel.d.ts.map +1 -1
  10. package/dist/channels/github/github-channel.js +14 -1
  11. package/dist/channels/github/types.d.ts +6 -1
  12. package/dist/channels/github/types.d.ts.map +1 -1
  13. package/dist/channels/slack/api.d.ts +2 -1
  14. package/dist/channels/slack/api.d.ts.map +1 -1
  15. package/dist/channels/slack/api.js +1 -0
  16. package/dist/channels/slack/auth.d.ts +13 -13
  17. package/dist/channels/slack/auth.d.ts.map +1 -1
  18. package/dist/channels/slack/auth.js +19 -10
  19. package/dist/channels/slack/cursor-account.d.ts +2 -1
  20. package/dist/channels/slack/cursor-account.d.ts.map +1 -1
  21. package/dist/channels/slack/cursor-account.js +3 -1
  22. package/dist/channels/slack/defaults.d.ts +7 -4
  23. package/dist/channels/slack/defaults.d.ts.map +1 -1
  24. package/dist/channels/slack/defaults.js +14 -4
  25. package/dist/channels/slack/dispatch.d.ts +10 -1
  26. package/dist/channels/slack/dispatch.d.ts.map +1 -1
  27. package/dist/channels/slack/dispatch.js +59 -21
  28. package/dist/channels/slack/external-policy.d.ts +27 -0
  29. package/dist/channels/slack/external-policy.d.ts.map +1 -0
  30. package/dist/channels/slack/external-policy.js +53 -0
  31. package/dist/channels/slack/index.d.ts +1 -0
  32. package/dist/channels/slack/index.d.ts.map +1 -1
  33. package/dist/channels/slack/index.js +1 -0
  34. package/dist/channels/slack/interactive.d.ts +8 -1
  35. package/dist/channels/slack/interactive.d.ts.map +1 -1
  36. package/dist/channels/slack/interactive.js +43 -15
  37. package/dist/channels/slack/slack-channel.d.ts.map +1 -1
  38. package/dist/channels/slack/slack-channel.js +22 -8
  39. package/dist/channels/slack/types.d.ts +16 -1
  40. package/dist/channels/slack/types.d.ts.map +1 -1
  41. package/dist/docs/404.html +2 -2
  42. package/dist/docs/ab.html +3 -3
  43. package/dist/docs/assets/{app.DYcC9FY-.js → app.CqjrYaT2.js} +1 -1
  44. package/dist/docs/assets/chunks/@localSearchIndexroot.VWQoPFJ1.js +1 -0
  45. package/dist/docs/assets/chunks/{VPLocalSearchBox.o4N_knTV.js → VPLocalSearchBox.ag-MwUel.js} +1 -1
  46. package/dist/docs/assets/chunks/{theme.DQ-njyo0.js → theme.BS-DJWat.js} +2 -2
  47. package/dist/docs/assets/{guides_slack.md.D_xFKlnF.js → guides_slack.md.CjmJSvZS.js} +8 -4
  48. package/dist/docs/assets/guides_slack.md.CjmJSvZS.lean.js +1 -0
  49. package/dist/docs/assets/guides_webhooks.md.wSOYas3X.js +183 -0
  50. package/dist/docs/assets/{guides_webhooks.md.B1EswtUu.lean.js → guides_webhooks.md.wSOYas3X.lean.js} +1 -1
  51. package/dist/docs/assets/{index.md.Dfv5ic9t.js → index.md.CH_s5uZe.js} +1 -1
  52. package/dist/docs/assets/{reference_channels.md.DdmiKgqf.js → reference_channels.md.CDhTRfUz.js} +2 -2
  53. package/dist/docs/assets/{reference_channels.md.DdmiKgqf.lean.js → reference_channels.md.CDhTRfUz.lean.js} +1 -1
  54. package/dist/docs/building-with-agents.html +3 -3
  55. package/dist/docs/concepts.html +3 -3
  56. package/dist/docs/deployment.html +3 -3
  57. package/dist/docs/evals.html +3 -3
  58. package/dist/docs/example-agents/approval-buddy.html +3 -3
  59. package/dist/docs/example-agents/benny.html +3 -3
  60. package/dist/docs/example-agents/bugbot.html +3 -3
  61. package/dist/docs/example-agents/codebase-wiki.html +3 -3
  62. package/dist/docs/example-agents/codeowners-review.html +3 -3
  63. package/dist/docs/example-agents/concierge.html +3 -3
  64. package/dist/docs/example-agents/fsd.html +3 -3
  65. package/dist/docs/example-agents/index.html +3 -3
  66. package/dist/docs/example-agents/knowledge-base.html +3 -3
  67. package/dist/docs/example-agents/oncall.html +3 -3
  68. package/dist/docs/example-agents/security-reviewer.html +3 -3
  69. package/dist/docs/example-agents/slack-agent.html +3 -3
  70. package/dist/docs/example-agents/weather-agent.html +3 -3
  71. package/dist/docs/guides/agent-to-agent.html +3 -3
  72. package/dist/docs/guides/cloud-runtime.html +3 -3
  73. package/dist/docs/guides/github.html +3 -3
  74. package/dist/docs/guides/human-in-the-loop.html +3 -3
  75. package/dist/docs/guides/mcp-oauth.html +3 -3
  76. package/dist/docs/guides/slack.html +11 -7
  77. package/dist/docs/guides/webhooks.html +138 -5
  78. package/dist/docs/hashmap.json +1 -1
  79. package/dist/docs/hillclimbing.html +3 -3
  80. package/dist/docs/index.html +5 -5
  81. package/dist/docs/quickstart.html +3 -3
  82. package/dist/docs/reference/agent-config.html +3 -3
  83. package/dist/docs/reference/channels.html +5 -5
  84. package/dist/docs/reference/cli.html +3 -3
  85. package/dist/docs/reference/connections.html +3 -3
  86. package/dist/docs/reference/hooks.html +3 -3
  87. package/dist/docs/reference/http-api.html +3 -3
  88. package/dist/docs/reference/instructions.html +3 -3
  89. package/dist/docs/reference/playground.html +3 -3
  90. package/dist/docs/reference/project-layout.html +3 -3
  91. package/dist/docs/reference/prompt.html +3 -3
  92. package/dist/docs/reference/schedules.html +3 -3
  93. package/dist/docs/reference/sessions.html +3 -3
  94. package/dist/docs/reference/skills.html +3 -3
  95. package/dist/docs/reference/subagents.html +3 -3
  96. package/dist/docs/reference/tools.html +3 -3
  97. package/dist/docs/scaffolding-agents.html +3 -3
  98. package/dist/docs/storage.html +3 -3
  99. package/dist/docs/troubleshooting.html +3 -3
  100. package/dist/evals/assertions.d.ts +10 -1
  101. package/dist/evals/assertions.d.ts.map +1 -1
  102. package/dist/evals/assertions.js +12 -0
  103. package/dist/evals.d.ts +1 -1
  104. package/dist/evals.d.ts.map +1 -1
  105. package/dist/index.d.ts +1 -0
  106. package/dist/index.d.ts.map +1 -1
  107. package/dist/index.js +1 -0
  108. package/dist/internal/ab-fold.d.ts.map +1 -1
  109. package/dist/internal/ab-fold.js +4 -0
  110. package/dist/internal/ab-snapshot.d.ts.map +1 -1
  111. package/dist/internal/ab-snapshot.js +1 -0
  112. package/dist/internal/artifacts-store.d.ts +45 -0
  113. package/dist/internal/artifacts-store.d.ts.map +1 -0
  114. package/dist/internal/artifacts-store.js +250 -0
  115. package/dist/internal/builtin-tools/artifacts.d.ts +10 -0
  116. package/dist/internal/builtin-tools/artifacts.d.ts.map +1 -0
  117. package/dist/internal/builtin-tools/artifacts.js +73 -0
  118. package/dist/internal/builtin-tools/index.d.ts +8 -1
  119. package/dist/internal/builtin-tools/index.d.ts.map +1 -1
  120. package/dist/internal/builtin-tools/index.js +15 -0
  121. package/dist/internal/cli-ax.d.ts +19 -0
  122. package/dist/internal/cli-ax.d.ts.map +1 -1
  123. package/dist/internal/cli-ax.js +196 -57
  124. package/dist/internal/cli-slack.d.ts.map +1 -1
  125. package/dist/internal/cli-slack.js +14 -6
  126. package/dist/internal/cursor-slack-relay.d.ts +2 -0
  127. package/dist/internal/cursor-slack-relay.d.ts.map +1 -1
  128. package/dist/internal/cursor-slack-relay.js +1 -0
  129. package/dist/internal/deploy-client.d.ts +2 -0
  130. package/dist/internal/deploy-client.d.ts.map +1 -1
  131. package/dist/internal/deploy-client.js +1 -0
  132. package/dist/internal/discovery.d.ts.map +1 -1
  133. package/dist/internal/discovery.js +91 -3
  134. package/dist/internal/distribution.d.ts.map +1 -1
  135. package/dist/internal/distribution.js +1 -0
  136. package/dist/internal/model-pricing.d.ts +49 -0
  137. package/dist/internal/model-pricing.d.ts.map +1 -0
  138. package/dist/internal/model-pricing.js +377 -0
  139. package/dist/internal/reminder-runner.d.ts.map +1 -1
  140. package/dist/internal/reminder-runner.js +1 -0
  141. package/dist/internal/schedule-runner.d.ts.map +1 -1
  142. package/dist/internal/schedule-runner.js +1 -0
  143. package/dist/internal/sdk-runner.d.ts.map +1 -1
  144. package/dist/internal/sdk-runner.js +9 -1
  145. package/dist/internal/server.d.ts.map +1 -1
  146. package/dist/internal/server.js +49 -5
  147. package/dist/internal/session-cost.d.ts +49 -0
  148. package/dist/internal/session-cost.d.ts.map +1 -0
  149. package/dist/internal/session-cost.js +175 -0
  150. package/dist/internal/session-engine.d.ts +35 -1
  151. package/dist/internal/session-engine.d.ts.map +1 -1
  152. package/dist/internal/session-engine.js +128 -7
  153. package/dist/internal/storage-coordinator.d.ts +15 -0
  154. package/dist/internal/storage-coordinator.d.ts.map +1 -1
  155. package/dist/internal/storage-coordinator.js +52 -0
  156. package/dist/internal/trajectory.d.ts +9 -1
  157. package/dist/internal/trajectory.d.ts.map +1 -1
  158. package/dist/internal/trajectory.js +32 -5
  159. package/dist/playground/assets/index-Bul1WfrB.css +1 -0
  160. package/dist/playground/assets/index-CkN74U_L.js +87 -0
  161. package/dist/playground/index.html +2 -2
  162. package/dist/storage.d.ts +4 -0
  163. package/dist/storage.d.ts.map +1 -1
  164. package/dist/storage.js +4 -0
  165. package/dist/types.d.ts +164 -1
  166. package/dist/types.d.ts.map +1 -1
  167. package/docs/README.md +1 -0
  168. package/docs/guides/slack.md +32 -7
  169. package/docs/guides/webhooks.md +183 -0
  170. package/docs/reference/channels.md +2 -1
  171. package/package.json +26 -26
  172. package/skills/setup-slack/SKILL.md +3 -0
  173. package/src/ab.ts +7 -0
  174. package/src/bin/agent-serve.ts +42 -5
  175. package/src/channels/slack/auth.ts +29 -22
  176. package/src/channels/slack/cursor-account.ts +2 -0
  177. package/src/channels/slack/defaults.ts +24 -4
  178. package/src/channels/slack/dispatch.ts +42 -1
  179. package/src/channels/slack/external-policy.ts +62 -0
  180. package/src/channels/slack/index.ts +1 -0
  181. package/src/channels/slack/interactive.ts +42 -10
  182. package/src/channels/slack/slack-channel.ts +20 -3
  183. package/src/channels/slack/types.ts +12 -0
  184. package/src/internal/ab-fold.ts +4 -0
  185. package/src/internal/ab-snapshot.ts +1 -0
  186. package/src/internal/cli-ax.ts +205 -34
  187. package/src/internal/cursor-slack-relay.ts +3 -0
  188. package/src/internal/deploy-client.ts +3 -0
  189. package/src/internal/discovery.ts +8 -1
  190. package/src/internal/model-pricing.ts +426 -0
  191. package/src/internal/sdk-runner.ts +10 -2
  192. package/src/internal/server.ts +9 -5
  193. package/src/internal/session-cost.ts +231 -0
  194. package/src/internal/session-engine.ts +28 -0
  195. package/src/internal/trajectory.ts +45 -3
  196. package/src/types.ts +24 -1
  197. package/dist/channels/github/instrument.d.ts +0 -20
  198. package/dist/channels/github/instrument.d.ts.map +0 -1
  199. package/dist/docs/assets/chunks/@localSearchIndexroot.BQTzJjR_.js +0 -1
  200. package/dist/docs/assets/guides_slack.md.D_xFKlnF.lean.js +0 -1
  201. package/dist/docs/assets/guides_webhooks.md.B1EswtUu.js +0 -50
  202. package/dist/internal/json-dir-store.d.ts +0 -32
  203. package/dist/internal/json-dir-store.d.ts.map +0 -1
  204. package/dist/internal/json-dir-store.js +0 -100
  205. package/dist/playground/assets/index-CjOQ4hN9.css +0 -1
  206. package/dist/playground/assets/index-DqXdAFGa.js +0 -85
  207. package/src/bin/agent-serve.version.test.ts +0 -64
  208. package/src/channels/github/api.test.ts +0 -64
  209. package/src/channels/github/auth.test.ts +0 -105
  210. package/src/channels/github/cursor-account.test.ts +0 -204
  211. package/src/channels/github/forward.test.ts +0 -457
  212. package/src/channels/github/github.test.ts +0 -985
  213. package/src/channels/github/replay.test.ts +0 -179
  214. package/src/channels/slack/api.post-message.test.ts +0 -148
  215. package/src/channels/slack/approvals.test.ts +0 -328
  216. package/src/channels/slack/block-actions.test.ts +0 -469
  217. package/src/channels/slack/bot-mentions.test.ts +0 -267
  218. package/src/channels/slack/channel-watch.test.ts +0 -363
  219. package/src/channels/slack/cursor-account.test.ts +0 -301
  220. package/src/channels/slack/defaults.final-post.test.ts +0 -182
  221. package/src/channels/slack/dispatch.test.ts +0 -875
  222. package/src/channels/slack/eval-directive.test.ts +0 -273
  223. package/src/channels/slack/message-body.test.ts +0 -54
  224. package/src/channels/slack/nudge-store.test.ts +0 -143
  225. package/src/channels/slack/slack.test.ts +0 -391
  226. package/src/channels/slack/stop.test.ts +0 -23
  227. package/src/channels/slack/thread-context.test.ts +0 -202
  228. package/src/evals/assertions.test.ts +0 -617
  229. package/src/evals/expect.test.ts +0 -144
  230. package/src/evals/judge.test.ts +0 -181
  231. package/src/evals/loaders.test.ts +0 -132
  232. package/src/evals/matchers.test.ts +0 -95
  233. package/src/evals/reporters.test.ts +0 -303
  234. package/src/evals/run-facts.test.ts +0 -259
  235. package/src/internal/ab-snapshot.test.ts +0 -325
  236. package/src/internal/approval-gate.test.ts +0 -49
  237. package/src/internal/approvals.integration.test.ts +0 -383
  238. package/src/internal/artifacts-store.test.ts +0 -283
  239. package/src/internal/authored-loaders.test.ts +0 -31
  240. package/src/internal/builtin-tools/artifacts.test.ts +0 -247
  241. package/src/internal/builtin-tools/reminders.test.ts +0 -201
  242. package/src/internal/channel-route-schema.test.ts +0 -294
  243. package/src/internal/chat-attach.test.ts +0 -262
  244. package/src/internal/cli-deploy.test.ts +0 -1991
  245. package/src/internal/cli-docs.test.ts +0 -161
  246. package/src/internal/cli-mcp.test.ts +0 -789
  247. package/src/internal/cli-skills.test.ts +0 -133
  248. package/src/internal/cli-slack.test.ts +0 -1654
  249. package/src/internal/cloud-merge.test.ts +0 -74
  250. package/src/internal/cron.test.ts +0 -22
  251. package/src/internal/cursor/account-mcp.test.ts +0 -807
  252. package/src/internal/cursor/backend-client.test.ts +0 -591
  253. package/src/internal/cursor/credentials.test.ts +0 -351
  254. package/src/internal/cursor/github-credentials.test.ts +0 -136
  255. package/src/internal/cursor-account-mcp-auth.test.ts +0 -310
  256. package/src/internal/cursor-account.integration.test.ts +0 -441
  257. package/src/internal/cursor-event-relay.test.ts +0 -746
  258. package/src/internal/cursor-github-credentials.integration.test.ts +0 -271
  259. package/src/internal/cursor-slack-relay.test.ts +0 -525
  260. package/src/internal/deploy-source.test.ts +0 -111
  261. package/src/internal/discovery.artifact-tool.test.ts +0 -136
  262. package/src/internal/discovery.artifacts.test.ts +0 -119
  263. package/src/internal/discovery.builtin-tools.test.ts +0 -94
  264. package/src/internal/discovery.concurrency.test.ts +0 -60
  265. package/src/internal/discovery.cursor-account.test.ts +0 -133
  266. package/src/internal/discovery.cwd.test.ts +0 -83
  267. package/src/internal/discovery.hosting.test.ts +0 -80
  268. package/src/internal/discovery.identity.test.ts +0 -44
  269. package/src/internal/docs-site.test.ts +0 -66
  270. package/src/internal/duration.test.ts +0 -29
  271. package/src/internal/eval-judge-model.test.ts +0 -187
  272. package/src/internal/eval-run-store.cancel.test.ts +0 -142
  273. package/src/internal/eval-run-store.storage.test.ts +0 -211
  274. package/src/internal/eval-runner.http.test.ts +0 -403
  275. package/src/internal/eval-runner.run.test.ts +0 -928
  276. package/src/internal/evals-client.test.ts +0 -307
  277. package/src/internal/event-mapper.test.ts +0 -243
  278. package/src/internal/github-fanout.test.ts +0 -213
  279. package/src/internal/handleAgentServeTrigger.test.ts +0 -185
  280. package/src/internal/host-kv.test.ts +0 -82
  281. package/src/internal/host-platforms.test.ts +0 -126
  282. package/src/internal/http-channel.test.ts +0 -402
  283. package/src/internal/init-project.test.ts +0 -270
  284. package/src/internal/install-cursor-skills.test.ts +0 -262
  285. package/src/internal/local-env.test.ts +0 -120
  286. package/src/internal/log-ring.test.ts +0 -31
  287. package/src/internal/logs-client.test.ts +0 -350
  288. package/src/internal/mcp-endpoint.test.ts +0 -436
  289. package/src/internal/mcp-host.test.ts +0 -298
  290. package/src/internal/mcp-oauth.test.ts +0 -148
  291. package/src/internal/net.test.ts +0 -17
  292. package/src/internal/peer-connections.test.ts +0 -128
  293. package/src/internal/peer-mcp.integration.test.ts +0 -289
  294. package/src/internal/playground/toolchain.test.ts +0 -53
  295. package/src/internal/playground-cli.test.ts +0 -187
  296. package/src/internal/playground-proxy.test.ts +0 -376
  297. package/src/internal/prompt-context.integration.test.ts +0 -232
  298. package/src/internal/prompt-context.test.ts +0 -127
  299. package/src/internal/reminder-runner.test.ts +0 -432
  300. package/src/internal/reminder-store.test.ts +0 -53
  301. package/src/internal/request-headers.test.ts +0 -27
  302. package/src/internal/resolve-prod-target.test.ts +0 -787
  303. package/src/internal/resolved-connections.test.ts +0 -295
  304. package/src/internal/router.test.ts +0 -57
  305. package/src/internal/sdk-runner.test.ts +0 -290
  306. package/src/internal/server.artifacts.test.ts +0 -334
  307. package/src/internal/session-engine.artifacts.test.ts +0 -293
  308. package/src/internal/session-engine.coalesce.test.ts +0 -169
  309. package/src/internal/session-engine.concurrency.test.ts +0 -250
  310. package/src/internal/session-engine.host-oauth-mcp.test.ts +0 -110
  311. package/src/internal/session-engine.interrupt.test.ts +0 -577
  312. package/src/internal/session-engine.storage.test.ts +0 -547
  313. package/src/internal/session-urls.test.ts +0 -28
  314. package/src/internal/sessions-client.test.ts +0 -518
  315. package/src/internal/storage-coordinator.test.ts +0 -517
  316. package/src/internal/tool-call.test.ts +0 -458
  317. package/src/internal/tool-result.test.ts +0 -52
  318. package/src/internal/trajectory.approvals.test.ts +0 -83
  319. package/src/internal/trajectory.subagents.test.ts +0 -198
  320. package/src/internal/turn-governor.test.ts +0 -137
  321. package/src/internal/update-check.test.ts +0 -485
  322. package/src/internal/workspace.test.ts +0 -207
  323. package/src/storage-backends/cursor-hosted.test.ts +0 -121
  324. /package/dist/docs/assets/{index.md.Dfv5ic9t.lean.js → index.md.CH_s5uZe.lean.js} +0 -0
@@ -1,525 +0,0 @@
1
- import { mkdtemp, readFile, rm } from "node:fs/promises";
2
- import { tmpdir } from "node:os";
3
- import { join } from "node:path";
4
- import { afterEach, beforeEach, describe, expect, it } from "vitest";
5
- import type { CursorSlackEnvelope } from "../channels/slack/cursor-account.js";
6
- import { slackChannel } from "../channels/slack/slack-channel.js";
7
- import { httpChannel } from "../channels.js";
8
- import type {
9
- AgentProject,
10
- AgentServeHandle,
11
- ChannelDefinition,
12
- } from "../types.js";
13
- import { RelayOffsetStore } from "./cursor-event-relay.js";
14
- import {
15
- CursorSlackRelay,
16
- type CursorSlackRelayEvent,
17
- createCursorSlackApiCaller,
18
- formatCursorSlackEventLog,
19
- } from "./cursor-slack-relay.js";
20
- import type { AgentRunner } from "./sdk-runner.js";
21
- import { startServer } from "./server.js";
22
-
23
- interface RecordedRequest {
24
- method: string;
25
- url: string;
26
- body?: unknown;
27
- }
28
-
29
- /**
30
- * Minimal fake of the /v0/slack-events surface: records requests and serves
31
- * a scripted queue of poll responses. Registration echoes the requested
32
- * agents as subscribed on one workspace.
33
- */
34
- function fakeBackend(script: {
35
- anchorOffset?: string;
36
- polls?: Array<{
37
- events: CursorSlackRelayEvent[];
38
- nextOffset: string;
39
- gapDetected?: boolean;
40
- }>;
41
- registrationFailures?: number;
42
- apiResponses?: Record<string, unknown>;
43
- }) {
44
- const requests: RecordedRequest[] = [];
45
- const polls = [...(script.polls ?? [])];
46
- let registrationFailures = script.registrationFailures ?? 0;
47
- const fetchImpl: typeof fetch = async (input, init) => {
48
- const url = String(input);
49
- const method = init?.method ?? "GET";
50
- const body =
51
- typeof init?.body === "string"
52
- ? (JSON.parse(init.body) as unknown)
53
- : undefined;
54
- requests.push({ method, url, ...(body === undefined ? {} : { body }) });
55
-
56
- if (url.includes("/v0/slack-events/subscriptions")) {
57
- if (registrationFailures > 0) {
58
- registrationFailures -= 1;
59
- return new Response("storage unavailable", { status: 503 });
60
- }
61
- return jsonResponse({
62
- workspaces: [{ slackTeamId: "T0TEST", isSubscribed: true }],
63
- agents: (
64
- (body as { agents?: Array<{ name: string }> })?.agents ?? []
65
- ).map((agent) => ({ name: agent.name, isSubscribed: true })),
66
- expiresAt: new Date().toISOString(),
67
- });
68
- }
69
- if (url.includes("/v0/slack-events/api")) {
70
- const request = body as { method?: string };
71
- return jsonResponse(
72
- script.apiResponses?.[request.method ?? ""] ?? {
73
- ok: true,
74
- ts: "999.111",
75
- }
76
- );
77
- }
78
- if (url.includes("after=%24") || url.includes("after=$")) {
79
- return jsonResponse({
80
- events: [],
81
- nextOffset: script.anchorOffset ?? "",
82
- gapDetected: false,
83
- });
84
- }
85
- const page = polls.shift() ?? {
86
- events: [],
87
- nextOffset: "",
88
- gapDetected: false,
89
- };
90
- return jsonResponse(page);
91
- };
92
- return { requests, fetchImpl };
93
- }
94
-
95
- function jsonResponse(body: unknown): Response {
96
- return new Response(JSON.stringify(body), {
97
- status: 200,
98
- headers: { "content-type": "application/json" },
99
- });
100
- }
101
-
102
- function envelope(
103
- offset: string,
104
- overrides: Partial<CursorSlackEnvelope> = {}
105
- ): CursorSlackRelayEvent {
106
- return {
107
- offset,
108
- eventName: "app_mention",
109
- slackTeamId: "T0TEST",
110
- channelId: "C0100",
111
- channelType: "channel",
112
- threadTs: "111.222",
113
- messageTs: "111.222",
114
- slackUserId: "U0AAA",
115
- text: "what's the weather?",
116
- agentName: "Benny",
117
- consumerId: "consumer-under-test",
118
- matchedBy: "name",
119
- eventId: `Ev${offset}`,
120
- receivedAtMs: Date.now(),
121
- ...overrides,
122
- };
123
- }
124
-
125
- async function waitFor(
126
- predicate: () => boolean,
127
- timeoutMs = 2_000
128
- ): Promise<void> {
129
- const deadline = Date.now() + timeoutMs;
130
- while (!predicate()) {
131
- if (Date.now() > deadline) {
132
- throw new Error("waitFor timed out");
133
- }
134
- await new Promise((resolve) => setTimeout(resolve, 10));
135
- }
136
- }
137
-
138
- describe("formatCursorSlackEventLog", () => {
139
- it("names the agent, match kind, and thread", () => {
140
- expect(
141
- formatCursorSlackEventLog({
142
- eventName: "app_mention",
143
- agentName: "Benny",
144
- matchedBy: "name",
145
- channelId: "C0100",
146
- threadTs: "111.222",
147
- receivedAtMs: Date.parse("2026-07-14T16:00:00.000Z"),
148
- eventId: "Ev1",
149
- })
150
- ).toBe(
151
- "app_mention → Benny (name) in C0100/111.222 received=2026-07-14T16:00:00.000Z (Ev1)"
152
- );
153
- });
154
- });
155
-
156
- describe("createCursorSlackApiCaller", () => {
157
- it("POSTs the method, args, agent name, and consumer id; returns the body", async () => {
158
- const backend = fakeBackend({
159
- apiResponses: { "chat.postMessage": { ok: true, ts: "123.456" } },
160
- });
161
- const call = createCursorSlackApiCaller({
162
- baseUrl: "https://api2.example/",
163
- apiKey: "key_1",
164
- agentName: "Benny",
165
- consumerId: "consumer-1",
166
- fetchImpl: backend.fetchImpl,
167
- });
168
- const result = await call("chat.postMessage", {
169
- channel: "C0100",
170
- markdown_text: "hi",
171
- thread_ts: "111.222",
172
- });
173
- expect(result).toEqual({ ok: true, ts: "123.456" });
174
- expect(backend.requests).toHaveLength(1);
175
- expect(backend.requests[0]).toMatchObject({
176
- method: "POST",
177
- url: "https://api2.example/v0/slack-events/api",
178
- body: {
179
- method: "chat.postMessage",
180
- arguments: {
181
- channel: "C0100",
182
- markdown_text: "hi",
183
- thread_ts: "111.222",
184
- },
185
- agentName: "Benny",
186
- consumerId: "consumer-1",
187
- },
188
- });
189
- });
190
-
191
- it("soft-fails Slack-style when the backend is unreachable", async () => {
192
- const call = createCursorSlackApiCaller({
193
- baseUrl: "https://api2.example",
194
- apiKey: "key_1",
195
- agentName: "Benny",
196
- consumerId: "consumer-1",
197
- fetchImpl: async () => {
198
- throw new Error("ECONNREFUSED");
199
- },
200
- });
201
- expect(await call("chat.postMessage", {})).toEqual({
202
- ok: false,
203
- error: "cursor_backend_unreachable",
204
- });
205
- });
206
- });
207
-
208
- describe("CursorSlackRelay", () => {
209
- let dir: string;
210
- let relay: CursorSlackRelay | undefined;
211
-
212
- afterEach(async () => {
213
- await relay?.stop();
214
- relay = undefined;
215
- if (dir !== undefined) {
216
- await rm(dir, { recursive: true, force: true });
217
- }
218
- });
219
-
220
- async function makeRelay(
221
- backend: ReturnType<typeof fakeBackend>,
222
- options?: {
223
- dispatch?: (e: CursorSlackRelayEvent) => Promise<void>;
224
- logger?: (line: string) => void;
225
- agents?: Array<{ name: string; iconEmoji?: string }>;
226
- }
227
- ): Promise<{ dispatched: CursorSlackRelayEvent[]; consumerId: string }> {
228
- const dispatched: CursorSlackRelayEvent[] = [];
229
- relay = new CursorSlackRelay({
230
- baseUrl: "https://api2.example",
231
- apiKey: "key",
232
- agents: options?.agents ?? [{ name: "Benny", iconEmoji: ":robot:" }],
233
- stateDir: dir,
234
- dispatch:
235
- options?.dispatch ??
236
- (async (e) => {
237
- dispatched.push(e);
238
- }),
239
- logger: options?.logger ?? (() => {}),
240
- fetchImpl: backend.fetchImpl,
241
- pollWaitMs: 0,
242
- });
243
- const consumerId = await relay.resolveConsumerId();
244
- relay.start();
245
- return { dispatched, consumerId };
246
- }
247
-
248
- it("registers before consuming, anchors, dispatches in order, persists offset + consumer id", async () => {
249
- dir = await mkdtemp(join(tmpdir(), "cursor-slack-"));
250
- const store = new RelayOffsetStore(dir);
251
- const backendProbe = fakeBackend({});
252
- // Resolve the consumer id first so the scripted poll can carry it.
253
- const probe = new CursorSlackRelay({
254
- baseUrl: "https://api2.example",
255
- apiKey: "key",
256
- agents: [{ name: "Benny" }],
257
- stateDir: dir,
258
- dispatch: async () => {},
259
- logger: () => {},
260
- fetchImpl: backendProbe.fetchImpl,
261
- });
262
- const consumerId = await probe.resolveConsumerId();
263
-
264
- const backend = fakeBackend({
265
- anchorOffset: "100-0",
266
- polls: [
267
- {
268
- events: [
269
- envelope("101-0", { consumerId }),
270
- envelope("102-0", {
271
- consumerId,
272
- eventName: "message",
273
- matchedBy: "thread",
274
- messageTs: "111.333",
275
- }),
276
- ],
277
- nextOffset: "102-0",
278
- },
279
- ],
280
- });
281
- const { dispatched } = await makeRelay(backend);
282
-
283
- await waitFor(() => dispatched.length === 2);
284
- expect(dispatched.map((e) => e.eventName)).toEqual([
285
- "app_mention",
286
- "message",
287
- ]);
288
- await waitFor(() =>
289
- backend.requests.some((r) => r.url.includes("after=102-0"))
290
- );
291
- await relay?.stop();
292
- relay = undefined;
293
-
294
- expect(await store.load()).toBe("102-0");
295
-
296
- // Consumption is registration-gated: the first request is the PUT.
297
- expect(backend.requests[0]?.method).toBe("PUT");
298
- expect(backend.requests[0]?.body).toMatchObject({
299
- consumerId,
300
- agents: [{ name: "Benny", iconEmoji: ":robot:" }],
301
- });
302
- expect((await readFile(join(dir, "consumer-id"), "utf8")).trim()).toBe(
303
- consumerId
304
- );
305
- });
306
-
307
- it("skips sibling consumers' events and unknown agents but advances the offset", async () => {
308
- dir = await mkdtemp(join(tmpdir(), "cursor-slack-"));
309
- const probeBackend = fakeBackend({});
310
- const probe = new CursorSlackRelay({
311
- baseUrl: "https://api2.example",
312
- apiKey: "key",
313
- agents: [{ name: "Benny" }],
314
- stateDir: dir,
315
- dispatch: async () => {},
316
- logger: () => {},
317
- fetchImpl: probeBackend.fetchImpl,
318
- });
319
- const consumerId = await probe.resolveConsumerId();
320
-
321
- const backend = fakeBackend({
322
- anchorOffset: "0-1",
323
- polls: [
324
- {
325
- events: [
326
- // Another host (consumer) on the same principal stream.
327
- envelope("1-0", { consumerId: "other-host" }),
328
- // Our consumer id but an agent we did not register.
329
- envelope("2-0", { consumerId, agentName: "Stranger" }),
330
- // Ours.
331
- envelope("3-0", { consumerId }),
332
- ],
333
- nextOffset: "3-0",
334
- },
335
- ],
336
- });
337
- const { dispatched } = await makeRelay(backend);
338
-
339
- await waitFor(() => dispatched.length === 1);
340
- expect(dispatched[0]?.offset).toBe("3-0");
341
- await relay?.stop();
342
- relay = undefined;
343
- const store = new RelayOffsetStore(dir);
344
- expect(await store.load()).toBe("3-0");
345
- });
346
-
347
- it("deregisters its agents on clean stop", async () => {
348
- dir = await mkdtemp(join(tmpdir(), "cursor-slack-"));
349
- const backend = fakeBackend({ anchorOffset: "1-0" });
350
- const { consumerId } = await makeRelay(backend);
351
- await waitFor(() => backend.requests.some((r) => r.method === "GET"));
352
-
353
- await relay?.stop();
354
- relay = undefined;
355
-
356
- const lastPut = backend.requests.filter((r) => r.method === "PUT").at(-1);
357
- expect(lastPut?.body).toEqual({ consumerId, agents: [] });
358
- });
359
-
360
- it("retries registration until it succeeds before any consumption", async () => {
361
- dir = await mkdtemp(join(tmpdir(), "cursor-slack-"));
362
- const probeBackend = fakeBackend({});
363
- const probe = new CursorSlackRelay({
364
- baseUrl: "https://api2.example",
365
- apiKey: "key",
366
- agents: [{ name: "Benny" }],
367
- stateDir: dir,
368
- dispatch: async () => {},
369
- logger: () => {},
370
- fetchImpl: probeBackend.fetchImpl,
371
- });
372
- const consumerId = await probe.resolveConsumerId();
373
- const backend = fakeBackend({
374
- anchorOffset: "10-0",
375
- polls: [
376
- { events: [envelope("11-0", { consumerId })], nextOffset: "11-0" },
377
- ],
378
- registrationFailures: 1,
379
- });
380
- const { dispatched } = await makeRelay(backend);
381
-
382
- await waitFor(() => dispatched.length === 1, 10_000);
383
- const firstGetIndex = backend.requests.findIndex((r) => r.method === "GET");
384
- const successfulPutIndex = backend.requests.findIndex(
385
- (r, index) => r.method === "PUT" && index > 0
386
- );
387
- expect(successfulPutIndex).toBeGreaterThan(0);
388
- expect(firstGetIndex).toBeGreaterThan(successfulPutIndex);
389
- });
390
- });
391
-
392
- describe("serve with cursor-account Slack channels", () => {
393
- const savedEnv: Record<string, string | undefined> = {};
394
- let stateRoot: string | undefined;
395
- let handle: AgentServeHandle | undefined;
396
-
397
- const runner: AgentRunner = {
398
- async runTurn() {
399
- return { status: "finished", result: "unused" };
400
- },
401
- };
402
-
403
- function fixture(): AgentProject {
404
- return {
405
- rootDir: "/tmp/cursor-slack-fixture",
406
- agentDir: "/tmp/cursor-slack-fixture/agent",
407
- name: "slack-fixture",
408
- agent: {
409
- name: "slack-fixture",
410
- runtime: "local",
411
- tools: [],
412
- skills: [],
413
- connections: [],
414
- subagents: [],
415
- seedFiles: [],
416
- },
417
- httpChannel: httpChannel(),
418
- channels: [
419
- {
420
- id: "slack",
421
- // Same erasure discovery performs when loading authored channels.
422
- definition: slackChannel({
423
- cursorAccount: true,
424
- agentName: "Benny",
425
- }) as unknown as ChannelDefinition,
426
- },
427
- ],
428
- schedules: [],
429
- hooks: [],
430
- abs: [],
431
- diagnostics: [],
432
- };
433
- }
434
-
435
- beforeEach(() => {
436
- for (const key of [
437
- "CURSOR_API_KEY",
438
- "CURSOR_API_BASE_URL",
439
- "AGENT_SERVE_CONFIG_DIR",
440
- ]) {
441
- savedEnv[key] = process.env[key];
442
- delete process.env[key];
443
- }
444
- // No stored login can leak in from the developer's machine.
445
- process.env.AGENT_SERVE_CONFIG_DIR = "/nonexistent-agent-serve-config";
446
- });
447
-
448
- afterEach(async () => {
449
- await handle?.close();
450
- handle = undefined;
451
- if (stateRoot !== undefined) {
452
- await rm(stateRoot, { recursive: true, force: true });
453
- stateRoot = undefined;
454
- }
455
- for (const [key, value] of Object.entries(savedEnv)) {
456
- if (value === undefined) {
457
- delete process.env[key];
458
- } else {
459
- process.env[key] = value;
460
- }
461
- }
462
- });
463
-
464
- it("refuses to serve when the host is not signed in to Cursor", async () => {
465
- const root = await mkdtemp(join(tmpdir(), "agent-serve-cursor-slack-"));
466
- stateRoot = root;
467
- await expect(
468
- startServer([{ slug: "", project: fixture() }], {
469
- port: 0,
470
- stateRoot: root,
471
- playground: false,
472
- runner,
473
- })
474
- ).rejects.toThrow(
475
- /cursorAccount: true[\s\S]*signed in to Cursor[\s\S]*agentkit login/
476
- );
477
- });
478
-
479
- it("starts the relay when a credential is present", async () => {
480
- const root = await mkdtemp(join(tmpdir(), "agent-serve-cursor-slack-"));
481
- stateRoot = root;
482
- process.env.CURSOR_API_KEY = "crsr_env";
483
- // Point at a closed local port so the background relay fails fast and
484
- // hermetically instead of reaching the real backend.
485
- process.env.CURSOR_API_BASE_URL = "http://127.0.0.1:9";
486
- const logs: string[] = [];
487
- handle = await startServer([{ slug: "", project: fixture() }], {
488
- port: 0,
489
- stateRoot: root,
490
- playground: false,
491
- runner,
492
- logger: (line) => logs.push(line),
493
- });
494
- expect(
495
- logs.some(
496
- (line) =>
497
- line.includes("cursor-slack: relaying Slack for") &&
498
- line.includes("Benny")
499
- )
500
- ).toBe(true);
501
- });
502
-
503
- it("rejects duplicate registered agent names across mounts", async () => {
504
- const root = await mkdtemp(join(tmpdir(), "agent-serve-cursor-slack-"));
505
- stateRoot = root;
506
- process.env.CURSOR_API_KEY = "crsr_env";
507
- process.env.CURSOR_API_BASE_URL = "http://127.0.0.1:9";
508
- const projectA = fixture();
509
- const projectB = fixture();
510
- await expect(
511
- startServer(
512
- [
513
- { slug: "a", project: projectA },
514
- { slug: "b", project: projectB },
515
- ],
516
- {
517
- port: 0,
518
- stateRoot: root,
519
- playground: false,
520
- runner,
521
- }
522
- )
523
- ).rejects.toThrow(/register the Slack name "Benny"/);
524
- });
525
- });
@@ -1,111 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import {
3
- agentPathRelativeToGitRoot,
4
- type GitRunner,
5
- httpsGitRepoUrlFromRemote,
6
- inferDeployGitSource,
7
- } from "./deploy-source.js";
8
-
9
- describe("httpsGitRepoUrlFromRemote", () => {
10
- it("normalizes https, ssh, and git@ remotes", () => {
11
- expect(
12
- httpsGitRepoUrlFromRemote("https://github.com/acme/agents.git")
13
- ).toBe("https://github.com/acme/agents");
14
- expect(httpsGitRepoUrlFromRemote("git@github.com:acme/agents.git")).toBe(
15
- "https://github.com/acme/agents"
16
- );
17
- expect(
18
- httpsGitRepoUrlFromRemote("ssh://git@github.com/acme/agents.git")
19
- ).toBe("https://github.com/acme/agents");
20
- expect(
21
- httpsGitRepoUrlFromRemote("ssh://git@github.com:22/acme/agents.git")
22
- ).toBe("https://github.com/acme/agents");
23
- });
24
-
25
- it("normalizes GitHub org-scoped SSH remotes (org-NNNN@github.com:…)", () => {
26
- expect(
27
- httpsGitRepoUrlFromRemote(
28
- "org-96667180@github.com:anysphere/everysphere.git"
29
- )
30
- ).toBe("https://github.com/anysphere/everysphere");
31
- });
32
-
33
- it("rejects unusable remotes", () => {
34
- expect(httpsGitRepoUrlFromRemote("")).toBeUndefined();
35
- expect(httpsGitRepoUrlFromRemote("not-a-url")).toBeUndefined();
36
- expect(httpsGitRepoUrlFromRemote("https://github.com/")).toBeUndefined();
37
- });
38
- });
39
-
40
- describe("agentPathRelativeToGitRoot", () => {
41
- it("returns a posix-relative path for nested dirs and omits the root", () => {
42
- expect(
43
- agentPathRelativeToGitRoot(
44
- "/repo/packages/agent-serve/examples/approval-buddy",
45
- "/repo"
46
- )
47
- ).toBe("packages/agent-serve/examples/approval-buddy");
48
- expect(agentPathRelativeToGitRoot("/repo", "/repo")).toBeUndefined();
49
- });
50
-
51
- it("returns undefined when dir is outside the repo", () => {
52
- expect(
53
- agentPathRelativeToGitRoot("/elsewhere/agent", "/repo")
54
- ).toBeUndefined();
55
- });
56
- });
57
-
58
- describe("inferDeployGitSource", () => {
59
- it("assembles repo, ref, and path from git probes", async () => {
60
- const git: GitRunner = async (args) => {
61
- const key = args.join(" ");
62
- switch (key) {
63
- case "rev-parse --show-toplevel":
64
- return "/repo";
65
- case "remote get-url origin":
66
- return "git@github.com:acme/agents.git";
67
- case "rev-parse --abbrev-ref HEAD":
68
- return "main";
69
- default:
70
- return undefined;
71
- }
72
- };
73
- await expect(
74
- inferDeployGitSource("/repo/examples/weather-agent", { git })
75
- ).resolves.toEqual({
76
- gitRepoUrl: "https://github.com/acme/agents",
77
- gitRef: "main",
78
- agentPath: "examples/weather-agent",
79
- });
80
- });
81
-
82
- it("pins a detached HEAD to the commit SHA", async () => {
83
- const git: GitRunner = async (args) => {
84
- const key = args.join(" ");
85
- switch (key) {
86
- case "rev-parse --show-toplevel":
87
- return "/repo";
88
- case "remote get-url origin":
89
- return "https://github.com/acme/agents.git";
90
- case "rev-parse --abbrev-ref HEAD":
91
- return "HEAD";
92
- case "rev-parse HEAD":
93
- return "abcdef0123456789";
94
- default:
95
- return undefined;
96
- }
97
- };
98
- await expect(inferDeployGitSource("/repo", { git })).resolves.toEqual({
99
- gitRepoUrl: "https://github.com/acme/agents",
100
- gitRef: "abcdef0123456789",
101
- agentPath: undefined,
102
- });
103
- });
104
-
105
- it("returns empty when not inside a git checkout", async () => {
106
- const git: GitRunner = async () => undefined;
107
- await expect(inferDeployGitSource("/tmp/agent", { git })).resolves.toEqual(
108
- {}
109
- );
110
- });
111
- });