Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
82ad879504 | ||
|
|
8d24b5131f | ||
|
|
770946d026 | ||
|
|
8601797233 |
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();
|
||||
});
|
||||
}
|
||||
@@ -18,7 +18,7 @@ function ReleaseNotesLink({
|
||||
}) {
|
||||
return (
|
||||
<button
|
||||
className="ml-2 inline-flex cursor-pointer items-center gap-1 align-baseline text-muted-foreground underline decoration-dotted underline-offset-4 transition-colors hover:text-foreground"
|
||||
className="ml-2 inline cursor-pointer text-muted-foreground underline decoration-dotted underline-offset-4 transition-colors hover:text-foreground"
|
||||
onClick={() => {
|
||||
void (async () => {
|
||||
try {
|
||||
@@ -32,7 +32,11 @@ function ReleaseNotesLink({
|
||||
type="button"
|
||||
>
|
||||
Read more
|
||||
<ArrowRightIcon aria-hidden className="size-3 -rotate-45" strokeWidth={2.25} />
|
||||
<ArrowRightIcon
|
||||
aria-hidden
|
||||
className="ml-1 inline size-3 -rotate-45 align-[-0.125em]"
|
||||
strokeWidth={2.25}
|
||||
/>
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ function TooltipPopup({
|
||||
<TooltipPrimitive.Positioner
|
||||
align={align}
|
||||
anchor={anchor}
|
||||
className="pointer-events-none z-70 h-(--positioner-height) w-(--positioner-width) max-w-(--available-width) transition-[top,left,right,bottom,transform] data-instant:transition-none"
|
||||
className="pointer-events-none z-[140] h-(--positioner-height) w-(--positioner-width) max-w-(--available-width) transition-[top,left,right,bottom,transform] data-instant:transition-none"
|
||||
data-slot="tooltip-positioner"
|
||||
side={side}
|
||||
sideOffset={sideOffset}
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
openPullRequestLink,
|
||||
parseChangeRequestUrl,
|
||||
PullRequestLinkOpenError,
|
||||
shouldOpenPullRequestExternally,
|
||||
} from "./openPullRequestLink";
|
||||
|
||||
describe("openPullRequestLink", () => {
|
||||
@@ -34,6 +35,17 @@ describe("openPullRequestLink", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("shouldOpenPullRequestExternally", () => {
|
||||
it("uses the browser for command-click and control-click", () => {
|
||||
expect(shouldOpenPullRequestExternally({ metaKey: true, ctrlKey: false })).toBe(true);
|
||||
expect(shouldOpenPullRequestExternally({ metaKey: false, ctrlKey: true })).toBe(true);
|
||||
});
|
||||
|
||||
it("keeps an unmodified click in the pull request view", () => {
|
||||
expect(shouldOpenPullRequestExternally({ metaKey: false, ctrlKey: false })).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("parseChangeRequestUrl", () => {
|
||||
it("reads a GitHub pull request", () => {
|
||||
expect(parseChangeRequestUrl("https://github.com/T3Tools/T3Code/pull/123")).toEqual({
|
||||
|
||||
@@ -173,10 +173,19 @@ export function findProjectForChangeRequest(
|
||||
* should still be reading it afterwards. Any change request opens there, not only the thread's
|
||||
* own, since the panel is told which one to show.
|
||||
*/
|
||||
export function shouldOpenPullRequestExternally(
|
||||
event: Pick<MouseEvent<HTMLElement>, "metaKey" | "ctrlKey">,
|
||||
): boolean {
|
||||
return event.metaKey || event.ctrlKey;
|
||||
}
|
||||
|
||||
export function useOpenChangeRequestLink(
|
||||
threadRef?: ScopedThreadRef,
|
||||
): (
|
||||
event: Pick<MouseEvent<HTMLElement>, "preventDefault" | "stopPropagation">,
|
||||
event: Pick<
|
||||
MouseEvent<HTMLElement>,
|
||||
"preventDefault" | "stopPropagation" | "metaKey" | "ctrlKey"
|
||||
>,
|
||||
targetUrl: string,
|
||||
targetThreadRef?: ScopedThreadRef,
|
||||
) => boolean {
|
||||
@@ -186,6 +195,7 @@ export function useOpenChangeRequestLink(
|
||||
const primaryEnvironmentId = usePrimaryEnvironmentId();
|
||||
return useCallback(
|
||||
(event, targetUrl, targetThreadRef) => {
|
||||
if (shouldOpenPullRequestExternally(event)) return false;
|
||||
const resolvedThreadRef = targetThreadRef ?? threadRef;
|
||||
const environmentId = resolvedThreadRef?.environmentId ?? primaryEnvironmentId;
|
||||
if (
|
||||
|
||||
Reference in new issue
Block a user