@cursor/july 0.1.25 → 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 (288) 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/channels/github/github-channel.ts +19 -2
  145. package/src/channels/github/types.ts +6 -0
  146. package/src/channels/slack/api.ts +3 -1
  147. package/src/channels/slack/cursor-account.ts +3 -1
  148. package/src/channels/slack/dispatch.ts +12 -1
  149. package/src/channels/slack/interactive.ts +3 -0
  150. package/src/channels/slack/slack-channel.ts +6 -0
  151. package/src/channels/slack/types.ts +6 -0
  152. package/src/internal/ab-fold.ts +4 -0
  153. package/src/internal/ab-snapshot.ts +1 -0
  154. package/src/internal/cli-ax.ts +95 -0
  155. package/src/internal/model-pricing.ts +426 -0
  156. package/src/internal/reminder-runner.ts +1 -0
  157. package/src/internal/schedule-runner.ts +1 -0
  158. package/src/internal/sdk-runner.ts +10 -2
  159. package/src/internal/server.ts +2 -0
  160. package/src/internal/session-cost.ts +231 -0
  161. package/src/internal/session-engine.ts +32 -1
  162. package/src/internal/trajectory.ts +45 -3
  163. package/src/types.ts +42 -2
  164. package/dist/channels/github/instrument.d.ts +0 -20
  165. package/dist/channels/github/instrument.d.ts.map +0 -1
  166. package/dist/docs/assets/chunks/@localSearchIndexroot.BQTzJjR_.js +0 -1
  167. package/dist/internal/json-dir-store.d.ts +0 -32
  168. package/dist/internal/json-dir-store.d.ts.map +0 -1
  169. package/dist/internal/json-dir-store.js +0 -100
  170. package/dist/playground/assets/index-CjOQ4hN9.css +0 -1
  171. package/dist/playground/assets/index-DqXdAFGa.js +0 -85
  172. package/src/bin/agent-serve.version.test.ts +0 -64
  173. package/src/channels/github/api.test.ts +0 -64
  174. package/src/channels/github/auth.test.ts +0 -105
  175. package/src/channels/github/cursor-account.test.ts +0 -204
  176. package/src/channels/github/forward.test.ts +0 -457
  177. package/src/channels/github/github.test.ts +0 -943
  178. package/src/channels/github/replay.test.ts +0 -179
  179. package/src/channels/slack/api.post-message.test.ts +0 -148
  180. package/src/channels/slack/approvals.test.ts +0 -328
  181. package/src/channels/slack/block-actions.test.ts +0 -452
  182. package/src/channels/slack/bot-mentions.test.ts +0 -267
  183. package/src/channels/slack/channel-watch.test.ts +0 -363
  184. package/src/channels/slack/cursor-account.test.ts +0 -253
  185. package/src/channels/slack/defaults.final-post.test.ts +0 -182
  186. package/src/channels/slack/dispatch.test.ts +0 -795
  187. package/src/channels/slack/eval-directive.test.ts +0 -273
  188. package/src/channels/slack/message-body.test.ts +0 -54
  189. package/src/channels/slack/nudge-store.test.ts +0 -143
  190. package/src/channels/slack/slack.test.ts +0 -391
  191. package/src/channels/slack/stop.test.ts +0 -23
  192. package/src/channels/slack/thread-context.test.ts +0 -202
  193. package/src/evals/assertions.test.ts +0 -617
  194. package/src/evals/expect.test.ts +0 -144
  195. package/src/evals/judge.test.ts +0 -181
  196. package/src/evals/loaders.test.ts +0 -132
  197. package/src/evals/matchers.test.ts +0 -95
  198. package/src/evals/reporters.test.ts +0 -303
  199. package/src/evals/run-facts.test.ts +0 -259
  200. package/src/internal/ab-snapshot.test.ts +0 -325
  201. package/src/internal/approval-gate.test.ts +0 -49
  202. package/src/internal/approvals.integration.test.ts +0 -383
  203. package/src/internal/artifacts-store.test.ts +0 -283
  204. package/src/internal/authored-loaders.test.ts +0 -31
  205. package/src/internal/builtin-tools/artifacts.test.ts +0 -247
  206. package/src/internal/builtin-tools/reminders.test.ts +0 -201
  207. package/src/internal/channel-route-schema.test.ts +0 -294
  208. package/src/internal/chat-attach.test.ts +0 -262
  209. package/src/internal/cli-deploy.test.ts +0 -1991
  210. package/src/internal/cli-docs.test.ts +0 -161
  211. package/src/internal/cli-mcp.test.ts +0 -789
  212. package/src/internal/cli-skills.test.ts +0 -133
  213. package/src/internal/cli-slack.test.ts +0 -1654
  214. package/src/internal/cloud-merge.test.ts +0 -74
  215. package/src/internal/cron.test.ts +0 -22
  216. package/src/internal/cursor/account-mcp.test.ts +0 -807
  217. package/src/internal/cursor/backend-client.test.ts +0 -591
  218. package/src/internal/cursor/credentials.test.ts +0 -351
  219. package/src/internal/cursor/github-credentials.test.ts +0 -136
  220. package/src/internal/cursor-account-mcp-auth.test.ts +0 -310
  221. package/src/internal/cursor-account.integration.test.ts +0 -441
  222. package/src/internal/cursor-event-relay.test.ts +0 -746
  223. package/src/internal/cursor-github-credentials.integration.test.ts +0 -271
  224. package/src/internal/cursor-slack-relay.test.ts +0 -525
  225. package/src/internal/deploy-source.test.ts +0 -111
  226. package/src/internal/discovery.artifact-tool.test.ts +0 -136
  227. package/src/internal/discovery.artifacts.test.ts +0 -119
  228. package/src/internal/discovery.builtin-tools.test.ts +0 -94
  229. package/src/internal/discovery.concurrency.test.ts +0 -60
  230. package/src/internal/discovery.cursor-account.test.ts +0 -133
  231. package/src/internal/discovery.cwd.test.ts +0 -83
  232. package/src/internal/discovery.hosting.test.ts +0 -80
  233. package/src/internal/discovery.identity.test.ts +0 -44
  234. package/src/internal/docs-site.test.ts +0 -66
  235. package/src/internal/duration.test.ts +0 -29
  236. package/src/internal/eval-judge-model.test.ts +0 -187
  237. package/src/internal/eval-run-store.cancel.test.ts +0 -142
  238. package/src/internal/eval-run-store.storage.test.ts +0 -211
  239. package/src/internal/eval-runner.http.test.ts +0 -403
  240. package/src/internal/eval-runner.run.test.ts +0 -928
  241. package/src/internal/evals-client.test.ts +0 -307
  242. package/src/internal/event-mapper.test.ts +0 -243
  243. package/src/internal/github-fanout.test.ts +0 -213
  244. package/src/internal/handleAgentServeTrigger.test.ts +0 -185
  245. package/src/internal/host-kv.test.ts +0 -82
  246. package/src/internal/host-platforms.test.ts +0 -126
  247. package/src/internal/http-channel.test.ts +0 -402
  248. package/src/internal/init-project.test.ts +0 -270
  249. package/src/internal/install-cursor-skills.test.ts +0 -262
  250. package/src/internal/local-env.test.ts +0 -120
  251. package/src/internal/log-ring.test.ts +0 -31
  252. package/src/internal/logs-client.test.ts +0 -350
  253. package/src/internal/mcp-endpoint.test.ts +0 -436
  254. package/src/internal/mcp-host.test.ts +0 -298
  255. package/src/internal/mcp-oauth.test.ts +0 -148
  256. package/src/internal/net.test.ts +0 -17
  257. package/src/internal/peer-connections.test.ts +0 -128
  258. package/src/internal/peer-mcp.integration.test.ts +0 -289
  259. package/src/internal/playground/toolchain.test.ts +0 -53
  260. package/src/internal/playground-cli.test.ts +0 -187
  261. package/src/internal/playground-proxy.test.ts +0 -376
  262. package/src/internal/prompt-context.integration.test.ts +0 -232
  263. package/src/internal/prompt-context.test.ts +0 -127
  264. package/src/internal/reminder-runner.test.ts +0 -390
  265. package/src/internal/reminder-store.test.ts +0 -53
  266. package/src/internal/request-headers.test.ts +0 -27
  267. package/src/internal/resolve-prod-target.test.ts +0 -787
  268. package/src/internal/resolved-connections.test.ts +0 -295
  269. package/src/internal/router.test.ts +0 -57
  270. package/src/internal/sdk-runner.test.ts +0 -290
  271. package/src/internal/server.artifacts.test.ts +0 -303
  272. package/src/internal/session-engine.artifacts.test.ts +0 -243
  273. package/src/internal/session-engine.coalesce.test.ts +0 -169
  274. package/src/internal/session-engine.concurrency.test.ts +0 -250
  275. package/src/internal/session-engine.host-oauth-mcp.test.ts +0 -110
  276. package/src/internal/session-engine.interrupt.test.ts +0 -577
  277. package/src/internal/session-engine.storage.test.ts +0 -547
  278. package/src/internal/session-urls.test.ts +0 -28
  279. package/src/internal/sessions-client.test.ts +0 -518
  280. package/src/internal/storage-coordinator.test.ts +0 -517
  281. package/src/internal/tool-call.test.ts +0 -458
  282. package/src/internal/tool-result.test.ts +0 -52
  283. package/src/internal/trajectory.approvals.test.ts +0 -83
  284. package/src/internal/trajectory.subagents.test.ts +0 -198
  285. package/src/internal/turn-governor.test.ts +0 -137
  286. package/src/internal/update-check.test.ts +0 -485
  287. package/src/internal/workspace.test.ts +0 -207
  288. package/src/storage-backends/cursor-hosted.test.ts +0 -121
