@cursor/july 0.1.20 → 0.1.21
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.
- package/dist/bin/agent-serve.js +0 -0
- package/dist/channels/github/instrument.d.ts +20 -0
- package/dist/channels/github/instrument.d.ts.map +1 -0
- package/dist/channels/slack/api.d.ts +2 -0
- package/dist/channels/slack/api.d.ts.map +1 -1
- package/dist/channels/slack/api.js +3 -0
- package/dist/channels/slack/bot-mentions.d.ts +106 -0
- package/dist/channels/slack/bot-mentions.d.ts.map +1 -0
- package/dist/channels/slack/bot-mentions.js +243 -0
- package/dist/channels/slack/dispatch.d.ts +6 -0
- package/dist/channels/slack/dispatch.d.ts.map +1 -1
- package/dist/channels/slack/dispatch.js +24 -3
- package/dist/channels/slack/inbound.d.ts +10 -1
- package/dist/channels/slack/inbound.d.ts.map +1 -1
- package/dist/channels/slack/inbound.js +12 -4
- package/dist/channels/slack/index.d.ts +1 -0
- package/dist/channels/slack/index.d.ts.map +1 -1
- package/dist/channels/slack/index.js +1 -0
- package/dist/channels/slack/slack-channel.d.ts.map +1 -1
- package/dist/channels/slack/slack-channel.js +61 -22
- package/dist/channels/slack/types.d.ts +58 -0
- package/dist/channels/slack/types.d.ts.map +1 -1
- package/dist/docs/404.html +1 -1
- package/dist/docs/ab.html +2 -2
- package/dist/docs/assets/{app.T-5ImnM3.js → app.jDxLzWv4.js} +1 -1
- package/dist/docs/assets/chunks/@localSearchIndexroot.DoJHJjqF.js +1 -0
- package/dist/docs/assets/chunks/{VPLocalSearchBox.OMGMWH6H.js → VPLocalSearchBox.Y6bDR1-a.js} +1 -1
- package/dist/docs/assets/chunks/{theme.DLg4yB4D.js → theme.CLazCWlJ.js} +2 -2
- package/dist/docs/building-with-agents.html +2 -2
- package/dist/docs/concepts.html +2 -2
- package/dist/docs/deployment.html +2 -2
- package/dist/docs/evals.html +2 -2
- package/dist/docs/example-agents/approval-buddy.html +2 -2
- package/dist/docs/example-agents/benny.html +2 -2
- package/dist/docs/example-agents/bugbot.html +2 -2
- package/dist/docs/example-agents/codebase-wiki.html +2 -2
- package/dist/docs/example-agents/codeowners-review.html +2 -2
- package/dist/docs/example-agents/concierge.html +2 -2
- package/dist/docs/example-agents/fsd.html +2 -2
- package/dist/docs/example-agents/index.html +2 -2
- package/dist/docs/example-agents/knowledge-base.html +2 -2
- package/dist/docs/example-agents/oncall.html +2 -2
- package/dist/docs/example-agents/security-reviewer.html +2 -2
- package/dist/docs/example-agents/slack-agent.html +2 -2
- package/dist/docs/example-agents/weather-agent.html +2 -2
- package/dist/docs/guides/agent-to-agent.html +2 -2
- package/dist/docs/guides/cloud-runtime.html +2 -2
- package/dist/docs/guides/github.html +2 -2
- package/dist/docs/guides/human-in-the-loop.html +2 -2
- package/dist/docs/guides/mcp-oauth.html +2 -2
- package/dist/docs/guides/slack.html +2 -2
- package/dist/docs/guides/webhooks.html +2 -2
- package/dist/docs/hillclimbing.html +2 -2
- package/dist/docs/index.html +2 -2
- package/dist/docs/quickstart.html +2 -2
- package/dist/docs/reference/agent-config.html +2 -2
- package/dist/docs/reference/channels.html +2 -2
- package/dist/docs/reference/cli.html +2 -2
- package/dist/docs/reference/connections.html +2 -2
- package/dist/docs/reference/hooks.html +2 -2
- package/dist/docs/reference/http-api.html +2 -2
- package/dist/docs/reference/instructions.html +2 -2
- package/dist/docs/reference/playground.html +2 -2
- package/dist/docs/reference/project-layout.html +2 -2
- package/dist/docs/reference/prompt.html +2 -2
- package/dist/docs/reference/schedules.html +2 -2
- package/dist/docs/reference/sessions.html +2 -2
- package/dist/docs/reference/skills.html +2 -2
- package/dist/docs/reference/subagents.html +2 -2
- package/dist/docs/reference/tools.html +2 -2
- package/dist/docs/scaffolding-agents.html +2 -2
- package/dist/docs/storage.html +2 -2
- package/dist/docs/troubleshooting.html +2 -2
- package/dist/internal/json-dir-store.d.ts +32 -0
- package/dist/internal/json-dir-store.d.ts.map +1 -0
- package/dist/internal/json-dir-store.js +100 -0
- package/dist/internal/resolved-connections.d.ts +1 -1
- package/dist/internal/resolved-connections.d.ts.map +1 -1
- package/dist/internal/resolved-connections.js +10 -0
- package/dist/internal/session-engine.d.ts +4 -1
- package/dist/internal/session-engine.d.ts.map +1 -1
- package/dist/internal/session-engine.js +13 -2
- package/dist/playground/assets/index-CjOQ4hN9.css +1 -0
- package/dist/playground/assets/index-dshZQJCp.js +85 -0
- package/dist/playground/index.html +2 -2
- package/dist/types.d.ts +7 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +9 -0
- package/package.json +24 -24
- package/src/bin/agent-serve.version.test.ts +62 -0
- package/src/channels/github/api.test.ts +64 -0
- package/src/channels/github/auth.test.ts +105 -0
- package/src/channels/github/cursor-account.test.ts +204 -0
- package/src/channels/github/forward.test.ts +457 -0
- package/src/channels/github/github.test.ts +937 -0
- package/src/channels/github/replay.test.ts +179 -0
- package/src/channels/slack/api.post-message.test.ts +148 -0
- package/src/channels/slack/api.ts +5 -0
- package/src/channels/slack/approvals.test.ts +328 -0
- package/src/channels/slack/block-actions.test.ts +452 -0
- package/src/channels/slack/bot-mentions.test.ts +217 -0
- package/src/channels/slack/bot-mentions.ts +315 -0
- package/src/channels/slack/channel-watch.test.ts +363 -0
- package/src/channels/slack/cursor-account.test.ts +253 -0
- package/src/channels/slack/defaults.final-post.test.ts +182 -0
- package/src/channels/slack/dispatch.test.ts +795 -0
- package/src/channels/slack/dispatch.ts +27 -1
- package/src/channels/slack/eval-directive.test.ts +273 -0
- package/src/channels/slack/inbound.ts +25 -4
- package/src/channels/slack/index.ts +1 -0
- package/src/channels/slack/message-body.test.ts +54 -0
- package/src/channels/slack/nudge-store.test.ts +143 -0
- package/src/channels/slack/slack-channel.ts +66 -8
- package/src/channels/slack/slack.test.ts +391 -0
- package/src/channels/slack/stop.test.ts +23 -0
- package/src/channels/slack/thread-context.test.ts +202 -0
- package/src/channels/slack/types.ts +60 -0
- package/src/evals/assertions.test.ts +580 -0
- package/src/evals/expect.test.ts +144 -0
- package/src/evals/judge.test.ts +181 -0
- package/src/evals/loaders.test.ts +132 -0
- package/src/evals/matchers.test.ts +95 -0
- package/src/evals/reporters.test.ts +303 -0
- package/src/evals/run-facts.test.ts +259 -0
- package/src/internal/ab-snapshot.test.ts +325 -0
- package/src/internal/approval-gate.test.ts +49 -0
- package/src/internal/approvals.integration.test.ts +383 -0
- package/src/internal/authored-loaders.test.ts +31 -0
- package/src/internal/builtin-tools/reminders.test.ts +201 -0
- package/src/internal/channel-route-schema.test.ts +294 -0
- package/src/internal/chat-attach.test.ts +262 -0
- package/src/internal/cli-deploy.test.ts +1991 -0
- package/src/internal/cli-mcp.test.ts +789 -0
- package/src/internal/cli-skills.test.ts +133 -0
- package/src/internal/cli-slack.test.ts +1647 -0
- package/src/internal/cloud-merge.test.ts +74 -0
- package/src/internal/cron.test.ts +22 -0
- package/src/internal/cursor/account-mcp.test.ts +807 -0
- package/src/internal/cursor/backend-client.test.ts +591 -0
- package/src/internal/cursor/credentials.test.ts +351 -0
- package/src/internal/cursor/github-credentials.test.ts +136 -0
- package/src/internal/cursor-account-mcp-auth.test.ts +310 -0
- package/src/internal/cursor-account.integration.test.ts +441 -0
- package/src/internal/cursor-event-relay.test.ts +746 -0
- package/src/internal/cursor-github-credentials.integration.test.ts +271 -0
- package/src/internal/cursor-slack-relay.test.ts +525 -0
- package/src/internal/deploy-source.test.ts +111 -0
- package/src/internal/discovery.builtin-tools.test.ts +94 -0
- package/src/internal/discovery.concurrency.test.ts +60 -0
- package/src/internal/discovery.cursor-account.test.ts +133 -0
- package/src/internal/discovery.cwd.test.ts +83 -0
- package/src/internal/discovery.hosting.test.ts +80 -0
- package/src/internal/discovery.identity.test.ts +44 -0
- package/src/internal/docs-site.test.ts +66 -0
- package/src/internal/duration.test.ts +29 -0
- package/src/internal/eval-judge-model.test.ts +187 -0
- package/src/internal/eval-run-store.cancel.test.ts +142 -0
- package/src/internal/eval-run-store.storage.test.ts +211 -0
- package/src/internal/eval-runner.http.test.ts +403 -0
- package/src/internal/eval-runner.run.test.ts +928 -0
- package/src/internal/evals-client.test.ts +307 -0
- package/src/internal/event-mapper.test.ts +243 -0
- package/src/internal/github-fanout.test.ts +213 -0
- package/src/internal/handleAgentServeTrigger.test.ts +179 -0
- package/src/internal/host-kv.test.ts +82 -0
- package/src/internal/host-platforms.test.ts +126 -0
- package/src/internal/http-channel.test.ts +402 -0
- package/src/internal/init-project.test.ts +269 -0
- package/src/internal/install-cursor-skills.test.ts +262 -0
- package/src/internal/local-env.test.ts +100 -0
- package/src/internal/log-ring.test.ts +31 -0
- package/src/internal/logs-client.test.ts +350 -0
- package/src/internal/mcp-endpoint.test.ts +436 -0
- package/src/internal/mcp-host.test.ts +298 -0
- package/src/internal/mcp-oauth.test.ts +148 -0
- package/src/internal/net.test.ts +17 -0
- package/src/internal/peer-connections.test.ts +128 -0
- package/src/internal/peer-mcp.integration.test.ts +289 -0
- package/src/internal/playground/toolchain.test.ts +53 -0
- package/src/internal/playground-cli.test.ts +187 -0
- package/src/internal/playground-proxy.test.ts +376 -0
- package/src/internal/prompt-context.integration.test.ts +232 -0
- package/src/internal/prompt-context.test.ts +127 -0
- package/src/internal/reminder-runner.test.ts +390 -0
- package/src/internal/reminder-store.test.ts +53 -0
- package/src/internal/request-headers.test.ts +27 -0
- package/src/internal/resolve-prod-target.test.ts +787 -0
- package/src/internal/resolved-connections.test.ts +295 -0
- package/src/internal/resolved-connections.ts +18 -1
- package/src/internal/router.test.ts +57 -0
- package/src/internal/sdk-runner.test.ts +290 -0
- package/src/internal/session-engine.coalesce.test.ts +169 -0
- package/src/internal/session-engine.concurrency.test.ts +250 -0
- package/src/internal/session-engine.host-oauth-mcp.test.ts +110 -0
- package/src/internal/session-engine.interrupt.test.ts +577 -0
- package/src/internal/session-engine.storage.test.ts +547 -0
- package/src/internal/session-engine.ts +15 -1
- package/src/internal/session-urls.test.ts +28 -0
- package/src/internal/sessions-client.test.ts +518 -0
- package/src/internal/storage-coordinator.test.ts +517 -0
- package/src/internal/tool-call.test.ts +458 -0
- package/src/internal/tool-result.test.ts +52 -0
- package/src/internal/trajectory.approvals.test.ts +83 -0
- package/src/internal/trajectory.subagents.test.ts +198 -0
- package/src/internal/turn-governor.test.ts +137 -0
- package/src/internal/update-check.test.ts +485 -0
- package/src/internal/workspace.test.ts +81 -0
- package/src/storage-backends/cursor-hosted.test.ts +121 -0
- package/src/types.ts +12 -0
- package/dist/docs/assets/chunks/@localSearchIndexroot.CvejISXF.js +0 -1
- package/dist/playground/assets/index-CidizGZv.css +0 -1
- package/dist/playground/assets/index-CuiAKZaP.js +0 -85
|
@@ -0,0 +1,127 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,390 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
});
|