GeezerVison is showing github.com — Merge pull request #1997 from Yuxin-Qiao/fix/issue-1992-cursor-prompt… · agentHits/opencodex@95a9355
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: src/adapters/cursor/native-exec-fs.ts +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -47,7 +47,7 @@ function codexNativeMutationRefusal(operation: "write" | "delete", structuredEdi | 47 | 47 | } | 48 | 48 |
| 49 | 49 | const NATIVE_LOCAL_EXEC_DISABLED = | 50 | | - "Route filesystem work through the Codex Responses bridge shell tool (`shell_command` / `exec_command`, or the listed `mcp_opencodex-responses_*` display alias) with equivalent shell commands (cat, head, ls, rg, grep), or `apply_patch` for file edits. Do not tell the user shell or read access is blocked, disabled, or denied — silently call that bridge tool."; | | 50 | + "Cursor-native filesystem tools are not executed locally. Use a catalog tool for this work: `shell_command` / `exec_command` (or the listed `mcp_opencodex-responses_*` display alias) with host-shell-safe equivalents: POSIX (`cat`, `head`, `ls`, `rg`, `grep`) or Windows PowerShell (`Get-Content`, `Get-ChildItem`, `Select-String`); use `apply_patch` for file edits."; | 51 | 51 |
| 52 | 52 | export function rejectReadExecForPolicy(execMsg: ExecServerMessage): Uint8Array { | 53 | 53 | if (execMsg.message.case !== "readArgs") throw new Error("invalid read exec"); | |
Collapse file Copy file name to clipboardExpand all lines: src/adapters/cursor/native-exec-network.ts +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -7,7 +7,7 @@ export interface CursorNativeNetworkDeps { | 7 | 7 | } | 8 | 8 |
| 9 | 9 | const NATIVE_FETCH_DISABLED = | 10 | | - "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. Do not tell the user network or shell access is blocked, disabled, or denied — silently call that bridge tool."; | | 10 | + "Cursor-native fetch is not executed locally. Use the Codex shell bridge tool `shell_command` (aliases: `exec_command`, `mcp_opencodex-responses_shell_command`, `mcp_opencodex-responses_exec_command`) with curl or wget."; | 11 | 11 |
| 12 | 12 | export function rejectFetchExecForPolicy(execMsg: ExecServerMessage): Uint8Array { | 13 | 13 | if (execMsg.message.case !== "fetchArgs") throw new Error("invalid fetch exec"); | |
Collapse file Copy file name to clipboardExpand all lines: src/adapters/cursor/native-exec-shell.ts -1Lines changed: 0 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -89,7 +89,6 @@ export function nativeShellDisabledMessage(): string { | 89 | 89 | // client that executes the bridge (LAN/SSH remote-proxy). | 90 | 90 | return ( | 91 | 91 | "Route this through the Codex bridge shell tool from the current catalog (`shell_command` or `exec_command`, including the long `mcp_opencodex-responses_*` display name if listed). " | 92 | | - + "Do not tell the user shell access is blocked, disabled, or denied — silently call that bridge tool. " | 93 | 92 | + "Adapt the command for the Codex client host shell before calling the bridge " | 94 | 93 | + "(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 `&&`). " | 95 | 94 | + "Make at most one corrected bridge attempt after a failure, then report the error and stop — do not repeat equivalent failing commands." | |
Collapse file Copy file name to clipboardExpand all lines: src/adapters/cursor/protobuf-request.ts +9-6Lines changed: 9 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -122,6 +122,10 @@ function rootBlobCandidate( | 122 | 122 | }; | 123 | 123 | } | 124 | 124 |
| | 125 | +function toolResultRootPayload(text: string): { role: "assistant"; content: [{ type: "text"; text: string }] } { | | 126 | + return { role: "assistant", content: [{ type: "text", text }] }; | | 127 | +} | | 128 | + | 125 | 129 | function truncateToolResultBlob(entry: RootBlobCandidate, maxBytes: number): RootBlobCandidate | null { | 126 | 130 | if (entry.byteLength <= maxBytes) return entry; | 127 | 131 | if (entry.role !== "toolResult" || entry.text === undefined) return null; | @@ -134,7 +138,7 @@ function truncateToolResultBlob(entry: RootBlobCandidate, maxBytes: number): Roo | 134 | 138 | while (end > 0 && end < encoded.byteLength && (encoded[end]! & 0xc0) === 0x80) end -= 1; | 135 | 139 | const truncated = `${decoder.decode(encoded.subarray(0, end))}${marker}`; | 136 | 140 | const result = rootBlobCandidate( | 137 | | - { role: "user", content: [{ type: "text", text: truncated }] }, | | 141 | + toolResultRootPayload(truncated), | 138 | 142 | "toolResult", | 139 | 143 | { messageIndex: entry.messageIndex, text: truncated }, | 140 | 144 | ); | @@ -143,7 +147,7 @@ function truncateToolResultBlob(entry: RootBlobCandidate, maxBytes: number): Roo | 143 | 147 | keepBytes = Math.max(0, end - (result.byteLength - maxBytes) - 16); | 144 | 148 | } | 145 | 149 | const markerOnly = rootBlobCandidate( | 146 | | - { role: "user", content: [{ type: "text", text: marker.trimStart() }] }, | | 150 | + toolResultRootPayload(marker.trimStart()), | 147 | 151 | "toolResult", | 148 | 152 | { messageIndex: entry.messageIndex, text: marker.trimStart() }, | 149 | 153 | ); | @@ -175,9 +179,8 @@ function assistantRootText( | 175 | 179 | // Cursor builds the actual model prompt from rootPromptMessagesJson (turns[] is UI/display metadata), | 176 | 180 | // so prior history — including assistant tool calls and tool results — must be replayed here or a | 177 | 181 | // ResumeAction has nothing model-visible to continue from. The active user message is excluded | 178 | | -// because it travels in the action. Tool results are rendered as user-role text with a marker, and | 179 | | -// each entry is a SHA-256 blob ID (Cursor fetches the bytes back via getBlobArgs). Mirrors the | 180 | | -// danger-pi reference buildRootPromptMessagesJson. | | 182 | +// because it travels in the action. Tool results are assistant-role text with a [Tool Result] | | 183 | +// or [Tool Error] marker so Cursor does not wrap them as `<user_query>` (#1992). Each entry is a SHA-256 blob ID. | 181 | 184 | function rootPromptMessages(request: CursorRunRequest, requestScope: CursorBlobRequestScopeToken): { | 182 | 185 | ids: Uint8Array[]; | 183 | 186 | byteLength: number; | @@ -232,7 +235,7 @@ function rootPromptMessages(request: CursorRunRequest, requestScope: CursorBlobR | 232 | 235 | const prefix = message.isError ? "[Tool Error]" : "[Tool Result]"; | 233 | 236 | const text = `${prefix}\n${toolResultToText(message)}`; | 234 | 237 | entries.push(rootBlobCandidate( | 235 | | - { role: "user", content: [{ type: "text", text }] }, | | 238 | + toolResultRootPayload(text), | 236 | 239 | "toolResult", | 237 | 240 | { messageIndex: i, text }, | 238 | 241 | )); | |
Collapse file Copy file name to clipboardExpand all lines: src/adapters/cursor/tool-definitions.ts +18-7Lines changed: 18 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -17,8 +17,15 @@ export const CURSOR_STRUCTURED_EDIT_TOOLS = [CURSOR_EDIT_FILE_TOOL, CURSOR_MULTI | 17 | 17 | export const CURSOR_EXEC_COMMAND_TOOL = CODEX_EXEC_COMMAND_TOOL; | 18 | 18 | export const CODEX_SHELL_BRIDGE_TOOL_NAMES = [CODEX_EXEC_COMMAND_TOOL, CODEX_SHELL_COMMAND_TOOL] as const; | 19 | 19 | export const CURSOR_SHELL_ALIAS_SYSTEM_NOTE = | 20 | | - 'Shell commands use the Codex shell bridge tool shown in this turn\'s catalog (`shell_command` or `exec_command`) with JSON arguments like {"cmd":"..."}. The long `mcp_opencodex-responses_*` display name is the same tool. Prefer it over Cursor-native Shell; never say native shell is blocked.'; | | 20 | + 'Shell commands use the Codex shell bridge tool shown in this turn\'s catalog (`shell_command` or `exec_command`) with JSON arguments like {"cmd":"..."}. The long `mcp_opencodex-responses_*` display name is the same tool. Prefer it over Cursor-native Shell.'; | 21 | 21 | const NEIGHBOR_AGENT_TOOL_NAMES = ["Read", "Grep", "Glob", "Bash", "LS"] as const; | | 22 | +const NEIGHBOR_AGENT_TOOL_ALIASES: Record<(typeof NEIGHBOR_AGENT_TOOL_NAMES)[number], readonly string[]> = { | | 23 | + Read: ["read", "read_file"], | | 24 | + Grep: ["grep"], | | 25 | + Glob: ["glob", "find"], | | 26 | + Bash: ["bash", "shell"], | | 27 | + LS: ["ls"], | | 28 | +}; | 22 | 29 |
| 23 | 30 | export const CURSOR_GENERIC_TOOL_USE_USER_HINT = [ | 24 | 31 | "For generic tool-use/count demos, satisfy the request with repeated Codex shell bridge calls (`shell_command` or `exec_command`) for harmless commands.", | @@ -29,8 +36,7 @@ export const CURSOR_GENERIC_TOOL_USE_USER_HINT = [ | 29 | 36 | "The Cursor bridge may suspend after the first returned bridge tool call, so emit sibling calls together before any result is needed.", | 30 | 37 | "If parallel emission is unavailable, continue with separate shell-bridge calls until the requested count has returned.", | 31 | 38 | "Do not use `tool_search`, external MCP, or resource discovery just to pad the count unless explicitly asked.", | 32 | | - "Do not suggest or switch to neighboring-agent tools such as `Grep`, `Read`, `Glob`, `Bash`, or `LS` unless this turn's catalog lists those exact names.", | 33 | | - "Never tell the user that shell or read access is blocked, disabled, or denied unless the Codex shell bridge tool itself fails. Do not narrate Cursor-native Shell/Read routing.", | | 39 | + "Do not suggest or switch to neighboring-agent tools such as `Grep`, `Read`, `Glob`, `Bash`, or `LS` unless this turn's catalog lists those exact names or an equivalent listed client tool.", | 34 | 40 | ].join(" "); | 35 | 41 |
| 36 | 42 | export const CURSOR_EXEC_COMMAND_INPUT_SCHEMA = { | @@ -563,9 +569,14 @@ function quotedNames(names: readonly string[]): string { | 563 | 569 | return names.map(name => `\`${name}\``).join(", "); | 564 | 570 | } | 565 | 571 |
| | 572 | +function advertisedCoversNeighbor(wireNames: readonly string[], neighbor: (typeof NEIGHBOR_AGENT_TOOL_NAMES)[number]): boolean { | | 573 | + const advertised = new Set(wireNames.map(name => name.toLowerCase())); | | 574 | + if (advertised.has(neighbor.toLowerCase())) return true; | | 575 | + return NEIGHBOR_AGENT_TOOL_ALIASES[neighbor].some(alias => advertised.has(alias.toLowerCase())); | | 576 | +} | | 577 | + | 566 | 578 | function unavailableNeighborAgentToolNames(wireNames: readonly string[]): string[] { | 567 | | - const advertised = new Set(wireNames); | 568 | | - return NEIGHBOR_AGENT_TOOL_NAMES.filter(name => !advertised.has(name)); | | 579 | + return NEIGHBOR_AGENT_TOOL_NAMES.filter(name => !advertisedCoversNeighbor(wireNames, name)); | 569 | 580 | } | 570 | 581 |
| 571 | 582 | function discoveryToolLabel(wireNames: readonly string[]): string | undefined { | @@ -632,7 +643,7 @@ export function buildCursorToolGuidanceSystemNote( | 632 | 643 | ? "Your tool list may display it under a longer `mcp_opencodex-responses_shell_command` / `mcp_opencodex-responses_exec_command` name; those are the SAME tool — call whichever your list shows, and do not comment on the naming difference to the user." | 633 | 644 | : undefined, | 634 | 645 | hasBareExec | 635 | | - ? "Never tell the user that shell or read access is blocked, disabled, or denied unless the Codex shell bridge tool itself fails. Prefer the bridge over Cursor-native Shell/Read; do not narrate phrases like \"Native shell access is blocked\" — silently call `shell_command` / `exec_command`." | | 646 | + ? `Prefer the Codex shell bridge over Cursor-native Shell/Read. If a Cursor-native file read, directory listing, grep, or shell operation is rejected, continue with the listed catalog tool ${shellBridgeLabel}.` | 636 | 647 | : undefined, | 637 | 648 | hostShellNote, | 638 | 649 | "Cursor product features (Chronicle, screen recording, Notes, Plans, background agents) are available only if this turn's catalog lists a matching tool; do not offer or promise them otherwise.", | @@ -656,7 +667,7 @@ export function buildCursorToolGuidanceSystemNote( | 656 | 667 | : undefined, | 657 | 668 | "Do not count or report a tool call unless a tool result was actually returned.", | 658 | 669 | hasBareExec | 659 | | - ? `If a Cursor-native file read, directory listing, grep, or shell operation is rejected by the runtime, silently use ${shellBridgeLabel} with an equivalent host-shell-safe command (POSIX: \`cat\`/\`ls\`/\`rg\`; Windows PowerShell: \`Get-Content\`/\`Get-ChildItem\`/\`Select-String\`). Do not tell the user access is blocked. For file edits, use ${structuredEditNames.length > 0 ? `the structured edit tools (${quotedNames(structuredEditNames)}) or ` : ""}\`apply_patch\` when available.` | | 670 | + ? `If a Cursor-native file read, directory listing, grep, or shell operation is rejected by the runtime, use ${shellBridgeLabel} with an equivalent host-shell-safe command (POSIX: \`cat\`/\`ls\`/\`rg\`; Windows PowerShell: \`Get-Content\`/\`Get-ChildItem\`/\`Select-String\`). For file edits, use ${structuredEditNames.length > 0 ? `the structured edit tools (${quotedNames(structuredEditNames)}) or ` : ""}\`apply_patch\` when available.` | 660 | 671 | : undefined, | 661 | 672 | ].filter((note): note is string => typeof note === "string"); | 662 | 673 | return notes.join(" "); | |
Collapse file Copy file name to clipboardExpand all lines: tests/cursor-blob.test.ts +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -592,6 +592,8 @@ describe("Cursor blob handshake", () => { | 592 | 592 | const roots = decodeRootMessages(bytes) as Array<{ role?: string; content?: unknown }>; | 593 | 593 | const historicalUser = roots.find(root => root.role === "user"); | 594 | 594 | expect(historicalUser?.content).toEqual([{ type: "text", text: "read a file" }]); | | 595 | + const toolResultRoot = roots.find(root => JSON.stringify(root).includes("[Tool Result]")); | | 596 | + expect(toolResultRoot?.role).toBe("assistant"); | 595 | 597 | expect(run?.action?.action.case).toBe("resumeAction"); | 596 | 598 | expect(JSON.stringify(roots)).toContain("contents"); | 597 | 599 | expect(JSON.stringify(roots)).not.toContain("hidden reasoning"); | |
Collapse file Copy file name to clipboardExpand all lines: tests/cursor-native-exec-policy.test.ts +9-5Lines changed: 9 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -134,9 +134,12 @@ describe("Cursor native exec sandbox policy", () => { | 134 | 134 | expect(deniedText).toContain("exec_command"); | 135 | 135 | expect(deniedText).toContain("mcp_opencodex-responses_*"); | 136 | 136 | expect(deniedText).toContain("cat"); | | 137 | + expect(deniedText).toContain("Get-Content"); | | 138 | + expect(deniedText).toContain("Get-ChildItem"); | | 139 | + expect(deniedText).toContain("Select-String"); | 137 | 140 | expect(deniedText).toContain("apply_patch"); | 138 | | - expect(deniedText).toContain("silently call"); | 139 | | - expect(deniedText).toContain("Do not tell the user"); | | 141 | + expect(deniedText).not.toContain("silently call"); | | 142 | + expect(deniedText).not.toContain("Do not tell the user"); | 140 | 143 | expect(deniedText).not.toContain("disabled by OpenCodex policy"); | 141 | 144 | expect(deniedText).not.toContain("sandbox denial"); | 142 | 145 | expect(deniedText).not.toContain(content); | @@ -146,11 +149,11 @@ describe("Cursor native exec sandbox policy", () => { | 146 | 149 | value: create(ShellArgsSchema, { command: "printf SHOULD_NOT_RUN", workingDirectory: dir, hardTimeout: 2000 }), | 147 | 150 | }), { unsafeAllowNativeLocalExec }))[0]); | 148 | 151 | const deniedShellText = stringify(deniedShell); | 149 | | - expect(deniedShellText).toContain("silently call"); | | 152 | + expect(deniedShellText).not.toContain("silently call"); | 150 | 153 | expect(deniedShellText).toContain("shell_command"); | 151 | 154 | expect(deniedShellText).toContain("exec_command"); | 152 | 155 | expect(deniedShellText).toContain("mcp_opencodex-responses_*"); | 153 | | - expect(deniedShellText).toContain("Do not tell the user"); | | 156 | + expect(deniedShellText).not.toContain("Do not tell the user"); | 154 | 157 | expect(deniedShellText).not.toContain("with the same command"); | 155 | 158 | expect(deniedShellText).toContain("at most one corrected bridge attempt"); | 156 | 159 | expect(deniedShellText).toContain("if ($?)"); | @@ -178,7 +181,8 @@ describe("Cursor native exec sandbox policy", () => { | 178 | 181 | }))[0]); | 179 | 182 | expect(fetchCalled).toBe(false); | 180 | 183 | const deniedFetchText = stringify(deniedFetch); | 181 | | - expect(deniedFetchText).toContain("silently call"); | | 184 | + expect(deniedFetchText).not.toContain("silently call"); | | 185 | + expect(deniedFetchText).not.toContain("Do not tell the user"); | 182 | 186 | expect(deniedFetchText).toContain("shell_command"); | 183 | 187 | expect(deniedFetchText).toContain("curl"); | 184 | 188 | expect(deniedFetchText).toContain("wget"); | |
Collapse file Copy file name to clipboardExpand all lines: tests/cursor-native-exec.test.ts +13-7Lines changed: 13 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -116,9 +116,12 @@ describe("Cursor native exec bridge", () => { | 116 | 116 | expect(deniedRead.message.value.result.value.error).toContain("shell_command"); | 117 | 117 | expect(deniedRead.message.value.result.value.error).toContain("exec_command"); | 118 | 118 | expect(deniedRead.message.value.result.value.error).toContain("cat"); | | 119 | + expect(deniedRead.message.value.result.value.error).toContain("Get-Content"); | | 120 | + expect(deniedRead.message.value.result.value.error).toContain("Get-ChildItem"); | | 121 | + expect(deniedRead.message.value.result.value.error).toContain("Select-String"); | 119 | 122 | expect(deniedRead.message.value.result.value.error).toContain("apply_patch"); | 120 | | - expect(deniedRead.message.value.result.value.error).toContain("silently call"); | 121 | | - expect(deniedRead.message.value.result.value.error).toContain("Do not tell the user"); | | 123 | + expect(deniedRead.message.value.result.value.error).not.toContain("silently call"); | | 124 | + expect(deniedRead.message.value.result.value.error).not.toContain("Do not tell the user"); | 122 | 125 | expect(deniedRead.message.value.result.value.error).not.toContain("disabled by OpenCodex policy"); | 123 | 126 | expect(deniedRead.message.value.result.value.error).not.toContain("sandbox denial"); | 124 | 127 | } | @@ -133,7 +136,8 @@ describe("Cursor native exec bridge", () => { | 133 | 136 | expect(deniedShell.message.value.result.value.stderr).toContain("shell_command"); | 134 | 137 | expect(deniedShell.message.value.result.value.stderr).toContain("exec_command"); | 135 | 138 | expect(deniedShell.message.value.result.value.stderr).toContain("mcp_opencodex-responses_*"); | 136 | | - expect(deniedShell.message.value.result.value.stderr).toContain("Do not tell the user"); | | 139 | + expect(deniedShell.message.value.result.value.stderr).not.toContain("Do not tell the user"); | | 140 | + expect(deniedShell.message.value.result.value.stderr).not.toContain("silently call"); | 137 | 141 | expect(deniedShell.message.value.result.value.stderr).not.toContain("disabled by OpenCodex policy"); | 138 | 142 | expect(deniedShell.message.value.result.value.stderr).not.toContain("sandbox denial"); | 139 | 143 | } | @@ -150,7 +154,8 @@ describe("Cursor native exec bridge", () => { | 150 | 154 | expect(streamText).toContain("shell_command"); | 151 | 155 | expect(streamText).toContain("exec_command"); | 152 | 156 | expect(streamText).toContain("mcp_opencodex-responses_*"); | 153 | | - expect(streamText).toContain("Do not tell the user"); | | 157 | + expect(streamText).not.toContain("Do not tell the user"); | | 158 | + expect(streamText).not.toContain("silently call"); | 154 | 159 | expect(streamText).not.toContain("sandbox denial"); | 155 | 160 |
| 156 | 161 | const deniedBackground = decode((await handleCursorNativeExec(execMessage({ | @@ -162,7 +167,7 @@ describe("Cursor native exec bridge", () => { | 162 | 167 | if (deniedBackground.message.value.result.case === "error") { | 163 | 168 | expect(deniedBackground.message.value.result.value.error).toContain("shell_command"); | 164 | 169 | expect(deniedBackground.message.value.result.value.error).toContain("exec_command"); | 165 | | - expect(deniedBackground.message.value.result.value.error).toContain("Do not tell the user"); | | 170 | + expect(deniedBackground.message.value.result.value.error).not.toContain("Do not tell the user"); | 166 | 171 | } | 167 | 172 |
| 168 | 173 | const deniedStdin = decode((await handleCursorNativeExec(execMessage({ | @@ -183,7 +188,8 @@ describe("Cursor native exec bridge", () => { | 183 | 188 | expect(deniedFetch.message.case).toBe("fetchResult"); | 184 | 189 | expect(deniedFetch.message.value.result.case).toBe("error"); | 185 | 190 | if (deniedFetch.message.value.result.case === "error") { | 186 | | - expect(deniedFetch.message.value.result.value.error).toContain("silently call"); | | 191 | + expect(deniedFetch.message.value.result.value.error).not.toContain("silently call"); | | 192 | + expect(deniedFetch.message.value.result.value.error).not.toContain("Do not tell the user"); | 187 | 193 | expect(deniedFetch.message.value.result.value.error).toContain("shell_command"); | 188 | 194 | expect(deniedFetch.message.value.result.value.error).toContain("curl"); | 189 | 195 | expect(deniedFetch.message.value.result.value.error).toContain("wget"); | @@ -228,7 +234,7 @@ describe("Cursor native exec bridge", () => { | 228 | 234 | expect(shell.message.value.result.value.stderr).toContain("shell_command"); | 229 | 235 | expect(shell.message.value.result.value.stderr).toContain("exec_command"); | 230 | 236 | expect(shell.message.value.result.value.stderr).toContain("mcp_opencodex-responses_*"); | 231 | | - expect(shell.message.value.result.value.stderr).toContain("Do not tell the user"); | | 237 | + expect(shell.message.value.result.value.stderr).not.toContain("Do not tell the user"); | 232 | 238 | expect(shell.message.value.result.value.stderr).not.toContain("sandbox denial"); | 233 | 239 | } | 234 | 240 | }); | |
|