DeepSeek Harness Plugin

lov0vo/dsh-composer-autopair

Stars ★ 1 Category UI Enhancements Added 2026-10-17

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:

  1. builds lib/client.js from src/autopair.mjs;

  2. copies the package into <DSH_HOME>/plugins/dsh-composer-autopair/ (a stable copy) and into <DSH_HOME>/profiles/desktop/node_modules/dsh-composer-autopair/;

  3. registers a file: dependency in the profile's package.json pointing at that stable copy, not at the repository — otherwise moving the repository turns it into a dangling dependency, pnpm install prunes the directory, and the plugin silently stops working;

  4. mounts the loader entry, choosing exactly one route from what the profile already has:

    dsh.profile.bundles in the profile What deploy does Activation
    already lists this package (installed by dshmarket, or added by hand) bundle route: the package's own cordis.patch.yml inserts the entry; deploy only removes the managed block from the user patch needs 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.yml immediate when the profile declares patchReload: live

    The managed block looks like this:

    - insert:
        - id: composer-autopair
          name: dsh-composer-autopair
    

    Why exactly one route: inserting both makes the id composer-autopair appear 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's pnpm-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 operation viaEditor grows and viaDom stays 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 and trace shows 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 .ldb it is no longer plain text — use the DevTools console then: JSON.parse(localStorage['dsh-composer-autopair-report']).

How it works

  1. Intercept beforeinput (document capture), not keydown. When a Chinese IME commits ( as (, the keydown is usually Process/keyCode 229; either way a beforeinput always arrives.
  2. Act on the Lexical model layer. The editor instance is [data-composer-input].__lexicalEditor; inside editor.update() we insertText() on the pending selection and place the caret with Point.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.
  3. 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().
  4. The IME path is handled separately. When compositionend arrives, 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 duplicate compositionend cannot 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 (recording imeNotSettled + ce-nocaret / ce-stale) instead of leaving the commit unpaired, and never deletes what the IME just committed.
  5. 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.
  6. 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 compositionend arrives. compositionstart therefore records the text first, and after the commit the plugin rebuilds open + text + close around 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.
  7. 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.
  8. Idempotent and disposable. installAutoPair disposes the previous instance; the plugin entry registers cleanup through ctx.effect, so disabling or hot-reloading removes the listeners.

Known limits

  • Relies on a few Lexical internals: __lexicalEditor, _pendingEditorState._selection, TextNode.setTextContent() and Point.set(). A DSH/Lexical upgrade may break them — caps.lexicalEditor / caps.editorError in 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

MIT

Content from the project README on GitHub ↗

Links

More in this category

View the whole category →

Community comments

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