Skip to content

fix(cursor): steer Windows bridge shell away from PS 5.1 syntax loops - #627

Merged
Wibias merged 3 commits into
lidge-jun:devfrom
Wibias:fix/604-cursor-win-shell-loop
Jul 29, 2026
Merged

fix(cursor): steer Windows bridge shell away from PS 5.1 syntax loops#627
Wibias merged 3 commits into
lidge-jun:devfrom
Wibias:fix/604-cursor-win-shell-loop

Conversation

@Wibias

@Wibias Wibias commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Fixes #604: cursor/auto on Windows PowerShell 5.1 could burn 20–45 tool calls after shell failures by repeatedly replaying bash/CMD syntax through the Codex shell bridge.
  • Screenshots on the issue show near-duplicate “continue / Codex shell bridge” progress lines after small repo tasks — matching a bridge-continuation loop, not a single stuck turn.
  • Stop telling the model to call the bridge with the same native-shell command; tell it to adapt for the host shell and not repeat a failing command.
  • On win32, inject PowerShell 5.1 guidance into Cursor tool system notes (no cd /d, no bash heredocs, no &&; prefer PowerShell cmdlets / ;).

Why

Native Cursor shell is deny-by-default; rejection stderr previously said “silently call that bridge tool with the same command.” Models then replay cd /d … && … and bash heredocs into PS 5.1, fail, and continue — a known Cursor/Codex Windows pattern (forum reports + Webwright #53-style loops). Guidance previously only listed POSIX cat/ls/rg examples.

Test plan

  • bun test tests/cursor-tool-definitions.test.ts tests/cursor-native-exec-policy.test.ts
  • bun run typecheck / privacy:scan
  • CI green
  • CodeRabbit + Codex threads resolved

Closes #604

Summary by CodeRabbit

  • New Features
    • Added platform-aware tool guidance that directs shell commands to be compatible with the client host, including Windows PowerShell 5.1 examples and POSIX alternatives.
  • Bug Fixes
    • Refined native execution policy-denial messaging with clearer, host-shell-neutral guidance across all native-shell rejection scenarios.
  • Tests
    • Expanded assertions to verify the updated denial text and the new Windows PowerShell 5.1 guidance content, including specific parser and command-syntax expectations.

Native-shell rejection told the model to replay the same bash/CMD command through the Codex bridge, which on Windows PowerShell 5.1 fails and loops (lidge-jun#604). Adapt for the host shell and inject PS-safe guidance instead.
@github-actions github-actions Bot added the bug Something isn't working label Jul 28, 2026
@Wibias

Wibias commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Review Change Stack

Important

Review skipped

No new commits to review since the last review.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: bcc2c203-f155-45ea-ae30-624a4b02ebd0

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The PR replaces static native-shell denial text with shared host-shell-aware guidance and updates Cursor tool notes with Windows PowerShell 5.1 and POSIX command examples. Tests verify denial wording and generated platform-specific guidance.

Changes

Cursor shell guidance

Layer / File(s) Summary
Platform-aware native shell rejection
src/adapters/cursor/native-exec-shell.ts, tests/cursor-native-exec-policy.test.ts
All native-shell policy rejection paths use nativeShellDisabledMessage(), with assertions for constrained execution, retry handling, and PowerShell 5.1 guidance.
Platform-specific Cursor tool guidance
src/adapters/cursor/tool-definitions.ts, tests/cursor-tool-definitions.test.ts
Guidance adds host-shell syntax instructions and platform-specific fallback commands, including PowerShell equivalents for common POSIX operations.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • lidge-jun/opencodex#402: Updates related Cursor native-shell rejection wording and shell-bridge fallback guidance.

Suggested reviewers: lidge-jun, ingwannu

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: Windows PowerShell 5.1 shell-bridge guidance to avoid repeated loops.
Linked Issues check ✅ Passed Changes in native-exec-shell.ts and tool-definitions.ts add PowerShell 5.1-aware guidance and tests, matching issue #604's recovery and loop-prevention goals.
Out of Scope Changes check ✅ Passed The PR stays focused on Windows shell-bridge guidance and its tests; no unrelated functionality appears in the diff.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2611629ed2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/adapters/cursor/tool-definitions.ts Outdated
Comment thread src/adapters/cursor/native-exec-shell.ts Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with 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.

Inline comments:
In `@src/adapters/cursor/native-exec-shell.ts`:
- Around line 30-32: The shell guidance in native-exec-shell.ts must explicitly
allow at most one corrected bridge attempt, then require reporting the failure
and stopping; update both Windows and non-Windows branches to prevent repeating
equivalent commands. Apply the same retry-stop contract to both fallback notes
in tool-definitions.ts, covering each platform-specific instruction without
changing unrelated guidance.

In `@tests/cursor-native-exec-policy.test.ts`:
- Around line 145-146: Update nativeShellDisabledMessage() and the rejection
test to make platform selection injectable, defaulting to process.platform for
existing callers. Add deterministic coverage that exercises both the POSIX and
win32 message branches through the same rejection path, asserting each
platform-specific wording rather than only generic text.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 764aa1bc-b8a7-4663-8fbb-82a663a37913

📥 Commits

Reviewing files that changed from the base of the PR and between ca7b104 and 2611629.

📒 Files selected for processing (4)
  • src/adapters/cursor/native-exec-shell.ts
  • src/adapters/cursor/tool-definitions.ts
  • tests/cursor-native-exec-policy.test.ts
  • tests/cursor-tool-definitions.test.ts

Comment thread src/adapters/cursor/native-exec-shell.ts Outdated
Comment thread tests/cursor-native-exec-policy.test.ts Outdated
…stop guidance

Drop proxy-OS platform branching and `;`-as-`&&` advice; use if ($?) and one corrected bridge attempt for Codex/CodeRabbit feedback on lidge-jun#627.
@Wibias

Wibias commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review
@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

@Wibias: I’ll review the changes with particular attention to PowerShell 5.1 command compatibility and whether every native-shell rejection path gives non-looping recovery guidance.

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with 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.

Inline comments:
In `@src/adapters/cursor/native-exec-shell.ts`:
- Around line 35-37: Update the shell guidance in
src/adapters/cursor/native-exec-shell.ts:35-37 and
src/adapters/cursor/tool-definitions.ts:420-423 to explicitly state that
PowerShell 5.1 does not support && or ||, and require if ($?) { ... } for
conditional follow-up steps; add matching assertions in
tests/cursor-native-exec-policy.test.ts:146-149 and
tests/cursor-tool-definitions.test.ts:335-337.

In `@tests/cursor-native-exec-policy.test.ts`:
- Around line 146-149: Update the deniedShellText assertions in the
cursor-native execution policy regression test to explicitly require guidance
that PowerShell 5.1 does not support &&. Preserve the existing assertions for if
($?), semicolon handling, and the PowerShell version while adding coverage for
the rejected && syntax.

In `@tests/cursor-tool-definitions.test.ts`:
- Around line 335-337: Update the assertions for the PowerShell note in the
relevant cursor tool definition test to explicitly verify that `&&` is
unsupported and that `if ($?)` is the replacement. Replace or supplement the
existing semicolon assertion while preserving the checks for the corrected
bridge-attempt limit.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: b583905e-d035-477e-99d5-859095a12a32

📥 Commits

Reviewing files that changed from the base of the PR and between 2611629 and b5d5bc5.

📒 Files selected for processing (4)
  • src/adapters/cursor/native-exec-shell.ts
  • src/adapters/cursor/tool-definitions.ts
  • tests/cursor-native-exec-policy.test.ts
  • tests/cursor-tool-definitions.test.ts

Comment thread src/adapters/cursor/native-exec-shell.ts
Comment thread tests/cursor-native-exec-policy.test.ts
Comment thread tests/cursor-tool-definitions.test.ts
CodeRabbit follow-up: make unsupported-parser-error wording explicit and assert it in rejection/guidance tests.
@Wibias

Wibias commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review
@coderabbitai review

Note: prior windows-latest failure was unrelated suite flake (storage cleanup / policy-preview timeouts), not #604 guidance tests.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown
🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '=== PR metadata and changed files ==='
gh pr view 627 --repo lidge-jun/opencodex --json number,title,headRefName,baseRefName,mergeable,statusCheckRollup

echo '=== PR diff ==='
gh pr diff 627 --repo lidge-jun/opencodex -- \
  src/adapters/cursor/native-exec-shell.ts \
  src/adapters/cursor/tool-definitions.ts \
  tests/cursor-native-exec-policy.test.ts \
  tests/cursor-tool-definitions.test.ts

echo '=== Source outlines ==='
ast-grep outline src/adapters/cursor/native-exec-shell.ts --items all
ast-grep outline src/adapters/cursor/tool-definitions.ts --items all

echo '=== Relevant source occurrences with context ==='
rg -n -C 10 \
  'nativeShellDisabledMessage|NATIVE_SHELL_DISABLED|rejectShellExecForPolicy|rejectShellStreamExecForPolicy|rejectBackgroundShellSpawnExecForPolicy|rejectWriteShellStdinExecForPolicy|buildCursorToolGuidanceSystemNote|hostShellNote' \
  src/adapters/cursor/native-exec-shell.ts \
  src/adapters/cursor/tool-definitions.ts

echo '=== Relevant test assertions with context ==='
rg -n -C 10 \
  'native shell|nativeShellDisabledMessage|PowerShell|cd /d|<<EOF|if \(\$\?\)|bridge attempt|host-shell-safe|buildCursorToolGuidanceSystemNote' \
  tests/cursor-native-exec-policy.test.ts \
  tests/cursor-tool-definitions.test.ts

Length of output: 4369


🏁 Script executed:

#!/bin/bash
set -euo pipefail

base_ref="origin/dev"
if ! git rev-parse --verify "$base_ref" >/dev/null 2>&1; then
  base_ref="dev"
fi
merge_base="$(git merge-base "$base_ref" HEAD)"

echo '=== Changed files relative to PR base ==='
git diff --name-status "$merge_base" HEAD

echo '=== Complete PR diff ==='
git diff --no-ext-diff --unified=80 "$merge_base" HEAD -- \
  src/adapters/cursor/native-exec-shell.ts \
  src/adapters/cursor/tool-definitions.ts \
  tests/cursor-native-exec-policy.test.ts \
  tests/cursor-tool-definitions.test.ts

echo '=== Source structure ==='
ast-grep outline src/adapters/cursor/native-exec-shell.ts --items all
ast-grep outline src/adapters/cursor/tool-definitions.ts --items all

echo '=== Native shell policy implementation ==='
nl -ba src/adapters/cursor/native-exec-shell.ts | sed -n '1,420p'

echo '=== Cursor tool guidance implementation ==='
nl -ba src/adapters/cursor/tool-definitions.ts | sed -n '1,420p'

echo '=== Native shell policy tests ==='
nl -ba tests/cursor-native-exec-policy.test.ts | sed -n '1,460p'

echo '=== Cursor tool guidance tests ==='
nl -ba tests/cursor-tool-definitions.test.ts | sed -n '1,520p'

Length of output: 1504


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '=== Authoritative PR file patches from GitHub ==='
gh api --paginate \
  'repos/lidge-jun/opencodex/pulls/627/files?per_page=100' \
  --jq '.[] | "FILE: \(.filename)\nSTATUS: \(.status)\nPATCH:\n\(.patch // "[no textual patch returned]")\n---"'

echo '=== Locate reviewed files in checkout ==='
for name in \
  native-exec-shell.ts \
  tool-definitions.ts \
  cursor-native-exec-policy.test.ts \
  cursor-tool-definitions.test.ts
do
  fd -a -t f "^${name}$" . || true
done

echo '=== Native-shell implementation and guidance source ==='
for path in \
  src/adapters/cursor/native-exec-shell.ts \
  src/adapters/cursor/tool-definitions.ts
do
  if [ -f "$path" ]; then
    echo "--- $path ---"
    nl -ba "$path" | sed -n '1,460p'
  fi
done

echo '=== Relevant tests ==='
for path in \
  tests/cursor-native-exec-policy.test.ts \
  tests/cursor-tool-definitions.test.ts
do
  if [ -f "$path" ]; then
    echo "--- $path ---"
    nl -ba "$path" | sed -n '1,560p'
  fi
done

Length of output: 11519


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '=== Native execution policy implementation (line-numbered via sed) ==='
sed -n '=' src/adapters/cursor/native-exec-shell.ts | sed -n '1,280p' >/dev/null
sed -n '1,280p' src/adapters/cursor/native-exec-shell.ts | cat -n

echo '=== Guidance construction ==='
sed -n '360,490p' src/adapters/cursor/tool-definitions.ts | cat -n

echo '=== Bridge tool schemas and working-directory handling ==='
rg -n -C 8 --type ts \
  '(shell_command|exec_command|workingDirectory|working_directory|cwd)' \
  src/adapters/cursor \
  tests/cursor-tool-definitions.test.ts

echo '=== All policy-denial function usage and focused test coverage ==='
rg -n -C 8 --type ts \
  '(rejectShellExecForPolicy|rejectShellStreamExecForPolicy|rejectBackgroundShellSpawnExecForPolicy|rejectWriteShellStdinExecForPolicy|nativeShellDisabledMessage|shellStream|backgroundShellSpawn|writeShellStdin)' \
  src/adapters/cursor \
  tests/cursor-native-exec-policy.test.ts

echo '=== Full changed test sections ==='
sed -n '1,280p' tests/cursor-native-exec-policy.test.ts | cat -n
sed -n '250,380p' tests/cursor-tool-definitions.test.ts | cat -n

Length of output: 180070


@Wibias I found one issue.

[P1] Keep filesystem policy-denial recovery guidance host-shell-safe — src/adapters/cursor/native-exec-fs.ts Line 47

The PR updates shell-denial guidance and the system note to prevent replaying POSIX/CMD syntax through a PowerShell 5.1 bridge. However, native filesystem policy denials still tell the model to continue with:

“equivalent shell commands (cat, head, ls, rg, grep)”

This string is emitted by rejectReadExecForPolicy (Lines 49-54) and reused by the rejected grep path (Lines 256-258). On a PowerShell 5.1 client, head is not a built-in command, while grep is an alias with different semantics; this can recreate the same failed-continuation pattern after a native Read/Grep denial despite the new system note.

Please update this denial text to use the same host-shell-aware guidance as the new shell message—for example, POSIX cat/ls/rg versus PowerShell Get-Content/Get-ChildItem/Select-String—and retain the one-corrected-attempt/stop rule. Ideally, centralize the recovery wording so the shell and filesystem policy-denial messages cannot drift.

The core shell change itself is otherwise consistent: nativeShellDisabledMessage() is used by regular, streamed, background-spawn, and stdin shell denial paths (Lines 51, 110, 211, and 248), and the recommended bridge workdir argument exists in CURSOR_EXEC_COMMAND_INPUT_SCHEMA (src/adapters/cursor/tool-definitions.ts Lines 30-41).

I did not run tests because the review sandbox prohibits executing repository files. The current CI status retrieved during review showed windows-latest in progress, not failed, so I found no evidence contradicting your note that the earlier Windows failure was an unrelated flake.

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@Wibias

Wibias commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator Author

Ready to merge.

@Wibias
Wibias merged commit dcaede6 into lidge-jun:dev Jul 29, 2026
11 checks passed
@Wibias

Wibias commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator Author

Transition complete for the dev land: squash dcaede6e.

Carry onto dev2-go: #675 (cherry-pick of dcaede6e).

Go decision: deferred — Cursor tool-guidance / shell-bridge notes under go/internal/adapter/cursor/ need the same #604 host-shell-neutral PS 5.1 + one-retry-stop text. Tracking: #674 (needs-go-port).

Wibias added a commit that referenced this pull request Jul 29, 2026
…#627)

* fix(cursor): steer Windows bridge shell away from PS 5.1 syntax loops

Native-shell rejection told the model to replay the same bash/CMD command through the Codex bridge, which on Windows PowerShell 5.1 fails and loops (#604). Adapt for the host shell and inject PS-safe guidance instead.

* fix(cursor): address #604 review — host-shell-neutral retry-stop guidance

Drop proxy-OS platform branching and `;`-as-`&&` advice; use if ($?) and one corrected bridge attempt for Codex/CodeRabbit feedback on #627.

* fix(cursor): state PowerShell 5.1 has no &&/|| in #604 guidance

CodeRabbit follow-up: make unsupported-parser-error wording explicit and assert it in rejection/guidance tests.
Wibias added a commit that referenced this pull request Jul 29, 2026
fix(cursor): carry Windows bridge shell guidance onto dev2-go (#627)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Cursor Auto repeats tool continuations on Windows PowerShell 5.1, causing excessive token usage

1 participant