Skip to content

fix(tools): platform-specific pager suggestions, quote/caret-safe cd detection - #543

Merged
kevincodex1 merged 1 commit into
Gitlawb:mainfrom
euxaristia:fix/windows-pager-cd-guard
Jul 7, 2026
Merged

fix(tools): platform-specific pager suggestions, quote/caret-safe cd detection#543
kevincodex1 merged 1 commit into
Gitlawb:mainfrom
euxaristia:fix/windows-pager-cd-guard

Conversation

@euxaristia

@euxaristia euxaristia commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Summary

  • The blocked-pager guard (less/more/most) now suggests type instead of cat/head/tail on Windows, since those tools don't exist there.
  • Drops more from the MSYS sandbox suggestion text, since more is itself blocked as an interactive pager and would send the model straight into that guard next.
  • detectShellCommandIssue strips double-quoted spans and cmd.exe caret escapes before matching the bash-style cd /foo pattern, so a cd-shaped string inside a quoted argument (e.g. a commit message) isn't mistaken for a real command.

This is independent of #468: it's branched from main and doesn't touch the quoting-guidance text or the MSYS/POSIX detection logic that #476 already owns.

Test plan

  • go build ./...
  • go test ./internal/tools/... ./internal/sandbox/...

Summary by CodeRabbit

  • Bug Fixes
    • Improved Windows command guidance for interactive pagers and shell issues, with clearer alternatives that better fit Windows usage.
    • Reduced false positives when detecting shell syntax issues by handling quoted text and escaped characters more accurately.
    • Updated suggestions for output piping on Windows to be more specific and less confusing.
    • Expanded test coverage for platform-specific command suggestions and detection behavior.

…detection

less/more/most now suggest `type` instead of cat/head/tail on Windows,
since those tools don't exist there. Drop `more` from the MSYS sandbox
suggestion too, since more is itself blocked as an interactive pager
and would send the model straight into that guard next.

detectShellCommandIssue also strips double-quoted spans and cmd.exe
caret escapes before matching the bash-style `cd /foo` pattern, so a
cd-shaped string inside a quoted argument (e.g. a commit message) isn't
mistaken for an actual command.
@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

This PR adds Windows-specific suggestion text for interactive pager commands (less, more, most) detected by the sandbox, and improves Windows shell-command detection by stripping quoted spans and caret-escaped metacharacters before regex matching, updating suggestion wording, and expanding test coverage accordingly.

Changes

Windows shell command detection and suggestions

Layer / File(s) Summary
Interactive pager Windows suggestion override
internal/sandbox/safe_command.go, internal/sandbox/safe_command_test.go
interactiveProgram gains a windowsSuggestion field; pager entries (less, more, most) define Windows-appropriate alternatives; DetectInteractiveCommand selects the override on Windows; new test validates platform-specific suggestion content.
Windows shell command preprocessing and suggestion text
internal/tools/shell_runtime.go, internal/tools/bash_tool_test.go
Adds stripDoubleQuotedSpans and stripCmdCaretEscapes helpers used before regex matching in detectShellCommandIssue, revises windowsMsysSandboxSuggestion and windows_shell_syntax suggestion text, and adds/updates tests for flagged bad commands, quoted-text/caret-escape false-positive avoidance, suggestion wording, and platform-specific guard output.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant BashTool
    participant ShellRuntime
    participant SafeCommand

    User->>BashTool: Submit shell command
    BashTool->>ShellRuntime: detectShellCommandIssue(command)
    ShellRuntime->>ShellRuntime: stripDoubleQuotedSpans(command)
    ShellRuntime->>ShellRuntime: stripCmdCaretEscapes(command)
    ShellRuntime->>ShellRuntime: match windowsBashStyleCDPattern
    ShellRuntime-->>BashTool: issue or nil
    BashTool->>SafeCommand: DetectInteractiveCommand(command)
    SafeCommand->>SafeCommand: lookup interactiveProgram
    SafeCommand->>SafeCommand: select suggestion (windowsSuggestion if goos=windows)
    SafeCommand-->>BashTool: InteractiveCommandResult
    BashTool-->>User: Block command with platform-specific suggestion
