@cursor/july 0.1.26 → 0.1.28

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