@cursor/july 0.1.23 → 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 (174) hide show
  1. package/dist/bin/agent-serve.js +0 -0
  2. package/dist/docs/404.html +1 -1
  3. package/dist/docs/ab.html +2 -2
  4. package/dist/docs/assets/{app.DYcC9FY-.js → app.CvSGaAxk.js} +1 -1
  5. package/dist/docs/assets/chunks/@localSearchIndexroot.CL2Y0Zmh.js +1 -0
  6. package/dist/docs/assets/chunks/{VPLocalSearchBox.o4N_knTV.js → VPLocalSearchBox.J1jJbCvs.js} +1 -1
  7. package/dist/docs/assets/chunks/{theme.DQ-njyo0.js → theme.C7vfzr7h.js} +2 -2
  8. package/dist/docs/building-with-agents.html +2 -2
  9. package/dist/docs/concepts.html +2 -2
  10. package/dist/docs/deployment.html +2 -2
  11. package/dist/docs/evals.html +2 -2
  12. package/dist/docs/example-agents/approval-buddy.html +2 -2
  13. package/dist/docs/example-agents/benny.html +2 -2
  14. package/dist/docs/example-agents/bugbot.html +2 -2
  15. package/dist/docs/example-agents/codebase-wiki.html +2 -2
  16. package/dist/docs/example-agents/codeowners-review.html +2 -2
  17. package/dist/docs/example-agents/concierge.html +2 -2
  18. package/dist/docs/example-agents/fsd.html +2 -2
  19. package/dist/docs/example-agents/index.html +2 -2
  20. package/dist/docs/example-agents/knowledge-base.html +2 -2
  21. package/dist/docs/example-agents/oncall.html +2 -2
  22. package/dist/docs/example-agents/security-reviewer.html +2 -2
  23. package/dist/docs/example-agents/slack-agent.html +2 -2
  24. package/dist/docs/example-agents/weather-agent.html +2 -2
  25. package/dist/docs/guides/agent-to-agent.html +2 -2
  26. package/dist/docs/guides/cloud-runtime.html +2 -2
  27. package/dist/docs/guides/github.html +2 -2
  28. package/dist/docs/guides/human-in-the-loop.html +2 -2
  29. package/dist/docs/guides/mcp-oauth.html +2 -2
  30. package/dist/docs/guides/slack.html +2 -2
  31. package/dist/docs/guides/webhooks.html +2 -2
  32. package/dist/docs/hillclimbing.html +2 -2
  33. package/dist/docs/index.html +2 -2
  34. package/dist/docs/quickstart.html +2 -2
  35. package/dist/docs/reference/agent-config.html +2 -2
  36. package/dist/docs/reference/channels.html +2 -2
  37. package/dist/docs/reference/cli.html +2 -2
  38. package/dist/docs/reference/connections.html +2 -2
  39. package/dist/docs/reference/hooks.html +2 -2
  40. package/dist/docs/reference/http-api.html +2 -2
  41. package/dist/docs/reference/instructions.html +2 -2
  42. package/dist/docs/reference/playground.html +2 -2
  43. package/dist/docs/reference/project-layout.html +2 -2
  44. package/dist/docs/reference/prompt.html +2 -2
  45. package/dist/docs/reference/schedules.html +2 -2
  46. package/dist/docs/reference/sessions.html +2 -2
  47. package/dist/docs/reference/skills.html +2 -2
  48. package/dist/docs/reference/subagents.html +2 -2
  49. package/dist/docs/reference/tools.html +2 -2
  50. package/dist/docs/scaffolding-agents.html +2 -2
  51. package/dist/docs/storage.html +2 -2
  52. package/dist/docs/troubleshooting.html +2 -2
  53. package/dist/playground/assets/index-CidizGZv.css +1 -0
  54. package/dist/playground/assets/{index-DqXdAFGa.js → index-DTG9OsPV.js} +41 -41
  55. package/dist/playground/index.html +2 -2
  56. package/package.json +24 -24
  57. package/dist/channels/github/instrument.d.ts +0 -20
  58. package/dist/channels/github/instrument.d.ts.map +0 -1
  59. package/dist/docs/assets/chunks/@localSearchIndexroot.BQTzJjR_.js +0 -1
  60. package/dist/internal/json-dir-store.d.ts +0 -32
  61. package/dist/internal/json-dir-store.d.ts.map +0 -1
  62. package/dist/internal/json-dir-store.js +0 -100
  63. package/dist/playground/assets/index-CjOQ4hN9.css +0 -1
  64. package/src/bin/agent-serve.version.test.ts +0 -64
  65. package/src/channels/github/api.test.ts +0 -64
  66. package/src/channels/github/auth.test.ts +0 -105
  67. package/src/channels/github/cursor-account.test.ts +0 -204
  68. package/src/channels/github/forward.test.ts +0 -457
  69. package/src/channels/github/github.test.ts +0 -937
  70. package/src/channels/github/replay.test.ts +0 -179
  71. package/src/channels/slack/api.post-message.test.ts +0 -148
  72. package/src/channels/slack/approvals.test.ts +0 -328
  73. package/src/channels/slack/block-actions.test.ts +0 -452
  74. package/src/channels/slack/bot-mentions.test.ts +0 -267
  75. package/src/channels/slack/channel-watch.test.ts +0 -363
  76. package/src/channels/slack/cursor-account.test.ts +0 -253
  77. package/src/channels/slack/defaults.final-post.test.ts +0 -182
  78. package/src/channels/slack/dispatch.test.ts +0 -795
  79. package/src/channels/slack/eval-directive.test.ts +0 -273
  80. package/src/channels/slack/message-body.test.ts +0 -54
  81. package/src/channels/slack/nudge-store.test.ts +0 -143
  82. package/src/channels/slack/slack.test.ts +0 -391
  83. package/src/channels/slack/stop.test.ts +0 -23
  84. package/src/channels/slack/thread-context.test.ts +0 -202
  85. package/src/evals/assertions.test.ts +0 -580
  86. package/src/evals/expect.test.ts +0 -144
  87. package/src/evals/judge.test.ts +0 -181
  88. package/src/evals/loaders.test.ts +0 -132
  89. package/src/evals/matchers.test.ts +0 -95
  90. package/src/evals/reporters.test.ts +0 -303
  91. package/src/evals/run-facts.test.ts +0 -259
  92. package/src/internal/ab-snapshot.test.ts +0 -325
  93. package/src/internal/approval-gate.test.ts +0 -49
  94. package/src/internal/approvals.integration.test.ts +0 -383
  95. package/src/internal/authored-loaders.test.ts +0 -31
  96. package/src/internal/builtin-tools/reminders.test.ts +0 -201
  97. package/src/internal/channel-route-schema.test.ts +0 -294
  98. package/src/internal/chat-attach.test.ts +0 -262
  99. package/src/internal/cli-deploy.test.ts +0 -1991
  100. package/src/internal/cli-docs.test.ts +0 -161
  101. package/src/internal/cli-mcp.test.ts +0 -789
  102. package/src/internal/cli-skills.test.ts +0 -133
  103. package/src/internal/cli-slack.test.ts +0 -1647
  104. package/src/internal/cloud-merge.test.ts +0 -74
  105. package/src/internal/cron.test.ts +0 -22
  106. package/src/internal/cursor/account-mcp.test.ts +0 -807
  107. package/src/internal/cursor/backend-client.test.ts +0 -591
  108. package/src/internal/cursor/credentials.test.ts +0 -351
  109. package/src/internal/cursor/github-credentials.test.ts +0 -136
  110. package/src/internal/cursor-account-mcp-auth.test.ts +0 -310
  111. package/src/internal/cursor-account.integration.test.ts +0 -441
  112. package/src/internal/cursor-event-relay.test.ts +0 -746
  113. package/src/internal/cursor-github-credentials.integration.test.ts +0 -271
  114. package/src/internal/cursor-slack-relay.test.ts +0 -525
  115. package/src/internal/deploy-source.test.ts +0 -111
  116. package/src/internal/discovery.builtin-tools.test.ts +0 -94
  117. package/src/internal/discovery.concurrency.test.ts +0 -60
  118. package/src/internal/discovery.cursor-account.test.ts +0 -133
  119. package/src/internal/discovery.cwd.test.ts +0 -83
  120. package/src/internal/discovery.hosting.test.ts +0 -80
  121. package/src/internal/discovery.identity.test.ts +0 -44
  122. package/src/internal/docs-site.test.ts +0 -66
  123. package/src/internal/duration.test.ts +0 -29
  124. package/src/internal/eval-judge-model.test.ts +0 -187
  125. package/src/internal/eval-run-store.cancel.test.ts +0 -142
  126. package/src/internal/eval-run-store.storage.test.ts +0 -211
  127. package/src/internal/eval-runner.http.test.ts +0 -403
  128. package/src/internal/eval-runner.run.test.ts +0 -928
  129. package/src/internal/evals-client.test.ts +0 -307
  130. package/src/internal/event-mapper.test.ts +0 -243
  131. package/src/internal/github-fanout.test.ts +0 -213
  132. package/src/internal/handleAgentServeTrigger.test.ts +0 -179
  133. package/src/internal/host-kv.test.ts +0 -82
  134. package/src/internal/host-platforms.test.ts +0 -126
  135. package/src/internal/http-channel.test.ts +0 -402
  136. package/src/internal/init-project.test.ts +0 -270
  137. package/src/internal/install-cursor-skills.test.ts +0 -262
  138. package/src/internal/local-env.test.ts +0 -120
  139. package/src/internal/log-ring.test.ts +0 -31
  140. package/src/internal/logs-client.test.ts +0 -350
  141. package/src/internal/mcp-endpoint.test.ts +0 -436
  142. package/src/internal/mcp-host.test.ts +0 -298
  143. package/src/internal/mcp-oauth.test.ts +0 -148
  144. package/src/internal/net.test.ts +0 -17
  145. package/src/internal/peer-connections.test.ts +0 -128
  146. package/src/internal/peer-mcp.integration.test.ts +0 -289
  147. package/src/internal/playground/toolchain.test.ts +0 -53
  148. package/src/internal/playground-cli.test.ts +0 -187
  149. package/src/internal/playground-proxy.test.ts +0 -376
  150. package/src/internal/prompt-context.integration.test.ts +0 -232
  151. package/src/internal/prompt-context.test.ts +0 -127
  152. package/src/internal/reminder-runner.test.ts +0 -390
  153. package/src/internal/reminder-store.test.ts +0 -53
  154. package/src/internal/request-headers.test.ts +0 -27
  155. package/src/internal/resolve-prod-target.test.ts +0 -787
  156. package/src/internal/resolved-connections.test.ts +0 -295
  157. package/src/internal/router.test.ts +0 -57
  158. package/src/internal/sdk-runner.test.ts +0 -290
  159. package/src/internal/session-engine.coalesce.test.ts +0 -169
  160. package/src/internal/session-engine.concurrency.test.ts +0 -250
  161. package/src/internal/session-engine.host-oauth-mcp.test.ts +0 -110
  162. package/src/internal/session-engine.interrupt.test.ts +0 -577
  163. package/src/internal/session-engine.storage.test.ts +0 -547
  164. package/src/internal/session-urls.test.ts +0 -28
  165. package/src/internal/sessions-client.test.ts +0 -518
  166. package/src/internal/storage-coordinator.test.ts +0 -517
  167. package/src/internal/tool-call.test.ts +0 -458
  168. package/src/internal/tool-result.test.ts +0 -52
  169. package/src/internal/trajectory.approvals.test.ts +0 -83
  170. package/src/internal/trajectory.subagents.test.ts +0 -198
  171. package/src/internal/turn-governor.test.ts +0 -137
  172. package/src/internal/update-check.test.ts +0 -485
  173. package/src/internal/workspace.test.ts +0 -207
  174. package/src/storage-backends/cursor-hosted.test.ts +0 -121
@@ -1,376 +0,0 @@
1
- import { createServer, type Server } from "node:http";
2
- import { afterEach, describe, expect, it } from "vitest";
3
- import { startPlaygroundProxy } from "./playground-proxy.js";
4
-
5
- const servers: Server[] = [];
6
- const proxies: Array<{ close: () => Promise<void> }> = [];
7
-
8
- afterEach(async () => {
9
- while (proxies.length > 0) {
10
- const proxy = proxies.pop();
11
- await proxy?.close().catch(() => {});
12
- }
13
- await Promise.all(
14
- servers.splice(0).map(
15
- (server) =>
16
- new Promise<void>((resolve) => {
17
- server.close(() => resolve());
18
- })
19
- )
20
- );
21
- });
22
-
23
- function listen(
24
- handler: (
25
- req: import("node:http").IncomingMessage,
26
- res: import("node:http").ServerResponse
27
- ) => void
28
- ): Promise<{ url: string; server: Server }> {
29
- const server = createServer(handler);
30
- servers.push(server);
31
- return new Promise((resolve, reject) => {
32
- server.listen(0, "127.0.0.1", () => {
33
- const address = server.address();
34
- if (address === null || typeof address === "string") {
35
- reject(new Error("expected AddressInfo"));
36
- return;
37
- }
38
- resolve({ url: `http://127.0.0.1:${address.port}`, server });
39
- });
40
- });
41
- }
42
-
43
- function cookieHeader(accessToken: string): Record<string, string> {
44
- return { cookie: `agentkit_playground_proxy=${accessToken}` };
45
- }
46
-
47
- describe("startPlaygroundProxy", () => {
48
- it("injects headers and forwards path + query", async () => {
49
- let seenAuth: string | undefined;
50
- let seenWake: string | undefined;
51
- let seenPath: string | undefined;
52
- const upstream = await listen((req, res) => {
53
- seenAuth = req.headers.authorization;
54
- seenWake = req.headers["x-anyrun-hibernation-lower-bound-s"] as
55
- | string
56
- | undefined;
57
- seenPath = req.url;
58
- if (req.url?.startsWith("/playground")) {
59
- res.writeHead(200, { "content-type": "text/html" });
60
- res.end("<html>ok</html>");
61
- return;
62
- }
63
- if (req.url?.startsWith("/v1/health")) {
64
- res.writeHead(200, { "content-type": "application/json" });
65
- res.end(JSON.stringify({ ok: true }));
66
- return;
67
- }
68
- res.writeHead(404);
69
- res.end();
70
- });
71
-
72
- const proxy = await startPlaygroundProxy({
73
- upstreamUrl: upstream.url,
74
- headers: {
75
- authorization: "Bearer engine-token",
76
- "x-anyrun-hibernation-lower-bound-s": "1800",
77
- },
78
- });
79
- proxies.push(proxy);
80
-
81
- const playground = await fetch(
82
- `${proxy.localUrl}/playground?sessionId=ses_1`,
83
- { headers: cookieHeader(proxy.accessToken) }
84
- );
85
- expect(playground.status).toBe(200);
86
- expect(await playground.text()).toBe("<html>ok</html>");
87
- expect(seenPath).toBe("/playground?sessionId=ses_1");
88
- expect(seenAuth).toBe("Bearer engine-token");
89
- expect(seenWake).toBe("1800");
90
-
91
- const health = await fetch(`${proxy.localUrl}/v1/health`, {
92
- headers: cookieHeader(proxy.accessToken),
93
- });
94
- expect(health.status).toBe(200);
95
- expect(await health.json()).toEqual({ ok: true });
96
- });
97
-
98
- it("bootstraps access via query token then cookie", async () => {
99
- const upstream = await listen((_req, res) => {
100
- res.writeHead(200);
101
- res.end("ok");
102
- });
103
- const proxy = await startPlaygroundProxy({
104
- upstreamUrl: upstream.url,
105
- accessToken: "test-token",
106
- });
107
- proxies.push(proxy);
108
-
109
- const denied = await fetch(`${proxy.localUrl}/v1/health`);
110
- expect(denied.status).toBe(401);
111
-
112
- const bootstrap = await fetch(proxy.playgroundUrl(), {
113
- redirect: "manual",
114
- });
115
- expect(bootstrap.status).toBe(302);
116
- expect(bootstrap.headers.get("location")).toBe("/playground");
117
- expect(bootstrap.headers.get("set-cookie")).toContain(
118
- "agentkit_playground_proxy=test-token"
119
- );
120
-
121
- const allowed = await fetch(`${proxy.localUrl}/v1/health`, {
122
- headers: cookieHeader("test-token"),
123
- });
124
- expect(allowed.status).toBe(200);
125
- });
126
-
127
- it("streams NDJSON responses without buffering the whole body", async () => {
128
- const upstream = await listen((req, res) => {
129
- if (req.url !== "/v1/session/ses_x/stream?startIndex=0") {
130
- res.writeHead(404);
131
- res.end();
132
- return;
133
- }
134
- res.writeHead(200, {
135
- "content-type": "application/x-ndjson",
136
- "cache-control": "no-cache",
137
- });
138
- res.write('{"type":"a"}\n');
139
- setTimeout(() => {
140
- res.write('{"type":"b"}\n');
141
- res.end();
142
- }, 20);
143
- });
144
-
145
- const proxy = await startPlaygroundProxy({
146
- upstreamUrl: upstream.url,
147
- headers: { "x-test": "1" },
148
- });
149
- proxies.push(proxy);
150
-
151
- const resp = await fetch(
152
- `${proxy.localUrl}/v1/session/ses_x/stream?startIndex=0`,
153
- { headers: cookieHeader(proxy.accessToken) }
154
- );
155
- expect(resp.status).toBe(200);
156
- const text = await resp.text();
157
- expect(text).toBe('{"type":"a"}\n{"type":"b"}\n');
158
- });
159
-
160
- it("prefers bearerToken over client Authorization", async () => {
161
- let seenAuth: string | undefined;
162
- const upstream = await listen((req, res) => {
163
- seenAuth = req.headers.authorization;
164
- res.writeHead(200);
165
- res.end("ok");
166
- });
167
-
168
- const proxy = await startPlaygroundProxy({
169
- upstreamUrl: upstream.url,
170
- bearerToken: "from-cli",
171
- });
172
- proxies.push(proxy);
173
-
174
- await fetch(`${proxy.localUrl}/v1/info`, {
175
- headers: {
176
- ...cookieHeader(proxy.accessToken),
177
- authorization: "Bearer from-browser",
178
- },
179
- });
180
- expect(seenAuth).toBe("Bearer from-cli");
181
- });
182
-
183
- it("prefixes upstream pathname mounts", async () => {
184
- let seenPath: string | undefined;
185
- const upstream = await listen((req, res) => {
186
- seenPath = req.url;
187
- res.writeHead(200);
188
- res.end("ok");
189
- });
190
-
191
- const proxy = await startPlaygroundProxy({
192
- upstreamUrl: `${upstream.url}/my-agent`,
193
- });
194
- proxies.push(proxy);
195
-
196
- await fetch(`${proxy.localUrl}/playground`, {
197
- headers: cookieHeader(proxy.accessToken),
198
- });
199
- expect(seenPath).toBe("/my-agent/playground");
200
- });
201
-
202
- it("does not treat a short mount prefix as a path match", async () => {
203
- let seenPath: string | undefined;
204
- const upstream = await listen((req, res) => {
205
- seenPath = req.url;
206
- res.writeHead(200);
207
- res.end("ok");
208
- });
209
-
210
- const proxy = await startPlaygroundProxy({
211
- upstreamUrl: `${upstream.url}/v`,
212
- });
213
- proxies.push(proxy);
214
-
215
- await fetch(`${proxy.localUrl}/v1/health`, {
216
- headers: cookieHeader(proxy.accessToken),
217
- });
218
- expect(seenPath).toBe("/v/v1/health");
219
- });
220
-
221
- it("rejects mutating requests from another 127.0.0.1 origin", async () => {
222
- let hits = 0;
223
- const upstream = await listen((_req, res) => {
224
- hits += 1;
225
- res.writeHead(200);
226
- res.end("ok");
227
- });
228
-
229
- const proxy = await startPlaygroundProxy({
230
- upstreamUrl: upstream.url,
231
- headers: { authorization: "Bearer secret" },
232
- });
233
- proxies.push(proxy);
234
-
235
- const csrf = await fetch(`${proxy.localUrl}/v1/session`, {
236
- method: "POST",
237
- headers: {
238
- ...cookieHeader(proxy.accessToken),
239
- origin: "http://127.0.0.1:9",
240
- "content-type": "text/plain",
241
- },
242
- body: '{"message":"pwn"}',
243
- });
244
- expect(csrf.status).toBe(403);
245
- expect(hits).toBe(0);
246
-
247
- const ok = await fetch(`${proxy.localUrl}/v1/session`, {
248
- method: "POST",
249
- headers: {
250
- ...cookieHeader(proxy.accessToken),
251
- origin: proxy.localUrl,
252
- "content-type": "application/json",
253
- },
254
- body: '{"message":"hi"}',
255
- });
256
- expect(ok.status).toBe(200);
257
- expect(hits).toBe(1);
258
- });
259
-
260
- it("rejects absolute-form targets without forwarding credentials", async () => {
261
- let hits = 0;
262
- const upstream = await listen((_req, res) => {
263
- hits += 1;
264
- res.writeHead(200);
265
- res.end("ok");
266
- });
267
-
268
- const proxy = await startPlaygroundProxy({
269
- upstreamUrl: upstream.url,
270
- headers: { authorization: "Bearer secret" },
271
- });
272
- proxies.push(proxy);
273
-
274
- const { request } = await import("node:http");
275
- const status = await new Promise<number>((resolve, reject) => {
276
- const req = request(
277
- {
278
- hostname: "127.0.0.1",
279
- port: proxy.port,
280
- path: "http://127.0.0.1:9/exfil",
281
- method: "GET",
282
- headers: cookieHeader(proxy.accessToken),
283
- },
284
- (res) => {
285
- res.resume();
286
- res.on("end", () => resolve(res.statusCode ?? 0));
287
- }
288
- );
289
- req.on("error", reject);
290
- req.end();
291
- });
292
-
293
- expect(status).toBe(400);
294
- expect(hits).toBe(0);
295
- });
296
-
297
- it("refreshes credentials on upstream 401 and retries once", async () => {
298
- const seen: string[] = [];
299
- const upstream = await listen((req, res) => {
300
- const token = String(req.headers["x-port-token"] ?? "");
301
- seen.push(token);
302
- if (token !== "fresh") {
303
- res.writeHead(401);
304
- res.end("expired");
305
- return;
306
- }
307
- res.writeHead(200);
308
- res.end("ok");
309
- });
310
-
311
- let refreshCount = 0;
312
- const proxy = await startPlaygroundProxy({
313
- upstreamUrl: upstream.url,
314
- headers: { "x-port-token": "stale" },
315
- refreshUpstream: async () => {
316
- refreshCount += 1;
317
- return {
318
- upstreamUrl: upstream.url,
319
- headers: { "x-port-token": "fresh" },
320
- expiresAt: "2099-01-01T00:00:00.000Z",
321
- };
322
- },
323
- });
324
- proxies.push(proxy);
325
-
326
- const resp = await fetch(`${proxy.localUrl}/v1/health`, {
327
- headers: cookieHeader(proxy.accessToken),
328
- });
329
- expect(resp.status).toBe(200);
330
- expect(await resp.text()).toBe("ok");
331
- expect(seen).toEqual(["stale", "fresh"]);
332
- expect(refreshCount).toBe(1);
333
- });
334
-
335
- it("proactively refreshes near expiresAt", async () => {
336
- let seenToken: string | undefined;
337
- const upstream = await listen((req, res) => {
338
- seenToken = req.headers["x-port-token"] as string | undefined;
339
- res.writeHead(200);
340
- res.end("ok");
341
- });
342
-
343
- let nowMs = Date.parse("2026-01-01T00:00:00.000Z");
344
- let refreshCount = 0;
345
- const proxy = await startPlaygroundProxy({
346
- upstreamUrl: upstream.url,
347
- headers: { "x-port-token": "old" },
348
- // Within the 5-minute leeway of "now".
349
- expiresAt: "2026-01-01T00:04:00.000Z",
350
- now: () => nowMs,
351
- refreshUpstream: async () => {
352
- refreshCount += 1;
353
- return {
354
- upstreamUrl: upstream.url,
355
- headers: { "x-port-token": "new" },
356
- expiresAt: "2099-01-01T00:00:00.000Z",
357
- };
358
- },
359
- });
360
- proxies.push(proxy);
361
-
362
- const resp = await fetch(`${proxy.localUrl}/v1/health`, {
363
- headers: cookieHeader(proxy.accessToken),
364
- });
365
- expect(resp.status).toBe(200);
366
- expect(seenToken).toBe("new");
367
- expect(refreshCount).toBe(1);
368
-
369
- // Still valid — no second refresh.
370
- nowMs = Date.parse("2026-01-01T00:01:00.000Z");
371
- await fetch(`${proxy.localUrl}/v1/health`, {
372
- headers: cookieHeader(proxy.accessToken),
373
- });
374
- expect(refreshCount).toBe(1);
375
- });
376
- });
@@ -1,232 +0,0 @@
1
- import { mkdir, mkdtemp, readFile, rm } from "node:fs/promises";
2
- import { tmpdir } from "node:os";
3
- import { join } from "node:path";
4
- import { afterEach, describe, expect, it } from "vitest";
5
- import { httpChannel } from "../channels.js";
6
- import { defineTool } from "../tools.js";
7
- import type {
8
- AgentProject,
9
- AgentRuntime,
10
- DiscoveredTool,
11
- RunnerTurnRequest,
12
- TurnOutcome,
13
- } from "../types.js";
14
- import { setDevMode } from "./dev-mode.js";
15
- import { toolInputJsonSchema } from "./json-schema.js";
16
- import type { AgentRunner } from "./sdk-runner.js";
17
- import { SessionEngine } from "./session-engine.js";
18
-
19
- function testProject(
20
- rootDir: string,
21
- options: {
22
- runtime?: AgentRuntime;
23
- localCwd?: string;
24
- tools?: DiscoveredTool[];
25
- } = {}
26
- ): AgentProject {
27
- return {
28
- rootDir,
29
- agentDir: join(rootDir, "agent"),
30
- name: "prompt-context-test",
31
- agent: {
32
- name: "prompt-context-test",
33
- description: "Exercises framework prompt context.",
34
- runtime: options.runtime ?? "local",
35
- instructions: "Answer briefly.",
36
- local: { cwd: options.localCwd },
37
- tools: options.tools ?? [],
38
- skills: [],
39
- connections: [],
40
- subagents: [],
41
- seedFiles: [],
42
- },
43
- httpChannel: httpChannel(),
44
- channels: [],
45
- schedules: [],
46
- hooks: [],
47
- abs: [],
48
- diagnostics: [],
49
- };
50
- }
51
-
52
- function recordingRunner(requests: RunnerTurnRequest[]): AgentRunner {
53
- return {
54
- runTurn: async (request): Promise<TurnOutcome> => {
55
- requests.push(request);
56
- return { status: "finished", result: "ok" };
57
- },
58
- };
59
- }
60
-
61
- const cleanups: Array<() => Promise<void>> = [];
62
-
63
- afterEach(async () => {
64
- setDevMode(false);
65
- while (cleanups.length > 0) {
66
- await cleanups.pop()?.();
67
- }
68
- });
69
-
70
- async function makeEngine(options: {
71
- runtime?: AgentRuntime;
72
- localCwd?: string;
73
- tools?: DiscoveredTool[];
74
- }): Promise<{ engine: SessionEngine; requests: RunnerTurnRequest[] }> {
75
- const stateRoot = await mkdtemp(join(tmpdir(), "agent-serve-promptctx-"));
76
- cleanups.push(() => rm(stateRoot, { recursive: true, force: true }));
77
- const requests: RunnerTurnRequest[] = [];
78
- const engine = new SessionEngine({
79
- project: testProject(stateRoot, options),
80
- stateRoot,
81
- runner: recordingRunner(requests),
82
- });
83
- cleanups.push(() => engine.close());
84
- return { engine, requests };
85
- }
86
-
87
- describe("framework prompt context (local runtime)", () => {
88
- it("writes the identity section into AGENTS.md after the instructions", async () => {
89
- const { engine } = await makeEngine({});
90
- const session = await engine.send("http", "hello", { auth: null });
91
- await session.waitForCompletion();
92
-
93
- const agentsMd = await readFile(
94
- join(engine.sessions.workspaceDir(session.id), "AGENTS.md"),
95
- "utf8"
96
- );
97
- expect(agentsMd.startsWith("Answer briefly.")).toBe(true);
98
- expect(agentsMd).toContain("## About you");
99
- expect(agentsMd).toContain(
100
- 'You are "prompt-context-test" — Exercises framework prompt context.'
101
- );
102
- });
103
-
104
- it("prepends the context block to the first turn only", async () => {
105
- setDevMode(true);
106
- const { engine, requests } = await makeEngine({});
107
- const session = await engine.send("http", "hello", { auth: null });
108
- await session.waitForCompletion();
109
- const follow = await engine.send("http", "again", {
110
- auth: null,
111
- continuationToken: session.continuationToken ?? undefined,
112
- });
113
- await follow.waitForCompletion();
114
-
115
- const first = requests[0]?.prompt ?? "";
116
- expect(first.startsWith("<agentkit_context>\n")).toBe(true);
117
- expect(first).toContain(`session: ${session.id}`);
118
- expect(first).toContain("channel: http");
119
- expect(first).toContain("environment: local dev server");
120
- expect(first.endsWith("\n\nhello")).toBe(true);
121
- expect(requests[1]?.prompt).toBe("again");
122
- });
123
-
124
- it("reports hosted deployment outside dev mode", async () => {
125
- const { engine, requests } = await makeEngine({});
126
- const session = await engine.send("http", "hello", { auth: null });
127
- await session.waitForCompletion();
128
- expect(requests[0]?.prompt).toContain("environment: hosted deployment");
129
- });
130
-
131
- it("inlines instructions on the first turn when the workspace is nested inside a git repo", async () => {
132
- // The harness roots project rules at the nearest enclosing git root, so
133
- // the scaffolded AGENTS.md in a nested (gitignored) session workspace
134
- // never loads — instructions must ride in the first prompt instead.
135
- const repoDir = await mkdtemp(join(tmpdir(), "agent-serve-nested-repo-"));
136
- cleanups.push(() => rm(repoDir, { recursive: true, force: true }));
137
- await mkdir(join(repoDir, ".git"), { recursive: true });
138
- const harnessParent = join(repoDir, ".state", "harness");
139
-
140
- const { engine, requests } = await makeEngine({ localCwd: harnessParent });
141
- const session = await engine.send("http", "hello", { auth: null });
142
- await session.waitForCompletion();
143
- const follow = await engine.send("http", "again", {
144
- auth: null,
145
- continuationToken: session.continuationToken ?? undefined,
146
- });
147
- await follow.waitForCompletion();
148
-
149
- const first = requests[0]?.prompt ?? "";
150
- expect(first.startsWith("Answer briefly.")).toBe(true);
151
- expect(first).toContain("## About you");
152
- const blockIndex = first.indexOf("<agentkit_context>");
153
- expect(blockIndex).toBeGreaterThan(first.indexOf("## About you"));
154
- expect(first.endsWith("\n\nhello")).toBe(true);
155
- expect(requests[1]?.prompt).toBe("again");
156
- });
157
-
158
- it("inlines instructions when the harness cwd is a per-session override", async () => {
159
- // With a workspace override (e.g. a PR worktree) the scaffold lands in
160
- // the durable session workspace, which the harness never roots at.
161
- const overrideDir = await mkdtemp(join(tmpdir(), "agent-serve-override-"));
162
- cleanups.push(() => rm(overrideDir, { recursive: true, force: true }));
163
-
164
- const { engine, requests } = await makeEngine({});
165
- const session = await engine.send("http", "hello", {
166
- auth: null,
167
- workspaceDir: overrideDir,
168
- });
169
- await session.waitForCompletion();
170
-
171
- const first = requests[0]?.prompt ?? "";
172
- expect(first.startsWith("Answer briefly.")).toBe(true);
173
- expect(first).toContain("## About you");
174
- expect(first).toContain("<agentkit_context>");
175
- });
176
-
177
- it("embeds agent tool scripts when inlining with a workspace override", async () => {
178
- const overrideDir = await mkdtemp(
179
- join(tmpdir(), "agent-serve-override-tools-")
180
- );
181
- cleanups.push(() => rm(overrideDir, { recursive: true, force: true }));
182
- const pipeTool = defineTool({
183
- description: "Pipe stdin to stdout.",
184
- execution: "agent",
185
- script: "#!/usr/bin/env bash\ncat\n",
186
- });
187
- const agentTool: DiscoveredTool = {
188
- name: "pipe",
189
- description: pipeTool.description,
190
- inputSchema: toolInputJsonSchema(pipeTool.inputSchema),
191
- execution: "agent",
192
- script: pipeTool.script,
193
- needsApproval: false,
194
- definition: pipeTool,
195
- };
196
-
197
- const { engine, requests } = await makeEngine({ tools: [agentTool] });
198
- const session = await engine.send("http", "hello", {
199
- auth: null,
200
- workspaceDir: overrideDir,
201
- });
202
- await session.waitForCompletion();
203
-
204
- const first = requests[0]?.prompt ?? "";
205
- expect(first).toContain(
206
- "Script body (write to the path above if missing):"
207
- );
208
- expect(first).toContain("#!/usr/bin/env bash");
209
- });
210
- });
211
-
212
- describe("framework prompt context (cloud runtime)", () => {
213
- it("prepends instructions, identity, and context block on the first turn only", async () => {
214
- const { engine, requests } = await makeEngine({ runtime: "cloud" });
215
- const session = await engine.send("http", "hello", { auth: null });
216
- await session.waitForCompletion();
217
- const follow = await engine.send("http", "again", {
218
- auth: null,
219
- continuationToken: session.continuationToken ?? undefined,
220
- });
221
- await follow.waitForCompletion();
222
-
223
- const first = requests[0]?.prompt ?? "";
224
- expect(first.startsWith("Answer briefly.")).toBe(true);
225
- expect(first).toContain("## About you");
226
- const blockIndex = first.indexOf("<agentkit_context>");
227
- expect(blockIndex).toBeGreaterThan(first.indexOf("## About you"));
228
- expect(first).toContain(`session: ${session.id}`);
229
- expect(first.endsWith("\n\nhello")).toBe(true);
230
- expect(requests[1]?.prompt).toBe("again");
231
- });
232
- });