Skip to content

About

Magic Context for DeepSeek Harness: reversible context reclaim, an out-of-band historian, an m[0]/m[1] memory baseline, project memories, and the compaction seam.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

3 stars

Watchers

0 watching

Forks

Latest commit

 

History

401 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Magic Context for DeepSeek Harness — elvisw fork

CI npm License: MIT Node

English | 简体中文

This is a port of Magic Context to DeepSeek Harness.

It remembers project facts across sessions, summarises older conversation history, and frees up context by replacing tool output with placeholders. The model can retrieve the original output when it needs it again.

Install

Requires Node ≥ 22.19. engines.dsh accepts DeepSeek Harness 0.2.1-rc.1, 0.2.2-rc.1 and 0.2.2-rc.5. The 0.2.2-rc.5 check covered the Windows web profile only. The settings page and telemetry badge need the Web or desktop UI. For dsh-go, see Android.

dsh plugin --profile web add @elvisw/dsh-magic-context

For the desktop app, use its bundled CLI and --profile desktop. Substitute your profile name if you use a custom one. The package is prebuilt; restart the profile unless hot reload (HMR) is enabled.

Keep the @elvisw/ scope. The unscoped dsh-magic-context is a separate implementation.

Upgrading from an older package? Remove @elvisw/dsh-plugin-magic-context (this fork's 0.12.x) or dsh-plugin-magic-context (the upstream DSH port) from the same profile before installing. The packages share a loader ID (magic-context-dsh), so co-installing them can hide the settings page. The migration guide has both uninstall commands. If you're upgrading from 0.12.x, follow its steps to rename the package in your profile patch after installing and before opening Settings. The rename leaves your memories, logs and data directory in place.

What you get

  • The badge by the input box shows how much context is in use. The configuration page is under Settings → Magic Context on hosts that provide the settings.section slot.
  • Project memory is on by default. The historian summarises old conversation history and saves project facts for later sessions.
  • The plugin tags tool results with §N§. The model queues output it has finished with. In normal use, the plugin waits for context usage to reach the execution threshold (65% by default) before replacing queued output with placeholders. Rewriting those messages invalidates the prompt cache prefix. Age alone does not trigger reclaim.

At policy.forceThreshold (85% by default), the plugin can also reclaim without waiting for the model. It protects the newest results that fit within 5% of the context window (clamped to 8k–64k tokens) and at least the newest eight by default (protectedToolResults). If the window size is unknown, only the count applies. Other tools go first, then edit / write / apply_patch / grep / glob, then read / todowrite / task, oldest first within each group. If the provider rejects a request as too long, the plugin can publish a ready summary, use the same reclaim order, and retry once if it changed the request. See the configuration reference for when forced reclaim is skipped, and PARITY.md for the model's reclaim reminders.

Common tasks

  • Save a project fact. Ask “Remember that we only tag a release after CI passes on main.” The model calls ctx_memory. Project memories are scoped by Git repository, with a directory fallback outside Git.
  • Compress older history manually. Type /ctx-wrapup 20 to keep the latest 20 entries.
  • Apply queued reclaims early. Type /ctx-flush, then send your next message.

Commands and tools

Ask in plain language to use the tools. Type slash commands directly.

Tool Purpose
ctx_reduce Queues tagged tool output for reclaim (a range or a list).
ctx_expand Retrieves original text by tag, by message (a session log event seq) or by start/end. Recovered tool output comes back as a new result; the original placeholder stays.
ctx_memory Memory read/write: list / search / get / write / update / archive / merge, plus review_global and promote
Command Purpose
/ctx-status Pressure, decisions, the reclaim ledger, digests, baseline, policy
/ctx-flush Marks already-queued reclaims to land on the next message; starts no historian, makes no model call
/ctx-recomp Re-runs the historian and replaces stored summaries in place
/ctx-wrapup Queues one manual compaction for the next pre-step, keeping the newest N entries (default 20)
/ctx-profile Confirm, reject or retire user-profile candidates
/ctx-global Domain membership and candidate approval

The port omits two upstream commands: /ctx-dream requires the full dreamer task set, and /ctx-embed indexes session history, memories and Git commits upstream. This port only indexes memories. See the command comparison.

Settings

Open Settings → Magic Context. The page follows the host's Chinese or English interface.

Settings page, upper half

Settings page, lower half

  • Summary model. Set a provider and model, or leave both empty to follow the session. Reasoning effort comes from the host model list.
  • Vector search. Defaults to local MiniLM (384 dimensions). For an OpenAI-compatible API such as SiliconFlow, pick the preset, load the model list and test the connection. The host credential store holds the key; the page only shows whether it is configured.
  • Compaction takeover. Off by default. Applies only to flat/headless hosts. See the setup steps before enabling it.
  • Project memory. To disable it, set memory.enabled: false in the existing plugin configuration in your profile patch. A config: override replaces the whole block, including any keys you omit such as registerCompactionEngine.

Telemetry badge. The pill by the input box shows context usage, summary status (H) and queued reclaims (Q<n>). Open it for the token breakdown and activity log. Missing values appear as —. Press Escape to close the panel and return focus to the badge.

Android

Native panels have been available since plugin version 0.18.0 and were verified on Android dsh-go 1.1.0 (source, releases). Choose the on-device engine.

Open Plugin market → DSH Go adapter and search for @elvisw/dsh-magic-context. The market catalog updates after its pull request is merged, so it can lag behind npm. If the version you want is missing, use the app's local terminal and restart the engine after installation:

dsh plugin --profile web add @elvisw/dsh-magic-context

That installs npm's latest. Append @<version> to pin a version, or run npm view @elvisw/dsh-magic-context dist-tags.latest to check the current tag.

Configure Magic Context in Web mode. If the plugin is installed on your phone's engine, open Settings → Interface → Open the web app in dsh-go, then Settings → Magic Context in DSH Web. You can pick the summary and verification models from that engine's list instead of typing IDs in the native form. Save your changes, then return to the native interface; you don't have to change your default interface. Native model selection is tracked in dsh-go #1648.

The native form still shows remote-only embedding fields when Local MiniLM is selected. Enter remote credentials in Web or desktop settings: the native key field is disabled in dsh-go 1.1.0 (dsh-go #1493). Local MiniLM needs no key.

  • Composer status strip. The same summary as the desktop pill, e.g. context 62% · reclaim 3. It yields to the host while a reply streams.
  • Context panel. When opened from a conversation, it uses only that session's data; when opened from All features, it is labelled a global view. Missing values show —. The phone does not recompute tokens.
  • Vector panel. Shows provider, model, probed dimensions, coverage and rebuild progress. It can load model IDs, test the connection, start a rebuild after confirmation, and pause or resume. Opening the panel or saving config never probes or rebuilds on its own.

Session context Vector rebuild progress

The Android verification report records local indexing, hybrid and semantic search, and persistence across an engine restart on 0.18.0. It did not cover the English mobile UI, iOS, long-history throughput, live provider traffic or Chinese keyword retrieval.

What it accesses

The dsh-go market labels the package high risk based on four flags from its static scan.

native-code (high): local semantic search. The bundled vendor/onnx/ort-wasm-simd-threaded.wasm runs MiniLM on your device. Without this WebAssembly file, the bundled local model couldn't generate vectors. You can use semantic search without sending memory text to an embedding service or configuring an API key. The package needs no native compilation.

shell (medium): project identity and cross-project warnings. git rev-list --max-parents=0 HEAD provides a repository identity for project memory, so different checkouts of the same repository can find the same memories. git rev-parse --show-toplevel finds repository roots so the plugin can warn when a session appears to be working in another repository. Both calls are read-only and time out after 3 seconds. Without Git, memory uses a directory-based identity and the cross-project check doesn't report a result. The scanner also counts SQLite and regex .exec() calls as shell use; those calls don't start a process.

network (low): model download, host UI and optional remote embeddings. Local search needs the MiniLM model files. On first use, the plugin fetches them from Hugging Face or its mirror, checks their SHA-256 hashes and caches them for offline reuse. The Web UI uses same-origin host routes to show context statistics and operate the embedding panel. If you choose remote embeddings, loading models, testing the connection or starting a rebuild contacts the configured endpoint. Once a rebuild enables remote indexing and search, memory and query text can be sent to that endpoint.

filesystem (medium): state across sessions and restarts. The plugin stores project memories in memories.db and keeps summaries and the reclaim queue in its runtime database. The journal keeps activity records for troubleshooting, and the model cache avoids repeat downloads. These files default to ~/.local/share/cortexkit/magic-context-dsh-poc/, outside the workspace. Set dataDir to use a different location.

See the scan replay for @elvisw/dsh-magic-context@0.18.0 for the matched files and false positives.

Known limits

  • Historian triggering and budgets estimate tokens as characters divided by four, not with a real tokenizer. The retrieval-vector path does use the real tokenizer.
  • The detail tiers of a digest are produced in a single call; upstream accumulates them across calls.
  • Chinese keyword retrieval is weak. FTS5's porter unicode61 tokenizer does not segment Chinese, so a run of Han characters counts as one token and Chinese queries depend on the vector lane. This is upstream behaviour inherited by this port.
  • review_global approval cards must be raised inside an agent turn. Headless hosts with no answerer refuse explicitly and change no state.
  • A journal that is off at mount time needs a restart to be turned on at runtime.

Troubleshooting

For persistent logs, check the plugin's SQL journal table or activity.log, which rotates past 5 MiB. Both are under the data directory. These logs record counts, tag numbers, token estimates, reasons and durations. They omit message bodies.

Run these diagnostics from a checkout of this repository:

npm run doctor         # read-only health report
node scripts/mc-report.mjs --days 7 [--json]   # journal review
node scripts/mc-acceptance.mjs [--hours 72]    # corpus acceptance, exits 1 on failure

Documentation

Currently maintained

Historical material

Kept for provenance only, not a current guarantee. Each file opens with its own status note and evidence baseline.

Contributing

Provenance and license

This repository is a fork of the DSH port wk544863858/dsh-plugin-magic-context (upstream npm release 0.11.2, MIT, Copyright (c) 2026 wukai). The port was extracted from Magic Context v0.46.0 (MIT, Copyright (c) 2025 Ufuk Altinok). Changes in this fork are Copyright (c) 2026 elvisw, also under MIT.

The changelog records changes since the fork, including the breaking change to output recovery in 0.12.0. The behaviour comparison in PARITY.md uses Magic Context v0.49.30; the command comparison uses v0.49.59. Each covers the items listed in its table.

See NOTICE for upstream revisions and third-party notices.

Compliance and disclaimer

  • Lawful use. Follow applicable laws and respect the rights of others when using this plugin.
  • Third-party services. If you use a model provider, an embedding service or another third-party application with the plugin, that service's terms and charges apply.
  • No warranty; back up your data. The plugin is provided “as is,” without express or implied warranties. It rewrites conversation history, drops tool output and stores memories in local SQLite files. Back up any data you need to keep. See the MIT LICENSE for the full terms, including limits on liability for data loss, service charges or other damages.

This summary is not legal advice. The license text governs the terms of the software.

About

Magic Context for DeepSeek Harness: reversible context reclaim, an out-of-band historian, an m[0]/m[1] memory baseline, project memories, and the compaction seam.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages