DSH Hub

fire-disposal/dsh-mojibake-interceptor

dsh-mojibake-interceptor

BundleWorkflow1 GitHub stars· updated 2026-08-15

Mojibake interceptor bundle for DeepSeek Harness: feature-based garbled-text detection, review-then-release, pwsh encoding audit.

Install

npx @deepseek-ai/dsh plugin --profile web add dsh-mojibake-interceptor

Restart `dsh web` after install. Bundle APIs can change during the developer preview.

README badge

dsh-mojibake-interceptor DSH Hub badge
[![DSH Hub](https://dshhub.dev/badge/dsh-mojibake-interceptor.svg)](https://dshhub.dev/plugins/dsh-mojibake-interceptor)

Paste this into your README. The star count updates with every catalog sync.

From the README

Excerpt from fire-disposal/dsh-mojibake-interceptor, cleaned of badges and images.

dsh-mojibake-interceptor — DeepSeek Harness 乱码拦截器

在 AI 把乱码写进文件之前打断,要求复查;若 AI 复查后仍执意(原样重试同一次写入)则放行。 纯特征值/算法检测——不维护任何关键词表。

- insert:
    - id: mojibake-interceptor
      name: 'dsh-mojibake-interceptor'
      config:
        mode: warn
        resultWatchTools: [pwsh, bash, bash_persistent, read]

工作原理

两个挂载点

挂载点事件行为
写入前拦截tools/pre-executewrite / edit / str_replace_editor 的待写入文本,以及 pwsh / bash / bash_persistent命令文本,在落盘/执行前被扫描;命中乱码特征或危险编码则返回 deny 并附复查说明
输出监视tools/post-executepwsh / bash / bash_persistent / read 的捕获结果被扫描;输出本身乱码时注入一条通知,警告模型「别把这段输出抄进文件」(Windows 上最常见的污染源)

pwsh 命令执行前审计(Windows 批量乱码悲剧的主防线)

AI 用 pwsh 写文件/替换内容时,命令文本在执行前被双重检查:

  1. 内容层:命令内嵌文本直接跑全部乱码特征(Set-Content -Value '中文'、heredoc 等执行前即命中)。
  2. 编码层pwshEncodingGuard: warn,默认):命中「写入原语 + 含非 ASCII 内容」时校验编码声明——
    • 危险编码(-Encoding Default/ANSI/OEM/Unicode[Text.Encoding]::DefaultGetEncoding(936/950/…)[Console]::OutputEncoding=chcp 非 65001)→ 严重拦截;
    • 未声明编码(PS 5.1 Set-Content 默认 ANSI/GBK、Out-File/> 默认 UTF-16LE)→ 中等拦截,提示显式 -Encoding utf8
    • 知情编码(-Encoding utf8[Text.Encoding]::UTF8、.NET WriteAllText 两参重载默认 UTF-8)→ 放行。
    • 纯 ASCII 命令永不触发编码审计;if ($a > $b) 的比较运算符不会被误判为重定向。

误报控制(正常操作不拦)

  • 注释剥离# 中文注释 / <# 块注释 #> 先剥离再审计,注释里的中文不会触发;
  • 文件名豁免-Path/-LiteralPath/-Destination 等参数值、读取命令(Get-Content 中文.txt)后的中文文件名不算内容;
  • 知情写法全识别-Enc utf8 参数缩写、[System.Text.Encoding]::UTF8[System.IO.File]::WriteAllText 全限定类型名均视为安全;
  • 非内容操作不审计Set-Item(环境变量/注册表)、Copy-Item/Move-Item/Remove-Item/Rename-Item、变量赋值($x = '你好')不触发;
  • 刻意灰色地带Set-Content 副本.txt 这类无引号位置参数中文文件名在 PS 5.1 下确实按默认编码写入(可能乱码),会拦一次提示加 -Encoding utf8,重试即放行;
  • 验证:test/regression-normal.test.mjs 覆盖正常中文文档、中英混排、日韩泰文、符号/数学/货币、西欧多语种、emoji、各类代码文件,以及十余条正常 pwsh/bash 命令,全部断言零误报(全套 72 项测试)。

复查→放行流程(mode: warn,默认)

  1. 首次命中乱码特征 → 写入被 deny,模型看到复查消息(列出命中的特征与还原结果)。
  2. AI 复查:
    • 修正编码 → 新内容重新检测,干净即放行;
    • 执意保留 → 原样重试同一次写入(同一工具 + 路径 + 内容指纹)→ 放行。
  3. mode: block:命中即永久拒绝(直到内容变化);mode: ask:每次命中都走 harness 审批通道(人工裁决)。

指纹键是 工具 + 路径 + 待写入文本,因此「改一个字的乱码重试」会被当作新内容重新检测,不会绕过。

检测特征(算法,无关键词表)

所有信号均由字符统计或编码回环校验推导:

Related plugins