Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions src/cli/opencode-cursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ import {
import { resolveCursorAgentBinary } from "../utils/binary.js";
import { getPossibleAuthPaths, isUsableSdkApiKey } from "../auth.js";
import { parseCursorBackendPreference } from "../provider/backend.js";
import { isAgentPoolEnabled, parseAgentPoolIdleMs } from "../client/cursor-agent-child.js";
import { groupCursorModels, mergeCursorModelEntries } from "../models/variants.js";
import { resolveOpenCodeConfigPath } from "../plugin-toggle.js";
import { isSessionResumeEnabled } from "../proxy/session-resume.js";
import type { DiscoveredModel } from "./model-discovery.js";

const BRANDING_HEADER = `
Expand Down Expand Up @@ -65,6 +67,23 @@ type StatusResult = {
sdkApiKey: boolean;
sdkApiKeySource?: "CURSOR_API_KEY" | "provider.options.apiKey";
};
runtime: {
backend: {
preference: "auto" | "cursor-agent" | "sdk";
};
agentPool: {
enabled: boolean;
idleMs: number;
};
sessionResume: {
enabled: boolean;
};
logging: {
level: string;
console: boolean;
dir: string;
};
};
};

type ModelExplanation = {
Expand Down Expand Up @@ -144,6 +163,26 @@ function resolveCliSdkAuthSource(config: unknown): StatusResult["auth"]["sdkApiK
return undefined;
}

function getRuntimeStatus(): StatusResult["runtime"] {
return {
backend: {
preference: parseCursorBackendPreference(process.env.CURSOR_ACP_BACKEND).preference,
},
agentPool: {
enabled: isAgentPoolEnabled(),
idleMs: parseAgentPoolIdleMs(),
},
sessionResume: {
enabled: isSessionResumeEnabled(),
},
logging: {
level: process.env.CURSOR_ACP_LOG_LEVEL || "info",
console: process.env.CURSOR_ACP_LOG_CONSOLE === "1",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Inconsistent boolean parsing for logging.console.

The logging.console field uses a simple === "1" check, while agentPool.enabled and sessionResume.enabled use helpers that accept multiple truthy values ("1", "true", "on", "yes"). This means CURSOR_ACP_LOG_CONSOLE=true won't enable console logging, creating an inconsistent user experience.

🔧 Proposed fix to use consistent boolean parsing

Consider creating a shared helper or checking multiple truthy values:

-      console: process.env.CURSOR_ACP_LOG_CONSOLE === "1",
+      console: ["1", "true", "on", "yes"].includes(process.env.CURSOR_ACP_LOG_CONSOLE?.toLowerCase() || ""),

Alternatively, extract a shared helper like isBooleanEnvEnabled(key) and use it consistently across all boolean environment variables.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
console: process.env.CURSOR_ACP_LOG_CONSOLE === "1",
console: ["1", "true", "on", "yes"].includes(process.env.CURSOR_ACP_LOG_CONSOLE?.toLowerCase() || ""),
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/cli/opencode-cursor.ts` at line 180, The `logging.console` property uses
a simple `=== "1"` comparison for the `CURSOR_ACP_LOG_CONSOLE` environment
variable, while `agentPool.enabled` and `sessionResume.enabled` use helper
functions that accept multiple truthy values like "1", "true", "on", and "yes".
Replace the `=== "1"` check for `logging.console` with the same helper function
pattern used by the other boolean environment variable checks to ensure
consistent parsing across all environment-based boolean configurations.

dir: process.env.CURSOR_ACP_LOG_DIR || join(homedir(), ".opencode-cursor"),
},
};
}

function checkSdkApiKey(config: unknown): CheckResult {
const source = resolveCliSdkAuthSource(config);
if (source) {
Expand Down Expand Up @@ -895,6 +934,7 @@ export function getStatusResult(configPath: string, pluginPath: string): StatusR
sdkApiKey: sdkApiKeySource !== undefined,
sdkApiKeySource,
},
runtime: getRuntimeStatus(),
};
}

