@cursor/july 0.1.24 → 0.1.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (205) hide show
  1. package/dist/bin/agent-serve.js +0 -0
  2. package/dist/channels/github/instrument.d.ts +20 -0
  3. package/dist/channels/github/instrument.d.ts.map +1 -0
  4. package/dist/docs/404.html +1 -1
  5. package/dist/docs/ab.html +2 -2
  6. package/dist/docs/assets/{app.CvSGaAxk.js → app.DYcC9FY-.js} +1 -1
  7. package/dist/docs/assets/chunks/@localSearchIndexroot.BQTzJjR_.js +1 -0
  8. package/dist/docs/assets/chunks/{VPLocalSearchBox.J1jJbCvs.js → VPLocalSearchBox.o4N_knTV.js} +1 -1
  9. package/dist/docs/assets/chunks/{theme.C7vfzr7h.js → theme.DQ-njyo0.js} +2 -2
  10. package/dist/docs/building-with-agents.html +2 -2
  11. package/dist/docs/concepts.html +2 -2
  12. package/dist/docs/deployment.html +2 -2
  13. package/dist/docs/evals.html +2 -2
  14. package/dist/docs/example-agents/approval-buddy.html +2 -2
  15. package/dist/docs/example-agents/benny.html +2 -2
  16. package/dist/docs/example-agents/bugbot.html +2 -2
  17. package/dist/docs/example-agents/codebase-wiki.html +2 -2
  18. package/dist/docs/example-agents/codeowners-review.html +2 -2
  19. package/dist/docs/example-agents/concierge.html +2 -2
  20. package/dist/docs/example-agents/fsd.html +2 -2
  21. package/dist/docs/example-agents/index.html +2 -2
  22. package/dist/docs/example-agents/knowledge-base.html +2 -2
  23. package/dist/docs/example-agents/oncall.html +2 -2
  24. package/dist/docs/example-agents/security-reviewer.html +2 -2
  25. package/dist/docs/example-agents/slack-agent.html +2 -2
  26. package/dist/docs/example-agents/weather-agent.html +2 -2
  27. package/dist/docs/guides/agent-to-agent.html +2 -2
  28. package/dist/docs/guides/cloud-runtime.html +2 -2
  29. package/dist/docs/guides/github.html +2 -2
  30. package/dist/docs/guides/human-in-the-loop.html +2 -2
  31. package/dist/docs/guides/mcp-oauth.html +2 -2
  32. package/dist/docs/guides/slack.html +2 -2
  33. package/dist/docs/guides/webhooks.html +2 -2
  34. package/dist/docs/hillclimbing.html +2 -2
  35. package/dist/docs/index.html +2 -2
  36. package/dist/docs/quickstart.html +2 -2
  37. package/dist/docs/reference/agent-config.html +2 -2
  38. package/dist/docs/reference/channels.html +2 -2
  39. package/dist/docs/reference/cli.html +2 -2
  40. package/dist/docs/reference/connections.html +2 -2
  41. package/dist/docs/reference/hooks.html +2 -2
  42. package/dist/docs/reference/http-api.html +2 -2
  43. package/dist/docs/reference/instructions.html +2 -2
  44. package/dist/docs/reference/playground.html +2 -2
  45. package/dist/docs/reference/project-layout.html +2 -2
  46. package/dist/docs/reference/prompt.html +2 -2
  47. package/dist/docs/reference/schedules.html +2 -2
  48. package/dist/docs/reference/sessions.html +2 -2
  49. package/dist/docs/reference/skills.html +2 -2
  50. package/dist/docs/reference/subagents.html +2 -2
  51. package/dist/docs/reference/tools.html +2 -2
  52. package/dist/docs/scaffolding-agents.html +2 -2
  53. package/dist/docs/storage.html +2 -2
  54. package/dist/docs/troubleshooting.html +2 -2
  55. package/dist/internal/json-dir-store.d.ts +32 -0
  56. package/dist/internal/json-dir-store.d.ts.map +1 -0
  57. package/dist/internal/json-dir-store.js +100 -0
  58. package/dist/playground/assets/index-CjOQ4hN9.css +1 -0
  59. package/dist/playground/assets/{index-DTG9OsPV.js → index-DqXdAFGa.js} +41 -41
  60. package/dist/playground/index.html +2 -2
  61. package/package.json +31 -24
  62. package/src/artifacts.ts +78 -0
  63. package/src/bin/agent-serve.version.test.ts +64 -0
  64. package/src/channels/github/api.test.ts +64 -0
  65. package/src/channels/github/auth.test.ts +105 -0
  66. package/src/channels/github/cursor-account.test.ts +204 -0
  67. package/src/channels/github/forward.test.ts +457 -0
  68. package/src/channels/github/github-channel.ts +19 -2
  69. package/src/channels/github/github.test.ts +985 -0
  70. package/src/channels/github/replay.test.ts +179 -0
  71. package/src/channels/github/types.ts +6 -0
  72. package/src/channels/slack/api.post-message.test.ts +148 -0
  73. package/src/channels/slack/api.ts +3 -1
  74. package/src/channels/slack/approvals.test.ts +328 -0
  75. package/src/channels/slack/block-actions.test.ts +469 -0
  76. package/src/channels/slack/bot-mentions.test.ts +267 -0
  77. package/src/channels/slack/channel-watch.test.ts +363 -0
  78. package/src/channels/slack/cursor-account.test.ts +301 -0
  79. package/src/channels/slack/cursor-account.ts +3 -1
  80. package/src/channels/slack/defaults.final-post.test.ts +182 -0
  81. package/src/channels/slack/dispatch.test.ts +875 -0
  82. package/src/channels/slack/dispatch.ts +12 -1
  83. package/src/channels/slack/eval-directive.test.ts +273 -0
  84. package/src/channels/slack/interactive.ts +3 -0
  85. package/src/channels/slack/message-body.test.ts +54 -0
  86. package/src/channels/slack/nudge-store.test.ts +143 -0
  87. package/src/channels/slack/slack-channel.ts +6 -0
  88. package/src/channels/slack/slack.test.ts +391 -0
  89. package/src/channels/slack/stop.test.ts +23 -0
  90. package/src/channels/slack/thread-context.test.ts +202 -0
  91. package/src/channels/slack/types.ts +6 -0
  92. package/src/evals/assertions.test.ts +617 -0
  93. package/src/evals/assertions.ts +37 -1
  94. package/src/evals/expect.test.ts +144 -0
  95. package/src/evals/judge.test.ts +181 -0
  96. package/src/evals/loaders.test.ts +132 -0
  97. package/src/evals/matchers.test.ts +95 -0
  98. package/src/evals/reporters.test.ts +303 -0
  99. package/src/evals/run-facts.test.ts +259 -0
  100. package/src/evals.ts +1 -0
  101. package/src/index.ts +1 -0
  102. package/src/internal/ab-snapshot.test.ts +325 -0
  103. package/src/internal/approval-gate.test.ts +49 -0
  104. package/src/internal/approvals.integration.test.ts +383 -0
  105. package/src/internal/artifacts-store.test.ts +283 -0
  106. package/src/internal/artifacts-store.ts +290 -0
  107. package/src/internal/authored-loaders.test.ts +31 -0
  108. package/src/internal/builtin-tools/artifacts.test.ts +247 -0
  109. package/src/internal/builtin-tools/artifacts.ts +74 -0
  110. package/src/internal/builtin-tools/index.ts +21 -0
  111. package/src/internal/builtin-tools/reminders.test.ts +201 -0
  112. package/src/internal/channel-route-schema.test.ts +294 -0
  113. package/src/internal/chat-attach.test.ts +262 -0
  114. package/src/internal/cli-deploy.test.ts +1991 -0
  115. package/src/internal/cli-docs.test.ts +161 -0
  116. package/src/internal/cli-mcp.test.ts +789 -0
  117. package/src/internal/cli-skills.test.ts +133 -0
  118. package/src/internal/cli-slack.test.ts +1654 -0
  119. package/src/internal/cli-slack.ts +13 -4
  120. package/src/internal/cloud-merge.test.ts +74 -0
  121. package/src/internal/cron.test.ts +22 -0
  122. package/src/internal/cursor/account-mcp.test.ts +807 -0
  123. package/src/internal/cursor/backend-client.test.ts +591 -0
  124. package/src/internal/cursor/credentials.test.ts +351 -0
  125. package/src/internal/cursor/github-credentials.test.ts +136 -0
  126. package/src/internal/cursor-account-mcp-auth.test.ts +310 -0
  127. package/src/internal/cursor-account.integration.test.ts +441 -0
  128. package/src/internal/cursor-event-relay.test.ts +746 -0
  129. package/src/internal/cursor-github-credentials.integration.test.ts +271 -0
  130. package/src/internal/cursor-slack-relay.test.ts +525 -0
  131. package/src/internal/deploy-source.test.ts +111 -0
  132. package/src/internal/discovery.artifact-tool.test.ts +136 -0
  133. package/src/internal/discovery.artifacts.test.ts +119 -0
  134. package/src/internal/discovery.builtin-tools.test.ts +94 -0
  135. package/src/internal/discovery.concurrency.test.ts +60 -0
  136. package/src/internal/discovery.cursor-account.test.ts +133 -0
  137. package/src/internal/discovery.cwd.test.ts +83 -0
  138. package/src/internal/discovery.hosting.test.ts +80 -0
  139. package/src/internal/discovery.identity.test.ts +44 -0
  140. package/src/internal/discovery.ts +102 -1
  141. package/src/internal/distribution.ts +1 -0
  142. package/src/internal/docs-site.test.ts +66 -0
  143. package/src/internal/duration.test.ts +29 -0
  144. package/src/internal/eval-judge-model.test.ts +187 -0
  145. package/src/internal/eval-run-store.cancel.test.ts +142 -0
  146. package/src/internal/eval-run-store.storage.test.ts +211 -0
  147. package/src/internal/eval-runner.http.test.ts +403 -0
  148. package/src/internal/eval-runner.run.test.ts +928 -0
  149. package/src/internal/evals-client.test.ts +307 -0
  150. package/src/internal/event-mapper.test.ts +243 -0
  151. package/src/internal/github-fanout.test.ts +213 -0
  152. package/src/internal/handleAgentServeTrigger.test.ts +185 -0
  153. package/src/internal/host-kv.test.ts +82 -0
  154. package/src/internal/host-platforms.test.ts +126 -0
  155. package/src/internal/http-channel.test.ts +402 -0
  156. package/src/internal/init-project.test.ts +270 -0
  157. package/src/internal/install-cursor-skills.test.ts +262 -0
  158. package/src/internal/local-env.test.ts +120 -0
  159. package/src/internal/log-ring.test.ts +31 -0
  160. package/src/internal/logs-client.test.ts +350 -0
  161. package/src/internal/mcp-endpoint.test.ts +436 -0
  162. package/src/internal/mcp-host.test.ts +298 -0
  163. package/src/internal/mcp-oauth.test.ts +148 -0
  164. package/src/internal/net.test.ts +17 -0
  165. package/src/internal/peer-connections.test.ts +128 -0
  166. package/src/internal/peer-mcp.integration.test.ts +289 -0
  167. package/src/internal/playground/toolchain.test.ts +53 -0
  168. package/src/internal/playground-cli.test.ts +187 -0
  169. package/src/internal/playground-proxy.test.ts +376 -0
  170. package/src/internal/prompt-context.integration.test.ts +232 -0
  171. package/src/internal/prompt-context.test.ts +127 -0
  172. package/src/internal/reminder-runner.test.ts +432 -0
  173. package/src/internal/reminder-runner.ts +1 -0
  174. package/src/internal/reminder-store.test.ts +53 -0
  175. package/src/internal/request-headers.test.ts +27 -0
  176. package/src/internal/resolve-prod-target.test.ts +787 -0
  177. package/src/internal/resolved-connections.test.ts +295 -0
  178. package/src/internal/router.test.ts +57 -0
  179. package/src/internal/schedule-runner.ts +1 -0
  180. package/src/internal/sdk-runner.test.ts +290 -0
  181. package/src/internal/server.artifacts.test.ts +334 -0
  182. package/src/internal/server.ts +45 -0
  183. package/src/internal/session-engine.artifacts.test.ts +293 -0
  184. package/src/internal/session-engine.coalesce.test.ts +169 -0
  185. package/src/internal/session-engine.concurrency.test.ts +250 -0
  186. package/src/internal/session-engine.host-oauth-mcp.test.ts +110 -0
  187. package/src/internal/session-engine.interrupt.test.ts +577 -0
  188. package/src/internal/session-engine.storage.test.ts +547 -0
  189. package/src/internal/session-engine.ts +129 -1
  190. package/src/internal/session-urls.test.ts +28 -0
  191. package/src/internal/sessions-client.test.ts +518 -0
  192. package/src/internal/storage-coordinator.test.ts +517 -0
  193. package/src/internal/storage-coordinator.ts +62 -0
  194. package/src/internal/tool-call.test.ts +458 -0
  195. package/src/internal/tool-result.test.ts +52 -0
  196. package/src/internal/trajectory.approvals.test.ts +83 -0
  197. package/src/internal/trajectory.subagents.test.ts +198 -0
  198. package/src/internal/turn-governor.test.ts +137 -0
  199. package/src/internal/update-check.test.ts +485 -0
  200. package/src/internal/workspace.test.ts +207 -0
  201. package/src/storage-backends/cursor-hosted.test.ts +121 -0
  202. package/src/storage.ts +6 -0
  203. package/src/types.ts +152 -2
  204. package/dist/docs/assets/chunks/@localSearchIndexroot.CL2Y0Zmh.js +0 -1
  205. package/dist/playground/assets/index-CidizGZv.css +0 -1
