DeepSeek Harness Plugin

PerryLink/dsh-mask

Stars ★ 18 Downloads (30d) 3,056 Category Security & Permissions Added 2026-08-29 npm dsh-mask

PII masking for DeepSeek Harness — anonymizes names, phones, emails, ids, and keys before requests and restores them at the display layer, keeping plaintext out of session logs.

Install

# from npm (prebuilt)

dsh plugin --profile web add dsh-mask

# from GitHub (first run asks for allowBuilds approval — follow the hint, retry)

dsh plugin --profile web add github:PerryLink/dsh-mask

Any plugin you install runs third-party code with your own permissions — it can read your files, use your credentials, and reach the network, and tool approvals don’t sandbox it. GitHub-sourced plugins also run build scripts at install time — pnpm blocks those until you allow them, so an install can stop with ERR_PNPM_GIT_DEP_PREPARE_NOT_ALLOWED or ERR_PNPM_IGNORED_BUILDS; dsh prints the exact key to add under allowBuilds in your profile’s pnpm-workspace.yaml, and the install works on the next run. Allowing a build is a trust decision: only install sources you trust, and pin a commit (github:owner/repo#sha).

README

dsh-mask

Anonymize personal data before it reaches the model — the plaintext never enters your session log.

A pure host-side PII masking middleware for DeepSeek Harness: phones, emails, ID cards, bank cards, and keys become placeholders at the model boundary, and the restore table stays on your own machine.

Install · Configuration · FAQ · 简体中文 · English · Español · Português · हिन्दी

dsh plugin --profile <name> add dsh-mask

Community plugin, not affiliated with DeepSeek. Canonical repository: https://github.com/PerryLink/dsh-mask (Gitee is a mirror).

What it is

Before a message reaches the model, dsh-mask rewrites the phones, emails, ID cards, bank cards, and keys inside it into placeholders such as <PHONE_1> — what the model sees and what the session log records are placeholders only. The originals live solely in the host-side restore table (memory plus the controlled dsh_mask storage domain), and an explicit /mask restore call delivers them back as a 0600-permission file whose path — never the plaintext — is what gets logged. Pure regex, zero dependencies, no network requests.

Three-step setup

  1. Install (pick one channel):

    # git channel (latest main; equivalent to git+https://github.com/PerryLink/dsh-mask.git)
    dsh plugin --profile web add github:PerryLink/dsh-mask
    # npm channel (published releases)
    dsh plugin --profile web add dsh-mask
    # tarball channel: pnpm pack in this repo, then
    dsh plugin --profile web add ./dsh-mask-<version>.tgz
    

    No build step — index.mjs and lib/ are the shipped artifacts.

  2. Minimal config (sane defaults; tailor the entity list as needed):

    - insert:
        - id: mask
          name: dsh-mask
          config:
            entities: [phone, email, id-card, bank-card, key]
    
  3. Verify it mounts:

    dsh --profile web --dump-config | grep -A2 'id: mask'
    
    > /mask status
    > /mask restore <PHONE_1>
    mask: restored 1 placeholder(s): <PHONE_1>
      file: /tmp/dsh-mask-restore/restore-1f0c….txt  (mode 0600, one file per session)
    

Uninstall: dsh plugin --profile web remove dsh-mask (or remove the row from the profile patch).

dsh-mask no longer bundles the storage stack. Profiles that already compose it (the web profile does, via @deepseek-ai/dsh-web-app) provide storageDomain, so persistence works out of the box. On a bare profile without storage the plugin still mounts and masks, but the restore table is memory-only (lost on restart) — compose the storage stack in your profile patch, or set persistRestoreTable: false.

Every PerryLink plugin is listed in the built-in DSH Desktop market: Market → Sources → Add source → paste https://perrylink-dsh-catalog.perrylink.workers.dev/catalog-source.json → select. Installation still requires the market's npm identity check and your confirmation.

Core capabilities

dsh-mask anonymizes personal data at the model boundary — before a message reaches the model — and keeps a restore table host-side so placeholders stay reversible:

  • Request-time masking — agent/pre-step messages are rewritten so phones, emails, ID cards, bank cards, and keys (on by default) and IPs (opt-in) become <PHONE_1>-style placeholders. The masked text is what gets logged and sent to the model.
  • Restore table — the placeholder → original map lives only in memory and a controlled storage domain (dsh_mask); the plaintext never enters the session log.
  • Audit, not plaintext — the mask/applied session event records only "replaced N values + type distribution", never the original text or the mapping.
  • /mask command — status (counts + distribution), on/off (runtime toggle), restore <text> (unmap placeholders and deliver the plaintext as a file, never as logged text), help.
  • mask_test tool — run a snippet through the detector and see the placeholder result; it never reveals the original values.
user message ──agent/pre-step──▶ placeholders ──model──▶ placeholders ──restore──▶ controlled file
                                   ▲                                                      │
                                   └──────── restore table (memory + dsh_mask) ───────────┘

Commands & tools surface

Surface Reveals plaintext Notes
agent/pre-step masking never Rewrites messages to placeholders before they are logged or sent to the model
tools/post-execute masking never Rewrites tool-result text blocks to placeholders before they are logged or fed back to the model (scope: tools)
/mask status never Enabled state, total replaced, type distribution
/mask on / /mask off never Runtime toggle (resets to config.enabled on restart)
/mask restore <text> yes (explicit) Unmaps placeholders back to the values stored for this session and writes them to a controlled file (one per session, mode 0600); the result text and the session log carry only that path and the placeholder names
mask_test never Masks a snippet and reports the placeholder result + counts

Examples

These are the plugin's real entry points; install once, then call one.

Detailed example — command mask_test, input:

{"text":"电话 13812345678"}

Output:

mask_test: replaced 1 PII value(s) (PHONE=1)
masked:
电话 <PHONE_1>

Observed from plugins/dsh-mask/index.mjs:243-250; test/index.test.mjs:306-315

Failure branch — input:

/mask restore <PHONE_1> with restoreDir=/tmp/dsh-mask-probe-not-a-dir (a regular file)

Output:

mask: restore failed: EEXIST: file already exists, mkdir '/tmp/dsh-mask-probe-not-a-dir'

Observed from plugins/dsh-mask/index.mjs:501-506; plugins/dsh-mask/lib/deliver.mjs:89-97; plugins/dsh-mask/test/index.test.mjs:278-290

Brief examples: mask_test · /mask restore <text>

Measured data

The per-type P/R/F1 benchmark over 108 synthetic samples (60 positive, 48 negative) is published in benchmark/RESULTS.md; regenerate it with node benchmark/run.mjs (no build step, zero new dependencies). The benchmark covers the regex path only: shape checks without checksums, the ip regex is range-loose (hence its false positives), and person/address are not measured.

Configuration

All tunables are Schemastery Config fields (changeable from cordis.yml). An id-targeted override replaces the whole row — restate every key you need. cordis.patch.yml documents each key inline.

Most-used keys:

Key Default Meaning
enabled true Master switch; false unregisters the listener, the /mask command, and the mask_test tool
mode regex Detection mode; only regex is implemented (regex+ner for name/address recognition is reserved and fails loud)
entities [phone, email, id-card, bank-card, key] Which PII types to mask; ip is also regex-capable (opt-in), person/address require NER
scope [messages] Masking surface(s); messages masks agent/pre-step messages, tools masks tool-result text on tools/post-execute. Accepts a string or an array, e.g. [messages, tools]
persistRestoreTable true Persist the restore table to the controlled dsh_mask storage domain (false = memory only)
restoreDir '' Where /mask restore delivers the restored plaintext. Empty = os.tmpdir()/dsh-mask-restore; a relative value resolves against the host process working directory. The directory is created 0700 and the file written 0600, one file per session
Key Default Meaning
enabled true Master switch; false unregisters the listener, the /mask command, and the mask_test tool
mode regex Detection mode; only regex is implemented (regex+ner for name/address recognition is reserved and fails loud)
entities [phone, email, id-card, bank-card, key] Which PII types to mask; ip is also regex-capable (opt-in), person/address require NER
scope [messages] Masking surface(s); messages masks agent/pre-step messages, tools masks tool-result text on tools/post-execute. Accepts a string or an array, e.g. [messages, tools]
registerCommand true Register the /mask command
registerTools true Register the mask_test tool when the tools service is present
persistRestoreTable true Persist the restore table to the controlled dsh_mask storage domain (false = memory only)
maxRestoreEntriesPerSession 500 Per-session restore entry cap (oldest evicted first)
maxSessions 1000 In-memory session cap (least-recently-used evicted, mapping reloaded on demand)
maskClientEnabled false Feature flag for the browser half "reveal" bubble (defensive; off by default until the live slot catalog verifies the target slot). The key is schema-declared and validated, but no runtime code reads it yet, so it changes nothing until the browser half ships
restoreDir '' Where /mask restore delivers the restored plaintext. Empty = os.tmpdir()/dsh-mask-restore; a relative value resolves against the host process working directory. The directory is created 0700 and the file written 0600, one file per session

Example override in your profile patch:

- insert:
    - id: mask
      name: dsh-mask
      config:
        entities: [phone, email, id-card, bank-card, key, ip]
        persistRestoreTable: false
        registerCommand: true

FAQ

The placeholder → original restore table lives in memory and, when persistRestoreTable: true, in the controlled dsh_mask storage domain — it is never written to the session log. The only other plaintext copy is the delivery file an explicit /mask restore writes under restoreDir (mode 0600, one file per session, overwritten by the next restore); nothing writes plaintext to disk implicitly.

Nothing is silent. On a bare profile without the storage stack the plugin still mounts and masks, with the restore table degrading to memory-only plus a one-time warning. When the host does not record the mask/applied event type, audit appends are skipped and the first refusal per session logs one visible warning. Unimplemented mode (regex+ner), NER entities, unknown scope values, and out-of-bounds numbers all fail loudly at load.

No. Every tool is namespaced, it provides no service key, registers no client slot and no webServer prefix, and mutates no globals; every shared-event listener delegates through next() and never short-circuits the chain. The point-by-point argument is in "Interoperability with other DSH plugins".

The detector is zero-dependency pure regex — no network requests, no model calls — rewriting message text synchronously on agent/pre-step. For measured accuracy, see "Measured data" (108 samples, Macro F1 0.972).

Security boundaries

  • Plaintext never enters the session log. The masked (placeholder) form is what gets logged and sent to the model, so model-visible content is reconstructable from the log in placeholder form; the originals stay in the restore table. The same rule governs the reveal direction: a command's result text is logged verbatim by the host and rendered from that same event, so /mask restore writes the plaintext to a controlled file and returns only its path.
  • Sanitize before display/log. lib/sanitize.mjs redacts PII, secrets, and URL credentials before any text reaches the model or the log; mask_test, /mask status, and every /mask error path never echo originals.
  • Controlled restore. /mask restore is the single explicit reveal surface, and it only reads the mapping for the active session. Failure fails closed: if the delivery file cannot be written, the command reports an error and never falls back to echoing the plaintext.
  • Fail closed. Unimplemented mode (regex+ner), unknown scope values, NER-only entities, and out-of-bounds numbers all fail loudly at load.
  • Registrations are effects. The listener, command, tool, and storage-domain close are all Cordis effects — stop/hot-reload removes them.

Permissions & data

  • Permissions: dsh-mask performs no network requests and stores no credentials; it reads the session at the agent/pre-step boundary, writes its own dsh_mask storage domain, and writes the /mask restore delivery file (the manifest declares filesystem:write for exactly that). The dshWorkshop manifest also declares network:none and credentials:none.
  • Data: see the first FAQ entry for where the restore table and the delivery file live — the conclusion stands: plaintext never reaches the session log.
  • Session log: mask/applied is declared in types.d.ts and appended only when the host records the type (see Known limitations). Its payload is counts + type distribution only.

Known limitations

  • Regex only. Name (person) and address (address) recognition needs an external NER recognizer, which the pure-host zero-dependency form does not bundle; mode: regex+ner and those entities fail loudly at load. The PII types covered out of the box are phone, email, ID card, bank card, key, and (opt-in) IP.
  • Region-specific patterns. The phone and id-card detectors match mainland-China formats only: phone is 1[3-9] followed by nine digits, and id-card is an 18-character Chinese resident ID (17 digits plus a digit or X). Phone numbers and national identifiers from other countries are not detected. email, ip, and key are region-agnostic; bank-card accepts any 16-19 digit run at a lower confidence score.
  • Display-layer restore needs a client half. Masking is fully host-side, but transparently un-masking the assistant bubbles in the client UI is a browser-half feature this pure-host form does not ship. The host side keeps the restore table and the exported RestoreStore seam (its methods take a session id), so a future client half would reach them through a host remote rather than directly; today the unmasking surface is the /mask restore <text> command, which delivers the plaintext as a file because a command result is logged verbatim (see Security boundaries), and the maskClientEnabled key is validated but read by no runtime code yet.
  • No no-argument /mask restore. Restoring every placeholder of the most recent assistant message is not offered, and the command says so when invoked without text. Two host facts block it: the restore table is a flat per-session {placeholder: original} map with no per-message index, so that message has to be located in the session event log; and the host deprecated Session.snapshotEvents() / eventAt() / ownEvents() with an explicit "new calls are prohibited", leaving an incremental projection as the only sanctioned route — which this plugin's declared host corridor (>=0.1.2-rc.1) cannot rely on. Placeholders keep working one at a time instead: /mask restore <PHONE_1>.
  • Session events on 0.1.7-rc.2. The harness records 59 session event types and none of them is mask/*; its Session.append also cannot stamp the ignorable envelope, so the session-log audit appends are skipped and sessions keep loading. The gate is not silent about it: the first refusal per session logs one visible warning naming the skipped type and this documented limitation. The plugin enables the append automatically once a host records the type or supports the ignorable envelope.

Interoperability with other DSH plugins

Verified against DSH 0.2.0-rc.2 (the runtime this README ships for) and the high-star plugin set surveyed on 2026-10-05.

This plugin does not interfere with other plugins, including the widely installed high-star ones:

  • No tool-name collision. Every tool is namespaced; no bare name owned by a shipped tool or another plugin is registered.
  • No service-key collision. It provides no service key at all, so it cannot collide on one.
  • No slot collision. It registers no client slot key, so it cannot contend for a shadows-shipped-ui seat.
  • No HTTP route collision. It registers no webServer prefix.
  • No patch-layer collision. The bundle patch only inserts its own row; it never overrides a built-in row's config.
  • No global mutation. It does not patch prototypes, rewrite process.env, or replace the global fetch dispatcher.

Shared event listeners are non-interfering by construction. It observes the ordering-sensitive events agent/pre-step, tools/post-execute with ctx.on() — Cordis's broadcast registration, where every listener runs and none can starve another. Every listener here delegates through next(), so the chain is never short-circuited, and a mutation is applied to the value next() produced rather than returned in its place:

  • agent/pre-step — also used by dsh-routing-suite (7000★, 7 listeners), modlens (4122★), dsh-purge (3317★), dsh-agent-teams (1923★), dsh-context (1849★).
  • tools/post-execute — also used by cc-safety-net (1576★).

Static evidence: dsh-plugin-doctor K10–K13 report pass for every check on this repository.

Compatibility

Surface Status
Harness DeepSeek Harness dsh-v0.2.1-alpha.1 (adapted 2026-09-18): the session envelope keeps its ignorable field for stored-log read compatibility only - Session.append still cannot stamp it, so audit-gate behavior is unchanged. Verified 2026-09-18 against the dsh-v0.1.7-alpha.1 master checkout (full gate chain + profile install smoke).
Node ^22.19.0 || >=24.0.0
Platforms Anywhere DSH runs (pure host, zero-dependency regex; no browser half)
Model Text models fully supported; no extra model capability required

Ecosystem & quality

Development

pnpm install                                       # node ^22.19 || >=24
pnpm run typecheck && pnpm run typecheck:ci        # two rulers: checkout face (guarded; unverifiable without the checkout) + published-line face
pnpm test                                          # node --test
pnpm run verify:self-contained                     # dependency specs resolve from the registry
pnpm run verify:artifacts                          # shipped files present + index.mjs importable
pnpm run check:readmes                             # five-language README consistency
pnpm pack                                          # the published tarball

There is no build step: pure ESM, index.mjs and lib/ are the shipped artifacts. Benchmark: node benchmark/run.mjs, results in benchmark/RESULTS.md. The README images are generated programmatically by scripts/gen-readme-assets.py (Python + Pillow) and are safe to re-run.

Topics: dsh, dsh-plugin, deepseek-harness, deepseek, cordis, pii, mask, privacy, anonymization, security

Family & thanks

This project is part of the DeepSeek Harness plugin family from PerryLink (all Apache-2.0). If it is useful, a star helps the next person find it — nothing is gated behind it.

  • @PerryLink — creator and maintainer: the regex PII detector ported from Pii-Stripper-Middleware, the agent/pre-step masking seam, the restore table, the /mask command and mask_test tool, and the five-language docs.
Plugin Status
dsh-aqua-input-check
dsh-archive-check
dsh-auto-review
dsh-autotier 🧊 FROZEN — see the repo README
dsh-bid-ca-precheck
dsh-bid-qual-check
dsh-cert-mcp 🧊 FROZEN — see the repo README
dsh-checkpoint-rewind
dsh-click
dsh-composer-history
dsh-contract-stance
dsh-customs-doc-check
dsh-data-quality
dsh-demurrage-ledger
dsh-doublecheck
dsh-drill-script-check
dsh-eia-guide-check
dsh-emergency-plan
dsh-essay-rubric-check
dsh-evidence-check
dsh-export-ctl-check
dsh-fast
dsh-fmea-table-check
dsh-forecast-penalty
dsh-fund-research
dsh-github
dsh-gongwen-flow-check
dsh-gongwen-word-check
dsh-guard-plan-qc
dsh-hazchem-check
dsh-hazplan-check
dsh-hidden-risk-map
dsh-hs-classify
dsh-icd-rule-check
dsh-industry-research
dsh-lawcite-adapter
dsh-laya
dsh-lc-doc-check
dsh-learning-gap-check
dsh-library
dsh-local-ai
dsh-lsp-actions
dsh-mask
dsh-mcp-panel
dsh-medrec-qc
dsh-memento
dsh-nsfc-form-check
dsh-nurse-record-check
dsh-observe
dsh-origin-rvc-check
dsh-ota-review-check
dsh-output-styles
dsh-paper-doc-adapter
dsh-permission-rules
dsh-permit-report-check
dsh-pipeline-check
dsh-pleading-draft
dsh-plugin-doctor 🚫 RETIRED (repo archived)
dsh-plugin-guide
dsh-plugin-kit 🚫 RETIRED (repo archived)
dsh-plugin-upgrade 🚫 RETIRED (repo archived)
dsh-policy-brief-draft
dsh-power-loss-split
dsh-power-ticket-check
dsh-ppap-check
dsh-protest-deadline
dsh-railway-window
dsh-repair-order-qc
dsh-research-report
dsh-review-reply-check
dsh-rulefile-check
dsh-safety-brief-check
dsh-score
dsh-session-sync
dsh-site-log-check
dsh-skill-pack-security
dsh-soe-decision-check
dsh-soilwater-check
dsh-sop-sync-check
dsh-spc-gbt-adapter
dsh-talk
dsh-tender-extract
dsh-tender-matrix
dsh-test-drive
dsh-ticktick 🚫 RETIRED (repo archived)
dsh-translate
dsh-warranty-calc
dsh-budget 🧊 FROZEN — see the repo README
dsh-claude-move 🧊 FROZEN — see the repo README
dsh-defend 🧊 FROZEN — see the repo README
dsh-draw 🧊 FROZEN — see the repo README
dsh-reach 🧊 FROZEN — see the repo README
dsh-background-agents 🚫 RETIRED (repo archived)
dsh-session-pin 🚫 RETIRED (repo archived)
dsh-team-rooms 🚫 RETIRED (repo archived)

License

LICENSE (Apache License 2.0) © 2026 dsh-mask contributors

Content from the project README on GitHub ↗

Links

More in this category

View the whole category →

Comments are public GitHub Discussions. Loading them connects to GitHub and Giscus; a GitHub account is required to post.