@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,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
- });