Expand Down Expand Up @@ -1046,6 +1086,16 @@ function commandStatus(options: Options) {
console.log(
` Cursor SDK API key: ${result.auth.sdkApiKey ? `found via ${result.auth.sdkApiKeySource}` : "not configured"}`,
);

console.log("");
console.log("Runtime");
console.log(` Backend preference: ${result.runtime.backend.preference}`);
console.log(` Agent pool: ${result.runtime.agentPool.enabled ? "enabled" : "disabled"}`);
console.log(` Agent pool idle: ${result.runtime.agentPool.idleMs}ms`);
console.log(` Session resume: ${result.runtime.sessionResume.enabled ? "enabled" : "disabled"}`);
console.log(` Log level: ${result.runtime.logging.level}`);
console.log(` Console logging: ${result.runtime.logging.console ? "enabled" : "disabled"}`);
console.log(` Log dir: ${result.runtime.logging.dir}`);
}

function commandDoctor(options: Options) {
Expand Down
67 changes: 67 additions & 0 deletions tests/unit/cli/opencode-cursor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,73 @@ describe("cli/opencode-cursor status", () => {
expect(result).toHaveProperty("provider");
expect(result).toHaveProperty("aiSdk");
});

it("reports the resolved default log directory", () => {
const originalLogDir = process.env.CURSOR_ACP_LOG_DIR;
delete process.env.CURSOR_ACP_LOG_DIR;

try {
const result = getStatusResult("/tmp/test-config.json", "/tmp/test-plugin");

expect(result.runtime.logging.dir).toBe(join(homedir(), ".opencode-cursor"));
} finally {
if (originalLogDir === undefined) {
delete process.env.CURSOR_ACP_LOG_DIR;
} else {
process.env.CURSOR_ACP_LOG_DIR = originalLogDir;
}
}
});

it("reports runtime settings that affect request performance", () => {
const originalEnv = {
CURSOR_ACP_AGENT_POOL: process.env.CURSOR_ACP_AGENT_POOL,
CURSOR_ACP_AGENT_POOL_IDLE_MS: process.env.CURSOR_ACP_AGENT_POOL_IDLE_MS,
CURSOR_ACP_SESSION_RESUME: process.env.CURSOR_ACP_SESSION_RESUME,
CURSOR_ACP_BACKEND: process.env.CURSOR_ACP_BACKEND,
CURSOR_ACP_LOG_LEVEL: process.env.CURSOR_ACP_LOG_LEVEL,
CURSOR_ACP_LOG_CONSOLE: process.env.CURSOR_ACP_LOG_CONSOLE,
CURSOR_ACP_LOG_DIR: process.env.CURSOR_ACP_LOG_DIR,
};

process.env.CURSOR_ACP_AGENT_POOL = "1";
process.env.CURSOR_ACP_AGENT_POOL_IDLE_MS = "0";
process.env.CURSOR_ACP_SESSION_RESUME = "yes";
process.env.CURSOR_ACP_BACKEND = "sdk";
process.env.CURSOR_ACP_LOG_LEVEL = "debug";
process.env.CURSOR_ACP_LOG_CONSOLE = "1";
process.env.CURSOR_ACP_LOG_DIR = "/tmp/open-cursor-logs";

try {
const result = getStatusResult("/tmp/test-config.json", "/tmp/test-plugin");

expect(result.runtime).toEqual({
backend: {
preference: "sdk",
},
agentPool: {
enabled: true,
idleMs: 0,
},
sessionResume: {
enabled: true,
},
logging: {
level: "debug",
console: true,
dir: "/tmp/open-cursor-logs",
},
});
} finally {
for (const [key, value] of Object.entries(originalEnv)) {
if (value === undefined) {
delete process.env[key];
} else {
process.env[key] = value;
}
}
}
});
});

describe("cli/opencode-cursor path resolution", () => {
Expand Down
Loading