Xpersona
W

Windows Shell Encoding Doctor - Windows Shell编码修复工具

CLAWHUB · Unverified

诊断修复 Windows 下 PowerShell/cmd/Git Bash 的乱码、引号转义、路径空格与 CRLF 等问题。当用户说:PowerShell 里跑 bash 命令报错、中文乱码怎么修、JSON 怎么安全传给命令行,或类似 Windows 终端编码问题时,使用本技能。 Skill: Windows Shell Encoding Doctor - Windows Shell编码修复工具 Owner: jisuapi Summary: 诊断修复 Windows 下 PowerShell/cmd/Git Bash 的乱码、引号转义、路径空格与 CRLF 等问题。当用户说:PowerShell 里跑 bash 命令报错、中文乱码怎么修、JSON 怎么安全传给命令行,或类似 Windows 终端编码问题时,使用本技能。 Tags: latest:1.0.1 Version history: v1.0.1 | 2026-04-03T10:02:04.967Z | user Version 1.0.1 - Updated skill name and description for improved clarity and concise communication. - No changes to imp

62
Rank
84
Safety
1.1k
Downloads

About

What it does, and when to use it.

Capability contract not published. No trust telemetry is available yet. 1.1K downloads reported by the source. Last updated 10/11/2026.

Avoid when

  • Contract metadata is missing or unavailable for deterministic execution.

Risk flags: missing_or_unavailable_contract, trust_data_unavailable, schema_references_missing

Install and run

Setup complexity: low.

clawhub skill install s174fh1b14sn7vkvbqwsdn0xtd83gz5h:windows-shell-encoding-doctor
  1. Setup complexity is LOW. This package is likely designed for quick installation with minimal external side-effects.
  2. Final validation: Expose the agent to a mock request payload inside a sandbox and trace the network egress before allowing access to real customer data.

Contract: missing

curl -s "https://www.xpersona.co/api/v1/agents/clawhub-jisuapi-windows-shell-encoding-doctor/snapshot"

Run-check

$0.02 USD

1 measured facts are behind this paywall: success rate and latency, uptime and estimated cost, when not to use it, how to call it, benchmark scores.

Agents pay $0.02 in USDC. A card payment is $0.50, the smallest a card allows.

Documentation

CLAWHUB

39,099 characters of source documentation, loaded on request.

Extracted files

5 files captured from the source.

SKILL.md

---
name: "Windows Shell Encoding Doctor - Windows Shell编码修复工具"
description: 诊断修复 Windows 下 PowerShell/cmd/Git Bash 的乱码、引号转义、路径空格与 CRLF 等问题。当用户说:PowerShell 里跑 bash 命令报错、中文乱码怎么修、JSON 怎么安全传给命令行,或类似 Windows 终端编码问题时,使用本技能。
metadata: { "openclaw": { "emoji": "🪟", "requires": { "bins": [] } } }
---

# Windows Shell 与编码排障

在 **Windows** 上排查 **PowerShell / cmd / Git Bash** 下的命令失败、乱码与换行问题。先识别 **当前 shell**,再归类:**shell 混用**、**引号与转义**、**编码与 code page**、**路径与空格**、**CRLF/LF**。用 **可粘贴命令** 与 **references** 中的清单/剧本修复;写无 BOM UTF-8 见正文与 `encoding-checklist.md` 中的 `[System.IO.File]::WriteAllText` 示例。不要一上来盲改命令。

## 何时使用本技能

- **bash 命令在 PowerShell 里报错**(heredoc、`export`、`grep | xargs` 等)
- **PowerShell 语法误贴在 Git Bash / cmd** 里
- **Windows 下中文乱码**、`\uXXXX` 字面量、mojibake、控制台编码
- **PowerShell 里安全传 JSON**、多行 payload、stdin
- **路径明明存在却找不到**(未加引号、工作目录错、分隔符习惯)
- **脚本在 Windows 编辑后到 Linux 失效**(CRLF、BOM)
- **文档或 Agent 给的 Linux 一键命令**在本地 PowerShell 粘贴失败

典型问法示例:「这个 bash 命令在 PowerShell 为什么报错?」「同样命令在 Linux 能跑,Windows 不行。」

## 核心工作流

1. 先识别当前 shell。
   - PowerShell:优先给 PowerShell 原生写法。
   - cmd.exe:避免 PowerShell 专属语法,尽量保持简单。
   - Git Bash / MSYS / WSL:通常可以接受 Unix 风格语法。
2. 再看失败命令长什么样。
   - 如果在 PowerShell 里出现 `<<EOF`、`cat <<'EOF'`、`export`、`/dev/null`、`grep | xargs` 之类,优先怀疑是 bash 语法被直接贴进来了。
   - 如果在 bash 里出现 `$env:NAME=...`、`ConvertTo-Json`、`Out-File`、反引号转义,优先怀疑是 PowerShell 语法被贴错地方。
