# dsh-mask
**Repository Path**: perrylink/dsh-mask
## Basic Information
- **Project Name**: dsh-mask
- **Description**: PII masking middleware for DeepSeek Harness: anonymize names, phones, emails, ID cards, bank cards, keys, and addresses to placeholders before they reach the model, restore them at the display layer,
- **Primary Language**: Unknown
- **License**: Apache-2.0
- **Default Branch**: main
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2026-08-22
- **Last Updated**: 2026-09-22
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# dsh-mask
- **1024 商店渠道**:先 `npm i -g dsh1024`,再 `dsh1024 plugin --profile web add dsh-mask`(计入 [deepseek1024.com](https://deepseek1024.com) 安装排行)。
**面向 DeepSeek Harness 的 PII 脱敏中间件——在个人数据进入模型前匿名化,在展示层还原。**
*电话、邮箱、身份证、银行卡、密钥等在模型边界变成占位符;原文绝不进入会话日志。*
[](LICENSE)
[](https://gitee.com/perrylink/dsh-mask)
[](https://github.com/topics/dsh-plugin)
[](https://github.com/PerryLink/dsh-plugin-doctor#verified-徽章)
[](https://dsh.market/)
[](#)
[](https://github.com/PerryLink/dsh-mask/actions)
[](https://github.com/PerryLink/dsh-mask/releases)
[](https://www.npmjs.com/package/dsh-mask)
[](https://www.npmjs.com/package/dsh-mask)
[English](README.md) · [简体中文](README-zh.md) · [Español](README-es.md) · [Português](README-pt.md) · [हिन्दी](README-hi.md)
---
## Compatibility
| 维度 | 状态 |
|---|---|
| Harness | DeepSeek Harness `dsh-v0.1.7-alpha.1`(2026-09-18 已适配):会话信封保留 ignorable 字段但仅用于存量日志读取兼容——Session.append 仍无法盖章,门控行为不变。已于 2026-09-18 针对 `dsh-v0.1.7-alpha.1` master checkout 核验(全量门禁链 + profile 安装冒烟测试)。 |
| Node | `^22.19.0 \|\| >=24.0.0` |
| 平台 | 任何 DSH 可运行处(纯 host、零依赖正则;无浏览器半) |
| 模型 | 文本模型完全支持;无需额外模型能力 |
## What you get
`dsh-mask` 在**模型边界**匿名化个人数据——消息进入模型之前——并维护一张恢复表,以便在展示层把占位符映射回原文:
- **请求前遮罩** —— 重写 `agent/pre-step` 消息,使电话、邮箱、身份证、银行卡、密钥(默认开启)与 IP(可选)变成 `` 之类的占位符。被遮罩的文本才是落盘并发送给模型的内容。
- **恢复表** —— `占位符 → 原文` 映射只存内存与受控 storage domain(`dsh_mask`);原文绝不进会话日志。
- **审计不含明文** —— `mask/applied` 会话事件只记「替换了 N 处 + 类型分布」,不记原文与映射。
- **`/mask` 命令** —— `status`(计数 + 分布)、`on`/`off`(运行时开关)、`restore `(还原占位符)、`help`。
- **`mask_test` 工具** —— 试跑一段文本看替换效果;绝不回显原文。
```text
用户消息 ──agent/pre-step──▶ 占位符 ──模型──▶ 占位符 ──restore──▶ 展示
▲ │
└──── 恢复表(内存 + dsh_mask)──────────┘
```
## Quick start
```sh
# 1. 把 bundle 安装进 profile
dsh plugin --profile web add "github:PerryLink/dsh-mask#main"
# 或从 npm(发布版本)
dsh plugin --profile web add dsh-mask
# 2. 校验行是否挂载
dsh --profile web --dump-config | grep -A2 'id: mask'
```
然后在 profile patch 里调整实体列表:
```yaml
- insert:
- id: mask
name: dsh-mask
config:
entities: [phone, email, id-card, bank-card, key]
```
```
> /mask status
> /mask restore
```
## Install & uninstall
- **git 通道**(最新 `main`):`dsh plugin --profile web add "github:PerryLink/dsh-mask#main"`(等价于从 `git+https://github.com/PerryLink/dsh-mask.git` 安装)。无构建步骤——`index.mjs` 与 `lib/` 即发布产物。
- **npm 通道**(发布版本):`dsh plugin --profile web add dsh-mask`。
- **tarball 通道**:在本仓库 `pnpm pack`,再 `dsh plugin --profile web add ./dsh-mask-.tgz`。
- **卸载**:`dsh plugin --profile web remove dsh-mask`(或从 profile patch 删掉该行)。
`dsh-mask` 不再自带 storage 栈。已组合该栈的 profile(`web` profile 通过 `@deepseek-ai/dsh-web-app` 提供)自带 `storageDomain`,持久化开箱即用。未组合 storage 的 bare profile 仍可正常挂载与遮罩,但恢复表仅存内存(重启丢失)——请在 profile patch 中组合 storage 栈,或将 `persistRestoreTable` 设为 `false`。
## Configuration
所有可调项都是 Schemastery `Config` 字段(可从 cordis.yml 覆盖)。按 id 覆盖会替换整行——请重述所有需要的键。`cordis.patch.yml` 逐键内联注释。
| 键 | 默认值 | 含义 |
|---|---|---|
| `enabled` | `true` | 总开关;`false` 卸载监听器、`/mask` 命令与 `mask_test` 工具 |
| `mode` | `regex` | 检测模式;只有 `regex` 实现(`regex+ner` 姓名/地址识别预留并响亮失败) |
| `entities` | `[phone, email, id-card, bank-card, key]` | 要遮罩的 PII 类型;`ip` 也支持正则(可选),`person`/`address` 需要 NER |
| `scope` | `[messages]` | 遮罩作用域;`messages` 遮罩 agent/pre-step 消息,`tools` 遮罩 tools/post-execute 工具结果。可为字符串或数组,如 `[messages, tools]` |
| `registerCommand` | `true` | 注册 `/mask` 命令 |
| `registerTools` | `true` | tools 服务存在时注册 `mask_test` 工具 |
| `persistRestoreTable` | `true` | 把恢复表持久化到受控 `dsh_mask` 领域(`false` = 仅内存) |
| `maxRestoreEntriesPerSession` | `500` | 每会话恢复条目上限(最旧先逐出) |
| `maxSessions` | `1000` | 内存会话上限(LRU 逐出,映射按需回载) |
profile patch 覆盖示例:
```yaml
- insert:
- id: mask
name: dsh-mask
config:
entities: [phone, email, id-card, bank-card, key, ip]
persistRestoreTable: false
registerCommand: true
```
## Tools & surfaces
| 表面 | 是否回显原文 | 说明 |
|---|---|---|
| `agent/pre-step` 遮罩 | 永不 | 把消息重写为占位符后再落盘/送模型 |
| `/mask status` | 永不 | 启用状态、替换总数、类型分布 |
| `/mask on` / `/mask off` | 永不 | 运行时开关(重启回到 `config.enabled`) |
| `/mask restore ` | 是(显式) | 把占位符还原为本会话存储的值 |
| `mask_test` | 永不 | 遮罩一段文本并报告占位符结果 + 计数 |
## Permissions & data
- **权限**:`dsh-mask` 不做网络请求、不存凭据;只在 `agent/pre-step` 边界读取会话,并写入自己的 `dsh_mask` 领域。`dshWorkshop` manifest 声明 `network:none` 与 `credentials:none`。
- **数据**:`占位符 → 原文` 恢复表存内存;`persistRestoreTable: true` 时另存受控 `dsh_mask` 领域——这是 PII 原文唯一落点,绝不写会话日志。
- **会话日志**:`mask/applied` 在 `types.d.ts` 声明,仅在宿主收录该类型时 append(见 Known limitations)。载荷只有计数 + 类型分布。
## Security boundaries
- **原文绝不进会话日志。** 落盘并送模型的是遮罩(占位符)形式,因此模型可见内容可自日志以占位符形式重建;原文留在恢复表。
- **展示/日志前脱敏。** `lib/sanitize.mjs` 在文本进入模型或日志前打码 PII、密钥与 URL 凭据;`mask_test` 与 `/mask status` 永不回显原文。
- **受控还原。** `/mask restore` 是唯一的显式还原面,且只读当前会话的映射。
- **失败关闭。** 未实现的 `mode`(`regex+ner`)、`scope`(`tools`)、NER 实体与越界数值均在加载期响亮失败。
- **注册即 effect。** 监听器、命令、工具与领域关闭都是 Cordis effect——停止/热重载即可撤销。
## Known limitations
- **仅正则。** 姓名(`person`)与地址(`address`)识别需要外部 NER 识别器,纯 host 零依赖形态未捆绑;`mode: regex+ner` 与这些实体在加载期响亮失败。开箱即用覆盖电话、邮箱、身份证、银行卡、密钥与(可选)IP。
- **正则具地域局限。** `phone` 与 `id-card` 只匹配中国大陆格式:`phone` 为 `1[3-9]` 加九位数字,`id-card` 为 18 位中国居民身份证(17 位数字加一位数字或 `X`)。其他国家的电话号码与证件号码不会被检出。`email`、`ip`、`key` 与地域无关;`bank-card` 以较低置信度接受任意 16-19 位数字串。
- **展示层还原需要浏览器半。** 遮罩完全在 host 侧,但客户端 UI 中透明还原助手气泡属于浏览器半功能,本纯 host 形态未交付。host 侧保留恢复表与已导出的 `RestoreStore` seam(其方法需要会话 id),因此未来的客户端半需经 host 远程面间接消费,而非直接使用;当前的反遮罩入口是 `/mask restore ` 命令;`maskClientEnabled` 键会被 schema 声明与校验,但尚无任何运行时代码读取它。
- **`0.1.6-alpha.2` 会话事件。** 宿主收录 58 个会话事件类型,其中没有 `mask/*`;其 `Session.append` 也无法盖章 `ignorable` 信封,因此会话日志审计 append 被跳过(会话仍可加载)。门控不再静默:每个会话首次被拒时打一条可见告警,写明被跳过的事件类型与本限制。宿主收录该类型或支持 `ignorable` 信封后自动开启。
## Development
```sh
pnpm install # node ^22.19 || >=24
pnpm run typecheck && pnpm run typecheck:ci # 两把尺子:checkout 面(带守卫,无 checkout 时不可验证)+ 已发布线面
pnpm test # node --test
pnpm run verify:self-contained # 依赖 spec 均来自 registry
pnpm run verify:artifacts # 发布文件齐全 + index.mjs 可 import
pnpm run check:readmes # 五语 README 一致性
pnpm pack # 发布 tarball
```
无构建步骤:纯 ESM,`index.mjs` 与 `lib/` 即发布产物。
### Benchmark
PII 基准(108 个合成样本的逐类 P/R/F1)见 [`benchmark/RESULTS.md`](benchmark/RESULTS.md);用 `node benchmark/run.mjs` 复现(无需构建、零新依赖)。
## Topics
`dsh`, `dsh-plugin`, `deepseek-harness`, `deepseek`, `cordis`, `pii`, `mask`, `privacy`, `anonymization`, `security`
## Contributors
- [@PerryLink](https://github.com/PerryLink) —— 创建者与维护者:从 Pii-Stripper-Middleware 移植的正则 PII 检测器、`agent/pre-step` 遮罩 seam、恢复表、`/mask` 命令与 `mask_test` 工具、五语文档。
## PerryLink DSH Plugin Family
This project is one of the **45 DeepSeek Harness plugins** maintained by [PerryLink](https://github.com/PerryLink). If this one helps you, the others likely will too:
| Plugin | One-liner |
|---|---|
| **[dsh-auto-review](https://github.com/PerryLink/dsh-auto-review)** | Second-model auto-review on the approval chain, fail-closed by default | |
| **[dsh-autotier](https://github.com/PerryLink/dsh-autotier)** | Automatic strong/cheap model-tier routing with deterministic risk guards and a `/tier` command | |
| **[dsh-background-agents](https://github.com/PerryLink/dsh-background-agents)** | Durable background child agents with a Web UI sidebar, messaging and interrupt | |
| **[dsh-budget](https://github.com/PerryLink/dsh-budget)** | Cost governance for DeepSeek Harness: budgets, carbon, and latency in one panel. | |
| **[dsh-catalog](https://github.com/PerryLink/dsh-catalog)** | DSH Desktop Market standard catalog source for the PerryLink family | |
| **[dsh-cert-mcp](https://github.com/PerryLink/dsh-cert-mcp)** | Read-only MCP server exposing the certification registry: grades, snapshots and five-dimension evidence | |
| **[dsh-checkpoint-rewind](https://github.com/PerryLink/dsh-checkpoint-rewind)** | Claude Code /rewind-equivalent: snapshots, session forks, one-shot restore | |
| **[dsh-claude-move](https://github.com/PerryLink/dsh-claude-move)** | Migrate Claude Code sessions, memory, skills and CLAUDE.md into DSH | |
| **[dsh-click](https://github.com/PerryLink/dsh-click)** | Cross-platform native desktop control for DeepSeek Harness — Windows first. | |
| **[dsh-composer-history](https://github.com/PerryLink/dsh-composer-history)** | Terminal-style input history for the web composer: arrows, Ctrl+R search | |
| **[dsh-data-quality](https://github.com/PerryLink/dsh-data-quality)** | Dataset quality checks and citation cross-checks (the optional numeric bridge consumed here) | |
| **[dsh-defend](https://github.com/PerryLink/dsh-defend)** | Prompt-injection, jailbreak, and secret-leak defense for DeepSeek Harness. | |
| **[dsh-doublecheck](https://github.com/PerryLink/dsh-doublecheck)** | Engineering-discipline guard: requirements grill, test gates, adversary review | |
| **[dsh-draw](https://github.com/PerryLink/dsh-draw)** | Unified static-image generation routing for DeepSeek Harness. | |
| **[dsh-fast](https://github.com/PerryLink/dsh-fast)** | Read-only performance diagnostics for DeepSeek Harness. | |
| **[dsh-fund-research](https://github.com/PerryLink/dsh-fund-research)** | Deterministic research reports for Chinese public mutual funds | |
| **[dsh-github](https://github.com/PerryLink/dsh-github)** | GitHub PR/issues integration for DSH, every write gated by approval | |
| **[dsh-industry-research](https://github.com/PerryLink/dsh-industry-research)** | Industry research orchestration that seals its deliverables through this plugin's `ctx.researchReport.assemble` | |
| **[dsh-laya](https://github.com/PerryLink/dsh-laya)** | Laya typed decisions (`noul`/`choice`/`score`) as a first-class Cordis service and model-visible tools | |
| **[dsh-library](https://github.com/PerryLink/dsh-library)** | Local document knowledge base for DeepSeek Harness. | |
| **[dsh-local-ai](https://github.com/PerryLink/dsh-local-ai)** | Local-model (Ollama) integration for DeepSeek Harness. | |
| **[dsh-lsp-actions](https://github.com/PerryLink/dsh-lsp-actions)** | LSP diagnostics, formatting, completion, code actions and rename over language servers | |
| **[dsh-mask](https://github.com/PerryLink/dsh-mask)** | PII masking middleware: anonymize at the model boundary, restore at the display layer | |
| **[dsh-mcp-panel](https://github.com/PerryLink/dsh-mcp-panel)** | Read-only MCP runtime panel: /mcp command + Settings tab with status, tools and errors | |
| **[dsh-memento](https://github.com/PerryLink/dsh-memento)** | Approval-gated cross-session memory: ctx.memory seam + SQLite + memory tool | |
| **[dsh-observe](https://github.com/PerryLink/dsh-observe)** | OpenTelemetry and Langfuse observability exporter for DeepSeek Harness. | |
| **[dsh-output-styles](https://github.com/PerryLink/dsh-output-styles)** | Claude Code outputStyles-equivalent runtime style switching | |
| **[dsh-permission-rules](https://github.com/PerryLink/dsh-permission-rules)** | Claude Code-style declarative allow/deny/ask permission rules with audit | |
| **[dsh-plugin-certification](https://github.com/PerryLink/dsh-plugin-certification)** | Community certification registry with repro-checkable grades and badges | |
| **[dsh-plugin-doctor](https://github.com/PerryLink/dsh-plugin-doctor)** | Zero-dependency static + sandbox smoke detector for DSH plugins | |
| **[dsh-plugin-guide](https://github.com/PerryLink/dsh-plugin-guide)** | Plugin-development knowledge base as an on-demand agent skill | |
| **[dsh-plugin-kit](https://github.com/PerryLink/dsh-plugin-kit)** | Shared zero-runtime-dependency toolkit for the PerryLink DSH plugins | |
| **[dsh-plugin-upgrade](https://github.com/PerryLink/dsh-plugin-upgrade)** | One-package, one-corridor-index plugin upgrade skill: routes a repository to the matching closed corridor card | |
| **[dsh-plugin-upgrade-015](https://github.com/PerryLink/dsh-plugin-upgrade-015)** | Merged `0.1.3-alpha.1` → `0.1.5-rc.1` upgrade corridor card plus a zero-dependency seam scanner | |
| **[dsh-reach](https://github.com/PerryLink/dsh-reach)** | Multi-channel approval/question bridge: WeChat/Telegram/Feishu, session console | |
| **[dsh-research-report](https://github.com/PerryLink/dsh-research-report)** | Verifiable research-report engine: content-addressed evidence ledger and sealed versions | |
| **[dsh-score](https://github.com/PerryLink/dsh-score)** | Multi-dimensional quality scoring for DeepSeek Harness plugins. | |
| **[dsh-session-pin](https://github.com/PerryLink/dsh-session-pin)** | Pin sessions in the Web sidebar with durable ordering | |
| **[dsh-session-sync](https://github.com/PerryLink/dsh-session-sync)** | Cross-device session sync for DeepSeek Harness — a dedicated git mirror of your session store. | |
| **[dsh-skill-pack-security](https://github.com/PerryLink/dsh-skill-pack-security)** | Security-audit skill pack: secret scan, dependency and supply-chain review | |
| **[dsh-talk](https://github.com/PerryLink/dsh-talk)** | Voice-first session loop for DeepSeek Harness: talk to it, hear it answer. | |
| **[dsh-team-rooms](https://github.com/PerryLink/dsh-team-rooms)** | Cross-session team rooms: shared message bus, task board and timeline | |
| **[dsh-test-drive](https://github.com/PerryLink/dsh-test-drive)** | Isolated install-and-smoke test drives for DeepSeek Harness plugins. | |
| **[dsh-ticktick](https://github.com/PerryLink/dsh-ticktick)** | TickTick/Dida365 task bridge: session-header panel + 11 tools | |
| **[dsh-translate](https://github.com/PerryLink/dsh-translate)** | Vendor parameter translation and deterministic JSON repair for DeepSeek Harness. | |
## License
[LICENSE](LICENSE)(Apache License 2.0)© 2026 dsh-mask contributors
### 从 DSH Desktop 市场安装
所有 PerryLink 插件均可在 DSH Desktop 内置市场中浏览:**市场 → 来源 → 添加来源 → 粘贴** `https://perrylink-dsh-catalog.perrylink.workers.dev/catalog-source.json` **→ 选中**。安装仍需通过市场的 npm 身份校验与你的确认。