@rama_nigg/open-cursor 2.3.14 → 2.3.15

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.
@@ -16,6 +16,65 @@ var __export = (target, all) => {
16
16
  var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
17
17
  var __require = /* @__PURE__ */ createRequire(import.meta.url);
18
18
 
19
+ // src/plugin-toggle.ts
20
+ import { existsSync, readFileSync } from "fs";
21
+ import { homedir } from "os";
22
+ import { join, resolve } from "path";
23
+ function matchesPlugin(entry) {
24
+ if (entry === CURSOR_PROVIDER_ID)
25
+ return true;
26
+ if (entry === NPM_PACKAGE_NAME)
27
+ return true;
28
+ if (entry.startsWith(`${NPM_PACKAGE_NAME}@`))
29
+ return true;
30
+ return false;
31
+ }
32
+ function resolveOpenCodeConfigPath(env = process.env) {
33
+ if (env.OPENCODE_CONFIG && env.OPENCODE_CONFIG.length > 0) {
34
+ return resolve(env.OPENCODE_CONFIG);
35
+ }
36
+ const configHome = env.XDG_CONFIG_HOME && env.XDG_CONFIG_HOME.length > 0 ? env.XDG_CONFIG_HOME : join(homedir(), ".config");
37
+ return join(configHome, "opencode", "opencode.json");
38
+ }
39
+ function isCursorPluginEnabledInConfig(config) {
40
+ if (!config || typeof config !== "object") {
41
+ return true;
42
+ }
43
+ const configObject = config;
44
+ if (Array.isArray(configObject.plugin)) {
45
+ return configObject.plugin.some((entry) => matchesPlugin(entry));
46
+ }
47
+ return true;
48
+ }
49
+ function shouldEnableCursorPlugin(env = process.env) {
50
+ const configPath = resolveOpenCodeConfigPath(env);
51
+ if (!existsSync(configPath)) {
52
+ return {
53
+ enabled: true,
54
+ configPath,
55
+ reason: "config_missing"
56
+ };
57
+ }
58
+ try {
59
+ const raw = readFileSync(configPath, "utf8");
60
+ const parsed = JSON.parse(raw);
61
+ const enabled = isCursorPluginEnabledInConfig(parsed);
62
+ return {
63
+ enabled,
64
+ configPath,
65
+ reason: enabled ? "enabled_in_plugin_array_or_legacy" : "disabled_in_plugin_array"
66
+ };
67
+ } catch {
68
+ return {
69
+ enabled: true,
70
+ configPath,
71
+ reason: "config_unreadable_or_invalid"
72
+ };
73
+ }
74
+ }
75
+ var CURSOR_PROVIDER_ID = "cursor-acp", NPM_PACKAGE_NAME = "@rama_nigg/open-cursor";
76
+ var init_plugin_toggle = () => {};
77
+
19
78
  // src/utils/logger.ts
20
79
  import * as fs from "node:fs";
21
80
  import * as path from "node:path";
@@ -14252,6 +14311,174 @@ class SkillResolver {
14252
14311
  }
14253
14312
  }
14254
14313
 
14314
+ // src/cli/model-discovery.ts
14315
+ import { execFileSync } from "child_process";
14316
+ function parseCursorModelsOutput(output) {
14317
+ const clean = stripAnsi(output);
14318
+ const models = [];
14319
+ const seen = new Set;
14320
+ for (const line of clean.split(`
14321
+ `)) {
14322
+ const trimmed = line.trim();
14323
+ if (!trimmed)
14324
+ continue;
14325
+ const match = trimmed.match(/^([a-zA-Z0-9._-]+)\s+-\s+(.+?)(?:\s+\((?:current|default)\))*\s*$/);
14326
+ if (!match)
14327
+ continue;
14328
+ const id = match[1];
14329
+ if (seen.has(id))
14330
+ continue;
14331
+ seen.add(id);
14332
+ models.push({ id, name: match[2].trim() });
14333
+ }
14334
+ return models;
14335
+ }
14336
+ function discoverModelsFromCursorAgent() {
14337
+ const raw = execFileSync("cursor-agent", ["models"], {
14338
+ encoding: "utf8",
14339
+ killSignal: "SIGTERM",
14340
+ stdio: ["ignore", "pipe", "pipe"],
14341
+ timeout: MODEL_DISCOVERY_TIMEOUT_MS
14342
+ });
14343
+ const models = parseCursorModelsOutput(raw);
14344
+ if (models.length === 0) {
14345
+ throw new Error("No models parsed from cursor-agent output");
14346
+ }
14347
+ return models;
14348
+ }
14349
+ function fallbackModels() {
14350
+ return [
14351
+ { id: "auto", name: "Auto" },
14352
+ { id: "composer-1.5", name: "Composer 1.5" },
14353
+ { id: "composer-1", name: "Composer 1" },
14354
+ { id: "opus-4.6-thinking", name: "Claude 4.6 Opus (Thinking)" },
14355
+ { id: "opus-4.6", name: "Claude 4.6 Opus" },
14356
+ { id: "sonnet-4.6", name: "Claude 4.6 Sonnet" },
14357
+ { id: "sonnet-4.6-thinking", name: "Claude 4.6 Sonnet (Thinking)" },
14358
+ { id: "opus-4.5", name: "Claude 4.5 Opus" },
14359
+ { id: "opus-4.5-thinking", name: "Claude 4.5 Opus (Thinking)" },
14360
+ { id: "sonnet-4.5", name: "Claude 4.5 Sonnet" },
14361
+ { id: "sonnet-4.5-thinking", name: "Claude 4.5 Sonnet (Thinking)" },
14362
+ { id: "gpt-5.4-high", name: "GPT-5.4 High" },
14363
+ { id: "gpt-5.4-medium", name: "GPT-5.4" },
14364
+ { id: "gpt-5.3-codex", name: "GPT-5.3 Codex" },
14365
+ { id: "gpt-5.2", name: "GPT-5.2" },
14366
+ { id: "gemini-3.1-pro", name: "Gemini 3.1 Pro" },
14367
+ { id: "gemini-3-pro", name: "Gemini 3 Pro" },
14368
+ { id: "gemini-3-flash", name: "Gemini 3 Flash" },
14369
+ { id: "grok", name: "Grok" },
14370
+ { id: "kimi-k2.5", name: "Kimi K2.5" }
14371
+ ];
14372
+ }
14373
+ var MODEL_DISCOVERY_TIMEOUT_MS = 5000;
14374
+ var init_model_discovery = () => {};
14375
+
14376
+ // src/models/sync.ts
14377
+ import {
14378
+ existsSync as nodeExistsSync,
14379
+ readFileSync as nodeReadFileSync,
14380
+ writeFileSync as nodeWriteFileSync
14381
+ } from "node:fs";
14382
+ function isRecord2(value) {
14383
+ return typeof value === "object" && value !== null && !Array.isArray(value);
14384
+ }
14385
+ function parseConfig(raw) {
14386
+ try {
14387
+ const parsed = JSON.parse(raw);
14388
+ return isRecord2(parsed) ? parsed : null;
14389
+ } catch {
14390
+ return null;
14391
+ }
14392
+ }
14393
+ function getProviderConfig(config2) {
14394
+ if (!isRecord2(config2.provider)) {
14395
+ return null;
14396
+ }
14397
+ const provider = config2.provider[PROVIDER_ID];
14398
+ return isRecord2(provider) ? provider : null;
14399
+ }
14400
+ function getExistingModels(provider) {
14401
+ return isRecord2(provider.models) ? { ...provider.models } : {};
14402
+ }
14403
+ function yieldForFireAndForget() {
14404
+ return Promise.resolve();
14405
+ }
14406
+ async function autoRefreshModels(deps = {}) {
14407
+ const resolvedDeps = {
14408
+ ...defaultDeps,
14409
+ defer: yieldForFireAndForget,
14410
+ ...deps
14411
+ };
14412
+ await resolvedDeps.defer();
14413
+ try {
14414
+ const configPath = resolveOpenCodeConfigPath(resolvedDeps.env);
14415
+ if (!resolvedDeps.existsSync(configPath)) {
14416
+ resolvedDeps.log.debug("Config file not found, skipping model auto-refresh", { configPath });
14417
+ return;
14418
+ }
14419
+ const raw = resolvedDeps.readFileSync(configPath, "utf8");
14420
+ const config2 = parseConfig(raw);
14421
+ if (!config2) {
14422
+ resolvedDeps.log.debug("Config file is not valid JSON, skipping model auto-refresh");
14423
+ return;
14424
+ }
14425
+ const provider = getProviderConfig(config2);
14426
+ if (!provider) {
14427
+ resolvedDeps.log.debug("Provider section not found in config, skipping model auto-refresh");
14428
+ return;
14429
+ }
14430
+ const existingModels = getExistingModels(provider);
14431
+ let discovered;
14432
+ try {
14433
+ discovered = resolvedDeps.discoverModels();
14434
+ } catch (err) {
14435
+ resolvedDeps.log.debug("cursor-agent model discovery failed, skipping auto-refresh", {
14436
+ error: String(err)
14437
+ });
14438
+ return;
14439
+ }
14440
+ let addedCount = 0;
14441
+ for (const model of discovered) {
14442
+ if (Object.prototype.hasOwnProperty.call(existingModels, model.id))
14443
+ continue;
14444
+ existingModels[model.id] = { name: model.name };
14445
+ addedCount++;
14446
+ }
14447
+ if (addedCount === 0) {
14448
+ resolvedDeps.log.debug("Model auto-refresh: no new models found", {
14449
+ existing: Object.keys(existingModels).length,
14450
+ discovered: discovered.length
14451
+ });
14452
+ return;
14453
+ }
14454
+ provider.models = existingModels;
14455
+ resolvedDeps.writeFileSync(configPath, `${JSON.stringify(config2, null, 2)}
14456
+ `, "utf8");
14457
+ resolvedDeps.log.info("Model auto-refresh: added new models", {
14458
+ added: addedCount,
14459
+ total: Object.keys(existingModels).length
14460
+ });
14461
+ } catch (err) {
14462
+ resolvedDeps.log.debug("Model auto-refresh failed", { error: String(err) });
14463
+ }
14464
+ }
14465
+ var log9, PROVIDER_ID = "cursor-acp", defaultDeps;
14466
+ var init_sync = __esm(() => {
14467
+ init_model_discovery();
14468
+ init_plugin_toggle();
14469
+ init_logger();
14470
+ log9 = createLogger("model-sync");
14471
+ defaultDeps = {
14472
+ defer: () => Promise.resolve(),
14473
+ discoverModels: discoverModelsFromCursorAgent,
14474
+ env: process.env,
14475
+ existsSync: nodeExistsSync,
14476
+ log: log9,
14477
+ readFileSync: nodeReadFileSync,
14478
+ writeFileSync: nodeWriteFileSync
14479
+ };
14480
+ });
14481
+
14255
14482
  // node_modules/@opencode-ai/sdk/dist/gen/types.gen.js
