@cursor/july 0.1.26 → 0.1.27

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