← Back to home@xiamubumu

dsh-patch-library

官方 DSH 内核补丁的数据化版本:10 条自包含补丁 + 自适应应用器(自己找安装位置、逐个备份、语法检查、一键回退),五种打法、零硬编码路径。仅支持 DSH 1.5,后续会跟进更新。 / Official DSH core patches as data: ten patches plus an adaptive applier. Five ways to apply. DSH 1.5 only.

Stars
0
Language
JavaScript
Created
Oct 14, 2026
Updated
Oct 14, 2026

Introduction

dsh-patch-library

The official DSH core patches, as data — and five ways to apply them.

官方 DSH 内核补丁的数据化版本 —— 10 条补丁,5 种打法。

Ten self-contained patches for @deepseek-ai/dsh-* and @earendil-works/pi-ai, plus a small applier that finds your DSH installation by itself. No hard-coded paths, no personal information anywhere in this repository, no network access required.

十条自成体系的补丁,覆盖 @deepseek-ai/dsh-* 与 @earendil-works/pi-ai;配一个小巧的应用器, 它会自己找到你的 DSH 安装位置。零硬编码路径、仓库里没有任何个人信息、全程不需要联网。

🌐 中文完整说明(推荐中文读者从这里开始) → README.zh-CN.md

中文读者还应该看这两份:教程-安装与官方补丁 里的补丁库章节 与 给 agent 的中文提示词。

Built for @deepseek-ai/dsh 0.1.5-rc.2 (the 1.5 line). Every patch records the exact sha256 of both the file it expects and the file it produces, so the applier can tell you exact / applied / conflict before it touches anything.


Why this repository exists

Some fixes cannot be shipped as a plugin: they have to run inside an official file, in the middle of a function that Cordis does not expose as a seam. Four of those fixes were already published as plugins (dsh-context-reclaim, dsh-capability-composer, dsh-composer-launcher, dsh-aux-degrade). The rest — plus the ones that only matter if you want the full set — live here, as ordinary unified diffs that anyone can read, review, apply, revert, or regenerate.

Nothing here is a binary blob and nothing here is magic: patches/<id>/change.diff is a normal patch, and manifest.json is the metadata that lets a script apply it safely and reversibly.

The ten patches

idpackage → filekindsizerestartalready handled by a plugin?
dsh-llm-writable-request@deepseek-ai/dsh-llm → lib/index.jslines+18 −1yesyes — dsh-context-reclaim
agent-loop-snapshot-prompt@deepseek-ai/dsh-agent-loop → lib/index.jslines+97 −20yesno
llm-pi-ai-system-prompt@deepseek-ai/dsh-llm-pi-ai → lib/index.jslines+96 −54yesno
compaction-pruner@deepseek-ai/dsh-compaction-tool-result-pruner → lib/index.jslines+354 −14yesno
ui-renderer-turntail@deepseek-ai/dsh-client-ui-renderer → lib/client.jslines+9 −1nono
ui-sidebar-wrap@deepseek-ai/dsh-client-ui-sidebar → lib/lib-client.jsregex+1 −1nono
session-format-v1-to-v2@deepseek-ai/dsh-session-format-v1-to-v2 → lib/index.jslines+2 −1yesno
session-persistence-jsonl@deepseek-ai/dsh-session-persistence-jsonl → lib/worker.cjslines+2 −1yesno
mcp-client@deepseek-ai/dsh-mcp-client → lib/index.jslines+59 −6yesno
pi-ai-max-tokens-floor@earendil-works/pi-ai → dist/api/simple-options.jslines+11 −1yesno

Every patch has its own patches/<id>/NOTES.md with what it changes, when you want it, how to verify it, and what to do if it does not fit your build — in English and Chinese.

ui-sidebar-wrap is a regex patch on purpose: the sidebar's class prefix is a build hash, so a line diff would be invalidated by any rebuild. patches/<id>/change.json stores the pattern and its explicit inverse.

Five ways to apply them

Pick whichever matches how you like to work. All five are documented step by step in docs/methods.md (Chinese: docs/methods.zh-CN.md).

methodcommand
Ascript (recommended)node apply.mjs --check then node apply.mjs --apply --all
Bgit applycd <pkg dir> && git apply -p1 <library>/patches/<id>/change.diff
Cyour own AI agentpaste the block from PROMPT.md and let it do A or B for you
Dregenerate for your buildnode tools/make-patch.mjs --file <patched> --orig <pristine> --pkg <pkg> --rel <rel>
Erevertnode apply.mjs --revert --all, or restore any *.orig by hand

