@cursor/july 0.1.23 → 0.1.24

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 (174) hide show
  1. package/dist/bin/agent-serve.js +0 -0
  2. package/dist/docs/404.html +1 -1
  3. package/dist/docs/ab.html +2 -2
  4. package/dist/docs/assets/{app.DYcC9FY-.js → app.CvSGaAxk.js} +1 -1
  5. package/dist/docs/assets/chunks/@localSearchIndexroot.CL2Y0Zmh.js +1 -0
  6. package/dist/docs/assets/chunks/{VPLocalSearchBox.o4N_knTV.js → VPLocalSearchBox.J1jJbCvs.js} +1 -1
  7. package/dist/docs/assets/chunks/{theme.DQ-njyo0.js → theme.C7vfzr7h.js} +2 -2
  8. package/dist/docs/building-with-agents.html +2 -2
  9. package/dist/docs/concepts.html +2 -2
  10. package/dist/docs/deployment.html +2 -2
  11. package/dist/docs/evals.html +2 -2
  12. package/dist/docs/example-agents/approval-buddy.html +2 -2
  13. package/dist/docs/example-agents/benny.html +2 -2
  14. package/dist/docs/example-agents/bugbot.html +2 -2
  15. package/dist/docs/example-agents/codebase-wiki.html +2 -2
  16. package/dist/docs/example-agents/codeowners-review.html +2 -2
  17. package/dist/docs/example-agents/concierge.html +2 -2
  18. package/dist/docs/example-agents/fsd.html +2 -2
  19. package/dist/docs/example-agents/index.html +2 -2
  20. package/dist/docs/example-agents/knowledge-base.html +2 -2
  21. package/dist/docs/example-agents/oncall.html +2 -2
  22. package/dist/docs/example-agents/security-reviewer.html +2 -2
  23. package/dist/docs/example-agents/slack-agent.html +2 -2
  24. package/dist/docs/example-agents/weather-agent.html +2 -2
  25. package/dist/docs/guides/agent-to-agent.html +2 -2
  26. package/dist/docs/guides/cloud-runtime.html +2 -2
  27. package/dist/docs/guides/github.html +2 -2
  28. package/dist/docs/guides/human-in-the-loop.html +2 -2
  29. package/dist/docs/guides/mcp-oauth.html +2 -2
  30. package/dist/docs/guides/slack.html +2 -2
  31. package/dist/docs/guides/webhooks.html +2 -2
  32. package/dist/docs/hillclimbing.html +2 -2
  33. package/dist/docs/index.html +2 -2
  34. package/dist/docs/quickstart.html +2 -2
  35. package/dist/docs/reference/agent-config.html +2 -2
  36. package/dist/docs/reference/channels.html +2 -2
  37. package/dist/docs/reference/cli.html +2 -2
  38. package/dist/docs/reference/connections.html +2 -2
  39. package/dist/docs/reference/hooks.html +2 -2
  40. package/dist/docs/reference/http-api.html +2 -2
  41. package/dist/docs/reference/instructions.html +2 -2
  42. package/dist/docs/reference/playground.html +2 -2
  43. package/dist/docs/reference/project-layout.html +2 -2
  44. package/dist/docs/reference/prompt.html +2 -2
  45. package/dist/docs/reference/schedules.html +2 -2
  46. package/dist/docs/reference/sessions.html +2 -2
  47. package/dist/docs/reference/skills.html +2 -2
  48. package/dist/docs/reference/subagents.html +2 -2
  49. package/dist/docs/reference/tools.html +2 -2
  50. package/dist/docs/scaffolding-agents.html +2 -2
  51. package/dist/docs/storage.html +2 -2
  52. package/dist/docs/troubleshooting.html +2 -2
  53. package/dist/playground/assets/index-CidizGZv.css +1 -0
  54. package/dist/playground/assets/{index-DqXdAFGa.js → index-DTG9OsPV.js} +41 -41
  55. package/dist/playground/index.html +2 -2
  56. package/package.json +24 -24
  57. package/dist/channels/github/instrument.d.ts +0 -20
  58. package/dist/channels/github/instrument.d.ts.map +0 -1
  59. package/dist/docs/assets/chunks/@localSearchIndexroot.BQTzJjR_.js +0 -1
  60. package/dist/internal/json-dir-store.d.ts +0 -32
  61. package/dist/internal/json-dir-store.d.ts.map +0 -1
  62. package/dist/internal/json-dir-store.js +0 -100
  63. package/dist/playground/assets/index-CjOQ4hN9.css +0 -1
  64. package/src/bin/agent-serve.version.test.ts +0 -64
  65. package/src/channels/github/api.test.ts +0 -64
  66. package/src/channels/github/auth.test.ts +0 -105
  67. package/src/channels/github/cursor-account.test.ts +0 -204
  68. package/src/channels/github/forward.test.ts +0 -457
  69. package/src/channels/github/github.test.ts +0 -937
  70. package/src/channels/github/replay.test.ts +0 -179
  71. package/src/channels/slack/api.post-message.test.ts +0 -148
  72. package/src/channels/slack/approvals.test.ts +0 -328
  73. package/src/channels/slack/block-actions.test.ts +0 -452
  74. package/src/channels/slack/bot-mentions.test.ts +0 -267
  75. package/src/channels/slack/channel-watch.test.ts +0 -363
  76. package/src/channels/slack/cursor-account.test.ts +0 -253
  77. package/src/channels/slack/defaults.final-post.test.ts +0 -182
  78. package/src/channels/slack/dispatch.test.ts +0 -795
  79. package/src/channels/slack/eval-directive.test.ts +0 -273
  80. package/src/channels/slack/message-body.test.ts +0 -54
  81. package/src/channels/slack/nudge-store.test.ts +0 -143
  82. package/src/channels/slack/slack.test.ts +0 -391
  83. package/src/channels/slack/stop.test.ts +0 -23
  84. package/src/channels/slack/thread-context.test.ts +0 -202
  85. package/src/evals/assertions.test.ts +0 -580
  86. package/src/evals/expect.test.ts +0 -144
  87. package/src/evals/judge.test.ts +0 -181
  88. package/src/evals/loaders.test.ts +0 -132
  89. package/src/evals/matchers.test.ts +0 -95
  90. package/src/evals/reporters.test.ts +0 -303
  91. package/src/evals/run-facts.test.ts +0 -259
  92. package/src/internal/ab-snapshot.test.ts +0 -325
  93. package/src/internal/approval-gate.test.ts +0 -49
  94. package/src/internal/approvals.integration.test.ts +0 -383
  95. package/src/internal/authored-loaders.test.ts +0 -31
  96. package/src/internal/builtin-tools/reminders.test.ts +0 -201
  97. package/src/internal/channel-route-schema.test.ts +0 -294
  98. package/src/internal/chat-attach.test.ts +0 -262
  99. package/src/internal/cli-deploy.test.ts +0 -1991
  100. package/src/internal/cli-docs.test.ts +0 -161
  101. package/src/internal/cli-mcp.test.ts +0 -789
  102. package/src/internal/cli-skills.test.ts +0 -133
  103. package/src/internal/cli-slack.test.ts +0 -1647
  104. package/src/internal/cloud-merge.test.ts +0 -74
  105. package/src/internal/cron.test.ts +0 -22
  106. package/src/internal/cursor/account-mcp.test.ts +0 -807
  107. package/src/internal/cursor/backend-client.test.ts +0 -591
  108. package/src/internal/cursor/credentials.test.ts +0 -351
  109. package/src/internal/cursor/github-credentials.test.ts +0 -136
  110. package/src/internal/cursor-account-mcp-auth.test.ts +0 -310
  111. package/src/internal/cursor-account.integration.test.ts +0 -441
  112. package/src/internal/cursor-event-relay.test.ts +0 -746
  113. package/src/internal/cursor-github-credentials.integration.test.ts +0 -271
  114. package/src/internal/cursor-slack-relay.test.ts +0 -525
  115. package/src/internal/deploy-source.test.ts +0 -111
  116. package/src/internal/discovery.builtin-tools.test.ts +0 -94
  117. package/src/internal/discovery.concurrency.test.ts +0 -60
  118. package/src/internal/discovery.cursor-account.test.ts +0 -133
  119. package/src/internal/discovery.cwd.test.ts +0 -83
  120. package/src/internal/discovery.hosting.test.ts +0 -80
  121. package/src/internal/discovery.identity.test.ts +0 -44
  122. package/src/internal/docs-site.test.ts +0 -66
  123. package/src/internal/duration.test.ts +0 -29
  124. package/src/internal/eval-judge-model.test.ts +0 -187
  125. package/src/internal/eval-run-store.cancel.test.ts +0 -142
  126. package/src/internal/eval-run-store.storage.test.ts +0 -211
  127. package/src/internal/eval-runner.http.test.ts +0 -403
  128. package/src/internal/eval-runner.run.test.ts +0 -928
  129. package/src/internal/evals-client.test.ts +0 -307
  130. package/src/internal/event-mapper.test.ts +0 -243
  131. package/src/internal/github-fanout.test.ts +0 -213
  132. package/src/internal/handleAgentServeTrigger.test.ts +0 -179
  133. package/src/internal/host-kv.test.ts +0 -82
  134. package/src/internal/host-platforms.test.ts +0 -126
  135. package/src/internal/http-channel.test.ts +0 -402
  136. package/src/internal/init-project.test.ts +0 -270
  137. package/src/internal/install-cursor-skills.test.ts +0 -262
  138. package/src/internal/local-env.test.ts +0 -120
  139. package/src/internal/log-ring.test.ts +0 -31
  140. package/src/internal/logs-client.test.ts +0 -350
  141. package/src/internal/mcp-endpoint.test.ts +0 -436
  142. package/src/internal/mcp-host.test.ts +0 -298
  143. package/src/internal/mcp-oauth.test.ts +0 -148
  144. package/src/internal/net.test.ts +0 -17
  145. package/src/internal/peer-connections.test.ts +0 -128
  146. package/src/internal/peer-mcp.integration.test.ts +0 -289
  147. package/src/internal/playground/toolchain.test.ts +0 -53
  148. package/src/internal/playground-cli.test.ts +0 -187
  149. package/src/internal/playground-proxy.test.ts +0 -376
  150. package/src/internal/prompt-context.integration.test.ts +0 -232
  151. package/src/internal/prompt-context.test.ts +0 -127
  152. package/src/internal/reminder-runner.test.ts +0 -390
  153. package/src/internal/reminder-store.test.ts +0 -53
  154. package/src/internal/request-headers.test.ts +0 -27
  155. package/src/internal/resolve-prod-target.test.ts +0 -787
  156. package/src/internal/resolved-connections.test.ts +0 -295
  157. package/src/internal/router.test.ts +0 -57
  158. package/src/internal/sdk-runner.test.ts +0 -290
  159. package/src/internal/session-engine.coalesce.test.ts +0 -169
  160. package/src/internal/session-engine.concurrency.test.ts +0 -250
  161. package/src/internal/session-engine.host-oauth-mcp.test.ts +0 -110
  162. package/src/internal/session-engine.interrupt.test.ts +0 -577
  163. package/src/internal/session-engine.storage.test.ts +0 -547
  164. package/src/internal/session-urls.test.ts +0 -28
  165. package/src/internal/sessions-client.test.ts +0 -518
  166. package/src/internal/storage-coordinator.test.ts +0 -517
  167. package/src/internal/tool-call.test.ts +0 -458
  168. package/src/internal/tool-result.test.ts +0 -52
  169. package/src/internal/trajectory.approvals.test.ts +0 -83
  170. package/src/internal/trajectory.subagents.test.ts +0 -198
  171. package/src/internal/turn-governor.test.ts +0 -137
  172. package/src/internal/update-check.test.ts +0 -485
  173. package/src/internal/workspace.test.ts +0 -207
  174. 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,390 +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 { 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
- return {
29
- stateRoot,
30
- storage,
31
- host: {
32
- mcp: {} as never,
33
- github: {} as never,
34
- slack: {} as never,
35
- },
36
- sessions: {
37
- findByContinuation: vi.fn(async () => ({
38
- sessionId: "ses_1",
39
- channelId: "drive",
40
- mode: "chat" as const,
41
- auth: null,
42
- continuationKey: "tok",
43
- turnCount: 1,
44
- createdAt: new Date().toISOString(),
45
- updatedAt: new Date().toISOString(),
46
- })),
47
- },
48
- send,
49
- waitForCompletion: async () => ({ status: "completed" as const }),
50
- trackBackground: () => {},
51
- getChannelSession: async () => null,
52
- isTurnRunning: () => false,
53
- } as unknown as SessionEngine;
54
- }
55
-
56
- function memoryStorage(): {
57
- coordinator: StorageCoordinator;
58
- store: Map<string, JsonValue>;
59
- } {
60
- const store = new Map<string, JsonValue>();
61
- const definition = defineStorage({
62
- put: (key, value) => {
63
- store.set(key, value);
64
- },
65
- get: (key) => store.get(key),
66
- delete: (key) => {
67
- store.delete(key);
68
- },
69
- list: (prefix) =>
70
- [...store.entries()]
71
- .filter(([key]) => key.startsWith(prefix))
72
- .sort(([a], [b]) => (a < b ? -1 : 1))
73
- .map(([key, value]) => ({ key, value })),
74
- });
75
- return {
76
- coordinator: new StorageCoordinator({
77
- definition,
78
- agentName: "test-agent",
79
- projectRoot: "/tmp/test-agent",
80
- logger: () => {},
81
- }),
82
- store,
83
- };
84
- }
85
-
86
- describe("ReminderRunner", () => {
87
- let dir: string;
88
-
89
- afterEach(async () => {
90
- if (dir !== undefined) {
91
- await rm(dir, { recursive: true, force: true });
92
- }
93
- });
94
-
95
- it("validates prompt XOR run and schedule shape", async () => {
96
- dir = await mkdtemp(join(tmpdir(), "rem-runner-"));
97
- const runner = new ReminderRunner(mockEngine(dir));
98
- await expect(
99
- runner.create({
100
- purpose: "x",
101
- channelId: "drive",
102
- continuationToken: "tok",
103
- prompt: "hi",
104
- run: async () => ({ action: "skip" }),
105
- delay: "1s",
106
- })
107
- ).rejects.toBeInstanceOf(ReminderValidationError);
108
-
109
- await expect(
110
- runner.create({
111
- purpose: "x",
112
- channelId: "drive",
113
- continuationToken: "tok",
114
- prompt: "hi",
115
- every: "1m",
116
- delay: "1s",
117
- })
118
- ).rejects.toBeInstanceOf(ReminderValidationError);
119
- });
120
-
121
- it("creates one-shot, dispatches, and completes", async () => {
122
- dir = await mkdtemp(join(tmpdir(), "rem-runner-"));
123
- const engine = mockEngine(dir);
124
- const runner = new ReminderRunner(engine);
125
- await runner.start();
126
-
127
- const created = await runner.create({
128
- purpose: "ci_recheck",
129
- channelId: "drive",
130
- continuationToken: "tok",
131
- delay: "1h",
132
- prompt: "check ci",
133
- });
134
- expect(created.status).toBe("armed");
135
- expect(created.hasRunHandler).toBe(false);
136
-
137
- await runner.dispatch(created.id);
138
- const listed = await runner.list();
139
- const done = listed.find((r) => r.id === created.id);
140
- expect(done?.status).toBe("completed");
141
- expect(engine.send).toHaveBeenCalled();
142
- const message = (engine.send as ReturnType<typeof vi.fn>).mock
143
- .calls[0]?.[1];
144
- expect(message).toContain(`id=${created.id}`);
145
- expect(message).toContain("check ci");
146
- });
147
-
148
- it("disarms prompt reminders when the bound session is gone", async () => {
149
- dir = await mkdtemp(join(tmpdir(), "rem-runner-"));
150
- const engine = mockEngine(dir);
151
- (
152
- engine.sessions.findByContinuation as ReturnType<typeof vi.fn>
153
- ).mockResolvedValue(undefined);
154
- const runner = new ReminderRunner(engine);
155
- await runner.start();
156
-
157
- const created = await runner.create({
158
- purpose: "orphan",
159
- channelId: "drive",
160
- continuationToken: "tok",
161
- delay: "1h",
162
- prompt: "should not wake",
163
- });
164
- const result = await runner.dispatch(created.id);
165
- expect(result.outcome).toBe("fired");
166
- expect(result.reason).toBe("session_gone");
167
- const listed = await runner.list();
168
- expect(listed.find((r) => r.id === created.id)?.status).toBe("disarmed");
169
- expect(listed.find((r) => r.id === created.id)?.disarmReason).toBe(
170
- "session_gone"
171
- );
172
- expect(engine.send).not.toHaveBeenCalled();
173
- });
174
-
175
- it("reports noop when dispatching a cancelled reminder", async () => {
176
- dir = await mkdtemp(join(tmpdir(), "rem-runner-"));
177
- const engine = mockEngine(dir);
178
- const runner = new ReminderRunner(engine);
179
- await runner.start();
180
- const created = await runner.create({
181
- purpose: "x",
182
- channelId: "drive",
183
- continuationToken: "tok",
184
- delay: "1h",
185
- prompt: "hi",
186
- });
187
- await runner.cancel(created.id);
188
- const result = await runner.dispatch(created.id);
189
- expect(result).toEqual({
190
- reminderId: created.id,
191
- outcome: "noop",
192
- reason: "not_armed",
193
- });
194
- expect(engine.send).not.toHaveBeenCalled();
195
- });
196
-
197
- it("rejects invalid reschedule.at instead of NaN-looping", async () => {
198
- dir = await mkdtemp(join(tmpdir(), "rem-runner-"));
199
- const engine = mockEngine(dir);
200
- const runner = new ReminderRunner(engine);
201
- await runner.start();
202
- const created = await runner.create({
203
- purpose: "watch",
204
- channelId: "drive",
205
- continuationToken: "tok",
206
- every: "30m",
207
- async run() {
208
- return { action: "skip", reschedule: { at: "not-a-date" } };
209
- },
210
- });
211
- await expect(runner.dispatch(created.id)).rejects.toBeInstanceOf(
212
- ReminderValidationError
213
- );
214
- await runner.cancel(created.id);
215
- });
216
-
217
- it("includes reminder id and cancel guidance only for recurring until prompts", 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
-
223
- const oneshot = await runner.create({
224
- purpose: "once",
225
- channelId: "drive",
226
- continuationToken: "tok",
227
- delay: "1h",
228
- prompt: "one shot body",
229
- until: "Stop when done.",
230
- });
231
- await runner.dispatch(oneshot.id);
232
- const oneshotMsg = (engine.send as ReturnType<typeof vi.fn>).mock
233
- .calls[0]?.[1] as string;
234
- expect(oneshotMsg).toContain(`id=${oneshot.id}`);
235
- expect(oneshotMsg).toContain("one-shot reminder");
236
- expect(oneshotMsg).not.toContain("reminders_cancel");
237
-
238
- (engine.send as ReturnType<typeof vi.fn>).mockClear();
239
- const recurring = await runner.create({
240
- purpose: "loop",
241
- channelId: "drive",
242
- continuationToken: "tok2",
243
- every: "30m",
244
- prompt: "loop body",
245
- until: "Cancel when green.",
246
- });
247
- await runner.dispatch(recurring.id);
248
- const loopMsg = (engine.send as ReturnType<typeof vi.fn>).mock
249
- .calls[0]?.[1] as string;
250
- expect(loopMsg).toContain(`id=${recurring.id}`);
251
- expect(loopMsg).toContain(`reminders_cancel with id=${recurring.id}`);
252
- await runner.cancel(recurring.id);
253
- });
254
-
255
- it("disarms when until function returns true", async () => {
256
- dir = await mkdtemp(join(tmpdir(), "rem-runner-"));
257
- const engine = mockEngine(dir);
258
- const runner = new ReminderRunner(engine);
259
- await runner.start();
260
-
261
- const created = await runner.create({
262
- purpose: "watch",
263
- channelId: "drive",
264
- continuationToken: "tok",
265
- delay: "1h",
266
- until: async () => true,
267
- async run() {
268
- return { action: "delivered" };
269
- },
270
- });
271
- await runner.dispatch(created.id);
272
- const listed = await runner.list();
273
- expect(listed.find((r) => r.id === created.id)?.status).toBe("disarmed");
274
- expect(engine.send).not.toHaveBeenCalled();
275
- });
276
-
277
- it("run handler can skip without waking the session", async () => {
278
- dir = await mkdtemp(join(tmpdir(), "rem-runner-"));
279
- const engine = mockEngine(dir);
280
- const runner = new ReminderRunner(engine);
281
- await runner.start();
282
-
283
- const created = await runner.create({
284
- purpose: "watch",
285
- channelId: "drive",
286
- continuationToken: "tok",
287
- every: "30m",
288
- async run() {
289
- return { action: "skip" };
290
- },
291
- });
292
- await runner.dispatch(created.id);
293
- const listed = await runner.list({ status: "armed" });
294
- expect(listed.some((r) => r.id === created.id)).toBe(true);
295
- expect(engine.send).not.toHaveBeenCalled();
296
- await runner.cancel(created.id);
297
- });
298
-
299
- it("mirrors prompt reminders into defineStorage and hydrates a fresh host", async () => {
300
- const { coordinator, store } = memoryStorage();
301
- dir = await mkdtemp(join(tmpdir(), "rem-runner-"));
302
- const engineA = mockEngine(dir, coordinator);
303
- const runnerA = new ReminderRunner(engineA);
304
- await runnerA.start();
305
- const created = await runnerA.create({
306
- purpose: "ci_recheck",
307
- channelId: "drive",
308
- continuationToken: "tok",
309
- delay: "1h",
310
- prompt: "check ci",
311
- });
312
- await coordinator.whenIdle();
313
- expect(store.size).toBeGreaterThan(0);
314
- runnerA.stop();
315
-
316
- // Fresh state root (replacement host) + same sink.
317
- const dirB = await mkdtemp(join(tmpdir(), "rem-runner-b-"));
318
- try {
319
- const engineB = mockEngine(dirB, coordinator);
320
- const runnerB = new ReminderRunner(engineB);
321
- await runnerB.start();
322
- const listed = await runnerB.list({ status: "armed" });
323
- const rem = listed.find((r) => r.id === created.id);
324
- expect(rem?.purpose).toBe("ci_recheck");
325
- expect(rem?.prompt).toBe("check ci");
326
- expect(rem?.status).toBe("armed");
327
- runnerB.stop();
328
- } finally {
329
- await rm(dirB, { recursive: true, force: true });
330
- }
331
- });
332
-
333
- it("disarms run-handler reminders on restart when handlers are gone", async () => {
334
- dir = await mkdtemp(join(tmpdir(), "rem-runner-"));
335
- const engine = mockEngine(dir);
336
- const runner = new ReminderRunner(engine);
337
- await runner.start();
338
- const created = await runner.create({
339
- purpose: "watch",
340
- channelId: "drive",
341
- continuationToken: "tok",
342
- every: "30m",
343
- async run() {
344
- return { action: "skip" };
345
- },
346
- });
347
- runner.stop();
348
-
349
- const restored = new ReminderRunner(engine);
350
- await restored.start();
351
- const listed = await restored.list();
352
- const rem = listed.find((r) => r.id === created.id);
353
- expect(rem?.status).toBe("disarmed");
354
- expect(rem?.disarmReason).toBe("handler_lost_on_restart");
355
- expect(engine.send).not.toHaveBeenCalled();
356
- });
357
-
358
- it("does not re-arm after cancel during an in-flight fire", async () => {
359
- dir = await mkdtemp(join(tmpdir(), "rem-runner-"));
360
- const engine = mockEngine(dir);
361
- const runner = new ReminderRunner(engine);
362
- await runner.start();
363
-
364
- let releaseRun: (() => void) | undefined;
365
- const runGate = new Promise<void>((resolve) => {
366
- releaseRun = resolve;
367
- });
368
-
369
- const created = await runner.create({
370
- purpose: "watch",
371
- channelId: "drive",
372
- continuationToken: "tok",
373
- every: "30m",
374
- async run() {
375
- await runGate;
376
- return { action: "delivered" };
377
- },
378
- });
379
-
380
- const firePromise = runner.dispatch(created.id);
381
- // Let fire() enter the run handler before cancel.
382
- await new Promise((r) => setTimeout(r, 10));
383
- await runner.cancel(created.id, "pr_closed");
384
- releaseRun?.();
385
- await firePromise;
386
-
387
- const listed = await runner.list();
388
- expect(listed.find((r) => r.id === created.id)?.status).toBe("cancelled");
389
- });
390
- });
@@ -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
- });