Skip to content

Commit 67e092e

Browse files
Merge branch 'main' into factory/pr-33944-a2
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2 parents 7572fc5 + 7d51718 commit 67e092e

8 files changed

Lines changed: 462 additions & 10 deletions

File tree

‎apps/server/src/workspace/WorkspaceSearchIndex.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ it.effect.skipIf(HostProcess.Platform.defaultValue() === "win32")(
135135

136136
expect(result.entries).toEqual([{ kind: "file", path: "dir\\one/report.txt" }]);
137137
}),
138-
),
138+
).pipe(Effect.provide(testLayer)),
139139
);
140140

141141
it.effect("continues whole-word searches after a filtered grep page", () =>

‎apps/server/src/workspace/WorkspaceSearchIndex.ts‎

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ function withDirectoryAncestors(entries: ReadonlyArray<ProjectEntry>): ProjectEn
294294
const listGitIgnoredPaths = Effect.fn("WorkspaceSearchIndex.listGitIgnoredPaths")(function* (
295295
vcsProcess: VcsProcess.VcsProcess["Service"],
296296
cwd: string,
297+
hostIsWindows: boolean,
297298
) {
298299
const result = yield* vcsProcess
299300
.run({
@@ -320,17 +321,23 @@ const listGitIgnoredPaths = Effect.fn("WorkspaceSearchIndex.listGitIgnoredPaths"
320321
result.stdout
321322
.split("\0")
322323
.filter((entry) => entry.length > 0)
323-
.map((entry) => trimDirectorySeparator(toPosixPath(entry))),
324+
.map((entry) => trimDirectorySeparator(toPosixPath(entry, hostIsWindows))),
324325
);
325326
});
326327

327328
function mixedItemPath(item: MixedItem): string {
328329
return item.item.relativePath;
329330
}
330331

331-
function isIgnoredPath(ignoredPaths: ReadonlySet<string>, relativePath: string): boolean {
332+
function isIgnoredPath(
333+
ignoredPaths: ReadonlySet<string>,
334+
relativePath: string,
335+
hostIsWindows: boolean,
336+
): boolean {
332337
if (ignoredPaths.size === 0) return false;
333-
let candidate: string | undefined = trimDirectorySeparator(toPosixPath(relativePath));
338+
let candidate: string | undefined = trimDirectorySeparator(
339+
toPosixPath(relativePath, hostIsWindows),
340+
);
334341
while (candidate) {
335342
if (ignoredPaths.has(candidate)) return true;
336343
candidate = parentPathOf(candidate);
@@ -402,7 +409,7 @@ export const make = Effect.fn("WorkspaceSearchIndex.make")(function* (
402409
);
403410
let initialScanTimedOut = false;
404411
const vcsProcess = yield* VcsProcess.VcsProcess;
405-
let ignoredPaths = yield* listGitIgnoredPaths(vcsProcess, cwd);
412+
let ignoredPaths = yield* listGitIgnoredPaths(vcsProcess, cwd, hostIsWindows);
406413
yield* waitForIndexReady(
407414
cwd,
408415
finder,
@@ -466,7 +473,9 @@ export const make = Effect.fn("WorkspaceSearchIndex.make")(function* (
466473
const fetchSize = size;
467474
const result = yield* runSearch(query, fetchSize, operation, () => execute(fetchSize));
468475
if (ignoredPaths.size === 0) return result;
469-
const items = result.items.filter((item) => !isIgnoredPath(ignoredPaths, pathOf(item)));
476+
const items = result.items.filter(
477+
(item) => !isIgnoredPath(ignoredPaths, pathOf(item), hostIsWindows),
478+
);
470479
if (
471480
items.length >= pageSize ||
472481
result.items.length >= result.totalMatched ||
@@ -512,7 +521,7 @@ export const make = Effect.fn("WorkspaceSearchIndex.make")(function* (
512521
cause,
513522
}),
514523
).pipe(Effect.catchTags({ WorkspaceSearchIndexScanTimedOut: () => Effect.void }));
515-
ignoredPaths = yield* listGitIgnoredPaths(vcsProcess, cwd);
524+
ignoredPaths = yield* listGitIgnoredPaths(vcsProcess, cwd, hostIsWindows);
516525
});
517526

518527
const list: WorkspaceSearchIndex["Service"]["list"] = Effect.fn("WorkspaceSearchIndex.list")(
@@ -625,7 +634,7 @@ export const make = Effect.fn("WorkspaceSearchIndex.make")(function* (
625634
}
626635

627636
for (const match of result.items) {
628-
if (isIgnoredPath(ignoredPaths, match.relativePath)) continue;
637+
if (isIgnoredPath(ignoredPaths, match.relativePath, hostIsWindows)) continue;
629638
const matchRanges = mapContentMatchRanges(match.lineContent, match.matchRanges).filter(
630639
(range) => !input.wholeWord || isWholeWordRange(match.lineContent, range),
631640
);

‎apps/server/vite.config.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ export default mergeConfig(
115115
},
116116
}
117117
: {}),
118+
// jsonc-parser's UMD main requires its own files at runtime, which the bundle cannot follow.
119+
alias: { "jsonc-parser": "jsonc-parser/lib/esm/main.js" },
118120
deps: {
119121
// alwaysBundle=false has no opinion; neverBundle must retain transitive native acceleration.
120122
alwaysBundle: shouldBundleCliDependency,

‎packages/provider-cursor/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"@t3tools/provider-core": "workspace:*",
5151
"@t3tools/shared": "workspace:*",
5252
"effect": "catalog:",
53+
"jsonc-parser": "3.3.1",
5354
"yaml": "catalog:"
5455
},
5556
"devDependencies": {

‎packages/provider-cursor/src/server/adapter.test.ts‎

Lines changed: 235 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,17 @@ import * as DateTime from "effect/DateTime";
2121
import * as Deferred from "effect/Deferred";
2222
import * as Effect from "effect/Effect";
2323
import * as Exit from "effect/Exit";
24+
import * as ChildProcess from "effect/process/ChildProcess";
25+
import { spawnAndCollect } from "@t3tools/provider-core/server/snapshotProbe";
26+
import * as HostProcess from "@t3tools/shared/HostProcess";
2427
import * as FileSystem from "effect/FileSystem";
2528
import * as Layer from "effect/Layer";
2629
import * as Option from "effect/Option";
2730
import * as Path from "effect/Path";
2831
import * as Stream from "effect/Stream";
2932
import { vi } from "vite-plus/test";
3033

34+
import { symlinksSupported } from "@t3tools/shared/testing/symlinks";
3135
import * as TestProviderHost from "@t3tools/provider-testing/TestProviderHost";
3236
import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator";
3337
import * as McpProviderSessions from "@t3tools/provider-core/server/McpProviderSessions";
@@ -42,6 +46,7 @@ import {
4246
} from "./adapter.ts";
4347
import * as CursorAgentSdk from "./CursorAgentSdk.ts";
4448
import { loadCursorSdk } from "./sdk.ts";
49+
import { cursorWorkspaceMcpServers } from "./workspaceMcpServers.ts";
4550

4651
// The SDK reads CURSOR_BACKEND_URL once when it loads, before any test body runs.
4752
const cursorBackendUrl = await vi.hoisted(async () => {
@@ -2034,6 +2039,236 @@ describe("CursorAdapterV2", () => {
20342039
assert.notInclude(logged, "secret-cursor-mcp-token");
20352040
});
20362041

2042+
it.effect.skipIf(!symlinksSupported)(
2043+
"starts mcp.json servers that use Cursor's workspace variables",
2044+
() =>
2045+
Effect.gen(function* () {
2046+
const fileSystem = yield* FileSystem.FileSystem;
2047+
const path = yield* Path.Path;
2048+
const scratch = yield* fileSystem.realPath(
2049+
yield* fileSystem.makeTempDirectoryScoped({ prefix: "cursor-v2-mcp-" }),
2050+
);
2051+
const workspace = path.join(scratch, "workspace");
2052+
const home = path.join(scratch, "home");
2053+
const loadServers = () =>
2054+
cursorWorkspaceMcpServers(cwd, { MCP_TYPE: "stdio" }).pipe(
2055+
Effect.provideService(HostProcess.HomeDirectory, home),
2056+
Effect.provideService(HostProcess.Environment, {}),
2057+
);
2058+
// Cursor resolves the project root through symlinks, as git does.
2059+
yield* fileSystem.makeDirectory(path.join(workspace, "packages", "app"), {
2060+
recursive: true,
2061+
});
2062+
yield* fileSystem.symlink(workspace, path.join(scratch, "link"));
2063+
const cwd = path.join(scratch, "link", "packages", "app");
2064+
yield* spawnAndCollect("git", ChildProcess.make("git", ["init", workspace]));
2065+
// Git prints forward slashes on Windows, and the loader passes its spelling through.
2066+
const projectRoot = (yield* spawnAndCollect(
2067+
"git",
2068+
ChildProcess.make("git", ["rev-parse", "--show-toplevel"], { cwd }),
2069+
)).stdout.trim();
2070+
yield* fileSystem.makeDirectory(path.join(workspace, ".cursor"), { recursive: true });
2071+
yield* fileSystem.makeDirectory(path.join(home, ".cursor"), { recursive: true });
2072+
yield* fileSystem.writeFileString(
2073+
path.join(workspace, ".cursor", "mcp.json"),
2074+
`{
2075+
// Cursor's editor accepts comments here.
2076+
"mcpServers": {
2077+
"repro": { "command": "node", "args": ["\${workspaceFolder}/server.mjs"], "startupTimeoutSec": 120 },
2078+
"plain": { "command": "node", "args": ["server.mjs"] },
2079+
"argument-only": { "command": "node", "args": ["server.mjs", "--workspace", "\${workspaceFolder}"] },
2080+
"env-only": { "command": "node", "args": ["server.mjs"], "env": { "PROJECT_ROOT": "\${workspaceFolder}" } },
2081+
"cwd-only": { "command": "node", "args": ["server.mjs"], "cwd": "\${workspaceFolder}" },
2082+
"unset-env": { "command": "node", "env": { "CONFIG": "\${env:T3_MCP_UNSET}" } },
2083+
"wrapped": { "command": "proto", "args": ["run", "node", "--", "\${workspaceFolder}/server.mjs"] },
2084+
"label": { "command": "node", "args": ["server.mjs", "--label", "\${workspaceFolder}/client"] },
2085+
"env-file": { "command": "node", "args": ["\${workspaceFolder}/server.mjs"], "envFile": ".env.mcp" },
2086+
"tool-filter": { "command": "node", "args": ["\${workspaceFolder}/server.mjs"], "enabledTools": ["read_file"] },
2087+
"off": { "command": "node", "args": ["\${workspaceFolder}/off.mjs"] },
2088+
"typed": { "type": "\${env:MCP_TYPE}", "command": "node", "args": ["server.mjs"] },
2089+
"plugin-docs-search": { "command": "node", "args": ["\${workspaceFolder}/search.mjs"] },
2090+
},
2091+
}`,
2092+
);
2093+
yield* fileSystem.writeFileString(
2094+
path.join(home, ".cursor", "mcp.json"),
2095+
JSON.stringify({
2096+
mcpServers: {
2097+
repro: { command: "node", args: ["${userHome}/shadowed.mjs"] },
2098+
docs: {
2099+
url: "https://docs.example/${workspaceFolderBasename}",
2100+
headers: { Authorization: "Bearer ${env:DOCS_TOKEN}" },
2101+
tls: { caBundle: "${userHome}/ca.pem" },
2102+
},
2103+
},
2104+
}),
2105+
);
2106+
// Cursor keeps per-project state under a directory named after the project path.
2107+
const projectDirectory = workspace.replace(/[^a-zA-Z0-9]+/g, "-").replace(/^-|-$/g, "");
2108+
yield* fileSystem.makeDirectory(path.join(home, ".cursor", "projects", projectDirectory), {
2109+
recursive: true,
2110+
});
2111+
yield* fileSystem.writeFileString(
2112+
path.join(home, ".cursor", "projects", projectDirectory, "mcp-disabled.json"),
2113+
JSON.stringify(["off"]),
2114+
);
2115+
2116+
const instanceId = ProviderInstanceId.make("cursor");
2117+
const threadId = ThreadId.make("cursor-mcp-thread");
2118+
const mcpSessions = yield* McpProviderSessions.McpProviderSessions;
2119+
yield* mcpSessions.set({
2120+
environmentId: EnvironmentId.make("cursor-mcp-environment"),
2121+
threadId,
2122+
providerSessionId: "cursor-mcp-session",
2123+
providerInstanceId: instanceId,
2124+
endpoint: "http://127.0.0.1:43123/mcp",
2125+
authorizationHeader: "Bearer synthetic-cursor-token",
2126+
browserToolsAvailable: false,
2127+
});
2128+
const t3Servers = cursorMcpServers(yield* mcpSessions.read(threadId));
2129+
const modelSelection = { instanceId, model: "composer-2.5" };
2130+
const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({
2131+
runtimeMode: "full-access",
2132+
interactionMode: "default",
2133+
cwd,
2134+
});
2135+
let openedWith: CursorAgentSdk.CursorAgentSdkOpenInput["options"] | undefined;
2136+
const sentWith: Array<Record<string, unknown> | undefined> = [];
2137+
const adapter = yield* makeCursorAdapterV2({
2138+
instanceId,
2139+
environment: {
2140+
HOME: path.join(scratch, "override"),
2141+
CURSOR_DATA_DIR: path.join(scratch, "override"),
2142+
DOCS_TOKEN: "docs-token",
2143+
MCP_TYPE: "stdio",
2144+
},
2145+
}).pipe(
2146+
Effect.provideService(CursorAgentSdk.CursorAgentSdkRunner, {
2147+
assertComplete: Effect.void,
2148+
open: (input) =>
2149+
Effect.sync(() => {
2150+
openedWith = input.options;
2151+
return {
2152+
agentId: "native-cursor-mcp",
2153+
listMessages: Effect.succeed([]),
2154+
close: Effect.void,
2155+
send: (sendInput) => {
2156+
sentWith.push(sendInput.options?.mcpServers);
2157+
return Effect.die("sent");
2158+
},
2159+
};
2160+
}),
2161+
}),
2162+
Effect.provide(TestProviderHost.layer({ cwd })),
2163+
);
2164+
const runtime = yield* adapter.openSession({
2165+
threadId,
2166+
providerSessionId: ProviderSessionId.make("cursor-mcp-session"),
2167+
modelSelection,
2168+
runtimePolicy,
2169+
});
2170+
const providerThread = yield* runtime
2171+
.ensureThread({ threadId, modelSelection, runtimePolicy })
2172+
.pipe(
2173+
Effect.provideService(HostProcess.HomeDirectory, home),
2174+
Effect.provideService(HostProcess.Environment, {}),
2175+
);
2176+
const now = yield* DateTime.now;
2177+
const sendTurn = (ordinal: number) =>
2178+
runtime
2179+
.startTurn({
2180+
threadId,
2181+
providerThread,
2182+
modelSelection,
2183+
runtimePolicy,
2184+
runId: RunId.make(`cursor-mcp-run-${ordinal}`),
2185+
runOrdinal: ordinal,
2186+
providerTurnOrdinal: ordinal,
2187+
attemptId: RunAttemptId.make(`cursor-mcp-attempt-${ordinal}`),
2188+
rootNodeId: NodeId.make(`cursor-mcp-root-${ordinal}`),
2189+
appThread: {
2190+
id: threadId,
2191+
projectId: ProjectId.make("cursor-mcp-project"),
2192+
createdBy: "user",
2193+
creationSource: "web",
2194+
title: "Cursor MCP",
2195+
providerInstanceId: instanceId,
2196+
modelSelection,
2197+
runtimeMode: "full-access",
2198+
interactionMode: "default",
2199+
branch: null,
2200+
worktreePath: null,
2201+
activeProviderThreadId: providerThread.id,
2202+
lineage: {
2203+
parentThreadId: null,
2204+
relationshipToParent: null,
2205+
rootThreadId: threadId,
2206+
},
2207+
forkedFrom: null,
2208+
createdAt: now,
2209+
updatedAt: now,
2210+
archivedAt: null,
2211+
settledOverride: null,
2212+
settledAt: null,
2213+
lastVisitedAt: null,
2214+
deletedAt: null,
2215+
},
2216+
message: {
2217+
messageId: MessageId.make(`cursor-mcp-message-${ordinal}`),
2218+
createdBy: "user",
2219+
creationSource: "web",
2220+
text: "Hello.",
2221+
attachments: [],
2222+
},
2223+
})
2224+
.pipe(
2225+
Effect.exit,
2226+
Effect.provideService(HostProcess.HomeDirectory, home),
2227+
Effect.provideService(HostProcess.Environment, {}),
2228+
);
2229+
2230+
const expectedServers = {
2231+
repro: {
2232+
command: "node",
2233+
args: [`${projectRoot}/server.mjs`],
2234+
startupTimeoutSec: 120,
2235+
cwd: projectRoot,
2236+
},
2237+
"cwd-only": { command: "node", args: ["server.mjs"], cwd: projectRoot },
2238+
};
2239+
// The agent is created with T3's server only; the resolved servers go with each turn.
2240+
assert.deepEqual(openedWith?.mcpServers, t3Servers);
2241+
yield* sendTurn(1);
2242+
assert.deepEqual(sentWith[0], { ...expectedServers, ...t3Servers });
2243+
// A server switched off between turns stays off on the next one.
2244+
yield* fileSystem.writeFileString(
2245+
path.join(home, ".cursor", "projects", projectDirectory, "mcp-disabled.json"),
2246+
JSON.stringify(["off", "repro"]),
2247+
);
2248+
yield* sendTurn(2);
2249+
const { repro: _disabled, ...stillEnabled } = expectedServers;
2250+
assert.deepEqual(sentWith[1], { ...stillEnabled, ...t3Servers });
2251+
// Unreadable disabled state starts none of the overrides, and the turn still goes out.
2252+
yield* fileSystem.writeFileString(
2253+
path.join(home, ".cursor", "projects", projectDirectory, "mcp-disabled.json"),
2254+
"[",
2255+
);
2256+
yield* sendTurn(3);
2257+
assert.deepEqual(sentWith[2], t3Servers);
2258+
yield* fileSystem.writeFileString(
2259+
path.join(workspace, ".cursor", "mcp.json"),
2260+
JSON.stringify({ mcpServers: { plain: { command: "node", args: ["server.mjs"] } } }),
2261+
);
2262+
yield* fileSystem.remove(path.join(home, ".cursor", "mcp.json"));
2263+
assert.deepEqual(yield* loadServers(), {});
2264+
}).pipe(
2265+
Effect.scoped,
2266+
Effect.provide(
2267+
Layer.mergeAll(NodeServices.layer, IdAllocator.layer, McpProviderSessions.layer),
2268+
),
2269+
),
2270+
);
2271+
20372272
it("recognizes direct and SDK-wrapped abort failures as cancellation", () => {
20382273
assert.isTrue(CursorAgentSdk.isCursorCancellationError({ name: "AbortError" }));
20392274
assert.isTrue(

0 commit comments

Comments
 (0)