Foreword¶
When running long conversations or large prompts in DeepSeek Harness (DSH), two common problems arise: the server returns a 400 error of the “context exceeded” type, and the official compression pipeline cannot be hooked into; or the local OpenAI-compatible service (such as llama.cpp) has a limited window, and you only discover the window has blown after sending. Products like Cursor and Codex often estimate before stepping based on a token ledger, rather than waiting for a KV memory error.
The community plugin dsh-plugin-local-prompt-bridge (maintainer tianyiming1) targets the above scenarios: it does not modify or replace any @deepseek-ai/* package, rewrites overflow errors via a Cordis patch, and—after routes are configured—performs proactive token accounting against the local /tokenize, converting requests that are about to exceed the limit into the CONTEXT_WINDOW_EXCEEDED error that the official compaction-basic can recognize, then retries. With the default routes: [], only global overflow rewriting is enabled; proactive compaction requires you to integrate with the providers in llm-pi-ai yourself.
What Is This¶
- Positioning: Stock-safe community DSH plugin; HTTP tokenize pressure detection + overflow →
CONTEXT_WINDOW_EXCEEDEDcompact-retry. - Repository: tianyiming1/dsh-plugin-local-prompt-bridge (npm package name
@local/dsh-plugin-local-prompt-bridge, current documented version 0.1.4, MIT). - Category: Model inference (SkillHub directory classification).
- Relationship with the official: Independent community work; the DSH ecosystem emphasizes “everything is a plugin”, with SkillHub and others serving as community directories, and has no official subordination to DeepSeek / High-Flyer.
Core Features¶
The two items below are explicitly documented in the README and can be understood separately.
1. Overflow Rewriting (default for all providers)¶
Rewrites exceed_context_size_error or HTTP 400 errors of the “context exceeded” type into CONTEXT_WINDOW_EXCEEDED, handing them to the official compaction-basic to compact history and then retry. It takes effect after installing the plugin and writing it into bundles, with no need to configure a local model.
2. Proactive Token Accounting (requires routes configuration)¶
Before each LLM call is issued:
- Call
/tokenizeon the configured local OpenAI-compatible endpoint; if it fails, fall back to/apply-templateto get the content and then estimate. - Calculate the token size of the request package about to be sent.
- If it exceeds
min(thresholdRatio × window, window − outputReserve)(defaultthresholdRatiois about 0.90, andoutputReserveis reserved for generation headroom), synthesize an overflow, trigger the official compaction, and then send. - If not exceeded, send directly (the earlier “soft-line false fullness” strategy is no longer used).
- If it still hits the actual server-side limit, the overflow rewriting in item 1 acts as a fallback.
The strategy aligns with “token ledger”-based context management rather than relying on KV memory errors.
Installation and Activation¶
The plugin is installed via pnpm in the web profile and registered in dsh.profile.bundles of package.json. Please operate on a closed DSH process (or shut it down before starting again).
Enter the profile directory and add the dependency:
cd $env:USERPROFILE\.dsh\profiles\web
pnpm add github:tianyiming1/dsh-plugin-local-prompt-bridge
For local development, if you have already cloned or linked to a local path, you can use:
pnpm add link:D:/deepseek-harness-workspace/dsh-plugin-local-prompt-bridge
(Replace the link: path with your local plugin directory.)
Append the bundle name to the end of the dsh.profile.bundles array in the package.json in the same directory:
"@local/dsh-plugin-local-prompt-bridge"
After saving, start the official DSH in the usual way (desktop / npx / command). Do not use a forked source code as a replacement.
Optional: Configuring Proactive Compaction¶
Edit cordis.patch.yml under your profile to override the plugin config (provider must match the id in llm-pi-ai):
- id: local-prompt-bridge
config:
routes:
- provider: llama-cpp-local # must match the provider id in llm-pi-ai
baseURL: http://127.0.0.1:8080/v1
contextWindow: 65536
thresholdRatio: 0.90
outputReserve: 4096
You can also directly modify the cordis.patch.yml in this package (only applicable for local forks / link:).
To temporarily disable: remove this package from bundles, or set rewriteOverflow / proactiveCompact in the config to false (see the README self-test section).
Typical Usage and Self-Test¶
The README recommends verifying in the following order, rather than writing separate business scripts.
- If proactive routes are enabled, first confirm the local OpenAI-compatible service is running (e.g., llama.cpp’s
/v1). - Start the official DSH in the usual way.
- Check whether the startup log shows something like:
[local-prompt-bridge] active (rewrite=all-providers, ... compactAt=0.9 ...). - A moderately large prompt (e.g., 40k / 64k magnitude) should pass directly; when approaching the window or triggering a server-side window exceedance, it should compact first and then retry.
- When not needed, remove from
bundlesor turn off the two boolean switches above.
Applicable Scenarios and Notes¶
Who it’s for
- Those already using community bundles in the DSH web profile who want to uniformly route context overflow errors from various providers to the official compact-retry.
- Those with local OpenAI-compatible services like llama.cpp that have small windows and want to perform token accounting via
/tokenizebefore sending requests to reduce invalid 400s. - Users who want to only reinstall the plugin after upgrading the official DSH, rather than patching the official package.
Notes
- The plugin runs with the permissions of the current DSH process; before installing, read the repository source code and MIT license, and confirm that
baseURLandroutespoint to a local service you trust. - By default it does not bind to any personal model or port; proactive compaction relies entirely on the routes you fill in in
cordis.patch.yml. - If the official later merges an optional
countPromptTokensor better overflow classification, you can gradually switch to the official capability and disable the corresponding part of this plugin, following the README’s “Relationship with upstream protocols” section. The proposal draft is in the repository’sDISCUSSION.md; discussions should be posted to the deepseek-harness Discussions.
Conclusion¶
dsh-plugin-local-prompt-bridge, without modifying the official package, provides global overflow rewriting and optional local token accounting, funneling over-long context problems into the existing compaction-basic path of DSH. The directory and details can be viewed on SkillHub: tianyiming1/dsh-plugin-local-prompt-bridge; the source code and full documentation are in the GitHub repository.