Loading

Possibly related issues

Possibly related PRs

  • Gitlawb/zero#109: Both modify internal/sandbox/safe_command.go's DetectInteractiveCommand interactive-program suggestion handling on Windows.
  • Gitlawb/zero#412: Both change shell_runtime.go's Windows detectShellCommandIssue logic and related bash_tool_test.go coverage for piped POSIX-utility detection.
  • Gitlawb/zero#476: Both modify shell_runtime.go's Windows MSYS/sandbox detection path, including windowsMsysSandboxSuggestion and quoted-span/caret-escape regex handling.

Suggested reviewers: Vasanthdev2004, gnanam1990, kevincodex1

🚥 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 accurately summarizes the main changes: platform-specific pager suggestions and safer cd detection on quoted/caret-escaped input.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@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.

🧹 Nitpick comments (1)
internal/tools/shell_runtime.go (1)

205-241: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Helper implementations look correct for the intended ASCII shell-metachar use case.

One nuance: stripDoubleQuotedSpans's doc comment claims it preserves "the string's length," but for multi-byte runes inside a quoted span it emits a single WriteByte(' ') per rune, which shrinks the byte length relative to the original (e.g. a 3-byte rune becomes 1 byte). This doesn't break the current regex-matching use case (shell metacharacters are all ASCII), so it's a doc-accuracy nit rather than a functional bug worth blocking on.

🤖 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 `@internal/tools/shell_runtime.go` around lines 205 - 241, The helper logic in
stripDoubleQuotedSpans is fine, but its doc comment is inaccurate because it
says the function preserves the string’s length even though multi-byte runes
inside quoted spans are replaced with single-byte spaces, changing byte length.
Update the comment to describe preserving alignment/position of unquoted text
rather than exact length, and keep the implementation in sync with the
documented behavior in stripDoubleQuotedSpans and stripCmdCaretEscapes.
🤖 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.

Nitpick comments:
In `@internal/tools/shell_runtime.go`:
- Around line 205-241: The helper logic in stripDoubleQuotedSpans is fine, but
its doc comment is inaccurate because it says the function preserves the
string’s length even though multi-byte runes inside quoted spans are replaced
with single-byte spaces, changing byte length. Update the comment to describe
preserving alignment/position of unquoted text rather than exact length, and
keep the implementation in sync with the documented behavior in
stripDoubleQuotedSpans and stripCmdCaretEscapes.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: decea9a2-1a1b-4cee-a349-b15a02f1a03d

📥 Commits

Reviewing files that changed from the base of the PR and between fd69233 and e7d21e8.

📒 Files selected for processing (4)
  • internal/sandbox/safe_command.go
  • internal/sandbox/safe_command_test.go
  • internal/tools/bash_tool_test.go
  • internal/tools/shell_runtime.go

@jatmn jatmn left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@kevincodex1 kevincodex1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@kevincodex1
kevincodex1 merged commit 8b248f4 into Gitlawb:main Jul 7, 2026
7 checks passed
yanalialiuk pushed a commit to yanalialiuk/zero that referenced this pull request Jul 8, 2026
…detection (Gitlawb#543)

less/more/most now suggest `type` instead of cat/head/tail on Windows,
since those tools don't exist there. Drop `more` from the MSYS sandbox
suggestion too, since more is itself blocked as an interactive pager
and would send the model straight into that guard next.

detectShellCommandIssue also strips double-quoted spans and cmd.exe
caret escapes before matching the bash-style `cd /foo` pattern, so a
cd-shaped string inside a quoted argument (e.g. a commit message) isn't
mistaken for an actual command.
@euxaristia
euxaristia deleted the fix/windows-pager-cd-guard branch July 17, 2026 21:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants