@cursor/july 0.1.25 → 0.1.27

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 (288) 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 +31 -9
  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/cursor-account.d.ts +2 -1
  17. package/dist/channels/slack/cursor-account.d.ts.map +1 -1
  18. package/dist/channels/slack/cursor-account.js +1 -1
  19. package/dist/channels/slack/dispatch.d.ts +4 -1
  20. package/dist/channels/slack/dispatch.d.ts.map +1 -1
  21. package/dist/channels/slack/dispatch.js +3 -3
  22. package/dist/channels/slack/interactive.d.ts +2 -1
  23. package/dist/channels/slack/interactive.d.ts.map +1 -1
  24. package/dist/channels/slack/interactive.js +1 -0
  25. package/dist/channels/slack/slack-channel.d.ts.map +1 -1
  26. package/dist/channels/slack/slack-channel.js +4 -3
  27. package/dist/channels/slack/types.d.ts +6 -1
  28. package/dist/channels/slack/types.d.ts.map +1 -1
  29. package/dist/docs/404.html +1 -1
  30. package/dist/docs/ab.html +2 -2
  31. package/dist/docs/assets/{app.DYcC9FY-.js → app.BICLoJYF.js} +1 -1
  32. package/dist/docs/assets/chunks/@localSearchIndexroot.CQJytDwU.js +1 -0
  33. package/dist/docs/assets/chunks/{VPLocalSearchBox.o4N_knTV.js → VPLocalSearchBox.wN4Ko9dT.js} +1 -1
  34. package/dist/docs/assets/chunks/{theme.DQ-njyo0.js → theme.dnnTE-Co.js} +2 -2
  35. package/dist/docs/building-with-agents.html +2 -2
  36. package/dist/docs/concepts.html +2 -2
  37. package/dist/docs/deployment.html +2 -2
  38. package/dist/docs/evals.html +2 -2
  39. package/dist/docs/example-agents/approval-buddy.html +2 -2
  40. package/dist/docs/example-agents/benny.html +2 -2
  41. package/dist/docs/example-agents/bugbot.html +2 -2
  42. package/dist/docs/example-agents/codebase-wiki.html +2 -2
  43. package/dist/docs/example-agents/codeowners-review.html +2 -2
  44. package/dist/docs/example-agents/concierge.html +2 -2
  45. package/dist/docs/example-agents/fsd.html +2 -2
  46. package/dist/docs/example-agents/index.html +2 -2
  47. package/dist/docs/example-agents/knowledge-base.html +2 -2
  48. package/dist/docs/example-agents/oncall.html +2 -2
  49. package/dist/docs/example-agents/security-reviewer.html +2 -2
  50. package/dist/docs/example-agents/slack-agent.html +2 -2
  51. package/dist/docs/example-agents/weather-agent.html +2 -2
  52. package/dist/docs/guides/agent-to-agent.html +2 -2
  53. package/dist/docs/guides/cloud-runtime.html +2 -2
  54. package/dist/docs/guides/github.html +2 -2
  55. package/dist/docs/guides/human-in-the-loop.html +2 -2
  56. package/dist/docs/guides/mcp-oauth.html +2 -2
  57. package/dist/docs/guides/slack.html +2 -2
  58. package/dist/docs/guides/webhooks.html +2 -2
  59. package/dist/docs/hillclimbing.html +2 -2
  60. package/dist/docs/index.html +2 -2
  61. package/dist/docs/quickstart.html +2 -2
  62. package/dist/docs/reference/agent-config.html +2 -2
  63. package/dist/docs/reference/channels.html +2 -2
  64. package/dist/docs/reference/cli.html +2 -2
  65. package/dist/docs/reference/connections.html +2 -2
  66. package/dist/docs/reference/hooks.html +2 -2
  67. package/dist/docs/reference/http-api.html +2 -2
  68. package/dist/docs/reference/instructions.html +2 -2
  69. package/dist/docs/reference/playground.html +2 -2
  70. package/dist/docs/reference/project-layout.html +2 -2
  71. package/dist/docs/reference/prompt.html +2 -2
  72. package/dist/docs/reference/schedules.html +2 -2
  73. package/dist/docs/reference/sessions.html +2 -2
  74. package/dist/docs/reference/skills.html +2 -2
  75. package/dist/docs/reference/subagents.html +2 -2
  76. package/dist/docs/reference/tools.html +2 -2
  77. package/dist/docs/scaffolding-agents.html +2 -2
  78. package/dist/docs/storage.html +2 -2
  79. package/dist/docs/troubleshooting.html +2 -2
  80. package/dist/evals/assertions.d.ts +10 -1
  81. package/dist/evals/assertions.d.ts.map +1 -1
  82. package/dist/evals/assertions.js +12 -0
  83. package/dist/evals.d.ts +1 -1
  84. package/dist/evals.d.ts.map +1 -1
  85. package/dist/index.d.ts +1 -0
  86. package/dist/index.d.ts.map +1 -1
  87. package/dist/index.js +1 -0
  88. package/dist/internal/ab-fold.d.ts.map +1 -1
  89. package/dist/internal/ab-fold.js +4 -0
  90. package/dist/internal/ab-snapshot.d.ts.map +1 -1
  91. package/dist/internal/ab-snapshot.js +1 -0
  92. package/dist/internal/artifacts-store.d.ts +45 -0
  93. package/dist/internal/artifacts-store.d.ts.map +1 -0
  94. package/dist/internal/artifacts-store.js +250 -0
  95. package/dist/internal/builtin-tools/artifacts.d.ts +10 -0
  96. package/dist/internal/builtin-tools/artifacts.d.ts.map +1 -0
  97. package/dist/internal/builtin-tools/artifacts.js +73 -0
  98. package/dist/internal/builtin-tools/index.d.ts +8 -1
  99. package/dist/internal/builtin-tools/index.d.ts.map +1 -1
  100. package/dist/internal/builtin-tools/index.js +15 -0
  101. package/dist/internal/cli-ax.d.ts +11 -0
  102. package/dist/internal/cli-ax.d.ts.map +1 -1
  103. package/dist/internal/cli-ax.js +80 -0
  104. package/dist/internal/cli-slack.d.ts.map +1 -1
  105. package/dist/internal/cli-slack.js +14 -6
  106. package/dist/internal/discovery.d.ts.map +1 -1
  107. package/dist/internal/discovery.js +83 -2
  108. package/dist/internal/distribution.d.ts.map +1 -1
  109. package/dist/internal/distribution.js +1 -0
  110. package/dist/internal/model-pricing.d.ts +49 -0
  111. package/dist/internal/model-pricing.d.ts.map +1 -0
  112. package/dist/internal/model-pricing.js +377 -0
  113. package/dist/internal/reminder-runner.d.ts.map +1 -1
  114. package/dist/internal/reminder-runner.js +1 -0
  115. package/dist/internal/schedule-runner.d.ts.map +1 -1
  116. package/dist/internal/schedule-runner.js +1 -0
  117. package/dist/internal/sdk-runner.d.ts.map +1 -1
  118. package/dist/internal/sdk-runner.js +9 -1
  119. package/dist/internal/server.d.ts.map +1 -1
  120. package/dist/internal/server.js +39 -0
  121. package/dist/internal/session-cost.d.ts +49 -0
  122. package/dist/internal/session-cost.d.ts.map +1 -0
  123. package/dist/internal/session-cost.js +175 -0
  124. package/dist/internal/session-engine.d.ts +35 -1
  125. package/dist/internal/session-engine.d.ts.map +1 -1
  126. package/dist/internal/session-engine.js +128 -7
  127. package/dist/internal/storage-coordinator.d.ts +15 -0
  128. package/dist/internal/storage-coordinator.d.ts.map +1 -1
  129. package/dist/internal/storage-coordinator.js +52 -0
  130. package/dist/internal/trajectory.d.ts +9 -1
  131. package/dist/internal/trajectory.d.ts.map +1 -1
  132. package/dist/internal/trajectory.js +32 -5
  133. package/dist/playground/assets/index-BDCeW4uc.js +86 -0
  134. package/dist/playground/assets/index-Bul1WfrB.css +1 -0
  135. package/dist/playground/index.html +2 -2
  136. package/dist/storage.d.ts +4 -0
  137. package/dist/storage.d.ts.map +1 -1
  138. package/dist/storage.js +4 -0
  139. package/dist/types.d.ts +164 -1
  140. package/dist/types.d.ts.map +1 -1
  141. package/package.json +26 -26
  142. package/src/ab.ts +7 -0
  143. package/src/bin/agent-serve.ts +30 -2
  144. package/src/channels/github/github-channel.ts +19 -2
  145. package/src/channels/github/types.ts +6 -0
  146. package/src/channels/slack/api.ts +3 -1
  147. package/src/channels/slack/cursor-account.ts +3 -1
  148. package/src/channels/slack/dispatch.ts +12 -1
  149. package/src/channels/slack/interactive.ts +3 -0
  150. package/src/channels/slack/slack-channel.ts +6 -0
  151. package/src/channels/slack/types.ts +6 -0
  152. package/src/internal/ab-fold.ts +4 -0
  153. package/src/internal/ab-snapshot.ts +1 -0
  154. package/src/internal/cli-ax.ts +95 -0
  155. package/src/internal/model-pricing.ts +426 -0
  156. package/src/internal/reminder-runner.ts +1 -0
  157. package/src/internal/schedule-runner.ts +1 -0
  158. package/src/internal/sdk-runner.ts +10 -2
  159. package/src/internal/server.ts +2 -0
  160. package/src/internal/session-cost.ts +231 -0
  161. package/src/internal/session-engine.ts +32 -1
  162. package/src/internal/trajectory.ts +45 -3
  163. package/src/types.ts +42 -2
  164. package/dist/channels/github/instrument.d.ts +0 -20
  165. package/dist/channels/github/instrument.d.ts.map +0 -1
  166. package/dist/docs/assets/chunks/@localSearchIndexroot.BQTzJjR_.js +0 -1
  167. package/dist/internal/json-dir-store.d.ts +0 -32
  168. package/dist/internal/json-dir-store.d.ts.map +0 -1
  169. package/dist/internal/json-dir-store.js +0 -100
  170. package/dist/playground/assets/index-CjOQ4hN9.css +0 -1
  171. package/dist/playground/assets/index-DqXdAFGa.js +0 -85
  172. package/src/bin/agent-serve.version.test.ts +0 -64
  173. package/src/channels/github/api.test.ts +0 -64
  174. package/src/channels/github/auth.test.ts +0 -105
  175. package/src/channels/github/cursor-account.test.ts +0 -204
  176. package/src/channels/github/forward.test.ts +0 -457
  177. package/src/channels/github/github.test.ts +0 -943
  178. package/src/channels/github/replay.test.ts +0 -179
  179. package/src/channels/slack/api.post-message.test.ts +0 -148
  180. package/src/channels/slack/approvals.test.ts +0 -328
  181. package/src/channels/slack/block-actions.test.ts +0 -452
  182. package/src/channels/slack/bot-mentions.test.ts +0 -267
  183. package/src/channels/slack/channel-watch.test.ts +0 -363
  184. package/src/channels/slack/cursor-account.test.ts +0 -253
  185. package/src/channels/slack/defaults.final-post.test.ts +0 -182
  186. package/src/channels/slack/dispatch.test.ts +0 -795
  187. package/src/channels/slack/eval-directive.test.ts +0 -273
  188. package/src/channels/slack/message-body.test.ts +0 -54
  189. package/src/channels/slack/nudge-store.test.ts +0 -143
  190. package/src/channels/slack/slack.test.ts +0 -391
  191. package/src/channels/slack/stop.test.ts +0 -23
  192. package/src/channels/slack/thread-context.test.ts +0 -202
  193. package/src/evals/assertions.test.ts +0 -617
  194. package/src/evals/expect.test.ts +0 -144
  195. package/src/evals/judge.test.ts +0 -181
  196. package/src/evals/loaders.test.ts +0 -132
  197. package/src/evals/matchers.test.ts +0 -95
  198. package/src/evals/reporters.test.ts +0 -303
  199. package/src/evals/run-facts.test.ts +0 -259
  200. package/src/internal/ab-snapshot.test.ts +0 -325
  201. package/src/internal/approval-gate.test.ts +0 -49
  202. package/src/internal/approvals.integration.test.ts +0 -383
  203. package/src/internal/artifacts-store.test.ts +0 -283
  204. package/src/internal/authored-loaders.test.ts +0 -31
  205. package/src/internal/builtin-tools/artifacts.test.ts +0 -247
  206. package/src/internal/builtin-tools/reminders.test.ts +0 -201
  207. package/src/internal/channel-route-schema.test.ts +0 -294
  208. package/src/internal/chat-attach.test.ts +0 -262
  209. package/src/internal/cli-deploy.test.ts +0 -1991
  210. package/src/internal/cli-docs.test.ts +0 -161
  211. package/src/internal/cli-mcp.test.ts +0 -789
  212. package/src/internal/cli-skills.test.ts +0 -133
  213. package/src/internal/cli-slack.test.ts +0 -1654
  214. package/src/internal/cloud-merge.test.ts +0 -74
  215. package/src/internal/cron.test.ts +0 -22
  216. package/src/internal/cursor/account-mcp.test.ts +0 -807
  217. package/src/internal/cursor/backend-client.test.ts +0 -591
  218. package/src/internal/cursor/credentials.test.ts +0 -351
  219. package/src/internal/cursor/github-credentials.test.ts +0 -136
  220. package/src/internal/cursor-account-mcp-auth.test.ts +0 -310
  221. package/src/internal/cursor-account.integration.test.ts +0 -441
  222. package/src/internal/cursor-event-relay.test.ts +0 -746
  223. package/src/internal/cursor-github-credentials.integration.test.ts +0 -271
  224. package/src/internal/cursor-slack-relay.test.ts +0 -525
  225. package/src/internal/deploy-source.test.ts +0 -111
  226. package/src/internal/discovery.artifact-tool.test.ts +0 -136
  227. package/src/internal/discovery.artifacts.test.ts +0 -119
  228. package/src/internal/discovery.builtin-tools.test.ts +0 -94
  229. package/src/internal/discovery.concurrency.test.ts +0 -60
  230. package/src/internal/discovery.cursor-account.test.ts +0 -133
  231. package/src/internal/discovery.cwd.test.ts +0 -83
  232. package/src/internal/discovery.hosting.test.ts +0 -80
  233. package/src/internal/discovery.identity.test.ts +0 -44
  234. package/src/internal/docs-site.test.ts +0 -66
  235. package/src/internal/duration.test.ts +0 -29
  236. package/src/internal/eval-judge-model.test.ts +0 -187
  237. package/src/internal/eval-run-store.cancel.test.ts +0 -142
  238. package/src/internal/eval-run-store.storage.test.ts +0 -211
  239. package/src/internal/eval-runner.http.test.ts +0 -403
  240. package/src/internal/eval-runner.run.test.ts +0 -928
  241. package/src/internal/evals-client.test.ts +0 -307
  242. package/src/internal/event-mapper.test.ts +0 -243
  243. package/src/internal/github-fanout.test.ts +0 -213
  244. package/src/internal/handleAgentServeTrigger.test.ts +0 -185
  245. package/src/internal/host-kv.test.ts +0 -82
  246. package/src/internal/host-platforms.test.ts +0 -126
  247. package/src/internal/http-channel.test.ts +0 -402
  248. package/src/internal/init-project.test.ts +0 -270
  249. package/src/internal/install-cursor-skills.test.ts +0 -262
  250. package/src/internal/local-env.test.ts +0 -120
  251. package/src/internal/log-ring.test.ts +0 -31
  252. package/src/internal/logs-client.test.ts +0 -350
  253. package/src/internal/mcp-endpoint.test.ts +0 -436
  254. package/src/internal/mcp-host.test.ts +0 -298
  255. package/src/internal/mcp-oauth.test.ts +0 -148
  256. package/src/internal/net.test.ts +0 -17
  257. package/src/internal/peer-connections.test.ts +0 -128
  258. package/src/internal/peer-mcp.integration.test.ts +0 -289
  259. package/src/internal/playground/toolchain.test.ts +0 -53
  260. package/src/internal/playground-cli.test.ts +0 -187
  261. package/src/internal/playground-proxy.test.ts +0 -376
  262. package/src/internal/prompt-context.integration.test.ts +0 -232
  263. package/src/internal/prompt-context.test.ts +0 -127
  264. package/src/internal/reminder-runner.test.ts +0 -390
  265. package/src/internal/reminder-store.test.ts +0 -53
  266. package/src/internal/request-headers.test.ts +0 -27
  267. package/src/internal/resolve-prod-target.test.ts +0 -787
  268. package/src/internal/resolved-connections.test.ts +0 -295
  269. package/src/internal/router.test.ts +0 -57
  270. package/src/internal/sdk-runner.test.ts +0 -290
  271. package/src/internal/server.artifacts.test.ts +0 -303
  272. package/src/internal/session-engine.artifacts.test.ts +0 -243
  273. package/src/internal/session-engine.coalesce.test.ts +0 -169
  274. package/src/internal/session-engine.concurrency.test.ts +0 -250
  275. package/src/internal/session-engine.host-oauth-mcp.test.ts +0 -110
  276. package/src/internal/session-engine.interrupt.test.ts +0 -577
  277. package/src/internal/session-engine.storage.test.ts +0 -547
  278. package/src/internal/session-urls.test.ts +0 -28
  279. package/src/internal/sessions-client.test.ts +0 -518
  280. package/src/internal/storage-coordinator.test.ts +0 -517
  281. package/src/internal/tool-call.test.ts +0 -458
  282. package/src/internal/tool-result.test.ts +0 -52
  283. package/src/internal/trajectory.approvals.test.ts +0 -83
  284. package/src/internal/trajectory.subagents.test.ts +0 -198
  285. package/src/internal/turn-governor.test.ts +0 -137
  286. package/src/internal/update-check.test.ts +0 -485
  287. package/src/internal/workspace.test.ts +0 -207
  288. package/src/storage-backends/cursor-hosted.test.ts +0 -121
