GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Merge pull request #1997 from Yuxin-Qiao/fix/issue-1992-cursor-prompt… · agentHits/opencodex@95a9355

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src/adapters/cursor
    • native-exec-fs.ts
    • native-exec-network.ts
    • native-exec-shell.ts
    • protobuf-request.ts
    • tool-definitions.ts
  • tests
    • cursor-blob.test.ts
    • cursor-native-exec-policy.test.ts
    • cursor-native-exec.test.ts
    • cursor-tool-definitions.test.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/adapters/cursor/native-exec-fs.ts‎

Copy file name to clipboardExpand all lines: src/adapters/cursor/native-exec-fs.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function codexNativeMutationRefusal(operation: "write" | "delete", structuredEdi
4747
}
4848

4949
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.";
5151

5252
export function rejectReadExecForPolicy(execMsg: ExecServerMessage): Uint8Array {
5353
if (execMsg.message.case !== "readArgs") throw new Error("invalid read exec");
Collapse file

‎src/adapters/cursor/native-exec-network.ts‎

Copy file name to clipboardExpand all lines: src/adapters/cursor/native-exec-network.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export interface CursorNativeNetworkDeps {
77
}
88

99
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.";
1111

1212
export function rejectFetchExecForPolicy(execMsg: ExecServerMessage): Uint8Array {
1313
if (execMsg.message.case !== "fetchArgs") throw new Error("invalid fetch exec");
Collapse file

‎src/adapters/cursor/native-exec-shell.ts‎

Copy file name to clipboardExpand all lines: src/adapters/cursor/native-exec-shell.ts
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ export function nativeShellDisabledMessage(): string {
8989
// client that executes the bridge (LAN/SSH remote-proxy).
9090
return (
9191
"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. "
9392
+ "Adapt the command for the Codex client host shell before calling the bridge "
9493
+ "(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 `&&`). "
9594
+ "Make at most one corrected bridge attempt after a failure, then report the error and stop — do not repeat equivalent failing commands."
Collapse file

‎src/adapters/cursor/protobuf-request.ts‎

Copy file name to clipboardExpand all lines: src/adapters/cursor/protobuf-request.ts
+9-6Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ function rootBlobCandidate(
122122
};
123123
}
124124

125+
function toolResultRootPayload(text: string): { role: "assistant"; content: [{ type: "text"; text: string }] } {
126+
return { role: "assistant", content: [{ type: "text", text }] };
127+
}
128+
125129
function truncateToolResultBlob(entry: RootBlobCandidate, maxBytes: number): RootBlobCandidate | null {
126130
if (entry.byteLength <= maxBytes) return entry;
127131
if (entry.role !== "toolResult" || entry.text === undefined) return null;
@@ -134,7 +138,7 @@ function truncateToolResultBlob(entry: RootBlobCandidate, maxBytes: number): Roo
134138
while (end > 0 && end < encoded.byteLength && (encoded[end]! & 0xc0) === 0x80) end -= 1;
135139
const truncated = `${decoder.decode(encoded.subarray(0, end))}${marker}`;
136140
const result = rootBlobCandidate(
137-
{ role: "user", content: [{ type: "text", text: truncated }] },
141+
toolResultRootPayload(truncated),
138142
"toolResult",
139143
{ messageIndex: entry.messageIndex, text: truncated },
140144
);
@@ -143,7 +147,7 @@ function truncateToolResultBlob(entry: RootBlobCandidate, maxBytes: number): Roo
143147
keepBytes = Math.max(0, end - (result.byteLength - maxBytes) - 16);
144148
}
145149
const markerOnly = rootBlobCandidate(
146-
{ role: "user", content: [{ type: "text", text: marker.trimStart() }] },
150+
toolResultRootPayload(marker.trimStart()),
147151
"toolResult",
148152
{ messageIndex: entry.messageIndex, text: marker.trimStart() },
149153
);
@@ -175,9 +179,8 @@ function assistantRootText(
175179
// Cursor builds the actual model prompt from rootPromptMessagesJson (turns[] is UI/display metadata),
176180
// so prior history — including assistant tool calls and tool results — must be replayed here or a
177181
// 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.
181184
function rootPromptMessages(request: CursorRunRequest, requestScope: CursorBlobRequestScopeToken): {
182185
ids: Uint8Array[];
183186
byteLength: number;
@@ -232,7 +235,7 @@ function rootPromptMessages(request: CursorRunRequest, requestScope: CursorBlobR
232235
const prefix = message.isError ? "[Tool Error]" : "[Tool Result]";
233236
const text = `${prefix}\n${toolResultToText(message)}`;
234237
entries.push(rootBlobCandidate(
235-
{ role: "user", content: [{ type: "text", text }] },
238+
toolResultRootPayload(text),
236239
"toolResult",
237240
{ messageIndex: i, text },
238241
));
Collapse file

‎src/adapters/cursor/tool-definitions.ts‎

Copy file name to clipboardExpand all lines: src/adapters/cursor/tool-definitions.ts
+18-7Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,15 @@ export const CURSOR_STRUCTURED_EDIT_TOOLS = [CURSOR_EDIT_FILE_TOOL, CURSOR_MULTI
1717
export const CURSOR_EXEC_COMMAND_TOOL = CODEX_EXEC_COMMAND_TOOL;
1818
export const CODEX_SHELL_BRIDGE_TOOL_NAMES = [CODEX_EXEC_COMMAND_TOOL, CODEX_SHELL_COMMAND_TOOL] as const;
1919
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.';
2121
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+
};
2229

2330
export const CURSOR_GENERIC_TOOL_USE_USER_HINT = [
2431
"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 = [
2936
"The Cursor bridge may suspend after the first returned bridge tool call, so emit sibling calls together before any result is needed.",
3037
"If parallel emission is unavailable, continue with separate shell-bridge calls until the requested count has returned.",
3138
"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.",
3440
].join(" ");
3541

3642
export const CURSOR_EXEC_COMMAND_INPUT_SCHEMA = {
@@ -563,9 +569,14 @@ function quotedNames(names: readonly string[]): string {
563569
return names.map(name => `\`${name}\``).join(", ");
564570
}
565571

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+
566578
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));
569580
}
570581

571582
function discoveryToolLabel(wireNames: readonly string[]): string | undefined {
@@ -632,7 +643,7 @@ export function buildCursorToolGuidanceSystemNote(
632643
? "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."
633644
: undefined,
634645
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}.`
636647
: undefined,
637648
hostShellNote,
638649
"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(
656667
: undefined,
657668
"Do not count or report a tool call unless a tool result was actually returned.",
658669
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.`
660671
: undefined,
661672
].filter((note): note is string => typeof note === "string");
662673
return notes.join(" ");
Collapse file

‎tests/cursor-blob.test.ts‎

Copy file name to clipboardExpand all lines: tests/cursor-blob.test.ts
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,8 @@ describe("Cursor blob handshake", () => {
592592
const roots = decodeRootMessages(bytes) as Array<{ role?: string; content?: unknown }>;
593593
const historicalUser = roots.find(root => root.role === "user");
594594
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");
595597
expect(run?.action?.action.case).toBe("resumeAction");
596598
expect(JSON.stringify(roots)).toContain("contents");
597599
expect(JSON.stringify(roots)).not.toContain("hidden reasoning");
Collapse file

‎tests/cursor-native-exec-policy.test.ts‎

Copy file name to clipboardExpand all lines: tests/cursor-native-exec-policy.test.ts
+9-5Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,12 @@ describe("Cursor native exec sandbox policy", () => {
134134
expect(deniedText).toContain("exec_command");
135135
expect(deniedText).toContain("mcp_opencodex-responses_*");
136136
expect(deniedText).toContain("cat");
137+
expect(deniedText).toContain("Get-Content");
138+
expect(deniedText).toContain("Get-ChildItem");
139+
expect(deniedText).toContain("Select-String");
137140
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");
140143
expect(deniedText).not.toContain("disabled by OpenCodex policy");
141144
expect(deniedText).not.toContain("sandbox denial");
142145
expect(deniedText).not.toContain(content);
@@ -146,11 +149,11 @@ describe("Cursor native exec sandbox policy", () => {
146149
value: create(ShellArgsSchema, { command: "printf SHOULD_NOT_RUN", workingDirectory: dir, hardTimeout: 2000 }),
147150
}), { unsafeAllowNativeLocalExec }))[0]);
148151
const deniedShellText = stringify(deniedShell);
149-
expect(deniedShellText).toContain("silently call");
152+
expect(deniedShellText).not.toContain("silently call");
150153
expect(deniedShellText).toContain("shell_command");
151154
expect(deniedShellText).toContain("exec_command");
152155
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");
154157
expect(deniedShellText).not.toContain("with the same command");
155158
expect(deniedShellText).toContain("at most one corrected bridge attempt");
156159
expect(deniedShellText).toContain("if ($?)");
@@ -178,7 +181,8 @@ describe("Cursor native exec sandbox policy", () => {
178181
}))[0]);
179182
expect(fetchCalled).toBe(false);
180183
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");
182186
expect(deniedFetchText).toContain("shell_command");
183187
expect(deniedFetchText).toContain("curl");
184188
expect(deniedFetchText).toContain("wget");
Collapse file

‎tests/cursor-native-exec.test.ts‎

Copy file name to clipboardExpand all lines: tests/cursor-native-exec.test.ts
+13-7Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,12 @@ describe("Cursor native exec bridge", () => {
116116
expect(deniedRead.message.value.result.value.error).toContain("shell_command");
117117
expect(deniedRead.message.value.result.value.error).toContain("exec_command");
118118
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");
119122
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");
122125
expect(deniedRead.message.value.result.value.error).not.toContain("disabled by OpenCodex policy");
123126
expect(deniedRead.message.value.result.value.error).not.toContain("sandbox denial");
124127
}
@@ -133,7 +136,8 @@ describe("Cursor native exec bridge", () => {
133136
expect(deniedShell.message.value.result.value.stderr).toContain("shell_command");
134137
expect(deniedShell.message.value.result.value.stderr).toContain("exec_command");
135138
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");
137141
expect(deniedShell.message.value.result.value.stderr).not.toContain("disabled by OpenCodex policy");
138142
expect(deniedShell.message.value.result.value.stderr).not.toContain("sandbox denial");
139143
}
@@ -150,7 +154,8 @@ describe("Cursor native exec bridge", () => {
150154
expect(streamText).toContain("shell_command");
151155
expect(streamText).toContain("exec_command");
152156
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");
154159
expect(streamText).not.toContain("sandbox denial");
155160

156161
const deniedBackground = decode((await handleCursorNativeExec(execMessage({
@@ -162,7 +167,7 @@ describe("Cursor native exec bridge", () => {
162167
if (deniedBackground.message.value.result.case === "error") {
163168
expect(deniedBackground.message.value.result.value.error).toContain("shell_command");
164169
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");
166171
}
167172

168173
const deniedStdin = decode((await handleCursorNativeExec(execMessage({
@@ -183,7 +188,8 @@ describe("Cursor native exec bridge", () => {
183188
expect(deniedFetch.message.case).toBe("fetchResult");
184189
expect(deniedFetch.message.value.result.case).toBe("error");
185190
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");
187193
expect(deniedFetch.message.value.result.value.error).toContain("shell_command");
188194
expect(deniedFetch.message.value.result.value.error).toContain("curl");
189195
expect(deniedFetch.message.value.result.value.error).toContain("wget");
@@ -228,7 +234,7 @@ describe("Cursor native exec bridge", () => {
228234
expect(shell.message.value.result.value.stderr).toContain("shell_command");
229235
expect(shell.message.value.result.value.stderr).toContain("exec_command");
230236
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");
232238
expect(shell.message.value.result.value.stderr).not.toContain("sandbox denial");
233239
}
234240
});

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.