3. 归类错误。
   - 在 `<`、`|`、`&`、`@`、`{`、`}` 附近报解析错误:通常是 shell 不匹配或转义问题。
   - 中文乱码、`\uXXXX` 字面量、mojibake:通常是编码问题。
   - 文件明明存在却提示找不到:通常是路径没加引号、分隔符不对、或工作目录不对。
   - 脚本能跑但输出在别的工具里坏掉:通常是 CRLF/LF 或编码链路问题。
4. 用**最低风险**的方式重写。
   - 大段 JSON 不要硬塞 one-liner。
   - PowerShell 下优先用 hashtable + `ConvertTo-Json`,或先写临时文件再由工具读取。
   - 路径带空格时优先整体加引号。
5. 最后简短说明根因。
   - 说清楚:原命令错在哪、是哪个 shell 假设失效了、为什么新的写法更稳。

## 回答结构(输出风格)

修命令时,优先按这个结构回答:

1. **原因**:一句话说清楚。
2. **修好的命令**:可以直接粘贴运行。
3. **更稳的文件版写法**:如果涉及 JSON、多行文本、中文内容,优先给。
4. **Shell 说明**:只有在用户明显混用了 PowerShell / bash 时才补充。

保持实用,不要上来长篇讲 shell 理论。

## 常用修复模式

### JSON、多行文本与 stdin(PowerShell)

在 PowerShell 里优先用:

- Hashtable + `ConvertTo-Json -Depth N`
- 先写成 UTF-8 文件,再交给目标工具读取
- Here-string 承载可读性更好的多行文本

避免直接照搬 bash heredoc:

```bash
python - <<'PY'
...
PY
```

这不是合法的 PowerShell 语法。

PowerShell 里更稳的是:

```powershell
@'
print("hello")
'@ | python -
```

如果引号层次复杂,优先写临时文件。

### 中文乱码与编码(UTF-8 / GBK / BOM)

先检查:

- 终端编码
- 文件编码
- 是否把 Unicode 变成了字面量 `\uXXXX`
- 是否被旧版 PowerShell / 某些 cmdlet 写成了 UTF-16 或别的编码

优先做法:

- `Set-Content -Encoding UTF8`
- 需要控制 BOM 时,用 `[System.IO.File]::WriteAllText(..., [System.Text.UTF8Encoding]::new($false))`
- 中文内容、富文本、长 JSON 尽量走 UTF-8 文件,不要依赖控制台直接传参

详见 `references/encoding-checklist.md`。

### 路径、空格与工作目录

优先检查:

- 路径里有没有空格
- 分隔符是否被目标工具正确理解
- 当前工作目录是不是你以为的那个目录
- 是否错误依赖了 bash 的路径扩展习惯

优先给出带引号路径:

```powershell
python ".\scripts\tool.py"
Get-Content ".\data\input file.json"
```

### bash → PowerShell 翻译

当用户把 Unix 风格命令贴到 Windows shell:

- 直接翻译成 Power

_meta.json

{
  "ownerId": "kn7ex9mabfb47dvpgkmeypwqj9825yyz",
  "slug": "windows-shell-encoding-doctor",
  "version": "1.0.1",
  "publishedAt": 1775210524967
}

references/common-failures.md

# Common Windows shell failures

Use this file when the user pasted a failing command or error message and the likely cause is not obvious at first glance.

## 1) Bash heredoc pasted into PowerShell

### Symptom

- parser error near `<`
- `Missing file specification after redirection operator`
- multiline script never reaches Python / Node / curl

### Likely cause

Bash heredoc syntax like `<<'EOF'` or `<<'PY'` was pasted into PowerShell.

### Safer fix

- Replace with a PowerShell here-string piped into stdin, or
- write a temp file and run it

### Preferred response shape

- state that the command is bash syntax
- give a PowerShell-native equivalent
- prefer temp files if JSON or Chinese text is involved

## 2) `export VAR=value` used in PowerShell

### Symptom

- `export` not recognized
- environment variable appears unset in the child process

### Likely cause

Bash environment variable syntax used in PowerShell.

### Safer fix

```powershell
$env:VAR = 'value'
```

## 3) JSON body breaks only on Windows

### Symptom

- API rejects JSON
- quotes disappear or double-escape
- Chinese text becomes mojibake or literal `\\uXXXX`

### Likely cause

Inline JSON was over-escaped in the shell, or the shell / tool wrote text with the wrong encoding.

### Safer fix

- build JSON as a PowerShell object and `ConvertTo-Json`, or
- write a UTF-8 request file and submit `@file`

See `references/json-and-stdin-patterns.md`.

## 4) `Get-Content` pipeline corrupts structured payloads

### Symptom

- line breaks inserted unexpectedly
- hash/signature mismatch
- file content arrives fragmented downstream

### Likely cause

