Skip to content

Commit 6b75f9a

Browse files
only21milclaude
andcommitted
refactor(cursor): build the SDK service once and name the CLI config read
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 6a1028b commit 6b75f9a

2 files changed

Lines changed: 10 additions & 12 deletions

File tree

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,42 +107,42 @@ const http1 = JSON.stringify({ network: { useHttp1ForAgent: true } });
107107
describe("CursorSdk agent transport", () => {
108108
it.effect.each([
109109
{
110-
name: "CURSOR_CONFIG_DIR before XDG_CONFIG_HOME",
110+
name: "when set in CURSOR_CONFIG_DIR over XDG_CONFIG_HOME",
111111
env: { CURSOR_CONFIG_DIR: "config", XDG_CONFIG_HOME: "xdg" },
112112
file: "config/cli-config.json",
113113
text: http1,
114114
expected: true,
115115
},
116116
{
117-
name: "XDG_CONFIG_HOME",
117+
name: "when set in XDG_CONFIG_HOME",
118118
env: { XDG_CONFIG_HOME: "xdg" },
119119
file: "xdg/cursor/cli-config.json",
120120
text: http1,
121121
expected: true,
122122
},
123123
{
124-
name: "the home directory",
124+
name: "when set in the home directory",
125125
env: {},
126126
file: "home/.cursor/cli-config.json",
127127
text: http1,
128128
expected: true,
129129
},
130130
{
131-
name: "an HTTP/2 setting",
131+
name: "when it is off",
132132
env: {},
133133
file: "home/.cursor/cli-config.json",
134134
text: JSON.stringify({ network: { useHttp1ForAgent: false } }),
135135
expected: undefined,
136136
},
137137
{
138-
name: "a damaged file",
138+
name: "when the file is damaged",
139139
env: {},
140140
file: "home/.cursor/cli-config.json",
141141
text: "{",
142142
expected: undefined,
143143
},
144-
{ name: "no file", env: {}, file: undefined, text: "", expected: undefined },
145-
])("follows the Cursor CLI's HTTP/1.1 setting from $name", ({ env, file, text, expected }) =>
144+
{ 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 }) =>
146146
Effect.gen(function* () {
147147
const fileSystem = yield* FileSystem.FileSystem;
148148
const path = yield* Path.Path;

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ const readCursorCliUseHttp1ForAgent = Effect.gen(function* () {
9696
.readFileString(path.join(configDirectory, "cli-config.json"))
9797
.pipe(Effect.flatMap(decodeCursorCliConfig), Effect.option);
9898
return Option.isSome(config) && config.value.network?.useHttp1ForAgent === true;
99-
});
99+
}).pipe(Effect.withSpan("CursorSdk.readCliUseHttp1ForAgent"));
100100

101101
/** Keeps the shell spawn guard armed while in-process agents run. */
102102
export class CursorSdk extends Context.Service<
@@ -121,9 +121,7 @@ export const layer = Layer.effect(
121121
}),
122122
);
123123
// The SDK picks the agent transport per process, so no provider instance can own this.
124-
if (!(yield* readCursorCliUseHttp1ForAgent)) {
125-
return CursorSdk.of({ load: loadCursorSdk, loadSqlite: loadCursorSqlite });
126-
}
124+
const useHttp1ForAgent = yield* readCursorCliUseHttp1ForAgent;
127125
let configured = false;
128126
yield* Effect.addFinalizer(() =>
129127
Effect.sync(() => {
@@ -133,7 +131,7 @@ export const layer = Layer.effect(
133131
return CursorSdk.of({
134132
load: () => {
135133
const sdk = loadCursorSdk();
136-
if (!configured) {
134+
if (useHttp1ForAgent && !configured) {
137135
sdk.Cursor.configure({ local: { useHttp1ForAgent: true } });
138136
configured = true;
139137
}

0 commit comments

Comments
 (0)