skills/fix-file-encoding/SKILL.md
偵測並修正檔案亂碼問題,依副檔名轉換至正確目標編碼(Big5/ANSI → UTF-8 系列)。
npx skillsauth add CloudyWing/ai-dotfiles fix-file-encodingInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
/fix-file-encoding [檔案路徑或 glob 模式]
若未傳入路徑,詢問使用者要處理哪些檔案。
列出符合條件的檔案清單,讓使用者確認範圍後再繼續。
依副檔名與專案框架決定目標編碼,規則同 CLAUDE.md §2 Encoding Strategy:
| 檔案類型 | 目標編碼 |
| --- | --- |
| *.ps1 | UTF-8 with BOM |
| *.csv | UTF-8 with BOM |
| .NET Framework 的 *.cs, *.vb, *.aspx, *.master | UTF-8 with BOM |
| net4x 框架的 *.cshtml | UTF-8 with BOM |
| 其他所有檔案 | UTF-8 無 BOM |
判斷 *.cshtml 的框架版本:讀取同專案的 .csproj,檢查 <TargetFramework> 欄位。net4x 為 .NET Framework,其餘(net5+、netcoreapp)為 .NET Core/ASP.NET Core。
使用 PowerShell 偵測檔案的實際編碼:
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
$bytes = [System.IO.File]::ReadAllBytes("$FilePath")
if ($bytes.Length -ge 3 -and $bytes[0] -eq 0xEF -and $bytes[1] -eq 0xBB -and $bytes[2] -eq 0xBF) {
"UTF-8 with BOM"
} elseif ($bytes.Length -ge 2 -and $bytes[0] -eq 0xFF -and $bytes[1] -eq 0xFE) {
"UTF-16 LE"
} else {
"Unknown (likely ANSI/Big5)"
}
若偵測為「Unknown」,嘗試以 Big5 解碼,若解碼後中文可讀,則來源編碼視為 Big5。
若來源編碼與目標編碼相同,告知使用者無需轉換並跳過。
執行轉換(PowerShell):
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
$content = [System.IO.File]::ReadAllText("$FilePath", [System.Text.Encoding]::GetEncoding(950)) # Big5
# 目標為 UTF-8 無 BOM
[System.IO.File]::WriteAllText("$OutputPath", $content, [System.Text.Encoding]::UTF8)
# 目標為 UTF-8 with BOM
[System.IO.File]::WriteAllText("$OutputPath", $content, [System.Text.Encoding]::UTF8) # 再手動加 BOM
轉換後重新以 UTF-8 讀取,確認中文內容可正常顯示,輸出前幾行供使用者確認。
## 編碼轉換摘要
| 檔案 | 來源編碼 | 目標編碼 | 狀態 |
| --- | --- | --- | --- |
| path/to/file.cs | Big5 | UTF-8 with BOM | ✅ 完成 |
| path/to/script.ps1 | UTF-8 無 BOM | UTF-8 with BOM | ✅ 完成 |
| path/to/other.cs | UTF-8 with BOM | UTF-8 with BOM | ⏭️ 略過(已正確) |
tools
產生或補齊 .gitattributes,統一行尾處理、二進位識別與 lock files 標記,保留既有自訂偏好。
development
產生或補齊前端 Lint 設定(Prettier + ESLint Flat Config),統一格式化與程式碼品質規則,保留既有自訂偏好。
testing
依據事實校閱報告修改技術文件:以事實層為不可違反的約束,由改檔者負責表達層的措辭與行文連貫。Use when the user asks to apply fact-check results to a document, or to edit a document based on a previously produced fact-check-report.md.
data-ai
多份資料檔整合流程。當需要將兩份以上的資料檔(如 JSON、CSV)合併、補齊闕漏欄位或去重成單一檔案時使用。以 dry-run、筆數核對與抽樣比對降低整合錯誤。