@stablekernel/opencode-cursor 0.2.0 → 0.4.0-rc.1

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.
@@ -562,8 +562,65 @@ function loadAgentBackend() {
562
562
  return cached3;
563
563
  }
564
564
 
565
+ // src/provider/session-store.ts
566
+ import { mkdirSync, readFileSync, rmSync, writeFileSync } from "fs";
567
+ import { homedir, tmpdir } from "os";
568
+ import { join as join2 } from "path";
569
+ var ENTRY_TTL_MS = 7 * 24 * 60 * 60 * 1e3;
570
+ var MAX_ENTRIES = 200;
571
+ function storeDir() {
572
+ const base = process.env.XDG_CACHE_HOME?.trim() || (homedir() ? join2(homedir(), ".cache") : tmpdir());
573
+ return join2(base, "opencode-cursor");
574
+ }
575
+ function storeFile() {
576
+ return join2(storeDir(), "session-pool.json");
577
+ }
578
+ function isStoredRecord(value) {
579
+ if (typeof value !== "object" || value === null) return false;
580
+ const v = value;
581
+ return typeof v["agentId"] === "string" && typeof v["systemHash"] === "string" && Array.isArray(v["userHashes"]) && v["userHashes"].every((h) => typeof h === "string") && typeof v["updatedAt"] === "number";
582
+ }
583
+ function loadSessionRecords(now = Date.now()) {
584
+ const out = /* @__PURE__ */ new Map();
585
+ try {
586
+ const parsed = JSON.parse(
587
+ readFileSync(storeFile(), "utf8")
588
+ );
589
+ if (typeof parsed?.sessions !== "object" || parsed.sessions === null)
590
+ return out;
591
+ for (const [key, value] of Object.entries(parsed.sessions)) {
592
+ if (!isStoredRecord(value)) continue;
593
+ if (now - value.updatedAt > ENTRY_TTL_MS) continue;
594
+ out.set(key, value);
595
+ }
596
+ } catch {
597
+ }
598
+ return out;
599
+ }
600
+ function saveSessionRecords(records, now = Date.now()) {
601
+ try {
602
+ const live = [...records.entries()].filter(([, r]) => now - r.updatedAt <= ENTRY_TTL_MS).sort(([, a], [, b]) => b.updatedAt - a.updatedAt).slice(0, MAX_ENTRIES);
603
+ mkdirSync(storeDir(), { recursive: true });
604
+ const envelope = { sessions: Object.fromEntries(live) };
605
+ writeFileSync(storeFile(), JSON.stringify(envelope), "utf8");
606
+ } catch {
607
+ }
608
+ }
609
+
565
610
  // src/provider/session-pool.ts
566
611
  var pool = /* @__PURE__ */ new Map();
