Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
82ad879504 |
No files matched your search
@@ -12,6 +12,7 @@ import {
|
||||
resolveCursorAcpConfigUpdates,
|
||||
} from "../Layers/CursorProvider.ts";
|
||||
import * as AcpSessionRuntime from "./AcpSessionRuntime.ts";
|
||||
import { discoverCursorPluginDirectories } from "./CursorMcpServers.ts";
|
||||
|
||||
type CursorAcpRuntimeCursorSettings = Pick<CursorSettings, "apiEndpoint" | "binaryPath">;
|
||||
|
||||
@@ -46,6 +47,20 @@ export function buildCursorAcpSpawnInput(
|
||||
};
|
||||
}
|
||||
|
||||
export function addCursorPluginDirectories(
|
||||
spawn: AcpSessionRuntime.AcpSpawnInput,
|
||||
pluginDirectories: ReadonlyArray<string>,
|
||||
): AcpSessionRuntime.AcpSpawnInput {
|
||||
return {
|
||||
...spawn,
|
||||
args: [
|
||||
...spawn.args.slice(0, -1),
|
||||
...pluginDirectories.flatMap((path) => ["--plugin-dir", path]),
|
||||
...spawn.args.slice(-1),
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
export const makeCursorAcpRuntime = (
|
||||
input: CursorAcpRuntimeInput,
|
||||
): Effect.Effect<
|
||||
@@ -54,10 +69,14 @@ export const makeCursorAcpRuntime = (
|
||||
Crypto.Crypto | Scope.Scope
|
||||
> =>
|
||||
Effect.gen(function* () {
|
||||
const pluginDirectories = yield* discoverCursorPluginDirectories(
|
||||
input.environment === undefined ? {} : { environment: input.environment },
|
||||
);
|
||||
const spawn = buildCursorAcpSpawnInput(input.cursorSettings, input.cwd, input.environment);
|
||||
const acpContext = yield* Layer.build(
|
||||
AcpSessionRuntime.layer({
|
||||
...input,
|
||||
spawn: buildCursorAcpSpawnInput(input.cursorSettings, input.cwd, input.environment),
|
||||
spawn: addCursorPluginDirectories(spawn, pluginDirectories),
|
||||
authMethodId: "cursor_login",
|
||||
clientCapabilities: CURSOR_PARAMETERIZED_MODEL_PICKER_CAPABILITIES,
|
||||
}).pipe(
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
// @effect-diagnostics nodeBuiltinImport:off
|
||||
import * as NodeFSP from "node:fs/promises";
|
||||
import * as NodePath from "node:path";
|
||||
|
||||
import { describe, expect, it } from "@effect/vitest";
|
||||
import * as Effect from "effect/Effect";
|
||||
|
||||
import { addCursorPluginDirectories, buildCursorAcpSpawnInput } from "./CursorAcpSupport.ts";
|
||||
import { discoverCursorPluginDirectories } from "./CursorMcpServers.ts";
|
||||
|
||||
const writePlugin = Effect.fn("writePlugin")(function* (pluginsRoot: string, slug: string) {
|
||||
const pluginRoot = NodePath.join(pluginsRoot, slug, "hash");
|
||||
yield* Effect.promise(() =>
|
||||
NodeFSP.mkdir(NodePath.join(pluginRoot, ".cursor-plugin"), { recursive: true }),
|
||||
);
|
||||
yield* Effect.promise(() =>
|
||||
NodeFSP.writeFile(
|
||||
NodePath.join(pluginRoot, ".cursor-plugin", "plugin.json"),
|
||||
`{"name":"${slug}"}`,
|
||||
),
|
||||
);
|
||||
yield* Effect.promise(() =>
|
||||
NodeFSP.writeFile(NodePath.join(pluginRoot, "mcp.json"), '{"mcpServers":{}}'),
|
||||
);
|
||||
return pluginRoot;
|
||||
});
|
||||
|
||||
describe("discoverCursorPluginDirectories", () => {
|
||||
it.effect("returns cached Cursor plugins that provide MCP servers", () =>
|
||||
Effect.gen(function* () {
|
||||
const temp = yield* Effect.acquireRelease(
|
||||
Effect.promise(() => NodeFSP.mkdtemp("/tmp/t3-cursor-mcp-")),
|
||||
(path) => Effect.promise(() => NodeFSP.rm(path, { recursive: true, force: true })),
|
||||
);
|
||||
const pluginsRoot = NodePath.join(temp, "plugins", "cache", "cursor-public");
|
||||
const paperRoot = yield* writePlugin(pluginsRoot, "paper-desktop");
|
||||
const noMcpRoot = NodePath.join(pluginsRoot, "no-mcp", "hash");
|
||||
yield* Effect.promise(() =>
|
||||
NodeFSP.mkdir(NodePath.join(noMcpRoot, ".cursor-plugin"), { recursive: true }),
|
||||
);
|
||||
yield* Effect.promise(() =>
|
||||
NodeFSP.writeFile(
|
||||
NodePath.join(noMcpRoot, ".cursor-plugin", "plugin.json"),
|
||||
'{"name":"no-mcp"}',
|
||||
),
|
||||
);
|
||||
|
||||
const directories = yield* discoverCursorPluginDirectories({ pluginsRoot });
|
||||
|
||||
expect(directories).toEqual([paperRoot]);
|
||||
|
||||
const spawn = buildCursorAcpSpawnInput(null, "/workspace");
|
||||
expect(addCursorPluginDirectories(spawn, directories).args).toEqual([
|
||||
"--plugin-dir",
|
||||
paperRoot,
|
||||
"acp",
|
||||
]);
|
||||
}).pipe(Effect.scoped),
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,46 @@
|
||||
// @effect-diagnostics nodeBuiltinImport:off
|
||||
import * as NodeFS from "node:fs";
|
||||
import * as NodePath from "node:path";
|
||||
|
||||
import { Effect } from "effect";
|
||||
|
||||
interface DiscoverCursorPluginDirectoriesOptions {
|
||||
readonly environment?: NodeJS.ProcessEnv;
|
||||
readonly homeDirectory?: string;
|
||||
readonly pluginsRoot?: string;
|
||||
}
|
||||
|
||||
function resolveHome(environment: NodeJS.ProcessEnv, explicit: string | undefined): string {
|
||||
return explicit ?? environment.HOME ?? environment.USERPROFILE ?? "";
|
||||
}
|
||||
|
||||
/** Finds cached Cursor plugins that declare MCP servers. */
|
||||
export function discoverCursorPluginDirectories(
|
||||
options: DiscoverCursorPluginDirectoriesOptions = {},
|
||||
): Effect.Effect<ReadonlyArray<string>> {
|
||||
return Effect.sync(() => {
|
||||
const environment = options.environment ?? process.env;
|
||||
const homeDirectory = resolveHome(environment, options.homeDirectory);
|
||||
const pluginsRoot =
|
||||
options.pluginsRoot ??
|
||||
NodePath.join(homeDirectory, ".cursor", "plugins", "cache", "cursor-public");
|
||||
if (!NodeFS.existsSync(pluginsRoot)) return [];
|
||||
|
||||
const directories: string[] = [];
|
||||
for (const slug of NodeFS.readdirSync(pluginsRoot, { withFileTypes: true })) {
|
||||
if (!slug.isDirectory()) continue;
|
||||
const slugRoot = NodePath.join(pluginsRoot, slug.name);
|
||||
for (const version of NodeFS.readdirSync(slugRoot, { withFileTypes: true })) {
|
||||
if (!version.isDirectory()) continue;
|
||||
const pluginRoot = NodePath.join(slugRoot, version.name);
|
||||
if (
|
||||
NodeFS.existsSync(NodePath.join(pluginRoot, "mcp.json")) ||
|
||||
NodeFS.existsSync(NodePath.join(pluginRoot, ".mcp.json"))
|
||||
) {
|
||||
directories.push(pluginRoot);
|
||||
}
|
||||
}
|
||||
}
|
||||
return directories.sort();
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user