Encoding Guardのロゴ

Encoding Guard

コミュニティ
cropflre
encoding-guard

Prevent garbled text (乱码) when editing code and comments. Use this skill whenever reading, writing, or modifying files to ensure proper UTF-8 encoding handling. Activates on any file edit operation, especially when working with Chinese characters, emoji, or non-ASCII content.

Add to TypingMind

概要

公開者cropflre
リポジトリnowen-note
スキル名encoding-guard
スター
553
フォーク
86
同梱ファイル
1
ライセンスGPL-3.0
リンク
  • Markdown形式の指示

    モデルが必要に応じて読み込むSKILL.mdファイルです。関連するリクエストがあったときだけトークンを消費します。

  • どのLLMでも利用可能

    AIスキルはプロバイダー固有のコードではなく、通常のMarkdownなので、GPT、Claude、Gemini、Grok、ローカルモデルで利用できます。

  • 1個の同梱ファイル

    モデルが作業中に読み取れるスクリプト、テンプレート、参考資料です。ファイルは読み取り専用で、実行されることはありません。

  • オープンソース

    cropflreがGitHubで公開しています。インストールする前にソースを確認してください。

インストール

AIスキル「Encoding Guard」をTypingMindにインストールすれば、どのLLMでも利用できます。SKILL.mdを読み取れる別のAIエージェントに追加することもできます。

1

TypingMindにインストール

TypingMindはGitHubフォルダから直接スキルをインストールします。SKILL.mdを読み取り、リソースファイルをまとめてローカルに保存します。

  1. アプリを開き、「プラグイン」→「スキル」に移動します。
  2. 「GitHubからインストール」を選択します。
  3. 以下のスキルフォルダのURLを貼り付けて確定します。
    https://github.com/cropflre/nowen-note/tree/main/.claude/skills/encoding-guard
  4. スキルを利用したいチャットごとに、そのスキルを有効にしてください。
「プラグイン」→「スキル」→「スキルを追加」→「GitHubのURLから」を選択し、フォルダのURLを貼り付けて「続行」を押します。
2

別のAIエージェントにインストール

Agent Skills形式を読み取れるAIエージェントなら、このスキルを利用できます。フォルダをそのAIエージェントのスキルディレクトリにコピーしてください。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/cropflre/nowen-note.git /tmp/nowen-note
mkdir -p .claude/skills
cp -r /tmp/nowen-note/.claude/skills/encoding-guard .claude/skills/encoding-guard
コピー後、新しいスキルを読み込むためにClaude Codeを再起動してください。

TypingMindで使用

TypingMindのチャットでEncoding Guardを有効にするだけで、あとはモデルが対応します。名前と説明がシステムプロンプトに含まれ、関連するリクエストがあると、モデルが指示の全文を自動で読み込みます。手動で呼び出す必要はなく、実際に使用されるまでトークンを消費しません。

関連するリクエストがあるとすぐに、モデルが自動的にEncoding Guardを読み込みます。

どのAIモデルでも利用可能

AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、Encoding Guardは作成時に想定されたモデルに縛られません。TypingMindに一度インストールすれば、ご自身のAPIキーを使って、GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama、またはご自身で実行するローカルモデルで利用できます。

  • 必要なときだけ読み込み

    システムプロンプトには名前と説明だけが含まれます。関連するリクエストが初めてあったときに指示を取得するため、スキルを使わない間は指示の読み込みにトークンを消費しません。

  • チャットの途中でモデルを切り替え

    スキルはコードではなく指示なので、モデルを切り替えてもそのまま使えます。次のモデルも同じSKILL.mdを読み込みます。

スキルの指示

モデルが読み込むSKILL.mdの内容です。スキルはモデルが従う指示なので、インストールする前に確認してください。

Encoding Guard

Ensures all file operations use proper UTF-8 encoding to prevent garbled text (乱码).

Core Principles

  1. Always use UTF-8 — Read and write files with explicit UTF-8 encoding
  2. Validate before write — Check that content is valid UTF-8 before saving
  3. Preserve BOM awareness — Detect and handle BOM (Byte Order Mark) when present
  4. Handle mixed encoding — Convert legacy encodings (GBK, GB2312, Big5) to UTF-8

When Reading Files

bash
# Always specify encoding when reading
cat -n file.tsx  # Use Read tool which handles encoding

# If you suspect encoding issues, check with:
file -I file.tsx  # Shows charset
hexdump -C file.tsx | head -5  # Inspect raw bytes

When Writing Files

bash
# Ensure locale supports UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8

# When using Edit tool, the content is already validated
# When using Write tool, ensure content is proper UTF-8

Detection Patterns

Watch for these signs of encoding problems:

  1. Mojibake characters: é, è, ü (UTF-8 read as Latin-1)
  2. Chinese garbled: 锟斤拷, 烫烫烫, 屯屯屯 (GBK/UTF-8 mismatch)
  3. Replacement character: � (U+FFFD) — missing or invalid bytes
  4. Question marks: ??? where Chinese should be

Fix Strategies

Strategy 1: Re-read with correct encoding

If a file shows garbled text:

bash
# Check current encoding
file -I problematic.tsx

# If it's GBK, convert to UTF-8
iconv -f GBK -t UTF-8 problematic.tsx > fixed.tsx
mv fixed.tsx problematic.tsx

Strategy 2: Use Read tool with encoding awareness

The Read tool automatically handles encoding. If you see garbled output:

  1. Stop and check the file's actual encoding
  2. Convert if needed before editing
  3. Then proceed with normal Read/Edit operations

Strategy 3: Validate after write

After any Edit or Write operation:

bash
# Quick validation
python3 -c "
with open('file.tsx', 'r', encoding='utf-8') as f:
    content = f.read()
    print(f'Valid UTF-8: {len(content)} chars')
