@cursor/july 0.1.26 → 0.1.27

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