612
+ var hydrated = false;
613
+ function hydrate() {
614
+ if (hydrated) return;
615
+ hydrated = true;
616
+ for (const [key, record] of loadSessionRecords()) {
617
+ if (!pool.has(key)) pool.set(key, record);
618
+ }
619
+ }
620
+ function getSessionRecord(sessionID) {
621
+ hydrate();
622
+ return pool.get(sessionID);
623
+ }
567
624
  async function acquireAgent(params) {
568
625
  const backend = loadAgentBackend();
569
626
  const createOptions = {
@@ -579,23 +636,30 @@ async function acquireAgent(params) {
579
636
  ...params.agents ? { agents: params.agents } : {},
580
637
  ...params.name ? { name: params.name } : {}
581
638
  };
582
- const pooling = params.session && Boolean(params.sessionID);
583
- const pooledId = pooling ? pool.get(params.sessionID) : void 0;
584
- const resumeId = params.agentId ?? pooledId;
585
639
  let agent;
586
640
  let resumed = false;
587
- if (resumeId) {
641
+ if (params.resumeAgentId) {
588
642
  try {
589
- agent = await backend.resumeAgent(resumeId, createOptions);
643
+ agent = await backend.resumeAgent(params.resumeAgentId, createOptions);
590
644
  resumed = true;
591
645
  } catch {
592
- if (pooledId && resumeId === pooledId) pool.delete(params.sessionID);
593
646
  }
594
647
  }
595
648
  if (!agent) {
596
649
  agent = await backend.createAgent(createOptions);
597
650
  }
598
- if (pooling) pool.set(params.sessionID, agent.agentId);
651
+ const pooling = params.poolKey !== void 0;
652
+ if (pooling && params.record) {
653
+ hydrate();
654
+ pool.set(params.poolKey, {
655
+ agentId: agent.agentId,
656
+ systemHash: params.record.systemHash,
657
+ userHashes: params.record.userHashes,
658
+ ...params.record.mcpHash !== void 0 ? { mcpHash: params.record.mcpHash } : {},
659
+ updatedAt: Date.now()
660
+ });
661
+ saveSessionRecords(pool);
662
+ }
599
663
  const release = () => {
600
664
  if (!pooling) {
601
665
  try {
@@ -614,6 +678,7 @@ export {
614
678
  buildModelSelection,
615
679
  resolveControls,
616
680
  loadCursorSdk,
681
+ getSessionRecord,
617
682
  acquireAgent
618
683
  };
619
- //# sourceMappingURL=chunk-D4YQ7ZEM.js.map
684
+ //# sourceMappingURL=chunk-BTI2NHEE.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/api-key.ts","../src/provider/agent-events.ts","../src/provider/controls.ts","../src/native-binding.ts","../src/cursor-runtime.ts","../src/provider/agent-backend.ts","../src/provider/sidecar-client.ts","../src/provider/session-store.ts","../src/provider/session-pool.ts"],"sourcesContent":["import { createHash } from \"node:crypto\";\n\n/** Environment variable the Cursor SDK itself reads as a fallback. */\nexport const CURSOR_API_KEY_ENV_VAR = \"CURSOR_API_KEY\";\n\n/**\n * Values that are *not* real keys but rather instructions to read the key from\n * the environment. opencode config commonly stores literal `{env:...}` style\n * placeholders, and users sometimes paste the variable name itself.\n */\nconst PLACEHOLDERS = new Set<string>([\n CURSOR_API_KEY_ENV_VAR,\n `$${CURSOR_API_KEY_ENV_VAR}`,\n `\\${${CURSOR_API_KEY_ENV_VAR}}`,\n]);\n\n/**\n * Resolve a usable Cursor API key.\n *\n * Resolution order: an explicit, non-placeholder candidate (e.g. from opencode\n * auth storage or provider options) wins; otherwise fall back to the\n * `CURSOR_API_KEY` environment variable. Returns `undefined` when no key is\n * available so callers can present a clear \"needs auth\" path.\n *\n * The key is never logged or persisted by this module.\n */\nexport function resolveCursorApiKey(candidate?: string | null): string | undefined {\n const trimmed = candidate?.trim();\n if (trimmed && !PLACEHOLDERS.has(trimmed)) return trimmed;\n const fromEnv = process.env[CURSOR_API_KEY_ENV_VAR]?.trim();\n return fromEnv ? fromEnv : undefined;\n}\n\n/**\n * Produce a short, non-reversible fingerprint of an API key. Used purely to key\n * the on-disk model cache so the cache invalidates when the key changes. The\n * raw key is never written to disk.\n */\nexport function fingerprintApiKey(apiKey: string): string {\n return createHash(\"sha256\").update(apiKey).digest(\"hex\").slice(0, 16);\n}\n","import type { AgentModeOption, SDKUserMessage } from \"@cursor/sdk\";\nimport type { AgentLike, AgentRunLike } from \"./agent-backend.js\";\n\n/** Token usage as reported by Cursor's `turn-ended` update. */\nexport interface CursorUsage {\n inputTokens: number;\n outputTokens: number;\n cacheReadTokens: number;\n cacheWriteTokens: number;\n}\n\n/** Normalized events bridged from the Cursor SDK's push callbacks. */\nexport type CursorEvent =\n | { type: \"text-delta\"; text: string }\n | { type: \"reasoning-delta\"; text: string }\n | { type: \"tool-call\"; id: string; name: string; input: unknown }\n | { type: \"tool-result\"; id: string; name: string; result: unknown; isError: boolean }\n | { type: \"usage\"; usage: CursorUsage }\n | { type: \"finish\"; text?: string };\n\nexport interface StreamAgentTurnOptions {\n mode: AgentModeOption;\n abortSignal?: AbortSignal;\n}\n\n/**\n * Human-readable name for a Cursor tool call. Most Cursor tools carry their\n * name in `toolCall.type` (shell/read/edit/…), but an MCP tool call has\n * `type: \"mcp\"` with the real tool in `args.toolName` (and server in\n * `args.providerIdentifier`) — surface that instead of the literal \"mcp\".\n */\nfunction toolDisplayName(toolCall: ({ type?: string } & Record<string, any>) | undefined): string {\n if (!toolCall) return \"tool\";\n if (toolCall.type === \"mcp\") {\n const name = toolCall.args?.toolName;\n const server = toolCall.args?.providerIdentifier;\n if (name) return server ? `${server}/${name}` : String(name);\n return \"mcp\";\n }\n return toolCall.type ?? \"tool\";\n}\n\n/**\n * Stream a single turn on an already-acquired Cursor agent and yield normalized\n * events. The agent's lifecycle (create/resume/close) is owned by the caller\n * (see session-pool.ts) so it can be reused across turns. The SDK streams via\n * `onDelta` callbacks; we bridge those into a pull-based async generator so both\n * `doStream` and `doGenerate` can consume them.\n */\nexport async function* streamAgentTurn(\n agent: AgentLike,\n message: SDKUserMessage,\n options: StreamAgentTurnOptions,\n): AsyncGenerator<CursorEvent> {\n const queue: CursorEvent[] = [];\n let wake: (() => void) | undefined;\n let finished = false;\n let failure: unknown;\n\n // Opt-in stderr tracing of what the live agent emits (set OPENCODE_CURSOR_DEBUG=1).\n const debug = process.env.OPENCODE_CURSOR_DEBUG === \"1\";\n const counts: Record<string, number> = {};\n\n const push = (event: CursorEvent) => {\n queue.push(event);\n wake?.();\n wake = undefined;\n };\n\n const onDelta = ({ update }: { update: { type: string } & Record<string, any> }) => {\n if (debug) counts[update.type] = (counts[update.type] ?? 0) + 1;\n switch (update.type) {\n case \"text-delta\":\n push({ type: \"text-delta\", text: update.text });\n break;\n case \"thinking-delta\":\n push({ type: \"reasoning-delta\", text: update.text });\n break;\n case \"tool-call-started\":\n push({\n type: \"tool-call\",\n id: String(update.callId),\n name: toolDisplayName(update.toolCall),\n input: update.toolCall?.args ?? {},\n });\n break;\n case \"tool-call-completed\": {\n const tool = update.toolCall ?? {};\n const result = tool.result;\n // MCP failures often arrive as {status:\"success\", value:{isError:true}}\n // (the MCP-protocol error flag), not as a top-level status error.\n const mcpError = tool.type === \"mcp\" && result?.value?.isError === true;\n push({\n type: \"tool-result\",\n id: String(update.callId),\n name: toolDisplayName(tool),\n result: result ?? null,\n isError: result?.status === \"error\" || mcpError,\n });\n break;\n }\n case \"turn-ended\":\n if (update.usage) push({ type: \"usage\", usage: update.usage as CursorUsage });\n break;\n }\n };\n\n const runHolder: { run?: AgentRunLike } = {};\n const onAbort = () => {\n void Promise.resolve(runHolder.run?.cancel()).catch(() => {});\n };\n options.abortSignal?.addEventListener(\"abort\", onAbort);\n\n // A previous opencode/CLI crash (or a second instance racing on the same\n // agent store) can leave a persisted run wedged; the SDK then rejects new\n // sends with AgentBusyError. Retry once with the SDK's documented recovery\n // path (local.force expires the wedged run) instead of failing the turn.\n const sendTurn = async (): Promise<AgentRunLike> => {\n try {\n return await agent.send(message, { mode: options.mode, onDelta });\n } catch (err) {\n if (err instanceof Error && err.name === \"AgentBusyError\") {\n if (debug) console.error(\"[cursor:debug] agent busy; retrying send with local.force\");\n return agent.send(message, { mode: options.mode, onDelta, local: { force: true } });\n }\n throw err;\n }\n };\n\n // Kick off the turn. Resolve text from run.wait() for models that don't emit\n // incremental text deltas.\n void sendTurn()\n .then(async (run) => {\n runHolder.run = run;\n const result = await run.wait();\n if (debug) {\n console.error(\n `[cursor:debug] updates=${JSON.stringify(counts)} status=${result.status} resultLen=${(result.result ?? \"\").length}`,\n );\n }\n if (result.status === \"error\") {\n // Surface the failure instead of finishing silently — a silent stop\n // leaves opencode showing dangling tool calls with no explanation.\n throw new Error(\n `Cursor run ended with status \"error\"${result.result ? `: ${result.result}` : \"\"}`,\n );\n }\n // A cancelled run finishes without fabricating final text.\n push({ type: \"finish\", ...(result.status === \"cancelled\" ? {} : { text: result.result }) });\n })\n .catch((err) => {\n failure = err;\n if (debug) console.error(`[cursor:debug] send failed: ${err instanceof Error ? err.message : String(err)}`);\n })\n .finally(() => {\n finished = true;\n wake?.();\n wake = undefined;\n });\n\n try {\n while (true) {\n if (queue.length > 0) {\n yield queue.shift()!;\n continue;\n }\n if (finished) break;\n await new Promise<void>((resolve) => {\n wake = resolve;\n });\n }\n // Drain anything queued right before completion.\n while (queue.length > 0) yield queue.shift()!;\n if (failure) throw failure;\n } finally {\n options.abortSignal?.removeEventListener(\"abort\", onAbort);\n }\n}\n","import type { AgentModeOption, ModelSelection } from \"@cursor/sdk\";\n\n/** Per-model static control defaults (from provider/model config options). */\nexport interface StaticControls {\n mode: AgentModeOption;\n /** Default Cursor model params (id -> value), e.g. { thinking: \"high\" }. */\n params?: Record<string, string>;\n}\n\nexport interface ResolvedControls {\n mode: AgentModeOption;\n modelSelection: ModelSelection;\n}\n\n/**\n * Build a Cursor `ModelSelection` from a model id and an optional map of model\n * params (e.g. `{ thinking: \"high\" }`). Shared by the provider control\n * resolution and the cloud/delegate tools so param handling stays consistent.\n */\nexport function buildModelSelection(\n modelId: string,\n params?: Record<string, string>,\n): ModelSelection {\n const paramList = Object.entries(params ?? {}).map(([id, value]) => ({ id, value }));\n return paramList.length > 0 ? { id: modelId, params: paramList } : { id: modelId };\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction isMode(value: unknown): value is AgentModeOption {\n return value === \"agent\" || value === \"plan\";\n}\n\n/**\n * Resolve the per-turn Cursor controls from static config plus opencode's\n * per-request `providerOptions.cursor` (which carries merged model `options` and\n * the selected model `variant`). Per-request values win over static defaults.\n *\n * Recognized keys in `providerOptions.cursor`:\n * - `mode`: \"agent\" | \"plan\"\n * - `params`: Record<string,string> of Cursor model params (e.g. { thinking: \"high\" })\n * - `thinking`: string convenience, mapped to the `thinking` param if not already set\n */\nexport function resolveControls(\n modelId: string,\n staticControls: StaticControls,\n providerOptions: Record<string, unknown> | undefined,\n): ResolvedControls {\n const po = providerOptions ?? {};\n\n const mode: AgentModeOption = isMode(po[\"mode\"]) ? po[\"mode\"] : staticControls.mode;\n\n const params: Record<string, string> = { ...(staticControls.params ?? {}) };\n if (isRecord(po[\"params\"])) {\n for (const [key, value] of Object.entries(po[\"params\"])) {\n if (value != null) params[key] = String(value);\n }\n }\n if (typeof po[\"thinking\"] === \"string\" && params[\"thinking\"] === undefined) {\n params[\"thinking\"] = po[\"thinking\"];\n }\n\n return { mode, modelSelection: buildModelSelection(modelId, params) };\n}\n","/**\n * Self-heal for sqlite3's native binding.\n *\n * `@cursor/sdk` depends on `sqlite3` (a native addon). opencode installs\n * plugin packages with Bun, which does not run sqlite3's `install` lifecycle\n * script (`prebuild-install -r napi || node-gyp rebuild`), so the installed\n * tree has **no** `node_sqlite3.node` binary and the SDK crashes at import\n * with \"Could not locate the bindings file\".\n *\n * Before loading the SDK (in-process or via the Node sidecar) we check for a\n * binding and, when it is missing, run sqlite3's own `prebuild-install -r napi`\n * to fetch the prebuilt NAPI binary (ABI-portable across Node versions, also\n * loadable by Bun). Failures degrade to a clear warning; the SDK import then\n * surfaces its own error.\n */\nimport { execSync, spawn } from \"node:child_process\";\nimport { existsSync, readdirSync, statSync } from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport { dirname, join } from \"node:path\";\n\nexport type EnsureResult = \"present\" | \"repaired\" | \"failed\" | \"not-found\";\n\nexport interface EnsureOptions {\n /** Override the sqlite3 package directory (tests). */\n sqliteDir?: string;\n /** Override the repair runner (tests). Returns true when the command succeeded. */\n run?: (sqliteDir: string) => Promise<boolean>;\n /** Override the warning sink (tests). */\n log?: (message: string) => void;\n}\n\n/** Directories (relative to the sqlite3 package root) that may hold the binding. */\nconst BINDING_ROOTS = [\"build\", \"lib/binding\", \"compiled\"];\n\nfunction hasNodeFile(dir: string, depth: number): boolean {\n if (depth < 0) return false;\n let entries: string[];\n try {\n entries = readdirSync(dir);\n } catch {\n return false;\n }\n for (const entry of entries) {\n const path = join(dir, entry);\n if (entry.endsWith(\".node\")) {\n try {\n if (statSync(path).isFile()) return true;\n } catch {\n // ignore unreadable entries\n }\n continue;\n }\n try {\n if (statSync(path).isDirectory() && hasNodeFile(path, depth - 1)) return true;\n } catch {\n // ignore unreadable entries\n }\n }\n return false;\n}\n\n/** True when the sqlite3 package dir contains a compiled `.node` binding. */\nexport function hasSqliteBinding(sqliteDir: string): boolean {\n return BINDING_ROOTS.some((root) => hasNodeFile(join(sqliteDir, root), 3));\n}\n\n/**\n * Locate the sqlite3 package directory that `@cursor/sdk` will load, walking\n * the same resolution chain (our module -> @cursor/sdk -> sqlite3).\n */\nexport function resolveSqliteDir(): string | undefined {\n const req = createRequire(import.meta.url);\n try {\n const sdkPkg = req.resolve(\"@cursor/sdk/package.json\");\n return dirname(createRequire(sdkPkg).resolve(\"sqlite3/package.json\"));\n } catch {\n // fall through: try resolving sqlite3 directly (hoisted installs)\n }\n try {\n return dirname(req.resolve(\"sqlite3/package.json\"));\n } catch {\n return undefined;\n }\n}\n\nfunction detectNodeExecutable(): string {\n const isBun = typeof (globalThis as { Bun?: unknown }).Bun !== \"undefined\";\n if (!isBun) return process.execPath;\n // Under Bun prefer a real Node (matches the sidecar runtime); prebuild-install\n // itself is plain JS, so Bun works as a last resort.\n try {\n const out = execSync(process.platform === \"win32\" ? \"where node\" : \"command -v node\", {\n encoding: \"utf8\",\n stdio: [\"ignore\", \"pipe\", \"ignore\"],\n }).trim();\n return out.split(\"\\n\")[0] || process.execPath;\n } catch {\n return process.execPath;\n }\n}\n\n/** Default repair: run sqlite3's own `prebuild-install -r napi` in its package dir. */\nasync function runPrebuildInstall(sqliteDir: string): Promise<boolean> {\n let bin: string;\n try {\n const req = createRequire(join(sqliteDir, \"package.json\"));\n const pkgPath = req.resolve(\"prebuild-install/package.json\");\n const pkg = (await import(pkgPath, { with: { type: \"json\" } })) as {\n default: { bin?: string | Record<string, string> };\n };\n const binField = pkg.default.bin;\n const rel = typeof binField === \"string\" ? binField : binField?.[\"prebuild-install\"];\n if (!rel) return false;\n bin = join(dirname(pkgPath), rel);\n } catch {\n return false;\n }\n if (!existsSync(bin)) return false;\n\n return new Promise<boolean>((resolve) => {\n const child = spawn(detectNodeExecutable(), [bin, \"-r\", \"napi\"], {\n cwd: sqliteDir,\n stdio: [\"ignore\", \"ignore\", \"pipe\"],\n });\n let stderr = \"\";\n child.stderr?.on(\"data\", (chunk: Buffer) => {\n stderr += chunk.toString();\n });\n child.on(\"error\", () => resolve(false));\n child.on(\"exit\", (code) => {\n if (code !== 0 && stderr && process.env[\"OPENCODE_CURSOR_DEBUG\"]) {\n console.error(`[opencode-cursor] prebuild-install stderr: ${stderr.trim()}`);\n }\n resolve(code === 0);\n });\n });\n}\n\nlet cached: Promise<EnsureResult> | undefined;\n\n/**\n * Ensure the sqlite3 native binding exists, repairing it once per process if\n * needed. Never throws; \"failed\"/\"not-found\" outcomes warn and let the SDK\n * import surface its own error.\n */\nexport function ensureSqliteBinding(options: EnsureOptions = {}): Promise<EnsureResult> {\n cached ??= (async () => {\n const log = options.log ?? ((message: string) => console.error(message));\n const sqliteDir = options.sqliteDir ?? resolveSqliteDir();\n if (!sqliteDir || !existsSync(join(sqliteDir, \"package.json\"))) {\n return \"not-found\";\n }\n if (hasSqliteBinding(sqliteDir)) return \"present\";\n\n const run = options.run ?? runPrebuildInstall;\n const ok = await run(sqliteDir).catch(() => false);\n if (ok && hasSqliteBinding(sqliteDir)) return \"repaired\";\n\n log(\n `[opencode-cursor] sqlite3 native binding is missing in ${sqliteDir} and automatic ` +\n `repair failed. @cursor/sdk will not load. Fix manually with: ` +\n `cd ${sqliteDir} && npx prebuild-install -r napi (or: npm rebuild sqlite3)`,\n );\n return \"failed\";\n })();\n return cached;\n}\n\n/** Test hook. */\nexport function resetNativeBinding(): void {\n cached = undefined;\n}\n","/**\n * Lazy loader for the official Cursor SDK (`@cursor/sdk`).\n *\n * The SDK is heavy and only needed once a Cursor model is actually used or\n * models are discovered, so it is imported on demand. A failed import (e.g. the\n * dependency is missing) degrades gracefully into a clear error instead of\n * crashing opencode at startup.\n */\nimport { ensureSqliteBinding } from \"./native-binding.js\";\n\nexport type CursorSdkModule = typeof import(\"@cursor/sdk\");\n\nlet cached: Promise<CursorSdkModule> | undefined;\n\nexport async function loadCursorSdk(): Promise<CursorSdkModule> {\n if (!cached) {\n // @cursor/sdk eagerly requires sqlite3 (native addon); opencode's Bun\n // install skips its build script, so repair the binding first if missing.\n cached = ensureSqliteBinding()\n .then(() => import(\"@cursor/sdk\"))\n .catch((err: unknown) => {\n // Allow a later retry if the failure was transient.\n cached = undefined;\n const detail = err instanceof Error ? err.message : String(err);\n throw new Error(\n `[opencode-cursor] Failed to load \"@cursor/sdk\". Make sure it is installed ` +\n `(\\`npm install @cursor/sdk\\`). Original error: ${detail}`,\n );\n });\n }\n return cached;\n}\n","/**\n * Selects where Cursor agents run:\n *\n * - \"in-process\": straight through `@cursor/sdk` in this process (Node — the\n * normal path for tests, scripts, and any non-Bun host).\n * - \"sidecar\": a spawned Node child hosting the SDK (Bun — opencode's runtime —\n * has a `node:http2` bug that kills Cursor's streaming RPC with\n * NGHTTP2_FRAME_SIZE_ERROR, losing tool-completion updates; see\n * src/sidecar/agent-host.mjs).\n *\n * Override with OPENCODE_CURSOR_SIDECAR=1/0 (force on/off).\n */\nimport { execSync } from \"node:child_process\";\nimport { existsSync } from \"node:fs\";\nimport { fileURLToPath } from \"node:url\";\nimport { loadCursorSdk } from \"../cursor-runtime.js\";\nimport { ensureSqliteBinding } from \"../native-binding.js\";\nimport { SidecarClient, type AgentLike } from \"./sidecar-client.js\";\n\nexport type { AgentLike, AgentRunLike, AgentSendOptions } from \"./sidecar-client.js\";\n\nexport type BackendKind = \"in-process\" | \"sidecar\";\n\nexport interface AgentBackend {\n kind: BackendKind;\n createAgent(options: unknown): Promise<AgentLike>;\n resumeAgent(agentId: string, options: unknown): Promise<AgentLike>;\n}\n\nexport interface BackendEnvironment {\n isBun: boolean;\n /** Resolved node executable, or undefined when not on PATH. */\n nodePath: string | undefined;\n}\n\n/** Pure selection logic (unit-testable without spawning anything). */\nexport function resolveBackendKind(env: BackendEnvironment): BackendKind {\n const override = process.env[\"OPENCODE_CURSOR_SIDECAR\"];\n if (override === \"0\" || override === \"false\") return \"in-process\";\n if (override === \"1\" || override === \"true\") return env.nodePath ? \"sidecar\" : \"in-process\";\n return env.isBun && env.nodePath ? \"sidecar\" : \"in-process\";\n}\n\nfunction detectNode(): string | undefined {\n try {\n const out = execSync(process.platform === \"win32\" ? \"where node\" : \"command -v node\", {\n encoding: \"utf8\",\n stdio: [\"ignore\", \"pipe\", \"ignore\"],\n }).trim();\n return out.split(\"\\n\")[0] || undefined;\n } catch {\n return undefined;\n }\n}\n\nfunction detectEnvironment(): BackendEnvironment {\n const isBun = typeof (globalThis as { Bun?: unknown }).Bun !== \"undefined\";\n // Only pay the PATH lookup when the answer can matter.\n const needsNode = isBun || process.env[\"OPENCODE_CURSOR_SIDECAR\"] === \"1\";\n return { isBun, nodePath: needsNode ? detectNode() : process.execPath };\n}\n\nfunction inProcessBackend(): AgentBackend {\n return {\n kind: \"in-process\",\n createAgent: async (options) => {\n const { Agent } = await loadCursorSdk();\n return (await Agent.create(options as never)) as unknown as AgentLike;\n },\n resumeAgent: async (agentId, options) => {\n const { Agent } = await loadCursorSdk();\n return (await Agent.resume(agentId, options as never)) as unknown as AgentLike;\n },\n };\n}\n\n/**\n * Locate the sidecar script across layouts: tsup may place this module in\n * dist/provider/index.js or hoist it into a root-level dist/chunk-*.js, and in\n * dev/tests it runs straight from src/. Try each known relative position.\n */\nexport function resolveSidecarScript(): string | undefined {\n const candidates = [\n \"./sidecar/agent-host.js\", // importer is a chunk at dist root\n \"../sidecar/agent-host.js\", // importer is dist/provider/index.js\n \"../sidecar/agent-host.mjs\", // importer is src/provider/*.ts (dev/tests)\n ];\n for (const candidate of candidates) {\n const path = fileURLToPath(new URL(candidate, import.meta.url));\n if (existsSync(path)) return path;\n }\n return undefined;\n}\n\nfunction sidecarBackend(nodePath: string, scriptPath: string): AgentBackend {\n const client = new SidecarClient({ scriptPath, nodePath });\n // The sidecar imports @cursor/sdk (which eagerly requires sqlite3's native\n // binding) in the child process; repair the binding before first use.\n return {\n kind: \"sidecar\",\n createAgent: async (options) => {\n await ensureSqliteBinding();\n return client.createAgent(options);\n },\n resumeAgent: async (agentId, options) => {\n await ensureSqliteBinding();\n return client.resumeAgent(agentId, options);\n },\n };\n}\n\nlet cached: AgentBackend | undefined;\n\n/** Resolve (and cache) the agent backend for this process. */\nexport function loadAgentBackend(): AgentBackend {\n if (!cached) {\n const env = detectEnvironment();\n const kind = resolveBackendKind(env);\n const scriptPath = kind === \"sidecar\" ? resolveSidecarScript() : undefined;\n // A user who explicitly opted out (OPENCODE_CURSOR_SIDECAR=0/false) has\n // accepted the in-process behavior and should not be warned.\n const override = process.env[\"OPENCODE_CURSOR_SIDECAR\"];\n const optedOut = override === \"0\" || override === \"false\";\n if (env.isBun && !optedOut && (kind === \"in-process\" || !scriptPath)) {\n console.error(\n \"[opencode-cursor] Running under Bun without a usable Node sidecar \" +\n `(node: ${env.nodePath ?? \"not found\"}, script: ${scriptPath ?? \"not found\"}): ` +\n \"Cursor native tool calls may fail (Bun node:http2 incompatibility). \" +\n \"Install Node.js to enable the sidecar, or set OPENCODE_CURSOR_SIDECAR=0 \" +\n \"to silence this warning.\",\n );\n }\n cached =\n kind === \"sidecar\" && env.nodePath && scriptPath\n ? sidecarBackend(env.nodePath, scriptPath)\n : inProcessBackend();\n }\n return cached;\n}\n\n/** Test hook. */\nexport function resetAgentBackend(): void {\n cached = undefined;\n}\n","/**\n * Client half of the Node sidecar (see src/sidecar/agent-host.mjs for the\n * protocol and the why). Spawns one Node child per client and multiplexes\n * agent create/resume/send/cancel/close requests over JSON-lines stdio,\n * exposing agents through the same minimal surface the provider already\n * consumes ({@link AgentLike}), so session-pool/agent-events need no\n * sidecar-specific logic.\n */\nimport { spawn, type ChildProcessByStdio } from \"node:child_process\";\nimport { createInterface, type Interface } from \"node:readline\";\nimport type { Readable, Writable } from \"node:stream\";\n\n/** Minimal run surface the provider consumes (subset of the SDK's Run). */\nexport interface AgentRunLike {\n wait(): Promise<{ status: string; result?: string }>;\n cancel(): void | Promise<void>;\n}\n\nexport interface AgentSendOptions {\n mode?: string;\n onDelta?: (input: { update: Record<string, unknown> & { type: string } }) => void;\n local?: { force?: boolean };\n}\n\n/** Minimal agent surface the provider consumes (subset of the SDK's SDKAgent). */\nexport interface AgentLike {\n agentId: string;\n send(message: unknown, options?: AgentSendOptions): Promise<AgentRunLike>;\n close(): void;\n}\n\nexport interface SidecarClientOptions {\n /** Path to the agent-host script. */\n scriptPath: string;\n /** Node executable; default \"node\" from PATH. */\n nodePath?: string;\n /** Extra environment for the child (merged over process.env). */\n env?: Record<string, string>;\n /** Mirror child stderr to this process (debug aid). */\n debug?: boolean;\n}\n\ninterface Pending {\n resolve: (msg: Record<string, unknown>) => void;\n reject: (err: Error) => void;\n /** Streaming hooks for \"send\" requests. */\n onUpdate?: (update: Record<string, unknown> & { type: string }) => void;\n onResult?: (result: { status: string; result?: string }) => void;\n onStreamError?: (err: Error) => void;\n}\n\nfunction reviveError(error: unknown): Error {\n const e = (error ?? {}) as { name?: string; message?: string };\n const err = new Error(e.message ?? \"sidecar error\");\n if (e.name) err.name = e.name;\n return err;\n}\n\nexport class SidecarClient {\n private readonly options: SidecarClientOptions;\n private child: ChildProcessByStdio<Writable, Readable, Readable> | undefined;\n private reader: Interface | undefined;\n private readonly pending = new Map<number, Pending>();\n private nextId = 1;\n private disposed = false;\n\n constructor(options: SidecarClientOptions) {\n this.options = options;\n }\n\n /** Spawn (or reuse) the child process. */\n private ensureChild(): ChildProcessByStdio<Writable, Readable, Readable> {\n if (this.disposed) throw new Error(\"cursor sidecar client disposed\");\n if (this.child) return this.child;\n\n const child = spawn(this.options.nodePath ?? \"node\", [this.options.scriptPath], {\n stdio: [\"pipe\", \"pipe\", \"pipe\"],\n env: { ...process.env, ...this.options.env },\n });\n this.child = child;\n\n this.reader = createInterface({ input: child.stdout });\n this.reader.on(\"line\", (line) => this.handleLine(line));\n child.stderr.on(\"data\", (chunk: Buffer) => {\n if (this.options.debug || process.env[\"OPENCODE_CURSOR_DEBUG\"]) {\n process.stderr.write(`[cursor:sidecar] ${chunk}`);\n }\n });\n child.on(\"exit\", (code) => {\n this.failAll(new Error(`cursor sidecar exited (code ${code ?? \"unknown\"})`));\n this.child = undefined;\n this.reader?.close();\n this.reader = undefined;\n });\n child.on(\"error\", (err) => {\n this.failAll(new Error(`cursor sidecar failed to start: ${err.message}`));\n this.child = undefined;\n });\n this.updateRefs();\n return child;\n }\n\n /**\n * Keep the child (and its pipes) from holding the parent's event loop open\n * while idle, but ref it whenever a reply is outstanding so the loop can't\n * exit mid-request. Without this, any process that uses the provider and\n * never dispose()s — scripts, tests, opencode itself on shutdown — hangs.\n */\n private updateRefs(): void {\n const child = this.child;\n if (!child) return;\n const refable = [child, child.stdin, child.stdout, child.stderr] as Array<{\n ref?: () => void;\n unref?: () => void;\n }>;\n if (this.pending.size > 0) {\n for (const target of refable) target.ref?.();\n } else {\n for (const target of refable) target.unref?.();\n }\n }\n\n private failAll(err: Error): void {\n for (const pending of this.pending.values()) {\n pending.onStreamError?.(err);\n pending.reject(err);\n }\n this.pending.clear();\n this.updateRefs();\n }\n\n private handleLine(line: string): void {\n if (!line.trim()) return;\n let msg: Record<string, unknown>;\n try {\n msg = JSON.parse(line) as Record<string, unknown>;\n } catch {\n return; // ignore non-protocol noise on stdout\n }\n const id = msg[\"id\"];\n if (typeof id !== \"number\") return;\n const pending = this.pending.get(id);\n if (!pending) return;\n\n const ev = msg[\"ev\"];\n if (ev === \"update\") {\n pending.onUpdate?.(msg[\"update\"] as Record<string, unknown> & { type: string });\n return;\n }\n if (ev === \"result\") {\n this.pending.delete(id);\n this.updateRefs();\n pending.onResult?.(msg[\"result\"] as { status: string; result?: string });\n return;\n }\n if (ev === \"error\") {\n this.pending.delete(id);\n this.updateRefs();\n pending.onStreamError?.(reviveError(msg[\"error\"]));\n return;\n }\n\n if (msg[\"ok\"] === true) {\n // \"send\" acks stay pending for their streaming terminal event.\n if (!pending.onResult) {\n this.pending.delete(id);\n this.updateRefs();\n }\n pending.resolve(msg);\n } else {\n this.pending.delete(id);\n this.updateRefs();\n pending.reject(reviveError(msg[\"error\"]));\n }\n }\n\n private request(\n payload: Record<string, unknown>,\n hooks?: Pick<Pending, \"onUpdate\" | \"onResult\" | \"onStreamError\">,\n ): Promise<Record<string, unknown>> {\n const child = this.ensureChild();\n const id = this.nextId++;\n return new Promise<Record<string, unknown>>((resolve, reject) => {\n this.pending.set(id, { resolve, reject, ...hooks });\n this.updateRefs();\n child.stdin.write(`${JSON.stringify({ id, ...payload })}\\n`, (err) => {\n if (err) {\n this.pending.delete(id);\n this.updateRefs();\n reject(err);\n }\n });\n });\n }\n\n async createAgent(options: unknown): Promise<AgentLike> {\n const res = await this.request({ op: \"create\", options });\n return this.wrapAgent(String(res[\"agentId\"]));\n }\n\n async resumeAgent(agentId: string, options: unknown): Promise<AgentLike> {\n const res = await this.request({ op: \"resume\", agentId, options });\n return this.wrapAgent(String(res[\"agentId\"]));\n }\n\n private wrapAgent(agentId: string): AgentLike {\n return {\n agentId,\n send: (message, options) => this.sendTurn(agentId, message, options),\n close: () => {\n void this.request({ op: \"close\", agentId }).catch(() => {\n // best effort, mirrors SDKAgent.close()\n });\n },\n };\n }\n\n private async sendTurn(\n agentId: string,\n message: unknown,\n options?: AgentSendOptions,\n ): Promise<AgentRunLike> {\n let settle!: {\n resolve: (r: { status: string; result?: string }) => void;\n reject: (e: Error) => void;\n };\n const waited = new Promise<{ status: string; result?: string }>((resolve, reject) => {\n settle = { resolve, reject };\n });\n // Avoid unhandled-rejection noise when the consumer never calls wait().\n waited.catch(() => {});\n\n let sendId: number | undefined;\n const ack = this.request(\n {\n op: \"send\",\n agentId,\n message,\n ...(options?.mode ? { mode: options.mode } : {}),\n ...(options?.local?.force ? { force: true } : {}),\n },\n {\n onUpdate: (update) => options?.onDelta?.({ update }),\n onResult: (result) => settle.resolve(result),\n onStreamError: (err) => settle.reject(err),\n },\n );\n // The request id is allocated synchronously inside request(); capture it\n // for cancel by reading the id we just used.\n sendId = this.nextId - 1;\n\n await ack;\n return {\n wait: () => waited,\n cancel: async () => {\n if (sendId === undefined) return;\n await this.request({ op: \"cancel\", sendId }).catch(() => {});\n },\n };\n }\n\n /** Kill the child and reject anything in flight. */\n dispose(): void {\n this.disposed = true;\n this.failAll(new Error(\"cursor sidecar client disposed\"));\n this.reader?.close();\n this.reader = undefined;\n this.child?.kill();\n this.child = undefined;\n }\n}\n","import { mkdirSync, readFileSync, rmSync, writeFileSync } from \"node:fs\";\nimport { homedir, tmpdir } from \"node:os\";\nimport { join } from \"node:path\";\nimport type { TranscriptRecord } from \"./transcript-fingerprint.js\";\n\n/**\n * Best-effort disk persistence for the session pool's fingerprint records, so\n * `session: \"auto\"` survives opencode restarts: the pool can re-resume a\n * session's Cursor agent (whose conversation lives in Cursor's own checkpoint\n * store) instead of paying a cache-cold full-transcript replay.\n *\n * Follows the model-cache pattern: JSON under `~/.cache/opencode-cursor/`,\n * never throws, treats the file as an optimization only. Multiple opencode\n * processes write last-wins on the whole file — a lost record costs exactly\n * one self-healing full replay, which is the same as not having the store.\n */\n\n/** A record persists this long after its last turn before being pruned. */\nconst ENTRY_TTL_MS = 7 * 24 * 60 * 60 * 1000;\n/** Cap stored sessions (most recently used win) to bound file growth. */\nconst MAX_ENTRIES = 200;\n\nexport interface StoredSessionRecord extends TranscriptRecord {\n\tupdatedAt: number;\n}\n\ninterface StoreEnvelope {\n\tsessions: Record<string, StoredSessionRecord>;\n}\n\nfunction storeDir(): string {\n\tconst base =\n\t\tprocess.env.XDG_CACHE_HOME?.trim() ||\n\t\t(homedir() ? join(homedir(), \".cache\") : tmpdir());\n\treturn join(base, \"opencode-cursor\");\n}\n\nfunction storeFile(): string {\n\treturn join(storeDir(), \"session-pool.json\");\n}\n\nfunction isStoredRecord(value: unknown): value is StoredSessionRecord {\n\tif (typeof value !== \"object\" || value === null) return false;\n\tconst v = value as Record<string, unknown>;\n\treturn (\n\t\ttypeof v[\"agentId\"] === \"string\" &&\n\t\ttypeof v[\"systemHash\"] === \"string\" &&\n\t\tArray.isArray(v[\"userHashes\"]) &&\n\t\t(v[\"userHashes\"] as unknown[]).every((h) => typeof h === \"string\") &&\n\t\ttypeof v[\"updatedAt\"] === \"number\"\n\t);\n}\n\n/** Load persisted records, dropping expired/corrupt entries. Never throws. */\nexport function loadSessionRecords(\n\tnow = Date.now(),\n): Map<string, StoredSessionRecord> {\n\tconst out = new Map<string, StoredSessionRecord>();\n\ttry {\n\t\tconst parsed = JSON.parse(\n\t\t\treadFileSync(storeFile(), \"utf8\"),\n\t\t) as StoreEnvelope;\n\t\tif (typeof parsed?.sessions !== \"object\" || parsed.sessions === null)\n\t\t\treturn out;\n\t\tfor (const [key, value] of Object.entries(parsed.sessions)) {\n\t\t\tif (!isStoredRecord(value)) continue;\n\t\t\tif (now - value.updatedAt > ENTRY_TTL_MS) continue;\n\t\t\tout.set(key, value);\n\t\t}\n\t} catch {\n\t\t// Missing/corrupt store: start empty.\n\t}\n\treturn out;\n}\n\n/** Persist records (pruned to TTL + entry cap). Best-effort; never throws. */\nexport function saveSessionRecords(\n\trecords: ReadonlyMap<string, StoredSessionRecord>,\n\tnow = Date.now(),\n): void {\n\ttry {\n\t\tconst live = [...records.entries()]\n\t\t\t.filter(([, r]) => now - r.updatedAt <= ENTRY_TTL_MS)\n\t\t\t.sort(([, a], [, b]) => b.updatedAt - a.updatedAt)\n\t\t\t.slice(0, MAX_ENTRIES);\n\t\tmkdirSync(storeDir(), { recursive: true });\n\t\tconst envelope: StoreEnvelope = { sessions: Object.fromEntries(live) };\n\t\twriteFileSync(storeFile(), JSON.stringify(envelope), \"utf8\");\n\t} catch {\n\t\t// Persistence is an optimization; ignore write failures.\n\t}\n}\n\n/** Delete the store file (test/diagnostic helper). Never throws. */\nexport function deleteSessionStore(): void {\n\ttry {\n\t\trmSync(storeFile(), { force: true });\n\t} catch {\n\t\t// best effort\n\t}\n}\n","import type {\n\tAgentDefinition,\n\tAgentModeOption,\n\tMcpServerConfig,\n\tModelSelection,\n\tSettingSource,\n} from \"@cursor/sdk\";\nimport { loadAgentBackend, type AgentLike } from \"./agent-backend.js\";\nimport {\n\tdeleteSessionStore,\n\tloadSessionRecords,\n\tsaveSessionRecords,\n\ttype StoredSessionRecord,\n} from \"./session-store.js\";\nimport type { TranscriptRecord } from \"./transcript-fingerprint.js\";\n\n/** sessionID -> fingerprint record, so a session reuses one Cursor agent across turns. */\nconst pool = new Map<string, StoredSessionRecord>();\n\n/**\n * Lazily merge disk-persisted records into the in-memory pool (memory wins),\n * so `session: \"auto\"` resumes a session's Cursor agent even after an opencode\n * restart. The agent's conversation itself lives in Cursor's checkpoint store;\n * this only restores our agentId + fingerprint bookkeeping.\n */\nlet hydrated = false;\nfunction hydrate(): void {\n\tif (hydrated) return;\n\thydrated = true;\n\tfor (const [key, record] of loadSessionRecords()) {\n\t\tif (!pool.has(key)) pool.set(key, record);\n\t}\n}\n\n/** Read the fingerprint record pooled for a session (undefined if none). */\nexport function getSessionRecord(\n\tsessionID: string,\n): TranscriptRecord | undefined {\n\thydrate();\n\treturn pool.get(sessionID);\n}\n\n/** Test/diagnostic helpers. */\nexport function getPooledAgentId(sessionID: string): string | undefined {\n\thydrate();\n\treturn pool.get(sessionID)?.agentId;\n}\nexport function clearAgentPool(): void {\n\tpool.clear();\n\thydrated = true; // don't re-hydrate stale disk state into a cleared pool\n\tdeleteSessionStore();\n}\n/** Test hook: drop in-memory state only, as if the process restarted. */\nexport function resetSessionPoolMemory(): void {\n\tpool.clear();\n\thydrated = false;\n}\n\nexport interface AcquireAgentParams {\n\tapiKey: string;\n\tmodelSelection: ModelSelection;\n\tmode: AgentModeOption;\n\tcwd: string;\n\tsettingSources?: SettingSource[];\n\tsandbox?: boolean;\n\tmcpServers?: Record<string, McpServerConfig>;\n\tagents?: Record<string, AgentDefinition>;\n\tname?: string;\n\t/**\n\t * Resume this Cursor agent before falling back to a fresh create. Set for a\n\t * fingerprinted \"continuation\" (the pooled agentId) or an explicit\n\t * `providerOptions.cursor.agentId`. A failed resume degrades to create.\n\t */\n\tresumeAgentId?: string;\n\t/**\n\t * Pool the resulting agent under this opencode session id. When set, the\n\t * agent persists across turns (release() does not close it) and `record` is\n\t * stored for the next turn's classification. When undefined, no pooling and\n\t * the agent is closed on release.\n\t */\n\tpoolKey?: string;\n\t/** Fingerprint of the current prompt, stored when `poolKey` is set. */\n\trecord?: { systemHash: string; userHashes: string[]; mcpHash?: string };\n}\n\nexport interface AcquiredAgent {\n\tagent: AgentLike;\n\t/** True when an existing agent was resumed (send only the new turn). */\n\tresumed: boolean;\n\t/** Close the agent unless it's pooled (pooled agents persist for the next turn). */\n\trelease: () => void;\n}\n\n/**\n * Get an agent to run a turn. Attempts a resume of `resumeAgentId` when given,\n * otherwise creates a fresh agent; a failed resume degrades to a fresh create\n * (so a stale/expired pool entry becomes a correct full-transcript turn rather\n * than an error). When `poolKey` is set, the resulting agent + `record` are\n * pooled for the session and survive `release()`.\n */\nexport async function acquireAgent(\n\tparams: AcquireAgentParams,\n): Promise<AcquiredAgent> {\n\tconst backend = loadAgentBackend();\n\n\tconst createOptions = {\n\t\tapiKey: params.apiKey,\n\t\tmodel: params.modelSelection,\n\t\tmode: params.mode,\n\t\tlocal: {\n\t\t\tcwd: params.cwd,\n\t\t\t...(params.settingSources\n\t\t\t\t? { settingSources: params.settingSources }\n\t\t\t\t: {}),\n\t\t\t...(params.sandbox !== undefined\n\t\t\t\t? { sandboxOptions: { enabled: params.sandbox } }\n\t\t\t\t: {}),\n\t\t},\n\t\t...(params.mcpServers ? { mcpServers: params.mcpServers } : {}),\n\t\t...(params.agents ? { agents: params.agents } : {}),\n\t\t...(params.name ? { name: params.name } : {}),\n\t};\n\n\tlet agent: AgentLike | undefined;\n\tlet resumed = false;\n\tif (params.resumeAgentId) {\n\t\ttry {\n\t\t\tagent = await backend.resumeAgent(params.resumeAgentId, createOptions);\n\t\t\tresumed = true;\n\t\t} catch {\n\t\t\t// Stale/expired id: fall through to a fresh create (full replay).\n\t\t}\n\t}\n\tif (!agent) {\n\t\tagent = await backend.createAgent(createOptions);\n\t}\n\n\tconst pooling = params.poolKey !== undefined;\n\tif (pooling && params.record) {\n\t\thydrate();\n\t\tpool.set(params.poolKey!, {\n\t\t\tagentId: agent.agentId,\n\t\t\tsystemHash: params.record.systemHash,\n\t\t\tuserHashes: params.record.userHashes,\n\t\t\t...(params.record.mcpHash !== undefined\n\t\t\t\t? { mcpHash: params.record.mcpHash }\n\t\t\t\t: {}),\n\t\t\tupdatedAt: Date.now(),\n\t\t});\n\t\t// Persist so session reuse survives opencode restarts (best-effort).\n\t\tsaveSessionRecords(pool);\n\t}\n\n\tconst release = () => {\n\t\tif (!pooling) {\n\t\t\ttry {\n\t\t\t\tagent!.close();\n\t\t\t} catch {\n\t\t\t\t// best effort\n\t\t\t}\n\t\t}\n\t};\n\n\treturn { agent, resumed, release };\n}\n"],"mappings":";AAAA,SAAS,kBAAkB;AAGpB,IAAM,yBAAyB;AAOtC,IAAM,eAAe,oBAAI,IAAY;AAAA,EACnC;AAAA,EACA,IAAI,sBAAsB;AAAA,EAC1B,MAAM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Y,OAAO,WAAW,IAAI,CAAC;AAAA,IAC7D,GAAI,OAAO,SAAS,EAAE,QAAQ,OAAO,OAAO,IAAI,CAAC;AAAA,IACjD,GAAI,OAAO,OAAO,EAAE,MAAM,OAAO,KAAK,IAAI,CAAC;AAAA,EAC5C;AAEA,MAAI;AACJ,MAAI,UAAU;AACd,MAAI,OAAO,eAAe;AACzB,QAAI;AACH,cAAQ,MAAM,QAAQ,YAAY,OAAO,eAAe,aAAa;AACrE,gBAAU;AAAA,IACX,QAAQ;AAAA,IAER;AAAA,EACD;AACA,MAAI,CAAC,OAAO;AACX,YAAQ,MAAM,QAAQ,YAAY,aAAa;AAAA,EAChD;AAEA,QAAM,UAAU,OAAO,YAAY;AACnC,MAAI,WAAW,OAAO,QAAQ;AAC7B,YAAQ;AACR,SAAK,IAAI,OAAO,SAAU;AAAA,MACzB,SAAS,MAAM;AAAA,MACf,YAAY,OAAO,OAAO;AAAA,MAC1B,YAAY,OAAO,OAAO;AAAA,MAC1B,GAAI,OAAO,OAAO,YAAY,SAC3B,EAAE,SAAS,OAAO,OAAO,QAAQ,IACjC,CAAC;AAAA,MACJ,WAAW,KAAK,IAAI;AAAA,IACrB,CAAC;AAED,uBAAmB,IAAI;AAAA,EACxB;AAEA,QAAM,UAAU,MAAM;AACrB,QAAI,CAAC,SAAS;AACb,UAAI;AACH,cAAO,MAAM;AAAA,MACd,QAAQ;AAAA,MAER;AAAA,IACD;AAAA,EACD;AAEA,SAAO,EAAE,OAAO,SAAS,QAAQ;AAClC;","names":["cached","execSync","existsSync","spawn","execSync","existsSync","cached","join"]}
@@ -6,7 +6,7 @@ import {
6
6
  resolveControls,
7
7
  resolveCursorApiKey,
8
8
  streamAgentTurn
9
- } from "../chunk-D4YQ7ZEM.js";
9
+ } from "../chunk-BTI2NHEE.js";
10
10
 
11
11
  // src/model-cache.ts
12
12
  import { mkdirSync, readFileSync, writeFileSync } from "fs";
@@ -76,21 +76,42 @@ var FALLBACK_MODELS = [
76
76
  // src/model-variants.ts
77
77
  var REASONING_PARAM = /think|reason|effort/i;
78
78
  var BOOLEAN_VALUES = /* @__PURE__ */ new Set(["true", "false"]);
79
+ function paramValues(param) {
80
+ return (param.values ?? []).map((v) => v.value);
81
+ }
82
+ function isBooleanParam(values) {
83
+ return values.length > 0 && values.every((v) => BOOLEAN_VALUES.has(v));
84
+ }
85
+ function defaultModelParams(item) {
86
+ const out = {};
87
+ for (const param of item.parameters ?? []) {
88
+ if (REASONING_PARAM.test(param.id)) continue;
89
+ if (isBooleanParam(paramValues(param))) out[param.id] = "false";
90
+ }
91
+ return out;
92
+ }
79
93
  function buildModelVariants(item) {
80
94
  const out = {};
95
+ const defaults = defaultModelParams(item);
81
96
  for (const param of item.parameters ?? []) {
82
- if (!REASONING_PARAM.test(param.id)) continue;
83
- const values = (param.values ?? []).map((v) => v.value);
97
+ const values = paramValues(param);
84
98
  if (values.length === 0) continue;
85
- if (values.every((v) => BOOLEAN_VALUES.has(v))) {
86
- if (values.includes("true")) {
87
- out[param.id.toLowerCase()] = { params: { [param.id]: "true" } };
99
+ const boolean = isBooleanParam(values);
100
+ if (REASONING_PARAM.test(param.id)) {
101
+ if (boolean) {
102
+ if (values.includes("true")) {
103
+ out[param.id.toLowerCase()] = { params: { ...defaults, [param.id]: "true" } };
104
+ }
105
+ continue;
106
+ }
107
+ for (const value of values) {
108
+ const key = out[value] === void 0 ? value : `${param.id}-${value}`;
109
+ out[key] = { params: { ...defaults, [param.id]: value } };
88
110
  }
89
111
  continue;
90
112
  }
91
- for (const value of values) {
92
- const key = out[value] === void 0 ? value : `${param.id}-${value}`;
93
- out[key] = { params: { [param.id]: value } };
113
+ if (boolean && values.includes("true")) {
114
+ out[param.id.toLowerCase()] = { params: { ...defaults, [param.id]: "true" } };
94
115
  }
95
116
  }
96
117
  return out;
@@ -146,6 +167,7 @@ function modelSupportsReasoning(item) {
146
167
  function toOpencodeModels(items) {
147
168
  const out = {};
148
169
  for (const item of items) {
170
+ const params = defaultModelParams(item);
149
171
  out[item.id] = {
150
172
  id: item.id,
151
173
  name: item.displayName || item.id,
@@ -153,7 +175,8 @@ function toOpencodeModels(items) {
153
175
  reasoning: modelSupportsReasoning(item),
154
176
  temperature: false,
155
177
  tool_call: true,
156
- variants: buildModelVariants(item)
178
+ variants: buildModelVariants(item),
179
+ options: Object.keys(params).length > 0 ? { params } : {}
157
180
  };
158
181
  }
159
182
  return out;
@@ -168,6 +191,7 @@ function providerNpm() {
168
191
  function buildModelV2Map(items) {
169
192
  const out = {};
170
193
  for (const item of items) {
194
+ const params = defaultModelParams(item);
171
195
  out[item.id] = {
172
196
  id: item.id,
173
197
  providerID: PROVIDER_ID,
@@ -185,7 +209,7 @@ function buildModelV2Map(items) {
185
209
  cost: { input: 0, output: 0, cache: { read: 0, write: 0 } },
186
210
  limit: { context: 2e5, output: 32e3 },
187
211
  status: "active",
188
- options: {},
212
+ options: Object.keys(params).length > 0 ? { params } : {},
189
213
  headers: {},
190
214
  release_date: "",
191
215
  variants: buildModelVariants(item)
@@ -195,11 +219,45 @@ function buildModelV2Map(items) {
195
219
  }
196
220
 
197
221
  // src/plugin/mcp-config.ts
198
- function translateMcpServers(mcp) {
222
+ var NEEDS_AUTH_STATUS = /* @__PURE__ */ new Set(["needs_auth", "needs_client_registration"]);
223
+ function oauthConfig(entry) {
224
+ if (entry.type !== "remote") return void 0;
225
+ return entry.oauth ? entry.oauth : void 0;
226
+ }
227
+ function toCursorAuth(oauth) {
228
+ if (!oauth?.clientId) return void 0;
229
+ const scopes = oauth.scope?.split(/\s+/).filter(Boolean);
230
+ return {
231
+ CLIENT_ID: oauth.clientId,
232
+ ...oauth.clientSecret ? { CLIENT_SECRET: oauth.clientSecret } : {},
233
+ ...scopes && scopes.length > 0 ? { scopes } : {}
234
+ };
235
+ }
236
+ function findUnshareableOAuthServers(mcp, status) {
237
+ const names = [];
238
+ if (!mcp) return names;
239
+ for (const [name, entry] of Object.entries(mcp)) {
240
+ if (!entry || entry.type !== "remote") continue;
241
+ if (!status && entry.enabled === false) continue;
242
+ const s2 = status?.[name]?.status;
243
+ if (status && s2 !== "connected" && !NEEDS_AUTH_STATUS.has(s2 ?? ""))
244
+ continue;
245
+ const oauth = oauthConfig(entry);
246
+ const needsOAuth = Boolean(oauth) || NEEDS_AUTH_STATUS.has(s2 ?? "");
247
+ if (needsOAuth && !toCursorAuth(oauth)) names.push(name);
248
+ }
249
+ return names;
250
+ }
251
+ function translateMcpServers(mcp, status) {
199
252
  const out = {};
200
253
  if (!mcp) return out;
201
254
  for (const [name, entry] of Object.entries(mcp)) {
202
- if (!entry || entry.enabled === false) continue;
255
+ if (!entry) continue;
256
+ if (status) {
257
+ if (status[name]?.status !== "connected") continue;
258
+ } else if (entry.enabled === false) {
259
+ continue;
260
+ }
203
261
  if (entry.type === "local") {
204
262
  const [command, ...args] = entry.command ?? [];
205
263
  if (!command) continue;
@@ -211,10 +269,14 @@ function translateMcpServers(mcp) {
211
269
  };
212
270
  } else if (entry.type === "remote") {
213
271
  if (!entry.url) continue;
272
+ const oauth = oauthConfig(entry);
273
+ const auth = toCursorAuth(oauth);
274
+ if (oauth && !auth) continue;
214
275
  out[name] = {
215
276
  type: "http",
216
277
  url: entry.url,
217
- ...entry.headers && Object.keys(entry.headers).length > 0 ? { headers: entry.headers } : {}
278
+ ...entry.headers && Object.keys(entry.headers).length > 0 ? { headers: entry.headers } : {},
279
+ ...auth ? { auth } : {}
218
280
  };
219
281
  }
220
282
  }
@@ -311,8 +373,7 @@ async function runDelegate(params) {
311
373
  mode,
312
374
  cwd: params.cwd,
313
375
  ...params.sandbox !== void 0 ? { sandbox: params.sandbox } : {},
314
- ...params.agentId ? { agentId: params.agentId } : {},
315
- session: false
376
+ ...params.agentId ? { resumeAgentId: params.agentId } : {}
316
377
  });
317
378
  const text = [];
318
379
  const reasoning = [];
@@ -322,7 +383,10 @@ async function runDelegate(params) {
322
383
  for await (const event of streamAgentTurn(
323
384
  acquired.agent,
324
385
  { text: params.prompt },
325
- { mode, ...params.abortSignal ? { abortSignal: params.abortSignal } : {} }
386
+ {
387
+ mode,
388
+ ...params.abortSignal ? { abortSignal: params.abortSignal } : {}
389
+ }
326
390
  )) {
327
391
  switch (event.type) {
328
392
  case "text-delta":
@@ -335,7 +399,8 @@ async function runDelegate(params) {
335
399
  toolActivity.push({ name: event.name, isError: false });
336
400
  break;
337
401
  case "tool-result":
338
- if (event.isError) toolActivity.push({ name: event.name, isError: true });
402
+ if (event.isError)
403
+ toolActivity.push({ name: event.name, isError: true });
339
404
  break;
340
405
  case "usage":
341
406
  usage = event.usage;
@@ -494,11 +559,18 @@ function apiKeyFromAuth(auth) {
494
559
  }
495
560
  var CursorPlugin = async (input) => {
496
561
  let capturedApiKey;
562
+ const client = input?.client;
563
+ const directory = input?.directory;
564
+ let forwardMcp = true;
565
+ let userMcp = {};
566
+ const warnedOAuth = /* @__PURE__ */ new Set();
497
567
  return {
498
568
  auth: {
499
569
  provider: PROVIDER_ID,
500
570
  loader: async (getAuth) => {
501
- const apiKey = resolveCursorApiKey(apiKeyFromAuth(await getAuth().catch(() => void 0)));
571
+ const apiKey = resolveCursorApiKey(
572
+ apiKeyFromAuth(await getAuth().catch(() => void 0))
573
+ );
502
574
  if (apiKey) {
503
575
  capturedApiKey = apiKey;
504
576
  void discoverModels({ apiKey });
@@ -519,8 +591,8 @@ var CursorPlugin = async (input) => {
519
591
  config.provider ??= {};
520
592
  const existing = config.provider[PROVIDER_ID] ?? {};
521
593
  const existingOptions = existing.options ?? {};
522
- const forwardMcp = existingOptions["forwardMcp"] !== false;
523
- const userMcp = existingOptions["mcpServers"] ?? {};
594
+ forwardMcp = existingOptions["forwardMcp"] !== false;
595
+ userMcp = existingOptions["mcpServers"] ?? {};
524
596
  const mcpServers = forwardMcp ? { ...userMcp, ...translateMcpServers(config.mcp) } : userMcp;
525
597
  config.provider[PROVIDER_ID] = {
526
598
  name: "Cursor",
@@ -551,10 +623,47 @@ var CursorPlugin = async (input) => {
551
623
  // agent-based default only applies when no mode was set.
552
624
  "chat.params": async (input2, output) => {
553
625
  if (input2.model?.providerID !== PROVIDER_ID) return;
554
- output.options = { ...output.options ?? {}, sessionID: input2.sessionID };
626
+ output.options = {
627
+ ...output.options ?? {},
628
+ sessionID: input2.sessionID
629
+ };
555
630
  if (input2.agent === "plan" && output.options["mode"] === void 0) {
556
631
  output.options["mode"] = "plan";
557
632
  }
633
+ if (forwardMcp && client) {
634
+ try {
635
+ const query = directory ? { query: { directory } } : void 0;
636
+ const [cfgRes, statusRes] = await Promise.all([
637
+ client.config.get(),
638
+ client.mcp.status(query)
639
+ ]);
640
+ const liveMcp = cfgRes?.data?.mcp;
641
+ const status = statusRes?.data;
642
+ if (status) {
643
+ output.options["mcpServers"] = {
644
+ ...userMcp,
645
+ ...translateMcpServers(liveMcp, status)
646
+ };
647
+ const unshareable = findUnshareableOAuthServers(
648
+ liveMcp,
649
+ status
650
+ ).filter((name) => !warnedOAuth.has(name));
651
+ if (unshareable.length > 0) {
652
+ for (const name of unshareable) warnedOAuth.add(name);
653
+ const plural = unshareable.length > 1;
654
+ void client.tui.showToast({
655
+ body: {
656
+ title: "Cursor MCP",
657
+ message: `Skipped OAuth MCP server${plural ? "s" : ""}: ${unshareable.join(", ")}. opencode's token can't be shared with the Cursor agent; configure an OAuth clientId to forward ${plural ? "them" : "it"}.`,
658
+ variant: "warning"
659
+ }
660
+ }).catch(() => {
661
+ });
662
+ }
663
+ }
664
+ } catch {
665
+ }
666
+ }
558
667
  },
559
668
  tool: {
560
669
  cursor_refresh_models: {
@@ -562,7 +671,9 @@ var CursorPlugin = async (input) => {
562
671
  args: {},
563
672
  execute: async () => {
564
673
  const result = await discoverModels({ forceRefresh: true });
565
- const lines = result.models.map((m) => `- ${m.id} \u2014 ${m.displayName}`);
674
+ const lines = result.models.map(
675
+ (m) => `- ${m.id} \u2014 ${m.displayName}`
676
+ );
566
677
  const header = result.source === "live" ? `Refreshed ${result.models.length} Cursor models (live):` : `Could not fetch live models (${result.source}). ${result.warning ?? ""}`.trim();
567
678
  return {
568
679
  title: `Cursor models (${result.source})`,