Repository navigation
[Feat] Tell the model which shell syntax execute_command uses (cmd.exe / PowerShell) #2115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
edelauna
merged 5 commits into
Zoo-Code-Org:main
from
PierrunoYT:fix/windows-shell-prompt
Nov 19, 2026
+116
−1
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
cc9bb5c
feat(prompt): state the command syntax for cmd.exe and PowerShell
PierrunoYT 61cf615
fix(prompt): correct PowerShell status guidance and assert dialect sy…
PierrunoYT 4f0b824
fix(prompt): qualify cmd.exe exit-code guidance and cover bare shell …
PierrunoYT 3b1a015
Merge remote-tracking branch 'upstream/main' into fix/windows-shell-p…
PierrunoYT 61e4821
test(prompt): assert cmd.exe ERRORLEVEL expansion and same-line succe…
PierrunoYT File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| import { describeShellDialect } from "../shellDialect" | ||
|
|
||
| describe("describeShellDialect", () => { | ||
| const cmdSyntax = ["`&`", "`&&`", "`%VAR%`", "`set X=Y`", "`%ERRORLEVEL%`", "`!ERRORLEVEL!`"] | ||
| const powershellSyntax = ["`;`", "`$env:VAR`", "`$?`", "`$LASTEXITCODE`"] | ||
|
|
||
| it.each([ | ||
| { shell: "C:\\Windows\\System32\\cmd.exe", expected: "cmd.exe", syntax: cmdSyntax }, | ||
| { shell: "C:\\Windows\\System32\\CMD.EXE", expected: "cmd.exe", syntax: cmdSyntax }, | ||
| { shell: "cmd", expected: "cmd.exe", syntax: cmdSyntax }, | ||
| { shell: "C:\\Program Files\\PowerShell\\7\\pwsh.exe", expected: "PowerShell", syntax: powershellSyntax }, | ||
| { | ||
| shell: "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", | ||
| expected: "PowerShell", | ||
| syntax: powershellSyntax, | ||
| }, | ||
| { shell: "powershell", expected: "PowerShell", syntax: powershellSyntax }, | ||
| { shell: "pwsh", expected: "PowerShell", syntax: powershellSyntax }, | ||
| ])("names the dialect and its syntax for $shell", ({ shell, expected, syntax }) => { | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| const description = describeShellDialect(shell) | ||
|
|
||
| expect(description).toContain(expected) | ||
| for (const token of syntax) { | ||
| expect(description).toContain(token) | ||
| } | ||
| }) | ||
|
|
||
| it("tells PowerShell users that a failed cmdlet does not change $LASTEXITCODE", () => { | ||
| expect(describeShellDialect("pwsh.exe")).toContain("does not change when a cmdlet fails") | ||
| }) | ||
|
|
||
| it("warns that ';' does not chain commands in cmd.exe", () => { | ||
| expect(describeShellDialect("C:\\Windows\\System32\\cmd.exe")).toContain("`;` is not a separator") | ||
| }) | ||
|
|
||
| it("tells cmd.exe users that %ERRORLEVEL% expands before a chained line runs", () => { | ||
| const description = describeShellDialect("C:\\Windows\\System32\\cmd.exe") | ||
|
|
||
| expect(description).toContain("`%ERRORLEVEL%` expands before a chained line runs") | ||
| expect(description).toContain("use `&&` or `||` for same-line success checks") | ||
| expect(description).toContain("enable delayed expansion and use `!ERRORLEVEL!`") | ||
| }) | ||
|
|
||
| it.each(["/bin/bash", "/bin/zsh", "C:\\Program Files\\Git\\bin\\bash.exe", "C:\\Windows\\System32\\wsl.exe"])( | ||
| "adds nothing for POSIX shell %s", | ||
| (shell) => { | ||
| expect(describeShellDialect(shell)).toBeUndefined() | ||
| }, | ||
| ) | ||
| }) | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| /** | ||
| * Describes the command syntax of Windows-native shells for the system prompt. | ||
| * | ||
| * Rules and habits written for bash silently do the wrong thing under these shells | ||
| * (e.g. `;` is not a command separator in cmd.exe), so the model is told which | ||
| * dialect it is writing for. Returns undefined for POSIX shells, where the shell | ||
| * path already names the dialect. | ||
| */ | ||
| export function describeShellDialect(shellPath: string): string | undefined { | ||
| // path.basename follows the host platform; split on both separators so Windows paths work anywhere. | ||
| const name = (shellPath.split(/[\\/]/).pop() ?? "").toLowerCase() | ||
|
Check warning on line 11 in src/utils/shellDialect.ts
|
||
|
|
||
| if (name === "cmd.exe" || name === "cmd") { | ||
| return ( | ||
| "Commands run through Windows cmd.exe, not bash. Use cmd syntax: `&` or `&&` to chain commands " + | ||
| "(`;` is not a separator), `%VAR%` for variables, `set X=Y`, and `%ERRORLEVEL%` for exit codes " + | ||
| "(`%ERRORLEVEL%` expands before a chained line runs, so use `&&` or `||` for same-line success checks; " + | ||
| "enable delayed expansion and use `!ERRORLEVEL!` when the numeric result is needed after a command), " + | ||
| "and `dir`, `type`, `findstr`. POSIX tools may be missing or shadowed by other binaries on PATH." | ||
| ) | ||
| } | ||
|
|
||
| if (name === "powershell.exe" || name === "pwsh.exe" || name === "powershell" || name === "pwsh") { | ||
| return ( | ||
| "Commands run through PowerShell, not bash. Use PowerShell syntax: `;` to chain commands, " + | ||
| "`$env:VAR` for environment variables, `$?` for whether the last command succeeded " + | ||
| "(`$LASTEXITCODE` only holds the exit code of native programs and does not change when a cmdlet fails), " + | ||
| "and cmdlets such as `Get-ChildItem` and `Select-String`." | ||
| ) | ||
| } | ||
|
|
||
| return undefined | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.