Skip to content

fix/windows powershell utf8 - #49012

Closed
ysmla wants to merge 1 commit into
anomalyco:devfrom
ysmla:fix/windows-powershell-utf8
Closed

ysmla wants to merge 1 commit into
anomalyco:devfrom
ysmla:fix/windows-powershell-utf8

Conversation

@ysmla

@ysmla ysmla commented Sep 14, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

修复opencode模型使用shell时的中文乱码问题
Closes #30205#30055
If you paste a large clearly AI generated description here your PR may be IGNORED or CLOSED!

How did you verify your code works?

Opencode web中,模型使用shell输出中文的时候产生乱码如图:
origin
发现PowerShell 5.1 管道输出用系统 OEM 代码页(CP936)编码、opencode 按 UTF-8 解码导致乱码;修复是在 Windows 上给 PowerShell 命令注入 [Console]::OutputEncoding UTF-8 前导语句,覆盖 shell 工具和 ! 命令两条路径,权限检查和界面显示不受影响,修复后如图:
fixed

Screenshots / recordings

No
If this is a UI change, please include a screenshot or recording.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

If you do not follow this template your PR will be automatically rejected.

@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Sep 14, 2026
@github-actions

github-actions Bot commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • No issue referenced. Please add Closes #<number> linking to the relevant issue.

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.

@github-actions

Copy link
Copy Markdown
Contributor

Hey! Your PR title Fix/windows powershell utf8 doesn't follow conventional commit format.

Please update it to start with one of:

  • feat: or feat(scope): new feature
  • fix: or fix(scope): bug fix
  • docs: or docs(scope): documentation changes
  • chore: or chore(scope): maintenance tasks
  • refactor: or refactor(scope): code refactoring
  • test: or test(scope): adding or updating tests

Where scope is the package name (e.g., app, desktop, opencode).

See CONTRIBUTING.md for details.

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Potential Duplicate PRs Found

This PR appears to be directly related to previous Windows PowerShell UTF-8 encoding fixes:

  1. fix(core): force UTF-8 for Windows shells #36608 - fix(core): force UTF-8 for Windows shells
    fix(core): force UTF-8 for Windows shells #36608

  2. fix: set default UTF-8 encoding for spawned subprocess on Windows #31658 - fix: set default UTF-8 encoding for spawned subprocess on Windows
    fix: set default UTF-8 encoding for spawned subprocess on Windows #31658

Why they're related: All three PRs address the same core issue—fixing UTF-8 encoding problems for PowerShell output on Windows. PR #49012 mentions it's related to issues #30205 and #30055, and appears to implement a similar fix by injecting [Console]::OutputEncoding = UTF-8 into PowerShell commands.

You should verify whether these previous PRs already resolved the issue or if this is addressing a gap they missed.

@ysmla ysmla changed the title Fix/windows powershell utf8 fix/windows powershell utf8 Sep 14, 2026
Windows PowerShell 5.1 encodes its stdout with the legacy OEM code page
(e.g. CP936 on zh-CN systems) when output is redirected, while opencode
decodes process output as UTF-8, producing mojibake for any non-ASCII
shell output.

Prepend a [Console]::OutputEncoding/$OutputEncoding UTF-8 preamble to
PowerShell commands spawned by the shell tool and bang commands on
Windows. Permission scanning and command titles still use the original
command text since the preamble is injected at spawn time.

Corresponds to upstream discussion in anomalyco#23636.
@ysmla
ysmla force-pushed the fix/windows-powershell-utf8 branch from 8aef152 to 042190d Compare September 14, 2026 16:49
@github-actions

Copy link
Copy Markdown
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.

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Sep 14, 2026
@github-actions github-actions Bot closed this Sep 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

在 Window 环境下 AI 使用 PowerShell 修改文件添加中文内容会有乱码出现

1 participant