feat(cursor): migrate remote sessions to ACP with model/variant pickers (#799)

* feat(cli,web,hub): migrate Cursor remote sessions to ACP with model/effort pickers

Move stream-json remote launcher to legacy path and add ACP launcher with
set_config_option model/mode sync, optimistic keepalive on config changes, and
shared catalog caching. Web gets dual base/effort Cursor pickers for session and
new-session flows; hide composer status bar when Cursor sends no usage_update.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(cli,web,shared): Cursor model picker — ACP wires + CLI sku variants

Enrich the web/mobile picker with agent --list-models SKUs grouped under
ACP wire bases, fix session-open base highlight, and keep catalog discovery
safe while the ACP transport holds the CLI lock.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(cursor-acp): apply ACP default model when web resets to Default

Web sends model: null for Default; push session/set_config_option with the
ACP default[] wire so Cursor backend matches hub state. Regression tests
for setModel(null) and applyModelConfig(null).

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(acp): clear stale agent-acp lock when owning process is gone

Check lock pid with signal 0; remove orphaned lock dirs after SIGKILL or
crash so listCursorModels can run cold probes again. Regression tests for
guard and catalog discovery.

Co-authored-by: Cursor <cursoragent@cursor.com>

* test(cursor): use live pid for ACP lock handler tests

Stale-lock cleanup clears dead pids; handler tests must simulate an
active lock with the current process pid to avoid cold probes/timeouts.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(acp): scope agent CLI lock guard to Cursor agent command only

Gemini/OpenCode/Kimi ACP sessions must not register agent-acp-active;
that blocked listCursorModels while unrelated backends were running.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(hub,web): reject Cursor model changes for local sessions

Hub returns 409 when controlledByUser is set, matching Codex. Web hides
model and variant pickers for local Cursor sessions so users do not hit
a dead RPC path. Document pre-push-review in AGENTS.md.

Verified: bun typecheck; bun run test (919 cli + 243 hub + 768 web + 46 shared).
Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(web): send stable ids for Cursor ask_question replies

Parse and submit question.id and option.id so ACP receives keys like
{ approach: ['a'] } instead of index/label. Verified: bun typecheck && bun run test.

Co-authored-by: Cursor <cursoragent@cursor.com>

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
SSU-WEI HUANG
2026-06-06 19:51:35 +08:00
committed by GitHub
co-authored by Cursor
parent f4c3513abd
commit 3a8693f380
110 changed files with 7945 additions and 496 deletions
+145 -6
View File
@@ -1,6 +1,83 @@
import { spawn } from 'node:child_process';
import type { CursorModelsResponse, CursorModelSummary } from '@hapi/protocol/apiTypes';
import { isAgentAcpTransportActive } from '@/agent/backends/acp/agentCliGuard';
import { getCursorAcpModelsSnapshot } from '@/cursor/utils/cursorAcpModelsBridge';
import { getErrorMessage } from './rpcResponses';
import {
readSharedCursorModelsCache,
writeSharedCursorModelsCache,
_resetSharedCursorModelsCacheForTests
} from './cursorModelsSharedCache';
import {
cursorCliSkuBaseId,
cursorModelBaseId,
isCursorAcpWireModelId
} from '@hapi/protocol';
import {
cursorProbeResponseHasWireCatalog,
runCursorAcpModelProbe
} from './cursorAcpModelProbe';
function filterCliSkusForWireBases(
cliSkus: CursorModelSummary[],
wires: CursorModelSummary[]
): CursorModelSummary[] {
const wireBases = new Set(
wires.map((entry) => cursorModelBaseId(entry.modelId)).filter((base) => base.length > 0)
);
return cliSkus.filter((entry) => {
const modelId = entry.modelId.trim();
if (!modelId || modelId === 'auto' || isCursorAcpWireModelId(modelId)) {
return false;
}
return wireBases.has(cursorCliSkuBaseId(modelId));
});
}
function attachCliSkusToResponse(
response: ListCursorModelsResponse,
cliSkus: readonly CursorModelSummary[]
): ListCursorModelsResponse {
if ((response.cliModelSkus?.length ?? 0) > 0) {
return response;
}
const wires = (response.availableModels ?? []).filter((entry) => isCursorAcpWireModelId(entry.modelId));
const filtered = filterCliSkusForWireBases([...cliSkus], wires);
return filtered.length > 0 ? { ...response, cliModelSkus: filtered } : response;
}
async function enrichCursorModelsWithCliSkus(
response: ListCursorModelsResponse
): Promise<ListCursorModelsResponse> {
if ((response.cliModelSkus?.length ?? 0) > 0) {
return response;
}
const wires = (response.availableModels ?? []).filter((entry) => isCursorAcpWireModelId(entry.modelId));
if (wires.length === 0) {
return response;
}
const shared = readSharedCursorModelsCache();
if (shared?.cliModelSkus?.length) {
return attachCliSkusToResponse(response, shared.cliModelSkus);
}
// Never spawn `agent --list-models` while an ACP session holds the CLI lock.
if (isAgentAcpTransportActive()) {
return response;
}
try {
const probe = await runCursorModelProbe();
const cliSkus = filterCliSkusForWireBases(probe.availableModels ?? [], wires);
return cliSkus.length > 0 ? { ...response, cliModelSkus: cliSkus } : response;
} catch {
return response;
}
}
export type ListCursorModelsResponse = CursorModelsResponse;
@@ -104,9 +181,52 @@ async function runCursorModelProbe(): Promise<ListCursorModelsResponse> {
});
}
async function applyInMemoryCache(response: ListCursorModelsResponse): Promise<ListCursorModelsResponse> {
const enriched = await enrichCursorModelsWithCliSkus(response);
if ((enriched.availableModels?.length ?? 0) > 0) {
cache.expiresAt = Date.now() + CACHE_TTL_MS;
cache.response = enriched;
writeSharedCursorModelsCache(enriched);
}
return enriched;
}
/** ACP session snapshot (Zed-style); falls back to seeded / on-disk cache from the last live session. */
async function listCursorModelsWhileAcpActive(): Promise<ListCursorModelsResponse> {
const acp = getCursorAcpModelsSnapshot();
if (acp && acp.availableModels.length > 0) {
return applyInMemoryCache({ success: true, ...acp });
}
// Session child writes the on-disk cache; prefer it over this process's in-memory entry.
const shared = readSharedCursorModelsCache();
if (shared) {
return applyInMemoryCache(shared);
}
if (cache.expiresAt > Date.now() && (cache.response.availableModels?.length ?? 0) > 0) {
const shared = readSharedCursorModelsCache();
const cachedSkus = cache.response.cliModelSkus ?? shared?.cliModelSkus ?? [];
return attachCliSkusToResponse(cache.response, cachedSkus);
}
return { success: true, availableModels: [], currentModelId: null };
}
export async function listCursorModels(): Promise<ListCursorModelsResponse> {
if (cache.expiresAt > Date.now()) {
return cache.response;
if (isAgentAcpTransportActive()) {
return listCursorModelsWhileAcpActive();
}
const acp = getCursorAcpModelsSnapshot();
if (acp && acp.availableModels.length > 0) {
return applyInMemoryCache({ success: true, ...acp });
}
if (cache.expiresAt > Date.now() && (cache.response.availableModels?.length ?? 0) > 0) {
return enrichCursorModelsWithCliSkus(cache.response);
}
const shared = readSharedCursorModelsCache();
if (shared) {
return applyInMemoryCache(shared);
}
if (inflight) {
@@ -115,10 +235,24 @@ export async function listCursorModels(): Promise<ListCursorModelsResponse> {
inflight = (async () => {
try {
const response = await runCursorModelProbe();
cache.expiresAt = Date.now() + CACHE_TTL_MS;
cache.response = response;
return response;
const acpResponse = await runCursorAcpModelProbe();
if (cursorProbeResponseHasWireCatalog(acpResponse)) {
return applyInMemoryCache(acpResponse);
}
const probeResponse = await runCursorModelProbe();
if (cursorProbeResponseHasWireCatalog(probeResponse)) {
return applyInMemoryCache(probeResponse);
}
// CLI `--list-models` returns slug ids without bracket params; never cache
// those for the web picker (New Session would show only Default + current slug).
if (acpResponse.success) {
return acpResponse;
}
return probeResponse.success
? { success: true, availableModels: [], currentModelId: null }
: probeResponse;
} catch (error) {
return {
success: false,
@@ -132,8 +266,13 @@ export async function listCursorModels(): Promise<ListCursorModelsResponse> {
return inflight;
}
export function seedCursorModelsCache(response: ListCursorModelsResponse): void {
void applyInMemoryCache(response);
}
export function _resetCursorModelsCacheForTests(): void {
cache.expiresAt = 0;
cache.response = { success: true, availableModels: [], currentModelId: null };
inflight = null;
_resetSharedCursorModelsCacheForTests();
}