TypeScript
fix(provider-cursor): start default Cursor threads on Windows (#20046)
fabiocolor19e06dc87583
diff --git a/apps/server/src/orchestration-v2/Adapters/CursorAdapterV2.testkit.ts b/apps/server/src/orchestration-v2/Adapters/CursorAdapterV2.testkit.tsindex 72d8ddac9da..e9c256624c4 100644--- a/apps/server/src/orchestration-v2/Adapters/CursorAdapterV2.testkit.ts+++ b/apps/server/src/orchestration-v2/Adapters/CursorAdapterV2.testkit.ts@@ -711,6 +711,7 @@ export const recordCursorAgentSdkReplayTranscript = Effect.fn(}),threadId,mcpSession: undefined,+ platform: yield* HostProcess.Platform,});const sendOptions = {model: cursorSdkModelSelection(input.modelSelection),diff --git a/docs/user/cursor.md b/docs/user/cursor.mdindex 5fc20811da6..3def8de7c02 100644--- a/docs/user/cursor.md+++ b/docs/user/cursor.md@@ -60,9 +60,12 @@ a provider thread to native task projections or advertise subagent thread IDs. Aread-only: send messages from the parent thread.Runtime modes map to the controls the local SDK exposes: full access disables its sandbox, while-restricted modes and explicit non-full-access sandbox policies enable it. Explicit approval policy-overrides also control Cursor Auto-review. Auto-review is not represented as an interactive T3 Code-approval flow.+restricted modes normally enable it. On Windows, Auto and Supervised run without filesystem+isolation when Cursor Auto-review is enabled, because the SDK does not support a filesystem sandbox+there. Restricted modes without Auto-review, including the default Auto-accept edits mode, still+request the sandbox and cannot start on Windows. Explicit sandbox policies remain authoritative,+including restrictive policies that the Windows SDK rejects. Explicit approval policy overrides+control Auto-review, which is not represented as an interactive T3 Code approval flow.The existing Cursor binary path and API endpoint settings belong to the CLI/ACP integration. CursorV2 execution does not launch that binary, and the SDK does not expose an API endpoint override.diff --git a/packages/provider-cursor/src/server/adapter.test.ts b/packages/provider-cursor/src/server/adapter.test.tsindex 8aecb9f92df..38d8d977b24 100644--- a/packages/provider-cursor/src/server/adapter.test.ts+++ b/packages/provider-cursor/src/server/adapter.test.ts@@ -22,6 +22,7 @@ import * as Path from "effect/Path";import * as Schema from "effect/Schema";import * as Stream from "effect/Stream";+import * as HostProcess from "@t3tools/shared/HostProcess";import * as TestProviderHost from "@t3tools/provider-testing/TestProviderHost";import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator";import * as McpProviderSessions from "@t3tools/provider-core/server/McpProviderSessions";@@ -1066,71 +1067,195 @@ describe("CursorAdapterV2", () => {cwd: "/tmp/cursor-adapter",};assert.deepEqual(- cursorRuntimeAgentPolicy({- ...base,- runtimeMode: "full-access",- }),+ cursorRuntimeAgentPolicy(+ {+ ...base,+ runtimeMode: "full-access",+ },+ "linux",+ ),{autoReview: false,sandboxEnabled: false,},);assert.deepEqual(- cursorRuntimeAgentPolicy({- ...base,- runtimeMode: "auto-accept-edits",- }),+ cursorRuntimeAgentPolicy(+ {+ ...base,+ runtimeMode: "auto-accept-edits",+ },+ "linux",+ ),{autoReview: false,sandboxEnabled: true,},);assert.deepEqual(- cursorRuntimeAgentPolicy({- ...base,- runtimeMode: "auto",- }),+ cursorRuntimeAgentPolicy(+ {+ ...base,+ runtimeMode: "auto",+ },+ "linux",+ ),{autoReview: true,sandboxEnabled: true,},);assert.deepEqual(- cursorRuntimeAgentPolicy({- ...base,- runtimeMode: "approval-required",- }),+ cursorRuntimeAgentPolicy(+ {+ ...base,+ runtimeMode: "approval-required",+ },+ "linux",+ ),{autoReview: true,sandboxEnabled: true,},);assert.deepEqual(- cursorRuntimeAgentPolicy({- ...base,- runtimeMode: "full-access",- approvalPolicy: "never",- sandboxPolicy: { type: "readOnly" },- }),+ cursorRuntimeAgentPolicy(+ {+ ...base,+ runtimeMode: "full-access",+ approvalPolicy: "never",+ sandboxPolicy: { type: "readOnly" },+ },+ "linux",+ ),{autoReview: false,sandboxEnabled: true,},);assert.deepEqual(- cursorRuntimeAgentPolicy({- ...base,- runtimeMode: "approval-required",- approvalPolicy: "never",- sandboxPolicy: { type: "dangerFullAccess" },- }),+ cursorRuntimeAgentPolicy(+ {+ ...base,+ runtimeMode: "approval-required",+ approvalPolicy: "never",+ sandboxPolicy: { type: "dangerFullAccess" },+ },+ "linux",+ ),{autoReview: false,sandboxEnabled: false,},);+ assert.deepEqual(+ cursorRuntimeAgentPolicy(+ {+ ...base,+ runtimeMode: "auto-accept-edits",+ },+ "win32",+ ),+ {+ autoReview: false,+ sandboxEnabled: true,+ },+ );+ assert.deepEqual(+ cursorRuntimeAgentPolicy(+ {+ ...base,+ runtimeMode: "auto",+ approvalPolicy: "never",+ },+ "win32",+ ),+ {+ autoReview: false,+ sandboxEnabled: true,+ },+ );+ // Auto-review can gate Windows execution without the unsupported SDK sandbox.+ assert.deepEqual(+ cursorRuntimeAgentPolicy(+ {+ ...base,+ runtimeMode: "auto",+ },+ "win32",+ ),+ {+ autoReview: true,+ sandboxEnabled: false,+ },+ );+ assert.deepEqual(+ cursorRuntimeAgentPolicy(+ {+ ...base,+ runtimeMode: "auto",+ sandboxPolicy: { type: "workspaceWrite" },+ },+ "win32",+ ),+ {+ autoReview: true,+ sandboxEnabled: true,+ },+ );});+ it.effect("opens Windows threads without requesting the unsupported SDK sandbox", () =>+ Effect.gen(function* () {+ const instanceId = ProviderInstanceId.make("cursor");+ const threadId = ThreadId.make("cursor-windows-thread");+ const modelSelection = { instanceId, model: "auto" };+ const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({+ runtimeMode: "auto",+ interactionMode: "default",+ cwd: "/workspace",+ });+ let opened = false;+ const adapter = yield* makeCursorAdapterV2({+ instanceId,+ settings: yield* decodeCursorSettings({}),+ environment: {},+ }).pipe(+ Effect.provideService(HostProcess.Platform, "win32"),+ Effect.provideService(CursorAgentSdk.CursorAgentSdkRunner, {+ assertComplete: Effect.void,+ open: (input) =>+ Effect.sync(() => {+ assert.isFalse(input.options.local?.sandboxOptions?.enabled);+ assert.isTrue(input.options.local?.autoReview);+ opened = true;+ return {+ agentId: "native-cursor-windows",+ listMessages: Effect.succeed([]),+ close: Effect.void,+ send: () => Effect.die("not used"),+ };+ }),+ }),+ Effect.provide(TestProviderHost.layer({ cwd: "/workspace" })),+ );+ const runtime = yield* adapter.openSession({+ threadId,+ providerSessionId: ProviderSessionId.make("cursor-windows-session"),+ modelSelection,+ runtimePolicy,+ });+ const thread = yield* runtime.ensureThread({ threadId, modelSelection, runtimePolicy });+ assert.isTrue(opened);+ assert.equal(thread.nativeThreadRef?.nativeId, "native-cursor-windows");+ }).pipe(+ Effect.scoped,+ Effect.provide(+ Layer.mergeAll(NodeServices.layer, IdAllocator.layer, McpProviderSessions.layer),+ ),+ ),+ );+it("loads the user's Cursor settings layers in every runtime mode", () => {for (const runtimeMode of ["full-access", "auto-accept-edits", "approval-required"] as const) {const options = makeCursorAgentOptions({@@ -1141,6 +1266,7 @@ describe("CursorAdapterV2", () => {runtimePolicy: { runtimeMode, interactionMode: "default", cwd: "/workspace" },threadId: ThreadId.make("thread-cursor-setting-sources"),mcpSession: undefined,+ platform: "linux",});assert.deepEqual(options.local?.settingSources, ["project",@@ -1187,6 +1313,7 @@ describe("CursorAdapterV2", () => {},threadId,mcpSession,+ platform: "linux",});assert.deepEqual(options.mcpServers, cursorMcpServers(mcpSession));diff --git a/packages/provider-cursor/src/server/adapter.ts b/packages/provider-cursor/src/server/adapter.tsindex 765ec16fdec..9ff5ba75f46 100644--- a/packages/provider-cursor/src/server/adapter.ts+++ b/packages/provider-cursor/src/server/adapter.ts@@ -183,6 +183,7 @@ export interface CursorRuntimeAgentPolicy {export function cursorRuntimeAgentPolicy(runtimePolicy: ProviderAdapter.ProviderAdapterV2RuntimePolicy,+ platform: NodeJS.Platform,): CursorRuntimeAgentPolicy {const sandboxPolicyType =typeof runtimePolicy.sandboxPolicy === "object" &&@@ -191,14 +192,17 @@ export function cursorRuntimeAgentPolicy(typeof runtimePolicy.sandboxPolicy.type === "string"? runtimePolicy.sandboxPolicy.type: undefined;+ const autoReview =+ runtimePolicy.approvalPolicy === undefined+ ? runtimePolicy.runtimeMode === "approval-required" || runtimePolicy.runtimeMode === "auto"+ : runtimePolicy.approvalPolicy !== "never";return {- autoReview:- runtimePolicy.approvalPolicy === undefined- ? runtimePolicy.runtimeMode === "approval-required" || runtimePolicy.runtimeMode === "auto"- : runtimePolicy.approvalPolicy !== "never",+ autoReview,+ // The Windows SDK has no filesystem sandbox; omit the default only when+ // Auto-review still gates execution. Explicit policies remain authoritative.sandboxEnabled:runtimePolicy.sandboxPolicy === undefined- ? runtimePolicy.runtimeMode !== "full-access"+ ? runtimePolicy.runtimeMode !== "full-access" && !(platform === "win32" && autoReview): sandboxPolicyType !== "dangerFullAccess",};}@@ -307,8 +311,9 @@ export function makeCursorAgentOptions(input: {readonly runtimePolicy: ProviderAdapter.ProviderAdapterV2RuntimePolicy;readonly threadId: ThreadId;readonly mcpSession: McpProviderSession.McpProviderSessionConfig | undefined;+ readonly platform: NodeJS.Platform;}): AgentOptions {- const policy = cursorRuntimeAgentPolicy(input.runtimePolicy);+ const policy = cursorRuntimeAgentPolicy(input.runtimePolicy, input.platform);const mcpServers = cursorMcpServers(input.mcpSession);return {model: cursorSdkModelSelection(input.modelSelection),@@ -887,6 +892,7 @@ export const makeCursorAdapterV2 = Effect.fn("makeCursorAdapterV2")(function* (const path = yield* Path.Path;const idAllocator = yield* IdAllocator.IdAllocatorV2;const runner = yield* CursorAgentSdk.CursorAgentSdkRunner;+ const platform = yield* HostProcess.Platform;const host = yield* ProviderHost.ProviderHost;const mcpSessions = yield* McpProviderSessions.McpProviderSessions;const adapterOptions = options;@@ -910,6 +916,7 @@ export const makeCursorAdapterV2 = Effect.fn("makeCursorAdapterV2")(function* (});const events = yield* Queue.unbounded<ProviderAdapter.ProviderAdapterV2Event>();const liveAgent = yield* Ref.make<CursorLiveAgent | null>(null);+ const warnedUnsupportedSandbox = yield* Ref.make(false);const activeTurn = yield* Ref.make<ActiveCursorTurn | null>(null);const planIds = yield* Ref.make(new Map<string, OrchestrationV2PlanArtifact["id"]>());@@ -2126,17 +2133,30 @@ export const makeCursorAdapterV2 = Effect.fn("makeCursorAdapterV2")(function* (yield* existing.session.close.pipe(Effect.ignore);yield* Ref.set(liveAgent, null);}+ const options = makeCursorAgentOptions({+ ...(apiKey === undefined ? {} : { apiKey }),+ modelSelection: openInput.modelSelection,+ runtimePolicy: openInput.runtimePolicy,+ platform,+ threadId: openInput.threadId,+ mcpSession: yield* mcpSessions.read(openInput.threadId),+ });+ if (+ platform === "win32" &&+ openInput.runtimePolicy.sandboxPolicy === undefined &&+ openInput.runtimePolicy.runtimeMode !== "full-access" &&+ options.local?.sandboxOptions?.enabled === false &&+ !(yield* Ref.getAndSet(warnedUnsupportedSandbox, true))+ ) {+ yield* Effect.logWarning(+ "Cursor cannot sandbox the filesystem on Windows; this thread runs without filesystem isolation.",+ );+ }const sdkSession = yield* runner.open({operation: openInput.operation,...(openInput.agentId === undefined ? {} : { agentId: openInput.agentId }),- options: makeCursorAgentOptions({- ...(apiKey === undefined ? {} : { apiKey }),- modelSelection: openInput.modelSelection,- runtimePolicy: openInput.runtimePolicy,- threadId: openInput.threadId,- mcpSession: yield* mcpSessions.read(openInput.threadId),- }),+ options,threadId: openInput.threadId,providerSessionId: input.providerSessionId,})