"

Common Scenarios

Scenario 1: Editing TypeScript/JSX with Chinese comments

typescript
// ✅ Correct: UTF-8 encoded comment
// 这是一个中文注释

// ❌ Wrong: Encoding mismatch causes garbled
// 杩欐槸涓€涓�腑鏂囨敞閲�

Action: Always use UTF-8 locale. Set in shell:

bash
export LANG=en_US.UTF-8

Scenario 2: Mixed encoding in project

If some files are GBK and others UTF-8:

bash
# Find all non-UTF-8 files
find . -name "*.tsx" -exec file -I {} \; | grep -v utf-8

# Batch convert
for f in $(find . -name "*.tsx" -exec file -I {} \; | grep gb2312 | cut -d: -f1); do
    iconv -f GBK -t UTF-8 "$f" > "$f.utf8"
    mv "$f.utf8" "$f"
done

Scenario 3: Git shows encoding warnings

bash
# Configure git to handle encoding
git config core.quotepath false  # Show Chinese filenames correctly
git config i18n.commitencoding utf-8
git config i18n.logoutputencoding utf-8

Prevention Checklist

Before any file operation:

  • Locale is set to UTF-8 (echo $LANG should show *.UTF-8)
  • File encoding is verified (file -I filename)
  • Content being written is valid UTF-8
  • Editor/IDE is configured for UTF-8

Quick Diagnostic

Run this to check your environment:

bash
echo "Locale: $LANG"
echo "LC_ALL: $LC_ALL"
python3 -c "import sys; print(f'Default encoding: {sys.getdefaultencoding()}')"
python3 -c "import locale; print(f'Preferred encoding: {locale.getpreferredencoding()}')"

Expected output:

Locale: en_US.UTF-8
LC_ALL: en_US.UTF-8
Default encoding: utf-8
Preferred encoding: UTF-8

Integration with Tools

Read Tool

  • Automatically detects and handles encoding
  • If garbled, the file may need conversion first

Edit Tool

  • Content parameter must be valid UTF-8
  • Tool validates encoding before applying changes

Write Tool

  • Content parameter must be valid UTF-8
  • Overwrites file with UTF-8 encoding

Bash Tool

  • Set locale before commands: LANG=en_US.UTF-8 command
  • Pipe through iconv if needed: command | iconv -f GBK -t UTF-8

同梱ファイル

スキルが読み込まれている間、モデルは必要に応じてこれらを読み取ります。読み取り可能なファイルとして提供され、実行されることはありません。

よくある質問

AIスキル「Encoding Guard」では何ができますか?

Prevent garbled text (乱码) when editing code and comments. Use this skill whenever reading, writing, or modifying files to ensure proper UTF-8 encoding handling. Activates on any file edit operation, especially when working with Chinese characters, emoji, or non-ASCII content.

TypingMindでEncoding Guardを使うメリットは何ですか?

一度インストールすれば、どのモデルでも使えるからです。Encoding Guardはプロバイダー固有のコードではなく、通常のMarkdownで記述されているため、同じスキルをGPT-5、Claude、Gemini、Grok、ローカルモデルで利用できます。チャットの途中でモデルを切り替えても、そのまま使い続けられます。TypingMindは自分のAPIキーで動作するため、シート単位のサブスクリプションではなく、プロバイダーに直接料金を支払います。スキルとチャットは自分のストレージに保持されます。

TypingMindにEncoding Guardをインストールするにはどうすればよいですか?

TypingMindで「プラグイン」→「スキル」→「GitHubからインストール」を開き、https://github.com/cropflre/nowen-note/tree/main/.claude/skills/encoding-guardを貼り付けてください。TypingMindがSKILL.mdを読み込み、関連ファイルをまとめて、チャットごとに有効にできるスキルとしてインストールします。

Encoding Guardを使えるAIモデルはどれですか?

TypingMindに接続したどのモデルでも利用できます。AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、GPT、Claude、Gemini、Grok、ローカルモデルのいずれも、リクエストの内容がこのスキルの用途に合ったときに、このスキルを読み込めます。

Encoding Guardで使えるAIモデルの数に制限はありますか?

数に制限はありません。スキルに対応したモデルであれば、GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llamaなど、どのモデルでもEncoding Guardを利用できます。すべてTypingMind上で、自分のAPIキーを使って利用できます。

AIスキル「Encoding Guard」は無料ですか?

はい。cropflreがGPL-3.0ライセンスのもとでGitHubに公開しています。ご利用のAIプロバイダーに支払うのは、使用したトークンの料金だけです。

AIスキルとは何ですか?

AIスキルは、特定のタスクの実行方法をAIモデルに教える、再利用可能な指示のセットです。オープンなAgent Skills形式に従い、名前と説明を含むSKILL.mdファイルに加え、モデルが必要とするスクリプト、テンプレート、参照ファイルで構成されます。モデルはリクエストがスキルに合致したときだけ指示を読み込むため、インストール済みのスキルも、使うまでは費用がかかりません。

AIスキルは、プラグインやMCPサーバーとどう違いますか?

プラグインやMCPサーバーは、モデルが呼び出せる新しいツールを提供します。ツールとは、どこかで実行され、結果を返すコードです。一方、AIスキルは、タスクへの取り組み方、従うべき手順、望ましい出力の例といった知識や進め方をモデルに伝えます。スキルは通常のMarkdownで記述されているため、サーバー、APIキー、実行環境は不要で、どのモデルでも利用できます。

すべて見る

今すぐ自分専用のAIワークスペースを作成

ニュースレターに登録すると、新機能や今後のプレゼント企画のお知らせが届きます👇