Auto-pairs brackets and quotes in the DSH chat composer, inserting the closing half with the caret in between; it also wraps selected text with the typed pair and handles brackets committed by an IME.
Install
# from GitHub (first run asks for allowBuilds approval — follow the hint, retry)
dsh plugin --profile web add github:lov0vo/dsh-composer-autopair
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
Auto-pair brackets and quotes in the DSH (DeepSeek Harness) chat composer: type the opening half, get the closing half, with the caret placed in between.
English | 中文
What it does
| You type | Result |
|---|---|
( [ { " ' ` ( 【 《 「 “ … |
The closing half is inserted, caret lands in between |
) while the caret sits inside () |
Skips over the closing half — no ()) |
A quote key while the caret sits inside an empty “” pair |
Nests another pair → ““”” (Chinese IMEs only give you the closing quote here) |
A quote key to finish quoting (“text”, caret at the end) |
Skips over the closing quote — normal wrapping-up |
( with text selected |
Wraps it → (selected text), with the text re-selected |
Backspace inside an empty () |
Deletes both characters at once |
A Chinese IME committing ( |
The matching ) is appended too |
A Chinese IME committing ) when a ) already follows |
Skips over it — no ()) |
The composer inside a DSH question card (AskUserQuestion-style <textarea>) |
Everything above works there too |
Pair table (17 pairs, ASCII + full-width):
( ) [ ] { } " " ' ' ` `
( ) [ ] { } 【 】 《 》 〈 〉 「 」 『 』 〔 〕 “ ” ‘ ’
Deliberately out of scope: settings inputs, the terminal, the right-sidebar editor and the file tree are never touched, and nothing happens while an IME composition is in progress.
That question-card input is a plain <textarea> (not Lexical). The plugin recognises it by the
aria-hidden mirror <div> next to it or by fieldInput in its class name; to cover another textarea on
your machine, put a comma-separated list of selectors into the dsh-composer-autopair:textareas
localStorage key.
Install
This is a regular DSH client plugin package (dsh.client + dsh.bundle.patch); the built bundle
lib/client.js is committed, so no build step is required to use it.
git clone https://github.com/lov0vo/dsh-composer-autopair
cd dsh-composer-autopair
node deploy.mjs # build + install (mounting route chosen automatically)
node deploy.mjs --check # dry run
node deploy.mjs --remove # uninstall
deploy.mjs does four things:
builds
lib/client.jsfromsrc/autopair.mjs;copies the package into
<DSH_HOME>/plugins/dsh-composer-autopair/(a stable copy) and into<DSH_HOME>/profiles/desktop/node_modules/dsh-composer-autopair/;registers a
file:dependency in the profile'spackage.jsonpointing at that stable copy, not at the repository — otherwise moving the repository turns it into a dangling dependency,pnpm installprunes the directory, and the plugin silently stops working;mounts the loader entry, choosing exactly one route from what the profile already has:
dsh.profile.bundlesin the profileWhat deploy does Activation already lists this package (installed by dshmarket, or added by hand) bundle route: the package's own cordis.patch.ymlinserts the entry; deploy only removes the managed block from the user patchneeds a DSH restart (the bundle list is read at host startup) does not list it user-patch route: deploy appends the managed block to the profile's cordis.patch.ymlimmediate when the profile declares patchReload: liveThe managed block looks like this:
- insert: - id: composer-autopair name: dsh-composer-autopairWhy exactly one route: inserting both makes the id
composer-autopairappear twice; the "can this composition start?" static check dshmarket runs after installing or updating a plugin reports a duplicate loader entry id and rolls the whole update back. (The real loader here is 1.0.5, where a duplicate merely means "the later layer wins" — but dshmarket reads the loader version from the profile'spnpm-lock.yaml, which does not contain it, so it conservatively treats it as fatal.)
Environment variables: DSH_HOME (default ~/.dsh), DSH_PROFILE_DIR
(default $DSH_HOME/profiles/desktop).
Toggling
No need to uninstall — turn it off temporarily:
// DevTools console
__dshComposerAutoPair.setEnabled(false); // off
__dshComposerAutoPair.setEnabled(true); // on
localStorage.setItem('dsh-composer-autopair:enabled', 'off'); // stays off across restarts
Diagnostics
Every 3 seconds the plugin writes a self-check report to localStorage, readable without DevTools:
| Key | Content |
|---|---|
dsh-composer-autopair-report |
caps (editor instance found? last model-layer error), stats (counters), log (last 12 actions), trace (last 24 events — enough to replay what one keypress actually did) |
dsh-composer-autopair:probe |
Load beacon — present means the plugin really ran |
dsh-composer-autopair:error |
Load / model-layer errors |
dsh-composer-autopair:enabled |
on / off |
node tools/read-report.mjs # reads the DSH desktop Local Storage by default
node tools/read-report.mjs "<leveldb dir>" # custom path
Counters worth watching:
viaEditor/viaDom— handled by the "Lexical model layer" or by the "DOM fallback". In normal operationviaEditorgrows andviaDomstays 0;nested— how many times an extra pair was nested inside an empty quote pair;imeCommits/imePaired/imeSkippedCloser/imeDuplicate— the four IME branches;imeNotSettled— times the plugin gave up because the model never absorbed the IME commit. This should stay 0; if it keeps growing, the input path changed andtraceshows where it stalled.
LevelDB flushes lazily: when the DSH window is in the background Chromium throttles timers to roughly once a minute, and flushes are slow too. Read 1–2 minutes after an action, otherwise you may be looking at the previous revision. Once a record is compacted into
.ldbit is no longer plain text — use the DevTools console then:JSON.parse(localStorage['dsh-composer-autopair-report']).
How it works
- Intercept
beforeinput(document capture), notkeydown. When a Chinese IME commits(as(, the keydown is usuallyProcess/keyCode 229; either way abeforeinputalways arrives. - Act on the Lexical model layer. The editor instance is
[data-composer-input].__lexicalEditor; insideeditor.update()weinsertText()on the pending selection and place the caret withPoint.set()+dirty. Insertion and caret move happen atomically in one update, so the model selection and the DOM can never disagree — which is what makes "caret always in the middle", "Backspace/Delete work in the middle" and "selection gets wrapped" reliable. - The DOM path is only a fallback, used when no editor instance is available (or the selection
contains decorator nodes such as
@reference chips):document.execCommand('insertText')+Selection.modify(). - The IME path is handled separately. When
compositionendarrives, Lexical usually has not yet written that commit into its model, so the plugin polls the model (up to 12 frames) until the committed character lands next to the caret, and only then decides whether an opening or closing half was committed. Our own appended closing half is recognised by a fingerprint record (text node key + caret offset + both halves + timestamp), so a duplicatecompositionendcannot double-insert, and "delete the pair, then type the same opening half in the same spot" is not misread as a duplicate. If the model never settles (or the model caret cannot be read at all), the plugin switches to the DOM fallback (recordingimeNotSettled+ce-nocaret/ce-stale) instead of leaving the commit unpaired, and never deletes what the IME just committed. - Quotes get their own rule. After an opening quote, a Chinese IME only produces the closing quote, so "inside an empty pair" nests another pair, while "pair already has content" still skips over. And a committed closing quote with no unmatched opening quote to its left (the caret sitting after a pair that already has content is the typical case) is rewritten into a fresh pair, so quotes always end up paired. Brackets are unaffected.
- With a selection, either half wraps. When an IME commits a symbol it first deletes the selection
and then inserts the character, so the original text is already gone by the time
compositionendarrives.compositionstarttherefore records the text first, and after the commit the plugin rebuildsopen + text + closearound the symbol immediately left of the caret. Closing halves (”,)) are handled the same way —wrapPairFor()looks up their opening half, so a selected word is never replaced by a lone closing quote. - One Ctrl+Z undoes the whole pair. Every model-layer update on the IME path carries
{ tag: ['history-merge'] }, so Lexical folds it into the history entry created by the IME commit and a single undo rolls back both symbols (and the wrapped text). The direct-typing path (beforeinput) does not use that tag, keeping step-by-step undo. - Idempotent and disposable.
installAutoPairdisposes the previous instance; the plugin entry registers cleanup throughctx.effect, so disabling or hot-reloading removes the listeners.
Known limits
- Relies on a few Lexical internals:
__lexicalEditor,_pendingEditorState._selection,TextNode.setTextContent()andPoint.set(). A DSH/Lexical upgrade may break them —caps.lexicalEditor/caps.editorErrorin the report tell you right away, and the plugin then falls back to the DOM path. - Only the chat composer (
[data-composer-input]). - Does not touch
/slash commands or@references — those belong to DSH itself. - Does nothing while an IME composition is active.
Development
src/autopair.mjs single source of truth: pair table, pure logic, Lexical adapter, apply(ctx)
src/autopair.test.mjs 80 tests: pure logic + full flow on a mini DOM + a fake Lexical editor + a fake textarea
src/deploy.test.mjs 8 installer tests: block stripping, route choice, both routes, --check, uninstall
build.mjs renders src into lib/client.js (the DSH client bundle shape)
deploy.mjs install / uninstall (picks the loader mounting route automatically)
tools/read-report.mjs read the diagnostics report from disk
lib/index.js host half (no-op; exists so the loader mounts the package)
lib/client.js build output — do not edit by hand
cordis.patch.yml loader entry used by bundle-style installs
node --test src/autopair.test.mjs src/deploy.test.mjs # run all 88 tests
node build.mjs # rebuild lib/client.js
node deploy.mjs # install into the profile
To change the pair table, edit DEFAULT_PAIRS in src/autopair.mjs, then
node build.mjs && node deploy.mjs.
Compatibility
Tested on DSH desktop (profile desktop, Windows). Any DSH build whose chat composer uses the same
Lexical editor should work; after installing, caps.composerReady === true in the report means the
anchor matched.
Changelog
Every release, including the root cause behind each fix, is documented in CHANGELOG.md (Chinese first, with English summaries). Tagged releases with notes are on the Releases page.
Recent versions:
| Version | Internal | In one line |
|---|---|---|
| 0.6.1 | v10 | With a selection, either half (”, )) wraps it; one Ctrl+Z undoes the whole pair |
| 0.6.0 | v9 | The question card's plain textarea pairs too |
| 0.5.3 | v8 | Wrapping a selection no longer relies on node identity that Lexical re-creates (0.5.2 did not fire in the real editor) |
| 0.5.2 | v7 | With a Chinese IME, typing a symbol over a selection wraps it instead of replacing it |
| 0.5.1 | v6 | Fixes a 0.5.0 regression: no more "nothing is paired" when the model caret is unreadable |
| 0.5.0 | v5 | Quotes pair up every time under a Chinese IME |
| 0.4.1 | v4 | A loader id is never mounted twice (bundle or user-patch, not both) |
License
Links
More in this category
zhu1090093659/dsh-web#packages/dsh-task-board★ 10696
Task board for the dsh web GUI: a sidebar multi-column kanban whose cards run in real DSH agent sessions and can also be scheduled with cron expressions, executed host-side even with the browser closed.
zhu1090093659/dsh-web#packages/dsh-web-all★ 10696
Plugin and skin collection for the DSH Web UI: task board, Git graph, right-side panel, remote mobile UI, pet, live token stats, and a skin center.
ccch1mneyyy/dsh-TUI★ 8484
Claude Code-style full-screen terminal UI: pixel-whale header, live status line, and streaming thought expansion.
MeteorNOX/DeepSeek-Balance-Whale-Widget★ 7509
A fixed-corner whale widget for the DSH web GUI — balance, today's usage and per-turn cost with peak/off-peak pricing, editable balance-alert and daily-budget bubbles, a module-based custom bubble queue with A/B weighted choices and random lines or images, 30+ vendor templates (OpenAI, OpenRouter, Kimi, SiliconFlow, Ark, Zhipu, MiniMax and more) with per-model balance and subscription quota, plus task-end sound, imported audio, custom roles and a resource manager. Local-only, no telemetry.
omdsh-dev/DSH-better-sidebar★ 5395
Full sidebar workbench with file rendering and editing, terminal, Git, and subagents; third-party plugins can register new tabs.
omdsh-dev/dsh-genui★ 1082
Interactive UI components rendered inline in replies: layout, charts, forms, quizzes, mermaid, 3D scenes, and an action event loop back to the model.
Community comments
Comments are public GitHub Discussions. Loading them connects to GitHub and Giscus; a GitHub account is required to post.