cursor-delegate-mcp 2.10.0 → 2.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +29 -0
- package/package.json +3 -2
- package/src/delegate.js +24 -5
- package/src/doctor.js +4 -2
- package/src/server.js +43 -30
- package/src/spawn.js +14 -2
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,35 @@ All notable changes to this project are documented here. The format follows
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [2.11.0] - 2026-11-23
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- `doctor` reports `client.protocolVersion`: `2026-07-28`, or the 2025-era revision the host
|
|
14
|
+
negotiated.
|
|
15
|
+
|
|
16
|
+
### Changed
|
|
17
|
+
|
|
18
|
+
- MCP SDK v2 (`@modelcontextprotocol/server` 2.4.0): the server takes 2025-era and 2026-07-28
|
|
19
|
+
hosts. The runtime dependencies are this package and `zod`.
|
|
20
|
+
- A delegation returns once cursor-agent has exited, about 0.1 s after the turn ends. A host that
|
|
21
|
+
closes stdin on the result, as a one-shot run does, exits the server, which on Windows left a
|
|
22
|
+
cursor-agent still being killed running.
|
|
23
|
+
|
|
24
|
+
### Fixed
|
|
25
|
+
|
|
26
|
+
- An agent whose exit is not seen after the kill is killed once more, by the delegation and by
|
|
27
|
+
server shutdown. A delegation that still sees no exit says so in `protocolWarnings` or its
|
|
28
|
+
error.
|
|
29
|
+
- `cancel` reports `not-running` for a turn that has ended while its agent is being stopped, and
|
|
30
|
+
leaves its result alone. `force` leaves a turn that ends during its grace to that turn's own
|
|
31
|
+
teardown.
|
|
32
|
+
- `doctor` on a 2025-era connection reports the identity and revision from `initialize`, even
|
|
33
|
+
when a request carries per-request envelope keys.
|
|
34
|
+
- On Windows, quotes and empty arguments in `ACP_AGENT_ARGS` reach cursor-agent when
|
|
35
|
+
`cursor-agent.cmd` forwards to its `.ps1` through Windows PowerShell 5.1.
|
|
36
|
+
- The Claude plugin manifest names its image `icon`, the field Anthropic's plugin directory reads.
|
|
37
|
+
|
|
9
38
|
## [2.10.0] - 2026-11-22
|
|
10
39
|
|
|
11
40
|
### Changed
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cursor-delegate-mcp",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.11.0",
|
|
4
4
|
"mcpName": "io.github.andreilungeanu/cursor-delegate-mcp",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Delegate multi-file coding work from Claude Code, Codex, Copilot, or any MCP client to Cursor's CLI agent — structured results, plan mode, and changed files.",
|
|
@@ -57,10 +57,11 @@
|
|
|
57
57
|
"typecheck": "tsc -p tsconfig.json"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@modelcontextprotocol/
|
|
60
|
+
"@modelcontextprotocol/server": "^2.4.0",
|
|
61
61
|
"zod": "^4.6.5"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
|
+
"@modelcontextprotocol/client": "^2.4.0",
|
|
64
65
|
"@types/node": "^26.1.1",
|
|
65
66
|
"typescript": "^7.0.2"
|
|
66
67
|
}
|
package/src/delegate.js
CHANGED
|
@@ -251,6 +251,7 @@ async function applyEffort(client, sessionId, model, value, modelOptions) {
|
|
|
251
251
|
* idleMs?: number, handshakeMs?: number, hardCapMs?: number, timeoutMs?: number,
|
|
252
252
|
* onClientReady?: (client: any) => void,
|
|
253
253
|
* onSessionReady?: (sessionId: string, client: any) => void,
|
|
254
|
+
* onTurnEnd?: () => void,
|
|
254
255
|
* onProgress?: (message: string) => void,
|
|
255
256
|
* progressThrottleMs?: number, heartbeatMs?: number, signal?: AbortSignal,
|
|
256
257
|
* }} [opts]
|
|
@@ -259,7 +260,7 @@ export async function runDelegate({
|
|
|
259
260
|
spec, mode = "agent", resumeSessionId, workspace,
|
|
260
261
|
model = DEFAULT_MODEL, fast = false, effort, context, contextFiles, clientFactory,
|
|
261
262
|
idleMs, handshakeMs, hardCapMs, timeoutMs,
|
|
262
|
-
onClientReady, onSessionReady, onProgress, progressThrottleMs = 2000,
|
|
263
|
+
onClientReady, onSessionReady, onTurnEnd, onProgress, progressThrottleMs = 2000,
|
|
263
264
|
heartbeatMs = DEFAULT_HEARTBEAT_MS,
|
|
264
265
|
signal,
|
|
265
266
|
} = {}) {
|
|
@@ -449,6 +450,11 @@ export async function runDelegate({
|
|
|
449
450
|
let servedModel;
|
|
450
451
|
let effectiveEffort;
|
|
451
452
|
const contextWarnings = [];
|
|
453
|
+
// Set before the teardown in finally, which notes an unseen exit on whichever is going out.
|
|
454
|
+
/** @type {any} */
|
|
455
|
+
let out;
|
|
456
|
+
/** @type {any} */
|
|
457
|
+
let failed;
|
|
452
458
|
try {
|
|
453
459
|
const res = await supervisor.supervise(async () => {
|
|
454
460
|
await client.start();
|
|
@@ -548,7 +554,7 @@ export async function runDelegate({
|
|
|
548
554
|
stopReason = res.stopReason;
|
|
549
555
|
}
|
|
550
556
|
}
|
|
551
|
-
|
|
557
|
+
out = {
|
|
552
558
|
result,
|
|
553
559
|
sessionId,
|
|
554
560
|
};
|
|
@@ -632,13 +638,26 @@ export async function runDelegate({
|
|
|
632
638
|
if (transcript) err.message += `\n\n--- recent ACP transcript (last ${frames} frames) ---\n` + transcript;
|
|
633
639
|
} catch {}
|
|
634
640
|
}
|
|
641
|
+
failed = err;
|
|
635
642
|
throw err;
|
|
636
643
|
} finally {
|
|
644
|
+
// The turn is decided: from here a cancel finds nothing running.
|
|
645
|
+
try { onTurnEnd?.(); } catch {}
|
|
637
646
|
clearInterval(heartbeat);
|
|
638
647
|
signal?.removeEventListener("abort", onAbort);
|
|
639
648
|
try { supervisor.finish(); } catch {}
|
|
640
|
-
//
|
|
641
|
-
//
|
|
642
|
-
|
|
649
|
+
// Awaited: a host may close stdin on the result, and on Windows the server's exit does not take
|
|
650
|
+
// a running agent with it (server.smoke.test.js). An exit not seen is noted instead.
|
|
651
|
+
// A rejected stop counts as unseen; an unseen exit is not memoized, so a retry kills afresh.
|
|
652
|
+
const stopOnce = () => Promise.resolve(client.stop()).catch(() => false);
|
|
653
|
+
let exited = await stopOnce();
|
|
654
|
+
if (exited === false) exited = await stopOnce();
|
|
655
|
+
if (exited === false) {
|
|
656
|
+
const pid = client.child?.pid;
|
|
657
|
+
const note = `the bridge stopped cursor-agent${pid ? ` (pid ${pid})` : ""} but did not see it exit; it may still be running.`;
|
|
658
|
+
// A failure whose message cannot be written keeps its own error rather than a TypeError.
|
|
659
|
+
if (failed) { try { failed.message += ` Note: ${note}`; } catch {} }
|
|
660
|
+
else if (out) (out.protocolWarnings ??= []).push(note);
|
|
661
|
+
}
|
|
643
662
|
}
|
|
644
663
|
}
|
package/src/doctor.js
CHANGED
|
@@ -165,7 +165,7 @@ async function runDeepHandshake({ spawnSpec, clientFactory, workspace, timeoutMs
|
|
|
165
165
|
/**
|
|
166
166
|
* onClientReady gets each process doctor starts, probe then agent, so a shutdown can stop it.
|
|
167
167
|
* @param {{
|
|
168
|
-
* getClientInfo?: () => { capabilities?: any, version?: any },
|
|
168
|
+
* getClientInfo?: () => { capabilities?: any, version?: any, protocolVersion?: string },
|
|
169
169
|
* deep?: boolean,
|
|
170
170
|
* spawnSpec?: { command: string, args: string[], options?: object },
|
|
171
171
|
* clientFactory?: (opts: any) => any,
|
|
@@ -189,7 +189,7 @@ export async function runDoctor({
|
|
|
189
189
|
signal,
|
|
190
190
|
onClientReady,
|
|
191
191
|
} = {}) {
|
|
192
|
-
const { capabilities, version } = getClientInfo();
|
|
192
|
+
const { capabilities, version, protocolVersion } = getClientInfo();
|
|
193
193
|
const agentProbe = await probeAgentVersion(spawnSpec, versionTimeoutMs, { signal, onSpawn: onClientReady });
|
|
194
194
|
|
|
195
195
|
/** @type {{ plugin: any, client: any, agent: any & { handshake?: any }, runtime: any, env: any }} */
|
|
@@ -199,6 +199,8 @@ export async function runDoctor({
|
|
|
199
199
|
name: version?.name ?? null,
|
|
200
200
|
version: version?.version ?? null,
|
|
201
201
|
capabilities: capabilities ?? {},
|
|
202
|
+
// The MCP revision the host speaks: 2026-07-28 or a 2025-era one.
|
|
203
|
+
...(typeof protocolVersion === "string" ? { protocolVersion } : {}),
|
|
202
204
|
},
|
|
203
205
|
agent: {
|
|
204
206
|
found: agentProbe.found,
|
package/src/server.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
import process from "node:process";
|
|
3
3
|
import { realpathSync } from "node:fs";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
|
-
import { McpServer } from "@modelcontextprotocol/
|
|
6
|
-
import {
|
|
5
|
+
import { McpServer, CLIENT_CAPABILITIES_META_KEY, CLIENT_INFO_META_KEY, PROTOCOL_VERSION_META_KEY } from "@modelcontextprotocol/server";
|
|
6
|
+
import { serveStdio } from "@modelcontextprotocol/server/stdio";
|
|
7
7
|
import { z } from "zod";
|
|
8
8
|
import { DEFAULT_MODEL, runDelegate as runDelegateDefault } from "./delegate.js";
|
|
9
9
|
import { runDoctor as runDoctorDefault } from "./doctor.js";
|
|
@@ -32,7 +32,7 @@ function registerInFlight(map, sessionId, handle) {
|
|
|
32
32
|
if (handles) handles.add(handle);
|
|
33
33
|
else map.set(sessionId, new Set([handle]));
|
|
34
34
|
}
|
|
35
|
-
/** @returns {import("@modelcontextprotocol/
|
|
35
|
+
/** @returns {import("@modelcontextprotocol/server").CallToolResult} */
|
|
36
36
|
function cancelResult(status, sessionId) {
|
|
37
37
|
return { content: [{ type: "text", text: JSON.stringify({ status, sessionId }) }] };
|
|
38
38
|
}
|
|
@@ -137,6 +137,7 @@ export const doctorOutputShape = {
|
|
|
137
137
|
name: z.string().nullable(),
|
|
138
138
|
version: z.string().nullable(),
|
|
139
139
|
capabilities: z.record(z.string(), z.unknown()),
|
|
140
|
+
protocolVersion: z.string().optional(),
|
|
140
141
|
}).passthrough(),
|
|
141
142
|
agent: z.object(doctorAgentShape).passthrough(),
|
|
142
143
|
runtime: z.object({
|
|
@@ -164,27 +165,26 @@ export const delegateInputSchema = z.object({
|
|
|
164
165
|
|
|
165
166
|
/**
|
|
166
167
|
* @param {{
|
|
167
|
-
* args: any,
|
|
168
|
+
* args: any, ctx?: any,
|
|
168
169
|
* runDelegate: (opts: any) => Promise<any>,
|
|
169
170
|
* inFlight: Map<string, Set<any>>,
|
|
170
171
|
* pending?: Set<any>,
|
|
171
172
|
* seenSessions?: Set<string>,
|
|
172
173
|
* }} deps
|
|
173
|
-
* @returns {Promise<import("@modelcontextprotocol/
|
|
174
|
+
* @returns {Promise<import("@modelcontextprotocol/server").CallToolResult>}
|
|
174
175
|
*/
|
|
175
|
-
export async function runDelegateTool({ args,
|
|
176
|
+
export async function runDelegateTool({ args, ctx, runDelegate, inFlight, pending = new Set(), seenSessions = new Set() }) {
|
|
176
177
|
const { spec, mode, resumeSessionId, workspace, model, fast, effort, context, contextFiles } = args;
|
|
177
178
|
|
|
178
|
-
const progressToken =
|
|
179
|
+
const progressToken = ctx?.mcpReq?._meta?.progressToken;
|
|
179
180
|
/** @type {(message: string) => void} */
|
|
180
181
|
let onProgress = () => {};
|
|
181
182
|
if (progressToken != null) {
|
|
182
183
|
let progress = 0;
|
|
183
184
|
onProgress = (message) => {
|
|
184
|
-
// An unhandled rejection from
|
|
185
|
-
// sync throw.
|
|
185
|
+
// An unhandled rejection from notify would exit the server; the try catches a sync throw.
|
|
186
186
|
try {
|
|
187
|
-
Promise.resolve(
|
|
187
|
+
Promise.resolve(ctx.mcpReq.notify({
|
|
188
188
|
method: "notifications/progress",
|
|
189
189
|
params: { progressToken, progress: ++progress, message },
|
|
190
190
|
})).catch(() => {});
|
|
@@ -206,7 +206,7 @@ export async function runDelegateTool({ args, extra, runDelegate, inFlight, pend
|
|
|
206
206
|
context,
|
|
207
207
|
contextFiles,
|
|
208
208
|
onProgress,
|
|
209
|
-
signal:
|
|
209
|
+
signal: ctx?.mcpReq?.signal,
|
|
210
210
|
onClientReady: (client) => {
|
|
211
211
|
handle = { client, cancelRequested: false };
|
|
212
212
|
pending.add(handle);
|
|
@@ -221,6 +221,7 @@ export async function runDelegateTool({ args, extra, runDelegate, inFlight, pend
|
|
|
221
221
|
// Sent now so a host that can call tools concurrently has an id to cancel mid-run.
|
|
222
222
|
onProgress(`session ready: ${sessionId}`);
|
|
223
223
|
},
|
|
224
|
+
onTurnEnd: () => { if (handle) handle.ended = true; },
|
|
224
225
|
});
|
|
225
226
|
if (handle?.cancelRequested) out.cancelRequested = true;
|
|
226
227
|
return { content: [{ type: "text", text: JSON.stringify(out) }] };
|
|
@@ -268,7 +269,7 @@ export function buildServer({ runDelegate: runDelegateInjected, runDoctor: runDo
|
|
|
268
269
|
openWorldHint: true,
|
|
269
270
|
},
|
|
270
271
|
},
|
|
271
|
-
async (args,
|
|
272
|
+
async (args, ctx) => runDelegateTool({ args, ctx, runDelegate, inFlight, pending, seenSessions })
|
|
272
273
|
);
|
|
273
274
|
|
|
274
275
|
server.registerTool(
|
|
@@ -276,11 +277,11 @@ export function buildServer({ runDelegate: runDelegateInjected, runDoctor: runDo
|
|
|
276
277
|
{
|
|
277
278
|
description:
|
|
278
279
|
"Best-effort cancel of an in-flight delegation by sessionId. session/cancel is advisory — the agent may finish the turn anyway, and the delegate result then carries cancelRequested. Status: cancelled, killed (agent process observed to exit), not-running (turn already ended, still resumable), not-found (id not in this process's recent session history).",
|
|
279
|
-
inputSchema: {
|
|
280
|
+
inputSchema: z.object({
|
|
280
281
|
// Blank is a malformed call, not a stale id.
|
|
281
282
|
sessionId: z.string().trim().min(1, "sessionId must not be blank"),
|
|
282
283
|
force: z.boolean().default(false).describe("Kill the agent process if the turn is still running after a short grace period."),
|
|
283
|
-
},
|
|
284
|
+
}),
|
|
284
285
|
annotations: {
|
|
285
286
|
title: "Cancel Cursor delegation",
|
|
286
287
|
readOnlyHint: false,
|
|
@@ -297,8 +298,10 @@ export function buildServer({ runDelegate: runDelegateInjected, runDoctor: runDo
|
|
|
297
298
|
return cancelResult(known ? "not-running" : "not-found", sessionId);
|
|
298
299
|
}
|
|
299
300
|
// Every turn on the id (the caller named a session), taken now: a resume that registers during
|
|
300
|
-
// the grace or the kill is not swept in.
|
|
301
|
-
|
|
301
|
+
// the grace or the kill is not swept in. An ended turn stays registered while its agent is
|
|
302
|
+
// stopped; its result is decided, so a cancel leaves it alone.
|
|
303
|
+
const targeted = [...handles].filter((handle) => !handle.ended);
|
|
304
|
+
if (targeted.length === 0) return cancelResult("not-running", sessionId);
|
|
302
305
|
for (const handle of targeted) handle.cancelRequested = true;
|
|
303
306
|
await Promise.all(targeted.map((handle) => handle.client.cancel(sessionId).catch(() => {})));
|
|
304
307
|
if (!force) {
|
|
@@ -307,7 +310,7 @@ export function buildServer({ runDelegate: runDelegateInjected, runDoctor: runDo
|
|
|
307
310
|
return cancelResult("cancelled", sessionId);
|
|
308
311
|
}
|
|
309
312
|
// Polled, not slept through: the turn often settles well inside the grace.
|
|
310
|
-
const running = () => targeted.filter((handle) => inFlight.get(sessionId)?.has(handle));
|
|
313
|
+
const running = () => targeted.filter((handle) => !handle.ended && inFlight.get(sessionId)?.has(handle));
|
|
311
314
|
const graceEnds = Date.now() + forceGraceMs;
|
|
312
315
|
while (Date.now() < graceEnds && running().length) {
|
|
313
316
|
await new Promise((r) => setTimeout(r, Math.min(50, Math.max(1, graceEnds - Date.now()))));
|
|
@@ -329,12 +332,12 @@ export function buildServer({ runDelegate: runDelegateInjected, runDoctor: runDo
|
|
|
329
332
|
{
|
|
330
333
|
description:
|
|
331
334
|
"Setup diagnostics: plugin version, MCP client capabilities, cursor-agent launcher resolution. Run when delegation fails or agent.found is false.",
|
|
332
|
-
inputSchema: {
|
|
335
|
+
inputSchema: z.object({
|
|
333
336
|
deep: z
|
|
334
337
|
.boolean()
|
|
335
338
|
.default(false)
|
|
336
339
|
.describe("Run an ACP handshake (start → initialize → newSession) to verify the agent is usable; adds models, modes and the current model's options."),
|
|
337
|
-
},
|
|
340
|
+
}),
|
|
338
341
|
annotations: {
|
|
339
342
|
title: "Diagnose Cursor delegation setup",
|
|
340
343
|
readOnlyHint: true,
|
|
@@ -343,18 +346,15 @@ export function buildServer({ runDelegate: runDelegateInjected, runDoctor: runDo
|
|
|
343
346
|
openWorldHint: false,
|
|
344
347
|
},
|
|
345
348
|
},
|
|
346
|
-
async ({ deep },
|
|
349
|
+
async ({ deep }, ctx) => {
|
|
347
350
|
// doctor's processes sit in pending while it runs, where shutdown already looks.
|
|
348
351
|
const handles = [];
|
|
349
352
|
try {
|
|
350
353
|
const out = await runDoctor({
|
|
351
354
|
deep,
|
|
352
|
-
signal:
|
|
355
|
+
signal: ctx?.mcpReq?.signal,
|
|
353
356
|
onClientReady: (client) => { const handle = { client }; handles.push(handle); pending.add(handle); },
|
|
354
|
-
getClientInfo: () => (
|
|
355
|
-
capabilities: server.server.getClientCapabilities(),
|
|
356
|
-
version: server.server.getClientVersion(),
|
|
357
|
-
}),
|
|
357
|
+
getClientInfo: () => clientInfoOf(server, ctx),
|
|
358
358
|
});
|
|
359
359
|
return { content: [{ type: "text", text: JSON.stringify(out) }] };
|
|
360
360
|
} finally {
|
|
@@ -366,6 +366,17 @@ export function buildServer({ runDelegate: runDelegateInjected, runDoctor: runDo
|
|
|
366
366
|
return server;
|
|
367
367
|
}
|
|
368
368
|
|
|
369
|
+
// A 2025-era client sends its identity once, in initialize, which stays authoritative on that
|
|
370
|
+
// connection even if a request carries envelope keys; a 2026-07-28 one sends it with each request.
|
|
371
|
+
export function clientInfoOf(server, ctx) {
|
|
372
|
+
const envelope = ctx?.mcpReq?.envelope;
|
|
373
|
+
return {
|
|
374
|
+
capabilities: server.server.getClientCapabilities() ?? envelope?.[CLIENT_CAPABILITIES_META_KEY],
|
|
375
|
+
version: server.server.getClientVersion() ?? envelope?.[CLIENT_INFO_META_KEY],
|
|
376
|
+
protocolVersion: server.server.getNegotiatedProtocolVersion() ?? envelope?.[PROTOCOL_VERSION_META_KEY],
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
|
|
369
380
|
const __filename = fileURLToPath(import.meta.url);
|
|
370
381
|
let isMain = false;
|
|
371
382
|
if (process.argv[1]) {
|
|
@@ -393,8 +404,10 @@ export function installSignalCleanup(map, {
|
|
|
393
404
|
// Set now: the loop may run dry before the scheduled exit gets a turn.
|
|
394
405
|
setExitCode(code);
|
|
395
406
|
const stops = [];
|
|
407
|
+
// An unseen exit is not memoized, so a second stop dispatches a fresh kill before the exit.
|
|
408
|
+
const stopOnce = (handle) => Promise.resolve(handle.client.stop()).catch(() => false);
|
|
396
409
|
const dispatch = (handle) => {
|
|
397
|
-
try { stops.push(
|
|
410
|
+
try { stops.push(stopOnce(handle).then((exited) => (exited === false ? stopOnce(handle) : exited))); } catch {}
|
|
398
411
|
};
|
|
399
412
|
for (const handles of map.values()) for (const handle of handles) dispatch(handle);
|
|
400
413
|
// Delegations still in their handshake: their agent runs, and only pending reaches it.
|
|
@@ -411,8 +424,8 @@ export function installSignalCleanup(map, {
|
|
|
411
424
|
const signals = /** @type {[NodeJS.Signals, number][]} */ ([["SIGINT", 130], ["SIGTERM", 143], ["SIGHUP", 129]]);
|
|
412
425
|
for (const [signal, code] of signals) process.on(signal, () => shutdown(code, true));
|
|
413
426
|
}
|
|
414
|
-
// A stdio host closes stdin before it resorts to a signal
|
|
415
|
-
//
|
|
427
|
+
// A stdio host closes stdin before it resorts to a signal. The SDK aborts in-flight requests on
|
|
428
|
+
// EOF; this also stops their agents directly, waits for the kills, and exits.
|
|
416
429
|
stdin.on("end", () => shutdown(0));
|
|
417
430
|
}
|
|
418
431
|
|
|
@@ -423,8 +436,8 @@ if (isMain) {
|
|
|
423
436
|
if (argv.includes("--version") || argv.includes("-v")) {
|
|
424
437
|
console.log(readPackageVersion());
|
|
425
438
|
} else {
|
|
426
|
-
const server = buildServer();
|
|
427
439
|
installSignalCleanup(inFlight, { pending: pendingDelegations });
|
|
428
|
-
|
|
440
|
+
// One factory serves both protocol eras: a 2025-era initialize pins a legacy instance.
|
|
441
|
+
serveStdio(() => buildServer());
|
|
429
442
|
}
|
|
430
443
|
}
|
package/src/spawn.js
CHANGED
|
@@ -54,6 +54,16 @@ function cmdQuote(value) {
|
|
|
54
54
|
return `"${s.replace(/(\\+)$/, "$1$1")}"`;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
+
// Windows PowerShell 5.1 pastes each argument into the command line unescaped, drops an empty one,
|
|
58
|
+
// and quotes one only if it has whitespace outside an even count of ". Escaped for node's parser;
|
|
59
|
+
// with whitespace a quote goes as "", which keeps that count even and reads as " inside the quotes.
|
|
60
|
+
function escapeForPs51(arg) {
|
|
61
|
+
if (arg === "") return '""';
|
|
62
|
+
const spaced = /\s/.test(arg);
|
|
63
|
+
const s = arg.replace(/(\\*)"/g, (_, bs) => `${bs}${bs}${spaced ? '""' : '\\"'}`);
|
|
64
|
+
return spaced ? s.replace(/(\\+)$/, "$1$1") : s;
|
|
65
|
+
}
|
|
66
|
+
|
|
57
67
|
/**
|
|
58
68
|
* What to hand spawn() for a spec, at each spawn site so doctor reads the spec as configured.
|
|
59
69
|
* @param {string} command @param {string[]} args
|
|
@@ -65,7 +75,8 @@ export function spawnArgv(command, args, options) {
|
|
|
65
75
|
// cmd.exe opens a .ps1 with its file association, so a .ps1, or the one a forwarding .cmd runs,
|
|
66
76
|
// goes to powershell.exe -File as cursor-agent.cmd does. Only x.ps1 itself: x.ps1.cmd stays cmd's.
|
|
67
77
|
const name = String(command).replace(/^["']|["']$/g, "");
|
|
68
|
-
const
|
|
78
|
+
const direct = /\.ps1$/i.test(name);
|
|
79
|
+
const script = direct ? findCommand(name, env, true) : forwardedScript(findCommand(name, env), env);
|
|
69
80
|
if (script) {
|
|
70
81
|
const rootKey = Object.keys(env).find((k) => k.toUpperCase() === "SYSTEMROOT");
|
|
71
82
|
const powershell = rootKey && env[rootKey]
|
|
@@ -73,7 +84,8 @@ export function spawnArgv(command, args, options) {
|
|
|
73
84
|
: "powershell.exe";
|
|
74
85
|
return {
|
|
75
86
|
command: powershell,
|
|
76
|
-
|
|
87
|
+
// cursor-agent.ps1 passes $args on to node; a .ps1 named directly may read them itself.
|
|
88
|
+
args: ["-NoProfile", "-ExecutionPolicy", "Bypass", "-File", script, ...(direct ? args : args.map(escapeForPs51))],
|
|
77
89
|
options: { ...options, shell: false },
|
|
78
90
|
};
|
|
79
91
|
}
|