@@ -0,0 +1,301 @@
1
+ import { describe, expect, it, vi } from "vitest";
2
+ import type { ArtifactsApi, HostContext, SendMessageFn } from "../../types.js";
3
+ import {
4
+ type CursorSlackEnvelope,
5
+ createPendingSlackApiTransport,
6
+ dispatchCursorSlackEnvelope,
7
+ getSlackCursorAccountRuntime,
8
+ } from "./cursor-account.js";
9
+ import { slackChannel } from "./slack-channel.js";
10
+
11
+ function envelope(
12
+ overrides: Partial<CursorSlackEnvelope> = {}
13
+ ): CursorSlackEnvelope {
14
+ return {
15
+ eventName: "app_mention",
16
+ slackTeamId: "T0TEST",
17
+ channelId: "C0100",
18
+ channelType: "channel",
19
+ threadTs: "111.222",
20
+ messageTs: "111.222",
21
+ slackUserId: "U0AAA",
22
+ text: "benny hello <@U0BBB>",
23
+ agentName: "Benny",
24
+ consumerId: "consumer-1",
25
+ matchedBy: "name",
26
+ eventId: "Ev1",
27
+ receivedAtMs: Date.now(),
28
+ ...overrides,
29
+ };
30
+ }
31
+
32
+ function fakeHost(): HostContext {
33
+ return {} as HostContext;
34
+ }
35
+
36
+ function testArtifacts(): ArtifactsApi {
37
+ return {
38
+ tag: async () => {
39
+ throw new Error("artifacts not configured in test");
40
+ },
41
+ list: async () => [],
42
+ };
43
+ }
44
+
45
+ describe("slackChannel({ cursorAccount: true })", () => {
46
+ it("registers a runtime with a pending transport and no Socket Mode routes", () => {
47
+ const definition = slackChannel({ cursorAccount: true });
48
+ const runtime = getSlackCursorAccountRuntime(definition);
49
+ expect(runtime).toBeDefined();
50
+ expect(runtime?.transport.kind).toBe("api-transport");
51
+ expect(definition.meta?.slackCursorAccount).toBe(true);
52
+ // Plain socket-mode channels register nothing.
53
+ expect(
54
+ getSlackCursorAccountRuntime(slackChannel({ envPrefix: "X" }))
55
+ ).toBeUndefined();
56
+ });
57
+
58
+ it("rejects mixing cursorAccount with a dedicated Slack app credentials", () => {
59
+ expect(() =>
60
+ slackChannel({ cursorAccount: true, envPrefix: "BUGBOT" })
61
+ ).toThrow(/do not also set credentials\/envPrefix/);
62
+ expect(() =>
63
+ slackChannel({
64
+ cursorAccount: true,
65
+ credentials: { botToken: "xoxb-x" },
66
+ })
67
+ ).toThrow(/do not also set credentials\/envPrefix/);
68
+ });
69
+
70
+ it("rejects channelPosts, toolApprovals, interactivity, and mention/DM off", () => {
71
+ expect(() =>
72
+ slackChannel({
73
+ cursorAccount: true,
74
+ engagement: { channelPosts: { allow: ["C0TEST"] } },
75
+ })
76
+ ).toThrow(/channelPosts/);
77
+ // Approvals ride Socket Mode interactive envelopes; there is no relay
78
+ // tap over the Cursor connection, so both toggles reject at construction.
79
+ expect(() =>
80
+ slackChannel({
81
+ cursorAccount: true,
82
+ toolApprovals: true,
83
+ })
84
+ ).toThrow(/toolApprovals/);
85
+ expect(() =>
86
+ slackChannel({
87
+ cursorAccount: true,
88
+ interactivity: true,
89
+ })
90
+ ).toThrow(/interactivity/);
91
+ expect(() =>
92
+ slackChannel({
93
+ cursorAccount: true,
94
+ onBlockAction: () => null,
95
+ })
96
+ ).toThrow(/onBlockAction/);
97
+ expect(() =>
98
+ slackChannel({
99
+ cursorAccount: true,
100
+ engagement: { mentions: false },
101
+ })
102
+ ).toThrow(/mentions/);
103
+ expect(() =>
104
+ slackChannel({
105
+ cursorAccount: true,
106
+ engagement: { directMessages: false },
107
+ })
108
+ ).toThrow(/directMessages/);
109
+ });
110
+
111
+ it("rejects agentName values that contain whitespace", () => {
112
+ expect(() =>
113
+ slackChannel({
114
+ cursorAccount: true,
115
+ // Cast: string literals with spaces are a type error; runtime still
116
+ // guards dynamic / widened strings.
117
+ agentName: "Approval Buddy" as string,
118
+ })
119
+ ).toThrow(/single token with no whitespace/);
120
+ });
121
+
122
+ it("calls through the transport once bound, soft-failing before", async () => {
123
+ const transport = createPendingSlackApiTransport();
124
+ expect(await transport.call("chat.postMessage", {})).toEqual({
125
+ ok: false,
126
+ error: "cursor_slack_relay_not_started",
127
+ });
128
+ const calls: Array<{ method: string; args: Record<string, unknown> }> = [];
129
+ transport.bind(async (method, args) => {
130
+ calls.push({ method, args });
131
+ return { ok: true, ts: "1.2" };
132
+ });
133
+ expect(await transport.call("chat.postMessage", { channel: "C1" })).toEqual(
134
+ { ok: true, ts: "1.2" }
135
+ );
136
+ expect(calls).toEqual([
137
+ { method: "chat.postMessage", args: { channel: "C1" } },
138
+ ]);
139
+ });
140
+ });
141
+
142
+ describe("dispatchCursorSlackEnvelope", () => {
143
+ function setup(options?: Parameters<typeof slackChannel>[0]) {
144
+ const definition = slackChannel({
145
+ cursorAccount: true,
146
+ agentName: "Benny",
147
+ ...options,
148
+ });
149
+ const runtime = getSlackCursorAccountRuntime(definition);
150
+ if (runtime === undefined) {
151
+ throw new Error("runtime not registered");
152
+ }
153
+ const apiCalls: Array<{ method: string; args: Record<string, unknown> }> =
154
+ [];
155
+ runtime.transport.bind(async (method, args) => {
156
+ apiCalls.push({ method, args });
157
+ return { ok: true, ts: "999.111" };
158
+ });
159
+ const sent: Array<{ message: string; options: any }> = [];
160
+ const send: SendMessageFn = async (message, sendOptions) => {
161
+ sent.push({ message, options: sendOptions });
162
+ return {
163
+ id: "ses_1",
164
+ isNew: true,
165
+ channelId: "slack",
166
+ continuationToken: "next",
167
+ } as any;
168
+ };
169
+ return { runtime, apiCalls, sent, send };
170
+ }
171
+
172
+ it("dispatches a mention into a thread-keyed session and proxies thread setup calls", async () => {
173
+ const { runtime, apiCalls, sent, send } = setup();
174
+ await dispatchCursorSlackEnvelope({
175
+ runtime,
176
+ envelope: envelope(),
177
+ send,
178
+ host: fakeHost(),
179
+ artifacts: testArtifacts(),
180
+ });
181
+
182
+ expect(sent).toHaveLength(1);
183
+ expect(sent[0].options.continuationToken).toBe("C0100:111.222");
184
+ expect(sent[0].options.auth).toMatchObject({
185
+ authenticator: "slack",
186
+ principalId: "slack:T0TEST:C0100:111.222",
187
+ });
188
+ expect(sent[0].message).toContain("benny hello @U0BBB");
189
+ expect(sent[0].message).toContain("<slack_context>");
190
+
191
+ // Root message: title + typing go through the bound transport.
192
+ const methods = apiCalls.map((call) => call.method);
193
+ expect(methods).toContain("assistant.threads.setTitle");
194
+ expect(methods).toContain("assistant.threads.setStatus");
195
+ });
196
+
197
+ it("hands the artifacts facade to the mention handler binding", async () => {
198
+ const tags: Array<Parameters<ArtifactsApi["tag"]>[0]> = [];
199
+ const artifacts: ArtifactsApi = {
200
+ tag: async (input) => {
201
+ tags.push(input);
202
+ return {
203
+ id: `art_${tags.length}`,
204
+ kind: input.kind ?? "artifact",
205
+ key: input.key,
206
+ data: input.data,
207
+ source: "host",
208
+ createdAt: new Date().toISOString(),
209
+ updatedAt: new Date().toISOString(),
210
+ };
211
+ },
212
+ list: async () => [],
213
+ };
214
+ const { runtime, send } = setup({
215
+ onAppMention: async (ctx) => {
216
+ await ctx.artifacts.tag({ key: "from-relay", data: "r" });
217
+ return null;
218
+ },
219
+ });
220
+ await dispatchCursorSlackEnvelope({
221
+ runtime,
222
+ envelope: envelope(),
223
+ send,
224
+ host: fakeHost(),
225
+ artifacts,
226
+ });
227
+ expect(tags).toEqual([{ key: "from-relay", data: "r" }]);
228
+ });
229
+
230
+ it("routes DMs to the direct-message handler", async () => {
231
+ const kinds: string[] = [];
232
+ const { runtime, send } = setup({
233
+ onAppMention: (ctx, message) => {
234
+ kinds.push("mention");
235
+ return null;
236
+ },
237
+ onDirectMessage: (ctx, message) => {
238
+ kinds.push("dm");
239
+ return null;
240
+ },
241
+ });
242
+ await dispatchCursorSlackEnvelope({
243
+ runtime,
244
+ envelope: envelope({
245
+ channelType: "im",
246
+ channelId: "D0200",
247
+ eventId: "Ev2",
248
+ }),
249
+ send,
250
+ host: fakeHost(),
251
+ artifacts: testArtifacts(),
252
+ });
253
+ await dispatchCursorSlackEnvelope({
254
+ runtime,
255
+ envelope: envelope({ eventId: "Ev3" }),
256
+ send,
257
+ host: fakeHost(),
258
+ artifacts: testArtifacts(),
259
+ });
260
+ expect(kinds).toEqual(["dm", "mention"]);
261
+ });
262
+
263
+ it("dedupes by Slack event id", async () => {
264
+ const { runtime, sent, send } = setup();
265
+ await dispatchCursorSlackEnvelope({
266
+ runtime,
267
+ envelope: envelope({ eventId: "EvDup" }),
268
+ send,
269
+ host: fakeHost(),
270
+ artifacts: testArtifacts(),
271
+ });
272
+ await dispatchCursorSlackEnvelope({
273
+ runtime,
274
+ envelope: envelope({ eventId: "EvDup" }),
275
+ send,
276
+ host: fakeHost(),
277
+ artifacts: testArtifacts(),
278
+ });
279
+ expect(sent).toHaveLength(1);
280
+ });
281
+
282
+ it("claimed-thread replies dispatch as mention-kind follow-ups on the same session key", async () => {
283
+ const { runtime, sent, send } = setup();
284
+ await dispatchCursorSlackEnvelope({
285
+ runtime,
286
+ envelope: envelope({
287
+ eventName: "message",
288
+ matchedBy: "thread",
289
+ messageTs: "111.333",
290
+ text: "and tomorrow?",
291
+ eventId: "Ev4",
292
+ }),
293
+ send,
294
+ host: fakeHost(),
295
+ artifacts: testArtifacts(),
296
+ });
297
+ expect(sent).toHaveLength(1);
298
+ expect(sent[0].options.continuationToken).toBe("C0100:111.222");
299
+ expect(sent[0].message).toContain("and tomorrow?");
300
+ });
301
+ });
@@ -12,7 +12,7 @@
12
12
  * dispatches relayed envelopes through the pack's normal inbound path.
