The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 18:30 UTC
fix(cursor): honor HTTP/1.1 transport for proxy networks (#25338)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Victor committed
Nov 12, 2026 at 16:02 UTC
39ab6a2d2ff5337c60f545c80262714c46510bad
5 files changed
+175
-11
apps/server/scripts/record-cursor-agent-sdk-replay-fixture.ts
+1
-1
@@ -219,6 +219,6 @@ const recordCursorReplayCommand = Command.make(
219
);
220
221
Command.run(recordCursorReplayCommand, { version: "0.0.0" }).pipe(
222
- Effect.provide(Layer.mergeAll(CursorSdk.layer, NodeServices.layer)),
222
+ Effect.provide(CursorSdk.layer.pipe(Layer.provideMerge(NodeServices.layer))),
223
NodeRuntime.runMain,
224
);
packages/provider-cursor/src/server/CursorSdk.test.ts
+106
-1
@@ -1,10 +1,42 @@
1
+import * as NodeServices from "@effect/platform-node/NodeServices";
2
import { assert, describe, it } from "@effect/vitest";
3
+import type { CursorConfigureOptions } from "@cursor/sdk";
4
+import * as HostProcess from "@t3tools/shared/HostProcess";
5
+import * as Context from "effect/Context";
6
import * as Effect from "effect/Effect";
7
+import * as FileSystem from "effect/FileSystem";
8
import * as Layer from "effect/Layer";
9
+import * as Logger from "effect/Logger";
10
+import * as Path from "effect/Path";
11
import { vi } from "vite-plus/test";
12
13
import * as CursorSdk from "./CursorSdk.ts";
14
15
+const sdkDefaults = vi.hoisted(() => ({ useHttp1ForAgent: undefined as boolean | undefined }));
16
+
17
+// Holds the SDK's process-wide default the way it does: only keys present change, null clears.
18
+vi.mock("./sdk.ts", () => ({
19
+ loadCursorSdk: () => ({
20
+ Cursor: {
21
+ configure: ({ local }: CursorConfigureOptions) => {
22
+ if (local !== undefined && "useHttp1ForAgent" in local) {
23
+ sdkDefaults.useHttp1ForAgent = local.useHttp1ForAgent ?? undefined;
24
+ }
25
+ },
26
+ },
27
+ }),
28
+ loadCursorSqlite: () => ({}),
29
+}));
30
+
31
+const withHost = (environment: NodeJS.ProcessEnv, home: string) =>
32
+ Effect.provide(
33
+ Layer.mergeAll(
34
+ NodeServices.layer,
35
+ Layer.succeed(HostProcess.Environment, environment),
36
+ Layer.succeed(HostProcess.HomeDirectory, home),
37
+ ),
38
+ );
39
+
40
// Shaped like the SDK's minified class: the constructor is not named after the error.
41
// @effect-diagnostics-next-line extendsNativeError:off - mimics the Cursor SDK's own native Error class.
42
class o extends Error {
@@ -27,7 +59,7 @@ const rejectThroughGuard = (reason: unknown) =>
59
for (const listener of others) process.on("unhandledRejection", listener);
60
}
61
return exit.mock.calls;
30
- }).pipe(Effect.scoped);
62
+ }).pipe(Effect.scoped, withHost({}, "/nonexistent-home"));
63
64
describe("CursorSdk unhandled rejection guard", () => {
65
it.effect("keeps the server running when the SDK writes to a closed stream", () =>
@@ -70,3 +102,76 @@ describe("CursorSdk unhandled rejection guard", () => {
102
}),
103
);
104
});
105
+
106
+const http1 = JSON.stringify({ network: { useHttp1ForAgent: true } });
107
+
108
+describe("CursorSdk agent transport", () => {
109
+ it.effect.each([
110
+ {
111
+ name: "when set in CURSOR_CONFIG_DIR over XDG_CONFIG_HOME",
112
+ env: { CURSOR_CONFIG_DIR: "config", XDG_CONFIG_HOME: "xdg" },
113
+ file: "config/cli-config.json",
114
+ text: http1,
115
+ expected: true,
116
+ },
117
+ {
118
+ name: "when set in XDG_CONFIG_HOME",
119
+ env: { XDG_CONFIG_HOME: "xdg" },
120
+ file: "xdg/cursor/cli-config.json",
121
+ text: http1,
122
+ expected: true,
123
+ },
124
+ {
125
+ name: "when set in the home directory",
126
+ env: {},
127
+ file: "home/.cursor/cli-config.json",
128
+ text: http1,
129
+ expected: true,
130
+ },
131
+ {
132
+ name: "when it is off",
133
+ env: {},
134
+ file: "home/.cursor/cli-config.json",
135
+ text: JSON.stringify({ network: { useHttp1ForAgent: false } }),
136
+ expected: undefined,
137
+ },
138
+ {
139
+ name: "when the file is damaged",
140
+ env: {},
141
+ file: "home/.cursor/cli-config.json",
142
+ text: "{",
143
+ expected: undefined,
144
+ warns: true,
145
+ },
146
+ { name: "when there is no file", env: {}, file: undefined, text: "", expected: undefined },
147
+ ])("follows the Cursor CLI's HTTP/1.1 setting $name", ({ env, file, text, expected, warns }) =>
148
+ Effect.gen(function* () {
149
+ const fileSystem = yield* FileSystem.FileSystem;
150
+ const path = yield* Path.Path;
151
+ const root = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-cursor-cli-config-" });
152
+ if (file !== undefined) {
153
+ yield* fileSystem.makeDirectory(path.dirname(path.join(root, file)), { recursive: true });
154
+ yield* fileSystem.writeFileString(path.join(root, file), text);
155
+ }
156
+ const environment = Object.fromEntries(
157
+ Object.entries(env).map(([key, directory]) => [key, path.join(root, directory)]),
158
+ );
159
+ const warnings: Array<unknown> = [];
160
+ const captureWarnings = Logger.make(({ logLevel, message }) => {
161
+ if (logLevel === "Warn") warnings.push(message);
162
+ });
163
+ yield* Effect.gen(function* () {
164
+ const sdk = Context.get(yield* Layer.build(CursorSdk.layer), CursorSdk.CursorSdk);
165
+ assert.isUndefined(sdkDefaults.useHttp1ForAgent);
166
+ sdk.load();
167
+ assert.strictEqual(sdkDefaults.useHttp1ForAgent, expected);
168
+ }).pipe(
169
+ Effect.scoped,
170
+ withHost(environment, path.join(root, "home")),
171
+ Effect.provide(Logger.layer([captureWarnings], { mergeWithExisting: false })),
172
+ );
173
+ assert.isUndefined(sdkDefaults.useHttp1ForAgent);
174
+ assert.lengthOf(warnings, warns ? 1 : 0);
175
+ }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
176
+ );
177
+});
packages/provider-cursor/src/server/CursorSdk.ts
+65
-7
@@ -1,7 +1,11 @@
1
// @effect-diagnostics nodeBuiltinImport:off globalConsole:off -- The guard runs in Node's unhandled-rejection callback, outside an Effect runtime. stderr must match Node's default unhandled-rejection print.
2
+import * as HostProcess from "@t3tools/shared/HostProcess";
3
import * as Context from "effect/Context";
4
import * as Effect from "effect/Effect";
5
+import * as FileSystem from "effect/FileSystem";
6
import * as Layer from "effect/Layer";
7
+import * as Path from "effect/Path";
8
+import * as Schema from "effect/Schema";
9
10
import { loadCursorSdk, loadCursorSqlite } from "./sdk.ts";
11
@@ -67,6 +71,39 @@ function onUnhandledRejection(reason: unknown): void {
71
process.exit(1);
72
}
73
74
+const decodeCursorCliConfig = Schema.decodeEffect(
75
+ Schema.fromJsonString(
76
+ Schema.Struct({
77
+ network: Schema.optionalKey(
78
+ Schema.Struct({ useHttp1ForAgent: Schema.optionalKey(Schema.Boolean) }),
79
+ ),
80
+ }),
81
+ ),
82
+);
83
+
84
+// Proxies without HTTP/2 need this Cursor CLI setting, which the SDK never reads itself.
85
+const readCursorCliUseHttp1ForAgent = Effect.gen(function* () {
86
+ const fileSystem = yield* FileSystem.FileSystem;
87
+ const path = yield* Path.Path;
88
+ const { CURSOR_CONFIG_DIR, XDG_CONFIG_HOME } = yield* HostProcess.Environment;
89
+ const configDirectory = CURSOR_CONFIG_DIR?.trim()
90
+ ? CURSOR_CONFIG_DIR
91
+ : XDG_CONFIG_HOME?.trim()
92
+ ? path.join(XDG_CONFIG_HOME, "cursor")
93
+ : path.join(yield* HostProcess.HomeDirectory, ".cursor");
94
+ const configPath = path.join(configDirectory, "cli-config.json");
95
+ const config = yield* fileSystem.readFileString(configPath).pipe(
96
+ Effect.flatMap(decodeCursorCliConfig),
97
+ Effect.catchReason("PlatformError", "NotFound", () => Effect.undefined),
98
+ Effect.catch(() =>
99
+ Effect.logWarning("Cursor CLI config could not be read; using the default agent transport", {
100
+ path: configPath,
101
+ }).pipe(Effect.as(undefined)),
102
+ ),
103
+ );
104
+ return config?.network?.useHttp1ForAgent === true;
105
+}).pipe(Effect.withSpan("CursorSdk.readCliUseHttp1ForAgent"));
106
+
107
/** Keeps the shell spawn guard armed while in-process agents run. */
108
export class CursorSdk extends Context.Service<
109
CursorSdk,
@@ -79,13 +116,34 @@ export class CursorSdk extends Context.Service<
116
/** Provide once per process: a second guard would defer to the first and swallow real rejections. */
117
export const layer = Layer.effect(
118
CursorSdk,
82
- Effect.acquireRelease(
83
- Effect.sync(() => {
84
- process.on("unhandledRejection", onUnhandledRejection);
85
- }),
86
- () =>
119
+ Effect.gen(function* () {
120
+ yield* Effect.acquireRelease(
121
+ Effect.sync(() => {
122
+ process.on("unhandledRejection", onUnhandledRejection);
123
+ }),
124
+ () =>
125
+ Effect.sync(() => {
126
+ process.off("unhandledRejection", onUnhandledRejection);
127
+ }),
128
+ );
129
+ // The SDK picks the agent transport per process, so no provider instance can own this.
130
+ const useHttp1ForAgent = yield* readCursorCliUseHttp1ForAgent;
131
+ let configured = false;
132
+ yield* Effect.addFinalizer(() =>
133
Effect.sync(() => {
88
- process.off("unhandledRejection", onUnhandledRejection);
134
+ if (configured) loadCursorSdk().Cursor.configure({ local: { useHttp1ForAgent: null } });
135
}),
90
- ).pipe(Effect.as(CursorSdk.of({ load: loadCursorSdk, loadSqlite: loadCursorSqlite }))),
136
+ );
137
+ return CursorSdk.of({
138
+ load: () => {
139
+ const sdk = loadCursorSdk();
140
+ if (useHttp1ForAgent && !configured) {
141
+ sdk.Cursor.configure({ local: { useHttp1ForAgent: true } });
142
+ configured = true;
143
+ }
144
+ return sdk;
145
+ },
146
+ loadSqlite: loadCursorSqlite,
147
+ });
148
+ }),
149
);
packages/provider-cursor/src/server/driver.test.ts
+1
-1
@@ -45,7 +45,7 @@ const layerTest = TestProviderHost.layer({ runBackgroundWork: false }).pipe(
45
Layer.provideMerge(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer)),
46
Layer.provideMerge(IdAllocator.layer),
47
Layer.provideMerge(McpProviderSessions.layer),
48
- Layer.provideMerge(CursorSdk.layer),
48
+ Layer.provideMerge(CursorSdk.layer.pipe(Layer.provide(NodeServices.layer))),
49
Layer.provideMerge(
50
Layer.mock(CursorAgentSdk.CursorAgentSdkRunner)({
51
open: () => Effect.die("Maintenance resolution must not open a Cursor session"),
packages/provider-cursor/src/server/textGeneration.test.ts
+2
-1
@@ -5,6 +5,7 @@ import { describe, expect, it } from "@effect/vitest";
5
import * as Effect from "effect/Effect";
6
import * as FileSystem from "effect/FileSystem";
7
import * as Layer from "effect/Layer";
8
+import * as Path from "effect/Path";
9
import * as Schema from "effect/Schema";
10
import { createModelSelection } from "@t3tools/shared/model";
11
import { beforeEach, vi } from "vite-plus/test";
@@ -40,7 +41,7 @@ const layerFs = FileSystem.layerNoop({
41
exists: () => Effect.succeed(hasCustomPolicy),
42
makeTempDirectoryScoped: () => Effect.succeed("/isolated-text-generation"),
43
});
43
-const layerTest = Layer.merge(layerFs, CursorSdk.layer);
44
+const layerTest = CursorSdk.layer.pipe(Layer.provideMerge(Layer.merge(layerFs, Path.layer)));
45
46
const decodeCursorSettings = Schema.decodeSync(CursorSettings);
47
const cursorSettings = decodeCursorSettings({ enabled: true });