@cursor/july 0.1.19 → 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/AGENTS.md +10 -0
- 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.CrsWMchO.js → app.jDxLzWv4.js} +1 -1
- package/dist/docs/assets/chunks/@localSearchIndexroot.DoJHJjqF.js +1 -0
- package/dist/docs/assets/chunks/{VPLocalSearchBox.D1JqzSh8.js → VPLocalSearchBox.Y6bDR1-a.js} +1 -1
- package/dist/docs/assets/chunks/{theme.DaBvZYwl.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-C2SU2xV5.js → index-dshZQJCp.js} +46 -46
- 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 +25 -25
- package/skills/create-agent/SKILL.md +36 -4
- package/skills/evals/SKILL.md +3 -0
- package/skills/framework-map/SKILL.md +14 -0
- package/skills/github/SKILL.md +6 -1
- package/skills/hillclimb/SKILL.md +28 -7
- 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.BnHRjfoe.js +0 -1
- package/dist/playground/assets/index-CidizGZv.css +0 -1
|
@@ -0,0 +1,525 @@
|
|
|
1
|
+
import { mkdtemp, readFile, rm } from "node:fs/promises";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
5
|
+
import type { CursorSlackEnvelope } from "../channels/slack/cursor-account.js";
|
|
6
|
+
import { slackChannel } from "../channels/slack/slack-channel.js";
|
|
7
|
+
import { httpChannel } from "../channels.js";
|
|
8
|
+
import type {
|
|
9
|
+
AgentProject,
|
|
10
|
+
AgentServeHandle,
|
|
11
|
+
ChannelDefinition,
|
|
12
|
+
} from "../types.js";
|
|
13
|
+
import { RelayOffsetStore } from "./cursor-event-relay.js";
|
|
14
|
+
import {
|
|
15
|
+
CursorSlackRelay,
|
|
16
|
+
type CursorSlackRelayEvent,
|
|
17
|
+
createCursorSlackApiCaller,
|
|
18
|
+
formatCursorSlackEventLog,
|
|
19
|
+
} from "./cursor-slack-relay.js";
|
|
20
|
+
import type { AgentRunner } from "./sdk-runner.js";
|
|
21
|
+
import { startServer } from "./server.js";
|
|
22
|
+
|
|
23
|
+
interface RecordedRequest {
|
|
24
|
+
method: string;
|
|
25
|
+
url: string;
|
|
26
|
+
body?: unknown;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Minimal fake of the /v0/slack-events surface: records requests and serves
|
|
31
|
+
* a scripted queue of poll responses. Registration echoes the requested
|
|
32
|
+
* agents as subscribed on one workspace.
|
|
33
|
+
*/
|
|
34
|
+
function fakeBackend(script: {
|
|
35
|
+
anchorOffset?: string;
|
|
36
|
+
polls?: Array<{
|
|
37
|
+
events: CursorSlackRelayEvent[];
|
|
38
|
+
nextOffset: string;
|
|
39
|
+
gapDetected?: boolean;
|
|
40
|
+
}>;
|
|
41
|
+
registrationFailures?: number;
|
|
42
|
+
apiResponses?: Record<string, unknown>;
|
|
43
|
+
}) {
|
|
44
|
+
const requests: RecordedRequest[] = [];
|
|
45
|
+
const polls = [...(script.polls ?? [])];
|
|
46
|
+
let registrationFailures = script.registrationFailures ?? 0;
|
|
47
|
+
const fetchImpl: typeof fetch = async (input, init) => {
|
|
48
|
+
const url = String(input);
|
|
49
|
+
const method = init?.method ?? "GET";
|
|
50
|
+
const body =
|
|
51
|
+
typeof init?.body === "string"
|
|
52
|
+
? (JSON.parse(init.body) as unknown)
|
|
53
|
+
: undefined;
|
|
54
|
+
requests.push({ method, url, ...(body === undefined ? {} : { body }) });
|
|
55
|
+
|
|
56
|
+
if (url.includes("/v0/slack-events/subscriptions")) {
|
|
57
|
+
if (registrationFailures > 0) {
|
|
58
|
+
registrationFailures -= 1;
|
|
59
|
+
return new Response("storage unavailable", { status: 503 });
|
|
60
|
+
}
|
|
61
|
+
return jsonResponse({
|
|
62
|
+
workspaces: [{ slackTeamId: "T0TEST", isSubscribed: true }],
|
|
63
|
+
agents: (
|
|
64
|
+
(body as { agents?: Array<{ name: string }> })?.agents ?? []
|
|
65
|
+
).map((agent) => ({ name: agent.name, isSubscribed: true })),
|
|
66
|
+
expiresAt: new Date().toISOString(),
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
if (url.includes("/v0/slack-events/api")) {
|
|
70
|
+
const request = body as { method?: string };
|
|
71
|
+
return jsonResponse(
|
|
72
|
+
script.apiResponses?.[request.method ?? ""] ?? {
|
|
73
|
+
ok: true,
|
|
74
|
+
ts: "999.111",
|
|
75
|
+
}
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
if (url.includes("after=%24") || url.includes("after=$")) {
|
|
79
|
+
return jsonResponse({
|
|
80
|
+
events: [],
|
|
81
|
+
nextOffset: script.anchorOffset ?? "",
|
|
82
|
+
gapDetected: false,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
const page = polls.shift() ?? {
|
|
86
|
+
events: [],
|
|
87
|
+
nextOffset: "",
|
|
88
|
+
gapDetected: false,
|
|
89
|
+
};
|
|
90
|
+
return jsonResponse(page);
|
|
91
|
+
};
|
|
92
|
+
return { requests, fetchImpl };
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function jsonResponse(body: unknown): Response {
|
|
96
|
+
return new Response(JSON.stringify(body), {
|
|
97
|
+
status: 200,
|
|
98
|
+
headers: { "content-type": "application/json" },
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function envelope(
|
|
103
|
+
offset: string,
|
|
104
|
+
overrides: Partial<CursorSlackEnvelope> = {}
|
|
105
|
+
): CursorSlackRelayEvent {
|
|
106
|
+
return {
|
|
107
|
+
offset,
|
|
108
|
+
eventName: "app_mention",
|
|
109
|
+
slackTeamId: "T0TEST",
|
|
110
|
+
channelId: "C0100",
|
|
111
|
+
channelType: "channel",
|
|
112
|
+
threadTs: "111.222",
|
|
113
|
+
messageTs: "111.222",
|
|
114
|
+
slackUserId: "U0AAA",
|
|
115
|
+
text: "what's the weather?",
|
|
116
|
+
agentName: "Benny",
|
|
117
|
+
consumerId: "consumer-under-test",
|
|
118
|
+
matchedBy: "name",
|
|
119
|
+
eventId: `Ev${offset}`,
|
|
120
|
+
receivedAtMs: Date.now(),
|
|
121
|
+
...overrides,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
async function waitFor(
|
|
126
|
+
predicate: () => boolean,
|
|
127
|
+
timeoutMs = 2_000
|
|
128
|
+
): Promise<void> {
|
|
129
|
+
const deadline = Date.now() + timeoutMs;
|
|
130
|
+
while (!predicate()) {
|
|
131
|
+
if (Date.now() > deadline) {
|
|
132
|
+
throw new Error("waitFor timed out");
|
|
133
|
+
}
|
|
134
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
describe("formatCursorSlackEventLog", () => {
|
|
139
|
+
it("names the agent, match kind, and thread", () => {
|
|
140
|
+
expect(
|
|
141
|
+
formatCursorSlackEventLog({
|
|
142
|
+
eventName: "app_mention",
|
|
143
|
+
agentName: "Benny",
|
|
144
|
+
matchedBy: "name",
|
|
145
|
+
channelId: "C0100",
|
|
146
|
+
threadTs: "111.222",
|
|
147
|
+
receivedAtMs: Date.parse("2026-07-14T16:00:00.000Z"),
|
|
148
|
+
eventId: "Ev1",
|
|
149
|
+
})
|
|
150
|
+
).toBe(
|
|
151
|
+
"app_mention → Benny (name) in C0100/111.222 received=2026-07-14T16:00:00.000Z (Ev1)"
|
|
152
|
+
);
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
describe("createCursorSlackApiCaller", () => {
|
|
157
|
+
it("POSTs the method, args, agent name, and consumer id; returns the body", async () => {
|
|
158
|
+
const backend = fakeBackend({
|
|
159
|
+
apiResponses: { "chat.postMessage": { ok: true, ts: "123.456" } },
|
|
160
|
+
});
|
|
161
|
+
const call = createCursorSlackApiCaller({
|
|
162
|
+
baseUrl: "https://api2.example/",
|
|
163
|
+
apiKey: "key_1",
|
|
164
|
+
agentName: "Benny",
|
|
165
|
+
consumerId: "consumer-1",
|
|
166
|
+
fetchImpl: backend.fetchImpl,
|
|
167
|
+
});
|
|
168
|
+
const result = await call("chat.postMessage", {
|
|
169
|
+
channel: "C0100",
|
|
170
|
+
markdown_text: "hi",
|
|
171
|
+
thread_ts: "111.222",
|
|
172
|
+
});
|
|
173
|
+
expect(result).toEqual({ ok: true, ts: "123.456" });
|
|
174
|
+
expect(backend.requests).toHaveLength(1);
|
|
175
|
+
expect(backend.requests[0]).toMatchObject({
|
|
176
|
+
method: "POST",
|
|
177
|
+
url: "https://api2.example/v0/slack-events/api",
|
|
178
|
+
body: {
|
|
179
|
+
method: "chat.postMessage",
|
|
180
|
+
arguments: {
|
|
181
|
+
channel: "C0100",
|
|
182
|
+
markdown_text: "hi",
|
|
183
|
+
thread_ts: "111.222",
|
|
184
|
+
},
|
|
185
|
+
agentName: "Benny",
|
|
186
|
+
consumerId: "consumer-1",
|
|
187
|
+
},
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it("soft-fails Slack-style when the backend is unreachable", async () => {
|
|
192
|
+
const call = createCursorSlackApiCaller({
|
|
193
|
+
baseUrl: "https://api2.example",
|
|
194
|
+
apiKey: "key_1",
|
|
195
|
+
agentName: "Benny",
|
|
196
|
+
consumerId: "consumer-1",
|
|
197
|
+
fetchImpl: async () => {
|
|
198
|
+
throw new Error("ECONNREFUSED");
|
|
199
|
+
},
|
|
200
|
+
});
|
|
201
|
+
expect(await call("chat.postMessage", {})).toEqual({
|
|
202
|
+
ok: false,
|
|
203
|
+
error: "cursor_backend_unreachable",
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
describe("CursorSlackRelay", () => {
|
|
209
|
+
let dir: string;
|
|
210
|
+
let relay: CursorSlackRelay | undefined;
|
|
211
|
+
|
|
212
|
+
afterEach(async () => {
|
|
213
|
+
await relay?.stop();
|
|
214
|
+
relay = undefined;
|
|
215
|
+
if (dir !== undefined) {
|
|
216
|
+
await rm(dir, { recursive: true, force: true });
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
async function makeRelay(
|
|
221
|
+
backend: ReturnType<typeof fakeBackend>,
|
|
222
|
+
options?: {
|
|
223
|
+
dispatch?: (e: CursorSlackRelayEvent) => Promise<void>;
|
|
224
|
+
logger?: (line: string) => void;
|
|
225
|
+
agents?: Array<{ name: string; iconEmoji?: string }>;
|
|
226
|
+
}
|
|
227
|
+
): Promise<{ dispatched: CursorSlackRelayEvent[]; consumerId: string }> {
|
|
228
|
+
const dispatched: CursorSlackRelayEvent[] = [];
|
|
229
|
+
relay = new CursorSlackRelay({
|
|
230
|
+
baseUrl: "https://api2.example",
|
|
231
|
+
apiKey: "key",
|
|
232
|
+
agents: options?.agents ?? [{ name: "Benny", iconEmoji: ":robot:" }],
|
|
233
|
+
stateDir: dir,
|
|
234
|
+
dispatch:
|
|
235
|
+
options?.dispatch ??
|
|
236
|
+
(async (e) => {
|
|
237
|
+
dispatched.push(e);
|
|
238
|
+
}),
|
|
239
|
+
logger: options?.logger ?? (() => {}),
|
|
240
|
+
fetchImpl: backend.fetchImpl,
|
|
241
|
+
pollWaitMs: 0,
|
|
242
|
+
});
|
|
243
|
+
const consumerId = await relay.resolveConsumerId();
|
|
244
|
+
relay.start();
|
|
245
|
+
return { dispatched, consumerId };
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
it("registers before consuming, anchors, dispatches in order, persists offset + consumer id", async () => {
|
|
249
|
+
dir = await mkdtemp(join(tmpdir(), "cursor-slack-"));
|
|
250
|
+
const store = new RelayOffsetStore(dir);
|
|
251
|
+
const backendProbe = fakeBackend({});
|
|
252
|
+
// Resolve the consumer id first so the scripted poll can carry it.
|
|
253
|
+
const probe = new CursorSlackRelay({
|
|
254
|
+
baseUrl: "https://api2.example",
|
|
255
|
+
apiKey: "key",
|
|
256
|
+
agents: [{ name: "Benny" }],
|
|
257
|
+
stateDir: dir,
|
|
258
|
+
dispatch: async () => {},
|
|
259
|
+
logger: () => {},
|
|
260
|
+
fetchImpl: backendProbe.fetchImpl,
|
|
261
|
+
});
|
|
262
|
+
const consumerId = await probe.resolveConsumerId();
|
|
263
|
+
|
|
264
|
+
const backend = fakeBackend({
|
|
265
|
+
anchorOffset: "100-0",
|
|
266
|
+
polls: [
|
|
267
|
+
{
|
|
268
|
+
events: [
|
|
269
|
+
envelope("101-0", { consumerId }),
|
|
270
|
+
envelope("102-0", {
|
|
271
|
+
consumerId,
|
|
272
|
+
eventName: "message",
|
|
273
|
+
matchedBy: "thread",
|
|
274
|
+
messageTs: "111.333",
|
|
275
|
+
}),
|
|
276
|
+
],
|
|
277
|
+
nextOffset: "102-0",
|
|
278
|
+
},
|
|
279
|
+
],
|
|
280
|
+
});
|
|
281
|
+
const { dispatched } = await makeRelay(backend);
|
|
282
|
+
|
|
283
|
+
await waitFor(() => dispatched.length === 2);
|
|
284
|
+
expect(dispatched.map((e) => e.eventName)).toEqual([
|
|
285
|
+
"app_mention",
|
|
286
|
+
"message",
|
|
287
|
+
]);
|
|
288
|
+
await waitFor(() =>
|
|
289
|
+
backend.requests.some((r) => r.url.includes("after=102-0"))
|
|
290
|
+
);
|
|
291
|
+
await relay?.stop();
|
|
292
|
+
relay = undefined;
|
|
293
|
+
|
|
294
|
+
expect(await store.load()).toBe("102-0");
|
|
295
|
+
|
|
296
|
+
// Consumption is registration-gated: the first request is the PUT.
|
|
297
|
+
expect(backend.requests[0]?.method).toBe("PUT");
|
|
298
|
+
expect(backend.requests[0]?.body).toMatchObject({
|
|
299
|
+
consumerId,
|
|
300
|
+
agents: [{ name: "Benny", iconEmoji: ":robot:" }],
|
|
301
|
+
});
|
|
302
|
+
expect((await readFile(join(dir, "consumer-id"), "utf8")).trim()).toBe(
|
|
303
|
+
consumerId
|
|
304
|
+
);
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
it("skips sibling consumers' events and unknown agents but advances the offset", async () => {
|
|
308
|
+
dir = await mkdtemp(join(tmpdir(), "cursor-slack-"));
|
|
309
|
+
const probeBackend = fakeBackend({});
|
|
310
|
+
const probe = new CursorSlackRelay({
|
|
311
|
+
baseUrl: "https://api2.example",
|
|
312
|
+
apiKey: "key",
|
|
313
|
+
agents: [{ name: "Benny" }],
|
|
314
|
+
stateDir: dir,
|
|
315
|
+
dispatch: async () => {},
|
|
316
|
+
logger: () => {},
|
|
317
|
+
fetchImpl: probeBackend.fetchImpl,
|
|
318
|
+
});
|
|
319
|
+
const consumerId = await probe.resolveConsumerId();
|
|
320
|
+
|
|
321
|
+
const backend = fakeBackend({
|
|
322
|
+
anchorOffset: "0-1",
|
|
323
|
+
polls: [
|
|
324
|
+
{
|
|
325
|
+
events: [
|
|
326
|
+
// Another host (consumer) on the same principal stream.
|
|
327
|
+
envelope("1-0", { consumerId: "other-host" }),
|
|
328
|
+
// Our consumer id but an agent we did not register.
|
|
329
|
+
envelope("2-0", { consumerId, agentName: "Stranger" }),
|
|
330
|
+
// Ours.
|
|
331
|
+
envelope("3-0", { consumerId }),
|
|
332
|
+
],
|
|
333
|
+
nextOffset: "3-0",
|
|
334
|
+
},
|
|
335
|
+
],
|
|
336
|
+
});
|
|
337
|
+
const { dispatched } = await makeRelay(backend);
|
|
338
|
+
|
|
339
|
+
await waitFor(() => dispatched.length === 1);
|
|
340
|
+
expect(dispatched[0]?.offset).toBe("3-0");
|
|
341
|
+
await relay?.stop();
|
|
342
|
+
relay = undefined;
|
|
343
|
+
const store = new RelayOffsetStore(dir);
|
|
344
|
+
expect(await store.load()).toBe("3-0");
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
it("deregisters its agents on clean stop", async () => {
|
|
348
|
+
dir = await mkdtemp(join(tmpdir(), "cursor-slack-"));
|
|
349
|
+
const backend = fakeBackend({ anchorOffset: "1-0" });
|
|
350
|
+
const { consumerId } = await makeRelay(backend);
|
|
351
|
+
await waitFor(() => backend.requests.some((r) => r.method === "GET"));
|
|
352
|
+
|
|
353
|
+
await relay?.stop();
|
|
354
|
+
relay = undefined;
|
|
355
|
+
|
|
356
|
+
const lastPut = backend.requests.filter((r) => r.method === "PUT").at(-1);
|
|
357
|
+
expect(lastPut?.body).toEqual({ consumerId, agents: [] });
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
it("retries registration until it succeeds before any consumption", async () => {
|
|
361
|
+
dir = await mkdtemp(join(tmpdir(), "cursor-slack-"));
|
|
362
|
+
const probeBackend = fakeBackend({});
|
|
363
|
+
const probe = new CursorSlackRelay({
|
|
364
|
+
baseUrl: "https://api2.example",
|
|
365
|
+
apiKey: "key",
|
|
366
|
+
agents: [{ name: "Benny" }],
|
|
367
|
+
stateDir: dir,
|
|
368
|
+
dispatch: async () => {},
|
|
369
|
+
logger: () => {},
|
|
370
|
+
fetchImpl: probeBackend.fetchImpl,
|
|
371
|
+
});
|
|
372
|
+
const consumerId = await probe.resolveConsumerId();
|
|
373
|
+
const backend = fakeBackend({
|
|
374
|
+
anchorOffset: "10-0",
|
|
375
|
+
polls: [
|
|
376
|
+
{ events: [envelope("11-0", { consumerId })], nextOffset: "11-0" },
|
|
377
|
+
],
|
|
378
|
+
registrationFailures: 1,
|
|
379
|
+
});
|
|
380
|
+
const { dispatched } = await makeRelay(backend);
|
|
381
|
+
|
|
382
|
+
await waitFor(() => dispatched.length === 1, 10_000);
|
|
383
|
+
const firstGetIndex = backend.requests.findIndex((r) => r.method === "GET");
|
|
384
|
+
const successfulPutIndex = backend.requests.findIndex(
|
|
385
|
+
(r, index) => r.method === "PUT" && index > 0
|
|
386
|
+
);
|
|
387
|
+
expect(successfulPutIndex).toBeGreaterThan(0);
|
|
388
|
+
expect(firstGetIndex).toBeGreaterThan(successfulPutIndex);
|
|
389
|
+
});
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
describe("serve with cursor-account Slack channels", () => {
|
|
393
|
+
const savedEnv: Record<string, string | undefined> = {};
|
|
394
|
+
let stateRoot: string | undefined;
|
|
395
|
+
let handle: AgentServeHandle | undefined;
|
|
396
|
+
|
|
397
|
+
const runner: AgentRunner = {
|
|
398
|
+
async runTurn() {
|
|
399
|
+
return { status: "finished", result: "unused" };
|
|
400
|
+
},
|
|
401
|
+
};
|
|
402
|
+
|
|
403
|
+
function fixture(): AgentProject {
|
|
404
|
+
return {
|
|
405
|
+
rootDir: "/tmp/cursor-slack-fixture",
|
|
406
|
+
agentDir: "/tmp/cursor-slack-fixture/agent",
|
|
407
|
+
name: "slack-fixture",
|
|
408
|
+
agent: {
|
|
409
|
+
name: "slack-fixture",
|
|
410
|
+
runtime: "local",
|
|
411
|
+
tools: [],
|
|
412
|
+
skills: [],
|
|
413
|
+
connections: [],
|
|
414
|
+
subagents: [],
|
|
415
|
+
seedFiles: [],
|
|
416
|
+
},
|
|
417
|
+
httpChannel: httpChannel(),
|
|
418
|
+
channels: [
|
|
419
|
+
{
|
|
420
|
+
id: "slack",
|
|
421
|
+
// Same erasure discovery performs when loading authored channels.
|
|
422
|
+
definition: slackChannel({
|
|
423
|
+
cursorAccount: true,
|
|
424
|
+
agentName: "Benny",
|
|
425
|
+
}) as unknown as ChannelDefinition,
|
|
426
|
+
},
|
|
427
|
+
],
|
|
428
|
+
schedules: [],
|
|
429
|
+
hooks: [],
|
|
430
|
+
abs: [],
|
|
431
|
+
diagnostics: [],
|
|
432
|
+
};
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
beforeEach(() => {
|
|
436
|
+
for (const key of [
|
|
437
|
+
"CURSOR_API_KEY",
|
|
438
|
+
"CURSOR_API_BASE_URL",
|
|
439
|
+
"AGENT_SERVE_CONFIG_DIR",
|
|
440
|
+
]) {
|
|
441
|
+
savedEnv[key] = process.env[key];
|
|
442
|
+
delete process.env[key];
|
|
443
|
+
}
|
|
444
|
+
// No stored login can leak in from the developer's machine.
|
|
445
|
+
process.env.AGENT_SERVE_CONFIG_DIR = "/nonexistent-agent-serve-config";
|
|
446
|
+
});
|
|
447
|
+
|
|
448
|
+
afterEach(async () => {
|
|
449
|
+
await handle?.close();
|
|
450
|
+
handle = undefined;
|
|
451
|
+
if (stateRoot !== undefined) {
|
|
452
|
+
await rm(stateRoot, { recursive: true, force: true });
|
|
453
|
+
stateRoot = undefined;
|
|
454
|
+
}
|
|
455
|
+
for (const [key, value] of Object.entries(savedEnv)) {
|
|
456
|
+
if (value === undefined) {
|
|
457
|
+
delete process.env[key];
|
|
458
|
+
} else {
|
|
459
|
+
process.env[key] = value;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
it("refuses to serve when the host is not signed in to Cursor", async () => {
|
|
465
|
+
const root = await mkdtemp(join(tmpdir(), "agent-serve-cursor-slack-"));
|
|
466
|
+
stateRoot = root;
|
|
467
|
+
await expect(
|
|
468
|
+
startServer([{ slug: "", project: fixture() }], {
|
|
469
|
+
port: 0,
|
|
470
|
+
stateRoot: root,
|
|
471
|
+
playground: false,
|
|
472
|
+
runner,
|
|
473
|
+
})
|
|
474
|
+
).rejects.toThrow(
|
|
475
|
+
/cursorAccount: true[\s\S]*signed in to Cursor[\s\S]*agentkit login/
|
|
476
|
+
);
|
|
477
|
+
});
|
|
478
|
+
|
|
479
|
+
it("starts the relay when a credential is present", async () => {
|
|
480
|
+
const root = await mkdtemp(join(tmpdir(), "agent-serve-cursor-slack-"));
|
|
481
|
+
stateRoot = root;
|
|
482
|
+
process.env.CURSOR_API_KEY = "crsr_env";
|
|
483
|
+
// Point at a closed local port so the background relay fails fast and
|
|
484
|
+
// hermetically instead of reaching the real backend.
|
|
485
|
+
process.env.CURSOR_API_BASE_URL = "http://127.0.0.1:9";
|
|
486
|
+
const logs: string[] = [];
|
|
487
|
+
handle = await startServer([{ slug: "", project: fixture() }], {
|
|
488
|
+
port: 0,
|
|
489
|
+
stateRoot: root,
|
|
490
|
+
playground: false,
|
|
491
|
+
runner,
|
|
492
|
+
logger: (line) => logs.push(line),
|
|
493
|
+
});
|
|
494
|
+
expect(
|
|
495
|
+
logs.some(
|
|
496
|
+
(line) =>
|
|
497
|
+
line.includes("cursor-slack: relaying Slack for") &&
|
|
498
|
+
line.includes("Benny")
|
|
499
|
+
)
|
|
500
|
+
).toBe(true);
|
|
501
|
+
});
|
|
502
|
+
|
|
503
|
+
it("rejects duplicate registered agent names across mounts", async () => {
|
|
504
|
+
const root = await mkdtemp(join(tmpdir(), "agent-serve-cursor-slack-"));
|
|
505
|
+
stateRoot = root;
|
|
506
|
+
process.env.CURSOR_API_KEY = "crsr_env";
|
|
507
|
+
process.env.CURSOR_API_BASE_URL = "http://127.0.0.1:9";
|
|
508
|
+
const projectA = fixture();
|
|
509
|
+
const projectB = fixture();
|
|
510
|
+
await expect(
|
|
511
|
+
startServer(
|
|
512
|
+
[
|
|
513
|
+
{ slug: "a", project: projectA },
|
|
514
|
+
{ slug: "b", project: projectB },
|
|
515
|
+
],
|
|
516
|
+
{
|
|
517
|
+
port: 0,
|
|
518
|
+
stateRoot: root,
|
|
519
|
+
playground: false,
|
|
520
|
+
runner,
|
|
521
|
+
}
|
|
522
|
+
)
|
|
523
|
+
).rejects.toThrow(/register the Slack name "Benny"/);
|
|
524
|
+
});
|
|
525
|
+
});
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
agentPathRelativeToGitRoot,
|
|
4
|
+
type GitRunner,
|
|
5
|
+
httpsGitRepoUrlFromRemote,
|
|
6
|
+
inferDeployGitSource,
|
|
7
|
+
} from "./deploy-source.js";
|
|
8
|
+
|
|
9
|
+
describe("httpsGitRepoUrlFromRemote", () => {
|
|
10
|
+
it("normalizes https, ssh, and git@ remotes", () => {
|
|
11
|
+
expect(
|
|
12
|
+
httpsGitRepoUrlFromRemote("https://github.com/acme/agents.git")
|
|
13
|
+
).toBe("https://github.com/acme/agents");
|
|
14
|
+
expect(httpsGitRepoUrlFromRemote("git@github.com:acme/agents.git")).toBe(
|
|
15
|
+
"https://github.com/acme/agents"
|
|
16
|
+
);
|
|
17
|
+
expect(
|
|
18
|
+
httpsGitRepoUrlFromRemote("ssh://git@github.com/acme/agents.git")
|
|
19
|
+
).toBe("https://github.com/acme/agents");
|
|
20
|
+
expect(
|
|
21
|
+
httpsGitRepoUrlFromRemote("ssh://git@github.com:22/acme/agents.git")
|
|
22
|
+
).toBe("https://github.com/acme/agents");
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("normalizes GitHub org-scoped SSH remotes (org-NNNN@github.com:…)", () => {
|
|
26
|
+
expect(
|
|
27
|
+
httpsGitRepoUrlFromRemote(
|
|
28
|
+
"org-96667180@github.com:anysphere/everysphere.git"
|
|
29
|
+
)
|
|
30
|
+
).toBe("https://github.com/anysphere/everysphere");
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("rejects unusable remotes", () => {
|
|
34
|
+
expect(httpsGitRepoUrlFromRemote("")).toBeUndefined();
|
|
35
|
+
expect(httpsGitRepoUrlFromRemote("not-a-url")).toBeUndefined();
|
|
36
|
+
expect(httpsGitRepoUrlFromRemote("https://github.com/")).toBeUndefined();
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
describe("agentPathRelativeToGitRoot", () => {
|
|
41
|
+
it("returns a posix-relative path for nested dirs and omits the root", () => {
|
|
42
|
+
expect(
|
|
43
|
+
agentPathRelativeToGitRoot(
|
|
44
|
+
"/repo/packages/agent-serve/examples/approval-buddy",
|
|
45
|
+
"/repo"
|
|
46
|
+
)
|
|
47
|
+
).toBe("packages/agent-serve/examples/approval-buddy");
|
|
48
|
+
expect(agentPathRelativeToGitRoot("/repo", "/repo")).toBeUndefined();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("returns undefined when dir is outside the repo", () => {
|
|
52
|
+
expect(
|
|
53
|
+
agentPathRelativeToGitRoot("/elsewhere/agent", "/repo")
|
|
54
|
+
).toBeUndefined();
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
describe("inferDeployGitSource", () => {
|
|
59
|
+
it("assembles repo, ref, and path from git probes", async () => {
|
|
60
|
+
const git: GitRunner = async (args) => {
|
|
61
|
+
const key = args.join(" ");
|
|
62
|
+
switch (key) {
|
|
63
|
+
case "rev-parse --show-toplevel":
|
|
64
|
+
return "/repo";
|
|
65
|
+
case "remote get-url origin":
|
|
66
|
+
return "git@github.com:acme/agents.git";
|
|
67
|
+
case "rev-parse --abbrev-ref HEAD":
|
|
68
|
+
return "main";
|
|
69
|
+
default:
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
await expect(
|
|
74
|
+
inferDeployGitSource("/repo/examples/weather-agent", { git })
|
|
75
|
+
).resolves.toEqual({
|
|
76
|
+
gitRepoUrl: "https://github.com/acme/agents",
|
|
77
|
+
gitRef: "main",
|
|
78
|
+
agentPath: "examples/weather-agent",
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("pins a detached HEAD to the commit SHA", async () => {
|
|
83
|
+
const git: GitRunner = async (args) => {
|
|
84
|
+
const key = args.join(" ");
|
|
85
|
+
switch (key) {
|
|
86
|
+
case "rev-parse --show-toplevel":
|
|
87
|
+
return "/repo";
|
|
88
|
+
case "remote get-url origin":
|
|
89
|
+
return "https://github.com/acme/agents.git";
|
|
90
|
+
case "rev-parse --abbrev-ref HEAD":
|
|
91
|
+
return "HEAD";
|
|
92
|
+
case "rev-parse HEAD":
|
|
93
|
+
return "abcdef0123456789";
|
|
94
|
+
default:
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
await expect(inferDeployGitSource("/repo", { git })).resolves.toEqual({
|
|
99
|
+
gitRepoUrl: "https://github.com/acme/agents",
|
|
100
|
+
gitRef: "abcdef0123456789",
|
|
101
|
+
agentPath: undefined,
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it("returns empty when not inside a git checkout", async () => {
|
|
106
|
+
const git: GitRunner = async () => undefined;
|
|
107
|
+
await expect(inferDeployGitSource("/tmp/agent", { git })).resolves.toEqual(
|
|
108
|
+
{}
|
|
109
|
+
);
|
|
110
|
+
});
|
|
111
|
+
});
|