All ten diffs were verified with git apply -p1 --check inside the package directory, so method B works on every one of them.

Method A in full

node apply.mjs --list                 # what is in here
node apply.mjs --roots                # which DSH installations were found on this machine
node apply.mjs --check                # per-file state: exact / applied / conflict / missing
node apply.mjs --apply --all          # apply everything that fits
node apply.mjs --apply --only mcp-client,compaction-pruner
node apply.mjs --revert --all         # put every .orig backup back

--check reports one of:

statemeaning
exactthe file is the pristine version this library was built from — applying is safe
appliedthe file already equals the patched version, nothing to do
variantsame version, different build (hash differs) but the hunks still fit — needs --allow-variant, or method D
conflictthe hunks do not fit. Nothing is written. Use method D to regenerate for your build
missingthat package is not part of the installation that was found

What the applier guarantees

  • It finds your installation, it does not assume one. --root, $DSH_APP_ROOT, $DSH_INSTALL_ROOT, $DSH_HOME (including profiles/*), the running process's own DSH path, a node resolution from the current directory, and a bounded scan of the usual install locations for Windows / macOS / Linux — see lib/discover.mjs. --root means exactly that root, never that root plus whatever else was found.
  • .orig is sacred. A backup is written once, next to the file, and never overwritten. If a .orig already exists, it is reused.
  • Every edit is syntax-checked. node --check runs after each write; on failure the backup is restored immediately and the patch is reported as failed.
  • A hunk that does not fit is a conflict, never a guess. The engine matches a hunk's old side exactly, exactly once, near the position it was recorded at.
  • It only writes inside the resolved root. Nothing under $DSH_HOME is touched except, if you explicitly point --root at a profile directory, that profile's own node_modules copy of a package.

Exit codes: 0 success, 1 a requested action failed or conflicted, 2 no installation found.

If you already run the four DSH plugins

You can skip dsh-llm-writable-request — dsh-context-reclaim takes over that path from inside the plugin, with the official patch reverted. --check says so explicitly:

= dsh-llm-writable-request     already    node_modules/@deepseek-ai/dsh-llm/lib/index.js
    not needed: the dsh-context-reclaim plugin already handles this

The other nine are independent of the plugins: install neither, one, or both.

Self-test

node verify.mjs

Offline, no DSH installation required. It checks that every diff parses and its hunk counts agree, that the declared marker really is added by its patch, that the apply/revert engine round-trips on synthetic samples, that a duplicated context is rejected instead of guessed, that the regex patch round-trips through any class prefix — and that no file in this repository contains a drive letter, a personal home directory or a private workspace name (that scan is part of the test suite, not a promise).

verify.mjs finishes with a read-only --check summary of whatever installation it finds.

Repository layout

apply.mjs             the applier: --list --roots --check --apply --revert --show
verify.mjs            offline self-test + personal-information scan
manifest.json         every patch's metadata: hashes, sizes, markers, risk, why, applyWhen
lib/manifest.mjs      manifest loading and schema checks
lib/discover.mjs      finds DSH installations (fully adaptive, platform-aware)
lib/unified.mjs       unified-diff parse / apply / revert engine
lib/backup.mjs        .orig backup and restore
lib/hash.mjs          sha256 helpers
patches/<id>/change.diff   the patch itself (package-relative paths)
patches/<id>/change.json   regex patches: pattern + explicit inverse
patches/<id>/NOTES.md      what / when / verify, in English and Chinese
tools/make-patch.mjs  regenerate a patch for a different build of the same version
docs/methods.md       the five methods, step by step
PROMPT.md             copy-paste block for your own agent

Honest boundaries

  • These patches are built against 0.1.5-rc.2. --check will tell you if your build differs (variant / conflict) — that is information, not a failure. Method D exists for that case.
  • Applying a patch edits files under your DSH installation. That is what a patch is. The applier keeps a .orig of every file it touches, and --revert puts them back. Uninstalling or updating DSH replaces the whole tree and therefore removes the patches.
  • restartRequired in the manifest tells you whether the affected code runs in the main process (restart DSH) or in the renderer (reload the window is enough).
  • The patches are the fixes; they are not a security review of DSH. Read patches/<id>/change.diff before you apply it — that option is the whole point of shipping them as data.

License

MIT. Upstream packages remain the property of their authors; this repository only contains diffs against them.