OpenCode 插件,在 Windows + PowerShell 7 环境下自动为所有 bash/shell 工具调用注入 UTF-8 编码配置,解决 LLM 输出中文/非 ASCII 字符乱码问题。
- TypeScript — 源码语言
- tsup — 构建工具(ESM 输出)
- Node.js 内置模块 — 零 npm 运行时依赖
- tsup — 构建工具(ESM 输出)
- Node.js 内置模块 — 零 npm 运行时依赖
- @opencode-ai/plugin — OpenCode 插件 API(
import type,编译期擦除)
src/
└── utf8-encoding.ts # 插件源码(单文件,tool.execute.before hook)
dist/ # 构建输出(gitignore)
npm install # 安装依赖
npm run build # tsup 构建 → dist/
npm run typecheck # tsc --noEmit 类型检查插件注册到 OpenCode 的 tool.execute.before hook:
- 拦截所有
bash/shell工具调用 - 在原命令前注入
[Console]::OutputEncoding=...前缀 - 跳过已包含
OutputEncoding的命令(防重复注入) - 保留
set VAR="value" &&前缀顺序 - 调试日志默认关闭,设
OPENCODE_UTF8_DEBUG=1开启
- 使用
strictTypeScript 模式 - 具名导出
Utf8EncodingPlugin+default导出 - 零 npm 运行时依赖(
import type编译期擦除) - 调试日志写入
$TMP/utf8-plugin.log,默认关闭(设OPENCODE_UTF8_DEBUG=1开启)
feat:— 新功能fix:— 修复docs:— 文档ci:— CI/CD
npm run build— 构建npm version <patch|minor|major>— 版本号git push --follow-tags— 推送标签触发 GitHub Actions 自动发布 npm