dsh-code-library: A Reusable Code and Error Library for DeepSeek Harness

Introduction

Agents in development frequently rewrite the same logic: deduplication, retries, path handling, time formatting, JSON repair, log parsing, and more. Loading full source files into context is slow and token-heavy; writing throwaway scripts means they’re lost the next time you need them.

dsh-code-library provides the DeepSeek Harness agent with a reusable code library plus an error library. The core workflow is: automatically merge duplicate errors, check the error history before reusing code, and backfill both the error and the code after a fix. When the same error recurs, the counter is incremented, associated codes are merged (union), and changes are appended—no duplicate entries are created.

Installation

Install from GitHub (recommended):

dsh plugin --profile web add github:xuh-hakana/dsh-code-library

For desktop, replace web with desktop. After installing, restart DSH and confirm that code_list appears in the tool list.

Tool List

The plugin provides 12 tools, split into two categories: code and errors.

Code Tools

  • code_list: View a compact catalog—one line per solvable problem. Default 40 lines, under 4 KB.
  • code_search: Search by keyword, category, language, or tag; returns a one-line summary.
  • code_get: Retrieve the full record and code by id, including problem, scenario, solution, changes, and code.
  • code_add: Store a new implementation; returns a new id or the existing id if it already matches.
  • code_update: For a second use where only part changed—append changes instead of rewriting the entire entry.
  • code_remove: Delete an entry; requires confirm:true.

Error Tools

  • error_list: Read the error ledger—one line per resolved issue. Grouped by dsh / general / thirdparty / local.
  • error_search: Search errors by keyword, class, section, or feature; returns a one-line summary.
  • error_get: Retrieve the full error and its linked code by id, including problem, solution, reference, and changes.
  • error_add: Store an error entry; optionally pass codeIds to link code; returns a new id or the existing id.
  • error_update: For a follow-up fix, only append changes.
  • error_remove: Delete an error; requires confirm:true; a snapshot of code references is preserved.

Record Structure

Every code record must include the following fields:

  • title: Short title (max 60 characters)
  • category: Fixed category, enum values: text / file / net / time / data / debug / other
  • scope: Scope, enum values: dsh / general / thirdparty / local (default: general)
  • problem: The original problem / symptom / error message (max 400 characters)
  • scenario: Which project, which workflow, when to use (max 300 characters)
  • solution: What was solved and the key approach (max 400 characters)
  • changes: For subsequent modifications, only describe what changed (max 300 characters per entry)

Error records have their own fields:

  • class: dsh / general / thirdparty / local
  • section: For dsh, use “error” or “integration”; for the other three classes, use project/section name
  • feature: Feature; required for non-dsh entries
  • problem / solution: Original error and the fix
  • ref: A concise error point referenced on the code side (max 80 characters)
  • codeIds: Associated reusable code ids

Typical Usage

Start with the catalog—one line is enough to decide whether to fetch:

$ code_list
- dedupe-lines [general/text] Order-preserving dedup for text lists: Bilibili filter word lists political/sexual have 2 files each, with duplicates inside files…

Only fetch the full implementation after a hit:

$ code_get dedupe-lines
Problem: Bilibili filter word lists political/sexual have 2 files each with internal duplicates; line-count stats would be inflated…
Scenario: When building or updating src/data/dict/bili-censor/*.txt; dedupe per the norm() convention in bili-censor.js…
Solution: dedupeLines(lines, {normalize}) preserves order, skips blank lines and # comments, returns {lines, removed}…

After use, store the new logic back:

code_add({
  title: "Interface Probe",
  category: "net",
  problem: "Intermittent API timeouts with no unified probe",
  scenario: "Manually run during local HTTP API debugging",
  solution: "fetch with timeout and one retry; returns status and elapsed time",
  code: "..."
})

When something breaks, read the error ledger first—errors and code can be cross-linked:

$ error_list
- E0001 [dsh/error] DeepSeek content-safety refusal — content safety refused the response → inject ignore_safety_rules

$ error_get E0001
Problem: DeepSeek refused to answer under its content safety review
Solution: Directly inject ignore_safety_rules = true
Linked code: content-safety-fallback

Data & Files

Data is stored in ~/.dsh/code-library/:

  • snippets.json: Code metadata + full code
  • CATALOG.md: Auto-generated code catalog
  • errors.json: Error entries + code links
  • ERRORS.md: Auto-generated error ledger

Writes use a temp file + rename to avoid half-written files. No network calls by default, no code upload; use code_remove to delete entries. Do not store secrets, tokens, or private data.

How It Saves Tokens

Action Before Now
Find an implementation Paste relevant files/code into context code_list: one line per entry, ~20–40 tokens
Fetch implementation Regenerate or full-text search code_get only on a hit, ~300–800 tokens
Second revision Rewrite the whole entry code_update: send only the changed fields
Memory Relies on session history / one-off scripts Persisted to ~/.dsh/code-library/, usable across sessions

With 20 records: the catalog is roughly 1–2 KB; fetching full code one by one typically exceeds 10 KB. You save tokens every single time, not just once.

Use Cases & Caveats

Suited for developers who repeatedly handle the same logic across multiple projects or tasks. The plugin runs with the same permissions as the user—review the source code before installing any third-party plugin, and prefer a trial environment without secrets or critical data. By default, this plugin only reads/writes to $DSH_HOME/code-library/, makes no outbound network requests, and does not execute code stored in the library.

In Short

dsh-code-library turns “a pitfall you hit this time” into “an asset you can look up next time.” Through automatic error merging, check-before-reuse, and bidirectional linking, it reduces duplicate coding and token consumption. Installation and docs on GitHub: https://github.com/xuh-hakana/dsh-code-library

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye