Skip to content

Commit eef37b7

Browse files
only21milclaude
andcommitted
fix(cursor): warn when the Cursor CLI config cannot be read
A missing cli-config.json still falls back to the default agent transport silently. Any other read failure, or a file that does not decode, now logs one warning with the config path before falling back. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 6b75f9a commit eef37b7

2 files changed

Lines changed: 24 additions & 7 deletions

File tree

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as Context from "effect/Context";
66
import * as Effect from "effect/Effect";
77
import * as FileSystem from "effect/FileSystem";
88
import * as Layer from "effect/Layer";
9+
import * as Logger from "effect/Logger";
910
import * as Path from "effect/Path";
1011
import { vi } from "vite-plus/test";
1112

@@ -140,9 +141,10 @@ describe("CursorSdk agent transport", () => {
140141
file: "home/.cursor/cli-config.json",
141142
text: "{",
142143
expected: undefined,
144+
warns: true,
143145
},
144146
{ name: "when there is no file", env: {}, file: undefined, text: "", expected: undefined },
145-
])("follows the Cursor CLI's HTTP/1.1 setting $name", ({ env, file, text, expected }) =>
147+
])("follows the Cursor CLI's HTTP/1.1 setting $name", ({ env, file, text, expected, warns }) =>
146148
Effect.gen(function* () {
147149
const fileSystem = yield* FileSystem.FileSystem;
148150
const path = yield* Path.Path;
@@ -154,13 +156,22 @@ describe("CursorSdk agent transport", () => {
154156
const environment = Object.fromEntries(
155157
Object.entries(env).map(([key, directory]) => [key, path.join(root, directory)]),
156158
);
159+
const warnings: Array<unknown> = [];
160+
const captureWarnings = Logger.make(({ logLevel, message }) => {
161+
if (logLevel === "Warn") warnings.push(message);
162+
});
157163
yield* Effect.gen(function* () {
158164
const sdk = Context.get(yield* Layer.build(CursorSdk.layer), CursorSdk.CursorSdk);
159165
assert.isUndefined(sdkDefaults.useHttp1ForAgent);
160166
sdk.load();
161167
assert.strictEqual(sdkDefaults.useHttp1ForAgent, expected);
162-
}).pipe(Effect.scoped, withHost(environment, path.join(root, "home")));
168+
}).pipe(
169+
Effect.scoped,
170+
withHost(environment, path.join(root, "home")),
171+
Effect.provide(Logger.layer([captureWarnings], { mergeWithExisting: false })),
172+
);
163173
assert.isUndefined(sdkDefaults.useHttp1ForAgent);
174+
assert.lengthOf(warnings, warns ? 1 : 0);
164175
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
165176
);
166177
});

‎packages/provider-cursor/src/server/CursorSdk.ts‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import * as Context from "effect/Context";
44
import * as Effect from "effect/Effect";
55
import * as FileSystem from "effect/FileSystem";
66
import * as Layer from "effect/Layer";
7-
import * as Option from "effect/Option";
87
import * as Path from "effect/Path";
98
import * as Schema from "effect/Schema";
109

@@ -92,10 +91,17 @@ const readCursorCliUseHttp1ForAgent = Effect.gen(function* () {
9291
: XDG_CONFIG_HOME?.trim()
9392
? path.join(XDG_CONFIG_HOME, "cursor")
9493
: path.join(yield* HostProcess.HomeDirectory, ".cursor");
95-
const config = yield* fileSystem
96-
.readFileString(path.join(configDirectory, "cli-config.json"))
97-
.pipe(Effect.flatMap(decodeCursorCliConfig), Effect.option);
98-
return Option.isSome(config) && config.value.network?.useHttp1ForAgent === true;
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;
99105
}).pipe(Effect.withSpan("CursorSdk.readCliUseHttp1ForAgent"));
100106

101107
/** Keeps the shell spawn guard armed while in-process agents run. */

0 commit comments

Comments
 (0)