@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,334 +0,0 @@
1
- import { mkdtemp, 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 { z } from "zod";
6
- import { defineArtifacts } from "../artifacts.js";
7
- import { defineChannel, httpChannel } from "../channels.js";
8
- import { defineTool } from "../tools.js";
9
- import type {
10
- AgentProject,
11
- ArtifactRecord,
12
- AuthContext,
13
- DiscoveredChannel,
14
- DiscoveredTool,
15
- ServeOptions,
16
- } from "../types.js";
17
- import { toolInputJsonSchema } from "./json-schema.js";
18
- import type { AgentRunner } from "./sdk-runner.js";
19
- import { type AgentMount, startServer } from "./server.js";
20
- import { SessionEngine } from "./session-engine.js";
21
-
22
- const seedTool = defineTool({
23
- description: "Tags one artifact (test seed).",
24
- inputSchema: z.object({
25
- kind: z.string(),
26
- key: z.string().optional(),
27
- note: z.string().optional(),
28
- }),
29
- execute: async ({ kind, key, note }, ctx) => {
30
- const record = await ctx.artifacts.tag({
31
- kind,
32
- key,
33
- data: { note: note ?? null },
34
- });
35
- return { id: record.id };
36
- },
37
- });
38
-
39
- function testProject(
40
- rootDir: string,
41
- options?: { channels?: DiscoveredChannel[] }
42
- ): AgentProject {
43
- const discovered: DiscoveredTool = {
44
- name: "seed",
45
- description: seedTool.description,
46
- inputSchema: toolInputJsonSchema(seedTool.inputSchema),
47
- execution: "server",
48
- needsApproval: false,
49
- definition: seedTool,
50
- };
51
- return {
52
- rootDir,
53
- agentDir: join(rootDir, "agent"),
54
- name: "artifacts-route-test",
55
- agent: {
56
- name: "artifacts-route-test",
57
- runtime: "local",
58
- instructions: "Test agent.",
59
- tools: [discovered],
60
- skills: [],
61
- connections: [],
62
- subagents: [],
63
- seedFiles: [],
64
- },
65
- httpChannel: httpChannel(),
66
- channels: options?.channels ?? [],
67
- schedules: [],
68
- hooks: [],
69
- abs: [],
70
- artifacts: defineArtifacts({
71
- kinds: {
72
- "reviewed-pr": { description: "A reviewed PR." },
73
- report: { description: "A report." },
74
- },
75
- }),
76
- diagnostics: [],
77
- };
78
- }
79
-
80
- const noTurnRunner: AgentRunner = {
81
- runTurn: () => {
82
- throw new Error("runTurn must not be called");
83
- },
84
- };
85
-
86
- const cleanups: Array<() => Promise<void>> = [];
87
-
88
- afterEach(async () => {
89
- while (cleanups.length > 0) {
90
- await cleanups.pop()?.();
91
- }
92
- });
93
-
94
- async function startTestServer(
95
- options?: Partial<ServeOptions>,
96
- projectOptions?: { channels?: DiscoveredChannel[] }
97
- ) {
98
- const stateRoot = await mkdtemp(join(tmpdir(), "agent-serve-artroute-"));
99
- cleanups.push(() => rm(stateRoot, { recursive: true, force: true }));
100
- const mounts: AgentMount[] = [
101
- { slug: "", project: testProject(stateRoot, projectOptions) },
102
- ];
103
- const handle = await startServer(mounts, {
104
- port: 0,
105
- stateRoot,
106
- playground: false,
107
- schedules: false,
108
- logger: () => {},
109
- runner: noTurnRunner,
110
- ...options,
111
- });
112
- cleanups.push(() => handle.close());
113
- return handle;
114
- }
115
-
116
- async function listArtifacts(
117
- url: string,
118
- query = "",
119
- headers: Record<string, string> = {}
120
- ): Promise<{ status: number; artifacts: ArtifactRecord[] }> {
121
- const response = await fetch(`${url}/v1/artifacts${query}`, { headers });
122
- if (response.status !== 200) {
123
- return { status: response.status, artifacts: [] };
124
- }
125
- const body = (await response.json()) as { artifacts: ArtifactRecord[] };
126
- return { status: response.status, artifacts: body.artifacts };
127
- }
128
-
129
- /** Force distinct `updatedAt` millis so newest-first ordering is stable. */
130
- function tick(): Promise<void> {
131
- return new Promise((resolve) => setTimeout(resolve, 5));
132
- }
133
-
134
- describe("GET /v1/artifacts", () => {
135
- it("lists newest-updated first with kind filtering (dev includeAll)", async () => {
136
- const handle = await startTestServer({ dev: true });
137
- await handle.callTool("seed", { kind: "reviewed-pr", key: "pr-1" });
138
- await tick();
139
- await handle.callTool("seed", { kind: "report", key: "r-1" });
140
- await tick();
141
- await handle.callTool("seed", { kind: "reviewed-pr", key: "pr-2" });
142
-
143
- const all = await listArtifacts(handle.url);
144
- expect(all.status).toBe(200);
145
- expect(all.artifacts.map((a) => a.key)).toEqual(["pr-2", "r-1", "pr-1"]);
146
-
147
- const reports = await listArtifacts(handle.url, "?kind=report");
148
- expect(reports.artifacts.map((a) => a.key)).toEqual(["r-1"]);
149
-
150
- const none = await listArtifacts(handle.url, "?kind=missing");
151
- expect(none.artifacts).toEqual([]);
152
- });
153
-
154
- it("filters by sessionId", async () => {
155
- // Scratch (session-less) seeds never match a sessionId filter.
156
- const handle = await startTestServer({ dev: true });
157
- await handle.callTool("seed", { kind: "report", key: "loose" });
158
- const filtered = await listArtifacts(handle.url, "?sessionId=ses_other");
159
- expect(filtered.status).toBe(200);
160
- expect(filtered.artifacts).toEqual([]);
161
- expect((await listArtifacts(handle.url)).artifacts).toHaveLength(1);
162
- });
163
-
164
- it("bounds the limit and rejects non-positive limits", async () => {
165
- const handle = await startTestServer({ dev: true });
166
- for (const key of ["a", "b", "c"]) {
167
- await handle.callTool("seed", { kind: "report", key });
168
- await tick();
169
- }
170
- const limited = await listArtifacts(handle.url, "?limit=2");
171
- expect(limited.artifacts).toHaveLength(2);
172
- expect(limited.artifacts.map((a) => a.key)).toEqual(["c", "b"]);
173
-
174
- // Above the ceiling clamps rather than erroring.
175
- const clamped = await listArtifacts(handle.url, "?limit=99999");
176
- expect(clamped.status).toBe(200);
177
- expect(clamped.artifacts).toHaveLength(3);
178
-
179
- expect((await listArtifacts(handle.url, "?limit=0")).status).toBe(400);
180
- expect((await listArtifacts(handle.url, "?limit=nope")).status).toBe(400);
181
- });
182
-
183
- it("hides session-less artifacts from non-includeAll callers", async () => {
184
- // No --dev: loopback callers get the strict per-principal view, and
185
- // session-less (agent-scoped) artifacts have no owning principal.
186
- const handle = await startTestServer();
187
- await handle.callTool("seed", { kind: "report", key: "agent-scoped" });
188
- const listed = await listArtifacts(handle.url);
189
- expect(listed.status).toBe(200);
190
- expect(listed.artifacts).toEqual([]);
191
- });
192
-
193
- it("channel onStart gets the unbound artifacts facade", async () => {
194
- const channel: DiscoveredChannel = {
195
- id: "starter",
196
- definition: defineChannel({
197
- async onStart({ artifacts }) {
198
- await artifacts.tag({
199
- kind: "report",
200
- key: "from-onstart",
201
- data: 1,
202
- });
203
- },
204
- }),
205
- };
206
- const handle = await startTestServer(
207
- { dev: true },
208
- { channels: [channel] }
209
- );
210
- const listed = await listArtifacts(handle.url);
211
- expect(listed.artifacts.map((a) => a.key)).toEqual(["from-onstart"]);
212
- expect(listed.artifacts[0]?.sessionId).toBeUndefined();
213
- });
214
-
215
- it("requires the bearer token when one is configured", async () => {
216
- const handle = await startTestServer({ authToken: "sekrit" });
217
- const denied = await fetch(`${handle.url}/v1/artifacts`);
218
- expect(denied.status).toBe(401);
219
- const allowed = await fetch(`${handle.url}/v1/artifacts`, {
220
- headers: { authorization: "Bearer sekrit" },
221
- });
222
- expect(allowed.status).toBe(200);
223
- });
224
-
225
- it("never widens to includeAll when a bearer token is configured", async () => {
226
- // Bearer auth vetoes relaxSessionReadAuth even under --dev on loopback,
227
- // matching GET /v1/sessions.
228
- const handle = await startTestServer({ dev: true, authToken: "sekrit" });
229
- await handle.callTool("seed", { kind: "report", key: "agent-scoped" });
230
- const listed = await listArtifacts(handle.url, "", {
231
- authorization: "Bearer sekrit",
232
- });
233
- expect(listed.status).toBe(200);
234
- expect(listed.artifacts).toEqual([]);
235
- });
236
- });
237
-
238
- describe("SessionEngine.listArtifacts ownership", () => {
239
- const alice: AuthContext = {
240
- authenticator: "test",
241
- principalId: "alice",
242
- principalType: "user",
243
- };
244
- const bob: AuthContext = {
245
- authenticator: "test",
246
- principalId: "bob",
247
- principalType: "user",
248
- };
249
-
250
- async function makeEngine(): Promise<SessionEngine> {
251
- const stateRoot = await mkdtemp(join(tmpdir(), "agent-serve-artown-"));
252
- cleanups.push(() => rm(stateRoot, { recursive: true, force: true }));
253
- const engine = new SessionEngine({
254
- project: testProject(stateRoot),
255
- stateRoot,
256
- runner: noTurnRunner,
257
- });
258
- cleanups.push(() => engine.close());
259
- return engine;
260
- }
261
-
262
- async function seedSession(
263
- engine: SessionEngine,
264
- sessionId: string,
265
- auth: AuthContext | null
266
- ): Promise<void> {
267
- await engine.sessions.save({
268
- sessionId,
269
- channelId: "http",
270
- mode: "chat",
271
- continuationKey: null,
272
- auth,
273
- turnCount: 0,
274
- createdAt: new Date().toISOString(),
275
- updatedAt: new Date().toISOString(),
276
- });
277
- }
278
-
279
- it("scopes non-includeAll listings to the caller's sessions", async () => {
280
- const engine = await makeEngine();
281
- await seedSession(engine, "ses_alice", alice);
282
- await seedSession(engine, "ses_bob", bob);
283
- await engine.artifacts.tag({
284
- kind: "report",
285
- key: "alice-report",
286
- data: 1,
287
- sessionId: "ses_alice",
288
- });
289
- await engine.artifacts.tag({
290
- kind: "report",
291
- key: "bob-report",
292
- data: 1,
293
- sessionId: "ses_bob",
294
- });
295
- await engine.artifacts.tag({ kind: "report", key: "loose", data: 1 });
296
-
297
- const forAlice = await engine.listArtifacts(alice);
298
- expect(forAlice.map((a) => a.key)).toEqual(["alice-report"]);
299
-
300
- const forBob = await engine.listArtifacts(bob);
301
- expect(forBob.map((a) => a.key)).toEqual(["bob-report"]);
302
-
303
- const anonymous = await engine.listArtifacts(null);
304
- expect(anonymous).toEqual([]);
305
-
306
- const everything = await engine.listArtifacts(null, { includeAll: true });
307
- expect(everything.map((a) => a.key).sort()).toEqual([
308
- "alice-report",
309
- "bob-report",
310
- "loose",
311
- ]);
312
- });
313
-
314
- it("applies the filter before ownership scoping", async () => {
315
- const engine = await makeEngine();
316
- await seedSession(engine, "ses_alice", alice);
317
- await engine.artifacts.tag({
318
- kind: "reviewed-pr",
319
- key: "pr",
320
- data: 1,
321
- sessionId: "ses_alice",
322
- });
323
- await engine.artifacts.tag({
324
- kind: "report",
325
- key: "rep",
326
- data: 1,
327
- sessionId: "ses_alice",
328
- });
329
- const filtered = await engine.listArtifacts(alice, {
330
- filter: { kind: "reviewed-pr" },
331
- });
332
- expect(filtered.map((a) => a.key)).toEqual(["pr"]);
333
- });
334
- });
@@ -1,293 +0,0 @@
1
- import { mkdtemp, rm } from "node:fs/promises";
2
- import { tmpdir } from "node:os";
3
- import { join } from "node:path";
4
- import { afterEach, describe, expect, it, vi } from "vitest";
5
- import { defineArtifacts } from "../artifacts.js";
6
- import { defineChannel, httpChannel } from "../channels.js";
7
- import { defineHook } from "../hooks.js";
8
- import { defineSchedule } from "../schedules.js";
9
- import { defineTool } from "../tools.js";
10
- import type {
11
- AgentProject,
12
- ArtifactsDefinition,
13
- DiscoveredChannel,
14
- DiscoveredHook,
15
- DiscoveredSchedule,
16
- DiscoveredTool,
17
- JsonObject,
18
- ToolContext,
19
- } from "../types.js";
20
- import { ScheduleRunner } from "./schedule-runner.js";
21
- import type { AgentRunner } from "./sdk-runner.js";
22
- import { SessionEngine } from "./session-engine.js";
23
-
24
- const AGENT = "artifacts-engine-test";
25
-
26
- function tagTool(): DiscoveredTool {
27
- const definition = defineTool({
28
- description: "Tags the reviewed PR as an artifact.",
29
- async execute(_input: JsonObject, ctx: ToolContext) {
30
- const record = await ctx.artifacts.tag({
31
- kind: "artifact",
32
- key: "pr-1",
33
- title: "Reviewed PR",
34
- data: { url: "https://github.com/org/repo/pull/1" },
35
- });
36
- return { id: record.id };
37
- },
38
- });
39
- return {
40
- name: "tag_result",
41
- description: definition.description,
42
- execution: "server",
43
- needsApproval: false,
44
- inputSchema: { type: "object", additionalProperties: false },
45
- definition,
46
- };
47
- }
48
-
49
- function testProject(options?: {
50
- artifacts?: ArtifactsDefinition;
51
- tools?: DiscoveredTool[];
52
- hooks?: DiscoveredHook[];
53
- schedules?: DiscoveredSchedule[];
54
- channels?: DiscoveredChannel[];
55
- }): AgentProject {
56
- return {
57
- rootDir: "/tmp/artifacts-fixture",
58
- agentDir: "/tmp/artifacts-fixture/agent",
59
- name: AGENT,
60
- agent: {
61
- name: AGENT,
62
- runtime: "local",
63
- instructions: "Test agent.",
64
- tools: options?.tools ?? [],
65
- skills: [],
66
- connections: [],
67
- subagents: [],
68
- seedFiles: [],
69
- },
70
- httpChannel: httpChannel(),
71
- channels: options?.channels ?? [],
72
- schedules: options?.schedules ?? [],
73
- hooks: options?.hooks ?? [],
74
- abs: [],
75
- artifacts: options?.artifacts,
76
- diagnostics: [],
77
- };
78
- }
79
-
80
- function echoRunner(): AgentRunner {
81
- return {
82
- runTurn: async (request) => ({
83
- status: "finished",
84
- result: `echo: ${request.prompt}`,
85
- }),
86
- };
87
- }
88
-
89
- /** Runner that invokes the session-bound `tag_result` custom tool. */
90
- function toolCallingRunner(): AgentRunner {
91
- return {
92
- runTurn: async (request) => {
93
- const tool = request.customTools.tag_result;
94
- if (tool === undefined) {
95
- throw new Error("tag_result not registered");
96
- }
97
- await tool.execute({}, { toolCallId: "call_tag_1" });
98
- return { status: "finished", result: "done" };
99
- },
100
- };
101
- }
102
-
103
- const cleanups: Array<() => Promise<void>> = [];
104
-
105
- afterEach(async () => {
106
- while (cleanups.length > 0) {
107
- await cleanups.pop()?.();
108
- }
109
- });
110
-
111
- async function makeEngine(
112
- project: AgentProject,
113
- runner: AgentRunner
114
- ): Promise<SessionEngine> {
115
- const stateRoot = await mkdtemp(join(tmpdir(), "agent-serve-artifacts-eng-"));
116
- cleanups.push(() => rm(stateRoot, { recursive: true, force: true }));
117
- const engine = new SessionEngine({ project, stateRoot, runner });
118
- cleanups.push(() => engine.close());
119
- return engine;
120
- }
121
-
122
- describe("session engine artifacts wiring", () => {
123
- it("tool ctx.artifacts auto-fills the session and appends artifact.tagged", async () => {
124
- const engine = await makeEngine(
125
- testProject({ tools: [tagTool()] }),
126
- toolCallingRunner()
127
- );
128
- const session = await engine.send("http", "review the PR", { auth: null });
129
- await session.waitForCompletion();
130
-
131
- const rows = await engine.artifacts.list({ sessionId: session.id });
132
- expect(rows).toHaveLength(1);
133
- expect(rows[0]).toMatchObject({
134
- kind: "artifact",
135
- key: "pr-1",
136
- sessionId: session.id,
137
- turnId: "turn_1",
138
- source: "host",
139
- });
140
-
141
- const events = await engine.listEvents(session.id);
142
- const tagged = events.filter((event) => event.type === "artifact.tagged");
143
- expect(tagged).toHaveLength(1);
144
- expect(tagged[0]).toMatchObject({
145
- sessionId: session.id,
146
- turnId: "turn_1",
147
- data: {
148
- id: rows[0]?.id,
149
- kind: "artifact",
150
- key: "pr-1",
151
- title: "Reviewed PR",
152
- source: "host",
153
- },
154
- });
155
- });
156
-
157
- it("bound facades reject a conflicting explicit sessionId", async () => {
158
- const engine = await makeEngine(testProject(), echoRunner());
159
- const session = await engine.send("http", "hello", { auth: null });
160
- await session.waitForCompletion();
161
-
162
- const bound = engine.artifactsApi({ sessionId: session.id });
163
- await expect(
164
- bound.tag({ data: 1, sessionId: "ses_other" })
165
- ).rejects.toThrow(/bound to session/);
166
- // The matching sessionId (a no-op override) is fine.
167
- await expect(
168
- bound.tag({ data: 1, sessionId: session.id })
169
- ).resolves.toMatchObject({ sessionId: session.id });
170
- });
171
-
172
- it("session-less tags via the unbound channel facade write the row only", async () => {
173
- const engine = await makeEngine(testProject(), echoRunner());
174
- const session = await engine.send("http", "hello", { auth: null });
175
- await session.waitForCompletion();
176
- const eventCount = (await engine.listEvents(session.id)).length;
177
-
178
- // ChannelHandlerArgs.artifacts is this same unbound facade.
179
- const record = await engine.artifacts.tag({ data: { note: "no session" } });
180
- expect(record.sessionId).toBeUndefined();
181
- expect(await engine.artifacts.list()).toHaveLength(1);
182
- expect(await engine.listEvents(session.id)).toHaveLength(eventCount);
183
- });
184
-
185
- it("unbound tags with an explicit sessionId stream to that session", async () => {
186
- const engine = await makeEngine(testProject(), echoRunner());
187
- const session = await engine.send("http", "hello", { auth: null });
188
- await session.waitForCompletion();
189
-
190
- const record = await engine.artifacts.tag({
191
- data: "attributed",
192
- sessionId: session.id,
193
- });
194
- expect(record.sessionId).toBe(session.id);
195
- const events = await engine.listEvents(session.id);
196
- expect(events.some((event) => event.type === "artifact.tagged")).toBe(true);
197
- });
198
-
199
- it("tags for an unknown sessionId reject before writing the row", async () => {
200
- const engine = await makeEngine(testProject(), echoRunner());
201
- await expect(
202
- engine.artifacts.tag({ data: 1, sessionId: "ses_nope" })
203
- ).rejects.toThrow(/Unknown session/);
204
- expect(await engine.artifacts.list()).toHaveLength(0);
205
- });
206
-
207
- it("schedule handlers get the unbound artifacts facade", async () => {
208
- const cron = "* * * * *";
209
- const schedule: DiscoveredSchedule = {
210
- name: "tagger",
211
- cron,
212
- kind: "run",
213
- definition: defineSchedule({
214
- cron,
215
- async run({ artifacts }) {
216
- await artifacts.tag({ key: "from-schedule", data: "s" });
217
- },
218
- }),
219
- };
220
- const project = testProject({ schedules: [schedule] });
221
- const engine = await makeEngine(project, echoRunner());
222
- const runner = new ScheduleRunner(engine, project);
223
- await runner.dispatch("tagger");
224
-
225
- const rows = await engine.artifacts.list();
226
- expect(rows.map((row) => row.key)).toEqual(["from-schedule"]);
227
- expect(rows[0]?.sessionId).toBeUndefined();
228
- });
229
-
230
- it("channel receive hooks get the unbound artifacts facade", async () => {
231
- const channel: DiscoveredChannel = {
232
- id: "handoff",
233
- definition: defineChannel({
234
- async receive(input, { send, artifacts }) {
235
- await artifacts.tag({ key: "from-receive", data: "r" });
236
- return send(input.message, { auth: input.auth });
237
- },
238
- }),
239
- };
240
- const engine = await makeEngine(
241
- testProject({ channels: [channel] }),
242
- echoRunner()
243
- );
244
- await engine.receive("handoff", { message: "hand-off", auth: null });
245
-
246
- const rows = await engine.artifacts.list();
247
- expect(rows.map((row) => row.key)).toEqual(["from-receive"]);
248
- expect(rows[0]?.sessionId).toBeUndefined();
249
- });
250
-
251
- it("hook ctx.artifacts is bound to the hook's session", async () => {
252
- const hook: DiscoveredHook = {
253
- name: "tagger",
254
- definition: defineHook({
255
- events: {
256
- async "turn.completed"(_event, ctx) {
257
- await ctx.artifacts.tag({ key: "from-hook", data: "h" });
258
- },
259
- },
260
- }),
261
- };
262
- const engine = await makeEngine(
263
- testProject({ hooks: [hook] }),
264
- echoRunner()
265
- );
266
- const session = await engine.send("http", "hello", { auth: null });
267
- await session.waitForCompletion();
268
-
269
- await vi.waitFor(async () => {
270
- const rows = await engine.artifacts.list({ sessionId: session.id });
271
- expect(rows.map((row) => row.key)).toEqual(["from-hook"]);
272
- });
273
- const events = await engine.listEvents(session.id);
274
- expect(events.some((event) => event.type === "artifact.tagged")).toBe(true);
275
- });
276
-
277
- it("enforces declared kinds end to end", async () => {
278
- const engine = await makeEngine(
279
- testProject({
280
- artifacts: defineArtifacts({
281
- kinds: { note: { description: "Note." } },
282
- }),
283
- }),
284
- echoRunner()
285
- );
286
- await expect(
287
- engine.artifacts.tag({ kind: "bogus", data: 1 })
288
- ).rejects.toThrow(/unknown kind/);
289
- await expect(
290
- engine.artifacts.tag({ kind: "note", data: 1 })
291
- ).resolves.toMatchObject({ kind: "note" });
292
- });
293
- });