feat: add OS-aware command transformation for cross-platform shell support#16573
Closed
jabing wants to merge 8 commits intoanomalyco:devfrom
Closed
feat: add OS-aware command transformation for cross-platform shell support#16573jabing wants to merge 8 commits intoanomalyco:devfrom
jabing wants to merge 8 commits intoanomalyco:devfrom
Conversation
… and shell type detection
…nd transformation
Contributor
|
This PR doesn't fully meet our contributing guidelines and PR template. What needs to be fixed:
Please edit this PR description to address the above within 2 hours, or it will be automatically closed. If you believe this was flagged incorrectly, please let a maintainer know. |
Contributor
|
This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window. Feel free to open a new pull request that follows our guidelines. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #
Context: OpenCode currently only supports Unix-style bash commands. When AI agents try to run commands like
export VAR=valueorls -laon Windows, they fail because these commands are not available in PowerShell or CMD.Type of change
What does this PR do?
Problem: OpenCode AI agents generate Unix-style commands (like
export,ls,rm), but these fail on Windows PowerShell/CMD, making the tool unusable for Windows users.Solution: Add OS-aware command transformation that automatically converts Unix commands to PowerShell/CMD equivalents when running on Windows.
Changes made:
packages/opencode/src/shell/command-transformer.ts(319 lines)CommandTransformerclass with pattern-based command mappinggetShellType(): Detects shell type (bash, PowerShell, CMD)transformCommand(): Converts 20+ Unix commandsexport,ls,rm,mkdir,touch,cat,cp,mv,grep,which,pwd,echo,seqpackages/opencode/src/shell/shell.tstransformCommand()functionpackages/opencode/src/tool/bash.tsShell.transformCommand(params.command, shell)on line 172packages/opencode/test/tool/bash.test.tsbeforeAll/afterAllimports (fixes typecheck error)seqcommand)custom-elements.d.tsinenterprisepackagecustom-elements.d.tsinapppackageHow it works:
On Windows:
export VAR=valuetransformCommand()detects the shell (PowerShell/CMD)$env:VAR=value(PowerShell) orset VAR=value(CMD)On Unix/Linux/macOS:
How did you verify your code works?
Unit tests pass:
bun turbo test --filter=opencodesucceedsManually tested commands:
Windows PowerShell: