@cursor/july 0.1.26 → 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 (277) 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/internal/ab-fold.ts +4 -0
  145. package/src/internal/ab-snapshot.ts +1 -0
  146. package/src/internal/cli-ax.ts +95 -0
  147. package/src/internal/model-pricing.ts +426 -0
  148. package/src/internal/sdk-runner.ts +10 -2
  149. package/src/internal/session-cost.ts +231 -0
  150. package/src/internal/session-engine.ts +28 -0
  151. package/src/internal/trajectory.ts +45 -3
  152. package/src/types.ts +24 -1
  153. package/dist/channels/github/instrument.d.ts +0 -20
  154. package/dist/channels/github/instrument.d.ts.map +0 -1
  155. package/dist/docs/assets/chunks/@localSearchIndexroot.BQTzJjR_.js +0 -1
  156. package/dist/internal/json-dir-store.d.ts +0 -32
  157. package/dist/internal/json-dir-store.d.ts.map +0 -1
  158. package/dist/internal/json-dir-store.js +0 -100
  159. package/dist/playground/assets/index-CjOQ4hN9.css +0 -1
  160. package/dist/playground/assets/index-DqXdAFGa.js +0 -85
  161. package/src/bin/agent-serve.version.test.ts +0 -64
  162. package/src/channels/github/api.test.ts +0 -64
  163. package/src/channels/github/auth.test.ts +0 -105
  164. package/src/channels/github/cursor-account.test.ts +0 -204
  165. package/src/channels/github/forward.test.ts +0 -457
  166. package/src/channels/github/github.test.ts +0 -985
  167. package/src/channels/github/replay.test.ts +0 -179
  168. package/src/channels/slack/api.post-message.test.ts +0 -148
  169. package/src/channels/slack/approvals.test.ts +0 -328
  170. package/src/channels/slack/block-actions.test.ts +0 -469
  171. package/src/channels/slack/bot-mentions.test.ts +0 -267
  172. package/src/channels/slack/channel-watch.test.ts +0 -363
  173. package/src/channels/slack/cursor-account.test.ts +0 -301
  174. package/src/channels/slack/defaults.final-post.test.ts +0 -182
  175. package/src/channels/slack/dispatch.test.ts +0 -875
  176. package/src/channels/slack/eval-directive.test.ts +0 -273
  177. package/src/channels/slack/message-body.test.ts +0 -54
  178. package/src/channels/slack/nudge-store.test.ts +0 -143
  179. package/src/channels/slack/slack.test.ts +0 -391
  180. package/src/channels/slack/stop.test.ts +0 -23
  181. package/src/channels/slack/thread-context.test.ts +0 -202
  182. package/src/evals/assertions.test.ts +0 -617
  183. package/src/evals/expect.test.ts +0 -144
  184. package/src/evals/judge.test.ts +0 -181
  185. package/src/evals/loaders.test.ts +0 -132
  186. package/src/evals/matchers.test.ts +0 -95
  187. package/src/evals/reporters.test.ts +0 -303
  188. package/src/evals/run-facts.test.ts +0 -259
  189. package/src/internal/ab-snapshot.test.ts +0 -325
  190. package/src/internal/approval-gate.test.ts +0 -49
  191. package/src/internal/approvals.integration.test.ts +0 -383
  192. package/src/internal/artifacts-store.test.ts +0 -283
  193. package/src/internal/authored-loaders.test.ts +0 -31
  194. package/src/internal/builtin-tools/artifacts.test.ts +0 -247
  195. package/src/internal/builtin-tools/reminders.test.ts +0 -201
  196. package/src/internal/channel-route-schema.test.ts +0 -294
  197. package/src/internal/chat-attach.test.ts +0 -262
  198. package/src/internal/cli-deploy.test.ts +0 -1991
  199. package/src/internal/cli-docs.test.ts +0 -161
  200. package/src/internal/cli-mcp.test.ts +0 -789
  201. package/src/internal/cli-skills.test.ts +0 -133
  202. package/src/internal/cli-slack.test.ts +0 -1654
  203. package/src/internal/cloud-merge.test.ts +0 -74
  204. package/src/internal/cron.test.ts +0 -22
  205. package/src/internal/cursor/account-mcp.test.ts +0 -807
  206. package/src/internal/cursor/backend-client.test.ts +0 -591
  207. package/src/internal/cursor/credentials.test.ts +0 -351
  208. package/src/internal/cursor/github-credentials.test.ts +0 -136
  209. package/src/internal/cursor-account-mcp-auth.test.ts +0 -310
  210. package/src/internal/cursor-account.integration.test.ts +0 -441
  211. package/src/internal/cursor-event-relay.test.ts +0 -746
  212. package/src/internal/cursor-github-credentials.integration.test.ts +0 -271
  213. package/src/internal/cursor-slack-relay.test.ts +0 -525
  214. package/src/internal/deploy-source.test.ts +0 -111
  215. package/src/internal/discovery.artifact-tool.test.ts +0 -136
  216. package/src/internal/discovery.artifacts.test.ts +0 -119
  217. package/src/internal/discovery.builtin-tools.test.ts +0 -94
  218. package/src/internal/discovery.concurrency.test.ts +0 -60
  219. package/src/internal/discovery.cursor-account.test.ts +0 -133
  220. package/src/internal/discovery.cwd.test.ts +0 -83
  221. package/src/internal/discovery.hosting.test.ts +0 -80
  222. package/src/internal/discovery.identity.test.ts +0 -44
  223. package/src/internal/docs-site.test.ts +0 -66
  224. package/src/internal/duration.test.ts +0 -29
  225. package/src/internal/eval-judge-model.test.ts +0 -187
  226. package/src/internal/eval-run-store.cancel.test.ts +0 -142
  227. package/src/internal/eval-run-store.storage.test.ts +0 -211
  228. package/src/internal/eval-runner.http.test.ts +0 -403
  229. package/src/internal/eval-runner.run.test.ts +0 -928
  230. package/src/internal/evals-client.test.ts +0 -307
  231. package/src/internal/event-mapper.test.ts +0 -243
  232. package/src/internal/github-fanout.test.ts +0 -213
  233. package/src/internal/handleAgentServeTrigger.test.ts +0 -185
  234. package/src/internal/host-kv.test.ts +0 -82
  235. package/src/internal/host-platforms.test.ts +0 -126
  236. package/src/internal/http-channel.test.ts +0 -402
  237. package/src/internal/init-project.test.ts +0 -270
  238. package/src/internal/install-cursor-skills.test.ts +0 -262
  239. package/src/internal/local-env.test.ts +0 -120
  240. package/src/internal/log-ring.test.ts +0 -31
  241. package/src/internal/logs-client.test.ts +0 -350
  242. package/src/internal/mcp-endpoint.test.ts +0 -436
  243. package/src/internal/mcp-host.test.ts +0 -298
  244. package/src/internal/mcp-oauth.test.ts +0 -148
  245. package/src/internal/net.test.ts +0 -17
  246. package/src/internal/peer-connections.test.ts +0 -128
  247. package/src/internal/peer-mcp.integration.test.ts +0 -289
  248. package/src/internal/playground/toolchain.test.ts +0 -53
  249. package/src/internal/playground-cli.test.ts +0 -187
  250. package/src/internal/playground-proxy.test.ts +0 -376
  251. package/src/internal/prompt-context.integration.test.ts +0 -232
  252. package/src/internal/prompt-context.test.ts +0 -127
  253. package/src/internal/reminder-runner.test.ts +0 -432
  254. package/src/internal/reminder-store.test.ts +0 -53
  255. package/src/internal/request-headers.test.ts +0 -27
  256. package/src/internal/resolve-prod-target.test.ts +0 -787
  257. package/src/internal/resolved-connections.test.ts +0 -295
  258. package/src/internal/router.test.ts +0 -57
  259. package/src/internal/sdk-runner.test.ts +0 -290
  260. package/src/internal/server.artifacts.test.ts +0 -334
  261. package/src/internal/session-engine.artifacts.test.ts +0 -293
  262. package/src/internal/session-engine.coalesce.test.ts +0 -169
  263. package/src/internal/session-engine.concurrency.test.ts +0 -250
  264. package/src/internal/session-engine.host-oauth-mcp.test.ts +0 -110
  265. package/src/internal/session-engine.interrupt.test.ts +0 -577
  266. package/src/internal/session-engine.storage.test.ts +0 -547
  267. package/src/internal/session-urls.test.ts +0 -28
  268. package/src/internal/sessions-client.test.ts +0 -518
  269. package/src/internal/storage-coordinator.test.ts +0 -517
  270. package/src/internal/tool-call.test.ts +0 -458
  271. package/src/internal/tool-result.test.ts +0 -52
  272. package/src/internal/trajectory.approvals.test.ts +0 -83
  273. package/src/internal/trajectory.subagents.test.ts +0 -198
  274. package/src/internal/turn-governor.test.ts +0 -137
  275. package/src/internal/update-check.test.ts +0 -485
  276. package/src/internal/workspace.test.ts +0 -207
  277. package/src/storage-backends/cursor-hosted.test.ts +0 -121
