@stablekernel/opencode-cursor 0.6.2-next.0 → 0.7.0-next.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 +55 -2
- package/README.md +16 -5
- package/dist/{chunk-52IYLL6B.js → chunk-COE6ZXMP.js} +178 -22
- package/dist/chunk-COE6ZXMP.js.map +1 -0
- package/dist/plugin/index.js +12 -3
- package/dist/plugin/index.js.map +1 -1
- package/dist/provider/index.js +102 -88
- package/dist/provider/index.js.map +1 -1
- package/dist/sidecar/agent-host.d.ts +43 -0
- package/dist/sidecar/agent-host.js +29 -0
- package/dist/sidecar/agent-host.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-52IYLL6B.js.map +0 -1
package/dist/provider/index.js
CHANGED
|
@@ -6,13 +6,15 @@ import {
|
|
|
6
6
|
extractSystemText,
|
|
7
7
|
getSessionRecord,
|
|
8
8
|
linkSubagentSession,
|
|
9
|
+
pluginLog,
|
|
9
10
|
resolveControls,
|
|
10
11
|
resolveCursorApiKey,
|
|
11
12
|
resolveSystemDelivery,
|
|
12
13
|
sendAgentTurnSilently,
|
|
13
14
|
setPreferredTransport,
|
|
14
|
-
streamAgentTurn
|
|
15
|
-
|
|
15
|
+
streamAgentTurn,
|
|
16
|
+
withSessionLock
|
|
17
|
+
} from "../chunk-COE6ZXMP.js";
|
|
16
18
|
|
|
17
19
|
// src/provider/index.ts
|
|
18
20
|
import { NoSuchModelError } from "@ai-sdk/provider";
|
|
@@ -1166,7 +1168,7 @@ var CursorLanguageModel = class {
|
|
|
1166
1168
|
warnOnce(message) {
|
|
1167
1169
|
if (this.warned.has(message)) return;
|
|
1168
1170
|
this.warned.add(message);
|
|
1169
|
-
|
|
1171
|
+
pluginLog("warn", message, { provider: this.provider });
|
|
1170
1172
|
}
|
|
1171
1173
|
requireApiKey() {
|
|
1172
1174
|
const apiKey = resolveCursorApiKey(this.config.apiKey);
|
|
@@ -1189,9 +1191,10 @@ var CursorLanguageModel = class {
|
|
|
1189
1191
|
providerOptions
|
|
1190
1192
|
);
|
|
1191
1193
|
if (process.env["OPENCODE_CURSOR_DEBUG"] === "1") {
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1194
|
+
pluginLog("debug", "model call", {
|
|
1195
|
+
model: this.modelId,
|
|
1196
|
+
selection: modelSelection
|
|
1197
|
+
});
|
|
1195
1198
|
}
|
|
1196
1199
|
const sessionID = typeof providerOptions?.["sessionID"] === "string" ? providerOptions["sessionID"] : void 0;
|
|
1197
1200
|
const dynamicMcp = providerOptions?.["mcpServers"];
|
|
@@ -1201,85 +1204,93 @@ var CursorLanguageModel = class {
|
|
|
1201
1204
|
const explicitAgentId = typeof providerOptions?.["agentId"] === "string" ? providerOptions["agentId"] : void 0;
|
|
1202
1205
|
const ephemeral = providerOptions?.["ephemeral"] === true;
|
|
1203
1206
|
const usePool = sessionEnabled && Boolean(sessionID) && !explicitAgentId;
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1207
|
+
const {
|
|
1208
|
+
acquired,
|
|
1209
|
+
multiTurns,
|
|
1210
|
+
idempotencyKey,
|
|
1211
|
+
systemMode,
|
|
1212
|
+
baseAcquire,
|
|
1213
|
+
record
|
|
1214
|
+
} = await withSessionLock(usePool ? sessionID : void 0, async () => {
|
|
1215
|
+
let resumeAgentId = explicitAgentId;
|
|
1216
|
+
let poolKey;
|
|
1217
|
+
let record2;
|
|
1218
|
+
let multiNewUserCount = 0;
|
|
1219
|
+
if (usePool) {
|
|
1220
|
+
const classification = ephemeral ? {
|
|
1221
|
+
kind: "side-call",
|
|
1222
|
+
fingerprint: fingerprint(options.prompt)
|
|
1223
|
+
} : classifyTurn(getSessionRecord(sessionID), options.prompt);
|
|
1224
|
+
switch (classification.kind) {
|
|
1225
|
+
case "continuation":
|
|
1226
|
+
case "continuation-multi": {
|
|
1227
|
+
const prev = getSessionRecord(sessionID);
|
|
1228
|
+
if (prev?.mcpHash === mcpHash) {
|
|
1229
|
+
resumeAgentId = prev?.agentId;
|
|
1230
|
+
}
|
|
1231
|
+
poolKey = sessionID;
|
|
1232
|
+
record2 = { ...classification.fingerprint, mcpHash };
|
|
1233
|
+
if (classification.kind === "continuation-multi") {
|
|
1234
|
+
multiNewUserCount = classification.newUserCount ?? 0;
|
|
1235
|
+
}
|
|
1236
|
+
break;
|
|
1224
1237
|
}
|
|
1225
|
-
|
|
1238
|
+
case "new":
|
|
1239
|
+
case "divergence":
|
|
1240
|
+
poolKey = sessionID;
|
|
1241
|
+
record2 = { ...classification.fingerprint, mcpHash };
|
|
1242
|
+
break;
|
|
1243
|
+
case "side-call":
|
|
1244
|
+
break;
|
|
1245
|
+
}
|
|
1246
|
+
if (process.env["OPENCODE_CURSOR_DEBUG"] === "1") {
|
|
1247
|
+
const label = classification.kind === "continuation" ? "resume" : classification.kind === "continuation-multi" ? `resume-multi:${multiNewUserCount}` : `fresh:${classification.kind}`;
|
|
1248
|
+
pluginLog("debug", "turn classification", { label, session: sessionID });
|
|
1226
1249
|
}
|
|
1227
|
-
case "new":
|
|
1228
|
-
case "divergence":
|
|
1229
|
-
poolKey = sessionID;
|
|
1230
|
-
record = { ...classification.fingerprint, mcpHash };
|
|
1231
|
-
break;
|
|
1232
|
-
case "side-call":
|
|
1233
|
-
break;
|
|
1234
|
-
}
|
|
1235
|
-
if (process.env["OPENCODE_CURSOR_DEBUG"] === "1") {
|
|
1236
|
-
const label = classification.kind === "continuation" ? "resume" : classification.kind === "continuation-multi" ? `resume-multi:${multiNewUserCount}` : `fresh:${classification.kind}`;
|
|
1237
|
-
console.error(
|
|
1238
|
-
`[cursor:debug] turn classification=${label} session=${sessionID}`
|
|
1239
|
-
);
|
|
1240
1250
|
}
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1251
|
+
let multiTurns2;
|
|
1252
|
+
if (multiNewUserCount >= 2) {
|
|
1253
|
+
const turns = trailingUserMessages(options.prompt, multiNewUserCount);
|
|
1254
|
+
if (turns.length === multiNewUserCount) {
|
|
1255
|
+
multiTurns2 = turns;
|
|
1256
|
+
} else {
|
|
1257
|
+
resumeAgentId = void 0;
|
|
1258
|
+
}
|
|
1249
1259
|
}
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1260
|
+
const latestUser = latestUserMessage(options.prompt);
|
|
1261
|
+
const idempotencyKey2 = sendIdempotencyKey(
|
|
1262
|
+
sessionID,
|
|
1263
|
+
record2,
|
|
1264
|
+
latestUser?.text ?? JSON.stringify(options.prompt)
|
|
1265
|
+
);
|
|
1266
|
+
const delivery = resolveSystemDelivery({
|
|
1267
|
+
mode: this.config.systemPrompt ?? "rules",
|
|
1268
|
+
settingSources: this.config.settingSources,
|
|
1269
|
+
cwd: this.config.cwd,
|
|
1270
|
+
systemText: extractSystemText(options.prompt),
|
|
1271
|
+
warn: (message) => this.warnOnce(message)
|
|
1272
|
+
});
|
|
1273
|
+
const systemMode2 = delivery.mode;
|
|
1274
|
+
const settingSources = delivery.settingSources;
|
|
1275
|
+
const baseAcquire2 = {
|
|
1276
|
+
apiKey: this.requireApiKey(),
|
|
1277
|
+
modelSelection,
|
|
1278
|
+
mode,
|
|
1279
|
+
cwd: this.config.cwd,
|
|
1280
|
+
...settingSources ? { settingSources } : {},
|
|
1281
|
+
...this.config.sandbox !== void 0 ? { sandbox: this.config.sandbox } : {},
|
|
1282
|
+
...this.config.autoReview !== void 0 ? { autoReview: this.config.autoReview } : {},
|
|
1283
|
+
...mcpServers ? { mcpServers } : {},
|
|
1284
|
+
...this.config.agents ? { agents: this.config.agents } : {},
|
|
1285
|
+
...poolKey ? { name: `opencode/${sessionID.slice(-8)}` } : {},
|
|
1286
|
+
...poolKey ? { poolKey } : {},
|
|
1287
|
+
...record2 ? { record: record2 } : {}
|
|
1288
|
+
};
|
|
1289
|
+
const acquired2 = await acquireAgent({
|
|
1290
|
+
...baseAcquire2,
|
|
1291
|
+
...resumeAgentId ? { resumeAgentId } : {}
|
|
1292
|
+
});
|
|
1293
|
+
return { acquired: acquired2, multiTurns: multiTurns2, idempotencyKey: idempotencyKey2, systemMode: systemMode2, baseAcquire: baseAcquire2, record: record2 };
|
|
1283
1294
|
});
|
|
1284
1295
|
let yielded = false;
|
|
1285
1296
|
let releasedOriginal = false;
|
|
@@ -1358,23 +1369,26 @@ var CursorLanguageModel = class {
|
|
|
1358
1369
|
const replayable = classified.kind === "agent-not-found" || classified.kind === "rate-limit" || classified.kind === "network" || classified.kind === "unknown";
|
|
1359
1370
|
if (replayable && acquired.resumed && !yielded && !options.abortSignal?.aborted) {
|
|
1360
1371
|
if (process.env["OPENCODE_CURSOR_DEBUG"] === "1") {
|
|
1361
|
-
|
|
1362
|
-
"
|
|
1372
|
+
pluginLog(
|
|
1373
|
+
"debug",
|
|
1374
|
+
"resumed turn failed before emitting; retrying with a fresh agent"
|
|
1363
1375
|
);
|
|
1364
1376
|
}
|
|
1365
1377
|
acquired.release();
|
|
1366
1378
|
releasedOriginal = true;
|
|
1367
1379
|
let retry;
|
|
1368
1380
|
try {
|
|
1369
|
-
retry = await
|
|
1381
|
+
retry = await withSessionLock(
|
|
1382
|
+
usePool ? sessionID : void 0,
|
|
1383
|
+
() => acquireAgent({ ...baseAcquire })
|
|
1384
|
+
);
|
|
1370
1385
|
} catch (retryErr) {
|
|
1371
1386
|
if (retryErr instanceof Error && retryErr.cause === void 0) {
|
|
1372
1387
|
retryErr.cause = err;
|
|
1373
1388
|
} else if (process.env["OPENCODE_CURSOR_DEBUG"] === "1") {
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
);
|
|
1389
|
+
pluginLog("debug", "original resume failure (not attachable as cause)", {
|
|
1390
|
+
error: err instanceof Error ? err.message : String(err)
|
|
1391
|
+
});
|
|
1378
1392
|
}
|
|
1379
1393
|
throw retryErr;
|
|
1380
1394
|
}
|