Getting it into your agent
One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.
npx agentmods add skills/realsharpswing/opencode-encoding-guard/skillnpx skills add realsharpswing/opencode-encoding-guard --skill skillgit clone --depth 1 https://github.com/realsharpswing/opencode-encoding-guardWhat it costs to keep this loaded
Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5 | $0.00048 | $0.01199 |
| Opus 5 | $0.00024 | $0.00600 |
| Sonnet 5 | $0.00010 | $0.00240 |
| Haiku 4.5 | $0.00005 | $0.00120 |
Grade A, and why
cjk-edit scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.
A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.
Nothing flagged
None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.
How it starts
The opening of the file, as written. The whole thing — 104 lines — stays where its author put it; the contents beside it link to each section on GitHub.
0. 前提
本项目文件编码原则:所有文本文件统一为 UTF-8 无 BOM。这是读、写、编辑三者的基准编码。
encoding-guard.ts 插件(.opencode/plugins/encoding-guard.ts)自动处理编码转换:
- 读取(A 类):拦截
read工具输出(tool.execute.after),检查 FF FD 密度判定 GBK,异步重读后替换输出 - 编辑(B 类):拦截
edit工具(tool.execute.before),检测 GBK 后在匹配前一次性转为 UTF-8 - 异步 I/O + 编码缓存(路径+mtime键控):同一文件不重复检测,零事件循环阻塞
- 全异步非阻塞:
node:fs/promises,不阻塞 UI 线程,零闪屏
下列旧工具/规则已被插件替代,不再为日常路径。skill 中保留仅为 filesystem_read_text_file 场景和手动降级兜底。
1. 读取
首选 read 工具
read 经 encoding-guard 插件加持可自动识别 GBK。始终优先使用。
filesystem_read_text_file 回退
此工具不受插件覆盖。若因工具限制需使用它读取含 CJK 的文件,且返回乱码:
- 手动用
tools/detect-encoding.ps1鉴定编码(参见附录 A) - 若为 GBK,改用
read或 bashGet-Content -Encoding GBK读取
2. 写入
首选平台工具
| 操作 | 工具 | 编码 |
|---|---|---|
| 写入 | filesystem_write_file |
UTF-8 无 BOM(默认) |
备份 (.md/.json) |
filesystem_copy_file → .bak |
不改变编码 |
PowerShell 降级
仅当 filesystem_* 失败时使用:
. "$Env:PROJECT_ROOT/tools/write-safe.ps1"
Write-SafeFile -Path "目标文件" -Content $newContent
显式编码指定
任何 PowerShell 文件操作(Get-Content / Set-Content / Out-File)必须显式指定编码:
| 场景 | 正确 |
|---|---|
| 读取 | -Encoding utf8 或 -Encoding GBK |
| 写入 | -Encoding utf8 或 [UTF8Encoding]::new($false) |
| 禁止 | 不带 -Encoding 参数的 Get-Content/Set-Content |
3. 编辑
edit 工具在操作前会自动检测文件编码:若为 GBK 则一次性转为 UTF-8 再执行匹配。 这由 encoding-guard 插件实现。
以下 SOP 仅在 edit 匹配失败时使用(作为兜底链路)。
3.1 首次尝试:短匹配原则
❌ 含中文标点的完整句子
oldString: - **批判性评估**:... [cite: 2026-01-15]
✅ 纯 ASCII 关键字 + 唯一标识
oldString: [cite: 2026-01-15]
3.2 失败恢复链路
edit 工具报 "could not find oldString"
├─ 步骤1:尝试 replaceAll: true
├─ 步骤2:用纯 ASCII 关键字重新定位
└─ 步骤3:降级至 filesystem_edit_file → bash Get-Content + 替换
4. PS Unicode 陷阱
PowerShell 字符串操作对 CJK 字符存在 culture-sensitive 陷阱。
| 场景 | 正确做法 | 错误做法 |
|---|---|---|
| CJK 字符串 IndexOf | $s.IndexOf("中", [StringComparison]::Ordinal) |
$s.IndexOf("中")(culture-sensitive) |
| 字面替换 | $s.Replace("旧","新")(.NET 方法) |
$s -replace "旧"(regex,含特殊字符时出错) |
| 文件写编码 | [UTF8Encoding]::new($false) |
[Encoding]::UTF8(产生 BOM) |
What this file has done since we first saw it
Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.
- 2d ago First seen · 104 lines · 48 tokens per session scan A 27dafd6ba3f3
cjk-edit is a skill published in the GitHub repository realsharpswing/opencode-encoding-guard (5 stars, last pushed 3mo ago), licensed MIT. It adds 48 tokens to every session and 1,199 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.
Other skills, from other repositories
i18n-localization
Internationalization and localization patterns. Detecting hardcoded strings, managing translations, locale files, RTL support.
seedance-vocab-ja
This skill should be used when the user asks for Japanese Seedance 2.0 prompt wording, Japanese cinematic vocabulary, or translation of camera, lighting, action, VFX, audio, and production terms into Japanese.
asc-subscription-localization
Bulk-localize subscription, subscription-group, and in-app purchase display names across App Store locales using asc, including API 4.4.1 version-scoped v2 resources. Use when filling or updating subscription/IAP names and descriptions without App Store Connect UI work.
harden
Improve interface resilience through better error handling, i18n support, text overflow handling, and edge case management. Makes interfaces robust and production-ready.
patina
Detect and rewrite AI writing patterns in Korean, English, Chinese, and Japanese text so it reads as if a human wrote it. Meaning-preservation (MPS) verified.
iflytek-text-proofread
Proofread Chinese text using iFlytek's Official Document Proofreading API (公文校对). Detects 27 types of errors across three categories.