@@ -1,295 +0,0 @@
1
- import { describe, expect, it, vi } from "vitest";
2
- import { httpChannel } from "../channels.js";
3
- import type { AgentProject, DiscoveredConnection } from "../types.js";
4
- import { CursorAccountMcpBridge } from "./cursor/account-mcp.js";
5
- import { CursorBackendClient } from "./cursor/backend-client.js";
6
- import {
7
- assertAccountConnectionsNotAnonymous,
8
- assertCloudCanHonorAccountServersFilters,
9
- resolveMountConnections,
10
- validateMountConnectionsConfig,
11
- } from "./resolved-connections.js";
12
-
13
- function makeProject(
14
- overrides: Partial<AgentProject["agent"]> = {},
15
- connections: DiscoveredConnection[] = []
16
- ): AgentProject {
17
- return {
18
- rootDir: "/tmp/resolved-connections-fixture",
19
- agentDir: "/tmp/resolved-connections-fixture/agent",
20
- name: "fixture",
21
- agent: {
22
- name: "fixture",
23
- runtime: "local",
24
- tools: [],
25
- skills: [],
26
- connections,
27
- subagents: [],
28
- seedFiles: [],
29
- ...overrides,
30
- },
31
- httpChannel: httpChannel(),
32
- channels: [],
33
- schedules: [],
34
- hooks: [],
35
- abs: [],
36
- diagnostics: [],
37
- };
38
- }
39
-
40
- function stubBridge(): CursorAccountMcpBridge {
41
- const fetchImpl = vi.fn(async () =>
42
- Response.json({ accessToken: "token", refreshToken: "refresh" })
43
- );
44
- return new CursorAccountMcpBridge({
45
- client: new CursorBackendClient({
46
- backendUrl: "http://127.0.0.1:9",
47
- apiKey: "crsr_test",
48
- fetchImpl,
49
- }),
50
- });
51
- }
52
-
53
- describe("resolveMountConnections", () => {
54
- it("refuses cloud-capable agents with filtered account MCP connections and no publicUrl", () => {
55
- const project = makeProject({ runtime: "cloud" }, [
56
- {
57
- name: "cursor",
58
- transport: { cursorAccount: true, servers: ["Linear"] },
59
- },
60
- ]);
61
- expect(() =>
62
- validateMountConnectionsConfig({
63
- slug: "",
64
- project,
65
- accountRefs: [{ name: "cursor", servers: ["Linear"] }],
66
- })
67
- ).toThrow(/servers.*filters.*no --public-url/);
68
- });
69
-
70
- it("allows cloud-capable agents with unfiltered account MCP connections and no publicUrl", () => {
71
- const project = makeProject({ runtime: "cloud" }, [
72
- { name: "cursor", transport: { cursorAccount: true } },
73
- ]);
74
- const warnings: string[] = [];
75
- const resolved = resolveMountConnections({
76
- slug: "",
77
- project,
78
- serverUrl: "http://127.0.0.1:4100",
79
- accountRefs: [{ name: "cursor" }],
80
- accountBridge: stubBridge(),
81
- logger: (line) => {
82
- warnings.push(line);
83
- },
84
- });
85
- expect(resolved).toHaveLength(1);
86
- expect(resolved[0]?.cloudUrl).toBeUndefined();
87
- expect(
88
- warnings.some((line) => line.includes("omit the account bridge"))
89
- ).toBe(true);
90
- });
91
-
92
- it("resolves cloudUrl for filtered account MCP connections when publicUrl is set", () => {
93
- const project = makeProject({ runtime: "cloud" }, [
94
- {
95
- name: "cursor",
96
- transport: { cursorAccount: true, servers: ["Linear"] },
97
- },
98
- ]);
99
- const resolved = resolveMountConnections({
100
- slug: "",
101
- project,
102
- serverUrl: "http://127.0.0.1:4100",
103
- publicUrl: "https://agents.example.com",
104
- accountRefs: [{ name: "cursor", servers: ["Linear"] }],
105
- accountBridge: stubBridge(),
106
- logger: () => {},
107
- });
108
- expect(resolved[0]?.cloudUrl).toBe(
109
- "https://agents.example.com/v1/cursor-account/cursor/mcp"
110
- );
111
- expect(resolved[0]?.accountServersFilter).toEqual(["Linear"]);
112
- });
113
-
114
- it("exempts hostOnly filtered account connections from the publicUrl requirement", () => {
115
- // A host-only bridge never reaches the model, so cloud turns have no
116
- // `servers` filter to honor — host-side calls always use loopback.
117
- const project = makeProject({ runtime: "cloud" }, [
118
- {
119
- name: "anytool",
120
- transport: { cursorAccount: true, servers: ["anytool"] },
121
- hostOnly: true,
122
- },
123
- ]);
124
- expect(() =>
125
- validateMountConnectionsConfig({
126
- slug: "",
127
- project,
128
- accountRefs: [{ name: "anytool", servers: ["anytool"] }],
129
- })
130
- ).not.toThrow();
131
- });
132
-
133
- it("still refuses when a filtered account connection is not hostOnly", () => {
134
- const project = makeProject({ runtime: "cloud" }, [
135
- {
136
- name: "anytool",
137
- transport: { cursorAccount: true, servers: ["anytool"] },
138
- hostOnly: true,
139
- },
140
- {
141
- name: "cursor",
142
- transport: { cursorAccount: true, servers: ["Linear"] },
143
- },
144
- ]);
145
- expect(() =>
146
- validateMountConnectionsConfig({
147
- slug: "",
148
- project,
149
- accountRefs: [
150
- { name: "anytool", servers: ["anytool"] },
151
- { name: "cursor", servers: ["Linear"] },
152
- ],
153
- })
154
- ).toThrow(/servers.*filters.*no --public-url/);
155
- });
156
-
157
- it("warns that cloud turns omit host-OAuth connections", () => {
158
- const project = makeProject({ runtime: "cloud" }, [
159
- {
160
- name: "anytool",
161
- transport: { url: "https://anytool.example.com/mcp", oauth: true },
162
- },
163
- ]);
164
- const warnings: string[] = [];
165
- resolveMountConnections({
166
- slug: "",
167
- project,
168
- serverUrl: "http://127.0.0.1:4100",
169
- logger: (line) => {
170
- warnings.push(line);
171
- },
172
- });
173
- expect(
174
- warnings.some(
175
- (line) =>
176
- line.includes("host-OAuth MCP connections (anytool)") &&
177
- line.includes("cloud-runtime turns omit them")
178
- )
179
- ).toBe(true);
180
- });
181
-
182
- it("does not warn about host-OAuth connections on local agents or hostOnly ones", () => {
183
- const warnings: string[] = [];
184
- const logger = (line: string): void => {
185
- warnings.push(line);
186
- };
187
- resolveMountConnections({
188
- slug: "",
189
- project: makeProject({ runtime: "local" }, [
190
- {
191
- name: "anytool",
192
- transport: { url: "https://anytool.example.com/mcp", oauth: true },
193
- },
194
- ]),
195
- serverUrl: "http://127.0.0.1:4100",
196
- logger,
197
- });
198
- resolveMountConnections({
199
- slug: "",
200
- project: makeProject({ runtime: "cloud" }, [
201
- {
202
- name: "anytool",
203
- transport: { url: "https://anytool.example.com/mcp", oauth: true },
204
- hostOnly: true,
205
- },
206
- ]),
207
- serverUrl: "http://127.0.0.1:4100",
208
- logger,
209
- });
210
- expect(warnings.some((line) => line.includes("host-OAuth"))).toBe(false);
211
- });
212
-
213
- it("allows local-default agents with filtered account MCP connections at startup", () => {
214
- const project = makeProject({ runtime: "local" }, [
215
- {
216
- name: "cursor",
217
- transport: { cursorAccount: true, servers: ["Linear"] },
218
- },
219
- ]);
220
- const resolved = resolveMountConnections({
221
- slug: "",
222
- project,
223
- serverUrl: "http://127.0.0.1:4100",
224
- accountRefs: [{ name: "cursor", servers: ["Linear"] }],
225
- accountBridge: stubBridge(),
226
- logger: () => {},
227
- });
228
- expect(resolved).toHaveLength(1);
229
- expect(resolved[0]?.cloudUrl).toBeUndefined();
230
- });
231
- });
232
-
233
- describe("assertCloudCanHonorAccountServersFilters", () => {
234
- it("refuses cloud turns when a filtered account bridge lacks cloudUrl", () => {
235
- expect(() =>
236
- assertCloudCanHonorAccountServersFilters({
237
- runtime: "cloud",
238
- resolvedConnections: [
239
- {
240
- name: "cursor",
241
- localUrl: "http://127.0.0.1:4100/v1/cursor-account/cursor/mcp",
242
- accountServersFilter: ["Linear"],
243
- },
244
- ],
245
- })
246
- ).toThrow(/cannot honor Cursor account `servers` filters/);
247
- });
248
-
249
- it("allows local turns without a public bridge URL", () => {
250
- expect(() =>
251
- assertCloudCanHonorAccountServersFilters({
252
- runtime: "local",
253
- resolvedConnections: [
254
- {
255
- name: "cursor",
256
- localUrl: "http://127.0.0.1:4100/v1/cursor-account/cursor/mcp",
257
- accountServersFilter: ["Linear"],
258
- },
259
- ],
260
- })
261
- ).not.toThrow();
262
- });
263
- });
264
-
265
- describe("assertAccountConnectionsNotAnonymous", () => {
266
- it("refuses anonymous admission when account MCP connections are configured", () => {
267
- expect(() =>
268
- assertAccountConnectionsNotAnonymous({
269
- allowAnonymous: true,
270
- hasAccountConnections: true,
271
- })
272
- ).toThrow(
273
- /--allow-anonymous cannot be used with Cursor account MCP connections/
274
- );
275
- });
276
-
277
- it("allows anonymous admission without account MCP connections", () => {
278
- expect(() =>
279
- assertAccountConnectionsNotAnonymous({
280
- allowAnonymous: true,
281
- hasAccountConnections: false,
282
- })
283
- ).not.toThrow();
284
- });
285
-
286
- it("allows anonymous admission when allowAnonymousCursorAccountMcp opts in", () => {
287
- expect(() =>
288
- assertAccountConnectionsNotAnonymous({
289
- allowAnonymous: true,
290
- allowAnonymousCursorAccountMcp: true,
291
- hasAccountConnections: true,
292
- })
293
- ).not.toThrow();
294
- });
295
- });
@@ -1,57 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { Router, type ServerRoute } from "./router.js";
3
-
4
- function route(pattern: string): ServerRoute {
5
- return {
6
- method: "GET",
7
- pattern,
8
- auth: "none",
9
- handler: () => new Response("ok"),
10
- };
11
- }
12
-
13
- describe("Router catch-all segments", () => {
14
- it("matches zero or more trailing segments", () => {
15
- const router = new Router();
16
- router.add(route("/docs/*path"));
17
-
18
- expect(router.match("GET", "/docs")?.params.path).toBe("");
19
- expect(router.match("GET", "/docs/")?.params.path).toBe("");
20
- expect(router.match("GET", "/docs/quickstart")?.params.path).toBe(
21
- "quickstart"
22
- );
23
- expect(router.match("GET", "/docs/guides/slack")?.params.path).toBe(
24
- "guides/slack"
25
- );
26
- expect(router.match("GET", "/docs/assets/chunks/app.js")?.params.path).toBe(
27
- "assets/chunks/app.js"
28
- );
29
- });
30
-
31
- it("decodes each captured segment", () => {
32
- const router = new Router();
33
- router.add(route("/docs/*path"));
34
- expect(router.match("GET", "/docs/a%20b/c")?.params.path).toBe("a b/c");
35
- });
36
-
37
- it("does not shadow unrelated prefixes", () => {
38
- const router = new Router();
39
- router.add(route("/docs/*path"));
40
- expect(router.match("GET", "/v1/health")).toBeUndefined();
41
- expect(router.match("GET", "/docsx")).toBeUndefined();
42
- });
43
-
44
- it("still matches fixed segments before the catch-all", () => {
45
- const router = new Router();
46
- router.add(route("/a/:id/*rest"));
47
- const match = router.match("GET", "/a/42/x/y");
48
- expect(match?.params.id).toBe("42");
49
- expect(match?.params.rest).toBe("x/y");
50
- expect(router.match("GET", "/a")).toBeUndefined();
51
- });
52
-
53
- it("rejects non-trailing catch-alls at registration", () => {
54
- const router = new Router();
55
- expect(() => router.add(route("/a/*rest/b"))).toThrow(/last segment/);
56
- });
57
- });
@@ -1,290 +0,0 @@
1
- import { mkdtemp } from "node:fs/promises";
2
- import { tmpdir } from "node:os";
3
- import { join } from "node:path";
4
- import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
5
- import type { RunnerTurnRequest } from "../types.js";
6
- import { CursorSdkRunner } from "./sdk-runner.js";
7
-
8
- const { createAgent, resumeAgent } = vi.hoisted(() => ({
9
- createAgent: vi.fn(),
10
- resumeAgent: vi.fn(),
11
- }));
12
-
13
- vi.mock("@cursor/sdk", () => ({
14
- Agent: {
15
- create: createAgent,
16
- resume: resumeAgent,
17
- },
18
- JsonlLocalAgentStore: class JsonlLocalAgentStore {
19
- constructor(readonly path: string) {}
20
- },
21
- }));
22
-
23
- describe("CursorSdkRunner", () => {
24
- beforeEach(() => {
25
- createAgent.mockReset();
26
- resumeAgent.mockReset();
27
- });
28
-
29
- afterEach(() => {
30
- delete process.env.CURSOR_API_KEY;
31
- });
32
-
33
- it("creates a local SDK agent when no SDK id was ever bound", async () => {
34
- process.env.CURSOR_API_KEY = "test-key";
35
- const agent = fakeAgent("ses_retry");
36
- createAgent.mockResolvedValue(agent);
37
- const runner = new CursorSdkRunner();
38
- const stateRoot = await mkdtemp(join(tmpdir(), "agent-serve-sdk-runner-"));
39
- const onSdkAgentId = vi.fn();
40
-
41
- await runner.runTurn({
42
- ...baseRequest(stateRoot),
43
- isFirstTurn: false,
44
- onSdkAgentId,
45
- });
46
-
47
- expect(createAgent).toHaveBeenCalledExactlyOnceWith(
48
- expect.objectContaining({ agentId: "ses_retry" })
49
- );
50
- expect(resumeAgent).not.toHaveBeenCalled();
51
- expect(onSdkAgentId).toHaveBeenCalledExactlyOnceWith("ses_retry");
52
- });
53
-
54
- it("falls back to a fresh conversation when resume finds no stored agent", async () => {
55
- process.env.CURSOR_API_KEY = "test-key";
56
- resumeAgent.mockRejectedValue(new Error("Agent ses_retry not found"));
57
- createAgent.mockResolvedValue(fakeAgent("ses_retry"));
58
- const lines: string[] = [];
59
- const runner = new CursorSdkRunner({ logger: (line) => lines.push(line) });
60
- const stateRoot = await mkdtemp(join(tmpdir(), "agent-serve-sdk-runner-"));
61
-
62
- const outcome = await runner.runTurn({
63
- ...baseRequest(stateRoot),
64
- isFirstTurn: false,
65
- sdkAgentId: "ses_retry",
66
- });
67
-
68
- expect(outcome.status).toBe("finished");
69
- expect(resumeAgent).toHaveBeenCalledOnce();
70
- expect(createAgent).toHaveBeenCalledExactlyOnceWith(
71
- expect.objectContaining({ agentId: "ses_retry" })
72
- );
73
- expect(lines.join("\n")).toContain("fresh");
74
- });
75
-
76
- it("propagates resume failures that are not a store miss", async () => {
77
- process.env.CURSOR_API_KEY = "test-key";
78
- resumeAgent.mockRejectedValue(new Error("transport exploded"));
79
- const runner = new CursorSdkRunner();
80
- const stateRoot = await mkdtemp(join(tmpdir(), "agent-serve-sdk-runner-"));
81
-
82
- await expect(
83
- runner.runTurn({
84
- ...baseRequest(stateRoot),
85
- isFirstTurn: false,
86
- sdkAgentId: "ses_retry",
87
- })
88
- ).rejects.toThrow("transport exploded");
89
- expect(createAgent).not.toHaveBeenCalled();
90
- });
91
-
92
- it("surfaces the SDK RunResult error message on failed turns", async () => {
93
- process.env.CURSOR_API_KEY = "test-key";
94
- const agent = {
95
- agentId: "ses_retry",
96
- send: vi.fn(async () => ({
97
- wait: async () => ({
98
- status: "error" as const,
99
- error: {
100
- message:
101
- "Authentication error If you are logged in, try logging out and back in.",
102
- },
103
- }),
104
- })),
105
- };
106
- createAgent.mockResolvedValue(agent);
107
- const runner = new CursorSdkRunner();
108
- const stateRoot = await mkdtemp(join(tmpdir(), "agent-serve-sdk-runner-"));
109
-
110
- const outcome = await runner.runTurn(baseRequest(stateRoot));
111
-
112
- expect(outcome.status).toBe("error");
113
- expect(outcome.errorMessage).toBe(
114
- "Authentication error If you are logged in, try logging out and back in."
115
- );
116
- // First turns never retry in place: their token was exchanged moments
117
- // ago, so the credential itself is bad and a fresh handle cannot help.
118
- expect(agent.send).toHaveBeenCalledTimes(1);
119
- });
120
-
121
- it("evicts the cached agent after an error result so the next turn reopens", async () => {
122
- process.env.CURSOR_API_KEY = "test-key";
123
- const broken = fakeErrorAgent("ses_retry", "model exploded");
124
- const healthy = fakeAgent("ses_retry");
125
- resumeAgent.mockResolvedValueOnce(broken).mockResolvedValueOnce(healthy);
126
- const runner = new CursorSdkRunner();
127
- const stateRoot = await mkdtemp(join(tmpdir(), "agent-serve-sdk-runner-"));
128
- const request = {
129
- ...baseRequest(stateRoot),
130
- isFirstTurn: false,
131
- sdkAgentId: "ses_retry",
132
- };
133
-
134
- const first = await runner.runTurn(request);
135
- expect(first.status).toBe("error");
136
- // Not an auth failure, so no in-place retry.
137
- expect(resumeAgent).toHaveBeenCalledTimes(1);
138
-
139
- const second = await runner.runTurn(request);
140
- expect(second.status).toBe("finished");
141
- expect(resumeAgent).toHaveBeenCalledTimes(2);
142
- expect(broken.close).toHaveBeenCalled();
143
- });
144
-
145
- it("retries once on a fresh handle when an auth failure precedes any output", async () => {
146
- process.env.CURSOR_API_KEY = "test-key";
147
- const broken = fakeErrorAgent("ses_retry", AUTH_ERROR_MESSAGE);
148
- const healthy = fakeAgent("ses_retry");
149
- resumeAgent.mockResolvedValueOnce(broken).mockResolvedValueOnce(healthy);
150
- const lines: string[] = [];
151
- const runner = new CursorSdkRunner({ logger: (line) => lines.push(line) });
152
- const stateRoot = await mkdtemp(join(tmpdir(), "agent-serve-sdk-runner-"));
153
-
154
- const outcome = await runner.runTurn({
155
- ...baseRequest(stateRoot),
156
- isFirstTurn: false,
157
- sdkAgentId: "ses_retry",
158
- });
159
-
160
- expect(outcome.status).toBe("finished");
161
- expect(resumeAgent).toHaveBeenCalledTimes(2);
162
- expect(broken.close).toHaveBeenCalled();
163
- expect(lines.join("\n")).toContain("retrying the turn");
164
- });
165
-
166
- it("does not retry an auth failure once the turn has streamed output", async () => {
167
- process.env.CURSOR_API_KEY = "test-key";
168
- const broken = {
169
- agentId: "ses_retry",
170
- close: vi.fn(),
171
- send: vi.fn(
172
- async (
173
- _prompt: string,
174
- options: { onDelta: (event: { update: unknown }) => Promise<void> }
175
- ) => {
176
- await options.onDelta({ update: { kind: "assistant" } });
177
- return {
178
- wait: async () => ({
179
- status: "error" as const,
180
- error: { message: AUTH_ERROR_MESSAGE },
181
- }),
182
- };
183
- }
184
- ),
185
- };
186
- resumeAgent.mockResolvedValue(broken);
187
- const runner = new CursorSdkRunner();
188
- const stateRoot = await mkdtemp(join(tmpdir(), "agent-serve-sdk-runner-"));
189
-
190
- const outcome = await runner.runTurn({
191
- ...baseRequest(stateRoot),
192
- isFirstTurn: false,
193
- sdkAgentId: "ses_retry",
194
- });
195
-
196
- expect(outcome.status).toBe("error");
197
- expect(outcome.errorMessage).toBe(AUTH_ERROR_MESSAGE);
198
- expect(resumeAgent).toHaveBeenCalledTimes(1);
199
- expect(broken.send).toHaveBeenCalledTimes(1);
200
- });
201
-
202
- it("recycles a handle older than the age budget onto a fresh open", async () => {
203
- process.env.CURSOR_API_KEY = "test-key";
204
- vi.useFakeTimers({
205
- now: new Date("2026-07-28T00:00:00Z"),
206
- toFake: ["Date"],
207
- });
208
- try {
209
- const early = fakeAgent("ses_retry");
210
- const late = fakeAgent("ses_retry");
211
- resumeAgent.mockResolvedValueOnce(early).mockResolvedValueOnce(late);
212
- const runner = new CursorSdkRunner();
213
- const stateRoot = await mkdtemp(
214
- join(tmpdir(), "agent-serve-sdk-runner-")
215
- );
216
- const request = {
217
- ...baseRequest(stateRoot),
218
- isFirstTurn: false,
219
- sdkAgentId: "ses_retry",
220
- };
221
-
222
- await runner.runTurn(request);
223
- // Within the budget the handle is reused.
224
- vi.setSystemTime(new Date("2026-07-28T00:30:00Z"));
225
- await runner.runTurn(request);
226
- expect(resumeAgent).toHaveBeenCalledTimes(1);
227
- expect(early.send).toHaveBeenCalledTimes(2);
228
-
229
- // Past the budget (45 min) the handle is retired before the send, so
230
- // the exchanged access token (60 min lifetime) can never expire
231
- // mid-session.
232
- vi.setSystemTime(new Date("2026-07-28T00:46:00Z"));
233
- await runner.runTurn(request);
234
- expect(resumeAgent).toHaveBeenCalledTimes(2);
235
- expect(late.send).toHaveBeenCalledTimes(1);
236
- expect(early.close).toHaveBeenCalled();
237
- } finally {
238
- vi.useRealTimers();
239
- }
240
- });
241
- });
242
-
243
- const AUTH_ERROR_MESSAGE =
244
- "Authentication error If you are logged in, try logging out and back in.";
245
-
246
- function fakeAgent(agentId: string): {
247
- agentId: string;
248
- send: ReturnType<typeof vi.fn>;
249
- close: ReturnType<typeof vi.fn>;
250
- } {
251
- return {
252
- agentId,
253
- send: vi.fn(async () => ({
254
- wait: async () => ({ status: "finished", result: "ok" }),
255
- })),
256
- close: vi.fn(),
257
- };
258
- }
259
-
260
- function fakeErrorAgent(
261
- agentId: string,
262
- message: string
263
- ): {
264
- agentId: string;
265
- send: ReturnType<typeof vi.fn>;
266
- close: ReturnType<typeof vi.fn>;
267
- } {
268
- return {
269
- agentId,
270
- send: vi.fn(async () => ({
271
- wait: async () => ({ status: "error", error: { message } }),
272
- })),
273
- close: vi.fn(),
274
- };
275
- }
276
-
277
- function baseRequest(stateRoot: string): RunnerTurnRequest {
278
- return {
279
- sessionId: "ses_retry",
280
- workspaceDir: stateRoot,
281
- runnerStateDir: join(stateRoot, "runner"),
282
- prompt: "hello",
283
- isFirstTurn: true,
284
- runtime: "local",
285
- customTools: {},
286
- mcpServers: {},
287
- subagents: [],
288
- onUpdate: () => {},
289
- };
290
- }