13
13
  */
14
14
 
15
- import type { HostContext, SendMessageFn } from "../../types.js";
15
+ import type { ArtifactsApi, HostContext, SendMessageFn } from "../../types.js";
16
16
  import { dispatchInboundMessage } from "./dispatch.js";
17
17
  import type { EventIdDedupe } from "./event-id-dedupe.js";
18
18
  import { slackTextToMarkdown } from "./inbound.js";
@@ -114,6 +114,7 @@ export async function dispatchCursorSlackEnvelope(args: {
114
114
  envelope: CursorSlackEnvelope;
115
115
  send: SendMessageFn;
116
116
  host: HostContext;
117
+ artifacts: ArtifactsApi;
117
118
  hasContinuationSession?: (continuationToken: string) => Promise<boolean>;
118
119
  isContinuationBusy?: (continuationToken: string) => Promise<boolean>;
119
120
  getContinuationLastBotMessageTs?: (
@@ -167,6 +168,7 @@ export async function dispatchCursorSlackEnvelope(args: {
167
168
  send: args.send,
168
169
  credentials: runtime.credentials,
169
170
  host: args.host,
171
+ artifacts: args.artifacts,
170
172
  log,
171
173
  evalCommandsEnabled: runtime.options.evalCommands !== false,
172
174
  cursorAgentName: envelope.agentName,
@@ -0,0 +1,182 @@
1
+ import { beforeEach, describe, expect, it, vi } from "vitest";
2
+ import type {
3
+ ChannelEventContext,
4
+ ChannelEventHandlers,
5
+ SessionContext,
6
+ SessionEvent,
7
+ } from "../../types.js";
8
+ import type { SlackChannelState } from "./types.js";
9
+
10
+ const mocks = vi.hoisted(() => ({
11
+ postMessage: vi.fn(),
12
+ updateMessage: vi.fn(),
13
+ setThreadStatus: vi.fn(),
14
+ startChatStream: vi.fn(),
15
+ appendChatStream: vi.fn(),
16
+ stopChatStream: vi.fn(),
17
+ }));
18
+
19
+ vi.mock("./api.js", () => ({
20
+ postMessage: mocks.postMessage,
21
+ updateMessage: mocks.updateMessage,
22
+ setThreadStatus: mocks.setThreadStatus,
23
+ startChatStream: mocks.startChatStream,
24
+ appendChatStream: mocks.appendChatStream,
25
+ stopChatStream: mocks.stopChatStream,
26
+ truncateTypingStatus: (text: string) => text.slice(0, 50),
27
+ }));
28
+
29
+ vi.mock("./assistant.js", () => ({
30
+ firstNonEmptyLine: (text: string) =>
31
+ text
32
+ .split("\n")
33
+ .map((line) => line.trim())
34
+ .find((line) => line.length > 0),
35
+ maybeSetSuggestedPrompts: vi.fn(),
36
+ }));
37
+
38
+ import { buildDefaultEvents } from "./defaults.js";
39
+
40
+ let eventIndex = 0;
41
+
42
+ function evt<T extends SessionEvent["type"]>(
43
+ partial: Omit<Extract<SessionEvent, { type: T }>, "index" | "at"> &
44
+ Partial<Pick<SessionEvent, "index" | "at">>
45
+ ): Extract<SessionEvent, { type: T }> {
46
+ return {
47
+ index: eventIndex++,
48
+ at: new Date().toISOString(),
49
+ ...partial,
50
+ } as Extract<SessionEvent, { type: T }>;
51
+ }
52
+
53
+ function channelOf(
54
+ state: SlackChannelState
55
+ ): ChannelEventContext<SlackChannelState> {
56
+ return {
57
+ channelId: "slack",
58
+ state,
59
+ continuationToken: null,
60
+ setContinuationToken: async () => {},
61
+ };
62
+ }
63
+
64
+ const sessionCtx: SessionContext = {
65
+ session: {
66
+ id: "s1",
67
+ channelId: "slack",
68
+ mode: "chat",
69
+ auth: null,
70
+ },
71
+ };
72
+
73
+ describe("buildDefaultEvents streaming:false (cursorAccount)", () => {
74
+ let handlers: ChannelEventHandlers<SlackChannelState>;
75
+
76
+ beforeEach(() => {
77
+ vi.clearAllMocks();
78
+ eventIndex = 0;
79
+ mocks.postMessage.mockResolvedValue({ ts: "9.9" });
80
+ mocks.setThreadStatus.mockResolvedValue(undefined);
81
+ handlers = buildDefaultEvents({ streaming: false });
82
+ });
83
+
84
+ it("uses setStatus for thinking and a single final postMessage", async () => {
85
+ const channel = channelOf({
86
+ channelId: "C1",
87
+ threadTs: "1.0",
88
+ teamId: "T1",
89
+ triggeringUserId: "U1",
90
+ pendingToolCallMessage: null,
91
+ lastReasoningTypingAtMs: null,
92
+ lastReasoningTypingStatus: null,
93
+ streamTs: null,
94
+ streamChannelId: null,
95
+ lastPostedText: null,
96
+ });
97
+
98
+ await handlers["turn.started"]!(
99
+ evt({
100
+ type: "turn.started",
101
+ sessionId: "s1",
102
+ turnId: "t1",
103
+ data: {},
104
+ }),
105
+ channel,
106
+ sessionCtx
107
+ );
108
+ expect(mocks.startChatStream).not.toHaveBeenCalled();
109
+ expect(mocks.postMessage).not.toHaveBeenCalled();
110
+ expect(mocks.setThreadStatus).toHaveBeenCalledWith(
111
+ expect.objectContaining({ status: "Working…" })
112
+ );
113
+
114
+ await handlers["actions.requested"]!(
115
+ evt({
116
+ type: "actions.requested",
117
+ sessionId: "s1",
118
+ turnId: "t1",
119
+ data: {
120
+ calls: [{ callId: "c1", toolName: "get_weather", args: {} }],
121
+ },
122
+ }),
123
+ channel,
124
+ sessionCtx
125
+ );
126
+ expect(mocks.updateMessage).not.toHaveBeenCalled();
127
+ expect(mocks.setThreadStatus).toHaveBeenCalledWith(
128
+ expect.objectContaining({ status: "Running get_weather…" })
129
+ );
130
+
131
+ await handlers["message.completed"]!(
132
+ evt({
133
+ type: "message.completed",
134
+ sessionId: "s1",
135
+ turnId: "t1",
136
+ data: { text: "Sunny in SF", finishReason: "stop" },
137
+ }),
138
+ channel,
139
+ sessionCtx
140
+ );
141
+ expect(mocks.updateMessage).not.toHaveBeenCalled();
142
+ expect(mocks.postMessage).toHaveBeenCalledTimes(1);
143
+ expect(mocks.postMessage).toHaveBeenCalledWith(
144
+ expect.objectContaining({ text: "Sunny in SF" })
145
+ );
146
+ });
147
+
148
+ it("posts the scrubbed turn.failed reason into the thread", async () => {
149
+ const channel = channelOf({
150
+ channelId: "C1",
151
+ threadTs: "1.0",
152
+ teamId: "T1",
153
+ triggeringUserId: "U1",
154
+ pendingToolCallMessage: null,
155
+ lastReasoningTypingAtMs: null,
156
+ lastReasoningTypingStatus: null,
157
+ streamTs: null,
158
+ streamChannelId: null,
159
+ lastPostedText: null,
160
+ });
161
+
162
+ await handlers["turn.failed"]!(
163
+ evt({
164
+ type: "turn.failed",
165
+ sessionId: "s1",
166
+ turnId: "t1",
167
+ data: {
168
+ message: String.raw`Authentication error at C:\Users\alice\secret and /home/ubuntu/secret`,
169
+ },
170
+ }),
171
+ channel,
172
+ sessionCtx
173
+ );
174
+
175
+ expect(mocks.postMessage).toHaveBeenCalledWith(
176
+ expect.objectContaining({
177
+ text: "I hit an error while handling your request: Authentication error at [path] and [path]",
178
+ threadTs: "1.0",
179
+ })
180
+ );
181
+ });
182
+ });