@cursor/july 0.1.22 → 0.1.24

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 (219) hide show
  1. package/README.md +5 -5
  2. package/dist/bin/agent-serve.d.ts +1 -0
  3. package/dist/bin/agent-serve.d.ts.map +1 -1
  4. package/dist/bin/agent-serve.js +21 -3
  5. package/dist/docs/404.html +2 -2
  6. package/dist/docs/ab.html +3 -3
  7. package/dist/docs/assets/{app.BKNKMLp4.js → app.CvSGaAxk.js} +1 -1
  8. package/dist/docs/assets/chunks/@localSearchIndexroot.CL2Y0Zmh.js +1 -0
  9. package/dist/docs/assets/chunks/{VPLocalSearchBox.sOSfEZR6.js → VPLocalSearchBox.J1jJbCvs.js} +1 -1
  10. package/dist/docs/assets/chunks/{theme.BvCHT5lj.js → theme.C7vfzr7h.js} +2 -2
  11. package/dist/docs/assets/index.md.Dfv5ic9t.js +20 -0
  12. package/dist/docs/assets/{index.md.t0TM2Qzz.lean.js → index.md.Dfv5ic9t.lean.js} +1 -1
  13. package/dist/docs/assets/{reference_cli.md.DnYfr5V2.js → reference_cli.md.ccoKOoXt.js} +4 -3
  14. package/dist/docs/assets/{reference_cli.md.DnYfr5V2.lean.js → reference_cli.md.ccoKOoXt.lean.js} +1 -1
  15. package/dist/docs/building-with-agents.html +3 -3
  16. package/dist/docs/concepts.html +3 -3
  17. package/dist/docs/deployment.html +3 -3
  18. package/dist/docs/evals.html +3 -3
  19. package/dist/docs/example-agents/approval-buddy.html +3 -3
  20. package/dist/docs/example-agents/benny.html +3 -3
  21. package/dist/docs/example-agents/bugbot.html +3 -3
  22. package/dist/docs/example-agents/codebase-wiki.html +3 -3
  23. package/dist/docs/example-agents/codeowners-review.html +3 -3
  24. package/dist/docs/example-agents/concierge.html +3 -3
  25. package/dist/docs/example-agents/fsd.html +3 -3
  26. package/dist/docs/example-agents/index.html +3 -3
  27. package/dist/docs/example-agents/knowledge-base.html +3 -3
  28. package/dist/docs/example-agents/oncall.html +3 -3
  29. package/dist/docs/example-agents/security-reviewer.html +3 -3
  30. package/dist/docs/example-agents/slack-agent.html +3 -3
  31. package/dist/docs/example-agents/weather-agent.html +3 -3
  32. package/dist/docs/guides/agent-to-agent.html +3 -3
  33. package/dist/docs/guides/cloud-runtime.html +3 -3
  34. package/dist/docs/guides/github.html +3 -3
  35. package/dist/docs/guides/human-in-the-loop.html +3 -3
  36. package/dist/docs/guides/mcp-oauth.html +3 -3
  37. package/dist/docs/guides/slack.html +3 -3
  38. package/dist/docs/guides/webhooks.html +3 -3
  39. package/dist/docs/hashmap.json +1 -1
  40. package/dist/docs/hillclimbing.html +3 -3
  41. package/dist/docs/index.html +6 -6
  42. package/dist/docs/quickstart.html +3 -3
  43. package/dist/docs/reference/agent-config.html +3 -3
  44. package/dist/docs/reference/channels.html +3 -3
  45. package/dist/docs/reference/cli.html +7 -6
  46. package/dist/docs/reference/connections.html +3 -3
  47. package/dist/docs/reference/hooks.html +3 -3
  48. package/dist/docs/reference/http-api.html +3 -3
  49. package/dist/docs/reference/instructions.html +3 -3
  50. package/dist/docs/reference/playground.html +3 -3
  51. package/dist/docs/reference/project-layout.html +3 -3
  52. package/dist/docs/reference/prompt.html +3 -3
  53. package/dist/docs/reference/schedules.html +3 -3
  54. package/dist/docs/reference/sessions.html +3 -3
  55. package/dist/docs/reference/skills.html +3 -3
  56. package/dist/docs/reference/subagents.html +3 -3
  57. package/dist/docs/reference/tools.html +3 -3
  58. package/dist/docs/scaffolding-agents.html +3 -3
  59. package/dist/docs/storage.html +3 -3
  60. package/dist/docs/troubleshooting.html +3 -3
  61. package/dist/index.d.ts +2 -0
  62. package/dist/index.d.ts.map +1 -1
  63. package/dist/index.js +1 -0
  64. package/dist/internal/cli-docs.d.ts +34 -0
  65. package/dist/internal/cli-docs.d.ts.map +1 -0
  66. package/dist/internal/cli-docs.js +162 -0
  67. package/dist/internal/distribution.d.ts +2 -1
  68. package/dist/internal/distribution.d.ts.map +1 -1
  69. package/dist/internal/distribution.js +3 -1
  70. package/dist/internal/docs-site.d.ts +4 -2
  71. package/dist/internal/docs-site.d.ts.map +1 -1
  72. package/dist/internal/docs-site.js +15 -11
  73. package/dist/internal/init-project.d.ts.map +1 -1
  74. package/dist/internal/init-project.js +19 -0
  75. package/dist/internal/session-engine.d.ts.map +1 -1
  76. package/dist/internal/session-engine.js +5 -0
  77. package/dist/internal/workspace.d.ts +9 -0
  78. package/dist/internal/workspace.d.ts.map +1 -1
  79. package/dist/internal/workspace.js +52 -5
  80. package/dist/memory.d.ts +79 -0
  81. package/dist/memory.d.ts.map +1 -0
  82. package/dist/memory.js +164 -0
  83. package/dist/playground/assets/index-CidizGZv.css +1 -0
  84. package/dist/playground/assets/index-DTG9OsPV.js +85 -0
  85. package/dist/playground/index.html +2 -2
  86. package/dist/types.d.ts +11 -0
  87. package/dist/types.d.ts.map +1 -1
  88. package/docs/README.md +8 -1
  89. package/docs/reference/cli.md +20 -4
  90. package/package.json +32 -24
  91. package/src/bin/agent-serve.ts +23 -3
  92. package/src/index.ts +2 -0
  93. package/src/internal/cli-docs.ts +191 -0
  94. package/src/internal/distribution.ts +3 -1
  95. package/src/internal/docs-site.ts +19 -11
  96. package/src/internal/init-project.ts +22 -0
  97. package/src/internal/session-engine.ts +5 -0
  98. package/src/internal/workspace.ts +81 -5
  99. package/src/memory.ts +215 -0
  100. package/src/types.ts +11 -0
  101. package/dist/channels/github/instrument.d.ts +0 -20
  102. package/dist/channels/github/instrument.d.ts.map +0 -1
  103. package/dist/docs/assets/chunks/@localSearchIndexroot.YFE6WoMB.js +0 -1
  104. package/dist/docs/assets/index.md.t0TM2Qzz.js +0 -20
  105. package/dist/internal/json-dir-store.d.ts +0 -32
  106. package/dist/internal/json-dir-store.d.ts.map +0 -1
  107. package/dist/internal/json-dir-store.js +0 -100
  108. package/dist/playground/assets/index-CjOQ4hN9.css +0 -1
  109. package/dist/playground/assets/index-dshZQJCp.js +0 -85
  110. package/src/bin/agent-serve.version.test.ts +0 -62
  111. package/src/channels/github/api.test.ts +0 -64
  112. package/src/channels/github/auth.test.ts +0 -105
  113. package/src/channels/github/cursor-account.test.ts +0 -204
  114. package/src/channels/github/forward.test.ts +0 -457
  115. package/src/channels/github/github.test.ts +0 -937
  116. package/src/channels/github/replay.test.ts +0 -179
  117. package/src/channels/slack/api.post-message.test.ts +0 -148
  118. package/src/channels/slack/approvals.test.ts +0 -328
  119. package/src/channels/slack/block-actions.test.ts +0 -452
  120. package/src/channels/slack/bot-mentions.test.ts +0 -267
  121. package/src/channels/slack/channel-watch.test.ts +0 -363
  122. package/src/channels/slack/cursor-account.test.ts +0 -253
  123. package/src/channels/slack/defaults.final-post.test.ts +0 -182
  124. package/src/channels/slack/dispatch.test.ts +0 -795
  125. package/src/channels/slack/eval-directive.test.ts +0 -273
  126. package/src/channels/slack/message-body.test.ts +0 -54
  127. package/src/channels/slack/nudge-store.test.ts +0 -143
  128. package/src/channels/slack/slack.test.ts +0 -391
  129. package/src/channels/slack/stop.test.ts +0 -23
  130. package/src/channels/slack/thread-context.test.ts +0 -202
  131. package/src/evals/assertions.test.ts +0 -580
  132. package/src/evals/expect.test.ts +0 -144
  133. package/src/evals/judge.test.ts +0 -181
  134. package/src/evals/loaders.test.ts +0 -132
  135. package/src/evals/matchers.test.ts +0 -95
  136. package/src/evals/reporters.test.ts +0 -303
  137. package/src/evals/run-facts.test.ts +0 -259
  138. package/src/internal/ab-snapshot.test.ts +0 -325
  139. package/src/internal/approval-gate.test.ts +0 -49
  140. package/src/internal/approvals.integration.test.ts +0 -383
  141. package/src/internal/authored-loaders.test.ts +0 -31
  142. package/src/internal/builtin-tools/reminders.test.ts +0 -201
  143. package/src/internal/channel-route-schema.test.ts +0 -294
  144. package/src/internal/chat-attach.test.ts +0 -262
  145. package/src/internal/cli-deploy.test.ts +0 -1991
  146. package/src/internal/cli-mcp.test.ts +0 -789
  147. package/src/internal/cli-skills.test.ts +0 -133
  148. package/src/internal/cli-slack.test.ts +0 -1647
  149. package/src/internal/cloud-merge.test.ts +0 -74
  150. package/src/internal/cron.test.ts +0 -22
  151. package/src/internal/cursor/account-mcp.test.ts +0 -807
  152. package/src/internal/cursor/backend-client.test.ts +0 -591
  153. package/src/internal/cursor/credentials.test.ts +0 -351
  154. package/src/internal/cursor/github-credentials.test.ts +0 -136
  155. package/src/internal/cursor-account-mcp-auth.test.ts +0 -310
  156. package/src/internal/cursor-account.integration.test.ts +0 -441
  157. package/src/internal/cursor-event-relay.test.ts +0 -746
  158. package/src/internal/cursor-github-credentials.integration.test.ts +0 -271
  159. package/src/internal/cursor-slack-relay.test.ts +0 -525
  160. package/src/internal/deploy-source.test.ts +0 -111
  161. package/src/internal/discovery.builtin-tools.test.ts +0 -94
  162. package/src/internal/discovery.concurrency.test.ts +0 -60
  163. package/src/internal/discovery.cursor-account.test.ts +0 -133
  164. package/src/internal/discovery.cwd.test.ts +0 -83
  165. package/src/internal/discovery.hosting.test.ts +0 -80
  166. package/src/internal/discovery.identity.test.ts +0 -44
  167. package/src/internal/docs-site.test.ts +0 -66
  168. package/src/internal/duration.test.ts +0 -29
  169. package/src/internal/eval-judge-model.test.ts +0 -187
  170. package/src/internal/eval-run-store.cancel.test.ts +0 -142
  171. package/src/internal/eval-run-store.storage.test.ts +0 -211
  172. package/src/internal/eval-runner.http.test.ts +0 -403
  173. package/src/internal/eval-runner.run.test.ts +0 -928
  174. package/src/internal/evals-client.test.ts +0 -307
  175. package/src/internal/event-mapper.test.ts +0 -243
  176. package/src/internal/github-fanout.test.ts +0 -213
  177. package/src/internal/handleAgentServeTrigger.test.ts +0 -179
  178. package/src/internal/host-kv.test.ts +0 -82
  179. package/src/internal/host-platforms.test.ts +0 -126
  180. package/src/internal/http-channel.test.ts +0 -402
  181. package/src/internal/init-project.test.ts +0 -269
  182. package/src/internal/install-cursor-skills.test.ts +0 -262
  183. package/src/internal/local-env.test.ts +0 -120
  184. package/src/internal/log-ring.test.ts +0 -31
  185. package/src/internal/logs-client.test.ts +0 -350
  186. package/src/internal/mcp-endpoint.test.ts +0 -436
  187. package/src/internal/mcp-host.test.ts +0 -298
  188. package/src/internal/mcp-oauth.test.ts +0 -148
  189. package/src/internal/net.test.ts +0 -17
  190. package/src/internal/peer-connections.test.ts +0 -128
  191. package/src/internal/peer-mcp.integration.test.ts +0 -289
  192. package/src/internal/playground/toolchain.test.ts +0 -53
  193. package/src/internal/playground-cli.test.ts +0 -187
  194. package/src/internal/playground-proxy.test.ts +0 -376
  195. package/src/internal/prompt-context.integration.test.ts +0 -232
  196. package/src/internal/prompt-context.test.ts +0 -127
  197. package/src/internal/reminder-runner.test.ts +0 -390
  198. package/src/internal/reminder-store.test.ts +0 -53
  199. package/src/internal/request-headers.test.ts +0 -27
  200. package/src/internal/resolve-prod-target.test.ts +0 -787
  201. package/src/internal/resolved-connections.test.ts +0 -295
  202. package/src/internal/router.test.ts +0 -57
  203. package/src/internal/sdk-runner.test.ts +0 -290
  204. package/src/internal/session-engine.coalesce.test.ts +0 -169
  205. package/src/internal/session-engine.concurrency.test.ts +0 -250
  206. package/src/internal/session-engine.host-oauth-mcp.test.ts +0 -110
  207. package/src/internal/session-engine.interrupt.test.ts +0 -577
  208. package/src/internal/session-engine.storage.test.ts +0 -547
  209. package/src/internal/session-urls.test.ts +0 -28
  210. package/src/internal/sessions-client.test.ts +0 -518
  211. package/src/internal/storage-coordinator.test.ts +0 -517
  212. package/src/internal/tool-call.test.ts +0 -458
  213. package/src/internal/tool-result.test.ts +0 -52
  214. package/src/internal/trajectory.approvals.test.ts +0 -83
  215. package/src/internal/trajectory.subagents.test.ts +0 -198
  216. package/src/internal/turn-governor.test.ts +0 -137
  217. package/src/internal/update-check.test.ts +0 -485
  218. package/src/internal/workspace.test.ts +0 -81
  219. package/src/storage-backends/cursor-hosted.test.ts +0 -121
@@ -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
- });