dsh-env-switcher

September 12, 2026 · View on GitHub

DeepSeek Harness tool plugin: four pure tools for working with .env file content. The model passes dotenv text in and gets structured data or ready file text out — the plugin never opens a file, spawns a process, reads the host environment, or talks to the network, so every call is deterministic and parallel-safe.

Install

npx -y @deepseek-ai/dsh plugin --profile web add @qingshanjiluo/dsh-env-switcher

The bundle layer (cordis.patch.yml) inserts the plugin into the profile's layer stack; the tools appear in the model's tool list on the next session.

Tools

ToolInputOutput
env_parsetext — complete .env contentvalues (ordered key → string map), count, invalid (one note per unreadable line)
env_diffa — original content, b — updated contentadded, removed, changed ({ key, from, to }), identical
env_validatetext.env content, schema (required[], optional[], checks[{ key, check, pattern }])valid, count, missing, extra, errors
env_serializevalues — key → scalar map, sortKeys — emit alphabeticallytext (file-ready content ending in a newline), count, skipped

Parsing rules

  • Blank lines and # comment lines are ignored; export KEY=value is accepted.
  • Single-quoted values are literal. Double-quoted values expand \n, \r, \t, \", \\. An unterminated quote or trailing junk after the closing quote is reported in invalid and never throws.
  • Unquoted values drop a # comment when it is preceded by whitespace (configurable); KEY=#thing becomes an empty value.
  • Duplicate keys: the last value wins, the first position is kept.
  • Keys must match [A-Za-z_][A-Za-z0-9_]* and stay within maxKeyLength; anything else is reported in invalid / errors / skipped.

Validation checks

check accepts nonempty, integer, number, boolean (true/false/1/0/yes/no/on/off, case-insensitive), port (1–65535), url (http/https), email, csv (comma-separated, no empty items), and pattern (a regex source in the same check entry — an invalid regex is reported as an error instead of throwing). A check for a key that is absent is skipped; keys named in a check count as declared, so they are not reported as extra.

Configuration

FieldTypeDefaultMeaning
allowExportPrefixbooleantrueAccept export KEY=value lines when parsing
stripInlineCommentsbooleantrueDrop trailing # comment from unquoted values
maxKeyLengthnumber128Report keys longer than this instead of storing them

Example

env_validate({
  text: "PORT=8080\nEXTRA=1",
  schema: {
    required: ["PORT", "HOST"],
    optional: [],
    checks: [{ key: "PORT", check: "port", pattern: "" }],
  },
})
# -> missing: HOST · extra: EXTRA · valid: false

Development

npm install --no-audit --no-fund
npx tsc --noEmit
npm run build          # lib/index.js + lib/index.d.ts
npx vitest run         # 23 behaviour cases
node scripts/load-smoke.mjs

License

MIT