14256
14483
  var init_types_gen = () => {};
14257
14484
 
@@ -15660,15 +15887,15 @@ class LocalExecutor {
15660
15887
  const out = await handler(args);
15661
15888
  return { status: "success", output: out };
15662
15889
  } catch (err) {
15663
- log9.warn("Local tool execution failed", { toolId, error: String(err?.message || err) });
15890
+ log10.warn("Local tool execution failed", { toolId, error: String(err?.message || err) });
15664
15891
  return { status: "error", error: String(err?.message || err) };
15665
15892
  }
15666
15893
  }
15667
15894
  }
15668
- var log9;
15895
+ var log10;
15669
15896
  var init_local = __esm(() => {
15670
15897
  init_logger();
15671
- log9 = createLogger("tools:executor:local");
15898
+ log10 = createLogger("tools:executor:local");
15672
15899
  });
15673
15900
 
15674
15901
  // src/tools/executors/sdk.ts
@@ -15695,7 +15922,7 @@ class SdkExecutor {
15695
15922
  const out = typeof res === "string" ? res : JSON.stringify(res);
15696
15923
  return { status: "success", output: out };
15697
15924
  } catch (err) {
15698
- log10.warn("SDK tool execution failed", { toolId, error: String(err?.message || err) });
15925
+ log11.warn("SDK tool execution failed", { toolId, error: String(err?.message || err) });
15699
15926
  return { status: "error", error: String(err?.message || err) };
15700
15927
  }
15701
15928
  }
@@ -15708,10 +15935,10 @@ class SdkExecutor {
15708
15935
  ]);
15709
15936
  }
15710
15937
  }
15711
- var log10;
15938
+ var log11;
15712
15939
  var init_sdk = __esm(() => {
15713
15940
  init_logger();
15714
- log10 = createLogger("tools:executor:sdk");
15941
+ log11 = createLogger("tools:executor:sdk");
15715
15942
  });
15716
15943
 
15717
15944
  // src/tools/executors/mcp.ts
@@ -15738,7 +15965,7 @@ class McpExecutor {
15738
15965
  const out = typeof res === "string" ? res : JSON.stringify(res);
15739
15966
  return { status: "success", output: out };
15740
15967
  } catch (err) {
15741
- log11.warn("MCP tool execution failed", { toolId, error: String(err?.message || err) });
15968
+ log12.warn("MCP tool execution failed", { toolId, error: String(err?.message || err) });
15742
15969
  return { status: "error", error: String(err?.message || err) };
15743
15970
  }
15744
15971
  }
@@ -15751,10 +15978,10 @@ class McpExecutor {
15751
15978
  ]);
15752
15979
  }
15753
15980
  }
15754
- var log11;
15981
+ var log12;
15755
15982
  var init_mcp = __esm(() => {
15756
15983
  init_logger();
15757
- log11 = createLogger("tools:executor:mcp");
15984
+ log12 = createLogger("tools:executor:mcp");
15758
15985
  });
15759
15986
 
15760
15987
  // src/tools/core/executor.ts
@@ -15764,17 +15991,17 @@ async function executeWithChain(executors, toolId, args) {
15764
15991
  try {
15765
15992
  return await ex.execute(toolId, args);
15766
15993
  } catch (err) {
15767
- log12.warn("Executor threw unexpected error", { toolId, error: String(err?.message || err) });
15994
+ log13.warn("Executor threw unexpected error", { toolId, error: String(err?.message || err) });
15768
15995
  return { status: "error", error: String(err?.message || err) };
15769
15996
  }
15770
15997
  }
15771
15998
  }
15772
15999
  return { status: "error", error: `No executor available for ${toolId}` };
15773
16000
  }
15774
- var log12;
16001
+ var log13;
15775
16002
  var init_executor = __esm(() => {
15776
16003
  init_logger();
15777
- log12 = createLogger("tools:executor:chain");
16004
+ log13 = createLogger("tools:executor:chain");
15778
16005
  });
15779
16006
 
15780
16007
  // src/tools/defaults.ts
