@cursor/july 0.1.26 → 0.1.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (324) hide show
  1. package/dist/ab.d.ts +6 -0
  2. package/dist/ab.d.ts.map +1 -1
  3. package/dist/ab.js +1 -0
  4. package/dist/artifacts.d.ts +34 -0
  5. package/dist/artifacts.d.ts.map +1 -0
  6. package/dist/artifacts.js +57 -0
  7. package/dist/bin/agent-serve.js +43 -12
  8. package/dist/channels/github/github-channel.d.ts +1 -1
  9. package/dist/channels/github/github-channel.d.ts.map +1 -1
  10. package/dist/channels/github/github-channel.js +14 -1
  11. package/dist/channels/github/types.d.ts +6 -1
  12. package/dist/channels/github/types.d.ts.map +1 -1
  13. package/dist/channels/slack/api.d.ts +2 -1
  14. package/dist/channels/slack/api.d.ts.map +1 -1
  15. package/dist/channels/slack/api.js +1 -0
  16. package/dist/channels/slack/auth.d.ts +13 -13
  17. package/dist/channels/slack/auth.d.ts.map +1 -1
  18. package/dist/channels/slack/auth.js +19 -10
  19. package/dist/channels/slack/cursor-account.d.ts +2 -1
  20. package/dist/channels/slack/cursor-account.d.ts.map +1 -1
  21. package/dist/channels/slack/cursor-account.js +3 -1
  22. package/dist/channels/slack/defaults.d.ts +7 -4
  23. package/dist/channels/slack/defaults.d.ts.map +1 -1
  24. package/dist/channels/slack/defaults.js +14 -4
  25. package/dist/channels/slack/dispatch.d.ts +10 -1
  26. package/dist/channels/slack/dispatch.d.ts.map +1 -1
  27. package/dist/channels/slack/dispatch.js +59 -21
  28. package/dist/channels/slack/external-policy.d.ts +27 -0
  29. package/dist/channels/slack/external-policy.d.ts.map +1 -0
  30. package/dist/channels/slack/external-policy.js +53 -0
  31. package/dist/channels/slack/index.d.ts +1 -0
  32. package/dist/channels/slack/index.d.ts.map +1 -1
  33. package/dist/channels/slack/index.js +1 -0
  34. package/dist/channels/slack/interactive.d.ts +8 -1
  35. package/dist/channels/slack/interactive.d.ts.map +1 -1
  36. package/dist/channels/slack/interactive.js +43 -15
  37. package/dist/channels/slack/slack-channel.d.ts.map +1 -1
  38. package/dist/channels/slack/slack-channel.js +22 -8
  39. package/dist/channels/slack/types.d.ts +16 -1
  40. package/dist/channels/slack/types.d.ts.map +1 -1
  41. package/dist/docs/404.html +2 -2
  42. package/dist/docs/ab.html +3 -3
  43. package/dist/docs/assets/{app.DYcC9FY-.js → app.CqjrYaT2.js} +1 -1
  44. package/dist/docs/assets/chunks/@localSearchIndexroot.VWQoPFJ1.js +1 -0
  45. package/dist/docs/assets/chunks/{VPLocalSearchBox.o4N_knTV.js → VPLocalSearchBox.ag-MwUel.js} +1 -1
  46. package/dist/docs/assets/chunks/{theme.DQ-njyo0.js → theme.BS-DJWat.js} +2 -2
  47. package/dist/docs/assets/{guides_slack.md.D_xFKlnF.js → guides_slack.md.CjmJSvZS.js} +8 -4
  48. package/dist/docs/assets/guides_slack.md.CjmJSvZS.lean.js +1 -0
  49. package/dist/docs/assets/guides_webhooks.md.wSOYas3X.js +183 -0
  50. package/dist/docs/assets/{guides_webhooks.md.B1EswtUu.lean.js → guides_webhooks.md.wSOYas3X.lean.js} +1 -1
  51. package/dist/docs/assets/{index.md.Dfv5ic9t.js → index.md.CH_s5uZe.js} +1 -1
  52. package/dist/docs/assets/{reference_channels.md.DdmiKgqf.js → reference_channels.md.CDhTRfUz.js} +2 -2
  53. package/dist/docs/assets/{reference_channels.md.DdmiKgqf.lean.js → reference_channels.md.CDhTRfUz.lean.js} +1 -1
  54. package/dist/docs/building-with-agents.html +3 -3
  55. package/dist/docs/concepts.html +3 -3
  56. package/dist/docs/deployment.html +3 -3
  57. package/dist/docs/evals.html +3 -3
  58. package/dist/docs/example-agents/approval-buddy.html +3 -3
  59. package/dist/docs/example-agents/benny.html +3 -3
  60. package/dist/docs/example-agents/bugbot.html +3 -3
  61. package/dist/docs/example-agents/codebase-wiki.html +3 -3
  62. package/dist/docs/example-agents/codeowners-review.html +3 -3
  63. package/dist/docs/example-agents/concierge.html +3 -3
  64. package/dist/docs/example-agents/fsd.html +3 -3
  65. package/dist/docs/example-agents/index.html +3 -3
  66. package/dist/docs/example-agents/knowledge-base.html +3 -3
  67. package/dist/docs/example-agents/oncall.html +3 -3
  68. package/dist/docs/example-agents/security-reviewer.html +3 -3
  69. package/dist/docs/example-agents/slack-agent.html +3 -3
  70. package/dist/docs/example-agents/weather-agent.html +3 -3
  71. package/dist/docs/guides/agent-to-agent.html +3 -3
  72. package/dist/docs/guides/cloud-runtime.html +3 -3
  73. package/dist/docs/guides/github.html +3 -3
  74. package/dist/docs/guides/human-in-the-loop.html +3 -3
  75. package/dist/docs/guides/mcp-oauth.html +3 -3
  76. package/dist/docs/guides/slack.html +11 -7
  77. package/dist/docs/guides/webhooks.html +138 -5
  78. package/dist/docs/hashmap.json +1 -1
  79. package/dist/docs/hillclimbing.html +3 -3
  80. package/dist/docs/index.html +5 -5
  81. package/dist/docs/quickstart.html +3 -3
  82. package/dist/docs/reference/agent-config.html +3 -3
  83. package/dist/docs/reference/channels.html +5 -5
  84. package/dist/docs/reference/cli.html +3 -3
  85. package/dist/docs/reference/connections.html +3 -3
  86. package/dist/docs/reference/hooks.html +3 -3
  87. package/dist/docs/reference/http-api.html +3 -3
  88. package/dist/docs/reference/instructions.html +3 -3
  89. package/dist/docs/reference/playground.html +3 -3
  90. package/dist/docs/reference/project-layout.html +3 -3
  91. package/dist/docs/reference/prompt.html +3 -3
  92. package/dist/docs/reference/schedules.html +3 -3
  93. package/dist/docs/reference/sessions.html +3 -3
  94. package/dist/docs/reference/skills.html +3 -3
  95. package/dist/docs/reference/subagents.html +3 -3
  96. package/dist/docs/reference/tools.html +3 -3
  97. package/dist/docs/scaffolding-agents.html +3 -3
  98. package/dist/docs/storage.html +3 -3
  99. package/dist/docs/troubleshooting.html +3 -3
  100. package/dist/evals/assertions.d.ts +10 -1
  101. package/dist/evals/assertions.d.ts.map +1 -1
  102. package/dist/evals/assertions.js +12 -0
  103. package/dist/evals.d.ts +1 -1
  104. package/dist/evals.d.ts.map +1 -1
  105. package/dist/index.d.ts +1 -0
  106. package/dist/index.d.ts.map +1 -1
  107. package/dist/index.js +1 -0
  108. package/dist/internal/ab-fold.d.ts.map +1 -1
  109. package/dist/internal/ab-fold.js +4 -0
  110. package/dist/internal/ab-snapshot.d.ts.map +1 -1
  111. package/dist/internal/ab-snapshot.js +1 -0
  112. package/dist/internal/artifacts-store.d.ts +45 -0
  113. package/dist/internal/artifacts-store.d.ts.map +1 -0
  114. package/dist/internal/artifacts-store.js +250 -0
  115. package/dist/internal/builtin-tools/artifacts.d.ts +10 -0
  116. package/dist/internal/builtin-tools/artifacts.d.ts.map +1 -0
  117. package/dist/internal/builtin-tools/artifacts.js +73 -0
  118. package/dist/internal/builtin-tools/index.d.ts +8 -1
  119. package/dist/internal/builtin-tools/index.d.ts.map +1 -1
  120. package/dist/internal/builtin-tools/index.js +15 -0
  121. package/dist/internal/cli-ax.d.ts +19 -0
  122. package/dist/internal/cli-ax.d.ts.map +1 -1
  123. package/dist/internal/cli-ax.js +196 -57
  124. package/dist/internal/cli-slack.d.ts.map +1 -1
  125. package/dist/internal/cli-slack.js +14 -6
  126. package/dist/internal/cursor-slack-relay.d.ts +2 -0
  127. package/dist/internal/cursor-slack-relay.d.ts.map +1 -1
  128. package/dist/internal/cursor-slack-relay.js +1 -0
  129. package/dist/internal/deploy-client.d.ts +2 -0
  130. package/dist/internal/deploy-client.d.ts.map +1 -1
  131. package/dist/internal/deploy-client.js +1 -0
  132. package/dist/internal/discovery.d.ts.map +1 -1
  133. package/dist/internal/discovery.js +91 -3
  134. package/dist/internal/distribution.d.ts.map +1 -1
  135. package/dist/internal/distribution.js +1 -0
  136. package/dist/internal/model-pricing.d.ts +49 -0
  137. package/dist/internal/model-pricing.d.ts.map +1 -0
  138. package/dist/internal/model-pricing.js +377 -0
  139. package/dist/internal/reminder-runner.d.ts.map +1 -1
  140. package/dist/internal/reminder-runner.js +1 -0
  141. package/dist/internal/schedule-runner.d.ts.map +1 -1
  142. package/dist/internal/schedule-runner.js +1 -0
  143. package/dist/internal/sdk-runner.d.ts.map +1 -1
  144. package/dist/internal/sdk-runner.js +9 -1
  145. package/dist/internal/server.d.ts.map +1 -1
  146. package/dist/internal/server.js +49 -5
  147. package/dist/internal/session-cost.d.ts +49 -0
  148. package/dist/internal/session-cost.d.ts.map +1 -0
  149. package/dist/internal/session-cost.js +175 -0
  150. package/dist/internal/session-engine.d.ts +35 -1
  151. package/dist/internal/session-engine.d.ts.map +1 -1
  152. package/dist/internal/session-engine.js +128 -7
  153. package/dist/internal/storage-coordinator.d.ts +15 -0
  154. package/dist/internal/storage-coordinator.d.ts.map +1 -1
  155. package/dist/internal/storage-coordinator.js +52 -0
  156. package/dist/internal/trajectory.d.ts +9 -1
  157. package/dist/internal/trajectory.d.ts.map +1 -1
  158. package/dist/internal/trajectory.js +32 -5
  159. package/dist/playground/assets/index-Bul1WfrB.css +1 -0
  160. package/dist/playground/assets/index-CkN74U_L.js +87 -0
  161. package/dist/playground/index.html +2 -2
  162. package/dist/storage.d.ts +4 -0
  163. package/dist/storage.d.ts.map +1 -1
  164. package/dist/storage.js +4 -0
  165. package/dist/types.d.ts +164 -1
  166. package/dist/types.d.ts.map +1 -1
  167. package/docs/README.md +1 -0
  168. package/docs/guides/slack.md +32 -7
  169. package/docs/guides/webhooks.md +183 -0
  170. package/docs/reference/channels.md +2 -1
  171. package/package.json +26 -26
  172. package/skills/setup-slack/SKILL.md +3 -0
  173. package/src/ab.ts +7 -0
  174. package/src/bin/agent-serve.ts +42 -5
  175. package/src/channels/slack/auth.ts +29 -22
  176. package/src/channels/slack/cursor-account.ts +2 -0
  177. package/src/channels/slack/defaults.ts +24 -4
  178. package/src/channels/slack/dispatch.ts +42 -1
  179. package/src/channels/slack/external-policy.ts +62 -0
  180. package/src/channels/slack/index.ts +1 -0
  181. package/src/channels/slack/interactive.ts +42 -10
  182. package/src/channels/slack/slack-channel.ts +20 -3
  183. package/src/channels/slack/types.ts +12 -0
  184. package/src/internal/ab-fold.ts +4 -0
  185. package/src/internal/ab-snapshot.ts +1 -0
  186. package/src/internal/cli-ax.ts +205 -34
  187. package/src/internal/cursor-slack-relay.ts +3 -0
  188. package/src/internal/deploy-client.ts +3 -0
  189. package/src/internal/discovery.ts +8 -1
  190. package/src/internal/model-pricing.ts +426 -0
  191. package/src/internal/sdk-runner.ts +10 -2
  192. package/src/internal/server.ts +9 -5
  193. package/src/internal/session-cost.ts +231 -0
  194. package/src/internal/session-engine.ts +28 -0
  195. package/src/internal/trajectory.ts +45 -3
  196. package/src/types.ts +24 -1
  197. package/dist/channels/github/instrument.d.ts +0 -20
  198. package/dist/channels/github/instrument.d.ts.map +0 -1
  199. package/dist/docs/assets/chunks/@localSearchIndexroot.BQTzJjR_.js +0 -1
  200. package/dist/docs/assets/guides_slack.md.D_xFKlnF.lean.js +0 -1
  201. package/dist/docs/assets/guides_webhooks.md.B1EswtUu.js +0 -50
  202. package/dist/internal/json-dir-store.d.ts +0 -32
  203. package/dist/internal/json-dir-store.d.ts.map +0 -1
  204. package/dist/internal/json-dir-store.js +0 -100
  205. package/dist/playground/assets/index-CjOQ4hN9.css +0 -1
  206. package/dist/playground/assets/index-DqXdAFGa.js +0 -85
  207. package/src/bin/agent-serve.version.test.ts +0 -64
  208. package/src/channels/github/api.test.ts +0 -64
  209. package/src/channels/github/auth.test.ts +0 -105
  210. package/src/channels/github/cursor-account.test.ts +0 -204
  211. package/src/channels/github/forward.test.ts +0 -457
  212. package/src/channels/github/github.test.ts +0 -985
  213. package/src/channels/github/replay.test.ts +0 -179
  214. package/src/channels/slack/api.post-message.test.ts +0 -148
  215. package/src/channels/slack/approvals.test.ts +0 -328
  216. package/src/channels/slack/block-actions.test.ts +0 -469
  217. package/src/channels/slack/bot-mentions.test.ts +0 -267
  218. package/src/channels/slack/channel-watch.test.ts +0 -363
  219. package/src/channels/slack/cursor-account.test.ts +0 -301
  220. package/src/channels/slack/defaults.final-post.test.ts +0 -182
  221. package/src/channels/slack/dispatch.test.ts +0 -875
  222. package/src/channels/slack/eval-directive.test.ts +0 -273
  223. package/src/channels/slack/message-body.test.ts +0 -54
  224. package/src/channels/slack/nudge-store.test.ts +0 -143
  225. package/src/channels/slack/slack.test.ts +0 -391
  226. package/src/channels/slack/stop.test.ts +0 -23
  227. package/src/channels/slack/thread-context.test.ts +0 -202
  228. package/src/evals/assertions.test.ts +0 -617
  229. package/src/evals/expect.test.ts +0 -144
  230. package/src/evals/judge.test.ts +0 -181
  231. package/src/evals/loaders.test.ts +0 -132
  232. package/src/evals/matchers.test.ts +0 -95
  233. package/src/evals/reporters.test.ts +0 -303
  234. package/src/evals/run-facts.test.ts +0 -259
  235. package/src/internal/ab-snapshot.test.ts +0 -325
  236. package/src/internal/approval-gate.test.ts +0 -49
  237. package/src/internal/approvals.integration.test.ts +0 -383
  238. package/src/internal/artifacts-store.test.ts +0 -283
  239. package/src/internal/authored-loaders.test.ts +0 -31
  240. package/src/internal/builtin-tools/artifacts.test.ts +0 -247
  241. package/src/internal/builtin-tools/reminders.test.ts +0 -201
  242. package/src/internal/channel-route-schema.test.ts +0 -294
  243. package/src/internal/chat-attach.test.ts +0 -262
  244. package/src/internal/cli-deploy.test.ts +0 -1991
  245. package/src/internal/cli-docs.test.ts +0 -161
  246. package/src/internal/cli-mcp.test.ts +0 -789
  247. package/src/internal/cli-skills.test.ts +0 -133
  248. package/src/internal/cli-slack.test.ts +0 -1654
  249. package/src/internal/cloud-merge.test.ts +0 -74
  250. package/src/internal/cron.test.ts +0 -22
  251. package/src/internal/cursor/account-mcp.test.ts +0 -807
  252. package/src/internal/cursor/backend-client.test.ts +0 -591
  253. package/src/internal/cursor/credentials.test.ts +0 -351
  254. package/src/internal/cursor/github-credentials.test.ts +0 -136
  255. package/src/internal/cursor-account-mcp-auth.test.ts +0 -310
  256. package/src/internal/cursor-account.integration.test.ts +0 -441
  257. package/src/internal/cursor-event-relay.test.ts +0 -746
  258. package/src/internal/cursor-github-credentials.integration.test.ts +0 -271
  259. package/src/internal/cursor-slack-relay.test.ts +0 -525
  260. package/src/internal/deploy-source.test.ts +0 -111
  261. package/src/internal/discovery.artifact-tool.test.ts +0 -136
  262. package/src/internal/discovery.artifacts.test.ts +0 -119
  263. package/src/internal/discovery.builtin-tools.test.ts +0 -94
  264. package/src/internal/discovery.concurrency.test.ts +0 -60
  265. package/src/internal/discovery.cursor-account.test.ts +0 -133
  266. package/src/internal/discovery.cwd.test.ts +0 -83
  267. package/src/internal/discovery.hosting.test.ts +0 -80
  268. package/src/internal/discovery.identity.test.ts +0 -44
  269. package/src/internal/docs-site.test.ts +0 -66
  270. package/src/internal/duration.test.ts +0 -29
  271. package/src/internal/eval-judge-model.test.ts +0 -187
  272. package/src/internal/eval-run-store.cancel.test.ts +0 -142
  273. package/src/internal/eval-run-store.storage.test.ts +0 -211
  274. package/src/internal/eval-runner.http.test.ts +0 -403
  275. package/src/internal/eval-runner.run.test.ts +0 -928
  276. package/src/internal/evals-client.test.ts +0 -307
  277. package/src/internal/event-mapper.test.ts +0 -243
  278. package/src/internal/github-fanout.test.ts +0 -213
  279. package/src/internal/handleAgentServeTrigger.test.ts +0 -185
  280. package/src/internal/host-kv.test.ts +0 -82
  281. package/src/internal/host-platforms.test.ts +0 -126
  282. package/src/internal/http-channel.test.ts +0 -402
  283. package/src/internal/init-project.test.ts +0 -270
  284. package/src/internal/install-cursor-skills.test.ts +0 -262
  285. package/src/internal/local-env.test.ts +0 -120
  286. package/src/internal/log-ring.test.ts +0 -31
  287. package/src/internal/logs-client.test.ts +0 -350
  288. package/src/internal/mcp-endpoint.test.ts +0 -436
  289. package/src/internal/mcp-host.test.ts +0 -298
  290. package/src/internal/mcp-oauth.test.ts +0 -148
  291. package/src/internal/net.test.ts +0 -17
  292. package/src/internal/peer-connections.test.ts +0 -128
  293. package/src/internal/peer-mcp.integration.test.ts +0 -289
  294. package/src/internal/playground/toolchain.test.ts +0 -53
  295. package/src/internal/playground-cli.test.ts +0 -187
  296. package/src/internal/playground-proxy.test.ts +0 -376
  297. package/src/internal/prompt-context.integration.test.ts +0 -232
  298. package/src/internal/prompt-context.test.ts +0 -127
  299. package/src/internal/reminder-runner.test.ts +0 -432
  300. package/src/internal/reminder-store.test.ts +0 -53
  301. package/src/internal/request-headers.test.ts +0 -27
  302. package/src/internal/resolve-prod-target.test.ts +0 -787
  303. package/src/internal/resolved-connections.test.ts +0 -295
  304. package/src/internal/router.test.ts +0 -57
  305. package/src/internal/sdk-runner.test.ts +0 -290
  306. package/src/internal/server.artifacts.test.ts +0 -334
  307. package/src/internal/session-engine.artifacts.test.ts +0 -293
  308. package/src/internal/session-engine.coalesce.test.ts +0 -169
  309. package/src/internal/session-engine.concurrency.test.ts +0 -250
  310. package/src/internal/session-engine.host-oauth-mcp.test.ts +0 -110
  311. package/src/internal/session-engine.interrupt.test.ts +0 -577
  312. package/src/internal/session-engine.storage.test.ts +0 -547
  313. package/src/internal/session-urls.test.ts +0 -28
  314. package/src/internal/sessions-client.test.ts +0 -518
  315. package/src/internal/storage-coordinator.test.ts +0 -517
  316. package/src/internal/tool-call.test.ts +0 -458
  317. package/src/internal/tool-result.test.ts +0 -52
  318. package/src/internal/trajectory.approvals.test.ts +0 -83
  319. package/src/internal/trajectory.subagents.test.ts +0 -198
  320. package/src/internal/turn-governor.test.ts +0 -137
  321. package/src/internal/update-check.test.ts +0 -485
  322. package/src/internal/workspace.test.ts +0 -207
  323. package/src/storage-backends/cursor-hosted.test.ts +0 -121
  324. /package/dist/docs/assets/{index.md.Dfv5ic9t.lean.js → index.md.CH_s5uZe.lean.js} +0 -0
