Repository navigation
Windows shell 执行/退出码修复 + bash→shell 改名 + PowerShell 编码/白名单 - #4
Merged
Merged
Conversation
Rename the "bash" tool to "shell" across all layers (agent tool name,
Rust symbols, gRPC bash/abort_bash commands, proto, TUI/CLI clients,
GUI tool-kind matching + i18n), so the model's strongest prior — the
tool name — no longer implies bash semantics on a platform where the
command is actually interpreted by PowerShell. Literal bash-binary
references (Unix `bash -c`, Seatbelt wrapper) are preserved.
Fix Windows execution/capture (P0): add sandbox::shell_invocation as
the single source of truth for how a command runs per platform. The
PowerShell wrapper now uses a `& { … }` script block (multi-statement
commands parse), clears $LASTEXITCODE before the command (kills the
chcp-polluted false [exit: 0]), falls back to $Error for command-not-
found / cmdlet failures that never set $LASTEXITCODE, sets UTF-8
console output encoding, and captures PowerShell's own stderr so parse
errors aren't silently dropped. merged_cmd no longer wraps a bash-ism
subshell on Windows.
Align the cognition layer (P1): the shell tool description and os_hint
now state the actual interpreter (PowerShell 5.1 on Windows: use `;`
not `&&`/`||`, $env:VAR not %VAR%), and remove the false "cmd syntax
is acceptable" claim.
Also fix three pre-existing bugs surfaced along the way: GUI exit-code
parsers (agentActivity.ts, persist.rs, store/runs.rs) still read the
old "[exit code: N]" prefix instead of the current "[exit: N]" footer,
so failure detection was dead; execute_shell hardcoded `bash -c`; and
several docs/comments claimed Windows runs via `cmd /c`.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
…-write prompt P2 hardening of the Windows shell path: - Prefer pwsh (PowerShell 7+) when on PATH, else Windows PowerShell 5.1. pwsh supports && / ||, defaults to UTF-8, and parses -EncodedCommand identically. Resolved once via a side-effect-free PATH scan (no spawn). - Deliver the wrapper script via -EncodedCommand (base64/UTF-16LE) instead of -Command, eliminating the fragile Rust→CreateProcess→PowerShell quote re-parsing. Wrapper logic (script block, $LASTEXITCODE/$Error capture, UTF-8) is unchanged and split into a testable windows_wrapper_script. - The cognition layer now tracks the resolved shell at runtime: sandbox::shell_display_name / shell_supports_chain_operators feed os_hint, so the chaining guidance (`;` only vs `;`/`&&`/`||`) matches the actual interpreter. The shell tool description is version-neutral to avoid contradicting it. Prompt review — platform-split the one remaining bash-flavored instruction: the "don't write files via shell redirection" guideline named tee/heredocs/ `cat > file`, which a PowerShell model can't map to Out-File/Set-Content. It now lists the redirection forms the host shell actually has. All other model-facing command examples were already platform-split or neutral. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…llow list
On Windows the model generates PowerShell, so the read-only auto-allow
whitelist (grep/ls/cat/git…) never matched the cmdlets it actually
emits (Get-ChildItem, Get-Content, Select-String, …), and every
read-only command fell through to a prompt on the Manual tier.
- Add WINDOWS_READONLY_PROGRAMS: read-only cmdlets and their built-in
aliases (gci/dir, gc, sls, measure, findstr, …). Deliberately excludes
writers (Set-/Add-/New-/Remove-/Out-File) and arbitrary-exec cmdlets
(Invoke-/Start-/ForEach-Object/Where-Object — the latter also need a
`{ … }` block, already rejected by the operator guard).
- Normalize the program basename cross-platform, matching the existing
is_soft_fail_command precedent: split on both `/` and `\`, strip a
`.exe` suffix, and lower-case (PowerShell resolves names case-
insensitively). So `C:\Windows\System32\findstr.exe` and
`get-content` both resolve correctly.
The operator guard (`{`, `` ` ``, `;`, `&`, `$(`, redirects) already
blocks PowerShell script blocks and subexpressions, so this only widens
recognition of bare read-only cmdlets — the conservative posture holds.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
…ll 5.1 The prior wrapper set `[Console]::OutputEncoding = [Text.Encoding]::UTF8`, which left two PowerShell 5.1 encoding gaps: - `[Text.Encoding]::UTF8` carries a BOM. On a redirected stdout (our captured pipe) PS 5.1 prepends it as a stray `EF BB BF`, which our `from_utf8_lossy` surfaces as a leading U+FEFF on every command's output. Switch all encodings to a BOM-less `UTF8Encoding($false)`. - `$OutputEncoding` (encoding for strings piped INTO a native command's stdin) defaults to ASCII in 5.1, mangling non-ASCII to `?`. Set it to UTF-8 too, so `"中文" | some.exe` round-trips. chcp 65001 (asks native children to emit UTF-8) is retained. Native tools that ignore the code page and hard-code OEM/ANSI output remain unfixable at this layer — those bytes degrade to replacement chars via from_utf8_lossy rather than corrupting the capture. pwsh 7 already defaults to BOM-less UTF-8, so these assignments are a no-op there. Co-Authored-By: Claude Opus 4.8 <[email protected]>
… failure" bug Direct-from-session regression coverage for nonZeroExitCode: a failed shell command (`future: command not found`, exit 127) rendered as "completed" because the deployed parser matched a "[exit code: N]" prefix while the agent writes an "[exit: N]" footer on the last line. The added cases pin: the exact capture with leading output + a blank line before the footer; the Windows form of the same failure (PowerShell reports command-not-found as exit 1, not 127 — the parser keys on any non-zero so both platforms are caught); rejection of the old prefix format; and that the soft-fail exemption still keys exit 1 to bare grep/findstr (Windows no-match) while a real command-not-found stays failed. Co-Authored-By: Claude Opus 4.8 <[email protected]>
huichen
pushed a commit
that referenced
this pull request
Jul 16, 2026
…handling, and more Bug fixes: - Navigation observer: poll 500ms instead of 15s for non-navigating actions. One fix resolves click file:// timeout, selector click timeout, and press 15s delay (bugs #1, #2, #3). - Snapshot: collect text content from h1-h6, p, li, td, th, dt, dd, label, span, div, pre, code, blockquote (bug #4). - CdpError: changed from plain object to class extends Error so it serialises as a readable message instead of '[object Object]' (bug #8). Improvements: - Snapshot: textarea/input name priority aria-label > placeholder > associated label > name > value[:30] (bug #10). - Tabs: all actions now return { tabs: [...], tabCount: N } for consistent output (bug #6). - Start: when endpoint already reachable, returns already_running with note instead of silently switching (bug #7). - Type: returns both ref (typed) and resolved selector (bug #9). - Scroll: new scroll command with direction/amount/ref arguments (bug #11). Defense in depth: - tools.ts catch block: extract .message from non-Error objects as fallback.
huichen
pushed a commit
that referenced
this pull request
Jul 16, 2026
…5760d Windows shell 执行/退出码修复 + bash→shell 改名 + PowerShell 编码/白名单
huichen
pushed a commit
that referenced
this pull request
Jul 16, 2026
…handling, and more Bug fixes: - Navigation observer: poll 500ms instead of 15s for non-navigating actions. One fix resolves click file:// timeout, selector click timeout, and press 15s delay (bugs #1, #2, #3). - Snapshot: collect text content from h1-h6, p, li, td, th, dt, dd, label, span, div, pre, code, blockquote (bug #4). - CdpError: changed from plain object to class extends Error so it serialises as a readable message instead of '[object Object]' (bug #8). Improvements: - Snapshot: textarea/input name priority aria-label > placeholder > associated label > name > value[:30] (bug #10). - Tabs: all actions now return { tabs: [...], tabCount: N } for consistent output (bug #6). - Start: when endpoint already reachable, returns already_running with note instead of silently switching (bug #7). - Type: returns both ref (typed) and resolved selector (bug #9). - Scroll: new scroll command with direction/amount/ref arguments (bug #11). Defense in depth: - tools.ts catch block: extract .message from non-Error objects as fallback.
huichen
pushed a commit
that referenced
this pull request
Jul 16, 2026
…5760d Windows shell 执行/退出码修复 + bash→shell 改名 + PowerShell 编码/白名单
huichen
pushed a commit
that referenced
this pull request
Jul 16, 2026
…handling, and more Bug fixes: - Navigation observer: poll 500ms instead of 15s for non-navigating actions. One fix resolves click file:// timeout, selector click timeout, and press 15s delay (bugs #1, #2, #3). - Snapshot: collect text content from h1-h6, p, li, td, th, dt, dd, label, span, div, pre, code, blockquote (bug #4). - CdpError: changed from plain object to class extends Error so it serialises as a readable message instead of '[object Object]' (bug #8). Improvements: - Snapshot: textarea/input name priority aria-label > placeholder > associated label > name > value[:30] (bug #10). - Tabs: all actions now return { tabs: [...], tabCount: N } for consistent output (bug #6). - Start: when endpoint already reachable, returns already_running with note instead of silently switching (bug #7). - Type: returns both ref (typed) and resolved selector (bug #9). - Scroll: new scroll command with direction/amount/ref arguments (bug #11). Defense in depth: - tools.ts catch block: extract .message from non-Error objects as fallback.
huichen
pushed a commit
that referenced
this pull request
Jul 16, 2026
…5760d Windows shell 执行/退出码修复 + bash→shell 改名 + PowerShell 编码/白名单
huichen
pushed a commit
that referenced
this pull request
Jul 16, 2026
…handling, and more Bug fixes: - Navigation observer: poll 500ms instead of 15s for non-navigating actions. One fix resolves click file:// timeout, selector click timeout, and press 15s delay (bugs #1, #2, #3). - Snapshot: collect text content from h1-h6, p, li, td, th, dt, dd, label, span, div, pre, code, blockquote (bug #4). - CdpError: changed from plain object to class extends Error so it serialises as a readable message instead of '[object Object]' (bug #8). Improvements: - Snapshot: textarea/input name priority aria-label > placeholder > associated label > name > value[:30] (bug #10). - Tabs: all actions now return { tabs: [...], tabCount: N } for consistent output (bug #6). - Start: when endpoint already reachable, returns already_running with note instead of silently switching (bug #7). - Type: returns both ref (typed) and resolved selector (bug #9). - Scroll: new scroll command with direction/amount/ref arguments (bug #11). Defense in depth: - tools.ts catch block: extract .message from non-Error objects as fallback.
huichen
pushed a commit
that referenced
this pull request
Jul 16, 2026
…5760d Windows shell 执行/退出码修复 + bash→shell 改名 + PowerShell 编码/白名单
huichen
pushed a commit
that referenced
this pull request
Jul 16, 2026
…handling, and more Bug fixes: - Navigation observer: poll 500ms instead of 15s for non-navigating actions. One fix resolves click file:// timeout, selector click timeout, and press 15s delay (bugs #1, #2, #3). - Snapshot: collect text content from h1-h6, p, li, td, th, dt, dd, label, span, div, pre, code, blockquote (bug #4). - CdpError: changed from plain object to class extends Error so it serialises as a readable message instead of '[object Object]' (bug #8). Improvements: - Snapshot: textarea/input name priority aria-label > placeholder > associated label > name > value[:30] (bug #10). - Tabs: all actions now return { tabs: [...], tabCount: N } for consistent output (bug #6). - Start: when endpoint already reachable, returns already_running with note instead of silently switching (bug #7). - Type: returns both ref (typed) and resolved selector (bug #9). - Scroll: new scroll command with direction/amount/ref arguments (bug #11). Defense in depth: - tools.ts catch block: extract .message from non-Error objects as fallback.
huichen
pushed a commit
that referenced
this pull request
Jul 16, 2026
…5760d Windows shell 执行/退出码修复 + bash→shell 改名 + PowerShell 编码/白名单
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.
背景
起于 Windows 下 shell 工具"明明失败却显示已完成"、退出码恒为 0 的问题;调查后扩展为一组 Windows 平台正确性修复 + 工具改名。
改动
sandbox::shell_invocation作为平台 shell 单一事实来源。PowerShell wrapper 用& { }脚本块(支持多语句)、执行前清$LASTEXITCODE(消除 chcp 污染出的假 exit 0)、$Error兜底命令未找到/cmdlet 失败、捕获 PowerShell 自身 stderr。&&/||,5.1 只准;;$env:VAR而非%VAR%);平台化文件写入禁令示例。UTF8Encoding($false),并设$OutputEncoding(5.1 默认 ASCII)修复中文管道乱码。\/.exe/大小写)。[exit: N]末行 footer,但 GUI 仍找[exit code: N]开头前缀 → 失败检测失效(即本次调查的直接根因)。含真实数据回归测试。验证
🤖 Generated with Claude Code