@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,127 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import {
3
- buildIdentitySection,
4
- buildSessionContextBlock,
5
- channelPresenceLine,
6
- } from "./prompt-context.js";
7
-
8
- describe("buildIdentitySection", () => {
9
- it("renders name and description in one section", () => {
10
- const section = buildIdentitySection({
11
- name: "pr-approver",
12
- description: "Reviews GitHub pull requests.",
13
- });
14
- expect(section).toBe(
15
- [
16
- "## About you",
17
- "",
18
- 'You are "pr-approver" — Reviews GitHub pull requests. You run as a persistent service: messages reach you through channels (such as Slack, GitHub, webhooks, or a web playground), and each conversation is a session that can continue across multiple turns.',
19
- ].join("\n")
20
- );
21
- });
22
-
23
- it("omits the description clause when absent", () => {
24
- const section = buildIdentitySection({ name: "solo" });
25
- expect(section).toContain(
26
- 'You are "solo". You run as a persistent service'
27
- );
28
- expect(section).not.toContain("—");
29
- });
30
-
31
- it("keeps names containing quotes verbatim", () => {
32
- const section = buildIdentitySection({ name: 'the "best" bot' });
33
- expect(section).toContain('You are "the "best" bot".');
34
- });
35
- });
36
-
37
- describe("channelPresenceLine", () => {
38
- it("marks http and mcp as live user channels", () => {
39
- const live =
40
- "A user is interacting with you live and sees your replies as they stream.";
41
- expect(channelPresenceLine({ channelId: "http" })).toBe(live);
42
- expect(channelPresenceLine({ channelId: "mcp" })).toBe(live);
43
- });
44
-
45
- it("resolves slack from the channel pack kind, whatever the file stem", () => {
46
- const slack =
47
- "You are replying in a Slack thread; participants will read your messages.";
48
- expect(
49
- channelPresenceLine({ channelId: "slack", channelKind: "slack" })
50
- ).toBe(slack);
51
- expect(
52
- channelPresenceLine({ channelId: "slack-app", channelKind: "slack" })
53
- ).toBe(slack);
54
- });
55
-
56
- it("resolves github from the channel pack kind", () => {
57
- expect(
58
- channelPresenceLine({ channelId: "pr-events", channelKind: "github" })
59
- ).toContain("triggered by a GitHub event");
60
- });
61
-
62
- it("marks any schedule:* channel as unattended", () => {
63
- expect(
64
- channelPresenceLine({ channelId: "schedule:nightly-report" })
65
- ).toContain("No user is watching");
66
- });
67
-
68
- it("returns undefined for unknown channels and kinds", () => {
69
- expect(channelPresenceLine({ channelId: "discord" })).toBeUndefined();
70
- expect(channelPresenceLine({ channelId: "schedules" })).toBeUndefined();
71
- expect(
72
- channelPresenceLine({ channelId: "custom", channelKind: "discord" })
73
- ).toBeUndefined();
74
- });
75
-
76
- it("does not infer slack/github semantics from the file stem alone", () => {
77
- expect(
78
- channelPresenceLine({ channelId: "slack", channelKind: undefined })
79
- ).toBeUndefined();
80
- });
81
- });
82
-
83
- describe("buildSessionContextBlock", () => {
84
- const now = new Date("2026-07-16T12:34:56.000Z");
85
-
86
- it("renders the tagged block with a presence line", () => {
87
- const block = buildSessionContextBlock({
88
- sessionId: "ses_abc",
89
- channelId: "http",
90
- environment: "local dev server",
91
- now,
92
- });
93
- expect(block).toBe(
94
- [
95
- "<agentkit_context>",
96
- "session: ses_abc",
97
- "channel: http",
98
- "environment: local dev server",
99
- "time: 2026-07-16T12:34:56.000Z",
100
- "</agentkit_context>",
101
- "A user is interacting with you live and sees your replies as they stream.",
102
- ].join("\n")
103
- );
104
- });
105
-
106
- it("omits the presence line for unknown channels", () => {
107
- const block = buildSessionContextBlock({
108
- sessionId: "ses_abc",
109
- channelId: "custom-webhook",
110
- environment: "hosted deployment",
111
- now,
112
- });
113
- expect(block.endsWith("</agentkit_context>")).toBe(true);
114
- expect(block).toContain("environment: hosted deployment");
115
- });
116
-
117
- it("stamps the current time in ISO 8601 UTC when no clock is given", () => {
118
- const block = buildSessionContextBlock({
119
- sessionId: "ses_abc",
120
- channelId: "http",
121
- environment: "local dev server",
122
- });
123
- const time = /time: (.+)\n/.exec(block)?.[1] ?? "";
124
- expect(time).toMatch(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/);
125
- expect(Math.abs(Date.parse(time) - Date.now())).toBeLessThan(5_000);
126
- });
127
- });
@@ -1,432 +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 { defineStorage } from "../storage.js";
6
- import type { ArtifactRecord, ArtifactsApi, JsonValue } from "../types.js";
7
- import { ReminderRunner, ReminderValidationError } from "./reminder-runner.js";
8
- import type { SessionEngine } from "./session-engine.js";
9
- import { StorageCoordinator } from "./storage-coordinator.js";
10
-
11
- function mockEngine(
12
- stateRoot: string,
13
- storage?: StorageCoordinator
14
- ): SessionEngine {
15
- const send = vi.fn(async () => ({
16
- id: "ses_1",
17
- continuationToken: "tok",
18
- isNew: false,
19
- info: {
20
- id: "ses_1",
21
- channelId: "drive",
22
- mode: "chat" as const,
23
- auth: null,
24
- },
25
- getEventStream: () => ({}) as never,
26
- waitForCompletion: async () => ({ status: "completed" as const }),
27
- }));
28
- const artifactRows: ArtifactRecord[] = [];
29
- const artifacts: ArtifactsApi = {
30
- tag: async (input) => {
31
- const record: ArtifactRecord = {
32
- id: `art_${artifactRows.length + 1}`,
33
- kind: input.kind ?? "artifact",
34
- key: input.key,
35
- data: input.data,
36
- sessionId: input.sessionId,
37
- source: "host",
38
- createdAt: new Date().toISOString(),
39
- updatedAt: new Date().toISOString(),
40
- };
41
- artifactRows.push(record);
42
- return record;
43
- },
44
- list: async () => [...artifactRows],
45
- };
46
- return {
47
- stateRoot,
48
- storage,
49
- artifacts,
50
- host: {
51
- mcp: {} as never,
52
- github: {} as never,
53
- slack: {} as never,
54
- },
55
- sessions: {
56
- findByContinuation: vi.fn(async () => ({
57
- sessionId: "ses_1",
58
- channelId: "drive",
59
- mode: "chat" as const,
60
- auth: null,
61
- continuationKey: "tok",
62
- turnCount: 1,
63
- createdAt: new Date().toISOString(),
64
- updatedAt: new Date().toISOString(),
65
- })),
66
- },
67
- send,
68
- waitForCompletion: async () => ({ status: "completed" as const }),
69
- trackBackground: () => {},
70
- getChannelSession: async () => null,
71
- isTurnRunning: () => false,
72
- } as unknown as SessionEngine;
73
- }
74
-
75
- function memoryStorage(): {
76
- coordinator: StorageCoordinator;
77
- store: Map<string, JsonValue>;
78
- } {
79
- const store = new Map<string, JsonValue>();
80
- const definition = defineStorage({
81
- put: (key, value) => {
82
- store.set(key, value);
83
- },
84
- get: (key) => store.get(key),
85
- delete: (key) => {
86
- store.delete(key);
87
- },
88
- list: (prefix) =>
89
- [...store.entries()]
90
- .filter(([key]) => key.startsWith(prefix))
91
- .sort(([a], [b]) => (a < b ? -1 : 1))
92
- .map(([key, value]) => ({ key, value })),
93
- });
94
- return {
95
- coordinator: new StorageCoordinator({
96
- definition,
97
- agentName: "test-agent",
98
- projectRoot: "/tmp/test-agent",
99
- logger: () => {},
100
- }),
101
- store,
102
- };
103
- }
104
-
105
- describe("ReminderRunner", () => {
106
- let dir: string;
107
-
108
- afterEach(async () => {
109
- if (dir !== undefined) {
110
- await rm(dir, { recursive: true, force: true });
111
- }
112
- });
113
-
114
- it("validates prompt XOR run and schedule shape", async () => {
115
- dir = await mkdtemp(join(tmpdir(), "rem-runner-"));
116
- const runner = new ReminderRunner(mockEngine(dir));
117
- await expect(
118
- runner.create({
119
- purpose: "x",
120
- channelId: "drive",
121
- continuationToken: "tok",
122
- prompt: "hi",
123
- run: async () => ({ action: "skip" }),
124
- delay: "1s",
125
- })
126
- ).rejects.toBeInstanceOf(ReminderValidationError);
127
-
128
- await expect(
129
- runner.create({
130
- purpose: "x",
131
- channelId: "drive",
132
- continuationToken: "tok",
133
- prompt: "hi",
134
- every: "1m",
135
- delay: "1s",
136
- })
137
- ).rejects.toBeInstanceOf(ReminderValidationError);
138
- });
139
-
140
- it("creates one-shot, dispatches, and completes", async () => {
141
- dir = await mkdtemp(join(tmpdir(), "rem-runner-"));
142
- const engine = mockEngine(dir);
143
- const runner = new ReminderRunner(engine);
144
- await runner.start();
145
-
146
- const created = await runner.create({
147
- purpose: "ci_recheck",
148
- channelId: "drive",
149
- continuationToken: "tok",
150
- delay: "1h",
151
- prompt: "check ci",
152
- });
153
- expect(created.status).toBe("armed");
154
- expect(created.hasRunHandler).toBe(false);
155
-
156
- await runner.dispatch(created.id);
157
- const listed = await runner.list();
158
- const done = listed.find((r) => r.id === created.id);
159
- expect(done?.status).toBe("completed");
160
- expect(engine.send).toHaveBeenCalled();
161
- const message = (engine.send as ReturnType<typeof vi.fn>).mock
162
- .calls[0]?.[1];
163
- expect(message).toContain(`id=${created.id}`);
164
- expect(message).toContain("check ci");
165
- });
166
-
167
- it("run handlers get the unbound artifacts facade", async () => {
168
- dir = await mkdtemp(join(tmpdir(), "rem-runner-"));
169
- const engine = mockEngine(dir);
170
- const runner = new ReminderRunner(engine);
171
- await runner.start();
172
-
173
- const created = await runner.create({
174
- purpose: "alert_watch",
175
- channelId: "drive",
176
- continuationToken: "tok",
177
- every: "1m",
178
- run: async ({ artifacts }) => {
179
- await artifacts.tag({ key: "from-reminder", data: "r" });
180
- return { action: "skip" };
181
- },
182
- });
183
- await runner.dispatch(created.id);
184
-
185
- const rows = await engine.artifacts.list();
186
- expect(rows.map((row) => row.key)).toEqual(["from-reminder"]);
187
- expect(rows[0]?.sessionId).toBeUndefined();
188
- });
189
-
190
- it("disarms prompt reminders when the bound session is gone", async () => {
191
- dir = await mkdtemp(join(tmpdir(), "rem-runner-"));
192
- const engine = mockEngine(dir);
193
- (
194
- engine.sessions.findByContinuation as ReturnType<typeof vi.fn>
195
- ).mockResolvedValue(undefined);
196
- const runner = new ReminderRunner(engine);
197
- await runner.start();
198
-
199
- const created = await runner.create({
200
- purpose: "orphan",
201
- channelId: "drive",
202
- continuationToken: "tok",
203
- delay: "1h",
204
- prompt: "should not wake",
205
- });
206
- const result = await runner.dispatch(created.id);
207
- expect(result.outcome).toBe("fired");
208
- expect(result.reason).toBe("session_gone");
209
- const listed = await runner.list();
210
- expect(listed.find((r) => r.id === created.id)?.status).toBe("disarmed");
211
- expect(listed.find((r) => r.id === created.id)?.disarmReason).toBe(
212
- "session_gone"
213
- );
214
- expect(engine.send).not.toHaveBeenCalled();
215
- });
216
-
217
- it("reports noop when dispatching a cancelled reminder", async () => {
218
- dir = await mkdtemp(join(tmpdir(), "rem-runner-"));
219
- const engine = mockEngine(dir);
220
- const runner = new ReminderRunner(engine);
221
- await runner.start();
222
- const created = await runner.create({
223
- purpose: "x",
224
- channelId: "drive",
225
- continuationToken: "tok",
226
- delay: "1h",
227
- prompt: "hi",
228
- });
229
- await runner.cancel(created.id);
230
- const result = await runner.dispatch(created.id);
231
- expect(result).toEqual({
232
- reminderId: created.id,
233
- outcome: "noop",
234
- reason: "not_armed",
235
- });
236
- expect(engine.send).not.toHaveBeenCalled();
237
- });
238
-
239
- it("rejects invalid reschedule.at instead of NaN-looping", async () => {
240
- dir = await mkdtemp(join(tmpdir(), "rem-runner-"));
241
- const engine = mockEngine(dir);
242
- const runner = new ReminderRunner(engine);
243
- await runner.start();
244
- const created = await runner.create({
245
- purpose: "watch",
246
- channelId: "drive",
247
- continuationToken: "tok",
248
- every: "30m",
249
- async run() {
250
- return { action: "skip", reschedule: { at: "not-a-date" } };
251
- },
252
- });
253
- await expect(runner.dispatch(created.id)).rejects.toBeInstanceOf(
254
- ReminderValidationError
255
- );
256
- await runner.cancel(created.id);
257
- });
258
-
259
- it("includes reminder id and cancel guidance only for recurring until prompts", async () => {
260
- dir = await mkdtemp(join(tmpdir(), "rem-runner-"));
261
- const engine = mockEngine(dir);
262
- const runner = new ReminderRunner(engine);
263
- await runner.start();
264
-
265
- const oneshot = await runner.create({
266
- purpose: "once",
267
- channelId: "drive",
268
- continuationToken: "tok",
269
- delay: "1h",
270
- prompt: "one shot body",
271
- until: "Stop when done.",
272
- });
273
- await runner.dispatch(oneshot.id);
274
- const oneshotMsg = (engine.send as ReturnType<typeof vi.fn>).mock
275
- .calls[0]?.[1] as string;
276
- expect(oneshotMsg).toContain(`id=${oneshot.id}`);
277
- expect(oneshotMsg).toContain("one-shot reminder");
278
- expect(oneshotMsg).not.toContain("reminders_cancel");
279
-
280
- (engine.send as ReturnType<typeof vi.fn>).mockClear();
281
- const recurring = await runner.create({
282
- purpose: "loop",
283
- channelId: "drive",
284
- continuationToken: "tok2",
285
- every: "30m",
286
- prompt: "loop body",
287
- until: "Cancel when green.",
288
- });
289
- await runner.dispatch(recurring.id);
290
- const loopMsg = (engine.send as ReturnType<typeof vi.fn>).mock
291
- .calls[0]?.[1] as string;
292
- expect(loopMsg).toContain(`id=${recurring.id}`);
293
- expect(loopMsg).toContain(`reminders_cancel with id=${recurring.id}`);
294
- await runner.cancel(recurring.id);
295
- });
296
-
297
- it("disarms when until function returns true", async () => {
298
- dir = await mkdtemp(join(tmpdir(), "rem-runner-"));
299
- const engine = mockEngine(dir);
300
- const runner = new ReminderRunner(engine);
301
- await runner.start();
302
-
303
- const created = await runner.create({
304
- purpose: "watch",
305
- channelId: "drive",
306
- continuationToken: "tok",
307
- delay: "1h",
308
- until: async () => true,
309
- async run() {
310
- return { action: "delivered" };
311
- },
312
- });
313
- await runner.dispatch(created.id);
314
- const listed = await runner.list();
315
- expect(listed.find((r) => r.id === created.id)?.status).toBe("disarmed");
316
- expect(engine.send).not.toHaveBeenCalled();
317
- });
318
-
319
- it("run handler can skip without waking the session", async () => {
320
- dir = await mkdtemp(join(tmpdir(), "rem-runner-"));
321
- const engine = mockEngine(dir);
322
- const runner = new ReminderRunner(engine);
323
- await runner.start();
324
-
325
- const created = await runner.create({
326
- purpose: "watch",
327
- channelId: "drive",
328
- continuationToken: "tok",
329
- every: "30m",
330
- async run() {
331
- return { action: "skip" };
332
- },
333
- });
334
- await runner.dispatch(created.id);
335
- const listed = await runner.list({ status: "armed" });
336
- expect(listed.some((r) => r.id === created.id)).toBe(true);
337
- expect(engine.send).not.toHaveBeenCalled();
338
- await runner.cancel(created.id);
339
- });
340
-
341
- it("mirrors prompt reminders into defineStorage and hydrates a fresh host", async () => {
342
- const { coordinator, store } = memoryStorage();
343
- dir = await mkdtemp(join(tmpdir(), "rem-runner-"));
344
- const engineA = mockEngine(dir, coordinator);
345
- const runnerA = new ReminderRunner(engineA);
346
- await runnerA.start();
347
- const created = await runnerA.create({
348
- purpose: "ci_recheck",
349
- channelId: "drive",
350
- continuationToken: "tok",
351
- delay: "1h",
352
- prompt: "check ci",
353
- });
354
- await coordinator.whenIdle();
355
- expect(store.size).toBeGreaterThan(0);
356
- runnerA.stop();
357
-
358
- // Fresh state root (replacement host) + same sink.
359
- const dirB = await mkdtemp(join(tmpdir(), "rem-runner-b-"));
360
- try {
361
- const engineB = mockEngine(dirB, coordinator);
362
- const runnerB = new ReminderRunner(engineB);
363
- await runnerB.start();
364
- const listed = await runnerB.list({ status: "armed" });
365
- const rem = listed.find((r) => r.id === created.id);
366
- expect(rem?.purpose).toBe("ci_recheck");
367
- expect(rem?.prompt).toBe("check ci");
368
- expect(rem?.status).toBe("armed");
369
- runnerB.stop();
370
- } finally {
371
- await rm(dirB, { recursive: true, force: true });
372
- }
373
- });
374
-
375
- it("disarms run-handler reminders on restart when handlers are gone", async () => {
376
- dir = await mkdtemp(join(tmpdir(), "rem-runner-"));
377
- const engine = mockEngine(dir);
378
- const runner = new ReminderRunner(engine);
379
- await runner.start();
380
- const created = await runner.create({
381
- purpose: "watch",
382
- channelId: "drive",
383
- continuationToken: "tok",
384
- every: "30m",
385
- async run() {
386
- return { action: "skip" };
387
- },
388
- });
389
- runner.stop();
390
-
391
- const restored = new ReminderRunner(engine);
392
- await restored.start();
393
- const listed = await restored.list();
394
- const rem = listed.find((r) => r.id === created.id);
395
- expect(rem?.status).toBe("disarmed");
396
- expect(rem?.disarmReason).toBe("handler_lost_on_restart");
397
- expect(engine.send).not.toHaveBeenCalled();
398
- });
399
-
400
- it("does not re-arm after cancel during an in-flight fire", async () => {
401
- dir = await mkdtemp(join(tmpdir(), "rem-runner-"));
402
- const engine = mockEngine(dir);
403
- const runner = new ReminderRunner(engine);
404
- await runner.start();
405
-
406
- let releaseRun: (() => void) | undefined;
407
- const runGate = new Promise<void>((resolve) => {
408
- releaseRun = resolve;
409
- });
410
-
411
- const created = await runner.create({
412
- purpose: "watch",
413
- channelId: "drive",
414
- continuationToken: "tok",
415
- every: "30m",
416
- async run() {
417
- await runGate;
418
- return { action: "delivered" };
419
- },
420
- });
421
-
422
- const firePromise = runner.dispatch(created.id);
423
- // Let fire() enter the run handler before cancel.
424
- await new Promise((r) => setTimeout(r, 10));
425
- await runner.cancel(created.id, "pr_closed");
426
- releaseRun?.();
427
- await firePromise;
428
-
429
- const listed = await runner.list();
430
- expect(listed.find((r) => r.id === created.id)?.status).toBe("cancelled");
431
- });
432
- });
@@ -1,53 +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 {
6
- isReminderRecord,
7
- type ReminderRecord,
8
- ReminderStore,
9
- } from "./reminder-store.js";
10
-
11
- describe("ReminderStore", () => {
12
- let dir: string;
13
-
14
- afterEach(async () => {
15
- if (dir !== undefined) {
16
- await rm(dir, { recursive: true, force: true });
17
- }
18
- });
19
-
20
- it("saves, lists, and loads armed reminders", async () => {
21
- dir = await mkdtemp(join(tmpdir(), "agent-serve-reminders-"));
22
- const store = new ReminderStore(dir);
23
- const now = new Date().toISOString();
24
- const record: ReminderRecord = {
25
- version: 1,
26
- id: "rem_test",
27
- purpose: "merge_conflict_watch",
28
- channelId: "drive",
29
- continuationToken: "pr-owner-repo-1",
30
- target: { prUrl: "https://github.com/owner/repo/pull/1" },
31
- scheduleKind: "every",
32
- scheduleValue: "30m",
33
- intervalMs: 30 * 60_000,
34
- hasRunHandler: true,
35
- hasUntilFn: true,
36
- busyPolicy: "skipIfBusy",
37
- status: "armed",
38
- fireCount: 0,
39
- nextFireAtMs: Date.now() + 60_000,
40
- createdAt: now,
41
- updatedAt: now,
42
- };
43
- await store.save(record);
44
- const loaded = await store.get("rem_test");
45
- expect(loaded?.purpose).toBe("merge_conflict_watch");
46
- const armed = await store.listArmed();
47
- expect(armed).toHaveLength(1);
48
- await store.delete("rem_test");
49
- expect(await store.get("rem_test")).toBeUndefined();
50
- expect(isReminderRecord(record)).toBe(true);
51
- expect(isReminderRecord({ not: "a reminder" })).toBe(false);
52
- });
53
- });
@@ -1,27 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { mergeRequestHeaders } from "./request-headers.js";
3
-
4
- describe("mergeRequestHeaders", () => {
5
- it("returns empty object when unset", () => {
6
- expect(mergeRequestHeaders(undefined)).toEqual({});
7
- expect(mergeRequestHeaders({})).toEqual({});
8
- });
9
-
10
- it("adds Authorization bearer", () => {
11
- expect(mergeRequestHeaders({ bearerToken: "secret" })).toEqual({
12
- authorization: "Bearer secret",
13
- });
14
- });
15
-
16
- it("merges engineAccess headers with bearer", () => {
17
- expect(
18
- mergeRequestHeaders({
19
- bearerToken: "secret",
20
- headers: { "x-anyrun-port-token": "pt" },
21
- })
22
- ).toEqual({
23
- "x-anyrun-port-token": "pt",
24
- authorization: "Bearer secret",
25
- });
26
- });
27
- });