Skip to content

fix(sandbox): Windows-appropriate suggestions when blocking interactive commands#414

Open
PierrunoYT wants to merge 1 commit into
Gitlawb:mainfrom
PierrunoYT:fix/windows-interactive-command-suggestions
Open

fix(sandbox): Windows-appropriate suggestions when blocking interactive commands#414
PierrunoYT wants to merge 1 commit into
Gitlawb:mainfrom
PierrunoYT:fix/windows-interactive-command-suggestions

Conversation

@PierrunoYT

@PierrunoYT PierrunoYT commented Jul 2, 2026

Copy link
Copy Markdown

Summary

DetectInteractiveCommand already receives goos, but its remediation text for pagers (less/more/most), process monitors (top/htop/btop/btm), and tail -f hardcoded POSIX-only alternatives (cat, head, tail -n N, ps aux) regardless of platform. On Windows none of those exist either (Zero's bash tool executes through native cmd.exe there), so blocking e.g. type file | more correctly stopped the interactive command but then pointed the model at three more commands cmd.exe doesn't have — undermining the guidance this check exists to give. Reported in the wild.

Adds an optional windowsSuggestion per program/segment, used in place of the POSIX suggestion when goos == "windows": type <file> (or the read_file tool) for pagers/tail -f, tasklist for process monitors. Non-Windows suggestions are unchanged. Scoped to the cases where the POSIX suggestion was the sole remediation offered — left vim/vi/etc.'s secondary sed -i mention alone since edit_file/write_file is already their correct primary suggestion.

Linked issue

Fixes #413

Checklist

  • The linked issue already has the issue-approved label.
  • go build ./..., go vet ./..., and go test ./... pass locally.
  • gofmt clean.
  • Tests added/updated for the change (and run under -race where relevant).
  • UI changes include screenshots or a short recording where possible.

Verification notes

  • go build ./... / go vet ./... clean.
  • Added TestDetectInteractiveCommandSuggestsWindowsAlternativesOnWindows (internal/sandbox/safe_command_test.go), covering more/lesstype, htoptasklist, tail -fread_file, and confirming Linux keeps the original POSIX suggestion unchanged.
  • go test ./internal/sandbox/... passes in full, including all pre-existing interactive-command tests.
  • gofmt -l on the touched files: pre-existing repo-wide CRLF flag (core.autocrlf=true on Windows), not introduced by this change — same as prior PRs against this repo.
  • Not a UI change.

Summary by CodeRabbit

  • New Features

    • Interactive command warnings now include Windows-specific suggested alternatives for common tools like pagers and process monitors.
    • Follow-mode commands now surface clearer Windows guidance when detected as interactive.
  • Bug Fixes

    • Improved suggestion selection so Windows users see more relevant next-step commands instead of POSIX-only alternatives.
  • Tests

    • Added coverage for Windows-specific interactive command suggestions and verified existing Linux behavior remains unchanged.

…ractive commands

DetectInteractiveCommand already receives goos, but its remediation
text for pagers (less/more/most), process monitors (top/htop/btop/
btm), and `tail -f` hardcoded POSIX-only alternatives (cat, head,
tail -n N, ps aux) regardless of platform. On Windows none of those
exist either, so blocking e.g. `type file | more` correctly stopped
the interactive command but then pointed the model at three more
commands cmd.exe doesn't have — directly undermining the guidance
this check exists to give. Reported in the wild (screenshot showing
`more` blocked with a "use cat, head, or tail -n N" suggestion on a
Windows session).

Adds an optional windowsSuggestion per program/segment, used in
place of the POSIX suggestion when goos == "windows" — `type` for
pagers, `tasklist` for process monitors, the read_file tool for
tail -f. Non-Windows suggestions are unchanged.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

This PR adds platform-aware remediation text to the interactive command blocker. interactiveProgram and interactiveSegments structs gain a windowsSuggestion field, populated for pagers, process monitors, and tail -f/--follow. DetectInteractiveCommand now selects the Windows-specific suggestion when running on Windows and an override exists, otherwise falling back to the existing POSIX suggestion. A new test validates Windows suggestions avoid POSIX-only commands while Linux behavior is unchanged.

Changes

Windows-specific interactive command suggestions

Layer / File(s) Summary
Interactive program/segment data with Windows overrides
internal/sandbox/safe_command.go
Adds windowsSuggestion field to interactiveProgram and interactiveSegments structs; populates Windows alternatives for less/more/most, top/htop/btop/btm, and tail -f/--follow entries.
Platform-aware suggestion selection in DetectInteractiveCommand
internal/sandbox/safe_command.go
Both the segment-match and program-match paths in DetectInteractiveCommand now override the suggestion with windowsSuggestion when goos == "windows" and a non-empty override exists.
Windows suggestion test coverage
internal/sandbox/safe_command_test.go
Adds a table-driven test confirming Windows suggestions mention appropriate alternatives and avoid POSIX-only commands, while Linux suggestions remain unchanged.

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

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant DetectInteractiveCommand
  participant interactivePrograms
  participant interactiveSegments

  Caller->>DetectInteractiveCommand: command string, goos
  DetectInteractiveCommand->>interactiveSegments: match segment
  alt segment matched
    interactiveSegments-->>DetectInteractiveCommand: suggestion, windowsSuggestion
  else program matched
    DetectInteractiveCommand->>interactivePrograms: match program
    interactivePrograms-->>DetectInteractiveCommand: suggestion, windowsSuggestion
  end
  DetectInteractiveCommand->>DetectInteractiveCommand: select windowsSuggestion if goos=="windows" and non-empty
  DetectInteractiveCommand-->>Caller: InteractiveCommandResult.Suggestion
Loading

Suggested reviewers: Vasanthdev2004

🚥 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 reflects the main change: Windows-specific suggestions for blocked interactive commands.
Linked Issues check ✅ Passed The changes add Windows-appropriate alternatives for pagers, process monitors, and tail-follow commands, matching the linked issue's goals.
Out of Scope Changes check ✅ Passed The diff stays focused on safe_command remediation text and its tests, with no clear unrelated feature additions.
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

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/sandbox/safe_command_test.go (1)

91-121: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Extend Windows suggestion test coverage.

The table exercises more, less, htop, and tail -f, but most, top, btop, and btm also gained new windowsSuggestion overrides in safe_command.go and aren't verified here.

✅ Suggested additional test cases
 		{command: "more file.txt", avoid: []string{"cat", "head", "tail"}, want: "type"},
 		{command: "less file.txt", avoid: []string{"cat", "head", "tail"}, want: "type"},
+		{command: "most file.txt", avoid: []string{"cat", "head", "tail"}, want: "type"},
 		{command: "htop", avoid: []string{"ps aux"}, want: "tasklist"},
+		{command: "top", avoid: []string{"ps aux"}, want: "tasklist"},
+		{command: "btop", avoid: []string{"ps aux"}, want: "tasklist"},
+		{command: "btm", avoid: []string{"ps aux"}, want: "tasklist"},
 		{command: "tail -f app.log", avoid: []string{"tail -n"}, want: "read_file"},
🤖 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/sandbox/safe_command_test.go` around lines 91 - 121,
`TestDetectInteractiveCommandSuggestsWindowsAlternativesOnWindows` does not
cover all Windows-specific overrides added in
`DetectInteractiveCommand`/`windowsSuggestion` in `safe_command.go`. Extend the
existing table-driven cases to include `most`, `top`, `btop`, and `btm`, and
assert their Windows suggestions mention the expected non-POSIX alternatives
while still keeping the Linux behavior check unchanged.
🤖 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/sandbox/safe_command_test.go`:
- Around line 91-121:
`TestDetectInteractiveCommandSuggestsWindowsAlternativesOnWindows` does not
cover all Windows-specific overrides added in
`DetectInteractiveCommand`/`windowsSuggestion` in `safe_command.go`. Extend the
existing table-driven cases to include `most`, `top`, `btop`, and `btm`, and
assert their Windows suggestions mention the expected non-POSIX alternatives
while still keeping the Linux behavior check unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 61a93c06-373a-472d-9371-1f558f7eaeac

📥 Commits

Reviewing files that changed from the base of the PR and between cdf9d83 and c82d4e3.

📒 Files selected for processing (2)
  • internal/sandbox/safe_command.go
  • internal/sandbox/safe_command_test.go

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.

interactive-command blocker suggests POSIX-only commands (cat/head/tail/ps aux) on Windows

1 participant