@@ -1,303 +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 { httpChannel } from "../channels.js";
8
- import { defineTool } from "../tools.js";
9
- import type {
10
- AgentProject,
11
- ArtifactRecord,
12
- AuthContext,
13
- DiscoveredTool,
14
- ServeOptions,
15
- } from "../types.js";
16
- import { toolInputJsonSchema } from "./json-schema.js";
17
- import type { AgentRunner } from "./sdk-runner.js";
18
- import { type AgentMount, startServer } from "./server.js";
19
- import { SessionEngine } from "./session-engine.js";
20
-
21
- const seedTool = defineTool({
22
- description: "Tags one artifact (test seed).",
23
- inputSchema: z.object({
24
- kind: z.string(),
25
- key: z.string().optional(),
26
- note: z.string().optional(),
27
- }),
28
- execute: async ({ kind, key, note }, ctx) => {
29
- const record = await ctx.artifacts.tag({
30
- kind,
31
- key,
32
- data: { note: note ?? null },
33
- });
34
- return { id: record.id };
35
- },
36
- });
37
-
38
- function testProject(rootDir: string): AgentProject {
39
- const discovered: DiscoveredTool = {
40
- name: "seed",
41
- description: seedTool.description,
42
- inputSchema: toolInputJsonSchema(seedTool.inputSchema),
43
- execution: "server",
44
- needsApproval: false,
45
- definition: seedTool,
46
- };
47
- return {
48
- rootDir,
49
- agentDir: join(rootDir, "agent"),
50
- name: "artifacts-route-test",
51
- agent: {
52
- name: "artifacts-route-test",
53
- runtime: "local",
54
- instructions: "Test agent.",
55
- tools: [discovered],
56
- skills: [],
57
- connections: [],
58
- subagents: [],
59
- seedFiles: [],
60
- },
61
- httpChannel: httpChannel(),
62
- channels: [],
63
- schedules: [],
64
- hooks: [],
65
- abs: [],
66
- artifacts: defineArtifacts({
67
- kinds: {
68
- "reviewed-pr": { description: "A reviewed PR." },
69
- report: { description: "A report." },
70
- },
71
- }),
72
- diagnostics: [],
73
- };
74
- }
75
-
76
- const noTurnRunner: AgentRunner = {
77
- runTurn: () => {
78
- throw new Error("runTurn must not be called");
79
- },
80
- };
81
-
82
- const cleanups: Array<() => Promise<void>> = [];
83
-
84
- afterEach(async () => {
85
- while (cleanups.length > 0) {
86
- await cleanups.pop()?.();
87
- }
88
- });
89
-
90
- async function startTestServer(options?: Partial<ServeOptions>) {
91
- const stateRoot = await mkdtemp(join(tmpdir(), "agent-serve-artroute-"));
92
- cleanups.push(() => rm(stateRoot, { recursive: true, force: true }));
93
- const mounts: AgentMount[] = [{ slug: "", project: testProject(stateRoot) }];
94
- const handle = await startServer(mounts, {
95
- port: 0,
96
- stateRoot,
97
- playground: false,
98
- schedules: false,
99
- logger: () => {},
100
- runner: noTurnRunner,
101
- ...options,
102
- });
103
- cleanups.push(() => handle.close());
104
- return handle;
105
- }
106
-
107
- async function listArtifacts(
108
- url: string,
109
- query = "",
110
- headers: Record<string, string> = {}
111
- ): Promise<{ status: number; artifacts: ArtifactRecord[] }> {
112
- const response = await fetch(`${url}/v1/artifacts${query}`, { headers });
113
- if (response.status !== 200) {
114
- return { status: response.status, artifacts: [] };
115
- }
116
- const body = (await response.json()) as { artifacts: ArtifactRecord[] };
117
- return { status: response.status, artifacts: body.artifacts };
118
- }
119
-
120
- /** Force distinct `updatedAt` millis so newest-first ordering is stable. */
121
- function tick(): Promise<void> {
122
- return new Promise((resolve) => setTimeout(resolve, 5));
123
- }
124
-
125
- describe("GET /v1/artifacts", () => {
126
- it("lists newest-updated first with kind filtering (dev includeAll)", async () => {
127
- const handle = await startTestServer({ dev: true });
128
- await handle.callTool("seed", { kind: "reviewed-pr", key: "pr-1" });
129
- await tick();
130
- await handle.callTool("seed", { kind: "report", key: "r-1" });
131
- await tick();
132
- await handle.callTool("seed", { kind: "reviewed-pr", key: "pr-2" });
133
-
134
- const all = await listArtifacts(handle.url);
135
- expect(all.status).toBe(200);
136
- expect(all.artifacts.map((a) => a.key)).toEqual(["pr-2", "r-1", "pr-1"]);
137
-
138
- const reports = await listArtifacts(handle.url, "?kind=report");
139
- expect(reports.artifacts.map((a) => a.key)).toEqual(["r-1"]);
140
-
141
- const none = await listArtifacts(handle.url, "?kind=missing");
142
- expect(none.artifacts).toEqual([]);
143
- });
144
-
145
- it("filters by sessionId", async () => {
146
- // Scratch (session-less) seeds never match a sessionId filter.
147
- const handle = await startTestServer({ dev: true });
148
- await handle.callTool("seed", { kind: "report", key: "loose" });
149
- const filtered = await listArtifacts(handle.url, "?sessionId=ses_other");
150
- expect(filtered.status).toBe(200);
151
- expect(filtered.artifacts).toEqual([]);
152
- expect((await listArtifacts(handle.url)).artifacts).toHaveLength(1);
153
- });
154
-
155
- it("bounds the limit and rejects non-positive limits", async () => {
156
- const handle = await startTestServer({ dev: true });
157
- for (const key of ["a", "b", "c"]) {
158
- await handle.callTool("seed", { kind: "report", key });
159
- await tick();
160
- }
161
- const limited = await listArtifacts(handle.url, "?limit=2");
162
- expect(limited.artifacts).toHaveLength(2);
163
- expect(limited.artifacts.map((a) => a.key)).toEqual(["c", "b"]);
164
-
165
- // Above the ceiling clamps rather than erroring.
166
- const clamped = await listArtifacts(handle.url, "?limit=99999");
167
- expect(clamped.status).toBe(200);
168
- expect(clamped.artifacts).toHaveLength(3);
169
-
170
- expect((await listArtifacts(handle.url, "?limit=0")).status).toBe(400);
171
- expect((await listArtifacts(handle.url, "?limit=nope")).status).toBe(400);
172
- });
173
-
174
- it("hides session-less artifacts from non-includeAll callers", async () => {
175
- // No --dev: loopback callers get the strict per-principal view, and
176
- // session-less (agent-scoped) artifacts have no owning principal.
177
- const handle = await startTestServer();
178
- await handle.callTool("seed", { kind: "report", key: "agent-scoped" });
179
- const listed = await listArtifacts(handle.url);
180
- expect(listed.status).toBe(200);
181
- expect(listed.artifacts).toEqual([]);
182
- });
183
-
184
- it("requires the bearer token when one is configured", async () => {
185
- const handle = await startTestServer({ authToken: "sekrit" });
186
- const denied = await fetch(`${handle.url}/v1/artifacts`);
187
- expect(denied.status).toBe(401);
188
- const allowed = await fetch(`${handle.url}/v1/artifacts`, {
189
- headers: { authorization: "Bearer sekrit" },
190
- });
191
- expect(allowed.status).toBe(200);
192
- });
193
-
194
- it("never widens to includeAll when a bearer token is configured", async () => {
195
- // Bearer auth vetoes relaxSessionReadAuth even under --dev on loopback,
196
- // matching GET /v1/sessions.
197
- const handle = await startTestServer({ dev: true, authToken: "sekrit" });
198
- await handle.callTool("seed", { kind: "report", key: "agent-scoped" });
199
- const listed = await listArtifacts(handle.url, "", {
200
- authorization: "Bearer sekrit",
201
- });
202
- expect(listed.status).toBe(200);
203
- expect(listed.artifacts).toEqual([]);
204
- });
205
- });
206
-
207
- describe("SessionEngine.listArtifacts ownership", () => {
208
- const alice: AuthContext = {
209
- authenticator: "test",
210
- principalId: "alice",
211
- principalType: "user",
212
- };
213
- const bob: AuthContext = {
214
- authenticator: "test",
215
- principalId: "bob",
216
- principalType: "user",
217
- };
218
-
219
- async function makeEngine(): Promise<SessionEngine> {
220
- const stateRoot = await mkdtemp(join(tmpdir(), "agent-serve-artown-"));
221
- cleanups.push(() => rm(stateRoot, { recursive: true, force: true }));
222
- const engine = new SessionEngine({
223
- project: testProject(stateRoot),
224
- stateRoot,
225
- runner: noTurnRunner,
226
- });
227
- cleanups.push(() => engine.close());
228
- return engine;
229
- }
230
-
231
- async function seedSession(
232
- engine: SessionEngine,
233
- sessionId: string,
234
- auth: AuthContext | null
235
- ): Promise<void> {
236
- await engine.sessions.save({
237
- sessionId,
238
- channelId: "http",
239
- mode: "chat",
240
- continuationKey: null,
241
- auth,
242
- turnCount: 0,
243
- createdAt: new Date().toISOString(),
244
- updatedAt: new Date().toISOString(),
245
- });
246
- }
247
-
248
- it("scopes non-includeAll listings to the caller's sessions", async () => {
249
- const engine = await makeEngine();
250
- await seedSession(engine, "ses_alice", alice);
251
- await seedSession(engine, "ses_bob", bob);
252
- await engine.artifacts.tag({
253
- kind: "report",
254
- key: "alice-report",
255
- data: 1,
256
- sessionId: "ses_alice",
257
- });
258
- await engine.artifacts.tag({
259
- kind: "report",
260
- key: "bob-report",
261
- data: 1,
262
- sessionId: "ses_bob",
263
- });
264
- await engine.artifacts.tag({ kind: "report", key: "loose", data: 1 });
265
-
266
- const forAlice = await engine.listArtifacts(alice);
267
- expect(forAlice.map((a) => a.key)).toEqual(["alice-report"]);
268
-
269
- const forBob = await engine.listArtifacts(bob);
270
- expect(forBob.map((a) => a.key)).toEqual(["bob-report"]);
271
-
272
- const anonymous = await engine.listArtifacts(null);
273
- expect(anonymous).toEqual([]);
274
-
275
- const everything = await engine.listArtifacts(null, { includeAll: true });
276
- expect(everything.map((a) => a.key).sort()).toEqual([
277
- "alice-report",
278
- "bob-report",
279
- "loose",
280
- ]);
281
- });
282
-
283
- it("applies the filter before ownership scoping", async () => {
284
- const engine = await makeEngine();
285
- await seedSession(engine, "ses_alice", alice);
286
- await engine.artifacts.tag({
287
- kind: "reviewed-pr",
288
- key: "pr",
289
- data: 1,
290
- sessionId: "ses_alice",
291
- });
292
- await engine.artifacts.tag({
293
- kind: "report",
294
- key: "rep",
295
- data: 1,
296
- sessionId: "ses_alice",
297
- });
298
- const filtered = await engine.listArtifacts(alice, {
299
- filter: { kind: "reviewed-pr" },
300
- });
301
- expect(filtered.map((a) => a.key)).toEqual(["pr"]);
302
- });
303
- });
@@ -1,243 +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 { httpChannel } from "../channels.js";
7
- import { defineHook } from "../hooks.js";
8
- import { defineTool } from "../tools.js";
9
- import type {
10
- AgentProject,
11
- ArtifactsDefinition,
12
- DiscoveredHook,
13
- DiscoveredTool,
14
- JsonObject,
15
- ToolContext,
16
- } from "../types.js";
17
- import type { AgentRunner } from "./sdk-runner.js";
18
- import { SessionEngine } from "./session-engine.js";
19
-
20
- const AGENT = "artifacts-engine-test";
21
-
22
- function tagTool(): DiscoveredTool {
23
- const definition = defineTool({
24
- description: "Tags the reviewed PR as an artifact.",
25
- async execute(_input: JsonObject, ctx: ToolContext) {
26
- const record = await ctx.artifacts.tag({
27
- kind: "artifact",
28
- key: "pr-1",
29
- title: "Reviewed PR",
30
- data: { url: "https://github.com/org/repo/pull/1" },
31
- });
32
- return { id: record.id };
33
- },
34
- });
35
- return {
36
- name: "tag_result",
37
- description: definition.description,
38
- execution: "server",
39
- needsApproval: false,
40
- inputSchema: { type: "object", additionalProperties: false },
41
- definition,
42
- };
43
- }
44
-
45
- function testProject(options?: {
46
- artifacts?: ArtifactsDefinition;
47
- tools?: DiscoveredTool[];
48
- hooks?: DiscoveredHook[];
49
- }): AgentProject {
50
- return {
51
- rootDir: "/tmp/artifacts-fixture",
52
- agentDir: "/tmp/artifacts-fixture/agent",
53
- name: AGENT,
54
- agent: {
55
- name: AGENT,
56
- runtime: "local",
57
- instructions: "Test agent.",
58
- tools: options?.tools ?? [],
59
- skills: [],
60
- connections: [],
61
- subagents: [],
62
- seedFiles: [],
63
- },
64
- httpChannel: httpChannel(),
65
- channels: [],
66
- schedules: [],
67
- hooks: options?.hooks ?? [],
68
- abs: [],
69
- artifacts: options?.artifacts,
70
- diagnostics: [],
71
- };
72
- }
73
-
74
- function echoRunner(): AgentRunner {
75
- return {
76
- runTurn: async (request) => ({
77
- status: "finished",
78
- result: `echo: ${request.prompt}`,
79
- }),
80
- };
81
- }
82
-
83
- /** Runner that invokes the session-bound `tag_result` custom tool. */
84
- function toolCallingRunner(): AgentRunner {
85
- return {
86
- runTurn: async (request) => {
87
- const tool = request.customTools.tag_result;
88
- if (tool === undefined) {
89
- throw new Error("tag_result not registered");
90
- }
91
- await tool.execute({}, { toolCallId: "call_tag_1" });
92
- return { status: "finished", result: "done" };
93
- },
94
- };
95
- }
96
-
97
- const cleanups: Array<() => Promise<void>> = [];
98
-
99
- afterEach(async () => {
100
- while (cleanups.length > 0) {
101
- await cleanups.pop()?.();
102
- }
103
- });
104
-
105
- async function makeEngine(
106
- project: AgentProject,
107
- runner: AgentRunner
108
- ): Promise<SessionEngine> {
109
- const stateRoot = await mkdtemp(join(tmpdir(), "agent-serve-artifacts-eng-"));
110
- cleanups.push(() => rm(stateRoot, { recursive: true, force: true }));
111
- const engine = new SessionEngine({ project, stateRoot, runner });
112
- cleanups.push(() => engine.close());
113
- return engine;
114
- }
115
-
116
- describe("session engine artifacts wiring", () => {
117
- it("tool ctx.artifacts auto-fills the session and appends artifact.tagged", async () => {
118
- const engine = await makeEngine(
119
- testProject({ tools: [tagTool()] }),
120
- toolCallingRunner()
121
- );
122
- const session = await engine.send("http", "review the PR", { auth: null });
123
- await session.waitForCompletion();
124
-
125
- const rows = await engine.artifacts.list({ sessionId: session.id });
126
- expect(rows).toHaveLength(1);
127
- expect(rows[0]).toMatchObject({
128
- kind: "artifact",
129
- key: "pr-1",
130
- sessionId: session.id,
131
- turnId: "turn_1",
132
- source: "host",
133
- });
134
-
135
- const events = await engine.listEvents(session.id);
136
- const tagged = events.filter((event) => event.type === "artifact.tagged");
137
- expect(tagged).toHaveLength(1);
138
- expect(tagged[0]).toMatchObject({
139
- sessionId: session.id,
140
- turnId: "turn_1",
141
- data: {
142
- id: rows[0]?.id,
143
- kind: "artifact",
144
- key: "pr-1",
145
- title: "Reviewed PR",
146
- source: "host",
147
- },
148
- });
149
- });
150
-
151
- it("bound facades reject a conflicting explicit sessionId", async () => {
152
- const engine = await makeEngine(testProject(), echoRunner());
153
- const session = await engine.send("http", "hello", { auth: null });
154
- await session.waitForCompletion();
155
-
156
- const bound = engine.artifactsApi({ sessionId: session.id });
157
- await expect(
158
- bound.tag({ data: 1, sessionId: "ses_other" })
159
- ).rejects.toThrow(/bound to session/);
160
- // The matching sessionId (a no-op override) is fine.
161
- await expect(
162
- bound.tag({ data: 1, sessionId: session.id })
163
- ).resolves.toMatchObject({ sessionId: session.id });
164
- });
165
-
166
- it("session-less tags via the unbound channel facade write the row only", async () => {
167
- const engine = await makeEngine(testProject(), echoRunner());
168
- const session = await engine.send("http", "hello", { auth: null });
169
- await session.waitForCompletion();
170
- const eventCount = (await engine.listEvents(session.id)).length;
171
-
172
- // ChannelHandlerArgs.artifacts is this same unbound facade.
173
- const record = await engine.artifacts.tag({ data: { note: "no session" } });
174
- expect(record.sessionId).toBeUndefined();
175
- expect(await engine.artifacts.list()).toHaveLength(1);
176
- expect(await engine.listEvents(session.id)).toHaveLength(eventCount);
177
- });
178
-
179
- it("unbound tags with an explicit sessionId stream to that session", async () => {
180
- const engine = await makeEngine(testProject(), echoRunner());
181
- const session = await engine.send("http", "hello", { auth: null });
182
- await session.waitForCompletion();
183
-
184
- const record = await engine.artifacts.tag({
185
- data: "attributed",
186
- sessionId: session.id,
187
- });
188
- expect(record.sessionId).toBe(session.id);
189
- const events = await engine.listEvents(session.id);
190
- expect(events.some((event) => event.type === "artifact.tagged")).toBe(true);
191
- });
192
-
193
- it("tags for an unknown sessionId reject before writing the row", async () => {
194
- const engine = await makeEngine(testProject(), echoRunner());
195
- await expect(
196
- engine.artifacts.tag({ data: 1, sessionId: "ses_nope" })
197
- ).rejects.toThrow(/Unknown session/);
198
- expect(await engine.artifacts.list()).toHaveLength(0);
199
- });
200
-
201
- it("hook ctx.artifacts is bound to the hook's session", async () => {
202
- const hook: DiscoveredHook = {
203
- name: "tagger",
204
- definition: defineHook({
205
- events: {
206
- async "turn.completed"(_event, ctx) {
207
- await ctx.artifacts.tag({ key: "from-hook", data: "h" });
208
- },
209
- },
210
- }),
211
- };
212
- const engine = await makeEngine(
213
- testProject({ hooks: [hook] }),
214
- echoRunner()
215
- );
216
- const session = await engine.send("http", "hello", { auth: null });
217
- await session.waitForCompletion();
218
-
219
- await vi.waitFor(async () => {
220
- const rows = await engine.artifacts.list({ sessionId: session.id });
221
- expect(rows.map((row) => row.key)).toEqual(["from-hook"]);
222
- });
223
- const events = await engine.listEvents(session.id);
224
- expect(events.some((event) => event.type === "artifact.tagged")).toBe(true);
225
- });
226
-
227
- it("enforces declared kinds end to end", async () => {
228
- const engine = await makeEngine(
229
- testProject({
230
- artifacts: defineArtifacts({
231
- kinds: { note: { description: "Note." } },
232
- }),
233
- }),
234
- echoRunner()
235
- );
236
- await expect(
237
- engine.artifacts.tag({ kind: "bogus", data: 1 })
238
- ).rejects.toThrow(/unknown kind/);
239
- await expect(
240
- engine.artifacts.tag({ kind: "note", data: 1 })
241
- ).resolves.toMatchObject({ kind: "note" });
242
- });
243
- });