`Get-Content` without `-Raw` returns an array of lines instead of one whole string.

### Safer fix

```powershell
Get-Content .\payload.json -Raw
```

## 5) Path exists but command says file not found

### Symptom

- file is visible in Explorer / `dir`
- tool says file not found or reads only part of the path

### Likely cause

Unquoted path with spaces, wrong working directory, or tool-specific path parsing.

### Safer fix

- quote the full path
- check the current working directory
- prefer relative paths only when the current directory is explicit

## 6) Script works in Git Bash but not in PowerShell

### Symptom

- pipelines or redirection behave differently
- `/dev/null`, `&&`, `grep`, `xargs`, `sed -i`, or command substitution breaks

### Likely cause

The command depends on bash semantics or Unix tool behavior.

### Safer fix

Translate intent, not token-by-token syntax. See `references/powershell-vs-bash.md`.

## 7) Chinese displays as garbage but file is actually fine

### Symptom

- terminal output is garbled
- file content opens correctly in a UTF-8-aware editor

### Likely cause

Display-only console encoding mismatch.

### Safer fix

Say clearly that the underlying data may be intact. Distinguish display pro

references/encoding-checklist.md

# Encoding checklist for Windows shell problems

Use this file when output is garbled, Chinese text turns into mojibake, JSON contains literal `\\uXXXX`, or files look correct in one tool but broken in another.

## Fast triage

1. Check whether the corruption happened:
   - in the terminal
   - in a file written to disk
   - over HTTP payload transport
   - after another tool re-serialized the text
2. Check shell and host:
   - Windows PowerShell 5.x behaves differently from PowerShell 7+
   - old console hosts often show encoding issues more easily
3. Check file encoding explicitly.
4. Prefer moving rich text into UTF-8 files rather than inline command arguments.

## Common failure modes

### A. Bash-style command pasted into PowerShell

Symptoms:
- parser error near `<`
- weird tokenization around quotes
- command never reaches the target program correctly

Fix shell syntax first. Encoding may be a secondary issue.

### B. Unicode was JSON-escaped as literal text

Symptoms:
- server stores `\\u4e2d\\u6587` literally
- resulting page or document shows backslash-u sequences

Safer pattern:
- serialize with real UTF-8 bytes when supported
- avoid transport paths that double-escape JSON
- prefer request files for rich content

### C. File written with the wrong encoding

Prefer:

```powershell
Set-Content -Path .\out.txt -Value $text -Encoding UTF8
```

For BOM control:

```powershell
[System.IO.File]::WriteAllText(
  '.\\out.txt',
  $text,
  [System.Text.UTF8Encoding]::new($false)
)
```

### D. CRLF/LF mismatch

Symptoms:
- shell scripts fail oddly
- parsers complain about invisible characters
- line-based tools behave inconsistently across platforms

Check line endings and normalize when needed.

## Advice patterns

- Prefer UTF-8 file inputs over inline console arguments for large Chinese payloads.
- Prefer `Get-Content -Raw` when passing whole-file content through a pipeline.
- Say whether the issue is display-only or data corruption; these need different fixes.

references/json-and-stdin-patterns.md

# JSON and stdin patterns on Windows

Use this file when the user needs to send structured payloads, multiline text, code snippets, or Chinese content through PowerShell without fighting escaping.

## Preferred patterns

### Pattern 1: Build JSON as an object

Use when the payload is moderate in size and values are already available as variables.

```powershell
$body = @{
  title = '中文标题'
  tags = @('a', 'b')
  nested = @{ enabled = $true }
} | ConvertTo-Json -Depth 5
```

Then pass `$body` to the client in the safest supported way.

### Pattern 2: Write UTF-8 request file

Use when:
- the payload contains lots of quotes
- the payload contains Chinese text
- the target tool supports `@file`
- reproducibility matters

```powershell
$body = @{
  title = '中文标题'
  content = '<p>内容</p>'
} | ConvertTo-Json -Depth 10

$path = Join-Path (Get-Location) 'request.json'
[System.IO.File]::WriteAllText($path, $body, [System.Text.UTF8Encoding]::new($false))
```

Then submit `@request.json` if the target tool supports it.

### Pattern 3: Pipe here-string into stdin

Use for short scripts or text blocks.

```powershell
@'
print("hello")
'@ | python -
```

If the content is long or contains multiple layers of quoting, prefer a file.

## Anti-patterns

- giant inline JSON one-liners with many escaped quotes
- bash heredocs pasted directly into PowerShell
- relying on terminal encoding for rich Chinese payloads
- using `Get-Content` without `-Raw` for whole-file transport

## Rule of thumb

If you see JSON + Chinese + PowerShell in the same command, strongly consider writing a UTF-8 file first.

Sponsored

Ads related to Windows Shell Encoding Doctor - Windows Shell编码修复工具 and adjacent AI workflows.