@@ -16451,11 +16678,11 @@ var init_boundary = __esm(() => {
16451
16678
  function buildToolSchemaMap(tools) {
16452
16679
  const schemas3 = new Map;
16453
16680
  for (const rawTool of tools) {
16454
- const tool3 = isRecord2(rawTool) ? rawTool : null;
16681
+ const tool3 = isRecord3(rawTool) ? rawTool : null;
16455
16682
  if (!tool3) {
16456
16683
  continue;
16457
16684
  }
16458
- const fn = isRecord2(tool3.function) ? tool3.function : tool3;
16685
+ const fn = isRecord3(tool3.function) ? tool3.function : tool3;
16459
16686
  const name = typeof fn.name === "string" ? fn.name.trim() : "";
16460
16687
  if (!name) {
16461
16688
  continue;
@@ -16493,7 +16720,7 @@ function applyToolSchemaCompat(toolCall, toolSchemaMap) {
16493
16720
  function parseArguments(rawArguments) {
16494
16721
  try {
16495
16722
  const parsed = JSON.parse(rawArguments);
16496
- if (isRecord2(parsed)) {
16723
+ if (isRecord3(parsed)) {
16497
16724
  return parsed;
16498
16725
  }
16499
16726
  return { value: parsed };
@@ -16555,7 +16782,7 @@ function normalizeToolSpecificArgs(toolName, args) {
16555
16782
  return args;
16556
16783
  }
16557
16784
  const todos = args.todos.map((entry) => {
16558
- if (!isRecord2(entry)) {
16785
+ if (!isRecord3(entry)) {
16559
16786
  return entry;
16560
16787
  }
16561
16788
  const todo = { ...entry };
@@ -16618,7 +16845,7 @@ function normalizeBashCommand(value) {
16618
16845
  const parts = value.map((entry) => typeof entry === "string" ? entry : coerceToString2(entry)).filter((entry) => typeof entry === "string" && entry.length > 0);
16619
16846
  return parts.length > 0 ? parts.join(" ") : null;
16620
16847
  }
16621
- if (isRecord2(value)) {
16848
+ if (isRecord3(value)) {
16622
16849
  const command = typeof value.command === "string" ? value.command : null;
16623
16850
  const args = Array.isArray(value.args) ? value.args.map((entry) => typeof entry === "string" ? entry : coerceToString2(entry)).filter((entry) => typeof entry === "string" && entry.length > 0) : [];
16624
16851
  if (command && args.length > 0) {
@@ -16653,13 +16880,13 @@ function normalizeTodoStatus(status) {
16653
16880
  return status;
16654
16881
  }
16655
16882
  function sanitizeArgumentsForSchema(args, schema) {
16656
- if (!isRecord2(schema)) {
16883
+ if (!isRecord3(schema)) {
16657
16884
  return { args, unexpected: [] };
16658
16885
  }
16659
16886
  if (schema.additionalProperties !== false) {
16660
16887
  return { args, unexpected: [] };
16661
16888
  }
16662
- const properties = isRecord2(schema.properties) ? schema.properties : {};
16889
+ const properties = isRecord3(schema.properties) ? schema.properties : {};
16663
16890
  const propertyNames = new Set(Object.keys(properties));
16664
16891
  const sanitized = {};
16665
16892
  const unexpected = [];
@@ -16673,7 +16900,7 @@ function sanitizeArgumentsForSchema(args, schema) {
16673
16900
  return { args: sanitized, unexpected };
16674
16901
  }
16675
16902
  function validateToolArguments(toolName, args, schema, unexpected) {
16676
- if (!isRecord2(schema)) {
16903
+ if (!isRecord3(schema)) {
16677
16904
  return {
16678
16905
  hasSchema: false,
16679
16906
  ok: true,
@@ -16682,13 +16909,13 @@ function validateToolArguments(toolName, args, schema, unexpected) {
16682
16909
  typeErrors: []
16683
16910
  };
16684
16911
  }
16685
- const properties = isRecord2(schema.properties) ? schema.properties : {};
16912
+ const properties = isRecord3(schema.properties) ? schema.properties : {};
16686
16913
  const required2 = Array.isArray(schema.required) ? schema.required.filter((value) => typeof value === "string") : [];
16687
16914
  const missing = required2.filter((key) => !hasOwn(args, key));
16688
16915
  const typeErrors = [];
16689
16916
  for (const [key, value] of Object.entries(args)) {
16690
16917
  const propertySchema = properties[key];
16691
- if (!isRecord2(propertySchema)) {
16918
+ if (!isRecord3(propertySchema)) {
16692
16919
  continue;
16693
16920
  }
16694
16921
  if (!matchesType(value, propertySchema.type)) {
@@ -16747,7 +16974,7 @@ function matchesType(value, schemaType) {
16747
16974
  case "boolean":
16748
16975
  return typeof value === "boolean";
16749
16976
  case "object":
16750
- return isRecord2(value);
16977
+ return isRecord3(value);
16751
16978
  case "array":
16752
16979
  return Array.isArray(value);
16753
16980
  case "null":
@@ -16768,7 +16995,7 @@ function coerceToString2(value) {
16768
16995
  for (const item of value) {
16769
16996
  if (typeof item === "string") {
16770
16997
  parts.push(item);
16771
- } else if (isRecord2(item)) {
16998
+ } else if (isRecord3(item)) {
16772
16999
  const text = typeof item.text === "string" ? item.text : typeof item.content === "string" ? item.content : typeof item.value === "string" ? item.value : null;
16773
17000
  if (text !== null) {
16774
17001
  parts.push(text);
@@ -16781,7 +17008,7 @@ function coerceToString2(value) {
16781
17008
  }
16782
17009
  return parts.length > 0 ? parts.join("") : null;
16783
17010
  }
16784
- if (isRecord2(value)) {
17011
+ if (isRecord3(value)) {
16785
17012
  if (typeof value.text === "string") {
16786
17013
  return value.text;
16787
17014
  }
@@ -16801,7 +17028,7 @@ function coerceToString2(value) {
16801
17028
  function hasOwn(record2, key) {
16802
17029
  return Object.prototype.hasOwnProperty.call(record2, key);
16803
17030
  }
16804
- function isRecord2(value) {
17031
+ function isRecord3(value) {
16805
17032
  return typeof value === "object" && value !== null && !Array.isArray(value);
16806
17033
  }
16807
17034
  var EDIT_COMPAT_REPAIR_ENABLED, ARG_KEY_ALIASES;
@@ -16864,7 +17091,7 @@ async function handleToolLoopEventLegacy(options) {
16864
17091
  const extraction = toolLoopMode === "opencode" ? extractOpenAiToolCall(event, allowedToolNames) : { action: "skip", skipReason: "tool_loop_mode_not_opencode" };
16865
17092
  if (extraction.action === "passthrough") {
16866
17093
  passThroughTracker?.trackTool(extraction.passthroughName);
16867
- log13.debug("MCP tool passed through to cursor-agent (legacy)", {
17094
+ log14.debug("MCP tool passed through to cursor-agent (legacy)", {
16868
17095
  tool: extraction.passthroughName
16869
17096
  });
16870
17097
  return { intercepted: false, skipConverter: false };
@@ -16888,7 +17115,7 @@ async function handleToolLoopEventLegacy(options) {
16888
17115
  if (interceptedToolCall) {
16889
17116
  const compat2 = applyToolSchemaCompat(interceptedToolCall, toolSchemaMap);
16890
17117
  let normalizedToolCall = compat2.toolCall;
16891
- log13.debug("Applied tool schema compatibility (legacy)", {
17118
+ log14.debug("Applied tool schema compatibility (legacy)", {
16892
17119
  tool: normalizedToolCall.function.name,
16893
17120
  originalArgKeys: compat2.originalArgKeys,
16894
17121
  normalizedArgKeys: compat2.normalizedArgKeys,
@@ -16902,7 +17129,7 @@ async function handleToolLoopEventLegacy(options) {
16902
17129
  }
16903
17130
  const reroutedWrite = tryRerouteEditToWrite(normalizedToolCall, compat2.normalizedArgs, allowedToolNames, toolSchemaMap);
16904
17131
  if (reroutedWrite) {
16905
- log13.debug("Rerouting malformed edit call to write (legacy)", {
17132
+ log14.debug("Rerouting malformed edit call to write (legacy)", {
16906
17133
  path: reroutedWrite.path,
16907
17134
  missing: compat2.validation.missing,
16908
17135
  typeErrors: compat2.validation.typeErrors
@@ -16910,7 +17137,7 @@ async function handleToolLoopEventLegacy(options) {
16910
17137
  normalizedToolCall = reroutedWrite.toolCall;
16911
17138
  } else if (shouldEmitNonFatalSchemaValidationHint(normalizedToolCall, compat2.validation)) {
16912
17139
  const hintChunk = createNonFatalSchemaValidationHintChunk(responseMeta, normalizedToolCall, compat2.validation);
16913
- log13.debug("Emitting non-fatal schema validation hint in legacy and skipping malformed tool execution", {
17140
+ log14.debug("Emitting non-fatal schema validation hint in legacy and skipping malformed tool execution", {
16914
17141
  tool: normalizedToolCall.function.name,
16915
17142
  missing: compat2.validation.missing,
16916
17143
  typeErrors: compat2.validation.typeErrors
@@ -16972,7 +17199,7 @@ async function handleToolLoopEventV1(options) {
16972
17199
  }
16973
17200
  if (extraction.action === "passthrough") {
16974
17201
  passThroughTracker?.trackTool(extraction.passthroughName);
16975
- log13.debug("MCP tool passed through to cursor-agent (v1)", {
17202
+ log14.debug("MCP tool passed through to cursor-agent (v1)", {
16976
17203
  tool: extraction.passthroughName
16977
17204
  });
16978
17205
  return { intercepted: false, skipConverter: false };
@@ -16999,7 +17226,7 @@ async function handleToolLoopEventV1(options) {
16999
17226
  rawArgs: safeArgTypeSummary(event),
17000
17227
  normalizedArgs: compat2.normalizedArgs
17001
17228
  } : undefined;
17002
- log13.debug("Applied tool schema compatibility", {
17229
+ log14.debug("Applied tool schema compatibility", {
17003
17230
  tool: normalizedToolCall.function.name,
17004
17231
  originalArgKeys: compat2.originalArgKeys,
17005
17232
  normalizedArgKeys: compat2.normalizedArgKeys,
@@ -17008,7 +17235,7 @@ async function handleToolLoopEventV1(options) {
17008
17235
  ...editDiag ? { editDiag } : {}
17009
17236
  });
17010
17237
  if (compat2.validation.hasSchema && !compat2.validation.ok) {
17011
- log13.debug("Tool schema compatibility validation failed", {
17238
+ log14.debug("Tool schema compatibility validation failed", {
17012
17239
  tool: normalizedToolCall.function.name,
17013
17240
  missing: compat2.validation.missing,
17014
17241
  unexpected: compat2.validation.unexpected,
@@ -17025,7 +17252,7 @@ async function handleToolLoopEventV1(options) {
17025
17252
  }
17026
17253
  const reroutedWrite = tryRerouteEditToWrite(normalizedToolCall, compat2.normalizedArgs, allowedToolNames, toolSchemaMap);
17027
17254
  if (reroutedWrite) {
17028
- log13.debug("Rerouting malformed edit call to write", {
17255
+ log14.debug("Rerouting malformed edit call to write", {
17029
17256
  path: reroutedWrite.path,
17030
17257
  missing: compat2.validation.missing,
17031
17258
  typeErrors: compat2.validation.typeErrors
@@ -17045,7 +17272,7 @@ async function handleToolLoopEventV1(options) {
17045
17272
  }
17046
17273
  if (schemaValidationFailureMode === "pass_through" && shouldEmitNonFatalSchemaValidationHint(normalizedToolCall, compat2.validation)) {
17047
17274
  const hintChunk = createNonFatalSchemaValidationHintChunk(responseMeta, normalizedToolCall, compat2.validation);
17048
- log13.debug("Emitting non-fatal schema validation hint and skipping malformed tool execution", {
17275
+ log14.debug("Emitting non-fatal schema validation hint and skipping malformed tool execution", {
17049
17276
  tool: normalizedToolCall.function.name,
17050
17277
  missing: compat2.validation.missing,
17051
17278
  typeErrors: compat2.validation.typeErrors
@@ -17063,7 +17290,7 @@ async function handleToolLoopEventV1(options) {
17063
17290
  terminate: createSchemaValidationTermination(normalizedToolCall, compat2.validation)
17064
17291
  };
17065
17292
  }
17066
- log13.debug("Forwarding schema-invalid tool call to OpenCode loop", {
17293
+ log14.debug("Forwarding schema-invalid tool call to OpenCode loop", {
17067
17294
  tool: normalizedToolCall.function.name,
17068
17295
  repairHint: compat2.validation.repairHint
17069
17296
  });
@@ -17126,7 +17353,7 @@ function evaluateToolLoopGuard(toolLoopGuard, toolCall) {
17126
17353
  if (!decision.triggered) {
17127
17354
  return null;
17128
17355
  }
17129
- log13.debug("Tool loop guard triggered", {
17356
+ log14.debug("Tool loop guard triggered", {
17130
17357
  tool: toolCall.function.name,
17131
17358
  fingerprint: decision.fingerprint,
17132
17359
  repeatCount: decision.repeatCount,
@@ -17185,7 +17412,7 @@ function evaluateSchemaValidationLoopGuard(toolLoopGuard, toolCall, validation)
17185
17412
  if (!decision.tracked || !decision.triggered) {
17186
17413
  return null;
17187
17414
  }
17188
- log13.warn("Tool loop guard triggered on schema validation", {
17415
+ log14.warn("Tool loop guard triggered on schema validation", {
17189
17416
  tool: toolCall.function.name,
17190
17417
  fingerprint: decision.fingerprint,
17191
17418
  repeatCount: decision.repeatCount,
@@ -17261,11 +17488,11 @@ function safeArgTypeSummary(event) {
17261
17488
  try {
17262
17489
  let raw;
17263
17490
  const toolCallPayload = event?.tool_call;
17264
- if (isRecord3(toolCallPayload)) {
17491
+ if (isRecord4(toolCallPayload)) {
17265
17492
  const entries = Object.entries(toolCallPayload);
17266
17493
  if (entries.length > 0) {
17267
17494
  const [, payload] = entries[0];
17268
- if (isRecord3(payload)) {
17495
+ if (isRecord4(payload)) {
17269
17496
  raw = payload.args;
17270
17497
  if (raw === undefined) {
17271
17498
  const { result: _result, ...rest } = payload;
@@ -17300,7 +17527,7 @@ function safeArgTypeSummary(event) {
17300
17527
  }
17301
17528
  function shouldUsePassThroughForEditSchema(event) {
17302
17529
  const toolCallPayload = event?.tool_call;
17303
- if (!isRecord3(toolCallPayload)) {
17530
+ if (!isRecord4(toolCallPayload)) {
17304
17531
  return false;
17305
17532
  }
17306
17533
  const keys = Object.keys(toolCallPayload);
@@ -17341,15 +17568,15 @@ function tryRerouteEditToWrite(toolCall, normalizedArgs, allowedToolNames, toolS
17341
17568
  }
17342
17569
  };
17343
17570
  }
17344
- function isRecord3(value) {
17571
+ function isRecord4(value) {
17345
17572
  return typeof value === "object" && value !== null && !Array.isArray(value);
17346
17573
  }
17347
- var log13, ToolBoundaryExtractionError;
17574
+ var log14, ToolBoundaryExtractionError;
17348
17575
  var init_runtime_interception = __esm(() => {
17349
17576
  init_tool_loop();
17350
17577
  init_logger();
17351
17578
  init_tool_schema_compat();
17352
- log13 = createLogger("provider:runtime-interception");
17579
+ log14 = createLogger("provider:runtime-interception");
17353
17580
  ToolBoundaryExtractionError = class ToolBoundaryExtractionError extends Error {
17354
17581
  cause;
17355
17582
  constructor(message, cause) {
@@ -17391,7 +17618,7 @@ class ToastService {
17391
17618
  }
17392
17619
  async show(options) {
17393
17620
  if (!this.client?.tui?.showToast) {
17394
- log14.debug("Toast not available; client.tui.showToast missing", { message: options.message });
17621
+ log15.debug("Toast not available; client.tui.showToast missing", { message: options.message });
17395
17622
  return;
17396
17623
  }
17397
17624
  try {
@@ -17403,7 +17630,7 @@ class ToastService {
17403
17630
  }
17404
17631
  });
17405
17632
  } catch (error45) {
17406
- log14.debug("Toast failed", { error: error45, message: options.message });
17633
+ log15.debug("Toast failed", { error: error45, message: options.message });
17407
17634
  }
17408
17635
  }
17409
17636
  async showPassThroughSummary(tools) {
@@ -17427,10 +17654,10 @@ class ToastService {
17427
17654
  });
17428
17655
  }
17429
17656
  }
17430
- var log14, toastService;
17657
+ var log15, toastService;
17431
17658
  var init_toast_service = __esm(() => {
17432
17659
  init_logger();
17433
- log14 = createLogger("services:toast");
17660
+ log15 = createLogger("services:toast");
17434
17661
  toastService = new ToastService;
17435
17662
  });
17436
17663
 
@@ -17528,7 +17755,7 @@ function indexToolResultErrorClasses(messages) {
17528
17755
  const byCallId = new Map;
17529
17756
  let latest = null;
17530
17757
  for (const message of messages) {
17531
- if (!isRecord4(message) || message.role !== "tool") {
17758
+ if (!isRecord5(message) || message.role !== "tool") {
17532
17759
  continue;
17533
17760
  }
17534
17761
  const errorClass = classifyToolResult(message.content);
@@ -17651,7 +17878,7 @@ function deriveSuccessCoarseFingerprint(toolName, rawArguments) {
17651
17878
  }
17652
17879
  try {
17653
17880
  const parsed = JSON.parse(rawArguments);
17654
- if (!isRecord4(parsed)) {
17881
+ if (!isRecord5(parsed)) {
17655
17882
  return null;
17656
17883
  }
17657
17884
  const path2 = typeof parsed.path === "string" ? parsed.path : "";
@@ -17672,15 +17899,15 @@ function deriveSuccessCoarseFingerprint(toolName, rawArguments) {
17672
17899
  function extractAssistantToolCalls(messages) {
17673
17900
  const calls = [];
17674
17901
  for (const message of messages) {
17675
- if (!isRecord4(message) || message.role !== "assistant" || !Array.isArray(message.tool_calls)) {
17902
+ if (!isRecord5(message) || message.role !== "assistant" || !Array.isArray(message.tool_calls)) {
17676
17903
  continue;
17677
17904
  }
17678
17905
  for (const call of message.tool_calls) {
17679
- if (!isRecord4(call)) {
17906
+ if (!isRecord5(call)) {
17680
17907
  continue;
17681
17908
  }
17682
17909
  const id = typeof call.id === "string" ? call.id : "";
17683
- const fn = isRecord4(call.function) ? call.function : null;
17910
+ const fn = isRecord5(call.function) ? call.function : null;
17684
17911
  const name = fn && typeof fn.name === "string" ? fn.name : "";
17685
17912
  const rawArguments = fn && typeof fn.arguments === "string" ? fn.arguments : JSON.stringify(fn?.arguments ?? {});
17686
17913
  if (!id || !name) {
@@ -17701,7 +17928,7 @@ function extractAssistantToolCalls(messages) {
17701
17928
  function extractArgumentKeys(rawArguments) {
17702
17929
  try {
17703
17930
  const parsed = JSON.parse(rawArguments);
17704
- if (!isRecord4(parsed)) {
17931
+ if (!isRecord5(parsed)) {
17705
17932
  return [];
17706
17933
  }
17707
17934
  return Object.keys(parsed);
@@ -17773,7 +18000,7 @@ function shapeOf(value) {
17773
18000
  }
17774
18001
  return [shapeOf(value[0])];
17775
18002
  }
17776
- if (isRecord4(value)) {
18003
+ if (isRecord5(value)) {
17777
18004
  const shaped = {};
17778
18005
  for (const key of Object.keys(value).sort()) {
17779
18006
  shaped[key] = shapeOf(value[key]);
@@ -17789,7 +18016,7 @@ function canonicalizeValue(value) {
17789
18016
  if (Array.isArray(value)) {
17790
18017
  return value.map((entry) => canonicalizeValue(entry));
17791
18018
  }
17792
- if (isRecord4(value)) {
18019
+ if (isRecord5(value)) {
17793
18020
  const canonical = {};
17794
18021
  for (const key of Object.keys(value).sort()) {
17795
18022
  canonical[key] = canonicalizeValue(value[key]);
@@ -17825,7 +18052,7 @@ function renderContent(content) {
17825
18052
  if (typeof part === "string") {
17826
18053
  return part;
17827
18054
  }
17828
- if (isRecord4(part) && typeof part.text === "string") {
18055
+ if (isRecord5(part) && typeof part.text === "string") {
17829
18056
  return part.text;
17830
18057
  }
17831
18058
  return JSON.stringify(part);
@@ -17839,7 +18066,7 @@ function renderContent(content) {
17839
18066
  function containsAny(text, patterns) {
17840
18067
  return patterns.some((pattern) => text.includes(pattern));
17841
18068
  }
17842
- function isRecord4(value) {
18069
+ function isRecord5(value) {
17843
18070
  return typeof value === "object" && value !== null && !Array.isArray(value);
17844
18071
  }
17845
18072
  var UNKNOWN_AS_SUCCESS_TOOLS, EXPLORATION_TOOLS, COARSE_LIMIT_MULTIPLIER = 3, EXPLORATION_LIMIT_MULTIPLIER = 5;
@@ -17909,9 +18136,9 @@ async function ensurePluginDirectory() {
17909
18136
  const pluginDir = join5(configHome, "opencode", "plugin");
17910
18137
  try {
17911
18138
  await mkdir(pluginDir, { recursive: true });
17912
- log15.debug("Plugin directory ensured", { path: pluginDir });
18139
+ log16.debug("Plugin directory ensured", { path: pluginDir });
17913
18140
  } catch (error45) {
17914
- log15.warn("Failed to create plugin directory", { error: String(error45) });
18141
+ log16.warn("Failed to create plugin directory", { error: String(error45) });
17915
18142
  }
17916
18143
  }
17917
18144
  function shouldProcessModel(model) {
@@ -18099,9 +18326,9 @@ function createBoundaryRuntimeContext(scope) {
18099
18326
  error: toErrorMessage(error45)
18100
18327
  };
18101
18328
  if (!fallbackActive) {
18102
- log15.warn("Provider boundary v1 failed; switching to legacy for this request", details);
18329
+ log16.warn("Provider boundary v1 failed; switching to legacy for this request", details);
18103
18330
  } else {
18104
- log15.debug("Provider boundary fallback already active", details);
18331
+ log16.debug("Provider boundary fallback already active", details);
18105
18332
  }
18106
18333
  fallbackActive = true;
18107
18334
  return true;
@@ -18239,7 +18466,7 @@ async function ensureCursorProxyServer(workspaceDirectory, toolRouter) {
18239
18466
  headers: { "Content-Type": "application/json" }
18240
18467
  });
18241
18468
  } catch (err) {
18242
- log15.error("Failed to list models", { error: String(err) });
18469
+ log16.error("Failed to list models", { error: String(err) });
18243
18470
  return new Response(JSON.stringify({ error: "Failed to fetch models from cursor-agent" }), {
18244
18471
  status: 500,
18245
18472
  headers: { "Content-Type": "application/json" }
@@ -18252,7 +18479,7 @@ async function ensureCursorProxyServer(workspaceDirectory, toolRouter) {
18252
18479
  headers: { "Content-Type": "application/json" }
18253
18480
  });
18254
18481
  }
18255
- log15.debug("Proxy request (bun)", { method: req.method, path: url2.pathname });
18482
+ log16.debug("Proxy request (bun)", { method: req.method, path: url2.pathname });
18256
18483
  const body = await req.json().catch(() => ({}));
18257
18484
  const messages = Array.isArray(body?.messages) ? body.messages : [];
18258
18485
  const stream = body?.stream === true;
@@ -18279,7 +18506,7 @@ async function ensureCursorProxyServer(workspaceDirectory, toolRouter) {
18279
18506
  const clen = typeof m?.content === "string" ? m.content.length : Array.isArray(m?.content) ? `arr${m.content.length}` : typeof m?.content;
18280
18507
  return `${i}:${role}${hasTc ? `(tc:${hasTc})` : ""}(clen:${clen})`;
18281
18508
  });
18282
- log15.debug("Proxy chat request (bun)", {
18509
+ log16.debug("Proxy chat request (bun)", {
18283
18510
  stream,
18284
18511
  model,
18285
18512
  messages: messages.length,
@@ -18325,7 +18552,7 @@ async function ensureCursorProxyServer(workspaceDirectory, toolRouter) {
18325
18552
  const stdout = (stdoutText || "").trim();
18326
18553
  const stderr = (stderrText || "").trim();
18327
18554
  const exitCode = await child.exited;
18328
- log15.debug("cursor-agent completed (bun non-stream)", {
18555
+ log16.debug("cursor-agent completed (bun non-stream)", {
18329
18556
  exitCode,
18330
18557
  stdoutChars: stdout.length,
18331
18558
  stderrChars: stderr.length
@@ -18351,7 +18578,7 @@ async function ensureCursorProxyServer(workspaceDirectory, toolRouter) {
18351
18578
  });
18352
18579
  }
18353
18580
  if (intercepted.toolCall) {
18354
- log15.debug("Intercepted OpenCode tool call (non-stream)", {
18581
+ log16.debug("Intercepted OpenCode tool call (non-stream)", {
18355
18582
  name: intercepted.toolCall.function.name,
18356
18583
  callId: intercepted.toolCall.id
18357
18584
  });
@@ -18365,7 +18592,7 @@ async function ensureCursorProxyServer(workspaceDirectory, toolRouter) {
18365
18592
  const errSource = stderr || stdout || `cursor-agent exited with code ${String(exitCode ?? "unknown")} and no output`;
18366
18593
  const parsed = parseAgentError(errSource);
18367
18594
  const userError = formatErrorForUser(parsed);
18368
- log15.error("cursor-cli failed", {
18595
+ log16.error("cursor-cli failed", {
18369
18596
  type: parsed.type,
18370
18597
  message: parsed.message,
18371
18598
  code: exitCode
@@ -18400,7 +18627,7 @@ async function ensureCursorProxyServer(workspaceDirectory, toolRouter) {
18400
18627
  const converter = new StreamToSseConverter(model, { id, created });
18401
18628
  const lineBuffer = new LineBuffer;
18402
18629
  const emitToolCallAndTerminate = (toolCall) => {
18403
- log15.debug("Intercepted OpenCode tool call (stream)", {
18630
+ log16.debug("Intercepted OpenCode tool call (stream)", {
18404
18631
  name: toolCall.function.name,
18405
18632
  callId: toolCall.id
18406
18633
  });
@@ -18582,7 +18809,7 @@ async function ensureCursorProxyServer(workspaceDirectory, toolRouter) {
18582
18809
  const errSource = (stderrText || "").trim() || `cursor-agent exited with code ${String(exitCode ?? "unknown")} and no output`;
18583
18810
  const parsed = parseAgentError(errSource);
18584
18811
  const msg = formatErrorForUser(parsed);
18585
- log15.error("cursor-cli streaming failed", {
18812
+ log16.error("cursor-cli streaming failed", {
18586
18813
  type: parsed.type,
18587
18814
  code: exitCode
18588
18815
  });
@@ -18593,7 +18820,7 @@ async function ensureCursorProxyServer(workspaceDirectory, toolRouter) {
18593
18820
  controller.enqueue(encoder.encode(formatSseDone()));
18594
18821
  return;
18595
18822
  }
18596
- log15.debug("cursor-agent completed (bun stream)", {
18823
+ log16.debug("cursor-agent completed (bun stream)", {
18597
18824
  exitCode
18598
18825
  });
18599
18826
  const passThroughSummary = passThroughTracker.getSummary();
@@ -18675,7 +18902,7 @@ async function ensureCursorProxyServer(workspaceDirectory, toolRouter) {
18675
18902
  res.writeHead(200, { "Content-Type": "application/json" });
18676
18903
  res.end(JSON.stringify({ object: "list", data: models }));
18677
18904
  } catch (err) {
18678
- log15.error("Failed to list models", { error: String(err) });
18905
+ log16.error("Failed to list models", { error: String(err) });
18679
18906
  res.writeHead(500, { "Content-Type": "application/json" });
18680
18907
  res.end(JSON.stringify({ error: "Failed to fetch models" }));
18681
18908
  }
@@ -18686,7 +18913,7 @@ async function ensureCursorProxyServer(workspaceDirectory, toolRouter) {
18686
18913
  res.end(JSON.stringify({ error: `Unsupported path: ${url2.pathname}` }));
18687
18914
  return;
18688
18915
  }
18689
- log15.debug("Proxy request (node)", { method: req.method, path: url2.pathname });
18916
+ log16.debug("Proxy request (node)", { method: req.method, path: url2.pathname });
18690
18917
  let body = "";
18691
18918
  for await (const chunk of req) {
18692
18919
  body += chunk;
@@ -18709,7 +18936,7 @@ async function ensureCursorProxyServer(workspaceDirectory, toolRouter) {
18709
18936
  const contentLen = typeof m?.content === "string" ? m.content.length : Array.isArray(m?.content) ? `arr${m.content.length}` : typeof m?.content;
18710
18937
  return `${i}:${role}${hasTc ? `(tc:${hasTc})` : ""}${role === "tool" ? `(tcid:${tcId},name:${tcName},clen:${contentLen})` : `(clen:${contentLen})`}`;
18711
18938
  });
18712
- log15.debug("Proxy chat request (node)", {
18939
+ log16.debug("Proxy chat request (node)", {
18713
18940
  stream,
18714
18941
  model,
18715
18942
  messages: messages.length,
@@ -18740,14 +18967,14 @@ async function ensureCursorProxyServer(workspaceDirectory, toolRouter) {
18740
18967
  let spawnErrorText = null;
18741
18968
  child.on("error", (error45) => {
18742
18969
  spawnErrorText = String(error45?.message || error45);
18743
- log15.error("Failed to spawn cursor-agent", { error: spawnErrorText, model });
18970
+ log16.error("Failed to spawn cursor-agent", { error: spawnErrorText, model });
18744
18971
  });
18745
18972
  child.stdout.on("data", (chunk) => stdoutChunks.push(chunk));
18746
18973
  child.stderr.on("data", (chunk) => stderrChunks.push(chunk));
18747
18974
  child.on("close", async (code) => {
18748
18975
  const stdout = Buffer.concat(stdoutChunks).toString().trim();
18749
18976
  const stderr = Buffer.concat(stderrChunks).toString().trim();
18750
- log15.debug("cursor-agent completed (node non-stream)", {
18977
+ log16.debug("cursor-agent completed (node non-stream)", {
18751
18978
  code,
18752
18979
  stdoutChars: stdout.length,
18753
18980
  stderrChars: stderr.length,
@@ -18773,7 +19000,7 @@ async function ensureCursorProxyServer(workspaceDirectory, toolRouter) {
18773
19000
  return;
18774
19001
  }
18775
19002
  if (intercepted.toolCall) {
18776
- log15.debug("Intercepted OpenCode tool call (non-stream)", {
19003
+ log16.debug("Intercepted OpenCode tool call (non-stream)", {
18777
19004
  name: intercepted.toolCall.function.name,
18778
19005
  callId: intercepted.toolCall.id
18779
19006
  });
@@ -18787,7 +19014,7 @@ async function ensureCursorProxyServer(workspaceDirectory, toolRouter) {
18787
19014
  const errSource = stderr || stdout || spawnErrorText || `cursor-agent exited with code ${String(code ?? "unknown")} and no output`;
18788
19015
  const parsed = parseAgentError(errSource);
18789
19016
  const userError = formatErrorForUser(parsed);
18790
- log15.error("cursor-cli failed", {
19017
+ log16.error("cursor-cli failed", {
18791
19018
  type: parsed.type,
18792
19019
  message: parsed.message,
18793
19020
  code
@@ -18827,7 +19054,7 @@ async function ensureCursorProxyServer(workspaceDirectory, toolRouter) {
18827
19054
  return;
18828
19055
  }
18829
19056
  const errSource = String(error45?.message || error45);
18830
- log15.error("Failed to spawn cursor-agent (stream)", { error: errSource, model });
19057
+ log16.error("Failed to spawn cursor-agent (stream)", { error: errSource, model });
18831
19058
  const parsed = parseAgentError(errSource);
18832
19059
  const msg = formatErrorForUser(parsed);
18833
19060
  const errChunk = createChatCompletionChunk(id, created, model, msg, true);
@@ -18842,7 +19069,7 @@ async function ensureCursorProxyServer(workspaceDirectory, toolRouter) {
18842
19069
  if (streamTerminated || res.writableEnded) {
18843
19070
  return;
18844
19071
  }
18845
- log15.debug("Intercepted OpenCode tool call (stream)", {
19072
+ log16.debug("Intercepted OpenCode tool call (stream)", {
18846
19073
  name: toolCall.function.name,
18847
19074
  callId: toolCall.id
18848
19075
  });
@@ -19026,7 +19253,7 @@ async function ensureCursorProxyServer(workspaceDirectory, toolRouter) {
19026
19253
  perf.mark("request:done");
19027
19254
  perf.summarize();
19028
19255
  const stderrText = Buffer.concat(stderrChunks).toString().trim();
19029
- log15.debug("cursor-agent completed (node stream)", {
19256
+ log16.debug("cursor-agent completed (node stream)", {
19030
19257
  code,
19031
19258
  stderrChars: stderrText.length
19032
19259
  });
@@ -19254,7 +19481,7 @@ function buildToolHookEntries(registry2, fallbackBaseDir) {
19254
19481
  const normalizedArgs = applyToolContextDefaults(toolName, args, context, fallbackBaseDir, sessionWorkspaceBySession);
19255
19482
  return await handler(normalizedArgs);
19256
19483
  } catch (error45) {
19257
- log15.debug("Tool hook execution failed", { tool: toolName, error: String(error45?.message || error45) });
19484
+ log16.debug("Tool hook execution failed", { tool: toolName, error: String(error45?.message || error45) });
19258
19485
  throw error45;
19259
19486
  }
19260
19487
  }
@@ -19266,9 +19493,9 @@ function buildToolHookEntries(registry2, fallbackBaseDir) {
19266
19493
  }
19267
19494
  return entries;
19268
19495
  }
19269
- var log15, DEBUG_LOG_DIR2, DEBUG_LOG_FILE2, CURSOR_PROVIDER_ID2 = "cursor-acp", CURSOR_PROVIDER_PREFIX, CURSOR_PROXY_HOST = "127.0.0.1", CURSOR_PROXY_DEFAULT_PORT = 32124, CURSOR_PROXY_DEFAULT_BASE_URL, REUSE_EXISTING_PROXY, SESSION_WORKSPACE_CACHE_LIMIT = 200, FORCE_TOOL_MODE, EMIT_TOOL_UPDATES, FORWARD_TOOL_CALLS, TOOL_LOOP_MODE_RAW, TOOL_LOOP_MODE, TOOL_LOOP_MODE_VALID, PROVIDER_BOUNDARY_MODE_RAW, PROVIDER_BOUNDARY_MODE, PROVIDER_BOUNDARY_MODE_VALID, LEGACY_PROVIDER_BOUNDARY, PROVIDER_BOUNDARY, ENABLE_PROVIDER_BOUNDARY_AUTOFALLBACK, TOOL_LOOP_MAX_REPEAT_RAW, TOOL_LOOP_MAX_REPEAT, TOOL_LOOP_MAX_REPEAT_VALID, PROXY_EXECUTE_TOOL_CALLS, SUPPRESS_CONVERTER_TOOL_EVENTS, SHOULD_EMIT_TOOL_UPDATES, CursorPlugin = async ({ $, directory, worktree, client: client3, serverUrl }) => {
19496
+ var log16, DEBUG_LOG_DIR2, DEBUG_LOG_FILE2, CURSOR_PROVIDER_ID2 = "cursor-acp", CURSOR_PROVIDER_PREFIX, CURSOR_PROXY_HOST = "127.0.0.1", CURSOR_PROXY_DEFAULT_PORT = 32124, CURSOR_PROXY_DEFAULT_BASE_URL, REUSE_EXISTING_PROXY, SESSION_WORKSPACE_CACHE_LIMIT = 200, FORCE_TOOL_MODE, EMIT_TOOL_UPDATES, FORWARD_TOOL_CALLS, TOOL_LOOP_MODE_RAW, TOOL_LOOP_MODE, TOOL_LOOP_MODE_VALID, PROVIDER_BOUNDARY_MODE_RAW, PROVIDER_BOUNDARY_MODE, PROVIDER_BOUNDARY_MODE_VALID, LEGACY_PROVIDER_BOUNDARY, PROVIDER_BOUNDARY, ENABLE_PROVIDER_BOUNDARY_AUTOFALLBACK, TOOL_LOOP_MAX_REPEAT_RAW, TOOL_LOOP_MAX_REPEAT, TOOL_LOOP_MAX_REPEAT_VALID, PROXY_EXECUTE_TOOL_CALLS, SUPPRESS_CONVERTER_TOOL_EVENTS, SHOULD_EMIT_TOOL_UPDATES, CursorPlugin = async ({ $, directory, worktree, client: client3, serverUrl }) => {
19270
19497
  const workspaceDirectory = resolveWorkspaceDirectory(worktree, directory);
19271
- log15.debug("Plugin initializing", {
19498
+ log16.debug("Plugin initializing", {
19272
19499
  directory,
19273
19500
  worktree,
19274
19501
  workspaceDirectory,
@@ -19276,22 +19503,22 @@ var log15, DEBUG_LOG_DIR2, DEBUG_LOG_FILE2, CURSOR_PROVIDER_ID2 = "cursor-acp",
19276
19503
  serverUrl: serverUrl?.toString()
19277
19504
  });
19278
19505
  if (!TOOL_LOOP_MODE_VALID) {
19279
- log15.warn("Invalid CURSOR_ACP_TOOL_LOOP_MODE; defaulting to opencode", { value: TOOL_LOOP_MODE_RAW });
19506
+ log16.warn("Invalid CURSOR_ACP_TOOL_LOOP_MODE; defaulting to opencode", { value: TOOL_LOOP_MODE_RAW });
19280
19507
  }
19281
19508
  if (!PROVIDER_BOUNDARY_MODE_VALID) {
19282
- log15.warn("Invalid CURSOR_ACP_PROVIDER_BOUNDARY; defaulting to v1", {
19509
+ log16.warn("Invalid CURSOR_ACP_PROVIDER_BOUNDARY; defaulting to v1", {
19283
19510
  value: PROVIDER_BOUNDARY_MODE_RAW
19284
19511
  });
19285
19512
  }
19286
19513
  if (!TOOL_LOOP_MAX_REPEAT_VALID) {
19287
- log15.warn("Invalid CURSOR_ACP_TOOL_LOOP_MAX_REPEAT; defaulting to 3", {
19514
+ log16.warn("Invalid CURSOR_ACP_TOOL_LOOP_MAX_REPEAT; defaulting to 3", {
19288
19515
  value: TOOL_LOOP_MAX_REPEAT_RAW
19289
19516
  });
19290
19517
  }
19291
19518
  if (ENABLE_PROVIDER_BOUNDARY_AUTOFALLBACK && PROVIDER_BOUNDARY.mode !== "v1") {
19292
- log15.debug("Provider boundary auto-fallback is enabled but inactive unless mode=v1");
19519
+ log16.debug("Provider boundary auto-fallback is enabled but inactive unless mode=v1");
19293
19520
  }
19294
- log15.info("Tool loop mode configured", {
19521
+ log16.info("Tool loop mode configured", {
19295
19522
  mode: TOOL_LOOP_MODE,
19296
19523
  providerBoundary: PROVIDER_BOUNDARY.mode,
19297
19524
  proxyExecToolCalls: PROXY_EXECUTE_TOOL_CALLS,
@@ -19299,14 +19526,14 @@ var log15, DEBUG_LOG_DIR2, DEBUG_LOG_FILE2, CURSOR_PROVIDER_ID2 = "cursor-acp",
19299
19526
  toolLoopMaxRepeat: TOOL_LOOP_MAX_REPEAT
19300
19527
  });
19301
19528
  await ensurePluginDirectory();
19302
- toastService.setClient(client3);
19529
+ autoRefreshModels().catch(() => {});
19303
19530
  toastService.setClient(client3);
19304
19531
  const toolsEnabled = process.env.CURSOR_ACP_ENABLE_OPENCODE_TOOLS !== "false";
19305
19532
  const legacyProxyToolPathsEnabled = toolsEnabled && TOOL_LOOP_MODE === "proxy-exec";
19306
19533
  if (toolsEnabled && TOOL_LOOP_MODE === "opencode") {
19307
- log15.debug("OpenCode mode active; skipping legacy SDK/MCP discovery and proxy-side tool execution");
19534
+ log16.debug("OpenCode mode active; skipping legacy SDK/MCP discovery and proxy-side tool execution");
19308
19535
  } else if (toolsEnabled && TOOL_LOOP_MODE === "off") {
19309
- log15.debug("Tool loop mode off; proxy-side tool execution disabled");
19536
+ log16.debug("Tool loop mode off; proxy-side tool execution disabled");
19310
19537
  }
19311
19538
  const serverClient = legacyProxyToolPathsEnabled ? createOpencodeClient({ baseUrl: serverUrl.toString(), directory: workspaceDirectory }) : null;
19312
19539
  const discovery = legacyProxyToolPathsEnabled ? new OpenCodeToolDiscovery(serverClient ?? client3) : null;
@@ -19358,7 +19585,7 @@ var log15, DEBUG_LOG_DIR2, DEBUG_LOG_FILE2, CURSOR_PROVIDER_ID2 = "cursor-acp",
19358
19585
  discoveredList = await discovery.listTools();
19359
19586
  discoveredList.forEach((t) => toolsByName.set(t.name, t));
19360
19587
  } catch (err) {
19361
- log15.debug("Tool discovery failed, using local tools only", { error: String(err) });
19588
+ log16.debug("Tool discovery failed, using local tools only", { error: String(err) });
19362
19589
  }
19363
19590
  }
19364
19591
  const allTools = [...localTools, ...discoveredList];
@@ -19388,11 +19615,11 @@ var log15, DEBUG_LOG_DIR2, DEBUG_LOG_FILE2, CURSOR_PROVIDER_ID2 = "cursor-acp",
19388
19615
  }
19389
19616
  lastToolNames = toolEntries.map((e) => e.function.name);
19390
19617
  lastToolMap = allTools.map((t) => ({ id: t.id, name: t.name }));
19391
- log15.debug("Tools refreshed", { local: localTools.length, discovered: discoveredList.length, total: toolEntries.length });
19618
+ log16.debug("Tools refreshed", { local: localTools.length, discovered: discoveredList.length, total: toolEntries.length });
19392
19619
  return toolEntries;
19393
19620
  }
19394
19621
  const proxyBaseURL = await ensureCursorProxyServer(workspaceDirectory, router);
19395
- log15.debug("Proxy server started", { baseURL: proxyBaseURL });
19622
+ log16.debug("Proxy server started", { baseURL: proxyBaseURL });
19396
19623
  const toolHookEntries = buildToolHookEntries(localRegistry, workspaceDirectory);
19397
19624
  return {
19398
19625
  tool: toolHookEntries,
@@ -19407,9 +19634,9 @@ var log15, DEBUG_LOG_DIR2, DEBUG_LOG_FILE2, CURSOR_PROVIDER_ID2 = "cursor-acp",
19407
19634
  type: "oauth",
19408
19635
  async authorize() {
19409
19636
  try {
19410
- log15.info("Starting OAuth flow");
19637
+ log16.info("Starting OAuth flow");
19411
19638
  const { url: url2, instructions, callback } = await startCursorOAuth();
19412
- log15.debug("Got OAuth URL", { url: url2.substring(0, 50) + "..." });
19639
+ log16.debug("Got OAuth URL", { url: url2.substring(0, 50) + "..." });
19413
19640
  return {
19414
19641
  url: url2,
19415
19642
  instructions,
@@ -19417,7 +19644,7 @@ var log15, DEBUG_LOG_DIR2, DEBUG_LOG_FILE2, CURSOR_PROVIDER_ID2 = "cursor-acp",
19417
19644
  callback
19418
19645
  };
19419
19646
  } catch (error45) {
19420
- log15.error("OAuth error", { error: error45 });
19647
+ log16.error("OAuth error", { error: error45 });
19421
19648
  throw error45;
19422
19649
  }
19423
19650
  }
@@ -19441,10 +19668,10 @@ var log15, DEBUG_LOG_DIR2, DEBUG_LOG_FILE2, CURSOR_PROVIDER_ID2 = "cursor-acp",
19441
19668
  output.options.tools = resolved.tools;
19442
19669
  } else if (resolved.action === "preserve") {
19443
19670
  const count = Array.isArray(existingTools) ? existingTools.length : 0;
19444
- log15.debug("Using OpenCode-provided tools from chat.params", { count });
19671
+ log16.debug("Using OpenCode-provided tools from chat.params", { count });
19445
19672
  }
19446
19673
  } catch (err) {
19447
- log15.debug("Failed to refresh tools", { error: String(err) });
19674
+ log16.debug("Failed to refresh tools", { error: String(err) });
19448
19675
  }
19449
19676
  }
19450
19677
  },
@@ -19470,6 +19697,7 @@ var init_plugin = __esm(() => {
19470
19697
  init_discovery();
19471
19698
  init_schema();
19472
19699
  init_router();
19700
+ init_sync();
19473
19701
  init_dist2();
19474
19702
  init_local();
19475
19703
  init_sdk();
@@ -19480,7 +19708,7 @@ var init_plugin = __esm(() => {
19480
19708
  init_toast_service();
19481
19709
  init_tool_schema_compat();
19482
19710
  init_tool_loop_guard();
19483
- log15 = createLogger("plugin");
19711
+ log16 = createLogger("plugin");
19484
19712
  DEBUG_LOG_DIR2 = join5(homedir5(), ".config", "opencode", "logs");
19485
19713
  DEBUG_LOG_FILE2 = join5(DEBUG_LOG_DIR2, "tool-loop-debug.log");
19486
19714
  CURSOR_PROVIDER_PREFIX = `${CURSOR_PROVIDER_ID2}/`;
@@ -19512,72 +19740,14 @@ var init_plugin = __esm(() => {
19512
19740
  plugin_default = CursorPlugin;
19513
19741
  });
19514
19742
 
19515
- // src/plugin-toggle.ts
19516
- import { existsSync, readFileSync } from "fs";
19517
- import { homedir } from "os";
19518
- import { join, resolve } from "path";
19519
- var CURSOR_PROVIDER_ID = "cursor-acp";
19520
- var NPM_PACKAGE_NAME = "@rama_nigg/open-cursor";
19521
- function matchesPlugin(entry) {
19522
- if (entry === CURSOR_PROVIDER_ID)
19523
- return true;
19524
- if (entry === NPM_PACKAGE_NAME)
19525
- return true;
19526
- if (entry.startsWith(`${NPM_PACKAGE_NAME}@`))
19527
- return true;
19528
- return false;
19529
- }
19530
- function resolveOpenCodeConfigPath(env = process.env) {
19531
- if (env.OPENCODE_CONFIG && env.OPENCODE_CONFIG.length > 0) {
19532
- return resolve(env.OPENCODE_CONFIG);
19533
- }
19534
- const configHome = env.XDG_CONFIG_HOME && env.XDG_CONFIG_HOME.length > 0 ? env.XDG_CONFIG_HOME : join(homedir(), ".config");
19535
- return join(configHome, "opencode", "opencode.json");
19536
- }
19537
- function isCursorPluginEnabledInConfig(config) {
19538
- if (!config || typeof config !== "object") {
19539
- return true;
19540
- }
19541
- const configObject = config;
19542
- if (Array.isArray(configObject.plugin)) {
19543
- return configObject.plugin.some((entry) => matchesPlugin(entry));
19544
- }
19545
- return true;
19546
- }
19547
- function shouldEnableCursorPlugin(env = process.env) {
19548
- const configPath = resolveOpenCodeConfigPath(env);
19549
- if (!existsSync(configPath)) {
19550
- return {
19551
- enabled: true,
19552
- configPath,
19553
- reason: "config_missing"
19554
- };
19555
- }
19556
- try {
19557
- const raw = readFileSync(configPath, "utf8");
19558
- const parsed = JSON.parse(raw);
19559
- const enabled = isCursorPluginEnabledInConfig(parsed);
19560
- return {
19561
- enabled,
19562
- configPath,
19563
- reason: enabled ? "enabled_in_plugin_array_or_legacy" : "disabled_in_plugin_array"
19564
- };
19565
- } catch {
19566
- return {
19567
- enabled: true,
19568
- configPath,
19569
- reason: "config_unreadable_or_invalid"
19570
- };
19571
- }
19572
- }
19573
-
19574
19743
  // src/plugin-entry.ts
19744
+ init_plugin_toggle();
19575
19745
  init_logger();
19576
- var log16 = createLogger("plugin-entry");
19746
+ var log17 = createLogger("plugin-entry");
19577
19747
  var CursorPluginEntry = async (input) => {
19578
19748
  const state = shouldEnableCursorPlugin();
19579
19749
  if (!state.enabled) {
19580
- log16.info("Plugin disabled in OpenCode config; skipping initialization", {
19750
+ log17.info("Plugin disabled in OpenCode config; skipping initialization", {
19581
19751
  configPath: state.configPath,
19582
19752
  reason: state.reason
19583
19753
  });