@@ -1,795 +0,0 @@
1
- import { mkdtemp, rm } from "node:fs/promises";
2
- import { tmpdir } from "node:os";
3
- import { join } from "node:path";
4
- import { afterEach, describe, expect, it, vi } from "vitest";
5
- import type {
6
- ChannelSession,
7
- HostContext,
8
- SendMessageFn,
9
- } from "../../types.js";
10
- import * as slackApi from "./api.js";
11
- import {
12
- createEventIdDedupe,
13
- createSlackLogger,
14
- dispatchInboundFromEventBody,
15
- dispatchInboundMessage,
16
- SlackAskDedupeStore,
17
- SlackNudgeStore,
18
- } from "./index.js";
19
- import type { SlackMessageHandler } from "./types.js";
20
-
21
- const testAuth = {
22
- authenticator: "test",
23
- principalId: "U1",
24
- principalType: "user" as const,
25
- };
26
-
27
- function mockSession(
28
- id = "ses_test",
29
- extras?: { coalesced?: boolean; isNew?: boolean }
30
- ): ChannelSession {
31
- return {
32
- id,
33
- continuationToken: null,
34
- isNew: extras?.isNew ?? true,
35
- ...(extras?.coalesced === true ? { coalesced: true as const } : {}),
36
- info: {
37
- id,
38
- channelId: "slack",
39
- mode: "chat",
40
- auth: testAuth,
41
- },
42
- getEventStream: async () => new ReadableStream(),
43
- waitForCompletion: async () => ({ status: "finished" }),
44
- setContinuationToken: async () => undefined,
45
- };
46
- }
47
-
48
- function createSendRecorder(options?: { coalesced?: boolean }): {
49
- send: SendMessageFn;
50
- calls: Array<{ message: string; options: Parameters<SendMessageFn>[1] }>;
51
- } {
52
- const calls: Array<{
53
- message: string;
54
- options: Parameters<SendMessageFn>[1];
55
- }> = [];
56
- const send: SendMessageFn = async (message, sendOptions) => {
57
- calls.push({ message, options: sendOptions });
58
- return mockSession("ses_1", {
59
- coalesced: options?.coalesced,
60
- isNew: false,
61
- });
62
- };
63
- return { send, calls };
64
- }
65
-
66
- function acceptHandler(): SlackMessageHandler {
67
- return async () => ({ auth: testAuth });
68
- }
69
-
70
- function testHost(options?: {
71
- nudgeRoot?: string;
72
- askRoot?: string;
73
- evals?: HostContext["evals"];
74
- }) {
75
- const nudgeStore =
76
- options?.nudgeRoot === undefined
77
- ? undefined
78
- : new SlackNudgeStore(options.nudgeRoot);
79
- const askStore =
80
- options?.askRoot === undefined
81
- ? undefined
82
- : new SlackAskDedupeStore(options.askRoot);
83
- return {
84
- mcp: {
85
- names: () => [] as string[],
86
- listTools: async () => [],
87
- callTool: async () => ({ content: [] }),
88
- },
89
- github: {
90
- getOctokit: async () => {
91
- throw new Error("github client not configured in test");
92
- },
93
- },
94
- slack: {
95
- getClient: async () => {
96
- throw new Error("slack client not configured in test");
97
- },
98
- },
99
- kv: {
100
- get: async () => undefined,
101
- put: async () => {},
102
- delete: async () => {},
103
- },
104
- evals: options?.evals,
105
- slackNudges:
106
- nudgeStore === undefined || askStore === undefined
107
- ? undefined
108
- : {
109
- append: (input: Parameters<SlackNudgeStore["append"]>[0]) =>
110
- nudgeStore.append(input),
111
- drainFormatted: (key: string) => nudgeStore.drainFormatted(key),
112
- clear: (key: string) => nudgeStore.clear(key),
113
- hasUndelivered: (key: string) => nudgeStore.hasUndelivered(key),
114
- isDelivered: (key: string, ts: string) =>
115
- nudgeStore.isDelivered(key, ts),
116
- tryClaimAsk: (channelId: string, ts: string) =>
117
- askStore.tryClaim(channelId, ts),
118
- releaseAsk: (channelId: string, ts: string) =>
119
- askStore.release(channelId, ts),
120
- },
121
- };
122
- }
123
-
124
- function mentionBody(
125
- args: {
126
- eventId?: string;
127
- text?: string;
128
- ts?: string;
129
- threadTs?: string;
130
- channel?: string;
131
- } = {}
132
- ): Record<string, unknown> {
133
- return {
134
- type: "event_callback",
135
- team_id: "T1",
136
- ...(args.eventId === undefined ? {} : { event_id: args.eventId }),
137
- event: {
138
- type: "app_mention",
139
- user: "U1",
140
- text: args.text ?? "<@Ubot> weather?",
141
- ts: args.ts ?? "10.0",
142
- // Different from ts so setTitle is skipped (no network).
143
- thread_ts: args.threadTs ?? "9.0",
144
- channel: args.channel ?? "C9",
145
- },
146
- };
147
- }
148
-
149
- const cleanups: Array<() => Promise<void>> = [];
150
-
151
- afterEach(async () => {
152
- vi.unstubAllGlobals();
153
- vi.restoreAllMocks();
154
- while (cleanups.length > 0) {
155
- await cleanups.pop()?.();
156
- }
157
- });
158
-
159
- describe("dispatchInboundFromEventBody", () => {
160
- it("dispatches app_mention to send with continuation token", async () => {
161
- const { send, calls } = createSendRecorder();
162
- const background: Promise<unknown>[] = [];
163
- const lines: string[] = [];
164
-
165
- const scheduled = dispatchInboundFromEventBody(mentionBody(), {
166
- send,
167
- waitUntil: (p) => {
168
- background.push(p);
169
- },
170
- onAppMention: acceptHandler(),
171
- onDirectMessage: async () => null,
172
- credentials: undefined,
173
- eventIds: createEventIdDedupe(),
174
- host: testHost(),
175
- log: createSlackLogger((line) => lines.push(line)),
176
- });
177
-
178
- expect(scheduled).toBe(true);
179
- await Promise.all(background);
180
- expect(calls).toHaveLength(1);
181
- expect(calls[0]?.options?.continuationToken).toBe("C9:9.0");
182
- expect(calls[0]?.message).toContain("weather?");
183
- expect(calls[0]?.message).toContain("<slack_context>");
184
- expect(lines.some((l) => l.includes("session start"))).toBe(true);
185
- });
186
-
187
- it("dedupes by event_id", async () => {
188
- const { send, calls } = createSendRecorder();
189
- const background: Promise<unknown>[] = [];
190
- const eventIds = createEventIdDedupe();
191
- const deps = {
192
- send,
193
- waitUntil: (p: Promise<unknown>) => {
194
- background.push(p);
195
- },
196
- onAppMention: acceptHandler(),
197
- onDirectMessage: async () => null,
198
- credentials: undefined as undefined,
199
- host: testHost(),
200
- eventIds,
201
- log: createSlackLogger(() => undefined),
202
- };
203
-
204
- const body = mentionBody({ eventId: "Ev1" });
205
- expect(dispatchInboundFromEventBody(body, deps)).toBe(true);
206
- expect(dispatchInboundFromEventBody(body, deps)).toBe(false);
207
- await Promise.all(background);
208
- expect(calls).toHaveLength(1);
209
- });
210
-
211
- it("skips send when handler returns null", async () => {
212
- const { send, calls } = createSendRecorder();
213
- const background: Promise<unknown>[] = [];
214
- dispatchInboundFromEventBody(mentionBody(), {
215
- send,
216
- waitUntil: (p) => {
217
- background.push(p);
218
- },
219
- onAppMention: async () => null,
220
- onDirectMessage: async () => null,
221
- credentials: undefined,
222
- eventIds: createEventIdDedupe(),
223
- host: testHost(),
224
- });
225
- await Promise.all(background);
226
- expect(calls).toHaveLength(0);
227
- });
228
-
229
- it("does not send when handler throws", async () => {
230
- const { send, calls } = createSendRecorder();
231
- const background: Promise<unknown>[] = [];
232
- dispatchInboundFromEventBody(mentionBody(), {
233
- send,
234
- waitUntil: (p) => {
235
- background.push(p);
236
- },
237
- onAppMention: async () => {
238
- throw new Error("boom");
239
- },
240
- onDirectMessage: async () => null,
241
- credentials: undefined,
242
- eventIds: createEventIdDedupe(),
243
- host: testHost(),
244
- log: createSlackLogger(() => undefined),
245
- });
246
- await Promise.all(background);
247
- expect(calls).toHaveLength(0);
248
- });
249
-
250
- it("dispatches direct messages", async () => {
251
- const { send, calls } = createSendRecorder();
252
- const background: Promise<unknown>[] = [];
253
- dispatchInboundFromEventBody(
254
- {
255
- type: "event_callback",
256
- team_id: "T1",
257
- event_id: "EvDM",
258
- event: {
259
- type: "message",
260
- channel_type: "im",
261
- user: "U1",
262
- text: "hi from dm",
263
- ts: "2.0",
264
- thread_ts: "1.0",
265
- channel: "D1",
266
- },
267
- },
268
- {
269
- send,
270
- waitUntil: (p) => {
271
- background.push(p);
272
- },
273
- onAppMention: async () => null,
274
- onDirectMessage: acceptHandler(),
275
- credentials: undefined,
276
- eventIds: createEventIdDedupe(),
277
- host: testHost(),
278
- }
279
- );
280
- await Promise.all(background);
281
- expect(calls).toHaveLength(1);
282
- expect(calls[0]?.options?.continuationToken).toBe("D1:1.0");
283
- });
284
-
285
- it("returns false for unhandled shapes", () => {
286
- expect(
287
- dispatchInboundFromEventBody(
288
- { type: "event_callback", event: { type: "reaction_added" } },
289
- {
290
- send: async () => mockSession(),
291
- waitUntil: () => undefined,
292
- onAppMention: async () => null,
293
- onDirectMessage: async () => null,
294
- credentials: undefined,
295
- eventIds: createEventIdDedupe(),
296
- host: testHost(),
297
- }
298
- )
299
- ).toBe(false);
300
- });
301
-
302
- it("forwards message override, workspaceFiles, and cloud options from the handler", async () => {
303
- const { send, calls } = createSendRecorder();
304
- const background: Promise<unknown>[] = [];
305
-
306
- dispatchInboundFromEventBody(mentionBody(), {
307
- send,
308
- waitUntil: (p) => {
309
- background.push(p);
310
- },
311
- onAppMention: async () => ({
312
- auth: testAuth,
313
- title: "Bugbot acme/widget#1",
314
- message: "Read pr.txt and review",
315
- workspaceFiles: { "pr.txt": "evidence" },
316
- cloud: {
317
- repos: [
318
- {
319
- url: "https://github.com/acme/widget",
320
- prUrl: "https://github.com/acme/widget/pull/1",
321
- },
322
- ],
323
- },
324
- }),
325
- onDirectMessage: async () => null,
326
- credentials: undefined,
327
- eventIds: createEventIdDedupe(),
328
- host: testHost(),
329
- });
330
- await Promise.all(background);
331
- expect(calls).toHaveLength(1);
332
- expect(calls[0]?.options?.title).toBe("Bugbot acme/widget#1");
333
- expect(calls[0]?.message).toContain("Read pr.txt");
334
- expect(calls[0]?.options?.workspaceFiles).toEqual({
335
- "pr.txt": "evidence",
336
- });
337
- expect(calls[0]?.options?.cloud).toEqual({
338
- repos: [
339
- {
340
- url: "https://github.com/acme/widget",
341
- prUrl: "https://github.com/acme/widget/pull/1",
342
- },
343
- ],
344
- });
345
- });
346
- });
347
-
348
- describe("engagement routing", () => {
349
- it("ignores mentions when mentionsEnabled is false", async () => {
350
- const { send, calls } = createSendRecorder();
351
- const background: Promise<unknown>[] = [];
352
- const scheduled = dispatchInboundFromEventBody(mentionBody(), {
353
- send,
354
- waitUntil: (p) => {
355
- background.push(p);
356
- },
357
- onAppMention: acceptHandler(),
358
- onDirectMessage: async () => null,
359
- credentials: undefined,
360
- eventIds: createEventIdDedupe(),
361
- host: testHost(),
362
- log: createSlackLogger(() => undefined),
363
- mentionsEnabled: false,
364
- });
365
- expect(scheduled).toBe(false);
366
- await Promise.all(background);
367
- expect(calls).toHaveLength(0);
368
- });
369
-
370
- it("routes channel posts to the watcher when configured", async () => {
371
- const { send, calls } = createSendRecorder();
372
- const background: Promise<unknown>[] = [];
373
- const handled: string[] = [];
374
- const deps = {
375
- send,
376
- waitUntil: (p: Promise<unknown>) => {
377
- background.push(p);
378
- },
379
- onAppMention: acceptHandler(),
380
- onDirectMessage: async () => null,
381
- credentials: undefined as undefined,
382
- eventIds: createEventIdDedupe(),
383
- host: testHost(),
384
- log: createSlackLogger(() => undefined),
385
- channelWatch: {
386
- handle: (event: { kind: string }, eventId?: string) => {
387
- handled.push(`${event.kind}:${eventId ?? ""}`);
388
- return true;
389
- },
390
- stop: () => undefined,
391
- },
392
- };
393
- const scheduled = dispatchInboundFromEventBody(
394
- {
395
- type: "event_callback",
396
- team_id: "T1",
397
- event_id: "Ev9",
398
- event: {
399
- type: "message",
400
- channel: "C9",
401
- channel_type: "channel",
402
- ts: "20.0",
403
- text: "fresh report",
404
- user: "U1",
405
- },
406
- },
407
- deps
408
- );
409
- expect(scheduled).toBe(true);
410
- await Promise.all(background);
411
- expect(handled).toEqual(["post:Ev9"]);
412
- // Watcher decides whether to dispatch; nothing sent by default here.
413
- expect(calls).toHaveLength(0);
414
- });
415
-
416
- it("ignores channel posts without a watcher", () => {
417
- const { send } = createSendRecorder();
418
- const scheduled = dispatchInboundFromEventBody(
419
- {
420
- type: "event_callback",
421
- event: {
422
- type: "message",
423
- channel: "C9",
424
- channel_type: "channel",
425
- ts: "20.0",
426
- text: "fresh report",
427
- user: "U1",
428
- },
429
- },
430
- {
431
- send,
432
- waitUntil: () => undefined,
433
- onAppMention: acceptHandler(),
434
- onDirectMessage: async () => null,
435
- credentials: undefined,
436
- eventIds: createEventIdDedupe(),
437
- host: testHost(),
438
- log: createSlackLogger(() => undefined),
439
- }
440
- );
441
- expect(scheduled).toBe(false);
442
- });
443
- });
444
-
445
- describe("dispatchInboundMessage", () => {
446
- it("logs delivery failure when send throws", async () => {
447
- const lines: string[] = [];
448
- await dispatchInboundMessage({
449
- kind: "app_mention",
450
- message: {
451
- text: "hi",
452
- body: "hi",
453
- markdown: "hi",
454
- ts: "2.0",
455
- threadTs: "1.0",
456
- channelId: "C1",
457
- teamId: "T1",
458
- author: { userId: "U1", isBot: false },
459
- },
460
- handler: acceptHandler(),
461
- send: async () => {
462
- throw new Error("engine down");
463
- },
464
- credentials: undefined,
465
- host: testHost(),
466
- log: createSlackLogger((line) => lines.push(line)),
467
- });
468
- expect(lines.some((line) => line.includes("delivery failed"))).toBe(true);
469
- });
470
-
471
- it("coalesces busy follow-ups with admission + nudge (no preempt retry)", async () => {
472
- const root = await mkdtemp(join(tmpdir(), "dispatch-coalesce-"));
473
- cleanups.push(() => rm(root, { recursive: true, force: true }));
474
- const apiSoft = vi.spyOn(slackApi, "callSlackApiSoft").mockResolvedValue({
475
- ok: true,
476
- messages: [
477
- { ts: "1.0", bot_id: "B1", text: "parent" },
478
- { ts: "2.0", user: "U1", text: "follow-up" },
479
- ],
480
- has_more: false,
481
- });
482
- const lines: string[] = [];
483
- const { send, calls } = createSendRecorder({ coalesced: true });
484
- const host = testHost({
485
- nudgeRoot: join(root, "nudges"),
486
- askRoot: join(root, "asks"),
487
- });
488
- await dispatchInboundMessage({
489
- kind: "app_mention",
490
- message: {
491
- text: "follow-up",
492
- body: "follow-up",
493
- markdown: "follow-up",
494
- ts: "2.0",
495
- threadTs: "1.0",
496
- channelId: "C1",
497
- teamId: "T1",
498
- author: { userId: "U1", isBot: false },
499
- },
500
- handler: acceptHandler(),
501
- send,
502
- credentials: { botToken: "xoxb-test" },
503
- host,
504
- hasContinuationSession: async () => true,
505
- log: createSlackLogger((line) => lines.push(line)),
506
- });
507
- expect(calls).toHaveLength(1);
508
- expect(calls[0]?.options?.admission).toBe("coalesce");
509
- expect(calls[0]?.options?.coalesceSourceTs).toBe("2.0");
510
- expect(
511
- lines.some((line) => line.includes("session busy; coalescing follow-up"))
512
- ).toBe(true);
513
- expect(await host.slackNudges?.hasUndelivered("C1:1.0")).toBe(false);
514
- // Follow-up typing uses same-module setThreadStatus → callSlackApiSoft;
515
- // vitest cannot spy that path. Coalesce admission + log is the contract.
516
- expect(apiSoft).toHaveBeenCalled();
517
- vi.restoreAllMocks();
518
- });
519
-
520
- it("handles whole-message stop without send", async () => {
521
- const root = await mkdtemp(join(tmpdir(), "dispatch-stop-"));
522
- cleanups.push(() => rm(root, { recursive: true, force: true }));
523
- vi.spyOn(slackApi, "setThreadStatus").mockResolvedValue({ ok: true });
524
- const { send, calls } = createSendRecorder();
525
- let interrupted = false;
526
- await dispatchInboundMessage({
527
- kind: "app_mention",
528
- message: {
529
- text: "<@Ubot> stop",
530
- body: "<@Ubot> stop",
531
- markdown: "@Ubot stop",
532
- ts: "2.0",
533
- threadTs: "1.0",
534
- channelId: "C1",
535
- teamId: "T1",
536
- author: { userId: "U1", isBot: false },
537
- },
538
- handler: acceptHandler(),
539
- send,
540
- credentials: { botToken: "xoxb-test" },
541
- host: testHost({
542
- nudgeRoot: join(root, "nudges"),
543
- askRoot: join(root, "asks"),
544
- }),
545
- interruptContinuation: async () => {
546
- interrupted = true;
547
- return true;
548
- },
549
- });
550
- expect(calls).toHaveLength(0);
551
- expect(interrupted).toBe(true);
552
- vi.restoreAllMocks();
553
- });
554
-
555
- it("handles eval list directive without send", async () => {
556
- // Assert host.evals.list ran and no agent turn was started. Slack
557
- // postMessage is same-module (not spyable via the export).
558
- const { send, calls } = createSendRecorder();
559
- let listed = false;
560
- await dispatchInboundMessage({
561
- kind: "app_mention",
562
- message: {
563
- text: "<@Ubot> eval list",
564
- body: "<@Ubot> eval list",
565
- markdown: "@Ubot eval list",
566
- ts: "2.0",
567
- threadTs: "1.0",
568
- channelId: "C1",
569
- teamId: "T1",
570
- author: { userId: "U1", isBot: false },
571
- },
572
- handler: acceptHandler(),
573
- send,
574
- credentials: { botToken: "xoxb-test" },
575
- host: testHost({
576
- evals: {
577
- list: async () => {
578
- listed = true;
579
- return {
580
- evals: [{ id: "smoke", fileId: "smoke" }],
581
- config: { maxPlaygroundRuns: 20, durableRuns: false },
582
- };
583
- },
584
- get: async () => undefined,
585
- listRunsWithActive: async () => ({ runs: [] }),
586
- start: async () => {
587
- throw new Error("should not start");
588
- },
589
- cancel: async () => {
590
- throw new Error("should not cancel");
591
- },
592
- },
593
- }),
594
- });
595
- expect(calls).toHaveLength(0);
596
- expect(listed).toBe(true);
597
- });
598
-
599
- it("skips eval directive when evalCommandsEnabled is false", async () => {
600
- const { send, calls } = createSendRecorder();
601
- await dispatchInboundMessage({
602
- kind: "app_mention",
603
- message: {
604
- text: "<@Ubot> eval list",
605
- body: "<@Ubot> eval list",
606
- markdown: "@Ubot eval list",
607
- ts: "2.0",
608
- threadTs: "1.0",
609
- channelId: "C1",
610
- teamId: "T1",
611
- author: { userId: "U1", isBot: false },
612
- },
613
- handler: acceptHandler(),
614
- send,
615
- credentials: undefined,
616
- host: testHost({
617
- evals: {
618
- list: async () => {
619
- throw new Error("should not list");
620
- },
621
- get: async () => undefined,
622
- listRunsWithActive: async () => ({ runs: [] }),
623
- start: async () => {
624
- throw new Error("should not start");
625
- },
626
- cancel: async () => {
627
- throw new Error("should not cancel");
628
- },
629
- },
630
- }),
631
- evalCommandsEnabled: false,
632
- });
633
- expect(calls).toHaveLength(1);
634
- });
635
-
636
- it("dedupes asks by channel:ts", async () => {
637
- const root = await mkdtemp(join(tmpdir(), "dispatch-dedupe-"));
638
- cleanups.push(() => rm(root, { recursive: true, force: true }));
639
- const host = testHost({
640
- nudgeRoot: join(root, "nudges"),
641
- askRoot: join(root, "asks"),
642
- });
643
- const { send, calls } = createSendRecorder();
644
- const message = {
645
- text: "hello",
646
- body: "hello",
647
- markdown: "hello",
648
- ts: "2.0",
649
- threadTs: "1.0",
650
- channelId: "C1",
651
- teamId: "T1",
652
- author: { userId: "U1", isBot: false },
653
- };
654
- await dispatchInboundMessage({
655
- kind: "app_mention",
656
- message,
657
- handler: acceptHandler(),
658
- send,
659
- credentials: undefined,
660
- host,
661
- });
662
- await dispatchInboundMessage({
663
- kind: "app_mention",
664
- message,
665
- handler: acceptHandler(),
666
- send,
667
- credentials: undefined,
668
- host,
669
- });
670
- expect(calls).toHaveLength(1);
671
- });
672
-
673
- it("hydrates prior thread messages into the prompt", async () => {
674
- vi.spyOn(slackApi, "callSlackApiSoft").mockResolvedValue({
675
- ok: true,
676
- messages: [
677
- {
678
- ts: "1.0",
679
- bot_id: "BDD",
680
- username: "Datadog",
681
- text: "Monitor alert: rate limited",
682
- },
683
- {
684
- ts: "2.0",
685
- user: "U1",
686
- text: "@jenny what happened here?",
687
- },
688
- ],
689
- has_more: false,
690
- });
691
- const { send, calls } = createSendRecorder();
692
- const lines: string[] = [];
693
- await dispatchInboundMessage({
694
- kind: "app_mention",
695
- message: {
696
- text: "<@BJENNY> what happened here?",
697
- body: "<@BJENNY> what happened here?",
698
- markdown: "@BJENNY what happened here?",
699
- ts: "2.0",
700
- threadTs: "1.0",
701
- channelId: "C1",
702
- teamId: "T1",
703
- author: { userId: "U1", isBot: false },
704
- },
705
- handler: acceptHandler(),
706
- send,
707
- credentials: { botToken: "xoxb-test" },
708
- host: testHost(),
709
- log: createSlackLogger((line) => lines.push(line)),
710
- });
711
- expect(calls).toHaveLength(1);
712
- expect(calls[0]!.message).toContain("<slack_thread>");
713
- expect(calls[0]!.message).toContain("Monitor alert: rate limited");
714
- expect(calls[0]!.message).toContain("@BJENNY what happened here?");
715
- expect(calls[0]!.message).not.toMatch(/\[reply\].*what happened here\?/);
716
- expect(lines.some((line) => line.includes("thread context loaded"))).toBe(
717
- true
718
- );
719
- vi.restoreAllMocks();
720
- });
721
-
722
- it("loads slack_thread_delta on warm continuations", async () => {
723
- const spy = vi.spyOn(slackApi, "callSlackApiSoft").mockResolvedValue({
724
- ok: true,
725
- messages: [
726
- { ts: "1.0", bot_id: "BDD", text: "parent alert" },
727
- { ts: "1.5", bot_id: "BJENNY", text: "first reply" },
728
- // Non-trigger reply after our last post — appears in the delta.
729
- // The triggering ask (3.0) is excluded from the block and appended
730
- // as user text at the end of the prompt.
731
- { ts: "2.0", user: "U2", text: "also looking" },
732
- { ts: "3.0", user: "U1", text: "any leads?" },
733
- ],
734
- has_more: false,
735
- });
736
- const { send, calls } = createSendRecorder();
737
- await dispatchInboundMessage({
738
- kind: "app_mention",
739
- message: {
740
- text: "any leads?",
741
- body: "any leads?",
742
- markdown: "any leads?",
743
- ts: "3.0",
744
- threadTs: "1.0",
745
- channelId: "C1",
746
- teamId: "T1",
747
- author: { userId: "U1", isBot: false },
748
- },
749
- handler: acceptHandler(),
750
- send,
751
- credentials: { botToken: "xoxb-test" },
752
- host: testHost(),
753
- hasContinuationSession: async () => true,
754
- // Agent watermark (not Datadog's parent) — human reply at 2.0 is in delta.
755
- getContinuationLastBotMessageTs: async () => "1.5",
756
- });
757
- expect(spy).toHaveBeenCalled();
758
- expect(calls[0]?.message).toContain("<slack_thread_delta>");
759
- expect(calls[0]?.message).toContain("also looking");
760
- expect(calls[0]?.message).not.toContain("<slack_thread>");
761
- expect(calls[0]?.options?.admission).toBe("coalesce");
762
- spy.mockRestore();
763
- });
764
-
765
- it("releases ask claim when send fails", async () => {
766
- const root = await mkdtemp(join(tmpdir(), "dispatch-claim-release-"));
767
- cleanups.push(() => rm(root, { recursive: true, force: true }));
768
- const host = testHost({
769
- nudgeRoot: join(root, "nudges"),
770
- askRoot: join(root, "asks"),
771
- });
772
- const send: SendMessageFn = async () => {
773
- throw new Error("boom");
774
- };
775
- await dispatchInboundMessage({
776
- kind: "app_mention",
777
- message: {
778
- text: "hello",
779
- body: "hello",
780
- markdown: "hello",
781
- ts: "2.0",
782
- threadTs: "1.0",
783
- channelId: "C1",
784
- teamId: "T1",
785
- author: { userId: "U1", isBot: false },
786
- },
787
- handler: acceptHandler(),
788
- send,
789
- credentials: undefined,
790
- host,
791
- log: createSlackLogger(() => undefined),
792
- });
793
- expect(await host.slackNudges?.tryClaimAsk("C1", "2.0")).toBe(true);
794
- });
795
- });