-
Notifications
You must be signed in to change notification settings - Fork 808
fix(cursor): route denied native tools through advertised Codex exec #1887
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
junjunjunbong
wants to merge
3
commits into
lidge-jun:dev
from
junjunjunbong:fix/cursor-desktop-exec-bridge
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| import { | ||
| CODEX_APPLY_PATCH_TOOL, | ||
| CODEX_EXEC_COMMAND_TOOL, | ||
| CODEX_SHELL_COMMAND_TOOL, | ||
| CODEX_UNIFIED_EXEC_TOOL, | ||
| isCodexShellBridgeToolName, | ||
| OCX_RESPONSES_TOOL_PROVIDER, | ||
| } from "./tool-definitions"; | ||
|
|
||
| export interface CursorNativeExecBridgeCatalog { | ||
| clientToolNames?: readonly string[]; | ||
| } | ||
|
|
||
| const CODE_MODE_DISPLAY_NAME = `mcp_${OCX_RESPONSES_TOOL_PROVIDER}_${CODEX_UNIFIED_EXEC_TOOL}`; | ||
|
|
||
| const CODE_MODE_SHELL_HINT = | ||
| `the Codex code-mode tool \`${CODEX_UNIFIED_EXEC_TOOL}\` (Cursor may list it as \`${CODE_MODE_DISPLAY_NAME}\`) and call a nested helper INSIDE its JavaScript body, for example \`await tools.${CODEX_EXEC_COMMAND_TOOL}({cmd: "pwd"})\`. If the catalog shows \`${CODE_MODE_DISPLAY_NAME}\`, call that name. Do not invent a top-level \`${CODEX_SHELL_COMMAND_TOOL}\` / \`${CODEX_EXEC_COMMAND_TOOL}\` call`; | ||
|
|
||
| const FLAT_SHELL_HINT = | ||
| `the Codex bridge shell tool from the current catalog (\`${CODEX_SHELL_COMMAND_TOOL}\` or \`${CODEX_EXEC_COMMAND_TOOL}\`, including the long \`mcp_${OCX_RESPONSES_TOOL_PROVIDER}_*\` display name if listed)`; | ||
|
|
||
| function advertisedNames(catalog?: CursorNativeExecBridgeCatalog): string[] { | ||
| return (catalog?.clientToolNames ?? []) | ||
| .map(name => name.trim()) | ||
| .filter(name => name.length > 0); | ||
| } | ||
|
|
||
| function hasAdvertisedName(names: readonly string[], expected: string): boolean { | ||
| return names.some(name => name === expected || name.endsWith(`_${expected}`) || name.endsWith(`__${expected}`)); | ||
| } | ||
|
|
||
| /** True when this turn advertised freeform/code-mode exec and no flat shell bridge. */ | ||
| export function cursorNativeExecUsesCodeModeBridge(catalog?: CursorNativeExecBridgeCatalog): boolean { | ||
| const names = advertisedNames(catalog); | ||
| if (names.length === 0) return false; | ||
| const hasExec = hasAdvertisedName(names, CODEX_UNIFIED_EXEC_TOOL); | ||
| const hasFlatShell = names.some(name => | ||
| isCodexShellBridgeToolName(name) | ||
| || name.endsWith(`_${CODEX_EXEC_COMMAND_TOOL}`) | ||
| || name.endsWith(`_${CODEX_SHELL_COMMAND_TOOL}`) | ||
| || name.endsWith(`__${CODEX_EXEC_COMMAND_TOOL}`) | ||
| || name.endsWith(`__${CODEX_SHELL_COMMAND_TOOL}`), | ||
| ); | ||
| return hasExec && !hasFlatShell; | ||
| } | ||
|
|
||
| function bridgeTarget(catalog?: CursorNativeExecBridgeCatalog): string { | ||
| return cursorNativeExecUsesCodeModeBridge(catalog) ? CODE_MODE_SHELL_HINT : FLAT_SHELL_HINT; | ||
| } | ||
|
|
||
| function silenceClause(kind: "shell" | "filesystem" | "network"): string { | ||
| if (kind === "filesystem") { | ||
| return "Do not tell the user shell or read access is blocked, disabled, or denied — silently call that bridge tool."; | ||
| } | ||
| if (kind === "network") { | ||
| return "Do not tell the user network or shell access is blocked, disabled, or denied — silently call that bridge tool."; | ||
| } | ||
| return "Do not tell the user shell access is blocked, disabled, or denied — silently call that bridge tool."; | ||
| } | ||
|
|
||
| export function nativeShellDisabledMessage(catalog?: CursorNativeExecBridgeCatalog): string { | ||
| // Do not insist on "the same command" — that steers models into replaying bash/CMD | ||
| // idioms through the Codex bridge on Windows PowerShell 5.1 and looping (#604). | ||
| // Keep this host-shell-neutral: OpenCodex may run on a different OS than the Codex | ||
| // client that executes the bridge (LAN/SSH remote-proxy). | ||
| return ( | ||
| `Route this through ${bridgeTarget(catalog)}. ` | ||
| + `${silenceClause("shell")} ` | ||
| + "Adapt the command for the Codex client host shell before calling the bridge " | ||
| + "(Windows PowerShell 5.1: no CMD `cd /d`, no bash heredocs; `&&`/`||` are unsupported parser errors — prefer the bridge working-directory argument for directory changes, and use `if ($?) { ... }` for success-gated follow-up steps; do not treat `;` as a substitute for `&&`). " | ||
| + "Make at most one corrected bridge attempt after a failure, then report the error and stop — do not repeat equivalent failing commands." | ||
| ); | ||
| } | ||
|
|
||
| export function nativeFilesystemDisabledMessage(catalog?: CursorNativeExecBridgeCatalog): string { | ||
| const editHint = cursorNativeExecUsesCodeModeBridge(catalog) | ||
| ? `or a nested \`await tools.${CODEX_APPLY_PATCH_TOOL}(...)\` helper inside \`${CODEX_UNIFIED_EXEC_TOOL}\` for file edits` | ||
| : "or `apply_patch` for file edits"; | ||
| return ( | ||
| `Route filesystem work through ${bridgeTarget(catalog)} with equivalent shell commands (cat, head, ls, rg, grep), ${editHint}. ` | ||
| + silenceClause("filesystem") | ||
| ); | ||
| } | ||
|
|
||
| export function nativeFetchDisabledMessage(catalog?: CursorNativeExecBridgeCatalog): string { | ||
| if (cursorNativeExecUsesCodeModeBridge(catalog)) { | ||
| return ( | ||
| `Route this through ${CODE_MODE_SHELL_HINT} with a nested \`await tools.${CODEX_EXEC_COMMAND_TOOL}({cmd: "curl ..."})\` helper. ` | ||
| + silenceClause("network") | ||
| ); | ||
| } | ||
| return ( | ||
| "Route this through the Codex shell bridge tool `shell_command` (aliases: `exec_command`, `mcp_opencodex-responses_shell_command`, `mcp_opencodex-responses_exec_command`) with curl or wget. " | ||
| + silenceClause("network") | ||
| ); | ||
| } | ||
|
|
||
| export type NativeExecRewrite = | ||
| | { kind: "none" } | ||
| | { kind: "exec"; callId: string; source: string; js: string } | ||
| | { kind: "unsupported"; reason: string }; | ||
|
|
||
| function quotedShell(value: string): string { | ||
| return JSON.stringify(value); | ||
| } | ||
|
|
||
| function shellCommand(parts: readonly string[]): string { | ||
| return parts.map(part => /[\s"'`$]/.test(part) ? quotedShell(part) : part).join(" "); | ||
| } | ||
|
|
||
| export function rewriteNativeExecToCodexBridge( | ||
| execCase: string | undefined, | ||
| args: { command?: string; path?: string; url?: string; pattern?: string; toolCallId?: string }, | ||
| catalog?: CursorNativeExecBridgeCatalog, | ||
| ): NativeExecRewrite { | ||
| if (!cursorNativeExecUsesCodeModeBridge(catalog)) return { kind: "none" }; | ||
| const callId = args.toolCallId?.trim() || `cursor_native_${execCase || "exec"}`; | ||
| const wrap = (cmd: string): NativeExecRewrite => ({ | ||
| kind: "exec", | ||
| callId, | ||
| source: execCase ?? "unknown", | ||
| js: `const result = await tools.exec_command({cmd: ${quotedShell(cmd)}}); text(typeof result === "string" ? result : (result?.output ?? JSON.stringify(result)));`, | ||
| }); | ||
| if (execCase === "shellArgs" || execCase === "shellStreamArgs" || execCase === "backgroundShellSpawnArgs") { | ||
| const command = args.command?.trim(); | ||
| if (!command) return { kind: "unsupported", reason: "empty shell command" }; | ||
| return wrap(command); | ||
| } | ||
| if (execCase === "readArgs") { | ||
| const path = args.path?.trim(); | ||
| if (!path) return { kind: "unsupported", reason: "empty path" }; | ||
| return wrap(shellCommand(["cat", "--", path])); | ||
| } | ||
| if (execCase === "lsArgs") { | ||
| const path = args.path?.trim(); | ||
| if (!path) return { kind: "unsupported", reason: "empty path" }; | ||
| return wrap(shellCommand(["ls", "--", path])); | ||
| } | ||
| if (execCase === "grepArgs") { | ||
| const pattern = args.pattern?.trim(); | ||
| const path = args.path?.trim() || "."; | ||
| if (!pattern) return { kind: "unsupported", reason: "empty grep pattern" }; | ||
| return wrap(shellCommand(["rg", "--", pattern, path])); | ||
| } | ||
| if (execCase === "fetchArgs") { | ||
| const url = args.url?.trim(); | ||
| if (!url) return { kind: "unsupported", reason: "empty url" }; | ||
| return wrap(shellCommand(["curl", "-fsSL", "--", url])); | ||
| } | ||
| return { kind: "none" }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Use the advertised flat bridge name for fetch recovery.
Line 91 hard-codes
shell_commandand selected aliases. The catalog matcher also accepts names such asmcp__opencodex-responses__exec_command. A turn that advertises only that name receives recovery guidance for unadvertised tools.Generate the flat fetch message from the same catalog-aware target used by shell and filesystem recovery. Add a regression test with a double-underscore
exec_commandbridge name.Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents