@stablekernel/opencode-cursor 0.4.7-next.0 → 0.5.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.
@@ -21,10 +21,16 @@ import { createInterface } from 'node:readline';
21
21
  * dist/sidecar/agent-host.js for production.
22
22
  */
23
23
 
24
- /** Plain-data error shape that survives JSON; name preserved for retry logic. */
24
+ /** Plain-data error shape that survives JSON; name + classification fields
25
+ * preserved so the Bun side can discriminate (see error-classify.ts). */
25
26
  function serializeError(err) {
26
27
  if (err instanceof Error) {
27
- return { name: err.name, message: err.message };
28
+ const out = { name: err.name, message: err.message };
29
+ for (const k of ["status", "code", "isRetryable", "helpUrl"]) {
30
+ const v = err[k];
31
+ if (typeof v === "number" || typeof v === "string" || typeof v === "boolean") out[k] = v;
32
+ }
33
+ return out;
28
34
  }
29
35
  return { name: "Error", message: String(err) };
30
36
  }
@@ -69,6 +75,7 @@ async function handleRequest(req) {
69
75
  const sendOptions = {
70
76
  ...(req.mode ? { mode: req.mode } : {}),
71
77
  ...(req.force ? { local: { force: true } } : {}),
78
+ ...(req.idempotencyKey ? { idempotencyKey: req.idempotencyKey } : {}),
72
79
  onDelta: ({ update }) => write({ id, ev: "update", update }),
73
80
  };
74
81
  const run = await agent.send(req.message, sendOptions);
@@ -2,7 +2,12 @@
2
2
  import { createInterface } from "readline";
3
3
  function serializeError(err) {
4
4
  if (err instanceof Error) {
5
- return { name: err.name, message: err.message };
5
+ const out = { name: err.name, message: err.message };
6
+ for (const k of ["status", "code", "isRetryable", "helpUrl"]) {
7
+ const v = err[k];
8
+ if (typeof v === "number" || typeof v === "string" || typeof v === "boolean") out[k] = v;
9
+ }
10
+ return out;
6
11
  }
7
12
  return { name: "Error", message: String(err) };
8
13
  }
@@ -38,6 +43,7 @@ async function handleRequest(req) {
38
43
  const sendOptions = {
39
44
  ...req.mode ? { mode: req.mode } : {},
40
45
  ...req.force ? { local: { force: true } } : {},
46
+ ...req.idempotencyKey ? { idempotencyKey: req.idempotencyKey } : {},
41
47
  onDelta: ({ update }) => write({ id, ev: "update", update })
42
48
  };
43
49
  const run = await agent.send(req.message, sendOptions);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/sidecar/agent-host.mjs"],"sourcesContent":["/**\n * Cursor agent sidecar — runs under Node and hosts all `@cursor/sdk` agent\n * traffic on behalf of the provider.\n *\n * Why this exists: opencode executes plugins under Bun, whose `node:http2`\n * client breaks Cursor's streaming connect RPC (NGHTTP2_FRAME_SIZE_ERROR);\n * tool-completion updates are lost and every native tool call dangles. Under\n * Node the same stream works, so when Bun is detected the provider spawns this\n * script with Node and proxies agent calls over a JSON-lines stdio protocol\n * (see sidecar-client.ts for the client side).\n *\n * Protocol (one JSON object per line):\n * request: {id, op: \"ping\"|\"create\"|\"resume\"|\"send\"|\"cancel\"|\"close\", ...}\n * response: {id, ok: true, ...} | {id, ok: false, error: {name, message}}\n * send stream: {id, ev: \"update\", update} ... then exactly one of\n * {id, ev: \"result\", result} | {id, ev: \"error\", error}\n *\n * Kept as plain .mjs so tests can spawn it pre-build; tsup also bundles it to\n * dist/sidecar/agent-host.js for production.\n */\nimport { createInterface } from \"node:readline\";\n\n/** Plain-data error shape that survives JSON; name preserved for retry logic. */\nfunction serializeError(err) {\n if (err instanceof Error) {\n return { name: err.name, message: err.message };\n }\n return { name: \"Error\", message: String(err) };\n}\n\nfunction write(payload) {\n process.stdout.write(`${JSON.stringify(payload)}\\n`);\n}\n\nlet sdkPromise;\nfunction loadSdk() {\n // OPENCODE_CURSOR_SDK_PATH lets tests substitute a fake SDK module.\n sdkPromise ??= import(process.env.OPENCODE_CURSOR_SDK_PATH || \"@cursor/sdk\");\n return sdkPromise;\n}\n\n/** agentId -> SDKAgent */\nconst agents = new Map();\n/** send request id -> Run (for cancel) */\nconst runs = new Map();\n\nasync function handleRequest(req) {\n const { id, op } = req;\n switch (op) {\n case \"ping\": {\n write({ id, ok: true, pid: process.pid });\n return;\n }\n case \"create\":\n case \"resume\": {\n const { Agent } = await loadSdk();\n const agent =\n op === \"resume\"\n ? await Agent.resume(req.agentId, req.options)\n : await Agent.create(req.options);\n agents.set(agent.agentId, agent);\n write({ id, ok: true, agentId: agent.agentId });\n return;\n }\n case \"send\": {\n const agent = agents.get(req.agentId);\n if (!agent) throw new Error(`unknown agent \"${req.agentId}\"`);\n const sendOptions = {\n ...(req.mode ? { mode: req.mode } : {}),\n ...(req.force ? { local: { force: true } } : {}),\n onDelta: ({ update }) => write({ id, ev: \"update\", update }),\n };\n const run = await agent.send(req.message, sendOptions);\n runs.set(id, run);\n // Acknowledge so the client can hand back a cancellable run handle.\n write({ id, ok: true });\n try {\n const result = await run.wait();\n write({ id, ev: \"result\", result });\n } catch (err) {\n write({ id, ev: \"error\", error: serializeError(err) });\n } finally {\n runs.delete(id);\n }\n return;\n }\n case \"cancel\": {\n const run = runs.get(req.sendId);\n if (run) await run.cancel();\n write({ id, ok: true });\n return;\n }\n case \"close\": {\n const agent = agents.get(req.agentId);\n agents.delete(req.agentId);\n try {\n agent?.close();\n } catch {\n // best effort\n }\n write({ id, ok: true });\n return;\n }\n default:\n throw new Error(`unknown op \"${op}\"`);\n }\n}\n\nconst rl = createInterface({ input: process.stdin });\nrl.on(\"line\", (line) => {\n if (!line.trim()) return;\n let req;\n try {\n req = JSON.parse(line);\n } catch (err) {\n write({ id: null, ok: false, error: serializeError(err) });\n return;\n }\n handleRequest(req).catch((err) => {\n write({ id: req.id, ok: false, error: serializeError(err) });\n });\n});\n\n// Parent gone (stdin closed) -> shut down; never outlive the plugin process.\nrl.on(\"close\", () => {\n process.exit(0);\n});\n"],"mappings":";AAoBA,SAAS,uBAAuB;AAGhC,SAAS,eAAe,KAAK;AAC3B,MAAI,eAAe,OAAO;AACxB,WAAO,EAAE,MAAM,IAAI,MAAM,SAAS,IAAI,QAAQ;AAAA,EAChD;AACA,SAAO,EAAE,MAAM,SAAS,SAAS,OAAO,GAAG,EAAE;AAC/C;AAEA,SAAS,MAAM,S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
1
+ {"version":3,"sources":["../../src/sidecar/agent-host.mjs"],"sourcesContent":["/**\n * Cursor agent sidecar — runs under Node and hosts all `@cursor/sdk` agent\n * traffic on behalf of the provider.\n *\n * Why this exists: opencode executes plugins under Bun, whose `node:http2`\n * client breaks Cursor's streaming connect RPC (NGHTTP2_FRAME_SIZE_ERROR);\n * tool-completion updates are lost and every native tool call dangles. Under\n * Node the same stream works, so when Bun is detected the provider spawns this\n * script with Node and proxies agent calls over a JSON-lines stdio protocol\n * (see sidecar-client.ts for the client side).\n *\n * Protocol (one JSON object per line):\n * request: {id, op: \"ping\"|\"create\"|\"resume\"|\"send\"|\"cancel\"|\"close\", ...}\n * response: {id, ok: true, ...} | {id, ok: false, error: {name, message}}\n * send stream: {id, ev: \"update\", update} ... then exactly one of\n * {id, ev: \"result\", result} | {id, ev: \"error\", error}\n *\n * Kept as plain .mjs so tests can spawn it pre-build; tsup also bundles it to\n * dist/sidecar/agent-host.js for production.\n */\nimport { createInterface } from \"node:readline\";\n\n/** Plain-data error shape that survives JSON; name + classification fields\n * preserved so the Bun side can discriminate (see error-classify.ts). */\nfunction serializeError(err) {\n if (err instanceof Error) {\n const out = { name: err.name, message: err.message };\n for (const k of [\"status\", \"code\", \"isRetryable\", \"helpUrl\"]) {\n const v = err[k];\n if (typeof v === \"number\" || typeof v === \"string\" || typeof v === \"boolean\") out[k] = v;\n }\n return out;\n }\n return { name: \"Error\", message: String(err) };\n}\n\nfunction write(payload) {\n process.stdout.write(`${JSON.stringify(payload)}\\n`);\n}\n\nlet sdkPromise;\nfunction loadSdk() {\n // OPENCODE_CURSOR_SDK_PATH lets tests substitute a fake SDK module.\n sdkPromise ??= import(process.env.OPENCODE_CURSOR_SDK_PATH || \"@cursor/sdk\");\n return sdkPromise;\n}\n\n/** agentId -> SDKAgent */\nconst agents = new Map();\n/** send request id -> Run (for cancel) */\nconst runs = new Map();\n\nasync function handleRequest(req) {\n const { id, op } = req;\n switch (op) {\n case \"ping\": {\n write({ id, ok: true, pid: process.pid });\n return;\n }\n case \"create\":\n case \"resume\": {\n const { Agent } = await loadSdk();\n const agent =\n op === \"resume\"\n ? await Agent.resume(req.agentId, req.options)\n : await Agent.create(req.options);\n agents.set(agent.agentId, agent);\n write({ id, ok: true, agentId: agent.agentId });\n return;\n }\n case \"send\": {\n const agent = agents.get(req.agentId);\n if (!agent) throw new Error(`unknown agent \"${req.agentId}\"`);\n const sendOptions = {\n ...(req.mode ? { mode: req.mode } : {}),\n ...(req.force ? { local: { force: true } } : {}),\n ...(req.idempotencyKey ? { idempotencyKey: req.idempotencyKey } : {}),\n onDelta: ({ update }) => write({ id, ev: \"update\", update }),\n };\n const run = await agent.send(req.message, sendOptions);\n runs.set(id, run);\n // Acknowledge so the client can hand back a cancellable run handle.\n write({ id, ok: true });\n try {\n const result = await run.wait();\n write({ id, ev: \"result\", result });\n } catch (err) {\n write({ id, ev: \"error\", error: serializeError(err) });\n } finally {\n runs.delete(id);\n }\n return;\n }\n case \"cancel\": {\n const run = runs.get(req.sendId);\n if (run) await run.cancel();\n write({ id, ok: true });\n return;\n }\n case \"close\": {\n const agent = agents.get(req.agentId);\n agents.delete(req.agentId);\n try {\n agent?.close();\n } catch {\n // best effort\n }\n write({ id, ok: true });\n return;\n }\n default:\n throw new Error(`unknown op \"${op}\"`);\n }\n}\n\nconst rl = createInterface({ input: process.stdin });\nrl.on(\"line\", (line) => {\n if (!line.trim()) return;\n let req;\n try {\n req = JSON.parse(line);\n } catch (err) {\n write({ id: null, ok: false, error: serializeError(err) });\n return;\n }\n handleRequest(req).catch((err) => {\n write({ id: req.id, ok: false, error: serializeError(err) });\n });\n});\n\n// Parent gone (stdin closed) -> shut down; never outlive the plugin process.\nrl.on(\"close\", () => {\n process.exit(0);\n});\n"],"mappings":";AAoBA,SAAS,uBAAuB;AAIhC,SAAS,eAAe,KAAK;AAC3B,MAAI,eAAe,OAAO;AACxB,UAAM,MAAM,EAAE,MAAM,IAAI,MAAM,SAAS,IAAI,QAAQ;AACn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AAM,IAAI;AAAA,EACvB,SAAS,KAAK;AACZ,UAAM,EAAE,IAAI,MAAM,IAAI,OAAO,OAAO,eAAe,GAAG,EAAE,CAAC;AACzD;AAAA,EACF;AACA,gBAAc,GAAG,EAAE,MAAM,CAAC,QAAQ;AAChC,UAAM,EAAE,IAAI,IAAI,IAAI,IAAI,OAAO,OAAO,eAAe,GAAG,EAAE,CAAC;AAAA,EAC7D,CAAC;AACH,CAAC;AAGD,GAAG,GAAG,SAAS,MAAM;AACnB,UAAQ,KAAK,CAAC;AAChB,CAAC;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stablekernel/opencode-cursor",
3
- "version": "0.4.7-next.0",
3
+ "version": "0.5.0",
4
4
  "description": "opencode provider plugin backed by the official Cursor SDK (@cursor/sdk) — adds a Cursor provider and lists its models",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -14,7 +14,7 @@
14
14
  "url": "https://github.com/stablekernel/opencode-cursor/issues"
15
15
  },
16
16
  "engines": {
17
- "node": ">=22.0.0"
17
+ "node": ">=22.13.0"
18
18
  },
19
19
  "keywords": [
20
20
  "opencode",
@@ -52,12 +52,13 @@
52
52
  "typecheck": "tsc --noEmit",
53
53
  "test": "vitest run",
54
54
  "test:watch": "vitest",
55
+ "test:e2e": "vitest run --config vitest.e2e.config.ts --passWithNoTests",
55
56
  "prepublishOnly": "npm run typecheck && npm test && npm run build"
56
57
  },
57
58
  "dependencies": {
58
59
  "@connectrpc/connect-node": "^2.1.2",
59
- "@cursor/sdk": "^1.0.23",
60
- "@opencode-ai/plugin": "^1.17.14",
60
+ "@cursor/sdk": "^1.0.24",
61
+ "@opencode-ai/plugin": "^1.18.4",
61
62
  "semver": "^7.8.4"
62
63
  },
63
64
  "overrides": {
@@ -70,7 +71,7 @@
70
71
  },
71
72
  "devDependencies": {
72
73
  "@ai-sdk/provider": "^3.0.13",
73
- "@opencode-ai/sdk": "^1.17.14",
74
+ "@opencode-ai/sdk": "^1.18.4",
74
75
  "@types/node": "^26.0.0",
75
76
  "@types/semver": "^7.7.1",
76
77
  "tsup": "^8.5.1",
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/api-key.ts","../src/provider/system-rule.ts","../src/provider/agent-events.ts","../src/provider/controls.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 {\n\tmkdirSync,\n\twriteFileSync,\n\treadFileSync,\n\texistsSync,\n\trmSync,\n} from \"node:fs\";\nimport { join } from \"node:path\";\nimport type { LanguageModelV3Prompt } from \"@ai-sdk/provider\";\nimport type { SettingSource } from \"@cursor/sdk\";\nimport type { SystemPromptMode } from \"./message-map.js\";\n\n/** Location of the generated rule, relative to the agent's cwd. */\nconst RULES_DIR = join(\".cursor\", \"rules\");\nconst RULE_FILE = \"opencode.mdc\";\nconst IGNORE_FILE = \".gitignore\";\n\n/**\n * Frontmatter sentinel marking the rule as generated by this plugin. Only\n * files carrying it are ever overwritten or deleted, so a user-owned\n * `.cursor/rules/opencode.mdc` is never clobbered.\n */\nconst SENTINEL = \"generated: opencode-cursor\";\n\n/** Concatenate every system-message body from an AI-SDK prompt (trimmed). */\nexport function extractSystemText(prompt: LanguageModelV3Prompt): string {\n\tconst parts: string[] = [];\n\tfor (const message of prompt) {\n\t\tif (message.role === \"system\") parts.push(message.content);\n\t}\n\treturn parts.join(\"\\n\\n\").trim();\n}\n\n/** Outcome of a {@link writeSystemRule} attempt. */\nexport type SystemRuleWrite =\n\t/** Rule file created or updated. */\n\t| \"written\"\n\t/** Existing generated rule already has this content; write skipped. */\n\t| \"unchanged\"\n\t/** No system text to deliver; nothing written. */\n\t| \"empty\"\n\t/** A user-owned (sentinel-less) opencode.mdc exists; left untouched. */\n\t| \"blocked\";\n\n/** True when the file carries the generated-by sentinel in its frontmatter. */\nfunction isGenerated(content: string): boolean {\n\tif (!content.startsWith(\"---\")) return false;\n\tconst end = content.indexOf(\"\\n---\", 3);\n\tconst frontmatter = end === -1 ? content : content.slice(0, end);\n\treturn frontmatter.split(/\\r?\\n/).includes(SENTINEL);\n}\n\n/**\n * Write opencode's system prompt to `<cwd>/.cursor/rules/opencode.mdc` as an\n * always-applied Cursor project rule. Cursor loads this through its authoritative\n * rules channel (`settingSources` including \"project\"), so opencode's controlling\n * instructions reach the agent without being flattened into the untrusted\n * user-message transcript (which injection-hardened models reject).\n *\n * The file carries a generated-by sentinel; a pre-existing sentinel-less file\n * is treated as user-owned and never overwritten (\"blocked\"). An existing\n * generated rule with identical content is left as-is (\"unchanged\") to keep\n * sync fs writes off the stream hot path. May throw on fs errors (read-only\n * checkout etc.) — callers should degrade gracefully.\n */\nexport function writeSystemRule(\n\tcwd: string,\n\tsystemText: string,\n): SystemRuleWrite {\n\tif (!systemText) return \"empty\";\n\tconst dir = join(cwd, RULES_DIR);\n\tconst path = join(dir, RULE_FILE);\n\tconst body = `---\\nalwaysApply: true\\n${SENTINEL}\\n---\\n\\n${systemText}\\n`;\n\tconst existing = existsSync(path) ? readFileSync(path, \"utf8\") : undefined;\n\tif (existing !== undefined) {\n\t\tif (!isGenerated(existing)) return \"blocked\";\n\t\tif (existing === body) return \"unchanged\";\n\t}\n\tmkdirSync(dir, { recursive: true });\n\twriteFileSync(path, body, \"utf8\");\n\tensureGitIgnored(dir);\n\treturn \"written\";\n}\n\n/**\n * Keep the generated rule out of git via `.cursor/rules/.gitignore` (which\n * also ignores itself so it doesn't pollute `git status`).\n */\nfunction ensureGitIgnored(dir: string): void {\n\tconst path = join(dir, IGNORE_FILE);\n\tconst existing = existsSync(path) ? readFileSync(path, \"utf8\") : \"\";\n\tconst lines = existing.split(/\\r?\\n/);\n\tconst missing = [RULE_FILE, IGNORE_FILE].filter(\n\t\t(entry) => !lines.includes(entry),\n\t);\n\tif (missing.length === 0) return;\n\tconst prefix =\n\t\texisting && !existing.endsWith(\"\\n\") ? `${existing}\\n` : existing;\n\twriteFileSync(path, `${prefix}${missing.join(\"\\n\")}\\n`, \"utf8\");\n}\n\n/**\n * Remove the generated rule (best-effort); used on plugin dispose. Only\n * deletes files carrying the generated-by sentinel — a user-owned\n * opencode.mdc is left in place.\n */\nexport function removeSystemRule(cwd: string): void {\n\ttry {\n\t\tconst path = join(cwd, RULES_DIR, RULE_FILE);\n\t\tif (isGenerated(readFileSync(path, \"utf8\"))) rmSync(path);\n\t} catch {\n\t\t// best effort — already gone or never written\n\t}\n}\n\n/** How the system prompt will be delivered for this turn. */\nexport interface SystemDelivery {\n\tmode: SystemPromptMode;\n\tsettingSources: SettingSource[] | undefined;\n}\n\n/**\n * Decide how opencode's system prompt reaches the Cursor agent for one turn.\n *\n * In \"rules\" mode this writes the rule file and enables the `project`\n * settings layer — but ONLY when the user did not explicitly configure\n * `settingSources` without \"project\" (a deliberate hardening opt-out: the\n * project layer also loads the repo's `.cursor/mcp.json`, hooks, and other\n * rules). On an opt-out, a failed write (read-only checkout etc.), or a\n * user-owned rule file, it degrades to inline \"message\" delivery for the\n * turn and reports the reason via `warn`. Never throws.\n */\nexport function resolveSystemDelivery(options: {\n\tmode: SystemPromptMode;\n\tsettingSources: SettingSource[] | undefined;\n\tcwd: string;\n\tsystemText: string;\n\twarn: (message: string) => void;\n}): SystemDelivery {\n\tconst { mode, settingSources, cwd, systemText, warn } = options;\n\tif (mode !== \"rules\") return { mode, settingSources };\n\tif (settingSources && !settingSources.includes(\"project\")) {\n\t\twarn(\n\t\t\t'systemPrompt \"rules\" needs the \"project\" settings layer, but settingSources was explicitly configured without it; delivering the system prompt inline (\"message\" mode) instead. Add \"project\" to settingSources or set systemPrompt: \"message\" to silence this.',\n\t\t);\n\t\treturn { mode: \"message\", settingSources };\n\t}\n\tlet result: SystemRuleWrite;\n\ttry {\n\t\tresult = writeSystemRule(cwd, systemText);\n\t} catch (error) {\n\t\twarn(\n\t\t\t`failed to write .cursor/rules/${RULE_FILE} (${error instanceof Error ? error.message : String(error)}); delivering the system prompt inline (\"message\" mode) for this turn.`,\n\t\t);\n\t\treturn { mode: \"message\", settingSources };\n\t}\n\tif (result === \"blocked\") {\n\t\twarn(\n\t\t\t`.cursor/rules/${RULE_FILE} exists but was not generated by opencode-cursor; leaving it untouched and delivering the system prompt inline (\"message\" mode).`,\n\t\t);\n\t\treturn { mode: \"message\", settingSources };\n\t}\n\tif (result === \"empty\") return { mode, settingSources };\n\treturn { mode, settingSources: settingSources ?? [\"project\"] };\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 const sendTurn = (): Promise<AgentRunLike> =>\n sendWithBusyRetry(agent, message, { mode: options.mode, onDelta }, debug);\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\n/**\n * Send a message on an agent, retrying once with the SDK's documented recovery\n * path on `AgentBusyError`. A previous opencode/CLI crash (or a second instance\n * racing on the same agent store) can leave a persisted run wedged; the SDK then\n * rejects new sends with `AgentBusyError`. `local.force` expires the wedged run\n * instead of failing the turn. Shared by streaming and silent sends.\n */\nasync function sendWithBusyRetry(\n agent: AgentLike,\n message: SDKUserMessage,\n sendOptions: {\n mode: AgentModeOption;\n onDelta?: (args: { update: { type: string } & Record<string, any> }) => void;\n },\n debug: boolean,\n): Promise<AgentRunLike> {\n try {\n return await agent.send(message, sendOptions);\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, { ...sendOptions, local: { force: true } });\n }\n throw err;\n }\n}\n\n/**\n * Send a single turn on an already-acquired agent WITHOUT streaming anything\n * back. Used to replay the leading messages of a multi-message interjection\n * (two-or-more user messages queued while the agent was busy): messages\n * `1..N-1` are sent silently and awaited, and only the final message streams\n * via {@link streamAgentTurn}. This mirrors opencode's own model, where\n * interjected messages fold into a single visible turn.\n *\n * Honors `options.abortSignal`: an abort cancels the in-flight run so the\n * caller can stop before sending the next queued message.\n *\n * Known trade-offs of silent turns being FULL agent runs:\n * - Tool invisibility: the agent may execute tools (shell, edits, MCP) during\n * a silent turn with zero streamed output or tool display — the user sees\n * nothing until the final message streams. Accepted because interjections\n * are typically short course-corrections, and opencode itself folds\n * interjected messages into one visible turn.\n * - Serial latency: each silent turn is awaited to completion before the next\n * send, so an N-message interjection costs N sequential agent runs.\n * - Usage undercount: no onDelta means the `turn-ended` usage update is never\n * observed, so opencode slightly undercounts tokens on multi-message turns.\n *\n * Concatenating the queued messages into one Cursor message was rejected for\n * message fidelity: each interjection must land as a distinct user turn in the\n * agent's conversation memory (mirroring opencode's transcript), so the model\n * sees the same message boundaries the user created and later fingerprint\n * classification stays aligned turn-for-turn.\n */\nexport async function sendAgentTurnSilently(\n agent: AgentLike,\n message: SDKUserMessage,\n options: StreamAgentTurnOptions,\n): Promise<void> {\n // Already aborted: don't start a turn just to cancel it.\n if (options.abortSignal?.aborted) return;\n const debug = process.env.OPENCODE_CURSOR_DEBUG === \"1\";\n const runHolder: { run?: AgentRunLike } = {};\n const onAbort = () => {\n void Promise.resolve(runHolder.run?.cancel()).catch(() => {});\n };\n options.abortSignal?.addEventListener(\"abort\", onAbort);\n try {\n const run = await sendWithBusyRetry(agent, message, { mode: options.mode }, debug);\n runHolder.run = run;\n // The signal may have fired while send() was in flight (before runHolder\n // was populated, so onAbort had nothing to cancel); cancel now.\n if (options.abortSignal?.aborted) void Promise.resolve(run.cancel()).catch(() => {});\n const result = await run.wait();\n if (result.status !== \"finished\") {\n // Our own abort cancelled the run mid-flight: expected, not a failure.\n // The caller's abort check stops the multi-send sequence and drops the\n // session record, so this partial turn is never counted as delivered.\n if (options.abortSignal?.aborted) return;\n // Anything else (\"error\", an external \"cancelled\", unknown states) means\n // the message was NOT delivered; treating it as success would leave the\n // session record claiming the agent saw a message it never received.\n throw new Error(\n `Cursor run ended with status \"${result.status}\"${result.result ? `: ${result.result}` : \"\"}`,\n );\n }\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 * Per-model floor params, applied UNDER {@link params} and per-request options\n * (an explicit param always wins). Pins Cursor's boolean toggles, e.g.\n * `{ fast: \"false\" }`, when a turn arrives with no params of its own.\n */\n defaults?: 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> = {\n ...(staticControls.defaults ?? {}),\n ...(staticControls.params ?? {}),\n };\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 * 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 */\nexport type CursorSdkModule = typeof import(\"@cursor/sdk\");\n\nlet cached: Promise<CursorSdkModule> | undefined;\n\nexport async function loadCursorSdk(): Promise<CursorSdkModule> {\n if (!cached) {\n cached = import(\"@cursor/sdk\").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 { 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 return {\n kind: \"sidecar\",\n createAgent: (options) => client.createAgent(options),\n resumeAgent: (agentId, options) => client.resumeAgent(agentId, options),\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/**\n * Drop a session's pooled record so the NEXT turn classifies as \"new\" (fresh\n * agent + full transcript replay). Called when a multi-message replay fails or\n * aborts mid-sequence: the record was written optimistically with the full new\n * fingerprint before delivery, so leaving it in place would let a later\n * \"continuation\" resume on top of messages the agent never received.\n */\nexport function dropSessionRecord(sessionID: string): void {\n\thydrate();\n\tif (pool.delete(sessionID)) saveSessionRecords(pool);\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,sBAAsB;AAC9B,CAAC;AAYM,SAAS,oBAAoB,WAA+C;AACjF,QAAM,UAAU,WAAW,KAAK;AAChC,MAAI,WAAW,CAAC,aAAa,IAAI,OAAO,EAAG,QAAO;AAClD,QAAM,UAAU,QAAQ,IAAI,sBAAsB,GAAG,KAAK;AAC1D,SAAO,UAAU,UAAU;AAC7B;AAOO,SAAS,kBAAkB,QAAwB;AACxD,SAAO,W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