@cursor/july 0.1.22 → 0.1.24

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