@@ -1,267 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import {
3
- botMentionsFromEnv,
4
- buildDelegationMetadata,
5
- normalizeBotMentionAllowlist,
6
- parseDelegationMetadata,
7
- SLACK_DELEGATION_METADATA_EVENT_TYPE,
8
- SlackBotMentionGate,
9
- } from "./bot-mentions.js";
10
- import { parseAppMentionEvent } from "./inbound.js";
11
- import type { SlackMessage } from "./types.js";
12
-
13
- function botMention(patch: Partial<SlackMessage> = {}): SlackMessage {
14
- return {
15
- text: "<@ULASSO> please deploy #123",
16
- body: "<@ULASSO> please deploy #123",
17
- markdown: "@ULASSO please deploy #123",
18
- ts: "2.0",
19
- threadTs: "1.0",
20
- channelId: "C9",
21
- author: { userId: "ULASSO", isBot: true, botId: "BLASSO" },
22
- ...patch,
23
- };
24
- }
25
-
26
- function gate(
27
- options: Partial<ConstructorParameters<typeof SlackBotMentionGate>[0]> = {},
28
- identity: { botId?: string; botUserId?: string } = {
29
- botId: "BSELF",
30
- botUserId: "USELF",
31
- }
32
- ): SlackBotMentionGate {
33
- return new SlackBotMentionGate(
34
- { allowFrom: ["BLASSO"], ...options },
35
- identity,
36
- { log: { info() {}, warn() {}, error() {}, debug() {}, write() {} } }
37
- );
38
- }
39
-
40
- describe("delegation metadata", () => {
41
- it("round-trips build → parse", () => {
42
- const metadata = buildDelegationMetadata({
43
- depth: 2,
44
- fromAgent: "lasso",
45
- originSessionId: "sess-1",
46
- });
47
- expect(metadata.event_type).toBe(SLACK_DELEGATION_METADATA_EVENT_TYPE);
48
- const parsed = parseDelegationMetadata({ metadata });
49
- expect(parsed).toEqual({
50
- depth: 2,
51
- fromAgent: "lasso",
52
- originSessionId: "sess-1",
53
- });
54
- });
55
-
56
- it("ignores foreign and malformed metadata", () => {
57
- expect(parseDelegationMetadata({})).toBeUndefined();
58
- expect(
59
- parseDelegationMetadata({
60
- metadata: { event_type: "other", event_payload: { depth: 1 } },
61
- })
62
- ).toBeUndefined();
63
- expect(
64
- parseDelegationMetadata({
65
- metadata: {
66
- event_type: SLACK_DELEGATION_METADATA_EVENT_TYPE,
67
- event_payload: { depth: 0 },
68
- },
69
- })
70
- ).toBeUndefined();
71
- expect(
72
- parseDelegationMetadata({
73
- metadata: {
74
- event_type: SLACK_DELEGATION_METADATA_EVENT_TYPE,
75
- event_payload: { depth: "two" },
76
- },
77
- })
78
- ).toBeUndefined();
79
- });
80
- });
81
-
82
- describe("botMentionsFromEnv", () => {
83
- it("returns undefined when unset and options when set", () => {
84
- const envVar = "BOT_MENTIONS_TEST_VAR";
85
- delete process.env[envVar];
86
- expect(botMentionsFromEnv(envVar)).toBeUndefined();
87
- process.env[envVar] = " B1 ,,U2 ";
88
- expect(botMentionsFromEnv(envVar)).toEqual({ allowFrom: ["B1", "U2"] });
89
- delete process.env[envVar];
90
- });
91
- });
92
-
93
- describe("parseAppMentionEvent bot-authored", () => {
94
- const body = {
95
- type: "event_callback",
96
- team_id: "T1",
97
- event: {
98
- type: "app_mention",
99
- user: "ULASSO",
100
- bot_id: "BLASSO",
101
- text: "<@UTARGET> look into this",
102
- ts: "2.0",
103
- thread_ts: "1.0",
104
- channel: "C9",
105
- metadata: buildDelegationMetadata({ depth: 1, fromAgent: "lasso" }),
106
- },
107
- };
108
-
109
- it("drops bot mentions by default", () => {
110
- expect(parseAppMentionEvent(body)).toBeNull();
111
- });
112
-
113
- it("keeps bot mentions with delegation info when opted in", () => {
114
- const message = parseAppMentionEvent(body, { includeBotAuthored: true });
115
- expect(message).not.toBeNull();
116
- expect(message?.author?.isBot).toBe(true);
117
- expect(message?.author?.botId).toBe("BLASSO");
118
- expect(message?.delegation).toEqual({ depth: 1, fromAgent: "lasso" });
119
- });
120
-
121
- it("still parses human mentions when opted in", () => {
122
- const message = parseAppMentionEvent(
123
- {
124
- type: "event_callback",
125
- event: {
126
- type: "app_mention",
127
- user: "U1",
128
- text: "<@UTARGET> hi",
129
- ts: "3.0",
130
- channel: "C9",
131
- },
132
- },
133
- { includeBotAuthored: true }
134
- );
135
- expect(message?.author?.isBot).toBe(false);
136
- expect(message?.delegation).toBeUndefined();
137
- });
138
- });
139
-
140
- describe("normalizeBotMentionAllowlist", () => {
141
- it("trims entries and rejects empty lists", () => {
142
- expect(normalizeBotMentionAllowlist([" B1 ", "U2"])).toEqual(["B1", "U2"]);
143
- expect(() => normalizeBotMentionAllowlist([" "])).toThrow(/allowFrom/);
144
- });
145
- });
146
-
147
- describe("SlackBotMentionGate", () => {
148
- it("requires its own bot identity", () => {
149
- expect(() => gate({}, {})).toThrow(/identity/);
150
- });
151
-
152
- it("admits an allowlisted bot mention", () => {
153
- const verdict = gate().evaluate(botMention());
154
- expect(verdict).toEqual({ allow: true, depth: 1 });
155
- });
156
-
157
- it("matches on bot user id as well as bot_id", () => {
158
- const verdict = gate({ allowFrom: ["ULASSO"] }).evaluate(botMention());
159
- expect(verdict.allow).toBe(true);
160
- });
161
-
162
- it("matches compound botId:username entries case-insensitively", () => {
163
- const g = gate({ allowFrom: ["BCURSOR:Lasso"] });
164
- const fromCursorAsLasso = botMention({
165
- author: {
166
- userId: "UCURSOR",
167
- isBot: true,
168
- botId: "BCURSOR",
169
- userName: "lasso",
170
- },
171
- });
172
- expect(g.evaluate(fromCursorAsLasso).allow).toBe(true);
173
- });
174
-
175
- it("compound entries deny other usernames and missing usernames", () => {
176
- const g = gate({ allowFrom: ["BCURSOR:Lasso"] });
177
- expect(
178
- g.evaluate(
179
- botMention({
180
- author: {
181
- userId: "UCURSOR",
182
- isBot: true,
183
- botId: "BCURSOR",
184
- userName: "SomeOtherAgent",
185
- },
186
- })
187
- )
188
- ).toMatchObject({ allow: false });
189
- // No username on the event → fail closed.
190
- expect(
191
- g.evaluate(
192
- botMention({
193
- author: { userId: "UCURSOR", isBot: true, botId: "BCURSOR" },
194
- })
195
- )
196
- ).toMatchObject({ allow: false });
197
- // Bare bot_id was not allowlisted, only the compound form.
198
- expect(
199
- g.evaluate(
200
- botMention({
201
- author: {
202
- userId: "UCURSOR",
203
- isBot: true,
204
- botId: "BCURSOR",
205
- userName: undefined,
206
- },
207
- })
208
- )
209
- ).toMatchObject({ allow: false });
210
- });
211
-
212
- it("denies bots not in the allowlist", () => {
213
- const verdict = gate().evaluate(
214
- botMention({ author: { userId: "UOTHER", isBot: true, botId: "BOTHER" } })
215
- );
216
- expect(verdict).toMatchObject({ allow: false });
217
- });
218
-
219
- it("denies its own posts even when allowlisted", () => {
220
- const verdict = gate({ allowFrom: ["BSELF"] }).evaluate(
221
- botMention({ author: { userId: "USELF", isBot: true, botId: "BSELF" } })
222
- );
223
- expect(verdict).toMatchObject({ allow: false, reason: /own post/ });
224
- });
225
-
226
- it("enforces the depth budget", () => {
227
- const g = gate();
228
- expect(g.evaluate(botMention({ delegation: { depth: 2 } })).allow).toBe(
229
- true
230
- );
231
- expect(
232
- g.evaluate(botMention({ ts: "3.0", delegation: { depth: 3 } }))
233
- ).toMatchObject({ allow: false, reason: /depth/ });
234
- });
235
-
236
- it("enforces the rate budget with a sliding window", () => {
237
- const g = gate({ maxPerThreadPerHour: 2 });
238
- expect(g.evaluate(botMention(), 1000).allow).toBe(true);
239
- expect(g.evaluate(botMention(), 2000).allow).toBe(true);
240
- expect(g.evaluate(botMention(), 3000)).toMatchObject({
241
- allow: false,
242
- reason: /rate budget/,
243
- });
244
- // Window slides: an hour later the thread has rate budget again.
245
- const later = 3000 + 60 * 60 * 1000;
246
- expect(g.evaluate(botMention(), later).allow).toBe(true);
247
- // Other threads are unaffected.
248
- expect(g.evaluate(botMention({ threadTs: "9.0" }), 3000).allow).toBe(true);
249
- });
250
-
251
- it("terminates ping-pong with the lifetime thread cap", () => {
252
- const g = gate({ maxPerThreadPerHour: 100, maxPerThreadTotal: 3 });
253
- expect(g.evaluate(botMention(), 1000).allow).toBe(true);
254
- expect(g.evaluate(botMention(), 2000).allow).toBe(true);
255
- expect(g.evaluate(botMention(), 3000).allow).toBe(true);
256
- expect(g.evaluate(botMention(), 4000)).toMatchObject({
257
- allow: false,
258
- reason: /lifetime/,
259
- });
260
- // Sliding the window does NOT refill the lifetime cap.
261
- const muchLater = 4000 + 5 * 60 * 60 * 1000;
262
- expect(g.evaluate(botMention(), muchLater)).toMatchObject({
263
- allow: false,
264
- reason: /lifetime/,
265
- });
266
- });
267
- });
@@ -1,363 +0,0 @@
1
- import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
2
- import {
3
- createChannelPostWatcher,
4
- SlackChannelAllowlist,
5
- } from "./channel-watch.js";
6
- import {
7
- parseChannelMessageEvent,
8
- type SlackChannelMessageEvent,
9
- } from "./inbound.js";
10
- import type { SlackMessage } from "./types.js";
11
-
12
- function channelPostBody(args: {
13
- channel?: string;
14
- ts?: string;
15
- threadTs?: string;
16
- text?: string;
17
- subtype?: string;
18
- botId?: string;
19
- channelType?: string;
20
- user?: string | null;
21
- }): unknown {
22
- return {
23
- type: "event_callback",
24
- event_id: "Ev1",
25
- team_id: "T1",
26
- event: {
27
- type: "message",
28
- channel: args.channel ?? "C123",
29
- channel_type: args.channelType ?? "channel",
30
- ts: args.ts ?? "100.1",
31
- ...(args.threadTs === undefined ? {} : { thread_ts: args.threadTs }),
32
- text: args.text ?? "new bug report",
33
- ...(args.user === null ? {} : { user: args.user ?? "U1" }),
34
- ...(args.subtype === undefined ? {} : { subtype: args.subtype }),
35
- ...(args.botId === undefined ? {} : { bot_id: args.botId }),
36
- },
37
- };
38
- }
39
-
40
- describe("parseChannelMessageEvent", () => {
41
- it("parses a top-level channel post", () => {
42
- const parsed = parseChannelMessageEvent(channelPostBody({}));
43
- expect(parsed).not.toBeNull();
44
- expect(parsed?.kind).toBe("post");
45
- if (parsed?.kind === "post") {
46
- expect(parsed.message.channelId).toBe("C123");
47
- expect(parsed.message.ts).toBe("100.1");
48
- expect(parsed.message.threadTs).toBe("100.1");
49
- }
50
- });
51
-
52
- it("parses private-channel (group) posts", () => {
53
- const parsed = parseChannelMessageEvent(
54
- channelPostBody({ channel: "G9", channelType: "group" })
55
- );
56
- expect(parsed?.kind).toBe("post");
57
- });
58
-
59
- it("drops bot-authored posts", () => {
60
- expect(
61
- parseChannelMessageEvent(channelPostBody({ botId: "B77" }))
62
- ).toBeNull();
63
- });
64
-
65
- it("keeps bot-authored posts when includeBotAuthored is set", () => {
66
- const parsed = parseChannelMessageEvent(channelPostBody({ botId: "B77" }), {
67
- includeBotAuthored: true,
68
- });
69
- expect(parsed?.kind).toBe("post");
70
- if (parsed?.kind === "post") {
71
- expect(parsed.message.author?.isBot).toBe(true);
72
- expect(parsed.message.author?.botId).toBe("B77");
73
- }
74
- });
75
-
76
- it("keeps userless bot_message webhook posts when includeBotAuthored is set", () => {
77
- const body = channelPostBody({
78
- botId: "B77",
79
- subtype: "bot_message",
80
- user: null,
81
- text: "PagerDuty: high error rate on api",
82
- });
83
- expect(parseChannelMessageEvent(body)).toBeNull();
84
- const parsed = parseChannelMessageEvent(body, {
85
- includeBotAuthored: true,
86
- });
87
- expect(parsed?.kind).toBe("post");
88
- if (parsed?.kind === "post") {
89
- expect(parsed.message.author).toEqual({
90
- userId: "",
91
- isBot: true,
92
- botId: "B77",
93
- });
94
- }
95
- });
96
-
97
- it("recovers alert content from attachments when top-level text is empty", () => {
98
- const parsed = parseChannelMessageEvent(
99
- {
100
- type: "event_callback",
101
- team_id: "T1",
102
- event: {
103
- type: "message",
104
- subtype: "bot_message",
105
- channel: "C123",
106
- channel_type: "channel",
107
- ts: "100.1",
108
- bot_id: "B77",
109
- username: "Datadog",
110
- text: "",
111
- attachments: [
112
- {
113
- title:
114
- "Triggered: [service-monitor prod:temporal-bugbot] High cache error rate",
115
- title_link: "https://us5.datadoghq.com/monitors/19610160",
116
- text: "Service temporal-bugbot has a high cache error rate.",
117
- },
118
- ],
119
- },
120
- },
121
- { includeBotAuthored: true }
122
- );
123
- expect(parsed?.kind).toBe("post");
124
- if (parsed?.kind === "post") {
125
- expect(parsed.message.text).toBe("");
126
- expect(parsed.message.body).toContain("temporal-bugbot");
127
- // Raw body keeps the monitor link; markdown is the model-facing view.
128
- expect(parsed.message.body).toContain(
129
- "https://us5.datadoghq.com/monitors/19610160"
130
- );
131
- expect(parsed.message.markdown).toContain("High cache error rate");
132
- }
133
- });
134
-
135
- it("drops DMs and unknown subtypes", () => {
136
- expect(
137
- parseChannelMessageEvent(
138
- channelPostBody({ channel: "D5", channelType: "im" })
139
- )
140
- ).toBeNull();
141
- expect(
142
- parseChannelMessageEvent(channelPostBody({ subtype: "channel_join" }))
143
- ).toBeNull();
144
- });
145
-
146
- it("parses message_changed into an edit with the new text", () => {
147
- const parsed = parseChannelMessageEvent({
148
- type: "event_callback",
149
- event: {
150
- type: "message",
151
- subtype: "message_changed",
152
- channel: "C123",
153
- channel_type: "channel",
154
- ts: "101.0",
155
- message: { type: "message", ts: "100.1", text: "edited!", user: "U1" },
156
- },
157
- });
158
- expect(parsed?.kind).toBe("edited");
159
- if (parsed?.kind === "edited") {
160
- expect(parsed.message.ts).toBe("100.1");
161
- expect(parsed.message.text).toBe("edited!");
162
- }
163
- });
164
-
165
- it("parses message_deleted into a deletion", () => {
166
- const parsed = parseChannelMessageEvent({
167
- type: "event_callback",
168
- event: {
169
- type: "message",
170
- subtype: "message_deleted",
171
- channel: "C123",
172
- channel_type: "channel",
173
- ts: "101.0",
174
- deleted_ts: "100.1",
175
- },
176
- });
177
- expect(parsed).toEqual({ kind: "deleted", channelId: "C123", ts: "100.1" });
178
- });
179
- });
180
-
181
- describe("SlackChannelAllowlist", () => {
182
- it("matches ids directly and names after resolution", () => {
183
- const allowlist = new SlackChannelAllowlist(["C123", "#issues-glass"]);
184
- expect(allowlist.matches("C123")).toBe(true);
185
- expect(allowlist.matches("C999")).toBe(false);
186
- expect(allowlist.unresolvedNames()).toEqual(["issues-glass"]);
187
- allowlist.applyResolvedNames(new Map([["issues-glass", "C999"]]));
188
- expect(allowlist.matches("C999")).toBe(true);
189
- });
190
-
191
- it("treats bare names as names, not ids", () => {
192
- const allowlist = new SlackChannelAllowlist(["issues-glass"]);
193
- expect(allowlist.unresolvedNames()).toEqual(["issues-glass"]);
194
- });
195
- });
196
-
197
- describe("createChannelPostWatcher", () => {
198
- const dispatched: Array<{ message: SlackMessage; eventId?: string }> = [];
199
-
200
- function watcher(args?: {
201
- posts?: "top-level" | "all";
202
- debounceMs?: number;
203
- includeBotPosts?: boolean;
204
- botUserId?: string;
205
- botId?: string;
206
- allow?: string[];
207
- }) {
208
- return createChannelPostWatcher({
209
- options: {
210
- allow: args?.allow ?? ["C123"],
211
- ...(args?.posts === undefined ? {} : { posts: args.posts }),
212
- ...(args?.debounceMs === undefined
213
- ? {}
214
- : { debounceMs: args.debounceMs }),
215
- ...(args?.includeBotPosts === undefined
216
- ? {}
217
- : { includeBotPosts: args.includeBotPosts }),
218
- },
219
- allowlist: new SlackChannelAllowlist(args?.allow ?? ["C123"]),
220
- getBotUserId: () => args?.botUserId,
221
- getBotId: () => args?.botId,
222
- dispatch: (message, eventId) =>
223
- dispatched.push(
224
- eventId === undefined ? { message } : { message, eventId }
225
- ),
226
- });
227
- }
228
-
229
- function post(args: {
230
- channel?: string;
231
- ts?: string;
232
- threadTs?: string;
233
- text?: string;
234
- subtype?: string;
235
- botId?: string;
236
- user?: string | null;
237
- }): SlackChannelMessageEvent {
238
- const parsed = parseChannelMessageEvent(channelPostBody(args), {
239
- includeBotAuthored: true,
240
- });
241
- if (parsed === null) {
242
- throw new Error("fixture did not parse");
243
- }
244
- return parsed;
245
- }
246
-
247
- beforeEach(() => {
248
- dispatched.length = 0;
249
- });
250
- afterEach(() => {
251
- vi.useRealTimers();
252
- });
253
-
254
- it("dispatches allowlisted top-level posts immediately by default", () => {
255
- const w = watcher();
256
- expect(w.handle(post({}), "Ev1")).toBe(true);
257
- expect(dispatched).toHaveLength(1);
258
- expect(dispatched[0]?.eventId).toBe("Ev1");
259
- });
260
-
261
- it("skips channels outside the allowlist", () => {
262
- const w = watcher();
263
- w.handle(post({ channel: "C999" }));
264
- expect(dispatched).toHaveLength(0);
265
- });
266
-
267
- it("skips thread replies unless posts is 'all'", () => {
268
- const w = watcher();
269
- w.handle(post({ ts: "100.2", threadTs: "100.1" }));
270
- expect(dispatched).toHaveLength(0);
271
-
272
- const all = watcher({ posts: "all" });
273
- all.handle(post({ ts: "100.2", threadTs: "100.1" }));
274
- expect(dispatched).toHaveLength(1);
275
- });
276
-
277
- it("skips posts that mention the bot (app_mention path owns them)", () => {
278
- const w = watcher({ botUserId: "UBOT" });
279
- w.handle(post({ text: "<@UBOT> please triage" }));
280
- expect(dispatched).toHaveLength(0);
281
- });
282
-
283
- it("skips bot-authored posts unless includeBotPosts is set", () => {
284
- const w = watcher();
285
- w.handle(post({ botId: "B77", user: null, subtype: "bot_message" }));
286
- expect(dispatched).toHaveLength(0);
287
-
288
- const withBots = watcher({
289
- includeBotPosts: true,
290
- botId: "BSELF",
291
- botUserId: "UBOT",
292
- });
293
- withBots.handle(post({ botId: "B77", user: null, subtype: "bot_message" }));
294
- expect(dispatched).toHaveLength(1);
295
- expect(dispatched[0]?.message.author?.botId).toBe("B77");
296
- });
297
-
298
- it("skips bot-authored posts when includeBotPosts is on but bot identity is unknown", () => {
299
- const w = watcher({ includeBotPosts: true });
300
- w.handle(post({ botId: "B77", user: null, subtype: "bot_message" }));
301
- expect(dispatched).toHaveLength(0);
302
- });
303
-
304
- it("always skips the watching bot's own posts (loop safety)", () => {
305
- const w = watcher({
306
- includeBotPosts: true,
307
- botUserId: "UBOT",
308
- botId: "BSELF",
309
- });
310
- w.handle(post({ botId: "BSELF", user: null, subtype: "bot_message" }));
311
- expect(dispatched).toHaveLength(0);
312
-
313
- // Same app posting with its bot user id attached.
314
- w.handle(post({ botId: "B99", user: "UBOT" }));
315
- expect(dispatched).toHaveLength(0);
316
-
317
- // A different bot still dispatches.
318
- w.handle(post({ botId: "B77", user: null, subtype: "bot_message" }));
319
- expect(dispatched).toHaveLength(1);
320
- });
321
-
322
- it("debounces: edits update the pending text, deletes cancel", () => {
323
- vi.useFakeTimers();
324
- const w = watcher({ debounceMs: 1_000 });
325
-
326
- w.handle(post({ ts: "100.1", text: "first" }));
327
- expect(dispatched).toHaveLength(0);
328
- const edit = parseChannelMessageEvent({
329
- type: "event_callback",
330
- event: {
331
- type: "message",
332
- subtype: "message_changed",
333
- channel: "C123",
334
- channel_type: "channel",
335
- ts: "101.0",
336
- message: { type: "message", ts: "100.1", text: "edited", user: "U1" },
337
- },
338
- });
339
- if (edit === null) {
340
- throw new Error("edit fixture did not parse");
341
- }
342
- w.handle(edit);
343
- vi.advanceTimersByTime(1_000);
344
- expect(dispatched).toHaveLength(1);
345
- expect(dispatched[0]?.message.text).toBe("edited");
346
-
347
- w.handle(post({ ts: "200.1", text: "will be deleted" }));
348
- w.handle({ kind: "deleted", channelId: "C123", ts: "200.1" });
349
- vi.advanceTimersByTime(5_000);
350
- expect(dispatched).toHaveLength(1);
351
-
352
- w.stop();
353
- });
354
-
355
- it("stop() cancels pending dispatches", () => {
356
- vi.useFakeTimers();
357
- const w = watcher({ debounceMs: 1_000 });
358
- w.handle(post({}));
359
- w.stop();
360
- vi.advanceTimersByTime(5_000);
361
- expect(dispatched).toHaveLength(0);
362
- });
363
- });